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
@@ -0,0 +1,381 @@
1
+ /**
2
+ * The `/wsl-doctor` UI command: the human runs the environment doctor through
3
+ * the command plane — the browser button drops a `/wsl-doctor` line, the
4
+ * commands registry executes it against a session, and the settled text
5
+ * renders in the UI detached from model history. No model turn happens: the
6
+ * command and its output add no tokens and never enter a request (the
7
+ * `dsh-commands` contract), which is the point — the diagnosis must not
8
+ * depend on the plugin's model-facing runtime being healthy.
9
+ *
10
+ * The handler does NOT collect the report in-process. It spawns the
11
+ * standalone doctor CLI (`scripts/doctor.mjs --json`) as a host subprocess:
12
+ * the CLI loads no peer dependency and no host service (its two peer-tainted
13
+ * imports are inlined and drift-pinned by test), so a diagnosis answers even
14
+ * when the plugin's own module graph is the thing that is broken. Formatting
15
+ * reuses `digestReport`/`renderDigest` from the tool module so the UI command
16
+ * and the model tool present identical itemized output.
17
+ *
18
+ * Grammar: `/wsl-doctor [quick|full|<section>] [--distro <name>]` — an empty
19
+ * line means quick. Without an explicit distro the session's own working
20
+ * directory names the distro; when that also fails, the CLI's effective
21
+ * configuration decides (the shipped preset's `auto` probes every installed
22
+ * distro). Unknown tokens settle as a direct command error with usage text.
23
+ *
24
+ * This is a TypeScript source built to `lib/wsl-doctor-command.js`; edit THIS
25
+ * file and run `pnpm run build` — the artifact under `lib/` is generated, and
26
+ * `pnpm test` fails when it drifts.
27
+ *
28
+ * @module dsh-plugin-wsl-env/wsl-doctor-command
29
+ */
30
+ import { spawn } from "node:child_process";
31
+ import { dirname, resolve } from "node:path";
32
+ import { fileURLToPath } from "node:url";
33
+ import { distroOfUnc } from "./distro-route.js";
34
+ import { digestReport, renderDigest, SECTIONS } from "./wsl-doctor-tool.js";
35
+ export const name = "wsl-doctor-command";
36
+ /**
37
+ * No required inject: a headless deployment has no commands registry, and a
38
+ * required inject would fail the whole composition mount over a surface this
39
+ * row cannot use. The registry resolves per mount through the optional
40
+ * `ctx.get` (cordis answers undefined for an absent name; a `get` needs no
41
+ * inject), with a plain property as the test seam — the same shape the
42
+ * `wsl_doctor` tool uses for its optional collector.
43
+ */
44
+ export const inject = [];
45
+ /** How long the cwd service may take before the command gives up on it. */
46
+ const CWD_SERVICE_TIMEOUT_MS = 5_000;
47
+ /**
48
+ * How long a distro-scoped doctor CLI run may take. A scoped quick run takes
49
+ * seconds and a scoped full run ~15 s, so only a stall reaches this; it sits
50
+ * below the command dispatcher's own deadline so the run settles with a
51
+ * message naming what happened instead of the dispatcher's opaque "operation
52
+ * was aborted".
53
+ */
54
+ export const DOCTOR_CLI_TIMEOUT_MS = 120_000;
55
+ /**
56
+ * How long an UNRESOLVED-target run may take. Without a distro the CLI's
57
+ * effective configuration decides, and the shipped `auto` probes every
58
+ * installed distro — minutes on a machine with several, with no progress to
59
+ * show in the UI. Failing fast with the narrowing hint beats a card that sits
60
+ * "executing" for the dispatcher's whole budget.
61
+ */
62
+ export const DOCTOR_CLI_SWEEP_TIMEOUT_MS = 60_000;
63
+ /** The doctor CLI this row spawns, resolved from the built module's package root. */
64
+ export const DOCTOR_SCRIPT = resolve(dirname(fileURLToPath(import.meta.url)), "..", "scripts", "doctor.mjs");
65
+ /** The usage text a grammar violation settles with. */
66
+ export const USAGE = "用法:/wsl-doctor [quick|full|<section>] [--distro <名称>]\n" +
67
+ "section ∈ " + SECTIONS.join(" | ") + ";空输入等价 quick。省略 --distro 时用当前会话的工作目录推断 distro。";
68
+ /**
69
+ * Parse the raw input after the command name. Tokens: one mode word or
70
+ * section name, plus an optional `--distro <name>` / `--distro=<name>`; a
71
+ * second bare token is accepted as the distro name.
72
+ *
73
+ * @param rawInput - everything after the command name.
74
+ * @returns the parsed mode, optional section, and optional distro.
75
+ * @throws when a token matches nothing — the caller settles usage text.
76
+ */
77
+ export function parseDoctorInput(rawInput) {
78
+ const parsed = { mode: "quick", distro: "" };
79
+ const tokens = rawInput.trim().split(/\s+/).filter((token) => token.length > 0);
80
+ let expectingDistro = false;
81
+ for (const token of tokens) {
82
+ if (expectingDistro) {
83
+ parsed.distro = token;
84
+ expectingDistro = false;
85
+ continue;
86
+ }
87
+ if (token === "--distro") {
88
+ expectingDistro = true;
89
+ continue;
90
+ }
91
+ if (token.startsWith("--distro=")) {
92
+ parsed.distro = token.slice("--distro=".length);
93
+ continue;
94
+ }
95
+ if (token === "quick" || token === "full") {
96
+ parsed.mode = token;
97
+ continue;
98
+ }
99
+ if (SECTIONS.includes(token)) {
100
+ parsed.mode = "section";
101
+ parsed.section = token;
102
+ continue;
103
+ }
104
+ if (parsed.distro.length === 0) {
105
+ parsed.distro = token;
106
+ continue;
107
+ }
108
+ throw new Error(`无法识别的参数:${token}`);
109
+ }
110
+ if (expectingDistro)
111
+ throw new Error("--distro 需要一个名称");
112
+ return parsed;
113
+ }
114
+ /**
115
+ * The default CLI runner: spawn the standalone doctor as a host subprocess.
116
+ * `process.execPath` is the Electron binary inside the harness, so
117
+ * `ELECTRON_RUN_AS_NODE=1` turns it into plain node for the child; under a
118
+ * plain node runtime the variable is ignored. Exit code 1 is a *blocked
119
+ * verdict*, which is a successful diagnosis — the JSON on stdout still parses;
120
+ * only a spawn failure or unparseable output is an infrastructure error.
121
+ *
122
+ * The run is bounded by {@link DOCTOR_CLI_TIMEOUT_MS}. Without a deadline a
123
+ * doctor that never reports keeps the command "executing" until the command
124
+ * dispatcher aborts it, and that abort surfaces as an opaque "operation was
125
+ * aborted" that names neither what ran nor how to narrow it.
126
+ *
127
+ * @param argv - flags after the script path (no node, no script — added here).
128
+ * @param signal - the dispatcher's abort signal; abort kills the child.
129
+ * @param timeoutMs - the deadline; tests shrink it to exercise the timeout.
130
+ * @returns the CLI's stdout (one JSON report).
131
+ */
132
+ export function runDoctorCli(argv, signal, timeoutMs = DOCTOR_CLI_TIMEOUT_MS) {
133
+ return new Promise((resolvePromise, rejectPromise) => {
134
+ const child = spawn(process.execPath, [DOCTOR_SCRIPT, ...argv], {
135
+ env: { ...process.env, ELECTRON_RUN_AS_NODE: "1" },
136
+ windowsHide: true,
137
+ stdio: ["ignore", "pipe", "pipe"],
138
+ signal,
139
+ });
140
+ let stdout = "";
141
+ let stderr = "";
142
+ let settled = false;
143
+ let timedOut = false;
144
+ const settle = (finish) => {
145
+ if (settled)
146
+ return;
147
+ settled = true;
148
+ clearTimeout(deadline);
149
+ finish();
150
+ };
151
+ const deadline = setTimeout(() => {
152
+ timedOut = true;
153
+ try {
154
+ child.kill();
155
+ }
156
+ catch {
157
+ // Already exited: the close handler settles the run.
158
+ }
159
+ }, timeoutMs);
160
+ child.stdout?.on("data", (chunk) => { stdout += chunk.toString("utf8"); });
161
+ child.stderr?.on("data", (chunk) => { stderr += chunk.toString("utf8"); });
162
+ child.on("error", (error) => {
163
+ // An abort arrives here as an AbortError; normalize it so the settled
164
+ // message names the run rather than the DOMException.
165
+ settle(() => rejectPromise(error.name === "AbortError" ? new Error("doctor CLI 已取消") : error));
166
+ });
167
+ child.on("close", (code, signalName) => {
168
+ const text = stdout.trim();
169
+ if (text.startsWith("{")) {
170
+ settle(() => resolvePromise(text));
171
+ return;
172
+ }
173
+ if (timedOut) {
174
+ settle(() => rejectPromise(new Error(`doctor CLI 在 ${timeoutMs / 1000} 秒内没有给出报告;用 --distro <名称> 收窄到单个发行版,或改用 quick / <分区> 重试`)));
175
+ return;
176
+ }
177
+ settle(() => rejectPromise(new Error(`doctor CLI 未能给出报告(exit ${code ?? signalName ?? "signal"})${stderr.trim().length > 0 ? `:${stderr.trim().slice(0, 400)}` : ""}`)));
178
+ });
179
+ });
180
+ }
181
+ /**
182
+ * Await a promise for at most `ms` milliseconds, returning undefined when the
183
+ * budget runs out. Used for the cwd service: naming the distro is a
184
+ * convenience, and a stalled resolution must never delay the diagnosis.
185
+ *
186
+ * @param promise - the pending resolution.
187
+ * @param ms - the budget.
188
+ * @returns the value, or undefined when the budget ran out.
189
+ */
190
+ async function within(promise, ms) {
191
+ let timer;
192
+ try {
193
+ return await Promise.race([
194
+ promise,
195
+ new Promise((resolve) => { timer = setTimeout(() => resolve(undefined), ms); }),
196
+ ]);
197
+ }
198
+ catch {
199
+ return undefined;
200
+ }
201
+ finally {
202
+ if (timer !== undefined)
203
+ clearTimeout(timer);
204
+ }
205
+ }
206
+ /**
207
+ * Resolve the commands registry: the provided `commands` service through the
208
+ * optional `ctx.get`, else the plain property (the test seam). Absent means a
209
+ * headless deployment — the row stays a no-op instead of failing the mount.
210
+ *
211
+ * @param ctx - the cordis context the row mounted in.
212
+ * @returns the registry, or undefined when the deployment has no command adapter.
213
+ */
214
+ function resolveCommands(ctx) {
215
+ if (typeof ctx.get === "function") {
216
+ const provided = ctx.get("commands");
217
+ if (provided !== undefined && provided !== null && typeof provided.register === "function") {
218
+ return provided; // the provided service's contract is this module's `register` slice
219
+ }
220
+ }
221
+ return ctx.commands;
222
+ }
223
+ /**
224
+ * Resolve the distro an invocation targets: the explicit `--distro` wins;
225
+ * otherwise the Session's own working directory names a distro when it is a
226
+ * WSL UNC path; otherwise empty — the CLI's effective configuration decides
227
+ * (the shipped preset's `auto` probes every installed distro).
228
+ *
229
+ * The `workingDirectory` service is agent-scoped: the preset's tool row
230
+ * injects it, and `wsl-cwd-prompt` reads it from `agent.ctx`. The app-level
231
+ * command row therefore reaches it through the invocation's agent, not through
232
+ * its own `ctx.get` — reading only the row's context silently missed the
233
+ * service, left the distro unresolved, and turned the run into the
234
+ * configuration's `auto` sweep over every installed distro. The Session
235
+ * header's `cwd` is the service-free fallback: it names the distro the
236
+ * session opened in even when the live value is unreachable.
237
+ *
238
+ * @param ctx - the cordis context (the row's own scope, the last resort).
239
+ * @param invocation - the registry's invocation face.
240
+ * @param distro - the explicitly requested distro, possibly empty.
241
+ * @returns the distro name, possibly empty.
242
+ */
243
+ async function resolveDistro(ctx, invocation, distro) {
244
+ if (distro.length > 0)
245
+ return distro;
246
+ const agent = invocation.agent;
247
+ if (agent === undefined)
248
+ return "";
249
+ const session = agent.session;
250
+ /** Every candidate service, in the order the resolution tries them. */
251
+ const services = [];
252
+ try {
253
+ const scoped = agent.ctx?.get?.("workingDirectory");
254
+ if (scoped !== undefined && scoped !== null)
255
+ services.push(scoped); // the service's contract is this module's slice
256
+ }
257
+ catch {
258
+ // A context that refuses the read contributes no service; the header cwd
259
+ // below still names the distro.
260
+ }
261
+ try {
262
+ const rowScoped = typeof ctx.get === "function"
263
+ ? ctx.get("workingDirectory") // absent at app scope in production; harmless when present
264
+ : ctx.workingDirectory;
265
+ if (rowScoped !== undefined && rowScoped !== null)
266
+ services.push(rowScoped);
267
+ }
268
+ catch {
269
+ // Same reason: the row's context is not where the service lives.
270
+ }
271
+ // The live value first (a mid-session `cd` can move the session to another
272
+ // distro), then the header's own cwd, then the async resolution.
273
+ for (const service of services) {
274
+ try {
275
+ const current = service?.get?.(session);
276
+ const fromCurrent = distroOfUnc(current ?? undefined);
277
+ if (fromCurrent !== undefined)
278
+ return fromCurrent;
279
+ }
280
+ catch {
281
+ // A throwing get contributes nothing.
282
+ }
283
+ }
284
+ const fromHeader = distroOfUnc(session?.header?.cwd);
285
+ if (fromHeader !== undefined)
286
+ return fromHeader;
287
+ for (const service of services) {
288
+ if (typeof service?.ensure !== "function")
289
+ continue;
290
+ let pending;
291
+ try {
292
+ pending = service.ensure(agent, invocation.signal);
293
+ }
294
+ catch {
295
+ // A synchronous throw is a failed resolution, never a failed command.
296
+ continue;
297
+ }
298
+ const resolved = await within(pending, CWD_SERVICE_TIMEOUT_MS);
299
+ const fromService = distroOfUnc(resolved);
300
+ if (fromService !== undefined)
301
+ return fromService;
302
+ }
303
+ return "";
304
+ }
305
+ /**
306
+ * Format the CLI's JSON report into the itemized text the UI renders — the
307
+ * same digest the `wsl_doctor` tool returns, so both surfaces itemize every
308
+ * check identically.
309
+ *
310
+ * @param json - the CLI's stdout, one versioned JSON report.
311
+ * @param distro - the distro the run named, for the session-distro markers.
312
+ * @returns the rendered report text.
313
+ */
314
+ export function formatDoctorReport(json, distro) {
315
+ const report = JSON.parse(json);
316
+ const digest = digestReport(report, distro.length > 0 ? distro : undefined);
317
+ return renderDigest(digest);
318
+ }
319
+ /**
320
+ * Mount the command.
321
+ *
322
+ * @param ctx - the cordis context (the composition root, where the commands
323
+ * registry and the harness cwd service are reachable).
324
+ */
325
+ export async function apply(ctx) {
326
+ const commands = resolveCommands(ctx);
327
+ // No command adapter: nothing to register, nothing to fail. The doctor CLI
328
+ // (`pnpm run doctor`) stays the surface for headless deployments.
329
+ if (commands === undefined)
330
+ return;
331
+ // The test seam is a plain object: `doctorCli`, when the context carries it,
332
+ // replaces the subprocess. Reading it may throw under the cordis property
333
+ // proxy ("cannot get property ... without inject"), so the read is guarded —
334
+ // the same shape the tool module uses for its optional `doctor`.
335
+ const runCli = (() => {
336
+ try {
337
+ if (typeof ctx.doctorCli === "function")
338
+ return ctx.doctorCli;
339
+ }
340
+ catch {
341
+ // Production: the row's context has no such property.
342
+ }
343
+ return runDoctorCli;
344
+ })();
345
+ commands.register({
346
+ name: "wsl-doctor",
347
+ description: "运行 WSL 环境诊断(独立 doctor CLI):结果直接显示在此,不进入模型对话。省略参数为快速诊断。",
348
+ input: { hint: "[quick|full|<section>] [--distro <名称>]" },
349
+ handler: async (invocation) => {
350
+ let parsed;
351
+ try {
352
+ parsed = parseDoctorInput(invocation.rawInput);
353
+ }
354
+ catch (error) {
355
+ return { kind: "error", text: `${error instanceof Error ? error.message : String(error)}\n\n${USAGE}` };
356
+ }
357
+ const distro = await resolveDistro(ctx, invocation, parsed.distro);
358
+ const argv = ["--json"];
359
+ if (parsed.mode === "quick")
360
+ argv.push("--quick");
361
+ if (parsed.mode === "section" && parsed.section !== undefined)
362
+ argv.push("--sections", parsed.section);
363
+ if (distro.length > 0)
364
+ argv.push("--distro", distro);
365
+ // A resolved target is one distro and finishes in seconds; an unresolved
366
+ // one hands the choice to the configuration, whose `auto` sweeps every
367
+ // installed distro — bounded tightly so it cannot sit "executing".
368
+ const budget = distro.length > 0 ? DOCTOR_CLI_TIMEOUT_MS : DOCTOR_CLI_SWEEP_TIMEOUT_MS;
369
+ try {
370
+ const json = await runCli(argv, invocation.signal, budget);
371
+ return { kind: "success", text: formatDoctorReport(json, distro) };
372
+ }
373
+ catch (error) {
374
+ const target = distro.length > 0
375
+ ? `发行版 ${distro}`
376
+ : "配置指定的目标(未从会话工作目录解析出发行版,auto 会逐个检查所有已安装发行版)";
377
+ return { kind: "error", text: `doctor 运行失败(${target}):${error instanceof Error ? error.message : String(error)}` };
378
+ }
379
+ },
380
+ });
381
+ }
@@ -36,11 +36,11 @@ export declare const name = "wsl-doctor-tool";
36
36
  */
