feat(tui): show estimated live token throughput in footer - #30164
Proton1917 wants to merge 9 commits into
Conversation
| return 0 | ||
| } | ||
|
|
||
| return Math.max(1, Math.round(live.nonAsciiChars + live.asciiChars / 4)) |
There was a problem hiding this comment.
Is this estimating tokens from chars?
Edit: I see from the description this is intentional, so maybe it's more of a why question...
There was a problem hiding this comment.
Also, you already added live.nonAsciiChars + live.asciiChars above, use chars instead :)
There was a problem hiding this comment.
Thanks, addressed in 46399ef. I removed the character heuristic entirely (asciiChars / nonAsciiChars are gone). The live footer now counts committed assistant/reasoning stream chunks as a provider-neutral fallback and keeps the ~ marker because this is still not provider/billing usage. Provider-reported usage/cost remains authoritative and replaces the fallback when it arrives.
The chars cleanup is no longer applicable after that change because the char-count fields were removed.
There was a problem hiding this comment.
Follow-up in d45c0d8: I changed this again after testing the chunk fallback. Stream chunk counts were too provider/model-dependent to present as token throughput, so the live footer now tracks committed response length, smooths it, and displays Math.round(smoothedResponseLength / 4) as an estimated token count. The ~ marker stays intentional, and provider-reported usage/cost still replaces the estimate when it arrives.
# Conflicts: # packages/opencode/src/cli/cmd/run/footer.ts # packages/opencode/src/cli/cmd/run/footer.view.tsx # packages/opencode/src/cli/cmd/run/runtime.queue.ts # packages/opencode/src/cli/cmd/run/session-replay.ts # packages/opencode/test/cli/run/footer.view.test.tsx
|
This has been updated to use response-length smoothing for the live estimate, merged with the latest dev to resolve conflicts, and checks are green. Ready for review when you have a chance. |
|
Automated PR Cleanup Thank you for contributing to opencode. Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions. This PR was closed because it matched the following cleanup criteria:
PRs created within the last month are not affected by this cleanup. If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate. Thanks again for taking the time to contribute. |
Issue for this PR
Refs #29909
Type of change
What does this PR do?
Adds footer-only live usage telemetry for direct run turns. While assistant/reasoning text streams, the reducer tracks committed response length, smooths that length, and derives an estimated output token count with
Math.round(smoothedResponseLength / 4).While a turn is running, the footer groups elapsed duration with the live estimate in the existing usage slot:
Provider-reported usage/cost still wins when it arrives, so billing/accounting stays unchanged. The live value is explicitly marked as estimated with
~; this keeps the first pass out of provider protocols, tokenizer dependencies, shell/tool streaming, and plugin/statusline APIs.This avoids using stream chunk counts as tokens. Chunk sizing varies heavily by provider/model, while response-length smoothing gives a stable spinner/footer estimate without pretending to be billing usage.
How did you verify your code works?
bun test test/cli/run/session-data.test.ts test/cli/run/session-replay.test.ts test/cli/run/footer.view.test.tsx --timeout 30000bun run --cwd packages/opencode typecheckbunx oxlint packages/opencode/src/cli/cmd/run/session-data.ts packages/opencode/src/cli/cmd/run/session-replay.ts packages/opencode/src/cli/cmd/run/stream.transport.ts packages/opencode/src/cli/cmd/run/footer.view.tsx packages/opencode/src/cli/cmd/run/footer.ts packages/opencode/src/cli/cmd/run/runtime.queue.ts packages/opencode/test/cli/run/session-data.test.ts packages/opencode/test/cli/run/session-replay.test.ts packages/opencode/test/cli/run/footer.view.test.tsx(0 errors; existing warnings remain)OPENCODE_CHANNEL=codex/live-token-tps bun run --cwd packages/opencode buildScreenshots / recordings
Text preview from the footer render test:
Checklist