dsh-plugin-wsl-env 0.26.3 → 0.27.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 +142 -0
- package/CONTRIBUTING.md +32 -25
- package/CONTRIBUTING.zh.md +3 -2
- package/README.md +1 -1
- package/SECURITY.md +21 -7
- package/SECURITY.zh.md +18 -5
- package/SUPPORT.md +2 -2
- package/SUPPORT.zh.md +2 -2
- package/client.js +351 -48
- package/cordis.patch.yml +26 -10
- package/docs/AGENT-PROTOCOL-V7.md +4 -2
- package/docs/API.md +3 -1
- package/docs/API.zh.md +3 -1
- package/docs/ARCHITECTURE.md +22 -4
- package/docs/ARCHITECTURE.zh.md +18 -4
- package/docs/CONFIGURATION.md +117 -17
- package/docs/CONFIGURATION.zh.md +97 -11
- package/docs/DIAGNOSTICS.md +22 -11
- package/docs/DIAGNOSTICS.zh.md +17 -9
- package/docs/LIMITATIONS.md +27 -4
- package/docs/LIMITATIONS.zh.md +20 -3
- package/docs/MIGRATION.md +2 -2
- package/docs/MIGRATION.zh.md +2 -2
- package/docs/PARITY.md +3 -1
- package/docs/QUICKSTART.md +31 -20
- package/docs/QUICKSTART.zh.md +16 -9
- package/docs/README.zh.md +1 -1
- package/docs/RELEASING.md +25 -3
- package/docs/REQUIREMENTS.zh.md +7 -6
- package/docs/ROADMAP-1.0.md +11 -7
- package/lib/agent-confined.d.ts +9 -1
- package/lib/agent-confined.js +3 -3
- package/lib/agent.d.ts +54 -18
- package/lib/agent.js +86 -19
- package/lib/bwrap.d.ts +16 -0
- package/lib/bwrap.js +9 -0
- package/lib/fs-routing.d.ts +6 -0
- package/lib/fs-routing.js +7 -0
- package/lib/fs-substrate.d.ts +1 -1
- package/lib/fs-substrate.js +10 -18
- package/lib/fsio-agent.d.ts +4 -0
- package/lib/fsio-agent.js +37 -10
- package/lib/listing.d.ts +2 -2
- package/lib/listing.js +5 -4
- package/lib/messages.d.ts +70 -0
- package/lib/messages.js +80 -0
- package/lib/open-in-app.js +12 -9
- package/lib/picker.d.ts +4 -1
- package/lib/picker.js +35 -11
- package/lib/plugin-update.d.ts +212 -0
- package/lib/plugin-update.js +283 -0
- package/lib/ports.js +8 -1
- package/lib/provider-common.d.ts +22 -0
- package/lib/provider-common.js +18 -0
- package/lib/provider-marker.d.ts +23 -0
- package/lib/provider-marker.js +21 -0
- package/lib/sandbox-core.d.ts +2 -0
- package/lib/sandbox-core.js +5 -3
- package/lib/session-runtime.d.ts +10 -1
- package/lib/session-runtime.js +3 -1
- package/lib/shell-env.js +1 -1
- package/lib/socket-isolation.d.ts +103 -0
- package/lib/socket-isolation.js +166 -0
- package/lib/status.d.ts +21 -8
- package/lib/status.js +61 -23
- package/lib/subprocess.d.ts +3 -0
- package/lib/subprocess.js +5 -0
- package/lib/takeover-report.js +4 -11
- package/lib/update-check.d.ts +49 -9
- package/lib/update-check.js +81 -28
- package/lib/watcher.d.ts +1 -1
- package/lib/watcher.js +1 -1
- package/lib/wsl-doctor-command.d.ts +6 -2
- package/lib/wsl-doctor-command.js +24 -15
- package/lib/wsl-doctor-tool.js +2 -0
- package/lib/wsl-filesystem.d.ts +53 -12
- package/lib/wsl-filesystem.js +90 -31
- package/lib/wsl-shell.d.ts +109 -40
- package/lib/wsl-shell.js +128 -54
- package/package.json +8 -3
- package/scripts/doctor.mjs +199 -3
- package/scripts/profile-preset.mjs +10 -2
package/lib/wsl-shell.js
CHANGED
|
@@ -14,7 +14,8 @@ import { configureAgentBackend, ensureNativeSessionAgent } from "./native-agent.
|
|
|
14
14
|
import { installMessagesLocale, t } from "./messages.js";
|
|
15
15
|
import { defaultDistro, defaultShell, runCapture, shellArgs, workdirFailure, wslErrorCode } from "./wsl.js";
|
|
16
16
|
import { validateWritableRootsConfig } from "./writable-roots.js";
|
|
17
|
-
import {
|
|
17
|
+
import { SocketIsolationError, socketMasksFor as resolveSocketMasks } from "./socket-isolation.js";
|
|
18
|
+
import { ProviderRuntimeBook, configuredCwd, distroHome, effectiveMaskWindowsDrive, effectiveWritableRoots, resolveOperationDistro, sessionRuntimeWanted } from "./provider-common.js";
|
|
18
19
|
/**
|
|
19
20
|
* Every model shell call gets a rebuilt managed `DSH_*` namespace (see
|
|
20
21
|
* `dsh-shell-env` / `ctx.shellEnv`). Those names exist only in the Windows-side
|
|
@@ -34,8 +35,6 @@ const SAFE_FORWARD = ["NO_COLOR", "TERM", "PAGER", "GIT_PAGER", "LANG", "LC_ALL"
|
|
|
34
35
|
const inheritedSpawnSpec = LocalBashExecutor.prototype.spawnSpec;
|
|
35
36
|
/**
|
|
36
37
|
* The refusal both shell resolvers share: the probes named no shell, and the
|
|
37
|
-
* command must not quietly run under some other interpreter.
|
|
38
|
-
* the probes named no shell, and the
|
|
39
38
|
* command must not quietly run under some other interpreter. The wording is
|
|
40
39
|
* the one `runInDistro` already throws with.
|
|
41
40
|
*
|
|
@@ -86,19 +85,6 @@ export class WslShellExecutor extends LocalBashExecutor {
|
|
|
86
85
|
* unconfined and `sandboxMode` is `undefined`, so the model is told so.
|
|
87
86
|
*/
|
|
88
87
|
sandbox: z.boolean().default(true),
|
|
89
|
-
/**
|
|
90
|
-
* Shadow `/mnt` with an empty tmpfs in every confined profile, hiding the
|
|
91
|
-
* Windows drive from confined commands: its files cannot be read or
|
|
92
|
-
* exfiltrated and its executables cannot be launched through interop —
|
|
93
|
-
* the hole that lets a "sandboxed" command reach your full Windows token.
|
|
94
|
-
* A narrowing, not a closure (a command can still write an executable
|
|
95
|
-
* into the workspace and run it — binfmt dispatches on content, not
|
|
96
|
-
* location), so enforcement stays `partial` and the sandbox fact reports
|
|
97
|
-
* `windowsDrive: "masked"`. Costs: confined commands cannot read or touch
|
|
98
|
-
* anything under `/mnt`, and tools that probe the drive degrade. The
|
|
99
|
-
* complete closure is distro-level: `[interop] enabled=false` in
|
|
100
|
-
* `wsl.conf`.
|
|
101
|
-
*/
|
|
102
88
|
/**
|
|
103
89
|
* The interop stance in one key (WSL-314), expanding to the per-key
|
|
104
90
|
* values the measured matrix documents:
|
|
@@ -119,7 +105,44 @@ export class WslShellExecutor extends LocalBashExecutor {
|
|
|
119
105
|
* boolean answer); the boolean remains for existing profiles.
|
|
120
106
|
*/
|
|
121
107
|
interopVisibility: z.union(["visible", "masked", "disabled"]),
|
|
108
|
+
/**
|
|
109
|
+
* Shadow `/mnt` with an empty tmpfs in every confined profile, hiding the
|
|
110
|
+
* Windows drive from confined commands: its files cannot be read or
|
|
111
|
+
* exfiltrated and its executables cannot be launched through interop —
|
|
112
|
+
* the hole that lets a "sandboxed" command reach your full Windows token.
|
|
113
|
+
* A narrowing, not a closure (a command can still write an executable
|
|
114
|
+
* into the workspace and run it — binfmt dispatches on content, not
|
|
115
|
+
* location), so enforcement stays `partial` and the sandbox fact reports
|
|
116
|
+
* `windowsDrive: "masked"`. Costs: confined commands cannot read or touch
|
|
117
|
+
* anything under `/mnt`, and tools that probe the drive degrade. The
|
|
118
|
+
* complete closure is distro-level: `[interop] enabled=false` in
|
|
119
|
+
* `wsl.conf`. The mask covers the COMMAND path only; the file tools'
|
|
120
|
+
* read side still reaches `/mnt` through the shared read agent.
|
|
121
|
+
*/
|
|
122
122
|
maskWindowsDrive: z.boolean().default(false),
|
|
123
|
+
/**
|
|
124
|
+
* The socket surfaces a confined COMMAND cannot reach. The sandbox's mount
|
|
125
|
+
* profile confines file effects, not process authority: a command can
|
|
126
|
+
* otherwise ask the user's systemd manager to start a unit outside the
|
|
127
|
+
* fence, or connect to a container daemon and start work outside it.
|
|
128
|
+
*
|
|
129
|
+
* - `off` (default) — nothing masked; the boundary is the documented
|
|
130
|
+
* `enforcement: partial`.
|
|
131
|
+
* - `session-bus` — masks `$XDG_RUNTIME_DIR/bus` and
|
|
132
|
+
* `$XDG_RUNTIME_DIR/systemd/private`, so `systemd-run --user` and
|
|
133
|
+
* `systemctl --user` fail inside the command.
|
|
134
|
+
* - `strict` — adds `/run/dbus/system_bus_socket` and the container
|
|
135
|
+
* sockets (`docker`, `podman`, `containerd`, `crio`) that exist and are
|
|
136
|
+
* reachable by the distro user; D-Bus and container clients inside the
|
|
137
|
+
* command fail.
|
|
138
|
+
*
|
|
139
|
+
* The masks are a narrowing, not a closure: same-user `/proc`, the
|
|
140
|
+
* interop transport and other IPC remain, and `enforcement` stays
|
|
141
|
+
* `partial`. The key applies to the command plane (`wsl-shell`); the
|
|
142
|
+
* filesystem rows' confined agent runs only this plugin's fs protocol,
|
|
143
|
+
* never model-authored commands. Verified by `pnpm run probe:sandbox`.
|
|
144
|
+
*/
|
|
145
|
+
socketIsolation: z.union(["off", "session-bus", "strict"]).default("off"),
|
|
123
146
|
/**
|
|
124
147
|
* Extra directories under `workspace-write`, in distro spelling. The
|
|
125
148
|
* plugin grants them together with the workspace, so toolchain caches
|
|
@@ -168,6 +191,21 @@ export class WslShellExecutor extends LocalBashExecutor {
|
|
|
168
191
|
*/
|
|
169
192
|
sessionSandbox: z.union([z.boolean(), z.const("auto")]).default(false),
|
|
170
193
|
});
|
|
194
|
+
/**
|
|
195
|
+
* Per-distro homes, delegated to the shared runtime book: `provider-common`'s
|
|
196
|
+
* `distroHome` reads this view, and tests pin the cache through it.
|
|
197
|
+
*/
|
|
198
|
+
get resolvedHomes() {
|
|
199
|
+
return this.runtimeBook.homes;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* The row's config without the peer's volatile wrapper. The schema validates
|
|
203
|
+
* the plain shape; the wrapper only widens the type, so one accessor states
|
|
204
|
+
* the cast instead of every method repeating it.
|
|
205
|
+
*/
|
|
206
|
+
get wslConfig() {
|
|
207
|
+
return this.config;
|
|
208
|
+
}
|
|
171
209
|
/**
|
|
172
210
|
* @param ctx - the composition context.
|
|
173
211
|
* @param config - the validated plugin config.
|
|
@@ -181,19 +219,17 @@ export class WslShellExecutor extends LocalBashExecutor {
|
|
|
181
219
|
this.resolvedShell = config.shell;
|
|
182
220
|
this.resolvedShells = new Map();
|
|
183
221
|
this.resolvedHome = undefined;
|
|
184
|
-
this.
|
|
222
|
+
this.runtimeBook = new ProviderRuntimeBook();
|
|
185
223
|
this.mode = config.sandbox ? ctx.sandboxPolicy.defaultMode : undefined;
|
|
186
224
|
this.sandbox = config.sandbox
|
|
187
225
|
? new WslSandbox({ wslPath: config.wslPath, maskWindowsDrive: effectiveMaskWindowsDrive(config) })
|
|
188
226
|
: undefined;
|
|
189
227
|
this.processFacts = new Map();
|
|
190
228
|
this.sessionRuntimes = sessionRuntimes;
|
|
191
|
-
this.sessionRuntimeEntries = new Map();
|
|
192
229
|
this.sessionRuntimeOwner = randomUUID();
|
|
193
230
|
this.sessionScopeProbe = (argv) => runCapture(argv);
|
|
194
231
|
this.writableRootsProbe = (argv) => runCapture(argv);
|
|
195
|
-
this.
|
|
196
|
-
this.autoSessionScope = new Map();
|
|
232
|
+
this.socketIsolationProbe = (argv) => runCapture(argv);
|
|
197
233
|
// The preset realm disposes when the session ends; the scope must go with
|
|
198
234
|
// it, or a dev server outlives the session that started it.
|
|
199
235
|
ctx.effect(() => () => this.disposeSessionRuntimes().catch(() => { }), "wsl session runtimes");
|
|
@@ -216,7 +252,7 @@ export class WslShellExecutor extends LocalBashExecutor {
|
|
|
216
252
|
* @returns the distro name.
|
|
217
253
|
*/
|
|
218
254
|
async distro() {
|
|
219
|
-
const config = this.
|
|
255
|
+
const config = this.wslConfig;
|
|
220
256
|
if (this.resolvedDistro.length === 0)
|
|
221
257
|
this.resolvedDistro = await defaultDistro({ wslPath: config.wslPath });
|
|
222
258
|
return this.resolvedDistro;
|
|
@@ -231,7 +267,7 @@ export class WslShellExecutor extends LocalBashExecutor {
|
|
|
231
267
|
* @returns the distro name.
|
|
232
268
|
*/
|
|
233
269
|
async distroFor(workdir, cwd) {
|
|
234
|
-
const config = this.
|
|
270
|
+
const config = this.wslConfig;
|
|
235
271
|
return resolveOperationDistro(config.distro, [workdir, cwd ?? configuredCwd(this.config)], () => this.distro());
|
|
236
272
|
}
|
|
237
273
|
/**
|
|
@@ -264,7 +300,7 @@ export class WslShellExecutor extends LocalBashExecutor {
|
|
|
264
300
|
* shell — the failure is not cached, so the next call re-probes.
|
|
265
301
|
*/
|
|
266
302
|
async shellFor(distro) {
|
|
267
|
-
const config = this.
|
|
303
|
+
const config = this.wslConfig;
|
|
268
304
|
if (config.shell.length > 0)
|
|
269
305
|
return config.shell;
|
|
270
306
|
if (this.resolvedDistro.length > 0 && distro === this.resolvedDistro)
|
|
@@ -288,7 +324,7 @@ export class WslShellExecutor extends LocalBashExecutor {
|
|
|
288
324
|
* shell — the failure is not cached, so the next call re-probes.
|
|
289
325
|
*/
|
|
290
326
|
async shell() {
|
|
291
|
-
const config = this.
|
|
327
|
+
const config = this.wslConfig;
|
|
292
328
|
if (this.resolvedShell.length === 0) {
|
|
293
329
|
const distro = await this.distro();
|
|
294
330
|
// An unresolvable shell fails the command loudly: the probes both came
|
|
@@ -310,7 +346,7 @@ export class WslShellExecutor extends LocalBashExecutor {
|
|
|
310
346
|
* @returns the host directory to spawn in.
|
|
311
347
|
*/
|
|
312
348
|
hostCwd() {
|
|
313
|
-
const config = this.
|
|
349
|
+
const config = this.wslConfig;
|
|
314
350
|
return config.hostCwd.get() ?? process.env.SystemRoot ?? process.cwd();
|
|
315
351
|
}
|
|
316
352
|
/**
|
|
@@ -332,15 +368,15 @@ export class WslShellExecutor extends LocalBashExecutor {
|
|
|
332
368
|
* @param distro - the resolved distro name.
|
|
333
369
|
* @returns the runtime entry, or undefined when the mode is off.
|
|
334
370
|
*/
|
|
335
|
-
sessionRuntimeFor(policy, resolved, distro, writableRoots = []) {
|
|
336
|
-
const config = this.
|
|
371
|
+
sessionRuntimeFor(policy, resolved, distro, writableRoots = [], socketMasks = [], maskInterop = false) {
|
|
372
|
+
const config = this.wslConfig;
|
|
337
373
|
if (!config.sessionSandbox)
|
|
338
374
|
return undefined;
|
|
339
375
|
const mode = policy?.mode ?? "danger-full-access";
|
|
340
376
|
const workspaceRoot = policy?.workspaceRoot ?? (configuredCwd(this.config) || resolved.workdir);
|
|
341
377
|
const sessionId = policy?.sessionId || resolved.dshEnv?.DSH_SESSION_ID || this.sessionRuntimeOwner;
|
|
342
|
-
const key = SessionRuntimes.key({ sessionId, distro, workspaceRoot, mode, maskWindowsDrive: effectiveMaskWindowsDrive(config), writableRoots });
|
|
343
|
-
const held = this.sessionRuntimeEntries.get(key);
|
|
378
|
+
const key = SessionRuntimes.key({ sessionId, distro, workspaceRoot, mode, maskWindowsDrive: effectiveMaskWindowsDrive(config), writableRoots, socketMasks, maskInterop });
|
|
379
|
+
const held = this.runtimeBook.sessionRuntimeEntries.get(key);
|
|
344
380
|
if (held !== undefined)
|
|
345
381
|
return held;
|
|
346
382
|
const entry = this.sessionRuntimes.acquire({
|
|
@@ -351,8 +387,10 @@ export class WslShellExecutor extends LocalBashExecutor {
|
|
|
351
387
|
mode,
|
|
352
388
|
maskWindowsDrive: effectiveMaskWindowsDrive(config),
|
|
353
389
|
writableRoots,
|
|
390
|
+
socketMasks,
|
|
391
|
+
maskInterop,
|
|
354
392
|
});
|
|
355
|
-
this.sessionRuntimeEntries.set(key, entry);
|
|
393
|
+
this.runtimeBook.sessionRuntimeEntries.set(key, entry);
|
|
356
394
|
return entry;
|
|
357
395
|
}
|
|
358
396
|
/**
|
|
@@ -368,14 +406,14 @@ export class WslShellExecutor extends LocalBashExecutor {
|
|
|
368
406
|
* @throws {Error} with the remedy when it cannot.
|
|
369
407
|
*/
|
|
370
408
|
async ensureSessionRuntimeUsable(distro) {
|
|
371
|
-
if (this.sessionRuntimePreflight.has(distro))
|
|
409
|
+
if (this.runtimeBook.sessionRuntimePreflight.has(distro))
|
|
372
410
|
return;
|
|
373
|
-
const config = this.
|
|
411
|
+
const config = this.wslConfig;
|
|
374
412
|
const problem = await probeSessionRuntime({ wslPath: config.wslPath, distro, run: this.sessionScopeProbe });
|
|
375
413
|
if (problem !== null)
|
|
376
414
|
throw new Error(problem);
|
|
377
415
|
await ensureNativeSessionAgent({ wslPath: config.wslPath, distro, setNative: setSessionNativeAgent });
|
|
378
|
-
this.sessionRuntimePreflight.add(distro);
|
|
416
|
+
this.runtimeBook.sessionRuntimePreflight.add(distro);
|
|
379
417
|
}
|
|
380
418
|
/**
|
|
381
419
|
* Whether this executor should use the session runtime for one distro, with
|
|
@@ -386,8 +424,8 @@ export class WslShellExecutor extends LocalBashExecutor {
|
|
|
386
424
|
* @returns whether to acquire the per-session scope.
|
|
387
425
|
*/
|
|
388
426
|
async wantsSessionRuntime(distro) {
|
|
389
|
-
const config = this.
|
|
390
|
-
return sessionRuntimeWanted(config.sessionSandbox, distro, () => this.ensureSessionRuntimeUsable(distro), this.autoSessionScope);
|
|
427
|
+
const config = this.wslConfig;
|
|
428
|
+
return sessionRuntimeWanted(config.sessionSandbox, distro, () => this.ensureSessionRuntimeUsable(distro), this.runtimeBook.autoSessionScope);
|
|
391
429
|
}
|
|
392
430
|
/**
|
|
393
431
|
* Release every runtime this executor holds, stopping each scope. Called
|
|
@@ -397,8 +435,8 @@ export class WslShellExecutor extends LocalBashExecutor {
|
|
|
397
435
|
* @returns resolved once every runtime is torn down.
|
|
398
436
|
*/
|
|
399
437
|
async disposeSessionRuntimes() {
|
|
400
|
-
const entries = [...this.sessionRuntimeEntries.values()];
|
|
401
|
-
this.sessionRuntimeEntries.clear();
|
|
438
|
+
const entries = [...this.runtimeBook.sessionRuntimeEntries.values()];
|
|
439
|
+
this.runtimeBook.sessionRuntimeEntries.clear();
|
|
402
440
|
for (const entry of entries)
|
|
403
441
|
await this.sessionRuntimes.release(entry.key);
|
|
404
442
|
}
|
|
@@ -413,7 +451,7 @@ export class WslShellExecutor extends LocalBashExecutor {
|
|
|
413
451
|
* @returns the distro-side argv.
|
|
414
452
|
*/
|
|
415
453
|
distroArgv(spec, shell) {
|
|
416
|
-
const config = this.
|
|
454
|
+
const config = this.wslConfig;
|
|
417
455
|
return [shell, ...shellArgs(shell, config.loginShell), spec.command];
|
|
418
456
|
}
|
|
419
457
|
/**
|
|
@@ -430,7 +468,7 @@ export class WslShellExecutor extends LocalBashExecutor {
|
|
|
430
468
|
* @returns the argv to spawn.
|
|
431
469
|
*/
|
|
432
470
|
argv(spec, distro, shell, inner) {
|
|
433
|
-
const config = this.
|
|
471
|
+
const config = this.wslConfig;
|
|
434
472
|
const distroArgs = distro.length > 0 ? ["-d", distro] : [];
|
|
435
473
|
return [
|
|
436
474
|
config.wslPath,
|
|
@@ -466,7 +504,7 @@ export class WslShellExecutor extends LocalBashExecutor {
|
|
|
466
504
|
* @returns the subprocess spawn spec.
|
|
467
505
|
*/
|
|
468
506
|
spawnSpec(spec, argv, stdoutMaxBytes, signal) {
|
|
469
|
-
const config = this.
|
|
507
|
+
const config = this.wslConfig;
|
|
470
508
|
const base = inheritedSpawnSpec.call(this, spec, argv, stdoutMaxBytes, signal);
|
|
471
509
|
const forward = new Set([...SAFE_FORWARD, ...config.forwardEnv]);
|
|
472
510
|
const forwarded = Object.keys(base.env ?? {}).filter((name) => forward.has(name) || name.startsWith(DSH_ENV_PREFIX));
|
|
@@ -509,7 +547,7 @@ export class WslShellExecutor extends LocalBashExecutor {
|
|
|
509
547
|
* @returns the fully-resolved spec.
|
|
510
548
|
*/
|
|
511
549
|
resolve(request) {
|
|
512
|
-
const config = this.
|
|
550
|
+
const config = this.wslConfig;
|
|
513
551
|
const spec = super.resolve(request);
|
|
514
552
|
const sandboxPolicy = this.sandbox === undefined ? undefined : (request?.sandboxPolicy ?? this.ctx.sandboxPolicy.resolve());
|
|
515
553
|
const workdir = typeof request?.workdir === "string" ? request.workdir : undefined;
|
|
@@ -648,7 +686,7 @@ export class WslShellExecutor extends LocalBashExecutor {
|
|
|
648
686
|
* @throws {SandboxInvalidRootError} when an entry cannot be granted or checked.
|
|
649
687
|
*/
|
|
650
688
|
async writableRootsFor(distro, policy, signal) {
|
|
651
|
-
const config = this.
|
|
689
|
+
const config = this.wslConfig;
|
|
652
690
|
if (!config.sandbox || policy === undefined || policy.mode !== "workspace-write")
|
|
653
691
|
return [];
|
|
654
692
|
if ((config.writableRoots?.length ?? 0) === 0 && (policy.additionalWritableRoots?.length ?? 0) === 0)
|
|
@@ -669,6 +707,37 @@ export class WslShellExecutor extends LocalBashExecutor {
|
|
|
669
707
|
run: this.writableRootsProbe,
|
|
670
708
|
});
|
|
671
709
|
}
|
|
710
|
+
/**
|
|
711
|
+
* The socket masks one confined command's profile binds, resolved once per
|
|
712
|
+
* distro from the row's `socketIsolation` stance. Empty when the sandbox is
|
|
713
|
+
* off, the command is unconfined, or the stance is `off`. A probe failure is
|
|
714
|
+
* a sandbox refusal, never an unmasked run.
|
|
715
|
+
*
|
|
716
|
+
* @param distro - the distro the command runs in.
|
|
717
|
+
* @param mode - the per-call file-effect mode.
|
|
718
|
+
* @param signal - optional cancellation for the one-time probe.
|
|
719
|
+
* @returns the existing socket paths to mask.
|
|
720
|
+
* @throws {SandboxUnavailableError} when a configured isolation cannot be resolved.
|
|
721
|
+
*/
|
|
722
|
+
async socketMasksFor(distro, mode, signal) {
|
|
723
|
+
const config = this.wslConfig;
|
|
724
|
+
if (!config.sandbox || mode === undefined || mode === "danger-full-access" || config.socketIsolation === "off")
|
|
725
|
+
return [];
|
|
726
|
+
try {
|
|
727
|
+
return await resolveSocketMasks({
|
|
728
|
+
mode: config.socketIsolation,
|
|
729
|
+
wslPath: config.wslPath,
|
|
730
|
+
distro,
|
|
731
|
+
run: this.socketIsolationProbe,
|
|
732
|
+
...(signal === undefined ? {} : { signal }),
|
|
733
|
+
});
|
|
734
|
+
}
|
|
735
|
+
catch (error) {
|
|
736
|
+
if (error instanceof SocketIsolationError)
|
|
737
|
+
throw new SandboxUnavailableError(mode, error.message);
|
|
738
|
+
throw error;
|
|
739
|
+
}
|
|
740
|
+
}
|
|
672
741
|
/**
|
|
673
742
|
* Execute one resolved spec inside the distro, confined by the per-call policy
|
|
674
743
|
* when there is one.
|
|
@@ -683,15 +752,20 @@ export class WslShellExecutor extends LocalBashExecutor {
|
|
|
683
752
|
* @returns the live shell process handle.
|
|
684
753
|
*/
|
|
685
754
|
async execute(spec) {
|
|
686
|
-
const config = this.
|
|
755
|
+
const config = this.wslConfig;
|
|
687
756
|
const resolved = await this.withDefaultWorkdir(spec);
|
|
688
757
|
const distro = await this.distroFor(resolved.workdir, configuredCwd(config));
|
|
689
758
|
const shell = await this.shellFor(distro);
|
|
690
759
|
this.throwIfWorkdirInAnotherDistro(resolved.workdir, distro);
|
|
691
760
|
const writableRoots = await this.writableRootsFor(distro, resolved.sandboxPolicy, resolved.signal);
|
|
761
|
+
const socketMasks = await this.socketMasksFor(distro, resolved.sandboxPolicy?.mode, resolved.signal);
|
|
762
|
+
const maskInterop = config.sandbox
|
|
763
|
+
&& config.socketIsolation === "strict"
|
|
764
|
+
&& resolved.sandboxPolicy !== undefined
|
|
765
|
+
&& resolved.sandboxPolicy.mode !== "danger-full-access";
|
|
692
766
|
if (config.agent) {
|
|
693
767
|
try {
|
|
694
|
-
return await this.executeViaAgent(resolved, distro, shell, writableRoots);
|
|
768
|
+
return await this.executeViaAgent(resolved, distro, shell, writableRoots, socketMasks, maskInterop);
|
|
695
769
|
}
|
|
696
770
|
catch (error) {
|
|
697
771
|
// Only an out-of-service agent falls back; anything else (a cwd
|
|
@@ -700,7 +774,7 @@ export class WslShellExecutor extends LocalBashExecutor {
|
|
|
700
774
|
throw error;
|
|
701
775
|
}
|
|
702
776
|
}
|
|
703
|
-
return this.executeOneShot(resolved, distro, shell, writableRoots);
|
|
777
|
+
return this.executeOneShot(resolved, distro, shell, writableRoots, socketMasks, maskInterop);
|
|
704
778
|
}
|
|
705
779
|
/**
|
|
706
780
|
* Refuse a workdir that names another WSL distro — the shell-side twin of
|
|
@@ -729,15 +803,15 @@ export class WslShellExecutor extends LocalBashExecutor {
|
|
|
729
803
|
* @param shell - the resolved distro shell.
|
|
730
804
|
* @returns the decorated execution result.
|
|
731
805
|
*/
|
|
732
|
-
async executeViaAgent(resolved, distro, shell, writableRoots = []) {
|
|
733
|
-
const config = this.
|
|
806
|
+
async executeViaAgent(resolved, distro, shell, writableRoots = [], socketMasks = [], maskInterop = false) {
|
|
807
|
+
const config = this.wslConfig;
|
|
734
808
|
const policy = resolved.sandboxPolicy;
|
|
735
809
|
const confined = this.sandbox !== undefined && policy !== undefined && policy.mode !== "danger-full-access"
|
|
736
|
-
? await this.sandbox.confine(this.distroArgv(resolved, shell), { ...policy, mode: policy.mode }, { distro, signal: resolved.signal, writableRoots })
|
|
810
|
+
? await this.sandbox.confine(this.distroArgv(resolved, shell), { ...policy, mode: policy.mode }, { distro, signal: resolved.signal, writableRoots, socketMasks, maskInterop })
|
|
737
811
|
: undefined;
|
|
738
812
|
const mode = policy?.mode;
|
|
739
813
|
const useScope = await this.wantsSessionRuntime(distro);
|
|
740
|
-
const runtime = useScope ? this.sessionRuntimeFor(policy, resolved, distro, writableRoots) : undefined;
|
|
814
|
+
const runtime = useScope ? this.sessionRuntimeFor(policy, resolved, distro, writableRoots, socketMasks, maskInterop) : undefined;
|
|
741
815
|
const agent = runtime !== undefined ? runtime.agent : await this.executionAgent(distro);
|
|
742
816
|
// A session runtime's own bwrap profile applies the mounts, so the
|
|
743
817
|
// command must NOT be wrapped a second time: the per-command probe still
|
|
@@ -824,7 +898,7 @@ export class WslShellExecutor extends LocalBashExecutor {
|
|
|
824
898
|
// warning names the directory — the failure path pays the extra spawn,
|
|
825
899
|
// the hot path does not.
|
|
826
900
|
if (error instanceof SpawnError) {
|
|
827
|
-
return this.executeOneShot(resolved, distro, shell, writableRoots).then((fallback) => fallback.result());
|
|
901
|
+
return this.executeOneShot(resolved, distro, shell, writableRoots, socketMasks, maskInterop).then((fallback) => fallback.result());
|
|
828
902
|
}
|
|
829
903
|
throw error;
|
|
830
904
|
});
|
|
@@ -843,7 +917,7 @@ export class WslShellExecutor extends LocalBashExecutor {
|
|
|
843
917
|
* @param shell - the resolved distro shell.
|
|
844
918
|
* @returns the decorated execution result.
|
|
845
919
|
*/
|
|
846
|
-
async executeOneShot(resolved, distro, shell, writableRoots = []) {
|
|
920
|
+
async executeOneShot(resolved, distro, shell, writableRoots = [], socketMasks = [], maskInterop = false) {
|
|
847
921
|
const policy = resolved.sandboxPolicy;
|
|
848
922
|
if (this.sandbox === undefined || policy === undefined || policy.mode === "danger-full-access") {
|
|
849
923
|
// `executeArgv` resolves to the execution handle, so it has to be awaited
|
|
@@ -868,7 +942,7 @@ export class WslShellExecutor extends LocalBashExecutor {
|
|
|
868
942
|
// closures.
|
|
869
943
|
const mode = policy.mode;
|
|
870
944
|
const confinement = { profile: undefined };
|
|
871
|
-
const execution = await this.executeArgv(resolved, (signal) => this.prepareConfinedArgv(resolved, distro, shell, policy, mode, confinement, writableRoots, signal), (process) => this.stampConfinedFacts(resolved, mode, confinement, process));
|
|
945
|
+
const execution = await this.executeArgv(resolved, (signal) => this.prepareConfinedArgv(resolved, distro, shell, policy, mode, confinement, writableRoots, socketMasks, maskInterop, signal), (process) => this.stampConfinedFacts(resolved, mode, confinement, process));
|
|
872
946
|
return WslShellExecutor.decorateResult(execution, (result) => {
|
|
873
947
|
return this.settleConfinedOneShot(result, distro, resolved, mode, confinement.profile);
|
|
874
948
|
}, (error) => {
|
|
@@ -894,13 +968,13 @@ export class WslShellExecutor extends LocalBashExecutor {
|
|
|
894
968
|
* @param writableRoots - the effective extra roots the profile binds.
|
|
895
969
|
* @param signal - the caller's cancellation.
|
|
896
970
|
*/
|
|
897
|
-
async prepareConfinedArgv(resolved, distro, shell, policy, mode, slot, writableRoots, signal) {
|
|
971
|
+
async prepareConfinedArgv(resolved, distro, shell, policy, mode, slot, writableRoots, socketMasks, maskInterop, signal) {
|
|
898
972
|
// Preparation is async, so it runs under executeArgv's deadline and
|
|
899
973
|
// cancellation handling rather than before them. A distro without a
|
|
900
974
|
// usable runner throws here, before anything is spawned. The outer
|
|
901
975
|
// guard narrowed the sandbox in, but narrowings do not reach closures —
|
|
902
976
|
// so the confined sandbox is asserted here, type-level only.
|
|
903
|
-
const profile = await this.sandbox.confine(this.distroArgv(resolved, shell), { ...policy, mode }, { distro, signal, writableRoots });
|
|
977
|
+
const profile = await this.sandbox.confine(this.distroArgv(resolved, shell), { ...policy, mode }, { distro, signal, writableRoots, socketMasks, maskInterop });
|
|
904
978
|
slot.profile = profile;
|
|
905
979
|
signal.throwIfAborted();
|
|
906
980
|
return this.argv(resolved, distro, shell, profile.argv);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-plugin-wsl-env",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.27.0",
|
|
4
4
|
"description": "在 WSL 的 Linux 实例中打开项目工作区,在对应 Linux 空间中进行命令执行、运行 shell 脚本和文件访问,以获得全套 Linux Shell 工具链收益,并通过 bubblewrap 对命令进行沙箱隔离",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"deepseek-harness",
|
|
@@ -79,6 +79,10 @@
|
|
|
79
79
|
},
|
|
80
80
|
"./picker/locale/en.json": "./locale/picker/en.json",
|
|
81
81
|
"./picker/locale/zh.json": "./locale/picker/zh.json",
|
|
82
|
+
"./plugin-update": {
|
|
83
|
+
"types": "./lib/plugin-update.d.ts",
|
|
84
|
+
"default": "./lib/plugin-update.js"
|
|
85
|
+
},
|
|
82
86
|
"./preflight": {
|
|
83
87
|
"types": "./lib/preflight.d.ts",
|
|
84
88
|
"default": "./lib/preflight.js"
|
|
@@ -215,9 +219,9 @@
|
|
|
215
219
|
"build": "node scripts/build.mjs",
|
|
216
220
|
"lint:build": "node test/build-freshness.mjs",
|
|
217
221
|
"test:browser": "node --test --test-timeout=120000 test/browser/e2e.test.mjs",
|
|
218
|
-
"test:coverage": "node scripts/coverage-gate.mjs -- node --test --test-timeout=60000 --experimental-test-coverage --test-coverage-lines=85 --test-coverage-branches=84 --test-coverage-functions=70 --test-coverage-exclude='scripts/**' --test-coverage-exclude='test/**' test/agent-exec.test.mjs test/agent-fs-script.test.mjs test/agent-protocol.test.mjs test/agent.test.mjs test/fs-substrate.test.mjs test/fs.boot.test.mjs test/composition.test.mjs test/bundle-mount.test.mjs test/hot-swap.test.mjs test/takeover-report.test.mjs test/provider.test.mjs test/provider-takeover.test.mjs test/file-reference-wsl.test.mjs test/fsio-agent.test.mjs test/fsio-text.test.mjs test/git-exec.test.mjs test/git-route.test.mjs test/listing.test.mjs test/paths.test.mjs test/ports.test.mjs test/preset-choice.test.mjs test/auto-preset.test.mjs test/probe-cache.test.mjs test/writable-roots.test.mjs test/preflight.test.mjs test/sandbox.test.mjs test/search-exec.test.mjs test/search-route.test.mjs test/shell.test.mjs test/shell-env.test.mjs test/terminal-activity.test.mjs test/terminal.test.mjs test/watcher.test.mjs test/wsl.test.mjs test/fs-decisions.test.mjs test/session-scope.test.mjs test/session-runtime.test.mjs test/native-agent.test.mjs test/peers.test.mjs test/agent-shared.test.mjs test/distro-route.test.mjs test/fs-routing.test.mjs test/update-check.test.mjs test/doctor.test.mjs test/doctor-collector.test.mjs test/release-scripts.test.mjs test/profile-preset.test.mjs test/packaging.test.mjs test/peer-canary.test.mjs test/probe-runner.test.mjs test/cwd-prompt.test.mjs test/cwd-prompt-tool.test.mjs test/wsl-doctor-tool.test.mjs test/wsl-doctor-command.test.mjs test/status.test.mjs test/client-host.test.mjs test/messages.test.mjs test/locales-examples.test.mjs test/client.test.mjs test/open-in-app.test.mjs",
|
|
222
|
+
"test:coverage": "node scripts/coverage-gate.mjs -- node --test --test-timeout=60000 --experimental-test-coverage --test-coverage-lines=85 --test-coverage-branches=84 --test-coverage-functions=70 --test-coverage-exclude='scripts/**' --test-coverage-exclude='test/**' test/agent-exec.test.mjs test/agent-fs-script.test.mjs test/agent-protocol.test.mjs test/agent.test.mjs test/fs-substrate.test.mjs test/fs.boot.test.mjs test/composition.test.mjs test/bundle-mount.test.mjs test/hot-swap.test.mjs test/takeover-report.test.mjs test/provider.test.mjs test/provider-takeover.test.mjs test/file-reference-wsl.test.mjs test/fsio-agent.test.mjs test/fsio-text.test.mjs test/git-exec.test.mjs test/git-route.test.mjs test/listing.test.mjs test/paths.test.mjs test/ports.test.mjs test/preset-choice.test.mjs test/auto-preset.test.mjs test/probe-cache.test.mjs test/writable-roots.test.mjs test/preflight.test.mjs test/sandbox.test.mjs test/socket-isolation.test.mjs test/search-exec.test.mjs test/search-route.test.mjs test/shell.test.mjs test/shell-env.test.mjs test/terminal-activity.test.mjs test/terminal.test.mjs test/watcher.test.mjs test/wsl.test.mjs test/fs-decisions.test.mjs test/session-scope.test.mjs test/session-runtime.test.mjs test/native-agent.test.mjs test/peers.test.mjs test/agent-shared.test.mjs test/distro-route.test.mjs test/fs-routing.test.mjs test/update-check.test.mjs test/plugin-update.test.mjs test/doctor.test.mjs test/doctor-collector.test.mjs test/release-scripts.test.mjs test/profile-preset.test.mjs test/packaging.test.mjs test/peer-canary.test.mjs test/probe-runner.test.mjs test/cwd-prompt.test.mjs test/cwd-prompt-tool.test.mjs test/wsl-doctor-tool.test.mjs test/wsl-doctor-command.test.mjs test/status.test.mjs test/client-host.test.mjs test/messages.test.mjs test/locales-examples.test.mjs test/client.test.mjs test/open-in-app.test.mjs",
|
|
219
223
|
"test:syntax": "node test/syntax.mjs",
|
|
220
|
-
"test:unit": "node scripts/test-watchdog.mjs -- node --test --test-timeout=60000 test/fs.boot.test.mjs test/fsio-text.test.mjs test/composition.test.mjs test/bundle-mount.test.mjs test/hot-swap.test.mjs test/takeover-report.test.mjs test/provider.test.mjs test/provider-takeover.test.mjs test/file-reference-wsl.test.mjs test/paths.test.mjs test/listing.test.mjs test/shell.test.mjs test/shell-env.test.mjs test/terminal.test.mjs test/probe-cache.test.mjs test/writable-roots.test.mjs test/preflight.test.mjs test/preset-choice.test.mjs test/auto-preset.test.mjs test/sandbox.test.mjs test/agent-protocol.test.mjs test/agent.test.mjs test/agent-fs-script.test.mjs test/fsio-agent.test.mjs test/fs-substrate.test.mjs test/agent-exec.test.mjs test/ports.test.mjs test/watcher.test.mjs test/wsl.test.mjs test/fs-decisions.test.mjs test/git-exec.test.mjs test/git-route.test.mjs test/search-route.test.mjs test/search-exec.test.mjs test/terminal-activity.test.mjs test/session-scope.test.mjs test/session-runtime.test.mjs test/native-agent.test.mjs test/peers.test.mjs test/agent-shared.test.mjs test/distro-route.test.mjs test/fs-routing.test.mjs test/update-check.test.mjs test/doctor.test.mjs test/doctor-collector.test.mjs test/release-scripts.test.mjs test/profile-preset.test.mjs test/packaging.test.mjs test/peer-canary.test.mjs test/probe-runner.test.mjs test/cwd-prompt.test.mjs test/cwd-prompt-tool.test.mjs test/wsl-doctor-tool.test.mjs test/wsl-doctor-command.test.mjs test/status.test.mjs test/client-host.test.mjs test/messages.test.mjs test/locales-examples.test.mjs test/client.test.mjs test/open-in-app.test.mjs",
|
|
224
|
+
"test:unit": "node scripts/test-watchdog.mjs -- node --test --test-timeout=60000 test/fs.boot.test.mjs test/fsio-text.test.mjs test/composition.test.mjs test/bundle-mount.test.mjs test/hot-swap.test.mjs test/takeover-report.test.mjs test/provider.test.mjs test/provider-takeover.test.mjs test/file-reference-wsl.test.mjs test/paths.test.mjs test/listing.test.mjs test/shell.test.mjs test/shell-env.test.mjs test/terminal.test.mjs test/probe-cache.test.mjs test/writable-roots.test.mjs test/preflight.test.mjs test/preset-choice.test.mjs test/auto-preset.test.mjs test/sandbox.test.mjs test/socket-isolation.test.mjs test/agent-protocol.test.mjs test/agent.test.mjs test/agent-fs-script.test.mjs test/fsio-agent.test.mjs test/fs-substrate.test.mjs test/agent-exec.test.mjs test/ports.test.mjs test/watcher.test.mjs test/wsl.test.mjs test/fs-decisions.test.mjs test/git-exec.test.mjs test/git-route.test.mjs test/search-route.test.mjs test/search-exec.test.mjs test/terminal-activity.test.mjs test/session-scope.test.mjs test/session-runtime.test.mjs test/native-agent.test.mjs test/peers.test.mjs test/agent-shared.test.mjs test/distro-route.test.mjs test/fs-routing.test.mjs test/update-check.test.mjs test/plugin-update.test.mjs test/doctor.test.mjs test/doctor-collector.test.mjs test/release-scripts.test.mjs test/profile-preset.test.mjs test/packaging.test.mjs test/peer-canary.test.mjs test/probe-runner.test.mjs test/cwd-prompt.test.mjs test/cwd-prompt-tool.test.mjs test/wsl-doctor-tool.test.mjs test/wsl-doctor-command.test.mjs test/status.test.mjs test/client-host.test.mjs test/messages.test.mjs test/locales-examples.test.mjs test/client.test.mjs test/open-in-app.test.mjs",
|
|
221
225
|
"lint:style": "node test/style.mjs",
|
|
222
226
|
"lint:links": "node scripts/check-links.mjs",
|
|
223
227
|
"lint:requirements": "node scripts/check-requirements.mjs",
|
|
@@ -232,6 +236,7 @@
|
|
|
232
236
|
"probe:sandbox-off": "bash test/probe/sandbox-off.sh",
|
|
233
237
|
"probe:terminal": "bash test/probe/terminal.sh",
|
|
234
238
|
"probe:sandbox": "bash test/probe/sandbox.sh",
|
|
239
|
+
"probe:cache-write": "bash test/probe/cache-write.sh",
|
|
235
240
|
"probe:sandbox-shell": "bash test/probe/sandbox-shell.sh",
|
|
236
241
|
"probe:interop-shell": "bash test/probe/interop-shell.sh",
|
|
237
242
|
"sync:windows": "bash test/probe/sync-to-windows.sh",
|