()
| 9 | const { setupHooks } = require('./hooks'); |
| 10 | |
| 11 | function attachTtyForwarders() { |
| 12 | if (!isTTY || state.ttyInputForwarderAttached) return; |
| 13 | |
| 14 | state.ttyInputHandler = (chunk) => { |
| 15 | if (state.DEBUG_TTY_INPUT) { |
| 16 | try { |
| 17 | log(`TTY input ${formatTtyInputChunk(chunk)}`); |
| 18 | } catch (err) { |
| 19 | log(`TTY input log error: ${err.message}`); |
| 20 | } |
| 21 | } |
| 22 | if (state.claudeProc) state.claudeProc.write(chunk); |
| 23 | const buf = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk); |
| 24 | if (buf.includes(0x03) && state.turnState.phase === 'running') { |
| 25 | log('Terminal Ctrl+C detected — injecting interrupt event'); |
| 26 | emitInterrupt('terminal'); |
| 27 | } |
| 28 | }; |
| 29 | state.ttyResizeHandler = () => { |
| 30 | if (state.claudeProc) state.claudeProc.resize(process.stdout.columns, process.stdout.rows); |
| 31 | }; |
| 32 | |
| 33 | process.stdin.setRawMode(true); |
| 34 | process.stdin.resume(); |
| 35 | process.stdin.on('data', state.ttyInputHandler); |
| 36 | process.stdout.on('resize', state.ttyResizeHandler); |
| 37 | state.ttyInputForwarderAttached = true; |
| 38 | } |
| 39 | |
| 40 | function trustProjectCwd(cwd) { |
| 41 | const resolved = path.resolve(String(cwd || '')); |
no test coverage detected