async fn stream_reader<R>(
reader: R,
kind: ToolChunkKind,
tx: Sender<LineEvent>,
last_activity: Arc<Mutex<Instant>>,
)where
R: AsyncRead + Unpin,Expand description
Read raw bytes from a child stdio handle and forward chunks to the publisher with three flush triggers:
- Newline. As soon as a
\nis in the buffer, drain everything up to and including that newline as one chunk. Loop, since a single read can contain multiple complete lines. - Size threshold (
FLUSH_BYTES). If the buffer accumulates without a newline (minified JSON output, long progress lines,printfwithout\n), flush as soon as it exceeds the threshold. Prevents unbounded memory growth and keeps streaming live for newline-free output. - Quiet-window (
FLUSH_QUIET_WINDOW). After this much idle time with non-empty pending bytes, flush. Surfaces slow-trickle output (one byte at a time) that would otherwise wait for the next byte to trigger a natural flush.