dsh-plugin-wsl-env 0.26.1 → 0.26.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -16,6 +16,85 @@ were part of the record.
16
16
 
17
17
  ## [Unreleased]
18
18
 
19
+ ## [0.26.2] - 2026-11-17
20
+
21
+ One theme: a broken distro's failures surface as the program's own —
22
+ actionable exit codes and remedies instead of opaque provider errors — while
23
+ the doctor's quick pass spots the missing tools before the model does.
24
+
25
+ ### Fixed
26
+
27
+ - **A search in a distro without ripgrep reports rg's failure, not an opaque
28
+ provider error.** The file-search tool reads rg's exit dialect (`1` = no
29
+ matches, `2` = rg failed), but `search-exec.js` treated only
30
+ `AgentUnavailableError` as a cue: the native resident's `SpawnError` — a
31
+ missing `rg` on the PATH the agent inherits from `wsl.exe`, which never
32
+ holds `~/.local/bin` — rejected `done`, and the tool rendered
33
+ "subprocess failed before reporting an outcome (ripgrep provider failure)".
34
+ The handle now synthesizes the documented shape: exit 127 with a message
35
+ naming the program, the distro, the user-local-PATH cause, and the
36
+ `scripts/bootstrap.sh <distro> --install` remedy. A missing working
37
+ directory becomes rg's error code 2 with the relay-shaped `chdir(...)` line
38
+ — never `1`, which the tool reads as "no matches". The one-shot fallback
39
+ translates the relay's `execvpe(rg) failed: No such file or directory` the
40
+ same way, and pins `WSL_UTF8=1` so that line (and every other relay
41
+ diagnostic) arrives readable. A spawn failure deliberately does not retry
42
+ one-shot: `wsl.exe --cd` does not fail on a missing directory — it warns and
43
+ runs the command in `/` — so the retry could turn a wrong directory into a
44
+ successful empty search. Pinned by `test/search-exec.test.mjs`;
45
+ `docs/LIMITATIONS.md` and `docs/ARCHITECTURE.md` record the failure shapes
46
+ and the PATH fact.
47
+
48
+ - **A git snapshot on a distro without git reports git's failure instead of a
49
+ silently empty change review.** `git-exec.js` had the same only-
50
+ `AgentUnavailableError` cue: the native resident's `SpawnError` (a missing
51
+ system `git` on the agent's inherited PATH) rejected `done`, and the
52
+ one-shot fallback would have been worse — `wsl.exe --cd <missing>` runs git
53
+ in `/`, where "not a git repository" reads as "no changes". The handle now
54
+ settles a missing program as exit 127 with the bootstrap remedy, a missing
55
+ directory as git's own `fatal: cannot change to ...` at exit 128, and
56
+ post-processes the one-shot relay's `execvpe(git) failed` / `chdir(...)
57
+ failed` lines into the same shapes (that path now pins `WSL_UTF8=1`). The
58
+ relay parsers are shared from `wsl.ts` (`execProgramFailure` joins
59
+ `workdirFailure`); pinned by `test/git-exec.test.mjs` and
60
+ `test/shell.test.mjs`, with `docs/LIMITATIONS.md` and
61
+ `docs/ARCHITECTURE.md` recording the contract.
62
+
63
+ - **A discovery answer's UNC translation no longer depends on the transport.**
64
+ When the host has no Windows git, the snapshot's sentinel `rev-parse`
65
+ discovery call routes into the distro; with the resident out, the one-shot
66
+ fallback returned that call's Linux absolute paths untranslated, so
67
+ `workspace-changes` resolved them in the host's coordinate system instead of
68
+ `\\wsl.localhost\<distro>`. The fallback now passes the delegated stdout
69
+ through `translateDiscoveryOutput` exactly as the agent path does, carrying
70
+ the delegate's per-stream cut flags over. Pinned by
71
+ `test/git-exec.test.mjs`.
72
+
73
+ - **The directory picker can no longer create a directory in `/` while
74
+ reporting the requested target.** `createDirectory`'s one-shot fallback ran
75
+ a relative `mkdir -- <name>` under `--cd <parent>`; a parent that vanished
76
+ makes `wsl.exe` warn, run in `/`, and exit 0 — where a writable root (a
77
+ root-default image) turns that into a created `/name` reported as the UNC
78
+ target. The argv now names the absolute target on both transports
79
+ (`distroMkdirArgv`), and the picker maps the agent's `CwdError` /
80
+ `SpawnError` to `DirectoryPickerError` instead of leaking an opaque provider
81
+ error. Pinned by `test/listing.test.mjs`; the peer-bound row itself remains
82
+ probe-covered.
83
+
84
+ ### Changed
85
+
86
+ - **The doctor's quick pass now includes the optional-tool probe.**
87
+ `tools.rg`, `tools.git` and `tools.inotifywait` ran only in a full scan, so
88
+ a distro without ripgrep surfaced at the model's first `grep`/`glob` and not
89
+ in the sidebar's quick check. One combined in-distro probe (a single
90
+ `wsl.exe`, not three) now answers all three in the quick profile too; a
91
+ missing `rg` warns with the install remedy, and a probe that answers nothing
92
+ reports `info` instead of fabricating "missing". Pinned by
93
+ `test/doctor.test.mjs`; `docs/CONFIGURATION.md`, `docs/QUICKSTART.md` and
94
+ `docs/DIAGNOSTICS.md` describe the quick scope, and the READMEs' `glob`/
95
+ `grep` troubleshooting row names the failure (exit 127) alongside the
96
+ slowness.
97
+
19
98
  ## [0.26.1] - 2026-11-16
20
99
 
21
100
  One theme: the peer self-check now answers for the set the running plugin
package/README.md CHANGED
@@ -114,7 +114,7 @@ Without `bubblewrap`, confined commands report `SANDBOX_UNAVAILABLE` and do not
114
114
  |---|---|
115
115
  | every command reports `SANDBOX_UNAVAILABLE` | install `bubblewrap` in the distro, or set `sandbox: false` |
116
116
  | the session refuses before the first command | run `pnpm run doctor`; enable systemd and linger, or set `sessionSandbox` to `auto` or `false` on `wsl-shell` and `wsl-fs` |
117
- | `glob` and `grep` are slow in the distro | run `pnpm run bootstrap <distro>` and use its printed install command to install `ripgrep` |
117
+ | `glob` and `grep` are slow in the distro, or fail with exit 127 (no `rg`) | run `pnpm run bootstrap <distro>` and use its printed install command to install `ripgrep`; a user-local install under `~/.local/bin` is not on the PATH commands run with |
118
118
  | `npm install` / `pnpm add` fail with `EROFS` | the sandbox grants only the workspace by default; configure `writableRoots` on `wsl-shell` and `wsl-fs` (e.g. `~/.npm`, `~/.cache`, `~/.local/share/pnpm`); see [CONFIGURATION](docs/CONFIGURATION.md#toolchain-caches-and-extra-writable-roots) |
119
119
  | the Plugins page finishes without feedback | trust the profile's `package.json` and its `dsh.profile.bundles` entry: the plugin listed there is installed |
120
120
  | a profile patch for `wsl-shell`/`wsl-fs` changes nothing | those rows are nested inside `preset-wsl`. Run `pnpm run preset --check <patch>`; it fails with the complete block to paste |
@@ -131,7 +131,14 @@ launches into the distro — the file-search tool's packaged ripgrep and git
131
131
  snapshot commands (each agent-first on the warm resident — protocol v6 carries
132
132
  a git call's stdin, and a one-shot call costs ~230 ms of `wsl.exe` startup
133
133
  against the resident's ~2 ms — with the one-shot `wsl.exe --exec` handle as
134
- the fallback when the agent is out). When the HOST has no git,
134
+ the fallback when the agent is out). A distro without rg or git does not
135
+ degrade into a silent fallback: the search handle translates the resident's
136
+ spawn failure into exit 127 with the bootstrap remedy, and a missing working
137
+ directory into rg's error code 2 (`1` means "no matches" and is never reused);
138
+ the snapshot handle uses the same 127 shape for a missing git and git's own
139
+ `fatal: cannot change to ...` (exit 128) for a missing directory, so a
140
+ snapshot cannot read as "no changes". `lib/search-exec.js` and
141
+ `lib/git-exec.js` own those translations. When the HOST has no git,
135
142
  `resolveExecutable` answers git with a distro sentinel path, and the snapshot
136
143
  command's discovery call (`rev-parse --show-toplevel ...`) routes too, its
137
144
  absolute-path output translated back into UNC form — so full WSL change review
@@ -116,7 +116,13 @@ agent preset 在其隔离域中运行服务。preset registry 在自己的上下
116
116
  发行版内——文件搜索工具随包的 ripgrep 和 git 快照命令(两者都优先走已预热的
117
117
  常驻 agent——协议 v6 承载 git 调用的 stdin,而一次性调用要付出约 230 ms 的
118
118
  `wsl.exe` 启动开销,常驻 agent 只需约 2 ms——agent 不在时以一次性的
119
- `wsl.exe --exec` 句柄为回退)。宿主没有 git 时,`resolveExecutable` 对 git
119
+ `wsl.exe --exec` 句柄为回退)。没有 rg 或 git 的发行版不会退化为静默回退:
120
+ 搜索句柄把常驻 agent 的 spawn 失败翻译为退出码 127 并附 bootstrap 安装指引,
121
+ 工作目录缺失则翻译为 rg 的错误码 2(`1` 属于“无匹配”,不能占用);快照句柄
122
+ 对缺 git 用同一 127 形状,对缺失目录用 git 自身的
123
+ `fatal: cannot change to ...`(退出码 128)——不会让快照读成“无变更”。这两层
124
+ 翻译分别由 `lib/search-exec.js` 与 `lib/git-exec.js` 拥有。宿主没有 git 时,
125
+ `resolveExecutable` 对 git
120
126
  返回一个发行版哨兵路径,快照命令的发现调用(`rev-parse --show-toplevel ...`)
121
127
  也随之路由,其绝对路径输出再转换回 UNC 形式——因此没有 Windows git 也能完成
122
128
  完整的 WSL 变更审阅。两个 spawn 决策都是纯坐标函数(`lib/search-route.js`、
@@ -393,7 +393,8 @@ verdict as an itemized listing — every check with an explicit status marker,
393
393
  grouped by distro, the copy-paste remedy under every failure — the user just
394
394
  asks for a diagnosis. The tool is interactive by design: `depth: "quick"` (the
395
395
  default) runs the prerequisites only (~10 s in one distro: host facts, the
396
- session sandbox quartet, bubblewrap — no smokes, no registry query, no port
396
+ session sandbox quartet, bubblewrap, and one combined optional-tool probe —
397
+ rg/git/inotifywait — no smokes, no registry query, no port
397
398
  survey) and is the right first call; `section` narrows a follow-up to one area
398
399
  (`host`, `sandbox`, `session`, `conf`, `net`, `agent`); `depth: "full"` is
399
400
  the complete scan and answers for everything. The `/wsl-doctor` command (the
@@ -363,7 +363,8 @@ profile 不使用会话 runtime 时,设置 `sessionSandbox: false`。
363
363
  进程内调用 doctor,以逐项清单返回判定——每个检查带显式状态标记、按 distro
364
364
  分组、失败项下附可复制的修复——用户只要请求诊断即可。该工具按设计是交互式
365
365
  的:`depth: "quick"`(默认)只跑前置项(单 distro 约 10 秒:宿主事实、会话
366
- 沙箱四件套、bubblewrap——无冒烟、无 registry 查询、无端口勘察),是正确的
366
+ 沙箱四件套、bubblewrap,以及一次合并的可选工具探测——rg/git/inotifywait——
367
+ 无冒烟、无 registry 查询、无端口勘察),是正确的
367
368
  首次调用;`section` 把跟进收窄到一个区域(`host`、`sandbox`、`session`、
368
369
  `conf`、`net`、`agent`);`depth: "full"` 是完整扫描,对所有检查负责。
369
370
  `/wsl-doctor` 命令(`wsl-doctor-command` 行,部署具有命令注册表时注册)在
@@ -107,6 +107,11 @@ posts the full-run action (`--fix-owned`, labeled 修复 or 完整检查):
107
107
  never reports. This is the only surface that depends on the model path; use
108
108
  the command or the CLI when the plugin's runtime itself is under suspicion.
109
109
 
110
+ The quick profile carries the optional-tool probe (`tools.rg`, `tools.git`,
111
+ `tools.inotifywait`) in one combined spawn, so a missing `rg` is visible in
112
+ the panel before the model's first `grep`/`glob`; those ids live in the `host`
113
+ section, and the quick scope covers them.
114
+
110
115
  One check is surface-dependent by construction: `session.preset-seam` reports
111
116
  whether `auto-preset` could wrap the host's `agents.createSession` in this
112
117
  process. That is host-process state, so the standalone CLI cannot see it; the
@@ -85,6 +85,10 @@ doctor 通过三个入口给出同一份报告;侧边栏的 **WSL 环境** 面
85
85
  会杀掉它,而两分钟时限加上有界的管道排空窗口,能让子进程不再报告时也有
86
86
  结论。这是唯一依赖模型链路的入口;怀疑插件运行时本身时,用命令或 CLI。
87
87
 
88
+ quick 档在一次合并探测中带上可选工具(`tools.rg`、`tools.git`、
89
+ `tools.inotifywait`),因此缺少 `rg` 会在模型第一次 `grep`/`glob` 之前就出现在
90
+ 面板里;这些 id 属于 `host` 分区,也在 quick 档的覆盖范围内。
91
+
88
92
  `peers.versions` 也按入口而异,因为它问的是本进程实际加载的对等包版本。宿主
89
93
  运行时会把链接插件声明的 peer 投影到安装处的同一份副本上,所以同一份插件在
90
94
  应用内加载的是应用自带的版本,而独立 Node 进程解析到的可能完全不同。修复前,
@@ -43,7 +43,12 @@ operations never use the 9p share.
43
43
  required; a policy change pays one agent startup; a write granted to `/tmp` lands
44
44
  in the distro's real `/tmp`.
45
45
  - **`glob`/`grep` run the distro's rg**; a distro without rg fails the search
46
- (exit 127). Install: `wsl.exe -d <distro> -u root -- apt-get install -y bubblewrap
46
+ with exit 127, naming the program and the install remedy below — no silent
47
+ fallback, and not an opaque provider error; a missing working directory
48
+ fails explicitly too (rg's error code 2, because `1` means "no matches").
49
+ Commands and the resident agent both inherit `wsl.exe`'s default PATH, so a
50
+ user-local install under `~/.local/bin` is invisible — install it
51
+ system-wide, or somewhere on that PATH. Install: `wsl.exe -d <distro> -u root -- apt-get install -y bubblewrap
47
52
  git ripgrep inotify-tools` (or the detected family's spelling). `--install` runs it
48
53
  only for a missing `bubblewrap`.
49
54
  - **`watch()` is coarse invalidation, not per-file notifications**: inotify events
@@ -247,6 +252,13 @@ sandbox's security statement: `enforcement: partial` is untouched.
247
252
  app. Two alternatives: the doctor's `git.win-safe` probe reports the state, and a
248
253
  machine **without** Windows git needs nothing — the provider routes discovery into
249
254
  the distro and translates the output into UNC form.
255
+ - **A distro without a system git never disguises change review as "no
256
+ changes"**: a snapshot call fails with exit 127, naming git, the agent
257
+ PATH's user-local blind spot (`~/.local/bin` is invisible), and the
258
+ bootstrap remedy; a missing snapshot directory fails in git's own dialect —
259
+ `fatal: cannot change to ...` at exit 128 — instead of returning an empty
260
+ result. The one-shot fallback translates the same relay lines
261
+ (`execvpe(git) failed`, `chdir(...) failed`) the same way.
250
262
  - **A multi-directory `GIT_*` value is translated, not skipped — and a
251
263
  Windows-form list comes out wrong.** The translation applies the single-value
252
264
  translator to every `GIT_*` value unchecked, so a list folds onto the first
@@ -39,8 +39,12 @@ Windows 侧 share 后端(`substrate: "share"`)在启动时被拒绝;WSL
39
39
  工作区之外以 `FS_SANDBOX_DENIED` 拒绝。代价:需要 `bubblewrap`;
40
40
  策略变更要付出一次 agent 启动;授予 `/tmp` 的写入落在发行版真实的
41
41
  `/tmp` 中。
42
- - **`glob`/`grep` 使用发行版的 rg**;没有 rg 的发行版搜索失败
43
- (退出码 127)。安装:`wsl.exe -d <distro> -u root -- apt-get install -y bubblewrap
42
+ - **`glob`/`grep` 使用发行版的 rg**;没有 rg 的发行版搜索失败,
43
+ 以退出码 127 报出程序名与下面的安装指引——不会静默回退,也不是不可读的
44
+ provider 错误;工作目录缺失同样显式失败(rg 的错误码 2,`1` 只表示"无
45
+ 匹配")。命令与常驻 agent 都继承 `wsl.exe` 的默认 PATH,因此
46
+ `~/.local/bin` 下的用户级安装不可见——请装成系统级,或放在那个 PATH 上。
47
+ 安装:`wsl.exe -d <distro> -u root -- apt-get install -y bubblewrap
44
48
  git ripgrep inotify-tools`(或检测到的包管理族对应的写法)。`--install` 只在
45
49
  缺少 `bubblewrap` 时才执行安装。
46
50
  - **`watch()` 是粗粒度失效,不是逐文件通知**:inotify 事件合并到 0.5 s,
@@ -218,6 +222,12 @@ Windows git `safe.directory` 白名单)。`--fix-owned` 把运行收窄到插
218
222
  应用。两个替代方案:doctor 的 `git.win-safe` 探针可报告该状态;而
219
223
  **没有** Windows git 的机器什么都不用做——提供者把发现请求路由进
220
224
  发行版,并把输出转写成 UNC 形式。
225
+ - **没有系统级 git 的发行版不会把变更审阅伪装成“无变更”**:快照调用以退出码
226
+ 127 报出 git 无法启动、agent PATH 的成因(`~/.local/bin` 下的安装不可见)
227
+ 与 bootstrap 安装指引;快照目录缺失则用 git 自身的
228
+ `fatal: cannot change to ...`(退出码 128)失败,而不是静默返回空结果。
229
+ 一次性回退路径上的同类 relay 文本(`execvpe(git) failed`、`chdir(...) failed`)
230
+ 做同样的翻译。
221
231
  - **多目录 `GIT_*` 值会被转写而不是跳过——Windows 形态的列表会译坏。**
222
232
  git 环境转写对每个 `GIT_*` 值无条件套用单值翻译,列表被折叠进首个盘符的
223
233
  挂载点(`C:\a;D:\b` 变成 `/mnt/c/a;D:/b`);只有 POSIX 形态的冒号列表
@@ -55,7 +55,8 @@ confirmation); `--fix-owned` restricts a fix run to the plugin-owned state
55
55
  (the panel's repair action); `--bundle <path>` writes
56
56
  the diagnostic file a setup report attaches (`--redact` strips the paths
57
57
  from it). A run can be scoped — `--quick` probes the first-command
58
- prerequisites only (~10 s), `--sections <list>` (comma-separated) runs the
58
+ prerequisites plus one combined optional-tool probe (~10 s), `--sections
59
+ <list>` (comma-separated) runs the
59
60
  named sections — or widened with `--all` to every installed distro; the
60
61
  report itemizes every check with an explicit status marker, grouped by
61
62
  distro. The fixed skeleton renders in the host's language
@@ -47,7 +47,8 @@ agent 缓存,两者都会复检;以及确认后的 Windows git 信任)或
47
47
  插件自有状态(面板的“修复”动作);
48
48
  `--bundle <路径>` 写出可附加到问题报告的诊断文件(`--redact`
49
49
  将其中的路径脱敏)。运行可以收窄范围——`--quick` 只探首条命令的前置项
50
- (约 10 秒),`--sections <分区清单>`(逗号分隔)只运行指定分区——
50
+ 与一次合并的可选工具探测(约 10 秒),`--sections <分区清单>`(逗号分隔)
51
+ 只运行指定分区——
51
52
  或用 `--all` 扩展到每个已装发行版;报告按 distro 分组逐项列出每个检查,
52
53
  带显式状态标记。固定骨架按宿主语言渲染(`--locale <标签>` 或
53
54
  `DSH_WSL_DOCTOR_LOCALE` 可覆盖检测)。
package/docs/README.zh.md CHANGED
@@ -114,7 +114,7 @@ wsl preset(每会话)
114
114
  |---|---|
115
115
  | 每条命令都报 `SANDBOX_UNAVAILABLE` | 在发行版内安装 `bubblewrap`,或设置 `sandbox: false` |
116
116
  | 会话在第一条命令前就被拒绝 | 运行 `pnpm run doctor`;启用 systemd 和 linger,或把 `wsl-shell`、`wsl-fs` 上的 `sessionSandbox` 设为 `auto` 或 `false` |
117
- | 发行版内 `glob`、`grep` 很慢 | 运行 `pnpm run bootstrap <发行版>`,使用打印的安装命令安装 `ripgrep` |
117
+ | 发行版内 `glob`、`grep` 很慢,或以退出码 127 失败(没有 `rg`) | 运行 `pnpm run bootstrap <发行版>`,使用打印的安装命令安装 `ripgrep`;`~/.local/bin` 下的用户级安装不在命令使用的 PATH 上 |
118
118
  | `npm install` / `pnpm add` 报 `EROFS` | 沙箱默认只授予工作区;在 `wsl-shell` 和 `wsl-fs` 上配置 `writableRoots`(如 `~/.npm`、`~/.cache`、`~/.local/share/pnpm`),见 [CONFIGURATION](CONFIGURATION.zh.md#工具链缓存与额外可写目录) |
119
119
  | Plugins 页面装完没有任何日志 | 以 profile 的 `package.json` 与 `dsh.profile.bundles` 为准:列出插件即安装成功 |
120
120
  | 对 `wsl-shell`/`wsl-fs` 的 profile 补丁不生效 | 这些行嵌套在 `preset-wsl` 里。运行 `pnpm run preset --check <补丁>`;它会失败并输出需要粘贴的完整块 |
@@ -43,7 +43,7 @@ docs/ 各篇里的行为承诺登记成带编号的需求条目,并给每条
43
43
  | R7 | 模型可见的发行版事实与 WSLENV 政策:受管 `DSH_*` 前缀准入,`PATH` 刻意不转发 | README「Using it」「Recipes」 | ①②③:两个 Windows 路径变量带 `/p` 翻译、`PATH` 不转发的理由成文;传输环境钉死 essentials+`DSH_*`+过滤后 WSLENV;shell 解析失败则省略事实而非报假值(宁可缺报不误报) | `terminal.test.mjs`(`/p` 翻译)、`agent.test.mjs`(传输环境 WSLENV 钉死为受管项)、`provider.test.mjs`(探针失败重试、不钉占位符)、`shell-env.test.mjs`(假 `wsl.exe` 下挂载/清扫/resolve 双路径与 doctorFact/windowsToPosix) | 已闭合(原残差:`lib/shell-env.js` 无单测、覆盖率报告不含该模块):`test:coverage` 实测该模块 行 97.7%/分支 83.6%/函数 92.9%,逐模块地板(85/70/60)达标,`coverage-allowlist` 豁免已撤;未覆盖项仅为需在驻 agent 的端口扫描成功臂(探针层) |
44
44
  | R8 | 权限三档(read-only / workspace-write / danger-full-access)与提权提议流 | README「Sandbox」表;ARCHITECTURE「Error codes」 | ①②:三档行为逐档成表;模型可见两行前缀逐字给出;`FS_SANDBOX_DENIED` 可提权而 `FS_OUTSIDE_DISTRO` 不可,且区分理由明文(宽权限开不出另一个发行版) | `fs-decisions.test.mjs`、`provider.test.mjs`、`fsio-agent.test.mjs`(分类) | — |
45
45
  | R9 | bubblewrap 沙箱:与 Linux runner 同参数、fail-closed、`enforcement: partial` 诚实上报 | ARCHITECTURE「Sandbox」全节;SECURITY「Sandbox enforcement is `partial` by design」 | ①②③⑤⑥:选型依据(ACL 令牌触不到 WSL)、探针失败不缓存、interop 洞 + `maskWindowsDrive` 收窄及其自身极限(binfmt 按内容分发)、完全关闭唯一路径(`wsl.conf`)、`sandbox: false` 退出——行为到边界到逃生门完整成链 | `sandbox.test.mjs`、`probe-cache.test.mjs`;probe:sandbox、probe:sandbox-off | interop 使 enforcement 恒为 partial——已声明的设计边界 |
46
- | R10 | 文件搜索跑发行版自身的 rg,绝不跨 9p share | PARITY「Contract audit」第 2 条;LIMITATIONS「glob 和 grep」条 | ①②③:拦截点与参数逐字转发成文;缺 rg 浮出 exit 127 附 bootstrap 指引;grep 回退被拒绝且理由明文(不读 `.gitignore`,非 rg 替身) | `search-route.test.mjs`、`search-exec.test.mjs` | — |
46
+ | R10 | 文件搜索跑发行版自身的 rg,绝不跨 9p share | PARITY「Contract audit」第 2 条;LIMITATIONS「glob 和 grep」条 | ①②③:拦截点与参数逐字转发成文;缺 rg 浮出 exit 127 附 bootstrap 指引(常驻 agent 的 spawn 失败与一次性回退的 `execvpe` 失败都翻译为该形状);工作目录缺失用 rg 的错误码 2,不复用「无匹配」的 1;grep 回退被拒绝且理由明文(不读 `.gitignore`,非 rg 替身) | `search-route.test.mjs`、`search-exec.test.mjs` | — |
47
47
  | R11 | watch():inotify 优先(无界目录),轮询回退;粗粒度失效 | PARITY「Contract audit」第 1 条;LIMITATIONS watch 两条 | ①②③:契约向上追溯到宿主接缝(`changed()` 无载荷 → 粗粒度失效即可);inotify 递归且 0.5s 合并、文件/限深/无 inotify-tools 回退轮询;更旧 mtime 盲区只属轮询路径、`watchMaxDepth` 旋钮、目标消失响亮报错成文 | `watcher.test.mjs`;probe:watch(无 inotify 时 7/7;装 inotify-tools 后盲区检查改为期望事件) | 轮询回退的 mtime 盲区已声明;inotify 路径依赖发行版的 inotify-tools |
48
48
  | R12 | share 基座退役:携带 `substrate: "share"` 的 profile 在 boot 被拒并附迁移 | README/CONFIGURATION/LIMITATIONS 三处一致 | ①②⑤:旧值处置与用户所见成文,迁移指引内嵌 | `fs-decisions.test.mjs`(拒绝消息与迁移指引文案) | boot 期拒绝分支无测试(构造器调 `shareSubstrateRefusal`,`src/wsl-filesystem.ts:225`):`fs.boot.test.mjs` 只以 `sandbox: true` 启动该行,仓内没有构造 `substrate: "share"` profile 的测试 |
49
49
  | R13 | 会话级 systemd scope:命令共享后台进程/真实 `/tmp`/`ps`,scope 随会话结束停止;systemd + linger 缺失时预检带修复拒绝 | ADR 0001;README/CONFIGURATION/LIMITATIONS 的 `sessionSandbox` 条 | ①②③⑤:scope 生命周期(agent 为主进程、refcount、dispose stop)、`sessionSandbox: false` 退出与 `auto` 回退、systemd/linger/systemd-run 四项预检与缓存策略成文;`/tmp` 与后台进程的保真边界限定在 runtime 开时 | `session-scope.test.mjs`、`session-runtime.test.mjs`、`provider.test.mjs`;真机会话验证(active scope、跨命令后台/`/tmp`、会话结束 0 units) | 硬崩溃可能留下 stale scope(启动清扫未随发,入 LIMITATIONS);受限写入已共享 runtime,读仍走无约束共享 agent,根级 fs-routing 不持有 session runtime |
package/lib/git-exec.d.ts CHANGED
@@ -25,14 +25,46 @@
25
25
  * The agent being out is the fallback cue, exactly as `search-exec.ts`:
26
26
  * `spawnFallback` (the caller's one-shot `wsl.exe` handle) is consulted
27
27
  * lazily inside `done`, and from that point the facade proxies the delegate
28
- * verbatim. Cancellation shares one channel: the caller's `signal` and
29
- * `kill()` abort the agent exec, settling `done` as killed.
28
+ * verbatim unless its relay named a broken program or directory. Cancellation
29
+ * shares one channel: the caller's `signal` and `kill()` abort the agent
30
+ * exec, settling `done` as killed.
31
+ *
32
+ * ## Failure surfacing: a broken distro must not look like "no changes"
33
+ *
34
+ * `GitRunner` reads git's own exit codes and stderr; a rejection from
35
+ * `handle.done` is an opaque snapshot failure the model cannot act on. The
36
+ * agent's two local failures therefore become git's own dialect instead:
37
+ *
38
+ * - A `SpawnError` means the agent could not start the program. The native
39
+ * agent reports both a missing executable and a missing working directory
40
+ * that way, without naming either — so the synthesized message names both
41
+ * and the install remedy, at exit 127 (a shell's command-not-found; never
42
+ * `1`, which several git subcommands use for a normal negative answer, nor
43
+ * `128`, which `GitRunner` reads as "not a repository").
44
+ * - A `CwdError` names the directory that could not be entered. It becomes
45
+ * git's fatal class — `fatal: cannot change to '<path>': No such file or
46
+ * directory` at exit 128 — which is exactly what `git -C <missing>` itself
47
+ * prints.
48
+ *
49
+ * Neither failure falls back to the one-shot path. A missing program would
50
+ * only produce the relay's `execvpe(git) failed` at exit `1`, and a missing
51
+ * directory is worse: `wsl.exe --cd` does not fail on it — it warns, runs in
52
+ * `/`, and exits 0 — where `git` then answers "not a git repository", which
53
+ * the snapshot reads as a clean, empty result. The one-shot delegate is
54
+ * post-processed for both relay markers, so the agent being out cannot turn a
55
+ * broken environment into a silent "no changes" either. Other failures still
56
+ * propagate through `done` as rejections.
57
+ *
58
+ * A discovery call's absolute-path answer is translated on BOTH transports:
59
+ * the one-shot delegate's stdout is taken over and passed through
60
+ * `translateDiscoveryOutput` exactly as the agent's result is, so change
61
+ * review sees the same UNC paths whether or not the resident is up.
30
62
  *
31
63
  * Pure shaping over injected collaborators, unit-testable without a distro.
32
64
  *
33
65
  * This is a TypeScript source built to `lib/git-exec.js`; edit THIS file and
34
- * run `pnpm run build` — the artifact under `lib/` is generated, and
35
- * `pnpm test` fails when it drifts.
66
+ * run `pnpm run build` — the artifact under `lib/` is generated, and `pnpm test`
67
+ * fails when it drifts.
36
68
  *
37
69
  * @module dsh-plugin-wsl-env/git-exec
38
70
  */
@@ -86,10 +118,10 @@ export declare function gitExecutionHandle({ agent, cwd, argv, env, stdin, caps,
86
118
  /** The distro-side argv (`git` and its arguments). */
87
119
  argv: string[];
88
120
  /**
89
- * The distro name; required when `discovery` is set (absolute path lines
90
- * become `\\wsl.localhost\<distro><path>`).
121
+ * The distro name; used by the discovery translation (absolute path lines
122
+ * become `\\wsl.localhost\<distro><path>`) and by every failure's remedy.
91
123
  */
92
- distro?: string;
124
+ distro: string;
93
125
  /**
94
126
  * True for a SENTINEL discovery call (`--show-toplevel` /
95
127
  * `--absolute-git-dir` / `--git-path` answered by the distro git): the
package/lib/git-exec.js CHANGED
@@ -25,19 +25,71 @@
25
25
  * The agent being out is the fallback cue, exactly as `search-exec.ts`:
26
26
  * `spawnFallback` (the caller's one-shot `wsl.exe` handle) is consulted
27
27
  * lazily inside `done`, and from that point the facade proxies the delegate
28
- * verbatim. Cancellation shares one channel: the caller's `signal` and
29
- * `kill()` abort the agent exec, settling `done` as killed.
28
+ * verbatim unless its relay named a broken program or directory. Cancellation
29
+ * shares one channel: the caller's `signal` and `kill()` abort the agent
30
+ * exec, settling `done` as killed.
31
+ *
32
+ * ## Failure surfacing: a broken distro must not look like "no changes"
33
+ *
34
+ * `GitRunner` reads git's own exit codes and stderr; a rejection from
35
+ * `handle.done` is an opaque snapshot failure the model cannot act on. The
36
+ * agent's two local failures therefore become git's own dialect instead:
37
+ *
38
+ * - A `SpawnError` means the agent could not start the program. The native
39
+ * agent reports both a missing executable and a missing working directory
40
+ * that way, without naming either — so the synthesized message names both
41
+ * and the install remedy, at exit 127 (a shell's command-not-found; never
42
+ * `1`, which several git subcommands use for a normal negative answer, nor
43
+ * `128`, which `GitRunner` reads as "not a repository").
44
+ * - A `CwdError` names the directory that could not be entered. It becomes
45
+ * git's fatal class — `fatal: cannot change to '<path>': No such file or
46
+ * directory` at exit 128 — which is exactly what `git -C <missing>` itself
47
+ * prints.
48
+ *
49
+ * Neither failure falls back to the one-shot path. A missing program would
50
+ * only produce the relay's `execvpe(git) failed` at exit `1`, and a missing
51
+ * directory is worse: `wsl.exe --cd` does not fail on it — it warns, runs in
52
+ * `/`, and exits 0 — where `git` then answers "not a git repository", which
53
+ * the snapshot reads as a clean, empty result. The one-shot delegate is
54
+ * post-processed for both relay markers, so the agent being out cannot turn a
55
+ * broken environment into a silent "no changes" either. Other failures still
56
+ * propagate through `done` as rejections.
57
+ *
58
+ * A discovery call's absolute-path answer is translated on BOTH transports:
59
+ * the one-shot delegate's stdout is taken over and passed through
60
+ * `translateDiscoveryOutput` exactly as the agent's result is, so change
61
+ * review sees the same UNC paths whether or not the resident is up.
30
62
  *
31
63
  * Pure shaping over injected collaborators, unit-testable without a distro.
32
64
  *
33
65
  * This is a TypeScript source built to `lib/git-exec.js`; edit THIS file and
34
- * run `pnpm run build` — the artifact under `lib/` is generated, and
35
- * `pnpm test` fails when it drifts.
66
+ * run `pnpm run build` — the artifact under `lib/` is generated, and `pnpm test`
67
+ * fails when it drifts.
36
68
  *
37
69
  * @module dsh-plugin-wsl-env/git-exec
38
70
  */
39
- import { AgentUnavailableError } from "./agent-errors.js";
71
+ import { AgentUnavailableError, CwdError, SpawnError } from "./agent-errors.js";
72
+ import { t } from "./messages.js";
40
73
  import { translateDiscoveryOutput } from "./git-route.js";
74
+ import { execProgramFailure, workdirFailure } from "./wsl.js";
75
+ /** The exit code a shell reports for a command it could not run. */
76
+ const COMMAND_NOT_FOUND_EXIT = 127;
77
+ /**
78
+ * git's fatal-error exit code. A directory that cannot be entered is what
79
+ * `git -C <missing>` itself reports this way, so the synthesized line speaks
80
+ * git's own dialect rather than inventing a code.
81
+ */
82
+ const GIT_FATAL_EXIT = 128;
83
+ /**
84
+ * The stderr one snapshot settles with when its working directory is gone:
85
+ * git's own fatal line, then the directory's remedy.
86
+ *
87
+ * @param linuxPath - the directory the agent could not enter.
88
+ * @returns the stderr text.
89
+ */
90
+ function workdirFailureText(linuxPath) {
91
+ return `fatal: cannot change to '${linuxPath}': No such file or directory\n${t("gitWorkdirMissing", { path: linuxPath })}`;
92
+ }
41
93
  /**
42
94
  * Run one git command through the agent and present it as a git-snapshot
43
95
  * handle.
@@ -46,7 +98,7 @@ import { translateDiscoveryOutput } from "./git-route.js";
46
98
  * @returns the snapshot handle (`done`, `collected`, `kill`).
47
99
  */
48
100
  export function gitExecutionHandle({ agent, cwd, argv, env, stdin, caps, distro, discovery, signal, spawnFallback }) {
49
- const state = { delegate: undefined, stdout: undefined, stderr: undefined };
101
+ const state = { delegate: undefined, stdout: undefined, stderr: undefined, lossy: { stdout: false, stderr: false } };
50
102
  const controller = new AbortController();
51
103
  if (signal?.aborted)
52
104
  controller.abort(signal.reason);
@@ -61,13 +113,86 @@ export function gitExecutionHandle({ agent, cwd, argv, env, stdin, caps, distro,
61
113
  return {
62
114
  readFrom(from) {
63
115
  const buffer = state[slot] ?? Buffer.alloc(0);
64
- const lossy = buffer.length > cap;
116
+ const lossy = state.lossy[slot] || buffer.length > cap;
65
117
  const visible = lossy ? buffer.subarray(0, cap) : buffer;
66
118
  const start = Math.min(from, visible.length);
67
119
  return { text: visible.subarray(start).toString("utf8"), lossy, nextOffset: visible.length };
68
120
  },
69
121
  };
70
122
  };
123
+ /**
124
+ * Settle on a synthesized failure: drop any delegate so `collected` serves
125
+ * the buffers this facade owns.
126
+ *
127
+ * @param exitCode - git's dialect exit code for the failure.
128
+ * @param stderr - the model-facing diagnostic, remedy included.
129
+ * @returns the settled outcome.
130
+ */
131
+ const settleFailure = (exitCode, stderr) => {
132
+ state.delegate = undefined;
133
+ state.stdout = Buffer.alloc(0);
134
+ state.stderr = Buffer.from(stderr, "utf8");
135
+ state.lossy = { stdout: false, stderr: false };
136
+ return { exitCode, signal: null };
137
+ };
138
+ /**
139
+ * The 127 result for a program the distro could not start.
140
+ *
141
+ * @param detail - the agent's or the relay's own spawn diagnostic.
142
+ * @returns the settled outcome.
143
+ */
144
+ const settleProgramMissing = (detail) => settleFailure(COMMAND_NOT_FOUND_EXIT, t("gitProgramMissing", { distro, detail }));
145
+ /**
146
+ * The fatal result for a directory the distro could not enter.
147
+ *
148
+ * @param linuxPath - the directory that could not be entered.
149
+ * @returns the settled outcome.
150
+ */
151
+ const settleWorkdirMissing = (linuxPath) => settleFailure(GIT_FATAL_EXIT, workdirFailureText(linuxPath));
152
+ /**
153
+ * Take the delegated discovery call's streams over so their stdout gets the
154
+ * SAME UNC translation the agent path applies. The one-shot transport runs
155
+ * the same distro git, so an untranslated answer would hand the caller
156
+ * Linux absolute paths that only resolve correctly on the agent transport —
157
+ * a transport-dependent change review. The delegate's per-stream cut flags
158
+ * are carried into this facade's readers rather than flattened.
159
+ *
160
+ * @param delegate - the settled one-shot handle.
161
+ */
162
+ const takeOverDiscoveryOutput = (delegate) => {
163
+ const stdout = delegate.collected.stdout?.readFrom(0);
164
+ const stderr = delegate.collected.stderr?.readFrom(0);
165
+ state.delegate = undefined;
166
+ state.stdout = translateDiscoveryOutput(distro, Buffer.from(stdout?.text ?? "", "utf8"));
167
+ state.stderr = Buffer.from(stderr?.text ?? "", "utf8");
168
+ state.lossy = { stdout: stdout?.lossy === true, stderr: stderr?.lossy === true };
169
+ };
170
+ /**
171
+ * Delegate one agent-unavailable request to the one-shot handle, translating
172
+ * the relay's missing-directory warning and missing-program line into the
173
+ * same explicit failures the agent path produces. Any other delegated
174
+ * outcome passes through verbatim (its collected streams stay the
175
+ * delegate's).
176
+ *
177
+ * @returns the settled outcome.
178
+ */
179
+ const settleDelegate = async () => {
180
+ const delegate = spawnFallback();
181
+ state.delegate = delegate;
182
+ const outcome = await delegate.done;
183
+ if (outcome.exitCode === null)
184
+ return outcome;
185
+ const text = delegate.collected.stderr?.readFrom(0).text ?? "";
186
+ const missingDir = workdirFailure("", text);
187
+ if (missingDir !== undefined)
188
+ return settleWorkdirMissing(missingDir);
189
+ const relayFailure = execProgramFailure("", text);
190
+ if (relayFailure !== undefined)
191
+ return settleProgramMissing(relayFailure);
192
+ if (discovery)
193
+ takeOverDiscoveryOutput(delegate);
194
+ return outcome;
195
+ };
71
196
  const handle = {
72
197
  get collected() {
73
198
  if (state.delegate !== undefined)
@@ -78,21 +203,29 @@ export function gitExecutionHandle({ agent, cwd, argv, env, stdin, caps, distro,
78
203
  let result;
79
204
  try {
80
205
  result = await agent.exec({ cwd, argv, env, stdin, maxOutputBytes: wireCap, signal: controller.signal });
81
- state.stdout = discovery ? translateDiscoveryOutput(distro ?? "", result.stdout) : result.stdout;
206
+ state.stdout = discovery ? translateDiscoveryOutput(distro, result.stdout) : result.stdout;
82
207
  state.stderr = result.stderr;
83
208
  }
84
209
  catch (error) {
85
- if (!(error instanceof AgentUnavailableError)) {
86
- if (controller.signal.aborted) {
87
- // Our kill() or the caller's cancellation: the killed outcome the
88
- // one-shot path reports, not a failure.
89
- return { exitCode: null, signal: "SIGTERM" };
90
- }
91
- throw error;
210
+ if (controller.signal.aborted) {
211
+ // Our kill() or the caller's cancellation: the killed outcome the
212
+ // one-shot path reports, not a failure.
213
+ return { exitCode: null, signal: "SIGTERM" };
214
+ }
215
+ if (error instanceof CwdError) {
216
+ // The directory is gone: git's own fatal dialect, so the snapshot
217
+ // reports the path instead of rejecting as a provider failure.
218
+ return settleWorkdirMissing(error.linuxPath);
92
219
  }
93
- const delegate = spawnFallback();
94
- state.delegate = delegate;
95
- return delegate.done;
220
+ if (error instanceof SpawnError) {
221
+ // The agent could not start the program. The native agent reports
222
+ // both a missing executable and a missing workdir this way, so the
223
+ // message names both and the remedy makes it actionable.
224
+ return settleProgramMissing(error.message);
225
+ }
226
+ if (!(error instanceof AgentUnavailableError))
227
+ throw error;
228
+ return await settleDelegate();
96
229
  }
97
230
  return { exitCode: result.exitCode, signal: null };
98
231
  })(),
package/lib/listing.d.ts CHANGED
@@ -111,6 +111,23 @@ export declare function boundedInsert<T extends {
111
111
  * @returns the argv for the agent or a `wsl.exe --exec` launch.
112
112
  */
113
113
  export declare function dirListingArgv(linuxDir: string): string[];
114
+ /**
115
+ * The distro-side argv one picker directory is created with.
116
+ *
117
+ * The target is named in ABSOLUTE form even though the agent path also sets a
118
+ * working directory: `wsl.exe --cd <missing>` does not fail — it warns, runs
119
+ * the command in `/` and exits 0 — so a relative `mkdir -- <name>` on the
120
+ * one-shot fallback would create `/name` while the picker reports the UNC
121
+ * target as created (when the distro user can write `/`, e.g. a root-default
122
+ * image). The absolute path makes the target independent of the directory the
123
+ * transport actually entered; the agent path keeps the same argv, and its
124
+ * `cwd` still supplies the existence check.
125
+ *
126
+ * @param linuxParent - the absolute Linux parent directory.
127
+ * @param name - the validated single path segment to create.
128
+ * @returns the argv for the agent or a `wsl.exe --exec` launch.
129
+ */
130
+ export declare function distroMkdirArgv(linuxParent: string, name: string): string[];
114
131
  /**
115
132
  * Parse one `find -print0` listing into the picker's rows.
116
133
  *
package/lib/listing.js CHANGED
@@ -148,6 +148,26 @@ export function boundedInsert(window, candidate, keep) {
148
148
  export function dirListingArgv(linuxDir) {
149
149
  return ["find", "-L", linuxDir, "-maxdepth", "1", "-mindepth", "1", "-type", "d", "-print0"];
150
150
  }
151
+ /**
152
+ * The distro-side argv one picker directory is created with.
153
+ *
154
+ * The target is named in ABSOLUTE form even though the agent path also sets a
155
+ * working directory: `wsl.exe --cd <missing>` does not fail — it warns, runs
156
+ * the command in `/` and exits 0 — so a relative `mkdir -- <name>` on the
157
+ * one-shot fallback would create `/name` while the picker reports the UNC
158
+ * target as created (when the distro user can write `/`, e.g. a root-default
159
+ * image). The absolute path makes the target independent of the directory the
160
+ * transport actually entered; the agent path keeps the same argv, and its
161
+ * `cwd` still supplies the existence check.
162
+ *
163
+ * @param linuxParent - the absolute Linux parent directory.
164
+ * @param name - the validated single path segment to create.
165
+ * @returns the argv for the agent or a `wsl.exe --exec` launch.
166
+ */
167
+ export function distroMkdirArgv(linuxParent, name) {
168
+ const base = linuxParent.endsWith("/") ? linuxParent : `${linuxParent}/`;
169
+ return ["mkdir", "--", `${base}${name}`];
170
+ }
151
171
  /**
152
172
  * Parse one `find -print0` listing into the picker's rows.
153
173
  *