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
package/src/forward.ts CHANGED
@@ -45,7 +45,18 @@ const LOOPBACK = '127.0.0.1'
45
45
  * the manager never reaches into the pool beyond one call.
46
46
  */
47
47
  export interface ForwardPoolLike {
48
- forwardOut(alias: string, dstHost: string, dstPort: number, srcPort?: number): Promise<ClientChannel>
48
+ /**
49
+ * Open one direct-tcpip channel. `opts.dedicated` asks for the host's dedicated
50
+ * forward connection; the answer carries which connection was actually used, so
51
+ * the rule can SAY "shared" after a fallback instead of pretending.
52
+ */
53
+ forwardOut(
54
+ alias: string,
55
+ dstHost: string,
56
+ dstPort: number,
57
+ srcPort?: number,
58
+ opts?: { dedicated?: boolean },
59
+ ): Promise<{ channel: ClientChannel; dedicated: boolean }>
49
60
  }
50
61
 
51
62
  export interface ForwardManagerDeps {
@@ -147,6 +158,14 @@ interface Forward {
147
158
  bytesIn: number
148
159
  bytesOut: number
149
160
  lastError: string | undefined
161
+ /**
162
+ * Which SSH connection the last successful channel used.
163
+ *
164
+ * `dedicated` = the host's own forward connection (the normal case); `shared` =
165
+ * the server refused that extra connection and the channel rode the shared one.
166
+ * `undefined` until a connection has succeeded at least once (no data to show).
167
+ */
168
+ transport: 'dedicated' | 'shared' | undefined
150
169
  startedAt: number
151
170
  }
152
171
 
@@ -316,6 +335,7 @@ export class ForwardManager {
316
335
  bytesIn: 0,
317
336
  bytesOut: 0,
318
337
  lastError: undefined,
338
+ transport: undefined,
319
339
  startedAt: Date.now(),
320
340
  }
321
341
  server.on('connection', (socket) => { this.accept(forward, socket) })
@@ -384,7 +404,22 @@ export class ForwardManager {
384
404
  private async connect(forward: Forward, socket: Socket): Promise<void> {
385
405
  let channel: ClientChannel
386
406
  try {
387
- channel = await this.deps.pool.forwardOut(forward.alias, forward.remoteHost, forward.remotePort)
407
+ /**
408
+ * Ask for the host's DEDICATED forward connection: forwarding traffic is
409
+ * long-lived and heavy, and multiplexed onto the shared connection it would
410
+ * queue ahead of exec/SFTP channels. The pool falls back on its own when the
411
+ * server refuses the extra connection, and tells us which one was used so
412
+ * the row can say so.
413
+ */
414
+ const opened = await this.deps.pool.forwardOut(
415
+ forward.alias,
416
+ forward.remoteHost,
417
+ forward.remotePort,
418
+ 0,
419
+ { dedicated: true },
420
+ )
421
+ channel = opened.channel
422
+ forward.transport = opened.dedicated ? 'dedicated' : 'shared'
388
423
  } catch (error) {
389
424
  forward.lastError = messageOf(error)
390
425
  this.log('warn', `forward ${forward.id} -> ${forward.remoteHost}:${forward.remotePort} failed: ${forward.lastError}`)
@@ -469,6 +504,7 @@ export class ForwardManager {
469
504
  bytesIn: forward.bytesIn,
470
505
  bytesOut: forward.bytesOut,
471
506
  ...(forward.lastError === undefined ? {} : { lastError: forward.lastError }),
507
+ ...(forward.transport === undefined ? {} : { transport: forward.transport }),
472
508
  startedAt: forward.startedAt,
473
509
  }
474
510
  }
package/src/importers.ts CHANGED
@@ -1,15 +1,20 @@
1
1
  /**
2
2
  * One-shot importers: ~/.ssh/config and the existing dsh-ssh.json. Both only
3
3
  * READ the source and produce payloads for our own store — no runtime coupling.
4
- * P0 supports direct key/password hosts only; jump/proxy/agent entries are
5
- * reported as skipped with reasons.
4
+ * Hosts are direct key hosts; the egress half of a `Host` block (`ProxyJump` /
5
+ * `ProxyCommand`) is mapped onto the store's `proxy` field when it names
6
+ * something this import actually produces, and refused BY NAME when it names a
7
+ * form this plugin cannot dial (multi-hop, a shell command, a jump host that is
8
+ * not part of the config). A silent skip used to be the answer to all of them;
9
+ * "one hop, from this same config" is the honest boundary.
6
10
  */
7
11
  import { existsSync, readFileSync } from 'node:fs'
8
12
  import { homedir } from 'node:os'
9
13
  import { join } from 'node:path'
10
14
  import { dshHome } from './paths.ts'
11
15
  import type { HostPayload } from './store.ts'
12
- import type { ImportReport } from './protocol.ts'
16
+ import type { ImportReport, RemoteHostProxySetting } from './protocol.ts'
17
+ import { parseProxyCommand, parseProxyJump } from './proxy.ts'
13
18
 
14
19
  export interface ParsedImport {
15
20
  payloads: HostPayload[]
@@ -36,9 +41,93 @@ function validPort(value: string | number): number | undefined {
36
41
  return port
37
42
  }
38
43
 
44
+ /** One host block that WILL be imported once its egress decision is known. */
45
+ interface CandidateHost {
46
+ alias: string
47
+ hostname: string
48
+ port: number
49
+ user: string
50
+ identityFile: string
51
+ fields: Map<string, string>
52
+ }
53
+
54
+ /** What resolving one block's `ProxyJump`/`ProxyCommand` produced. */
55
+ type ProxyResolution =
56
+ | { ok: true; proxy?: RemoteHostProxySetting }
57
+ | { ok: false; reason: string }
58
+
59
+ /** `ProxyJump none` / `ProxyCommand none` is OpenSSH for "explicitly no proxy". */
60
+ function isNone(value: string): boolean {
61
+ return value.trim().toLowerCase() === 'none'
62
+ }
63
+
64
+ /**
65
+ * Index every name an imported host answers to: its alias and its `HostName`.
66
+ *
67
+ * `ProxyJump bastion` may name the `Host bastion` alias or the literal hostname
68
+ * it resolves to, so both are accepted; a name with no host behind it in THIS
69
+ * config cannot become a `viaAlias` (the stored setting would dangle).
70
+ */
71
+ function nameIndex(candidates: CandidateHost[]): Map<string, string> {
72
+ const index = new Map<string, string>()
73
+ for (const candidate of candidates) {
74
+ index.set(candidate.alias, candidate.alias)
75
+ index.set(candidate.alias.toLowerCase(), candidate.alias)
76
+ index.set(candidate.hostname, candidate.alias)
77
+ index.set(candidate.hostname.toLowerCase(), candidate.alias)
78
+ }
79
+ return index
80
+ }
81
+
82
+ /** Resolve one jump host name against the hosts this import creates. */
83
+ function resolveJump(self: string, name: string, index: Map<string, string>): ProxyResolution {
84
+ const viaAlias = index.get(name) ?? index.get(name.toLowerCase())
85
+ if (viaAlias === undefined) {
86
+ return {
87
+ ok: false,
88
+ reason: `jump host '${name}' is not imported by this config — a jump host must be one of its Host entries`,
89
+ }
90
+ }
91
+ if (viaAlias === self) return { ok: false, reason: `jump host '${name}' is this host itself` }
92
+ return { ok: true, proxy: { mode: 'jump', jump: { viaAlias } } }
93
+ }
94
+
95
+ /**
96
+ * Turn one block's egress directive into the store's proxy decision.
97
+ *
98
+ * Precedence matches OpenSSH (a set `ProxyJump` wins over `ProxyCommand`), and
99
+ * everything unusable keeps the PARSER's own reason so the report says what to
100
+ * fix ("only one hop", "not supported program") instead of a generic skip.
101
+ */
102
+ function resolveProxy(self: string, fields: Map<string, string>, index: Map<string, string>): ProxyResolution {
103
+ const jump = fields.get('proxyjump')
104
+ if (jump !== undefined) {
105
+ if (isNone(jump)) return { ok: true }
106
+ const parsed = parseProxyJump(jump)
107
+ if (!parsed.ok) return { ok: false, reason: parsed.reason }
108
+ return resolveJump(self, parsed.target.host, index)
109
+ }
110
+ const command = fields.get('proxycommand')
111
+ if (command !== undefined) {
112
+ if (isNone(command)) return { ok: true }
113
+ const plan = parseProxyCommand(command)
114
+ if (plan.kind === 'proxy') {
115
+ // The parsed plan carries no credentials on purpose: an nc/ncat command
116
+ // line may name a proxy but never its password, and guessing one would
117
+ // produce a host that fails with "the proxy rejected the credentials".
118
+ return {
119
+ ok: true,
120
+ proxy: { mode: 'proxy', proxy: { kind: plan.proxy.kind, host: plan.proxy.host, port: plan.proxy.port } },
121
+ }
122
+ }
123
+ if (plan.kind === 'jump') return resolveJump(self, plan.target.host, index)
124
+ return { ok: false, reason: plan.reason }
125
+ }
126
+ return { ok: true }
127
+ }
128
+
39
129
  /** Parse OpenSSH client config text into host payloads. */
40
130
  export function parseSshConfig(text: string): ParsedImport {
41
- const payloads: HostPayload[] = []
42
131
  const skipped: { alias: string; reason: string }[] = []
43
132
  interface Block { patterns: string[]; fields: Map<string, string> }
44
133
  const blocks: Block[] = []
@@ -67,6 +156,11 @@ export function parseSshConfig(text: string): ParsedImport {
67
156
  current.fields.set(key, value)
68
157
  }
69
158
  }
159
+ // Pass 1: which names become hosts at all. The proxy decision is resolved in
160
+ // pass 2 because `ProxyJump` may name a block that appears LATER in the file —
161
+ // and because a jump host that is itself skipped (no IdentityFile) must not be
162
+ // recorded as a live alias.
163
+ const candidates: CandidateHost[] = []
70
164
  for (const block of blocks) {
71
165
  // A `Host a b` line declares TWO names with the same fields: import each
72
166
  // concrete pattern instead of silently dropping everything after the first.
@@ -79,10 +173,6 @@ export function parseSshConfig(text: string): ParsedImport {
79
173
  if (special.length === 0) skipped.push({ alias: '(empty)', reason: 'Host line has no pattern' })
80
174
  continue
81
175
  }
82
- if (block.fields.has('proxyjump') || block.fields.has('proxycommand')) {
83
- for (const alias of concrete) skipped.push({ alias, reason: 'proxyJump/proxyCommand needs P1 (direct hosts only in P0)' })
84
- continue
85
- }
86
176
  const rawPort = block.fields.get('port')
87
177
  const port = rawPort === undefined ? 22 : validPort(rawPort)
88
178
  const identityFile = block.fields.get('identityfile')?.split(/\s+/)[0]
@@ -102,16 +192,35 @@ export function parseSshConfig(text: string): ParsedImport {
102
192
  skipped.push({ alias, reason: 'no IdentityFile in ssh_config — add the key or password after import' })
103
193
  continue
104
194
  }
105
- payloads.push({
195
+ candidates.push({
106
196
  alias,
107
- host: block.fields.get('hostname') ?? alias,
197
+ hostname: block.fields.get('hostname') ?? alias,
108
198
  port,
109
199
  user,
110
- auth: { kind: 'key', keyPath: expandHome(identityFile) },
111
- tags: ['imported:ssh-config'],
200
+ identityFile,
201
+ fields: block.fields,
112
202
  })
113
203
  }
114
204
  }
205
+ // Pass 2: the egress decision, against the names pass 1 will actually create.
206
+ const index = nameIndex(candidates)
207
+ const payloads: HostPayload[] = []
208
+ for (const candidate of candidates) {
209
+ const resolution = resolveProxy(candidate.alias, candidate.fields, index)
210
+ if (!resolution.ok) {
211
+ skipped.push({ alias: candidate.alias, reason: resolution.reason })
212
+ continue
213
+ }
214
+ payloads.push({
215
+ alias: candidate.alias,
216
+ host: candidate.hostname,
217
+ port: candidate.port,
218
+ user: candidate.user,
219
+ auth: { kind: 'key', keyPath: expandHome(candidate.identityFile) },
220
+ tags: ['imported:ssh-config'],
221
+ ...(resolution.proxy === undefined ? {} : { proxy: resolution.proxy }),
222
+ })
223
+ }
115
224
  return { payloads, skipped }
116
225
  }
117
226
 
@@ -148,7 +257,10 @@ export function migrateDshSsh(home: string = dshHome()): ParsedImport {
148
257
  continue
149
258
  }
150
259
  if (hasProxy) {
151
- skipped.push({ alias, reason: 'proxyJump/proxyCommand needs P1 (direct hosts only in P0)' })
260
+ // dsh-ssh.json stores the SAME two directives in its own shape; mapping
261
+ // them would mean a second parser with no cfg sample to verify against, so
262
+ // this path keeps refusing and says where the mapping DOES exist.
263
+ skipped.push({ alias, reason: "proxyJump/proxyCommand in dsh-ssh.json is not mapped — import from ~/.ssh/config instead" })
152
264
  continue
153
265
  }
154
266
  if (kind === 'key' && (typeof auth.keyPath !== 'string' || auth.keyPath.trim() === '')) {
package/src/keygen.ts CHANGED
@@ -117,8 +117,15 @@ export async function bootstrap(pool: RemotePool, store: RemoteStore, alias: str
117
117
  if (!result.success) {
118
118
  throw new Error(`key install failed [exit code: ${result.exitCode}]: ${result.stderr || result.stdout || result.error || 'unknown'}`)
119
119
  }
120
+ // Order matters and matches the host PATCH route: flip the entry FIRST, then
121
+ // drop the connection, so a dial racing this request cannot slip in a
122
+ // password-auth connection that nobody tears down afterwards.
120
123
  store.update(alias, { auth: { kind: 'key', keyPath: privatePath } })
121
- pool.drop(alias)
124
+ // `forget`, not `drop`: the old auth attempt's verdict ("password rejected",
125
+ // "key not installed yet") describes a credential this entry no longer uses,
126
+ // so it must not survive to colour the chip. The `test()` below records the
127
+ // new verdict against the key.
128
+ pool.forget(alias)
122
129
  // Verify the new key actually works before declaring victory.
123
130
  const check = await pool.test(alias)
124
131
  if (!check.ok) {
@@ -10,6 +10,7 @@ import { SshRpcPeer, SSH_PROTOCOL_VERSION } from '@deepseek-ai/dsh-ssh/protocol'
10
10
  import { helloSchema } from '@deepseek-ai/dsh-ssh/schemas'
11
11
  import { z } from 'zod'
12
12
  import type { RemoteHostEntry } from '../protocol.ts'
13
+ import type { RoutedDial } from '../pool.ts'
13
14
  import { InFlightGate } from './in-flight-gate.ts'
14
15
 
15
16
  export interface RpcDialOpts {
@@ -21,6 +22,26 @@ export interface RpcDialOpts {
21
22
  /** Remote default workspace for the hello handshake. */
22
23
  workspace: string
23
24
  leaseMs?: number
25
+ /**
26
+ * The HOST's routed transport for this alias (proxy tunnel / jump-host channel),
27
+ * optional so a caller without a pool still dials directly.
28
+ *
29
+ * Without it this transport is a BARE direct connection: a host reachable only
30
+ * through a proxy or jump host would answer exec/SFTP (the pool honours the
31
+ * route) and fail every file/Git fast path — the "some features work, some do
32
+ * not" report. The pool supplies it via `openRoutedSocket`; the returned
33
+ * `release` is called here (once) on failure, close, reconnect and dispose.
34
+ */
35
+ openSocket?: () => Promise<RoutedDial>
36
+ /**
37
+ * The ssh2 client factory.
38
+ *
39
+ * A seam, not a preference — the same one `RemotePool.makeClient` has: the only
40
+ * way a self-check can observe what this transport hands ssh2 (`{sock}` with no
41
+ * `host`/`port` for a routed dial, the reverse for a direct one) without a real
42
+ * server. Production never overrides it.
43
+ */
44
+ makeClient?: () => Client
24
45
  }
25
46
 
26
47
  export interface RpcHello {
@@ -174,6 +195,17 @@ export class RpcConnection {
174
195
  * grow host memory.
175
196
  */
176
197
  private stderrTail = ''
198
+ /**
199
+ * Teardown of the ROUTED transport this attempt rides (proxy socket / jump-host
200
+ * tunnel), or undefined for a direct dial.
201
+ *
202
+ * It lives on the instance because the release has to outlive the handshake: the
203
+ * tunnel must stay open exactly as long as the SSH connection rides it, so the
204
+ * call belongs in `teardownTransport` (dispose, reconnect, failed open) rather
205
+ * than in the dial promise. The pool's release is idempotent, so calling it from
206
+ * a failure path AND from the teardown is safe.
207
+ */
208
+ private releaseRoute: (() => void) | undefined
177
209
  /** Per-connection in-flight cap; see MAX_IN_FLIGHT. */
178
210
  private readonly gate = new InFlightGate(MAX_IN_FLIGHT)
179
211
 
@@ -189,6 +221,18 @@ export class RpcConnection {
189
221
  return this.stderrTail.trim()
190
222
  }
191
223
 
224
+ /**
225
+ * How many helper calls are in flight right now.
226
+ *
227
+ * Read-only diagnostics for the monitor: the helper caps itself at its own
228
+ * gate, so a saturated helper shows up as a number here instead of looking
229
+ * like an idle connection. It is NOT a queue — a call waits inside the gate
230
+ * before it counts, so this number never exceeds the gate's ceiling.
231
+ */
232
+ get inFlight(): number {
233
+ return this.gate.inFlight
234
+ }
235
+
192
236
  get ready(): Promise<RpcHello> {
193
237
  if (this.readyPromise === undefined) this.readyPromise = this.open()
194
238
  return this.readyPromise
@@ -327,10 +371,17 @@ export class RpcConnection {
327
371
  this.channel = undefined
328
372
  this.conn = undefined
329
373
  this.stderrTail = ''
374
+ // LAST: give the tunnel back after the connection riding it is closed (for a
375
+ // jump host this closes the channel and releases the hold; for a proxy it
376
+ // destroys the socket). Idempotent on the pool side, so a failure path that
377
+ // already released is fine.
378
+ const release = this.releaseRoute
379
+ this.releaseRoute = undefined
380
+ release?.()
330
381
  }
331
382
 
332
383
  private async open(): Promise<RpcHello> {
333
- const conn = new Client()
384
+ const conn = this.opts.makeClient?.() ?? new Client()
334
385
  this.conn = conn
335
386
  try {
336
387
  const hello = await this.dialAndHello(conn)
@@ -362,6 +413,19 @@ export class RpcConnection {
362
413
  // teardown is about a link nobody owns any more; the callbacks below compare
363
414
  // against the live value before touching `dead`/`stderrTail`.
364
415
  const generation = this.generation
416
+ /**
417
+ * The route the HOST resolves for this alias — a proxy tunnel socket or a
418
+ * jump-host channel — or nothing for a direct connection. It is acquired
419
+ * BEFORE the handshake so a route failure surfaces as itself (`proxy auth
420
+ * failed: …` / `jump host "x" failed: …`) instead of as a mysterious
421
+ * connection timeout.
422
+ *
423
+ * The release is stashed for `teardownTransport`, which runs on every way this
424
+ * attempt can end (ready-then-lost, failed open, reconnect, dispose). If the
425
+ * acquisition itself throws there is nothing to release.
426
+ */
427
+ const routed = this.opts.openSocket === undefined ? undefined : await this.opts.openSocket()
428
+ if (routed !== undefined) this.releaseRoute = routed.release
365
429
  await new Promise<void>((resolve, reject) => {
366
430
  let settled = false
367
431
  conn.on('ready', () => {
@@ -390,10 +454,15 @@ export class RpcConnection {
390
454
  if (generation === this.generation) this.invalidate(new Error('ssh connection closed'))
391
455
  })
392
456
  try {
457
+ // `{ sock }` and NOT `host`/`port`: a routed transport is the socket ssh2
458
+ // must ride, and passing both would let ssh2 pick between dialing the
459
+ // target itself and riding the tunnel (the same rule `pool.dial` follows).
460
+ const transport = routed?.sock === undefined
461
+ ? { host: entry.host, port: entry.port }
462
+ : { sock: routed.sock }
393
463
  if (entry.auth.kind === 'key') {
394
464
  conn.connect({
395
- host: entry.host,
396
- port: entry.port,
465
+ ...transport,
397
466
  username: entry.user,
398
467
  privateKey: readFileSync(entry.auth.keyPath as string),
399
468
  passphrase: entry.auth.passphrase,
@@ -403,8 +472,7 @@ export class RpcConnection {
403
472
  })
404
473
  } else {
405
474
  conn.connect({
406
- host: entry.host,
407
- port: entry.port,
475
+ ...transport,
408
476
  username: entry.user,
409
477
  password: entry.auth.password,
410
478
  readyTimeout: CONNECT_READY_TIMEOUT_MS,
package/src/p2/worlds.ts CHANGED
@@ -82,6 +82,17 @@ const DIAL_IMMEDIATE_RETRIES = 2
82
82
 
83
83
  export class RemoteWorlds {
84
84
  private readonly rpcs = new Map<string, Promise<RpcConnection>>()
85
+ /**
86
+ * Aliases whose helper connection is still being dialed.
87
+ *
88
+ * `rpcs` holds the PROMISE, so a caller that awaits it waits for the whole
89
+ * dial (up to `CONNECT_READY_TIMEOUT_MS`, 45 s through a proxy or a jump host).
90
+ * The monitor polls `helperLane` every few seconds and must never inherit that
91
+ * wait — the route is read-only and would report the previous sample for the
92
+ * whole dial, or hold the client's single-flight guard. A name in this set is
93
+ * therefore "cannot say yet", which the client already renders as no row.
94
+ */
95
+ private readonly dialingRpc = new Map<string, Promise<RpcConnection>>()
85
96
  private readonly fsViews = new Map<string, Promise<FsView>>()
86
97
  private readonly fsReady = new Map<string, FsView>()
87
98
  private readonly procs = new Map<string, SshProcRuntime>()
@@ -471,6 +482,30 @@ export class RemoteWorlds {
471
482
  }
472
483
  }
473
484
 
485
+ /**
486
+ * The helper connection of one alias, for the monitor's fifth lane.
487
+ *
488
+ * The helper dials its OWN SSH connection (see `RpcConnection`), so the pool
489
+ * cannot report it — this is the only place that knows. Read-only by
490
+ * contract: it awaits a record that already exists and never starts a dial, a
491
+ * deploy or a reconnect, because the monitor polls this every few seconds and
492
+ * a diagnostic must not be able to bring a helper up (or keep a dead one
493
+ * alive). `undefined` means "cannot say": no record, a record still dialing, or
494
+ * a record the router is about to replace — the client then omits the row
495
+ * rather than claiming the helper is closed.
496
+ */
497
+ async helperLane(alias: string): Promise<{ open: boolean; channels: number; held: number } | undefined> {
498
+ // A record that is still dialing is not an answer: awaiting it would make the
499
+ // monitor wait out the handshake (45 s worst case) for a read-only poll.
500
+ if (this.dialingRpc.has(alias)) return undefined
501
+ const pending = this.rpcs.get(alias)
502
+ if (pending === undefined) return undefined
503
+ const conn = await pending.catch(() => undefined)
504
+ if (conn === undefined || !conn.alive) return undefined
505
+ // One channel is the whole helper transport (exec + JSON-RPC frames).
506
+ return { open: true, channels: 1, held: conn.inFlight }
507
+ }
508
+
474
509
  /** Drop one host's RPC + fs view + proc runtime (call after host update/delete). */
475
510
  async dropHost(alias: string): Promise<void> {
476
511
  this.fsReady.delete(alias)
@@ -635,11 +670,18 @@ export class RemoteWorlds {
635
670
  if (pending === undefined) {
636
671
  pending = this.createRpc(alias)
637
672
  this.rpcs.set(alias, pending)
673
+ this.dialingRpc.set(alias, pending)
638
674
  void pending.then(
639
675
  () => {
676
+ // Identity guard: a host edit (`dropHost`) can start a SECOND dial while
677
+ // this one settles, and an unconditional delete would clear the new
678
+ // dial's mark — `helperLane` would then wait out that dial and the
679
+ // monitor would freeze for it, the exact thing this set prevents.
680
+ if (this.dialingRpc.get(alias) === pending) this.dialingRpc.delete(alias)
640
681
  this.dialFailures.delete(alias)
641
682
  },
642
683
  (error: unknown) => {
684
+ if (this.dialingRpc.get(alias) === pending) this.dialingRpc.delete(alias)
643
685
  if (this.rpcs.get(alias) === pending) this.rpcs.delete(alias)
644
686
  this.noteDialFailure(alias, error)
645
687
  },
@@ -803,6 +845,12 @@ export class RemoteWorlds {
803
845
  helperHash: helper.sha256,
804
846
  workspace: home,
805
847
  leaseMs: 60000,
848
+ // The helper dials its OWN ssh2 client, so it must be handed the route the
849
+ // pool would take (proxy tunnel / jump-host channel): without it a host
850
+ // reachable only through a hop answers exec and SFTP but fails every
851
+ // file/Git path that rides the helper. The pool owns the decision and the
852
+ // error layering; this transport releases the transport when it tears down.
853
+ openSocket: () => this.deps.pool.openRoutedSocket(alias),
806
854
  })
807
855
  try {
808
856
  await conn.ready