dsh-remote-vs 0.28.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.
Files changed (46) hide show
  1. package/README.en.md +63 -7
  2. package/README.md +51 -7
  3. package/lib/client.js +393 -112
  4. package/lib/index.js +2271 -160
  5. package/lib/p2-router-fs.js +1 -1
  6. package/lib/types/changes/recorder.d.ts +65 -10
  7. package/lib/types/changes/status.d.ts +48 -3
  8. package/lib/types/client/ConnectionsSection.d.ts +73 -0
  9. package/lib/types/client/HostsView.d.ts +139 -2
  10. package/lib/types/client/api.d.ts +65 -2
  11. package/lib/types/client/connection.d.ts +28 -1
  12. package/lib/types/client/scm/actions.d.ts +25 -1
  13. package/lib/types/forward.d.ts +11 -1
  14. package/lib/types/p2/helper-rpc.d.ts +48 -0
  15. package/lib/types/p2/worlds.d.ts +28 -0
  16. package/lib/types/pool.d.ts +337 -8
  17. package/lib/types/protocol.d.ts +218 -0
  18. package/lib/types/proxy.d.ts +136 -0
  19. package/lib/types/store.d.ts +81 -1
  20. package/lib/types/tools.d.ts +3 -0
  21. package/lib/{worlds-RG8K5eom.js → worlds-CRRZMZhg.js} +85 -6
  22. package/package.json +1 -1
  23. package/src/changes/recorder.ts +151 -15
  24. package/src/changes/status.ts +59 -4
  25. package/src/client/ConnectionStatus.tsx +19 -5
  26. package/src/client/ConnectionsSection.tsx +359 -0
  27. package/src/client/HostsView.tsx +552 -11
  28. package/src/client/MonitorView.tsx +14 -0
  29. package/src/client/PortsView.tsx +16 -0
  30. package/src/client/SettingsHosts.tsx +132 -6
  31. package/src/client/api.ts +102 -4
  32. package/src/client/connection.ts +76 -2
  33. package/src/client/i18n.ts +152 -2
  34. package/src/client/scm/actions.ts +63 -12
  35. package/src/client/vsc/vsc.css +281 -0
  36. package/src/forward.ts +38 -2
  37. package/src/importers.ts +125 -13
  38. package/src/keygen.ts +8 -1
  39. package/src/p2/helper-rpc.ts +73 -5
  40. package/src/p2/worlds.ts +48 -0
  41. package/src/pool.ts +1120 -100
  42. package/src/protocol.ts +228 -0
  43. package/src/proxy.ts +673 -0
  44. package/src/routes.ts +139 -5
  45. package/src/store.ts +335 -0
  46. package/src/tools.ts +47 -2
