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.
- package/CHANGELOG.md +274 -0
- package/CONTRIBUTING.md +37 -5
- package/README.md +60 -5
- package/SUPPORT.md +3 -3
- package/agent/native/linux-aarch64/dsh-wsl-agent +0 -0
- package/agent/native/linux-x86_64/dsh-wsl-agent +0 -0
- package/agent/wsl-agent.sh +331 -11
- package/client.d.ts +5 -0
- package/client.js +98 -0
- package/cordis.patch.yml +66 -1
- package/docs/AGENT-PROTOCOL-V7.md +175 -0
- package/docs/API.md +25 -0
- package/docs/ARCHITECTURE.md +14 -1
- package/docs/CONFIGURATION.md +47 -6
- package/docs/CONFIGURATION.zh.md +20 -4
- package/docs/DIAGNOSTICS.md +83 -0
- package/docs/DIAGNOSTICS.zh.md +73 -0
- package/docs/LIMITATIONS.md +41 -4
- package/docs/LIMITATIONS.zh.md +27 -11
- package/docs/MIGRATION.md +4 -4
- package/docs/PEER-PARITY.md +50 -33
- package/docs/QUICKSTART.md +37 -4
- package/docs/QUICKSTART.zh.md +16 -1
- package/docs/README.zh.md +43 -4
- package/docs/RELEASING.md +4 -1
- package/docs/REQUIREMENTS.zh.md +3 -2
- package/docs/ROADMAP-1.0.md +75 -19
- package/docs/UPSTREAM-FILE-REFERENCE-SEAM.md +8 -1
- package/docs/UPSTREAM-OPEN-IN-APP.md +33 -0
- package/docs/UPSTREAM-SESSION-NOTICE.md +3 -1
- package/docs/UPSTREAM-TERMINAL-TITLE.md +3 -0
- package/docs/root-fs-routing.md +3 -3
- package/lib/agent-confined.js +4 -4
- package/lib/agent-errors.d.ts +1 -1
- package/lib/agent-errors.js +1 -1
- package/lib/agent-exec.d.ts +1 -1
- package/lib/agent-exec.js +1 -1
- package/lib/agent-protocol.d.ts +58 -8
- package/lib/agent-protocol.js +40 -7
- package/lib/agent-shared.d.ts +1 -1
- package/lib/agent-shared.js +1 -1
- package/lib/agent.d.ts +171 -1
- package/lib/agent.js +448 -288
- package/lib/auto-preset.d.ts +1 -1
- package/lib/auto-preset.js +1 -1
- package/lib/bwrap.d.ts +1 -1
- package/lib/bwrap.js +1 -1
- 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/distro-route.d.ts +1 -1
- package/lib/distro-route.js +1 -1
- package/lib/doctor-live.d.ts +57 -0
- package/lib/doctor-live.js +38 -0
- package/lib/file-reference-wsl.d.ts +1 -1
- package/lib/file-reference-wsl.js +1 -1
- package/lib/fs-decisions.d.ts +1 -1
- package/lib/fs-decisions.js +1 -1
- package/lib/fs-routing.d.ts +1 -1
- package/lib/fs-routing.js +1 -1
- package/lib/fs-substrate.d.ts +90 -11
- package/lib/fs-substrate.js +202 -1
- package/lib/fs.d.ts +1 -1
- package/lib/fs.js +1 -1
- package/lib/fsio-agent.d.ts +128 -4
- package/lib/fsio-agent.js +224 -15
- package/lib/fsio-text.d.ts +1 -1
- package/lib/fsio-text.js +1 -1
- package/lib/git-exec.d.ts +1 -1
- package/lib/git-exec.js +1 -1
- package/lib/git-route.d.ts +1 -1
- package/lib/git-route.js +1 -1
- package/lib/index.d.ts +105 -30
- package/lib/index.js +272 -130
- package/lib/listing.d.ts +1 -1
- package/lib/listing.js +1 -1
- package/lib/messages.d.ts +157 -0
- package/lib/messages.js +199 -0
- package/lib/native-agent.d.ts +1 -1
- package/lib/native-agent.js +2 -2
- package/lib/paths.d.ts +6 -3
- package/lib/paths.js +4 -4
- package/lib/picker.d.ts +1 -1
- package/lib/picker.js +7 -7
- package/lib/ports.d.ts +1 -1
- package/lib/ports.js +1 -1
- package/lib/preflight.d.ts +25 -1
- package/lib/preflight.js +112 -12
- package/lib/sandbox-core.d.ts +1 -1
- package/lib/sandbox-core.js +9 -16
- package/lib/sandbox.d.ts +1 -1
- package/lib/sandbox.js +1 -1
- package/lib/search-exec.d.ts +1 -1
- package/lib/search-exec.js +1 -1
- package/lib/search-route.d.ts +1 -1
- package/lib/search-route.js +1 -1
- package/lib/session-runtime.d.ts +1 -1
- package/lib/session-runtime.js +2 -2
- package/lib/session-scope.d.ts +1 -1
- package/lib/session-scope.js +11 -6
- package/lib/shell-env.d.ts +26 -1
- package/lib/shell-env.js +57 -1
- package/lib/shell.d.ts +4 -2
- package/lib/shell.js +4 -2
- package/lib/subprocess.d.ts +1 -1
- package/lib/subprocess.js +2 -2
- package/lib/terminal-activity.d.ts +1 -1
- package/lib/terminal-activity.js +1 -1
- package/lib/terminal-route.d.ts +1 -1
- package/lib/terminal-route.js +1 -1
- package/lib/update-check.d.ts +197 -0
- package/lib/update-check.js +211 -0
- package/lib/watcher.d.ts +1 -1
- package/lib/watcher.js +1 -1
- package/lib/wsl-doctor-tool.d.ts +122 -0
- package/lib/wsl-doctor-tool.js +161 -0
- package/lib/wsl.d.ts +1 -31
- package/lib/wsl.js +1 -21
- package/package.json +55 -6
- package/scripts/doctor.mjs +1196 -166
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
|
|
@@ -21,7 +27,7 @@
|
|
|
21
27
|
* run `pnpm run build` — the artifact under `lib/` is generated, and
|
|
22
28
|
* `pnpm test` fails when it drifts.
|
|
23
29
|
*
|
|
24
|
-
* @module dsh-plugin-wsl/preflight
|
|
30
|
+
* @module dsh-plugin-wsl-env/preflight
|
|
25
31
|
*/
|
|
26
32
|
import z from "@deepseek-ai/schemastery";
|
|
27
33
|
import { isWslUnc } from "./paths.js";
|
|
@@ -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.d.ts
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* and run `pnpm run build` — the artifact under `lib/` is generated, and
|
|
15
15
|
* `pnpm test` fails when it drifts.
|
|
16
16
|
*
|
|
17
|
-
* @module dsh-plugin-wsl/sandbox-core
|
|
17
|
+
* @module dsh-plugin-wsl-env/sandbox-core
|
|
18
18
|
*/
|
|
19
19
|
/**
|
|
20
20
|
* The canonical remedy for a distro whose `bwrap` is missing — also the
|
package/lib/sandbox-core.js
CHANGED
|
@@ -14,12 +14,13 @@
|
|
|
14
14
|
* and run `pnpm run build` — the artifact under `lib/` is generated, and
|
|
15
15
|
* `pnpm test` fails when it drifts.
|
|
16
16
|
*
|
|
17
|
-
* @module dsh-plugin-wsl/sandbox-core
|
|
17
|
+
* @module dsh-plugin-wsl-env/sandbox-core
|
|
18
18
|
*/
|
|
19
19
|
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.
|
|
@@ -295,7 +288,7 @@ export function createSandboxCore({ SandboxUnavailableError }) {
|
|
|
295
288
|
if (!(await this.usable(distro, signal))) {
|
|
296
289
|
throw new SandboxUnavailableError(policy.mode, bwrapFailure(this.wslPath, distro) ?? missingBwrapRemedy(distro));
|
|
297
290
|
}
|
|
298
|
-
const workspaceRoot = toLinuxPath(policy.workspaceRoot
|
|
291
|
+
const workspaceRoot = toLinuxPath(policy.workspaceRoot);
|
|
299
292
|
const prefix = bwrapArgvPrefix({ ...policy, workspaceRoot }, { maskWindowsDrive: this.maskWindowsDrive });
|
|
300
293
|
return {
|
|
301
294
|
argv: [...prefix, ...argv],
|
package/lib/sandbox.d.ts
CHANGED
package/lib/sandbox.js
CHANGED
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
* `pnpm run build` — the artifact under `lib/` is generated, and `pnpm test`
|
|
35
35
|
* fails when it drifts.
|
|
36
36
|
*
|
|
37
|
-
* @module dsh-plugin-wsl/sandbox
|
|
37
|
+
* @module dsh-plugin-wsl-env/sandbox
|
|
38
38
|
*/
|
|
39
39
|
import { SandboxUnavailableError } from "@deepseek-ai/dsh-sandbox";
|
|
40
40
|
import { createSandboxCore } from "./sandbox-core.js";
|
package/lib/search-exec.d.ts
CHANGED
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
* run `pnpm run build` — the artifact under `lib/` is generated, and `pnpm test`
|
|
28
28
|
* fails when it drifts.
|
|
29
29
|
*
|
|
30
|
-
* @module dsh-plugin-wsl/search-exec
|
|
30
|
+
* @module dsh-plugin-wsl-env/search-exec
|
|
31
31
|
*/
|
|
32
32
|
import type { AgentExecRunner } from "./agent-exec.js";
|
|
33
33
|
/**
|
package/lib/search-exec.js
CHANGED
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
* run `pnpm run build` — the artifact under `lib/` is generated, and `pnpm test`
|
|
28
28
|
* fails when it drifts.
|
|
29
29
|
*
|
|
30
|
-
* @module dsh-plugin-wsl/search-exec
|
|
30
|
+
* @module dsh-plugin-wsl-env/search-exec
|
|
31
31
|
*/
|
|
32
32
|
import { AgentUnavailableError } from "./agent-errors.js";
|
|
33
33
|
/**
|
package/lib/search-route.d.ts
CHANGED
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
* and run `pnpm run build` — the artifact under `lib/` is generated, and
|
|
38
38
|
* `pnpm test` fails when it drifts.
|
|
39
39
|
*
|
|
40
|
-
* @module dsh-plugin-wsl/search-route
|
|
40
|
+
* @module dsh-plugin-wsl-env/search-route
|
|
41
41
|
*/
|
|
42
42
|
/**
|
|
43
43
|
* Whether a spawn's program is the ripgrep binary.
|
package/lib/search-route.js
CHANGED
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
* and run `pnpm run build` — the artifact under `lib/` is generated, and
|
|
38
38
|
* `pnpm test` fails when it drifts.
|
|
39
39
|
*
|
|
40
|
-
* @module dsh-plugin-wsl/search-route
|
|
40
|
+
* @module dsh-plugin-wsl-env/search-route
|
|
41
41
|
*/
|
|
42
42
|
import { uncToPosix } from "./paths.js";
|
|
43
43
|
/** The one program this rewrite passes through to the distro. */
|
package/lib/session-runtime.d.ts
CHANGED
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
* file and run `pnpm run build` — the artifact under `lib/` is generated, and
|
|
23
23
|
* `pnpm test` fails when it drifts.
|
|
24
24
|
*
|
|
25
|
-
* @module dsh-plugin-wsl/session-runtime
|
|
25
|
+
* @module dsh-plugin-wsl-env/session-runtime
|
|
26
26
|
*/
|
|
27
27
|
import { WslAgent } from "./agent.js";
|
|
28
28
|
/**
|
package/lib/session-runtime.js
CHANGED
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
* file and run `pnpm run build` — the artifact under `lib/` is generated, and
|
|
23
23
|
* `pnpm test` fails when it drifts.
|
|
24
24
|
*
|
|
25
|
-
* @module dsh-plugin-wsl/session-runtime
|
|
25
|
+
* @module dsh-plugin-wsl-env/session-runtime
|
|
26
26
|
*/
|
|
27
27
|
import { spawn } from "node:child_process";
|
|
28
28
|
import { randomUUID } from "node:crypto";
|
|
@@ -165,7 +165,7 @@ export class SessionRuntimes {
|
|
|
165
165
|
const unit = sessionScopeUnit(request.distro, this.token());
|
|
166
166
|
const prefix = sessionScopePrefix(unit);
|
|
167
167
|
if (request.mode !== "danger-full-access") {
|
|
168
|
-
prefix.push(...bwrapArgvPrefix({ mode: request.mode, workspaceRoot: toLinuxPath(request.workspaceRoot
|
|
168
|
+
prefix.push(...bwrapArgvPrefix({ mode: request.mode, workspaceRoot: toLinuxPath(request.workspaceRoot) }, { maskWindowsDrive: request.maskWindowsDrive, realTmp: true, pidNamespace: false }));
|
|
169
169
|
}
|
|
170
170
|
const agent = this.spawnAgent({
|
|
171
171
|
distro: request.distro,
|
package/lib/session-scope.d.ts
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
* and run `pnpm run build` — the artifact under `lib/` is generated, and
|
|
18
18
|
* `pnpm test` fails when it drifts.
|
|
19
19
|
*
|
|
20
|
-
* @module dsh-plugin-wsl/session-scope
|
|
20
|
+
* @module dsh-plugin-wsl-env/session-scope
|
|
21
21
|
*/
|
|
22
22
|
/**
|
|
23
23
|
* Build the systemd user unit name for one session runtime.
|
package/lib/session-scope.js
CHANGED
|
@@ -17,8 +17,9 @@
|
|
|
17
17
|
* and run `pnpm run build` — the artifact under `lib/` is generated, and
|
|
18
18
|
* `pnpm test` fails when it drifts.
|
|
19
19
|
*
|
|
20
|
-
* @module dsh-plugin-wsl/session-scope
|
|
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
|
@@ -24,10 +24,35 @@
|
|
|
24
24
|
* run `pnpm run build` — the artifact under `lib/` is generated, and `pnpm test`
|
|
25
25
|
* fails when it drifts.
|
|
26
26
|
*
|
|
27
|
-
* @module dsh-plugin-wsl/shell-env
|
|
27
|
+
* @module dsh-plugin-wsl-env/shell-env
|
|
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
|
@@ -24,14 +24,54 @@
|
|
|
24
24
|
* run `pnpm run build` — the artifact under `lib/` is generated, and `pnpm test`
|
|
25
25
|
* fails when it drifts.
|
|
26
26
|
*
|
|
27
|
-
* @module dsh-plugin-wsl/shell-env
|
|
27
|
+
* @module dsh-plugin-wsl-env/shell-env
|
|
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,10 +1,12 @@
|
|
|
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`
|
|
6
8
|
* fails when it drifts.
|
|
7
9
|
*
|
|
8
|
-
* @module dsh-plugin-wsl/shell
|
|
10
|
+
* @module dsh-plugin-wsl-env/shell
|
|
9
11
|
*/
|
|
10
12
|
export { WslShellExecutor as default, WslShellExecutor } from "./index.js";
|
package/lib/shell.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
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`
|
|
6
8
|
* fails when it drifts.
|
|
7
9
|
*
|
|
8
|
-
* @module dsh-plugin-wsl/shell
|
|
10
|
+
* @module dsh-plugin-wsl-env/shell
|
|
9
11
|
*/
|
|
10
12
|
export { WslShellExecutor as default, WslShellExecutor } from "./index.js";
|
package/lib/subprocess.d.ts
CHANGED
|
@@ -80,7 +80,7 @@
|
|
|
80
80
|
* run `pnpm run build` — the artifact under `lib/` is generated, and `pnpm test`
|
|
81
81
|
* fails when it drifts.
|
|
82
82
|
*
|
|
83
|
-
* @module dsh-plugin-wsl/subprocess
|
|
83
|
+
* @module dsh-plugin-wsl-env/subprocess
|
|
84
84
|
*/
|
|
85
85
|
import z from "@deepseek-ai/schemastery";
|
|
86
86
|
import { LocalSubprocessRuntime } from "@deepseek-ai/dsh-subprocess-local";
|
package/lib/subprocess.js
CHANGED
|
@@ -80,7 +80,7 @@
|
|
|
80
80
|
* run `pnpm run build` — the artifact under `lib/` is generated, and `pnpm test`
|
|
81
81
|
* fails when it drifts.
|
|
82
82
|
*
|
|
83
|
-
* @module dsh-plugin-wsl/subprocess
|
|
83
|
+
* @module dsh-plugin-wsl-env/subprocess
|
|
84
84
|
*/
|
|
85
85
|
import { randomUUID } from "node:crypto";
|
|
86
86
|
import { Buffer } from "node:buffer";
|
|
@@ -224,7 +224,7 @@ export class WslSubprocessRuntime extends LocalSubprocessRuntime {
|
|
|
224
224
|
const mounted = windowsToLinuxMount(text);
|
|
225
225
|
if (mounted !== undefined)
|
|
226
226
|
return { distro, linuxCwd: mounted };
|
|
227
|
-
return { distro, linuxCwd: toLinuxPath(this.config.cwd
|
|
227
|
+
return { distro, linuxCwd: toLinuxPath(this.config.cwd) };
|
|
228
228
|
}
|
|
229
229
|
/**
|
|
230
230
|
* Open one interactive shell inside the distro over the host's PTY.
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
* file and run `pnpm run build` — the artifact under `lib/` is generated, and
|
|
34
34
|
* `pnpm test` fails when it drifts.
|
|
35
35
|
*
|
|
36
|
-
* @module dsh-plugin-wsl/terminal-activity
|
|
36
|
+
* @module dsh-plugin-wsl-env/terminal-activity
|
|
37
37
|
*/
|
|
38
38
|
import type { SubprocessTerminalHandle } from "@deepseek-ai/dsh-subprocess";
|
|
39
39
|
/** The env name that marks one terminal's process tree inside the distro. */
|
package/lib/terminal-activity.js
CHANGED
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
* file and run `pnpm run build` — the artifact under `lib/` is generated, and
|
|
34
34
|
* `pnpm test` fails when it drifts.
|
|
35
35
|
*
|
|
36
|
-
* @module dsh-plugin-wsl/terminal-activity
|
|
36
|
+
* @module dsh-plugin-wsl-env/terminal-activity
|
|
37
37
|
*/
|
|
38
38
|
/** The env name that marks one terminal's process tree inside the distro. */
|
|
39
39
|
export const TERMINAL_ID_ENV = "DSH_TERMINAL_ID";
|
package/lib/terminal-route.d.ts
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* and run `pnpm run build` — the artifact under `lib/` is generated, and
|
|
16
16
|
* `pnpm test` fails when it drifts.
|
|
17
17
|
*
|
|
18
|
-
* @module dsh-plugin-wsl/terminal-route
|
|
18
|
+
* @module dsh-plugin-wsl-env/terminal-route
|
|
19
19
|
*/
|
|
20
20
|
/**
|
|
21
21
|
* The route decision for one terminal launch.
|
package/lib/terminal-route.js
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* and run `pnpm run build` — the artifact under `lib/` is generated, and
|
|
16
16
|
* `pnpm test` fails when it drifts.
|
|
17
17
|
*
|
|
18
|
-
* @module dsh-plugin-wsl/terminal-route
|
|
18
|
+
* @module dsh-plugin-wsl-env/terminal-route
|
|
19
19
|
*/
|
|
20
20
|
import { isPosixAbsolute, uncToPosix, windowsToLinuxMount } from "./paths.js";
|
|
21
21
|
/**
|