import { WorkflowError } from "./errors.js"; export interface JsonlParseError { line: string; error: string; lineNumber: number; } export interface JsonlParserResult { events: T[]; errors: JsonlParseError[]; remainder: string; } /** Incremental JSON-lines parser suitable for stdout streams split at any byte. */ export declare class IncrementalJsonlParser { private buffer; private lineNumber; private readonly events; private readonly errors; push(chunk: string | Uint8Array): void; finish(): JsonlParserResult; result(): JsonlParserResult; private consume; } export declare function parseJsonl(text: string): JsonlParserResult; export interface CliSpawnOptions { cwd?: string; env?: NodeJS.ProcessEnv; prompt?: string; signal?: AbortSignal; stderrLimit?: number; terminateGraceMs?: number; killGraceMs?: number; /** Injectable in tests; defaults to node:child_process.spawn. */ spawn?: SpawnFactory; } export interface SpawnedCliProcess { stdin: NodeJS.WritableStream | null; stdout: NodeJS.ReadableStream | null; stderr: NodeJS.ReadableStream | null; once(event: "close" | "error", listener: (...args: any[]) => void): this; kill(signal?: NodeJS.Signals | number): boolean; } export type SpawnFactory = (command: string, args: readonly string[], options: { cwd?: string; env?: NodeJS.ProcessEnv; shell: false; stdio: ["pipe", "pipe", "pipe"]; }) => SpawnedCliProcess; export interface CliProcessResult { command: string; args: string[]; exitCode: number | null; signal: NodeJS.Signals | null; stdout: string; stderr: string; events: T[]; jsonlErrors: JsonlParseError[]; } /** Abort error that retains protocol output parsed before process termination. */ export declare class CliProcessAbortedError extends WorkflowError { readonly partialResult: CliProcessResult; constructor(partialResult: CliProcessResult); } export declare function isCliProcessAbortedError(error: unknown): error is CliProcessAbortedError; /** * Run one CLI process with no shell interpretation. It always closes stdin, * incrementally parses stdout as JSONL, bounds stderr, and drains the process * through close. Abort sends SIGTERM first and SIGKILL after a bounded grace. */ export declare function runCliProcess(command: string, args?: readonly string[], options?: CliSpawnOptions): Promise>; /** Convert bounded CLI diagnostics into a concise error detail string. */ export declare function boundedDiagnostics(stderr: string, maxChars?: number): string;