Commit Graph
57 Commits
Author SHA1 Message Date
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 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
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
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
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 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
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
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 b07478285c zcode 0.1.28: a key's route is read again with each card read, after a Start Plan refusal, and a minute after one list without its plan (#369, #379)
Also publishes #371 (a team seat lists the person's gift plans and their
-Trial models, 935ddb5), which landed without a version bump.

#369: a BigModel GLM Coding Plan account got the Start Plan's 405 for about
seven minutes on plain models, then recovered with nothing changed. A plain
model goes to the Start Plan only when plansOf says start, i.e. the key's
/api/biz/subscription/list read with no VALID plan, and that answer was
kept for ten minutes. Now:
- a key whose list reads no plan where the last read found one keeps that
  for a minute, not ten (read the same way again, it is known: ten);
- a Start Plan refusal (405 / 3012 / block page) on a key account that
  wasn't a -Trial pick drops the route, so the next request reads the
  plans again.
Not known: what the list answered during the reporter's window; this is
the one path in the plugin that sends a plan-holding key's plain model to
zcode.z.ai, and it matches the window's length.

#379: the card's numbers are read fresh on every usage call already; what
lagged was the route (which plan, which gift) for up to ten minutes. Each
usage read now reads the route again, so routing follows what the card
shows.

Run: packages/zcode, Bun 1.4.2, sandbox HOME and TMPDIR: 110 pass, 0 fail.
The three new dual.test.mjs cases are red on 0.1.27+935ddb5's index.mjs
(3 fail). bun scripts/check.mjs zcode ok. Loaded through magpie's plugin
host (origin/main 4dfd88206, scripts/try.sh, sandbox HOME): zcode listed
with 4 models.
Not tried: against a real account; no account was in the sandbox.
2026-10-25 14:25:56 +08:00
yetone 28f9cbb3b2 zcode 0.1.27: the Start Plan's 405 code 3012 says ZCode's risk control blocked the account, not a network block (#348)
zcode.z.ai answers {"code":3012,"msg":"request has been blocked due to
unusual activity."} with 405. Since 10-24 many accounts get it on every
request, and on several of them ZCode's own app (3.16.3) gets the same 405;
ZCode's support bot calls 3012 platform risk control on the account. The
plugin used to put "though magpie sends it as the ZCode app does; it can
be a network block of this IP" after it, and read that JSON as the edge
firewall's page (EDGE_BLOCKED matched "request has been blocked"), so
ZCode's own words and code were dropped.

Now: ZCode's words with the status and code, then provider
ZCodeRestrictedHint word for word ("ZCode's risk control blocked this
account for unusual activity (code 3012); it rests, and the group's other
providers are used. ..."), which magpie's gateway reads as the account
restricted (2h rest, next member asked) from the next magpie release on.
Only an HTML / errors.aliyun.com block page says the network's address
(provider.BlockedHint's words).

Compared with ZCode 3.16.3's glm/zcode.cjs (downloaded from
cdn-zcode.z.ai, the latest on zcode.z.ai): the Start Plan is sent
unsigned there too (requiresClientRequestSigning is false for
zhipu-account start-plan, off-peak and highspeed; X-Client-Sig/Pow apply
to coding-plan keys on the paas origin), and the headers plugins#348's
curl shows are the plugin's set. No request difference was found that
explains 3012; not tried against a real blocked account.

Run: packages/zcode, Bun 1.4.2, sandbox HOME: 102 pass, 0 fail. The new
start.test.mjs case is red on 0.1.26's index.mjs (1 fail, the 3012
message). bun scripts/check.mjs ok.
2026-10-24 23:28:48 +08:00
yetone cc0bd902b3 zcode 0.1.26: a gift's -Trial models are listed when ZCode's config is out of reach, a failed gift read is asked again in a minute, and a card with no ZCode session says the gift needs one
bigsteven (Discord #feedback, 10-24): GLM Coding Plan spent, requests
go to it, and the model list has no GLM-5.3-Trial. Which sign-in the
account has is still asked; three ways the plugin drops a signed-in
account's -Trial entries, or drops them unsaid, are fixed here:

- ZCode's provider config out of reach (cdn-zcode.z.ai, 8s): the list
  falls back to the table and is marked magpie.fellBack, and magpie
  then keeps the list it was told last (internal/plugin/providers.go),
  from before the gift. The -Trial entries just read from the balance
  went with it. A list that carries trial entries is no longer marked.
- A gift balance read that failed was cached as "no gift" for ten
  minutes beside a good plan list, so one hiccup hid the -Trial
  entries and the gift's card section for ten minutes. It is now
  unknown and asked again in a minute (an expired session is known,
  and kept for ten).
- A key, or a sign-in whose ZCode session has expired (that token
  can't be renewed, and with a key beside it the account is never
  marked), reads no gift, so it lists no -Trial models, and the card
  said nothing. Its card now sets aside a line "ZCode gift plans
  (-Trial models) need ZCode's sign-in", with why in the display (an
  API key / no ZCode session / sign-in expired).

Run: HOME=<scratch> bun test packages/zcode: 102 pass (3 new tests);
bun scripts/check.mjs zcode ok.
Broken by hand: each of the three fixes reverted alone turns its
tests red (fellBack 1, retry 2, card line 1), restored after.
Changed on purpose: dual.test's "a gift read that fails at once still
trusts the plan list for ten minutes" now says a minute; usage.test's
key and key-only oauth cards carry the new line.
Not tried: a real account (no ZCode sign-in with a gift in this
session), nor a real CDN failure; the config fallback was forced in the
test through _internal.config(null). The new line's name is not yet in
magpie's i18n. A team-seat sign-in (an account with no plan of its own)
still lists no -Trial entries; not changed here.
2026-10-24 17:04:32 +08:00
yetone 71021b8f72 zcode 0.1.25: a key with no GLM Coding Plan says a ZCode gift plan (Start Plan, 1024 Dev Day) needs ZCode's sign-in
rtbeilin (X, 10-24) has ZCode 1024 Dev Day and no GLM Coding Plan.
"ZCode app's sign-in" works in magpie; the browser sign-in and the API
key don't.

The key: ZCode's gift plans are served by zcode.z.ai to ZCode's session
token (zcodejwttoken, the poll's `token`). A key carries none, so a key
reaches api.z.ai's / open.bigmodel.cn's coding plan alone, and a
gift-only account has nothing there. The card was empty, no error
(usage.test's own "API key, BigModel's" case: an empty list and no
limits gave {windows: []}), and each request got Z.ai's 1113 "no
resource package" with nothing saying why. Now:
- codingUsage: a subscription list read as having no VALID plan, with no
  level, no counted window and no saved plan, is the card's error
  NO_PLAN_KEY, which names the gift plans and says to add the account
  with "ZCode app's sign-in" or a ZCode browser sign-in. A list that
  can't be read keeps the card as it was.
- the fetch: a coding-plan refusal >= 400 to a sign-in with no ZCode
  session, whose code is 1113 (error.code, error.type or the envelope's
  code), keeps its status and Z.ai's words and adds NO_PLAN_KEY. The
  body is read only after the request failed. A sign-in with a session
  and any other code go as they came.
README says it under the key method.

The browser sign-in: no cause found. 3.16.3's bundle (the current
stable, downloaded from zcode.z.ai's release manifest) starts, polls
and reads the flow as the plugin does: same init body, the same
redirect / redirect_uri override, the same ready fields, Z.ai's token
exchanged at /api/auth/z/login. yg6888's screenshot in the same thread
shows two Dev Day accounts working in magpie. Not changed here.

Run:
- bun test packages/zcode, scratch HOME: 99 pass. The two new tests
  (usage "a key with no GLM Coding Plan...", signin "a key's 1113...")
  fail on 0.1.24's index.mjs. bun scripts/check.mjs zcode: ok.
- Real: the owner's real Z.ai key through the new usage hook: card
  "GLM Coding Lite", 5 hours + Weekly, no error. A bogus key: card
  "Authentication Failed", a request 401 {"error":{"message":
  "Authentication Failed","type":"1000"}} unchanged.

Not tried: a real key with no plan (none at hand), so the 1113 body is
magpie's zhipu_coding_test fixture, not a captured one. BigModel's real
answer neither. The browser sign-in with a Dev Day account.
2026-10-24 16:37:39 +08:00
yetone d1b65007ff zcode 0.1.24: Claude Code's tool search goes to ZCode's plans as ToolSearchTool, so a subagent sees Bash, Read and Write
小八 (Discord #general, 10-24): Claude Code through magpie on ZCode
(glm-5.3, glm-5.3-flash) gave subagents only the deferred MCP tools;
Bash, Read and Write were missing. Another upstream worked.

Cause, measured against api.z.ai with a real GLM Coding Plan account:
when a request's tools include one named exactly "ToolSearch", z.ai
shows the model none of the other tools except those a tool_reference
loaded. Claude Code 2.1.310's subagent request (captured from the real
binary in a sandbox HOME) has Agent, Bash, Edit, Read, Skill,
ToolSearch, DeferredToolPlaceholder (defer_loading) and Write. Input
tokens for that request: 2886 with ToolSearch, 2439 with no tools at
all, 5995 without ToolSearch. ToolSearch plus Bash also counts 2886.
Renaming the tool (tool_search, ToolSearchTool, SearchTools, ...) gives
6346, every tool counted. The anthropic-beta header changes nothing
(with or without advanced-tool-use: 2886), and neither does
defer_loading. So 0.1.22's dropped beta on the Start Plan is not the
cause; the coding plan path, which keeps the agent's headers, fails
the same way. ZCode 3.14.3's own client sends no ToolSearch tool and
no defer_loading (glm/zcode.cjs).

Now every path (GLM Coding Plan, team, Start Plan and gift) sends
Claude Code's ToolSearch as ToolSearchTool, in the tools and in the
assistant turns that called it. Tools go without defer_loading, as
ZCode's do; Claude Code sends a deferred tool's schema only after a
search loaded it. DeferredToolPlaceholder is left out. The tool_reference
results stay. The model's calls to ToolSearchTool come back to Claude
Code as ToolSearch, in a stream's content_block_start or a whole
message's content. A request without ToolSearch, or one that already
has a tool named ToolSearchTool, goes as before.

Run:
- toolsearch.test.mjs: 4 of 5 fail on 0.1.23's index.mjs (the
  passthrough test passes on both). bun test packages/zcode under a
  scratch HOME: 97 pass. bun scripts/check.mjs zcode: ok.
- Real, through the plugin's fetch to api.z.ai (GLM Coding Plan),
  real Claude Code 2.1.310 in a sandbox HOME with a stdio MCP server:
  on 0.1.23, "spawn a subagent to run ls -a with Bash" ended with the
  model saying it had no Agent tool. On this change the subagent ran
  Bash and returned the listing. A deferred MCP tool loaded through
  ToolSearch (now sent as ToolSearchTool) and was then called.

Not tried: the Start Plan against z.ai. The account's Start Plan
quota is spent (1005 exceed quota limit), so that path has only the
fake-server test. BigModel (open.bigmodel.cn) was not tried either.
2026-10-24 07:37:51 +08:00
yetone 1f8d38b8cd zcode 0.1.23: with two gift plans each bucket is named by its plan, and the live ones come first
01huadalang (Discord #feedback, 10-24): an account with the 1024 plan and
the new-user plan showed GLM-5.3 at 0 once the new-user plan's GLM-5.3 was
used up, and never showed the 1024 plan's GLM-5.3.

Cause: the plugin already kept every live plan's buckets (giftOf) and
counted a model on the live one (bestBuckets), setting the spent one aside.
But every window was named by its bucket's show_name alone, so both read
"GLM-5.3", and the windows went out in the balance's order: the new-user
plan's spent GLM-5.3 and its Flash first, the 1024 plan's after. magpie's
account row shows a card's first two windows and puts the rest in its
tooltip, so the row showed the spent GLM-5.3 at 0 and the 1024 plan's
allowance was out of sight, and where both showed they couldn't be told
apart.

Fix (startUsage and dualUsage alike): when the gift's buckets come from
more than one plan, each window is named "<plan> · <bucket>" ("ZCode 1024
Dev Day · GLM-5.3"); one plan's buckets keep their own names, as before.
The windows a request spends go before those set aside, each group in the
balance's order. A used-up plan still shows, at 100% used, set aside.

The 1024 plan's plan_id, name, show_names, capabilities and grant_units in
the new fixture are real bytes: the owner's account read
/billing/preview (read-only GET, credentials read in memory, nothing
written) and is offered "ZCode 1024 Dev Day" (zcode-v3-start-plan-1024,
GLM-5.3-Flash 300M, GLM-5.3 200M). That account has no active plan, so
its /billing/balance is empty; the balance rows are written in the shape
the existing fixtures use, and the new-user plan's name is the Start
Plan's from ganlerk's balance. The reporter's real balance wasn't seen.

Run at this head (parent efa41e3, origin/main fetched just before):
- packages/zcode: HOME=$(mktemp -d) bun test (Bun) 92 pass, 0 fail. The
  tests import bun:test, so they don't run under Node; under Node 24 the
  plugin loaded (node --check) and a scratch script ran auth.usage over the
  reporter's two-plan shape, gift-only and with a coding plan, and gave
  the labelled, ordered windows.
- Whole repo, as CI runs it: HOME=$(mktemp -d) bun test 2375 pass,
  0 fail; bun scripts/check.mjs all pass.
- Broke it by hand: index.mjs at efa41e3 turns the two new gift tests and
  ganlerk's test red (3 fail); keeping the labels but dropping the
  ordering turns both new tests red.

Changed expectations: ganlerk's test and dual.test's "every live plan"
test have two plans, so their windows now carry the plan's name.

Not tried: no account with two active gift plans was available, so no
real card with both was seen in magpie. Not changed: in dualUsage a
spent bucket set aside keeps its plain model names (startUsage drops
them); aside windows don't count, so left as it was.
2026-10-24 05:04:58 +08:00
yetone 57ec655a24 zcode 0.1.22: a Start Plan request goes with ZCode 3.16.3's headers alone, never the agent's, and without ?beta=true
01huadalang (Discord) gets 405 / "ZCode's Start Plan still turned this
request away" again on 0.1.21. #343's check was a curl request to magpie,
which carries no agent headers.

What reached zcode.z.ai: startHeaders set ZCode's headers on top of the
ones it was given and removed only x-api-key, authorization and
X-Device-Mid. A plugin provider has no account of its own in magpie's
gateway, so a request from Claude Code goes to the plugin with
Claude Code's own headers (anthropic-beta claude-code-20250219,...,
x-app: cli, x-stainless-*, anthropic-dangerous-direct-browser-access,
x-claude-code-session-id) and ?beta=true on the URL (gateway.go
claudeCodeHeader, #179). All of that went on to the Start Plan. The
retired built-in deleted anthropic-beta, and its accounts never got the
Claude Code pass-through. ZCode sends none of these on the Start Plan:
its only beta, advanced-tool-use, is for coding plans.

Now startHeaders builds a new header set: the body's content-type and
ZCode's headers, as ZCode.app 3.16.3 (the current stable, 10-23) sends
them in glm/zcode.cjs:
- buildZCodeSourceHeadersFromContext: X-Os-Version is os.release()
  alone (it was "darwin 25.2.0 arm64"), and X-Client-Timezone is
  "unknown" when there is none.
- createModelRequestAttributionHeaders: the new x-zcode-query-source:
  main_turn.
- APP_VERSION goes to 3.16.3 (User-Agent, X-ZCode-App-Version and the
  app_version query).
The Start Plan URL loses its query. Prompt texts, the Start Plan
provider entry and ai-sdk/anthropic 3.0.81 are the same in 3.14.3 and
3.16.3 (checked against both bundles). The GLM Coding Plan and team
paths are unchanged, and a new test holds that they keep the agent's
query and headers.

Not established: which header (if any) zcode.z.ai keys on. No Start
Plan account was used. A network block of the user's IP is still
possible, and the error still says so.

Run: bun test in packages/zcode under a temp HOME, 90 pass. The two
start.test.mjs header tests fail on 0.1.21's index.mjs (Claude Code's
x-app/x-stainless-*/anthropic-beta and the query reach the fake).
2026-10-24 00:44:28 +08:00
yetone 44036e2fcc zcode 0.1.21: a Start Plan request sends the agent's system prompt at the end of ZCode's third system block, not as a fourth (#343)
fordlyn's report: on a Start Plan account zcode.z.ai now answers every
request whose system has more than three blocks with 405
{"code":3012,"msg":"request has been blocked due to unusual activity."}.
dress() put ZCode's three cached blocks first and then the agent's own
system texts as blocks 4, 5, ..., so every agent (all of them send a
system prompt) was turned away; only a system-less request passed.

What ZCode does, read from ZCode.app 3.14.3's glm/zcode.cjs
(ContextBuilder.assembleSystemMessages): it sends at most three system
messages, the cli_prefix section, the stable sections, and every dynamic
system section joined with "\n\n" into a third block that starts with
"\n\n". A section added to the builder (addSection) is dynamic by
default, so ZCode's own extra system text lands in the third block.
dress() now does the same: the agent's non-blank text blocks are joined
with "\n\n" after afterEnvironment in the third block, which keeps its
cache mark. The first two blocks stay byte for byte ZCode's, as the
issue's bisect requires. GLM Coding Plan and team requests are not
dressed and are unchanged.

Run: TMPDIR=<scratch> HOME=<scratch>/home bun test (2341 pass, 0 fail);
bun scripts/check.mjs (all ok). The new #343 test in start.test.mjs and
four updated layout tests are red on the old index.mjs (5 of 12 fail).
Not tried against the real API: no Start Plan account at hand. The
reporter's own harness got 200 for this shape (system "x", system plus
tools, 32 KB system, multi-turn).
2026-10-23 23:22:58 +08:00
yetone d87dd8f3f9 zcode 0.1.20: a team's GLM Coding Plan signs in beside the account's own (#285)
An account with a GLM Coding Plan of its own and a seat on a team's plan
could only reach its own plan: signedIn took the own plan whenever there
was one and looked for a team seat only when there wasn't. ZCode itself
defaults the same way but lets the user switch its plan picker to the
team's plan (a "team-coding-plan" selection with the team's organization
and project, read from ZCode.app's bundle).

New sign-in method "ZCode: a team's GLM Coding Plan" (asks Z.ai or
BigModel, as the key method does) signs in through the same ZCode flow
and takes the team seat alone: the team project's zcode-team-api-key, as
the existing team-only route already does. It is saved under
"<email> (team)" so magpie's host keeps it as a second account instead of
replacing the own-plan account of the same email. With no seat it fails
with the reason and never falls back to the own plan. Existing sign-ins
are unchanged.

Run: TMPDIR=<scratch> HOME=<scratch>/h1 bun test (2016 pass, 0 fail);
bun scripts/check.mjs (all ok). team.test.mjs goes red (2 of 4) with the
onTeam argument dropped from the callback. Not tried against a real
account with both plans (none at hand).
2026-10-21 09:18:04 +08:00
yetone 09f946b5e6 zcode 0.1.19: a GLM Coding Plan's own resets show on the card, each with its end, a team's say so, and a Start Plan refusal says what to do, as the built-in did
What changed, for parity with magpie's built-in ZCode before it retires:

- Personal resets. The built-in's zcodeQuota read
  /api/biz/customer-package-reset/list?targetType=PERSONAL with the plan's
  key (zhipuPersonalResets, yetone/magpie#1191) and showed the count, by
  window, and each reset's end. The plugin read only the team's list.
  codingUsage now reads the personal list alongside the subscription list,
  so a Coding Plan card (and a dual gift + Coding Plan card, built on it)
  carries resets: {count, byWindow, fiveHour, weekly, until, each}.
- Team resets now carry team: true and each, as zhipuTeamResets set Team.
  Both lists are read by one resetsOf: only available ones count, each
  {until?, window} sorted soonest first with an endless one last
  (sortResetCards), nothing on a failed read or none left.
- Start Plan refusal. A Start Plan answer that is a 405, the block page
  ("request has been blocked" / errors.aliyun.com) or code 3012 / "unusual
  activity" now comes back, same status, as {type:"error", error:{message:
  "<vendor's words, or the status for a block page> — <hint>"}}, the hint
  word for word magpie's provider.ZCodeStartBlockedHint, as the built-in's
  zcodeStartExplain / Provider.Explain put it. The block page's own words
  are left out, so magpie's APIError no longer reads it as a network
  firewall's (BlockedHint). Coding Plan and team answers are untouched.
- README: the resets and the Start Plan's hint.

What was run:
- usage.test.mjs: a new test with #1191's literal reset list (the
  built-in's zhipuResetList) fails on 0.1.18 (no resets); the team test,
  now expecting team and each, fails on 0.1.18 too.
- start.test.mjs: the new refusal test fails with the startBlocked line
  disabled by hand (block page passed through), passes with it.
- Every packages/zcode test file under a scratch HOME: dual 25, gift 20,
  models 1, moved 1, own 6, signin 3, start 11, usage 16 (83 pass).
- bun scripts/check.mjs zcode passes.

Not tried: a real account's reset list or a real Start Plan refusal.
`team` and `each` reach magpie's card from its next release; older magpie
ignores them.
2026-10-16 17:36:24 +08:00
yetone 5c0aebce8f zcode 0.1.18: ZCode app's sign-in reads ZCode 3.15's plan key from config.json, so a valid GLM Coding Plan no longer reads as "no plan" (yetone/magpie#2130)
What changed: ZCode 3.15 keeps no coding plan key in credentials.json any
more. The key it uses is in config.json, at provider["builtin:bigmodel-
coding-plan" / "builtin:zai-coding-plan"].options.apiKey; ZCode 3.15.3's
host reads that value as it is. ownSignIn found no key, so a signed-in
GLM Coding Plan account fell to the Start Plan and read as having no plan.

ownSignIn now falls back to config.json (configKey) when credentials.json
has no key: Z.ai's first, then BigModel. It also takes the provider ids
3.15 normalizes to (account:*-individual-coding-plan) and a value written
encrypted. A value that isn't a key, such as "{env:...}", is skipped. A key
in credentials.json and a team switch still come first. This matches
magpie's built-in (magpie 1d8e83a79, zcodeOwn/zcodeConfigKey).

What was run:
- The new own.test.mjs case uses the reporter's layout (BigModel sign-in,
  no key in credentials.json, key in config.json). It fails without the
  fallback ("j1" in place of "bm.secret").
- Every packages/zcode test file passes under a scratch HOME/TMPDIR:
  dual 25, gift 20, models 1, moved 1, own 6, signin 3, start 10, usage 15.
- bun scripts/check.mjs passes.

Not tried: a real ZCode 3.15 account.
2026-10-14 15:45:44 +08:00
yetone 65a76769d6 zcode 0.1.17: ZCode app's sign-in follows a ZCode whose data was moved to another folder
What changed: ZCode 3.14 has a 数据存储路径 (data storage path) setting.
Changing it copies ~/.zcode/v2 to <folder>/.zcode/v2 (all but setting.json,
copyDataDirectory's filter) and from the next start ZCode reads
credentials.json and runtime/provider from there. The choice stays in the
home folder's .zcode/v2/setting.json as dataBaseDir
(readBootstrapDataBaseDirFromDisk), and setting.json itself is always read
from the home folder (getSettingsFile: ZCODE_DESKTOP_HOME_DIR, HOME,
USERPROFILE). The plugin read credentials.json and runtime/provider from
~/.zcode/v2 only, so for such a user "ZCode app's sign-in" read the stale
copy left at home (or nothing). It now reads dataBaseDir as magpie's built-in
does (magpie 41972b25f, internal/appdir ZCodeDataIn: trimmed, ignored when
empty, not a string or not absolute) for credentials.json and the
zcode-builtin.json walk, and keeps reading setting.json (the team plan)
from the home folder. The credential key's seed is unchanged: ZCode builds
it from os.homedir(), not the data folder.

Read from ZCode 3.14.3's app.asar (a copy): out/main/index.js (bootstrap),
out/main/chunk-*.js and out/host/chunk-*.js (getDataBaseDir,
getAppConfigDir, copyDataDirectory, getCredentialsFile, the settings file
under the home folder, defaultCredentialSecret).

What was run:
- moved.test.mjs (new): with dataBaseDir set, ownSignIn takes the moved
  folder's key and session over the stale home copy, and a team plan named
  in the home setting.json; "", blank, relative, number and null keep the
  home folder. With zcodeDir put back on homedir() it fails (old key read).
- HOME=$(mktemp -d) bun test at the repo root: 1185 pass, 0 fail.
- bun scripts/check.mjs zcode.
- Not run: a real ZCode with a moved folder, Windows.
2026-10-13 16:33:29 +08:00
yetone d2be892d70 zcode 0.1.16: the ZCode app's sign-in follows ZCode only while it is signed in to the same account (LingYi_Stu on X)
The app's sign-in stores the account ZCode is signed in to, and stateOf
read ~/.zcode/v2 again for every request. After ZCode switched to account
B and the app's sign-in was added again, both entries read B's
credentials: A's sent B's requests and its usage card showed B.

stateOf now follows ZCode's own credentials only when ZCode's user is the
entry's accountId. Otherwise (ZCode signed out, or on another account) it
uses the snapshot saved at sign-in, which holds the coding plan key, the
Start Plan JWT, the team project and the device. A snapshot whose JWT has
run out says EXPIRED (sign in again), as a lapsed sign-in already did,
instead of borrowing B's session.

own.test.mjs: two app sign-ins (A, then B) with ZCode on B; A's request
carries A's key and no request (messages, plan, usage) carries B's key or
JWT; and A with only an expired JWT says sign in again without sending
B's. Both fail on 0.1.15 (A sent idB.secretB; the expired case was served
with B's JWT). The first test now keeps the account's user_info as ZCode
signs in again. HOME=$(mktemp -d) bun test packages/zcode: 79 pass.
bun scripts/check.mjs zcode passes.
2026-10-12 14:41:07 +08:00
yetone baa788b1e4 zcode 0.1.15: a Start Plan request says the agent's folder, not magpie's, and leaves out what it doesn't know (#86, Hipple)
The plugin runs in magpie's plugin host, so process.cwd() is magpie's own
folder (C:\Users\<user>\.config\magpie on Windows). The Start Plan's
"# Environment" section said it as "Primary working directory", with a
constant "Is a git repository: no" and magpie's shell, and the model went
looking in magpie's folder.

Now the folder and the git state are the agent's, as magpie tells the
plugin's fetch in x-magpie-work-dir (percent-encoded) and
x-magpie-work-git (yes/no) (yetone/magpie, provider.WorkDirHeader). Each
line is left out when magpie doesn't tell it (an older magpie, an agent
that names no folder, a folder not on this computer). The Shell line is
gone: the agent's shell isn't known here. Platform and OS Version stay;
they are this computer's, as the X-Os-* headers already say. The headers
are taken off before anything is sent, on the coding plan too.

Run: bun test in packages/zcode (77 pass), bun scripts/check.mjs zcode.
With the old index.mjs the new tests fail (6 fail). One real request
through the plugin with the owner's z.ai account (coding plan; its Start
Plan balance is empty, so the dressed Start Plan path was not tried
against the real service): 200.
2026-10-11 21:36:02 +08:00
yetone aca7c59261 zcode 0.1.14: a gift-only account lists its gift's models by their own names, as ZCode does (yetone/magpie#1261)
sun1090's account has no GLM Coding Plan, only ZCode's Start Plan, whose
buckets serve GLM-5.3 (3,000,000) and GLM-5.3-Flash (5,000,000). magpie's
usage card counted GLM-5.3, but the model list had GLM-5.3-Flash, GLM-5.2
and GLM-5-Turbo (the Start Plan's providerId in ZCode's provider config,
revisions 23 and 30, which leaves GLM-5.3 out) plus GLM-5.3-Trial and
GLM-5.3-Flash-Trial, so GLM-5.3 itself was missing.

ZCode 3.14.3 (host/index.js, resolveZaiStartPlanBalanceModelIds and the
start-plan overlay's builtinModelIds) lists a Start Plan account's models
as the balance's bucket capabilities, by their own names. A gift-only
account's requests all go to zcode.z.ai's Start Plan anyway, so the plugin
now also lists each gift model under its own name for such an account.
The -Trial entries stay, so a model a user already picked keeps working;
a coding plan account's gift is still reached only through its -Trial
entries. A gift model's context, output and efforts now also come from
the coding plan's config and the fallback table, so GLM-5.3(-Trial) on
a Start Plan account gets low/high/max rather than no efforts.

gift.test.mjs: "a gift-only account lists its gift's models by their own
names" fails on 0.1.13 (GLM-5.3 undefined); it also checks every model the
card counts is listed and that GLM-5.3 goes to zcode.z.ai. "a coding plan
account's gift stays on its trial entries alone" guards the dual route.
HOME=$(mktemp -d) bun test packages/zcode (75 pass) and
bun scripts/check.mjs zcode pass. Not tried with a real Start Plan
account.
2026-10-08 16:12:53 +08:00
如是 f06dacd1ec zcode 0.1.13: the claim line's name is a sentence magpie translates; its count and plan name are the display (#43)
The claim line was a window named after the plan and displaying
"1 to claim · claim it in the ZCode app". magpie shows a window's
display as it came — quotaCount (internal/gui/assets/app.js) returns
w.display when the window has no limit — and translates only the name
(t(w.name), on the card, the tips and the chart), so the line stayed
English on a Chinese interface (yetone/magpie#1001). The plugin cannot
know the interface's language (host.js and provider.Provider hand it no
locale) and magpie's translation is keyed by the string, so the
sentence has to be the name.

The window is now named "Gift plans to claim in the ZCode app" and its
display is "1 · ZCode Trust Build": the count and the plan's own name,
which are data and stay as they came, and one name for any number, so
no plural forms are needed. aside, the placement after every real
window, and the failure handling (nothing to claim, a failed preview or
an error card add no line) are unchanged. magpie adds the zh/ja/de
entries for that name alongside this.

usage.test.mjs: the fixtures carry the new name and display, and the
names list of "a coding account's line goes after its coding and gift
windows". Four of them fail on 0.1.12; bun test packages/zcode (73
pass) and bun scripts/check.mjs zcode pass.
2026-10-08 11:52:36 +08:00
wizzy-yangandwizzy-yang c2b0462227 zcode 0.1.12: a counted window says its count as used or as left, as the share beside it is (#659) — the Coding Plan limits and the Start Plan / Trust Build buckets told only the vendor's own text, "28746939 / 100000000", so magpie's card froze that used-first count beside a "71.3% left" figure. Each counted window now carries the count as amount of limit, as WorkBuddy's credits do. usage.test.mjs: "a counted window carries what is used of the whole" fails on 0.1.11; bun test packages/zcode (73 pass) and bun scripts/check.mjs zcode pass. (#35)
Co-authored-by: wizzy-yang <wizzy-yang@users.noreply.github.com>
2026-10-07 18:46:04 +08:00
如是 bcec59ec31 zcode 0.1.11: a gift plan ZCode holds but hasn't granted is named on the card ("1 to claim · claim it in the ZCode app") (#30)
ZCode hands out one-off trust-build / gift plans that are not on the
account until the ZCode app claims them; the plugin only ever consumed
gifts already granted, so an account signed in through magpie alone sat
on the entitlement and it lapsed unclaimed (yetone/magpie#1001). The
claim itself cannot be made here: POST /billing/claim is answered 400
code 3007 "captcha verify failed" without the Aliyun captcha
attestation, and the SDK that makes it (AliyunCaptcha.js) throws unless
window and document exist, so only the app's renderer can claim one.
The author asked for the read-only half instead: ask the app's own list
(GET /api/v1/zcode-plan/billing/preview, the call the app's settings
dialog makes) while the usage card is read, and name what it lists.

The line is a window set aside, so the card shows it and routing, usage
caps and the menu bar pass it over (allowanceOf skips Aside windows;
sameAccount skips them too, so a GLM key's plan still matches the
account by its real windows). It goes last, after the coding plan's and
the gift's own buckets. A preview that fails or lists nothing adds no
line at all, a card that is an error keeps its error and asks nothing,
and an expired sign-in is no request either: the read never changes a
card or a route.

Both fixtures are real responses: an account's preview while the day's
ZCode Trust Build was unclaimed, and one after it had claimed it
(plans: []). usage.test.mjs is new (6 cases; all 72 of the package pass,
bun scripts/check.mjs zcode passes). The preview's shape is also
verified against a real account: the request goes out on the JWT with
the device id, app_version and platform the app sends.
2026-10-06 17:42:31 +08:00
yetone 6b13dc05e4 zcode 0.1.10: a gift-only account's spent bucket doesn't hold up a model another of its plans still has (ganlerk on Discord) — an account with both ZCode Trust Build (GLM-5.3-Flash 14.5% used) and the Start Plan (GLM-5.3-Flash all used) showed the Start Plan's spent bucket as counting GLM-5.3-Flash, so magpie read the model, and the account, as 100% used and sent Flash requests elsewhere. The server picks the bucket (ZCode sends no plan with a request), so a gift-only account's usage now counts each model on its live bucket, the least used, and sets spent siblings aside, as an account with a coding plan already did. bun scripts/check.mjs zcode and the zcode tests pass; the new gift test fails on 0.1.9. 2026-10-05 19:50:37 +08:00
erlinerd dbd14ccb98 zcode 0.1.9: the gift's models are trial entries the user picks, not an automatic gift-first route (#21)
Why: 0.1.8 sent every request for a gift-served model to the gift first, so a user who meant to spend the coding plan had no say, and the card hid the gift's models behind notModels. The gift is an allowance outside the plan; spending it should be a choice.

What: every model a live gift bucket serves is listed again as <model>-Trial, in the catalog's spelling (GLM-5.3-Flash-Trial), and a request for that entry goes to the gift dressed as ZCode's own; a plain model always spends the coding plan. A trial entry whose bucket is spent or blocked answers 429 without touching the coding plan, as do the gift's quota errors (1113, 1005 inside a 200); any other gift answer goes on as it came. The usage card names the gift window by its trial model, drops the plan prefix, and puts MCP - Month last.

Tests: dual.test.mjs rewritten for the new routing (a plain model to the coding plan whatever the gift holds, a trial entry to the gift), usage.test.mjs and gift.test.mjs follow the naming; bun test (65 pass in the package, 516 in the repo) and bun scripts/check.mjs zcode pass.
2026-10-05 14:24:17 +08:00
erlinerd d22ac2039a zcode 0.1.8: spend an account's gift plans before its GLM Coding Plan, and show both on the usage card (#19)
Why: a GLM Coding Plan account can also hold gift plans from ZCode
activities (a "Trust Build" grant, say). They lapse on a fixed date, and
every request went to the coding plan, so their allowance went unspent.

What: plansOf now reads the gift's balance (per the ZCode session, kept
10 minutes) and takes the union of the models every live bucket of every
active gift plan still serves (not expired, remaining_units > 0). A
request for a model the gift serves goes to the Start Plan first, dressed
as ZCode's own client; when the gift can't serve it — any answer 400 or
over, or its quota error inside an HTTP 200 (code 1113/1005) — the
request is replayed once to the coding plan as the agent sent it. Only a
quota answer keeps that model off the gift for a minute; a 405 refusal is
asked again next request. The usage card shows the coding plan's windows
and the gift's buckets together, each bucket prefixed with its plan's
name; a gift read that fails leaves just the coding card. A pure gift
account (no coding plan) behaves as before.

Tests: dual.test.mjs, 14 tests — routing, replay, the 60s quota block,
the 200-with-quota-error case, stream passthrough, an expired ZCode
session, the cache TTLs, a multi-plan union and a gift-only account;
HOME=$(mktemp -d) bun test (37 pass) and bun scripts/check.mjs zcode pass.
2026-10-04 20:04:08 +08:00
yetone cc57432d16 zcode: Start Plan requests go as ZCode's own, with its headers and system prompt (0.1.7) (#5)
ARNO on Discord: the plugin's Start Plan requests were answered 405 / 3012
"blocked due to unusual activity" while his own plugin (Freeflow, provider
zcode-start) worked from the same machine. zcode.z.ai serves the plan only
to what looks like ZCode's own request: a Start Plan request now carries
ZCode's headers and its body is dressed as ZCode's (three cached system
blocks, the environment section, the date reminder as the first turn, one
cache mark on the last block, metadata.user_id naming the sign-in's
device). The prompt texts are magpie's (901fd87e), each matching ARNO's
plugin's hash. Coding Plan and team requests are unchanged. The Start Plan
is advertised again.
2026-10-02 19:28:42 +08:00
yetone bd5e91ee00 zcode: stop advertising ZCode's free Start Plan — zcode.z.ai serves it only to requests carrying the official ZCode client's system prompt and answers others HTTP 405 'request has been blocked due to unusual activity'; the plugin, like magpie, never rewrites prompts or poses as the official client, so the plan can't be used through it. registry.json's summary (en/zh), the root README's table, the package's description and its README now name the GLM Coding Plan and team seats only, and the package README says why the Start Plan isn't usable. Text only; no code or version change. 2026-10-01 23:11:00 +08:00
yetone 7b70b40c7b zcode 0.1.6: ZCode's config out of reach, the plugin's table stands in marked Symbol.for("magpie.fellBack"), and magpie keeps the list it was told last, as the built-in keeps the one it fetched last. models.test.mjs (passes on Linux with no ZCode installed; with ZCode.app on macOS its own config is read, unmarked). 2026-10-01 17:06:07 +08:00