Skip to content

feat(grok): add Grok Build CLI usage adapter - #1520

Closed
LeeShunEE wants to merge 1 commit into
ccusage:mainfrom
LeeShunEE:feature/grok-build-usage-adapter
Closed

feat(grok): add Grok Build CLI usage adapter#1520
LeeShunEE wants to merge 1 commit into
ccusage:mainfrom
LeeShunEE:feature/grok-build-usage-adapter

Conversation

@LeeShunEE

@LeeShunEE LeeShunEE commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Summary

Add first-class Grok Build CLI usage reporting to ccusage.

Closes #1513

What changed

  • New Rust adapter ccusage-adapter-grok reads completed turns from $GROK_HOME/sessions/**/updates.jsonl (sessionUpdate == "turn_completed" + usage / modelUsage)
  • Root resolution: official GROK_HOME, then ~/.grok (no ccusage-only path override)
  • Token mapping: uncached input = inputTokens - cachedReadTokens, full outputTokens as output, reasoningTokens in extra total only (not double-billed), ignore costUsdTicks for invoice USD
  • Wire ccusage grok daily|monthly|session, config shared options, and all-agent / bare ccusage loaders
  • Session reports use SessionAccumulator so first_activity, last_activity, and project_path are present in tables and JSON (aligned with qwen/opencode/antigravity)
  • Docs under docs/guide/grok/

Why

Grok Build writes per-model token usage on completed turns, but ccusage did not load it, so unified totals were incomplete for Grok users.

Rebase / conflicts

