/** * @file Locked-down spawn for AI agent CLIs (Claude / Codex / Gemini / * OpenCode). Per the CLAUDE.md "Programmatic Claude calls" rule: every * headless invocation MUST set the four lockdown flags (tools / disallow / * permissionMode). The helper enforces this at the * type level (`SpawnAiAgentOptions` requires the relevant fields) AND at the * spawn site, via the per-agent flag translator. Why a CLI subprocess instead * of an SDK call: Socket's contract matches what the local user sees when * invoking the CLI — same auth config, same model availability, same tool * permissions. SDK calls would diverge on auth handling and force per-agent * SDK installs. Retry: 3 attempts on overload (HTTP 529 / "Overloaded"), exp. * backoff (5s / 15s / 45s). Each retry is a fresh subprocess. */ import type { LocalAgentProvider } from './spawn-local.js'; import type { RouteContext, TierCandidate } from './route.js'; import type { AiTier } from './tier.js'; import type { AgentSpawnResult, AiAgentName, SpawnAiAgentOptions } from './types.js'; export declare function backoffFor(attempt: number): number; /** * Build CLI arg list for a given agent. The flag names differ across agents but * the conceptual surface is the same: "here are the allowed tools, here are the * denied tools, and here is the permission mode." This * translator is the single source of truth for how each agent's flags map. * * When an agent changes its flag surface, update two sites: 1. The relevant * case below. 2. The agent's docs link, cited inline. */ export declare function buildArgs(agent: AiAgentName, options: SpawnAiAgentOptions): string[]; /** * Fable and Mythos run adaptive thinking only — thinking is always on and there * is no manual thinking-budget knob. The effort dial does not apply the way it * does on Opus, so the spawn layer drops `--effort` for these models rather * than passing a level they should ignore. Matches both alias and full-id * shapes (`fable`, `claude-fable-5`, `mythos`, `claude-mythos-5`). */ export declare function isAdaptiveOnlyModel(model: string): boolean; export declare function pickAgent(requested: AiAgentName | undefined, cwd: string): Promise; /** * Spawn an AI agent CLI subprocess with the locked-down flag set. * * @example * ```ts * import { AI_PROFILE } from '@socketsecurity/lib/ai/profiles' * import { spawnAiAgent } from '@socketsecurity/lib/ai/spawn' * * const result = await spawnAiAgent({ * ...AI_PROFILE.edit, * prompt: 'Fix the lint findings in src/foo.ts', * cwd: getNodeProcess().cwd(), * model: 'claude-sonnet-4-6', * timeoutMs: 5 * 60 * 1000, * }) * if (result.exitCode !== 0) { ... } * ``` * * Throws when the requested agent isn't on PATH (or, when no agent * is requested, when none of the known agents are on PATH). */ export declare function spawnAiAgent(options: SpawnAiAgentOptions): Promise; /** * Result of a tier spawn that may have fallen over one or more offline models. * `result` is the spawn that actually ran (the first whose model was not * `unavailable`, or the last attempt if every candidate was down). `candidate` * is the engine/model that produced it. `fellOver` lists the candidates that * reported their model offline before this one — empty on a first-try success. */ export interface TierSpawnResult { readonly candidate: TierCandidate; readonly fellOver: readonly TierCandidate[]; readonly result: AgentSpawnResult; } /** * Spawn a tier's work, automatically FALLING OVER to the next agent when a * model is offline. Walks the tier's usable candidates (Claude → Codex → * open-weight) in order; if a spawn comes back with `unavailable` (the model is * down or gated — e.g. "Claude Fable 5 is currently unavailable"), it advances * to the next candidate instead of failing. This is the runtime complement to * `route.mts`'s static availability check: that check can't predict an outage, * so the live spawn result drives the fallback. * * Returns the first non-`unavailable` spawn (success OR a genuine work failure * on a model that WAS reachable — a real failure shouldn't silently retry on a * weaker model). If every candidate is offline, returns the last attempt with * its `unavailable` flag set, so the caller can report "all models down". * Throws only when the tier has no usable candidate at all (nothing installed + * keyed) — same contract as `resolveTier` returning undefined. */ export declare function spawnTierWithFallback(tier: AiTier, ctx: RouteContext, options: Omit, localProvider?: LocalAgentProvider | undefined): Promise;