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(node-header): a refused ✓ Approve / ✕ Deny now says so

reviewfe4e2e6fca10
diff --git a/src/renderer/lib/approveGate.test.ts b/src/renderer/lib/approveGate.test.ts
index 71ab48b41..eefe5e3a6 100644
--- a/src/renderer/lib/approveGate.test.ts
+++ b/src/renderer/lib/approveGate.test.ts
@@ -4,10 +4,10 @@
// core/agent-status-mirror.test.ts); with a stash the mirror strips pendingId and nothing renders.
import { readFileSync } from 'node:fs'
import { resolve } from 'node:path'
-import { describe, expect, it } from 'vitest'
+import { describe, expect, it, vi } from 'vitest'
import { normalizeClaude } from '@shared/agents/normalize'
import { useAgentStatus } from '../state/agentStatus'
-import { canPlainApprove } from './approveGate'
+import { canPlainApprove, sendHeaderAnswer } from './approveGate'
let seq = 0
function held(tool: string, toolInput: unknown): string {
@@ -47,4 +47,44 @@ describe('canPlainApprove', () => {
const src = readFileSync(resolve(__dirname, '../nodes/TerminalNode.tsx'), 'utf8')
expect(src).toContain('{canPlainApprove(status) && (')
})
+ it('both header buttons answer through sendHeaderAnswer (a refusal is never silent)', () => {
+ const src = readFileSync(resolve(__dirname, '../nodes/TerminalNode.tsx'), 'utf8').replace(/\r\n/g, '\n')
+ expect(src.match(/sendHeaderAnswer\(window\.nodeTerminal\.answerPermission, \{/g)).toHaveLength(2)
+ expect(src).not.toContain('void window.nodeTerminal.answerPermission(')
+ })
+})
+
+describe('sendHeaderAnswer — the header ✓/✕ never fails silently', () => {
+ const payload = { nodeId: 'n', pendingId: 'n-1-1', decision: 'allow' as const }
+ it('a refused answer raises an error toast that points at the terminal', async () => {
+ const toast = vi.fn()
+ expect(await sendHeaderAnswer(async () => false, payload, toast)).toBe(false)
+ expect(toast).toHaveBeenCalledWith("Couldn't approve — answer in the terminal")
+ })
+ it('a rejected call is the same refusal (never an unhandled rejection)', async () => {
+ const toast = vi.fn()
+ expect(
+ await sendHeaderAnswer(async () => { throw new Error('ipc down') }, { ...payload, decision: 'deny' }, toast)
+ ).toBe(false)
+ expect(toast).toHaveBeenCalledWith("Couldn't deny — answer in the terminal")
+ })
+ it('a delivered answer says nothing (the badge change is the receipt)', async () => {
+ const toast = vi.fn()
+ const send = vi.fn(async () => true)
+ expect(await sendHeaderAnswer(send, payload, toast)).toBe(true)
+ expect(send).toHaveBeenCalledWith(payload)
+ expect(toast).not.toHaveBeenCalled()
+ })
+ it('the default sink is the app error toast', async () => {
+ const seen: unknown[] = []
+ const g = globalThis as unknown as { window?: { dispatchEvent: (e: { detail: unknown }) => void } }
+ const prev = g.window
+ g.window = { dispatchEvent: (e) => void seen.push(e.detail) }
+ try {
+ await sendHeaderAnswer(async () => false, payload)
+ } finally {
+ g.window = prev
+ }
+ expect(seen).toEqual([{ kind: 'error', message: "Couldn't approve — answer in the terminal" }])
+ })
})
diff --git a/src/renderer/lib/approveGate.ts b/src/renderer/lib/approveGate.ts
index f637720fb..b6e22c2a1 100644
--- a/src/renderer/lib/approveGate.ts
+++ b/src/renderer/lib/approveGate.ts
@@ -1,4 +1,8 @@
-import { ASK_USER_QUESTION_TOOL, type HeldPermission } from '@shared/agents/permission-answer'
+import {
+ ASK_USER_QUESTION_TOOL,
+ type AnswerPermissionPayload,
+ type HeldPermission
+} from '@shared/agents/permission-answer'
/**
* Whether the node header may offer ✓ Approve (a plain `allow`) for the node's current ticket.
@@ -14,3 +18,31 @@ export function canPlainApprove(status: { pendingId?: string; held?: HeldPermiss
if (!status?.pendingId) return false
return !(status.held?.toolName === ASK_USER_QUESTION_TOOL && status.held.pendingId === status.pendingId)
}
+
+/** Where a failed header answer is reported: the app's error toast (the only kind Canvas renders). */
+function errorToast(message: string): void {
+ window.dispatchEvent(new CustomEvent('nodeterm:toast', { detail: { kind: 'error', message } }))
+}
+
+/**
+ * Send the node header's ✓ Approve / ✕ Deny and say so when it did not land. `answerPermission`
+ * resolves `false` when core refuses (an expired hold, a ticket it has no record of, a plain allow a
+ * hook script too old to honour it would drop) — the header used to drop that silently, leaving a
+ * NEEDS YOU badge the user believed they had just answered. A rejected call is the same refusal.
+ * Success says nothing: the badge leaving NEEDS YOU is the receipt. The TUI prompt is untouched either
+ * way, so the message points there.
+ */
+export async function sendHeaderAnswer(
+ send: (payload: AnswerPermissionPayload) => Promise<boolean>,
+ payload: AnswerPermissionPayload & { decision: 'allow' | 'deny' },
+ toast: (message: string) => void = errorToast
+): Promise<boolean> {
+ let ok = false
+ try {
+ ok = (await send(payload)) === true
+ } catch {
+ ok = false
+ }
+ if (!ok) toast(`Couldn't ${payload.decision === 'allow' ? 'approve' : 'deny'} — answer in the terminal`)
+ return ok
+}
diff --git a/src/renderer/nodes/TerminalNode.tsx b/src/renderer/nodes/TerminalNode.tsx
index 3dddae290..e87e41aa9 100644
--- a/src/renderer/nodes/TerminalNode.tsx
+++ b/src/renderer/nodes/TerminalNode.tsx
@@ -1,5 +1,5 @@
import { useContextEnsure } from '../terminal/useContextEnsure'
-import { canPlainApprove } from '../lib/approveGate'
+import { canPlainApprove, sendHeaderAnswer } from '../lib/approveGate'
import { FIND_DECORATIONS } from '../lib/palette'
import { ptyRefusal } from '@shared/pty-refusal'
@@ -5700,7 +5700,7 @@ export function TerminalNode({
className="term-node__approve-btn term-node__approve-btn--allow"
title="Approve this permission request"
onClick={() =>
- void window.nodeTerminal.answerPermission({
+ void sendHeaderAnswer(window.nodeTerminal.answerPermission, {
nodeId: id,
pendingId: status.pendingId!,
decision: 'allow'
@@ -5714,7 +5714,7 @@ export function TerminalNode({
className="term-node__approve-btn term-node__approve-btn--deny"
title="Deny this permission request"
onClick={() =>
- void window.nodeTerminal.answerPermission({
+ void sendHeaderAnswer(window.nodeTerminal.answerPermission, {
nodeId: id,
pendingId: status.pendingId!,
decision: 'deny'