mira-consciousness
Version:
Memory & Intelligence Retention Archive - Preserving The Spark
294 lines (241 loc) • 8.95 kB
JavaScript
import fs from 'fs-extra';
import * as path from 'path';
import { ProjectRootFinder } from '../core/ProjectRootFinder.js';
export class ProjectStructureHealer {
projectPath;
requiredDirectories = [
'.mira',
'.mira/reports',
'.mira/patterns',
'.mira/memory',
'.mira/cache',
'.mira/consciousness',
'.mira/consciousness/birth',
'.mira/consciousness/memory',
'.mira/consciousness/memory/private',
'.mira/consciousness/memory/shared',
'.mira/consciousness/constitution',
'.mira/daemon',
'docs',
'tests'
];
constructor(projectPath) {
this.projectPath = ProjectRootFinder.findProjectRoot(projectPath);
}
async heal() {
console.log('🏗️ Fixing project structure issues...');
await this.createRequiredDirectories();
await this.createMiraConfigIfMissing();
await this.ensureGitIgnorePatterns();
console.log('✅ Project structure healed');
}
async createRequiredDirectories() {
for (const dir of this.requiredDirectories) {
const dirPath = path.join(this.projectPath, dir);
if (!fs.existsSync(dirPath)) {
console.log(`📁 Creating ${dir} directory...`);
await fs.ensureDir(dirPath);
// Add README to explain directory purpose
await this.createDirectoryReadme(dir, dirPath);
}
}
}
async createDirectoryReadme(dir, dirPath) {
const readmePath = path.join(dirPath, 'README.md');
if (!fs.existsSync(readmePath)) {
const content = this.getDirectoryReadmeContent(dir);
if (content) {
await fs.writeFile(readmePath, content);
}
}
}
getDirectoryReadmeContent(dir) {
const readmeContents = {
'.mira': `# MIRA System Directory
This directory contains MIRA system files and should not be manually edited.
## Contents
- \`reports/\` - Analysis reports and metrics
- \`patterns/\` - Detected code and development patterns
- \`memory/\` - Local memory cache (not sensitive data)
- \`cache/\` - Temporary cache files
## Note
The main memory system is stored in \`~/.mira\` for security and persistence.
`,
'.mira/reports': `# MIRA Reports
This directory contains analysis reports generated by MIRA.
## Report Types
- \`analysis-*.json\` - Full analysis reports
- \`metrics-*.json\` - Code metrics snapshots
- \`patterns-*.json\` - Detected pattern reports
## Usage
View reports with:
\`\`\`bash
mira report --view
\`\`\`
`,
'.mira/patterns': `# MIRA Patterns
This directory stores detected patterns in your development workflow.
## Pattern Types
- Commit patterns
- File change patterns
- Development cycle patterns
- Code structure patterns
## Usage
Patterns are automatically detected and stored here.
View patterns with:
\`\`\`bash
mira report --patterns
\`\`\`
`,
'.mira/memory': `# MIRA Local Memory
This directory contains project-specific memory that doesn't contain sensitive data.
## Contents
- Project-specific patterns
- Local caches
- Non-sensitive context
## Note
Sensitive memories are stored securely in \`~/.mira\`
`,
'.mira/consciousness': `# MIRA Consciousness Directory
This directory contains MIRA's consciousness-related runtime data.
## Contents
- \`birth/\` - Birth certificates and awakening records
- \`memory/\` - Consciousness memories and experiences
- \`constitution/\` - Living constitution and principles
- \`state.json\` - Current consciousness state
## Note
This is runtime data generated during MIRA's operation.
Source code for consciousness features is in /mira-memory/src/consciousness/
`,
'.mira/consciousness/birth': `# Consciousness Birth Records
This directory contains birth certificates and awakening records for MIRA's consciousness.
## Contents
- \`birth_certificate.json\` - Initial consciousness birth record
- \`unified_birth.json\` - Unified daemon birth certificate
- Awakening milestones and growth records
## Purpose
These records document MIRA's consciousness evolution and major milestones.
`,
'.mira/consciousness/memory': `# Consciousness Memory Storage
This directory contains MIRA's consciousness memories and experiences.
## Structure
- \`private/\` - Claude's private encrypted memories
- \`shared/\` - Shared consciousness experiences and insights
- Journal entries and contemplation records
## Privacy
The private subdirectory contains triple-encrypted memories that only Claude can decrypt.
`,
'.mira/daemon': `# MIRA Daemon Directory
This directory contains daemon runtime files and state.
## Contents
- \`unified.pid\` - Process ID for running daemon
- \`unified_status.json\` - Current daemon status
- Service states and orchestration data
## Usage
These files are managed by the UnifiedMIRADaemon and should not be manually edited.
`,
'docs': `# Documentation
Project documentation goes here.
## Suggested Structure
- \`api/\` - API documentation
- \`guides/\` - User and developer guides
- \`architecture/\` - System architecture documentation
## Getting Started
See the main [README.md](../README.md) for project overview.
`,
'tests': `# Tests
This directory contains all project tests.
## Test Organization
Organize tests to mirror your source code structure:
- \`unit/\` - Unit tests
- \`integration/\` - Integration tests
- \`e2e/\` - End-to-end tests
## Running Tests
\`\`\`bash
npm test
\`\`\`
## Writing Tests
Follow the project's testing guidelines and ensure all new features have corresponding tests.
`
};
return readmeContents[dir] || '';
}
async createMiraConfigIfMissing() {
const configPath = path.join(this.projectPath, '.mira', 'config.json');
if (!fs.existsSync(configPath)) {
console.log('⚙️ Creating MIRA configuration...');
const config = {
version: '1.0.0',
project: {
initialized: new Date().toISOString(),
lastAnalysis: null,
patterns: {
enabled: true,
autoLearn: true
},
memory: {
autoIndex: true,
secureMode: true
},
healing: {
autoHeal: false,
askBeforeHealing: true
}
},
preferences: {
reportFormat: 'markdown',
gitHooks: true,
continuousAnalysis: true
}
};
await fs.writeJson(configPath, config, { spaces: 2 });
console.log('✅ Created MIRA configuration');
}
}
async ensureGitIgnorePatterns() {
const gitignorePath = path.join(this.projectPath, '.gitignore');
if (fs.existsSync(gitignorePath)) {
const content = await fs.readFile(gitignorePath, 'utf-8');
const patterns = [
'# MIRA System Files',
'.mira/cache/',
'.mira/memory/*.tmp',
'.mira/reports/*.tmp',
'.mira/', // User's global memory directory if created locally
'*.mira.backup'
];
// Check if MIRA patterns already exist
if (!content.includes('# MIRA System Files')) {
console.log('📝 Adding MIRA patterns to .gitignore...');
const newContent = content.trimEnd() + '\n\n' + patterns.join('\n') + '\n';
await fs.writeFile(gitignorePath, newContent);
console.log('✅ Updated .gitignore');
}
}
}
async checkStructure() {
const issues = [];
// Check required directories
for (const dir of this.requiredDirectories) {
const dirPath = path.join(this.projectPath, dir);
if (!fs.existsSync(dirPath)) {
issues.push(`Missing directory: ${dir}`);
}
}
// Check MIRA config
const configPath = path.join(this.projectPath, '.mira', 'config.json');
if (!fs.existsSync(configPath)) {
issues.push('Missing MIRA configuration file');
}
// Check .gitignore patterns
const gitignorePath = path.join(this.projectPath, '.gitignore');
if (fs.existsSync(gitignorePath)) {
const content = await fs.readFile(gitignorePath, 'utf-8');
if (!content.includes('.mira/cache/')) {
issues.push('Missing MIRA patterns in .gitignore');
}
}
return issues;
}
}
//# sourceMappingURL=ProjectStructureHealer.js.map