Skip to content

feat: let a review use a SuperGrok subscription - #120

Draft
Kudo wants to merge 2 commits into
mainfrom
feat/grok-oauth
Draft

Kudo wants to merge 2 commits into
mainfrom
feat/grok-oauth

Conversation

@Kudo

@Kudo Kudo commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator

Why

xai/… models already run on OpenCode. The pinned CLI can sign in with SuperGrok (opencode auth login -p xai lists SuperGrok Subscription), but ecr setup-auth filed an xai oauth entry as unsupported. A review also had no owner for XAI_API_KEY or XAI_OAUTH_ACCESS_TOKEN, so an xAI API key was copied into ANTHROPIC_API_KEY.

Claude reviews still do not write auth.json. The token goes on the Claude child. Codex reviews write an isolated auth.json, and a SuperGrok review does the same with the access token.

How

  • ecr setup-auth runs the bundled opencode auth login -p xai -m "SuperGrok Subscription" from a temp directory. It reads xai.access from OpenCode's store and prints export XAI_OAUTH_ACCESS_TOKEN='…'. The refresh token stays in that store. A live access token is reused. If the env var is already set, the login is skipped.
  • prepareAuth writes that JWT into the isolated $XDG_DATA_HOME/opencode/auth.json as { type: "oauth", access, refresh: "", expires }. It does not set XAI_API_KEY from the access token.
  • An opaque xAI value fails before any pass and names ecr setup-auth. So does a JWT that is expired or has 120 seconds or less left. Under about two hours left, the run warns and continues.
  • An xAI API key uses XAI_API_KEY. setup-auth prints https://console.x.ai. It does not run "Manually enter API Key".
  • Both env names belong to xai. An MCP server token env cannot use either. mode: "oauth" still caps concurrency at 3.
  • No schema change and no OpenCode bump. buildOpencodeConfig does not add a provider.xai block.

Test Plan

  • bun test on auth, setup-auth, opencode, mcp-servers, and review-internals: 182 pass.
  • bun run typecheck, bun run lint, bun run fmt:check, and bun run llp:check.
  • Pinned opencode-ai@1.19.5: opencode auth login -p xai -m '__no-such-method__' lists SuperGrok Subscription and Manually enter API Key.
  • Not run: a finished ecr setup-auth device login, then ecr doctor, then one short local review on xai/…. If that review returns 402 or 403, stop and report the host. Do not send the oauth token to api.x.ai.

xAI models already run on OpenCode, and the pinned CLI can sign in with SuperGrok. setup-auth treated that oauth entry as unsupported, so a review never received the access token.
@github-actions

github-actions Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

🤖 AI code review

Decision: Ready for human review

Overall PR risk: Medium. This change modifies xAI authentication handling to support SuperGrok subscriptions by redirecting credentials from ANTHROPIC_API_KEY to XAI_API_KEY and adding token expiry validation. Existing behavior affected: xAI users, MCP token env guards, and setup-auth login flow. What could break: repos naming XAI_API_KEY or XAI_OAUTH_ACCESS_TOKEN for non-xai purposes are now refused; oauth runs fail fast on expired or near-expiry tokens; setup-auth depends on bundled OpenCode CLI method labels. Rollback is direct.

🔎 Reviewer summaries (3)
  • consistency: I compared the xAI additions with the sibling openai/meta paths in setup-auth, auth.ts, the tests, and templates/config.jsonc. The new code follows the existing patterns. The earlier tokenEnv finding is now fixed.
  • correctness: I checked the xAI oauth and api-key paths through checkOauthTokenShape, checkAuthEntry, prepareAuth, and the setup-auth SuperGrok plan. The earlier tokenEnv finding is now fixed. I found no new defect.
  • security: Reviewed the xAI/SuperGrok auth support for token forwarding, the deny-list guards, auth.json staging, and setup-auth exports. I found no exploitable path. The ownership guard covers both xAI envs, and no token reaches logs or error text.

🔗 Review setup:

  • This PR changes code the reviewer prompts cite (src/tests, src/core/auth.ts, templates/config.jsonc). Check that the guidance quoting it is still correct.

No findings.


This review is advisory — it never blocks a merge and never auto-approves.

An xAI oauth entry with no tokenEnv cannot run. setup-auth was filling in XAI_OAUTH_ACCESS_TOKEN and printing an export, then the review rejected the same config.
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.

1 participant