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(hooks): refuse a partial AskUserQuestion answer set

review84876ef50252
diff --git a/docs/hook-reply-approvals.md b/docs/hook-reply-approvals.md
index 3e8143fd2..204042caf 100644
--- a/docs/hook-reply-approvals.md
+++ b/docs/hook-reply-approvals.md
@@ -86,7 +86,8 @@ Core builds it (`core/agents/permission-decision.ts`, `buildPermissionDecision`)
agent's host** — the only source of truth for the tool and for `questions` (never renderer-echoed
data). Every field is validated: the tool must match, plan modes are a closed enum, a label must
exist in that question's options unless the entry is explicitly free text, several labels only on a
-multiSelect question, sizes capped (text 8000 chars, the whole decision 64 KB). A structured answer
+multiSelect question, EVERY question the request asks must be answered (a partial set is refused —
+the TUI never submits a half-answered picker), sizes capped (text 8000 chars, the whole decision 64 KB). A structured answer
is refused when the request file is gone (the hold ended) — the call resolves `false`.
**What the script prints** (`managed-script.ts`, tested under a real `/bin/sh` in
diff --git a/src/core/agents/permission-decision.test.ts b/src/core/agents/permission-decision.test.ts
index 8ae0a50a1..4820d2139 100644
--- a/src/core/agents/permission-decision.test.ts
+++ b/src/core/agents/permission-decision.test.ts
@@ -178,11 +178,16 @@ describe('buildPermissionDecision — plan', () => {
})
})
+// The request asks TWO questions; a valid answer answers both (core refuses a partial set).
+const SURFACES = 'Which surfaces should get it?'
+const ANSWER_1 = { [QUESTION_TEXT]: 'Kim kimi okuyabilir (context)' }
+const ANSWER_2 = { [SURFACES]: ['Desktop'] }
+
describe('buildPermissionDecision — question', () => {
it('echoes the PENDING request\'s questions verbatim and adds answers keyed by the exact question text', () => {
const r = buildPermissionDecision(QUESTION_REQ, {
kind: 'question',
- answers: { [QUESTION_TEXT]: 'Kim kimi okuyabilir (context)' }
+ answers: { ...ANSWER_1, ...ANSWER_2 }
})
if (!r.ok) throw new Error(r.reason)
expect(r.decision).toBe('allow')
@@ -190,39 +195,43 @@ describe('buildPermissionDecision — question', () => {
expect(d.behavior).toBe('allow')
expect(d.updatedInput).toEqual({
questions: REAL_QUESTIONS,
- answers: { [QUESTION_TEXT]: 'Kim kimi okuyabilir (context)' }
+ answers: { [QUESTION_TEXT]: 'Kim kimi okuyabilir (context)', [SURFACES]: 'Desktop' }
})
expect(r.content.startsWith(PERMISSION_DECISION_PREFIX)).toBe(true)
})
it('multiSelect: an array of labels is joined with ", " (the TUI\'s own transcript format)', () => {
const r = buildPermissionDecision(QUESTION_REQ, {
kind: 'question',
- answers: { 'Which surfaces should get it?': ['Desktop', 'Phone'] }
+ answers: { ...ANSWER_1, [SURFACES]: ['Desktop', 'Phone'] }
})
if (!r.ok) throw new Error(r.reason)
expect((decisionOf(r.content).updatedInput as { answers: unknown }).answers).toEqual({
- 'Which surfaces should get it?': 'Desktop, Phone'
+ ...ANSWER_1,
+ [SURFACES]: 'Desktop, Phone'
})
})
it('free text is accepted ONLY for a key the answer marks explicitly as free text', () => {
const typed = 'context bağlamak pazarlama değeri var kalabilir'
- expect(buildPermissionDecision(QUESTION_REQ, { kind: 'question', answers: { [QUESTION_TEXT]: typed } }).ok).toBe(false)
+ expect(
+ buildPermissionDecision(QUESTION_REQ, { kind: 'question', answers: { [QUESTION_TEXT]: typed, ...ANSWER_2 } }).ok
+ ).toBe(false)
const r = buildPermissionDecision(QUESTION_REQ, {
kind: 'question',
- answers: { [QUESTION_TEXT]: typed },
+ answers: { [QUESTION_TEXT]: typed, ...ANSWER_2 },
freeText: [QUESTION_TEXT]
})
if (!r.ok) throw new Error(r.reason)
expect((decisionOf(r.content).updatedInput as { answers: Record<string, string> }).answers[QUESTION_TEXT]).toBe(typed)
})
it('refuses: unknown question, unknown label, array on a single-select, empty/duplicate/oversized picks', () => {
+ // Each set is otherwise COMPLETE, so the one defect is what refuses it.
const bad: Array<Record<string, string | string[]>> = [
- { 'Not a question we asked': 'Desktop' },
- { [QUESTION_TEXT]: 'Desktop' },
- { [QUESTION_TEXT]: ['Kim kimi okuyabilir (context)'] },
- { 'Which surfaces should get it?': [] },
- { 'Which surfaces should get it?': ['Desktop', 'Desktop'] },
- { 'Which surfaces should get it?': ['Desktop', 'Nope'] },
+ { ...ANSWER_1, ...ANSWER_2, 'Not a question we asked': 'Desktop' },
+ { [QUESTION_TEXT]: 'Desktop', ...ANSWER_2 },
+ { [QUESTION_TEXT]: ['Kim kimi okuyabilir (context)'], ...ANSWER_2 },
+ { ...ANSWER_1, [SURFACES]: [] },
+ { ...ANSWER_1, [SURFACES]: ['Desktop', 'Desktop'] },
+ { ...ANSWER_1, [SURFACES]: ['Desktop', 'Nope'] },
{}
]
for (const answers of bad) {
@@ -231,7 +240,7 @@ describe('buildPermissionDecision — question', () => {
expect(
buildPermissionDecision(QUESTION_REQ, {
kind: 'question',
- answers: { [QUESTION_TEXT]: 'x'.repeat(20_000) },
+ answers: { [QUESTION_TEXT]: 'x'.repeat(20_000), ...ANSWER_2 },
freeText: [QUESTION_TEXT]
}).ok
).toBe(false)
@@ -239,11 +248,42 @@ describe('buildPermissionDecision — question', () => {
expect(
buildPermissionDecision(QUESTION_REQ, {
kind: 'question',
- answers: { [QUESTION_TEXT]: 'Kim kimi okuyabilir (context)' },
+ answers: { ...ANSWER_1, ...ANSWER_2 },
freeText: ['something else']
}).ok
).toBe(false)
})
+ it('refuses a PARTIAL answer set: every question the request asks must be answered', () => {
+ // The TUI never submits a half-answered picker; `updatedInput` REPLACES the tool input, so a
+ // missing answer would reach Claude as a question the user never saw answered.
+ for (const answers of [ANSWER_1, ANSWER_2]) {
+ expect(buildPermissionDecision(QUESTION_REQ, { kind: 'question', answers }), JSON.stringify(answers)).toMatchObject({
+ ok: false
+ })
+ }
+ expect(buildPermissionDecision(QUESTION_REQ, { kind: 'question', answers: { ...ANSWER_1, ...ANSWER_2 } }).ok).toBe(true)
+ })
+ it('"__proto__" counts as an ordinary question in the completeness check too', () => {
+ const req = parsePendingRequest(
+ envelope('AskUserQuestion', {
+ questions: [
+ { question: '__proto__', header: 'h', options: [{ label: 'a' }], multiSelect: false },
+ { question: 'B?', header: 'h', options: [{ label: 'b' }], multiSelect: false }
+ ]
+ })
+ ) as PendingRequest
+ // Only the __proto__ key: an own key, but one of two — refused.
+ const onlyProto = parsePermissionAnswer(JSON.parse('{"kind":"question","answers":{"__proto__":"a"}}'))
+ expect(onlyProto).not.toBeNull()
+ expect(buildPermissionDecision(req, onlyProto!)).toMatchObject({ ok: false })
+ // Both: accepted, and __proto__ is written as data.
+ const both = parsePermissionAnswer(JSON.parse('{"kind":"question","answers":{"__proto__":"a","B?":"b"}}'))
+ const r = buildPermissionDecision(req, both!)
+ if (!r.ok) throw new Error(r.reason)
+ expect((decisionOf(r.content).updatedInput as { answers: Record<string, string> }).answers).toEqual(
+ JSON.parse('{"__proto__":"a","B?":"b"}')
+ )
+ })
it('a question text of "__proto__" is an ordinary key, not a prototype write', () => {
const req = parsePendingRequest(
envelope('AskUserQuestion', { questions: [{ question: '__proto__', header: 'h', options: [{ label: 'a' }], multiSelect: false }] })
@@ -358,7 +398,7 @@ describe('answerHeldPermission — the one orchestration both shells call', () =
expect(await answerHeldPermission(OLD, { answer: { kind: 'plan', mode: 'restore' } }, x)).toEqual({ ok: false })
const q = io(envelope('AskUserQuestion', { questions: REAL_QUESTIONS }))
expect(
- await answerHeldPermission(OLD, { answer: { kind: 'question', answers: { [QUESTION_TEXT]: 'Kim kimi okuyabilir (context)' } } }, q)
+ await answerHeldPermission(OLD, { answer: { kind: 'question', answers: { ...ANSWER_1, ...ANSWER_2 } } }, q)
).toEqual({ ok: false })
expect(x.writes).toEqual([])
expect(q.writes).toEqual([])
diff --git a/src/core/agents/permission-decision.ts b/src/core/agents/permission-decision.ts
index f75b8839d..4951ceab8 100644
--- a/src/core/agents/permission-decision.ts
+++ b/src/core/agents/permission-decision.ts
@@ -196,6 +196,10 @@ function buildQuestionDecision(
out[question] = answer.join(', ')
}
}
+ // Every question the request asks must be answered — the TUI never submits a half-answered
+ // picker, and `updatedInput` would hand Claude a question the user never saw answered. Counted on
+ // the null-prototype `out`, whose keys are all validated question texts ("__proto__" included).
+ if (Object.keys(out).length !== index.size) return { ok: false, reason: 'not every question is answered' }
// `updatedInput` REPLACES the whole input, so everything the request carried (questions,
// title/metadata on the extended variant) is echoed from the PENDING FILE, never from the renderer.
const updatedInput = { ...pending.toolInput, answers: out }