dsh-plugin-wsl-env 0.18.0 → 0.21.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 +274 -0
- package/CONTRIBUTING.md +37 -5
- package/README.md +60 -5
- package/SUPPORT.md +3 -3
- package/agent/native/linux-aarch64/dsh-wsl-agent +0 -0
- package/agent/native/linux-x86_64/dsh-wsl-agent +0 -0
- package/agent/wsl-agent.sh +331 -11
- package/client.d.ts +5 -0
- package/client.js +98 -0
- package/cordis.patch.yml +66 -1
- package/docs/AGENT-PROTOCOL-V7.md +175 -0
- package/docs/API.md +25 -0
- package/docs/ARCHITECTURE.md +14 -1
- package/docs/CONFIGURATION.md +47 -6
- package/docs/CONFIGURATION.zh.md +20 -4
- package/docs/DIAGNOSTICS.md +83 -0
- package/docs/DIAGNOSTICS.zh.md +73 -0
- package/docs/LIMITATIONS.md +41 -4
- package/docs/LIMITATIONS.zh.md +27 -11
- package/docs/MIGRATION.md +4 -4
- package/docs/PEER-PARITY.md +50 -33
- package/docs/QUICKSTART.md +37 -4
- package/docs/QUICKSTART.zh.md +16 -1
- package/docs/README.zh.md +43 -4
- package/docs/RELEASING.md +4 -1
- package/docs/REQUIREMENTS.zh.md +3 -2
- package/docs/ROADMAP-1.0.md +75 -19
- package/docs/UPSTREAM-FILE-REFERENCE-SEAM.md +8 -1
- package/docs/UPSTREAM-OPEN-IN-APP.md +33 -0
- package/docs/UPSTREAM-SESSION-NOTICE.md +3 -1
- package/docs/UPSTREAM-TERMINAL-TITLE.md +3 -0
- package/docs/root-fs-routing.md +3 -3
- package/lib/agent-confined.js +4 -4
- package/lib/agent-errors.d.ts +1 -1
- package/lib/agent-errors.js +1 -1
- package/lib/agent-exec.d.ts +1 -1
- package/lib/agent-exec.js +1 -1
- package/lib/agent-protocol.d.ts +58 -8
- package/lib/agent-protocol.js +40 -7
- package/lib/agent-shared.d.ts +1 -1
- package/lib/agent-shared.js +1 -1
- package/lib/agent.d.ts +171 -1
- package/lib/agent.js +448 -288
- package/lib/auto-preset.d.ts +1 -1
- package/lib/auto-preset.js +1 -1
- package/lib/bwrap.d.ts +1 -1
- package/lib/bwrap.js +1 -1
- package/lib/client-host.d.ts +29 -0
- package/lib/client-host.js +29 -0
- package/lib/cwd-prompt-tool.d.ts +88 -0
- package/lib/cwd-prompt-tool.js +94 -0
- package/lib/cwd-prompt.d.ts +166 -0
- package/lib/cwd-prompt.js +203 -0
- package/lib/distro-route.d.ts +1 -1
- package/lib/distro-route.js +1 -1
- package/lib/doctor-live.d.ts +57 -0
- package/lib/doctor-live.js +38 -0
- package/lib/file-reference-wsl.d.ts +1 -1
- package/lib/file-reference-wsl.js +1 -1
- package/lib/fs-decisions.d.ts +1 -1
- package/lib/fs-decisions.js +1 -1
- package/lib/fs-routing.d.ts +1 -1
- package/lib/fs-routing.js +1 -1
- package/lib/fs-substrate.d.ts +90 -11
- package/lib/fs-substrate.js +202 -1
- package/lib/fs.d.ts +1 -1
- package/lib/fs.js +1 -1
- package/lib/fsio-agent.d.ts +128 -4
- package/lib/fsio-agent.js +224 -15
- package/lib/fsio-text.d.ts +1 -1
- package/lib/fsio-text.js +1 -1
- package/lib/git-exec.d.ts +1 -1
- package/lib/git-exec.js +1 -1
- package/lib/git-route.d.ts +1 -1
- package/lib/git-route.js +1 -1
- package/lib/index.d.ts +105 -30
- package/lib/index.js +272 -130
- package/lib/listing.d.ts +1 -1
- package/lib/listing.js +1 -1
- package/lib/messages.d.ts +157 -0
- package/lib/messages.js +199 -0
- package/lib/native-agent.d.ts +1 -1
- package/lib/native-agent.js +2 -2
- package/lib/paths.d.ts +6 -3
- package/lib/paths.js +4 -4
- package/lib/picker.d.ts +1 -1
- package/lib/picker.js +7 -7
- package/lib/ports.d.ts +1 -1
- package/lib/ports.js +1 -1
- package/lib/preflight.d.ts +25 -1
- package/lib/preflight.js +112 -12
- package/lib/sandbox-core.d.ts +1 -1
- package/lib/sandbox-core.js +9 -16
- package/lib/sandbox.d.ts +1 -1
- package/lib/sandbox.js +1 -1
- package/lib/search-exec.d.ts +1 -1
- package/lib/search-exec.js +1 -1
- package/lib/search-route.d.ts +1 -1
- package/lib/search-route.js +1 -1
- package/lib/session-runtime.d.ts +1 -1
- package/lib/session-runtime.js +2 -2
- package/lib/session-scope.d.ts +1 -1
- package/lib/session-scope.js +11 -6
- package/lib/shell-env.d.ts +26 -1
- package/lib/shell-env.js +57 -1
- package/lib/shell.d.ts +4 -2
- package/lib/shell.js +4 -2
- package/lib/subprocess.d.ts +1 -1
- package/lib/subprocess.js +2 -2
- package/lib/terminal-activity.d.ts +1 -1
- package/lib/terminal-activity.js +1 -1
- package/lib/terminal-route.d.ts +1 -1
- package/lib/terminal-route.js +1 -1
- package/lib/update-check.d.ts +197 -0
- package/lib/update-check.js +211 -0
- package/lib/watcher.d.ts +1 -1
- package/lib/watcher.js +1 -1
- package/lib/wsl-doctor-tool.d.ts +122 -0
- package/lib/wsl-doctor-tool.js +161 -0
- package/lib/wsl.d.ts +1 -31
- package/lib/wsl.js +1 -21
- package/package.json +55 -6
- package/scripts/doctor.mjs +1196 -166
package/lib/index.js
CHANGED
|
@@ -59,6 +59,11 @@ import { FsCodedError } from "./fsio-text.js";
|
|
|
59
59
|
import { confinedAgent } from "./agent-confined.js";
|
|
60
60
|
import { SessionRuntimes, probeSessionRuntime, sessionRuntimes, setSessionNativeAgent } from "./session-runtime.js";
|
|
61
61
|
import { configureAgentBackend, ensureNativeSessionAgent } from "./native-agent.js";
|
|
62
|
+
import { installMessagesLocale, t } from "./messages.js";
|
|
63
|
+
import { mergeLiveResidentStatus } from "./doctor-live.js";
|
|
64
|
+
import { spawnSync } from "node:child_process";
|
|
65
|
+
import { fileURLToPath } from "node:url";
|
|
66
|
+
import { dirname, join } from "node:path";
|
|
62
67
|
// `runCapture` and distro discovery live in ./wsl.js so the directory picker
|
|
63
68
|
// can use them without pulling this file's executor and filesystem peers in.
|
|
64
69
|
import { defaultDistro, defaultShell, linuxHomePath, runCapture, shellArgs, workdirFailure, wslErrorCode } from "./wsl.js";
|
|
@@ -175,6 +180,57 @@ function wslWritableRoots(policy, distro) {
|
|
|
175
180
|
}
|
|
176
181
|
return [...roots];
|
|
177
182
|
}
|
|
183
|
+
/** The doctor script this package ships, resolved from the compiled module. */
|
|
184
|
+
const DOCTOR_SCRIPT = join(dirname(fileURLToPath(import.meta.url)), "..", "scripts", "doctor.mjs");
|
|
185
|
+
/**
|
|
186
|
+
* Collect the doctor's versioned JSON report and merge the live resident's
|
|
187
|
+
* own lifecycle facts when this process holds one (WSL-313).
|
|
188
|
+
*
|
|
189
|
+
* The doctor CLI is a separate process, so its handshake check can only probe
|
|
190
|
+
* a fresh resident; a live resident's `deaths` and `lastError` are
|
|
191
|
+
* host-process state with no IPC to reach them. This entry point runs from
|
|
192
|
+
* the plugin's own context instead: it collects the report as a subprocess
|
|
193
|
+
* (no plugin code is re-entered) and folds `sharedAgent(distro).status()` in
|
|
194
|
+
* — the sanctioned merge, since a snapshot that answers for no resident
|
|
195
|
+
* changes nothing. Outside the app the singleton was never started, so the
|
|
196
|
+
* returned report is the fresh probe verbatim; inside it, a wedged live
|
|
197
|
+
* resident's failures finally reach the report.
|
|
198
|
+
*
|
|
199
|
+
* @param distro - the distro the doctor examines.
|
|
200
|
+
* @param options - `doctorPath` overrides the shipped script (tests);
|
|
201
|
+
* `liveStatus` overrides the in-process status snapshot (tests).
|
|
202
|
+
* @returns the merged report.
|
|
203
|
+
*/
|
|
204
|
+
export async function doctorReport(distro, options) {
|
|
205
|
+
const script = options?.doctorPath ?? DOCTOR_SCRIPT;
|
|
206
|
+
const argv = [script, distro, "--json"];
|
|
207
|
+
if (options?.wslPath !== undefined)
|
|
208
|
+
argv.push("--wsl", options.wslPath);
|
|
209
|
+
// A nonzero doctor exit usually means an environment check FAILED on the
|
|
210
|
+
// machine being examined — that is a valid report, not a broken collection.
|
|
211
|
+
// The stdout is parsed regardless; only a run that produced no versioned
|
|
212
|
+
// report rejects.
|
|
213
|
+
const spawned = spawnSync(process.execPath, argv, {
|
|
214
|
+
timeout: 120_000,
|
|
215
|
+
maxBuffer: 4 * 1024 * 1024,
|
|
216
|
+
windowsHide: true,
|
|
217
|
+
encoding: "utf8",
|
|
218
|
+
...(options?.envPath !== undefined ? { env: { ...process.env, PATH: `${options.envPath}:${process.env.PATH ?? ""}` } } : {}),
|
|
219
|
+
});
|
|
220
|
+
// A nonzero doctor exit usually means an environment check FAILED on the
|
|
221
|
+
// machine being examined — the versioned report on stdout is still the
|
|
222
|
+
// deliverable, so it parses whenever present. Only a run that produced no
|
|
223
|
+
// report rejects, naming the spawn failure and any stderr tail.
|
|
224
|
+
let report;
|
|
225
|
+
try {
|
|
226
|
+
report = JSON.parse(spawned.stdout);
|
|
227
|
+
}
|
|
228
|
+
catch {
|
|
229
|
+
throw new Error(`doctor run failed: ${spawned.error?.message ?? `exited with code ${spawned.status}`}${spawned.stderr.length > 0 ? ` — ${spawned.stderr.trim().slice(-400)}` : ""}`);
|
|
230
|
+
}
|
|
231
|
+
const status = options?.liveStatus ?? sharedAgent(distro).status();
|
|
232
|
+
return mergeLiveResidentStatus(report, status);
|
|
233
|
+
}
|
|
178
234
|
/**
|
|
179
235
|
* The WSL shell executor's validated config — the keys of
|
|
180
236
|
* {@link WslShellExecutor.Config}, which the upstream `LocalBashExecutor`
|
|
@@ -241,6 +297,44 @@ async function sessionRuntimeWanted(value, distro, ensure, cache) {
|
|
|
241
297
|
return false;
|
|
242
298
|
}
|
|
243
299
|
}
|
|
300
|
+
/**
|
|
301
|
+
* The distro one operation belongs to, shared by the shell and filesystem
|
|
302
|
+
* resolvers: a pinned name wins, `default` goes straight to the probe, the
|
|
303
|
+
* first candidate naming a UNC distro wins, and the probe closes the list.
|
|
304
|
+
* The probe is lazy on purpose — a pinned row never pays for a default-distro
|
|
305
|
+
* probe, and a failing probe fails only the calls that actually needed it.
|
|
306
|
+
* `selectDistro` (distro-route) is the pure sibling whose fallback arrives
|
|
307
|
+
* already resolved; this one owns the probing.
|
|
308
|
+
*
|
|
309
|
+
* @param configured - the row's `distro` value.
|
|
310
|
+
* @param candidates - paths in any coordinate system, strongest evidence first.
|
|
311
|
+
* @param probeDefault - the fallback probe, invoked at most once per call.
|
|
312
|
+
*/
|
|
313
|
+
async function resolveOperationDistro(configured, candidates, probeDefault) {
|
|
314
|
+
const pinned = pinnedDistro(configured);
|
|
315
|
+
if (pinned !== undefined)
|
|
316
|
+
return pinned;
|
|
317
|
+
if (!isDefaultDistro(configured)) {
|
|
318
|
+
for (const candidate of candidates) {
|
|
319
|
+
const named = distroOfUnc(candidate);
|
|
320
|
+
if (named !== undefined)
|
|
321
|
+
return named;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
return probeDefault();
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* The refusal both shell resolvers share: the probes named no shell, and the
|
|
328
|
+
* command must not quietly run under some other interpreter.
|
|
329
|
+
* the probes named no shell, and the
|
|
330
|
+
* command must not quietly run under some other interpreter. The wording is
|
|
331
|
+
* the one `runInDistro` already throws with.
|
|
332
|
+
*
|
|
333
|
+
* @param distro - the distro whose shell could not be resolved.
|
|
334
|
+
*/
|
|
335
|
+
const unusableShell = (distro) => new Error(`dsh-plugin-wsl: distro "${distro}" named no usable shell (passwd probe and $SHELL both failed). ` +
|
|
336
|
+
`Check the user's login shell in /etc/passwd (\`getent passwd "$(id -u)"\` inside the distro), ` +
|
|
337
|
+
`or point this row's \`shell\` at an existing absolute path.`);
|
|
244
338
|
/**
|
|
245
339
|
* Bash executor that runs every command inside a WSL distro.
|
|
246
340
|
*
|
|
@@ -359,6 +453,7 @@ export class WslShellExecutor extends LocalBashExecutor {
|
|
|
359
453
|
constructor(ctx, config) {
|
|
360
454
|
super(ctx, config);
|
|
361
455
|
configureAgentBackend(config.agentBackend ?? "auto");
|
|
456
|
+
installMessagesLocale(ctx);
|
|
362
457
|
this.resolvedDistro = pinnedDistro(config.distro) ?? "";
|
|
363
458
|
this.resolvedShell = config.shell;
|
|
364
459
|
this.resolvedShells = new Map();
|
|
@@ -413,28 +508,23 @@ export class WslShellExecutor extends LocalBashExecutor {
|
|
|
413
508
|
*/
|
|
414
509
|
async distroFor(workdir, cwd) {
|
|
415
510
|
const config = this.config;
|
|
416
|
-
|
|
417
|
-
if (pinned !== undefined)
|
|
418
|
-
return pinned;
|
|
419
|
-
if (!isDefaultDistro(config.distro)) {
|
|
420
|
-
for (const candidate of [workdir, cwd ?? configuredCwd(this.config)]) {
|
|
421
|
-
const named = distroOfUnc(candidate);
|
|
422
|
-
if (named !== undefined)
|
|
423
|
-
return named;
|
|
424
|
-
}
|
|
425
|
-
}
|
|
426
|
-
return this.distro();
|
|
511
|
+
return resolveOperationDistro(config.distro, [workdir, cwd ?? configuredCwd(this.config)], () => this.distro());
|
|
427
512
|
}
|
|
428
513
|
/**
|
|
429
514
|
* The shell name for the default/pinned distro, as the shell tool presents
|
|
430
515
|
* it.
|
|
431
516
|
*
|
|
432
|
-
* @returns the basename of the shell
|
|
517
|
+
* @returns the basename of the shell; `shell` while the probe fails, and
|
|
518
|
+
* `bash` for an implausible basename.
|
|
433
519
|
*/
|
|
434
520
|
async shellName() {
|
|
435
521
|
// Consumed by the shell tool after upstream change A: it names and describes
|
|
436
|
-
// itself from the executor, so a zsh distro is never presented as bash.
|
|
437
|
-
|
|
522
|
+
// itself from the executor, so a zsh distro is never presented as bash. The
|
|
523
|
+
// naming path must not crash on a failed probe — "shell" is the honest
|
|
524
|
+
// neutral — while an implausible basename keeps the bash fallback below.
|
|
525
|
+
const shell = await this.shell().catch(() => undefined);
|
|
526
|
+
if (shell === undefined)
|
|
527
|
+
return "shell";
|
|
438
528
|
const base = String(shell ?? "").split("/").pop() ?? "";
|
|
439
529
|
const name = base.replace(/\.exe$/i, "").replace(/^[-.]+/, "");
|
|
440
530
|
return /^[a-z0-9_+-]+$/i.test(name) ? name : "bash";
|
|
@@ -446,6 +536,8 @@ export class WslShellExecutor extends LocalBashExecutor {
|
|
|
446
536
|
*
|
|
447
537
|
* @param distro - the distro name.
|
|
448
538
|
* @returns an absolute path to the shell inside the distro.
|
|
539
|
+
* @throws {Error} when neither the config nor the distro names a usable
|
|
540
|
+
* shell — the failure is not cached, so the next call re-probes.
|
|
449
541
|
*/
|
|
450
542
|
async shellFor(distro) {
|
|
451
543
|
const config = this.config;
|
|
@@ -459,26 +551,32 @@ export class WslShellExecutor extends LocalBashExecutor {
|
|
|
459
551
|
const resolved = await defaultShell(distro, { wslPath: config.wslPath });
|
|
460
552
|
if (resolved !== undefined)
|
|
461
553
|
this.resolvedShells.set(distro, resolved);
|
|
462
|
-
|
|
554
|
+
if (resolved === undefined)
|
|
555
|
+
throw unusableShell(distro);
|
|
556
|
+
return resolved;
|
|
463
557
|
}
|
|
464
558
|
/**
|
|
465
559
|
* The shell for the default/pinned distro: the configured one, else the
|
|
466
560
|
* login shell, resolved once and cached.
|
|
467
561
|
*
|
|
468
562
|
* @returns an absolute path to the shell inside the distro.
|
|
563
|
+
* @throws {Error} when neither the config nor the distro names a usable
|
|
564
|
+
* shell — the failure is not cached, so the next call re-probes.
|
|
469
565
|
*/
|
|
470
566
|
async shell() {
|
|
471
567
|
const config = this.config;
|
|
472
568
|
if (this.resolvedShell.length === 0) {
|
|
473
569
|
const distro = await this.distro();
|
|
474
|
-
// An unresolvable shell
|
|
475
|
-
// distro, a flaky first wsl.exe call
|
|
476
|
-
//
|
|
477
|
-
//
|
|
570
|
+
// An unresolvable shell fails the command loudly: the probes both came
|
|
571
|
+
// back empty (a cold distro, a flaky first wsl.exe call, a musl distro
|
|
572
|
+
// without getent), and running the command under some other interpreter
|
|
573
|
+
// would hide that from the caller. The failure is not cached — a later
|
|
574
|
+
// call re-probes and resolves the real shell once the distro is warm.
|
|
478
575
|
const resolved = await defaultShell(distro, { wslPath: config.wslPath });
|
|
479
576
|
if (resolved)
|
|
480
577
|
this.resolvedShell = resolved;
|
|
481
|
-
|
|
578
|
+
else
|
|
579
|
+
throw unusableShell(distro);
|
|
482
580
|
}
|
|
483
581
|
return this.resolvedShell;
|
|
484
582
|
}
|
|
@@ -613,7 +711,7 @@ export class WslShellExecutor extends LocalBashExecutor {
|
|
|
613
711
|
config.wslPath,
|
|
614
712
|
...distroArgs,
|
|
615
713
|
"--cd",
|
|
616
|
-
toLinuxPath(spec.workdir
|
|
714
|
+
toLinuxPath(spec.workdir),
|
|
617
715
|
// `--exec` is essential, not decoration. Without it wsl.exe hands the
|
|
618
716
|
// command line to the distro's DEFAULT SHELL, which expands it once before
|
|
619
717
|
// our own shell ever sees it: `x=1; echo "$x"` arrives as `x=1; echo ""`,
|
|
@@ -717,7 +815,7 @@ export class WslShellExecutor extends LocalBashExecutor {
|
|
|
717
815
|
const home = await distroHome(this, distro);
|
|
718
816
|
if (tail === undefined || tail.length === 0)
|
|
719
817
|
return { ...spec, workdir: home };
|
|
720
|
-
return { ...spec, workdir: toLinuxPath(tail, {
|
|
818
|
+
return { ...spec, workdir: toLinuxPath(tail, { cwd: home }) };
|
|
721
819
|
}
|
|
722
820
|
/**
|
|
723
821
|
* Decorate a handle's foreground projection in place, memoized once. The
|
|
@@ -792,9 +890,7 @@ export class WslShellExecutor extends LocalBashExecutor {
|
|
|
792
890
|
const code = wslErrorCode(result?.stdout?.text, result?.stderr?.text);
|
|
793
891
|
if (code === undefined)
|
|
794
892
|
return;
|
|
795
|
-
throw new Error(
|
|
796
|
-
`Start it with \`wsl.exe -d ${distro}\`, check \`wsl.exe -l -v\`, or point \`distro\` at another one. ` +
|
|
797
|
-
`This is not a sandbox denial, so running with wider permissions will not help.`);
|
|
893
|
+
throw new Error(t("distroUnavailable", { code, distro }));
|
|
798
894
|
}
|
|
799
895
|
/**
|
|
800
896
|
* Reject a command that ran in the wrong directory.
|
|
@@ -812,8 +908,7 @@ export class WslShellExecutor extends LocalBashExecutor {
|
|
|
812
908
|
const missing = workdirFailure(result?.stdout?.text, result?.stderr?.text);
|
|
813
909
|
if (missing === undefined)
|
|
814
910
|
return;
|
|
815
|
-
throw new Error(
|
|
816
|
-
`Create it, or point \`cwd\` (or the request's \`workdir\`) at a directory that exists.`);
|
|
911
|
+
throw new Error(t("workdirMissing", { missing }));
|
|
817
912
|
}
|
|
818
913
|
/**
|
|
819
914
|
* Execute one resolved spec inside the distro, confined by the per-call policy
|
|
@@ -862,9 +957,7 @@ export class WslShellExecutor extends LocalBashExecutor {
|
|
|
862
957
|
throwIfWorkdirInAnotherDistro(workdir, distro) {
|
|
863
958
|
if (!isAnotherDistrosUnc(workdir, distro))
|
|
864
959
|
return;
|
|
865
|
-
throw new Error(
|
|
866
|
-
`running them here would act on a different machine's tree. Open a session in that distro, ` +
|
|
867
|
-
`or point cwd/workdir at this distro.`);
|
|
960
|
+
throw new Error(t("workdirAnotherDistro", { workdir, distro }));
|
|
868
961
|
}
|
|
869
962
|
/**
|
|
870
963
|
* The agent-backed execution path: one long-lived in-distro process, the
|
|
@@ -906,7 +999,7 @@ export class WslShellExecutor extends LocalBashExecutor {
|
|
|
906
999
|
// coordinate system inside argv(); the agent carries the cwd as a frame
|
|
907
1000
|
// field, so the SAME conversion happens here — a raw UNC must never
|
|
908
1001
|
// reach `chdir` (that is the bug this line fixes).
|
|
909
|
-
cwd: toLinuxPath(resolved.workdir
|
|
1002
|
+
cwd: toLinuxPath(resolved.workdir),
|
|
910
1003
|
argv,
|
|
911
1004
|
env: Object.keys(env).length > 0 ? env : undefined,
|
|
912
1005
|
timeoutMs: resolved.timeoutMs,
|
|
@@ -1007,63 +1100,107 @@ export class WslShellExecutor extends LocalBashExecutor {
|
|
|
1007
1100
|
throw error;
|
|
1008
1101
|
});
|
|
1009
1102
|
}
|
|
1103
|
+
// The confined prepare closes over this slot: the argv builder assigns it,
|
|
1104
|
+
// the fact-stamper and the settlement mapping read it. `executeArgv` runs
|
|
1105
|
+
// the builder before either callback can fire, so the reads always see the
|
|
1106
|
+
// assigned profile (or the run never happened). The mode is captured once
|
|
1107
|
+
// here: the guard above narrowed it, and property narrowings do not reach
|
|
1108
|
+
// closures.
|
|
1010
1109
|
const mode = policy.mode;
|
|
1011
|
-
|
|
1012
|
-
const execution = await this.executeArgv(resolved,
|
|
1013
|
-
// Preparation is async, so it runs under executeArgv's deadline and
|
|
1014
|
-
// cancellation handling rather than before them. A distro without a
|
|
1015
|
-
// usable runner throws here, before anything is spawned. The outer
|
|
1016
|
-
// guard narrowed the sandbox in, but narrowings do not reach closures —
|
|
1017
|
-
// so the confined sandbox is asserted here, type-level only.
|
|
1018
|
-
confined = await this.sandbox.confine(this.distroArgv(resolved, shell), { ...policy, mode }, { distro, signal });
|
|
1019
|
-
signal.throwIfAborted();
|
|
1020
|
-
return this.argv(resolved, distro, shell, confined.argv);
|
|
1021
|
-
}, (process) => {
|
|
1022
|
-
// The outer guard cannot narrow the captured profile inside the
|
|
1023
|
-
// callback, so the confined shape is asserted once here.
|
|
1024
|
-
const profile = confined;
|
|
1025
|
-
this.processFacts.set(process, {
|
|
1026
|
-
mode,
|
|
1027
|
-
enforcement: profile.enforcement,
|
|
1028
|
-
denialSignatures: profile.denialSignatures,
|
|
1029
|
-
runnerFailureRules: profile.runnerFailureRules,
|
|
1030
|
-
runnerProgram: profile.argv[0] ?? "",
|
|
1031
|
-
workdir: resolved.workdir,
|
|
1032
|
-
windowsDrive: profile.windowsDrive,
|
|
1033
|
-
sessionScope: "per-command",
|
|
1034
|
-
});
|
|
1035
|
-
});
|
|
1110
|
+
const confinement = { profile: undefined };
|
|
1111
|
+
const execution = await this.executeArgv(resolved, (signal) => this.prepareConfinedArgv(resolved, distro, shell, policy, mode, confinement, signal), (process) => this.stampConfinedFacts(resolved, mode, confinement, process));
|
|
1036
1112
|
return WslShellExecutor.decorateResult(execution, (result) => {
|
|
1037
|
-
this.
|
|
1038
|
-
this.throwIfWorkdirMissing(result, resolved.workdir);
|
|
1039
|
-
if (confined === undefined) {
|
|
1040
|
-
return ({ ...result, sandbox: { mode, denied: false, sessionScope: "per-command" } });
|
|
1041
|
-
}
|
|
1042
|
-
const { enforcement, denialSignatures, runnerFailureRules, windowsDrive } = confined;
|
|
1043
|
-
// Runner failure outranks denial because the command did not run at all.
|
|
1044
|
-
const runnerFailure = classifyRunnerFailure(result.exitCode, result.stderr.text, runnerFailureRules);
|
|
1045
|
-
if (runnerFailure !== undefined)
|
|
1046
|
-
throw new SandboxUnavailableError(mode, withBwrapHint(runnerFailure.detail, distro));
|
|
1047
|
-
return ({
|
|
1048
|
-
...result,
|
|
1049
|
-
sandbox: {
|
|
1050
|
-
mode,
|
|
1051
|
-
denied: matchesSignature(result.exitCode, result.stderr.text, denialSignatures),
|
|
1052
|
-
enforcement,
|
|
1053
|
-
windowsDrive,
|
|
1054
|
-
sessionScope: "per-command",
|
|
1055
|
-
},
|
|
1056
|
-
});
|
|
1113
|
+
return this.settleConfinedOneShot(result, distro, resolved, mode, confinement.profile);
|
|
1057
1114
|
}, (error) => {
|
|
1058
1115
|
// An upstream abort remains cancellation even when it prevents spawn.
|
|
1059
1116
|
if (resolved.signal?.aborted === true)
|
|
1060
1117
|
resolved.signal.throwIfAborted();
|
|
1061
|
-
if (
|
|
1118
|
+
if (confinement.profile !== undefined && isRunnerSpawnFailure(error, confinement.profile.argv[0], resolved.workdir)) {
|
|
1062
1119
|
throw new SandboxUnavailableError(mode, withBwrapHint(String(error), distro));
|
|
1063
1120
|
}
|
|
1064
1121
|
throw error;
|
|
1065
1122
|
});
|
|
1066
1123
|
}
|
|
1124
|
+
/**
|
|
1125
|
+
* The confined one-shot's argv prepare: confine the distro argv under the
|
|
1126
|
+
* policy, keep the resulting profile for the fact-stamper and the settlement
|
|
1127
|
+
* mapping, and hand back the wrapped host argv.
|
|
1128
|
+
*
|
|
1129
|
+
* @param resolved - the resolved spec.
|
|
1130
|
+
* @param distro - the resolved distro name.
|
|
1131
|
+
* @param shell - the resolved distro shell.
|
|
1132
|
+
* @param policy - the confined policy (narrowed in by `executeOneShot`).
|
|
1133
|
+
* @param slot - the closure the builder assigns the profile into.
|
|
1134
|
+
* @param signal - the caller's cancellation.
|
|
1135
|
+
*/
|
|
1136
|
+
async prepareConfinedArgv(resolved, distro, shell, policy, mode, slot, signal) {
|
|
1137
|
+
// Preparation is async, so it runs under executeArgv's deadline and
|
|
1138
|
+
// cancellation handling rather than before them. A distro without a
|
|
1139
|
+
// usable runner throws here, before anything is spawned. The outer
|
|
1140
|
+
// guard narrowed the sandbox in, but narrowings do not reach closures —
|
|
1141
|
+
// so the confined sandbox is asserted here, type-level only.
|
|
1142
|
+
const profile = await this.sandbox.confine(this.distroArgv(resolved, shell), { ...policy, mode }, { distro, signal });
|
|
1143
|
+
slot.profile = profile;
|
|
1144
|
+
signal.throwIfAborted();
|
|
1145
|
+
return this.argv(resolved, distro, shell, profile.argv);
|
|
1146
|
+
}
|
|
1147
|
+
/**
|
|
1148
|
+
* Stamp the per-process sandbox facts before `done` settles, so a background
|
|
1149
|
+
* process reports the same mode, denial and enforcement a foreground run
|
|
1150
|
+
* would.
|
|
1151
|
+
*
|
|
1152
|
+
* @param resolved - the resolved spec.
|
|
1153
|
+
* @param mode - the confined policy's mode.
|
|
1154
|
+
* @param slot - the closure holding the assigned profile.
|
|
1155
|
+
* @param process - the spawned handle.
|
|
1156
|
+
*/
|
|
1157
|
+
stampConfinedFacts(resolved, mode, slot, process) {
|
|
1158
|
+
// The builder has run before any process callback can fire; the confined
|
|
1159
|
+
// shape is asserted once here, type-level only.
|
|
1160
|
+
const profile = slot.profile;
|
|
1161
|
+
this.processFacts.set(process, {
|
|
1162
|
+
mode,
|
|
1163
|
+
enforcement: profile.enforcement,
|
|
1164
|
+
denialSignatures: profile.denialSignatures,
|
|
1165
|
+
runnerFailureRules: profile.runnerFailureRules,
|
|
1166
|
+
runnerProgram: profile.argv[0] ?? "",
|
|
1167
|
+
workdir: resolved.workdir,
|
|
1168
|
+
windowsDrive: profile.windowsDrive,
|
|
1169
|
+
sessionScope: "per-command",
|
|
1170
|
+
});
|
|
1171
|
+
}
|
|
1172
|
+
/**
|
|
1173
|
+
* Settle one confined one-shot result: the distro and workdir verdicts, the
|
|
1174
|
+
* never-armed honesty stamp, the runner-failure throw, and the denial facts.
|
|
1175
|
+
*
|
|
1176
|
+
* @param result - the settled process result.
|
|
1177
|
+
* @param distro - the resolved distro name.
|
|
1178
|
+
* @param resolved - the resolved spec.
|
|
1179
|
+
* @param mode - the confined policy's mode.
|
|
1180
|
+
* @param confined - the profile the argv prepare armed, when it ran.
|
|
1181
|
+
*/
|
|
1182
|
+
settleConfinedOneShot(result, distro, resolved, mode, confined) {
|
|
1183
|
+
this.throwIfDistroUnavailable(result, distro);
|
|
1184
|
+
this.throwIfWorkdirMissing(result, resolved.workdir);
|
|
1185
|
+
if (confined === undefined) {
|
|
1186
|
+
return ({ ...result, sandbox: { mode, denied: false, sessionScope: "per-command" } });
|
|
1187
|
+
}
|
|
1188
|
+
const { enforcement, denialSignatures, runnerFailureRules, windowsDrive } = confined;
|
|
1189
|
+
// Runner failure outranks denial because the command did not run at all.
|
|
1190
|
+
const runnerFailure = classifyRunnerFailure(result.exitCode, result.stderr.text, runnerFailureRules);
|
|
1191
|
+
if (runnerFailure !== undefined)
|
|
1192
|
+
throw new SandboxUnavailableError(mode, withBwrapHint(runnerFailure.detail, distro));
|
|
1193
|
+
return ({
|
|
1194
|
+
...result,
|
|
1195
|
+
sandbox: {
|
|
1196
|
+
mode,
|
|
1197
|
+
denied: matchesSignature(result.exitCode, result.stderr.text, denialSignatures),
|
|
1198
|
+
enforcement,
|
|
1199
|
+
windowsDrive,
|
|
1200
|
+
sessionScope: "per-command",
|
|
1201
|
+
},
|
|
1202
|
+
});
|
|
1203
|
+
}
|
|
1067
1204
|
}
|
|
1068
1205
|
export class WslFileSystem extends LocalFileSystem {
|
|
1069
1206
|
static inject = ["sandboxPolicy"];
|
|
@@ -1155,6 +1292,7 @@ export class WslFileSystem extends LocalFileSystem {
|
|
|
1155
1292
|
if (refusal !== null)
|
|
1156
1293
|
throw new Error(refusal.message);
|
|
1157
1294
|
super(ctx, config);
|
|
1295
|
+
installMessagesLocale(ctx);
|
|
1158
1296
|
this.resolvedDistro = pinnedDistro(config.distro) ?? "";
|
|
1159
1297
|
this.resolvedHome = undefined;
|
|
1160
1298
|
this.resolvedHomes = new Map();
|
|
@@ -1430,17 +1568,7 @@ export class WslFileSystem extends LocalFileSystem {
|
|
|
1430
1568
|
*/
|
|
1431
1569
|
async distroForPath(path, cwd) {
|
|
1432
1570
|
const config = this.config;
|
|
1433
|
-
|
|
1434
|
-
if (pinned !== undefined)
|
|
1435
|
-
return pinned;
|
|
1436
|
-
if (!isDefaultDistro(config.distro)) {
|
|
1437
|
-
for (const candidate of [path, cwd ?? config.cwd]) {
|
|
1438
|
-
const named = distroOfUnc(candidate);
|
|
1439
|
-
if (named !== undefined)
|
|
1440
|
-
return named;
|
|
1441
|
-
}
|
|
1442
|
-
}
|
|
1443
|
-
return this.distro();
|
|
1571
|
+
return resolveOperationDistro(config.distro, [path, cwd ?? config.cwd], () => this.distro());
|
|
1444
1572
|
}
|
|
1445
1573
|
/**
|
|
1446
1574
|
* The distro a resolved target belongs to. A UNC identity names it outright;
|
|
@@ -1461,17 +1589,7 @@ export class WslFileSystem extends LocalFileSystem {
|
|
|
1461
1589
|
*/
|
|
1462
1590
|
async distroForPolicy(policy) {
|
|
1463
1591
|
const config = this.config;
|
|
1464
|
-
|
|
1465
|
-
if (pinned !== undefined)
|
|
1466
|
-
return pinned;
|
|
1467
|
-
if (!isDefaultDistro(config.distro)) {
|
|
1468
|
-
for (const candidate of [policy?.workspaceRoot, config.cwd]) {
|
|
1469
|
-
const named = distroOfUnc(candidate);
|
|
1470
|
-
if (named !== undefined)
|
|
1471
|
-
return named;
|
|
1472
|
-
}
|
|
1473
|
-
}
|
|
1474
|
-
return this.distro();
|
|
1592
|
+
return resolveOperationDistro(config.distro, [policy?.workspaceRoot, config.cwd], () => this.distro());
|
|
1475
1593
|
}
|
|
1476
1594
|
/**
|
|
1477
1595
|
* Translate one caller path into the world path, enforcing the distro fence.
|
|
@@ -1817,46 +1935,70 @@ export class WslFileSystem extends LocalFileSystem {
|
|
|
1817
1935
|
}
|
|
1818
1936
|
}
|
|
1819
1937
|
/**
|
|
1820
|
-
*
|
|
1821
|
-
*
|
|
1822
|
-
* the
|
|
1823
|
-
*
|
|
1824
|
-
*
|
|
1825
|
-
*
|
|
1826
|
-
*
|
|
1827
|
-
*
|
|
1828
|
-
* @param
|
|
1829
|
-
* @param
|
|
1830
|
-
* @
|
|
1831
|
-
* @param _signal - cancellation; unused while the operation refuses.
|
|
1832
|
-
* @param _sandboxPolicy - the per-call policy; unused while the operation refuses.
|
|
1938
|
+
* Apply parsed hunks (protocol 7): hunk matching and application run
|
|
1939
|
+
* in-process through the peer's own `applyHunks` (the same dialect and
|
|
1940
|
+
* `FS_PATCH_MISMATCH` the peer emits), against the distro's bytes, then
|
|
1941
|
+
* publish through the same guarded atomic write an edit takes.
|
|
1942
|
+
*
|
|
1943
|
+
* @param target - the resolved regular file.
|
|
1944
|
+
* @param hunks - ordered hunks from the caller's patch parse.
|
|
1945
|
+
* @param expected - the version the patch was based on.
|
|
1946
|
+
* @param signal - cancels the patch.
|
|
1947
|
+
* @param sandboxPolicy - the per-call policy; omit for the deployment default.
|
|
1948
|
+
* @returns the pre/post text and the published version.
|
|
1833
1949
|
*/
|
|
1834
|
-
async patchText(target,
|
|
1835
|
-
|
|
1950
|
+
async patchText(target, hunks, expected, signal, sandboxPolicy) {
|
|
1951
|
+
const policy = sandboxPolicy ?? this.ctx.sandboxPolicy.resolve();
|
|
1952
|
+
const fenced = await this.checkedTarget(target, policy);
|
|
1953
|
+
try {
|
|
1954
|
+
return (await (await this.substrateForTarget(fenced)).patchText(fenced, hunks, expected, signal, policy));
|
|
1955
|
+
}
|
|
1956
|
+
catch (error) {
|
|
1957
|
+
throw this.peerError(error);
|
|
1958
|
+
}
|
|
1836
1959
|
}
|
|
1837
1960
|
/**
|
|
1838
|
-
*
|
|
1839
|
-
*
|
|
1840
|
-
*
|
|
1841
|
-
*
|
|
1842
|
-
* @param
|
|
1843
|
-
* @param
|
|
1844
|
-
* @param
|
|
1961
|
+
* Remove one regular file (protocol 7) after fencing the target by the
|
|
1962
|
+
* per-call policy; the guarded removal re-verifies the expected version
|
|
1963
|
+
* distro-side.
|
|
1964
|
+
*
|
|
1965
|
+
* @param target - the resolved file.
|
|
1966
|
+
* @param expected - the version the removal was based on.
|
|
1967
|
+
* @param signal - cancels the removal.
|
|
1968
|
+
* @param sandboxPolicy - the per-call policy; omit for the deployment default.
|
|
1969
|
+
* @returns the bounded pre-removal text basis.
|
|
1845
1970
|
*/
|
|
1846
|
-
async deleteFile(target,
|
|
1847
|
-
|
|
1971
|
+
async deleteFile(target, expected, signal, sandboxPolicy) {
|
|
1972
|
+
const policy = sandboxPolicy ?? this.ctx.sandboxPolicy.resolve();
|
|
1973
|
+
const fenced = await this.checkedTarget(target, policy);
|
|
1974
|
+
try {
|
|
1975
|
+
return (await (await this.substrateForTarget(fenced)).deleteFile(fenced, expected, signal, policy));
|
|
1976
|
+
}
|
|
1977
|
+
catch (error) {
|
|
1978
|
+
throw this.peerError(error);
|
|
1979
|
+
}
|
|
1848
1980
|
}
|
|
1849
1981
|
/**
|
|
1850
|
-
*
|
|
1851
|
-
*
|
|
1982
|
+
* Move one regular file (protocol 7) after fencing BOTH endpoints by the
|
|
1983
|
+
* per-call policy — the destination publishes and the source is removed, so
|
|
1984
|
+
* each must be writable under the same roots.
|
|
1852
1985
|
*
|
|
1853
1986
|
* @param source - the resolved source.
|
|
1854
1987
|
* @param destination - the resolved destination.
|
|
1855
|
-
* @param
|
|
1856
|
-
* @param
|
|
1857
|
-
* @param
|
|
1988
|
+
* @param options - the hunks and the source/destination guards.
|
|
1989
|
+
* @param signal - cancels before publication.
|
|
1990
|
+
* @param sandboxPolicy - the per-call policy; omit for the deployment default.
|
|
1991
|
+
* @returns the bounded source basis and the destination outcome.
|
|
1858
1992
|
*/
|
|
1859
|
-
async moveFile(source, destination,
|
|
1860
|
-
|
|
1993
|
+
async moveFile(source, destination, options, signal, sandboxPolicy) {
|
|
1994
|
+
const policy = sandboxPolicy ?? this.ctx.sandboxPolicy.resolve();
|
|
1995
|
+
const fencedSource = await this.checkedTarget(source, policy);
|
|
1996
|
+
const fencedDestination = await this.checkedTarget(destination, policy);
|
|
1997
|
+
try {
|
|
1998
|
+
return (await (await this.substrateForTarget(fencedSource)).moveFile(fencedSource, fencedDestination, options, signal, policy));
|
|
1999
|
+
}
|
|
2000
|
+
catch (error) {
|
|
2001
|
+
throw this.peerError(error);
|
|
2002
|
+
}
|
|
1861
2003
|
}
|
|
1862
2004
|
}
|
package/lib/listing.d.ts
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* run `pnpm run build` — the artifact under `lib/` is generated, and `pnpm test`
|
|
9
9
|
* fails when it drifts.
|
|
10
10
|
*
|
|
11
|
-
* @module dsh-plugin-wsl/listing
|
|
11
|
+
* @module dsh-plugin-wsl-env/listing
|
|
12
12
|
*/
|
|
13
13
|
/** One picker row: a display name, its jump target, and the dot-entry flag. */
|
|
14
14
|
export interface ListingRow {
|
package/lib/listing.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* run `pnpm run build` — the artifact under `lib/` is generated, and `pnpm test`
|
|
9
9
|
* fails when it drifts.
|
|
10
10
|
*
|
|
11
|
-
* @module dsh-plugin-wsl/listing
|
|
11
|
+
* @module dsh-plugin-wsl-env/listing
|
|
12
12
|
*/
|
|
13
13
|
import { win32 } from "node:path";
|
|
14
14
|
import { isWslUnc, uncToPosix } from "./paths.js";
|