dsh-linked-workspace 0.27.0 → 0.28.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 CHANGED
@@ -1,5 +1,33 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.28.0 — 2026-11-26
4
+
5
+ - The directory tree now follows renames and deletions instead of waiting for a page reload. Every
6
+ mutation made through the plugin bumps a Host-side `listings` counter that the panel polls every
7
+ five seconds, a quiet refresh no longer keeps rows the listing stopped returning, the remote tree
8
+ refreshes on the same tick as the local one, and the refresh button forces a real re-list instead of
9
+ remounting a panel that restored its cached rows.
10
+ - An open file tab no longer outlives its file: pane tabs re-check their path with `fs.stat` /
11
+ `local.stat` whenever the trees refresh, sidebar file tabs probe it every ten seconds, and a tab
12
+ whose file disappeared closes itself, re-lists the tree and says why.
13
+
14
+ ## 0.27.1 — 2026-11-26
15
+
16
+ - Markdown previews **refuse documents above 512 Ki characters** instead of rendering them
17
+ synchronously on the Host's event loop. A 9 MB plan rendered in ~9 s and produced a 97 MB fragment,
18
+ and every other API call queued behind it. The panel now falls back to the editor with a yellow
19
+ notice, a file whose byte size alone exceeds the ceiling (three UTF-8 bytes per character) is
20
+ rejected from a single `stat` without transferring it, and the last three rendered previews are
21
+ cached by content hash so re-opening a file is instant.
22
+ - Markdown opened in a **file tab** shows the document pane (preview, edit, export) instead of the bare
23
+ code editor — the same surface the directory panel already used.
24
+ - A missing KaTeX stylesheet no longer breaks the whole preview: the renderer falls back to the base
25
+ fragment with a plain `<pre>` body.
26
+ - The free-space chip in the directory header refreshes together with the tree instead of keeping the
27
+ value from the first load until the panel was reopened.
28
+ - The placeholder hand-over now polls `nativePathTabs()` every 2 s (was 1 s) and skips hidden windows,
29
+ so a background tab costs nothing.
30
+
3
31
  ## 0.27.0 — 2026-11-26
4
32
 
5
33
  - Markdown previews are rendered **inside the Host process** instead of by spawning
package/README.en.md CHANGED
@@ -77,6 +77,8 @@ Settings → Linked workspaces → *Where the last artifact opens* picks the def
77
77
  The heading shows the free space of the remote volume that holds the workspace;
78
78
  hover it for the total size and the used percentage.
79
79
 
80
+ The tree follows the remote side on its own: a file renamed or deleted in a session is relisted within seconds (the old name never lingers as a clickable ghost), the panel asks the Host for a change counter every five seconds, both trees share one four-second tick, and the refresh button really re-lists. A file tab whose target was renamed or deleted closes itself and says “that file is gone from the remote side”.
81
+
80
82
  - Fixed on the far right of the sidebar: **remote tree on top, local tree below**, both rooted at “All files”; the plugin's `.local`/`.remote` internal folders are hidden from the local tree.
81
83
  - **Single-click opens, double-click pins**: single-click a folder to expand/collapse; single-click a file to open it in the content panel, replacing the current unpinned preview. Double-click a file to pin it so later single clicks do not replace it; double-clicking a folder only keeps it expanded.
82
84
  - Toolbar (top right of the sidebar):
package/README.md CHANGED
@@ -78,6 +78,8 @@
78
78
 
79
79
  目录栏标题右侧显示该工作区所在远端卷的可用空间,悬停可看到总量与已用百分比。
80
80
 
81
+ 目录树跟着远端走,不用手动刷新:会话里改名或删除的文件,几秒内从树里换成新名字(旧名不会残留成可点的幽灵条目);面板打开时每 5 秒问一次 Host 的改动计数,远端树与本地树共用同一个 4 秒刷新节拍,「刷新目录」按钮是真正的重新列举。已经打开的文件标签在文件被改名/删除后会自己关闭,并提示「这个文件已不在远端」。
82
+
81
83
  - 面板固定在右侧栏最右边:**上方远端树,下方本地树**,两棵树根部都显示「所有文件」;本地树自动隐藏插件的 `.local`/`.remote` 内部目录。
82
84
  - **单击打开,双击固定**:单击文件夹立即展开/折叠;单击文件直接在文件内容面板打开,再次单击其他文件会替换当前未固定的预览标签。双击文件可固定该标签,之后单击其他文件不会覆盖它;双击文件夹只保持展开。
83
85
  - 工具栏(右侧栏右上角):
package/docs/API.md CHANGED
@@ -24,7 +24,7 @@ Codes: `BAD_REQUEST`, `NOT_FOUND`, `SSH_CONNECT`, `AUTH_FAILED`,
24
24
  | `docs.text` | `{ path, linkedId?, remoteId?, maxChars? }` | `{ kind, path, size, mtime, pageCount?, text, truncated }` (plain text out of PDF / Word / Excel / PowerPoint; `maxChars` is clamped to 1000–200000, default 40000) |
25
25
  | `docs.write` | `{ path, data, expectedMtime?, linkedId?, remoteId? }` | `{ kind, path, size, mtime }` |
26
26
  | `docs.create` | `{ path, kind?, linkedId?, remoteId? }` | `{ kind, path, size, mtime }` |
