dsh-plugin-wsl-env 0.18.0 → 0.19.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.
Files changed (105) hide show
  1. package/CHANGELOG.md +152 -0
  2. package/CONTRIBUTING.md +37 -5
  3. package/README.md +59 -4
  4. package/SUPPORT.md +3 -3
  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 +331 -11
  8. package/docs/AGENT-PROTOCOL-V7.md +175 -0
  9. package/docs/API.md +24 -0
  10. package/docs/ARCHITECTURE.md +14 -1
  11. package/docs/CONFIGURATION.md +12 -5
  12. package/docs/CONFIGURATION.zh.md +5 -3
  13. package/docs/LIMITATIONS.md +16 -4
  14. package/docs/LIMITATIONS.zh.md +20 -11
  15. package/docs/MIGRATION.md +4 -4
  16. package/docs/PEER-PARITY.md +50 -33
  17. package/docs/QUICKSTART.md +18 -1
  18. package/docs/QUICKSTART.zh.md +16 -1
  19. package/docs/README.zh.md +43 -4
  20. package/docs/RELEASING.md +1 -1
  21. package/docs/REQUIREMENTS.zh.md +3 -2
  22. package/docs/ROADMAP-1.0.md +27 -16
  23. package/docs/UPSTREAM-FILE-REFERENCE-SEAM.md +3 -1
  24. package/docs/UPSTREAM-SESSION-NOTICE.md +3 -1
  25. package/docs/UPSTREAM-TERMINAL-TITLE.md +3 -0
  26. package/docs/root-fs-routing.md +3 -3
  27. package/lib/agent-confined.js +4 -4
  28. package/lib/agent-errors.d.ts +1 -1
  29. package/lib/agent-errors.js +1 -1
  30. package/lib/agent-exec.d.ts +1 -1
  31. package/lib/agent-exec.js +1 -1
  32. package/lib/agent-protocol.d.ts +58 -8
  33. package/lib/agent-protocol.js +40 -7
  34. package/lib/agent-shared.d.ts +1 -1
  35. package/lib/agent-shared.js +1 -1
  36. package/lib/agent.d.ts +171 -1
  37. package/lib/agent.js +448 -288
  38. package/lib/auto-preset.d.ts +1 -1
  39. package/lib/auto-preset.js +1 -1
  40. package/lib/bwrap.d.ts +1 -1
  41. package/lib/bwrap.js +1 -1
  42. package/lib/distro-route.d.ts +1 -1
  43. package/lib/distro-route.js +1 -1
  44. package/lib/doctor-live.d.ts +53 -0
  45. package/lib/doctor-live.js +37 -0
  46. package/lib/file-reference-wsl.d.ts +1 -1
  47. package/lib/file-reference-wsl.js +1 -1
  48. package/lib/fs-decisions.d.ts +1 -1
  49. package/lib/fs-decisions.js +1 -1
  50. package/lib/fs-routing.d.ts +1 -1
  51. package/lib/fs-routing.js +1 -1
  52. package/lib/fs-substrate.d.ts +90 -11
  53. package/lib/fs-substrate.js +202 -1
  54. package/lib/fs.d.ts +1 -1
  55. package/lib/fs.js +1 -1
  56. package/lib/fsio-agent.d.ts +128 -4
  57. package/lib/fsio-agent.js +224 -15
  58. package/lib/fsio-text.d.ts +1 -1
  59. package/lib/fsio-text.js +1 -1
  60. package/lib/git-exec.d.ts +1 -1
  61. package/lib/git-exec.js +1 -1
  62. package/lib/git-route.d.ts +1 -1
  63. package/lib/git-route.js +1 -1
  64. package/lib/index.d.ts +105 -30
  65. package/lib/index.js +266 -122
  66. package/lib/listing.d.ts +1 -1
  67. package/lib/listing.js +1 -1
  68. package/lib/native-agent.d.ts +1 -1
  69. package/lib/native-agent.js +2 -2
  70. package/lib/paths.d.ts +6 -3
  71. package/lib/paths.js +4 -4
  72. package/lib/picker.d.ts +1 -1
  73. package/lib/picker.js +7 -7
  74. package/lib/ports.d.ts +1 -1
  75. package/lib/ports.js +1 -1
  76. package/lib/preflight.d.ts +1 -1
  77. package/lib/preflight.js +1 -1
  78. package/lib/sandbox-core.d.ts +1 -1
  79. package/lib/sandbox-core.js +2 -2
  80. package/lib/sandbox.d.ts +1 -1
  81. package/lib/sandbox.js +1 -1
  82. package/lib/search-exec.d.ts +1 -1
  83. package/lib/search-exec.js +1 -1
  84. package/lib/search-route.d.ts +1 -1
  85. package/lib/search-route.js +1 -1
  86. package/lib/session-runtime.d.ts +1 -1
  87. package/lib/session-runtime.js +2 -2
  88. package/lib/session-scope.d.ts +1 -1
  89. package/lib/session-scope.js +1 -1
  90. package/lib/shell-env.d.ts +1 -1
  91. package/lib/shell-env.js +1 -1
  92. package/lib/shell.d.ts +1 -1
  93. package/lib/shell.js +1 -1
  94. package/lib/subprocess.d.ts +1 -1
  95. package/lib/subprocess.js +2 -2
  96. package/lib/terminal-activity.d.ts +1 -1
  97. package/lib/terminal-activity.js +1 -1
  98. package/lib/terminal-route.d.ts +1 -1
  99. package/lib/terminal-route.js +1 -1
  100. package/lib/watcher.d.ts +1 -1
  101. package/lib/watcher.js +1 -1
  102. package/lib/wsl.d.ts +1 -31
  103. package/lib/wsl.js +1 -21
  104. package/package.json +15 -4
  105. package/scripts/doctor.mjs +34 -11
