dsh-plugin-wsl-env 0.23.1 → 0.25.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. package/CHANGELOG.md +212 -0
  2. package/README.md +9 -5
  3. package/SECURITY.md +10 -0
  4. package/client.js +974 -165
  5. package/cordis.patch.yml +28 -3
  6. package/docs/API.md +2 -1
  7. package/docs/ARCHITECTURE.md +36 -13
  8. package/docs/COMPATIBILITY.md +5 -0
  9. package/docs/CONFIGURATION.md +80 -9
  10. package/docs/CONFIGURATION.zh.md +64 -8
  11. package/docs/DIAGNOSTICS.md +48 -20
  12. package/docs/DIAGNOSTICS.zh.md +36 -14
  13. package/docs/LIMITATIONS.md +36 -9
  14. package/docs/LIMITATIONS.zh.md +26 -7
  15. package/docs/MIGRATION.md +1 -1
  16. package/docs/PEER-PARITY.md +4 -4
  17. package/docs/QUICKSTART.md +42 -12
  18. package/docs/QUICKSTART.zh.md +29 -8
  19. package/docs/README.zh.md +9 -5
  20. package/docs/RELEASING.md +17 -13
  21. package/docs/REQUIREMENTS.zh.md +5 -4
  22. package/docs/UPSTREAM-FSIO-EXPORT.md +5 -4
  23. package/docs/UPSTREAM-PROMPT-ADAPTERS.md +85 -0
  24. package/docs/root-fs-routing.md +1 -1
  25. package/lib/agent-confined.d.ts +7 -1
  26. package/lib/agent-confined.js +3 -3
  27. package/lib/auto-preset.d.ts +27 -0
  28. package/lib/auto-preset.js +40 -3
  29. package/lib/bwrap.d.ts +14 -0
  30. package/lib/bwrap.js +11 -0
  31. package/lib/client-host.d.ts +2 -2
  32. package/lib/client-host.js +2 -2
  33. package/lib/cwd-prompt.d.ts +41 -3
  34. package/lib/cwd-prompt.js +125 -8
  35. package/lib/doctor-report.d.ts +50 -0
  36. package/lib/doctor-report.js +172 -0
  37. package/lib/fs-routing.d.ts +1 -1
  38. package/lib/fs-routing.js +1 -1
  39. package/lib/fs.d.ts +1 -1
  40. package/lib/fs.js +1 -1
  41. package/lib/index.d.ts +6 -1464
  42. package/lib/index.js +5 -2120
  43. package/lib/listing.d.ts +21 -9
  44. package/lib/listing.js +25 -21
  45. package/lib/messages.d.ts +1 -1
  46. package/lib/messages.js +3 -3
  47. package/lib/picker.d.ts +50 -16
  48. package/lib/picker.js +103 -23
  49. package/lib/preflight.d.ts +7 -4
  50. package/lib/preflight.js +27 -13
  51. package/lib/preset-choice.d.ts +22 -3
  52. package/lib/preset-choice.js +36 -3
  53. package/lib/provider-common.d.ts +58 -0
  54. package/lib/provider-common.js +123 -0
  55. package/lib/sandbox-core.d.ts +1 -0
  56. package/lib/sandbox-core.js +4 -2
  57. package/lib/session-runtime.d.ts +7 -1
  58. package/lib/session-runtime.js +9 -2
  59. package/lib/shell.d.ts +1 -1
  60. package/lib/shell.js +1 -1
  61. package/lib/status.d.ts +261 -0
  62. package/lib/status.js +425 -0
  63. package/lib/writable-roots.d.ts +109 -0
  64. package/lib/writable-roots.js +257 -0
  65. package/lib/wsl-doctor-tool.d.ts +8 -0
  66. package/lib/wsl-doctor-tool.js +18 -20
  67. package/lib/wsl-filesystem.d.ts +692 -0
  68. package/lib/wsl-filesystem.js +897 -0
  69. package/lib/wsl-shell.d.ts +742 -0
  70. package/lib/wsl-shell.js +965 -0
  71. package/lib/wsl.d.ts +13 -1
  72. package/lib/wsl.js +16 -1
  73. package/locale/doctor/en.json +3 -2
  74. package/locale/doctor/zh.json +3 -2
  75. package/package.json +12 -4
  76. package/scripts/doctor.mjs +436 -226
  77. package/scripts/profile-preset.mjs +17 -5