37
37
  export declare const inject: string[];
38
38
  /** The tool registry slice this service consumes. */
39
- export interface ToolRegistrySlice {
39
+ interface ToolRegistrySlice {
40
40
  register: (tool: unknown) => unknown;
41
41
  }
42
42
  /** The harness's `workingDirectory` service slice (cwd resolution). */
43
- export interface WorkingDirectoryToolSlice {
43
+ interface WorkingDirectoryToolSlice {
44
44
  ensure: (agent: unknown, signal?: unknown) => Promise<string>;
45
45
  }
46
46
  /** The doctor report this tool digests — the doctor CLI's versioned shape. */
@@ -61,26 +61,58 @@ export interface DoctorReportLike {
61
61
  distro?: string;
62
62
  }>;
63
63
  summary?: Record<string, number>;
64
+ /** The run's scope when the report is quick or section-filtered. */
65
+ scope?: {
66
+ sections: string[];
67
+ quick: boolean;
68
+ };
64
69
  }
65
- /** The cordis context slice this service consumes. */
66
- export type WslDoctorToolContext = {
70
+ /** The doctor report collector: distro plus run scope in, report out. */
71
+ type DoctorCollector = (distro: string, options?: {
72
+ quick?: boolean;
73
+ sections?: readonly string[];
74
+ signal?: AbortSignal;
75
+ }) => Promise<DoctorReportLike>;
76
+ /** The context slice this service consumes. */
77
+ type WslDoctorToolContext = {
67
78
  tools: ToolRegistrySlice;
68
79
  workingDirectory: WorkingDirectoryToolSlice;
69
80
  /** Optional cordis-style lookup: how production resolves `doctor` without an inject. */
70
81
  get?: (name: string) => unknown;
71
82
  /** The in-process collector: a provided `doctor` service, or the test seam's fake. */
72
- doctor?: (distro: string) => Promise<DoctorReportLike>;
83
+ doctor?: DoctorCollector;
73
84
  };
74
- /** The tool's config: the row takes no options. */
75
- export interface WslDoctorToolConfig {
76
- /** Reserved; the wrapper has no options today. */
77
- enabled?: boolean;
78
- }
79
85
  /** One failing check as the digest carries it: what failed and what to do. */
80
- export interface FailingCheck {
86
+ interface FailingCheck {
81
87
  id: string;
82
88
  detail: string;
83
89
  remedy: string;
90
+ /** The distro the failing check ran in; absent for host-wide checks. */
91
+ distro?: string;
92
+ }
93
+ /** Per-distro tallies: what was tested in each distro and how it came out. */
94
+ interface DistroTally {
95
+ name: string;
96
+ ok: number;
97
+ warn: number;
98
+ fail: number;
99
+ unknown: number;
100
+ info: number;
101
+ skipped: number;
102
+ /** This distro is the session's own — the run's primary subject. */
103
+ session?: boolean;
104
+ /** The distro's own verdict when the report carried one. */
105
+ verdict?: string;
106
+ }
107
+ /** One check as the itemized listing carries it: what was tested and how it came out. */
108
+ interface CheckItem {
109
+ id: string;
110
+ /** The check's display name; falls back to the id when the report omits it. */
111
+ title: string;
112
+ status: string;
113
+ detail: string;
114
+ distro?: string;
115
+ remedy?: string;
84
116
  }
85
117
  /** The tool's result: the doctor's verdict, condensed for the model. */
86
118
  export interface DoctorDigest {
@@ -89,6 +121,23 @@ export interface DoctorDigest {
89
121
  failing: FailingCheck[];
90
122
  warningCount: number;
91
123
  skippedCount: number;
124
+ /** Per-section tallies for the checks the report carried, in SECTIONS order. */
125
+ sections: Array<{
126
+ section: string;
127
+ ok: number;
128
+ warn: number;
129
+ fail: number;
130
+ unknown: number;
131
+ }>;
132
+ /** Per-distro tallies in first-appearance order — the grouped summary. */
133
+ distros: DistroTally[];
134
+ /** Every check the report carried, in report order — the itemized listing. */
135
+ items: CheckItem[];
136
+ /** The scope the report answers for (quick profile or a section subset). */
137
+ scope?: {
138
+ sections: string[];
139
+ quick: boolean;
140
+ };
92
141
  distroVerdicts: Array<{
93
142
  name: string;
94
143
  verdict: string;
@@ -96,19 +145,54 @@ export interface DoctorDigest {
96
145
  }>;
97
146
  note: string;
98
147
  }
148
+ /**
149
+ * The section a check id belongs to. Mirrors `sectionOf` in
150
+ * `scripts/doctor.mjs` (the CLI's `--sections` filter reads that one); the
151
+ * parity is pinned by a test in `test/wsl-doctor-tool.test.mjs`, so a check
152
+ * cannot move sections on one side without the other noticing.
153
+ * @param id - the check id.
154
+ * @returns the section name.
155
+ */
156
+ export declare function sectionOf(id: string): "host" | "sandbox" | "session" | "conf" | "net" | "agent";
157
+ /** The sections in report order, matching the doctor CLI's SECTIONS list. */
158
+ export declare const SECTIONS: string[];
159
+ /**
160
+ * Every check id the doctor can emit — the CLI's whole probing surface,
161
+ * including the ids that only appear conditionally (`distro.present` for a
162
+ * configured-but-missing distro, `fix.git-trust` for a `--fix` run) and the
163
+ * `tools.*` ids the optional-tool loop constructs. The itemized listing uses
164
+ * this to show the checks a scoped (quick or section) run did NOT execute as
165
+ * explicit `[SKIP]` rows instead of silently dropping them; the parity test
166
+ * in `test/wsl-doctor-tool.test.mjs` re-extracts the ids from the CLI source
167
+ * and fails when the catalog drifts. A full run carries no scope, so a
168
+ * conditional id whose trigger never fired (no distro is missing, no
169
+ * `--fix`) also surfaces there under the generic `no scope recorded`
170
+ * reason — for those ids the honest reading is "did not fire", not
171
+ * "out of scope".
172
+ */
173
+ export declare const CHECK_CATALOG: readonly string[];
99
174
  /**
100
175
  * Digest one doctor report down to what the model acts on: the verdict, the
101
- * blockers, and every failing check with its copy-paste remedy. Warnings and
176
+ * blockers, every failing check with its copy-paste remedy, and the
177
+ * per-section tallies that make the passed checks visible (a bare verdict
178
+ * says nothing about what was tested — the sections do). Warnings and
102
179
  * skipped legs count but do not list — the report's own ids name them when
103
180
  * the model asks.
104
181
  * @param report - the collected (and live-merged) doctor report.
182
+ * @param sessionDistro - the distro this session runs in, when known; the
183
+ * matching tally is flagged so the rendered summary can name it.
105
184
  * @returns the digest.
106
185
  */
107
- export declare function digestReport(report: DoctorReportLike): DoctorDigest;
186
+ export declare function digestReport(report: DoctorReportLike, sessionDistro?: string): DoctorDigest;
108
187
  /**
109
- * Render the digest as the tool's text output: one verdict line, one line
110
- * per failing check with its remedy. The model narrates this; keeping it
111
- * plain text keeps the transcript readable.
188
+ * Render the digest as the tool's text output, in the style of a regular
189
+ * diagnostic tool: one verdict line, then an itemized listing — every check
190
+ * the report carried, grouped by distro, each with an explicit status marker
191
+ * (`[OK]` / `[WARN]` / `[FAIL]` / `[INFO]` / `[SKIP]` / `[??]`), its name and
192
+ * what it found. A failed check carries its copy-paste remedy on the next
193
+ * line; a warned check carries its detail, which is already the remedy's
194
+ * context. The model narrates this; keeping it plain text keeps the
195
+ * transcript readable.
112
196
  * @param digest - the digested report.
113
197
  * @returns the multi-line text.
114
198
  */
@@ -120,3 +204,4 @@ export declare function renderDigest(digest: DoctorDigest): string;
120
204
  * registry and the workingDirectory service are reachable).
121
205
  */
122
206
  export declare function apply(ctx: WslDoctorToolContext): Promise<void>;
207
+ export {};