/** * @file Opt-in "AI assist when stuck" helper — a thin, dependency-light layer * over the ai-agent runner (pickAgent + spawnAiAgent). When a task is STUCK * an opted-in caller hands the task (+ optional context) here and gets a * resolved backend (claude → codex → opencode/gemini, or an explicit one) to * attempt it, returning a structured `{ backend, ok, output }` result. OPT-IN * by design: `assistWhenStuck` is a NO-OP unless the caller opted in — via * `optIn: true` OR the `SOCKET_AI_ASSIST` env flag — so a stuck build / * optimize / release step degrades to its normal failure UNLESS AI help was * requested; assist never fires on its own. Consumers: socket-cli `optimize` * and the wheelhouse gh-release / fleet optimization scripts, dropped into * their stuck/catch paths. */ import type { AiAgentName } from './types.js'; export declare const AI_ASSIST_ENV = "SOCKET_AI_ASSIST"; export declare const DEFAULT_TIMEOUT_MS: number; export interface AiAssistOptions { readonly task: string; readonly cwd: string; readonly context?: string | undefined; readonly backend?: AiAgentName | undefined; readonly timeoutMs?: number | undefined; readonly optIn?: boolean | undefined; } export interface AiAssistResult { readonly backend: AiAgentName; readonly ok: boolean; readonly output: string; readonly error?: string | undefined; } /** * Run an AI agent against a stuck task and return a structured result. Resolves * a backend (explicit `backend`, else claude → codex → opencode → gemini via * `pickAgent`), runs it under the locked-down `edit` profile, and reports * whether it succeeded (`ok` = clean exit AND the model was reachable). Does * NOT check the opt-in gate — use `assistWhenStuck` for the guarded entry. * Throws only when no agent CLI is on PATH (from `pickAgent`). */ export declare function aiAssist(options: AiAssistOptions): Promise; /** * The stuck-path entry: a NO-OP returning `undefined` unless the caller opted * in (`optIn === true` OR `SOCKET_AI_ASSIST`). When opted in it runs `aiAssist` * and NEVER throws — a failure to even reach an agent collapses to a failed * result — so a catch/stuck path can call it without its own guard: * * @example * ;```ts * try { doOptimizeStep() } catch (e) { * const help = await assistWhenStuck({ * task: 'This optimize step failed; diagnose + fix.', * context: errorMessage(e), * cwd: repoRoot, * }) * if (help?.ok) { … } // undefined when not opted in * } * ``` */ export declare function assistWhenStuck(options: AiAssistOptions): Promise; /** * Compose the agent prompt from the task and optional context. Pure. */ export declare function buildAssistPrompt(task: string, context?: string | undefined): string; /** * True when this session has opted into AI assistance * (`SOCKET_AI_ASSIST=1` or `=true`). Off by default — assist must be explicitly * requested. The env map is injectable for tests. */ export declare function isAiAssistEnabled(env?: Readonly>): boolean;