/**
 * Iterative Repair Engine
 *
 * Implements conversation-driven repair with test feedback loop.
 * Based on research from:
 * - ChatRepair (ISSTA 2024): Conversational program repair
 * - RepairAgent: Autonomous LLM-based repair
 * - RePair: Reinforcement learning for debugging
 *
 * Key features:
 * 1. Iterative fix attempts with instant feedback
 * 2. Learning from both successes and failures
 * 3. Progressive error understanding
 * 4. Multi-strategy repair attempts
 */
import { EventEmitter } from 'events';
export interface RepairContext {
    file: string;
    errorMessage: string;
    errorType: 'compile' | 'runtime' | 'test' | 'lint' | 'type';
    errorLine?: number;
    errorColumn?: number;
    codeSnippet?: string;
    testCommand?: string;
    previousAttempts: RepairAttempt[];
}
export interface RepairAttempt {
    id: string;
    strategy: RepairStrategy;
    patch: string;
    originalCode: string;
    newCode: string;
    success: boolean;
    feedback: RepairFeedback;
    timestamp: number;
}
export interface RepairFeedback {
    compiled: boolean;
    testsRun: number;
    testsPassed: number;
    testsFailed: number;
    newErrors: string[];
    fixedErrors: string[];
    regressions: string[];
    executionTime: number;
}
export type RepairStrategy = 'null_check' | 'type_coercion' | 'boundary_check' | 'exception_handling' | 'import_fix' | 'syntax_fix' | 'logic_fix' | 'api_update' | 'refactor';
export interface RepairConfig {
    maxAttempts: number;
    testTimeout: number;
    enableRollback: boolean;
    strategies: RepairStrategy[];
    learnFromHistory: boolean;
}
export interface RepairResult {
    success: boolean;
    finalPatch?: string;
    attempts: RepairAttempt[];
    totalTime: number;
    strategyUsed?: RepairStrategy;
    lessonsLearned: string[];
}
export declare class IterativeRepairEngine extends EventEmitter {
    private config;
    private history;
    private successfulPatterns;
    constructor(config?: Partial<RepairConfig>);
    /**
     * Attempt iterative repair with feedback loop
     */
    repair(context: RepairContext): Promise<RepairResult>;
    /**
     * Analyze error and prioritize repair strategies
     */
    private analyzeAndPrioritizeStrategies;
    /**
     * Generate a patch based on strategy
     */
    private generatePatch;
    /**
     * Apply patch and run tests to get feedback
     */
    private applyAndTest;
    /**
     * Apply patch to code (simplified implementation)
     */
    private applyPatchToCode;
    /**
     * Run tests and collect feedback
     */
    private runTests;
    /**
     * Extract error messages from output
     */
    private extractErrors;
    /**
     * Rollback to original code
     */
    private rollback;
    /**
     * Learn from successful repair
     */
    private learnFromSuccess;
    /**
     * Learn from failed repair attempt
     */
    private learnFromFailure;
    /**
     * Hash error message for pattern matching
     */
    private hashError;
    /**
     * Get repair history
     */
    getHistory(): Map<string, RepairAttempt[]>;
    /**
     * Get learned patterns
     */
    getLearnedPatterns(): Map<string, RepairStrategy>;
    /**
     * Clear learned patterns
     */
    clearLearning(): void;
    /**
     * Dispose and cleanup
     */
    dispose(): void;
    /**
     * ChatRepair-style conversational repair with full context
     *
     * Implements the key insight from ChatRepair (ISSTA 2024):
     * - Include failing test code in context
     * - Include full error message and stack trace
     * - Maintain conversation history for multi-turn repair
     * - Validate plausibility of patches before testing
     *
     * @param context Repair context with error information
     * @param generatePatch Function to generate patch using LLM
     * @returns RepairResult with conversation history
     */
    chatRepair(context: RepairContext & {
        testCode?: string;
        stackTrace?: string;
        buggyMethod?: string;
    }, generatePatch: (prompt: string, history: ConversationTurn[]) => Promise<string>): Promise<RepairResult & {
        conversation: ConversationTurn[];
    }>;
    /**
     * Build ChatRepair-style prompt with full context
     */
    private buildChatRepairPrompt;
    /**
     * Build follow-up prompt after failed attempt
     */
    private buildFollowUpPrompt;
    /**
     * Build test feedback message for conversation
     */
    private buildTestFeedbackMessage;
    /**
     * Extract patch from LLM response
     */
    private extractPatchFromResponse;
    /**
     * Validate patch plausibility before testing
     * (ChatRepair validation to reduce wasted test runs)
     */
    private validatePatchPlausibility;
}
/**
 * Conversation turn for ChatRepair
 */
export interface ConversationTurn {
    role: 'system' | 'user' | 'assistant';
    content: string;
}
export declare function getIterativeRepairEngine(config?: Partial<RepairConfig>): IterativeRepairEngine;
export declare function resetIterativeRepairEngine(): void;
