Skip to content

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

Closed
unleashed-nick wants to merge 5 commits into
omacom:quattrofrom
unleashed-nick:grok-agent-usage
Closed

unleashed-nick wants to merge 5 commits into
omacom:quattrofrom
unleashed-nick:grok-agent-usage

Conversation

@unleashed-nick

@unleashed-nick unleashed-nick commented Aug 17, 2026 •

Copy link
Copy Markdown

Towards #7198.

Setup already offers Grok as a first-party default coding agent, but omarchy.agents never 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.

  • Local token stats come from $GROK_HOME/sessions (default ~/.grok/sessions/<cwd>/<id>/). Grok writes billed usage on updates.jsonl turn_completed rows (nested usage, or flat token fields / event_name), not events.jsonl / chat_history.jsonl. Cache read is split out of input so the four panel buckets stay mutually exclusive. session_kind values that start with subagent (subagent on Grok 1.0.x, subagent_fork on older builds) are skipped so parent totals are not counted twice.
  • Limits and plan come from Grok ACP _x.ai/billing (grok agent --no-leader stdio), the same source /usage uses. A SuperGrok weekly (or monthly) pool becomes limits[]. Leftover prepaid / on-demand credits become a balance only 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); SuperGrokPro still rewrites to SuperGrok Pro.
  • assets/grok.svg (and a -light twin) 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).

grok-panel

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.md now lists Grok with the other first-party collectors and notes the SuperGrok weekly pool plus local token stats.

@benwyrosdick benwyrosdick mentioned this pull request Aug 18, 2026
5 of 6 tasks
Copilot AI balanced review requested due to automatic review settings August 22, 2026 21:03

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

@unleashed-nick

unleashed-nick commented Aug 22, 2026 •

Copy link
Copy Markdown
Author

grok-panel

@knu2

knu2 commented Aug 28, 2026

Copy link
Copy Markdown

Confirmed on a real install — this gap is still present.

Environment

  • Omarchy 4.0.1-1
  • Default coding agent: grok (omarchy default agent → grok)
  • Packaged collectors only: claude, codex, fireworks (no omarchy-agent-usage-grok)
  • No ~/.local/state/omarchy/agents/usage/grok.json

What I see
Stock omarchy.agents opens with “No AI coding subscriptions found,” even though Grok is the first-party default agent and I use it regularly. The panel stays empty because discovery is $OMARCHY_PATH/bin/omarchy-agent-usage-*, so Grok never gets a usage record.

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.
@unleashed-nick

unleashed-nick commented Aug 28, 2026 •

Copy link
Copy Markdown
Author

Thanks @knu2 - that's the gap this PR is meant to close, and 4.0.1-1 still doesn't ship omarchy-agent-usage-grok, so the panel can't grow a Grok tab. Collectors are discovered from $OMARCHY_PATH/bin/omarchy-agent-usage-*; without that script, grok.json never appears.

Rebased onto current quattro. Branch is grok-agent-usage on this PR.

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.json

Then open the agents panel and hit r. Happy to walk through any empty grok.json if it still doesn't light up.

@knu2

knu2 commented Aug 29, 2026

Copy link
Copy Markdown

Tried the branch on Omarchy 4.0.1-1 as suggested — works.

Installed omarchy-agent-usage-grok + the grok SVG assets, then:

omarchy agent usage update grok --force
omarchy-shell omarchy.agents refresh

~/.local/state/omarchy/agents/usage/grok.json appeared with ready: true, plan SuperGrok Plus, a Weekly 22% meter, balance, and local token/session stats. The Agents panel picks up the Grok tab after refresh.

Thanks for the clear verify steps.

@dbech

dbech commented Aug 29, 2026

Copy link
Copy Markdown

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

@knu2

knu2 commented Aug 30, 2026

Copy link
Copy Markdown

Follow-up from verifying this branch on Omarchy 4.0.1-1 with a live SuperGrok Plus account.

Prepaid Credits is 100× too high

The collector and Grok /usage both read _x.ai/billing, but they disagree on units.

Live ACP payload:

