Skip to content

minimax 0.2.13: the usage card lists reset cards and the off-peak window - #4

Closed
klarkxy wants to merge 782 commits into
mainfrom
cursor/minimax-reset-cards-offpeak-36bc
Closed

klarkxy wants to merge 782 commits into
mainfrom
cursor/minimax-reset-cards-offpeak-36bc

Conversation

@klarkxy

@klarkxy klarkxy commented Dec 5, 2026 •

Copy link
Copy Markdown
Owner

Base is wrong for merge: this PR tool opened against klarkxy/plugins:main (stale fork). The intended review/merge target is magpie-community/plugins:main with head klarkxy:cursor/minimax-reset-cards-offpeak-36bc. Compare: https://github.com/magpie-community/plugins/compare/main...klarkxy:cursor/minimax-reset-cards-offpeak-36bc?expand=1 — do not merge this fork-main PR.


Implements yetone/magpie#1884 in @magpie-community/opencode-minimax-auth: the usage card lists MiniMax reset cards (限额重置) and can spend one, and it labels MiniMax's published off-peak hours. yetone/magpie#4609 (reset cards granted by check-in) is related; this PR lists whatever the account API returns, including check-in cards, but does not change check-in itself.

Reset cards (yetone/magpie#1884)

yetone confirmed the MiniMax Code login-session APIs on agent.minimax.cn / agent.minimax.io:

  • GET /backend/account/reset_card/list — available cards and expiry
  • POST /backend/account/reset_card/use — body { source_type, out_biz_no } taken from a list item; nothing else is sent
  • GET /backend/account/reset_card/flows — 30-day history, not implemented (optional)

These are not on the open-platform API Key surface. The plugin reads them with the same signed account client as usage and check-in (accountCall / siteFetch). The China site still falls back from agent.minimaxi.com to agent.minimax.cn when the first host cannot be reached. The international site is covered the same way on its own host.

Listing. A logged-in usage card reports resets: { count, until } (available count and the soonest expiry). Magpie already renders that. A list that cannot be read is omitted, same as a failed credit ledger: the rest of the card still shows. A successful empty list is count: 0, so “none” and “could not read” do not look the same.

Use. Magpie that supports cardActions draws a Use a reset card button. The click spends the unexpired card that expires soonest, then Magpie refreshes usage. Using a card is irreversible; the button asks for confirmation.

Auto-use. An independent auto_use_reset_cards switch (auth.options) defaults off (default omitted; Magpie treats that as off). When on, a usage reading that finds a token plan whose weekly quota is used up, and an unexpired card remaining, spends the soonest-expiring card and re-reads the windows. A spent general 5-hour window is not treated as exhausting the plan (on Go / Explore / Build, M4 / image / video consume only the weekly window). Auto-use does not run for a free account, an API Key, or a host that does not expose magpie.option.

API Key / no plugin login. Only this plugin's MiniMax Code OAuth session can list or use reset cards. An API Key usage card skips the list and says why; the use action is refused.

Off-peak display

Official docs (CN, global): during the promotion, M Plan and Token Plan subscribers using language models in MiniMax Code from 23:00 to 09:00 UTC+8 have subscription quota deducted at 0.5× (double token quota). Automatic, limited-time, MiniMax Code only, subscription quota only (not credit packs), all language models currently in the plan — not M4-specific.

The card adds an aside Off-peak line for a token plan. Remaining quota still comes from remains_percent / remains. There is no off-peak API field, and weekly_boost_permille is a plan bonus, not this multiplier. Official docs limit the offer to MiniMax Code; whether Magpie traffic actually gets 0.5× is unverified, and the card does not claim that it does.

Host changes

None, and no PR on yetone/magpie. Magpie already has usage.resets, magpie.cardActions / auth.action, and magpie.option / auth.options. List, the use button, and the auto-use switch all live in this plugin. An older Magpie without cardActions still lists cards and has no button; auto-use stays off unless that host exposes option.

Schema assumptions (the list/use JSON is unpublished)

Parsed defensively; a shape this plugin does not know is a failed read, never a made-up zero.

  • List array: items / list / cards / reset_cards / records / rows, including nested under data / result / payload, or a bare array there. camelCase variants of source_type / out_biz_no / expiry keys are accepted.
  • Expiry: expire_at_ms, expire_at, expires_at, expire_time, valid_until, end_time, and camelCase; unix seconds or ms; a Beijing wall time without a zone is UTC+8.
  • Spent: English used / spent / expired / invalid / unavailable / consumed only. Unknown numeric statuses are left as available.
  • A remaining_count (or similar) with no item array reports the count but cannot spend (no source_type / out_biz_no).
  • Use POST body is only { source_type, out_biz_no } from the chosen list item.

Tests

packages/minimax/usage.test.mjs against fake.mjs only. No real MiniMax API, no real account.

  • list success, HTTP failure leaving the rest of the card, unknown shape, global site, API Key without login
  • use success (soonest card, those two fields only), missing params
  • auto-use off by default; on only when the weekly window is exhausted; not on a free account or without a magpie host
  • off-peak vs daytime with a frozen clock; weekly_boost_permille is not the night multiplier
HOME=$(mktemp -d) bun test packages/minimax
HOME=$(mktemp -d) bun scripts/check.mjs minimax

242 pass, 0 fail (package tests). scripts/check.mjs minimax exits 0.

Patch version 0.2.12 → 0.2.13.

Open in Web Open in Cursor 

yetone and others added 30 commits November 30, 2026 23:14
…ill reaches UEBox (magpie-community#1764)

syncLibrary skipped hashing a skill whose stat signature (size, mtime,
ctime, inode) matched the last sync's. File times come from a coarse
clock (a jiffy on Linux's 6.6 kernel, 2s on FAT), so a same-size edit
made in the same tick as the sync's stat kept every one of those and
was never copied. statSignature now returns null while any file in the
folder changed under 2s ago; every caller already treats a null
signature as untrusted, so the sync compares contents (hashDirectory)
until the files are older. The same holds for the target side
(isTargetModifiedByUser's dstSig).

Test: "syncLibrary copies a same-size skill edit made in the same tick
as the sync before it" syncs, rewrites the skill with a same-size body
and syncs again, up to 400 rounds, until the rewrite landed in the
same file-clock tick three times.

Run (wsl-run, magpie-desktop, Ubuntu 24.04, kernel 6.6, bun 1.4.2,
HOME a temp dir):
- the new test on the old library.mjs (that is the break by hand):
  red 3 of 3, the second sync copied nothing;
- with the fix: packages/uebox/uebox.test.mjs 26 pass, 5 of 5.
- agy-cli, uebox and scripts tests plus scripts/check.mjs: see the
  magpie-community#1765 commit after this one, run at that head.

Not tried: macOS. APFS's nanosecond times and kernels 6.13+ with
multigrain timestamps may never hit the same tick, so there the test
passes on the old code too; it has no assertion that needs the race.
…a 500ms bar (magpie-community#1765)

The test held an EXCLUSIVE lock on the step store during a tool step
and asserted the step returned in under 500ms, to show the poll gives
up on SQLITE_BUSY instead of waiting out STEP_USAGE_WAIT_MS (1s). On
a loaded host the step took 653ms without polling at all, so the bar
had no room.

It now raises STEP_USAGE_WAIT_MS to 10 minutes for this kit and keeps
the lock until the tool result comes back. A poll that went on under
the lock would hold the step for the whole 10 minutes, so the step is
only bounded at 60s: room on both sides, and no measurement of how
fast the machine is. Test-only; the bump ships it with the package.

Run (mote-run, bun 1.4.2, HOME a temp dir, AGY_BRIDGE_STORED_SIGNIN=skip):
- old test with a 600ms pause before agy's first tool call (a slow
  host): red, "首步耗时 640ms";
- new test with the same pause: green (713ms);
- new test with the poll broken by hand so a locked store keeps
  polling (`if (batch && complete(batch.steps)) break`): red at 60s,
  "SQLITE_BUSY 时首步 60s 仍未返回";
- new test as committed: green (115ms).

At this head with the uebox commit before it (wsl-run, magpie-desktop,
bun 1.4.2, HOME a temp dir): `bun test packages/agy-cli packages/uebox
scripts` 156 pass, 0 fail (12 files, 379s); `bun scripts/check.mjs`
exit 0. Not run: the whole repo's suite. Both Macs' suite locks were
queued for hours and WSL was running another session's GUI suite;
nothing outside agy-cli and uebox changed.

Rebased onto 1142101 (agy-tui, README.md and registry.json only) and
run again there: `bun test scripts packages/uebox` 82 pass, 0 fail;
`bun scripts/check.mjs` exit 0.
…gain, so tools_not_loaded heals without a restart (magpie-community#1766)

magpie-community#1766 (holEeast979, macOS): after about an hour every agy-cli account
failed 502 tools_not_loaded ("the MCP server agy starts through `nc`
… didn't answer within 20s") until magpie restarted.

Both suspects were real on origin/main (ac9904b):
- ensureShimDir() re-checked only Windows' shared nc.exe. The owned
  macOS/Linux dir (magpie-agy-bridge-bin-* under os.tmpdir()) was
  cached for the host's life: once it was gone, agy ran the next `nc`
  in PATH (/usr/bin/nc), which never reaches the bridge.
- ensureControlServer() cached its promise forever, with no close or
  post-listen error handling and no check that it still listened.

Now:
- checkShim() runs before each agy and before each request
  (acquireProcLocked). A missing or non-executable shim is written
  again in the same dir (temp file + rename, 0700), so agy already
  started with that dir in PATH reach the bridge again. A dir that
  is no longer safely ours (another uid, group/other bits, not a real
  dir; Linux's shared /tmp) is left for a new mkdtemp dir.
- The control server drops its cache on close, on an error after
  listen, and when it no longer listens. It is made again on the port
  it had, so live agy keep working; if that port was taken, on a new
  one.
- bridgeEpoch moves only when the shim dir or control port actually
  changed. A pooled agy, spare or stateless/same-opening donor started
  before then is not reused (why "bridge_moved").
- tools_not_loaded says what it found: nc shim ok/missing/not
  executable, its runtime (bun execPath), the MCP server file, control
  port N listening/closed, whether it was made again, and the last
  300 chars of agy's stderr. The same is logged as booleans. The text
  now says the plugin's own `nc` shim, not a netcat on the computer.

What removes the dir on the reporter's Mac is not known (no sweep in
the plugin or magpie; a temp cleaner or a runtime update are
guesses). The diagnosis will name it if it happens again.

testkit: each net.createServer is a fake server with listening,
close and EADDRINUSE, and an agy's MCP server connects to the one on
its own AGY_BRIDGE_CONTROL_PORT (nothing once it is closed).

test/bridge-heal.mjs, 7 tests:
- shim dir removed between turns;
- shim's execute bit removed;
- dir replaced by a 0777 one;
- control server closed between turns (live agy reaches it again);
- the port taken meanwhile;
- the 502's diagnosis and the next try heals;
- the diagnosis when all is fine.

Run (wsl-run, magpie-desktop, bun 1.4.2, HOME a named scratch dir,
AGY_BRIDGE_STORED_SIGNIN=skip):
- bridge-heal.mjs on the new index: 7 pass;
- bridge-heal.mjs on origin/main's index.mjs (AGY_BRIDGE_TEST_INDEX):
  7 fail, each for its reason (tools_not_loaded on the second turn,
  follow-up kept on the stale agy, "no tools: null" from the closed
  server, old wording);
- `bun test` in packages/agy-cli: 75 pass, 0 fail (365s);
- `bun scripts/check.mjs` exit 0 and `bun test scripts` 56 pass, at
  this tree with the version bump.

Not run: the whole repo's suite (only agy-cli changed); a real agy on
macOS; a real $TMPDIR cleanup; Windows (the shared nc.exe check moved
into checkShim unchanged; windows-nc.mjs passes under the fake win32).
… history on its first call (magpie-community#1769)

Darkatse (magpie-community#1769): Devin's Gemini models answer a tool loop with usage and
nothing else when a step goes back without its thought signature. The
plugin kept each signature only in memory (thoughts), so after magpie
restarted mid-loop, or after a routing group fell over to another
provider for some steps, the earlier Gemini steps went back unsigned and
the turn failed as "an empty reply".

Reply side (chat completions): a Gemini reply's delta_signature, of type
"gemini", now goes to the client on the step's first call as
extra_content.google.thought_signature, where Google's OpenAI-compatible
API puts it and where magpie's gateway reads it. In a whole message it
is set on tool_calls[0]. In a stream it is on the delta that opens the
first call, the only delta the gateway reads it from; Devin gives the
signature after the call (the real capture in
testdata/gemini-tool-reply.bin), so for a Gemini model that first call,
and what follows it, is held until the signature is whole (the next
event that isn't part of it) or the reply ends. Other models' streams
are sent as before, event by event.

Request side: an assistant message's signature is taken from its
tool_calls[].extra_content.google.thought_signature first (the first
call that has one; Google's "skip_thought_signature_validator" counts as
none), and from thoughts only when the history carries none. The
text-only fallback (thoughts by the reply's words), the Messages wire
(tool_use has no such field) and the retry once without signatures on
invalid_argument are unchanged.

Field 22 (the model that wrote the signature): the model the plugin
noted with that same signature in thoughts, when it has one, else the
current request's model. The noted one is the exact variant that wrote
it, so it wins when known; when the history comes from a fresh process
or another magpie there is no record, and the request's model is the
best guess: the step was most likely written by the model the client
is still asking. Not tried: whether Devin turns a signature away when
field 22 names another effort of the same family; the retry without
signatures still covers a refusal.

A Claude model, swe-2, GPT and every non-Gemini model are unchanged:
no extra_content on their replies (a swe-2 or Claude reply carrying an
anthropic signature streams the same chunks as before) and none read
from their histories.

magpie's gateway already carries extra_content both ways for a plugin
provider (checked with a throwaway gateway test on mote against a fake
plugin: chat streamed and whole, Messages and Gemini-native requests
all brought the signature back to the plugin on the next turn), so no
magpie change is needed beyond the mover min.

Tests: gemini-extra-content.test.mjs (18 tests), with fakes only:
- the real capture, whole and streamed: the opening delta carries the
  signature, nothing else does, the arguments follow;
- a fresh process (forgetThoughts) whose history carries extra_content,
  streamed and whole: the signature, type and model reach Devin;
- a history mixing signed steps with another provider's unsigned step
  and a skip_thought_signature_validator step: only the signed go signed;
- a parallel step: the signature on the first call only, sent back once;
- text before the call stays in order; a reply with no signature opens
  its call unsigned at its end;
- the history's signature comes first, the map gives only the model;
- a history's signature Devin refuses is sent again once without it;
- claude-opus-4-6, swe-2 and gpt-5-2 histories send the same bytes with
  or without extra_content; swe-2 and Claude replies give none.

Red on the old code (origin/main 05a8729's index.mjs): 10 of 18 fail;
the 8 that pass are the unchanged-model guards and the unsigned reply.
Broken by hand: the request side alone reverted fails 7; the stream
hold alone removed fails 4 (the opening delta, the streamed fresh
process, the parallel step and the order test).

Run at this tree: on mote, gemini-extra-content, gemini-thought and
long-session (32 pass); on the WSL2 Linux box (mote's suite queue was
held by other sessions' GUI runs), the root HOME=$(mktemp -d) bun test:
10113 pass, 30 skip, 2 fail, and bun scripts/check.mjs ok. The 2 reds
are gumloop's "a host that exits while its charge waits for a busy
peer" (Node and Bun), untouched here, red 3 of 3 alone on WSL2 and
green on CI's ubuntu at 05a8729: filed as magpie-community#1770.

Not tried: a real Devin account (no real-account requests), and a real
magpie restart mid tool loop with the reporter's routing group.
… read in its own month (magpie-community#1770)

The two "a host that exits while its charge waits for a busy peer still
writes it" tests (Node, Bun) failed on the WSL2 box with calls 0 / credits 0
and an exit 0 with empty stderr. Nothing was lost and nothing is
WSL-specific: the charge was written, into another month's bucket.

Cause: bun test runs the test file in UTC when TZ isn't set, but doesn't
put TZ in the environment, so a child it spawns runs in the system's zone
(Asia/Shanghai on the WSL box and on HQ, America/Los_Angeles on mote).
The ledger's month is local time (monthKey). The issue's runs were at
2026-11-30 23:53Z, 07:53 on Dec 1st in Shanghai: the child charged month
2026-12, and the test read the account with Store.account in UTC, found
month 2026-11 missing and got a fresh empty month. That's the "key":
"2026-11", calls 0 in the report. It fails in the hours each month when
the system zone's month differs from UTC's, on any OS, and never on CI,
which runs in UTC. The 200-charge test reads the raw ledger, so it passed.

Users: none affected. Every plugin host of one magpie runs in the system
zone (no bun test there), so all of them write and read the same month.
proc.mjs and the lock code are not involved.

Fix: the test file starts every host (holdLock's owner, the busy-peer
host, the two 200-charge hosts) through one host() helper that gives it
TZ = this file's resolved zone. A new test per runtime checks that a host
reports that zone, and the same month as this file at magpie-community#1770's minute.
Test only: no shipped file changes, so no version bump (scripts/bumped.mjs
counts no tests); gumloop 0.1.3 stays as it is on dist.

Run:
- WSL2 magpie-desktop (wsl-run, HOME=$(mktemp -d)), the system zone set
  per run in an unprivileged user+mount namespace (/etc copied, localtime
  linked to the zone, bind-mounted over /etc), TZ unset:
  - origin/main 7a84ec3, Pacific/Honolulu (Nov 30 there, Dec 1 UTC):
    both busy-peer tests fail as reported, mirrored ("key": "2026-12",
    calls 0). With a print added, the raw ledger held
    {"key":"2026-11","credits":1,"calls":1} and 1 charge.
  - origin/main, Asia/Shanghai (same month as UTC then): 48 pass.
  - fixed, Honolulu and Shanghai: 50 pass, 0 fail each.
  - fixed with host()'s TZ removed, the box's own zone, no namespace:
    the two new tests fail ("zone": "Asia/Shanghai", "month": "2026-12"
    against "UTC", "2026-11"); 48 pass.
  - root bun test at 7a84ec3, in the namespace: under Honolulu 10110
    pass, 3 fail (the two busy-peer tests and page-harnessweight's "a
    failed release is reported"); under Shanghai 10112 pass, 1 fail (that
    same page-harnessweight test). So no other test in the repo depends on
    the zone. The page-harnessweight red is my harness: it needs chmod 0555
    to stop an unlink, and the namespace runs as uid 0; as uid 1000 on the
    same box that file is 15 pass, 0 fail.
- mote (macOS, America/Los_Angeles, mote-run, HOME=$(mktemp -d)) at
  Nov 30 16:32 PST: origin/main's file fails the same two tests natively
  (2 fail, 46 pass); fixed, 50 pass.
- Windows xiaomi-gpu (win-run): fixed, 50 pass.

Not tried: Node's own test runner (the file is bun:test only); a real
magpie install, since no shipped code changed.
…unified rollout left (magpie-community#1771)

Grok Build auto-updated jchenio's install to `grok 2.0.5 [unified]`:
~/.grok/bin/grok -> agent-host -> ../downloads/agent-host-2.0.5-macos-aarch64,
recorded in ~/.grok/channel-switch.json ({"previous_target":
"../downloads/grok-1.0.92-macos-aarch64", "binary": "agent-host",
"channel": "unified", "rollout": true}). The plugin never refreshes a
token itself: it runs `GROK_HOME=<home> grok models` and reads auth.json
again. The unified build keeps its own sign-in, so its `grok models` exits
0 with auth.json as it was. Every renewal "worked" and renewed nothing,
and the failure said to open Grok Build or add the account again, which
doesn't help either: the opened Grok Build is that same unified build.

Fix: cli() picks the build to run. When the grok found is the unified build,
it runs the newest native grok-1.x build in ~/.grok/downloads made for this
system (on a Mac both arches, own first) and runnable. The unified build is
recognised by:
- a name on its symlink chain (agent-host...), from bin/grok or from a
  GROK_BIN_DIR link (the installer makes that one absolute);
- on Windows, which has no symlinks, a bin\grok.exe that is a copy of
  downloads\agent-host-*.exe;
- else channel-switch.json saying agent-host/unified for the bin Grok
  Build manages (or GROK_BIN_DIR), only where a native build exists.
A grok that links to or copies a native build runs as before, whatever a
stale record says. Renewal (auth.refresh, token() before a request, the 401
retry), and sign-in use it. With no native build left, the failure says that
Grok Build updated itself to its unified build, and gives the install command
that pins the previous build (curl | bash -s <ver>, or PowerShell's -Version
<ver>, version from previous_target). It says to set auto_update = false in
<GROK_HOME>/config.toml. The unified build isn't run for it. For Grok
Build's own home, an unrenewed sign-in names the native build to run, not
"open Grok Build". README has a section on it.

Not changed: clientVersion still reads the found grok's --version (only a
header value; unchanged for native installs), and importCPA/current() still
only check that a grok exists. Cursor CLI's own switch record
(~/.cursor/grok-switch.json) is not read: it doesn't move ~/.grok/bin.

unified.test.mjs (new): fakes are bun under a build's name (symlink, a
hard link on Windows) running a `models` script that logs the name it ran
as and, as agent-host, prints 2.0.5's "You are not authenticated" list and
exits 0; as native, writes a new token. Covers unified symlink + natives
(newest picked), the 401 retry, unified with no native (message, agent-host
never run), native-only with a stale record and agent-host beside it,
plain-file native, GROK_BIN_DIR, Windows copy layout with and without a
native, Windows copy of a native, and sign-in through the native build /
the sign-in message.

Run:
- WSL2 magpie-desktop (wsl-run): packages/grok 127 pass, 0 fail at the
  committed tree. Root HOME=$(mktemp -d) bun test: 10127 pass, 0 fail,
  30 skip (700 files), run before the last test-only edit (cli in
  _internal, the Windows native-copy test); `bun scripts/check.mjs grok` ok.
- Red on the old code: unified.test.mjs against origin/main's index.mjs
  fails 7 of 10; the 3 that pass are the unchanged-behaviour tests. Broken
  by hand: the version sort reversed and copy detection off (1.0.80 picked,
  Windows no-native message red); the native-name early return dropped
  (stale-record test red).
- Windows 11 xiaomi-gpu (win-run, temp HOME/USERPROFILE): packages/grok
  88 pass, 21 fail; the 4 tests here that run on Windows pass. origin/main
  has the same 21 reds there (84 pass), the /bin/sh fakes: magpie-community#1773.
- mote and mica were each running a queued full suite; not used.

Not tried: no real grok binaries and no real account. Whether the native
1.0.92 still renews when the unified build is installed beside it, and
whether its own auto-update moves bin/grok when run for a renewal, is
unverified. A direct OIDC refresh against auth.x.ai was not added.
… the CLI fakes run on Windows (magpie-community#1773)

On Windows `bun test` in packages/grok had 21 reds on main: backoff,
refresh and renew tests faked Grok Build with /bin/sh under grok's name
reading a shell script, and /bin/sh isn't there. CI runs ubuntu only.

Tests: fakecli.mjs gives those three files one fake that runs on every OS.
It is bun under grok's name (a symlink, a hard link to grok.exe on Windows,
else a copy), so `grok models` is `bun models` running a JS script in the
folder the plugin runs it in, as unified.test.mjs does. Each file's script
does what its shell script did (count the run, renew, same, slow, logout,
the CLI's own failure lines). Nothing is skipped on win32. It is still
not a file written and then run, so magpie-community#65's macOS scan delay doesn't come
back. fakecli.mjs isn't packed (files in package.json).

index.mjs: run() caught nothing when execFile threw instead of calling
back. It throws where the system refuses the file: EUNKNOWN (uv_spawn)
for a grok.exe that isn't a program on Windows, ENOEXEC on macOS. The
renewal then rejected with the raw spawn error, and a request turned away
said "EUNKNOWN: unknown error, uv_spawn. Grok said: ...". run() now
resolves with that error like any failed run, so it reads "Grok Build
couldn't renew the sign-in (grok models exited EUNKNOWN); open Grok Build
and send it a message ...". clientVersion's `grok --version` goes through
the same run() and already handled err. New test in renew.test.mjs: a
grok that is junk bytes with the exec bit.

Run:
- Windows 11 xiaomi-gpu (win-run, temp HOME/USERPROFILE): packages/grok
  110 pass, 18 skip, 0 fail (main: 84 pass, 21 fail). The new test with
  the old run(): red, "EUNKNOWN: unknown error, uv_spawn. Grok said: ...".
- macOS (HQ, the one test, workers busy): red with the old run(), green
  with the new.
- WSL2 magpie-desktop (wsl-run): packages/grok 128 pass, 0 fail; root
  HOME=$(mktemp -d) bun test: 10128 pass, 30 skip, 0 fail, 700 files; `bun scripts/check.mjs grok` ok.

Not tried: whether Linux's spawn throws for the junk file (it may run it
through /bin/sh and fail asynchronously instead). The test passes either
way there, so on Linux it doesn't tell the old code from the new.
…s face value (magpie-community#1776)

runsOut was an income bill's points, the grant's face value, capped by the
whole balance (Math.min(avail, expiringPts), and Math.min(dailyRemain,
dailySoonestPts) for the Daily pool). A daily grant already spent to 0
still read "300 即将过期" while daily_points was 300 or more, and that 300
weighed in the `expiring` and `pace-drain` routing. PanXinglin's five
accounts all read runsOut 300 with 187/23/3/30/54 used.

The bills carry no remainder per grant, and a busy account's spend bills
can't all be read (a page is at most 100 rows and paging.offset is
ignored). So it is derived: spending is taken to draw on the grant that
expires first (the vendor doesn't document its order; this is the order
that wastes the least), so the balance sits in the grants that expire
last. heldByGrants hands the balance out from the grant expiring last
backwards (one that never expires first), each holding at most its face
value. nextToRunOut takes the soonest grant still holding credits: a
grant spent to 0 is passed over, and with none left runsOutAt and
runsOut are left out, as magpie reads RunsOutAt ("when the soonest
credits left in the window are lost").

- Daily pool: daily grants share daily_points.
- Credits: with daily_points known, daily grants share it and the others
  share the rest of available_points; on the setting_info path (no
  daily_points) every grant shares available_points.
- Grants past expire_at not swept yet sit behind every live grant, so
  they take only what the live ones can't hold.

The test that pinned runsOut 300 under daily_points 519 now reads 219
(b1 holds 300, b2 the 219 left). README (en, zh) says what runsOut is
and the assumption.

Tests, from the reporter's numbers (300 a day, 7 days, so 7 live grants
of 300): daily_points 1,800 with the oldest spent reads 300 at the next
day's expiry; used 187/23/3/30/54 read 113/277/297/270/246 at the
soonest; daily_points 0 leaves Credits with no runsOut; the setting_info
path with 187 spent reads 113.

Run on xiaomi-gpu WSL (magpie-desktop), HOME a temp dir:
- bun test packages/raccoon at f208c4d plus only the new tests: 88 pass,
  4 fail (the four magpie-community#1776 tests); with the fix: 92 pass, 0 fail.
- Broken by hand (each grant holds its face value): 5 fail, the four
  magpie-community#1776 tests and the 219 one.
- bun scripts/check.mjs raccoon: ok. bun test scripts: 56 pass.
- Full bun test: queued under suite.lock on the same box behind other
  sessions' suites; not finished at push.
Not tried: no request to a real raccoon account; the spend order is an
assumption, not the vendor's word.
…munity#1777)

Google reverted the 4x quota charge for custom agents on 2026-11-30
(antigravity-cli#1890), so the comment no longer stated why the plugin
stays on the default agent. It now says: it is the session agy itself
opens, and with accounts being disabled (magpie-community#1741) the session shape stays
until the owner rules on magpie-community#1777.

Comment only; no code or version change. Ran: node --check on the file.
…s prompt cache is read again (magpie-community#1774)

The reporter's Claude Code calls through the plugin were billed about 0.70
credits each, every call, while kiro2cc-proxy on the same work was billed
0.65 for the first and about 0.2 after. Claude Code opens its system with
"x-anthropic-billing-header: cc_version=…; cc_entrypoint=…; cch=…;", and
with a first-party base URL (2.1.327, or
_CLAUDE_CODE_ASSUME_FIRST_PARTY_BASE_URL) or before that gate (2.1.114,
magpie magpie-community#1600) cch, cc_prompt_id and cc_turn_index change every turn. magpie
hands the line on to a Claude model on Anthropic's Messages, which the
Kiro plugin's models are, and the plugin put the system at the head of the
first message, so every request differed from Kiro's 80th character on and
its prefix cache missed. kiro2cc-proxy blanks cch for this reason
(normalize_billing_header); Kiro's own clients send no such line, so the
plugin leaves it out, as the WorkBuddy and Factory plugins do. Text after
it in the same block, and the blocks' cache marks, stay.

Turned two real Claude Code 2.1.327 -p turns (a fake Anthropic server,
sandbox HOME, _CLAUDE_CODE_ASSUME_FIRST_PARTY_BASE_URL=1) into Kiro bodies:
before, turn 2's first message matched turn 1's for 79 of 47031
characters; now for all 46837, with the tools the same.

Run on WSL magpie-desktop (Bun 1.4.2, HOME=$(mktemp -d)):
- At base 3228442: bun test (whole repo) 10135 pass, 30 skip, 0 fail;
  bun scripts/check.mjs ok.
- At this head (rebased on 5623438, which changes agy-cli's
  default-agent.mjs comment only): bun test packages/kiro packages/agy-cli
  314 pass, 0 fail; bun scripts/check.mjs kiro agy-cli ok.
- bun scripts/bumped.mjs origin/main (HQ, needs .git): ok; npm had 0.1.45.
Broken by hand: billing-line.test.mjs against origin/main's index.mjs,
2 of 3 red (the third guards the marks); with the string system's line
kept, 1 red.
Not tried before the push: a real Kiro turn (done after publishing, recorded
in magpie's min commit and on magpie-community#1774).
…agpie-community#1778)

Reported on X (xiaojiang596): after Grok Build updated itself, the Grok
card stayed on "Grok Build couldn't renew the sign-in
(grok-1.0.92-macos-aarch64 models ran and left the same token in 2s:
- grok-4.5)", and running the native build by hand changed nothing.

Cause: `grok models` renews a token only within
GROK_AUTH_EARLY_INVALIDATION_SECS (300 s) of its expires_at. A token Grok
turns away ("Invalid or expired credentials") hours before that is left
as it was; the run prints the model list and exits 0. So the 401 path
(requests, model list, usage) never renewed such a token, on any build;
the tests' fake CLI renewed whatever it was asked to, which hid it.

Fix: the renewal for a token Grok judged (TURNED_AWAY, or a 401 with no
words) sets GROK_AUTH_EARLY_INVALIDATION_SECS for its run to a minute more
than the token has left, decided as the run starts and only while
auth.json still holds that token. It stays under the token's whole life
(JWT exp - iat): a huge value makes the CLI refresh on every call of the
run (7 refreshes seen with 1.0.92), so a token refused within ~90 s of
being made isn't forced. A 401 with other words (magpie-community#818) is left to the CLI
as before. Sibling: rolled out to the unified build, "not signed in",
"ended" and "turned away even after renewing" name the native build's
login (`~/.grok/downloads/grok-1.x… login`), not `grok login`, whose
unified login makes no auth.json (magpie-community#1771).

The fakes now renew only when the real CLI would (due() in fakecli.mjs,
and unified.test.mjs's native fake), which turns the existing renew
tests into tests of this.

Run:
- Real grok 1.0.50, 1.0.67, 1.0.92 and 1.0.97 (macos-aarch64) in a
  sandbox HOME/GROK_HOME against a stand-in OIDC issuer and a logging
  proxy, token with 3 h left: plain `grok models` 0 refreshes, token
  unchanged, exit 0; with the variable set to left+60, 1 refresh and a
  new token each. A revoked refresh token (invalid_grant): exit 0 and
  auth.json becomes {}.
- The plugin's request 401 path with the real 1.0.92 in that sandbox:
  old index.mjs gives the reporter's message ("grok models ran and left
  the same token in 2s: - grok-4.5"); new index.mjs: one refresh, the
  request sent again with the new token, 200. Same with 1.0.97.
- packages/grok on WSL (magpie-desktop, bun 1.4.2): 132 pass. New tests
  against the old index.mjs: 7 fail (the four renew-again tests, the
  forced-renewal test, the cap test, the unified one). The native login
  message broken by hand (loginCmd returning "grok login"): the unified
  test fails.
- packages/grok on Windows (xiaomi-gpu, win-run): 113 pass, 0 fail.
- Root `HOME=$(mktemp -d) bun test` on WSL at this change: 10133 pass,
  3 fail, all outside grok and timed out at load 30-40 beside two Go
  suites: cursor native-http1 KV replies (magpie-community#754), cursor native-session
  frames (magpie-community#1780), tabbit both builds (magpie-community#1781). Those two files alone right
  after: 57 pass, 0 fail. `bun scripts/check.mjs grok` ok.

Not tried: a real xAI account (no real-account requests), and the
unified agent-host build itself (its download 404s here); where it keeps
its own sign-in is still unknown.

Rebased onto 8814b39 (kiro only) after the runs; packages/grok unchanged by it.
…e app's own (magpie-community#1779)

0.1.19, on top of 0.1.18. Found while looking at a report of the opposite kind (额度 not showing because the user had opened *their* 豆包, not the plugin's copy): with the plugin's own window open, a check-in right after a usage read said `inactive` for an account Doubao does offer a 每日签到 to.

0.1.16 read the common query off any /alice/ request that carried device_id
and aid — and then built a query that carries both too. After one read the
plugin's own call passed for the app's, and every read after it copied that.
Doubao answers a query without runtime_version with the campaign's reduced task
list (5 tasks, no daily_signin), so magpie said "豆包今天没有给这个账号签到入口"
for an account Doubao does offer a 每日签到 to. Seen on a real account once its
window had just been opened: the usage read went first, and the check-in after
it said inactive, while the same account's detail read a minute later showed
checked_in_today with the day's reward and a streak of 1.

A request is the app's own when it carries runtime_version, the one value the
page cannot build (no localStorage key, no <meta>, no global has it — only the
app's own requests do). The built query never has it, so it can no longer pass
for the app's, and a check-in read before the app's first call is failed to try
again, as it was meant to be.

queryWait is 15s now, from 8. A cold launch here took 6.4s from the window
answering to the app's first request, and magpie gives a check-in 25s: 8 left
little room on a slower machine.

Run on Windows 11, Bun 1.4.5, at origin/main 5623438 plus this change:
- packages/doubao-work `bun test ./doubao-work.test.mjs --timeout 60000`: 92
  tests, 91 pass, 1 fail. The red is "App says at once that a copy the user
  opened keeps it from starting": it expects the macOS app_busy path, which
  cdp.mjs (untouched) doesn't take on Windows. The 60s is this machine: bun's
  5s default also times out that test's neighbour, whose first choose() runs
  PowerShell (3.6-10s here).
- `bun scripts/check.mjs doubao-work`: ok.
- Against a real account, with the app's own window open: usage → 免费体验,
  活动赠送额度 used 46% (1,400 / 3,000 额度), resetsAt 2026-12-07T06:33:02.986Z;
  checkin → done, streak 1, credit 200 — twice in a row, with the plugin's own
  calls already in the page. The same sequence said inactive before the fix.

Broken by hand, each red:
- the predicate back to device_id and aid: 1 fails (a call the plugin made
  itself is not taken for the app's own).
- queryWait 0: 1 fails (a check-in waits for a window that has just opened to
  make its own call).

Not tried: a day not yet checked in — this account was in today, so the claim
itself was again only seen as the idempotent answer, as the README says.


Review run at the reviewed head 13dacd9 (WSL magpie-desktop, Bun, sandbox HOME):
- packages/doubao-work `bun test ./doubao-work.test.mjs --timeout 30000`: 92 pass, 0 fail (the Windows-only app_busy red the author names does not occur on Linux).
- `bun scripts/check.mjs doubao-work`: ok.
- Predicate put back to device_id and aid by hand: 91 pass, 1 fail ("a call the plugin made itself is not taken for the app's own").
- Merges clean with main f1bed88. runtime_version is already what the detail read relies on for the full task list (checkinOf), so the new mark adds no assumption about the app's requests that the check-in didn't already make.
- Not tried by the reviewer: a real Doubao account (author ran one on Windows), macOS.
…and in routing (magpie-community#1784)

A personal QwenWork account's quota has total and used null, so its card
was a balance string only and windows was empty: magpie's expiring and
pace-drain routing had no runsOutAt / runsOut for it. The wallets answer
already lists each live grant in active_wallets.wallets with its balance
and valid_to.

parseAccountContext now gives such an account one balance window
(Credits, balance = quota.remaining, unit credits, no used share), and
nextLapse puts the batch that ends first on it: runsOutAt its valid_to,
runsOut its balance, capped at what is left. Wallets carry no pool name,
so batches are told apart by their date alone; several ending at once are
one batch. A wallet with balance 0 or a valid_to in the past is skipped.
A live wallet whose valid_to is missing, empty or unreadable may end
before any other, so the next batch is left unknown (no runsOutAt), never
taken as "never". The balance string with each pool stays as magpie-community#385 made
it; the spent window for nothing left, accounts with a total, biz
accounts and the enterprise flagship are unchanged. One balance window,
not one per pool, as magpie would count each balance window as a fund
of its own.

Tests (qwenwork.test.mjs) use the magpie-community#385 WALLETS fixture with the clock
held, and the reporter's 239.49 (monthly 100 · long-term 139.49); the
issue gives no dates for those, so theirs are set around the held
moment.

Run (WSL magpie-desktop, HOME=$(mktemp -d)):
- packages/qoder bun test: 499 pass, 0 fail, 48 files
- qwenwork.test.mjs under TZ=UTC, Asia/Shanghai, America/Los_Angeles:
  32 pass each
- bun scripts/check.mjs qoder: ok
- bun scripts/bumped.mjs origin/main (HQ): ok

Broken by hand, each red in qwenwork.test.mjs: no runsOut on the window
(9 fail), a missing valid_to taken as never (3), past wallets kept (1),
same-date wallets not summed (1), runsOut not capped by what is left
(1), empty wallets kept (4).

Not tried: a real QwenWork account (no real-account requests); what
valid_to a monthly or daily wallet carries in the reporter's own answer.
… says so and names the models that still answer (magpie-community#1785)

gtk96's Team account: Cursor refused cursor/auto-smart with 429 "Your
team has reached its usage limit: Please reach out to an admin to enable
on-demand usage, or return on 12/4/2026 when your limit resets." while
cursor/composer-2.5 and cursor/grok-4.7@500k answered in the same
minute. The reading had Cursor Models 72.48%, Other Models 100%, Total
76.91%, and no on-demand.

Cause: on Teams, Auto is Cursor Router (auto-smart), which counts what
it runs against the pool of the model it routes to. With Other Models
spent and on-demand off, Cursor refuses it and every model that pool
counts. Cursor Models still has room. Cursor's words name neither pool,
so the refusal reads as the whole account out. Total is not what gets
checked. magpie already rests only auto-smart, not the account, once
the windows are read (Other Models is scoped, so Allowance.Pooled holds
and restAfterMarked rests restID). Nothing changes on magpie's side.

Now usage() keeps each account's last two-pool reading (by token
subject, 64 at most, dropped for a merged plan). A 429 "usage limit
reached" for an Auto entry or a model Other Models counts, on a reading
from the last 30 minutes of the current period that says Other Models
is at 100% and Cursor Models isn't, gets the following after Cursor's
words: "— auto-smart routes to models this account's Other Models pool
counts, and that pool is used up (100%). Its Cursor Models pool (72%
used) still has room: pick one of its models by name (composer-2.5,
grok-4.7@500k)". It applies at every error exit of answerOf: before the
first event, mid-stream, and after a rebuild. Nothing is asked again as
another model, because that would change what the user is billed for.
The message still starts with "usage limit reached" and holds none of
magpie's creditWords, so it is still read as a quota limit and not as
out of credit.

Tests (pools-hint.test.mjs): a fake Cursor (stand-in fetch, an HTTP/2
agent server) refusing with Cursor's ERROR_USAGE_LIMIT words. They read
usage at the reporter's numbers, then check auto-smart and
claude-opus-5-5 get the hint, unstreamed, streamed and refused after
some text. They check composer-2.5 and grok-4.7@500k answer 200, and
that only auto-smart reached the agent API. These stay unchanged: no
reading, both pools at 100%, Other Models with room, a named Cursor
Models model, a non-429, a stale reading, and a reading past its
period's end.

Run: WSL magpie-desktop (wsl-run, temp HOME), bun test packages/cursor:
509 pass, 0 fail. bun scripts/check.mjs cursor: ok. HQ:
bun scripts/bumped.mjs origin/main: ok.

Broken by hand: with poolsHint returning e at once, 2 of 4 tests are
red. With only the SSE site unhinted, the main test is red on the
mid-stream case (it was green before that case was added, so it was
added).

Not tried: a real Cursor account (no real-account probes). The
reporter's real autoBucketModels is unknown, so the named list on
their account depends on it.
…nother call with the same ones reads them from the cache (magpie-community#1774)

After 0.1.46 the reporter (Kiro Power, enterprise) still measured the
plugin about 7% dearer than kiro2cc-proxy over the same work: 88 calls
for about 11.1 credits against 89 for 10.53. In their fixed-prefix test,
kiro2cc-proxy's calls were billed 0.017 to 0.028 each, the plugin's about
0.10. Within one conversation the plugin's opening was already stable
after 0.1.46 (the captured turns convert to the same bytes up to the new
message), and its conversationId is stable (magpie's
X-Magpie-Conversation). What was still different from kiro2cc-proxy is
where the instructions go: kiro2cc-proxy, and AIClient2API, send them as
a user turn of their own, answered "I will follow these instructions.";
the plugin put them at the head of the first user message. Kiro's cache
is read up to a message's end, so instructions that end with the first
question are never read by a call that asks something else: a title, a
subagent's first turn, a new conversation. kiro2cc-proxy's docs record
that first turns hit system+tools across sessions.

kiroRequest now opens with that pair (a thinking budget opens the
instructions' turn, and a budget alone makes one); the cache mark on the
instructions goes on their turn. The IDE's CreateResponse arm
(responsesBody) puts them back at the head of the first message, as the
IDE sends them. magpie-community#1783 (Claude Code's Environment reminder moving) now
only touches what comes after the pair.

Run (WSL magpie-desktop, Bun 1.4.2, temp HOME): kiro bun test 244 pass;
bun scripts/check.mjs kiro ok. The whole plugins suite on WSL had 10145
pass, 1 fail that the cut log doesn't name, under another session's GUI
suite; a rerun there drowned in load timeouts (185, none in kiro). The
pull request's CI run is the whole-suite record: pr.yml run 46594923196 at 94d7cde (ubuntu, attempt 1), bun test and check.mjs green.
Broken by hand: the five touched test files against 0.1.46's index.mjs,
13 of 19 red (all five files, every system-turn test but the empty and
CreateResponse ones); with responsesBody reading the raw entries, the
CreateResponse test red.
The two captured Claude Code 2.1.327 turns, converted (cmp.mjs): turn 2
opens with turn 1's pair and question byte for byte (27579 and 76 chars,
then 19636 of 19636), same conversationId, tools the same; the pair is
the one kiro2cc-proxy's converter sends (src/kiro/provider tests).
Not tried: a real account. The two real turns allowed for magpie-community#1774 went on
0.1.46, so the saving is inferred from kiro2cc-proxy's billing and its
docs, not measured; the reporter is asked to rerun their fixed-prefix
test.
…emini and the other new steps opt-in (magpie-community#1788)

history-trim 0.2.0 by manjughosa. Two fixes now apply by default:
- A cut is never longer than the original (the length-inversion guard).
- An Anthropic tool_result with several text parts is held to maxToolLength in total, and its non-text parts (images) are kept.

Everything else is opt-in and off by default:
- truncationMode "head-tail" (65% from the head, 35% from the tail)
- preserveToolErrors
- foldContentBlocks
- trimDeveloper
- trimAnthropicSystem
- trimResponses
- trimGemini, whose cut keeps short response fields such as stderr and exit_code whole

The prompt-cache guard from the first version (respectCacheControl and the options that went with it) was taken out after review: its floor moved with the client's breakpoints and caused cache misses.

Reviewed and run at 484f035. Unless noted, runs were on WSL magpie-desktop on xiaomi-gpu with Bun 1.4.2 and a temp HOME.
- `bun test packages/history-trim`: 44 pass, 0 fail. The first 27 cases are byte-identical to main's.
- `bun scripts/check.mjs history-trim`: registry.json passes. `bun scripts/bumped.mjs origin/main` (on HQ): passes.
- Broken by hand, each turning its own case red, then restored to 44/44:
  - the length-inversion guard
  - the surrogate guards at the head and the tail. The tail case now fails without its guard; at 50ac03a it didn't.
  - preserveToolErrors
  - the multi-part budget
  - Gemini's short-field budget
  - Gemini thought parts being folded
  - each of trimResponses, trimGemini, trimDeveloper, trimAnthropicSystem and foldContentBlocks defaulting to on
  - head-tail falling back to head
  - the Responses current turn being cut
- Old (0.1.2) against new, on 36k random bodies across Anthropic, Chat, Responses and Gemini, using only 0.1.2's options. 83% are byte-identical. Every difference is one of the two default fixes:
  - an Anthropic tool_result with several text parts
  - a result where 0.1.2's cut came out longer than its input, e.g. 2005 chars became 2010
- Defaults leave these unchanged: an Anthropic string body.system, a Responses function_call_output, a Gemini functionResponse, and a repeated developer message.
- Gemini `{stdout: 6000 chars, stderr, exit_code}` in head mode: stderr and exit_code are kept whole and stdout is cut.
- Invariant fuzz over 12k bodies per format, with the opt-ins switched on at random. No break in any of these:
  - tool pairs stay together, and the first message stays a user message
  - thinking blocks and signatures are unchanged, and so is the current turn
  - no lone surrogate appears, and the body never grows
- Cache stability: about 60k pairs of consecutive requests, replaying each conversation one turn at a time. Each request re-sends the earlier history byte for byte, along with system, instructions and systemInstruction, with one exception: under the opt-in trimAnthropicSystem, body.system changes once, from turn 1 to turn 2. The first request is left whole, the same as 0.1.2 does with messages.
- The earlier review's cases A, B, C and F (client breakpoints that move) now match 0.1.2 exactly.
- Bun timing on 2000 items (about 3.2MB): old and new are within 1-3ms of each other for Anthropic and Chat, and Responses and Gemini go through untouched by default. At 50ac03a in moejs, Chat already took about 250ms on main, at the onRequest limit. That is not this change.

Not tried: real clients or accounts, and magpie's moejs at this head. moejs was run at 50ac03a, and its default paths are the same as here.
… and dropped only when its own listing names no profile (magpie-community#1786)

An Identity Center account whose organization took a region away (its
profile there still saved) had every chat, model list and provider test
answered 403 "The bearer token included in the request is invalid."
however often the token was renewed. A region that turns down a renewed
token (a chat, a model list, or a credits read that is turned down again
after renewal) is now passed over for an hour while the other region
takes the request, and its profiles are listed again. It is dropped from
the saved sign-in only when its own List-Available-Profiles answered
with a list that names no profile there. A failed listing (a 5xx, a
timeout, a 403) or a 200 with no list keeps it. With every region
refusing, the 403 is passed on and no region is shut out.

By caozhenyuan (magpie-community#1786); the 200-with-no-list guard was added in review.

Review, at ca73f3b (rebased on 7deb56a, kiro 0.1.47):
- Read every line of index.mjs, README and region-refused.test.mjs.
- At 54c90db a 503 on the refused region's listing, or one usage 403 plus
  a failed listing, deleted us-east-1 from the saved sign-in. Fixed in
  11434c7.
- Probes against 11434c7, with the test file's fake: a chat-refused
  region whose listing answers 503, 500, 403, 429 or times out stays saved
  over two requests. One usage 403 plus a failed listing neither refuses
  nor drops it. A renewed usage 403 plus a failed listing keeps it. 15 of
  15 kept. A 200 {} listing dropped it, so ca73f3b counts a listing as
  answered only when it holds a profiles array.
- WSL magpie-desktop, Bun 1.4.2, temp HOME: kiro bun test 268 pass, 0 fail;
  check.mjs kiro ok.
- Broken by hand, each turning region-refused tests red:
  - the old drop rule: 1;
  - answered never filled: 1;
  - usage refusing on one 403: 2;
  - usage never refusing: 1;
  - pick ignoring refused: 2;
  - the models hook without listedModels: 1;
  - any 200 counted as answered: 1.
- CI pr.yml run 46597530426 at ca73f3b, attempt 1: test (whole suite) and
  check green; bumped and on-npm green.
Not tried: a real account whose region was taken away.
…in (magpie-community#1796)

Since 0.1.16 the model list comes from brief_list and the menu isn't read, so no model got a 倍率. Each brief_list model item carries the tags the menu prints beside it in tag_list ("0.65x", "限时优惠 0.01x", "新上线 0.80x", "小额免费"). listOf now gives those tag texts to the row as its lines, and rateOf reads the rate from them. A free tag gives no rate. When a task's menu is read (ask), its rate still comes first, and the tags are used only when the menu has none. models.json goes from format 2 to 3, so a list cached without rates is read again. Its models are kept until then, as for any older format.

Reviewed at 295f216:
- tag_list's shape was checked against Doubao's own client code, because the repo's only real brief_list (testdata, 2026-11-13) has no tag_list. The bundled ai-views JS of Doubao.app (Doubao Browser 147.0.7727.149) maps a menu item's `tag_list` to `{type, text, icon, colours}` and renders those tags beside the model's name. The PR reads `.text`, and LIST's icon filter leaves it alone.
- WSL (magpie-desktop), HOME=$(mktemp -d): `bun test` in packages/doubao-work gave 95 pass, 0 fail. `bun scripts/check.mjs doubao-work` passed.
- HQ: `bun scripts/bumped.mjs origin/main` passed. dist's index.json has 0.1.19 as latest.
- Broken by hand on WSL, each one red: no tag_list passed to the row (the listOf test), CACHE back to 2 (4 tests), and tableFrom ignoring lines (the listOf test and the menu-rate test).
- Windows (xiaomi-gpu): the author's one red, "App says at once that a copy the user opened keeps it from starting", is red the same way at origin/main 6986371. The test leaves out `platform`, so it is a test bug and not a plugin bug. Filed as magpie-community#1797.

Not tried: a real Doubao account (that is the author's run in the PR), the app itself, or the Windows suite as a whole.
… the end doesn't wait for agy to exit

agy asks Gemini for its thoughts (includeThoughts) and writes them into its
conversation store while they come, in field 20.3 of the PLANNER_RESPONSE
step, before the answer's 20.1. live.mjs read 20.1 only, so a client saw
nothing for as long as the model thought: with Gemini sending six thoughts
0.5s apart, the first delta reached the client at 4.31s though the first
thought was in the store at 1.27s.

- live.mjs: stepOf reads a step's text and thinking; liveReply gives both
  ({ text, thinking }). replyOf and liveText stay as they were.
- index.mjs: the turn's live state carries the thinking; a stream sends
  what is new of it as delta.reasoning_content, before the text, kept
  apart across a tool call's responses like the text (turn.thought); not
  streamed, it is the message's reasoning_content.
- The client is told the end as soon as the turn has its answer, before
  the turn's agy is stopped. agy flushes its telemetry to
  play.googleapis.com on the way out, and [DONE] waited for that (up to the
  5s kill). Its files still go once agy has; settled() lets the tests wait
  for that.
- The fake helper writes thinking (FAKE_TUI_THINK), can take a while to
  exit (FAKE_TUI_EXIT_MS), and gives each spawn its own conversation id, as
  agy does: with one fixed id, a turn's claim on it outlived the turn by the
  previous agy's exit, and the next turn couldn't find its own.

Measured with the real agy 1.5.20 against a fake Gemini (API key, sandbox
HOME): six thoughts then four text pieces, 0.5s apart.
- before (0.1.5): first delta at 4.31s, the first text, though Gemini's
  first thought went out at 1.27s; deltas CCCC.
- after: first delta at 1.24s, 0.05s after Gemini's first thought;
  deltas RRRRRRCCCC.
- with agy's network held 3s a connection (its exit flush to
  play.googleapis.com): [DONE] 3.08s after the last text before, 0.03s
  after.

Run at 944c2d9d:
- packages/agy-tui, bun test with the real agy (AGY_TUI_TEST_AGY=agy
  1.5.20, MAGPIE_EXE=v0.1.5217's tui-helper), temp HOME, HQ: 53 pass,
  0 fail.
- bun scripts/check.mjs, HQ: ok.
- the fake suite alone before the rebase (only doubao-work changed since),
  mote: 44 pass, 11 skip (the real agy's), 0 fail.
- The root bun test is queued behind mote's suite lock; CI runs it on
  this push.

Broken by hand, on mote: without the 20.3 read, the store test and both
thinking tests go red; with the end told after cleanup again, "the end
doesn't wait for agy's way out" goes red (end 4.1s after the last text,
bar 2.5s).

Not tried: a signed-in (OAuth) account. Every turn's agy still makes ~20
Cloud Code calls and the userinfo eligibility check before its first
model request; that start-up cost is not changed here.
…context percentage (magpie-community#1774)

Kiro sends no token counts. The plugin reckoned the input as Kiro's
contextUsagePercentage times the model's listed maxInputTokens. That
percentage is how full Kiro's own context window is, by Kiro's own count
and against its own window, not the size of the prompt. Against what the
plugin sent it came out at 1.2 to 2.5 times the prompt:
- magpie-community#1774 (skytechfyh): 62.7K reported for a prompt kiro2cc-proxy's cl100k
  counts at 30.2K, so magpie showed about $3.99 for 36 calls where the
  proxy showed $0.43, at the same credits;
- the real reply in cache-unknown.test.mjs: 11.03% of 200K, 22K, for a
  prompt of about 9K.
The plugin doesn't send anything twice: a real Claude Code request has
92,509 characters of content and its Kiro body 92,310. kiro2cc-proxy
dropped the same reckoning for the same reason (its openspec "决策 10")
and counts locally.

Now ask() records promptTokens of the body it sends, keyed by Kiro's
reply, and events() reports it as the input when Kiro reports no
tokenUsage. promptTokens counts every text the body carries (the
instructions' turn, messages, tool calls and results, reasoning, the
tools offered): four ASCII characters a token, a token for each other
character, 1,600 for each image. On the real Claude Code 2.1.327
request cl100k gives 4.44 characters a token, so this sits about 11%
above cl100k, near Claude's own tokenizer. It is still an estimate: the
cache stays unknown (magpie_cache_unknown) and usage.credit is Kiro's
as before. A web search's turns each count their own prompt, summed.
The windows map, used only for the old reckoning, is gone.

Run, at this tree (base e901616):
- wsl-run (magpie-desktop), HOME=$(mktemp -d), packages/kiro: bun test,
  258 pass, 0 fail; bun scripts/check.mjs kiro, ok.
- HQ: bun scripts/bumped.mjs origin/main, ok.
Broken by hand:
- the old index.mjs with only promptTokens and kiroSent grafted in:
  prompt-tokens.test.mjs 3 red (input 62700 where <= 10235, and a
  search's 90000 where 2758), the 3 promptTokens unit tests green.
- promptTokens counting every character at four a token, no images:
  the CJK/image test red (250 where 1000).
Not tried: a real Kiro request. No real account was used; how close the
estimate comes to Kiro's own count is known only from the captured
request and the reporter's numbers.
…ch directive (magpie-community#1795)

magpie's plugin frame is `sandbox="allow-scripts"`, so the page has an opaque origin and the system WebKit matches `'self'` against nothing. page-usage-tree's CSP named the loopback origin only in connect-src, so style.css, the scripts and the icon were refused and the page rendered unstyled in magpie's Mac window (magpie-community#1794). default-src, script-src, style-src, img-src and connect-src now list `http://127.0.0.1:<port> http://localhost:<port>` beside `'self'` (no `[::1]`: CSP host-source has no IPv6 literal). A new server test asserts each directive lists the service's origin. 0.1.2 -> 0.1.3.

Run at the reviewed head 71764ec (only 71764ec is new since the review at d8d4d56; it drops the `[::1]` source and updates the comment):
- WSL (magpie-desktop, Bun 1.4.2, Node 22): `bun test` in the package 63 pass, 1 skip (parity, needs a live gateway); `node --test test/server.test.mjs test/page.test.mjs` 48/48; `bun scripts/check.mjs page-usage-tree` ok.
- HQ: `bun scripts/bumped.mjs origin/main` (71d3933) ok. dist index.json had 0.1.0 to 0.1.2, so 0.1.3 is new.
- Real WKWebView on macOS 26.2, page in a `sandbox="allow-scripts"` frame on another origin: main's server fetched only `/` and rendered unstyled; this head fetched style.css, bridge.js, i18n.js, view.js, app.js and /api/tree, rendered styled, and reported no securitypolicyviolation.
- At d8d4d56 the new test was red with main's CSP put back by hand.
…ult-src and script-src (magpie-community#1801)

window-warmup's page CSP was `default-src 'self'; script-src 'self' 'nonce-…'`. magpie's plugin frame is `sandbox="allow-scripts"`, so the page has an opaque origin and the system WebKit matches `'self'` against nothing: the external style.css and the module app.js were refused and the page stayed empty in magpie's Mac window (magpie-community#1506). default-src and script-src now list `http://127.0.0.1:<port> http://localhost:<port>` beside `'self'` (no `[::1]`). connect-src already allowed `http: https:`. The page loads nothing else: no images, fonts, frames or workers, and its inline styling is CSSOM only. A server test asserts both directives list the origin and that `[::1]` is absent. 0.1.7 -> 0.1.8.

Run at the reviewed head 3adb496:
- WSL (magpie-desktop, Bun 1.4.2): `bun test` in the package 282 pass, 1 skip (the browser smoke, because bun test doesn't use NODE_PATH). With playwright linked into node_modules, tests/browser.test.ts passed 6/6 in Chromium and WebKit. `bun run build` reproduced dist/ byte for byte (`diff -r` empty). `bun scripts/check.mjs window-warmup` ok. With main's CSP put back by hand, the new server test went red (`Expected to contain: "http://127.0.0.1:39003"`).
- HQ: `bun scripts/bumped.mjs origin/main` (71d3933) ok. dist index.json had 0.1.0 to 0.1.7, so 0.1.8 is new. Not on npm (dist only).
- Real WKWebView on macOS 26.2: the service ran from src with a fake gateway, its page in a `sandbox="allow-scripts"` frame on another origin. On main, only `/` was fetched; style.css and app.js raised securitypolicyviolation (style-src-elem, script-src-elem) and the page was unstyled markup with no tasks. At this head: style.css, app.js, /api/catalog and /api/state were fetched, the page rendered, "新建任务" opened the editor with the fake account, and no violation was reported.
- Not tried: a real magpie window with the installed package.
…a fixed 2,100 (magpie-community#1807)

The Daily pool's limit was Math.max(DAILY_POOL_CAP, dailyRemain,
dailyUnexpired), so it never went under 2,100 (7 x 300). On a day whose
grant isn't claimed yet only six daily grants are live (1,800), and the
unclaimed 300 read as spent. PanXinglin's account A: daily_points 1,466
against six live grants read 634 / 2100; the bills say 334 / 1800.
Account B (1,598 then 1,578 left) read ~522 where 222 is used.

dailyPoolLimit takes the face value of the unexpired daily_grant bills
when the bills account for the pool, so used = live grants - daily_points.
The grants are unknown, not 0, and the limit falls back to the old
max(2,100, daily_points, live grants) when:
- the bills weren't read (both reads failed);
- the page came back full (income: 200 rows; the paged fallback: 5,000).
  paging.offset is ignored, so a full page may have left grants out;
  allBills marks it `full`;
- daily_points is over every live daily grant listed (a grant past
  expire_at not swept yet, or a schedule the bills don't show).
Expired grants were already left out of dailyUnexpired (expire_at <= now).

runsOut/runsOutAt are unchanged (magpie-community#1776's first-to-expire-first-spent).
The issue expected runsOut 300 for account A, but under that order
334 used is today's 300 plus 34 of tomorrow's, so tomorrow holds 266
(1,466 = 4 x 300 + 266); the test pins 266 at tomorrow's expiry, with
today's spent grant passed over. Account B's today grant holds 78.

The 2-grant fixture of "usage reports Credits window..." read 1581 / 2100
for 600 of live grants and 519 left; it now reads 81 / 600. README (en,
zh) says where the limit comes from and when it falls back.

Tests, from the reporter's numbers (six live 300 grants, soonest today,
two expired ones listed too): account A 334 / 1800, runsOut 266 at
tomorrow; account B 202 and 222 / 1800, runsOut 98 and 78 today; after
claiming (seven grants, 1,766 left) 334 / 2100, used unchanged; bills
read failed, a full page of 200, and daily_points over the live grants
each fall back to 2,100.

Run on xiaomi-gpu WSL (magpie-desktop), HOME a temp dir, at this tree
(base c330e54):
- bun test packages/raccoon: 98 pass, 0 fail.
- Broken by hand: the old max(2,100, ...) limit: 3 fail (accounts A, B,
  and the 81 / 600 test). known = true: 5 fail (the three fallbacks and
  the two older fallback tests). allBills without `full`: 1 fail (the
  full-page test).
- bun scripts/check.mjs raccoon: ok. bun scripts/bumped.mjs origin/main
  run on HQ after the commit (it needs git; the WSL copy has none).
Not tried: no request to a real raccoon account; the reporter's numbers
are the only real data. Whether income bills come newest first is not
known, so a full page always falls back.
…g after a refused built-in tool hears the tool is off (magpie-community#1804, magpie-community#1805)

magpie-community#1804 (holEeast979, four Pro accounts): one account's saved offer lost
Gemini 4 Neon and Carbon while agy's calls to its service failed
(loadCodeAssist: EOF). For the offer's hour, requests for gemini-4-carbon
got 400 "unavailable to this agy account; another signed-in agy account
lists it", though `agy models` and a fresh agy acp session listed both.
A plugin-host restart in that hour froze the short offer into magpie's
plugin-providers.json. All three of the reporter's points held on
origin/main:
- A config_option_update mid-session overwrote the offer and saved it.
  Now an update that loses a model family the offer had isn't saved; the
  offer is marked stale and asked again. Families are compared because
  an update names bare ids (gemini-4-neon) where an opened session's
  offer also has suffixed ones (gemini-4-neon-high). An update with the
  same families is believed, as before.
- The magpie-community#1542 fast 400 had no re-probe. Now, when the offer lacks the model
  but this account's `agy models` lists it and another account lists it,
  recheckOffer asks agy acp again first (at most once in 5 minutes per
  account, past the probes' 60s gate, bounded by the probe's 30s). A
  fresh offer with the model lets the request through. A probe that
  fails leaves the offer stale (unknown), and the request goes on by the
  listing.
- models() didn't mark fell back while an offer in doubt was being asked
  again. Now a stale offer (past its hour, saved by an earlier run, or
  put in doubt by an update) with a listing or probe in flight is marked
  magpie.fellBack, so magpie keeps the list it had.
magpie side, not changed: after a fell-back answer magpie keeps the last
good list (keepListed) and asks again at the hourly relist. It doesn't
re-read when the probe ends (host.js doesn't read warming()). Filed as
yetone/magpie#8475.

magpie-community#1805 (berwinjoule): a native agy tool (read_file, run_command) on a path
outside the session's folder is asked of the bridge as
session/request_permission. The bridge refuses it, and agy tells the
model "user denied permission … do not circumvent". The model ended its
turn thinking. The retry's generic "Your last reply was empty" then led
it to tell the user it had no access to the project. Now a refused
permission or a tool-gate hook denial in the turn marks it. An ending
after it with no text and no tool call is asked again (a bare one too,
which before was taken as the reply), with words that say the built-in
tool is off in this session, that this is not the user refusing the
project, that there is no need to ask for workspace access, and to use
the tools it was given. The words name neither magpie, agy, Google,
Gemini nor the bridge's parts; a test fails if they do. A second empty
ending's error says a call to one of agy's own tools was turned away.
A better refusal text was not possible: agy 1.5.20's
RequestPermissionResult has only the selected/cancelled outcome, with no
message, and its "user denied permission" wording is fixed. For
read_file outside the workspace, agy's path permission check comes
before the PreToolUse hook. allowNonWorkspaceAccess would let reads
outside the folder through unchecked, so it was not used.

Tests, each red with its fix taken out by hand (WSL, agy-cli test/):
- catalog.mjs "a session's update that loses models …": red without the
  update guard.
- "a model the offer lacks but agy models lists …": red without
  recheckOffer. It also checks the 5-minute throttle and that a still-short
  offer is turned away.
- "a saved offer in doubt is marked fell back …": red with the old
  fellBack condition.
- repeat-batch.mjs "an empty ending after a refused built-in tool …"
  (refused permission, hook denial, refusal with nothing after): red with
  EMPTY_REPLY_PROMPT kept, and red without deniedSinceCall in
  emptyEnding.
- Also added: the plain-words case, a refusal answered in text, and the
  second-empty error.

Run at this tree (rebased on e837bf6):
- wsl-run (magpie-desktop, Bun 1.4.2): packages/agy-cli `HOME=$(mktemp -d)
  bun test`: 75 pass, 0 fail across 3 files
  (agy-cli.test.mjs runs each test/*.mjs, catalog.mjs and
  repeat-batch.mjs included), 351.77s
- bun scripts/check.mjs agy-cli: registry.json and agy-cli ok
- HQ: bun scripts/bumped.mjs origin/main: "every package that changed
  since origin/main has a new version".
Not tried: a real agy (no sandbox run; a fake sign-in could make agy
refresh a token with Google), and no real account.
…ls (magpie-community#1809)

performCheckIn called setting_info and diffed the grant bills before and
after. With no new grant it answered done / 今日已签到 in two cases where
nothing says the day's credit is in (PanXinglin's accounts had no
daily_grant today):
- the bills read before the call failed: it returned done without
  reading the bills at all;
- the bills read fine but held no grant today: setting_info answering
  code 0 (with point_grant_popups []) was taken as checked in.
It also read only the newest 20 bills of every kind, so on a busy
account desktop LLM spends could push the day's grant out of view.

Now the outcome comes from the income bills, read as the usage read
reads them (allBills: type=income first, the paged read as fallback):
- a grant bill not there before the call: claimed, as before;
- a daily_grant created today (the Beijing day, beijingTodayKey and
  created_at's date, as before) already there: done / 今日已签到;
- none today: inactive, "今日每日积分未入账:收入账单里还没有今天的每日
  发放(daily_grant)", with until 30 minutes on. magpie settles a
  plugin's inactive for the Beijing day from noon on, but an until is
  asked again when reached whatever the outcome (settled), so the
  account keeps being looked at and turns done once a grant shows up,
  with no change to magpie's pluginRechecks;
- bills unread after the call: failed, "读不到积分账单,无法确认今日是否
  已签到", tried again after 30 minutes. A 401 there is thrown, so the
  hook's refresh path runs. An onboarding grant claimed in the same call
  still reads claimed.
A failed before-read only leaves claimed from done untold: a grant
today then reads done.

No claim endpoint is known: setting_info stays the only call, and no
chat request is made to trigger a grant. Why the vendor didn't grant on
the reporter's accounts is not known and not guessed at in the message.

Tests (the issue's five cases, bills in the shapes of the income bills
the report read): setting_info 200 with only yesterday's daily_grant ->
inactive with until 30 min on, income filter used; bills unread before,
read after with no grant -> inactive; unread both times -> failed; a
daily_grant today from another client -> done; a grant that lands
between two check-ins (after a chat) -> inactive then done; a desktop
spend but no income -> inactive twice; a busy account (40 spends ahead of
the grant in the mixed list) -> claimed +300. Three older tests that
pinned done for no grant now expect inactive, and the before-read
failure test fails the income and paged reads both.

Run on xiaomi-gpu WSL (magpie-desktop), HOME a temp dir, at this tree
(base 2f953b1):
- bun test packages/raccoon: 103 pass, 0 fail.
- Broken by hand (raccoon.test.mjs): origin/main's index.mjs: 6 fail
  (cases 1, 2, 4, 5, the busy account, the onboarding test); done
  restored for no grant: 5 fail; the newest-20 mixed read instead of
  allBills: 2 fail; done when the bills are unread: 1 fail. The
  "another client" case passes on the old code too, as it should.
- bun scripts/check.mjs raccoon: ok. bun scripts/bumped.mjs origin/main
  run on HQ after the commit.
Not tried: no request to a real Raccoon account. In magpie, an inactive
past noon hides the card's Check in now (checkinDue), though the loop
still asks at the until; the card reads "No check-in event now · <the
message>".
…sh window from the ledger and routes on it (magpie-community#1806)

zane668 (magpie-community#1806) asked for an opt-in that turns the China build's
deepseek-v4.1-flash window back into a card from the ledger, so that the
account's "cap at N%" stops the model before WorkBuddy refuses it. On
accounts spent only through their magpie, WorkBuddy refused within about
1% of CN_WINDOWS' 2e8, and the named reset was the window's first request
+ 24h to the minute.

Decision (coordinator): one provider-level switch, not per account.
magpie's plugin options (auth.options, magpie-community#2038) are per provider and on/off
only; a per-account, sized setting would be a magpie settings and GUI
change of its own. So the size is the measured 2e8, one constant
(CN_FLASH_CAP), and the README says it is the measured cap.

- CN_ESTIMATE ("cn_flash_estimate"), declared on the China build only,
  off by default, in en/zh/zh-TW/ja/de. Its words say it is for accounts
  used only through this magpie.
- Off: cnWindows(false) is CN_WINDOWS itself, and usage() takes the same
  path as 0.2.49 (rows && freeWindowOf), so the output is unchanged.
- On: routedWindowOf gives "deepseek-v4.1-flash tokens (est.)" with
  in + cache_read + out against 2e8, not set aside (magpie caps a window
  that isn't aside, account_caps.go), its end the window's first request
  + 24h (freeWindowOf's chain). A refusal whose reset is ahead still wins,
  with or without an open window. Nothing spent in the window: 0, no end.
  A ledger that can't be read (freeWindowRows null): display "?", no
  share, set aside, so unknown and never 0 used.
- freeWindowOf's card is now windowCard, the same object, shared with
  routedWindowOf.

Tests:
- freewindow.test.mjs: switch off is CN_WINDOWS itself; on gives
  180M/2e8 = 90%, reset at the first request after the last window
  + 24h, -sg rows counted, other accounts and the AI build not; a refusal
  wins over the count, also with no answered row; a lapsed window reads 0
  and a ledger that is a folder reads unknown.
- usage.test.mjs: through usage() with input.magpie.option, off equals
  the card with no magpie at all (Credits only); on gives the routed card
  (75%, reset first + 24h); with the ledger gone, the "?" card; only the
  China build declares the switch, off by default, words within magpie's
  60/300 limits.

Run on WSL magpie-desktop (wsl-run, bun 1.4.2, HOME=$(mktemp -d)):
- packages/workbuddy bun test: 466 pass, 0 fail, 41 files.
- bun scripts/check.mjs workbuddy: registry.json and workbuddy ok.
- bun scripts/bumped.mjs origin/main on HQ: every changed package bumped.
Broken by hand: the new tests against origin/main's index.mjs (2f953b1):
6 fail, 97 pass in freewindow and usage. With routedWindowOf reading an
unread ledger as [] and the routed card set aside: 3 fail.

Not tried: a real China-build account through magpie (no real-account
requests), the reporter's own ledger, and magpie's routing of the card
with a cap set (the card's shape is what magpie caps; not run end to end).
…its (magpie-community#1811)

Fixes magpie-community#1810. After a same-build reuse of the service port (the host on its
way out during magpie's rolling update), startServer() now tries to bind
the port once a second; EADDRINUSE waits silently, any other error is
logged once and stops. When the holder exits this copy binds, logs
"[usage-tree] the copy holding <port> let go — took it over" and warms
today's read. The reused handle's close() stops the attempt and closes a
server it took over, including one whose bind lands during close(). The
start path's close moved into a shared stop(). Another build on the port
is still reported and never reused or killed. 0.1.3 -> 0.1.4, rebased on
0.1.3's CSP fix (8ca1726), CSP unchanged.

Run by the reviewer at the reviewed head a2c5eac:
- WSL (magpie-desktop, bun 1.4.2, node 22.23.4): bun test 64 pass 1 skip
  (parity) 0 fail; node --test test/*.test.mjs 71 pass 1 skip 0 fail;
  bun scripts/check.mjs page-usage-tree ok.
- Windows (xiaomi-gpu, bun 1.4.2, node 22.23.4): bun test 68 pass 1 skip
  0 fail (with the review cases below); node --test lifecycle, server and
  the review cases 17 pass 0 fail; check.mjs ok.
- HQ: bun scripts/bumped.mjs origin/main ok.
- The new lifecycle test, with server.mjs at origin/main 14506bc: red
  under bun and node (0 !== 200).
- Review-only cases (not committed), WSL, Windows and mote (macOS): close()
  while waiting leaves the port unbound after 8 ticks; two waiters: one
  takes over, one log line, no error, the other takes the next turn after
  the first closes; a foreign server grabbing the port after the holder
  leaves: no takeover and no log line over ~7 ticks, then a takeover once
  it closes; after a takeover / is 200, the CSP lists 127.0.0.1:<port> in
  every fetch directive, and /api/tree with the page's token is 200.
- magpie-community#1810 for real, two processes loading index.mjs on a free port with a
  fake gateway, holder killed after 3s: PR head binds 0.05-0.12s after the
  holder exits and serves /, /healthz and /api/tree 200 on WSL, Windows
  and mote, node->node, bun->bun, node->bun and bun->node; origin/main
  stays dead for 6s on all three. A 0.1.3 holder with a 0.1.4 new copy is
  still "held by another build" (unchanged).

Not tried: a real magpie self-update; bun 1.4.5 (the reporter's).
Not changed, filed as magpie-community#1813: a page loaded from the old holder keeps
its token, so after any host swap its /api/tree answers 401 until the page
is opened again (also on main after any host restart).
…e-community#1753)

Fixes magpie-community#1408. agy-cli's installer ran a freshly written `agy --version` (and renamed it into place) once a WriteStream said `finish`, while its fd could still be open for writing, so Linux refused the exec with ETXTBSY. Both outputs (the raw download and the binary taken out of the tar.gz) are now written through a FileHandle: each chunk's write is awaited, and the handle's close is awaited before the file is renamed, probed or installed. A failing write or close fails the install; installAgy's cleanup removes the partial download and staged file, and the installed binary and version file stay. `drained` and its test went with the WriteStreams (nothing else used it).

Run at 1aad8f9 (the reviewed head, on main 7cf44e6):
- WSL magpie-desktop (Ubuntu 24.04, Bun 1.4.2), temp HOME: `bun test packages/agy-cli` 76 pass, 0 fail; `bun scripts/check.mjs agy-cli` ok. `node --test packages/agy-cli/*.test.mjs` fails to load (bun:test imports, ERR_UNSUPPORTED_ESM_URL_SCHEME), as on main.
- Red without the fix (WSL): the PR's install.test.mjs against origin/main's install.mjs, 2 fail (both close-fails tests); against the PR with `await` dropped from handle.close(), 2 fail; at the PR, 12 of 12.
- ETXTBSY for real (WSL, local fixtures, no network): installAgy of a #!/bin/sh agy from a local server, 2000 runs each under Bun 1.4.2. origin/main: archive 7 ETXTBSY, raw 4. PR: 0 and 0. Node 22.23.4, 300 runs: main 2 and 1, PR 0 and 0. 3MB multi-chunk fixtures installed whole (sha512) on Bun and Node; untarMember of a 6MB member whole, mode 755.
- Windows xiaomi-gpu (Bun 1.4.2): install.test.mjs 3 pass, 9 skipped (unix-only), 0 fail. With Node 22, installing an 87MB exe raw, starting it, and installing again over it: both installs whole, the running copy kept running and exited 0, the old one moved aside to .old-*.exe, same as main. untarMember of 6MB whole under Bun and Node.
- HQ: `bun scripts/bumped.mjs origin/main` ok. 0.1.183 is above dist's 0.1.182; npm has no agy-cli package (served from dist).

Not tried: a real agy download (no network to Antigravity), Bun on Windows through installAgy's raw path (untarMember covers the same writer there), and a sibling spawn inheriting the write fd between fork and exec (O_CLOEXEC; not this race).
…agpie-community#1813)

A page served by a plugin's local service carries that service copy's
per-run token. After a host swap (magpie's self-update, a restart) the
copy answering has a new token, so every /api call answered 401/403, and
the old "reload once" guards didn't hold in magpie's frame: it is
sandboxed with an opaque origin, so sessionStorage throws (model-quota's
guard never fired), an in-memory flag is gone after the reload (chat,
fingerprint, page-harnessweight's hash looped or got stuck), and several
pages had no recovery at all.

Every page.service package that gives its page a per-run token now
follows one rule. On the service's token refusal the page calls
location.replace with reauth=<now> added to its address (everything the
launcher put there kept). A document that such a reload opened and whose
token was never accepted shows the error instead of reloading again, so a
token that stays refused can't loop; a document whose token was accepted
once recovers from the next swap too. A second refusal while the page is
already going doesn't replace twice, and where a call can't finish it is
left pending instead of throwing into the UI.

- page-usage-tree 0.1.4 -> 0.1.5 (401 on /api/tree)
- page-model-quota 0.1.0 -> 0.1.1 (401; drops the sessionStorage guard)
- page-usage-board 0.1.2 -> 0.1.3 (401; every /api call through api())
- page-harnessweight 0.4.1 -> 0.4.2 (403 with reload:true)
- page-chat 0.1.15 -> 0.1.16 (403 with reload:true)
- opencode-atomcode-auth 0.3.2 -> 0.3.3 (diagnostics page, 403)
- gateway-aelios 0.1.1 -> 0.1.2 (/test page, 403; the reload also sets
  auto=1 so the test runs again, and /test accepts reauth)
- gateway-nowledge-mem 0.1.6 -> 0.1.7 (403; a reauth load runs the test)
- agent-kimi-desktop 0.1.7 -> 0.1.8 (settings, 403 invalid_session; only
  when nothing is unsaved, otherwise the restart notice stays)
- page-fingerprint 0.2.3 -> 0.2.4 (401; was location.reload() with no
  guard, a loop on a permanent 401; dist rebuilt)
- page-window-warmup 0.1.8 -> 0.1.9 (kept its ww-reauth marker; it now
  also reloads again after a later swap when its token had been
  accepted, and replaces once when two calls are refused together; dist
  rebuilt)

Not changed: amp-usage (token kept in a file), ua-switcher (capability
path, a 404 redirects), company-guard (nonce fetched again), layerfs (no
token).

Tests: scripts/fake-page.mjs runs a page's own scripts in a vm context
with a location that records replace(), storage that throws as in the
sandboxed frame, and waits on the page's requests in flight. Each
package's test drives real copies of its service on one port: swap, the
page reloads once with reauth and its address kept, the new document is
let in, a second swap recovers too; a reauth document with a refused
token shows the error with no replace. fingerprint and window-warmup have
Playwright tests in Chromium and WebKit in a sandbox="allow-scripts"
iframe (skipped where Playwright isn't installed, as CI has it);
window-warmup's also run with history.replaceState refused.

Run (WSL magpie-desktop, bun 1.4.2, node 22):
- HOME=$(mktemp -d) bun test at the root, at origin/main 7cf44e6 plus
  this change (rebased after onto 56d0344, agy-cli only, no file in
  common): 10221 pass,
  48 skip, 0 fail (713 files); bun scripts/check.mjs: exit 0. An earlier
  root run at load 18 (other sessions) had two reds in agy-tui and
  agy-cli, which this change doesn't touch; both pass alone and in the
  rerun, filed as magpie-community#1819. That run also showed that two token tests needed
  the harness to wait for the page's requests rather than a fixed number of
  turns (fixed before the rerun).
- node --test: page-usage-tree 73 pass, page-model-quota 15 pass,
  page-harnessweight 62 pass, page-usage-board 39 pass, 0 fail.
- bun test of the 9 fake-page token test files, 5 times: 9 pass each.
- fingerprint and window-warmup: tsc --noEmit ok; Playwright tests with
  playwright 1.62 linked into node_modules and PLAYWRIGHT_BROWSERS_PATH
  set: fingerprint 4 pass, window-warmup 6 pass (Chromium + WebKit).
- dist rebuilt on WSL; a build of the base reproduced the committed dist
  byte for byte first.
- Red on the old code, with the new tests: every swap test of the 9
  fake-page packages fails at origin/main 7cf44e6's sources (bun and
  node); fingerprint's old dist fails all 4 (the stuck page loaded 89
  times in Chromium, 60 in WebKit in 3s); window-warmup's old app.js
  fails both replaceState-refused swaps at the second swap and the
  Chromium stuck test (two replaces).
- HQ: bun scripts/bumped.mjs origin/main ok.

Not tried: a real magpie host swap or self-update; real accounts; the
real WebView2, WKWebView and WebKitGTK frames (Playwright's Chromium and
WebKit allow replaceState in an opaque frame, contrary to window-warmup's
comment, so the refused case is simulated).
…r line, nor a sign-in to make again (magpie-community#1711)

AlanWu-lab (0.2.12, magpie 0.1.5223) had about ten `auth.refresh` errors
a day: "grok models ran and left the same token in 5s: - grok-4.5". Three
of them came within 12s, just after the plugin updated.

Cause:
- These are real renewals of a token past its end, not ones run too
  early. `grok models` gives auth.x.ai's token exchange about 5s and then
  gives up silently. It exits 0 with empty stderr and prints the model
  list it shows signed out. The only record of the failure is
  "auth: silent refresh {outcome: Failed(SelfHealing)}" in its own
  <home>/logs/unified.jsonl.
- Measured with grok 1.0.67 against a stand-in token endpoint:
  - an answer after 3.5s renews;
  - after 6.5s, or no answer, it doesn't: 5s, exit 0, last line
    "  - grok-4.5", which is the reporter's line;
  - 503 gives four "token exchange failed" lines, then SelfHealing;
  - invalid_grant clears auth.json (ManualLogin).
- A slow or reset link to auth.x.ai fits the reporter's ECONNRESET the
  same day.
- The plugin read none of that. It took the stdout's last line, told the
  user to add the account again, which is wrong for this, and kept its
  backoff in memory. An update, a restart or a second magpie lost it, so
  the CLI was run and the failure told again at once.

Fix:
- After each run the plugin reads that run's lines in unified.jsonl (its
  pid, from when it started): the silent-refresh outcome, the exchange
  error, a terminal error and a permanent or transient failure.
  - ManualLogin/ProviderLogin, a terminal error or a permanent failure
    ends the sign-in at once, even at exit 0.
  - SelfHealing or a transient failure passes by itself. The error says
    so, and says to check the way to auth.x.ai (proxy). It is quiet in
    magpie's log for backoff.grace (30 min); one that lasts longer is
    told once, with "failing for N min".
- An unchanged token that is still good, with nothing failed, is no
  failure.
- The backoff state is kept in <home>/magpie-renewal.json, written
  through temp and rename. It holds a 16-hex sha256 prefix of the token,
  never the token, and is removed when a renewal works or the token
  changes. Memory is used where the file can't be written.

Run:
- The new selfheal.test.mjs has 7 tests built from the reporter's line
  and the real CLI's log lines. On origin/main's index.mjs (7555ca2) 6
  of 7 are red; the revoked case passes there too, as it should.
- Broken by hand, each break turned its test red:
  - the state not persisted → the restart test;
  - no grace → 4 tests;
  - verdict.final ignored → the ManualLogin-at-exit-0 test;
  - still-valid not success → its test;
  - lines not filtered by pid → the neighbour test, written after this
    run's own line with a pid that starts with this one's.
- `bun test packages/grok`: 139 pass, 0 fail. `bun scripts/check.mjs
  grok` passed. Both ran on WSL (magpie-desktop) with a temp HOME.
- `bun scripts/bumped.mjs origin/main` passed on HQ.

Not tried:
- a real xAI account;
- grok 1.0.92/1.0.97's log lines (1.0.67 only);
- whether xAI rotates the refresh token on an exchange the CLI dropped;
- these tests on macOS or Windows.
yetone and others added 28 commits December 4, 2026 22:26
… project access token, as ZCode 4.0 does

Eliot on Discord: the sign-in failed with "BigModel API key: 请求地址不允许访问
(403, code 403)", no VPN on, magpie's proxy left on Global.

Which request: the message is projectKey's, from call()'s envelope (msg,
HTTP status, code). getCustomerInfo and the key list had already answered
on the same host and network a moment before, so it is the create or the
copy (GET …/api_keys/copy/<id>) that BigModel refuses, not the address or
the region; the body is BigModel's own JSON, not an edge page.

Why: ZCode stopped reading a key's secret in 4.0. zai-org/ZCode main a4b44451
docs/model-provider-project-access-token.md ("删除 Copy Secret") and
packages/shared/src/project-access-token-client.ts: it makes its key for
the coding plan (usageScene 1, API_KEY_USAGE_SCENE.CODING_PLAN), never
calls copy, and asks POST …/api_keys/<id>/access_tokens with
Authorization: Bearer <login token> and {clientType: "zcode",
clientVersion}, getting {enable, accessToken, expiresIn, expiresAt}; it
renews two minutes before the end and reads subscription/list with that
token bare. The plugin still copied the secret and made keys with no
usageScene.

What changes:
- a key made is made with usageScene 1, personal and team;
- a copy answering 403 is CopyRefused; the sign-in keeps the key's
  location (loc: origin, org, project, apiKeyId, pat) and the login
  token, key "", and never saves a token;
- located() asks the key's project token for such a location (or one
  whose copy was refused at runtime, the ZCode app's own location
  included), keeps it until two minutes before it ends, and while a
  renewal can't reach the site serves the old one to its end; enable
  false is said; a 404 leaves the sign-in keyless as before;
- a team seat (teamSignIn, teamKey) takes the same path, and serve and
  usage save its location, not the token;
- a key whose secret is still copied goes as before.

Run at 1b3606f + this change, on mote (HOME=$(mktemp -d), bun 1.4.2):
- bun test packages/zcode: 311 pass, 0 fail (new pat.test.mjs, 6 tests:
  sign-in, request + renewal with setSystemTime, usageScene on create,
  team seat, enable false, the ZCode app's location; usage.test.mjs's
  create body now carries usageScene 1).
- bun scripts/check.mjs zcode: ok.
- Broken by hand (CopyRefused, the located 403 branch and usageScene
  taken out): pat.test.mjs 0 pass, 6 fail; the ZCode app case fails with
  the reporter's words, "请求地址不允许访问 (403, code 403)".
Not tried: a real BigModel or Z.ai account (none was used, and nothing
was sent to Zhipu's servers); whether Z.ai's copy is refused the same way
is not known, and its key path is unchanged unless its copy answers 403.
…naming the host and the proxy

Bjing (Discord, 2026-12-04, Windows, 全局代理): the WorkBuddy page said
登录成功 while magpie stayed on "Sign in to WorkBuddy in the browser; this
finishes by itself". The account's usage read failed the same way
("context deadline exceeded"): requests to copilot.tencent.com through that
proxy weren't being answered.

The poll now asks each check within 15s (SIGN_IN.ask), bounded by a timer
as well as the fetch's signal, so a fetch that ignores its signal can't
hold it. A check with no answer is asked again; 3 in a row end the sign-in
with "WorkBuddy (copilot.tencent.com) didn't answer 3 times in a row: … A
proxy, VPN or firewall between magpie and copilot.tencent.com is holding
the request: pick another proxy for this subscription, or none, and sign
in again." The state request says the same when it gets no answer. The
callback takes magpie's signal (callback(code, {signal})), so a sign-in
magpie gave up on stops asking. The 5-minute deadline says "didn't confirm
the sign-in within 5 minutes; sign in again". WorkBuddy's own refusals are
said as before.

Run (mote, Bun 1.4.2, HOME=$(mktemp -d)): packages/workbuddy bun test, 482
pass, 0 fail, 43 files. bun scripts/check.mjs passes (HQ).
Broken by hand (HQ, Bun 1.4.5), signin-wait.test.mjs red each time:
without the timer race the fetch that ignores its signal never ends the
check (1 fail); without the signal passed the cancelled sign-in keeps
asking to its 5s deadline (1 fail); throwing on the first no-answer fails
3 tests.
Fake proxy (HQ, Bun 1.4.5, a fake WorkBuddy on http behind a fake HTTP
proxy that blackholes after the state request): 0.2.52 fails at 30s with
"The operation timed out."; 0.2.53 fails at 47s with the message above.
The proxy answering every request 5s late still signs in (33s); a working
one signs in in 3s.
Not tried: Windows (xiaomi-gpu's sshd refused connections all afternoon,
MaxStartups), real accounts or WorkBuddy's servers, a real proxy.
…o, and what to try

Bjing (Discord, 2026-12-04) set the proxy to direct and WorkBuddy's sign-in
still waited on "this finishes by itself" after the page said 登录成功, so
the proxy isn't the whole story. A sign-in that reaches its 5 minutes with
WorkBuddy answering every check 11217 ("not yet") now says that: its page
never finished this sign-in, and a page that said signed in without asking
may not have been this sign-in's, so sign out on www.workbuddy.cn (the
page's own host) or use a private window. One whose checks got no answer
still says 0.2.53's no-answer message; one past the token whose account
WorkBuddy never named says it timed out as before.

Run (mote, Bun 1.4.2, HOME=$(mktemp -d)): packages/workbuddy bun test, 483
pass, 0 fail, 43 files. bun scripts/check.mjs passes (HQ).
Broken by hand (HQ, Bun 1.4.5): without the "not yet" count the deadline
test says "didn't confirm" and fails.
Not tried: whether WorkBuddy's page binds the sign-in's state when the
browser is signed in already (no real accounts or WorkBuddy servers),
Windows (xiaomi-gpu's sshd refusing connections).
… with read_file of the session's saved tool output (magpie-community#1992)

agy has no tool that reads a page, so a model answering a client's web
search with agy's own search_web could only search again for what a page
says. "Web fetch in native search" (native_web_fetch, off by default,
AGY_BRIDGE_NATIVE_WEB_FETCH) gives such a session magpie's web_fetch
(/mcp/magpie/web-search):
- a client that offered only its search gets the tool for its model and
  none of its blocks or counts; a client's own hosted web_fetch is run as
  declared, blocks and count sent; with the option off it is passed over;
- bounds: 10 URLs a call, 4 in flight and 20 uses a turn unless the
  client's tool names max_uses, raised only by AGY_BRIDGE_NATIVE_FETCH_*;
  the turn's uses and in-flight slots are shared by the calls agy runs at
  once in one step (each URL reserves from the turn's live count;
  fetchSlots on the turn);
- tool-gate.mjs lets read_file / view_file open this session's saved step
  output.txt and nothing else, so a spilled result can be read whole.
The batched search (hosted_search) is untouched.

Reviewed at 1425d03 (aabbccgg, magpie-community#1992),
after rounds at 0c09a99 and b3d8280. magpie-community#2004 (searchCalls cleanup) landed
first as 0.1.209; this head is rebased on 1b3606f.

Run at this head:
- mote (macOS, bun 1.4.2, HOME=$(mktemp -d)): root `bun test`; every
  agy-cli file passes, native-search.mjs (20 tests, bounds plus magpie-community#2004's
  two), hosted-search.mjs, default-agent.mjs and idle-reuse.mjs among
  them. The run's 174 reds are all in packages this PR doesn't touch
  (window-warmup, sap-aicore, page-*, fingerprint, ...), at load 40-60.
  `bun scripts/check.mjs agy-cli`: ok.
- CI pr.yml run 47352841082: test and on-npm green.
- Broken by hand on mote, each turning "native web_fetch is bounded" red:
  usesLeft read from the call-start count (live = false): "the turn's 20
  across the five calls" fails; slots: undefined (a pool per call): "at
  most 4 in flight across the five calls, saw 20".
- The gate test with the old mkdtemp line (no realpathSync) fails on
  macOS (decision deny for the real-path read), passes with the fix.
- tool-gate.mjs is byte for byte the file read at 0c09a99 and b3d8280.
Not tried: a real agy or magpie here; Windows.
…answers it

Since 0.1.29 a request whose agy stopped at a prompt of its own ended in
502, so an outer agent's chat broke there. The PreToolUse hook still
turns down every call of agy's own tools, ask_question included, so the
usual path is unchanged; these prompts show only when the hook gives no
decision in time and no permission rule covers the call.

- ask_question: the turn ends with the model's text, then the question
  and its options, numbered (several questions as numbered blocks). The
  agy is kept as a spare even with spares off, and the next message in
  the conversation answers it by keys: an option by its number or its
  words, anything else through Write-in; numbered lines answer several.
  When that agy is gone (idle 15 minutes, another model or tools), the
  answer goes into the conversation as a message; agy 1.5.23 gives the
  model "Tool execution was canceled", 1.5.24 nothing.
- An approval of one of agy's own tools is declined, never approved, and
  the reply says what agy asked. The chat goes on in the same
  conversation. A client saying yes on the user's behalf is not the
  user's consent, and nothing runs outside the hook and the rules.
- Folder trust at agy's start (kept away by trustedWorkspaces): the reply
  asks it and holds the message; a plain "yes" trusts the turn's own new
  folder and sends it, anything else sends nothing. agy leaves the
  answered dialog drawn above its screen, so question and trust are told
  from the screen's last lines only.
- Any other choice is still a 502 that shows what agy asked.
- README (zh, en) says each case. The fake tui-helper draws the question
  and trust dialogs and takes their keys.

Run, at this tree on origin/main c02db2a:
- Real agy on mote (macOS) with tui-helper from magpie main, a fake
  Gemini on loopback, GEMINI_API_KEY=fake-key, dead proxies, a temp HOME
  and no account. The new tests use their own account home; wrappers put
  a silent hook in place (so agy draws its own prompts) and, for trust,
  strip trustedWorkspaces:
  - agy 1.5.24, packages/agy-tui whole: 149 pass, 0 fail.
  - agy 1.5.23, packages/agy-tui whole: 149 pass, 0 fail.
  The real trust test was 8 of 8 green after the last-lines fix.
- bun scripts/check.mjs ok; bun scripts/bumped.mjs origin/main ok (HQ).
- Root suite (HOME=$(mktemp -d) bun test): not run here. mote and mica
  were at load 250 and 170 with suites queued on their locks, and
  xiaomi-gpu refused SSH. publish.yml runs it on ubuntu before it
  publishes.

Broken by hand on mote, each red under the new tests: decline picking
Yes (approval test), the answer's waits not marked as answering and the
spare not kept when spares are off (both question tests), the trust
wait not marked (trust yes), question and trust told from the whole
screen (the prompt-kind unit test), answers not split by numbered lines
(unit and two-question test), an option not matched by its words (unit),
a loose yes (unit and trust-no test), a plain decline notice (unit and
approval test).

Not tried: Windows; a real Google account; an image sent with an
answer; agy's other choice dialogs on real agy.

Rebased on a5af28e (agy-cli files only) after the run; this package
is unchanged by it.
A request that carries tool calls or tool results in its messages but
declares no tools takes the tool path for its history alone. There every
delta went out live, since no call was wanted, and at the end the held
text went out again whole, because nothing had marked the reply as
streamed: the agent got the answer twice ("Hello thereHello there").
The end now sends the held text only when tools were wanted, where the
deltas were held.

Found while reworking the tool path for aaron0x10's report (tool calls
returned as text, the next commit).

Run: bun test packages/catpaw on HQ (98 pass); the new test is red on
origin/main's 0.2.7 index.mjs ("Hello thereHello there") and green after.
bun scripts/check.mjs catpaw, bun scripts/bumped.mjs origin/main: ok.
Root bun test with HOME=$(mktemp -d) on mote at this tree (bun 1.4.2,
load 90 to 200 on 18 cores): 11049 pass, 41 skip, 174 fail. Only the
stderr tail was kept, so the reds are not all named; the ones shown were
5s timeouts in other packages' stream-deadline tests. The full suite at
the pushed head runs in publish.yml before dist (next commit's record).
Not tried: a real CatPaw account (no probes on real accounts).
…t as text

aaron0x10 (on X, 0.2.7): Codex and other agents stop for no reason, because
the plugin hands their tool calls back as plain text. Codex runs nothing
and the turn ends.

Cause. 0.2.7's diff from 0.2.6 is usage only, so this is not a regression
in that release. CatPaw has no tools field: the plugin writes the tools
into the prompt, asks for {"tool_calls":[…]} alone, and reads the reply
back. Only a reply that WAS that JSON (or one fenced block) was read as a
call. A model that first says what it is about to do ("I'll list the
files.\n{"tool_calls":…}" or a ```json fence after prose) had its call
sent to the agent as text, with finish_reason stop. In a stream the prose
went out live and nothing after it was ever looked at. Two things made
that likelier: past calls were shown to the model as
"Tool call requested: shell {…}", a line no parser reads, which the model
copies; and a call naming its tool exactly but missing a required argument
was dropped, so its JSON went out as the answer.

Fix, for buffered and streamed replies alike:
- A call that stands on lines of its own after or among prose, a bare JSON
  object or a ``` / ```json fence, is a call. Several are all taken. The
  prose stays the message's content; finish_reason is tool_calls. A call
  quoted inside a sentence is still text, and one among prose must carry
  its tool's required arguments (an example usually doesn't).
- In a stream, prose still goes out live. A line that opens a fence or an
  object is held until it closes: a call is taken out, anything else goes
  out as it was, and one never closed goes out at the end.
- Past calls are shown in the instructed shape,
  {"tool_calls":[{"name":…,"arguments":{…}}]}.
- A call naming its tool exactly goes to the agent even missing a required
  argument; the agent answers that as the call's result. A name that only
  drifted to a tool by prefix is still dropped then.
- A string where arguments belong goes into the tool's one property, so
  Codex's apply_patch ({input: string}) gets {input: patch}, not {value}.
- Call ids are random per call (two payloads in one reply could share one).
- The held object's brace scan resumes where the last delta left it: a
  240KB apply_patch held after prose took 2.3s of rescans at 20 characters
  a delta, 30ms now.

Fixtures: the reporter posted no bytes. The replies are the plugin's own
instructed format with prose before it, in the cumulative text frames of
testdata/captured-turn.json; the tools are Codex's shell and apply_patch
as magpie's Responses translation offers them (customSchema in magpie's
internal/gateway/responses.go).

Run:
- bun test packages/catpaw on HQ: 116 pass. 13 of the new or changed tests
  are red on origin/main's 0.2.7 index.mjs (12 here, 1 in the commit
  before) and green after.
- Broken by hand, each red: stream scanner off (5 red), history in the old
  shape (1), string arg as {value} (1), calls among prose not held to
  required args (1), exact-name rule off (1), buffered among-prose off
  (4), one id for every call (1), the brace scan resuming past an escape's
  backslash (the every-character cut test, 1).
- bun scripts/check.mjs catpaw, bun scripts/bumped.mjs origin/main: ok.
- bun test scripts packages/catpaw with a scratch HOME on HQ, after
  rebasing onto 045d268 (agy-cli and agy-tui only): 176 pass, 1 fail. The red is check.test.mjs's undeclared-port
  test reading packages through URL.pathname in a path with a space
  (scripts/ unchanged from origin/main), filed as plugins#2016.
- The whole root bun test was not run locally at this tree: xiaomi-gpu's
  ssh kept resetting, and mote and mica were at load 260. publish.yml
  runs it (HOME=$(mktemp -d) bun test, ubuntu) before it packs dist.

Not tried: a real CatPaw account or a real Codex session through magpie
(no probes on real accounts). Lines in the old "Tool call requested:"
form are not read as calls; once a conversation's history is rendered in
the new shape the model no longer sees that form.
…agpie-community#2018)

Removes agy-cli's batched web search (`hosted_search` option, `AGY_BRIDGE_HOSTED_SEARCH`,
`AGY_BRIDGE_SEARCH_DEFAULT_MAX_USES`, `AGY_BRIDGE_SEARCH_TIMEOUT_MS`) as its own change,
as asked on magpie-community#1992. A hosted web_search is now always agy's own search_web's to answer.
web_fetch keeps its limits. Users who never turned the switch on see no change (the
catalog was already built with it off). Users who did now get native search; the
READMEs (en, zh) say so.

Reviewed at 617a58c: read every line. No code in the repo or in magpie core refers to
the removed exports or option.
Ran on mote (macOS arm64, bun 1.4.2, fresh HOME): `bun test packages/agy-cli`
94 pass, 0 fail; `bun scripts/check.mjs agy-cli` passes. CI root `bun test` is green
on attempt 1 at this head. Main moved only in catpaw since the base, and the merge is clean.
Not tried: real agy.

npm publish of agy-cli (never published) waits for the owner; magpie installs it
from dist meanwhile.
… read runs at a time (tmr11235 on X)

0.1.207 (58e721c) put a folder where agy keeps
antigravity-cli/jetbox_summaries_proto.pb, so that a new agy would not
resume a conversation another agy left waiting for a tool result
(liuyuexue2020). But that file is also agy's cache of every
conversation's summary. With the folder in its place each new agy logs
"failed to read new format summaries file: ... is a directory",
"reconcile checked N, restored N, cached 0", then opens every
conversation's store again, and its writes of the file fail ("atomic
rename"). tmr11235 has 4,162 conversations (6.35 GB): each agy started
spent 367-414s at ~1550% CPU and ~1 GB/s of reads, so 3 or 4
concurrent requests on 0.1.210 and 0.1.211 filled a 4-core server.
`agy usage` and `agy -p /usage` start the same backend (its log:
"Creating CLI server backend", then the reconcile), so every usage
read did the same for as long as it ran, and a usage refresh runs one
per account: tmr11235's screenshot shows seven `agy usage --output-format
json` at once, ~400 MB each, one at 170% CPU.

Now the file stays. Before an agy's first session the bridge takes out
of it only the conversations agy would resume: status running,
canceling or busy, not_fully_idle, background tasks or running
subagents (SummariesState and CascadeTrajectorySummary fields read from
agy 1.5.24's embedded descriptors). The rest of the bytes, unknown
fields included, are written back as they were, through a temp file and
a rename, and only when something was taken out. A file that doesn't
parse is left alone. The folder 0.1.207 to 0.1.213 left is removed on
upgrade (geminiDirArgs, an lstat per request), and agy writes the file
again after its first read. The filter runs once per agy started, never
per request: in Proc's first session (so a spare taken later reads it
then), the models and search probes, one-shot sessions (images, agent
summaries) and usage reads, including an account home's .gemini when
the app's gateway is off. ~/.gemini and agy-own (gateway-free) are left
alone, as before: their running conversations are the user's.

Usage reads now run one at a time in the plugin's process, across every
account's reader (usage.mjs oneAtATime). Each reader already shared its
read with calls that came while it ran; the accounts didn't. A read's
deadline starts when it runs, and a caller that stops waiting (17s) is
answered by the next refresh, as any slow read is.

Real agy 1.5.24, sandbox HOME, fake API key, loopback only (HQ):
- 400 conversations (copies of a real conversation store, 175 MB):
  first start "restored 400, cached 0" (5.1s, sys 4.5s), second start
  "restored 0, cached 400" in 2ms (sys 0.08s).
- With the 0.1.207 folder: both starts "restored 400, cached 0" and
  four "is a directory"/"atomic rename" errors each. After
  quietSummaries: the folder is gone, the next start restores 400 once
  and writes the file, the one after reads "cached 400" in 2ms.
- liuyuexue2020's case again (the 0.1.207 harness, A waiting for a tool
  result while B starts a new agy, RESUMECALL=1): the file at B's start
  listed A with status 2 and not_fully_idle; B's agy sent nothing of
  A's (no "background tasks have been stopped" request before part 2).
  The same harness with neither the folder nor the filter sent it at
  B's start (req-003).
- The filter on two real summaries files with nothing running leaves
  them as they are.
- agy writes the file as it goes: with the file removed, two starts
  stopped after 0.8s each left it at 114 KB then 194 KB, and the third
  start read "restored 136, cached 264". So a usage read cut short
  carries the rebuild on instead of starting it again.
- `agy usage --output-format json` (signed out, so it ends in 0.2s) on
  the 400: "Creating CLI server backend" and the reconcile ("cached
  400", 2ms) with the file; with the folder, "failed to read new format
  summaries file: ... is a directory" at the same point.

Tests (mote, temp HOME, at this tree, on 22fe13b):
- bun test --timeout 300000 packages/agy-cli: 94 pass, 0 fail (560s)
- bun scripts/check.mjs agy-cli: ok
- test/restart-resume.mjs rewritten (6 tests). Broken by hand on mote:
  quietSummaries a no-op: 3 red (own folder, account home, spare);
  without the call in Proc's first session: the same 3 red; without
  the folder removal: the folder test red.
- test/usage.mjs: a usage read quiets its folder before its agy runs;
  three accounts' readers asked at once (one twice) run three agy, none
  while another reads (a busy file the fake agy holds). Broken by hand
  on mote (fetchUsage called without oneAtATime): red, busy true.

Not tried: a signed-in `agy usage` (no real accounts in tests; signed
out it ends before the reconcile gets far), a real account, a real
history of thousands of conversations, Linux or Docker (the reporter
runs magpie web in a container), agy versions other than 1.5.24. After
the upgrade agy still reads every conversation once more, spread over
the agy started until the file is whole. A live agy can write the file
again between the filter and a new agy's read. agy-tui and agent-agy
never touched the file.
…opy's connection resets, as a browser does (magpie-community#2011)

The token test's fetch sends a request once more when Node's fetch fails with ECONNRESET or UND_ERR_SOCKET on the closed copy's kept-alive connection, as a browser does. No page or service code changes. Refs magpie-community#1934 (its first test only).

Reviewed at 1e7cc0c, merged onto origin/main 0b79514. Run on mote (macOS, Node v22.22.0, bun 1.4.2), HOME=$(mktemp -d):
- main's test with `node --test test/token.test.mjs`: red 10 of 10. Logged, the page's fetch failed with `ECONNRESET read ECONNRESET` after the swap.
- This test: green 30 of 30 at load ~250 on 18 cores.
- Broken by hand, each red 5 of 5: the 403 no longer calls reloadForToken (line 81), and `tokenTaken = true` removed (line 95, the second swap).
- `node --test test/*.test.mjs` in the package, root `HOME=$(mktemp -d) bun test` and `bun scripts/check.mjs`: root bun test 11255 pass, 0 fail; check.mjs ok. The package's node suite: 60 pass, 2 fail. The two reds are cross-process.test.mjs:102 and :122. Both are time bounds, red at load ~830 to ~950, and red the same way at origin/main. :122 is magpie-community#1934's second item; :102 is filed as magpie-community#2019. Both pass when the file runs alone.

`git diff --check` clean. Not run: Node 24, Windows (the test box was unreachable).
…nd (magpie-community#2012)

The stale-lock test counts the lock's Atomics.wait calls during the second chat (0 expected) instead of a 200ms bound. A stale record that is removed at once costs no wait on a loaded machine. One removed only after a wait is caught. Fixes magpie-community#1948.

Reviewed at bae9a10, merged onto origin/main 0b79514. Run on mote (macOS, bun 1.4.2), HOME=$(mktemp -d). Each break was injected into gumloop.mjs, 3 runs each:
- nothing injected: main's test and this test green 3 of 3.
- 300ms busy loop before a stale record's removal (load, no wait): main's test red 3 of 3 (301ms), this test green 3 of 3.
- isStale false for its first two calls (removed after one 5ms wait): main's test green, this test red 3 of 3 (waits 1).
- isStale false until the deadline (waits out the lock): both red (251ms; waits 37).
- `bun test` in packages/gumloop, root `HOME=$(mktemp -d) bun test` and `bun scripts/check.mjs`: packages/gumloop 91 pass, 0 fail; root bun test 11255 pass, 0 fail; check.mjs ok; `git diff --check` clean.

Not run: Windows (the test box was unreachable). On Windows, retryFs also waits in Atomics.wait on EPERM/EACCES/EBUSY.
…sation warm (magpie-community#2014)

A side request (Hermes' background_review, /btw) sends the chat with one
more message. It carried the kept conversation on first and took it off
the list, so the chat's own next turn, which comes back to the same
checkpoint, started cold: a new agy conversation, 0% cache.

agy writes the conversation's id, its brain folder and the workspace
into the model's instructions, ahead of the history, so a copy under
another id, or agy's own /fork, misses the cache too. Only the same id
in the same folders stays warm, so one branch is kept warm, the last
one to come back:

- A checkpoint carried on from is lent, not taken. Before its agy opens
  the conversation, a snapshot of it is taken (snapshot.mjs): the store
  through VACUUM INTO from a read-only connection, put back in WAL mode,
  and the brain folder, written beside and renamed into place, under
  <account>/agy-tui-snapshots/<id>.
- A request that comes back to a lent checkpoint gets the conversation
  put back as it was, under its own id and folders (store, sidecars
  removed first, then the brain folder swapped, each by rename), and the
  checkpoints that went on from it since are taken off the list. That
  branch's next turn starts a conversation of its own.
- Never put back while an agy has the conversation open or a request is
  on its way to one (a count kept from launch to the agy's close, and
  from claim to start). Spares waiting on it are dropped first; any
  other holder leaves it as it is and the request starts its own, cold,
  as before. A snapshot that can't be taken or put back never fails the
  turn: the request gets today's behaviour.
- Bounds: one snapshot a conversation; a lent checkpoint and its
  snapshot go once the chat goes on from the next one; 8 an account,
  oldest first; none for a conversation over 64 MB (real ones are
  0.4-0.75 MB). Pruned, mended or replaced entries drop their snapshot,
  and a restart sweeps snapshots no lent entry names.
- No client is detected by its prompt text.
- README (en, zh) says it.

Run:
- packages/agy-tui, the four new tests and the carried-on block, on
  mica before the rebase onto 0b79514 (the two fork tests again after
  a fix to the test's store reader), HOME a scratch dir: pass.
- The new tests against origin/main's index.mjs (c02db2a, the rest of
  the tree new), on mica: the side-request test is red at its
  --conversation check (the chat's next turn started its own), the
  rewind test and the cap test are red; the open-conversation test
  passes there (the old code never puts anything back).
- Broken by hand: both open-conversation checks in restored() removed,
  and the open-conversation test is red (the put-back conversation
  lost the side request's open turn).
- Root suite on mote at this tree on origin/main 0b79514:
  TMPDIR a scratch dir under ~/xdev/wt, HOME=$(mktemp -d) bun test:
  11077 pass, 48 skip, 174 fail across 757 files (2123s). packages/agy-tui
  all green, the four new tests in it. The 174 reds are in 16 packages
  this commit doesn't touch (window-warmup 67, mostly its scheduler's 5s
  waits, then page-harnessweight, atomcode, search1api, fingerprint,
  gcp-ai and others), at mote load 200 to 930 from other sessions: the
  pattern of magpie-community#1380. Not rerun alone (mote at 930, mica at 370,
  xiaomi-gpu refused SSH); publish.yml runs the root suite on ubuntu
  before it publishes.
- bun scripts/check.mjs and bun scripts/bumped.mjs origin/main ok (HQ).

Not tried: real agy and a real account (no network, no real-account
requests in this work), so the restore was never run against agy's own
store while it reads it; Windows; a real Hermes background_review.
Two agy processes (two magpie instances) sharing one account home are
not counted against each other: the open count is per process.

Rebased on ae9d7f2 after the run; packages/agy-tui is unchanged by it.
…gpie-community#2020)

Lists hub-qwenwork-intl (QwenWork Intl) under magpie-providers-hub; the summary now counts 14 providers. Needs npm 0.13.15.

Review at 9549564: only registry.json changes. registry.npmjs.org has magpie-providers-hub 0.13.15 (shasum 61961810b7...). The package ships src/qwenwork-intl.mjs and src/qwenwork-intl-cosy.mjs. They call only qwenwork.ai / gateway.qwenwork.ai, and the login status page listens on 127.0.0.1 only. QwenWork is the vendor's own subscription, not a relay.
CI at this head: test, bumped and on-npm all passed.
Not tried: a real QwenWork Intl sign-in. The package README itself says sign-in and refresh are verified only against mocks.
Every pr.yml run since 2026-12-05 00:42Z failed 16 checks in
packages/opendesign/reset.test.mjs (first: reset.test.mjs:221, 1 !== 2).
The fixture's soonest card, c2, expired at the fixed 2026-12-05T00:00:00Z.
cardsOf drops a card whose expiry is past by the real clock, which is
right for a real account, so at midnight UTC the list held one card, not
two, and every check of the count, the button and the spend went red. The
second card (2026-12-17) and the 100-card confirm check (2027-01-01..28)
were the same bomb on a later date. Shipped code is unchanged, so no
version bump.

Card expiries in the fixtures are now built from the clock: SOON = now +
12 days, LATER = now + 24 days, and the 100 cards now + 1..28 days, so
both bounds have days of room on each side. The confirm's date is
checked against SOON's UTC day, which is what the plugin prints. The
pure cardToSpend check keeps its fixed dates: it reads no clock.

Run on mote (bun 1.4.2; WSL on xiaomi-gpu still fails to mount its
disk, ERROR_SHARING_VIOLATION), at real now 2026-12-05 ~01:54Z, with a
preload that moves Date to FAKE_NOW and lets it tick:
- old reset.test.mjs at 2026-12-04T23:40Z: 60 pass 0 fail
- old reset.test.mjs at 2026-12-05T00:42Z: 44 pass 16 fail
  (the same 16 as CI); at the real clock: 44 pass 16 fail
- new reset.test.mjs at 12-04 23:40Z, 12-05 00:42Z and the real
  clock: 60 pass 0 fail each
- HOME=$(mktemp -d) bun test packages/opendesign, TZ=UTC and
  TZ=Asia/Shanghai: 173 pass 0 fail each
- HOME=$(mktemp -d) bun test at the root, as pr.yml runs it: 11259
  pass 0 fail, 11307 tests across 757 files, exit 0 (mote, after a
  first try there was cut off when mote rebooted)
- on Windows (xiaomi-gpu, bun 1.4.2, HOME and USERPROFILE fresh):
  bun test packages/opendesign 167 pass 0 fail (6 posix-only skips);
  the root run's 58 reds are all in other packages (agy-tui, registry
  file modes and others), none in opendesign, and were not looked into

Not tried: a clean run with the clock weeks ahead. Shifting Date forward
leaves file mtimes on the real clock, so three lock checks (a live lock
goes stale after 135s by mtime) fail at any forward shift, real + 1 hour
included, with no card date crossed; at 2026-12-17T01:00Z and
2027-02-01Z only those three failed. Fake timers in the test itself
were not used.
…ne, not the one with every conversation (tmr11235 on X)

tmr11235 on X, after 0.1.214: on a four-core Docker server with one
account and only one or two Gemini requests, htop still showed
`agy usage --output-format json` at up to 104.8% CPU (nine lines, the
threads of one agy), with magpie web busy beside it.

Cause: magpie reads the quota of the account agy is on every ten
minutes (and on each refresh). Each read starts agy's whole backend on
the folder of the user's conversations, and on every start, signed in,
that backend goes through all of them ("[Summaries] reconcile checked
N"), with the summaries cache whole or not. tmr11235 has 4,162
conversations (6.35 GB). The quota needs none of them.

Fix: usageOnlyDir (gateway-free.mjs) keeps a folder for the quota read
alone, one per folder agy would read (under
$XDG_STATE_HOME/magpie-agy-bridge/usage/<hash>): agy's config folder and
antigravity-cli's antigravity-oauth-token, settings.json,
installation_id and jetski_state.pbtxt linked from it, and no
conversation. On agy with `agy usage` (1.5.22+) the read runs as
`agy --gemini_dir <that folder> usage --output-format json`: the flag
before the subcommand, which agy's top level takes (plugins#1935
checked that 1.5.22/1.5.23 parse it; 1.5.24 reads with it, below).
- The token is linked, never copied or written. A file agy put in a
  link's place is linked again on the next read; an entry gone from
  the source goes here too (signed out there, signed out here).
- A read that may renew the sign-in reads where agy would, as before:
  the reader passes renewDue when the stored access token ends within
  USAGE_DIR_RENEW_MS (15 minutes), its end isn't known, or the sign-in
  can't be read (macOS keychain and Windows Credential Manager states
  included), so a renewed token lands in agy's own folder.
- A read on the usage folder that isn't a quota (an agy that refuses
  the flag, a sign-in agy finds only in its own folder) is read again
  where agy would, so neither "sign-in no longer works" nor an error is
  ever said for the folder alone. A read out of time isn't run twice.
- No folder (it can't be made, a link can't be made, e.g. Windows
  without the symlink privilege) or agy before 1.5.22: as before.
- With the Antigravity app's gateway on, the usage folder stands for
  the gateway-free one, so that case reads with `agy usage` too.
The comment that said `agy usage` doesn't take --gemini_dir now says
which position it takes.

Measured (HQ, macOS, agy 1.5.24, sandbox HOME with 1,819 conversations
(1 GB), a fake token by file sign-in (SSH_CONNECTION), Google's
endpoints pointed at a loopback fake, the proxy at a dead port):
- this commit's fetchUsage on the real agy, /usr/bin/time -l of the
  whole node process: user's folder 1.20 user / 3.93 sys and 1.22 /
  3.34; usage folder 0.28 / 0.14 and 0.27 / 0.11. Same quota both ways
  (7 days 40.5, 5 hours 0.9), the fake saw the linked token's Bearer,
  and the usage folder has no conversation.
- agy alone, earlier: 1.0-2.0s user and 2.5-4.8s sys on the user's
  folder with agy's summaries cache whole, 0.13-0.26 / 0.06-0.12 on the
  usage folder.

Tests (mote, HOME=$(mktemp -d), Bun 1.4.2):
- `bun test` in packages/agy-cli: 94 pass, 0 fail (471s).
- test/usage.mjs alone: 81 pass, 0 fail. New: the read runs with
  --gemini_dir <usage folder> before `usage`, for agy's own folder and
  the gateway-free one; a failed usage-folder read is read again as
  before; no folder, a throwing builder, renewDue and agy 1.5.21 read as
  before; the reader passes renewDue at 10 minutes left, an unknown end
  and an unknown sign-in, not at 60 minutes; usageOnlyDir's links, no
  conversation, relinking over agy's file, removal when the source is
  gone, and null when it can't be made.
- Broken by hand (each on a copy, test/usage.mjs on mote):
  the usage folder never used: 3 red (the folder read, the read
  again, the reader's renewDue); no read again after a failed folder
  read: that test red; the reader never passing renewDue: its test
  red; fetchUsage ignoring renewDue: 2 red. Restored, 81 pass.

Not tried: a real Google account, Linux or Docker (WSL's magpie-desktop
was down: vhdx sharing violation), Windows, the reporter's own folder,
and agy renewing a token through the link (the reader keeps such reads
on agy's folder instead).
…try or a new sign-in (magpie-community#2009)

gcp-ai's credits card stops re-opening Chrome while the Console session is
expired (magpie-community#1905). With a host that shows card actions (magpie.cardActions),
a CONSOLE_SIGN_IN_REQUIRED failure is held until the user presses the
card's "Retry credits" or a successful row sign-in records
creditsSignedInAt, so a hold older than that sign-in is let go. Hosts
without card actions keep main's 20-minute failure TTL. Chrome start-up
and network failures back off from 15 minutes, doubling up to 4 hours,
and reset after a success. safeGoto accepts a navigation replaced by a
redirect, and the Console sign-in check is split out of
assertConsoleSession. gcp-ai 0.2.7.

Reviewed head 434ec11 (int8259). It
addresses the change requested on fd77166: a row sign-in with
creditsSession "ready" releases the held failure.

What was run on mote (macOS, bun 1.4.2, node 22.22.0, fresh HOME):
- At 434ec11: bun test packages/gcp-ai/test 107 pass, 15 skip, 0 fail.
  node --test test/*.test.mjs 107 pass, 0 fail.
- Merged onto main a381504: bun the same, and
  `bun scripts/check.mjs gcp-ai` ok.
- The two new tests ("a successful row sign-in lets the next usage read
  try Chrome again" and "a new Console sign-in releases the old failure
  and a later expiration pauses again"):
  - copied onto fd77166: both red;
  - at 434ec11 with the `checkedAt < settings.creditsSignedInAt` line
    removed by hand: both red.
- Root suite: PR CI ran it on ubuntu at merge ref a28e241 (main
  76fe450 plus this head): 11269 pass, 16 fail. All 16 are opendesign
  reset-card tests whose fixture expired on 2026-12-05. main's only
  commit since, a381504, touches nothing but
  packages/opendesign/reset.test.mjs and fixes them. On the merged tree,
  `bun test packages/opendesign packages/gcp-ai` gave 280 pass, 0 fail.
  The full root suite was not run again on mote, where about 15 suites
  were queued behind suite.lock.
- node's parallel runner turned up a lock.test/want.test red under load.
  It shows on main too and isn't from this change: magpie-community#2028, magpie-community#2029.

Not tried: no real Google account or Chrome profile. The review did not
allow real-account probes, so the Console expiry is exercised only
through the tests' fakes.
…a later clock read (magpie-community#2028)

lock.test's "releasing twice frees the lock once, and the gap counts from
the release" took `before = Date.now()` after `await held()` returned and
asserted `Date.now() - before >= 250` around `apart(file, 300)`. release()
writes `.since` and then removes the lock, and apart waits until
`.since + 300`, so every millisecond between the `.since` write and
`before` came off the measured wait: past 50ms of scheduling delay the
test was red while apart did what it should. It now reads `.since`,
checks it lies between the moment before held() and the moment after,
and asserts `Date.now() >= since + 300 - 2` (2ms for a timer that fires
before Date.now() says it is due). Test only; lock.mjs is unchanged, and
the reproduction showed no bug in it. No version bump: tests aren't
packed (scripts/bumped.mjs origin/main passes).

Run on mica (macOS, node 22.22.0, bun 1.4.2, load 250 to 350 on 12
cores from other sessions' suites), TMPDIR and HOME in a scratch dir,
against a copy of gcp-ai with env-guarded injections in lib/lock.mjs.
Main's test (old) and this one (new), the one test by name:
- nothing injected: old green 5 of 5, new green 5 of 5, node and bun.
- 100ms sleep in release() after the `.since` write (a scheduler delay
  between the record and held() returning): old red 5 of 5 under node
  and bun (`assert.ok(Date.now() - before >= 250)`), new green 5 of 5
  under node and bun.
- `.since` never written (broken by hand): old red 3 of 3, new red 3 of
  3 (ENOENT on .since), node and bun.
- With the next commit's changes: the package's own `node --expose-gc
  --test test/*.test.mjs` 3 runs, each 122 tests, 107 pass, 0 fail (15
  skipped); lock.test.mjs alone 20 of 20 green; `bun test
  packages/gcp-ai scripts` 168 pass, 0 fail; `bun scripts/check.mjs` ok.
- Linux (WSL2 magpie-desktop on xiaomi-gpu, node 22.23.4, bun 1.4.2):
  lock and want tests 10 of 10 green under node, 7 pass under bun; the
  package's node suite 108 pass, 0 fail.

Not tried: the root `bun test` (another session's suites had mica at
load ~300; CI runs it on this push), Windows for gcp-ai. The test still
doesn't tell an apart that counts 300ms from its own call (which waits
longer) from one that counts from the release; main's didn't either.
…or 200ms (magpie-community#2029)

want.test's "a waiter is visible to the holder, and taking the lock
clears it" slept a fixed 200ms for the second take() to write `.want`,
then asserted `wanted(file) > takenAt`. On a busy machine the waiter's
first write lands after those 200ms. It now polls for
`wanted(file) > takenAt` (test/until.mjs, up to 4s, under bun test's
5s for a whole test) and fails at once if the waiter has given up. The
waiter writes the mark on every poll, so a file time coarser than
Date.now() is passed too.

Sibling, same file pattern: lock.test's "a lock held by another process
is waited for, then taken" slept 150ms and asserted the waiter hadn't
taken the lock. That could not go red under load, only pass without
the waiter having looked at the lock yet. It now waits for the waiter's
`.want` mark (it found the lock held and waits), and fails as soon as
the waiter takes a lock still held. Test only; lock.mjs is unchanged,
and the reproduction showed no bug in it. No version bump: tests aren't
packed (scripts/bumped.mjs origin/main passes).

Run on mica (macOS, node 22.22.0, bun 1.4.2, load 250 to 350 on 12
cores from other sessions' suites), TMPDIR and HOME in a scratch dir,
against a copy of gcp-ai with env-guarded injections in lib/lock.mjs.
Main's tests (old) and these (new), each test by name, node and bun
alike:
- want, nothing injected: old green 5 of 5, new green 5 of 5.
- want, 300ms sleep before each `.want` write: old red 5 of 5 ("the
  wait is not visible to the holder"), new green 5 of 5.
- want, `.want` never written (broken by hand): old red 3 of 3, new
  red 3 of 3 ("not seen within 4000ms").
- lock "waited for", nothing injected: old and new green 5 of 5; 300ms
  before `.want`: new green 5 of 5; no `.want`: new red 3 of 3.
- lock "waited for", lock broken by hand (open "w" not "wx") with 300ms
  before a take: old green 3 of 3 (it never saw the waiter), new red 3
  of 3 ("the waiter took a lock that is still held"). With no delay
  both are red 3 of 3.
- The package's `node --expose-gc --test test/*.test.mjs` 3 runs, each
  122 tests, 107 pass, 0 fail (15 skipped); lock.test.mjs and
  want.test.mjs alone 20 of 20 green each; `bun test packages/gcp-ai
  scripts` 168 pass, 0 fail; `bun scripts/check.mjs` ok.
- Linux (WSL2 magpie-desktop on xiaomi-gpu, node 22.23.4, bun 1.4.2):
  lock and want tests 10 of 10 green under node, 7 pass under bun; the
  package's node suite 108 pass, 0 fail.

Not tried: the root `bun test` (mica was at load ~300 from other
sessions; CI runs it on this push), Windows for gcp-ai.
…h, not URL.pathname (magpie-community#2016)

check.test.mjs's "a port a package's shipped code sets but its
package.json doesn't declare fails" passed `new URL(n, own).pathname` to
sourceFiles. A pathname keeps a space as %20, so in a checkout whose
path has one readdirSync looked for `.../with%20space/...` (ENOENT), and
on Windows it starts `/C:/`, read as `\C:\...` (ENOENT). Both calls now
use fileURLToPath. No other `.pathname` in scripts/ turns a URL into a
path. The one other in the repo, ua-switcher's ui.html path (shipped
code, used only under Node), is filed as magpie-community#2046.

On Windows the test then passed in 9.3 to 9.9s in a fresh copy (it reads
every package's source, about 3,250 files; 0.11s once cached), past bun's
default 5s, so it was still red there: the test now has 60s. Test only;
no package changes, no bump.

Run (HOME and TMPDIR in a scratch dir):
- mica (macOS, bun 1.4.2), the tree copied under
  ".../plugins-reds/with space/plugins": main's check.test.mjs red
  (ENOENT scandir '.../with%20space/plugins/packages/powercontext'),
  this one green; the whole file 19 pass, 0 fail.
- xiaomi-gpu (Windows 11, bun 1.4.2, fresh HOME and USERPROFILE) via
  win-run: main's test red (ENOENT scandir '\C:\Users\yeton\runs\...
  \packages\aelios'); this one with only the fileURLToPath change red
  at bun's 5s (9.9s); three runs back to back 9.3s, 0.11s, 0.12s; with
  60s, `bun test ./scripts` 61 pass, 0 fail.
- mica: `bun test packages/gcp-ai scripts` 168 pass, 0 fail;
  `bun scripts/check.mjs` ok.

Not tried: the root `bun test` on Windows or in a path with a space
(only scripts/ was), Linux in a path with a space.
…code names, with the 429's reset (magpie-community#1416)

solarwind0 and saiswj (magpie-community#1416): when every retry of a model call fails,
agy writes "⚠ <STATUS> (code N): <Google's words>" as the reply's last
line and ends the prompt on end_turn. The bridge knew one 429 wording
("Resource has been exhausted (e.g. check quota).") and a few named
endings, so anything else went to the client as the model's text, a
200: "⚠ FAILED_PRECONDITION (code 400): User location is not supported
for the API use." behind a VPN, and saiswj's agy 1.5.22 "⚠
RESOURCE_EXHAUSTED (code 429): You have exhausted your capacity on this
model. Your quota will reset after …". No rest, no failover, and the
429's reset reached only the reader. The shape is agy's own format
string, "%s (code %d): %s" shown after "⚠ ".

Fix:
- statusEnding finds the notice by where it sits, not by its words: a
  line of its own ("⚠ ", an upper-case status, " (code ", three digits,
  "): ") with nothing but whitespace after it. heldFrom holds such a
  line back while it streams, as it does the named endings, so neither
  a whole nor a split notice reaches the client. A notice the model
  quotes mid-line, or with its own text after, is the model's reply;
  so are "⚠ NOTE: …" and a code that isn't three digits.
- endText checks it last, after the named endings, so the exact 429
  marker keeps its log-read path and the system-prompt-turned-away
  answer.
- #statusError maps the code: 429 (or a quota status) goes through
  #formatAgentError as agy's 429 ending does; 401 authError; 403 agy's
  refusal if it names one, else permission_error; 404 not_found_error;
  413 request_too_large; 503/529 overloaded_error; other 4xx
  invalid_request_error; other 5xx api_error. The error carries the
  code as its HTTP status. The region refusal says to turn off a VPN or
  proxy that puts you in another region.
- A rate limit that names its reset carries it: resetSeconds reads
  "reset after" as well as "Resets in", days, and fractional seconds
  (rounded up). streamErrorOf passes it as resets_in_seconds (magpie's
  resetsIn), and a non-stream reply gets Retry-After too.
- Siblings: the same reset now goes with agy's "Individual quota
  reached … Resets in" ending, with #formatAgentError's quota errors
  read from agy's log, and with the safety pre-check fallback, which
  said "Your quota will reset after …" only in its message. Two
  existing tests in repeat-batch.mjs now expect resets_in_seconds (the
  quota-ending deepEqual, and the pre-check table test, which also
  checks Retry-After).

Tests (WSL2 magpie-desktop on xiaomi-gpu, Ubuntu 24.04, Bun 1.4.2,
TMPDIR=<run>/.scratch, HOME=$(mktemp -d) inside it; mote and mica were
at load 425 and 510):
- test/status-ending.mjs (new, in agy-cli.test.mjs's list), from the
  reporters' literal lines: 8 pass. Against the old index.mjs
  (AGY_BRIDGE_TEST_INDEX): 7 fail, 1 pass; the one that passes is the
  guard that quoted notices stay text, which the old code never broke.
- `bun test packages/agy-cli`: 95 pass, 0 fail (4 files, 382s).
- root `bun test`: 11273 pass, 47 skip, 0 fail (11320 tests, 758
  files, 1138s).

These ran at base 8e5088b. Rebased onto beb0959, whose three commits
change only gcp-ai tests and scripts/check.test.mjs; that file, run at
the pushed tree: 19 pass, 0 fail.

Broken by hand: the old index.mjs run above.

Not tried: a real agy run (no account touched, no network). The 429
wording is saiswj's from agy 1.5.22; other statuses' words are Google's
standard ones, not captured from agy.
…ce or on Windows (magpie-community#2046)

UI_HTML_PATH fell back, under Node, to new URL(import.meta.url).pathname
with a regex for the Windows drive. A pathname keeps a space as %20, so in
a folder like C:\Users\John Smith\... the page read
...\John%20Smith\...\ui.html, which doesn't exist, and served the
"无法加载 ui.html" stub. It is now path.dirname(fileURLToPath(import.meta.url))
under both Bun and Node, so one expression covers both.

Test: the package's packed files are copied into <tmp>/John Smith/ua-switcher,
and node and bun each import it and call _internal.page() (page is now
exported in _internal); the result must be ui.html's own bytes.

Swept the repo (packages/*, scripts/, excluding node_modules) for other
import.meta.url or file URLs turned into a path through .pathname,
including the bundled dist files: ua-switcher was the only one, so no
other package issues were filed. (scripts/check.test.mjs was fixed in magpie-community#2016.)

Run (TMPDIR a scratch dir, HOME=$(mktemp -d) inside it):
- WSL magpie-desktop on xiaomi-gpu (wsl-run, Node 22.23.4, Bun 1.4.2):
  bun test packages/ua-switcher: 7 pass 0 fail.
- Windows 11 on xiaomi-gpu (win-run, Bun 1.4.2): 7 pass 0 fail.
- Red before: origin/main's index.mjs with only `page` added to
  _internal, plus the new test: on WSL and on Windows the new test fails
  under node with ENOENT on ".../John%20Smith/ua-switcher/ui.html"; on HQ too.
- bun scripts/bumped.mjs origin/main and bun scripts/check.mjs ua-switcher: ok.
- HQ (macOS, HFS+ external drive): the new test passes; "rejects Claude
  Code impersonation ... hand-edited ua-switcher.json" fails at origin/main
  as well, 3 of 3. That is magpie-community#1918: loadCfg caches on mtime, and HFS+ keeps
  mtime to the second, so a hand-edit in the same second as the save is
  not read. Cause added to magpie-community#1918; not changed here.

Not tried: the page inside a real magpie install in a folder with a space
(the plugin host runs Bun, where import.meta.dir already worked; the bug
is the Node path). Full root `bun test` not run; only ua-switcher changed.
…ught up, not left (magpie-community#2035)

updateOwnAgy left the plugin's own agy copy alone whenever another agy was
the one in use, and pickAgy never took a copy below MIN_AGY_VERSION. A
copy that old was therefore never picked and never brought up: on a
machine whose own agy never updates itself, every handshake refused agy
for good. updateOwnAgy now skips an unused copy only when it can stand in
(pickAgy's own test, !isOutdated(installedVersion)); a copy below the
floor, or with no .version file, is brought up to the manifest's version.
Only ownPath() is written, through the existing temp-file-then-rename
install; the user's agy, AGY_PATH and AGY_CLI_DISABLE_AUTO_UPDATE are
untouched.

fcmyoo's change (4fb849f), rebased by a maintainer onto 4264907, which
took 0.1.216 (magpie-community#1416); the version is 0.1.217.

Run by the reviewer:
- mote, TMPDIR and HOME in a scratch dir: the new test against main
  beb0959's install.mjs: 12 pass, 1 fail (Expected "updated", Received
  "not used"). packages/agy-cli `bun test` at cb6ce7f (same tree as
  4fb849f): 95 pass, 0 fail; at main beb0959: 94 pass, 0 fail.
- mote, at the rebased head: 2693eed on main 4264907: packages/agy-cli
  `bun test` 96 pass, 0 fail (the new test among them); bun
  scripts/check.mjs ok; `bun test scripts` 61 pass, 0 fail.
- bun scripts/bumped.mjs origin/main at the rebased head: ok.
- xiaomi-gpu (Windows, bun 1.4.2), a harness on updateOwnAgy at
  cb6ce7f with a loopback 404 manifest server: a copy at 1.5.17 or with
  no .version, used elsewhere, goes on to the manifest (the gate opens);
  1.5.19, 1.6.0-beta.1 and an unparseable version stay "not used"; the
  copy's folder holds only agy.exe after.

Not tried: a real agy, a real machine with two `agy` names on PATH.
…orization, as cursor-agent does (magpie-community#2041)

`/auth/exchange_user_api_key` now sends only `Content-Type` and `Authorization: Bearer <key>`. Before, it reused `headersFor()` with some headers stripped, and still sent ones cursor-agent doesn't (`x-cursor-team-id` from cli-config among them; magpie-community#1953). New `exchangeHeaders(key)`; `keyToken` uses it. Bump 0.2.69 → 0.2.70. Fixes magpie-community#1953.

Checked against the official client. In cursor-agent 2026.11.17-f532c45 and 2026.11.05-86047df (`dist-package/index.js`), `loginWithApiKey` sends `(0,s.XX)({"Content-Type":"application/json",Authorization:`Bearer ${t}`,...n})`. `n` is the MDM `x-cursor-mdm-signin-policy` header, present only on a managed machine. `s.XX` adds `local-cli-mode: true` only with CURSOR_AGENT_CLI_LOCAL_MODE=true. On an ordinary machine the official client sends these two headers alone, which is what this change sends. Not changed here: Bun's default User-Agent/Accept against undici's.

Run at head c1f8622 on mote (macOS, Bun 1.4.2), `HOME=$(mktemp -d) bun test` in packages/cursor:
- 547 pass, 0 fail, plus one probe test that prints the exchange headers: {"Content-Type","Authorization"} only.
- The PR's test file on main's index.mjs (beb0959): 2 fail, both new team-id.test.mjs cases. Red on the old code.
- main beb0959: 546 pass, 0 fail, plus the probe.
- `bun scripts/bumped.mjs` at the head: every changed package has a new version.

Root suite on origin/main 491bb01 with magpie-community#2041, magpie-community#2043, magpie-community#2044 and magpie-community#2045 merged: see the last of those merges.

Sibling left alone: the browser sign-in's /auth/poll still sends x-cursor-client-version and x-cursor-client-type, which cursor-agent doesn't. Filed magpie-community#2050.
…-community#2043)

`drop_old_images: false` now holds in saccade mode too. collapseMessage, collapseInput, collapseContent and collapseGemini replaced an old image with `[fovea: prior topic not carried]` without checking `cfg.dropImages`. The slim paths already check it. page/measure.js is rebuilt from the middleware, as the suite requires. Fixes magpie-community#2037. The maintainer added the 0.2.6 → 0.2.7 bump and a CHANGELOG entry (22cffcf).

Run on mote (macOS, Bun 1.4.2), `HOME=$(mktemp -d) bun test` in packages/fovea:
- head 22cffcf: 63 pass, 0 fail (also 63/0 at the PR's own a177a6a).
- PR's fovea.test.mjs on main's middleware (beb0959): 1 fail, "saccade honours drop_old_images: false and keeps the old image". Red on the old code.
- main beb0959: 62 pass, 0 fail.
- `bun scripts/bumped.mjs` at the head: every changed package has a new version.

All four image branches of the collapse paths are covered. The slim paths at :260, :290, :317 and :525 were already right.

Root suite before these merges: origin/main 491bb01 with magpie-community#2041 (c1f8622), magpie-community#2043 (22cffcf), magpie-community#2044 (4c33155) and magpie-community#2045 (76da308) merged, on xiaomi-gpu WSL2 Linux (Bun 1.4.2): `HOME=$(mktemp -d) bun test` 11281 pass, 47 skip, 0 fail across 758 files; `bun scripts/check.mjs` ok. Main gained only agy-cli (92c293b) and cursor (magpie-community#2041) commits since, which touch none of these packages.
…fatal (magpie-community#2044)

model-map skips a key that looks like `/pattern/flags` but won't compile, instead of throwing from `rules()` and dropping every mapping. Two cases.json cases and a README line. Fixes magpie-community#2038. The maintainer added the 0.1.1 → 0.1.2 bump (4c33155).

Run on mote (macOS, Bun 1.4.2), `HOME=$(mktemp -d) bun test` in packages/model-map:
- head 4c33155: 14 pass, 0 fail (also 14/0 at the PR's own 5ac7bf5).
- PR's cases.json on main's middleware (beb0959): 2 fail, "a key that will not compile is left out, and the rest still map" and "… does not stop a valid pattern". Red on the old code.
- main beb0959: 12 pass, 0 fail.
- `bun scripts/bumped.mjs` at the head: every changed package has a new version.

This is the package's only RegExp construction. Not changed: a key with "gg" flags keeps one g after `.replace("g","")`.

Root suite before these merges: origin/main 491bb01 with magpie-community#2041 (c1f8622), magpie-community#2043 (22cffcf), magpie-community#2044 (4c33155) and magpie-community#2045 (76da308) merged, on xiaomi-gpu WSL2 Linux (Bun 1.4.2): `HOME=$(mktemp -d) bun test` 11281 pass, 47 skip, 0 fail across 758 files; `bun scripts/check.mjs` ok. Main gained only agy-cli (92c293b) and cursor (magpie-community#2041) commits since, which touch none of these packages.
…andidate (magpie-community#2045)

page-usage-tree's gateway candidates accept a bracketed IPv6 MAGPIE_ADDR (`[::1]:3425`), which the old `/^[\w.-]+:\d+$/` dropped. Fixes magpie-community#2039. The maintainer added the 0.1.5 → 0.1.6 bump (76da308).

Run on mote (macOS, Node 22.22.0), `node --test test/*.test.mjs` in packages/page-usage-tree:
- head 76da308: 76 pass, 0 fail, 1 skipped, plus my one probe test (same at the PR's own deb1e53).
- PR's test/gateway.test.mjs on main's lib (beb0959): 2 fail ("MAGPIE_ADDR=[::1]:port stays an IPv6 loopback candidate", "… accepts other bracketed IPv6 literals"). Red on the old code.
- main beb0959: 73 pass, 0 fail, 1 skipped, plus the probe.
- A probe at the head: `[::1]:3425` gives http://[::1]:3425 then 127.0.0.1. `[::]` and `0.0.0.0` give 127.0.0.1 only. `[FE80::1]:3425` is still dropped, because the regex has no `/i`.
- `bun scripts/bumped.mjs` at the head: every changed package has a new version.

Same bug in packages/chat/lib/gateway.mjs: filed magpie-community#2051.

Root suite before these merges: origin/main 491bb01 with magpie-community#2041 (c1f8622), magpie-community#2043 (22cffcf), magpie-community#2044 (4c33155) and magpie-community#2045 (76da308) merged, on xiaomi-gpu WSL2 Linux (Bun 1.4.2): `HOME=$(mktemp -d) bun test` 11281 pass, 47 skip, 0 fail across 758 files; `bun scripts/check.mjs` ok. Main gained only agy-cli (92c293b) and cursor (magpie-community#2041) commits since, which touch none of these packages.
…ce agy holds another

nowayjose2022 on X (12-05): from Claude Code through magpie, agy-cli
answered that the account was disabled, while the same Google account
answered in the web and in the Antigravity app.

agy's own account (home null) is whichever Google account agy's
keyring holds. Three things the plugin learns of an account were kept
by home alone, so once agy was signed in to another account (in the
Antigravity app or `agy` in a terminal) they were said of that one:

- the disabled hold (magpie-community#1563): a banned account's ToS 403 refused every
  request for ten minutes with no agy asked, the working account's
  too, and magpie (since v0.1.5695) rests a Google account a month on
  those words;
- the refusal `agy models` gave (#3501, eligibility, license): models()
  threw it and the catalog was never listed again until a refresh;
- the agy a conversation runs in: acquireProcLocked, the live,
  continued, idle and spare finders compared home only, so the
  account agy holds now went on in an agy started on the one before.

Each is now kept with the sign-in it was said of (storedSignIn's who,
the hash of id_token_email; its fp when either has no email). A renewed
token is the same account: the hold and the refusal stand, and the
conversation stays in its agy. sameAccount also compares the Proc's
sign-in at start, the compatible check of a conversation's own agy asks
sameAccount (reason "sign_in" in the session log), and launchKey takes
the account so a spare started on another isn't handed out.

Tests (agy's real go-keyring value, agy 1.5.10's ToS text BANNED_1510,
agy 1.5.9's #3501 listing):
- repeat-batch: agy switches from banned a@ to b@ inside the hold: a's
  renewed token stays held with nothing sent; b is asked, answers, in a
  new agy.
- repeat-batch: a conversation goes on in its agy across a renewed
  token, and in a new one once agy holds another account.
- catalog: a #3501 refusal stands across a renewed token with no
  listing; once agy holds b, b's list is asked for and served.

Broken by hand (WSL, bun 1.4.2): the old index.mjs fails all three
(b gets the 403 "Google has disabled this account's access…", the
continued request goes on in a's agy, b's models() throws a's #3501);
dropping only the hold's sign-in check fails the first; dropping only
sameAccount's sign-in check fails the first two.

Run (xiaomi-gpu WSL magpie-desktop, bun 1.4.2, HOME a temp dir):
- at this tree on 48313a2: `bun test packages/agy-cli` 96 pass, 0 fail (repeat-batch,
  catalog, signin, usage and status-ending among them)
- at the same change on beb0959 (before 0.1.216 and 0.1.217 landed):
  `bun test packages/agy-cli` 94 pass, 0 fail; root `bun test` 11061
  pass, 47 skip, 208 fail, none of them agy-cli's, while three other
  sessions' root suites ran on the same box (the reds named in the
  kept tail: window, a lock helper, gcp-ai's ADC sign-in, a scheduler
  page's server, all timeouts or fixed-port tests in packages this
  change doesn't touch; the rest of that log was cut by tail, so
  they are not named or filed here); `bun scripts/check.mjs` ok.

Not tried: a real agy switching Google accounts (whether agy acp
re-reads its keyring mid-run is not known; the new agy covers either
way), a real banned account, Windows. No request went to Google.
Accounts magpie already rested as disabled from this keep the rest
until the user presses Check again or a model answers; a real ban
can't be told apart from here.
Reset cards (yetone/magpie#1884) are read from the MiniMax Code login
session and can be spent from the card or, off by default, when the
weekly quota is exhausted. Off-peak is labeled from MiniMax's published
hours; remaining quota is still remains_percent, and Magpie 0.5x is
unverified.

Co-authored-by: Klarkxy <klarkxy@users.noreply.github.com>

klarkxy commented Dec 5, 2026

Copy link
Copy Markdown
Owner Author

Closing this PR because it targets this fork’s stale main and would show hundreds of unrelated commits. The intended review/merge PR is magpie-community#2052 (magpie-community/plugins:main ← klarkxy:cursor/minimax-reset-cards-offpeak-36bc).

@klarkxy klarkxy closed this Dec 5, 2026
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.