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.
@@ -0,0 +1,359 @@
1
+ /**
2
+ * SSH connection-pool section shown on the monitor page, right under the
3
+ * process table.
4
+ *
5
+ * The pool is where "why is this slow" has an actual answer: one shared TCP
6
+ * connection per host carries exec/git/monitor traffic, terminals and port
7
+ * forwards dial their own, file operations ride a third, and each lane has a
8
+ * channel budget. When a budget is full the work QUEUES — and that is invisible
9
+ * from the file tree, where a slow listing just looks like a slow remote. So
10
+ * the page prints the four lanes, their channel counts, the slot occupancy and
11
+ * the route the shared connection took.
12
+ *
13
+ * Cost rules, the same ones the process section above follows:
14
+ * - collapsed by default; a collapsed section issues ZERO requests, because a
15
+ * closed diagnostic panel must not become the plugin's traffic source;
16
+ * - sampling happens only while the section is EXPANDED, the monitor panel is
17
+ * the visible view AND the page is in the foreground. There is no second
18
+ * throttle: the panel's own interval (and its pause control) is the cadence.
19
+ *
20
+ * Degradation: a Host that predates the route answers 404. That is not an error
21
+ * — the section keeps its header and prints ONE muted line saying so, instead of
22
+ * an error banner or an empty pool that would read as "nothing is connected".
23
+ * After it has said that it stops asking: the answer cannot change without an
24
+ * upgrade and a page reload.
25
+ */
26
+ import { useCallback, useEffect, useMemo, useRef, useState, type ReactNode } from 'react'
27
+ import type {
28
+ RemoteHostPoolStats,
29
+ RemoteHostSummary,
30
+ RemotePoolLane,
31
+ RemotePoolStatsResult,
32
+ } from '../protocol.ts'
33
+ import { api, RemoteApiError } from './api.ts'
34
+ import { egressTitleLine } from './connection.ts'
35
+ import { MiniSpinner } from './vsc/kit.tsx'
36
+
37
+ /** Fallback cadence when the panel has no interval of its own. */
38
+ export const POOL_POLL_MS = 5_000
39
+
40
+ /**
41
+ * Rounds waiting for a channel on ANY budget of one host.
42
+ *
43
+ * All three budgets are queues the user can be stuck behind, so the badge, the
44
+ * summary and the "a queue sorts first" rank count them together; which budget
45
+ * is full is the per-line detail below the lanes.
46
+ */
47
+ export function queuedOf(host: RemoteHostPoolStats): number {
48
+ return host.slots.queued + (host.sftpSlots?.queued ?? 0) + (host.netSlots?.queued ?? 0) + (host.gitSlots?.queued ?? 0)
49
+ }
50
+
51
+ /**
52
+ * Channels riding that host's lanes (the header summary's "N connections").
53
+ *
54
+ * The helper counts too: it is its own SSH connection with one channel, and a
55
+ * summary that said "0 connections" while a helper session was up would be the
56
+ * one number on the page that lies. Its lane is absent when the Host cannot
57
+ * report it, and then it contributes nothing.
58
+ */
59
+ export function channelsOf(host: RemoteHostPoolStats): number {
60
+ const lanes = host.connections
61
+ return lanes.shared.channels + lanes.pty.channels + lanes.forward.channels + lanes.sftp.channels
62
+ + (lanes.helper?.channels ?? 0)
63
+ }
64
+
65
+ /**
66
+ * Host order: the CURRENT host first, then a queue, then alias.
67
+ *
68
+ * The current host is the one the workspace is bound to, so its numbers are the
69
+ * answer to "why is what I am doing slow" — it belongs at the top even when it
70
+ * has nothing queued. Everything below keeps the rules this list was built on:
71
+ * a queued host outranks an idle one, and the rest is alias order.
72
+ *
73
+ * The host with work waiting behind a full budget is the one the user is
74
+ * looking for, so "has a queue" is the only promotion. The rank is a BOOLEAN on
75
+ * purpose: ranking by the queue DEPTH made rows swap places between polls (a
76
+ * host draining from 3 queued to 1 slid under a host at 2 — the same two hosts,
77
+ * a different order, nothing the user could have come to read). Everything else
78
+ * keeps a fixed order; the number itself is on the row's badge and in the
79
+ * summary. Aliases compare by code unit, not `localeCompare`: the order must
80
+ * not depend on the browser's locale.
81
+ */
82
+ export function sortPoolHosts(
83
+ hosts: readonly RemoteHostPoolStats[],
84
+ currentAlias = '',
85
+ ): RemoteHostPoolStats[] {
86
+ return [...hosts].sort((left, right) => {
87
+ // `currentAlias` is '' when no workspace is bound: nothing matches, so no
88
+ // host is promoted by identity (an alias is never the empty string).
89
+ const current = Number(right.alias === currentAlias) - Number(left.alias === currentAlias)
90
+ if (current !== 0) return current
91
+ const rank = Number(queuedOf(right) > 0) - Number(queuedOf(left) > 0)
92
+ if (rank !== 0) return rank
93
+ return left.alias < right.alias ? -1 : left.alias > right.alias ? 1 : 0
94
+ })
95
+ }
96
+
97
+ /**
98
+ * One connection kind: its name, dialled-or-not, and how many channels ride it.
99
+ * `egress` is passed for the shared lane only — it is the route that connection
100
+ * took, already worded by `connection.ts` — `fallback` for the file-transfer
101
+ * lane, which says the files are riding the shared connection instead of their
102
+ * own, and `inFlight` for the helper lane, whose `held` counts RPC calls inside
103
+ * the connection rather than a queue (so it is a clause, not a budget line).
104
+ */
105
+ function PoolLane(props: {
106
+ t: (key: string) => string
107
+ label: string
108
+ lane: RemotePoolLane
109
+ egress?: string | undefined
110
+ fallback?: string | undefined
111
+ inFlight?: string | undefined
112
+ }): ReactNode {
113
+ const t = props.t
114
+ return (
115
+ <div className="rvs-pool-lane">
116
+ <span className="rvs-pool-lane-name">{props.label}</span>
117
+ <span className={props.lane.open ? 'rvs-pool-lane-state open' : 'rvs-pool-lane-state'}>
118
+ {props.lane.open ? t('pool.laneOpen') : t('pool.laneClosed')}
119
+ {' · '}
120
+ {t('pool.channels').replace('{channels}', String(props.lane.channels))}
121
+ {props.inFlight !== undefined && (<>{' · '}{props.inFlight}</>)}
122
+ </span>
123
+ {props.egress !== undefined && (
124
+ <span className="rvs-pool-egress" title={props.egress}>{props.egress}</span>
125
+ )}
126
+ {props.fallback !== undefined && (
127
+ <span className="rvs-pool-fallback" title={props.fallback}>{props.fallback}</span>
128
+ )}
129
+ </div>
130
+ )
131
+ }
132
+
133
+ /** One host's pool: the four lanes, then its channel budget(s). */
134
+ function PoolHost(props: { t: (key: string) => string; host: RemoteHostPoolStats }): ReactNode {
135
+ const t = props.t
136
+ const host = props.host
137
+ const queued = queuedOf(host)
138
+ // The live route of the held shared connection, worded once by `connection.ts`
139
+ // (an absent egress means the shared connection is not dialled — say nothing
140
+ // rather than guess a route).
141
+ const egress = host.egress === undefined ? undefined : egressTitleLine({ egress: host.egress }, t)
142
+ // A host that refused its own SFTP connection still serves files, over the
143
+ // shared connection. Without this line the "file transfer: closed, 0 channels"
144
+ // row would read as "files are down", which is the opposite of the truth.
145
+ const fallback = host.sftpFallback === true ? t('pool.sftpFallback') : undefined
146
+ /**
147
+ * The SSH helper (the p2 transport: the file/Git fast path).
148
+ *
149
+ * It dials from `p2/worlds.ts`, not from the pool, so the key is OPTIONAL — a
150
+ * Host that cannot report it omits it rather than claiming "closed" — and its
151
+ * `held` counts RPC calls IN FLIGHT, not work waiting for a channel. That
152
+ * difference is load-bearing in two places:
153
+ * - it is a clause on the row (`3 calls in flight`), never a budget line: the
154
+ * helper has no channel limit to compare `active/limit` against;
155
+ * - it is NOT part of `queuedOf`, so a busy helper never paints a queue badge,
156
+ * never promotes its host in the ordering and never inflates the summary's
157
+ * queue count. A saturated helper is busy, not blocked.
158
+ */
159
+ const helper = host.connections.helper
160
+ const helperInFlight = helper === undefined || helper.held <= 0
161
+ ? undefined
162
+ : t('pool.helperInFlight').replace('{count}', String(helper.held))
163
+ return (
164
+ <div className="rvs-pool-host" role="group" aria-label={host.alias}>
165
+ <div className="rvs-pool-host-head">
166
+ <span className="rvs-pool-host-alias" title={host.alias}>{host.alias}</span>
167
+ {queued > 0 && (
168
+ <span className="rvs-pool-queue">{t('pool.queued').replace('{queued}', String(queued))}</span>
169
+ )}
170
+ </div>
171
+ <PoolLane t={t} label={t('pool.shared')} lane={host.connections.shared} egress={egress} />
172
+ <PoolLane t={t} label={t('pool.pty')} lane={host.connections.pty} />
173
+ <PoolLane t={t} label={t('pool.forward')} lane={host.connections.forward} />
174
+ <PoolLane t={t} label={t('pool.sftp')} lane={host.connections.sftp} fallback={fallback} />
175
+ {/* Fifth, and after the four pool lanes on purpose: the pool owns those,
176
+ the p2 layer owns this one, and an absent key means "no helper to
177
+ report" rather than "closed". */}
178
+ {helper !== undefined && (
179
+ <PoolLane t={t} label={t('pool.helper')} lane={helper} inFlight={helperInFlight} />
180
+ )}
181
+ <div className="rvs-pool-slots">
182
+ {t('pool.slots')
183
+ .replace('{active}', String(host.slots.active))
184
+ .replace('{limit}', String(host.slots.limit))
185
+ .replace('{queued}', String(host.slots.queued))}
186
+ </div>
187
+ {host.sftpSlots !== undefined && (
188
+ <div className="rvs-pool-slots">
189
+ {t('pool.sftpSlots')
190
+ .replace('{active}', String(host.sftpSlots.active))
191
+ .replace('{limit}', String(host.sftpSlots.limit))
192
+ .replace('{queued}', String(host.sftpSlots.queued))}
193
+ </div>
194
+ )}
195
+ {/* Network verbs (git fetch/pull/push) hold a channel for the whole network
196
+ timeout, so they have their own small budget; the line only appears while
197
+ one is running, which is also when the shared budget is NOT the thing
198
+ holding them up. */}
199
+ {host.netSlots !== undefined && (
200
+ <div className="rvs-pool-slots">
201
+ {t('pool.netSlots')
202
+ .replace('{active}', String(host.netSlots.active))
203
+ .replace('{limit}', String(host.netSlots.limit))
204
+ .replace('{queued}', String(host.netSlots.queued))}
205
+ </div>
206
+ )}
207
+ {/* Git commands (the `git status`/`diff`/`log` reads, the ledger's own
208
+ scans, and the SCM panel's local writes) take seconds on a big tree, so
209
+ they have a budget of their own rather than eating the exec slots the
210
+ monitor and agent tools need. Printed only while one is running or
211
+ waiting, like the two budgets above. */}
212
+ {host.gitSlots !== undefined && (
213
+ <div className="rvs-pool-slots">
214
+ {t('pool.gitSlots')
215
+ .replace('{active}', String(host.gitSlots.active))
216
+ .replace('{limit}', String(host.gitSlots.limit))
217
+ .replace('{queued}', String(host.gitSlots.queued))}
218
+ </div>
219
+ )}
220
+ </div>
221
+ )
222
+ }
223
+
224
+ export function ConnectionsSection(props: {
225
+ t: (key: string) => string
226
+ hosts: RemoteHostSummary[]
227
+ visible: boolean
228
+ paused: boolean
229
+ intervalMs: number
230
+ /** Alias of the host this workspace is bound to (sorted first). */
231
+ currentAlias?: string
232
+ }): ReactNode {
233
+ const t = props.t
234
+ const [expanded, setExpanded] = useState(false)
235
+ const [result, setResult] = useState<RemotePoolStatsResult | undefined>(undefined)
236
+ /** The Host answered 404: the route does not exist in this version. */
237
+ const [unsupported, setUnsupported] = useState(false)
238
+ const [error, setError] = useState<string | undefined>(undefined)
239
+ /** One request at a time: an interval tick cannot open a second channel. */
240
+ const inFlight = useRef(false)
241
+ const alive = useRef(true)
242
+
243
+ useEffect(() => {
244
+ alive.current = true
245
+ return () => { alive.current = false }
246
+ }, [])
247
+
248
+ const load = useCallback(async (): Promise<void> => {
249
+ if (inFlight.current) return
250
+ inFlight.current = true
251
+ try {
252
+ const next = await api.getPoolStats()
253
+ if (!alive.current) return
254
+ // `undefined` is the Host saying "I do not know this route" (404). Keep
255
+ // the header, say it once, and stop sampling (see the module docstring).
256
+ if (next === undefined) {
257
+ setUnsupported(true)
258
+ return
259
+ }
260
+ setResult(next)
261
+ setError(undefined)
262
+ } catch (caught) {
263
+ if (!alive.current) return
264
+ setError(caught instanceof RemoteApiError ? caught.message : String(caught))
265
+ } finally {
266
+ inFlight.current = false
267
+ }
268
+ }, [])
269
+
270
+ // The ONLY sampling sites: the immediate first sample plus the interval. Same
271
+ // guards as the process section above — expanded, panel visible, page not
272
+ // paused — and the tick itself re-checks `document.hidden`, so a background
273
+ // tab stops asking immediately instead of after the next interval.
274
+ useEffect(() => {
275
+ if (!expanded || !props.visible || props.paused || unsupported) return
276
+ const tick = (): void => {
277
+ if (document.hidden) return
278
+ void load()
279
+ }
280
+ tick()
281
+ const timer = window.setInterval(tick, Math.max(2_000, props.intervalMs || POOL_POLL_MS))
282
+ return () => window.clearInterval(timer)
283
+ }, [expanded, props.visible, props.paused, unsupported, load, props.intervalMs])
284
+
285
+ useEffect(() => {
286
+ if (!expanded || !props.visible || props.paused || unsupported) return
287
+ const onVisible = (): void => {
288
+ if (!document.hidden) void load()
289
+ }
290
+ document.addEventListener('visibilitychange', onVisible)
291
+ return () => document.removeEventListener('visibilitychange', onVisible)
292
+ }, [expanded, props.visible, props.paused, unsupported, load])
293
+
294
+ const currentAlias = props.currentAlias ?? ''
295
+ const hosts = useMemo(
296
+ () => sortPoolHosts(result?.hosts ?? [], currentAlias),
297
+ [result, currentAlias],
298
+ )
299
+ const summary = useMemo(() => {
300
+ if (result === undefined) return undefined
301
+ return {
302
+ hosts: hosts.length,
303
+ connections: hosts.reduce((total, host) => total + channelsOf(host), 0),
304
+ queued: hosts.reduce((total, host) => total + queuedOf(host), 0),
305
+ }
306
+ }, [result, hosts])
307
+
308
+ // Nothing to diagnose before the first host exists; the panel's own "no hosts"
309
+ // banner already explains the empty page.
310
+ if (props.hosts.length === 0) return null
311
+
312
+ const loading = expanded && !unsupported && error === undefined && result === undefined
313
+
314
+ return (
315
+ <section className={expanded ? 'rvs-pool expanded' : 'rvs-pool'} aria-label={t('pool.title')}>
316
+ <div className="rvs-pool-head">
317
+ <button
318
+ type="button"
319
+ className="rvs-pool-toggle"
320
+ aria-expanded={expanded}
321
+ onClick={() => { setExpanded(value => !value) }}
322
+ title={expanded ? t('pool.collapse') : t('pool.expand')}
323
+ >
324
+ <span aria-hidden="true">{expanded ? '▾' : '▸'}</span>
325
+ </button>
326
+ <span className="rvs-pool-title">{t('pool.title')}</span>
327
+ {summary !== undefined && (
328
+ // `aria-live` lives HERE, not on the list: the numbers above are one
329
+ // short sentence whose change is worth announcing (a queue appeared,
330
+ // a channel was freed), while the table below re-renders every 5 s —
331
+ // a live region around it makes a screen reader re-read every lane on
332
+ // each poll.
333
+ <span className="rvs-pool-summary" aria-live="polite">
334
+ {t('pool.summary')
335
+ .replace('{hosts}', String(summary.hosts))
336
+ .replace('{connections}', String(summary.connections))
337
+ .replace('{queued}', String(summary.queued))}
338
+ </span>
339
+ )}
340
+ </div>
341
+ {!expanded && <div className="rvs-pool-collapsed">{t('pool.collapsedHint')}</div>}
342
+ {expanded && unsupported && <div className="rvs-pool-note">{t('pool.unsupported')}</div>}
343
+ {expanded && !unsupported && error !== undefined && <div className="rvs-pool-note error">{error}</div>}
344
+ {loading && (
345
+ <div className="rvs-pool-note">
346
+ <MiniSpinner /> {t('pool.loading')}
347
+ </div>
348
+ )}
349
+ {expanded && !unsupported && result !== undefined && hosts.length === 0 && (
350
+ <div className="rvs-pool-note">{t('pool.empty')}</div>
351
+ )}
352
+ {expanded && hosts.length > 0 && (
353
+ <div className="rvs-pool-list rvs-scroll">
354
+ {hosts.map(host => <PoolHost key={host.alias} t={t} host={host} />)}
355
+ </div>
356
+ )}
357
+ </section>
358
+ )
359
+ }
@@ -31,6 +31,7 @@ import { useExplorer } from './store.tsx'
31
31
  import { optionStyle } from './ui.tsx'
