dsh-linked-workspace 0.28.0 → 0.29.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,27 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.29.0 — 2026-11-27
4
+
5
+ - A folder link in a Markdown preview no longer opens a file tab that could only fail. A trailing separator
6
+ settles it immediately; a link without one (say `sub`) is probed with `fs.stat` / `local.stat` first, and a
7
+ directory is revealed in the tree with a short note instead of a dead tab.
8
+ - The same error is no longer printed twice: a folder opened as a file used to say "is a directory: is a
9
+ directory, not something that can be read as a file", and now says it once.
10
+ - Ctrl/⌘-click and a middle click on a preview link open the target in its own tab, so two documents can be
11
+ compared side by side; dragging a link no longer navigates the window.
12
+ - Local file tabs on Windows are keyed case-insensitively, so `pics/note.md` and `PICS/note.md` no longer
13
+ produce two tabs for one file.
14
+ - Theme changes arrive through the host's `theme/change` event instead of a 1.5-second `getTheme()` poll
15
+ (the poll remains only as a fallback when no event is available).
16
+
17
+ ## 0.28.1 — 2026-11-27
18
+
19
+ - Links inside a Markdown preview no longer navigate the window — that navigation is what turned the whole
20
+ DSH window white. A link that resolves to a file inside the workspace now opens it in a file tab of the
21
+ same panel; a link that leaves the workspace is refused with a note instead of being followed; `#anchor`
22
+ scrolls the preview itself; and `http(s)` / `mailto` / `tel` links go to the system browser through the
23
+ new `local.openUrl` Host method (those four schemes, nothing else).
24
+
3
25
  ## 0.28.0 — 2026-11-26
4
26
 
5
27
  - The directory tree now follows renames and deletions instead of waiting for a page reload. Every
package/docs/API.md CHANGED
@@ -98,6 +98,7 @@ scope root, or absolute inside it.
98
98
  | `linked.syncCancel` | `{ id }` | `{ cancelled: boolean }` |
99
99
  | `local.list` | `{ path, limit?, offset? }` | `{ path, entries: [{ name, path, type, size, mtime }], total, offset, limit, hasMore }` |
100
100
  | `local.openExternal` | `{ path }` | `{ opened, path }` |
101
+ | `local.openUrl` | `{ url }` | `{ opened, url }` (only `http:`, `https:`, `mailto:` and `tel:`; the preview hands external links here instead of navigating — anything else is `BAD_REQUEST`) |
101
102
  | `terminal.open` | `{ linkedId?/remoteId?, side: 'remote'\|'local', path? }` | `{ opened, side, path, host? }` (`path` must stay inside the workspace; remote workspaces only support `side: 'remote'`) |
102
103
  | `fs.openExternal` | `{ linkedId?/remoteId?, path }` | `{ opened, localPath, size }` |
103
104
  | `localWorkspace.create` | `{ path, name? }` | `{ workspaceId, title, path }` |
package/docs/VERIFY.md CHANGED
@@ -2,6 +2,19 @@
2
2
 
3
3
  Host code (lib/) reloads live with `plugin_manager set_plugin include:linked-workspace-ui`; client changes load with **应用 → 重新加载界面** (a full restart is only needed after re-installing the package). Then verify:
4
4
 
5
+ ## 预览链接的文件夹与并行打开(未发布)
6
+
7
+ 1. 在一份 Markdown 里写 `[sub/](sub/)` 与 `[sub](sub)`(`sub` 是真实存在的目录),预览里先后点这两条:都只出
8
+ 「这是文件夹链接,这里只打开文件」提示,目录树展开并把该目录滚到视野中,标签条不新增死标签。
9
+ 2. 再写 `[gone](gone.md)`(不存在的文件)并点击:给出一次读取失败的提示,不会有悬停不掉的半开标签。
10
+ 3. 把一个目录直接开进文件标签(或让某个打开的视图指向目录):错误文案只出现一次「目标是目录」,
11
+ 不应出现「目标是目录:目标是目录」。
12
+ 4. 预览里 **Ctrl/⌘ + 点击**一个文件链接:右侧栏多出一个「远程文件」标签、面板自身的标签不变,地址栏不变;
13
+ **中键点击**同样开一个标签且不发生导航;**拖拽**链接到页面其它位置不产生导航。
14
+ 5. 在 Windows 本地目录里准备 `pics/note.md`,文档里分别写 `[a](pics/note.md)` 与 `[b](PICS/note.md)`,
15
+ 先后点击两者:只应存在一个 `note.md` 标签。
16
+ 6. 切换系统深浅色主题:界面跟随,控制台无报错(宿主提供 `theme/change` 事件时不依赖 1.5 秒轮询)。
17
+
5
18
  ## 主机密钥与输出编码(0.20.0)
6
19
 
