/** * Graceful shutdown handling for openlore CLI */ export interface ShutdownState { /** Current phase when interrupted */ phase: 'init' | 'analyze' | 'generate' | 'verify'; /** Files that were being processed */ currentFiles?: string[]; /** Partial results that were saved */ savedResults?: string; /** Timestamp of interruption */ timestamp: number; } type CleanupCallback = () => void | Promise; /** * Manages graceful shutdown with cleanup callbacks */ export declare class ShutdownManager { private callbacks; private isShuttingDown; private state; private stateFile; private handlers; private handlersAttached; constructor(projectPath?: string, options?: { skipHandlers?: boolean; }); private setupHandlers; /** * Remove all registered signal handlers (for testing) */ removeHandlers(): void; private handleShutdown; /** * Register a cleanup callback to run on shutdown */ onCleanup(callback: CleanupCallback): void; /** * Remove a cleanup callback */ removeCleanup(callback: CleanupCallback): void; /** * Set the current state for potential resume */ setState(state: Partial): void; /** * Clear state (call on successful completion) */ clearState(): void; /** * Save state to file for potential resume */ private saveState; /** * Load previous shutdown state */ loadState(): ShutdownState | null; /** * Check if there's a previous interrupted session */ hasPreviousState(): boolean; private showResumeSuggestion; /** * Check if shutdown is in progress */ isInProgress(): boolean; } /** * A single idempotent teardown path for a surface whose lifetime is bound to a * transport — the MCP stdio server, whose lifetime is its stdin. Distinct from * {@link ShutdownManager}, which is the analyze/generate pipeline's interrupt * handler (resume state, banner, exit 130). This one has no state file and no * banner: a closed transport is ordinary end-of-work, so it exits 0 by default. * * Every way the surface can end — stdin EOF, `SIGINT`, `SIGTERM` — routes * through one `shutdown()`, so no signal implements a partial teardown of its * own and running it twice is harmless. Teardown is bounded: a handle that hangs * on close cannot turn "exit on EOF" back into a hang, because the process * exits once the grace window elapses regardless. */ export interface ShutdownCoordinator { /** Register a teardown to run once, on the first shutdown. */ register(teardown: CleanupCallback): void; /** Run every teardown once (bounded), then exit. Idempotent. */ shutdown(code?: number): Promise; /** True once shutdown has begun. */ readonly isShuttingDown: boolean; } export declare function createShutdownCoordinator(options?: { /** Exit hook — defaults to process.exit; injected in tests. */ exit?: (code: number) => void; /** Max ms to wait for teardowns before exiting anyway (default 2000). */ graceMs?: number; }): ShutdownCoordinator; /** * Get or create the global shutdown manager */ export declare function getShutdownManager(projectPath?: string): ShutdownManager; /** * Register a cleanup callback with the global manager */ export declare function onShutdown(callback: CleanupCallback): void; /** * Set current state for potential resume */ export declare function setShutdownState(state: Partial): void; /** * Clear shutdown state (call on successful completion) */ export declare function clearShutdownState(): void; /** * Create a scope that sets/clears state automatically */ export declare function withShutdownState(state: Partial, fn: () => Promise): Promise; export {}; //# sourceMappingURL=shutdown.d.ts.map