/** * Enhanced Multi-Agent Orchestration with Clickable Monitoring * Integrates subagent spawning visibility and lifecycle management */ import { XrayStateManager } from "../state/state-manager.js"; export interface AgentSpawnRequest { agentType: string; task: string; context?: Record; priority?: "low" | "medium" | "high" | "critical"; timeout?: number; dependencies?: string[]; } export interface AgentExecutionResult { success: boolean; agentType: string; task: string; executionTime?: number; complexity?: number; result?: unknown; delegationResult?: unknown; } export interface SpawnedAgent { id: string; agentType: string; task: string; status: "spawning" | "active" | "completed" | "failed" | "cancelled"; startTime: number; endTime?: number; result?: AgentExecutionResult; error?: string; progress: number; clickable: boolean; monitorable: boolean; cleanupRequired: boolean; spawnTrackingId: string | undefined; } export interface AgentOrchestrationState { activeAgents: Map; pendingSpawns: AgentSpawnRequest[]; completedAgents: Map; failedAgents: Map; agentDependencies: Map; monitoringEnabled: boolean; cleanupInterval: number; isMainOrchestrator: boolean; } export interface ExecutionContext { isExecutingAsSubagent: boolean; currentAgentId: string | null; spawnStack: string[]; } export interface OrchestrationDelegationRequest { operation: string; description: string; context?: Record; } export interface OrchestrationDelegationResult { success: boolean; results?: Array<{ agent: string; output: unknown; executionTime: number; }>; totalTime: number; errors?: string[]; agents?: string[]; } export declare class EnhancedMultiAgentOrchestrator { private state; private stateManager; private complexityAnalyzer; private agentDelegator; private executionContext; private cleanupTimer; constructor(stateManager?: XrayStateManager, isMainOrchestrator?: boolean); /** * 🚨 SECURITY: Check if currently executing as a subagent * Prevents subagents from spawning other subagents (infinite loops, resource exhaustion) */ private isCurrentlyExecutingAsSubagent; /** * Enhanced agent spawning with clickable monitoring integration */ spawnAgent(request: AgentSpawnRequest): Promise; /** * Execute agent with monitoring and cleanup */ private executeAgent; /** * Execute agent using the agent delegator system */ private executeAgentWithDelegator; /** * Simulate agent execution (FALLBACK - used when plugin not loaded) * * NOTE: The primary execution path is through the OpenCode plugin: * - .opencode/plugin/xray-codex-injection.js intercepts prompts * - Routes to agents via .opencode/agents/*.yml configs * - OpenCode spawns actual agent processes * - Hermes Agent handles MCP server execution * * This simulation is a fallback for: * - Testing without real agent execution * - When plugin fails to load * - Documentation of what the framework orchestrates * * For production use, ensure the plugin is loaded in OpenCode. */ private simulateAgentExecution; /** * Get estimated execution time for agent type */ private getAgentExecutionTime; /** * Update agent monitoring (integrates with clickable interface) */ private updateAgentMonitoring; /** * Check for pending spawns that can now execute */ private checkPendingSpawns; /** * Lookup one monitored agent without copying every spawn map. * Precedence matches getMonitoringInterface: failed, then completed, then active. */ getMonitoredAgent(agentId: string): SpawnedAgent | undefined; /** * Get clickable agent monitoring interface */ getMonitoringInterface(): Record; /** * Cancel agent execution */ cancelAgent(agentId: string): Promise; /** * Initialize cleanup system for completed agents */ private initializeCleanupSystem; /** * Perform cleanup of completed/failed agents */ private performCleanup; /** * Get orchestration statistics */ getStatistics(): { activeAgents: number; completedAgents: number; failedAgents: number; pendingSpawns: number; totalSpawned: number; }; /** * Shutdown orchestration system */ shutdown(): Promise; start(): void; stop(): void; } export declare const enhancedMultiAgentOrchestrator: EnhancedMultiAgentOrchestrator;