diff --git a/src/acp/client-helpers.ts b/src/acp/client-helpers.ts index 68da8b1aead0..891274293a22 100644 --- a/src/acp/client-helpers.ts +++ b/src/acp/client-helpers.ts @@ -123,13 +123,12 @@ export async function resolvePermissionRequest( const promptRequired = !classification.autoApprove; if (!promptRequired) { - const option = allowOption ?? options[0]; - if (!option) { - log(`[permission cancelled] ${toolName}: no selectable options`); + if (!allowOption) { + log(`[permission cancelled] ${toolName ?? "unknown"}: missing allow option`); return cancelledPermission(); } log(`[permission auto-approved] ${toolName} (${toolKind ?? "unknown"})`); - return selectedPermission(option.optionId); + return selectedPermission(allowOption.optionId); } log( diff --git a/src/acp/client.test.ts b/src/acp/client.test.ts index 3e54b6822b9e..2ff5d18b0cb0 100644 --- a/src/acp/client.test.ts +++ b/src/acp/client.test.ts @@ -659,6 +659,27 @@ describe("resolvePermissionRequest", () => { expect(res).toEqual({ outcome: { outcome: "selected", optionId: "reject-always" } }); }); + it("cancels auto-approved requests when no allow option is available", async () => { + const prompt = vi.fn(async () => true); + const log = vi.fn(); + const res = await resolvePermissionRequest( + makePermissionRequest({ + toolCall: { + toolCallId: "tool-read-no-allow", + title: "read: src/index.ts", + status: "pending", + kind: "read", + }, + options: [{ kind: "reject_once", name: "Reject", optionId: "reject" }], + }), + { prompt, log }, + ); + + expect(prompt).not.toHaveBeenCalled(); + expect(log).toHaveBeenCalledWith("[permission cancelled] read: missing allow option"); + expect(res).toEqual({ outcome: { outcome: "cancelled" } }); + }); + it("prompts when tool identity is unknown and can still approve", async () => { const prompt = vi.fn(async () => true); const res = await resolvePermissionRequest(