UNPKG

me-engine-one

Version:

The magic file system that regenerates entire AI universes from me.md

277 lines (235 loc) 8.37 kB
#!/usr/bin/env node /** * ME Engine CLI - Command line interface for the magic file system * * Usage: * me generate # Regenerate universe from me.md * me watch # Watch me.md for changes * me validate # Validate me.md file * me sample # Generate sample me.md * me status # Show engine status */ import { fileURLToPath } from 'url'; import { dirname, resolve } from 'path'; import chalk from 'chalk'; import { meEngine } from '../index.js'; const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); // CLI Header function showHeader() { console.log(chalk.magenta(` ╔══════════════════════════════════════════════════════════════════════════════╗ ║ ║ ║ 🌟 ME ENGINE - Magic File System ║ ║ Edit one file → Transform your entire AI universe ║ ║ ║ ╚══════════════════════════════════════════════════════════════════════════════╝ `)); } // Show usage information function showUsage() { console.log(chalk.cyan(` Usage: me <command> [options] Commands: ${chalk.green('generate')} Regenerate entire universe from me.md ${chalk.green('watch')} Watch me.md for changes and auto-regenerate ${chalk.green('validate')} Validate me.md file without regenerating ${chalk.green('sample')} Generate a sample me.md file ${chalk.green('status')} Show ME Engine status ${chalk.green('help')} Show this help message Options: --file <path> Path to me.md file (default: ./me/me.md) --output <path> Output directory (default: current directory) --quiet Suppress progress messages --verbose Show detailed progress information Examples: me generate # Regenerate from ./me/me.md me generate --file /path/to/me.md # Use custom me.md location me watch --file ./my-me.md # Watch custom file me sample --output ./me/ # Generate sample in ./me/ folder me validate # Check if me.md is valid The MySpace Revolution: One file controls everything! 🚀 `)); } // Main CLI function async function main() { const args = process.argv.slice(2); const command = args[0]; // Parse options const options = { file: './me/me.md', output: './', quiet: false, verbose: false }; for (let i = 1; i < args.length; i += 2) { const flag = args[i]; const value = args[i + 1]; switch (flag) { case '--file': options.file = value; break; case '--output': options.output = value; break; case '--quiet': options.quiet = true; i--; // No value for this flag break; case '--verbose': options.verbose = true; i--; // No value for this flag break; } } // Configure logger based on options const logger = { log: options.quiet ? () => {} : console.log, warn: console.warn, error: console.error }; // Configure engine with options meEngine.logger = logger; try { switch (command) { case 'generate': await handleGenerate(options, logger); break; case 'watch': await handleWatch(options, logger); break; case 'validate': await handleValidate(options, logger); break; case 'sample': await handleSample(options, logger); break; case 'status': await handleStatus(options, logger); break; case 'help': case '--help': case '-h': showHeader(); showUsage(); break; default: if (!command) { showHeader(); showUsage(); } else { console.error(chalk.red(`❌ Unknown command: ${command}`)); console.log(chalk.cyan('Run "me help" for usage information')); process.exit(1); } } } catch (error) { console.error(chalk.red(`💥 Error: ${error.message}`)); if (options.verbose) { console.error(error.stack); } process.exit(1); } } // Handle generate command async function handleGenerate(options, logger) { if (!options.quiet) { showHeader(); logger.log(chalk.cyan(`🌟 Generating universe from: ${options.file}`)); } const results = await meEngine.regenerateUniverse(options.file); if (results.success) { logger.log(chalk.green('✨ Universe regenerated successfully!')); if (options.verbose) { logger.log(chalk.gray('Config:'), JSON.stringify(results.config, null, 2)); } } else { logger.error(chalk.red('❌ Regeneration failed:'), results.error); if (results.details) { logger.error(chalk.yellow('Details:'), results.details); } process.exit(1); } } // Handle watch command async function handleWatch(options, logger) { if (!options.quiet) { showHeader(); logger.log(chalk.cyan(`👀 Watching for changes: ${options.file}`)); logger.log(chalk.gray('Press Ctrl+C to stop watching...')); } const watcher = await meEngine.watchMeFile(options.file, (results) => { if (results.success) { logger.log(chalk.green('🔄 Universe updated!')); } else { logger.error(chalk.red('❌ Update failed:'), results.error); } }); // Handle graceful shutdown process.on('SIGINT', () => { logger.log(chalk.yellow('\n👋 Stopping watch mode...')); watcher.close(); process.exit(0); }); // Keep process alive await new Promise(() => {}); } // Handle validate command async function handleValidate(options, logger) { if (!options.quiet) { logger.log(chalk.cyan(`🔍 Validating: ${options.file}`)); } const results = await meEngine.validateMeFile(options.file); if (results.valid) { logger.log(chalk.green('✅ me.md is valid!')); if (options.verbose && results.config) { logger.log(chalk.gray('Parsed config:')); console.log(JSON.stringify(results.config, null, 2)); } } else { logger.error(chalk.red('❌ Validation failed:'), results.error); if (results.details) { logger.error(chalk.yellow('Issues found:')); results.details.forEach((detail, index) => { logger.error(chalk.red(` ${index + 1}. ${detail.path}: ${detail.message}`)); if (detail.suggestion) { logger.log(chalk.cyan(` 💡 ${detail.suggestion}`)); } }); } process.exit(1); } } // Handle sample command async function handleSample(options, logger) { if (!options.quiet) { logger.log(chalk.cyan(`📄 Generating sample me.md in: ${options.output}`)); } const samplePath = resolve(options.output, 'me.md'); const results = await meEngine.generateSampleMeFile(samplePath); logger.log(chalk.green(`✅ Sample generated at: ${results.path}`)); logger.log(chalk.cyan('💡 Edit this file to customize your AI universe!')); if (options.verbose) { logger.log(chalk.gray('\nSample content:')); console.log(results.content); } } // Handle status command async function handleStatus(options, logger) { const status = meEngine.getStatus(); if (!options.quiet) { showHeader(); } logger.log(chalk.green('🟢 ME Engine Status:')); logger.log(chalk.cyan(` Engine: ${status.engine}`)); logger.log(chalk.cyan(` Parser: ${status.parser}`)); logger.log(chalk.cyan(` Regenerator: ${status.regenerator}`)); logger.log(chalk.cyan(` Watch Mode: ${status.watching ? 'active' : 'inactive'}`)); logger.log(chalk.cyan(` Timestamp: ${status.timestamp}`)); logger.log(chalk.magenta('\n✨ Ready to transform your AI universe!')); } // Run CLI main().catch(error => { console.error(chalk.red('💥 CLI Error:'), error.message); process.exit(1); });