feat(cli): stream incremental reasoning/text deltas in run --format json#38504
Open
mustafa3rsan wants to merge 1 commit into
Open
feat(cli): stream incremental reasoning/text deltas in run --format json#38504mustafa3rsan wants to merge 1 commit into
mustafa3rsan wants to merge 1 commit into
Conversation
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue for this PR
N/A — no existing issue.
Type of change
What does this PR do?
opencode run --format json --thinkingnever streams reasoning. During a long thinking phase the JSON stream is silent, then the whole reasoning block appears at once when it ends.The loop in
run.tsonly handlesmessage.part.updated, and gatesreasoning/textonpart.time?.end, which is only set once the part finishes (SessionProcessor.finishReasoning). The incremental tokens are published asmessage.part.delta(session.updatePartDelta), butrunnever listens for them, so they're dropped.This adds one branch that emits
message.part.deltaaspart_deltaevents when--format json. ApartID -> part.typemap (filled frommessage.part.updated) tags each delta so consumers know whether it's reasoning or text:{"type":"part_delta","partID":"prt_...","field":"text","delta":"...","partType":"reasoning"}emit()is a no-op unless--format json, so the formatted/TTY output is untouched (it still waits for the whole part on purpose). It's a new event type, so existing JSON consumers ignore it; the finalreasoning/textevents are still emitted attime.end.How did you verify your code works?
Ran the patched build from source against a real model:
The JSON stream now includes
part_deltaevents (it didn't before):4 part_delta / 2 reasoning / 2 text / 1 step_start / 1 step_finish. Reasoning tokens arrive incrementally instead of only at block end, e.g.:bun run typecheck(tsgo --noEmit) passes andoxlintreports 0 errors on the file.Screenshots / recordings
N/A — not a UI change.
Checklist