Skip to content

Add a Grok usage collector for the agents panel - #7784

Closed
shawnyeager wants to merge 1 commit into
omacom:quattrofrom
shawnyeager:add-grok-agent-usage
Closed

shawnyeager wants to merge 1 commit into
omacom:quattrofrom
shawnyeager:add-grok-agent-usage

Conversation

@shawnyeager

Copy link
Copy Markdown
Contributor

What

Adds omarchy-agent-usage-grok so the existing omarchy.agents panel grows a Grok tab the same way it already does for Claude, Codex, and Fireworks. No QML change: the panel draws any record that lands in ~/.local/state/omarchy/agents/usage/.

How

  • Local stats come from documented Grok sessions under $GROK_HOME (default ~/.grok). Each turn_completed event in updates.jsonl is one prompt. Cache reads are split out of inputTokens so the four panel buckets stay mutually exclusive.
  • Subagent sessions are skipped. Grok 1.0.x writes session_kind: subagent; older builds used subagent_fork. Parent turn_completed already includes finished child spend, so counting the child file would double tokens and invent extra prompts.
  • Turn shapes that some 1.0.x builds emit are also counted: event_name: turn_completed, and a flat token ledger on the update object itself (no nested usage).
  • Limits and plan come from the same cli-chat-proxy endpoints Grok's /usage command uses (/v1/billing?format=credits and /v1/settings). The live product string subscription_tier_display is preferred (SuperGrok Heavy here); SuperGrokPro from /v1/user is the fallback. The collector only reads the OIDC token already stored in ~/.grok/auth.json. It never writes credentials and does not refresh them — that stays with grok login.
  • A SuperGrok weekly pool with a zero prepaid ledger is reported as a limit, not $0.00 remaining. Prepaid / leftover on-demand credits still become a balance when the billing payload actually has them.
  • Ships assets/grok.svg plus a light-surface twin, and enables grok in the widget defaults.

Verified on a live SuperGrok Heavy login (Grok 1.0.5): the collector printed a ready record with SuperGrok Heavy, a Weekly 15% meter, 548 prompts across 54 parent sessions, tokens by day, and tokens by model (grok-4.5-build, grok-4.6-build).

Related collectors already in review: #6902, #6485, #7393, #7200, #6477. This one is the 1.0.5 session kind (subagent, not only subagent_fork) plus subscription_tier_display. Happy to close in favor of whichever lands.

Tests

./test/shell.d/agent-usage-grok-scanner-test.sh
./test/shell.d/agent-usage-update-test.sh
./test/shell.d/agents-panel-test.sh
./bin/omarchy commands --check

Covers empty/unauthenticated records, per-turn summing and dedupe, subagent and subagent_fork skip, GROK_HOME, weekly/on-demand/balance mapping, SuperGrok Heavy labeling, SuperGrokPro fallback, a zero SuperGrok prepaid ledger, expired tokens, --limits-only cache reuse, event_name/flat ledger, and transport vs HTTP error handling.

The panel already draws any record that lands in
~/.local/state/omarchy/agents/usage/. This ships the missing
omarchy-agent-usage-grok collector, brand marks, and tests.

Local stats come from documented Grok sessions under $GROK_HOME.
Each turn_completed event is one prompt. Cache reads are split
out of input so the four panel buckets stay exclusive. Sessions
labeled subagent or subagent_fork are skipped so parent totals
are not counted twice.

Limits and the plan label come from the same cli-chat-proxy
endpoints Grok's /usage command uses. The weekly SuperGrok pool
is a limit; a zero prepaid ledger is omitted rather than shown
as $0.00 remaining. The live product string
subscription_tier_display is preferred over rewriting
SuperGrokPro.
Copilot AI balanced review requested due to automatic review settings August 22, 2026 15:29

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 usage, limits, and plan data to the existing agents panel.

Changes:

  • Adds the Grok collector with session scanning, caching, authentication, and billing support.
  • Enables Grok by default with dark/light icons.
  • Adds documentation and comprehensive scanner tests.

Tip

If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or run gh pr ready --undo.
Click "Ready for review" or run gh pr ready to reengage.

Reviewed changes

Copilot reviewed 4 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
bin/omarchy-agent-usage-grok Implements Grok usage collection.
test/shell.d/agent-usage-grok-scanner-test.sh Tests scanner, billing, auth, and failures.
shell/plugins/agents/manifest.json Enables Grok by default.
shell/plugins/agents/README.md Documents Grok integration.
shell/plugins/agents/assets/grok.svg Adds the dark-surface icon.
shell/plugins/agents/assets/grok-light.svg Adds the light-surface icon.
manual/17-ai.md Lists Grok as supported.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +11 to +12
today="$(date +%Y-%m-%d)"
timestamp="${today}T12:00:00Z"
@shawnyeager

Copy link
Copy Markdown
Contributor Author

Closing in favor of #6902, which already has the collector, community verification, and an author taking patches onto the branch.

The one extra this PR had — skip Grok 1.0.x session_kind: subagent, not only subagent_fork — is offered there instead: https://github.com/csfh/omarchy/pull/3

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.

2 participants