feat(tui): live context gauge via per-iteration usage events - #20
Merged
Conversation
odek serve v1.23.0 streams a "usage" event after every LLM turn (cumulative contextTokens/outputTokens for the run). Handle it to keep the header context gauge live during multi-turn runs instead of stale until "done". Zero-usage events (providers without usage reporting) are ignored so the last known fill is preserved. Renders are coalesced via the existing streaming flush path. Verified end-to-end against a real odek v1.23.0 serve: 3 usage events streamed before the first response token, final value matching done.contextTokens.
bodek is a pure front-end; odek-side fixes must be handed to the user as a task for an odek session, not edited directly.
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.
What
The header context gauge only refreshed when a run finished, because odek serve reported token economics solely on the
doneevent (once per user prompt, after the whole agent loop). odek v1.23.0 (BackendStack21/odek#127) now streams a lightweightusageevent after every LLM turn — this PR consumes it.Changes
internal/tui/events.go— handle theusageevent: refreshwinCtxTok(the gauge's data source) mid-run, coalesced through the existing 80ms streaming flush. Zero-usage events (providers without usage reporting) are ignored so the last known fill is preserved. Turn state (busy,status) is untouched.internal/tui/stats_test.go— regression test: gauge refreshes mid-run onusage, zero values don't clobber a known fill, turn state undisturbed.AGENTS.md— new workflow rule: never modify the odek project from a bodek session; hand odek-side fixes to the user as a task for an odek session.Compatibility
Fully backward compatible both ways: older bodek ignores the unknown event type; older odek simply never sends it (gauge behaves as before).
Verification
make fmt / vet / lint (0 issues) / test -race— all green.usageevents streamed live (9.1k → 9.1k → 18.4k ctx tokens) before the first response token and beforedone, final value matchingdone.contextTokens.