agents proxy: opencode M4 — tool parts and real token/cost totals - #1950
Open
julia-ye wants to merge 1 commit into
Open
agents proxy: opencode M4 — tool parts and real token/cost totals#1950julia-ye wants to merge 1 commit into
julia-ye wants to merge 1 commit into
Conversation
Live: run.tool_call_started/completed become tool part.updated frames
(running -> completed/error), re-carrying the input on completion and
reusing the guest opencode's own prt_ ids so parts sort where the tool
actually ran; dangling tools are closed out as errors on turn end (both
completed and failed). run.completed's own payload carries the per-turn
totals (total_tokens_in/out, run_cost_micros) — rendered as a closing
step-finish part and on the finalized assistant message, which is what
the TUI's token counter and cost display key off. usage_recorded /
cost_accrued / run.log become explicit no-ops instead of unhandled-log
spam.
History: tool parts, step-finish, and real totals reconstruct the same
way; text/reasoning part ids are minted at turn END so the answer sorts
after the tool activity.
Also fixes the blank footer model segment: assistant message info uses
FLAT modelID/providerID (nested model{} is user-message shape — confirmed
against real-server history payloads).
Live-verified: a tool-using prompt renders the command block (workdir,
command, output), the answer, a real duration, the model name in the
footer, and a token count in the status bar.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Stacked on #1949 (M3, which stacks on #1948 — review in order; this diff is M4 only). Fourth slice: tool-using prompts render their command activity, and real token/cost numbers reach the TUI.
What's here
run.tool_call_started/run.tool_call_completedbecome toolmessage.part.updatedframes (running→completed/error), re-carrying the input on completion (the TUI keeps a part's final state). The canonicaltool_call_idis the guest opencode's ownprt_…id — time-encoded by the guest — so it's reused verbatim and the part sorts where the tool actually ran. Dangling tools are closed out as errors on turn end, on both the completed and failed paths.run.completed's payload carries per-turntotal_tokens_in/outandrun_cost_micros(confirmed live against the dev stack), rendered as a closingstep-finishpart and on the finalized assistant message — the two places the TUI's token counter and cost display read from.usage_recorded/cost_accrued/run.logbecome explicit no-ops instead of unhandled-log spam.step-finish, and totals reconstruct in the replay path too; text/reasoning part ids are minted at turn end so the answer sorts after the tool activity within the message.modelID/providerID— the nestedmodel{}form is user-message shape (confirmed against real-server history payloads), and using it on assistant messages left the TUI's footer model segment blank.Ground truth
Captured a real
opencode servetool turn (bash) through the logging relay for the part lifecycle (pending → running with streamingmetadata.output→ completed withoutput/exit/title, bracketed bystep-start/step-finish), and a hosted-session tool turn for the canonical payload shapes. Both recorded in the capture doc on the internal side.Testing
# Running in /workspace,$ echo …, output), the streamed answer, the model name + real duration in the message footer, and a token count in the status bar — with zero unhandled routes.Not in this PR
Permission round-trips (M5), stream reconnect (M6). Known cosmetic gap: per-step
step-finishgranularity (one closing part stands in; canonical only exposes per-turn totals).🤖 Generated with Claude Code