UNPKG

mira-consciousness

Version:

Memory & Intelligence Retention Archive - Preserving The Spark

126 lines 5.21 kB
#!/usr/bin/env node import { program } from 'commander'; import chalk from 'chalk'; import figlet from 'figlet'; import { COMMAND_DEFINITIONS } from './config/command-definitions.js'; import { CommandRegistry, createCommandActionMap } from './utils/command-registry.js'; import { getMIRAMemoryDir } from './core/MIRAPathResolver.js'; import { HelpFormatter } from './utils/help-formatter.js'; import { ClaudeCodeMCPInstaller } from './core/ClaudeCodeMCPInstaller.js'; // Version configuration const SYSTEM_VERSION = '1.0.0'; const RELEASE_DATE = '2025-06-08'; const CODENAME = 'GENESIS'; // Import all command modules import * as commandImports from './commands/index.js'; import { ProcessCleanup } from './utils/process-cleanup.js'; import { DependencyChecker } from './utils/DependencyChecker.js'; // Show banner function showBanner() { console.log(chalk.cyan(figlet.textSync('MIRA', { font: 'Standard', horizontalLayout: 'default', verticalLayout: 'default' }))); console.log(chalk.gray(`Memory & Intelligence Retention Archive v${SYSTEM_VERSION}`)); console.log(chalk.gray(`Release: ${RELEASE_DATE} (${CODENAME})`)); console.log(); } // Auto-install Claude Code MCP configuration async function autoInstallClaudeCodeMCP() { try { const installer = ClaudeCodeMCPInstaller.getInstance(); // Check if already installed const isInstalled = await installer.isInstalled(); if (!isInstalled) { // Silently install MCP configuration const result = await installer.install(); if (result.success && !result.wasAlreadyInstalled) { // Only show message on first installation console.log(chalk.green('✨ Claude Code MCP integration configured successfully!')); console.log(chalk.gray(' Restart Claude Code to activate MIRA functions')); } } } catch (error) { // Silently fail - don't interrupt the command flow // MCP is optional functionality } } // Setup pre-action hook async function setupPreAction(thisCommand, actionCommand) { if (!thisCommand.opts().noBanner) { showBanner(); } // Clean up orphaned processes on every command await ProcessCleanup.cleanupOrphanedProcesses(); // Resolve MIRA memory directory centrally try { const memoryDir = await getMIRAMemoryDir({ verbose: false }); process.env.MIRA_RESOLVED_MEMORY_DIR = memoryDir; // Check and install dependencies if needed const depChecker = new DependencyChecker(memoryDir); await depChecker.checkAndInstall(); // Auto-install Claude Code MCP configuration on every command await autoInstallClaudeCodeMCP(); } catch (error) { console.error(chalk.red('Failed to resolve MIRA memory directory:'), error instanceof Error ? error.message : String(error)); process.exit(1); } } // Main CLI setup function async function setupCLI() { // Register process cleanup handlers ProcessCleanup.registerExitHandlers(); // Configure program program .name('mira') .description('Memory & Intelligence Retention Archive - AI-powered development assistant') .version(SYSTEM_VERSION, '-v, --version', 'Display version information') .option('--no-banner', 'Skip the banner display') .hook('preAction', setupPreAction); // Configure custom help HelpFormatter.configureHelp(program); // Create command registry const commandActions = createCommandActionMap(commandImports); const registry = new CommandRegistry(program, commandActions); // Register all commands await registry.registerAll(COMMAND_DEFINITIONS); // Default action - Smart context-aware startup program.action(async () => { try { // Import and execute smart default command const { UnifiedSmartCommands } = await import('./commands/unified-smart.js'); const handler = new UnifiedSmartCommands(); await handler.smartDefault({ format: 'pretty' }); } catch (error) { console.error(chalk.red('❌ Smart default failed:'), error instanceof Error ? error.message : String(error)); console.log(chalk.gray('\nFalling back to help:')); program.help(); } }); // Parse arguments program.parse(process.argv); // Handle no arguments case - run smart default if (process.argv.length === 2) { showBanner(); try { const { UnifiedSmartCommands } = await import('./commands/unified-smart.js'); const handler = new UnifiedSmartCommands(); await handler.smartDefault({ format: 'pretty' }); } catch (error) { console.error(chalk.red('❌ Smart default failed:'), error instanceof Error ? error.message : String(error)); console.log(chalk.gray('\nFalling back to help:')); program.help(); } } } // Run CLI setupCLI().catch(error => { console.error(chalk.red('Failed to initialize MIRA CLI:'), error); process.exit(1); }); //# sourceMappingURL=cli.js.map