Skip to content

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.

feat(mirror): expose the currently-working nodes for the reconnect resync

enes4390ed886713
diff --git a/src/core/agent-status-mirror.test.ts b/src/core/agent-status-mirror.test.ts
index 06948aeaf..6bd0771d5 100644
--- a/src/core/agent-status-mirror.test.ts
+++ b/src/core/agent-status-mirror.test.ts
@@ -30,6 +30,7 @@ import {
onNodeNowChange,
onInboxActionable,
isEventUnresolved,
+ workingNodes,
_resetForTest,
_snapshot,
_inboxSnapshot,
@@ -1678,3 +1679,20 @@ describe('recordAgentEvent — codex request_user_input broadcast conversion', (
expect(_snapshot().n1.state).toBe('waiting')
})
})
+
+describe('workingNodes', () => {
+ beforeEach(() => _resetForTest())
+ afterEach(() => _resetForTest())
+
+ it('lists only the nodes currently believed to be working, with their identity', () => {
+ recordAgentEvent(ev({ nodeId: 'n1', agentId: 'claude', state: 'working', sessionId: 's1' }))
+ recordAgentEvent(ev({ nodeId: 'n2', agentId: 'claude', state: 'done', sessionId: 's2' }))
+
+ expect(workingNodes()).toEqual([{ nodeId: 'n1', agentId: 'claude', sessionId: 's1' }])
+ })
+
+ it('is empty when nothing is working', () => {
+ recordAgentEvent(ev({ nodeId: 'n3', agentId: 'codex', state: 'done' }))
+ expect(workingNodes()).toEqual([])
+ })
+})
diff --git a/src/core/agent-status-mirror.ts b/src/core/agent-status-mirror.ts
index 6ec7cc852..8eaf70d3a 100644
--- a/src/core/agent-status-mirror.ts
+++ b/src/core/agent-status-mirror.ts
@@ -1418,6 +1418,19 @@ export function nodeState(nodeId: string): AgentState | undefined {
return state.get(nodeId)?.state
}
+/**
+ * The nodes the mirror currently believes are `working`, with the identity a synthetic event needs.
+ * Read-only peek for the shells — the reconnect resync asks the host about exactly these, because
+ * `working` is the only state a lost hook event can strand (see remote-ssh/agent-resync-decide.ts).
+ */
+export function workingNodes(): { nodeId: string; agentId?: string; sessionId?: string }[] {
+ const out: { nodeId: string; agentId?: string; sessionId?: string }[] = []
+ for (const [nodeId, e] of state) {
+ if (e.state === 'working') out.push({ nodeId, agentId: e.agentId, sessionId: e.sessionId })
+ }
+ return out
+}
+
/** The entries the session-name sweep walks: id + what it needs to resolve and dedupe. */
export function sessionNameSweepEntries(): {
nodeId: string