import { type HarnessName, type SpawnOpts } from './harness-adapter'; export type LogFn = (text: string, level?: 'stdout' | 'stderr') => void; /** * Does this harness output line report "the conversation is too big for the * model's context window"? (2026-12) * * Harnesses fail this way in words, not codes, and every vendor phrases it * differently: OpenAI says "maximum context length", Anthropic "prompt is too * long", Gemini "input token count ... exceeds", local models print * "context window exceeded". We only need to recognise it well enough to * ROTATE instead of failing the reply - a false positive costs one fresh * session, a false negative loses the human's message. * * Deliberately narrow: bare "token" or "context" alone would match ordinary * chatter, so each pattern pairs the idea with a limit/exceed verb. */ export declare function isContextOverflowText(text: string): boolean; /** * Kill a spawned harness AND its whole descendant tree. Plain child.kill() * only terminates the shell wrapper (cmd.exe / sh) - npm/vitest/LSP * grandchildren survive as orphans racing future sessions (2026-08-23 * Dealership incident). * * The kill is SELECTIVE (`killTreeExcept`): browser processes are never * terminated. A harness that escalated to the browser (browser_open) must not * have that window closed when its session ends - the human closes it. * * Graceful-then-force: WM_CLOSE/SIGTERM first (allows finally blocks and lock * cleanup to run), then a force kill after 3s. This prevents stale locks from * force-killed sessions that never get a chance to call releaseLock(). */ export declare function killTree(pid: number | undefined): void; /** * Is this a PRIVATE tree (an isolation mirror or a run scope)? * * Only in a private tree can we assume every running shell belongs to this run: * elsewhere (the human's own linked folder) a shell they started by hand must * never keep a dead run alive. */ export declare function isIsolatedTree(path: string | undefined): boolean; /** A background shell that outlived the turn, with its final state. */ export interface ShellContinuation { waitedMs: number; /** Shells that finished CLEANLY (exit 0). A shell that FAILED is never here: * its exit status belongs to the agent and is not a reason to resume. */ shells: Array<{ id: string; command?: string; exit?: number; }>; } /** * The prompt that resumes a session whose background command just finished. * * Shaped like `buildAnsweredBlock` in brief.ts: the FIRST thing the model reads, * stating why this turn exists. Keeping the log tail out of it is deliberate - * the agent can read the file, and a 40-line tail would bury the instruction. */ export declare function formatShellContinuation(c: ShellContinuation): string; /** * Mint (or REUSE) a per-RUN MCP relay token from the local daemon * (2026-10-15, run-keyed 2026-10-25). * * The harness's MCP config then points at `http://127.0.0.1:/mcp-relay` * with this token instead of the API key, and the daemon injects the key on the * way out. Returns null when there is no daemon (or an older one without the * endpoint) - the caller then falls back to the direct API entry with the run's * own key, which is the pre-2026-10-15 behaviour. * * `runKey` is what makes a long or RESUMED run work: the OpenCode V2 service * holds ONE MCP connection per run directory and never re-initializes it when * the config changes, so the same run must keep the same token. `relayKeyFor` * derives it from the task + mode (stable across processes); a per-process id * here would defeat the reuse entirely. * * The token is deliberately NOT revoked when a harness process exits: a * question pause, a retry or a continuation reuses that run's identity and the * service still authenticates with the token it first opened. The daemon revokes * on stop, on a scope violation, and after TOKEN_TTL_MS of IDLENESS. */ export declare function resolveMcpRelay(agentKey: string, label?: string, runKey?: string): Promise<{ url: string; token: string; } | null>; /** * Revoke the relay token of a run that must STOP NOW. * * Only two callers are legitimate: the daemon's stop path and the scope guard * (a violating session is being killed, so its surviving service session must * not keep acting). NEVER call it from a normal harness exit: a resume keeps * the service's MCP connection, and revoking its token leaves that live * connection authenticating with a dead credential. */ export declare function revokeRelayKey(runKey?: string): Promise; export declare function spawnHarness(harness: HarnessName, prompt: string, log: LogFn, settings?: SpawnOpts): Promise;