Repository navigation
Add a Grok collector for the agents usage panel - #7200
unleashed-nick wants to merge 5 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
Adds Grok usage and billing data to the agents panel.
Changes:
- Adds a Grok session collector with ACP billing support and caching.
- Adds Grok provider configuration, icons, and documentation.
- Adds scanner, token, billing, and error-path 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 no comments.
Show a summary per file
| File | Description |
|---|---|
bin/omarchy-agent-usage-grok |
Implements Grok usage and billing collection. |
test/shell.d/agent-usage-grok-scanner-test.sh |
Tests session scanning and billing responses. |
shell/plugins/agents/README.md |
Documents Grok collector behavior. |
shell/plugins/agents/manifest.json |
Enables Grok by default. |
shell/plugins/agents/assets/grok.svg |
Adds the dark-surface Grok mark. |
shell/plugins/agents/assets/grok-light.svg |
Adds the light-surface Grok mark. |
manual/17-ai.md |
Documents Grok panel support. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
Confirmed on a real install — this gap is still present. Environment
What I see A first-party Grok collector for the existing Agents panel would close this. Happy to test a branch if that helps. |
Setup already offers Grok as a default coding agent, but the bar widget only lights up for Claude, Codex, and Fireworks. Scan local sessions under $GROK_HOME/sessions so the existing panel can show Grok prompt and session counts. There is no xAI rate-limit API.
Grok writes billed tokens on updates.jsonl turn_completed rows, not events.jsonl. Scan that ledger for the panel charts, skip subagent sessions, and pull the SuperGrok weekly pool (and leftover prepaid credits) from grok agent stdio `_x.ai/billing`.
Replace the sparkle placeholder with the two-path glyph from grok.com/images/favicon.svg, matching Codex's dark/light SVG pair.
05424fb to
a796774
Compare
|
Thanks @knu2 - that's the gap this PR is meant to close, and 4.0.1-1 still doesn't ship Rebased onto current If you want to verify on 4.0.1 before it lands: sudo install -m 755 bin/omarchy-agent-usage-grok /usr/share/omarchy/bin/omarchy-agent-usage-grok
sudo install -m 755 bin/omarchy-agent-usage-grok /usr/bin/omarchy-agent-usage-grok
sudo install -m 644 shell/plugins/agents/assets/grok.svg \
/usr/share/omarchy/shell/plugins/agents/assets/grok.svg
sudo install -m 644 shell/plugins/agents/assets/grok-light.svg \
/usr/share/omarchy/shell/plugins/agents/assets/grok-light.svg
omarchy agent usage-update grok --force
ls ~/.local/state/omarchy/agents/usage/grok.jsonThen open the agents panel and hit |
|
Tried the branch on Omarchy Installed omarchy agent usage update grok --force
omarchy-shell omarchy.agents refresh
Thanks for the clear verify steps. |
|
I gave this code a try and it works and looks good. One thing I noticed, for daily usage you only scan the grok harness. The other tabs scan all harness' omarchy supports. You can see an example of this is PR #6902 |
|
Follow-up from verifying this branch on Omarchy Prepaid Credits is 100× too highThe collector and Grok Live ACP payload: "prepaidBalance": { "val": 488 },
"onDemandCap": { "val": 0 },
"onDemandUsed": { "val": 0 }
So ACP return max(0.0, amount / 100.0)Tests assume dollars
"prepaidBalance": {"val": 12.5},
"onDemandCap": {"val": 20},
"onDemandUsed": {"val": 5}…and expects Weekly Happy to re-test after a cents fix lands. |
|
Confirmed on Omarchy Environment
Collector from this PR Writing that JSON to This is the remaining gap: Grok is a first-party default agent, but |
ACP Money.val is cents. A live prepaidBalance of 488 was drawing as $488.00 instead of the $4.88 /usage shows. Local stats only walked ~/.grok/sessions. Merge pi, omp, and opencode rows on an xAI provider, the same way Claude and Codex do, and skip caching a scan that died mid-opencode-db. The scan cache now follows Codex: scanDate, reject a future mtime, and still emit a record when the cache dir is unwritable.
Clamp cache out of input with max(0, ...) so a messy ledger cannot overlap the four panel buckets. Count pi rows that only have totalTokens. Treat sign-in as expired only on 401/403 or real auth wording, not a stray "author". Drop --cache-seconds; the panel never passes it.
|
I tested this PR, and can confirm it works for me on Omarchy 4.0.2-1 with Grok CLI 1.0.13 (SuperGrok Heavy). Collector wrote a ready grok.json, the Agents panel showed the Grok tab, and the weekly meter matched my /usage. |
|
I pulled this PR and am running it locally, it matches my usage as well. Thanks for sharing this so I didn't have to re-do the work 🙏 |
|
Verified on a live install — this still closes the gap, and 4.0.3 still does not ship Environment
What I ran Result
Writing that JSON to Notes (not blockers)
This is still the right first-party collector. Happy to re-test after a rebase onto current |
|
Automated duplication check: this pull request looks similar to #9498, which covers the same Grok usage collector. I keep that one open and close this one to consolidate review. If you feel this is the wrong decision, please open the PR again with a note on the difference. |

Towards #7198.
Setup already offers Grok as a first-party default coding agent, but
omarchy.agentsnever lights up for it. Collectors are discovered from$OMARCHY_PATH/bin/omarchy-agent-usage-*; there was no Grok one.This adds
omarchy-agent-usage-grok. It prints the same record contract the panel already understands — no QML changes.$GROK_HOME/sessions(default~/.grok/sessions/<cwd>/<id>/). Grok writes billed usage onupdates.jsonlturn_completedrows (nestedusage, or flat token fields /event_name), notevents.jsonl/chat_history.jsonl. Cache read is split out of input so the four panel buckets stay mutually exclusive.session_kindvalues that start withsubagent(subagenton Grok 1.0.x,subagent_forkon older builds) are skipped so parent totals are not counted twice._x.ai/billing(grok agent --no-leader stdio), the same source/usageuses. A SuperGrok weekly (or monthly) pool becomeslimits[]. Leftover prepaid / on-demand credits become abalanceonly when the ledger is actually non-zero — a weekly pool with a $0 prepaid ledger is a meter, not$0.00 remaining. Plan label prefers the display string (SuperGrok Heavy);SuperGrokProstill rewrites toSuperGrok Pro.assets/grok.svg(and a-lighttwin) use the official Grok mark from grok.com/images/favicon.svg, the same glyph as the Omarchy icon font. The bar glyph still stands in without them.Verified on Grok 1.0.5 against live sessions: the panel gained a Grok tab with SuperGrok Heavy, a Weekly 16% meter, tokens by day, and tokens by model (
grok-4.6-build).Tests
test/shell.d/agent-usage-grok-scanner-test.sh— nested and flat turn ledgers, cache split, prompt_id dedupe, subagent skip, empty install, weekly/monthly mapping, zero prepaid omit, leftover credits, missing percent, expired auth, mise/ACP noise.Manual
manual/17-ai.mdnow lists Grok with the other first-party collectors and notes the SuperGrok weekly pool plus local token stats.