import type { ChildProcess } from "node:child_process"; import { RECYCLE_ID_PREFIX, RECYCLE_INIT_ID, RECYCLE_LOAD_ID, RECYCLE_MODE_ID, RECYCLE_CONFIG_PREFIX, type AcpStreamMessage, type CachedSessionMetadata, type CoreContext, type SessionCache, type UrlRewriter } from "./types.js"; import type { AcpPipeline } from "./pipeline.js"; export { RECYCLE_ID_PREFIX, RECYCLE_INIT_ID, RECYCLE_LOAD_ID, RECYCLE_MODE_ID, RECYCLE_CONFIG_PREFIX, }; export declare const DEFAULT_RECYCLE_TIMEOUT_MS = 180000; export declare const DEFAULT_RECYCLE_SPAWN_ATTEMPTS = 3; export declare const DEFAULT_RECYCLE_RETRY_DELAY_MS = 500; export declare const DEFAULT_PROMPT_SETTLE_TIMEOUT_MS = 0; export declare const LOAD_TIMEOUT_PER_MB_MS = 500; export declare function computeSessionLoadTimeout(sessionId: string, baseTimeoutMs?: number, customDbPath?: string): number; export declare const AGENT_CONNECTION_LOST_PATTERN: RegExp; export interface SupervisorOptions { cmd: string; args: string[]; initialChild: ChildProcess; pipeline: AcpPipeline; sessionCache?: SessionCache | undefined; proxies?: UrlRewriter | undefined; spawnProcess?: ((cmd: string, args: string[]) => ChildProcess | Promise) | undefined; recycleTimeoutMs?: number | undefined; /** Total spawn+resync attempts per recycle before giving up (including the first). */ recycleSpawnAttempts?: number | undefined; /** Delay between failed respawn attempts. */ recycleRetryDelayMs?: number | undefined; /** Watchdog timeout in ms to synthesize terminal prompt response when upstream hangs after usage_update. */ promptSettlementTimeoutMs?: number | undefined; customDbPathGetter?: ((sessionId: string) => string) | undefined; } export declare class ProcessSupervisor implements CoreContext { currentChild: ChildProcess; isRecycling: boolean; isClosed: boolean; readonly sessionCache: SessionCache; proxies?: UrlRewriter | undefined; readonly pipeline: AcpPipeline; private readonly cmd; private readonly args; private readonly spawnFn; private readonly recycleTimeoutMs; private readonly recycleSpawnAttempts; private readonly recycleRetryDelayMs; private readonly promptSettlementTimeoutMs; private readonly customDbPathGetter?; private readonly promptSettlementTimers; private readonly activePrompts; private readonly pendingRequests; private readonly suppressedResponseIds; private activeRecycle; private inboundQueue; private rlOut; private rlErr; private readableController; private readonly baseContext; private readonly stderrContext; constructor(options: SupervisorOptions); private forwardInboundFromContext; setController(controller: ReadableStreamDefaultController): void; forwardInbound(msg: AcpStreamMessage): void; writeToChild(msg: AcpStreamMessage): Promise; declareHang(sessionId: string, promptId: string | number, reason: string): void; private clearPromptSettlementTimer; private clearAllPromptSettlementTimers; private armPromptSettlementWatchdog; private settleHungPrompt; triggerRecycle(session: CachedSessionMetadata): Promise; sendInternalRequest(msg: AcpStreamMessage, timeoutMs?: number): Promise; private tryHandleInternalRecycle; private tryHandleSuppressedResponse; private createContext; private recordOutboundSessionNew; private recordOutboundSessionLoad; private recordOutboundSetMode; private recordOutboundSetConfigOption; private handleSessionLifecycleMetadata; private recordOutboundPrompt; private recordOutboundCancel; private recordOutboundMetadata; private trackPendingRequestSession; private rejectOutboundRequest; private prepareOutboundSession; handleOutbound(msg: AcpStreamMessage, proxies?: UrlRewriter): Promise; private recordInboundSessionAllocation; private clearActivePromptByMsg; private handleInboundPromptSettlement; private dispatchInboundPipeline; handleStdoutLine(line: string): Promise; /** * Handles child stdout lines one at a time. Inbound fixes settle at different * speeds, so concurrent handling lets a prompt result overtake the updates * emitted before it. Lines received while recycling bypass the queue: inbound * fixes may await a recycle, which needs the new child's internal replies, and * every other line is dropped while recycling anyway. */ private enqueueStdoutLine; handleStderrLine(line: string): void; private bindChild; private rejectPendingRequests; private closeController; private handleChildClose; private resyncSessionLoad; private resyncSessionMode; private resyncSessionConfig; private performResync; private killChildProcess; private cleanupOldChild; recycleProcess(session: CachedSessionMetadata): Promise; /** * Cleans up after all recycle attempts fail: kills the child, rejects the active * prompt with the underlying reason, and escalates. Escalation closes the whole * ACP stream, so every session multiplexed on this process goes down with it — * correct for one-process-per-session hosts, disruptive for clients that share an * agent process across sessions. */ private failRecycle; /** * Closes the ACP stream so the host performs the cold agent reload it already * does for a crashed child. Deferred one macrotask: the rejection queued by * prepareOutboundSession is delivered before the stream ends. The callback's * isClosed check makes a repeated schedule a no-op. */ private scheduleHostRecovery; close(): void; abort(): void; createStreams(): { readable: ReadableStream; writable: WritableStream; }; } //# sourceMappingURL=supervisor.d.ts.map