@@ -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,58 @@
1
+ import type { SandboxExecutionPolicy } from "@deepseek-ai/dsh-sandbox";
2
+ interface DistroHomeOwner {
3
+ config: unknown;
4
+ resolvedDistro: string;
5
+ resolvedHome: string | undefined;
6
+ resolvedHomes: Map<string, string>;
7
+ }
8
+ /**
9
+ * The configured default workdir, or an empty string when the operator left it
10
+ * unset. `cwd` is a volatile field on both providers, so it is read through
11
+ * `.get()`, and it may be absent entirely.
12
+ */
13
+ export declare function configuredCwd(config: {
14
+ cwd?: {
15
+ get(): string | undefined;
16
+ };
17
+ }): string;
18
+ /**
19
+ * The distro user's home as a Linux path, cached on the provider instance whose
20
+ * `distro`/`wslPath` config it belongs to.
21
+ */
22
+ export declare function distroHome(owner: DistroHomeOwner, distro: string): Promise<string>;
23
+ /**
24
+ * Translate workspace-write grants into the vocabulary used by the target
25
+ * filesystem. WSL workspaces receive distro-local temporary and extra roots;
26
+ * Windows workspaces retain the upstream grant.
27
+ */
28
+ export declare function wslWritableRoots(policy: SandboxExecutionPolicy, distro: string, linuxExtraRoots: readonly string[]): string[];
29
+ /**
30
+ * Resolve configured and policy-provided roots for one distro, then verify
31
+ * their physical directories before they are bound into a confinement profile.
32
+ */
33
+ export declare function effectiveWritableRoots(input: {
34
+ configured?: readonly string[] | undefined;
35
+ policy?: SandboxExecutionPolicy | undefined;
36
+ distro: string;
37
+ home: string;
38
+ wslPath: string;
39
+ signal?: AbortSignal | undefined;
40
+ run?: ((argv: string[]) => Promise<string>) | undefined;
41
+ check?: boolean;
42
+ }): Promise<string[]>;
43
+ /** Whether confined profiles shadow `/mnt`, with the explicit stance winning. */
44
+ export declare function effectiveMaskWindowsDrive(config: {
45
+ interopVisibility?: "visible" | "masked" | "disabled";
46
+ maskWindowsDrive?: boolean;
47
+ }): boolean;
48
+ /** Resolve the distro for an operation from its configuration and candidates. */
49
+ export declare function resolveOperationDistro(configured: string, candidates: ReadonlyArray<string | undefined>, probeDefault: () => Promise<string>): Promise<string>;
50
+ /**
51
+ * Choose the session runtime policy for one distro, retrying an automatic
52
+ * failed probe after its short cache expires.
53
+ */
54
+ export declare function sessionRuntimeWanted(value: boolean | "auto", distro: string, ensure: () => Promise<void>, cache: Map<string, {
55
+ usable: boolean;
56
+ checkedAt: number;
57
+ }>): Promise<boolean>;
58
+ export {};
@@ -0,0 +1,123 @@
1
+ import { canonicalPath, SandboxInvalidRootError, writableRoots } from "@deepseek-ai/dsh-sandbox";
2
+ import { isWslUnc, posixToUnc, toLinuxPath } from "./paths.js";
3
+ import { distroOfUnc, isDefaultDistro, pinnedDistro } from "./distro-route.js";
4
+ import { linuxHomePath } from "./wsl.js";
5
+ import { WritableRootError, ensureWritableRoots, resolveWritableRoots } from "./writable-roots.js";
6
+ const AUTO_SCOPE_RECHECK_MS = 60_000;
7
+ /**
8
+ * The configured default workdir, or an empty string when the operator left it
9
+ * unset. `cwd` is a volatile field on both providers, so it is read through
10
+ * `.get()`, and it may be absent entirely.
11
+ */
12
+ export function configuredCwd(config) {
13
+ return String(config.cwd?.get?.() ?? "").trim();
14
+ }
15
+ /**
16
+ * The distro user's home as a Linux path, cached on the provider instance whose
17
+ * `distro`/`wslPath` config it belongs to.
18
+ */
19
+ export async function distroHome(owner, distro) {
20
+ const cached = owner.resolvedHomes.get(distro);
21
+ if (cached !== undefined)
22
+ return cached;
23
+ if (owner.resolvedHome !== undefined && owner.resolvedDistro.length > 0 && distro === owner.resolvedDistro) {
24
+ owner.resolvedHomes.set(distro, owner.resolvedHome);
25
+ return owner.resolvedHome;
26
+ }
27
+ const config = owner.config;
28
+ const home = await linuxHomePath(distro, { wslPath: config.wslPath });
29
+ owner.resolvedHomes.set(distro, home);
30
+ if (owner.resolvedDistro.length > 0 && distro === owner.resolvedDistro)
31
+ owner.resolvedHome = home;
32
+ return home;
33
+ }
34
+ /**
35
+ * Translate workspace-write grants into the vocabulary used by the target
36
+ * filesystem. WSL workspaces receive distro-local temporary and extra roots;
37
+ * Windows workspaces retain the upstream grant.
38
+ */
39
+ export function wslWritableRoots(policy, distro, linuxExtraRoots) {
40
+ if (policy.mode !== "workspace-write")
41
+ return [];
42
+ const roots = new Set([canonicalPath(policy.workspaceRoot)]);
43
+ if (isWslUnc(policy.workspaceRoot)) {
44
+ roots.add(canonicalPath(posixToUnc(distro, "/tmp")));
45
+ for (const root of linuxExtraRoots)
46
+ roots.add(canonicalPath(posixToUnc(distro, root)));
47
+ }
48
+ else {
49
+ for (const root of writableRoots(policy))
50
+ roots.add(root);
51
+ }
52
+ return [...roots];
53
+ }
54
+ /**
55
+ * Resolve configured and policy-provided roots for one distro, then verify
56
+ * their physical directories before they are bound into a confinement profile.
57
+ */
58
+ export async function effectiveWritableRoots(input) {
59
+ try {
60
+ const roots = resolveWritableRoots({
61
+ configured: input.configured,
62
+ policy: input.policy?.additionalWritableRoots,
63
+ home: input.home,
64
+ distro: input.distro,
65
+ workspaceRoot: toLinuxPath(input.policy?.workspaceRoot ?? input.home),
66
+ });
67
+ if (input.check !== false) {
68
+ await ensureWritableRoots({ wslPath: input.wslPath, distro: input.distro, roots, signal: input.signal, ...(input.run === undefined ? {} : { run: input.run }) });
69
+ }
70
+ return roots;
71
+ }
72
+ catch (error) {
73
+ if (error instanceof WritableRootError)
74
+ throw new SandboxInvalidRootError(error.root, error.reason);
75
+ throw error;
76
+ }
77
+ }
78
+ /** Whether confined profiles shadow `/mnt`, with the explicit stance winning. */
79
+ export function effectiveMaskWindowsDrive(config) {
80
+ if (config.interopVisibility !== undefined)
81
+ return config.interopVisibility !== "visible";
82
+ return config.maskWindowsDrive === true;
83
+ }
84
+ /** Resolve the distro for an operation from its configuration and candidates. */
85
+ export async function resolveOperationDistro(configured, candidates, probeDefault) {
86
+ const pinned = pinnedDistro(configured);
87
+ if (pinned !== undefined)
88
+ return pinned;
89
+ if (!isDefaultDistro(configured)) {
90
+ for (const candidate of candidates) {
91
+ const named = distroOfUnc(candidate);
92
+ if (named !== undefined)
93
+ return named;
94
+ }
95
+ }
96
+ return probeDefault();
97
+ }
98
+ /**
99
+ * Choose the session runtime policy for one distro, retrying an automatic
100
+ * failed probe after its short cache expires.
101
+ */
102
+ export async function sessionRuntimeWanted(value, distro, ensure, cache) {
103
+ if (value === false)
104
+ return false;
105
+ if (value === true) {
106
+ await ensure();
107
+ return true;
108
+ }
109
+ const cached = cache.get(distro);
110
+ if (cached?.usable === true)
111
+ return true;
112
+ if (cached !== undefined && Date.now() - cached.checkedAt < AUTO_SCOPE_RECHECK_MS)
113
+ return false;
114
+ try {
115
+ await ensure();
116
+ cache.set(distro, { usable: true, checkedAt: Date.now() });
117
+ return true;
118
+ }
119
+ catch {
120
+ cache.set(distro, { usable: false, checkedAt: Date.now() });
121
+ return false;
122
+ }
123
+ }
@@ -118,6 +118,7 @@ export interface WslSandboxCoreInstance {
118
118
  }, options: {
119
119
  distro: string;
120
120
  signal?: AbortSignal | undefined;
121
+ writableRoots?: readonly string[] | undefined;
121
122
  }) => Promise<WslConfined>;
