Skip to content

Add Grok as a model-usage provider - #6485

Open
scottjones wants to merge 3 commits into
basecamp:quattrofrom
scottjones:model-usage-grok-provider
Open

Add Grok as a model-usage provider#6485
scottjones wants to merge 3 commits into
basecamp:quattrofrom
scottjones:model-usage-grok-provider

Conversation

@scottjones

@scottjones scottjones commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Adds Grok alongside Claude Code and Codex in the model-usage bar panel: tokens by day and by model from the CLI's session transcripts, plus the weekly credit meter and subscription tier.

image

Grok publishes no supported way to read that allowance — no subcommand exposes it and the ACP surface has no account-credits method — so the scanner asks the billing endpoint the CLI itself calls, at the same 15-minute cadence the Claude provider already probes Anthropic on, and falls back to the log grok writes whenever that call can't be made or trusted. A reading whose period has already ended is dropped rather than shown, so a quiet week reports no meter instead of last week's number.

Worth knowing when reading the panel: the meter and the token chart don't agree and can't be made to. Grok's transcripts are ~97% cache reads, and the allowance is billed per X identity rather than per machine, so usage from the web or another box lands in the meter with nothing local to explain it.

The first commit is separable — it makes the hero fall back to the bar's AI glyph when a provider ships no brand mark, which nothing needed until now.

Validation caveat: everything here was verified against one billing identity. prepaidBalance and onDemandCap are 0 there and are not handled; an account with purchased credits or on-demand overage is untested. The failure mode is a missing or incomplete meter rather than a wrong number.

Test plan

  • test/shell.d/model-usage-grok-scanner-test.sh — 9 assertions covering turn summing, per-turn dedupe, cache not double-counted, multi-model turns, the credit meter, an expired period, live-call fallback, and no log at all
  • Scanner totals cross-checked against a raw jq sum of every turn_completed record (exact match, grand total and every daily bucket)
  • Existing Claude/Codex/migration tests and ./test/cli pass
  • Panel verified in a running shell on both light and dark themes
  • Degrades correctly with no Grok installed, signed out, and with a malformed auth.json
  • Untested: an account with non-zero prepaid balance or on-demand cap

🤖 Generated with Claude Code

scottjones and others added 2 commits August 1, 2026 10:15
The hero drew an Image unconditionally, so a provider without an SVG in
assets/ left a hole where the logo belongs. Wrap it in an Item that swaps
in the bar's own AI glyph when no mark is named or the named file fails to
load, which also means adding a mark later is just dropping in the file.

Hoist that glyph to a property built from its codepoint so the bar and the
hero share one definition and no raw astral literal has to survive an edit.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Tokens come from the turn_completed records in the CLI's session
transcripts, which already carry a per-model breakdown and report each turn
rather than a running total. Grok folds cache reads into inputTokens and
reasoning into outputTokens, so the scanner subtracts the cache read to keep
the split visible without counting either twice.

The weekly credit allowance has no supported read: no subcommand exposes it
and the ACP surface has no account-credits method. grok fetches it from a
billing endpoint and writes the result to its own log, so the scanner asks
that endpoint directly and falls back to the log whenever the call cannot be
made or cannot be trusted — no token, an expired one, a timeout, a bad body.
It asks at most every 15 minutes, the cadence the Claude provider already
probes Anthropic's usage endpoint on.

A reading whose period has already ended is dropped rather than shown, on
either path, so a quiet week reports no meter instead of the previous week's
number.

That allowance is billed per X identity, not per machine, workspace, or
plan: signing in under a second team id returns a byte-identical credits
body with isUnifiedBillingUser set. So the meter and the token chart measure
different things and will not agree — one period here read 22% against zero
recorded local spend — and the percentage cannot be reconstructed from local
totals, which is worth knowing before anyone tries.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings August 1, 2026 14:41

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, model breakdowns, subscription tier, and weekly credit limits to the model-usage panel.

Changes:

  • Adds Grok transcript and billing scanners with tests.
  • Integrates Grok into provider selection and synchronization.
  • Adds Grok branding, configuration, and documentation.

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 7 out of 9 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
test/shell.d/model-usage-grok-scanner-test.sh Tests Grok usage and credit scanning.
shell/plugins/model-usage/scripts/grok_usage_scanner.py Scans transcripts, billing logs, and live credits.
shell/plugins/model-usage/README.md Documents Grok behavior and configuration.
shell/plugins/model-usage/providers/Grok.qml Implements the Grok provider.
shell/plugins/model-usage/Panel.qml Adds Grok branding and icon fallback.
shell/plugins/model-usage/manifest.json Enables Grok by default.
shell/plugins/model-usage/Main.qml Integrates Grok into provider orchestration.
shell/plugins/model-usage/assets/grok.svg Adds the dark-background Grok mark.
shell/plugins/model-usage/assets/grok-light.svg Adds the light-background Grok mark.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread test/shell.d/model-usage-grok-scanner-test.sh
Comment thread shell/plugins/model-usage/scripts/grok_usage_scanner.py Outdated
Falling back only on a None response covered a call that failed outright but
not one that returned a body this cannot read — a partial config, renamed
fields, a period that has already closed. Those blanked the meter even when
the log still held a good reading, which is not the "cannot be made or
cannot be trusted" behaviour the docs describe. Decide on the limit rather
than on the response.

The offline test that was meant to cover this never opened a socket: the
fixture had no auth.json, so the scanner returned before reaching the
endpoint and the case passed as a no-token case. Give the fixture a token,
and add a stub credits endpoint so a reply that parses but cannot be used,
and one that can, are both exercised for real.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings August 1, 2026 14:47

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 7 out of 9 changed files in this pull request and generated no new comments.

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.

2 participants