Skip to content

Include Grok in CLI and serve local cost scans (SBS-934) - #325

Merged
tsouth89 merged 2 commits into
mainfrom
fix/sbs-934-cost-include-grok
Aug 18, 2026
Merged

Include Grok in CLI and serve local cost scans (SBS-934)#325
tsouth89 merged 2 commits into
mainfrom
fix/sbs-934-cost-include-grok

Conversation

@tsouth89

@tsouth89 tsouth89 commented Aug 17, 2026

Copy link
Copy Markdown
Owner

Summary

  • codexbar cost and serve GET /cost now scan Grok the same way Charts already does (~/.grok/sessions, costUsdTicks).
  • Default Enabled-providers cost (claude, codex, cursor, grok) no longer lists Grok as unsupported or says only Codex and Claude have local logs.
  • The same Codex/Claude-only list lived in codexbar mcp get_spend. That path now uses the shared CostScanner::supports_local_scan / scan_provider so the three surfaces cannot drift again. Cursor, Gemini, and Copilot stay unsupported.

A user who runs codexbar cost or GET /cost on a machine with Grok sessions now sees Grok totals (or "No usage data found"), not "Local cost scanning not available" / "Only Codex and Claude have local logs". codexbar cost -p grok and GET /cost?provider=grok are the same.

Test plan

  • cargo fmt --all --check --manifest-path rust/Cargo.toml — clean
  • New tests (8) pass:
    • cli::cost::tests::grok_cost_is_supported_and_does_not_claim_codex_claude_only
    • cli::cost::tests::grok_cost_reads_session_ticks_when_sessions_exist
    • cli::cost::tests::default_enabled_cost_marks_grok_supported
    • cost_scanner::tests::scan_provider_supports_grok_and_not_cursor
    • cli::serve::tests::cost_payloads_mark_grok_supported_and_cursor_not
    • cli::mcp::tests::list_providers_and_spend_include_grok
    • cli::mcp::tests::spend_rejects_unsupported_provider
    • cli::tests::cost_subcommand_help_mentions_grok
  • Fail-without-fix: reverted only supports_local_scan / scan_provider Grok arms. All 6 wiring tests failed (Grok supported: false / supports_local_scan false). Restored.
  • cargo test --manifest-path rust/Cargo.toml — 1007 passed; 6 pre-existing Linux failures (Windows \ path fixtures). CI rust-shared is windows-latest.
  • cargo clippy --manifest-path rust/Cargo.toml --all-targets -- -D warnings — two pre-existing Linux-only unused/dead_code items in secure_file.rs / updater.rs (Windows-only). Not in this diff.

Fail-without-fix

assertion failed: CostScanner::supports_local_scan(ProviderId::Grok)
assertion failed: grok must be a local-log scanner
assertion failed: results[0].supported
assertion `left == right` failed  left: Bool(false)  right: true   # serve + mcp
assertion failed: grok.supported   # default enabled set

Pattern sweep

rg -n "Only Codex and Claude|Claude and Codex|Claude \+ Codex|Codex/Claude|COST_SUPPORTED|Local cost scanning" --glob '!target/**'

Fixed this ticket:

  • rust/src/cli/cost.rs match + "Only Codex and Claude have local logs" + clap help
  • rust/src/cli/serve.rs cost_response
  • rust/src/cli/mcp.rs COST_SUPPORTED / get_spend / list_providers / instructions
  • rust/src/cli/mod.rs cost about text
  • docs/CLI.md cost section

Left alone, with why:

  • Spend-anomaly alert still reads Codex + Claude logs only. 1.5.33 shipped that as a product choice ("spend on other providers is in neither today's total nor the baseline"), not a CLI cost surface.
  • statusline --no-cost reads the widget snapshot, not local logs.
  • apps/desktop-tauri/src/surfaces/ChartsPanel.tsx still says "Codex/Claude also scan local transcripts". Charts already includes Grok; comment only. Not CLI.
  • Historical CHANGELOG / HANDOFF / settings session-discovery wording.

What this makes more likely

Default codexbar cost, GET /cost, and MCP get_spend now walk ~/.grok/sessions on every run. A bug in scan_grok_report is no longer Charts-only. Grok session trees are small relative to Codex/Claude JSONL; the extra pass is the same one Charts already pays.

Gaps

  • Did not run the desktop/Tauri test job (no UI change).
  • Full rust suite and clippy -D warnings are red on this Linux box for pre-existing Windows-path / Windows-only items. Required CI job is windows-latest.
  • Did not hit a live codexbar serve HTTP socket; /cost is covered by cost_payloads unit tests.
  • Did not add Grok to the spend-anomaly baseline (see sweep).

Closes nothing on GitHub. Linear: SBS-934. Not merged.

Note

