dsh-plugin-wsl-env 0.23.1 → 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 +212 -0
- package/README.md +9 -5
- package/SECURITY.md +10 -0
- package/client.js +974 -165
- package/cordis.patch.yml +28 -3
- package/docs/API.md +2 -1
- package/docs/ARCHITECTURE.md +36 -13
- package/docs/COMPATIBILITY.md +5 -0
- package/docs/CONFIGURATION.md +80 -9
- package/docs/CONFIGURATION.zh.md +64 -8
- package/docs/DIAGNOSTICS.md +48 -20
- package/docs/DIAGNOSTICS.zh.md +36 -14
- package/docs/LIMITATIONS.md +36 -9
- package/docs/LIMITATIONS.zh.md +26 -7
- package/docs/MIGRATION.md +1 -1
- package/docs/PEER-PARITY.md +4 -4
- package/docs/QUICKSTART.md +42 -12
- package/docs/QUICKSTART.zh.md +29 -8
- package/docs/README.zh.md +9 -5
- package/docs/RELEASING.md +17 -13
- package/docs/REQUIREMENTS.zh.md +5 -4
- 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/auto-preset.d.ts +27 -0
- package/lib/auto-preset.js +40 -3
- package/lib/bwrap.d.ts +14 -0
- package/lib/bwrap.js +11 -0
- package/lib/client-host.d.ts +2 -2
- package/lib/client-host.js +2 -2
- 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/listing.d.ts +21 -9
- package/lib/listing.js +25 -21
- package/lib/messages.d.ts +1 -1
- package/lib/messages.js +3 -3
- package/lib/picker.d.ts +50 -16
- package/lib/picker.js +103 -23
- package/lib/preflight.d.ts +7 -4
- package/lib/preflight.js +27 -13
- package/lib/preset-choice.d.ts +22 -3
- package/lib/preset-choice.js +36 -3
- 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.d.ts +261 -0
- package/lib/status.js +425 -0
- package/lib/writable-roots.d.ts +109 -0
- package/lib/writable-roots.js +257 -0
- package/lib/wsl-doctor-tool.d.ts +8 -0
- package/lib/wsl-doctor-tool.js +18 -20
- 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 +13 -1
- package/lib/wsl.js +16 -1
- package/locale/doctor/en.json +3 -2
- package/locale/doctor/zh.json +3 -2
- package/package.json +12 -4
- package/scripts/doctor.mjs +436 -226
- package/scripts/profile-preset.mjs +17 -5
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) => {
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { AgentStatus } from "./agent.js";
|
|
2
|
+
import { type DoctorReport } from "./doctor-live.js";
|
|
3
|
+
/**
|
|
4
|
+
* Collect the doctor's versioned JSON report and merge the live resident's
|
|
5
|
+
* own lifecycle facts when this process holds one (WSL-313).
|
|
6
|
+
*
|
|
7
|
+
* The doctor CLI is a separate process, so its handshake check can only probe
|
|
8
|
+
* a fresh resident; a live resident's `deaths` and `lastError` are
|
|
9
|
+
* host-process state with no IPC to reach them. This entry point runs from
|
|
10
|
+
* the plugin's own context instead: it collects the report as a subprocess
|
|
11
|
+
* (no plugin code is re-entered) and folds `sharedAgent(distro).status()` in
|
|
12
|
+
* — the sanctioned merge, since a snapshot that answers for no resident
|
|
13
|
+
* changes nothing. Outside the app the singleton was never started, so the
|
|
14
|
+
* returned report is the fresh probe verbatim; inside it, a wedged live
|
|
15
|
+
* resident's failures finally reach the report.
|
|
16
|
+
*
|
|
17
|
+
* @param distro - the distro the doctor examines.
|
|
18
|
+
* @param options - `doctorPath` overrides the shipped script (tests);
|
|
19
|
+
* `timeoutMs` bounds the run; `signal` lets the caller cancel it;
|
|
20
|
+
* `liveStatus` overrides the in-process status snapshot (tests).
|
|
21
|
+
* @returns the merged report.
|
|
22
|
+
*/
|
|
23
|
+
export declare function doctorReport(distro: string, options?: {
|
|
24
|
+
doctorPath?: string;
|
|
25
|
+
/** The `wsl.exe` the doctor probes with; forwarded as `--wsl <path>`. */
|
|
26
|
+
wslPath?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Run the quick profile instead of the full scan: first-command
|
|
29
|
+
* prerequisites only (host/session/sandbox, no smokes, no registry query,
|
|
30
|
+
* no port survey) — forwarded as `--quick`.
|
|
31
|
+
*/
|
|
32
|
+
quick?: boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Restrict the run to these doctor sections (host, sandbox, session, conf,
|
|
35
|
+
* net, agent); forwarded as `--sections <csv>`. Undefined runs everything.
|
|
36
|
+
*/
|
|
37
|
+
sections?: readonly string[];
|
|
38
|
+
/**
|
|
39
|
+
* Prepended to the doctor subprocess's PATH — a caller that stages a fake
|
|
40
|
+
* `wsl.exe` (tests) passes the staging directory here instead of mutating
|
|
41
|
+
* `process.env`, whose visibility across spawned grandchildren is exactly
|
|
42
|
+
* the ambiguity this option removes.
|
|
43
|
+
*/
|
|
44
|
+
envPath?: string;
|
|
45
|
+
/** Hard deadline for the subprocess; defaults to two minutes. */
|
|
46
|
+
timeoutMs?: number;
|
|
47
|
+
/** The caller's cancellation (the tool's `exec.signal`); aborts the child. */
|
|
48
|
+
signal?: AbortSignal;
|
|
49
|
+
liveStatus?: AgentStatus;
|
|
50
|
+
}): Promise<DoctorReport>;
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { sharedAgent } from "./agent-shared.js";
|
|
2
|
+
import { mergeLiveResidentStatus } from "./doctor-live.js";
|
|
3
|
+
import { spawn } from "node:child_process";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import { dirname, join } from "node:path";
|
|
6
|
+
/** The doctor script this package ships, resolved from the compiled module. */
|
|
7
|
+
const DOCTOR_SCRIPT = join(dirname(fileURLToPath(import.meta.url)), "..", "scripts", "doctor.mjs");
|
|
8
|
+
/** How long the doctor subprocess may run before the collector kills it. */
|
|
9
|
+
const DOCTOR_TIMEOUT_MS = 120_000;
|
|
10
|
+
/**
|
|
11
|
+
* How much of one doctor stream the collector retains. The `--json` report is
|
|
12
|
+
* a few dozen KiB; the cap exists so a runaway child cannot grow the Host's
|
|
13
|
+
* memory without bound.
|
|
14
|
+
*/
|
|
15
|
+
const DOCTOR_OUTPUT_LIMIT_BYTES = 4 * 1024 * 1024;
|
|
16
|
+
/**
|
|
17
|
+
* How long after the doctor exits the collector waits for its pipes. A
|
|
18
|
+
* grandchild that inherited the pipes can keep them open forever; the report
|
|
19
|
+
* on stdout is complete once the doctor itself has exited, so the wait is
|
|
20
|
+
* bounded instead of following the pipes to EOF.
|
|
21
|
+
*/
|
|
22
|
+
const DOCTOR_DRAIN_GRACE_MS = 500;
|
|
23
|
+
/**
|
|
24
|
+
* Run the doctor CLI asynchronously and collect its streams.
|
|
25
|
+
*
|
|
26
|
+
* `spawnSync` would block the Host's event loop for the whole run — up to the
|
|
27
|
+
* deadline, with no way to cancel and every other tool stalled behind it — so
|
|
28
|
+
* the collector spawns, arms a deadline and the caller's abort signal, and
|
|
29
|
+
* settles on the child's exit plus a bounded drain window. A grandchild that
|
|
30
|
+
* inherits the pipes cannot hold the collector past that window.
|
|
31
|
+
*
|
|
32
|
+
* @param argv - the node argv (script path first).
|
|
33
|
+
* @param options - the child env, the deadline, and the caller's signal.
|
|
34
|
+
* @returns the finished run, including the spawn failure when it never started.
|
|
35
|
+
*/
|
|
36
|
+
function runDoctorProcess(argv, options) {
|
|
37
|
+
return new Promise((resolvePromise) => {
|
|
38
|
+
let stdout = "";
|
|
39
|
+
let stderr = "";
|
|
40
|
+
let timedOut = false;
|
|
41
|
+
let overLimit = false;
|
|
42
|
+
let spawnError;
|
|
43
|
+
let exit;
|
|
44
|
+
let drainTimer;
|
|
45
|
+
let settled = false;
|
|
46
|
+
const child = spawn(process.execPath, argv, {
|
|
47
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
48
|
+
windowsHide: true,
|
|
49
|
+
...(options.env === undefined ? {} : { env: options.env }),
|
|
50
|
+
...(options.signal === undefined ? {} : { signal: options.signal }),
|
|
51
|
+
});
|
|
52
|
+
const settle = () => {
|
|
53
|
+
if (settled)
|
|
54
|
+
return;
|
|
55
|
+
settled = true;
|
|
56
|
+
clearTimeout(deadlineTimer);
|
|
57
|
+
if (drainTimer !== undefined)
|
|
58
|
+
clearTimeout(drainTimer);
|
|
59
|
+
resolvePromise({
|
|
60
|
+
stdout,
|
|
61
|
+
stderr,
|
|
62
|
+
status: exit?.status ?? null,
|
|
63
|
+
signal: exit?.signal ?? null,
|
|
64
|
+
timedOut,
|
|
65
|
+
overLimit,
|
|
66
|
+
...(spawnError === undefined ? {} : { spawnError }),
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
const kill = () => {
|
|
70
|
+
try {
|
|
71
|
+
child.kill();
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
// An already-exited child: the exit handler settles the run.
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
const deadlineTimer = setTimeout(() => {
|
|
78
|
+
timedOut = true;
|
|
79
|
+
kill();
|
|
80
|
+
}, options.timeoutMs);
|
|
81
|
+
const capture = (chunk, which) => {
|
|
82
|
+
if (settled)
|
|
83
|
+
return;
|
|
84
|
+
if (which === "stdout")
|
|
85
|
+
stdout += chunk;
|
|
86
|
+
else
|
|
87
|
+
stderr += chunk;
|
|
88
|
+
if (stdout.length + stderr.length > DOCTOR_OUTPUT_LIMIT_BYTES) {
|
|
89
|
+
overLimit = true;
|
|
90
|
+
kill();
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
child.stdout?.on("data", (chunk) => capture(chunk.toString("utf8"), "stdout"));
|
|
94
|
+
child.stderr?.on("data", (chunk) => capture(chunk.toString("utf8"), "stderr"));
|
|
95
|
+
child.on("error", (error) => {
|
|
96
|
+
// A spawn failure never reaches `exit`; an abort is reported with the
|
|
97
|
+
// same event, so the marker is normalized into a plain message.
|
|
98
|
+
spawnError = error.name === "AbortError"
|
|
99
|
+
? new Error("doctor run aborted")
|
|
100
|
+
: error;
|
|
101
|
+
if (exit === undefined)
|
|
102
|
+
settle();
|
|
103
|
+
});
|
|
104
|
+
child.on("exit", (code, signalName) => {
|
|
105
|
+
exit = { status: code, signal: signalName ?? null };
|
|
106
|
+
// The report is complete at exit; give the pipes one bounded window to
|
|
107
|
+
// flush (a grandchild holding them must not stall the collector).
|
|
108
|
+
drainTimer = setTimeout(settle, DOCTOR_DRAIN_GRACE_MS);
|
|
109
|
+
});
|
|
110
|
+
child.on("close", () => {
|
|
111
|
+
if (exit !== undefined)
|
|
112
|
+
settle();
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Collect the doctor's versioned JSON report and merge the live resident's
|
|
118
|
+
* own lifecycle facts when this process holds one (WSL-313).
|
|
119
|
+
*
|
|
120
|
+
* The doctor CLI is a separate process, so its handshake check can only probe
|
|
121
|
+
* a fresh resident; a live resident's `deaths` and `lastError` are
|
|
122
|
+
* host-process state with no IPC to reach them. This entry point runs from
|
|
123
|
+
* the plugin's own context instead: it collects the report as a subprocess
|
|
124
|
+
* (no plugin code is re-entered) and folds `sharedAgent(distro).status()` in
|
|
125
|
+
* — the sanctioned merge, since a snapshot that answers for no resident
|
|
126
|
+
* changes nothing. Outside the app the singleton was never started, so the
|
|
127
|
+
* returned report is the fresh probe verbatim; inside it, a wedged live
|
|
128
|
+
* resident's failures finally reach the report.
|
|
129
|
+
*
|
|
130
|
+
* @param distro - the distro the doctor examines.
|
|
131
|
+
* @param options - `doctorPath` overrides the shipped script (tests);
|
|
132
|
+
* `timeoutMs` bounds the run; `signal` lets the caller cancel it;
|
|
133
|
+
* `liveStatus` overrides the in-process status snapshot (tests).
|
|
134
|
+
* @returns the merged report.
|
|
135
|
+
*/
|
|
136
|
+
export async function doctorReport(distro, options) {
|
|
137
|
+
const script = options?.doctorPath ?? DOCTOR_SCRIPT;
|
|
138
|
+
const argv = [script, distro, "--json"];
|
|
139
|
+
if (options?.quick === true)
|
|
140
|
+
argv.push("--quick");
|
|
141
|
+
if (options?.sections !== undefined && options.sections.length > 0)
|
|
142
|
+
argv.push("--sections", [...options.sections].join(","));
|
|
143
|
+
if (options?.wslPath !== undefined)
|
|
144
|
+
argv.push("--wsl", options.wslPath);
|
|
145
|
+
// A nonzero doctor exit usually means an environment check FAILED on the
|
|
146
|
+
// machine being examined — that is a valid report, not a broken collection.
|
|
147
|
+
// The stdout is parsed regardless; only a run that produced no versioned
|
|
148
|
+
// report rejects.
|
|
149
|
+
const timeoutMs = options?.timeoutMs ?? DOCTOR_TIMEOUT_MS;
|
|
150
|
+
const run = await runDoctorProcess(argv, {
|
|
151
|
+
timeoutMs,
|
|
152
|
+
...(options?.envPath !== undefined ? { env: { ...process.env, PATH: `${options.envPath}:${process.env.PATH ?? ""}` } } : {}),
|
|
153
|
+
...(options?.signal === undefined ? {} : { signal: options.signal }),
|
|
154
|
+
});
|
|
155
|
+
let report;
|
|
156
|
+
try {
|
|
157
|
+
report = JSON.parse(run.stdout);
|
|
158
|
+
}
|
|
159
|
+
catch {
|
|
160
|
+
// A run that produced no report rejects, naming the transport failure
|
|
161
|
+
// (spawn error, deadline, output cap, exit) and any stderr tail.
|
|
162
|
+
const cause = run.spawnError?.message
|
|
163
|
+
?? (run.timedOut
|
|
164
|
+
? `timed out after ${timeoutMs}ms`
|
|
165
|
+
: run.overLimit
|
|
166
|
+
? `produced more than ${DOCTOR_OUTPUT_LIMIT_BYTES} bytes`
|
|
167
|
+
: `exited with code ${run.status ?? run.signal ?? "unknown"}`);
|
|
168
|
+
throw new Error(`doctor run failed: ${cause}${run.stderr.length > 0 ? ` — ${run.stderr.trim().slice(-400)}` : ""}`);
|
|
169
|
+
}
|
|
170
|
+
const status = options?.liveStatus ?? sharedAgent(distro).status();
|
|
171
|
+
return mergeLiveResidentStatus(report, status);
|
|
172
|
+
}
|
package/lib/fs-routing.d.ts
CHANGED
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
*/
|
|
33
33
|
import z from "@deepseek-ai/schemastery";
|
|
34
34
|
import { LocalFileSystem } from "@deepseek-ai/dsh-fs-local";
|
|
35
|
-
import { WslFileSystem } from "./
|
|
35
|
+
import { WslFileSystem } from "./wsl-filesystem.js";
|
|
36
36
|
import type { Context } from "@deepseek-ai/cordis";
|
|
37
37
|
import type { FileSystem, FsEditRequest, FsTarget, FsVersion, FsWriteIntent } from "@deepseek-ai/dsh-fs";
|
|
38
38
|
import type { SandboxExecutionPolicy } from "@deepseek-ai/dsh-sandbox";
|
package/lib/fs-routing.js
CHANGED
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
import { isWslUnc, uncToPosix } from "./paths.js";
|
|
34
34
|
import z from "@deepseek-ai/schemastery";
|
|
35
35
|
import { LocalFileSystem } from "@deepseek-ai/dsh-fs-local";
|
|
36
|
-
import { WslFileSystem } from "./
|
|
36
|
+
import { WslFileSystem } from "./wsl-filesystem.js";
|
|
37
37
|
/**
|
|
38
38
|
* Whether a resolved target identity belongs to the distro.
|
|
39
39
|
*
|
package/lib/fs.d.ts
CHANGED
package/lib/fs.js
CHANGED