You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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)
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.
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.
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.
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: 8
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
The title is a short imperative summary that accurately describes moving Codex cost CLI modes behind a provider extension.
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Provider Data Stays Siloed
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
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
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
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Refactor with no intended behavior change. It moves the Codex-only modes of
codexbar costout of the sharedrust/src/cli/cost.rsand 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>(BeforePeriodorBoundedWindow)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_CLIinrust/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 literalcodex(so theopenaialias is still rejected), and host mode still requires the resolved providers to be exactly[Codex].Dispatch in
cost.rs: build aCostCliInvocation, ask each registered extension for an exclusive mode, run aBeforePeriodmode before settings load (as before), otherwise resolve the period and run aBoundedWindowmode 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 fieldsspend_contract,historyCoverageIsEstablishedandknownZero.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: cleancargo clippy --manifest-path rust/Cargo.toml --all-targets -- -D warnings: passcargo clippy --manifest-path apps/desktop-tauri/src-tauri/Cargo.toml --all-targets -- -D warnings: passcargo test --manifest-path rust/Cargo.toml --lib -- cost codex_costs core::: 926 passedNo UI change. No CHANGELOG entry, since user-visible behavior is unchanged.
Summary by CodeRabbit