Add Grok support to codexbar cost CLI, MCP tools, and /cost HTTP endpoint

  • Adds CostScanner::scan_provider, scan_grok, and supports_local_scan methods to centralize provider dispatch and expose a single source of truth for which providers have local logs.
  • Updates the cost CLI command, MCP get_spend/list_providers tools, and the GET /cost serve handler to include Grok alongside Codex and Claude — replacing hardcoded two-provider lists with dynamic lookups via CostScanner.
  • Updates unsupported-provider hint text to say "Only Codex, Claude, and Grok have local logs" everywhere it appears.

Macroscope summarized 9b6d582.

CostScanner and Charts already read ~/.grok/sessions; default cost and /cost still treated Grok as unsupported.
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
ceiling 9b6d582 Commit Preview URL

Branch Preview URL
Aug 18 2026, 02:44 AM

@coderabbitai

coderabbitai Bot commented Aug 17, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@tsouth89, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 38 seconds

Limit details: You’ve used all 1 included review currently available under your plan.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 4dd53a06-d2f6-4869-bb16-4cfbdf44cd0e

📥 Commits

Reviewing files that changed from the base of the PR and between 6303cb9 and 9b6d582.

📒 Files selected for processing (7)
  • CHANGELOG.md
  • docs/CLI.md
  • rust/src/cli/cost.rs
  • rust/src/cli/mcp.rs
  • rust/src/cli/mod.rs
  • rust/src/cli/serve.rs
  • rust/src/cost_scanner.rs

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.

@github-actions

Copy link
Copy Markdown

Automated review

Found 3 issues:

  1. Grok cost text labels effort as Codex

    rust/src/cli/cost.rs:229 · disposition: fix-if-quick · confidence: high · severity: medium · quick win

    collect_results now marks Grok supported, so print_text_output takes the data branch. add_grok_record_to_summary always writes a by_effort_tokens bucket (the session effort, or "unknown"), so any Grok row with sessions hits the printer that still hardcodes "Codex effort:". A default codexbar cost (enabled set includes grok) therefore attributes Grok reasoning effort to Codex.

    Prompt for AI agents

    In rust/src/cli/cost.rs around line 229: Print "Effort:" or gate that block on result.provider == "codex". Add a test that formats a Grok CostResult with by_effort_tokens and asserts the text does not contain "Codex effort". Verify against the current code first; if no longer valid, skip with a brief reason. Keep the change minimal.

  2. Grok --days uses a rolling UTC cutoff, not the CLI calendar window

    rust/src/cost_scanner.rs:780 · disposition: follow-up · confidence: high · severity: medium

    scan_grok returns scan_grok_report(..., self.days).thirty_days. That report drops records older than Utc::now() minus Duration::days(N) (N times 24h), then fills only local calendar buckets. scan_codex and scan_claude on the same codexbar cost --days N use an inclusive local calendar from midnight (codex_period_start). Shortly after midnight, codexbar cost --days 1 -p grok can increment sessions_count for a yesterday 23:00 session (inside the 24h cutoff) while omitting its dollars (yesterday is not in the 1-day bucket), and that total will not match Claude or Codex "today" on the same command.

    Prompt for AI agents

    In rust/src/cost_scanner.rs around line 780: Point scan_grok_report's cutoff at local_day_start_utc(codex_period_start(today, days)), matching Claude. Add a test with a record at local yesterday 23:00 and CostScanner::new(1) after midnight, and assert Grok include/exclude matches scan_codex. Check Charts' today card before landing, because it shares this scanner. Verify against the current code first; if no longer valid, skip with a brief reason. Keep the change minimal.

  3. "both" provider alias still means codex+claude, not including grok

    rust/src/cli/cost.rs:14 · disposition: advisory · confidence: medium · severity: low · quick win

    CostArgs help now lists "codex, claude, grok, cursor, gemini, copilot, all, both" but ProviderSelection handling for "both" is unchanged (historically codex+claude). A user passing --provider both will not get Grok costs while --provider all will, making the alias inconsistent with the new supported set and the help text does not explain the difference.

    Prompt for AI agents

    In rust/src/cli/cost.rs around line 14: Update ProviderSelection so "both" includes grok or deprecate "both" and document that it is codex+claude only; add a test for ProviderSelection::from_str("both"). Verify against the current code first; if no longer valid, skip with a brief reason. Keep the change minimal.

For coding agents: fix BLOCK and FIX IF QUICK findings now; everything else is tracked or informational; never exceed one CodeRev fix round per PR.

Advisory. Findings generated by grok-subscription and muse-spark-1.2-contributor, each filtered through a 3-vote refutation panel with the changed code in evidence.

@tsouth89
tsouth89 merged commit c7a016f into main Aug 18, 2026
10 of 12 checks passed
@tsouth89
tsouth89 deleted the fix/sbs-934-cost-include-grok branch August 18, 2026 03:04
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