dsh-linked-workspace 0.30.0 → 0.32.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 +47 -0
- package/docs/API.md +1 -1
- package/docs/VERIFY.md +48 -0
- package/lib/client.js +561 -25
- package/lib/index.js +9 -2
- package/lib/ssh.js +14 -6
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,52 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.32.0 — 2026-11-29
|
|
4
|
+
|
|
5
|
+
- **Working outside the workspace is now readable, not truncated**: the read-only tab pages through a file
|
|
6
|
+
256 KiB at a time ("Load more" continues where the last window stopped), the footer shows "Showing X of Y"
|
|
7
|
+
plus the remote mtime, and it offers "Reload" and "Copy absolute address". Hitting the 4 MB ceiling says so
|
|
8
|
+
and points at downloading the file. Before this, only the first window was reachable and the banner
|
|
9
|
+
reported the file size as if it were what had been shown.
|
|
10
|
+
- **A full tab table no longer swallows the click**: file slots went from 12 to 24, and once they are all
|
|
11
|
+
taken a chat link is claimed instead of landing on the native "file not found" page (`slotFull`). Slot
|
|
12
|
+
recycling is not possible on this platform: the sidebar binds a tab kind to one tab for good, a closed kind
|
|
13
|
+
cannot be reopened, and `updateTab` repoints the address without re-rendering the plugin view.
|
|
14
|
+
- **Two roots with the same tail no longer steal each other's links**: a chat link is matched against the
|
|
15
|
+
session's own host first, then against the longest prefix.
|
|
16
|
+
- **The directory toolbar reads well with a screen reader**: its 12 icon buttons mirror their `title` into
|
|
17
|
+
`aria-label`.
|
|
18
|
+
- **Host**: `fs.readOutside` accepts `offset` and reports `returned` (paged reads), and `lib/ssh.js`'s
|
|
19
|
+
`readFile` can start anywhere in the file.
|
|
20
|
+
|
|
21
|
+
## 0.31.0 — 2026-11-28
|
|
22
|
+
|
|
23
|
+
- Closing a chat-linked tab no longer brings it back, and activating another native tab no longer
|
|
24
|
+
resurrects the old "file not found" page: once an outside path has its read-only tab, the hand-over stops
|
|
25
|
+
opening it again and closes the stale native duplicate instead. The claim's memory now survives a replaced
|
|
26
|
+
sidebar service, which is what made the tab reappear after switching tabs.
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
- A chat link that points **outside every workspace root** but at a file on the same host no longer
|
|
30
|
+
ends as a native "file not found" tab. The plugin claims it like the other links and opens a read-only
|
|
31
|
+
tab that reads through the "extra roots" gate; when the path is not allow-listed yet the tab offers
|
|
32
|
+
one-click "add this folder to the extra roots and open it". Folders and the user's own disk keep the
|
|
33
|
+
native viewer.
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
- The claim now survives a late `dsh-better-sidebar`: its client service can register **after** this plugin
|
|
37
|
+
(that is what happens on the desktop profile), and the hand-over used to give up at apply time. It is retried
|
|
38
|
+
once a second instead, so chat links stop falling through to the native tab even when the companion loads
|
|
39
|
+
late. `openFile` — the path `@` references use — is claimed the same way, and the workspace index is warmed
|
|
40
|
+
at install so the first click does not wait for `linked.list` over SSH.
|
|
41
|
+
- A chat file link now opens straight in its workspace tab: the sidebar's `openTab({ type: 'editor' })` call is
|
|
42
|
+
claimed **before** the native tab exists, so the "file not found" page no longer flashes for a second or two
|
|
43
|
+
while the hand-over catches up. Paths outside the workspaces (the user's own disk, POSIX paths elsewhere)
|
|
44
|
+
fall back to the native viewer unchanged.
|
|
45
|
+
- Typing a workspace name no longer jumps the caret back into the directory field. The dialog's portal ref was
|
|
46
|
+
re-created on every render, so React detached it with `null` and re-attached it each commit; that state change
|
|
47
|
+
re-ran the "focus the first field" effect after every keystroke. The ref callback is stable now, and the
|
|
48
|
+
effect focuses once per opened dialog and once per tab switch.
|
|
49
|
+
|
|
3
50
|
## 0.30.0 — 2026-11-27
|
|
4
51
|
|
|
5
52
|
- A file link in a chat message that points into a remote workspace now opens **inside that workspace's tree
|
package/docs/API.md
CHANGED
|
@@ -59,7 +59,7 @@ scope root, or absolute inside it.
|
|
|
59
59
|
| `hosts.hostKeys` | `{}` | `{ entries: [{ authority, fingerprint, firstSeen, hostId?, hostName? }] }` — the keys remembered in `known_hosts.json`; `hostId` is filled in when the authority still matches a configured host |
|
|
60
60
|
| `hosts.forgetHostKey` | `{ hostId?/authority? }` | `{ authority, removed }` — drops the stored key (and the live connection) so the next connect trusts the host again; `settings.hostKeyPolicy` decides whether an unknown key is accepted (`tofu`, default) or refused (`strict`) |
|
|
61
61
|
| `hosts.status` | `{ hostIds? }` | `{ statuses: { [hostId]: { state, reason?, message?, latencyMs?, checkedAt? } } }` (in-memory snapshot of the pool, never dials; an `error` older than 60 s is reported as `idle`; defaults to every known host of the host list plus every workspace's host id) |
|
|
62
|
-
| `fs.readOutside` | `{ linkedId?, remoteId?, path, maxBytes? }` | `{ path, size, mtime, binary, truncated, content }` (
|
|
62
|
+
| `fs.readOutside` | `{ linkedId?, remoteId?, path, maxBytes?, offset? }` | `{ path, size, mtime, binary, offset, returned, truncated, content }` (`offset` pages through a large file; `returned` is how many bytes this call read) |
|
|
63
63
|
| `fs.writeOutside` | `{ linkedId?, remoteId?, path, content, ifModifiedSince? }` | `{ path, size, mtime, created }` (8 MB limit; only under an `extraRoots` prefix; audited) |
|
|
64
64
|
| `fs.listOutside` | `{ linkedId?, remoteId?, path }` | `{ path, entries }` (only under an `extraRoots` prefix; audited) |
|
|
65
65
|
| `hosts.forward` | `{ hostId, remotePort, remoteHost?, localPort? }` | `{ forward: { id, hostId, hostName, remoteHost, remotePort, localPort, startedAt, url } }` (localhost TCP tunnel; reuses an identical one; the definition is written to `forwards.json`, so a restarted Host re-binds the same port) |
|
package/docs/VERIFY.md
CHANGED
|
@@ -1,7 +1,45 @@
|
|
|
1
1
|
# Manual verification checklist
|
|
2
2
|
|
|
3
|
+
## 工作区外的只读视图与标签位(未发布)
|
|
4
|
+
|
|
5
|
+
1. 联动工作区根目录在 `/shared_data_ssd1/huangjh`,准备一个 `/shared_data_hdd1/huangjh/big.jsonl`(≥ 300 KB,
|
|
6
|
+
且已在「额外根目录」里允许):在会话里点它的链接 → 出现「工作区外」只读标签。
|
|
7
|
+
2. 首屏显示 256 KB,页脚为「已显示 256 KB,共 374 KB」+「修改于 …」;点「加载更多」→ 显示全部、
|
|
8
|
+
页脚变成「已显示 374 KB,共 374 KB」且按钮消失。
|
|
9
|
+
3. 点「重新加载」→ 回到首屏;点「复制绝对地址」→ 剪贴板里是完整远端路径,页脚出现「已复制:…」。
|
|
10
|
+
4. 打开超过 4 MB 的工作区外文件:走到底后提示已达读取上限,不再无限追加。
|
|
11
|
+
5. 依次点开 25 条不同的聊天文件链接:前 24 条各占一个文件标签;第 25 条不会出现原生「文件不存在」页
|
|
12
|
+
(点击被接管,但没有空位可放)。
|
|
13
|
+
6. 目录栏悬停任意图标按钮:`aria-label` 与可见提示一致(读屏可念出)。
|
|
14
|
+
7. 两个工作区根目录尾段同名(如都是 `/x/huangjh`)时,点其中一个会话里的链接应落回该会话自己的主机。
|
|
15
|
+
|
|
16
|
+
|
|
3
17
|
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
18
|
|
|
19
|
+
## 工作区外的聊天链接(未发布)
|
|
20
|
+
|
|
21
|
+
1. 联动工作区根目录在 `/shared_data_ssd1/huangjh`,准备一个 `/shared_data_hdd1/huangjh/probe.txt`,
|
|
22
|
+
在会话里点击指向它的链接:**不应**出现原生「文件不存在」标签,而是一个标题带「工作区外」的只读标签。
|
|
23
|
+
2. 该标签在额外根目录还为空时显示「把 … 加入额外根目录并打开」按钮;点一下,文件内容立刻出现,
|
|
24
|
+
「设置 → 联动工作区 → 额外根目录」里也多出该前缀。
|
|
25
|
+
3. 再加一个已允许路径下的文件链接:直接显示内容,没有按钮。
|
|
26
|
+
4. 指向**文件夹**的工作区外链接(含尾斜杠,或指向一个真实目录)只给一句「这是文件夹链接…」,不提供按钮。
|
|
27
|
+
5. 工作区内的文件链接仍落在目录树标签内部的文件标签;本地磁盘路径仍由原生标签打开。
|
|
28
|
+
6. 关掉那个「工作区外」标签,等 5 秒:**不得**自己重开,也不得再出现原生「文件不存在」标签。
|
|
29
|
+
7. 接着打开一个本地文件的原生标签并激活它:那个工作区外标签**不得**跟着冒出来;再点同一条聊天链接时
|
|
30
|
+
仍应正常打开(记忆只拦住接管逻辑,不拦用户操作)。
|
|
31
|
+
|
|
32
|
+
## 聊天链接直达与表单焦点(未发布)
|
|
33
|
+
|
|
34
|
+
1. 在联动工作区会话里,让模型输出一个远端文件的绝对路径(例如 `/data/proj/a.md`),点击聊天里的那个链接:
|
|
35
|
+
**不应**先出现「文件不存在」的原生标签,而应直接在工作区目录树标签内部多出 `a.md`;从点击到出现内容应
|
|
36
|
+
在一秒内。
|
|
37
|
+
2. 再点同一个链接:只在已有内部标签之间切换,不新增标签,也不出现原生标签。
|
|
38
|
+
3. 点一个指向远端**目录**的链接:目录树展开并滚到该目录,标签条不新增。
|
|
39
|
+
4. 点一个位于**本机磁盘**(工作区之外)的文件链接:仍由原生查看器打开,说明接管只挑工作区内的路径。
|
|
40
|
+
5. 打开「添加工作区」对话框,在「2. 工作区名称」里连续输入 20 个以上字符:光标应始终留在名称输入框,
|
|
41
|
+
不再跳到「1. 本地目录」;切换顶部标签后再次输入,焦点仍按标签正确落位。
|
|
42
|
+
|
|
5
43
|
## 预览链接的文件夹与并行打开(未发布)
|
|
6
44
|
|
|
7
45
|
1. 在一份 Markdown 里写 `[sub/](sub/)` 与 `[sub](sub)`(`sub` 是真实存在的目录),预览里先后点这两条:都只出
|
|
@@ -15,6 +53,16 @@ Host code (lib/) reloads live with `plugin_manager set_plugin include:linked-wor
|
|
|
15
53
|
先后点击两者:只应存在一个 `note.md` 标签。
|
|
16
54
|
6. 切换系统深浅色主题:界面跟随,控制台无报错(宿主提供 `theme/change` 事件时不依赖 1.5 秒轮询)。
|
|
17
55
|
|
|
56
|
+
## 配套插件晚到时仍然直达(未发布)
|
|
57
|
+
|
|
58
|
+
1. 完全退出 DSH 后重启,确认 `dsh-better-sidebar` 的客户端服务比本插件注册得更晚(桌面 profile 常见):
|
|
59
|
+
打开联动工作区目录标签,点一个聊天里的远端文件链接,**不应**出现原生「文件不存在」标签,而应直接落进
|
|
60
|
+
目录树的文件标签;重复点同一链接只切换、不新增。
|
|
61
|
+
2. 通过 `@` 引用(走 `openFile`)打开一个远端文件:同样落在目录树标签内部,不开原生标签。
|
|
62
|
+
3. 首次点击不应等待数秒:工作区索引在接管安装时已预热,`linked.list` 走 SSH 的耗时不再落在第一次点击上。
|
|
63
|
+
4. 断网或主机不可达时点聊天链接:控制台无未捕获异常。此时工作区索引取不到,允许先出现原生标签;等主机恢复、
|
|
64
|
+
索引重建后,兜底扫描应在两秒内把内容搬进目录树标签并关掉那个原生标签。
|
|
65
|
+
|
|
18
66
|
## 主机密钥与输出编码(0.20.0)
|
|
19
67
|
|
|
20
68
|
1. 设置 → 联动工作区 → 「SSH 主机密钥与输出编码」应能看到「主机密钥策略」(tofu / strict)、「远端命令输出编码」(utf8 / gbk),以及已记住的主机列表(每行显示 `host:port` 与 `SHA256:…` 指纹)。
|
package/lib/client.js
CHANGED
|
@@ -2351,8 +2351,17 @@ function isInsideRoot(root, target) {
|
|
|
2351
2351
|
fileSlotByKind.delete(kind);
|
|
2352
2352
|
}
|
|
2353
2353
|
|
|
2354
|
+
// A slot is a one-shot slot: better-sidebar binds a tab kind to its one tab,
|
|
2355
|
+
// a closed kind can never be reopened, and updateTab repoints the address
|
|
2356
|
+
// without re-rendering the plugin view (so the previous file would stay on
|
|
2357
|
+
// screen). A full table is therefore reported as "full" and the caller
|
|
2358
|
+
// falls back, instead of showing the wrong file under a new title.
|
|
2359
|
+
var slotFull = false;
|
|
2360
|
+
|
|
2354
2361
|
function remoteFileSlotFor(key) {
|
|
2355
|
-
|
|
2362
|
+
slotFull = false;
|
|
2363
|
+
var taken = fileSlotByKey.get(key);
|
|
2364
|
+
if (taken !== undefined) return taken;
|
|
2356
2365
|
for (var index = 1; index <= FILE_SLOT_COUNT; index += 1) {
|
|
2357
2366
|
var kind = FILE_SLOT_PREFIX + index;
|
|
2358
2367
|
if (!fileSlotByKind.has(kind)) {
|
|
@@ -2361,9 +2370,23 @@ function isInsideRoot(root, target) {
|
|
|
2361
2370
|
return kind;
|
|
2362
2371
|
}
|
|
2363
2372
|
}
|
|
2373
|
+
slotFull = true;
|
|
2364
2374
|
return undefined;
|
|
2365
2375
|
}
|
|
2366
2376
|
|
|
2377
|
+
// Open a file into the slot its key owns. Slots are one-shot (see above), so
|
|
2378
|
+
// there is no recycle branch here: a new key gets a free slot or nothing.
|
|
2379
|
+
function openFileSlotTab(sidebar, scope, kind, seed) {
|
|
2380
|
+
var known = nativeTabKeys(sidebar);
|
|
2381
|
+
try {
|
|
2382
|
+
sidebar.openTab(seed(kind), scope);
|
|
2383
|
+
} catch (error) {
|
|
2384
|
+
return false;
|
|
2385
|
+
}
|
|
2386
|
+
claimNewNativeTabs(sidebar, known);
|
|
2387
|
+
return true;
|
|
2388
|
+
}
|
|
2389
|
+
|
|
2367
2390
|
// A link inside a remote document has to become an absolute path on the same
|
|
2368
2391
|
// host, and the panel that owns the tab does not carry the workspace root.
|
|
2369
2392
|
// The two lists change rarely, so one lookup serves every click for 30 s.
|
|
@@ -2393,6 +2416,14 @@ function isInsideRoot(root, target) {
|
|
|
2393
2416
|
// we open land in that very list too. Remember the ids we created so the
|
|
2394
2417
|
// hand-over below never mistakes its own work for something to take over.
|
|
2395
2418
|
var ownedNativeTabs = new Set();
|
|
2419
|
+
// The hand-over is re-installed whenever the sidebar service is replaced, so
|
|
2420
|
+
// its memory has to live out here: forgetting which tabs were already taken
|
|
2421
|
+
// makes a closed tab come back on the next tick.
|
|
2422
|
+
var handedNativeTabs = new Set();
|
|
2423
|
+
var outsideSeenPaths = new Set();
|
|
2424
|
+
// sessionId -> cwd, learned from the native path tabs, so an outside link
|
|
2425
|
+
// can be mapped to its workspace before any tab of ours exists.
|
|
2426
|
+
var sessionCwds = new Map();
|
|
2396
2427
|
|
|
2397
2428
|
function nativeTabKeys(sidebar) {
|
|
2398
2429
|
try {
|
|
@@ -2423,23 +2454,51 @@ function isInsideRoot(root, target) {
|
|
|
2423
2454
|
}, 0);
|
|
2424
2455
|
}
|
|
2425
2456
|
|
|
2426
|
-
function openRemoteFileTab(sidebar, scope, source, filePath) {
|
|
2457
|
+
function openRemoteFileTab(sidebar, scope, source, filePath, options) {
|
|
2427
2458
|
if (!sidebar || typeof sidebar.openTab !== 'function') return false;
|
|
2428
2459
|
var key = scopeKeyOf(sourceScopeOf(source)) + ':' + filePath;
|
|
2429
2460
|
var kind = remoteFileSlotFor(key);
|
|
2430
2461
|
if (kind === undefined) return false;
|
|
2431
|
-
var known = nativeTabKeys(sidebar);
|
|
2432
2462
|
// The slot id is the identity, so asking for the same file again focuses
|
|
2433
2463
|
// the tab that is already open instead of stacking a second one.
|
|
2434
|
-
sidebar
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
|
|
2464
|
+
return openFileSlotTab(sidebar, scope, kind, function (kind) {
|
|
2465
|
+
return {
|
|
2466
|
+
type: kind,
|
|
2467
|
+
id: kind,
|
|
2468
|
+
title: basename(filePath),
|
|
2469
|
+
path: filePath,
|
|
2470
|
+
meta: sourceMetaOf(source),
|
|
2471
|
+
};
|
|
2472
|
+
});
|
|
2473
|
+
}
|
|
2474
|
+
|
|
2475
|
+
// The folder that has to be allow-listed before an outside path is readable.
|
|
2476
|
+
function outsideDirOf(filePath) {
|
|
2477
|
+
var cut = filePath.lastIndexOf('/')
|
|
2478
|
+
return cut > 0 ? filePath.slice(0, cut) : filePath
|
|
2479
|
+
}
|
|
2480
|
+
|
|
2481
|
+
// A chat link may point at a file that is not inside any workspace root yet
|
|
2482
|
+
// still lives on the same host (artefacts written next to the working copy).
|
|
2483
|
+
// The workspace tree cannot reach it, so open a read-only tab that reads
|
|
2484
|
+
// through the "extra roots" gate instead of letting the native viewer report
|
|
2485
|
+
// "file not found" for a path it never could read.
|
|
2486
|
+
function openOutsideFileTab(sidebar, scope, scoped, filePath) {
|
|
2487
|
+
if (!sidebar || typeof sidebar.openTab !== 'function') return false;
|
|
2488
|
+
var source = scoped.linkedId
|
|
2489
|
+
? { kind: 'linked', id: scoped.linkedId, name: '' }
|
|
2490
|
+
: scoped.remoteId
|
|
2491
|
+
? { kind: 'remote', id: scoped.remoteId, name: '' }
|
|
2492
|
+
: null;
|
|
2493
|
+
if (!source) return false;
|
|
2494
|
+
var key = 'outside:' + scopeKeyOf(sourceScopeOf(source)) + ':' + filePath;
|
|
2495
|
+
var kind = remoteFileSlotFor(key);
|
|
2496
|
+
if (kind === undefined) return false;
|
|
2497
|
+
var meta = sourceMetaOf(source);
|
|
2498
|
+
meta.outside = true;
|
|
2499
|
+
return openFileSlotTab(sidebar, scope, kind, function (kind) {
|
|
2500
|
+
return { type: kind, id: kind, title: basename(filePath), path: filePath, meta: meta };
|
|
2501
|
+
});
|
|
2443
2502
|
}
|
|
2444
2503
|
|
|
2445
2504
|
// Chat artifacts live outside our tabs, so opening one has to travel
|
|
@@ -2457,7 +2516,12 @@ function isInsideRoot(root, target) {
|
|
|
2457
2516
|
// A folder has no file to open, so the panel reveals it in the tree.
|
|
2458
2517
|
if (options.dir) meta.revealKind = 'dir';
|
|
2459
2518
|
try {
|
|
2519
|
+
// Mark it as ours right away: the tree tab stores the workspace root as
|
|
2520
|
+
// its path, and the hand-over would otherwise mistake it for a file that
|
|
2521
|
+
// needs rescuing.
|
|
2522
|
+
var known = typeof nativeTabKeys === 'function' ? nativeTabKeys(sidebar) : null;
|
|
2460
2523
|
sidebar.openTab({ type: type, id: type, title: t(remoteOnly ? 'remoteTabTitle' : 'tabTitle'), path: '/', meta: meta }, scope);
|
|
2524
|
+
if (known) claimNewNativeTabs(sidebar, known);
|
|
2461
2525
|
return true;
|
|
2462
2526
|
} catch (error) {
|
|
2463
2527
|
return false;
|
|
@@ -2466,7 +2530,7 @@ function isInsideRoot(root, target) {
|
|
|
2466
2530
|
|
|
2467
2531
|
var FILE_TAB_TYPE = 'dsh-linked-workspace:file';
|
|
2468
2532
|
var FILE_SLOT_PREFIX = 'dsh-linked-workspace:file:';
|
|
2469
|
-
var FILE_SLOT_COUNT =
|
|
2533
|
+
var FILE_SLOT_COUNT = 24;
|
|
2470
2534
|
// DSH's native right sidebar deduplicates ordinary page tabs by kind, so a
|
|
2471
2535
|
// second file opened under one kind would focus the first tab. Each file
|
|
2472
2536
|
// slot is its own hidden page kind; this map hands a free slot to a file and
|
|
@@ -2774,6 +2838,16 @@ function isInsideRoot(root, target) {
|
|
|
2774
2838
|
previewTooLarge: '这个文件太大({{chars}} 字符,上限 {{limit}}),没有生成预览;可以在编辑器里查看,或下载后用别的工具打开。',
|
|
2775
2839
|
previewTooLargeBytes: '这个文件太大({{bytes}}),没有生成预览;可以在编辑器里查看,或下载后用别的工具打开。',
|
|
2776
2840
|
fileGone: '这个文件已不在远端(可能被重命名或删除),已关闭它的标签并刷新目录。',
|
|
2841
|
+
outsideNote: '这个路径在工作区之外,插件还没有读取它的权限。',
|
|
2842
|
+
outsideAddRoot: '把 {{dir}} 加入额外根目录并打开',
|
|
2843
|
+
outsideBadge: '工作区外',
|
|
2844
|
+
outsideBinary: '二进制文件,无法在这里预览({{size}})。',
|
|
2845
|
+
outsideReload: '重新加载',
|
|
2846
|
+
outsideCopyPath: '复制绝对地址',
|
|
2847
|
+
outsideLoadMore: '加载更多',
|
|
2848
|
+
outsideShown: '已显示 {{shown}},共 {{total}}',
|
|
2849
|
+
outsideMtime: '修改于 {{when}}',
|
|
2850
|
+
outsideCeiling: '已达到 {{size}} 的读取上限,剩下的内容请下载后查看。',
|
|
2777
2851
|
linkOutside: '这个链接指向工作区之外,没有打开:{{path}}',
|
|
2778
2852
|
linkFolder: '这是文件夹链接,这里只打开文件:{{path}}',
|
|
2779
2853
|
linkedTitle: '联动工作区',
|
|
@@ -3380,6 +3454,16 @@ function isInsideRoot(root, target) {
|
|
|
3380
3454
|
previewTooLarge: 'Too large to preview ({{chars}} characters, the ceiling is {{limit}}). Read it in the editor, or download it and open it elsewhere.',
|
|
3381
3455
|
previewTooLargeBytes: 'Too large to preview ({{bytes}}). Read it in the editor, or download it and open it elsewhere.',
|
|
3382
3456
|
fileGone: 'That file is gone from the remote side (renamed or deleted). Closed its tab and refreshed the tree.',
|
|
3457
|
+
outsideNote: 'That path sits outside the workspace, so the plugin is not allowed to read it yet.',
|
|
3458
|
+
outsideAddRoot: 'Add {{dir}} to the extra roots and open it',
|
|
3459
|
+
outsideBadge: 'Outside',
|
|
3460
|
+
outsideBinary: 'Binary file, so it cannot be previewed here ({{size}}).',
|
|
3461
|
+
outsideReload: 'Reload',
|
|
3462
|
+
outsideCopyPath: 'Copy absolute address',
|
|
3463
|
+
outsideLoadMore: 'Load more',
|
|
3464
|
+
outsideShown: 'Showing {{shown}} of {{total}}',
|
|
3465
|
+
outsideMtime: 'Modified {{when}}',
|
|
3466
|
+
outsideCeiling: 'Reached the {{size}} reading ceiling; download the file for the rest.',
|
|
3383
3467
|
linkOutside: 'That link points outside the workspace, so it was left alone: {{path}}',
|
|
3384
3468
|
linkFolder: 'That link is a folder; only files open here: {{path}}',
|
|
3385
3469
|
linkedTitle: 'Linked workspaces',
|
|
@@ -4365,6 +4449,9 @@ function isInsideRoot(root, target) {
|
|
|
4365
4449
|
'.rw-doc{display:flex;flex-direction:column;flex:1 1 auto;min-height:0;min-width:0;background:var(--dsw-alias-bg-base)}',
|
|
4366
4450
|
'.rw-doc-toolbar{display:flex;align-items:center;gap:6px;padding:6px 8px;border-bottom:1px solid var(--dsw-alias-border-l1);background:var(--dsw-alias-bg-layer-1);flex:none;flex-wrap:wrap}',
|
|
4367
4451
|
'.rw-doc-body{display:flex;flex-direction:column;flex:1 1 auto;min-height:0;overflow:auto;padding:10px}',
|
|
4452
|
+
'.rw-outside-actions{display:flex;flex-direction:column;gap:8px;padding:4px 0}',
|
|
4453
|
+
'.rw-outside-footer{display:flex;align-items:center;gap:10px;flex-wrap:wrap;padding:8px 0 2px;border-top:1px solid var(--dsw-alias-border-l1);margin-top:8px;flex:none}',
|
|
4454
|
+
'.rw-outside-text{margin:0;font-family:var(--dsw-alias-font-mono,ui-monospace,SFMono-Regular,Menlo,monospace);font-size:12px;line-height:1.5;white-space:pre-wrap;word-break:break-word;flex:1 1 auto;min-height:0}',
|
|
4368
4455
|
'.rw-doc-textarea{width:100%;min-height:260px;flex:1 1 auto;resize:none;border:1px solid var(--dsw-alias-border-l2);border-radius:8px;padding:10px;background:var(--dsw-alias-bg-layer-1);color:var(--dsw-alias-label-primary);font:12.5px/18px ui-monospace,"Cascadia Code",Consolas,monospace;outline:none;box-sizing:border-box}',
|
|
4369
4456
|
'.rw-doc-preview{max-width:920px;margin:0 auto;color:var(--dsw-alias-label-primary);font-size:14px;line-height:1.65;overflow-wrap:anywhere}',
|
|
4370
4457
|
'.rw-doc-preview h1,.rw-doc-preview h2,.rw-doc-preview h3{line-height:1.3;margin:1em 0 .5em}',
|
|
@@ -6826,7 +6913,18 @@ function isInsideRoot(root, target) {
|
|
|
6826
6913
|
|
|
6827
6914
|
function close() { setMenu(null); }
|
|
6828
6915
|
|
|
6829
|
-
|
|
6916
|
+
var toolbarRef = useRef(null);
|
|
6917
|
+
useEffect(function () {
|
|
6918
|
+
var node = toolbarRef.current;
|
|
6919
|
+
if (!node || typeof node.querySelectorAll !== 'function') return;
|
|
6920
|
+
var buttons = node.querySelectorAll('button.rw-icon-btn');
|
|
6921
|
+
for (var index = 0; index < buttons.length; index += 1) {
|
|
6922
|
+
if (buttons[index].getAttribute('aria-label')) continue;
|
|
6923
|
+
buttons[index].setAttribute('aria-label', buttons[index].getAttribute('title') || '');
|
|
6924
|
+
}
|
|
6925
|
+
});
|
|
6926
|
+
|
|
6927
|
+
return h('div', { className: 'rw-linked-toolbar', ref: toolbarRef },
|
|
6830
6928
|
h('span', { className: 'rw-tree-toolbar-title' }, props.title || t('tabTitle')),
|
|
6831
6929
|
h('div', { className: 'rw-actions', style: { marginLeft: 'auto', gap: 2 } },
|
|
6832
6930
|
h('button', {
|
|
@@ -10646,6 +10744,147 @@ function rememberShowHidden(value) {
|
|
|
10646
10744
|
dialog ? renderDialog() : null);
|
|
10647
10745
|
}
|
|
10648
10746
|
|
|
10747
|
+
// Read-only view for a path outside every workspace root. The host only
|
|
10748
|
+
// hands out such files when their prefix is in the extra roots, so an
|
|
10749
|
+
// unreadable path offers to add its folder instead of showing a raw error.
|
|
10750
|
+
function OutsideFileView(props) {
|
|
10751
|
+
var t = props.t;
|
|
10752
|
+
var locale = props.locale;
|
|
10753
|
+
var scope = props.scope;
|
|
10754
|
+
var filePath = props.filePath;
|
|
10755
|
+
var loadRef = useState({ loading: true, more: false, error: null, data: null });
|
|
10756
|
+
var load = loadRef[0];
|
|
10757
|
+
var setLoad = loadRef[1];
|
|
10758
|
+
var busyRef = useState(false);
|
|
10759
|
+
var busy = busyRef[0];
|
|
10760
|
+
var setBusy = busyRef[1];
|
|
10761
|
+
var noteRef = useState('');
|
|
10762
|
+
var note = noteRef[0];
|
|
10763
|
+
var setNote = noteRef[1];
|
|
10764
|
+
// One page per click keeps a 200 MB log from freezing the tab, and the
|
|
10765
|
+
// ceiling keeps the DOM bounded even if someone keeps clicking.
|
|
10766
|
+
var PAGE_BYTES = 256 * 1024;
|
|
10767
|
+
var CEILING_BYTES = 4 * 1024 * 1024;
|
|
10768
|
+
|
|
10769
|
+
function read(from, append) {
|
|
10770
|
+
var start = Math.max(0, Number(from) || 0);
|
|
10771
|
+
setLoad(function (previous) {
|
|
10772
|
+
return { loading: !append, more: append, error: null, data: previous.data };
|
|
10773
|
+
});
|
|
10774
|
+
apiCall('fs.readOutside', Object.assign({ path: filePath, maxBytes: PAGE_BYTES, offset: start }, scopeParams(scope)))
|
|
10775
|
+
.then(function (result) {
|
|
10776
|
+
setLoad(function (previous) {
|
|
10777
|
+
var earlier = append && previous.data ? previous.data : null;
|
|
10778
|
+
var text = typeof result.content === 'string' ? result.content : '';
|
|
10779
|
+
var merged = Object.assign({}, result, {
|
|
10780
|
+
content: earlier && typeof earlier.content === 'string' ? earlier.content + text : text,
|
|
10781
|
+
shown: (earlier && Number(earlier.shown) ? Number(earlier.shown) : 0) + (Number(result.returned) || 0),
|
|
10782
|
+
next: (Number(result.offset) || 0) + (Number(result.returned) || 0),
|
|
10783
|
+
});
|
|
10784
|
+
return { loading: false, more: false, error: null, data: merged };
|
|
10785
|
+
});
|
|
10786
|
+
}, function (error) {
|
|
10787
|
+
setLoad(function (previous) {
|
|
10788
|
+
return { loading: false, more: false, error: error, data: previous.data };
|
|
10789
|
+
});
|
|
10790
|
+
});
|
|
10791
|
+
}
|
|
10792
|
+
|
|
10793
|
+
useEffect(function () { read(0, false); }, [filePath, scope.kind, scope.id]);
|
|
10794
|
+
|
|
10795
|
+
function loadMore() {
|
|
10796
|
+
if (!load.data || load.more) return;
|
|
10797
|
+
read(Number(load.data.next) || 0, true);
|
|
10798
|
+
}
|
|
10799
|
+
|
|
10800
|
+
function copyPath() {
|
|
10801
|
+
try {
|
|
10802
|
+
if (navigator.clipboard && navigator.clipboard.writeText) {
|
|
10803
|
+
navigator.clipboard.writeText(filePath).then(function () {
|
|
10804
|
+
setNote(t('addressCopied', { address: filePath }));
|
|
10805
|
+
setTimeout(function () { setNote(''); }, 2500);
|
|
10806
|
+
}).catch(function () {});
|
|
10807
|
+
}
|
|
10808
|
+
} catch (error) { /* clipboard unavailable */ }
|
|
10809
|
+
}
|
|
10810
|
+
|
|
10811
|
+
function addRoot() {
|
|
10812
|
+
if (busy) return;
|
|
10813
|
+
setBusy(true);
|
|
10814
|
+
apiCall('settings.get').then(function (settings) {
|
|
10815
|
+
var roots = settings && Array.isArray(settings.extraRoots) ? settings.extraRoots.slice() : [];
|
|
10816
|
+
var dir = outsideDirOf(filePath);
|
|
10817
|
+
if (dir && roots.indexOf(dir) < 0) roots.push(dir);
|
|
10818
|
+
return apiCall('settings.update', { extraRoots: roots });
|
|
10819
|
+
}).then(function () {
|
|
10820
|
+
setBusy(false);
|
|
10821
|
+
read(0, false);
|
|
10822
|
+
}, function (error) {
|
|
10823
|
+
setBusy(false);
|
|
10824
|
+
setLoad({ loading: false, more: false, error: error, data: null });
|
|
10825
|
+
});
|
|
10826
|
+
}
|
|
10827
|
+
|
|
10828
|
+
var toolbar = h('div', { className: 'rw-doc-toolbar' },
|
|
10829
|
+
h('span', { className: 'rw-doc-badge' }, t('outsideBadge')),
|
|
10830
|
+
h('span', { className: 'rw-editor-path', title: filePath }, filePath),
|
|
10831
|
+
h('span', { style: { flex: '1 1 auto' } }),
|
|
10832
|
+
h('button', {
|
|
10833
|
+
className: 'rw-btn rw-btn-sm',
|
|
10834
|
+
title: t('outsideCopyPath'),
|
|
10835
|
+
'aria-label': t('outsideCopyPath'),
|
|
10836
|
+
onClick: copyPath,
|
|
10837
|
+
}, t('outsideCopyPath')),
|
|
10838
|
+
h('button', {
|
|
10839
|
+
className: 'rw-btn rw-btn-sm',
|
|
10840
|
+
title: t('outsideReload'),
|
|
10841
|
+
'aria-label': t('outsideReload'),
|
|
10842
|
+
disabled: load.loading || load.more,
|
|
10843
|
+
onClick: function () { read(0, false); },
|
|
10844
|
+
}, t('outsideReload')));
|
|
10845
|
+
var body;
|
|
10846
|
+
if (load.loading) {
|
|
10847
|
+
body = h('div', { className: 'rw-doc-loading' }, h('div', { className: 'rw-spinner' }), h('span', null, t('loading')));
|
|
10848
|
+
} else if (load.error && !load.data) {
|
|
10849
|
+
// A folder outside the workspace is not a permission problem: nothing
|
|
10850
|
+
// here can open it, so say so instead of offering an allow-list entry.
|
|
10851
|
+
var blocked = load.error.code === 'BAD_REQUEST';
|
|
10852
|
+
var isDir = load.error.code === 'FS_IS_DIR' || load.error.code === 'FS_NOT_DIRECTORY';
|
|
10853
|
+
body = h('div', { className: 'rw-doc-body' },
|
|
10854
|
+
h(Banner, { kind: 'warn' }, messageOf(load.error, t, locale)),
|
|
10855
|
+
h('div', { className: 'rw-outside-actions' },
|
|
10856
|
+
blocked && !isDir
|
|
10857
|
+
? h('button', { className: 'rw-btn rw-btn-sm rw-btn-primary', disabled: busy, onClick: addRoot },
|
|
10858
|
+
t('outsideAddRoot', { dir: outsideDirOf(filePath) }))
|
|
10859
|
+
: null,
|
|
10860
|
+
h('div', { className: 'rw-hint' }, isDir ? t('linkFolder', { path: filePath }) : t('outsideNote'))));
|
|
10861
|
+
} else {
|
|
10862
|
+
var data = load.data || {};
|
|
10863
|
+
var shown = Number(data.shown) || 0;
|
|
10864
|
+
var total = Number(data.size) || 0;
|
|
10865
|
+
var canMore = Boolean(data.truncated) && shown < CEILING_BYTES;
|
|
10866
|
+
var footer = h('div', { className: 'rw-outside-footer' },
|
|
10867
|
+
h('span', { className: 'rw-hint' }, t('outsideShown', { shown: formatBytes(shown), total: formatBytes(total) })),
|
|
10868
|
+
typeof data.mtime === 'number' && data.mtime > 0
|
|
10869
|
+
? h('span', { className: 'rw-hint' }, t('outsideMtime', { when: new Date(data.mtime).toLocaleString() }))
|
|
10870
|
+
: null,
|
|
10871
|
+
note ? h('span', { className: 'rw-hint' }, note) : null,
|
|
10872
|
+
canMore
|
|
10873
|
+
? h('button', { className: 'rw-btn rw-btn-sm', disabled: load.more, onClick: loadMore },
|
|
10874
|
+
load.more ? t('loading') : t('outsideLoadMore'))
|
|
10875
|
+
: null,
|
|
10876
|
+
Boolean(data.truncated) && !canMore
|
|
10877
|
+
? h('span', { className: 'rw-hint' }, t('outsideCeiling', { size: formatBytes(CEILING_BYTES) }))
|
|
10878
|
+
: null);
|
|
10879
|
+
body = h('div', { className: 'rw-doc-body' },
|
|
10880
|
+
data.binary
|
|
10881
|
+
? h('div', { className: 'rw-outside-actions' }, h('div', { className: 'rw-hint' }, t('outsideBinary', { size: formatBytes(total) })))
|
|
10882
|
+
: h('pre', { className: 'rw-outside-text' }, typeof data.content === 'string' ? data.content : ''),
|
|
10883
|
+
footer);
|
|
10884
|
+
}
|
|
10885
|
+
return h('div', { className: 'rw-editor-pane' }, toolbar, body);
|
|
10886
|
+
}
|
|
10887
|
+
|
|
10649
10888
|
function RemoteFileTab(props) {
|
|
10650
10889
|
var ctx = props.ctx;
|
|
10651
10890
|
var t = props.t;
|
|
@@ -10690,6 +10929,9 @@ function rememberShowHidden(value) {
|
|
|
10690
10929
|
// re-reads this file: probe it now and then and reclaim the tab once the
|
|
10691
10930
|
// path is gone (a rename inside a session is the usual cause).
|
|
10692
10931
|
useEffect(function () {
|
|
10932
|
+
// An outside file has no workspace scope to stat; its own view handles
|
|
10933
|
+
// the reads and their errors.
|
|
10934
|
+
if (meta.outside === true) return function () { /* nothing to probe */ };
|
|
10693
10935
|
var cancelled = false;
|
|
10694
10936
|
var timer = setInterval(function () {
|
|
10695
10937
|
if (typeof document !== 'undefined' && document.visibilityState === 'hidden') return;
|
|
@@ -10701,7 +10943,9 @@ function rememberShowHidden(value) {
|
|
|
10701
10943
|
return function () { cancelled = true; clearInterval(timer); };
|
|
10702
10944
|
}, [filePath, scope.kind, scope.id]);
|
|
10703
10945
|
|
|
10704
|
-
var pane =
|
|
10946
|
+
var pane = meta.outside === true
|
|
10947
|
+
? h(OutsideFileView, { t: t, locale: locale, scope: scope, filePath: filePath })
|
|
10948
|
+
: docKind === 'image'
|
|
10705
10949
|
? h(ImagePreview, { ctx: ctx, t: t, locale: locale, scope: scope, path: filePath, local: false })
|
|
10706
10950
|
: docKind === 'html'
|
|
10707
10951
|
? h(HtmlPreview, { ctx: ctx, t: t, locale: locale, scope: scope, path: filePath, local: false })
|
|
@@ -11650,10 +11894,15 @@ function rememberShowHidden(value) {
|
|
|
11650
11894
|
var modalNodeState = useState(null);
|
|
11651
11895
|
var modalNode = modalNodeState[0];
|
|
11652
11896
|
var setModalNode = modalNodeState[1];
|
|
11653
|
-
|
|
11897
|
+
// A ref callback is re-created on every render, so React detaches it with
|
|
11898
|
+
// null and attaches it again on every commit; calling setModalNode(null)
|
|
11899
|
+
// there re-ran the focus effect just after each keystroke and pulled the
|
|
11900
|
+
// caret out of the name field and back into the first input. Keep the
|
|
11901
|
+
// callback stable so the node never flickers.
|
|
11902
|
+
var attachModal = useCallback(function (node) {
|
|
11654
11903
|
modalRef.current = node;
|
|
11655
|
-
|
|
11656
|
-
};
|
|
11904
|
+
setModalNode(node);
|
|
11905
|
+
}, []);
|
|
11657
11906
|
var focusablesOf = function () {
|
|
11658
11907
|
var node = modalRef.current;
|
|
11659
11908
|
if (!node) return [];
|
|
@@ -11662,10 +11911,17 @@ function rememberShowHidden(value) {
|
|
|
11662
11911
|
function (element) { return !element.disabled && element.offsetParent !== null; });
|
|
11663
11912
|
};
|
|
11664
11913
|
|
|
11914
|
+
var focusSigRef = useRef('');
|
|
11665
11915
|
useEffect(function () {
|
|
11666
|
-
if (!props.open) return;
|
|
11916
|
+
if (!props.open) { focusSigRef.current = ''; return; }
|
|
11667
11917
|
var node = modalRef.current;
|
|
11668
11918
|
if (!node) return;
|
|
11919
|
+
// Focus once per opened dialog and once per tab switch — never on the
|
|
11920
|
+
// re-renders a keystroke causes, or typing a name jumps back to the
|
|
11921
|
+
// first field.
|
|
11922
|
+
var sig = String(flow);
|
|
11923
|
+
if (focusSigRef.current === sig) return;
|
|
11924
|
+
focusSigRef.current = sig;
|
|
11669
11925
|
// Focus the first real field, not the tab strip, so typing works at once.
|
|
11670
11926
|
var target = node.querySelector('.rw-modal-body input, .rw-modal-body textarea') || focusablesOf()[0];
|
|
11671
11927
|
if (target && typeof target.focus === 'function') target.focus();
|
|
@@ -13566,9 +13822,45 @@ function rememberShowHidden(value) {
|
|
|
13566
13822
|
var PLACEHOLDER_PATH = /[\\/]remote-placeholders[\\/]([^\\/]+)([\\/].*)$/i;
|
|
13567
13823
|
|
|
13568
13824
|
function installPlaceholderHandover(ctx) {
|
|
13569
|
-
var
|
|
13570
|
-
|
|
13571
|
-
|
|
13825
|
+
var installedFor = null;
|
|
13826
|
+
var stopHandover = null;
|
|
13827
|
+
|
|
13828
|
+
// better-sidebar registers its client service lazily, and on the desktop
|
|
13829
|
+
// profile it can come up after this plugin. A single check at apply time
|
|
13830
|
+
// used to leave chat links unclaimed for the whole session, which looked
|
|
13831
|
+
// exactly like the old "moved after two seconds" behaviour.
|
|
13832
|
+
function attach() {
|
|
13833
|
+
var sidebar = sidebarService(ctx);
|
|
13834
|
+
if (!sidebar || typeof sidebar.nativePathTabs !== 'function' || typeof sidebar.subscribeState !== 'function') return;
|
|
13835
|
+
if (installedFor === sidebar) return;
|
|
13836
|
+
if (stopHandover) {
|
|
13837
|
+
try { stopHandover(); } catch (error) { /* already torn down */ }
|
|
13838
|
+
}
|
|
13839
|
+
installedFor = sidebar;
|
|
13840
|
+
stopHandover = installHandover(ctx, sidebar);
|
|
13841
|
+
}
|
|
13842
|
+
|
|
13843
|
+
attach();
|
|
13844
|
+
// One object lookup per second; it also picks up a sidebar that is
|
|
13845
|
+
// replaced after a plugin reload.
|
|
13846
|
+
ctx.effect(function () {
|
|
13847
|
+
var timer = setInterval(attach, 1000);
|
|
13848
|
+
return function () {
|
|
13849
|
+
clearInterval(timer);
|
|
13850
|
+
if (stopHandover) {
|
|
13851
|
+
try { stopHandover(); } catch (error) { /* already torn down */ }
|
|
13852
|
+
stopHandover = null;
|
|
13853
|
+
}
|
|
13854
|
+
};
|
|
13855
|
+
}, 'dsh-linked-workspace: late sidebar hand-over');
|
|
13856
|
+
}
|
|
13857
|
+
|
|
13858
|
+
function installHandover(ctx, sidebar) {
|
|
13859
|
+
var handled = handedNativeTabs;
|
|
13860
|
+
// Paths for which we already opened an "outside" tab. If the user closes
|
|
13861
|
+
// that tab we must not open it again from the scan: the stale native tab
|
|
13862
|
+
// is closed, nothing reopens, and a later click goes through the claim.
|
|
13863
|
+
var outsideSeen = outsideSeenPaths;
|
|
13572
13864
|
var known = null;
|
|
13573
13865
|
var knownAt = 0;
|
|
13574
13866
|
var scanning = false;
|
|
@@ -13657,7 +13949,24 @@ function rememberShowHidden(value) {
|
|
|
13657
13949
|
// The sidebar may have stored a workspace-relative path.
|
|
13658
13950
|
absolute = root.replace(/[\/]+$/, '') + (root.charAt(0) === '/' ? '/' : '\\') + candidate.replace(/^[\/]+/, '');
|
|
13659
13951
|
}
|
|
13660
|
-
if (!isInsideRoot(root, absolute))
|
|
13952
|
+
if (!isInsideRoot(root, absolute)) {
|
|
13953
|
+
// Outside this workspace but on the same host: keep the tab by
|
|
13954
|
+
// opening it read-only rather than leaving the native error.
|
|
13955
|
+
if (!outsideOpenable(absolute)) return undefined;
|
|
13956
|
+
var outsideKey = String(tab.sessionId || '') + '|' + absolute;
|
|
13957
|
+
if (!outsideSeen.has(outsideKey)) {
|
|
13958
|
+
if (outsideSeen.size > 200) outsideSeen.clear();
|
|
13959
|
+
outsideSeen.add(outsideKey);
|
|
13960
|
+
openOutside(scoped, absolute);
|
|
13961
|
+
}
|
|
13962
|
+
// The native tab cannot show this path, so it goes away for good
|
|
13963
|
+
// — otherwise closing our tab would resurrect it on the next
|
|
13964
|
+
// scan, and activating another native tab would bring it back.
|
|
13965
|
+
if (handled.size > 200) handled.clear();
|
|
13966
|
+
handled.add(key);
|
|
13967
|
+
try { sidebar.closeTab(tab.id, scope); } catch (error) { /* already gone */ }
|
|
13968
|
+
return undefined;
|
|
13969
|
+
}
|
|
13661
13970
|
if (handled.size > 200) handled.clear();
|
|
13662
13971
|
handled.add(key);
|
|
13663
13972
|
var kind = scoped.linkedId ? 'linked' : 'remote';
|
|
@@ -13684,6 +13993,219 @@ function rememberShowHidden(value) {
|
|
|
13684
13993
|
.then(function () { probing.delete(key); }, function () { probing.delete(key); });
|
|
13685
13994
|
}
|
|
13686
13995
|
|
|
13996
|
+
// Chat links reach the sidebar as `openTab({ type: 'editor', path })` with
|
|
13997
|
+
// the path already resolved against the drive ("\data\x.md"), so waiting
|
|
13998
|
+
// for the native tab and moving it afterwards always shows a "file not
|
|
13999
|
+
// found" page first. Claim the tab before it exists: a path that lands
|
|
14000
|
+
// inside one of our workspaces opens straight in its tree tab, and the
|
|
14001
|
+
// caller never has a native tab to close.
|
|
14002
|
+
// The session's own workspace, matched by its local directory (linked) or
|
|
14003
|
+
// its placeholder (remote). Used to give the right machine priority when
|
|
14004
|
+
// two workspaces live on different hosts but share a path.
|
|
14005
|
+
function sessionWorkspaceOf(index, cwd) {
|
|
14006
|
+
var wanted = String(cwd == null ? '' : cwd).replace(/\\/g, '/').replace(/\/+$/, '');
|
|
14007
|
+
if (wanted === '') return null;
|
|
14008
|
+
var all = (index.linked || []).concat(index.remote || []);
|
|
14009
|
+
var lowered = wanted.toLowerCase();
|
|
14010
|
+
for (var cursor = 0; cursor < all.length; cursor += 1) {
|
|
14011
|
+
var record = all[cursor];
|
|
14012
|
+
if (!record) continue;
|
|
14013
|
+
var local = String(record.localPath || '').replace(/\\/g, '/').replace(/\/+$/, '').toLowerCase();
|
|
14014
|
+
var placeholder = String(record.placeholderPath || '').replace(/\\/g, '/').replace(/\/+$/, '').toLowerCase();
|
|
14015
|
+
if ((local !== '' && local === lowered) || (placeholder !== '' && placeholder === lowered)) return record;
|
|
14016
|
+
}
|
|
14017
|
+
return null;
|
|
14018
|
+
}
|
|
14019
|
+
|
|
14020
|
+
function ownerOfPath(index, normalized, preferredHostId) {
|
|
14021
|
+
var best = null;
|
|
14022
|
+
var bestHere = null;
|
|
14023
|
+
var host = String(preferredHostId || '');
|
|
14024
|
+
function consider(list, kind) {
|
|
14025
|
+
for (var cursor = 0; cursor < list.length; cursor += 1) {
|
|
14026
|
+
var record = list[cursor];
|
|
14027
|
+
if (!record) continue;
|
|
14028
|
+
var root = String(record.remotePath || '').replace(/\/+$/, '');
|
|
14029
|
+
if (root === '' || root === '/') continue;
|
|
14030
|
+
if (normalized !== root && normalized.indexOf(root + '/') !== 0) continue;
|
|
14031
|
+
// The deepest root wins, so a workspace nested inside another one
|
|
14032
|
+
// keeps its own files.
|
|
14033
|
+
if (!best || root.length > best.root.length) best = { kind: kind, record: record, root: root };
|
|
14034
|
+
if (host !== '' && String(record.hostId || '') === host) {
|
|
14035
|
+
if (!bestHere || root.length > bestHere.root.length) bestHere = { kind: kind, record: record, root: root };
|
|
14036
|
+
}
|
|
14037
|
+
}
|
|
14038
|
+
}
|
|
14039
|
+
consider(index.linked || [], 'linked');
|
|
14040
|
+
consider(index.remote || [], 'remote');
|
|
14041
|
+
return bestHere || best;
|
|
14042
|
+
}
|
|
14043
|
+
|
|
14044
|
+
// Native path tabs are the only place DSH shows us a session's cwd, so
|
|
14045
|
+
// remember it: an outside link has to be attributed to a host even before
|
|
14046
|
+
// its first tab exists.
|
|
14047
|
+
function currentSessionId() {
|
|
14048
|
+
try {
|
|
14049
|
+
var snapshot = typeof sidebar.getSnapshot === 'function' ? sidebar.getSnapshot() : null;
|
|
14050
|
+
return snapshot && snapshot.sessionId ? String(snapshot.sessionId) : '';
|
|
14051
|
+
} catch (error) {
|
|
14052
|
+
return '';
|
|
14053
|
+
}
|
|
14054
|
+
}
|
|
14055
|
+
|
|
14056
|
+
// The sidebar is not the only source of that cwd: the session list knows it
|
|
14057
|
+
// from the first moment, which is what makes an outside link land on the
|
|
14058
|
+
// right host before any tab of ours has ever been seen.
|
|
14059
|
+
function sessionCwdOf(sessionId) {
|
|
14060
|
+
var rememberedCwd = sessionId !== '' ? sessionCwds.get(sessionId) || '' : '';
|
|
14061
|
+
if (rememberedCwd !== '') return rememberedCwd;
|
|
14062
|
+
try {
|
|
14063
|
+
var service = ctx.sessions;
|
|
14064
|
+
var listing = service && service.list && typeof service.list.getSnapshot === 'function'
|
|
14065
|
+
? service.list.getSnapshot()
|
|
14066
|
+
: null;
|
|
14067
|
+
var record = listing && listing.byId ? listing.byId[sessionId] : null;
|
|
14068
|
+
var cwd = record && typeof record.cwd === 'string' ? record.cwd : '';
|
|
14069
|
+
if (cwd !== '') sessionCwds.set(sessionId, cwd);
|
|
14070
|
+
return cwd;
|
|
14071
|
+
} catch (error) {
|
|
14072
|
+
return '';
|
|
14073
|
+
}
|
|
14074
|
+
}
|
|
14075
|
+
|
|
14076
|
+
// Only a file path can become an outside tab. A bare "/" is how the
|
|
14077
|
+
// sidebar stores its own directory tabs, and a trailing slash names a
|
|
14078
|
+
// folder the tree can reveal instead.
|
|
14079
|
+
function outsideOpenable(absolute) {
|
|
14080
|
+
if (typeof absolute !== 'string' || absolute.length < 2) return false;
|
|
14081
|
+
if (absolute.charAt(0) !== '/') return false;
|
|
14082
|
+
if (/\/$/.test(absolute)) return false;
|
|
14083
|
+
var base = absolute.slice(absolute.lastIndexOf('/') + 1);
|
|
14084
|
+
return base !== '' && base !== '.' && base !== '..';
|
|
14085
|
+
}
|
|
14086
|
+
|
|
14087
|
+
function openOutside(scoped, absolute) {
|
|
14088
|
+
var sessionId = currentSessionId();
|
|
14089
|
+
var scope = sessionId !== '' ? { sessionId: sessionId } : {};
|
|
14090
|
+
var opened = openOutsideFileTab(sidebar, scope, scoped, absolute) === true;
|
|
14091
|
+
// With every slot busy the click is claimed but has nowhere to land: the
|
|
14092
|
+
// native viewer would only show "file not found", so report it as handled.
|
|
14093
|
+
return opened || slotFull === true;
|
|
14094
|
+
}
|
|
14095
|
+
|
|
14096
|
+
function claimScope(owner) {
|
|
14097
|
+
var scope = {};
|
|
14098
|
+
var sessionId = '';
|
|
14099
|
+
try {
|
|
14100
|
+
var snapshot = typeof sidebar.getSnapshot === 'function' ? sidebar.getSnapshot() : null;
|
|
14101
|
+
if (snapshot && snapshot.sessionId) sessionId = String(snapshot.sessionId);
|
|
14102
|
+
} catch (error) { /* no session on screen */ }
|
|
14103
|
+
if (sessionId !== '') scope.sessionId = sessionId;
|
|
14104
|
+
scope.cwd = owner.kind === 'linked'
|
|
14105
|
+
? String(owner.record.localPath || '')
|
|
14106
|
+
: String(owner.record.placeholderPath || '');
|
|
14107
|
+
return scope;
|
|
14108
|
+
}
|
|
14109
|
+
|
|
14110
|
+
function takeSeed(normalized, sessionCwd) {
|
|
14111
|
+
// DSH may keep the drive letter ("D:\data\x.md") or drop it
|
|
14112
|
+
// ("\data\x.md"); both spellings have to be tried against the roots.
|
|
14113
|
+
var candidates = [normalized];
|
|
14114
|
+
var stripped = normalized.replace(/^[A-Za-z]:/, '');
|
|
14115
|
+
if (stripped !== normalized && stripped.charAt(0) === '/') candidates.push(stripped);
|
|
14116
|
+
return workspaceIndex().then(function (index) {
|
|
14117
|
+
var here = sessionWorkspaceOf(index, sessionCwd);
|
|
14118
|
+
var preferredHost = here && here.hostId ? String(here.hostId) : '';
|
|
14119
|
+
var found = null;
|
|
14120
|
+
for (var cursor = 0; cursor < candidates.length && !found; cursor += 1) {
|
|
14121
|
+
var owner = ownerOfPath(index, candidates[cursor], preferredHost);
|
|
14122
|
+
if (owner) found = { owner: owner, absolute: candidates[cursor] };
|
|
14123
|
+
}
|
|
14124
|
+
if (!found) {
|
|
14125
|
+
// Not inside any workspace root: the link may still name a file on
|
|
14126
|
+
// the same host, which the workspace tree can never show.
|
|
14127
|
+
var outside = candidates[0];
|
|
14128
|
+
if (!outsideOpenable(outside)) return false;
|
|
14129
|
+
var sessionId = currentSessionId();
|
|
14130
|
+
var cwd = String(sessionCwd || '') || sessionCwdOf(sessionId);
|
|
14131
|
+
if (cwd === '') return false;
|
|
14132
|
+
return scanReferenceScope(cwd, '').then(function (scoped) {
|
|
14133
|
+
if (!scoped || !scoped.root) return false;
|
|
14134
|
+
// Remember it here too: a native duplicate that shows up later must
|
|
14135
|
+
// be closed rather than turned into a second copy of this tab.
|
|
14136
|
+
var outsideKey = sessionId + '|' + outside;
|
|
14137
|
+
if (outsideSeen.size > 200) outsideSeen.clear();
|
|
14138
|
+
outsideSeen.add(outsideKey);
|
|
14139
|
+
return openOutside(scoped, outside);
|
|
14140
|
+
}, function () { return false; });
|
|
14141
|
+
}
|
|
14142
|
+
var record = found.owner.record;
|
|
14143
|
+
var absolute = found.absolute;
|
|
14144
|
+
// A trailing separator or a file extension settles the kind without
|
|
14145
|
+
// a round trip; only an extension-less name has to be asked.
|
|
14146
|
+
var looksDir = /\/$/.test(absolute);
|
|
14147
|
+
var looksFile = !looksDir && /\.[^./]+$/.test(absolute);
|
|
14148
|
+
var open = function (dir) {
|
|
14149
|
+
return openTreeTabAt(ctx, {
|
|
14150
|
+
kind: found.owner.kind, id: record.id, side: 'remote',
|
|
14151
|
+
relative: absolute, dir: dir,
|
|
14152
|
+
}, claimScope(found.owner)) === true;
|
|
14153
|
+
};
|
|
14154
|
+
if (looksFile) return open(false);
|
|
14155
|
+
if (looksDir) return open(true);
|
|
14156
|
+
var stat = found.owner.kind === 'linked'
|
|
14157
|
+
? apiCall('fs.stat', { linkedId: record.id, path: absolute })
|
|
14158
|
+
: apiCall('fs.stat', { remoteId: record.id, path: absolute });
|
|
14159
|
+
return stat.then(function (result) {
|
|
14160
|
+
var type = result && result.type ? String(result.type) : '';
|
|
14161
|
+
return open(type === 'dir' || type === 'directory');
|
|
14162
|
+
}, function () { return false; });
|
|
14163
|
+
});
|
|
14164
|
+
}
|
|
14165
|
+
|
|
14166
|
+
function installOpenTabClaim() {
|
|
14167
|
+
if (typeof sidebar.openTab !== 'function' || sidebar.__lwClaimed === true) return false;
|
|
14168
|
+
var original = sidebar.openTab;
|
|
14169
|
+
try {
|
|
14170
|
+
Object.defineProperty(sidebar, '__lwClaimed', { value: true, enumerable: false });
|
|
14171
|
+
} catch (error) { sidebar.__lwClaimed = true; }
|
|
14172
|
+
sidebar.openTab = function (seed, scope) {
|
|
14173
|
+
// Only "show me this file" goes through the claim; every other kind —
|
|
14174
|
+
// including the tabs this plugin opens itself — keeps the old path.
|
|
14175
|
+
if (!seed || seed.type !== 'editor' || typeof seed.path !== 'string') {
|
|
14176
|
+
return original.apply(sidebar, arguments);
|
|
14177
|
+
}
|
|
14178
|
+
var normalized = String(seed.path).replace(/\\/g, '/');
|
|
14179
|
+
// Only a path that could name one of our roots: "/data/x.md" or
|
|
14180
|
+
// "D:/data/x.md". A relative or UNC path stays native.
|
|
14181
|
+
if (normalized.charAt(0) !== '/' && /^[A-Za-z]:\//.test(normalized) === false) {
|
|
14182
|
+
return original.apply(sidebar, arguments);
|
|
14183
|
+
}
|
|
14184
|
+
var seedCwd = scope && typeof scope.cwd === 'string' ? scope.cwd : '';
|
|
14185
|
+
takeSeed(normalized, seedCwd).then(function (claimed) {
|
|
14186
|
+
if (!claimed) original.call(sidebar, seed, scope);
|
|
14187
|
+
}, function () { original.call(sidebar, seed, scope); });
|
|
14188
|
+
return undefined;
|
|
14189
|
+
};
|
|
14190
|
+
// References open through openFile, not openTab; the same remote
|
|
14191
|
+
// path has to land in the tree there as well.
|
|
14192
|
+
var openFileOriginal = sidebar.openFile;
|
|
14193
|
+
if (typeof openFileOriginal === 'function') {
|
|
14194
|
+
sidebar.openFile = function (scope, path, title, options) {
|
|
14195
|
+
var args = arguments;
|
|
14196
|
+
var normalizedFile = typeof path === 'string' ? path.split(String.fromCharCode(92)).join('/') : '';
|
|
14197
|
+
var rooted = normalizedFile !== '' && (normalizedFile.charAt(0) === '/' || /^[A-Za-z]:\//.test(normalizedFile));
|
|
14198
|
+
if (!rooted) return openFileOriginal.apply(sidebar, args);
|
|
14199
|
+
var fileCwd = scope && typeof scope.cwd === 'string' ? scope.cwd : '';
|
|
14200
|
+
takeSeed(normalizedFile, fileCwd).then(function (claimed) {
|
|
14201
|
+
if (!claimed) openFileOriginal.apply(sidebar, args);
|
|
14202
|
+
}, function () { openFileOriginal.apply(sidebar, args); });
|
|
14203
|
+
return undefined;
|
|
14204
|
+
};
|
|
14205
|
+
}
|
|
14206
|
+
return true;
|
|
14207
|
+
}
|
|
14208
|
+
|
|
13687
14209
|
function handOver(tab) {
|
|
13688
14210
|
var normalized = String(tab && tab.path ? tab.path : '').replace(/\\/g, '/');
|
|
13689
14211
|
var match = PLACEHOLDER_PATH.exec(normalized);
|
|
@@ -13717,6 +14239,12 @@ function rememberShowHidden(value) {
|
|
|
13717
14239
|
scanning = true;
|
|
13718
14240
|
try {
|
|
13719
14241
|
var tabs = sidebar.nativePathTabs() || [];
|
|
14242
|
+
for (var remember = 0; remember < tabs.length; remember += 1) {
|
|
14243
|
+
var remembered = tabs[remember];
|
|
14244
|
+
if (remembered && remembered.sessionId && remembered.cwd) {
|
|
14245
|
+
sessionCwds.set(String(remembered.sessionId), String(remembered.cwd));
|
|
14246
|
+
}
|
|
14247
|
+
}
|
|
13720
14248
|
if (ownedNativeTabs.size > 0) {
|
|
13721
14249
|
var live = new Set();
|
|
13722
14250
|
for (var cursor = 0; cursor < tabs.length; cursor += 1) {
|
|
@@ -13732,14 +14260,22 @@ function rememberShowHidden(value) {
|
|
|
13732
14260
|
}
|
|
13733
14261
|
}
|
|
13734
14262
|
|
|
14263
|
+
// Claiming has to be installed before the first chat link is clicked; the
|
|
14264
|
+
// scan below stays as the safety net for a sidebar that owns a different
|
|
14265
|
+
// object than the one we patched.
|
|
14266
|
+
installOpenTabClaim();
|
|
13735
14267
|
scan();
|
|
13736
14268
|
// Native right-column tabs live in the sidebar's own adapter and never
|
|
13737
14269
|
// reach the shared store, so `subscribeState` stays silent when one opens
|
|
13738
14270
|
// — the interval is what actually catches them. It only runs the prefix
|
|
13739
14271
|
// test, so a tick costs nothing when nothing is open.
|
|
13740
|
-
|
|
14272
|
+
// Warm the index now: the first click should not wait for two host
|
|
14273
|
+
// calls, and linked.list can take seconds over SSH.
|
|
14274
|
+
workspaceIndex();
|
|
14275
|
+
|
|
14276
|
+
return ctx.effect(function () {
|
|
13741
14277
|
var stop = sidebar.subscribeState(scan);
|
|
13742
|
-
var timer = setInterval(scan,
|
|
14278
|
+
var timer = setInterval(scan, 800);
|
|
13743
14279
|
// A hand-over skipped while the window was hidden has to happen as soon
|
|
13744
14280
|
// as it is back, otherwise the click looks like it did nothing.
|
|
13745
14281
|
function onVisibility() {
|
package/lib/index.js
CHANGED
|
@@ -4246,14 +4246,21 @@ export function apply(ctx) {
|
|
|
4246
4246
|
const stat = await scope.remote.stat(target)
|
|
4247
4247
|
if (stat.type === 'dir') throw new ApiError('FS_IS_DIR', '目标是目录,请用 list_outside')
|
|
4248
4248
|
const limit = clampInt(params.maxBytes, 1024, READ_CAP, 262144)
|
|
4249
|
-
|
|
4249
|
+
// Paging: the caller passes the byte it stopped at, so a big artefact can
|
|
4250
|
+
// be read in pieces instead of being cut off at one window.
|
|
4251
|
+
const offset = clampInt(params.offset, 0, Number.MAX_SAFE_INTEGER, 0)
|
|
4252
|
+
const start = Math.min(offset, stat.size)
|
|
4253
|
+
const read = await scope.remote.readFile(target, { maxBytes: limit, offset: start })
|
|
4250
4254
|
const binary = looksBinary(read.data)
|
|
4255
|
+
const returned = read.data.length
|
|
4251
4256
|
return {
|
|
4252
4257
|
path: target,
|
|
4253
4258
|
size: stat.size,
|
|
4254
4259
|
mtime: stat.mtime,
|
|
4255
4260
|
binary,
|
|
4256
|
-
|
|
4261
|
+
offset: start,
|
|
4262
|
+
returned,
|
|
4263
|
+
truncated: start + returned < stat.size,
|
|
4257
4264
|
content: binary ? '' : decodeUtf8(read.data),
|
|
4258
4265
|
}
|
|
4259
4266
|
},
|
package/lib/ssh.js
CHANGED
|
@@ -1808,23 +1808,31 @@ export class RemoteHost {
|
|
|
1808
1808
|
if (stat.type === 'dir') throw new SshError('FS_IS_DIR', `Cannot read "${target}": it is a directory`);
|
|
1809
1809
|
|
|
1810
1810
|
const size = stat.size;
|
|
1811
|
-
|
|
1812
|
-
|
|
1811
|
+
// Callers that page through a big file pass an offset; everything else
|
|
1812
|
+
// starts at the beginning, exactly as before.
|
|
1813
|
+
const requestedOffset = Number(options && options.offset);
|
|
1814
|
+
const offset = Number.isFinite(requestedOffset) && requestedOffset > 0
|
|
1815
|
+
? Math.min(Math.floor(requestedOffset), size)
|
|
1816
|
+
: 0;
|
|
1817
|
+
const remaining = size - offset;
|
|
1818
|
+
const truncated = remaining > maxBytes;
|
|
1819
|
+
const limit = truncated ? maxBytes : remaining;
|
|
1813
1820
|
|
|
1814
1821
|
const data = await this.#sftpOp(label, async (sftp) => {
|
|
1815
1822
|
const handle = await callSftp(sftp, 'open', target, 'r');
|
|
1816
1823
|
try {
|
|
1817
1824
|
const chunks = [];
|
|
1818
|
-
let position =
|
|
1819
|
-
|
|
1820
|
-
|
|
1825
|
+
let position = offset;
|
|
1826
|
+
const end = offset + limit;
|
|
1827
|
+
while (position < end) {
|
|
1828
|
+
const want = Math.min(SFTP_READ_CHUNK, end - position);
|
|
1821
1829
|
const buffer = Buffer.allocUnsafe(want);
|
|
1822
1830
|
const bytesRead = await callSftp(sftp, 'read', handle, buffer, 0, want, position);
|
|
1823
1831
|
if (!bytesRead) break;
|
|
1824
1832
|
chunks.push(buffer.subarray(0, bytesRead));
|
|
1825
1833
|
position += bytesRead;
|
|
1826
1834
|
}
|
|
1827
|
-
return Buffer.concat(chunks, position);
|
|
1835
|
+
return Buffer.concat(chunks, position - offset);
|
|
1828
1836
|
} finally {
|
|
1829
1837
|
try {
|
|
1830
1838
|
await callSftp(sftp, 'close', handle);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-linked-workspace",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.32.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",
|