Conversation
|
The following comment was made by an LLM, it may be inaccurate: Based on my search, I found related PRs that touch on cost display and TUI footer enhancements, but no direct duplicates of PR #39807: Related PRs (not duplicates, but in similar areas):
None of these address the specific feature of showing optional daily session cost in the TUI footer with the 30-second refresh and midnight-based calculation that PR #39807 implements. No duplicate PRs found |
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
65b9103 to
22200eb
Compare
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Registering it last avoids renumbering every positional Endpoint3_N constant in the generated effect client; find-my-way-ts matches static segments before :sessionID regardless of registration order. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Drop the per-session cost refetch and the unrelated stats aggregation change so the PR only adds today's total, matching the v2 branch. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
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
Related to #39740. Session cost is already visible in the sidebar Context section, but users also need an optional total for all sessions updated today without running
opencode stats --days 1.Type of change
What does this PR do?
Adds an optional Today cost below the existing session spend in the sidebar Context section. The footer is unchanged. The display is:
When the current session's model has no pricing information (e.g. a custom model without a
costentry in the catalog or config), the spent line readsN/A spentinstead of$0.00 spent, since the true cost cannot be derived. The footer session-cost display is unchanged.Today is calculated from every session in the shared local database updated since local midnight. It is therefore shared across concurrently running OpenCode terminals and each Context view refreshes it every 30 seconds. The current session spend is fetched from the persisted session record as well. If a value cannot be fetched, it is omitted.
The Today line is disabled by default and appears only when
show_today_costis set totrue. Create~/.config/opencode/tui.jsonif it does not exist:{ "$schema": "https://opencode.ai/tui.json", "show_today_cost": true }A project-local
.opencode/tui.jsoncan also be used. The daily aggregation is exposed through the typed session API and does not shell out toopencode stats --days 1.Why the diff touches so many files
The hand-written change is small: the endpoint (
packages/protocol/src/groups/session.ts,packages/server/src/handlers/session.ts,packages/core/src/session.ts), the TUI config flag, and the sidebar Context view (including theN/A spentfallback). Everything else is regenerated output:packages/client/src/generated-effect/client.tsandpackages/client/src/generated/*.ts— generated by@opencode-ai/httpapi-codegen(// Do not editheader), adding the typedsession.costclient method. The endpoint is registered last in the session group so the generator's positionalEndpoint3_Nconstants keep their existing names and the generated diff is append-only. Route matching is unaffected: the router (find-my-way-ts) prioritizes the static/api/session/costsegment over/api/session/:sessionIDregardless of registration order.packages/sdk/js/src/v2/gen/*.ts— the hey-api codegen adding the samecost()method to the SDK.packages/plugin/src/tui.ts— theTuiConfigViewtype gains the resolvedshow_today_costfield so plugins see the setting.packages/opencode/src/cli/cmd/stats.ts— refactored to reuse the newsumSessionCostshelper instead of accumulating cost inline (same output, one code path for cost summation).Note on attribution: the total sums the full
costof every session withtime_updatedsince local midnight. A long-running session that started yesterday and is touched today counts its entire cost toward today. This is a deliberate simplification for a glanceable stat; exact per-day attribution would require message-level aggregation.How did you verify your code works?
bun typecheckpassed inpackages/plugin,packages/sdk/js, andpackages/tui.--version.origin/devbefore updating this PR.N/A spentwhen the session model has no pricing and the currency amount when it does.The repository-wide pre-push typecheck is currently blocked by unrelated AWS stats client type errors and a Bun/tsgo segmentation fault.
Screenshots / recordings
This is a terminal UI change. Expected sidebar Context output with the setting enabled:
For a model without pricing information:
Checklist