dsh-plugin-wsl-env 0.28.0 → 0.29.1

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 (81) hide show
  1. package/CHANGELOG.md +368 -0
  2. package/CONTRIBUTING.md +68 -12
  3. package/CONTRIBUTING.zh.md +34 -4
  4. package/README.md +1 -1
  5. package/agent/native/linux-aarch64/dsh-wsl-agent +0 -0
  6. package/agent/native/linux-x86_64/dsh-wsl-agent +0 -0
  7. package/agent/wsl-agent.sh +15 -4
  8. package/client.js +540 -160
  9. package/cordis.patch.yml +28 -7
  10. package/docs/AGENT-PROTOCOL-V7.md +4 -2
  11. package/docs/API.md +1 -1
  12. package/docs/API.zh.md +1 -1
  13. package/docs/ARCHITECTURE.md +7 -4
  14. package/docs/ARCHITECTURE.zh.md +6 -4
  15. package/docs/COMPATIBILITY.md +1 -1
  16. package/docs/COMPATIBILITY.zh.md +1 -1
  17. package/docs/CONFIGURATION.md +28 -15
  18. package/docs/CONFIGURATION.zh.md +20 -11
  19. package/docs/DIAGNOSTICS.md +45 -19
  20. package/docs/DIAGNOSTICS.zh.md +33 -15
  21. package/docs/LIMITATIONS.md +70 -10
  22. package/docs/LIMITATIONS.zh.md +53 -8
  23. package/docs/PERFORMANCE.md +29 -1
  24. package/docs/PERFORMANCE.zh.md +23 -1
  25. package/docs/QUICKSTART.md +21 -15
  26. package/docs/QUICKSTART.zh.md +13 -11
  27. package/docs/README.zh.md +1 -1
  28. package/docs/RELEASING.md +29 -6
  29. package/docs/RELEASING.zh.md +9 -0
  30. package/docs/adr/0002-native-agent.md +50 -2
  31. package/lib/agent-confined.js +15 -4
  32. package/lib/agent-errors.d.ts +16 -0
  33. package/lib/agent-errors.js +19 -0
  34. package/lib/agent-exec.d.ts +8 -1
  35. package/lib/agent-exec.js +2 -1
  36. package/lib/agent-shared.d.ts +85 -2
  37. package/lib/agent-shared.js +167 -38
  38. package/lib/agent.d.ts +60 -6
  39. package/lib/agent.js +177 -28
  40. package/lib/auto-preset.js +7 -2
  41. package/lib/doctor-live.d.ts +36 -7
  42. package/lib/doctor-live.js +61 -12
  43. package/lib/doctor-process.d.ts +68 -0
  44. package/lib/doctor-process.js +139 -0
  45. package/lib/doctor-report.js +11 -109
  46. package/lib/fs-substrate.js +3 -3
  47. package/lib/fsio-agent.d.ts +57 -6
  48. package/lib/fsio-agent.js +168 -75
  49. package/lib/git-exec.d.ts +7 -1
  50. package/lib/git-exec.js +14 -2
  51. package/lib/native-agent.d.ts +25 -4
  52. package/lib/native-agent.js +52 -9
  53. package/lib/picker.d.ts +2 -1
  54. package/lib/picker.js +30 -13
  55. package/lib/plugin-update.js +18 -14
  56. package/lib/provider-common.d.ts +112 -0
  57. package/lib/provider-common.js +171 -0
  58. package/lib/sandbox-core.js +52 -13
  59. package/lib/search-exec.d.ts +6 -0
  60. package/lib/search-exec.js +10 -2
  61. package/lib/session-runtime.d.ts +46 -1
  62. package/lib/session-runtime.js +57 -7
  63. package/lib/session-scope.d.ts +22 -1
  64. package/lib/session-scope.js +33 -7
  65. package/lib/shell-env.js +125 -12
  66. package/lib/socket-isolation.d.ts +12 -4
  67. package/lib/socket-isolation.js +27 -10
  68. package/lib/status.d.ts +7 -4
  69. package/lib/status.js +72 -16
  70. package/lib/subprocess.js +3 -3
  71. package/lib/terminal-activity.js +6 -9
  72. package/lib/wsl-doctor-command.js +36 -80
  73. package/lib/wsl-filesystem.d.ts +9 -4
  74. package/lib/wsl-filesystem.js +26 -10
  75. package/lib/wsl-shell.d.ts +27 -17
  76. package/lib/wsl-shell.js +83 -24
  77. package/lib/wsl.d.ts +3 -1
  78. package/lib/wsl.js +82 -7
  79. package/package.json +5 -4
  80. package/scripts/bootstrap.sh +36 -12
  81. package/scripts/doctor.mjs +514 -201
package/lib/wsl-shell.js CHANGED
@@ -6,7 +6,7 @@ import { isAnotherDistrosUnc, isRelativeWorldPath, toLinuxPath } from "./paths.j
6
6
  import { pinnedDistro } from "./distro-route.js";
7
7
  import { WslSandbox } from "./sandbox.js";
8
8
  import { withBwrapHint } from "./sandbox-core.js";
9
- import { AgentUnavailableError, SpawnError } from "./agent-errors.js";
9
+ import { AgentRequestStateUnknownError, AgentUnavailableError, SpawnError } from "./agent-errors.js";
10
10
  import { agentExecutionHandle } from "./agent-exec.js";
11
11
  import { sharedAgent } from "./agent-shared.js";
12
12
  import { SessionRuntimes, probeSessionRuntime, sessionRuntimes, setSessionNativeAgent } from "./session-runtime.js";
@@ -15,7 +15,21 @@ 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
17
  import { SocketIsolationError, socketMasksFor as resolveSocketMasks } from "./socket-isolation.js";
18
- import { ProviderRuntimeBook, configuredCwd, distroHome, effectiveMaskWindowsDrive, effectiveWritableRoots, resolveOperationDistro, sessionRuntimeWanted } from "./provider-common.js";
18
+ import { ProviderRuntimeBook, SessionEndWatch, configuredCwd, distroHome, effectiveMaskWindowsDrive, effectiveWritableRoots, resolveOperationDistro, sessionRuntimeWanted } from "./provider-common.js";
19
+ /**
20
+ * Whether one rejection is the executor's cue to run the command again on the
21
+ * one-shot `wsl.exe` path: the resident is out AND the command provably never
22
+ * reached a distro process through it. A request that was with the resident
23
+ * when it was lost may have run — {@link AgentRequestStateUnknownError} — and
24
+ * re-running it there would run non-idempotent work twice, or report a create
25
+ * that succeeded as a refusal, so it is not a cue.
26
+ *
27
+ * @param error - the rejection the agent path settled with.
28
+ * @returns true when the command may be retried one-shot.
29
+ */
30
+ function isFallbackCue(error) {
31
+ return error instanceof AgentUnavailableError && !(error instanceof AgentRequestStateUnknownError);
32
+ }
19
33
  /**
20
34
  * Every model shell call gets a rebuilt managed `DSH_*` namespace (see
21
35
  * `dsh-shell-env` / `ctx.shellEnv`). Those names exist only in the Windows-side
@@ -174,9 +188,11 @@ export class WslShellExecutor extends LocalBashExecutor {
174
188
  /**
175
189
  * Run commands through the resident agent when it is up (one long-lived
176
190
  * in-distro process; in-distro timeout semantics), falling back to the
177
- * one-shot `wsl.exe` path whenever the agent is out. `false` never uses
178
- * the agent. The confinement, the output budgets' shapes and the result
179
- * decoration are identical on both paths.
191
+ * one-shot `wsl.exe` path whenever the agent is out and the command had
192
+ * not reached it. A command that was in flight when the resident died is
193
+ * not run again — its state is unknown — and fails saying so. `false`
194
+ * never uses the agent. The confinement, the output budgets' shapes and
195
+ * the result decoration are identical on both paths.
180
196
  */
181
197
  agent: z.boolean().default(true),
182
198
  agentBackend: z.union(["auto", "native", "shell"]).default("auto"),
@@ -184,8 +200,8 @@ export class WslShellExecutor extends LocalBashExecutor {
184
200
  * Run this session's commands in one persistent systemd user scope (ADR
185
201
  * 0001): background processes survive the command that started them, `/tmp`
186
202
  * is the distro's real `/tmp` under workspace-write, and `ps` sees the
187
- * session. The executor holds the runtime until the session's scope
188
- * disposes, then stops it. Requires systemd, a reachable user manager and
203
+ * session. The executor holds the runtime until the session's agent is
204
+ * disposed, then stops it. Requires systemd, a reachable user manager and
189
205
  * `Linger`; the preflight refuses with the remedy when one is missing, and
190
206
  * only a success is cached. Off by default; requires `agent: true`.
191
207
  */
@@ -230,8 +246,11 @@ export class WslShellExecutor extends LocalBashExecutor {
230
246
  this.sessionScopeProbe = (argv) => runCapture(argv);
231
247
  this.writableRootsProbe = (argv) => runCapture(argv);
232
248
  this.socketIsolationProbe = (argv) => runCapture(argv);
233
- // The preset realm disposes when the session ends; the scope must go with
234
- // it, or a dev server outlives the session that started it.
249
+ // The preset realm this row lives in is the PROCESS's, not the session's:
250
+ // upstream disposes it only when the preset definition is unregistered, so
251
+ // this disposer is the process-level backstop. The session's end is the
252
+ // harness's own `agent/disposed`, which the watch wires to a release.
253
+ this.sessionEndWatch = new SessionEndWatch(this, ctx);
235
254
  ctx.effect(() => () => this.disposeSessionRuntimes().catch(() => { }), "wsl session runtimes");
236
255
  }
237
256
  /**
@@ -356,12 +375,13 @@ export class WslShellExecutor extends LocalBashExecutor {
356
375
  * @returns the shared agent.
357
376
  */
358
377
  executionAgent(distro) {
359
- return sharedAgent(distro);
378
+ return sharedAgent(distro, this.wslConfig.wslPath);
360
379
  }
361
380
  /**
362
381
  * The persistent session runtime for one policy, when `sessionSandbox` is
363
- * on. The executor holds one reference per `(session, distro, workspace, policy)` and
364
- * releases them when the session's scope disposes.
382
+ * on. The executor holds one reference per `(session, distro, workspace, policy)`;
383
+ * the session's end (`agent/disposed`, through {@link sessionEndWatch})
384
+ * releases them.
365
385
  *
366
386
  * @param policy - the resolved file-effect policy, when the executor has one.
367
387
  * @param resolved - the resolved spec, for the fallback workspace.
@@ -377,8 +397,15 @@ export class WslShellExecutor extends LocalBashExecutor {
377
397
  const sessionId = policy?.sessionId || resolved.dshEnv?.DSH_SESSION_ID || this.sessionRuntimeOwner;
378
398
  const key = SessionRuntimes.key({ sessionId, distro, workspaceRoot, mode, maskWindowsDrive: effectiveMaskWindowsDrive(config), writableRoots, socketMasks, maskInterop });
379
399
  const held = this.runtimeBook.sessionRuntimeEntries.get(key);
380
- if (held !== undefined)
381
- return held;
400
+ if (held !== undefined) {
401
+ // A session end tears its runtimes down through every holder. One that
402
+ // reached this runtime without this executor must not leave it handing
403
+ // out a closed agent: the stale reference goes, and a resumed session
404
+ // gets a fresh runtime below.
405
+ if (this.sessionRuntimes.holds(held))
406
+ return held;
407
+ this.runtimeBook.sessionRuntimeEntries.delete(key);
408
+ }
382
409
  const entry = this.sessionRuntimes.acquire({
383
410
  sessionId,
384
411
  distro,
@@ -391,6 +418,7 @@ export class WslShellExecutor extends LocalBashExecutor {
391
418
  maskInterop,
392
419
  });
393
420
  this.runtimeBook.sessionRuntimeEntries.set(key, entry);
421
+ this.sessionEndWatch.ensureSweep();
394
422
  return entry;
395
423
  }
396
424
  /**
@@ -429,12 +457,14 @@ export class WslShellExecutor extends LocalBashExecutor {
429
457
  }
430
458
  /**
431
459
  * Release every runtime this executor holds, stopping each scope. Called
432
- * from the session's dispose hook; public so tests and shutdown paths can
433
- * await it.
460
+ * when the row goes away (the preset is unregistered, the app shuts down) —
461
+ * the sessions ended long before, each through {@link sessionEndWatch};
462
+ * public so tests and shutdown paths can await it.
434
463
  *
435
464
  * @returns resolved once every runtime is torn down.
436
465
  */
437
466
  async disposeSessionRuntimes() {
467
+ this.sessionEndWatch.dispose();
438
468
  const entries = [...this.runtimeBook.sessionRuntimeEntries.values()];
439
469
  this.runtimeBook.sessionRuntimeEntries.clear();
440
470
  for (const entry of entries)
@@ -768,9 +798,10 @@ export class WslShellExecutor extends LocalBashExecutor {
768
798
  return await this.executeViaAgent(resolved, distro, shell, writableRoots, socketMasks, maskInterop);
769
799
  }
770
800
  catch (error) {
771
- // Only an out-of-service agent falls back; anything else (a cwd
772
- // refusal, a sandbox refusal) is the command's own verdict.
773
- if (!(error instanceof AgentUnavailableError))
801
+ // Only an out-of-service agent that never took the command falls
802
+ // back; anything else (a cwd refusal, a sandbox refusal, a command
803
+ // whose state is unknown) is the command's own verdict.
804
+ if (!isFallbackCue(error))
774
805
  throw error;
775
806
  }
776
807
  }
@@ -795,8 +826,10 @@ export class WslShellExecutor extends LocalBashExecutor {
795
826
  }
796
827
  /**
797
828
  * The agent-backed execution path: one long-lived in-distro process, the
798
- * confinement argv unchanged, the handle shape unchanged. Any
799
- * {@link AgentUnavailableError} propagates for the caller's fallback.
829
+ * confinement argv unchanged, the handle shape unchanged. An
830
+ * {@link AgentUnavailableError} for a command the resident never took
831
+ * settles the handle with the one-shot retry instead; one for a command
832
+ * that was in flight when the resident was lost propagates.
800
833
  *
801
834
  * @param resolved - the resolved spec from {@link WslShellExecutor.execute}.
802
835
  * @param distro - the resolved distro name.
@@ -863,6 +896,14 @@ export class WslShellExecutor extends LocalBashExecutor {
863
896
  });
864
897
  }
865
898
  : undefined,
899
+ // Upstream's own handle calls `onProcessDone` as it settles; without
900
+ // this the stamp `onStarted` left would never be applied to the handle
901
+ // (a background process would report no sandbox facts) and never be
902
+ // released — every confined command through the resident would keep its
903
+ // handle, output buffers included, in `processFacts` for good.
904
+ onSettled: (proc, error) => {
905
+ this.onProcessDone(proc, proc.observed.stderr.readFrom(0).text, error !== undefined, error);
906
+ },
866
907
  });
867
908
  const decorated = WslShellExecutor.decorateResult(execution, (result) => {
868
909
  this.throwIfDistroUnavailable(result, distro);
@@ -893,13 +934,31 @@ export class WslShellExecutor extends LocalBashExecutor {
893
934
  }, (error) => {
894
935
  if (resolved.signal?.aborted === true)
895
936
  resolved.signal.throwIfAborted();
937
+ /**
938
+ * Run the command again on the one-shot path and settle with that
939
+ * handle's result. The agent handle stamped confinement facts for a run
940
+ * that never happened through it, so the stamp goes before the retry;
941
+ * the one-shot handle stamps and settles its own.
942
+ *
943
+ * @returns the one-shot result.
944
+ */
945
+ const retryOneShot = () => {
946
+ this.processFacts.delete(execution);
947
+ return this.executeOneShot(resolved, distro, shell, writableRoots, socketMasks, maskInterop).then((fallback) => fallback.result());
948
+ };
896
949
  // The native agent reports a missing workdir as a spawn failure without
