(orchestrator: Orchestrator, agentId: string)
| 56 | } |
| 57 | |
| 58 | export async function startRepl(orchestrator: Orchestrator, agentId: string): Promise<void> { |
| 59 | const rl = readline.createInterface({ |
| 60 | input, |
| 61 | output, |
| 62 | terminal: true |
| 63 | }); |
| 64 | |
| 65 | let intentionalClose = false; |
| 66 | |
| 67 | rl.on('close', () => { |
| 68 | if (!intentionalClose) { |
| 69 | console.log(chalk.red('\nReadline closed unexpectedly.')); |
| 70 | console.log(chalk.gray('This usually means stdin is not attached to a live TTY.')); |
| 71 | } |
| 72 | orchestrator.shutdown(); |
| 73 | }); |
| 74 | |
| 75 | process.on('SIGINT', () => { |
| 76 | console.log(chalk.yellow('\nUse "exit" or "quit" to leave the session.')); |
| 77 | }); |
| 78 | |
| 79 | const agent = orchestrator.getAgent(agentId); |
| 80 | const agentName = agent?.config.name || agentId; |
| 81 | const model = agent?.config.model || 'unknown'; |
| 82 | const workspacePath = process.cwd(); |
| 83 | |
| 84 | renderHeader(agentName, model, workspacePath); |
| 85 | |
| 86 | while (true) { |
| 87 | try { |
| 88 | const message = await rl.question(renderPrompt()); |
| 89 | |
| 90 | if (!message.trim()) continue; |
| 91 | |
| 92 | const normalized = message.toLowerCase(); |
| 93 | |
| 94 | if (normalized === 'exit' || normalized === 'quit') { |
| 95 | console.log(chalk.hex('#fbbf24')('\nSession closed.')); |
| 96 | intentionalClose = true; |
| 97 | rl.close(); |
| 98 | return; |
| 99 | } |
| 100 | |
| 101 | if (normalized === 'stats') { |
| 102 | const stats = orchestrator.getStats(); |
| 103 | console.log(); |
| 104 | console.log( |
| 105 | boxen(JSON.stringify(stats, null, 2), { |
| 106 | padding: { top: 0, right: 1, bottom: 0, left: 1 }, |
| 107 | borderStyle: 'round', |
| 108 | borderColor: 'blue' |
| 109 | }) |
| 110 | ); |
| 111 | console.log(); |
| 112 | continue; |
| 113 | } |
| 114 | |
| 115 | if (normalized === 'clear') { |
no test coverage detected