Skip to content

Add Grok Build usage to the agents panel - #6902

Closed
csfh wants to merge 13 commits into
omacom:quattrofrom
csfh:feature/grok-build-agents
Closed

csfh wants to merge 13 commits into
omacom:quattrofrom
csfh:feature/grok-build-agents

Conversation

@csfh

@csfh csfh commented Aug 14, 2026 •

Copy link
Copy Markdown
Member

Summary

Adds a Grok Build collector so the agents panel can show SuperGrok weekly usage, extra credits, and local token history.

omarchy-agent-usage-update already globs omarchy-agent-usage-*. This ships bin/omarchy-agent-usage-grok; the panel picks up the record with no QML changes.

Change

  • Local stats come from documented Grok Build sessions under $GROK_HOME (default ~/.grok): each turn_completed event in updates.jsonl is one prompt (nested usage, flat token fields, or event_name). Cache read is split out of input. 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.
  • pi/omp sessions on an xai / xai-auth provider, and OpenCode messages with providerID xai, are merged in the same way Claude and Codex pick up those agents. Other providers, non-assistant rows, prefix-colliding ids such as xai-proxy, and non-object JSONL / malformed OpenCode rows are ignored. An interrupted OpenCode scan is not cached.
  • Limits come from cli-chat-proxy /v1/billing?format=credits (weekly or monthly pool as limits[], prepaid / leftover on-demand credits as balance). Plan label prefers /v1/settings subscription_tier_display (the string Grok's UI shows) and falls back to /v1/user subscriptionTier (SuperGrokPro → SuperGrok Pro).
  • creditUsagePercent is read as 0-100, matching productUsage. A retry is advised only on a transport miss; an HTTP status means the endpoint answered, so the panel's 30-second retry is not set.
  • Missing or expired auth.json keeps local stats and asks for grok login. The token is never written into the usage record.
  • Incremental scan cache under ~/.cache/omarchy/agent-usage/. --limits-only reuses any same-day scan so opening the panel refreshes the weekly percent without walking transcripts; --force rereads the files. An unwritable cache still prints a complete record.
  • Optional assets/grok.svg / grok-light.svg mark (from the official Grok favicon paths). Manifest and manual list Grok Build next to Claude, Codex, and Fireworks.

Related: #6477 also adds a grok collector (with Kimi). This PR is Grok Build only, and it counts billed turn_completed usage rather than peak _meta.totalTokens context size.

Testing

./test/shell.d/agent-usage-grok-scanner-test.sh
./test/shell.d/agent-usage-update-test.sh

Focused collector tests passed, including pi xAI merge, OpenCode xAI merge, subagent skip, live plan label, flat turns, malformed params, and cache reuse.

Copilot AI balanced review requested due to automatic review settings August 14, 2026 21:49

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

Note

Copilot was unable to run its full agentic suite in this review.

Adds Grok Build support to the agents usage panel by introducing a new Grok usage/limits collector, wiring it into the plugin manifest, and documenting/validating behavior with assets and shell-based tests.

Changes:

  • Added a new omarchy-agent-usage-grok collector that scans local Grok session files and optionally probes Grok billing/user endpoints.
  • Enabled the Grok provider in the agents plugin manifest and added Grok icon assets.
  • Updated user-facing docs and added a shell test covering token aggregation, session filtering, cache behavior, and offline/expired-auth scenarios.

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
test/shell.d/agent-usage-grok-scanner-test.sh Adds end-to-end shell test fixtures and assertions for Grok usage scanning and limits probing behavior.
shell/plugins/agents/manifest.json Registers/enables the new grok provider and updates plugin description.
shell/plugins/agents/assets/grok.svg Adds dark-surface Grok icon asset.
shell/plugins/agents/assets/grok-light.svg Adds light-surface Grok icon asset variant.
shell/plugins/agents/README.md Documents Grok provider data sources, env vars, and auth handling.
manual/17-ai.md Mentions Grok Build as supported out of the box in the manual.
bin/omarchy-agent-usage-grok Introduces the Grok Build collector implementation (local scan + optional limits probe + caching).

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

@csfh

csfh commented Aug 14, 2026

Copy link
Copy Markdown
Member Author
image

Screenshot attached.

Ship omarchy-agent-usage-grok so the agents panel can show SuperGrok
weekly pool, extra credits, and local session token stats. Session
turn_completed events under $GROK_HOME are scanned; limits come from
Grok Build's cli-chat-proxy billing and user endpoints, the same ones
/usage uses.
Copilot AI review requested due to automatic review settings August 14, 2026 22:10
@csfh
csfh force-pushed the feature/grok-build-agents branch from 05b6d3c to 8146bb0 Compare August 14, 2026 22:10

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

Copilot reviewed 4 out of 7 changed files in this pull request and generated no new comments.

Suppressed comments (2)

test/shell.d/agent-usage-grok-scanner-test.sh:199

  • This test hard-codes an absolute billing period end timestamp and asserts it verbatim. That makes the test brittle over time (and can also fail in environments where fixtures are expected to be relative to ‘now’). Prefer generating the start/end timestamps relative to the test’s runtime (similar to how expires_at is generated), and assert the derived/expected value (or assert shape + presence rather than an exact, fixed date).
      "start": "2026-08-08T14:46:02.562637+00:00",
      "end": "2026-08-15T14:46:02.562637+00:00"

test/shell.d/agent-usage-grok-scanner-test.sh:213

  • This test hard-codes an absolute billing period end timestamp and asserts it verbatim. That makes the test brittle over time (and can also fail in environments where fixtures are expected to be relative to ‘now’). Prefer generating the start/end timestamps relative to the test’s runtime (similar to how expires_at is generated), and assert the derived/expected value (or assert shape + presence rather than an exact, fixed date).
[[ $(jq -c '[.limits[] | {label, percent, resetsAt}]' <<<"$limits") == '[{"label":"Weekly","percent":0.24,"resetsAt":"2026-08-15T14:46:02.562637+00:00"}]' ]] ||

dhh and others added 2 commits August 15, 2026 03:15
The field is 0-100 alongside productUsage's percentages, so the fraction
branch turned 0.4% used into 40% and 1% into a fully spent pool.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
An HTTP status means the endpoint is up, so the panel's 30-second retry
just pesters it; a 429 or 503 outage put every refresh on that treadmill.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Copilot AI review requested due to automatic review settings August 15, 2026 10:16

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

Copilot reviewed 4 out of 7 changed files in this pull request and generated no new comments.

@AnthonyPoschen

AnthonyPoschen commented Aug 15, 2026 •

Copy link
Copy Markdown
Contributor

i was about to make this as i just installed quattro and wanted this, thank you :)

