feat: Grok Build SuperGrok pool (init --grok) — Claude-resolution greedy swap via billing?format=credits - #2
Open
chasehuh wants to merge 1 commit into
Open
feat: Grok Build SuperGrok pool (init --grok) — Claude-resolution greedy swap via billing?format=credits#2chasehuh wants to merge 1 commit into
chasehuh wants to merge 1 commit into
Conversation
Adds init/add/switch/ls/status/watch/doctor/rm/rename --grok, a PATH grok supervisor (argv0 grok / __supervise-grok), always-trusted Stop + StopFailure hooks under ~/.grok/hooks/tokenmaxxing-grok.json, and the greedy weekly pace-pressure swap over the free billing?format=credits GET (creditUsagePercent used% + currentPeriod.end weekly reset; no 5h window exists and none is invented). Grok mechanics that shaped the shape, vs the codex template it mirrors: - A running grok hot-reloads a swapped auth.json on its next API call, so a plain swap restarts nothing and carries every default-home session (no codex-style sibling reconcile). Respawn markers exist only for the depleted-pool countdown (waitUntil + `grok --resume <sid>`) and the StopFailure rate_limit fallback (the config watcher can skip a same-key reload). - The live store is a one-slot issuer map, replaced losslessly under grok's own auth.json.lock flock held across the whole harvest-install critical section, plus tokenmaxxing's grok-lock for our own actors. - No token self-refresh: the real binary refreshes an installed credential itself. Parked access tokens rot on an hours-scale TTL and report as honest sample misses, never probed and never needs-reauth; only a refusal of a token inside its TTL marks a dead grant. - init pins grokBin to the newest ~/.grok/downloads binary (grok update clobbers the ~/.grok/bin launcher), never overwrites the installer, and init/doctor flag PATH shadowers (~/.grok/bin, ~/.local/bin/grok) with the exact retarget command. - The supervisor scrubs XAI_API_KEY / GROK_AUTH_PROVIDER_COMMAND on managed and passthrough spawns alike: the pool is OIDC-session-only. - status --force never pings grok; the Stop hook filters reason == end_turn, exits 0 with no output, and never blocks. - --grok is accepted anywhere in argv and mutually exclusive with --codex; an empty grok pool adds zero doctor findings. Hermetic tests mirror test/codex.test.ts on a third pid-strided mock port (mapper credits/monthly-zeros fixtures, picker, swap, decide incl. depleted-wait and the rate_limit force guard, presence, stop hook, dispatch permutations). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Implements #1: a third tokenmaxxing pool for Grok Build SuperGrok OIDC logins at the same CLI resolution as Claude Code and Codex.
What's in
init/add/switch/rm/rename --grok(flag accepted anywhere in argv, mutually exclusive with--codex), grok sections inls/status/watch/doctor,grokBininconfig, grok teardown inuninstall.GET {base}/billing?format=creditswithAuthorization: Bearer <issuer.key>+X-XAI-Token-Auth: xai-grok-cli.config.creditUsagePercent= used%,config.currentPeriod.end= weekly reset,productUsage[GrokBuild]as fallback. The query is pinned in one place (billingUrl()), and the mapper throws on the legacy monthly-zeros body so a lostformat=creditscan never render as an empty weekly bar. Weekly window only — no 5h bar invented,status --forcenever pings grok.auth.json.lockflock (held across harvest→install) plus tokenmaxxing'sgrok-lock. Harvest keys on the blob'suser_id, never a label; an unpooled live identity refuses the swap. Live writes are atomic 0600; parked blobs are the lossless full map ingrok-creds/(0600).waitUntil+grok --resume <session-id>) and (b) the StopFailurerate_limitreactive path, which restarts the refused session in case grok's config watcher skipped a same-key reload.~/.grok/hooks/tokenmaxxing-grok.json(Stop + StopFailurerate_limitmatcher, timeout 15s). Stop filtersreason == "end_turn", exits 0 with no output, never blocks, never asks for/hookstrust.cmux-session.jsonuntouched.argv0 grok/__supervise-grok): scrubsXAI_API_KEY+GROK_AUTH_PROVIDER_COMMAND(managed and passthrough spawns alike — the pool is OIDC-session-only), wrap-depth/rate loop guards, child-pid presence files under the flock, headless-pstill managed.init --grokprefers the newest~/.grok/downloads/grok-*binary (survivesgrok updateclobbering the~/.grok/binlauncher), verifies--version, and never overwrites~/.grok/bin/grok. init + doctor flag PATH shadowers (~/.grok/bin,~/.local/bin/grok) with the exactln -sfretarget command.test/grok.test.ts(51 tests) mirrors the codex suite hermetically — mapper fixtures (credits + monthly-zeros), picker/margin/engagement, swap sequence + refusals, decide incl. depleted-wait, the rate_limit force path and its transient-529 guard, presence, stop-hook marker matrix, install lifecycle, argv dispatch permutations,--grok+--codexmutual exclusion. Mock billing on a third pid-strided port (test/setup.tsstride 2→3).Verification
bun test: 394 pass / 1 skip (the pre-existing macOS keychain skip) / 0 failbun run typecheck(tsc --noEmit): cleanbun test/e2e/swap-concurrency.ts(standalone): ALL PASSgrok --help, 1.0.8 Mach-O):-r, --resume [<SESSION_ID_OR_TITLE>], bare--resume= most recent. Login flags verified:--oauth(default),--device-auth/--device-code. Hook envelope (camelCase,reason/error/stopHookActive), always-trusted global hooks dir, hot-reload, andGROK_AUTH_EARLY_INVALIDATION_SECS=300verified against the local 1.0.8 user-guide docs.Not live-verified (per issue constraints — no billed runs, no real credentials touched)
user_id) — fallback is the restart path, one cold turn.init --grokon the desk logins (QA step 4 is Chase's, post-merge).productUsage[GrokBuild]divergence fromconfig.creditUsagePercent— v1 usesconfigas primary,GrokBuildrow as fallback, per the issue.auth.json— v1 pools theprincipal_type=Usersession entry; desk blobs have exactly one.One interpretation call
Issue acceptance says
add --grok"refuses duplicate user_id", while the validation rules name isolated re-login as the needs-reauth recovery. Implemented as the codex precedent: an idle existing account upserts (re-parks the fresh grant, clears needs-reauth — one index entry per user_id, so no duplicates ever exist), while a live-supervised account and the current live login still refuse. If a hard refusal is preferred, it's a 5-line change.Notes
Closes #1
🤖 Generated with Claude Code