"prepaidBalance": { "val": 488 },
"onDemandCap": { "val": 0 },
"onDemandUsed": { "val": 0 }
  • Grok Build /usage shows $4.88 remaining (correct)
  • This collector’s money() treats val as dollars, so the Agents panel showed $488.00

So ACP Money.val appears to be integer cents, not dollars. Locally, dividing by 100 made the panel match /usage:

return max(0.0, amount / 100.0)

Tests assume dollars

test/shell.d/agent-usage-grok-scanner-test.sh currently uses dollar-scale fixtures, e.g.:

"prepaidBalance": {"val": 12.5},
"onDemandCap": {"val": 20},
"onDemandUsed": {"val": 5}

…and expects balance.remaining == 27.5. That won’t match live ACP once money() is fixed for cents (fixtures would need something like 488 → $4.88).

Weekly creditUsagePercent mapping looked fine (23–24% matched /usage).

Happy to re-test after a cents fix lands.

@aspinalljohn

Copy link
Copy Markdown

Confirmed on Omarchy 4.0.1-2 — the packaged agents panel still has no Grok collector.

Environment

  • Omarchy 4.0.1-2
  • Grok CLI 1.0.13
  • Packaged collectors only: claude, codex, fireworks (no omarchy-agent-usage-grok)
  • Grok is installed and in regular use; Claude and Codex already appear in the agents panel

Collector from this PR
Ran bin/omarchy-agent-usage-grok --force from this branch against live ~/.grok/sessions. It printed a ready: true record with plan SuperGrok Heavy, a Weekly 12% meter from _x.ai/billing, and local token/session stats from updates.jsonl turn_completed rows (grok-4.6-build).

Writing that JSON to ~/.local/state/omarchy/agents/usage/grok.json and running omarchy-shell omarchy.agents refresh made the stock panel pick Grok up. Still no prepaid ledger on this account, so I did not re-check the cents/Money.val issue from the earlier comment.

This is the remaining gap: Grok is a first-party default agent, but omarchy-agent-usage-update never discovers it until this collector ships.

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.
@mattmcgiv

mattmcgiv commented Sep 1, 2026 •

Copy link
Copy Markdown

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.

@DanMacDonald

Copy link
Copy Markdown

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 🙏

@loraque-git

Copy link
Copy Markdown

Verified on a live install — this still closes the gap, and 4.0.3 still does not ship omarchy-agent-usage-grok.

Environment

  • Omarchy 4.0.3-1
  • Grok CLI 1.0.25 (stable)
  • Default agent: grok
  • Packaged collectors only: claude, codex, fireworks (no omarchy-agent-usage-grok under /usr/share/omarchy/bin)
  • SuperGrok (weekly pool in use)

What I ran
Downloaded bin/omarchy-agent-usage-grok from this branch (0090bff) and ran --force against the real ~/.grok home. Did not install over packaged files.

Result
Printed a ready: true record that matches the agents-panel contract:

  • Plan SuperGrok
  • Weekly 22% (reset 2026-09-16), same window Grok /usage has been showing
  • Local stats from parent sessions only: 102 prompts / 7 sessions / 4 active days
  • Tokens by model: grok-4.6 and grok-4.6-build
  • No prepaid ledger on this account (collector correctly omitted balance)

Writing that JSON to ~/.local/state/omarchy/agents/usage/grok.json is enough for stock omarchy.agents to grow a Grok tab. I already run a user-space collector of the same shape; this PR’s output is the core SuperGrok + Grok Build scan, with no QML required.

Notes (not blockers)

  • This branch surfaces one Weekly meter. #10074 also adds a Grok Build product slice from productUsage. On this login those two percentages were the same (22%), so a second meter would have been redundant here — still useful on accounts where Build diverges from the shared pool.
  • I did not re-run test/shell.d/agent-usage-grok-scanner-test.sh (needs the repo’s base-test.sh). Happy to do that from a checkout if it helps.

This is still the right first-party collector. Happy to re-test after a rebase onto current quattro.

@bjarneo

bjarneo commented Sep 20, 2026

Copy link
Copy Markdown
Member

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.

@bjarneo bjarneo closed this Sep 20, 2026
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.

9 participants