dsh-plugin-wsl-env 0.18.0 → 0.21.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 (123) hide show
  1. package/CHANGELOG.md +274 -0
  2. package/CONTRIBUTING.md +37 -5
  3. package/README.md +60 -5
  4. package/SUPPORT.md +3 -3
  5. package/agent/native/linux-aarch64/dsh-wsl-agent +0 -0
  6. package/agent/native/linux-x86_64/dsh-wsl-agent +0 -0
  7. package/agent/wsl-agent.sh +331 -11
  8. package/client.d.ts +5 -0
  9. package/client.js +98 -0
  10. package/cordis.patch.yml +66 -1
  11. package/docs/AGENT-PROTOCOL-V7.md +175 -0
  12. package/docs/API.md +25 -0
  13. package/docs/ARCHITECTURE.md +14 -1
  14. package/docs/CONFIGURATION.md +47 -6
  15. package/docs/CONFIGURATION.zh.md +20 -4
  16. package/docs/DIAGNOSTICS.md +83 -0
  17. package/docs/DIAGNOSTICS.zh.md +73 -0
  18. package/docs/LIMITATIONS.md +41 -4
  19. package/docs/LIMITATIONS.zh.md +27 -11
  20. package/docs/MIGRATION.md +4 -4
  21. package/docs/PEER-PARITY.md +50 -33
  22. package/docs/QUICKSTART.md +37 -4
  23. package/docs/QUICKSTART.zh.md +16 -1
  24. package/docs/README.zh.md +43 -4
  25. package/docs/RELEASING.md +4 -1
  26. package/docs/REQUIREMENTS.zh.md +3 -2
  27. package/docs/ROADMAP-1.0.md +75 -19
  28. package/docs/UPSTREAM-FILE-REFERENCE-SEAM.md +8 -1
  29. package/docs/UPSTREAM-OPEN-IN-APP.md +33 -0
  30. package/docs/UPSTREAM-SESSION-NOTICE.md +3 -1
  31. package/docs/UPSTREAM-TERMINAL-TITLE.md +3 -0
  32. package/docs/root-fs-routing.md +3 -3
  33. package/lib/agent-confined.js +4 -4
  34. package/lib/agent-errors.d.ts +1 -1
  35. package/lib/agent-errors.js +1 -1
  36. package/lib/agent-exec.d.ts +1 -1
  37. package/lib/agent-exec.js +1 -1
  38. package/lib/agent-protocol.d.ts +58 -8
  39. package/lib/agent-protocol.js +40 -7
  40. package/lib/agent-shared.d.ts +1 -1
  41. package/lib/agent-shared.js +1 -1
  42. package/lib/agent.d.ts +171 -1
  43. package/lib/agent.js +448 -288
  44. package/lib/auto-preset.d.ts +1 -1
  45. package/lib/auto-preset.js +1 -1
  46. package/lib/bwrap.d.ts +1 -1
  47. package/lib/bwrap.js +1 -1
  48. package/lib/client-host.d.ts +29 -0
  49. package/lib/client-host.js +29 -0
  50. package/lib/cwd-prompt-tool.d.ts +88 -0
  51. package/lib/cwd-prompt-tool.js +94 -0
  52. package/lib/cwd-prompt.d.ts +166 -0
  53. package/lib/cwd-prompt.js +203 -0
  54. package/lib/distro-route.d.ts +1 -1
  55. package/lib/distro-route.js +1 -1
  56. package/lib/doctor-live.d.ts +57 -0
  57. package/lib/doctor-live.js +38 -0
  58. package/lib/file-reference-wsl.d.ts +1 -1
  59. package/lib/file-reference-wsl.js +1 -1
  60. package/lib/fs-decisions.d.ts +1 -1
  61. package/lib/fs-decisions.js +1 -1
  62. package/lib/fs-routing.d.ts +1 -1
  63. package/lib/fs-routing.js +1 -1
  64. package/lib/fs-substrate.d.ts +90 -11
  65. package/lib/fs-substrate.js +202 -1
  66. package/lib/fs.d.ts +1 -1
  67. package/lib/fs.js +1 -1
  68. package/lib/fsio-agent.d.ts +128 -4
  69. package/lib/fsio-agent.js +224 -15
  70. package/lib/fsio-text.d.ts +1 -1
  71. package/lib/fsio-text.js +1 -1
  72. package/lib/git-exec.d.ts +1 -1
  73. package/lib/git-exec.js +1 -1
  74. package/lib/git-route.d.ts +1 -1
  75. package/lib/git-route.js +1 -1
  76. package/lib/index.d.ts +105 -30
  77. package/lib/index.js +272 -130
  78. package/lib/listing.d.ts +1 -1
  79. package/lib/listing.js +1 -1
  80. package/lib/messages.d.ts +157 -0
  81. package/lib/messages.js +199 -0
  82. package/lib/native-agent.d.ts +1 -1
  83. package/lib/native-agent.js +2 -2
  84. package/lib/paths.d.ts +6 -3
  85. package/lib/paths.js +4 -4
  86. package/lib/picker.d.ts +1 -1
  87. package/lib/picker.js +7 -7
  88. package/lib/ports.d.ts +1 -1
  89. package/lib/ports.js +1 -1
  90. package/lib/preflight.d.ts +25 -1
  91. package/lib/preflight.js +112 -12
  92. package/lib/sandbox-core.d.ts +1 -1
  93. package/lib/sandbox-core.js +9 -16
  94. package/lib/sandbox.d.ts +1 -1
  95. package/lib/sandbox.js +1 -1
  96. package/lib/search-exec.d.ts +1 -1
  97. package/lib/search-exec.js +1 -1
  98. package/lib/search-route.d.ts +1 -1
  99. package/lib/search-route.js +1 -1
  100. package/lib/session-runtime.d.ts +1 -1
  101. package/lib/session-runtime.js +2 -2
  102. package/lib/session-scope.d.ts +1 -1
  103. package/lib/session-scope.js +11 -6
  104. package/lib/shell-env.d.ts +26 -1
  105. package/lib/shell-env.js +57 -1
  106. package/lib/shell.d.ts +4 -2
  107. package/lib/shell.js +4 -2
  108. package/lib/subprocess.d.ts +1 -1
  109. package/lib/subprocess.js +2 -2
  110. package/lib/terminal-activity.d.ts +1 -1
  111. package/lib/terminal-activity.js +1 -1
  112. package/lib/terminal-route.d.ts +1 -1
  113. package/lib/terminal-route.js +1 -1
  114. package/lib/update-check.d.ts +197 -0
  115. package/lib/update-check.js +211 -0
  116. package/lib/watcher.d.ts +1 -1
  117. package/lib/watcher.js +1 -1
  118. package/lib/wsl-doctor-tool.d.ts +122 -0
  119. package/lib/wsl-doctor-tool.js +161 -0
  120. package/lib/wsl.d.ts +1 -31
  121. package/lib/wsl.js +1 -21
  122. package/package.json +55 -6
  123. package/scripts/doctor.mjs +1196 -166
