dsh-plugin-wsl-env 0.26.3-rc.0 → 0.26.4
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 +89 -0
- package/CONTRIBUTING.md +25 -21
- package/SUPPORT.md +2 -2
- package/SUPPORT.zh.md +2 -2
- package/docs/AGENT-PROTOCOL-V7.md +4 -2
- package/docs/API.md +1 -0
- package/docs/API.zh.md +1 -0
- package/docs/CONFIGURATION.md +21 -5
- package/docs/CONFIGURATION.zh.md +17 -3
- package/docs/MIGRATION.md +1 -1
- package/docs/MIGRATION.zh.md +1 -1
- package/docs/PARITY.md +3 -1
- package/docs/RELEASING.md +25 -3
- package/docs/REQUIREMENTS.zh.md +4 -4
- package/docs/ROADMAP-1.0.md +11 -7
- package/lib/agent.d.ts +54 -18
- package/lib/agent.js +86 -19
- package/lib/fs-routing.d.ts +3 -0
- package/lib/fs-routing.js +5 -0
- package/lib/fs-substrate.d.ts +1 -1
- package/lib/fs-substrate.js +10 -18
- package/lib/fsio-agent.d.ts +4 -0
- package/lib/fsio-agent.js +37 -10
- package/lib/listing.d.ts +2 -2
- package/lib/listing.js +5 -4
- package/lib/messages.d.ts +70 -0
- package/lib/messages.js +80 -0
- package/lib/open-in-app.js +12 -9
- package/lib/picker.d.ts +4 -1
- package/lib/picker.js +35 -11
- package/lib/ports.js +8 -1
- package/lib/provider-common.d.ts +22 -0
- package/lib/provider-common.js +18 -0
- package/lib/provider-marker.d.ts +23 -0
- package/lib/provider-marker.js +21 -0
- package/lib/status.js +8 -5
- package/lib/subprocess.d.ts +3 -0
- package/lib/subprocess.js +5 -0
- package/lib/takeover-report.js +4 -11
- package/lib/watcher.d.ts +1 -1
- package/lib/watcher.js +1 -1
- package/lib/wsl-doctor-command.d.ts +6 -2
- package/lib/wsl-doctor-command.js +24 -15
- package/lib/wsl-filesystem.d.ts +14 -11
- package/lib/wsl-filesystem.js +39 -27
- package/lib/wsl-shell.d.ts +42 -37
- package/lib/wsl-shell.js +53 -42
- package/package.json +1 -1
package/lib/agent.d.ts
CHANGED
|
@@ -23,9 +23,12 @@
|
|
|
23
23
|
* behind a dead `wsl.exe`. The host-side watchdog is armed on the agent's
|
|
24
24
|
* `ACK` — the dequeue signal — so it measures EXECUTION, never the queue
|
|
25
25
|
* wait: a short-budget request queued behind a long one can no longer
|
|
26
|
-
* kill the shared transport for a stall that was never its own.
|
|
27
|
-
*
|
|
28
|
-
*
|
|
26
|
+
* kill the shared transport for a stall that was never its own. A second,
|
|
27
|
+
* much looser ceiling starts when the frame is WRITTEN: a resident that
|
|
28
|
+
* stays alive but never dequeues the request (a wedged `wait`, a blocked
|
|
29
|
+
* pipe) otherwise stranded it, and the serial queue behind it, forever. It
|
|
30
|
+
* still catches an agent that accepted a request and then stopped answering
|
|
31
|
+
* at all.
|
|
29
32
|
* 3. **Idle agents go away.** `idleMs` after the last exchange the process is
|
|
30
33
|
* killed; the next call starts a fresh one. WSL VMs are shared, but every
|
|
31
34
|
* process is a promise someone has to keep.
|
|
@@ -103,6 +106,11 @@ interface PendingRequest {
|
|
|
103
106
|
answered: boolean;
|
|
104
107
|
/** The delayed cancel signal, so it can be dropped when the request settles. */
|
|
105
108
|
signalTimer: NodeJS.Timeout | null;
|
|
109
|
+
/**
|
|
110
|
+
* The frame-written watchdog timer: a resident that never ACKs is wedged,
|
|
111
|
+
* and the ACK-armed watchdog alone would never start.
|
|
112
|
+
*/
|
|
113
|
+
dispatchWatchdog: NodeJS.Timeout | null;
|
|
106
114
|
}
|
|
107
115
|
/** Per-kind request metrics. */
|
|
108
116
|
interface RequestMetrics {
|
|
@@ -250,6 +258,8 @@ export declare class WslAgent {
|
|
|
250
258
|
serialRequests: boolean;
|
|
251
259
|
/** The maximum requests allowed in flight on this resident. */
|
|
252
260
|
maxPending: number;
|
|
261
|
+
/** How long a written frame may await the agent's ACK. */
|
|
262
|
+
dispatchTimeoutMs: number;
|
|
253
263
|
/** The live resident process, when any. */
|
|
254
264
|
process: ChildProcess | null;
|
|
255
265
|
/** The lifecycle state. */
|
|
@@ -331,6 +341,11 @@ export declare class WslAgent {
|
|
|
331
341
|
serialRequests?: boolean;
|
|
332
342
|
/** Hard ceiling in bytes on one stdout protocol line; defaults to {@link MAX_FRAME_BYTES}. */
|
|
333
343
|
frameCapBytes?: number;
|
|
344
|
+
/**
|
|
345
|
+
* How long a written frame may await the agent's ACK before the transport
|
|
346
|
+
* is killed. Defaults to {@link DISPATCH_TIMEOUT_MS}; tests shorten it.
|
|
347
|
+
*/
|
|
348
|
+
dispatchTimeoutMs?: number;
|
|
334
349
|
/** Injectable process factory for tests. */
|
|
335
350
|
spawnTransport?: (options: {
|
|
336
351
|
wslPath: string;
|
|
@@ -564,8 +579,29 @@ export declare class WslAgent {
|
|
|
564
579
|
* @param signal - the caller's cancellation.
|
|
565
580
|
*/
|
|
566
581
|
private attachCancellation;
|
|
567
|
-
/**
|
|
582
|
+
/**
|
|
583
|
+
* Send a tracked request, recording dispatch before synchronous responses.
|
|
584
|
+
* A written frame starts the dispatch watchdog: the ACK that arms the
|
|
585
|
+
* execution budget is not guaranteed to arrive at all.
|
|
586
|
+
*
|
|
587
|
+
* @param pending - the request to send.
|
|
588
|
+
* @returns whether the frame was written.
|
|
589
|
+
*/
|
|
568
590
|
private sendPending;
|
|
591
|
+
/**
|
|
592
|
+
* Arm the frame-written watchdog: a resident that stays alive without
|
|
593
|
+
* dequeuing the request is a wedged transport, not a slow command.
|
|
594
|
+
*
|
|
595
|
+
* @param pending - the sent request.
|
|
596
|
+
*/
|
|
597
|
+
private armDispatchWatchdog;
|
|
598
|
+
/**
|
|
599
|
+
* Release the frame-written watchdog once the ACK proves the resident
|
|
600
|
+
* dequeued the request.
|
|
601
|
+
*
|
|
602
|
+
* @param pending - the acknowledged request.
|
|
603
|
+
*/
|
|
604
|
+
private releaseDispatchWatchdog;
|
|
569
605
|
/** Dispatch the next shell request only after the preceding answer. */
|
|
570
606
|
private dispatchQueued;
|
|
571
607
|
/**
|
|
@@ -680,20 +716,6 @@ export declare class WslAgent {
|
|
|
680
716
|
* @returns resolved on PONG.
|
|
681
717
|
*/
|
|
682
718
|
ping(signal?: AbortSignal): Promise<void>;
|
|
683
|
-
/**
|
|
684
|
-
* Deliver an out-of-band signal to the resident shell. The serial stdin loop
|
|
685
|
-
* cannot consume a frame while a command runs, so cancellation is a signal;
|
|
686
|
-
* a second `wsl.exe` is the only channel that reaches the agent while it is
|
|
687
|
-
* blocked in `wait`.
|
|
688
|
-
*
|
|
689
|
-
* Only an agent that shares the distro's PID namespace is addressable: the
|
|
690
|
-
* plain agent, or a session runtime (its prefix is a scope plus mounts, but
|
|
691
|
-
* no PID namespace). A confined resident runs inside a PID namespace whose
|
|
692
|
-
* PIDs do not exist in the distro, so signalling its HELLO PID could hit an
|
|
693
|
-
* unrelated process; there the KILL frame remains the (delayed) fallback.
|
|
694
|
-
*
|
|
695
|
-
* @param signal - the signal to deliver (`SIGUSR1` is the cancel trap).
|
|
696
|
-
*/
|
|
697
719
|
/**
|
|
698
720
|
* The cumulative request metrics: queue wait (submission -> ACK) and execution
|
|
699
721
|
* time (ACK -> settle) per request kind, plus the peak in-flight count.
|
|
@@ -726,6 +748,20 @@ export declare class WslAgent {
|
|
|
726
748
|
* @param error - the failure, when any.
|
|
727
749
|
*/
|
|
728
750
|
private recordSettle;
|
|
751
|
+
/**
|
|
752
|
+
* Deliver an out-of-band signal to the resident shell. The serial stdin loop
|
|
753
|
+
* cannot consume a frame while a command runs, so cancellation is a signal;
|
|
754
|
+
* a second `wsl.exe` is the only channel that reaches the agent while it is
|
|
755
|
+
* blocked in `wait`.
|
|
756
|
+
*
|
|
757
|
+
* Only an agent that shares the distro's PID namespace is addressable: the
|
|
758
|
+
* plain agent, or a session runtime (its prefix is a scope plus mounts, but
|
|
759
|
+
* no PID namespace). A confined resident runs inside a PID namespace whose
|
|
760
|
+
* PIDs do not exist in the distro, so signalling its HELLO PID could hit an
|
|
761
|
+
* unrelated process; there the KILL frame remains the (delayed) fallback.
|
|
762
|
+
*
|
|
763
|
+
* @param signal - the signal to deliver (`SIGUSR1` is the cancel trap).
|
|
764
|
+
*/
|
|
729
765
|
private signalAgent;
|
|
730
766
|
/**
|
|
731
767
|
* Shut the agent down: SHUTDOWN first, then kill after a short grace. The
|
package/lib/agent.js
CHANGED
|
@@ -23,9 +23,12 @@
|
|
|
23
23
|
* behind a dead `wsl.exe`. The host-side watchdog is armed on the agent's
|
|
24
24
|
* `ACK` — the dequeue signal — so it measures EXECUTION, never the queue
|
|
25
25
|
* wait: a short-budget request queued behind a long one can no longer
|
|
26
|
-
* kill the shared transport for a stall that was never its own.
|
|
27
|
-
*
|
|
28
|
-
*
|
|
26
|
+
* kill the shared transport for a stall that was never its own. A second,
|
|
27
|
+
* much looser ceiling starts when the frame is WRITTEN: a resident that
|
|
28
|
+
* stays alive but never dequeues the request (a wedged `wait`, a blocked
|
|
29
|
+
* pipe) otherwise stranded it, and the serial queue behind it, forever. It
|
|
30
|
+
* still catches an agent that accepted a request and then stopped answering
|
|
31
|
+
* at all.
|
|
29
32
|
* 3. **Idle agents go away.** `idleMs` after the last exchange the process is
|
|
30
33
|
* killed; the next call starts a fresh one. WSL VMs are shared, but every
|
|
31
34
|
* process is a promise someone has to keep.
|
|
@@ -60,6 +63,16 @@ function emptyAgentMetrics() {
|
|
|
60
63
|
const HANDSHAKE_TIMEOUT_MS = 15000;
|
|
61
64
|
/** Extra time the host watchdog waits past the request's own in-distro timeout. */
|
|
62
65
|
const WATCHDOG_GRACE_MS = 13000;
|
|
66
|
+
/**
|
|
67
|
+
* How long a written frame may wait for the agent's dequeue `ACK`. The ACK is
|
|
68
|
+
* one line the resident prints before it runs anything, so this is not an
|
|
69
|
+
* execution budget; it exists to turn a resident that is alive but no longer
|
|
70
|
+
* dequeuing (a wedged `wait`, a blocked stdin pipe) into a bounded failure
|
|
71
|
+
* instead of an entry that holds the serial queue forever. Generous on
|
|
72
|
+
* purpose: a legitimately busy foreground command is ACKed as soon as it is
|
|
73
|
+
* dequeued, and only the queue wait precedes that.
|
|
74
|
+
*/
|
|
75
|
+
const DISPATCH_TIMEOUT_MS = 120_000;
|
|
63
76
|
/**
|
|
64
77
|
* How many times a resident that reached `dead` may be revived before the
|
|
65
78
|
* failure becomes permanent. Each revival gets the one permitted rebuild.
|
|
@@ -180,6 +193,7 @@ export class WslAgent {
|
|
|
180
193
|
this.configuredSignal = config.signalTransport;
|
|
181
194
|
this.configuredLease = config.leaseMs;
|
|
182
195
|
this.maxPending = config.maxPending ?? MAX_PENDING_REQUESTS;
|
|
196
|
+
this.dispatchTimeoutMs = config.dispatchTimeoutMs ?? DISPATCH_TIMEOUT_MS;
|
|
183
197
|
this.agentPid = undefined;
|
|
184
198
|
this.process = null;
|
|
185
199
|
this.state = "idle";
|
|
@@ -530,6 +544,7 @@ export class WslAgent {
|
|
|
530
544
|
return;
|
|
531
545
|
pending.started = true;
|
|
532
546
|
this.lastAckedSeq = pending.seq;
|
|
547
|
+
this.releaseDispatchWatchdog(pending);
|
|
533
548
|
this.recordAck(pending);
|
|
534
549
|
if (pending.cancelled)
|
|
535
550
|
this.armCancelSignal(pending);
|
|
@@ -672,6 +687,9 @@ export class WslAgent {
|
|
|
672
687
|
clearTimeout(pending.watchdog);
|
|
673
688
|
pending.watchdog = null;
|
|
674
689
|
}
|
|
690
|
+
// The rebuilt agent gets a fresh ACK window too; a timer bound to the
|
|
691
|
+
// dead transport must not survive the relay.
|
|
692
|
+
this.releaseDispatchWatchdog(pending);
|
|
675
693
|
relayable.push(pending);
|
|
676
694
|
}
|
|
677
695
|
else {
|
|
@@ -822,6 +840,7 @@ export class WslAgent {
|
|
|
822
840
|
settled: false,
|
|
823
841
|
answered: false,
|
|
824
842
|
signalTimer: null,
|
|
843
|
+
dispatchWatchdog: null,
|
|
825
844
|
armWatchdog: timeoutMs > 0
|
|
826
845
|
? () => {
|
|
827
846
|
if (pending.watchdog)
|
|
@@ -888,10 +907,57 @@ export class WslAgent {
|
|
|
888
907
|
};
|
|
889
908
|
signal.addEventListener("abort", pending.onAbort, { once: true });
|
|
890
909
|
}
|
|
891
|
-
/**
|
|
910
|
+
/**
|
|
911
|
+
* Send a tracked request, recording dispatch before synchronous responses.
|
|
912
|
+
* A written frame starts the dispatch watchdog: the ACK that arms the
|
|
913
|
+
* execution budget is not guaranteed to arrive at all.
|
|
914
|
+
*
|
|
915
|
+
* @param pending - the request to send.
|
|
916
|
+
* @returns whether the frame was written.
|
|
917
|
+
*/
|
|
892
918
|
sendPending(pending) {
|
|
893
919
|
pending.sent = true;
|
|
894
|
-
|
|
920
|
+
if (!this.writeLines(pending.lines))
|
|
921
|
+
return false;
|
|
922
|
+
this.armDispatchWatchdog(pending);
|
|
923
|
+
return true;
|
|
924
|
+
}
|
|
925
|
+
/**
|
|
926
|
+
* Arm the frame-written watchdog: a resident that stays alive without
|
|
927
|
+
* dequeuing the request is a wedged transport, not a slow command.
|
|
928
|
+
*
|
|
929
|
+
* @param pending - the sent request.
|
|
930
|
+
*/
|
|
931
|
+
armDispatchWatchdog(pending) {
|
|
932
|
+
if (pending.dispatchWatchdog)
|
|
933
|
+
return;
|
|
934
|
+
const child = this.process;
|
|
935
|
+
if (!child)
|
|
936
|
+
return;
|
|
937
|
+
pending.dispatchWatchdog = setTimeout(() => {
|
|
938
|
+
// Bind the timer to the generation it was armed on, exactly as the
|
|
939
|
+
// ACK-armed watchdog does.
|
|
940
|
+
if (this.process !== child)
|
|
941
|
+
return;
|
|
942
|
+
this.lastError = `agent did not acknowledge request ${pending.id} within ${this.dispatchTimeoutMs}ms of its dispatch`;
|
|
943
|
+
child.kill();
|
|
944
|
+
}, this.dispatchTimeoutMs);
|
|
945
|
+
// The transport's child process (and its pipes) already keeps the loop
|
|
946
|
+
// alive while there is something to time out; an idle host that has let
|
|
947
|
+
// every other handle go must not be held open by this diagnostic timer.
|
|
948
|
+
pending.dispatchWatchdog.unref?.();
|
|
949
|
+
}
|
|
950
|
+
/**
|
|
951
|
+
* Release the frame-written watchdog once the ACK proves the resident
|
|
952
|
+
* dequeued the request.
|
|
953
|
+
*
|
|
954
|
+
* @param pending - the acknowledged request.
|
|
955
|
+
*/
|
|
956
|
+
releaseDispatchWatchdog(pending) {
|
|
957
|
+
if (!pending.dispatchWatchdog)
|
|
958
|
+
return;
|
|
959
|
+
clearTimeout(pending.dispatchWatchdog);
|
|
960
|
+
pending.dispatchWatchdog = null;
|
|
895
961
|
}
|
|
896
962
|
/** Dispatch the next shell request only after the preceding answer. */
|
|
897
963
|
dispatchQueued() {
|
|
@@ -989,20 +1055,6 @@ export class WslAgent {
|
|
|
989
1055
|
this.track({ id, kind: "exec", lines, resolve: () => resolve(), reject, timeoutMs: HANDSHAKE_TIMEOUT_MS, signal });
|
|
990
1056
|
});
|
|
991
1057
|
}
|
|
992
|
-
/**
|
|
993
|
-
* Deliver an out-of-band signal to the resident shell. The serial stdin loop
|
|
994
|
-
* cannot consume a frame while a command runs, so cancellation is a signal;
|
|
995
|
-
* a second `wsl.exe` is the only channel that reaches the agent while it is
|
|
996
|
-
* blocked in `wait`.
|
|
997
|
-
*
|
|
998
|
-
* Only an agent that shares the distro's PID namespace is addressable: the
|
|
999
|
-
* plain agent, or a session runtime (its prefix is a scope plus mounts, but
|
|
1000
|
-
* no PID namespace). A confined resident runs inside a PID namespace whose
|
|
1001
|
-
* PIDs do not exist in the distro, so signalling its HELLO PID could hit an
|
|
1002
|
-
* unrelated process; there the KILL frame remains the (delayed) fallback.
|
|
1003
|
-
*
|
|
1004
|
-
* @param signal - the signal to deliver (`SIGUSR1` is the cancel trap).
|
|
1005
|
-
*/
|
|
1006
1058
|
/**
|
|
1007
1059
|
* The cumulative request metrics: queue wait (submission -> ACK) and execution
|
|
1008
1060
|
* time (ACK -> settle) per request kind, plus the peak in-flight count.
|
|
@@ -1077,6 +1129,20 @@ export class WslAgent {
|
|
|
1077
1129
|
else if (error !== undefined)
|
|
1078
1130
|
stats.failed += 1;
|
|
1079
1131
|
}
|
|
1132
|
+
/**
|
|
1133
|
+
* Deliver an out-of-band signal to the resident shell. The serial stdin loop
|
|
1134
|
+
* cannot consume a frame while a command runs, so cancellation is a signal;
|
|
1135
|
+
* a second `wsl.exe` is the only channel that reaches the agent while it is
|
|
1136
|
+
* blocked in `wait`.
|
|
1137
|
+
*
|
|
1138
|
+
* Only an agent that shares the distro's PID namespace is addressable: the
|
|
1139
|
+
* plain agent, or a session runtime (its prefix is a scope plus mounts, but
|
|
1140
|
+
* no PID namespace). A confined resident runs inside a PID namespace whose
|
|
1141
|
+
* PIDs do not exist in the distro, so signalling its HELLO PID could hit an
|
|
1142
|
+
* unrelated process; there the KILL frame remains the (delayed) fallback.
|
|
1143
|
+
*
|
|
1144
|
+
* @param signal - the signal to deliver (`SIGUSR1` is the cancel trap).
|
|
1145
|
+
*/
|
|
1080
1146
|
signalAgent(signal) {
|
|
1081
1147
|
const pid = this.agentPid;
|
|
1082
1148
|
if (pid === undefined || !this.signalable)
|
|
@@ -1207,6 +1273,7 @@ export class WslAgent {
|
|
|
1207
1273
|
clearPending(pending) {
|
|
1208
1274
|
if (pending.watchdog)
|
|
1209
1275
|
clearTimeout(pending.watchdog);
|
|
1276
|
+
this.releaseDispatchWatchdog(pending);
|
|
1210
1277
|
if (pending.signalTimer)
|
|
1211
1278
|
clearTimeout(pending.signalTimer);
|
|
1212
1279
|
pending.signalTimer = null;
|
package/lib/fs-routing.d.ts
CHANGED
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
*
|
|
31
31
|
* @module dsh-plugin-wsl-env/fs-routing
|
|
32
32
|
*/
|
|
33
|
+
import { PLUGIN_PROVIDER } from "./provider-marker.js";
|
|
33
34
|
import z from "@deepseek-ai/schemastery";
|
|
34
35
|
import { LocalFileSystem } from "@deepseek-ai/dsh-fs-local";
|
|
35
36
|
import { WslFileSystem } from "./wsl-filesystem.js";
|
|
@@ -98,6 +99,8 @@ export declare function inputIsDistro(value: string | undefined): boolean;
|
|
|
98
99
|
* mode the distro side reports through `sandboxMode`).
|
|
99
100
|
*/
|
|
100
101
|
export declare class WslRoutingFileSystem extends LocalFileSystem {
|
|
102
|
+
/** Brand for the in-app takeover report; see `provider-marker`. */
|
|
103
|
+
get [PLUGIN_PROVIDER](): "fs";
|
|
101
104
|
static Config: z<RoutingConfig>;
|
|
102
105
|
/**
|
|
103
106
|
* The routed backend's constructor reads the deployment default mode from
|
package/lib/fs-routing.js
CHANGED
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
* @module dsh-plugin-wsl-env/fs-routing
|
|
32
32
|
*/
|
|
33
33
|
import { isWslUnc, uncToPosix } from "./paths.js";
|
|
34
|
+
import { PLUGIN_PROVIDER } from "./provider-marker.js";
|
|
34
35
|
import z from "@deepseek-ai/schemastery";
|
|
35
36
|
import { LocalFileSystem } from "@deepseek-ai/dsh-fs-local";
|
|
36
37
|
import { WslFileSystem } from "./wsl-filesystem.js";
|
|
@@ -103,6 +104,10 @@ export function inputIsDistro(value) {
|
|
|
103
104
|
* mode the distro side reports through `sandboxMode`).
|
|
104
105
|
*/
|
|
105
106
|
export class WslRoutingFileSystem extends LocalFileSystem {
|
|
107
|
+
/** Brand for the in-app takeover report; see `provider-marker`. */
|
|
108
|
+
get [PLUGIN_PROVIDER]() {
|
|
109
|
+
return "fs";
|
|
110
|
+
}
|
|
106
111
|
static Config = z.intersect([
|
|
107
112
|
LocalFileSystem.Config,
|
|
108
113
|
z.object({
|
package/lib/fs-substrate.d.ts
CHANGED
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
* @module dsh-plugin-wsl-env/fs-substrate
|
|
32
32
|
*/
|
|
33
33
|
import type { PatchHunk } from "@deepseek-ai/dsh-fs-patch";
|
|
34
|
-
import { ResolvedTarget } from "./fsio-agent.js";
|
|
34
|
+
import { type ResolvedTarget } from "./fsio-agent.js";
|
|
35
35
|
import { DistroFs } from "./fsio-agent.js";
|
|
36
36
|
import type { WslAgent } from "./agent.js";
|
|
37
37
|
/**
|
package/lib/fs-substrate.js
CHANGED
|
@@ -35,10 +35,6 @@ import { reasonToCode } from "./fsio-agent.js";
|
|
|
35
35
|
import { applyLiteralEdit, FsCodedError, normalizeLineEndings, restoreLineEndings } from "./fsio-text.js";
|
|
36
36
|
import { DistroFs } from "./fsio-agent.js";
|
|
37
37
|
import { posixToUnc, uncToPosix } from "./paths.js";
|
|
38
|
-
/**
|
|
39
|
-
* A resolved target: the Linux spelling the model sees and the UNC identity
|
|
40
|
-
* the harness keys on, as returned by {@linkcode AgentSubstrate#resolve}.
|
|
41
|
-
*/
|
|
42
38
|
/**
|
|
43
39
|
* The provider's stat/lstat row, type-spelled the way the tool layer reads it.
|
|
44
40
|
*
|
|
@@ -434,20 +430,15 @@ export class AgentSubstrate {
|
|
|
434
430
|
let destinationRow;
|
|
435
431
|
let sourceFailure;
|
|
436
432
|
if (options.hunks !== undefined) {
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
destinationRow = { version: published ? published.version : `missing:${destination.targetKey}` };
|
|
447
|
-
}
|
|
448
|
-
catch (error) {
|
|
449
|
-
throw error;
|
|
450
|
-
}
|
|
433
|
+
await this.fs.writeFileAtomic(destinationPath, content, {
|
|
434
|
+
mode: sourceInfo.mode,
|
|
435
|
+
createIfAbsent: options.expectedDestination?.kind === "createIfAbsent" ? { displayPath: destination.displayPath } : undefined,
|
|
436
|
+
expectedVersion: options.expectedDestination?.kind === "replaceIfVersion" ? options.expectedDestination.version : undefined,
|
|
437
|
+
signal,
|
|
438
|
+
agent: mutationAgent,
|
|
439
|
+
});
|
|
440
|
+
const published = await this.fs.stat(destinationPath, { signal });
|
|
441
|
+
destinationRow = { version: published ? published.version : `missing:${destination.targetKey}` };
|
|
451
442
|
try {
|
|
452
443
|
await this.fs.removeFile(sourcePath, sourceInfo.version, signal, mutationAgent);
|
|
453
444
|
}
|
|
@@ -464,6 +455,7 @@ export class AgentSubstrate {
|
|
|
464
455
|
guard: options.expectedDestination?.kind === "createIfAbsent" ? "no-replace" : "replace",
|
|
465
456
|
sourceVersion: sourceInfo.version,
|
|
466
457
|
destinationVersion: options.expectedDestination?.kind === "replaceIfVersion" ? options.expectedDestination.version : undefined,
|
|
458
|
+
size: sourceInfo.size,
|
|
467
459
|
signal,
|
|
468
460
|
agent: mutationAgent,
|
|
469
461
|
});
|
package/lib/fsio-agent.d.ts
CHANGED
|
@@ -376,6 +376,10 @@ export declare class DistroFs {
|
|
|
376
376
|
sourceVersion?: string;
|
|
377
377
|
/** The destination version the move was based on. */
|
|
378
378
|
destinationVersion?: string;
|
|
379
|
+
/** The source size in bytes, when known, so the budget scales with the copy. */
|
|
380
|
+
size?: number;
|
|
381
|
+
/** Explicit budget override in ms; takes precedence over `size`. */
|
|
382
|
+
timeoutMs?: number;
|
|
379
383
|
signal?: AbortSignal;
|
|
380
384
|
agent?: WslAgent;
|
|
381
385
|
}): Promise<{
|
package/lib/fsio-agent.js
CHANGED
|
@@ -24,8 +24,24 @@
|
|
|
24
24
|
import { FS_READ_CHUNK_BYTES } from "./agent-protocol.js";
|
|
25
25
|
import { BINARY_SAMPLE_BYTES, FsCodedError, decodeUtf8, decodeUtf8Stream, detectLineEndings, normalizeLineEndings, throwIfAborted, } from "./fsio-text.js";
|
|
26
26
|
import { posixToUnc, uncToPosix } from "./paths.js";
|
|
27
|
-
/**
|
|
27
|
+
/** Base in-distro watchdog for one FS frame. */
|
|
28
28
|
const FS_OP_TIMEOUT_MS = 30_000;
|
|
29
|
+
/** Extra in-distro budget per MiB of content the op must copy, write or move. */
|
|
30
|
+
const FS_OP_TIMEOUT_PER_MIB_MS = 1_000;
|
|
31
|
+
/** Ceiling on the size-scaled budget; a stuck op must still fail in bounded time. */
|
|
32
|
+
const FS_OP_TIMEOUT_MAX_MS = 10 * 60_000;
|
|
33
|
+
/**
|
|
34
|
+
* The in-distro budget for an op whose cost scales with `bytes`: a fixed 30 s
|
|
35
|
+
* was a false `FS_IO_ERROR` for a multi-GB `move` (the agent copies with
|
|
36
|
+
* `cat > tmp`) or write on a slow 9p-backed distro path.
|
|
37
|
+
*
|
|
38
|
+
* @param bytes - the content size the op must handle, when known.
|
|
39
|
+
* @returns the frame's timeout budget in ms, capped at ten minutes.
|
|
40
|
+
*/
|
|
41
|
+
function fsOpTimeoutMs(bytes = 0) {
|
|
42
|
+
const scaled = FS_OP_TIMEOUT_MS + Math.ceil(bytes / (1024 * 1024)) * FS_OP_TIMEOUT_PER_MIB_MS;
|
|
43
|
+
return Math.min(scaled, FS_OP_TIMEOUT_MAX_MS);
|
|
44
|
+
}
|
|
29
45
|
/**
|
|
30
46
|
* Normalize one agent timestamp ("seconds.frac", 9 or 10 fractional digits
|
|
31
47
|
* depending on whether stat or find produced it) into the peer's nanosecond
|
|
@@ -122,9 +138,9 @@ export class DistroFs {
|
|
|
122
138
|
* @param agent - the agent that must run the op; the plain resident by default.
|
|
123
139
|
* @returns the op's result.
|
|
124
140
|
*/
|
|
125
|
-
async request(op, args, signal, agent = this.agent) {
|
|
141
|
+
async request(op, args, signal, agent = this.agent, timeoutMs = FS_OP_TIMEOUT_MS) {
|
|
126
142
|
try {
|
|
127
|
-
return await agent.fs({ op, args: args, timeoutMs
|
|
143
|
+
return await agent.fs({ op, args: args, timeoutMs, signal });
|
|
128
144
|
}
|
|
129
145
|
catch (error) {
|
|
130
146
|
if (signal?.aborted) {
|
|
@@ -533,7 +549,7 @@ export class DistroFs {
|
|
|
533
549
|
createIfAbsent ? "no-replace" : "replace",
|
|
534
550
|
expectedVersion ?? "-",
|
|
535
551
|
content,
|
|
536
|
-
], signal, agent);
|
|
552
|
+
], signal, agent, fsOpTimeoutMs(typeof content === "string" ? Buffer.byteLength(content, "utf8") : content.byteLength));
|
|
537
553
|
if (result.exitCode === 0)
|
|
538
554
|
return;
|
|
539
555
|
const failure = this.fail("write", result, displayPath);
|
|
@@ -580,17 +596,28 @@ export class DistroFs {
|
|
|
580
596
|
if (result.exitCode !== 0)
|
|
581
597
|
throw this.fail("batch", result, ops.map((op) => op.op).join(","));
|
|
582
598
|
const records = [];
|
|
599
|
+
let expected = 1;
|
|
583
600
|
for (const line of result.stdout.toString("utf8").split("\n")) {
|
|
584
601
|
if (line.length === 0)
|
|
585
602
|
continue;
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
603
|
+
const bad = line.startsWith("BAD ");
|
|
604
|
+
if (!bad && !line.startsWith("OK "))
|
|
605
|
+
continue;
|
|
606
|
+
const bar = line.indexOf("|");
|
|
607
|
+
const indexText = line.slice(bad ? 4 : 3, bar);
|
|
608
|
+
const index = Number(indexText);
|
|
609
|
+
if (bar < 0 || !Number.isInteger(index) || index !== expected) {
|
|
610
|
+
throw new FsCodedError(`cannot run the batch (${ops.map((op) => op.op).join(",")}): record ${expected} was answered as "${line.slice(0, bar < 0 ? 40 : bar)}"`, "FS_IO_ERROR");
|
|
611
|
+
}
|
|
612
|
+
const rest = line.slice(bar + 1);
|
|
613
|
+
if (!bad) {
|
|
614
|
+
records.push({ ok: true, payload: Buffer.from(rest, "base64") });
|
|
589
615
|
}
|
|
590
|
-
else
|
|
591
|
-
const [
|
|
616
|
+
else {
|
|
617
|
+
const [reason, message] = rest.split("|");
|
|
592
618
|
records.push({ ok: false, reason: reason ?? "io", message: Buffer.from(message ?? "", "base64").toString("utf8") });
|
|
593
619
|
}
|
|
620
|
+
expected += 1;
|
|
594
621
|
}
|
|
595
622
|
return records;
|
|
596
623
|
}
|
|
@@ -633,7 +660,7 @@ export class DistroFs {
|
|
|
633
660
|
options.guard,
|
|
634
661
|
options.sourceVersion ?? "-",
|
|
635
662
|
options.destinationVersion ?? "-",
|
|
636
|
-
], options.signal, options.agent ?? this.agent);
|
|
663
|
+
], options.signal, options.agent ?? this.agent, options.timeoutMs ?? fsOpTimeoutMs(options.size));
|
|
637
664
|
if (result.exitCode !== 0)
|
|
638
665
|
throw this.fail("move", result, source);
|
|
639
666
|
const lines = result.stdout.toString("utf8").split("\n").filter((line) => line.length > 0);
|
package/lib/listing.d.ts
CHANGED
|
@@ -51,7 +51,7 @@ export declare function fullyQualified(path: string): boolean;
|
|
|
51
51
|
export declare function ancestryCrumbs(target: string): ListingRow[];
|
|
52
52
|
/** The three virtual roots the picker's breadcrumb trail is built from. */
|
|
53
53
|
export interface PickerRoots {
|
|
54
|
-
/** The two-category level ("
|
|
54
|
+
/** The two-category level ("Workspace"): Windows paths and WSL distros. */
|
|
55
55
|
picker: string;
|
|
56
56
|
/** The Windows branch's drive list. */
|
|
57
57
|
windows: string;
|
|
@@ -63,7 +63,7 @@ export interface PickerRoots {
|
|
|
63
63
|
* belongs to, then the path itself.
|
|
64
64
|
*
|
|
65
65
|
* The trail is what makes the two top-level categories reachable from anywhere:
|
|
66
|
-
* every level keeps
|
|
66
|
+
* every level keeps the workspace crumb as its first, so a browse into a distro or a
|
|
67
67
|
* drive never strands the user without a way back to the other world.
|
|
68
68
|
*
|
|
69
69
|
* Two Windows path quirks need explicit handling. `win32.dirname` treats
|
package/lib/listing.js
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
* @module dsh-plugin-wsl-env/listing
|
|
12
12
|
*/
|
|
13
13
|
import { win32 } from "node:path";
|
|
14
|
+
import { t } from "./messages.js";
|
|
14
15
|
import { isWslUnc, uncToPosix } from "./paths.js";
|
|
15
16
|
/**
|
|
16
17
|
* Whether a path names one fixed filesystem location regardless of process
|
|
@@ -61,7 +62,7 @@ export function ancestryCrumbs(target) {
|
|
|
61
62
|
* belongs to, then the path itself.
|
|
62
63
|
*
|
|
63
64
|
* The trail is what makes the two top-level categories reachable from anywhere:
|
|
64
|
-
* every level keeps
|
|
65
|
+
* every level keeps the workspace crumb as its first, so a browse into a distro or a
|
|
65
66
|
* drive never strands the user without a way back to the other world.
|
|
66
67
|
*
|
|
67
68
|
* Two Windows path quirks need explicit handling. `win32.dirname` treats
|
|
@@ -75,13 +76,13 @@ export function ancestryCrumbs(target) {
|
|
|
75
76
|
* @returns breadcrumb rows, outermost first.
|
|
76
77
|
*/
|
|
77
78
|
export function breadcrumbs(target, roots) {
|
|
78
|
-
const head = [{ name: "
|
|
79
|
+
const head = [{ name: t("pickerWorkspace", {}), path: roots.picker, hidden: false }];
|
|
79
80
|
const parsed = isWslUnc(target) ? uncToPosix(target) : undefined;
|
|
80
81
|
if (parsed === undefined) {
|
|
81
|
-
return [...head, { name: "
|
|
82
|
+
return [...head, { name: t("pickerWindowsPaths", {}), path: roots.windows, hidden: false }, ...ancestryCrumbs(target)];
|
|
82
83
|
}
|
|
83
84
|
const distroRootPath = `${roots.wsl}\\${parsed.distro}`;
|
|
84
|
-
head.push({ name: "
|
|
85
|
+
head.push({ name: t("pickerWslDistros", {}), path: roots.wsl, hidden: false });
|
|
85
86
|
head.push({ name: parsed.distro, path: distroRootPath, hidden: false });
|
|
86
87
|
let current = distroRootPath;
|
|
87
88
|
for (const segment of parsed.linuxPath.split("/").filter((part) => part.length > 0)) {
|
package/lib/messages.d.ts
CHANGED
|
@@ -138,6 +138,76 @@ declare const en: {
|
|
|
138
138
|
cwd: string;
|
|
139
139
|
distro: string;
|
|
140
140
|
}) => string;
|
|
141
|
+
/** `wsl-status`: the route's method guard. */
|
|
142
|
+
statusMethodNotAllowed: () => string;
|
|
143
|
+
/** `wsl-status`: `wsl.exe -l -q` did not answer. */
|
|
144
|
+
statusDistroListFailed: ({ detail }: {
|
|
145
|
+
detail: string;
|
|
146
|
+
}) => string;
|
|
147
|
+
/** `wsl-status`: a repair POST named no distro. */
|
|
148
|
+
statusRepairNeedsDistro: () => string;
|
|
149
|
+
/** `wsl-status`: the requested name is not in `wsl.exe -l -q`. */
|
|
150
|
+
statusUnknownDistro: ({ distro }: {
|
|
151
|
+
distro: string;
|
|
152
|
+
}) => string;
|
|
153
|
+
/** `wsl-open-in-app`: the route's method guard. */
|
|
154
|
+
openInAppPostOnly: () => string;
|
|
155
|
+
/** `wsl-open-in-app`: the route requires a JSON content type. */
|
|
156
|
+
openInAppJsonContentType: () => string;
|
|
157
|
+
/** `wsl-open-in-app`: the request body did not parse as JSON. */
|
|
158
|
+
openInAppInvalidJson: () => string;
|
|
159
|
+
/** `wsl-open-in-app`: the body parsed but is not an object. */
|
|
160
|
+
openInAppBodyNotObject: () => string;
|
|
161
|
+
/** `wsl-open-in-app`: the body's `path` is not a string. */
|
|
162
|
+
openInAppPathMustBeString: () => string;
|
|
163
|
+
/** `wsl-open-in-app`: the path is not a WSL UNC workspace. */
|
|
164
|
+
openInAppNotWslWorkspacePath: () => string;
|
|
165
|
+
/** `wsl-open-in-app`: the detached launch failed. */
|
|
166
|
+
openInAppLaunchFailed: () => string;
|
|
167
|
+
/** `wsl-open-in-app`: no editor executable could be resolved. */
|
|
168
|
+
openInAppExecutableMissing: () => string;
|
|
169
|
+
/** The directory picker's root crumb, shared by every level. */
|
|
170
|
+
pickerWorkspace: () => string;
|
|
171
|
+
/** The directory picker's Windows branch label. */
|
|
172
|
+
pickerWindowsPaths: () => string;
|
|
173
|
+
/** The directory picker's WSL branch label. */
|
|
174
|
+
pickerWslDistros: () => string;
|
|
175
|
+
/** `/wsl-doctor`: the usage block a grammar violation settles with. */
|
|
176
|
+
doctorUsage: ({ sections }: {
|
|
177
|
+
sections: string;
|
|
178
|
+
}) => string;
|
|
179
|
+
/** `/wsl-doctor`: a token that matches no mode, section or distro spelling. */
|
|
180
|
+
doctorUnknownToken: ({ token }: {
|
|
181
|
+
token: string;
|
|
182
|
+
}) => string;
|
|
183
|
+
/** `/wsl-doctor`: `--distro` was not followed by a name. */
|
|
184
|
+
doctorDistroNeedsName: () => string;
|
|
185
|
+
/** `/wsl-doctor`: the CLI run was cancelled. */
|
|
186
|
+
doctorCliCancelled: () => string;
|
|
187
|
+
/** `/wsl-doctor`: the CLI produced no report before the deadline. */
|
|
188
|
+
doctorCliTimeout: ({ seconds }: {
|
|
189
|
+
seconds: number;
|
|
190
|
+
}) => string;
|
|
191
|
+
/** `/wsl-doctor`: the CLI exited without a report. `detail` is "" or ": <stderr>". */
|
|
192
|
+
doctorCliNoReport: ({ status, detail }: {
|
|
193
|
+
status: string;
|
|
194
|
+
detail: string;
|
|
195
|
+
}) => string;
|
|
196
|
+
/** `/wsl-doctor`: the resolved target is one named distro. */
|
|
197
|
+
doctorTargetDistro: ({ distro }: {
|
|
198
|
+
distro: string;
|
|
199
|
+
}) => string;
|
|
200
|
+
/** `/wsl-doctor`: no distro resolved, so the CLI's configured target decides. */
|
|
201
|
+
doctorTargetConfigured: () => string;
|
|
202
|
+
/** `/wsl-doctor`: the CLI run failed; `target` is the localized target phrase. */
|
|
203
|
+
doctorRunFailed: ({ target, message }: {
|
|
204
|
+
target: string;
|
|
205
|
+
message: string;
|
|
206
|
+
}) => string;
|
|
207
|
+
/** `/wsl-doctor`: the command-plane description. */
|
|
208
|
+
doctorCommandDescription: () => string;
|
|
209
|
+
/** `/wsl-doctor`: the input hint under the command name. */
|
|
210
|
+
doctorInputHint: () => string;
|
|
141
211
|
/** `wsl_doctor` digest: the verdict line. `verdict` is the report's own `ready`/`blocked`. */
|
|
142
212
|
doctorDigestVerdict: ({ verdict }: {
|
|
143
213
|
verdict: string;
|