dsh-linked-workspace 0.30.0 → 0.31.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,34 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.31.0 — 2026-11-28
4
+
5
+ - Closing a chat-linked tab no longer brings it back, and activating another native tab no longer
6
+ resurrects the old "file not found" page: once an outside path has its read-only tab, the hand-over stops
7
+ opening it again and closes the stale native duplicate instead. The claim's memory now survives a replaced
8
+ sidebar service, which is what made the tab reappear after switching tabs.
9
+
10
+
11
+ - A chat link that points **outside every workspace root** but at a file on the same host no longer
12
+ ends as a native "file not found" tab. The plugin claims it like the other links and opens a read-only
13
+ tab that reads through the "extra roots" gate; when the path is not allow-listed yet the tab offers
14
+ one-click "add this folder to the extra roots and open it". Folders and the user's own disk keep the
15
+ native viewer.
16
+
17
+
18
+ - The claim now survives a late `dsh-better-sidebar`: its client service can register **after** this plugin
19
+ (that is what happens on the desktop profile), and the hand-over used to give up at apply time. It is retried
20
+ once a second instead, so chat links stop falling through to the native tab even when the companion loads
21
+ late. `openFile` — the path `@` references use — is claimed the same way, and the workspace index is warmed
22
+ at install so the first click does not wait for `linked.list` over SSH.
23
+ - A chat file link now opens straight in its workspace tab: the sidebar's `openTab({ type: 'editor' })` call is
24
+ claimed **before** the native tab exists, so the "file not found" page no longer flashes for a second or two
25
+ while the hand-over catches up. Paths outside the workspaces (the user's own disk, POSIX paths elsewhere)
26
+ fall back to the native viewer unchanged.
27
+ - Typing a workspace name no longer jumps the caret back into the directory field. The dialog's portal ref was
28
+ re-created on every render, so React detached it with `null` and re-attached it each commit; that state change
29
+ re-ran the "focus the first field" effect after every keystroke. The ref callback is stable now, and the
30
+ effect focuses once per opened dialog and once per tab switch.
31
+
3
32
  ## 0.30.0 — 2026-11-27
4
33
 
5
34
  - A file link in a chat message that points into a remote workspace now opens **inside that workspace's tree
package/docs/VERIFY.md CHANGED
@@ -2,6 +2,30 @@
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. 联动工作区根目录在 `/shared_data_ssd1/huangjh`,准备一个 `/shared_data_hdd1/huangjh/probe.txt`,
8
+ 在会话里点击指向它的链接:**不应**出现原生「文件不存在」标签,而是一个标题带「工作区外」的只读标签。
9
+ 2. 该标签在额外根目录还为空时显示「把 … 加入额外根目录并打开」按钮;点一下,文件内容立刻出现,
10
+ 「设置 → 联动工作区 → 额外根目录」里也多出该前缀。
11
+ 3. 再加一个已允许路径下的文件链接:直接显示内容,没有按钮。
12
+ 4. 指向**文件夹**的工作区外链接(含尾斜杠,或指向一个真实目录)只给一句「这是文件夹链接…」,不提供按钮。
13
+ 5. 工作区内的文件链接仍落在目录树标签内部的文件标签;本地磁盘路径仍由原生标签打开。
14
+ 6. 关掉那个「工作区外」标签,等 5 秒:**不得**自己重开,也不得再出现原生「文件不存在」标签。
15
+ 7. 接着打开一个本地文件的原生标签并激活它:那个工作区外标签**不得**跟着冒出来;再点同一条聊天链接时
16
+ 仍应正常打开(记忆只拦住接管逻辑,不拦用户操作)。
17
+
18
+ ## 聊天链接直达与表单焦点(未发布)
19
+
20
+ 1. 在联动工作区会话里,让模型输出一个远端文件的绝对路径(例如 `/data/proj/a.md`),点击聊天里的那个链接:
21
+ **不应**先出现「文件不存在」的原生标签,而应直接在工作区目录树标签内部多出 `a.md`;从点击到出现内容应
22
+ 在一秒内。
23
+ 2. 再点同一个链接:只在已有内部标签之间切换,不新增标签,也不出现原生标签。
24
+ 3. 点一个指向远端**目录**的链接:目录树展开并滚到该目录,标签条不新增。
25
+ 4. 点一个位于**本机磁盘**(工作区之外)的文件链接:仍由原生查看器打开,说明接管只挑工作区内的路径。
26
+ 5. 打开「添加工作区」对话框,在「2. 工作区名称」里连续输入 20 个以上字符:光标应始终留在名称输入框,
27
+ 不再跳到「1. 本地目录」;切换顶部标签后再次输入,焦点仍按标签正确落位。
28
+
5
29
  ## 预览链接的文件夹与并行打开(未发布)
6
30
 
7
31
  1. 在一份 Markdown 里写 `[sub/](sub/)` 与 `[sub](sub)`(`sub` 是真实存在的目录),预览里先后点这两条:都只出
@@ -15,6 +39,16 @@ Host code (lib/) reloads live with `plugin_manager set_plugin include:linked-wor
15
39
  先后点击两者:只应存在一个 `note.md` 标签。
16
40
  6. 切换系统深浅色主题:界面跟随,控制台无报错(宿主提供 `theme/change` 事件时不依赖 1.5 秒轮询)。
17
41
 
42
+ ## 配套插件晚到时仍然直达(未发布)
43
+
44
+ 1. 完全退出 DSH 后重启,确认 `dsh-better-sidebar` 的客户端服务比本插件注册得更晚(桌面 profile 常见):
45
+ 打开联动工作区目录标签,点一个聊天里的远端文件链接,**不应**出现原生「文件不存在」标签,而应直接落进
46
+ 目录树的文件标签;重复点同一链接只切换、不新增。
47
+ 2. 通过 `@` 引用(走 `openFile`)打开一个远端文件:同样落在目录树标签内部,不开原生标签。
48
+ 3. 首次点击不应等待数秒:工作区索引在接管安装时已预热,`linked.list` 走 SSH 的耗时不再落在第一次点击上。
49
+ 4. 断网或主机不可达时点聊天链接:控制台无未捕获异常。此时工作区索引取不到,允许先出现原生标签;等主机恢复、
50
+ 索引重建后,兜底扫描应在两秒内把内容搬进目录树标签并关掉那个原生标签。
51
+
18
52
  ## 主机密钥与输出编码(0.20.0)
19
53
 
20
54
  1. 设置 → 联动工作区 → 「SSH 主机密钥与输出编码」应能看到「主机密钥策略」(tofu / strict)、「远端命令输出编码」(utf8 / gbk),以及已记住的主机列表(每行显示 `host:port` 与 `SHA256:…` 指纹)。
package/lib/client.js CHANGED
@@ -2393,6 +2393,14 @@ function isInsideRoot(root, target) {
2393
2393
  // we open land in that very list too. Remember the ids we created so the
2394
2394
  // hand-over below never mistakes its own work for something to take over.
2395
2395
  var ownedNativeTabs = new Set();
2396
+ // The hand-over is re-installed whenever the sidebar service is replaced, so
2397
+ // its memory has to live out here: forgetting which tabs were already taken
2398
+ // makes a closed tab come back on the next tick.
2399
+ var handedNativeTabs = new Set();
2400
+ var outsideSeenPaths = new Set();
2401
+ // sessionId -> cwd, learned from the native path tabs, so an outside link
2402
+ // can be mapped to its workspace before any tab of ours exists.
2403
+ var sessionCwds = new Map();
2396
2404
 
2397
2405
  function nativeTabKeys(sidebar) {
2398
2406
  try {
@@ -2442,6 +2450,36 @@ function isInsideRoot(root, target) {
2442
2450
  return true;
2443
2451
  }
2444
2452
 
2453
+ // The folder that has to be allow-listed before an outside path is readable.
2454
+ function outsideDirOf(filePath) {
2455
+ var cut = filePath.lastIndexOf('/')
2456
+ return cut > 0 ? filePath.slice(0, cut) : filePath
2457
+ }
2458
+
2459
+ // A chat link may point at a file that is not inside any workspace root yet
2460
+ // still lives on the same host (artefacts written next to the working copy).
2461
+ // The workspace tree cannot reach it, so open a read-only tab that reads
2462
+ // through the "extra roots" gate instead of letting the native viewer report
2463
+ // "file not found" for a path it never could read.
2464
+ function openOutsideFileTab(sidebar, scope, scoped, filePath) {
2465
+ if (!sidebar || typeof sidebar.openTab !== 'function') return false;
2466
+ var source = scoped.linkedId
2467
+ ? { kind: 'linked', id: scoped.linkedId, name: '' }
2468
+ : scoped.remoteId
2469
+ ? { kind: 'remote', id: scoped.remoteId, name: '' }
2470
+ : null;
2471
+ if (!source) return false;
2472
+ var key = 'outside:' + scopeKeyOf(sourceScopeOf(source)) + ':' + filePath;
2473
+ var kind = remoteFileSlotFor(key);
2474
+ if (kind === undefined) return false;
2475
+ var meta = sourceMetaOf(source);
2476
+ meta.outside = true;
2477
+ var known = nativeTabKeys(sidebar);
2478
+ sidebar.openTab({ type: kind, id: kind, title: basename(filePath), path: filePath, meta: meta }, scope);
2479
+ claimNewNativeTabs(sidebar, known);
2480
+ return true;
2481
+ }
2482
+
2445
2483
  // Chat artifacts live outside our tabs, so opening one has to travel
2446
2484
  // through the tab meta: the tab component reads revealPath on every render.
2447
2485
  function openTreeTabAt(ctx, options, scope) {
@@ -2457,7 +2495,12 @@ function isInsideRoot(root, target) {
2457
2495
  // A folder has no file to open, so the panel reveals it in the tree.
2458
2496
  if (options.dir) meta.revealKind = 'dir';
2459
2497
  try {
2498
+ // Mark it as ours right away: the tree tab stores the workspace root as
2499
+ // its path, and the hand-over would otherwise mistake it for a file that
2500
+ // needs rescuing.
2501
+ var known = typeof nativeTabKeys === 'function' ? nativeTabKeys(sidebar) : null;
2460
2502
  sidebar.openTab({ type: type, id: type, title: t(remoteOnly ? 'remoteTabTitle' : 'tabTitle'), path: '/', meta: meta }, scope);
2503
+ if (known) claimNewNativeTabs(sidebar, known);
2461
2504
  return true;
2462
2505
  } catch (error) {
2463
2506
  return false;
@@ -2774,6 +2817,11 @@ function isInsideRoot(root, target) {
2774
2817
  previewTooLarge: '这个文件太大({{chars}} 字符,上限 {{limit}}),没有生成预览;可以在编辑器里查看,或下载后用别的工具打开。',
2775
2818
  previewTooLargeBytes: '这个文件太大({{bytes}}),没有生成预览;可以在编辑器里查看,或下载后用别的工具打开。',
2776
2819
  fileGone: '这个文件已不在远端(可能被重命名或删除),已关闭它的标签并刷新目录。',
2820
+ outsideNote: '这个路径在工作区之外,插件还没有读取它的权限。',
2821
+ outsideAddRoot: '把 {{dir}} 加入额外根目录并打开',
2822
+ outsideBadge: '工作区外',
2823
+ outsideBinary: '二进制文件,无法在这里预览({{size}})。',
2824
+ outsideTruncated: '文件较大,只显示前 {{size}}。',
2777
2825
  linkOutside: '这个链接指向工作区之外,没有打开:{{path}}',
2778
2826
  linkFolder: '这是文件夹链接,这里只打开文件:{{path}}',
2779
2827
  linkedTitle: '联动工作区',
@@ -3380,6 +3428,11 @@ function isInsideRoot(root, target) {
3380
3428
  previewTooLarge: 'Too large to preview ({{chars}} characters, the ceiling is {{limit}}). Read it in the editor, or download it and open it elsewhere.',
3381
3429
  previewTooLargeBytes: 'Too large to preview ({{bytes}}). Read it in the editor, or download it and open it elsewhere.',
3382
3430
  fileGone: 'That file is gone from the remote side (renamed or deleted). Closed its tab and refreshed the tree.',
3431
+ outsideNote: 'That path sits outside the workspace, so the plugin is not allowed to read it yet.',
3432
+ outsideAddRoot: 'Add {{dir}} to the extra roots and open it',
3433
+ outsideBadge: 'Outside',
3434
+ outsideBinary: 'Binary file, so it cannot be previewed here ({{size}}).',
3435
+ outsideTruncated: 'Large file: only the first {{size}} is shown.',
3383
3436
  linkOutside: 'That link points outside the workspace, so it was left alone: {{path}}',
3384
3437
  linkFolder: 'That link is a folder; only files open here: {{path}}',
3385
3438
  linkedTitle: 'Linked workspaces',
@@ -10646,6 +10699,77 @@ function rememberShowHidden(value) {
10646
10699
  dialog ? renderDialog() : null);
10647
10700
  }
10648
10701
 
10702
+ // Read-only view for a path outside every workspace root. The host only
10703
+ // hands out such files when their prefix is in the extra roots, so an
10704
+ // unreadable path offers to add its folder instead of showing a raw error.
10705
+ function OutsideFileView(props) {
10706
+ var t = props.t;
10707
+ var locale = props.locale;
10708
+ var scope = props.scope;
10709
+ var filePath = props.filePath;
10710
+ var loadRef = useState({ loading: true, error: null, data: null });
10711
+ var load = loadRef[0];
10712
+ var setLoad = loadRef[1];
10713
+ var busyRef = useState(false);
10714
+ var busy = busyRef[0];
10715
+ var setBusy = busyRef[1];
10716
+
10717
+ function read() {
10718
+ setLoad(function (previous) { return { loading: true, error: null, data: previous.data }; });
10719
+ apiCall('fs.readOutside', Object.assign({ path: filePath, maxBytes: 262144 }, scopeParams(scope)))
10720
+ .then(function (result) {
10721
+ setLoad({ loading: false, error: null, data: result });
10722
+ }, function (error) {
10723
+ setLoad({ loading: false, error: error, data: null });
10724
+ });
10725
+ }
10726
+
10727
+ useEffect(function () { read(); }, [filePath, scope.kind, scope.id]);
10728
+
10729
+ function addRoot() {
10730
+ if (busy) return;
10731
+ setBusy(true);
10732
+ apiCall('settings.get').then(function (settings) {
10733
+ var roots = settings && Array.isArray(settings.extraRoots) ? settings.extraRoots.slice() : [];
10734
+ var dir = outsideDirOf(filePath);
10735
+ if (dir && roots.indexOf(dir) < 0) roots.push(dir);
10736
+ return apiCall('settings.update', { extraRoots: roots });
10737
+ }).then(function () {
10738
+ setBusy(false);
10739
+ read();
10740
+ }, function (error) {
10741
+ setBusy(false);
10742
+ setLoad({ loading: false, error: error, data: null });
10743
+ });
10744
+ }
10745
+
10746
+ var toolbar = h('div', { className: 'rw-doc-toolbar' },
10747
+ h('span', { className: 'rw-doc-badge' }, t('outsideBadge')),
10748
+ h('span', { className: 'rw-editor-path', title: filePath }, filePath));
10749
+ var body;
10750
+ if (load.loading) {
10751
+ body = h('div', { className: 'rw-doc-loading' }, h('div', { className: 'rw-spinner' }), h('span', null, t('loading')));
10752
+ } else if (load.error) {
10753
+ // A folder outside the workspace is not a permission problem: nothing
10754
+ // here can open it, so say so instead of offering an allow-list entry.
10755
+ var isDir = load.error.code === 'FS_IS_DIR' || load.error.code === 'FS_NOT_DIRECTORY';
10756
+ body = h('div', { className: 'rw-doc-body' },
10757
+ h(Banner, { kind: 'warn' }, messageOf(load.error, t, locale)),
10758
+ h('div', { className: 'rw-outside-actions' },
10759
+ isDir ? null : h('button', { className: 'rw-btn rw-btn-sm rw-btn-primary', disabled: busy, onClick: addRoot },
10760
+ t('outsideAddRoot', { dir: outsideDirOf(filePath) })),
10761
+ h('div', { className: 'rw-hint' }, isDir ? t('linkFolder', { path: filePath }) : t('outsideNote'))));
10762
+ } else {
10763
+ var data = load.data || {};
10764
+ body = h('div', { className: 'rw-doc-body' },
10765
+ data.truncated ? h(Banner, { kind: 'info' }, t('outsideTruncated', { size: formatBytes(data.size) })) : null,
10766
+ data.binary
10767
+ ? h('div', { className: 'rw-outside-actions' }, h('div', { className: 'rw-hint' }, t('outsideBinary', { size: formatBytes(data.size) })))
10768
+ : h('pre', { className: 'rw-outside-text' }, typeof data.content === 'string' ? data.content : ''));
10769
+ }
10770
+ return h('div', { className: 'rw-editor-pane' }, toolbar, body);
10771
+ }
10772
+
10649
10773
  function RemoteFileTab(props) {
10650
10774
  var ctx = props.ctx;
10651
10775
  var t = props.t;
@@ -10690,6 +10814,9 @@ function rememberShowHidden(value) {
10690
10814
  // re-reads this file: probe it now and then and reclaim the tab once the
10691
10815
  // path is gone (a rename inside a session is the usual cause).
10692
10816
  useEffect(function () {
10817
+ // An outside file has no workspace scope to stat; its own view handles
10818
+ // the reads and their errors.
10819
+ if (meta.outside === true) return function () { /* nothing to probe */ };
10693
10820
  var cancelled = false;
10694
10821
  var timer = setInterval(function () {
10695
10822
  if (typeof document !== 'undefined' && document.visibilityState === 'hidden') return;
@@ -10701,7 +10828,9 @@ function rememberShowHidden(value) {
10701
10828
  return function () { cancelled = true; clearInterval(timer); };
10702
10829
  }, [filePath, scope.kind, scope.id]);
10703
10830
 
10704
- var pane = docKind === 'image'
10831
+ var pane = meta.outside === true
10832
+ ? h(OutsideFileView, { t: t, locale: locale, scope: scope, filePath: filePath })
10833
+ : docKind === 'image'
10705
10834
  ? h(ImagePreview, { ctx: ctx, t: t, locale: locale, scope: scope, path: filePath, local: false })
10706
10835
  : docKind === 'html'
10707
10836
  ? h(HtmlPreview, { ctx: ctx, t: t, locale: locale, scope: scope, path: filePath, local: false })
@@ -11650,10 +11779,15 @@ function rememberShowHidden(value) {
11650
11779
  var modalNodeState = useState(null);
11651
11780
  var modalNode = modalNodeState[0];
11652
11781
  var setModalNode = modalNodeState[1];
11653
- var attachModal = function (node) {
11782
+ // A ref callback is re-created on every render, so React detaches it with
11783
+ // null and attaches it again on every commit; calling setModalNode(null)
11784
+ // there re-ran the focus effect just after each keystroke and pulled the
11785
+ // caret out of the name field and back into the first input. Keep the
11786
+ // callback stable so the node never flickers.
11787
+ var attachModal = useCallback(function (node) {
11654
11788
  modalRef.current = node;
11655
- if (node !== modalNode) setModalNode(node);
11656
- };
11789
+ setModalNode(node);
11790
+ }, []);
11657
11791
  var focusablesOf = function () {
11658
11792
  var node = modalRef.current;
11659
11793
  if (!node) return [];
@@ -11662,10 +11796,17 @@ function rememberShowHidden(value) {
11662
11796
  function (element) { return !element.disabled && element.offsetParent !== null; });
11663
11797
  };
11664
11798
 
11799
+ var focusSigRef = useRef('');
11665
11800
  useEffect(function () {
11666
- if (!props.open) return;
11801
+ if (!props.open) { focusSigRef.current = ''; return; }
11667
11802
  var node = modalRef.current;
11668
11803
  if (!node) return;
11804
+ // Focus once per opened dialog and once per tab switch — never on the
11805
+ // re-renders a keystroke causes, or typing a name jumps back to the
11806
+ // first field.
11807
+ var sig = String(flow);
11808
+ if (focusSigRef.current === sig) return;
11809
+ focusSigRef.current = sig;
11669
11810
  // Focus the first real field, not the tab strip, so typing works at once.
11670
11811
  var target = node.querySelector('.rw-modal-body input, .rw-modal-body textarea') || focusablesOf()[0];
11671
11812
  if (target && typeof target.focus === 'function') target.focus();
@@ -13566,9 +13707,45 @@ function rememberShowHidden(value) {
13566
13707
  var PLACEHOLDER_PATH = /[\\/]remote-placeholders[\\/]([^\\/]+)([\\/].*)$/i;
13567
13708
 
13568
13709
  function installPlaceholderHandover(ctx) {
13569
- var sidebar = sidebarService(ctx);
13570
- if (!sidebar || typeof sidebar.nativePathTabs !== 'function' || typeof sidebar.subscribeState !== 'function') return;
13571
- var handled = new Set();
13710
+ var installedFor = null;
13711
+ var stopHandover = null;
13712
+
13713
+ // better-sidebar registers its client service lazily, and on the desktop
13714
+ // profile it can come up after this plugin. A single check at apply time
13715
+ // used to leave chat links unclaimed for the whole session, which looked
13716
+ // exactly like the old "moved after two seconds" behaviour.
13717
+ function attach() {
13718
+ var sidebar = sidebarService(ctx);
13719
+ if (!sidebar || typeof sidebar.nativePathTabs !== 'function' || typeof sidebar.subscribeState !== 'function') return;
13720
+ if (installedFor === sidebar) return;
13721
+ if (stopHandover) {
13722
+ try { stopHandover(); } catch (error) { /* already torn down */ }
13723
+ }
13724
+ installedFor = sidebar;
13725
+ stopHandover = installHandover(ctx, sidebar);
13726
+ }
13727
+
13728
+ attach();
13729
+ // One object lookup per second; it also picks up a sidebar that is
13730
+ // replaced after a plugin reload.
13731
+ ctx.effect(function () {
13732
+ var timer = setInterval(attach, 1000);
13733
+ return function () {
13734
+ clearInterval(timer);
13735
+ if (stopHandover) {
13736
+ try { stopHandover(); } catch (error) { /* already torn down */ }
13737
+ stopHandover = null;
13738
+ }
13739
+ };
13740
+ }, 'dsh-linked-workspace: late sidebar hand-over');
13741
+ }
13742
+
13743
+ function installHandover(ctx, sidebar) {
13744
+ var handled = handedNativeTabs;
13745
+ // Paths for which we already opened an "outside" tab. If the user closes
13746
+ // that tab we must not open it again from the scan: the stale native tab
13747
+ // is closed, nothing reopens, and a later click goes through the claim.
13748
+ var outsideSeen = outsideSeenPaths;
13572
13749
  var known = null;
13573
13750
  var knownAt = 0;
13574
13751
  var scanning = false;
@@ -13657,7 +13834,24 @@ function rememberShowHidden(value) {
13657
13834
  // The sidebar may have stored a workspace-relative path.
13658
13835
  absolute = root.replace(/[\/]+$/, '') + (root.charAt(0) === '/' ? '/' : '\\') + candidate.replace(/^[\/]+/, '');
13659
13836
  }
13660
- if (!isInsideRoot(root, absolute)) return undefined;
13837
+ if (!isInsideRoot(root, absolute)) {
13838
+ // Outside this workspace but on the same host: keep the tab by
13839
+ // opening it read-only rather than leaving the native error.
13840
+ if (!outsideOpenable(absolute)) return undefined;
13841
+ var outsideKey = String(tab.sessionId || '') + '|' + absolute;
13842
+ if (!outsideSeen.has(outsideKey)) {
13843
+ if (outsideSeen.size > 200) outsideSeen.clear();
13844
+ outsideSeen.add(outsideKey);
13845
+ openOutside(scoped, absolute);
13846
+ }
13847
+ // The native tab cannot show this path, so it goes away for good
13848
+ // — otherwise closing our tab would resurrect it on the next
13849
+ // scan, and activating another native tab would bring it back.
13850
+ if (handled.size > 200) handled.clear();
13851
+ handled.add(key);
13852
+ try { sidebar.closeTab(tab.id, scope); } catch (error) { /* already gone */ }
13853
+ return undefined;
13854
+ }
13661
13855
  if (handled.size > 200) handled.clear();
13662
13856
  handled.add(key);
13663
13857
  var kind = scoped.linkedId ? 'linked' : 'remote';
@@ -13684,6 +13878,189 @@ function rememberShowHidden(value) {
13684
13878
  .then(function () { probing.delete(key); }, function () { probing.delete(key); });
13685
13879
  }
13686
13880
 
13881
+ // Chat links reach the sidebar as `openTab({ type: 'editor', path })` with
13882
+ // the path already resolved against the drive ("\data\x.md"), so waiting
13883
+ // for the native tab and moving it afterwards always shows a "file not
13884
+ // found" page first. Claim the tab before it exists: a path that lands
13885
+ // inside one of our workspaces opens straight in its tree tab, and the
13886
+ // caller never has a native tab to close.
13887
+ function ownerOfPath(index, normalized) {
13888
+ var best = null;
13889
+ function consider(list, kind) {
13890
+ for (var cursor = 0; cursor < list.length; cursor += 1) {
13891
+ var record = list[cursor];
13892
+ if (!record) continue;
13893
+ var root = String(record.remotePath || '').replace(/\/+$/, '');
13894
+ if (root === '' || root === '/') continue;
13895
+ if (normalized !== root && normalized.indexOf(root + '/') !== 0) continue;
13896
+ // The deepest root wins, so a workspace nested inside another one
13897
+ // keeps its own files.
13898
+ if (!best || root.length > best.root.length) best = { kind: kind, record: record, root: root };
13899
+ }
13900
+ }
13901
+ consider(index.linked || [], 'linked');
13902
+ consider(index.remote || [], 'remote');
13903
+ return best;
13904
+ }
13905
+
13906
+ // Native path tabs are the only place DSH shows us a session's cwd, so
13907
+ // remember it: an outside link has to be attributed to a host even before
13908
+ // its first tab exists.
13909
+ function currentSessionId() {
13910
+ try {
13911
+ var snapshot = typeof sidebar.getSnapshot === 'function' ? sidebar.getSnapshot() : null;
13912
+ return snapshot && snapshot.sessionId ? String(snapshot.sessionId) : '';
13913
+ } catch (error) {
13914
+ return '';
13915
+ }
13916
+ }
13917
+
13918
+ // The sidebar is not the only source of that cwd: the session list knows it
13919
+ // from the first moment, which is what makes an outside link land on the
13920
+ // right host before any tab of ours has ever been seen.
13921
+ function sessionCwdOf(sessionId) {
13922
+ var rememberedCwd = sessionId !== '' ? sessionCwds.get(sessionId) || '' : '';
13923
+ if (rememberedCwd !== '') return rememberedCwd;
13924
+ try {
13925
+ var service = ctx.sessions;
13926
+ var listing = service && service.list && typeof service.list.getSnapshot === 'function'
13927
+ ? service.list.getSnapshot()
13928
+ : null;
13929
+ var record = listing && listing.byId ? listing.byId[sessionId] : null;
13930
+ var cwd = record && typeof record.cwd === 'string' ? record.cwd : '';
13931
+ if (cwd !== '') sessionCwds.set(sessionId, cwd);
13932
+ return cwd;
13933
+ } catch (error) {
13934
+ return '';
13935
+ }
13936
+ }
13937
+
13938
+ // Only a file path can become an outside tab. A bare "/" is how the
13939
+ // sidebar stores its own directory tabs, and a trailing slash names a
13940
+ // folder the tree can reveal instead.
13941
+ function outsideOpenable(absolute) {
13942
+ if (typeof absolute !== 'string' || absolute.length < 2) return false;
13943
+ if (absolute.charAt(0) !== '/') return false;
13944
+ if (/\/$/.test(absolute)) return false;
13945
+ var base = absolute.slice(absolute.lastIndexOf('/') + 1);
13946
+ return base !== '' && base !== '.' && base !== '..';
13947
+ }
13948
+
13949
+ function openOutside(scoped, absolute) {
13950
+ var sessionId = currentSessionId();
13951
+ var scope = sessionId !== '' ? { sessionId: sessionId } : {};
13952
+ return openOutsideFileTab(sidebar, scope, scoped, absolute) === true;
13953
+ }
13954
+
13955
+ function claimScope(owner) {
13956
+ var scope = {};
13957
+ var sessionId = '';
13958
+ try {
13959
+ var snapshot = typeof sidebar.getSnapshot === 'function' ? sidebar.getSnapshot() : null;
13960
+ if (snapshot && snapshot.sessionId) sessionId = String(snapshot.sessionId);
13961
+ } catch (error) { /* no session on screen */ }
13962
+ if (sessionId !== '') scope.sessionId = sessionId;
13963
+ scope.cwd = owner.kind === 'linked'
13964
+ ? String(owner.record.localPath || '')
13965
+ : String(owner.record.placeholderPath || '');
13966
+ return scope;
13967
+ }
13968
+
13969
+ function takeSeed(normalized) {
13970
+ // DSH may keep the drive letter ("D:\data\x.md") or drop it
13971
+ // ("\data\x.md"); both spellings have to be tried against the roots.
13972
+ var candidates = [normalized];
13973
+ var stripped = normalized.replace(/^[A-Za-z]:/, '');
13974
+ if (stripped !== normalized && stripped.charAt(0) === '/') candidates.push(stripped);
13975
+ return workspaceIndex().then(function (index) {
13976
+ var found = null;
13977
+ for (var cursor = 0; cursor < candidates.length && !found; cursor += 1) {
13978
+ var owner = ownerOfPath(index, candidates[cursor]);
13979
+ if (owner) found = { owner: owner, absolute: candidates[cursor] };
13980
+ }
13981
+ if (!found) {
13982
+ // Not inside any workspace root: the link may still name a file on
13983
+ // the same host, which the workspace tree can never show.
13984
+ var outside = candidates[0];
13985
+ if (!outsideOpenable(outside)) return false;
13986
+ var sessionId = currentSessionId();
13987
+ var cwd = sessionCwdOf(sessionId);
13988
+ if (cwd === '') return false;
13989
+ return scanReferenceScope(cwd, '').then(function (scoped) {
13990
+ if (!scoped || !scoped.root) return false;
13991
+ // Remember it here too: a native duplicate that shows up later must
13992
+ // be closed rather than turned into a second copy of this tab.
13993
+ var outsideKey = sessionId + '|' + outside;
13994
+ if (outsideSeen.size > 200) outsideSeen.clear();
13995
+ outsideSeen.add(outsideKey);
13996
+ return openOutside(scoped, outside);
13997
+ }, function () { return false; });
13998
+ }
13999
+ var record = found.owner.record;
14000
+ var absolute = found.absolute;
14001
+ // A trailing separator or a file extension settles the kind without
14002
+ // a round trip; only an extension-less name has to be asked.
14003
+ var looksDir = /\/$/.test(absolute);
14004
+ var looksFile = !looksDir && /\.[^./]+$/.test(absolute);
14005
+ var open = function (dir) {
14006
+ return openTreeTabAt(ctx, {
14007
+ kind: found.owner.kind, id: record.id, side: 'remote',
14008
+ relative: absolute, dir: dir,
14009
+ }, claimScope(found.owner)) === true;
14010
+ };
14011
+ if (looksFile) return open(false);
14012
+ if (looksDir) return open(true);
14013
+ var stat = found.owner.kind === 'linked'
14014
+ ? apiCall('fs.stat', { linkedId: record.id, path: absolute })
14015
+ : apiCall('fs.stat', { remoteId: record.id, path: absolute });
14016
+ return stat.then(function (result) {
14017
+ var type = result && result.type ? String(result.type) : '';
14018
+ return open(type === 'dir' || type === 'directory');
14019
+ }, function () { return false; });
14020
+ });
14021
+ }
14022
+
14023
+ function installOpenTabClaim() {
14024
+ if (typeof sidebar.openTab !== 'function' || sidebar.__lwClaimed === true) return false;
14025
+ var original = sidebar.openTab;
14026
+ try {
14027
+ Object.defineProperty(sidebar, '__lwClaimed', { value: true, enumerable: false });
14028
+ } catch (error) { sidebar.__lwClaimed = true; }
14029
+ sidebar.openTab = function (seed, scope) {
14030
+ // Only "show me this file" goes through the claim; every other kind —
14031
+ // including the tabs this plugin opens itself — keeps the old path.
14032
+ if (!seed || seed.type !== 'editor' || typeof seed.path !== 'string') {
14033
+ return original.apply(sidebar, arguments);
14034
+ }
14035
+ var normalized = String(seed.path).replace(/\\/g, '/');
14036
+ // Only a path that could name one of our roots: "/data/x.md" or
14037
+ // "D:/data/x.md". A relative or UNC path stays native.
14038
+ if (normalized.charAt(0) !== '/' && /^[A-Za-z]:\//.test(normalized) === false) {
14039
+ return original.apply(sidebar, arguments);
14040
+ }
14041
+ takeSeed(normalized).then(function (claimed) {
14042
+ if (!claimed) original.call(sidebar, seed, scope);
14043
+ }, function () { original.call(sidebar, seed, scope); });
14044
+ return undefined;
14045
+ };
14046
+ // References open through openFile, not openTab; the same remote
14047
+ // path has to land in the tree there as well.
14048
+ var openFileOriginal = sidebar.openFile;
14049
+ if (typeof openFileOriginal === 'function') {
14050
+ sidebar.openFile = function (scope, path, title, options) {
14051
+ var args = arguments;
14052
+ var normalizedFile = typeof path === 'string' ? path.split(String.fromCharCode(92)).join('/') : '';
14053
+ var rooted = normalizedFile !== '' && (normalizedFile.charAt(0) === '/' || /^[A-Za-z]:\//.test(normalizedFile));
14054
+ if (!rooted) return openFileOriginal.apply(sidebar, args);
14055
+ takeSeed(normalizedFile).then(function (claimed) {
14056
+ if (!claimed) openFileOriginal.apply(sidebar, args);
14057
+ }, function () { openFileOriginal.apply(sidebar, args); });
14058
+ return undefined;
14059
+ };
14060
+ }
14061
+ return true;
14062
+ }
14063
+
13687
14064
  function handOver(tab) {
13688
14065
  var normalized = String(tab && tab.path ? tab.path : '').replace(/\\/g, '/');
13689
14066
  var match = PLACEHOLDER_PATH.exec(normalized);
@@ -13717,6 +14094,12 @@ function rememberShowHidden(value) {
13717
14094
  scanning = true;
13718
14095
  try {
13719
14096
  var tabs = sidebar.nativePathTabs() || [];
14097
+ for (var remember = 0; remember < tabs.length; remember += 1) {
14098
+ var remembered = tabs[remember];
14099
+ if (remembered && remembered.sessionId && remembered.cwd) {
14100
+ sessionCwds.set(String(remembered.sessionId), String(remembered.cwd));
14101
+ }
14102
+ }
13720
14103
  if (ownedNativeTabs.size > 0) {
13721
14104
  var live = new Set();
13722
14105
  for (var cursor = 0; cursor < tabs.length; cursor += 1) {
@@ -13732,14 +14115,22 @@ function rememberShowHidden(value) {
13732
14115
  }
13733
14116
  }
13734
14117
 
14118
+ // Claiming has to be installed before the first chat link is clicked; the
14119
+ // scan below stays as the safety net for a sidebar that owns a different
14120
+ // object than the one we patched.
14121
+ installOpenTabClaim();
13735
14122
  scan();
13736
14123
  // Native right-column tabs live in the sidebar's own adapter and never
13737
14124
  // reach the shared store, so `subscribeState` stays silent when one opens
13738
14125
  // — the interval is what actually catches them. It only runs the prefix
13739
14126
  // test, so a tick costs nothing when nothing is open.
13740
- ctx.effect(function () {
14127
+ // Warm the index now: the first click should not wait for two host
14128
+ // calls, and linked.list can take seconds over SSH.
14129
+ workspaceIndex();
14130
+
14131
+ return ctx.effect(function () {
13741
14132
  var stop = sidebar.subscribeState(scan);
13742
- var timer = setInterval(scan, 2000);
14133
+ var timer = setInterval(scan, 800);
13743
14134
  // A hand-over skipped while the window was hidden has to happen as soon
13744
14135
  // as it is back, otherwise the click looks like it did nothing.
13745
14136
  function onVisibility() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-linked-workspace",
3
- "version": "0.30.0",
3
+ "version": "0.31.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",