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/picker.d.ts CHANGED
@@ -51,6 +51,18 @@ import z from "@deepseek-ai/schemastery";
51
51
  import { DirectoryPicker } from "@deepseek-ai/dsh-host-directory-picker";
52
52
  import type { Context } from "@deepseek-ai/cordis";
53
53
  import type { DirectoryEntry, DirectoryListing, DirectoryPickerBrowseCapability } from "@deepseek-ai/dsh-host-directory-picker";
54
+ /**
55
+ * Virtual root of the picker's category level: the Windows world and the WSL
56
+ * world. It is a sentinel, never a filesystem path; `list` recognises it and
57
+ * answers the two-category listing.
58
+ */
59
+ export declare const PICKER_ROOT = "\\\\dsh.localhost\\picker";
60
+ /**
61
+ * Virtual root of the Windows branch: the host's drive roots. Start the
62
+ * Windows walk at the drives rather than at one user's home, so the branch
63
+ * covers every volume and every account.
64
+ */
65
+ export declare const HOST_ROOT = "\\\\dsh.localhost\\windows";
54
66
  /**
55
67
  * The resolved service configuration, as {@link WslDirectoryPicker.Config} yields.
56
68
  */
@@ -63,7 +75,9 @@ interface PickerConfig {
63
75
  */
64
76
  preferredDistro: string;
65
77
  /**
66
- * Whether the Windows home is also offered at the root level.
78
+ * Whether the picker offers the Windows path branch. That branch starts at
79
+ * the drive roots, so it covers every volume and account; without it the
80
+ * category level carries the WSL branch alone.
67
81
  */
68
82
  includeHostHome: boolean;
69
83
  /**
@@ -90,9 +104,10 @@ export declare class WslDirectoryPicker extends DirectoryPicker {
90
104
  */
91
105
  preferredDistro: z<string, string, "defined">;
92
106
  /**
93
- * Also offer the Windows home directory at the root level, so a normal
94
- * host folder stays reachable without typing a path. The dialog's editable
95
- * path zone accepts any Windows path either way.
107
+ * Offer the Windows path branch, starting at the drive roots, so every
108
+ * volume and account stays reachable without typing a path. Without it the
109
+ * category level carries the WSL branch alone; the dialog's editable path
110
+ * zone accepts any Windows path either way.
96
111
  */
97
112
  includeHostHome: z<boolean, boolean, "defined">;
98
113
  /** Bound on the directory rows one `list` call may return; the level is flagged truncated. */
@@ -108,9 +123,10 @@ export declare class WslDirectoryPicker extends DirectoryPicker {
108
123
  */
109
124
  preferredDistro: z<string, string, "defined">;
110
125
  /**
111
- * Also offer the Windows home directory at the root level, so a normal
112
- * host folder stays reachable without typing a path. The dialog's editable
113
- * path zone accepts any Windows path either way.
126
+ * Offer the Windows path branch, starting at the drive roots, so every
127
+ * volume and account stays reachable without typing a path. Without it the
128
+ * category level carries the WSL branch alone; the dialog's editable path
129
+ * zone accepts any Windows path either way.
114
130
  */
115
131
  includeHostHome: z<boolean, boolean, "defined">;
116
132
  /** Bound on the directory rows one `list` call may return; the level is flagged truncated. */
@@ -171,18 +187,34 @@ export declare class WslDirectoryPicker extends DirectoryPicker {
171
187
  */
172
188
  homeOf(distro: string, signal?: AbortSignal): Promise<string>;
173
189
  /**
174
- * The root level: one row per installed distro, plus the Windows home when
175
- * configured. `path` is the preferred distro's root rather than the share
176
- * root, so adopting the level with nothing selected still yields a real
177
- * directory; the breadcrumb's "WSL" row carries the share root and returns
178
- * here.
190
+ * The category level: the Windows world and the WSL world.
191
+ *
192
+ * `path` is the Windows home — a real directory — so adopting the level with
193
+ * nothing selected still yields something adoptable; the entries are the two
194
+ * branches, and the "工作区" crumb returns here from either one.
195
+ *
196
+ * @param signal - optional cancellation.
197
+ * @returns the category listing.
198
+ */
199
+ categoryLevel(signal?: AbortSignal): Promise<DirectoryListing>;
200
+ /**
201
+ * The WSL branch: one row per installed distro. `path` is the preferred
202
+ * distro's root rather than the share root, so adopting the level with
203
+ * nothing selected still yields a real directory.
179
204
  *
180
205
  * @param signal - optional cancellation.
181
- * @returns the root listing.
206
+ * @returns the distro listing.
207
+ */
208
+ distroLevel(signal?: AbortSignal): Promise<DirectoryListing>;
209
+ /**
210
+ * The Windows branch: the host's drive roots, so the walk starts at every
211
+ * volume rather than at one account's home.
212
+ *
213
+ * @returns the drive listing.
182
214
  */
183
- rootLevel(signal?: AbortSignal): Promise<DirectoryListing>;
215
+ driveLevel(): Promise<DirectoryListing>;
184
216
  /**
185
- * Breadcrumb rows for a level, headed by the WSL row.
217
+ * Breadcrumb rows for a level: the category root, its world, then the path.
186
218
  *
187
219
  * @param target - the directory being listed.
188
220
  * @returns breadcrumb rows.
@@ -191,7 +223,9 @@ export declare class WslDirectoryPicker extends DirectoryPicker {
191
223
  /**
192
224
  * List one directory level.
193
225
  *
194
- * @param path - absolute directory; absent or the share root lists the distros.
226
+ * @param path - absent, the picker root or the WSL share root selects a
227
+ * virtual level (categories, distros or drives); anything else is a real
228
+ * directory.
195
229
  * @param signal - caller lifetime.
196
230
  * @returns the level's listing with its ancestry.
197
231
  * @throws DirectoryPickerError with code `directory-unreadable`.
package/lib/picker.js CHANGED
@@ -59,6 +59,20 @@ import { sharedAgent } from "./agent-shared.js";
59
59
  import { AgentUnavailableError } from "./agent-errors.js";
60
60
  /** How long a resolved distro list stays fresh before it is queried again. */
61
61
  const DEFAULT_DISTRO_CACHE_MS = 5_000;
62
+ /**
63
+ * Virtual root of the picker's category level: the Windows world and the WSL
64
+ * world. It is a sentinel, never a filesystem path; `list` recognises it and
65
+ * answers the two-category listing.
66
+ */
67
+ export const PICKER_ROOT = "\\\\dsh.localhost\\picker";
68
+ /**
69
+ * Virtual root of the Windows branch: the host's drive roots. Start the
70
+ * Windows walk at the drives rather than at one user's home, so the branch
71
+ * covers every volume and every account.
72
+ */
73
+ export const HOST_ROOT = "\\\\dsh.localhost\\windows";
74
+ /** The breadcrumb jump targets every listing shares. */
75
+ const PICKER_ROOTS = { picker: PICKER_ROOT, windows: HOST_ROOT, wsl: UNC_PROVIDER_ROOT };
62
76
  /**
63
77
  * Await `operation`, but reject with the signal's reason the moment it aborts.
64
78
  * Node's filesystem reads are not retractable, so the operation itself keeps
@@ -145,9 +159,10 @@ export class WslDirectoryPicker extends DirectoryPicker {
145
159
  */
146
160
  preferredDistro: z.string().default(""),
147
161
  /**
148
- * Also offer the Windows home directory at the root level, so a normal
149
- * host folder stays reachable without typing a path. The dialog's editable
150
- * path zone accepts any Windows path either way.
162
+ * Offer the Windows path branch, starting at the drive roots, so every
163
+ * volume and account stays reachable without typing a path. Without it the
164
+ * category level carries the WSL branch alone; the dialog's editable path
165
+ * zone accepts any Windows path either way.
151
166
  */
152
167
  includeHostHome: z.boolean().default(true),
153
168
  /** Bound on the directory rows one `list` call may return; the level is flagged truncated. */
@@ -237,54 +252,119 @@ export class WslDirectoryPicker extends DirectoryPicker {
237
252
  return home;
238
253
  }
239
254
  /**
240
- * The root level: one row per installed distro, plus the Windows home when
241
- * configured. `path` is the preferred distro's root rather than the share
242
- * root, so adopting the level with nothing selected still yields a real
243
- * directory; the breadcrumb's "WSL" row carries the share root and returns
244
- * here.
255
+ * The category level: the Windows world and the WSL world.
256
+ *
257
+ * `path` is the Windows home — a real directory — so adopting the level with
258
+ * nothing selected still yields something adoptable; the entries are the two
259
+ * branches, and the "工作区" crumb returns here from either one.
260
+ *
261
+ * @param signal - optional cancellation.
262
+ * @returns the category listing.
263
+ */
264
+ async categoryLevel(signal) {
265
+ const entries = [];
266
+ // The key historically meant "also offer Windows paths"; it now gates the
267
+ // whole Windows branch, whose walk starts at the drives.
268
+ if (this.config.includeHostHome)
269
+ entries.push({ name: "Windows 路径", path: HOST_ROOT, hidden: false });
270
+ entries.push({ name: "WSL 发行版", path: UNC_PROVIDER_ROOT, hidden: false });
271
+ const preferred = await this.preferredDistro(signal);
272
+ const home = preferred.length > 0 ? await this.homeOf(preferred, signal) : homedir();
273
+ return {
274
+ path: homedir(),
275
+ home,
276
+ crumbs: [{ name: "工作区", path: PICKER_ROOT, hidden: false }],
277
+ entries,
278
+ truncated: false,
279
+ };
280
+ }
281
+ /**
282
+ * The WSL branch: one row per installed distro. `path` is the preferred
283
+ * distro's root rather than the share root, so adopting the level with
284
+ * nothing selected still yields a real directory.
245
285
  *
246
286
  * @param signal - optional cancellation.
247
- * @returns the root listing.
287
+ * @returns the distro listing.
248
288
  */
249
- async rootLevel(signal) {
289
+ async distroLevel(signal) {
250
290
  const distros = await this.distros(signal);
251
291
  const preferred = await this.preferredDistro(signal);
252
- const entries = [];
253
- if (this.config.includeHostHome) {
254
- const hostHome = homedir();
255
- entries.push({ name: hostHome, path: hostHome, hidden: false });
256
- }
257
- for (const distro of distros)
258
- entries.push({ name: distro, path: distroRoot(distro), hidden: false });
292
+ const entries = distros.map((distro) => ({
293
+ name: distro,
294
+ path: distroRoot(distro),
295
+ hidden: false,
296
+ }));
259
297
  const home = preferred.length > 0 ? await this.homeOf(preferred, signal) : homedir();
260
298
  return {
261
299
  path: preferred.length > 0 ? distroRoot(preferred) : homedir(),
262
300
  home,
263
- crumbs: [{ name: "WSL", path: UNC_PROVIDER_ROOT, hidden: false }],
301
+ crumbs: [
302
+ { name: "工作区", path: PICKER_ROOT, hidden: false },
303
+ { name: "WSL 发行版", path: UNC_PROVIDER_ROOT, hidden: false },
304
+ ],
305
+ entries,
306
+ truncated: false,
307
+ };
308
+ }
309
+ /**
310
+ * The Windows branch: the host's drive roots, so the walk starts at every
311
+ * volume rather than at one account's home.
312
+ *
313
+ * @returns the drive listing.
314
+ */
315
+ async driveLevel() {
316
+ const entries = [];
317
+ for (const letter of "CDEFGHIJKLMNOPQRSTUVWXYZ") {
318
+ const path = `${letter}:\\`;
319
+ try {
320
+ await stat(path);
321
+ }
322
+ catch {
323
+ continue;
324
+ }
325
+ entries.push({ name: path, path, hidden: false });
326
+ }
327
+ const home = homedir();
328
+ return {
329
+ path: home,
330
+ home,
331
+ crumbs: [
332
+ { name: "工作区", path: PICKER_ROOT, hidden: false },
333
+ { name: "Windows 路径", path: HOST_ROOT, hidden: false },
334
+ ],
264
335
  entries,
265
336
  truncated: false,
266
337
  };
267
338
  }
268
339
  /**
269
- * Breadcrumb rows for a level, headed by the WSL row.
340
+ * Breadcrumb rows for a level: the category root, its world, then the path.
270
341
  *
271
342
  * @param target - the directory being listed.
272
343
  * @returns breadcrumb rows.
273
344
  */
274
345
  crumbsFor(target) {
275
- return breadcrumbs(target, UNC_PROVIDER_ROOT);
346
+ return breadcrumbs(target, PICKER_ROOTS);
276
347
  }
277
348
  /**
278
349
  * List one directory level.
279
350
  *
280
- * @param path - absolute directory; absent or the share root lists the distros.
351
+ * @param path - absent, the picker root or the WSL share root selects a
352
+ * virtual level (categories, distros or drives); anything else is a real
353
+ * directory.
281
354
  * @param signal - caller lifetime.
282
355
  * @returns the level's listing with its ancestry.
283
356
  * @throws DirectoryPickerError with code `directory-unreadable`.
284
357
  */
285
358
  async list(path, signal) {
286
- if (path === void 0 || isProviderRoot(path))
287
- return this.rootLevel(signal);
359
+ // Sentinel comparison trims trailing separators; the real-path branch keeps
360
+ // the spelling it was given — `C:\` must stay a volume root, not `C:`.
361
+ const sentinel = path === undefined ? "" : path.replace(/[\\/]+$/, "");
362
+ if (path === undefined || sentinel === "" || sentinel === PICKER_ROOT)
363
+ return this.categoryLevel(signal);
364
+ if (sentinel === HOST_ROOT)
365
+ return this.driveLevel();
366
+ if (isProviderRoot(sentinel))
367
+ return this.distroLevel(signal);
288
368
  if (!fullyQualified(path)) {
289
369
  throw new DirectoryPickerError("directory-unreadable", path, `cannot list "${path}": not a fully qualified path`);
290
370
  }
@@ -19,15 +19,34 @@
19
19
  * and run `pnpm run build` — the artifact under `lib/` is generated, and
20
20
  * `pnpm test` fails when it drifts.
21
21
  */
22
+ /**
23
+ * Whether a workspace lies inside one of the directories the operator opened
24
+ * for Windows access (9p) instead of the distro environment.
25
+ *
26
+ * The comparison is prefix-based on whole path segments: `\\wsl.localhost\ubuntu\a`
27
+ * matches the directory itself and everything below it, but not `…\ab`. Paths
28
+ * are Windows/UNC paths, hence case-insensitive.
29
+ *
30
+ * @param cwd - the session's workspace directory.
31
+ * @param windowsAccess - directories opened in Windows access mode.
32
+ * @returns true when this workspace opted out of the distro environment.
33
+ */
34
+ export declare function isWindowsAccessWorkspace(cwd: string, windowsAccess: readonly string[]): boolean;
22
35
  /**
23
36
  * The adoption decision.
24
37
  *
25
- * @param input - the new session's workspace, the preset it currently has, and
26
- * the registry default.
38
+ * `windowsAccess` lists directories the operator explicitly opened for Windows
39
+ * access; a session inside one of them keeps the host preset, so the choice
40
+ * survives every later session in that workspace rather than only the one the
41
+ * operator answered the dialog for.
42
+ *
43
+ * @param input - the new session's workspace, the preset it currently has, the
44
+ * registry default, and the directories reserved for Windows access.
27
45
  * @returns true when the WSL preset should be selected for this session.
28
46
  */
29
- export declare function shouldAdoptWslPreset({ cwd, current, fallback }?: {
47
+ export declare function shouldAdoptWslPreset({ cwd, current, fallback, windowsAccess }?: {
30
48
  cwd?: string;
31
49
  current?: string;
32
50
  fallback?: string;
51
+ windowsAccess?: readonly string[];
33
52
  }): boolean;
@@ -20,16 +20,49 @@
20
20
  * `pnpm test` fails when it drifts.
21
21
  */
22
22
  import { isWslUnc } from "./paths.js";
23
+ /** One directory that must keep the host environment, as a normalized UNC path. */
24
+ function normalizeWorkspace(value) {
25
+ const trimmed = value.trim().replace(/[\\/]+$/, "");
26
+ return trimmed.replace(/\//g, "\\").toLowerCase();
27
+ }
28
+ /**
29
+ * Whether a workspace lies inside one of the directories the operator opened
30
+ * for Windows access (9p) instead of the distro environment.
31
+ *
32
+ * The comparison is prefix-based on whole path segments: `\\wsl.localhost\ubuntu\a`
33
+ * matches the directory itself and everything below it, but not `…\ab`. Paths
34
+ * are Windows/UNC paths, hence case-insensitive.
35
+ *
36
+ * @param cwd - the session's workspace directory.
37
+ * @param windowsAccess - directories opened in Windows access mode.
38
+ * @returns true when this workspace opted out of the distro environment.
39
+ */
40
+ export function isWindowsAccessWorkspace(cwd, windowsAccess) {
41
+ const target = normalizeWorkspace(cwd);
42
+ return windowsAccess.some((entry) => {
43
+ if (entry.trim() === "")
44
+ return false;
45
+ const base = normalizeWorkspace(entry);
46
+ return target === base || target.startsWith(`${base}\\`);
47
+ });
48
+ }
23
49
  /**
24
50
  * The adoption decision.
25
51
  *
26
- * @param input - the new session's workspace, the preset it currently has, and
27
- * the registry default.
52
+ * `windowsAccess` lists directories the operator explicitly opened for Windows
53
+ * access; a session inside one of them keeps the host preset, so the choice
54
+ * survives every later session in that workspace rather than only the one the
55
+ * operator answered the dialog for.
56
+ *
57
+ * @param input - the new session's workspace, the preset it currently has, the
58
+ * registry default, and the directories reserved for Windows access.
28
59
  * @returns true when the WSL preset should be selected for this session.
29
60
  */
30
- export function shouldAdoptWslPreset({ cwd, current, fallback } = {}) {
61
+ export function shouldAdoptWslPreset({ cwd, current, fallback, windowsAccess } = {}) {
31
62
  if (cwd === undefined || !isWslUnc(cwd))
32
63
  return false;
64
+ if (windowsAccess !== undefined && isWindowsAccessWorkspace(cwd, windowsAccess))
65
+ return false;
33
66
  if (current === void 0)
34
67
  return true;
35
68
  return current === fallback;
@@ -0,0 +1,261 @@
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 { type DoctorDigest } from "./wsl-doctor-tool.js";
49
+ export declare const name = "wsl-status";
50
+ /** The one route the panel fetches; it must live under the `/api` channel. */
51
+ export declare const STATUS_PATH = "/api/wsl-env/status";
52
+ export declare const Config: z<Schemastery.ObjectS<NoInfer<{
53
+ /** How long one distro's quick verdict stays fresh, in milliseconds. */
54
+ cacheMs: z<number, number, "defined">;
55
+ /** Deadline for one scoped quick doctor run, in milliseconds. */
56
+ timeoutMs: z<number, number, "defined">;
57
+ /** `wsl.exe` to list the distros; keep in step with the providers' `wslPath`. */
58
+ wslPath: z<string, string, "defined">;
59
+ }>>, Schemastery.ObjectT<NoInfer<{
60
+ /** How long one distro's quick verdict stays fresh, in milliseconds. */
61
+ cacheMs: z<number, number, "defined">;
62
+ /** Deadline for one scoped quick doctor run, in milliseconds. */
63
+ timeoutMs: z<number, number, "defined">;
64
+ /** `wsl.exe` to list the distros; keep in step with the providers' `wslPath`. */
65
+ wslPath: z<string, string, "defined">;
66
+ }>>, "plain">;
67
+ /** The config schema's validated output. */
68
+ export interface StatusConfig {
69
+ /** How long one distro's quick verdict stays fresh, in milliseconds. */
70
+ cacheMs?: number;
71
+ /** Deadline for one scoped quick doctor run, in milliseconds. */
72
+ timeoutMs?: number;
73
+ /** `wsl.exe` to list the distros. */
74
+ wslPath?: string;
75
+ }
76
+ /** The CLI runner seam: argv in, one JSON report out. */
77
+ type DoctorCli = (argv: string[], signal?: AbortSignal, timeoutMs?: number) => Promise<string>;
78
+ /** One warning the report carried: advisory, not blocking. */
79
+ export interface StatusWarning {
80
+ /** The check id. */
81
+ id: string;
82
+ /** What the check saw. */
83
+ detail: string;
84
+ /** The remedy the CLI printed, when it printed one. */
85
+ remedy?: string;
86
+ }
87
+ /** One repair the doctor performed (or attempted), as the panel consumes it. */
88
+ export interface StatusRepair {
89
+ /** The doctor's fix check id: `fix.scopes` or `fix.cache`. */
90
+ id: string;
91
+ /** What was attempted. */
92
+ title: string;
93
+ /** The doctor's status: `ok` when the fresh probe verified it, `warn` otherwise. */
94
+ status: string;
95
+ /** The before → after evidence. */
96
+ detail: string;
97
+ /** What to do when the repair did not take. */
98
+ remedy?: string;
99
+ }
100
+ /** One check row, as the panel's expandable detail renders it. */
101
+ export interface StatusCheck {
102
+ /** The check id. */
103
+ id: string;
104
+ /** The check's display name. */
105
+ title: string;
106
+ /** The doctor's status: `ok`, `warn`, `fail`, `info`, `skipped` or `unknown`. */
107
+ status: string;
108
+ /** What the check saw. */
109
+ detail: string;
110
+ /** The remedy the CLI printed, when it printed one. */
111
+ remedy?: string;
112
+ /** The doctor section the check belongs to, for grouping. */
113
+ section: string;
114
+ }
115
+ /** One distro's verdict, as the panel consumes it. */
116
+ export interface DistroStatusView {
117
+ /** The distro the verdict belongs to. */
118
+ distro: string;
119
+ /** `ready` and `blocked` come from the report; `error` means the run failed. */
120
+ verdict: "ready" | "blocked" | "error";
121
+ /** Whether this answer came from the repair action (a full `--fix-owned` run). */
122
+ repaired: boolean;
123
+ /** The doctor's fix rows: what the repair did and whether it verified. */
124
+ repairs: StatusRepair[];
125
+ /**
126
+ * The findings `--fix-owned` can act on right now: `runtime.scopes` with
127
+ * stale units, `agent.cache` with unusable entries, and `agent.handshake`
128
+ * when the cache explains it. Everything else is manual — its remedy is
129
+ * the next step, and the panel must not offer a repair that cannot apply.
130
+ */
131
+ repairable: string[];
132
+ /** Unix epoch milliseconds of the run. */
133
+ checkedAt: number;
134
+ /** Every failing check with the remedy the CLI printed. */
135
+ failures: Array<{
136
+ id: string;
137
+ detail: string;
138
+ remedy: string;
139
+ }>;
140
+ /** Every warning check, so a ready verdict still shows what to look at. */
141
+ warnings: StatusWarning[];
142
+ /**
143
+ * The result's structure: how many checks landed in each status. Synthetic
144
+ * "not run in this scope" rows and the repair's own `fix.*` rows are
145
+ * excluded, so the numbers describe the environment this distro answered.
146
+ */
147
+ counts: {
148
+ ok: number;
149
+ warn: number;
150
+ fail: number;
151
+ info: number;
152
+ skipped: number;
153
+ unknown: number;
154
+ };
155
+ /** Per-section tallies, in the doctor's section order. */
156
+ sections: DoctorDigest["sections"];
157
+ /**
158
+ * Every check this run executed, with its result — the panel's expandable
159
+ * "details" list. Synthetic "not run in this scope" rows are excluded (the
160
+ * `notRun` count speaks for them), so a row never claims a check it did not
161
+ * run.
162
+ */
163
+ checks: StatusCheck[];
164
+ /**
165
+ * Catalog checks a scoped run never executed. Zero for a full run: its
166
+ * unlisted catalog ids are conditional checks that did not fire, not a
167
+ * coverage gap to advertise.
168
+ */
169
+ notRun: number;
170
+ /** The report's unresolved blocker ids. */
171
+ blockers: string[];
172
+ /** Whether the answer came from the persisted or in-memory cache. */
173
+ cached?: boolean;
174
+ /**
175
+ * Who started the run: an explicit panel action (`user`) or the page-load
176
+ * refresh for an already-running distro (`background`). Persisted with the
177
+ * result so a reload still says where the check came from.
178
+ */
179
+ source: "user" | "background";
180
+ /** Why the run failed, when `verdict` is `error`. */
181
+ error?: string;
182
+ }
183
+ /** The answer to a list request. */
184
+ export interface DistroListReply {
185
+ /** Installed distro names, WSL's own order. */
186
+ distros: string[];
187
+ /** The installed distros that are running now; only these may be refreshed in the background. */
188
+ running: string[];
189
+ /** The last stored verdict per installed distro, complete so a reload keeps its details. */
190
+ cached: DistroStatusView[];
191
+ }
192
+ /** The route handler this module publishes. */
193
+ export type StatusHandler = (request: Request) => Promise<Response>;
194
+ /** One exact route's registration shape. */
195
+ interface ConnectionRoute {
196
+ readonly path: string;
197
+ readonly methods: readonly string[];
198
+ readonly requestBody: "buffered" | "streaming";
199
+ readonly fetch: (request: Request) => Promise<Response>;
200
+ }
201
+ /** The connection slice this row registers into. */
202
+ interface ConnectionFace {
203
+ /** The exact-Fetch route registry. */
204
+ readonly fetch: {
205
+ /** Register one exact route; the returned disposer withdraws it. */
206
+ register: (route: ConnectionRoute) => () => Promise<void> | void;
207
+ };
208
+ }
209
+ /**
210
+ * The context slice this row consumes. `inject`/`effect` are Cordis fiber
211
+ * methods; the optional seams exist so the handler and registration are
212
+ * unit-testable without a boot.
213
+ */
214
+ interface StatusContext {
215
+ /** Optional cordis-style lookup: how production resolves the connection. */
216
+ get?: (name: string) => unknown;
217
+ /** Wait for a service, then run the callback in its scope. */
218
+ inject?: (deps: readonly string[], callback: (scope: StatusContext) => void) => unknown;
219
+ /** Own one disposer on the calling fiber. */
220
+ effect?: (callback: () => () => void, label?: string) => unknown;
221
+ /** The Host connection whose `/api` channel carries the route. */
222
+ connection?: ConnectionFace;
223
+ }
224
+ /** The handler options a test builds directly. */
225
+ export interface StatusHandlerOptions {
226
+ /** How long a verdict stays fresh. */
227
+ cacheMs: number;
228
+ /** Deadline for one run. */
229
+ timeoutMs: number;
230
+ /** Installed distro names, WSL's order. */
231
+ distros: () => Promise<string[]>;
232
+ /** The CLI runner. */
233
+ runCli: DoctorCli;
234
+ /** Clock seam. */
235
+ now?: () => number;
236
+ /** Where the last results persist; `""` disables persistence. */
237
+ statePath?: string;
238
+ /** Running distro names, for the panel's background refresh. */
239
+ running?: () => Promise<string[]>;
240
+ }
241
+ /**
242
+ * Build the route handler.
243
+ *
244
+ * One handler owns one cache, so the row registers exactly one instance and an
245
+ * unload drops every verdict with it.
246
+ *
247
+ * @param options - the distro, runner, and cache seams.
248
+ * @returns the request handler.
249
+ */
250
+ export declare function createStatusHandler(options: StatusHandlerOptions): StatusHandler;
251
+ /**
252
+ * Mount the row: register the route once the Host connection is available.
253
+ *
254
+ * A composition without `connection` (headless, ACP) leaves the row inert —
255
+ * the same posture the other surface rows take.
256
+ *
257
+ * @param ctx - the cordis context.
258
+ * @param config - the schema-validated config.
259
+ */
260
+ export declare function apply(ctx: StatusContext, config?: StatusConfig): void;
261
+ export {};