all: a usage read says what it means for the sign-in, and a renewal clears the mark whatever follows, as the built-ins did (要保证插件跟内置的所有逻辑都要一模一样) — auth.usage returns signIn on every path: expired where the built-in's quota read marked the account (Zed's /users/me 401, Factory's and MiMo's refused renewals, Qoder's refused job refresh), renewed after a renewal, which took the mark off, kept everywhere else, so magpie no longer guesses from the words 'sign in again' (Kiro's, Devin's and ZCode's usage errors marked accounts their built-ins never did) nor clears on a clean read. A request after a renewal says renewed on any status; one without says kept, as the built-ins cleared only on renewal. Kiro, Cursor, Devin, Command Code, WorkBuddy, Grok and ZCode, whose built-ins never marked an account, say kept on every answer. New tests fail against 85d7dd0's index.mjs.

This commit is contained in:
yetone
2026-10-01 04:53:29 +08:00
parent 85d7dd0d0a
commit 01aee5da28
31 changed files with 541 additions and 229 deletions
+7 -5
View File
@@ -1096,9 +1096,8 @@ export async function ZCodeAuthPlugin({ client }) {
h.set("x-api-key", key)
h.set("Authorization", "Bearer " + key)
const res = await fetch(url, { ...opts, headers: h })
// the plan's 401 goes on as it came: the built-in never
// marked a ZCode account lapsed
if (res.status !== 401) return res
// the plan's answer goes on as it came, the account kept: the
// built-in never marked a ZCode account lapsed nor cleared one
const kept = new Headers(res.headers)
kept.delete("content-length")
kept.delete("content-encoding")
@@ -1107,17 +1106,20 @@ export async function ZCodeAuthPlugin({ client }) {
},
}
},
// the plan's allowance, as magpie's built-in showed it
// the plan's allowance, as magpie's built-in showed it. Each read
// keeps the sign-in (signIn): the built-in's marked no account lapsed,
// its expired Start Plan sign-in among them, and cleared none
async usage(getAuth, provider) {
const auth = await getAuth()
const s = stateOf(auth)
if (!s) return { error: "not signed in" }
if (!s) return { error: "not signed in", signIn: "kept" }
// every card starts from the plan the sign-in saved, as magpie's
// built-in did: a reply without a level, a team detail that
// failed or an error keeps it
const saved = (out) => {
const plan = s.plan || auth?.plan
if (plan && !out.plan) out.plan = plan
out.signIn = "kept"
return out
}
try {