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(grok): the routine per-tool permission prompt is not a NEEDS YOU
enescef081a9746e
diff --git a/src/shared/agents/normalize.grok.test.ts b/src/shared/agents/normalize.grok.test.tsindex 02f8f5dfa..a047d07d0 100644--- a/src/shared/agents/normalize.grok.test.ts+++ b/src/shared/agents/normalize.grok.test.ts@@ -81,17 +81,120 @@ describe('normalizeGrok — Stop', () => {})})+/**+ * Notification is the one grok event nobody here could measure, and the two sources that describe it+ * disagree — so every expectation below cites the source it encodes, and ALL of it is inference:+ *+ * - orca (`/root/orca-main`, MIT, a shipping grok integration) — `permission_prompt` plus prose+ * messages, `src/shared/agent-hook-listener.ts:2370-2402` (readers) and `:3994-4012` (precedence).+ * - grok's own shipped docs — `turn_complete | approval_required | session_ready | task_complete |+ * agent_error`, `~/.grok/docs/user-guide/05-configuration.md:414`.+ *+ * The mapping is therefore built to be safe under BOTH vocabularies: the routine per-tool prompt is+ * suppressed, a genuine ask still reaches NEEDS YOU under either spelling, and anything unrecognized+ * changes no state.+ */describe('normalizeGrok — Notification', () => {- it('a permission notification is blocked; an input request is waiting', () => {+ /**+ * THE regression this branch's first mapping had backwards. Orca's+ * `isGrokRoutinePermissionPromptNotification` (`agent-hook-listener.ts:2378-2389`) exists because+ * "Grok emits this before each tool even under bypassPermissions; PreToolUse already covers+ * progress" — its own named regression test is+ * `src/renderer/src/hooks/agent-hook-completion-notifications.test.ts:654`. Mapping it to `blocked`+ * fires markUnread (no cooldown), the needs-you chime, an OS notification while unfocused and a+ * phone inbox card on EVERY tool call.+ */+ it('the routine per-tool permission prompt is suppressed, not a NEEDS YOU', () => {+ expect(+ normalizeGrok(+ env({+ hookEventName: 'notification',+ notificationType: 'permission_prompt',+ message: 'Tool permission requested',+ level: 'info'+ })+ )+ ).toBeNull()+ // Level absent is the same routine case (orca: `!level || level === 'info'`), and the message is+ // compared trimmed + case-folded.+ expect(+ normalizeGrok(+ env({+ hookEventName: 'notification',+ notificationType: 'permission_prompt',+ message: ' tool permission requested '+ })+ )+ ).toBeNull()+ })++ it('a GENUINE ask still reaches NEEDS YOU — the suppression is narrow, not a mute', () => {+ // Same type, a real message: this is the ask a human must answer.+ expect(+ normalizeGrok(+ env({+ hookEventName: 'notification',+ notificationType: 'permission_prompt',+ message: 'Bash wants to run `rm -rf build`'+ })+ )+ ).toMatchObject({ state: 'blocked' })+ // Same type and the routine message, but LOUDER than info — orca's level condition fails, so it+ // is treated as a real ask rather than swallowed.expect(- normalizeGrok(env({ hookEventName: 'notification', notificationType: 'permission_prompt' }))+ normalizeGrok(+ env({+ hookEventName: 'notification',+ notificationType: 'permission_prompt',+ message: 'tool permission requested',+ level: 'warn'+ })+ )).toMatchObject({ state: 'blocked' })expect(normalizeGrok(env({ hookEventName: 'notification', notificationType: 'agent_needs_input' }))).toMatchObject({ state: 'waiting' })})- it('an idle notification is the rescue signal (done + idle), not a NEEDS YOU', () => {+ /**+ * grok's own docs name `approval_required` (05-configuration.md:414) where orca names+ * `permission_prompt`; the two share no substring, so both are matched. Without this the mapping+ * fires for NOTHING if the docs' vocabulary turns out to be the real one.+ */+ it("maps grok's own documented `approval_required` to NEEDS YOU as well", () => {+ expect(+ normalizeGrok(env({ hookEventName: 'notification', notificationType: 'approval_required' }))+ ).toMatchObject({ state: 'blocked' })+ })++ /**+ * The rescue signal, and the reason it must key off the MESSAGE: grok states its idle prompt in+ * prose (orca's `isGrokIdleNotification`, `agent-hook-listener.ts:2391-2402`) and neither source+ * names an "idle" TYPE — so the type-only test this replaced could never fire. It is the only thing+ * that can clear a node stuck on `working` after an Esc, because grok sends no hook for an+ * interrupted turn at all.+ */+ it('detects idle from the MESSAGE — each of orca\'s four phrases clears the badge', () => {+ for (const message of [+ 'Type your message or @path/to/file',+ 'enter send · shift-tab normal mode',+ 'shift-tab normal mode',+ 'Ask a side question without interrupting'+ ]) {+ expect(+ normalizeGrok(env({ hookEventName: 'notification', notificationType: 'session_ready', message })),+ message+ ).toMatchObject({ state: 'done', idle: true, interrupted: true })+ }+ // No type at all is still enough — the message carries it.+ expect(+ normalizeGrok(env({ hookEventName: 'notification', message: 'TYPE YOUR MESSAGE' }))+ ).toMatchObject({ state: 'done', idle: true, interrupted: true })+ })++ it('keeps a type-based idle fallback for a message-less notification', () => {+ // Belt and braces: unlike a substring test on an ASK word, a false positive here can only CLEAR+ // a badge — it can never leave one stuck.expect(normalizeGrok(env({ hookEventName: 'notification', notificationType: 'idle_prompt' }))).toMatchObject({state: 'done',idle: true,@@ -99,6 +202,37 @@ describe('normalizeGrok — Notification', () => {})})+ /**+ * Precedence, mirroring orca's own order (`agent-hook-listener.ts:3994-4012`: routine-suppress,+ * then ask, then idle): a payload claiming BOTH an ask type and idle prose is asking. A wrongly+ * cleared NEEDS YOU is the failure this branch exists to prevent; a badge that lingers one hook+ * longer is not.+ */+ it('an ask type wins over idle prose in the same payload', () => {+ expect(+ normalizeGrok(+ env({+ hookEventName: 'notification',+ notificationType: 'permission_request',+ message: 'Approve? (type your message to answer)'+ })+ )+ ).toMatchObject({ state: 'blocked' })+ })++ /**+ * Orca reads the kind from THREE keys (`notificationType ?? notification_type ?? type`,+ * `agent-hook-listener.ts:2370-2376`); the third was missing here.+ */+ it('reads the notification kind from the bare `type` key too', () => {+ expect(normalizeGrok(env({ hookEventName: 'notification', type: 'approval_required' }))).toMatchObject({+ state: 'blocked'+ })+ expect(+ normalizeGrok(env({ hookEventName: 'notification', type: 'agent_needs_input' }))+ ).toMatchObject({ state: 'waiting' })+ })+it('an UNKNOWN notification type is a no-op — a future type must not stick a badge', () => {expect(normalizeGrok(env({ hookEventName: 'notification', notificationType: 'auth_success' }))).toBeNull()expect(normalizeGrok(env({ hookEventName: 'notification' }))).toBeNull()diff --git a/src/shared/agents/normalize.ts b/src/shared/agents/normalize.tsindex 019ad4daa..754b2042c 100644--- a/src/shared/agents/normalize.ts+++ b/src/shared/agents/normalize.ts@@ -338,9 +338,10 @@ export function normalizeOpencode(env: RawHookEnvelope): NormalizedAgentEvent |return null}-// grok hook payload. Its dialect differs from every other agent here in two ways, both measured-// against the shipped 1.0.0 CLI: the keys are camelCase, and `hookEventName`'s VALUE is-// snake_case ("pre_tool_use"). Hooks registered through the grok SDK convert the top-level keys to+// grok hook payload. Its dialect differs from every other agent here in two ways, both taken from+// the shipped 1.0.0 DOCS (no grok binary was available on the machine that wrote this, so nothing+// here is a capture): the keys are camelCase, and `hookEventName`'s VALUE is snake_case+// ("pre_tool_use"). Hooks registered through the grok SDK convert the top-level keys to// snake_case instead, so both spellings occur in the wild — hence every field is read twice and// the event name is CANONICALIZED (lowercased, letters only) rather than compared literally.// There is deliberately no `transcript_path` in this envelope: grok's transcript is DERIVED from@@ -361,11 +362,38 @@ interface GrokPayload {last_assistant_message?: stringnotificationType?: stringnotification_type?: string+ /** Notification only, THIRD spelling of the kind. Not from grok's docs — from orca+ * (`/root/orca-main`, MIT), a shipping grok integration whose reader is+ * `notificationType ?? notification_type ?? type` (`src/shared/agent-hook-listener.ts:2370-2376`).+ * Reading a key a shipped integration reads costs nothing and closes a whole dialect. */+ type?: string+ /** Notification only: the human-readable status line. Orca reads it as a bare `message`+ * (`agent-hook-listener.ts:3973`) — one spelling, so no dual read here — and grok's idle state is+ * detectable ONLY from it (see GROK_IDLE_MESSAGES). */+ message?: string+ /** Notification only: severity. Orca reads a bare `level` (`agent-hook-listener.ts:3975`) and uses+ * it to tell grok's routine per-tool permission prompt (`info`) from a louder one. */+ level?: string/** Stop only: 'end_turn' for a genuine turn end; 'channel_closed'/'shutdown' at session close. */reason?: stringprompt?: string}+/**+ * Fragments of a grok `Notification` MESSAGE that mean "sat at the prompt, nothing running".+ *+ * Provenance: orca's `isGrokIdleNotification` (`/root/orca-main/src/shared/agent-hook-listener.ts:2391-2402`,+ * MIT), matched case-insensitively as substrings of the message — grok states its idle prompt in+ * prose ("Type your message…", "shift-tab normal mode"), not with a notification TYPE. This list is+ * therefore INFERRED from another integration's reader, not measured here: no grok binary was run.+ */+const GROK_IDLE_MESSAGES = [+ 'type your message',+ 'enter send',+ 'shift-tab normal',+ 'ask a side question'+] as const+/** Canonical form of a grok event name: 'pre_tool_use', 'PreToolUse' and 'preToolUse' all → 'pretooluse'. */const grokEventName = (p: GrokPayload): string =>(p.hookEventName ?? p.hook_event_name ?? '').toLowerCase().replace(/[^a-z]/g, '')@@ -432,14 +460,46 @@ export function normalizeGrok(env: RawHookEnvelope): NormalizedAgentEvent | null// The turn died on an API error — grok skips Stop entirely here, exactly as Claude does.if (ev === 'stopfailure') return { ...base, kind: 'state', state: 'done', lastMessage }if (ev === 'notification') {- // Everything unrecognized is a deliberate NO-OP: same discipline as normalizeClaude, where an+ // grok's Notification is the one event whose vocabulary we could not measure, and the three+ // sources that describe it do not agree, so this mapping is deliberately safe in BOTH+ // directions. Every line below cites where its words come from; all of it is INFERENCE — no+ // grok binary was run on the machine that wrote it.+ // - orca (`/root/orca-main`, MIT, a shipping grok integration) names `permission_prompt`+ // plus prose messages (`agent-hook-listener.ts:2378-2402`).+ // - grok's own shipped docs name a different set entirely:+ // `turn_complete | approval_required | session_ready | task_complete | agent_error`+ // (`~/.grok/docs/user-guide/05-configuration.md:414`).+ // Everything unrecognized stays a deliberate NO-OP: same discipline as normalizeClaude, where an// unknown future type sticking a badge on a finished node is the failure that has actually// happened before.- const type = (p.notificationType ?? p.notification_type ?? '').toLowerCase()- // A permission ask is genuinely a FAMILY of names ('permission_prompt', 'permission_request',- // …), and its worst case is a `blocked` badge the agent's next hook clears — so substring is- // the right trade here.- if (type.includes('permission')) return { ...base, kind: 'state', state: 'blocked', lastMessage }+ const type = (p.notificationType ?? p.notification_type ?? p.type ?? '').toLowerCase()+ const message = (p.message ?? '').trim().toLowerCase()+ const level = (p.level ?? '').trim().toLowerCase()+ // THE ROUTINE PER-TOOL PROMPT IS NOT A NEEDS-YOU. Orca's+ // `isGrokRoutinePermissionPromptNotification` (`agent-hook-listener.ts:2378-2389`) suppresses it,+ // comment verbatim: "Grok emits this before each tool even under bypassPermissions; PreToolUse+ // already covers progress." Its regression test is+ // `src/renderer/src/hooks/agent-hook-completion-notifications.test.ts:654`.+ // Left unsuppressed, EVERY grok tool call would raise `blocked` here, and downstream that edge+ // has no de-duplication: markUnread with no cooldown, the needs-you chime, an OS notification+ // whenever the window is unfocused, and one phone inbox card per working→blocked edge.+ // Matched exactly as orca matches it — the precise type, the precise message, and a level that+ // is `info` or absent — so a LOUDER prompt (a real ask reusing the same type) still gets through.+ if (+ type === 'permission_prompt' &&+ message === 'tool permission requested' &&+ (!level || level === 'info')+ ) {+ return null+ }+ // A genuine permission ask is a FAMILY of names ('permission_prompt', 'permission_request', …),+ // and its worst case is a `blocked` badge the agent's next hook clears — so substring is the+ // right trade. `approval_required` is grok's OWN word for it (05-configuration.md:414) and is+ // matched exactly: it shares no substring with the orca spelling, and adding it is what keeps+ // this mapping from firing for nothing if the docs' vocabulary is the real one.+ if (type.includes('permission') || type === 'approval_required') {+ return { ...base, kind: 'state', state: 'blocked', lastMessage }+ }// The asking types are a CLOSED set, exactly as in normalizeClaude, and for its reason: grok's// vocabulary is claude-derived, and claude's `elicitation_complete` / `elicitation_response` are// informational — they fire when an elicitation ENDS. A substring test on 'elicit' would match@@ -447,9 +507,17 @@ export function normalizeGrok(env: RawHookEnvelope): NormalizedAgentEvent | nullif (type === 'elicitation_dialog' || type === 'agent_needs_input') {return { ...base, kind: 'state', state: 'waiting', lastMessage }}- // Idle at the prompt: the RESCUE signal for a node stuck on `working`. grok fires no hook at- // all for an interrupted turn, so this is the only thing that can clear one.- if (type.includes('idle')) {+ // Idle at the prompt: the RESCUE signal for a node stuck on `working`. grok fires no hook at all+ // for an interrupted turn (Esc), so this is the only thing that can ever clear one — which is+ // why it is keyed off the MESSAGE (GROK_IDLE_MESSAGES, per orca) and not off a type. A+ // type-only test was dead code: neither source names an "idle" type.+ // It is checked AFTER the ask branches on purpose, mirroring orca's own precedence+ // (`agent-hook-listener.ts:3994-4012`: routine-suppress, then ask, then idle) — a payload that+ // claims both an ask type and idle prose is asking, and a wrongly-cleared badge is the failure+ // this whole branch exists to prevent. `type.includes('idle')` is kept as a belt-and-braces+ // fallback for a message-less idle notification: unlike a substring test on an ASK word it can+ // only ever CLEAR a badge, so a false positive costs a badge, never a stuck one.+ if (GROK_IDLE_MESSAGES.some((m) => message.includes(m)) || type.includes('idle')) {return { ...base, kind: 'state', state: 'done', interrupted: true, idle: true }}return null