Add Grok as a model-usage provider - #6485
Open
scottjones wants to merge 3 commits into
Open
Conversation
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>
Contributor
There was a problem hiding this comment.
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.
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>
7 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.
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.
prepaidBalanceandonDemandCapare0there 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 alljqsum of everyturn_completedrecord (exact match, grand total and every daily bucket)./test/clipassauth.json🤖 Generated with Claude Code