/** * Process Guardian — Protects WrongStack processes from being killed via * bash/kill commands. Runs as a watchdog that: * * 1. Registers the main process and all children with persistent registry * 2. Monitors for kill attempts against protected PIDs * 3. Provides recovery mechanisms when killed processes are detected * 4. Coordinates protection across multiple WrongStack instances * * This is NOT a security mechanism against intentional root-level kills. * A user with sudo/root can still kill any process. This is a guardrail * to prevent accidental kills from the WrongStack agent itself. */ export interface ProcessGuardianConfig { /** Interval for heartbeat in ms */ heartbeatIntervalMs?: number; /** Enable automatic process resurrection */ autoResurrect?: boolean; /** Maximum resurrection attempts */ maxResurrectionAttempts?: number; /** Custom protection patterns */ protectedPatterns?: string[]; /** * How many SIGTERM signals to tolerate before exiting. * The first N-1 are ignored to protect against accidental `kill` from the * AI agent; the Nth triggers graceful shutdown via `stop()` + `process.exit(0)`. * Default 3 — balances AI guardrail vs container orchestration (Docker, * systemd repeat SIGTERM up to StopTimeout ~10s, then SIGKILL). * Set to 0 to always exit on the first SIGTERM, or Infinity to never exit. */ sigtermThreshold?: number; } /** * Process Guardian watches over WrongStack processes and prevents accidental kills. */ export declare class ProcessGuardian { private readonly registry; private readonly config; private readonly protectedProcesses; private heartbeatTimer; private isRunning; private instanceId; private sigtermCount; private processHandlersInstalled; private readonly onProcessExit; private readonly onUncaughtException; private readonly onUnhandledRejection; private readonly onSigterm; private readonly onSighup; constructor(config?: ProcessGuardianConfig); /** * Start the guardian - begins monitoring and registration. */ start(): void; /** * Stop the guardian gracefully. */ stop(): void; /** * Register a process with the guardian. */ registerProcess(pid: number, name: string): void; /** * Unregister a process (e.g., when it exits normally). */ unregisterProcess(pid: number): void; /** * Register all child processes that already exist. */ private registerExistingChildren; /** * Sync protected processes with the base ProcessRegistry. */ private syncWithProcessRegistry; /** * Heartbeat - updates timestamps and checks for anomalies. */ private heartbeat; /** * Set up process-level event handlers. */ private setupProcessHandlers; private removeProcessHandlers; /** * Check if a PID is protected by this guardian. */ isProtected(pid: number): boolean; /** * Get all PIDs protected by this guardian. */ getProtectedPids(): number[]; /** * Get status information for monitoring. */ getStatus(): { instanceId: string; mainPid: number; protectedCount: number; platform: string; hostname: string; uptime: number; }; } export declare function getProcessGuardian(): ProcessGuardian; export declare function startProcessGuardian(config?: ProcessGuardianConfig): ProcessGuardian; export declare function stopProcessGuardian(): void; //# sourceMappingURL=process-guardian.d.ts.map