dsh-linked-workspace 0.28.0 → 0.28.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,13 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.28.1 — 2026-11-27
4
+
5
+ - Links inside a Markdown preview no longer navigate the window — that navigation is what turned the whole
6
+ DSH window white. A link that resolves to a file inside the workspace now opens it in a file tab of the
7
+ same panel; a link that leaves the workspace is refused with a note instead of being followed; `#anchor`
8
+ scrolls the preview itself; and `http(s)` / `mailto` / `tel` links go to the system browser through the
9
+ new `local.openUrl` Host method (those four schemes, nothing else).
10
+
3
11
  ## 0.28.0 — 2026-11-26
4
12
 
5
13
  - 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
@@ -456,3 +456,13 @@ DSH_HOME/linked-workspace/exec-audit.jsonl` 追加一行 JSON,含 `auditId`、
456
456
  4. 在**文件标签页**里打开一个 Markdown(例如从聊天里的占位路径链接转交过来的那份):应出现文档面板的工具栏(MARKDOWN 徽标 + 预览 / 导出 PDF / 保存),而不是只有代码编辑器;点「编辑」可改、可保存。
457
457
  5. 目录栏标题右侧的可用空间芯片:点「刷新目录」后它的 title(可用 / 已用 / 总量)随之更新,不再永远停在首次打开面板时的数值。
458
458
  6. 把窗口最小化或切到别的应用 30 秒再回来:占位目录转交仍在工作(后台不轮询、回到前台立刻补一次),并且这段时间没有产生额外的网络请求。
459
+
460
+ ## 预览里的链接(Unreleased)
461
+
462
+ 1. 在一份 Markdown 预览里点一个**指向同目录另一个文件**的相对链接(`other.md`、`./sub/a.md`、`../latex/table.tex`):目标文件在同一个文件面板里打开,地址栏不变,页面不跳转;目标已经打开时只切到那个标签,不新开重复标签。
463
+ 2. 点一个**绝对路径**链接(`/shared_data_ssd1/…`):只有在当前工作区根目录之内才会打开;越界的(例如 `/etc/passwd`)给出提示「这个链接指向工作区之外,没有打开:…」,页面不动。
464
+ 3. 点一个用 `../../..` 跳出工作区的相对链接:同样只给提示,**不会**把整个 DSH 界面导航成白页。
465
+ 4. 点 `#section` 锚点:预览在自身内部滚动到对应标题,不触发任何请求。
466
+ 5. 点 `http(s)` / `mailto:` 链接:交给系统默认浏览器 / 邮件客户端打开(Host 走 `local.openUrl`),DSH 窗口保持原样;`javascript:`、`file:` 一律拒绝(Host 返回 400)。
467
+ 6. 在侧边栏的独立文件标签(`远程文件`)里重复第 1–3 条:越界链接在标签顶部显示黄色横幅,工作区内链接打开同侧的文件标签。
468
+ 7. 用真实鼠标(不是脚本合成事件)点第 3 条那种越界链接:地址栏必须仍是 `http://127.0.0.1:<port>/`,界面存活——这是回归白屏 bug 的关键一步。
package/lib/client.js CHANGED
@@ -2151,6 +2151,50 @@ 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
+ var joined = parts.join('/')
2185
+ return sep === '\\' ? joined.replace(/\//g, '\\') : joined
2186
+ }
2187
+
2188
+ // True when `target` sits inside `root` (or is the root itself). Comparison is
2189
+ // case-sensitive on purpose: both paths come from the same host listing, so the
2190
+ // spelling already agrees, and Linux remotes really do distinguish case.
2191
+ function isInsideRoot(root, target) {
2192
+ var base = String(root == null ? '' : root).replace(/[\\/]+$/, '').replace(/\\/g, '/')
2193
+ var full = String(target == null ? '' : target).replace(/[\\/]+$/, '').replace(/\\/g, '/')
2194
+ if (base === '' || full === '') return false
2195
+ return full === base || full.indexOf(base + '/') === 0
2196
+ }
2197
+
2154
2198
  var TREE_TAB_TYPE = 'dsh-linked-workspace';
2155
2199
  // Remote workspaces get their own page kind: the two modes show different
