dsh-linked-workspace 0.29.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,42 @@
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
+
32
+ ## 0.30.0 — 2026-11-27
33
+
34
+ - A file link in a chat message that points into a remote workspace now opens **inside that workspace's tree
35
+ tab**, as one of its file tabs — not as a sibling of the directory tab, and not as a native tab that could
36
+ only report "file not found" (DSH resolves `/data/x.md` against the drive, so the path arrives as
37
+ `\data\x.md`). Asking for the same file again switches to the tab that is already open; a link to a folder
38
+ expands the tree and scrolls to it without opening anything.
39
+
3
40
  ## 0.29.0 — 2026-11-27
4
41
 
5
42
  - A folder link in a Markdown preview no longer opens a file tab that could only fail. A trailing separator
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:…` 指纹)。
@@ -470,6 +504,14 @@ DSH_HOME/linked-workspace/exec-audit.jsonl` 追加一行 JSON,含 `auditId`、
470
504
  5. 目录栏标题右侧的可用空间芯片:点「刷新目录」后它的 title(可用 / 已用 / 总量)随之更新,不再永远停在首次打开面板时的数值。
471
505
  6. 把窗口最小化或切到别的应用 30 秒再回来:占位目录转交仍在工作(后台不轮询、回到前台立刻补一次),并且这段时间没有产生额外的网络请求。
472
506
 
507
+ ## 聊天里的文件链接(Unreleased)
508
+
509
+ 1. 在联动工作区的会话里,让模型输出一个**远端绝对路径**(例如 `/shared_data_ssd1/huangjh/docs/note.md`)并点它:右侧栏不应该再出现「文件不存在:\shared_data_ssd1\…」的原生标签,而是右侧栏只多出/聚焦该工作区的**目录树标签**,文件作为它的一个内部文件标签打开并显示内容(不是与目录标签同级的独立标签)。
510
+ 2. 同一条链接再点一次:只切到那个已经打开的文件标签,标签数量不变(侧栏仍只有一个目录树标签)。
511
+ 3. 让模型输出一个**远端目录**(`/shared_data_ssd1/huangjh/chatdir/`,带不带尾斜杠都试):目录树展开到该目录并滚动定位,**不新建**文件标签。
512
+ 4. 点一个**本地**文件链接(`D:\…\note.md`):仍然由原生标签打开,不被接管。
513
+ 5. 断开该主机的 SSH 连接后再点远端链接:不崩溃、不白屏;无法认证时保持原样(交接只在路径确实属于某个工作区时发生)。
514
+
473
515
  ## 预览里的链接(Unreleased)
474
516
 
475
517
  1. 在一份 Markdown 预览里点一个**指向同目录另一个文件**的相对链接(`other.md`、`./sub/a.md`、`../latex/table.tex`):目标文件在同一个文件面板里打开,地址栏不变,页面不跳转;目标已经打开时只切到那个标签,不新开重复标签。
package/lib/client.js CHANGED
@@ -2368,6 +2368,8 @@ function isInsideRoot(root, target) {
2368
2368
  // host, and the panel that owns the tab does not carry the workspace root.
2369
2369
  // The two lists change rarely, so one lookup serves every click for 30 s.
2370
2370
  var scopeRootState = { at: 0, roots: null };
2371
+ // Same idea, but keeping the records: a hand-over needs the workspace name.
2372
+ var workspaceIndexState = { at: 0, index: null };
2371
2373
  function scopeRootOf(scope) {
2372
2374
  if (!scope || (scope.kind !== 'linked' && scope.kind !== 'remote')) return Promise.resolve('');
2373
2375
  var key = scope.kind + ':' + (scope.id || '');
@@ -2387,11 +2389,56 @@ function isInsideRoot(root, target) {
2387
2389
  });
2388
2390
  }
2389
2391
 
