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(status): the renderer store carries the verified flag too
enes7bfbc8b3d22a
diff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsxindex ed29ecb24..dd11df5d3 100644--- a/src/renderer/canvas/Canvas.tsx+++ b/src/renderer/canvas/Canvas.tsx@@ -7552,7 +7552,10 @@ export function Canvas() {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 && !stuckRescueSkip) cs.setState(e.nodeId, e.state, e.agentId, e.newTurn, e.pendingId)+ // `e.verified` is the identity evidence for this very transition (hook-server labels it);+ // it was in scope here and dropped on the floor before the store had a field for it.+ if (e.state && !stuckRescueSkip)+ cs.setState(e.nodeId, e.state, e.agentId, e.newTurn, e.pendingId, e.verified)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-languagediff --git a/src/renderer/state/agentStatus.test.ts b/src/renderer/state/agentStatus.test.tsindex d1fa9b0b4..76f0ab9db 100644--- a/src/renderer/state/agentStatus.test.ts+++ b/src/renderer/state/agentStatus.test.ts@@ -1,4 +1,6 @@import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'+import { readFileSync } from 'node:fs'+import { resolve } from 'node:path'import {useAgentStatus,createAgentStatusSession,@@ -228,3 +230,70 @@ describe('clearUnread — cross-surface ack vs. external (host-driven) clear', (expect(acked).toEqual([])})})++describe('the verified evidence for a transition', () => {+ it('setState records it', () => {+ const s = useAgentStatus.getState()+ const id = nid()+ s.setState(id, 'done', 'claude', false, undefined, true)+ expect(useAgentStatus.getState().byId[id].stateVerified).toBe(true)+ s.setState(id, 'working', 'claude', true, undefined, false)+ expect(useAgentStatus.getState().byId[id].stateVerified).toBe(false)+ })++ it('an omitted argument is not proof (every existing call site keeps compiling, and lies about nothing)', () => {+ const id = nid()+ useAgentStatus.getState().setState(id, 'done', 'claude')+ expect(useAgentStatus.getState().byId[id].stateVerified).toBe(false)+ })++ it('Canvas hands the event\'s flag to the store — the drop this whole change exists to fix', () => {+ // A store field with no writer is the same bug in a new place, and this one is a plain+ // argument list: nothing else in the suite would notice if the last argument disappeared.+ const src = readFileSync(resolve(__dirname, '../../..', 'src/renderer/canvas/Canvas.tsx'), 'utf8')+ expect(src).toMatch(+ /cs\.setState\(\s*e\.nodeId,\s*e\.state,\s*e\.agentId,\s*e\.newTurn,\s*e\.pendingId,\s*e\.verified\s*\)/+ )+ })++ it('a same-state re-assert by a legacy POST drops the earlier proof', () => {+ // The same-state fast path refreshes in place instead of allocating; the evidence has to ride+ // along, or this copy would keep saying `verified` about a state a tokenless event re-asserted.+ const s = useAgentStatus.getState()+ const id = nid()+ s.setState(id, 'working', 'claude', true, undefined, true)+ s.setState(id, 'working', 'claude', false, undefined, false)+ expect(useAgentStatus.getState().byId[id].stateVerified).toBe(false)+ })++ it('stateVerified is TRANSIENT — never persisted', () => {+ // This suite runs under node, not jsdom, so the store's localStorage writes are swallowed by+ // its own try/catch. A minimal in-memory stub is what makes the durable whitelist observable+ // at all — without it this assertion would pass against ANY whitelist, including a broken one.+ const mem = new Map<string, string>()+ ;(globalThis as unknown as { localStorage: unknown }).localStorage = {+ getItem: (k: string) => mem.get(k) ?? null,+ setItem: (k: string, v: string) => void mem.set(k, v),+ removeItem: (k: string) => void mem.delete(k)+ }+ try {+ const KEY = 'nodeterm.agentStatus.verified-test'+ const { store } = createAgentStatusSession(KEY)+ const id = nid()+ // ORDER IS LOAD-BEARING, and the first draft of this test had it backwards. `setState` does+ // not itself call `save`, and `save` skips entries with no durable field — so writing the+ // blob BEFORE the verified transition produced a blob that could not contain `stateVerified`+ // whatever the whitelist said, and the assertion below passed against a whitelist that+ // included it. Set the flag first, then trigger a save with a durable write.+ store.getState().setState(id, 'done', 'claude', false, undefined, true)+ expect(store.getState().byId[id].stateVerified).toBe(true)+ store.getState().markUnread(id)+ const saved = JSON.parse(mem.get(KEY) ?? '{}')+ expect(saved[id]).toBeTruthy()+ expect(saved[id].unread).toBe(true)+ expect(saved[id].stateVerified).toBeUndefined()+ } finally {+ delete (globalThis as unknown as { localStorage?: unknown }).localStorage+ }+ })+})diff --git a/src/renderer/state/agentStatus.ts b/src/renderer/state/agentStatus.tsindex 6be1636ca..543a4ecf2 100644--- a/src/renderer/state/agentStatus.ts+++ b/src/renderer/state/agentStatus.ts@@ -43,6 +43,14 @@ export interface AgentNodeStatus {* interrupt-inference baseline. Same-state events refresh it in place (no re-render).*/stateAt?: number+ /**+ * Did the hook POST that set the current `state` carry a per-node token? Mirrors+ * `MirrorEntry.stateVerified` (core/agent-status-mirror.ts), which is where the messaging gate+ * actually reads it — this copy exists so the UI can SHOW identity state, not so anything can+ * gate on it. TRANSIENT, deliberately excluded from the durable whitelist in `save()`: a relaunch+ * has seen no events, and a restored `true` would assert proof that was never presented this run.+ */+ stateVerified?: boolean/*** When this node last CHANGED state — the idle clock the hibernation policy reads* (`terminal/hibernation-policy.ts`). Deliberately not `stateAt`: that one is refreshed by@@ -132,13 +140,16 @@ export interface AgentStatusStore {setActive(id: string, active: boolean): void/** `newTurn` marks a genuine UserPromptSubmit — the only working that may follow a fresh done.* `pendingId` (deterministic approvals) is retained only while `state === 'blocked'`; any other- * state clears it, so the header's Approve/Deny buttons disappear as soon as the node moves on. */+ * state clears it, so the header's Approve/Deny buttons disappear as soon as the node moves on.+ * `verified` is the identity evidence for THIS transition (see `stateVerified`); a caller that+ * omits it asserts nothing, which is why it is trailing and optional. */setState(id: string,state: AgentState | undefined,agentId?: AgentId,newTurn?: boolean,- pendingId?: string+ pendingId?: string,+ verified?: boolean): void/** Clear `working` entries whose last event is older than `staleMs` (lost-Stop safety net). */sweepStaleWorking(staleMs?: number): void@@ -309,7 +320,7 @@ export function createAgentStatusSession(return s.activeId === id ? { activeId: null } : s}),- setState: (id, state, agentId, newTurn, pendingId) =>+ setState: (id, state, agentId, newTurn, pendingId, verified) =>set((s) => {const prev = s.byId[id] ?? EMPTYconst now = Date.now()@@ -336,13 +347,22 @@ export function createAgentStatusSession() {// Same-state event: refresh freshness in place — stateAt is never rendered, and a// new object here would re-render every node header on each tool event.- if (s.byId[id]) s.byId[id].stateAt = now+ if (s.byId[id]) {+ s.byId[id].stateAt = now+ // The evidence rides along, in place and for the same reason: a re-assert of the SAME+ // state by a legacy POST must not leave an earlier `true` standing, or this copy would+ // disagree with the mirror the gate actually reads.+ s.byId[id].stateVerified = verified === true+ }return s}// The ONE place a state transition is recorded, so it is also the one place the idle// clock is stamped (the same-state fast path above deliberately does not touch it —// see `lastEventAt`).const next = { ...prev, state, stateAt: now, lastEventAt: now }+ // Written on the same edge the state is — the evidence describes THIS transition, and an+ // absent argument is not evidence.+ next.stateVerified = verified === trueif (agentId !== undefined) next.agentId = agentId// Retain the approval ticket only while blocked; any other state clears it (transient).next.pendingId = state === 'blocked' ? (pendingId ?? prev.pendingId) : undefined