Skip to content

Port upstream 0.58.0: re-land stranded Usage & Spend daily ledger (#492) with the 0.67.0 30-row cap - #715

Draft
Finesssee wants to merge 4 commits into
mainfrom
port/micro-0.58.0-reland-usage-spend-ledger
Draft

Finesssee wants to merge 4 commits into
mainfrom
port/micro-0.58.0-reland-usage-spend-ledger

Conversation

@Finesssee

Copy link
Copy Markdown
Collaborator

Summary

Re-lands the upstream v0.58.0 Usage & Spend port #492. It was merged on 2026-09-13 only into the stacked base port/upstream-0.58.0 and never reached main; git cherry against main @ 7695471b still reported both commits as missing.

  • Daily ledger (Settings > Usage & Spend): a table built from the existing SpendContract.daily cost and token fields, newest day first. A missing cost or token count shows "Unknown", and an explicit zero stays $0.00 / 0 tokens.
  • Local cost chart hover titles (tray card): each bar's title now also shows that day's token count from chartData.tokensHistory.
  • Upstream 0.67.0 Fix Usage & Spend scroll lag on long ranges steipete/CodexBar#3998, which applies once the ledger exists: long ledgers open with the newest 30 days plus a Show all (N) / Show less control. 0.67.0.md row 18 marked this SKIP because Windows had no ledger. This PR adds the ledger, so the row is ported here.

The original commits are cherry-picked with -x. The second commit adapts them to main, which already keeps the canonical spend formatters in lib/usageSpendSharing.ts. The ledger reuses formatUsd, and the token-cell helper is added there as formatSpendTokens instead of a second formatter module.

Upstream reference

Ported / Deferred

Change Status
Daily ledger with unknown vs zero cells Ported (#492)
Token counts in local cost chart hover titles Ported (#492)
Newest 30 rows + Show all / Show less Ported (steipete#3998)
Upstream ledger Providers and Requests columns Not ported. The Windows SpendContract.daily point has no per-day provider mix or request count, and wire shapes are not invented.

Locale: six new keys (UsageSpendDailyLedger, UsageSpendDailyLedgerHelper, UsageSpendNoDailyData, UsageSpendColDate, UsageSpendColCost, UsageSpendColTokens) are in rust/src/locale.rs, keys.ts and all eight .ftl files. The toggle reuses the existing UsageSpendShowAll / UsageSpendShowLess.

Validation

Run in the worker worktree on Rust 1.98.0 and Node 24:

Command Result
pnpm install --frozen-lockfile pass
pnpm run check-locale 877 keys match between Rust and TS
pnpm test 66 files, 404 tests passed
pnpm run lint 0 errors. The 11 warnings are the same unused imports as on main
pnpm run build pass
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 2160 passed, 0 failed, 1 ignored
cargo +1.98.0 test -p codexbar-desktop-tauri -- --skip bootstrap_payload_exposes_every_provider_variant 459 passed, 0 failed

The skipped desktop test is the non-hermetic #684 test, which reads the real %APPDATA%\CodexBar\settings.json on main. #711 fixes it separately.

Affected areas

  • apps/desktop-tauri/src/components/UsageSpendDailyLedger.tsx (new) and its test
  • apps/desktop-tauri/src/components/MenuCardDetails.tsx (chart hover titles) and MenuCard.test.tsx
  • apps/desktop-tauri/src/lib/usageSpendSharing.ts (formatSpendTokens) and its test
  • apps/desktop-tauri/src/surfaces/settings/tabs/UsageSpendTab.tsx (mounts the ledger)
  • apps/desktop-tauri/src/styles.css, apps/desktop-tauri/src/i18n/keys.ts, rust/src/locale.rs, rust/src/locale/*.ftl

UI proof

Pending: a browser-use proof over WebView2 CDP of Settings > Usage & Spend (ledger, 30-row cap, Show all) and the tray card chart titles, built from this head with isolated data. It will be posted as a "UI proof (browser-use)" comment.

(cherry picked from commit f43cb6e)
Adapted to main: main already keeps the canonical spend formatters in
lib/usageSpendSharing.ts (formatUsd, formatSpendMetric), so the daily
ledger reuses them and the token-cell helper is added there as
formatSpendTokens instead of a second lib/usageSpendFormatters.ts module.
UsageSpendTab keeps main's layout unchanged.

(cherry picked from commit 89edce6)
The re-landed daily ledger added six keys to en-US only. Add them to the
other seven locale files so every .ftl stays aligned with locale.rs and
keys.ts.
Port upstream 0.67.0 steipete#3998 (ce1b808) now that the daily ledger exists:
the ledger opens with the newest 30 days and a Show all (N) / Show less
control expands it to the complete history. Translates the upstream
SpendDashboardDailyLedgerTests expansion test.
@coderabbitai

coderabbitai Bot commented Sep 30, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • 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.

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