Stream the report to the terminal as the writer generates it #5

Merged
schaefera merged 5 commits from worktree-deep-research-streaming into master 2026-08-17 10:48:53 +00:00
Collaborator

Summary

  • Switches the writer phase from Agent::prompt to rig's stream_prompt, printing each text delta to stdout as it's generated instead of waiting for the full response
  • Also carries the already-in-progress starter.rs -> core.rs rename (CLI parsing/observability init consolidated into core, main.rs left as a thin entry point) and a schemars import fix in review.rs, since these were already applied uncommitted in the working tree this branched from

Test plan

  • cargo build -p deep_research
  • cargo clippy -p deep_research (clean)
  • Manual run against a local Ollama instance to confirm the report streams token-by-token on the terminal
## Summary - Switches the writer phase from `Agent::prompt` to rig's `stream_prompt`, printing each text delta to stdout as it's generated instead of waiting for the full response - Also carries the already-in-progress `starter.rs` -> `core.rs` rename (CLI parsing/observability init consolidated into `core`, `main.rs` left as a thin entry point) and a `schemars` import fix in `review.rs`, since these were already applied uncommitted in the working tree this branched from ## Test plan - [x] `cargo build -p deep_research` - [x] `cargo clippy -p deep_research` (clean) - [ ] Manual run against a local Ollama instance to confirm the report streams token-by-token on the terminal
claude-bot added 1 commit 2026-08-17 10:17:47 +00:00
Wires up starter.rs -> core.rs (CLI parsing and observability init moved
into core, main.rs left as a thin entry point) and switches the report
phase from Agent::prompt to rig's stream_prompt, printing each text
delta to stdout as it arrives instead of waiting for the full response.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
schaefera added 1 commit 2026-08-17 10:19:13 +00:00
print! already locks stdout per call, so the manual lock()/write!() was
extra ceremony over what the flush actually needed. Matches rig's own
cli_chatbot streaming example more closely.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
schaefera added 1 commit 2026-08-17 10:20:40 +00:00
print!/println! each acquire stdout's lock internally; doing that per
streamed chunk in a tight loop adds needless contention. Lock once up
front and write!/writeln! through the held handle instead — which also
means the trailing newline must go through that same handle rather than
println!, since re-locking from the same thread would deadlock.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
schaefera added 1 commit 2026-08-17 10:30:26 +00:00
No destructuring needed since only .text is used; matching the whole
Text struct and drops the now-unused rig::message::Text import.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
schaefera added 1 commit 2026-08-17 10:37:15 +00:00
write_text_stream() in the new stream.rs doesn't touch anything specific
to write_report (topic, findings, the agent) — it just drains a
MultiTurnStreamItem stream, writes each text chunk to a caller-provided
writer, and returns the accumulated string. Pulling it out lets it be
covered by unit tests against a mocked stream and an in-memory writer,
independent of a live model.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
schaefera approved these changes 2026-08-17 10:48:43 +00:00
schaefera merged commit 0ce51a5f4e into master 2026-08-17 10:48:53 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: schaefera/doubleo7#5
No description provided.