dsh-linked-workspace 0.27.0 → 0.27.1

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,22 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.27.1 — 2026-11-26
4
+
5
+ - Markdown previews **refuse documents above 512 Ki characters** instead of rendering them
6
+ synchronously on the Host's event loop. A 9 MB plan rendered in ~9 s and produced a 97 MB fragment,
7
+ and every other API call queued behind it. The panel now falls back to the editor with a yellow
8
+ notice, a file whose byte size alone exceeds the ceiling (three UTF-8 bytes per character) is
9
+ rejected from a single `stat` without transferring it, and the last three rendered previews are
10
+ cached by content hash so re-opening a file is instant.
11
+ - Markdown opened in a **file tab** shows the document pane (preview, edit, export) instead of the bare
12
+ code editor — the same surface the directory panel already used.
13
+ - A missing KaTeX stylesheet no longer breaks the whole preview: the renderer falls back to the base
14
+ fragment with a plain `<pre>` body.
15
+ - The free-space chip in the directory header refreshes together with the tree instead of keeping the
16
+ value from the first load until the panel was reopened.
17
+ - The placeholder hand-over now polls `nativePathTabs()` every 2 s (was 1 s) and skips hidden windows,
18
+ so a background tab costs nothing.
19
+
3
20
  ## 0.27.0 — 2026-11-26
4
21
 
