Skip to content

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

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

Kudo wants to merge 5 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.
  • setup-auth reuses a stored or exported token only when a review would take it with no error and no expiry warning. Otherwise it signs in again, because the review names ecr setup-auth as the fix.
  • 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, ecr doctor and the run both warn and continue.
  • The access token lasts 6 hours, and a review cannot renew it. So this mode suits local runs, and the README says so.
  • An xAI API key uses XAI_API_KEY. setup-auth prints https://console.x.ai. It does not run "Manually enter API Key". An xai api-key entry with no tokenEnv still relies on OpenCode's own login.
  • Both env names belong to xai, and an alias with upstream: "xai" cannot borrow them. The two CODEX_OAUTH_* names now belong to openai. An api-key entry that names XAI_OAUTH_ACCESS_TOKEN is refused. An MCP server token env cannot use either xAI name. mode: "oauth" still caps concurrency at 3.
  • One schema change: an auth tokenEnv must be an env var name, because setup-auth prints it into an export line. There is no OpenCode bump, and buildOpencodeConfig does not add a provider.xai block.
  • The OpenCode logins set OPENCODE_DISABLE_PROJECT_CONFIG=1. OpenCode reads config from every parent of its cwd, and the login cwd is the shared /tmp on Linux.

Test Plan

  • bun test: 1184 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.
  • Live run with a SuperGrok login: ecr setup-auth did the device login, ecr doctor passed, and one short local review on xai/grok-4.7 completed. It found the off-by-one bug in the test diff. The access token was a JWT with a 6-hour lifetime.
  • The pinned OpenCode sends the staged token to https://api.x.ai/v1/responses. A run with a placeholder token showed that host and got a 400. With the real token staged the same way, a direct request and the review both completed.
  • ecr setup-auth on Node with an expired, a live, and a 90-minute token in the env. It signs in again for the first and the third, and it skips the login for the second.

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 auth validation, the setup-auth command, and xai provider handling. Existing configurations with oauth entries that name another provider's token through an upstream alias are now rejected, and auth tokenEnv entries containing non-identifier characters now fail at load. The blast radius is limited to credential handling, and rollback requires only a plain revert.

🔎 Reviewer summaries (3)
  • consistency: Checked the xAI auth additions against sibling providers, setup-auth flows, config schema and template. The new code follows the existing ChatGPT and Meta patterns. The template documents both xAI modes. I found no consistency defects.
  • correctness: I reviewed the xAI/SuperGrok auth support: the ownership guards, token-shape checks, prepareAuth warnings, the setup-auth login flow and export escaping, and the tokenEnv schema check. I found no correctness defects.
  • security: Checked the xAI credential ownership guard, the oauth staging path, the new run warnings, the export-line quoting, and the schema refine on tokenEnv. Warnings and errors name only the env var, never the token value. No security defect found.

🔗 Review setup:

  • This PR changes code the reviewer prompts cite (src/tests, src/config/schema.ts, 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.

Kudo added 4 commits November 27, 2026 00:11
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.
An alias with upstream "xai" could carry an xAI credential under another provider id. A ChatGPT access token also passed the xAI check, because the Codex env names had no owner. An api-key entry that named XAI_OAUTH_ACCESS_TOKEN copied the token into XAI_API_KEY with no expiry check.

The docs said a run warns about a token that lapses soon, but only doctor printed the warning. prepareAuth now returns the warnings of the tokens it staged, and the review prints them.

An xai api-key entry with no tokenEnv relies on OpenCode's own login again, as it did before XAI_API_KEY had an owner.
The review names `ecr setup-auth` as the fix for an expired token. setup-auth skipped the login while the env var was set, so the fix did nothing. It also reused a stored token with seconds left and called it "1 more hour(s)". It now reuses a token only when a review takes it with no error and no expiry warning.

The access token lasts hours, so the README says this mode suits local runs.

An auth tokenEnv must be an env var name, because setup-auth prints it into an export line. The OpenCode logins turn project config off. OpenCode reads config from every parent of its cwd, and the login cwd is the shared /tmp on Linux.
A device login through the pinned OpenCode gave a 6-hour access token. Staged the way a review stages it, that token completed one direct request and one local review on xai/grok-4.7.
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