@@ -9,6 +9,7 @@
9
9
  * a fresh-agent handshake, stale session scopes, and the known profile-patch trap.
10
10
  *
11
11
  * node scripts/doctor.mjs [distro] [--json] [--fix] [--install] [--yes] [--read-only]
12
+ * [--wsl <path to wsl.exe>]
12
13
  *
13
14
  * Exit status is 0 when nothing failed and 1 when a `fail` check did; warnings
14
15
  * (optional tools, a missing cache) do not fail the run. `--fix` performs only
@@ -23,6 +24,12 @@
23
24
  * `--json` prints one machine-readable report instead of the human sections.
24
25
  * The report shape is versioned (`schemaVersion`).
25
26
  *
27
+ * This CLI always probes a **fresh** resident — the app process's live
28
+ * resident's `deaths`/`lastError` are host-private (no IPC), and the report
29
+ * says so at the handshake check. Consumers holding the plugin's context
30
+ * merge them through `doctorReport()` in `lib/index.js` / the
31
+ * `mergeLiveResidentStatus` helper in `lib/doctor-live.js` (WSL-313).
32
+ *
26
33
  * @module dsh-plugin-wsl/scripts/doctor
27
34
  */
28
35
  import { execFile, spawn } from "node:child_process";
@@ -39,7 +46,7 @@ import { sessionScopeSweepScript } from "../lib/session-scope.js";
39
46
  import { parseListeningPorts, procNetScript } from "../lib/ports.js";
40
47
 
41
48
  const ROOT = resolve(dirname(fileURLToPath(import.meta.url)), "..");
42
- const WSL = "wsl.exe";
49
+ let WSL = "wsl.exe";
43
50
  const CMD = "cmd.exe";
44
51
  const TIMEOUT_MS = 60_000;
45
52
 
