UNPKG

@codemafia0000/d0

Version:

Claude Multi-Agent Automated Development AI - Revolutionary development environment where multiple AI agents collaborate to automate software development

243 lines (196 loc) 8.05 kB
#!/usr/bin/env node const { program } = require('commander'); const chalk = require('chalk'); // Import command handlers const { handleInit, handleStart, handleStop, handleStatus } = require('../src/lib/commands/basic-commands'); const { handleTell, handleCommunication, handleTeam, handleHi } = require('../src/lib/commands/communication-commands'); const { handleAnalyzeProject, handleAutoSetup, handleHistory, handleAnalytics, handleLogMessage, handleLogTask } = require('../src/lib/commands/analysis-commands'); const { handleGenerateInstruction, handleAgents, handleList, handleCompletion, handleMonitor } = require('../src/lib/commands/utility-commands'); const { handleContext } = require('../src/lib/commands/context-commands'); // Import constants const CONSTANTS = require('../src/lib/constants'); // CLI configuration program .name('d0') .description('Claude Agents CLI - Intelligent multi-agent development environment') .version(CONSTANTS.VERSION) .configureHelp({ sortSubcommands: true, subcommandTerm: (cmd) => cmd.name() + ' ' + cmd.usage() }); // ======================================== // SETUP & INITIALIZATION COMMANDS // ======================================== program .command('init') .description('Initialize and setup Claude agents environment in current project') .option('-f, --force', 'Force initialization even if already exists') .option('-w, --workers <number>', `Number of worker agents (${CONSTANTS.MIN_WORKERS}-${CONSTANTS.MAX_WORKERS})`, CONSTANTS.DEFAULT_WORKERS.toString()) .action(handleInit); // ======================================== // SESSION MANAGEMENT COMMANDS // ======================================== program .command('start') .description('Start agent sessions in background') .option('--daemon', 'Run in daemon mode (background)') .action(handleStart); program .command('stop') .description('Stop all agent sessions') .action(handleStop); program .command('status') .description('Show current project and session status') .action(handleStatus); // ======================================== // COMMUNICATION COMMANDS // ======================================== program .command('tell <messageOrRecipient> [messageRest...]') .description('Send message to an agent (defaults to president if no recipient specified)') .option('-f, --file <path>', 'Send message from file') .action(handleTell); program .command('communication') .alias('comm') .description('Check agent communication status and message flow') .option('--clear', 'Clear message notifications') .action(handleCommunication); program .command('hi <session>') .description('Quick connect to an agent session') .action(handleHi); // ======================================== // TEAM & COLLABORATION COMMANDS // ======================================== program .command('team') .description('Check worker team completion status') .option('--status-only', 'Only show status, don\'t send notifications') .option('--reset', 'Reset all completion markers') .option('--workers <n>', 'Number of workers to check (default: from config)') .action(handleTeam); program .command('agents') .description('List all configured agents and their roles') .action(handleAgents); program .command('list') .description('List available agent sessions') .action(handleList); // ======================================== // PROJECT ANALYSIS COMMANDS // ======================================== program .command('analyze-project') .description('Analyze current project structure and suggest optimal agent configuration') .action(handleAnalyzeProject); program .command('auto-setup') .description('Automatically configure agents based on project analysis') .action(handleAutoSetup); // ======================================== // HISTORY & ANALYTICS COMMANDS // ======================================== program .command('history') .description('Show project development history') .option('-t, --type <type>', 'History type: all, messages, tasks, sessions, progress', 'all') .option('-a, --agent <agent>', 'Filter by specific agent') .option('-d, --days <days>', 'Number of days to show', CONSTANTS.DEFAULT_HISTORY_DAYS.toString()) .action(handleHistory); program .command('analytics') .description('Show project analytics and activity metrics') .option('-d, --days <days>', 'Number of days to analyze', CONSTANTS.DEFAULT_ANALYTICS_DAYS.toString()) .action(handleAnalytics); // ======================================== // UTILITY & ADMIN COMMANDS // ======================================== program .command('generate-instruction <role>') .description('Generate custom instruction template for a specific role') .action(handleGenerateInstruction); program .command('completion <shell>') .description('Generate shell completion script') .action(handleCompletion); program .command('monitor') .description('Monitor agent sessions and communication in real-time') .option('--refresh <seconds>', 'Auto-refresh interval in seconds', '2') .action(handleMonitor); program .command('context [agent]') .description('View agent context files') .action(handleContext); // ======================================== // LOGGING COMMANDS (for internal use) // ======================================== program .command('log-message <from> <to> <message>') .description('Log an agent message (internal command)') .action(handleLogMessage); program .command('log-task <action> <agent> <task>') .description('Log a task action (internal command)') .action(handleLogTask); // ======================================== // HELP & INFO CUSTOMIZATION // ======================================== // Add custom help information program.addHelpText('beforeAll', ` ${chalk.blue.bold('d0 Claude Agents CLI')} - ${chalk.gray('Intelligent Multi-Agent Development Environment')} ${chalk.gray('Version')} ${CONSTANTS.VERSION} `); program.addHelpText('afterAll', ` ${chalk.yellow('Quick Start:')} ${chalk.cyan('d0 init')} Initialize project ${chalk.cyan('d0 start')} Start all agents ${chalk.cyan('d0 tell "Build a React app"')} Send task to president ${chalk.yellow('Communication:')} ${chalk.cyan('d0 tell boss "message"')} Direct message to boss ${chalk.cyan('d0 tell everyone "message"')} Broadcast to all agents ${chalk.cyan('d0 comm')} Check message status ${chalk.cyan('d0 team')} Check team progress ${chalk.yellow('Project Management:')} ${chalk.cyan('d0 status')} Show overall status ${chalk.cyan('d0 agents')} List all agents ${chalk.cyan('d0 history')} View development history ${chalk.cyan('d0 analytics')} Show project metrics ${chalk.gray('For more information about a specific command:')} ${chalk.cyan('d0 <command> --help')} ${chalk.gray('Documentation:')} ${chalk.blue('https://docs.anthropic.com/en/docs/claude-code')} `); // ======================================== // ERROR HANDLING & EXECUTION // ======================================== // Handle unknown commands program.on('command:*', function (operands) { console.error(chalk.red(`❌ Unknown command: ${operands[0]}`)); console.log(chalk.yellow('See --help for a list of available commands.')); process.exitCode = 1; }); // Global error handler process.on('uncaughtException', (error) => { console.error(chalk.red('❌ Uncaught Exception:'), error.message); if (process.env.DEBUG) { console.error(error.stack); } process.exit(1); }); process.on('unhandledRejection', (reason, promise) => { console.error(chalk.red('❌ Unhandled Rejection at:'), promise); console.error(chalk.red('Reason:'), reason); if (process.env.DEBUG) { console.error(reason); } process.exit(1); }); // Parse command line arguments program.parse(); // If no command provided, show help if (!process.argv.slice(2).length) { program.outputHelp(); }