5
22
  - Markdown previews are rendered **inside the Host process** instead of by spawning
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
package/docs/VERIFY.md CHANGED
@@ -438,3 +438,12 @@ 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. 在目录树里点开一个**超过 51.2 万字符**的 Markdown(例如几 MB 的计划文档):面板顶部出现黄色提示「这个文件太大(N 字符,上限 524288),没有生成预览…」,正文退回编辑器(可编辑、可保存),不出现空白预览。
445
+ 2. 用浏览器开发者工具观察该请求:`docs.mdPreview` 的返回是 `{ kind: 'markdown-preview-too-large', ... }`,**几毫秒内**就回来(不传输整个文件),期间目录列表、保存、传输进度等其它操作不被卡住。
446
+ 3. 同一个正常大小的 Markdown 连续打开两次:第二次明显更快(Host 侧按内容哈希缓存最近 3 份预览),两次渲染结果必须完全一致。
447
+ 4. 在**文件标签页**里打开一个 Markdown(例如从聊天里的占位路径链接转交过来的那份):应出现文档面板的工具栏(MARKDOWN 徽标 + 预览 / 导出 PDF / 保存),而不是只有代码编辑器;点「编辑」可改、可保存。
448
+ 5. 目录栏标题右侧的可用空间芯片:点「刷新目录」后它的 title(可用 / 已用 / 总量)随之更新,不再永远停在首次打开面板时的数值。
449
+ 6. 把窗口最小化或切到别的应用 30 秒再回来:占位目录转交仍在工作(后台不轮询、回到前台立刻补一次),并且这段时间没有产生额外的网络请求。
package/lib/client.js CHANGED
@@ -2657,6 +2657,8 @@ function katexStyleViolation(value) {
2657
2657
  docPageOf: '第 {page} / {total} 页',
2658
2658
  docExportDone: '已导出 PDF:{path}',
2659
2659
  docPreviewFailed: '预览失败',
2660
+ previewTooLarge: '这个文件太大({{chars}} 字符,上限 {{limit}}),没有生成预览;可以在编辑器里查看,或下载后用别的工具打开。',
2661
+ previewTooLargeBytes: '这个文件太大({{bytes}}),没有生成预览;可以在编辑器里查看,或下载后用别的工具打开。',
2660
2662
  linkedTitle: '联动工作区',
2661
2663
  linkedHint: '本地目录与远端目录成对出现:DSH 会话在该本地目录中工作,并通过 linked_workspace 工具直接编辑远端文件。',
2662
2664
  localFlow: '本地目录',
@@ -3258,6 +3260,8 @@ function katexStyleViolation(value) {
3258
3260
  docPageOf: 'Page {page} / {total}',
3259
3261
  docExportDone: 'Exported PDF: {path}',
3260
3262
  docPreviewFailed: 'Preview failed',
3263
+ previewTooLarge: 'Too large to preview ({{chars}} characters, the ceiling is {{limit}}). Read it in the editor, or download it and open it elsewhere.',
3264
+ previewTooLargeBytes: 'Too large to preview ({{bytes}}). Read it in the editor, or download it and open it elsewhere.',
3261
3265
  linkedTitle: 'Linked workspaces',
3262
3266
  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
3267
  localFlow: 'Local folder',
@@ -7721,7 +7725,7 @@ function rememberShowHidden(value) {
7721
7725
  page: rememberedView ? Number(rememberedView.page) || 0 : 0,
7722
7726
  sheet: rememberedView ? Number(rememberedView.sheet) || 0 : 0,
7723
7727
  slide: rememberedView ? Number(rememberedView.slide) || 0 : 0,
7724
- updates: {}, pptxUpdates: {}, rotations: {}, deleted: {}, pdfLoading: false, notice: '',
7728
+ updates: {}, pptxUpdates: {}, rotations: {}, deleted: {}, pdfLoading: false, notice: '', warn: '',
7725
7729
  findOpen: false, findQuery: '', findIndex: 0,
7726
7730
  });
7727
7731
  var state = stateRef[0];
@@ -7734,13 +7738,29 @@ function rememberShowHidden(value) {
7734
7738
  setState(function (previous) { return Object.assign({}, previous, next); });
7735
7739
  }
7736
7740
 
7741
+ // D1: the Host refuses to render a document above its preview ceiling and
7742
+ // answers with a typed result; drop to the editor and say why.
7743
+ function applyPreviewResult(result) {
7744
+ if (result && result.kind === 'markdown-preview-too-large') {
7745
+ patch({
7746
+ preview: false, previewLoading: false, html: '', css: '',
7747
+ warn: result.bytes
7748
+ ? t('previewTooLargeBytes', { bytes: formatBytes(result.bytes) })
7749
+ : t('previewTooLarge', { chars: String(result.chars), limit: String(result.limit) }),
7750
+ });
7751
+ return;
7752
+ }
7753
+ var clean = sanitizeDocumentHtml(result.html);
7754
+ patch({ previewLoading: false, html: clean.html, css: clean.css });
7755
+ }
7756
+
7737
7757
  function params(extra) {
7738
7758
  var base = local ? { path: path } : Object.assign({ path: path }, scopeParams(scope));
7739
7759
  return Object.assign(base, extra || {});
7740
7760
  }
7741
7761
 
7742
7762
  function load() {
7743
- patch({ loading: true, error: '', notice: '' });
7763
+ patch({ loading: true, error: '', notice: '', warn: '' });
7744
7764
  apiCall('docs.read', params()).then(function (result) {
7745
7765
  var remembered = recallView(viewKey);
7746
7766
  patch({
@@ -7787,8 +7807,7 @@ function rememberShowHidden(value) {
7787
7807
  if (state.loading || !state.preview || kind !== 'markdown' || state.html || state.previewLoading) return;
7788
7808
  patch({ previewLoading: true });
7789
7809
  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 });
7810
+ applyPreviewResult(result);
7792
7811
  }).catch(function (error) {
7793
7812
  patch({ previewLoading: false, error: messageOf(error, t, locale) });
7794
7813
  });
@@ -7902,11 +7921,10 @@ function rememberShowHidden(value) {
7902
7921
 
7903
7922
  function showPreview() {
7904
7923
  var next = !state.preview;
7905
- patch({ preview: next, previewLoading: next && !state.html });
7924
+ patch({ preview: next, previewLoading: next && !state.html, warn: '' });
7906
7925
  if (!next || state.html) return;
7907
7926
  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 });
7927
+ applyPreviewResult(result);
7910
7928
  }).catch(function (error) {
7911
7929
  patch({ previewLoading: false, error: messageOf(error, t, locale) });
7912
7930
  });
@@ -8122,6 +8140,7 @@ function rememberShowHidden(value) {
8122
8140
  return h('div', { className: 'rw-doc' }, toolbar,
8123
8141
  state.notice ? h('div', { style: { padding: '6px 10px 0' } }, h(Banner, { kind: 'success' }, state.notice)) : null,
8124
8142
  state.error ? h('div', { style: { padding: '6px 10px 0' } }, h(Banner, { kind: 'error' }, state.error)) : null,
8143
+ state.warn ? h('div', { style: { padding: '6px 10px 0' } }, h(Banner, { kind: 'warn', onClose: function () { patch({ warn: '' }); } }, state.warn)) : null,
8125
8144
  body,
8126
8145
  h('div', { className: 'rw-doc-status' },
8127
8146
  h('span', null, kind.toUpperCase()),
@@ -8342,8 +8361,9 @@ function rememberShowHidden(value) {
8342
8361
 
8343
8362
  var scopeRef = selected ? sourceScopeOf(selected) : null;
8344
8363
 
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.
8364
+ // Free space on the remote volume: fetched once per workspace and again
8365
+ // whenever the tree refreshes (`version` bumps inside refreshTree()), so
8366
+ // the number does not go stale while the panel stays open (D4).
8347
8367
  var diskState = useState(null);
8348
8368
  var disk = diskState[0];
8349
8369
  var setDisk = diskState[1];
@@ -8356,7 +8376,7 @@ function rememberShowHidden(value) {
8356
8376
  if (alive) setDisk(result && result.disk ? result.disk : null);
8357
8377
  }).catch(function () { if (alive) setDisk(null); });
8358
8378
  return function () { alive = false; };
8359
- }, [diskHostId, diskPath]);
8379
+ }, [diskHostId, diskPath, version]);
8360
8380
 