122
123
  }
123
124
  /**
@@ -277,7 +277,9 @@ export function createSandboxCore({ SandboxUnavailableError }) {
277
277
  * @param argv - the argv to run INSIDE the distro (shell, its flags, command).
278
278
  * @param policy - the resolved confined policy (`mode` is never
279
279
  * `danger-full-access`; the caller does not confine that case at all).
280
- * @param options - the distro to run in and optional cancellation.
280
+ * @param options - the distro to run in, optional cancellation, and the
281
+ * resolved extra writable roots (already Linux paths, filtered and
282
+ * physically checked by the provider).
281
283
  * @returns the wrapped argv plus the settlement-classification facts, in the
282
284
  * seam's `ConfinedArgv` shape.
283
285
  * @throws SandboxUnavailableError when the distro has no usable `bwrap`, so a
@@ -289,7 +291,7 @@ export function createSandboxCore({ SandboxUnavailableError }) {
289
291
  throw new SandboxUnavailableError(policy.mode, bwrapFailure(this.wslPath, distro) ?? missingBwrapRemedy(distro));
290
292
  }
291
293
  const workspaceRoot = toLinuxPath(policy.workspaceRoot);
292
- const prefix = bwrapArgvPrefix({ ...policy, workspaceRoot }, { maskWindowsDrive: this.maskWindowsDrive });
294
+ const prefix = bwrapArgvPrefix({ ...policy, workspaceRoot }, { maskWindowsDrive: this.maskWindowsDrive, writableRoots: options.writableRoots });
293
295
  return {
294
296
  argv: [...prefix, ...argv],
295
297
  enforcement: ENFORCEMENT,
@@ -55,6 +55,12 @@ interface SessionRuntimeRequest {
55
55
  mode: string;
56
56
  /** Shadow `/mnt` in the runtime's mount profile. */
