Repository navigation
Add a Grok collector to the agents widget - #11539
ConsultingFuture4200 wants to merge 2 commits into
Conversation
The agents panel gains a tab for any record that lands in the usage directory, so adding Grok is adding a collector — no plugin code changes. Local stats come from the SQLite session index under ~/.grok/sessions, with `grok usage <id>` per session for tokens, models, and cost. Only local sessions carry token data: `grok sessions list` reports server-side sessions that `grok usage` cannot answer for. Per-session totals are cached and re-read only when a session's own timestamp moves, so a refresh costs one CLI call per changed session. The plan and signed-in identity come from ~/.grok/auth.json, and GROK_HOME is honored the way CODEX_HOME is. Two deliberate omissions: Grok reports no rate limits. A grok.com subscription does have allowances, but nothing exposes them to a collector — Grok's status-line documentation lists a rate-limit summary among the fields it deliberately omits, as "a number it cannot source honestly". The record carries no limits rather than an invented meter. `grok usage` prices sessions at API list rates, but a subscription bills nothing per token, so that figure is notional. It travels as notionalCostUsd and is not published as a balance, which would have drawn a prepaid credit ledger for an account that has none. Day totals sum cache traffic the way the model rows do, since Grok's own totalTokens counts input and output only and the panel's two sections would otherwise disagree. The tier claim in the access token is a plain integer with no published mapping, so only a value confirmed against a real account is named; anything else falls back to the generic label. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Three corrections after running this against a real account for two days. A failed `grok usage` call now keeps the session's last good numbers and leaves its timestamp alone, so the next run retries rather than treating the carried-forward reading as fresh. Only a session with nothing cached counts as unread, and then the record says the totals are incomplete instead of implying an idle week. The tab also says what it can and cannot see. Only Grok CLI sessions on this machine leave token data behind; work done on grok.com, in the Grok app, or on another machine is invisible here, and `grok usage` cannot answer for the server-side sessions `grok sessions list` reports. An empty week now says so rather than showing zeros that read as broken tracking. The tier mapping is gone. The access token's `tier` claim is not a stable plan id: one account read 1 and, two days later with no plan change to explain it, 7. With no published mapping, an unmapped tier falls back to the panel's generic label, which is never wrong, rather than putting a guessed plan name in someone's bar. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CRqM55mgaBbMgkkYzPNHqi
|
Pushed three corrections after running this against a real account for a couple of days. A failed read no longer looks like an idle week. If The tab now states its scope. Only Grok CLI sessions on the local machine leave token data behind — work done on grok.com, in the Grok app, or on another machine is invisible, and The tier mapping is removed. I'd mapped Behaviour otherwise unchanged; the record contract is the same. 🤖 Generated with Claude Code |
|
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. |
The agents panel gains a tab for any record that lands in the usage directory, so adding Grok is adding a collector — no plugin code changes. This follows the pattern the widget's own README describes:
Where the numbers come from
Local stats come from the SQLite session index under
~/.grok/sessions, withgrok usage <id>per session for tokens, models, and cost. Only local sessions carry token data —grok sessions listreports server-side sessions thatgrok usagecannot answer for.Per-session totals are cached in
~/.local/state/omarchy/agents/grok-usage-cache.jsonand re-read only when a session's ownupdated_atmoves, so a refresh costs one CLI call per changed session rather than per session. The plan and signed-in identity come from~/.grok/auth.json, andGROK_HOMEis honored the wayCODEX_HOMEis.Two deliberate omissions
No limit meters. A grok.com subscription does have allowances, but nothing exposes them to a collector. Grok's own status-line documentation lists a rate-limit summary among the fields it deliberately does not send, calling it "a number it cannot source honestly." The record carries no limits rather than a meter no one can stand behind.
No balance.
grok usageprices each session at API list rates, but a subscription bills nothing per token, so that figure is notional rather than money spent. It travels asnotionalCostUsdand is deliberately not published as abalance— that section draws a prepaid credit ledger, and publishing one rendered "Prepaid credits $0.00" for an account that is neither prepaid nor at zero.Notes for review
totalTokenscounts input and output only, so TOKENS BY DAY and TOKENS BY MODEL would otherwise disagree.tierclaim is a plain integer with no published mapping. Only a value confirmed against a real account is named (1→ SuperGrok, verified on a $30 subscription); anything else falls back to the generic label rather than stating a guessed plan as fact. Happy to drop the mapping entirely if you'd rather not carry an unpublished constant.grokis resolved viashutil.whichwith a mise fallback, since version managers keep it off the PATH a bar widget inherits. Open to a better convention if one exists.Testing
Verified on Omarchy 4.0.3-1 against a real signed-in SuperGrok account:
bin/omarchy-agent-usage-update --force grokwritesgrok.json; the panel picks it up and renders the tab with no plugin changes.--forceand--limits-onlyboth produce valid records.GROK_HOME=/nonexistent) yieldsready=false, "Waiting for auth", and thegrok loginhint.grok-4.6-build).I don't have a second Grok account or another tier to test against, so the tier mapping is confirmed for one value only.
🤖 Generated with Claude Code