Skip to content

Port upstream CodexBar 0.52.0-0.53.0 - #346

Merged
Finesssee merged 23 commits into
mainfrom
port/upstream-0.53-review
Aug 19, 2026
Merged

Port upstream CodexBar 0.52.0-0.53.0#346
Finesssee merged 23 commits into
mainfrom
port/upstream-0.53-review

Conversation

@Finesssee

@Finesssee Finesssee commented Aug 19, 2026

Copy link
Copy Markdown
Collaborator

Port of upstream steipete/CodexBar v0.53.0 (stacked on #345; read-only consumption of tagged sources, zero upstream contact per docs/PORTING.md).

Ported

Item Notes
Explicit cost provenance and coverage (steipete#3015) spend_contract.rs: SpendContract with CostProvenance (ListPriceEstimate/VendorMetered/Mixed/Unknown), CostCoverageCounts (priced/estimated/unpriced/unmetered), price_coverage_ratio. Partial totals show coverage, nothing unpriced masquerades as a bill.
Token mix, hourly activity, conversation totals (steipete#3017) SpendTokenMix (input/output/cache_read/cache_creation/reasoning), SpendActivityCell (weekday/hour/conversations), ActivityHeatmap in UsageSpendTab.tsx. MetricCard renders spend, coverage, conversations, token mix.
All-time range (365 days) (steipete#3009) `selectedDays: 0
Exact-match custom pricing overlays (steipete#3016) CustomPricing loads custom-pricing.json from config dir. CustomRates with input/output/cache_read/cache_write per-million-token rates. Custom rates are authoritative over models.dev/built-in. Missing fields stay unknown, explicit zero is known-free.
Opt-in read-only OpenCodex import (steipete#3018) spend_contract/opencodex.rs: reads usage.jsonl, deduplicates by request_id, aggregates into ImportedSpendSource with models, daily, hourly activity, coverage. SQLite cache in CodexBar cache dir. Toggle in UsageSpendTab.
Grok source picker (steipete#3010) UsageSourceSection.tsx: Auto / Grok CLI / SuperGrok OAuth / Browser cookies. set_provider_usage_source Tauri command. SourceMode::parse validates against available_sources().
CLI: codexbar usage --format toon (steipete#2996, steipete#3021) cli/toon.rs: TOON v4.1 JSON payload emission. cli/usage.rs: --format flag accepting text/json/toon.
CLI: codexbar cost --json alignment (steipete#3019) cli/cost.rs: JSON output aligned with spend provenance, token mix, coverage, opt-in OpenCodex.
Low Power Mode Off/On/Automatic (steipete#2995) LowPowerModePreference enum (Off/On/Automatic). auto_refresh.rs: system_battery_saver_enabled() reads Windows Battery Saver via SystemStatusFlag. GeneralTab.tsx: Select dropdown replacing Toggle. Legacy low_power_mode boolean kept for settings.json migration (backed by tests).
UsageSpendTab rebuild SpendContractOverview with provenance/coverage/conversations/token-mix metric cards. ContractModelsPanel replacing ModelsPanel. ProjectsPanel using contract.projects/contract.conversations. OpenCodex import + hide-native-Codex checkboxes.
TrayPanel OverviewSpend OverviewSpendSummary component showing 30-day total spend across all providers in the tray panel header.
Pinned IANA day-bucketing timezone spend_contract.rs uses chrono Local/Utc for consistent day bucketing.
Uncertain Codex fork accounting fail-closed known_zero + history_coverage_established fields. Empty scans with established coverage report known_zero: true, unknown scans report known_cost_usd: None.

Skipped (no Windows counterpart — macOS-only)

Item Reason
Settings window keepalive-window hack removal (steipete#3003, steipete#3029) macOS NSWindow controller lifecycle. Tauri manages windows directly; no invisible keepalive window exists.
CloudKit sync assertion crash fix (steipete#3030) macOS CloudKit framework. No equivalent on Windows.
Codex RPC timeout error messaging (steipete#3022) Win-CodexBar uses OAuth REST API, not the Codex CLI app-server process. No RPC timeout path.
Keychain non-interactive browser imports (steipete#2986) macOS Keychain access gate. Windows uses DPAPI/secure_file — different credential store, no interactive access gate.

Deferred (evidence)

Item Reason
Full upstream 0.53 locale parity for all 23 languages Only en-US ported. Other 6 catalogs need translation pass.
TOON v4.1 spec conformance depth Basic JSON emission implemented. Not fully audited against the complete v4.1 specification — needs a dedicated conformance test.
Grok gRPC-web+proto billing internals Upstream uses grok_api_v2.GrokBuildBilling/GetGrokCreditsConfig with protobuf wire scanner. Win-CodexBar uses REST endpoint with JSON parsing. Behavior matches but implementation differs.
Codex fork-accounting timezone audit Day-bucketing uses local timezone. Not re-audited against all upstream timezone edge cases (IANA pinned but cross-day-boundary sessions not exhaustively tested).
UsageSourceSection backend-driven options Currently hardcodes Grok options. Should fetch from available_sources() like CookieSourceSection does — noted as thermo-nuclear blocker.

Verification

  • cargo fmt --all — clean
  • cargo clippy --manifest-path rust/Cargo.toml --all-targets -- -D warnings — clean
  • cargo clippy --manifest-path apps/desktop-tauri/src-tauri/Cargo.toml --all-targets -- -D warnings — clean
  • cargo test --manifest-path rust/Cargo.toml --lib — passed
  • cargo test --manifest-path apps/desktop-tauri/src-tauri/Cargo.toml — passed
  • pnpm --dir apps/desktop-tauri test — passed
  • pnpm --dir apps/desktop-tauri run build — passed
  • scripts/local-check.ps1not run: known StrictMode bug (Set-StrictMode -Version Latest + $ErrorActionPreference = "Stop" causes terminating errors on undefined variable references). Documented as gate limitation.
  • CUA Windows desktop proof — in progress: fresh tauri:build:debug capture on the 0.53 branch. Surfaces: UsageSpendTab (SpendContract, heatmap, models, projects, OpenCodex toggle), TrayPanel (OverviewSpend), GeneralTab (low-power selector), Grok provider detail (UsageSourceSection).
  • git diff --check — clean (no whitespace errors)

Thermo-nuclear review

A thermo-nuclear code-quality review was performed. 4 blocking findings:

  1. Collapse Port upstream CodexBar 0.52.0 #345 stacked churn (UsageSpendModelRow → SpendContract)
  2. cost_pricing.rs crosses 1k lines — extract Claude routed pricing
  3. UsageSourceSection hardcodes Grok options in generic-named component
  4. CustomRates::cost() / cost_parts() formula duplication

Plus 2 non-blocking notes (tuple destructuring in build_local_spend_contract_from_summary, ModelAccumulator saw_* bools vs Option).
See review comment: #346 (comment)

@Finesssee

Copy link
Copy Markdown
Collaborator Author

Thermo-nuclear review: BLOCKING on 4 items.

  1. Collapse Port upstream CodexBar 0.52.0 #345's throwaway model aggregation — Port upstream CodexBar 0.52.0 #345 introduces UsageSpendModelRow/extend_model_rows/ModelsPanel which Port upstream CodexBar 0.52.0-0.53.0 #346 immediately deletes and replaces with SpendContract. Squash Port upstream CodexBar 0.52.0 #345 into Port upstream CodexBar 0.52.0-0.53.0 #346 or introduce SpendContract in Port upstream CodexBar 0.52.0 #345 directly.

  2. cost_pricing.rs crosses from 999 to ~1062 lines — extract the 63-line Claude routed pricing additions into codex_routed_pricing.rs or a new claude_routed_pricing.rs. Don't let it cross 1k.

  3. UsageSourceSection.tsx is named generic but hardcodes Grok options (GROK_OPTIONS const, returns null for non-Grok). Either rename to GrokUsageSourceSection and stop pretending it's generic, or fetch available sources from the backend like CookieSourceSection does via get_provider_cookie_source_options. The backend already has SourceMode::parse and available_sources().

  4. CustomRates has cost() and cost_parts() with near-identical formulas. cost_parts takes raw u64s, cost takes a struct. Convert to ModelTokenCounts and call cost(), or make cost_parts the primitive and have cost() delegate to it. Don't duplicate the formula.

Additional notes (non-blocking):

  • build_local_spend_contract_from_summary has 5- and 6-tuple destructurings with conditional branches. Extract the native-vs-imported merge into a helper for testability.
  • ModelAccumulator in opencodex.rs uses saw_total/saw_cost bools instead of Option fields — make the known-vs-unknown invariant explicit.

@Finesssee Finesssee changed the title Port upstream 0.53 Port upstream CodexBar 0.53.0 Aug 19, 2026
@Finesssee Finesssee changed the title Port upstream CodexBar 0.53.0 Port upstream CodexBar 0.52.0-0.53.0 Aug 19, 2026
@Finesssee
Finesssee changed the base branch from port/upstream-0.52-review to main August 19, 2026 04:46
@Finesssee

Copy link
Copy Markdown
Collaborator Author

Thermo-nuclear review addressed in 1e1f6d6.\n\nBlocking items:\n1. Stacked churn: PR #345 is closed; #346 is retargeted to main, so 0.52+0.53 now land as one coherent SpendContract architecture.\n2. 1k-line cost_pricing.rs: extracted Claude routed/models.dev pricing into rust/src/core/claude_routed_pricing.rs. cost_pricing.rs is now 961 lines.\n3. Generic UsageSourceSection: renamed to GrokUsageSourceSection and updated the only consumer, making the Grok-specific contract explicit.\n4. Duplicate CustomRates formulas: cost() now delegates to cost_parts(); one pricing formula remains.\n\nNon-blocking notes also addressed:\n- replaced tuple-heavy native/imported spend destructuring with NativeSpendData + ResolvedSpendData helpers.\n- ModelAccumulator now uses Option/Option for known-vs-unknown total/cost instead of saw_total/saw_cost booleans.\n\nValidation:\n- cargo check --manifest-path rust/Cargo.toml: PASS\n- cargo check -p codexbar-desktop-tauri: PASS\n- cargo test --manifest-path rust/Cargo.toml spend_contract: 4/4 PASS\n- claude_bare_models_route_to_first_party_vendors: PASS\n- claude_explicit_unknown_vendor_fails_closed: PASS\n- TypeScript tsc --noEmit: PASS\n- Vitest: 43 files / 266 tests PASS\n- git diff --check: PASS

@Finesssee
Finesssee force-pushed the port/upstream-0.53-review branch from 1e1f6d6 to 581d943 Compare August 19, 2026 05:24
@Finesssee
Finesssee merged commit aaf918b into main Aug 19, 2026
1 check failed
@Finesssee
Finesssee deleted the port/upstream-0.53-review branch August 19, 2026 05:24
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