7
20
  1. 设置 → 联动工作区 → 「SSH 主机密钥与输出编码」应能看到「主机密钥策略」(tofu / strict)、「远端命令输出编码」(utf8 / gbk),以及已记住的主机列表(每行显示 `host:port` 与 `SHA256:…` 指纹)。
@@ -456,3 +469,13 @@ DSH_HOME/linked-workspace/exec-audit.jsonl` 追加一行 JSON,含 `auditId`、
456
469
  4. 在**文件标签页**里打开一个 Markdown(例如从聊天里的占位路径链接转交过来的那份):应出现文档面板的工具栏(MARKDOWN 徽标 + 预览 / 导出 PDF / 保存),而不是只有代码编辑器;点「编辑」可改、可保存。
457
470
  5. 目录栏标题右侧的可用空间芯片:点「刷新目录」后它的 title(可用 / 已用 / 总量)随之更新,不再永远停在首次打开面板时的数值。
458
471
  6. 把窗口最小化或切到别的应用 30 秒再回来:占位目录转交仍在工作(后台不轮询、回到前台立刻补一次),并且这段时间没有产生额外的网络请求。
472
+
473
+ ## 预览里的链接(Unreleased)
474
+
475
+ 1. 在一份 Markdown 预览里点一个**指向同目录另一个文件**的相对链接(`other.md`、`./sub/a.md`、`../latex/table.tex`):目标文件在同一个文件面板里打开,地址栏不变,页面不跳转;目标已经打开时只切到那个标签,不新开重复标签。
476
+ 2. 点一个**绝对路径**链接(`/shared_data_ssd1/…`):只有在当前工作区根目录之内才会打开;越界的(例如 `/etc/passwd`)给出提示「这个链接指向工作区之外,没有打开:…」,页面不动。
477
+ 3. 点一个用 `../../..` 跳出工作区的相对链接:同样只给提示,**不会**把整个 DSH 界面导航成白页。
478
+ 4. 点 `#section` 锚点:预览在自身内部滚动到对应标题,不触发任何请求。
479
+ 5. 点 `http(s)` / `mailto:` 链接:交给系统默认浏览器 / 邮件客户端打开(Host 走 `local.openUrl`),DSH 窗口保持原样;`javascript:`、`file:` 一律拒绝(Host 返回 400)。
480
+ 6. 在侧边栏的独立文件标签(`远程文件`)里重复第 1–3 条:越界链接在标签顶部显示黄色横幅,工作区内链接打开同侧的文件标签。
481
+ 7. 用真实鼠标(不是脚本合成事件)点第 3 条那种越界链接:地址栏必须仍是 `http://127.0.0.1:<port>/`,界面存活——这是回归白屏 bug 的关键一步。
package/lib/client.js CHANGED
@@ -2151,6 +2151,55 @@ function katexStyleViolation(value) {
2151
2151
  return '';
2152
2152
  }
2153
2153
 
