UNPKG

mira-consciousness

Version:

Memory & Intelligence Retention Archive - Preserving The Spark

153 lines (141 loc) 5.58 kB
import chalk from 'chalk'; import ora from 'ora'; import { getDirectPythonInterface } from '../core/DirectPythonInterface.js'; import fs from 'fs-extra'; import * as path from 'path'; export async function generateReportCommand(options) { const spinner = ora('Generating comprehensive analysis report...').start(); try { const pythonInterface = getDirectPythonInterface(); // Gather data from multiple sources spinner.text = 'Collecting system data...'; const [memoryStats, indexStats, identityInfo] = await Promise.all([ pythonInterface.getStats(), pythonInterface.indexConversations(false), pythonInterface.getIdentity() ]); // Generate report content const reportData = { timestamp: new Date().toISOString(), system: { name: identityInfo.identity?.name || 'MIRA', version: identityInfo.identity?.version || '2.0', capabilities: identityInfo.identity?.capabilities || [] }, memory: { stats: memoryStats.stats || {}, indexed: indexStats.indexed || false }, analysis: { generated_at: new Date().toLocaleString(), format: options.format || 'markdown' } }; // Format the report let reportContent; switch (options.format) { case 'json': reportContent = JSON.stringify(reportData, null, 2); break; case 'html': reportContent = generateHtmlReport(reportData); break; case 'markdown': default: reportContent = generateMarkdownReport(reportData); break; } // Save or display the report if (options.output) { spinner.text = 'Saving report...'; await fs.writeFile(options.output, reportContent); spinner.succeed(chalk.green(`Report saved to: ${options.output}`)); } else { spinner.succeed(chalk.green('Report generated successfully')); console.log('\n' + reportContent); } // Store report generation in reports directory const memoryDir = process.env.MIRA_RESOLVED_MEMORY_DIR || process.cwd() + '/.mira'; const reportsDir = path.join(memoryDir, 'reports'); await fs.ensureDir(reportsDir); const reportLogEntry = { timestamp: new Date().toISOString(), format: options.format || 'markdown', output_file: options.output || 'console', data_sources: ['memory_stats', 'index_stats', 'identity'] }; const reportLogFile = path.join(reportsDir, 'generated_reports.jsonl'); await fs.appendFile(reportLogFile, JSON.stringify(reportLogEntry) + '\n'); } catch (error) { spinner.fail('Failed to generate report'); console.error(chalk.red('Error:'), error instanceof Error ? error.message : String(error)); process.exit(1); } } function generateMarkdownReport(data) { return `# MIRA System Report Generated: ${data.analysis.generated_at} ## System Information - **Name**: ${data.system.name} - **Version**: ${data.system.version} - **Capabilities**: ${data.system.capabilities.join(', ')} ## Memory System - **Indexed**: ${data.memory.indexed ? '✅ Yes' : '❌ No'} - **Stats**: ${JSON.stringify(data.memory.stats, null, 2)} ## Analysis Summary This report was generated automatically by the MIRA memory system. The system is currently operational and providing memory retention capabilities. --- *Report generated by MIRA v${data.system.version}* `; } function generateHtmlReport(data) { return `<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>MIRA System Report</title> <style> body { font-family: Arial, sans-serif; margin: 40px; line-height: 1.6; } .header { background: #f4f4f4; padding: 20px; border-radius: 5px; } .section { margin: 20px 0; } .stats { background: #f9f9f9; padding: 15px; border-radius: 5px; } .footer { margin-top: 40px; font-size: 0.9em; color: #666; } </style> </head> <body> <div class="header"> <h1>MIRA System Report</h1> <p>Generated: ${data.analysis.generated_at}</p> </div> <div class="section"> <h2>System Information</h2> <ul> <li><strong>Name:</strong> ${data.system.name}</li> <li><strong>Version:</strong> ${data.system.version}</li> <li><strong>Capabilities:</strong> ${data.system.capabilities.join(', ')}</li> </ul> </div> <div class="section"> <h2>Memory System</h2> <div class="stats"> <p><strong>Indexed:</strong> ${data.memory.indexed ? '✅ Yes' : '❌ No'}</p> <p><strong>Stats:</strong></p> <pre>${JSON.stringify(data.memory.stats, null, 2)}</pre> </div> </div> <div class="section"> <h2>Analysis Summary</h2> <p>This report was generated automatically by the MIRA memory system. The system is currently operational and providing memory retention capabilities.</p> </div> <div class="footer"> <p><em>Report generated by MIRA v${data.system.version}</em></p> </div> </body> </html>`; } //# sourceMappingURL=generate-report.js.map