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/src/protocol.ts
CHANGED
|
@@ -34,6 +34,8 @@ export const REMOTE_API = {
|
|
|
34
34
|
viewSettings: '/api/dsh-remote/view-settings',
|
|
35
35
|
/** Profile-wide proxy default (per-host overrides live on the host rows). */
|
|
36
36
|
proxySettings: '/api/dsh-remote/proxy-settings',
|
|
37
|
+
/** Live SSH pool shape per host: connections, channels, slot occupancy. */
|
|
38
|
+
connections: '/api/dsh-remote/connections',
|
|
37
39
|
/** Current working directory of one live session (click resolution helper). */
|
|
38
40
|
sessionCwd: '/api/dsh-remote/session-cwd',
|
|
39
41
|
/** What one live session changed on its remote host (the review panel). */
|
|
@@ -335,6 +337,104 @@ export interface RemoteConnectionStatus {
|
|
|
335
337
|
configured?: EgressInfo
|
|
336
338
|
}
|
|
337
339
|
|
|
340
|
+
/** One pool connection kind: whether it is dialed, and how many channels ride it. */
|
|
341
|
+
export interface RemotePoolLane {
|
|
342
|
+
/**
|
|
343
|
+
* The connection is fully dialed. A dial still in flight is NOT open (the pool
|
|
344
|
+
* creates its bookkeeping entry before the Client exists), and every lane is
|
|
345
|
+
* always present: a kind that is not dialed reports `false` here with zero
|
|
346
|
+
* channels and zero rounds, so "not in use" is a value, not a missing field.
|
|
347
|
+
*/
|
|
348
|
+
open: boolean
|
|
349
|
+
/** Channels currently open on this connection (exec sessions, SFTP sessions, PTY, tunnels). */
|
|
350
|
+
channels: number
|
|
351
|
+
/** Rounds currently pinned to it (an operation in flight keeps the connection alive). */
|
|
352
|
+
held: number
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
/** Channel-slot occupancy of one budget: what is running and what is waiting behind it. */
|
|
356
|
+
export interface RemotePoolSlots {
|
|
357
|
+
/** Operations holding a channel right now. */
|
|
358
|
+
active: number
|
|
359
|
+
/** Operations queued for one (they fail after a bounded wait). */
|
|
360
|
+
queued: number
|
|
361
|
+
/** How many may run at once. */
|
|
362
|
+
limit: number
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* Live SSH pool shape of one host.
|
|
367
|
+
*
|
|
368
|
+
* Read-only diagnostics for the monitor page: "why is this slow" is usually one
|
|
369
|
+
* of three answers — too few connections (everything shares one TCP), the channel
|
|
370
|
+
* budget is full, or a queue has built up behind a stalled operation. Each is a
|
|
371
|
+
* number here, so the page can show the answer instead of a hunch.
|
|
372
|
+
*/
|
|
373
|
+
export interface RemoteHostPoolStats {
|
|
374
|
+
alias: string
|
|
375
|
+
/** The four connection classes the pool can hold for one host. */
|
|
376
|
+
connections: {
|
|
377
|
+
/** Everything that is not isolated: exec, git, monitor, helper, agent tools. */
|
|
378
|
+
shared: RemotePoolLane
|
|
379
|
+
/** Interactive terminals (their own connection). */
|
|
380
|
+
pty: RemotePoolLane
|
|
381
|
+
/** Local port forwards (their own connection). */
|
|
382
|
+
forward: RemotePoolLane
|
|
383
|
+
/** File operations: browse, read, write, upload, download (their own connection). */
|
|
384
|
+
sftp: RemotePoolLane
|
|
385
|
+
/**
|
|
386
|
+
* The SSH helper (p2 transport: the file/Git fast path).
|
|
387
|
+
*
|
|
388
|
+
* Optional because the helper dials from `p2/worlds.ts`, not from the pool: a
|
|
389
|
+
* Host that cannot report it (or has no helper deployed) omits the key rather
|
|
390
|
+
* than claiming "closed". When present, `channels` is the helper's own session
|
|
391
|
+
* and `held` counts the RPC calls in flight — a helper that is saturated shows
|
|
392
|
+
* up here instead of looking like an idle connection.
|
|
393
|
+
*/
|
|
394
|
+
helper?: RemotePoolLane
|
|
395
|
+
}
|
|
396
|
+
/** Channel budget of the shared connection (exec sessions, plus SFTP that fell back). */
|
|
397
|
+
slots: RemotePoolSlots
|
|
398
|
+
/** Channel budget of the dedicated SFTP connection (absent while it is not used). */
|
|
399
|
+
sftpSlots?: RemotePoolSlots
|
|
400
|
+
/**
|
|
401
|
+
* Channel budget of the NETWORK-verb lane (git fetch/pull/push/sync).
|
|
402
|
+
*
|
|
403
|
+
* These verbs can hold a channel for the whole network timeout (20 minutes by
|
|
404
|
+
* default), so they get their own small budget instead of eating the shared
|
|
405
|
+
* exec slots. Absent while no network verb is running and none is queued.
|
|
406
|
+
*/
|
|
407
|
+
netSlots?: RemotePoolSlots
|
|
408
|
+
/**
|
|
409
|
+
* Channel budget of the GIT-COMMAND lane (git status / diff / log, the session
|
|
410
|
+
* ledger's own scans, and the SCM panel's local writes such as commit / stage).
|
|
411
|
+
*
|
|
412
|
+
* A repository-wide `git status` is the longest single command the plugin runs
|
|
413
|
+
* outside the network verbs (300 s by default, 30 min at the ceiling) and it
|
|
414
|
+
* shares the connection with monitoring, the process panel and agent tools. Its
|
|
415
|
+
* own budget keeps a slow command from spending the exec slots those poll on.
|
|
416
|
+
* Absent while no git command is running and none is queued.
|
|
417
|
+
*/
|
|
418
|
+
gitSlots?: RemotePoolSlots
|
|
419
|
+
/** Route the shared connection was opened through, when it is open. */
|
|
420
|
+
egress?: EgressInfo
|
|
421
|
+
/**
|
|
422
|
+
* File operations are riding the SHARED connection right now, because the host
|
|
423
|
+
* refused one of its own.
|
|
424
|
+
*
|
|
425
|
+
* Sticky until a dedicated connection succeeds again or the host is edited. It
|
|
426
|
+
* is diagnostic, not an error: the files still work, they just lost the
|
|
427
|
+
* isolation (and a browse refresh can queue behind exec again), which is
|
|
428
|
+
* exactly the thing a user staring at the monitor page cannot see otherwise.
|
|
429
|
+
*/
|
|
430
|
+
sftpFallback?: boolean
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
/** Response of {@link REMOTE_API.connections}. */
|
|
434
|
+
export interface RemotePoolStatsResult {
|
|
435
|
+
hosts: RemoteHostPoolStats[]
|
|
436
|
+
}
|
|
437
|
+
|
|
338
438
|
/** Remote OS probe outcome. */
|
|
339
439
|
export interface RemoteProbe {
|
|
340
440
|
alias: string
|
package/src/routes.ts
CHANGED
|
@@ -62,6 +62,25 @@ function bodyAliasOf(value: unknown): string | null {
|
|
|
62
62
|
return typeof alias === 'string' && alias !== '' ? alias : null
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
+
/**
|
|
66
|
+
* Which channel budget an exec request asks for, from the two accepted spellings.
|
|
67
|
+
*
|
|
68
|
+
* `lane` is the current field (`'network'` for fetch/pull/push, `'git'` for git
|
|
69
|
+
* commands — reads and local writes alike) and `network: true` is the flag from
|
|
70
|
+
* before the git budget existed — kept because a browser tab can run an OLD client
|
|
71
|
+
* bundle against this host. An explicit `lane` wins when both are sent, and
|
|
72
|
+
* anything else (a typo, `'exec'`, a number) is IGNORED so a bad value can never
|
|
73
|
+
* move traffic onto a smaller budget than the caller meant.
|
|
74
|
+
*
|
|
75
|
+
* An empty object means "no lane": the command spends the shared exec budget,
|
|
76
|
+
* which is what every caller that predates the lanes gets.
|
|
77
|
+
*/
|
|
78
|
+
function execLaneOf(body: { lane?: unknown; network?: unknown }): { lane?: 'network' | 'git' } {
|
|
79
|
+
if (body.lane === 'network' || body.lane === 'git') return { lane: body.lane }
|
|
80
|
+
if (body.network === true) return { lane: 'network' }
|
|
81
|
+
return {}
|
|
82
|
+
}
|
|
83
|
+
|
|
65
84
|
/**
|
|
66
85
|
* A caller mistake the route can name: well-formed HTTP, unusable payload.
|
|
67
86
|
*
|
|
@@ -629,6 +648,41 @@ export function makeRoutes(deps: RemoteRoutesDeps): {
|
|
|
629
648
|
writeJson(res, 200, { connections: pool.status() })
|
|
630
649
|
},
|
|
631
650
|
},
|
|
651
|
+
// ------------------------------------------------------ pool shape
|
|
652
|
+
// The live pool per host: the four connection lanes, their open channels and
|
|
653
|
+
// the two channel budgets. Same contract as `status` (read-only, dial-free) —
|
|
654
|
+
// it answers "why is this slow" with numbers instead of a hunch, which is
|
|
655
|
+
// what the monitor page needs.
|
|
656
|
+
{
|
|
657
|
+
kind: 'exact',
|
|
658
|
+
path: REMOTE_API.connections,
|
|
659
|
+
handler: async (req, res) => {
|
|
660
|
+
if (!isLoopbackRequest(req)) {
|
|
661
|
+
writeJson(res, 403, { error: 'forbidden: loopback-only' })
|
|
662
|
+
return
|
|
663
|
+
}
|
|
664
|
+
if (req.method !== 'GET') {
|
|
665
|
+
writeJson(res, 405, { error: `method not allowed: ${req.method}` })
|
|
666
|
+
return
|
|
667
|
+
}
|
|
668
|
+
try {
|
|
669
|
+
const hosts = pool.stats()
|
|
670
|
+
// The helper owns the fifth lane but dials outside the pool, so its
|
|
671
|
+
// record is merged in here. A host without one keeps the key absent —
|
|
672
|
+
// "cannot say" must not read as "closed". `helperLane` never dials
|
|
673
|
+
// (see its docstring), so a monitor poll cannot bring a helper up.
|
|
674
|
+
await Promise.all(hosts.map(async host => {
|
|
675
|
+
// One host whose record misbehaves must not cost the whole page its
|
|
676
|
+
// data: the diagnostic value of the other hosts is the point.
|
|
677
|
+
const lane = await worlds.helperLane(host.alias).catch(() => undefined)
|
|
678
|
+
if (lane !== undefined) host.connections.helper = lane
|
|
679
|
+
}))
|
|
680
|
+
writeJson(res, 200, { hosts })
|
|
681
|
+
} catch (error) {
|
|
682
|
+
writeRouteError(res, error)
|
|
683
|
+
}
|
|
684
|
+
},
|
|
685
|
+
},
|
|
632
686
|
// ------------------------------------------------------------- test
|
|
633
687
|
{
|
|
634
688
|
kind: 'exact',
|
|
@@ -700,6 +754,8 @@ export function makeRoutes(deps: RemoteRoutesDeps): {
|
|
|
700
754
|
alias?: unknown
|
|
701
755
|
command?: unknown
|
|
702
756
|
timeoutMs?: unknown
|
|
757
|
+
network?: unknown
|
|
758
|
+
lane?: unknown
|
|
703
759
|
}>(req, res, { objectOnly: true })
|
|
704
760
|
if (!read.ok) return
|
|
705
761
|
const body = read.body
|
|
@@ -708,6 +764,9 @@ export function makeRoutes(deps: RemoteRoutesDeps): {
|
|
|
708
764
|
return
|
|
709
765
|
}
|
|
710
766
|
const timeoutMs = clampExecTimeout(body.timeoutMs)
|
|
767
|
+
// `lane` (network verbs / git commands) with the older `network: true`
|
|
768
|
+
// flag still honoured — see `execLaneOf`.
|
|
769
|
+
const lane = execLaneOf(body)
|
|
711
770
|
/** The client closed the request: its response is never read. */
|
|
712
771
|
let clientGone = false
|
|
713
772
|
/** The client asked to stop: kill the remote even if the read is still opening. */
|
|
@@ -740,6 +799,7 @@ export function makeRoutes(deps: RemoteRoutesDeps): {
|
|
|
740
799
|
try {
|
|
741
800
|
const result = await pool.exec(body.alias, body.command, {
|
|
742
801
|
...(timeoutMs === undefined ? {} : { timeoutMs }),
|
|
802
|
+
...lane,
|
|
743
803
|
onCancel: (handle) => {
|
|
744
804
|
cancel = handle
|
|
745
805
|
if (cancelRequested && !cancelSent) {
|
|
@@ -774,6 +834,8 @@ export function makeRoutes(deps: RemoteRoutesDeps): {
|
|
|
774
834
|
alias?: unknown
|
|
775
835
|
command?: unknown
|
|
776
836
|
timeoutMs?: unknown
|
|
837
|
+
network?: unknown
|
|
838
|
+
lane?: unknown
|
|
777
839
|
}>(req, res, { objectOnly: true })
|
|
778
840
|
if (!read.ok) return
|
|
779
841
|
const body = read.body
|
|
@@ -782,6 +844,9 @@ export function makeRoutes(deps: RemoteRoutesDeps): {
|
|
|
782
844
|
return
|
|
783
845
|
}
|
|
784
846
|
const timeoutMs = clampExecTimeout(body.timeoutMs)
|
|
847
|
+
// Same resolution as the unary route: `lane` first, `network: true` for
|
|
848
|
+
// older clients (`execLaneOf`), nothing means the exec budget.
|
|
849
|
+
const lane = execLaneOf(body)
|
|
785
850
|
res.writeHead(200, {
|
|
786
851
|
'Content-Type': 'text/event-stream; charset=utf-8',
|
|
787
852
|
'Cache-Control': 'no-cache, no-transform',
|
|
@@ -862,6 +927,7 @@ export function makeRoutes(deps: RemoteRoutesDeps): {
|
|
|
862
927
|
try {
|
|
863
928
|
const result = await pool.exec(body.alias, body.command, {
|
|
864
929
|
...(timeoutMs === undefined ? {} : { timeoutMs }),
|
|
930
|
+
...lane,
|
|
865
931
|
onData: (stream, text) => {
|
|
866
932
|
if (outputClosed || sent >= FORWARD_CAP) return
|
|
867
933
|
sent += Buffer.byteLength(text, 'utf8')
|