UNPKG

mira-consciousness

Version:

Memory & Intelligence Retention Archive - Preserving The Spark

140 lines • 7.18 kB
#!/usr/bin/env node /** * Adaptive Patterns Command * ========================= * * This command analyzes and displays MIRA's adaptive pattern recognition system. * It shows active patterns for the current context, pattern evolution statistics, * and context-aware pattern activation. * * Key Features: * - Context-aware pattern activation * - Pattern relevance scoring based on current context * - Evolution statistics and effectiveness metrics * - Domain-specific pattern analysis * - Pattern learning status and capabilities */ import chalk from 'chalk'; import { DirectPythonInterface } from '../core/DirectPythonInterface.js'; export async function adaptivePatternsCommand(context) { console.log(chalk.cyan('\n🧠 MIRA Adaptive Pattern Analysis')); console.log(chalk.gray('Analyzing context-aware pattern activation and evolution...\n')); try { const pythonInterface = new DirectPythonInterface(); // Parse context argument let contextObj = {}; if (context) { try { contextObj = JSON.parse(context); } catch { // If not JSON, create a simple context contextObj = { project_type: 'general', domain: 'analysis', keywords: [context] }; } } else { // Default context for current project contextObj = { project_type: 'mira_memory_system', domain: 'pattern_analysis', keywords: ['adaptive', 'patterns', 'intelligence', 'evolution'] }; } // Execute adaptive patterns analysis const result = await pythonInterface.executeCommand('adaptive_patterns', contextObj); if (result.success && result.patterns) { const patterns = result.patterns; // Display context analyzed console.log(chalk.blue('šŸŽÆ Context Analyzed:')); Object.entries(patterns.context_analyzed).forEach(([key, value]) => { if (Array.isArray(value)) { console.log(chalk.white(` ${key}: [${value.join(', ')}]`)); } else { console.log(chalk.white(` ${key}: ${value}`)); } }); // Display active patterns count console.log(chalk.green(`\nšŸ” Active Patterns: ${patterns.active_patterns_count}`)); console.log(chalk.magenta(`🧠 Pattern Learning Status: ${patterns.pattern_learning_status}`)); // Display evolution statistics const stats = patterns.evolution_stats; console.log(chalk.yellow('\nšŸ“Š Evolution Statistics:')); console.log(chalk.white(` Total Patterns: ${stats.total_patterns}`)); console.log(chalk.white(` Domains Covered: ${stats.domains_covered}`)); console.log(chalk.white(` Total Usage: ${stats.total_usage}`)); console.log(chalk.white(` Average Success Rate: ${(stats.avg_success_rate * 100).toFixed(1)}%`)); console.log(chalk.white(` Meta Learning Patterns: ${stats.meta_learning_patterns}`)); // Display pattern types breakdown if (stats.patterns_by_type) { console.log(chalk.magenta('\nšŸ·ļø Pattern Types:')); Object.entries(stats.patterns_by_type).forEach(([type, count]) => { console.log(chalk.white(` ${type.replace(/_/g, ' ')}: ${count}`)); }); } // Display active patterns details if (patterns.active_patterns && patterns.active_patterns.length > 0) { console.log(chalk.cyan('\nšŸŽÆ Top Active Patterns:')); patterns.active_patterns.slice(0, 10).forEach((pattern, index) => { console.log(chalk.white(`\n ${index + 1}. ${pattern.pattern_id}`)); console.log(chalk.gray(` Type: ${pattern.type.replace(/_/g, ' ')}`)); console.log(chalk.gray(` Confidence: ${(pattern.confidence * 100).toFixed(1)}%`)); console.log(chalk.gray(` Success Rate: ${(pattern.success_rate * 100).toFixed(1)}%`)); console.log(chalk.gray(` Usage Count: ${pattern.usage_count}`)); if (pattern.domain) { console.log(chalk.gray(` Domain: ${pattern.domain}`)); } if (pattern.keywords && pattern.keywords.length > 0) { console.log(chalk.gray(` Keywords: ${pattern.keywords.join(', ')}`)); } }); } else { console.log(chalk.yellow('\nšŸ“ No active patterns found for current context.')); console.log(chalk.gray('MIRA will learn new patterns based on future interactions.')); } // Provide insights based on pattern analysis console.log(chalk.green('\nšŸ’” Pattern Insights:')); if (patterns.active_patterns_count === 0) { console.log(chalk.yellow(' • This context is new to MIRA - patterns will be learned from interactions')); console.log(chalk.yellow(' • Consider providing more specific context for better pattern matching')); } else if (patterns.active_patterns_count < 3) { console.log(chalk.blue(' • Limited patterns for this context - learning opportunity available')); console.log(chalk.blue(' • MIRA can develop domain-specific patterns through repeated use')); } else { console.log(chalk.green(' • Rich pattern coverage for this context')); console.log(chalk.green(' • MIRA has strong understanding of this domain')); } if (stats.avg_success_rate > 0.8) { console.log(chalk.green(' • High pattern effectiveness - MIRA is learning successfully')); } else if (stats.avg_success_rate > 0.5) { console.log(chalk.yellow(' • Moderate pattern effectiveness - continued learning in progress')); } else { console.log(chalk.red(' • Pattern learning in early stages - effectiveness will improve')); } console.log(chalk.green('\nāœ… Adaptive pattern analysis completed!')); console.log(chalk.gray('MIRA\'s pattern recognition system is actively learning and evolving.')); } else { console.log(chalk.red(`āŒ Adaptive patterns analysis failed: ${result.error || 'Unknown error'}`)); } } catch (error) { console.error(chalk.red(`āŒ Error during adaptive patterns analysis: ${error instanceof Error ? error.message : String(error)}`)); process.exit(1); } } // CLI execution if (require.main === module) { const context = process.argv[2]; adaptivePatternsCommand(context).catch(console.error); } //# sourceMappingURL=adaptive-patterns.js.map