dsh-plugin-wsl-env 0.21.0 → 0.23.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 (86) hide show
  1. package/CHANGELOG.md +119 -0
  2. package/CONTRIBUTING.md +7 -3
  3. package/README.md +11 -9
  4. package/SUPPORT.md +1 -1
  5. package/client.js +153 -33
  6. package/cordis.patch.yml +13 -4
  7. package/docs/AGENT-PROTOCOL-V7.md +4 -4
  8. package/docs/API.md +12 -2
  9. package/docs/ARCHITECTURE.md +59 -19
  10. package/docs/CONFIGURATION.md +44 -13
  11. package/docs/CONFIGURATION.zh.md +44 -8
  12. package/docs/DIAGNOSTICS.md +41 -1
  13. package/docs/DIAGNOSTICS.zh.md +34 -2
  14. package/docs/LIMITATIONS.md +42 -17
  15. package/docs/LIMITATIONS.zh.md +47 -12
  16. package/docs/MIGRATION.md +1 -1
  17. package/docs/PEER-PARITY.md +8 -7
  18. package/docs/QUICKSTART.md +16 -8
  19. package/docs/QUICKSTART.zh.md +22 -4
  20. package/docs/README.zh.md +19 -10
  21. package/docs/RELEASING.md +8 -3
  22. package/docs/REQUIREMENTS.zh.md +11 -6
  23. package/docs/ROADMAP-1.0.md +12 -11
  24. package/docs/ROADMAP.md +10 -8
  25. package/docs/UPSTREAM-FILE-REFERENCE-SEAM.md +3 -2
  26. package/docs/UPSTREAM-FSIO-EXPORT.md +8 -9
  27. package/docs/UPSTREAM-SERVICE-SWAP.md +9 -5
  28. package/docs/UPSTREAM-TERMINAL-TITLE.md +9 -8
  29. package/docs/VALUE.zh.md +5 -5
  30. package/docs/root-fs-routing.md +26 -19
  31. package/lib/agent-confined.d.ts +2 -2
  32. package/lib/agent-confined.js +0 -1
  33. package/lib/agent-exec.d.ts +2 -11
  34. package/lib/agent-protocol.d.ts +6 -5
  35. package/lib/agent.d.ts +5 -5
  36. package/lib/auto-preset.d.ts +4 -3
  37. package/lib/bwrap.d.ts +2 -1
  38. package/lib/client-host.d.ts +1 -1
  39. package/lib/client-host.js +1 -1
  40. package/lib/cwd-prompt-tool.d.ts +4 -20
  41. package/lib/cwd-prompt.d.ts +11 -10
  42. package/lib/distro-route.d.ts +3 -2
  43. package/lib/doctor-live.d.ts +2 -1
  44. package/lib/fs-routing.d.ts +29 -1
  45. package/lib/fs-routing.js +30 -3
  46. package/lib/fs-substrate.d.ts +0 -1
  47. package/lib/fs-substrate.js +0 -1
  48. package/lib/fsio-agent.d.ts +3 -21
  49. package/lib/fsio-agent.js +2 -4
  50. package/lib/git-exec.d.ts +3 -2
  51. package/lib/git-route.d.ts +4 -2
  52. package/lib/git-route.js +4 -2
  53. package/lib/index.d.ts +20 -10
  54. package/lib/index.js +128 -12
  55. package/lib/listing.d.ts +2 -1
  56. package/lib/messages.d.ts +82 -1
  57. package/lib/messages.js +94 -1
  58. package/lib/native-agent.d.ts +3 -2
  59. package/lib/paths.d.ts +2 -1
  60. package/lib/picker.d.ts +1 -14
  61. package/lib/picker.js +1 -2
  62. package/lib/preflight.d.ts +5 -4
  63. package/lib/probe-cache.d.ts +2 -1
  64. package/lib/sandbox-core.d.ts +2 -11
  65. package/lib/sandbox-core.js +1 -1
  66. package/lib/sandbox.d.ts +0 -1
  67. package/lib/sandbox.js +0 -4
  68. package/lib/search-exec.d.ts +2 -1
  69. package/lib/session-runtime.d.ts +3 -2
  70. package/lib/shell-env.d.ts +3 -2
  71. package/lib/shell.d.ts +1 -1
  72. package/lib/shell.js +1 -1
  73. package/lib/subprocess.d.ts +1 -1
  74. package/lib/update-check.d.ts +3 -3
  75. package/lib/wsl-doctor-command.d.ts +133 -0
  76. package/lib/wsl-doctor-command.js +381 -0
  77. package/lib/wsl-doctor-tool.d.ts +101 -16
  78. package/lib/wsl-doctor-tool.js +290 -22
  79. package/lib/wsl.d.ts +3 -2
  80. package/locale/doctor/en.json +30 -0
  81. package/locale/doctor/zh.json +30 -0
  82. package/package.json +29 -31
  83. package/scripts/bootstrap-import.sh +189 -0
  84. package/scripts/doctor.mjs +569 -141
  85. package/scripts/open-wsl-vscode.ps1 +36 -0
  86. package/examples/preset-wsl-session-sandbox.cordis.patch.yml +0 -178
