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.

fix(push): multiSelect rides the question pipeline; state edges are marked

enes1c15af5fa31e
diff --git a/src/core/agent-status-mirror.test.ts b/src/core/agent-status-mirror.test.ts
index bd1eaecd4..2798460e4 100644
--- a/src/core/agent-status-mirror.test.ts
+++ b/src/core/agent-status-mirror.test.ts
@@ -23,6 +23,7 @@ import {
firstLine,
extractQuestionOptions,
extractQuestionText,
+ extractQuestionMultiSelect,
onNodeStateChange,
onNodeNowChange,
_resetForTest,
@@ -656,6 +657,124 @@ describe('question options (AskUserQuestion)', () => {
})
})
+// ---- multiSelect (rides the AskUserQuestion pipeline) ---------------------------------------
+
+describe('question multiSelect (AskUserQuestion)', () => {
+ beforeEach(() => _resetForTest())
+ afterEach(() => _resetForTest())
+
+ const qms = (multiSelect: unknown) => ({
+ questions: [{ question: 'Pick', options: [{ label: 'A' }, { label: 'B' }], multiSelect }]
+ })
+
+ it('extracts the tolerant boolean, undefined on absence/non-boolean/bad shape', () => {
+ expect(extractQuestionMultiSelect(qms(true))).toBe(true)
+ expect(extractQuestionMultiSelect(qms(false))).toBe(false)
+ // absent multiSelect key → undefined
+ expect(extractQuestionMultiSelect({ questions: [{ options: [{ label: 'A' }] }] })).toBeUndefined()
+ // non-boolean is tolerated as undefined (never coerced)
+ expect(extractQuestionMultiSelect(qms('yes'))).toBeUndefined()
+ expect(extractQuestionMultiSelect(qms(1))).toBeUndefined()
+ // only the FIRST question's flag
+ expect(
+ extractQuestionMultiSelect({ questions: [{ multiSelect: true }, { multiSelect: false }] })
+ ).toBe(true)
+ // fail-open on every shape mismatch
+ expect(extractQuestionMultiSelect(undefined)).toBeUndefined()
+ expect(extractQuestionMultiSelect({})).toBeUndefined()
+ expect(extractQuestionMultiSelect({ questions: [] })).toBeUndefined()
+ expect(extractQuestionMultiSelect({ questions: 'x' } as unknown as Record<string, unknown>)).toBeUndefined()
+ })
+
+ it('stashes multiSelect and attaches it to the next question event', () => {
+ recordRawToolEvent('n1', {
+ hook_event_name: 'PreToolUse',
+ tool_name: 'AskUserQuestion',
+ tool_input: qms(true)
+ })
+ recordAgentEvent(ev({ nodeId: 'n1', state: 'waiting', lastMessage: 'Pick some' }))
+ const q = _inboxSnapshot().events.find((e) => e.nodeId === 'n1' && e.kind === 'question')!
+ expect(q.options).toEqual(['A', 'B'])
+ expect(q.multiSelect).toBe(true)
+ })
+
+ it('omits multiSelect from the event when the flag is false', () => {
+ recordRawToolEvent('n2', {
+ hook_event_name: 'PreToolUse',
+ tool_name: 'AskUserQuestion',
+ tool_input: qms(false)
+ })
+ recordAgentEvent(ev({ nodeId: 'n2', state: 'waiting', lastMessage: 'Pick one' }))
+ const q = _inboxSnapshot().events.find((e) => e.nodeId === 'n2')!
+ expect(q.options).toEqual(['A', 'B'])
+ expect('multiSelect' in q).toBe(false)
+ })
+
+ it('omits multiSelect for a plain question and for an approval (no stash)', () => {
+ recordAgentEvent(ev({ nodeId: 'q', state: 'waiting', lastMessage: 'Which file?' }))
+ recordAgentEvent(ev({ nodeId: 'a', state: 'blocked', lastMessage: 'Approve write' }))
+ expect('multiSelect' in _inboxSnapshot().events.find((e) => e.nodeId === 'q')!).toBe(false)
+ expect('multiSelect' in _inboxSnapshot().events.find((e) => e.nodeId === 'a')!).toBe(false)
+ })
+
+ it('rides a stash-reclassified blocked edge (options force question) and survives a PermissionRequest merge', () => {
+ recordRawToolEvent('n3', {
+ hook_event_name: 'PreToolUse',
+ tool_name: 'AskUserQuestion',
+ tool_input: qms(true)
+ })
+ // A PermissionRequest for the same picker merges onto the stash — multiSelect must survive.
+ recordRawToolEvent('n3', {
+ hook_event_name: 'PermissionRequest',
+ tool_name: 'AskUserQuestion',
+ tool_input: qms(true)
+ })
+ recordAgentEvent(ev({ nodeId: 'n3', state: 'blocked', lastMessage: 'Approve?', pendingId: 'n3-1-1' }))
+ const e = _inboxSnapshot().events.find((x) => x.nodeId === 'n3')!
+ expect(e.kind).toBe('question')
+ expect(e.multiSelect).toBe(true)
+ })
+
+ it('clears multiSelect with the stash when the node leaves waiting', () => {
+ recordRawToolEvent('n4', {
+ hook_event_name: 'PreToolUse',
+ tool_name: 'AskUserQuestion',
+ tool_input: qms(true)
+ })
+ recordAgentEvent(ev({ nodeId: 'n4', state: 'waiting', lastMessage: 'Q1' }))
+ recordAgentEvent(ev({ nodeId: 'n4', state: 'working' })) // leaves waiting → clears stash
+ recordAgentEvent(ev({ nodeId: 'n4', state: 'waiting', lastMessage: 'Q2' }))
+ const qs = _inboxSnapshot().events.filter((e) => e.nodeId === 'n4' && e.kind === 'question')
+ expect('multiSelect' in qs[qs.length - 1]).toBe(false)
+ })
+
+ it('the onNodeStateChange needsYou edge carries multiSelect (present true / omitted false)', () => {
+ const seen: NodeStateChange[] = []
+ const unsub = onNodeStateChange((c) => seen.push(c))
+ recordRawToolEvent('n5', {
+ hook_event_name: 'PreToolUse',
+ tool_name: 'AskUserQuestion',
+ tool_input: qms(true)
+ })
+ recordAgentEvent(ev({ nodeId: 'n5', state: 'waiting', lastMessage: 'Pick some' }))
+ const ny = seen.find((c) => c.nodeId === 'n5' && c.state === 'needsYou')!
+ expect(ny.kind).toBe('question')
+ expect(ny.multiSelect).toBe(true)
+
+ // A false flag is omitted from the edge.
+ recordRawToolEvent('n6', {
+ hook_event_name: 'PreToolUse',
+ tool_name: 'AskUserQuestion',
+ tool_input: qms(false)
+ })
+ recordAgentEvent(ev({ nodeId: 'n6', state: 'waiting', lastMessage: 'Pick one' }))
+ const ny2 = seen.find((c) => c.nodeId === 'n6' && c.state === 'needsYou')!
+ expect(ny2.kind).toBe('question')
+ expect('multiSelect' in ny2).toBe(false)
+ unsub()
+ })
+})
+
// ---- Approval summary (PermissionRequest → "what's being approved") -------------------------
describe('buildApprovalSummary (builder table)', () => {
diff --git a/src/core/agent-status-mirror.ts b/src/core/agent-status-mirror.ts
index d8cc8a4f9..a441d459a 100644
--- a/src/core/agent-status-mirror.ts
+++ b/src/core/agent-status-mirror.ts
@@ -212,6 +212,10 @@ export interface InboxEvent {
* phone can render numbered chips / notification actions. Absent for approvals + plain questions
* (spec: interactive-push-live-activities). */
options?: string[]
+ /** question only: the AskUserQuestion `questions[0].multiSelect` flag — the picker accepts more
+ * than one choice. Rides the pipeline so the phone renders multi-select chips. Omitted when
+ * absent/false (spec: interactive-push-live-activities). */
+ multiSelect?: boolean
/** approval only: the deterministic hook-reply ticket (docs/hook-reply-approvals.md). Present when
* the managed permission hook is holding open for an answer — the phone/canvas write
* `~/.nodeterm/pending/<pendingId>.answer` to answer it. Rides the mirror to the phone; dropped
@@ -468,6 +472,9 @@ export interface NodeStateChange {
/** question needsYou only: the AskUserQuestion choices from the stash (≤4 × ≤60), so the phone
* can render option buttons straight from the Live Activity. Absent otherwise. */
options?: string[]
+ /** question needsYou only: the AskUserQuestion `multiSelect` flag from the stash. Omitted when
+ * absent/false. */
+ multiSelect?: boolean
/** 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
@@ -530,6 +537,8 @@ interface QuestionStash {
options?: string[]
/** The first question's prompt text, clipped to INBOX_TITLE_MAX. Absent if not present/parseable. */
question?: string
+ /** AskUserQuestion `questions[0].multiSelect` (tolerant boolean). Absent when not present/false. */
+ multiSelect?: boolean
/** PermissionRequest: the derived "what's being approved" summary (title + optional detail). */
approval?: { title: string; detail?: string }
/** When the AskUserQuestion PreToolUse / PermissionRequest stashed this — freshness-guard anchor. */
@@ -596,6 +605,25 @@ export function extractQuestionText(
}
}
+/**
+ * Extract the first question's `multiSelect` flag from an AskUserQuestion `tool_input`
+ * (`questions[0].multiSelect`). Pure; TOLERANT — a non-boolean or any shape mismatch yields
+ * `undefined` (treated the same as `false` downstream). Rides the stash so the next question event +
+ * push carry it (spec: interactive-push-live-activities).
+ */
+export function extractQuestionMultiSelect(
+ toolInput: Record<string, unknown> | undefined
+): boolean | undefined {
+ try {
+ const questions = (toolInput as { questions?: unknown })?.questions
+ if (!Array.isArray(questions) || questions.length === 0) return undefined
+ const ms = (questions[0] as { multiSelect?: unknown })?.multiSelect
+ return typeof ms === 'boolean' ? ms : undefined
+ } catch {
+ return undefined
+ }
+}
+
/** mcp tool short name: `mcp__<server>__<tool>` → `<tool>`. Degrades gracefully on odd shapes. */
function mcpShortName(name: string): string {
const parts = name.split('__').filter(Boolean)
@@ -847,6 +875,8 @@ function produceInboxFromState(
// Only a real AskUserQuestion picker (options present) forces the QUESTION classification — an
// approval-only stash (a PermissionRequest summary) must stay an approval.
const options = stash?.options
+ // multiSelect rides only a real question (options present) — an approval-only stash never sets it.
+ const multiSelect = options ? stash?.multiSelect : undefined
const hasQuestion = !!options
const kind: 'approval' | 'question' = hasQuestion || nextState === 'waiting' ? 'question' : 'approval'
const approval = kind === 'approval' ? stash?.approval : undefined
@@ -886,6 +916,7 @@ function produceInboxFromState(
kind,
message: headline,
...(options ? { options } : {}),
+ ...(multiSelect ? { multiSelect: true } : {}),
...(pendingId ? { pendingId } : {})
})
}
@@ -896,6 +927,7 @@ function produceInboxFromState(
title,
...(detail ? { detail } : {}),
...(options ? { options } : {}),
+ ...(multiSelect ? { multiSelect: true } : {}),
...(pendingId ? { pendingId } : {})
})
} else if (nextState === 'done' && prevState !== 'done') {
@@ -946,7 +978,13 @@ export function recordRawToolEvent(nodeId: string, payload: Record<string, unkno
// shape mismatch leaves no stash.
if (toolName === 'AskUserQuestion') {
const opts = extractQuestionOptions(toolInput)
- if (opts) pendingQuestions.set(nodeId, { options: opts, question: extractQuestionText(toolInput), at: now })
+ if (opts)
+ pendingQuestions.set(nodeId, {
+ options: opts,
+ question: extractQuestionText(toolInput),
+ multiSelect: extractQuestionMultiSelect(toolInput),
+ at: now
+ })
}
const activity = toolActivity(toolName, toolInput)
const cur = inboxNodes.get(nodeId)
diff --git a/src/core/push-notify.test.ts b/src/core/push-notify.test.ts
index dcd078f07..bd627dd14 100644
--- a/src/core/push-notify.test.ts
+++ b/src/core/push-notify.test.ts
@@ -12,13 +12,17 @@ import {
} from './push-notify'
import {
onInboxActionable,
+ onNodeStateChange,
+ onNodeNowChange,
recordAgentEvent,
+ recordRawToolEvent,
initAgentStatusMirror,
_resetForTest,
type InboxEvent,
type NodeStateChange,
type NodeNowChange
} from './agent-status-mirror'
+import { syntheticAnsweredEvent } from './agents/pending-approvals'
/** A generic manual event source standing in for the mirror subscribe seams. */
function emitter<T>(): { subscribe: (cb: (e: T) => void) => () => void; emit: (e: T) => void } {
@@ -444,6 +448,26 @@ describe('createPushNotify', () => {
expect(bodyOf().events[0]).not.toHaveProperty('options')
h.stop()
})
+
+ it('passes multiSelect through when the question is multi-select', async () => {
+ const em = makeEmitter()
+ const h = createPushNotify(baseDeps({ subscribe: em.subscribe }))
+ em.emit(iev({ nodeId: 'a', kind: 'question', title: 'Pick', options: ['A', 'B'], multiSelect: true }))
+ await vi.advanceTimersByTimeAsync(2000)
+ expect(bodyOf().events[0].multiSelect).toBe(true)
+ expect(bodyOf().events[0].options).toEqual(['A', 'B'])
+ h.stop()
+ })
+
+ it('omits multiSelect when absent or false', async () => {
+ const em = makeEmitter()
+ const h = createPushNotify(baseDeps({ subscribe: em.subscribe }))
+ em.emit(iev({ nodeId: 'a', kind: 'question', title: 'Pick', options: ['A'], multiSelect: false }))
+ em.emit(iev({ nodeId: 'b', kind: 'question', title: 'Pick', options: ['A'] }))
+ await vi.advanceTimersByTimeAsync(2000)
+ for (const e of bodyOf().events) expect(e).not.toHaveProperty('multiSelect')
+ h.stop()
+ })
})
it('stop() unsubscribes so later events are ignored', async () => {
@@ -535,6 +559,8 @@ describe('createLiveUpdatePush', () => {
agentId: 'claude',
event: 'update',
state: 'needsYou',
+ // A state edge (here the needsYou edge) is marked so the backend can prioritize it (10 vs 5).
+ edge: true,
message: 'Approve write',
ts: 42
})
@@ -703,6 +729,110 @@ describe('createLiveUpdatePush', () => {
expect(u).not.toHaveProperty('pendingId')
h.stop()
})
+
+ it('passes multiSelect on a question needsYou edge; omits it when absent', async () => {
+ const { h, st } = wire()
+ st.emit({
+ nodeId: 'a',
+ event: 'update',
+ state: 'needsYou',
+ kind: 'question',
+ options: ['A', 'B'],
+ multiSelect: true,
+ ts: 1
+ })
+ st.emit({ nodeId: 'b', event: 'update', state: 'needsYou', kind: 'question', options: ['A'], ts: 2 })
+ await vi.advanceTimersByTimeAsync(1000)
+ expect(liveBodyOf().updates[0].multiSelect).toBe(true)
+ expect(liveBodyOf().updates[1]).not.toHaveProperty('multiSelect')
+ h.stop()
+ })
+
+ it('never carries multiSelect on a working/done edge even if the change object has it', async () => {
+ const { h, st } = wire()
+ // Belt-and-braces: a non-needsYou change with a stray multiSelect must not leak it.
+ st.emit({ nodeId: 'a', event: 'start', state: 'working', multiSelect: true, ts: 1 } as NodeStateChange)
+ await vi.advanceTimersByTimeAsync(1000)
+ expect(liveBodyOf().updates[0]).not.toHaveProperty('multiSelect')
+ h.stop()
+ })
+ })
+
+ describe('state-edge marking (edge flag)', () => {
+ it('marks every state edge (start/needsYou/end) with edge:true', async () => {
+ const { h, st } = wire()
+ st.emit({ nodeId: 'a', event: 'start', state: 'working', ts: 1 })
+ st.emit({ nodeId: 'b', event: 'update', state: 'needsYou', message: 'Approve', ts: 2 })
+ st.emit({ nodeId: 'c', event: 'end', state: 'done', message: 'Finished', ts: 3 })
+ await vi.advanceTimersByTimeAsync(1000)
+ for (const u of liveBodyOf().updates) expect(u.edge).toBe(true)
+ h.stop()
+ })
+
+ it('never marks a now-tick (activity/context) with edge', async () => {
+ const { h, nw } = wire()
+ clock = 0
+ nw.emit({ nodeId: 'a', activity: 'Editing a.ts', contextPercent: 10, ts: 0 })
+ await vi.advanceTimersByTimeAsync(1000)
+ expect(liveBodyOf().updates[0]).not.toHaveProperty('edge')
+ h.stop()
+ })
+
+ // Wire the live-update push to the REAL mirror seams so the synthetic answered blocked→working
+ // transition (built exactly as the held hook's second POST) is exercised end-to-end.
+ describe('via the real mirror', () => {
+ let dir: string
+ beforeEach(() => {
+ _resetForTest()
+ dir = fs.mkdtempSync(path.join(os.tmpdir(), 'push-edge-'))
+ initAgentStatusMirror(path.join(dir, 'agent-status.json'))
+ })
+ afterEach(() => {
+ _resetForTest()
+ fs.rmSync(dir, { recursive: true, force: true })
+ })
+
+ function ev(p: Partial<NormalizedAgentEvent>): NormalizedAgentEvent {
+ return { nodeId: 'n1', agentId: 'claude', kind: 'state', ...p } as NormalizedAgentEvent
+ }
+
+ it('the answered blocked→working synthetic transition flows through onNodeStateChange as an edge', async () => {
+ const h = createLiveUpdatePush(
+ liveDeps({ subscribeStateChange: onNodeStateChange, subscribeNowChange: onNodeNowChange })
+ )
+ recordAgentEvent(ev({ state: 'working', newTurn: true })) // start edge
+ recordAgentEvent(ev({ state: 'blocked', lastMessage: 'Approve write', pendingId: 'n1-1-1' })) // needsYou edge
+ // The answered signal (allow) → synthetic working, i.e. a blocked→working state edge.
+ recordAgentEvent(syntheticAnsweredEvent('n1', 'n1-1-1', 'allow')!)
+ recordAgentEvent(ev({ state: 'done', lastMessage: 'Done' })) // end edge
+ await vi.advanceTimersByTimeAsync(1000)
+ const updates = liveBodyOf().updates
+ // Four state edges, and every one is marked.
+ expect(updates.map((u: Record<string, unknown>) => [u.event, u.state])).toEqual([
+ ['start', 'working'],
+ ['update', 'needsYou'],
+ ['start', 'working'],
+ ['end', 'done']
+ ])
+ for (const u of updates) expect(u.edge).toBe(true)
+ h.stop()
+ })
+
+ it('activity ticks interleaved with edges stay unmarked while edges are marked', async () => {
+ const h = createLiveUpdatePush(
+ liveDeps({ subscribeStateChange: onNodeStateChange, subscribeNowChange: onNodeNowChange })
+ )
+ recordAgentEvent(ev({ state: 'working', newTurn: true })) // start edge
+ recordRawToolEvent('n1', { hook_event_name: 'PreToolUse', tool_name: 'Bash', tool_input: { command: 'ls' } }) // now-tick
+ await vi.advanceTimersByTimeAsync(1000)
+ const updates = liveBodyOf().updates
+ const start = updates.find((u: Record<string, unknown>) => u.event === 'start')!
+ const tick = updates.find((u: Record<string, unknown>) => u.activity === 'Running ls')!
+ expect(start.edge).toBe(true)
+ expect(tick).not.toHaveProperty('edge')
+ h.stop()
+ })
+ })
})
it('stop() unsubscribes both seams so later events are ignored', async () => {
diff --git a/src/core/push-notify.ts b/src/core/push-notify.ts
index 3b5e7efcb..a2e74b021 100644
--- a/src/core/push-notify.ts
+++ b/src/core/push-notify.ts
@@ -53,6 +53,9 @@ export interface PushNotifyEvent {
* them as numbered notification actions + appends them to the body (spec:
* interactive-push-live-activities). Absent for approvals + plain questions. */
options?: string[]
+ /** question only: the AskUserQuestion `multiSelect` flag — the picker accepts multiple choices.
+ * Rides the `nt` block so the phone renders multi-select. Omitted when absent/false. */
+ multiSelect?: boolean
ts: number
}
@@ -171,6 +174,7 @@ export function createPushNotify(deps: PushNotifyDeps): PushNotifyHandle {
...(e.agentId ? { agentId: e.agentId } : {}),
...(nodeTitle ? { nodeTitle } : {}),
...(e.options && e.options.length > 0 ? { options: e.options } : {}),
+ ...(e.multiSelect ? { multiSelect: true } : {}),
ts: e.ts
})
scheduleFlush()
@@ -261,8 +265,15 @@ export interface LiveUpdateItem {
kind?: 'approval' | 'question'
/** question needsYou only: the AskUserQuestion choices (≤4 × ≤60), for Live Activity buttons. */
options?: string[]
+ /** question needsYou only: the AskUserQuestion `multiSelect` flag. Omitted when absent/false. */
+ multiSelect?: boolean
/** approval needsYou only: the deterministic hook-reply ticket, letting an intent answer. */
pendingId?: string
+ /** true on a state EDGE (start / needsYou / end, and the working update that follows an answered
+ * needs-you) — a user-visible state change. Absent on the ≥20s activity/context coalesced ticks.
+ * The backend uses it for APNs priority: an edge is priority 10, a tick priority 5 (iOS delays
+ * priority-5 liveactivity pushes, which was leaving the island up minutes after an answer). */
+ edge?: boolean
ts: number
}
@@ -350,9 +361,9 @@ export function createLiveUpdatePush(deps: LiveUpdateDeps): LiveUpdateHandle {
function onStateChange(c: NodeStateChange): void {
if (!liveIdentity()) return
const title = nodeTitleOf(c.nodeId)
- // kind/options/pendingId ride only a needsYou edge (spec: interactive-push-live-activities
- // addendum) — belt-and-braces gate on state so a working/done edge never carries them (the
- // backend also nulls them on non-needsYou content-state).
+ // kind/options/multiSelect/pendingId ride only a needsYou edge (spec:
+ // interactive-push-live-activities addendum) — belt-and-braces gate on state so a working/done
+ // edge never carries them (the backend also nulls them on non-needsYou content-state).
const needsYou = c.state === 'needsYou'
buffer.push({
nodeId: c.nodeId,
@@ -360,9 +371,14 @@ export function createLiveUpdatePush(deps: LiveUpdateDeps): LiveUpdateHandle {
...(c.agentId ? { agentId: c.agentId } : {}),
event: c.event,
state: c.state,
+ // Every onStateChange push IS a state edge (start / needsYou / end, and the working update
+ // that follows an answered needs-you) — mark it so the backend can prioritize it (10 vs the
+ // ticks' 5). The now-tick sender (emitNow) deliberately omits this.
+ edge: true,
...(c.message ? { message: c.message.slice(0, LIVE_MESSAGE_MAX) } : {}),
...(needsYou && c.kind ? { kind: c.kind } : {}),
...(needsYou && c.options && c.options.length > 0 ? { options: c.options } : {}),
+ ...(needsYou && c.multiSelect ? { multiSelect: true } : {}),
...(needsYou && c.pendingId ? { pendingId: c.pendingId } : {}),
ts: c.ts
})