Files
plugins/packages/grok/package.json
T
yetone 92d555769b grok 0.2.1: a token Grok turns away is renewed once, and one Grok Build can't renew says so (#324)
Grok can reject a token hours before its expires_at. A 401 used to be
passed on (requests) or read as "Grok's sign-in has expired; run `grok
login`" (models), with no renewal tried: token(home, expired) was never
called with expired set. And an auth.json caught while the CLI rewrote
it read as "not signed in", which the refresh hook marks as an expired
sign-in.

- token(home, rejected): rejected is the token Grok turned away. A token
  on disk other than that one was renewed already and is used; else the
  CLI renews it (`grok models` in the home). A run that leaves the same
  token throws "Grok Build couldn't renew the sign-in (grok models
  <exited N | ran and left the same token>: <its last line>)", never
  "not signed in" or "expired".
- What it says helps: for Grok Build's own home (current()), open Grok
  Build and send it a message; for a home of the plugin's (a second
  device-code account, a CPA import) add the account in magpie again.
  No "run `grok login`" where that signs in a different home. A home of
  the plugin's with no sign-in left says to add the account again too.
- Requests: a 401 renews once and resends the same body with the new
  token. Unrenewable, the 401 carries that message plus Grok's own words
  (JSON error), still X-Magpie-Sign-In: kept. Models: a 401 renews once
  and lists again; a renewed token also refused says so. Usage: same
  retry once. auth.refresh's unrenewed case uses the same message.
- look(): an empty or non-JSON auth.json is torn. read() tries it again
  for ~0.5s (6 x 100ms), then keeps the last sign-in read whole there,
  as the CLI does ("auth reload: auth.json unreadable, keeping previous
  credentials", in its binary's strings). Torn with nothing read before
  is an error saying it couldn't be read, with no signIn mark. No
  auth.json.lock is taken: it is the CLI's flock around its renewal,
  Node can't take a flock, and holding it could only delay a renewal.

Changed tests: signin.test's 401 now has no CLI and expects the no-CLI
message beside Grok's body; usage.test and models.test the same; a
private home's "not signed in" says to add the account again.

Run (worktree at 59990e1, PATH without ~/.grok/bin and ~/.local/bin so
no real grok is found; TMPDIR and HOME in a fresh temp dir):
- packages/grok: bun test, 82 pass 0 fail
- repo: bun test, 2166 pass 0 fail across 189 files; bun scripts/check.mjs ok

Broken by hand (renew.test.mjs, 9 tests):
- old index.mjs: all 9 red
- TORN_TRIES = 1: the mid-write test red
- no last-good fallback: the stays-torn test red
- unchanged token not caught after renewal: the three couldn't-renew
  tests (request private home, request shared home, models) red
- shared() always false: the shared-home message test red

Not tried: the real Grok Build CLI or a real Grok account (the fake CLI is
/bin/sh, fetch is a stand-in); a real 401 from Grok before expires_at; a
CLI writing auth.json in place while it is read (the torn file is
written by the test); a body that is a stream (not resent, as before:
only a string or no body is retried); Windows. magpie's mover min for
grok is not raised here.
2026-10-23 03:02:09 +08:00

17 lines
536 B
JSON

{
"name": "@magpie-community/opencode-grok-auth",
"version": "0.2.1",
"description": "OpenCode provider plugin: Grok (SuperGrok / X Premium+) through the Grok Build CLI's sign-in",
"type": "module",
"main": "./index.mjs",
"exports": "./index.mjs",
"files": ["index.mjs", "README.md"],
"keywords": ["opencode", "opencode-plugin", "grok", "xai", "supergrok"],
"license": "MIT",
"repository": {
"type": "git",
"url": "git+https://github.com/magpie-community/plugins.git",
"directory": "packages/grok"
}
}