dsh-plugin-wsl-env 0.26.3 → 0.26.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/CHANGELOG.md +81 -0
  2. package/CONTRIBUTING.md +25 -21
  3. package/SUPPORT.md +2 -2
  4. package/SUPPORT.zh.md +2 -2
  5. package/docs/AGENT-PROTOCOL-V7.md +4 -2
  6. package/docs/API.md +1 -0
  7. package/docs/API.zh.md +1 -0
  8. package/docs/CONFIGURATION.md +21 -5
  9. package/docs/CONFIGURATION.zh.md +17 -3
  10. package/docs/PARITY.md +3 -1
  11. package/docs/RELEASING.md +25 -3
  12. package/docs/REQUIREMENTS.zh.md +4 -4
  13. package/docs/ROADMAP-1.0.md +11 -7
  14. package/lib/agent.d.ts +54 -18
  15. package/lib/agent.js +86 -19
  16. package/lib/fs-routing.d.ts +3 -0
  17. package/lib/fs-routing.js +5 -0
  18. package/lib/fs-substrate.d.ts +1 -1
  19. package/lib/fs-substrate.js +10 -18
  20. package/lib/fsio-agent.d.ts +4 -0
  21. package/lib/fsio-agent.js +37 -10
  22. package/lib/listing.d.ts +2 -2
  23. package/lib/listing.js +5 -4
  24. package/lib/messages.d.ts +70 -0
  25. package/lib/messages.js +80 -0
  26. package/lib/open-in-app.js +12 -9
  27. package/lib/picker.d.ts +4 -1
  28. package/lib/picker.js +35 -11
  29. package/lib/ports.js +8 -1
  30. package/lib/provider-common.d.ts +22 -0
  31. package/lib/provider-common.js +18 -0
  32. package/lib/provider-marker.d.ts +23 -0
  33. package/lib/provider-marker.js +21 -0
  34. package/lib/status.js +8 -5
  35. package/lib/subprocess.d.ts +3 -0
  36. package/lib/subprocess.js +5 -0
  37. package/lib/takeover-report.js +4 -11
  38. package/lib/watcher.d.ts +1 -1
  39. package/lib/watcher.js +1 -1
  40. package/lib/wsl-doctor-command.d.ts +6 -2
  41. package/lib/wsl-doctor-command.js +24 -15
  42. package/lib/wsl-filesystem.d.ts +14 -11
  43. package/lib/wsl-filesystem.js +39 -27
  44. package/lib/wsl-shell.d.ts +42 -37
  45. package/lib/wsl-shell.js +53 -42
  46. package/package.json +1 -1
package/lib/wsl-shell.js CHANGED
@@ -14,7 +14,7 @@ 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 { configuredCwd, distroHome, effectiveMaskWindowsDrive, effectiveWritableRoots, resolveOperationDistro, sessionRuntimeWanted } from "./provider-common.js";
17
+ import { ProviderRuntimeBook, configuredCwd, distroHome, effectiveMaskWindowsDrive, effectiveWritableRoots, resolveOperationDistro, sessionRuntimeWanted } from "./provider-common.js";
18
18
  /**
19
19
  * Every model shell call gets a rebuilt managed `DSH_*` namespace (see
20
20
  * `dsh-shell-env` / `ctx.shellEnv`). Those names exist only in the Windows-side
@@ -34,8 +34,6 @@ const SAFE_FORWARD = ["NO_COLOR", "TERM", "PAGER", "GIT_PAGER", "LANG", "LC_ALL"
34
34
  const inheritedSpawnSpec = LocalBashExecutor.prototype.spawnSpec;
35
35
  /**
36
36
  * 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
37
  * command must not quietly run under some other interpreter. The wording is
40
38
  * the one `runInDistro` already throws with.
41
39
  *
@@ -86,19 +84,6 @@ export class WslShellExecutor extends LocalBashExecutor {
86
84
  * unconfined and `sandboxMode` is `undefined`, so the model is told so.
87
85
  */
88
86
  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
87
  /**
103
88
  * The interop stance in one key (WSL-314), expanding to the per-key
104
89
  * values the measured matrix documents:
@@ -119,6 +104,20 @@ export class WslShellExecutor extends LocalBashExecutor {
119
104
  * boolean answer); the boolean remains for existing profiles.
120
105
  */
121
106
  interopVisibility: z.union(["visible", "masked", "disabled"]),
