/**
 * Self-Upgrade System for AGI Core
 *
 * Provides the ability to:
 * 1. npm install a fresh version of the CLI
 * 2. Launch a new CLI instance
 * 3. Continue work seamlessly after upgrade
 * 4. Integrate with edits, builds, tests, and RL scoring
 *
 * This module enables true self-improvement through version updates
 * while maintaining session continuity.
 */
import { EventEmitter } from 'node:events';
export interface SelfUpgradeConfig {
    /** Package name to upgrade (default: deepseek-coder-cli) */
    packageName?: string;
    /** Whether to run in global mode (default: true) */
    global?: boolean;
    /** Working directory for session resumption */
    workingDir?: string;
    /** Custom logger function */
    logger?: (message: string) => void;
    /** Timeout for npm operations in ms (default: 5 minutes) */
    timeout?: number;
    /** Whether to automatically restart after upgrade */
    autoRestart?: boolean;
    /** Session state to preserve across upgrade */
    sessionState?: UpgradeSessionState;
}
export interface UpgradeSessionState {
    /** Current working directory */
    workingDir: string;
    /** Pending tasks to continue */
    pendingTasks?: string[];
    /** Last user prompt */
    lastPrompt?: string;
    /** Context summary for resumption */
    contextSummary?: string;
    /** Current version before upgrade */
    fromVersion: string;
    /** Target version after upgrade */
    toVersion?: string;
    /** Timestamp of upgrade initiation */
    timestamp: number;
    /** RL iteration context if applicable */
    rlContext?: RLUpgradeContext;
    /** Files being edited before upgrade */
    activeEdits?: string[];
    /** Build state before upgrade */
    buildState?: BuildState;
    /** Test state before upgrade */
    testState?: TestState;
}
export interface RLUpgradeContext {
    /** Current iteration number */
    iteration: number;
    /** Current agent variant */
    variant: 'primary' | 'refiner';
    /** Objective being worked on */
    objective: string;
    /** Current score before upgrade */
    currentScore: number;
    /** Files modified so far */
    filesModified: string[];
}
export interface BuildState {
    /** Whether build was successful */
    success: boolean;
    /** Build output/errors */
    output?: string;
    /** Build command used */
    command?: string;
}
export interface TestState {
    /** Number of tests passed */
    passed: number;
    /** Number of tests failed */
    failed: number;
    /** Test output */
    output?: string;
    /** Test command used */
    command?: string;
}
export interface UpgradeResult {
    /** Whether upgrade was successful */
    success: boolean;
    /** Previous version */
    fromVersion: string;
    /** New version (if successful) */
    toVersion?: string;
    /** Error message if failed */
    error?: string;
    /** Whether CLI was restarted */
    restarted: boolean;
    /** Duration of upgrade in ms */
    durationMs: number;
    /** RL score impact (if applicable) */
    rlScoreImpact?: number;
}
export interface VersionInfo {
    /** Current installed version */
    current: string;
    /** Latest available version */
    latest: string;
    /** Whether update is available */
    updateAvailable: boolean;
    /** Release notes URL */
    releaseNotesUrl?: string;
}
export type UpgradeEventType = 'upgrade:start' | 'upgrade:download' | 'upgrade:install' | 'upgrade:complete' | 'upgrade:error' | 'upgrade:restart' | 'upgrade:resume' | 'upgrade:rl-checkpoint';
export interface UpgradeEvent {
    type: UpgradeEventType;
    timestamp: number;
    data?: Record<string, unknown>;
}
export declare class SelfUpgrade extends EventEmitter {
    private config;
    private upgradeInProgress;
    private childProcess;
    constructor(config?: SelfUpgradeConfig);
    /**
     * Check for available updates
     */
    checkForUpdates(): Promise<VersionInfo>;
    /**
     * Get currently installed version
     */
    getCurrentVersion(): Promise<string>;
    /**
     * Get latest available version from npm registry
     */
    getLatestVersion(): Promise<string>;
    /**
     * Compare two semver versions
     * Returns: 1 if v1 > v2, -1 if v1 < v2, 0 if equal
     */
    private compareVersions;
    /**
     * Perform npm install of fresh version
     */
    npmInstallFresh(version?: string): Promise<UpgradeResult>;
    /**
     * Launch a new CLI instance and optionally continue work
     */
    launchNewInstance(resumeSession?: boolean): Promise<boolean>;
    /**
     * Save session state for resumption after upgrade
     */
    saveSessionState(state: UpgradeSessionState): void;
    /**
     * Load session state after upgrade
     */
    loadSessionState(): UpgradeSessionState | null;
    /**
     * Clear session state after successful resumption
     */
    clearSessionState(): void;
    /**
     * Check if there's a pending session to resume
     */
    hasPendingSession(): boolean;
    /**
     * Save RL checkpoint before upgrade (for RL scoring continuity)
     */
    saveRLCheckpoint(context: RLUpgradeContext): void;
    /**
     * Load RL checkpoint after upgrade
     */
    loadRLCheckpoint(): RLUpgradeContext | null;
    /**
     * Clear RL checkpoint after successful resumption
     */
    clearRLCheckpoint(): void;
    /**
     * Calculate RL score impact from upgrade
     * Positive impact if upgrade improves capability
     */
    calculateRLScoreImpact(preUpgrade: RLUpgradeContext, postUpgradeSuccess: boolean): number;
    /**
     * Upgrade with build verification
     */
    upgradeWithBuildCheck(version?: string, buildCommand?: string): Promise<UpgradeResult & {
        buildSuccess: boolean;
    }>;
    /**
     * Upgrade with test verification
     */
    upgradeWithTestCheck(version?: string, testCommand?: string): Promise<UpgradeResult & {
        testState: TestState;
    }>;
    /**
     * Full upgrade with build and test verification
     */
    upgradeWithFullVerification(version?: string, buildCommand?: string, testCommand?: string): Promise<UpgradeResult & {
        buildSuccess: boolean;
        testState: TestState;
    }>;
    private parseTestCount;
    /**
     * Save active edits before upgrade for continuity
     */
    saveActiveEdits(files: string[]): void;
    /**
     * Get active edits to resume after upgrade
     */
    getActiveEdits(): string[];
    private logUpgrade;
    private emitEvent;
    /**
     * Check if this process was started after an upgrade
     */
    static wasUpgraded(): boolean;
    /**
     * Get the version we upgraded from
     */
    static getUpgradeFromVersion(): string | null;
    /**
     * Check if we should resume a session
     */
    static shouldResumeSession(): boolean;
}
export declare function getSelfUpgrade(config?: SelfUpgradeConfig): SelfUpgrade;
export declare function resetSelfUpgrade(): void;
/**
 * Quick upgrade to latest version with session continuity
 */
export declare function upgradeToLatest(options?: {
    autoRestart?: boolean;
    workingDir?: string;
    logger?: (message: string) => void;
}): Promise<UpgradeResult>;
/**
 * Upgrade with full verification (build + tests)
 */
export declare function upgradeAndVerify(options?: {
    version?: string;
    buildCommand?: string;
    testCommand?: string;
    workingDir?: string;
    logger?: (message: string) => void;
}): Promise<UpgradeResult & {
    buildSuccess: boolean;
    testState: TestState;
}>;
/**
 * Save current work state for upgrade resumption
 */
export declare function saveUpgradeState(state: Omit<UpgradeSessionState, 'timestamp' | 'fromVersion'>): void;
/**
 * Resume work after upgrade
 */
export declare function resumeAfterUpgrade(): UpgradeSessionState | null;
//# sourceMappingURL=selfUpgrade.d.ts.map