2392
+ // Chat links open native tabs inside the sidebar's own adapter, and the tabs
2393
+ // we open land in that very list too. Remember the ids we created so the
2394
+ // hand-over below never mistakes its own work for something to take over.
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();
2404
+
2405
+ function nativeTabKeys(sidebar) {
2406
+ try {
2407
+ var tabs = sidebar.nativePathTabs() || [];
2408
+ var keys = [];
2409
+ for (var index = 0; index < tabs.length; index += 1) {
2410
+ keys.push(String(tabs[index].sessionId || '') + '|' + String(tabs[index].id || ''));
2411
+ }
2412
+ return keys;
2413
+ } catch (error) {
2414
+ return null;
2415
+ }
2416
+ }
2417
+
2418
+ // The sidebar publishes the tab on its next render, so the diff runs on the
2419
+ // following task rather than inline.
2420
+ function claimNewNativeTabs(sidebar, known) {
2421
+ if (!known) return;
2422
+ setTimeout(function () {
2423
+ var keys = nativeTabKeys(sidebar);
2424
+ if (!keys) return;
2425
+ for (var index = 0; index < keys.length; index += 1) {
2426
+ if (known.indexOf(keys[index]) < 0) {
2427
+ if (ownedNativeTabs.size > 200) ownedNativeTabs.clear();
2428
+ ownedNativeTabs.add(keys[index]);
2429
+ }
2430
+ }
2431
+ }, 0);
2432
+ }
2433
+
2390
2434
  function openRemoteFileTab(sidebar, scope, source, filePath) {
2391
2435
  if (!sidebar || typeof sidebar.openTab !== 'function') return false;
2392
2436
  var key = scopeKeyOf(sourceScopeOf(source)) + ':' + filePath;
2393
2437
  var kind = remoteFileSlotFor(key);
2394
2438
  if (kind === undefined) return false;
2439
+ var known = nativeTabKeys(sidebar);
2440
+ // The slot id is the identity, so asking for the same file again focuses
2441
+ // the tab that is already open instead of stacking a second one.
2395
2442
  sidebar.openTab({
2396
2443
  type: kind,
2397
2444
  id: kind,
@@ -2399,6 +2446,37 @@ function isInsideRoot(root, target) {
2399
2446
  path: filePath,
2400
2447
  meta: sourceMetaOf(source),
2401
2448
  }, scope);
2449
+ claimNewNativeTabs(sidebar, known);
2450
+ return true;
2451
+ }
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);
2402
2480
  return true;
2403
2481
  }
2404
2482
 
