dsh-plugin-wsl-env 0.23.0 → 0.24.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/lib/status.js ADDED
@@ -0,0 +1,425 @@
1
+ /**
2
+ * The sidebar panel's diagnostic route (`GET`/`POST /api/wsl-env/status`).
3
+ *
4
+ * The panel is a status/config surface, and the authoritative environment
5
+ * verdict is the doctor's. A browser plugin cannot reach a plugin-private Host
6
+ * method (the Client Remote assembly fixes its namespaces at build time), but
7
+ * it can reach an **authenticated exact Fetch route** on the `/api` channel:
8
+ * `ctx.connection.fetch.register` is the same seam the shipped Session-log and
9
+ * file routes use, it admits only the owner Peer, and it needs no generated
10
+ * wire schema. This row therefore publishes two answers:
11
+ *
12
+ * - `GET /api/wsl-env/status` — the installed distros (from `wsl.exe -l -q`,
13
+ * which starts nothing) plus the last successful verdict per distro,
14
+ * restored from the store below;
15
+ * - `GET /api/wsl-env/status?distro=<name>` — one distro's quick doctor
16
+ * report, digested to the same shape the `/wsl-doctor` command renders;
17
+ * - `POST /api/wsl-env/status?distro=<name>` — the panel's repair action: a
18
+ * full doctor run with `--fix-owned`, which sweeps stale session scopes
19
+ * and purges a broken agent cache, then re-verifies both and answers with
20
+ * the same digest plus the `fix.*` rows. Nothing outside the plugin's own
21
+ * state is touched (no packages, no Windows git config), so the panel
22
+ * stays a diagnostic surface that can heal its own residue.
23
+ *
24
+ * The doctor runs as the standalone CLI subprocess, exactly as the command row
25
+ * runs it, so a diagnosis still answers when the plugin's own module graph is
26
+ * what is broken. Runs are cached per distro for `cacheMs`; `refresh=1` drops
27
+ * the entry. A check is only ever started by an explicit click in the panel:
28
+ * probing a stopped distro boots it, which a page load must not do to every
29
+ * installed distro.
30
+ *
31
+ * The last result per distro — success or failure — is persisted to
32
+ * `$DSH_HOME/cache/dsh-plugin-wsl-env/status.json` (falling back to `~/.dsh`),
33
+ * so a page reload or an app restart still shows what the last check found and
34
+ * when. `source` records whether that run came from an explicit panel action
35
+ * or from the page-load background refresh; a failed background run overwrites
36
+ * the stored result exactly as it was observed. Results are never labeled
37
+ * expired: the timestamp is the timestamp, and the row's check button is the
38
+ * next step. Writing is best-effort — a read-only home degrades to the
39
+ * in-memory cache rather than failing the diagnosis.
40
+ *
41
+ * This is a TypeScript source built to `lib/status.js`; edit THIS file and run
42
+ * `pnpm run build` — the artifact under `lib/` is generated, and `pnpm test`
43
+ * fails when it drifts.
44
+ *
45
+ * @module dsh-plugin-wsl-env/status
46
+ */
47
+ import z from "@deepseek-ai/schemastery";
48
+ import { mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
49
+ import { homedir } from "node:os";
50
+ import { dirname, join } from "node:path";
51
+ import { listDistros, listRunningDistros } from "./wsl.js";
52
+ import { digestReport, sectionOf } from "./wsl-doctor-tool.js";
53
+ import { runDoctorCli } from "./wsl-doctor-command.js";
54
+ export const name = "wsl-status";
55
+ /** The one route the panel fetches; it must live under the `/api` channel. */
56
+ export const STATUS_PATH = "/api/wsl-env/status";
57
+ /** The on-disk schema version. */
58
+ const STORE_VERSION = 1;
59
+ /**
60
+ * Where the last successful results live: the harness home's cache directory,
61
+ * falling back to `~/.dsh` when the Host process names no home. The panel's
62
+ * guidance must survive a page reload and an app restart; an in-memory cache
63
+ * cannot, because the page's own reload drops the browser state and a plugin
64
+ * reload drops the process state.
65
+ * @returns the absolute path of the status store.
66
+ */
67
+ function defaultStatePath() {
68
+ const configured = (process.env.DSH_HOME ?? "").trim();
69
+ const home = configured.length > 0 ? configured : join(homedir(), ".dsh");
70
+ return join(home, "cache", "dsh-plugin-wsl-env", "status.json");
71
+ }
72
+ export const Config = z.object({
73
+ /** How long one distro's quick verdict stays fresh, in milliseconds. */
74
+ cacheMs: z.natural().default(15_000),
75
+ /** Deadline for one scoped quick doctor run, in milliseconds. */
76
+ timeoutMs: z.natural().min(1).default(90_000),
77
+ /** `wsl.exe` to list the distros; keep in step with the providers' `wslPath`. */
78
+ wslPath: z.string().default("wsl.exe"),
79
+ });
80
+ /**
81
+ * Read the status store. A missing, unreadable or malformed file is no
82
+ * guidance at all: the handler starts empty and the next check rewrites it.
83
+ * @param path - the store path; empty disables persistence.
84
+ * @returns the parsed store, or undefined.
85
+ */
86
+ function readStored(path) {
87
+ if (path.length === 0)
88
+ return undefined;
89
+ try {
90
+ const parsed = JSON.parse(readFileSync(path, "utf8"));
91
+ if (parsed.version !== STORE_VERSION || parsed.distros === null || typeof parsed.distros !== "object")
92
+ return undefined;
93
+ return { version: STORE_VERSION, distros: parsed.distros };
94
+ }
95
+ catch {
96
+ return undefined;
97
+ }
98
+ }
99
+ /**
100
+ * Write the last successful verdicts atomically. A read-only or missing home
101
+ * must not fail the diagnosis that produced them, so a write error is
102
+ * swallowed: the in-memory answer still reaches the panel.
103
+ * @param path - the store path; empty disables persistence.
104
+ * @param verdicts - the verdicts to persist, keyed by distro.
105
+ */
106
+ function writeStored(path, verdicts) {
107
+ if (path.length === 0)
108
+ return;
109
+ const distros = {};
110
+ for (const [distro, entry] of verdicts) {
111
+ const stored = { ...entry.view };
112
+ delete stored.cached;
113
+ distros[distro] = stored;
114
+ }
115
+ try {
116
+ mkdirSync(dirname(path), { recursive: true });
117
+ const temporary = `${path}.tmp`;
118
+ writeFileSync(temporary, `${JSON.stringify({ version: STORE_VERSION, distros }, null, 2)}\n`, { mode: 0o600 });
119
+ renameSync(temporary, path);
120
+ }
121
+ catch {
122
+ // Best effort: the result is still served from memory.
123
+ }
124
+ }
125
+ /**
126
+ * Build the JSON response for one request.
127
+ * @param body - the JSON-serializable value.
128
+ * @param status - the HTTP status.
129
+ * @returns a JSON response.
130
+ */
131
+ function json(body, status = 200) {
132
+ return Response.json(body, { status, headers: { "cache-control": "no-store" } });
133
+ }
134
+ /**
135
+ * Count the statuses the report actually produced for this distro, leaving
136
+ * out the digest's synthetic "not run in this scope" catalog rows.
137
+ * @param findings - the report's rows, already stripped of `fix.*` rows.
138
+ * @returns the per-status totals.
139
+ */
140
+ function countsOf(findings) {
141
+ const actual = findings.filter((item) => item.distro !== "(not run)");
142
+ const count = (status) => actual.filter((item) => item.status === status).length;
143
+ return {
144
+ ok: count("ok"),
145
+ warn: count("warn"),
146
+ fail: count("fail"),
147
+ info: count("info"),
148
+ skipped: count("skipped"),
149
+ unknown: count("unknown"),
150
+ };
151
+ }
152
+ /**
153
+ * Digest one parsed doctor report into the panel's shape.
154
+ * @param digest - the shared digest the command and the tool render.
155
+ * @param distro - the distro the report answers for.
156
+ * @param now - the run's timestamp.
157
+ * @param repaired - whether the run was the full `--fix-owned` action.
158
+ * @param source - who started the run.
159
+ * @returns the panel view.
160
+ */
161
+ function viewOf(digest, distro, now, repaired, source) {
162
+ // The fix rows are the repair's own narration, not findings about the
163
+ // environment: keep them out of the failure/warning lists so a repair does
164
+ // not double-list its work, and surface them separately.
165
+ // The digest also carries synthetic skip rows for catalog ids the report
166
+ // never emitted (`fix.git-trust` on a quiet run): only the fix rows the
167
+ // doctor actually produced are repairs.
168
+ const fixes = digest.items.filter((item) => item.id.startsWith("fix.") && item.status !== "skipped");
169
+ const findings = digest.items.filter((item) => !item.id.startsWith("fix."));
170
+ // Which findings the plugin-owned repair can actually act on. A repair
171
+ // button that cannot apply is worse than no button: the user sees warnings,
172
+ // clicks "修复", and nothing changes. The cache only explains a failed
173
+ // handshake when the cache is the finding — otherwise the handshake needs a
174
+ // reinstall or a resync, not a purge.
175
+ // A broken cache is `warn` under `agentBackend: auto` and `fail` under
176
+ // `native`; both are plugin-owned and repairable by the purge.
177
+ const cacheBroken = findings.some((item) => item.id === "agent.cache" && (item.status === "warn" || item.status === "fail"));
178
+ const repairable = findings
179
+ .filter((item) => (item.id === "runtime.scopes" && item.status === "warn")
180
+ || (item.id === "agent.cache" && (item.status === "warn" || item.status === "fail"))
181
+ || (item.id === "agent.handshake" && item.status === "fail" && cacheBroken))
182
+ .map((item) => item.id);
183
+ // Every executed check, in report order, grouped later by section. The
184
+ // synthetic catalog rows and the repair's own `fix.*` narration are not
185
+ // findings about this distro, so they stay out.
186
+ const checkRows = findings
187
+ .filter((item) => item.scopeSkip !== true)
188
+ .map((item) => ({
189
+ id: item.id,
190
+ title: item.title,
191
+ status: item.status,
192
+ detail: item.detail,
193
+ ...(item.remedy === undefined ? {} : { remedy: item.remedy }),
194
+ section: sectionOf(item.id),
195
+ }));
196
+ return {
197
+ distro,
198
+ verdict: digest.verdict === "ready" ? "ready" : "blocked",
199
+ repaired,
200
+ repairs: repaired
201
+ ? fixes.map((item) => ({
202
+ id: item.id,
203
+ title: item.title,
204
+ status: item.status,
205
+ detail: item.detail,
206
+ ...(item.remedy === undefined ? {} : { remedy: item.remedy }),
207
+ }))
208
+ : [],
209
+ repairable,
210
+ checkedAt: now,
211
+ cached: false,
212
+ source,
213
+ failures: digest.failing
214
+ .filter((check) => !check.id.startsWith("fix."))
215
+ .map((check) => ({ id: check.id, detail: check.detail, remedy: check.remedy })),
216
+ warnings: findings
217
+ .filter((item) => item.status === "warn")
218
+ .map((item) => ({
219
+ id: item.id,
220
+ detail: item.detail,
221
+ ...(item.remedy === undefined ? {} : { remedy: item.remedy }),
222
+ })),
223
+ // Count the rows this run actually answered. The digest's synthetic
224
+ // "not run in this scope" rows describe the catalog, not this distro, and
225
+ // a repair's own `fix.*` rows are narration — both stay out.
226
+ counts: countsOf(findings),
227
+ sections: digest.sections,
228
+ checks: checkRows,
229
+ notRun: digest.scope === undefined ? 0 : digest.notRun,
230
+ blockers: digest.blockers,
231
+ };
232
+ }
233
+ /**
234
+ * Build the route handler.
235
+ *
236
+ * One handler owns one cache, so the row registers exactly one instance and an
237
+ * unload drops every verdict with it.
238
+ *
239
+ * @param options - the distro, runner, and cache seams.
240
+ * @returns the request handler.
241
+ */
242
+ export function createStatusHandler(options) {
243
+ const now = options.now ?? (() => Date.now());
244
+ const statePath = options.statePath ?? defaultStatePath();
245
+ const verdicts = new Map();
246
+ let list;
247
+ // Restore the last successful results before the first request. The stored
248
+ // view is the panel's shape; the fields later releases may have added are
249
+ // defaulted so an older store still renders instead of failing the load.
250
+ for (const [distro, view] of Object.entries(readStored(statePath)?.distros ?? {})) {
251
+ if (view === null || typeof view !== "object" || view.distro !== distro || typeof view.checkedAt !== "number")
252
+ continue;
253
+ verdicts.set(distro, {
254
+ at: view.checkedAt,
255
+ view: {
256
+ ...view,
257
+ repairs: Array.isArray(view.repairs) ? view.repairs : [],
258
+ repairable: Array.isArray(view.repairable) ? view.repairable : [],
259
+ failures: Array.isArray(view.failures) ? view.failures : [],
260
+ warnings: Array.isArray(view.warnings) ? view.warnings : [],
261
+ counts: view.counts ?? { ok: 0, warn: 0, fail: 0, info: 0, skipped: 0, unknown: 0 },
262
+ sections: Array.isArray(view.sections) ? view.sections : [],
263
+ checks: Array.isArray(view.checks) ? view.checks : [],
264
+ notRun: typeof view.notRun === "number" ? view.notRun : 0,
265
+ blockers: Array.isArray(view.blockers) ? view.blockers : [],
266
+ source: view.source === "background" ? "background" : "user",
267
+ cached: false,
268
+ },
269
+ });
270
+ }
271
+ /**
272
+ * Mark a stored or fresh answer for transport. The view's own `checkedAt`
273
+ * and `source` are the truth about the run; `cached` only says whether this
274
+ * response re-ran the doctor.
275
+ * @param view - the view to present.
276
+ * @param cached - whether the answer came from the cache.
277
+ * @returns the presented view.
278
+ */
279
+ const present = (view, cached) => ({ ...view, cached });
280
+ const installed = async (refresh) => {
281
+ if (!refresh && list !== undefined && now() - list.at < options.cacheMs)
282
+ return list.names;
283
+ const names = await options.distros();
284
+ list = { at: now(), names };
285
+ return names;
286
+ };
287
+ const check = async (distro, refresh, repair = false, source = "user") => {
288
+ const cached = verdicts.get(distro);
289
+ // A failure is a fact of this moment: it is kept for the list and the
290
+ // store, but a plain GET re-runs instead of serving it as fresh.
291
+ if (!refresh && cached !== undefined && cached.view.verdict !== "error" && now() - cached.at < options.cacheMs)
292
+ return present(cached.view, true);
293
+ const at = now();
294
+ let view;
295
+ try {
296
+ // A repair needs a full run: `--fix` refuses a scoped one because a
297
+ // scoped report cannot re-verify what it did not probe. `--fix-owned`
298
+ // keeps the loop on plugin-owned state (scopes, agent cache) — the panel
299
+ // never installs packages or rewrites Windows-owned configuration.
300
+ const argv = repair
301
+ ? ["--json", "--fix", "--fix-owned", "--distro", distro]
302
+ : ["--json", "--quick", "--distro", distro];
303
+ const raw = await options.runCli(argv, undefined, options.timeoutMs);
304
+ const report = JSON.parse(raw);
305
+ view = viewOf(digestReport(report, distro), distro, at, repair, source);
306
+ }
307
+ catch (error) {
308
+ view = {
309
+ distro,
310
+ verdict: "error",
311
+ repaired: false,
312
+ repairs: [],
313
+ repairable: [],
314
+ checkedAt: at,
315
+ cached: false,
316
+ source,
317
+ failures: [],
318
+ warnings: [],
319
+ counts: { ok: 0, warn: 0, fail: 0, info: 0, skipped: 0, unknown: 0 },
320
+ sections: [],
321
+ checks: [],
322
+ notRun: 0,
323
+ blockers: [],
324
+ error: error?.message ?? String(error),
325
+ };
326
+ }
327
+ // Persist the result exactly as observed, failure included: a failed
328
+ // background refresh must overwrite the last good result rather than
329
+ // leave a stale success on screen. The store keeps the truth; the panel
330
+ // shows the error and offers the retry.
331
+ verdicts.set(distro, { at, view });
332
+ writeStored(statePath, verdicts);
333
+ return present(view, false);
334
+ };
335
+ return async (request) => {
336
+ if (request.method !== "GET" && request.method !== "POST")
337
+ return json({ error: "只支持 GET 与 POST" }, 405);
338
+ const url = new URL(request.url);
339
+ const repair = request.method === "POST";
340
+ const refresh = url.searchParams.get("refresh") === "1";
341
+ const requested = url.searchParams.get("distro");
342
+ let names;
343
+ try {
344
+ names = await installed(repair || refresh);
345
+ }
346
+ catch (error) {
347
+ return json({ error: `无法读取发行版清单:${error?.message ?? String(error)}` }, 502);
348
+ }
349
+ if (requested === null || requested === "") {
350
+ if (repair)
351
+ return json({ error: "修复需要指定发行版" }, 400);
352
+ // The running list bounds the panel's background refresh: only a
353
+ // distro that is already up may be re-checked without the user asking,
354
+ // because a probe boots a stopped one. A failed read means no refresh.
355
+ let running = [];
356
+ try {
357
+ running = (await options.running?.() ?? []).filter((name) => names.includes(name));
358
+ }
359
+ catch {
360
+ running = [];
361
+ }
362
+ const reply = {
363
+ distros: names,
364
+ running,
365
+ cached: [...verdicts.entries()]
366
+ .filter(([distro]) => names.includes(distro))
367
+ .map(([, entry]) => present(entry.view, true)),
368
+ };
369
+ return json(reply);
370
+ }
371
+ if (!names.includes(requested))
372
+ return json({ error: `未知发行版:${requested}` }, 400);
373
+ const background = !repair && url.searchParams.get("background") === "1";
374
+ return json(await check(requested, refresh || repair, repair, background ? "background" : "user"));
375
+ };
376
+ }
377
+ /**
378
+ * Resolve the row's config into handler options.
379
+ *
380
+ * The seams live in {@link StatusHandlerOptions} (and are exercised by the
381
+ * handler tests). Reading them off the Context would be wrong twice over: a
382
+ * Cordis context property accessor throws for a name that was not injected
383
+ * ("cannot get property ... without inject"), which silently broke route
384
+ * registration once already, and a plugin has no business inventing service
385
+ * names.
386
+ *
387
+ * @param config - the schema-validated config.
388
+ * @returns handler options.
389
+ */
390
+ function optionsFor(config) {
391
+ const wslPath = config.wslPath ?? "wsl.exe";
392
+ return {
393
+ cacheMs: config.cacheMs ?? 15_000,
394
+ timeoutMs: config.timeoutMs ?? 90_000,
395
+ distros: () => listDistros({ wslPath }),
396
+ running: () => listRunningDistros({ wslPath }),
397
+ runCli: runDoctorCli,
398
+ };
399
+ }
400
+ /**
401
+ * Mount the row: register the route once the Host connection is available.
402
+ *
403
+ * A composition without `connection` (headless, ACP) leaves the row inert —
404
+ * the same posture the other surface rows take.
405
+ *
406
+ * @param ctx - the cordis context.
407
+ * @param config - the schema-validated config.
408
+ */
409
+ export function apply(ctx, config = {}) {
410
+ if (typeof ctx.inject !== "function")
411
+ return;
412
+ ctx.inject(["connection"], (scope) => {
413
+ const connection = scope.connection ?? scope.get?.("connection");
414
+ if (connection === undefined)
415
+ return;
416
+ const handler = createStatusHandler(optionsFor(config));
417
+ const dispose = connection.fetch.register({
418
+ path: STATUS_PATH,
419
+ methods: ["GET", "POST"],
420
+ requestBody: "buffered",
421
+ fetch: handler,
422
+ });
423
+ scope.effect?.(() => () => { void dispose(); }, `wsl-status: ${STATUS_PATH}`);
424
+ });
425
+ }
@@ -113,6 +113,8 @@ interface CheckItem {
113
113
  detail: string;
114
114
  distro?: string;
115
115
  remedy?: string;
116
+ /** Synthetic catalog row: this run's scope never executed the check. */
117
+ scopeSkip?: true;
116
118
  }
117
119
  /** The tool's result: the doctor's verdict, condensed for the model. */
118
120
  export interface DoctorDigest {
@@ -133,6 +135,12 @@ export interface DoctorDigest {
133
135
  distros: DistroTally[];
134
136
  /** Every check the report carried, in report order — the itemized listing. */
135
137
  items: CheckItem[];
138
+ /**
139
+ * Catalog ids the report did not carry: checks a scoped run never executed,
140
+ * plus conditional ids whose trigger did not fire (a quiet full run's
141
+ * `distro.present` / `fix.git-trust`).
142
+ */
143
+ notRun: number;
136
144
  /** The scope the report answers for (quick profile or a section subset). */
137
145
  scope?: {
138
146
  sections: string[];
@@ -56,7 +56,7 @@ export function sectionOf(id) {
56
56
  return "conf";
57
57
  if (id === "distro.dns")
58
58
  return "net";
59
- if (id.startsWith("agent.") || id === "functional.exec" || id === "functional.fs")
59
+ if (id.startsWith("agent.") || id === "functional.exec" || id === "functional.fs" || id === "functional.native")
60
60
  return "agent";
61
61
  return "host";
62
62
  }
@@ -83,24 +83,21 @@ const SKIP_DETAIL_PREFIX = "skipped: ";
83
83
  * "out of scope".
84
84
  */
85
85
  export const CHECK_CATALOG = [
86
- "agent.arch",
87
86
  "agent.cache",
88
87
  "agent.handshake",
88
+ "agent.home-writable",
89
89
  "agent.native",
90
90
  "config.deprecated",
91
91
  "config.effective",
92
92
  "config.preset-trap",
93
- "config.profiles",
94
93
  "config.wslconfig",
95
94
  "distro.clock",
96
95
  "distro.disk",
97
96
  "distro.dns",
98
- "distro.family",
99
- "distro.home",
100
- "distro.kernel",
97
+ "distro.identity",
101
98
  "distro.present",
102
99
  "distro.reachable",
103
- "distro.shell",
100
+ "distro.unc",
104
101
  "distro.wsl-conf-automount",
105
102
  "distro.wsl-conf-boot",
106
103
  "distro.wsl-conf-interop",
@@ -108,11 +105,12 @@ export const CHECK_CATALOG = [
108
105
  "fix.git-trust",
109
106
  "functional.exec",
110
107
  "functional.fs",
108
+ "functional.native",
111
109
  "functional.sandbox",
112
110
  "git.win-safe",
111
+ "host.disk",
113
112
  "host.distros",
114
- "host.windows",
115
- "host.wsl",
113
+ "host.platform",
116
114
  "peers.versions",
117
115
  "runtime.scopes",
118
116
  "sandbox.bwrap",
@@ -124,7 +122,6 @@ export const CHECK_CATALOG = [
124
122
  "tools.git",
125
123
  "tools.inotifywait",
126
124
  "tools.rg",
127
- "update.latest",
128
125
  ];
129
126
  /**
130
127
  * Digest one doctor report down to what the model acts on: the verdict, the
@@ -197,6 +194,12 @@ export function digestReport(report, sessionDistro) {
197
194
  ...(verdict === undefined ? {} : { verdict }),
198
195
  };
199
196
  });
197
+ // Scope the listing never drops silently: every catalog id the report did
198
+ // not carry joins the items as an explicit skip row, so a quick or
199
+ // section-scoped answer still shows the full check surface. The same set
200
+ // feeds `notRun`, which the panel renders as "the full run covers N more".
201
+ const reported = new Set(checks.map((check) => check.id));
202
+ const notRunIds = CHECK_CATALOG.filter((id) => !reported.has(id));
200
203
  return {
201
204
  verdict,
202
205
  blockers,
@@ -216,17 +219,12 @@ export function digestReport(report, sessionDistro) {
216
219
  ? check.status === "fail" ? { remedy: "no remedy — see docs/DIAGNOSTICS.md" } : {}
217
220
  : { remedy: check.remedy }),
218
221
  }));
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 });
222
+ for (const id of notRunIds) {
223
+ rows.push({ id, title: id, status: "skipped", detail: SCOPE_SKIP_DETAIL, distro: NOT_RUN, scopeSkip: true });
227
224
  }
228
225
  return rows;
229
226
  })(),
227
+ notRun: notRunIds.length,
230
228
  ...(report.scope === undefined ? {} : { scope: report.scope }),
231
229
  distroVerdicts: report.distroVerdicts ?? [],
232
230
  note: verdict === "ready"
package/lib/wsl.d.ts CHANGED
@@ -59,6 +59,18 @@ export declare function runCapture(argv: string[], signal?: AbortSignal, deadlin
59
59
  * @returns distro names in WSL's own order, default distro first.
60
60
  */
61
61
  export declare function listDistros(options?: WslCallOptions): Promise<string[]>;
62
+ /**
63
+ * List the distros that are running right now (`wsl.exe -l --running -q`).
64
+ *
65
+ * The status panel uses this to decide which stored results may be refreshed
66
+ * in the background: probing a stopped distro boots it, and a page load must
67
+ * never do that. A failure here is not fatal to the caller — no running list
68
+ * means no background refresh, which is a prompt to check on demand instead.
69
+ *
70
+ * @param options - the `wsl.exe` path and optional cancellation.
71
+ * @returns running distro names in WSL's own order.
72
+ */
73
+ export declare function listRunningDistros(options?: WslCallOptions): Promise<string[]>;
62
74
  /**
63
75
  * Parse `wsl.exe -l -q` output into distro names. A pure seam so the CRLF and
64
76
  * blank-line shapes of the real output are unit-testable on hosts without
package/lib/wsl.js CHANGED
@@ -81,6 +81,21 @@ export async function listDistros(options = {}) {
81
81
  const stdout = await runCapture([options.wslPath ?? DEFAULT_WSL_PATH, "-l", "-q"], options.signal);
82
82
  return parseDistroList(stdout);
83
83
  }
84
+ /**
85
+ * List the distros that are running right now (`wsl.exe -l --running -q`).
86
+ *
87
+ * The status panel uses this to decide which stored results may be refreshed
88
+ * in the background: probing a stopped distro boots it, and a page load must
89
+ * never do that. A failure here is not fatal to the caller — no running list
90
+ * means no background refresh, which is a prompt to check on demand instead.
91
+ *
92
+ * @param options - the `wsl.exe` path and optional cancellation.
93
+ * @returns running distro names in WSL's own order.
94
+ */
95
+ export async function listRunningDistros(options = {}) {
96
+ const stdout = await runCapture([options.wslPath ?? DEFAULT_WSL_PATH, "-l", "--running", "-q"], options.signal);
97
+ return parseDistroList(stdout);
98
+ }
84
99
  /**
85
100
  * Parse `wsl.exe -l -q` output into distro names. A pure seam so the CRLF and
86
101
  * blank-line shapes of the real output are unit-testable on hosts without
@@ -15,7 +15,7 @@
15
15
  "verdict.ready.many": "verdict: READY — the first command should succeed in each of: {targets}",
16
16
  "verdict.blocked": "verdict: BLOCKED by: {blockers} — apply the fixes above, then rerun",
17
17
  "fix.prefix": " fix: {remedy}",
18
- "fix.hint": "run with --fix to sweep stale scopes; --fix --install asks before installing packages",
18
+ "fix.hint": "run with --fix to sweep stale scopes and purge a broken agent cache; --fix --install asks before installing packages",
19
19
  "sessions.title": "sessions across running distros",
20
20
  "sessions.none": " (none)",
21
21
  "sessions.no-user-manager": "no user manager — scopes unavailable",
@@ -26,5 +26,6 @@
26
26
  "bundle.redacted": ", redacted",
27
27
  "refusal.read-only": "doctor: --read-only refuses --fix/--install; run `pnpm run doctor --fix` instead",
28
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?"
29
+ "confirm.install": "Install {packages} in \"{distro}\" as root?",
30
+ "refusal.owned-install": "doctor: --fix-owned repairs plugin-owned state only and cannot be combined with --install"
30
31
  }
@@ -15,7 +15,7 @@
15
15
  "verdict.ready.many": "裁决: READY——首条命令应能在以下每个 distro 中成功: {targets}",
16
16
  "verdict.blocked": "裁决: BLOCKED——阻断项: {blockers};先应用上方的修复,再重跑",
17
17
  "fix.prefix": " 修复: {remedy}",
18
- "fix.hint": "加 --fix 清扫残留 scope;--fix --install 安装软件包前会先询问",
18
+ "fix.hint": "加 --fix 清扫残留 scope 并清理损坏的 agent 缓存;--fix --install 安装软件包前会先询问",
19
19
  "sessions.title": "正在运行的 distro 会话",
20
20
  "sessions.none": " (无)",
21
21
  "sessions.no-user-manager": "无用户管理器——scope 不可用",
@@ -26,5 +26,6 @@
26
26
  "bundle.redacted": ",已脱敏",
27
27
  "refusal.read-only": "doctor: --read-only 拒绝 --fix/--install;请改用 `pnpm run doctor --fix`",
28
28
  "refusal.scoped-fix": "doctor: --fix 需要完整运行——分区运行无法复核未探测的项目",
29
- "confirm.install": "以 root 在 \"{distro}\" 中安装 {packages}?"
29
+ "confirm.install": "以 root 在 \"{distro}\" 中安装 {packages}?",
30
+ "refusal.owned-install": "doctor: --fix-owned 只修复插件自有状态,不能与 --install 同用"
30
31
  }