/**
 * Graceful Shutdown Manager
 *
 * Provides clean application shutdown with:
 * - Session state preservation
 * - Pending operation completion (waits for in-progress operations)
 * - Connection cleanup (MCP, Database)
 * - Log flushing
 * - Configurable timeout (default 30s) before force exit
 *
 * Intercepts signals: SIGINT (Ctrl+C), SIGTERM (kill), SIGHUP (terminal closed)
 */
import { type Disposable } from './disposable.js';
export interface ShutdownOptions {
    /** Maximum time to wait for shutdown in milliseconds (default: 30000) */
    timeoutMs: number;
    /** Whether to force exit after timeout (default: true) */
    forceExitOnTimeout: boolean;
    /** Custom exit code (default: 0 for graceful, 1 for timeout) */
    exitCode?: number;
    /** Show progress during shutdown (default: true) */
    showProgress: boolean;
}
export interface ShutdownHandler {
    /** Name for logging purposes */
    name: string;
    /** Priority (higher = runs first, default: 0) */
    priority: number;
    /** The shutdown handler function */
    handler: () => void | Promise<void>;
}
/**
 * Graceful Shutdown Manager
 *
 * Coordinates clean shutdown of all application components
 */
export declare class GracefulShutdownManager implements Disposable {
    private static instance;
    private handlers;
    private isShuttingDown;
    private shutdownPromise;
    private options;
    private signalsRegistered;
    private pendingOperations;
    private completedHandlers;
    private constructor();
    /**
     * Get singleton instance
     */
    static getInstance(options?: Partial<ShutdownOptions>): GracefulShutdownManager;
    /**
     * Register process signal handlers
     */
    registerSignalHandlers(): void;
    /**
     * Handle incoming signal
     */
    private handleSignal;
    /**
     * Register a shutdown handler
     */
    registerHandler(handler: ShutdownHandler): void;
    /**
     * Unregister a shutdown handler by name
     */
    unregisterHandler(name: string): boolean;
    /**
     * Track a pending operation (blocks shutdown until complete)
     * Returns a function to mark the operation as complete
     */
    trackOperation(id: string, description: string): () => void;
    /**
     * Check if there are pending operations
     */
    hasPendingOperations(): boolean;
    /**
     * Get list of pending operations
     */
    getPendingOperations(): Array<{
        id: string;
        description: string;
        duration: number;
    }>;
    /**
     * Execute shutdown with timeout
     */
    shutdown(overrideOptions?: Partial<ShutdownOptions>): Promise<void>;
    /**
     * Execute the actual shutdown sequence
     */
    private executeShutdown;
    /**
     * Wait for pending operations to complete
     */
    private waitForPendingOperations;
    /**
     * Run all shutdown handlers in priority order
     */
    private runShutdownHandlers;
    /**
     * Flush all pending logs
     */
    private flushLogs;
    /**
     * Check if shutdown is in progress
     */
    isInShutdown(): boolean;
    /**
     * Implement Disposable interface
     */
    dispose(): void;
    /**
     * Reset the singleton (for testing)
     */
    static reset(): void;
}
/**
 * Get the global shutdown manager instance
 */
export declare function getShutdownManager(options?: Partial<ShutdownOptions>): GracefulShutdownManager;
/**
 * Register a shutdown handler with the global manager
 */
export declare function onShutdown(name: string, handler: () => void | Promise<void>, priority?: number): void;
/**
 * Initiate graceful shutdown
 */
export declare function initiateShutdown(options?: Partial<ShutdownOptions>): Promise<void>;
/**
 * Track a pending operation that should complete before shutdown
 * Returns a function to mark the operation as complete
 *
 * @example
 * const done = trackOperation('file-save', 'Saving file...');
 * try {
 *   await saveFile();
 * } finally {
 *   done();
 * }
 */
export declare function trackOperation(id: string, description: string): () => void;
/**
 * Check if shutdown is in progress
 */
export declare function isShuttingDown(): boolean;
/**
 * Register default handlers for common resources
 */
export declare function registerDefaultShutdownHandlers(): void;
/**
 * Initialize graceful shutdown system
 * Call this early in application startup
 */
export declare function initializeGracefulShutdown(options?: Partial<ShutdownOptions>): GracefulShutdownManager;
