dsh-remote-vs 0.29.0 → 0.30.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/README.en.md +14 -3
- package/README.md +10 -3
- package/lib/client.js +264 -88
- package/lib/index.js +821 -127
- package/lib/p2-router-fs.js +1 -1
- package/lib/types/changes/recorder.d.ts +65 -10
- package/lib/types/changes/status.d.ts +48 -3
- package/lib/types/client/ConnectionsSection.d.ts +73 -0
- package/lib/types/client/api.d.ts +41 -2
- package/lib/types/client/scm/actions.d.ts +25 -1
- package/lib/types/p2/helper-rpc.d.ts +48 -0
- package/lib/types/p2/worlds.d.ts +28 -0
- package/lib/types/pool.d.ts +245 -10
- package/lib/types/protocol.d.ts +96 -0
- package/lib/{worlds-RG8K5eom.js → worlds-CRRZMZhg.js} +85 -6
- package/package.json +1 -1
- package/src/changes/recorder.ts +151 -15
- package/src/changes/status.ts +59 -4
- package/src/client/ConnectionsSection.tsx +359 -0
- package/src/client/MonitorView.tsx +14 -0
- package/src/client/api.ts +72 -4
- package/src/client/i18n.ts +50 -2
- package/src/client/scm/actions.ts +63 -12
- package/src/client/vsc/vsc.css +176 -0
- package/src/p2/helper-rpc.ts +73 -5
- package/src/p2/worlds.ts +48 -0
- package/src/pool.ts +736 -111
- package/src/protocol.ts +100 -0
- package/src/routes.ts +66 -0
package/lib/types/pool.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import type { Duplex } from 'node:stream';
|
|
1
2
|
import { type ClientChannel, type SFTPWrapper } from 'ssh2';
|
|
2
3
|
import type { RemoteStore } from './store.ts';
|
|
3
4
|
import { DeadlineError } from './timeouts.ts';
|
|
4
|
-
import type { RemoteConnectionStatus, RemoteExecResult } from './protocol.ts';
|
|
5
|
+
import type { RemoteConnectionStatus, RemoteExecResult, RemoteHostPoolStats } from './protocol.ts';
|
|
5
6
|
/**
|
|
6
7
|
* The budget-out type lives in `timeouts.ts` (both halves need it); re-exported
|
|
7
8
|
* here because existing callers and the browse gate import it from the pool.
|
|
@@ -27,11 +28,44 @@ export interface ExecOptions {
|
|
|
27
28
|
* recurse into the machinery that dispatched them.
|
|
28
29
|
*/
|
|
29
30
|
bare?: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Which channel budget this command spends. Omitted means the shared exec
|
|
33
|
+
* budget — every caller that predates the split keeps that behaviour.
|
|
34
|
+
*
|
|
35
|
+
* `'network'` is for `git fetch/pull/push/sync`: those can hold a channel for
|
|
36
|
+
* the whole network timeout (20 minutes by default), so they get
|
|
37
|
+
* {@link NET_CHANNEL_LIMIT} slots of their own instead of eating the exec slots
|
|
38
|
+
* the rest of the app (status polls, monitor, agent tools) depends on.
|
|
39
|
+
*
|
|
40
|
+
* `'git'` is for GIT COMMANDS — the repository reads (`git status/diff/log`, the
|
|
41
|
+
* session ledger's scans) AND the local writes the SCM panel runs (`commit`,
|
|
42
|
+
* `stage`, `discard`, branch verbs, `merge`): a big tree's `git status` is
|
|
43
|
+
* allowed 300 s, so these get {@link GIT_CHANNEL_LIMIT} slots — otherwise one
|
|
44
|
+
* slow command parks an exec slot for minutes and the monitor/process panel/
|
|
45
|
+
* agent tools queue behind it.
|
|
46
|
+
*/
|
|
47
|
+
lane?: 'exec' | 'network' | 'git';
|
|
30
48
|
}
|
|
31
49
|
export interface ShellOptions {
|
|
32
50
|
cols?: number;
|
|
33
51
|
rows?: number;
|
|
34
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* The transport one configured route hands to an ssh2 dial (see `openRoutedSocket`).
|
|
55
|
+
*
|
|
56
|
+
* `sock` is absent for a direct route, where ssh2 dials the target itself. When it
|
|
57
|
+
* IS present ssh2 must be given `{ sock }` and NOT `host`/`port`: supplying both
|
|
58
|
+
* lets ssh2 choose between "dial this host myself" and "ride the tunnel", and the
|
|
59
|
+
* choice is an implementation detail, not a feature.
|
|
60
|
+
*
|
|
61
|
+
* `release` is idempotent and is the OWNER's to call — a proxy socket has to be
|
|
62
|
+
* destroyed and a jump-host tunnel has to close its channel and give the jump
|
|
63
|
+
* host's hold back, or the next dial finds a pinned connection.
|
|
64
|
+
*/
|
|
65
|
+
export interface RoutedDial {
|
|
66
|
+
sock?: Duplex;
|
|
67
|
+
release: () => void;
|
|
68
|
+
}
|
|
35
69
|
export interface SftpOptions {
|
|
36
70
|
/**
|
|
37
71
|
* Wall-clock cap for the callback body. `0` disables it for an operation that
|
|
@@ -82,6 +116,38 @@ export declare class RemotePool {
|
|
|
82
116
|
* stops working because of it — it only loses the isolation.
|
|
83
117
|
*/
|
|
84
118
|
private readonly forwardConns;
|
|
119
|
+
/**
|
|
120
|
+
* Dedicated connections for FILE operations (one per alias).
|
|
121
|
+
*
|
|
122
|
+
* The third instance of the same argument. Browse/read/write/upload/download
|
|
123
|
+
* used to ride the shared connection, which meant a `git status` burst or a
|
|
124
|
+
* long exec could sit in front of a directory refresh (SSH offers no
|
|
125
|
+
* per-channel priority), AND that the shared link's channel budget was shared
|
|
126
|
+
* with file I/O: a few in-flight git/search commands and the explorer could not
|
|
127
|
+
* open a channel at all. A file operation is exactly the traffic a user is
|
|
128
|
+
* watching (a folder must open, a save must land), so it gets its own
|
|
129
|
+
* connection and its own channel budget (`sftpSlots`).
|
|
130
|
+
*
|
|
131
|
+
* Cost: one extra handshake per alias that touches files, plus one held TCP
|
|
132
|
+
* connection while any of its channels is open (the 30-minute idle eviction
|
|
133
|
+
* applies once the last one ends). `acquireSftp` falls back to the
|
|
134
|
+
* shared connection when this one cannot be established — a host that refuses
|
|
135
|
+
* extra connections still serves files, it only loses the isolation.
|
|
136
|
+
*/
|
|
137
|
+
private readonly sftpConns;
|
|
138
|
+
/** Aliases whose dedicated-SFTP downgrade was already logged (once per alias). */
|
|
139
|
+
private readonly sftpFallbackNoted;
|
|
140
|
+
/** alias -> timestamp until which the dedicated SFTP connection is skipped. */
|
|
141
|
+
private readonly sftpBlocked;
|
|
142
|
+
/**
|
|
143
|
+
* Aliases whose file operations are DOWNGRADED right now (sticky until a
|
|
144
|
+
* dedicated connection succeeds again or the host is edited).
|
|
145
|
+
*
|
|
146
|
+
* Purely diagnostic: `stats()` reports it so the monitor page can say "these
|
|
147
|
+
* files are riding the shared connection" instead of leaving the user to
|
|
148
|
+
* wonder why a browse refresh still queues behind git.
|
|
149
|
+
*/
|
|
150
|
+
private readonly sftpFallback;
|
|
85
151
|
/** Aliases whose dedicated-forward downgrade was already logged (once per alias). */
|
|
86
152
|
private readonly forwardFallbackNoted;
|
|
87
153
|
/** alias -> timestamp until which the dedicated forward connection is skipped. */
|
|
@@ -90,8 +156,35 @@ export declare class RemotePool {
|
|
|
90
156
|
private readonly hostKeys;
|
|
91
157
|
/** Per-alias `setsid --wait` capability, probed once (see supportsSetsid). */
|
|
92
158
|
private readonly setsidProbes;
|
|
93
|
-
/**
|
|
159
|
+
/**
|
|
160
|
+
* Channel slots of the SHARED connection (see acquireSlot), and of the
|
|
161
|
+
* dedicated SFTP connection.
|
|
162
|
+
*
|
|
163
|
+
* Two tables because the budget is per connection (`MaxSessions` counts
|
|
164
|
+
* channels on one link): a fallback SFTP operation counts against the shared
|
|
165
|
+
* table — the connection it really rides — and never against both.
|
|
166
|
+
*/
|
|
94
167
|
private readonly slots;
|
|
168
|
+
private readonly sftpSlots;
|
|
169
|
+
/**
|
|
170
|
+
* Channel budget of the NETWORK verbs (see {@link NET_CHANNEL_LIMIT}).
|
|
171
|
+
*
|
|
172
|
+
* A third table on the SHARED connection: unlike the SFTP lane this is not about
|
|
173
|
+
* isolating bytes, it is about isolating TIME. A `git push` holds its channel
|
|
174
|
+
* for minutes, and the failure mode it caused — a full exec table, so every
|
|
175
|
+
* status refresh answered "host is busy" after 30 s — came from the two kinds
|
|
176
|
+
* sharing one ceiling.
|
|
177
|
+
*/
|
|
178
|
+
private readonly netSlots;
|
|
179
|
+
/**
|
|
180
|
+
* Channel budget of the GIT COMMANDS (see {@link GIT_CHANNEL_LIMIT}).
|
|
181
|
+
*
|
|
182
|
+
* A fourth table on the SHARED connection, for the same reason as the network
|
|
183
|
+
* one — hold TIME, not traffic: a `git status` on a big tree may run for
|
|
184
|
+
* minutes, and a git command must not be the reason a monitor sample or an agent
|
|
185
|
+
* tool waits.
|
|
186
|
+
*/
|
|
187
|
+
private readonly gitSlots;
|
|
95
188
|
/** Per-alias BROWSE SFTP session (see withBrowseSftp). */
|
|
96
189
|
private readonly browsed;
|
|
97
190
|
/** Per-alias connection health for the browser's status chip (see status). */
|
|
@@ -117,12 +210,27 @@ export declare class RemotePool {
|
|
|
117
210
|
* indicator's poll never creates a connection as a side effect.
|
|
118
211
|
*/
|
|
119
212
|
status(): RemoteConnectionStatus[];
|
|
213
|
+
/**
|
|
214
|
+
* Live pool shape per host: connections, channels, and channel-budget
|
|
215
|
+
* occupancy (see `RemoteHostPoolStats`).
|
|
216
|
+
*
|
|
217
|
+
* Same contract as `status()`: read-only and dial-free, so the monitor's poll
|
|
218
|
+
* reports what the pool already knows instead of creating work. Answers every
|
|
219
|
+
* alias the store knows PLUS every alias the pool holds something for — a host
|
|
220
|
+
* removed from the store still has a connection for a moment, and a page that
|
|
221
|
+
* shows connections must not hide exactly those.
|
|
222
|
+
*/
|
|
223
|
+
stats(): RemoteHostPoolStats[];
|
|
224
|
+
/** One lane of one host: dialed or not, its open channels, its pinned rounds. */
|
|
225
|
+
private laneOf;
|
|
226
|
+
/** One channel budget, as reported (a budget nobody touched is empty, not absent). */
|
|
227
|
+
private slotsOf;
|
|
120
228
|
/**
|
|
121
229
|
* The egress of the alias' LIVE connection, whichever class owns it.
|
|
122
230
|
*
|
|
123
|
-
* All
|
|
124
|
-
*
|
|
125
|
-
*
|
|
231
|
+
* All four classes open through the same resolved route, so the first one that
|
|
232
|
+
* is up answers for the alias; the shared connection is preferred because it is
|
|
233
|
+
* the one exec/browse (the surface the chip describes) rides.
|
|
126
234
|
*/
|
|
127
235
|
private liveEgress;
|
|
128
236
|
/**
|
|
@@ -178,13 +286,31 @@ export declare class RemotePool {
|
|
|
178
286
|
* of queueing. The pool's own housekeeping (`bare`: the setsid probe and the
|
|
179
287
|
* group kill) is exempt — a kill that waits behind user traffic would be a
|
|
180
288
|
* worse bug than the one it fixes.
|
|
289
|
+
*
|
|
290
|
+
* `opts.lane` picks the budget: network verbs (`git fetch/pull/push/sync`) have
|
|
291
|
+
* their own small one, so a 20-minute push cannot starve the exec slots.
|
|
292
|
+
* Acquisition and release read the SAME table — a mismatch would leak a slot on
|
|
293
|
+
* one budget and double-count on the other.
|
|
181
294
|
*/
|
|
182
295
|
exec(alias: string, command: string, opts?: ExecOptions): Promise<RemoteExecResult>;
|
|
296
|
+
/** The channel budget an exec spends, by lane (see `ExecOptions.lane`). */
|
|
297
|
+
private execBudget;
|
|
183
298
|
/** The exec body, run while the caller already holds a channel slot. */
|
|
184
299
|
private runExec;
|
|
185
300
|
/** Open an interactive PTY shell. The caller owns the channel lifecycle. */
|
|
186
301
|
shell(alias: string, opts?: ShellOptions): Promise<ClientChannel>;
|
|
187
|
-
/**
|
|
302
|
+
/**
|
|
303
|
+
* Open one exec channel. The caller owns the channel lifecycle.
|
|
304
|
+
*
|
|
305
|
+
* This channel spends an EXEC SLOT (same budget as `runExec`): it is a real
|
|
306
|
+
* `conn.exec` session on the shared connection, so `MaxSessions` counts it
|
|
307
|
+
* whether the pool does or not. The subprocess runtime opens these for every
|
|
308
|
+
* command it runs (`p2/ssh-proc.ts`) and can have several in flight, which used
|
|
309
|
+
* to be the one way to push the shared connection past its ceiling: sshd then
|
|
310
|
+
* refuses the extra channel HARD — no retry, and the operation fails looking
|
|
311
|
+
* like a broken host. A slot makes the surplus WAIT instead: bounded queue, then
|
|
312
|
+
* a readable "busy" message naming the cause.
|
|
313
|
+
*/
|
|
188
314
|
execChannel(alias: string, command: string): Promise<ClientChannel>;
|
|
189
315
|
/**
|
|
190
316
|
* Open one direct-tcpip channel to a TCP target reachable FROM the remote
|
|
@@ -285,6 +411,9 @@ export declare class RemotePool {
|
|
|
285
411
|
* place that can still see the session, and a late one would otherwise leak a
|
|
286
412
|
* server-side channel that no slot or hold accounts for (the caller has long
|
|
287
413
|
* returned its own and moved on).
|
|
414
|
+
*
|
|
415
|
+
* `alias`/`map` name the connection the session rides, so the channel it holds
|
|
416
|
+
* is counted on the right lane (see `countChannel`).
|
|
288
417
|
*/
|
|
289
418
|
private openSession;
|
|
290
419
|
/**
|
|
@@ -298,6 +427,10 @@ export declare class RemotePool {
|
|
|
298
427
|
/**
|
|
299
428
|
* Open the browse session: a channel slot + a connection hold + the SFTP
|
|
300
429
|
* session itself, all released together by evictBrowse().
|
|
430
|
+
*
|
|
431
|
+
* The lane is chosen HERE, once per session, and recorded on the state: the
|
|
432
|
+
* eviction path must give the slot and the hold back to the connection that
|
|
433
|
+
* actually served the session (dedicated SFTP, or the shared fallback).
|
|
301
434
|
*/
|
|
302
435
|
private openBrowse;
|
|
303
436
|
/** One completed browse operation: idle-close the channel when it is unused. */
|
|
@@ -314,11 +447,25 @@ export declare class RemotePool {
|
|
|
314
447
|
private evictBrowse;
|
|
315
448
|
private browseState;
|
|
316
449
|
/**
|
|
317
|
-
* Take one channel slot for `alias
|
|
318
|
-
* The wait is bounded: waiting forever behind a peer
|
|
319
|
-
* worse than a readable error naming the cause
|
|
450
|
+
* Take one channel slot for `alias` on the budget `slots` names, waiting FIFO
|
|
451
|
+
* when the limit is reached. The wait is bounded: waiting forever behind a peer
|
|
452
|
+
* that never finishes is worse than a readable error naming the cause.
|
|
453
|
+
*
|
|
454
|
+
* `slots` defaults to the SHARED connection's exec budget — the table every
|
|
455
|
+
* caller meant before the lanes existed; dedicated-lane callers pass theirs.
|
|
320
456
|
*/
|
|
321
457
|
private acquireSlot;
|
|
458
|
+
/**
|
|
459
|
+
* The ceiling and the wording of one budget.
|
|
460
|
+
*
|
|
461
|
+
* The TABLE is the budget's identity: a caller that hands in a table gets that
|
|
462
|
+
* budget's own ceiling AND its own nouns, so a full network lane says "2
|
|
463
|
+
* network operations already hold channels" and a full git lane says "2 git
|
|
464
|
+
* commands already hold channels" instead of borrowing the exec sentence — a
|
|
465
|
+
* user reading "5 operations" about a two-slot lane would go looking for
|
|
466
|
+
* operations that do not exist. A new budget is described here, once.
|
|
467
|
+
*/
|
|
468
|
+
private budgetOf;
|
|
322
469
|
/**
|
|
323
470
|
* Take one channel slot only if one is free RIGHT NOW; never queue.
|
|
324
471
|
*
|
|
@@ -330,7 +477,7 @@ export declare class RemotePool {
|
|
|
330
477
|
* would just move the wait.
|
|
331
478
|
*/
|
|
332
479
|
private tryAcquireSlot;
|
|
333
|
-
/** Give a slot back, handing it straight to the longest
|
|
480
|
+
/** Give a slot back to its budget, handing it straight to the longest waiter. */
|
|
334
481
|
private releaseSlot;
|
|
335
482
|
private slotState;
|
|
336
483
|
/**
|
|
@@ -359,6 +506,23 @@ export declare class RemotePool {
|
|
|
359
506
|
private hold;
|
|
360
507
|
private holdIn;
|
|
361
508
|
private release;
|
|
509
|
+
/**
|
|
510
|
+
* Count one SSH channel that is now open on a pooled connection, and give the
|
|
511
|
+
* number back when the channel closes.
|
|
512
|
+
*
|
|
513
|
+
* `held` is NOT this number (see `Pooled.channels`): a jump tunnel pins the
|
|
514
|
+
* jump host twice for its single channel, and `stats()` reports both, so the
|
|
515
|
+
* monitor page never prints a hold count as a channel count. The close listener
|
|
516
|
+
* mutates the entry OBJECT it was registered on, so a channel that outlives its
|
|
517
|
+
* entry cannot decrement the counter of a successor entry.
|
|
518
|
+
*
|
|
519
|
+
* The entry is looked up when the channel is COUNTED, so a session that answers
|
|
520
|
+
* pathologically late (after `drop()` and a fresh dial) is charged to the
|
|
521
|
+
* successor entry and given back when it closes. Accepted: the window needs a
|
|
522
|
+
* reply that outlives a host edit, the number is diagnostic, and the pair is
|
|
523
|
+
* still symmetric (one increment, one decrement).
|
|
524
|
+
*/
|
|
525
|
+
private countChannel;
|
|
362
526
|
private releaseIn;
|
|
363
527
|
private acquire;
|
|
364
528
|
/** `acquire` for the dedicated PTY connection map. */
|
|
@@ -380,6 +544,40 @@ export declare class RemotePool {
|
|
|
380
544
|
* `acquireIn`.
|
|
381
545
|
*/
|
|
382
546
|
private acquireForward;
|
|
547
|
+
/**
|
|
548
|
+
* Take the connection a FILE operation should ride: the dedicated SFTP one,
|
|
549
|
+
* else the shared one (recorded as the fallback).
|
|
550
|
+
*
|
|
551
|
+
* Same three-part shape as the PTY/forward precedents, for the same reasons:
|
|
552
|
+
*
|
|
553
|
+
* 1. `quiet` on the dial — a dedicated connection is an optional isolation, so
|
|
554
|
+
* the server refusing it (MaxStartups, a per-user limit) says nothing about
|
|
555
|
+
* the shared link and must not paint the connection chip red.
|
|
556
|
+
* 2. A short own budget ({@link SFTP_DEDICATED_BUDGET_MS}) — browsing is one
|
|
557
|
+
* request per folder, so waiting out the 45 s connect watchdog before falling
|
|
558
|
+
* back would freeze the explorer. The abandoned dial keeps running: if it
|
|
559
|
+
* eventually succeeds the connection is pooled and the next request uses it.
|
|
560
|
+
* 3. A cooldown ({@link SFTP_DEDICATED_BLOCK_MS}) — without it every browse
|
|
561
|
+
* request would pay that budget again. A success or `drop()` clears it.
|
|
562
|
+
*
|
|
563
|
+
* The shared fallback's own dial failure is NOT quiet (it is a real link
|
|
564
|
+
* failure and `acquire` reports it as one).
|
|
565
|
+
*/
|
|
566
|
+
private acquireSftp;
|
|
567
|
+
/** The pooled map behind a lane: the dedicated SFTP connection, or the shared one. */
|
|
568
|
+
private laneConns;
|
|
569
|
+
/** The channel budget behind a lane: each connection has its own `MaxSessions`. */
|
|
570
|
+
private laneSlots;
|
|
571
|
+
/**
|
|
572
|
+
* Is this alias's dedicated SFTP connection in its short cooldown?
|
|
573
|
+
*
|
|
574
|
+
* Expired entries are dropped eagerly so the map cannot grow per alias forever.
|
|
575
|
+
*/
|
|
576
|
+
private sftpCoolingDown;
|
|
577
|
+
/** Park the dedicated SFTP connection for one alias and log the downgrade, once. */
|
|
578
|
+
private blockSftp;
|
|
579
|
+
/** Log one alias's file-operation downgrade to the shared connection, once. */
|
|
580
|
+
private noteSftpFallback;
|
|
383
581
|
private acquireIn;
|
|
384
582
|
/** Evict ONE alias from ONE map (host removal drops both maps explicitly). */
|
|
385
583
|
private evictFrom;
|
|
@@ -392,6 +590,43 @@ export declare class RemotePool {
|
|
|
392
590
|
* overrides it.
|
|
393
591
|
*/
|
|
394
592
|
private makeClient;
|
|
593
|
+
/**
|
|
594
|
+
* Open the transport `alias`'s configured route requires, WITHOUT dialing SSH.
|
|
595
|
+
*
|
|
596
|
+
* This is the part of {@link dial} that turns a `ResolvedProxy` decision into a
|
|
597
|
+
* socket: nothing for a direct route, a tunnel socket for a proxy, and a
|
|
598
|
+
* `direct-tcpip` channel riding the jump host's pooled connection for a jump.
|
|
599
|
+
* Extracted so a SECOND ssh2 dialer — p2's helper transport, which owns its own
|
|
600
|
+
* `Client` — takes exactly the same route instead of a bare direct connection
|
|
601
|
+
* (otherwise a host reachable only through a proxy or jump host answers exec and
|
|
602
|
+
* SFTP but fails every file/Git fast path).
|
|
603
|
+
*
|
|
604
|
+
* `route` may be passed in when the caller has already resolved it and needs the
|
|
605
|
+
* decision for its own purposes (`dial` reports the egress it settled on): the
|
|
606
|
+
* default resolves it from the store.
|
|
607
|
+
*
|
|
608
|
+
* The returned `release` is IDEMPOTENT and belongs to the caller: it tears down
|
|
609
|
+
* the tunnel (destroys the proxy socket / closes the channel and gives the jump
|
|
610
|
+
* host's hold back). It must be called exactly once by whoever owns the socket —
|
|
611
|
+
* on failure, on close, and on dispose. A direct route has nothing to release,
|
|
612
|
+
* so it gets a no-op.
|
|
613
|
+
*/
|
|
614
|
+
private openRoute;
|
|
615
|
+
/**
|
|
616
|
+
* The routed transport for `alias`, for a caller that dials its OWN ssh2 client.
|
|
617
|
+
*
|
|
618
|
+
* Same decision, same error layering (`proxy auth failed: …`, `jump host "x"
|
|
619
|
+
* failed: …`), same socket as a pooled connection would ride — p2's helper
|
|
620
|
+
* transport uses this so "reachable only through the jump host" stops meaning
|
|
621
|
+
* "exec works, files do not".
|
|
622
|
+
*
|
|
623
|
+
* **The caller owns the result**: when `sock` is set, ssh2 must be given `{ sock }`
|
|
624
|
+
* and NOT `host`/`port` (both together let ssh2 choose between dialing the target
|
|
625
|
+
* itself and riding the tunnel). `release` must be called exactly once — on
|
|
626
|
+
* failure, on the connection's close, and on dispose — or the jump host's hold
|
|
627
|
+
* leaks and the proxy socket stays open.
|
|
628
|
+
*/
|
|
629
|
+
openRoutedSocket(alias: string): Promise<RoutedDial>;
|
|
395
630
|
/**
|
|
396
631
|
* Open one SSH connection, through whatever route the store resolves.
|
|
397
632
|
*
|
package/lib/types/protocol.d.ts
CHANGED
|
@@ -33,6 +33,8 @@ export declare const REMOTE_API: {
|
|
|
33
33
|
readonly viewSettings: "/api/dsh-remote/view-settings";
|
|
34
34
|
/** Profile-wide proxy default (per-host overrides live on the host rows). */
|
|
35
35
|
readonly proxySettings: "/api/dsh-remote/proxy-settings";
|
|
36
|
+
/** Live SSH pool shape per host: connections, channels, slot occupancy. */
|
|
37
|
+
readonly connections: "/api/dsh-remote/connections";
|
|
36
38
|
/** Current working directory of one live session (click resolution helper). */
|
|
37
39
|
readonly sessionCwd: "/api/dsh-remote/session-cwd";
|
|
38
40
|
/** What one live session changed on its remote host (the review panel). */
|
|
@@ -305,6 +307,100 @@ export interface RemoteConnectionStatus {
|
|
|
305
307
|
*/
|
|
306
308
|
configured?: EgressInfo;
|
|
307
309
|
}
|
|
310
|
+
/** One pool connection kind: whether it is dialed, and how many channels ride it. */
|
|
311
|
+
export interface RemotePoolLane {
|
|
312
|
+
/**
|
|
313
|
+
* The connection is fully dialed. A dial still in flight is NOT open (the pool
|
|
314
|
+
* creates its bookkeeping entry before the Client exists), and every lane is
|
|
315
|
+
* always present: a kind that is not dialed reports `false` here with zero
|
|
316
|
+
* channels and zero rounds, so "not in use" is a value, not a missing field.
|
|
317
|
+
*/
|
|
318
|
+
open: boolean;
|
|
319
|
+
/** Channels currently open on this connection (exec sessions, SFTP sessions, PTY, tunnels). */
|
|
320
|
+
channels: number;
|
|
321
|
+
/** Rounds currently pinned to it (an operation in flight keeps the connection alive). */
|
|
322
|
+
held: number;
|
|
323
|
+
}
|
|
324
|
+
/** Channel-slot occupancy of one budget: what is running and what is waiting behind it. */
|
|
325
|
+
export interface RemotePoolSlots {
|
|
326
|
+
/** Operations holding a channel right now. */
|
|
327
|
+
active: number;
|
|
328
|
+
/** Operations queued for one (they fail after a bounded wait). */
|
|
329
|
+
queued: number;
|
|
330
|
+
/** How many may run at once. */
|
|
331
|
+
limit: number;
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* Live SSH pool shape of one host.
|
|
335
|
+
*
|
|
336
|
+
* Read-only diagnostics for the monitor page: "why is this slow" is usually one
|
|
337
|
+
* of three answers — too few connections (everything shares one TCP), the channel
|
|
338
|
+
* budget is full, or a queue has built up behind a stalled operation. Each is a
|
|
339
|
+
* number here, so the page can show the answer instead of a hunch.
|
|
340
|
+
*/
|
|
341
|
+
export interface RemoteHostPoolStats {
|
|
342
|
+
alias: string;
|
|
343
|
+
/** The four connection classes the pool can hold for one host. */
|
|
344
|
+
connections: {
|
|
345
|
+
/** Everything that is not isolated: exec, git, monitor, helper, agent tools. */
|
|
346
|
+
shared: RemotePoolLane;
|
|
347
|
+
/** Interactive terminals (their own connection). */
|
|
348
|
+
pty: RemotePoolLane;
|
|
349
|
+
/** Local port forwards (their own connection). */
|
|
350
|
+
forward: RemotePoolLane;
|
|
351
|
+
/** File operations: browse, read, write, upload, download (their own connection). */
|
|
352
|
+
sftp: RemotePoolLane;
|
|
353
|
+
/**
|
|
354
|
+
* The SSH helper (p2 transport: the file/Git fast path).
|
|
355
|
+
*
|
|
356
|
+
* Optional because the helper dials from `p2/worlds.ts`, not from the pool: a
|
|
357
|
+
* Host that cannot report it (or has no helper deployed) omits the key rather
|
|
358
|
+
* than claiming "closed". When present, `channels` is the helper's own session
|
|
359
|
+
* and `held` counts the RPC calls in flight — a helper that is saturated shows
|
|
360
|
+
* up here instead of looking like an idle connection.
|
|
361
|
+
*/
|
|
362
|
+
helper?: RemotePoolLane;
|
|
363
|
+
};
|
|
364
|
+
/** Channel budget of the shared connection (exec sessions, plus SFTP that fell back). */
|
|
365
|
+
slots: RemotePoolSlots;
|
|
366
|
+
/** Channel budget of the dedicated SFTP connection (absent while it is not used). */
|
|
367
|
+
sftpSlots?: RemotePoolSlots;
|
|
368
|
+
/**
|
|
369
|
+
* Channel budget of the NETWORK-verb lane (git fetch/pull/push/sync).
|
|
370
|
+
*
|
|
371
|
+
* These verbs can hold a channel for the whole network timeout (20 minutes by
|
|
372
|
+
* default), so they get their own small budget instead of eating the shared
|
|
373
|
+
* exec slots. Absent while no network verb is running and none is queued.
|
|
374
|
+
*/
|
|
375
|
+
netSlots?: RemotePoolSlots;
|
|
376
|
+
/**
|
|
377
|
+
* Channel budget of the GIT-COMMAND lane (git status / diff / log, the session
|
|
378
|
+
* ledger's own scans, and the SCM panel's local writes such as commit / stage).
|
|
379
|
+
*
|
|
380
|
+
* A repository-wide `git status` is the longest single command the plugin runs
|
|
381
|
+
* outside the network verbs (300 s by default, 30 min at the ceiling) and it
|
|
382
|
+
* shares the connection with monitoring, the process panel and agent tools. Its
|
|
383
|
+
* own budget keeps a slow command from spending the exec slots those poll on.
|
|
384
|
+
* Absent while no git command is running and none is queued.
|
|
385
|
+
*/
|
|
386
|
+
gitSlots?: RemotePoolSlots;
|
|
387
|
+
/** Route the shared connection was opened through, when it is open. */
|
|
388
|
+
egress?: EgressInfo;
|
|
389
|
+
/**
|
|
390
|
+
* File operations are riding the SHARED connection right now, because the host
|
|
391
|
+
* refused one of its own.
|
|
392
|
+
*
|
|
393
|
+
* Sticky until a dedicated connection succeeds again or the host is edited. It
|
|
394
|
+
* is diagnostic, not an error: the files still work, they just lost the
|
|
395
|
+
* isolation (and a browse refresh can queue behind exec again), which is
|
|
396
|
+
* exactly the thing a user staring at the monitor page cannot see otherwise.
|
|
397
|
+
*/
|
|
398
|
+
sftpFallback?: boolean;
|
|
399
|
+
}
|
|
400
|
+
/** Response of {@link REMOTE_API.connections}. */
|
|
401
|
+
export interface RemotePoolStatsResult {
|
|
402
|
+
hosts: RemoteHostPoolStats[];
|
|
403
|
+
}
|
|
308
404
|
/** Remote OS probe outcome. */
|
|
309
405
|
export interface RemoteProbe {
|
|
310
406
|
alias: string;
|
|
@@ -19245,6 +19245,17 @@ var RpcConnection = class {
|
|
|
19245
19245
|
* grow host memory.
|
|
19246
19246
|
*/
|
|
19247
19247
|
stderrTail = "";
|
|
19248
|
+
/**
|
|
19249
|
+
* Teardown of the ROUTED transport this attempt rides (proxy socket / jump-host
|
|
19250
|
+
* tunnel), or undefined for a direct dial.
|
|
19251
|
+
*
|
|
19252
|
+
* It lives on the instance because the release has to outlive the handshake: the
|
|
19253
|
+
* tunnel must stay open exactly as long as the SSH connection rides it, so the
|
|
19254
|
+
* call belongs in `teardownTransport` (dispose, reconnect, failed open) rather
|
|
19255
|
+
* than in the dial promise. The pool's release is idempotent, so calling it from
|
|
19256
|
+
* a failure path AND from the teardown is safe.
|
|
19257
|
+
*/
|
|
19258
|
+
releaseRoute;
|
|
19248
19259
|
/** Per-connection in-flight cap; see MAX_IN_FLIGHT. */
|
|
19249
19260
|
gate = new InFlightGate(MAX_IN_FLIGHT);
|
|
19250
19261
|
constructor(opts) {
|
|
@@ -19258,6 +19269,17 @@ var RpcConnection = class {
|
|
|
19258
19269
|
get diagnostics() {
|
|
19259
19270
|
return this.stderrTail.trim();
|
|
19260
19271
|
}
|
|
19272
|
+
/**
|
|
19273
|
+
* How many helper calls are in flight right now.
|
|
19274
|
+
*
|
|
19275
|
+
* Read-only diagnostics for the monitor: the helper caps itself at its own
|
|
19276
|
+
* gate, so a saturated helper shows up as a number here instead of looking
|
|
19277
|
+
* like an idle connection. It is NOT a queue — a call waits inside the gate
|
|
19278
|
+
* before it counts, so this number never exceeds the gate's ceiling.
|
|
19279
|
+
*/
|
|
19280
|
+
get inFlight() {
|
|
19281
|
+
return this.gate.inFlight;
|
|
19282
|
+
}
|
|
19261
19283
|
get ready() {
|
|
19262
19284
|
if (this.readyPromise === void 0) this.readyPromise = this.open();
|
|
19263
19285
|
return this.readyPromise;
|
|
@@ -19358,9 +19380,12 @@ var RpcConnection = class {
|
|
|
19358
19380
|
this.channel = void 0;
|
|
19359
19381
|
this.conn = void 0;
|
|
19360
19382
|
this.stderrTail = "";
|
|
19383
|
+
const release = this.releaseRoute;
|
|
19384
|
+
this.releaseRoute = void 0;
|
|
19385
|
+
release?.();
|
|
19361
19386
|
}
|
|
19362
19387
|
async open() {
|
|
19363
|
-
const conn = new import_lib.Client();
|
|
19388
|
+
const conn = this.opts.makeClient?.() ?? new import_lib.Client();
|
|
19364
19389
|
this.conn = conn;
|
|
19365
19390
|
try {
|
|
19366
19391
|
const hello = await this.dialAndHello(conn);
|
|
@@ -19378,6 +19403,19 @@ var RpcConnection = class {
|
|
|
19378
19403
|
async dialAndHello(conn) {
|
|
19379
19404
|
const { entry } = this.opts;
|
|
19380
19405
|
const generation = this.generation;
|
|
19406
|
+
/**
|
|
19407
|
+
* The route the HOST resolves for this alias — a proxy tunnel socket or a
|
|
19408
|
+
* jump-host channel — or nothing for a direct connection. It is acquired
|
|
19409
|
+
* BEFORE the handshake so a route failure surfaces as itself (`proxy auth
|
|
19410
|
+
* failed: …` / `jump host "x" failed: …`) instead of as a mysterious
|
|
19411
|
+
* connection timeout.
|
|
19412
|
+
*
|
|
19413
|
+
* The release is stashed for `teardownTransport`, which runs on every way this
|
|
19414
|
+
* attempt can end (ready-then-lost, failed open, reconnect, dispose). If the
|
|
19415
|
+
* acquisition itself throws there is nothing to release.
|
|
19416
|
+
*/
|
|
19417
|
+
const routed = this.opts.openSocket === void 0 ? void 0 : await this.opts.openSocket();
|
|
19418
|
+
if (routed !== void 0) this.releaseRoute = routed.release;
|
|
19381
19419
|
await new Promise((resolve, reject) => {
|
|
19382
19420
|
let settled = false;
|
|
19383
19421
|
conn.on("ready", () => {
|
|
@@ -19400,9 +19438,12 @@ var RpcConnection = class {
|
|
|
19400
19438
|
if (generation === this.generation) this.invalidate(/* @__PURE__ */ new Error("ssh connection closed"));
|
|
19401
19439
|
});
|
|
19402
19440
|
try {
|
|
19403
|
-
|
|
19441
|
+
const transport = routed?.sock === void 0 ? {
|
|
19404
19442
|
host: entry.host,
|
|
19405
|
-
port: entry.port
|
|
19443
|
+
port: entry.port
|
|
19444
|
+
} : { sock: routed.sock };
|
|
19445
|
+
if (entry.auth.kind === "key") conn.connect({
|
|
19446
|
+
...transport,
|
|
19406
19447
|
username: entry.user,
|
|
19407
19448
|
privateKey: readFileSync(entry.auth.keyPath),
|
|
19408
19449
|
passphrase: entry.auth.passphrase,
|
|
@@ -19411,8 +19452,7 @@ var RpcConnection = class {
|
|
|
19411
19452
|
keepaliveCountMax: 3
|
|
19412
19453
|
});
|
|
19413
19454
|
else conn.connect({
|
|
19414
|
-
|
|
19415
|
-
port: entry.port,
|
|
19455
|
+
...transport,
|
|
19416
19456
|
username: entry.user,
|
|
19417
19457
|
password: entry.auth.password,
|
|
19418
19458
|
readyTimeout: CONNECT_READY_TIMEOUT_MS,
|
|
@@ -19608,6 +19648,17 @@ var RemoteWorlds = class {
|
|
|
19608
19648
|
ctx;
|
|
19609
19649
|
deps;
|
|
19610
19650
|
rpcs = /* @__PURE__ */ new Map();
|
|
19651
|
+
/**
|
|
19652
|
+
* Aliases whose helper connection is still being dialed.
|
|
19653
|
+
*
|
|
19654
|
+
* `rpcs` holds the PROMISE, so a caller that awaits it waits for the whole
|
|
19655
|
+
* dial (up to `CONNECT_READY_TIMEOUT_MS`, 45 s through a proxy or a jump host).
|
|
19656
|
+
* The monitor polls `helperLane` every few seconds and must never inherit that
|
|
19657
|
+
* wait — the route is read-only and would report the previous sample for the
|
|
19658
|
+
* whole dial, or hold the client's single-flight guard. A name in this set is
|
|
19659
|
+
* therefore "cannot say yet", which the client already renders as no row.
|
|
19660
|
+
*/
|
|
19661
|
+
dialingRpc = /* @__PURE__ */ new Map();
|
|
19611
19662
|
fsViews = /* @__PURE__ */ new Map();
|
|
19612
19663
|
fsReady = /* @__PURE__ */ new Map();
|
|
19613
19664
|
procs = /* @__PURE__ */ new Map();
|
|
@@ -19904,6 +19955,30 @@ var RemoteWorlds = class {
|
|
|
19904
19955
|
const result = await this.deps.pool.exec(alias, spillDirSweepCommand(dir, ttlDays), { timeoutMs: 2e4 });
|
|
19905
19956
|
if (!result.success) throw new Error(`remote spill dir sweep failed: ${result.stderr || result.error || `exit ${result.exitCode}`}`);
|
|
19906
19957
|
}
|
|
19958
|
+
/**
|
|
19959
|
+
* The helper connection of one alias, for the monitor's fifth lane.
|
|
19960
|
+
*
|
|
19961
|
+
* The helper dials its OWN SSH connection (see `RpcConnection`), so the pool
|
|
19962
|
+
* cannot report it — this is the only place that knows. Read-only by
|
|
19963
|
+
* contract: it awaits a record that already exists and never starts a dial, a
|
|
19964
|
+
* deploy or a reconnect, because the monitor polls this every few seconds and
|
|
19965
|
+
* a diagnostic must not be able to bring a helper up (or keep a dead one
|
|
19966
|
+
* alive). `undefined` means "cannot say": no record, a record still dialing, or
|
|
19967
|
+
* a record the router is about to replace — the client then omits the row
|
|
19968
|
+
* rather than claiming the helper is closed.
|
|
19969
|
+
*/
|
|
19970
|
+
async helperLane(alias) {
|
|
19971
|
+
if (this.dialingRpc.has(alias)) return void 0;
|
|
19972
|
+
const pending = this.rpcs.get(alias);
|
|
19973
|
+
if (pending === void 0) return void 0;
|
|
19974
|
+
const conn = await pending.catch(() => void 0);
|
|
19975
|
+
if (conn === void 0 || !conn.alive) return void 0;
|
|
19976
|
+
return {
|
|
19977
|
+
open: true,
|
|
19978
|
+
channels: 1,
|
|
19979
|
+
held: conn.inFlight
|
|
19980
|
+
};
|
|
19981
|
+
}
|
|
19907
19982
|
/** Drop one host's RPC + fs view + proc runtime (call after host update/delete). */
|
|
19908
19983
|
async dropHost(alias) {
|
|
19909
19984
|
this.fsReady.delete(alias);
|
|
@@ -20041,9 +20116,12 @@ var RemoteWorlds = class {
|
|
|
20041
20116
|
if (pending === void 0) {
|
|
20042
20117
|
pending = this.createRpc(alias);
|
|
20043
20118
|
this.rpcs.set(alias, pending);
|
|
20119
|
+
this.dialingRpc.set(alias, pending);
|
|
20044
20120
|
pending.then(() => {
|
|
20121
|
+
if (this.dialingRpc.get(alias) === pending) this.dialingRpc.delete(alias);
|
|
20045
20122
|
this.dialFailures.delete(alias);
|
|
20046
20123
|
}, (error) => {
|
|
20124
|
+
if (this.dialingRpc.get(alias) === pending) this.dialingRpc.delete(alias);
|
|
20047
20125
|
if (this.rpcs.get(alias) === pending) this.rpcs.delete(alias);
|
|
20048
20126
|
this.noteDialFailure(alias, error);
|
|
20049
20127
|
});
|
|
@@ -20119,7 +20197,8 @@ var RemoteWorlds = class {
|
|
|
20119
20197
|
helperPath,
|
|
20120
20198
|
helperHash: helper.sha256,
|
|
20121
20199
|
workspace: home,
|
|
20122
|
-
leaseMs: 6e4
|
|
20200
|
+
leaseMs: 6e4,
|
|
20201
|
+
openSocket: () => this.deps.pool.openRoutedSocket(alias)
|
|
20123
20202
|
});
|
|
20124
20203
|
try {
|
|
20125
20204
|
await conn.ready;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-remote-vs",
|
|
3
3
|
"description": "VSCode-style remote development for DSH: SSH host manager (key/password), helper deploy pipeline with version check, remote file explorer + editor + terminal in dsh-better-sidebar.",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.30.0",
|
|
5
5
|
"icon": "icon.svg",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"dsh",
|