Merged current main (including Antigravity #1544 and related docs/wiring) into feature/grok-build-usage-adapter. Conflicts were resolved so both Grok and Antigravity remain wired in:

  • agent inventories (README / guides / env / config namespaces)
  • BUILT_IN_AGENT_NAMES, unified loader, CLI parser, last_window, config schema
  • source-support Q&A (Grok and Antigravity documented as supported)

Branch tip: a3d4a2a. Merge-base with main is current main (no remaining conflicts).

Testing

Raised Grok adapter coverage to roughly the same bar as the Antigravity adapter (#1544): fixture-backed, behavior-named tests; synthesized updates.jsonl (no real session trees committed).

Coverage layers

Layer Module Examples
Path discovery paths.rs updates.jsonl only, nested multi-project trees, blank GROK_HOME fallback, non-directory override
Parser / mapping parser.rs uncached vs cache split, reasoning-only rows, top-level usage fallback, timestamp preference (agentTimestampMs vs envelope seconds), summary vs line session id, URL-decoded project path, missing pricing, ignore costUsdTicks, in-file dedupe
Loader loader.rs cross-session event dedupe, corrupt sibling isolation, timestamp sort, has_data negative path
Report report.rs cache read columns, session activity bounds + projectPath in JSON
Smoke lib.rs #[ignore] real $GROK_HOME load

Also: CLI parser (grok help / rejects --grok-path), config schema (no grokPath), unified all-agent tests that exercise GROK_HOME.

Local results (after merge with main)

cargo test -p ccusage-adapter-grok --lib
  -> 39 passed; 0 failed; 1 ignored

cargo test -p ccusage-cli-parser --lib
  -> 75 passed

cargo test -p ccusage-config --lib
  -> 26 passed

cargo test -p ccusage-adapter-antigravity --lib
  -> 34 passed

cargo test -p ccusage-adapter-all --lib
  -> 36 passed

Related commits on this branch after the original adapter:

  • 237d30b fix(grok): report session activity and project path
  • 97777cf test(grok): expand adapter coverage to antigravity-level
  • a3d4a2a merge upstream/main (conflict resolution)

Parse completed Grok Build turns, map token usage and LiteLLM pricing, and expose focused and unified reports. Discover data from non-empty GROK_HOME or ~/.grok, add schema and CLI integration, and document the source.
Copilot AI review requested due to automatic review settings July 28, 2026 12:05
@github-actions

Copy link
Copy Markdown
Contributor

This PR was auto-closed. Only contributors approved with lgtm can open PRs. Open an issue first.

Maintainers review auto-closed issues and reopen worthwhile ones. Issues that do not meet the quality bar in CONTRIBUTING.md may not be reopened or receive a reply.

If a maintainer replies lgtmi, your future issues will stay open. If a maintainer replies lgtm, your future issues and PRs will stay open.

See CONTRIBUTING.md.

@github-actions github-actions Bot closed this Jul 28, 2026
@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 9299e16f-4312-484d-9712-c68ced3abe61

📥 Commits

Reviewing files that changed from the base of the PR and between b16676f and 1a448b4.

⛔ Files ignored due to path filters (4)
  • rust/Cargo.lock is excluded by !**/*.lock
  • rust/crates/ccusage-cli-parser/src/snapshots/ccusage_cli_parser__tests__root_help.snap is excluded by !**/*.snap
  • rust/crates/ccusage-cli-parser/src/snapshots/ccusage_cli_parser__tests__snapshots_representative_cli_parse_shapes.snap is excluded by !**/*.snap
  • rust/crates/ccusage-config/src/snapshots/ccusage_config__config_schema__tests__snapshots_schema_agent_specific_option_edges.snap is excluded by !**/*.snap
📒 Files selected for processing (35)
  • .agents/skills/agent-sources/SKILL.md
  • apps/ccusage/README.md
  • apps/ccusage/config-schema.json
  • docs/.vitepress/config.ts
  • docs/guide/grok/index.md
  • docs/guide/index.md
  • docs/guide/source-support-qa.md
  • docs/superpowers/specs/2026-07-28-grok-env-only-path-design.md
  • rust/Cargo.toml
  • rust/adapters/grok/Cargo.toml
  • rust/adapters/grok/README.md
  • rust/adapters/grok/src/lib.rs
  • rust/adapters/grok/src/loader.rs
  • rust/adapters/grok/src/parser.rs
  • rust/adapters/grok/src/paths.rs
  • rust/adapters/grok/src/report.rs
  • rust/crates/ccusage-adapter-all/Cargo.toml
  • rust/crates/ccusage-adapter-all/README.md
  • rust/crates/ccusage-adapter-all/src/lib.rs
  • rust/crates/ccusage-adapter-all/src/loader.rs
  • rust/crates/ccusage-adapter-all/src/report.rs
  • rust/crates/ccusage-adapter-all/src/tests.rs
  • rust/crates/ccusage-cli-parser/src/cli-commands.json
  • rust/crates/ccusage-cli-parser/src/parser.rs
  • rust/crates/ccusage-cli-parser/src/tests.rs
  • rust/crates/ccusage-cli/README.md
  • rust/crates/ccusage-cli/src/types.rs
  • rust/crates/ccusage-config/src/config.rs
  • rust/crates/ccusage-config/src/config_schema.rs
  • rust/crates/ccusage-core/src/lib.rs
  • rust/crates/ccusage/Cargo.toml
  • rust/crates/ccusage/README.md
  • rust/crates/ccusage/src/adapter/mod.rs
  • rust/crates/ccusage/src/cli/last_window.rs
  • rust/crates/ccusage/src/main.rs

📝 Walkthrough

Walkthrough

Adds first-class Grok Build CLI support through a Rust adapter that reads completed session turns, generates usage and cost reports, integrates with focused and unified CLI commands, adds Grok configuration, and documents data discovery and report behavior.

Changes

Grok usage reporting

Layer / File(s) Summary
Grok adapter implementation
rust/adapters/grok/..., rust/Cargo.toml
Adds session discovery, JSONL parsing, token normalization, deduplication, pricing, aggregation, JSON output, and tests.
CLI and configuration contracts
rust/crates/ccusage-cli-parser/..., rust/crates/ccusage-config/..., apps/ccusage/config-schema.json, rust/crates/ccusage-core/src/lib.rs
Adds grok daily, monthly, and session commands, Command::Grok, shared options, schema support, and parser/configuration tests.
Unified loading and execution wiring
rust/crates/ccusage-adapter-all/..., rust/crates/ccusage/..., rust/crates/ccusage-cli/README.md
Registers Grok in unified loading, detection, labels, date-window handling, main dispatch, adapter dependencies, and integration tests.
Documentation and path design
docs/..., apps/ccusage/README.md, .agents/skills/...
Documents Grok support, session paths, report semantics, configuration, troubleshooting, navigation, and env-only GROK_HOME resolution.

Estimated code review effort: 4 (Complex) | ~45 minutes

Possibly related PRs

Suggested reviewers: copilot

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@LeeShunEE

Copy link
Copy Markdown
Contributor Author

@ryoppippi
Grok Build CLI usage PR's here check the issue first. #1513

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes — adds a new Grok Build CLI adapter (ccusage-adapter-grok) that reads completed turns from ~/.grok/sessions/**/updates.jsonl, supporting ccusage grok daily|monthly|session and unified/all-agent reports.

  • New ccusage-adapter-grok crate — JSONL parser for turn_completed events with modelUsage breakdowns, token split (uncached = input − cache), pricing candidate lookup (strip -build, try xai//x-ai/ prefixes), intra- and cross-session dedup, and GROK_HOME~/.grok path resolution
  • CLI command wiringCommand::Grok variant dispatched through parse_basic_agent_command with STANDARD_AGENT_REPORTS; root help, parse shapes, and rejection test for the intentionally-unavailable --grok-path flag
  • Config & schemaGrokConfig / GrokCommandsConfig in config schema with shared options only; no grokPath property; schema snapshot updated
  • Unified reports integration — Grok at index 15 in BUILT_IN_AGENT_NAMES and AgentLoadSpec; agent_label("grok") and isolated-env guard; unified daily and session integration tests
  • Documentation — full Grok guide (docs/guide/grok/), VitePress nav, guide index table, source-support-qa update (from "not supported" to supported), README additions, and env-only path design spec

Pullfrog  | ⚠️ this action is pinned to a commit SHA, which freezes the cleanup step — switch to @v0 or keep the SHA fresh with Dependabot | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds Grok Build CLI as a first-class ccusage data source by introducing a new Rust adapter that reads turn_completed usage from Grok session logs, wires it into focused (ccusage grok ...) and unified reports, and documents the new source (including env-only path discovery via GROK_HOME~/.grok).

Changes:

  • Introduce new ccusage-adapter-grok crate (path discovery, JSONL parsing, token mapping, cost estimation via existing pricing).
  • Wire Grok into the main CLI command enum/parser, unified loader, config schema, and snapshot tests.
  • Add user documentation for Grok (guide page + nav + source-support Q&A updates) and update generated config schema outputs.

Reviewed changes

Copilot reviewed 38 out of 39 changed files in this pull request and generated no comments.

Show a summary per file
File Description
rust/crates/ccusage/src/main.rs Dispatch ccusage grok to the Grok adapter and extend adapter-exposure test list.
rust/crates/ccusage/src/cli/last_window.rs Include Grok in the commands that support --last window targeting.
rust/crates/ccusage/src/adapter/mod.rs Re-export the new ccusage_adapter_grok crate for the runtime.
rust/crates/ccusage/README.md Document the new ccusage-adapter-grok crate among adapter crates.
rust/crates/ccusage/Cargo.toml Add workspace dependency on ccusage-adapter-grok.
rust/crates/ccusage-core/src/lib.rs Add grok to the built-in agent name list used by unified reporting.
rust/crates/ccusage-config/src/snapshots/ccusage_config__config_schema__tests__snapshots_schema_agent_specific_option_edges.snap Update schema snapshot to include the Grok namespace defaults/shape.
rust/crates/ccusage-config/src/config.rs Add config test ensuring grok namespace supports shared report options.
rust/crates/ccusage-config/src/config_schema.rs Add GrokConfig types and schema tests (including “no grokPath” assertions).
rust/crates/ccusage-cli/src/types.rs Add Command::Grok to the shared command enum.
rust/crates/ccusage-cli/README.md Update adapter count note to reflect the new adapter.
rust/crates/ccusage-cli-parser/src/tests.rs Add Grok parse/help tests and representative parse-shape coverage.
rust/crates/ccusage-cli-parser/src/snapshots/ccusage_cli_parser__tests__snapshots_representative_cli_parse_shapes.snap Update parse-shape snapshot to include grok daily.
rust/crates/ccusage-cli-parser/src/snapshots/ccusage_cli_parser__tests__root_help.snap Update root help snapshot to list grok.
rust/crates/ccusage-cli-parser/src/parser.rs Add Grok command parsing and include Grok in agent command classification/display-name handling.
rust/crates/ccusage-cli-parser/src/cli-commands.json Add Grok command definitions and help wiring for daily/monthly/session.
rust/crates/ccusage-adapter-all/src/tests.rs Add unified-loader tests validating GROK_HOME discovery and token mapping.
rust/crates/ccusage-adapter-all/src/report.rs Provide a unified report label mapping for the grok agent.
rust/crates/ccusage-adapter-all/src/loader.rs Add Grok to unified loading specs and detection logic.
rust/crates/ccusage-adapter-all/src/lib.rs Re-export Grok adapter in the all-adapters crate.
rust/crates/ccusage-adapter-all/README.md Update documentation and adapter list for the new adapter dependency.
rust/crates/ccusage-adapter-all/Cargo.toml Add workspace dependency on ccusage-adapter-grok.
rust/Cargo.toml Register the new ccusage-adapter-grok workspace member path.
rust/Cargo.lock Lockfile updates for the newly added Grok adapter crate.
rust/adapters/grok/src/report.rs Implement Grok-focused report JSON and daily/monthly/session summarization.
rust/adapters/grok/src/paths.rs Implement env-only root resolution (GROK_HOME~/.grok) and session file discovery.
rust/adapters/grok/src/parser.rs Parse updates.jsonl turn_completed events, map tokens, handle per-model usage, and estimate costs.
rust/adapters/grok/src/loader.rs Load all Grok sessions (parallel read), apply global dedupe, and expose has_data().
rust/adapters/grok/src/lib.rs Wire adapter entrypoint (run) and shared report rendering behavior.
rust/adapters/grok/README.md Document Grok adapter ownership, data source, token mapping, and pricing behavior.
rust/adapters/grok/Cargo.toml Define the new adapter crate and its dependencies/dev-deps.
docs/superpowers/specs/2026-07-28-grok-env-only-path-design.md Capture design decision: env-only root discovery and no --grok-path/grokPath.
docs/guide/source-support-qa.md Update Q&A to reflect that Grok Build CLI is now supported and how it’s loaded.
docs/guide/index.md Add Grok Build CLI to the supported-sources overview and examples.
docs/guide/grok/index.md Add Grok Build CLI guide page (usage, discovery, config, troubleshooting).
docs/.vitepress/config.ts Add Grok Build CLI to the guide navigation.
apps/ccusage/README.md Include Grok in the app-level supported sources list and examples.
apps/ccusage/config-schema.json Update generated config schema JSON to include Grok configuration namespace.
.agents/skills/agent-sources/SKILL.md Add Grok Build CLI adapter reference in agent-sources skill documentation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@LeeShunEE

LeeShunEE commented Jul 30, 2026

Copy link
Copy Markdown
Contributor Author

@ryoppippi

Update after resolving conflicts with current main and strengthening Grok adapter tests (same bar as Antigravity #1544).

Branch

Test hardening (new)

  • Expanded fixture-backed coverage in paths / parser / loader / report
  • Session reports now carry first_activity / last_activity / project_path via SessionAccumulator
  • Tests synthesize updates.jsonl instead of committing real session trees

Local test results

Package Result
ccusage-adapter-grok 39 passed, 1 ignored (real-home smoke)
ccusage-cli-parser 75 passed
ccusage-config 26 passed
ccusage-adapter-antigravity 34 passed
ccusage-adapter-all 36 passed

Issue context: #1513

Would appreciate a reopen / lgtm when you have a chance - this PR was auto-closed by the contributor gate.

@LeeShunEE

Copy link
Copy Markdown
Contributor Author

@ryoppippi

Update: this PR branch is now synced to the latest main.

Sync status

Conflict resolution notes

Conflicts were mostly agent inventory lists (docs / loader / CLI / schema). Resolution keeps Grok Build CLI fully wired, and does not reintroduce Antigravity (which was reverted on main in #1569).

Grok remains documented as supported (Build CLI updates.jsonl); Antigravity stays in the unsupported Q&A section.

Local verification after sync

Package Result
ccusage-adapter-grok 39 passed, 1 ignored
ccusage-cli-parser 75 passed
ccusage-config 26 passed
ccusage-adapter-all 36 passed

Issue context: #1513

This PR was auto-closed by the contributor gate — would appreciate a reopen / lgtm when you have a chance.

@LeeShunEE

Copy link
Copy Markdown
Contributor Author

@ryoppippi

Branch is synced to the latest main, the full test suite passes, and I ran it on real Grok data on my machine.

Sync

  • Merged upstream/main (dc9018f — latest pricing snapshots, vitepress/actions dep bumps)
  • Merge commit: 147e05b, no conflicts (the 13 new upstream commits are pricing/deps only — nothing touched the adapter wiring)

Test results (local, Windows, after sync)

Package Result
ccusage-adapter-grok 39 passed, 0 failed, 1 ignored
ccusage-adapter-grok (real-home smoke) passed — loads my real ~/.grok/sessions data
ccusage-cli-parser 75 passed
ccusage-config 26 passed
ccusage-adapter-all 36 passed

Real run: ccusage grok daily on my machine (grok 0.2.112, Windows)

Date Input Output Cache Read Total Tokens Cost
2026-07-28 246,278 42,824 8,955,776 9,267,987 $3.90
2026-07-30 1,336,630 155,522 25,235,840 26,810,987 $12.67
2026-07-31 488,189 46,833 8,104,064 8,665,920 $4.18
2026-08-01 174,640 597 185,088 360,597 $0.46
2026-08-04 5,268,481 821,340 92,840,448 99,464,505 $49.11
2026-08-05 5,886,240 948,862 120,786,432 128,237,288 $60.88
Total 13,400,458 2,015,978 256,107,648 272,807,284 $131.20

Real turn_completed usage from ~/.grok/sessions/**/updates.jsonl, all on grok-4.5-build. The cache-read split and cost estimation work end-to-end on production data.

Branch: feature/grok-build-usage-adapter @ 147e05b

This PR and the issue were auto-closed by the contributor gate — could you take a look and reopen / lgtm when you have a chance?

Issue context: #1513

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.

Add Grok Build CLI usage reporting

2 participants