dsh-plugin-wsl-env 0.24.0 → 0.25.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/CHANGELOG.md +52 -0
  2. package/README.md +6 -3
  3. package/SECURITY.md +10 -0
  4. package/cordis.patch.yml +4 -0
  5. package/docs/ARCHITECTURE.md +28 -9
  6. package/docs/CONFIGURATION.md +43 -0
  7. package/docs/CONFIGURATION.zh.md +36 -0
  8. package/docs/DIAGNOSTICS.md +4 -2
  9. package/docs/DIAGNOSTICS.zh.md +3 -1
  10. package/docs/LIMITATIONS.md +17 -4
  11. package/docs/LIMITATIONS.zh.md +11 -3
  12. package/docs/MIGRATION.md +1 -1
  13. package/docs/PEER-PARITY.md +4 -4
  14. package/docs/QUICKSTART.md +12 -5
  15. package/docs/QUICKSTART.zh.md +8 -2
  16. package/docs/README.zh.md +6 -3
  17. package/docs/RELEASING.md +17 -13
  18. package/docs/REQUIREMENTS.zh.md +3 -2
  19. package/docs/UPSTREAM-FSIO-EXPORT.md +5 -4
  20. package/docs/UPSTREAM-PROMPT-ADAPTERS.md +85 -0
  21. package/docs/root-fs-routing.md +1 -1
  22. package/lib/agent-confined.d.ts +7 -1
  23. package/lib/agent-confined.js +3 -3
  24. package/lib/bwrap.d.ts +14 -0
  25. package/lib/bwrap.js +11 -0
  26. package/lib/cwd-prompt.d.ts +41 -3
  27. package/lib/cwd-prompt.js +125 -8
  28. package/lib/doctor-report.d.ts +50 -0
  29. package/lib/doctor-report.js +172 -0
  30. package/lib/fs-routing.d.ts +1 -1
  31. package/lib/fs-routing.js +1 -1
  32. package/lib/fs.d.ts +1 -1
  33. package/lib/fs.js +1 -1
  34. package/lib/index.d.ts +6 -1464
  35. package/lib/index.js +5 -2120
  36. package/lib/messages.d.ts +1 -1
  37. package/lib/messages.js +3 -3
  38. package/lib/preflight.d.ts +7 -4
  39. package/lib/preflight.js +27 -13
  40. package/lib/provider-common.d.ts +58 -0
  41. package/lib/provider-common.js +123 -0
  42. package/lib/sandbox-core.d.ts +1 -0
  43. package/lib/sandbox-core.js +4 -2
  44. package/lib/session-runtime.d.ts +7 -1
  45. package/lib/session-runtime.js +9 -2
  46. package/lib/shell.d.ts +1 -1
  47. package/lib/shell.js +1 -1
  48. package/lib/writable-roots.d.ts +109 -0
  49. package/lib/writable-roots.js +257 -0
  50. package/lib/wsl-doctor-tool.js +2 -2
  51. package/lib/wsl-filesystem.d.ts +692 -0
  52. package/lib/wsl-filesystem.js +897 -0
  53. package/lib/wsl-shell.d.ts +742 -0
  54. package/lib/wsl-shell.js +965 -0
  55. package/lib/wsl.d.ts +1 -1
  56. package/lib/wsl.js +1 -1
  57. package/package.json +4 -3
  58. package/scripts/doctor.mjs +1 -1
  59. package/scripts/profile-preset.mjs +17 -5
@@ -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
+ }
@@ -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 "./index.js";
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 "./index.js";
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
@@ -7,4 +7,4 @@
7
7
  *
8
8
  * @module dsh-plugin-wsl-env/fs
9
9
  */
10
- export { WslFileSystem as default, WslFileSystem } from "./index.js";
10
+ export { WslFileSystem as default, WslFileSystem } from "./wsl-filesystem.js";
package/lib/fs.js CHANGED
@@ -7,4 +7,4 @@
7
7
  *
8
8
  * @module dsh-plugin-wsl-env/fs
9
9
  */
10
- export { WslFileSystem as default, WslFileSystem } from "./index.js";
10
+ export { WslFileSystem as default, WslFileSystem } from "./wsl-filesystem.js";