86 Commits
Author SHA1 Message Date
yetone 36dc4007fc zcode 0.1.68: every account takes requests, the Start Plan held to six in flight from this address
mathfournity on X: with several ZCode accounts in magpie, requests went to
two of them only. 0.1.40 declared maxAccounts 2 after 01huadalang's address
was refused with a 405 while three accounts took requests at once, so
magpie kept the first two of the list taking requests and held every other
account in reserve until one rested. A user with five gift accounts saw
two used.

What zcode.z.ai's edge firewall counts is the address's Start Plan
requests in flight (busyHold's logs: ~10 in flight against a cap of three
before the IP's 405), not how many accounts sent them. So the plugin no
longer declares maxAccounts, and holds that instead: besides each
account's three (startGate), every account's Start Plan requests share
one address lane of six, what two accounts of three each sent while the
two-account default stood. A request takes its account's slot first, then
the address's, within the one 120s wait; a wait that runs out on the
address's is answered here with a 429 that says so, nothing sent, and
lets the account's slot go. Free first counts the address lane full as
it does the account's. The coding plan, on api.z.ai, is held to none of
it. A user's own Accounts at once is kept as they set it.

Run:
- HOME=$(mktemp -d) bun test in packages/zcode on the Linux box
  (wsl-run, Bun 1.4.2): 275 pass, 0 fail.
- Broken by hand: the new tests against origin/main's index.mjs and
  package.json: 3 red (maxAccounts 2 declared; peak 12 in flight over
  four accounts where six are allowed; the address wait never runs out).
- magpie's gateway with this plugin under bun and four accounts on a fake
  Z.ai (a throwaway test, not committed, on mote): 12 requests at once
  went 3/3/3/3 to the four accounts, where 0.1.67 sent 6/6 to two and
  none to the others; 1302, 1308, 3008 and 500 on one account each went
  to the next and rested the first, as before.
- start.test's in-flight hold test parks twelve accounts' requests at
  once; it raises the address lane to twelve, since the hold's handling
  of such a run is what it tests.

Not tried: a real ZCode account; whether zcode.z.ai refuses an address
for the number of accounts as well as for requests in flight.
2026-11-17 01:24:45 +08:00
yetone a96714544e zcode 0.1.67: ZCode 3.18's enc:v2 sign-in is named as unreadable, not as signed out (#1196)
hupeak (#1196): ZCode 3.18 writes credentials.json's values as
"enc:v2:os:<…>:<…>". decrypt reads enc:v1 alone, so the jwt read as
null and the card said "this sign-in has no ZCode session: sign in
again", which signing in again can't fix: ZCode writes enc:v2 again.
The new form looks bound to the system's own key store (the "os"
part); this change doesn't try to read it.

- A ZCode app sign-in that finds values in an enc: form other than v1
  fails with "ZCode 3.18 keeps its sign-in in a new form this plugin
  can't read yet: add the account with a Z.ai or BigModel sign-in",
  instead of "ZCode isn't signed in on this computer".
- An account signed in "as ZCode" before has the same words on its
  card's gift line. A browser sign-in, or enc:v1, keeps the old words.

Run (mote, HOME=$(mktemp -d)):
- bun test packages/zcode: 272 pass, 0 fail.
- bun scripts/check.mjs zcode: ok.

Broken by hand: origin/main's index.mjs (with giftSignIn exported) and
the new test: 1 fail, the sign-in says "ZCode isn't signed in on this
computer".

Not tried: ZCode 3.18 itself (not installed here); the stored values
are the shape the reporter showed. Reading enc:v2 is not done; #1196
stays open for it.
2026-11-16 11:27:21 +08:00
yetone 87a8cf03c6 zcode 0.1.66: a gift-only account's model the gift doesn't name is not sent to be billed, and a failed plan read keeps it on the gift (bg5eau on X)
bg5eau on X (11-14): through magpie ZCode's gift quota stopped going
down while the account's pay-as-you-go balance was charged. Two routes
in the plugin let a key with no GLM Coding Plan spend money while its
free Start Plan quota sat unspent:

- A gift-only account sends every request to the Start Plan, whatever
  the model. ZCode's app offers such an account only the models its
  balance names (resolveStartPlanBalanceAvailability in 3.18.2); an
  agent left on another model (GLM-5.2 while the gift serves only
  GLM-5.3-Flash) spent none of the gift. Such a request is now answered
  400 with the models the balance names and is not sent. The balance is
  the one the model list already reads (aloneSeen, ten minutes); only a
  model it doesn't name has it read again, so a gift claimed since is
  sent, and a request whose model it names reads nothing. A balance not
  read yet, one that fails, or one naming none leaves the request as it
  was (unknown is not a refusal).
- plansOf's catch path: a plan-list read that failed sent every key
  account down the dual route, to api.z.ai / open.bigmodel.cn's
  /api/anthropic with its key, which bills a key with no plan
  pay-as-you-go. An account whose last read found no plan now stays on
  the Start Plan for the minute. A key with no earlier read still takes
  the dual route, as before.

Not known: which of the two was bg5eau's (no request log from them).
No 503 is made by the plugin (skykiahhub's 503 on X is the vendor's or
one of magpie's own, each of which says why).

Run (mote, load ~130-180, mica's disk was full; HOME=$(mktemp -d)):
bun test packages/zcode 271 pass 0 fail; bun scripts/check.mjs zcode ok.
Broken by hand: the guard off, "a gift-only account's model its balance
doesn't name is not sent" fails; the catch-path change off, "a
gift-only account stays on the Start Plan when its plan list stops
reading" fails (it sent GLM-5.2 to api.z.ai).

Not tried: a real gift-only account (the owner's has a coding plan and
no gift), a real pay-as-you-go charge, Windows and Linux.
2026-11-14 18:37:07 +08:00
yetone 1dbbc1fb48 zcode 0.1.65: a -Trial pick with no gift names the weekend plan ZCode holds unclaimed (heduian, bg5eau on X)
heduian and bg5eau on X (11-14, a Saturday): magpie no longer uses
ZCode's weekend gift. GLM-5.3-Flash-Trial is not in the list, a
manually added one answers "ZCode has no active limited quota", and
free first spends the weekday gift but not the weekend's.

Diffed against the official ZCode 3.18.2 (zai-org/ZCode fec975905,
11-13) and 3.17.2 (a9fe401ee):

- The weekend plan (ZCODE WEEKEND BUILD, testdata/touch-1030-wk.json)
  is a gift ZCode holds until it is claimed from the app's banner. The
  claim (MarketingTouchProvider -> prepareRequestVerificationClaim ->
  claimManualPlan) carries the app's Aliyun captcha proof in 3.18.2 as
  in 3.17.2, and client/configs still says captcha.enabled true. The
  plugin has posted no claim since 0.1.55 (11-07), and claims without
  the proof were refused 3007 since 10-06. Until the plan is claimed
  in the ZCode app it has no balance bucket, so the plugin lists no
  -Trial entry for it and free first has nothing to spend. That is the
  report. The captcha is not got past.
- The Start Plan request: 3.18.2's headers (buildCliZCodeSourceHeaders,
  zcode-source-headers.ts) are the plugin's startHeaders but for the
  version (3.17.2) in User-Agent and X-ZCode-App-Version;
  @ai-sdk/anthropic is 3.0.81 in both. Start's credential in 3.18 is
  the shared ZCode JWT, as the plugin sends. No header picks a plan or
  bucket: the server chooses which bucket a model spends.
- The balance read (zaiStartPlanBilling.ts) is unchanged in 3.18, and
  on the owner's account the balance, the feed and client/configs
  answer the same for app_version 3.17.2 and 3.18.2. APP_VERSION stays.

So the change is the refusal: a -Trial pick that finds no gift now
reads the claim feed (toClaim; kept ten minutes per session, a failed
read names none and is not kept) and, when ZCode holds a plan there,
says "ZCode holds ZCODE WEEKEND BUILD for this account unclaimed:
claim it in the ZCode app (its claim needs the app's security check),
and GLM-5.3-Flash-Trial spends it". Nothing is claimed and no model is
asked. The card's "Gift plans to claim in the ZCode app" line was
already there. README says what happens until the claim.

Run (mote, sandbox HOME): bun test in packages/zcode, 265 pass 0
fail; bun scripts/check.mjs zcode ok. Real account (owner's, sandbox
HOME): unclaimed() read the live feed, [] (no weekend delivery on that
account today).
Broken by hand, each red, then restored: the refusal without the feed
(2 fail), the ten-minute keep removed (1 fail).
Not tried: a real account holding a weekend plan (the owner's has no
delivery or balance plan today), and a claim in the ZCode app followed
by a request; Windows and Linux.
2026-11-14 18:17:21 +08:00
yetone 8e19b6a0e7 zcode 0.1.64: a Start Plan request refused beside the account's others waits its turn, not 429 (JJLIN070414 on X)
JJLIN070414 on X: with two or more sessions on ZCode's Start Plan
through magpie, 429s keep showing; the same work in DeepSeek Harness
runs on. Cause: ZCode answers 3008 when an account has more Start Plan
requests in flight than it serves (some accounts one at a time,
plugins#438). Since 0.1.58 such a cap with others of the account in
flight narrows the gate to one for five minutes, but the request that
was refused still went back to magpie as busyAnswer's 429 after its
1s and 2s re-asks. With one account magpie has no one else to ask, so
the agent got the 429 (Claude Code shows it and retries; dsh retries
silently), again each time the narrowing ran out.

ZCode's own client (zcode-src docs/dynamic-workflow/concurrency.md,
start-plan-provider-business-errors.md) cuts its per-key cap on 3008
and queues capped subagent requests with unbounded retries; only a
main turn's first admission shows the busy banner.

Now askBusy stops at the narrowing (onCap says true) and marks its
answer `requeue`; the Start Plan path gives the slot back, waits at
the head of the queue (startSlot front) until one of the account's
other requests ends, and sends again. The waits share one
startGate.wait, then the queue's own 429; REQUEUE_MAX (4) bounds the
turns. A cap refused alone still counts toward the firewall hold and
goes back as before; free first's gift still replays on the plan.

Run (mica, Bun 1.4.2, HOME and TMPDIR in the run folder; mote's load
was over its cores): packages/zcode bun test 262 pass, 0 fail, 18
files; bun scripts/check.mjs and check.mjs zcode exit 0.

Broken by hand: REQUEUE_MAX = 0 (the old behaviour): the reporter's
two-session test, the #438 test (now all pairs 200) and the wait-bound
test fail; the other 15 in inflight.test pass.

Not tried: a real ZCode Start Plan account with two sessions (a run of
caps can get the home IP a 405 from ZCode's firewall for 1-2 hours);
the queue-front order has no test of its own.

Reported-by: JJLIN070414 (X)
2026-11-14 17:21:51 +08:00
Lucentio-HuangandLucentio-Huang 3f37b858db zcode 0.1.63: the app's China sign-in keeps its identity, and the active provider's profile names the account (#1135)
ZCode's app sign-in reads oauth:active_provider and includes zai_cn, so
a China-channel account keeps its name and user id, follows renewal for
the same user, and stays on its own session when the app switches to
another user with the same display name. Unreadable active_provider
falls back to the old order with zai_cn added.

Reviewed at 5d6e923e3. Run (mica, sandbox HOME): bun test packages/zcode
260 pass; scripts/check.mjs zcode ok. Broken by hand: main's index.mjs
with this PR's tests fails 3 of own.test.mjs (China identity, active
zai_cn, active bigmodel).

Co-authored-by: Lucentio-Huang <Lucentio-Huang@users.noreply.github.com>
2026-11-14 17:02:35 +08:00
yetone 0135b7b0ea agy-cli 0.1.32: the first model list after warming has agy's Claude and GPT models (#1064)
On a signed-in agy, `agy models` takes about 4.4s and `agy acp`'s
session/new about 3s. provider.models() needed three calls before
claude-opus-5-5, claude-sonnet-5-5 and gpt-oss-120b showed up, and
OpenCode 2.x calls it once.

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

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

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

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

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

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

Reported-by: hiee3
2026-11-13 10:59:13 +08:00
yetone fc87cc8855 zcode 0.1.61: a reset past its end is not counted as a card (nathan_ift_us on X)
customer-package-reset/list can still flag a reset available after its
expireTime has passed; the vendor's page lists such a reset among the
expired. resetsOf counted on the flag alone, so an account that owns no
usable reset showed "2 resets" with a stale end (11/8). A reset whose end
has passed is now skipped; one with no end still counts.

Shape read from the vendor's own usage page chunk (bigmodel.cn
ResetQuotaCard: fiveHourResets/weekResets, available === true,
expireTime, recordId, grantType) and the captured list in usage.test.mjs.

Run: bun test packages/zcode on mote with a temp HOME, 256 pass. The new
test is red on the old index.mjs (19 pass, 1 fail). The older fixtures'
fixed 2026 dates are moved to 2027 (they were past by now).
Not tried: nathan_ift_us's real list (no access to the account), so the
cause is inferred from the date, not seen on the wire.
2026-11-12 21:36:31 +08:00
yetone 7c44d02796 zcode 0.1.60: an unreachable plan key or a full plan is a wall, sent once (#1020)
takomitkm saw one GLM-5.3-Flash-Trial request tried 8 times over ~389s,
each failing with "ZCode's Z.ai coding plan key: ECONNRESET: The socket
connection was closed unexpectedly". That text is not the replay: it is
located(), ZCode 3.16's key-location read of the coding plan key
(api_keys/copy/<id>), which runs first in serve(), before any gift or
plan choice. Its failure was thrown, magpie read the throw as a 502 and
asked again (same-one retries, then patience rounds), and the read had
no timeout, so one hung read held the request for minutes. It also told
the user to sign in again for what was the network.

- located(): the key read is bounded (20s). A read that never reached
  Z.ai (ECONNRESET, refused, a timeout, a name that didn't resolve)
  uses the last key read for that location when there is one; with
  none, it is a 429 wall answer (error.code user_model_rate_limited,
  one of magpie's wallCodes, yetone/magpie@067e4c484): sent once,
  rested as a rate limit, the next account asked. An answer that
  refused the read (401, 500) is said as before, sign-in hint included.
- free first's replayOnPlan(): a coding plan whose last usage read
  (codingUsage, teamUsage) counted a window full with its reset ahead
  is not sent to; the replay answers the same wall. The mark is
  dropped by a read with room, at the reset, or 30 minutes after the
  read. A replay that can't reach the plan answers the wall too; a
  caller's abort stays an abort. The gift-first fallback is unchanged.
- The wall's words stay off magpie's quota and credit words, so it
  rests a minute, not a quota's rest.

Tests: packages/zcode/wall.test.mjs (new, 12), built on the reporter's
literal error text; no network (fetch is a fake).

Run:
- packages/zcode bun test on wsl-run (magpie-desktop): 255 pass 0 fail.
- Full suite: `HOME=$(mktemp -d) bun test` on wsl-run (magpie-desktop),
  since mote's and mica's suite locks were queued for hours: 8407 pass,
  0 fail, 19 skip, 593 files. `bun scripts/check.mjs`: exit 0, 59 ok
  (zcode among them).
- Broken by hand (wall.test.mjs on wsl-run), each red, then green
  restored: serve's catch off (2 red), the full-plan check off (1),
  the replay's catch rethrowing (1), the read's timeout removed (1),
  the last key unused (1), the old "sign in again" message (2).

Not changed: a socket error on the plain coding plan path (no free
first) still throws, and magpie still retries any thrown plugin error
as a 502 eight times; filed on yetone/magpie (yetone/magpie#6208).
Not tried: a real Z.ai account whose key read drops, or a real full
plan; magpie's classification of the wall body was read from
origin/main's walled()/failure(), not run.

Reported-by: takomitkm
Refs #1020
2026-11-12 03:15:36 +08:00
yetone 9204c079ae zcode 0.1.59: a reply the gift answered names the -Trial entry, so Usage, sessions and the request log show free quota was spent (WJaunita45604 on X)
Free first sent the plain model to the Start Plan under the plain name, and
the gift answers under that name too, so magpie named the plan's model for
both routes. trialNamed rewrites the model of a gift's whole reply or event
stream to GLM-5.3-Flash-Trial; a failed reply, and a free-first replay on the
coding plan, keep what came.

Run: bun test dual.test.mjs on wsl (61 pass); the two new gift tests fail with
the rename taken out. Not tried: a real Start Plan reply (no gift balance on
this account at this hour).
2026-11-11 13:55:37 +08:00
yetone ea3573bfe9 zcode 0.1.58: an account served fewer than three is narrowed, not held; trial entries are free (#438)
takomitkm (plugins#438, 0.1.57, default settings) had the busy hold arm
with one account, one agent and at most two in flight, at about five
asks a minute, and arm again within a minute of its end. A coding plan
model's weekly or monthly limit (1310) also rested the whole account, so
its -Trial models got the cached 1310 without being asked.

Busy hold. ZCode serves that account one Start Plan request at a time,
so every second request was refused again at its 1s re-ask and counted
toward the process-wide hold. A sustained cap with others of the same
account in flight (the gate's lane busy >= 2) now narrows that account's
gate to busy-1, at least one, for NARROW_FOR (5 minutes; startGate.now
is its injectable clock) and counts toward no hold. A lone sustained
cap still counts, so the hold stays process-wide and keeps the firewall
protection: #801's caps came with up to ~10 in flight, which the gate
never sends, and an account whose slots are taken elsewhere narrows
3 -> 2 -> 1 within a few caps and is then refused alone, which arms the
hold as before. The queue answer says the account's current number.

Rest. The models hook marks each -Trial entry free: true, so magpie's
PaidBesideFree makes a coding plan model's quota refusal rest that
model, not the account. Gift-only accounts' plain names stay unmarked.
Side effects: the Free mark in pickers, free-preferring groups pick the
trials first, and they price at 0, which they are.

Run (mote, bun 1.4.2, HOME=$(mktemp -d)): packages/zcode bun test,
240 pass, 0 fail, 17 files, at this head rebased on 60acd62b;
bun scripts/check.mjs exit 0.

Broken by hand:
- narrowing off (if (false && ...)): the three new inflight tests fail;
  the reporter's case shows the hold armed (until=1000000240000).
- lone caps narrow too (busy < 1): seven hold tests fail (the
  saturated-elsewhere replay, refused-even-one-at-a-time, start.test's
  hold tests, dual's hold test).
- free: true removed: the new gift test fails.

Tests: inflight.test's reporter's case (fake caps at >= 2 in flight,
injected clocks), the narrowing's expiry, and a lone refusal still
arming the hold; gift.test's free trial entries. start.test's in-flight
guard now uses twelve accounts of one request each, and dual.test's hold
test a gate of one, so their caps stay lone ones.

Not tried: a real ZCode account served one at a time; the core side
(magpie's TestZCodeCodingPlanLimitLeavesTrials) is in magpie with the
mover min.

Reported-by: takomitkm
2026-11-11 03:26:57 +08:00
zxy20250120 93dacd738f zcode 0.1.57: the busy hold's answer arms no quota rest (#859)
A busy hold (0.1.54) armed while a Start Plan request was in flight
answers that request with the hold's own 429 from askBusy. It carries no
3008, so busy() does not claim it and spentUp counts it as a spent gift.
On a -Trial pick that rested the model in `blocked` for a minute, and
the next -Trial asks were answered locally "over its quota ... exhausted"
with quota left. Under free first it rested the model the same way
before the replay on the plan.

busyHeldAnswer now sets `x-magpie-busy-hold: 1`, and the -Trial and
free-first gift paths read it before spentUp: the hold's answer passes on
as the rate limit it is and arms no rest. Free first still replays a
held answer on the plan, through the plain >= 400 branch. The gate's
queue answer and the hold's early returns never reach those paths.

Run at the reviewed head e5858d7b merged with origin/main 03ab6d66, on
mote (Bun 1.4.2, HOME and TMPDIR inside the run folder):
- bun test packages/zcode: 236 pass, 0 fail.
- bun scripts/check.mjs zcode: ok.
- The new test with main's index.mjs: red at
  blocked.get(...glm-5.3-flash) toBeUndefined (received a timestamp).
- Broken by hand: the free-first guard removed alone leaves all 236
  green, so only the -Trial guard has a test.

npm had 0.1.56 before the merge; this is 0.1.57.
2026-11-08 15:26:54 +08:00
我是一条没有名字的区 087c36123d inkstone 0.1.3: image-caps preflight, a zero-prompt browser sign-in, key calls on the session cookie (#832)
inkstone 0.1.3 (#832, yunwang2442-creator):

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

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

Not tried: a real InkStone account or sign-in, Windows and Linux runs.
2026-11-07 22:24:56 +08:00
yetone a313a00306 zcode 0.1.56: the Start Plan goes three at a time and re-asks a cap twice, as ZCode's client does
Users of other agent apps on the ZCode plugin saw "rate limited 5 times
in a minute" (star21321321124 on Discord). That is the plugin's own
3-minute busy hold (0.1.54, #801), which trips after ZCode refuses five
requests in a minute as over its in-flight cap (429 3008/3009). The
plugin drove those refusals itself:

- It sent every request magpie passed it. magpie's lane is 3 per
  account, but nothing in the plugin held the Start Plan to that.
- It re-asked a capped request up to six times over about 10s
  (BUSY_WAITS 250..4000, from #395). That kept slots taken and drew
  more caps.
- It counted every capped request toward the hold, including ones the
  next re-ask got past.

ZCode 3.17.2, read from its bundle: wqo = {3008, 3009, 3010} and
kqo = [1e3, 2e3]. So a busy cap is re-asked at most twice, after 1s and
2s, Start Plan only. There is no hold, and one main turn runs per
session.

What changes:
- BUSY_WAITS is [1000, 2000], with no jitter, and 3010 counts as busy.
  This applies to every plan, since the coding plan goes through the
  same askBusy.
- startGate: on the Start Plan, an account has at most 3 requests in
  flight (#395 measured about 3: 3 of 12 and 4 of 12 served). The
  account is keyed by uid, then accountId, then key. Further requests
  wait in a FIFO queue in the plugin and are not sent. A slot is freed
  when the upstream body ends, the agent cancels, or its signal aborts
  (the body is pumped eagerly so an unread reply cannot hold a slot).
  After 2 minutes of waiting, the plugin answers 429 rate_limit_error
  with Retry-After 5: "ZCode's free Start Plan serves this account 3
  requests at a time; this one waited 120s behind the others and was
  not sent. Run fewer agents or subagents on ZCode at once, or try
  again". The coding plan stays ungated. Its cap follows the tier (the
  #395 review), and magpie's lane covers it.
- Free first skips the gift while its account's gate is full, so the
  plain model goes to the coding plan rather than queueing.
- The hold counts a request only when ZCode refuses it again at the 1s
  re-ask. N=5, the 60s window and the 3-minute hold are unchanged, as
  is the rule that an in-flight or queued request stops once the hold
  is armed. Its message now says what happened and what to do: "ZCode
  turned away 5 requests in the last minute as too many requests at
  once, each again when asked a second later. So that ZCode's firewall
  does not block this network, magpie sends no free Start Plan
  requests for the next Ns. Wait, run fewer agents or subagents on
  ZCode at once, or use a GLM Coding Plan model". The words avoid
  "plan"+"limit" after "exceeded", which magpie's usedUpWords would
  read as spent.

History checked: #395 (0.1.32) added the long waits and had an
in-plugin gate removed in review, because it held Max coding-plan
accounts to 3 and was keyed on the jwt. This gate is Start Plan only
(one tier) and keyed per account. #801 (0.1.54) added the hold from
the logs of 11-05 23:06 and 11-06 06:23: about 16 to 18 req/min, 7 to
10 in flight, and the first 405 after 205 to 517s. The hold still
trips on sustained refusals: the replay below has the account
saturated elsewhere, and the hold arms within the replayed minute with
nothing sent after it.

Run on mote, HOME=$(mktemp -d), at the rebased head, Bun 1.4.2:
- bun test packages/zcode: 235 pass, 0 fail.
- New inflight.test.mjs: 13 pass. It covers re-ask count and timing
  (3 asks, gaps of about 1s and 2s), 3010, at most 3 in flight of 12
  sent at once, per-account slots, a slot held across re-asks, the
  queue wait running out (nothing sent, plain 429), abort while queued,
  a cancelled stream freeing its slot, the coding plan ungated, a cap
  the 1s re-ask got past not counting, and the hold message. It also
  replays #801's two days at 20x speed against a fake that refuses past
  3 in flight: 0 refusals, peak 3, no hold, all served. A second replay
  with the account saturated elsewhere arms the hold within a minute.
- bun scripts/check.mjs zcode: ok (registry.json, zcode). Repo bun test: 6780 pass, 0 fail, 20 skip, 491 files.
Broken by hand: inflight.test.mjs against 0.1.55's index.mjs gives 11
of 13 red. 0.1.55 made 7 asks, had 12 in flight, drew 24 refusals in
the replay, and armed the hold on caps a re-ask got past. Two pass on
both, as expected: the coding plan stays ungated, and the saturated
replay still holds.
Not tried: real ZCode Start Plan accounts, live; the replay is
synthetic from the #801 figures, as the raw logs are not in the repo.
Not copied from ZCode's client: its "no re-ask on a session's first
turn" rule, since the plugin cannot tell a first turn reliably.

Reported-by: star21321321124
2026-11-07 17:54:55 +08:00
我是一条没有名字的区 e7004d9354 inkstone 0.1.0: Intern InkStone (书生·端砚) Token Plan, browser sign-in, credit card and ink-* key chat (#775)
New package @magpie-community/opencode-inkstone-auth 0.1.0 for Intern
InkStone (书生·端砚, Shanghai AI Lab) Token Plan, provider id
`intern-inkstone`. Community package by yunwang2442-creator.

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

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

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

Not tried: a real InkStone account sign-in on macOS, Linux or Windows (no
account here); a live chat request; magpie end to end with the plugin.
2026-11-07 15:07:06 +08:00
yetone ea9904d54c zcode 0.1.55: no claim while ZCode asks its security check; the desktop's X-Title and a per-turn x-query-id
young02036 (Discord, 11-07): on an account with a GLM Coding Plan, the
GLM-5.3-Flash-Trial gift answers 405 code 3012 ("blocked due to unusual
activity") while the paid models work, and the plugin's daily check-in
gets a captcha every day while the app shows none.

Diffed against the official ZCode 3.17.2 (zip sha512 matched its
manifest; glm/zcode.cjs and app.asar's host and renderer code):

- The claim. The app's claimManualPlan posts the claim with
  X-Aliyun-Captcha-Verify-Param/Region, and its renderer always runs the
  traceless captcha first. client/configs says captcha.enabled true
  (testdata/client-configs-1107.json, the real reply cut down). The plugin
  can't make that proof, so each day's claim was one more refused claim.
  Now claimDaily reads client/configs (cached ten minutes, a failed read
  not kept) before posting: while captcha.enabled is not false nothing is
  posted and each plan answers captcha, "claim it in the ZCode app"; a
  config that doesn't read is failed, nothing posted. The captcha is not
  got past.
- X-Title. The desktop's model requests say "Z Code@electron"
  (sourceTitle from zcode-protocol-entrypoint); the plugin said
  "Z Code@cli".
- x-query-id. ZCode sends one per user query (query_<uuid>, prefix
  stripped). The Start Plan path now sends a UUID made from the session
  and the count of user text messages: the same through a turn's tool
  results, new with the next user message.

The 3012 itself: on the owner's account (no gift, so code 1005 "exceed
quota limit" means risk control let it through) every shape answered
200 code 1005: adaptive thinking with effort max and max_tokens 64000, a
1.6 MB body, max_tokens 200000, thinking enabled with budget 1024, and
X-Title electron. So the request's shape is not what trips 3012; the
reporter's account looks blocked by risk control as a whole, which only
ZCode support lifts. That the daily captcha-less claims fed it is a
guess.

Run (mote): HOME=$(mktemp -d) bun test in packages/zcode, 222 pass 0
fail; bun scripts/check.mjs zcode ok.
Broken by hand, each red, then restored (cmp ok): the claim gate removed
(2 fail), a config read failure taken as no captcha (1), x-query-id not
set (2), user turns counted wrong (1), the title back to cli (3).
Not tried: a real claim or a real 3012 account (the reporter's); the new
headers against an account that has a gift; Windows and Linux.

Reported-by: young02036
2026-11-07 14:57:59 +08:00
zxy20250120 09a27bef01 zcode 0.1.54: a busy hold also stops requests already in flight (#801)
When five Start Plan requests in 60s get ZCode's 3008 "busy", magpie holds
zcode.z.ai off, so that the counting firewall doesn't escalate to its 405
block. While the hold is on, a Start Plan request is answered locally with a
429 carrying Retry-After, and it is not counted. A request that was already
retrying when the hold armed now stops too: askBusy checks the hold after
counting a cap and again after each wait. The coding plan and free first's
replay pass no onCap, so the hold never touches them. When the edge (405)
hold and the busy hold are both on, the edge hold's answer wins.

Run at the reviewed head 19f7e9019ca22a3bad97c974bdf796b88ec8e3e3 (Bun 1.4.2,
HOME=$(mktemp -d)):
- macOS (mote): bun test packages/zcode 217 pass 0 fail; bun scripts/check.mjs
  zcode ok; repo-root bun test 6580 pass, 20 skip, 0 fail (475 files).
- Linux (WSL2 Ubuntu 24.04): bun test packages/zcode 217 pass 0 fail; check ok.

Broken by hand (full zcode suite each):
- post-sleep hold check removed: red, 16 asks instead of 12;
- busyCap's in-hold return removed: red, hits 2 instead of 0.
- The post-cap check removed, or onCap keying dropped: still green. These are
  latency and coding-plan scoping, left for a follow-up test.

npm had 0.1.51 to 0.1.53 at review time, so 0.1.54 is free.

Not tried: a real ZCode 3008 storm, the firewall's real 405, magpie's fallback
on the hold's 429 in a real gateway run, Windows.
2026-11-07 12:00:06 +08:00
yetone 367edb503c zcode 0.1.53: a spent bucket's 200 says 429 on the plain path too (#817)
A ZCode answer that carries a spent code (1005 "exceed quota limit",
1113) inside an HTTP 200 now reaches magpie as a 429 on every path. Before,
only a -Trial entry (forcedGift) and free first's gift did this. On a
gift-only Start Plan account, a request for the plain model (GLM-5.3) went
through `return done(kept(res))` as a 200. magpie took it for a reply that
did not stream (502), failOther, and its window branch rested the whole
account until the bucket reset. GLM-5.3-Flash, which has its own bucket,
went unused for ~22h. As a 429 it is failQuota, and magpie rests the model
whose window is full.

spentSaid reads only a non-stream JSON answer under 400. Any other answer,
a stream included, goes on as it came. A reply whose text happens to say
1005 stays a 200. The same applies to the plan answer free first replays
on (replayOnPlan, three places), and to the coding plan's own 200 with
1113.

Run at 081c67ac on mote, HOME a temp folder: bun test packages/zcode
212 pass, 0 fail; the whole repo bun test 6558 pass, 20 skip, 0 fail;
scripts/check.mjs exit 0. Broken by hand, each red: the plain path back
to done(kept(res)) (gift.test's two new tests, 200 for 429); the
replays without spentSaid (dual.test's new free-first test).

Not tried: a live spent bucket. The 200 body is the reporter's words, and
dual.test's fixture already had it.

Reported-by: zane668
2026-11-07 09:11:36 +08:00
kongbai01203 e0769e8e20 zcode 0.1.52: hold a rate-limited account in the plugin until ZCode's wait is over (#503)
When ZCode rate limits a check-in (HTTP 429 on the touch feed, or code
3002 on a claim), the plugin now holds that account itself. Until the
wait is over, a check-in answers the same failed (message and until) and
sends no request. The wait follows Retry-After (seconds or a date) up to
six hours. Without one, it doubles from 30 minutes. A read that comes
through with nothing rate limited forgets it. magpie before v0.1.3165 asks
a failed again after 30 minutes whatever its until says, which is how #503
saw 180 reads in four days. The hold is keyed by the account
(s.key || s.jwt), so keyless Start-Plan sign-ins each have their own. It
lives in memory, so a restart forgets it.

Run at 017e5dfc (merge base 654d3bea), on mote with HOME in a temp
folder: bun test packages/zcode 208 pass, 0 fail; check.mjs zcode ok.
Merged with origin/main 8163be36: zcode 209 pass; the whole repo
check.mjs exit 0 and bun test 6498 pass, 20 skip, 0 fail. Broken by hand, each red: holdKey back to s.key
(the two-keyless-accounts test), the delete moved before the claims (the
claim doubling test), no forget after a read with nothing to claim (the
doubling test). CI on-npm and test green at 017e5dfc.

Not tried: a live ZCode 429 or 3002.
2026-11-07 01:13:55 +08:00
yetone 8163be365f zcode: test the system shape zcode.z.ai lets through (plugins#348)
XinOrigin's matrix on plugins#348 (11-04) says zcode.z.ai serves a Start
Plan request only when its system is an array of two or three text
blocks, ZCode's first byte for byte and its second as ZCode's begins; a
string, no system, the first block alone, the first with a block of the
caller's, or a fourth block answers 405/3012. The new test sends Claude
Code's shape (billing-header block, prompt, CLAUDE.md block, with
thinking adaptive, context_management and output_config), Codex's string
instructions, no system, and ZCode's first block alone, and checks each
goes out as the passing row: three text blocks, ZCode's first two
unchanged, the agent's text after ZCode's own sections in the third, the
top-level fields kept.

No code change: 0.1.51 already sends this shape (0.1.21 for #343, 0.1.48
for the 3.17.2 texts).

Live, on the owner's ZCode account (11-06 15:48 UTC, a GLM Coding Plan
account with no Start Plan gift), one request each to
zcode.z.ai/api/v1/zcode-plan/anthropic/v1/messages with 0.1.51's
startHeaders and dress:
- Claude Code-style system: 200 {"code":1005,"msg":"exceed quota limit"}
- the same with a 30KB agent system: 200, 1005
- Codex-style string system: 200, 1005
- Claude Code's top-level fields and a tool: 200, 1005
- control, ZCode's first block alone, not dressed: 405 code 3012
  (logid 20261106154826f91ddad38c8bfdefae1d)
So the system check runs before the quota check, and 0.1.51's dressing
gets past it. Not tried: a request on an account with a live gift (the
owner's has none), and a burst of requests.

Run on mote: bun test in packages/zcode, 201 pass, 0 fail, 12 runs in a
row; one earlier run had 5 reds in userid.test.mjs (expect(got.length)
.toBe(1)), not seen again in those 12 runs. bun scripts/check.mjs zcode
ok. Broken by hand: dress sending the agent's text as a fourth block
and more turns the new test red (Expected 3, Received 6); restored,
green.
2026-11-07 00:33:28 +08:00
yetone c96d04bb6b zcode 0.1.51: a gift-only account lists only the models its balance names (young02036)
young02036 on Discord: two ZCode accounts in magpie, one with no GLM
Coding Plan whose Start Plan holds glm-5.3-flash, one subscribed whose
gift shows as GLM-5.3-Flash-Trial. Picking per account the models each
can use worked; left to the plugin's lists, requests failed while the
ZCode app on the same accounts worked.

A gift-only account listed every model the Start Plan's provider config
names (GLM-5.3-Flash, GLM-5.2, GLM-5-Turbo), whatever its balance held,
so magpie's routing took it to serve models it has no bucket for. ZCode
3.17.2 offers such an account the balance's models alone
(resolveStartPlanBalanceAvailability / resolveZaiStartPlanBalanceModelIds).
The models hook now keeps, for a gift-only account, the config models
its balance names (plus the gift names the config lacks and the -Trial
entries, as before). A balance naming no model, or one that can't be
read, leaves the config's list as it was. Coding plan accounts are
unchanged.

Run (mote, bun 1.4.2, isolated HOME): bun test packages/zcode, 200 pass;
bun scripts/check.mjs zcode ok. The new gift.test.mjs case was red on the
old code (GLM-5-Turbo and GLM-5.2 listed) and green after.
Not tried: a real ZCode account (none available); whether the reported
3012 came from such a request is not proven.
2026-11-05 11:30:10 +08:00
yetone 8fcc592e8b zcode: say what the feed's seq is, ZCode's count of its requests, not a page (#676)
#676 (XinOrigin) suggests scanning marketing/touch at seq 0..8 each
round. ZCode 3.17.2's client (zai-org/ZCode@a9fe401) sends seq as a
per-process counter from 0, one GET per refresh
(marketingTouchService.ts, bootRequestSeq), and its doc says the
number is only for the server's logs and does not change what is
delivered (docs/marketing-touch-client.md, "启动请求序号 seq"). The
plugin already sends it that way. Nine GETs a round per account would
be the tighter polling #503 asks us not to do, so the comment says
why it is one ask.

Comment only: no version bump, nothing run.
2026-11-05 01:44:15 +08:00
kongbai01203andkongbai01203 81df338116 zcode 0.1.50: a claim's code 1004 is ineligible, read again in half an hour (kongbai01203, #729)
A claim ZCode answers with code 1004 (HTTP 400, a plan the account is not offered at that moment) is read as ineligible, naming the plan, and asked again half an hour out as an inactive is, instead of failed. Captcha (3007) is unchanged: still "claim it in the ZCode app", never solved. Version 0.1.50 (maintainer bump on the PR branch).

Run at 6837f27e on mote (macOS, Bun 1.4.2, sandbox HOME):
- packages/zcode `bun test`: 199 pass, 0 fail. `bun scripts/check.mjs zcode`: ok.
- Broken by hand: dropping the 1004 branch in claimOne turns 3 checkin tests red; dropping the recheck `until` on an ineligible turns 2 red.
- magpie's host accepts "ineligible" with an until and asks again at it (host.js checkinOutcomes, plugin_checkin.go ValidUntil).

Not tried: a real 1004. The owner's one ZCode account answered 3007 (captcha) for zcode-v3-start-plan-1029 and zcode-v3-start-plan-gb-1104 under both 3.16.3's and 3.17.2's header, so the fixture's message text is the author's, from their six accounts on 11-04.

Co-authored-by: kongbai01203 <kongbai01203@users.noreply.github.com>
2026-11-04 23:14:06 +08:00
yetone 36a017ac9e zcode 0.1.49: a free-first refusal no longer answers the -Trial entry a local "quota exhausted" 429; free first gets a switch in magpie's provider editor
Can4ry_ on X (11-04): testing GLM-5.3-Flash-Trial in magpie answered
"429 · ZCode's limited quota for glm-5.3-flash is exhausted or temporarily
unavailable" while ZCode's own app was served, glm-5.3-flash kept using
the Coding Plan after the Start Plan opened at 23:00, and there was no
freeFirst setting under the ZCode provider.

Cause: free first's plain GLM-5.3-Flash request goes to the gift first.
When zcode.z.ai turned it away with 405/3012 (risk control, or 0.1.46/0.1.47's
3.14.3 prompt texts), restModel rested glm-5.3-flash in `blocked`, the same
map a -Trial entry's quota check reads. So for the next minute the Trial
entry answered a local 429 that called the quota exhausted, without asking
ZCode, and every plain request in that minute went to the plan. The
suffix it added, "ZCode answered 429", was wrong too, and it pushed the
spent words off the end of the message, so magpie's zcodeSpentWords
didn't match and the gateway rested the whole account.

Change:
- A free-first refusal that is not a quota answer rests the model in a
  new `sidelined` map, read by free first only. A quota answer still rests
  it in `blocked`, which the -Trial entry obeys too.
- The local 429 keeps "ZCode's limited quota for X is exhausted or
  temporarily unavailable" last; why it rests now goes in front.
- auth.options declares a "Free quota first" switch (free_first, on by
  default, zh/zh-TW/ja/de words), read through input.magpie.options. Off
  keeps the plain models on the plan. A JSON freeFirst: false still turns
  it off; an absent key (an older magpie, OpenCode) leaves the JSON's word.
- README says where the switch is and what a refusal rests now.

Run: bun test packages/zcode on mote under a temp HOME, 197 pass, 0 fail.
bun scripts/check.mjs on mote, exit 0.

Broken by hand: the new dual tests against HEAD's index.mjs (the old
code), 4 fail. "a free-first refusal leaves the -Trial entry asking
ZCode" fails with 429 for 200, the reported case. The others are the
spent words test (no match), the switch test, and the block-page test,
whose second plain request went to the gift again.

Not tried: a real account. The owner's account has no live Start Plan to
be refused or spent. Not tried: magpie's editor showing the switch. That
comes from host.js optionsOf and app.js pluginOptionsField, unchanged.
2026-11-04 01:59:22 +08:00
yetone 97e9c23804 zcode 0.1.48: publish #682's 3.17.2 prompt texts (jinpy666) with 0.1.47's wire model spelling
7e37132 landed #682 under 0.1.47, which 6a75bbd had already published, so
npm kept 0.1.47 without the texts. 0.1.48 carries both. Why: since 11-03
zcode.z.ai answers dressed Start Plan requests with 405/3012 while the
app works on the same accounts (#348); #682 found 3.14.3 texts in the
body under a 3.17.2 header. Run: bun test packages/zcode on mote, 194
pass, 0 fail (before the version-only change). Not tried: a real account.
2026-11-04 01:12:03 +08:00
jinpy666 7e3713233f zcode 0.1.47: the Start Plan's prompt texts are ZCode 3.17.2's
zcode.z.ai turns every dressed Start Plan (gift) request away again
with 405 "request has been blocked due to unusual activity", code 3012,
since the evening of 11-03: every account with a live gift, while the
ZCode app's own gift requests go through on the same machine and the
same accounts (five gift-holding accounts probed, all 405 through the
plugin, the four without a gift taking the plugin's own 400). The plan
path (api.z.ai, open.bigmodel.cn) is unaffected — only the dressed
requests to zcode.z.ai are refused, so it is the dressing, not the
accounts and not the address.

0.1.46 raised APP_VERSION to 3.17.2 (8fc12a3), and 0.1.45 had already
read the marketing feed as 3.17.2 (#678), but the body a Start Plan
request carries was still ZCode 3.14.3's prompt texts (901fd87e, from
magpie's zcode_prompt.json, 10-02). The vendor's risk control now
compares the body against the current client's, and a request that says
3.17.2 in its headers while its three system blocks are three versions
old is turned away as unusual activity.

Following 3.17.2's source (a9fe401, apps/zcode-cli/packages/core/src/
context/), the dressed request now says what the 3.17.2 client says.
system[0] is "You are ZCode, an interactive agent" (sections/cli-prefix.ts;
was "... interactive coding agent"). system[1] is the identity section
(sections/identity.ts: "You are an agent working with the user toward
their goals, using your own judgment along the way.", # Harness bullets
one space in, the mid-conversation-system wording) joined with "\n\n" to
the desktop context (sections/desktop.ts, its new Interactive views
part and the no-directory branch, the plugin knowing of no Gen UI
output directory). system[2], after its "\n\n" boundary, joins the
unheaded dynamic sections (dynamic-sections.ts): the code-style,
pronouns and action-caution paragraphs, the slash-skill guidance when
the request has a Skill tool (buildSessionGuidanceSection's gate, the
tool table being the request's own), the environment (env-info.ts,
bullets one space in, the invoked line's trailing space, the
untrusted-downloads note, git as true/false; the agent's shell is still
unknown to the plugin and left out, as #86 left it), the model line as
its own section ("You are powered by the model named ...",
buildModelSection), and context management — then the agent's own
system text, as before. The day goes into its <system-reminder> turn
alone, 3.14.3's currentDate intro and outro being gone from 3.17.2's
meta-user context (docs/design/v2/loop/system-prompt-contract.md,
meta-user-context.md). The three-block shape is untouched (#343), as
are the headers (the @ai-sdk/anthropic version is 3.0.81 in 3.17.2's
lockfile too) and metadata.user_id.

The texts were checked byte for byte by importing 3.17.2's own section
builders (bun, a stub for @zcode/shared) and comparing their content
strings: cliPrefix 7779642ea44a4696, identity aac4ba4cc7b555b3, desktop
86e0396775d5ed0e, dynamic behavior 7d843753f3adae93, session guidance
6596a0131800c779, context management 406a0480d88086cd (start.test.mjs
pins them). Live on the reporter's machine, after the texts: every
gift-holding account's -Trial request answers 200 again (five accounts,
405 on all before), the coding plan's account's plain request routes
onto its gift (free first) and answers 200, and through magpie's
gateway zcode/GLM-5.3-Flash serves as the gift's glm-5.3-flash, 200.
bun test (192 pass) and bun run check pass.
2026-11-04 01:03:48 +08:00
yetone 6a75bbd43c zcode 0.1.47: a gift model goes out under ZCode's registry spelling, and a rested model says why
A -Trial request took the model name from the bucket's capabilities,
lowercased ("glm-5.3-flash"), and sent that. ZCode 3.17.2 sends its registry
id ("GLM-5.3-Flash"): normalizeOfficialGlmModelId's spelling, which its own
docs say is not rewritten on requests. The plugin now sends the registry
spelling for the models ZCode knows (wireModel), for trial entries and the
free-first plain model alike; unknown names go as the bucket wrote them.

A 429 from the gift also rests that model for a minute, and the local
refusal in that minute read the same as a spent bucket. It now says ZCode
answered 429 to the last request and the model is not asked again for a
minute.

Not changed: X-Device-Mid. 3.17.2's docs say it goes on config GETs, not on
the model transport, and start.test.mjs holds that.

Run at this head: bun test packages/zcode on mote, 193 pass. Undoing
wireModel turns 7 tests red. Not tried: a real account (none here); the
cause of the reports (429 and 405 on glm-5.3-flash-trial, 11-03) is not
proven, the model spelling is the one request difference found in the
3.17.2 source.
2026-11-04 00:35:49 +08:00
yetone 8fc12a38b3 zcode 0.1.46: sign in as ZCode 3.17.2 and take a Start Plan that starts later
Three changes, each matching the client's source at zai-org/ZCode@a9fe401
(v3.17.2):

- Every call goes out as 3.17.2: the sign-in, the Start Plan balance,
  the config, the requests, and (as in #678) the feed and the claim.
  ZCode gates by the version. #678 found the feed answers empty to 3.16.3,
  and the balance "judges capability by the real app_version"
  (zaiStartPlanBilling.ts). MARKETING_VERSION folds into APP_VERSION.
- A sign-in whose only Start Plan starts later is taken, not refused with
  "has ended or was never started". ZCode's
  resolveStartPlanBalanceAvailability counts such a plan ("pending") as
  the account's. startPlan takes it only when the sign-in asks
  (coming); requests and the card are unchanged, and the card already
  names its start.
- X-Client-Language on the feed is zh-CN or en-US only, as
  marketingTouchService's localeSchema sends it. Before, it was the
  computer's locale as it was (zh-Hans-CN, en-GB, ...).

Run at this tree on mote:
- bun test packages/zcode: 191 pass, 0 fail.
- bun scripts/check.mjs: clean.

Broken by hand:
- APP_VERSION back to 3.16.3: 7 red, among them the two new sign-in tests
  through their balance app_version check.
- The sign-in without coming: those 2 red.
- The old locale: the language test red.

Not tried: a live sign-in, balance or feed. No ZCode account was in a
sandbox. Whether the balance answered sliyrainbow's account with no plan
under 3.16.3 or with one that starts later is not known; this fix
covers both.

Reported by jinpy666 (#676) and sliyrainbow (Discord).
2026-11-03 21:32:29 +08:00
Jinpy 017a7ee3b2 zcode 0.1.45: the daily claim reads the feed as the current client does (#678)
The marketing feed (touch) and the claim now go out under ZCode 3.17.2's
version header. jinpy666 found that under the pinned 3.16.3 the feed
answers empty, while under 3.17.2 the day's banner shows, and checked it
against the live API. The check-in no longer reads /billing/preview,
which the v3.17 client doesn't poll (docs/marketing-touch-client.md in
zai-org/ZCode@a9fe401).

Reviewed at f805d97 and run there on mote:
- bun test packages/zcode: 187 pass, 0 fail.
- bun scripts/check.mjs: clean.
- Broken by hand: with MARKETING_VERSION set back to 3.16.3, 4 tests go
  red (the touch and claim version pins, and the card's feed read).

Not tried here: a live feed or claim. No ZCode account was in a
sandbox, so the live run is jinpy666's (10 accounts: 7 captcha, 3
inactive).

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

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

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

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

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

Not tried: a real sign-in with a real account on 2.x; Windows (the
reporter's OS); chat.headers, chat.params, usage and tool hooks, which
the adapter doesn't carry to 2.x; the tools/pages packages (calc,
goanyapi, layerfs, search1api, aelios, agent-console, chat,
fingerprint, nowledge-mem, kimi-desktop), which still load only on 1.x.
2026-11-03 13:54:26 +08:00
yetone 036fb6ed43 zcode 0.1.43: a block page holds zcode.z.ai off three minutes, for every account (#649, frank6com)
frank6com's 405 ("the provider's network firewall blocked requests from
this IP") is Aliyun's edge firewall in front of zcode.z.ai answering
POST /api/v1/zcode-plan/anthropic/v1/messages (the Start Plan) with its
405 HTML page. It is the address, not the method nor the account: ZCode's
own app got the same 405. Two Start Plan accounts and three sessions with
subagents (up to 6 requests at once from one IP), and every request after
the block went on knocking on the firewall, from both accounts, since the
gateway falls back but rests nothing for an edge block.

Now a block page sets a process-wide hold (edge.until, EDGE_HOLD three
minutes): while it lasts, a Start Plan request and a picked -Trial entry
are answered here with the same 405, permission_error and
provider.BlockedHint word for word, plus until when, so magpie's
EdgeBlocked and retryable still send the request to the group's next
provider. Free first leaves the gift and keeps a dual account on its
coding plan (api.z.ai, another host). A 3012 or a bare 405 is the
account's and holds nothing. The first request after the hold asks again.

Run, at this head, on mote:
- packages/zcode: bun test, 189 pass, 0 fail.
- bun scripts/check.mjs zcode: ok.
- Broken by hand: without the line that sets the hold, both new tests
  are red (65 pass, 2 fail in start + dual); without !edgeHeld() in free
  first, the dual test is red (66 pass, 1 fail).

Not tried: a real zcode.z.ai request. Reproducing needs the address
blocked, and asking until it is would block the owner's network. The page
the tests use is the one plugins#425 recorded.
2026-11-03 02:28:30 +08:00
yetone b820704803 zcode 0.1.42: a plain GLM model spends a live ZCode gift first, by default (sgfvdsg86265 on X)
The request (X, 2117210897471169009): when the account has gift quota
for a GLM model, which ZCode hands out every weekend, spend that first.
freeFirst (#505) already does it, but only when it was turned on, so a
gift lapsed unused behind an agent that asks for the plain model. It is
now on unless the plugin's options or the provider's say
`"freeFirst": false`, which are still honoured as they are. Every way
the gift can fail (spent, a model it doesn't serve, no ZCode session, a
refusal's minute of rest) still falls back to the coding plan, as
before. A team seat's plain model spends the personal gift first too.

The tests that are about the plan and the -Trial picks now build the
plugin with freeFirst off, as they assumed it was.

Run on mote: HOME=$(mktemp -d) bun test in packages/zcode, 187 pass;
bun scripts/check.mjs zcode ok.
Broken by hand: with the default back to off, "free first is on when
nothing sets it" and "free first is on by default for a team seat"
fail; the rest pass.
Not tried: a real account with a claimed gift. The owner's account has
only an unclaimed one, which wasn't claimed for this.
2026-11-02 19:13:09 +08:00
yetone 25a50db0fa zcode: the check-in recheck's notes no longer name reset cards as feed plans
Reset cards are customer-package-reset, read for usage and spent on
ZCode's own page; they never come through the plan feed that #600's
half-hour recheck reads. The README and the RECHECK comment named
one, which the PR's own body says is out of scope. Wording only.

Run at this tree on the Mac mini (Bun 1.4.2, HOME=$(mktemp -d)):
`bun test` in packages/zcode, 184 pass, 0 fail.
2026-11-01 23:55:33 +08:00
Pr1p 081c4cb8f0 zcode 0.1.41: a nothing-to-claim check-in asks again in half an hour (#600)
A plan feed answer of nothing to claim (`inactive`) now carries an `until` half an hour out, so magpie's check-in loop asks again during the day and a gift plan dropped into the feed after the day's first ask (the 19:00 Beijing weekend plan) is claimed before it expires. captcha, claimed, done and failed answers still stand for the day. Bumps the package to 0.1.41. By Pr1p.

Run at c655b088ef0eba6e130b78c867e429b6c39ac09c on the Mac mini (Bun 1.4.2, temp HOME):
- `bun test` in packages/zcode: 184 pass, 0 fail.
- `bun scripts/check.mjs zcode`: ok, exit 0.
- Broken by hand: putting `until` on the captcha answer turns "an inactive says until half an hour out…" red (1 fail); removing it from inactive turns 3 tests red.
- package.json changes only the version (0.1.40 to 0.1.41).

Not tried: a real ZCode account over a day. The README and the RECHECK comment still name "a reset card" among what arrives in the plan feed; reset cards are customer-package-reset and are not claimed here. That wording is fixed in a follow-up commit.
2026-11-01 23:54:51 +08:00
yetone 26864ec9b0 zcode 0.1.40: two accounts take requests at once, the others in reserve
01huadalang on Discord (#feedback): three ZCode accounts used at once
from one address got the address refused with a 405; two were served.
They asked for the first account to be used until it runs out, then the
next.

The plugin now declares maxAccounts 2, on the auth hook and as
magpie.maxAccounts in package.json, beside maxConcurrency. magpie (the
release after this, its provider setting Accounts at once) sends
requests to the first two accounts of the user's list only and holds the
others in reserve; one that runs out or fails rests and the first in
reserve takes its place. The user's own value on the provider wins, 0
for every account. A magpie that doesn't read the field uses every
account, as before. README: "Two accounts at once".

Run on mote: HOME=$(mktemp -d) bun test in packages/zcode (183 pass,
0 fail) and bun scripts/check.mjs (exit 0). Broken by hand:
package.json's maxAccounts set to 3 turns "two accounts at once are
declared, the same number twice" red. Not tried: real ZCode accounts
(none used, per the task), and whether two at once is always under
ZCode's limit; that is the reporter's finding, and the user can lower
it to 1.
2026-11-01 04:02:16 +08:00
yetone 28881086c5 zcode: the daily claim is tested on #503's real marketing/touch reply
kongbai01203 posted the real GET /api/v1/marketing/touch?seq=0 reply
(10-30 22:11 +08:00, comment 6526694290) for the account that claimed
ZCODE WEEKEND BUILD. It is in packages/zcode/testdata/touch-1030-wk.json
as their bytes. Their paste was cut inside
success_popup.description.content's HTML (2510 of 2628 characters), so
only the closing `"}}}}]}}` is added and their trailing "…" taken off.

0.1.39's parser handles it as it is; no change to index.mjs, no version
bump (the package's published files are unchanged):
- checkin: the one claim_zcode_plan button is claimed once with
  {"plan_id":"zcode-v3-start-plan-1030-wk"}, named ZCODE WEEKEND BUILD;
  the close button ("args": null) and the success popup's navigate and
  copy_text buttons claim nothing, and nothing goes to touch/action.
- the same delivery with its claim button taken out is inactive, though
  its background and success popup still carry the zcode_plan.
- after the claim, deliveries is empty (their second finding, count
  theirs, bytes the real reply's top level): inactive, not failed.
- the card's claim line from the real feed: "1 · ZCODE WEEKEND BUILD".

What the real reply has that the 0.1.39 hand-made fixture didn't:
button text as {format, content}, a close button's args null, a bundle
background, resource_position and priority, and a success_popup inside
the banner repeating the zcode_plan.

Run on mote: HOME=$(mktemp -d) bun test (3880 pass, 0 fail) and bun
scripts/check.mjs (exit 0). Broken by hand: claiming a zcode_plan's
plan_id with no claim button turns "the real delivery without its claim
button" red (the hand-made closeOnly case stayed green); naming a plan
from a later zcode_plan when the first is the same turned the two
real-feed tests red. Not tried: a complete, uncut touch reply (the
reporter will post one at the next window), and a real claim through
the plugin.
2026-10-31 00:05:27 +08:00
yetone 2e580cfead zcode 0.1.39: gift plans are also claimed from the ZCode app's banner feed (#503)
kongbai01203 found on 10-30 that a ZCode claim banner's plan (ZCODE
WEEKEND BUILD, 500M GLM-5.3-Flash tokens) is in neither
/billing/preview nor /billing/current while the app shows the banner,
so 0.1.35's daily claim said "no ZCode gift plan to claim". The app
reads the banner from GET /api/v1/marketing/touch?seq=<n>: each
delivery's banner button with action type claim_zcode_plan carries the
plan_id, and the claim is the same POST /billing/claim. Their capture
has a real code 0 claim reply ("Plan claimed successfully.").

- toClaim reads both lists (the feed first, then the preview) and keeps
  each plan_id once; claimDaily and the card's claim line use it.
- The feed goes out with what the capture shows the app sends: the
  session, X-Device-Mid, X-ZCode-App-Version and X-Client-Language
  (the system locale), seq counting up from 0 per process.
- A list that doesn't read is failed (asked again later), never
  "nothing to claim"; a plan claimed beside it is still named.
- claimOne is unchanged; README says the two lists and that a plan just
  claimed may show in neither billing list until its effective_at.

Run on mote (macOS, Bun 1.4.2, temp HOME), on eee889a:
- packages/zcode `bun test`: 178 pass 0 fail.
- Red on the old index.mjs (origin/main's, with the new tests): 3 fail
  (the banner claimed from the feed, an unreadable feed is failed, the
  banner named on the card).
- Broken by hand: claiming each plan per list (no dedupe) and dropping
  the "list unread with nothing listed" return: 3 fail (plan both lists
  name claimed once, unreadable feed, unreadable preview).
- Full `HOME=$(mktemp -d) bun test` from the root: first run 3870 pass
  1 fail, its name lost (the log was cut by tail); two reruns with the
  whole log kept: 3871 pass 0 fail. `bun scripts/check.mjs`: ok.

Not tried: a real claim through the plugin. The feed fixture is built
from the capture's description of its fields, not its literal bytes
(only the claim reply was posted whole); the touch/action call the app
makes for a banner's confirm/close is not sent.
2026-10-30 23:08:10 +08:00
Jinpyandjinpy666 5a9c776832 zcode 0.1.38: freeFirst, the plain model spends the account's gift first (#505)
freeFirst (a boolean plugin or provider option): a plain model request
spends the dual account's own live gift first, under the name the gift
lists, and falls back to the coding plan when the gift can't serve it.
Any gift failure (spent 1113/1005, block page, 4xx/5xx, its own
waited-out busy cap, a network throw) is replayed on the plan in the same
request with the plan's own busy patience; a caller's abort stays an
abort. -Trial entries keep their strict meaning. Off by default.
zcode 0.1.38.

Run at the reviewed head 7ae2ea15d (on main 7673cd0), on mote (macOS,
Bun 1.4.2, temp HOME): `bun test` in packages/zcode 173 pass 0 fail;
`bun scripts/check.mjs zcode` ok; `npm pack --dry-run` 4 files
(README.md, index.mjs, package.json, prompt.mjs) at 0.1.38.

Broken by hand: the gift's catch reduced to `throw e` turns "a gift that
cannot be asked at all is answered from the plan" red; the abort guard
reduced to `if (!freeGift) throw e` turns both abort tests red (2 fail);
the signal check alone removed turns the in-flight abort test red.
Reviewer probes (abort before/in flight, gift 3008 then throw, gift and
plan both throwing, freeFirst off) behave as intended.

Not tried: a real dual account against zcode.z.ai; every case here runs
against a fetch fake.

Co-authored-by: jinpy666 <5868671+jinpy666@users.noreply.github.com>
2026-10-30 14:27:16 +08:00
yetone 7673cd06de zcode 0.1.37: an account with no gift plan to claim is no check-in event, not a failed check-in
hykql (Discord, magpie v0.1.2143, zcode 0.1.36) saw every ZCode account's
daily check-in fail with "gift plans to claim: no plan list in the reply",
a Start Plan account and one with no GLM Coding Plan alike. ZCode's
GET /billing/preview answers an account with nothing to claim with no
data at all, not data.plans []:

  {"code":0,"msg":"","logid":"202610300535585c4e3de75769b684da87"}

(the owner's account, read 10-30 with GETs only, with and without the
X-ZCode-App-Version / X-Platform headers; both the same). #503's capture
of 10-29 had "plans": [], so 0.1.35 took a missing list as unreadable.

previewPlans now reads the list for both the claim and the card's claim
line: no data, data null, or data without plans (or plans null) is a
list of none, so the check-in is "inactive" (magpie shows "No check-in
event now"). call has already judged the code, so only a code 0 reply
gets here. Data that isn't an object, or plans that aren't a list, still
don't read and stay failed, never claimed.

Run (wsl-run on magpie-desktop, HOME=$(mktemp -d); mote was at load
220-250): `bun test` in packages/zcode, 152 pass 0 fail; the whole
repo's `bun test`, 3720 pass 0 fail of 3727 across 298 files;
`bun scripts/check.mjs zcode` ok. The new checkin test (the real
no-data reply, data null, data without plans, plans null) is red on
0.1.36's index.mjs (1 fail). Broken by hand: plans that aren't a list
read as none turns "a preview that doesn't read is failed" red; put
back, green.

Not tried: a real claim (no account has a plan to claim now), and the
official ZCode client's own parse of this reply (no ZCode app on hand);
the fixture is the vendor's real bytes. Not changed: #505 (freeFirst)
touches other parts of index.mjs.
2026-10-30 13:45:42 +08:00
yetone 63748b9d67 zcode 0.1.36: a gift bucket beside a Coding Plan is named by its model first (#504)
Danbuth's GLM Coding Max account had claimed ZCode's Start Plan (plan_id
zcode-v3-start-plan-1029, named "ZCODE GLOBAL BUILD") and found no Start
Plan on magpie's card. The plugin did read it: usage asks
/billing/balance beside /quota/limit and adds every live gift plan's
buckets after the Coding windows, whatever the plan type, every plan
and not only the first. The bucket was the panel's third ring, named
"ZCODE GLOBAL BUILD · GLM-5.3-Trial", which magpie's ring and account row
cut to "ZCODE GLOBAL BUI…": neither the model nor the plan's kind.

ZCode 3.16.3's own popover (host getStartPlanSnapshot, renderer
"Today's balance") lists these buckets by show_name, apart from the
Coding Plan's windows. So a gift bucket's name now starts with that
(the picker's -Trial id when it counts a model) and the plan follows:
"GLM-5.3-Trial · ZCODE GLOBAL BUILD". A gift-only account with several
plans names them the same way round.

Run (on mote, HOME=$(mktemp -d)): `bun test packages/zcode`, 151 pass 0
fail; `bun scripts/check.mjs`, every package ok, exit 0. The new test
uses a real /quota/limit reply (owner's account, read in a sandbox HOME
copy with GETs only) and the real ZCODE GLOBAL BUILD plan row from #503,
times moved to now. Broken by hand (old label order): the new test and
five others red; put back, green.

Not tried: a real balance of the ZCODE GLOBAL BUILD plan (the owner's
account has none), so its buckets take the shape of ganlerk's Start Plan
balance. Not changed: magpie's tray panel shows at most three rings and
the account row two windows, so beside a Coding Plan's 5h and weekly
only the first gift bucket is on the panel; the rest are in the tooltip
and on the Usage page.
2026-10-30 10:31:28 +08:00
yetone 8ebbaa5880 zcode 0.1.35: claims each account's ZCode gift plans daily through magpie's check-in (#503)
ZCode hands out gift/resource plans that sit on an account until claimed,
and an account used only through magpie let them lapse. The plugin now has
auth.checkin, so magpie's daily check-in (`magpie accounts checkin`, and
Settings -> Daily check-in, where ZCode is off until the user turns it on)
claims them, the shape the MiniMax, Qoder and Loomy plugins use.

claimDaily reads GET /api/v1/zcode-plan/billing/preview (the list the card
already read) and POSTs {"plan_id"} to /billing/claim for each plan it
lists, with the account's ZCode jwt, X-Device-Mid, X-ZCode-App-Version and
X-Platform, as kongbai01203 captured them. The claim is judged by the body's
code: 0 claimed, 1003 "target already exists" (HTTP 200) done, 3007 or a
captcha message "captcha" (claim it in the ZCode app), anything else, an
HTTP error without a code or a body that isn't JSON failed. A failed read is
never taken as claimed, and no answer carries signIn, so a failed claim
leaves the account as it was. Nothing listed is inactive; a key-only
account is ineligible; an expired ZCode session is failed with no request.
A plan claimed now drops the account's cached route, so the next request
uses it. One failed among several makes the whole answer failed (with the
claimed ones named), so magpie asks again later and the claimed ones then
answer 1003.

Run (on mote, HOME=$(mktemp -d)): `bun test` in packages/zcode, 150 pass;
the whole repo's `bun test`, 3698 pass 0 fail of 3706 across 297 files;
`bun scripts/check.mjs zcode` ok. checkin.test.mjs covers preview empty,
one plan claimed with code 0 (request body and headers checked), 1003,
3007, seven unreadable claim answers, five unreadable previews, one
claimed + one failed then asked again, and key/expired accounts asking
nothing. Broken by hand: 1003 -> claimed and an unreadable reply ->
claimed turned three of these tests red; put back, green.

Not tried: a real claim that answers code 0. No account has a plan to
claim right now (every preview answers plans: []), so the code 0 body is
a fixture carrying only its code, and nothing else of it is read. On
10-06 a claim without the ZCode app's Aliyun captcha was answered 400
code 3007 (#30); if ZCode still asks that for a fresh plan, the check-in
says "captcha" and the plan is claimed in the app, as before. The real
1003 reply is in the tests as captured.
2026-10-30 08:24:30 +08:00
yetone 3b3209e0dd zcode 0.1.34: a gift plan that starts later is named with its start, and gift buckets beside a Coding Plan carry their plan's name
windy (Discord): "添加zcode供应商的时候,好像无法区分Coding Plan 和Start Plan的额度?
例如今天23点要生效的Start Plan就没显示".

- A plan on /billing/balance whose starts_at is still to come serves
  nothing yet: startPlan no longer routes to it (an "active" plan with a
  future start would have been), and its buckets don't count. The card
  names it in an aside line "ZCode gift plan not started yet", display
  "<plan> · <start in local time>", soonest first.
- A coding account with a ZCode session reads the gift on every card
  read, not only while a gift is live, so a coming plan shows beside the
  Coding Plan. The route cache is read again when the coming plan starts.
- A gift-only account whose only plan starts later gets a card with that
  line instead of "ended or never started".
- Beside a Coding Plan, every gift bucket is prefixed with its plan's
  name ("Start Plan · GLM-5.1-Trial"), one plan or several.

Not known: which status ZCode gives a plan that hasn't started. The
fixtures use starts_at as the real balance/preview replies carry it
(Unix seconds) and try both "active" and an unknown status word; any
status but "expired" with a future starts_at is taken as coming. No
real account with a pending plan was read.

Run on mote: HOME=$(mktemp -d) bun test in packages/zcode, 142 pass
0 fail; pending.test.mjs under TZ=UTC, Pacific/Kiritimati and
America/Los_Angeles, 7 pass each; bun scripts/check.mjs, every package
ok. Broken by hand: with the old index.mjs, 6 of pending.test.mjs's 7
tests fail (the 7th, a plan whose start has come, passes on both).
2026-10-29 22:31:07 +08:00
yetone 2ef8b8b5ef zcode 0.1.33: a ZCode 3.16 sign-in lists its coding plan's models, GLM-5.3 among them (#439)
provider.models read the "as ZCode" sign-in without located(). ZCode
3.16 keeps only where the coding plan key is (project-key-location:v1,
#410), so the state had no key, plansOf took it for a Start Plan
sign-in, and the list was account:zai-start-plan's: GLM-5.3 left out
and delisted, while requests and usage (which call located) worked.
models() now reads the key first, as the request path does. A key that
can't be read throws, so magpie keeps the list it had instead of being
told the Start Plan's.

Reported, with the cause and this fix, by dinghao-8.

Run (TMPDIR/HOME sandboxed, Bun 1.4.2):
- bun test in packages/zcode: 135 pass, 0 fail; bun scripts/check.mjs
  exit 0.
- Broken by hand: the new own.test.mjs case against main's index.mjs
  fails with exactly the reporter's list, [GLM-5.3-Flash, GLM-5.2,
  GLM-5-Turbo].
- npm had 0.1.32; this is 0.1.33.

Not tried: a real ZCode 3.16 account (reading ZCode's credentials needs
the Keychain secret); the reporter ran the same one-line patch end to
end against BigModel.
2026-10-27 23:41:59 +08:00
yetone 9c886c12f9 zcode: a cap that outlasts the waits still rests the account, the README says
#395's README said busyAnswer lets magpie "move that request along
instead of resting the account". It doesn't: on magpie origin/main
e7173958e, failure(429, body) reads both ZCode's bare
{"code":3008,"msg":"user concurrency limit exceeded"} and busyAnswer's
rewording of it as "rate", so the account rests and the request falls
to the next group member, as before #395. The retry and the declared
maxConcurrency are what keep the cap from reaching magpie; the README
now says so. README only, no version change.

Run: the probe above (a throwaway test in magpie's internal/gateway,
removed); bun scripts/check.mjs zcode ok.
2026-10-27 11:21:35 +08:00
ANDY-JK 8b21033daa zcode 0.1.32: a plan's cap refusal is asked again, with no gate of the plugin's own (#395)
ZCode answers 429 with code 3008 "user concurrency limit exceeded" or
3009 "model concurrency limit exceeded" when one account has more in
flight than its plan serves. Such a refusal is now asked again, the same
bytes, after 250ms, 500, 900, 1600, 2800 and 4000 (jittered); one that
outlasts the waits goes on as a 429 with ZCode's words and what they
mean (busyAnswer). spentUp no longer counts 3008/3009 as a spent gift.
maxConcurrency: 3 is declared on the auth hook and as
magpie.maxConcurrency, as a default magpie's per-account queue applies
and a user can raise; the plugin keeps no gate of its own.

By ANDY-JK. Reviewed at 8dc0b8dade49001b3a0e89b5e26fd674e8657694, applied
onto main bf8faa2 (no zcode change on main since the branch's base):
- TMPDIR/HOME sandboxed, Bun 1.4.2: bun test in packages/zcode, 134 pass,
  0 fail; bun scripts/check.mjs exit 0.
- PR CI (pull_request run 40323330525, merge ref): test and on-npm green.
- Broken by hand: busy() out of spentUp fails "the cap's own codes are
  not a gift spent"; cap forced false fails the retry and outlasts-the-
  waits tests; busyAnswer replaced by the plain body fails the latter;
  concurrency.test.mjs against main's index.mjs fails at import.
- magpie origin/main e7173958e: host.js concurrencyOf reads both
  declared sites. failure() reads the cap refusal as "rate" both before
  and after busyAnswer, so a cap that outlasts the waits still rests the
  account a minute as before; the README's "instead of resting the
  account" is corrected in a follow-up.
- npm had 0.1.31; this is 0.1.32.

Not tried: a real ZCode account (the author measured one Z.ai gift-plan
account through magpie's gateway, numbers on the PR).
2026-10-27 11:20:36 +08:00
yetone d2ada161cc zcode 0.1.31: ZCode 3.16's key location gives the coding plan its key (#410)
ZCode 3.16.3 on a Mac keeps no coding plan key in credentials.json or
config.json, only a project-key-location:v1 record
({organizationId, projectId, apiKeyId}, encrypted like the rest). With no
key, plansOf sent the account to the gift and the BigModel GLM Coding Plan
never showed (meraki7304).

ownSignIn now reads that record (the account's own: team null, coding
plan, the profile's user id, the family ZCode is on first), and located()
reads the named key's secret from api_keys/copy/{apiKeyId} with the OAuth
token, as ZCode lists keys (BigModel bare, Z.ai as a Bearer). Only GET:
nothing is created. The record's origin is used only when it is an https
z.ai / bigmodel.cn host, else the site's own API. A 404 leaves the sign-in
as before; another failure says sign in again. Request fetch and usage
resolve it before plansOf.

Record format and auth forms read from ZCode 3.16.3's own app.asar
(ProjectAccessTokenClient / project-key-location:v1).

Run: HOME=$(mktemp -d) bun test in packages/zcode, 119 pass;
bun scripts/check.mjs ok.
Red on old code: the new own.test.mjs case fails with the old index.mjs
(key "" and start true).
Not tried: a real ZCode 3.16 account (no vendor credentials used); the
reporter's read-only check of the same endpoints is the evidence.
2026-10-26 16:03:20 +08:00
wendyeq 2b56b3bc4f zcode: name the conversation in x-session-id as a bare UUID, so BigModel's prompt cache hits (#388)
ZCode's client names every request's conversation in x-session-id: a bare
UUID, the same on each turn (3.14.3 xst/Tst). BigModel keeps a prompt's
cache for the requests that name the same session. The plugin sent none,
so a long conversation seldom hit the cache (#387). Every zcode request,
on the Start Plan and on Coding Plan or team seats alike, now carries it:
- the agent's session (chat.headers' sessionID, which magpie fills) goes
  as it is when it is a UUID, lower-cased;
- any other id (magpie-<hex>, ses_..., sess_...) goes as a stable UUID
  made from its sha256;
- with no session, a UUID made from the device.
metadata.user_id's session_id is the same UUID, in dress() and marked().

Reviewed at 48013c0, which addresses all four points of the earlier
review (UUID shape, session_id in user_id, rebase onto 0.1.30, no
"Closes #387"):
- TMPDIR=<scratch> HOME=$(mktemp -d) bun test in packages/zcode: 125
  pass, 0 fail. bun scripts/check.mjs zcode passes. Merges cleanly onto
  main.
- With main's index.mjs and the PR's tests: 17 fail (all 7 new session
  tests, plus the start, userid and dual assertions on the header).
- Probe through the plugin's chat.headers and loader fetch, as magpie's
  host calls them (host.js passes sessionID and sets out.headers before
  the fetch): magpie-<hex> twice gives the same UUID in the header and
  in user_id.session_id, and ses_other gives a different UUID. None
  contains magpie, ses_ or sess_.

Not tried: a real BigModel request (the author's hit-rate numbers are the
evidence: 3/12 before, 24/24 after through magpie).
2026-10-26 16:02:38 +08:00
yetone 57598ad410 zcode 0.1.30: a coding plan's requests name the device in metadata.user_id, as ZCode's do (#387)
wendyeq measured BigModel's GLM Coding Plan through magpie hitting the
prompt cache 1 time in 19 without metadata.user_id and 13 in 16 with it;
the official ZCode on the same account reads 95-98% of input from cache.
The plugin only put user_id on the Start Plan's dressed body; a coding
plan or team request went as the agent sent it, and Pi sends none.

ZCode 3.14.3 (glm/zcode.cjs) sets it on every Anthropic-format request,
not only the Start Plan's: Pst() returns MLs({deviceMid, sessionId}) for
any providerKind "anthropic", and vWr() puts it in
providerOptions.anthropic.metadata.userId for both generateText and
streamText. The value is {"device_id":<machine id>,"account_uuid":"",
"session_id":...}.

Now a coding plan or team request to .../v1/messages gets
metadata.user_id = {"device_id":<sign-in's saved device>,
"account_uuid":"","session_id":""}, the same value dress() puts on the
Start Plan's, when the agent sent no user_id of its own; other metadata
is kept and content-length dropped when the body changed. count_tokens
and non-Messages bodies go as they were. An account known only by a key
(a pasted API key, or a saved state with no device) gets a device id
hashed from the key, so it is the same on every start rather than
anyDevice, which was new per process.

Differences from ZCode, kept on purpose: ZCode overwrites any user_id
and fills session_id with its session (sess_ prefix stripped); this
keeps an agent's own user_id and sends session_id "" as dress() does,
one stable value per account.

Tests: userid.test.mjs (new, 6 tests; 5 red on origin/main's index.mjs,
the count_tokens one passes there as it should). start, toolsearch and
dual tests that pinned coding plan bodies byte for byte now expect the
agent's body plus the device's user_id.
Run at this tree: HOME=$(mktemp -d) bun test -> 2672 pass, 1 skip,
0 fail across 229 files; bun scripts/check.mjs ok.
Not tried: a real BigModel or Z.ai coding plan request, so the cache
hit rate after the change is the reporter's measurement, not mine.
2026-10-25 18:25:51 +08:00
yetone 5c9b7a4137 zcode 0.1.29: a sign-in keeps the account's user id beside its name
wakkana on Discord reported WorkBuddy accounts of one name collapsing
into one. WorkBuddy's plugin already keeps a uid, which magpie's plugin
host tells same-name accounts apart by. ZCode names an account by email,
else by its name, and gave no uid, so two ZCode accounts with no email
and one name were one account in the host. Both sign-ins (browser and
the ZCode app's) now give uid: user_id. The app's entry also follows
ZCode only while ZCode is signed in to the same user id, not another
account of that name.

Run: HOME=<scratch> TMPDIR=<scratch> bun test in packages/zcode, 112
pass. Both new tests (own.test.mjs, team.test.mjs) fail with index.mjs
from HEAD (uid undefined). bun scripts/check.mjs green.
Not tried: a real ZCode sign-in; whether ZCode's poll user carries
user_id is read from who(), which already reads it.
2026-10-25 17:37:19 +08:00
yetone 2d59003f8e zcode: the team seat's request test uses a key of its own
start.test.mjs's "a team seat's request goes as the agent sent it" used
key "team.secret", the same as team-gift.test.mjs. In one bun test
process the two files share index.mjs's routes cache (key + jwt), and
when both jwts were built in the same second the seat test read
team-gift's cached route, skipped the billing/balance read and saw 1
request where it expects 2. That kept publish.yml red since ba343b8, so
zcode 0.1.28 (and every other package) never published.

Run: with both files' jwt exp pinned to one value, `bun test
./team-gift.test.mjs ./start.test.mjs` fails the seat test on the old
key and passes 19/19 with "seat.secret". Whole-repo `bun test` (HOME
under TMPDIR, as CI): zcode all pass; the 20 reds are gcp-ai's, which
another session is fixing. `bun scripts/check.mjs` ok.
2026-10-25 14:38:06 +08:00