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(agent-status): Esc that ran no Stop hook no longer leaves a node working
enes4f19af8714cd
diff --git a/src/core/agent-status-mirror.test.ts b/src/core/agent-status-mirror.test.tsindex 977d0c735..e3bb1b442 100644--- a/src/core/agent-status-mirror.test.ts+++ b/src/core/agent-status-mirror.test.ts@@ -1536,3 +1536,30 @@ describe('stale-working sweep (shared/agents/stale)', () => {expect(_snapshot().n2.state).toBe('working')})})+++describe('idle_prompt rescue (Esc that ran no Stop hook)', () => {+ it('moves a stuck working node off working', () => {+ const prev = reduceEntry(undefined, ev({ state: 'working' }), 1000)+ expect(prev.state).toBe('working')+ const next = reduceEntry(prev, ev({ state: 'done', idle: true, interrupted: true }), 2000)+ expect(next.state).toBe('done')+ expect(next.updatedAt).toBe(2000)+ })++ it('never clears a pending approval / question — those are idle at the prompt too', () => {+ for (const state of ['blocked', 'waiting'] as const) {+ const prev = reduceEntry(undefined, ev({ state }), 1000)+ const next = reduceEntry(prev, ev({ state: 'done', idle: true, interrupted: true }), 2000)+ expect(next.state).toBe(state)+ expect(next.updatedAt).toBe(1000) // untouched, so the freshness window keeps measuring+ }+ })++ it('is a no-op on an already-finished node (it fires after every normal turn)', () => {+ const prev = reduceEntry(undefined, ev({ state: 'done' }), 1000)+ const next = reduceEntry(prev, ev({ state: 'done', idle: true, interrupted: true }), 2000)+ expect(next.state).toBe('done')+ expect(next.updatedAt).toBe(1000)+ })+})diff --git a/src/core/agent-status-mirror.ts b/src/core/agent-status-mirror.tsindex bd3857190..36b6102c0 100644--- a/src/core/agent-status-mirror.ts+++ b/src/core/agent-status-mirror.ts@@ -288,6 +288,10 @@ export function reduceEntry(if (ev.sessionId) next.sessionId = ev.sessionIdif (ev.kind === 'state' && ev.state) {+ // An `idle` done (Claude went quiet at its prompt) is a RESCUE, not a turn end: it may only+ // move a node that is still `working`. A node that is blocked/waiting is ALSO idle at the+ // prompt — clearing it there would drop a live approval — and one already done needs nothing.+ if (ev.idle && prev?.state !== 'working') return next// Done-holdoff: a late, non-newTurn `working` (out-of-order parallel hook, or an in-flight// tool POST at interrupt) must not resurrect a turn that just finished. Only a genuine new// turn (UserPromptSubmit) may. Leave state + updatedAt untouched so the window keepsdiff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsxindex d525f265c..c54231e5a 100644--- a/src/renderer/canvas/Canvas.tsx+++ b/src/renderer/canvas/Canvas.tsx@@ -5443,10 +5443,15 @@ export function Canvas() {}const an = useAgentNodes.getState()switch (e.kind) {- case 'state':+ case 'state': {+ // An `idle` done (the CLI went quiet at its prompt — see normalize) is a RESCUE for a+ // node stuck on `working` after an Esc that ran no turn-end hook. It may ONLY move a+ // working node: blocked/waiting is also "idle at the prompt", and clearing it there+ // would drop a live approval off the badge. Same rule as the mirror's reduceEntry.+ const stuckRescueSkip = e.idle === true && cs.byId[e.nodeId]?.state !== 'working'// `pendingId` (deterministic approvals) rides a `blocked` event; the store keeps it only// while blocked so the header's Approve/Deny buttons appear + vanish with the state.- if (e.state) cs.setState(e.nodeId, e.state, e.agentId, e.newTurn, e.pendingId)+ if (e.state && !stuckRescueSkip) cs.setState(e.nodeId, e.state, e.agentId, e.newTurn, e.pendingId)if (e.newTurn) an.clearForParent(e.nodeId) // genuine new turn → drop the previous fan-outif (e.newTurn && e.task) {// Prompt-prefix fallback for /loop|/schedule|/cron when the natural-language@@ -5465,6 +5470,7 @@ export function Canvas() {else if (e.state === 'waiting')alert('needs input', `${agentLabel} is waiting for your response.`, 'needsYou')break+ }case 'subagent-start':if (e.toolUseId) {an.start(e.toolUseId, {diff --git a/src/shared/agents/normalize.test.ts b/src/shared/agents/normalize.test.tsindex 23050c47a..979562ef0 100644--- a/src/shared/agents/normalize.test.ts+++ b/src/shared/agents/normalize.test.ts@@ -163,10 +163,12 @@ describe('normalizeClaude — permission signals', () => {expect(e).toMatchObject({ kind: 'state', state: 'blocked' })})- // Claude Code fires an idle_prompt Notification AFTER a turn completes normally (after- // Stop). Mapping it to waiting resurrected NEEDS YOU on a finished node and left it- // stuck there until the next prompt.- it('Notification idle_prompt after Stop does NOT change state', () => {+ // Claude Code fires an idle_prompt Notification whenever it is sitting at its prompt: after a+ // normally-finished turn (already done → the consumers' working-only rule makes it a no-op) AND+ // after an Esc that aborted a tool call without ever running Stop — the one case that left a node+ // stuck on `working`. It is a RESCUE, hence `idle` + `interrupted`, never a celebration.+ // Mapping it to `waiting` (the obvious reading) is what used to stick NEEDS YOU on finished nodes.+ it('Notification idle_prompt → an idle, interrupted done (the stuck-working rescue)', () => {const e = normalizeClaude(env({hook_event_name: 'Notification',@@ -174,7 +176,7 @@ describe('normalizeClaude — permission signals', () => {message: 'Claude is waiting for your input'}))- expect(e).toBeNull()+ expect(e).toMatchObject({ kind: 'state', state: 'done', idle: true, interrupted: true })})it('Notification elicitation_dialog / agent_needs_input → waiting', () => {diff --git a/src/shared/agents/normalize.ts b/src/shared/agents/normalize.tsindex 68130e0a4..90cabdc76 100644--- a/src/shared/agents/normalize.ts+++ b/src/shared/agents/normalize.ts@@ -12,6 +12,11 @@ export interface NormalizedAgentEvent {// done only: the turn ended because the user interrupted (Esc/Ctrl-C) — the renderer// skips the completion alert/unread for these (the user was right there).interrupted?: boolean+ // done only: this `done` was inferred from the CLI going IDLE at its prompt (Claude's+ // `idle_prompt` notification), not from a turn-end hook. It is a RESCUE signal: it may only+ // move a node that is still `working` (see reduceEntry / the Canvas listener), because a+ // pending approval/question is also "idle at the prompt" and must not be cleared by it.+ idle?: boolean// true only for a genuine new turn (Claude UserPromptSubmit), so the renderer can// clear per-turn fan-out without clearing on every mid-turn tool event.newTurn?: boolean@@ -224,6 +229,19 @@ export function normalizeClaude(env: RawHookEnvelope): NormalizedAgentEvent | nuif (p.notification_type === 'elicitation_dialog' || p.notification_type === 'agent_needs_input') {return { ...base, kind: 'state', state: 'waiting', lastMessage: p.last_assistant_message }}+ // `idle_prompt` = the CLI is sitting at its prompt waiting for you to type. It cannot be true+ // while a turn runs, which makes it the ONE signal that rescues a node stuck on `working` when+ // no turn-end hook ever fired — the Esc-during-a-tool-call case, where Claude aborts the tool+ // and returns to "Interrupted · What should Claude do instead?" without running Stop.+ //+ // Marked `idle` (and `interrupted`, since nothing was accomplished) so consumers can apply the+ // narrow rule this needs: it may only move a node that is still WORKING. It also fires after a+ // normally-finished turn (already `done` → no-op) and can fire while an approval prompt is up+ // (`blocked`/`waiting` → must NOT be cleared). Mapping it to `waiting` — the obvious reading —+ // is what stuck NEEDS YOU on finished nodes before, hence the deliberate no-op default below.+ if (p.notification_type === 'idle_prompt') {+ return { ...base, kind: 'state', state: 'done', interrupted: true, idle: true }+ }return null}if (ev === 'SessionStart') return { ...base, kind: 'session', sessionPhase: 'start' }