27
- | `docs.mdPreview` | `{ path, text?, linkedId?, remoteId? }` | `{ kind, html }` (rendered in-process; the fragment carries the KaTeX stylesheet and expects the plugin's `/dsh-linked-workspace/assets/katex/` fonts) |
27
+ | `docs.mdPreview` | `{ path, text?, linkedId?, remoteId? }` | `{ kind: 'markdown-preview', html }` (rendered in-process; the fragment carries the KaTeX stylesheet and expects the plugin's `/dsh-linked-workspace/assets/katex/` fonts; the last 3 renders are cached by content hash) or `{ kind: 'markdown-preview-too-large', chars \| bytes, limit }` for a document above 512 Ki characters — the viewer must show the editor instead |
28
28
  | `docs.mdPdf` | `{ path, text?, linkedId?, remoteId? }` | `{ kind: "pdf", path, size, mtime }` |
29
29
 
30
30
  ## Records
@@ -84,7 +84,7 @@ scope root, or absolute inside it.
84
84
  | `fs.move` | `{ linkedId?/remoteId?, path, targetDir? }` | `{ path }` (same remote tree; collision → 409) |
85
85
  | `fs.delete` | `{ linkedId?/remoteId?, path }` | `{}` |
86
86
  | `fs.home` | `{ linkedId?/remoteId? }` | `{ home }` |
87
- | `meta.info` | `{}` | `{ version, apiRevision, startedAt }` (the client warns when `apiRevision` is older than its own, i.e. DSH still runs an older copy of this plugin) |
87
+ | `meta.info` | `{}` | `{ version, apiRevision, startedAt, listings }` (the client warns when `apiRevision` is older than its own, i.e. DSH still runs an older copy of this plugin; `listings` is a counter that every mutation bumps, so the panel can notice changes made elsewhere) |
88
88
  | `settings.get` | `{}` | `{ editorTheme, editorThemeFamily, editorThemeMode, fileOpenMode, autoSave }` |
89
89
  | `settings.update` | `{ editorTheme?, editorThemeFamily?, editorThemeMode?, fileOpenMode?, autoSave? }` | `{ editorTheme, editorThemeFamily, editorThemeMode, fileOpenMode, autoSave }` |
90
90
  | `local.browse` | `{ path? }` | `{ path, parent, home, entries: [{ name, path }] }` |
package/docs/VERIFY.md CHANGED
@@ -438,3 +438,21 @@ DSH_HOME/linked-workspace/exec-audit.jsonl` 追加一行 JSON,含 `auditId`、
438
438
  3. 打开一个**本地**工作区里的文件(`D:\…`)和一个占位目录下的文件:只有后者被转交,本地文件标签原样保留、不被关闭。
439
439
  4. 占位目录下带子目录的路径(例如 `…\remote-placeholders\<uuid>\sub\notes.md`)同样转交成功;目录与无扩展名的路径不转交。
440
440
  5. 关闭并重启 DSH 后再点一次这样的链接:行为不变(首次轮询就能转交,不需要刷新页面);新建一个远程工作区后不刷新页面也能转交。
441
+
442
+ ## 目录同步与陈旧条目(Unreleased)
443
+
444
+ 1. 在会话里让 Agent 重命名或删除一个已打开的文件:5 秒内该文件的标签自己关闭,顶部提示「这个文件已不在远端(可能被重命名或删除),已关闭它的标签并刷新目录。」,目录树里旧名字消失、新名字出现,不需要手动刷新。
445
+ 2. 用插件之外的手段(例如另开一个 SSH 会话 `mv a.txt b.txt`)改名:不点任何按钮,目录树在 15 秒内自动换成新名字,旧行不会残留成可点的幽灵条目。
446
+ 3. 展开的目录里删掉一个文件后点「刷新目录」:立即重新列举(不走 15 秒节流),被删的行立刻消失。
447
+ 4. 打开一个文件后,在另一个会话里改名,再切回本会话:面板里的旧标签已关闭、树是新名字,不会出现「点开就报 `lstat … No such file`」的死标签。
448
+ 5. 侧边栏的独立文件标签(`远程文件`)在文件被改名后 10 秒内自动关闭。
449
+ 6. 目录树没有打开的标签页时,不会因为刷新而产生任何多余请求(关掉面板后 `listings` 轮询应停止)。
450
+
451
+ ## 预览体积、文件标签与刷新(Unreleased)
452
+
453
+ 1. 在目录树里点开一个**超过 51.2 万字符**的 Markdown(例如几 MB 的计划文档):面板顶部出现黄色提示「这个文件太大(N 字符,上限 524288),没有生成预览…」,正文退回编辑器(可编辑、可保存),不出现空白预览。
454
+ 2. 用浏览器开发者工具观察该请求:`docs.mdPreview` 的返回是 `{ kind: 'markdown-preview-too-large', ... }`,**几毫秒内**就回来(不传输整个文件),期间目录列表、保存、传输进度等其它操作不被卡住。
455
+ 3. 同一个正常大小的 Markdown 连续打开两次:第二次明显更快(Host 侧按内容哈希缓存最近 3 份预览),两次渲染结果必须完全一致。
456
+ 4. 在**文件标签页**里打开一个 Markdown(例如从聊天里的占位路径链接转交过来的那份):应出现文档面板的工具栏(MARKDOWN 徽标 + 预览 / 导出 PDF / 保存),而不是只有代码编辑器;点「编辑」可改、可保存。
457
+ 5. 目录栏标题右侧的可用空间芯片:点「刷新目录」后它的 title(可用 / 已用 / 总量)随之更新,不再永远停在首次打开面板时的数值。
458
+ 6. 把窗口最小化或切到别的应用 30 秒再回来:占位目录转交仍在工作(后台不轮询、回到前台立刻补一次),并且这段时间没有产生额外的网络请求。
package/lib/client.js CHANGED
@@ -2657,6 +2657,9 @@ function katexStyleViolation(value) {
2657
2657
  docPageOf: '第 {page} / {total} 页',
2658
2658
  docExportDone: '已导出 PDF:{path}',
2659
2659
  docPreviewFailed: '预览失败',
2660
+ previewTooLarge: '这个文件太大({{chars}} 字符,上限 {{limit}}),没有生成预览;可以在编辑器里查看,或下载后用别的工具打开。',
2661
+ previewTooLargeBytes: '这个文件太大({{bytes}}),没有生成预览;可以在编辑器里查看,或下载后用别的工具打开。',
2662
+ fileGone: '这个文件已不在远端(可能被重命名或删除),已关闭它的标签并刷新目录。',
2660
2663
  linkedTitle: '联动工作区',
2661
2664
  linkedHint: '本地目录与远端目录成对出现:DSH 会话在该本地目录中工作,并通过 linked_workspace 工具直接编辑远端文件。',
2662
2665
  localFlow: '本地目录',
@@ -3258,6 +3261,9 @@ function katexStyleViolation(value) {
3258
3261
  docPageOf: 'Page {page} / {total}',
3259
3262
  docExportDone: 'Exported PDF: {path}',
3260
3263
  docPreviewFailed: 'Preview failed',
3264
+ previewTooLarge: 'Too large to preview ({{chars}} characters, the ceiling is {{limit}}). Read it in the editor, or download it and open it elsewhere.',
3265
+ previewTooLargeBytes: 'Too large to preview ({{bytes}}). Read it in the editor, or download it and open it elsewhere.',
3266
+ fileGone: 'That file is gone from the remote side (renamed or deleted). Closed its tab and refreshed the tree.',
3261
3267
  linkedTitle: 'Linked workspaces',
3262
3268
  linkedHint: 'A local folder paired with a remote folder: DSH sessions work in the local folder and edit remote files through the linked_workspace tool.',
3263
3269
  localFlow: 'Local folder',
@@ -3642,7 +3648,7 @@ function katexStyleViolation(value) {
3642
3648
  * Host methods the running DSH process does not have yet, the directory
3643
3649
  * pane says so instead of surfacing an unrelated error.
3644
3650
  */
3645
- var HOST_API_REVISION = 14;
3651
+ var HOST_API_REVISION = 15;
3646
3652
  var hostInfoProbe = null;
3647
3653
 
3648
3654
  function probeHostInfo() {
@@ -5871,6 +5877,7 @@ function katexStyleViolation(value) {
5871
5877
  setSave({ saving: false, conflict: false, error: '', ok: false });
5872
5878
  }).catch(function (error) {
5873
5879
  setLoad({ loading: false, error: error, file: null });
5880
+ if (error && error.code === 'FS_NOT_FOUND' && typeof props.onMissing === 'function') props.onMissing(props.path);
5874
5881
  });
5875
5882
  }, [scopeKeyOf(scope), filePath, local]);
5876
5883
 
@@ -6426,6 +6433,17 @@ function katexStyleViolation(value) {
6426
6433
  });
6427
6434
  }, [props.refreshTick]);
6428
6435
 
6436
+ // An explicit refresh (the toolbar button, or a mutation this panel did
6437
+ // not make) must not trust the listing remembered from a previous mount:
6438
+ // the cache is dropped and every expanded directory is read again,
6439
+ // bypassing the REFRESH_MIN_INTERVAL_MS throttle the background tick obeys.
6440
+ useEffect(function () {
6441
+ if (!props.forceTick) return;
6442
+ pending.current.clear();
6443
+ lastRefreshAt.current.clear();
6444
+ setCache({ entries: new Map() });
6445
+ }, [props.forceTick]);
6446
+
6429
6447
  function toggle(path) {
6430
6448
  setExpanded(function (previous) {
6431
6449
  var next = new Set(previous);
@@ -6472,7 +6490,13 @@ function katexStyleViolation(value) {
6472
6490
  var freshPaths = new Set(fresh.map(function (entry) { return entry.path; }));
6473
6491
  // Keep rows beyond the refreshed page so a silent refresh cannot
6474
6492
  // shrink a list the user scrolled many pages into.
6475
- var retained = silent
6493
+ // A silent refresh asks for at least as many rows as were already
6494
+ // loaded, so the page it gets back is authoritative: a row that
6495
+ // disappeared because the file was renamed or deleted elsewhere has
6496
+ // to go, or it lingers as a phantom that fails with ENOENT when the
6497
+ // user clicks it.
6498
+ var previousRaw = Number(existing.raw) || 0;
6499
+ var retained = silent && previousRaw > pageRaw
6476
6500
  ? (existing.entries || []).filter(function (entry) { return !freshPaths.has(entry.path); })
6477
6501
  : [];
6478
6502
  var pageRaw = (result.entries || []).length;
@@ -7721,7 +7745,7 @@ function rememberShowHidden(value) {
7721
7745
  page: rememberedView ? Number(rememberedView.page) || 0 : 0,
7722
7746
  sheet: rememberedView ? Number(rememberedView.sheet) || 0 : 0,
7723
7747
  slide: rememberedView ? Number(rememberedView.slide) || 0 : 0,
7724
- updates: {}, pptxUpdates: {}, rotations: {}, deleted: {}, pdfLoading: false, notice: '',
7748
+ updates: {}, pptxUpdates: {}, rotations: {}, deleted: {}, pdfLoading: false, notice: '', warn: '',
7725
7749
  findOpen: false, findQuery: '', findIndex: 0,
7726
7750
  });
7727
7751
  var state = stateRef[0];
@@ -7734,13 +7758,29 @@ function rememberShowHidden(value) {
7734
7758
  setState(function (previous) { return Object.assign({}, previous, next); });
7735
7759
  }
7736
7760
 
7761
+ // D1: the Host refuses to render a document above its preview ceiling and
7762
+ // answers with a typed result; drop to the editor and say why.
7763
+ function applyPreviewResult(result) {
7764
+ if (result && result.kind === 'markdown-preview-too-large') {
7765
+ patch({
7766
+ preview: false, previewLoading: false, html: '', css: '',
7767
+ warn: result.bytes
7768
+ ? t('previewTooLargeBytes', { bytes: formatBytes(result.bytes) })
7769
+ : t('previewTooLarge', { chars: String(result.chars), limit: String(result.limit) }),
7770
+ });
7771
+ return;
7772
+ }
7773
+ var clean = sanitizeDocumentHtml(result.html);
7774
+ patch({ previewLoading: false, html: clean.html, css: clean.css });
7775
+ }
7776
+
7737
7777
  function params(extra) {
7738
7778
  var base = local ? { path: path } : Object.assign({ path: path }, scopeParams(scope));
7739
7779
  return Object.assign(base, extra || {});
7740
7780
  }
7741
7781
 
7742
7782
  function load() {
7743
- patch({ loading: true, error: '', notice: '' });
7783
+ patch({ loading: true, error: '', notice: '', warn: '' });
7744
7784
  apiCall('docs.read', params()).then(function (result) {
7745
7785
  var remembered = recallView(viewKey);
7746
7786
  patch({
@@ -7755,6 +7795,9 @@ function rememberShowHidden(value) {
7755
7795
  });
7756
7796
  }).catch(function (error) {
7757
7797
  patch({ loading: false, error: messageOf(error, t, locale) });
7798
+ // The path no longer exists: say so once and let the panel drop the tab
7799
+ // rather than reopening it on every mount.
7800
+ if (error && error.code === 'FS_NOT_FOUND' && typeof props.onMissing === 'function') props.onMissing(path);
7758
7801
  });
7759
7802
  }
7760
7803
 
@@ -7787,8 +7830,7 @@ function rememberShowHidden(value) {
7787
7830
  if (state.loading || !state.preview || kind !== 'markdown' || state.html || state.previewLoading) return;
7788
7831
  patch({ previewLoading: true });
7789
7832
  apiCall('docs.mdPreview', params({ text: state.text })).then(function (result) {
7790
- var clean = sanitizeDocumentHtml(result.html);
7791
- patch({ previewLoading: false, html: clean.html, css: clean.css });
7833
+ applyPreviewResult(result);
7792
7834
  }).catch(function (error) {
7793
7835
  patch({ previewLoading: false, error: messageOf(error, t, locale) });
7794
7836
  });
@@ -7902,11 +7944,10 @@ function rememberShowHidden(value) {
7902
7944
 
7903
7945
  function showPreview() {
7904
7946
  var next = !state.preview;
7905
- patch({ preview: next, previewLoading: next && !state.html });
7947
+ patch({ preview: next, previewLoading: next && !state.html, warn: '' });
7906
7948
  if (!next || state.html) return;
7907
7949
  apiCall('docs.mdPreview', params({ text: state.text })).then(function (result) {
7908
- var clean = sanitizeDocumentHtml(result.html);
7909
- patch({ previewLoading: false, html: clean.html, css: clean.css });
7950
+ applyPreviewResult(result);
7910
7951
  }).catch(function (error) {
7911
7952
  patch({ previewLoading: false, error: messageOf(error, t, locale) });
7912
7953
  });
@@ -8122,6 +8163,7 @@ function rememberShowHidden(value) {
8122
8163
  return h('div', { className: 'rw-doc' }, toolbar,
8123
8164
  state.notice ? h('div', { style: { padding: '6px 10px 0' } }, h(Banner, { kind: 'success' }, state.notice)) : null,
8124
8165
  state.error ? h('div', { style: { padding: '6px 10px 0' } }, h(Banner, { kind: 'error' }, state.error)) : null,
8166
+ state.warn ? h('div', { style: { padding: '6px 10px 0' } }, h(Banner, { kind: 'warn', onClose: function () { patch({ warn: '' }); } }, state.warn)) : null,
8125
8167
  body,
8126
8168
  h('div', { className: 'rw-doc-status' },
8127
8169
  h('span', null, kind.toUpperCase()),
@@ -8342,8 +8384,9 @@ function rememberShowHidden(value) {
8342
8384
 
8343
8385
  var scopeRef = selected ? sourceScopeOf(selected) : null;
8344
8386
 
8345
- // Free space on the remote volume (F2): fetched once per workspace and
8346
- // refreshed when the tree is refreshed. Cheap enough to keep on screen.
8387
+ // Free space on the remote volume: fetched once per workspace and again
8388
+ // whenever the tree refreshes (`version` bumps inside refreshTree()), so
8389
+ // the number does not go stale while the panel stays open (D4).
8347
8390
  var diskState = useState(null);
8348
8391
  var disk = diskState[0];
8349
8392
  var setDisk = diskState[1];
@@ -8356,7 +8399,7 @@ function rememberShowHidden(value) {
8356
8399
  if (alive) setDisk(result && result.disk ? result.disk : null);
8357
8400
  }).catch(function () { if (alive) setDisk(null); });
8358
8401
  return function () { alive = false; };
8359
- }, [diskHostId, diskPath]);
8402
+ }, [diskHostId, diskPath, version]);
8360
8403
 
8361
8404
  // autoPush is host-side and silent, so surface it here: the per-workspace
8362
8405
  // switch state (0.24.0) plus the newest push from the transfer history.
@@ -8424,6 +8467,9 @@ function rememberShowHidden(value) {
8424
8467
  var localTickState = useState(0);
8425
8468
  var localTick = localTickState[0];
8426
8469
  var setLocalTick = localTickState[1];
8470
+ var treeForceState = useState(0);
8471
+ var treeForceTick = treeForceState[0];
8472
+ var setTreeForceTick = treeForceState[1];
8427
8473
  var fileDirtyState = useState({});
8428
8474
  var fileDirty = fileDirtyState[0];
8429
8475
  var setFileDirty = fileDirtyState[1];
@@ -8464,6 +8510,25 @@ function rememberShowHidden(value) {
8464
8510
  };
8465
8511
  }, [directoryOpen, selectedKey]);
8466
8512
 
8513
+ // A rename or delete made anywhere else (an agent session, another window)
8514
+ // bumps the Host's listings counter. Following it keeps the tree honest
8515
+ // without polling every directory: meta.info answers from memory, no SSH.
8516
+ useEffect(function () {
8517
+ if (!directoryOpen) return undefined;
8518
+ var last = null;
8519
+ var timer = setInterval(function () {
8520
+ if (typeof document !== 'undefined' && document.visibilityState === 'hidden') return;
8521
+ apiCall('meta.info', {}).then(function (info) {
8522
+ var value = info && typeof info.listings === 'number' ? info.listings : null;
8523
+ if (value === null) return; // older Host without the counter
8524
+ if (last === null) { last = value; return; }
8525
+ if (value !== last) { last = value; forceRefreshTrees(); }
8526
+ }).catch(function () { /* meta.info is best effort */ });
8527
+ }, 5000);
8528
+ if (timer && typeof timer.unref === 'function') timer.unref();
8529
+ return function () { clearInterval(timer); };
8530
+ }, [directoryOpen]);
8531
+
8467
8532
  function beginResize(event) {
8468
8533
  if (event.button !== undefined && event.button !== 0) return;
8469
8534
  event.preventDefault();
@@ -8508,13 +8573,23 @@ function rememberShowHidden(value) {
8508
8573
  noticeTimer.current = setTimeout(function () { setNotice(null); }, 4200);
8509
8574
  }
8510
8575
 
8576
+ // Everything that changes the tree comes through here: the toolbar button,
8577
+ // every mutation this panel makes, and the listings counter below. Bumping
8578
+ // the tree epoch drops the remembered listings first, so a rename made in
8579
+ // another session cannot leave a phantom row behind.
8580
+ function forceRefreshTrees() {
8581
+ setTreeForceTick(function (value) { return value + 1; });
8582
+ }
8583
+
8511
8584
  function refreshAll() {
8585
+ forceRefreshTrees();
8512
8586
  bumpVersion(function (value) { return value + 1; });
8513
8587
  data.reload();
8514
8588
  }
8515
8589
 
8516
8590
  function refreshTree() {
8517
8591
  clearStaleError();
8592
+ forceRefreshTrees();
8518
8593
  bumpVersion(function (value) { return value + 1; });
8519
8594
  data.reload();
8520
8595
  }
@@ -8630,6 +8705,62 @@ function rememberShowHidden(value) {
8630
8705
  setDirectoryOpen(true);
8631
8706
  }
8632
8707
 
8708
+ // A file read came back FS_NOT_FOUND: the tab was restored from a listing
8709
+ // that has since changed. Close it and re-read the tree instead of leaving
8710
+ // a tab that can only fail.
8711
+ function dropOpenFile(side, filePath) {
8712
+ var key = side + ':' + (side === 'remote' ? scopeKeyOf(scopeRef) : 'local') + ':' + filePath;
8713
+ setOpenFiles(function (previous) {
8714
+ return previous.filter(function (file) { return file.key !== key; });
8715
+ });
8716
+ setFileDirty(function (dirtyMap) {
8717
+ if (!dirtyMap[key]) return dirtyMap;
8718
+ var copy = Object.assign({}, dirtyMap);
8719
+ delete copy[key];
8720
+ return copy;
8721
+ });
8722
+ showNotice('info', t('fileGone'));
8723
+ forceRefreshTrees();
8724
+ }
8725
+
8726
+ // A pane tab keeps its file open for the whole session, so a rename on the
8727
+ // other side leaves it pointing at a path that no longer exists (the
8728
+ // 0.27.1 report: the tree still listed the old name and clicking it opened
8729
+ // a tab that could only fail with lstat). Re-stat the open pane files
8730
+ // whenever the trees are force-refreshed and drop the ones that are gone,
8731
+ // so the panel heals itself instead of waiting for a read to fail.
8732
+ var openFileKeys = openFiles.map(function (file) { return file.key; }).join('|');
8733
+ var staleProbeRef = useRef(0);
8734
+ function probeOpenFiles() {
8735
+ var cancelled = false;
8736
+ openFiles.forEach(function (file) {
8737
+ var probe = file.side === 'local'
8738
+ ? apiCall('local.stat', { path: file.path })
8739
+ : (selected ? apiCall('fs.stat', Object.assign({}, scopeParams(selected), { path: file.path })) : null);
8740
+ if (!probe) return;
8741
+ probe.then(function () { return null; }, function (error) {
8742
+ if (cancelled || !error || error.code !== 'FS_NOT_FOUND') return;
8743
+ dropOpenFile(file.side, file.path);
8744
+ });
8745
+ });
8746
+ return function () { cancelled = true; };
8747
+ }
8748
+ // A mutation made through the plugin (or the refresh button) is worth an
8749
+ // immediate check; an outside change only needs to be caught eventually, so
8750
+ // the periodic tree tick is throttled to keep the host quiet.
8751
+ useEffect(function () {
8752
+ if (!treeForceTick || openFiles.length === 0) return undefined;
8753
+ staleProbeRef.current = Date.now();
8754
+ return probeOpenFiles();
8755
+ }, [treeForceTick, openFileKeys]);
8756
+ useEffect(function () {
8757
+ if (!localTick || openFiles.length === 0) return undefined;
8758
+ var now = Date.now();
8759
+ if (now - staleProbeRef.current < 10000) return undefined;
8760
+ staleProbeRef.current = now;
8761
+ return probeOpenFiles();
8762
+ }, [localTick, openFileKeys]);
8763
+
8633
8764
  function closeInternalFile(key) {
8634
8765
  setOpenFiles(function (previous) {
8635
8766
  var next = previous.filter(function (file) { return file.key !== key; });
@@ -9891,6 +10022,8 @@ function rememberShowHidden(value) {
9891
10022
  onDropOnPath: dropOnPath,
9892
10023
  onSelect: function (filePath) { openByMode('remote', filePath, { pinned: false, preview: true }); },
9893
10024
  onPin: function (filePath) { pinByMode('remote', filePath); },
10025
+ refreshTick: localTick,
10026
+ forceTick: treeForceTick,
9894
10027
  onContextMenu: function (info) { setSelectedEntry(Object.assign({ side: 'remote' }, info)); openContextMenu('remote', info); },
9895
10028
  })),
9896
10029
  selected.kind === 'linked'
@@ -9917,6 +10050,7 @@ function rememberShowHidden(value) {
9917
10050
  onSelect: function (filePath) { openByMode('local', filePath, { pinned: false, preview: true }); },
9918
10051
  onPin: function (filePath) { pinByMode('local', filePath); },
9919
10052
  refreshTick: localTick,
10053
+ forceTick: treeForceTick,
9920
10054
  onContextMenu: function (info) { setSelectedEntry(Object.assign({ side: 'local' }, info)); openContextMenu('local', info); },
9921
10055
  }))
9922
10056
  : null);
@@ -9950,6 +10084,7 @@ function rememberShowHidden(value) {
9950
10084
  path: activeFile.path,
9951
10085
  local: activeFile.side === 'local',
9952
10086
  onSaved: refreshTree,
10087
+ onMissing: function (filePath) { dropOpenFile(activeFile.side, filePath); },
9953
10088
  onSaveReady: function (handler) {
9954
10089
  if (handler) saveHandlersRef.current[activeFile.key] = handler;
9955
10090
  else delete saveHandlersRef.current[activeFile.key];
@@ -9971,6 +10106,7 @@ function rememberShowHidden(value) {
9971
10106
  hideHeader: true,
9972
10107
  focusLine: activeFile.line || 0,
9973
10108
  hitQuery: searchQuery,
10109
+ onMissing: function (filePath) { dropOpenFile(activeFile.side, filePath); },
9974
10110
  onSaveReady: function (handler) {
9975
10111
  if (handler) saveHandlersRef.current[activeFile.key] = handler;
9976
10112
  else delete saveHandlersRef.current[activeFile.key];
@@ -10231,15 +10367,50 @@ function rememberShowHidden(value) {
10231
10367
  ? { kind: 'remote', id: meta.remoteId }
10232
10368
  : { kind: 'workspace', id: meta.workspaceId };
10233
10369
  var filePath = tab && tab.path ? tab.path : '';
10234
- return h('div', { className: 'rw-editor-pane' },
10235
- h(RemoteFileEditor, {
10236
- ctx: ctx, t: t, locale: locale,
10237
- scope: scope,
10238
- path: filePath,
10239
- visible: props.visible !== false,
10240
- tabId: tab ? tab.id : undefined,
10241
- sessionId: props.scope ? props.scope.sessionId : undefined,
10242
- }));
10370
+ var visible = props.visible !== false;
10371
+ // D2: this tab used to be a plain code editor only, so the same Markdown
10372
+ // opened here (placeholder paths, references) had no preview while the
10373
+ // very same file opened in the directory panel did. Mirror that dispatch.
10374
+ var docKind = documentKindOf(filePath);
10375
+ // A file tab whose target vanished closes itself; the panel that opened it
10376
+ // is gone, so the sidebar is the only thing that can reclaim the tab.
10377
+ function closeSelf() {
10378
+ try {
10379
+ var service = sidebarService(ctx);
10380
+ if (service && typeof service.closeTab === 'function' && tab && tab.id) service.closeTab(tab.id, props.scope);
10381
+ } catch (error) { /* no sidebar attached */ }
10382
+ }
10383
+ // A sidebar tab outlives the panel that opened it, so nothing else ever
10384
+ // re-reads this file: probe it now and then and reclaim the tab once the
10385
+ // path is gone (a rename inside a session is the usual cause).
10386
+ useEffect(function () {
10387
+ var cancelled = false;
10388
+ var timer = setInterval(function () {
10389
+ if (typeof document !== 'undefined' && document.visibilityState === 'hidden') return;
10390
+ apiCall('fs.stat', Object.assign({ path: filePath }, scopeParams(scope))).then(function () { return null; }, function (error) {
10391
+ if (cancelled || !error || error.code !== 'FS_NOT_FOUND') return;
10392
+ closeSelf();
10393
+ });
10394
+ }, 10000);
10395
+ return function () { cancelled = true; clearInterval(timer); };
10396
+ }, [filePath, scope.kind, scope.id]);
10397
+
10398
+ var pane = docKind === 'image'
10399
+ ? h(ImagePreview, { ctx: ctx, t: t, locale: locale, scope: scope, path: filePath, local: false })
10400
+ : docKind === 'html'
10401
+ ? h(HtmlPreview, { ctx: ctx, t: t, locale: locale, scope: scope, path: filePath, local: false })
10402
+ : docKind && docKind !== 'csv'
10403
+ ? h(DocumentPane, { ctx: ctx, t: t, locale: locale, scope: scope, path: filePath, local: false, visible: visible, onMissing: closeSelf })
10404
+ : h(RemoteFileEditor, {
10405
+ ctx: ctx, t: t, locale: locale,
10406
+ scope: scope,
10407
+ path: filePath,
10408
+ visible: visible,
10409
+ tabId: tab ? tab.id : undefined,
10410
+ sessionId: props.scope ? props.scope.sessionId : undefined,
10411
+ onMissing: closeSelf,
10412
+ });
10413
+ return h('div', { className: 'rw-editor-pane' }, pane);
10243
10414
  }
10244
10415
 
10245
10416
  // ── tree ───────────────────────────────────────────────────────────────
@@ -13148,6 +13319,9 @@ function rememberShowHidden(value) {
13148
13319
 
13149
13320
  function scan() {
13150
13321
  if (scanning) return;
13322
+ // F1: a hidden window cannot be looking at a file, so do not poll for
13323
+ // nothing — the visibility handler below catches up on return.
13324
+ if (typeof document !== 'undefined' && document.visibilityState === 'hidden') return;
13151
13325
  scanning = true;
13152
13326
  try {
13153
13327
  var tabs = sidebar.nativePathTabs() || [];
@@ -13166,10 +13340,17 @@ function rememberShowHidden(value) {
13166
13340
  // test, so a tick costs nothing when nothing is open.
13167
13341
  ctx.effect(function () {
13168
13342
  var stop = sidebar.subscribeState(scan);
13169
- var timer = setInterval(scan, 1000);
13343
+ var timer = setInterval(scan, 2000);
13344
+ // A hand-over skipped while the window was hidden has to happen as soon
13345
+ // as it is back, otherwise the click looks like it did nothing.
13346
+ function onVisibility() {
13347
+ if (typeof document !== 'undefined' && document.visibilityState === 'visible') scan();
13348
+ }
13349
+ if (typeof document !== 'undefined') document.addEventListener('visibilitychange', onVisibility);
13170
13350
  return function () {
13171
13351
  try { stop(); } catch (error) { /* already disposed */ }
13172
13352
  clearInterval(timer);
13353
+ if (typeof document !== 'undefined') document.removeEventListener('visibilitychange', onVisibility);
13173
13354
  };
13174
13355
  }, 'dsh-linked-workspace: placeholder hand-over');
13175
13356
  }
package/lib/index.js CHANGED
@@ -41,7 +41,7 @@ export const inject = ['webServer', 'tools', 'systemPrompt', 'workingDirectory']
41
41
  * is still running an older copy of the Host — refreshing the page only swaps
42
42
  * the browser bundle, so the two halves can drift by one restart.
43
43
  */
44
- const API_REVISION = 14
44
+ const API_REVISION = 15
45
45
 
46
46
  /** When this copy of the Host was loaded; shown by `meta.info`. */
47
47
  const STARTED_AT = new Date().toISOString()
@@ -195,7 +195,14 @@ const rememberListing = (key, listing) => {
195
195
  listingCache.delete(listingCache.keys().next().value)
196
196
  }
197
197
  }
198
- const forgetListings = () => listingCache.clear()
198
+ // Every mutation clears the cache; the counter lets the client notice that a
199
+ // listing changed underneath it (a rename made by an agent session, an upload
200
+ // from another window) without having to poll the tree itself.
201
+ let listingsGeneration = 0
202
+ const forgetListings = () => {
203
+ listingsGeneration += 1
204
+ listingCache.clear()
205
+ }
199
206
 
200
207
  /** Clamp a requested page window to the listing limits. */
201
208
  const pageWindow = (params = {}, total = 0) => {
@@ -2619,6 +2626,13 @@ export function apply(ctx) {
2619
2626
  // ── document bridge (Markdown/PDF/DOCX/XLSX/PPTX) ──────────────────────
2620
2627
 
2621
2628
  const DOC_MAX_BYTES = 80 * 1024 * 1024
2629
+ // A Markdown preview is rendered synchronously on the Host event loop, so an
2630
+ // unbounded document freezes every other API call for as long as it takes
2631
+ // (9 MB of formula-heavy text measured ~9 s and produced a 97 MB fragment).
2632
+ // Above this ceiling the client drops to the text editor instead.
2633
+ const PREVIEW_MAX_CHARS = 512 * 1024
2634
+ const PREVIEW_CACHE_LIMIT = 3
2635
+ const previewCache = new Map()
2622
2636
  const DOC_PDF_SUFFIX_MAX = 999
2623
2637
  const DOC_TOOL = join(dirname(fileURLToPath(import.meta.url)), '..', 'scripts', 'doc_tool.py')
2624
2638
  const DOC_KIND_BY_EXT = new Map([
@@ -3917,6 +3931,13 @@ export function apply(ctx) {
3917
3931
  assertDocKind(target.path, 'markdown')
3918
3932
  let text = typeof params.text === 'string' ? params.text : null
3919
3933
  if (text === null) {
3934
+ // Do not ship a document the preview would refuse anyway: UTF-8 needs
3935
+ // at most three bytes per character in the BMP, so a file above 3x the
3936
+ // ceiling cannot fit. One stat beats a pointless transfer.
3937
+ const info = await docStat(target)
3938
+ if (Number(info.size) > PREVIEW_MAX_CHARS * 3) {
3939
+ return { kind: 'markdown-preview-too-large', bytes: Number(info.size), limit: PREVIEW_MAX_CHARS }
3940
+ }
3920
3941
  const current = await readDocBytes(target, target)
3921
3942
  text = decodeUtf8(current.data)
3922
3943
  }
@@ -3924,7 +3945,28 @@ export function apply(ctx) {
3924
3945
  // to `node scripts/md-to-html.mjs`, and a DSH process without `node` on its
3925
3946
  // PATH silently fell back to a plain renderer — every formula came out as
3926
3947
  // raw `$$…$$` text.
3927
- return { kind: 'markdown-preview', html: renderMarkdownFragment(text) }
3948
+ // D1: never render an unbounded document on the event loop. The caller
3949
+ // turns this answer into "too large — showing the editor".
3950
+ if (text.length > PREVIEW_MAX_CHARS) {
3951
+ return { kind: 'markdown-preview-too-large', chars: text.length, limit: PREVIEW_MAX_CHARS }
3952
+ }
3953
+ // F2: keep the last few previews. The key is the text itself, because the
3954
+ // caller may send unsaved text, in which case path + mtime would be stale.
3955
+ const cacheKey = createHash('sha1').update(text).digest('hex')
3956
+ const cached = previewCache.get(cacheKey)
3957
+ if (typeof cached === 'string') {
3958
+ previewCache.delete(cacheKey)
3959
+ previewCache.set(cacheKey, cached)
3960
+ return { kind: 'markdown-preview', html: cached }
3961
+ }
3962
+ const html = renderMarkdownFragment(text)
3963
+ previewCache.set(cacheKey, html)
3964
+ while (previewCache.size > PREVIEW_CACHE_LIMIT) {
3965
+ const oldest = previewCache.keys().next()
3966
+ if (oldest.done) break
3967
+ previewCache.delete(oldest.value)
3968
+ }
3969
+ return { kind: 'markdown-preview', html }
3928
3970
  },
3929
3971
 
3930
3972
  async 'docs.mdPdf'(params = {}) {
@@ -4265,6 +4307,7 @@ export function apply(ctx) {
4265
4307
  apiRevision: API_REVISION,
4266
4308
  startedAt: STARTED_AT,
4267
4309
  execAuditFile: join(dir, EXEC_AUDIT_NAME),
4310
+ listings: listingsGeneration,
4268
4311
  }
4269
4312
  },
4270
4313
 
package/lib/markdown.js CHANGED
@@ -70,9 +70,17 @@ export function renderMarkdownFragment(markdown) {
70
70
  // Only KaTeX rules live in the fragment: they are namespaced under .katex*,
71
71
  // so inserting them into the host page cannot restyle the app itself. The
72
72
  // handful of layout tweaks below are scoped to the preview container.
73
+ // D3: a missing or broken `katex` package must degrade to unstyled maths,
74
+ // not turn the whole preview into an INTERNAL error.
75
+ let css = '';
76
+ try {
77
+ css = katexCss();
78
+ } catch (error) {
79
+ css = '';
80
+ }
73
81
  const html = [
74
82
  '<style data-rw-katex="1">',
75
- katexCss(),
83
+ css,
76
84
  '.rw-doc-preview .katex{font-size:1.05em}',
77
85
  '.rw-doc-preview .katex-display{overflow-x:auto;overflow-y:hidden;margin:1.1em 0;padding:2px 0}',
78
86
  // Keep KaTeX's own block layout: the equation number (`\tag`) is absolutely
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-linked-workspace",
3
- "version": "0.27.0",
3
+ "version": "0.28.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",