package/lib/fs-routing.js CHANGED
@@ -356,12 +356,39 @@ export class WslRoutingFileSystem extends LocalFileSystem {
356
356
  return super.contains(parent, child);
357
357
  }
358
358
  /**
359
+ * The host spelling for a distro target: its canonical UNC identity.
360
+ *
361
+ * `processPath` answers "the path in this filesystem's execution world", and
362
+ * the routed backend's target key already IS the coordinate the Host I/O
363
+ * stack uses — the same answer the session backend gives, because it inherits
364
+ * the host implementation (`String(targetKey)`). The root router answered in
365
+ * Linux form before this change; that broke every consumer that treats
366
+ * `processPath` as a HOST path. `session.openWorkspacePath` and
367
+ * `session.workspacePathApplications` verify a path by requiring
368
+ * `fs.processPath(await fs.resolve(fs.processPathFromHostPath(hostPath)))`
369
+ * to equal `hostPath` (`packages/api/session-controller`,
370
+ * `verifyDesktopPath`), and `processPathFromHostPath` is the inherited host
371
+ * implementation — so with a Linux answer the round trip could never close
372
+ * and "Open in app" / "Reveal in file manager" refused every distro file
373
+ * with `Path has no verified Host path`. The same equality drives
374
+ * `ui-deliverables`' presented-file route.
375
+ *
376
+ * The Linux path is still the target's `displayPath` (what the model sees),
377
+ * and `contains` still compares POSIX coordinates; only this accessor — the
378
+ * one the Host's path-taking consumers read — speaks host spelling.
379
+ *
380
+ * The share root is the one spelling the substrate and the Host disagree on:
381
+ * `posixToUnc(distro, "/")` renders `\\wsl.localhost\<distro>\` (a trailing
382
+ * separator), while the Host's `path.resolve` normalizes the same directory
383
+ * to `\\wsl.localhost\<distro>`. Stripping it keeps the round trip closed for
384
+ * a distro root chosen as the workspace.
385
+ *
359
386
  * @param target - the resolved target.
387
+ * @returns the canonical UNC for a distro target, the host path otherwise.
360
388
  */
361
389
  processPath(target) {
362
- const parsed = uncToPosix(target.targetKey);
363
- if (parsed !== undefined)
364
- return parsed.linuxPath.length > 0 ? parsed.linuxPath : "/";
390
+ if (targetIsDistro(target.targetKey))
391
+ return String(target.targetKey).replace(/\\+$/, "");
365
392
  return super.processPath(target);
366
393
  }
367
394
  }
@@ -336,4 +336,3 @@ export declare class AgentSubstrate {
336
336
  };
337
337
  }>;
338
338
  }
339
- export default AgentSubstrate;
@@ -489,4 +489,3 @@ export class AgentSubstrate {
489
489
  }));
490
490
  }
491
491
  }
492
- export default AgentSubstrate;
@@ -21,23 +21,7 @@
21
21
  *
22
22
  * @module dsh-plugin-wsl-env/fsio-agent
23
23
  */
24
- import { normalizeLineEndings, restoreLineEndings, applyLiteralEdit } from "./fsio-text.js";
25
24
  import type { WslAgent } from "./agent.js";
26
- /** One agent FS round trip's result — the shape `WslAgent#fs` resolves to. */
27
- export interface AgentFsResult {
28
- /** The op's exit status. */
29
- exitCode: number;
30
- /** The op's payload bytes. */
31
- stdout: Buffer;
32
- /** The op's diagnostic line(s). */
33
- stderr: Buffer;
34
- /**
35
- * Protocol 7's FS refusal token, when the op failed through the structured
36
- * FSERR line; the adapter maps it onto `FsErrorCode` directly. Undefined
37
- * for legacy (v6) agents, whose refusal rides the stderr convention.
38
- */
39
- reason?: string;
40
- }
41
25
  /**
42
26
  * Normalize one agent timestamp ("seconds.frac", 9 or 10 fractional digits
43
27
  * depending on whether stat or find produced it) into the peer's nanosecond
@@ -91,7 +75,6 @@ export interface ResolvedTarget {
91
75
  /** The UNC identity this target keys on. */
