dsh-plugin-wsl-env 0.19.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.
- package/CHANGELOG.md +122 -0
- package/README.md +2 -2
- package/client.d.ts +5 -0
- package/client.js +98 -0
- package/cordis.patch.yml +66 -1
- package/docs/API.md +1 -0
- package/docs/CONFIGURATION.md +39 -5
- package/docs/CONFIGURATION.zh.md +15 -1
- package/docs/DIAGNOSTICS.md +83 -0
- package/docs/DIAGNOSTICS.zh.md +73 -0
- package/docs/LIMITATIONS.md +25 -0
- package/docs/LIMITATIONS.zh.md +7 -0
- package/docs/MIGRATION.md +1 -1
- package/docs/QUICKSTART.md +19 -3
- package/docs/RELEASING.md +3 -0
- package/docs/ROADMAP-1.0.md +49 -4
- package/docs/UPSTREAM-FILE-REFERENCE-SEAM.md +5 -0
- package/docs/UPSTREAM-OPEN-IN-APP.md +33 -0
- package/lib/client-host.d.ts +29 -0
- package/lib/client-host.js +29 -0
- package/lib/cwd-prompt-tool.d.ts +88 -0
- package/lib/cwd-prompt-tool.js +94 -0
- package/lib/cwd-prompt.d.ts +166 -0
- package/lib/cwd-prompt.js +203 -0
- package/lib/doctor-live.d.ts +5 -1
- package/lib/doctor-live.js +3 -2
- package/lib/index.js +6 -8
- package/lib/messages.d.ts +157 -0
- package/lib/messages.js +199 -0
- package/lib/preflight.d.ts +24 -0
- package/lib/preflight.js +111 -11
- package/lib/sandbox-core.js +7 -14
- package/lib/session-scope.js +10 -5
- package/lib/shell-env.d.ts +25 -0
- package/lib/shell-env.js +56 -0
- package/lib/shell.d.ts +3 -1
- package/lib/shell.js +3 -1
- package/lib/update-check.d.ts +197 -0
- package/lib/update-check.js +211 -0
- package/lib/wsl-doctor-tool.d.ts +122 -0
- package/lib/wsl-doctor-tool.js +161 -0
- package/package.json +43 -5
- package/scripts/doctor.mjs +1167 -160
package/lib/preflight.d.ts
CHANGED
|
@@ -11,6 +11,12 @@
|
|
|
11
11
|
* command after it pays nothing. Nothing else changes: the failure semantics
|
|
12
12
|
* stay exactly as fail-closed as before, this service only MOVES THE NEWS.
|
|
13
13
|
*
|
|
14
|
+
* The same probes also run once at plugin load (`startup`, on by default) so an
|
|
15
|
+
* install-plus-restart already carries the verdict in the log — the pinned or
|
|
16
|
+
* WSL-default distro — before the first session opens. A session on that distro
|
|
17
|
+
* repeats only the runtime-context entry; other distros keep the session-open
|
|
18
|
+
* check unchanged.
|
|
19
|
+
*
|
|
14
20
|
* Advisory by construction. A preflight that cannot run (no WSL, a wedged
|
|
15
21
|
* `wsl.exe`) degrades to a log line; it must never fail a session that has not
|
|
16
22
|
* even asked for confinement yet. It also never installs anything: the remedy
|
|
@@ -44,6 +50,14 @@ export declare const Config: z<Schemastery.ObjectS<NoInfer<{
|
|
|
44
50
|
* that profile does not use.
|
|
45
51
|
*/
|
|
46
52
|
sessionSandbox: z<boolean, boolean, "defined">;
|
|
53
|
+
/**
|
|
54
|
+
* Whether the same checks also run once at plugin load — install + restart —
|
|
55
|
+
* against the pinned or WSL-default distro, so the verdict is in the log
|
|
56
|
+
* before any session opens. Sessions on other distros are still checked at
|
|
57
|
+
* open, and a session announcement for a message the load pass already
|
|
58
|
+
* logged skips the duplicate log line but keeps its runtime-context entry.
|
|
59
|
+
*/
|
|
60
|
+
startup: z<boolean, boolean, "defined">;
|
|
47
61
|
}>>, Schemastery.ObjectT<NoInfer<{
|
|
48
62
|
/**
|
|
49
63
|
* Distro to preflight. Empty/`"auto"` follows the session workspace; an
|
|
@@ -62,6 +76,14 @@ export declare const Config: z<Schemastery.ObjectS<NoInfer<{
|
|
|
62
76
|
* that profile does not use.
|
|
63
77
|
*/
|
|
64
78
|
sessionSandbox: z<boolean, boolean, "defined">;
|
|
79
|
+
/**
|
|
80
|
+
* Whether the same checks also run once at plugin load — install + restart —
|
|
81
|
+
* against the pinned or WSL-default distro, so the verdict is in the log
|
|
82
|
+
* before any session opens. Sessions on other distros are still checked at
|
|
83
|
+
* open, and a session announcement for a message the load pass already
|
|
84
|
+
* logged skips the duplicate log line but keeps its runtime-context entry.
|
|
85
|
+
*/
|
|
86
|
+
startup: z<boolean, boolean, "defined">;
|
|
65
87
|
}>>, "plain">;
|
|
66
88
|
/** The config schema's validated output. */
|
|
67
89
|
export interface PreflightConfig {
|
|
@@ -73,6 +95,8 @@ export interface PreflightConfig {
|
|
|
73
95
|
sandbox?: boolean;
|
|
74
96
|
/** Whether the session-runtime prerequisites are preflighted too. */
|
|
75
97
|
sessionSandbox?: boolean;
|
|
98
|
+
/** Whether the checks also run once at plugin load, before any session. */
|
|
99
|
+
startup?: boolean;
|
|
76
100
|
}
|
|
77
101
|
/**
|
|
78
102
|
* The slice of a created agent this service inspects; the harness's agent
|
package/lib/preflight.js
CHANGED
|
@@ -11,6 +11,12 @@
|
|
|
11
11
|
* command after it pays nothing. Nothing else changes: the failure semantics
|
|
12
12
|
* stay exactly as fail-closed as before, this service only MOVES THE NEWS.
|
|
13
13
|
*
|
|
14
|
+
* The same probes also run once at plugin load (`startup`, on by default) so an
|
|
15
|
+
* install-plus-restart already carries the verdict in the log — the pinned or
|
|
16
|
+
* WSL-default distro — before the first session opens. A session on that distro
|
|
17
|
+
* repeats only the runtime-context entry; other distros keep the session-open
|
|
18
|
+
* check unchanged.
|
|
19
|
+
*
|
|
14
20
|
* Advisory by construction. A preflight that cannot run (no WSL, a wedged
|
|
15
21
|
* `wsl.exe`) degrades to a log line; it must never fail a session that has not
|
|
16
22
|
* even asked for confinement yet. It also never installs anything: the remedy
|
|
@@ -29,6 +35,7 @@ import { defaultDistro, runCapture } from "./wsl.js";
|
|
|
29
35
|
import { distroOfUnc, isDefaultDistro, pinnedDistro } from "./distro-route.js";
|
|
30
36
|
import { bwrapFailure, bwrapUsable, missingBwrapRemedy } from "./sandbox-core.js";
|
|
31
37
|
import { sessionScopeProblem, sessionScopeProbeScript, sessionScopeSweepScript } from "./session-scope.js";
|
|
38
|
+
import { installMessagesLocale } from "./messages.js";
|
|
32
39
|
export const name = "wsl-preflight";
|
|
33
40
|
export const Config = z.object({
|
|
34
41
|
/**
|
|
@@ -48,6 +55,14 @@ export const Config = z.object({
|
|
|
48
55
|
* that profile does not use.
|
|
49
56
|
*/
|
|
50
57
|
sessionSandbox: z.boolean().default(true),
|
|
58
|
+
/**
|
|
59
|
+
* Whether the same checks also run once at plugin load — install + restart —
|
|
60
|
+
* against the pinned or WSL-default distro, so the verdict is in the log
|
|
61
|
+
* before any session opens. Sessions on other distros are still checked at
|
|
62
|
+
* open, and a session announcement for a message the load pass already
|
|
63
|
+
* logged skips the duplicate log line but keeps its runtime-context entry.
|
|
64
|
+
*/
|
|
65
|
+
startup: z.boolean().default(true),
|
|
51
66
|
});
|
|
52
67
|
/** Distros whose stale-scope sweep has already run in this process. */
|
|
53
68
|
const sweptDistros = new Set();
|
|
@@ -75,6 +90,10 @@ const sweepStaleScopes = (wslPath, distro) => {
|
|
|
75
90
|
* @param config - the schema-validated plugin config.
|
|
76
91
|
*/
|
|
77
92
|
export async function apply(ctx, config = {}) {
|
|
93
|
+
// Before the sandbox early return: the advisories' language follows the
|
|
94
|
+
// harness locale even when this profile runs without the preflight's own
|
|
95
|
+
// probes (the shell and fs rows install the same wiring themselves).
|
|
96
|
+
installMessagesLocale(ctx);
|
|
78
97
|
if (!(config.sandbox ?? true))
|
|
79
98
|
return;
|
|
80
99
|
const wslPath = config.wslPath ?? "wsl.exe";
|
|
@@ -88,9 +107,10 @@ export async function apply(ctx, config = {}) {
|
|
|
88
107
|
*
|
|
89
108
|
* @param agent - the session that just opened.
|
|
90
109
|
* @param message - the advisory, remedy included.
|
|
110
|
+
* @param level - `warn` for a blocked environment (the historical shape); `info` for the ready line, which is confirmation, not a complaint.
|
|
91
111
|
*/
|
|
92
|
-
const announce = (agent, message) => {
|
|
93
|
-
|
|
112
|
+
const announce = (agent, message, level = "warn") => {
|
|
113
|
+
announceLog(message, level);
|
|
94
114
|
const agentCtx = agent.ctx;
|
|
95
115
|
if (agentCtx === undefined || typeof agentCtx.inject !== "function")
|
|
96
116
|
return;
|
|
@@ -103,6 +123,26 @@ export async function apply(ctx, config = {}) {
|
|
|
103
123
|
ctx.logger?.debug?.(`wsl-preflight: could not publish the notice to the session (${error?.message ?? error})`);
|
|
104
124
|
}
|
|
105
125
|
};
|
|
126
|
+
/** Messages the load pass already logged; a session announcement repeats only the entry. */
|
|
127
|
+
const startupLogged = new Set();
|
|
128
|
+
/**
|
|
129
|
+
* The log-only half of {@link announce}: a blocked environment warns, a ready
|
|
130
|
+
* verdict debugs. A message the startup pass already logged is skipped so the
|
|
131
|
+
* first session on that distro does not repeat the same line.
|
|
132
|
+
*
|
|
133
|
+
* @param message - the advisory or ready line.
|
|
134
|
+
* @param level - `warn` for a blocked environment; `info` for the ready line.
|
|
135
|
+
*/
|
|
136
|
+
const announceLog = (message, level) => {
|
|
137
|
+
if (startupLogged.has(message))
|
|
138
|
+
return;
|
|
139
|
+
if (level === "info") {
|
|
140
|
+
ctx.logger?.debug?.(message);
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
warn(message);
|
|
144
|
+
}
|
|
145
|
+
};
|
|
106
146
|
/**
|
|
107
147
|
* Ask the distro's session-runtime probe. Only a recognized refusal is a
|
|
108
148
|
* verdict: an empty or unfamiliar answer means "cannot tell" (a fixture, an
|
|
@@ -125,6 +165,40 @@ export async function apply(ctx, config = {}) {
|
|
|
125
165
|
return undefined;
|
|
126
166
|
}
|
|
127
167
|
};
|
|
168
|
+
/**
|
|
169
|
+
* Probe one distro and compose its verdict: the same shape the session-open
|
|
170
|
+
* check announces and the load pass logs. Concurrent callers share one flight
|
|
171
|
+
* (the mount-time load pass and a session opening during startup), so both
|
|
172
|
+
* read one verdict and the dedupe below lands exactly one log line; the entry
|
|
173
|
+
* is dropped once settled so later sessions re-probe fresh.
|
|
174
|
+
*
|
|
175
|
+
* @param distro - the resolved distro.
|
|
176
|
+
* @returns the message and its level.
|
|
177
|
+
*/
|
|
178
|
+
const inflight = new Map();
|
|
179
|
+
const verdictOf = (distro) => {
|
|
180
|
+
const shared = inflight.get(distro);
|
|
181
|
+
if (shared !== undefined)
|
|
182
|
+
return shared;
|
|
183
|
+
const flight = (async () => {
|
|
184
|
+
const usable = await bwrapUsable({ wslPath, distro });
|
|
185
|
+
if (!usable) {
|
|
186
|
+
return { message: `wsl-preflight: ${bwrapFailure(wslPath, distro) ?? missingBwrapRemedy(distro)}`, level: "warn" };
|
|
187
|
+
}
|
|
188
|
+
if (!(config.sessionSandbox ?? true)) {
|
|
189
|
+
return { message: `wsl-preflight: ready — bwrap is usable inside "${distro}" (the session scope is not checked: sessionSandbox: false)`, level: "info" };
|
|
190
|
+
}
|
|
191
|
+
const sessionProblem = await probeSession(distro);
|
|
192
|
+
if (sessionProblem !== undefined) {
|
|
193
|
+
return { message: `wsl-preflight: ${sessionProblem}`, level: "warn" };
|
|
194
|
+
}
|
|
195
|
+
return { message: `wsl-preflight: ready — bwrap and the session scope are usable inside "${distro}"`, level: "info" };
|
|
196
|
+
})();
|
|
197
|
+
inflight.set(distro, flight);
|
|
198
|
+
void flight.finally(() => { if (inflight.get(distro) === flight)
|
|
199
|
+
inflight.delete(distro); });
|
|
200
|
+
return flight;
|
|
201
|
+
};
|
|
128
202
|
/**
|
|
129
203
|
* Probe the distro once and surface an unusable `bwrap` as a warning.
|
|
130
204
|
*
|
|
@@ -160,19 +234,45 @@ export async function apply(ctx, config = {}) {
|
|
|
160
234
|
// Clean up what a hard crash left behind before this session creates its
|
|
161
235
|
// runtime; a live agent in another session's cgroup makes its scope safe.
|
|
162
236
|
sweepStaleScopes(wslPath, distro);
|
|
163
|
-
const
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
237
|
+
const { message, level } = await verdictOf(distro);
|
|
238
|
+
announce(agent, message, level);
|
|
239
|
+
};
|
|
240
|
+
/**
|
|
241
|
+
* The load pass: run the same probes once at mount — install + restart,
|
|
242
|
+
* before any session — against the pinned or WSL-default distro, and log the
|
|
243
|
+
* verdict. A session announcement for the same message then skips the
|
|
244
|
+
* duplicate log line but keeps its runtime-context entry. Advisory like every
|
|
245
|
+
* other arm: an unreachable distro degrades to a debug line.
|
|
246
|
+
*/
|
|
247
|
+
const startupCheck = async () => {
|
|
248
|
+
let distro = "";
|
|
249
|
+
try {
|
|
250
|
+
distro = pinnedDistro(config.distro) ?? await defaultDistro({ wslPath });
|
|
167
251
|
}
|
|
168
|
-
|
|
169
|
-
|
|
252
|
+
catch (error) {
|
|
253
|
+
ctx.logger?.debug?.(`wsl-preflight: no distro to preflight at load (${error?.message ?? error})`);
|
|
170
254
|
return;
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
255
|
+
}
|
|
256
|
+
try {
|
|
257
|
+
sweepStaleScopes(wslPath, distro);
|
|
258
|
+
const { message, level } = await verdictOf(distro);
|
|
259
|
+
// Mark first, log second: a session opening during the load pass reads
|
|
260
|
+
// the same flight and either order leaves exactly one log line.
|
|
261
|
+
startupLogged.add(message);
|
|
262
|
+
if (level === "info") {
|
|
263
|
+
ctx.logger?.debug?.(message);
|
|
264
|
+
}
|
|
265
|
+
else {
|
|
266
|
+
warn(message);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
catch (error) {
|
|
270
|
+
ctx.logger?.debug?.(`wsl-preflight: the load pass could not run (${error?.message ?? error})`);
|
|
271
|
+
}
|
|
174
272
|
};
|
|
175
273
|
ctx.on("agent/created", (payload) => void check(payload?.agent));
|
|
274
|
+
if (config.startup ?? true)
|
|
275
|
+
void startupCheck();
|
|
176
276
|
// Mount order is not a guarantee: a session created during startup can finish
|
|
177
277
|
// before this service mounts and miss the event entirely (dsh-headless does
|
|
178
278
|
// exactly that, and auto-preset sweeps for the same reason).
|
package/lib/sandbox-core.js
CHANGED
|
@@ -20,6 +20,7 @@ import { createProbeCache } from "./probe-cache.js";
|
|
|
20
20
|
import { toLinuxPath } from "./paths.js";
|
|
21
21
|
import { runCapture } from "./wsl.js";
|
|
22
22
|
import { bwrapArgvPrefix } from "./bwrap.js";
|
|
23
|
+
import { t } from "./messages.js";
|
|
23
24
|
/**
|
|
24
25
|
* bwrap's denial dialect: a write outside the granted mounts fails with EROFS,
|
|
25
26
|
* whose message is "Read-only file system". Classified case-insensitively.
|
|
@@ -145,12 +146,10 @@ async function composeBwrapFailure(wslPath, distro, cause, signal) {
|
|
|
145
146
|
const kind = classifyProbeOutput(output);
|
|
146
147
|
if (kind === "broken") {
|
|
147
148
|
// A broken verdict requires the bwrap banner, so the output is never empty here.
|
|
148
|
-
return (
|
|
149
|
-
`This is usually the kernel (unprivileged user namespaces disabled) or an unusable bwrap build rather than a missing package, so reinstalling will not help. ` +
|
|
150
|
-
`Check \`wsl.exe -d ${distro} --exec bwrap --version\` inside the distro, or set \`sandbox: false\` on the wsl-shell and wsl-fs rows to run unconfined.`);
|
|
149
|
+
return t("bwrapBroken", { distro, output });
|
|
151
150
|
}
|
|
152
151
|
const remedy = missingBwrapRemedy(distro, await detectPackageFamily(wslPath, distro, signal));
|
|
153
|
-
return kind === "unknown" && output.length > 0 ? `${remedy}
|
|
152
|
+
return kind === "unknown" && output.length > 0 ? `${remedy}${t("bwrapProbeFailedSuffix", { output })}` : remedy;
|
|
154
153
|
}
|
|
155
154
|
/**
|
|
156
155
|
* The canonical remedy for a distro whose `bwrap` is missing — also the
|
|
@@ -165,14 +164,9 @@ async function composeBwrapFailure(wslPath, distro, cause, signal) {
|
|
|
165
164
|
*/
|
|
166
165
|
export function missingBwrapRemedy(distro, family) {
|
|
167
166
|
const direct = family === undefined ? undefined : FAMILY_INSTALL[family];
|
|
168
|
-
if (direct === undefined)
|
|
169
|
-
return (
|
|
170
|
-
|
|
171
|
-
`"bubblewrap" package with the distro's package manager.`);
|
|
172
|
-
}
|
|
173
|
-
return (`bwrap is not usable inside distro "${distro}". Install it with ` +
|
|
174
|
-
`"scripts/bootstrap.sh ${distro} --install" (from the package), or directly: ` +
|
|
175
|
-
`wsl.exe -d ${distro} -u root -- ${direct}`);
|
|
167
|
+
if (direct === undefined)
|
|
168
|
+
return t("bwrapMissingGeneric", { distro });
|
|
169
|
+
return t("bwrapMissingFamily", { distro, direct });
|
|
176
170
|
}
|
|
177
171
|
/**
|
|
178
172
|
* The remedy for a bwrap that PROBED healthy but failed a run — the runtime
|
|
@@ -184,8 +178,7 @@ export function missingBwrapRemedy(distro, family) {
|
|
|
184
178
|
* @returns the operator-facing hint text.
|
|
185
179
|
*/
|
|
186
180
|
export function bwrapInstallHint(distro) {
|
|
187
|
-
return (
|
|
188
|
-
`or reinstall it: "scripts/bootstrap.sh ${distro} --install".`);
|
|
181
|
+
return t("bwrapRuntimeFailure", { distro });
|
|
189
182
|
}
|
|
190
183
|
/**
|
|
191
184
|
* Append {@link bwrapInstallHint} to a runner-failure detail that names bwrap.
|
package/lib/session-scope.js
CHANGED
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
*
|
|
20
20
|
* @module dsh-plugin-wsl-env/session-scope
|
|
21
21
|
*/
|
|
22
|
+
import { t } from "./messages.js";
|
|
22
23
|
/** The longest piece of a unit name this builder emits, per component. */
|
|
23
24
|
const MAX_COMPONENT = 64;
|
|
24
25
|
/**
|
|
@@ -162,15 +163,19 @@ export function sessionScopeProblem({ output, distro }) {
|
|
|
162
163
|
case "ok":
|
|
163
164
|
return null;
|
|
164
165
|
case "no-systemd":
|
|
165
|
-
return
|
|
166
|
+
return t("sessionScopeNoSystemd", { distro });
|
|
166
167
|
case "no-user-manager":
|
|
167
|
-
return
|
|
168
|
+
return t("sessionScopeNoUserManager", { distro });
|
|
168
169
|
case "no-systemd-run":
|
|
169
|
-
return
|
|
170
|
+
return t("sessionScopeNoSystemdRun", { distro });
|
|
170
171
|
case "no-linger":
|
|
171
|
-
return
|
|
172
|
+
return t("sessionScopeNoLinger", { distro });
|
|
172
173
|
default:
|
|
173
|
-
return
|
|
174
|
+
return t("sessionScopeUnknownAnswer", {
|
|
175
|
+
distro,
|
|
176
|
+
answer: word === "" ? "(nothing)" : `"${word}"`,
|
|
177
|
+
errorSuffix: output.error === undefined ? "" : `: ${output.error}`,
|
|
178
|
+
});
|
|
174
179
|
}
|
|
175
180
|
}
|
|
176
181
|
/**
|
package/lib/shell-env.d.ts
CHANGED
|
@@ -28,6 +28,31 @@
|
|
|
28
28
|
*/
|
|
29
29
|
import z from "@deepseek-ai/schemastery";
|
|
30
30
|
import type { Context } from "@deepseek-ai/cordis";
|
|
31
|
+
/**
|
|
32
|
+
* One Windows path as the POSIX side sees it through the default automount
|
|
33
|
+
* (`C:\a\b` → `/mnt/c/a/b`). The doctor command names the app's own runtime
|
|
34
|
+
* this way, because it is executed by the distro's shell through interop.
|
|
35
|
+
* A moved automount root is the `distro.wsl-conf-automount` check's finding,
|
|
36
|
+
* not this mapping's problem to guess.
|
|
37
|
+
* @param p - the Windows path.
|
|
38
|
+
* @returns the POSIX form for a `C:`-drive path; anything else passes through.
|
|
39
|
+
*/
|
|
40
|
+
export declare function windowsToPosix(p: string): string;
|
|
41
|
+
/**
|
|
42
|
+
* The `DSH_WSL_DOCTOR` value: a ready-to-run POSIX-sh command that executes
|
|
43
|
+
* the plugin's doctor from inside a distro session. The interpreter is the
|
|
44
|
+
* app's own runtime in Node mode (`ELECTRON_RUN_AS_NODE=1` — the same
|
|
45
|
+
* mechanism the probe suite uses for headless CLI runs), reached through
|
|
46
|
+
* interop at its `/mnt/...` path; the script stays a Windows path because
|
|
47
|
+
* the runtime is a Windows binary and interop translates arguments for
|
|
48
|
+
* nothing. `WSLENV` is inlined so the flag actually crosses the boundary.
|
|
49
|
+
* Windows hosts only: the whole mechanism is the interop path.
|
|
50
|
+
* @param execPath - `process.execPath` in the app process (the runtime binary).
|
|
51
|
+
* @param pluginRoot - the plugin's installed root (holding `scripts/doctor.mjs`).
|
|
52
|
+
* @param isWindows - `process.platform === "win32"` at the call site.
|
|
53
|
+
* @returns the command string, or undefined off Windows.
|
|
54
|
+
*/
|
|
55
|
+
export declare function doctorFact(execPath: string, pluginRoot: string, isWindows?: boolean): string | undefined;
|
|
31
56
|
export declare const name = "wsl-shell-env";
|
|
32
57
|
export declare const inject: string[];
|
|
33
58
|
export declare const Config: z<Schemastery.ObjectS<NoInfer<{
|
package/lib/shell-env.js
CHANGED
|
@@ -28,10 +28,50 @@
|
|
|
28
28
|
*/
|
|
29
29
|
import z from "@deepseek-ai/schemastery";
|
|
30
30
|
import { uncToPosix } from "./paths.js";
|
|
31
|
+
import { fileURLToPath } from "node:url";
|
|
32
|
+
import { dirname, join } from "node:path";
|
|
31
33
|
import { defaultDistro, defaultShell, linuxHomePath, listDistros } from "./wsl.js";
|
|
32
34
|
import { isDefaultDistro, pinnedDistro } from "./distro-route.js";
|
|
33
35
|
import { sharedAgent } from "./agent-shared.js";
|
|
34
36
|
import { scanListeningPorts } from "./ports.js";
|
|
37
|
+
import { currentUpdateFact, updateFactMessage } from "./update-check.js";
|
|
38
|
+
/**
|
|
39
|
+
* One Windows path as the POSIX side sees it through the default automount
|
|
40
|
+
* (`C:\a\b` → `/mnt/c/a/b`). The doctor command names the app's own runtime
|
|
41
|
+
* this way, because it is executed by the distro's shell through interop.
|
|
42
|
+
* A moved automount root is the `distro.wsl-conf-automount` check's finding,
|
|
43
|
+
* not this mapping's problem to guess.
|
|
44
|
+
* @param p - the Windows path.
|
|
45
|
+
* @returns the POSIX form for a `C:`-drive path; anything else passes through.
|
|
46
|
+
*/
|
|
47
|
+
export function windowsToPosix(p) {
|
|
48
|
+
const match = /^([A-Za-z]):[\\/](.*)$/.exec(p);
|
|
49
|
+
if (match === null)
|
|
50
|
+
return p;
|
|
51
|
+
return `/mnt/${(match[1] ?? "").toLowerCase()}/${(match[2] ?? "").replaceAll("\\", "/")}`;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* The `DSH_WSL_DOCTOR` value: a ready-to-run POSIX-sh command that executes
|
|
55
|
+
* the plugin's doctor from inside a distro session. The interpreter is the
|
|
56
|
+
* app's own runtime in Node mode (`ELECTRON_RUN_AS_NODE=1` — the same
|
|
57
|
+
* mechanism the probe suite uses for headless CLI runs), reached through
|
|
58
|
+
* interop at its `/mnt/...` path; the script stays a Windows path because
|
|
59
|
+
* the runtime is a Windows binary and interop translates arguments for
|
|
60
|
+
* nothing. `WSLENV` is inlined so the flag actually crosses the boundary.
|
|
61
|
+
* Windows hosts only: the whole mechanism is the interop path.
|
|
62
|
+
* @param execPath - `process.execPath` in the app process (the runtime binary).
|
|
63
|
+
* @param pluginRoot - the plugin's installed root (holding `scripts/doctor.mjs`).
|
|
64
|
+
* @param isWindows - `process.platform === "win32"` at the call site.
|
|
65
|
+
* @returns the command string, or undefined off Windows.
|
|
66
|
+
*/
|
|
67
|
+
export function doctorFact(execPath, pluginRoot, isWindows = process.platform === "win32") {
|
|
68
|
+
if (!isWindows)
|
|
69
|
+
return undefined;
|
|
70
|
+
const script = join(pluginRoot, "scripts", "doctor.mjs");
|
|
71
|
+
const existing = process.env.WSLENV;
|
|
72
|
+
const wslenv = existing !== undefined && existing.length > 0 ? `ELECTRON_RUN_AS_NODE:${existing}` : "ELECTRON_RUN_AS_NODE";
|
|
73
|
+
return `WSLENV="${wslenv}" ELECTRON_RUN_AS_NODE=1 '${windowsToPosix(execPath)}' '${script}'`;
|
|
74
|
+
}
|
|
35
75
|
export const name = "wsl-shell-env";
|
|
36
76
|
export const inject = ["shellEnv"];
|
|
37
77
|
export const Config = z.object({
|
|
@@ -100,6 +140,7 @@ export async function apply(ctx, config = {}) {
|
|
|
100
140
|
const initial = pinned ?? defaultName;
|
|
101
141
|
if (initial !== undefined)
|
|
102
142
|
await ensureFacts(initial);
|
|
143
|
+
let doctorFactValue;
|
|
103
144
|
const variables = {
|
|
104
145
|
DSH_WSL_DISTRO: {
|
|
105
146
|
description: "Name of the WSL distro this session's workspace lives in.",
|
|
@@ -113,6 +154,12 @@ export async function apply(ctx, config = {}) {
|
|
|
113
154
|
DSH_WSL_PORTS: {
|
|
114
155
|
description: `Ports with a listener inside that distro (comma-separated, ascending), as of the last snapshot — refreshed every ${Math.round(portsRefreshMs / 1000)}s, so a dev server started moments ago may not be listed yet. Empty means none were listening at the last successful scan (or no scan has succeeded yet); a failed scan keeps the last successful list.`,
|
|
115
156
|
},
|
|
157
|
+
DSH_WSL_PLUGIN_UPDATE: {
|
|
158
|
+
description: "A newer release of this plugin (dsh-plugin-wsl-env), as of the last update check — checked against the registry about once a day. Empty means the installed version is current (or the check has not run yet). Applying it is manual: the Plugins page's Versions section, or `dsh plugin --profile <name> add dsh-plugin-wsl-env`, then restart DSH.",
|
|
159
|
+
},
|
|
160
|
+
DSH_WSL_DOCTOR: {
|
|
161
|
+
description: "Ready-to-run command that executes this plugin's environment doctor (scripts/doctor.mjs) from inside a session, using the app's own runtime as Node — no terminal or separate Node install needed. Run it as: sh -c \"$DSH_WSL_DOCTOR --json\" (drop --json for the human report). The output ends in a verdict (ready, or blocked with per-failure copy-paste remedies).",
|
|
162
|
+
},
|
|
116
163
|
};
|
|
117
164
|
// The port snapshot refreshes on a timer and is served synchronously: the
|
|
118
165
|
// registry's resolve is sync by contract, so live reads are impossible —
|
|
@@ -180,11 +227,20 @@ export async function apply(ctx, config = {}) {
|
|
|
180
227
|
if (isDefaultDistro(configured) && defaultName !== undefined && named.toLowerCase() !== defaultName.toLowerCase())
|
|
181
228
|
return {};
|
|
182
229
|
const canonical = [...facts.keys()].find((distro) => distro.toLowerCase() === named.toLowerCase()) ?? named;
|
|
230
|
+
const doctorCommand = doctorFactValue ?? doctorFact(process.execPath, dirname(dirname(fileURLToPath(import.meta.url))));
|
|
231
|
+
doctorFactValue = doctorCommand;
|
|
183
232
|
const known = facts.get(canonical);
|
|
184
233
|
ensurePorts(canonical);
|
|
185
234
|
const resolved = {
|
|
186
235
|
DSH_WSL_DISTRO: canonical,
|
|
187
236
|
DSH_WSL_PORTS: (ports.get(canonical) ?? []).join(","),
|
|
237
|
+
// The update fact is distro-agnostic, but the sessions this row serves
|
|
238
|
+
// are exactly the distro ones, so it rides the same accepted-branch —
|
|
239
|
+
// the timer-fed state is read synchronously, like the ports snapshot.
|
|
240
|
+
DSH_WSL_PLUGIN_UPDATE: updateFactMessage(currentUpdateFact()),
|
|
241
|
+
// The doctor command is host-shaped (Windows paths), so it exists only
|
|
242
|
+
// where the interop mechanism exists; elsewhere the key stays absent.
|
|
243
|
+
...(doctorCommand === undefined ? {} : { DSH_WSL_DOCTOR: doctorCommand }),
|
|
188
244
|
};
|
|
189
245
|
if (known?.home !== undefined)
|
|
190
246
|
resolved.DSH_WSL_HOME = known.home;
|
package/lib/shell.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* `ctx.shell`
|
|
2
|
+
* `ctx.shell` executor for the WSL agent preset — load as
|
|
3
|
+
* `dsh-plugin-wsl-env/shell` (before 0.20.0 the package root resolved here;
|
|
4
|
+
* the root is now the no-op web client host half, see `src/client-host.ts`).
|
|
3
5
|
*
|
|
4
6
|
* This is a TypeScript source built to `lib/shell.js`; edit THIS file and run
|
|
5
7
|
* `pnpm run build` — the artifact under `lib/` is generated, and `pnpm test`
|
package/lib/shell.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* `ctx.shell`
|
|
2
|
+
* `ctx.shell` executor for the WSL agent preset — load as
|
|
3
|
+
* `dsh-plugin-wsl-env/shell` (before 0.20.0 the package root resolved here;
|
|
4
|
+
* the root is now the no-op web client host half, see `src/client-host.ts`).
|
|
3
5
|
*
|
|
4
6
|
* This is a TypeScript source built to `lib/shell.js`; edit THIS file and run
|
|
5
7
|
* `pnpm run build` — the artifact under `lib/` is generated, and `pnpm test`
|
|
@@ -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 {};
|