(config)
| 250 | const improvementAttempts = {}; // filePath → attempt count |
| 251 | |
| 252 | async function runTUI(config) { |
| 253 | const createCommandHandler = require('./commands'); |
| 254 | const handleCmd = createCommandHandler(config, conversationHistory, improvementAttempts, runAgentLoop, runValidation, MAX_IMPROVE_ITERATIONS, memoryStore, escalationEngine, tokenMonitor); |
| 255 | |
| 256 | const ok = await checkOllama(config); |
| 257 | if (!ok && config.model.provider === 'ollama') { |
| 258 | process.exit(1); |
| 259 | } |
| 260 | |
| 261 | // Start built-in code graph MCP |
| 262 | let graphOk = false; |
| 263 | process.stdout.write(chalk.gray(' Code graph: ')); |
| 264 | graphOk = await initCodeGraph(); |
| 265 | if (graphOk) { |
| 266 | console.log(chalk.green('✓ indexed')); |
| 267 | } else { |
| 268 | console.log(chalk.gray('disabled')); |
| 269 | } |
| 270 | |
| 271 | // ─── FULLSCREEN TUI (default) ───────────────────────────────────────── |
| 272 | if (!flags.classic) { |
| 273 | const { FullScreenTUI } = require('../src/tui/fullscreen.js'); |
| 274 | |
| 275 | const screen = new FullScreenTUI({ |
| 276 | model: config.model.name, |
| 277 | endpoint: config.model.baseUrl, |
| 278 | theme: config.tui?.theme || 'dark', |
| 279 | showToolPanel: (process.stdout.columns || 80) > 120, |
| 280 | onSubmit: async (input) => { |
| 281 | screen.setStreaming(true); |
| 282 | await runAgentLoop(input, config); |
| 283 | screen.setStreaming(false); |
| 284 | // Update token counter in status bar |
| 285 | if (tokenTracker) screen.setTokenInfo(tokenTracker.formatShort()); |
| 286 | }, |
| 287 | onCommand: async (cmd) => { |
| 288 | if (cmd === '/quit' || cmd === '/q' || cmd === '/exit') { |
| 289 | if (sessionStore) sessionStore.save(conversationHistory, { tokens: tokenTracker ? tokenTracker.stats() : undefined }); |
| 290 | screen.leave(); |
| 291 | killMCP() |
| 292 | process.exit(0); |
| 293 | } |
| 294 | // Capture command output by temporarily redirecting stdout + console.log |
| 295 | const origWrite = process.stdout.write.bind(process.stdout); |
| 296 | const origConsoleLog = console.log; |
| 297 | let captured = ''; |
| 298 | process.stdout.write = (chunk) => { captured += chunk.toString(); return true; }; |
| 299 | console.log = (...args) => { captured += args.join(' ') + '\n'; }; |
| 300 | // Create a mock rl for command handler |
| 301 | const mockRl = { prompt: () => {}, close: () => { screen.leave(); process.exit(0); } }; |
| 302 | try { |
| 303 | await handleCmd(cmd, mockRl); |
| 304 | } catch (e) { |
| 305 | captured += `Error: ${e.message}\n`; |
| 306 | } |
| 307 | process.stdout.write = origWrite; |
| 308 | console.log = origConsoleLog; |
| 309 | if (captured.trim()) { |
no test coverage detected