32
32
  import { IconButton, IconRefresh, MiniSpinner, Segmented } from './vsc/kit.tsx'
33
33
  import { ProcessesSection } from './ProcessesSection.tsx'
34
+ import { ConnectionsSection } from './ConnectionsSection.tsx'
34
35
 
35
36
  /** Visible-panel poll cadence. The Host's own reuse window is shorter (3 s). */
36
37
  export const MONITOR_POLL_MS = 5_000
@@ -641,6 +642,19 @@ export function MonitorView(props: {
641
642
  paused={paused}
642
643
  intervalMs={intervalMs}
643
644
  />
645
+ {/* Last, and for a reason: the metrics and processes above are what the
646
+ page was opened for; the pool shape explains WHY they are slow, so it
647
+ reads as the footnote to both. Two collapsed sections stack at the
648
+ bottom of the pane; whichever one is expanded takes the leftover
649
+ height (see `.rvs-monitor-body:has(.rvs-proc.expanded)`). */}
650
+ <ConnectionsSection
651
+ t={t}
652
+ hosts={props.hosts}
653
+ visible={props.visible}
654
+ paused={paused}
655
+ intervalMs={intervalMs}
656
+ currentAlias={currentAlias}
657
+ />
644
658
  </div>
645
659
  </div>
646
660
  )
package/src/client/api.ts CHANGED
@@ -26,6 +26,7 @@ import {
26
26
  type RemoteProcessKillResult,
27
27
  type RemoteProcessesResult,
28
28
  type RemotePluginMeta,
29
+ type RemotePoolStatsResult,
29
30
  type RemoteProbe,
30
31
  type RemoteProxySettingsPatch,
31
32
  type RemoteProxySettingsView,
@@ -501,6 +502,19 @@ function afterRemoteWrite<T>(value: T): T {
501
502
  return value
502
503
  }
503
504
 
505
+ /**
506
+ * Which HOST channel budget a command spends (see `api.exec`).
507
+ *
508
+ * The host keeps three budgets on the shared connection: the default exec one,
509
+ * `network` for `git fetch/pull/push/sync` (they can hold a channel for the whole
510
+ * 20-minute network timeout) and `git` for git commands — the reads
511
+ * (`git status/diff/log` and the ledger's scans, 300 s by default) and the local
512
+ * writes (commit / stage / discard / branch verbs). Both of those used to park an
513
+ * exec slot for minutes, which is what starved the monitor, the process panel and
514
+ * the agent tools.
515
+ */
516
+ export type ExecLane = 'exec' | 'network' | 'git'
517
+
504
518
  export const api = {
505
519
  // -- hosts
506
520
  getHosts: () => call<{ hosts: RemoteHostSummary[] }>(REMOTE_API.hosts).then(r => r.hosts),
@@ -554,9 +568,27 @@ export const api = {
554
568
  * One remote command (`/exec`), foreground unless `opts.background` asks for
555
569
  * the git channel. Reads the SCM panel builds stay foreground; the
556
570
  * repository-wide walks pass `{ background: true }` (see `scm/actions.ts`).
571
+ *
572
+ * `lane` picks the HOST's channel budget, and it is a separate argument on
573
+ * purpose: `opts` is scheduling (request gate, abort) and never reaches the
574
+ * body, while this one is a body field the pool reads. `'network'` is for
575
+ * `git fetch/pull/push/sync` only — those can hold a channel for 20 minutes and
576
+ * must not spend the slots every other command waits on. Omitted means the
577
+ * shared exec budget, i.e. what all existing callers get.
557
578
  */
558
- exec: (alias: string, command: string, timeoutMs?: number, opts?: RequestOptions) =>
559
- post<RemoteExecResult>(REMOTE_API.exec, timeoutMs === undefined ? { alias, command } : { alias, command, timeoutMs }, opts)
579
+ exec: (alias: string, command: string, timeoutMs?: number, opts?: RequestOptions, lane?: ExecLane) =>
580
+ post<RemoteExecResult>(
581
+ REMOTE_API.exec,
582
+ {
583
+ alias,
584
+ command,
585
+ ...(timeoutMs === undefined ? {} : { timeoutMs }),
586
+ // `'exec'` is the host's default, so it is not sent: an older host that
587
+ // knows no `lane` field keeps its pre-existing behaviour either way.
588
+ ...(lane === undefined || lane === 'exec' ? {} : { lane }),
589
+ },
590
+ opts,
591
+ )
560
592
  .then((result) => {
561
593
  // A worktree-changing git verb (discard / checkout / stash apply …) runs
562
594
  // through here rather than `fileOp`, so it is the one place an index
@@ -571,13 +603,27 @@ export const api = {
571
603
  * command runs, and the promise settles on the `exit` frame. An aborted
572
604
  * `signal` cancels the remote process group on the host side (the route acts
573
605
  * on the closed response), so a cancel button can actually stop a push.
606
+ *
607
+ * `lane` marks the HOST budget exactly like `api.exec`'s fifth argument
608
+ * (`'network'` for fetch/pull/push, `'git'` for git commands). It is a body
609
+ * field, kept in this handlers bag because that bag IS the options object this
610
+ * call already has (a fifth positional would read as `timeoutMs`). The older
611
+ * `network: true` spelling is still accepted and means `lane: 'network'`, so a
612
+ * caller written before the third budget keeps working.
574
613
  */
575
614
  execStream: async (
576
615
  alias: string,
577
616
  command: string,
578
617
  timeoutMs: number,
579
- handlers: { onData?: (stream: 'out' | 'err', text: string) => void; signal?: AbortSignal },
618
+ handlers: {
619
+ onData?: (stream: 'out' | 'err', text: string) => void
620
+ signal?: AbortSignal
621
+ lane?: ExecLane
622
+ /** @deprecated use `lane: 'network'` */
623
+ network?: boolean
624
+ },
580
625
  ): Promise<RemoteExecResult> => {
626
+ const lane = handlers.lane ?? (handlers.network === true ? 'network' : undefined)
581
627
  // A USER-initiated verb (fetch/pull/push, its own live panel), so it is
582
628
  // foreground — but only the RESPONSE ESTABLISHMENT is claimed: the SSE body
583
629
  // streams for minutes, and holding the foreground counter for that long
@@ -586,7 +632,12 @@ export const api = {
586
632
  const response = await requestGate.runForeground(() => fetch(REMOTE_API.execStream, {
587
633
  method: 'POST',
588
634
  headers: { 'content-type': 'application/json' },
589
- body: JSON.stringify({ alias, command, timeoutMs }),
635
+ body: JSON.stringify({
636
+ alias,
637
+ command,
638
+ timeoutMs,
639
+ ...(lane === undefined || lane === 'exec' ? {} : { lane }),
640
+ }),
590
641
  ...(handlers.signal === undefined ? {} : { signal: handlers.signal }),
591
642
  }))
592
643
  if (!response.ok || response.body === null) {
@@ -792,6 +843,23 @@ export const api = {
792
843
  if (metrics === undefined) throw new RemoteApiError(502, `no metrics for ${alias}`)
793
844
  return metrics
794
845
  }),
846
+ /**
847
+ * Live SSH pool shape of every host (connections, channels, slot occupancy).
848
+ *
849
+ * A purely LOCAL read of the Host's own pool — no remote command rides it, so
850
+ * the monitor page can poll it while a section is open without spending a
851
+ * channel. `undefined` means the Host does not know the route (404, an older
852
+ * plugin): the caller degrades quietly instead of painting an error, the same
853
+ * rule `proc.hostTooOld` follows for the process panel.
854
+ */
855
+ getPoolStats: async (): Promise<RemotePoolStatsResult | undefined> => {
856
+ try {
857
+ return await call<RemotePoolStatsResult>(REMOTE_API.connections)
858
+ } catch (caught) {
859
+ if (caught instanceof RemoteApiError && caught.status === 404) return undefined
860
+ throw caught
861
+ }
862
+ },
795
863
  // -- git (over the exec route; parsed in the browser, no host changes)
796
864
  // Timeouts come from the effective setting: status/log on a huge cold tree
797
865
  // routinely exceed the old fixed 120 s, and the client deadline used to cut
@@ -846,7 +846,7 @@ const zh: Record<string, string> = {
846
846
  'changes.statusDeleted': '删除',
847
847
  'changes.statusModified': '修改',
848
848
  'changes.statusRenamed': '重命名',
849
- 'changes.truncated': '文件过多,只列出前 500 个(统计数字也只算这 500 个)。',
849
+ 'changes.truncated': '改动列表不完整:文件过多、或未跟踪目录展开受限,部分文件未列出(统计数字也只算列出的部分)。',
850
850
  'changes.excluded': '未统计构建产物目录:{dirs}',
851
851
  'changes.markReviewed': '标记为已审阅',
852
852
  'changes.unmarkReviewed': '取消审阅标记',
@@ -1047,6 +1047,31 @@ const zh: Record<string, string> = {
1047
1047
  'proc.expand': '展开进程分区',
1048
1048
  'proc.collapse': '收起进程分区',
1049
1049
  'proc.collapsedHint': '展开以查看远端的进程快照(按 CPU 排序)。',
1050
+ // SSH 连接池分区(监控页):四类连接、通道数与槽位/排队。
1051
+ // 出口文案复用 connection.egress*(describeEgress/egressTitleLine),这里不另造。
1052
+ 'pool.title': 'SSH 连接',
1053
+ 'pool.expand': '展开连接分区',
1054
+ 'pool.collapse': '收起连接分区',
1055
+ 'pool.collapsedHint': '展开以查看每台主机的连接池:共享 / 终端 / 端口转发 / 文件传输四类连接、通道数与排队。',
1056
+ 'pool.summary': '{hosts} 台 · {connections} 条连接 · 排队 {queued}',
1057
+ 'pool.shared': '共享',
1058
+ 'pool.pty': '终端',
1059
+ 'pool.forward': '端口转发',
1060
+ 'pool.sftp': '文件传输',
1061
+ 'pool.helper': 'helper 工具',
1062
+ 'pool.helperInFlight': '{count} 个调用进行中',
1063
+ 'pool.laneOpen': '开着',
1064
+ 'pool.laneClosed': '未开',
1065
+ 'pool.channels': '{channels} 通道',
1066
+ 'pool.slots': '共享通道 {active}/{limit} · 排队 {queued}',
1067
+ 'pool.sftpSlots': '文件传输通道 {active}/{limit} · 排队 {queued}',
1068
+ 'pool.netSlots': '网络命令通道 {active}/{limit} · 排队 {queued}',
1069
+ 'pool.gitSlots': 'git 命令通道 {active}/{limit} · 排队 {queued}',
1070
+ 'pool.queued': '排队 {queued}',
1071
+ 'pool.sftpFallback': '文件操作正共用共享连接(该主机拒绝了专用 SFTP 连接)',
1072
+ 'pool.unsupported': '当前 Host 版本不提供连接池统计:升级 dsh-remote-vs 后刷新即可看到。',
1073
+ 'pool.loading': '正在读取连接池…',
1074
+ 'pool.empty': '还没有主机建立连接。',
1050
1075
  }
1051
1076
 
1052
1077
  const en: Record<string, string> = {
@@ -1765,7 +1790,7 @@ const en: Record<string, string> = {
1765
1790
  'changes.statusDeleted': 'deleted',
1766
1791
  'changes.statusModified': 'modified',
1767
1792
  'changes.statusRenamed': 'renamed',
1768
- 'changes.truncated': 'Too many files: the first 500 are listed (the counts cover only those).',
1793
+ 'changes.truncated': 'This list is incomplete: too many files, or the untracked-directory expansion hit its limit, so some files are missing (the counts cover only what is listed).',
1769
1794
  'changes.excluded': 'Build output directories not counted: {dirs}',
1770
1795
  'changes.markReviewed': 'Mark as reviewed',
1771
1796
  'changes.unmarkReviewed': 'Clear the review mark',
@@ -1966,6 +1991,29 @@ const en: Record<string, string> = {
1966
1991
  'proc.expand': 'Expand processes',
1967
1992
  'proc.collapse': 'Collapse processes',
1968
1993
  'proc.collapsedHint': 'Expand for the remote process snapshot (sorted by CPU).',
1994
+ 'pool.title': 'SSH connections',
1995
+ 'pool.expand': 'Expand the connection section',
1996
+ 'pool.collapse': 'Collapse the connection section',
1997
+ 'pool.collapsedHint': 'Expand for the per-host pool: shared / terminals / port forwards / file transfer, channel counts and queues.',
1998
+ 'pool.summary': '{hosts} hosts · {connections} connections · {queued} queued',
1999
+ 'pool.shared': 'Shared',
2000
+ 'pool.pty': 'Terminals',
2001
+ 'pool.forward': 'Port forwards',
2002
+ 'pool.sftp': 'File transfer',
2003
+ 'pool.helper': 'Helper',
2004
+ 'pool.helperInFlight': '{count} calls in flight',
2005
+ 'pool.laneOpen': 'open',
2006
+ 'pool.laneClosed': 'closed',
2007
+ 'pool.channels': '{channels} ch',
2008
+ 'pool.slots': 'Shared channels {active}/{limit} · {queued} queued',
2009
+ 'pool.sftpSlots': 'File-transfer channels {active}/{limit} · {queued} queued',
2010
+ 'pool.netSlots': 'Network-verb channels {active}/{limit} · {queued} queued',
2011
+ 'pool.gitSlots': 'Git-command channels {active}/{limit} · {queued} queued',
2012
+ 'pool.queued': '{queued} queued',
2013
+ 'pool.sftpFallback': 'File operations share the main connection (this host refused its own SFTP one)',
2014
+ 'pool.unsupported': 'This Host version does not report pool statistics: upgrade dsh-remote-vs and refresh.',
2015
+ 'pool.loading': 'Reading the connection pool…',
2016
+ 'pool.empty': 'No host has opened a connection yet.',
1969
2017
  }
1970
2018
 
1971
2019
  export type Lang = 'zh' | 'en'