/** * PersistentProcessRegistry — filesystem-backed process registry that survives * process restarts and coordinates protection across multiple WrongStack instances * running in different terminals. * * Key features: * - PIDs stored in ~/.wrongstack/process-registry.json * - File locking for cross-instance coordination * - Heartbeat mechanism to detect stale entries * - Protection whitelist that blocks kill commands targeting WrongStack processes * - Multi-instance awareness: all instances share the same protection state */ import { type ProcessRegistryImpl } from './process-registry.js'; export interface PersistentProcessEntry { pid: number; name: string; command: string; startedAt: number; lastHeartbeat: number; sessionId?: string; instanceId: string; /** Hostname where this process is running */ hostname: string; protected: boolean; /** How this process was spawned: 'fork' (child_process.fork), 'spawn' (child_process.spawn), 'main' (the main WrongStack process itself) */ spawnMode: 'fork' | 'spawn' | 'main'; /** Parent PID if spawned via fork/spawn */ parentPid?: number; /** OS platform where this entry was created */ platform: string; } export interface PersistentRegistryData { version: 1; instances: Map; protectedPatterns: string[]; lastCleanup: number; } /** * PersistentProcessRegistry wraps the in-memory ProcessRegistryImpl and * synchronizes entries to a filesystem-backed store for cross-instance coordination. */ export declare class PersistentProcessRegistry { private readonly instanceId; private readonly registryPath; private readonly lockPath; private readonly baseRegistry; private heartbeatInterval; private cleanupInterval; private heartbeatRunning; private cleanupRunning; private isShuttingDown; private readonly onProcessExit; constructor(baseRegistry?: ProcessRegistryImpl); private ensureDirectory; private runInBackground; /** * Start the heartbeat and periodic cleanup tasks. */ start(): void; /** * Stop the heartbeat and clean up. */ stop(): void; /** * Register the main WrongStack process as protected. */ registerMainProcess(): void; /** * Register a spawned child process with the persistent registry. */ registerChildProcess(pid: number, name: string, command: string, sessionId?: string, spawnMode?: 'spawn' | 'fork'): void; /** * Update or add an entry in the persistent registry. */ private updatePersistentEntry; /** * Unregister a process from the persistent registry. */ unregister(pid: number): Promise; /** * Send heartbeat to mark all this instance's processes as alive. */ private heartbeat; private cleanup; /** * Sync this instance's processes to the persistent registry. */ private syncToPersistent; /** * Remove entries for processes that are no longer running. */ private cleanupStaleEntries; /** * Check if a PID belongs to a WrongStack process and should be protected. */ isProtectedPid(pid: number): Promise; /** * Get all protected PIDs from all WrongStack instances. */ getAllProtectedPids(): Promise; /** * Get complete status of all tracked processes across all instances. */ getGlobalStatus(): Promise<{ instances: Map; totalProcesses: number; protectedCount: number; staleCount: number; }>; /** * Get the instance ID for this process. */ getInstanceId(): string; /** * Check if a kill command should be blocked. * Returns true if the kill should be blocked (target is a WrongStack process). */ shouldBlockKill(pid: number): Promise; /** * Add a pattern-based protection rule. * Processes whose command matches any protected pattern are protected. */ addProtectedPattern(pattern: string): Promise; } export declare function getPersistentProcessRegistry(): PersistentProcessRegistry; export declare function resetPersistentProcessRegistry(): void; //# sourceMappingURL=process-registry-persistent.d.ts.map