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.
- package/CHANGELOG.md +152 -0
- package/CONTRIBUTING.md +37 -5
- package/README.md +59 -4
- 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/docs/AGENT-PROTOCOL-V7.md +175 -0
- package/docs/API.md +24 -0
- package/docs/ARCHITECTURE.md +14 -1
- package/docs/CONFIGURATION.md +12 -5
- package/docs/CONFIGURATION.zh.md +5 -3
- package/docs/LIMITATIONS.md +16 -4
- package/docs/LIMITATIONS.zh.md +20 -11
- package/docs/MIGRATION.md +4 -4
- package/docs/PEER-PARITY.md +50 -33
- package/docs/QUICKSTART.md +18 -1
- package/docs/QUICKSTART.zh.md +16 -1
- package/docs/README.zh.md +43 -4
- package/docs/RELEASING.md +1 -1
- package/docs/REQUIREMENTS.zh.md +3 -2
- package/docs/ROADMAP-1.0.md +27 -16
- package/docs/UPSTREAM-FILE-REFERENCE-SEAM.md +3 -1
- 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 +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 +266 -122
- 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 +15 -4
- package/scripts/doctor.mjs +34 -11
package/lib/fsio-agent.d.ts
CHANGED
|
@@ -19,11 +19,10 @@
|
|
|
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 { normalizeLineEndings, restoreLineEndings, applyLiteralEdit } from "./fsio-text.js";
|
|
25
25
|
import type { WslAgent } from "./agent.js";
|
|
26
|
-
import type { ResolvedTarget } from "./fs-substrate.js";
|
|
27
26
|
/** One agent FS round trip's result — the shape `WslAgent#fs` resolves to. */
|
|
28
27
|
export interface AgentFsResult {
|
|
29
28
|
/** The op's exit status. */
|
|
@@ -32,6 +31,12 @@ export interface AgentFsResult {
|
|
|
32
31
|
stdout: Buffer;
|
|
33
32
|
/** The op's diagnostic line(s). */
|
|
34
33
|
stderr: Buffer;
|
|
34
|
+
/**
|
|
35
|
+
* Protocol 7's FS refusal token, when the op failed through the structured
|
|
36
|
+
* FSERR line; the adapter maps it onto `FsErrorCode` directly. Undefined
|
|
37
|
+
* for legacy (v6) agents, whose refusal rides the stderr convention.
|
|
38
|
+
*/
|
|
39
|
+
reason?: string;
|
|
35
40
|
}
|
|
36
41
|
/**
|
|
37
42
|
* Normalize one agent timestamp ("seconds.frac", 9 or 10 fractional digits
|
|
@@ -44,8 +49,11 @@ export interface AgentFsResult {
|
|
|
44
49
|
export declare function nanoseconds(value: string): string;
|
|
45
50
|
/**
|
|
46
51
|
* The peer's `versionOf`: dev, inode, size and both nanosecond timestamps.
|
|
47
|
-
* Self-consistency within this provider is what versions need
|
|
48
|
-
*
|
|
52
|
+
* Self-consistency within this provider is what versions need. The string's
|
|
53
|
+
* granularity is the file's stat identity, not its bytes: a write that moves
|
|
54
|
+
* size or either timestamp moves the string, while a same-size write that
|
|
55
|
+
* leaves both timestamps untouched does not — the peer's own `versionOf`
|
|
56
|
+
* has exactly the same granularity, so guard comparisons behave alike.
|
|
49
57
|
*
|
|
50
58
|
* @param ingredients - the stat record's identity fields.
|
|
51
59
|
* @returns the opaque version string.
|
|
@@ -72,6 +80,25 @@ export declare function parseStatRecord(stdout: Buffer): {
|
|
|
72
80
|
ino: string;
|
|
73
81
|
version: string;
|
|
74
82
|
};
|
|
83
|
+
/**
|
|
84
|
+
* One resolved filesystem target: the display spelling the model sees and the
|
|
85
|
+
* UNC identity the operations key on. Lives here because the substrate's
|
|
86
|
+
* operations consume it and the substrate layer builds on this one.
|
|
87
|
+
*/
|
|
88
|
+
export interface ResolvedTarget {
|
|
89
|
+
/** The canonical Linux path spelling. */
|
|
90
|
+
displayPath: string;
|
|
91
|
+
/** The UNC identity this target keys on. */
|
|
92
|
+
targetKey: string;
|
|
93
|
+
}
|
|
94
|
+
export declare const REASON_CODES: Record<string, string>;
|
|
95
|
+
/**
|
|
96
|
+
* Map one wire reason token onto the peer's `FsErrorCode` vocabulary.
|
|
97
|
+
*
|
|
98
|
+
* @param reason - the agent's reason token (`notfound`, `stale`, …).
|
|
99
|
+
* @returns the corresponding code; unknown tokens read as I/O failures.
|
|
100
|
+
*/
|
|
101
|
+
export declare function reasonToCode(reason: string): string;
|
|
75
102
|
/** One `find` listing row, as `listChildren` shapes it. */
|
|
76
103
|
export interface ChildRow {
|
|
77
104
|
name: string;
|
|
@@ -209,6 +236,25 @@ export declare class DistroFs {
|
|
|
209
236
|
* @returns the full decoded text, byte-for-byte.
|
|
210
237
|
*/
|
|
211
238
|
readWholeText(target: ResolvedTarget, signal?: AbortSignal): Promise<string>;
|
|
239
|
+
/**
|
|
240
|
+
* The single-frame fallback for {@link readWholeText}: one stat, then the
|
|
241
|
+
* windowed read loop (a v6 peer).
|
|
242
|
+
*
|
|
243
|
+
* @param target - the resolved file.
|
|
244
|
+
* @param signal - aborts the read.
|
|
245
|
+
* @returns the file's bytes.
|
|
246
|
+
*/
|
|
247
|
+
private statThenReadWhole;
|
|
248
|
+
/**
|
|
249
|
+
* The protocol-7 batch path for {@link readWholeText}: the stat and the
|
|
250
|
+
* first read window ride ONE FSB frame — the GUI preview's dominant
|
|
251
|
+
* shape — and further windows stay single reads.
|
|
252
|
+
*
|
|
253
|
+
* @param target - the resolved file.
|
|
254
|
+
* @param signal - aborts the read.
|
|
255
|
+
* @returns the file's bytes.
|
|
256
|
+
*/
|
|
257
|
+
private readWholeBatched;
|
|
212
258
|
/**
|
|
213
259
|
* Read a whole regular file as raw bytes, bounded by `maxBytes`.
|
|
214
260
|
*
|
|
@@ -278,6 +324,84 @@ export declare class DistroFs {
|
|
|
278
324
|
*/
|
|
279
325
|
agent?: WslAgent;
|
|
280
326
|
}): Promise<void>;
|
|
327
|
+
/**
|
|
328
|
+
* Whether the resident accepts protocol-7 batch frames.
|
|
329
|
+
*
|
|
330
|
+
* @param agent - the agent to ask; the default resident by default.
|
|
331
|
+
* @returns true when the negotiated version and capabilities allow FSB.
|
|
332
|
+
*/
|
|
333
|
+
supportsBatch(agent?: WslAgent): boolean;
|
|
334
|
+
/**
|
|
335
|
+
* Whether the resident serves the protocol-7 destructive ops
|
|
336
|
+
* (`delete`, `move`) and the structured FSERR channel.
|
|
337
|
+
*
|
|
338
|
+
* @param agent - the agent to ask; the default resident by default.
|
|
339
|
+
* @returns true for a protocol-7 resident.
|
|
340
|
+
*/
|
|
341
|
+
supportsDestructive(agent?: WslAgent): boolean;
|
|
342
|
+
/**
|
|
343
|
+
* Run one batched FS frame and parse its per-op records.
|
|
344
|
+
*
|
|
345
|
+
* @param ops - the ordered ops (`stat`, `list`, `read`, …).
|
|
346
|
+
* @param signal - cancels the batch.
|
|
347
|
+
* @param agent - the agent to run it on.
|
|
348
|
+
* @returns one record per op, in order.
|
|
349
|
+
*/
|
|
350
|
+
batch(ops: Array<{
|
|
351
|
+
op: string;
|
|
352
|
+
args: string[];
|
|
353
|
+
}>, signal: AbortSignal | undefined, agent?: WslAgent): Promise<Array<{
|
|
354
|
+
ok: true;
|
|
355
|
+
payload: Buffer;
|
|
356
|
+
} | {
|
|
357
|
+
ok: false;
|
|
358
|
+
reason: string;
|
|
359
|
+
message: string;
|
|
360
|
+
}>>;
|
|
361
|
+
/**
|
|
362
|
+
* Remove one regular file through the protocol-7 `delete` op, whose guards
|
|
363
|
+
* mirror the peer's `requireFile`: a vanished file is stale, a non-regular
|
|
364
|
+
* target its own refusal, an expected version re-verified distro-side.
|
|
365
|
+
*
|
|
366
|
+
* @param linuxPath - the resolved Linux path.
|
|
367
|
+
* @param expectedVersion - the version the removal was based on.
|
|
368
|
+
* @param signal - cancels the removal.
|
|
369
|
+
* @param agent - the agent that must run it.
|
|
370
|
+
* @returns resolves when the file is gone.
|
|
371
|
+
*/
|
|
372
|
+
removeFile(linuxPath: string, expectedVersion: string | undefined, signal: AbortSignal | undefined, agent?: WslAgent): Promise<void>;
|
|
373
|
+
/**
|
|
374
|
+
* Move one regular file through the protocol-7 `move` op: the destination
|
|
375
|
+
* publishes through the write machinery's staging (atomic rename, or the
|
|
376
|
+
* no-replace link for a guarded create), then the source is removed. A
|
|
377
|
+
* destination that published while the source survived comes back as
|
|
378
|
+
* `sourceFailure` — the peer's two-effect outcome.
|
|
379
|
+
*
|
|
380
|
+
* @param source - the resolved source path.
|
|
381
|
+
* @param destination - the resolved destination path.
|
|
382
|
+
* @param options - the destination mode, publish guard and version guards.
|
|
383
|
+
* @param signal - cancels the move.
|
|
384
|
+
* @param agent - the agent that must run it.
|
|
385
|
+
* @returns the destination's fresh stat row and the source-removal outcome.
|
|
386
|
+
*/
|
|
387
|
+
moveAtomic(source: string, destination: string, options: {
|
|
388
|
+
/** The mode to publish at the destination (the source's, in practice). */
|
|
389
|
+
mode: number | undefined;
|
|
390
|
+
/** `no-replace` for a guarded create, otherwise `replace`. */
|
|
391
|
+
guard: "replace" | "no-replace";
|
|
392
|
+
/** The source version the move was based on. */
|
|
393
|
+
sourceVersion?: string;
|
|
394
|
+
/** The destination version the move was based on. */
|
|
395
|
+
destinationVersion?: string;
|
|
396
|
+
signal?: AbortSignal;
|
|
397
|
+
agent?: WslAgent;
|
|
398
|
+
}): Promise<{
|
|
399
|
+
destination: StatRow;
|
|
400
|
+
sourceFailure?: {
|
|
401
|
+
reason: string;
|
|
402
|
+
message: string;
|
|
403
|
+
};
|
|
404
|
+
}>;
|
|
281
405
|
/**
|
|
282
406
|
* Read and decode a file for editing: LF-normalized content plus the style
|
|
283
407
|
* to restore on write-back.
|
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. */
|