57
57
  maskWindowsDrive?: boolean;
58
+ /**
59
+ * Extra Linux roots to bind read-write in the runtime's profile. The
60
+ * providers resolved, filtered and checked them; they are part of the key
61
+ * because the mount table is fixed for the runtime's lifetime.
62
+ */
63
+ writableRoots?: readonly string[];
58
64
  /** The agent's client lease; 0 disables. */
59
65
  leaseMs?: number;
60
66
  }
@@ -134,7 +140,7 @@ export declare class SessionRuntimes {
134
140
  * @param request - the runtime request.
135
141
  * @returns the registry key.
136
142
  */
137
- static key(request: Pick<SessionRuntimeRequest, "distro" | "workspaceRoot" | "mode" | "maskWindowsDrive" | "sessionId">): string;
143
+ static key(request: Pick<SessionRuntimeRequest, "distro" | "workspaceRoot" | "mode" | "maskWindowsDrive" | "sessionId" | "writableRoots">): string;
138
144
  /**
139
145
  * Acquire the runtime for one key, creating it on first use.
140
146
  *
@@ -146,7 +146,14 @@ export class SessionRuntimes {
146
146
  * @returns the registry key.
147
147
  */
148
148
  static key(request) {
149
- return [request.sessionId ?? "", request.distro, request.workspaceRoot, request.mode, request.maskWindowsDrive === true ? "masked" : "visible"].join("\u0000");
149
+ return [
150
+ request.sessionId ?? "",
151
+ request.distro,
152
+ request.workspaceRoot,
153
+ request.mode,
154
+ request.maskWindowsDrive === true ? "masked" : "visible",
155
+ (request.writableRoots ?? []).join("\u0000"),
156
+ ].join("\u0000");
150
157
  }
151
158
  /**
152
159
  * Acquire the runtime for one key, creating it on first use.
@@ -165,7 +172,7 @@ export class SessionRuntimes {
165
172
  const unit = sessionScopeUnit(request.distro, this.token());
166
173
  const prefix = sessionScopePrefix(unit);
167
174
  if (request.mode !== "danger-full-access") {
168
- prefix.push(...bwrapArgvPrefix({ mode: request.mode, workspaceRoot: toLinuxPath(request.workspaceRoot) }, { maskWindowsDrive: request.maskWindowsDrive, realTmp: true, pidNamespace: false }));
175
+ prefix.push(...bwrapArgvPrefix({ mode: request.mode, workspaceRoot: toLinuxPath(request.workspaceRoot) }, { maskWindowsDrive: request.maskWindowsDrive, realTmp: true, pidNamespace: false, writableRoots: request.writableRoots }));
169
176
  }
170
177
  const agent = this.spawnAgent({
171
178
  distro: request.distro,
package/lib/shell.d.ts CHANGED
@@ -9,4 +9,4 @@
9
9
  *
10
10
  * @module dsh-plugin-wsl-env/shell
11
11
  */
12
- export { WslShellExecutor as default, WslShellExecutor } from "./index.js";
12
+ export { WslShellExecutor as default, WslShellExecutor } from "./wsl-shell.js";
package/lib/shell.js CHANGED
@@ -9,4 +9,4 @@
9
9
  *
10
10
  * @module dsh-plugin-wsl-env/shell
11
11
  */
12
- export { WslShellExecutor as default, WslShellExecutor } from "./index.js";
12
+ export { WslShellExecutor as default, WslShellExecutor } from "./wsl-shell.js";
@@ -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 {};