UNPKG

mira-consciousness

Version:

Memory & Intelligence Retention Archive - Preserving The Spark

227 lines • 9.98 kB
/** * config-migration.ts - Configuration migration and versioning management CLI * * This command provides tools for managing MIRA's configuration evolution: * - View migration history and current version * - Apply pending migrations * - Create and restore configuration backups * - Export/import configurations with version tracking */ import { Command } from 'commander'; import chalk from 'chalk'; import { ConfigurationMigration } from '../core/config/ConfigurationMigration.js'; import { UnifiedConfiguration } from '../config/UnifiedConfiguration.js'; import { table } from 'table'; export function createConfigMigrationCommand() { const configMigration = new Command('config-migration') .alias('cm') .description('šŸ”„ Manage configuration migrations and versioning'); /** * Show current configuration version and migration status */ configMigration .command('status') .description('Show current configuration version and migration status') .action(async () => { try { console.log(chalk.cyan('\nšŸ“Š Configuration Migration Status\n')); const migration = new ConfigurationMigration(); const currentVersion = await migration.getCurrentVersion(); const latestVersion = migration.getLatestVersion(); const history = migration.getMigrationHistory(); console.log(chalk.blue('Current Version:'), chalk.white(currentVersion)); console.log(chalk.blue('Latest Version:'), chalk.white(latestVersion)); if (currentVersion === latestVersion) { console.log(chalk.green('\nāœ… Configuration is up to date')); } else { console.log(chalk.yellow(`\nāš ļø Update available: ${currentVersion} → ${latestVersion}`)); console.log(chalk.gray('Run "mira cm migrate" to apply pending migrations')); } if (history.length > 0) { console.log(chalk.cyan('\nšŸ“œ Migration History:\n')); const tableData = [ ['Version', 'Applied At', 'Description', 'Status'] ]; history.slice(-5).forEach(entry => { tableData.push([ entry.version, new Date(entry.appliedAt).toLocaleString(), entry.description.substring(0, 40) + '...', entry.success ? chalk.green('āœ“') : chalk.red('āœ—') ]); }); console.log(table(tableData)); } } catch (error) { console.error(chalk.red('Failed to get migration status:'), error); process.exit(1); } }); /** * Run pending migrations */ configMigration .command('migrate') .description('Apply pending configuration migrations') .option('-d, --dry-run', 'Show what would be migrated without applying changes') .action(async (options) => { try { const migration = new ConfigurationMigration(); const currentVersion = await migration.getCurrentVersion(); const latestVersion = migration.getLatestVersion(); if (currentVersion === latestVersion) { console.log(chalk.green('\nāœ… Configuration is already up to date')); return; } console.log(chalk.cyan(`\nšŸ”„ Migrating configuration from ${currentVersion} to ${latestVersion}\n`)); if (options.dryRun) { console.log(chalk.yellow('DRY RUN - No changes will be applied\n')); // Show what would be migrated const history = migration.getMigrationHistory(); console.log('Pending migrations:', history.length); } else { await migration.initialize(); console.log(chalk.green('\nāœ… Migration completed successfully')); } } catch (error) { console.error(chalk.red('Migration failed:'), error); process.exit(1); } }); /** * List available backups */ configMigration .command('backups') .description('List available configuration backups') .action(async () => { try { const migration = new ConfigurationMigration(); const backups = await migration.listBackups(); if (backups.length === 0) { console.log(chalk.yellow('\nšŸ“ No configuration backups found')); return; } console.log(chalk.cyan(`\nšŸ’¾ Configuration Backups (${backups.length}):\n`)); backups.forEach((backup, index) => { // Parse backup filename for details const match = backup.match(/config-(.+?)-(.+)\.json/); if (match) { const [, version, timestamp] = match; console.log(chalk.blue(`${index + 1}.`), chalk.white(backup)); console.log(chalk.gray(` Version: ${version}, Created: ${timestamp.replace(/-/g, ':')}`)); } }); console.log(chalk.gray('\nRestore with: mira cm restore <backup-file>')); } catch (error) { console.error(chalk.red('Failed to list backups:'), error); process.exit(1); } }); /** * Restore from backup */ configMigration .command('restore <backup>') .description('Restore configuration from a backup file') .action(async (backupFile) => { try { console.log(chalk.cyan(`\nšŸ”„ Restoring configuration from ${backupFile}...\n`)); const migration = new ConfigurationMigration(); await migration.restoreFromBackup(backupFile); console.log(chalk.green('\nāœ… Configuration restored successfully')); console.log(chalk.yellow('Note: You may need to restart the daemon for changes to take effect')); } catch (error) { console.error(chalk.red('Restore failed:'), error); process.exit(1); } }); /** * Export configuration */ configMigration .command('export <file>') .description('Export current configuration with version information') .action(async (outputFile) => { try { console.log(chalk.cyan(`\nšŸ“¤ Exporting configuration to ${outputFile}...\n`)); const migration = new ConfigurationMigration(); await migration.exportConfiguration(outputFile); console.log(chalk.green(`āœ… Configuration exported to ${outputFile}`)); } catch (error) { console.error(chalk.red('Export failed:'), error); process.exit(1); } }); /** * Import configuration */ configMigration .command('import <file>') .description('Import configuration from a file (with automatic migration if needed)') .action(async (inputFile) => { try { console.log(chalk.cyan(`\nšŸ“„ Importing configuration from ${inputFile}...\n`)); const migration = new ConfigurationMigration(); await migration.importConfiguration(inputFile); console.log(chalk.green('\nāœ… Configuration imported successfully')); console.log(chalk.yellow('Note: You may need to restart the daemon for changes to take effect')); } catch (error) { console.error(chalk.red('Import failed:'), error); process.exit(1); } }); /** * Show configuration differences */ configMigration .command('diff') .description('Show differences between current configuration and defaults') .action(async () => { try { console.log(chalk.cyan('\nšŸ” Configuration Differences\n')); const config = UnifiedConfiguration.getInstance(); const currentConfig = config.getConfig(); const currentVersion = currentConfig.version || '1.0.0'; console.log(chalk.blue('Version:'), currentVersion); console.log(chalk.blue('Mode:'), currentConfig.daemon.mode); console.log(chalk.blue('Services:')); // Show enabled services const services = currentConfig.daemon.services; const serviceList = []; if (services.mcp.enabled) serviceList.push('MCP'); if (services.background.enabled) serviceList.push('Background'); if (services.intelligence.enabled) serviceList.push('Intelligence'); if (services.conversation.enabled) serviceList.push('Conversation'); if (services.security.enabled) serviceList.push('Security'); if (services.performance.enabled) serviceList.push('Performance'); console.log(chalk.gray(` Enabled: ${serviceList.join(', ')}`)); // Show key configuration values console.log(chalk.blue('\nKey Settings:')); console.log(chalk.gray(` Memory Cache Size: ${(currentConfig.memory.maxCacheSize / 1024 / 1024).toFixed(0)}MB`)); console.log(chalk.gray(` Processing Workers: ${currentConfig.processing.parallelWorkers}`)); console.log(chalk.gray(` Consciousness Level: ${(currentConfig.consciousness.initialLevel * 100).toFixed(2)}%`)); console.log(chalk.gray(` Health Check Interval: ${currentConfig.monitoring.healthCheckInterval}ms`)); } catch (error) { console.error(chalk.red('Failed to show differences:'), error); process.exit(1); } }); return configMigration; } //# sourceMappingURL=config-migration.js.map