/** * Confirmation flow utility for safety-guarded operations. * * @module safety/with-confirmation */ import type { SafetyGuard } from './safety-guard.js'; import type { SafetyEvaluation } from './types.js'; /** * Handler that prompts a user for confirmation. * * Implementations vary by context: * - CLI: readline-based prompt * - VS Code: `vscode.window.showWarningMessage({ modal: true })` * - MCP/non-interactive: always returns `false` * * @param evaluation - The safety evaluation that triggered confirmation * @returns true if the user confirmed, false to cancel */ export type ConfirmHandler = (evaluation: SafetyEvaluation) => Promise; /** * Execute an operation with safety confirmation support. * * If the operation throws {@link SafetyConfirmationRequired}, the * `confirmHandler` is called. If the user confirms, the operation * is retried with a temporary exemption. If the user cancels (or * the handler returns false), a {@link SafetyBlockedError} is thrown. * * Non-confirmation errors are re-thrown as-is. * * @param guard - The SafetyGuard instance * @param operation - The operation to execute * @param confirmHandler - Context-specific confirmation handler * @returns The operation's return value * * @example * ```typescript * // CLI usage * const result = await withSafetyConfirmation( * guard, * () => instance.ocapi.POST('/jobs/import/executions', ...), * async (eval) => { * if (!process.stdin.isTTY) return false; * return confirm(`Safety: ${eval.reason}. Proceed?`); * }, * ); * * // VS Code usage * const result = await withSafetyConfirmation( * guard, * () => runJobImport(), * async (eval) => { * const choice = await vscode.window.showWarningMessage(eval.reason, { modal: true }, 'Proceed'); * return choice === 'Proceed'; * }, * ); * ``` */ export declare function withSafetyConfirmation(guard: SafetyGuard, operation: () => Promise, confirmHandler: ConfirmHandler): Promise;