Skip to content

Move Codex cost CLI modes behind a provider extension - #906

Merged
Finesssee merged 3 commits into
mainfrom
refactor/cost-cli-provider
Oct 16, 2026
Merged

Finesssee merged 3 commits into
mainfrom
refactor/cost-cli-provider

Conversation

@Finesssee

@Finesssee Finesssee commented Oct 16, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Refactor with no intended behavior change. It moves the Codex-only modes of codexbar cost out of the shared rust/src/cli/cost.rs and behind a typed provider capability. This answers the CodeRabbit "Provider Data Stays Siloed" finding, which asked to remove the raw "codex" checks for identified-usage dispatch and project-report rendering from the shared CLI.

New interface (rust/src/core/cost_cli_extension.rs): CostCliExtension: Sync, every method defaulting to a no-op:

  • exclusive_mode(&CostCliInvocation) -> Option<CostCliMode> (BeforePeriod or BoundedWindow)
  • run_exclusive_mode(mode, invocation, window_days)
  • grouped_report(CostGrouping, &CostGroupedReportContext) -> Option<Vec<String>> (Project / Session)
  • coverage_notice(&CostSummary) -> Option<&'static str>

Registry (core/provider_factory.rs): cost_cli_extension_for(ProviderId) is an exhaustive match, so a new provider without an arm fails to compile. Only Codex registers one (CODEX_COST_CLI in rust/src/codex_costs/cost_cli.rs), which now owns identified-request mode, host mode, the project and session renderers and the partial-history notice. The original matching rules are kept: identified mode accepts only the literal codex (so the openai alias is still rejected), and host mode still requires the resolved providers to be exactly [Codex].

Dispatch in cost.rs: build a CostCliInvocation, ask each registered extension for an exclusive mode, run a BeforePeriod mode before settings load (as before), otherwise resolve the period and run a BoundedWindow mode with the resolved days. Text grouping order is unchanged; providers without an extension still get the existing "only available for Codex" lines.

Still in cost.rs (outside the flagged scope): the OpenCodex pricing refresh before JSON output and the JSON payload fields spend_contract, historyCoverageIsEstablished and knownZero.

Tests

  • First commit adds 24 golden tests (rust/src/cli/cost_golden_tests.rs) over text output, errors and exit codes, plus two test seams (run_with_settings, a buffered text renderer). They passed before the refactor and pass unchanged after it.
  • only_codex_registers_a_cost_cli_extension.

Commands run (after syncing with main)

  • cargo fmt --all -- --check: clean
  • cargo clippy --manifest-path rust/Cargo.toml --all-targets -- -D warnings: pass
  • cargo clippy --manifest-path apps/desktop-tauri/src-tauri/Cargo.toml --all-targets -- -D warnings: pass
  • cargo test --manifest-path rust/Cargo.toml --lib -- cost codex_costs core::: 926 passed

No UI change. No CHANGELOG entry, since user-visible behavior is unchanged.

Summary by CodeRabbit

  • New Features
    • Added Codex cost reports grouped by project or session, with cost and token totals and relevant project or activity details.
    • Project reports respect the setting to hide personal information.
  • Improvements
    • Cost reports can show notices when history coverage is partial, and report when history is unavailable.
    • Existing cost and token-history output remains available.

@coderabbitai

coderabbitai Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: nesszer/Win-CodexBar/.coderabbit.yaml
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 32aa5d9f-864d-48d9-8e73-97f9e63869d5
📥 Commits

Reviewing files that changed from the base of the PR and between 06fbaaf and 1876cd0.

📒 Files selected for processing: 7
  • rust/src/cli/cost.rs
  • rust/src/cli/cost_golden_tests.rs
  • rust/src/codex_costs.rs
  • rust/src/codex_costs/cost_cli.rs
  • rust/src/core/cost_cli_extension.rs
  • rust/src/core/mod.rs
  • rust/src/core/provider_factory.rs

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review.

📝 Walkthrough

The cost CLI now routes provider-specific exclusive modes and grouped reports through registered extensions. Codex provides identified-usage, host-summary, project, and conversation reports. Shared rendering buffers text output, and golden tests cover reports and argument validation.

Changes: Provider-extensible cost CLI

