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.
This commit is contained in:
yetone
2026-11-14 18:17:21 +08:00
parent da17052c0c
commit 1dbbc1fb48
4 changed files with 96 additions and 6 deletions
+6 -2
View File
@@ -350,8 +350,12 @@ menu bar pass it over. The name is a fixed sentence magpie can
translate; the count and the plan's own name are the display. Reading
the card never claims one. A preview that fails, or lists nothing, adds
no line at all, and a card that is an error keeps its error. Claim the
plan in the ZCode app (open it once), or let the daily claim below do it;
the next read shows it as an ordinary gift bucket.
plan in the ZCode app (open it once); while ZCode asks its security check
for a claim, as it does now, the daily claim below posts none. The next
read shows it as an ordinary gift bucket: its `-Trial` entry is listed and
free first spends it. Until then a `-Trial` pick that finds no gift is
refused with the held plan's name and "claim it in the ZCode app", not
only "no active limited quota" (heduian and bg5eau on X, 11-14).
## The daily claim
+64 -1
View File
@@ -1,6 +1,6 @@
import { afterEach, beforeEach, expect, spyOn, test } from "bun:test"
import { homedir, tmpdir } from "node:os"
import { realpathSync } from "node:fs"
import { readFileSync, realpathSync } from "node:fs"
if (![tmpdir(), realpathSync(tmpdir())].some((t) => homedir().startsWith(t))) throw new Error("run in an isolated home")
const { ZCodeAuthPlugin, _internal } = await import("./index.mjs")
@@ -481,3 +481,66 @@ test("a gift-only account lists only the models its balance names (young02036)",
_internal.config(undefined)
}
})
// heduian and bg5eau on X (11-14): on a weekend the GLM-5.3-Flash-Trial
// pick answered only "no active limited quota". The weekend plan
// (ZCODE WEEKEND BUILD, testdata/touch-1030-wk.json, the feed's real
// reply) is a gift ZCode holds until it is claimed, and its claim needs
// the ZCode app's captcha, which the plugin doesn't post. The refusal
// now names the held plan and where it is claimed; it still asks no
// model and posts no claim, and the feed is read once for a retry.
test("a -Trial pick with no gift names the weekend plan ZCode holds unclaimed", async () => {
const touch = readFileSync(new URL("./testdata/touch-1030-wk.json", import.meta.url), "utf8")
balance = { server_time: now, plans: [], balances: [] }
_internal.unclaimedSeen.clear()
const asked = []
const base = globalThis.fetch
globalThis.fetch = async (input, init = {}) => {
const url = new URL(input instanceof Request ? input.url : String(input))
if (url.pathname === "/api/v1/marketing/touch") {
asked.push((init.method ?? "GET").toUpperCase())
return new Response(touch, { headers: { "content-type": "application/json" } })
}
if (url.pathname === "/api/v1/zcode-plan/billing/claim") throw new Error("a claim was posted")
return base(input, init)
}
for (let i = 0; i < 2; i++) {
const res = await send("GLM-5.3-Flash-Trial")
expect(res.status).toBe(400)
const { error } = await res.json()
expect(error.message).toStartWith("ZCode has no active limited quota for GLM-5.3-Flash-Trial. ")
expect(error.message).toContain("ZCODE WEEKEND BUILD")
expect(error.message).toContain("claim it in the ZCode app")
}
expect(asked).toEqual(["GET"])
expect(sent).toHaveLength(0)
})
test("a -Trial pick with no gift and nothing held says only that there is none", async () => {
balance = { server_time: now, plans: [], balances: [] }
_internal.unclaimedSeen.clear()
const base = globalThis.fetch
globalThis.fetch = async (input, init = {}) => {
const url = new URL(input instanceof Request ? input.url : String(input))
if (url.pathname === "/api/v1/marketing/touch") return ok({ deliveries: [] })
return base(input, init)
}
const res = await send("GLM-5.3-Flash-Trial")
expect(res.status).toBe(400)
expect((await res.json()).error.message).toBe("ZCode has no active limited quota for GLM-5.3-Flash-Trial")
expect(sent).toHaveLength(0)
})
test("a -Trial pick whose feed doesn't read says only that there is none, and asks the feed again", async () => {
balance = { server_time: now, plans: [], balances: [] }
_internal.unclaimedSeen.clear()
let reads = 0
const base = globalThis.fetch
globalThis.fetch = async (input, init = {}) => {
const url = new URL(input instanceof Request ? input.url : String(input))
if (url.pathname === "/api/v1/marketing/touch") return reads++, new Response("bad gateway", { status: 502 })
return base(input, init)
}
for (let i = 0; i < 2; i++) expect((await (await send("GLM-5.3-Flash-Trial")).json()).error.message).toBe("ZCode has no active limited quota for GLM-5.3-Flash-Trial")
expect(reads).toBe(2)
})
+25 -2
View File
@@ -715,6 +715,28 @@ async function claimHint(s) {
return { name: CLAIM_HINT, used: 0, aside: true, display: `${n} · ${plan}` }
}
// unclaimed names the gift plans ZCode holds for the account but has not
// put on it (toClaim), for a -Trial pick that finds no gift: the weekend
// plan (ZCODE WEEKEND BUILD) comes only by a claim, and the claim needs
// the ZCode app's captcha (claimDaily posts none), so until it is
// claimed in the app the pick's quota does not exist yet (heduian and
// bg5eau on X, 11-14). The refusal says where the quota is rather than
// only that there is none. Kept ten minutes per session, so an agent
// retrying the pick doesn't read the feed each time; a read that fails
// names none and is not kept.
const unclaimedSeen = new Map()
async function unclaimed(s) {
if (!s.jwt || jwtExpired(s.jwt)) return []
const k = s.jwt
const c = unclaimedSeen.get(k)
if (c && Date.now() - c.at < 600_000) return c.names
const got = await toClaim(s).catch(() => null)
if (!got || got.unread.length) return []
const names = uniqueModels(got.plans.map((p) => first(p.name, p.plan_id)).filter(Boolean))
unclaimedSeen.set(k, { at: Date.now(), names })
return names
}
// ---- the daily claim ---------------------------------------------------------------
// CLAIMED_ALREADY is /billing/claim's body code for a plan the account
@@ -3119,7 +3141,8 @@ export async function ZCodeAuthPlugin({ client, magpie } = {}, options = {}) {
const raw = giftModel(gift, m)
const available = raw && giftUsable(s, gift, raw)
if (!available) {
const error = { type: raw ? "rate_limit_error" : "invalid_request_error", message: raw ? `${giftRested(s, raw) ? `ZCode said the last request for ${raw} was over its quota, so it is not asked again for a minute: ` : ""}ZCode's limited quota for ${raw} is exhausted or temporarily unavailable` : `ZCode has no active limited quota for ${m}` }
const held = raw ? [] : await unclaimed(s)
const error = { type: raw ? "rate_limit_error" : "invalid_request_error", message: raw ? `${giftRested(s, raw) ? `ZCode said the last request for ${raw} was over its quota, so it is not asked again for a minute: ` : ""}ZCode's limited quota for ${raw} is exhausted or temporarily unavailable` : `ZCode has no active limited quota for ${m}${held.length ? `. ZCode holds ${held.join(", ")} for this account unclaimed: claim it in the ZCode app (its claim needs the app's security check), and ${m} spends it` : ""}` }
return kept(new Response(JSON.stringify({ type: "error", error }), { status: raw ? 429 : 400, headers: { "content-type": "application/json" } }))
}
orig = opts.body = JSON.stringify({ ...JSON.parse(orig), model: wireModel(raw) })
@@ -3501,4 +3524,4 @@ export async function ZCodeAuthPlugin({ client, magpie } = {}, options = {}) {
// config sets what zcodeConfig has read, for tests: null is ZCode's config
// out of reach, undefined forgets it
const config = (cfg) => (cfgCache = cfg === undefined ? null : { cfg, at: Date.now() })
export const _internal = { wallAnswer, unreached, planFull, notePlan, planFullUntil, locatedKeys, lastKeys, edge, EDGE_HOLD, busyHold, startGate, NARROW_FOR, limitOf, BUSY_N, BUSY_WINDOW, BUSY_HOLD, busyCap, busyHeld, config, entry, limitWindows, termOf, startUsage, routes, blocked, sidelined, plansOf, giftOf, dualUsage, claimHint, claimDaily, spentUp, giftServes, modelOf, teamKeys, ownSignIn, stateOf, located, dress, queryOf, PROMPT, marked, keyDevice, sessionOf, busy, BUSY_WAITS, DEFAULT_CONCURRENCY, DEFAULT_ACCOUNTS }
export const _internal = { wallAnswer, unreached, planFull, notePlan, planFullUntil, locatedKeys, lastKeys, edge, EDGE_HOLD, busyHold, startGate, NARROW_FOR, limitOf, BUSY_N, BUSY_WINDOW, BUSY_HOLD, busyCap, busyHeld, config, entry, limitWindows, termOf, startUsage, routes, blocked, sidelined, plansOf, giftOf, dualUsage, claimHint, unclaimed, unclaimedSeen, claimDaily, spentUp, giftServes, modelOf, teamKeys, ownSignIn, stateOf, located, dress, queryOf, PROMPT, marked, keyDevice, sessionOf, busy, BUSY_WAITS, DEFAULT_CONCURRENCY, DEFAULT_ACCOUNTS }
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@magpie-community/opencode-zcode-auth",
"version": "0.1.64",
"version": "0.1.65",
"description": "OpenCode provider plugin: signs in to Z.ai's or BigModel's (智谱) GLM Coding Plan as ZCode does, including team seats and ZCode's Start Plan, and claims its gift plans daily",
"type": "module",
"main": "./opencode.mjs",