Skip to content

Add Grok Build / SuperGrok usage monitoring - #72

Open
reloadlife wants to merge 2 commits into
f-is-h:mainfrom
reloadlife:main
Open

Add Grok Build / SuperGrok usage monitoring#72
reloadlife wants to merge 2 commits into
f-is-h:mainfrom
reloadlife:main

Conversation

@reloadlife

Copy link
Copy Markdown

Summary

Adds optional Grok Build / SuperGrok usage monitoring as a third provider alongside Claude and Codex, addressing #69.

Closes #69

What users get

  • Weekly SuperGrok / Grok Build quota (?format=credits billing response)
  • Monthly included allowance (default billing form)
  • Credits residual (prepaid / on-demand)
  • Menu bar icons + detail-window column (alone or next to Claude/Codex)
  • Multi-account storage in Keychain (same pattern as Codex)

Auth (Settings → Authentication)

  1. Import Grok Auth — pick Grok CLI ~/.grok/auth.json (recommended if you already run grok login)
  2. Grok Device Login — OIDC device-code flow against auth.x.ai (public Grok CLI client id)

Technical approach

Mirrors the existing Codex provider integration:

Layer Implementation
Models ProviderType.grok, GrokUsageData + billing response parsers
API GrokAPIService — refresh_token → access_token → concurrent credits + monthly billing GETs
Auth GrokOAuthService — token refresh, device code, auth.json import
Storage accounts_grok Keychain list + AccountStore CRUD
UI GrokColumnView, multi-column detail width, menu-bar composition
Limits grok_weekly / grok_monthly / grok_credits colors, notifications, custom display

Billing endpoints (same surface used by official Grok CLI /usage):

  • GET https://cli-chat-proxy.grok.com/v1/billing?format=credits
  • GET https://cli-chat-proxy.grok.com/v1/billing

Tests

Repo already has a SwiftPM pure-function test target. Added:

  • Tests/Usage4ClaudeCoreTests/GrokUsageResponseTests.swift
    • credits weekly % from productUsage / creditUsagePercent fallback
    • Grok product preference over other products
    • monthly used/limit percentage + edge cases (missing limit/used, zero limit)
    • percentage clamping, empty payloads
    • ISO8601 with/without fractional seconds
    • GrokCreditsData enabled / percentage rules
    • ProviderType.grok display name

Run (on a machine with Swift toolchain):

swift test

Full macOS app still builds via Xcode / ./scripts/build.sh.

Notes for reviewers

  • Claude-only and Codex-only flows are unchanged until a Grok account is added.
  • No Grok brand asset pack yet — menu bar uses a small synthetic “G” badge; can be swapped for real assets later.
  • Device-code + auth.json import only (no embedded WKWebView for Grok); keeps parity with how Grok CLI authenticates and avoids reverse-engineering private web cookies.

Test plan

  • swift test passes (Grok parser suite + existing suites)
  • Import ~/.grok/auth.json → Grok column appears with weekly/monthly data
  • Device-code login completes and persists account across relaunch
  • Claude-only / Codex-only / Grok-only / multi-provider layouts look correct
  • Manual refresh and smart refresh still work with Grok credentials present
  • Custom display toggles for Grok weekly/monthly/credits work
  • 90% usage notification fires for Grok weekly/monthly when enabled

Monitor SuperGrok/Grok Build weekly quota, monthly included allowance,
and credits via the same billing API used by the Grok CLI. Accounts can
be imported from ~/.grok/auth.json or signed in with OIDC device-code
flow. Grok appears as a third provider in the menu bar and detail window.
Cover productUsage preference, creditUsagePercent fallback, monthly
edge cases, percentage clamping, ISO8601 date parsing, and credits
enabled/percentage rules.
Copilot AI review requested due to automatic review settings July 21, 2026 23:54

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@reloadlife

Copy link
Copy Markdown
Author

Hey @f-is-h

as a Grok user, i'd appreciate if you accept this PR.

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.

Idea: add grok usage too

2 participants