set it up locally works great for me

image

@csfh

csfh commented Aug 15, 2026

Copy link
Copy Markdown
Member Author

i was about to make this as i just installed quattro and wanted this, thank you :)

set it up locally works great for me

image

You are very welcome.

@thehamsti

Copy link
Copy Markdown

Nice! Literally just built this and was going to make a PR. Should have checked. 👍🏼

A SuperGrok subscription used through pi or omp never writes a Grok Build
transcript. Merge those xAI assistant messages the same way Claude and Codex
already do, and skip every other provider.
@thehamsti

Copy link
Copy Markdown

Rather than open a competing Grok collector, I branched off this PR and added the SuperGrok usage that never writes a Grok Build transcript: pi/omp sessions on an xai / xai-auth provider, the same merge Claude and Codex already do.

PR onto this branch: https://github.com/csfh/omarchy/pull/1

@csfh

csfh commented Aug 17, 2026

Copy link
Copy Markdown
Member Author

@thehamsti

Hello. I had my agent review your PR (lol). One potential bug. Please take a look, thank you sir.

@jkubo

jkubo commented Aug 19, 2026

Copy link
Copy Markdown

Two small extras from running this locally on Grok Build 1.0.5 (SuperGrok Heavy), if useful before merge. Happy to push them onto this branch rather than open another collector.

  1. Plan label. GET /v1/settings already returns subscription_tier_display as the human string (SuperGrok Heavy here). That skips the SuperGrokPro → "SuperGrok Pro" rewrite and stays in sync with what Grok's own UI shows.

  2. Turn ledger. Some turn_completed rows put the token fields on the update object itself, and/or use event_name instead of sessionUpdate. Requiring nested update.usage plus "usage" in line drops those. A fallback to the flat ledger + event_name == "turn_completed" is a few lines.

