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): canonicalize the notification type, and correct four close-out residuals
enes9602d3a250c0
diff --git a/docs/grok-agent.md b/docs/grok-agent.mdindex be8a455cf..5e864e82e 100644--- a/docs/grok-agent.md+++ b/docs/grok-agent.md@@ -109,8 +109,8 @@ deliberate no-op:| `Stop` (`reason` anything but `channel_closed`/`shutdown`) | `done` + `lastMessage` | a **denylist**, not an allowlist of `end_turn`: `Stop` is the event the RUNNING badge depends on ending, so an unknown reason must fail towards reporting it || `Stop` (`channel_closed` / `shutdown`) | `done`, `interrupted: true` | the observe-only second `Stop` at session close; `interrupted` suppresses the completion alert and unread dot, and the stale `lastAssistantMessage` is dropped || `StopFailure` | `done` + `lastMessage` | fires **instead of** `Stop` when the turn dies on an API error — without it the badge sticks |-| `Notification` `permission_prompt` + message `tool permission requested` + level `info`/absent | **nothing** (`null`) | grok emits this before **every** tool call, even under `bypassPermissions` (orca's `isGrokRoutinePermissionPromptNotification`, `agent-hook-listener.ts:2378-2389`). Mapping it to `blocked` fired `markUnread` with no cooldown, the needs-you chime, an OS notification per tool call while unfocused, and a phone inbox card per `working→blocked` edge. Matched exactly, so a **louder** prompt with the same type still gets through |-| `Notification` `*permission*` / `approval_required` | `blocked` | substring for the permission family (its worst case is a badge the next hook clears), plus grok's own documented word for the same thing (`05-configuration.md:414`) — the two spellings share no substring, and matching both is what keeps this mapping from firing for nothing under either vocabulary |+| `Notification` `permission_prompt` + message `tool permission requested` + level `info`/absent | **nothing** (`null`) | grok emits this before **every** tool call, even under `bypassPermissions` (orca's `isGrokRoutinePermissionPromptNotification`, `agent-hook-listener.ts:2378-2389`). The type is canonicalized first (`grokCanonical`, the same letters-only rule the event name uses), so the camelCase spelling grok's envelope would plausibly carry — `permissionPrompt` — is suppressed too; comparing raw would drop it into the ask row below and reinstate the strobe. Mapping it to `blocked` fired `markUnread` with no cooldown, the needs-you chime, an OS notification per tool call while unfocused, and a phone inbox card per `working→blocked` edge. Matched exactly, so a **louder** prompt with the same type still gets through |+| `Notification` `*permission*` / `approval_required` | `blocked` | substring for the permission family (its worst case is a badge the next hook clears), plus `approval_required` — which is **inference on inference**: `05-configuration.md:414` names it as a notification *trigger*, not as a `notificationType` value, and the bridge is `10-hooks.md:153` ("the matcher tests … the notification type on `Notification`"). Matched exactly for that reason. The two spellings share no substring, and matching both is what keeps this mapping from firing for nothing under either vocabulary || `Notification` `elicitation_dialog` / `agent_needs_input` | `waiting` | a **closed set**, exactly as in `normalizeClaude`: a substring test on `elicit` would also match claude's informational `elicitation_complete`/`_response` and leave NEEDS YOU on a node that just finished, with no later hook to clear it || `Notification` whose **message** reads idle (`type your message`, `enter send`, `shift-tab normal`, `ask a side question`; `*idle*` type as a fallback) | `done`, `interrupted`, `idle` | the **rescue** signal for a node stuck on `working` — see §8. Keyed on the MESSAGE because that is where grok states it (orca's `isGrokIdleNotification`, `:2391-2402`); a type-only test never fired, since no source names an "idle" type. Checked **after** the ask branches, mirroring orca's own precedence (`:3994-4012`) |@@ -375,7 +375,11 @@ ai-name / comments).a user whose `export GROK_HOME=…` lives in `.zshrc`, we write the hook file under `~/.grok` and grokreads somewhere else: no badge, no unread dot, no notification, no session name, **ever**, and nodiagnostic. Same class as `findTmux()` resolving an absolute path "because GUI apps don't inherit the- shell PATH", and the same trap the SSH side already handles properly (checklist **26**). Fixing it+ shell PATH". The SSH side is **better but not immune**, and the distinction matters: it at least asks+ the host and validates the answer (`isSafeRemoteGrokHome`) before falling back deliberately — but the+ probe runs over a **plain ssh exec channel**, so a host exporting `GROK_HOME` only from `.bashrc`+ reports empty and silently gets `~/.grok`. That is checklist **26**, which exists because the remote+ side shares the blind spot, not because it is solved there. Fixing itmeans probing the login shell — a change with its own failure modes, not a comment — so checklist**31** asks first whether anyone sets the variable at all. The trap is documented at `grokHomeDir`.@@ -442,8 +446,19 @@ State machine edges9. Press Esc mid-turn. Expected (documented): NO hook fires and the badge stays RUNNING untilthe next prompt. Confirm, and record how bad it feels — this decides whether a watchdog isworth building.-10. Trigger a permission prompt (a mode that asks). Does ANY Notification fire, and with what- `notificationType`? This is the only path to a NEEDS YOU badge; record the vocabulary.+10. The `Notification` capture — the highest-value item on this list, because the mapping in §5 rests+ entirely on another integration's reader. Record, VERBATIM and per notification, all THREE fields+ the mapping reads: the kind (`notificationType` / `notification_type` / `type` — note which key,+ and its exact casing), `message`, and `level`. Do it for BOTH cases, because they are handled+ oppositely and only the exact strings can tell them apart:+ (a) a **routine** run — one turn with several tool calls, under `auto` AND under+ `bypassPermissions`, window in the BACKGROUND. If a notification fires per tool call, our+ suppression must match its message/level exactly or the node strobes NEEDS YOU (chime + OS+ notification + phone card per tool call). Count the notifications against the tool calls.+ (b) a **genuine** ask that needs a human answer. That one must still reach `blocked`.+ Also note whether an IDLE notification exists at all and its exact message (item 9's rescue+ depends on the four phrases in `GROK_IDLE_MESSAGES`). This is the only path to a NEEDS YOU badge;+ record the vocabulary.11. Force an API error (e.g. an invalid model). Does StopFailure clear the RUNNING badge?12. Quit with `/quit`. Does the session-close Stop stay silent (no "agent finished" notification)?diff --git a/src/core/agents/grok-paths.ts b/src/core/agents/grok-paths.tsindex 062bd377d..b4c46b660 100644--- a/src/core/agents/grok-paths.ts+++ b/src/core/agents/grok-paths.ts@@ -12,7 +12,9 @@// file's contract. Should a renderer surface ever need one of these helpers, split the genuinely// pure half out (the encoding/validation functions) instead of moving the file back.//-// Measured layout (shipped 1.0.0):+// Layout per grok's shipped 1.0.0 docs (`~/.grok/docs/user-guide/17-sessions.md:18,27`) — NOT observed:+// the branch never had a logged-in session, so no `$GROK_HOME/sessions/` tree ever existed here to+// look at. Every path rule below is therefore a claim about that document:// $GROK_HOME/hooks/*.json — hook files, all merged; GROK_HOME defaults to ~/.grok// $GROK_HOME/sessions/<encoded cwd>/<id>/ — one directory per session, grouped by cwd// summary.json updates.jsonl chat_history.jsonl signals.json plan.json subagents/@@ -52,8 +54,14 @@ type GrokEnv = { GROK_HOME?: string }* tmux pane, which DID source that rc — reads the exported path. Nothing errors. The hook file is* written successfully, grok never loads it, and the consequence is total and silent: no RUNNING /* NEEDS YOU badge, no unread dot, no completion notification, no session name, ever, with no- * diagnostic anywhere. The REMOTE path does not have this problem (`RemoteHooks.installGrokRemote`- * asks the host through a login shell and validates the answer with `isSafeRemoteGrokHome`).+ * diagnostic anywhere.+ *+ * The REMOTE path is BETTER, not immune, and the difference is worth being precise about: it at least+ * ASKS the host (`RemoteHooks.installGrokRemote` runs `printf %s "${GROK_HOME:-}"`) and validates the+ * answer (`isSafeRemoteGrokHome`) before falling back to `$HOME/.grok` deliberately. But that probe+ * goes over a **plain ssh exec channel**, not a login shell, so it shares this exact blind spot: a+ * host that exports `GROK_HOME` only from `.bashrc` reports empty and silently gets `~/.grok`. That is+ * checklist item 26, which exists BECAUSE the remote side has the problem too.** Deliberately NOT fixed here: resolving it means probing the user's login shell for `GROK_HOME`* (a spawn, a cache, and a fail-open policy), which is its own change with its own failure modes —diff --git a/src/core/agents/hooks/grok.test.ts b/src/core/agents/hooks/grok.test.tsindex 94764dbce..d5af69257 100644--- a/src/core/agents/hooks/grok.test.ts+++ b/src/core/agents/hooks/grok.test.ts@@ -38,7 +38,7 @@ describe('grok hook installer', () => {)})- it('writes the `.*` matcher on tool events — a bare `*` is invalid and kills them silently', async () => {+ it('writes the `.*` matcher on tool events — the matcher is a REGEX, so a bare `*` would not compile', async () => {const { installGrokHooks, grokHookConfigPath } = await import('./grok')installGrokHooks()const cfg = read(grokHookConfigPath())diff --git a/src/shared/agents/hook-events.ts b/src/shared/agents/hook-events.tsindex 1a7d20dbc..8b6281919 100644--- a/src/shared/agents/hook-events.ts+++ b/src/shared/agents/hook-events.ts@@ -13,10 +13,12 @@/*** One managed hook subscription: an event name, or an event name PLUS the matcher to write for it.- * Only grok needs the second form — its tool-event `matcher` is a real REGEX, and a bare `*` is- * invalid there and silently stops tool events from firing at all (measured on the shipped 1.0.0- * binary). `.*` is the value that works. claude/codex/gemini stay plain strings, so their emitted- * config is byte-identical to what it has always been.+ * Only grok needs the second form — its tool-event `matcher` is a real REGEX+ * (`~/.grok/docs/user-guide/10-hooks.md:153`), so a bare `*` is not a valid match-all but an invalid+ * pattern, and the expected failure is silence: the tool events simply never fire. We write `.*`.+ * That is read off the docs, not observed — no hook was ever seen firing here (see GROK_HOOK_EVENTS).+ * claude/codex/gemini stay plain strings, so their emitted config is byte-identical to what it has+ * always been.*/export type ManagedHookEvent = string | { event: string; matcher: string }diff --git a/src/shared/agents/normalize.grok.test.ts b/src/shared/agents/normalize.grok.test.tsindex 9e9ba4633..1997d1b5a 100644--- a/src/shared/agents/normalize.grok.test.ts+++ b/src/shared/agents/normalize.grok.test.ts@@ -129,6 +129,41 @@ describe('normalizeGrok — Notification', () => {).toBeNull()})+ /**+ * The suppression must survive grok's OTHER dialect. grok's envelope is documented camelCase+ * throughout, so `permissionPrompt` is a plausible spelling of the same type — and comparing the+ * type raw would make it miss the suppression and fall through to `includes('permission')`, i.e.+ * bring the per-tool-call strobe straight back. The type therefore goes through the same+ * `grokCanonical` rule the event name uses (orca canonicalizes too, to snake_case:+ * `normalizeHookEventName`, `agent-hook-listener.ts:2201-2210`).+ */+ it('suppresses the routine prompt in EVERY spelling of its type', () => {+ for (const notificationType of ['permissionPrompt', 'permission_prompt', 'Permission-Prompt', 'PERMISSION_PROMPT']) {+ expect(+ normalizeGrok(+ env({ hookEventName: 'notification', notificationType, message: 'tool permission requested' })+ ),+ notificationType+ ).toBeNull()+ }+ })++ it('reads the other ask + idle types in camelCase too (one canonicalization, not three)', () => {+ expect(+ normalizeGrok(env({ hookEventName: 'notification', notificationType: 'agentNeedsInput' }))+ ).toMatchObject({ state: 'waiting' })+ expect(+ normalizeGrok(env({ hookEventName: 'notification', notificationType: 'elicitationDialog' }))+ ).toMatchObject({ state: 'waiting' })+ expect(+ normalizeGrok(env({ hookEventName: 'notification', notificationType: 'approvalRequired' }))+ ).toMatchObject({ state: 'blocked' })+ // And the closed set stays closed under canonicalization: an elicitation END is still inert.+ expect(+ normalizeGrok(env({ hookEventName: 'notification', notificationType: 'elicitationComplete' }))+ ).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(diff --git a/src/shared/agents/normalize.ts b/src/shared/agents/normalize.tsindex aeacc3a2c..c064a75d6 100644--- a/src/shared/agents/normalize.ts+++ b/src/shared/agents/normalize.ts@@ -394,9 +394,18 @@ const GROK_IDLE_MESSAGES = ['ask a side question'] as const+/**+ * ONE canonicalization for every grok VALUE we compare — lowercase, letters only, so all of+ * 'pre_tool_use', 'PreToolUse', 'preToolUse' and 'Pre-Tool-Use' land on 'pretooluse'. grok's envelope+ * is documented camelCase while its event values are snake_case, and the SDK path flips the keys, so+ * one dialect rule shared by every comparison in this file is the point: a second spelling rule is+ * how a value gets normalized in one branch and matched raw in another.+ */+const grokCanonical = (v: string | undefined): string => (v ?? '').toLowerCase().replace(/[^a-z]/g, '')+/** 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, '')+ grokCanonical(p.hookEventName ?? p.hook_event_name)/*** The fields the SHELLS need from a raw grok payload, in nodeterm's own names — one definition@@ -467,12 +476,24 @@ export function normalizeGrok(env: RawHookEnvelope): NormalizedAgentEvent | null// - 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`).+ // `turn_complete | approval_required | session_ready | task_complete | agent_error` — but see+ // the `approval_required` branch below: that list is the NOTIFICATION TRIGGER vocabulary+ // (`~/.grok/docs/user-guide/05-configuration.md:414`), not documented `notificationType` values.// 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 ?? p.type ?? '').toLowerCase()+ //+ // The type goes through `grokCanonical`, the SAME rule the event name uses — so the literals+ // below are letters-only ('permission_prompt', 'permissionPrompt' and 'Permission-Prompt' all+ // become 'permissionprompt'). This is not decoration: grok's envelope is documented camelCase+ // throughout, so `permissionPrompt` is a plausible spelling, and comparing it raw would let it+ // MISS the suppression below and fall through to the `includes('permission')` ask branch — i.e.+ // reinstate the per-tool-call strobe in the one direction that hurts. Orca canonicalizes too, to+ // snake_case (`normalizeHookEventName`, `agent-hook-listener.ts:2201-2210`); we reuse OUR one rule+ // rather than adopting a second spelling convention into this file.+ const type = grokCanonical(p.notificationType ?? p.notification_type ?? p.type)+ // message/level are prose, not identifiers: trim + lowercase only, field-for-field as orca reads+ // them (`:3973-3975`). Canonicalizing THESE would strip the spaces the phrases are made of.const message = (p.message ?? '').trim().toLowerCase()const level = (p.level ?? '').trim().toLowerCase()// THE ROUTINE PER-TOOL PROMPT IS NOT A NEEDS-YOU. Orca's@@ -486,7 +507,7 @@ export function normalizeGrok(env: RawHookEnvelope): NormalizedAgentEvent | null// 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' &&+ type === 'permissionprompt' &&message === 'tool permission requested' &&(!level || level === 'info')) {@@ -494,17 +515,21 @@ export function normalizeGrok(env: RawHookEnvelope): NormalizedAgentEvent | 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') {+ // right trade.+ // `approval_required` is INFERENCE ON INFERENCE, and is labelled that way deliberately: grok's+ // docs name it only as a `[ui.notifications].events` TRIGGER (05-configuration.md:414), never as a+ // `notificationType` value. The bridge is `10-hooks.md:153`, "the matcher tests … the notification+ // type on `Notification`", which implies the type vocabulary is drawn from that same set. Weaker+ // than the orca spelling above, and matched exactly for that reason — it costs nothing if wrong+ // (an unused literal) and is the only thing that fires at all if grok's own words are the real ones.+ if (type.includes('permission') || type === 'approvalrequired') {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// them and leave NEEDS YOU on a node that just finished, with no later hook to clear it.- if (type === 'elicitation_dialog' || type === 'agent_needs_input') {+ if (type === 'elicitationdialog' || type === 'agentneedsinput') {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