dsh-plugin-wsl-env 0.24.0 → 0.26.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 +136 -0
- package/CODE_OF_CONDUCT.md +85 -0
- package/CODE_OF_CONDUCT.zh.md +85 -0
- package/CONTRIBUTING.md +19 -3
- package/CONTRIBUTING.zh.md +200 -0
- package/README.md +18 -6
- package/SECURITY.md +12 -0
- package/SECURITY.zh.md +108 -0
- package/SUPPORT.md +2 -0
- package/SUPPORT.zh.md +99 -0
- package/client.js +409 -8
- package/cordis.patch.yml +17 -0
- package/docs/AGENT-PROTOCOL-V7.md +2 -2
- package/docs/API.md +2 -0
- package/docs/API.zh.md +38 -0
- package/docs/ARCHITECTURE.md +30 -9
- package/docs/ARCHITECTURE.zh.md +511 -0
- package/docs/COMPATIBILITY.md +2 -0
- package/docs/COMPATIBILITY.zh.md +117 -0
- package/docs/CONFIGURATION.md +45 -2
- package/docs/CONFIGURATION.zh.md +39 -3
- package/docs/DIAGNOSTICS.md +12 -2
- package/docs/DIAGNOSTICS.zh.md +5 -1
- package/docs/LIMITATIONS.md +60 -9
- package/docs/LIMITATIONS.zh.md +45 -9
- package/docs/MIGRATION.md +6 -3
- package/docs/MIGRATION.zh.md +91 -0
- package/docs/PEER-PARITY.md +63 -51
- package/docs/PERFORMANCE.md +2 -0
- package/docs/PERFORMANCE.zh.md +59 -0
- package/docs/QUICKSTART.md +21 -6
- package/docs/QUICKSTART.zh.md +16 -4
- package/docs/README.zh.md +28 -19
- package/docs/RELEASING.md +19 -14
- package/docs/REQUIREMENTS.zh.md +6 -3
- package/docs/ROADMAP-1.0.md +1 -1
- package/docs/UPSTREAM-FILE-REFERENCE-SEAM.md +1 -1
- package/docs/UPSTREAM-FSIO-EXPORT.md +5 -4
- package/docs/UPSTREAM-OPEN-IN-APP.md +33 -11
- package/docs/UPSTREAM-PROMPT-ADAPTERS.md +85 -0
- package/docs/UPSTREAM-SESSION-NOTICE.md +7 -0
- package/docs/VALUE.md +146 -0
- package/docs/VALUE.zh.md +15 -13
- package/docs/root-fs-routing.md +1 -1
- package/lib/agent-confined.d.ts +7 -1
- package/lib/agent-confined.js +3 -3
- package/lib/auto-preset-seam.d.ts +45 -0
- package/lib/auto-preset-seam.js +47 -0
- package/lib/auto-preset.d.ts +33 -10
- package/lib/auto-preset.js +148 -44
- package/lib/bwrap.d.ts +14 -0
- package/lib/bwrap.js +11 -0
- package/lib/cwd-prompt.d.ts +41 -3
- package/lib/cwd-prompt.js +125 -8
- package/lib/doctor-live.d.ts +30 -0
- package/lib/doctor-live.js +37 -0
- package/lib/doctor-report.d.ts +50 -0
- package/lib/doctor-report.js +172 -0
- package/lib/fs-routing.d.ts +1 -1
- package/lib/fs-routing.js +1 -1
- package/lib/fs.d.ts +1 -1
- package/lib/fs.js +1 -1
- package/lib/index.d.ts +6 -1464
- package/lib/index.js +5 -2120
- package/lib/messages.d.ts +20 -1
- package/lib/messages.js +31 -3
- package/lib/open-in-app.d.ts +206 -0
- package/lib/open-in-app.js +300 -0
- package/lib/preflight.d.ts +7 -4
- package/lib/preflight.js +27 -13
- package/lib/preset-choice.d.ts +13 -0
- package/lib/preset-choice.js +18 -1
- package/lib/provider-common.d.ts +58 -0
- package/lib/provider-common.js +123 -0
- package/lib/sandbox-core.d.ts +1 -0
- package/lib/sandbox-core.js +4 -2
- package/lib/session-runtime.d.ts +7 -1
- package/lib/session-runtime.js +9 -2
- package/lib/shell.d.ts +1 -1
- package/lib/shell.js +1 -1
- package/lib/status.js +2 -1
- package/lib/writable-roots.d.ts +109 -0
- package/lib/writable-roots.js +257 -0
- package/lib/wsl-doctor-command.js +2 -1
- package/lib/wsl-doctor-tool.js +2 -2
- package/lib/wsl-filesystem.d.ts +692 -0
- package/lib/wsl-filesystem.js +897 -0
- package/lib/wsl-shell.d.ts +742 -0
- package/lib/wsl-shell.js +965 -0
- package/lib/wsl.d.ts +1 -1
- package/lib/wsl.js +1 -1
- package/package.json +48 -24
- package/scripts/doctor.mjs +1 -1
- package/scripts/profile-preset.mjs +17 -5
package/lib/preflight.js
CHANGED
|
@@ -14,8 +14,9 @@
|
|
|
14
14
|
* The same probes also run once at plugin load (`startup`, on by default) so an
|
|
15
15
|
* install-plus-restart already carries the verdict in the log — the pinned or
|
|
16
16
|
* WSL-default distro — before the first session opens. A session on that distro
|
|
17
|
-
* repeats only the runtime-context entry;
|
|
18
|
-
*
|
|
17
|
+
* repeats only a failing verdict as the runtime-context entry; a ready verdict
|
|
18
|
+
* stays in the log, because "the prerequisite is usable" is not an action the
|
|
19
|
+
* model needs to take. Other distros keep the session-open check unchanged.
|
|
19
20
|
*
|
|
20
21
|
* Advisory by construction. A preflight that cannot run (no WSL, a wedged
|
|
21
22
|
* `wsl.exe`) degrades to a log line; it must never fail a session that has not
|
|
@@ -60,12 +61,22 @@ export const Config = z.object({
|
|
|
60
61
|
* against the pinned or WSL-default distro, so the verdict is in the log
|
|
61
62
|
* before any session opens. Sessions on other distros are still checked at
|
|
62
63
|
* open, and a session announcement for a message the load pass already
|
|
63
|
-
* logged skips the duplicate log line
|
|
64
|
+
* logged skips the duplicate log line; a failing verdict still lands as the
|
|
65
|
+
* session's runtime-context entry.
|
|
64
66
|
*/
|
|
65
67
|
startup: z.boolean().default(true),
|
|
66
68
|
});
|
|
67
69
|
/** Distros whose stale-scope sweep has already run in this process. */
|
|
68
70
|
const sweptDistros = new Set();
|
|
71
|
+
/** The one instruction a blocked remedy needs; the model must not install packages unasked. */
|
|
72
|
+
const OPERATOR = "operator action: ask the user before running a remedy";
|
|
73
|
+
/**
|
|
74
|
+
* Mark a blocked verdict's remedy as user-owned action.
|
|
75
|
+
*
|
|
76
|
+
* @param message - the composed problem and remedy.
|
|
77
|
+
* @returns the model-facing sentence.
|
|
78
|
+
*/
|
|
79
|
+
const blocked = (message) => `${message.replace(/[.\s]+$/u, "")} (${OPERATOR}).`;
|
|
69
80
|
/**
|
|
70
81
|
* Stop `dsh-wsl-*.scope` units a crashed app left behind. A scope is stale
|
|
71
82
|
* when its cgroup has no `wsl-agent.sh`; a live agent means another session
|
|
@@ -99,18 +110,20 @@ export async function apply(ctx, config = {}) {
|
|
|
99
110
|
const wslPath = config.wslPath ?? "wsl.exe";
|
|
100
111
|
const warn = (message) => ctx.logger?.warn?.(message);
|
|
101
112
|
/**
|
|
102
|
-
* Publish one advisory: the log line always, plus — when the
|
|
103
|
-
* the agent's `systemPrompt` — a
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
113
|
+
* Publish one advisory: the log line always, plus — when the verdict is
|
|
114
|
+
* blocked and the harness exposes the agent's `systemPrompt` — a
|
|
115
|
+
* session-scoped runtime-context entry, so the failure is visible to the
|
|
116
|
+
* session instead of only in the app log. A ready verdict is log-only: it is
|
|
117
|
+
* not an action and does not belong in the model's context.
|
|
107
118
|
*
|
|
108
119
|
* @param agent - the session that just opened.
|
|
109
120
|
* @param message - the advisory, remedy included.
|
|
110
|
-
* @param level - `warn` for a blocked environment
|
|
121
|
+
* @param level - `warn` for a blocked environment; `info` for the ready line, which is confirmation, not a complaint.
|
|
111
122
|
*/
|
|
112
123
|
const announce = (agent, message, level = "warn") => {
|
|
113
124
|
announceLog(message, level);
|
|
125
|
+
if (level !== "warn")
|
|
126
|
+
return;
|
|
114
127
|
const agentCtx = agent.ctx;
|
|
115
128
|
if (agentCtx === undefined || typeof agentCtx.inject !== "function")
|
|
116
129
|
return;
|
|
@@ -123,7 +136,7 @@ export async function apply(ctx, config = {}) {
|
|
|
123
136
|
ctx.logger?.debug?.(`wsl-preflight: could not publish the notice to the session (${error?.message ?? error})`);
|
|
124
137
|
}
|
|
125
138
|
};
|
|
126
|
-
/** Messages the load pass already logged; a session announcement repeats only
|
|
139
|
+
/** Messages the load pass already logged; a session announcement repeats only a blocked entry. */
|
|
127
140
|
const startupLogged = new Set();
|
|
128
141
|
/**
|
|
129
142
|
* The log-only half of {@link announce}: a blocked environment warns, a ready
|
|
@@ -183,14 +196,14 @@ export async function apply(ctx, config = {}) {
|
|
|
183
196
|
const flight = (async () => {
|
|
184
197
|
const usable = await bwrapUsable({ wslPath, distro });
|
|
185
198
|
if (!usable) {
|
|
186
|
-
return { message: `wsl-preflight: ${bwrapFailure(wslPath, distro) ?? missingBwrapRemedy(distro)}
|
|
199
|
+
return { message: blocked(`wsl-preflight: ${bwrapFailure(wslPath, distro) ?? missingBwrapRemedy(distro)}`), level: "warn" };
|
|
187
200
|
}
|
|
188
201
|
if (!(config.sessionSandbox ?? true)) {
|
|
189
202
|
return { message: `wsl-preflight: ready — bwrap is usable inside "${distro}" (the session scope is not checked: sessionSandbox: false)`, level: "info" };
|
|
190
203
|
}
|
|
191
204
|
const sessionProblem = await probeSession(distro);
|
|
192
205
|
if (sessionProblem !== undefined) {
|
|
193
|
-
return { message: `wsl-preflight: ${sessionProblem}
|
|
206
|
+
return { message: blocked(`wsl-preflight: ${sessionProblem}`), level: "warn" };
|
|
194
207
|
}
|
|
195
208
|
return { message: `wsl-preflight: ready — bwrap and the session scope are usable inside "${distro}"`, level: "info" };
|
|
196
209
|
})();
|
|
@@ -241,7 +254,8 @@ export async function apply(ctx, config = {}) {
|
|
|
241
254
|
* The load pass: run the same probes once at mount — install + restart,
|
|
242
255
|
* before any session — against the pinned or WSL-default distro, and log the
|
|
243
256
|
* verdict. A session announcement for the same message then skips the
|
|
244
|
-
* duplicate log line
|
|
257
|
+
* duplicate log line; a blocked verdict still lands as the runtime-context
|
|
258
|
+
* entry. Advisory like every
|
|
245
259
|
* other arm: an unreachable distro degrades to a debug line.
|
|
246
260
|
*/
|
|
247
261
|
const startupCheck = async () => {
|
package/lib/preset-choice.d.ts
CHANGED
|
@@ -32,6 +32,19 @@
|
|
|
32
32
|
* @returns true when this workspace opted out of the distro environment.
|
|
33
33
|
*/
|
|
34
34
|
export declare function isWindowsAccessWorkspace(cwd: string, windowsAccess: readonly string[]): boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Whether a session-creation preset id leaves the environment to this plugin.
|
|
37
|
+
*
|
|
38
|
+
* An absent id means the caller mounted nothing (the headless runner); the
|
|
39
|
+
* registry's default id means the caller passed the default explicitly, which
|
|
40
|
+
* is not a pick of a different environment. A non-default id is an operator's
|
|
41
|
+
* choice and must win.
|
|
42
|
+
*
|
|
43
|
+
* @param presetId - the preset id the session controller received.
|
|
44
|
+
* @param fallback - the registry's default id, when it exposes one.
|
|
45
|
+
* @returns true when the WSL preset may be selected for the session.
|
|
46
|
+
*/
|
|
47
|
+
export declare function isDefaultPresetChoice(presetId: string | undefined, fallback: string | undefined): boolean;
|
|
35
48
|
/**
|
|
36
49
|
* The adoption decision.
|
|
37
50
|
*
|
package/lib/preset-choice.js
CHANGED
|
@@ -40,12 +40,29 @@ function normalizeWorkspace(value) {
|
|
|
40
40
|
export function isWindowsAccessWorkspace(cwd, windowsAccess) {
|
|
41
41
|
const target = normalizeWorkspace(cwd);
|
|
42
42
|
return windowsAccess.some((entry) => {
|
|
43
|
-
|
|
43
|
+
// The list is settings-sourced. A malformed entry is ignored rather than
|
|
44
|
+
// allowed to fail a session creation or an adoption decision.
|
|
45
|
+
if (typeof entry !== "string" || entry.trim() === "")
|
|
44
46
|
return false;
|
|
45
47
|
const base = normalizeWorkspace(entry);
|
|
46
48
|
return target === base || target.startsWith(`${base}\\`);
|
|
47
49
|
});
|
|
48
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* Whether a session-creation preset id leaves the environment to this plugin.
|
|
53
|
+
*
|
|
54
|
+
* An absent id means the caller mounted nothing (the headless runner); the
|
|
55
|
+
* registry's default id means the caller passed the default explicitly, which
|
|
56
|
+
* is not a pick of a different environment. A non-default id is an operator's
|
|
57
|
+
* choice and must win.
|
|
58
|
+
*
|
|
59
|
+
* @param presetId - the preset id the session controller received.
|
|
60
|
+
* @param fallback - the registry's default id, when it exposes one.
|
|
61
|
+
* @returns true when the WSL preset may be selected for the session.
|
|
62
|
+
*/
|
|
63
|
+
export function isDefaultPresetChoice(presetId, fallback) {
|
|
64
|
+
return presetId === undefined || (fallback !== undefined && presetId === fallback);
|
|
65
|
+
}
|
|
49
66
|
/**
|
|
50
67
|
* The adoption decision.
|
|
51
68
|
*
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { SandboxExecutionPolicy } from "@deepseek-ai/dsh-sandbox";
|
|
2
|
+
interface DistroHomeOwner {
|
|
3
|
+
config: unknown;
|
|
4
|
+
resolvedDistro: string;
|
|
5
|
+
resolvedHome: string | undefined;
|
|
6
|
+
resolvedHomes: Map<string, string>;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* The configured default workdir, or an empty string when the operator left it
|
|
10
|
+
* unset. `cwd` is a volatile field on both providers, so it is read through
|
|
11
|
+
* `.get()`, and it may be absent entirely.
|
|
12
|
+
*/
|
|
13
|
+
export declare function configuredCwd(config: {
|
|
14
|
+
cwd?: {
|
|
15
|
+
get(): string | undefined;
|
|
16
|
+
};
|
|
17
|
+
}): string;
|
|
18
|
+
/**
|
|
19
|
+
* The distro user's home as a Linux path, cached on the provider instance whose
|
|
20
|
+
* `distro`/`wslPath` config it belongs to.
|
|
21
|
+
*/
|
|
22
|
+
export declare function distroHome(owner: DistroHomeOwner, distro: string): Promise<string>;
|
|
23
|
+
/**
|
|
24
|
+
* Translate workspace-write grants into the vocabulary used by the target
|
|
25
|
+
* filesystem. WSL workspaces receive distro-local temporary and extra roots;
|
|
26
|
+
* Windows workspaces retain the upstream grant.
|
|
27
|
+
*/
|
|
28
|
+
export declare function wslWritableRoots(policy: SandboxExecutionPolicy, distro: string, linuxExtraRoots: readonly string[]): string[];
|
|
29
|
+
/**
|
|
30
|
+
* Resolve configured and policy-provided roots for one distro, then verify
|
|
31
|
+
* their physical directories before they are bound into a confinement profile.
|
|
32
|
+
*/
|
|
33
|
+
export declare function effectiveWritableRoots(input: {
|
|
34
|
+
configured?: readonly string[] | undefined;
|
|
35
|
+
policy?: SandboxExecutionPolicy | undefined;
|
|
36
|
+
distro: string;
|
|
37
|
+
home: string;
|
|
38
|
+
wslPath: string;
|
|
39
|
+
signal?: AbortSignal | undefined;
|
|
40
|
+
run?: ((argv: string[]) => Promise<string>) | undefined;
|
|
41
|
+
check?: boolean;
|
|
42
|
+
}): Promise<string[]>;
|
|
43
|
+
/** Whether confined profiles shadow `/mnt`, with the explicit stance winning. */
|
|
44
|
+
export declare function effectiveMaskWindowsDrive(config: {
|
|
45
|
+
interopVisibility?: "visible" | "masked" | "disabled";
|
|
46
|
+
maskWindowsDrive?: boolean;
|
|
47
|
+
}): boolean;
|
|
48
|
+
/** Resolve the distro for an operation from its configuration and candidates. */
|
|
49
|
+
export declare function resolveOperationDistro(configured: string, candidates: ReadonlyArray<string | undefined>, probeDefault: () => Promise<string>): Promise<string>;
|
|
50
|
+
/**
|
|
51
|
+
* Choose the session runtime policy for one distro, retrying an automatic
|
|
52
|
+
* failed probe after its short cache expires.
|
|
53
|
+
*/
|
|
54
|
+
export declare function sessionRuntimeWanted(value: boolean | "auto", distro: string, ensure: () => Promise<void>, cache: Map<string, {
|
|
55
|
+
usable: boolean;
|
|
56
|
+
checkedAt: number;
|
|
57
|
+
}>): Promise<boolean>;
|
|
58
|
+
export {};
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { canonicalPath, SandboxInvalidRootError, writableRoots } from "@deepseek-ai/dsh-sandbox";
|
|
2
|
+
import { isWslUnc, posixToUnc, toLinuxPath } from "./paths.js";
|
|
3
|
+
import { distroOfUnc, isDefaultDistro, pinnedDistro } from "./distro-route.js";
|
|
4
|
+
import { linuxHomePath } from "./wsl.js";
|
|
5
|
+
import { WritableRootError, ensureWritableRoots, resolveWritableRoots } from "./writable-roots.js";
|
|
6
|
+
const AUTO_SCOPE_RECHECK_MS = 60_000;
|
|
7
|
+
/**
|
|
8
|
+
* The configured default workdir, or an empty string when the operator left it
|
|
9
|
+
* unset. `cwd` is a volatile field on both providers, so it is read through
|
|
10
|
+
* `.get()`, and it may be absent entirely.
|
|
11
|
+
*/
|
|
12
|
+
export function configuredCwd(config) {
|
|
13
|
+
return String(config.cwd?.get?.() ?? "").trim();
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* The distro user's home as a Linux path, cached on the provider instance whose
|
|
17
|
+
* `distro`/`wslPath` config it belongs to.
|
|
18
|
+
*/
|
|
19
|
+
export async function distroHome(owner, distro) {
|
|
20
|
+
const cached = owner.resolvedHomes.get(distro);
|
|
21
|
+
if (cached !== undefined)
|
|
22
|
+
return cached;
|
|
23
|
+
if (owner.resolvedHome !== undefined && owner.resolvedDistro.length > 0 && distro === owner.resolvedDistro) {
|
|
24
|
+
owner.resolvedHomes.set(distro, owner.resolvedHome);
|
|
25
|
+
return owner.resolvedHome;
|
|
26
|
+
}
|
|
27
|
+
const config = owner.config;
|
|
28
|
+
const home = await linuxHomePath(distro, { wslPath: config.wslPath });
|
|
29
|
+
owner.resolvedHomes.set(distro, home);
|
|
30
|
+
if (owner.resolvedDistro.length > 0 && distro === owner.resolvedDistro)
|
|
31
|
+
owner.resolvedHome = home;
|
|
32
|
+
return home;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Translate workspace-write grants into the vocabulary used by the target
|
|
36
|
+
* filesystem. WSL workspaces receive distro-local temporary and extra roots;
|
|
37
|
+
* Windows workspaces retain the upstream grant.
|
|
38
|
+
*/
|
|
39
|
+
export function wslWritableRoots(policy, distro, linuxExtraRoots) {
|
|
40
|
+
if (policy.mode !== "workspace-write")
|
|
41
|
+
return [];
|
|
42
|
+
const roots = new Set([canonicalPath(policy.workspaceRoot)]);
|
|
43
|
+
if (isWslUnc(policy.workspaceRoot)) {
|
|
44
|
+
roots.add(canonicalPath(posixToUnc(distro, "/tmp")));
|
|
45
|
+
for (const root of linuxExtraRoots)
|
|
46
|
+
roots.add(canonicalPath(posixToUnc(distro, root)));
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
for (const root of writableRoots(policy))
|
|
50
|
+
roots.add(root);
|
|
51
|
+
}
|
|
52
|
+
return [...roots];
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Resolve configured and policy-provided roots for one distro, then verify
|
|
56
|
+
* their physical directories before they are bound into a confinement profile.
|
|
57
|
+
*/
|
|
58
|
+
export async function effectiveWritableRoots(input) {
|
|
59
|
+
try {
|
|
60
|
+
const roots = resolveWritableRoots({
|
|
61
|
+
configured: input.configured,
|
|
62
|
+
policy: input.policy?.additionalWritableRoots,
|
|
63
|
+
home: input.home,
|
|
64
|
+
distro: input.distro,
|
|
65
|
+
workspaceRoot: toLinuxPath(input.policy?.workspaceRoot ?? input.home),
|
|
66
|
+
});
|
|
67
|
+
if (input.check !== false) {
|
|
68
|
+
await ensureWritableRoots({ wslPath: input.wslPath, distro: input.distro, roots, signal: input.signal, ...(input.run === undefined ? {} : { run: input.run }) });
|
|
69
|
+
}
|
|
70
|
+
return roots;
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
if (error instanceof WritableRootError)
|
|
74
|
+
throw new SandboxInvalidRootError(error.root, error.reason);
|
|
75
|
+
throw error;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/** Whether confined profiles shadow `/mnt`, with the explicit stance winning. */
|
|
79
|
+
export function effectiveMaskWindowsDrive(config) {
|
|
80
|
+
if (config.interopVisibility !== undefined)
|
|
81
|
+
return config.interopVisibility !== "visible";
|
|
82
|
+
return config.maskWindowsDrive === true;
|
|
83
|
+
}
|
|
84
|
+
/** Resolve the distro for an operation from its configuration and candidates. */
|
|
85
|
+
export async function resolveOperationDistro(configured, candidates, probeDefault) {
|
|
86
|
+
const pinned = pinnedDistro(configured);
|
|
87
|
+
if (pinned !== undefined)
|
|
88
|
+
return pinned;
|
|
89
|
+
if (!isDefaultDistro(configured)) {
|
|
90
|
+
for (const candidate of candidates) {
|
|
91
|
+
const named = distroOfUnc(candidate);
|
|
92
|
+
if (named !== undefined)
|
|
93
|
+
return named;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return probeDefault();
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Choose the session runtime policy for one distro, retrying an automatic
|
|
100
|
+
* failed probe after its short cache expires.
|
|
101
|
+
*/
|
|
102
|
+
export async function sessionRuntimeWanted(value, distro, ensure, cache) {
|
|
103
|
+
if (value === false)
|
|
104
|
+
return false;
|
|
105
|
+
if (value === true) {
|
|
106
|
+
await ensure();
|
|
107
|
+
return true;
|
|
108
|
+
}
|
|
109
|
+
const cached = cache.get(distro);
|
|
110
|
+
if (cached?.usable === true)
|
|
111
|
+
return true;
|
|
112
|
+
if (cached !== undefined && Date.now() - cached.checkedAt < AUTO_SCOPE_RECHECK_MS)
|
|
113
|
+
return false;
|
|
114
|
+
try {
|
|
115
|
+
await ensure();
|
|
116
|
+
cache.set(distro, { usable: true, checkedAt: Date.now() });
|
|
117
|
+
return true;
|
|
118
|
+
}
|
|
119
|
+
catch {
|
|
120
|
+
cache.set(distro, { usable: false, checkedAt: Date.now() });
|
|
121
|
+
return false;
|
|
122
|
+
}
|
|
123
|
+
}
|
package/lib/sandbox-core.d.ts
CHANGED
package/lib/sandbox-core.js
CHANGED
|
@@ -277,7 +277,9 @@ export function createSandboxCore({ SandboxUnavailableError }) {
|
|
|
277
277
|
* @param argv - the argv to run INSIDE the distro (shell, its flags, command).
|
|
278
278
|
* @param policy - the resolved confined policy (`mode` is never
|
|
279
279
|
* `danger-full-access`; the caller does not confine that case at all).
|
|
280
|
-
* @param options - the distro to run in
|
|
280
|
+
* @param options - the distro to run in, optional cancellation, and the
|
|
281
|
+
* resolved extra writable roots (already Linux paths, filtered and
|
|
282
|
+
* physically checked by the provider).
|
|
281
283
|
* @returns the wrapped argv plus the settlement-classification facts, in the
|
|
282
284
|
* seam's `ConfinedArgv` shape.
|
|
283
285
|
* @throws SandboxUnavailableError when the distro has no usable `bwrap`, so a
|
|
@@ -289,7 +291,7 @@ export function createSandboxCore({ SandboxUnavailableError }) {
|
|
|
289
291
|
throw new SandboxUnavailableError(policy.mode, bwrapFailure(this.wslPath, distro) ?? missingBwrapRemedy(distro));
|
|
290
292
|
}
|
|
291
293
|
const workspaceRoot = toLinuxPath(policy.workspaceRoot);
|
|
292
|
-
const prefix = bwrapArgvPrefix({ ...policy, workspaceRoot }, { maskWindowsDrive: this.maskWindowsDrive });
|
|
294
|
+
const prefix = bwrapArgvPrefix({ ...policy, workspaceRoot }, { maskWindowsDrive: this.maskWindowsDrive, writableRoots: options.writableRoots });
|
|
293
295
|
return {
|
|
294
296
|
argv: [...prefix, ...argv],
|
|
295
297
|
enforcement: ENFORCEMENT,
|
package/lib/session-runtime.d.ts
CHANGED
|
@@ -55,6 +55,12 @@ interface SessionRuntimeRequest {
|
|
|
55
55
|
mode: string;
|
|
56
56
|
/** Shadow `/mnt` in the runtime's mount profile. */
|
|
57
57
|
maskWindowsDrive?: boolean;
|
|
58
|
+
/**
|
|
59
|
+
* Extra Linux roots to bind read-write in the runtime's profile. The
|
|
60
|
+
* providers resolved, filtered and checked them; they are part of the key
|
|
61
|
+
* because the mount table is fixed for the runtime's lifetime.
|
|
62
|
+
*/
|
|
63
|
+
writableRoots?: readonly string[];
|
|
58
64
|
/** The agent's client lease; 0 disables. */
|
|
59
65
|
leaseMs?: number;
|
|
60
66
|
}
|
|
@@ -134,7 +140,7 @@ export declare class SessionRuntimes {
|
|
|
134
140
|
* @param request - the runtime request.
|
|
135
141
|
* @returns the registry key.
|
|
136
142
|
*/
|
|
137
|
-
static key(request: Pick<SessionRuntimeRequest, "distro" | "workspaceRoot" | "mode" | "maskWindowsDrive" | "sessionId">): string;
|
|
143
|
+
static key(request: Pick<SessionRuntimeRequest, "distro" | "workspaceRoot" | "mode" | "maskWindowsDrive" | "sessionId" | "writableRoots">): string;
|
|
138
144
|
/**
|
|
139
145
|
* Acquire the runtime for one key, creating it on first use.
|
|
140
146
|
*
|
package/lib/session-runtime.js
CHANGED
|
@@ -146,7 +146,14 @@ export class SessionRuntimes {
|
|
|
146
146
|
* @returns the registry key.
|
|
147
147
|
*/
|
|
148
148
|
static key(request) {
|
|
149
|
-
return [
|
|
149
|
+
return [
|
|
150
|
+
request.sessionId ?? "",
|
|
151
|
+
request.distro,
|
|
152
|
+
request.workspaceRoot,
|
|
153
|
+
request.mode,
|
|
154
|
+
request.maskWindowsDrive === true ? "masked" : "visible",
|
|
155
|
+
(request.writableRoots ?? []).join("\u0000"),
|
|
156
|
+
].join("\u0000");
|
|
150
157
|
}
|
|
151
158
|
/**
|
|
152
159
|
* Acquire the runtime for one key, creating it on first use.
|
|
@@ -165,7 +172,7 @@ export class SessionRuntimes {
|
|
|
165
172
|
const unit = sessionScopeUnit(request.distro, this.token());
|
|
166
173
|
const prefix = sessionScopePrefix(unit);
|
|
167
174
|
if (request.mode !== "danger-full-access") {
|
|
168
|
-
prefix.push(...bwrapArgvPrefix({ mode: request.mode, workspaceRoot: toLinuxPath(request.workspaceRoot) }, { maskWindowsDrive: request.maskWindowsDrive, realTmp: true, pidNamespace: false }));
|
|
175
|
+
prefix.push(...bwrapArgvPrefix({ mode: request.mode, workspaceRoot: toLinuxPath(request.workspaceRoot) }, { maskWindowsDrive: request.maskWindowsDrive, realTmp: true, pidNamespace: false, writableRoots: request.writableRoots }));
|
|
169
176
|
}
|
|
170
177
|
const agent = this.spawnAgent({
|
|
171
178
|
distro: request.distro,
|
package/lib/shell.d.ts
CHANGED
package/lib/shell.js
CHANGED
package/lib/status.js
CHANGED
|
@@ -51,6 +51,7 @@ import { dirname, join } from "node:path";
|
|
|
51
51
|
import { listDistros, listRunningDistros } from "./wsl.js";
|
|
52
52
|
import { digestReport, sectionOf } from "./wsl-doctor-tool.js";
|
|
53
53
|
import { runDoctorCli } from "./wsl-doctor-command.js";
|
|
54
|
+
import { mergeAutoPresetSeam } from "./doctor-live.js";
|
|
54
55
|
export const name = "wsl-status";
|
|
55
56
|
/** The one route the panel fetches; it must live under the `/api` channel. */
|
|
56
57
|
export const STATUS_PATH = "/api/wsl-env/status";
|
|
@@ -302,7 +303,7 @@ export function createStatusHandler(options) {
|
|
|
302
303
|
: ["--json", "--quick", "--distro", distro];
|
|
303
304
|
const raw = await options.runCli(argv, undefined, options.timeoutMs);
|
|
304
305
|
const report = JSON.parse(raw);
|
|
305
|
-
view = viewOf(digestReport(report, distro), distro, at, repair, source);
|
|
306
|
+
view = viewOf(digestReport(mergeAutoPresetSeam(report), distro), distro, at, repair, source);
|
|
306
307
|
}
|
|
307
308
|
catch (error) {
|
|
308
309
|
view = {
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The extra directories a WSL confinement grants read-write under
|
|
3
|
+
* `workspace-write`, and the one-time check that they are usable.
|
|
4
|
+
*
|
|
5
|
+
* `workspace-write` grants the session workspace and the distro's temp areas —
|
|
6
|
+
* nothing under the user's home. Toolchains do not stay inside the workspace:
|
|
7
|
+
* npm writes `~/.npm`, pnpm writes its store under `~/.local/share/pnpm`,
|
|
8
|
+
* cargo writes `~/.cargo/registry`, and a linked Git worktree writes the
|
|
9
|
+
* shared `.git` directory. This module turns the operator's grants (the plugin
|
|
10
|
+
* rows' `writableRoots` plus the shared policy's `additionalWritableRoots`)
|
|
11
|
+
* into the Linux paths the bwrap profile binds.
|
|
12
|
+
*
|
|
13
|
+
* ## Why the roots are filtered
|
|
14
|
+
*
|
|
15
|
+
* A grant is bound rw into the distro's mount table. If the bound path could
|
|
16
|
+
* be replaced by a symlink after the check, the next command would bind the
|
|
17
|
+
* link's target — the classic grant-redirection escape. The model can write
|
|
18
|
+
* only the workspace and the temp areas, so a grant whose parent is writable
|
|
19
|
+
* is not merely redundant, it is a redirection risk. Candidates already
|
|
20
|
+
* writable (inside the workspace, `/tmp` or `/dev/shm`) and candidates nested
|
|
21
|
+
* inside another grant are therefore dropped, not bound. Every effective root
|
|
22
|
+
* has a read-only parent, which is what makes the one-time physical-path
|
|
23
|
+
* check below sufficient for the model threat model.
|
|
24
|
+
*
|
|
25
|
+
* This module is peer-free so the rules are unit-testable in a bare checkout;
|
|
26
|
+
* `lib/provider-common.js` converts {@link WritableRootError} into the peer's
|
|
27
|
+
* `SandboxInvalidRootError` at the call sites.
|
|
28
|
+
*
|
|
29
|
+
* This is a TypeScript source built to `lib/writable-roots.js`; edit THIS file
|
|
30
|
+
* and run `pnpm run build` — the artifact under `lib/` is generated, and
|
|
31
|
+
* `pnpm test` fails when it drifts.
|
|
32
|
+
*
|
|
33
|
+
* @module dsh-plugin-wsl-env/writable-roots
|
|
34
|
+
*/
|
|
35
|
+
/** A configured grant that cannot be used, with the reason the model-facing error carries. */
|
|
36
|
+
export declare class WritableRootError extends Error {
|
|
37
|
+
/** The entry as configured (or the policy's spelling). */
|
|
38
|
+
readonly root: string;
|
|
39
|
+
/** Why it was refused. */
|
|
40
|
+
readonly reason: string;
|
|
41
|
+
/**
|
|
42
|
+
* @param root - the entry as configured.
|
|
43
|
+
* @param reason - the model-facing reason.
|
|
44
|
+
*/
|
|
45
|
+
constructor(root: string, reason: string);
|
|
46
|
+
}
|
|
47
|
+
/** The inputs of {@link resolveWritableRoots}. */
|
|
48
|
+
export interface WritableRootsInput {
|
|
49
|
+
/** The plugin rows' `writableRoots` (distro paths; `~` expands to the distro home). */
|
|
50
|
+
configured?: readonly string[] | undefined;
|
|
51
|
+
/** The shared policy's `additionalWritableRoots` (UNC of this distro, or Linux paths). */
|
|
52
|
+
policy?: readonly string[] | undefined;
|
|
53
|
+
/** The resolved distro user's home, for `~` and `~/...` entries. */
|
|
54
|
+
home: string;
|
|
55
|
+
/** The distro the workspace belongs to, for the UNC check and the embedded error text. */
|
|
56
|
+
distro: string;
|
|
57
|
+
/** The workspace root in Linux form; grants inside it are already writable. */
|
|
58
|
+
workspaceRoot: string;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Validate the shape of a row's `writableRoots` before any distro is known.
|
|
62
|
+
* Called from the providers' constructors so a typo fails at boot instead of
|
|
63
|
+
* at the first command.
|
|
64
|
+
*
|
|
65
|
+
* @param values - the configured entries, if present.
|
|
66
|
+
* @throws {Error} naming the first entry that is not a distro path.
|
|
67
|
+
*/
|
|
68
|
+
export declare function validateWritableRootsConfig(values: readonly string[] | undefined): void;
|
|
69
|
+
/**
|
|
70
|
+
* Turn the configured and policy grants into the effective Linux roots.
|
|
71
|
+
*
|
|
72
|
+
* Entries already writable (inside the workspace, `/tmp` or `/dev/shm`) and
|
|
73
|
+
* entries nested inside another grant are dropped: they add no permission, and
|
|
74
|
+
* binding them would let the model redirect the bind through a symlink. The
|
|
75
|
+
* rest are deduplicated, sorted and returned.
|
|
76
|
+
*
|
|
77
|
+
* @param input - the configured grants, policy grants, home and workspace.
|
|
78
|
+
* @returns the effective roots, in deterministic order.
|
|
79
|
+
* @throws {WritableRootError} for an entry that names another world or is malformed.
|
|
80
|
+
*/
|
|
81
|
+
export declare function resolveWritableRoots(input: WritableRootsInput): string[];
|
|
82
|
+
/** The argv of the one-time physical-directory check, exported for tests and diagnostics. */
|
|
83
|
+
export declare function writableRootsCheckArgv(wslPath: string, distro: string, roots: readonly string[]): string[];
|
|
84
|
+
/**
|
|
85
|
+
* Check once per process that every effective root exists, is readable and is
|
|
86
|
+
* its own physical directory. A missing root reports the operator-facing
|
|
87
|
+
* failure instead of letting bwrap die with an opaque mount error; a symlinked
|
|
88
|
+
* root is refused with the physical-path rule the peer's extra-root contract
|
|
89
|
+
* uses.
|
|
90
|
+
*
|
|
91
|
+
* A success is remembered for the process lifetime: the effective roots have
|
|
92
|
+
* read-only parents, so the model cannot replace them, and the common roots
|
|
93
|
+
* (`~/.npm`, `~/.cache`, …) are stable. A failed check is not remembered, so a
|
|
94
|
+
* directory the operator creates while the app runs is believed next time.
|
|
95
|
+
*
|
|
96
|
+
* @param options - the `wsl.exe` path, distro, effective roots and optional run override.
|
|
97
|
+
* @returns resolved when every root is usable.
|
|
98
|
+
* @throws {WritableRootError} naming the first unusable root.
|
|
99
|
+
*/
|
|
100
|
+
export declare function ensureWritableRoots(options: {
|
|
101
|
+
wslPath: string;
|
|
102
|
+
distro: string;
|
|
103
|
+
roots: readonly string[];
|
|
104
|
+
signal?: AbortSignal | undefined;
|
|
105
|
+
/** The runner, overridable in tests; defaults to the shared capture. */
|
|
106
|
+
run?: (argv: string[]) => Promise<string>;
|
|
107
|
+
}): Promise<void>;
|
|
108
|
+
/** Test hook: forget the remembered checks. */
|
|
109
|
+
export declare function resetWritableRootsChecks(): void;
|