8361
8381
  // autoPush is host-side and silent, so surface it here: the per-workspace
8362
8382
  // switch state (0.24.0) plus the newest push from the transfer history.
@@ -10231,15 +10251,26 @@ function rememberShowHidden(value) {
10231
10251
  ? { kind: 'remote', id: meta.remoteId }
10232
10252
  : { kind: 'workspace', id: meta.workspaceId };
10233
10253
  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
- }));
10254
+ var visible = props.visible !== false;
10255
+ // D2: this tab used to be a plain code editor only, so the same Markdown
10256
+ // opened here (placeholder paths, references) had no preview while the
10257
+ // very same file opened in the directory panel did. Mirror that dispatch.
10258
+ var docKind = documentKindOf(filePath);
10259
+ var pane = docKind === 'image'
10260
+ ? h(ImagePreview, { ctx: ctx, t: t, locale: locale, scope: scope, path: filePath, local: false })
10261
+ : docKind === 'html'
10262
+ ? h(HtmlPreview, { ctx: ctx, t: t, locale: locale, scope: scope, path: filePath, local: false })
10263
+ : docKind && docKind !== 'csv'
10264
+ ? h(DocumentPane, { ctx: ctx, t: t, locale: locale, scope: scope, path: filePath, local: false, visible: visible })
10265
+ : h(RemoteFileEditor, {
10266
+ ctx: ctx, t: t, locale: locale,
10267
+ scope: scope,
10268
+ path: filePath,
10269
+ visible: visible,
10270
+ tabId: tab ? tab.id : undefined,
10271
+ sessionId: props.scope ? props.scope.sessionId : undefined,
10272
+ });
10273
+ return h('div', { className: 'rw-editor-pane' }, pane);
10243
10274
  }
10244
10275
 
10245
10276
  // ── tree ───────────────────────────────────────────────────────────────
