dsh-plugin-wsl-env 0.24.0 → 0.25.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 +52 -0
- package/README.md +6 -3
- package/SECURITY.md +10 -0
- package/cordis.patch.yml +4 -0
- package/docs/ARCHITECTURE.md +28 -9
- package/docs/CONFIGURATION.md +43 -0
- package/docs/CONFIGURATION.zh.md +36 -0
- package/docs/DIAGNOSTICS.md +4 -2
- package/docs/DIAGNOSTICS.zh.md +3 -1
- package/docs/LIMITATIONS.md +17 -4
- package/docs/LIMITATIONS.zh.md +11 -3
- package/docs/MIGRATION.md +1 -1
- package/docs/PEER-PARITY.md +4 -4
- package/docs/QUICKSTART.md +12 -5
- package/docs/QUICKSTART.zh.md +8 -2
- package/docs/README.zh.md +6 -3
- package/docs/RELEASING.md +17 -13
- package/docs/REQUIREMENTS.zh.md +3 -2
- package/docs/UPSTREAM-FSIO-EXPORT.md +5 -4
- package/docs/UPSTREAM-PROMPT-ADAPTERS.md +85 -0
- package/docs/root-fs-routing.md +1 -1
- package/lib/agent-confined.d.ts +7 -1
- package/lib/agent-confined.js +3 -3
- package/lib/bwrap.d.ts +14 -0
- package/lib/bwrap.js +11 -0
- package/lib/cwd-prompt.d.ts +41 -3
- package/lib/cwd-prompt.js +125 -8
- package/lib/doctor-report.d.ts +50 -0
- package/lib/doctor-report.js +172 -0
- package/lib/fs-routing.d.ts +1 -1
- package/lib/fs-routing.js +1 -1
- package/lib/fs.d.ts +1 -1
- package/lib/fs.js +1 -1
- package/lib/index.d.ts +6 -1464
- package/lib/index.js +5 -2120
- package/lib/messages.d.ts +1 -1
- package/lib/messages.js +3 -3
- package/lib/preflight.d.ts +7 -4
- package/lib/preflight.js +27 -13
- package/lib/provider-common.d.ts +58 -0
- package/lib/provider-common.js +123 -0
- package/lib/sandbox-core.d.ts +1 -0
- package/lib/sandbox-core.js +4 -2
- package/lib/session-runtime.d.ts +7 -1
- package/lib/session-runtime.js +9 -2
- package/lib/shell.d.ts +1 -1
- package/lib/shell.js +1 -1
- package/lib/writable-roots.d.ts +109 -0
- package/lib/writable-roots.js +257 -0
- package/lib/wsl-doctor-tool.js +2 -2
- package/lib/wsl-filesystem.d.ts +692 -0
- package/lib/wsl-filesystem.js +897 -0
- package/lib/wsl-shell.d.ts +742 -0
- package/lib/wsl-shell.js +965 -0
- package/lib/wsl.d.ts +1 -1
- package/lib/wsl.js +1 -1
- package/package.json +4 -3
- package/scripts/doctor.mjs +1 -1
- package/scripts/profile-preset.mjs +17 -5
package/docs/README.zh.md
CHANGED
|
@@ -47,7 +47,7 @@ Windows 上的编程工具要在 WSL 项目中工作,有三条路:把整个
|
|
|
47
47
|
- **发行版内没有服务。** 没有辅助服务、没有守护进程、没有监听端口。唯一持久化的内容是 `~/.cache/dsh-wsl/agent/` 下按内容寻址的原生 agent 副本。
|
|
48
48
|
- **默认有沙箱。** 受限命令在发行版内的 `bubblewrap` 中运行。缺少 `bubblewrap` 时命令直接失败,不会脱箱运行。
|
|
49
49
|
- **按会话生效。** 打开发行版文件夹的会话获得发行版环境;打开 Windows 文件夹的会话保留 Windows 工具。两者可同时运行在一个 harness 进程中。
|
|
50
|
-
- **与 GUI 集成。** 文件夹选择器列出已安装的发行版,终端在发行版内打开 shell,模型能看到监听端口。侧边栏的 **WSL 环境** 面板按发行版运行 doctor
|
|
50
|
+
- **与 GUI 集成。** 文件夹选择器列出已安装的发行版,终端在发行版内打开 shell,模型能看到监听端口。侧边栏的 **WSL 环境** 面板按发行版运行 doctor 快速检查——宿主侧执行,不进模型对话;会话启动预检在每次会话打开时把环境判定写进日志,只有 blocked 判定同时进入会话上下文。
|
|
51
51
|
|
|
52
52
|
### 为什么是 Linux,而不是 PowerShell
|
|
53
53
|
|
|
@@ -111,7 +111,7 @@ dsh --profile wsl # 启动
|
|
|
111
111
|
wsl.exe -d <发行版> -u root -- apt-get install -y bubblewrap
|
|
112
112
|
```
|
|
113
113
|
|
|
114
|
-
在插件检出目录中,`pnpm run doctor` 是一键环境体检:Windows/WSL 平台、每个发行版的 WSL 模式与身份、`.wslconfig` 与 `/etc/wsl.conf` 交叉核对、发行版与宿主卷、时钟与 DNS、bubblewrap 可用性、systemd / user manager / Linger、可选工具、peer 版本、native agent 与其缓存、新 agent 握手、证明链路完好的 shell 冒烟腿(帧 I/O、受限围栏、批量 substrate)与一条 native HELLO 腿、残留会话 scope、已知的 profile 补丁与废弃键陷阱。报告逐项列出每个检查——按 distro 分组,每项带显式状态标记,失败项下附可复制的处理办法——并以裁决收尾:`ready
|
|
114
|
+
在插件检出目录中,`pnpm run doctor` 是一键环境体检:Windows/WSL 平台、每个发行版的 WSL 模式与身份、`.wslconfig` 与 `/etc/wsl.conf` 交叉核对、发行版与宿主卷、时钟与 DNS、bubblewrap 可用性、systemd / user manager / Linger、可选工具、peer 版本、native agent 与其缓存、新 agent 握手、证明链路完好的 shell 冒烟腿(帧 I/O、受限围栏、批量 substrate)与一条 native HELLO 腿、残留会话 scope、已知的 profile 补丁与废弃键陷阱。报告逐项列出每个检查——按 distro 分组,每项带显式状态标记,失败项下附可复制的处理办法——并以裁决收尾:`ready`(本次运行覆盖的检查全部通过,不保证每条命令都成功)或 `blocked`(列明待修项),按生效配置计算。运行可以收窄范围:`--quick` 只探首条命令的前置项(约 10 秒),`--sections <分区清单>`(逗号分隔)只运行指定分区,且范围化报告会把未运行的检查显式列为跳过项。`--json` 供脚本使用;`--fix` 会复核它修过的项——插件自有的残留 scope 清扫与 agent 缓存清理是安全自动的,安装包需要 `--fix --install` 并显式确认,`--fix-owned` 只运行插件自有的这两类(即侧边栏面板的“修复”动作)——`--all` 检查每个已装发行版,`--bundle <路径>` 写出可附加到问题报告的诊断文件(`--redact` 将路径脱敏)。固定骨架按宿主语言渲染——从 Windows 区域设置检测,可用 `--locale <标签>` 或 `DSH_WSL_DOCTOR_LOCALE` 覆盖;`--json` 保持语言无关。同一份报告经三个入口给出:本 CLI、`/wsl-doctor` 命令(在输入框输入——宿主侧执行,不进模型对话)、以及 `wsl_doctor` 模型工具(进程内采集,合并常驻 agent 的实时状态)。`DSH_WSL_DOCTOR` 还携带一条现成命令(`sh -c "$DSH_WSL_DOCTOR --json"`),可在发行版内直接重放 doctor。`pnpm run diagnose` 是 CLI 的只读别名。`pnpm run bootstrap <发行版>` 仍是较窄的工具安装助手。
|
|
115
115
|
|
|
116
116
|
插件大约每天自行检查一次更新(启动后 2–10 分钟内首查),方式是询问应用的插件管理器——它从不自行联网。当存在更新的稳定版时,每个发行版会话中受管的 `DSH_WSL_PLUGIN_UPDATE` 变量会携带该事实;补丁配置里的 `wsl-update-check.enabled: false` 可关闭该检查。升级保持手动,因为 harness 没有热重载:重新安装(Plugins 页面或 `add` 命令),然后重启。
|
|
117
117
|
|
|
@@ -139,11 +139,13 @@ wsl.exe -d <发行版> -u root -- apt-get install -y bubblewrap
|
|
|
139
139
|
| | `sessionSandbox` | `false`;随包 `true` | 会话命令跑在同一个 systemd user scope 中 |
|
|
140
140
|
| | `agentBackend` | `auto` | 发行版内 agent:`auto`、`native` 或 `shell` |
|
|
141
141
|
| | `maskWindowsDrive` | `false` | 让受限命令看不到 `/mnt` |
|
|
142
|
+
| | `writableRoots` | `[]` | 额外可写的发行版目录(工具链缓存等;`wsl-fs` 上配同一列表) |
|
|
142
143
|
| `wsl-fs` | `distro` | `''` | 发行版模式;空/`auto` 跟随每个目标路径 |
|
|
143
144
|
| | `restrictToDistro` | `true` | 固定发行版(`default` 或名字)时拒绝属于其他发行版的路径 |
|
|
144
145
|
| | `sandbox` | `true` | 按策略检查受限写入 |
|
|
145
146
|
| | `sessionSandbox` | `false`;随包 `true` | 受限写入跑在会话 runtime 中 |
|
|
146
147
|
| | `substrate` | `agent` | 发行版内 agent;`share` 在启动时被拒绝 |
|
|
148
|
+
| | `writableRoots` | `[]` | 与 `wsl-shell` 相同的额外可写目录列表 |
|
|
147
149
|
| `directory-picker-wsl` | `includeHostHome` | `true` | 同时提供 Windows 路径分支(从驱动器开始) |
|
|
148
150
|
| `subprocess-wsl` | `distro` | `''` | 发行版模式;空/`auto` 跟随启动目录 |
|
|
149
151
|
| `wsl-preflight` | `distro` | `''` | 环境检查探测的发行版;空/`auto` 跟随会话工作区 |
|
|
@@ -176,7 +178,7 @@ wsl preset(每个会话)
|
|
|
176
178
|
| 模式 | 命令可以做什么 |
|
|
177
179
|
|---|---|
|
|
178
180
|
| `read-only` | 读整个发行版;挂载新的 `/dev`,其余不可写 |
|
|
179
|
-
| `workspace-write` |
|
|
181
|
+
| `workspace-write` | 上面的权限,加上会话工作区与配置的 `writableRoots`;会话 runtime 下 `/tmp` 是发行版真实 `/tmp` |
|
|
180
182
|
| `danger-full-access` | 不经过沙箱 |
|
|
181
183
|
|
|
182
184
|
设置 `sessionSandbox: false` 时,`workspace-write` 命令使用私有的 `/tmp`,而不是发行版的真实 `/tmp`;`read-only` 不挂载可写的 `/tmp`。
|
|
@@ -192,6 +194,7 @@ wsl preset(每个会话)
|
|
|
192
194
|
| 每条命令都报 `SANDBOX_UNAVAILABLE` | 在发行版内安装 `bubblewrap`,或设置 `sandbox: false` |
|
|
193
195
|
| 会话在第一条命令前就被拒绝 | 运行 `pnpm run doctor`;启用 systemd 和 linger,或把 `wsl-shell`、`wsl-fs` 上的 `sessionSandbox` 设为 `auto` 或 `false` |
|
|
194
196
|
| 发行版内 `glob`、`grep` 很慢 | 运行 `pnpm run bootstrap <发行版>`,使用打印的安装命令安装 `ripgrep` |
|
|
197
|
+
| `npm install` / `pnpm add` 报 `EROFS` | 沙箱默认只授予工作区;在 `wsl-shell` 和 `wsl-fs` 上配置 `writableRoots`(如 `~/.npm`、`~/.cache`、`~/.local/share/pnpm`),见 [CONFIGURATION](CONFIGURATION.zh.md#工具链缓存与额外可写目录) |
|
|
195
198
|
| `dsh plugin add` 没有输出,或 Plugins 页面装完没有日志 | 以 profile 的 `package.json` 与 `dsh.profile.bundles` 为准:列出插件即安装成功 |
|
|
196
199
|
| 对 `wsl-shell`/`wsl-fs` 的 profile 补丁不生效 | 这些行嵌套在 `preset-wsl` 里。运行 `pnpm run preset --check <补丁>`;它会失败并输出需要粘贴的完整块 |
|
|
197
200
|
| 改了 `lib/` 但不生效 | 运行 `pnpm run sync:windows`,然后重启应用 |
|
package/docs/RELEASING.md
CHANGED
|
@@ -43,14 +43,14 @@ build step at pack time.
|
|
|
43
43
|
The coverage thresholds are 85 lines / 84 branches / 70 functions. The
|
|
44
44
|
branch threshold is one point under the others deliberately: the
|
|
45
45
|
integration layer is now measured, and part of what it leaves uncovered
|
|
46
|
-
needs a live `wsl.exe` — the distro-bound paths in `lib/
|
|
47
|
-
resolved home, the distro home, arming the watcher), the `wsl.exe` calls
|
|
46
|
+
needs a live `wsl.exe` — the distro-bound paths in `lib/wsl-filesystem.js` and
|
|
47
|
+
`lib/wsl-shell.js` (the resolved home, the distro home, arming the watcher), the `wsl.exe` calls
|
|
48
48
|
in `lib/wsl.js` (`defaultDistro`'s no-distro throw, `linuxHomePath`,
|
|
49
49
|
and the other distro calls), and the real spawn internals
|
|
50
50
|
in `lib/watcher.js`. The real-machine probes cover that tail, not CI.
|
|
51
51
|
The rest of the uncovered branches — the host-path arm of
|
|
52
|
-
`wslWritableRoots`, the sandbox-error and rethrow
|
|
53
|
-
unrestricted-path result
|
|
52
|
+
`wslWritableRoots` in `lib/provider-common.js`, the sandbox-error and rethrow
|
|
53
|
+
arms, and the unrestricted-path result in `lib/wsl-filesystem.js` — are ordinary
|
|
54
54
|
CI-coverable code. Do not raise the branch number without either covering
|
|
55
55
|
the `wsl.exe` tail on the Windows CI legs or moving the coverage job
|
|
56
56
|
(currently `runs-on: ubuntu-latest` in `.github/workflows/ci.yml`) to
|
|
@@ -213,25 +213,29 @@ the mirror does not, or one that differs.
|
|
|
213
213
|
That destination is outside a session workspace, so a confined agent session is
|
|
214
214
|
refused there and has to approve a wider permission for the one command.
|
|
215
215
|
|
|
216
|
-
## 8.5. Announce on the upstream
|
|
216
|
+
## 8.5. Announce on the upstream discussions
|
|
217
217
|
|
|
218
|
-
Every release appends an update comment to
|
|
219
|
-
[deepseek-ai/deepseek-harness
|
|
220
|
-
(
|
|
218
|
+
Every release appends an update comment to both plugin threads in
|
|
219
|
+
[deepseek-ai/deepseek-harness](https://github.com/deepseek-ai/deepseek-harness):
|
|
220
|
+
[discussion #8644](https://github.com/deepseek-ai/deepseek-harness/discussions/8644)
|
|
221
|
+
(node id `D_kwDOT3T1g84AptnQ`) and
|
|
222
|
+
[discussion #11251](https://github.com/deepseek-ai/deepseek-harness/discussions/11251)
|
|
223
|
+
(node id `D_kwDOT3T1g84AqhvH`), so followers of either thread see each version
|
|
221
224
|
without watching this repository:
|
|
222
225
|
|
|
223
|
-
- One comment per release, in Chinese (the
|
|
224
|
-
updates; the English original stays as the top post, refreshed
|
|
225
|
-
releases).
|
|
226
|
+
- One comment per release in **each** thread, in Chinese (the established
|
|
227
|
+
language for updates; the English original stays as the top post, refreshed
|
|
228
|
+
on notable releases).
|
|
226
229
|
- Content: the version, the two or three headline changes, the current
|
|
227
230
|
verification snapshot in one line (unit tests, matrix, container and qemu
|
|
228
231
|
legs, nightly probes), and the release link.
|
|
229
232
|
- Post it with the same GraphQL mutation the 2026-10-27 update used
|
|
230
233
|
(`addDiscussionComment` on the discussion's node id) from a session that
|
|
231
234
|
holds the maintainer's GitHub credentials — the release workflow's
|
|
232
|
-
`GITHUB_TOKEN` is scoped to this repository and cannot write there.
|
|
235
|
+
`GITHUB_TOKEN` is scoped to this repository and cannot write there. Post the
|
|
236
|
+
same body to both, then read each back and compare it to the local source.
|
|
233
237
|
|
|
234
|
-
This is a hard checklist item, not a nicety: the
|
|
238
|
+
This is a hard checklist item, not a nicety: the threads are where the DSH
|
|
235
239
|
community found the plugin, and a stale thread reads as an abandoned one.
|
|
236
240
|
|
|
237
241
|
## 9. If a version turns out to be bad
|
package/docs/REQUIREMENTS.zh.md
CHANGED
|
@@ -45,7 +45,7 @@ docs/ 各篇里的行为承诺登记成带编号的需求条目,并给每条
|
|
|
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
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` | — |
|
|
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
|
-
| R12 | share 基座退役:携带 `substrate: "share"` 的 profile 在 boot 被拒并附迁移 | README/CONFIGURATION/LIMITATIONS 三处一致 | ①②⑤:旧值处置与用户所见成文,迁移指引内嵌 | `fs-decisions.test.mjs`(拒绝消息与迁移指引文案) | boot 期拒绝分支无测试(构造器调 `shareSubstrateRefusal`,`src/
|
|
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 |
|
|
50
50
|
| R14 | bootstrap:bwrap/ripgrep 等的就地体检与安装 | README「Install」「Troubleshooting」;CONFIGURATION | ①②⑤:`--install` 与只读体检两式、体检对象、错误消息补救指引成文 | 0.7.4 起脚本随包(`files` 收录,补救指引在 npm 安装下可用) | 脚本本身无 CI 腿(真机排错路径覆盖) |
|
|
51
51
|
| R15 | 错误码方言:每个 `FS_*` 码给出抛出者、含义、解除条件;`wsl.exe` 自身失败显式收编 | ARCHITECTURE「Error codes」表 | ①②:逐码三列成表;两类历史隐形失败(UTF-16 stdout、cwd 回退 exit 0)收编;`FS_OUTSIDE_DISTRO` 独立成码的理由明文 | `fs-decisions.test.mjs`、`fsio-agent.test.mjs`、`fs-substrate.test.mjs`、`provider.test.mjs`(断言码与消息) | — |
|
|
@@ -53,7 +53,7 @@ docs/ 各篇里的行为承诺登记成带编号的需求条目,并给每条
|
|
|
53
53
|
| R17 | 常驻 agent 协议:ACK 计时看门狗、只读帧才重放、逐流输出上限、sha256 部署校验、租约存活、进程组两段杀 | CHANGELOG 0.3.0/0.6.0/0.7.3;PARITY Phase 1/Phase 3 | ①②④:每条健壮性属性有规格出处与实证记录;「EXEC/变异 FS 帧禁止盲重发」是写明的不变量 | `agent-protocol.test.mjs`(HELLO 版本+摘要)、`agent.test.mjs`、`agent-exec.test.mjs`(truncated 旗标)、`agent-fs-script.test.mjs`;probe:agent、probe:exec | — |
|
|
54
54
|
| R18 | 配置面:每键默认值成文;层组合语义(整行替换、不深合并、后层胜) | CONFIGURATION;`cordis.patch.yml` 头注 | ⑤:随发键成表、未列表键点名;覆盖方式的正确心智模型(整行替换)成文 | `composition.test.mjs`(层组合);`style.mjs`(`files` 契约) | — |
|
|
55
55
|
| R19 | 非目标集:不做什么与为什么 | LIMITATIONS 开篇原则;PARITY「Not applicable」 | ③:已知极限入册;不适用项「记下来免得像遗漏」 | —(文档性) | — |
|
|
56
|
-
| R20 | 验证策略:三层(fake → 真脚本过真线 → 真机探针)+ CI 矩阵 + 覆盖率阈值 | ARCHITECTURE「Test layers」;README「Development」 | ④:CI 在 Node 22/24 × Linux/Windows 上跑 `pnpm test`,`pnpm run test:coverage` 只在 Node 24 上跑(门槛旗标需 Node 22.8);Node 20 有意排除(`engines` 下限);覆盖率阈值 85/84/70(行/分支/函数),测量集合覆盖 `test/` 下
|
|
56
|
+
| R20 | 验证策略:三层(fake → 真脚本过真线 → 真机探针)+ CI 矩阵 + 覆盖率阈值 | ARCHITECTURE「Test layers」;README「Development」 | ④:CI 在 Node 22/24 × Linux/Windows 上跑 `pnpm test`,`pnpm run test:coverage` 只在 Node 24 上跑(门槛旗标需 Node 22.8);Node 20 有意排除(`engines` 下限);覆盖率阈值 85/84/70(行/分支/函数),测量集合覆盖 `test/` 下 50 个测试文件,且 `lib/*.js` 必须逐个实测或带理由豁免 | `pnpm test`、`pnpm run test:coverage`;CI(ci.yml) | 真机验证依赖 Windows 和可用的 WSL 发行版;非功能无量化目标(OI-1) |
|
|
57
57
|
| R21 | 安全过程:范围内外、响应时限、partial 属设计边界、凭据政策 | SECURITY 全文 | ②③⑥:范围、3/10/30 个工作日时限(标注「目标非合同」)、partial 定性、凭据零容忍成文 | —(过程性) | — |
|
|
58
58
|
| R22 | 支持矩阵:Windows 10/11 + WSL2 + Node `^22.19.0 \|\| >=24.0.0` + peer 版本范围 | SUPPORT 全文 | ⑥:支持与不受支持清单、peer 范围及精确开发依赖成文;Node 20 在范围外(理由见 SUPPORT,`engines` 为准) | `peerDependencies`、`devDependencies` 与 `engines`(`package.json`);CI 矩阵(ci.yml) | 新 peer 版本仍需验证 |
|
|
59
59
|
| R23 | 根平面 `ctx.fs` 按坐标路由:发行版 UNC 由发行版内 agent 服务(inotify 或轮询 watch),盘符路径留在宿主;接替随发的 `fs-sandbox` 行 | README「Architecture」;ARCHITECTURE「The root-plane filesystem takeover」;CONFIGURATION `fs-routing` 行;root-fs-routing.md(设计) | ①②③⑤:路由判定与接替理由(写围栏在根平面无消费者)成文;`distro` 的 `auto`/`default`/pin 三态、每个 UNC 目标由自身 distro 服务、pin 下拒外来路径,以及 `distroCwd`/`restrictToDistro`/`sandbox`/`maskWindowsDrive`/`watchMaxDepth` 逐键成表,且自成一行、不与会话级行联动;`sandbox` 失败关闭成文 | `fs-routing.test.mjs`(纯谓词与路径助手)、`provider.test.mjs`(per-distro substrate/worldPath) | 类本体无单测(需 DSH peers 与实机);由组合测试与真机探针覆盖 |
|
|
@@ -62,6 +62,7 @@ docs/ 各篇里的行为承诺登记成带编号的需求条目,并给每条
|
|
|
62
62
|
| R26 | 诊断三入口同一份逐项报告:独立 CLI、`/wsl-doctor` UI 命令(宿主侧、不进模型历史)、`wsl_doctor` 模型工具(进程内合并常驻状态);报告按 distro 分组逐项带显式状态标记与失败修复;`--quick`/`--sections`(工具侧 `depth`/`section`)收窄范围且未运行项显式列为跳过 | DIAGNOSTICS「The surfaces」;README「Install」;CONFIGURATION「Diagnose configuration and refusals」 | ①②④:三入口的分工与边界成文;范围化报告携带 `scope`、`--fix` 要求完整运行成文;逐项化与跳过行的形态由 parity 测试钉住 | `wsl-doctor-tool.test.mjs`(digest/渲染/CHECK_CATALOG parity)、`wsl-doctor-command.test.mjs`(语法/handler/子进程面)、`doctor.test.mjs`(CLI 采集) | 真机多 distro 报告依赖实机;报告形态的宿主渲染(命令面 UI)无单测 |
|
|
63
63
|
| R27 | doctor CLI 独立性:不加载 peer 依赖与宿主服务,插件运行时本身损坏时仍可诊断;固定骨架本地化(Windows 区域设置检测,`--locale`/`DSH_WSL_DOCTOR_LOCALE` 覆盖),逐项事实保持英文,`--json` 语言无关 | DIAGNOSTICS「The surfaces」;CONFIGURATION「Message language」;LIMITATIONS「消息本地化」条 | ①②④:peer-free 内联与防漂移对拍成文;catalog 键 parity 与占位符行为有测试 | `doctor.test.mjs`(inlining parity、locale catalog、检测与覆盖) | 语言检测需 Windows registry(非 Windows 上回退英文,`run` 不抛错) |
|
|
64
64
|
| R28 | 每日更新检查经宿主插件管理器委托,不自取;事实进 `DSH_WSL_PLUGIN_UPDATE`;`wsl-update-check.enabled: false` 可关闭 | README「Install」;CONFIGURATION `wsl-update-check` 行 | ①②⑤:委托路径、TTL、关闭开关成文 | `update-check.test.mjs` | doctor 不再自行查询 registry:更新提示只走这条委托路径 |
|
|
65
|
+
| R29 | `workspace-write` 的额外可写目录:`writableRoots`(两行同列表)与共享 `additionalWritableRoots` 解析为同一组 Linux 根,经一次物理目录检查后绑定进命令、受限写入 resident 与 session runtime;已被工作区/临时区覆盖或嵌套的条目不绑定 | CONFIGURATION「工具链缓存与额外可写目录」;ARCHITECTURE「Sandbox」;LIMITATIONS「workspace-write 默认不授予…」 | ①②③⑤⑥:`~` 展开、UNC/Linux 拼写、跨发行版/盘符拒绝、together-grant、cached key、安全代价与 `partial` 成文 | `writable-roots.test.mjs`、`agent.test.mjs`(bwrap argv)、`provider.test.mjs`(围栏与命令两条路径)、`session-runtime.test.mjs`(key 与前缀);probe:sandbox 的授权根腿 | 真机端到端 `pnpm install` 尚未纳入探针套件;`additionalWritableRoots` 的宿主会话语义仍由上游策略决定 |
|
|
65
66
|
|
|
66
67
|
登记覆盖面:上表登记 README 与 docs/ 中对外成文的行为承诺(含随发的服务面)。
|
|
67
68
|
**有意未接线**的模块不设条目——`lib/file-reference-wsl.js`(`@` 补全的发行版侧
|
|
@@ -116,12 +116,13 @@ The rest of the module stays. `BINARY_SAMPLE_BYTES`, `FsCodedError`,
|
|
|
116
116
|
(`src/fsio-text.ts:23`, `:30`, `:53`, `:67`, `:86`, `:179`) have no counterpart
|
|
117
117
|
in the fsio declarations, and the module's other consumers keep importing them
|
|
118
118
|
locally (`src/fsio-agent.ts:27-34`, `src/fs-substrate.ts:37`,
|
|
119
|
-
`src/
|
|
119
|
+
`src/wsl-filesystem.ts:15`). `lib/fsio-text.js` is not deleted; four of its ten exports
|
|
120
120
|
are.
|
|
121
121
|
|
|
122
|
-
Importing from the entry costs this consumer nothing new:
|
|
123
|
-
`LocalFileSystem` from the same entry
|
|
124
|
-
`src/fs-routing.ts:36`) and `@deepseek-ai/dsh-fs`
|
|
122
|
+
Importing from the entry costs this consumer nothing new: the filesystem
|
|
123
|
+
provider imports `LocalFileSystem` from the same entry
|
|
124
|
+
(`src/wsl-filesystem.ts:3`, `src/fs-routing.ts:36`) and the `@deepseek-ai/dsh-fs`
|
|
125
|
+
types (`src/wsl-filesystem.ts:24`). The
|
|
125
126
|
entry's non-builtin static imports are `chokidar` (`lib/index.js:3`),
|
|
126
127
|
`@deepseek-ai/schemastery` (`:6`) and the `@deepseek-ai/dsh-fs` peer (`:7`) —
|
|
127
128
|
all three already in this consumer's graph; `koffi` loads lazily (`await
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# Upstream prompt adapters
|
|
2
|
+
|
|
3
|
+
*Status: temporary plugin-side adapters, 2026-11-11. Host line: DeepSeek Harness
|
|
4
|
+
0.2.2-rc.1. Remove each adapter once its upstream issue ships, then re-run the
|
|
5
|
+
prompt checks and the WSL probe suite.*
|
|
6
|
+
|
|
7
|
+
The plugin can present the WSL session correctly without waiting for the host,
|
|
8
|
+
because the host's generic prompt facts are written for a Windows workspace. The
|
|
9
|
+
adapters are deliberately narrow: each either replaces a host contribution or
|
|
10
|
+
adds one sentence, and each names the upstream change that retires it. See `src/cwd-prompt.ts` for the implementation and `test/cwd-prompt.test.mjs`
|
|
11
|
+
for the pinned behavior.
|
|
12
|
+
|
|
13
|
+
## 1. Shell note (`wsl:shell`)
|
|
14
|
+
|
|
15
|
+
**Adapter.** One system-prompt section after `tool:bash` says commands run in the
|
|
16
|
+
distro's login shell with `-lc`, not necessarily bash, and that `~/.bashrc` is
|
|
17
|
+
not read. It names `$DSH_WSL_SHELL` as the exact-shell source.
|
|
18
|
+
|
|
19
|
+
**Why.** The host's `dsh-tool-bash` hardcodes the tool name `bash` and the
|
|
20
|
+
description `bash -c`; a WSL preset actually runs the distro user's login shell
|
|
21
|
+
(e.g. `zsh -lc`). See [LIMITATIONS](LIMITATIONS.md#shell-startup-semantics-wsl-shell).
|
|
22
|
+
|
|
23
|
+
**Upstream issue.** `dsh-tool-bash` should consume `ShellExecutor.shellName()` and
|
|
24
|
+
derive the model-facing tool name and description from the mounted executor. The
|
|
25
|
+
longer-term rename is `dsh-tool-shell`: a POSIX-shell package named `shell`
|
|
26
|
+
(model tool `shell`, actual shell in the description), with
|
|
27
|
+
`dsh-tool-bash` kept as a compatibility alias. The package name and the
|
|
28
|
+
model-facing tool name are separate decisions: the latter is what the model
|
|
29
|
+
reads, so both must move together. The plugin deletes this section after the
|
|
30
|
+
short-term change ships.
|
|
31
|
+
|
|
32
|
+
## 2. POSIX policy (`sandbox:policy`)
|
|
33
|
+
|
|
34
|
+
**Adapter.** A session-scoped `sandbox:policy` context replaces the host line. It
|
|
35
|
+
reads `ctx.sandboxPolicy.resolve({ session })`, converts the workspace and any
|
|
36
|
+
additional writable roots to POSIX, omits anything without a POSIX spelling, and
|
|
37
|
+
adds the conditional partial-enforcement note. No UNC or Windows path is printed.
|
|
38
|
+
|
|
39
|
+
**Why.** The host renders `workspaceRoot` verbatim; a WSL workspace is a
|
|
40
|
+
`\\wsl.localhost\...` UNC. Its policy line also omits the plugin's `partial`
|
|
41
|
+
enforcement (WSL interop is outside bwrap). The model should not need to translate
|
|
42
|
+
a coordinate system or infer isolation the plugin does not provide.
|
|
43
|
+
|
|
44
|
+
**Upstream issue.** `dsh-sandbox-policy` should accept/render an execution-world
|
|
45
|
+
display path from the provider (POSIX for the WSL preset) and carry the
|
|
46
|
+
provider's `enforcement` fact. The adapter lists the host policy's
|
|
47
|
+
`additionalWritableRoots` and omits every non-POSIX spelling; the plugin rows'
|
|
48
|
+
own `writableRoots` are not part of that host policy, so the upstream contract
|
|
49
|
+
also needs the provider's effective writable roots. The plugin deletes this
|
|
50
|
+
replacement after that ships.
|
|
51
|
+
|
|
52
|
+
## 3. Host source (`harness:source`)
|
|
53
|
+
|
|
54
|
+
**Adapter.** A session-scoped empty `harness:source` section and context shadow
|
|
55
|
+
the host values in a WSL session. Nothing is printed.
|
|
56
|
+
|
|
57
|
+
**Why.** The host names the installed `app.asar` path (`C:\...`) as an
|
|
58
|
+
"implementation checkout" and tells the model it may inspect or extend it. In a
|
|
59
|
+
WSL session that path is a Windows path, not a readable source checkout; the
|
|
60
|
+
model gains nothing from it and may spend calls proving it.
|
|
61
|
+
|
|
62
|
+
**Upstream issue.** `dsh-harness-dev-context` should detect a packaged
|
|
63
|
+
installation and either omit the value or label it as a packaged installation.
|
|
64
|
+
The plugin deletes the shadow after that ships.
|
|
65
|
+
|
|
66
|
+
## 4. Preflight notice (`wsl-preflight`)
|
|
67
|
+
|
|
68
|
+
**Adapter.** Only a blocked preflight verdict is published as a runtime-context
|
|
69
|
+
entry, with its remedy marked as operator action. A ready verdict is log-only.
|
|
70
|
+
|
|
71
|
+
**Why.** DSH 0.2.1 has no session-notice seam; the runtime context is the only
|
|
72
|
+
visible channel. A ready verdict is not an action, so it is noise.
|
|
73
|
+
|
|
74
|
+
**Upstream issue.** A session notice seam would let the blocked advisory leave
|
|
75
|
+
the model's durable context. See
|
|
76
|
+
[UPSTREAM-SESSION-NOTICE.md](UPSTREAM-SESSION-NOTICE.md). The plugin then drops
|
|
77
|
+
the runtime-context entry.
|
|
78
|
+
|
|
79
|
+
## Explicit diagnostic exception
|
|
80
|
+
|
|
81
|
+
`wsl_doctor` is not injected proactively. When the user explicitly asks for a
|
|
82
|
+
host diagnosis, its report may name Windows paths for the host-owned checks
|
|
83
|
+
(`.wslconfig`, the Windows git trust, and similar). That output is the
|
|
84
|
+
diagnostic subject, not prompt context; the adapter set above keeps the
|
|
85
|
+
proactive prompt POSIX-only.
|
package/docs/root-fs-routing.md
CHANGED
|
@@ -69,7 +69,7 @@ home 缓存,所以同一个根平面可以同时服务多个发行版;`distr
|
|
|
69
69
|
客户端 `fileMediaUrl` 拒绝 `\\` 开头的路径(§2.2)——真有消费者时需要
|
|
70
70
|
按需覆写。
|
|
71
71
|
- `processPathFromHostPath` 也是宿主实现(绝对宿主路径取 `resolve`)。被路由的
|
|
72
|
-
`WslFileSystem` 自己有一份 distro 映射(`src/
|
|
72
|
+
`WslFileSystem` 自己有一份 distro 映射(`src/wsl-filesystem.ts:530`),那份映射不经
|
|
73
73
|
本路由。
|
|
74
74
|
|
|
75
75
|
### 2.2 有意的行为差异(对照原根 fs-sandbox)
|
package/lib/agent-confined.d.ts
CHANGED
|
@@ -65,6 +65,12 @@ interface ConfinedAgentRequest {
|
|
|
65
65
|
* exists to prevent.
|
|
66
66
|
*/
|
|
67
67
|
realTmp?: boolean;
|
|
68
|
+
/**
|
|
69
|
+
* Extra Linux roots to bind read-write in the resident's profile. The
|
|
70
|
+
* provider resolved, filtered and checked them; they are part of the cache
|
|
71
|
+
* key because the mount table is fixed for the resident's lifetime.
|
|
72
|
+
*/
|
|
73
|
+
writableRoots?: readonly string[];
|
|
68
74
|
}
|
|
69
75
|
/**
|
|
70
76
|
* The confined agent for one distro and one resolved policy, created on first
|
|
@@ -74,7 +80,7 @@ interface ConfinedAgentRequest {
|
|
|
74
80
|
* @param request - the confinement request.
|
|
75
81
|
* @returns the confined resident for this key.
|
|
76
82
|
*/
|
|
77
|
-
export declare function confinedAgent({ distro, wslPath, policy, maskWindowsDrive, realTmp }: ConfinedAgentRequest): WslAgent;
|
|
83
|
+
export declare function confinedAgent({ distro, wslPath, policy, maskWindowsDrive, realTmp, writableRoots }: ConfinedAgentRequest): WslAgent;
|
|
78
84
|
/** Test hook: forget every confined resident (the plain agent has no factory state). */
|
|
79
85
|
export declare function resetConfinedAgents(): void;
|
|
80
86
|
export {};
|
package/lib/agent-confined.js
CHANGED
|
@@ -105,8 +105,8 @@ export async function runSpawnChecklist({ wslPath, distro, root, runFn }) {
|
|
|
105
105
|
* @param request - the confinement request.
|
|
106
106
|
* @returns the confined resident for this key.
|
|
107
107
|
*/
|
|
108
|
-
export function confinedAgent({ distro, wslPath = "wsl.exe", policy, maskWindowsDrive = false, realTmp = true }) {
|
|
109
|
-
const key = `${wslPath}\0${distro}\0${policy.mode}\0${policy.workspaceRoot}\0${maskWindowsDrive ? "masked" : "visible"}\0${realTmp ? "real" : "ephemeral"}`;
|
|
108
|
+
export function confinedAgent({ distro, wslPath = "wsl.exe", policy, maskWindowsDrive = false, realTmp = true, writableRoots = [] }) {
|
|
109
|
+
const key = `${wslPath}\0${distro}\0${policy.mode}\0${policy.workspaceRoot}\0${maskWindowsDrive ? "masked" : "visible"}\0${realTmp ? "real" : "ephemeral"}\0${writableRoots.join("\0")}`;
|
|
110
110
|
let agent = confinedAgents.get(key);
|
|
111
111
|
if (agent === undefined) {
|
|
112
112
|
const linuxRoot = toLinuxPath(policy.workspaceRoot);
|
|
@@ -120,7 +120,7 @@ export function confinedAgent({ distro, wslPath = "wsl.exe", policy, maskWindows
|
|
|
120
120
|
// `wsl.exe --exec` and the `sh <script>` pair (`lib/agent.js`'s
|
|
121
121
|
// `spawnDefault`). Both confinement sites share that assembly in
|
|
122
122
|
// `lib/bwrap.js`, whose module doc records what happened when they did not.
|
|
123
|
-
argvPrefix: bwrapArgvPrefix({ mode: policy.mode, workspaceRoot: linuxRoot }, { maskWindowsDrive, realTmp }),
|
|
123
|
+
argvPrefix: bwrapArgvPrefix({ mode: policy.mode, workspaceRoot: linuxRoot }, { maskWindowsDrive, realTmp, writableRoots }),
|
|
124
124
|
// workspace-write is the only mode that binds the workspace root, and
|
|
125
125
|
// bwrap refuses a missing bind source (WSL-305): on a freshly imported
|
|
126
126
|
// distro the first write's workspace may not exist yet, and the resident
|
package/lib/bwrap.d.ts
CHANGED
|
@@ -40,6 +40,14 @@ interface BwrapProfileOptions {
|
|
|
40
40
|
* is then the cleanup boundary (ADR 0001).
|
|
41
41
|
*/
|
|
42
42
|
pidNamespace?: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Extra Linux directories to bind read-write under `workspace-write` — the
|
|
45
|
+
* toolchain caches and linked-worktree grants the operator configured. The
|
|
46
|
+
* caller has already resolved, filtered and physically checked them
|
|
47
|
+
* (`lib/writable-roots.js`); this module only turns them into mounts.
|
|
48
|
+
* Inert under `read-only`: the mode grants no write outside `/`.
|
|
49
|
+
*/
|
|
50
|
+
writableRoots?: readonly string[];
|
|
43
51
|
}
|
|
44
52
|
/**
|
|
45
53
|
* Build the bwrap profile arguments for one file-effect policy, exactly as
|
|
@@ -72,6 +80,12 @@ interface BwrapProfileOptions {
|
|
|
72
80
|
* resident. Read-only mode mounts no `/tmp` at all, so the option is inert
|
|
73
81
|
* there.
|
|
74
82
|
*
|
|
83
|
+
* `options.writableRoots` adds the operator's toolchain grants after the
|
|
84
|
+
* workspace bind. The caller owns their resolution, filtering and physical
|
|
85
|
+
* check (`lib/writable-roots.js`); binding a raw configured string here would
|
|
86
|
+
* let a model-written symlink redirect the grant, so this module never does
|
|
87
|
+
* that itself.
|
|
88
|
+
*
|
|
75
89
|
* @param policy - the policy to express as bwrap mounts.
|
|
76
90
|
* @param options - profile options.
|
|
77
91
|
* @returns profile arguments, before the `--` separator and the command argv.
|
package/lib/bwrap.js
CHANGED
|
@@ -54,6 +54,12 @@
|
|
|
54
54
|
* resident. Read-only mode mounts no `/tmp` at all, so the option is inert
|
|
55
55
|
* there.
|
|
56
56
|
*
|
|
57
|
+
* `options.writableRoots` adds the operator's toolchain grants after the
|
|
58
|
+
* workspace bind. The caller owns their resolution, filtering and physical
|
|
59
|
+
* check (`lib/writable-roots.js`); binding a raw configured string here would
|
|
60
|
+
* let a model-written symlink redirect the grant, so this module never does
|
|
61
|
+
* that itself.
|
|
62
|
+
*
|
|
57
63
|
* @param policy - the policy to express as bwrap mounts.
|
|
58
64
|
* @param options - profile options.
|
|
59
65
|
* @returns profile arguments, before the `--` separator and the command argv.
|
|
@@ -71,6 +77,11 @@ export function bwrapProfileArgs(policy, options = {}) {
|
|
|
71
77
|
args.push("--tmpfs", "/tmp");
|
|
72
78
|
}
|
|
73
79
|
args.push("--bind", policy.workspaceRoot, policy.workspaceRoot);
|
|
80
|
+
// The operator's toolchain grants come after the workspace bind, in the
|
|
81
|
+
// deterministic order the resolver returned. They are already filtered to
|
|
82
|
+
// roots with a read-only parent and checked to be physical directories.
|
|
83
|
+
for (const root of options.writableRoots ?? [])
|
|
84
|
+
args.push("--bind", root, root);
|
|
74
85
|
}
|
|
75
86
|
if (options.maskWindowsDrive) {
|
|
76
87
|
args.push("--tmpfs", "/mnt");
|
package/lib/cwd-prompt.d.ts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Distro-native
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* Distro-native model context: rewrite the `working-directory:current` entry so
|
|
3
|
+
* a distro session reads its directory as the POSIX path its own commands use,
|
|
4
|
+
* and adapt the host prompt facts that are wrong or unnecessarily Windows-shaped
|
|
5
|
+
* in a WSL session. The adaptations are deliberately narrow and replaceable:
|
|
6
|
+
* a one-sentence shell note, a POSIX-only replacement for `sandbox:policy`, and
|
|
7
|
+
* suppression of the host's `harness:source` value (its `app.asar`/Windows path
|
|
8
|
+
* is not a readable source checkout from the distro). See
|
|
9
|
+
* docs/UPSTREAM-PROMPT-ADAPTERS.md for the upstream issues that remove them.
|
|
5
10
|
*
|
|
6
11
|
* The harness's `working-directory` service prints the session cwd verbatim,
|
|
7
12
|
* which on this deployment is `\\wsl.localhost\<distro>\...` — the coordinate
|
|
@@ -84,8 +89,17 @@ interface CwdPromptScope {
|
|
|
84
89
|
interpolate: boolean;
|
|
85
90
|
text: (context: AssembleRequestContext) => string;
|
|
86
91
|
}) => unknown;
|
|
92
|
+
/** Register one system-prompt section in this scope's layer, when the harness has the seam. */
|
|
93
|
+
section?: (entry: {
|
|
94
|
+
name: string;
|
|
95
|
+
order: number;
|
|
96
|
+
interpolate: boolean;
|
|
97
|
+
text: string;
|
|
98
|
+
}) => unknown;
|
|
87
99
|
/** The order constant the harness assigned to a named context family. */
|
|
88
100
|
getContextOrder?: (family: string) => number | undefined;
|
|
101
|
+
/** The order constant the harness assigned to a named system-prompt section family. */
|
|
102
|
+
getSectionOrder?: (family: string) => number | undefined;
|
|
89
103
|
};
|
|
90
104
|
}
|
|
91
105
|
/** The assembly request context: what a provider's `text` receives. */
|
|
@@ -156,6 +170,30 @@ export declare function rewriteQuotedUnc(text: string): string;
|
|
|
156
170
|
* @returns the entry text.
|
|
157
171
|
*/
|
|
158
172
|
export declare function entryText(agent: AssembleRequestContext["agent"], workingDirectory: WorkingDirectorySlice | undefined): string;
|
|
173
|
+
/**
|
|
174
|
+
* One path in the only spelling a WSL model should see. A WSL UNC becomes its
|
|
175
|
+
* POSIX path; an already-POSIX path passes; every Windows spelling returns
|
|
176
|
+
* undefined, so a caller can omit it rather than leak it.
|
|
177
|
+
*
|
|
178
|
+
* @param value - a path from the host policy service or a session header.
|
|
179
|
+
* @returns the POSIX path, or undefined when no POSIX spelling is available.
|
|
180
|
+
*/
|
|
181
|
+
export declare function posixPath(value: string | undefined): string | undefined;
|
|
182
|
+
/**
|
|
183
|
+
* The POSIX-only replacement for the host's `sandbox:policy` context. It keeps
|
|
184
|
+
* the host's mode and root (resolved through `ctx.sandboxPolicy`) but never
|
|
185
|
+
* prints a UNC or Windows path. The partial qualifier is conditional because
|
|
186
|
+
* the plugin can be configured with the sandbox off or in danger-full-access.
|
|
187
|
+
*
|
|
188
|
+
* @param policy - the host policy resolution, when the service is available.
|
|
189
|
+
* @param cwd - the session's workspace, used when the policy root is not POSIX.
|
|
190
|
+
* @returns the model-facing policy text.
|
|
191
|
+
*/
|
|
192
|
+
export declare function policyText(policy: {
|
|
193
|
+
mode?: string;
|
|
194
|
+
workspaceRoot?: string;
|
|
195
|
+
additionalWritableRoots?: readonly string[];
|
|
196
|
+
} | undefined, cwd: string): string;
|
|
159
197
|
/**
|
|
160
198
|
* Mount the rewrite.
|
|
161
199
|
*
|
package/lib/cwd-prompt.js
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Distro-native
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* Distro-native model context: rewrite the `working-directory:current` entry so
|
|
3
|
+
* a distro session reads its directory as the POSIX path its own commands use,
|
|
4
|
+
* and adapt the host prompt facts that are wrong or unnecessarily Windows-shaped
|
|
5
|
+
* in a WSL session. The adaptations are deliberately narrow and replaceable:
|
|
6
|
+
* a one-sentence shell note, a POSIX-only replacement for `sandbox:policy`, and
|
|
7
|
+
* suppression of the host's `harness:source` value (its `app.asar`/Windows path
|
|
8
|
+
* is not a readable source checkout from the distro). See
|
|
9
|
+
* docs/UPSTREAM-PROMPT-ADAPTERS.md for the upstream issues that remove them.
|
|
5
10
|
*
|
|
6
11
|
* The harness's `working-directory` service prints the session cwd verbatim,
|
|
7
12
|
* which on this deployment is `\\wsl.localhost\<distro>\...` — the coordinate
|
|
@@ -42,7 +47,7 @@
|
|
|
42
47
|
* @module dsh-plugin-wsl-env/cwd-prompt
|
|
43
48
|
*/
|
|
44
49
|
import z from "@deepseek-ai/schemastery";
|
|
45
|
-
import { isWslUnc, uncToPosix } from "./paths.js";
|
|
50
|
+
import { isPosixAbsolute, isWslUnc, uncToPosix } from "./paths.js";
|
|
46
51
|
export const name = "wsl-cwd-prompt";
|
|
47
52
|
export const Config = z.object({
|
|
48
53
|
/** Whether the runtime-context rewrite runs at all. */
|
|
@@ -54,6 +59,16 @@ export const Config = z.object({
|
|
|
54
59
|
* (`assemble` and `refreshContext` merge scoped layers over the global one).
|
|
55
60
|
*/
|
|
56
61
|
const ENTRY_NAME = "working-directory:current";
|
|
62
|
+
/** The model-facing shell note; the host's bash tool name cannot be changed here. */
|
|
63
|
+
const SHELL_SECTION = "wsl:shell";
|
|
64
|
+
/** The shell note's literal text; no path, no session-specific value. */
|
|
65
|
+
const SHELL_NOTE = "The shell tool may be named `bash`, but commands run in the distro's login shell with `-lc` by default; it is not necessarily bash, and `~/.bashrc` is not read. Check `$DSH_WSL_SHELL` for the exact shell.";
|
|
66
|
+
/** The host policy context this plugin replaces with a POSIX-only rendering. */
|
|
67
|
+
const POLICY_CONTEXT = "sandbox:policy";
|
|
68
|
+
/** The host source context and section this plugin suppresses in a WSL session. */
|
|
69
|
+
const SOURCE_CONTEXT = "harness:source";
|
|
70
|
+
/** The qualification that keeps a WSL policy line from claiming full isolation. */
|
|
71
|
+
const PARTIAL_NOTE = "bwrap enforcement is \"partial\": WSL interop to Windows is outside it.";
|
|
57
72
|
/**
|
|
58
73
|
* Rewrite every JSON-string-quoted WSL UNC path in one text to its POSIX form.
|
|
59
74
|
* The harness writes the cwd through `JSON.stringify`, so the backslashes are
|
|
@@ -105,6 +120,60 @@ export function entryText(agent, workingDirectory) {
|
|
|
105
120
|
directory = session?.header?.cwd ?? "";
|
|
106
121
|
return rewriteQuotedUnc(`Current working directory: ${JSON.stringify(directory)}.`);
|
|
107
122
|
}
|
|
123
|
+
/**
|
|
124
|
+
* One path in the only spelling a WSL model should see. A WSL UNC becomes its
|
|
125
|
+
* POSIX path; an already-POSIX path passes; every Windows spelling returns
|
|
126
|
+
* undefined, so a caller can omit it rather than leak it.
|
|
127
|
+
*
|
|
128
|
+
* @param value - a path from the host policy service or a session header.
|
|
129
|
+
* @returns the POSIX path, or undefined when no POSIX spelling is available.
|
|
130
|
+
*/
|
|
131
|
+
export function posixPath(value) {
|
|
132
|
+
if (value === undefined || value.length === 0)
|
|
133
|
+
return undefined;
|
|
134
|
+
const parsed = uncToPosix(value);
|
|
135
|
+
if (parsed !== undefined)
|
|
136
|
+
return parsed.linuxPath;
|
|
137
|
+
return isPosixAbsolute(value) ? value : undefined;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* The POSIX-only replacement for the host's `sandbox:policy` context. It keeps
|
|
141
|
+
* the host's mode and root (resolved through `ctx.sandboxPolicy`) but never
|
|
142
|
+
* prints a UNC or Windows path. The partial qualifier is conditional because
|
|
143
|
+
* the plugin can be configured with the sandbox off or in danger-full-access.
|
|
144
|
+
*
|
|
145
|
+
* @param policy - the host policy resolution, when the service is available.
|
|
146
|
+
* @param cwd - the session's workspace, used when the policy root is not POSIX.
|
|
147
|
+
* @returns the model-facing policy text.
|
|
148
|
+
*/
|
|
149
|
+
export function policyText(policy, cwd) {
|
|
150
|
+
const mode = policy?.mode ?? "unknown";
|
|
151
|
+
const workspace = posixPath(policy?.workspaceRoot) ?? posixPath(cwd);
|
|
152
|
+
const roots = (policy?.additionalWritableRoots ?? [])
|
|
153
|
+
.map((root) => posixPath(root))
|
|
154
|
+
.filter((root) => root !== undefined);
|
|
155
|
+
const parts = [`Current DSH file policy: ${mode}.`];
|
|
156
|
+
if (mode === "danger-full-access") {
|
|
157
|
+
parts.push("No WSL file fence is applied.");
|
|
158
|
+
return parts.join(" ");
|
|
159
|
+
}
|
|
160
|
+
if (workspace !== undefined)
|
|
161
|
+
parts.push(`WSL workspace: ${JSON.stringify(workspace)}.`);
|
|
162
|
+
if (roots.length > 0)
|
|
163
|
+
parts.push(`Additional WSL writable roots: ${roots.map((root) => JSON.stringify(root)).join(", ")}.`);
|
|
164
|
+
if (mode === "read-only") {
|
|
165
|
+
parts.push(`When the WSL sandbox is enabled, mutations are refused; ${PARTIAL_NOTE}`);
|
|
166
|
+
}
|
|
167
|
+
else if (mode === "workspace-write") {
|
|
168
|
+
parts.push(roots.length > 0
|
|
169
|
+
? `When the WSL sandbox is enabled, mutations are limited to the WSL workspace and the listed roots; ${PARTIAL_NOTE}`
|
|
170
|
+
: `When the WSL sandbox is enabled, mutations are limited to the WSL workspace; ${PARTIAL_NOTE}`);
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
parts.push(`When the WSL sandbox enforces a mode, ${PARTIAL_NOTE}`);
|
|
174
|
+
}
|
|
175
|
+
return parts.join(" ");
|
|
176
|
+
}
|
|
108
177
|
/**
|
|
109
178
|
* Mount the rewrite.
|
|
110
179
|
*
|
|
@@ -133,6 +202,7 @@ export function apply(ctx, config = {}) {
|
|
|
133
202
|
if (agentCtx === undefined || typeof agentCtx.inject !== "function")
|
|
134
203
|
return;
|
|
135
204
|
let workingDirectory;
|
|
205
|
+
let sandboxPolicy;
|
|
136
206
|
try {
|
|
137
207
|
const resolved = agentCtx.get?.("workingDirectory");
|
|
138
208
|
if (resolved !== undefined && resolved !== null)
|
|
@@ -141,20 +211,67 @@ export function apply(ctx, config = {}) {
|
|
|
141
211
|
catch (error) {
|
|
142
212
|
debug(`wsl-cwd-prompt: could not read the workingDirectory service (${error?.message ?? error})`);
|
|
143
213
|
}
|
|
214
|
+
try {
|
|
215
|
+
const resolved = agentCtx.get?.("sandboxPolicy");
|
|
216
|
+
if (resolved !== undefined && resolved !== null)
|
|
217
|
+
sandboxPolicy = /** @type {SandboxPolicySlice} */ (resolved);
|
|
218
|
+
}
|
|
219
|
+
catch (error) {
|
|
220
|
+
debug(`wsl-cwd-prompt: could not read the sandboxPolicy service (${error?.message ?? error})`);
|
|
221
|
+
}
|
|
222
|
+
const resolvePolicy = () => {
|
|
223
|
+
try {
|
|
224
|
+
return sandboxPolicy?.resolve?.({ session: agent.session });
|
|
225
|
+
}
|
|
226
|
+
catch {
|
|
227
|
+
return undefined;
|
|
228
|
+
}
|
|
229
|
+
};
|
|
144
230
|
try {
|
|
145
231
|
agentCtx.inject(["systemPrompt"], (scope) => {
|
|
146
|
-
const
|
|
147
|
-
|
|
232
|
+
const systemPrompt = scope.systemPrompt;
|
|
233
|
+
systemPrompt.context({
|
|
148
234
|
name: ENTRY_NAME,
|
|
149
|
-
order,
|
|
235
|
+
order: systemPrompt.getContextOrder?.("WORKING_DIRECTORY") ?? 200,
|
|
150
236
|
required: true,
|
|
151
237
|
interpolate: false,
|
|
152
238
|
text: (context) => entryText(context?.agent, workingDirectory),
|
|
153
239
|
});
|
|
240
|
+
systemPrompt.context({
|
|
241
|
+
name: POLICY_CONTEXT,
|
|
242
|
+
order: systemPrompt.getContextOrder?.("SANDBOX_POLICY") ?? 110,
|
|
243
|
+
required: false,
|
|
244
|
+
interpolate: false,
|
|
245
|
+
text: () => policyText(resolvePolicy(), cwd),
|
|
246
|
+
});
|
|
247
|
+
// The host source value is a Windows/app.asar path in this deployment.
|
|
248
|
+
// An empty scoped contribution removes it from the snapshot; a WSL
|
|
249
|
+
// session has no readable use for the host spelling.
|
|
250
|
+
systemPrompt.context({
|
|
251
|
+
name: SOURCE_CONTEXT,
|
|
252
|
+
order: systemPrompt.getContextOrder?.("HARNESS_SOURCE") ?? 200,
|
|
253
|
+
required: false,
|
|
254
|
+
interpolate: false,
|
|
255
|
+
text: () => "",
|
|
256
|
+
});
|
|
257
|
+
if (typeof systemPrompt.section === "function") {
|
|
258
|
+
systemPrompt.section({
|
|
259
|
+
name: SHELL_SECTION,
|
|
260
|
+
order: systemPrompt.getSectionOrder?.("TOOL_BASH") ?? 1000,
|
|
261
|
+
interpolate: false,
|
|
262
|
+
text: SHELL_NOTE,
|
|
263
|
+
});
|
|
264
|
+
systemPrompt.section({
|
|
265
|
+
name: SOURCE_CONTEXT,
|
|
266
|
+
order: systemPrompt.getSectionOrder?.("HARNESS_SOURCE") ?? 10000,
|
|
267
|
+
interpolate: false,
|
|
268
|
+
text: "",
|
|
269
|
+
});
|
|
270
|
+
}
|
|
154
271
|
});
|
|
155
272
|
}
|
|
156
273
|
catch (error) {
|
|
157
|
-
debug(`wsl-cwd-prompt: could not install the
|
|
274
|
+
debug(`wsl-cwd-prompt: could not install the prompt adapters (${error?.message ?? error})`);
|
|
158
275
|
}
|
|
159
276
|
};
|
|
160
277
|
ctx.on("agent/created", (payload) => {
|