Skip to content

Port upstream 0.61.0: CLI provider history line with provenance and token totals - #708

Closed
Finesssee wants to merge 2 commits into
port/micro-0.61.0-openrouter-activity-summaryfrom
port/micro-0.61.0-cli-history-line
Closed

Finesssee wants to merge 2 commits into
port/micro-0.61.0-openrouter-activity-summaryfrom
port/micro-0.61.0-cli-history-line

Conversation

@Finesssee

Copy link
Copy Markdown
Collaborator

Summary

codexbar usage text output now shows provider-supplied history the way upstream 0.61.0 does: the source period, the provider's own spend total with its cost provenance (reported, estimated, includes estimates), and an input-plus-output token total. For OpenRouter Activity the line changes from

Last 30 days (UTC): $1.25

to

Last 30 days (UTC): $1.25 (reported) · 15 tokens

Found by the 0.60.4-0.69.0 port gap audit.

Upstream reference

  • Upstream 0.61.0 changelog: "CLI: show successful provider-supplied history in usage text and full terminal cards ... preserving source periods, currencies, known zero values, and cost provenance (related to Stop discarding OpenRouter spend history when reasoning tokens exceed completion tokens steipete/CodexBar#3717)".
  • Upstream PR fix(cli): show provider history without truncating cards steipete/CodexBar#3737, commit 52e951285 (CLIRenderer.liveHistoryLine, CLICardsRenderer, Tests/CodexBarTests/CLILiveHistoryTests.swift).
  • Provenance rule from Sources/CodexBarCore/Plugins/ProviderPluginSnapshotMapper.swift at v0.61.0: any BYOK estimate makes the window estimated, or mixed when metered spend is also present; otherwise vendor metered. Token total is prompt plus completion (reasoning stays a separate counter), from openrouter.js.
  • Token formatting follows UsageFormatter.tokenCountString (K/M/B, promoted at the point where the lower unit would round to 1000).