@@ -125,10 +132,19 @@ function inDistro(distro, script) {
125
132
  /**
126
133
  * Parse the doctor's own arguments.
127
134
  * @param {string[]} argv - `process.argv.slice(2)`.
128
- * @returns {{ distro: string, json: boolean, fix: boolean, install: boolean, yes: boolean, readOnly: boolean, help: boolean }} the options.
135
+ * @returns {{ distro: string, wsl: string, json: boolean, fix: boolean, install: boolean, yes: boolean, readOnly: boolean, help: boolean }} the options.
129
136
  */
130
137
  function parseArgs(argv) {
131
- const options = { distro: "", json: false, fix: false, install: false, yes: false, readOnly: false, help: false };
138
+ const options = {
139
+ distro: "",
140
+ wsl: "",
141
+ json: false,
142
+ fix: false,
143
+ install: false,
144
+ yes: false,
145
+ readOnly: false,
146
+ help: false,
147
+ };
132
148
  for (let i = 0; i < argv.length; i += 1) {
133
149
  const arg = argv[i] ?? "";
134
150
  if (arg === "--json") options.json = true;
@@ -139,6 +155,8 @@ function parseArgs(argv) {
139
155
  else if (arg === "--help" || arg === "-h") options.help = true;
140
156
  else if (arg === "--distro") options.distro = argv[++i] ?? "";
141
157
  else if (arg.startsWith("--distro=")) options.distro = arg.slice("--distro=".length);
158
+ else if (arg === "--wsl") options.wsl = argv[++i] ?? "";
159
+ else if (arg.startsWith("--wsl=")) options.wsl = arg.slice("--wsl=".length);
142
160
  else if (arg.startsWith("-")) throw new Error(`doctor: unknown option "${arg}"`);
143
161
  else options.distro = arg;
144
162
  }
@@ -261,11 +279,16 @@ function rejectReadOnly() {
261
279
 
262
280
  /**
263
281
  * Run the doctor.
264
- * @param {{ distro: string, json: boolean, fix: boolean, install: boolean, yes: boolean, readOnly: boolean }} options - the parsed options.
282
+ * @param {{ distro: string, wsl: string, json: boolean, fix: boolean, install: boolean, yes: boolean, readOnly: boolean, help: boolean }} options - the parsed options.
265
283
  * @returns {Promise<number>} the exit status.
266
284
  */
267
285
  async function main(options) {
268
286
  if (options.readOnly && (options.fix || options.install)) return rejectReadOnly();
287
+ // One rebinding covers every probe below (`-l -q`, `inDistro`, the
288
+ // resident handshake, the sessions survey): an explicit `--wsl` replaces
289
+ // the module-level default for this whole run.
290
+ const wslExe = options.wsl.length > 0 ? options.wsl : WSL;
291
+ WSL = wslExe;
269
292
  /** @type {Check[]} */
270
293
  const checks = [];
271
294
  /**
@@ -285,12 +308,12 @@ async function main(options) {
285
308
  if (build !== null) check("host.windows", "ok", "Windows build", build[0]);
286
309
  else check("host.windows", "info", "Windows build", "unreadable through cmd.exe; run this from Windows or a WSL with interop enabled");
287
310
 
288
- const version = await run([WSL, "--version"]);
311
+ const version = await run([wslExe, "--version"]);
289
312
  const wslVersion = version.stdout.replace(/\0/g, "").split(/\r?\n/).filter((line) => line.trim().length > 0).slice(0, 2).join(" ");
290
313
  if (version.ok && wslVersion.length > 0) check("host.wsl", "ok", "WSL version", wslVersion);
291
314
  else check("host.wsl", "warn", "WSL version", "wsl.exe --version failed; WSL 1 or a very old build", "wsl.exe --update, then confirm the distro runs as WSL 2 (wsl.exe -l -v shows VERSION 2)");
292
315
 
293
- const listed = await run([WSL, "-l", "-q"]);
316
+ const listed = await run([wslExe, "-l", "-q"]);
294
317
  const distros = listed.ok ? parseDistroList(listed.stdout.replace(/\0/g, "")) : [];
295
318
  if (distros.length === 0) {
296
319
  check("host.distros", "fail", "Installed distros", "none", "wsl.exe --list --online lists names; wsl.exe --install -d <name> installs one, then reopen the session");
@@ -421,13 +444,13 @@ async function main(options) {
421
444
  } else if (!existsSync(agentScript)) {
422
445
  check("agent.handshake", "fail", "Agent handshake", "agent/wsl-agent.sh is missing from this install", "reinstall the plugin; the shell agent ships with the package");
423
446
  } else {
424
- const handshake = await probeResident(distro, agentScript);
447
+ const handshake = await probeResident(distro, agentScript, wslExe);
425
448
  if (handshake.ok) {
426
449
  const live = livePids.length > 0
427
- ? `; a live resident (pid${livePids.length > 1 ? "s" : ""} ${livePids.join(", ")}) is already running in this distro — this check starts a fresh one, which cannot read its last error`
450
+ ? `; a live resident (pid${livePids.length > 1 ? "s" : ""} ${livePids.join(", ")}) is already running in this distro — this check starts a fresh one, which cannot read its last error; the app-side doctorReport() merge surfaces it`
428
451
  : "";
429
452
  check("agent.handshake", handshake.digestMatches ? "ok" : "fail", "Agent handshake",
430
- `pid ${handshake.pid}, protocol ${PROTOCOL_VERSION}, digest ${handshake.digestMatches ? "matches" : "MISMATCH — the distro reads a different script than this package"}${live}`,
453
+ `probed: a fresh resident, pid ${handshake.pid}, protocol ${PROTOCOL_VERSION}, digest ${handshake.digestMatches ? "matches" : "MISMATCH — the distro reads a different script than this package"}${live}`,
431
454
  handshake.digestMatches ? undefined : "resync the runtime copy (pnpm run sync:windows), then restart the app");
432
455
  } else {
433
456
  check("agent.handshake", "fail", "Agent handshake", handshake.detail, "restart the DSH app; if it persists, delete ~/.cache/dsh-wsl/agent inside the distro and rerun the doctor");
@@ -573,7 +596,7 @@ async function main(options) {
573
596
  * @param {string} scriptPath - the agent script as a Linux path inside the distro.
574
597
  * @returns {Promise<{ ok: true, pid: number, digestMatches: boolean } | { ok: false, detail: string }>} the verdict, with the pid on success.
575
598
  */
576
- function probeResident(distro, scriptPath) {
599
+ function probeResident(distro, scriptPath, wslExe = WSL) {
577
600
  return new Promise((settle) => {
578
601
  let settled = false;
579
602
  /** @param {{ ok: true, pid: number, digestMatches: boolean } | { ok: false, detail: string }} value - the verdict. */
@@ -584,7 +607,7 @@ function probeResident(distro, scriptPath) {
584
607
  child.kill();
585
608
  settle(value);
586
609
  };
587
- const child = spawn(WSL, ["-d", distro, "--exec", "sh", scriptPath], {
610
+ const child = spawn(wslExe, ["-d", distro, "--exec", "sh", scriptPath], {
588
611
  stdio: ["pipe", "pipe", "pipe"],
589
612
  windowsHide: true,
590
613
  env: { ...process.env, WSL_UTF8: "1" },