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.
- package/CHANGELOG.md +119 -0
- package/CONTRIBUTING.md +7 -3
- package/README.md +11 -9
- package/SUPPORT.md +1 -1
- package/client.js +153 -33
- package/cordis.patch.yml +13 -4
- package/docs/AGENT-PROTOCOL-V7.md +4 -4
- package/docs/API.md +12 -2
- package/docs/ARCHITECTURE.md +59 -19
- package/docs/CONFIGURATION.md +44 -13
- package/docs/CONFIGURATION.zh.md +44 -8
- package/docs/DIAGNOSTICS.md +41 -1
- package/docs/DIAGNOSTICS.zh.md +34 -2
- package/docs/LIMITATIONS.md +42 -17
- package/docs/LIMITATIONS.zh.md +47 -12
- package/docs/MIGRATION.md +1 -1
- package/docs/PEER-PARITY.md +8 -7
- package/docs/QUICKSTART.md +16 -8
- package/docs/QUICKSTART.zh.md +22 -4
- package/docs/README.zh.md +19 -10
- package/docs/RELEASING.md +8 -3
- package/docs/REQUIREMENTS.zh.md +11 -6
- package/docs/ROADMAP-1.0.md +12 -11
- package/docs/ROADMAP.md +10 -8
- package/docs/UPSTREAM-FILE-REFERENCE-SEAM.md +3 -2
- package/docs/UPSTREAM-FSIO-EXPORT.md +8 -9
- package/docs/UPSTREAM-SERVICE-SWAP.md +9 -5
- package/docs/UPSTREAM-TERMINAL-TITLE.md +9 -8
- package/docs/VALUE.zh.md +5 -5
- package/docs/root-fs-routing.md +26 -19
- package/lib/agent-confined.d.ts +2 -2
- package/lib/agent-confined.js +0 -1
- package/lib/agent-exec.d.ts +2 -11
- package/lib/agent-protocol.d.ts +6 -5
- package/lib/agent.d.ts +5 -5
- package/lib/auto-preset.d.ts +4 -3
- package/lib/bwrap.d.ts +2 -1
- package/lib/client-host.d.ts +1 -1
- package/lib/client-host.js +1 -1
- package/lib/cwd-prompt-tool.d.ts +4 -20
- package/lib/cwd-prompt.d.ts +11 -10
- package/lib/distro-route.d.ts +3 -2
- package/lib/doctor-live.d.ts +2 -1
- package/lib/fs-routing.d.ts +29 -1
- package/lib/fs-routing.js +30 -3
- package/lib/fs-substrate.d.ts +0 -1
- package/lib/fs-substrate.js +0 -1
- package/lib/fsio-agent.d.ts +3 -21
- package/lib/fsio-agent.js +2 -4
- package/lib/git-exec.d.ts +3 -2
- package/lib/git-route.d.ts +4 -2
- package/lib/git-route.js +4 -2
- package/lib/index.d.ts +20 -10
- package/lib/index.js +128 -12
- package/lib/listing.d.ts +2 -1
- package/lib/messages.d.ts +82 -1
- package/lib/messages.js +94 -1
- package/lib/native-agent.d.ts +3 -2
- package/lib/paths.d.ts +2 -1
- package/lib/picker.d.ts +1 -14
- package/lib/picker.js +1 -2
- package/lib/preflight.d.ts +5 -4
- package/lib/probe-cache.d.ts +2 -1
- package/lib/sandbox-core.d.ts +2 -11
- package/lib/sandbox-core.js +1 -1
- package/lib/sandbox.d.ts +0 -1
- package/lib/sandbox.js +0 -4
- package/lib/search-exec.d.ts +2 -1
- package/lib/session-runtime.d.ts +3 -2
- package/lib/shell-env.d.ts +3 -2
- package/lib/shell.d.ts +1 -1
- package/lib/shell.js +1 -1
- package/lib/subprocess.d.ts +1 -1
- package/lib/update-check.d.ts +3 -3
- package/lib/wsl-doctor-command.d.ts +133 -0
- package/lib/wsl-doctor-command.js +381 -0
- package/lib/wsl-doctor-tool.d.ts +101 -16
- package/lib/wsl-doctor-tool.js +290 -22
- package/lib/wsl.d.ts +3 -2
- package/locale/doctor/en.json +30 -0
- package/locale/doctor/zh.json +30 -0
- package/package.json +29 -31
- package/scripts/bootstrap-import.sh +189 -0
- package/scripts/doctor.mjs +569 -141
- package/scripts/open-wsl-vscode.ps1 +36 -0
- package/examples/preset-wsl-session-sandbox.cordis.patch.yml +0 -178
package/scripts/doctor.mjs
CHANGED
|
@@ -20,7 +20,9 @@
|
|
|
20
20
|
* config-awareness downgrades a check's *status* (a missing systemd only fails
|
|
21
21
|
* under `sessionSandbox: true`; `auto` and `false` downgrade it to a warning),
|
|
22
22
|
* so there is no per-id exception table to drift. `skipped` marks a check that
|
|
23
|
-
* could not run because another check failed.
|
|
23
|
+
* could not run because another check failed. `unknown` marks a read the
|
|
24
|
+
* wsl.exe transport could not vouch for (a flake that survived one retry) —
|
|
25
|
+
* it never blocks and never feeds a config verdict; rerun for a clean answer. `--fix` performs only safe
|
|
24
26
|
* actions: it sweeps stale `dsh-wsl-*.scope` units (the same sweep the session
|
|
25
27
|
* preflight runs). Installing packages needs `--install` *and* an explicit
|
|
26
28
|
* confirmation (`--yes` skips the prompt, not the flag), so a fix run can never
|
|
@@ -34,6 +36,13 @@
|
|
|
34
36
|
* `distroVerdicts`, the effective `config`, and per-check `distro` /
|
|
35
37
|
* `blocksFirstCommand` fields.
|
|
36
38
|
*
|
|
39
|
+
* The doctor is the standalone surface by design: it loads **no peer
|
|
40
|
+
* dependency and no host service**, so it still starts when the plugin's own
|
|
41
|
+
* runtime is the thing that is broken (the chicken-and-egg failure the
|
|
42
|
+
* in-process tool path cannot escape). Only pure, peer-free lib modules are
|
|
43
|
+
* imported; the two helpers that lived behind peer-tainted modules are inlined
|
|
44
|
+
* below and drift-pinned by test.
|
|
45
|
+
*
|
|
37
46
|
* This CLI always probes a **fresh** resident — the app process's live
|
|
38
47
|
* resident's `deaths`/`lastError` are host-private (no IPC), and the report
|
|
39
48
|
* says so at the handshake check. Consumers holding the plugin's context
|
|
@@ -50,13 +59,147 @@ import { homedir } from "node:os";
|
|
|
50
59
|
import { dirname, join, resolve } from "node:path";
|
|
51
60
|
import { createInterface } from "node:readline/promises";
|
|
52
61
|
import { fileURLToPath } from "node:url";
|
|
62
|
+
// Pure, peer-free lib modules stay imported: `lint:build` pins them byte-for-byte
|
|
63
|
+
// to `src/`, so the doctor probes exactly the shipped behavior without loading
|
|
64
|
+
// any peer dependency (see the inlining note below).
|
|
53
65
|
import { parseDistroList } from "../lib/wsl.js";
|
|
54
|
-
import { effectiveMaskWindowsDrive } from "../lib/index.js";
|
|
55
66
|
import { AGENT_NAME, PROTOCOL_VERSION, encodeExecFrame, encodeFsbFrame, parseAgentLine } from "../lib/agent-protocol.js";
|
|
56
67
|
import { bwrapArgvPrefix } from "../lib/bwrap.js";
|
|
57
68
|
import { sessionScopeSweepScript } from "../lib/session-scope.js";
|
|
58
69
|
import { parseListeningPorts, procNetScript } from "../lib/ports.js";
|
|
59
|
-
|
|
70
|
+
|
|
71
|
+
// ── Peer-free inlining of the two peer-tainted helpers ────────────────────────
|
|
72
|
+
//
|
|
73
|
+
// The doctor must start even when the plugin's runtime is the thing that is
|
|
74
|
+
// broken. Two of the lib modules it used to import are unsafe for that:
|
|
75
|
+
//
|
|
76
|
+
// - `lib/index.js` pulls the whole plugin graph and every `@deepseek-ai/dsh-*`
|
|
77
|
+
// peer dependency at load time;
|
|
78
|
+
// - `lib/update-check.js` imports `@deepseek-ai/schemastery` at the top level.
|
|
79
|
+
//
|
|
80
|
+
// Both helpers are pure two-liners, so they are inlined here instead. A test in
|
|
81
|
+
// `test/doctor.test.mjs` compares these copies against the lib exports to pin
|
|
82
|
+
// them against drift.
|
|
83
|
+
//
|
|
84
|
+
// Inlined from `src/index.ts` `effectiveMaskWindowsDrive`:
|
|
85
|
+
/**
|
|
86
|
+
* Whether confined profiles shadow `/mnt` under this config.
|
|
87
|
+
*
|
|
88
|
+
* @param {{ interopVisibility?: "visible" | "masked" | "disabled", maskWindowsDrive?: boolean }} config - anything carrying the two keys.
|
|
89
|
+
* @returns {boolean} whether confined profiles shadow `/mnt`.
|
|
90
|
+
*/
|
|
91
|
+
export function effectiveMaskWindowsDrive(config) {
|
|
92
|
+
if (config.interopVisibility !== undefined) return config.interopVisibility !== "visible";
|
|
93
|
+
return config.maskWindowsDrive === true;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Inlined from `src/update-check.ts` `updateFactMessage`:
|
|
97
|
+
/**
|
|
98
|
+
* One human line about an available update.
|
|
99
|
+
*
|
|
100
|
+
* @param {{ latest: string, installed: string, incompatible?: boolean, deprecated?: string, checkedAt?: number } | undefined} update - the update fact, or undefined when none.
|
|
101
|
+
* @returns {string} the message, empty when there is no update.
|
|
102
|
+
*/
|
|
103
|
+
export function updateFactMessage(update) {
|
|
104
|
+
if (update === undefined) return "";
|
|
105
|
+
const marks = [];
|
|
106
|
+
if (update.incompatible) marks.push("requires a newer DSH first");
|
|
107
|
+
if (update.deprecated !== undefined) marks.push(`deprecated: ${update.deprecated}`);
|
|
108
|
+
const tail = marks.length === 0 ? "" : ` — ${marks.join("; ")}`;
|
|
109
|
+
return `${update.latest} available (installed ${update.installed})${tail}`;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// ── Host-locale output catalogs ──────────────────────────────────────────────
|
|
113
|
+
//
|
|
114
|
+
// The human output renders in the host's language: the doctor detects the
|
|
115
|
+
// Windows locale through the registry (fast, no PowerShell startup), the
|
|
116
|
+
// `--locale` flag and `DSH_WSL_DOCTOR_LOCALE` override it, and `--json` stays
|
|
117
|
+
// language-independent. Only the fixed skeleton is cataloged (verdict,
|
|
118
|
+
// summary, section marks, hints); per-check titles/details/remedies stay
|
|
119
|
+
// English — remedies carry copy-paste commands. The catalogs live in
|
|
120
|
+
// `locale/doctor/{en,zh}.json`; a test pins their key parity.
|
|
121
|
+
|
|
122
|
+
/** The languages the doctor's own catalogs ship. @type {Record<string, Record<string, string> | undefined>} */
|
|
123
|
+
const CATALOGS = {};
|
|
124
|
+
/** The active catalog language; English until a detection or flag selects otherwise. */
|
|
125
|
+
let LOCALE = "en";
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Load one catalog, falling back to the English file when the requested one
|
|
129
|
+
* is missing or unreadable (a truncated install must not break the run).
|
|
130
|
+
*
|
|
131
|
+
* @param {string} name - the catalog language id.
|
|
132
|
+
* @returns {Record<string, string>} the catalog table.
|
|
133
|
+
*/
|
|
134
|
+
function doctorCatalog(name) {
|
|
135
|
+
if (CATALOGS[name] === undefined) {
|
|
136
|
+
try {
|
|
137
|
+
CATALOGS[name] = JSON.parse(readFileSync(join(ROOT, "locale", "doctor", `${name}.json`), "utf8"));
|
|
138
|
+
} catch {
|
|
139
|
+
CATALOGS[name] = {};
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return CATALOGS[name] ?? {};
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Select the output language. `zh` requires its catalog to have loaded; any
|
|
147
|
+
* other id renders English.
|
|
148
|
+
*
|
|
149
|
+
* @param {string} name - the requested language id.
|
|
150
|
+
*/
|
|
151
|
+
export function setDoctorLocale(name) {
|
|
152
|
+
LOCALE = name === "zh" && Object.keys(doctorCatalog("zh")).length > 0 ? "zh" : "en";
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Render one catalog message in the active language, substituting
|
|
157
|
+
* `{placeholder}` tokens; a key the active catalog lacks falls back to the
|
|
158
|
+
* English entry.
|
|
159
|
+
*
|
|
160
|
+
* @param {string} key - the catalog key.
|
|
161
|
+
* @param {Record<string, string | number>} [params] - the placeholder values.
|
|
162
|
+
* @returns {string} the rendered line.
|
|
163
|
+
*/
|
|
164
|
+
export function doctorT(key, params = {}) {
|
|
165
|
+
const template = doctorCatalog(LOCALE)[key] ?? doctorCatalog("en")[key] ?? key;
|
|
166
|
+
return template.replace(/\{(\w+)\}/gu, (whole, name) => (params[name] === undefined ? whole : String(params[name])));
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Extract the locale name from a `reg query ... /v LocaleName` answer.
|
|
171
|
+
*
|
|
172
|
+
* @param {string} text - the command's stdout.
|
|
173
|
+
* @returns {string} the `LocaleName` value, or "" when the answer names none.
|
|
174
|
+
*/
|
|
175
|
+
export function localeNameFromReg(text) {
|
|
176
|
+
const match = text.match(/LocaleName\s+REG_SZ\s+(\S+)/);
|
|
177
|
+
return match === null ? "" : match[1] ?? "";
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Map a BCP 47-style tag onto a catalog language: `zh*` renders Chinese,
|
|
182
|
+
* everything else English.
|
|
183
|
+
*
|
|
184
|
+
* @param {string} tag - the locale tag (may be empty).
|
|
185
|
+
* @returns {"en" | "zh"} the catalog language.
|
|
186
|
+
*/
|
|
187
|
+
export function localeFromTag(tag) {
|
|
188
|
+
return /^zh/iu.test(tag) ? "zh" : "en";
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Resolve the output language: the `--locale` flag wins, then
|
|
193
|
+
* `DSH_WSL_DOCTOR_LOCALE`, then English (the caller probes the registry only
|
|
194
|
+
* when neither override is set).
|
|
195
|
+
*
|
|
196
|
+
* @param {string} flag - the `--locale` value, possibly empty.
|
|
197
|
+
* @returns {"en" | "zh"} the catalog language the overrides select, when they select one.
|
|
198
|
+
*/
|
|
199
|
+
export function overrideLocale(flag) {
|
|
200
|
+
const tag = flag.length > 0 ? flag : process.env.DSH_WSL_DOCTOR_LOCALE ?? "";
|
|
201
|
+
return tag.length > 0 ? localeFromTag(tag) : "en";
|
|
202
|
+
}
|
|
60
203
|
|
|
61
204
|
const ROOT = resolve(dirname(fileURLToPath(import.meta.url)), "..");
|
|
62
205
|
let WSL = "wsl.exe";
|
|
@@ -104,7 +247,10 @@ const CACHE_REPORT = [
|
|
|
104
247
|
* One check result.
|
|
105
248
|
* @typedef {object} Check
|
|
106
249
|
* @property {string} id - stable dotted id.
|
|
107
|
-
* @property {"ok"|"warn"|"fail"|"info"|"skipped"} status - the verdict.
|
|
250
|
+
* @property {"ok"|"warn"|"fail"|"info"|"skipped"|"unknown"} status - the verdict.
|
|
251
|
+
* `unknown` marks a read the transport could not vouch for (a wsl.exe flake
|
|
252
|
+
* that survived one retry): it never blocks, and it never feeds a config
|
|
253
|
+
* verdict — a flaked read of `wsl.conf` must not report the file broken.
|
|
108
254
|
* @property {string} title - what was checked.
|
|
109
255
|
* @property {string} [detail] - the evidence.
|
|
110
256
|
* @property {string} [remedy] - a copy-paste next step when not ok.
|
|
@@ -112,6 +258,30 @@ const CACHE_REPORT = [
|
|
|
112
258
|
* @property {boolean} [blocksFirstCommand] - whether a `fail` here blocks the first command (stamped by `report()`: true for every `fail`; config-awareness downgrades statuses rather than keeping a per-id exception table).
|
|
113
259
|
*/
|
|
114
260
|
|
|
261
|
+
/** The check sections a scoped run can select, in the order the tool names them. */
|
|
262
|
+
export const SECTIONS = ["host", "sandbox", "session", "conf", "net", "agent"];
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* The section one check id belongs to — the single mapping the CLI's
|
|
266
|
+
* `--sections` filter and the `wsl_doctor` tool's per-section summary both
|
|
267
|
+
* read, so a tool digest and the report can never disagree about where a
|
|
268
|
+
* check lives. `host` is the default: the cheap environment basics every
|
|
269
|
+
* scoped run still probes.
|
|
270
|
+
* @param {string} id - the check id.
|
|
271
|
+
* @returns {"host"|"sandbox"|"session"|"conf"|"net"|"agent"} the section.
|
|
272
|
+
*/
|
|
273
|
+
export function sectionOf(id) {
|
|
274
|
+
if (id.startsWith("sandbox.") || id === "functional.sandbox") return "sandbox";
|
|
275
|
+
if (id.startsWith("session.") || id === "runtime.scopes" || id === "distro.wsl-conf-boot") return "session";
|
|
276
|
+
if (id.startsWith("config.") || id === "distro.wsl-conf-interop" || id === "distro.wsl-conf-automount") return "conf";
|
|
277
|
+
if (id === "distro.dns") return "net";
|
|
278
|
+
if (id.startsWith("agent.") || id === "functional.exec" || id === "functional.fs") return "agent";
|
|
279
|
+
return "host";
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/** The sections a `--quick` run selects: first-command prerequisites only. */
|
|
283
|
+
const QUICK_SECTIONS = ["host", "session", "sandbox"];
|
|
284
|
+
|
|
115
285
|
/**
|
|
116
286
|
* The effective configuration the blocking verdict answers under.
|
|
117
287
|
* @typedef {object} EffectiveConfig
|
|
@@ -128,7 +298,7 @@ const CACHE_REPORT = [
|
|
|
128
298
|
/**
|
|
129
299
|
* Run one host command; never throws.
|
|
130
300
|
* @param {string[]} argv - executable and arguments.
|
|
131
|
-
* @returns {Promise<{ ok: boolean, stdout: string, stderr: string, code?: string }>} the capture.
|
|
301
|
+
* @returns {Promise<{ ok: boolean, stdout: string, stderr: string, code?: string, timedOut?: boolean }>} the capture.
|
|
132
302
|
*/
|
|
133
303
|
function run(argv) {
|
|
134
304
|
return new Promise((settle) => {
|
|
@@ -141,7 +311,8 @@ function run(argv) {
|
|
|
141
311
|
*/
|
|
142
312
|
const done = (error, stdout, stderr) => {
|
|
143
313
|
const code = error === null ? undefined : /** @type {NodeJS.ErrnoException} */ (error).code ?? "1";
|
|
144
|
-
|
|
314
|
+
const timedOut = error !== null && /** @type {NodeJS.ErrnoException & { signal?: string }} */ (error).signal === "SIGTERM";
|
|
315
|
+
settle({ ok: error === null, stdout: stdout ?? "", stderr: stderr ?? "", code, timedOut });
|
|
145
316
|
};
|
|
146
317
|
execFile(file, args, { encoding: "utf8", timeout: TIMEOUT_MS, windowsHide: true, env: { ...process.env, WSL_UTF8: "1" } }, done);
|
|
147
318
|
});
|
|
@@ -401,10 +572,46 @@ function inDistro(distro, script) {
|
|
|
401
572
|
return run([WSL, "-d", distro, "--exec", "sh", "-c", script]);
|
|
402
573
|
}
|
|
403
574
|
|
|
575
|
+
/**
|
|
576
|
+
* Whether one capture smells like a `wsl.exe` transport flake rather than an
|
|
577
|
+
* answer from the distro: the execFile deadline fired, or the output carries
|
|
578
|
+
* WSL's own wedged-service error (`Wsl/Service/WSAETIMEDOUT` and friends —
|
|
579
|
+
* localized text is fine, the error class rides every language). Under the
|
|
580
|
+
* doctor's concurrent probing of several distros on one VM, these flakes
|
|
581
|
+
* arrive exactly when a cold distro is mid-boot, and trusting them produced
|
|
582
|
+
* the wrong class of report: static config (`wsl.conf`, resolv.conf) read as
|
|
583
|
+
* broken when the read itself was the casualty.
|
|
584
|
+
* @param {{ ok: boolean, stdout: string, stderr: string, timedOut?: boolean }} answer - the capture.
|
|
585
|
+
* @returns {boolean} true when the capture must not feed a config verdict.
|
|
586
|
+
*/
|
|
587
|
+
export function isFlake(answer) {
|
|
588
|
+
return answer.timedOut === true || /WSAETIMEDOUT|Wsl\/Service/i.test(`${answer.stderr}\n${answer.stdout}`);
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
/** How long one retry waits for the VM to settle before probing again. */
|
|
592
|
+
const FLAKE_SETTLE_MS = 2_000;
|
|
593
|
+
|
|
594
|
+
/**
|
|
595
|
+
* One in-distro probe with a transport-flake retry: a capture that smells like
|
|
596
|
+
* a flake is retried once after a settle delay, and the result carries whether
|
|
597
|
+
* the FINAL answer is still untrusted (`flaked`), so a caller can report
|
|
598
|
+
* `unknown` instead of a configuration verdict built on a wedged read.
|
|
599
|
+
* @param {string} distro - the distro name.
|
|
600
|
+
* @param {string} script - the shell script.
|
|
601
|
+
* @returns {Promise<{ ok: boolean, stdout: string, stderr: string, code?: string, timedOut?: boolean, flaked: boolean }>} the capture plus the flake flag.
|
|
602
|
+
*/
|
|
603
|
+
async function askDistro(distro, script) {
|
|
604
|
+
const first = await inDistro(distro, script);
|
|
605
|
+
if (first.ok || !isFlake(first)) return { ...first, flaked: isFlake(first) };
|
|
606
|
+
await new Promise((resolve) => setTimeout(resolve, FLAKE_SETTLE_MS));
|
|
607
|
+
const second = await inDistro(distro, script);
|
|
608
|
+
return { ...second, flaked: isFlake(second) };
|
|
609
|
+
}
|
|
610
|
+
|
|
404
611
|
/**
|
|
405
612
|
* Parse the doctor's own arguments.
|
|
406
613
|
* @param {string[]} argv - `process.argv.slice(2)`.
|
|
407
|
-
* @returns {{ distro: string, wsl: string, json: boolean, fix: boolean, install: boolean, yes: boolean, readOnly: boolean, all: boolean, bundle: string, redact: boolean, help: boolean }} the options.
|
|
614
|
+
* @returns {{ distro: string, wsl: string, json: boolean, fix: boolean, install: boolean, yes: boolean, readOnly: boolean, all: boolean, bundle: string, redact: boolean, sections: string, quick: boolean, help: boolean, locale: string }} the options.
|
|
408
615
|
*/
|
|
409
616
|
function parseArgs(argv) {
|
|
410
617
|
const options = {
|
|
@@ -418,16 +625,24 @@ function parseArgs(argv) {
|
|
|
418
625
|
all: false,
|
|
419
626
|
bundle: "",
|
|
420
627
|
redact: false,
|
|
628
|
+
sections: "",
|
|
629
|
+
quick: false,
|
|
421
630
|
help: false,
|
|
631
|
+
locale: "",
|
|
422
632
|
};
|
|
423
633
|
for (let i = 0; i < argv.length; i += 1) {
|
|
424
634
|
const arg = argv[i] ?? "";
|
|
425
635
|
if (arg === "--json") options.json = true;
|
|
636
|
+
else if (arg === "--locale") options.locale = argv[++i] ?? "";
|
|
637
|
+
else if (arg.startsWith("--locale=")) options.locale = arg.slice("--locale=".length);
|
|
426
638
|
else if (arg === "--fix") options.fix = true;
|
|
427
639
|
else if (arg === "--install") options.install = true;
|
|
428
640
|
else if (arg === "--yes" || arg === "-y") options.yes = true;
|
|
429
641
|
else if (arg === "--read-only") options.readOnly = true;
|
|
430
642
|
else if (arg === "--all") options.all = true;
|
|
643
|
+
else if (arg === "--quick") options.quick = true;
|
|
644
|
+
else if (arg === "--sections") options.sections = argv[++i] ?? "";
|
|
645
|
+
else if (arg.startsWith("--sections=")) options.sections = arg.slice("--sections=".length);
|
|
431
646
|
else if (arg === "--bundle") options.bundle = argv[++i] ?? "";
|
|
432
647
|
else if (arg.startsWith("--bundle=")) options.bundle = arg.slice("--bundle=".length);
|
|
433
648
|
else if (arg === "--redact") options.redact = true;
|
|
@@ -618,7 +833,7 @@ function installRemedy(distro, family) {
|
|
|
618
833
|
* @returns {number} the exit status.
|
|
619
834
|
*/
|
|
620
835
|
function rejectReadOnly() {
|
|
621
|
-
console.error("
|
|
836
|
+
console.error(doctorT("refusal.read-only"));
|
|
622
837
|
return 2;
|
|
623
838
|
}
|
|
624
839
|
|
|
@@ -660,7 +875,24 @@ const DISTRO_CONCURRENCY = 3;
|
|
|
660
875
|
* @param {{ distro: string, wsl: string, json: boolean, fix: boolean, install: boolean, yes: boolean, readOnly: boolean, all: boolean, bundle: string, redact: boolean, help: boolean }} options - the parsed options.
|
|
661
876
|
* @returns {Promise<number>} the exit status.
|
|
662
877
|
*/
|
|
878
|
+
/**
|
|
879
|
+
* The doctor run: collect the checks under the effective configuration and
|
|
880
|
+
* the requested scope, then report.
|
|
881
|
+
* @param {ReturnType<typeof parseArgs>} options - the parsed arguments.
|
|
882
|
+
* @returns {Promise<number>} 0 when the verdict is `ready`, 1 when `blocked`.
|
|
883
|
+
*/
|
|
663
884
|
async function main(options) {
|
|
885
|
+
// The output language: an explicit `--locale` / `DSH_WSL_DOCTOR_LOCALE`
|
|
886
|
+
// wins without probing; otherwise a human run detects the Windows locale
|
|
887
|
+
// through the registry (fast, no PowerShell startup) — the refusals below
|
|
888
|
+
// render in the detected language too. `--json` stays language-independent
|
|
889
|
+
// and pays no extra subprocess.
|
|
890
|
+
if (options.json) setDoctorLocale("en");
|
|
891
|
+
else setDoctorLocale(overrideLocale(options.locale));
|
|
892
|
+
if (!options.json && options.locale.length === 0 && (process.env.DSH_WSL_DOCTOR_LOCALE ?? "").length === 0) {
|
|
893
|
+
const query = await run([CMD, "/c", "reg query \"HKCU\\Control Panel\\International\" /v LocaleName"]);
|
|
894
|
+
setDoctorLocale(localeFromTag(localeNameFromReg(query.stdout)));
|
|
895
|
+
}
|
|
664
896
|
if (options.readOnly && (options.fix || options.install)) return rejectReadOnly();
|
|
665
897
|
// One rebinding covers every probe below (`-l -q`, `inDistro`, the
|
|
666
898
|
// resident handshake, the sessions survey): an explicit `--wsl` replaces
|
|
@@ -695,6 +927,31 @@ async function main(options) {
|
|
|
695
927
|
checks.push({ id, status, title, ...(detail === undefined ? {} : { detail }), ...(remedy === undefined ? {} : { remedy }) });
|
|
696
928
|
};
|
|
697
929
|
|
|
930
|
+
// ---- scope ----------------------------------------------------------------
|
|
931
|
+
// `--quick` and `--sections` bound what this run probes and reports: a
|
|
932
|
+
// scoped run still probes `distro.reachable` (the transport gate) but its
|
|
933
|
+
// report carries only the requested sections, and the expensive legs — the
|
|
934
|
+
// resident smokes, the fence smoke, the registry query, the port survey —
|
|
935
|
+
// run only when their section is selected and the run is not quick. A full
|
|
936
|
+
// run (the default) sets `wanted = null`: every section, no gating.
|
|
937
|
+
const wanted = options.quick
|
|
938
|
+
? new Set(QUICK_SECTIONS)
|
|
939
|
+
: options.sections.length > 0
|
|
940
|
+
? (() => {
|
|
941
|
+
/** @param {string} s - one comma-separated section token. @returns {boolean} whether it names a section. */
|
|
942
|
+
const known = (s) => SECTIONS.includes(s);
|
|
943
|
+
const picked = options.sections.split(",").map((s) => s.trim()).filter(known);
|
|
944
|
+
if (picked.length === 0) return null;
|
|
945
|
+
return new Set(picked);
|
|
946
|
+
})()
|
|
947
|
+
: null;
|
|
948
|
+
const quick = options.quick;
|
|
949
|
+
/** Whether a section is in this run's scope. */
|
|
950
|
+
const want = (/** @type {string} */ section) => wanted === null || wanted.has(section);
|
|
951
|
+
/** @type {{ sections: string[], quick: boolean } | undefined} */
|
|
952
|
+
let scope;
|
|
953
|
+
if (wanted !== null) scope = { sections: [...wanted], quick };
|
|
954
|
+
|
|
698
955
|
// ---- host ----------------------------------------------------------------
|
|
699
956
|
const windows = await run([CMD, "/c", "ver"]);
|
|
700
957
|
const build = /[0-9][0-9.]*/.exec(windows.stdout.replace(/\0/g, ""));
|
|
@@ -771,9 +1028,14 @@ async function main(options) {
|
|
|
771
1028
|
// default) means the workspace decides, so every installed distro is a
|
|
772
1029
|
// candidate and all are checked; `default` resolves to the distro WSL
|
|
773
1030
|
// itself marks as default; a pinned name checks exactly that one.
|
|
774
|
-
const runInfo = /** @type {{ distros: string[], config?: EffectiveConfig, timingsMs?: Record<string, number>, bundle?: { path: string, redact: boolean, manifest: { name?: string, version?: string, peerDependencies?: Record<string, string> } } }} */ ({ distros: [], timingsMs });
|
|
1031
|
+
const runInfo = /** @type {{ distros: string[], config?: EffectiveConfig, timingsMs?: Record<string, number>, scope?: { sections: string[], quick: boolean }, bundle?: { path: string, redact: boolean, manifest: { name?: string, version?: string, peerDependencies?: Record<string, string> } } }} */ ({ distros: [], timingsMs });
|
|
775
1032
|
if (options.bundle.length > 0) runInfo.bundle = { path: options.bundle, redact: options.redact, manifest };
|
|
776
1033
|
runInfo.config = { ...effective };
|
|
1034
|
+
if (options.fix && wanted !== null) {
|
|
1035
|
+
console.error(doctorT("refusal.scoped-fix"));
|
|
1036
|
+
return 2;
|
|
1037
|
+
}
|
|
1038
|
+
if (scope !== undefined) runInfo.scope = scope;
|
|
777
1039
|
/** The `wsl.exe -l -v` table, parsed once: the default marker feeds target selection, the VERSION column feeds `distro.wsl-mode`. */
|
|
778
1040
|
const wslTable = parseWslVerbose((await run([wslExe, "-l", "-v"])).stdout.replace(/\0/g, ""));
|
|
779
1041
|
/** @type {string[]} */
|
|
@@ -811,7 +1073,17 @@ async function main(options) {
|
|
|
811
1073
|
const check = (/** @type {string} */ id, /** @type {Check["status"]} */ status, /** @type {string} */ title, /** @type {string | undefined} */ detail = undefined, /** @type {string | undefined} */ remedy = undefined) => {
|
|
812
1074
|
collected.push({ id, status, title, ...(detail === undefined ? {} : { detail }), ...(remedy === undefined ? {} : { remedy }), distro: target });
|
|
813
1075
|
};
|
|
814
|
-
|
|
1076
|
+
/** One in-distro probe with the flake retry. */
|
|
1077
|
+
const probe = (/** @type {string} */ script) => askDistro(target, script);
|
|
1078
|
+
/** The `unknown` row a transport flake earns instead of a config verdict. */
|
|
1079
|
+
const flakeCheck = (/** @type {string} */ id, /** @type {string} */ title, /** @type {{ stderr: string, stdout: string }} */ answer) => check(id, "unknown", title,
|
|
1080
|
+
`transport flake — wsl.exe timed out or wedged (${(answer.stderr || answer.stdout || "no output").trim().split(/\r?\n/)[0]?.slice(0, 80) || "no output"}); this read is not trusted as a configuration verdict`,
|
|
1081
|
+
`rerun the doctor; if the flake repeats, "wsl.exe -t ${target}" (terminate just this distro) and rerun again`);
|
|
1082
|
+
const alive = await probe("printf %s ok");
|
|
1083
|
+
if (!alive.ok && alive.flaked) {
|
|
1084
|
+
flakeCheck("distro.reachable", `Distro "${target}"`, alive);
|
|
1085
|
+
return { checks: collected, reachable: false, bwrapPath: "", stale: 0, family: "unknown" };
|
|
1086
|
+
}
|
|
815
1087
|
if (!alive.ok || alive.stdout.trim() !== "ok") {
|
|
816
1088
|
check("distro.reachable", "fail", `Distro "${target}"`, "wsl.exe could not run a command in it (stopped, wedged, or missing)", `wsl.exe -d ${target} -- true; if that hangs, wsl.exe --shutdown, then retry`);
|
|
817
1089
|
return { checks: collected, reachable: false, bwrapPath: "", stale: 0, family: "unknown" };
|
|
@@ -819,22 +1091,36 @@ async function main(options) {
|
|
|
819
1091
|
check("distro.reachable", "ok", `Distro "${target}"`, "answers commands");
|
|
820
1092
|
|
|
821
1093
|
// ---- distro facts --------------------------------------------------------
|
|
822
|
-
|
|
823
|
-
const
|
|
824
|
-
if (
|
|
825
|
-
else
|
|
1094
|
+
let family = "unknown";
|
|
1095
|
+
const shellAnswer = await probe('s=$(getent passwd "$(id -u)" | cut -d: -f7); [ -n "$s" ] || s=$SHELL; printf %s "$s"');
|
|
1096
|
+
if (!shellAnswer.ok && shellAnswer.flaked) flakeCheck("distro.shell", "Login shell", shellAnswer);
|
|
1097
|
+
else {
|
|
1098
|
+
const shell = shellAnswer.stdout.trim();
|
|
1099
|
+
if (shell.startsWith("/")) check("distro.shell", "ok", "Login shell", shell);
|
|
1100
|
+
else check("distro.shell", "fail", "Login shell", shell.length === 0 ? "no shell reported" : shell, `check the user's /etc/passwd entry in "${target}": getent passwd "$(id -u)"`);
|
|
1101
|
+
}
|
|
826
1102
|
|
|
827
|
-
const homeAnswer = await
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
1103
|
+
const homeAnswer = await probe('printf %s "$HOME"');
|
|
1104
|
+
if (!homeAnswer.ok && homeAnswer.flaked) flakeCheck("distro.home", "Home", homeAnswer);
|
|
1105
|
+
else {
|
|
1106
|
+
const home = homeAnswer.stdout.trim();
|
|
1107
|
+
if (home.startsWith("/")) check("distro.home", "ok", "Home", home);
|
|
1108
|
+
else check("distro.home", "fail", "Home", home.length === 0 ? "no home reported" : home, `check the default user's home in "${target}": getent passwd "$(id -u)"`);
|
|
1109
|
+
}
|
|
831
1110
|
|
|
832
|
-
const
|
|
833
|
-
|
|
1111
|
+
const kernelAnswer = await probe("uname -r");
|
|
1112
|
+
if (!kernelAnswer.ok && kernelAnswer.flaked) flakeCheck("distro.kernel", "Kernel", kernelAnswer);
|
|
1113
|
+
else {
|
|
1114
|
+
const kernel = kernelAnswer.stdout.trim();
|
|
1115
|
+
check("distro.kernel", "info", "Kernel", kernel.length > 0 ? kernel : "unreadable");
|
|
1116
|
+
}
|
|
834
1117
|
|
|
835
|
-
const familyAnswer = await
|
|
836
|
-
|
|
837
|
-
|
|
1118
|
+
const familyAnswer = await probe(`for f in ${FAMILIES.join(" ")}; do command -v "$f" >/dev/null 2>&1 && { echo "$f"; exit 0; }; done; echo unknown`);
|
|
1119
|
+
if (!familyAnswer.ok && familyAnswer.flaked) flakeCheck("distro.family", "Package family", familyAnswer);
|
|
1120
|
+
else {
|
|
1121
|
+
family = familyAnswer.stdout.trim();
|
|
1122
|
+
check("distro.family", "info", "Package family", family.length > 0 ? family : "unknown");
|
|
1123
|
+
}
|
|
838
1124
|
|
|
839
1125
|
// ---- WSL mode ------------------------------------------------------------
|
|
840
1126
|
// WSL1 is a declared non-goal, but until now it failed unexplained: the
|
|
@@ -854,35 +1140,49 @@ async function main(options) {
|
|
|
854
1140
|
// the ext4 VHDX stops growing (or the Windows drive holding it is full)
|
|
855
1141
|
// and every write failure surfaces as something unrelated. One df call;
|
|
856
1142
|
// the fail line at 97% is where the first cache write starts to break.
|
|
857
|
-
const dfAnswer = await
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
1143
|
+
const dfAnswer = await probe("df -Pm /");
|
|
1144
|
+
if (!dfAnswer.ok && dfAnswer.flaked) flakeCheck("distro.disk", "Disk", dfAnswer);
|
|
1145
|
+
else {
|
|
1146
|
+
const dfLine = dfAnswer.stdout.trim().split(/\r?\n/).map((line) => line.trim()).filter((line) => line.length > 0)[1] ?? "";
|
|
1147
|
+
const dfFields = dfLine.split(/\s+/);
|
|
1148
|
+
const dfCapacity = Number((dfFields[4] ?? "").replace(/%$/, ""));
|
|
1149
|
+
const dfTotal = dfFields[1] ?? "?";
|
|
1150
|
+
const dfAvail = dfFields[3] ?? "?";
|
|
1151
|
+
if (!Number.isFinite(dfCapacity)) {
|
|
1152
|
+
check("distro.disk", "info", "Disk", "unreadable — df did not answer in the expected shape");
|
|
1153
|
+
} else if (dfCapacity >= 97) {
|
|
1154
|
+
check("distro.disk", "fail", "Disk", `/${dfCapacity}% used (${dfAvail} MiB free of ${dfTotal} MiB) — writes into the distro will start failing`, `free space inside "${target}" or on the Windows drive holding the ext4 VHDX; sparse VHD (the .wslconfig sparseVhd key) lets "wsl.exe --shutdown" shrink it back`);
|
|
1155
|
+
} else if (dfCapacity >= 90) {
|
|
1156
|
+
check("distro.disk", "warn", "Disk", `/${dfCapacity}% used (${dfAvail} MiB free of ${dfTotal} MiB)`, "plan a cleanup before the 97% line, where writes start to fail");
|
|
1157
|
+
} else {
|
|
1158
|
+
check("distro.disk", "ok", "Disk", `/${dfCapacity}% used (${dfAvail} MiB free of ${dfTotal} MiB)`);
|
|
1159
|
+
}
|
|
871
1160
|
}
|
|
872
1161
|
|
|
873
1162
|
// ---- sandbox prerequisites ----------------------------------------------
|
|
874
1163
|
let bwrapUsable = false;
|
|
875
|
-
|
|
1164
|
+
let bwrapPath = "";
|
|
876
1165
|
const install = installRemedy(target, family);
|
|
877
|
-
if (
|
|
878
|
-
|
|
1166
|
+
if (!want("sandbox")) {
|
|
1167
|
+
// sandbox section out of scope: bwrapPath stays "" and the fence smoke
|
|
1168
|
+
// below is skipped with it.
|
|
879
1169
|
} else {
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
1170
|
+
const bwrapAnswer = await probe("command -v bwrap");
|
|
1171
|
+
if (!bwrapAnswer.ok && bwrapAnswer.flaked) flakeCheck("sandbox.bwrap", "bubblewrap", bwrapAnswer);
|
|
1172
|
+
else {
|
|
1173
|
+
bwrapPath = bwrapAnswer.stdout.trim();
|
|
1174
|
+
if (bwrapPath.length === 0) {
|
|
1175
|
+
check("sandbox.bwrap", "fail", "bubblewrap", "missing; every confined command fails closed without it", `${install}, or run "pnpm run bootstrap ${target} --install"`);
|
|
1176
|
+
} else {
|
|
1177
|
+
check("sandbox.bwrap", "ok", "bubblewrap", bwrapPath);
|
|
1178
|
+
const userns = await probe("bwrap --ro-bind / / -- true");
|
|
1179
|
+
if (!userns.ok && userns.flaked) flakeCheck("sandbox.bwrap-usable", "bubblewrap usability", userns);
|
|
1180
|
+
else if (userns.ok) {
|
|
1181
|
+
check("sandbox.bwrap-usable", "ok", "bubblewrap usability", "a read-only profile runs");
|
|
1182
|
+
bwrapUsable = true;
|
|
1183
|
+
} else check("sandbox.bwrap-usable", "fail", "bubblewrap usability", "installed but the read-only profile failed", "the kernel likely disables unprivileged user namespaces; reinstalling will not help — see docs/LIMITATIONS.md");
|
|
1184
|
+
}
|
|
1185
|
+
}
|
|
886
1186
|
}
|
|
887
1187
|
|
|
888
1188
|
// ---- session sandbox prerequisites --------------------------------------
|
|
@@ -891,37 +1191,72 @@ async function main(options) {
|
|
|
891
1191
|
// per-command bwrap profile and `false` does not use the scope at all, so
|
|
892
1192
|
// in both cases a missing prerequisite downgrades to a warning — a `fail`
|
|
893
1193
|
// always blocks, which is the invariant the verdict leans on.
|
|
894
|
-
|
|
895
|
-
|
|
1194
|
+
let runtimeSystemd = false;
|
|
1195
|
+
let systemdPid = "";
|
|
1196
|
+
if (want("session")) {
|
|
1197
|
+
const systemd = await probe('if [ -d /run/systemd/system ]; then printf "systemd %s" "$(cat /proc/1/comm)"; else printf "none %s" "$(cat /proc/1/comm)"; fi');
|
|
1198
|
+
if (!systemd.ok && systemd.flaked) flakeCheck("session.systemd", "systemd as PID 1", systemd);
|
|
1199
|
+
else if (!systemd.stdout.startsWith("systemd")) {
|
|
896
1200
|
check("session.systemd", sessionStatus(), "systemd as PID 1", withScopeNote(systemd.stdout.trim().length > 0 ? systemd.stdout.trim() : "not systemd"), `set [boot] systemd=true in /etc/wsl.conf inside "${target}", run "wsl.exe --shutdown", then reopen the session. Without it, sessionSandbox cannot run`);
|
|
897
1201
|
} else check("session.systemd", "ok", "systemd as PID 1", "running");
|
|
898
1202
|
|
|
899
|
-
const systemdRun =
|
|
900
|
-
if (systemdRun.
|
|
901
|
-
else
|
|
1203
|
+
const systemdRun = await probe("command -v systemd-run");
|
|
1204
|
+
if (!systemdRun.ok && systemdRun.flaked) flakeCheck("session.systemd-run", "systemd-run", systemdRun);
|
|
1205
|
+
else {
|
|
1206
|
+
const systemdRunPath = systemdRun.stdout.trim();
|
|
1207
|
+
if (systemdRunPath.length > 0) check("session.systemd-run", "ok", "systemd-run", systemdRunPath);
|
|
1208
|
+
else check("session.systemd-run", sessionStatus(), "systemd-run", withScopeNote("missing; the distro's systemd package is incomplete"), `reinstall systemd inside "${target}" (apt-get install --reinstall systemd, or the family's equivalent)`);
|
|
1209
|
+
}
|
|
902
1210
|
|
|
903
|
-
const userManager =
|
|
904
|
-
if (userManager
|
|
905
|
-
else
|
|
1211
|
+
const userManager = await probe("systemctl --user is-system-running 2>/dev/null || true");
|
|
1212
|
+
if (!userManager.ok && userManager.flaked) flakeCheck("session.user-manager", "systemd user manager", userManager);
|
|
1213
|
+
else {
|
|
1214
|
+
const userState = userManager.stdout.trim();
|
|
1215
|
+
if (userState === "running" || userState === "degraded") check("session.user-manager", "ok", "systemd user manager", userState);
|
|
1216
|
+
else check("session.user-manager", sessionStatus(), "systemd user manager", withScopeNote(userState.length > 0 ? userState : "unreachable"), `log in to "${target}" once, or enable lingering (next remedy), then retry`);
|
|
1217
|
+
}
|
|
906
1218
|
|
|
907
|
-
const linger =
|
|
908
|
-
if (linger
|
|
909
|
-
else
|
|
1219
|
+
const linger = await probe('loginctl show-user "$(id -un)" -p Linger 2>/dev/null');
|
|
1220
|
+
if (!linger.ok && linger.flaked) flakeCheck("session.linger", "Linger", linger);
|
|
1221
|
+
else {
|
|
1222
|
+
const lingerState = linger.stdout.trim();
|
|
1223
|
+
if (lingerState === "Linger=yes") check("session.linger", "ok", "Linger", lingerState);
|
|
1224
|
+
else check("session.linger", sessionStatus(), "Linger", withScopeNote(lingerState.length > 0 ? lingerState : "unset"), `wsl.exe -d ${target} -- loginctl enable-linger "$(id -un)" (this needs the user's own session; run it inside the distro)`);
|
|
1225
|
+
}
|
|
1226
|
+
runtimeSystemd = systemd.stdout.startsWith("systemd");
|
|
1227
|
+
systemdPid = systemd.stdout.trim();
|
|
1228
|
+
}
|
|
910
1229
|
|
|
911
1230
|
// ---- /etc/wsl.conf cross-checks ------------------------------------------
|
|
912
1231
|
// The distro-level settings the plugin cannot change (LIMITATIONS): boot,
|
|
913
1232
|
// interop, automount. Each check reads the conf against the runtime facts
|
|
914
1233
|
// the probes above collected and names the terminate semantics — a conf
|
|
915
1234
|
// value that is not in effect is a different problem from one that is.
|
|
916
|
-
|
|
1235
|
+
// A flaked read earns three `unknown` rows, never a verdict: the conf is
|
|
1236
|
+
// on disk, and the read — not the file — is what failed.
|
|
1237
|
+
const confAnswer = await probe("cat /etc/wsl.conf 2>/dev/null || true");
|
|
1238
|
+
const confFlaked = !confAnswer.ok && confAnswer.flaked;
|
|
917
1239
|
const conf = parseIni(confAnswer.stdout);
|
|
918
1240
|
const noConf = confAnswer.stdout.trim().length === 0;
|
|
919
|
-
const
|
|
1241
|
+
const confWanted = want("session") || want("conf");
|
|
1242
|
+
if (!confWanted) {
|
|
1243
|
+
// Scoped run: neither the boot cross-check nor the interop/automount
|
|
1244
|
+
// rows are in scope — the conf read above stays (one cheap call that
|
|
1245
|
+
// the section rows share), but no rows report.
|
|
1246
|
+
} else if (confFlaked) {
|
|
1247
|
+
if (want("session")) flakeCheck("distro.wsl-conf-boot", "/etc/wsl.conf [boot]", confAnswer);
|
|
1248
|
+
if (want("conf")) {
|
|
1249
|
+
flakeCheck("distro.wsl-conf-interop", "/etc/wsl.conf [interop]", confAnswer);
|
|
1250
|
+
flakeCheck("distro.wsl-conf-automount", "/etc/wsl.conf [automount]", confAnswer);
|
|
1251
|
+
}
|
|
1252
|
+
} else {
|
|
920
1253
|
const bootSystemd = ((noConf ? undefined : conf.boot?.systemd) ?? "").trim().toLowerCase();
|
|
921
|
-
if (
|
|
1254
|
+
if (!want("session")) {
|
|
1255
|
+
// boot row out of scope
|
|
1256
|
+
} else if (noConf) {
|
|
922
1257
|
check("distro.wsl-conf-boot", "info", "/etc/wsl.conf [boot]", "no /etc/wsl.conf — the default (systemd off) applies, and the runtime matches it");
|
|
923
1258
|
} else if (bootSystemd === "true" && !runtimeSystemd) {
|
|
924
|
-
check("distro.wsl-conf-boot", "warn", "/etc/wsl.conf [boot]", `[boot] systemd=true but PID 1 is ${
|
|
1259
|
+
check("distro.wsl-conf-boot", "warn", "/etc/wsl.conf [boot]", `[boot] systemd=true but PID 1 is ${systemdPid || "not systemd"} — the value is set but not in effect`, `wsl.exe --terminate ${target} (or "wsl.exe --shutdown"), then reopen the session`);
|
|
925
1260
|
} else if (bootSystemd === "false" && runtimeSystemd) {
|
|
926
1261
|
check("distro.wsl-conf-boot", "warn", "/etc/wsl.conf [boot]", "[boot] systemd=false but PID 1 is systemd — the running boot predates the value", `wsl.exe --terminate ${target} applies it; check sessionSandbox first, because the scope needs systemd`);
|
|
927
1262
|
} else {
|
|
@@ -929,9 +1264,12 @@ async function main(options) {
|
|
|
929
1264
|
}
|
|
930
1265
|
|
|
931
1266
|
const interopEnabled = ((noConf ? undefined : conf.interop?.enabled) ?? "").trim().toLowerCase();
|
|
932
|
-
if (
|
|
933
|
-
|
|
934
|
-
|
|
1267
|
+
if (!want("conf")) {
|
|
1268
|
+
// interop/automount rows out of scope
|
|
1269
|
+
} else if (interopEnabled === "false") {
|
|
1270
|
+
const binfmtProbe = await probe("[ -e /proc/sys/fs/binfmt_misc/WSLInterop ] && printf yes || printf no");
|
|
1271
|
+
const binfmt = binfmtProbe.ok && !binfmtProbe.flaked ? binfmtProbe.stdout.trim() : "unreadable";
|
|
1272
|
+
check("distro.wsl-conf-interop", "warn", "/etc/wsl.conf [interop]", `interop is disabled in wsl.conf${binfmt === "yes" ? " but the WSLInterop handler is still loaded (stale boot)" : binfmt === "unreadable" ? " (the binfmt cross-check flaked — treat the stale-boot note as unverified)" : ""} — Windows git, open-in-app and the cmd.exe probes are unreachable from this distro`, `remove the [interop] enabled=false line in /etc/wsl.conf, then wsl.exe --terminate ${target}`);
|
|
935
1273
|
} else {
|
|
936
1274
|
const appendWindowsPath = ((noConf ? undefined : conf.interop?.appendWindowsPath) ?? "").trim().toLowerCase();
|
|
937
1275
|
check("distro.wsl-conf-interop", "ok", "/etc/wsl.conf [interop]", noConf
|
|
@@ -941,7 +1279,9 @@ async function main(options) {
|
|
|
941
1279
|
|
|
942
1280
|
const automountEnabled = ((noConf ? undefined : conf.automount?.enabled) ?? "").trim().toLowerCase();
|
|
943
1281
|
const automountRoot = ((noConf ? undefined : conf.automount?.root) ?? "").trim();
|
|
944
|
-
if (
|
|
1282
|
+
if (!want("conf")) {
|
|
1283
|
+
// automount row out of scope
|
|
1284
|
+
} else if (automountEnabled === "false") {
|
|
945
1285
|
check("distro.wsl-conf-automount", "warn", "/etc/wsl.conf [automount]", "automount is disabled — /mnt has no Windows drives and Windows files are unreachable from this distro; the masking stance is moot", `remove [automount] enabled=false in /etc/wsl.conf, then wsl.exe --terminate ${target}`);
|
|
946
1286
|
} else if (automountRoot.length > 0 && automountRoot !== "/mnt" && interopMasked) {
|
|
947
1287
|
check("distro.wsl-conf-automount", "warn", "/etc/wsl.conf [automount]", `the automount root is ${automountRoot}, not /mnt — the drive-masking stance is in effect and targets /mnt, so ${automountRoot} is not covered`, `reset [automount] root to /mnt in /etc/wsl.conf, then wsl.exe --terminate ${target}`);
|
|
@@ -950,20 +1290,25 @@ async function main(options) {
|
|
|
950
1290
|
? "no /etc/wsl.conf — /mnt mounts (the default)"
|
|
951
1291
|
: `enabled=${automountEnabled || "true (the default)"}, root=${automountRoot || "/mnt"}`);
|
|
952
1292
|
}
|
|
1293
|
+
}
|
|
953
1294
|
|
|
954
1295
|
// ---- clock ----------------------------------------------------------------
|
|
955
1296
|
// A sleeping host desyncs the WSL clock (the VM's clock stops with it);
|
|
956
1297
|
// the classic symptom is TLS and git failing with certificate or
|
|
957
1298
|
// timestamp errors minutes after resume. One comparison, one remedy.
|
|
958
|
-
const
|
|
959
|
-
if (!
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
check("distro.clock", "warn", "Clock", `the distro clock is ${skew}s off the host — TLS and git fail with certificate/timestamp errors after a host sleep`, `"wsl.exe --shutdown", then reopen — the VM resyncs on boot`);
|
|
1299
|
+
const clockAnswer = await probe("date +%s");
|
|
1300
|
+
if (!clockAnswer.ok && clockAnswer.flaked) flakeCheck("distro.clock", "Clock", clockAnswer);
|
|
1301
|
+
else {
|
|
1302
|
+
const distroEpoch = Number(clockAnswer.stdout.trim());
|
|
1303
|
+
if (!Number.isFinite(distroEpoch) || distroEpoch <= 0) {
|
|
1304
|
+
check("distro.clock", "info", "Clock", "unreadable — date did not answer an epoch");
|
|
965
1305
|
} else {
|
|
966
|
-
|
|
1306
|
+
const skew = Math.abs(distroEpoch - Math.floor(Date.now() / 1000));
|
|
1307
|
+
if (skew > 60) {
|
|
1308
|
+
check("distro.clock", "warn", "Clock", `the distro clock is ${skew}s off the host — TLS and git fail with certificate/timestamp errors after a host sleep`, `"wsl.exe --shutdown", then reopen — the VM resyncs on boot`);
|
|
1309
|
+
} else {
|
|
1310
|
+
check("distro.clock", "ok", "Clock", `within ${skew}s of the host`);
|
|
1311
|
+
}
|
|
967
1312
|
}
|
|
968
1313
|
}
|
|
969
1314
|
|
|
@@ -973,15 +1318,19 @@ async function main(options) {
|
|
|
973
1318
|
// the VPN-tunnel class where the file looks fine but queries die. The
|
|
974
1319
|
// probe is warn-grade and honest about offline — a machine without a
|
|
975
1320
|
// network answers the same as a broken resolver.
|
|
976
|
-
const
|
|
977
|
-
if (!
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
check("distro.dns", "ok", "DNS", `resolv.conf present (${resolvBytes} bytes); ${(resolved.split(/\s+/)[0] ?? "?")} resolved the probe name`);
|
|
1321
|
+
const resolvAnswer = want("net") ? await probe("wc -c < /etc/resolv.conf 2>/dev/null || printf 0") : undefined;
|
|
1322
|
+
if (resolvAnswer !== undefined && !resolvAnswer.ok && resolvAnswer.flaked) flakeCheck("distro.dns", "DNS", resolvAnswer);
|
|
1323
|
+
else if (resolvAnswer !== undefined) {
|
|
1324
|
+
const resolvBytes = Number(resolvAnswer.stdout.trim());
|
|
1325
|
+
if (!Number.isFinite(resolvBytes) || resolvBytes === 0) {
|
|
1326
|
+
check("distro.dns", "warn", "DNS", "/etc/resolv.conf is missing or empty — name resolution fails (npm, git fetch, bootstrap installs)", `wsl.conf [network] generateResolvConf controls the file; "wsl.exe --shutdown" regenerates it unless disabled`);
|
|
983
1327
|
} else {
|
|
984
|
-
|
|
1328
|
+
const resolved = (await probe("getent hosts deb.debian.org 2>/dev/null | head -1")).stdout.trim();
|
|
1329
|
+
if (resolved.length > 0) {
|
|
1330
|
+
check("distro.dns", "ok", "DNS", `resolv.conf present (${resolvBytes} bytes); ${(resolved.split(/\s+/)[0] ?? "?")} resolved the probe name`);
|
|
1331
|
+
} else {
|
|
1332
|
+
check("distro.dns", "warn", "DNS", `resolv.conf present (${resolvBytes} bytes) but the probe name did not resolve — offline, or the resolver is broken (the VPN-tunnel class)`, "check the network; with a VPN up, see the WSL DNS tunneling notes in docs/CONFIGURATION.md");
|
|
1333
|
+
}
|
|
985
1334
|
}
|
|
986
1335
|
}
|
|
987
1336
|
|
|
@@ -990,41 +1339,72 @@ async function main(options) {
|
|
|
990
1339
|
/** @type {Array<[string, string]>} */
|
|
991
1340
|
const optionalTools = [["rg", "in-distro search"], ["git", "workspace-change baselines"], ["inotifywait", "the watcher's primary backend"]];
|
|
992
1341
|
for (const [tool, purpose] of optionalTools) {
|
|
993
|
-
const
|
|
994
|
-
if (
|
|
995
|
-
else
|
|
1342
|
+
const toolAnswer = await probe(`command -v ${tool}`);
|
|
1343
|
+
if (!toolAnswer.ok && toolAnswer.flaked) flakeCheck(`tools.${tool}`, tool, toolAnswer);
|
|
1344
|
+
else {
|
|
1345
|
+
const found = toolAnswer.stdout.trim();
|
|
1346
|
+
if (found.length > 0) check(`tools.${tool}`, "ok", tool, found);
|
|
1347
|
+
else check(`tools.${tool}`, "warn", tool, `missing; ${purpose} degrades to a slower fallback`, install);
|
|
1348
|
+
}
|
|
996
1349
|
}
|
|
997
1350
|
|
|
998
1351
|
// ---- agents and caches ---------------------------------------------------
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
const cache = (await inDistro(target, CACHE_REPORT)).stdout.trim();
|
|
1007
|
-
if (cache === "none" || cache.length === 0) check("agent.cache", "info", "Agent cache", "empty (a first command populates it)");
|
|
1352
|
+
// Gated on the agent section: this region is the expensive chain (arch,
|
|
1353
|
+
// cache inventory, handshake, resident smokes). A scoped run without it
|
|
1354
|
+
// (quick included) stops after the session rows.
|
|
1355
|
+
if (want("agent")) {
|
|
1356
|
+
const archAnswer = await probe("uname -m");
|
|
1357
|
+
if (!archAnswer.ok && archAnswer.flaked) flakeCheck("agent.arch", "Distro architecture", archAnswer);
|
|
1008
1358
|
else {
|
|
1009
|
-
const
|
|
1010
|
-
const
|
|
1011
|
-
|
|
1359
|
+
const arch = archAnswer.stdout.trim();
|
|
1360
|
+
const packaged = ["x86_64", "aarch64"].includes(arch) ? join(ROOT, "agent", "native", `linux-${arch}`, "dsh-wsl-agent") : "";
|
|
1361
|
+
if (arch.length === 0) check("agent.arch", "info", "Distro architecture", "unreadable");
|
|
1362
|
+
else if (packaged.length === 0) check("agent.arch", "info", "Distro architecture", `${arch} has no packaged native agent; the shell agent is the only backend`);
|
|
1363
|
+
else if (existsSync(packaged)) check("agent.native", "ok", "Packaged native agent", packaged.slice(ROOT.length + 1));
|
|
1364
|
+
else check("agent.native", "warn", "Packaged native agent", `missing for ${arch}`, "reinstall the plugin (the binaries ship with the package), or use agentBackend: shell");
|
|
1012
1365
|
}
|
|
1013
1366
|
|
|
1014
|
-
const
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1367
|
+
const cacheAnswer = await probe(CACHE_REPORT);
|
|
1368
|
+
if (!cacheAnswer.ok && cacheAnswer.flaked) flakeCheck("agent.cache", "Agent cache", cacheAnswer);
|
|
1369
|
+
else {
|
|
1370
|
+
const cache = cacheAnswer.stdout.trim();
|
|
1371
|
+
if (cache === "none" || cache.length === 0) check("agent.cache", "info", "Agent cache", "empty (a first command populates it)");
|
|
1372
|
+
else {
|
|
1373
|
+
const entries = cache.split(/\r?\n/).filter((line) => line.trim().length > 0);
|
|
1374
|
+
const bad = entries.filter((line) => line.startsWith("noexec ")).length;
|
|
1375
|
+
check("agent.cache", bad > 0 ? "warn" : "ok", "Agent cache", `${entries.length} cached binary(ies)${bad > 0 ? `, ${bad} not executable` : ""}`, bad > 0 ? `rm -rf ~/.cache/dsh-wsl/agent inside "${target}"; the next command repopulates it` : undefined);
|
|
1376
|
+
}
|
|
1377
|
+
}
|
|
1378
|
+
}
|
|
1022
1379
|
|
|
1023
|
-
// ----
|
|
1380
|
+
// ---- session scopes (section: session) ------------------------------------
|
|
1381
|
+
const scopesAnswer = want("session") ? await probe(STALE_SCOPE_REPORT) : undefined;
|
|
1382
|
+
let stale = 0;
|
|
1383
|
+
/** @type {string[]} */
|
|
1384
|
+
let livePids = [];
|
|
1385
|
+
/** @type {string[]} */
|
|
1386
|
+
let scopeLines = [];
|
|
1387
|
+
/** ok | fail | info — the handshake state the smoke legs read. */
|
|
1388
|
+
let handshakeState = "info";
|
|
1389
|
+
if (scopesAnswer !== undefined && !scopesAnswer.ok && scopesAnswer.flaked) flakeCheck("runtime.scopes", "Session scopes", scopesAnswer);
|
|
1390
|
+
else if (scopesAnswer !== undefined) {
|
|
1391
|
+
const scopes = scopesAnswer.stdout.trim();
|
|
1392
|
+
scopeLines = scopes === "none" || scopes.length === 0 ? [] : scopes.split(/\r?\n/);
|
|
1393
|
+
stale = scopeLines.filter((line) => /\sstale(\s|$)/.test(line)).length;
|
|
1394
|
+
livePids = scopeLines.flatMap((line) => {
|
|
1395
|
+
const m = /\spids:([0-9 ]+)$/.exec(line);
|
|
1396
|
+
if (m === null) return [];
|
|
1397
|
+
return (m[1] ?? "").trim().split(/\s+/).filter((p) => p.length > 0);
|
|
1398
|
+
});
|
|
1399
|
+
}
|
|
1400
|
+
|
|
1401
|
+
// ---- resident handshake (section: agent) ----------------------------------
|
|
1024
1402
|
const agentScript = join(ROOT, "agent", "wsl-agent.sh");
|
|
1025
1403
|
/** ok | fail | info — the legs skip with a story that matches. */
|
|
1026
|
-
|
|
1027
|
-
if (!
|
|
1404
|
+
handshakeState = "info";
|
|
1405
|
+
if (!want("agent")) {
|
|
1406
|
+
// agent section out of scope: no handshake, no resident smokes.
|
|
1407
|
+
} else if (!agentScript.startsWith("/")) {
|
|
1028
1408
|
check("agent.handshake", "info", "Agent handshake", "skipped: run the doctor from inside the distro (the script path is a Windows path)");
|
|
1029
1409
|
} else if (!existsSync(agentScript)) {
|
|
1030
1410
|
check("agent.handshake", "fail", "Agent handshake", "agent/wsl-agent.sh is missing from this install", "reinstall the plugin; the shell agent ships with the package");
|
|
@@ -1053,7 +1433,9 @@ async function main(options) {
|
|
|
1053
1433
|
}
|
|
1054
1434
|
|
|
1055
1435
|
// ---- stale session scopes ------------------------------------------------
|
|
1056
|
-
if (
|
|
1436
|
+
if (!want("session")) {
|
|
1437
|
+
// session section out of scope
|
|
1438
|
+
} else if (scopeLines.length === 0) check("runtime.scopes", "info", "Session scopes", "none (no user manager, or none left behind)");
|
|
1057
1439
|
else if (stale === 0) check("runtime.scopes", "ok", "Session scopes", `${scopeLines.length} live, none stale`);
|
|
1058
1440
|
else check("runtime.scopes", "warn", "Session scopes", `${stale} stale of ${scopeLines.length}`, "--fix stops them (the same sweep the session preflight runs); they are safe to stop when no agent process is inside");
|
|
1059
1441
|
|
|
@@ -1066,19 +1448,40 @@ async function main(options) {
|
|
|
1066
1448
|
const residentBlocked = handshakeState !== "ok";
|
|
1067
1449
|
const sandboxBlocked = bwrapPath.length === 0 || !bwrapUsable;
|
|
1068
1450
|
const residentBlocker = handshakeState === "fail" ? "blocked by agent.handshake" : "the handshake could not run in this distro";
|
|
1069
|
-
|
|
1451
|
+
// A quick run skips both smokes — their worth is the deep verdict, and
|
|
1452
|
+
// the quick profile's promise is a fast prerequisite answer.
|
|
1453
|
+
const residentSmokeWanted = want("agent") && !quick;
|
|
1454
|
+
const sandboxSmokeWanted = want("sandbox") && !quick;
|
|
1455
|
+
if (!residentSmokeWanted) {
|
|
1456
|
+
// resident smokes out of scope (or quick)
|
|
1457
|
+
} else if (residentBlocked) {
|
|
1070
1458
|
check("functional.exec", "skipped", "Smoke: EXEC", `skipped: ${residentBlocker}`);
|
|
1071
1459
|
check("functional.fs", "skipped", "Smoke: FSB batch", `skipped: ${residentBlocker}`);
|
|
1072
1460
|
} else {
|
|
1073
|
-
|
|
1461
|
+
// One retry for both smoke sessions: under concurrent probing a wedge
|
|
1462
|
+
// can kill an otherwise healthy chain, and a smoke `fail` is the most
|
|
1463
|
+
// alarming row the report can carry — it must not rest on one flaked
|
|
1464
|
+
// transport.
|
|
1465
|
+
let smoke = await runSmokeLegs(target, agentScript, wslExe);
|
|
1466
|
+
if (!smoke.execOk || !smoke.fsOk) {
|
|
1467
|
+
await new Promise((resolve) => setTimeout(resolve, FLAKE_SETTLE_MS));
|
|
1468
|
+
smoke = await runSmokeLegs(target, agentScript, wslExe);
|
|
1469
|
+
}
|
|
1074
1470
|
check("functional.exec", smoke.execOk ? "ok" : "fail", "Smoke: EXEC", smoke.execDetail, smoke.execOk ? undefined : "restart the DSH app; if it persists, delete ~/.cache/dsh-wsl/agent inside the distro and rerun the doctor");
|
|
1075
1471
|
check("functional.fs", smoke.fsOk ? "ok" : "fail", "Smoke: FSB batch", smoke.fsDetail, smoke.fsOk ? undefined : "restart the DSH app; if it persists, delete ~/.cache/dsh-wsl/agent inside the distro and rerun the doctor");
|
|
1076
1472
|
}
|
|
1077
|
-
if (
|
|
1473
|
+
if (!sandboxSmokeWanted) {
|
|
1474
|
+
// fence smoke out of scope (or quick)
|
|
1475
|
+
} else if (sandboxBlocked) {
|
|
1078
1476
|
check("functional.sandbox", "skipped", "Smoke: confined profile", `skipped: blocked by ${bwrapPath.length === 0 ? "sandbox.bwrap" : "sandbox.bwrap-usable"}`);
|
|
1079
1477
|
} else {
|
|
1080
|
-
|
|
1081
|
-
|
|
1478
|
+
let sandbox = await runSandboxSmoke(target);
|
|
1479
|
+
if (!sandbox.ok && !sandbox.flaked) {
|
|
1480
|
+
await new Promise((resolve) => setTimeout(resolve, FLAKE_SETTLE_MS));
|
|
1481
|
+
sandbox = await runSandboxSmoke(target);
|
|
1482
|
+
}
|
|
1483
|
+
if (sandbox.flaked) flakeCheck("functional.sandbox", "Smoke: confined profile", { stderr: sandbox.detail, stdout: "" });
|
|
1484
|
+
else check("functional.sandbox", sandbox.ok ? "ok" : "fail", "Smoke: confined profile", sandbox.detail, sandbox.ok ? undefined : "the shipped profile refused a write it must allow, or allowed one it must refuse — see docs/LIMITATIONS.md and pnpm run probe:sandbox");
|
|
1082
1485
|
}
|
|
1083
1486
|
|
|
1084
1487
|
return { checks: collected, reachable: true, bwrapPath, stale, family };
|
|
@@ -1108,6 +1511,10 @@ async function main(options) {
|
|
|
1108
1511
|
// resolves git to a distro sentinel and routes everything. What the doctor
|
|
1109
1512
|
// can probe cheaply from here is interop git.exe and its whitelist.
|
|
1110
1513
|
let winGitOk = false;
|
|
1514
|
+
if (quick) {
|
|
1515
|
+
// quick profile: the trust check needs interop git.exe and is advice, not
|
|
1516
|
+
// a prerequisite — a scoped run leaves it out.
|
|
1517
|
+
} else {
|
|
1111
1518
|
const winGitVersion = await run(["git.exe", "--version"]);
|
|
1112
1519
|
if (!winGitVersion.ok) {
|
|
1113
1520
|
check("git.win-safe", "info", "Windows git trust", "Windows git not found through interop — WSL change review uses the distro fallback; host (C:\\...) workspaces would need git for their own review");
|
|
@@ -1120,6 +1527,7 @@ async function main(options) {
|
|
|
1120
1527
|
: "Windows git does not trust the \\\\wsl.localhost share; WSL workspaces' change review silently degrades to file-tool edits",
|
|
1121
1528
|
whitelisted ? undefined : 'on Windows: git config --global --add safe.directory "//wsl.localhost/*", then restart the app');
|
|
1122
1529
|
}
|
|
1530
|
+
}
|
|
1123
1531
|
|
|
1124
1532
|
phase("git");
|
|
1125
1533
|
// ---- sessions across running distros (WSL-309) ----------------------------
|
|
@@ -1137,19 +1545,19 @@ async function main(options) {
|
|
|
1137
1545
|
const running = ((await run([WSL, "--list", "--running"])).stdout ?? "").split(/\r?\n/).map((line) => line.trim().replace(/\s+\([^)]*\)$/, "")).filter((line) => distroNames.includes(line));
|
|
1138
1546
|
if (!options.json) {
|
|
1139
1547
|
console.log("");
|
|
1140
|
-
console.log("sessions
|
|
1548
|
+
console.log(doctorT("sessions.title"));
|
|
1141
1549
|
if (running.length === 0) {
|
|
1142
|
-
console.log("
|
|
1550
|
+
console.log(doctorT("sessions.none"));
|
|
1143
1551
|
} else {
|
|
1144
1552
|
for (const d of running) {
|
|
1145
1553
|
const report = (await inDistro(d, STALE_SCOPE_REPORT)).stdout.trim();
|
|
1146
1554
|
const lines = report === "none" || report.length === 0 ? [] : report.split(/\r?\n/);
|
|
1147
1555
|
if (report === "none") {
|
|
1148
|
-
console.log(` ${d} no
|
|
1556
|
+
console.log(` ${d} ${doctorT("sessions.no-user-manager")}`);
|
|
1149
1557
|
continue;
|
|
1150
1558
|
}
|
|
1151
1559
|
if (lines.length === 0) {
|
|
1152
|
-
console.log(` ${d} no
|
|
1560
|
+
console.log(` ${d} ${doctorT("sessions.no-scopes")}`);
|
|
1153
1561
|
continue;
|
|
1154
1562
|
}
|
|
1155
1563
|
for (const line of lines) {
|
|
@@ -1169,7 +1577,7 @@ async function main(options) {
|
|
|
1169
1577
|
// serves the human, with the two actions the facts imply: the localhost URL
|
|
1170
1578
|
// WSL2's forwarding already makes reachable, and the netsh line that would
|
|
1171
1579
|
// extend reach beyond the host (printed, never applied).
|
|
1172
|
-
if (!options.json) {
|
|
1580
|
+
if (!options.json && !quick) {
|
|
1173
1581
|
const portScript = procNetScript();
|
|
1174
1582
|
let anyPorts = false;
|
|
1175
1583
|
for (const d of running) {
|
|
@@ -1179,12 +1587,12 @@ async function main(options) {
|
|
|
1179
1587
|
anyPorts = true;
|
|
1180
1588
|
const ip = ((await inDistro(d, "hostname -I")).stdout ?? "").trim().split(/\s+/)[0] ?? "";
|
|
1181
1589
|
console.log("");
|
|
1182
|
-
console.log(
|
|
1590
|
+
console.log(doctorT("ports.title", { distro: d }));
|
|
1183
1591
|
for (const port of ports) {
|
|
1184
1592
|
console.log(` :${port} http://localhost:${port} (LAN: netsh interface portproxy add v4tov4 listenport=${port} listenaddress=0.0.0.0 connectport=${port} connectaddress=${ip})`);
|
|
1185
1593
|
}
|
|
1186
1594
|
}
|
|
1187
|
-
if (!anyPorts && running.length > 0) console.log("
|
|
1595
|
+
if (!anyPorts && running.length > 0) console.log(doctorT("ports.none"));
|
|
1188
1596
|
}
|
|
1189
1597
|
|
|
1190
1598
|
// ---- peers ---------------------------------------------------------------
|
|
@@ -1206,10 +1614,13 @@ async function main(options) {
|
|
|
1206
1614
|
// stable channel's newest release against this checkout's version. A
|
|
1207
1615
|
// registry the doctor cannot reach is normal (offline, a proxy), so it
|
|
1208
1616
|
// reports as `info` and points at the page that asks it live — never a
|
|
1209
|
-
// warning, and never a network side effect beyond the two GETs.
|
|
1617
|
+
// warning, and never a network side effect beyond the two GETs. The quick
|
|
1618
|
+
// profile skips it: no network on the fast path.
|
|
1210
1619
|
const installedVersion = manifest.version ?? "";
|
|
1211
|
-
const latest = installedVersion.length > 0 ? await fetchLatestRelease() : undefined;
|
|
1212
|
-
if (
|
|
1620
|
+
const latest = !quick && installedVersion.length > 0 ? await fetchLatestRelease() : undefined;
|
|
1621
|
+
if (quick) {
|
|
1622
|
+
// quick profile: no update row at all — the registry stays untouched.
|
|
1623
|
+
} else if (latest === undefined) {
|
|
1213
1624
|
check("update.latest", "info", "Update check", "the registry was unreachable (offline, or a proxy is in the way); the app's Versions page asks the same question live");
|
|
1214
1625
|
} else if (compareVersions(latest.version, installedVersion) > 0) {
|
|
1215
1626
|
const message = updateFactMessage({ installed: installedVersion, latest: latest.version, incompatible: false, ...(latest.deprecated === undefined ? {} : { deprecated: latest.deprecated }), checkedAt: 0 });
|
|
@@ -1310,7 +1721,7 @@ async function main(options) {
|
|
|
1310
1721
|
const install = installRemedy(target, state.family);
|
|
1311
1722
|
if (!options.install) {
|
|
1312
1723
|
fixCheck("fix.install", "info", "Package installation", "not attempted", "re-run with --fix --install (and --yes for a non-interactive run)");
|
|
1313
|
-
} else if (!(await confirm(
|
|
1724
|
+
} else if (!(await confirm(doctorT("confirm.install", { packages: PACKAGES, distro: target }), options.yes))) {
|
|
1314
1725
|
fixCheck("fix.install", "info", "Package installation", "declined", install);
|
|
1315
1726
|
} else {
|
|
1316
1727
|
const command = INSTALL[state.family] ?? INSTALL["apt-get"] ?? `apt-get install -y ${PACKAGES}`;
|
|
@@ -1563,21 +1974,23 @@ function runSmokeLegs(distro, scriptPath, wslExe = WSL) {
|
|
|
1563
1974
|
* are the two assertions `probe:sandbox` makes, in miniature, so the doctor's
|
|
1564
1975
|
* verdict covers the fence and not just the binary.
|
|
1565
1976
|
* @param {string} distro - the distro.
|
|
1566
|
-
* @returns {Promise<{ ok: boolean, detail: string }>} the fence verdict.
|
|
1977
|
+
* @returns {Promise<{ ok: boolean, flaked: boolean, detail: string }>} the fence verdict.
|
|
1567
1978
|
*/
|
|
1568
1979
|
async function runSandboxSmoke(distro) {
|
|
1569
|
-
const dirAnswer = await
|
|
1980
|
+
const dirAnswer = await askDistro(distro, 'd=$(mktemp -d /tmp/dsh-doctor-smoke-XXXXXXXX) && printf %s "$d"');
|
|
1570
1981
|
const dir = dirAnswer.stdout.trim();
|
|
1571
|
-
if (dir.length === 0) return { ok: false, detail: "the temp dir for the fence leg could not be created" };
|
|
1982
|
+
if (dir.length === 0) return { ok: false, flaked: !dirAnswer.ok && dirAnswer.flaked, detail: "the temp dir for the fence leg could not be created" };
|
|
1572
1983
|
const prefix = bwrapArgvPrefix({ mode: "workspace-write", workspaceRoot: dir }, {});
|
|
1573
1984
|
const inside = await run([WSL, "-d", distro, "--exec", ...prefix, "sh", "-c", 'printf ok > "$0" && cat "$0"', `${dir}/inside`]);
|
|
1574
1985
|
const outside = await run([WSL, "-d", distro, "--exec", ...prefix, "sh", "-c", 'printf no > "$0" 2>/dev/null', "/etc/dsh-doctor-smoke-refuse"]);
|
|
1575
|
-
const cleanup = await
|
|
1986
|
+
const cleanup = await askDistro(distro, `rm -rf "${dir}"`);
|
|
1987
|
+
const flaked = [inside, outside, cleanup].some((answer) => isFlake(answer));
|
|
1576
1988
|
const insideOk = inside.ok && inside.stdout.trim() === "ok";
|
|
1577
1989
|
const outsideRefused = !outside.ok;
|
|
1578
1990
|
const ok = insideOk && outsideRefused;
|
|
1579
1991
|
return {
|
|
1580
1992
|
ok,
|
|
1993
|
+
flaked,
|
|
1581
1994
|
detail: `a write inside ${dir} ${insideOk ? "ran" : "was REFUSED (the profile broke)"} and a write to /etc ${outsideRefused ? "was refused" : "RAN (the fence is open)"} — the shipped workspace-write shape${cleanup.ok ? "" : `; CLEANUP FAILED — ${dir} is left behind`}`,
|
|
1582
1995
|
};
|
|
1583
1996
|
}
|
|
@@ -1611,17 +2024,24 @@ async function confirm(question, yes) {
|
|
|
1611
2024
|
*
|
|
1612
2025
|
* @param {Check[]} checks - the collected checks (distro-scoped ones carry their `distro`).
|
|
1613
2026
|
* @param {{ json: boolean }} options - the output mode.
|
|
1614
|
-
* @param {{ distros?: string[], config?: EffectiveConfig, timingsMs?: Record<string, number>, bundle?: { path: string, redact: boolean, manifest: { name?: string, version?: string, peerDependencies?: Record<string, string> } } }} [runInfo] - the target distros, the effective configuration, the per-phase wall clock, and the bundle request.
|
|
2027
|
+
* @param {{ distros?: string[], config?: EffectiveConfig, timingsMs?: Record<string, number>, scope?: { sections: string[], quick: boolean }, bundle?: { path: string, redact: boolean, manifest: { name?: string, version?: string, peerDependencies?: Record<string, string> } } }} [runInfo] - the target distros, the effective configuration, the run scope, the per-phase wall clock, and the bundle request.
|
|
1615
2028
|
* @returns {number} 0 when the verdict is `ready`, 1 when `blocked`.
|
|
1616
2029
|
*/
|
|
1617
2030
|
function report(checks, options, runInfo = {}) {
|
|
1618
|
-
|
|
2031
|
+
// Scoped run: keep only the requested sections. `distro.reachable` is the
|
|
2032
|
+
// transport gate every scoped run probes, so it always stays — a scoped
|
|
2033
|
+
// verdict answers "is this distro healthy *within the requested scope*".
|
|
2034
|
+
const wantedSections = runInfo.scope === undefined ? null : new Set(runInfo.scope.sections);
|
|
2035
|
+
/** @param {{ id: string }} entry - the check. @returns {boolean} whether it survives the scope. */
|
|
2036
|
+
const inScope = (entry) => wantedSections === null || wantedSections.has(sectionOf(entry.id)) || entry.id === "distro.reachable";
|
|
2037
|
+
const scoped = checks.filter(inScope);
|
|
2038
|
+
const stamped = scoped.map((entry) => ({
|
|
1619
2039
|
...entry,
|
|
1620
2040
|
blocksFirstCommand: entry.status === "fail",
|
|
1621
2041
|
}));
|
|
1622
2042
|
/** @param {string} status - the status to count. @returns {number} how many checks carry it. */
|
|
1623
2043
|
const count = (status) => stamped.filter((entry) => entry.status === status).length;
|
|
1624
|
-
const summary = { ok: count("ok"), warn: count("warn"), fail: count("fail"), info: count("info"), skipped: count("skipped") };
|
|
2044
|
+
const summary = { ok: count("ok"), warn: count("warn"), fail: count("fail"), info: count("info"), skipped: count("skipped"), unknown: count("unknown") };
|
|
1625
2045
|
const blockers = stamped.filter((entry) => entry.blocksFirstCommand).map((entry) => entry.id);
|
|
1626
2046
|
const verdict = blockers.length === 0 ? "ready" : "blocked";
|
|
1627
2047
|
/** The blockers a distro verdict owns: its own fails plus the host-level ones.
|
|
@@ -1641,6 +2061,7 @@ function report(checks, options, runInfo = {}) {
|
|
|
1641
2061
|
schemaVersion: 2,
|
|
1642
2062
|
generatedAt: new Date().toISOString(),
|
|
1643
2063
|
...(runInfo.config === undefined ? {} : { config: runInfo.config }),
|
|
2064
|
+
...(runInfo.scope === undefined ? {} : { scope: runInfo.scope }),
|
|
1644
2065
|
checks: stamped,
|
|
1645
2066
|
summary,
|
|
1646
2067
|
distroVerdicts,
|
|
@@ -1649,7 +2070,7 @@ function report(checks, options, runInfo = {}) {
|
|
|
1649
2070
|
...(runInfo.timingsMs === undefined ? {} : { timingsMs: runInfo.timingsMs }),
|
|
1650
2071
|
}, null, 2));
|
|
1651
2072
|
} else {
|
|
1652
|
-
console.log("
|
|
2073
|
+
console.log(doctorT("app"));
|
|
1653
2074
|
let section = "";
|
|
1654
2075
|
let lastDistro = /** @type {string | undefined} */ (undefined);
|
|
1655
2076
|
for (const entry of stamped) {
|
|
@@ -1663,16 +2084,23 @@ function report(checks, options, runInfo = {}) {
|
|
|
1663
2084
|
section = current;
|
|
1664
2085
|
console.log(`\n${section}`);
|
|
1665
2086
|
}
|
|
1666
|
-
const mark = entry.status
|
|
2087
|
+
const mark = doctorT(`mark.${entry.status}`);
|
|
1667
2088
|
console.log(` ${mark} ${entry.title}${entry.detail === undefined ? "" : ` — ${entry.detail}`}`);
|
|
1668
|
-
if (entry.remedy !== undefined) console.log(
|
|
2089
|
+
if (entry.remedy !== undefined) console.log(doctorT("fix.prefix", { remedy: entry.remedy }));
|
|
1669
2090
|
}
|
|
1670
|
-
|
|
2091
|
+
const summaryLine = doctorT("summary", { ok: summary.ok, warn: summary.warn, fail: summary.fail, info: summary.info })
|
|
2092
|
+
+ (summary.skipped > 0 ? doctorT("summary.skipped", { n: summary.skipped }) : "")
|
|
2093
|
+
+ (summary.unknown > 0 ? doctorT("summary.unknown", { n: summary.unknown }) : "");
|
|
2094
|
+
console.log(`\n${summaryLine}`);
|
|
1671
2095
|
const timingLine = Object.entries(runInfo.timingsMs ?? {}).filter(([key]) => key !== "total").map(([key, ms]) => `${key} ${ms}ms`).join(", ");
|
|
1672
|
-
if (timingLine.length > 0) console.log(
|
|
1673
|
-
if (verdict === "ready") console.log(
|
|
1674
|
-
|
|
1675
|
-
|
|
2096
|
+
if (timingLine.length > 0) console.log(doctorT("timings", { line: timingLine, total: runInfo.timingsMs?.total ?? "?" }));
|
|
2097
|
+
if (verdict === "ready") console.log(targets.length === 1 && targets[0] !== undefined
|
|
2098
|
+
? doctorT("verdict.ready.one", { target: targets[0] })
|
|
2099
|
+
: targets.length > 1
|
|
2100
|
+
? doctorT("verdict.ready.many", { targets: targets.join(", ") })
|
|
2101
|
+
: doctorT("verdict.ready.none"));
|
|
2102
|
+
else console.log(doctorT("verdict.blocked", { blockers: blockers.join(", ") }));
|
|
2103
|
+
if (summary.fail > 0 || summary.skipped > 0) console.log(doctorT("fix.hint"));
|
|
1676
2104
|
}
|
|
1677
2105
|
if (runInfo.bundle !== undefined) {
|
|
1678
2106
|
const bundle = {
|
|
@@ -1690,7 +2118,7 @@ function report(checks, options, runInfo = {}) {
|
|
|
1690
2118
|
payload = payload.split(homeReal).join("<redacted-home>").split(dshReal).join("<redacted-dsh-home>");
|
|
1691
2119
|
}
|
|
1692
2120
|
writeFileSync(runInfo.bundle.path, payload);
|
|
1693
|
-
console.log(
|
|
2121
|
+
console.log(doctorT("bundle.written", { path: runInfo.bundle.path, bytes: payload.length, redacted: runInfo.bundle.redact ? doctorT("bundle.redacted") : "" }));
|
|
1694
2122
|
}
|
|
1695
2123
|
return verdict === "blocked" ? 1 : 0;
|
|
1696
2124
|
}
|
|
@@ -1698,7 +2126,7 @@ function report(checks, options, runInfo = {}) {
|
|
|
1698
2126
|
if (process.argv[1] !== undefined && resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
|
|
1699
2127
|
const options = parseArgs(process.argv.slice(2));
|
|
1700
2128
|
if (options.help) {
|
|
1701
|
-
console.log("node scripts/doctor.mjs [distro] [--all] [--json] [--fix] [--install] [--yes] [--read-only] [--bundle <path>] [--redact]");
|
|
2129
|
+
console.log("node scripts/doctor.mjs [distro] [--all] [--json] [--quick] [--sections host,sandbox,session,conf,net,agent] [--fix] [--install] [--yes] [--read-only] [--bundle <path>] [--redact] [--locale <tag>]");
|
|
1702
2130
|
} else {
|
|
1703
2131
|
process.exitCode = await main(options);
|
|
1704
2132
|
}
|