2154
+ // Turns a link found inside a document into an absolute path on the document's
2155
+ // own side. Returns '' for in-page anchors ("#section") and for anything that
2156
+ // is not a path at all (http(s), mailto, tel, protocol-relative), so the caller
2157
+ // can decide between scrolling, the system browser and opening a file.
2158
+ function resolveLinkTarget(baseDir, href) {
2159
+ var raw = String(href == null ? '' : href).trim()
2160
+ // Browsers drop the query and the fragment before asking for a file, and so do
2161
+ // we: neither can be part of a name on either side.
2162
+ var cut = raw.indexOf('#')
2163
+ if (cut >= 0) raw = raw.slice(0, cut)
2164
+ cut = raw.indexOf('?')
2165
+ if (cut >= 0) raw = raw.slice(0, cut)
2166
+ if (raw === '') return ''
2167
+ if (/^[a-zA-Z][a-zA-Z0-9+.-]*:/.test(raw) && !/^[a-zA-Z]:[\\/]/.test(raw)) return ''
2168
+ if (raw.slice(0, 2) === '//') return ''
2169
+ try { raw = decodeURIComponent(raw) } catch (error) { /* keep the literal text */ }
2170
+ var sep = baseDir && baseDir.indexOf('\\') >= 0 ? '\\' : '/'
2171
+ var text = raw.replace(/[\\/]/g, '/')
2172
+ var parts
2173
+ if (/^[a-zA-Z]:\//.test(text) || text.charAt(0) === '/') {
2174
+ parts = text.split('/')
2175
+ } else {
2176
+ parts = String(baseDir == null ? '' : baseDir).replace(/[\\/]/g, '/').split('/')
2177
+ if (parts.length > 1) parts.pop()
2178
+ text.split('/').forEach(function (part) {
2179
+ if (part === '' || part === '.') return
2180
+ if (part === '..') { if (parts.length > 1) parts.pop(); return }
2181
+ parts.push(part)
2182
+ })
2183
+ }
2184
+ // A trailing separator is information, not noise: the caller tells "docs/"
2185
+ // (a folder) from "docs" (a file) with it, before anything is stat'ed.
2186
+ var trailing = /[\\/]$/.test(raw)
2187
+ var joined = parts.join('/')
2188
+ // An absolute path already ends with the separator it was written with.
2189
+ if (trailing && joined !== '' && joined.charAt(joined.length - 1) !== '/') joined += '/'
2190
+ return sep === '\\' ? joined.replace(/\//g, '\\') : joined
2191
+ }
2192
+
2193
+ // True when `target` sits inside `root` (or is the root itself). Comparison is
2194
+ // case-sensitive on purpose: both paths come from the same host listing, so the
2195
+ // spelling already agrees, and Linux remotes really do distinguish case.
2196
+ function isInsideRoot(root, target) {
2197
+ var base = String(root == null ? '' : root).replace(/[\\/]+$/, '').replace(/\\/g, '/')
2198
+ var full = String(target == null ? '' : target).replace(/[\\/]+$/, '').replace(/\\/g, '/')
2199
+ if (base === '' || full === '') return false
2200
+ return full === base || full.indexOf(base + '/') === 0
2201
+ }
2202
+
2154
2203
  var TREE_TAB_TYPE = 'dsh-linked-workspace';
2155
2204
  // Remote workspaces get their own page kind: the two modes show different
2156
2205
  // trees (local ⇄ remote pair vs. a plain remote root), so a session must be
@@ -2315,6 +2364,29 @@ function katexStyleViolation(value) {
2315
2364
  return undefined;
2316
2365
  }
2317
2366
 
2367
+ // A link inside a remote document has to become an absolute path on the same
2368
+ // host, and the panel that owns the tab does not carry the workspace root.
2369
+ // The two lists change rarely, so one lookup serves every click for 30 s.
2370
+ var scopeRootState = { at: 0, roots: null };
2371
+ function scopeRootOf(scope) {
2372
+ if (!scope || (scope.kind !== 'linked' && scope.kind !== 'remote')) return Promise.resolve('');
2373
+ var key = scope.kind + ':' + (scope.id || '');
2374
+ var now = Date.now();
2375
+ if (scopeRootState.roots && now - scopeRootState.at < 30000) {
2376
+ return Promise.resolve(scopeRootState.roots[key] || '');
2377
+ }
2378
+ return Promise.all([
2379
+ apiCall('linked.list').then(function (result) { return (result && result.links) || []; }, function () { return []; }),
2380
+ apiCall('remote_workspaces.list').then(function (result) { return (result && result.workspaces) || []; }, function () { return []; }),
2381
+ ]).then(function (both) {
2382
+ var roots = {};
2383
+ (both[0] || []).forEach(function (item) { if (item && item.id) roots['linked:' + item.id] = String(item.remotePath || ''); });
2384
+ (both[1] || []).forEach(function (item) { if (item && item.id) roots['remote:' + item.id] = String(item.remotePath || ''); });
2385
+ scopeRootState = { at: Date.now(), roots: roots };
2386
+ return roots[key] || '';
2387
+ });
2388
+ }
2389
+
2318
2390
  function openRemoteFileTab(sidebar, scope, source, filePath) {
2319
2391
  if (!sidebar || typeof sidebar.openTab !== 'function') return false;
2320
2392
  var key = scopeKeyOf(sourceScopeOf(source)) + ':' + filePath;
@@ -2660,6 +2732,8 @@ function katexStyleViolation(value) {
2660
2732
  previewTooLarge: '这个文件太大({{chars}} 字符,上限 {{limit}}),没有生成预览;可以在编辑器里查看,或下载后用别的工具打开。',
2661
2733
  previewTooLargeBytes: '这个文件太大({{bytes}}),没有生成预览;可以在编辑器里查看,或下载后用别的工具打开。',
2662
2734
  fileGone: '这个文件已不在远端(可能被重命名或删除),已关闭它的标签并刷新目录。',
2735
+ linkOutside: '这个链接指向工作区之外,没有打开:{{path}}',
2736
+ linkFolder: '这是文件夹链接,这里只打开文件:{{path}}',
2663
2737
  linkedTitle: '联动工作区',
2664
2738
  linkedHint: '本地目录与远端目录成对出现:DSH 会话在该本地目录中工作,并通过 linked_workspace 工具直接编辑远端文件。',
2665
2739
  localFlow: '本地目录',
@@ -3264,6 +3338,8 @@ function katexStyleViolation(value) {
3264
3338
  previewTooLarge: 'Too large to preview ({{chars}} characters, the ceiling is {{limit}}). Read it in the editor, or download it and open it elsewhere.',
3265
3339
  previewTooLargeBytes: 'Too large to preview ({{bytes}}). Read it in the editor, or download it and open it elsewhere.',
3266
3340
  fileGone: 'That file is gone from the remote side (renamed or deleted). Closed its tab and refreshed the tree.',
3341
+ linkOutside: 'That link points outside the workspace, so it was left alone: {{path}}',
3342
+ linkFolder: 'That link is a folder; only files open here: {{path}}',
3267
3343
  linkedTitle: 'Linked workspaces',
3268
3344
  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.',
3269
3345
  localFlow: 'Local folder',
@@ -3648,7 +3724,7 @@ function katexStyleViolation(value) {
3648
3724
  * Host methods the running DSH process does not have yet, the directory
3649
3725
  * pane says so instead of surfacing an unrelated error.
3650
3726
  */
3651
- var HOST_API_REVISION = 15;
3727
+ var HOST_API_REVISION = 16;
3652
3728
  var hostInfoProbe = null;
3653
3729
 
3654
3730
  function probeHostInfo() {
@@ -3714,6 +3790,10 @@ function katexStyleViolation(value) {
3714
3790
  // so name the usual cause and the way back whenever this code shows up.
3715
3791
  var hint = error.code === 'FS_PERMISSION' ? t('permissionHint') : '';
3716
3792
  if (!detail || detail === known) return known + hint;
3793
+ // The host often starts its own message with the generic text ("is a
3794
+ // directory; open it as a folder"), so prefixing the code text said the
3795
+ // same thing twice: "is a directory: is a directory, ...".
3796
+ if (detail.indexOf(known) === 0) return detail + hint;
3717
3797
  return known + (locale === 'zh' ? ':' : ': ') + detail + hint;
3718
3798
  }
3719
3799
 
@@ -6444,6 +6524,40 @@ function katexStyleViolation(value) {
6444
6524
  setCache({ entries: new Map() });
6445
6525
  }, [props.forceTick]);
6446
6526
 
6527
+ // F1: a folder link in a preview should land the reader on that folder, and
6528
+ // a row only exists once its parents are expanded and listed — so expand the
6529
+ // whole chain, ask for every level, then scroll the row into view.
6530
+ useEffect(function () {
6531
+ if (!props.revealDirPath || !props.revealDirTick) return undefined;
6532
+ var base = String(rootPath || '').replace(/[\\/]+$/, '');
6533
+ var wanted = String(props.revealDirPath).replace(/[\\/]+$/, '');
6534
+ if (base === '' || wanted === '') return undefined;
6535
+ var sep = base.indexOf('\\') >= 0 ? '\\' : '/';
6536
+ var baseSlash = base.replace(/\\/g, '/');
6537
+ var wantedSlash = wanted.replace(/\\/g, '/');
6538
+ if (wantedSlash !== baseSlash && wantedSlash.indexOf(baseSlash + '/') !== 0) return undefined;
6539
+ var chain = [baseSlash];
6540
+ if (wantedSlash !== baseSlash) {
6541
+ wantedSlash.slice(baseSlash.length + 1).split('/').forEach(function (part) {
6542
+ if (!part || part === '.' || part === '..') return;
6543
+ chain.push(chain[chain.length - 1] + '/' + part);
6544
+ });
6545
+ }
6546
+ var paths = chain.map(function (item) { return sep === '\\' ? item.replace(/\//g, '\\') : item; });
6547
+ setExpanded(function (previous) {
6548
+ var next = new Set(previous);
6549
+ paths.forEach(function (item) { next.add(item); });
6550
+ return next;
6551
+ });
6552
+ paths.forEach(function (item) { load(item); });
6553
+ var targetPath = paths[paths.length - 1];
6554
+ var timer = setTimeout(function () {
6555
+ var row = document.querySelector('button.rw-row[data-dir-path="' + targetPath.replace(/"/g, '\\"') + '"]');
6556
+ if (row && typeof row.scrollIntoView === 'function') row.scrollIntoView({ block: 'center' });
6557
+ }, 700);
6558
+ return function () { clearTimeout(timer); };
6559
+ }, [props.revealDirTick]);
6560
+
6447
6561
  function toggle(path) {
6448
6562
  setExpanded(function (previous) {
6449
6563
  var next = new Set(previous);
@@ -7734,6 +7848,7 @@ function rememberShowHidden(value) {
7734
7848
  var path = props.path;
7735
7849
  var local = props.local === true;
7736
7850
  var onSaved = props.onSaved;
7851
+ var onOpenLink = props.onOpenLink;
7737
7852
  var settings = useRuntimeSettings();
7738
7853
  var kind = documentKindOf(path);
7739
7854
  var viewKey = (local ? 'local' : ((scope && scope.kind ? scope.kind : 'remote') + ':' + ((scope && scope.id) || ''))) + '|' + path;
@@ -7779,6 +7894,60 @@ function rememberShowHidden(value) {
7779
7894
  return Object.assign(base, extra || {});
7780
7895
  }
7781
7896
 
7897
+ // A link in the preview used to navigate the whole window: the client is a
7898
+ // single-page app with no route for a file path, so the page went blank and
7899
+ // the reader lost the panel with it. Every anchor is ours to handle now,
7900
+ // including the two gestures that never reach onClick: the middle button
7901
+ // (auxclick) and dragging a link out of the page.
7902
+ function anchorOf(event) {
7903
+ var node = event && event.target;
7904
+ return node && typeof node.closest === 'function' ? node.closest('a') : null;
7905
+ }
7906
+
7907
+ function followAnchor(anchor, options) {
7908
+ var href = String(anchor.getAttribute('href') || '').trim();
7909
+ if (href === '') return;
7910
+ if (href.charAt(0) === '#') {
7911
+ var body = docPreviewRef.current;
7912
+ var id = href.slice(1);
7913
+ var target = body && id ? body.querySelector('[id="' + id.replace(/"/g, '\\"') + '"]') : null;
7914
+ if (target && typeof target.scrollIntoView === 'function') target.scrollIntoView({ block: 'nearest' });
7915
+ return;
7916
+ }
7917
+ var scheme = urlSchemeOf(href);
7918
+ if (scheme === 'http' || scheme === 'https' || scheme === 'mailto' || scheme === 'tel') {
7919
+ apiCall('local.openUrl', { url: href }).catch(function (error) {
7920
+ patch({ warn: t('openFailed') + ':' + messageOf(error, t, locale) });
7921
+ });
7922
+ return;
7923
+ }
7924
+ if (scheme !== '' && !/^[a-zA-Z]:[\\/]/.test(href)) return;
7925
+ if (onOpenLink) onOpenLink(href, options || {});
7926
+ }
7927
+
7928
+ function previewLink(event) {
7929
+ var anchor = anchorOf(event);
7930
+ if (!anchor) return;
7931
+ event.preventDefault();
7932
+ event.stopPropagation();
7933
+ followAnchor(anchor, { newTab: Boolean(event.ctrlKey || event.metaKey) });
7934
+ }
7935
+
7936
+ // The middle button is the browser's own "open elsewhere" gesture: swallow
7937
+ // it and open the target in its own tab instead of letting the app navigate.
7938
+ function previewAuxClick(event) {
7939
+ if (!event || event.button !== 1) return;
7940
+ var anchor = anchorOf(event);
7941
+ if (!anchor) return;
7942
+ event.preventDefault();
7943
+ event.stopPropagation();
7944
+ followAnchor(anchor, { newTab: true });
7945
+ }
7946
+
7947
+ function previewDragStart(event) {
7948
+ if (anchorOf(event)) event.preventDefault();
7949
+ }
7950
+
7782
7951
  function load() {
7783
7952
  patch({ loading: true, error: '', notice: '', warn: '' });
7784
7953
  apiCall('docs.read', params()).then(function (result) {
@@ -8044,7 +8213,7 @@ function rememberShowHidden(value) {
8044
8213
  ? h('div', { className: 'rw-doc-body', ref: docBodyRef, onScroll: rememberScroll },
8045
8214
  state.previewLoading ? h('div', { className: 'rw-editor-message' }, Spinner(14), t('loading')) : null,
8046
8215
  state.html ? h('style', { 'data-rw-katex': '1', dangerouslySetInnerHTML: { __html: state.css || '' } }) : null,
8047
- state.html ? h('div', { ref: docPreviewRef, className: 'rw-doc-preview', onScroll: rememberScroll, dangerouslySetInnerHTML: { __html: state.html } }) : null)
8216
+ state.html ? h('div', { ref: docPreviewRef, className: 'rw-doc-preview', onScroll: rememberScroll, onClick: previewLink, onAuxClick: previewAuxClick, onDragStart: previewDragStart, dangerouslySetInnerHTML: { __html: state.html } }) : null)
8048
8217
  : h('div', { className: 'rw-doc-body', ref: docBodyRef, onScroll: rememberScroll },
8049
8218
  state.findOpen ? h('div', { className: 'rw-find-bar rw-doc-find' },
8050
8219
  h('input', {
@@ -8470,6 +8639,10 @@ function rememberShowHidden(value) {
8470
8639
  var treeForceState = useState(0);
8471
8640
  var treeForceTick = treeForceState[0];
8472
8641
  var setTreeForceTick = treeForceState[1];
8642
+ // F1: a folder link asks the trees to open the way down to that folder.
8643
+ var revealDirState = useState(null);
8644
+ var revealDir = revealDirState[0];
8645
+ var setRevealDir = revealDirState[1];
8473
8646
  var fileDirtyState = useState({});
8474
8647
  var fileDirty = fileDirtyState[0];
8475
8648
  var setFileDirty = fileDirtyState[1];
@@ -8646,6 +8819,59 @@ function rememberShowHidden(value) {
8646
8819
  openByMode(side, filePath, { pinned: true, preview: false });
8647
8820
  }
8648
8821
 
8822
+ // A link inside the preview resolves against the file that holds it, and
8823
+ // only opens when it stays inside this workspace.
8824
+ function openPreviewLink(href, options) {
8825
+ if (!selected) return;
8826
+ var file = openFiles.filter(function (item) { return item.key === activeFileKey; })[0];
8827
+ if (!file) return;
8828
+ var side = file.side;
8829
+ var root = side === 'remote' ? String(selected.remotePath || '') : String(selected.localPath || '');
8830
+ var resolved = resolveLinkTarget(file.path, href);
8831
+ if (!resolved) return;
8832
+ // F1: a folder link is not a failure, it is a place. Expand the tree down
8833
+ // to it and locate the row, then say why nothing was opened.
8834
+ if (/[\\/]$/.test(resolved)) {
8835
+ if (isInsideRoot(root, resolved)) setRevealDir({ side: side, path: resolved, at: Date.now() });
8836
+ showNotice('info', t('linkFolder', { path: resolved }));
8837
+ return;
8838
+ }
8839
+ if (!isInsideRoot(root, resolved)) { showNotice('info', t('linkOutside', { path: resolved })); return; }
8840
+ // "sub" without a trailing slash may still be a folder, and the separator
8841
+ // alone cannot tell. Ask the host before opening a tab that could only
8842
+ // fail with "is a directory".
8843
+ var probe = side === 'local'
8844
+ ? apiCall('local.stat', { path: resolved })
8845
+ : apiCall('fs.stat', Object.assign({}, scopeParams(scopeRef), { path: resolved }));
8846
+ probe.then(function (result) {
8847
+ var type = result && result.type ? String(result.type) : '';
8848
+ if (type === 'dir' || type === 'directory') {
8849
+ setRevealDir({ side: side, path: resolved, at: Date.now() });
8850
+ showNotice('info', t('linkFolder', { path: resolved }));
8851
+ return;
8852
+ }
8853
+ // F2: Ctrl/⌘-click asks for both documents at once, which only a sidebar
8854
+ // tab can give: the pane shows one file at a time.
8855
+ if (options && options.newTab && openInSidebarTab(side, resolved)) return;
8856
+ openByMode(side, resolved);
8857
+ }, function (error) {
8858
+ showNotice('error', t('openFailed') + ':' + messageOf(error, t, locale));
8859
+ });
8860
+ }
8861
+
8862
+ // F2: a second view of the same workspace, opened from a link.
8863
+ function openInSidebarTab(side, filePath) {
8864
+ var service = sidebarService(ctx);
8865
+ if (!service) return false;
8866
+ if (side === 'remote') {
8867
+ return Boolean(selected) && openRemoteFileTab(service, props.scope, selected, filePath);
8868
+ }
8869
+ if (typeof service.openFile === 'function') {
8870
+ try { service.openFile(props.scope, filePath, basename(filePath)); return true; } catch (error) { return false; }
8871
+ }
8872
+ return false;
8873
+ }
8874
+
8649
8875
  function openByMode(side, filePath, options) {
8650
8876
  if (!selected || !filePath) return;
8651
8877
  clearStaleError();
@@ -8669,9 +8895,22 @@ function rememberShowHidden(value) {
8669
8895
  openInternalFile(side, filePath, options || { pinned: true });
8670
8896
  }
8671
8897
 
8898
+ // Windows and macOS resolve paths case-insensitively, so one file can reach
8899
+ // us as "pics/note.md" from one link and "PICS/note.md" from another; both
8900
+ // used to become their own tab. Normalise the local side only — the remote
8901
+ // side is POSIX, where case is meaningful.
8902
+ function panelFileKey(side, filePath) {
8903
+ var path = String(filePath || '');
8904
+ if (side !== 'remote') {
8905
+ if (path.indexOf('\\') >= 0 || /^[a-zA-Z]:[\\/]/.test(path)) path = path.replace(/\//g, '\\');
8906
+ path = path.toLowerCase();
8907
+ }
8908
+ return side + ':' + (side === 'remote' ? scopeKeyOf(scopeRef) : 'local') + ':' + path;
8909
+ }
8910
+
8672
8911
  function openInternalFile(side, filePath, options) {
8673
8912
  var opts = options || { pinned: true };
8674
- var key = side + ':' + (side === 'remote' ? scopeKeyOf(scopeRef) : 'local') + ':' + filePath;
8913
+ var key = panelFileKey(side, filePath);
8675
8914
  setOpenFiles(function (previous) {
8676
8915
  var existing = previous.filter(function (file) { return file.key === key; })[0];
8677
8916
  if (existing) {
@@ -8709,7 +8948,7 @@ function rememberShowHidden(value) {
8709
8948
  // that has since changed. Close it and re-read the tree instead of leaving
8710
8949
  // a tab that can only fail.
8711
8950
  function dropOpenFile(side, filePath) {
8712
- var key = side + ':' + (side === 'remote' ? scopeKeyOf(scopeRef) : 'local') + ':' + filePath;
8951
+ var key = panelFileKey(side, filePath);
8713
8952
  setOpenFiles(function (previous) {
8714
8953
  return previous.filter(function (file) { return file.key !== key; });
8715
8954
  });
@@ -10024,6 +10263,8 @@ function rememberShowHidden(value) {
10024
10263
  onPin: function (filePath) { pinByMode('remote', filePath); },
10025
10264
  refreshTick: localTick,
10026
10265
  forceTick: treeForceTick,
10266
+ revealDirPath: revealDir && revealDir.side === 'remote' ? revealDir.path : '',
10267
+ revealDirTick: revealDir && revealDir.side === 'remote' ? revealDir.at : 0,
10027
10268
  onContextMenu: function (info) { setSelectedEntry(Object.assign({ side: 'remote' }, info)); openContextMenu('remote', info); },
10028
10269
  })),
10029
10270
  selected.kind === 'linked'
@@ -10051,6 +10292,8 @@ function rememberShowHidden(value) {
10051
10292
  onPin: function (filePath) { pinByMode('local', filePath); },
10052
10293
  refreshTick: localTick,
10053
10294
  forceTick: treeForceTick,
10295
+ revealDirPath: revealDir && revealDir.side === 'local' ? revealDir.path : '',
10296
+ revealDirTick: revealDir && revealDir.side === 'local' ? revealDir.at : 0,
10054
10297
  onContextMenu: function (info) { setSelectedEntry(Object.assign({ side: 'local' }, info)); openContextMenu('local', info); },
10055
10298
  }))
10056
10299
  : null);
@@ -10084,6 +10327,7 @@ function rememberShowHidden(value) {
10084
10327
  path: activeFile.path,
10085
10328
  local: activeFile.side === 'local',
10086
10329
  onSaved: refreshTree,
10330
+ onOpenLink: openPreviewLink,
10087
10331
  onMissing: function (filePath) { dropOpenFile(activeFile.side, filePath); },
10088
10332
  onSaveReady: function (handler) {
10089
10333
  if (handler) saveHandlersRef.current[activeFile.key] = handler;
@@ -10372,6 +10616,21 @@ function rememberShowHidden(value) {
10372
10616
  // opened here (placeholder paths, references) had no preview while the
10373
10617
  // very same file opened in the directory panel did. Mirror that dispatch.
10374
10618
  var docKind = documentKindOf(filePath);
10619
+ var linkNoteRef = useState('');
10620
+ var linkNote = linkNoteRef[0];
10621
+ var setLinkNote = linkNoteRef[1];
10622
+ function openPreviewLink(href) {
10623
+ scopeRootOf(scope).then(function (root) {
10624
+ var resolved = resolveLinkTarget(filePath, href);
10625
+ if (!resolved) return;
10626
+ if (/[\\/]$/.test(resolved)) { setLinkNote(t('linkFolder', { path: resolved })); return; }
10627
+ if (!isInsideRoot(root, resolved)) { setLinkNote(t('linkOutside', { path: resolved })); return; }
10628
+ var service = sidebarService(ctx);
10629
+ if (!service || typeof service.openTab !== 'function') return;
10630
+ var source = { kind: scope.kind, id: scope.id, name: meta.linkedName || meta.remoteName || '' };
10631
+ openRemoteFileTab(service, props.scope, source, resolved);
10632
+ }, function () { /* a failed lookup leaves the link alone */ });
10633
+ }
10375
10634
  // A file tab whose target vanished closes itself; the panel that opened it
10376
10635
  // is gone, so the sidebar is the only thing that can reclaim the tab.
10377
10636
  function closeSelf() {
@@ -10400,7 +10659,7 @@ function rememberShowHidden(value) {
10400
10659
  : docKind === 'html'
10401
10660
  ? h(HtmlPreview, { ctx: ctx, t: t, locale: locale, scope: scope, path: filePath, local: false })
10402
10661
  : docKind && docKind !== 'csv'
10403
- ? h(DocumentPane, { ctx: ctx, t: t, locale: locale, scope: scope, path: filePath, local: false, visible: visible, onMissing: closeSelf })
10662
+ ? h(DocumentPane, { ctx: ctx, t: t, locale: locale, scope: scope, path: filePath, local: false, visible: visible, onMissing: closeSelf, onOpenLink: openPreviewLink })
10404
10663
  : h(RemoteFileEditor, {
10405
10664
  ctx: ctx, t: t, locale: locale,
10406
10665
  scope: scope,
@@ -10410,7 +10669,9 @@ function rememberShowHidden(value) {
10410
10669
  sessionId: props.scope ? props.scope.sessionId : undefined,
10411
10670
  onMissing: closeSelf,
10412
10671
  });
10413
- return h('div', { className: 'rw-editor-pane' }, pane);
10672
+ return h('div', { className: 'rw-editor-pane' },
10673
+ linkNote ? h('div', { style: { padding: '6px 10px 0' } }, h(Banner, { kind: 'warn', onClose: function () { setLinkNote(''); } }, linkNote)) : null,
10674
+ pane);
10414
10675
  }
10415
10676
 
10416
10677
  // ── tree ───────────────────────────────────────────────────────────────
@@ -13380,9 +13641,21 @@ function rememberShowHidden(value) {
13380
13641
  } catch (error) { /* theme service unavailable */ }
13381
13642
  };
13382
13643
  sync();
13383
- var timer = setInterval(sync, 1500);
13384
- if (timer && typeof timer.unref === 'function') timer.unref();
13385
- return function () { clearInterval(timer); };
13644
+ // The theme contract asks for event-driven sync ("continuous sync only
13645
+ // through the theme/change event"); a 1.5 s poll was only a stand-in.
13646
+ var off = null;
13647
+ if (typeof ctx.on === 'function') {
13648
+ try { off = ctx.on('theme/change', function () { sync(); }); } catch (error) { off = null; }
13649
+ }
13650
+ if (!off) {
13651
+ var timer = setInterval(sync, 1500);
13652
+ if (timer && typeof timer.unref === 'function') timer.unref();
13653
+ return function () { clearInterval(timer); };
13654
+ }
13655
+ return function () {
13656
+ if (typeof off !== 'function') return;
13657
+ try { off(); } catch (error) { /* already disposed */ }
13658
+ };
13386
13659
  }, 'dsh-linked-workspace: app theme sync');
13387
13660
  ctx.effect(function () {
13388
13661
  if (syncDirectoryTabsRef) syncDirectoryTabsRef();
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 = 15
44
+ const API_REVISION = 16
45
45
 
46
46
  /** When this copy of the Host was loaded; shown by `meta.info`. */
47
47
  const STARTED_AT = new Date().toISOString()
@@ -332,6 +332,26 @@ function openWithSystem(targetPath) {
332
332
  }
333
333
  }
334
334
 
335
+ // Same idea for a URL: rundll32 hands it to the registered protocol handler
336
+ // without a shell, so nothing re-parses "&" or spaces inside the link.
337
+ function openUrlWithSystem(url) {
338
+ let child
339
+ try {
340
+ if (process.platform === 'win32') {
341
+ child = spawn('rundll32.exe', ['url.dll,FileProtocolHandler', url], { detached: true, stdio: 'ignore', windowsHide: true })
342
+ } else if (process.platform === 'darwin') {
343
+ child = spawn('open', [url], { detached: true, stdio: 'ignore' })
344
+ } else {
345
+ child = spawn('xdg-open', [url], { detached: true, stdio: 'ignore' })
346
+ }
347
+ if (typeof child.unref === 'function') child.unref()
348
+ return true
349
+ } catch (error) {
350
+ log('warn', `cannot open ${url}: ${error && error.message ? error.message : error}`)
351
+ return false
352
+ }
353
+ }
354
+
335
355
  /** Spawn a detached console process and report whether the executable started. */
336
356
  function launchDetached(command, args, extra = {}) {
337
357
  return new Promise((resolveLaunch) => {
@@ -4683,6 +4703,16 @@ export function apply(ctx) {
4683
4703
  return { opened: true, path: target }
4684
4704
  },
4685
4705
 
4706
+ // A link inside a remote document cannot be followed by the window that
4707
+ // shows the preview: the SPA has no route for it and goes blank. External
4708
+ // links are handed to the system browser instead.
4709
+ async 'local.openUrl'(params = {}) {
4710
+ const raw = typeof params.url === 'string' ? params.url.trim() : ''
4711
+ if (!/^(?:https?|mailto|tel):/i.test(raw)) throw new ApiError('BAD_REQUEST', '只支持 http、https、mailto 与 tel 链接')
4712
+ if (!openUrlWithSystem(raw)) throw new ApiError('INTERNAL', '无法启动系统浏览器')
4713
+ return { opened: true, url: raw }
4714
+ },
4715
+
4686
4716
  async 'fs.openExternal'(params = {}) {
4687
4717
  const scope = await requireScope(params)
4688
4718
  const target = scopeTarget(scope, params.path)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-linked-workspace",
3
- "version": "0.28.0",
3
+ "version": "0.29.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",