UNPKG

claude-flow

Version:

Enterprise-grade AI agent orchestration with ruv-swarm integration (Alpha Release)

1,039 lines (913 loc) â€ĸ 33.3 kB
/** * Enhanced Web UI Complete - Full Integration * Combines all MCP tools with enhanced UI views and real-time updates * Provides access to all 87 Claude-Flow MCP tools through a comprehensive interface */ import { printSuccess, printError, printWarning, printInfo } from '../utils.js'; import { compat } from '../runtime-detector.js'; import SwarmWebUIIntegration from './swarm-webui-integration.js'; import MCPIntegrationLayer from './mcp-integration-layer.js'; import ToolExecutionFramework from './tool-execution-framework.js'; import { EnhancedUIViews, ENHANCED_VIEWS } from './enhanced-ui-views.js'; import RealtimeUpdateSystem from './realtime-update-system.js'; // Enhanced view modes with all tool categories const ALL_VIEWS = { ...ENHANCED_VIEWS, // Add any additional views if needed }; export class EnhancedWebUIComplete { constructor() { this.processes = new Map(); this.running = true; this.selectedIndex = 0; this.currentView = ALL_VIEWS.PROCESSES; this.agents = []; this.tasks = []; this.memoryStats = { totalEntries: 0, totalSize: 0, namespaces: [], }; this.logs = []; this.systemStats = { uptime: 0, totalTasks: 0, completedTasks: 0, activeAgents: 0, memoryUsage: 0, cpuUsage: 0, }; // Enhanced components this.mcpIntegration = null; this.toolFramework = null; this.enhancedViews = null; this.realtimeUpdates = null; // Input handling this.inputBuffer = ''; this.commandHistory = []; this.historyIndex = -1; // Colors for consistent styling this.colors = { cyan: (text) => `\x1b[36m${text}\x1b[0m`, gray: (text) => `\x1b[90m${text}\x1b[0m`, white: (text) => `\x1b[37m${text}\x1b[0m`, yellow: (text) => `\x1b[33m${text}\x1b[0m`, green: (text) => `\x1b[32m${text}\x1b[0m`, red: (text) => `\x1b[31m${text}\x1b[0m`, blue: (text) => `\x1b[34m${text}\x1b[0m`, magenta: (text) => `\x1b[35m${text}\x1b[0m`, bold: (text) => `\x1b[1m${text}\x1b[0m`, dim: (text) => `\x1b[2m${text}\x1b[0m`, }; this.initializeEnhancedUI(); } /** * Initialize all enhanced UI components */ async initializeEnhancedUI() { try { // Initialize original swarm integration this.swarmIntegration = new SwarmWebUIIntegration(this); // Initialize MCP integration layer this.mcpIntegration = new MCPIntegrationLayer(this); // Initialize tool execution framework this.toolFramework = new ToolExecutionFramework(this); // Initialize enhanced UI views this.enhancedViews = new EnhancedUIViews(this); // Initialize real-time update system this.realtimeUpdates = new RealtimeUpdateSystem(this); // Initialize default processes this.initializeProcesses(); // Initialize mock data await this.initializeSystemData(); // Start system monitoring this.startSystemMonitoring(); this.addLog('success', '🚀 Enhanced Web UI fully initialized with all 87 MCP tools'); } catch (error) { this.addLog('error', `Failed to initialize enhanced UI: ${error.message}`); throw error; } } /** * Initialize system processes */ initializeProcesses() { const PROCESSES = [ { id: 'event-bus', name: 'Event Bus', description: 'Central event distribution system' }, { id: 'orchestrator', name: 'Orchestrator', description: 'Main coordination engine' }, { id: 'memory-manager', name: 'Memory Manager', description: 'Persistent memory system' }, { id: 'terminal-pool', name: 'Terminal Pool', description: 'Terminal session management' }, { id: 'mcp-server', name: 'MCP Server', description: 'Model Context Protocol server' }, { id: 'coordinator', name: 'Coordinator', description: 'Task coordination service' }, { id: 'neural-engine', name: 'Neural Engine', description: 'Neural network processing' }, { id: 'analysis-service', name: 'Analysis Service', description: 'Performance analysis' }, { id: 'workflow-engine', name: 'Workflow Engine', description: 'Automation workflows' }, { id: 'github-connector', name: 'GitHub Connector', description: 'GitHub integration' }, { id: 'daa-controller', name: 'DAA Controller', description: 'Dynamic agent architecture' }, ]; PROCESSES.forEach((p) => { this.processes.set(p.id, { ...p, status: 'running', // Start most services as running pid: Math.floor(Math.random() * 50000) + 1000, uptime: Math.floor(Math.random() * 86400), // Random uptime up to 24h cpu: Math.random() * 5, memory: Math.random() * 100, }); }); } /** * Initialize system data */ async initializeSystemData() { // Initialize swarm await this.swarmIntegration.initializeSwarm('hierarchical', 8); // Initialize memory stats this.memoryStats = { totalEntries: 156, totalSize: '2.3 MB', namespaces: [ { name: 'neural', entries: 42, size: '856 KB' }, { name: 'swarm', entries: 35, size: '645 KB' }, { name: 'analysis', entries: 28, size: '423 KB' }, { name: 'workflow', entries: 24, size: '298 KB' }, { name: 'github', entries: 15, size: '156 KB' }, { name: 'system', entries: 12, size: '89 KB' }, ], }; // Initialize logs this.logs = [ { time: new Date(), level: 'success', message: '🧠 Neural engine initialized with 27 models', }, { time: new Date(), level: 'success', message: '🐝 Swarm orchestration active with hierarchical topology', }, { time: new Date(), level: 'info', message: '📊 Analysis service monitoring 13 performance metrics', }, { time: new Date(), level: 'success', message: '🔄 Workflow engine loaded 11 automation tools', }, { time: new Date(), level: 'info', message: '🐙 GitHub connector established with 8 integration tools', }, { time: new Date(), level: 'success', message: '🤖 DAA controller managing 8 dynamic agent tools', }, { time: new Date(), level: 'success', message: '💾 Memory system active with 12 persistence tools', }, { time: new Date(), level: 'success', message: 'đŸ› ī¸ System utilities loaded 8 management tools', }, ]; // Start uptime counter setInterval(() => { this.systemStats.uptime++; // Update process uptimes this.processes.forEach((process) => { if (process.status === 'running') { process.uptime++; } }); }, 1000); } /** * Start system monitoring */ startSystemMonitoring() { setInterval(() => { // Update system stats this.systemStats.cpuUsage = Math.max( 0, this.systemStats.cpuUsage + (Math.random() - 0.5) * 2, ); this.systemStats.memoryUsage = Math.max( 0, this.systemStats.memoryUsage + (Math.random() - 0.5) * 3, ); // Update process stats this.processes.forEach((process) => { if (process.status === 'running') { process.cpu = Math.max(0, process.cpu + (Math.random() - 0.5) * 1); process.memory = Math.max(0, process.memory + (Math.random() - 0.5) * 5); } }); // Emit performance metrics for real-time updates if (this.realtimeUpdates) { this.realtimeUpdates.emit('system_stats_update', { cpuUsage: this.systemStats.cpuUsage, memoryUsage: this.systemStats.memoryUsage, processCount: this.processes.size, }); } }, 5000); } /** * Start the enhanced UI */ async start() { // Clear screen console.clear(); // Show enhanced welcome printSuccess('🧠 Claude-Flow Enhanced Web UI v2.0.0'); printInfo('🔧 Comprehensive MCP Tool Integration - 87 Tools Available'); console.log('─'.repeat(80)); console.log(); // Show tool categories summary this.showToolCategoriesSummary(); // Initial render this.render(); // Setup input handling this.setupInputHandling(); // Main UI loop while (this.running) { await this.handleInput(); if (this.running) { this.render(); } } } /** * Show tool categories summary at startup */ showToolCategoriesSummary() { const categories = [ { name: 'Swarm Coordination', count: 12, icon: '🐝' }, { name: 'Neural Networks', count: 15, icon: '🧠' }, { name: 'Memory & Persistence', count: 12, icon: '💾' }, { name: 'Analysis & Monitoring', count: 13, icon: '📊' }, { name: 'Workflow & Automation', count: 11, icon: '🔄' }, { name: 'GitHub Integration', count: 8, icon: '🐙' }, { name: 'Dynamic Agents (DAA)', count: 8, icon: '🤖' }, { name: 'System & Utilities', count: 8, icon: 'đŸ› ī¸' }, ]; console.log(this.colors.cyan('📂 Available Tool Categories:')); categories.forEach((cat) => { console.log( ` ${cat.icon} ${this.colors.white(cat.name)}: ${this.colors.yellow(cat.count)} tools`, ); }); console.log(); console.log(this.colors.green(`Total: ${this.colors.bold('87')} MCP tools ready for use`)); console.log(); } /** * Setup input handling for enhanced features */ setupInputHandling() { // Enable raw input mode for better key handling if (process.stdin.setRawMode) { process.stdin.setRawMode(true); } process.stdin.resume(); } /** * Enhanced render method */ render() { // Clear screen and move cursor to top console.log('\x1b[2J\x1b[H'); // Header with enhanced navigation this.renderEnhancedHeader(); // Main content based on current view switch (this.currentView) { case ALL_VIEWS.PROCESSES: this.renderProcessView(); break; case ALL_VIEWS.STATUS: this.renderStatusView(); break; case ALL_VIEWS.ORCHESTRATION: this.renderOrchestrationView(); break; case ALL_VIEWS.MEMORY: this.renderMemoryView(); break; case ALL_VIEWS.LOGS: this.renderLogsView(); break; case ALL_VIEWS.NEURAL: this.enhancedViews.renderNeuralView(); break; case ALL_VIEWS.ANALYSIS: this.enhancedViews.renderAnalysisView(); break; case ALL_VIEWS.WORKFLOW: this.enhancedViews.renderWorkflowView(); break; case ALL_VIEWS.GITHUB: this.enhancedViews.renderGitHubView(); break; case ALL_VIEWS.DAA: this.enhancedViews.renderDAAView(); break; case ALL_VIEWS.SYSTEM: this.enhancedViews.renderSystemView(); break; case ALL_VIEWS.TOOLS: this.enhancedViews.renderToolsView(); break; case ALL_VIEWS.HELP: this.renderEnhancedHelpView(); break; } // Enhanced footer with more controls this.renderEnhancedFooter(); } /** * Render enhanced header with all navigation options */ renderEnhancedHeader() { console.log(this.colors.cyan(this.colors.bold('🧠 Claude-Flow Enhanced Web UI v2.0.0'))); console.log(this.colors.gray('─'.repeat(80))); // Main navigation tabs (row 1) const mainTabs = [ { key: '1', view: ALL_VIEWS.PROCESSES, label: 'Processes' }, { key: '2', view: ALL_VIEWS.STATUS, label: 'Status' }, { key: '3', view: ALL_VIEWS.ORCHESTRATION, label: 'Orchestration' }, { key: '4', view: ALL_VIEWS.MEMORY, label: 'Memory' }, { key: '5', view: ALL_VIEWS.LOGS, label: 'Logs' }, ]; let mainTabLine = ''; mainTabs.forEach((tab) => { const isActive = this.currentView === tab.view; const label = isActive ? this.colors.yellow(`[${tab.label}]`) : this.colors.gray(`${tab.label}`); mainTabLine += ` ${this.colors.bold(tab.key)}:${label}`; }); console.log(mainTabLine); // Enhanced tool tabs (row 2) const toolTabs = [ { key: '6', view: ALL_VIEWS.NEURAL, label: 'Neural', icon: '🧠' }, { key: '7', view: ALL_VIEWS.ANALYSIS, label: 'Analysis', icon: '📊' }, { key: '8', view: ALL_VIEWS.WORKFLOW, label: 'Workflow', icon: '🔄' }, { key: '9', view: ALL_VIEWS.GITHUB, label: 'GitHub', icon: '🐙' }, { key: '0', view: ALL_VIEWS.DAA, label: 'DAA', icon: '🤖' }, ]; let toolTabLine = ''; toolTabs.forEach((tab) => { const isActive = this.currentView === tab.view; const label = isActive ? this.colors.yellow(`[${tab.icon}${tab.label}]`) : this.colors.gray(`${tab.icon}${tab.label}`); toolTabLine += ` ${this.colors.bold(tab.key)}:${label}`; }); console.log(toolTabLine); // Additional tabs (row 3) const additionalTabs = [ { key: 't', view: ALL_VIEWS.TOOLS, label: 'Tools', icon: 'đŸŽ›ī¸' }, { key: 's', view: ALL_VIEWS.SYSTEM, label: 'System', icon: 'đŸ› ī¸' }, { key: 'h', view: ALL_VIEWS.HELP, label: 'Help', icon: '❓' }, ]; let additionalTabLine = ''; additionalTabs.forEach((tab) => { const isActive = this.currentView === tab.view; const label = isActive ? this.colors.yellow(`[${tab.icon}${tab.label}]`) : this.colors.gray(`${tab.icon}${tab.label}`); additionalTabLine += ` ${this.colors.bold(tab.key)}:${label}`; }); console.log(additionalTabLine); console.log(this.colors.gray('─'.repeat(80))); console.log(); } /** * Render enhanced help view */ renderEnhancedHelpView() { console.log(this.colors.white(this.colors.bold('❓ Enhanced Web UI Help'))); console.log(); console.log(this.colors.cyan('đŸ—ī¸ Navigation Keys:')); console.log(' 1-5: Main views (Processes, Status, Orchestration, Memory, Logs)'); console.log(' 6-0: Tool categories (Neural, Analysis, Workflow, GitHub, DAA)'); console.log(' t: Tool execution center'); console.log(' s: System utilities'); console.log(' h: This help screen'); console.log(); console.log(this.colors.cyan('🔧 Tool Categories:')); console.log(' 🧠 Neural (15 tools): Training, prediction, model management'); console.log(' 📊 Analysis (13 tools): Performance reports, monitoring, metrics'); console.log(' 🔄 Workflow (11 tools): Automation, pipelines, scheduling'); console.log(' 🐙 GitHub (8 tools): Repository management, PR automation'); console.log(' 🤖 DAA (8 tools): Dynamic agent architecture'); console.log(' đŸ› ī¸ System (8 tools): Configuration, security, diagnostics'); console.log(' 🐝 Swarm (12 tools): Agent coordination, task orchestration'); console.log(' 💾 Memory (12 tools): Persistence, caching, namespaces'); console.log(); console.log(this.colors.cyan('⚡ Quick Actions:')); console.log(' r: Run custom tool (from any view)'); console.log(' w: Execute workflow'); console.log(' b: Batch tool execution'); console.log(' c: Clear screen'); console.log(' q: Quit application'); console.log(); console.log(this.colors.cyan('💡 Features:')); console.log(' â€ĸ Real-time updates and monitoring'); console.log(' â€ĸ Comprehensive MCP tool integration'); console.log(' â€ĸ Batch and workflow execution'); console.log(' â€ĸ Performance tracking and analysis'); console.log(' â€ĸ Memory management and persistence'); console.log(' â€ĸ GitHub integration and automation'); console.log(' â€ĸ Dynamic agent architecture'); console.log(' â€ĸ Neural network management'); } /** * Render enhanced footer */ renderEnhancedFooter() { console.log(); console.log(this.colors.gray('─'.repeat(80))); // Status line const mcpStatus = this.mcpIntegration ? this.mcpIntegration.getStatus() : null; const toolStatus = this.toolFramework ? this.toolFramework.getStatus() : null; let statusLine = `🧠 Claude-Flow Enhanced UI | `; statusLine += `MCP: ${mcpStatus?.mcpAvailable ? this.colors.green('✓') : this.colors.red('✗')} | `; statusLine += `Tools: ${this.colors.yellow(mcpStatus?.totalTools || 87)} | `; statusLine += `Active: ${this.colors.blue(toolStatus?.currentExecutions || 0)} | `; statusLine += `Queued: ${this.colors.cyan(toolStatus?.queuedExecutions || 0)} | `; statusLine += `Uptime: ${this.colors.white(this.formatUptime(this.systemStats.uptime))}`; console.log(statusLine); // Controls line let controlsLine = `${this.colors.gray('Controls:')} `; controlsLine += `${this.colors.yellow('r')}=Run Tool | `; controlsLine += `${this.colors.yellow('w')}=Workflow | `; controlsLine += `${this.colors.yellow('b')}=Batch | `; controlsLine += `${this.colors.yellow('c')}=Clear | `; controlsLine += `${this.colors.yellow('q')}=Quit | `; controlsLine += `${this.colors.yellow('↑↓')}=Navigate`; console.log(controlsLine); } /** * Enhanced input handling */ async handleInput() { return new Promise((resolve) => { const onData = async (chunk) => { const key = chunk.toString(); // Remove listener process.stdin.removeListener('data', onData); try { // Handle navigation keys if (await this.handleNavigationInput(key)) { resolve(); return; } // Handle enhanced view input if (await this.handleEnhancedViewInput(key)) { resolve(); return; } // Handle global commands if (await this.handleGlobalCommands(key)) { resolve(); return; } // Handle original input await this.handleOriginalInput(key); } catch (error) { this.addLog('error', `Input handling error: ${error.message}`); } resolve(); }; process.stdin.once('data', onData); }); } /** * Handle navigation input */ async handleNavigationInput(key) { const navigationMap = { 1: ALL_VIEWS.PROCESSES, 2: ALL_VIEWS.STATUS, 3: ALL_VIEWS.ORCHESTRATION, 4: ALL_VIEWS.MEMORY, 5: ALL_VIEWS.LOGS, 6: ALL_VIEWS.NEURAL, 7: ALL_VIEWS.ANALYSIS, 8: ALL_VIEWS.WORKFLOW, 9: ALL_VIEWS.GITHUB, 0: ALL_VIEWS.DAA, t: ALL_VIEWS.TOOLS, s: ALL_VIEWS.SYSTEM, h: ALL_VIEWS.HELP, }; if (navigationMap[key]) { this.currentView = navigationMap[key]; this.selectedIndex = 0; this.addLog('info', `Switched to ${this.currentView} view`); return true; } return false; } /** * Handle enhanced view input */ async handleEnhancedViewInput(key) { if (this.enhancedViews) { return await this.enhancedViews.handleEnhancedInput(key, this.currentView); } return false; } /** * Handle global commands */ async handleGlobalCommands(key) { switch (key) { case 'r': await this.promptRunTool(); return true; case 'w': await this.promptRunWorkflow(); return true; case 'b': await this.promptBatchExecution(); return true; case 'c': console.clear(); return true; case 'q': case '\x03': // Ctrl+C await this.shutdown(); return true; } return false; } /** * Prompt for tool execution */ async promptRunTool() { // In a real implementation, this would show an interactive prompt // For now, execute a sample tool this.addLog('info', 'Tool execution prompt (demo)'); try { const result = await this.toolFramework.executeTool('features_detect'); this.addLog('success', 'Tool executed successfully'); this.enhancedViews.displayToolResult(result); } catch (error) { this.addLog('error', `Tool execution failed: ${error.message}`); } } /** * Prompt for workflow execution */ async promptRunWorkflow() { this.addLog('info', 'Executing sample workflow...'); try { const result = await this.toolFramework.executePredefinedWorkflow('performance_analysis'); this.addLog('success', 'Workflow completed successfully'); } catch (error) { this.addLog('error', `Workflow failed: ${error.message}`); } } /** * Prompt for batch execution */ async promptBatchExecution() { this.addLog('info', 'Executing sample batch...'); const batchTools = [ { toolName: 'swarm_status' }, { toolName: 'neural_status' }, { toolName: 'memory_usage', parameters: { action: 'list' } }, ]; try { const result = await this.toolFramework.executeToolsBatch(batchTools, { parallel: true }); this.addLog( 'success', `Batch completed: ${result.summary.successful}/${result.summary.total} successful`, ); } catch (error) { this.addLog('error', `Batch execution failed: ${error.message}`); } } /** * Handle original input for backward compatibility */ async handleOriginalInput(key) { // Handle original process view navigation if (this.currentView === ALL_VIEWS.PROCESSES) { switch (key) { case '\x1b[A': // Up arrow this.selectedIndex = Math.max(0, this.selectedIndex - 1); break; case '\x1b[B': // Down arrow this.selectedIndex = Math.min(this.processes.size - 1, this.selectedIndex + 1); break; case ' ': case '\r': await this.toggleSelectedProcess(); break; } } } /** * Toggle selected process status */ async toggleSelectedProcess() { const processes = Array.from(this.processes.values()); const selected = processes[this.selectedIndex]; if (selected) { if (selected.status === 'running') { selected.status = 'stopped'; selected.pid = null; this.addLog('warning', `Stopped ${selected.name}`); } else { selected.status = 'running'; selected.pid = Math.floor(Math.random() * 50000) + 1000; this.addLog('success', `Started ${selected.name}`); } } } /** * Add log entry with enhanced formatting */ addLog(level, message) { const logEntry = { time: new Date(), level, message, }; this.logs.unshift(logEntry); // Keep only last 100 logs if (this.logs.length > 100) { this.logs = this.logs.slice(0, 100); } // Emit log event for real-time updates if (this.realtimeUpdates) { this.realtimeUpdates.emit('log_added', logEntry); } } /** * Render process view (original) */ renderProcessView() { console.log(this.colors.white(this.colors.bold('Process Management'))); console.log(); let index = 0; for (const [id, process] of this.processes) { const selected = index === this.selectedIndex; const prefix = selected ? this.colors.yellow('â–ļ ') : ' '; const status = this.getStatusIcon(process.status); const name = selected ? this.colors.yellow(process.name) : this.colors.white(process.name); console.log(`${prefix}${status} ${name}`); console.log(` ${this.colors.gray(process.description)}`); if (process.status === 'running') { const stats = this.colors.dim( `PID: ${process.pid} | Uptime: ${this.formatUptime(process.uptime)} | CPU: ${process.cpu.toFixed(1)}% | Mem: ${process.memory.toFixed(0)}MB`, ); console.log(` ${stats}`); } console.log(); index++; } // Enhanced stats const running = Array.from(this.processes.values()).filter( (p) => p.status === 'running', ).length; console.log(this.colors.gray('─'.repeat(80))); console.log( this.colors.white( `Total: ${this.processes.size} | Running: ${this.colors.green(running)} | Stopped: ${this.colors.gray(this.processes.size - running)}`, ), ); console.log( this.colors.cyan( `Enhanced: ${this.colors.yellow('87 MCP tools')} available across ${this.colors.yellow('8 categories')}`, ), ); } /** * Render status view with enhanced metrics */ renderStatusView() { console.log(this.colors.white(this.colors.bold('Enhanced System Status'))); console.log(); // System overview console.log(this.colors.cyan('📊 System Overview')); console.log(` Uptime: ${this.colors.green(this.formatUptime(this.systemStats.uptime))}`); console.log(` Process Health: ${this.getHealthBar()}`); console.log(` MCP Tools: ${this.colors.yellow('87')} available`); console.log(` Tool Categories: ${this.colors.blue('8')} active`); console.log(); // Enhanced resource usage console.log(this.colors.cyan('đŸ’ģ Resource Usage')); console.log( ` CPU Usage: ${this.getUsageBar(this.systemStats.cpuUsage, 100)} ${this.systemStats.cpuUsage.toFixed(1)}%`, ); console.log( ` Memory: ${this.getUsageBar(this.systemStats.memoryUsage, 100)} ${this.systemStats.memoryUsage.toFixed(1)}%`, ); console.log(); // Enhanced activity metrics console.log(this.colors.cyan('📈 Enhanced Activity Metrics')); console.log( ` Active Agents: ${this.colors.yellow(this.agents.filter((a) => a.status === 'working').length)}/${this.agents.length}`, ); console.log(` Total Tasks: ${this.tasks.length}`); console.log(` Tool Executions: ${this.colors.green('Running')}`); console.log(` Real-time Updates: ${this.colors.green('Active')}`); console.log(); // Tool status const mcpStatus = this.mcpIntegration ? this.mcpIntegration.getStatus() : null; if (mcpStatus) { console.log(this.colors.cyan('🔧 Tool System Status')); console.log( ` MCP Connection: ${mcpStatus.mcpAvailable ? this.colors.green('Connected') : this.colors.red('Mock Mode')}`, ); console.log(` Active Executions: ${this.colors.yellow(mcpStatus.activeExecutions || 0)}`); console.log(` Cache Size: ${this.colors.blue(mcpStatus.cacheSize || 0)} entries`); console.log(); } // Recent events console.log(this.colors.cyan('🔔 Recent Events')); this.logs.slice(0, 5).forEach((log) => { const time = log.time.toLocaleTimeString(); const icon = log.level === 'success' ? '✓' : log.level === 'warning' ? '⚠' : log.level === 'error' ? '❌' : 'ℹ'; const color = log.level === 'success' ? this.colors.green : log.level === 'warning' ? this.colors.yellow : log.level === 'error' ? this.colors.red : this.colors.blue; console.log(` ${this.colors.gray(time)} ${color(icon)} ${log.message}`); }); } /** * Render orchestration view (enhanced) */ renderOrchestrationView() { console.log(this.colors.white(this.colors.bold('Enhanced Swarm Orchestration'))); console.log(); // Enhanced swarm metrics const metrics = this.swarmIntegration.getSwarmMetrics(); if (metrics) { console.log(this.colors.cyan('🐝 Swarm Status')); console.log(` Swarm ID: ${this.colors.yellow(metrics.swarmId)}`); console.log(` Topology: ${this.colors.blue('hierarchical')} (optimized)`); console.log( ` Agents: ${this.colors.green(metrics.agents.active)}/${metrics.agents.total} active`, ); console.log( ` Tasks: ${this.colors.yellow(metrics.tasks.inProgress)} in progress, ${this.colors.green(metrics.tasks.completed)} completed`, ); console.log(` Efficiency: ${this.colors.green(metrics.efficiency + '%')}`); console.log(` Coordination Tools: ${this.colors.cyan('12')} available`); console.log(); } // Enhanced agents section console.log(this.colors.cyan('🤖 Enhanced Agent Pool')); console.log(); this.agents.forEach((agent, index) => { const selected = this.currentView === ALL_VIEWS.ORCHESTRATION && index === this.selectedIndex; const prefix = selected ? this.colors.yellow('â–ļ ') : ' '; const statusIcon = agent.status === 'working' ? this.colors.green('●') : this.colors.gray('○'); const name = selected ? this.colors.yellow(agent.name) : this.colors.white(agent.name); console.log(`${prefix}${statusIcon} ${name} (${agent.type})`); console.log(` ID: ${agent.id} | Tasks: ${agent.tasks} | Status: ${agent.status}`); if (agent.capabilities && agent.capabilities.length > 0) { console.log(` Capabilities: ${this.colors.dim(agent.capabilities.join(', '))}`); } console.log(); }); console.log(this.colors.gray('─'.repeat(40))); console.log( this.colors.cyan('⚡ Quick Actions: [1-9] Execute swarm tools | [r] Run custom tool'), ); } /** * Render memory view (enhanced) */ renderMemoryView() { console.log(this.colors.white(this.colors.bold('Enhanced Memory Management'))); console.log(); // Enhanced memory overview console.log(this.colors.cyan('💾 Memory Overview')); console.log(` Total Entries: ${this.colors.yellow(this.memoryStats.totalEntries)}`); console.log(` Total Size: ${this.colors.blue(this.memoryStats.totalSize)}`); console.log(` Namespaces: ${this.colors.green(this.memoryStats.namespaces.length)}`); console.log(` Persistence Tools: ${this.colors.cyan('12')} available`); console.log(); // Enhanced namespace details console.log(this.colors.cyan('📂 Namespace Details')); this.memoryStats.namespaces.forEach((ns) => { const usageBar = this.getUsageBar(ns.entries, 100); console.log( ` ${this.colors.white(ns.name.padEnd(12))} ${usageBar} ${this.colors.yellow(ns.entries)} entries (${this.colors.blue(ns.size)})`, ); }); console.log(); console.log(this.colors.cyan('⚡ Memory Tools Available:')); console.log(` ${this.colors.gray('â€ĸ Store/Retrieve operations')}`); console.log(` ${this.colors.gray('â€ĸ Backup and restore')}`); console.log(` ${this.colors.gray('â€ĸ Cross-session persistence')}`); console.log(` ${this.colors.gray('â€ĸ Memory analytics and compression')}`); } /** * Render logs view (enhanced) */ renderLogsView() { console.log(this.colors.white(this.colors.bold('Enhanced System Logs'))); console.log(); console.log(this.colors.cyan(`📋 Recent Activity (${this.logs.length} total entries)`)); console.log(); this.logs.slice(0, 15).forEach((log) => { const time = log.time.toLocaleTimeString(); const icon = log.level === 'success' ? this.colors.green('✅') : log.level === 'warning' ? this.colors.yellow('âš ī¸') : log.level === 'error' ? this.colors.red('❌') : this.colors.blue('â„šī¸'); console.log(`${this.colors.gray(time)} ${icon} ${log.message}`); }); console.log(); console.log(this.colors.gray('─'.repeat(80))); console.log( this.colors.cyan( '🔍 Log Analysis Tools Available: Pattern detection, error analysis, usage statistics', ), ); } /** * Utility methods */ getStatusIcon(status) { return status === 'running' ? this.colors.green('●') : this.colors.gray('○'); } formatUptime(seconds) { const hours = Math.floor(seconds / 3600); const minutes = Math.floor((seconds % 3600) / 60); const secs = seconds % 60; return `${hours}h ${minutes}m ${secs}s`; } getHealthBar() { const running = Array.from(this.processes.values()).filter( (p) => p.status === 'running', ).length; const total = this.processes.size; const percentage = (running / total) * 100; return this.getUsageBar(percentage, 100); } getUsageBar(value, max, width = 20) { const percentage = Math.min((value / max) * 100, 100); const filled = Math.round((percentage / 100) * width); const empty = width - filled; const color = percentage > 80 ? this.colors.red : percentage > 60 ? this.colors.yellow : this.colors.green; return color('█'.repeat(filled)) + this.colors.gray('░'.repeat(empty)); } /** * Shutdown the enhanced UI */ async shutdown() { console.log(); this.addLog('info', 'Shutting down Enhanced Web UI...'); // Cleanup enhanced components if (this.enhancedViews) { this.enhancedViews.cleanup(); } if (this.realtimeUpdates) { this.realtimeUpdates.cleanup(); } // Reset terminal if (process.stdin.setRawMode) { process.stdin.setRawMode(false); } process.stdin.pause(); this.running = false; console.log(); printSuccess('👋 Enhanced Web UI shutdown complete'); process.exit(0); } } export default EnhancedWebUIComplete;