Everything else here (weekly meter from /v1/billing?format=credits, Grok Build name, subagent_fork skip, cache split) already matches what we needed. No competing PR from us.

@csfh

csfh commented Aug 19, 2026

Copy link
Copy Markdown
Member Author

@jkubo

Let's tag it on to this branch no problem.

…without a full scan

Read subscription_tier_display from GET /v1/settings so the panel shows the
same plan string as Grok's own UI, falling back to subscriptionTier. Count
turn_completed rows that put the ledger on the update itself or use
event_name instead of sessionUpdate.

--limits-only reuses any same-day session scan so opening the panel can
refresh the weekly meter without walking every transcript. Collector test
fixtures use padded dummy ids, not live UUIDv7s.
Grok 1.0.x writes session_kind: subagent. Older builds used
subagent_fork. The collector only skipped the old name, so child
sessions on current Grok were counted again on top of the parent
turn_completed ledger.
@shawnyeager

Copy link
Copy Markdown
Contributor

One more follow-up from a live Grok 1.0.5 scan, offered the same way as #1 and #2 on this branch.

Grok 1.0.x writes session_kind: subagent. This collector only skips subagent_fork, so child sessions on current Grok are counted again on top of the parent turn_completed ledger. On one SuperGrok Heavy machine that was 36 extra sessions.

Patch onto this branch: https://github.com/csfh/omarchy/pull/3

Closing the competing Basecamp PR (#7784) in favor of this one.

@csfh

csfh commented Aug 22, 2026

Copy link
Copy Markdown
Member Author

Great. Thanks @shawnyeager

csfh and others added 3 commits August 22, 2026 11:50
Skip Grok 1.0.x subagent sessions in the usage collector
Count pi and omp xAI sessions in the Grok usage collector. Skip non-dict
JSONL lines and require type=message plus assistant role, matching Claude.

Co-authored-by: Cursor <[email protected]>
Prefer live plan label and accept flat turn_completed usage

Co-authored-by: Cursor <[email protected]>
csfh and others added 3 commits August 22, 2026 12:01
A non-dict params field in updates.jsonl raised AttributeError and took
the collector down. Skip those rows, treat an empty nested usage as the
flat ledger, and ignore non-assistant pi JSONL the same way Claude does.

Co-authored-by: Cursor <[email protected]>
A SuperGrok subscription burned entirely through OpenCode never writes a
Grok Build transcript. Merge those messages the same way Claude and Codex
already do, skip every other provider, and do not cache an interrupted scan.

Co-authored-by: Cursor <[email protected]>
SuperGrok grants "reset tokens": banked resets that clear the credit
period before it runs out. The CLI chat proxy this collector speaks to
carries no trace of them, so the count comes from the grpc-web RPC
grok.com itself calls, on the same bearer token the proxy requests use.

Reported as resetCreditsAvailable, the provider-neutral field basecamp#7799
adds for Codex, so the panel prints it with no further change here.

The fetch is advisory: a failure reports nothing rather than disturbing a
weekly meter that was read successfully.
@csfh

csfh commented Aug 22, 2026

Copy link
Copy Markdown
Member Author

@thehamsti @jkubo @shawnyeager

All should be merged.

@dbech

dbech commented Aug 29, 2026

Copy link
Copy Markdown

Heya, I tried this PR on my machine, I like it.

One thing, omp’s provider id is xai-oauth, not xai / xai-auth. Without that match daily and model usage is empty.

@csfh

csfh commented Aug 29, 2026

Copy link
Copy Markdown
Member Author

Omp is Pi? Oh my pi?

@dbech

dbech commented Aug 30, 2026

Copy link
Copy Markdown

SuperGrok reset tokens are not on the CLI chat proxy, so the collector reads them from grok.com's GetRemainingResets grpc-web RPC and reports the still-valid count as resetCreditsAvailable.
@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.

10 participants