@@ -631,6 +631,22 @@ export function PortsView(props: {
631
631
  </div>
632
632
  {forward.lastError !== undefined && <div className="rvs-ports-err">{forward.lastError}</div>}
633
633
  <div className="rvs-ports-actions">
634
+ {/*
635
+ Which SSH connection this rule currently rides. Absent until the
636
+ first connection succeeded (nothing to say yet) and absent from
637
+ older hosts that do not publish `transport`.
638
+ */}
639
+ {forward.transport !== undefined && forward.connections > 0 && (
640
+ <span
641
+ className="rvs-ports-transport"
642
+ data-transport={forward.transport}
643
+ title={forward.transport === 'dedicated'
644
+ ? t('ports.transportDedicatedHint')
645
+ : t('ports.transportSharedHint')}
646
+ >
647
+ {forward.transport === 'dedicated' ? t('ports.transportDedicated') : t('ports.transportShared')}
648
+ </span>
649
+ )}
634
650
  <span className="rvs-ports-conn">
635
651
  {t('ports.connections').replace('{count}', String(forward.connections))}
636
652
  </span>
@@ -12,24 +12,36 @@
12
12
  * the two surfaces list the same hosts/bindings, and a workspace created here
13
13
  * used to stay invisible in the Remote tab until the whole page reloaded.
14
14
  */
15
- import { useCallback, useEffect, useState, type ReactNode } from 'react'
15
+ import { useCallback, useEffect, useId, useState, type ReactNode } from 'react'
16
16
  import type { SettingsSectionOwnerProps } from '@deepseek-ai/dsh-client-ui-settings/client'
17
17
  import {
18
18
  REMOTE_VIEW_SETTINGS_DEFAULTS,
19
19
  REMOTE_VIEW_WIDTH_MAX,
20
20
  REMOTE_VIEW_WIDTH_MIN,
21
21
  type RemoteHostSummary,
22
+ type RemoteProxySettingsPatch,
23
+ type RemoteProxySettingsView,
22
24
  type RemoteRoutingStatus,
23
25
  type RemoteViewSettings,
24
26
  type RemoteWorkspaceBinding,
25
27
  } from '../protocol.ts'
26
28
  import { RemoteApiError, api } from './api.ts'
27
- import { HostsView } from './HostsView.tsx'
29
+ import {
30
+ HostsView,
31
+ ProxyFields,
32
+ ProxySectionHeader,
33
+ defaultProxyStateOf,
34
+ proxyFormProblem,
35
+ proxySummary,
36
+ proxyTargetOf,
37
+ type ProxyChipModel,
38
+ type ProxyFormState,
39
+ } from './HostsView.tsx'
28
40
  import { refreshAll as refreshSidebarStore } from './store.tsx'
29
41
  import { loadViewSettings, saveViewSettings } from './view-settings.ts'
30
42
  import { WorkspacesView } from './WorkspacesView.tsx'
31
43
  import { detectLang, makeT } from './i18n.ts'
32
- import { Notice, Row, hairline, optionStyle, selectStyle } from './ui.tsx'
44
+ import { Btn, Notice, Row, hairline, optionStyle, selectStyle } from './ui.tsx'
33
45
 
34
46
  export function SettingsHostsSection(_props: SettingsSectionOwnerProps): ReactNode {
35
47
  const [t] = useState(() => makeT(detectLang()))
@@ -44,11 +56,23 @@ export function SettingsHostsSection(_props: SettingsSectionOwnerProps): ReactNo
44
56
  /** The width slider's live value while dragging; persisted on release. */
45
57
  const [ratio, setRatio] = useState(REMOTE_VIEW_SETTINGS_DEFAULTS.remoteWorkspaceWidthRatio)
46
58
  const [viewSaving, setViewSaving] = useState(false)
59
+ /** Profile-wide egress default (the card above the view preferences). */
60
+ const [proxySettings, setProxySettings] = useState<RemoteProxySettingsView | undefined>(undefined)
61
+ const [proxyDraft, setProxyDraft] = useState<ProxyFormState>(() => defaultProxyStateOf(undefined))
62
+ const [proxyOpen, setProxyOpen] = useState(false)
63
+ const [proxySaving, setProxySaving] = useState(false)
64
+ const [proxyError, setProxyError] = useState<string | undefined>(undefined)
65
+ const proxyPanelId = useId()
66
+ const proxyGroupName = useId()
47
67
 
48
68
  const refresh = useCallback(() => {
49
69
  setError(undefined)
50
- Promise.all([api.getHosts(), api.getWorkspaces(), loadViewSettings()]).then(
51
- ([rows, w, settings]) => {
70
+ // The proxy route is asked SEPARATELY and may fail on its own: an older Host
71
+ // answers 404 there, and that must not blank out the host list or the view
72
+ // preferences of an otherwise working page.
73
+ const loadProxy = api.getProxySettings().then(settings => settings, () => undefined)
74
+ Promise.all([api.getHosts(), api.getWorkspaces(), loadViewSettings(), loadProxy]).then(
75
+ ([rows, w, settings, proxy]) => {
52
76
  setHosts(rows)
53
77
  setMode(w.mode)
54
78
  setVersion(w.version)
@@ -56,6 +80,10 @@ export function SettingsHostsSection(_props: SettingsSectionOwnerProps): ReactNo
56
80
  setView(settings)
57
81
  setRatio(settings.remoteWorkspaceWidthRatio)
58
82
  }
83
+ if (proxy !== undefined) {
84
+ setProxySettings(proxy)
85
+ setProxyDraft(defaultProxyStateOf(proxy))
86
+ }
59
87
  },
60
88
  (e: unknown) => setError(e instanceof RemoteApiError ? e.message : String(e)),
61
89
  )
@@ -113,6 +141,47 @@ export function SettingsHostsSection(_props: SettingsSectionOwnerProps): ReactNo
113
141
  saveView({ remoteWorkspaceWidthRatio: ratio })
114
142
  }
115
143
 
144
+ /**
145
+ * Persist the profile-wide egress default.
146
+ *
147
+ * Only `target` is sent while the mode is `proxy` — switching to `direct`
148
+ * omits it so the stored endpoint (and its password) survives a flip back, and
149
+ * an empty password box omits the secret rather than clearing it.
150
+ */
151
+ const saveProxyDefault = (): void => {
152
+ const problem = proxyFormProblem(proxyDraft)
153
+ if (problem !== undefined) {
154
+ setProxyError(problem === 'target' ? t('proxy.invalidTarget') : t('proxy.invalidJump'))
155
+ return
156
+ }
157
+ setProxySaving(true)
158
+ setProxyError(undefined)
159
+ const patch: RemoteProxySettingsPatch = proxyDraft.mode === 'proxy'
160
+ ? { defaultMode: 'proxy', target: proxyTargetOf(proxyDraft) }
161
+ : { defaultMode: 'direct' }
162
+ api.patchProxySettings(patch).then(
163
+ (next) => {
164
+ setProxySettings(next)
165
+ setProxyDraft(defaultProxyStateOf(next))
166
+ },
167
+ (e: unknown) => setProxyError(
168
+ t('proxy.saveFailed').replace('{message}', e instanceof RemoteApiError ? e.message : String(e)),
169
+ ),
170
+ ).finally(() => setProxySaving(false))
171
+ }
172
+
173
+ // The collapsed chip reuses the form's own sentence, so the two surfaces can
174
+ // never disagree about how the route is WORDED — but it reads the STORED answer,
175
+ // not the draft: a chip that followed unsaved radio clicks would claim a route
176
+ // that is not in effect (the panel is where the pending edit belongs).
177
+ const proxyDefaultSummary = proxySummary(t, defaultProxyStateOf(proxySettings), undefined)
178
+ const proxyChip: ProxyChipModel = {
179
+ mode: proxyDraft.mode,
180
+ label: proxyDefaultSummary,
181
+ title: t('proxy.chipTitle').replace('{summary}', proxyDefaultSummary),
182
+ problem: false,
183
+ }
184
+
116
185
  return (
117
186
  <div style={{ padding: '4px 2px', fontSize: 13, lineHeight: 1.5 }}>
118
187
  <div style={{ ...hairline, borderTop: 'none', borderBottom: '1px solid rgba(127,127,127,.25)', marginBottom: 10, paddingBottom: 8 }}>
@@ -138,7 +207,64 @@ export function SettingsHostsSection(_props: SettingsSectionOwnerProps): ReactNo
138
207
  <div style={{ fontSize: 11, opacity: 0.6, marginTop: 4 }}>{t('route.hint')}</div>
139
208
  </div>
140
209
  {error !== undefined && <Notice kind="error">{error}</Notice>}
141
- <HostsView t={t} hosts={hosts} onChanged={reload} />
210
+ <HostsView t={t} hosts={hosts} proxyDefault={proxySettings} onChanged={reload} />
211
+ <div style={{ ...hairline, marginTop: 12, paddingTop: 10 }}>
212
+ <ProxySectionHeader
213
+ open={proxyOpen}
214
+ label={t('proxy.default.title')}
215
+ expandLabel={t('proxy.expand')}
216
+ collapseLabel={t('proxy.collapse')}
217
+ chip={proxyChip}
218
+ controls={proxyPanelId}
219
+ onToggle={() => setProxyOpen(!proxyOpen)}
220
+ />
221
+ <div id={proxyPanelId} hidden={!proxyOpen} className="rvs-proxy-panel">
222
+ <Row>
223
+ <label style={{ marginRight: 10, opacity: proxySaving ? 0.5 : 1 }}>
224
+ <input
225
+ type="radio"
226
+ name={proxyGroupName}
227
+ checked={proxyDraft.mode === 'direct'}
228
+ disabled={proxySaving}
229
+ onChange={() => { setProxyDraft({ ...proxyDraft, mode: 'direct' }); setProxyError(undefined) }}
230
+ />{' '}{t('proxy.mode.direct')}
231
+ </label>
232
+ <label style={{ opacity: proxySaving ? 0.5 : 1 }}>
233
+ <input
234
+ type="radio"
235
+ name={proxyGroupName}
236
+ checked={proxyDraft.mode === 'proxy'}
237
+ disabled={proxySaving}
238
+ onChange={() => { setProxyDraft({ ...proxyDraft, mode: 'proxy' }); setProxyError(undefined) }}
239
+ />{' '}{t('proxy.mode.proxy')}
240
+ </label>
241
+ </Row>
242
+ {proxyDraft.mode === 'proxy' && (
243
+ <ProxyFields
244
+ t={t}
245
+ state={proxyDraft}
246
+ onChange={(next) => { setProxyDraft(next); setProxyError(undefined) }}
247
+ /**
248
+ * Same rule as the host form: "leave it empty to keep it" only
249
+ * holds while the endpoint still matches the stored one.
250
+ */
251
+ storedPassword={proxySettings?.target?.hasPassword === true
252
+ && proxyDraft.kind === proxySettings.target.kind
253
+ && proxyDraft.host.trim() === proxySettings.target.host
254
+ && proxyDraft.port.trim() === String(proxySettings.target.port)
255
+ && proxyDraft.username.trim() === (proxySettings.target.username ?? '')}
256
+ disabled={proxySaving}
257
+ />
258
+ )}
259
+ <div style={{ fontSize: 11, opacity: 0.6, marginBottom: 8 }}>{t('proxy.default.hint')}</div>
260
+ <Row>
261
+ <Btn kind="primary" onClick={saveProxyDefault} disabled={proxySaving}>
262
+ {proxySaving ? t('proxy.saving') : t('proxy.save')}
263
+ </Btn>
264
+ </Row>
265
+ {proxyError !== undefined && <Notice kind="error">{proxyError}</Notice>}
266
+ </div>
267
+ </div>
142
268
  <div style={{ ...hairline, marginTop: 12, paddingTop: 10 }}>
143
269
  <div style={{ fontSize: 12, opacity: 0.75, marginBottom: 6 }}>{t('viewSettings.title')}</div>
144
270
  <Row>
package/src/client/api.ts CHANGED
@@ -19,13 +19,17 @@ import {
19
19
  type RemoteFileEntry,
20
20
  type RemoteForwardRequest,
21
21
  type RemoteForwardState,
22
+ type RemoteHostProxySetting,
22
23
  type RemoteHostSummary,
23
24
  type RemoteListenPortsResult,
24
25
  type RemoteMetricsResult,
25
26
  type RemoteProcessKillResult,
26
27
  type RemoteProcessesResult,
27
28
  type RemotePluginMeta,
29
+ type RemotePoolStatsResult,
28
30
  type RemoteProbe,
31
+ type RemoteProxySettingsPatch,
32
+ type RemoteProxySettingsView,
29
33
  type RemoteRead,
30
34
  type RemoteRoutingStatus,
31
35
  type RemoteTimeouts,
@@ -402,6 +406,14 @@ export interface HostForm {
402
406
  auth: { kind: 'key' | 'password'; keyPath?: string; passphrase?: string; password?: string }
403
407
  description?: string
404
408
  tags?: string[]
409
+ /**
410
+ * How this host reaches the network (see `RemoteHostProxySetting`).
411
+ *
412
+ * Absent means "no opinion": a create then keeps the profile default, and an
413
+ * update keeps whatever the host already had — which is what makes the field
414
+ * backward compatible with a Host that never heard of it.
415
+ */
416
+ proxy?: RemoteHostProxySetting
405
417
  }
406
418
 
407
419
  export interface PushReportView {
@@ -490,6 +502,19 @@ function afterRemoteWrite<T>(value: T): T {
490
502
  return value
491
503
  }
492
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
+
493
518
  export const api = {
494
519
  // -- hosts
495
520
  getHosts: () => call<{ hosts: RemoteHostSummary[] }>(REMOTE_API.hosts).then(r => r.hosts),
@@ -543,9 +568,27 @@ export const api = {
543
568
  * One remote command (`/exec`), foreground unless `opts.background` asks for
544
569
  * the git channel. Reads the SCM panel builds stay foreground; the
545
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.
546
578
  */
547
- exec: (alias: string, command: string, timeoutMs?: number, opts?: RequestOptions) =>
548
- 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
+ )
549
592
  .then((result) => {
550
593
  // A worktree-changing git verb (discard / checkout / stash apply …) runs
551
594
  // through here rather than `fileOp`, so it is the one place an index
@@ -560,13 +603,27 @@ export const api = {
560
603
  * command runs, and the promise settles on the `exit` frame. An aborted
561
604
  * `signal` cancels the remote process group on the host side (the route acts
562
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.
563
613
  */
564
614
  execStream: async (
565
615
  alias: string,
566
616
  command: string,
567
617
  timeoutMs: number,
568
- 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
+ },
569
625
  ): Promise<RemoteExecResult> => {
626
+ const lane = handlers.lane ?? (handlers.network === true ? 'network' : undefined)
570
627
  // A USER-initiated verb (fetch/pull/push, its own live panel), so it is
571
628
  // foreground — but only the RESPONSE ESTABLISHMENT is claimed: the SSE body
572
629
  // streams for minutes, and holding the foreground counter for that long
@@ -575,7 +632,12 @@ export const api = {
575
632
  const response = await requestGate.runForeground(() => fetch(REMOTE_API.execStream, {
576
633
  method: 'POST',
577
634
  headers: { 'content-type': 'application/json' },
578
- body: JSON.stringify({ alias, command, timeoutMs }),
635
+ body: JSON.stringify({
636
+ alias,
637
+ command,
638
+ timeoutMs,
639
+ ...(lane === undefined || lane === 'exec' ? {} : { lane }),
640
+ }),
579
641
  ...(handlers.signal === undefined ? {} : { signal: handlers.signal }),
580
642
  }))
581
643
  if (!response.ok || response.body === null) {
@@ -693,6 +755,25 @@ export const api = {
693
755
  /** Flat patch: unknown keys are ignored, unusable values keep the stored one. */
694
756
  setViewSettings: (patch: Partial<RemoteViewSettings>) =>
695
757
  post<{ settings: RemoteViewSettings }>(REMOTE_API.viewSettings, patch).then((r) => r.settings),
758
+ // -- profile-wide egress default (per-host overrides live on the host rows)
759
+ /**
760
+ * The default egress every `mode: 'inherit'` host follows.
761
+ *
762
+ * Answers the DEFAULTS on a fresh profile (`direct`), and a Host too old to
763
+ * know the route answers 404 — callers treat that as "direct" and keep the
764
+ * per-host form working (see `proxySummary`).
765
+ */
766
+ getProxySettings: () =>
767
+ call<{ settings: RemoteProxySettingsView }>(REMOTE_API.proxySettings).then((r) => r.settings),
768
+ /**
769
+ * Patch the default egress.
770
+ *
771
+ * `target: null` clears the stored endpoint; omitting it keeps the stored one
772
+ * (so flipping to `direct` and back does not lose the address), and an empty
773
+ * password keeps the stored secret — the browser never sees it.
774
+ */
775
+ patchProxySettings: (patch: RemoteProxySettingsPatch) =>
776
+ post<{ settings: RemoteProxySettingsView }>(REMOTE_API.proxySettings, patch).then((r) => r.settings),
696
777
  // -- deploy
697
778
  deployStatus: (alias: string) =>
698
779
  call<{ deploy: RemoteDeployState; helpers: HelperAvailability[] }>(
@@ -762,6 +843,23 @@ export const api = {
762
843
  if (metrics === undefined) throw new RemoteApiError(502, `no metrics for ${alias}`)
763
844
  return metrics
764
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
+ },
765
863
  // -- git (over the exec route; parsed in the browser, no host changes)
766
864
  // Timeouts come from the effective setting: status/log on a huge cold tree
767
865
  // routinely exceed the old fixed 120 s, and the client deadline used to cut
@@ -14,7 +14,7 @@
14
14
  * idle minutes, and the next operation dials again.
15
15
  */
16
16
  import { useSyncExternalStore } from 'react'
17
- import type { RemoteConnectionStatus } from '../protocol.ts'
17
+ import type { EgressInfo, RemoteConnectionStatus } from '../protocol.ts'
18
18
 
19
19
  export type ConnectionState = 'ok' | 'error' | 'idle'
20
20
 
@@ -59,6 +59,51 @@ export function connectionLabelKey(state: ConnectionState): string {
59
59
  return 'connection.idle'
60
60
  }
61
61
 
62
+ /**
63
+ * One route, as the localized sentence fragment the chip prints.
64
+ *
65
+ * Pure and exported so the jsdom gate can pin the copy without a browser and the
66
+ * three route kinds cannot drift into three different wordings. The Host sends
67
+ * the hop (`host:port` / the jump alias), never a sentence: the wording is UI
68
+ * copy and has to exist in both languages.
69
+ */
70
+ export function describeEgress(egress: EgressInfo, t: (key: string) => string): string {
71
+ if (egress.kind === 'jump') return t('connection.egressJump').replace('{jump}', egress.viaAlias ?? egress.detail)
72
+ if (egress.kind === 'proxy') {
73
+ const template = egress.proxyKind === 'socks5' ? t('connection.egressSocks5') : t('connection.egressHttp')
74
+ return template.replace('{proxy}', egress.detail)
75
+ }
76
+ return t('connection.egressDirect').replace('{target}', egress.detail)
77
+ }
78
+
79
+ /**
80
+ * The tooltip line that answers "did this really go through the jump host?".
81
+ *
82
+ * The ACTUAL egress of the live connection wins. With nothing dialed the
83
+ * CONFIGURED route is shown and LABELLED as such, so a configuration can never
84
+ * be read as evidence about a connection — that distinction is the whole point
85
+ * (a host edited to use a jump host keeps serving on its old direct link until
86
+ * the old connection is dropped). A configured route that cannot be used says
87
+ * why instead of reading healthy.
88
+ */
89
+ export function egressTitleLine(
90
+ connection: Pick<ConnectionView, 'egress' | 'configured'>,
91
+ t: (key: string) => string,
92
+ ): string | undefined {
93
+ if (connection.egress !== undefined) {
94
+ return t('connection.egress').replace('{egress}', describeEgress(connection.egress, t))
95
+ }
96
+ const configured = connection.configured
97
+ if (configured === undefined) return undefined
98
+ const line = t('connection.egressConfigured').replace('{egress}', describeEgress(configured, t))
99
+ return configured.problem === undefined
100
+ ? line
101
+ : // No separator space here: the two copies carry their own (zh uses a
102
+ // full-width bracket, en a leading space), so the punctuation stays right
103
+ // in both languages.
104
+ `${line}${t('connection.egressProblem').replace('{problem}', configured.problem)}`
105
+ }
106
+
62
107
  /** What the UI renders for one alias. */
63
108
  export interface ConnectionView {
64
109
  alias: string
@@ -71,6 +116,13 @@ export interface ConnectionView {
71
116
  okAt?: number
72
117
  /** A pooled SSH connection is open right now (diagnostic detail only). */
73
118
  open: boolean
119
+ /**
120
+ * The route the LIVE connection was opened through. Evidence, not intention:
121
+ * it is what the Host's pool reports for the connection it is holding.
122
+ */
123
+ egress?: EgressInfo
124
+ /** The route the stored configuration resolves to (no live connection). */
125
+ configured?: EgressInfo
74
126
  /**
75
127
  * Client time of the last locally noted failure. A poll that still reports
76
128
  * the older success must not clear an error the page just saw.
@@ -125,12 +177,28 @@ function refreshSnapshot(): void {
125
177
  || (next !== undefined && snapshot !== undefined
126
178
  && next.alias === snapshot.alias && next.state === snapshot.state
127
179
  && next.error === snapshot.error && next.errorAt === snapshot.errorAt
128
- && next.okAt === snapshot.okAt && next.open === snapshot.open && next.notedAt === snapshot.notedAt)
180
+ && next.okAt === snapshot.okAt && next.open === snapshot.open && next.notedAt === snapshot.notedAt
181
+ && sameEgress(next.egress, snapshot.egress) && sameEgress(next.configured, snapshot.configured))
129
182
  if (same) return
130
183
  snapshot = next
131
184
  notify()
132
185
  }
133
186
 
187
+ /**
188
+ * Field-wise equality for one reported route.
189
+ *
190
+ * The Host re-sends the object on every poll and this module rebuilds the view,
191
+ * so identity says nothing: a fresh-but-equal egress must not wake subscribers
192
+ * (that would repaint the whole surface every 5 s), while a real change — the
193
+ * route the connection took — must.
194
+ */
195
+ function sameEgress(a: EgressInfo | undefined, b: EgressInfo | undefined): boolean {
196
+ if (a === b) return true
197
+ if (a === undefined || b === undefined) return false
198
+ return a.kind === b.kind && a.detail === b.detail && a.viaAlias === b.viaAlias
199
+ && a.source === b.source && a.proxyKind === b.proxyKind && a.problem === b.problem
200
+ }
201
+
134
202
  /** Point the view at the workspace the user is looking at. */
135
203
  export function setActiveConnectionAlias(alias: string): void {
136
204
  if (alias === activeAlias) return
@@ -166,6 +234,8 @@ export function applyConnectionStatuses(list: readonly RemoteConnectionStatus[])
166
234
  ...(item.errorAt === undefined ? {} : { errorAt: item.errorAt }),
167
235
  ...(item.okAt === undefined ? {} : { okAt: item.okAt }),
168
236
  open: item.open,
237
+ ...(item.egress === undefined ? {} : { egress: item.egress }),
238
+ ...(item.configured === undefined ? {} : { configured: item.configured }),
169
239
  })
170
240
  }
171
241
  refreshSnapshot()
@@ -186,6 +256,10 @@ export function noteConnectionFailure(alias: string, error: unknown): void {
186
256
  errorAt: Date.now(),
187
257
  ...(prev?.okAt === undefined ? {} : { okAt: prev.okAt }),
188
258
  open: prev?.open ?? false,
259
+ // The route the DEAD connection used is not carried over (it is evidence
260
+ // about a link that just failed); the configured route still describes what
261
+ // the next attempt will take, so it stays until the Host answers.
262
+ ...(prev?.configured === undefined ? {} : { configured: prev.configured }),
189
263
  notedAt: Date.now(),
190
264
  })
191
265
  refreshSnapshot()