dsh-plugin-wsl-env 0.29.0 → 0.29.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/CHANGELOG.md +342 -0
  2. package/CONTRIBUTING.md +68 -12
  3. package/CONTRIBUTING.zh.md +34 -4
  4. package/README.md +1 -1
  5. package/agent/native/linux-aarch64/dsh-wsl-agent +0 -0
  6. package/agent/native/linux-x86_64/dsh-wsl-agent +0 -0
  7. package/agent/wsl-agent.sh +15 -4
  8. package/client.js +454 -110
  9. package/cordis.patch.yml +28 -7
  10. package/docs/AGENT-PROTOCOL-V7.md +4 -2
  11. package/docs/ARCHITECTURE.md +3 -1
  12. package/docs/ARCHITECTURE.zh.md +3 -1
  13. package/docs/COMPATIBILITY.md +1 -1
  14. package/docs/COMPATIBILITY.zh.md +1 -1
  15. package/docs/CONFIGURATION.md +19 -7
  16. package/docs/CONFIGURATION.zh.md +13 -5
  17. package/docs/DIAGNOSTICS.md +31 -5
  18. package/docs/DIAGNOSTICS.zh.md +22 -5
  19. package/docs/LIMITATIONS.md +65 -6
  20. package/docs/LIMITATIONS.zh.md +51 -6
  21. package/docs/PERFORMANCE.md +29 -1
  22. package/docs/PERFORMANCE.zh.md +23 -1
  23. package/docs/QUICKSTART.md +1 -1
  24. package/docs/QUICKSTART.zh.md +1 -1
  25. package/docs/README.zh.md +1 -1
  26. package/docs/RELEASING.md +29 -6
  27. package/docs/RELEASING.zh.md +9 -0
  28. package/docs/adr/0002-native-agent.md +50 -2
  29. package/lib/agent-confined.js +15 -4
  30. package/lib/agent-errors.d.ts +16 -0
  31. package/lib/agent-errors.js +19 -0
  32. package/lib/agent-exec.d.ts +8 -1
  33. package/lib/agent-exec.js +2 -1
  34. package/lib/agent-shared.d.ts +85 -2
  35. package/lib/agent-shared.js +167 -38
  36. package/lib/agent.d.ts +60 -6
  37. package/lib/agent.js +177 -28
  38. package/lib/auto-preset.js +7 -2
  39. package/lib/doctor-live.d.ts +36 -7
  40. package/lib/doctor-live.js +61 -12
  41. package/lib/doctor-process.d.ts +68 -0
  42. package/lib/doctor-process.js +139 -0
  43. package/lib/doctor-report.js +11 -109
  44. package/lib/fs-substrate.js +3 -3
  45. package/lib/fsio-agent.d.ts +57 -6
  46. package/lib/fsio-agent.js +168 -75
  47. package/lib/git-exec.d.ts +7 -1
  48. package/lib/git-exec.js +14 -2
  49. package/lib/native-agent.d.ts +25 -4
  50. package/lib/native-agent.js +52 -9
  51. package/lib/picker.d.ts +2 -1
  52. package/lib/picker.js +30 -13
  53. package/lib/plugin-update.js +18 -14
  54. package/lib/provider-common.d.ts +112 -0
  55. package/lib/provider-common.js +171 -0
  56. package/lib/sandbox-core.js +52 -13
  57. package/lib/search-exec.d.ts +6 -0
  58. package/lib/search-exec.js +10 -2
  59. package/lib/session-runtime.d.ts +46 -1
  60. package/lib/session-runtime.js +57 -7
  61. package/lib/session-scope.d.ts +22 -1
  62. package/lib/session-scope.js +33 -7
  63. package/lib/shell-env.js +125 -12
  64. package/lib/socket-isolation.d.ts +12 -4
  65. package/lib/socket-isolation.js +27 -10
  66. package/lib/status.js +53 -4
  67. package/lib/subprocess.js +3 -3
  68. package/lib/terminal-activity.js +6 -9
  69. package/lib/wsl-doctor-command.js +36 -80
  70. package/lib/wsl-filesystem.d.ts +9 -4
  71. package/lib/wsl-filesystem.js +26 -10
  72. package/lib/wsl-shell.d.ts +27 -17
  73. package/lib/wsl-shell.js +83 -24
  74. package/lib/wsl.d.ts +3 -1
  75. package/lib/wsl.js +82 -7
  76. package/package.json +5 -4
  77. package/scripts/bootstrap.sh +36 -12
  78. package/scripts/doctor.mjs +514 -201
@@ -18,6 +18,12 @@ Windows 侧 share 后端(`substrate: "share"`)在启动时被拒绝;WSL
18
18
  substrate,并附带恢复路径。一次崩溃可用一次重建;重建耗尽后进入有界复活
19
19
  (2/4/8 s),共三次尝试;第 4 次死亡才永久退出,直到应用重启。没有回退
20
20
  I/O——这是有意为之。
21
+ - **native agent 的降级只凭证据,并且会自动重试** —— 每个 distro 只有一个共享
22
+ agent 实例,死亡后由它自己的重建与复活预算恢复,不会被换成一个新实例。
23
+ 只有当一次启动里失败的是 native 入口、而随后的 shell 入口在同一发行版上
24
+ 启动成功时,读操作才改走 shell agent,5 分钟后再试 native。发行版本身宕机
25
+ 时两种入口一样失败,不算在 native 头上;准备失败(复制、校验、执行检查)
26
+ 也不会被当成结论缓存,下一次启动会重新准备。
21
27
  - **变更守卫不是原子的比较并交换。** 创建使用不可替换的 link;覆盖在 rename 前
22
28
  会重新校验版本。不匹配时返回 `FS_STALE_VERSION`,但检查与 rename 之间发生的
23
29
  变更仍可能被覆盖。