107
+ /**
108
+ * Shadow `/mnt` with an empty tmpfs in every confined profile, hiding the
109
+ * Windows drive from confined commands: its files cannot be read or
110
+ * exfiltrated and its executables cannot be launched through interop —
111
+ * the hole that lets a "sandboxed" command reach your full Windows token.
112
+ * A narrowing, not a closure (a command can still write an executable
113
+ * into the workspace and run it — binfmt dispatches on content, not
114
+ * location), so enforcement stays `partial` and the sandbox fact reports
115
+ * `windowsDrive: "masked"`. Costs: confined commands cannot read or touch
116
+ * anything under `/mnt`, and tools that probe the drive degrade. The
117
+ * complete closure is distro-level: `[interop] enabled=false` in
118
+ * `wsl.conf`. The mask covers the COMMAND path only; the file tools'
119
+ * read side still reaches `/mnt` through the shared read agent.
120
+ */
122
121
  maskWindowsDrive: z.boolean().default(false),
123
122
  /**
124
123
  * Extra directories under `workspace-write`, in distro spelling. The
@@ -168,6 +167,21 @@ export class WslShellExecutor extends LocalBashExecutor {
168
167
  */
169
168
  sessionSandbox: z.union([z.boolean(), z.const("auto")]).default(false),
170
169
  });
170
+ /**
171
+ * Per-distro homes, delegated to the shared runtime book: `provider-common`'s
172
+ * `distroHome` reads this view, and tests pin the cache through it.
173
+ */
174
+ get resolvedHomes() {
175
+ return this.runtimeBook.homes;
176
+ }
177
+ /**
178
+ * The row's config without the peer's volatile wrapper. The schema validates
179
+ * the plain shape; the wrapper only widens the type, so one accessor states
180
+ * the cast instead of every method repeating it.
181
+ */
182
+ get wslConfig() {
183
+ return this.config;
184
+ }
171
185
  /**
172
186
  * @param ctx - the composition context.
173
187
  * @param config - the validated plugin config.
@@ -181,19 +195,16 @@ export class WslShellExecutor extends LocalBashExecutor {
181
195
  this.resolvedShell = config.shell;
182
196
  this.resolvedShells = new Map();
183
197
  this.resolvedHome = undefined;
184
- this.resolvedHomes = new Map();
198
+ this.runtimeBook = new ProviderRuntimeBook();
185
199
  this.mode = config.sandbox ? ctx.sandboxPolicy.defaultMode : undefined;
186
200
  this.sandbox = config.sandbox
187
201
  ? new WslSandbox({ wslPath: config.wslPath, maskWindowsDrive: effectiveMaskWindowsDrive(config) })
188
202
  : undefined;
189
203
  this.processFacts = new Map();
190
204
  this.sessionRuntimes = sessionRuntimes;
191
- this.sessionRuntimeEntries = new Map();
192
205
  this.sessionRuntimeOwner = randomUUID();
193
206
  this.sessionScopeProbe = (argv) => runCapture(argv);
194
207
  this.writableRootsProbe = (argv) => runCapture(argv);
195
- this.sessionRuntimePreflight = new Set();
196
- this.autoSessionScope = new Map();
197
208
  // The preset realm disposes when the session ends; the scope must go with
198
209
  // it, or a dev server outlives the session that started it.
199
210
  ctx.effect(() => () => this.disposeSessionRuntimes().catch(() => { }), "wsl session runtimes");
@@ -216,7 +227,7 @@ export class WslShellExecutor extends LocalBashExecutor {
216
227
  * @returns the distro name.
217
228
  */
