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(relay): surface the phone's approval prompt again — no device could ever be pinned (#372)
enes5d051e868c92
diff --git a/src/main/remote/host-service.ts b/src/main/remote/host-service.tsindex 21a529998..a1c535517 100644--- a/src/main/remote/host-service.ts+++ b/src/main/remote/host-service.ts@@ -888,6 +888,7 @@ export function initRemoteHost(// phone host, and a single "Approve" click broadcasts to both listeners — so each acts only on// an event carrying ITS OWN pending id, never on one meant for the other host.let pendingApprovalId: string | null = null+ let pendingApprovalPub: string | null = nullfunction send(channel: string, ...args: unknown[]): void {if (!win.isDestroyed()) win.webContents.send(channel, ...args)@@ -947,11 +948,17 @@ export function initRemoteHost(// and appears in the facepile only — see docs/team-presence.md ("Peers may have no cursor").phone.join()pendingApprovalId = randomUUID()- send(IPC.remoteHostPeerPending, { sas: s.sas(), id: pendingApprovalId })+ pendingApprovalPub = s.peerPublicKeyB64()+ send(IPC.remoteHostPeerPending, {+ sas: s.sas(),+ id: pendingApprovalId,+ pub: pendingApprovalPub+ })},onClose: () => {phone.leave()pendingApprovalId = null+ pendingApprovalPub = null}})@@ -967,15 +974,23 @@ export function initRemoteHost(// Host human approved the pending device → start serving its pty/fs RPCs. Only act on a// still-pending session: the approve/reject channels are shared with the standing phone host,// so an event meant for the phone must not disturb an already-approved interactive session.- ipcMain.on(IPC.remoteHostApprove, (_e, msg: { id?: string } = {}) => {- if (!pendingApprovalId || msg?.id !== pendingApprovalId) return+ ipcMain.on(IPC.remoteHostApprove, (_e, msg: { id?: string; pub?: string } = {}) => {+ const matched =+ (pendingApprovalId && msg?.id === pendingApprovalId) ||+ (pendingApprovalPub && msg?.pub === pendingApprovalPub)+ if (!matched) returnpendingApprovalId = null+ pendingApprovalPub = nullif (session && !session.isApproved()) session.approve()})// Host human rejected the pending device → drop the connection entirely (pending sessions only).- ipcMain.on(IPC.remoteHostReject, (_e, msg: { id?: string } = {}) => {- if (!pendingApprovalId || msg?.id !== pendingApprovalId) return+ ipcMain.on(IPC.remoteHostReject, (_e, msg: { id?: string; pub?: string } = {}) => {+ const matched =+ (pendingApprovalId && msg?.id === pendingApprovalId) ||+ (pendingApprovalPub && msg?.pub === pendingApprovalPub)+ if (!matched) returnpendingApprovalId = null+ pendingApprovalPub = nullif (session && !session.isApproved()) endSession()})diff --git a/src/main/remote/standing-host.ts b/src/main/remote/standing-host.tsindex 8f3300b5c..6db4a99b8 100644--- a/src/main/remote/standing-host.ts+++ b/src/main/remote/standing-host.ts@@ -197,9 +197,12 @@ export function initStandingHost(p.session.close()}- function findByApprovalId(id: string | undefined): Pooled | null {- if (!id) return null- for (const p of pool) if (p.approvalId === id) return p+ // The peer's box key is STABLE across the phone's reconnect churn while the per-attach id+ // dies with each socket, so an Approve clicked mid-retry still lands when matched by pub+ // (issue #372's race note). The id stays as the exact-match fallback.+ function findPending(msg: { id?: string; pub?: string }): Pooled | null {+ if (msg.pub) for (const p of pool) if (p.approvalPub && p.approvalPub === msg.pub) return p+ if (msg.id) for (const p of pool) if (p.approvalId && p.approvalId === msg.id) return preturn null}@@ -269,12 +272,19 @@ export function initStandingHost(pooled.approvalId = randomUUID()if (pooled.approvalTimer) clearTimeout(pooled.approvalTimer)pooled.approvalTimer = setTimeout(() => {+ const expiredId = pooled.approvalIdpooled.approvalPub = nullpooled.approvalId = nullpooled.approvalTimer = null+ // Tell the renderer the prompt died — without this the dialog outlives the id and+ // Approve becomes a silent no-op (issue #372).+ send(IPC.remoteHostPeerPendingCleared, { id: expiredId, pub })}, 120_000)pooled.approvalTimer.unref?.()- send(IPC.remoteHostPeerPending, { sas: s.sas(), id: pooled.approvalId })+ // `pub` rides along so the renderer can key the dialog on the STABLE device identity: a+ // retry-churning phone re-raises this event with a fresh id but the same pub + SAS, and+ // the open dialog just updates in place instead of flashing.+ send(IPC.remoteHostPeerPending, { sas: s.sas(), id: pooled.approvalId, pub })}async function connectOne(): Promise<void> {@@ -388,8 +398,8 @@ export function initStandingHost(// Host human approved / rejected a pending phone (by its pending id). Shared with the interactive// host; the id scoping means each acts only on its own pending session.- ipcMain.on(IPC.remoteHostApprove, (_e, msg: { id?: string } = {}) => {- const p = findByApprovalId(msg?.id)+ ipcMain.on(IPC.remoteHostApprove, (_e, msg: { id?: string; pub?: string } = {}) => {+ const p = findPending(msg ?? {})if (!p) return// Pin the DEVICE (its stable box key), whether or not its session is still live — the phone's// browse socket may have already closed. Prefer the live peer's key, else the remembered one.@@ -404,8 +414,8 @@ export function initStandingHost(}p.session.approve()})- ipcMain.on(IPC.remoteHostReject, (_e, msg: { id?: string } = {}) => {- const p = findByApprovalId(msg?.id)+ ipcMain.on(IPC.remoteHostReject, (_e, msg: { id?: string; pub?: string } = {}) => {+ const p = findPending(msg ?? {})if (!p) returnremoveFromPool(p) // drop this rejected sessionensurePool()diff --git a/src/preload/index.ts b/src/preload/index.tsindex 237c9890c..cf533db69 100644--- a/src/preload/index.ts+++ b/src/preload/index.ts@@ -47,7 +47,12 @@ function subscribe<A extends unknown[] = []>(channel: string) {const subscribeMutation = subscribe<[CanvasMutation]>(IPC.remoteHostApplyMutation)// Fan-out subscriber for the connection-approval prompt (main → host renderer when a client// finishes the handshake; carries the SAS to show in the approval dialog).-const subscribePeerPending = subscribe<[{ sas: string | null; id: string }]>(IPC.remoteHostPeerPending)+const subscribePeerPending = subscribe<[{ sas: string | null; id: string; pub?: string | null }]>(+ IPC.remoteHostPeerPending+)+const subscribePeerPendingCleared = subscribe<[{ id: string | null; pub?: string | null }]>(+ IPC.remoteHostPeerPendingCleared+)// New relay tunnel (Stage 4). Non-per-id host events reuse the fan-out helper; per-connection// client events (sas/approved/frame/closed) attach directly per connectionId.@@ -562,8 +567,9 @@ const api: NodeTerminalApi = {sendCanvasState: (state) => ipcRenderer.send(IPC.remoteHostCanvasState, state),onApplyMutation: subscribeMutation,onPeerPending: subscribePeerPending,- approve: (id: string) => ipcRenderer.send(IPC.remoteHostApprove, { id }),- reject: (id: string) => ipcRenderer.send(IPC.remoteHostReject, { id }),+ onPeerPendingCleared: subscribePeerPendingCleared,+ approve: (id: string, pub?: string) => ipcRenderer.send(IPC.remoteHostApprove, { id, pub }),+ reject: (id: string, pub?: string) => ipcRenderer.send(IPC.remoteHostReject, { id, pub }),setPhoneAccess: (enabled) => ipcRenderer.send(IPC.remoteStandingHostSet, enabled)},relayHost: {diff --git a/src/renderer/bridge/stubs.ts b/src/renderer/bridge/stubs.tsindex 02c16bc6d..5d3b67553 100644--- a/src/renderer/bridge/stubs.ts+++ b/src/renderer/bridge/stubs.ts@@ -360,6 +360,7 @@ export function buildStubApi(): Omit<sendCanvasState: noop,onApplyMutation: noopUnsub,onPeerPending: noopUnsub,+ onPeerPendingCleared: noopUnsub,approve: (_id: string) => {},reject: (_id: string) => {},setPhoneAccess: noopdiff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsxindex 3dbe804e7..b13ffb602 100644--- a/src/renderer/canvas/Canvas.tsx+++ b/src/renderer/canvas/Canvas.tsx@@ -533,6 +533,14 @@ interface PendingPeerState {/** Human-facing peer name, if the tunnel carries one. The relay `RelayPeerPending` payload does* not yet, so this is undefined → the ConsentNotice falls back to a generic subject. */label?: string+ /** Which host raised it: the new relay tunnel (confirm via relayHost) or the legacy+ * standing/interactive phone host (approve/reject via remoteHost). Issue #372: the phone+ * source lost its dialog when the SAS prompt migrated to relayHost while iOS still speaks+ * the legacy dialect — both sources feed this ONE dialog until that migration lands. */+ source: 'relay' | 'phone'+ /** The peer's stable box key (phone source): survives the phone's reconnect churn where the+ * per-attach id does not, so a mid-retry Approve still lands. */+ pub?: string | null}/**@@ -2372,8 +2380,34 @@ export function Canvas() {// (docs/ios-protocol-migration.md) and Task 10 deletes the `remoteHost` dialect outright. So we// fully migrate rather than keep both sources alive (which would only complicate that removal).useEffect(() => {- return window.nodeTerminal.relayHost.onPeerPending((info) => setPendingPeer(info))- }, [])+ return window.nodeTerminal.relayHost.onPeerPending((info) =>+ setPendingPeer({ ...info, source: 'relay' })+ )+ }, [setPendingPeer])++ // The LEGACY phone host feeds the SAME dialog (issue #372): when the SAS prompt migrated to+ // the relayHost tunnel, the phone — still on the legacy dialect — lost its prompt entirely:+ // `remoteHostPeerPending` was emitted into the void, approve() became unreachable, and NO new+ // device could ever be pinned over the relay ("Awaiting host approval." forever). Two rules+ // from the race in that issue: a retry-churning phone re-raises with a fresh id but a STABLE+ // pub + SAS (the payload replaces the open dialog in place — visually nothing changes), and a+ // host-side expiry drops the dialog rather than leaving Approve aimed at a dead id.+ useEffect(() => {+ const unPending = window.nodeTerminal.remoteHost.onPeerPending((info) =>+ setPendingPeer({ ...info, source: 'phone', label: 'Your phone' })+ )+ const unCleared = window.nodeTerminal.remoteHost.onPeerPendingCleared((info) => {+ setPendingPeerState((cur) => {+ const next = cur && cur.source === 'phone' && cur.id === info.id ? null : cur+ confirmFlags.current.peer = !!next+ return next+ })+ })+ return () => {+ unPending()+ unCleared()+ }+ }, [setPendingPeer])// Team Access seat table (docs/…/team-access, Task 3): a SEPARATE relay-host subscription set from// the SAS-approval effect above — one feeds the dialog, this one feeds the live/pending seats store.@@ -11210,7 +11244,11 @@ export function Canvas() {enterConfirms={false}dangeronConfirm={() => {- window.nodeTerminal.relayHost.confirm(peerApprovalView(pendingPeer).confirmId)+ if (pendingPeer.source === 'phone') {+ window.nodeTerminal.remoteHost.approve(pendingPeer.id, pendingPeer.pub ?? undefined)+ } else {+ window.nodeTerminal.relayHost.confirm(peerApprovalView(pendingPeer).confirmId)+ }setPendingPeer(null)}}// The relay host API offers no explicit reject (see main/remote/relay-host-service.ts):@@ -11218,6 +11256,11 @@ export function Canvas() {// confirms (`onOpen` fires after both humans match the SAS), so closing this dialog// without confirming leaves the pending peer un-admitted and it times out server-side.onCancel={() => {+ // The legacy phone host HAS an explicit reject (unlike relayHost, where declining is+ // just not-confirming): use it, so a denied phone is dropped instead of idling out.+ if (pendingPeer.source === 'phone') {+ window.nodeTerminal.remoteHost.reject(pendingPeer.id, pendingPeer.pub ?? undefined)+ }setPendingPeer(null)}}/>diff --git a/src/shared/ipc.ts b/src/shared/ipc.tsindex db91e4f2a..8653f53c7 100644--- a/src/shared/ipc.ts+++ b/src/shared/ipc.ts@@ -455,6 +455,7 @@ export const IPC = {// SAS to display); renderer → main to approve/reject. Until approved, the host serves no// pty/fs RPCs or input frames, so a leaked offer cannot grant silent access.remoteHostPeerPending: 'remote:host:peer-pending',+ remoteHostPeerPendingCleared: 'remote:host:peer-pending-cleared',remoteHostApprove: 'remote:host:approve',remoteHostReject: 'remote:host:reject',// Host canvas mirror: renderer pushes its serialized active-project canvas to main;diff --git a/src/shared/types.ts b/src/shared/types.tsindex a76ddb381..45a52d0bd 100644--- a/src/shared/types.ts+++ b/src/shared/types.ts@@ -2525,11 +2525,20 @@ export interface RemoteHostApi {* `approve()` before any of the client's pty/fs RPCs are served; `sas` is the channel* verification code to display. Returns an unsubscribe function.*/- onPeerPending(listener: (info: { sas: string | null; id: string }) => void): () => void- /** Approve the pending client (by its pending id) → the host begins serving its pty/fs RPCs. */- approve(id: string): void- /** Reject the pending client (by its pending id) → the connection is dropped. */- reject(id: string): void+ onPeerPending(+ listener: (info: { sas: string | null; id: string; pub?: string | null }) => void+ ): () => void+ /** The pending prompt expired host-side (120 s) — the dialog must drop or re-arm, else its+ * Approve is a silent no-op against a dead id (issue #372). */+ onPeerPendingCleared(+ listener: (info: { id: string | null; pub?: string | null }) => void+ ): () => void+ /** Approve the pending client → the host begins serving its pty/fs RPCs. `pub` (the peer's+ * stable box key) survives the phone's reconnect churn where the per-attach `id` does not —+ * pass both when known. */+ approve(id: string, pub?: string): void+ /** Reject the pending client → the connection is dropped. Same id/pub matching as approve. */+ reject(id: string, pub?: string): void/*** Start/stop the standing (phone) relay host so a paired phone can reach this Mac from anywhere.* Mirrors `settings.phoneAccessEnabled`.