/**
 * Enhanced Multi-Agent Coordination
 *
 * Advanced coordination mechanisms for the multi-agent system based on research:
 * - AgentCoder: Hierarchical multi-agent code generation
 * - RepairAgent: Autonomous LLM-based repair with learning
 * - ComplexAgents: Specialized agent roles and communication
 *
 * Key features:
 * - Adaptive task allocation based on agent performance
 * - Conflict resolution protocol between agents
 * - Resource pooling and efficient context sharing
 * - Progress synchronization for parallel tasks
 * - Learning from success/failure patterns
 */
import { EventEmitter } from 'events';
import { AgentRole, AgentTask, AgentExecutionResult, SharedContext, TaskArtifact } from './types.js';
/**
 * Agent performance metrics
 */
export interface AgentMetrics {
    role: AgentRole;
    totalTasks: number;
    successfulTasks: number;
    failedTasks: number;
    avgDuration: number;
    avgRounds: number;
    successRate: number;
    specialties: Map<string, number>;
    recentPerformance: number[];
}
/**
 * Conflict between agents
 */
export interface AgentConflict {
    id: string;
    type: 'code_overlap' | 'approach_disagreement' | 'resource_contention' | 'deadline_conflict';
    agents: AgentRole[];
    description: string;
    severity: 'low' | 'medium' | 'high';
    timestamp: Date;
    resolution?: ConflictResolution;
}
/**
 * Resolution for a conflict
 */
export interface ConflictResolution {
    strategy: 'priority' | 'consensus' | 'arbitration' | 'merge';
    decision: string;
    resolvedBy: AgentRole;
    timestamp: Date;
}
/**
 * Task dependency information
 */
export interface TaskDependency {
    taskId: string;
    dependsOn: string[];
    blockedBy: string[];
    enables: string[];
}
/**
 * Coordination configuration
 */
export interface CoordinationConfig {
    enableAdaptiveAllocation: boolean;
    minAssignmentConfidence: number;
    maxParallelPerAgent: number;
    enableConflictResolution: boolean;
    conflictTimeout: number;
    enableLearning: boolean;
    historySize: number;
    checkpointInterval: number;
}
/**
 * Resource value types for type-safe resource sharing
 */
export type CodeSnippetResource = {
    code: string;
    source: AgentRole;
    relevance: number;
};
export type FileModificationResource = {
    agent: AgentRole;
    timestamp: Date;
    type: 'create' | 'modify' | 'delete';
};
export type InsightResource = {
    insight: string;
    source: AgentRole;
    confidence: number;
};
export type TestResultResource = {
    passed: boolean;
    output: string;
    timestamp: Date;
};
/**
 * Shared resource pool
 */
export interface ResourcePool {
    codeSnippets: Map<string, CodeSnippetResource>;
    fileModifications: Map<string, FileModificationResource>;
    insights: Map<string, InsightResource>;
    testResults: Map<string, TestResultResource>;
}
/**
 * Maps resource pool keys to their value types
 */
export type ResourceValueType<K extends keyof ResourcePool> = K extends 'codeSnippets' ? CodeSnippetResource : K extends 'fileModifications' ? FileModificationResource : K extends 'insights' ? InsightResource : K extends 'testResults' ? TestResultResource : never;
/**
 * Checkpoint for recovery
 */
export interface Checkpoint {
    id: string;
    timestamp: Date;
    completedTasks: string[];
    pendingTasks: string[];
    artifacts: TaskArtifact[];
    metrics: Map<AgentRole, AgentMetrics>;
    resourcePool: ResourcePool;
}
/**
 * Enhanced Coordination Manager
 */
export declare class EnhancedCoordinator extends EventEmitter {
    private config;
    private agentMetrics;
    private taskDependencies;
    private conflicts;
    private resourcePool;
    private checkpoints;
    private taskHistory;
    private activeTasksPerAgent;
    constructor(config?: Partial<CoordinationConfig>);
    /**
     * Initialize metrics for all agent roles
     */
    private initializeMetrics;
    /**
     * Create empty resource pool
     */
    private createEmptyResourcePool;
    /**
     * Adaptively allocate a task to the best suited agent
     */
    allocateTask(task: AgentTask, availableAgents: AgentRole[]): {
        agent: AgentRole;
        confidence: number;
        reasoning: string;
    };
    /**
     * Calculate recent success rate
     */
    private calculateRecentSuccessRate;
    /**
     * Extract task type for specialty tracking
     */
    private extractTaskType;
    /**
     * Record task completion for learning
     */
    recordTaskCompletion(task: AgentTask, result: AgentExecutionResult): void;
    /**
     * Mark task as started
     */
    markTaskStarted(task: AgentTask, agent: AgentRole): void;
    /**
     * Detect and handle conflicts
     */
    detectConflicts(tasks: AgentTask[], _context: SharedContext): AgentConflict[];
    /**
     * Resolve a conflict
     */
    resolveConflict(conflictId: string, resolution: Omit<ConflictResolution, 'timestamp'>): boolean;
    /**
     * Auto-resolve conflicts using predefined strategies
     */
    autoResolveConflicts(): void;
    /**
     * Share a resource with the pool
     */
    shareResource<K extends keyof ResourcePool>(type: K, key: string, value: ResourceValueType<K>, source: AgentRole): void;
    /**
     * Get resource from pool
     */
    getResource<T>(type: keyof ResourcePool, key: string): T | undefined;
    /**
     * Build task dependencies
     */
    buildDependencies(tasks: AgentTask[]): Map<string, TaskDependency>;
    /**
     * Get ready tasks (no blockers)
     */
    getReadyTasks(tasks: AgentTask[]): AgentTask[];
    /**
     * Create a checkpoint for recovery
     */
    createCheckpoint(): Checkpoint;
    /**
     * Restore from checkpoint
     */
    restoreFromCheckpoint(checkpointId: string): boolean;
    /**
     * Get performance report
     */
    getPerformanceReport(): string;
    /**
     * Get metrics for an agent
     */
    getAgentMetrics(role: AgentRole): AgentMetrics | undefined;
    /**
     * Get all conflicts
     */
    getConflicts(): AgentConflict[];
    /**
     * Get the resource pool
     */
    getResourcePool(): ResourcePool;
    /**
     * Reset coordinator state
     */
    reset(): void;
    /**
     * Dispose and cleanup
     */
    dispose(): void;
}
/**
 * Create an EnhancedCoordinator instance
 */
export declare function createEnhancedCoordinator(config?: Partial<CoordinationConfig>): EnhancedCoordinator;
export declare function getEnhancedCoordinator(config?: Partial<CoordinationConfig>): EnhancedCoordinator;
export declare function resetEnhancedCoordinator(): void;