@@ -44,8 +50,8 @@ Windows 侧 share 后端(`substrate: "share"`)在启动时被拒绝;WSL
44
50
  provider 错误;工作目录缺失同样显式失败(rg 的错误码 2,`1` 只表示"无
45
51
  匹配")。命令与常驻 agent 都继承 `wsl.exe` 的默认 PATH,因此
46
52
  `~/.local/bin` 下的用户级安装不可见——请装成系统级,或放在那个 PATH 上。
47
- 安装:`wsl.exe -d <distro> -u root -- apt-get install -y bubblewrap
48
- git ripgrep inotify-tools`(或检测到的包管理族对应的写法)。`--install` 只在
53
+ 安装:`wsl.exe -d <distro> -u root -- sh -c "apt-get update -qq && apt-get install -y --no-install-recommends bubblewrap git ripgrep inotify-tools"`
54
+ (或检测到的包管理族对应的写法)。`--install` 只在
49
55
  缺少 `bubblewrap` 时才执行安装。
50
56
  - **`watch()` 是粗粒度失效,不是逐文件通知**:inotify 事件合并到 0.5 s,
51
57
  否则使用 `find -newer` 轮询循环。轮询路径会遗漏原地的 `cp -p`,以及恢复
@@ -77,21 +83,55 @@ Windows 侧 share 后端(`substrate: "share"`)在启动时被拒绝;WSL
77
83
  `FileReferenceTraversal` 接缝:
78
84
  [UPSTREAM-FILE-REFERENCE-SEAM.md](UPSTREAM-FILE-REFERENCE-SEAM.md)。
79
85
 
86
+ ## 内置 skill
87
+
88
+ `preset-wsl` 与应用自带的标准模式保持同一份行集,其中 `skill-filesystem`
89
+ 的 `customSkillDirs` 照搬上游,指向应用安装目录里 agent preset 包自带的
90
+ `skills` 目录。该目录在宿主上,而本 preset 的文件系统是发行版的:
91
+
92
+ - **内置 skill 经发行版的 `/mnt/<盘符>/…` 读取**:`wsl-fs` 把宿主盘符路径
93
+ 映射到发行版的挂载点,再由常驻 agent 读取(2026-11-24 实测:未打包的
94
+ 宿主目录 `resolve` 与 `listDir` 正常)。发行版把盘符挂在别处
95
+ (`/etc/wsl.conf` 的 `automount.root`)时读不到。
96
+ - **Desktop 安装包的 WSL 会话里没有内置 skill**:应用的 `node_modules` 打在
97
+ `app.asar` 归档内,`/mnt/c/…/app.asar/…` 在发行版内不是目录,`wsl-fs`
98
+ 以 `FS_NOT_DIRECTORY` 拒绝(2026-11-24 实测);skill 提供方把这类根按
99
+ 「不存在」跳过,所以内置的 `dsh-doc` 不会出现在工具面,其余 skill 根
100
+ (项目目录、用户目录)不受影响。宿主模式由应用进程直接读归档,没有
101
+ 这个限制。
102
+
80
103
  ## 沙箱
81
104
 
82
105
  - **一次性回退路径只有宿主截止时间** —— `wsl.exe` 被杀时不会把 kill 传进
83
106
  发行版,因此 Linux 进程树可能比调用活得更久。长命令建议
84
107
  `agent: true` 并使用会话 runtime。
108
+ - **常驻 agent 丢失时已在途的命令不会重跑** —— 命令尚未到达常驻 agent
109
+ (agent 已死、正在退避、握手失败)时回退到一次性 `wsl.exe`。常驻 agent
110
+ 在命令执行途中死亡时,命令可能已经生效:它以「状态未知」失败,并提示先
111
+ 检查发行版,不会在一次性路径上再执行一遍。
85
112
  - **批量读取按发行版共享一个原生 agent**(16 个并发调用 2.4-4.1 ms;
86
113
  第一次调用要付出约 70 ms 的准备)。
87
114
  - **aarch64 只在 CI 中于 qemu 下运行**(身边没有 Windows-on-ARM 机器——
88
115
  [COMPATIBILITY.md](COMPATIBILITY.md#scope-decisions))。`auto` 仍会选择
89
116
  包内二进制;`native` 在准备失败时拒绝;`shell` 强制使用 shell agent。
117
+ - **托管的 cloud WSL 门禁以发行版的 root 用户跑完整探针套件** ——
118
+ `.github/workflows/cloud-wsl-gate.yml` 以 `-u root` 执行
119
+ `run-all-when-closed.sh`,并只为 root 开启 linger。真实部署使用普通 distro
120
+ 用户:非特权 user namespace、用户级 systemd 与 linger 是另一条路径,root
121
+ 下通过不等于普通用户下通过。普通用户路径仍以真机探针为准,该门禁不声称
122
+ 覆盖它(见 #88)。
90
123
  - **会话 runtime 需要 systemd 和带 linger 的 user manager** —— 否则在
91
124
  第一条命令时被拒绝并给出补救方法;把 `sessionSandbox` 设为 `auto`
92
125
  (无 systemd 时即按命令形态)或 `false` 保留旧的按命令形态。应用硬崩溃
93
126
  可能留下过期的 `dsh-wsl-*.scope`;预检会在下一个
94
127
  WSL 会话时清扫过期 scope(从不清扫其他活跃会话的)。
128
+ - **会话 runtime 随会话的 agent 释放** —— 会话的 agent 被处置(上游的
129
+ `agent/disposed`)时,两个 provider 各自放掉该会话的引用,scope 被停止,
130
+ 其中的后台进程一并回收。当前 Harness(≤ 0.2.2-rc.5)在关闭会话视图时并不
131
+ 处置 agent,而是保留到应用退出,所以在此之前每个跑过命令的会话各有一个
132
+ runtime。另有一层兜底清扫:runtime 连续 10 分钟没有任何交换、且已没有活跃
133
+ agent 属于该会话(或它从未指明会话)时,该会话结束;会话仍活跃的 runtime
134
+ 不设空闲时限。
95
135
  - **沙箱不管辖 WSL interop** —— 上报为 `enforcement: partial`。
96
136
  `maskWindowsDrive` 和 `interopVisibility` 收窄 `/mnt` 但不是关闭;即使是
97
137
  `interopVisibility: "disabled"` 也只是给出 `wsl.conf` 中
@@ -152,7 +192,9 @@ Windows 侧 share 后端(`substrate: "share"`)在启动时被拒绝;WSL
152
192
  在跑的那个——存在共享 agent 时,doctorReport 会经
153
193
  `mergeLiveResidentStatus` 合入 `WslAgent.status()` 的在驻视角(0.18.0),
154
194
  但 CLI 的握手检查仍会标注其探测来源(`probed: a fresh resident`);
155
- 没有应用侧调用时,`lastError` 仍留在应用日志里。
195
+ 没有应用侧调用时,`lastError` 仍留在应用日志里。已经死亡的常驻 agent
196
+ 会让合并后的检查失败,报告的 verdict 随之变为 blocked;恢复后的常驻
197
+ agent 沿用新探测的结论,读操作不在 native agent 上时合并详情会写明原因。
156
198
  - **`dsh-wsl-*.scope` 计数是某一时刻的快照**;`--fix` 会执行预检的清扫。
157
199
  - **doctor 的 `git.win-safe` 探针通过 interop 的 `git.exe` 报告 Windows git
158
200
  的信任状态** —— 装了 Windows git 时,WSL 变更审查需要那份
@@ -210,9 +252,12 @@ Windows git `safe.directory` 白名单)。`--fix-owned` 把运行收窄到插
210
252
 
211
253
  ## 端口
212
254
 
213
- - **端口轮询让常驻 agent 在每个活跃发行版上永久保温**
214
- (10 s 刷新)。把 `portsRefreshMs` 调到超过 agent 的空闲超时即可恢复
215
- 空闲关停,代价是端口事实更陈旧。
255
+ - **端口轮询让常驻 agent 在使用它的发行版上保持保温** —— 只要有存活
256
+ 会话在该发行版里工作,就每 `portsRefreshMs`(默认 10 s)刷新一次;会话
257
+ 都结束后停止轮询,agent 才会空闲关停。每个周期先向 WSL 确认哪些发行版
258
+ 在运行:已停止的发行版不会被探测(探测会把它重新启动起来),
259
+ `DSH_WSL_PORTS` 读作空。把 `portsRefreshMs` 调到超过 agent 的空闲超时可以
260
+ 提早恢复空闲关停,代价是端口事实更陈旧。
216
261
 
217
262
  ## 目录选择器
218
263
 
@@ -33,6 +33,31 @@ Absolute numbers are machine-dependent; the ratio and the budgets are the point.
33
33
  | GUI-preview backend: `stat` | — | p95 **2.7 ms** | `pnpm run probe:gui-preview` (20 iterations, 2026-10-19) |
34
34
  | GUI-preview backend: listing | — | p95 **5.1 ms** | same |
35
35
  | GUI-preview backend: 1 MiB page | — | p95 **63.5 ms/MiB** | same |
36
+ | Whole-file read of 1 MiB (native agent) | — | median **15.0 ms** (26.6 ms with the read window inside the batched frame) | #76, 2026-11-24 |
37
+ | Parsing one 16 MiB response frame (arriving in 64 KiB chunks) | — | **83 ms** of the host event loop (2678 ms when every chunk re-joined one growing string) | same, host side only |
38
+ | Listing a directory of 200 symlinks | — | median **6.1 ms** (136.3 ms with two round trips per link) | same |
39
+ | A 64–256 KiB stdin payload through `wsl.exe` (native agent) | — | median **18–67 ms** (114–117 ms as one write) | #86, 2026-11-24, Windows host Node |
40
+
41
+ The first three rows dated 2026-11-24 were measured on WSL 2 Ubuntu x86_64
42
+ with the native agent started directly inside the distro (no `wsl.exe` hop), as
43
+ the median of 15 runs; the numbers in parentheses are the previous code on the
44
+ same machine. They stand for three structural costs — a read payload
45
+ base64-encoded twice inside a batched frame, a whole frame re-joined and
46
+ re-scanned on every chunk, and two round trips per symlink — so what went away
47
+ is the term that grew with the square of the size, not merely a constant.
48
+
49
+ The stdin row was measured on the same machine from Node v24.17 on the Windows
50
+ host, through `wsl.exe`, as time to result. A frame above one pipe buffer
51
+ (64 KiB) written as one `write()` cost a fixed ~100 ms before the resident had
52
+ the rest of it — its own `ACK` was what arrived late — while the same binary
53
+ started directly inside the distro answered a 68 KiB payload in 14 ms. The
54
+ piece size is not the cause (the same bytes written back to back as several
55
+ pieces pay it too), nor is the reader (`cat` and a line-at-a-time reader see
56
+ 68 KiB in under 5 ms); what removes the cost is a timer turn between the
57
+ pieces. Frames between 64 KiB and 512 KiB now go out in pieces; larger ones
58
+ stay one write (a 512 KiB payload: 123 ms as one write, 144 ms pieced). A
59
+ timer turn costs about 10 ms on a Windows host, so it is paid only inside the
60
+ band where the measurement says it wins.
36
61
 
37
62
  The GUI-preview number covers the routed backend operations a preview pays.
38
63
  The shipped `workspace-files` service adds its own calls on top; that service
@@ -51,7 +76,10 @@ node test/probe/fs-queue.mjs # the agent queue, sequential vs concurrent, w
51
76
 
52
77
  Both need WSL interop, a working distro and Node; neither boots the harness.
53
78
  The queue measurement also needs systemd and a usable native binary; it prints
54
- wall times and queue metrics but does not enforce latency budgets. The GUI-preview
79
+ wall times and queue metrics but does not enforce latency budgets. It prints
80
+ one `stdin write` row per payload size; the step that row is about shows only
81
+ when the probe runs from Node on the Windows host — inside the distro the
82
+ pieces are written just the same, but one write never paid it there. The GUI-preview
55
83
  probe reports p50/p95/max and fails when its budgets are exceeded.
56
84
 
57
85
  ## What is not measured
@@ -31,6 +31,26 @@ GUI 文件树、预览和模型的文件工具都走 agent 路径。设计与权
31
31
  | GUI 预览后端:`stat` | — | p95 **2.7 ms** | `pnpm run probe:gui-preview`(20 次迭代,2026-10-19) |
32
32
  | GUI 预览后端:目录列举 | — | p95 **5.1 ms** | 同上 |
33
33
  | GUI 预览后端:1 MiB 页面 | — | p95 **63.5 ms/MiB** | 同上 |
34
+ | 整文件读取 1 MiB(native agent) | — | 中位 **15.0 ms**(读窗口放进批量帧时为 26.6 ms) | #76,2026-11-24 |
35
+ | 解析一个 16 MiB 的响应帧(按 64 KiB 分块到达) | — | 占用宿主事件循环 **83 ms**(逐块拼接到一个增长的字符串时为 2678 ms) | 同上,纯宿主侧 |
36
+ | 列举含 200 个符号链接的目录 | — | 中位 **6.1 ms**(每个链接各走两次往返时为 136.3 ms) | 同上 |
37
+ | 经 `wsl.exe` 的 64–256 KiB stdin 载荷(native agent) | — | 中位 **18–67 ms**(一次写入时为 114–117 ms) | #86,2026-11-24,Windows 宿主 Node |
38
+
39
+ 2026-11-24 的前三行在 WSL 2 Ubuntu x86_64 上测得:native agent 直接在
40
+ 发行版内启动(不经 `wsl.exe`),取 15 次运行的中位数;括号里是同一台
41
+ 机器上改动之前的代码。它们对应三处结构性开销——读载荷在批量帧里被
42
+ base64 编码两次、每来一块就把整帧重新拼接并扫描、每个符号链接各付两次
43
+ 往返——所以消除的是随大小平方增长的那一项,而不只是常数。
44
+
45
+ stdin 一行在同一台机器的 Windows 宿主上用 Node v24.17 测得(经
46
+ `wsl.exe`,计时到结果)。超过一个管道缓冲(64 KiB)的帧一次写入,要等
47
+ 固定约 100 ms 常驻进程才拿到其余部分——迟到的是它自己的 `ACK`——而同一个
48
+ 二进制直接在发行版内启动时,68 KiB 载荷 14 ms 就返回。分片大小不是原因
49
+ (同样的字节背靠背写成多片一样要付),读方也不是(`cat` 和逐行读取器
50
+ 5 ms 内拿到 68 KiB);去掉这笔开销的是片与片之间让出一个定时器回合。
51
+ 现在 64 KiB 到 512 KiB 之间的帧分片写入,更大的帧保持一次写入(512 KiB
52
+ 载荷:一次写入 123 ms,分片 144 ms)。Windows 上一个定时器回合约 10 ms,
53
+ 所以只在实测划算的区间内支付。
34
54
 
35
55
  GUI 预览数字覆盖一次预览所支付的、经路由的后端操作。随包的
36
56
  `workspace-files` 服务会在其上追加自己的调用;该服务的形态在
@@ -48,7 +68,9 @@ node test/probe/fs-queue.mjs # the agent queue, sequential vs concurrent, w
48
68
 
49
69
  两者都需要 WSL 互操作、可用的发行版和 Node;都不启动 harness。队列测量还
50
70
  需要 systemd 和可用的原生二进制;它打印实际耗时和队列指标,但不强制延迟
51
- 预算。GUI 预览探针报告 p50/p95/max,并在超出预算时失败。
71
+ 预算。队列测量按载荷大小各打印一行 `stdin write`;那一节只有从 Windows
72
+ 宿主的 Node 运行时才看得到台阶——在发行版内运行时分片同样生效,但一次
73
+ 写入本来就没有这笔开销。GUI 预览探针报告 p50/p95/max,并在超出预算时失败。
52
74
 
53
75
  ## 未测量的内容
54
76
 
@@ -27,7 +27,7 @@ supplies the WSL environment.
27
27
  |---|---|---|
28
28
  | Windows 10/11 with WSL 2 | `wsl.exe -l -v` shows `VERSION 2` | `wsl.exe --install` |
29
29
  | A distro | one line in the list above | `wsl.exe --install -d Ubuntu` |
30
- | `bubblewrap` | `wsl.exe -d <distro> -- which bwrap` | `wsl.exe -d <distro> -u root -- apt-get install -y bubblewrap` |
30
+ | `bubblewrap` | `wsl.exe -d <distro> -- which bwrap` | `wsl.exe -d <distro> -u root -- sh -c "apt-get update -qq && apt-get install -y --no-install-recommends bubblewrap"` |
31
31
  | systemd + Linger (for the session runtime) | `node <plugin>/scripts/doctor.mjs` (installed) or `pnpm run doctor` (checkout) | `[boot] systemd=true` in `/etc/wsl.conf`, `wsl --shutdown`, then `loginctl enable-linger "$USER"`; or set `sessionSandbox: auto`/`false` |
32
32
  | Node `^22.19.0` or `>=24.0.0` | only needed for source/development work | not needed inside the distro to use the published plugin |
33
33
 
@@ -25,7 +25,7 @@ dsh headless "run the tests" # 单任务、输出答案后退出
25
25
  |---|---|---|
26
26
  | Windows 10/11,启用 WSL 2 | `wsl.exe -l -v` 显示 `VERSION 2` | `wsl.exe --install` |
27
27
  | 一个发行版 | 上面列表中有一行 | `wsl.exe --install -d Ubuntu` |
28
- | `bubblewrap` | `wsl.exe -d <distro> -- which bwrap` | `wsl.exe -d <distro> -u root -- apt-get install -y bubblewrap` |
28
+ | `bubblewrap` | `wsl.exe -d <distro> -- which bwrap` | `wsl.exe -d <distro> -u root -- sh -c "apt-get update -qq && apt-get install -y --no-install-recommends bubblewrap"` |
29
29
  | systemd + Linger(会话 runtime 需要) | `node <plugin>/scripts/doctor.mjs`(已安装)或 `pnpm run doctor`(检出目录) | 在 `/etc/wsl.conf` 设置 `[boot] systemd=true`,`wsl --shutdown`,然后 `loginctl enable-linger "$USER"`;或设置 `sessionSandbox: auto`/`false` |
30
30
  | Node `^22.19.0` 或 `>=24.0.0` | 仅源码/开发工作需要 | 使用已发布的插件时,发行版内不需要 Node |
31
31
 
package/docs/README.zh.md CHANGED
@@ -31,7 +31,7 @@
31
31
 
32
32
  桌面应用没有 `dsh` 可执行程序;插件经 **Plugins** 页安装。三步:
33
33
 
34
- 1. `wsl.exe -d <发行版> -u root -- apt-get install -y bubblewrap`
34
+ 1. `wsl.exe -d <发行版> -u root -- sh -c "apt-get update -qq && apt-get install -y --no-install-recommends bubblewrap"`
35
35
  2. Plugins 页:**Add plugin** → `dsh-plugin-wsl-env`,启用。
36
36
  3. 重启应用,打开发行版内的文件夹;输入 `/wsl-doctor`(宿主侧执行)得到 `ready`/`blocked` 裁决。
37
37
 
package/docs/RELEASING.md CHANGED
@@ -72,11 +72,19 @@ the `wsl.exe` tail on the Windows CI legs or moving the coverage job
72
72
  `windows-latest`.
73
73
 
74
74
  Run the full real-machine suite when behaviour changed, and keep its output for
75
- the pull request or the release notes. The harness application must be closed;
76
- the runner waits until it exits:
75
+ the pull request or the release notes. The default launcher closes ordinary
76
+ Harness processes itself — a process-tree kill, announced with the PIDs — so a
77
+ closed window or a tray-resident build does not have to be found by hand;
78
+ `--wait-only` keeps the manual-close workflow and kills nothing. Either way the
79
+ run polls until the app is gone, refuses to run while a stale probe instance
80
+ is still up, and bounds each probe with its own deadline
81
+ (`DSH_WSL_ENV_PROBE_TIMEOUT`, default 900 s) — a wedged probe reports as
82
+ `FAIL <probe> (timeout after …)` instead of holding the suite unseen:
77
83
 
78
84
  ```bash
79
85
  bash test/probe/run-all-when-closed.sh --include-fs
86
+ # with the app closed by hand:
87
+ bash test/probe/run-all-when-closed.sh --include-fs --wait-only
80
88
  ```
81
89
 
82
90
  See [CONTRIBUTING.md](../CONTRIBUTING.md) for individual probes, prerequisites,
@@ -120,7 +128,11 @@ CDN's exact-version path
120
128
  (`download.deepseek.com/dsh-desk/bin/win-x64/deepseek-harness-<version>-win-x64.exe`);
121
129
  the CDN publishes no checksum object, so the smoke records the downloaded
122
130
  file's sha256 instead of verifying a published one, and requires `dsh
123
- --version` to report the exact requested version. The smoke identifies the
131
+ --version` to report the exact requested version. Before executing it, the
132
+ smoke also requires a `Valid` Authenticode signature whose signer CN is
133
+ `Hangzhou DeepSeek Artificial Intelligence Co., Ltd.` (overridable through
134
+ `DSH_OFFICIAL_HARNESS_SIGNER`); the download and the silent install each have
135
+ a 600-second ceiling. The smoke identifies the
124
136
  package by its tarball/registry identity (name, version, sha512);
125
137
  `--dump-config` proves the profile composes the plugin with no skipped
126
138
  entries, and the through-plugin probe (`test/probe/official-smoke-probe.mjs`)
@@ -141,8 +153,12 @@ in this order:
141
153
  2. Runs the official-Harness candidate smoke on Windows
142
154
  (`candidate-package-smoke`). Publish depends on this job, so a failing
143
155
  candidate blocks the release.
144
- 3. Runs `pnpm test`, `pnpm run test:coverage`, and the shipped x86_64 and
145
- aarch64 native-agent tests (the latter under QEMU).
156
+ 3. Runs the source gates in the separate read-only `gates` job, in parallel
157
+ with the Windows smoke: `pnpm test`, `pnpm run test:coverage`, the browser
158
+ suite, and the shipped x86_64 and aarch64 native-agent tests (the latter
159
+ under QEMU). Keeping this job away from publish means the write/OIDC
160
+ credentials never sit beside test code, and a red gate is reported without
161
+ waiting for the 45-minute Windows job.
146
162
  4. Downloads the `candidate-package` artifact, verifies its sha512 integrity
147
163
  and `pack.json` identity equal the pack job's outputs, asks the registry
148
164
  whether this version is already published, and skips the upload when it
@@ -151,7 +167,7 @@ in this order:
151
167
  5. Publishes the downloaded candidate tarball with
152
168
  `npm publish <tgz> --provenance --access public`. That attaches a signed
153
169
  attestation tying the tarball to this workflow run and this commit. A
154
- tarball publish runs no lifecycle scripts; the Gates step has already run
170
+ tarball publish runs no lifecycle scripts; the gates job has already run
155
171
  the full chain. A hand-run publish from the package directory keeps the
156
172
  `prepublishOnly` hook as its safety net.
157
173
  6. Reads back what the registry serves (integrity, file count, README name)
@@ -212,6 +228,13 @@ node scripts/check-release-tag.mjs vx.y.z
212
228
  npm publish --registry=https://registry.npmjs.org/ --access public
213
229
  ```
214
230
 
231
+ The same script answers the npm dist-tag the workflow publishes under:
232
+ `node scripts/check-release-tag.mjs --dist-tag` prints `next` for any
233
+ version with a prerelease segment and `latest` otherwise, and the tag check
234
+ refuses a version that is not `MAJOR.MINOR.PATCH` with an optional
235
+ `-prerelease`. A prerelease must never move `latest`, so a manual publish of
236
+ one adds `--tag "$(node scripts/check-release-tag.mjs --dist-tag)"`.
237
+
215
238
  Set `--registry` explicitly. A local `~/.npmrc` may point at a mirror, and a
216
239
  release published to a mirror is not a release.
217
240
 
@@ -23,6 +23,12 @@ Post-release gate: 每个 stable/next tag 在 registry 传播后
23
23
  - 官方 Harness 安装包从官方 CDN 的精确版本路径解析
24
24
  (`download.deepseek.com/dsh-desk/bin/win-x64/deepseek-harness-<version>-win-x64.exe`);
25
25
  CDN 不提供官方 checksum,smoke 记录下载文件的 sha256 作为证据而非比对。
26
+ 执行前还校验 Authenticode:签名状态必须为 `Valid`,签署者 CN 必须是
27
+ `Hangzhou DeepSeek Artificial Intelligence Co., Ltd.`(可用
28
+ `DSH_OFFICIAL_HARNESS_SIGNER` 覆盖);下载与静默安装各设 600 秒上限。
29
+ - 源码门禁(`pnpm test`、覆盖率、浏览器与原生 agent)在独立的只读 `gates` 任务
30
+ 中与 Windows smoke 并行执行;publish 只做 tarball 校验、发布与 registry 回读,
31
+ 预算 20 分钟(含最长 10 分钟的传播轮询)。
26
32
  - smoke 用 `dsh --version` 验证实际安装版本等于请求版本;两个 Windows 任务在
27
33
  smoke 前均先经 `.github/actions/provision-wsl` 安装 distro 与 WSL 前置依赖。
28
34
  - smoke 以 tarball/registry 身份(名称、版本、sha512)标识包;`--dump-config`
@@ -30,6 +36,9 @@ Post-release gate: 每个 stable/next tag 在 registry 传播后
30
36
  由 `test/probe/official-smoke-probe.mjs` 在官方 CLI 无头启动上覆盖(挂载插件的
31
37
  WSL shell executor,属 provider 级证据;session 运行时路径仍以源码门禁为准),
32
38
  失败即 FAIL。
39
+ - 发布使用的 dist-tag 由 `scripts/check-release-tag.mjs --dist-tag` 决定:任何带
40
+ 预发布段的版本发到 `next`,其余发到 `latest`;tag 检查同时拒绝不是
41
+ `MAJOR.MINOR.PATCH[-pre]` 形式的版本。
33
42
 
34
43
  其余步骤(确定版本、切分变更日志、完整检查、真机探针与发布后核验)见英文版
35
44
  [RELEASING.md](RELEASING.md)。
@@ -152,7 +152,9 @@ One process per agent, an event loop over stdin plus child pipes and timers:
152
152
  acknowledges them (`ACK|id`) and spawns each request's process group (or
153
153
  performs the FS syscalls directly for `stat`/`read`/`write`).
154
154
  - `KILL|id` and the per-request deadline signal the group: `TERM`, then
155
- `KILL` after a fixed grace; the event loop keeps serving other requests.
155
+ `KILL` after a grace; the event loop keeps serving other requests. Both
156
+ take the cancel path's three seconds (the deadline used to allow 100 ms —
157
+ see the hardening pass below).
156
158
  - stdout/stderr pipes are drained into per-request bounded buffers; the RES
157
159
  line carries the exit code, both buffers and the cut flags.
158
160
  - stdin EOF, `SHUTDOWN` or a fatal IO error runs the same cleanup as today:
@@ -162,7 +164,10 @@ One process per agent, an event loop over stdin plus child pipes and timers:
162
164
  - FS operations use syscalls (stat/lstat/readlink/read/write, atomic rename);
163
165
  no `sh`, `base64`, `stat`, `find` subprocesses. The write path keeps the
164
166
  no-replace and expected-version semantics the host fence relies on, and the
165
- same staging-directory cleanup for killed writes.
167
+ same staging-directory cleanup for killed writes. Mutations serialize with
168
+ each other under `fs_lock`; reads wait for nothing. A `move` on one
169
+ filesystem is a `rename` — the inode keeps its identity — and is copied
170
+ only across filesystems.
166
171
 
167
172
  ## Host integration
168
173
 
@@ -299,6 +304,49 @@ step is the **native shared read agent (v5)** — same packaged binary and
299
304
  protocol, the shell as fallback, roughly 30x on batch reads — not v6. The
300
305
  single-op latency (~22 ms) is the transport, not the FS backend.
301
306
 
307
+ ## Hardening pass (2026-11-24, #74 and #78)
308
+
309
+ A code review with measurements on a real distro found six defects in this
310
+ process model. Each is fixed in `agent/native/spike/src/main.rs` and pinned by
311
+ a check in `agent/native/spike/test.mjs` that fails against the previous
312
+ binary and passes against the rebuilt one, on x86_64 and (under qemu-user) on
313
+ aarch64:
314
+
315
+ - **The stdin feed could deadlock the request thread.** It was written from
316
+ the request's own thread before the output readers started, on the claim
317
+ that "the pipe holds a frame-sized feed". A child that echoes — `cat` with
318
+ 1.25 MiB or more on stdin — filled its stdout pipe, stopped reading, and
319
+ the feed blocked with the wait loop and its timeout queued behind it; the
320
+ host watchdog killed the transport eighteen seconds in. The feed now runs
321
+ on its own thread, after both readers are running.
322
+ - **Every FS frame took `fs_lock`, and the `ACK` followed the lock.** A
323
+ stat queued behind a 32 MiB write waited its full 408 ms. Only mutations
324
+ (`write`, `delete`, `move`, and a batch holding one) take the lock now, and
325
+ the `ACK` reports the dequeue.
326
+ - **One vanished entry failed a whole listing.** A directory under churn
327
+ (a build output directory) failed about a tenth to a third of its listings
328
+ with `notfound` while it existed; an entry whose `lstat` answers `ENOENT`
329
+ is skipped. The shell agent's `find` is tolerated the same way, for the one
330
+ diagnostic that names a vanished entry.
331
+ - **The timeout allowed 100 ms before `KILL`.** A command that cleans up on
332
+ `TERM` was killed first (exit 137). The deadline now takes the cancel
333
+ path's TERM-then-KILL grace.
334
+ - **`move` always copied the file whole.** 106 ms for 256 MiB, under the
335
+ lock. A same-filesystem move is now `rename(2)`, with
336
+ `renameat2(RENAME_NOREPLACE)` for the no-replace guard; `EXDEV` (and a
337
+ filesystem without the flag) falls back to the copy.
338
+ - **Orphan staging directories were never swept.** The shell agent swept its
339
+ own leftovers, under a name the native agent did not use. Both agents now
340
+ stage under `.<base>.<pid>.<token>.tmpdir`, and a write sweeps that target's
341
+ staging directories whose creator's pid is gone — a live pid, and the
342
+ agent's own, are left alone.
343
+
344
+ The packaged binaries (`agent/native/linux-<arch>/dsh-wsl-agent`) were rebuilt
345
+ from this source with the pinned toolchain (1.99.1). They were linked with the
346
+ toolchain's self-contained musl objects rather than by the CI job's
347
+ `musl-gcc`/zig linkers, which this machine does not have; both pass the full
348
+ suite, the aarch64 one under qemu-user, and the session-runtime probe.
349
+
302
350
  ## Why it was built
303
351
 
304
352
  Built in 0.10.0. The triggers that fired were the long-build/FS-serialization
@@ -110,6 +110,16 @@ export function confinedAgent({ distro, wslPath = "wsl.exe", policy, maskWindows
110
110
  let agent = confinedAgents.get(key);
111
111
  if (agent === undefined) {
112
112
  const linuxRoot = toLinuxPath(policy.workspaceRoot);
113
+ /** The root-creating checklist, run at most once per resident instance. */
114
+ let checklist;
115
+ const prepareRoot = () => {
116
+ checklist ??= runSpawnChecklist({ wslPath, distro, root: linuxRoot }).catch((error) => {
117
+ // A failed checklist is not a verdict: the next start retries it.
118
+ checklist = undefined;
119
+ throw error;
120
+ });
121
+ return checklist.then(() => undefined);
122
+ };
113
123
  agent = new WslAgent({
114
124
  distro,
115
125
  wslPath,
@@ -125,10 +135,11 @@ export function confinedAgent({ distro, wslPath = "wsl.exe", policy, maskWindows
125
135
  // bwrap refuses a missing bind source (WSL-305): on a freshly imported
126
136
  // distro the first write's workspace may not exist yet, and the resident
127
137
  // used to exit during its handshake with a bare code 1. Create the root
128
- // before the first spawn; every later start re-runs it harmlessly.
129
- prepare: policy.mode === "workspace-write"
130
- ? () => runSpawnChecklist({ wslPath, distro, root: linuxRoot }).then(() => undefined)
131
- : undefined,
138
+ // before the first spawn. The memo keeps a later revival from spending
139
+ // another `wsl.exe` round trip; the agent's own start path calls
140
+ // `prepare` on every revival, and the checklist's other facts cannot
141
+ // change under a running resident.
142
+ prepare: policy.mode === "workspace-write" ? prepareRoot : undefined,
132
143
  });
133
144
  confinedAgents.set(key, agent);
134
145
  }
@@ -23,6 +23,22 @@ export declare class AgentUnavailableError extends Error {
23
23
  */
24
24
  constructor(message: string);
25
25
  }
26
+ /**
27
+ * The resident was lost while this request was with it, so the request MAY
28
+ * have run. Still an {@link AgentUnavailableError} — the resident is out — so
29
+ * a caller whose request is read-only (the search and git handles, the picker)
30
+ * keeps its fallback and simply runs the request again. A caller whose request
31
+ * has effects must not: replaying it would run non-idempotent work twice, or
32
+ * report a create that actually succeeded as a refusal. The shell executor
33
+ * therefore lets this one propagate instead of retrying on the one-shot path,
34
+ * and the message tells the model to inspect the distro before retrying.
35
+ */
36
+ export declare class AgentRequestStateUnknownError extends AgentUnavailableError {
37
+ /**
38
+ * @param message - what was in flight, for the log.
39
+ */
40
+ constructor(message: string);
41
+ }
26
42
  /**
27
43
  * The request's workdir could not be entered inside the distro. Carries the
28
44
  * Linux path so a caller can synthesize the same diagnostic the one-shot
@@ -26,6 +26,25 @@ export class AgentUnavailableError extends Error {
26
26
  this.name = "AgentUnavailableError";
27
27
  }
28
28
  }
29
+ /**
30
+ * The resident was lost while this request was with it, so the request MAY
31
+ * have run. Still an {@link AgentUnavailableError} — the resident is out — so
32
+ * a caller whose request is read-only (the search and git handles, the picker)
33
+ * keeps its fallback and simply runs the request again. A caller whose request
34
+ * has effects must not: replaying it would run non-idempotent work twice, or
35
+ * report a create that actually succeeded as a refusal. The shell executor
36
+ * therefore lets this one propagate instead of retrying on the one-shot path,
37
+ * and the message tells the model to inspect the distro before retrying.
38
+ */
39
+ export class AgentRequestStateUnknownError extends AgentUnavailableError {
40
+ /**
41
+ * @param message - what was in flight, for the log.
42
+ */
43
+ constructor(message) {
44
+ super(message);
45
+ this.name = "AgentRequestStateUnknownError";
46
+ }
47
+ }
29
48
  /**
30
49
  * The request's workdir could not be entered inside the distro. Carries the
31
50
  * Linux path so a caller can synthesize the same diagnostic the one-shot
@@ -124,7 +124,7 @@ export interface AgentExecutionHandle {
124
124
  * @returns the execution handle (`status`, `exitCode`, `signal`, `observed`,
125
125
  * `done`, `readOutput`, `kill`, `result`).
126
126
  */
127
- export declare function agentExecutionHandle({ agent, cwd, argv, timeoutMs, maxOutputBytes, env, signal, onStarted }: {
127
+ export declare function agentExecutionHandle({ agent, cwd, argv, timeoutMs, maxOutputBytes, env, signal, onStarted, onSettled }: {
128
128
  /**
129
129
  * The {@link WslAgent}-like runner: `exec` accepting
130
130
  * `{cwd, argv, timeoutMs, env, signal}` and resolving `{exitCode, stdout, stderr}`;
@@ -157,5 +157,12 @@ export declare function agentExecutionHandle({ agent, cwd, argv, timeoutMs, maxO
157
157
  * Provider-facts hook, called synchronously before the handle can settle.
158
158
  */
159
159
  onStarted?: (proc: object) => void;
160
+ /**
161
+ * Settlement hook, called after the status, exit code and signal are
162
+ * stamped and before `done` resolves to anyone else — the point at which
163
+ * upstream's own handle calls its settlement hook. `error` is the failure
164
+ * `result()` rejects with, when there is one.
165
+ */
166
+ onSettled?: (proc: AgentExecutionHandle, error: unknown) => void;
160
167
  }): AgentExecutionHandle;
161
168
  export {};
package/lib/agent-exec.js CHANGED
@@ -54,7 +54,7 @@ function memoryReader(buffer) {
54
54
  * @returns the execution handle (`status`, `exitCode`, `signal`, `observed`,
55
55
  * `done`, `readOutput`, `kill`, `result`).
56
56
  */
57
- export function agentExecutionHandle({ agent, cwd, argv, timeoutMs = 0, maxOutputBytes = 0, env, signal, onStarted }) {
57
+ export function agentExecutionHandle({ agent, cwd, argv, timeoutMs = 0, maxOutputBytes = 0, env, signal, onStarted, onSettled }) {
58
58
  // Our own controller is the kill channel; the caller's signal races it.
59
59
  const controller = new AbortController();
60
60
  let timedOut = false;
@@ -140,6 +140,7 @@ export function agentExecutionHandle({ agent, cwd, argv, timeoutMs = 0, maxOutpu
140
140
  proc.status = exitOutcome.signal !== null || exitOutcome.exitCode === null ? "killed" : "completed";
141
141
  proc.exitCode = exitOutcome.exitCode;
142
142
  proc.signal = exitOutcome.signal;
143
+ onSettled?.(proc, settleError);
143
144
  }),
144
145
  readOutput() {
145
146
  const out = stdoutReader().readFrom(stdoutOffset);
@@ -7,6 +7,23 @@
7
7
  * port snapshot all queue on ONE agent per distro, and the per-distro startup
8
8
  * cost is paid once per process.
9
9
  *
10
+ * One instance per `(wslPath, distro)` for the life of the process, and never a
11
+ * second for that pair: every holder (the executor, the filesystem provider,
12
+ * the picker, the git and search handles, the doctor) addresses the same
13
+ * object, so the state a diagnosis reads is the state the file operations run
14
+ * on. The transport is part of the key because a row with a custom `wslPath`
15
+ * must not keep talking through the default executable. The instance owns
16
+ * its own recovery — one rebuild per death, then a bounded revival — and this
17
+ * module does not second-guess it by swapping in a fresh one, which used to
18
+ * reset that budget at the first death and, at the same time, retire the
19
+ * native entry for good.
20
+ *
21
+ * The ENTRY is chosen per start, not per process: the native binary when the
22
+ * backend allows it and it comes up, the shell script otherwise. The native
23
+ * entry is demoted only on evidence that it is the one at fault — it failed
24
+ * a start and the shell entry then started on the same distro — and only for
25
+ * a while, after which it is tried again.
26
+ *
10
27
  * This is a TypeScript source built to `lib/agent-shared.js`; edit THIS file
11
28
  * and run `pnpm run build` — the artifact under `lib/` is generated, and
12
29
  * `pnpm test` fails when it drifts.
@@ -14,14 +31,80 @@
14
31
  * @module dsh-plugin-wsl-env/agent-shared
15
32
  */
16
33
  import { WslAgent } from "./agent.js";
34
+ /**
35
+ * How long the native entry stays demoted once it failed a start that the
36
+ * shell entry then made on the same distro. A demotion is a verdict about
37
+ * the moment, not the process — a reinstalled or resynced binary, or a cache
38
+ * directory made executable, works without an app restart — so the entry is
39
+ * tried again after this long; a still-broken one costs its next start one
40
+ * failed round trip and is demoted again.
41
+ */
42
+ export declare const NATIVE_DEMOTION_MS = 300000;
43
+ /** What one distro's starts have said so far about its native entry. */
44
+ export interface NativeVerdict {
45
+ /** The native entry failed its last start; the shell entry's next start decides. */
46
+ suspect: boolean;
47
+ /** When a demotion ends, epoch ms; 0 while the entry is not demoted. */
48
+ demotedUntil: number;
49
+ }
50
+ /** @returns a verdict nothing has been said about yet. */
51
+ export declare function freshNativeVerdict(): NativeVerdict;
52
+ /**
53
+ * Whether a start may use the native entry. A suspicion says no: the next
54
+ * start is the shell entry's, and its outcome is what turns the suspicion
55
+ * into a verdict. A demotion says no until it ends.
56
+ *
57
+ * @param verdict - the distro's verdict.
58
+ * @param now - the current time, epoch ms.
59
+ * @returns true when the native entry may be tried.
60
+ */
61
+ export declare function nativeEntryAllowed(verdict: NativeVerdict, now: number): boolean;
62
+ /**
63
+ * Read one start's outcome into the verdict.
64
+ *
65
+ * A failed native start is a suspicion, not a verdict: a distro that is down
66
+ * fails both entries alike, and must not retire a healthy binary. The shell
67
+ * entry starting right after it is the evidence — same distro, one entry up
68
+ * and one down — and that is what demotes the native entry. A native start
69
+ * that succeeds clears both.
70
+ *
71
+ * @param verdict - the distro's verdict; updated in place.
72
+ * @param outcome - how the start ended, and with which entry.
73
+ * @param now - the current time, epoch ms.
74
+ */
75
+ export declare function recordStart(verdict: NativeVerdict, outcome: {
76
+ ok: boolean;
77
+ native: boolean;
78
+ }, now: number): void;
17
79
  /** The agent script as a host-side path, for factories that need both spellings. */
18
80
  export declare const agentScriptPath: string;
19
81
  /** The sha256 of the shipped agent script; every resident verifies its HELLO against it. */
20
82
  export declare const agentScriptDigest: string;
21
83
  /**
22
- * The shared agent for one distro, created on first use.
84
+ * The shared agent for one distro and transport: created on first use, and the
85
+ * same instance on every call after that — through deaths, revivals and a
86
+ * change of entry. Its own lifecycle is the recovery; a caller that finds it
87
+ * unavailable (`status().state === "dead"`) falls back for that call.
88
+ *
89
+ * The transport is part of the identity: a row pointed at a custom `wslPath`
90
+ * must not keep talking through the default executable, and a native entry
91
+ * staged through one transport cannot be assumed reachable through another.
23
92
  *
24
93
  * @param distro - the distro name.
94
+ * @param wslPath - the `wsl.exe` path the row configured.
25
95
  * @returns the shared agent.
26
96
  */
27
- export declare function sharedAgent(distro: string): WslAgent;
97
+ export declare function sharedAgent(distro: string, wslPath?: string): WslAgent;
98
+ /**
99
+ * Why the shared resident is not on the native entry though the backend asks
100
+ * for it, for a diagnosis: the entry is demoted, or it just failed a start.
101
+ * Undefined when neither is the case.
102
+ *
103
+ * @param distro - the distro name.
104
+ * @returns the reason, or undefined.
105
+ */
106
+ export declare function sharedAgentNativeNote(distro: string): string | undefined;
107
+ /**
108
+ * Forget every shared agent and every native verdict; tests only.
109
+ */
110
+ export declare function resetSharedAgents(): void;