import { Command } from 'commander'; import chalk from 'chalk'; import ora from 'ora'; import { getApiKey, getProjectId, getApiUrl } from '../utils/config.js'; import { loadManifest } from '../utils/manifest.js'; import { detectCurrentIDE, autoRegisterMCP } from '../utils/ide.js'; import { verifySovereignty, displayPreFlightReport } from '../utils/sovereignty.js'; import { enableDaemon, isDaemonRunning } from '../utils/service-manager.js'; export function createBootCommand() { return new Command('boot') .description('šŸš€ The ultimate takeoff command. Orchestrates Auth, Sync, Rules, Daemon and Monitor.') .option('--skip-check', 'Skip sovereign pre-flight check') .option('--no-mcp', 'Skip MCP auto-registration') .action(async (options) => { console.log(chalk.bold.hex('#6366f1')('\n🌌 Rigstate Taking Off...\n')); const spinner = ora(); try { // 1. Identity Check let apiKey: string; try { apiKey = getApiKey(); console.log(`${chalk.green('āœ”')} Identity verified.`); } catch (e) { console.log(`${chalk.yellow('⚠')} Identity missing. Starting login flow...`); // In a real CLI we would call the login command here console.log(chalk.dim(' (Run "rigstate login" to authenticate)')); return; } const apiUrl = getApiUrl(); let projectId = getProjectId(); // 2. Project Context const manifest = await loadManifest(); if (manifest?.project_id) { projectId = manifest.project_id; } if (!projectId) { console.log(`${chalk.yellow('⚠')} No project linked. Starting initialization...`); // In a real CLI we would trigger 'init' console.log(chalk.dim(' (Run "rigstate init" to link a project)')); return; } // 3. Sovereign Pre-flight Check if (!options.skipCheck) { const report = await verifySovereignty(apiUrl, apiKey, projectId); displayPreFlightReport(report); if (!report.hasSecrets || !report.isRepo) { console.log(chalk.red('šŸ›‘ Flight aborted. Environment is not Sovereign-ready.')); console.log(chalk.dim(' Fix the issues above and try again.')); return; } } // 4. Sync Context & Rules spinner.start('Synchronizing Intelligence & Rules...'); const { syncNexus, checkArchitectureDrift } = await import('../utils/nexus.js'); // Simulate sync results or call actual logic if ready await new Promise(resolve => setTimeout(resolve, 500)); spinner.succeed('Intelligence & Rules synchronized.'); // 4b. Nexus Registry Sync & Digital Archive await syncNexus(apiUrl, apiKey, projectId, process.cwd()); await checkArchitectureDrift(apiUrl, apiKey, projectId, process.cwd()); // 5. IDE & MCP Integration if (!options.noMcp) { spinner.start('Integrating with IDE...'); const registered = await autoRegisterMCP(apiUrl, apiKey); if (registered) { spinner.succeed('MCP Server registered with IDE.'); } else { spinner.info('MCP auto-registration skipped (generic IDE or unsupported platform).'); } } // 6. Guardian Daemon const daemonActive = await isDaemonRunning(); if (!daemonActive) { spinner.start('Activating Guardian Daemon...'); await enableDaemon(); spinner.succeed('Guardian Daemon is now watching.'); } else { console.log(`${chalk.green('āœ”')} Guardian Daemon is already active.`); } // 7. Launch Mission Control console.log(chalk.bold.green('\nšŸš€ Takeoff Successful! Entering Mission Control...\n')); // In a real CLI, we would exec 'rigstate monitor' // For now, we'll provide a clear instruction console.log(chalk.cyan(' Run "rigstate monitor" to see Frank in action.')); } catch (error: any) { spinner.fail(chalk.red('Takeoff failed: ' + error.message)); } }); }