@@ -0,0 +1,197 @@
1
+ /**
2
+ * The plugin's update check: notice when a newer release exists, stop there.
3
+ *
4
+ * Upgrading today means re-installing by hand (Plugins page, or
5
+ * `dsh plugin add`) and the harness's own plugin-manager already answers
6
+ * "which versions exist and do they fit this DSH" — `listVersions` resolves
7
+ * dist-tags, deprecation, and the `engines.dsh`/peer compatibility of every
8
+ * candidate against the running DSH. This service makes that answer arrive
9
+ * without the user opening the Versions page first: on a slow timer it asks
10
+ * the host's `pluginManager` for this package's version list and, when the
11
+ * stable channel has moved, publishes one fact. Applying the update stays a
12
+ * user action — a plugin that silently replaces its own code under a running
13
+ * harness is a posture this plugin rejects, and the harness has no HMR, so
14
+ * even a correct swap needs a restart to take effect.
15
+ *
16
+ * Delegation is the whole network story: the check spawns nothing and fetches
17
+ * nothing itself. `pluginManager` is read with `ctx.get`, the sanctioned read
18
+ * for a service this row does not inject — a host without it (or a bundle
19
+ * loaded from a linked checkout, which `listVersions` refuses as
20
+ * `not-updatable` because the mirror is managed by `pnpm run sync:windows`)
21
+ * simply means no check ran, at debug level, never a warning.
22
+ *
23
+ * This is a TypeScript source built to `lib/update-check.js`; edit THIS file
24
+ * and run `pnpm run build` — the artifact under `lib/` is generated, and
25
+ * `pnpm test` fails when it drifts.
26
+ *
27
+ * @module dsh-plugin-wsl-env/update-check
28
+ */
29
+ import z from "@deepseek-ai/schemastery";
30
+ import type { Context } from "@deepseek-ai/cordis";
31
+ export declare const name = "wsl-update-check";
32
+ /** The interval the row ships with. */
33
+ export declare const DEFAULT_INTERVAL_MS: number;
34
+ /** The smallest interval a config may ask for; one check spawns `pnpm view` in the profile. */
35
+ export declare const MIN_INTERVAL_MS: number;
36
+ export declare const Config: z<Schemastery.ObjectS<NoInfer<{
37
+ /** Whether the update check runs at all. */
38
+ enabled: z<boolean, boolean, "defined">;
39
+ /** How often the registry is asked, in milliseconds; floored at one minute. */
40
+ intervalMs: z<number, number, "defined">;
41
+ }>>, Schemastery.ObjectT<NoInfer<{
42
+ /** Whether the update check runs at all. */
43
+ enabled: z<boolean, boolean, "defined">;
44
+ /** How often the registry is asked, in milliseconds; floored at one minute. */
45
+ intervalMs: z<number, number, "defined">;
46
+ }>>, "plain">;
47
+ /** The config schema's validated output. */
48
+ export interface UpdateCheckConfig {
49
+ /** Whether the update check runs at all. */
50
+ enabled?: boolean;
51
+ /** How often the registry is asked, in milliseconds. */
52
+ intervalMs?: number;
53
+ }
54
+ /** One published version, reduced to what the fact reads (host plugin-manager types). */
55
+ interface ListedVersion {
56
+ readonly version: string;
57
+ readonly publishedAt?: string;
58
+ readonly tags: readonly string[];
59
+ /** Whether the version carries a semver prerelease suffix. */
60
+ readonly prerelease: boolean;
61
+ /** The registry's deprecation message, when the version is deprecated. */
62
+ readonly deprecated?: string;
63
+ /** A version without the bundle manifest cannot replace this bundle. */
64
+ readonly bundle: boolean;
65
+ /** Present when the running DSH rejects this version's engines/peers. */
66
+ readonly incompatible?: {
67
+ reason?: string;
68
+ } | undefined;
69
+ }
70
+ /** What one check learned, in the two shapes `listVersions` answers (host plugin-manager types). */
71
+ export type VersionList = {
72
+ readonly status: "listed";
73
+ readonly installed: string;
74
+ readonly registry: string;
75
+ readonly attempts: readonly unknown[];
76
+ /** Published versions newer than `installed`, newest first. */
77
+ readonly versions: readonly ListedVersion[];
78
+ readonly omitted: number;
79
+ } | {
80
+ readonly status: "refused";
81
+ readonly problem: "not-updatable" | "not-found" | "network" | "unknown";
82
+ readonly reason: string;
83
+ readonly attempts: readonly unknown[];
84
+ };
85
+ /**
86
+ * The slice of the host's plugin-manager this row calls. The service belongs
87
+ * to the harness and its declaration is not visible to this plugin, so it is
88
+ * spelled structurally; `versions` are newer than the installed one, newest
89
+ * first (see `packages/boot/plugin-manager/src/types.ts` upstream).
90
+ */
91
+ export interface PluginManagerSlice {
92
+ listVersions: (name: string) => Promise<VersionList>;
93
+ }
94
+ /** The update fact one successful check publishes. */
95
+ export interface UpdateFact {
96
+ /** The version this process runs. */
97
+ installed: string;
98
+ /** The version the stable channel offers. */
99
+ latest: string;
100
+ /** When the registry published it, as an ISO 8601 string. */
101
+ publishedAt?: string;
102
+ /** The running DSH rejects this version; upgrading means upgrading DSH first. */
103
+ incompatible: boolean;
104
+ /** The registry's deprecation message, when the newest release is deprecated. */
105
+ deprecated?: string;
106
+ /** When the check ran, in epoch milliseconds. */
107
+ checkedAt: number;
108
+ }
109
+ /**
110
+ * The newest update fact this process has published, or undefined when no
111
+ * check ran, the registry said "up to date", or the last check learned
112
+ * nothing actionable.
113
+ *
114
+ * @returns the fact, for `shellEnv`'s synchronous resolver.
115
+ */
116
+ export declare function currentUpdateFact(): UpdateFact | undefined;
117
+ /**
118
+ * Publish (or clear) the update fact. Exported for the tests, which must be
119
+ * able to stage a fact without a host plugin-manager — the same "tests-only"
120
+ * carve-out as `clearNativeBackendCache`.
121
+ *
122
+ * @param next - the fact to publish, or undefined to clear.
123
+ */
124
+ export declare function setUpdateFact(next: UpdateFact | undefined): void;
125
+ /**
126
+ * The interval a config asks for, floored at {@link MIN_INTERVAL_MS}. A check
127
+ * spawns `pnpm view` in the profile, so a tight loop would hammer the
128
+ * registry; the floor makes even `0` safe.
129
+ *
130
+ * @param ms - the configured interval, or undefined for the default.
131
+ * @returns the interval the scheduler uses.
132
+ */
133
+ export declare function clampInterval(ms: number | undefined): number;
134
+ /**
135
+ * How long after mount the first check waits: two to ten minutes, jittered.
136
+ * The delay keeps the check off the startup path (a cold start must not wait
137
+ * on a registry round-trip) and off the startup stampede of `pnpm` work the
138
+ * profile is already doing.
139
+ *
140
+ * @param random - the randomness source, injectable for tests.
141
+ * @returns the delay in milliseconds.
142
+ */
143
+ export declare function firstDelayMs(random?: () => number): number;
144
+ /**
145
+ * Pick the version the fact should name: the stable channel's newest release
146
+ * (`latest` tag) that is still a bundle. Prereleases ship on `next` by the
147
+ * release discipline and never move `latest`, so they are not news; a version
148
+ * that lost the bundle manifest could not be installed as an update. The list
149
+ * is newest-first, so the first match is the newest.
150
+ *
151
+ * @param list - the version list `listVersions` answered with.
152
+ * @returns the target version, or undefined when the stable channel has not moved.
153
+ */
154
+ export declare function updateTarget(list: Extract<VersionList, {
155
+ status: "listed";
156
+ }>): ListedVersion | undefined;
157
+ /**
158
+ * Run one check against the host's plugin-manager and publish the fact.
159
+ *
160
+ * Every non-answer is quiet by design: a missing manager, a linked checkout
161
+ * (`not-updatable`), a registry the host cannot reach (`network`), or a stable
162
+ * channel that has not moved all leave the previous fact (or none) standing —
163
+ * an update check must never become the noisiest thing in the app.
164
+ *
165
+ * @param manager - the host plugin-manager, or undefined when the host has none.
166
+ * @returns the published fact, or undefined when the check learned nothing.
167
+ */
168
+ export declare function checkForUpdate(manager: PluginManagerSlice | undefined): Promise<UpdateFact | undefined>;
169
+ /**
170
+ * The fact as one line, for the managed `DSH_*` variable and the log. The
171
+ * wording is the same the doctor's section reuses, so "available" never
172
+ * drifts between the two surfaces.
173
+ *
174
+ * @param update - the fact, or undefined.
175
+ * @returns the message, or an empty string when there is nothing to say.
176
+ */
177
+ export declare function updateFactMessage(update: UpdateFact | undefined): string;
178
+ /**
179
+ * The cordis context extended with the slices this service consumes. `logger`
180
+ * and `pluginManager` belong to the harness, whose declarations are not
181
+ * visible to this plugin, so they are spelled structurally on top of the
182
+ * framework's {@link Context}.
183
+ */
184
+ export type UpdateCheckContext = Context & {
185
+ logger?: {
186
+ debug?: (message: string) => void;
187
+ };
188
+ pluginManager?: PluginManagerSlice;
189
+ };
190
+ /**
191
+ * Mount the update check.
192
+ *
193
+ * @param ctx - the cordis context.
194
+ * @param config - the schema-validated plugin config.
195
+ */
196
+ export declare function apply(ctx: UpdateCheckContext, config?: UpdateCheckConfig): Promise<void>;
197
+ export {};
@@ -0,0 +1,211 @@
1
+ /**
2
+ * The plugin's update check: notice when a newer release exists, stop there.
3
+ *
4
+ * Upgrading today means re-installing by hand (Plugins page, or
5
+ * `dsh plugin add`) and the harness's own plugin-manager already answers
6
+ * "which versions exist and do they fit this DSH" — `listVersions` resolves
7
+ * dist-tags, deprecation, and the `engines.dsh`/peer compatibility of every
8
+ * candidate against the running DSH. This service makes that answer arrive
9
+ * without the user opening the Versions page first: on a slow timer it asks
10
+ * the host's `pluginManager` for this package's version list and, when the
11
+ * stable channel has moved, publishes one fact. Applying the update stays a
12
+ * user action — a plugin that silently replaces its own code under a running
13
+ * harness is a posture this plugin rejects, and the harness has no HMR, so
14
+ * even a correct swap needs a restart to take effect.
15
+ *
16
+ * Delegation is the whole network story: the check spawns nothing and fetches
17
+ * nothing itself. `pluginManager` is read with `ctx.get`, the sanctioned read
18
+ * for a service this row does not inject — a host without it (or a bundle
19
+ * loaded from a linked checkout, which `listVersions` refuses as
20
+ * `not-updatable` because the mirror is managed by `pnpm run sync:windows`)
21
+ * simply means no check ran, at debug level, never a warning.
22
+ *
23
+ * This is a TypeScript source built to `lib/update-check.js`; edit THIS file
24
+ * and run `pnpm run build` — the artifact under `lib/` is generated, and
25
+ * `pnpm test` fails when it drifts.
26
+ *
27
+ * @module dsh-plugin-wsl-env/update-check
28
+ */
29
+ import z from "@deepseek-ai/schemastery";
30
+ export const name = "wsl-update-check";
31
+ /** The checked package: this plugin, by its npm name. */
32
+ const PACKAGE = "dsh-plugin-wsl-env";
33
+ /** The interval the row ships with. */
34
+ export const DEFAULT_INTERVAL_MS = 24 * 60 * 60 * 1000;
35
+ /** The smallest interval a config may ask for; one check spawns `pnpm view` in the profile. */
36
+ export const MIN_INTERVAL_MS = 60 * 1000;
37
+ export const Config = z.object({
38
+ /** Whether the update check runs at all. */
39
+ enabled: z.boolean().default(true),
40
+ /** How often the registry is asked, in milliseconds; floored at one minute. */
41
+ intervalMs: z.number().default(DEFAULT_INTERVAL_MS),
42
+ });
43
+ /**
44
+ * The module-level fact store. `shellEnv`'s resolver is synchronous by
45
+ * contract, so the timer-fed fact must live somewhere a plain import can read
46
+ * without await — the same posture as the ports snapshot, and the same
47
+ * module-singleton pattern as the shared agent (`lib/agent-shared.js`).
48
+ */
49
+ let fact;
50
+ /**
51
+ * The newest update fact this process has published, or undefined when no
52
+ * check ran, the registry said "up to date", or the last check learned
53
+ * nothing actionable.
54
+ *
55
+ * @returns the fact, for `shellEnv`'s synchronous resolver.
56
+ */
57
+ export function currentUpdateFact() {
58
+ return fact;
59
+ }
60
+ /**
61
+ * Publish (or clear) the update fact. Exported for the tests, which must be
62
+ * able to stage a fact without a host plugin-manager — the same "tests-only"
63
+ * carve-out as `clearNativeBackendCache`.
64
+ *
65
+ * @param next - the fact to publish, or undefined to clear.
66
+ */
67
+ export function setUpdateFact(next) {
68
+ fact = next;
69
+ }
70
+ /**
71
+ * The interval a config asks for, floored at {@link MIN_INTERVAL_MS}. A check
72
+ * spawns `pnpm view` in the profile, so a tight loop would hammer the
73
+ * registry; the floor makes even `0` safe.
74
+ *
75
+ * @param ms - the configured interval, or undefined for the default.
76
+ * @returns the interval the scheduler uses.
77
+ */
78
+ export function clampInterval(ms) {
79
+ return Math.max(ms ?? DEFAULT_INTERVAL_MS, MIN_INTERVAL_MS);
80
+ }
81
+ /**
82
+ * How long after mount the first check waits: two to ten minutes, jittered.
83
+ * The delay keeps the check off the startup path (a cold start must not wait
84
+ * on a registry round-trip) and off the startup stampede of `pnpm` work the
85
+ * profile is already doing.
86
+ *
87
+ * @param random - the randomness source, injectable for tests.
88
+ * @returns the delay in milliseconds.
89
+ */
90
+ export function firstDelayMs(random = Math.random) {
91
+ return 120_000 + random() * 480_000;
92
+ }
93
+ /**
94
+ * Pick the version the fact should name: the stable channel's newest release
95
+ * (`latest` tag) that is still a bundle. Prereleases ship on `next` by the
96
+ * release discipline and never move `latest`, so they are not news; a version
97
+ * that lost the bundle manifest could not be installed as an update. The list
98
+ * is newest-first, so the first match is the newest.
99
+ *
100
+ * @param list - the version list `listVersions` answered with.
101
+ * @returns the target version, or undefined when the stable channel has not moved.
102
+ */
103
+ export function updateTarget(list) {
104
+ return list.versions.find((version) => version.bundle && version.tags.includes("latest"));
105
+ }
106
+ /**
107
+ * Run one check against the host's plugin-manager and publish the fact.
108
+ *
109
+ * Every non-answer is quiet by design: a missing manager, a linked checkout
110
+ * (`not-updatable`), a registry the host cannot reach (`network`), or a stable
111
+ * channel that has not moved all leave the previous fact (or none) standing —
112
+ * an update check must never become the noisiest thing in the app.
113
+ *
114
+ * @param manager - the host plugin-manager, or undefined when the host has none.
115
+ * @returns the published fact, or undefined when the check learned nothing.
116
+ */
117
+ export async function checkForUpdate(manager) {
118
+ if (manager === undefined)
119
+ return undefined;
120
+ let list;
121
+ try {
122
+ list = await manager.listVersions(PACKAGE);
123
+ }
124
+ catch {
125
+ // `listVersions` resolves refusals into its result; a throw means the
126
+ // service itself is broken. The next tick retries; nothing is published.
127
+ return undefined;
128
+ }
129
+ if (list.status !== "listed")
130
+ return undefined;
131
+ const target = updateTarget(list);
132
+ if (target === undefined) {
133
+ setUpdateFact(undefined);
134
+ return undefined;
135
+ }
136
+ const next = {
137
+ installed: list.installed,
138
+ latest: target.version,
139
+ ...(target.publishedAt === undefined ? {} : { publishedAt: target.publishedAt }),
140
+ incompatible: target.incompatible !== undefined,
141
+ ...(target.deprecated === undefined ? {} : { deprecated: target.deprecated }),
142
+ checkedAt: Date.now(),
143
+ };
144
+ setUpdateFact(next);
145
+ return next;
146
+ }
147
+ /**
148
+ * The fact as one line, for the managed `DSH_*` variable and the log. The
149
+ * wording is the same the doctor's section reuses, so "available" never
150
+ * drifts between the two surfaces.
151
+ *
152
+ * @param update - the fact, or undefined.
153
+ * @returns the message, or an empty string when there is nothing to say.
154
+ */
155
+ export function updateFactMessage(update) {
156
+ if (update === undefined)
157
+ return "";
158
+ const marks = [];
159
+ if (update.incompatible)
160
+ marks.push("requires a newer DSH first");
161
+ if (update.deprecated !== undefined)
162
+ marks.push(`deprecated: ${update.deprecated}`);
163
+ const tail = marks.length === 0 ? "" : ` — ${marks.join("; ")}`;
164
+ return `${update.latest} available (installed ${update.installed})${tail}`;
165
+ }
166
+ /**
167
+ * Mount the update check.
168
+ *
169
+ * @param ctx - the cordis context.
170
+ * @param config - the schema-validated plugin config.
171
+ */
172
+ export async function apply(ctx, config = {}) {
173
+ if (!(config.enabled ?? true))
174
+ return;
175
+ const intervalMs = clampInterval(config.intervalMs);
176
+ const debug = (message) => ctx.logger?.debug?.(message);
177
+ const tick = async () => {
178
+ try {
179
+ // The read is the cordis-sanctioned one for a service this row does not
180
+ // inject: `ctx.get` answers undefined when the host has no
181
+ // plugin-manager (a headless harness, a bare composition), where a
182
+ // property read would throw and mark the whole component failed.
183
+ const manager = ctx.get("pluginManager");
184
+ if (manager === undefined) {
185
+ debug("wsl-update-check: the host has no plugin-manager; the check is skipped");
186
+ return;
187
+ }
188
+ const published = await checkForUpdate(manager);
189
+ if (published === undefined) {
190
+ debug("wsl-update-check: no newer stable release (or the registry was unreachable)");
191
+ return;
192
+ }
193
+ debug(`wsl-update-check: ${updateFactMessage(published)}`);
194
+ }
195
+ catch (error) {
196
+ // A check that cannot run is a next tick's business, never a session's
197
+ // error: the timer swallows everything at debug level.
198
+ debug(`wsl-update-check: the check failed (${error?.message ?? error})`);
199
+ }
200
+ };
201
+ const first = setTimeout(() => void tick(), firstDelayMs());
202
+ const repeat = setInterval(() => void tick(), intervalMs);
203
+ first.unref?.();
204
+ repeat.unref?.();
205
+ // Disposing matters: a config hot-reload re-runs apply(), and two live
206
+ // timers would double the registry traffic.
207
+ ctx.effect(() => () => {
208
+ clearTimeout(first);
209
+ clearInterval(repeat);
210
+ });
211
+ }
package/lib/watcher.d.ts CHANGED
@@ -44,7 +44,7 @@
44
44
  * run `pnpm run build` — the artifact under `lib/` is generated, and `pnpm test`
