feat(agents): add Grok usage collector - #10074
Open
pmcclelland wants to merge 1 commit into
Open
Conversation
Ship omarchy-agent-usage-grok so the agents panel can show SuperGrok weekly credits and local Grok CLI token stats. Sessions under $GROK_HOME are scanned for turn_completed usage; limits come from the same billing endpoint /usage uses.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Grok is already a first-party default coding agent (
omarchy default agent grok), but the agents bar widget never appears for it. Collectors are discovered from$OMARCHY_PATH/bin/omarchy-agent-usage-*; Claude, Codex, and Fireworks ship one, Grok did not. On a machine that only uses Grok the panel stays hidden, even when there are weeks of local session history and a live SuperGrok weekly allowance.The panel itself does not need QML changes. It already watches whatever JSON records land in
~/.local/state/omarchy/agents/usage/. This PR adds the missing collector plus the optional mark and docs so that file appears.What it shows
Once
omarchy-agent-usage-grokhas writtengrok.json, the existing panel grows a Grok tab with:Verified on a live SuperGrok Plus session: Weekly 5% (reset in ~5d 15h), Grok Build 4%, local history for
grok-4.6.How the numbers are made
Local stats come from
$GROK_HOME/sessions(default~/.grok/sessions/<cwd>/<id>/updates.jsonl). Grok records billed usage onturn_completedrows, not onevents.jsonl/chat_history.jsonl.prompt_idis one prompt; duplicates in the same file are ignoredsession_kind/session_relationshipvalues that start withsubagentare skipped so parent totals are not counted twice-buildmodel suffix is stripped for display (grok-4.6-build→ Grok 4.6)Limits come from the same billing endpoint Grok's own
/usagecommand uses, authenticated with the OAuth session in~/.grok/auth.json:GET https://cli-chat-proxy.grok.com/v1/billing?format=credits→creditUsagePercent(weekly pool) andproductUsage[GrokBuild].usagePercentGET https://cli-chat-proxy.grok.com/v1/user?include=subscription→subscriptionTier(SuperGrokPlus→ SuperGrok Plus)https://auth.x.ai/oauth2/tokenand written back toauth.jsonat0600Without a signed-in Grok CLI the collector still prints a valid hidden-by-default record (
ready: false,Waiting for auth) so the update runner has something to write.Files
bin/omarchy-agent-usage-grokomarchy agent usage-updatealready globsomarchy-agent-usage-*)shell/plugins/agents/assets/grok.svg(+-lighttwin)shell/plugins/agents/manifest.jsongrokby default and mention it in the widget descriptionshell/plugins/agents/README.mdGROK_HOME, and providers examplemanual/17-ai.mdtest/shell.d/agent-usage-grok-scanner-test.shTest plan
bash test/shell.d/agent-usage-grok-scanner-test.sh— 8 assertions: empty record without auth, one-count perprompt_id, subagent skip, exclusive token buckets, SuperGrok Plus label, weekly5→0.05meter, Grok Build slice only (chat/imagine ignored)./test/allon CIRelated: #7200, #6902, #9924, #9840.