dsh-plugin-wsl-env 0.19.0 → 0.22.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 +188 -1
- package/README.md +2 -2
- package/client.d.ts +5 -0
- package/client.js +218 -0
- package/cordis.patch.yml +75 -1
- package/docs/API.md +1 -0
- package/docs/CONFIGURATION.md +48 -5
- package/docs/CONFIGURATION.zh.md +15 -1
- package/docs/DIAGNOSTICS.md +110 -0
- package/docs/DIAGNOSTICS.zh.md +96 -0
- package/docs/LIMITATIONS.md +25 -0
- package/docs/LIMITATIONS.zh.md +7 -0
- package/docs/MIGRATION.md +1 -1
- package/docs/QUICKSTART.md +19 -3
- package/docs/RELEASING.md +3 -0
- package/docs/ROADMAP-1.0.md +49 -4
- package/docs/UPSTREAM-FILE-REFERENCE-SEAM.md +5 -0
- package/docs/UPSTREAM-OPEN-IN-APP.md +33 -0
- package/lib/client-host.d.ts +29 -0
- package/lib/client-host.js +29 -0
- package/lib/cwd-prompt-tool.d.ts +88 -0
- package/lib/cwd-prompt-tool.js +94 -0
- package/lib/cwd-prompt.d.ts +166 -0
- package/lib/cwd-prompt.js +203 -0
- package/lib/doctor-live.d.ts +5 -1
- package/lib/doctor-live.js +3 -2
- package/lib/index.d.ts +11 -0
- package/lib/index.js +10 -8
- package/lib/messages.d.ts +238 -0
- package/lib/messages.js +292 -0
- package/lib/preflight.d.ts +24 -0
- package/lib/preflight.js +111 -11
- package/lib/sandbox-core.js +7 -14
- package/lib/session-scope.js +10 -5
- package/lib/shell-env.d.ts +25 -0
- package/lib/shell-env.js +56 -0
- package/lib/shell.d.ts +3 -1
- package/lib/shell.js +3 -1
- package/lib/update-check.d.ts +197 -0
- package/lib/update-check.js +211 -0
- package/lib/wsl-doctor-command.d.ts +105 -0
- package/lib/wsl-doctor-command.js +240 -0
- package/lib/wsl-doctor-tool.d.ts +214 -0
- package/lib/wsl-doctor-tool.js +423 -0
- package/locale/doctor/en.json +30 -0
- package/locale/doctor/zh.json +30 -0
- package/package.json +47 -5
- package/scripts/doctor.mjs +1606 -171
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `wsl_doctor` tool: the model runs the environment doctor itself, and
|
|
3
|
+
* the verdict lands in the transcript — the GUI entry that belongs entirely
|
|
4
|
+
* to the plugin.
|
|
5
|
+
*
|
|
6
|
+
* The doctor is this package's own diagnostic (WSL-316); exposing it as a
|
|
7
|
+
* tool keeps the loop cohesive: no upstream surface is required, no file is
|
|
8
|
+
* written into the user's workspace, and the model gets a structured digest
|
|
9
|
+
* (verdict, blockers, per-failure copy-paste remedies) it can narrate or
|
|
10
|
+
* act on. The heavy lifting is {@link doctorReport} — the sanctioned
|
|
11
|
+
* in-process collector that spawns the shipped CLI once with the app's own
|
|
12
|
+
* runtime and folds the live resident's state in; the tool adds only the
|
|
13
|
+
* distro resolution and the digest.
|
|
14
|
+
*
|
|
15
|
+
* The distro comes from the caller when given, else from the agent's own
|
|
16
|
+
* session cwd through the harness's `workingDirectory` service — the same
|
|
17
|
+
* resolution the preflight performs, and the reason this row mounts inside
|
|
18
|
+
* the `preset-wsl` block: a host-preset agent has no distro to examine.
|
|
19
|
+
*
|
|
20
|
+
* This is a TypeScript source built to `lib/wsl-doctor-tool.js`; edit THIS
|
|
21
|
+
* file and run `pnpm run build` — the artifact under `lib/` is generated,
|
|
22
|
+
* and `pnpm test` fails when it drifts.
|
|
23
|
+
*
|
|
24
|
+
* @module dsh-plugin-wsl-env/wsl-doctor-tool
|
|
25
|
+
*/
|
|
26
|
+
export declare const name = "wsl-doctor-tool";
|
|
27
|
+
/**
|
|
28
|
+
* The context properties `apply` reads eagerly: the tool registry and the
|
|
29
|
+
* harness's `workingDirectory` service (the session's distro resolution).
|
|
30
|
+
* Cordis 4 refuses an undeclared read, so both must be named here. The doctor
|
|
31
|
+
* collector is deliberately NOT injected: no host row provides a `doctor`
|
|
32
|
+
* service, and a required inject would fail the whole preset mount; it is
|
|
33
|
+
* resolved per call through the optional `ctx.get` (which needs no inject)
|
|
34
|
+
* with the package's own `doctorReport` as the fallback — `doctorCollector`
|
|
35
|
+
* below.
|
|
36
|
+
*/
|
|
37
|
+
export declare const inject: string[];
|
|
38
|
+
/** The tool registry slice this service consumes. */
|
|
39
|
+
export interface ToolRegistrySlice {
|
|
40
|
+
register: (tool: unknown) => unknown;
|
|
41
|
+
}
|
|
42
|
+
/** The harness's `workingDirectory` service slice (cwd resolution). */
|
|
43
|
+
export interface WorkingDirectoryToolSlice {
|
|
44
|
+
ensure: (agent: unknown, signal?: unknown) => Promise<string>;
|
|
45
|
+
}
|
|
46
|
+
/** The doctor report this tool digests — the doctor CLI's versioned shape. */
|
|
47
|
+
export interface DoctorReportLike {
|
|
48
|
+
verdict?: string;
|
|
49
|
+
blockers?: string[];
|
|
50
|
+
distroVerdicts?: Array<{
|
|
51
|
+
name: string;
|
|
52
|
+
verdict: string;
|
|
53
|
+
blockers: string[];
|
|
54
|
+
}>;
|
|
55
|
+
checks?: Array<{
|
|
56
|
+
id: string;
|
|
57
|
+
status: string;
|
|
58
|
+
title?: string;
|
|
59
|
+
detail?: string;
|
|
60
|
+
remedy?: string;
|
|
61
|
+
distro?: string;
|
|
62
|
+
}>;
|
|
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
|
+
};
|
|
69
|
+
}
|
|
70
|
+
/** The doctor report collector: distro plus run scope in, report out. */
|
|
71
|
+
export type DoctorCollector = (distro: string, options?: {
|
|
72
|
+
quick?: boolean;
|
|
73
|
+
sections?: readonly string[];
|
|
74
|
+
}) => Promise<DoctorReportLike>;
|
|
75
|
+
/** The context slice this service consumes. */
|
|
76
|
+
export type WslDoctorToolContext = {
|
|
77
|
+
tools: ToolRegistrySlice;
|
|
78
|
+
workingDirectory: WorkingDirectoryToolSlice;
|
|
79
|
+
/** Optional cordis-style lookup: how production resolves `doctor` without an inject. */
|
|
80
|
+
get?: (name: string) => unknown;
|
|
81
|
+
/** The in-process collector: a provided `doctor` service, or the test seam's fake. */
|
|
82
|
+
doctor?: DoctorCollector;
|
|
83
|
+
};
|
|
84
|
+
/** The tool's config: the row takes no options. */
|
|
85
|
+
export interface WslDoctorToolConfig {
|
|
86
|
+
/** Reserved; the wrapper has no options today. */
|
|
87
|
+
enabled?: boolean;
|
|
88
|
+
}
|
|
89
|
+
/** One failing check as the digest carries it: what failed and what to do. */
|
|
90
|
+
export interface FailingCheck {
|
|
91
|
+
id: string;
|
|
92
|
+
detail: string;
|
|
93
|
+
remedy: string;
|
|
94
|
+
/** The distro the failing check ran in; absent for host-wide checks. */
|
|
95
|
+
distro?: string;
|
|
96
|
+
}
|
|
97
|
+
/** Per-distro tallies: what was tested in each distro and how it came out. */
|
|
98
|
+
export interface DistroTally {
|
|
99
|
+
name: string;
|
|
100
|
+
ok: number;
|
|
101
|
+
warn: number;
|
|
102
|
+
fail: number;
|
|
103
|
+
unknown: number;
|
|
104
|
+
info: number;
|
|
105
|
+
skipped: number;
|
|
106
|
+
/** This distro is the session's own — the run's primary subject. */
|
|
107
|
+
session?: boolean;
|
|
108
|
+
/** The distro's own verdict when the report carried one. */
|
|
109
|
+
verdict?: string;
|
|
110
|
+
}
|
|
111
|
+
/** One check as the itemized listing carries it: what was tested and how it came out. */
|
|
112
|
+
export interface CheckItem {
|
|
113
|
+
id: string;
|
|
114
|
+
/** The check's display name; falls back to the id when the report omits it. */
|
|
115
|
+
title: string;
|
|
116
|
+
status: string;
|
|
117
|
+
detail: string;
|
|
118
|
+
distro?: string;
|
|
119
|
+
remedy?: string;
|
|
120
|
+
}
|
|
121
|
+
/** The tool's result: the doctor's verdict, condensed for the model. */
|
|
122
|
+
export interface DoctorDigest {
|
|
123
|
+
verdict: string;
|
|
124
|
+
blockers: string[];
|
|
125
|
+
failing: FailingCheck[];
|
|
126
|
+
warningCount: number;
|
|
127
|
+
skippedCount: number;
|
|
128
|
+
/** Per-section tallies for the checks the report carried, in SECTIONS order. */
|
|
129
|
+
sections: Array<{
|
|
130
|
+
section: string;
|
|
131
|
+
ok: number;
|
|
132
|
+
warn: number;
|
|
133
|
+
fail: number;
|
|
134
|
+
unknown: number;
|
|
135
|
+
}>;
|
|
136
|
+
/** Per-distro tallies in first-appearance order — the grouped summary. */
|
|
137
|
+
distros: DistroTally[];
|
|
138
|
+
/** Every check the report carried, in report order — the itemized listing. */
|
|
139
|
+
items: CheckItem[];
|
|
140
|
+
/** The scope the report answers for (quick profile or a section subset). */
|
|
141
|
+
scope?: {
|
|
142
|
+
sections: string[];
|
|
143
|
+
quick: boolean;
|
|
144
|
+
};
|
|
145
|
+
distroVerdicts: Array<{
|
|
146
|
+
name: string;
|
|
147
|
+
verdict: string;
|
|
148
|
+
blockers: string[];
|
|
149
|
+
}>;
|
|
150
|
+
note: string;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* The section a check id belongs to. Mirrors `sectionOf` in
|
|
154
|
+
* `scripts/doctor.mjs` (the CLI's `--sections` filter reads that one); the
|
|
155
|
+
* parity is pinned by a test in `test/wsl-doctor-tool.test.mjs`, so a check
|
|
156
|
+
* cannot move sections on one side without the other noticing.
|
|
157
|
+
* @param id - the check id.
|
|
158
|
+
* @returns the section name.
|
|
159
|
+
*/
|
|
160
|
+
export declare function sectionOf(id: string): "host" | "sandbox" | "session" | "conf" | "net" | "agent";
|
|
161
|
+
/** The sections in report order, matching the doctor CLI's SECTIONS list. */
|
|
162
|
+
export declare const SECTIONS: string[];
|
|
163
|
+
/** The detail a scope-filtered skip row carries; the marker the renderer buckets on. */
|
|
164
|
+
export declare const SCOPE_SKIP_DETAIL = "not run in this scope";
|
|
165
|
+
/** The detail prefix a CLI-gated skip row carries (the blocker follows it). */
|
|
166
|
+
export declare const SKIP_DETAIL_PREFIX = "skipped: ";
|
|
167
|
+
/**
|
|
168
|
+
* Every check id the doctor can emit — the CLI's whole probing surface,
|
|
169
|
+
* including the ids that only appear conditionally (`distro.present` for a
|
|
170
|
+
* configured-but-missing distro, `fix.git-trust` for a `--fix` run) and the
|
|
171
|
+
* `tools.*` ids the optional-tool loop constructs. The itemized listing uses
|
|
172
|
+
* this to show the checks a scoped (quick or section) run did NOT execute as
|
|
173
|
+
* explicit `[SKIP]` rows instead of silently dropping them; the parity test
|
|
174
|
+
* in `test/wsl-doctor-tool.test.mjs` re-extracts the ids from the CLI source
|
|
175
|
+
* and fails when the catalog drifts. A full run carries no scope, so a
|
|
176
|
+
* conditional id whose trigger never fired (no distro is missing, no
|
|
177
|
+
* `--fix`) also surfaces there under the generic `no scope recorded`
|
|
178
|
+
* reason — for those ids the honest reading is "did not fire", not
|
|
179
|
+
* "out of scope".
|
|
180
|
+
*/
|
|
181
|
+
export declare const CHECK_CATALOG: readonly string[];
|
|
182
|
+
/**
|
|
183
|
+
* Digest one doctor report down to what the model acts on: the verdict, the
|
|
184
|
+
* blockers, every failing check with its copy-paste remedy, and the
|
|
185
|
+
* per-section tallies that make the passed checks visible (a bare verdict
|
|
186
|
+
* says nothing about what was tested — the sections do). Warnings and
|
|
187
|
+
* skipped legs count but do not list — the report's own ids name them when
|
|
188
|
+
* the model asks.
|
|
189
|
+
* @param report - the collected (and live-merged) doctor report.
|
|
190
|
+
* @param sessionDistro - the distro this session runs in, when known; the
|
|
191
|
+
* matching tally is flagged so the rendered summary can name it.
|
|
192
|
+
* @returns the digest.
|
|
193
|
+
*/
|
|
194
|
+
export declare function digestReport(report: DoctorReportLike, sessionDistro?: string): DoctorDigest;
|
|
195
|
+
/**
|
|
196
|
+
* Render the digest as the tool's text output, in the style of a regular
|
|
197
|
+
* diagnostic tool: one verdict line, then an itemized listing — every check
|
|
198
|
+
* the report carried, grouped by distro, each with an explicit status marker
|
|
199
|
+
* (`[OK]` / `[WARN]` / `[FAIL]` / `[INFO]` / `[SKIP]` / `[??]`), its name and
|
|
200
|
+
* what it found. A failed check carries its copy-paste remedy on the next
|
|
201
|
+
* line; a warned check carries its detail, which is already the remedy's
|
|
202
|
+
* context. The model narrates this; keeping it plain text keeps the
|
|
203
|
+
* transcript readable.
|
|
204
|
+
* @param digest - the digested report.
|
|
205
|
+
* @returns the multi-line text.
|
|
206
|
+
*/
|
|
207
|
+
export declare function renderDigest(digest: DoctorDigest): string;
|
|
208
|
+
/**
|
|
209
|
+
* Mount the tool.
|
|
210
|
+
*
|
|
211
|
+
* @param ctx - the cordis context (the preset realm, where the tools
|
|
212
|
+
* registry and the workingDirectory service are reachable).
|
|
213
|
+
*/
|
|
214
|
+
export declare function apply(ctx: WslDoctorToolContext): Promise<void>;
|
|
@@ -0,0 +1,423 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `wsl_doctor` tool: the model runs the environment doctor itself, and
|
|
3
|
+
* the verdict lands in the transcript — the GUI entry that belongs entirely
|
|
4
|
+
* to the plugin.
|
|
5
|
+
*
|
|
6
|
+
* The doctor is this package's own diagnostic (WSL-316); exposing it as a
|
|
7
|
+
* tool keeps the loop cohesive: no upstream surface is required, no file is
|
|
8
|
+
* written into the user's workspace, and the model gets a structured digest
|
|
9
|
+
* (verdict, blockers, per-failure copy-paste remedies) it can narrate or
|
|
10
|
+
* act on. The heavy lifting is {@link doctorReport} — the sanctioned
|
|
11
|
+
* in-process collector that spawns the shipped CLI once with the app's own
|
|
12
|
+
* runtime and folds the live resident's state in; the tool adds only the
|
|
13
|
+
* distro resolution and the digest.
|
|
14
|
+
*
|
|
15
|
+
* The distro comes from the caller when given, else from the agent's own
|
|
16
|
+
* session cwd through the harness's `workingDirectory` service — the same
|
|
17
|
+
* resolution the preflight performs, and the reason this row mounts inside
|
|
18
|
+
* the `preset-wsl` block: a host-preset agent has no distro to examine.
|
|
19
|
+
*
|
|
20
|
+
* This is a TypeScript source built to `lib/wsl-doctor-tool.js`; edit THIS
|
|
21
|
+
* file and run `pnpm run build` — the artifact under `lib/` is generated,
|
|
22
|
+
* and `pnpm test` fails when it drifts.
|
|
23
|
+
*
|
|
24
|
+
* @module dsh-plugin-wsl-env/wsl-doctor-tool
|
|
25
|
+
*/
|
|
26
|
+
import { defineTool } from "@deepseek-ai/dsh-tools";
|
|
27
|
+
import { distroOfUnc } from "./distro-route.js";
|
|
28
|
+
import { t } from "./messages.js";
|
|
29
|
+
import { doctorReport } from "./index.js";
|
|
30
|
+
export const name = "wsl-doctor-tool";
|
|
31
|
+
/**
|
|
32
|
+
* The context properties `apply` reads eagerly: the tool registry and the
|
|
33
|
+
* harness's `workingDirectory` service (the session's distro resolution).
|
|
34
|
+
* Cordis 4 refuses an undeclared read, so both must be named here. The doctor
|
|
35
|
+
* collector is deliberately NOT injected: no host row provides a `doctor`
|
|
36
|
+
* service, and a required inject would fail the whole preset mount; it is
|
|
37
|
+
* resolved per call through the optional `ctx.get` (which needs no inject)
|
|
38
|
+
* with the package's own `doctorReport` as the fallback — `doctorCollector`
|
|
39
|
+
* below.
|
|
40
|
+
*/
|
|
41
|
+
export const inject = ["tools", "workingDirectory"];
|
|
42
|
+
/**
|
|
43
|
+
* The section a check id belongs to. Mirrors `sectionOf` in
|
|
44
|
+
* `scripts/doctor.mjs` (the CLI's `--sections` filter reads that one); the
|
|
45
|
+
* parity is pinned by a test in `test/wsl-doctor-tool.test.mjs`, so a check
|
|
46
|
+
* cannot move sections on one side without the other noticing.
|
|
47
|
+
* @param id - the check id.
|
|
48
|
+
* @returns the section name.
|
|
49
|
+
*/
|
|
50
|
+
export function sectionOf(id) {
|
|
51
|
+
if (id.startsWith("sandbox.") || id === "functional.sandbox")
|
|
52
|
+
return "sandbox";
|
|
53
|
+
if (id.startsWith("session.") || id === "runtime.scopes" || id === "distro.wsl-conf-boot")
|
|
54
|
+
return "session";
|
|
55
|
+
if (id.startsWith("config.") || id === "distro.wsl-conf-interop" || id === "distro.wsl-conf-automount")
|
|
56
|
+
return "conf";
|
|
57
|
+
if (id === "distro.dns")
|
|
58
|
+
return "net";
|
|
59
|
+
if (id.startsWith("agent.") || id === "functional.exec" || id === "functional.fs")
|
|
60
|
+
return "agent";
|
|
61
|
+
return "host";
|
|
62
|
+
}
|
|
63
|
+
/** The sections in report order, matching the doctor CLI's SECTIONS list. */
|
|
64
|
+
export const SECTIONS = ["host", "sandbox", "session", "conf", "net", "agent"];
|
|
65
|
+
/** The pseudo-distro a check lands under when this run's scope never executed it. */
|
|
66
|
+
const NOT_RUN = "(not run)";
|
|
67
|
+
/** The detail a scope-filtered skip row carries; the marker the renderer buckets on. */
|
|
68
|
+
export const SCOPE_SKIP_DETAIL = "not run in this scope";
|
|
69
|
+
/** The detail prefix a CLI-gated skip row carries (the blocker follows it). */
|
|
70
|
+
export const SKIP_DETAIL_PREFIX = "skipped: ";
|
|
71
|
+
/**
|
|
72
|
+
* Every check id the doctor can emit — the CLI's whole probing surface,
|
|
73
|
+
* including the ids that only appear conditionally (`distro.present` for a
|
|
74
|
+
* configured-but-missing distro, `fix.git-trust` for a `--fix` run) and the
|
|
75
|
+
* `tools.*` ids the optional-tool loop constructs. The itemized listing uses
|
|
76
|
+
* this to show the checks a scoped (quick or section) run did NOT execute as
|
|
77
|
+
* explicit `[SKIP]` rows instead of silently dropping them; the parity test
|
|
78
|
+
* in `test/wsl-doctor-tool.test.mjs` re-extracts the ids from the CLI source
|
|
79
|
+
* and fails when the catalog drifts. A full run carries no scope, so a
|
|
80
|
+
* conditional id whose trigger never fired (no distro is missing, no
|
|
81
|
+
* `--fix`) also surfaces there under the generic `no scope recorded`
|
|
82
|
+
* reason — for those ids the honest reading is "did not fire", not
|
|
83
|
+
* "out of scope".
|
|
84
|
+
*/
|
|
85
|
+
export const CHECK_CATALOG = [
|
|
86
|
+
"agent.arch",
|
|
87
|
+
"agent.cache",
|
|
88
|
+
"agent.handshake",
|
|
89
|
+
"agent.native",
|
|
90
|
+
"config.deprecated",
|
|
91
|
+
"config.effective",
|
|
92
|
+
"config.preset-trap",
|
|
93
|
+
"config.profiles",
|
|
94
|
+
"config.wslconfig",
|
|
95
|
+
"distro.clock",
|
|
96
|
+
"distro.disk",
|
|
97
|
+
"distro.dns",
|
|
98
|
+
"distro.family",
|
|
99
|
+
"distro.home",
|
|
100
|
+
"distro.kernel",
|
|
101
|
+
"distro.present",
|
|
102
|
+
"distro.reachable",
|
|
103
|
+
"distro.shell",
|
|
104
|
+
"distro.wsl-conf-automount",
|
|
105
|
+
"distro.wsl-conf-boot",
|
|
106
|
+
"distro.wsl-conf-interop",
|
|
107
|
+
"distro.wsl-mode",
|
|
108
|
+
"fix.git-trust",
|
|
109
|
+
"functional.exec",
|
|
110
|
+
"functional.fs",
|
|
111
|
+
"functional.sandbox",
|
|
112
|
+
"git.win-safe",
|
|
113
|
+
"host.distros",
|
|
114
|
+
"host.windows",
|
|
115
|
+
"host.wsl",
|
|
116
|
+
"peers.versions",
|
|
117
|
+
"runtime.scopes",
|
|
118
|
+
"sandbox.bwrap",
|
|
119
|
+
"sandbox.bwrap-usable",
|
|
120
|
+
"session.linger",
|
|
121
|
+
"session.systemd",
|
|
122
|
+
"session.systemd-run",
|
|
123
|
+
"session.user-manager",
|
|
124
|
+
"tools.git",
|
|
125
|
+
"tools.inotifywait",
|
|
126
|
+
"tools.rg",
|
|
127
|
+
"update.latest",
|
|
128
|
+
];
|
|
129
|
+
/**
|
|
130
|
+
* Digest one doctor report down to what the model acts on: the verdict, the
|
|
131
|
+
* blockers, every failing check with its copy-paste remedy, and the
|
|
132
|
+
* per-section tallies that make the passed checks visible (a bare verdict
|
|
133
|
+
* says nothing about what was tested — the sections do). Warnings and
|
|
134
|
+
* skipped legs count but do not list — the report's own ids name them when
|
|
135
|
+
* the model asks.
|
|
136
|
+
* @param report - the collected (and live-merged) doctor report.
|
|
137
|
+
* @param sessionDistro - the distro this session runs in, when known; the
|
|
138
|
+
* matching tally is flagged so the rendered summary can name it.
|
|
139
|
+
* @returns the digest.
|
|
140
|
+
*/
|
|
141
|
+
export function digestReport(report, sessionDistro) {
|
|
142
|
+
const checks = report.checks ?? [];
|
|
143
|
+
const failing = checks
|
|
144
|
+
.filter((check) => check.status === "fail")
|
|
145
|
+
.map((check) => ({
|
|
146
|
+
id: check.id,
|
|
147
|
+
detail: check.detail ?? "",
|
|
148
|
+
remedy: check.remedy === undefined || check.remedy.length === 0 ? "no remedy — see docs/DIAGNOSTICS.md" : check.remedy,
|
|
149
|
+
...(check.distro === undefined ? {} : { distro: check.distro }),
|
|
150
|
+
}));
|
|
151
|
+
const blockers = report.blockers ?? failing.map((check) => check.id);
|
|
152
|
+
const verdict = report.verdict ?? (blockers.length === 0 ? "ready" : "blocked");
|
|
153
|
+
const warningCount = report.summary?.warn ?? checks.filter((check) => check.status === "warn").length;
|
|
154
|
+
const skippedCount = report.summary?.skipped ?? checks.filter((check) => check.status === "skipped").length;
|
|
155
|
+
const sections = SECTIONS
|
|
156
|
+
.map((section) => {
|
|
157
|
+
const rows = checks.filter((check) => sectionOf(check.id) === section && check.status !== "skipped");
|
|
158
|
+
const count = (status) => rows.filter((check) => check.status === status).length;
|
|
159
|
+
return {
|
|
160
|
+
section,
|
|
161
|
+
ok: count("ok"),
|
|
162
|
+
warn: count("warn"),
|
|
163
|
+
fail: count("fail"),
|
|
164
|
+
unknown: count("unknown"),
|
|
165
|
+
};
|
|
166
|
+
})
|
|
167
|
+
.filter((tally) => tally.ok + tally.warn + tally.fail + tally.unknown > 0);
|
|
168
|
+
// Per-distro tallies in first-appearance order. Host-wide checks carry no
|
|
169
|
+
// distro and group under "(host)" so the summary stays complete.
|
|
170
|
+
const distroVerdictByName = new Map(report.distroVerdicts?.map((row) => [row.name, row.verdict]) ?? []);
|
|
171
|
+
const distroMap = new Map();
|
|
172
|
+
for (const check of checks) {
|
|
173
|
+
const name = check.distro ?? "(host)";
|
|
174
|
+
let tally = distroMap.get(name);
|
|
175
|
+
if (tally === undefined) {
|
|
176
|
+
tally = { name, ok: 0, warn: 0, fail: 0, unknown: 0, info: 0, skipped: 0 };
|
|
177
|
+
distroMap.set(name, tally);
|
|
178
|
+
}
|
|
179
|
+
if (check.status === "ok")
|
|
180
|
+
tally.ok += 1;
|
|
181
|
+
else if (check.status === "warn")
|
|
182
|
+
tally.warn += 1;
|
|
183
|
+
else if (check.status === "fail")
|
|
184
|
+
tally.fail += 1;
|
|
185
|
+
else if (check.status === "unknown")
|
|
186
|
+
tally.unknown += 1;
|
|
187
|
+
else if (check.status === "info")
|
|
188
|
+
tally.info += 1;
|
|
189
|
+
else if (check.status === "skipped")
|
|
190
|
+
tally.skipped += 1;
|
|
191
|
+
}
|
|
192
|
+
const distros = [...distroMap.values()].map((tally) => {
|
|
193
|
+
const verdict = distroVerdictByName.get(tally.name);
|
|
194
|
+
return {
|
|
195
|
+
...tally,
|
|
196
|
+
...(sessionDistro !== undefined && tally.name === sessionDistro ? { session: true } : {}),
|
|
197
|
+
...(verdict === undefined ? {} : { verdict }),
|
|
198
|
+
};
|
|
199
|
+
});
|
|
200
|
+
return {
|
|
201
|
+
verdict,
|
|
202
|
+
blockers,
|
|
203
|
+
failing,
|
|
204
|
+
warningCount,
|
|
205
|
+
skippedCount,
|
|
206
|
+
sections,
|
|
207
|
+
distros,
|
|
208
|
+
items: (() => {
|
|
209
|
+
const rows = checks.map((check) => ({
|
|
210
|
+
id: check.id,
|
|
211
|
+
title: check.title ?? check.id,
|
|
212
|
+
status: check.status,
|
|
213
|
+
detail: check.detail ?? "",
|
|
214
|
+
...(check.distro === undefined ? {} : { distro: check.distro }),
|
|
215
|
+
...(check.remedy === undefined || check.remedy.length === 0
|
|
216
|
+
? check.status === "fail" ? { remedy: "no remedy — see docs/DIAGNOSTICS.md" } : {}
|
|
217
|
+
: { remedy: check.remedy }),
|
|
218
|
+
}));
|
|
219
|
+
// Scope the listing never drops silently: every catalog id the report
|
|
220
|
+
// did not carry joins the items as an explicit skip row, so a quick or
|
|
221
|
+
// section-scoped answer still shows the full check surface.
|
|
222
|
+
const reported = new Set(checks.map((check) => check.id));
|
|
223
|
+
for (const id of CHECK_CATALOG) {
|
|
224
|
+
if (reported.has(id))
|
|
225
|
+
continue;
|
|
226
|
+
rows.push({ id, title: id, status: "skipped", detail: SCOPE_SKIP_DETAIL, distro: NOT_RUN });
|
|
227
|
+
}
|
|
228
|
+
return rows;
|
|
229
|
+
})(),
|
|
230
|
+
...(report.scope === undefined ? {} : { scope: report.scope }),
|
|
231
|
+
distroVerdicts: report.distroVerdicts ?? [],
|
|
232
|
+
note: verdict === "ready"
|
|
233
|
+
? t("doctorDigestNoteReady", {})
|
|
234
|
+
: t("doctorDigestNoteBlocked", {}),
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Render the digest as the tool's text output, in the style of a regular
|
|
239
|
+
* diagnostic tool: one verdict line, then an itemized listing — every check
|
|
240
|
+
* the report carried, grouped by distro, each with an explicit status marker
|
|
241
|
+
* (`[OK]` / `[WARN]` / `[FAIL]` / `[INFO]` / `[SKIP]` / `[??]`), its name and
|
|
242
|
+
* what it found. A failed check carries its copy-paste remedy on the next
|
|
243
|
+
* line; a warned check carries its detail, which is already the remedy's
|
|
244
|
+
* context. The model narrates this; keeping it plain text keeps the
|
|
245
|
+
* transcript readable.
|
|
246
|
+
* @param digest - the digested report.
|
|
247
|
+
* @returns the multi-line text.
|
|
248
|
+
*/
|
|
249
|
+
export function renderDigest(digest) {
|
|
250
|
+
const lines = [t("doctorDigestVerdict", { verdict: digest.verdict.toUpperCase() })];
|
|
251
|
+
const mark = (status) => {
|
|
252
|
+
if (status === "ok")
|
|
253
|
+
return "[ OK ]";
|
|
254
|
+
if (status === "warn")
|
|
255
|
+
return "[WARN]";
|
|
256
|
+
if (status === "fail")
|
|
257
|
+
return "[FAIL]";
|
|
258
|
+
if (status === "info")
|
|
259
|
+
return "[INFO]";
|
|
260
|
+
if (status === "skipped")
|
|
261
|
+
return "[SKIP]";
|
|
262
|
+
return "[ ?? ]";
|
|
263
|
+
};
|
|
264
|
+
// Group the itemized listing by distro in first-appearance order; the
|
|
265
|
+
// session distro is labeled so the reader knows which group is "here".
|
|
266
|
+
const sessionName = digest.distros.find((tally) => tally.session)?.name;
|
|
267
|
+
const groups = [];
|
|
268
|
+
for (const item of digest.items) {
|
|
269
|
+
const name = item.distro ?? "(host)";
|
|
270
|
+
let group = groups.find((entry) => entry.name === name);
|
|
271
|
+
if (group === undefined) {
|
|
272
|
+
group = { name, items: [] };
|
|
273
|
+
groups.push(group);
|
|
274
|
+
}
|
|
275
|
+
group.items.push(item);
|
|
276
|
+
}
|
|
277
|
+
for (const group of groups) {
|
|
278
|
+
const tally = digest.distros.find((entry) => entry.name === group.name);
|
|
279
|
+
const label = group.name === "(host)"
|
|
280
|
+
? t("doctorDigestHostLabel", {})
|
|
281
|
+
: group.name === NOT_RUN
|
|
282
|
+
? t("doctorDigestNotRunLabel", {})
|
|
283
|
+
: sessionName !== undefined && group.name === sessionName ? t("doctorDigestSessionLabel", { name: group.name }) : group.name;
|
|
284
|
+
lines.push("", `== ${label} =`);
|
|
285
|
+
// Skip rows carry no actionable content — one summary line per group
|
|
286
|
+
// instead of one row per check, so the checks that actually ran keep
|
|
287
|
+
// the reader's attention. Two distinct reasons share the bucket and must
|
|
288
|
+
// not blur: out-of-scope checks (the run's profile never touched them)
|
|
289
|
+
// collapse into one line that names the scope's shape, while a failed
|
|
290
|
+
// prerequisite's gated smoke legs keep one line each — their blocker is
|
|
291
|
+
// the actionable fact.
|
|
292
|
+
const skipped = group.items.filter((item) => item.status === "skipped");
|
|
293
|
+
const scoped = skipped.filter((item) => item.detail === SCOPE_SKIP_DETAIL);
|
|
294
|
+
const gated = skipped.filter((item) => item.detail !== SCOPE_SKIP_DETAIL);
|
|
295
|
+
for (const item of group.items) {
|
|
296
|
+
if (item.status === "skipped")
|
|
297
|
+
continue;
|
|
298
|
+
const name = item.title === item.id ? item.id : `${item.id} — ${item.title}`;
|
|
299
|
+
lines.push(`${mark(item.status)} ${name}${item.detail.length > 0 ? `: ${item.detail}` : ""}`);
|
|
300
|
+
if (item.status === "fail" && item.remedy !== undefined && item.remedy.length > 0) {
|
|
301
|
+
lines.push(t("doctorDigestFixPrefix", { remedy: item.remedy }));
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
if (scoped.length > 0) {
|
|
305
|
+
const reason = digest.scope === undefined
|
|
306
|
+
? t("doctorSkipReasonGeneric", {})
|
|
307
|
+
: digest.scope.quick
|
|
308
|
+
? t("doctorSkipReasonQuick", {})
|
|
309
|
+
: t("doctorSkipReasonSections", { sections: digest.scope.sections.join(", ") });
|
|
310
|
+
lines.push(t("doctorDigestSkipRow", { n: scoped.length, reason, ids: scoped.map((item) => item.id).join(", ") }));
|
|
311
|
+
}
|
|
312
|
+
for (const item of gated) {
|
|
313
|
+
const detail = item.detail.startsWith(SKIP_DETAIL_PREFIX) ? item.detail.slice(SKIP_DETAIL_PREFIX.length) : item.detail;
|
|
314
|
+
lines.push(t("doctorSkipGated", { id: item.id, reason: detail }));
|
|
315
|
+
}
|
|
316
|
+
if (tally !== undefined) {
|
|
317
|
+
const counts = [];
|
|
318
|
+
if (tally.ok > 0)
|
|
319
|
+
counts.push(t("doctorTallyOk", { n: tally.ok }));
|
|
320
|
+
if (tally.warn > 0)
|
|
321
|
+
counts.push(t("doctorTallyWarn", { n: tally.warn }));
|
|
322
|
+
if (tally.fail > 0)
|
|
323
|
+
counts.push(t("doctorTallyFail", { n: tally.fail }));
|
|
324
|
+
if (tally.unknown > 0)
|
|
325
|
+
counts.push(t("doctorTallyUnknown", { n: tally.unknown }));
|
|
326
|
+
if (tally.info > 0)
|
|
327
|
+
counts.push(t("doctorTallyInfo", { n: tally.info }));
|
|
328
|
+
if (tally.skipped > 0)
|
|
329
|
+
counts.push(t("doctorTallySkipped", { n: tally.skipped }));
|
|
330
|
+
if (counts.length > 0)
|
|
331
|
+
lines.push(`-- ${counts.join(", ")}`);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
const blockers = digest.failing.map((check) => check.distro !== undefined && digest.distros.length > 1 ? `${check.distro}/${check.id}` : check.id);
|
|
335
|
+
if (digest.failing.length === 0) {
|
|
336
|
+
lines.push("", digest.note);
|
|
337
|
+
}
|
|
338
|
+
else {
|
|
339
|
+
lines.push("", t("doctorDigestBlockedTail", { blockers: blockers.join(", "), warnings: digest.warningCount, skipped: digest.skippedCount, note: digest.note }));
|
|
340
|
+
}
|
|
341
|
+
return lines.join("\n");
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* The doctor collector this run uses. No host row provides a `doctor`
|
|
345
|
+
* service, so a required inject would fail the whole preset mount; the
|
|
346
|
+
* collector resolves per call instead: a provided `doctor` service through
|
|
347
|
+
* the optional `ctx.get` (cordis answers undefined for an absent name, and a
|
|
348
|
+
* `get` needs no inject), else the plain `doctor` property (the test seam),
|
|
349
|
+
* else the package's own `doctorReport` — the sanctioned in-process
|
|
350
|
+
* collector, imported from the composition root.
|
|
351
|
+
*
|
|
352
|
+
* @param ctx - the cordis context the row mounted in.
|
|
353
|
+
* @returns the collector: distro in, versioned doctor report out.
|
|
354
|
+
*/
|
|
355
|
+
async function doctorCollector(ctx) {
|
|
356
|
+
if (typeof ctx.get === "function") {
|
|
357
|
+
const provided = ctx.get("doctor");
|
|
358
|
+
if (typeof provided === "function")
|
|
359
|
+
return provided; // the provided service's contract is this module's `doctor` slice
|
|
360
|
+
}
|
|
361
|
+
else if (typeof ctx.doctor === "function") {
|
|
362
|
+
return ctx.doctor;
|
|
363
|
+
}
|
|
364
|
+
return doctorReport;
|
|
365
|
+
}
|
|
366
|
+
/**
|
|
367
|
+
* Mount the tool.
|
|
368
|
+
*
|
|
369
|
+
* @param ctx - the cordis context (the preset realm, where the tools
|
|
370
|
+
* registry and the workingDirectory service are reachable).
|
|
371
|
+
*/
|
|
372
|
+
export async function apply(ctx) {
|
|
373
|
+
ctx.tools.register(defineTool({
|
|
374
|
+
name: "wsl_doctor",
|
|
375
|
+
description: "Run the WSL environment doctor for this session's distro and return the verdict: ready (the first command should succeed), or blocked with per-failure copy-paste remedies. Interactive by design: start with depth \"quick\" (prerequisites only, ~10 s) and narrate the result, then narrow with \"section\" (one of host/sandbox/session/conf/net/agent) or run depth \"full\" only when the user asked for a complete diagnosis — each call probes its scope and itemizes every check it tested with an explicit status marker, grouped by distro.",
|
|
376
|
+
parameters: {
|
|
377
|
+
distro: {
|
|
378
|
+
type: "string",
|
|
379
|
+
description: "Distro to examine. Omit to examine this session's own distro.",
|
|
380
|
+
},
|
|
381
|
+
depth: {
|
|
382
|
+
type: "string",
|
|
383
|
+
enum: ["quick", "full"],
|
|
384
|
+
description: "quick (default): prerequisites only (~10 s) — the right first call. full: every check including the agent smokes and the registry update query — pass it only when the user asked for a complete diagnosis.",
|
|
385
|
+
},
|
|
386
|
+
section: {
|
|
387
|
+
type: "string",
|
|
388
|
+
enum: ["host", "sandbox", "session", "conf", "net", "agent"],
|
|
389
|
+
description: "Restrict the run to one section for a focused follow-up (e.g. session to re-check systemd/linger after a fix). Overrides depth.",
|
|
390
|
+
},
|
|
391
|
+
},
|
|
392
|
+
output: {
|
|
393
|
+
schema: {
|
|
394
|
+
type: "object",
|
|
395
|
+
additionalProperties: false,
|
|
396
|
+
properties: {
|
|
397
|
+
verdict: { type: "string", required: true, description: "ready or blocked." },
|
|
398
|
+
blockers: { type: "string", required: true, description: "Comma-separated blocking check ids; empty when ready." },
|
|
399
|
+
report: { type: "string", required: true, description: "Itemized per-check listing grouped by distro — each check with an explicit [OK]/[WARN]/[FAIL] status marker, what it found, and the copy-paste fix for every failure." },
|
|
400
|
+
},
|
|
401
|
+
},
|
|
402
|
+
render: (_args, value) => [{ type: "text", text: value.report }],
|
|
403
|
+
},
|
|
404
|
+
async execute(args, exec) {
|
|
405
|
+
const argv = args;
|
|
406
|
+
let distro = argv.distro ?? "";
|
|
407
|
+
if (distro.length === 0) {
|
|
408
|
+
if (exec.agent === undefined)
|
|
409
|
+
throw new Error("wsl_doctor requires an agent Session (or an explicit distro)");
|
|
410
|
+
const cwd = await ctx.workingDirectory.ensure(exec.agent, exec.signal);
|
|
411
|
+
distro = distroOfUnc(cwd) ?? "";
|
|
412
|
+
}
|
|
413
|
+
if (distro.length === 0) {
|
|
414
|
+
throw new Error("wsl_doctor could not resolve the session's distro from its working directory — pass one explicitly");
|
|
415
|
+
}
|
|
416
|
+
const quick = argv.section === undefined || argv.section.length === 0 ? argv.depth !== "full" : false;
|
|
417
|
+
const sections = argv.section !== undefined && argv.section.length > 0 ? [argv.section] : undefined;
|
|
418
|
+
const doctor = await doctorCollector(ctx);
|
|
419
|
+
const digest = digestReport(await doctor(distro, { ...(quick ? { quick: true } : {}), ...(sections !== undefined ? { sections } : {}) }), distro);
|
|
420
|
+
return { verdict: digest.verdict, blockers: digest.blockers.join(", "), report: renderDigest(digest) };
|
|
421
|
+
}
|
|
422
|
+
}));
|
|
423
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"app": "dsh-plugin-wsl-env doctor",
|
|
3
|
+
"mark.ok": "ok ",
|
|
4
|
+
"mark.warn": "warn",
|
|
5
|
+
"mark.fail": "fail",
|
|
6
|
+
"mark.skipped": "skip",
|
|
7
|
+
"mark.unknown": "unkn",
|
|
8
|
+
"mark.info": "info",
|
|
9
|
+
"summary": "{ok} ok, {warn} warn, {fail} fail, {info} info",
|
|
10
|
+
"summary.skipped": ", {n} skipped",
|
|
11
|
+
"summary.unknown": ", {n} unknown (transport flakes — rerun for a verdict)",
|
|
12
|
+
"timings": "timings: {line}; total {total}ms",
|
|
13
|
+
"verdict.ready.none": "verdict: READY — the first command should succeed",
|
|
14
|
+
"verdict.ready.one": "verdict: READY — the first command should succeed in {target}",
|
|
15
|
+
"verdict.ready.many": "verdict: READY — the first command should succeed in each of: {targets}",
|
|
16
|
+
"verdict.blocked": "verdict: BLOCKED by: {blockers} — apply the fixes above, then rerun",
|
|
17
|
+
"fix.prefix": " fix: {remedy}",
|
|
18
|
+
"fix.hint": "run with --fix to sweep stale scopes; --fix --install asks before installing packages",
|
|
19
|
+
"sessions.title": "sessions across running distros",
|
|
20
|
+
"sessions.none": " (none)",
|
|
21
|
+
"sessions.no-user-manager": "no user manager — scopes unavailable",
|
|
22
|
+
"sessions.no-scopes": "no session scopes",
|
|
23
|
+
"ports.title": "listening ports in {distro}",
|
|
24
|
+
"ports.none": "\nno listening ports in the running distros",
|
|
25
|
+
"bundle.written": "bundle: written to {path} ({bytes} bytes{redacted})",
|
|
26
|
+
"bundle.redacted": ", redacted",
|
|
27
|
+
"refusal.read-only": "doctor: --read-only refuses --fix/--install; run `pnpm run doctor --fix` instead",
|
|
28
|
+
"refusal.scoped-fix": "doctor: --fix needs a full run — a scoped run cannot re-verify what it did not probe",
|
|
29
|
+
"confirm.install": "Install {packages} in \"{distro}\" as root?"
|
|
30
|
+
}
|