Layer / File(s) Summary
Cost CLI extension contract and registry
rust/src/core/cost_cli_extension.rs, rust/src/core/mod.rs, rust/src/core/provider_factory.rs
Adds extension types for exclusive modes and grouped reports, default extension hooks, and a registry that returns the Codex extension.
Codex cost reports
rust/src/codex_costs.rs, rust/src/codex_costs/cost_cli.rs
Adds Codex handling for identified and host-cost modes, project and conversation reports, and coverage notices.
Cost CLI dispatch and text rendering
rust/src/cli/cost.rs
Routes exclusive modes through extensions before or after period resolution. Renders buffered text and delegates grouped reports and coverage notices to extensions.
Cost report and argument validation tests
rust/src/cli/cost_golden_tests.rs
Adds golden output tests and checks argument validation for identified and host-summary modes.

Priority: ⬇️ Low

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Refactor

Sequence Diagram(s)

sequenceDiagram
  participant CLI as cost::run_with_settings
  participant Registry as cost_cli_extensions
  participant Codex as CodexCostCli
  participant Settings as settings_loader
  CLI->>Registry: enumerate registered cost CLI extensions
  CLI->>Codex: select exclusive mode from invocation
  alt BeforePeriod mode
    CLI->>Codex: run exclusive mode
  else BoundedWindow mode
    CLI->>Settings: load settings
    CLI->>Codex: run with resolved period
  end
Loading
Merge Risk: ⚪ Minimal · up to 1876c

The checked cost modes retain their provider routing and validation behavior. No issue identified here prevents merging after normal checks.

Pre-merge checks: Passed 8
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title is a short imperative summary that accurately describes moving Codex cost CLI modes behind a provider extension.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Provider Data Stays Siloed Passed PASS. The refactor keeps provider-specific output within the Codex cost extension. Shared cost.rs now resolves extensions generically with ProviderId::from_cli_name and passes each result only to …
Secrets Handled Safely Passed No changed code introduces credential handling or credential-bearing output. The diff adds no keyring, secure-file, auth-header, cookie, OAuth, API-key, or credential-file deletion/overwrite operation…
No Unapproved Dependencies Passed The pull request changes only Rust source files under rust/src. It does not modify any Cargo.toml or package.json, add an npm/yarn lockfile, or change a pinned pnpm packageManager version. No dependen…
Ui Changes Include Windows Proof Passed PASS: The exact PR range changes only Rust cost CLI, Codex cost, and core provider files. It changes no files under apps/desktop-tauri/src, rust/src/tray, or UI areas such as the float bar, settin…
Full details: Provider Data Stays Siloed

Explanation

PASS. The refactor keeps provider-specific output within the Codex cost extension. Shared cost.rs now resolves extensions generically with ProviderId::from_cli_name and passes each result only to its matching extension; it does not add a specific-provider branch. provider_factory.rs contains the new exhaustive Codex registration, which the check permits. Existing provider matches in cost.rs and JSON provider fields are unchanged. The Codex extension validates Codex-only modes and emits Codex project/session data only for Codex results.

Full details: Secrets Handled Safely

Explanation

No changed code introduces credential handling or credential-bearing output. The diff adds no keyring, secure-file, auth-header, cookie, OAuth, API-key, or credential-file deletion/overwrite operations. New text output contains usage counts, model names, session IDs, activity times, and project paths; test fixtures use temporary files and redact temporary paths and activity times. The moved Codex dispatch and report paths preserve existing behavior, and the added tests contain no credential literals.

Full details: No Unapproved Dependencies

Explanation

The pull request changes only Rust source files under rust/src. It does not modify any Cargo.toml or package.json, add an npm/yarn lockfile, or change a pinned pnpm packageManager version. No dependency approval is required.

Full details: Ui Changes Include Windows Proof

Explanation

PASS: The exact PR range changes only Rust cost CLI, Codex cost, and core provider files. It changes no files under apps/desktop-tauri/src, rust/src/tray, or UI areas such as the float bar, settings, or window chrome. The PR description also states that there is no UI change. Windows screenshots or a fresh-build proof note are therefore not required.

✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@Finesssee
Finesssee merged commit df0a136 into main Oct 16, 2026
4 checks passed
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