37 Commits
Author SHA1 Message Date
yetone 0135b7b0ea agy-cli 0.1.32: the first model list after warming has agy's Claude and GPT models (#1064)
On a signed-in agy, `agy models` takes about 4.4s and `agy acp`'s
session/new about 3s. provider.models() needed three calls before
claude-opus-5-5, claude-sonnet-5-5 and gpt-oss-120b showed up, and
OpenCode 2.x calls it once.

What changed:
- packages/agy-cli/index.mjs:
  - The offered-model probe now starts in listAgyModels' .then, as soon as
    a non-empty list arrives and a caller asked for probeOffered. It no
    longer waits for the next models() call. A hung or failed `agy models`
    still never spawns the probe.
  - probeSignedIn reuses the `agy models` stdout it already has. The same
    parser (parseAgyModels, split out of listAgyModels) fills
    cachedModelCatalog, and the probe starts. Sign-in waits for the probe
    for at most 3s.
  - The offer (acpOfferedModels, acpOfferedKey, offeredProbeAt and any
    in-flight probe) is forgotten when agyPath changes and after a new
    sign-in finishes. A generation counter drops the answer of a probe
    that started before the reset.
  - provider.warming() returns a promise while a list or probe is still
    running, and null when nothing is.
- scripts/opencode2.mjs, copied byte for byte to every
  packages/*/opencode2.mjs: after the first background refresh, the
  adapter awaits hooks.provider.warming() once, for at most 60s, and then
  refreshes once more. It does not loop. Plugins without warming() behave
  as before.
- Not done: the issue's on-disk catalog cache (point 3), skipped as asked.

Known gap: agy-cli has no `config` hook, so under OpenCode 2.x the adapter
lists no provider for it. refresh() returns before it calls
provider.models(), so the follow-up refresh can't add agy's models on 2.x
until agy-cli gets a config hook.

Tests: test/testkit.mjs's fake agy takes a sessionNewDelayMs. The new
tests in test/catalog.mjs set 1.5s on both `agy models` and session/new
and wait for state through warming(), with no fixed sleeps:
- On a slow cold start, the first models() after warming lists Claude and
  GPT, from one probe spawn.
- authorize() on a signed-in agy fills the catalog, and the next models()
  runs no second `agy models`.
- The sign-in wait is bounded: with a 6s session/new, sign-in returns in
  about 4.5s.
- Changing agyPath probes again.
The hang test now awaits warming() before it counts acp spawns.
scripts/opencode2.test.mjs: the warming list is read a second time when
warming ends, and only once when nothing is warming.

Run on Linux (a separate test Mac was over its load limit):
- packages/agy-cli bun test: 17 pass, 0 fail.
- bun scripts/check.mjs agy-cli: ok.
- bun scripts/check.mjs (all packages): ok.
- Root bun test in a temp HOME: 8530 pass, 19 skip, 0 fail.

Broken by hand on Linux, each red, then restored green:
- No probe in the .then: the slow cold-start test.
- probeSignedIn drops the list: the authorize and bounded-wait tests.
- agyPath change keeps the old offer: the agyPath test.
- Unbounded sign-in wait: the bounded-wait test (7514ms).
- Probe also on a failed listing: the hang test.
- origin/main's index.mjs with the new tests: all four #1064 tests.
- Adapter reads the list once: the warming adapter test, and the
  copy-identity check.

Not tried: a real agy (no Google sign-in, no network). The reset after
login.finish has no unit test of its own.

Reported-by: hiee3
2026-11-13 10:59:13 +08:00
yetone 740e1af252 tests: grok's nocli puts PATH back when its file ends, so gumloop's Node children find node on CI
publish.yml has been red on main since 7ebab07c (run 43011771755, and
43012668584, 43012789287 after it): 4 of gumloop's regression tests
failed with `Executable not found in $PATH: "node"`, so dist and npm
were skipped and gumloop 0.1.0 and agy-cli 0.1.19 reached neither.

Cause: bun test runs every file of the root run in one process.
packages/grok/nocli.mjs sets PATH=/usr/bin:/bin (and HOME, USERPROFILE,
GROK_HOME, GROK_BIN_DIR) for grok's files and never put them back, so
every file after grok's ran with that PATH. On ubuntu CI node is
actions/setup-node's, under /opt/hostedtoolcache, so gumloop's
spawn("node") found none whenever bun ran grok's files before
gumloop's (CI's order). Locally bun ran gumloop first, so it passed.

Change:
- grok/nocli.mjs: the first noRealGrok of a file snapshots process.env
  and registers an afterAll that puts it back, removing what was added.
- gumloop/regression.test.mjs: node's absolute path is found once with
  Bun.which at load and spawned by path; not found, the Node tests fail
  as before (no skip).
- Siblings the same way (a file-level env change never put back), found
  by a full-run env audit: chat/chat.test.mjs (XDG_CONFIG_HOME pointing
  at its deleted temp dir, MAGPIE_API_KEY/GATEWAY_KEY/ADDR deleted) and
  cursor/calls.test.mjs (XDG_DATA_HOME) now restore them in afterAll.
  window-warmup's fake-gateway.ts/scheduler.test.ts XDG pins are left,
  filed as #996 (fake-gateway is also the --serve demo's).
  Other PATH writers (devin, gcp-ai, grok's own tests, sap-aicore,
  agy-cli, layerfs) already restore theirs; the audit saw PATH change
  only at grok's files.

Ran (magpie-desktop WSL, node only in ~/sdk/node/bin, bun 1.4.2):
- Red first, origin/main: `bun test --randomize --seed=3` (and 5) on
  grok/loop-check + gumloop/regression: the 4 CI failures, same error;
  also with --preload ./packages/grok/nocli.mjs.
- Same seeds with this change: 95 pass 0 fail (new gumloop test plus
  origin/main's copy of it).
- Broken by hand: afterAll(putBack) commented out -> both seeds red
  again, 4 fail.
- Root `HOME=$(mktemp -d) bun test` (with an env-audit preload): 8298
  pass, 19 skip, 0 fail, 8317 tests, 584 files; PATH back to the start
  value at the first file after grok's.
- Touched packages (chat, cursor, grok, gumloop, qoder) after the
  chat/cursor change: 1117 pass 0 fail, each XDG value back to start.

Not tried: ubuntu CI itself before pushing (publish.yml runs it next);
Windows (nocli sets PATH empty there, restored the same way).
2026-11-11 19:53:46 +08:00
yetone 9696b6f37a grok 0.2.7: speech to text through xAI's /v1/stt, the one Grok Build's voice dictation uses (CoderCCz on X)
magpie's /v1/audio/transcriptions form (OpenAI's) is sent on to
api.x.ai/v1/stt signed as the CLI signs: the audio byte for byte, language
passed on, OpenAI's model left out (xAI answers 404 to any id but its own),
json/text/verbose_json answered in OpenAI's shapes, srt/vtt and
translations refused. cli-chat-proxy has no stt route (404), api.x.ai takes
the Grok Build token.

Images: an input_image in a Responses request already goes through
unchanged and the models say image input; a real request with a 64x64 PNG
answered "Red" through the plugin's own fetch. A 8x8 one is Grok's own 400
(minimum 512 pixels).

Run: bun test in packages/grok (112 pass), mote. Broke by hand: with the
transcription branch out of fetch, 4 of the 5 new tests go red. Real
account: the plugin's fetch with ~/.grok's sign-in transcribed a say(1)
wav ("Hello world, this is a test.") as verbose_json and described a
red PNG. Not tried: through a built magpie gateway.
2026-11-11 03:06:03 +08:00
lxyer ae51883634 grok 0.2.6: a stream cut before its first byte is asked again (#852)
A Responses stream from Grok that dies before its first byte (the
connection reset, nothing sent yet) is asked again, up to three times,
before the answer is returned. A retry's own answer is noted, so a 429
or 401 on a retry comes back as itself, not folded into a 200.

Once a byte has arrived, response.created and reasoning included, the
stream is passed on at once, one upstream chunk per pull, and cancelling
it cancels the upstream read. A later cut is not asked again and nothing
is written in its place: the stream ends, and magpie 0.1.3298 or newer
(yetone/magpie 29bfd5dc8) closes it as a whole response.failed with
created_at and sequence_number. The frames 0.2.6's first version wrote
had no sequence_number, and Grok Build failed the turn on them. An
upstream response.failed, error or response.incomplete is passed on
unchanged, and an end with no bytes is not asked again.

Run on mote (macOS 27), at 463afb79, each in a temp HOME:
- packages/grok `bun test`: 107 pass, 0 fail.
- `bun scripts/check.mjs grok`: ok.
- Repo-root `bun test` with HOME=$(mktemp -d): 6878 pass, 20 skip,
  0 fail. A first run with HOME under /tmp had 21 reds in devin, zcode
  and sap-aicore. Those tests refuse a HOME outside $TMPDIR, and
  plugins main ecab8396 had the same reds under that HOME.
- Broken by hand, cut-retry.test.mjs goes red:
  - STREAM_TRIES=1: 3 fail;
  - the retry's note() removed: the 429 test fails;
  - cancel() not passed upstream: the cancel test fails;
  - "aborted" counted as a cut: the abort test fails;
  - a later cut erroring the stream instead of ending it: 2 fail.
  Asking again after a zero-byte clean end is the one break no test
  catches.
- Real chain: Grok Build 1.0.67 and 1.0.77 (x.ai's own build, the
  reporter's version), then magpie eef99e4bb (`magpie serve`, sandbox
  HOME), then this plugin (BASE pointed at a fake), then a fake Grok
  upstream:
  - ok: "pong".
  - Cut before the first byte, then ok: "pong", with the retry inside
    the plugin.
  - Cut, then 429: magpie logs a 429 from Grok, and Grok Build retries
    on "rate limited".
  - Always cut before a byte: an empty 200, which magpie reports as a
    retryable 502. Grok Build retries it as server_error.
  - Cut after response.created, and cut after text: magpie's
    response.failed ("the reply ended before it was complete"). Grok
    Build reads it and retries it as server_error. No "missing field"
    in either version.
  - Upstream response.failed: one call, and Grok Build shows the
    vendor's own message.

Not tried: a live Grok stream cut by the real vendor.
2026-11-08 12:42:31 +08:00
我是一条没有名字的区 087c36123d inkstone 0.1.3: image-caps preflight, a zero-prompt browser sign-in, key calls on the session cookie (#832)
inkstone 0.1.3 (#832, yunwang2442-creator):

- Image requests are prechecked before they leave: 8 images, 10MB each, 40MB in all.
  - A request over a cap gets a local 400 shape refusal, so magpie asks the next account and rests none.
  - The plan's invalid_media / media_fetch_failed / unsupported_media_type errors become the same kind of refusal.
- The body rewrite strips the reasoning fields and sets image detail to auto.
- A zero-prompt browser sign-in comes first, and a second browser method reuses a pasted key.
  - Neither browser method is offered when no Chromium-family browser is found (#825).
- The /keys calls ride the session cookie, without the pagination query. Key creation retries the console's -15100 "refresh page and retry".
- The #826 metadata token read is kept, and its test is back.
- The fake browser is built once per user and source hash (#824), and the title wait reads only on Windows.
- maxConcurrency is 4.
- The doubled comment line is dropped from every opencode2.mjs copy, agy-cli's included.

Reviewed at 88e66bde, on mote (macOS, Bun 1.4.2) with a temp HOME:
- full bun test: 6853 pass / 0 fail; both checks exit 0
- bun scripts/check.mjs and bun scripts/check.mjs inkstone: exit 0
- 21 hand breaks: 20 red, 1 not caught (the /keys pagination test calls protocol.listKeys directly; follow-up filed)

Not tried: a real InkStone account or sign-in, Windows and Linux runs.
2026-11-07 22:24:56 +08:00
我是一条没有名字的区 e7004d9354 inkstone 0.1.0: Intern InkStone (书生·端砚) Token Plan, browser sign-in, credit card and ink-* key chat (#775)
New package @magpie-community/opencode-inkstone-auth 0.1.0 for Intern
InkStone (书生·端砚, Shanghai AI Lab) Token Plan, provider id
`intern-inkstone`. Community package by yunwang2442-creator.

What it does:
- Browser sign-in (Edge/Chrome, its own profile under
  $XDG_CONFIG_HOME or ~/.config/magpie/inkstone-browser, or
  %LOCALAPPDATA%\magpie\inkstone-browser). The login window has no
  debugging port. A headless CDP read takes the uaa-token cookie, and the
  same read renews it silently later.
- Usage card: ink-credit balance, 5-hour and 7-day windows, credit packs.
- Chat: a pasted ink-* API key, or one the sign-in creates, named
  ink-<host4>-<acct4>-<rand4> (18 of the console's 20 characters). An
  idempotency clash (-15109) retries with a fresh name, up to three times.
  Pruning is on by default. It only touches this machine's and account's
  prefix, keeps the newest two and the key this sign-in created, and never
  deletes manual keys or keys of unknown age.
- Closing on Unix: SIGTERM, then SIGKILL only after a 15s grace. Leftover
  browsers are matched by --user-data-dir=<escaped profile>, and Windows
  uses .Contains().
- The login wait comes from an injected waitForLogin in tests. No env
  hook is left in production code.
- Hosts: discovery.intern-ai.org.cn, discovery-api.intern-ai.org.cn,
  127.0.0.1 (CDP).

Outside the package: scripts/opencode2.mjs lets a prompt with
`required: false` stay optional (`p.required !== false`). Every package's
copy is synced byte for byte, so all 39 copies in the merged tree are blob
afe074cb. No other package sets `required: false` on a prompt, so this
changes nothing for them. Also a root README row and a registry entry.

Review at 36412a15, on mote, HOME=$(mktemp -d), Bun 1.4.2:
- bun test packages/inkstone: 68 pass, 0 fail in Asia/Shanghai, UTC,
  America/Los_Angeles and Pacific/Kiritimati.
- bun scripts/check.mjs inkstone and bun scripts/check.mjs: ok.
- bun test (repo), on 36412a15 merged with origin/main e7cb9dc5:
  6743 pass, 20 skip, 0 fail. main has since moved by cline 0.1.14 and
  zcode 0.1.55 only, and none of the adapter copies changed.
- Broken by hand, each red: no protectName protection; prune_keys default
  off; no post-sign-in prune; no SIGTERM on close; the -15109 retry keeping
  its name.

Not tried: a real InkStone account sign-in on macOS, Linux or Windows (no
account here); a live chat request; magpie end to end with the plugin.
2026-11-07 15:07:06 +08:00
yetone 5bbdb82660 grok 0.2.5: a 401 that isn't Grok judging the token, on one Grok Build left good, is a 503 that passes, not "add the account again" (#818)
zane668 got 401 {"error":"Authentication required"} a few times a day on
tokens not near their end. grok models left the same token, so the
plugin said "couldn't renew the sign-in ... add the account in magpie
again", yet the same token answered 2-5 minutes later.

What tells the two apart: cli-chat-proxy answers a token it doesn't take
at once with "Invalid or expired credentials (auth_kind=..., upstream=
Unauthenticated|PermissionDenied, reason=...)" (curl'd 11-07 with made-up
tokens, signed and unsigned, on /models, /responses, /chat/completions,
/billing: each in under 1.5s). "Authentication required" after 78-114s
is not that verdict.

Now, after a 401 on a request, model list or usage read whose renewal
leaves the token as it was:
- the body is not "Invalid or expired credentials", the token is not
  past its end, and grok models didn't exit with an error (it ran, or
  was still running): a 503 with Retry-After: 60, X-Magpie-Sign-In: kept,
  code auth_refused_transient, saying what Grok said, how long it took
  to answer, and that no new sign-in is needed. magpie's gateway reads a
  503 as before (failOther: a short backoff rest, the next account
  asked), so routing is unchanged; only the advice and status change. A
  model list or usage read gives the same words, with no sign-in mark.
- otherwise as before: "couldn't renew the sign-in", sign in again.
- the wait on Grok Build's renewal after a 401 is capped at 15s; the run
  goes on and the next asker takes what it gave. The message names
  grok models' own run time when it is 1s or more.

Where the 78-114s went: the plugin's own part is grok models, capped at
30s by execFile before and at 15s now. grok models "ran" (exit 0) in the
report, so it took under 30s; the rest, at least ~50s, was Grok's answer
to the request. zane668 saw "no first token in 120s" and ECONNRESET on
other vendors in the same windows, so the wait is upstream/network and
the plugin doesn't bound it. The message now says both times, so the
next report shows the split. Not done: the report's suggestion to resend
after a few seconds; the refusal lasted minutes and each try waited
over a minute, so handing over at once is faster.

Left ambiguous: a token xAI revoked but answered with words other than
"Invalid or expired credentials" would now read as passing and keep
being retried with short rests; a revoked real token was not available
to see its words.

Run at this tree:
- packages/grok bun test on mote: 96 pass, 0 fail.
- repo bun test (HOME=$(mktemp -d)) on the Linux VM (wsl-run,
  magpie-desktop): 6571 pass, 19 skip, 0 fail. Not on mote: its suite
  lock had a 3h GUI run and four Go suites queued.
- bun scripts/check.mjs grok on mote and Linux: ok.
- Real: the plugin against the real cli-chat-proxy with a made-up token
  and a fake grok models leaving it: 401 sign_in_unrenewed, Grok's
  "Invalid or expired credentials (... upstream=PermissionDenied ...)"
  quoted, after 1s.

Broken by hand (renew.test.mjs, 15 tests): old index.mjs fails the 503,
bounded-wait, model-list and usage tests (4); passing() without the
TURNED_AWAY check fails 3 (two old tests and the new verdict test); the
CLI's failure ignored fails the exit-1 test; no 15s bound fails the
bounded-wait test (2013ms); models and usage not passing Grok's words
each fail their test.

Not tried: a real "Authentication required" 401 (it can't be called up),
a revoked real token, a real Grok Build slower than 15s.

Reported-by: zane668
2026-11-07 09:52:36 +08:00
yetone 17e5ef7457 all: load on OpenCode 2.x through a default {id, setup} (#657)
nbczw8750 (#657): trae 0.2.26 on OpenCode 2.2.5 fails with "Plugin
must export a default definition with an id and an effect or setup
function. (cause: SchemaError(Missing key at ["default"]))". 2.x
imports a package's exports["."] (a plugin dir and an npm install
alike) and has no V1 path at all, so every package here that serves
models failed the same way, not only trae.

Every one of the 32 model packages now has:
- opencode2.mjs, exports["."]: a copy of scripts/opencode2.mjs, an
  adapter that runs the package's V1 plugins inside 2.x's promise
  API. Config providers become 2.x providers (package pinned so the
  aisdk sdk hook runs), V1 auth methods become integration methods
  (oauth auto/code with forms; api without authorize as a key method),
  V1 credentials are kept in metadata.v1, the loader's baseURL,
  apiKey, headers and fetch are applied through the sdk hook, an
  auth.set renewal is stored per credential, and credential.switched
  /updated reload the account's own model list.
- opencode.mjs, main: re-exports the V1 plugin functions only.
  OpenCode 1.x and magpie's host.js take main. On 1.x, trae 0.2.26's
  main exported a non-plugin (_internal) and 1.19.5 refused it ("Plugin
  export is not a function"); the new main fixes that too.
- both files in "files"; patch version bumped. devin already had 2.x
  and is unchanged.

scripts/check.mjs fails a model package whose 2.x entry has no default
{id, setup}, whose opencode2.mjs differs from the canonical one, whose
entry is missing from files, or whose main exports a non-plugin.

Run at this head (mote):
- HOME=$(mktemp -d) bun test, as CI runs it: 4900 pass, 0 fail
  (4914 tests, 374 files). A first run set globalThis.fetch for the
  whole process from opencode2.test and failed 528 tests in other
  packages; the block is now set and put back around that file's tests.
- bun scripts/check.mjs: every package passes. With the network
  blocked cloudflare-workers-ai fails on its fetched catalog, the same
  on origin/main.
- Real OpenCode 2.2.5 (npm opencode-ai), sandbox HOME, packed trae
  0.2.27: loads with no error; /api/integration lists trae-cn "Trae CN"
  and trae-global "Trae Global" with their browser sign-ins; `auth
  login` starts the trae.cn authorization and waits (cancelled there);
  with a fake credential POSTed to /api/credential, `opencode models`
  lists trae-cn's six models.
- Real 2.2.5 with a fake V1 key plugin through the same adapter
  against a local fake server: `auth login` with a key, `models`,
  `opencode run` reached /real/v1/chat/completions with the loader's
  "Bearer loader-sk-fake" and header, and printed the fake's reply;
  with @ai-sdk/anthropic it reached /real/v1/messages with x-api-key
  from the loader. This run found the key method missing after 2.x's
  second integration transform (a once-only flag outside the
  transform); fixed, and opencode2.test checks a rebuild.
- Real OpenCode 1.19.5, sandbox HOME, trae 0.2.27: `opencode models`
  lists trae-cn and trae-global models; 0.2.26 failed there.

Broken by hand (scratch copy, bun test scripts/ and check.mjs):
- trae's exports back to "./index.mjs": the trae 2.x test fails
  (default.id undefined), check fails trae with "OpenCode 2.x:
  ./index.mjs has no default {id, setup} (plugins#657)".
- zed's opencode2.mjs changed: the copies test fails, check fails zed
  "differs from scripts/opencode2.mjs".
- the key flag back outside the transform: the 1.x plugin test fails
  on the rebuilt sign-ins (key missing).

Not tried: a real sign-in with a real account on 2.x; Windows (the
reporter's OS); chat.headers, chat.params, usage and tool hooks, which
the adapter doesn't carry to 2.x; the tools/pages packages (calc,
goanyapi, layerfs, search1api, aelios, agent-console, chat,
fingerprint, nowledge-mem, kimi-desktop), which still load only on 1.x.
2026-11-03 13:54:26 +08:00
yetone 254c3e7aef grok 0.2.3: Codex's output.encrypted_content is left out of include (#524)
Codex asks an OpenAI-named provider for output token replay with
include ["reasoning.encrypted_content", "output.encrypted_content"]
(codex-rs/core/src/client.rs). Grok answers 400 'Argument not
supported: "output.encrypted_content" in "include" field'. rewrite()
now drops that one value (and include when nothing is left), and its
pre-filter also opens a body that names it, so an include-only body is
no longer passed through untouched. reasoning.encrypted_content and the
tool-output values xAI's docs list stay; store is not touched (Grok
takes it).

Tests: packages/grok/include.test.mjs, from the reporter's two bodies
and Codex's include. Red on the old index.mjs (4 of 5; the 5th checks
that accepted values stay). Broken by hand: without the pre-filter
change the include-only case is red.
Run on mote: HOME=$(mktemp -d) bun test (3782 pass, 0 fail) and
bun scripts/check.mjs (exit 0).
Not tried: a real Grok account; no Codex turn sent through Grok.
Sealed copies an OpenAI model wrote earlier in a thread (encrypted_content
on a message) are not stripped here; magpie's forVendor takes those out
before a non-OpenAI provider.
2026-10-30 18:45:39 +08:00
yetone 9608d0311d grok 0.2.2: Responses requests ask for Grok Build's loop checks (yetone/magpie#3594)
Grok Build 1.0.67 sends `x-grok-doom-loop-check: 1024` and
`x-grok-exact-repetition-check: 64` on every /v1/responses request
(seen in a mitm capture of the real CLI; the strings are in its binary
next to "server reported doom-loop triggers for this response"). The
plugin sent neither. Without them cli-chat-proxy lets a reply that
repeats itself run on: it cut "* " repeated after ~4,265 output tokens,
and a looser loop runs to max_output_tokens (128000 from Pi). That is
the "repeats until max output, ends in Internal error during token
generation" of #3594, seen on Pi -> magpie -> Grok but not in Grok
Build. The fetch now sets both on a Responses request unless the
caller set them already.

Ruled out while diffing the CLI's request against magpie's: the system
prompt. `instructions`, a system message and a developer message in
`input` all reach the model (same input_tokens, 1266 vs 1249 without,
same reply), so magpie's `instructions` is not lost.

Run:
- bun test in packages/grok on mote: 85 pass 0 fail.
- bun run check (whole repo) on mote: exit 0.
- Broken by hand: loop-check.test.mjs against index.mjs at HEAD:
  2 of 3 fail (the headers are missing); with the change 3 pass.
- Real account (owner's SuperGrok, sandbox magpie on origin/main with
  this plugin from disk, requests through mitm): the same "* " x3000
  prompt over /v1/responses, /v1/chat/completions and /v1/messages each
  carried both headers upstream and was stopped after ~1,020 deltas
  (~1K tokens) with "Internal error during token generation", against
  ~4,265 tokens without the headers (direct curl, earlier).

Not tried: the CLI's client-side doom-loop recovery (it resamples a
confident tool-call loop with a reminder). The proxy's
response.doom_loop_check event (a soft loop it reports, not stops)
goes through as it came and nothing acts on it yet.
2026-10-30 06:51:57 +08:00
yetone 5ab7df285b grok tests: no test finds an installed Grok Build (#325)
Some grok tests looked Grok Build up as the plugin does and ran what they
found (`grok --version`, `grok models`). On a machine with Grok Build
installed that ran the real CLI, which can reach xAI.

packages/grok/nocli.mjs is imported first by every grok test file, and
each calls noRealGrok() before reading its environment. It sets every
place executable() looks:
- PATH: /usr/bin and /bin only (the fakes' scripts run cat, rm, sleep),
  each left out if it holds a grok; empty on Windows.
- GROK_BIN_DIR: a folder that doesn't exist; GROK_HOME: an empty folder.
- HOME and USERPROFILE: an empty folder, for ~/.grok/bin and
  ~/.local/bin. Bun's os.homedir() keeps the HOME the process started
  with (checked: setting process.env.HOME doesn't change it), so the
  helper mock.module()s node:os with a homedir that reads HOME
  (USERPROFILE) at call time, as Node's does, before index.mjs loads.
  Other packages in the same run see Node's behaviour: the started HOME
  unless a test changed it.
A test that wants a CLI still puts its fake in GROK_BIN_DIR.

Marker proof: a fake grok (under a .grok folder, so it counts as Grok
Build) that appends its argv to a marker file, placed on the outer PATH,
in ~/.local/bin and ~/.grok/bin under the test HOME. Run as
TMPDIR=$H HOME=$H/home PATH=$H/outer:$PATH bun test:
- old tests (92d5557), packages/grok: marker written, 5 runs (1 `grok
  --version`, 4 `grok models`, from ~/.grok/bin under the test HOME),
  78 pass 4 fail
- new tests, packages/grok: no marker, 82 pass 0 fail
- new tests with the mock.module line commented out: marker written
  again (same 5 runs), 78 pass 4 fail
- new tests, whole repo: no marker, 2166 pass 0 fail across 189 files
- bun scripts/check.mjs: ok (no version bump: test-only change)

Not tried: Windows; a run with the real HOME (the marker run covers the
same folders under a test HOME); the real grok was never run.

Closes #325
2026-10-23 03:19:41 +08:00
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
Vector 1ea9223e83 grok 0.2.0: opt-in native X search (#263)
An option on the grok provider, "Native X search" (auth.options key
x_search, off by default), read through magpie.option on each fetch.
When on, a Responses request whose tool_choice is auto, or absent with
tools declared, is offered Grok's native {"type":"x_search"}. none,
required, a named tool, allowed_tools and an x_search choice add nothing;
an x_search already declared keeps its filters and isn't duplicated; a
request with neither tools nor a tool_choice is left alone.

Reviewed at 99e602006 (vectorisvector). Run at that head:
- HOME and TMPDIR in a scratch dir, bun test: 2040 pass, 0 fail;
  bun scripts/check.mjs: ok; PR CI run 39532960081 green (attempt 1 was
  only awaiting approval)
- broken by hand, each red: on by default 4 fail, option ignored 2, every
  path 1, tool_choice ignored 5, duplicate x_search 1, inject after
  tools filtered 1, both no-tools guards removed 1, non-array tools 1,
  wrong provider id 1, no injection 10
- magpie gateway at ba319a758 with this plugin loaded (BASE pointed at a
  fake upstream), option off/on/off: Chat, Anthropic and Gemini (whole and
  streamed) with a function get x_search; their tools-off "none" and
  Chat/Anthropic required, named and no-tools requests don't; Responses
  auto (whole and streamed) gets it, none doesn't, an existing x_search
  is kept once; no upstream body names magpie; an x_search_call item in
  the reply doesn't reach Chat/Anthropic/Gemini clients
- one gap on magpie's side: an allowed_tools choice is dropped by the
  gateway before the plugin can read it, so it gets x_search; filed as
  yetone/magpie#3153

Not tried: a real Grok account.
2026-10-21 16:19:26 +08:00
yetone aee6b9de5e grok 0.1.18: a tool_choice with no tools beside it is left out before Grok (yetone/magpie#3110)
magpie now hands a request that turned tools off with none declared
(Chat's tool_choice "none", Anthropic's {"type":"none"}, Gemini's
functionCallingConfig NONE) to a Responses plugin as tool_choice "none"
with no tools, so a plugin that adds a server-side tool (x_search, #263)
can tell it from no choice. Grok's backend refuses a tool_choice with no
tools ("A tool_choice was set on the request but no tools were
specified", yetone/magpie#378), which magpie's grokBody used to leave out
for the plugin. rewrite now leaves out any tool_choice with no tools, or
none left after the dropped types, as the built-in's grokBody does.

What was run:
- TMPDIR=<scratch> HOME=<scratch>/home bun test: 2018 pass, 0 fail.
  (HOME outside os.tmpdir() trips zcode's isolated-home guard: 19 fail,
  2 errors, all that guard; not this change.)
- bun scripts/check.mjs: passes.
- tool-choice.test.mjs against origin/main's index.mjs: 1 pass, 1 fail
  (the lone-tool_choice case), green with this change.
Not tried against Grok's live backend.
2026-10-21 09:59:50 +08:00
yetone 47fbf634e7 grok 0.1.17: the sign-in page opens once, not twice (andyfmyth on X)
"magpie里的grok 登录验证 在mac下 似乎每次都会弹两次验证, 在浏览器窗口里":
`grok login --device-auth` (Grok Build 1.0.50, the webbrowser crate)
opens the device page itself, and magpie opened the same URL again.

Reproduced in a sandbox HOME/GROK_HOME on macOS: grok's own device-code
tab appeared in Chrome with magpie not involved, with and without
SSH_CONNECTION set. What decides grok's own open, from the binary's
strings and webbrowser 1.2.4's source:
- macOS: NSWorkspace, $BROWSER never read (the macOS binary has no
  "BROWSER" string);
- Windows: ShellExecuteW, no $BROWSER either;
- Linux and the rest: $BROWSER, else xdg-open, skipped with no display.

So the sign-in now says `opened: true` on darwin and win32 (magpie then
opens nothing; magpie >= the commit that raises the grok mover min reads
it), and elsewhere gives grok BROWSER=true, a no-op, so the opener stays
the only one to open the page. OpenCode ignores the extra field.

Tests: login.test.mjs runs the sign-in as darwin/win32 (opened, $BROWSER
untouched) and linux/freebsd (not opened, BROWSER=true reaches grok).
Both fail on 0.1.16's index.mjs (10 pass, 2 fail).

Run: HOME=<scratch> bun test packages/grok: 49 pass, 0 fail;
bun scripts/check.mjs: exit 0.
2026-10-19 11:29:05 +08:00
yetone 8cdf2d2020 grok 0.1.16: a sign-in with no email is kept by its xAI user id, and a login that leaves none says where it looked (llllleo9 on X)
llllleo9 couldn't add Grok: grok login --device-auth exited 0, and the
sign-in failed with "grok login finished without an account".

Grok Build 1.0.62 was run in a sandbox HOME. The stand-in auth.x.ai sat
behind an HTTPS_PROXY MITM, with its CA passed through
GROK_EXTRA_CA_BUNDLE, and sandbox-exec denied opening a browser. The CLI
takes email and user_id from the id_token's claims alone. With no email
claim (an xAI account signed in through X), it writes "email": null and
still prints "✓ Signed in". When Grok Build's own home is already signed
in, the plugin signs in beside it and demanded an email, so that sign-in
failed.

- An account is now told apart by its email, else its user_id, else the
  token's sub. saved() and the refresh path's remember() use the same
  account id.
- GROK_AUTH_PATH is now left out of the CLI's run. With it set, 1.0.62
  keeps the sign-in at that file, and the home the plugin reads stays
  empty (seen in the same sandbox). The login always runs with envFor(home)
  now, not process.env.
- A login that finishes with nothing readable now says what grok said,
  which file it read and what was there (no file, not JSON, no token,
  or no account). It also points to "Use Grok Build's current sign-in".

Run:
- TMPDIR and HOME set to a scratch dir, bun test packages/grok: 47 pass,
  0 fail. The six new login tests FAIL with 0.1.15's index.mjs.
- bun scripts/check.mjs grok: ✓.
- node --check and git diff --check are clean.
- The plugin was run against the real grok 1.0.62 and the stand-in x.ai,
  with the CLI home already signed in:
  - id_token without email: 0.1.16 returns success with accountId
    "user-1". 0.1.15 returns "grok login finished without an account",
    the reporter's message.
  - GROK_AUTH_PATH set: 0.1.16 returns success, 0.1.15 fails the same way.
- login.test's "a login's link is still handed on" timed out at 5s in 2 of
  10 runs alone, on 0.1.15's code too. That is #160, which another session
  has taken; the data point was added there.

Not tried with a real xAI account: whether xAI's token for llllleo9's
account lacks the email claim, and whether their Grok Build was already
signed in.
2026-10-19 00:22:52 +08:00
yetone 9cfc18ae52 grok 0.1.15: a sign-in without Grok Build says GROK_BIN_DIR takes one put in a folder of your own, not only the curl installer (yetone/magpie#2223, evier12345)
In magpie's Docker image there is no curl to run xAI's installer, and a
grok binary dropped on PATH outside a .grok folder isn't taken (isGrokBuild
keeps another program named grok out). GROK_BIN_DIR already took one as it
is; the error now says so, and the README says where the CLI is looked for.

Run: TMPDIR=<scratch> HOME=<scratch home> bun test in packages/grok (41
pass, 0 fail); bun scripts/check.mjs grok (✓). With index.mjs put back to
0.1.14, import.test's "no Grok Build … is refused first" fails on the new
GROK_BIN_DIR assertion. Not tried in a real container from this commit;
magpie's own fix (installing Grok Build before `magpie plugin login grok`)
is in yetone/magpie.
2026-10-15 00:33:49 +08:00
yetone f98026557e grok 0.1.14: a window offered without a k (grok-4.7@131072) asks Grok for that model at that window (yetone/magpie#1679)
labelOf writes a window no multiple of 1000 as its digits alone, so
windowsOf offers grok-4.7@131072 beside grok-4.7@500k. modelOf read only
"<n>k", so that id went to Grok as an x-grok-model-override of its own
("grok-4.7@131072", a model Grok doesn't list) with no
x-grok-context-window. It now reads the digits as the window itself, and
a k as thousands, as the built-in's grokWindowed does after
yetone/magpie#1679 (ggbdpq's patch). An id with no model before the @,
or a window of 0, is no window, as the built-in reads it.

Not tried against Grok: today every window xAI lists is a multiple of
1000, so no real model is offered without the k.

Run: TMPDIR and HOME set to an empty scratch dir, bun test
packages/grok: 41 pass, 0 fail. The new test FAILs with modelOf put
back (expected { model: "grok-4.7", window: 131072 }, got the id as a
model with window 0). node --check packages/grok/index.mjs, bun
scripts/check.mjs grok and git diff --check are clean.
2026-10-13 09:53:12 +08:00
yetone 6f1605f01d grok: the login and refresh tests' fake CLI is /bin/sh, not a script just written, so a busy Mac doesn't time them out (#65)
What waited was not a timer in the tests. On macOS the first run of an
executable just written waits for the system's scan of it: 4-15s each
here on a busy machine (a fresh `#!/bin/sh` file timed at 3.8-15.4s on
its first run, 0.00s after; a hard link or symlink to a scanned file, or
the same file read by sh, 0.00s). login.test.mjs wrote a new fake per
test, refresh.test.mjs one per file, so each paid it inside a test.

The fake grok is now a symlink to /bin/sh, and the plugin's own
`grok models` / `grok login --device-auth` become `sh models` /
`sh login …`, which read a plain script in the folder the plugin runs
the CLI in (root above the account's home; the home folder for login,
which login.test.mjs now only uses when HOME is a temp home). No
timeout was raised; refresh's `sleep 0.2` (for the joined-run test)
stays.

Run:
- With 14 `yes` burners of mine (load ~45): origin/main's two files
  5 and 6 fail (bun's 5s), this commit 0 fail in 1.5-1.9s, 3 runs.
- Idle: 10 pass, ~1.2s, 3 runs. Linux (oven/bun:1.4.2, /bin/sh = dash):
  10 pass.
- Broken by hand: links not taken (1 red), the CLI's last line not the
  reason (2 red), renewals not joined (1 red).
2026-10-12 18:22:47 +08:00
moxuunandyetone 01fdc091c0 grok 0.1.13: import a CLIProxyAPI (CPA) xAI account from its file (#92)
* grok 0.1.13: import a CLIProxyAPI (CPA) xAI account from its file

CPA (CLIProxyAPI) keeps each of its accounts in ~/.cli-proxy-api as a flat
JSON file: {type: "xai", auth_kind: "oauth", access_token, refresh_token,
expired, last_refresh, sub, email, disabled, …}. Its xAI accounts sign in
with the same OAuth client Grok Build does, so such an account is a sign-in
Grok Build can hold — but the plugin could only take the CLI's own sign-in
or make a new one, so an account that lives in CPA could not be used here.

The third sign-in method takes the path to one of those files, reads it and
writes Grok Build's own shape (key, auth_mode: "oidc", create_time,
user_id, email, refresh_token, expires_at, oidc_issuer, oidc_client_id)
into a home of the plugin's own, as a device-code sign-in does. The
imported file is only read, and only the fields above are carried over:
base_url is not honored and expires_in is not turned into a lifetime
measured from the import.

A file is refused, before any home is made, when it is not an enabled
(type xai, auth_kind oauth, not disabled) xAI account with tokens, identity
and timestamps, or when the token's own iss/aud are not the Grok Build
xAI ones. The refresh token rotates and both clients would spend it, so the
prompt and the README say to stop using the account in CPA first. Nothing
here refreshes a live token or touches CPA.

bun test: 39 pass on the grok package (4 new in import.test.mjs: the
translated home, the refusals, no Grok Build, and a home that can't be
made). bun scripts/check.mjs grok and node --check pass.

* grok: string timestamps, and import.test.mjs off POSIX

`Date.parse` coerces, so a `last_refresh` or `expired` that was a list or an
object read as a date: the file must say a string before it is parsed.

The test's fake CLI is named for the platform (`grok.exe` on Windows), PATH
joins with the platform delimiter, and the 0600 file is only checked where
POSIX gives it. The mkdir that fails is what the last test covers, not the
cleanup after a write that fails, and it now says so.

* grok: the import's placeholder names the file CPA writes, xai-<email>.json (review of #92)

CLIProxyAPI's xAI sign-in saves each account as xai-<email>.json
(internal/auth/xai/token.go CredentialFileName), not cpa_*.json.
Text only; import.test.mjs still 5 pass.

---------

Co-authored-by: yetone <yetoneful@gmail.com>
2026-10-12 18:16:23 +08:00
8260d97941 grok 0.1.12: a model Grok lists at two windows is offered at each (#83, guoqchen1001)
* grok 0.1.12: a model Grok lists at two windows is offered at each

context_window stays the plain id, so a saved grok-4.7 keeps the default
256k window. Each other size in context_windows is listed beside it
(grok-4.7@500k) with that window. A request for it sends the plain model
and x-grok-context-window: 500000, which is the window a client such as
Claude Code compacts against. The proxy serves up to its largest window
either way and refuses past it.

* grok: a window model's api.id keeps its @size, so x-grok-context-window is sent

The models hook gave grok-4.7@500k the api.id grok-4.7. magpie
(internal/provider/plugins.go, modelAPIID + withModel) and OpenCode's AI
SDK both put api.id in the request body, so the plugin's fetch only ever
saw grok-4.7 and never sent x-grok-context-window. api.id is now the
offered id; fetch strips the window (modelOf) before Grok sees the body.

Run: HOME=$(mktemp -d) bun test packages/grok (35 pass);
bun scripts/check.mjs grok. The new round-trip test (models hook ->
api.id -> fetch) is red on f4872fb and red again with the body rewrite
removed by hand. Real use against the owner's Grok account (copied
home): /v1/models lists 4 models at 256k and 500k; grok-4.7 and
grok-4.7@500k each answered 200, the latter with x-grok-context-window:
500000 and model grok-4.7 in the body.

---------

Co-authored-by: chenguoqing <chenguoqing@kemai.cn>
Co-authored-by: yetone <yetoneful@gmail.com>
2026-10-11 19:37:48 +08:00
Morgan 6bed2c1c32 cursor 0.2.5: a Cursor account with a Grok Bot allowance shows it on its Usage card (#64)
Grok Bot has an allowance of its own, apart from Cursor's monthly usage,
and it shows on cursor.com's dashboard only. auth.usage now also reads
https://cursor.com/api/dashboard/get-sand-usage-status with the sign-in
as the dashboard session (WorkosCursorSessionToken, as Cursor's dashboard
and CodexBar's CursorSandUsage.swift send it), and adds a "Grok Bot"
window: a paid grant with its weekly reset, a live trial as
"Grok Bot (trial)" without one. The window is aside, so Bot running out
never stops Cursor model requests, and it comes before Total so it is
among the Usage card's three rings. No grant, an expired trial, a
non-2xx, a redirect (not followed), a hang past 5 s or a reply that
isn't JSON each leave Cursor's own windows as they were.

Rebased onto main after cursor 0.2.4 (7516d63); package version is 0.2.5.
Optional pins for the 5 s AbortSignal.timeout and the Origin header are
not in this commit (Codex CLI unavailable for the edits); the runtime
guards stay.

Tests: usagePercent 130 is shown as 100 (and -5 as 0), and a 307 to a
login page is refused rather than followed; each fails with its guard
removed from botUsage.

HOME=$(mktemp -d) bun test packages/cursor: 73 pass, 0 fail.
HOME=$(mktemp -d) bun test (whole repo, on this commit atop main
7516d63): 1033 pass, 0 fail. bun scripts/check.mjs: all 15 ok. Checked
by hand once before an earlier squash: a Free Cursor account linked to
SuperGrok showed the Bot ring in magpie. Not tried with a paid Cursor
grant.
2026-10-10 11:49:29 +08:00
yetone 5189b287e7 grok 0.1.11: a plain Codex agent_message (a subagent's task or reply) reaches Grok as a user message (#61, congee949)
Releases #61 (13e813d), which merged without a version bump: Grok's
Responses backend turned these requests away with 422 unknown item type
"agent_message". Sealed tasks are still sent as they came.

Verified at #61's head merged onto e1efc3d: bun test packages/grok 31 pass,
the whole repo 1007 pass, bun scripts/check.mjs ok. Without the change in
index.mjs, agent-message.test.mjs fails 2 of 4. Sent through
loader().fetch to a local fake of cli-chat-proxy.grok.com: main gives 422,
this version gives 200.
2026-10-09 22:32:53 +08:00
congee949 13e813ddb0 grok: plain Codex collaboration messages reach the Responses backend as user messages (#61) 2026-10-09 22:32:27 +08:00
yetone a6910fd50a grok 0.1.10: a tool whose parameters are a union at the root reaches Grok as an object, so Codex desktop's turns are no longer refused (yetone/magpie#1271)
xiaocui12: Codex on Grok failed every turn with "[invalid_client_tool_schema]
mcp__codex_app__automation_update: tool parameter root must be an object
type (root schema is an anyOf/oneOf union with a non-object branch)".
Codex desktop's codex_app automation_update has an anyOf at its
parameters' root (ChatGPT.app 26.930 builds it with zod 4's toJSONSchema),
and its create and update branches are unions themselves.

rewrite() now folds a function's parameters to an object root as magpie's
built-in provider.ObjectRoot does, nested union branches folded first so
their fields (name, prompt, rrule, kind...) are kept and only "mode" is
required. Before, the plugin sent the union as it came; magpie's grokBody
folded it for requests through magpie, but not for OpenCode's own.

Verified: the real schema (testdata, rebuilt with zod 4.1.8) sent to the
real Grok subscription raw gets 400 with the reporter's exact message;
folded it gets 200 and a correct create call
({"mode":"create","kind":"heartbeat",...,"rrule":"FREQ=MINUTELY;INTERVAL=30"}).
schema.test.mjs: 2 of its 3 tests fail on 0.1.9 and pass now.
HOME=$(mktemp -d) bun test: the rest of the package matches main (login and
refresh tests time out here on main as well; CI runs them on Linux).
2026-10-08 16:51:46 +08:00
yetone b35eee46de grok 0.1.9: the same code as 0.1.8, published because magpie asks for 0.1.9 (yetone/magpie#1065) — magpie daeb108b, Command Code's mover change, raised Grok's mover min to 0.1.9 as well, a version never published, so from magpie v0.1.1078 every "Move to plugin" for Grok failed with "@magpie-community/opencode-grok-auth 0.1.8 is installed; moving needs 0.1.9 or newer" and keepMovedCurrent couldn't update moved users. Publishing 0.1.9 lets released magpie builds move again. bun test (24 pass) and check.mjs grok pass. 2026-10-07 08:22:41 +08:00
yetone 719ba0c621 grok 0.1.8: a grok login that prints no link says why, and the endpoint a failed one names isn't taken for the page to open (𝕏 on Discord) — the sign-in said only "grok login gave no link to open", dropping what the CLI said; it now ends with the CLI's last line, or asks whether auth.x.ai is reachable when it said nothing. grok 1.0.46, unable to reach x.ai, prints "Error: error sending request for url (https://auth.x.ai/oauth2/device/code): …", whose URL was handed on as the link; a line saying error gives none. A spawn that fails settles the link at once instead of after 30s. login.test.mjs is new (fails on 0.1.7); bun test and check.mjs pass. Checked with grok 1.0.46 itself through magpie's plugin host, given a proxy that refuses: the error now names it. 2026-10-05 22:10:57 +08:00
yetone 8df77e69aa grok 0.1.7: a 429 shows a spent Rate limit window on the card until it lifts (H20 on Discord)
Grok's billing (/v1/billing?format=credits) says nothing of a plan's rate
limit: a free account read 0% used, 100 left, while its requests came back
429. The plugin now keeps an account's last 429 (by its CLI home) and
usage shows a "Rate limit" window at 100%, aside, before the period's,
until the reset the 429 named (Retry-After in seconds or as a date, or a
*ratelimit*reset* header), or, with none named, until a request goes
through or 5 minutes have passed. magpie's gateway already rests the
account; this is what the card says.
2026-10-05 20:51:52 +08:00
yetone 0af8500c08 grok 0.1.6: magpie renews the sign-in ahead of time through auth.refresh
auth.refresh with refreshLead 5 minutes (the in-fetch margin): the CLI
renews the sign-in in the account's home (grok models), once per home
however many ask, and the token is read back. A token the CLI renewed
already is given without running it; no credential left (grok logout) is
signIn "expired"; a token the CLI couldn't renew throws and is retried.

The check before each request stays for OpenCode, which doesn't call the
hook (magpie 0.1.684+ does). refresh.test.mjs fails without the change;
HOME=$(mktemp -d) bun test passes (396 across the repo).
2026-10-03 12:07:22 +08:00
yetone ce298d8ad9 grok 0.1.5: a token Grok refuses before its time says the sign-in has expired, as one past its time does — magpie's move takes such an account along untried; "Grok models: 401 …" stopped every Grok account's move. models.test.mjs fails against 0.1.4. 2026-10-01 12:37:59 +08:00
yetone e44077a705 grok 0.1.4: grok-4.7 keeps its low/medium/high/xhigh reasoning levels when Grok's model list can't be read, as the built-in offered them — the default list carries the variants. models.test.mjs fails against 0.1.3. 2026-10-01 07:04:58 +08:00
yetone 01aee5da28 all: a usage read says what it means for the sign-in, and a renewal clears the mark whatever follows, as the built-ins did (要保证插件跟内置的所有逻辑都要一模一样) — auth.usage returns signIn on every path: expired where the built-in's quota read marked the account (Zed's /users/me 401, Factory's and MiMo's refused renewals, Qoder's refused job refresh), renewed after a renewal, which took the mark off, kept everywhere else, so magpie no longer guesses from the words 'sign in again' (Kiro's, Devin's and ZCode's usage errors marked accounts their built-ins never did) nor clears on a clean read. A request after a renewal says renewed on any status; one without says kept, as the built-ins cleared only on renewal. Kiro, Cursor, Devin, Command Code, WorkBuddy, Grok and ZCode, whose built-ins never marked an account, say kept on every answer. New tests fail against 85d7dd0's index.mjs. 2026-10-01 04:53:29 +08:00
yetone 85d7dd0d0a all: each plugin fails with its built-in's status and marks the sign-in as it did, through X-Magpie-Sign-In (要保证插件跟内置的所有逻辑都要一模一样) — Factory's and MiMo's refused renewals are the built-ins' 502 marked expired, not 401s; Qoder's vendor 403 is the built-in's 401 kept, its model list's failure a 400, its job refresh refused marked expired; Zed's retried 401 is a 401 kept, not a 403; Kiro's unreachable refresh a 401 kept; Cursor's expired trial a 401 kept; a vendor 401 WorkBuddy, Grok, Devin, Command Code and ZCode passed on no longer marks the account, as their built-ins never did, and Grok and MiMo no longer retry what their built-ins sent once. Messages take the built-ins' words. New tests fail against the previous index.mjs. 2026-10-01 04:47:03 +08:00
yetone 0c7275a140 grok 0.1.2: a usage fetch that fails or a reply that isn't JSON is the card's error, as grok_usage.go says it (Go's Get "<url>": … with no such host / connection refused / timeout / EOF for magpie's keepLast, encoding/json's words); a status Go has no words for says "HTTP <n>"; a model list Grok couldn't give fails instead of falling back to the configured few; a request body handed over as bytes is reshaped as a string one 2026-10-01 03:07:40 +08:00
yetone 79ab574970 grok 0.1.1: usage shows as magpie's built-in did — plan, period, windows and what they count, balancegrok 2026-09-30 23:03:09 +08:00
yetone 5a18bbdac4 Name the scope @magpie-community (the org's name, spelled right) 2026-09-30 17:04:47 +08:00
yetone 7f0f20132d grok: Grok (SuperGrok / X Premium+) through the Grok Build CLI's sign-in — device-code sign-in or the CLI's current one, token refreshed by the CLI, Responses at cli-chat-proxy.grok.com with magpie's headers and body clean-up, the account's models 2026-09-30 17:00:20 +08:00