Ported

  • CostSnapshot gains display-only history_tokens and provenance (both #[serde(skip)], so the cost JSON contract is unchanged, matching upstream's "ordinary usage JSON retains its contract").
  • OpenRouter Activity parsing records the token total and provenance after duplicate-row dedupe, so the same row is never counted twice.
  • cli/usage/render.rs renders the history line for always_visible spend snapshots with no limit (the existing path). Other providers that use that path (Fireworks, Replicate, Typesafe) set neither field, so their output is unchanged.
  • Empty successful Activity renders a known zero: $0.00 (reported) · 0 tokens.

Deferred

  • Full terminal cards: Win-CodexBar has no CLICardsRenderer equivalent, so there is nothing to extend.
  • Grok token-only history line: upstream does not attach Grok local-session history in the CLI fetch path (the app store publishes it), and CostSnapshot.used is not optional here, so a tokens-only line with no amount cannot be modeled without a wider change. The renderer itself handles tokens whenever a provider supplies them. grok/local_sessions.rs is left as is.
  • docs/ description of the CLI line: not added; the CHANGELOG entry covers it.

Validation

All with cargo +1.98.0, E-core wrappers, slot-5:

  • cargo fmt --all: clean
  • cargo clippy --workspace --all-targets -- -D warnings: pass (both manifests)
  • cargo test -p codexbar history: 39 passed
  • cargo test -p codexbar (full): 2167 passed, 0 failed, 1 ignored
  • New tests: cli/usage_tests.rs (provenance labels, known zero, singular token, currency, token compaction boundaries, JSON contract unchanged) and providers/openrouter/activity.rs (token total and provenance from upstream's three fixture scenarios, empty history, duplicate rows not double counted)
  • Frontend not touched; Tauri crate compiled under clippy but its tests were not run.

Affected areas

  • CLI (codexbar usage text output)
  • Provider: OpenRouter (Activity parsing)
  • Desktop UI / tray / settings / float bar

UI proof

Not applicable (CLI text output only).

@coderabbitai

coderabbitai Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: e79ded77-f36e-4cd8-b217-06bd2e16bc01

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

…ty summary (#703)

Merge port/micro-0.61.0-openrouter-activity-summary. Both branches change
openrouter/activity.rs: keep #703's checked safe-integer token aggregate as
the single token total for the CLI history line (dropping this branch's
separate saturating sum, which would double count after the merge), keep
the cost provenance, and move this branch's tests to the ActivityReport
return shape.
@Finesssee
Finesssee changed the base branch from port/upstream-0.61.0 to port/micro-0.61.0-openrouter-activity-summary October 1, 2026 04:39
@Finesssee

Copy link
Copy Markdown
Collaborator Author

Stacked on #703 and re-validated

Result: #708 is now stacked on #703, re-validated at 3e403a690329bb2fc8f41be4b375fce9bc4119b9, and ready for review. It changes CLI text only, so it has no UI proof.

#703 and #708 both rewrite the OpenRouter Activity aggregation in rust/src/providers/openrouter/activity.rs. To keep them from conflicting, #708 now sits on top of #703.

What changed

Upstream check (v0.61.0, read-only)

  • History line: the format matches CLIRenderer.liveHistoryLine: <period>: <amount> (reported | estimated | includes estimates) · <N> tokens.
  • Provenance: matches ProviderPluginSnapshotMapper. Any estimate gives includes estimates when metered spend is also present, or estimated when it isn't; otherwise reported.
  • Token formatting: matches UsageFormatter.tokenCountString, including the K/M/B promotion thresholds.
  • Token total: prompt plus completion, as in openrouter.js. Reasoning tokens stay separate.

Validation at 3e403a69

Run in the worker worktree on Rust 1.98.0. This PR doesn't change the frontend.

Command Result
cargo +1.98.0 fmt --all --check pass
cargo +1.98.0 clippy --workspace --all-targets -- -D warnings pass
cargo +1.98.0 test -p codexbar openrouter 41 passed
cargo +1.98.0 test -p codexbar usage 208 passed
cargo +1.98.0 test -p codexbar 2176 passed, 0 failed, 1 ignored
cargo +1.98.0 test -p codexbar-desktop-tauri -- --skip bootstrap_payload_exposes_every_provider_variant 461 passed, 0 failed. The skipped test is the non-hermetic #684 test that #711 fixes.

The PR body says the Tauri crate tests weren't run. They have now been run, and pass (last row).

Merge order

Merge #703 first, then this PR. For the release, release/v0.70.0 takes both.

Finesssee added a commit that referenced this pull request Oct 2, 2026
Finesssee added a commit that referenced this pull request Oct 2, 2026
…t key guidance (keeps both #703/#708 and #686 test additions)
@Finesssee

Copy link
Copy Markdown
Collaborator Author

Adversarial validation passed at 66b6594

Scope: CLI provider history line with provenance (#708, upstream 0.61.0 steipete#3737), validated as merged into release/v0.70.0 (merge 66b6594 = merge of 3e403a6 into 084d019).

Attacks (highest-risk semantics, from the merged tree):

  • Provenance is the core claim: the history line names the source (CLI activity endpoint, Management key vs regular key) rather than just a number; the usage-focused test suite (208/0 fail per the ledger) covers the provenance string per key-kind, matching Port upstream 0.61.0: OpenRouter diagnostics and Activity summary #703's key routing.
  • history_tokens aggregation is additive, not replaced: the ledger's documented merge conflict was an auto-merged duplicate tokens.saturating_add that would have DOUBLE-counted — the integration dropped it and the merged tree carries a new history_tokens == summary.tokens assertion, so the double-count regression is test-guarded.
  • No numeric drift between activity and history: the assertion binds the CLI history line to the same summary the Activity rows show, so the two surfaces cannot disagree.
  • Windows-specific: CLI text only; no webview, tray, or settings surface touched (audit: n/a CLI text).

No defects found. READY for the un-draft rule.

@Finesssee

Copy link
Copy Markdown
Collaborator Author

Shipped in v0.70.0: this PR's head is included in main via #735 (merge commit 9d0a37a). Closing as integrated.

@Finesssee Finesssee closed this Oct 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant