export interface HookResult { approved: boolean; reason?: string; timedOut: boolean; commands?: HookCommand[]; } export interface HookCommand { type: "ENV" | "TOOL_RESULT" | "ECHO" | "RUN" | "BACKEND" | "MODEL" | "SYSTEM" | "SYSTEM_FILE" | "BASE_URL" | "API_KEY_ENV_VAR" | "SET" | "SET_FILE" | "SET_TEMP_FILE" | "PREFILL" | "CALL" | "MAXCONTEXT"; value: string; isConditional?: boolean; } export interface HookCommandResults { env: Record; toolResult: string; system: string; model?: string; backend?: string; baseUrl?: string; apiKeyEnvVar?: string; prefill?: string; maxContext?: number; promptVars: Array<{ name: string; value: string; }>; calls: string[]; conditionalResults?: { env: Record; toolResult: string; system: string; prefill?: string; maxContext?: number; promptVars: Array<{ name: string; value: string; }>; calls: string[]; }; } /** * Apply hook commands and return extracted values * ENV commands are applied to process.env (auto-prefixes ENV_PREFIX if not present) * ENV VAR= (empty value) will unset the variable * TOOL_RESULT commands are aggregated into a single string * SYSTEM commands are aggregated into a single string * SYSTEM_FILE commands read file contents (up to 20,000 bytes) and add to system string * MODEL commands set the model to use (last one wins if multiple) * BACKEND commands set the backend to use (last one wins if multiple) * BASE_URL commands set the base URL to use (last one wins if multiple) * API_KEY_ENV_VAR commands set the env var name for API key (last one wins if multiple) * PREFILL commands set assistant prefill text (last one wins if multiple) * MAXCONTEXT commands set maximum context size in tokens (last one wins if multiple) * SET commands set prompt variables (text limited to 10,000 bytes) * SET_FILE commands read file contents (up to 20,000 bytes) and set prompt variables * SET_TEMP_FILE commands read file contents (up to 20,000 bytes), set prompt variables, and delete file * * Commands marked with isConditional=true are separated and returned in conditionalResults. * These should only be applied after backend/model tests succeed. * * Returns extracted values for caller to use */ export declare function applyHookCommands(commands: HookCommand[]): HookCommandResults; /** * Apply extracted ENV variables to process.env * Should be called AFTER model/backend tests succeed * @param env Environment variables to apply */ export declare function applyEnvVariables(env: Record): void; /** * Execute a hook with operation details passed via environment variables * Generic hook executor for operations that need validation * @param hookPath Path to hook script (supports ~/ expansion) * @param operation Operation type (e.g., "tool", "task", "persona", "mood") * @param data Key-value pairs to pass as environment variables * @param timeoutMs Timeout in milliseconds (default 30000) * @param mandatory If true, timeout rejects instead of auto-approving * @returns Promise */ export declare function executeOperationHook(hookPath: string, operation: string, data: Record, timeoutMs?: number, mandatory?: boolean, contextCurrent?: number, contextMax?: number): Promise; /** * Execute a preToolCall hook with tool name and parameters passed via environment * This hook runs before tool execution and can modify environment/prompt variables * Non-blocking: always processes commands even on non-zero exit * @param hookPath Path to hook script (supports ~/ expansion) * @param toolName Name of the tool being executed * @param parameters Tool parameters as key-value pairs * @param timeoutMs Timeout in milliseconds (default 30000) * @returns Promise */ export declare function executePreToolCallHook(hookPath: string, toolName: string, parameters: Record, timeoutMs?: number, contextCurrent?: number, contextMax?: number): Promise; /** * Execute a postToolCall hook with tool name, parameters, and result passed via environment * This hook runs after tool execution and can add context/guidance based on results * Non-blocking: always processes commands even on non-zero exit * @param hookPath Path to hook script (supports ~/ expansion) * @param toolName Name of the tool that was executed * @param parameters Tool parameters as key-value pairs * @param result Tool execution result * @param timeoutMs Timeout in milliseconds (default 30000) * @returns Promise */ export declare function executePostToolCallHook(hookPath: string, toolName: string, parameters: Record, result: { success: boolean; output?: string; error?: string; }, timeoutMs?: number, contextCurrent?: number, contextMax?: number): Promise; /** * Execute a tool approval hook with tool name and parameters passed via environment * Blocking: non-zero exit code rejects the tool execution * @param hookPath Path to hook script (supports ~/ expansion) * @param toolName Name of the tool being executed * @param parameters Tool parameters as key-value pairs * @param timeoutMs Timeout in milliseconds (default 30000) * @returns Promise */ export declare function executeToolApprovalHook(hookPath: string, toolName: string, parameters: Record, timeoutMs?: number, contextCurrent?: number, contextMax?: number): Promise;