import { EventEmitter } from 'node:events'; import { type ExecConfig } from '../lib/config.js'; /** * Child process status */ export type ChildProcessStatus = 'stopped' | 'starting' | 'running' | 'restarting' | 'crashed' | 'max_restarts_exceeded'; /** * Child process state information for health endpoint */ export interface ChildProcessState { status: ChildProcessStatus; pid: number | null; restartCount: number; lastExitCode: number | null; lastExitSignal: string | null; lastExitTime: string | null; lastStartTime: string | null; } /** * Events emitted by ChildProcessManager */ export interface ChildProcessManagerEvents { started: (pid: number) => void; stopped: (code: number | null, signal: string | null) => void; restarting: (reason: string) => void; maxRestartsExceeded: () => void; error: (error: Error) => void; } /** * Manages a child process with secrets as environment variables. * Handles restart on changes, crash recovery with backoff, and signal forwarding. */ export declare class ChildProcessManager extends EventEmitter { private child; private readonly config; private readonly mappings; private readonly useFileMode; private isShuttingDown; private restartCount; private restartWindowStart; private restartTimeout; private status; private lastExitCode; private lastExitSignal; private lastExitTime; private lastStartTime; private readonly signalHandlers; constructor(execConfig: ExecConfig); /** * Kill any orphaned child process from a previous agent run. * This prevents zombie processes when the agent crashes and restarts. */ private killOrphanedChild; /** * Wait for a process to exit with timeout. * Returns true if process exited, false if timeout. */ private waitForProcessExit; /** * Write child PID to file for orphan detection. */ private writePidFile; /** * Remove the child PID file. */ private cleanupPidFile; /** * Start the child process */ start(): Promise; /** * Stop the child process gracefully */ stop(): Promise; /** * Restart the child process (e.g., after cert/secret change) */ restart(reason: string): Promise; /** * Get current process state for health endpoint */ getState(): ChildProcessState; /** * Check if process is in a healthy state */ isHealthy(): boolean; /** * Check if process is in a degraded state (restarting or max restarts exceeded) */ isDegraded(): boolean; /** * Stop child without setting shutdown flag */ private stopChild; /** * Set up signal forwarding from parent to child */ private setupSignalForwarding; /** * Clean up signal handlers */ private cleanupSignalHandlers; /** * Set up event handlers for child process */ private setupChildEventHandlers; /** * Handle child process crash with rate limiting */ private handleCrash; /** * Reset restart counter (call after successful manual restart) */ resetRestartCount(): void; } //# sourceMappingURL=child-process-manager.d.ts.map