* Send output chunk to renderer
(processId: string, type: "stdout" | "stderr", data: string)
| 235 | * Send output chunk to renderer |
| 236 | */ |
| 237 | function sendOutput(processId: string, type: "stdout" | "stderr", data: string): void { |
| 238 | const proc = activeProcesses.get(processId) |
| 239 | if (!proc) return |
| 240 | |
| 241 | const chunk: ProcessOutputChunk = { |
| 242 | type, |
| 243 | data, |
| 244 | timestamp: Date.now(), |
| 245 | } |
| 246 | |
| 247 | // Buffer the output (with size limit) |
| 248 | const chunkSize = Buffer.byteLength(data, "utf8") |
| 249 | if (proc.bufferSizeBytes + chunkSize <= MAX_BUFFER_SIZE_BYTES) { |
| 250 | proc.outputBuffer.push(chunk) |
| 251 | proc.bufferSizeBytes += chunkSize |
| 252 | } else { |
| 253 | // Buffer full - shift old entries to make room |
| 254 | while (proc.outputBuffer.length > 0 && proc.bufferSizeBytes + chunkSize > MAX_BUFFER_SIZE_BYTES) { |
| 255 | const removed = proc.outputBuffer.shift() |
| 256 | if (removed) { |
| 257 | proc.bufferSizeBytes -= Buffer.byteLength(removed.data, "utf8") |
| 258 | } |
| 259 | } |
| 260 | proc.outputBuffer.push(chunk) |
| 261 | proc.bufferSizeBytes += chunkSize |
| 262 | } |
| 263 | |
| 264 | emitLifecycle({ type: "output", processId, chunk }) |
| 265 | } |
| 266 | |
| 267 | /** |
| 268 | * Send exit event to renderer |
no test coverage detected