mira-consciousness
Version:
Memory & Intelligence Retention Archive - Preserving The Spark
130 lines • 5.99 kB
JavaScript
import fs from 'fs-extra';
import * as path from 'path';
import chalk from 'chalk';
export class ReportGenerator {
projectRoot;
reportsDir;
constructor(projectRoot) {
this.projectRoot = projectRoot;
this.reportsDir = path.join(projectRoot, '.mira', 'reports');
}
async generateReport(result) {
await fs.ensureDir(this.reportsDir);
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
const reportPath = path.join(this.reportsDir, `analysis-${timestamp}.md`);
const report = this.formatMarkdownReport(result);
await fs.writeFile(reportPath, report);
// Also create a latest.md symlink
const latestPath = path.join(this.reportsDir, 'latest.md');
try {
await fs.remove(latestPath);
await fs.symlink(path.basename(reportPath), latestPath);
}
catch (error) {
// Fallback to copy if symlink fails (Windows compatibility)
await fs.copy(reportPath, latestPath);
}
console.log(chalk.gray(`Report saved to: ${path.relative(this.projectRoot, reportPath)}`));
}
formatMarkdownReport(result) {
const report = [];
report.push('# MIRA Analysis Report');
report.push(`Generated: ${new Date().toISOString()}`);
report.push(`Execution Time: ${result.executionTime.toFixed(2)}s`);
report.push('');
// Project Information
if (result.projectInfo) {
report.push('## Project Information');
report.push(`- **Name**: ${result.projectInfo.name}`);
report.push(`- **Type**: ${result.projectInfo.type}`);
report.push(`- **Tech Stack**: ${result.projectInfo.techStack.join(', ')}`);
report.push(`- **Frameworks**: ${result.projectInfo.frameworks.join(', ') || 'None detected'}`);
report.push(`- **Has Tests**: ${result.projectInfo.hasTests ? '✅' : '❌'}`);
report.push(`- **Has CI**: ${result.projectInfo.hasCI ? '✅' : '❌'}`);
report.push(`- **Has Docs**: ${result.projectInfo.hasDocs ? '✅' : '❌'}`);
report.push('');
}
// Metrics
if (result.metrics) {
report.push('## Code Metrics');
report.push(`- **Total Files**: ${result.metrics.fileCount}`);
if (result.metrics.totalLines > 0) {
report.push(`- **Total Lines**: ${result.metrics.totalLines.toLocaleString()}`);
report.push(`- **Code Lines**: ${result.metrics.codeLines.toLocaleString()}`);
report.push(`- **Comment Lines**: ${result.metrics.commentLines.toLocaleString()}`);
report.push(`- **Blank Lines**: ${result.metrics.blankLines.toLocaleString()}`);
}
report.push('');
if (result.metrics.filesByExtension) {
report.push('### Files by Extension');
const sorted = Object.entries(result.metrics.filesByExtension)
.sort(([, a], [, b]) => b - a);
for (const [ext, count] of sorted) {
report.push(`- ${ext}: ${count}`);
}
report.push('');
}
if (result.metrics.largestFiles?.length > 0) {
report.push('### Largest Files');
for (const file of result.metrics.largestFiles) {
report.push(`- ${file.path}: ${file.lines.toLocaleString()} lines`);
}
report.push('');
}
}
// Code Quality
if (result.codeQuality) {
report.push('## Code Quality');
report.push(`- **Score**: ${result.codeQuality.score}/100`);
report.push(`- **Issues Found**: ${result.codeQuality.issues.length}`);
if (result.codeQuality.issues.length > 0) {
report.push('');
report.push('### Top Issues');
const topIssues = result.codeQuality.issues.slice(0, 10);
for (const issue of topIssues) {
const location = issue.line ? `${issue.file}:${issue.line}` : issue.file;
report.push(`- **${issue.severity}**: ${issue.message} (${location})`);
}
}
if (result.codeQuality.suggestions?.length > 0) {
report.push('');
report.push('### Suggestions');
for (const suggestion of result.codeQuality.suggestions) {
report.push(`- ${suggestion}`);
}
}
report.push('');
}
// Security
if (result.security) {
report.push('## Security Analysis');
report.push(`- **Total Issues**: ${result.security.issues}`);
report.push(`- **Critical Issues**: ${result.security.criticalIssues || 0}`);
report.push('');
}
// Performance
if (result.performance) {
report.push('## Performance Analysis');
report.push(`- **Score**: ${result.performance.score}/100`);
report.push('');
}
// Documentation
if (result.documentation) {
report.push('## Documentation Coverage');
report.push(`- **Coverage**: ${result.documentation.coverage}%`);
report.push('');
}
// Dependencies
if (result.dependencies) {
report.push('## Dependencies');
report.push(`- **Total**: ${result.dependencies.totalDependencies}`);
report.push(`- **Outdated**: ${result.dependencies.outdated}`);
report.push(`- **Vulnerabilities**: ${result.dependencies.vulnerabilities}`);
report.push('');
}
report.push('---');
report.push('Generated by MIRA (Memory & Intelligence Retention Archive)');
return report.join('\n');
}
}
//# sourceMappingURL=ReportGenerator.js.map