import child_process from "node:child_process"; import { BatchClusterEmitter } from "./BatchClusterEmitter"; import { BatchProcessOptions } from "./BatchProcessOptions"; import { Logger } from "./Logger"; import { Task } from "./Task"; /** * Configuration for stream handling behavior */ export interface StreamHandlerOptions { readonly logger: () => Logger; readonly shouldIgnoreStderrLine?: ((line: string) => boolean) | undefined; readonly isRetirementRequest?: BatchProcessOptions["isRetirementRequest"]; readonly streamFlushMillis?: number | undefined; } /** * Interface for objects that can provide stream context */ export interface StreamContext { readonly name: string; isEnding(): boolean; getCurrentTask(): Task | undefined; onError: (reason: string, error: Error) => void; end: (gracefully: boolean, reason: string) => void | Promise; onIdle: () => void; requestRetirement: () => void; } /** * Handles stdout/stderr stream processing for child processes. * Manages stream event listeners, data routing, and error handling. */ export declare class StreamHandler { #private; private readonly emitter; constructor(options: StreamHandlerOptions, emitter: BatchClusterEmitter); /** * Set up stream event listeners for a child process */ setupStreamListeners(proc: child_process.ChildProcess, context: StreamContext): void; /** * Process stdout data directly (for testing or manual processing) */ processStdout(data: string | Buffer, context: StreamContext): void; /** * Process stderr data directly (for testing or manual processing) */ processStderr(data: string | Buffer, context: StreamContext): void; /** * Process a buffered, unterminated stderr line (for testing or stream end). */ endStderr(context: StreamContext): void; /** Flush stdout at stream end (also available for tests). */ endStdout(context: StreamContext): void; /** Flush received fragments owned by this task before invoking its parser. */ flushOutputForTask(task: Task, context: StreamContext): void; /** Start bounded flushing for fragments left behind by a settled task. */ onTaskSettled(context: StreamContext): void; /** * Resolve a partial stderr line owned by `task` before its parser runs. */ flushStderrForTask(task: Task, context: StreamContext): void; /** * Whether stderr contains a partial line whose disposition is not yet known. */ get hasIncompleteStderrLine(): boolean; /** Partial output must not be attributed to a subsequently assigned task. */ get hasIncompleteOutputLine(): boolean; /** * Whether a partial line will be flushed within `streamFlushMillis`. A * pending task's partial line isn't flushed while `isRetirementRequest` is * set, so this can be false while `hasIncompleteOutputLine` is true. */ get hasScheduledLineFlush(): boolean; /** * Check if data is considered blank/empty */ isBlankData(data: string | Buffer | null | undefined): boolean; /** * Get stream handler statistics */ getStats(): { handlerActive: boolean; emitterConnected: boolean; }; }