Skip to content

Add a Grok usage collector - #7393

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

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

Conversation

@fuziontech

Copy link
Copy Markdown

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. session_kind: subagent_fork sessions are skipped so parent totals are not counted twice.
  • Limits and plan come from the same cli-chat-proxy endpoints Grok's /usage command uses (/v1/billing?format=credits and /v1/user?include=subscription). 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 Plus login (Grok 1.0.5): the panel gained a Grok tab with SuperGrok Plus, a Weekly 31% meter, tokens by day, and tokens by model (grok-4.6-build). creditUsagePercent is present on this version.

Related collectors already in review: #6902, #6485, #7200, #6477. Happy to close this 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

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

omarchy-agent-usage-grok prints the shared agents-panel record from
~/.grok/sessions turn_completed usage and the cli-chat-proxy billing
endpoint grok's /usage command already calls. SuperGrok weekly
allowance is a limit; a zero prepaid ledger is omitted rather than
shown as $0.00. The panel needs no QML change.
Copilot AI balanced review requested due to automatic review settings August 18, 2026 15:33

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

This PR adds a new omarchy-agent-usage-grok collector so the existing omarchy.agents bar panel grows a Grok tab, matching how Claude, Codex, and Fireworks already work. No QML changes are needed because the panel renders any record dropped into ~/.local/state/omarchy/agents/usage/ by omarchy-agent-usage-update (which globs omarchy-agent-usage-*). Local token stats are scanned from turn_completed events in $GROK_HOME/sessions/*/updates.jsonl, while plan/limits/balance come from Grok's cli-chat-proxy billing and user endpoints using the OIDC token in ~/.grok/auth.json (read-only). Subagent-fork sessions are skipped to avoid double counting, and a SuperGrok weekly pool with a zero prepaid ledger is surfaced as a limit rather than a $0.00 balance.

Changes:

  • New Python collector bin/omarchy-agent-usage-grok (local scan + cache/lock, auth token read, weekly limit and prepaid/on-demand balance mapping, plan labeling, error/expiry handling).
  • Panel wiring: enables grok by default in manifest.json, ships assets/grok.svg and light twin, and documents the provider in the plugin README and user manual.
  • Extensive shell test test/shell.d/agent-usage-grok-scanner-test.sh covering token math, dedupe, fork skip, GROK_HOME, auth selection, expiry, cache reuse, and HTTP/transport error handling.

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 no comments.

Show a summary per file
File Description
bin/omarchy-agent-usage-grok New collector that scans local Grok sessions and probes billing/user endpoints to emit one display-ready JSON usage record.
test/shell.d/agent-usage-grok-scanner-test.sh New test suite validating token accounting, dedupe/fork handling, auth, caching, and limit/error paths.
shell/plugins/agents/manifest.json Enables grok as a default provider and updates the panel description.
shell/plugins/agents/README.md Documents the Grok source, GROK_HOME/auth.json behavior, and default provider config.
shell/plugins/agents/assets/grok.svg Grok brand mark for dark surfaces.
shell/plugins/agents/assets/grok-light.svg Grok brand mark for light surfaces.
manual/17-ai.md Lists Grok among the out-of-the-box supported agents.

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

@spencerbull

Copy link
Copy Markdown
Contributor

Closing in favor of #6485, which implements the same Grok usage collector and has the active maintainer discussion, post-refactor implementation, and broader validation history. Please carry over any unique test coverage or edge cases from this PR if #6485 does not already cover them.

@spencerbull spencerbull closed this Sep 4, 2026
Vladkarok added a commit to Vladkarok/omarchy-fixes that referenced this pull request Nov 10, 2026
Omarchy ships collectors for Claude, Codex, and Fireworks only, and the
seven upstream PRs adding Grok are all still open. Vendor the collector
from omacom/omarchy#7393 — the one variant that touches no QML — and
drive it from a systemd user timer, since omarchy-agent-usage-update
only globs the package-owned $OMARCHY_PATH/bin and cannot pick it up.
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.

3 participants