218
229
  async distro() {
219
- const config = this.config;
230
+ const config = this.wslConfig;
220
231
  if (this.resolvedDistro.length === 0)
221
232
  this.resolvedDistro = await defaultDistro({ wslPath: config.wslPath });
222
233
  return this.resolvedDistro;
@@ -231,7 +242,7 @@ export class WslShellExecutor extends LocalBashExecutor {
231
242
  * @returns the distro name.
232
243
  */
233
244
  async distroFor(workdir, cwd) {
234
- const config = this.config;
245
+ const config = this.wslConfig;
235
246
  return resolveOperationDistro(config.distro, [workdir, cwd ?? configuredCwd(this.config)], () => this.distro());
236
247
  }
237
248
  /**
@@ -264,7 +275,7 @@ export class WslShellExecutor extends LocalBashExecutor {
264
275
  * shell — the failure is not cached, so the next call re-probes.
265
276
  */
266
277
  async shellFor(distro) {
267
- const config = this.config;
278
+ const config = this.wslConfig;
268
279
  if (config.shell.length > 0)
269
280
  return config.shell;
270
281
  if (this.resolvedDistro.length > 0 && distro === this.resolvedDistro)
@@ -288,7 +299,7 @@ export class WslShellExecutor extends LocalBashExecutor {
288
299
  * shell — the failure is not cached, so the next call re-probes.
289
300
  */
290
301
  async shell() {
291
- const config = this.config;
302
+ const config = this.wslConfig;
292
303
  if (this.resolvedShell.length === 0) {
293
304
  const distro = await this.distro();
294
305
  // An unresolvable shell fails the command loudly: the probes both came
@@ -310,7 +321,7 @@ export class WslShellExecutor extends LocalBashExecutor {
310
321
  * @returns the host directory to spawn in.
311
322
  */
312
323
  hostCwd() {
313
- const config = this.config;
324
+ const config = this.wslConfig;
314
325
  return config.hostCwd.get() ?? process.env.SystemRoot ?? process.cwd();
315
326
  }
316
327
  /**
@@ -333,14 +344,14 @@ export class WslShellExecutor extends LocalBashExecutor {
333
344
  * @returns the runtime entry, or undefined when the mode is off.
334
345
  */
335
346
  sessionRuntimeFor(policy, resolved, distro, writableRoots = []) {
336
- const config = this.config;
347
+ const config = this.wslConfig;
337
348
  if (!config.sessionSandbox)
338
349
  return undefined;
339
350
  const mode = policy?.mode ?? "danger-full-access";
340
351
  const workspaceRoot = policy?.workspaceRoot ?? (configuredCwd(this.config) || resolved.workdir);
341
352
  const sessionId = policy?.sessionId || resolved.dshEnv?.DSH_SESSION_ID || this.sessionRuntimeOwner;
342
353
  const key = SessionRuntimes.key({ sessionId, distro, workspaceRoot, mode, maskWindowsDrive: effectiveMaskWindowsDrive(config), writableRoots });
343
- const held = this.sessionRuntimeEntries.get(key);
354
+ const held = this.runtimeBook.sessionRuntimeEntries.get(key);
344
355
  if (held !== undefined)
345
356
  return held;
346
357
  const entry = this.sessionRuntimes.acquire({
@@ -352,7 +363,7 @@ export class WslShellExecutor extends LocalBashExecutor {
352
363
  maskWindowsDrive: effectiveMaskWindowsDrive(config),
353
364
  writableRoots,
354
365
  });
355
- this.sessionRuntimeEntries.set(key, entry);
366
+ this.runtimeBook.sessionRuntimeEntries.set(key, entry);
356
367
  return entry;
357
368
  }
358
369
  /**
@@ -368,14 +379,14 @@ export class WslShellExecutor extends LocalBashExecutor {
368
379
  * @throws {Error} with the remedy when it cannot.
369
380
  */
370
381
  async ensureSessionRuntimeUsable(distro) {
371
- if (this.sessionRuntimePreflight.has(distro))
382
+ if (this.runtimeBook.sessionRuntimePreflight.has(distro))
372
383
  return;
373
- const config = this.config;
384
+ const config = this.wslConfig;
374
385
  const problem = await probeSessionRuntime({ wslPath: config.wslPath, distro, run: this.sessionScopeProbe });
375
386
  if (problem !== null)
376
387
  throw new Error(problem);
377
388
  await ensureNativeSessionAgent({ wslPath: config.wslPath, distro, setNative: setSessionNativeAgent });
378
- this.sessionRuntimePreflight.add(distro);
389
+ this.runtimeBook.sessionRuntimePreflight.add(distro);
379
390
  }
380
391
  /**
381
392
  * Whether this executor should use the session runtime for one distro, with
@@ -386,8 +397,8 @@ export class WslShellExecutor extends LocalBashExecutor {
386
397
  * @returns whether to acquire the per-session scope.
387
398
  */
388
399
  async wantsSessionRuntime(distro) {
389
- const config = this.config;
390
- return sessionRuntimeWanted(config.sessionSandbox, distro, () => this.ensureSessionRuntimeUsable(distro), this.autoSessionScope);
400
+ const config = this.wslConfig;
401
+ return sessionRuntimeWanted(config.sessionSandbox, distro, () => this.ensureSessionRuntimeUsable(distro), this.runtimeBook.autoSessionScope);
391
402
  }
392
403
  /**
393
404
  * Release every runtime this executor holds, stopping each scope. Called
@@ -397,8 +408,8 @@ export class WslShellExecutor extends LocalBashExecutor {
397
408
  * @returns resolved once every runtime is torn down.
398
409
  */
399
410
  async disposeSessionRuntimes() {
400
- const entries = [...this.sessionRuntimeEntries.values()];
401
- this.sessionRuntimeEntries.clear();
411
+ const entries = [...this.runtimeBook.sessionRuntimeEntries.values()];
412
+ this.runtimeBook.sessionRuntimeEntries.clear();
402
413
  for (const entry of entries)
403
414
  await this.sessionRuntimes.release(entry.key);
404
415
  }
@@ -413,7 +424,7 @@ export class WslShellExecutor extends LocalBashExecutor {
413
424
  * @returns the distro-side argv.
414
425
  */
415
426
  distroArgv(spec, shell) {
416
- const config = this.config;
427
+ const config = this.wslConfig;
417
428
  return [shell, ...shellArgs(shell, config.loginShell), spec.command];
418
429
  }
419
430
  /**
@@ -430,7 +441,7 @@ export class WslShellExecutor extends LocalBashExecutor {
430
441
  * @returns the argv to spawn.
431
442
  */
432
443
  argv(spec, distro, shell, inner) {
433
- const config = this.config;
444
+ const config = this.wslConfig;
434
445
  const distroArgs = distro.length > 0 ? ["-d", distro] : [];
435
446
  return [
436
447
  config.wslPath,
@@ -466,7 +477,7 @@ export class WslShellExecutor extends LocalBashExecutor {
466
477
  * @returns the subprocess spawn spec.
467
478
  */
468
479
  spawnSpec(spec, argv, stdoutMaxBytes, signal) {
469
- const config = this.config;
480
+ const config = this.wslConfig;
470
481
  const base = inheritedSpawnSpec.call(this, spec, argv, stdoutMaxBytes, signal);
471
482
  const forward = new Set([...SAFE_FORWARD, ...config.forwardEnv]);
472
483
  const forwarded = Object.keys(base.env ?? {}).filter((name) => forward.has(name) || name.startsWith(DSH_ENV_PREFIX));
@@ -509,7 +520,7 @@ export class WslShellExecutor extends LocalBashExecutor {
509
520
  * @returns the fully-resolved spec.
510
521
  */
511
522
  resolve(request) {
512
- const config = this.config;
523
+ const config = this.wslConfig;
513
524
  const spec = super.resolve(request);
514
525
  const sandboxPolicy = this.sandbox === undefined ? undefined : (request?.sandboxPolicy ?? this.ctx.sandboxPolicy.resolve());
515
526
  const workdir = typeof request?.workdir === "string" ? request.workdir : undefined;
@@ -648,7 +659,7 @@ export class WslShellExecutor extends LocalBashExecutor {
648
659
  * @throws {SandboxInvalidRootError} when an entry cannot be granted or checked.
649
660
  */
650
661
  async writableRootsFor(distro, policy, signal) {
651
- const config = this.config;
662
+ const config = this.wslConfig;
652
663
  if (!config.sandbox || policy === undefined || policy.mode !== "workspace-write")
653
664
  return [];
654
665
  if ((config.writableRoots?.length ?? 0) === 0 && (policy.additionalWritableRoots?.length ?? 0) === 0)
@@ -683,7 +694,7 @@ export class WslShellExecutor extends LocalBashExecutor {
683
694
  * @returns the live shell process handle.
684
695
  */
685
696
  async execute(spec) {
686
- const config = this.config;
697
+ const config = this.wslConfig;
687
698
  const resolved = await this.withDefaultWorkdir(spec);
688
699
  const distro = await this.distroFor(resolved.workdir, configuredCwd(config));
689
700
  const shell = await this.shellFor(distro);
@@ -730,7 +741,7 @@ export class WslShellExecutor extends LocalBashExecutor {
730
741
  * @returns the decorated execution result.
731
742
  */
732
743
  async executeViaAgent(resolved, distro, shell, writableRoots = []) {
733
- const config = this.config;
744
+ const config = this.wslConfig;
734
745
  const policy = resolved.sandboxPolicy;
735
746
  const confined = this.sandbox !== undefined && policy !== undefined && policy.mode !== "danger-full-access"
736
747
  ? await this.sandbox.confine(this.distroArgv(resolved, shell), { ...policy, mode: policy.mode }, { distro, signal: resolved.signal, writableRoots })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-plugin-wsl-env",
3
- "version": "0.26.3",
3
+ "version": "0.26.4",
4
4
  "description": "在 WSL 的 Linux 实例中打开项目工作区,在对应 Linux 空间中进行命令执行、运行 shell 脚本和文件访问,以获得全套 Linux Shell 工具链收益,并通过 bubblewrap 对命令进行沙箱隔离",
5
5
  "keywords": [
6
6
  "deepseek-harness",