@@ -2414,8 +2492,15 @@ function isInsideRoot(root, target) {
2414
2492
  meta.revealPath = options.relative || '';
2415
2493
  meta.revealSide = options.side === 'local' ? 'local' : 'remote';
2416
2494
  meta.revealAt = String(Date.now());
2495
+ // A folder has no file to open, so the panel reveals it in the tree.
2496
+ if (options.dir) meta.revealKind = 'dir';
2417
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;
2418
2502
  sidebar.openTab({ type: type, id: type, title: t(remoteOnly ? 'remoteTabTitle' : 'tabTitle'), path: '/', meta: meta }, scope);
2503
+ if (known) claimNewNativeTabs(sidebar, known);
2419
2504
  return true;
2420
2505
  } catch (error) {
2421
2506
  return false;
@@ -2732,6 +2817,11 @@ function isInsideRoot(root, target) {
2732
2817
  previewTooLarge: '这个文件太大({{chars}} 字符,上限 {{limit}}),没有生成预览;可以在编辑器里查看,或下载后用别的工具打开。',
2733
2818
  previewTooLargeBytes: '这个文件太大({{bytes}}),没有生成预览;可以在编辑器里查看,或下载后用别的工具打开。',
2734
2819
  fileGone: '这个文件已不在远端(可能被重命名或删除),已关闭它的标签并刷新目录。',
2820
+ outsideNote: '这个路径在工作区之外,插件还没有读取它的权限。',
2821
+ outsideAddRoot: '把 {{dir}} 加入额外根目录并打开',
2822
+ outsideBadge: '工作区外',
2823
+ outsideBinary: '二进制文件,无法在这里预览({{size}})。',
2824
+ outsideTruncated: '文件较大,只显示前 {{size}}。',
2735
2825
  linkOutside: '这个链接指向工作区之外,没有打开:{{path}}',
2736
2826
  linkFolder: '这是文件夹链接,这里只打开文件:{{path}}',
2737
2827
  linkedTitle: '联动工作区',
@@ -3338,6 +3428,11 @@ function isInsideRoot(root, target) {
3338
3428
  previewTooLarge: 'Too large to preview ({{chars}} characters, the ceiling is {{limit}}). Read it in the editor, or download it and open it elsewhere.',
3339
3429
  previewTooLargeBytes: 'Too large to preview ({{bytes}}). Read it in the editor, or download it and open it elsewhere.',
3340
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.',
3341
3436
  linkOutside: 'That link points outside the workspace, so it was left alone: {{path}}',
3342
3437
  linkFolder: 'That link is a folder; only files open here: {{path}}',
3343
3438
  linkedTitle: 'Linked workspaces',
@@ -8544,12 +8639,17 @@ function rememberShowHidden(value) {
8544
8639
  useEffect(function () {
8545
8640
  var wanted = tabMeta.revealPath ? String(tabMeta.revealPath) : '';
8546
8641
  if (!wanted || !selected) return;
8547
- var stamp = String(tabMeta.revealAt || '') + ':' + wanted;
8642
+ var stamp = String(tabMeta.revealAt || '') + ':' + wanted + ':' + String(tabMeta.revealKind || '');
8548
8643
  if (revealedRef.current === stamp) return;
8549
8644
  revealedRef.current = stamp;
8550
8645
  var side = tabMeta.revealSide === 'local' && !remoteOnly ? 'local' : 'remote';
8646
+ if (tabMeta.revealKind === 'dir') {
8647
+ // Nothing to open: land the reader on the folder in the tree.
8648
+ setRevealDir({ side: side, path: wanted, at: Date.now() });
8649
+ return;
8650
+ }
8551
8651
  openInternalFile(side, wanted, { pinned: true });
8552
- }, [tabMeta.revealPath, tabMeta.revealAt, tabMeta.revealSide, selected && selected.key]);
8652
+ }, [tabMeta.revealPath, tabMeta.revealAt, tabMeta.revealSide, tabMeta.revealKind, selected && selected.key]);
8553
8653
 
8554
8654
  var scopeRef = selected ? sourceScopeOf(selected) : null;
8555
8655
 
@@ -10599,6 +10699,77 @@ function rememberShowHidden(value) {
10599
10699
  dialog ? renderDialog() : null);
10600
10700
  }
10601
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
+
10602
10773
  function RemoteFileTab(props) {
10603
10774
  var ctx = props.ctx;
10604
10775
  var t = props.t;
@@ -10643,6 +10814,9 @@ function rememberShowHidden(value) {
10643
10814
  // re-reads this file: probe it now and then and reclaim the tab once the
10644
10815
  // path is gone (a rename inside a session is the usual cause).
10645
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 */ };
10646
10820
  var cancelled = false;
10647
10821
  var timer = setInterval(function () {
10648
10822
  if (typeof document !== 'undefined' && document.visibilityState === 'hidden') return;
@@ -10654,7 +10828,9 @@ function rememberShowHidden(value) {
10654
10828
  return function () { cancelled = true; clearInterval(timer); };
10655
10829
  }, [filePath, scope.kind, scope.id]);
10656
10830
 
10657
- var pane = docKind === 'image'
10831
+ var pane = meta.outside === true
10832
+ ? h(OutsideFileView, { t: t, locale: locale, scope: scope, filePath: filePath })
10833
+ : docKind === 'image'
10658
10834
  ? h(ImagePreview, { ctx: ctx, t: t, locale: locale, scope: scope, path: filePath, local: false })
10659
10835
  : docKind === 'html'
10660
10836
  ? h(HtmlPreview, { ctx: ctx, t: t, locale: locale, scope: scope, path: filePath, local: false })
@@ -11603,10 +11779,15 @@ function rememberShowHidden(value) {
11603
11779
  var modalNodeState = useState(null);
11604
11780
  var modalNode = modalNodeState[0];
11605
11781
  var setModalNode = modalNodeState[1];
11606
- 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) {
11607
11788
  modalRef.current = node;
11608
- if (node !== modalNode) setModalNode(node);
11609
- };
11789
+ setModalNode(node);
11790
+ }, []);
11610
11791
  var focusablesOf = function () {
11611
11792
  var node = modalRef.current;
11612
11793
  if (!node) return [];
@@ -11615,10 +11796,17 @@ function rememberShowHidden(value) {
11615
11796
  function (element) { return !element.disabled && element.offsetParent !== null; });
11616
11797
  };
11617
11798
 
11799
+ var focusSigRef = useRef('');
11618
11800
  useEffect(function () {
11619
- if (!props.open) return;
11801
+ if (!props.open) { focusSigRef.current = ''; return; }
11620
11802
  var node = modalRef.current;
11621
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;
11622
11810
  // Focus the first real field, not the tab strip, so typing works at once.
11623
11811
  var target = node.querySelector('.rw-modal-body input, .rw-modal-body textarea') || focusablesOf()[0];
11624
11812
  if (target && typeof target.focus === 'function') target.focus();
@@ -13519,9 +13707,45 @@ function rememberShowHidden(value) {
13519
13707
  var PLACEHOLDER_PATH = /[\\/]remote-placeholders[\\/]([^\\/]+)([\\/].*)$/i;
13520
13708
 
13521
13709
  function installPlaceholderHandover(ctx) {
13522
- var sidebar = sidebarService(ctx);
13523
- if (!sidebar || typeof sidebar.nativePathTabs !== 'function' || typeof sidebar.subscribeState !== 'function') return;
13524
- 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;
13525
13749
  var known = null;
13526
13750
  var knownAt = 0;
13527
13751
  var scanning = false;
@@ -13553,10 +13777,294 @@ function rememberShowHidden(value) {
13553
13777
  try { sidebar.closeTab(tab.id, scope); } catch (error) { /* the page is gone already */ }
13554
13778
  }
13555
13779
 
13780
+ // A chat link to a remote file reaches the sidebar as a native tab whose
13781
+ // path DSH resolved against the drive ("\data\x.md"), and the native
13782
+ // viewer can only report "file not found". Paths that land inside one of
13783
+ // our workspaces are ours: open the file in our own tab, or reveal the
13784
+ // folder in the tree when the link points at one.
13785
+ var probing = new Set();
13786
+
13787
+ function workspaceIndex() {
13788
+ if (workspaceIndexState.index && Date.now() - workspaceIndexState.at < 30000) {
13789
+ return Promise.resolve(workspaceIndexState.index);
13790
+ }
13791
+ return Promise.all([
13792
+ apiCall('linked.list').then(function (result) { return (result && result.links) || []; }, function () { return []; }),
13793
+ apiCall('remote_workspaces.list').then(function (result) { return (result && result.workspaces) || []; }, function () { return []; }),
13794
+ ]).then(function (both) {
13795
+ var index = { linked: both[0] || [], remote: both[1] || [] };
13796
+ workspaceIndexState = { at: Date.now(), index: index };
13797
+ return index;
13798
+ });
13799
+ }
13800
+
13801
+ function recordOf(index, scoped) {
13802
+ var list = scoped.linkedId ? index.linked : index.remote;
13803
+ var id = scoped.linkedId || scoped.remoteId;
13804
+ for (var cursor = 0; cursor < list.length; cursor += 1) {
13805
+ if (list[cursor] && list[cursor].id === id) return list[cursor];
13806
+ }
13807
+ return null;
13808
+ }
13809
+
13810
+ function takeRemotePath(tab, normalized) {
13811
+ if (normalized === '') return;
13812
+ // A drive path is the user's own disk. Only root-relative paths can be
13813
+ // the remote file DSH mangled into "\data\x.md".
13814
+ if (/^[A-Za-z]:[\\/]/.test(normalized)) return;
13815
+ var candidate = normalized;
13816
+ var key = String(tab.sessionId || '') + '|' + String(tab.id || '');
13817
+ if (ownedNativeTabs.has(key)) return;
13818
+ if (handled.has(key) || probing.has(key)) return;
13819
+ var scope = { sessionId: tab.sessionId };
13820
+ if (tab.cwd) scope.cwd = tab.cwd;
13821
+ if (probing.size > 50) probing.clear();
13822
+ probing.add(key);
13823
+ scanReferenceScope(String(tab.cwd || ''), '')
13824
+ .then(function (scoped) {
13825
+ if (!scoped || !scoped.root) return undefined;
13826
+ return workspaceIndex().then(function (index) {
13827
+ var owner = recordOf(index, scoped);
13828
+ if (!owner) return undefined;
13829
+ var root = String(scoped.root);
13830
+ var absolute;
13831
+ if (candidate.charAt(0) === '/') {
13832
+ absolute = root.charAt(0) === '/' ? candidate : candidate.replace(/\//g, '\\');
13833
+ } else {
13834
+ // The sidebar may have stored a workspace-relative path.
13835
+ absolute = root.replace(/[\/]+$/, '') + (root.charAt(0) === '/' ? '/' : '\\') + candidate.replace(/^[\/]+/, '');
13836
+ }
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
+ }
13855
+ if (handled.size > 200) handled.clear();
13856
+ handled.add(key);
13857
+ var kind = scoped.linkedId ? 'linked' : 'remote';
13858
+ var stat = apiCall('fs.stat', scoped.linkedId
13859
+ ? { linkedId: scoped.linkedId, path: absolute }
13860
+ : { remoteId: scoped.remoteId, path: absolute });
13861
+ return stat.then(function (result) {
13862
+ return result && result.type ? String(result.type) : '';
13863
+ }, function () { return ''; }).then(function (type) {
13864
+ if (type === 'dir' || type === 'directory') {
13865
+ var opened = openTreeTabAt(ctx, { kind: kind, id: owner.id, side: 'remote', relative: absolute, dir: true }, scope);
13866
+ if (!opened) return;
13867
+ } else {
13868
+ // A file belongs under the workspace's own tree tab, as one of
13869
+ // its file tabs — not as a sibling of the directory tab.
13870
+ var shown = openTreeTabAt(ctx, { kind: kind, id: owner.id, side: 'remote', relative: absolute }, scope);
13871
+ if (!shown) return;
13872
+ }
13873
+ try { sidebar.closeTab(tab.id, scope); } catch (error) { /* the page is gone already */ }
13874
+ });
13875
+ });
13876
+ })
13877
+ .catch(function () { /* not ours after all */ })
13878
+ .then(function () { probing.delete(key); }, function () { probing.delete(key); });
13879
+ }
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
+
13556
14064
  function handOver(tab) {
13557
14065
  var normalized = String(tab && tab.path ? tab.path : '').replace(/\\/g, '/');
13558
14066
  var match = PLACEHOLDER_PATH.exec(normalized);
13559
- if (!match) return;
14067
+ if (!match) { takeRemotePath(tab, normalized); return; }
13560
14068
  var relative = String(match[2] || '').replace(/^\/+/, '');
13561
14069
  // Directories and extension-less names are not ours to render.
13562
14070
  if (relative === '' || /\/$/.test(relative) || !/\.[^./]+$/.test(relative)) return;
@@ -13586,6 +14094,19 @@ function rememberShowHidden(value) {
13586
14094
  scanning = true;
13587
14095
  try {
13588
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
+ }
14103
+ if (ownedNativeTabs.size > 0) {
14104
+ var live = new Set();
14105
+ for (var cursor = 0; cursor < tabs.length; cursor += 1) {
14106
+ live.add(String(tabs[cursor].sessionId || '') + '|' + String(tabs[cursor].id || ''));
14107
+ }
14108
+ ownedNativeTabs.forEach(function (item) { if (!live.has(item)) ownedNativeTabs.delete(item); });
14109
+ }
13589
14110
  for (var index = 0; index < tabs.length; index += 1) handOver(tabs[index]);
13590
14111
  } catch (error) {
13591
14112
  /* a sidebar without path tabs simply never hands over */
@@ -13594,14 +14115,22 @@ function rememberShowHidden(value) {
13594
14115
  }
13595
14116
  }
13596
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();
13597
14122
  scan();
13598
14123
  // Native right-column tabs live in the sidebar's own adapter and never
13599
14124
  // reach the shared store, so `subscribeState` stays silent when one opens
13600
14125
  // — the interval is what actually catches them. It only runs the prefix
13601
14126
  // test, so a tick costs nothing when nothing is open.
13602
- 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 () {
13603
14132
  var stop = sidebar.subscribeState(scan);
13604
- var timer = setInterval(scan, 2000);
14133
+ var timer = setInterval(scan, 800);
13605
14134
  // A hand-over skipped while the window was hidden has to happen as soon
13606
14135
  // as it is back, otherwise the click looks like it did nothing.
13607
14136
  function onVisibility() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-linked-workspace",
3
- "version": "0.29.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",