45
45
  * fails when it drifts.
46
46
  *
47
- * @module dsh-plugin-wsl/watcher
47
+ * @module dsh-plugin-wsl-env/watcher
48
48
  */
49
49
  import type { ChildProcess } from "node:child_process";
50
50
  /**
package/lib/watcher.js CHANGED
@@ -44,7 +44,7 @@
44
44
  * run `pnpm run build` — the artifact under `lib/` is generated, and `pnpm test`
45
45
  * fails when it drifts.
46
46
  *
47
- * @module dsh-plugin-wsl/watcher
47
+ * @module dsh-plugin-wsl-env/watcher
48
48
  */
49
49
  import { spawn } from "node:child_process";
50
50
  import { createInterface } from "node:readline";
@@ -0,0 +1,122 @@
1
+ /**
2
+ * The `wsl_doctor` tool: the model runs the environment doctor itself, and
3
+ * the verdict lands in the transcript — the GUI entry that belongs entirely
4
+ * to the plugin.
5
+ *
6
+ * The doctor is this package's own diagnostic (WSL-316); exposing it as a
7
+ * tool keeps the loop cohesive: no upstream surface is required, no file is
8
+ * written into the user's workspace, and the model gets a structured digest
9
+ * (verdict, blockers, per-failure copy-paste remedies) it can narrate or
10
+ * act on. The heavy lifting is {@link doctorReport} — the sanctioned
11
+ * in-process collector that spawns the shipped CLI once with the app's own
12
+ * runtime and folds the live resident's state in; the tool adds only the
13
+ * distro resolution and the digest.
14
+ *
15
+ * The distro comes from the caller when given, else from the agent's own
16
+ * session cwd through the harness's `workingDirectory` service — the same
17
+ * resolution the preflight performs, and the reason this row mounts inside
18
+ * the `preset-wsl` block: a host-preset agent has no distro to examine.
19
+ *
20
+ * This is a TypeScript source built to `lib/wsl-doctor-tool.js`; edit THIS
21
+ * file and run `pnpm run build` — the artifact under `lib/` is generated,
22
+ * and `pnpm test` fails when it drifts.
23
+ *
24
+ * @module dsh-plugin-wsl-env/wsl-doctor-tool
25
+ */
26
+ export declare const name = "wsl-doctor-tool";
27
+ /**
28
+ * The context properties `apply` reads eagerly: the tool registry and the
29
+ * harness's `workingDirectory` service (the session's distro resolution).
30
+ * Cordis 4 refuses an undeclared read, so both must be named here. The doctor
31
+ * collector is deliberately NOT injected: no host row provides a `doctor`
32
+ * service, and a required inject would fail the whole preset mount; it is
33
+ * resolved per call through the optional `ctx.get` (which needs no inject)
34
+ * with the package's own `doctorReport` as the fallback — `doctorCollector`
35
+ * below.
36
+ */
37
+ export declare const inject: string[];
38
+ /** The tool registry slice this service consumes. */
39
+ export interface ToolRegistrySlice {
40
+ register: (tool: unknown) => unknown;
41
+ }
42
+ /** The harness's `workingDirectory` service slice (cwd resolution). */
43
+ export interface WorkingDirectoryToolSlice {
44
+ ensure: (agent: unknown, signal?: unknown) => Promise<string>;
45
+ }
46
+ /** The doctor report this tool digests — the doctor CLI's versioned shape. */
47
+ export interface DoctorReportLike {
48
+ verdict?: string;
49
+ blockers?: string[];
50
+ distroVerdicts?: Array<{
51
+ name: string;
52
+ verdict: string;
53
+ blockers: string[];
54
+ }>;
55
+ checks?: Array<{
56
+ id: string;
57
+ status: string;
58
+ title?: string;
59
+ detail?: string;
60
+ remedy?: string;
61
+ distro?: string;
62
+ }>;
63
+ summary?: Record<string, number>;
64
+ }
65
+ /** The cordis context slice this service consumes. */
66
+ export type WslDoctorToolContext = {
67
+ tools: ToolRegistrySlice;
68
+ workingDirectory: WorkingDirectoryToolSlice;
69
+ /** Optional cordis-style lookup: how production resolves `doctor` without an inject. */
70
+ get?: (name: string) => unknown;
71
+ /** The in-process collector: a provided `doctor` service, or the test seam's fake. */
72
+ doctor?: (distro: string) => Promise<DoctorReportLike>;
73
+ };
74
+ /** The tool's config: the row takes no options. */
75
+ export interface WslDoctorToolConfig {
76
+ /** Reserved; the wrapper has no options today. */
77
+ enabled?: boolean;
78
+ }
79
+ /** One failing check as the digest carries it: what failed and what to do. */
80
+ export interface FailingCheck {
81
+ id: string;
82
+ detail: string;
83
+ remedy: string;
84
+ }
85
+ /** The tool's result: the doctor's verdict, condensed for the model. */
86
+ export interface DoctorDigest {
87
+ verdict: string;
88
+ blockers: string[];
89
+ failing: FailingCheck[];
90
+ warningCount: number;
91
+ skippedCount: number;
92
+ distroVerdicts: Array<{
93
+ name: string;
94
+ verdict: string;
95
+ blockers: string[];
96
+ }>;
97
+ note: string;
98
+ }
99
+ /**
100
+ * Digest one doctor report down to what the model acts on: the verdict, the
101
+ * blockers, and every failing check with its copy-paste remedy. Warnings and
102
+ * skipped legs count but do not list — the report's own ids name them when
103
+ * the model asks.
104
+ * @param report - the collected (and live-merged) doctor report.
105
+ * @returns the digest.
106
+ */
107
+ export declare function digestReport(report: DoctorReportLike): DoctorDigest;
108
+ /**
109
+ * Render the digest as the tool's text output: one verdict line, one line
110
+ * per failing check with its remedy. The model narrates this; keeping it
111
+ * plain text keeps the transcript readable.
112
+ * @param digest - the digested report.
113
+ * @returns the multi-line text.
114
+ */
115
+ export declare function renderDigest(digest: DoctorDigest): string;
116
+ /**
117
+ * Mount the tool.
118
+ *
119
+ * @param ctx - the cordis context (the preset realm, where the tools
120
+ * registry and the workingDirectory service are reachable).
121
+ */
122
+ export declare function apply(ctx: WslDoctorToolContext): Promise<void>;