UNPKG

claude-code-company

Version:

Multi-agent tmux coordination system for Claude Code with perfect Unicode support

165 lines (136 loc) 5.93 kB
#!/usr/bin/env node const { colors } = require('./lib/config'); const { setupSystem } = require('./lib/setup'); const { chainCommand, destroyPanes } = require('./lib/tasks'); const { interactiveMenu, cleanupRl } = require('./lib/menu'); // ASCIIアートバナー表示 function showBanner() { console.log(`${colors.brightCyan}${colors.bold}CLAUDE CODE COMPANY${colors.nc}`); console.log(`${colors.brightYellow}⚡ 超軽量エージェント通信システム - たった5つのコマンドで完結 ⚡${colors.nc}\n`); } // ヘルプ表示 function showHelp() { showBanner(); console.log(`${colors.brightYellow}📋 基本機能${colors.nc}`); console.log(`${colors.cyan} 📦 setup ${colors.dim}${colors.nc} tmuxセッション初期化`); console.log(`${colors.cyan} 📤 send <target> "<message>" ${colors.dim}${colors.nc} 指示・報告送信`); console.log(`${colors.cyan} 🗑️ destroy ${colors.dim}${colors.nc} pane 0以外を削除`); console.log(`${colors.cyan} ❓ help ${colors.dim}${colors.nc} このヘルプ表示`); console.log(`\n${colors.brightYellow}🏛️ 階層システム${colors.nc}`); console.log(`${colors.lime} President → Boss → Workers の階層構造${colors.nc}`); console.log(`${colors.orange} 例: send boss1 "指示" → send workers "分散" → send president "報告"${colors.nc}\n`); console.log(`${colors.blue} 🔗 送信先例: president, boss1, workers, worker1, worker2, worker3${colors.nc}\n`); } // メイン処理 async function main() { const args = process.argv.slice(2); if (args.length > 0) { try { switch (args[0]) { case 'setup': const workerCount = args[1] ? parseInt(args[1]) : 3; const bossCount = args[2] ? parseInt(args[2]) : 1; const projectBranch = args[3] || null; if (isNaN(workerCount) || workerCount < 1 || workerCount > 15) { console.log(`${colors.red}❌ Worker数は1-15で指定してください${colors.nc}`); process.exit(1); } if (isNaN(bossCount) || bossCount < 1 || bossCount > 5) { console.log(`${colors.red}❌ Boss数は1-5で指定してください${colors.nc}`); process.exit(1); } await setupSystem(workerCount, projectBranch, bossCount); break; case 'send': let target, message; if (args.length < 2) { console.log(`${colors.red}❌ Usage: npx claude-code-company@latest send [target] "<message>"${colors.nc}`); console.log(`${colors.blue}💡 例: send "最終報告" (デフォルト: president)${colors.nc}`); console.log(`${colors.blue}💡 例: send president "最終報告"${colors.nc}`); console.log(`${colors.blue}💡 例: send boss1 "新機能を実装"${colors.nc}`); console.log(`${colors.blue}💡 例: send workers "タスク分散"${colors.nc}`); console.log(`${colors.blue}💡 例: send worker1 "完了報告"${colors.nc}`); process.exit(1); } else if (args.length === 2) { // 送信先が省略された場合はpresidentをデフォルトとする target = 'president'; message = args[1]; console.log(`${colors.blue}📋 送信先未指定のため、デフォルトでpresidentに送信します${colors.nc}`); } else { // 通常の送信先指定あり target = args[1]; message = args.slice(2).join(' '); } await chainCommand(target, message); break; case 'destroy': await destroyPanes(); console.log(`${colors.green}✅ pane 0以外を削除しました${colors.nc}`); break; case 'help': case '--help': case '-h': showHelp(); break; case 'version': case '--version': case '-v': const pkg = require('./package.json'); console.log(pkg.version); break; default: console.log(`${colors.red}❌ Unknown command: ${args[0]}${colors.nc}`); console.log(`${colors.blue}💡 Use 'npx claude-code-company@latest help' for usage information${colors.nc}`); process.exit(1); } } catch (e) { console.log(`${colors.red}${e.message}${colors.nc}`); process.exit(1); } } else { await interactiveMenu(); } cleanupRl(); } // 終了処理 process.on('SIGINT', () => { console.log(`\n${colors.green}👋 Goodbye!${colors.nc}`); gracefulShutdown(); }); process.on('SIGTERM', () => { console.log(`\n${colors.yellow}⚠️ Received SIGTERM, shutting down gracefully...${colors.nc}`); gracefulShutdown(); }); process.on('exit', (code) => { if (code !== 0) { console.error(`${colors.red}❌ Process exiting with code ${code}${colors.nc}`); } cleanupRl(); }); process.on('uncaughtException', (error) => { console.error(`${colors.red}❌ Uncaught Exception: ${error.message}${colors.nc}`); console.error(error.stack); gracefulShutdown(1); }); process.on('unhandledRejection', (reason, promise) => { console.error(`${colors.red}❌ Unhandled Rejection at: ${promise}, reason: ${reason}${colors.nc}`); gracefulShutdown(1); }); // Graceful shutdown handler function gracefulShutdown(exitCode = 0) { try { cleanupRl(); process.exit(exitCode); } catch (error) { console.error(`${colors.red}❌ Error during shutdown: ${error.message}${colors.nc}`); process.exit(1); } } // 実行 main().catch(e => { console.error(`${colors.red}❌ Fatal error: ${e.message}${colors.nc}`); if (e.stack) { console.error(`Stack trace: ${e.stack}`); } gracefulShutdown(1); });