Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.
TypeScript adhdagent-orchestrationai-agentscanvasclaude-codecodexcoding-agentsdeveloper-toolselectrongeminilinuxmacosmultiplexeropencodeparallel-agentsterminalterminal-emulatorterminal-multiplexertmuxworkspace-manager
fix(ssh): fire the tunnel-verified hook after the entry is written, so the resync has a remote $HOME
enes5b3b9d57e4a0
diff --git a/src/main/remote-ssh/ssh-project.test.ts b/src/main/remote-ssh/ssh-project.test.tsindex 3cd285e11..989c5d9ed 100644--- a/src/main/remote-ssh/ssh-project.test.ts+++ b/src/main/remote-ssh/ssh-project.test.ts@@ -805,6 +805,22 @@ describe('SshProjectManager', () => {expect(onTunnelVerified).toHaveBeenCalledWith('p1', controlPathFor('p1'), conn)})+ it('fires only once the project entry is written — the resync needs the cached remote $HOME', async () => {+ // Ordering, not decoration. The resync's transcript leg resolves the host's transcript root+ // through `remoteHomeForControlPath`, and that reads the field off the project entry — which+ // is created at master spawn WITHOUT it. Firing before the entry update therefore handed the+ // locator `undefined` every single time, not occasionally. That leg is the only one that can+ // tell "the CLI still owns the pane but the turn ended" (a finished Claude sitting at its+ // prompt) from "still working"; without it the feature degrades to catching an exited CLI.+ let mgr: SshProjectManager | undefined+ let homeAtHookTime: string | undefined | 'hook-never-fired' = 'hook-never-fired'+ mgr = makeVerifiedMgr((_projectId, controlPath) => {+ homeAtHookTime = mgr?.remoteHomeForControlPath(controlPath)+ })+ await mgr.connect('p1', conn, '/remote/cwd')+ expect(homeAtHookTime).toBe('/home/u')+ })+it('does NOT fire on the reuse branch — a live master never lost its tunnel', async () => {const onTunnelVerified = vi.fn()const mgr = makeVerifiedMgr(onTunnelVerified)diff --git a/src/main/remote-ssh/ssh-project.ts b/src/main/remote-ssh/ssh-project.tsindex 162ace2a6..5fd122301 100644--- a/src/main/remote-ssh/ssh-project.ts+++ b/src/main/remote-ssh/ssh-project.ts@@ -525,22 +525,6 @@ export class SshProjectManager {continue}const hookEndpointPath = res?.endpointPath- // The tunnel is live again on a master we just established (the reuse branch returned long- // before this line), so this is exactly the moment the hook events lost while it was down- // can be reconstructed from the host. Fire-and-forget: the resync runs several remote round- // trips and must never delay (or fail) the connect that is already reporting `connected`.- // The try/catch is the contract, not politeness: what this hook drives will grow, and a- // throw inside it would surface to the user as a dead SSH project — the connect fails, the- // entry is left half-built, and the reason is a repair job that was only ever best-effort.- // A resync must never cost the user the connection that is already reporting `connected`.- // (`onStatus` above carries the same guard for the same hard-won reason.) Do not tidy away.- if (hookEndpointPath) {- try {- this.r.onTunnelVerified?.(projectId, controlPath, conn)- } catch {- // undecided changes nothing: the stale sweep remains the backstop, as before this hook- }- }// Resolve the remote $HOME once and retain it (the hook setup above also learns it but// doesn't surface it). Phase 2b uses it to jail remote transcript reads. Fail-open: an// unresolved home just disables the remote context meter / subagent transcript / search.@@ -599,6 +583,34 @@ export class SshProjectManager {entry.remoteHome = remoteHomeentry.tmuxConfPath = tmuxConfPaththis.r.onStatus({ projectId, status: 'connected' })+ // The tunnel is live again on a master we just established (the reuse branch returned long+ // before this line), so this is exactly the moment the hook events lost while it was down+ // can be reconstructed from the host.+ //+ // Position is load-bearing, and it is HERE rather than beside `setup()` for three reasons.+ // (1) The resync's transcript leg resolves the host's transcript root through+ // `remoteHomeForControlPath`, which reads `entry.remoteHome` — written one line above.+ // Firing before that left the locator without a remote $HOME on EVERY connect (the entry+ // is created at master spawn without the field), and that leg is the only one that can+ // tell a finished agent sitting at its prompt from one still working. (2) It is past the+ // ownership check, so a superseded attempt no longer resyncs against an entry it does not+ // own. (3) It stays inside `if (hookEndpointPath)`, so a tunnel that failed verification+ // still never fires it — there would be nothing to reconstruct through.+ //+ // Fire-and-forget: the resync runs several remote round trips and must never delay (or+ // fail) the connect that is already reporting `connected`. The try/catch is the contract,+ // not politeness: what this hook drives will grow, and a throw inside it would surface to+ // the user as a dead SSH project — the connect fails, the entry is left half-built, and+ // the reason is a repair job that was only ever best-effort. A resync must never cost the+ // user the connection that is already reporting `connected`. (`onStatus` above carries the+ // same guard for the same hard-won reason.) Do not tidy away.+ if (hookEndpointPath) {+ try {+ this.r.onTunnelVerified?.(projectId, controlPath, conn)+ } catch {+ // undecided changes nothing: the stale sweep remains the backstop, as before this hook+ }+ }}// Probe the REMOTE claude CLI once per connect, `--permission-mode auto` only exists in// >= 2.1.71 and the host's CLI may be older than the local one. NOT awaited: the answer is