@@ -13148,6 +13179,9 @@ function rememberShowHidden(value) {
13148
13179
 
13149
13180
  function scan() {
13150
13181
  if (scanning) return;
13182
+ // F1: a hidden window cannot be looking at a file, so do not poll for
13183
+ // nothing — the visibility handler below catches up on return.
13184
+ if (typeof document !== 'undefined' && document.visibilityState === 'hidden') return;
13151
13185
  scanning = true;
13152
13186
  try {
13153
13187
  var tabs = sidebar.nativePathTabs() || [];
@@ -13166,10 +13200,17 @@ function rememberShowHidden(value) {
13166
13200
  // test, so a tick costs nothing when nothing is open.
13167
13201
  ctx.effect(function () {
13168
13202
  var stop = sidebar.subscribeState(scan);
13169
- var timer = setInterval(scan, 1000);
13203
+ var timer = setInterval(scan, 2000);
13204
+ // A hand-over skipped while the window was hidden has to happen as soon
13205
+ // as it is back, otherwise the click looks like it did nothing.
13206
+ function onVisibility() {
13207
+ if (typeof document !== 'undefined' && document.visibilityState === 'visible') scan();
13208
+ }
13209
+ if (typeof document !== 'undefined') document.addEventListener('visibilitychange', onVisibility);
13170
13210
  return function () {
13171
13211
  try { stop(); } catch (error) { /* already disposed */ }
13172
13212
  clearInterval(timer);
13213
+ if (typeof document !== 'undefined') document.removeEventListener('visibilitychange', onVisibility);
13173
13214
  };
13174
13215
  }, 'dsh-linked-workspace: placeholder hand-over');
13175
13216
  }
package/lib/index.js CHANGED
@@ -2619,6 +2619,13 @@ export function apply(ctx) {
2619
2619
  // ── document bridge (Markdown/PDF/DOCX/XLSX/PPTX) ──────────────────────
2620
2620
 
2621
2621
  const DOC_MAX_BYTES = 80 * 1024 * 1024
2622
+ // A Markdown preview is rendered synchronously on the Host event loop, so an
2623
+ // unbounded document freezes every other API call for as long as it takes
2624
+ // (9 MB of formula-heavy text measured ~9 s and produced a 97 MB fragment).
2625
+ // Above this ceiling the client drops to the text editor instead.
2626
+ const PREVIEW_MAX_CHARS = 512 * 1024
2627
+ const PREVIEW_CACHE_LIMIT = 3
2628
+ const previewCache = new Map()
2622
2629
  const DOC_PDF_SUFFIX_MAX = 999
2623
2630
  const DOC_TOOL = join(dirname(fileURLToPath(import.meta.url)), '..', 'scripts', 'doc_tool.py')
2624
2631
  const DOC_KIND_BY_EXT = new Map([
@@ -3917,6 +3924,13 @@ export function apply(ctx) {
3917
3924
  assertDocKind(target.path, 'markdown')
3918
3925
  let text = typeof params.text === 'string' ? params.text : null
3919
3926
  if (text === null) {
3927
+ // Do not ship a document the preview would refuse anyway: UTF-8 needs
3928
+ // at most three bytes per character in the BMP, so a file above 3x the
3929
+ // ceiling cannot fit. One stat beats a pointless transfer.
3930
+ const info = await docStat(target)
3931
+ if (Number(info.size) > PREVIEW_MAX_CHARS * 3) {
3932
+ return { kind: 'markdown-preview-too-large', bytes: Number(info.size), limit: PREVIEW_MAX_CHARS }
3933
+ }
3920
3934
  const current = await readDocBytes(target, target)
3921
3935
  text = decodeUtf8(current.data)
3922
3936
  }
@@ -3924,7 +3938,28 @@ export function apply(ctx) {
3924
3938
  // to `node scripts/md-to-html.mjs`, and a DSH process without `node` on its
3925
3939
  // PATH silently fell back to a plain renderer — every formula came out as
3926
3940
  // raw `$$…$$` text.
3927
- return { kind: 'markdown-preview', html: renderMarkdownFragment(text) }
3941
+ // D1: never render an unbounded document on the event loop. The caller
3942
+ // turns this answer into "too large — showing the editor".
3943
+ if (text.length > PREVIEW_MAX_CHARS) {
3944
+ return { kind: 'markdown-preview-too-large', chars: text.length, limit: PREVIEW_MAX_CHARS }
3945
+ }
3946
+ // F2: keep the last few previews. The key is the text itself, because the
3947
+ // caller may send unsaved text, in which case path + mtime would be stale.
3948
+ const cacheKey = createHash('sha1').update(text).digest('hex')
3949
+ const cached = previewCache.get(cacheKey)
3950
+ if (typeof cached === 'string') {
3951
+ previewCache.delete(cacheKey)
3952
+ previewCache.set(cacheKey, cached)
3953
+ return { kind: 'markdown-preview', html: cached }
3954
+ }
3955
+ const html = renderMarkdownFragment(text)
3956
+ previewCache.set(cacheKey, html)
3957
+ while (previewCache.size > PREVIEW_CACHE_LIMIT) {
3958
+ const oldest = previewCache.keys().next()
3959
+ if (oldest.done) break
3960
+ previewCache.delete(oldest.value)
3961
+ }
3962
+ return { kind: 'markdown-preview', html }
3928
3963
  },
3929
3964
 
3930
3965
  async 'docs.mdPdf'(params = {}) {
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.27.1",
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",