dsh-plugin-wsl-env 0.17.1 → 0.19.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 +225 -0
- package/CONTRIBUTING.md +37 -5
- package/README.md +61 -6
- package/SUPPORT.md +3 -3
- package/agent/native/linux-aarch64/dsh-wsl-agent +0 -0
- package/agent/native/linux-x86_64/dsh-wsl-agent +0 -0
- package/agent/wsl-agent.sh +331 -11
- package/cordis.patch.yml +10 -5
- package/docs/AGENT-PROTOCOL-V7.md +175 -0
- package/docs/API.md +24 -0
- package/docs/ARCHITECTURE.md +20 -6
- package/docs/COMPATIBILITY.md +1 -1
- package/docs/CONFIGURATION.md +33 -5
- package/docs/CONFIGURATION.zh.md +25 -4
- package/docs/LIMITATIONS.md +39 -7
- package/docs/LIMITATIONS.zh.md +31 -6
- package/docs/MIGRATION.md +4 -4
- package/docs/PEER-PARITY.md +94 -35
- package/docs/QUICKSTART.md +19 -2
- package/docs/QUICKSTART.zh.md +16 -1
- package/docs/README.zh.md +47 -7
- package/docs/RELEASING.md +3 -2
- package/docs/REQUIREMENTS.zh.md +11 -6
- package/docs/ROADMAP-1.0.md +40 -29
- package/docs/ROADMAP.md +10 -6
- package/docs/UPSTREAM-FILE-REFERENCE-SEAM.md +6 -1
- package/docs/UPSTREAM-FSIO-EXPORT.md +2 -2
- package/docs/UPSTREAM-SERVICE-SWAP.md +124 -0
- package/docs/UPSTREAM-SESSION-NOTICE.md +3 -1
- package/docs/UPSTREAM-TERMINAL-TITLE.md +3 -0
- package/docs/root-fs-routing.md +3 -3
- package/lib/agent-confined.js +4 -4
- package/lib/agent-errors.d.ts +1 -1
- package/lib/agent-errors.js +1 -1
- package/lib/agent-exec.d.ts +1 -1
- package/lib/agent-exec.js +1 -1
- package/lib/agent-protocol.d.ts +58 -8
- package/lib/agent-protocol.js +40 -7
- package/lib/agent-shared.d.ts +1 -1
- package/lib/agent-shared.js +1 -1
- package/lib/agent.d.ts +171 -1
- package/lib/agent.js +448 -288
- package/lib/auto-preset.d.ts +1 -1
- package/lib/auto-preset.js +1 -1
- package/lib/bwrap.d.ts +1 -1
- package/lib/bwrap.js +1 -1
- package/lib/distro-route.d.ts +1 -1
- package/lib/distro-route.js +1 -1
- package/lib/doctor-live.d.ts +53 -0
- package/lib/doctor-live.js +37 -0
- package/lib/file-reference-wsl.d.ts +1 -1
- package/lib/file-reference-wsl.js +1 -1
- package/lib/fs-decisions.d.ts +1 -1
- package/lib/fs-decisions.js +1 -1
- package/lib/fs-routing.d.ts +52 -2
- package/lib/fs-routing.js +56 -1
- package/lib/fs-substrate.d.ts +90 -11
- package/lib/fs-substrate.js +202 -1
- package/lib/fs.d.ts +1 -1
- package/lib/fs.js +1 -1
- package/lib/fsio-agent.d.ts +128 -4
- package/lib/fsio-agent.js +224 -15
- package/lib/fsio-text.d.ts +1 -1
- package/lib/fsio-text.js +1 -1
- package/lib/git-exec.d.ts +1 -1
- package/lib/git-exec.js +1 -1
- package/lib/git-route.d.ts +1 -1
- package/lib/git-route.js +1 -1
- package/lib/index.d.ts +127 -3
- package/lib/index.js +301 -99
- package/lib/listing.d.ts +1 -1
- package/lib/listing.js +1 -1
- package/lib/native-agent.d.ts +1 -1
- package/lib/native-agent.js +2 -2
- package/lib/paths.d.ts +6 -3
- package/lib/paths.js +4 -4
- package/lib/picker.d.ts +1 -1
- package/lib/picker.js +7 -7
- package/lib/ports.d.ts +1 -1
- package/lib/ports.js +1 -1
- package/lib/preflight.d.ts +1 -1
- package/lib/preflight.js +1 -1
- package/lib/sandbox-core.d.ts +1 -1
- package/lib/sandbox-core.js +2 -2
- package/lib/sandbox.d.ts +1 -1
- package/lib/sandbox.js +1 -1
- package/lib/search-exec.d.ts +1 -1
- package/lib/search-exec.js +1 -1
- package/lib/search-route.d.ts +1 -1
- package/lib/search-route.js +1 -1
- package/lib/session-runtime.d.ts +1 -1
- package/lib/session-runtime.js +2 -2
- package/lib/session-scope.d.ts +1 -1
- package/lib/session-scope.js +1 -1
- package/lib/shell-env.d.ts +1 -1
- package/lib/shell-env.js +1 -1
- package/lib/shell.d.ts +1 -1
- package/lib/shell.js +1 -1
- package/lib/subprocess.d.ts +1 -1
- package/lib/subprocess.js +2 -2
- package/lib/terminal-activity.d.ts +1 -1
- package/lib/terminal-activity.js +1 -1
- package/lib/terminal-route.d.ts +1 -1
- package/lib/terminal-route.js +1 -1
- package/lib/watcher.d.ts +1 -1
- package/lib/watcher.js +1 -1
- package/lib/wsl.d.ts +1 -31
- package/lib/wsl.js +1 -21
- package/package.json +41 -28
- package/scripts/doctor.mjs +34 -11
package/docs/root-fs-routing.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
> `lib/fs-routing.js` 是其编译产物;当前开发依赖及 peer 范围以
|
|
5
5
|
> `package.json` 为准。
|
|
6
6
|
> 时效:§5 的验证与回退小节于 2026-10-31 对照现行测试与探针清单复核
|
|
7
|
-
> (组合测试 12 项、单测 4 项、真机套件
|
|
7
|
+
> (组合测试 12 项、单测 4 项、真机套件 17 项含 `fs-routing.sh`、`two-distro.sh` 与 `agent-restart.sh`,2026-11-06 复核);
|
|
8
8
|
> 其余章节保留设计时的历史表述。
|
|
9
9
|
> 关联:promotion-map 附录 C(workspace-files 接管评审)、附录 B(剩余 9P
|
|
10
10
|
> 消费者)、`docs/upstream/rfc-wsl-workspaces.md` 增补(根平面路由 fs 的
|
|
@@ -156,8 +156,8 @@ export `./fs-routing`)。config 承载两侧旋钮:宿主侧 `cwd`/`diffBasi
|
|
|
156
156
|
`distroContains`/`inputIsDistro`/`linuxJoin`);类本体改由上一项的组合测试经
|
|
157
157
|
服务代理覆盖。该文件自 2026-10-19 起已在 `test:unit` 与 `test:coverage`
|
|
158
158
|
清单里(`docs/REQUIREMENTS.zh.md` 的 OI-7,已解决)。
|
|
159
|
-
- 真机探针全套(`test/probe/run-all-when-closed.sh --include-fs`,
|
|
160
|
-
+ `run.sh` 共
|
|
159
|
+
- 真机探针全套(`test/probe/run-all-when-closed.sh --include-fs`,16 项常规
|
|
160
|
+
+ `run.sh` 共 17 项,2026-11-06 起)覆盖 agent、watch、substrate 等底座,并包含本路由的
|
|
161
161
|
`test/probe/fs-routing.sh`:临时 profile 以本路由为根 `fs`,经 UNC 坐标读
|
|
162
162
|
distro 内 ext4 文件、经盘符路径读 Windows 文件,并拒绝另一 distro 的 UNC。
|
|
163
163
|
|
package/lib/agent-confined.js
CHANGED
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
* and run `pnpm run build` — the artifact under `lib/` is generated, and
|
|
30
30
|
* `pnpm test` fails when it drifts.
|
|
31
31
|
*
|
|
32
|
-
* @module dsh-plugin-wsl/agent-confined
|
|
32
|
+
* @module dsh-plugin-wsl-env/agent-confined
|
|
33
33
|
*/
|
|
34
34
|
import { bwrapArgvPrefix } from "./bwrap.js";
|
|
35
35
|
import { toLinuxPath } from "./paths.js";
|
|
@@ -91,10 +91,10 @@ export async function runSpawnChecklist({ wslPath, distro, root, runFn }) {
|
|
|
91
91
|
}
|
|
92
92
|
const named = /workspace-root|interpreter|base64|sha256sum/.exec(detail)?.[0];
|
|
93
93
|
if (named !== undefined) {
|
|
94
|
-
throw new Error(`spawn checklist step '${named}' failed in ${distro}`);
|
|
94
|
+
throw new Error(`dsh-plugin-wsl-env: the confined spawn checklist step '${named}' failed in ${distro}`);
|
|
95
95
|
}
|
|
96
96
|
if (detail !== "") {
|
|
97
|
-
throw new Error(`spawn checklist could not run in ${distro}: ${detail.slice(0, 200)}`);
|
|
97
|
+
throw new Error(`dsh-plugin-wsl-env: the confined spawn checklist could not run in ${distro}: ${detail.slice(0, 200)}`);
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
100
|
/**
|
|
@@ -109,7 +109,7 @@ export function confinedAgent({ distro, wslPath = "wsl.exe", policy, maskWindows
|
|
|
109
109
|
const key = `${wslPath}\0${distro}\0${policy.mode}\0${policy.workspaceRoot}\0${maskWindowsDrive ? "masked" : "visible"}\0${realTmp ? "real" : "ephemeral"}`;
|
|
110
110
|
let agent = confinedAgents.get(key);
|
|
111
111
|
if (agent === undefined) {
|
|
112
|
-
const linuxRoot = toLinuxPath(policy.workspaceRoot
|
|
112
|
+
const linuxRoot = toLinuxPath(policy.workspaceRoot);
|
|
113
113
|
agent = new WslAgent({
|
|
114
114
|
distro,
|
|
115
115
|
wslPath,
|
package/lib/agent-errors.d.ts
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* and run `pnpm run build` — the artifact under `lib/` is generated, and
|
|
9
9
|
* `pnpm test` fails when it drifts.
|
|
10
10
|
*
|
|
11
|
-
* @module dsh-plugin-wsl/agent-errors
|
|
11
|
+
* @module dsh-plugin-wsl-env/agent-errors
|
|
12
12
|
*/
|
|
13
13
|
/**
|
|
14
14
|
* The abort reason the execution layer uses when its timer fires. The timeout
|
package/lib/agent-errors.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* and run `pnpm run build` — the artifact under `lib/` is generated, and
|
|
9
9
|
* `pnpm test` fails when it drifts.
|
|
10
10
|
*
|
|
11
|
-
* @module dsh-plugin-wsl/agent-errors
|
|
11
|
+
* @module dsh-plugin-wsl-env/agent-errors
|
|
12
12
|
*/
|
|
13
13
|
/**
|
|
14
14
|
* The abort reason the execution layer uses when its timer fires. The timeout
|
package/lib/agent-exec.d.ts
CHANGED
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
* run `pnpm run build` — the artifact under `lib/` is generated, and `pnpm test`
|
|
27
27
|
* fails when it drifts.
|
|
28
28
|
*
|
|
29
|
-
* @module dsh-plugin-wsl/agent-exec
|
|
29
|
+
* @module dsh-plugin-wsl-env/agent-exec
|
|
30
30
|
*/
|
|
31
31
|
/** The request one agent `exec` carries. */
|
|
32
32
|
export interface AgentExecRequest {
|
package/lib/agent-exec.js
CHANGED
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
* run `pnpm run build` — the artifact under `lib/` is generated, and `pnpm test`
|
|
27
27
|
* fails when it drifts.
|
|
28
28
|
*
|
|
29
|
-
* @module dsh-plugin-wsl/agent-exec
|
|
29
|
+
* @module dsh-plugin-wsl-env/agent-exec
|
|
30
30
|
*/
|
|
31
31
|
import { BASH_TIMEOUT_REASON, CwdError } from "./agent-errors.js";
|
|
32
32
|
/**
|
package/lib/agent-protocol.d.ts
CHANGED
|
@@ -11,10 +11,16 @@
|
|
|
11
11
|
* to `lib/agent-protocol.js`; edit THIS file and run `pnpm run build` — the
|
|
12
12
|
* artifact under `lib/` is generated, and `pnpm test` fails when it drifts.
|
|
13
13
|
*
|
|
14
|
-
* @module dsh-plugin-wsl/agent-protocol
|
|
14
|
+
* @module dsh-plugin-wsl-env/agent-protocol
|
|
15
15
|
*/
|
|
16
|
-
/** The protocol version this host side speaks
|
|
17
|
-
export declare const PROTOCOL_VERSION =
|
|
16
|
+
/** The protocol version this host side speaks. */
|
|
17
|
+
export declare const PROTOCOL_VERSION = 7;
|
|
18
|
+
/**
|
|
19
|
+
* The oldest agent protocol this host still accepts. A v6 resident keeps
|
|
20
|
+
* working: every v7 frame is gated on the HELLO version, so a half-updated
|
|
21
|
+
* mirror (one side at 6) degrades to v6 behaviour instead of desyncing.
|
|
22
|
+
*/
|
|
23
|
+
export declare const MIN_PROTOCOL_VERSION = 6;
|
|
18
24
|
/**
|
|
19
25
|
* Upper bound on one `read` op's payload, set by the HOST looping over windowed
|
|
20
26
|
* requests. Keeping each frame's decoded payload here means the agent's RES
|
|
@@ -126,9 +132,10 @@ export interface FsFrameRequest {
|
|
|
126
132
|
* count, followed by one base64 line per argument.
|
|
127
133
|
*
|
|
128
134
|
* Ops (see `agent/wsl-agent.sh` for the server side and the wire grammar):
|
|
129
|
-
* `stat`, `lstat`, `list`, `realpath`, `read`, `write
|
|
130
|
-
* EXEC `ACK`/`RES`/`ERR`
|
|
131
|
-
* the watchdog) is
|
|
135
|
+
* `stat`, `lstat`, `list`, `realpath`, `read`, `write`, and — protocol 7 —
|
|
136
|
+
* `delete` and `move`. Responses reuse the EXEC `ACK`/`RES`/`ERR`/`FSERR`
|
|
137
|
+
* lines, so the request machinery (pending map, KILL, the watchdog) is
|
|
138
|
+
* shared unchanged.
|
|
132
139
|
*
|
|
133
140
|
* The argument contract: callers pass PLAINTEXT values here; this frame is the
|
|
134
141
|
* single base64 boundary, and the agent decodes each argument once. A write's
|
|
@@ -139,8 +146,32 @@ export interface FsFrameRequest {
|
|
|
139
146
|
* @returns the lines to write to the agent's stdin, in order.
|
|
140
147
|
*/
|
|
141
148
|
export declare function encodeFsFrame({ id, op, args, timeoutMs }: FsFrameRequest): string[];
|
|
149
|
+
/** One op inside a batch frame — the same shape as an FS frame's op and args. */
|
|
150
|
+
export interface FsBatchOp {
|
|
151
|
+
/** The op name (`stat`, `lstat`, `list`, `read`, … — the FS vocabulary). */
|
|
152
|
+
op: string;
|
|
153
|
+
/** Op arguments, one wire line each. */
|
|
154
|
+
args: string[];
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Build the request lines for one batched FS frame — protocol 7. The shape is
|
|
158
|
+
* a `FSB|<id>|<timeout seconds|0>|<n ops>` header followed by `n ops` records,
|
|
159
|
+
* each an `OP|<op>|<n args>` line plus its base64 arguments. The agent runs
|
|
160
|
+
* the ops in order in ONE worker and answers with one RES whose payload is
|
|
161
|
+
* the concatenated per-op records (`OK <i>|<b64 payload>` /
|
|
162
|
+
* `BAD <i>|<reason>|<b64 message>`) — so a GUI-preview-shaped
|
|
163
|
+
* stat+list+read costs one round trip instead of four to six.
|
|
164
|
+
*
|
|
165
|
+
* @param request - the batch request: an id, a timeout and the ordered ops.
|
|
166
|
+
* @returns the lines to write to the agent's stdin, in order.
|
|
167
|
+
*/
|
|
168
|
+
export declare function encodeFsbFrame({ id, timeoutMs, ops }: {
|
|
169
|
+
id: string;
|
|
170
|
+
timeoutMs?: number;
|
|
171
|
+
ops: FsBatchOp[];
|
|
172
|
+
}): string[];
|
|
142
173
|
/**
|
|
143
|
-
* `HELLO|name|version|digest|pid` — `digest` is the sha256 of the script file
|
|
174
|
+
* `HELLO|name|version|digest|pid|caps` — `digest` is the sha256 of the script file
|
|
144
175
|
* the agent is executing (empty when it could not hash it); the host compares
|
|
145
176
|
* it against its own shipped copy. `pid` is the agent shell's PID inside the
|
|
146
177
|
* distro, present from protocol 5 on: the host uses it to deliver an
|
|
@@ -148,6 +179,12 @@ export declare function encodeFsFrame({ id, op, args, timeoutMs }: FsFrameReques
|
|
|
148
179
|
* the serial stdin loop cannot do by frame. It is absent when the agent
|
|
149
180
|
* itself runs inside a PID namespace (the confined resident), where that PID
|
|
150
181
|
* is not addressable from a second `wsl.exe`.
|
|
182
|
+
*
|
|
183
|
+
* `caps` (protocol 7) is a comma-separated capability token list — `conc`
|
|
184
|
+
* (FS ops may run concurrently and answer out of order), `batch` (the
|
|
185
|
+
* `FSB` batch frame is accepted). Absent or empty (a v6 peer, a fake)
|
|
186
|
+
* means no capabilities: the host never sends a v7 frame at a peer that
|
|
187
|
+
* did not advertise the capability.
|
|
151
188
|
*/
|
|
152
189
|
export interface HelloMessage {
|
|
153
190
|
type: "hello";
|
|
@@ -155,6 +192,7 @@ export interface HelloMessage {
|
|
|
155
192
|
version: number;
|
|
156
193
|
digest: string;
|
|
157
194
|
pid?: number;
|
|
195
|
+
caps?: string[];
|
|
158
196
|
}
|
|
159
197
|
/** `PONG` — the liveness answer to `PING`. */
|
|
160
198
|
export interface PongMessage {
|
|
@@ -190,6 +228,18 @@ export interface AgentErrorMessage {
|
|
|
190
228
|
reason: string;
|
|
191
229
|
message: string;
|
|
192
230
|
}
|
|
231
|
+
/**
|
|
232
|
+
* `FSERR|id|reason|message` — protocol 7's structured FS failure: a failed FS
|
|
233
|
+
* op answers with this line instead of (or, from an older agent, in addition
|
|
234
|
+
* to) the `dsh-fs|reason|…` first-stderr-line convention. The host maps
|
|
235
|
+
* `reason` onto the `FsErrorCode` vocabulary directly.
|
|
236
|
+
*/
|
|
237
|
+
export interface FsErrorMessage {
|
|
238
|
+
type: "fsError";
|
|
239
|
+
id: string;
|
|
240
|
+
reason: string;
|
|
241
|
+
message: string;
|
|
242
|
+
}
|
|
193
243
|
/**
|
|
194
244
|
* Any other line — never thrown; the host decides whether an unrecognized line
|
|
195
245
|
* is fatal. (Anything during the handshake is; after it, garbage on stdout is
|
|
@@ -201,7 +251,7 @@ export interface UnknownMessage {
|
|
|
201
251
|
line: string;
|
|
202
252
|
}
|
|
203
253
|
/** The line parser's verdict: the union of every message shape above. */
|
|
204
|
-
export type AgentMessage = HelloMessage | PongMessage | AckMessage | ResultMessage | AgentErrorMessage | UnknownMessage;
|
|
254
|
+
export type AgentMessage = HelloMessage | PongMessage | AckMessage | ResultMessage | AgentErrorMessage | FsErrorMessage | UnknownMessage;
|
|
205
255
|
/**
|
|
206
256
|
* Parse one line of the agent's stdout.
|
|
207
257
|
*
|
package/lib/agent-protocol.js
CHANGED
|
@@ -11,10 +11,16 @@
|
|
|
11
11
|
* to `lib/agent-protocol.js`; edit THIS file and run `pnpm run build` — the
|
|
12
12
|
* artifact under `lib/` is generated, and `pnpm test` fails when it drifts.
|
|
13
13
|
*
|
|
14
|
-
* @module dsh-plugin-wsl/agent-protocol
|
|
14
|
+
* @module dsh-plugin-wsl-env/agent-protocol
|
|
15
15
|
*/
|
|
16
|
-
/** The protocol version this host side speaks
|
|
17
|
-
export const PROTOCOL_VERSION =
|
|
16
|
+
/** The protocol version this host side speaks. */
|
|
17
|
+
export const PROTOCOL_VERSION = 7;
|
|
18
|
+
/**
|
|
19
|
+
* The oldest agent protocol this host still accepts. A v6 resident keeps
|
|
20
|
+
* working: every v7 frame is gated on the HELLO version, so a half-updated
|
|
21
|
+
* mirror (one side at 6) degrades to v6 behaviour instead of desyncing.
|
|
22
|
+
*/
|
|
23
|
+
export const MIN_PROTOCOL_VERSION = 6;
|
|
18
24
|
/**
|
|
19
25
|
* Upper bound on one `read` op's payload, set by the HOST looping over windowed
|
|
20
26
|
* requests. Keeping each frame's decoded payload here means the agent's RES
|
|
@@ -102,9 +108,10 @@ export function encodeKill(id) {
|
|
|
102
108
|
* count, followed by one base64 line per argument.
|
|
103
109
|
*
|
|
104
110
|
* Ops (see `agent/wsl-agent.sh` for the server side and the wire grammar):
|
|
105
|
-
* `stat`, `lstat`, `list`, `realpath`, `read`, `write
|
|
106
|
-
* EXEC `ACK`/`RES`/`ERR`
|
|
107
|
-
* the watchdog) is
|
|
111
|
+
* `stat`, `lstat`, `list`, `realpath`, `read`, `write`, and — protocol 7 —
|
|
112
|
+
* `delete` and `move`. Responses reuse the EXEC `ACK`/`RES`/`ERR`/`FSERR`
|
|
113
|
+
* lines, so the request machinery (pending map, KILL, the watchdog) is
|
|
114
|
+
* shared unchanged.
|
|
108
115
|
*
|
|
109
116
|
* The argument contract: callers pass PLAINTEXT values here; this frame is the
|
|
110
117
|
* single base64 boundary, and the agent decodes each argument once. A write's
|
|
@@ -121,6 +128,27 @@ export function encodeFsFrame({ id, op, args, timeoutMs = 0 }) {
|
|
|
121
128
|
...args.map((word) => encodeB64(word)),
|
|
122
129
|
];
|
|
123
130
|
}
|
|
131
|
+
/**
|
|
132
|
+
* Build the request lines for one batched FS frame — protocol 7. The shape is
|
|
133
|
+
* a `FSB|<id>|<timeout seconds|0>|<n ops>` header followed by `n ops` records,
|
|
134
|
+
* each an `OP|<op>|<n args>` line plus its base64 arguments. The agent runs
|
|
135
|
+
* the ops in order in ONE worker and answers with one RES whose payload is
|
|
136
|
+
* the concatenated per-op records (`OK <i>|<b64 payload>` /
|
|
137
|
+
* `BAD <i>|<reason>|<b64 message>`) — so a GUI-preview-shaped
|
|
138
|
+
* stat+list+read costs one round trip instead of four to six.
|
|
139
|
+
*
|
|
140
|
+
* @param request - the batch request: an id, a timeout and the ordered ops.
|
|
141
|
+
* @returns the lines to write to the agent's stdin, in order.
|
|
142
|
+
*/
|
|
143
|
+
export function encodeFsbFrame({ id, timeoutMs = 0, ops }) {
|
|
144
|
+
const timeoutSeconds = timeoutMs > 0 ? Math.ceil(timeoutMs / 1000) : 0;
|
|
145
|
+
const lines = [`FSB|${id}|${timeoutSeconds}|${ops.length}`];
|
|
146
|
+
for (const { op, args } of ops) {
|
|
147
|
+
lines.push(`OP|${op}|${args.length}`);
|
|
148
|
+
lines.push(...args.map((word) => encodeB64(word)));
|
|
149
|
+
}
|
|
150
|
+
return lines;
|
|
151
|
+
}
|
|
124
152
|
/**
|
|
125
153
|
* Parse one line of the agent's stdout.
|
|
126
154
|
*
|
|
@@ -129,7 +157,7 @@ export function encodeFsFrame({ id, op, args, timeoutMs = 0 }) {
|
|
|
129
157
|
*/
|
|
130
158
|
export function parseAgentLine(line) {
|
|
131
159
|
if (line.startsWith("HELLO|")) {
|
|
132
|
-
const [, name, version, digest, pid] = line.split("|");
|
|
160
|
+
const [, name, version, digest, pid, caps] = line.split("|");
|
|
133
161
|
const agentPid = Number(pid);
|
|
134
162
|
return {
|
|
135
163
|
type: "hello",
|
|
@@ -137,6 +165,7 @@ export function parseAgentLine(line) {
|
|
|
137
165
|
version: Number(version),
|
|
138
166
|
digest: digest ?? "",
|
|
139
167
|
...(Number.isSafeInteger(agentPid) && agentPid > 0 ? { pid: agentPid } : {}),
|
|
168
|
+
...(caps !== undefined && caps.length > 0 ? { caps: caps.split(",").filter((token) => token.length > 0) } : {}),
|
|
140
169
|
};
|
|
141
170
|
}
|
|
142
171
|
if (line === "PONG")
|
|
@@ -163,5 +192,9 @@ export function parseAgentLine(line) {
|
|
|
163
192
|
const [, id, reason, message] = line.split("|");
|
|
164
193
|
return { type: "agentError", id: id ?? "", reason: reason ?? "protocol", message: decodeB64(message ?? "").toString("utf8") };
|
|
165
194
|
}
|
|
195
|
+
if (line.startsWith("FSERR|")) {
|
|
196
|
+
const [, id, reason, message] = line.split("|");
|
|
197
|
+
return { type: "fsError", id: id ?? "", reason: reason ?? "io", message: decodeB64(message ?? "").toString("utf8") };
|
|
198
|
+
}
|
|
166
199
|
return { type: "unknown", line };
|
|
167
200
|
}
|
package/lib/agent-shared.d.ts
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* and run `pnpm run build` — the artifact under `lib/` is generated, and
|
|
12
12
|
* `pnpm test` fails when it drifts.
|
|
13
13
|
*
|
|
14
|
-
* @module dsh-plugin-wsl/agent-shared
|
|
14
|
+
* @module dsh-plugin-wsl-env/agent-shared
|
|
15
15
|
*/
|
|
16
16
|
import { WslAgent } from "./agent.js";
|
|
17
17
|
/** The agent script as a host-side path, for factories that need both spellings. */
|
package/lib/agent-shared.js
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* and run `pnpm run build` — the artifact under `lib/` is generated, and
|
|
12
12
|
* `pnpm test` fails when it drifts.
|
|
13
13
|
*
|
|
14
|
-
* @module dsh-plugin-wsl/agent-shared
|
|
14
|
+
* @module dsh-plugin-wsl-env/agent-shared
|
|
15
15
|
*/
|
|
16
16
|
import { createHash } from "node:crypto";
|
|
17
17
|
import { spawn } from "node:child_process";
|
package/lib/agent.d.ts
CHANGED
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
* `pnpm run build` — the artifact under `lib/` is generated, and `pnpm test`
|
|
38
38
|
* fails when it drifts.
|
|
39
39
|
*
|
|
40
|
-
* @module dsh-plugin-wsl/agent
|
|
40
|
+
* @module dsh-plugin-wsl-env/agent
|
|
41
41
|
*/
|
|
42
42
|
import type { ChildProcess } from "node:child_process";
|
|
43
43
|
/** One settled command result, as `exec` resolves it. */
|
|
@@ -53,6 +53,12 @@ export interface ExecResult {
|
|
|
53
53
|
stdout: boolean;
|
|
54
54
|
stderr: boolean;
|
|
55
55
|
};
|
|
56
|
+
/**
|
|
57
|
+
* Protocol 7's FS refusal token (`notfound`, `stale`, …), present only on a
|
|
58
|
+
* failed FS op answered with the structured FSERR line. FS consumers map it
|
|
59
|
+
* onto `FsErrorCode` directly; command results never carry one.
|
|
60
|
+
*/
|
|
61
|
+
reason?: string;
|
|
56
62
|
}
|
|
57
63
|
/**
|
|
58
64
|
* One request in flight on an agent: its frame, its settlement callbacks, and
|
|
@@ -248,6 +254,10 @@ export declare class WslAgent {
|
|
|
248
254
|
process: ChildProcess | null;
|
|
249
255
|
/** The lifecycle state. */
|
|
250
256
|
state: "idle" | "starting" | "ready" | "dead";
|
|
257
|
+
/** The protocol version the resident announced in HELLO (0 before one). */
|
|
258
|
+
protocolVersion: number;
|
|
259
|
+
/** The capabilities the resident advertised in HELLO (`conc`, `batch`). */
|
|
260
|
+
caps: Set<string>;
|
|
251
261
|
/** The in-flight start, shared by concurrent callers. */
|
|
252
262
|
startPromise: Promise<void> | null;
|
|
253
263
|
/** The in-flight start's settler, so close() can fail a start it interrupts. */
|
|
@@ -392,6 +402,29 @@ export declare class WslAgent {
|
|
|
392
402
|
* @returns resolved once the state is `ready`.
|
|
393
403
|
*/
|
|
394
404
|
private beginStart;
|
|
405
|
+
/**
|
|
406
|
+
* The transport's failure and exit wiring, in the order the spawn attaches
|
|
407
|
+
* it: a spawn error, the stdin EPIPE guard, the handshake stderr tail, the
|
|
408
|
+
* exit handler, the stdout reader, then the diagnostic stderr reader.
|
|
409
|
+
*
|
|
410
|
+
* @param child - the freshly spawned transport.
|
|
411
|
+
* @param current - whether this child is still the current generation.
|
|
412
|
+
* @param settleStart - the handshake settler.
|
|
413
|
+
* @param handshakeTimer - the handshake watchdog.
|
|
414
|
+
*/
|
|
415
|
+
private wireAgentProcess;
|
|
416
|
+
/**
|
|
417
|
+
* The stdout line splitter: a bounded buffer instead of readline, which
|
|
418
|
+
* accumulates an over-long line whole before anyone can object — exactly the
|
|
419
|
+
* unbounded-capture hole. Protocol lines are ASCII by construction (ids,
|
|
420
|
+
* numbers, base64), so chunk-boundary decoding is not a concern.
|
|
421
|
+
*
|
|
422
|
+
* @param child - the transport to read.
|
|
423
|
+
* @param current - whether this child is still the current generation.
|
|
424
|
+
* @param settleStart - the handshake settler.
|
|
425
|
+
* @param handshakeTimer - the handshake watchdog.
|
|
426
|
+
*/
|
|
427
|
+
private readAgentOutput;
|
|
395
428
|
/**
|
|
396
429
|
* One stdout line from the agent. The first must be a matching HELLO.
|
|
397
430
|
*
|
|
@@ -400,6 +433,71 @@ export declare class WslAgent {
|
|
|
400
433
|
* @param handshakeTimer - the handshake watchdog.
|
|
401
434
|
*/
|
|
402
435
|
private handleLine;
|
|
436
|
+
/**
|
|
437
|
+
* The agent named itself. A refusal settles BEFORE killing: the exit event
|
|
438
|
+
* must not overwrite the real reason with the generic handshake message (the
|
|
439
|
+
* fake transports emit exit synchronously inside kill(); a real wsl.exe races
|
|
440
|
+
* it).
|
|
441
|
+
*
|
|
442
|
+
* @param message - the agent's HELLO.
|
|
443
|
+
* @param settleStart - the handshake settler.
|
|
444
|
+
* @param handshakeTimer - the handshake watchdog.
|
|
445
|
+
*/
|
|
446
|
+
private acceptHandshake;
|
|
447
|
+
/**
|
|
448
|
+
* Why this HELLO is refused, or undefined when it is accepted: the name and
|
|
449
|
+
* version window first, then the digest of the script the distro actually
|
|
450
|
+
* read.
|
|
451
|
+
*
|
|
452
|
+
* @param message - the agent's HELLO.
|
|
453
|
+
* @returns the refusal reason, or undefined when the handshake is accepted.
|
|
454
|
+
*/
|
|
455
|
+
private handshakeRefusal;
|
|
456
|
+
/**
|
|
457
|
+
* The agent dequeued this request: start its own budget clock NOW. Armed
|
|
458
|
+
* here instead of at submission, a queued request can no longer time out on
|
|
459
|
+
* a queue it never chose to join — and its watchdog can never kill the
|
|
460
|
+
* shared transport for a stall that was never its own. A request cancelled
|
|
461
|
+
* while it was queued is killed only now, when it is the one running.
|
|
462
|
+
*
|
|
463
|
+
* @param message - the agent's ACK.
|
|
464
|
+
*/
|
|
465
|
+
private acceptAck;
|
|
466
|
+
/**
|
|
467
|
+
* Take the entry an answer settles, running the bookkeeping every answer
|
|
468
|
+
* shares: mark it answered, release its timers, drop it from the map, and
|
|
469
|
+
* move the queue on. An answer for an entry the caller already gave up on is
|
|
470
|
+
* noise: it cleans up and settles nothing.
|
|
471
|
+
*
|
|
472
|
+
* @param id - the request id the answer names.
|
|
473
|
+
* @returns the entry to settle, or undefined when there is nothing to settle.
|
|
474
|
+
*/
|
|
475
|
+
private takeAnswered;
|
|
476
|
+
/**
|
|
477
|
+
* Settle a normal answer. A cancelled request keeps its entry only until this
|
|
478
|
+
* answer arrives.
|
|
479
|
+
*
|
|
480
|
+
* @param message - the agent's RES.
|
|
481
|
+
*/
|
|
482
|
+
private settleResult;
|
|
483
|
+
/**
|
|
484
|
+
* Protocol 7's structured FS refusal: settle the pending FS request with the
|
|
485
|
+
* reason preserved, so the adapter maps the code directly instead of sniffing
|
|
486
|
+
* a synthesized stderr line.
|
|
487
|
+
*
|
|
488
|
+
* @param message - the agent's FSERR.
|
|
489
|
+
*/
|
|
490
|
+
private settleFsError;
|
|
491
|
+
/**
|
|
492
|
+
* A refused request. A cwd rejection is the command's own failure, not the
|
|
493
|
+
* agent's — it becomes a CwdError so the execution layer can report it
|
|
494
|
+
* exactly like the one-shot path's relay text. A `spawn` rejection is the
|
|
495
|
+
* same class of failure on the native agent (it cannot distinguish a missing
|
|
496
|
+
* workdir), so it gets its own class and the executor retries it one-shot.
|
|
497
|
+
*
|
|
498
|
+
* @param message - the agent's ERR.
|
|
499
|
+
*/
|
|
500
|
+
private settleAgentError;
|
|
403
501
|
/**
|
|
404
502
|
* The process died. Requests in flight ride exactly one rebuild; a second
|
|
405
503
|
* death is permanent.
|
|
@@ -409,6 +507,33 @@ export declare class WslAgent {
|
|
|
409
507
|
* @param signalName - the killing signal, null on a normal exit.
|
|
410
508
|
*/
|
|
411
509
|
private handleProcessExit;
|
|
510
|
+
/**
|
|
511
|
+
* Sort the requests a dead transport left behind into the three fates the
|
|
512
|
+
* one rebuild allows. Only provably read-only FS requests ride it: whatever
|
|
513
|
+
* their first execution did, it changed nothing. A command or a write that
|
|
514
|
+
* was in flight has UNKNOWN state — replaying it would run non-idempotent
|
|
515
|
+
* work a second time, or report a guarded create that actually succeeded as a
|
|
516
|
+
* refusal — so it fails with that fact instead. An aborted or unsent entry
|
|
517
|
+
* was already answered, or never ran, and settles locally.
|
|
518
|
+
*
|
|
519
|
+
* @param carrying - the entries taken off the map before the rebuild.
|
|
520
|
+
* @returns the entries that ride the rebuild.
|
|
521
|
+
*/
|
|
522
|
+
private partitionForRebuild;
|
|
523
|
+
/**
|
|
524
|
+
* Start the rebuild and hand it the replayable requests under fresh ids.
|
|
525
|
+
* A stale watchdog must not survive the rebuild: its closure kills
|
|
526
|
+
* `this.process`, which is by then the NEW transport.
|
|
527
|
+
*
|
|
528
|
+
* @param relayable - the requests `partitionForRebuild` cleared to replay.
|
|
529
|
+
*/
|
|
530
|
+
private relayOverRebuild;
|
|
531
|
+
/**
|
|
532
|
+
* Fail every entry still on the map: the second death is permanent.
|
|
533
|
+
*
|
|
534
|
+
* @param message - the reason, already stored as `lastError`.
|
|
535
|
+
*/
|
|
536
|
+
private rejectAllPending;
|
|
412
537
|
/**
|
|
413
538
|
* Register one request's pending entry and write its frame: the shared
|
|
414
539
|
* request machinery (abort, submission, the ACK-armed watchdog). The
|
|
@@ -420,6 +545,25 @@ export declare class WslAgent {
|
|
|
420
545
|
* @param request - the request to register.
|
|
421
546
|
*/
|
|
422
547
|
private track;
|
|
548
|
+
/**
|
|
549
|
+
* Build one pending entry: the caller's settle wrappers (which record the
|
|
550
|
+
* metric once) and, when the request carries a budget, the stuck-request
|
|
551
|
+
* watchdog armed by the agent's ACK.
|
|
552
|
+
*
|
|
553
|
+
* @param request - the request being tracked.
|
|
554
|
+
* @param kind - the metric bucket, with the caller's default resolved.
|
|
555
|
+
* @returns the entry, not yet registered.
|
|
556
|
+
*/
|
|
557
|
+
private newPendingRequest;
|
|
558
|
+
/**
|
|
559
|
+
* Wire the caller's abort. An unsent request dies immediately; a sent one
|
|
560
|
+
* writes the KILL frame and, when the request is running, arms the signal
|
|
561
|
+
* that interrupts the command where it lives.
|
|
562
|
+
*
|
|
563
|
+
* @param pending - the tracked request.
|
|
564
|
+
* @param signal - the caller's cancellation.
|
|
565
|
+
*/
|
|
566
|
+
private attachCancellation;
|
|
423
567
|
/** Send a tracked request, recording dispatch before synchronous responses. */
|
|
424
568
|
private sendPending;
|
|
425
569
|
/** Dispatch the next shell request only after the preceding answer. */
|
|
@@ -502,6 +646,32 @@ export declare class WslAgent {
|
|
|
502
646
|
exitCode: number;
|
|
503
647
|
stdout: Buffer;
|
|
504
648
|
stderr: Buffer;
|
|
649
|
+
reason?: string;
|
|
650
|
+
}>;
|
|
651
|
+
/**
|
|
652
|
+
* Run one batched FS frame (protocol 7): the ordered ops execute in one
|
|
653
|
+
* worker and the resolution is ONE result whose stdout is the per-op
|
|
654
|
+
* record stream (`OK <i>|<b64>` / `BAD <i>|<reason>|<b64>`). The host sends
|
|
655
|
+
* this only to a resident that advertised `batch`; `DistroFs` gates it.
|
|
656
|
+
*
|
|
657
|
+
* @param request - the batch request.
|
|
658
|
+
* @returns the settled batch result.
|
|
659
|
+
*/
|
|
660
|
+
fsb({ ops, timeoutMs, signal }: {
|
|
661
|
+
/** The ordered ops, each `{ op, args }` in the FS vocabulary. */
|
|
662
|
+
ops: Array<{
|
|
663
|
+
op: string;
|
|
664
|
+
args: string[];
|
|
665
|
+
}>;
|
|
666
|
+
/** In-distro timeout from the dequeue ACK; `<= 0` means none. */
|
|
667
|
+
timeoutMs?: number;
|
|
668
|
+
/** Cancels the request, sending KILL if it was already dispatched. */
|
|
669
|
+
signal?: AbortSignal;
|
|
670
|
+
}): Promise<{
|
|
671
|
+
exitCode: number;
|
|
672
|
+
stdout: Buffer;
|
|
673
|
+
stderr: Buffer;
|
|
674
|
+
reason?: string;
|
|
505
675
|
}>;
|
|
506
676
|
/**
|
|
507
677
|
* Liveness probe, also used to warm the agent up.
|