dsh-linked-workspace 0.22.0 → 0.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17 -0
- package/README.en.md +8 -1
- package/README.md +8 -1
- package/docs/API.md +9 -1
- package/docs/VERIFY.md +11 -1
- package/lib/client.js +359 -134
- package/lib/index.js +418 -35
- package/lib/linked.js +43 -0
- package/lib/ssh.js +28 -0
- package/package.json +1 -1
- package/scripts/doc_tool.py +89 -0
package/lib/linked.js
CHANGED
|
@@ -67,6 +67,7 @@ const ALLOWED_UPDATE_FIELDS = Object.freeze([
|
|
|
67
67
|
'hostSnapshot',
|
|
68
68
|
'remotePath',
|
|
69
69
|
'mirror',
|
|
70
|
+
'autoPush',
|
|
70
71
|
])
|
|
71
72
|
|
|
72
73
|
// -- small helpers ----------------------------------------------------------
|
|
@@ -252,6 +253,47 @@ function sanitizeHostSnapshot(input, previous) {
|
|
|
252
253
|
}
|
|
253
254
|
}
|
|
254
255
|
|
|
256
|
+
/** autoPush knobs, clamped here so a hand-edited registry cannot break a watcher. */
|
|
257
|
+
const AUTO_PUSH_DEBOUNCE_MIN = 300
|
|
258
|
+
const AUTO_PUSH_DEBOUNCE_MAX = 60000
|
|
259
|
+
const AUTO_PUSH_DEBOUNCE_DEFAULT = 1500
|
|
260
|
+
|
|
261
|
+
function autoPushPatterns(value, fallback) {
|
|
262
|
+
const source = Array.isArray(value) ? value : Array.isArray(fallback) ? fallback : []
|
|
263
|
+
const seen = new Set()
|
|
264
|
+
const out = []
|
|
265
|
+
for (const item of source) {
|
|
266
|
+
if (typeof item !== 'string') continue
|
|
267
|
+
const pattern = item.trim()
|
|
268
|
+
if (pattern === '' || seen.has(pattern)) continue
|
|
269
|
+
seen.add(pattern)
|
|
270
|
+
out.push(pattern)
|
|
271
|
+
if (out.length >= 100) break
|
|
272
|
+
}
|
|
273
|
+
return out
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* Per-workspace push config (0.24.0). `enabled` alone decides whether this
|
|
278
|
+
* workspace gets a watcher; the other three are per-workspace overrides of the
|
|
279
|
+
* old global settings.
|
|
280
|
+
*/
|
|
281
|
+
function sanitizeAutoPush(input, previous) {
|
|
282
|
+
const source = isObject(input) ? input : {}
|
|
283
|
+
const base = isObject(previous) ? previous : {}
|
|
284
|
+
const enabled = typeof source.enabled === 'boolean' ? source.enabled : base.enabled === true
|
|
285
|
+
const raw = Number(source.debounceMs ?? base.debounceMs)
|
|
286
|
+
const debounceMs = Number.isFinite(raw)
|
|
287
|
+
? Math.min(AUTO_PUSH_DEBOUNCE_MAX, Math.max(AUTO_PUSH_DEBOUNCE_MIN, Math.round(raw)))
|
|
288
|
+
: AUTO_PUSH_DEBOUNCE_DEFAULT
|
|
289
|
+
return {
|
|
290
|
+
enabled,
|
|
291
|
+
debounceMs,
|
|
292
|
+
include: autoPushPatterns(source.include, base.include),
|
|
293
|
+
exclude: autoPushPatterns(source.exclude, base.exclude),
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
|
|
255
297
|
/**
|
|
256
298
|
* Build a persisted LinkRecord from untrusted JSON or caller input.
|
|
257
299
|
* `previous` supplies defaults for a merge-style update.
|
|
@@ -279,6 +321,7 @@ function sanitizeRecord(input, previous) {
|
|
|
279
321
|
remotePath,
|
|
280
322
|
mirror,
|
|
281
323
|
syncChoice,
|
|
324
|
+
autoPush: sanitizeAutoPush(input.autoPush, base.autoPush),
|
|
282
325
|
createdAt,
|
|
283
326
|
}
|
|
284
327
|
}
|
package/lib/ssh.js
CHANGED
|
@@ -1510,6 +1510,34 @@ export class RemoteHost {
|
|
|
1510
1510
|
* @param {{ timeoutMs?: number, signal?: AbortSignal }} [options]
|
|
1511
1511
|
* @returns {Promise<{ stdout: string, stderr: string, code: number }>}
|
|
1512
1512
|
*/
|
|
1513
|
+
/**
|
|
1514
|
+
* Open a direct-tcpip channel to `host:port` as seen from the SSH server.
|
|
1515
|
+
* The caller pipes a local socket through it, which is what makes a local
|
|
1516
|
+
* tunnel to a remote TensorBoard/Jupyter possible.
|
|
1517
|
+
*/
|
|
1518
|
+
async forwardOut(host, port) {
|
|
1519
|
+
const targetHost = typeof host === 'string' && host.trim() !== '' ? host.trim() : '127.0.0.1';
|
|
1520
|
+
const targetPort = Number(port);
|
|
1521
|
+
if (!Number.isInteger(targetPort) || targetPort <= 0 || targetPort > 65535) {
|
|
1522
|
+
throw new SshError('BAD_REQUEST', `Invalid remote port: ${port}`);
|
|
1523
|
+
}
|
|
1524
|
+
const client = await this.#readyClient();
|
|
1525
|
+
return await new Promise((resolve, reject) => {
|
|
1526
|
+
client.forwardOut('127.0.0.1', 0, targetHost, targetPort, (err, channel) => {
|
|
1527
|
+
if (err) {
|
|
1528
|
+
reject(
|
|
1529
|
+
new SshError(
|
|
1530
|
+
'SSH_FORWARD',
|
|
1531
|
+
`Cannot open a tunnel to ${targetHost}:${targetPort} on ${this.authority}: ${(err && err.message) || err}`,
|
|
1532
|
+
),
|
|
1533
|
+
);
|
|
1534
|
+
return;
|
|
1535
|
+
}
|
|
1536
|
+
resolve(channel);
|
|
1537
|
+
});
|
|
1538
|
+
});
|
|
1539
|
+
}
|
|
1540
|
+
|
|
1513
1541
|
async exec(command, options = {}) {
|
|
1514
1542
|
const defaultTimeoutMs = 20000;
|
|
1515
1543
|
const commandText = typeof command === 'string' ? command : '';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-linked-workspace",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.24.0",
|
|
4
4
|
"description": "Linked local ⇄ remote workspaces and remote workspaces for DeepSeek Harness: theme-aware split editor, file-type icons, and agent tools that edit remote files directly.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
package/scripts/doc_tool.py
CHANGED
|
@@ -24,6 +24,9 @@ MAX_PDF_WIDTH = 1100
|
|
|
24
24
|
MAX_SHEET_ROWS = 200
|
|
25
25
|
MAX_SHEET_COLS = 40
|
|
26
26
|
MAX_PPTX_SLIDES = 80
|
|
27
|
+
# Text extraction for the model keeps every page/sheet but stops collecting
|
|
28
|
+
# cells once a sheet gets unreasonably long; the host truncates the final text.
|
|
29
|
+
MAX_XLSX_ROWS = 2000
|
|
27
30
|
|
|
28
31
|
|
|
29
32
|
def fail(message):
|
|
@@ -183,6 +186,29 @@ def read_pptx(path):
|
|
|
183
186
|
emit({"kind": "pptx", "slides": slides, "slideCount": len(presentation.slides)})
|
|
184
187
|
|
|
185
188
|
|
|
189
|
+
def read_text_pptx(path):
|
|
190
|
+
from pptx import Presentation
|
|
191
|
+
|
|
192
|
+
presentation = Presentation(path)
|
|
193
|
+
slides = []
|
|
194
|
+
for slide_index, slide in enumerate(presentation.slides):
|
|
195
|
+
if slide_index >= MAX_PPTX_SLIDES:
|
|
196
|
+
break
|
|
197
|
+
texts = []
|
|
198
|
+
for shape in slide.shapes:
|
|
199
|
+
if not getattr(shape, "has_text_frame", False):
|
|
200
|
+
continue
|
|
201
|
+
text = shape.text_frame.text
|
|
202
|
+
if text.strip() == "":
|
|
203
|
+
continue
|
|
204
|
+
texts.append(text)
|
|
205
|
+
notes = ""
|
|
206
|
+
if getattr(slide, "has_notes_slide", False):
|
|
207
|
+
notes = slide.notes_slide.notes_text_frame.text or ""
|
|
208
|
+
slides.append({"index": slide_index, "texts": texts, "notes": notes})
|
|
209
|
+
emit({"kind": "pptx", "slides": slides, "slideCount": len(presentation.slides)})
|
|
210
|
+
|
|
211
|
+
|
|
186
212
|
def write_pptx(source, data, out):
|
|
187
213
|
from pptx import Presentation
|
|
188
214
|
|
|
@@ -245,6 +271,54 @@ def read_pdf(path, page_index=None):
|
|
|
245
271
|
})
|
|
246
272
|
|
|
247
273
|
|
|
274
|
+
def read_text_pdf(path):
|
|
275
|
+
import fitz
|
|
276
|
+
|
|
277
|
+
doc = fitz.open(path)
|
|
278
|
+
pages = []
|
|
279
|
+
for index in range(doc.page_count):
|
|
280
|
+
pages.append({"index": index, "text": doc[index].get_text("text")})
|
|
281
|
+
metadata = doc.metadata or {}
|
|
282
|
+
emit({
|
|
283
|
+
"kind": "pdf",
|
|
284
|
+
"pageCount": doc.page_count,
|
|
285
|
+
"title": metadata.get("title", ""),
|
|
286
|
+
"author": metadata.get("author", ""),
|
|
287
|
+
"pages": pages,
|
|
288
|
+
})
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
def read_text_docx(path):
|
|
292
|
+
from docx import Document
|
|
293
|
+
|
|
294
|
+
document = Document(path)
|
|
295
|
+
paragraphs = [paragraph.text for paragraph in document.paragraphs]
|
|
296
|
+
tables = []
|
|
297
|
+
for table in document.tables:
|
|
298
|
+
rows = []
|
|
299
|
+
for row in table.rows:
|
|
300
|
+
rows.append([cell.text for cell in row.cells])
|
|
301
|
+
tables.append(rows)
|
|
302
|
+
emit({"kind": "docx", "paragraphs": paragraphs, "tables": tables})
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
def read_text_xlsx(path):
|
|
306
|
+
from openpyxl import load_workbook
|
|
307
|
+
|
|
308
|
+
workbook = load_workbook(path, data_only=True, read_only=True)
|
|
309
|
+
sheets = []
|
|
310
|
+
for sheet in workbook.worksheets:
|
|
311
|
+
rows = []
|
|
312
|
+
for row in sheet.iter_rows(values_only=True):
|
|
313
|
+
cells = ["" if value is None else str(value) for value in row]
|
|
314
|
+
if any(cell.strip() != "" for cell in cells):
|
|
315
|
+
rows.append(cells)
|
|
316
|
+
if len(rows) >= MAX_XLSX_ROWS:
|
|
317
|
+
break
|
|
318
|
+
sheets.append({"name": sheet.title, "rows": rows})
|
|
319
|
+
emit({"kind": "xlsx", "sheets": sheets})
|
|
320
|
+
|
|
321
|
+
|
|
248
322
|
def write_pdf(source, data, out):
|
|
249
323
|
import fitz
|
|
250
324
|
|
|
@@ -381,6 +455,10 @@ def main():
|
|
|
381
455
|
pdf.add_argument("--file", required=True)
|
|
382
456
|
pdf.add_argument("--out", required=True)
|
|
383
457
|
|
|
458
|
+
text = sub.add_parser("read-text")
|
|
459
|
+
text.add_argument("--kind", required=True)
|
|
460
|
+
text.add_argument("--file", required=True)
|
|
461
|
+
|
|
384
462
|
args = parser.parse_args()
|
|
385
463
|
try:
|
|
386
464
|
if args.command == "read":
|
|
@@ -413,6 +491,17 @@ def main():
|
|
|
413
491
|
markdown_preview(args.file)
|
|
414
492
|
elif args.command == "md-pdf":
|
|
415
493
|
markdown_pdf(args.file, args.out)
|
|
494
|
+
elif args.command == "read-text":
|
|
495
|
+
if args.kind == "docx":
|
|
496
|
+
read_text_docx(args.file)
|
|
497
|
+
elif args.kind == "xlsx":
|
|
498
|
+
read_text_xlsx(args.file)
|
|
499
|
+
elif args.kind == "pptx":
|
|
500
|
+
read_text_pptx(args.file)
|
|
501
|
+
elif args.kind == "pdf":
|
|
502
|
+
read_text_pdf(args.file)
|
|
503
|
+
else:
|
|
504
|
+
raise ValueError(f"unsupported kind: {args.kind}")
|
|
416
505
|
except Exception as error: # pragma: no cover - CLI boundary
|
|
417
506
|
fail(error)
|
|
418
507
|
|