897
950
  // naming it. Retry that command on the one-shot path, whose `--cd`
898
951
  // warning names the directory — the failure path pays the extra spawn,
899
952
  // the hot path does not.
900
- if (error instanceof SpawnError) {
901
- return this.executeOneShot(resolved, distro, shell, writableRoots, socketMasks, maskInterop).then((fallback) => fallback.result());
902
- }
953
+ if (error instanceof SpawnError)
954
+ return retryOneShot();
955
+ // The resident refused the command before running it — dead, backing off
956
+ // after a death, or its handshake failed. `WslAgent.exec` is async, so
957
+ // that refusal always arrives here, through `result()`, never as the
958
+ // synchronous throw `execute` catches. A command that WAS with the
959
+ // resident when it was lost is not a cue: see `isFallbackCue`.
960
+ if (isFallbackCue(error))
961
+ return retryOneShot();
903
962
  throw error;
904
963
  });
905
964
  // The agent handle IS the upstream execution shape at runtime; its typedef
package/lib/wsl.d.ts CHANGED
@@ -102,10 +102,12 @@ export declare function parseDistroList(stdout: string): string[];
102
102
  * @throws when no distro is installed.
103
103
  */
104
104
  export declare function defaultDistro(options?: WslCallOptions): Promise<string>;
105
+ /** Test hook: forget the shared home and shell probes. */
106
+ export declare function resetWslProbeCacheForTests(): void;
105
107
  /**
106
108
  * The Linux home directory of a distro's default user, as a Linux path. `$HOME`
107
109
  * is set by `wsl.exe` itself from the distro's default user, so this needs no
108
- * passwd parsing.
110
+ * passwd parsing. Resolved once per `(wslPath, distro)` per process.
109
111
  *
110
112
  * @param distro - distro name.
111
113
  * @param options - the `wsl.exe` path and optional cancellation.
package/lib/wsl.js CHANGED
@@ -155,19 +155,92 @@ export async function defaultDistro(options = {}) {
155
155
  }
156
156
  return first;
157
157
  }
158
+ /**
159
+ * Successful probe answers shared by every caller in this process, keyed by
160
+ * `(wslPath, distro)`. A distro's home and login shell do not change while DSH
161
+ * runs, and six call sites used to spend a `wsl.exe` round trip each on the
162
+ * same two questions. Only success is remembered: a failed probe stays
163
+ * retryable, as the shell executor's own contract requires.
164
+ */
165
+ const homeProbes = new Map();
166
+ const shellProbes = new Map();
167
+ /** Key for both probe caches; the `wslPath` is part of it so overrides do not alias. */
168
+ function probeKey(wslPath, distro) {
169
+ return `${wslPath}\u0000${distro}`;
170
+ }
171
+ /**
172
+ * Reject with the caller's own abort reason without settling the shared probe:
173
+ * one caller cancelling must not turn another caller's answer into a failure.
174
+ *
175
+ * @param pending - the shared probe.
176
+ * @param signal - the caller's lifetime.
177
+ * @returns the probe's answer, or a rejection when the caller aborts first.
178
+ */
179
+ function raceProbeAbort(pending, signal) {
180
+ if (signal === undefined)
181
+ return pending;
182
+ return new Promise((resolvePromise, rejectPromise) => {
183
+ if (signal.aborted) {
184
+ rejectPromise(signal.reason ?? new Error("aborted"));
185
+ return;
186
+ }
187
+ const onAbort = () => {
188
+ rejectPromise(signal.reason ?? new Error("aborted"));
189
+ };
190
+ signal.addEventListener("abort", onAbort, { once: true });
191
+ pending.then((value) => {
192
+ signal.removeEventListener("abort", onAbort);
193
+ resolvePromise(value);
194
+ }, (error) => {
195
+ signal.removeEventListener("abort", onAbort);
196
+ rejectPromise(error);
197
+ });
198
+ });
199
+ }
200
+ /**
201
+ * Run one probe through a process-level cache with single-flight: concurrent
202
+ * callers share the in-flight `wsl.exe` call, and a settled answer is kept only
203
+ * when `keep` says so.
204
+ *
205
+ * @param cache - the probe's cache.
206
+ * @param key - the distro/transport key.
207
+ * @param probe - starts the probe when no one else has.
208
+ * @param keep - whether a settled answer is worth remembering.
209
+ * @param signal - the caller's lifetime.
210
+ * @returns the probe's answer.
211
+ */
212
+ function sharedProbe(cache, key, probe, keep, signal) {
213
+ let pending = cache.get(key);
214
+ if (pending === undefined) {
215
+ pending = probe();
216
+ cache.set(key, pending);
217
+ pending.then((value) => {
218
+ if (!keep(value))
219
+ cache.delete(key);
220
+ }, () => {
221
+ cache.delete(key);
222
+ });
223
+ }
224
+ return raceProbeAbort(pending, signal);
225
+ }
226
+ /** Test hook: forget the shared home and shell probes. */
227
+ export function resetWslProbeCacheForTests() {
228
+ homeProbes.clear();
229
+ shellProbes.clear();
230
+ }
158
231
  /**
159
232
  * The Linux home directory of a distro's default user, as a Linux path. `$HOME`
160
233
  * is set by `wsl.exe` itself from the distro's default user, so this needs no
161
- * passwd parsing.
234
+ * passwd parsing. Resolved once per `(wslPath, distro)` per process.
162
235
  *
163
236
  * @param distro - distro name.
164
237
  * @param options - the `wsl.exe` path and optional cancellation.
165
238
  * @returns e.g. `/home/andy`.
166
239
  * @throws when the distro cannot be queried or reports no home.
167
240
  */