92
76
  targetKey: string;
93
77
  }
94
- export declare const REASON_CODES: Record<string, string>;
95
78
  /**
96
79
  * Map one wire reason token onto the peer's `FsErrorCode` vocabulary.
97
80
  *
@@ -100,7 +83,7 @@ export declare const REASON_CODES: Record<string, string>;
100
83
  */
101
84
  export declare function reasonToCode(reason: string): string;
102
85
  /** One `find` listing row, as `listChildren` shapes it. */
103
- export interface ChildRow {
86
+ interface ChildRow {
104
87
  name: string;
105
88
  type: string;
106
89
  target: {
@@ -111,7 +94,7 @@ export interface ChildRow {
111
94
  size?: number;
112
95
  }
113
96
  /** The stat row `stat` returns. */
114
- export interface StatRow {
97
+ interface StatRow {
115
98
  type: string;
116
99
  mode: number;
117
100
  size: number;
@@ -426,5 +409,4 @@ export declare class DistroFs {
426
409
  */
427
410
  readTextForDiff(target: ResolvedTarget, maxBytes: number, signal?: AbortSignal): Promise<string | null>;
428
411
  }
429
- export { applyLiteralEdit, normalizeLineEndings, restoreLineEndings };
430
- export default DistroFs;
412
+ export {};
package/lib/fsio-agent.js CHANGED
@@ -22,7 +22,7 @@
22
22
  * @module dsh-plugin-wsl-env/fsio-agent
23
23
  */
24
24
  import { FS_READ_CHUNK_BYTES } from "./agent-protocol.js";
25
- import { BINARY_SAMPLE_BYTES, FsCodedError, decodeUtf8, decodeUtf8Stream, detectLineEndings, normalizeLineEndings, restoreLineEndings, applyLiteralEdit, throwIfAborted, } from "./fsio-text.js";
25
+ import { BINARY_SAMPLE_BYTES, FsCodedError, decodeUtf8, decodeUtf8Stream, detectLineEndings, normalizeLineEndings, throwIfAborted, } from "./fsio-text.js";
26
26
  import { posixToUnc, uncToPosix } from "./paths.js";
27
27
  /** One FS frame's in-distro watchdog; fs ops are short, writes bounded by content size. */
28
28
  const FS_OP_TIMEOUT_MS = 30_000;
@@ -73,7 +73,7 @@ export function parseStatRecord(stdout) {
73
73
  version: versionOf({ dev, ino, size, mtimeNs: nanoseconds(mtime), ctimeNs: nanoseconds(ctime) }),
74
74
  };
75
75
  }
76
- export const REASON_CODES = {
76
+ const REASON_CODES = {
77
77
  notfound: "FS_NOT_FOUND",
78
78
  notdir: "FS_NOT_DIRECTORY",
79
79
  perm: "FS_IO_ERROR",
@@ -689,5 +689,3 @@ export class DistroFs {
689
689
  }
690
690
  }
691
691
  }
692
- export { applyLiteralEdit, normalizeLineEndings, restoreLineEndings };
693
- export default DistroFs;
package/lib/git-exec.d.ts CHANGED
@@ -38,7 +38,7 @@
38
38
  */
39
39
  import type { AgentExecRunner } from "./agent-exec.js";
40
40
  /** One collected-stream reader with the seam's standard shape. */
41
- export interface GitStreamReader {
41
+ interface GitStreamReader {
42
42
  /** Read the stream from a byte offset; `lossy` says the cap cut it. */
43
43
  readFrom: (from: number) => {
44
44
  text: string;
@@ -65,7 +65,7 @@ export interface GitExecutionHandle {
65
65
  kill?: () => boolean | void;
66
66
  }
67
67
  /** Per-stream capture budgets the caller declared on its `stdio` spec. */
68
- export interface GitStreamCaps {
68
+ interface GitStreamCaps {
69
69
  /** The stdout budget in bytes; the snapshot's `outputMaxBytes`. */
70
70
  stdout: number;
71
71
  /** The stderr tail budget in bytes. */
@@ -115,3 +115,4 @@ export declare function gitExecutionHandle({ agent, cwd, argv, env, stdin, caps,
115
115
  */
116
116
  spawnFallback: () => GitExecutionHandle;
117
117
  }): GitExecutionHandle;
118
+ export {};
@@ -44,8 +44,10 @@
44
44
  * two shapes into distro paths with the same pure translations the fs seam
45
45
  * uses, forwards every other value verbatim (`GIT_CONFIG_COUNT=0` and
46
46
  * friends), and returns the names that must ride `WSLENV`. One documented
47
- * limit: a colon-separated multi-directory value (none of the current
48
- * callers set one) passes through untranslated.
47
+ * limit: the translation is single-valued, so a Windows-form multi-directory
48
+ * value is not skipped — it folds onto the first drive's mount (`C:\a;D:\b`
49
+ * becomes `/mnt/c/a;D:/b`) — and only a POSIX-form colon list (`/a:/b`)
50
+ * passes through untranslated (none of the current callers set a list).
49
51
  *
50
52
  * This is a TypeScript source built to `lib/git-route.js`; edit THIS file and
51
53
  * run `pnpm run build` — the artifact under `lib/` is generated, and `pnpm test`
package/lib/git-route.js CHANGED
@@ -44,8 +44,10 @@
44
44
  * two shapes into distro paths with the same pure translations the fs seam
45
45
  * uses, forwards every other value verbatim (`GIT_CONFIG_COUNT=0` and
46
46
  * friends), and returns the names that must ride `WSLENV`. One documented
47
- * limit: a colon-separated multi-directory value (none of the current
48
- * callers set one) passes through untranslated.
47
+ * limit: the translation is single-valued, so a Windows-form multi-directory
48
+ * value is not skipped — it folds onto the first drive's mount (`C:\a;D:\b`
49
+ * becomes `/mnt/c/a;D:/b`) — and only a POSIX-form colon list (`/a:/b`)
50
+ * passes through untranslated (none of the current callers set a list).
49
51
  *
50
52
  * This is a TypeScript source built to `lib/git-route.js`; edit THIS file and
51
53
  * run `pnpm run build` — the artifact under `lib/` is generated, and `pnpm test`
package/lib/index.d.ts CHANGED
@@ -68,21 +68,15 @@ type MoveFileOptions = Parameters<FileSystem["moveFile"]>[2];
68
68
  * execution types ride in through the executor's own signatures.
69
69
  */
70
70
  export type ShellExecSpec = Parameters<LocalBashExecutor["execute"]>[0];
71
- export type ShellExecRequest = Parameters<LocalBashExecutor["resolve"]>[0];
71
+ type ShellExecRequest = Parameters<LocalBashExecutor["resolve"]>[0];
72
72
  export type ShellExecution = Awaited<ReturnType<LocalBashExecutor["execute"]>>;
73
- /**
74
- * One confined command's distro-side profile, as the confinement returns it:
75
- * the wrapped argv, the enforcement completeness, the denial dialect, the
76
- * runner-failure rules and the Windows-drive masking fact.
77
- */
78
- export type ConfinedProfile = Awaited<ReturnType<InstanceType<typeof WslSandbox>["confine"]>>;
79
73
  /**
80
74
  * The resolved spec this executor stamps with its home-marker fields: an empty
81
75
  * `workdir` plus the relative tail that {@link WslShellExecutor.withDefaultWorkdir}
82
76
  * joins against the distro home. The extra keys are this provider's own; the
83
77
  * seam's `ShellExecSpec` does not know them.
84
78
  */
85
- export type WslExecSpec = ShellExecSpec & {
79
+ type WslExecSpec = ShellExecSpec & {
86
80
  relativeWorkdir?: string;
87
81
  };
88
82
  /**
@@ -101,6 +95,7 @@ export type WslExecSpec = ShellExecSpec & {
101
95
  *
102
96
  * @param distro - the distro the doctor examines.
103
97
  * @param options - `doctorPath` overrides the shipped script (tests);
98
+ * `timeoutMs` bounds the run; `signal` lets the caller cancel it;
104
99
  * `liveStatus` overrides the in-process status snapshot (tests).
105
100
  * @returns the merged report.
106
101
  */
@@ -108,6 +103,17 @@ export declare function doctorReport(distro: string, options?: {
108
103
  doctorPath?: string;
109
104
  /** The `wsl.exe` the doctor probes with; forwarded as `--wsl <path>`. */
110
105
  wslPath?: string;
106
+ /**
107
+ * Run the quick profile instead of the full scan: first-command
108
+ * prerequisites only (host/session/sandbox, no smokes, no registry query,
109
+ * no port survey) — forwarded as `--quick`.
110
+ */
111
+ quick?: boolean;
112
+ /**
113
+ * Restrict the run to these doctor sections (host, sandbox, session, conf,
114
+ * net, agent); forwarded as `--sections <csv>`. Undefined runs everything.
115
+ */
116
+ sections?: readonly string[];
111
117
  /**
112
118
  * Prepended to the doctor subprocess's PATH — a caller that stages a fake
113
119
  * `wsl.exe` (tests) passes the staging directory here instead of mutating
@@ -115,6 +121,10 @@ export declare function doctorReport(distro: string, options?: {
115
121
  * the ambiguity this option removes.
116
122
  */
117
123
  envPath?: string;
124
+ /** Hard deadline for the subprocess; defaults to two minutes. */
125
+ timeoutMs?: number;
126
+ /** The caller's cancellation (the tool's `exec.signal`); aborts the child. */
127
+ signal?: AbortSignal;
118
128
  liveStatus?: AgentStatus;
119
129
  }): Promise<DoctorReport>;
120
130
  /**
@@ -139,7 +149,7 @@ export declare function effectiveMaskWindowsDrive(config: {
139
149
  interopVisibility?: "visible" | "masked" | "disabled";
140
150
  maskWindowsDrive?: boolean;
141
151
  }): boolean;
142
- export interface WslShellExecutorConfig {
152
+ interface WslShellExecutorConfig {
143
153
  /** The pinned distro; empty means WSL's default. */
144
154
  distro: string;
145
155
  /** The `wsl.exe` path. */
@@ -842,7 +852,7 @@ export declare class WslShellExecutor extends LocalBashExecutor {
842
852
  * type does not know. This provider has no volatile fields: every key is read
843
853
  * as its plain value.
844
854
  */
845
- export interface WslFileSystemConfig {
855
+ interface WslFileSystemConfig {
846
856
  /** The pinned distro; empty resolves WSL's default. */
847
857
  distro: string;
848
858
  /** The base directory for relative input. */
package/lib/index.js CHANGED
@@ -61,7 +61,7 @@ import { SessionRuntimes, probeSessionRuntime, sessionRuntimes, setSessionNative
61
61
  import { configureAgentBackend, ensureNativeSessionAgent } from "./native-agent.js";
62
62
  import { installMessagesLocale, t } from "./messages.js";
63
63
  import { mergeLiveResidentStatus } from "./doctor-live.js";
64
- import { spawnSync } from "node:child_process";
64
+ import { spawn } from "node:child_process";
65
65
  import { fileURLToPath } from "node:url";
66
66
  import { dirname, join } from "node:path";
67
67
  // `runCapture` and distro discovery live in ./wsl.js so the directory picker
@@ -182,6 +182,114 @@ function wslWritableRoots(policy, distro) {
182
182
  }
183
183
  /** The doctor script this package ships, resolved from the compiled module. */
184
184
  const DOCTOR_SCRIPT = join(dirname(fileURLToPath(import.meta.url)), "..", "scripts", "doctor.mjs");
185
+ /** How long the doctor subprocess may run before the collector kills it. */
186
+ const DOCTOR_TIMEOUT_MS = 120_000;
187
+ /**
188
+ * How much of one doctor stream the collector retains. The `--json` report is
189
+ * a few dozen KiB; the cap exists so a runaway child cannot grow the Host's
190
+ * memory without bound.
191
+ */
192
+ const DOCTOR_OUTPUT_LIMIT_BYTES = 4 * 1024 * 1024;
193
+ /**
194
+ * How long after the doctor exits the collector waits for its pipes. A
195
+ * grandchild that inherited the pipes can keep them open forever; the report
196
+ * on stdout is complete once the doctor itself has exited, so the wait is
197
+ * bounded instead of following the pipes to EOF.
198
+ */
199
+ const DOCTOR_DRAIN_GRACE_MS = 500;
200
+ /**
201
+ * Run the doctor CLI asynchronously and collect its streams.
202
+ *
203
+ * `spawnSync` would block the Host's event loop for the whole run — up to the
204
+ * deadline, with no way to cancel and every other tool stalled behind it — so
205
+ * the collector spawns, arms a deadline and the caller's abort signal, and
206
+ * settles on the child's exit plus a bounded drain window. A grandchild that
207
+ * inherits the pipes cannot hold the collector past that window.
208
+ *
209
+ * @param argv - the node argv (script path first).
210
+ * @param options - the child env, the deadline, and the caller's signal.
211
+ * @returns the finished run, including the spawn failure when it never started.
212
+ */
213
+ function runDoctorProcess(argv, options) {
214
+ return new Promise((resolvePromise) => {
215
+ let stdout = "";
216
+ let stderr = "";
217
+ let timedOut = false;
218
+ let overLimit = false;
219
+ let spawnError;
220
+ let exit;
221
+ let drainTimer;
222
+ let settled = false;
223
+ const child = spawn(process.execPath, argv, {
224
+ stdio: ["ignore", "pipe", "pipe"],
225
+ windowsHide: true,
226
+ ...(options.env === undefined ? {} : { env: options.env }),
227
+ ...(options.signal === undefined ? {} : { signal: options.signal }),
228
+ });
229
+ const settle = () => {
230
+ if (settled)
231
+ return;
232
+ settled = true;
233
+ clearTimeout(deadlineTimer);
234
+ if (drainTimer !== undefined)
235
+ clearTimeout(drainTimer);
236
+ resolvePromise({
237
+ stdout,
238
+ stderr,
239
+ status: exit?.status ?? null,
240
+ signal: exit?.signal ?? null,
241
+ timedOut,
242
+ overLimit,
243
+ ...(spawnError === undefined ? {} : { spawnError }),
244
+ });
245
+ };
246
+ const kill = () => {
247
+ try {
248
+ child.kill();
249
+ }
250
+ catch {
251
+ // An already-exited child: the exit handler settles the run.
252
+ }
253
+ };
254
+ const deadlineTimer = setTimeout(() => {
255
+ timedOut = true;
256
+ kill();
257
+ }, options.timeoutMs);
258
+ const capture = (chunk, which) => {
259
+ if (settled)
260
+ return;
261
+ if (which === "stdout")
262
+ stdout += chunk;
263
+ else
264
+ stderr += chunk;
265
+ if (stdout.length + stderr.length > DOCTOR_OUTPUT_LIMIT_BYTES) {
266
+ overLimit = true;
267
+ kill();
268
+ }
269
+ };
270
+ child.stdout?.on("data", (chunk) => capture(chunk.toString("utf8"), "stdout"));
271
+ child.stderr?.on("data", (chunk) => capture(chunk.toString("utf8"), "stderr"));
272
+ child.on("error", (error) => {
273
+ // A spawn failure never reaches `exit`; an abort is reported with the
274
+ // same event, so the marker is normalized into a plain message.
275
+ spawnError = error.name === "AbortError"
276
+ ? new Error("doctor run aborted")
277
+ : error;
278
+ if (exit === undefined)
279
+ settle();
280
+ });
281
+ child.on("exit", (code, signalName) => {
282
+ exit = { status: code, signal: signalName ?? null };
283
+ // The report is complete at exit; give the pipes one bounded window to
284
+ // flush (a grandchild holding them must not stall the collector).
285
+ drainTimer = setTimeout(settle, DOCTOR_DRAIN_GRACE_MS);
286
+ });
287
+ child.on("close", () => {
288
+ if (exit !== undefined)
289
+ settle();
290
+ });
291
+ });
292
+ }
185
293
  /**
186
294
  * Collect the doctor's versioned JSON report and merge the live resident's
187
295
  * own lifecycle facts when this process holds one (WSL-313).
@@ -198,35 +306,43 @@ const DOCTOR_SCRIPT = join(dirname(fileURLToPath(import.meta.url)), "..", "scrip
198
306
  *
199
307
  * @param distro - the distro the doctor examines.
200
308
  * @param options - `doctorPath` overrides the shipped script (tests);
309
+ * `timeoutMs` bounds the run; `signal` lets the caller cancel it;
201
310
  * `liveStatus` overrides the in-process status snapshot (tests).
202
311
  * @returns the merged report.
203
312
  */
204
313
  export async function doctorReport(distro, options) {
205
314
  const script = options?.doctorPath ?? DOCTOR_SCRIPT;
206
315
  const argv = [script, distro, "--json"];
316
+ if (options?.quick === true)
317
+ argv.push("--quick");
318
+ if (options?.sections !== undefined && options.sections.length > 0)
319
+ argv.push("--sections", [...options.sections].join(","));
207
320
  if (options?.wslPath !== undefined)
208
321
  argv.push("--wsl", options.wslPath);
209
322
  // A nonzero doctor exit usually means an environment check FAILED on the
210
323
  // machine being examined — that is a valid report, not a broken collection.
211
324
  // The stdout is parsed regardless; only a run that produced no versioned
212
325
  // report rejects.
213
- const spawned = spawnSync(process.execPath, argv, {
214
- timeout: 120_000,
215
- maxBuffer: 4 * 1024 * 1024,
216
- windowsHide: true,
217
- encoding: "utf8",
326
+ const timeoutMs = options?.timeoutMs ?? DOCTOR_TIMEOUT_MS;
327
+ const run = await runDoctorProcess(argv, {
328
+ timeoutMs,
218
329
  ...(options?.envPath !== undefined ? { env: { ...process.env, PATH: `${options.envPath}:${process.env.PATH ?? ""}` } } : {}),
330
+ ...(options?.signal === undefined ? {} : { signal: options.signal }),
219
331
  });
220
- // A nonzero doctor exit usually means an environment check FAILED on the
221
- // machine being examined — the versioned report on stdout is still the
222
- // deliverable, so it parses whenever present. Only a run that produced no
223
- // report rejects, naming the spawn failure and any stderr tail.
224
332
  let report;
225
333
  try {
226
- report = JSON.parse(spawned.stdout);
334
+ report = JSON.parse(run.stdout);
227
335
  }
228
336
  catch {
229
- throw new Error(`doctor run failed: ${spawned.error?.message ?? `exited with code ${spawned.status}`}${spawned.stderr.length > 0 ? ` — ${spawned.stderr.trim().slice(-400)}` : ""}`);
337
+ // A run that produced no report rejects, naming the transport failure
338
+ // (spawn error, deadline, output cap, exit) and any stderr tail.
339
+ const cause = run.spawnError?.message
340
+ ?? (run.timedOut
341
+ ? `timed out after ${timeoutMs}ms`
342
+ : run.overLimit
343
+ ? `produced more than ${DOCTOR_OUTPUT_LIMIT_BYTES} bytes`
344
+ : `exited with code ${run.status ?? run.signal ?? "unknown"}`);
345
+ throw new Error(`doctor run failed: ${cause}${run.stderr.length > 0 ? ` — ${run.stderr.trim().slice(-400)}` : ""}`);
230
346
  }
231
347
  const status = options?.liveStatus ?? sharedAgent(distro).status();
232
348
  return mergeLiveResidentStatus(report, status);
package/lib/listing.d.ts CHANGED
@@ -11,7 +11,7 @@
11
11
  * @module dsh-plugin-wsl-env/listing
12
12
  */
13
13
  /** One picker row: a display name, its jump target, and the dot-entry flag. */
14
- export interface ListingRow {
14
+ interface ListingRow {
15
15
  /** The row's display name. */
16
16
  name: string;
17
17
  /** The row's jump target, Windows spelling. */
@@ -119,3 +119,4 @@ export declare function parseDirListing(stdout: string | Buffer, linuxDir: strin
119
119
  rows: ListingRow[];
120
120
  truncated: boolean;
121
121
  };
122
+ export {};
package/lib/messages.d.ts CHANGED
@@ -23,7 +23,7 @@
23
23
  */
24
24
  import type { Context } from "@deepseek-ai/cordis";
25
25
  /** The languages the catalogs ship. More locales are additive: add a table and widen the resolver. */
26
- export type MessagesLocale = "en" | "zh";
26
+ type MessagesLocale = "en" | "zh";
27
27
  /**
28
28
  * The message templates, keyed by call site. Each entry owns its parameter
29
29
  * shape; the `zh` table is type-checked against the `en` table's key and
@@ -92,6 +92,71 @@ declare const en: {
92
92
  workdir: string;
93
93
  distro: string;
94
94
  }) => string;
95
+ /** `wsl_doctor` digest: the verdict line. `verdict` is the report's own `ready`/`blocked`. */
96
+ doctorDigestVerdict: ({ verdict }: {
97
+ verdict: string;
98
+ }) => string;
99
+ /** `wsl_doctor` digest: the host-wide group heading. */
100
+ doctorDigestHostLabel: () => string;
101
+ /** `wsl_doctor` digest: the heading for checks the run's scope never executed. */
102
+ doctorDigestNotRunLabel: () => string;
103
+ /** `wsl_doctor` digest: marks which distro group is the session's own. */
104
+ doctorDigestSessionLabel: ({ name }: {
105
+ name: string;
106
+ }) => string;
107
+ /** `wsl_doctor` digest: one summary line for the checks the run's scope never executed; `reason` says why (the run's scope profile). */
108
+ doctorDigestSkipRow: ({ n, reason, ids }: {
109
+ n: number;
110
+ reason: string;
111
+ ids: string;
112
+ }) => string;
113
+ /** `wsl_doctor` digest: the scope reason for a quick run's skip line. */
114
+ doctorSkipReasonQuick: () => string;
115
+ /** `wsl_doctor` digest: the scope reason for a section-filtered run's skip line. */
116
+ doctorSkipReasonSections: ({ sections }: {
117
+ sections: string;
118
+ }) => string;
119
+ /** `wsl_doctor` digest: the scope reason when the report recorded none. */
120
+ doctorSkipReasonGeneric: () => string;
121
+ /** `wsl_doctor` digest: one line per check a failed prerequisite gated out; `reason` names the blocker. */
122
+ doctorSkipGated: ({ id, reason }: {
123
+ id: string;
124
+ reason: string;
125
+ }) => string;
126
+ /** `wsl_doctor` digest: per-group tallies, one entry per non-zero status. */
127
+ doctorTallyOk: ({ n }: {
128
+ n: number;
129
+ }) => string;
130
+ doctorTallyWarn: ({ n }: {
131
+ n: number;
132
+ }) => string;
133
+ doctorTallyFail: ({ n }: {
134
+ n: number;
135
+ }) => string;
136
+ doctorTallyUnknown: ({ n }: {
137
+ n: number;
138
+ }) => string;
139
+ doctorTallyInfo: ({ n }: {
140
+ n: number;
141
+ }) => string;
142
+ doctorTallySkipped: ({ n }: {
143
+ n: number;
144
+ }) => string;
145
+ /** `wsl_doctor` digest: the remedy prefix under a failed check. */
146
+ doctorDigestFixPrefix: ({ remedy }: {
147
+ remedy: string;
148
+ }) => string;
149
+ /** `wsl_doctor` digest: the ready note (how to attach the full report). */
150
+ doctorDigestNoteReady: () => string;
151
+ /** `wsl_doctor` digest: the blocked note (the rerun is the re-verification). */
152
+ doctorDigestNoteBlocked: () => string;
153
+ /** `wsl_doctor` digest: the blocked summary tail; `noneBlocking` is the fixed clause. */
154
+ doctorDigestBlockedTail: ({ blockers, warnings, skipped, note }: {
155
+ blockers: string;
156
+ warnings: number;
157
+ skipped: number;
158
+ note: string;
159
+ }) => string;
95
160
  };
96
161
  type Catalog = typeof en;
97
162
  type MessageKey = keyof Catalog;
@@ -147,6 +212,13 @@ export declare function resolveMessagesLocale(preference: unknown): MessagesLoca
147
212
  * which also covers the `locale` entry activating after this row did. A read
148
213
  * that throws keeps the previous language: this is presentation, not gating.
149
214
  *
215
+ * A browser whose user never picked a language in Settings has NO persisted
216
+ * `locale.preference` — its Chinese UI came from the navigator's provisional
217
+ * match, which the Host settings never record. For that case the fallback
218
+ * reads the process's ICU default locale (Electron: the OS UI language), so
219
+ * a zh-CN Windows with a provisional-Chinese UI still renders Chinese. An
220
+ * explicit Settings choice always wins over the fallback.
221
+ *
150
222
  * @param ctx - the row's composition context.
151
223
  */
152
224
  export declare function installMessagesLocale(ctx: Context): void;
@@ -154,4 +226,13 @@ export declare function installMessagesLocale(ctx: Context): void;
154
226
  * Restore English. Tests only: production wiring is process-wide by design.
155
227
  */
156
228
  export declare function resetMessagesLocaleForTests(): void;
229
+ /**
230
+ * The no-settings fallback: the process's ICU default locale, which in the
231
+ * desktop app follows the OS UI language (a zh-CN Windows yields `zh-CN`).
232
+ * Under Node's small-icu builds this is `en-US`, which maps to English — the
233
+ * previous default. Exported for tests.
234
+ *
235
+ * @returns {"en" | "zh"} the language the OS-level locale selects.
236
+ */
237
+ export declare function hostFallbackLocale(): MessagesLocale;
157
238
  export {};