import type { AgentRunArgs } from './agent-runner.js'; import { type PiRunTracker, type PiTextStream, type PiTurnBudget } from './pi-runner-state.js'; export declare const TURN_TIMEOUT_MS: number; /** Distinct from TURN_TIMEOUT_MS: catches a hung first-run interactive prompt * fast instead of waiting out the full turn timeout. Any output at all * disarms it. `--mode json` never shows the trust prompt (pi * docs/security.md), and the runner always passes --approve/--no-approve, * so this is a defensive backstop. */ export declare const STARTUP_GRACE_MS = 45000; /** * One parsed pi stream event, normalized for incremental streaming. * - 'assistant': rawText is one whole message_end text (fences intact) for * end-of-turn tool-call parsing, absent on a text_delta increment; text * is the prose to show now (fence-stripped), when there is any. * - 'native': pi's own tool call starting (`toolStart`) or ending * (`toolEnd`), paired by toolCallId. * - 'tool': the spawn-time liveness yield — forwarded by run() as a * `tool_use` liveness AgentMessage (see header). */ export interface PiStreamEvent { kind: 'assistant' | 'native' | 'tool'; text?: string; rawText?: string; toolName?: string; toolStart?: { id: string; name: string; input: unknown; }; toolEnd?: { id: string; output: unknown; isError: boolean; }; } export interface TurnOutcome { exitCode: number; stderrTail: string; timedOut: boolean; /** True when the process was killed by STARTUP_GRACE_MS with no output — * likely stuck on a first-run interactive prompt headless mode can't answer. */ hangSuspected: boolean; /** The `session` header's id. */ sessionId?: string; } /** Per-invocation state streamTurn folds pi's events into: usage/failure/ * completion, visible text, and the mailbox message's turn budget (shared * across its tool rounds). */ export interface PiTurnState { tracker: PiRunTracker; text: PiTextStream; budget: PiTurnBudget; } /** * Run one `pi` invocation and stream its `--mode json` output * INCREMENTALLY: each parsed event is yielded as soon as its line arrives * on stdout (see the header's "Streaming / liveness" note for why * buffering until process exit was a bug, #204). End-of-turn facts (exit * code, stderr tail, timeout/hang flags) are written into `outcome`, usage * and completion into `state.tracker`; the caller reads both after this * generator completes. */ export declare function streamTurn(bin: string, prompt: string, sessionId: string, args: AgentRunArgs, outcome: TurnOutcome, state: PiTurnState): AsyncGenerator; /** Build the actionable error for a failed pi turn. `failure` is the error * pi reported in the stream (a final assistant error or a failed * auto-retry) — pi exits 0 on those, so stderr alone misses them. */ export declare function turnError(outcome: TurnOutcome, round: number, failure?: string): Error; //# sourceMappingURL=pi-runner-stream.d.ts.map