mira-consciousness
Version:
Memory & Intelligence Retention Archive - Preserving The Spark
251 lines • 11.4 kB
JavaScript
import { Command } from 'commander';
import chalk from 'chalk';
import ora from 'ora';
import * as path from 'path';
import { getDirectPythonInterface } from '../core/DirectPythonInterface.js';
import { AnalyzerConfigLoader } from '../config/analyzer-config.js';
export function createUnifiedAnalysisCommand() {
return new Command('unified-analysis')
.alias('analyze-unified')
.description('Run unified intelligence analysis on code or issues')
.option('-c, --code <path>', 'Analyze specific code file or directory')
.option('-i, --issue <description>', 'Analyze and solve specific issue')
.option('-p, --pattern', 'Analyze patterns in current project')
.option('-m, --memory', 'Include memory context in analysis')
.option('-d, --deep', 'Perform deep analysis with all subsystems')
.option('--config <path>', 'Path to custom analyzer configuration file')
.action(async (options) => {
const pythonInterface = getDirectPythonInterface();
// Load configuration
let configLoader;
if (options.config) {
configLoader = await AnalyzerConfigLoader.loadFromFile(options.config);
console.log(chalk.gray(`Using custom configuration from: ${options.config}`));
}
else {
// Try to load from default location
const defaultConfigPath = path.join(process.cwd(), '.mira-analyzer-config.json');
configLoader = await AnalyzerConfigLoader.loadFromFile(defaultConfigPath);
}
const config = configLoader.getConfig();
if (!config.enabled) {
console.log(chalk.yellow('⚠️ Analyzers are disabled in configuration'));
return;
}
console.log(chalk.cyan('\n🧠 MIRA Unified Intelligence Analysis\n'));
if (options.code) {
// Code analysis
const spinner = ora('Analyzing code with unified intelligence...').start();
try {
const result = await pythonInterface.runUnifiedAnalysis(options.code);
spinner.stop();
if (result.success && result.data) {
displayCodeAnalysis(result.data);
}
else {
throw new Error(result.error || 'Analysis failed');
}
}
catch (error) {
spinner.fail('Code analysis failed');
console.error(chalk.red(`Error: ${error instanceof Error ? error.message : String(error)}`));
process.exit(1);
}
}
else if (options.issue) {
// Issue analysis
const spinner = ora('Analyzing issue with unified intelligence...').start();
try {
const result = await pythonInterface.runUnifiedAnalysis(options.issue);
spinner.stop();
if (result.success && result.data) {
displayIssueAnalysis(result.data);
}
else {
throw new Error(result.error || 'Analysis failed');
}
}
catch (error) {
spinner.fail('Issue analysis failed');
console.error(chalk.red(`Error: ${error instanceof Error ? error.message : String(error)}`));
process.exit(1);
}
}
else if (options.pattern) {
// Pattern analysis
const spinner = ora('Analyzing project patterns...').start();
try {
const result = await pythonInterface.runUnifiedAnalysis('patterns');
spinner.stop();
if (result.success && result.data) {
displayPatternAnalysis(result.data);
}
else {
throw new Error(result.error || 'Analysis failed');
}
}
catch (error) {
spinner.fail('Pattern analysis failed');
console.error(chalk.red(`Error: ${error instanceof Error ? error.message : String(error)}`));
process.exit(1);
}
}
else {
// General project analysis
const spinner = ora('Running unified project analysis...').start();
try {
const result = await pythonInterface.runUnifiedAnalysis('general');
spinner.stop();
if (result.success && result.data) {
displayGeneralAnalysis(result.data);
}
else {
throw new Error(result.error || 'Analysis failed');
}
}
catch (error) {
spinner.fail('Project analysis failed');
console.error(chalk.red(`Error: ${error instanceof Error ? error.message : String(error)}`));
process.exit(1);
}
}
});
}
function displayCodeAnalysis(analysis) {
console.log(chalk.cyan('📊 Code Analysis Results\n'));
if (analysis.summary) {
console.log(chalk.white('Summary:'));
console.log(analysis.summary);
}
if (analysis.quality) {
console.log(chalk.cyan('\n🎯 Code Quality:'));
console.log(chalk.gray(` • Score: ${analysis.quality.score}/10`));
console.log(chalk.gray(` • Complexity: ${analysis.quality.complexity}`));
console.log(chalk.gray(` • Maintainability: ${analysis.quality.maintainability}`));
}
if (analysis.issues && analysis.issues.length > 0) {
console.log(chalk.yellow('\n⚠️ Issues Found:'));
analysis.issues.forEach((issue, index) => {
console.log(chalk.yellow(` ${index + 1}. ${issue.description}`));
if (issue.suggestion) {
console.log(chalk.gray(` 💡 ${issue.suggestion}`));
}
});
}
if (analysis.suggestions && analysis.suggestions.length > 0) {
console.log(chalk.green('\n💡 Suggestions:'));
analysis.suggestions.forEach((suggestion, index) => {
console.log(chalk.green(` ${index + 1}. ${suggestion}`));
});
}
if (analysis.memoryContext && analysis.memoryContext.length > 0) {
console.log(chalk.blue('\n🧠 Related Memory Context:'));
analysis.memoryContext.forEach((memory) => {
console.log(chalk.blue(` • ${memory.summary}`));
});
}
}
function displayIssueAnalysis(analysis) {
console.log(chalk.cyan('🔍 Issue Analysis Results\n'));
if (analysis.understanding) {
console.log(chalk.white('Issue Understanding:'));
console.log(analysis.understanding);
}
if (analysis.rootCause) {
console.log(chalk.yellow('\n🎯 Root Cause:'));
console.log(analysis.rootCause);
}
if (analysis.solutions && analysis.solutions.length > 0) {
console.log(chalk.green('\n💡 Proposed Solutions:'));
analysis.solutions.forEach((solution, index) => {
console.log(chalk.green(`\n${index + 1}. ${solution.title}`));
console.log(chalk.white(` ${solution.description}`));
if (solution.steps && solution.steps.length > 0) {
console.log(chalk.gray(' Steps:'));
solution.steps.forEach((step, stepIndex) => {
console.log(chalk.gray(` ${stepIndex + 1}) ${step}`));
});
}
if (solution.confidence) {
console.log(chalk.gray(` Confidence: ${solution.confidence}%`));
}
});
}
if (analysis.preventionTips && analysis.preventionTips.length > 0) {
console.log(chalk.blue('\n🛡️ Prevention Tips:'));
analysis.preventionTips.forEach((tip, index) => {
console.log(chalk.blue(` ${index + 1}. ${tip}`));
});
}
}
function displayPatternAnalysis(analysis) {
console.log(chalk.cyan('🔮 Pattern Analysis Results\n'));
if (analysis.developmentPatterns && analysis.developmentPatterns.length > 0) {
console.log(chalk.white('Development Patterns:'));
analysis.developmentPatterns.forEach((pattern) => {
console.log(chalk.white(` • ${pattern.name}: ${pattern.description}`));
console.log(chalk.gray(` Frequency: ${pattern.frequency}, Impact: ${pattern.impact}`));
});
}
if (analysis.codePatterns && analysis.codePatterns.length > 0) {
console.log(chalk.yellow('\n📝 Code Patterns:'));
analysis.codePatterns.forEach((pattern) => {
console.log(chalk.yellow(` • ${pattern.name}`));
console.log(chalk.gray(` ${pattern.description}`));
});
}
if (analysis.antiPatterns && analysis.antiPatterns.length > 0) {
console.log(chalk.red('\n❌ Anti-Patterns Detected:'));
analysis.antiPatterns.forEach((pattern) => {
console.log(chalk.red(` • ${pattern.name}`));
console.log(chalk.gray(` ${pattern.description}`));
if (pattern.fix) {
console.log(chalk.green(` 💡 Fix: ${pattern.fix}`));
}
});
}
if (analysis.recommendations && analysis.recommendations.length > 0) {
console.log(chalk.green('\n✨ Recommendations:'));
analysis.recommendations.forEach((rec, index) => {
console.log(chalk.green(` ${index + 1}. ${rec}`));
});
}
}
function displayGeneralAnalysis(analysis) {
console.log(chalk.cyan('🏗️ Project Analysis Overview\n'));
if (analysis.projectHealth) {
const health = analysis.projectHealth;
console.log(chalk.white('Project Health:'));
console.log(chalk.gray(` • Overall Score: ${health.score}/100`));
console.log(chalk.gray(` • Code Quality: ${health.codeQuality}`));
console.log(chalk.gray(` • Test Coverage: ${health.testCoverage || 'Unknown'}`));
console.log(chalk.gray(` • Documentation: ${health.documentation}`));
console.log(chalk.gray(` • Maintainability: ${health.maintainability}`));
}
if (analysis.strengths && analysis.strengths.length > 0) {
console.log(chalk.green('\n💪 Strengths:'));
analysis.strengths.forEach((strength) => {
console.log(chalk.green(` ✓ ${strength}`));
});
}
if (analysis.weaknesses && analysis.weaknesses.length > 0) {
console.log(chalk.yellow('\n⚠️ Areas for Improvement:'));
analysis.weaknesses.forEach((weakness) => {
console.log(chalk.yellow(` • ${weakness}`));
});
}
if (analysis.priorities && analysis.priorities.length > 0) {
console.log(chalk.cyan('\n🎯 Recommended Priorities:'));
analysis.priorities.forEach((priority, index) => {
console.log(chalk.cyan(` ${index + 1}. ${priority.task}`));
console.log(chalk.gray(` Impact: ${priority.impact}, Effort: ${priority.effort}`));
});
}
if (analysis.nextSteps && analysis.nextSteps.length > 0) {
console.log(chalk.white('\n📋 Next Steps:'));
analysis.nextSteps.forEach((step, index) => {
console.log(chalk.white(` ${index + 1}. ${step}`));
});
}
}
//# sourceMappingURL=unified-analysis.js.map