dsh-plugin-wsl-env 0.17.1 → 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.
- package/CHANGELOG.md +225 -0
- package/CONTRIBUTING.md +37 -5
- package/README.md +61 -6
- 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/cordis.patch.yml +10 -5
- package/docs/AGENT-PROTOCOL-V7.md +175 -0
- package/docs/API.md +24 -0
- package/docs/ARCHITECTURE.md +20 -6
- package/docs/COMPATIBILITY.md +1 -1
- package/docs/CONFIGURATION.md +33 -5
- package/docs/CONFIGURATION.zh.md +25 -4
- package/docs/LIMITATIONS.md +39 -7
- package/docs/LIMITATIONS.zh.md +31 -6
- package/docs/MIGRATION.md +4 -4
- package/docs/PEER-PARITY.md +94 -35
- package/docs/QUICKSTART.md +19 -2
- package/docs/QUICKSTART.zh.md +16 -1
- package/docs/README.zh.md +47 -7
- package/docs/RELEASING.md +3 -2
- package/docs/REQUIREMENTS.zh.md +11 -6
- package/docs/ROADMAP-1.0.md +40 -29
- package/docs/ROADMAP.md +10 -6
- package/docs/UPSTREAM-FILE-REFERENCE-SEAM.md +6 -1
- package/docs/UPSTREAM-FSIO-EXPORT.md +2 -2
- package/docs/UPSTREAM-SERVICE-SWAP.md +124 -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/distro-route.d.ts +1 -1
- package/lib/distro-route.js +1 -1
- package/lib/doctor-live.d.ts +53 -0
- package/lib/doctor-live.js +37 -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 +52 -2
- package/lib/fs-routing.js +56 -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 +127 -3
- package/lib/index.js +301 -99
- package/lib/listing.d.ts +1 -1
- package/lib/listing.js +1 -1
- 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 +1 -1
- package/lib/preflight.js +1 -1
- package/lib/sandbox-core.d.ts +1 -1
- package/lib/sandbox-core.js +2 -2
- 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 +1 -1
- package/lib/shell-env.d.ts +1 -1
- package/lib/shell-env.js +1 -1
- package/lib/shell.d.ts +1 -1
- package/lib/shell.js +1 -1
- 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/watcher.d.ts +1 -1
- package/lib/watcher.js +1 -1
- package/lib/wsl.d.ts +1 -31
- package/lib/wsl.js +1 -21
- package/package.json +41 -28
- package/scripts/doctor.mjs +34 -11
package/lib/fsio-agent.js
CHANGED
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
* run `pnpm run build` — the artifact under `lib/` is generated, and `pnpm test`
|
|
20
20
|
* fails when it drifts.
|
|
21
21
|
*
|
|
22
|
-
* @module dsh-plugin-wsl/fsio-agent
|
|
22
|
+
* @module dsh-plugin-wsl-env/fsio-agent
|
|
23
23
|
*/
|
|
24
24
|
import { FS_READ_CHUNK_BYTES } from "./agent-protocol.js";
|
|
25
25
|
import { BINARY_SAMPLE_BYTES, FsCodedError, decodeUtf8, decodeUtf8Stream, detectLineEndings, normalizeLineEndings, restoreLineEndings, applyLiteralEdit, throwIfAborted, } from "./fsio-text.js";
|
|
@@ -40,8 +40,11 @@ export function nanoseconds(value) {
|
|
|
40
40
|
}
|
|
41
41
|
/**
|
|
42
42
|
* The peer's `versionOf`: dev, inode, size and both nanosecond timestamps.
|
|
43
|
-
* Self-consistency within this provider is what versions need
|
|
44
|
-
*
|
|
43
|
+
* Self-consistency within this provider is what versions need. The string's
|
|
44
|
+
* granularity is the file's stat identity, not its bytes: a write that moves
|
|
45
|
+
* size or either timestamp moves the string, while a same-size write that
|
|
46
|
+
* leaves both timestamps untouched does not — the peer's own `versionOf`
|
|
47
|
+
* has exactly the same granularity, so guard comparisons behave alike.
|
|
45
48
|
*
|
|
46
49
|
* @param ingredients - the stat record's identity fields.
|
|
47
50
|
* @returns the opaque version string.
|
|
@@ -70,7 +73,7 @@ export function parseStatRecord(stdout) {
|
|
|
70
73
|
version: versionOf({ dev, ino, size, mtimeNs: nanoseconds(mtime), ctimeNs: nanoseconds(ctime) }),
|
|
71
74
|
};
|
|
72
75
|
}
|
|
73
|
-
const REASON_CODES = {
|
|
76
|
+
export const REASON_CODES = {
|
|
74
77
|
notfound: "FS_NOT_FOUND",
|
|
75
78
|
notdir: "FS_NOT_DIRECTORY",
|
|
76
79
|
perm: "FS_IO_ERROR",
|
|
@@ -79,6 +82,15 @@ const REASON_CODES = {
|
|
|
79
82
|
stale: "FS_STALE_VERSION",
|
|
80
83
|
io: "FS_IO_ERROR",
|
|
81
84
|
};
|
|
85
|
+
/**
|
|
86
|
+
* Map one wire reason token onto the peer's `FsErrorCode` vocabulary.
|
|
87
|
+
*
|
|
88
|
+
* @param reason - the agent's reason token (`notfound`, `stale`, …).
|
|
89
|
+
* @returns the corresponding code; unknown tokens read as I/O failures.
|
|
90
|
+
*/
|
|
91
|
+
export function reasonToCode(reason) {
|
|
92
|
+
return REASON_CODES[reason] ?? "FS_IO_ERROR";
|
|
93
|
+
}
|
|
82
94
|
/**
|
|
83
95
|
* The kernel's denial dialect: a write that a read-only bind refused. The
|
|
84
96
|
* command path classifies the same signature into its sandbox denial, so a
|
|
@@ -135,6 +147,13 @@ export class DistroFs {
|
|
|
135
147
|
*/
|
|
136
148
|
fail(op, result, displayPath) {
|
|
137
149
|
const text = result.stderr.toString("utf8");
|
|
150
|
+
if (result.reason !== undefined) {
|
|
151
|
+
const message = text.trim();
|
|
152
|
+
if (op === "write" && DENIAL_SIGNATURES.some((signature) => message.toLowerCase().includes(signature))) {
|
|
153
|
+
return new FsCodedError(`cannot write "${displayPath}": ${message}`, "FS_SANDBOX_DENIED");
|
|
154
|
+
}
|
|
155
|
+
return new FsCodedError(message, REASON_CODES[result.reason] ?? "FS_IO_ERROR");
|
|
156
|
+
}
|
|
138
157
|
const first = text.split("\n")[0] ?? "";
|
|
139
158
|
if (first.startsWith("dsh-fs|")) {
|
|
140
159
|
const [, reason, encoded] = first.split("|");
|
|
@@ -212,16 +231,44 @@ export class DistroFs {
|
|
|
212
231
|
async listChildren(target, signal) {
|
|
213
232
|
throwIfAborted(signal, "list");
|
|
214
233
|
const linuxDir = uncToPosix(target.targetKey)?.linuxPath ?? target.displayPath;
|
|
215
|
-
|
|
216
|
-
if (
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
234
|
+
let listPayload;
|
|
235
|
+
if (this.supportsBatch()) {
|
|
236
|
+
// Protocol 7: the stat and the list ride one FSB frame.
|
|
237
|
+
const records = await this.batch([
|
|
238
|
+
{ op: "stat", args: [linuxDir] },
|
|
239
|
+
{ op: "list", args: [linuxDir] },
|
|
240
|
+
], signal);
|
|
241
|
+
const statRecord = records[0];
|
|
242
|
+
const listRecord = records[1];
|
|
243
|
+
if (statRecord === undefined || !statRecord.ok) {
|
|
244
|
+
if (statRecord !== undefined && !statRecord.ok && statRecord.reason !== "notfound") {
|
|
245
|
+
throw new FsCodedError(statRecord.message, reasonToCode(statRecord.reason));
|
|
246
|
+
}
|
|
247
|
+
throw new FsCodedError(`cannot list "${target.displayPath}": not found`, "FS_NOT_FOUND");
|
|
248
|
+
}
|
|
249
|
+
if (parseStatRecord(statRecord.payload).type !== "d") {
|
|
250
|
+
throw new FsCodedError(`cannot list "${target.displayPath}": not a directory`, "FS_NOT_DIRECTORY");
|
|
251
|
+
}
|
|
252
|
+
if (listRecord === undefined || !listRecord.ok) {
|
|
253
|
+
if (listRecord !== undefined && !listRecord.ok)
|
|
254
|
+
throw new FsCodedError(listRecord.message, reasonToCode(listRecord.reason));
|
|
255
|
+
throw new FsCodedError(`cannot list "${target.displayPath}": distro I/O failure`, "FS_IO_ERROR");
|
|
256
|
+
}
|
|
257
|
+
listPayload = listRecord.payload;
|
|
258
|
+
}
|
|
259
|
+
else {
|
|
260
|
+
const info = await this.stat(linuxDir, { signal });
|
|
261
|
+
if (!info)
|
|
262
|
+
throw new FsCodedError(`cannot list "${target.displayPath}": not found`, "FS_NOT_FOUND");
|
|
263
|
+
if (info.type !== "d")
|
|
264
|
+
throw new FsCodedError(`cannot list "${target.displayPath}": not a directory`, "FS_NOT_DIRECTORY");
|
|
265
|
+
const result = await this.request("list", [linuxDir], signal);
|
|
266
|
+
if (result.exitCode !== 0)
|
|
267
|
+
throw this.fail("list", result, target.displayPath);
|
|
268
|
+
listPayload = result.stdout;
|
|
269
|
+
}
|
|
223
270
|
const parentCanonical = linuxDir;
|
|
224
|
-
const records =
|
|
271
|
+
const records = listPayload.toString("utf8").split("\0").filter((record) => record.length > 0);
|
|
225
272
|
const entries = [];
|
|
226
273
|
for (const record of records) {
|
|
227
274
|
throwIfAborted(signal, "list");
|
|
@@ -324,13 +371,75 @@ export class DistroFs {
|
|
|
324
371
|
* @returns the full decoded text, byte-for-byte.
|
|
325
372
|
*/
|
|
326
373
|
async readWholeText(target, signal) {
|
|
327
|
-
await this.
|
|
328
|
-
const raw = await this.readWhole(target, signal);
|
|
374
|
+
const raw = this.supportsBatch() ? await this.readWholeBatched(target, signal) : await this.statThenReadWhole(target, signal);
|
|
329
375
|
if (raw.subarray(0, BINARY_SAMPLE_BYTES).includes(0)) {
|
|
330
376
|
throw new FsCodedError(`cannot read "${target.displayPath}": binary file`, "FS_NOT_TEXT");
|
|
331
377
|
}
|
|
332
378
|
return decodeUtf8(raw, "read", target.displayPath);
|
|
333
379
|
}
|
|
380
|
+
/**
|
|
381
|
+
* The single-frame fallback for {@link readWholeText}: one stat, then the
|
|
382
|
+
* windowed read loop (a v6 peer).
|
|
383
|
+
*
|
|
384
|
+
* @param target - the resolved file.
|
|
385
|
+
* @param signal - aborts the read.
|
|
386
|
+
* @returns the file's bytes.
|
|
387
|
+
*/
|
|
388
|
+
async statThenReadWhole(target, signal) {
|
|
389
|
+
await this.statRegularFile(target, "read", signal);
|
|
390
|
+
return this.readWhole(target, signal);
|
|
391
|
+
}
|
|
392
|
+
/**
|
|
393
|
+
* The protocol-7 batch path for {@link readWholeText}: the stat and the
|
|
394
|
+
* first read window ride ONE FSB frame — the GUI preview's dominant
|
|
395
|
+
* shape — and further windows stay single reads.
|
|
396
|
+
*
|
|
397
|
+
* @param target - the resolved file.
|
|
398
|
+
* @param signal - aborts the read.
|
|
399
|
+
* @returns the file's bytes.
|
|
400
|
+
*/
|
|
401
|
+
async readWholeBatched(target, signal) {
|
|
402
|
+
const linuxPath = uncToPosix(target.targetKey)?.linuxPath ?? target.displayPath;
|
|
403
|
+
const records = await this.batch([
|
|
404
|
+
{ op: "stat", args: [linuxPath] },
|
|
405
|
+
{ op: "read", args: [linuxPath, "0", String(FS_READ_CHUNK_BYTES)] },
|
|
406
|
+
], signal);
|
|
407
|
+
const statRecord = records[0];
|
|
408
|
+
if (statRecord === undefined || !statRecord.ok) {
|
|
409
|
+
if (statRecord !== undefined && !statRecord.ok) {
|
|
410
|
+
if (statRecord.reason === "notfound")
|
|
411
|
+
throw new FsCodedError(`cannot read "${target.displayPath}": not found`, "FS_NOT_FOUND");
|
|
412
|
+
throw new FsCodedError(statRecord.message, reasonToCode(statRecord.reason));
|
|
413
|
+
}
|
|
414
|
+
throw new FsCodedError(`cannot read "${target.displayPath}": distro I/O failure`, "FS_IO_ERROR");
|
|
415
|
+
}
|
|
416
|
+
const info = parseStatRecord(statRecord.payload);
|
|
417
|
+
if (info.type !== "f")
|
|
418
|
+
throw new FsCodedError(`cannot read "${target.displayPath}": not a regular file`, "FS_NOT_REGULAR_FILE");
|
|
419
|
+
const first = records[1];
|
|
420
|
+
if (first === undefined || !first.ok) {
|
|
421
|
+
if (first !== undefined && !first.ok)
|
|
422
|
+
throw new FsCodedError(first.message, reasonToCode(first.reason));
|
|
423
|
+
throw new FsCodedError(`cannot read "${target.displayPath}": distro I/O failure`, "FS_IO_ERROR");
|
|
424
|
+
}
|
|
425
|
+
const chunks = [];
|
|
426
|
+
let offset = 0;
|
|
427
|
+
let chunk = first.payload;
|
|
428
|
+
for (;;) {
|
|
429
|
+
if (chunk.length === 0)
|
|
430
|
+
break;
|
|
431
|
+
chunks.push(chunk);
|
|
432
|
+
offset += chunk.length;
|
|
433
|
+
if (chunk.length < FS_READ_CHUNK_BYTES)
|
|
434
|
+
break;
|
|
435
|
+
throwIfAborted(signal, "read");
|
|
436
|
+
const result = await this.request("read", [linuxPath, String(offset), String(FS_READ_CHUNK_BYTES)], signal);
|
|
437
|
+
if (result.exitCode !== 0)
|
|
438
|
+
throw this.fail("read", result, target.displayPath);
|
|
439
|
+
chunk = result.stdout;
|
|
440
|
+
}
|
|
441
|
+
return Buffer.concat(chunks, offset);
|
|
442
|
+
}
|
|
334
443
|
/**
|
|
335
444
|
* Read a whole regular file as raw bytes, bounded by `maxBytes`.
|
|
336
445
|
*
|
|
@@ -439,6 +548,106 @@ export class DistroFs {
|
|
|
439
548
|
}
|
|
440
549
|
throw new FsCodedError(`cannot overwrite existing "${displayPath}" without reading it first`, "FS_NOT_OBSERVED", failure);
|
|
441
550
|
}
|
|
551
|
+
/**
|
|
552
|
+
* Whether the resident accepts protocol-7 batch frames.
|
|
553
|
+
*
|
|
554
|
+
* @param agent - the agent to ask; the default resident by default.
|
|
555
|
+
* @returns true when the negotiated version and capabilities allow FSB.
|
|
556
|
+
*/
|
|
557
|
+
supportsBatch(agent = this.agent) {
|
|
558
|
+
return agent.protocolVersion >= 7 && agent.caps.has("batch");
|
|
559
|
+
}
|
|
560
|
+
/**
|
|
561
|
+
* Whether the resident serves the protocol-7 destructive ops
|
|
562
|
+
* (`delete`, `move`) and the structured FSERR channel.
|
|
563
|
+
*
|
|
564
|
+
* @param agent - the agent to ask; the default resident by default.
|
|
565
|
+
* @returns true for a protocol-7 resident.
|
|
566
|
+
*/
|
|
567
|
+
supportsDestructive(agent = this.agent) {
|
|
568
|
+
return agent.protocolVersion >= 7;
|
|
569
|
+
}
|
|
570
|
+
/**
|
|
571
|
+
* Run one batched FS frame and parse its per-op records.
|
|
572
|
+
*
|
|
573
|
+
* @param ops - the ordered ops (`stat`, `list`, `read`, …).
|
|
574
|
+
* @param signal - cancels the batch.
|
|
575
|
+
* @param agent - the agent to run it on.
|
|
576
|
+
* @returns one record per op, in order.
|
|
577
|
+
*/
|
|
578
|
+
async batch(ops, signal, agent = this.agent) {
|
|
579
|
+
const result = await agent.fsb({ ops, timeoutMs: FS_OP_TIMEOUT_MS, signal });
|
|
580
|
+
if (result.exitCode !== 0)
|
|
581
|
+
throw this.fail("batch", result, ops.map((op) => op.op).join(","));
|
|
582
|
+
const records = [];
|
|
583
|
+
for (const line of result.stdout.toString("utf8").split("\n")) {
|
|
584
|
+
if (line.length === 0)
|
|
585
|
+
continue;
|
|
586
|
+
if (line.startsWith("OK ")) {
|
|
587
|
+
const bar = line.indexOf("|");
|
|
588
|
+
records.push({ ok: true, payload: Buffer.from(line.slice(bar + 1), "base64") });
|
|
589
|
+
}
|
|
590
|
+
else if (line.startsWith("BAD ")) {
|
|
591
|
+
const [, reason, message] = line.split("|");
|
|
592
|
+
records.push({ ok: false, reason: reason ?? "io", message: Buffer.from(message ?? "", "base64").toString("utf8") });
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
return records;
|
|
596
|
+
}
|
|
597
|
+
/**
|
|
598
|
+
* Remove one regular file through the protocol-7 `delete` op, whose guards
|
|
599
|
+
* mirror the peer's `requireFile`: a vanished file is stale, a non-regular
|
|
600
|
+
* target its own refusal, an expected version re-verified distro-side.
|
|
601
|
+
*
|
|
602
|
+
* @param linuxPath - the resolved Linux path.
|
|
603
|
+
* @param expectedVersion - the version the removal was based on.
|
|
604
|
+
* @param signal - cancels the removal.
|
|
605
|
+
* @param agent - the agent that must run it.
|
|
606
|
+
* @returns resolves when the file is gone.
|
|
607
|
+
*/
|
|
608
|
+
async removeFile(linuxPath, expectedVersion, signal, agent = this.agent) {
|
|
609
|
+
const result = await this.request("delete", [linuxPath, expectedVersion ?? "-"], signal, agent);
|
|
610
|
+
if (result.exitCode === 0)
|
|
611
|
+
return;
|
|
612
|
+
throw this.fail("delete", result, linuxPath);
|
|
613
|
+
}
|
|
614
|
+
/**
|
|
615
|
+
* Move one regular file through the protocol-7 `move` op: the destination
|
|
616
|
+
* publishes through the write machinery's staging (atomic rename, or the
|
|
617
|
+
* no-replace link for a guarded create), then the source is removed. A
|
|
618
|
+
* destination that published while the source survived comes back as
|
|
619
|
+
* `sourceFailure` — the peer's two-effect outcome.
|
|
620
|
+
*
|
|
621
|
+
* @param source - the resolved source path.
|
|
622
|
+
* @param destination - the resolved destination path.
|
|
623
|
+
* @param options - the destination mode, publish guard and version guards.
|
|
624
|
+
* @param signal - cancels the move.
|
|
625
|
+
* @param agent - the agent that must run it.
|
|
626
|
+
* @returns the destination's fresh stat row and the source-removal outcome.
|
|
627
|
+
*/
|
|
628
|
+
async moveAtomic(source, destination, options) {
|
|
629
|
+
const result = await this.request("move", [
|
|
630
|
+
source,
|
|
631
|
+
destination,
|
|
632
|
+
options.mode === undefined ? "-" : (options.mode & 0o7777).toString(8),
|
|
633
|
+
options.guard,
|
|
634
|
+
options.sourceVersion ?? "-",
|
|
635
|
+
options.destinationVersion ?? "-",
|
|
636
|
+
], options.signal, options.agent ?? this.agent);
|
|
637
|
+
if (result.exitCode !== 0)
|
|
638
|
+
throw this.fail("move", result, source);
|
|
639
|
+
const lines = result.stdout.toString("utf8").split("\n").filter((line) => line.length > 0);
|
|
640
|
+
const statLine = lines[0] ?? "";
|
|
641
|
+
const destinationRow = parseStatRecord(Buffer.from(statLine, "utf8"));
|
|
642
|
+
const failureLine = lines.find((line) => line.startsWith("SRCFAIL|"));
|
|
643
|
+
if (failureLine === undefined)
|
|
644
|
+
return { destination: destinationRow };
|
|
645
|
+
const [, reason, encoded] = failureLine.split("|");
|
|
646
|
+
return {
|
|
647
|
+
destination: destinationRow,
|
|
648
|
+
sourceFailure: { reason: reason ?? "io", message: Buffer.from(encoded ?? "", "base64").toString("utf8") },
|
|
649
|
+
};
|
|
650
|
+
}
|
|
442
651
|
/**
|
|
443
652
|
* Read and decode a file for editing: LF-normalized content plus the style
|
|
444
653
|
* to restore on write-back.
|
package/lib/fsio-text.d.ts
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
* run `pnpm run build` — the artifact under `lib/` is generated, and `pnpm test`
|
|
17
17
|
* fails when it drifts.
|
|
18
18
|
*
|
|
19
|
-
* @module dsh-plugin-wsl/fsio-text
|
|
19
|
+
* @module dsh-plugin-wsl-env/fsio-text
|
|
20
20
|
*/
|
|
21
21
|
/** The byte prefix scanned for a NUL before a read is declared binary. */
|
|
22
22
|
export declare const BINARY_SAMPLE_BYTES = 8192;
|
package/lib/fsio-text.js
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
* run `pnpm run build` — the artifact under `lib/` is generated, and `pnpm test`
|
|
17
17
|
* fails when it drifts.
|
|
18
18
|
*
|
|
19
|
-
* @module dsh-plugin-wsl/fsio-text
|
|
19
|
+
* @module dsh-plugin-wsl-env/fsio-text
|
|
20
20
|
*/
|
|
21
21
|
/** The byte prefix scanned for a NUL before a read is declared binary. */
|
|
22
22
|
export const BINARY_SAMPLE_BYTES = 8192;
|
package/lib/git-exec.d.ts
CHANGED
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
* run `pnpm run build` — the artifact under `lib/` is generated, and
|
|
35
35
|
* `pnpm test` fails when it drifts.
|
|
36
36
|
*
|
|
37
|
-
* @module dsh-plugin-wsl/git-exec
|
|
37
|
+
* @module dsh-plugin-wsl-env/git-exec
|
|
38
38
|
*/
|
|
39
39
|
import type { AgentExecRunner } from "./agent-exec.js";
|
|
40
40
|
/** One collected-stream reader with the seam's standard shape. */
|
package/lib/git-exec.js
CHANGED
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
* run `pnpm run build` — the artifact under `lib/` is generated, and
|
|
35
35
|
* `pnpm test` fails when it drifts.
|
|
36
36
|
*
|
|
37
|
-
* @module dsh-plugin-wsl/git-exec
|
|
37
|
+
* @module dsh-plugin-wsl-env/git-exec
|
|
38
38
|
*/
|
|
39
39
|
import { AgentUnavailableError } from "./agent-errors.js";
|
|
40
40
|
import { translateDiscoveryOutput } from "./git-route.js";
|
package/lib/git-route.d.ts
CHANGED
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
* run `pnpm run build` — the artifact under `lib/` is generated, and `pnpm test`
|
|
52
52
|
* fails when it drifts.
|
|
53
53
|
*
|
|
54
|
-
* @module dsh-plugin-wsl/git-route
|
|
54
|
+
* @module dsh-plugin-wsl-env/git-route
|
|
55
55
|
*/
|
|
56
56
|
/**
|
|
57
57
|
* The program path `resolveExecutable` returns for git when the HOST has no
|
package/lib/git-route.js
CHANGED
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
* run `pnpm run build` — the artifact under `lib/` is generated, and `pnpm test`
|
|
52
52
|
* fails when it drifts.
|
|
53
53
|
*
|
|
54
|
-
* @module dsh-plugin-wsl/git-route
|
|
54
|
+
* @module dsh-plugin-wsl-env/git-route
|
|
55
55
|
*/
|
|
56
56
|
import { isWslUnc, uncToPosix, windowsToLinuxMount } from "./paths.js";
|
|
57
57
|
/** The one program this rewrite passes through to the distro. */
|
package/lib/index.d.ts
CHANGED
|
@@ -44,15 +44,24 @@ import { LocalBashExecutor } from "@deepseek-ai/dsh-bash-local";
|
|
|
44
44
|
import { LocalFileSystem } from "@deepseek-ai/dsh-fs-local";
|
|
45
45
|
import { FsError } from "@deepseek-ai/dsh-fs";
|
|
46
46
|
import { WslSandbox } from "./sandbox.js";
|
|
47
|
-
import type { WslAgent } from "./agent.js";
|
|
47
|
+
import type { WslAgent, AgentStatus } from "./agent.js";
|
|
48
48
|
import { AgentSubstrate } from "./fs-substrate.js";
|
|
49
49
|
import { SessionRuntimes } from "./session-runtime.js";
|
|
50
|
+
import { type DoctorReport } from "./doctor-live.js";
|
|
50
51
|
import type { AgentBackend } from "./native-agent.js";
|
|
51
52
|
import type { SessionRuntimeEntry } from "./session-runtime.js";
|
|
52
53
|
import type { Context } from "@deepseek-ai/cordis";
|
|
53
|
-
import type { FsDirEntry, FsEditOutcome, FsEditRequest, FsInfo, FsPathInfo, FsTarget, FsVersion, FsWriteIntent, FsWriteOutcome } from "@deepseek-ai/dsh-fs";
|
|
54
|
+
import type { FsDeleteOutcome, FsDirEntry, FsEditOutcome, FsEditRequest, FsInfo, FsMoveOutcome, FsPathInfo, FsTarget, FsVersion, FsWriteIntent, FsWriteOutcome, FileSystem } from "@deepseek-ai/dsh-fs";
|
|
54
55
|
import type { SandboxExecutionPolicy, SandboxMode } from "@deepseek-ai/dsh-sandbox";
|
|
55
56
|
import type { SubprocessSpawnSpec } from "@deepseek-ai/dsh-subprocess";
|
|
57
|
+
/**
|
|
58
|
+
* The 0.2.2-rc.1 patch/move operations' parameter shapes, derived from the
|
|
59
|
+
* peer's abstract surface: `PatchHunk` lives in `@deepseek-ai/dsh-fs-patch`,
|
|
60
|
+
* which this package does not depend on, so the types ride in through the
|
|
61
|
+
* `FileSystem` declaration instead.
|
|
62
|
+
*/
|
|
63
|
+
type PatchHunks = Parameters<FileSystem["patchText"]>[1];
|
|
64
|
+
type MoveFileOptions = Parameters<FileSystem["moveFile"]>[2];
|
|
56
65
|
/**
|
|
57
66
|
* Upstream shell vocabulary, derived through `@deepseek-ai/dsh-bash-local` —
|
|
58
67
|
* this package does not depend on `@deepseek-ai/dsh-shell` directly, so the
|
|
@@ -76,6 +85,38 @@ export type ConfinedProfile = Awaited<ReturnType<InstanceType<typeof WslSandbox>
|
|
|
76
85
|
export type WslExecSpec = ShellExecSpec & {
|
|
77
86
|
relativeWorkdir?: string;
|
|
78
87
|
};
|
|
88
|
+
/**
|
|
89
|
+
* Collect the doctor's versioned JSON report and merge the live resident's
|
|
90
|
+
* own lifecycle facts when this process holds one (WSL-313).
|
|
91
|
+
*
|
|
92
|
+
* The doctor CLI is a separate process, so its handshake check can only probe
|
|
93
|
+
* a fresh resident; a live resident's `deaths` and `lastError` are
|
|
94
|
+
* host-process state with no IPC to reach them. This entry point runs from
|
|
95
|
+
* the plugin's own context instead: it collects the report as a subprocess
|
|
96
|
+
* (no plugin code is re-entered) and folds `sharedAgent(distro).status()` in
|
|
97
|
+
* — the sanctioned merge, since a snapshot that answers for no resident
|
|
98
|
+
* changes nothing. Outside the app the singleton was never started, so the
|
|
99
|
+
* returned report is the fresh probe verbatim; inside it, a wedged live
|
|
100
|
+
* resident's failures finally reach the report.
|
|
101
|
+
*
|
|
102
|
+
* @param distro - the distro the doctor examines.
|
|
103
|
+
* @param options - `doctorPath` overrides the shipped script (tests);
|
|
104
|
+
* `liveStatus` overrides the in-process status snapshot (tests).
|
|
105
|
+
* @returns the merged report.
|
|
106
|
+
*/
|
|
107
|
+
export declare function doctorReport(distro: string, options?: {
|
|
108
|
+
doctorPath?: string;
|
|
109
|
+
/** The `wsl.exe` the doctor probes with; forwarded as `--wsl <path>`. */
|
|
110
|
+
wslPath?: string;
|
|
111
|
+
/**
|
|
112
|
+
* Prepended to the doctor subprocess's PATH — a caller that stages a fake
|
|
113
|
+
* `wsl.exe` (tests) passes the staging directory here instead of mutating
|
|
114
|
+
* `process.env`, whose visibility across spawned grandchildren is exactly
|
|
115
|
+
* the ambiguity this option removes.
|
|
116
|
+
*/
|
|
117
|
+
envPath?: string;
|
|
118
|
+
liveStatus?: AgentStatus;
|
|
119
|
+
}): Promise<DoctorReport>;
|
|
79
120
|
/**
|
|
80
121
|
* The WSL shell executor's validated config — the keys of
|
|
81
122
|
* {@link WslShellExecutor.Config}, which the upstream `LocalBashExecutor`
|
|
@@ -459,7 +500,8 @@ export declare class WslShellExecutor extends LocalBashExecutor {
|
|
|
459
500
|
* The shell name for the default/pinned distro, as the shell tool presents
|
|
460
501
|
* it.
|
|
461
502
|
*
|
|
462
|
-
* @returns the basename of the shell
|
|
503
|
+
* @returns the basename of the shell; `shell` while the probe fails, and
|
|
504
|
+
* `bash` for an implausible basename.
|
|
463
505
|
*/
|
|
464
506
|
shellName(): Promise<string>;
|
|
465
507
|
/**
|
|
@@ -469,6 +511,8 @@ export declare class WslShellExecutor extends LocalBashExecutor {
|
|
|
469
511
|
*
|
|
470
512
|
* @param distro - the distro name.
|
|
471
513
|
* @returns an absolute path to the shell inside the distro.
|
|
514
|
+
* @throws {Error} when neither the config nor the distro names a usable
|
|
515
|
+
* shell — the failure is not cached, so the next call re-probes.
|
|
472
516
|
*/
|
|
473
517
|
shellFor(distro: string): Promise<string>;
|
|
474
518
|
/**
|
|
@@ -476,6 +520,8 @@ export declare class WslShellExecutor extends LocalBashExecutor {
|
|
|
476
520
|
* login shell, resolved once and cached.
|
|
477
521
|
*
|
|
478
522
|
* @returns an absolute path to the shell inside the distro.
|
|
523
|
+
* @throws {Error} when neither the config nor the distro names a usable
|
|
524
|
+
* shell — the failure is not cached, so the next call re-probes.
|
|
479
525
|
*/
|
|
480
526
|
shell(): Promise<string>;
|
|
481
527
|
/**
|
|
@@ -727,6 +773,41 @@ export declare class WslShellExecutor extends LocalBashExecutor {
|
|
|
727
773
|
* @returns the decorated execution result.
|
|
728
774
|
*/
|
|
729
775
|
executeOneShot(resolved: WslExecSpec, distro: string, shell: string): Promise<ShellExecution>;
|
|
776
|
+
/**
|
|
777
|
+
* The confined one-shot's argv prepare: confine the distro argv under the
|
|
778
|
+
* policy, keep the resulting profile for the fact-stamper and the settlement
|
|
779
|
+
* mapping, and hand back the wrapped host argv.
|
|
780
|
+
*
|
|
781
|
+
* @param resolved - the resolved spec.
|
|
782
|
+
* @param distro - the resolved distro name.
|
|
783
|
+
* @param shell - the resolved distro shell.
|
|
784
|
+
* @param policy - the confined policy (narrowed in by `executeOneShot`).
|
|
785
|
+
* @param slot - the closure the builder assigns the profile into.
|
|
786
|
+
* @param signal - the caller's cancellation.
|
|
787
|
+
*/
|
|
788
|
+
private prepareConfinedArgv;
|
|
789
|
+
/**
|
|
790
|
+
* Stamp the per-process sandbox facts before `done` settles, so a background
|
|
791
|
+
* process reports the same mode, denial and enforcement a foreground run
|
|
792
|
+
* would.
|
|
793
|
+
*
|
|
794
|
+
* @param resolved - the resolved spec.
|
|
795
|
+
* @param mode - the confined policy's mode.
|
|
796
|
+
* @param slot - the closure holding the assigned profile.
|
|
797
|
+
* @param process - the spawned handle.
|
|
798
|
+
*/
|
|
799
|
+
private stampConfinedFacts;
|
|
800
|
+
/**
|
|
801
|
+
* Settle one confined one-shot result: the distro and workdir verdicts, the
|
|
802
|
+
* never-armed honesty stamp, the runner-failure throw, and the denial facts.
|
|
803
|
+
*
|
|
804
|
+
* @param result - the settled process result.
|
|
805
|
+
* @param distro - the resolved distro name.
|
|
806
|
+
* @param resolved - the resolved spec.
|
|
807
|
+
* @param mode - the confined policy's mode.
|
|
808
|
+
* @param confined - the profile the argv prepare armed, when it ran.
|
|
809
|
+
*/
|
|
810
|
+
private settleConfinedOneShot;
|
|
730
811
|
}
|
|
731
812
|
/**
|
|
732
813
|
* Filesystem backend over a WSL distro's UNC share.
|
|
@@ -1326,5 +1407,48 @@ export declare class WslFileSystem extends LocalFileSystem {
|
|
|
1326
1407
|
editText(target: FsTarget, edit: FsEditRequest, expected?: {
|
|
1327
1408
|
version: FsVersion;
|
|
1328
1409
|
}, signal?: AbortSignal, sandboxPolicy?: SandboxExecutionPolicy): Promise<FsEditOutcome>;
|
|
1410
|
+
/**
|
|
1411
|
+
* Apply parsed hunks (protocol 7): hunk matching and application run
|
|
1412
|
+
* in-process through the peer's own `applyHunks` (the same dialect and
|
|
1413
|
+
* `FS_PATCH_MISMATCH` the peer emits), against the distro's bytes, then
|
|
1414
|
+
* publish through the same guarded atomic write an edit takes.
|
|
1415
|
+
*
|
|
1416
|
+
* @param target - the resolved regular file.
|
|
1417
|
+
* @param hunks - ordered hunks from the caller's patch parse.
|
|
1418
|
+
* @param expected - the version the patch was based on.
|
|
1419
|
+
* @param signal - cancels the patch.
|
|
1420
|
+
* @param sandboxPolicy - the per-call policy; omit for the deployment default.
|
|
1421
|
+
* @returns the pre/post text and the published version.
|
|
1422
|
+
*/
|
|
1423
|
+
patchText(target: FsTarget, hunks: PatchHunks, expected?: {
|
|
1424
|
+
version: FsVersion;
|
|
1425
|
+
}, signal?: AbortSignal, sandboxPolicy?: SandboxExecutionPolicy): Promise<FsEditOutcome>;
|
|
1426
|
+
/**
|
|
1427
|
+
* Remove one regular file (protocol 7) after fencing the target by the
|
|
1428
|
+
* per-call policy; the guarded removal re-verifies the expected version
|
|
1429
|
+
* distro-side.
|
|
1430
|
+
*
|
|
1431
|
+
* @param target - the resolved file.
|
|
1432
|
+
* @param expected - the version the removal was based on.
|
|
1433
|
+
* @param signal - cancels the removal.
|
|
1434
|
+
* @param sandboxPolicy - the per-call policy; omit for the deployment default.
|
|
1435
|
+
* @returns the bounded pre-removal text basis.
|
|
1436
|
+
*/
|
|
1437
|
+
deleteFile(target: FsTarget, expected?: {
|
|
1438
|
+
version: FsVersion;
|
|
1439
|
+
}, signal?: AbortSignal, sandboxPolicy?: SandboxExecutionPolicy): Promise<FsDeleteOutcome>;
|
|
1440
|
+
/**
|
|
1441
|
+
* Move one regular file (protocol 7) after fencing BOTH endpoints by the
|
|
1442
|
+
* per-call policy — the destination publishes and the source is removed, so
|
|
1443
|
+
* each must be writable under the same roots.
|
|
1444
|
+
*
|
|
1445
|
+
* @param source - the resolved source.
|
|
1446
|
+
* @param destination - the resolved destination.
|
|
1447
|
+
* @param options - the hunks and the source/destination guards.
|
|
1448
|
+
* @param signal - cancels before publication.
|
|
1449
|
+
* @param sandboxPolicy - the per-call policy; omit for the deployment default.
|
|
1450
|
+
* @returns the bounded source basis and the destination outcome.
|
|
1451
|
+
*/
|
|
1452
|
+
moveFile(source: FsTarget, destination: FsTarget, options: MoveFileOptions, signal?: AbortSignal, sandboxPolicy?: SandboxExecutionPolicy): Promise<FsMoveOutcome>;
|
|
1329
1453
|
}
|
|
1330
1454
|
export {};
|