2156
2200
  // trees (local ⇄ remote pair vs. a plain remote root), so a session must be
@@ -2315,6 +2359,29 @@ function katexStyleViolation(value) {
2315
2359
  return undefined;
2316
2360
  }
2317
2361
 
2362
+ // A link inside a remote document has to become an absolute path on the same
2363
+ // host, and the panel that owns the tab does not carry the workspace root.
2364
+ // The two lists change rarely, so one lookup serves every click for 30 s.
2365
+ var scopeRootState = { at: 0, roots: null };
2366
+ function scopeRootOf(scope) {
2367
+ if (!scope || (scope.kind !== 'linked' && scope.kind !== 'remote')) return Promise.resolve('');
2368
+ var key = scope.kind + ':' + (scope.id || '');
2369
+ var now = Date.now();
2370
+ if (scopeRootState.roots && now - scopeRootState.at < 30000) {
2371
+ return Promise.resolve(scopeRootState.roots[key] || '');
2372
+ }
2373
+ return Promise.all([
2374
+ apiCall('linked.list').then(function (result) { return (result && result.links) || []; }, function () { return []; }),
2375
+ apiCall('remote_workspaces.list').then(function (result) { return (result && result.workspaces) || []; }, function () { return []; }),
2376
+ ]).then(function (both) {
2377
+ var roots = {};
2378
+ (both[0] || []).forEach(function (item) { if (item && item.id) roots['linked:' + item.id] = String(item.remotePath || ''); });
2379
+ (both[1] || []).forEach(function (item) { if (item && item.id) roots['remote:' + item.id] = String(item.remotePath || ''); });
2380
+ scopeRootState = { at: Date.now(), roots: roots };
2381
+ return roots[key] || '';
2382
+ });
2383
+ }
2384
+
2318
2385
  function openRemoteFileTab(sidebar, scope, source, filePath) {
2319
2386
  if (!sidebar || typeof sidebar.openTab !== 'function') return false;
2320
2387
  var key = scopeKeyOf(sourceScopeOf(source)) + ':' + filePath;
@@ -2660,6 +2727,8 @@ function katexStyleViolation(value) {
2660
2727
  previewTooLarge: '这个文件太大({{chars}} 字符,上限 {{limit}}),没有生成预览;可以在编辑器里查看,或下载后用别的工具打开。',
2661
2728
  previewTooLargeBytes: '这个文件太大({{bytes}}),没有生成预览;可以在编辑器里查看,或下载后用别的工具打开。',
2662
2729
  fileGone: '这个文件已不在远端(可能被重命名或删除),已关闭它的标签并刷新目录。',
2730
+ linkOutside: '这个链接指向工作区之外,没有打开:{{path}}',
2731
+ linkFolder: '这是文件夹链接,这里只打开文件:{{path}}',
2663
2732
  linkedTitle: '联动工作区',
2664
2733
  linkedHint: '本地目录与远端目录成对出现:DSH 会话在该本地目录中工作,并通过 linked_workspace 工具直接编辑远端文件。',
2665
2734
  localFlow: '本地目录',
@@ -3264,6 +3333,8 @@ function katexStyleViolation(value) {
3264
3333
  previewTooLarge: 'Too large to preview ({{chars}} characters, the ceiling is {{limit}}). Read it in the editor, or download it and open it elsewhere.',
3265
3334
  previewTooLargeBytes: 'Too large to preview ({{bytes}}). Read it in the editor, or download it and open it elsewhere.',
3266
3335
  fileGone: 'That file is gone from the remote side (renamed or deleted). Closed its tab and refreshed the tree.',
3336
+ linkOutside: 'That link points outside the workspace, so it was left alone: {{path}}',
3337
+ linkFolder: 'That link is a folder; only files open here: {{path}}',
3267
3338
  linkedTitle: 'Linked workspaces',
3268
3339
  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
3340
  localFlow: 'Local folder',
@@ -3648,7 +3719,7 @@ function katexStyleViolation(value) {
3648
3719
  * Host methods the running DSH process does not have yet, the directory
3649
3720
  * pane says so instead of surfacing an unrelated error.
3650
3721
  */
3651
- var HOST_API_REVISION = 15;
3722
+ var HOST_API_REVISION = 16;
3652
3723
  var hostInfoProbe = null;
3653
3724
 
3654
3725
  function probeHostInfo() {
@@ -7734,6 +7805,7 @@ function rememberShowHidden(value) {
7734
7805
  var path = props.path;
7735
7806
  var local = props.local === true;
7736
7807
  var onSaved = props.onSaved;
7808
+ var onOpenLink = props.onOpenLink;
7737
7809
  var settings = useRuntimeSettings();
7738
7810
  var kind = documentKindOf(path);
7739
7811
  var viewKey = (local ? 'local' : ((scope && scope.kind ? scope.kind : 'remote') + ':' + ((scope && scope.id) || ''))) + '|' + path;
@@ -7779,6 +7851,35 @@ function rememberShowHidden(value) {
7779
7851
  return Object.assign(base, extra || {});
7780
7852
  }
7781
7853
 
7854
+ // A link in the preview used to navigate the whole window: the client is a
7855
+ // single-page app with no route for a file path, so the page went blank and
7856
+ // the reader lost the panel with it. Every anchor is ours to handle now.
7857
+ function previewLink(event) {
7858
+ var node = event && event.target;
7859
+ var anchor = node && typeof node.closest === 'function' ? node.closest('a') : null;
7860
+ if (!anchor) return;
7861
+ event.preventDefault();
7862
+ event.stopPropagation();
7863
+ var href = String(anchor.getAttribute('href') || '').trim();
7864
+ if (href === '') return;
7865
+ if (href.charAt(0) === '#') {
7866
+ var body = docPreviewRef.current;
7867
+ var id = href.slice(1);
7868
+ var target = body && id ? body.querySelector('[id="' + id.replace(/"/g, '\\"') + '"]') : null;
7869
+ if (target && typeof target.scrollIntoView === 'function') target.scrollIntoView({ block: 'nearest' });
7870
+ return;
7871
+ }
7872
+ var scheme = urlSchemeOf(href);
7873
+ if (scheme === 'http' || scheme === 'https' || scheme === 'mailto' || scheme === 'tel') {
7874
+ apiCall('local.openUrl', { url: href }).catch(function (error) {
7875
+ patch({ warn: t('openFailed') + ':' + messageOf(error, t, locale) });
7876
+ });
7877
+ return;
7878
+ }
7879
+ if (scheme !== '' && !/^[a-zA-Z]:[\\/]/.test(href)) return;
7880
+ if (onOpenLink) onOpenLink(href);
7881
+ }
7882
+
7782
7883
  function load() {
7783
7884
  patch({ loading: true, error: '', notice: '', warn: '' });
7784
7885
  apiCall('docs.read', params()).then(function (result) {
@@ -8044,7 +8145,7 @@ function rememberShowHidden(value) {
8044
8145
  ? h('div', { className: 'rw-doc-body', ref: docBodyRef, onScroll: rememberScroll },
8045
8146
  state.previewLoading ? h('div', { className: 'rw-editor-message' }, Spinner(14), t('loading')) : null,
8046
8147
  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)
8148
+ state.html ? h('div', { ref: docPreviewRef, className: 'rw-doc-preview', onScroll: rememberScroll, onClick: previewLink, dangerouslySetInnerHTML: { __html: state.html } }) : null)
8048
8149
  : h('div', { className: 'rw-doc-body', ref: docBodyRef, onScroll: rememberScroll },
8049
8150
  state.findOpen ? h('div', { className: 'rw-find-bar rw-doc-find' },
8050
8151
  h('input', {
@@ -8646,6 +8747,21 @@ function rememberShowHidden(value) {
8646
8747
  openByMode(side, filePath, { pinned: true, preview: false });
8647
8748
  }
8648
8749
 
8750
+ // A link inside the preview resolves against the file that holds it, and
8751
+ // only opens when it stays inside this workspace.
8752
+ function openPreviewLink(href) {
8753
+ if (!selected) return;
8754
+ var file = openFiles.filter(function (item) { return item.key === activeFileKey; })[0];
8755
+ if (!file) return;
8756
+ var side = file.side;
8757
+ var root = side === 'remote' ? String(selected.remotePath || '') : String(selected.localPath || '');
8758
+ var resolved = resolveLinkTarget(file.path, href);
8759
+ if (!resolved) return;
8760
+ if (/[\\/]$/.test(resolved)) { showNotice('info', t('linkFolder', { path: resolved })); return; }
8761
+ if (!isInsideRoot(root, resolved)) { showNotice('info', t('linkOutside', { path: resolved })); return; }
8762
+ openByMode(side, resolved);
8763
+ }
8764
+
8649
8765
  function openByMode(side, filePath, options) {
8650
8766
  if (!selected || !filePath) return;
8651
8767
  clearStaleError();
@@ -10084,6 +10200,7 @@ function rememberShowHidden(value) {
10084
10200
  path: activeFile.path,
10085
10201
  local: activeFile.side === 'local',
10086
10202
  onSaved: refreshTree,
10203
+ onOpenLink: openPreviewLink,
10087
10204
  onMissing: function (filePath) { dropOpenFile(activeFile.side, filePath); },
10088
10205
  onSaveReady: function (handler) {
10089
10206
  if (handler) saveHandlersRef.current[activeFile.key] = handler;
@@ -10372,6 +10489,21 @@ function rememberShowHidden(value) {
10372
10489
  // opened here (placeholder paths, references) had no preview while the
10373
10490
  // very same file opened in the directory panel did. Mirror that dispatch.
10374
10491
  var docKind = documentKindOf(filePath);
10492
+ var linkNoteRef = useState('');
10493
+ var linkNote = linkNoteRef[0];
10494
+ var setLinkNote = linkNoteRef[1];
10495
+ function openPreviewLink(href) {
10496
+ scopeRootOf(scope).then(function (root) {
10497
+ var resolved = resolveLinkTarget(filePath, href);
10498
+ if (!resolved) return;
10499
+ if (/[\\/]$/.test(resolved)) { setLinkNote(t('linkFolder', { path: resolved })); return; }
10500
+ if (!isInsideRoot(root, resolved)) { setLinkNote(t('linkOutside', { path: resolved })); return; }
10501
+ var service = sidebarService(ctx);
10502
+ if (!service || typeof service.openTab !== 'function') return;
10503
+ var source = { kind: scope.kind, id: scope.id, name: meta.linkedName || meta.remoteName || '' };
10504
+ openRemoteFileTab(service, props.scope, source, resolved);
10505
+ }, function () { /* a failed lookup leaves the link alone */ });
10506
+ }
10375
10507
  // A file tab whose target vanished closes itself; the panel that opened it
10376
10508
  // is gone, so the sidebar is the only thing that can reclaim the tab.
10377
10509
  function closeSelf() {
@@ -10400,7 +10532,7 @@ function rememberShowHidden(value) {
10400
10532
  : docKind === 'html'
10401
10533
  ? h(HtmlPreview, { ctx: ctx, t: t, locale: locale, scope: scope, path: filePath, local: false })
10402
10534
  : docKind && docKind !== 'csv'
10403
- ? h(DocumentPane, { ctx: ctx, t: t, locale: locale, scope: scope, path: filePath, local: false, visible: visible, onMissing: closeSelf })
10535
+ ? h(DocumentPane, { ctx: ctx, t: t, locale: locale, scope: scope, path: filePath, local: false, visible: visible, onMissing: closeSelf, onOpenLink: openPreviewLink })
10404
10536
  : h(RemoteFileEditor, {
10405
10537
  ctx: ctx, t: t, locale: locale,
10406
10538
  scope: scope,
@@ -10410,7 +10542,9 @@ function rememberShowHidden(value) {
10410
10542
  sessionId: props.scope ? props.scope.sessionId : undefined,
10411
10543
  onMissing: closeSelf,
10412
10544
  });
10413
- return h('div', { className: 'rw-editor-pane' }, pane);
10545
+ return h('div', { className: 'rw-editor-pane' },
10546
+ linkNote ? h('div', { style: { padding: '6px 10px 0' } }, h(Banner, { kind: 'warn', onClose: function () { setLinkNote(''); } }, linkNote)) : null,
10547
+ pane);
10414
10548
  }
10415
10549
 
10416
10550
  // ── tree ───────────────────────────────────────────────────────────────
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.28.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",