@@ -51,6 +51,7 @@ import type {
5151} from "@anthropic-ai/claude-agent-sdk/sdk-tools" ;
5252// @effect -diagnostics-next-line nodeBuiltinImport:off -- the SDK takes a Node ChildProcess for the CLI.
5353import * as NodeChildProcess from "node:child_process" ;
54+ import * as NodeUtil from "node:util" ;
5455import { parseCliArgs } from "@t3tools/shared/cliArgs" ;
5556import { fromLenientJson } from "@t3tools/shared/schemaJson" ;
5657import { AgentScope } from "@t3tools/shared/AgentScope" ;
@@ -87,6 +88,8 @@ import {
8788 type OrchestrationV2TurnItem ,
8889 type OrchestrationV2WebSearchResult ,
8990 type ProviderApprovalDecision ,
91+ type ProviderApprovalFullAccessOverride ,
92+ type ProviderApprovalOption ,
9093 ProviderDriverKind ,
9194 type ProviderInstanceId ,
9295 type ProviderRequestKind ,
@@ -2794,6 +2797,45 @@ function parentToolUseIdFromSdkMessage(message: SDKMessage): string | null {
27942797 : null ;
27952798}
27962799
2800+ const CLAUDE_NO_STANDING_GRANT_OPTIONS = [
2801+ { decision : "decline" , label : "Decline" } ,
2802+ { decision : "accept" , label : "Approve" } ,
2803+ ] satisfies ReadonlyArray < ProviderApprovalOption > ;
2804+
2805+ export function claudeApprovalPresentation ( input : {
2806+ readonly permissionMode : PermissionMode ;
2807+ readonly prompt : string ;
2808+ readonly callbackOptions : Pick <
2809+ Parameters < CanUseTool > [ 2 ] ,
2810+ "decisionReason" | "matchedAskRule" | "suppressAlwaysAllowRule"
2811+ > ;
2812+ } ) : {
2813+ readonly reason ?: string ;
2814+ readonly fullAccessOverride ?: ProviderApprovalFullAccessOverride ;
2815+ readonly options ?: ReadonlyArray < ProviderApprovalOption > ;
2816+ } {
2817+ // The reason can carry terminal escapes from the CLI's own prompt renderer.
2818+ const reason = NodeUtil . stripVTControlCharacters (
2819+ input . callbackOptions . decisionReason ?? "" ,
2820+ ) . trim ( ) ;
2821+ // Bypass auto-allows everything it can, so any ask that still reaches the
2822+ // callback is one bypass refused. The SDK drops the CLI's decision_reason_type,
2823+ // leaving the matched ask rule as the only way to tell the two causes apart.
2824+ const fullAccessOverride : ProviderApprovalFullAccessOverride | undefined =
2825+ input . permissionMode !== "bypassPermissions"
2826+ ? undefined
2827+ : input . callbackOptions . matchedAskRule === undefined
2828+ ? "provider_check"
2829+ : "ask_rule" ;
2830+ return {
2831+ ...( reason === "" || reason === input . prompt ? { } : { reason } ) ,
2832+ ...( fullAccessOverride === undefined ? { } : { fullAccessOverride } ) ,
2833+ ...( input . callbackOptions . suppressAlwaysAllowRule === true
2834+ ? { options : CLAUDE_NO_STANDING_GRANT_OPTIONS }
2835+ : { } ) ,
2836+ } ;
2837+ }
2838+
27972839export function permissionResultFromDecision ( input : {
27982840 readonly toolName : string ;
27992841 readonly decision : ProviderApprovalDecision ;
@@ -6290,6 +6332,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
62906332 readonly nativeRequestId : string ;
62916333 readonly requestKind : OrchestrationV2RuntimeRequest [ "kind" ] ;
62926334 readonly prompt ?: string ;
6335+ readonly presentation ?: ReturnType < typeof claudeApprovalPresentation > ;
62936336 readonly questions ?: ReadonlyArray < OrchestrationV2UserInputQuestion > ;
62946337 } ) {
62956338 const createdAt = yield * DateTime . now ;
@@ -6374,6 +6417,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
63746417 requestId,
63756418 requestKind : input . requestKind as ProviderRequestKind ,
63766419 ...( input . prompt === undefined ? { } : { prompt : input . prompt } ) ,
6420+ ...input . presentation ,
63776421 }
63786422 : {
63796423 type : "user_input_request" as const ,
@@ -8861,6 +8905,11 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
88618905 nativeRequestId,
88628906 requestKind,
88638907 prompt,
8908+ presentation : claudeApprovalPresentation ( {
8909+ permissionMode : context . queryPolicy . permissionMode ,
8910+ prompt,
8911+ callbackOptions,
8912+ } ) ,
88648913 } ) ;
88658914 const decision = yield * Deferred . make < ProviderApprovalDecision , never > ( ) ;
88668915 yield * Ref . update ( pendingRuntimeRequests , ( current ) => {
0 commit comments