/**
 * Hot Reload System for AGI Core
 *
 * Enables seamless version transitions by:
 * 1. Detecting when a new version is available
 * 2. Hot-swapping modules where possible
 * 3. Gracefully restarting when full reload is needed
 * 4. Preserving state across reloads
 *
 * Integrated with the self-upgrade system for continuous improvement.
 */
import { EventEmitter } from 'node:events';
import { type RLUpgradeContext } from './selfUpgrade.js';
export interface HotReloadConfig {
    /** Enable automatic version checking */
    autoCheck?: boolean;
    /** Check interval in ms (default: 5 minutes) */
    checkInterval?: number;
    /** Enable hot-swap where possible (default: true) */
    enableHotSwap?: boolean;
    /** Logger function */
    logger?: (message: string) => void;
    /** Working directory */
    workingDir?: string;
}
export interface HotReloadState {
    /** Current version */
    currentVersion: string;
    /** Last check timestamp */
    lastCheck: number;
    /** Pending reload */
    pendingReload: boolean;
    /** Modules that can be hot-swapped */
    hotSwappableModules: string[];
    /** State to preserve across reload */
    preservedState: Record<string, unknown>;
}
export type HotReloadEventType = 'hotReload:check' | 'hotReload:available' | 'hotReload:swap' | 'hotReload:restart' | 'hotReload:complete' | 'hotReload:error';
export interface HotReloadEvent {
    type: HotReloadEventType;
    timestamp: number;
    data?: Record<string, unknown>;
}
export interface ReloadStrategy {
    /** Whether hot-swap is possible */
    canHotSwap: boolean;
    /** Modules that need full reload */
    requiresRestart: string[];
    /** Modules that can be hot-swapped */
    hotSwappable: string[];
    /** Estimated downtime */
    estimatedDowntimeMs: number;
}
export declare class HotReload extends EventEmitter {
    private config;
    private state;
    private checkTimer;
    private watchingFiles;
    constructor(config?: HotReloadConfig);
    private loadState;
    private saveState;
    /**
     * Start automatic version checking
     */
    startAutoCheck(): void;
    /**
     * Stop automatic version checking
     */
    stopAutoCheck(): void;
    /**
     * Check for available updates
     */
    checkForUpdates(): Promise<{
        available: boolean;
        version?: string;
        strategy?: ReloadStrategy;
    }>;
    /**
     * Determine the best reload strategy for a version update
     */
    determineReloadStrategy(currentVersion: string, targetVersion: string): Promise<ReloadStrategy>;
    /**
     * Perform hot reload with state preservation
     */
    performHotReload(options?: {
        preserveState?: Record<string, unknown>;
        rlContext?: RLUpgradeContext;
        activeEdits?: string[];
    }): Promise<{
        success: boolean;
        strategy: 'hot-swap' | 'restart';
        error?: string;
    }>;
    /**
     * Hot-swap specific modules without restart
     */
    private hotSwapModules;
    /**
     * Perform full restart with state preservation
     */
    private performFullRestart;
    /**
     * Watch for local file changes (development mode)
     */
    watchFiles(files: string[]): void;
    /**
     * Stop watching files
     */
    unwatchFiles(): void;
    /**
     * Preserve state for reload
     */
    preserveState(key: string, value: unknown): void;
    /**
     * Get preserved state
     */
    getPreservedState<T>(key: string): T | undefined;
    /**
     * Clear preserved state
     */
    clearPreservedState(): void;
    private emitEvent;
    /**
     * Cleanup resources
     */
    dispose(): void;
    /**
     * Check if we should resume from a hot reload
     */
    static shouldResume(): boolean;
    /**
     * Get preserved state from previous session
     */
    static getResumeState(): Record<string, unknown> | null;
}
export declare function getHotReload(config?: HotReloadConfig): HotReload;
export declare function resetHotReload(): void;
/**
 * Quick check and reload if update available
 */
export declare function checkAndReload(options?: {
    preserveState?: Record<string, unknown>;
    rlContext?: RLUpgradeContext;
    logger?: (message: string) => void;
}): Promise<boolean>;
/**
 * Enable auto-checking for updates
 */
export declare function enableAutoCheck(intervalMs?: number): void;
/**
 * Disable auto-checking for updates
 */
export declare function disableAutoCheck(): void;
//# sourceMappingURL=hotReload.d.ts.map