/** * Issue #454/#455: pure decoding, normalization and reply encoding for * Claude's `can_use_tool` control requests on a persistent session. Under * `--permission-prompt-tool stdio` (verified 2.1.319) the child asks the * host about each permission-gated tool call and waits for a * `control_response`; this module turns the native request into the * normalized `approval-request` proposal and a host decision back into the * native reply. No process logic lives here: the execution layer owns the * pending map, the write and the clearing. * * hcn decides nothing here: Claude resolves deny rules, hooks and the * managed policy before it asks, and the choices offered are exactly the * native ones (allow once, session-scoped native suggestions, deny) - no * rule of hcn's own, and nothing is offered that would write the user's * settings files (suggestions with other destinations are dropped). */ import type { ApprovalChoice, ApprovalQuestion } from "../knowledge/native-approvals.js"; export type SessionApprovalCategory = "tool" | "question" | "plan"; /** One offered choice. `update` carries the native permission * suggestion a `suggestion-N` choice replays verbatim as * `updatedPermissions` - and forwards to the host unchanged, so a host * can show the exact native update it grants. */ export interface SessionApprovalChoice extends ApprovalChoice { readonly update?: unknown; } /** The normalized proposal one `can_use_tool` request becomes. */ export interface SessionApprovalProposal { readonly category: SessionApprovalCategory; readonly tool: string; readonly details: string; /** The native tool input, unchanged. */ readonly input: unknown; readonly choices: readonly SessionApprovalChoice[]; /** `question` only: the normalized questions, keyed by their text. */ readonly questions?: readonly ApprovalQuestion[]; /** `plan` only: the input's plan text. */ readonly plan?: string; } /** The native reply a decision becomes: an allow with the (possibly * amended) tool input, or a deny whose message reaches the model. */ export type SessionApprovalReply = { readonly behavior: "allow"; readonly updatedInput: unknown; readonly updatedPermissions?: readonly unknown[]; } | { readonly behavior: "deny"; readonly message: string; }; export declare const DEFAULT_DENY_MESSAGE = "The user denied this action."; export declare const DEFAULT_DECLINE_MESSAGE = "The user declined to answer."; /** A host decision as it reached the session stdin, structurally parsed. */ export interface SessionApprovalDecision { readonly choiceId: string; readonly message?: string; readonly answers?: Readonly>; } export type SessionApprovalDecisionRejection = "unknown-choice" | "invalid-answers" | "invalid-message"; /** Decode one parsed `control_request` record carrying a `can_use_tool` * request into the offered proposal, or null when the record is not one * (or carries no usable identity). Only `subtype === "can_use_tool"` * opens this channel: another control request that happens to carry a * `tool_name` stays out. */ export declare const decodeClaudePermissionRequest: (record: Record) => { readonly requestId: string; readonly proposal: SessionApprovalProposal; } | null; /** The `control_response` line that answers one request. */ export declare const encodeClaudeControlResponse: (requestId: string, reply: SessionApprovalReply) => string; /** Apply one structurally valid decision to a proposal: the closed choice * validation (answers required for `answer`, refused elsewhere; message * denied on allow-scope choices) and the native reply it becomes. Pure: * the caller owns consumption and the write. */ export declare const applySessionApprovalDecision: (proposal: SessionApprovalProposal, decision: SessionApprovalDecision) => { readonly ok: true; readonly reply: SessionApprovalReply; } | { readonly ok: false; readonly reason: SessionApprovalDecisionRejection; }; //# sourceMappingURL=session-approvals.d.ts.map