(source)
| 210 | } |
| 211 | |
| 212 | function emitInterrupt(source) { |
| 213 | const interruptEvent = { |
| 214 | type: 'interrupt', |
| 215 | source, |
| 216 | timestamp: Date.now(), |
| 217 | uuid: crypto.randomUUID(), |
| 218 | }; |
| 219 | const record = { seq: ++state.eventSeq, event: interruptEvent }; |
| 220 | state.eventBuffer.push(record); |
| 221 | if (state.eventBuffer.length > EVENT_BUFFER_MAX) { |
| 222 | state.eventBuffer = state.eventBuffer.slice(-Math.round(EVENT_BUFFER_MAX * 0.8)); |
| 223 | } |
| 224 | broadcast({ type: 'log_event', seq: record.seq, event: interruptEvent }); |
| 225 | setTurnState('idle', { reason: `${source}_interrupt` }); |
| 226 | } |
| 227 | |
| 228 | function formatTtyInputChunk(chunk) { |
| 229 | const buf = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk); |
no test coverage detected