Repository navigation
Add a Grok usage collector for the agents panel - #13219
d4dgpt-netizen wants to merge 2 commits into
Conversation
Grok is a first-class default agent but never appeared in the bar widget, which only draws collectors that write a usage record. Scan $GROK_HOME/sessions usage.json files (default ~/.grok/sessions) into the same JSON contract Claude and Codex already use, and ship the Grok mark so the panel can render a tab. Grok CLI does not publish a rate-limit endpoint, so the record carries local token history without a limits list.
SuperGrok is a shared weekly pool across Chat, Imagine, Voice, and Build, not a 5-hour session window. Probe the same CLI billing endpoint the Grok TUI uses, and draw that week plus Grok Build's share of it in the same limits rows Claude and Codex already use.
Automated AI review
Verified: the local-stats collector fits the agents panel contract. Grok CLI references below are to its public source, xai-org/grok-build at Expired sign-in: the collector redeems the CLI's refresh token and discards the replacementWhen the saved access token has expired ( Synthetic probe (fake IdP that rotates refresh tokens and rejects reuse, no real endpoint contacted): Grok's source treats these tokens as single-use:
Impact: a user who leaves Grok closed past one access-token lifetime can find the Grok CLI signed out after the collector's next run. It then keeps re-presenting a spent token on every refresh and panel open. The collector is enabled by default. This consequence is inferred from Grok's source; the live IdP was not tested, and the token lifetime is not in source. Smaller problems on the same path:
Suggested change: drop Forked and subagent sessions are counted twice
The fork case follows Grok's copy code directly. The subagent case is modelled on Grok's source, not observed on a real Impact: inflated prompt, session, per-day and per-model counts, which also carry into synced snapshots. Suggested change: skip session directories whose Credit usage below 1 % is read as a fractionGrok defines
Impact: every weekly period starts at zero, so a nearly unused pool can show as almost exhausted and raise the bar alarm early in the week. Related gaps in the same parser:
Suggested change: always divide Cache-write tokens are counted twiceGrok's Impact: inflated token totals for Grok sessions on Anthropic Messages backends, the only backends that report cache writes. Suggested change: subtract cache writes as well as cache reads from Other notesOpen question, Build meter spelling: the collector matches only Smaller notes:
Related open PRs
Verified: Grok's nanosecond RFC 3339 timestamps are attributed to the right local day, malformed Review informationTest scope: Source review of the PR head AI process: Opus 5.5 Medium coordination and synthesis, Opus 5.5 Xhigh technical review and final fact check, GPT 6 Sol Xhigh search for related issues, Opus 5.5 Medium editorial check. Opt out: To stop receiving these reviews, reply to this comment saying so. |
|
Thanks! Grok's section in the agents panel landed with #13992 (plan, weekly credits meter, accounts, sessions). Closing this in favor of it. |
Why
Grok is already a first-class Omarchy default agent (
omarchy default agent grok, Super+Shift+Ctrl+A, the agents menu). The top-bar agents widget never showed it, because that panel only draws usage records written byomarchy-agent-usage-<agent>collectors, and Omarchy shipped collectors for Claude, Codex, and Fireworks only.What
omarchy-agent-usage-grok, which scans$GROK_HOME/sessions/**/usage.json(default~/.grok/sessions) into the same display-ready JSON contract the panel already watches.turnsarray), keep input/cache/output buckets mutually exclusive, honorGROK_HOME, and cache like the Codex collector (--force/--limits-only).assets/grok.svgandassets/grok-light.svgfrom the official Grok mark.manual/17-ai.md.Grok CLI does not publish a rate-limit endpoint the way Claude Code and Codex do, so the tab shows local token history (today, last week, by model) without a limits meter.
Test plan
bash test/shell.d/agent-usage-grok-scanner-test.sh~/.grok/sessionsproduced a ready record; writing it to~/.local/state/omarchy/agents/usage/grok.jsonmade a Grok chip appear in the agents panel next to Claude Code and Codex.