dsh-plugin-wsl-env 0.26.2 → 0.26.3-rc.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.
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Deferred registration for the plugin's same-name root-plane takeovers.
3
+ *
4
+ * The bundle patch disables the shipped `subprocess`/`fs`/`directoryPicker`
5
+ * rows and inserts this plugin's providers under the same service names. On a
6
+ * cold boot the shipped rows never start, so the provider registers freely.
7
+ * On a LIVE recomposition the outgoing provision can still be registered while
8
+ * the replacement mounts — the HMR plugin-update path (`updateBundle` removes
9
+ * the old bundle layer, the shipped rows re-activate, then the incoming layer
10
+ * disables them again) or a busy-profile enable while live sessions hold the
11
+ * service. Cordis refuses the duplicate registration, the row enters FAILED,
12
+ * and the plugin manager reports the update as failed and rolls back (issue
13
+ * #39, upstream deepseek-harness#12510).
14
+ *
15
+ * A row that mounts through this helper stays ACTIVE either way: when the name
16
+ * is free it registers immediately (the cold path, unchanged), and when a
17
+ * provision is still registered it waits for `internal/service` to report the
18
+ * slot released, then registers. The recomposition therefore succeeds, the
19
+ * outgoing provider keeps serving until its dependents release, and the
20
+ * takeover lands as soon as it does — or at the next restart, if a dependent
21
+ * never releases (the in-app doctor's `providers.takeover` row names the
22
+ * provider still in place).
23
+ *
24
+ * Guards:
25
+ * - `ctx.reflect.get(name, false)` reads the store including an UNLOADING
26
+ * implementation, so a slot that is about to free still reads as occupied.
27
+ * - The handler never registers from a fiber that is itself unloading: the
28
+ * release it observes can be its own disposal, and a provision registered
29
+ * then would be owned by a dying fiber.
30
+ *
31
+ * This is a TypeScript source built to `lib/service-takeover.js`; edit THIS
32
+ * file and run `pnpm run build`.
33
+ *
34
+ * @module dsh-plugin-wsl-env/service-takeover
35
+ */
36
+ /**
37
+ * Register a same-name takeover provider now, or after the outgoing provision
38
+ * releases.
39
+ *
40
+ * @param ctx - the row's context; the provision is owned by its fiber.
41
+ * @param service - the service name the provider registers.
42
+ * @param mount - constructs the provider on `ctx` (its constructor performs
43
+ * the registration and owns the cleanup).
44
+ */
45
+ export function mountTakeover(ctx, service, mount) {
46
+ /** Whether the service store still holds an implementation, unloading included. */
47
+ const occupied = () => ctx.reflect.get(service, false) !== undefined;
48
+ if (!occupied()) {
49
+ mount();
50
+ return;
51
+ }
52
+ ctx.logger?.warn?.(`dsh-plugin-wsl-env: "${service}" is still registered by an outgoing provider; the WSL provider will take over when it releases — restart DSH to apply it immediately`);
53
+ ctx.on("internal/service", (name, value) => {
54
+ if (name !== service || value !== undefined)
55
+ return;
56
+ if (occupied())
57
+ return;
58
+ // The observed release may be this fiber's own disposal; never register
59
+ // from a fiber that is unloading.
60
+ if (ctx.fiber.state !== 2 /* FiberState.ACTIVE */)
61
+ return;
62
+ ctx.logger?.debug?.(`dsh-plugin-wsl-env: "${service}" was released; the WSL provider takes over now`);
63
+ mount();
64
+ });
65
+ }
package/lib/status.d.ts CHANGED
@@ -46,6 +46,7 @@
46
46
  */
47
47
  import z from "@deepseek-ai/schemastery";
48
48
  import { type DoctorDigest } from "./wsl-doctor-tool.js";
49
+ import { type TakeoverSnapshot } from "./takeover-report.js";
49
50
  export declare const name = "wsl-status";
50
51
  /** The one route the panel fetches; it must live under the `/api` channel. */
51
52
  export declare const STATUS_PATH = "/api/wsl-env/status";
@@ -237,6 +238,12 @@ export interface StatusHandlerOptions {
237
238
  statePath?: string;
238
239
  /** Running distro names, for the panel's background refresh. */
239
240
  running?: () => Promise<string[]>;
241
+ /**
242
+ * The effective takeover providers this process sees; the panel adds them
243
+ * as the `providers.takeover` check. Absent keeps the panel's historical
244
+ * shape (the route tests and the standalone CLI path).
245
+ */
246
+ providers?: () => readonly TakeoverSnapshot[];
240
247
  }
241
248
  /**
242
249
  * Build the route handler.
package/lib/status.js CHANGED
@@ -52,6 +52,7 @@ import { listDistros, listRunningDistros } from "./wsl.js";
52
52
  import { digestReport, sectionOf } from "./wsl-doctor-tool.js";
53
53
  import { runDoctorCli } from "./wsl-doctor-command.js";
54
54
  import { mergeAutoPresetSeam } from "./doctor-live.js";
55
+ import { mergeTakeoverReport, takeoverSnapshot } from "./takeover-report.js";
55
56
  export const name = "wsl-status";
56
57
  /** The one route the panel fetches; it must live under the `/api` channel. */
57
58
  export const STATUS_PATH = "/api/wsl-env/status";
@@ -303,7 +304,8 @@ export function createStatusHandler(options) {
303
304
  : ["--json", "--quick", "--distro", distro];
304
305
  const raw = await options.runCli(argv, undefined, options.timeoutMs);
305
306
  const report = JSON.parse(raw);
306
- view = viewOf(digestReport(mergeAutoPresetSeam(report), distro), distro, at, repair, source);
307
+ const live = mergeTakeoverReport(mergeAutoPresetSeam(report), options.providers?.() ?? []);
308
+ view = viewOf(digestReport(live, distro), distro, at, repair, source);
307
309
  }
308
310
  catch (error) {
309
311
  view = {
@@ -388,7 +390,7 @@ export function createStatusHandler(options) {
388
390
  * @param config - the schema-validated config.
389
391
  * @returns handler options.
390
392
  */
391
- function optionsFor(config) {
393
+ function optionsFor(config, providers) {
392
394
  const wslPath = config.wslPath ?? "wsl.exe";
393
395
  return {
394
396
  cacheMs: config.cacheMs ?? 15_000,
@@ -396,6 +398,7 @@ function optionsFor(config) {
396
398
  distros: () => listDistros({ wslPath }),
397
399
  running: () => listRunningDistros({ wslPath }),
398
400
  runCli: runDoctorCli,
401
+ ...(providers === undefined ? {} : { providers }),
399
402
  };
400
403
  }
401
404
  /**
@@ -414,7 +417,7 @@ export function apply(ctx, config = {}) {
414
417
  const connection = scope.connection ?? scope.get?.("connection");
415
418
  if (connection === undefined)
416
419
  return;
417
- const handler = createStatusHandler(optionsFor(config));
420
+ const handler = createStatusHandler(optionsFor(config, () => takeoverSnapshot(ctx)));
418
421
  const dispose = connection.fetch.register({
419
422
  path: STATUS_PATH,
420
423
  methods: ["GET", "POST"],
@@ -336,4 +336,111 @@ export declare class WslSubprocessRuntime extends LocalSubprocessRuntime {
336
336
  */
337
337
  launchesDistro(argv?: readonly string[]): boolean;
338
338
  }
339
- export default WslSubprocessRuntime;
339
+ /**
340
+ * The row the loader mounts: registers {@link WslSubprocessRuntime} under the
341
+ * `subprocess` name now, or after an outgoing provision releases.
342
+ *
343
+ * The deferral is what keeps a live enable/update from failing with cordis's
344
+ * duplicate-service error and the plugin manager from rolling the update back;
345
+ * {@link mountTakeover} carries the reasoning. A cold boot takes the immediate
346
+ * branch, so the installed behaviour is unchanged.
347
+ */
348
+ export default class WslSubprocessRow {
349
+ static Config: z<Schemastery.ObjectS<NoInfer<{
350
+ /**
351
+ * Distro mode: empty/`"auto"` follows the launch directory, `"default"`
352
+ * forces WSL's default, and an explicit name pins.
353
+ */
354
+ distro: z<string, string, "defined">;
355
+ /** Path to `wsl.exe`; overridable for a non-standard install. */
356
+ wslPath: z<string, string, "defined">;
357
+ /**
358
+ * A shell to pin inside the distro, as an absolute Linux path. Empty — the
359
+ * default — leaves the choice to `wsl.exe`, which starts the distro user's
360
+ * login shell exactly as an interactive `wsl.exe` does.
361
+ */
362
+ shell: z<string, string, "defined">;
363
+ /**
364
+ * Login-shell semantics for a pinned shell. Ignored when no shell is pinned,
365
+ * because then the login shell is the shell.
366
+ */
367
+ loginShell: z<boolean, boolean, "defined">;
368
+ /** Fallback directory when a launch names none; accepts any coordinate system. */
369
+ cwd: z<string, string, "defined">;
370
+ /** Windows directory the `wsl.exe` process itself starts in. */
371
+ hostCwd: z<string, string, "volatile">;
372
+ /** Extra env names to forward into the distro through WSLENV. */
373
+ forwardEnv: z<string[], string[], "defined">;
374
+ /**
375
+ * Give a session opened on a WINDOWS folder a host shell instead of the
376
+ * distro's shell started at `/mnt/<drive>/…`. WSL-folder sessions always
377
+ * get the distro shell — that is this provider's purpose. `false` restores
378
+ * the composition-owned terminal for every session.
379
+ */
380
+ hostSessions: z<boolean, boolean, "defined">;
381
+ /**
382
+ * Let the controller reclaim an idle distro terminal. The terminal is
383
+ * marked at launch (`DSH_TERMINAL_ID` through the existing `WSLENV`
384
+ * forwarding) and its handle's `inspectActivity` is replaced with a
385
+ * distro-side observation: the resident agent scans `/proc` for the
386
+ * marker — a shell with live children is busy, a shell without children
387
+ * is idle. The shipped observation can only answer `unknown` for a distro
388
+ * terminal, and `unknown` never accumulates idle, which is why these
389
+ * terminals had to be closed by hand. When the agent is out the
390
+ * observation answers `unknown` (no reclaim) — a probe that cannot answer
391
+ * must not authorize a close. `false` restores that posture.
392
+ */
393
+ terminalIdleReclaim: z<boolean, boolean, "defined">;
394
+ }>>, Schemastery.ObjectT<NoInfer<{
395
+ /**
396
+ * Distro mode: empty/`"auto"` follows the launch directory, `"default"`
397
+ * forces WSL's default, and an explicit name pins.
398
+ */
399
+ distro: z<string, string, "defined">;
400
+ /** Path to `wsl.exe`; overridable for a non-standard install. */
401
+ wslPath: z<string, string, "defined">;
402
+ /**
403
+ * A shell to pin inside the distro, as an absolute Linux path. Empty — the
404
+ * default — leaves the choice to `wsl.exe`, which starts the distro user's
405
+ * login shell exactly as an interactive `wsl.exe` does.
406
+ */
407
+ shell: z<string, string, "defined">;
408
+ /**
409
+ * Login-shell semantics for a pinned shell. Ignored when no shell is pinned,
410
+ * because then the login shell is the shell.
411
+ */
412
+ loginShell: z<boolean, boolean, "defined">;
413
+ /** Fallback directory when a launch names none; accepts any coordinate system. */
414
+ cwd: z<string, string, "defined">;
415
+ /** Windows directory the `wsl.exe` process itself starts in. */
416
+ hostCwd: z<string, string, "volatile">;
417
+ /** Extra env names to forward into the distro through WSLENV. */
418
+ forwardEnv: z<string[], string[], "defined">;
419
+ /**
420
+ * Give a session opened on a WINDOWS folder a host shell instead of the
421
+ * distro's shell started at `/mnt/<drive>/…`. WSL-folder sessions always
422
+ * get the distro shell — that is this provider's purpose. `false` restores
423
+ * the composition-owned terminal for every session.
424
+ */
425
+ hostSessions: z<boolean, boolean, "defined">;
426
+ /**
427
+ * Let the controller reclaim an idle distro terminal. The terminal is
428
+ * marked at launch (`DSH_TERMINAL_ID` through the existing `WSLENV`
429
+ * forwarding) and its handle's `inspectActivity` is replaced with a
430
+ * distro-side observation: the resident agent scans `/proc` for the
431
+ * marker — a shell with live children is busy, a shell without children
432
+ * is idle. The shipped observation can only answer `unknown` for a distro
433
+ * terminal, and `unknown` never accumulates idle, which is why these
434
+ * terminals had to be closed by hand. When the agent is out the
435
+ * observation answers `unknown` (no reclaim) — a probe that cannot answer
436
+ * must not authorize a close. `false` restores that posture.
437
+ */
438
+ terminalIdleReclaim: z<boolean, boolean, "defined">;
439
+ }>>, "plain">;
440
+ /**
441
+ * @param ctx - the row's context; it owns the provider's provision.
442
+ * @param config - the schema-validated row config.
443
+ */
444
+ constructor(ctx: Context, config: WslSubprocessConfig);
445
+ }
446
+ export {};
package/lib/subprocess.js CHANGED
@@ -97,6 +97,7 @@ import { parseTerminalActivity, TERMINAL_ID_ENV, terminalActivityProbe, wrapTerm
97
97
  import { AgentUnavailableError } from "./agent-errors.js";
98
98
  import { terminalRoute } from "./terminal-route.js";
99
99
  import { pinnedDistro, isDefaultDistro } from "./distro-route.js";
100
+ import { mountTakeover } from "./service-takeover.js";
100
101
  /**
101
102
  * Env names a terminal launch keeps for the distro. `TERM` rides along because
102
103
  * the PTY consumer sets it for the host process, and WSL imports no name that
@@ -469,4 +470,22 @@ export class WslSubprocessRuntime extends LocalSubprocessRuntime {
469
470
  return base.toLowerCase().replace(/\.exe$/u, "") === WSL_PROGRAM;
470
471
  }
471
472
  }
472
- export default WslSubprocessRuntime;
473
+ /**
474
+ * The row the loader mounts: registers {@link WslSubprocessRuntime} under the
475
+ * `subprocess` name now, or after an outgoing provision releases.
476
+ *
477
+ * The deferral is what keeps a live enable/update from failing with cordis's
478
+ * duplicate-service error and the plugin manager from rolling the update back;
479
+ * {@link mountTakeover} carries the reasoning. A cold boot takes the immediate
480
+ * branch, so the installed behaviour is unchanged.
481
+ */
482
+ export default class WslSubprocessRow {
483
+ static Config = WslSubprocessRuntime.Config;
484
+ /**
485
+ * @param ctx - the row's context; it owns the provider's provision.
486
+ * @param config - the schema-validated row config.
487
+ */
488
+ constructor(ctx, config) {
489
+ mountTakeover(ctx, "subprocess", () => { new WslSubprocessRuntime(ctx, config); });
490
+ }
491
+ }
@@ -0,0 +1,80 @@
1
+ /**
2
+ * The in-app doctor's effective-provider check for the three root-plane
3
+ * takeovers.
4
+ *
5
+ * The plugin replaces `subprocess`, `fs` and `directoryPicker` by disabling
6
+ * the shipped rows and mounting same-name providers. That swap can fail at
7
+ * runtime — most visibly on a HMR plugin upgrade, where the outgoing bundle
8
+ * layer re-activates the shipped rows before the incoming layer disables them
9
+ * again (see docs/UPSTREAM-SERVICE-SWAP.md). The failed rows leave no log line
10
+ * a user reads, and the doctor's standalone CLI cannot see live services at
11
+ * all, so the in-app surfaces inspect the context instead and report which
12
+ * provider is serving each name.
13
+ *
14
+ * `missing` for one name only is possible in a composition that intentionally
15
+ * disables the row; the check stays silent when NONE of the three is served,
16
+ * which is the shape of every context that cannot see the composition root
17
+ * (the test seam, a preset realm, the standalone CLI).
18
+ *
19
+ * This is a TypeScript source built to `lib/takeover-report.js`; edit THIS
20
+ * file and run `pnpm run build` — the artifact under `lib/` is generated.
21
+ *
22
+ * @module dsh-plugin-wsl-env/takeover-report
23
+ */
24
+ /** The service names this plugin replaces with its own providers. */
25
+ export declare const TAKEOVER_SERVICES: readonly ["subprocess", "fs", "directoryPicker"];
26
+ /** One replaced service name. */
27
+ export type TakeoverService = (typeof TAKEOVER_SERVICES)[number];
28
+ /** Which provider currently serves one takeover name. */
29
+ export interface TakeoverSnapshot {
30
+ /** The service name. */
31
+ readonly service: TakeoverService;
32
+ /** `plugin` — this plugin's class; `other` — a different provider; `missing` — none. */
33
+ readonly state: "plugin" | "other" | "missing";
34
+ /** The other provider's constructor name, when it has one. */
35
+ readonly provider?: string;
36
+ }
37
+ /** The context face the snapshot needs: an optional service lookup. */
38
+ export interface TakeoverContext {
39
+ /** Read a service; absent means the caller cannot observe one. */
40
+ get?: (name: string) => unknown;
41
+ }
42
+ /** The report fields {@link mergeTakeoverReport} reads and rewrites. */
43
+ export interface TakeoverMergeReport {
44
+ /** The report's check rows. */
45
+ checks?: Array<{
46
+ id: string;
47
+ status: string;
48
+ title?: string;
49
+ detail?: string;
50
+ remedy?: string;
51
+ distro?: string;
52
+ blocksFirstCommand?: boolean;
53
+ }>;
54
+ /** The per-status tally. */
55
+ summary?: Record<string, number>;
56
+ }
57
+ /**
58
+ * Read which provider serves each takeover name in this context.
59
+ *
60
+ * A context that cannot look services up (a test seam, the standalone CLI
61
+ * report) yields an empty snapshot, and the merge then adds no row.
62
+ *
63
+ * @param ctx - the context to inspect.
64
+ * @returns one entry per takeover name, in {@link TAKEOVER_SERVICES} order.
65
+ */
66
+ export declare function takeoverSnapshot(ctx: TakeoverContext): TakeoverSnapshot[];
67
+ /**
68
+ * Fold the effective-provider snapshot into a doctor report as one check.
69
+ *
70
+ * A context that cannot see any of the three services adds no row: it has no
71
+ * evidence about the takeovers, and inventing a finding would be noise in
72
+ * every preset realm and every unit test. When at least one service is
73
+ * served, the row names all three so a single `warn` says exactly which half
74
+ * of the swap landed.
75
+ *
76
+ * @param report - the doctor report (not mutated).
77
+ * @param snapshot - {@link takeoverSnapshot}'s answer.
78
+ * @returns the report with the `providers.takeover` row appended, when it has evidence.
79
+ */
80
+ export declare function mergeTakeoverReport<T extends TakeoverMergeReport>(report: T, snapshot: readonly TakeoverSnapshot[]): T;
@@ -0,0 +1,119 @@
1
+ /**
2
+ * The in-app doctor's effective-provider check for the three root-plane
3
+ * takeovers.
4
+ *
5
+ * The plugin replaces `subprocess`, `fs` and `directoryPicker` by disabling
6
+ * the shipped rows and mounting same-name providers. That swap can fail at
7
+ * runtime — most visibly on a HMR plugin upgrade, where the outgoing bundle
8
+ * layer re-activates the shipped rows before the incoming layer disables them
9
+ * again (see docs/UPSTREAM-SERVICE-SWAP.md). The failed rows leave no log line
10
+ * a user reads, and the doctor's standalone CLI cannot see live services at
11
+ * all, so the in-app surfaces inspect the context instead and report which
12
+ * provider is serving each name.
13
+ *
14
+ * `missing` for one name only is possible in a composition that intentionally
15
+ * disables the row; the check stays silent when NONE of the three is served,
16
+ * which is the shape of every context that cannot see the composition root
17
+ * (the test seam, a preset realm, the standalone CLI).
18
+ *
19
+ * This is a TypeScript source built to `lib/takeover-report.js`; edit THIS
20
+ * file and run `pnpm run build` — the artifact under `lib/` is generated.
21
+ *
22
+ * @module dsh-plugin-wsl-env/takeover-report
23
+ */
24
+ import { WslRoutingFileSystem } from "./fs-routing.js";
25
+ import { WslDirectoryPicker } from "./picker.js";
26
+ import { WslSubprocessRuntime } from "./subprocess.js";
27
+ /** The service names this plugin replaces with its own providers. */
28
+ export const TAKEOVER_SERVICES = ["subprocess", "fs", "directoryPicker"];
29
+ /**
30
+ * Whether one value is this plugin's provider for the named service.
31
+ *
32
+ * @param service - the service name.
33
+ * @param value - the value read from the context.
34
+ * @returns true for this plugin's class of that service.
35
+ */
36
+ function isPluginProvider(service, value) {
37
+ switch (service) {
38
+ case "subprocess":
39
+ return value instanceof WslSubprocessRuntime;
40
+ case "fs":
41
+ return value instanceof WslRoutingFileSystem;
42
+ case "directoryPicker":
43
+ return value instanceof WslDirectoryPicker;
44
+ }
45
+ }
46
+ /**
47
+ * Read which provider serves each takeover name in this context.
48
+ *
49
+ * A context that cannot look services up (a test seam, the standalone CLI
50
+ * report) yields an empty snapshot, and the merge then adds no row.
51
+ *
52
+ * @param ctx - the context to inspect.
53
+ * @returns one entry per takeover name, in {@link TAKEOVER_SERVICES} order.
54
+ */
55
+ export function takeoverSnapshot(ctx) {
56
+ const lookup = ctx.get;
57
+ if (typeof lookup !== "function")
58
+ return [];
59
+ return TAKEOVER_SERVICES.map((service) => {
60
+ let value;
61
+ try {
62
+ value = lookup(service);
63
+ }
64
+ catch {
65
+ // A context that refuses the read contributes no provider, exactly as
66
+ // an absent one does; the doctor reports what it could observe.
67
+ value = undefined;
68
+ }
69
+ if (value === undefined || value === null)
70
+ return { service, state: "missing" };
71
+ if (isPluginProvider(service, value))
72
+ return { service, state: "plugin" };
73
+ const name = value.constructor?.name;
74
+ return {
75
+ service,
76
+ state: "other",
77
+ ...(typeof name === "string" && name.length > 0 ? { provider: name } : {}),
78
+ };
79
+ });
80
+ }
81
+ /**
82
+ * Fold the effective-provider snapshot into a doctor report as one check.
83
+ *
84
+ * A context that cannot see any of the three services adds no row: it has no
85
+ * evidence about the takeovers, and inventing a finding would be noise in
86
+ * every preset realm and every unit test. When at least one service is
87
+ * served, the row names all three so a single `warn` says exactly which half
88
+ * of the swap landed.
89
+ *
90
+ * @param report - the doctor report (not mutated).
91
+ * @param snapshot - {@link takeoverSnapshot}'s answer.
92
+ * @returns the report with the `providers.takeover` row appended, when it has evidence.
93
+ */
94
+ export function mergeTakeoverReport(report, snapshot) {
95
+ if (snapshot.length === 0)
96
+ return report;
97
+ if (snapshot.every((entry) => entry.state === "missing"))
98
+ return report;
99
+ const inactive = snapshot.filter((entry) => entry.state !== "plugin");
100
+ const status = inactive.length === 0 ? "ok" : "warn";
101
+ const describe = (entry) => entry.state === "plugin"
102
+ ? "plugin"
103
+ : entry.state === "missing"
104
+ ? "missing"
105
+ : entry.provider ?? "another provider";
106
+ const check = {
107
+ id: "providers.takeover",
108
+ status,
109
+ title: "WSL service takeovers",
110
+ detail: `effective providers: ${snapshot.map((entry) => `${entry.service}=${describe(entry)}`).join(", ")}`,
111
+ ...(status === "warn"
112
+ ? { remedy: "restart DSH so the new composition applies the takeover; if a service stays on the shipped provider, quit DSH and install the plugin with the app closed — see docs/LIMITATIONS.md" }
113
+ : {}),
114
+ };
115
+ const checks = [...(report.checks ?? []), check];
116
+ const summary = { ...report.summary };
117
+ summary[status] = (summary[status] ?? 0) + 1;
118
+ return { ...report, checks, summary };
119
+ }
@@ -1,3 +1,4 @@
1
+ import { type TakeoverSnapshot } from "./takeover-report.js";
1
2
  export declare const name = "wsl-doctor-command";
2
3
  /**
3
4
  * No required inject: a headless deployment has no commands registry, and a
@@ -120,9 +121,11 @@ export declare function runDoctorCli(argv: string[], signal?: AbortSignal, timeo
120
121
  *
121
122
  * @param json - the CLI's stdout, one versioned JSON report.
122
123
  * @param distro - the distro the run named, for the session-distro markers.
124
+ * @param providers - the effective takeover providers this host process sees
125
+ * ({@link takeoverSnapshot}); the standalone CLI cannot observe them.
123
126
  * @returns the rendered report text.
124
127
  */
125
- export declare function formatDoctorReport(json: string, distro: string): string;
128
+ export declare function formatDoctorReport(json: string, distro: string, providers?: readonly TakeoverSnapshot[]): string;
126
129
  /**
127
130
  * Mount the command.
128
131
  *
@@ -34,6 +34,7 @@ import { distroOfUnc } from "./distro-route.js";
34
34
  import { withHostPeerVersions } from "./peer-versions.js";
35
35
  import { digestReport, renderDigest, SECTIONS } from "./wsl-doctor-tool.js";
36
36
  import { mergeAutoPresetSeam } from "./doctor-live.js";
37
+ import { mergeTakeoverReport, takeoverSnapshot } from "./takeover-report.js";
37
38
  export const name = "wsl-doctor-command";
38
39
  /**
39
40
  * No required inject: a headless deployment has no commands registry, and a
@@ -311,11 +312,14 @@ async function resolveDistro(ctx, invocation, distro) {
311
312
  *
312
313
  * @param json - the CLI's stdout, one versioned JSON report.
313
314
  * @param distro - the distro the run named, for the session-distro markers.
315
+ * @param providers - the effective takeover providers this host process sees
316
+ * ({@link takeoverSnapshot}); the standalone CLI cannot observe them.
314
317
  * @returns the rendered report text.
315
318
  */
316
- export function formatDoctorReport(json, distro) {
319
+ export function formatDoctorReport(json, distro, providers = []) {
317
320
  const report = JSON.parse(json);
318
- const digest = digestReport(mergeAutoPresetSeam(report), distro.length > 0 ? distro : undefined);
321
+ const live = mergeTakeoverReport(mergeAutoPresetSeam(report), providers);
322
+ const digest = digestReport(live, distro.length > 0 ? distro : undefined);
319
323
  return renderDigest(digest);
320
324
  }
321
325
  /**
@@ -370,7 +374,7 @@ export async function apply(ctx) {
370
374
  const budget = distro.length > 0 ? DOCTOR_CLI_TIMEOUT_MS : DOCTOR_CLI_SWEEP_TIMEOUT_MS;
371
375
  try {
372
376
  const json = await runCli(argv, invocation.signal, budget);
373
- return { kind: "success", text: formatDoctorReport(json, distro) };
377
+ return { kind: "success", text: formatDoctorReport(json, distro, takeoverSnapshot(ctx)) };
374
378
  }
375
379
  catch (error) {
376
380
  const target = distro.length > 0
@@ -27,6 +27,7 @@ import { defineTool } from "@deepseek-ai/dsh-tools";
27
27
  import { distroOfUnc } from "./distro-route.js";
28
28
  import { t } from "./messages.js";
29
29
  import { doctorReport } from "./doctor-report.js";
30
+ import { mergeTakeoverReport, takeoverSnapshot } from "./takeover-report.js";
30
31
  export const name = "wsl-doctor-tool";
31
32
  /**
32
33
  * The context properties `apply` reads eagerly: the tool registry and the
@@ -414,13 +415,16 @@ export async function apply(ctx) {
414
415
  const quick = argv.section === undefined || argv.section.length === 0 ? argv.depth !== "full" : false;
415
416
  const sections = argv.section !== undefined && argv.section.length > 0 ? [argv.section] : undefined;
416
417
  const doctor = await doctorCollector(ctx);
417
- const digest = digestReport(await doctor(distro, {
418
+ const report = await doctor(distro, {
418
419
  ...(quick ? { quick: true } : {}),
419
420
  ...(sections !== undefined ? { sections } : {}),
420
421
  // The run is a subprocess: the caller's cancellation (Esc on the
421
422
  // tool call) kills it instead of leaving it to finish unwatched.
422
423
  ...(exec.signal === undefined ? {} : { signal: exec.signal }),
423
- }), distro);
424
+ });
425
+ // The CLI cannot see live services; this row mounts in the app, so it
426
+ // adds the effective-provider check for the three root-plane takeovers.
427
+ const digest = digestReport(mergeTakeoverReport(report, takeoverSnapshot(ctx)), distro);
424
428
  return { verdict: digest.verdict, blockers: digest.blockers.join(", "), report: renderDigest(digest) };
425
429
  }
426
430
  }));
package/lib/wsl.d.ts CHANGED
@@ -52,6 +52,20 @@ export declare const DEFAULT_WSL_DEADLINE_MS = 60000;
52
52
  * @throws the execFile error, with a hint attached when the cause is the sandbox.
53
53
  */
54
54
  export declare function runCapture(argv: string[], signal?: AbortSignal, deadlineMs?: number): Promise<string>;
55
+ /**
56
+ * Run one host command and capture UTF-8 output with NUL bytes preserved.
57
+ *
58
+ * `runCapture` strips NULs because `wsl.exe` writes its own diagnostics as
59
+ * UTF-16LE; a distro command's `find -print0` output is NUL-separated data, and
60
+ * stripping it corrupts every name after the first. Callers that consume NUL
61
+ * separators use this variant instead.
62
+ *
63
+ * @param argv - executable plus arguments, spawned without a shell.
64
+ * @param signal - optional cancellation.
65
+ * @param deadlineMs - kill the call after this many milliseconds.
66
+ * @returns captured stdout, NUL separators intact.
67
+ */
68
+ export declare function runCaptureRaw(argv: string[], signal?: AbortSignal, deadlineMs?: number): Promise<string>;
55
69
  /**
56
70
  * List installed distros with `wsl.exe -l -q`.
57
71
  *
package/lib/wsl.js CHANGED
@@ -42,6 +42,34 @@ export const DEFAULT_WSL_DEADLINE_MS = 60_000;
42
42
  * @throws the execFile error, with a hint attached when the cause is the sandbox.
43
43
  */
44
44
  export function runCapture(argv, signal, deadlineMs = DEFAULT_WSL_DEADLINE_MS) {
45
+ return runCaptureWith(argv, signal, deadlineMs, true);
46
+ }
47
+ /**
48
+ * Run one host command and capture UTF-8 output with NUL bytes preserved.
49
+ *
50
+ * `runCapture` strips NULs because `wsl.exe` writes its own diagnostics as
51
+ * UTF-16LE; a distro command's `find -print0` output is NUL-separated data, and
52
+ * stripping it corrupts every name after the first. Callers that consume NUL
53
+ * separators use this variant instead.
54
+ *
55
+ * @param argv - executable plus arguments, spawned without a shell.
56
+ * @param signal - optional cancellation.
57
+ * @param deadlineMs - kill the call after this many milliseconds.
58
+ * @returns captured stdout, NUL separators intact.
59
+ */
60
+ export function runCaptureRaw(argv, signal, deadlineMs = DEFAULT_WSL_DEADLINE_MS) {
61
+ return runCaptureWith(argv, signal, deadlineMs, false);
62
+ }
63
+ /**
64
+ * The shared body of {@link runCapture} and {@link runCaptureRaw}.
65
+ *
66
+ * @param argv - executable plus arguments.
67
+ * @param signal - optional cancellation.
68
+ * @param deadlineMs - kill the call after this many milliseconds.
69
+ * @param stripNulls - drop NUL bytes (UTF-16LE diagnostics) before returning.
70
+ * @returns captured stdout.
71
+ */
72
+ function runCaptureWith(argv, signal, deadlineMs, stripNulls) {
45
73
  const [file, ...args] = argv;
46
74
  if (file === undefined)
47
75
  throw new Error("wsl: runCapture needs a program to run");
@@ -67,7 +95,8 @@ export function runCapture(argv, signal, deadlineMs = DEFAULT_WSL_DEADLINE_MS) {
67
95
  reject(error);
68
96
  return;
69
97
  }
70
- resolve(String(stdout ?? "").replace(/\u0000/g, ""));
98
+ const text = String(stdout ?? "");
99
+ resolve(stripNulls ? text.replace(/\u0000/g, "") : text);
71
100
  });
72
101
  });
73
102
  }