import { spawn } from "node:child_process"; import type { StructuredExecHost } from "./structured-exec-host.js"; import type { StructuredRunnerExecution, StructuredRunnerObserver, StructuredRunnerResult, StructuredRunnerTurnState } from "./structured-runner.js"; /** * Shared pump for CLI-backed structured runners. One implementation drives both * ownership modes: a local ChildProcess (legacy lifecycle, test injection) and * a daemon-backed StructuredExecProcess whose streams survive web restarts. * Per-provider differences stay in the adapter via processLine/finalize hooks. */ export interface StructuredCliPumpContext { state: S; stderr: string; observer: StructuredRunnerObserver; /** Ask the underlying CLI to stop early (e.g. Claude ask-user-question). */ requestStop(): void; } export interface StructuredCliPumpOptions { sessionId: string; file: string; args: string[]; cwd: string; env: NodeJS.ProcessEnv; /** Written to stdin once then closed; omit for stdio-ignore CLIs. */ stdinData?: string; observer: StructuredRunnerObserver; /** When set and persistent, the run is owned by terminald instead of us. */ execHost?: StructuredExecHost; /** Local/test spawn injection; ignored when the execHost takes over. */ spawnProcess?: typeof spawn; /** Fresh per-run state (or reducer-owned state) for the pump context. */ createState(): S; processLine(line: string, ctx: StructuredCliPumpContext): void; /** Raw stdout text hook (e.g. Claude stdoutTail bookkeeping). */ onStdoutText?(text: string): void; finalize(ctx: StructuredCliPumpContext, exitCode: number | null, signal: NodeJS.Signals | null, spawnError?: NodeJS.ErrnoException): StructuredRunnerResult; } export declare function startStructuredCli(options: StructuredCliPumpOptions): StructuredRunnerExecution;