168
- export async function linuxHomePath(distro, options = {}) {
169
- const stdout = await runCapture([options.wslPath ?? DEFAULT_WSL_PATH, "-d", distro, "--exec", "sh", "-c", 'printf %s "$HOME"'], options.signal);
170
- return parseHomePath(distro, stdout);
241
+ export function linuxHomePath(distro, options = {}) {
242
+ const wslPath = options.wslPath ?? DEFAULT_WSL_PATH;
243
+ return sharedProbe(homeProbes, probeKey(wslPath, distro), async () => parseHomePath(distro, await runCapture([wslPath, "-d", distro, "--exec", "sh", "-c", 'printf %s "$HOME"'], options.signal)), () => true, options.signal);
171
244
  }
172
245
  /**
173
246
  * Validate the distro's reported $HOME. A pure seam: the failure shapes
@@ -390,8 +463,10 @@ export async function defaultShell(distro, options = {}) {
390
463
  // No "bash" placeholder: a failed probe (a cold distro, a flaky first
391
464
  // `wsl.exe` call) used to be pinned as the literal shell for the
392
465
  // executor's lifetime. `undefined` tells the caller both answers failed;
393
- // it may retry later or fall back itself.
394
- return ((await ask('getent passwd "$(id -u)" | cut -d: -f7')) ??
466
+ // it may retry later or fall back itself. The shared cache keeps a
467
+ // confirmed answer and drops an unresolved one, so that retry can still
468
+ // happen.
469
+ return sharedProbe(shellProbes, probeKey(wslPath, distro), async () => ((await ask('getent passwd "$(id -u)" | cut -d: -f7')) ??
395
470
  (await ask('printf %s "$SHELL"')) ??
396
- undefined);
471
+ undefined), (value) => value !== undefined, options.signal);
397
472
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-plugin-wsl-env",
3
- "version": "0.28.0",
3
+ "version": "0.29.1",
4
4
  "description": "在 WSL 的 Linux 实例中打开项目工作区,在对应 Linux 空间中进行命令执行、运行 shell 脚本和文件访问,以获得全套 Linux Shell 工具链收益,并通过 bubblewrap 对命令进行沙箱隔离",
5
5
  "keywords": [
6
6
  "deepseek-harness",
@@ -219,10 +219,10 @@
219
219
  "lint:types": "tsc --noEmit",
220
220
  "build": "node scripts/build.mjs",
221
221
  "lint:build": "node test/build-freshness.mjs",
222
- "test:browser": "node --test --test-timeout=120000 test/browser/e2e.test.mjs",
223
- "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 test/cloud-wsl-gate.test.mjs test/official-harness-smoke.test.mjs",
222
+ "test:browser": "node --test --test-timeout=240000 test/browser/e2e.test.mjs",
223
+ "test:coverage": "node scripts/coverage-gate.mjs -- node --test --test-timeout=240000 --experimental-test-coverage --test-coverage-lines=85 --test-coverage-branches=84 --test-coverage-functions=70 --test-coverage-exclude='scripts/build.mjs' --test-coverage-exclude='scripts/changelog-section.mjs' --test-coverage-exclude='scripts/check-doc-consistency.mjs' --test-coverage-exclude='scripts/check-links.mjs' --test-coverage-exclude='scripts/check-requirements.mjs' --test-coverage-exclude='scripts/coverage-gate.mjs' --test-coverage-exclude='scripts/doctor.mjs' --test-coverage-exclude='scripts/native-wiring-check.mjs' --test-coverage-exclude='scripts/test-watchdog.mjs' --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/preset-sync.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 test/cloud-wsl-gate.test.mjs test/official-harness-smoke.test.mjs",
224
224
  "test:syntax": "node test/syntax.mjs",
225
- "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 test/cloud-wsl-gate.test.mjs test/official-harness-smoke.test.mjs",
225
+ "test:unit": "node scripts/test-watchdog.mjs -- node --test --test-timeout=240000 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/preset-sync.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 test/cloud-wsl-gate.test.mjs test/official-harness-smoke.test.mjs",
226
226
  "lint:style": "node test/style.mjs",
227
227
  "lint:links": "node scripts/check-links.mjs",
228
228
  "lint:requirements": "node scripts/check-requirements.mjs",
@@ -253,6 +253,7 @@
253
253
  "diagnose": "bash scripts/diagnose.sh",
254
254
  "doctor": "node scripts/doctor.mjs",
255
255
  "preset": "node scripts/profile-preset.mjs",
256
+ "preset:sync": "node scripts/preset-sync.mjs",
256
257
  "e2e:install": "bash test/e2e/install.sh",
257
258
  "canary:peers": "node scripts/peer-canary.mjs",
258
259
  "probe:auto-preset": "bash test/probe/auto-preset.sh",
@@ -10,7 +10,11 @@
10
10
  # The install runs as the distro's root through `wsl.exe -d <distro> -u root --`,
11
11
  # so it never touches the Windows side and never needs a sudo prompt inside the
12
12
  # distro. Without --install the script is strictly read-only: it reports and
13
- # prints the exact commands, runnable as-is.
13
+ # prints the exact command, runnable as-is. apt refreshes its package index
14
+ # first (a freshly installed Debian or Ubuntu has none); that command contains
15
+ # a `&&`, so every family's command runs through `sh -c "…"` and the printed
16
+ # line carries the same quotes — they keep the operator inside the distro when
17
+ # the line is pasted into cmd, PowerShell 5.1 or PowerShell 7.
14
18
  #
15
19
  # Exit status: 0 when everything REQUIRED is present (or was installed), 1 when
16
20
  # bubblewrap is still missing.
@@ -42,29 +46,47 @@ run_in_distro() {
42
46
  wsl.exe -d "$DISTRO" --exec sh -c "$1" sh "$2"
43
47
  }
44
48
 
45
- # The package family decides the install command; a distro with none reported
46
- # gets the apt spelling, which covers the default Ubuntu images.
49
+ # One spawn answers every pre-install question — the package family and the
50
+ # tools' presence — where six serial wsl.exe calls used to do it one each.
51
+ # FAMILY is emitted only when found; a distro with none reported keeps the apt
52
+ # spelling, which covers the default Ubuntu images.
53
+ FACTS="$(run_in_distro '
54
+ for f in apt-get dnf pacman zypper; do command -v "$f" >/dev/null 2>&1 && { echo "FAMILY=$f"; break; }; done
55
+ for t in bwrap rg git inotifywait; do
56
+ if p=$(command -v "$t" 2>/dev/null); then echo "TOOL $t $p"; else echo "MISSING $t"; fi
57
+ done
58
+ ' "")"
59
+
60
+ if [ -z "$FACTS" ]; then
61
+ echo "bootstrap: wsl.exe could not run a command in \"$DISTRO\"" >&2
62
+ exit 1
63
+ fi
64
+
47
65
  family() {
48
- run_in_distro 'for f in apt-get dnf pacman zypper; do command -v "$f" >/dev/null 2>&1 && { echo "$f"; exit 0; }; done; echo unknown' ""
66
+ printf '%s\n' "$FACTS" | sed -n 's/^FAMILY=//p' | head -n 1
49
67
  }
50
68
 
51
69
  install_command() {
52
70
  case "$(family)" in
53
- apt-get) echo 'apt-get install -y bubblewrap git ripgrep inotify-tools' ;;
54
71
  dnf) echo 'dnf install -y bubblewrap git ripgrep inotify-tools' ;;
55
- pacman) echo 'pacman -Sy --noconfirm bubblewrap git ripgrep inotify-tools' ;;
72
+ pacman) echo 'pacman -S --noconfirm --needed bubblewrap git ripgrep inotify-tools' ;;
56
73
  zypper) echo 'zypper --non-interactive install bubblewrap git ripgrep inotify-tools' ;;
57
- *) echo 'apt-get install -y bubblewrap git ripgrep inotify-tools' ;;
74
+ *) echo 'apt-get update -qq && apt-get install -y --no-install-recommends bubblewrap git ripgrep inotify-tools' ;;
58
75
  esac
59
76
  }
60
77
 
78
+ # The pre-install answers come from FACTS; only a post-install check re-probes.
79
+ tool_path() {
80
+ printf '%s\n' "$FACTS" | awk -v t="$1" '$1 == "TOOL" && $2 == t { print $3; exit }'
81
+ }
82
+
61
83
  present() {
62
84
  run_in_distro 'for t in "$@"; do command -v "$t" >/dev/null 2>&1 || exit 1; done' "$1"
63
85
  }
64
86
 
65
87
  report() {
66
88
  local label="$1" tool="$2"
67
- if run_in_distro "command -v $tool >/dev/null 2>&1" ""; then
89
+ if [ -n "$(tool_path "$tool")" ]; then
68
90
  echo "ok $label ($tool)"
69
91
  else
70
92
  echo "MISSING $label ($tool)"
@@ -74,10 +96,12 @@ report() {
74
96
  echo "distro: $DISTRO"
75
97
 
76
98
  BW_OK="yes"
77
- if present "bwrap"; then
99
+ if [ -z "$(tool_path bwrap)" ]; then
100
+ BW_OK="no"
101
+ fi
102
+ if [ "$BW_OK" = "yes" ]; then
78
103
  report "bubblewrap (required; commands fail closed without it)" "bwrap"
79
104
  else
80
- BW_OK="no"
81
105
  echo "MISSING bubblewrap (REQUIRED; every command fails closed without it)"
82
106
  fi
83
107
  report "ripgrep (in-distro search backend)" "rg"
@@ -87,7 +111,7 @@ report "inotifywait (watcher primary backend)" "inotifywait"
87
111
  CMD="$(install_command)"
88
112
  echo
89
113
  echo "install command:"
90
- echo " wsl.exe -d $DISTRO -u root -- $CMD"
114
+ echo " wsl.exe -d $DISTRO -u root -- sh -c \"$CMD\""
91
115
 
92
116
  if [ "$BW_OK" = "yes" ]; then
93
117
  echo
@@ -103,7 +127,7 @@ fi
103
127
 
104
128
  echo
105
129
  echo "installing..."
106
- wsl.exe -d "$DISTRO" -u root -- $CMD
130
+ wsl.exe -d "$DISTRO" -u root -- sh -c "$CMD"
107
131
 
108
132
  if present "bwrap"; then
109
133
  echo "bubblewrap installed successfully."