dsh-plugin-wsl-env 0.24.0 → 0.26.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 +136 -0
- package/CODE_OF_CONDUCT.md +85 -0
- package/CODE_OF_CONDUCT.zh.md +85 -0
- package/CONTRIBUTING.md +19 -3
- package/CONTRIBUTING.zh.md +200 -0
- package/README.md +18 -6
- package/SECURITY.md +12 -0
- package/SECURITY.zh.md +108 -0
- package/SUPPORT.md +2 -0
- package/SUPPORT.zh.md +99 -0
- package/client.js +409 -8
- package/cordis.patch.yml +17 -0
- package/docs/AGENT-PROTOCOL-V7.md +2 -2
- package/docs/API.md +2 -0
- package/docs/API.zh.md +38 -0
- package/docs/ARCHITECTURE.md +30 -9
- package/docs/ARCHITECTURE.zh.md +511 -0
- package/docs/COMPATIBILITY.md +2 -0
- package/docs/COMPATIBILITY.zh.md +117 -0
- package/docs/CONFIGURATION.md +45 -2
- package/docs/CONFIGURATION.zh.md +39 -3
- package/docs/DIAGNOSTICS.md +12 -2
- package/docs/DIAGNOSTICS.zh.md +5 -1
- package/docs/LIMITATIONS.md +60 -9
- package/docs/LIMITATIONS.zh.md +45 -9
- package/docs/MIGRATION.md +6 -3
- package/docs/MIGRATION.zh.md +91 -0
- package/docs/PEER-PARITY.md +63 -51
- package/docs/PERFORMANCE.md +2 -0
- package/docs/PERFORMANCE.zh.md +59 -0
- package/docs/QUICKSTART.md +21 -6
- package/docs/QUICKSTART.zh.md +16 -4
- package/docs/README.zh.md +28 -19
- package/docs/RELEASING.md +19 -14
- package/docs/REQUIREMENTS.zh.md +6 -3
- package/docs/ROADMAP-1.0.md +1 -1
- package/docs/UPSTREAM-FILE-REFERENCE-SEAM.md +1 -1
- package/docs/UPSTREAM-FSIO-EXPORT.md +5 -4
- package/docs/UPSTREAM-OPEN-IN-APP.md +33 -11
- package/docs/UPSTREAM-PROMPT-ADAPTERS.md +85 -0
- package/docs/UPSTREAM-SESSION-NOTICE.md +7 -0
- package/docs/VALUE.md +146 -0
- package/docs/VALUE.zh.md +15 -13
- 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/auto-preset-seam.d.ts +45 -0
- package/lib/auto-preset-seam.js +47 -0
- package/lib/auto-preset.d.ts +33 -10
- package/lib/auto-preset.js +148 -44
- 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-live.d.ts +30 -0
- package/lib/doctor-live.js +37 -0
- 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 +20 -1
- package/lib/messages.js +31 -3
- package/lib/open-in-app.d.ts +206 -0
- package/lib/open-in-app.js +300 -0
- package/lib/preflight.d.ts +7 -4
- package/lib/preflight.js +27 -13
- package/lib/preset-choice.d.ts +13 -0
- package/lib/preset-choice.js +18 -1
- 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/status.js +2 -1
- package/lib/writable-roots.d.ts +109 -0
- package/lib/writable-roots.js +257 -0
- package/lib/wsl-doctor-command.js +2 -1
- 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 +48 -24
- package/scripts/doctor.mjs +1 -1
- package/scripts/profile-preset.mjs +17 -5
|
@@ -0,0 +1,511 @@
|
|
|
1
|
+
# 架构
|
|
2
|
+
|
|
3
|
+
[English](ARCHITECTURE.md)
|
|
4
|
+
|
|
5
|
+
本文件描述插件当前的实际状态。它覆盖代码做了什么,以及每个部分位于何处。
|
|
6
|
+
设计背后的推理,包括被否决的设计,记录在
|
|
7
|
+
[`CHANGELOG.md`](../CHANGELOG.md) 和
|
|
8
|
+
[`archive/engineering-record.zh.md`](https://github.com/Big-Dao/dsh-plugin-wsl-env/blob/main/docs/archive/engineering-record.zh.md)
|
|
9
|
+
中。
|
|
10
|
+
|
|
11
|
+
## 这里的“provider”指什么
|
|
12
|
+
|
|
13
|
+
DSH 以服务的形式暴露自身能力。面向模型的工具(`bash`、`read`、`write`、
|
|
14
|
+
`edit`、`glob`、`grep`)消费这些服务,它们从不直接接触文件系统或 shell。
|
|
15
|
+
|
|
16
|
+
本插件为其中三项提供 WSL 后端实现,替换三个应用层行(`subprocess`、
|
|
17
|
+
`fs-sandbox`、`directory-picker`),并新增下文列出的较小集成。
|
|
18
|
+
|
|
19
|
+
## 三个服务提供者
|
|
20
|
+
|
|
21
|
+
| 服务 | 类 | 文件 | 作用 |
|
|
22
|
+
|---|---|---|---|
|
|
23
|
+
| `ctx.shell` | `WslShellExecutor` | [`lib/wsl-shell.js`](../lib/wsl-shell.js) | 在发行版的登录 shell 中运行每条命令,默认经由常驻的发行版内 agent,并包在发行版侧的 `bwrap` 沙箱里;agent 不在时,或设置 `agent: false` 时,同一条命令退回到一个 `wsl.exe -d <distro> --cd <linux dir> --exec <login shell> -lc <cmd>` 进程。 |
|
|
24
|
+
| `ctx.fs` | `WslFileSystem` | [`lib/wsl-filesystem.js`](../lib/wsl-filesystem.js) | 通过常驻的发行版内 agent 服务 WSL 路由的文件操作;此前的 Windows 侧 share 底座已退役(见下文)。 |
|
|
25
|
+
| `ctx.subprocess` | `WslSubprocessRuntime` | [`lib/subprocess.js`](../lib/subprocess.js) | 在发行版内、会话工作区中打开 GUI 终端,并把文件搜索与 git 快照的 spawn 改写到发行版内(见下文)。 |
|
|
26
|
+
|
|
27
|
+
`WslShellExecutor` 继承随包的 `LocalBashExecutor`,`WslFileSystem` 继承随包的
|
|
28
|
+
`LocalFileSystem`。只覆盖需要发行版的那部分。
|
|
29
|
+
|
|
30
|
+
## 根平面的文件系统接管
|
|
31
|
+
|
|
32
|
+
根级 `ctx.fs` 没有会话,因此无法由 agent preset 提供服务。该层用一个按坐标
|
|
33
|
+
路由的子类整体替换它的随包行:
|
|
34
|
+
|
|
35
|
+
| 服务 | 类 | 文件 | 作用 |
|
|
36
|
+
|---|---|---|---|
|
|
37
|
+
| `ctx.fs`(根平面) | `WslRoutingFileSystem` | [`lib/fs-routing.js`](../lib/fs-routing.js) | 根文件系统,按坐标路由:发行版 UNC 标识在发行版内服务(可用时用 inotify,否则轮询),盘符路径保持宿主原生。它接替随包的 `fs-sandbox` 行——该行的写围栏在根平面没有消费者,模型的写入走 preset 文件系统。设计见 [`root-fs-routing.md`](root-fs-routing.md)。 |
|
|
38
|
+
|
|
39
|
+
GUI 文件树与预览保留随包的 `workspace-files` 行。它的客户端半边是侧边栏预览
|
|
40
|
+
所需的浏览器 `file` 资源提供者,因此用仅服务端的子类替换该行会丢掉它;随包的
|
|
41
|
+
服务改为通过被路由的根文件系统读取 WSL 路径。代价是每次列表、`stat` 或分页
|
|
42
|
+
读取都多出几次 `ctx.fs` 往返(见 [LIMITATIONS.zh.md](LIMITATIONS.zh.md))。
|
|
43
|
+
|
|
44
|
+
这次接管发生在组合层,理由与终端正好互为镜像(见下文):没有会话标识能到达
|
|
45
|
+
根文件系统。它是一个顶层的 `disabled:` 条目,指向随包行,外加一个只含替代行的
|
|
46
|
+
`insert:` 列表——因为写在 insert 列表*内部*的 `disabled` 不是 patch,而是一行
|
|
47
|
+
重复 id 的数据行;而嵌套的 `insert:` 根本不会被解释。
|
|
48
|
+
[`cordis.patch.yml`](../cordis.patch.yml) 承载完整的行列表,`test/composition.test.mjs`
|
|
49
|
+
用真实的 patch 算法跑一遍该文件,以保持结构诚实。
|
|
50
|
+
|
|
51
|
+
还有一个模块随包构建,但有意不接线:
|
|
52
|
+
[`lib/file-reference-wsl.js`](../lib/file-reference-wsl.js),即 `@` 补全的
|
|
53
|
+
发行版侧遍历策略。它已构建、已测试,但**未**接入 `cordis.patch.yml`——它消费的
|
|
54
|
+
接缝是一项上游提案
|
|
55
|
+
([`upstream/rfc-wsl-workspaces.md`](https://github.com/Big-Dao/dsh-plugin-wsl-env/blob/main/docs/upstream/rfc-wsl-workspaces.md)),
|
|
56
|
+
而要在没有它的情况下抵达这些漏斗(funnel),就得用子类越过模块内部的函数。
|
|
57
|
+
|
|
58
|
+
## 较小的集成
|
|
59
|
+
|
|
60
|
+
| 子路径 | 类或名称 | 文件 | 作用 |
|
|
61
|
+
|---|---|---|---|
|
|
62
|
+
| `dsh-plugin-wsl-env/picker` | `WslDirectoryPicker` | [`lib/picker.js`](../lib/picker.js) | 文件夹选择器的两个世界:一个分类根,带 Windows 分支(从盘符开始)和 WSL 分支(每个已安装发行版一行);发行版层级在发行版内部列出(用常驻 agent 的 `find`,它不在时用一次性 `wsl.exe`)。 |
|
|
63
|
+
| `dsh-plugin-wsl-env/auto-preset` | `auto-preset` | [`lib/auto-preset.js`](../lib/auto-preset.js) | 当新会话的工作区位于某个发行版内时,绑定 `wsl` agent preset。 |
|
|
64
|
+
| `dsh-plugin-wsl-env/shell-env` | `wsl-shell-env` | [`lib/shell-env.js`](../lib/shell-env.js) | 向受管的 `DSH_*` 命名空间贡献 `DSH_WSL_DISTRO`、`DSH_WSL_SHELL`、`DSH_WSL_HOME` 和 `DSH_WSL_PORTS`,并选取会话工作区所属的发行版(默认/钉死的事实于挂载时探测;其他发行版在其会话出现时预热)。端口列表是每个活跃发行版的快照,每 `portsRefreshMs`(默认 10000)刷新一次,因此刚启动的服务器可能尚未列出。 |
|
|
65
|
+
| `dsh-plugin-wsl-env/preflight` | `wsl-preflight` | [`lib/preflight.js`](../lib/preflight.js) | 在会话开始时运行环境提示——若 `startup: true`(默认值),还在插件加载时运行一次——把 doctor 风格的判定作为不阻断的警告呈现。 |
|
|
66
|
+
| `dsh-plugin-wsl-env/update-check` | `wsl-update-check` | [`lib/update-check.js`](../lib/update-check.js) | 大约每天一次向应用的插件管理器询问是否有更新的稳定版本,并把该事实带在 `DSH_WSL_PLUGIN_UPDATE` 中;自身从不抓取。 |
|
|
67
|
+
| `dsh-plugin-wsl-env/cwd-prompt` | `wsl-cwd-prompt` | [`lib/cwd-prompt.js`](../lib/cwd-prompt.js) | 把运行时上下文的工作目录条目改写为发行版的 POSIX 形式;新增一句 `wsl:shell` 说明;把 `sandbox:policy` 替换为仅 POSIX 的渲染;并在 WSL 会话中抑制宿主的 `harness:source` 值。后三项是临时适配器,跟踪于 [UPSTREAM-PROMPT-ADAPTERS.md](UPSTREAM-PROMPT-ADAPTERS.md)。 |
|
|
68
|
+
| `dsh-plugin-wsl-env/cwd-prompt-tool` | `wsl-cwd-prompt-tool` | [`lib/cwd-prompt-tool.js`](../lib/cwd-prompt-tool.js) | 以 harness 随包提供的相同语义提供模型的 read/`cd` 工具,把返回的 `cwd` 改写为发行版的 POSIX 形式。 |
|
|
69
|
+
| `dsh-plugin-wsl-env/wsl-doctor-tool` | `wsl-doctor-tool` | [`lib/wsl-doctor-tool.js`](../lib/wsl-doctor-tool.js) | `wsl_doctor` 模型工具:进程内的 doctor(合并活跃常驻 agent 的状态),按 `depth`/`section` 限定范围,渲染为逐项摘要。 |
|
|
70
|
+
| `dsh-plugin-wsl-env/wsl-doctor-command` | `wsl-doctor-command` | [`lib/wsl-doctor-command.js`](../lib/wsl-doctor-command.js) | `/wsl-doctor` UI 命令:把独立的 doctor CLI 作为宿主子进程启动,并在与模型历史分离的界面中渲染同一份摘要。 |
|
|
71
|
+
| `dsh-plugin-wsl-env/status` | `wsl-status` | [`lib/status.js`](../lib/status.js) | 侧边栏面板的路由(`GET /api/wsl-env/status`):列出已安装的发行版,并对其中一个发行版运行 quick doctor;同一路由上的 `POST` 以 `--fix-owned` 运行完整 doctor(当陈旧的 scope 或损坏的 agent 缓存可修复时标为修复,否则为完整检查;两者都会重新验证)。响应经 Host 连接已认证的 exact-Fetch 通道返回;每个发行版的最近结果持久化在 `$DSH_HOME/cache/dsh-plugin-wsl-env/status.json`,运行中发行版的已存结果会在后台刷新。 |
|
|
72
|
+
| `dsh-plugin-wsl-env`(裸名) | `wsl-env-client-host` | [`lib/client-host.js`](../lib/client-host.js) | 有意为之的空操作宿主半边;它的裸名挂载让 web 客户端名册能够提供 `./client`:侧边栏的 WSL 环境面板,以及添加后的访问模式提示。 |
|
|
73
|
+
|
|
74
|
+
三个路径与 interop 助手不导入任何 DSH 包。
|
|
75
|
+
[`lib/paths.js`](../lib/paths.js) 负责路径转换。
|
|
76
|
+
[`lib/listing.js`](../lib/listing.js) 构建目录列表与面包屑。
|
|
77
|
+
[`lib/wsl.js`](../lib/wsl.js) 持有 `wsl.exe` interop 原语。
|
|
78
|
+
|
|
79
|
+
[`lib/provider-common.js`](../lib/provider-common.js) 是提供者间的粘合层,而不是
|
|
80
|
+
无 peer 依赖的助手:它导入 `@deepseek-ai/dsh-sandbox`,在 shell 与文件系统
|
|
81
|
+
提供者之间共享发行版解析、home 缓存、运行时选择和可写根转换。
|
|
82
|
+
|
|
83
|
+
## 各部件如何挂载
|
|
84
|
+
|
|
85
|
+
[`cordis.patch.yml`](../cordis.patch.yml) 是 bundle 层。它是 patch 条目的顶层
|
|
86
|
+
YAML 数组,`dsh plugin --profile <name> add dsh-plugin-wsl-env` 在 CLI 发行版上
|
|
87
|
+
把它作为一层应用;桌面应用通过侧边栏 **Plugins** 页面(**Add plugin**)应用
|
|
88
|
+
同一个 bundle,并记录到 profile 的 `dsh.profile.bundles` 中。
|
|
89
|
+
|
|
90
|
+
环境按会话而非按进程:
|
|
91
|
+
|
|
92
|
+
| 行 | 挂载位置 | 为什么在那里 |
|
|
93
|
+
|---|---|---|
|
|
94
|
+
| `wsl-shell`、`wsl-fs` | 位于 `preset-wsl` 内——一个带隔离域的 agent preset | 使一个进程可以同时服务 Windows 工作区和发行版工作区 |
|
|
95
|
+
| `subprocess-wsl` | 在应用层(即组合层);随包的 `subprocess` 行被禁用 | 因为没有会话标识能到达终端控制器,见下文 |
|
|
96
|
+
| `workspace-files` | 随包、未替换 | 其客户端半边是侧边栏预览所需的浏览器 `file` 资源提供者;它通过被路由的根文件系统读取 WSL 路径 |
|
|
97
|
+
| `fs-routing` | 在应用层;随包的 `fs-sandbox` 行被禁用 | 根 `ctx.fs` 无会话,且其写围栏在根平面没有消费者 |
|
|
98
|
+
| `directory-picker-wsl`、`wsl-shell-env`、`auto-preset`、`wsl-preflight`、`wsl-update-check`、`wsl-cwd-prompt`、`wsl-cwd-prompt-tool`、`wsl-doctor-command`、`wsl-status`、`wsl-env-client-host` | 在应用层 | 它们回答的问题不限定于单个 preset;`shell-env` 按会话工作区解析其事实,而提示/诊断类行必须在会话从未打开时也能应答 |
|
|
99
|
+
| `wsl-doctor-tool` | 位于 `preset-wsl` 内(面向模型) | 工具面跟随 preset:在 Windows 文件夹上的会话保留随包工具 |
|
|
100
|
+
|
|
101
|
+
preset 挂载需要隔离域。缺少时,registry 以
|
|
102
|
+
`Preset services require isolate realms: shell, fs` 拒绝这些提供者。
|
|
103
|
+
|
|
104
|
+
### 终端提供者为何位于应用层
|
|
105
|
+
|
|
106
|
+
agent preset 在其隔离域中运行服务。preset registry 在自己的上下文下用
|
|
107
|
+
`createScope(this.owner, ...)` 创建该域。agent loop 则在根域下用
|
|
108
|
+
`createScope(loopCtx, ...)` 创建 Agent 上下文。
|
|
109
|
+
|
|
110
|
+
终端控制器用 `agent.ctx.get("subprocess")` 解析其执行世界,而该查找落在第二棵
|
|
111
|
+
树中。因此挂载在第一棵树里的提供者对它是不可见的。registry 为此缺口提供了
|
|
112
|
+
`agentPresets.serviceFor(agent, name)`,但终端控制器并未使用它。
|
|
113
|
+
|
|
114
|
+
于是该层禁用随包的 `subprocess` 行,并在应用层原位插入
|
|
115
|
+
`dsh-plugin-wsl-env/subprocess`。子类覆盖两个方法:`spawnTerminal` 把 `wsl.exe`
|
|
116
|
+
启动改写为 `wsl.exe -d <distro> --cd <linux dir>`;`spawn()` 把两类启动改写到
|
|
117
|
+
发行版内——文件搜索工具随包的 ripgrep 和 git 快照命令(两者都优先走已预热的
|
|
118
|
+
常驻 agent——协议 v6 承载 git 调用的 stdin,而一次性调用要付出约 230 ms 的
|
|
119
|
+
`wsl.exe` 启动开销,常驻 agent 只需约 2 ms——agent 不在时以一次性的
|
|
120
|
+
`wsl.exe --exec` 句柄为回退)。宿主没有 git 时,`resolveExecutable` 对 git
|
|
121
|
+
返回一个发行版哨兵路径,快照命令的发现调用(`rev-parse --show-toplevel ...`)
|
|
122
|
+
也随之路由,其绝对路径输出再转换回 UNC 形式——因此没有 Windows git 也能完成
|
|
123
|
+
完整的 WSL 变更审阅。两个 spawn 决策都是纯坐标函数(`lib/search-route.js`、
|
|
124
|
+
`lib/git-route.js`);其余所有 `spawn()`——包括一次性回退自身的
|
|
125
|
+
`wsl.exe -lc <command>`(默认 agent 路径是通过常驻 agent 承载命令,而不是
|
|
126
|
+
spawn)——都原样到达随包实现,pwsh 执行器和 LSP 宿主同样如此。
|
|
127
|
+
|
|
128
|
+
终端的执行世界跟随会话(`hostSessions`,默认开启):WSL 文件夹上的会话运行
|
|
129
|
+
发行版 shell,Windows 文件夹上的会话在其自身目录中运行 `powershell.exe`。
|
|
130
|
+
仍然跟随应用配置的是 shell 菜单的 DEFAULT 条目及其标题,两者都来自组合层
|
|
131
|
+
唯一的 `WSL` shell profile——所以新标签页无论运行什么,标题都显示 `WSL`,
|
|
132
|
+
包括宿主会话的 PowerShell。菜单还列出宿主候选(`powershell`、`cmd`;
|
|
133
|
+
`wsl.exe` 去重进默认项),手动选择的 shell 以自身命名。见
|
|
134
|
+
[LIMITATIONS.zh.md](LIMITATIONS.zh.md) 和
|
|
135
|
+
[UPSTREAM-TERMINAL-TITLE.md](UPSTREAM-TERMINAL-TITLE.md)。
|
|
136
|
+
|
|
137
|
+
## 路径坐标
|
|
138
|
+
|
|
139
|
+
代码中出现三种坐标系统:
|
|
140
|
+
|
|
141
|
+
| 系统 | 示例 | 使用者 |
|
|
142
|
+
|---|---|---|
|
|
143
|
+
| 发行版内的 Linux | `/home/you/proj/a.ts` | 命令、`ctx.shell` |
|
|
144
|
+
| 发行版的 UNC 共享 | `\\wsl.localhost\ubuntu\home\you\proj\a.ts` | harness 的路径标识(`ctx.fs` 目标键)、选择器与终端路由——这是坐标而非 I/O 路径:没有文件工具通过该共享读写 |
|
|
145
|
+
| Windows 文件系统 | `C:\Users\you\...`,或在发行版内写作 `/mnt/c/Users/you/...` | 在 Windows 文件夹上打开的会话 |
|
|
146
|
+
|
|
147
|
+
[`lib/paths.js`](../lib/paths.js) 在它们之间转换。它是纯的:不导入 DSH 包,
|
|
148
|
+
也不做 I/O。其包含关系助手判断目标路径是否位于某个可写根之下。文件系统围栏
|
|
149
|
+
使用它们。
|
|
150
|
+
|
|
151
|
+
## 文件系统 substrate
|
|
152
|
+
|
|
153
|
+
`wsl-fs` 在一个 I/O substrate 上服务 `ctx.fs`:常驻的发行版内 agent。此前的
|
|
154
|
+
Windows 侧 share 后端(`substrate: "share"`)已退役——带该值的 profile 在启动
|
|
155
|
+
时被拒绝,且没有文件工具跨 9p 共享。该 substrate 的事实如下:
|
|
156
|
+
|
|
157
|
+
- **读取、写入、标识**都经常驻 agent 在支撑发行版路径的文件系统上执行,
|
|
158
|
+
发行版自有文件通常是 ext4。符号链接与权限位行为同样取决于该文件系统;
|
|
159
|
+
标识使用发行版侧的 `realpath`,发布使用内核的 rename 或 link。
|
|
160
|
+
- **受守卫的写入**把意图带到发布环节:`createIfAbsent` 以不可替换的 link
|
|
161
|
+
发布,从根上关掉创建时的“先检查后写入”窗口;覆盖、编辑、patch、删除或移动
|
|
162
|
+
把期望版本带入操作,agent 在 rename 或移除之前重新校验(`moveFile` 校验
|
|
163
|
+
两端)。不匹配返回 `FS_STALE_VERSION`,但该检查之后发生的变更仍可能被覆盖。
|
|
164
|
+
- **内核强制**是第二阶段:变更运行在受约束的常驻 agent 上——每个(发行版、
|
|
165
|
+
策略)组合一个长生命周期 agent,其 bwrap profile 恰好绑定该模式授予的内容
|
|
166
|
+
——因此内核会拒绝检查本应拒绝的操作,检查代码的 bug 不会变成工作区之外的
|
|
167
|
+
写入。升级后的写入(`danger-full-access`)走普通常驻 agent。内核拒绝携带
|
|
168
|
+
`FS_SANDBOX_DENIED`,与命令路径同一方言。
|
|
169
|
+
- **新文件**以 0600 发布——与 Linux 宿主上一样,这是宿主后端自身的 POSIX
|
|
170
|
+
发布语义。
|
|
171
|
+
- **agent 中断**时失败关闭:报 `FS_IO_ERROR`,指明 substrate 与恢复路径。
|
|
172
|
+
没有回退 I/O;没有可用 bwrap 的发行版会以 bootstrap 命令拒绝受限变更,
|
|
173
|
+
与命令路径相同的关闭式失败。
|
|
174
|
+
|
|
175
|
+
写入用命令路径沙箱所描述的同一套宿主侧策略做围栏——
|
|
176
|
+
`WslFileSystem.checkedTarget`,基于同一份可写列表;命令路径本身由发行版侧
|
|
177
|
+
profile 约束,从不调用它——而 substrate 不改变 `sandboxMode` 上报的内容。
|
|
178
|
+
substrate 使用的线协议记录在 [`agent/wsl-agent.sh`](../agent/wsl-agent.sh);
|
|
179
|
+
编排层是 [`lib/fsio-agent.js`](../lib/fsio-agent.js)(fsio 在 FS 帧之上的
|
|
180
|
+
机制)、[`lib/fs-substrate.js`](../lib/fs-substrate.js)(提供者形态的操作,
|
|
181
|
+
包含写入/编辑守卫的编排),以及 [`lib/fsio-text.js`](../lib/fsio-text.js)
|
|
182
|
+
(纯文本机制,在上游导出落地前从上游复制,导出提案见
|
|
183
|
+
[UPSTREAM-FSIO-EXPORT.md](UPSTREAM-FSIO-EXPORT.md))。
|
|
184
|
+
|
|
185
|
+
## 沙箱
|
|
186
|
+
|
|
187
|
+
### 为什么不能用 Windows runner
|
|
188
|
+
|
|
189
|
+
在 Windows 上,DSH 用 `dsh-sandbox-windows-acl` 约束命令。它使用受限的
|
|
190
|
+
低完整性 Windows 令牌和写入允许列表。
|
|
191
|
+
|
|
192
|
+
该令牌无法触达 WSL。`wsl.exe` 以 `Wsl/E_ACCESSDENIED` 失败,
|
|
193
|
+
`\\wsl.localhost\<distro>` 报告访问被拒绝。两者在沙箱之外都正常工作。
|
|
194
|
+
|
|
195
|
+
### 插件改用另一种做法
|
|
196
|
+
|
|
197
|
+
插件在 Windows 侧构建 `bubblewrap` profile,把得到的 argv 交给发行版——默认
|
|
198
|
+
经由常驻 agent,或在一次性回退中交给 `wsl.exe --exec`。约束在发行版内创建,
|
|
199
|
+
两条路径的 argv 相同:
|
|
200
|
+
|
|
201
|
+
```text
|
|
202
|
+
wsl.exe -d <distro> --cd <linux dir> --exec bwrap \
|
|
203
|
+
--ro-bind / / --dev /dev --unshare-pid --proc /proc --die-with-parent \
|
|
204
|
+
[--tmpfs /tmp --bind <workspace> <workspace> [--bind <root> <root> ...]] [--tmpfs /mnt] -- <shell> -lc <cmd>
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
默认情况下,该 profile 只在 `systemd-run --user --scope` 下包裹会话的常驻
|
|
208
|
+
agent 一次,命令 argv 就是 shell 行本身:
|
|
209
|
+
`bwrap … --die-with-parent --bind /tmp /tmp --bind <workspace> <workspace> -- sh agent.sh`。
|
|
210
|
+
这里没有 `--unshare-pid`,也没有按命令的 tmpfs,因此后台进程得以存活,`/tmp`
|
|
211
|
+
是发行版真实的 `/tmp`,`ps` 能看到该会话。上面那种按命令的 argv 仍是
|
|
212
|
+
`sessionSandbox: false`(以及一次性回退)所运行的。
|
|
213
|
+
|
|
214
|
+
这些参数与 DSH 的 Linux runner(`dsh-sandbox-local`)所用的一致,因此行为和
|
|
215
|
+
错误消息与 Linux 宿主相同。构建它们的是 [`lib/bwrap.js`](../lib/bwrap.js)
|
|
216
|
+
中的函数 `bwrapProfileArgs`——每个约束点都组合使用的无 peer 依赖构建器。
|
|
217
|
+
末尾的 `[--tmpfs /mnt]` 是 `maskWindowsDrive` 选项:开启时,Windows 盘在每个
|
|
218
|
+
受限 profile 中都被一个空 tmpfs 遮蔽,其文件无法被读取或外泄,其可执行文件
|
|
219
|
+
也无法通过 interop 启动。该选项默认关闭;
|
|
220
|
+
[CONFIGURATION.zh.md](CONFIGURATION.zh.md) 列出了该行的键,
|
|
221
|
+
`lib/sandbox-core.js` 说明其真实上限。
|
|
222
|
+
|
|
223
|
+
可选的 `--bind <root> <root>` 对来自该行的 `writableRoots` 和共享策略的
|
|
224
|
+
`additionalWritableRoots`。`lib/writable-roots.js` 负责解析它们(`~` 展开、
|
|
225
|
+
UNC/Linux 写法),丢弃已在工作区、`/tmp` 或 `/dev/shm` 下可写的条目,以及
|
|
226
|
+
嵌套在另一条授权内的条目,然后每个进程检查一次,确认剩余每个根都是已存在的
|
|
227
|
+
物理目录。同一份有效列表会进入命令 profile、受限写入常驻 agent 和会话运行时
|
|
228
|
+
——也进入它们的缓存键,因为挂载表在 agent 生命周期内固定。
|
|
229
|
+
|
|
230
|
+
| 模式 | 发行版内的命令能做什么 |
|
|
231
|
+
|---|---|
|
|
232
|
+
| `read-only` | 读整个发行版;新的 `/dev` 以可写挂载,因此 `/dev/null` 与 `/dev/shm` 可用,其余不行 |
|
|
233
|
+
| `workspace-write` | 上述之外,会话工作区和任何显式授予的根可写;会话运行时中的 `/tmp` 是发行版真实的 `/tmp`,按命令 profile(`sessionSandbox: false`)中是新的 tmpfs |
|
|
234
|
+
| `danger-full-access` | 无沙箱;用于获批的更宽权限请求 |
|
|
235
|
+
|
|
236
|
+
`WslFileSystem` 用同一策略和同一可写列表检查写入,但有一处有意的转换:对
|
|
237
|
+
发行版内的会话,临时根是发行版自己的 `/tmp`,Windows 临时目录*不*授予,因为
|
|
238
|
+
它位于策略所描述的执行世界之外。这避免了 `bash` 能写 `/tmp` 而写入工具不能
|
|
239
|
+
的不一致。在按命令 profile(`sessionSandbox: false`)中,两个 `/tmp` 是不同
|
|
240
|
+
的目录——命令侧是新的 tmpfs;随包的会话运行时共享发行版真实的 `/tmp`——见
|
|
241
|
+
[LIMITATIONS.zh.md](LIMITATIONS.zh.md)。提供者的变更面是 `writeText`、
|
|
242
|
+
`editText`、`patchText`、`deleteFile` 和 `moveFile`;每一项都经
|
|
243
|
+
`checkedTarget`,因此围栏覆盖该提供者能服务的每个变更。两个提供者都通过
|
|
244
|
+
`sandboxMode` 上报模式。工具层和 Permissions 选择器读取该值。
|
|
245
|
+
|
|
246
|
+
### 上报的强制程度
|
|
247
|
+
|
|
248
|
+
`WslSandbox` 上报 `enforcement: partial`,而不是 `full`。发行版内的进程仍可
|
|
249
|
+
通过 WSL interop 运行 Windows 程序,例如 `/mnt/c/.../*.exe`。Bubblewrap 并不
|
|
250
|
+
管束该进程。
|
|
251
|
+
|
|
252
|
+
`maskWindowsDrive`,或 `interopVisibility` 的 `masked` 与 `disabled` 立场,会在
|
|
253
|
+
受限命令中遮蔽 `/mnt`,这是收窄而非关闭。其他挂载和不受约束的文件读取不在
|
|
254
|
+
遮罩覆盖范围内,而 `binfmt` interop 按文件*内容*分派,所以能写工作区的命令
|
|
255
|
+
仍可在那里写入 PE 并让它作为 Windows 进程启动。无论哪种方式,提供者都上报
|
|
256
|
+
`partial`。禁用 WSL interop 需要发行版层面的另一项改动(`wsl.conf` 中的
|
|
257
|
+
`[interop] enabled=false`);`disabled` 立场不会做这项改动。遮罩在结果的
|
|
258
|
+
sandbox fact 上报为 `windowsDrive: "masked"`(或 `"visible"`),但那是本插件
|
|
259
|
+
自己的额外字段:被钉死的 harness 版本中,sandbox 类型及其面向模型的注记只
|
|
260
|
+
携带 `mode`、`denied`、`enforcement` 和 `runnerFailed`,因此该字段到达结果与
|
|
261
|
+
测试,不到模型。
|
|
262
|
+
|
|
263
|
+
`pnpm run probe:sandbox` 在你的机器上演示该边界,并以 `INFO` 记录。
|
|
264
|
+
|
|
265
|
+
### 失败模式
|
|
266
|
+
|
|
267
|
+
两个提供者都失败关闭。发行版内没有可用的 `bwrap` 时,`WslSandbox` 抛出
|
|
268
|
+
`SandboxUnavailableError`,每条受限命令都上报 `SANDBOX_UNAVAILABLE`。不会有
|
|
269
|
+
任何东西在无约束状态下静默运行。字符串 `read-only file system` 被归为拒绝,
|
|
270
|
+
因此工具层能提供放宽权限的路径。
|
|
271
|
+
|
|
272
|
+
失败的探测**不会**被记住:只有成功才会在进程生命周期内缓存,因此应用运行期间
|
|
273
|
+
安装的 `bubblewrap` 在下一条命令就被认可。见
|
|
274
|
+
[`lib/probe-cache.js`](../lib/probe-cache.js)。
|
|
275
|
+
|
|
276
|
+
因发行版本身缺失、已停止或未注册而从未启动的命令,单独上报:
|
|
277
|
+
`wsl.exe` 把 `WSL_E_*` 码写在 stdout 上,stderr 为空,`WslShellExecutor`
|
|
278
|
+
把它转成点名发行版与补救方法的错误,而不是一个裸的非零退出。它有意不是沙箱
|
|
279
|
+
错误码,因为更宽的权限不能创建发行版。
|
|
280
|
+
|
|
281
|
+
在任一提供者上设置 `sandbox: false` 即可退出。命令随后不受约束地运行,
|
|
282
|
+
`sandboxMode` 返回 `undefined`。
|
|
283
|
+
|
|
284
|
+
## 错误码
|
|
285
|
+
|
|
286
|
+
插件抛出带错误码的 `FsError`,由工具层映射;`wsl.exe` 自身的失败也有命名。
|
|
287
|
+
插件自身抛出的每个 `FsError` 错误码都在下面——模型看到错误码,追问“是什么
|
|
288
|
+
拒绝了我”的读者在这里找到答案。盘符路径背后由随包宿主栈抛出的错误码原样
|
|
289
|
+
穿过 `lib/fs-routing.js`,属于 peer 而非本表;GUI 文件服务是随包的
|
|
290
|
+
`workspace-files` 行,其线协议拒绝使用 peer 自己的方言,在表后说明。
|
|
291
|
+
|
|
292
|
+
| 错误码 | 抛出方 | 含义 | 如何解除 |
|
|
293
|
+
|---|---|---|---|
|
|
294
|
+
| `SANDBOX_UNAVAILABLE` | `WslSandbox.confine` | 所请求的模式无法强制:发行版内没有可用的 `bwrap` | 在发行版内安装 `bubblewrap`(失败的探测会重跑,无需重启),或设置 `sandbox: false` |
|
|
295
|
+
| `SANDBOX_INVALID_ROOT` | `effectiveWritableRoots`(两个提供者) | `writableRoots` 或 `additionalWritableRoots` 中的条目格式错误、指向另一个世界,或未通过一次性物理目录检查 | 修正该条目;先在发行版内创建目录,使用绝对 Linux 路径或 `~/...`,并使用物理目录而非符号链接 |
|
|
296
|
+
| `FS_SANDBOX_DENIED` | `WslFileSystem.checkedTarget`,以及 `lib/fsio-agent.js`(受限常驻 agent 的挂载表拒绝的写入,按内核的 `read-only file system` 归类) | 文件效果策略拒绝了写入:`read-only`,或目标位于可写根之外——或内核在常驻 agent 的 profile 处拒绝了它 | 为那一次调用放宽权限,或让会话工作区包含该目标 |
|
|
297
|
+
| `FS_OUTSIDE_DISTRO` | `WslFileSystem.worldPath` | `distro` 被固定(`default` 或某名称),`restrictToDistro` 开启,而该路径指向**另一个发行版**的共享——这是配置围栏,不是沙箱决策。`distro: ''`/`auto` 时,UNC 目标由它自己的发行版服务,围栏没有外来目标可拒 | 把 `distro` 设为 `''`/`auto`(默认),或在该发行版中打开会话。更宽的权限**不能**解除它 |
|
|
298
|
+
| `FS_NOT_OBSERVED` | `lib/fs-substrate.js`(`writeText`;agent 的 `exists` 结论,在 `lib/fsio-agent.js` 中映射) | 受守卫的创建(`createIfAbsent`)指向一个已存在且此前未被读取的文件 | 先读取该文件,然后用版本守卫覆盖或编辑它 |
|
|
299
|
+
| `FS_STALE_VERSION` | `lib/fs-substrate.js`(`writeText`、`editText`;agent 的 `stale` 结论,在 `lib/fsio-agent.js` 中映射) | 调用方持有的版本不再匹配:文件已变更或已消失 | 重新读取,并以新版本重试 |
|
|
300
|
+
| `FS_IO_ERROR` | 文件系统栈:`lib/fs-decisions.js`(substrate 不可用)、`lib/fsio-agent.js`(`perm`/`loop`/`io` 原因或畸形记录)、`lib/wsl-filesystem.js`(无法映射的路径,或 `SandboxUnavailableError`),以及 `WslFileSystem.watch` | 兜底的 I/O 失败——最常见的是常驻 agent 不在,或发行版返回 I/O 错误,即上文的「agent 中断时失败关闭」情形。监视目标落在所选发行版之外则属于较窄的情形 | 恢复常驻 agent(检查 `wsl.exe -l -v`,然后重启会话);对于监视,把目标指向发行版路径——监视本身运行在文件所在处(`lib/watcher.js`) |
|
|
301
|
+
| `FS_NOT_FOUND` | `lib/fsio-agent.js` 与 `lib/fs-substrate.js`(agent 的 `notfound`/`notdir` 结论、空路径,或缺失的编辑目标),以及盘符路径背后的宿主文件系统栈 | 路径不存在——普通的回答 | — |
|
|
302
|
+
| `FS_NOT_REGULAR_FILE` | `lib/fsio-agent.js`、`lib/fs-substrate.js` | 目标在要求普通文件处不是普通文件:读取时的目录、符号链接或设备,或写入时的非文件目标 | 把调用指向普通文件 |
|
|
303
|
+
| `FS_NOT_DIRECTORY` | `lib/fsio-agent.js`(`listChildren`) | 目标不是目录,因此没有子项可列 | 改为列出目录 |
|
|
304
|
+
| `FS_NOT_TEXT` | `lib/fsio-agent.js`、`lib/fsio-text.js` | 内容不是 UTF-8 文本:NUL 样本(二进制)或解码失败 | 不是策略拒绝——请读取文本,或对二进制内容使用命令 |
|
|
305
|
+
| `FS_TOO_LARGE` | `lib/fsio-agent.js` | 内容超出调用方操作携带的字节上限 | 改为读取字节范围(`WslFileSystem.readByteRange`),而不是整个文件;或提高上限 |
|
|
306
|
+
| `FS_ABORTED` | `lib/fsio-agent.js`、`lib/fsio-text.js` | 调用方的 signal 在操作之前或期间被中止 | 不是拒绝——调用方取消了;重新调用即可清除 |
|
|
307
|
+
| `FS_EDIT_NOT_FOUND` | `lib/fsio-text.js`(`applyLiteralEdit`) | `old_string` 为空,或在文件中没有匹配 | 给出文件中确实存在的 `old_string` |
|
|
308
|
+
| `FS_AMBIGUOUS_EDIT` | `lib/fsio-text.js`(`applyLiteralEdit`) | `old_string` 匹配多次且未设置 `replace_all` | 让 `old_string` 唯一,或设置 `replace_all` |
|
|
309
|
+
| `FS_PATCH_MISMATCH` | `lib/fs-substrate.js`(`patchText`;agent 的记录方言,`docs/AGENT-PROTOCOL-V7.md`) | hunk 的 `oldLines` 在 hunk 指定的行处不再匹配文件——文本在调用方读取与 patch 之间漂移了 | 重新读取文件,并基于新文本重建 hunk |
|
|
310
|
+
| `FS_SAME_TARGET` | `lib/fs-substrate.js`(`moveFile`) | `moveFile` 的源和目标解析到同一个文件 | 给出两个不同的路径,或放弃该调用 |
|
|
311
|
+
|
|
312
|
+
GUI 文件服务保留随包的 `workspace-files` 行,因此其线协议拒绝是 peer 的
|
|
313
|
+
`workspace-file/*` 方言(外加畸形分页请求的 `gateway/bad-request`),而不是
|
|
314
|
+
本插件的 `FsError` 错误码。插件提供被路由的 `ctx.fs`;agent 中断以
|
|
315
|
+
`FS_IO_ERROR` 到达该服务,由 peer 映射。
|
|
316
|
+
|
|
317
|
+
另有两类失败来自 `wsl.exe` 本身,而不是我们的错误码,它们过去都不可见:
|
|
318
|
+
|
|
319
|
+
| 失败 | 如何到达 | 插件如何处理 |
|
|
320
|
+
|---|---|---|
|
|
321
|
+
| 发行版缺失、已停止或未注册 | **stdout** 上的 `Wsl/Service/WSL_E_*` 码,某些构建为 UTF-16,stderr 为空,退出码 255 | `WslShellExecutor` 剥掉 NUL 后读取该码,并以发行版名称和补救方法失败。有意不作为沙箱错误码:更宽的权限不能创建发行版 |
|
|
322
|
+
| 无法进入工作目录 | stderr 上的一行中继信息,退出码 **0**,命令实际在 `/` 中运行 | `WslShellExecutor` 以该目录和回退方案失败,而不是报告一次作用在错误目录树上的成功 |
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
模型在文件系统拒绝时实际看到的是工具层前置的两行:
|
|
326
|
+
`[sandbox: file access denied under <mode> mode]`,然后是
|
|
327
|
+
`[sandbox: escalation available — retry this exact operation once with
|
|
328
|
+
sandbox_permissions (the narrowest wider mode that suffices) + justification; the
|
|
329
|
+
approval prompt asks the user]`。不是 `FS_SANDBOX_DENIED` 的错误码则两行都
|
|
330
|
+
不会出现——这正是 `FS_OUTSIDE_DISTRO` 拥有独立错误码的原因。
|
|
331
|
+
|
|
332
|
+
## 运行时镜像
|
|
333
|
+
|
|
334
|
+
检出目录位于发行版内。DSH profile 只能链接 Windows 路径,而 pnpm 会把
|
|
335
|
+
`link:\\wsl.localhost\...` 改写成断链的 `/wsl.localhost/...` 符号链接。因此
|
|
336
|
+
harness 无法从发行版内的检出目录加载插件。
|
|
337
|
+
|
|
338
|
+
`default-workspace/dsh-plugin-wsl` 处的 Windows 副本是运行时镜像。
|
|
339
|
+
[`test/probe/sync-to-windows.sh`](https://github.com/Big-Dao/dsh-plugin-wsl-env/blob/main/test/probe/sync-to-windows.sh)
|
|
340
|
+
让它与检出目录保持一致,`pnpm run sync:windows` 运行该脚本。
|
|
341
|
+
|
|
342
|
+
## 测试分层
|
|
343
|
+
|
|
344
|
+
| 分层 | 位置 | 需要 harness |
|
|
345
|
+
|---|---|---|
|
|
346
|
+
| 风格与打包检查 | [`test/style.mjs`](https://github.com/Big-Dao/dsh-plugin-wsl-env/blob/main/test/style.mjs) | 否 |
|
|
347
|
+
| 语法检查 | [`test/syntax.mjs`](https://github.com/Big-Dao/dsh-plugin-wsl-env/blob/main/test/syntax.mjs) | 否 |
|
|
348
|
+
| 构建一致性 | [`test/build-freshness.mjs`](https://github.com/Big-Dao/dsh-plugin-wsl-env/blob/main/test/build-freshness.mjs) | 否;它会重跑真实构建并逐字节比较已提交的 `lib/`,因此也能发现那里的孤立文件 |
|
|
349
|
+
| 类型检查 | 对 `test/**` 和 `types/*.d.ts` 运行 `tsc --noEmit`(`src/` 由构建本身检查) | 否 |
|
|
350
|
+
| 单元测试 | `test/*.test.mjs` | 否 |
|
|
351
|
+
| 需求矩阵 | [`scripts/check-requirements.mjs`](https://github.com/Big-Dao/dsh-plugin-wsl-env/blob/main/scripts/check-requirements.mjs) | 否;每个被引用的测试都必须存在并保持接线 |
|
|
352
|
+
| 文档一致性 | [`scripts/check-doc-consistency.mjs`](https://github.com/Big-Dao/dsh-plugin-wsl-env/blob/main/scripts/check-doc-consistency.mjs) | 否;覆盖重复事实、doctor 面与双语对完整性 |
|
|
353
|
+
| 沙箱探针 | [`test/probe/sandbox.sh`](https://github.com/Big-Dao/dsh-plugin-wsl-env/blob/main/test/probe/sandbox.sh) | 否;它直接应用 profile 参数 |
|
|
354
|
+
| Harness 探针 | [`test/probe/run.sh`](https://github.com/Big-Dao/dsh-plugin-wsl-env/blob/main/test/probe/run.sh)、`terminal.sh`、`sandbox-shell.sh`、`interop-shell.sh`、`picker.sh`、`fs-routing.sh`、`missing-wsl.sh`、`sandbox-off.sh`、`native-session.sh` | 是:Windows、WSL2、已挂载的 profile 和链接的检出目录 |
|
|
355
|
+
| 发行版探针 | [`test/probe/substrate.sh`](https://github.com/Big-Dao/dsh-plugin-wsl-env/blob/main/test/probe/substrate.sh)、`watch.sh`、`agent.sh`、`exec.sh`、`session-sandbox.sh`、`gui-preview.sh`、`file-reference-9p.sh` | 需要 Windows 和 WSL2,但不需要启动 harness,也不需要 profile:它们在装有 Node 的发行版终端中运行,经 interop 触达 `wsl.exe` |
|
|
356
|
+
| 宿主探针 | [`test/probe/mode.sh`](https://github.com/Big-Dao/dsh-plugin-wsl-env/blob/main/test/probe/mode.sh) | Windows Node,无 harness |
|
|
357
|
+
| 探针插件 | `test/probe/` 中的 `*-probe.mjs` 与 `*-probe.yml` 文件(以及诸如 `gui-preview.mjs`、`native-session.mjs`、`fs-probe.mjs`、`fs-queue.mjs` 之类的独立测量器) | 由上述脚本加载或调用 |
|
|
358
|
+
|
|
359
|
+
`pnpm test` 按顺序运行 `lint:style`、`lint:links`、`lint:requirements`、
|
|
360
|
+
`lint:docs`、`test:syntax`、`lint:build`、`lint:types` 和 `test:unit`。
|
|
361
|
+
[`test/probe/run-all-when-closed.sh`](https://github.com/Big-Dao/dsh-plugin-wsl-env/blob/main/test/probe/run-all-when-closed.sh)
|
|
362
|
+
等待应用退出,然后完整运行一次真机套件——`--include-fs` 会把 `run.sh`
|
|
363
|
+
放在最前面。
|
|
364
|
+
|
|
365
|
+
单元测试分两类:多数只导入 Node 内建模块,而
|
|
366
|
+
[`test/composition.test.mjs`](https://github.com/Big-Dao/dsh-plugin-wsl-env/blob/main/test/composition.test.mjs)、
|
|
367
|
+
[`test/fs.boot.test.mjs`](https://github.com/Big-Dao/dsh-plugin-wsl-env/blob/main/test/fs.boot.test.mjs)、
|
|
368
|
+
[`test/fsio-agent.test.mjs`](https://github.com/Big-Dao/dsh-plugin-wsl-env/blob/main/test/fsio-agent.test.mjs) 和
|
|
369
|
+
[`test/provider.test.mjs`](https://github.com/Big-Dao/dsh-plugin-wsl-env/blob/main/test/provider.test.mjs)
|
|
370
|
+
导入钉死的 `@deepseek-ai/*` 开发依赖(组合与启动测试运行加载器真实的 patch
|
|
371
|
+
算法)。首次运行前执行一次 `pnpm install` 即可重建该依赖树;运行时包本身仍
|
|
372
|
+
零依赖。CI 在 Linux 和 Windows、Node 22 和 24 上运行 `pnpm test`,只在
|
|
373
|
+
Node 24 上运行 `pnpm run test:coverage`——阈值标志需要 Node 22.8。Node 20
|
|
374
|
+
是有意缺席的:`engines` 要求 `^22.19.0 || >=24.0.0`,即 harness 宿主自身的
|
|
375
|
+
下限。harness 探针是手动步骤,因为托管 runner 没有 WSL 发行版,也没有可挂载
|
|
376
|
+
的 profile。
|
|
377
|
+
|
|
378
|
+
探针脚本共用
|
|
379
|
+
[`test/probe/env.sh`](https://github.com/Big-Dao/dsh-plugin-wsl-env/blob/main/test/probe/env.sh),
|
|
380
|
+
它从机器推导 Windows 用户、发行版名称和检出目录的 UNC 写法;Node 侧探针则共用
|
|
381
|
+
[`test/probe/env.mjs`](https://github.com/Big-Dao/dsh-plugin-wsl-env/blob/main/test/probe/env.mjs)。
|
|
382
|
+
没有探针携带用户名,YAML overlay 是带 `@NAME@` 占位符的模板,由脚本替换进
|
|
383
|
+
生成的副本。
|
|
384
|
+
|
|
385
|
+
## 文件布局
|
|
386
|
+
|
|
387
|
+
`lib/` 是生成产物:每个模块的源码是 `src/<name>.ts`,`pnpm run build` 产出
|
|
388
|
+
`lib/<name>.js` 及其 `lib/<name>.d.ts`。绝不要手改 `lib/`——已提交字节与真实
|
|
389
|
+
构建漂移时 `lint:build` 失败,任一方向的孤立文件同样使它失败。
|
|
390
|
+
|
|
391
|
+
```text
|
|
392
|
+
src/<name>.ts the sources — edit THESE; each builds to lib/<name>.{js,d.ts}
|
|
393
|
+
agent/wsl-agent.sh the resident in-distro agent (POSIX sh, coreutils only)
|
|
394
|
+
cordis.patch.yml the bundle configuration layer (dsh.bundle), commented
|
|
395
|
+
examples/ one machine-local profile layer, for comparison
|
|
396
|
+
locale/ the Plugins-page display metadata (title/description)
|
|
397
|
+
scripts/ the build (build.mjs), the release helpers
|
|
398
|
+
(check-release-tag.mjs, changelog-section.mjs), and the
|
|
399
|
+
distro-side bootstrap installer (bootstrap.sh)
|
|
400
|
+
test/ unit tests, the style/build/type gates, and the probes
|
|
401
|
+
docs/ this file, the configuration and limitation references,
|
|
402
|
+
the release checklist, and the archived designs
|
|
403
|
+
```
|
|
404
|
+
|
|
405
|
+
模块按字母顺序排列:
|
|
406
|
+
|
|
407
|
+
```text
|
|
408
|
+
src/agent-confined.ts the confined residents' factory (one per policy)
|
|
409
|
+
src/agent-errors.ts the error a resident outage rejects with
|
|
410
|
+
src/agent-exec.ts the agent-backed shell execution handle
|
|
411
|
+
src/agent-protocol.ts the wire protocol codecs (pure)
|
|
412
|
+
src/agent-shared.ts the per-distro resident shared by every provider
|
|
413
|
+
src/agent.ts the resident in-distro agent's host side
|
|
414
|
+
src/auto-preset.ts per-session environment selection
|
|
415
|
+
src/bwrap.ts the bwrap command line every confinement site
|
|
416
|
+
assembles (no imports, so a bare checkout can
|
|
417
|
+
assert it)
|
|
418
|
+
src/client-host.ts the bare-name host half — a deliberate no-op that
|
|
419
|
+
anchors the browser client
|
|
420
|
+
src/cwd-prompt.ts rewrites the working directory; applies the temporary prompt adapters
|
|
421
|
+
to the distro's POSIX form
|
|
422
|
+
src/cwd-prompt-tool.ts serves the model's read/cd tool with distro-POSIX
|
|
423
|
+
cwd output
|
|
424
|
+
src/distro-route.ts the pure distro-mode selector (pinned / workspace /
|
|
425
|
+
default) shared by shell, fs, preflight and env
|
|
426
|
+
src/doctor-live.ts merges the live resident's status into a collected
|
|
427
|
+
doctor report
|
|
428
|
+
src/file-reference-wsl.ts the distro-side `@`-completion traversal — built,
|
|
429
|
+
tested, not yet wired (see above)
|
|
430
|
+
src/fs.ts the ctx.fs subpath entry point
|
|
431
|
+
src/fs-decisions.ts the filesystem provider's policy decisions (pure,
|
|
432
|
+
unit-testable in a bare checkout)
|
|
433
|
+
src/fs-routing.ts WslRoutingFileSystem, the root-plane ctx.fs
|
|
434
|
+
src/fs-substrate.ts the agent substrate's provider-shaped operations
|
|
435
|
+
src/fsio-agent.ts fsio's mechanics over the agent's FS frames
|
|
436
|
+
src/fsio-text.ts the peer's pure text mechanics, replicated pending
|
|
437
|
+
the upstream fsio export (UPSTREAM-FSIO-EXPORT.md)
|
|
438
|
+
src/git-exec.ts the agent-backed execution handle for the
|
|
439
|
+
git-snapshot spawn
|
|
440
|
+
src/git-route.ts which git spawns belong inside the distro (pure)
|
|
441
|
+
src/index.ts public provider exports
|
|
442
|
+
src/wsl-shell.ts WslShellExecutor (ctx.shell)
|
|
443
|
+
src/wsl-filesystem.ts WslFileSystem (ctx.fs)
|
|
444
|
+
src/doctor-report.ts in-process doctor collector used by the tool
|
|
445
|
+
src/provider-common.ts distro, home, runtime and writable-root helpers
|
|
446
|
+
src/listing.ts pure directory listing and breadcrumb helpers
|
|
447
|
+
src/messages.ts the en/zh message catalogs and the host-locale wiring
|
|
448
|
+
src/native-agent.ts native binary selection and preparation
|
|
449
|
+
src/paths.ts pure conversion between the three path formats
|
|
450
|
+
src/picker.ts WslDirectoryPicker (ctx.directoryPicker)
|
|
451
|
+
src/ports.ts the listening-port snapshot behind DSH_WSL_PORTS
|
|
452
|
+
src/preflight.ts session-start environment advisories
|
|
453
|
+
src/preset-choice.ts whether a new session adopts the WSL preset (pure)
|
|
454
|
+
src/probe-cache.ts which probe verdicts may be remembered (pure)
|
|
455
|
+
src/sandbox.ts the distro-side bwrap confinement shared by both
|
|
456
|
+
providers, bound to the peer's failure type
|
|
457
|
+
src/sandbox-core.ts the probe-and-confinement core, free of DSH peers
|
|
458
|
+
src/search-exec.ts the agent-backed execution handle for a search
|
|
459
|
+
src/search-route.ts which execution world a search spawn belongs to (pure)
|
|
460
|
+
src/session-runtime.ts shared session runtime and agent lifecycle
|
|
461
|
+
src/session-scope.ts systemd scope creation and cleanup
|
|
462
|
+
src/shell.ts the ctx.shell subpath entry point
|
|
463
|
+
src/shell-env.ts registers the DSH_WSL_* environment variables
|
|
464
|
+
src/subprocess.ts WslSubprocessRuntime (ctx.subprocess), the GUI
|
|
465
|
+
terminal window
|
|
466
|
+
src/terminal-activity.ts the distro-side activity probe for idle terminal
|
|
467
|
+
reclamation
|
|
468
|
+
src/terminal-route.ts which execution world a terminal launch belongs to (pure)
|
|
469
|
+
src/update-check.ts the once-a-day update notice (fact store +
|
|
470
|
+
host-delegated check)
|
|
471
|
+
src/watcher.ts in-distro file watching for WslFileSystem.watch
|
|
472
|
+
src/status.ts the panel's route (distro list, one distro's
|
|
473
|
+
quick doctor, and the --fix-owned repair over /api)
|
|
474
|
+
src/wsl-doctor-command.ts the `/wsl-doctor` UI command row (spawns the
|
|
475
|
+
standalone doctor CLI)
|
|
476
|
+
src/wsl-doctor-tool.ts the `wsl_doctor` model tool row (in-process diagnosis)
|
|
477
|
+
src/wsl.ts wsl.exe interop primitives (no DSH imports)
|
|
478
|
+
```
|
|
479
|
+
|
|
480
|
+
`package.json` 只发布这棵树的一个子集:`files` 列表就是契约,条目不再匹配
|
|
481
|
+
受跟踪内容时 `pnpm run lint:style` 失败。
|
|
482
|
+
|
|
483
|
+
## 推理记录在哪里
|
|
484
|
+
|
|
485
|
+
- [`CHANGELOG.md`](../CHANGELOG.md) 记录每次发布的变化,也点名读者本来会照做
|
|
486
|
+
但已不再成立的文档。
|
|
487
|
+
- [`REQUIREMENTS.zh.md`](REQUIREMENTS.zh.md) 是需求登记册:每条成文的行为
|
|
488
|
+
承诺都有编号,并注明规定位置与验证方式,另列未完成项(中文,面向维护者,
|
|
489
|
+
随 npm 包发布)。
|
|
490
|
+
- [`archive/engineering-record.zh.md`](https://github.com/Big-Dao/dsh-plugin-wsl-env/blob/main/docs/archive/engineering-record.zh.md)
|
|
491
|
+
是完整的工程记录,中文:实测契约、调试回合,以及当时得出的结论。
|
|
492
|
+
- [`archive/README.md`](https://github.com/Big-Dao/dsh-plugin-wsl-env/blob/main/docs/archive/README.md) 和
|
|
493
|
+
[`archive/README.en.md`](https://github.com/Big-Dao/dsh-plugin-wsl-env/blob/main/docs/archive/README.en.md)
|
|
494
|
+
是同样三份归档文件的两份英文索引;后者让不读中文的读者也能知道其中有什么;
|
|
495
|
+
记录本身是中文。
|
|
496
|
+
- [`docs/README.zh.md`](README.zh.md) 与 [`README.md`](../README.md) 是当前状态的
|
|
497
|
+
陈述。
|
|
498
|
+
|
|
499
|
+
## 诊断
|
|
500
|
+
|
|
501
|
+
`pnpm run doctor`(以及 `pnpm run diagnose`)是覆盖上述全部内容的运维入口:
|
|
502
|
+
它探测 Windows/WSL 版本、发行版及其 shell、bubblewrap、systemd/Linger、
|
|
503
|
+
peer 下限、新 agent 握手和陈旧的会话 scope,并报告带版本的 `doctorReport`
|
|
504
|
+
结构(`scripts/doctor.mjs`、`lib/doctor-live.js`),每项失败附带补救方法。
|
|
505
|
+
同一份报告通过三个界面应答:这个独立 CLI(设计上无 peer 依赖,因此插件自身
|
|
506
|
+
运行时损坏时它仍能启动)、`/wsl-doctor` UI 命令(在宿主侧启动 CLI,渲染与
|
|
507
|
+
模型历史分离),以及 `wsl_doctor` 模型工具(进程内,通过 `lib/doctor-live.js`
|
|
508
|
+
合并活跃常驻 agent 的状态)。侧边栏面板以同样方式渲染快速摘要并提交修复动作
|
|
509
|
+
(`--fix-owned`:仅插件自有状态)。运行可以限定范围(CLI 上的 `--quick`、
|
|
510
|
+
`--sections <csv>`;工具上的 `depth` / `section`),报告按发行版分组逐项列出
|
|
511
|
+
每项检查。各界面与判定契约见 [DIAGNOSTICS.zh.md](DIAGNOSTICS.zh.md)。
|
package/docs/COMPATIBILITY.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# Compatibility matrix
|
|
2
2
|
|
|
3
|
+
[中文](COMPATIBILITY.zh.md)
|
|
4
|
+
|
|
3
5
|
Measured evidence for the support tiers in [`ROADMAP-1.0.md`](ROADMAP-1.0.md)
|
|
4
6
|
(WSL-202). Every row below was executed on real WSL2 distros on one machine
|
|
5
7
|
(x86_64, Windows 11, WSL 2, kernel 6.18) on **2026-10-26**, with the probe
|