processOutput reads stdout line by line, logs it, and parses events.
(r io.Reader)
| 452 | |
| 453 | // processOutput reads stdout line by line, logs it, and parses events. |
| 454 | func (l *Loop) processOutput(r io.Reader) { |
| 455 | scanner := bufio.NewScanner(r) |
| 456 | // Increase buffer size for long lines (Claude can output large JSON) |
| 457 | buf := make([]byte, 0, 64*1024) |
| 458 | scanner.Buffer(buf, 1024*1024) |
| 459 | |
| 460 | for scanner.Scan() { |
| 461 | line := scanner.Text() |
| 462 | |
| 463 | // Update last output time for watchdog |
| 464 | l.mu.Lock() |
| 465 | l.lastOutputTime = time.Now() |
| 466 | l.mu.Unlock() |
| 467 | |
| 468 | // Log raw output |
| 469 | l.logLine(line) |
| 470 | |
| 471 | // Parse the line and emit event if valid |
| 472 | if event := l.provider.ParseLine(line); event != nil { |
| 473 | l.mu.Lock() |
| 474 | event.Iteration = l.iteration |
| 475 | if event.Type == EventStoryDone { |
| 476 | l.sawStoryDone = true |
| 477 | } |
| 478 | l.mu.Unlock() |
| 479 | l.events <- *event |
| 480 | } |
| 481 | } |
| 482 | } |
| 483 | |
| 484 | // logStream logs a stream with a prefix. |
| 485 | func (l *Loop) logStream(r io.Reader, prefix string) { |