From b3a2b91e7449e74c4c6aa9704b6a4e57c85bdcd5 Mon Sep 17 00:00:00 2001 From: Christina Tong Date: Wed, 28 Jan 2026 12:28:37 -0800 Subject: [PATCH] fix: wired up updatedInput in headless (#720) --- src/headless.ts | 25 +++++++++++++++++++------ src/types/protocol.ts | 2 +- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/headless.ts b/src/headless.ts index 54a0422..eb5bd83 100644 --- a/src/headless.ts +++ b/src/headless.ts @@ -1822,7 +1822,11 @@ async function runBidirectionalMode( toolCallId: string, toolName: string, toolInput: Record, - ): Promise<{ decision: "allow" | "deny"; reason?: string }> { + ): Promise<{ + decision: "allow" | "deny"; + reason?: string; + updatedInput?: Record | null; + }> { const requestId = `perm-${toolCallId}`; // Build can_use_tool control request (Claude SDK format) @@ -1866,7 +1870,7 @@ async function runBidirectionalMode( } if (response.behavior === "allow") { - return { decision: "allow" }; + return { decision: "allow", updatedInput: response.updatedInput }; } else { return { decision: "deny", @@ -2135,9 +2139,18 @@ async function runBidirectionalMode( ); if (permResponse.decision === "allow") { + // If provided updatedInput (e.g., for AskUserQuestion with answers), + // update the approval's toolArgs to use it + const finalApproval = permResponse.updatedInput + ? { + ...approval, + toolArgs: JSON.stringify(permResponse.updatedInput), + } + : approval; + decisions.push({ type: "approve", - approval, + approval: finalApproval, matchedRule: "SDK callback approved", }); @@ -2145,9 +2158,9 @@ async function runBidirectionalMode( const autoApprovalMsg: AutoApprovalMessage = { type: "auto_approval", tool_call: { - name: approval.toolName, - tool_call_id: approval.toolCallId, - arguments: approval.toolArgs, + name: finalApproval.toolName, + tool_call_id: finalApproval.toolCallId, + arguments: finalApproval.toolArgs, }, reason: permResponse.reason || "SDK callback approved", matched_rule: "canUseTool callback", diff --git a/src/types/protocol.ts b/src/types/protocol.ts index 749cf23..d33c48f 100644 --- a/src/types/protocol.ts +++ b/src/types/protocol.ts @@ -301,7 +301,7 @@ export type ControlResponseBody = // --- can_use_tool response payloads --- export interface CanUseToolResponseAllow { behavior: "allow"; - /** TODO: Not supported - Letta stores tool calls server-side */ + /** Modified tool input */ updatedInput?: Record | null; /** TODO: Not implemented - dynamic permission rule updates */ updatedPermissions?: unknown[];