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
feat(ack): reading a finished session on the desktop clears it everywhere
enes3e0f3afb12b6
diff --git a/src/core/agent-status-mirror.test.ts b/src/core/agent-status-mirror.test.tsindex 658d7bdf8..2c9d8f018 100644--- a/src/core/agent-status-mirror.test.ts+++ b/src/core/agent-status-mirror.test.ts@@ -13,6 +13,7 @@ import {recordRawToolEvent,recordContextUsage,clearNode,+ ackDone,flush,initAgentStatusMirror,setMirrorSettingsProvider,@@ -451,6 +452,98 @@ describe('inbox event production (via recordAgentEvent)', () => {})})+describe('ackDone (read-a-finished-session)', () => {+ beforeEach(() => _resetForTest())+ afterEach(() => _resetForTest())++ /** Drive a node to a done inbox event. */+ function toDone(nodeId: string): void {+ recordAgentEvent(ev({ nodeId, state: 'working', newTurn: true }))+ recordAgentEvent(ev({ nodeId, state: 'done', lastMessage: 'All done.' }))+ }++ it('resolves the done event and fires one end/ack seam', () => {+ const changes: NodeStateChange[] = []+ const unsub = onNodeStateChange((c) => changes.push(c))+ toDone('n1')+ // Seams so far: working 'start' + done 'end' (the natural turn-end). Snapshot the count.+ const before = changes.length+ expect(_inboxSnapshot().events[0].resolved).toBeUndefined()++ ackDone('n1')++ const ib = _inboxSnapshot()+ expect(ib.events).toHaveLength(1)+ expect(ib.events[0].kind).toBe('done')+ expect(ib.events[0].resolved).toBe(true)+ // Exactly one new seam, an ack 'end' carrying identity from the done event.+ expect(changes.length).toBe(before + 1)+ expect(changes[changes.length - 1]).toMatchObject({+ nodeId: 'n1',+ event: 'end',+ state: 'done',+ ack: true,+ agentId: 'claude'+ })+ unsub()+ })++ it('is idempotent — a second ack resolves nothing new and fires no seam', () => {+ toDone('n1')+ ackDone('n1')+ const changes: NodeStateChange[] = []+ const unsub = onNodeStateChange((c) => changes.push(c))+ ackDone('n1') // already resolved+ expect(changes).toHaveLength(0)+ expect(_inboxSnapshot().events[0].resolved).toBe(true)+ unsub()+ })++ it('no-ops for a node with no unresolved done event (working focus / unknown node)', () => {+ const changes: NodeStateChange[] = []+ const unsub = onNodeStateChange((c) => changes.push(c))+ // A node that is only working (no done yet) — the renderer gate should prevent this, but the+ // mirror must be defensive: no seam, nothing to resolve.+ recordAgentEvent(ev({ nodeId: 'w', state: 'working', newTurn: true }))+ changes.length = 0+ ackDone('w')+ ackDone('nope') // unknown node+ expect(changes).toHaveLength(0)+ unsub()+ })++ it('resolves done ONLY — leaves an unrelated node and approval/question events untouched', () => {+ toDone('n1')+ // A separate node sitting on an approval card.+ recordAgentEvent(ev({ nodeId: 'n2', state: 'working', newTurn: true }))+ recordAgentEvent(ev({ nodeId: 'n2', state: 'blocked', lastMessage: 'Approve?' }))+ ackDone('n1')+ const events = _inboxSnapshot().events+ const done = events.find((e) => e.nodeId === 'n1')+ const approval = events.find((e) => e.nodeId === 'n2')+ expect(done?.resolved).toBe(true)+ expect(approval?.kind).toBe('approval')+ expect(approval?.resolved).toBeUndefined() // approval NOT touched by a done-ack+ })++ it('resolves the newest done and carries its identity', () => {+ // Two finished turns on one node → two done events; ack resolves both, seam uses the newest.+ recordAgentEvent(ev({ nodeId: 'n1', state: 'working', newTurn: true }))+ recordAgentEvent(ev({ nodeId: 'n1', state: 'done', sessionId: 's1' }))+ recordAgentEvent(ev({ nodeId: 'n1', state: 'working', newTurn: true }))+ recordAgentEvent(ev({ nodeId: 'n1', state: 'done', sessionId: 's2' }))+ const changes: NodeStateChange[] = []+ const unsub = onNodeStateChange((c) => changes.push(c))+ ackDone('n1')+ const dones = _inboxSnapshot().events.filter((e) => e.kind === 'done')+ expect(dones).toHaveLength(2)+ expect(dones.every((e) => e.resolved)).toBe(true)+ expect(changes).toHaveLength(1)+ expect(changes[0].sessionId).toBe('s2') // newest done's identity+ unsub()+ })+})+describe('activity mapping (toolActivity + recordRawToolEvent)', () => {beforeEach(() => _resetForTest())afterEach(() => _resetForTest())diff --git a/src/core/agent-status-mirror.ts b/src/core/agent-status-mirror.tsindex 704563845..7b0cfbae5 100644--- a/src/core/agent-status-mirror.ts+++ b/src/core/agent-status-mirror.ts@@ -206,7 +206,9 @@ export interface InboxEvent {detail?: string/** done: the user hit Esc/Ctrl-C. */interrupted?: boolean- /** approval/question: the node has since left blocked/waiting (moves to the phone's archive). */+ /** approval/question: the node has since left blocked/waiting (moves to the phone's archive).+ * done: the desktop/browser user READ the finished session (`ackDone`), so the phone marks the+ * Inbox card seen and its lingering DONE Live Activity is dismissed. Set on next mirror flush. */resolved?: boolean/** question only: the AskUserQuestion choices (first question, ≤4 labels, each ≤60 chars) so the* phone can render numbered chips / notification actions. Absent for approvals + plain questions@@ -478,6 +480,11 @@ export interface NodeStateChange {/** approval needsYou only: the deterministic hook-reply ticket from the just-produced approval* event, letting an intent answer the held hook. Absent otherwise. */pendingId?: string+ /** done only: this 'end' was produced by an explicit desktop/browser READ of the finished+ * session (`ackDone`), NOT the natural turn-end edge. Both send event:'end', which is what the+ * phone uses to dismiss the Live Activity — `ack` only distinguishes them for internal+ * bookkeeping/tests; the push sender does not need to forward it (end = dismiss). */+ ack?: booleants: number}@@ -1085,6 +1092,43 @@ export function clearNode(nodeId: string): void {if (changed) scheduleWrite()}+/**+ * ACK a node's finished turn: the desktop/browser user READ the finished session (spec: the+ * unread-clear funnel in the renderer, gated on the node's latest state being `done`). Two effects,+ * both cross-surface:+ * - marks the node's UNRESOLVED `done` inbox event(s) `resolved:true` so the phone's Inbox archives+ * the card on its next mirror poll (schedules a flush);+ * - fires ONE onNodeStateChange 'end' edge (state 'done', `ack:true`) so the live-update push+ * (createLiveUpdatePush) POSTs an 'end' the backend fans out to the phone, dismissing the+ * lingering DONE Live Activity. The natural turn-end already sent an 'end' at done-time; this+ * re-sends it on the READ, which is what actually clears an activity ActivityKit's dismissal+ * policy kept on the lock screen.+ * NO-OP when the node has no unresolved done event (a stray/duplicate ack — e.g. a second read, or a+ * working-state focus that slipped the renderer gate — fires no seam and schedules no write). Pure+ * apart from the seam + write; `now` is Date.now for parity with the rest of the module.+ */+export function ackDone(nodeId: string): void {+ if (!nodeId) return+ let latest: InboxEvent | undefined+ for (const e of inboxEvents) {+ if (e.nodeId === nodeId && e.kind === 'done' && !e.resolved) {+ e.resolved = true+ latest = e // feed is oldest→newest, so the last match is the newest done+ }+ }+ if (!latest) return+ fireNodeStateChange({+ nodeId,+ agentId: latest.agentId,+ sessionId: latest.sessionId,+ event: 'end',+ state: 'done',+ ack: true,+ ts: Date.now()+ })+ scheduleWrite()+}+function scheduleWrite(): void {if (writeTimer) returnwriteTimer = setTimeout(() => {diff --git a/src/main/index.ts b/src/main/index.tsindex 1f4cd1d47..88ed96d3a 100644--- a/src/main/index.ts+++ b/src/main/index.ts@@ -31,6 +31,7 @@ import {onMirrorFlush,flush as flushAgentStatusMirror,recordAgentEvent,+ ackDone,recordRawToolEvent,recordContextUsage,setMirrorSettingsProvider,@@ -1073,6 +1074,13 @@ app.whenReady().then(async () => {return ok})+ // Read-a-finished-session ack (this feature): the renderer's unread-clear funnel calls it when the+ // just-read node's latest state is `done`. The mirror resolves the node's done inbox event(s)+ // (phone Inbox archives the card) and re-sends an 'end' live-update so the paired phone dismisses+ // its lingering DONE Live Activity. Fire-and-forget; the mirror no-ops with no unresolved done.+ corePlatform.handle(IPC.agentAckDone, (nodeId: string) => {+ ackDone(nodeId)+ })// Sweep stale request/answer files (~/.nodeterm/pending) on boot + hourly — orphans from killed// sessions that never got an answer. Local only; a remote host runs its own sweep if it hosts// nodeterm, else the files age out harmlessly.diff --git a/src/preload/index.ts b/src/preload/index.tsindex 51513e19b..e66c6a1c0 100644--- a/src/preload/index.ts+++ b/src/preload/index.ts@@ -501,6 +501,9 @@ const api: NodeTerminalApi = {return () => ipcRenderer.removeListener(IPC.appFocusNode, handler)},answerPermission: (payload) => ipcRenderer.invoke(IPC.agentAnswerPermission, payload),+ ackDone: (nodeId) => {+ void ipcRenderer.invoke(IPC.agentAckDone, nodeId)+ },onAgentStatus: (listener) => {const handler = (_e: unknown, payload: Parameters<typeof listener>[0]) => listener(payload)ipcRenderer.on(IPC.agentStatus, handler)diff --git a/src/renderer/bridge/stubs.ts b/src/renderer/bridge/stubs.tsindex d78a46a40..0b69c0e2a 100644--- a/src/renderer/bridge/stubs.ts+++ b/src/renderer/bridge/stubs.ts@@ -116,6 +116,7 @@ export function buildStubApi(): Omit<| 'onAgentStatus'| 'onSubagentActivity'| 'answerPermission'+ | 'ackDone'// Real over the bridge (IPC.appUserDataDir): the worktree dialog's default path is derived from// it, and a '' stub would propose `/worktrees/…` at the filesystem root.| 'userDataDir'@@ -332,6 +333,7 @@ export function buildStubApi(): Omit<| 'onAgentStatus'| 'onSubagentActivity'| 'answerPermission'+ | 'ackDone'| 'userDataDir'| 'presence'| 'speech'diff --git a/src/renderer/bridge/ws-bridge.ts b/src/renderer/bridge/ws-bridge.tsindex 6085e315c..eda58c0d8 100644--- a/src/renderer/bridge/ws-bridge.ts+++ b/src/renderer/bridge/ws-bridge.ts@@ -415,7 +415,7 @@ export function buildFilesApi(*/export function buildAgentApi(client: RpcClient-): Pick<NodeTerminalApi, 'onAgentStatus' | 'onSubagentActivity' | 'answerPermission'> {+): Pick<NodeTerminalApi, 'onAgentStatus' | 'onSubagentActivity' | 'answerPermission' | 'ackDone'> {return {onAgentStatus: (listener) => client.subscribe(IPC.agentStatus, listener as Listener),onSubagentActivity: (listener) =>@@ -424,7 +424,13 @@ export function buildAgentApi(// ON the host, so a local project's answer file is written right there (SSH-from-server is v1// unsupported and the handler returns false). See docs/hook-reply-approvals.md.answerPermission: (payload) =>- client.request(IPC.agentAnswerPermission, payload) as Promise<boolean>+ client.request(IPC.agentAnswerPermission, payload) as Promise<boolean>,+ // Read-a-finished-session ack: a real fire-and-forget request over the bridge — the browser+ // canvas runs ON the host, so the server's mirror acks the done event + re-sends the 'end'+ // live-update to the paired phone, same as desktop. See agent-status-mirror `ackDone`.+ ackDone: (nodeId) => {+ void client.request(IPC.agentAckDone, nodeId)+ }}}diff --git a/src/renderer/state/agentStatus.ts b/src/renderer/state/agentStatus.tsindex 3021e41f3..c52629b35 100644--- a/src/renderer/state/agentStatus.ts+++ b/src/renderer/state/agentStatus.ts@@ -153,7 +153,10 @@ export interface AgentStatusSession {* save is a no-op — the instance never touches localStorage). See the module docblock for* why only the default instance has a key today.*/-export function createAgentStatusSession(persistKey?: string): AgentStatusSession {+export function createAgentStatusSession(+ persistKey?: string,+ ackDone?: (nodeId: string) => void+): AgentStatusSession {if (persistKey === KEY) migrateLegacyKey()function load(): Record<string, AgentNodeStatus> {@@ -297,6 +300,12 @@ export function createAgentStatusSession(persistKey?: string): AgentStatusSessioset((s) => {const prev = s.byId[id]if (!prev?.unread) return s+ // Cross-surface ACK: reading a FINISHED session here dismisses the paired phone's lingering+ // DONE Live Activity and marks its Inbox card seen (via the core mirror's `ackDone`). Gated+ // on the node's LATEST state being `done` — a working-state focus (unread from an earlier+ // turn while a new turn is now live) must not ack. Fire-and-forget; the mirror no-ops when+ // there is no unresolved done event, so a stray call is harmless + idempotent.+ if (prev.state === 'done') ackDone?.(id)const byId = { ...s.byId, [id]: { ...prev, unread: false } }save(byId)return { byId }@@ -383,7 +392,10 @@ const instanceByApi = new WeakMap<NodeTerminalApi, AgentStatusSession>()export function agentStatusForApi(api: NodeTerminalApi): AgentStatusSession {const existing = api ? instanceByApi.get(api) : undefinedif (existing) return existing- const session = createAgentStatusSession() // keyless — remote status is never persisted (4a)+ // Keyless — remote status is never persisted (4a) — but the done-read ack routes to THAT core's+ // api (a remote/relay core acks on its own host), so reading a finished remote session dismisses+ // its phone activity too. A nullish api (node-env tests) gets no ack.+ const session = createAgentStatusSession(undefined, api ? (id) => api.ackDone(id) : undefined)if (api) instanceByApi.set(api, session)return session}@@ -397,7 +409,11 @@ export function agentStatusForApi(api: NodeTerminalApi): AgentStatusSession {* `agentStatusForApi(window.nodeTerminal)` — the session registry's local session — resolve* here, never to a parallel twin.*/-const defaultAgentStatus = createAgentStatusSession(KEY)+// The default (local core) acks the finished-session read to `window.nodeTerminal.ackDone` — guarded+// for node-environment tests where no preload exists (the callback is invoked later, at clear time).+const defaultAgentStatus = createAgentStatusSession(KEY, (id) => {+ if (typeof window !== 'undefined') window.nodeTerminal?.ackDone?.(id)+})export { defaultAgentStatus }if (typeof window !== 'undefined' && window.nodeTerminal) {instanceByApi.set(window.nodeTerminal as NodeTerminalApi, defaultAgentStatus)diff --git a/src/server/index.ts b/src/server/index.tsindex 4cc96c589..a4cbd3f7e 100644--- a/src/server/index.ts+++ b/src/server/index.ts@@ -28,6 +28,7 @@ import {initAgentStatusMirror,flush as flushAgentStatusMirror,recordAgentEvent,+ ackDone,setMirrorSettingsProvider,onInboxActionable,onNodeStateChange,@@ -240,6 +241,13 @@ export async function startServer(return ok})+ // Read-a-finished-session ack (parity with desktop): the browser canvas's unread-clear funnel+ // calls it when the just-read node's latest state is `done`. The mirror resolves the node's done+ // inbox event(s) + re-sends an 'end' live-update so the paired phone dismisses its lingering DONE+ // Live Activity. Fire-and-forget; no-op with no unresolved done.+ platform.handle(IPC.agentAckDone, (nodeId: string) => {+ ackDone(nodeId)+ })// Sweep stale ~/.nodeterm/pending files on boot + hourly (orphans from killed sessions).startPendingSweep(os.homedir())// Phone push via SSH-possession GRANTS (spec: nodeterm-server/docs/specs/2026-07-21-push-grants.md).diff --git a/src/shared/ipc.ts b/src/shared/ipc.tsindex 7b583c61a..f1fe04e3d 100644--- a/src/shared/ipc.ts+++ b/src/shared/ipc.ts@@ -39,6 +39,10 @@ export const IPC = {* Payload: `{ nodeId, pendingId, decision: 'allow'|'deny' }`; resolves boolean. See* docs/hook-reply-approvals.md. */agentAnswerPermission: 'agent:answer-permission',+ /** Renderer → main/server: the user READ a finished (done) session on this surface. Acks the+ * node's done inbox event(s) + dismisses the paired phone's lingering DONE Live Activity. Arg:+ * `nodeId: string`. Fire-and-forget. See agent-status-mirror `ackDone`. */+ agentAckDone: 'agent:ack-done',agentSubagentActivity: 'agent:subagent-activity',agentControl: 'agent:control',agentControlResult: 'agent:control-result',diff --git a/src/shared/types.ts b/src/shared/types.tsindex 826b783a6..7b75830d6 100644--- a/src/shared/types.ts+++ b/src/shared/types.ts@@ -1624,6 +1624,12 @@ export interface NodeTerminalApi {* `true` when the file was written, `false` on any failure (invalid pendingId, unknown node,* unsupported project, fs/exec error). */answerPermission(payload: { nodeId: string; pendingId: string; decision: 'allow' | 'deny' }): Promise<boolean>+ /** Notify the core that the user READ a finished (done) session on this surface (the unread-clear+ * funnel calls it when the node's latest state is `done`). The core marks the node's done inbox+ * event(s) resolved (phone Inbox archives the card) and re-sends an 'end' live-update so the+ * paired phone dismisses its lingering DONE Live Activity. Fire-and-forget; no-op if the node has+ * no unresolved done event. */+ ackDone(nodeId: string): void/** Fires on each normalized agent hook event (working/done/waiting/subagent/…). Returns unsubscribe. */onAgentStatus(listener: (e: NormalizedAgentEvent) => void): () => void/** Fires with live subagent transcript chunks while a subagent runs. Returns unsubscribe. */