Commit Graph
14 Commits
Author SHA1 Message Date
yetone d248efa7a1 workbuddy 0.1.34: a free account's plan is "Free plan", not "Free" (#337)
Buger2008 read the "Free" beside their WorkBuddy account in Providers as
the model they picked (Deepseek-V4.1-Flash, 0.11x) being free, and as why
routing chose WorkBuddy first. It is the account's plan; routing doesn't
read it. The label now says it is a plan. Nothing in magpie or the plugins
compares a plan to "Free" (grepped internal/ and packages/).

Run: bun test in packages/workbuddy, sandbox HOME, network at a dead
proxy: 152 pass 0 fail; on the old index.mjs the 4 tests that say the
label fail. bun scripts/check.mjs: workbuddy ok.
Not tried: a real WorkBuddy account in the GUI.
Siblings: trae ("Free", d.plan || "Free") and mimo (plan "Free") say the
same; filed as their own issue.
2026-10-25 15:06:45 +08:00
yetone f658842089 workbuddy 0.1.31: a 401 is renewed once and sent again; a refused sign-in says to sign in again
wenchen855443 on X: with WorkBuddy as the provider, requests return 401.
Until now a chat 401 was passed on as WorkBuddy's HTML APISIX page with
X-Magpie-Sign-In: kept. A token is renewed only near its end, and a
browser sign-in's token lasts about 340 days. So a token WorkBuddy
refused before then was sent again on every request, for months.
Nothing renewed it and nothing told the user what to do.

What changed (packages/workbuddy/index.mjs):
- A chat or usage summary answered 401 is renewed once, whatever the
  token's time, then sent once more. The request body is sent as it
  was, and only a body that can be resent is retried. The first 401's
  body is cancelled. A second 401 is never renewed.
- Before spending the refresh token, a newer token another process saved
  (getAuth) is taken first. This is also checked after a refused refresh,
  for the case where another process spent the refresh token at the same
  moment (part of plugins#332).
- A desktop sign-in never spends the app's refresh token here. The plugin
  drops the token it held, reads the app's file again, and retries only
  if the token there changed.
- When there is no new token, or the retry is refused too, the plugin
  answers 401 with authentication_error. The message names why ("it
  refused the refresh token too (…)", "there is no refresh token to renew
  it with", "it refused the token renewed for it too") and says where to
  sign in again: Providers → WorkBuddy [AI] → this account's Sign in again,
  or WorkBuddy desktop for a desktop sign-in. The >2 MiB ECONNRESET note
  stays in that message.
- readDesktop marks its result source: "desktop". Before this,
  unanswered's desktop wording could never show.

Marking the account expired:
- The plugin sends X-Magpie-Sign-In: expired (usage: signIn) only when
  WorkBuddy itself says the sign-in is gone:
  - the refresh token was refused (HTTP 401 / invalid_grant);
  - the access token was refused with WWW-Authenticate error=
    "invalid_token" and no refresh token was left, or one had ended;
  - a just-renewed token was refused with invalid_token.
- Why mark it at all: a marked account leaves routing, so the user's
  other accounts serve; the row says to sign in again; and a dead
  account stops spending a refresh on every request.
- Why not on every 401: WorkBuddy answers some paths with a bare 401
  even for a good sign-in (magpie's workbuddy_checkin_test). A refresh
  that fails for another reason (5xx, network) also leaves the account
  as it is.
- A desktop sign-in is never marked: the app's file is read on every
  request, so signing in to the app again fixes it.
- A success after a renewal sends "renewed", which clears a mark.
- auth.refresh (refreshed()) still never marks the account, because a
  refresh token spent by another process there could read as refused.

What WorkBuddy does (www.workbuddy.ai, 2026-10-23, the owner's real
workbuddy-ai sign-in copied into a sandbox HOME):
- Chat with a wrong or garbage token: 401, HTML APISIX page,
  WWW-Authenticate: Bearer realm="copilot", error="invalid_token".
- Chat with an empty token: 401, no WWW-Authenticate.
- The meter: the same 401. /v3/config: 200 to a bad token.
- Refresh with a wrong refresh token: HTTP 401 {"code":12153,"msg":"12153:
  refresh token failed:400 Bad Request: invalid_grant: Invalid refresh
  token"}. With garbage: 401, code 12153 "token format error".
- A real refresh: 200; both tokens rotate, and both expiries are about
  340 days out.
- The old access token still answered 200 after the refresh.
- The rotated tokens were written back to the live plugin-auth.json under
  its lock (temp + rename, only workbuddy-ai's entry changed). The live
  gateway answered workbuddy-ai/deepseek-v4.1-flash with 200 afterwards.

Run at this tree (652f06d + this change):
- HOME=$(mktemp -d) bun test: 2329 pass, 0 fail, 197 files.
- bun scripts/check.mjs: ok.
- New unauthorized.test.mjs (12 tests): renew then 200 (renewed, saved,
  new Bearer); refresh refused → sign in again, expired; transient refresh
  failure → kept; no second renew or retry; no refresh token
  (expired with invalid_token, kept on a bare 401); a token another
  process saved is taken; desktop re-read and never marked; usage renew;
  usage refused → expired.
- Existing tests that pinned the old pass-through were updated:
  signin.test.mjs, usage.test.mjs, reset.test.mjs.

Broken by hand:
- With origin/main's index.mjs, all 12 new tests are red.
- Without the renewed guard: the "isn't renewed twice" test goes red.
- With gone() always false: the 3 marking tests go red.
- Without the newer() check: the 2 "another process saved" tests go red.

Not tried:
- Reusing an old refresh token after rotation, which risks revoking the
  owner's session. Whether WorkBuddy refuses it, or revokes the session,
  is unknown.
- The China build (www.codebuddy.cn) was not probed for a real 401.
- A desktop sign-in with real accounts.
- The reporter's case is unknown: their site, their sign-in kind, and the
  401's body. So is what revokes a WorkBuddy access token before its end;
  a refresh by another process does not.
2026-10-23 22:13:05 +08:00
yetone ec8ae09cc8 workbuddy 0.1.23: credits used up leave the free models counted out, so magpie doesn't put the account last for deepseek-v4.1-flash (#138, hheei)
WorkBuddy serves a model at x0.00 (deepseek-v4.1-flash) with the account's
credits used up: hheei's account at 560 / 560 was still served it. The
usage read gave one Credits window over every model, so at 100% magpie's
routing ranked the account spent for its free models too: put behind every
other account, and moved off by conversation affinity.

The Credits window (personal and enterprise) now carries notModels: the
ids the account's live list (/v3/config) prices at x0.00. A model free only
some hours (a night promotion) still counts, as the list never says it is
free. A list that can't be read leaves the window as before. magpie reads
notModels as it does for Devin's and Cursor's windows (Limit.applies), so
For(free model) no longer sees the full window, and a 14018 on a paid model
rests only that model (Pooled), as PaidBesideFree already did.

Run: HOME=<temp> bun test in packages/workbuddy: 92 pass. Broke it by hand
(no notModels set): the two new usage tests go red. bun scripts/check.mjs
workbuddy: ok. Not tried against a real account at 100% credits; the
behaviour that free models are still served there is the reporter's.
2026-10-15 13:11:46 +08:00
yetone 169e4e607c workbuddy 0.1.19: an enterprise account's card shows its credits, from the enterprise meter WorkBuddy's usage page reads (magpie #1904, CnsMaple)
An enterprise (team) account's /billing/meter/get-user-resource-summary
answers with an empty Packages list, so the card had no window and no
error ("暂无额度数据"). WorkBuddy's own usage page reads
/billing/meter/get-enterprise-user-usage for such an account, which
answers credit / limitNum and the cycle's start and reset (UTC+8).

auth.usage now asks the enterprise meter when the summary gives no
credits, and shows a Credits window of credit used of limitNum, resetting
at cycleResetTime, with span from cycleStartTime; plan "Enterprise" when
the sign-in has none. A personal account's refusal of that meter (400
10001 "uid or enterpriseID is empty", seen on a real WorkBuddy AI account)
leaves the card as the summary said. An account with packages never asks
it.

Run: HOME=$(mktemp -d) bun test (1172 pass), bun scripts/check.mjs.
The new enterprise test uses the reporter's two answers byte for byte;
with the fallback turned off it fails (no window, plan Free). A real
personal WorkBuddy AI account's usage read through this index.mjs is
unchanged (same window, no enterprise request). Not tried with a real
enterprise account: none here.
2026-10-13 11:39:45 +08:00
yetone 9814cca34d workbuddy 0.1.18: a desktop sign-in WorkBuddy 5.6+ keeps encrypted says so and points to the browser sign-in, not "isn't signed in" (#18)
seavenlin on #18: on WorkBuddy desktop 5.8.1 the tokens in
workbuddy-desktop[-ai].info are sealed ({$wbEncrypted: 1, envelope}), so
the desktop sign-in failed as "isn't signed in" while the app was signed
in, and one made before the app sealed it fell back to the built-in list
and its chats failed.

The sealed tokens are not opened (only the app opens them; #18's way of
running the app's binary to take its key is declined). Sign-in, usage and
chats now say the app keeps its sign-in encrypted and to use the browser
sign-in. The app's file is still only read.

Run: the new test fails on the old index.mjs and passes here; HOME=$(mktemp
-d) bun test for the repo, 1155 pass 0 fail; bun scripts/check.mjs green.
Not tried with a real WorkBuddy 5.8.1 install; the file shape is the one
in #18 and seavenlin's comment.
2026-10-13 04:46:47 +08:00
yetone cb9093181d workbuddy 0.1.16: WorkBuddy AI's GLM models are text-only, so magpie's image-describing model reads their images (Yirasumi on Discord)
What: for the workbuddy-ai provider only, a model whose id starts with
glm- is listed without image input (capabilities.input.image and
attachment false), whatever /v3/config's supportsImages says.

Why: checked on 2026-10-13 with a real WorkBuddy AI account. Its
www.workbuddy.ai/v3/config marks every model supportsImages: true, but
an image sent to glm-5.3-flash, glm-5.3 or glm-5.2 is taken out by the
server and replaced with "[System reminder: the current model does not
support images. Content filtered. ...]". Its other models
(deepseek-v4.1-flash, kimi, gemini, grok, gpt) read images, and WorkBuddy
(China, copilot.tencent.com)'s glm-5.3-flash does too. Listed as taking
images, magpie sent them straight through and the model never saw them;
listed text-only, magpie's image-describing model reads them first. A
user who set the model's image support by hand in magpie keeps it
(magpie's ModelImages setting is applied over the provider's list).

Scoped by site (SITES["workbuddy-ai"].noImages = /^glm-/) and family,
not a list of three ids, so a later GLM on WorkBuddy AI is covered.

Run: TMPDIR=<scratch> HOME=<scratch>/home bun test in packages/workbuddy:
68 pass. The new test fails on the old index.mjs (glm-5.3-flash listed
with images). bun scripts/check.mjs green. Not run: a live chat through
the plugin with an image (the account check above was done before this
change).
2026-10-13 01:48:32 +08:00
yetone f0274d69f7 workbuddy 0.1.14: the Credits window says when the soonest credits left run out (runsOutAt, runsOut), for magpie's smart routing to spend those first (cdredfox on X)
cdredfox: with several WorkBuddy accounts in one smart routing group, the
account whose credits expire soonest should be used first. WorkBuddy's own
client lists each package with its end (the billing page's paid and free
package lists); the plugin now reads them too.

- /billing/meter/get-user-resource-paid-packages and -free-packages, asked
  as the client asks: PageSize 200 up to 10 pages, Status [0,3], its
  COMMODITY_CODES (without them the API answers 10001 "PackageCodes
  required"), NeedRenewInfo / today's SlicePeriod (UTC+8).
- A package's end is DeductionEndTime, else ExpiredTime, else CycleEndTime
  read as UTC+8 (the API's own DeductionEndTime for the same package says
  so). Only packages the summary counts, with credits left; the daily Free
  Plan slice (CapacityType 4, code 001) is left out, since it ends at the
  same midnight on every account.
- The soonest end goes on the Credits window as runsOutAt (RFC 3339) and
  the credits lost then as runsOut. A list that can't be read leaves both
  out; the card stands as before.

Run: HOME=<tmp> bun test in packages/workbuddy, 63 pass (3 new); with
index.mjs back at 0.1.13, 2 of the 3 new go red. Tried live on a real
WorkBuddy AI account: packagesOf + runsOutOf gave the Bonus Pack's 232.4
credits ending 2026-10-12T16:39:27Z, before Pro's 10-28T16:40:52Z, with
the Free Plan slice left out. Not tried on a CN workbuddy account (its
stored token here is stale); the paths and body are the same on both.
2026-10-11 19:39:13 +08:00
yetone 873449a2f4 workbuddy 0.1.8: the credits window tells its count, amount of limit in credits, beside its share and display — for magpie to say how many credits are used or left on the Routing page, the Usage page and the menu bar as it says the share (yetone/magpie#659). usage.test.mjs checks the count for a paid, a free and a fractional account; it fails on the old code and passes. Tried with the real WorkBuddy and WorkBuddy AI accounts in a sandbox magpie: 33.29 / 3900 and 13.47 / 2250 credits come through the host. 2026-10-03 16:40:09 +08:00
yetone ef81d34320 tests: a usage test's offline fetch is put back when its file is done, so the next file doesn't inherit it
bun test runs every file in one process, and three usage tests left
globalThis.fetch on a fake of theirs: zcode's (offline, set in a
beforeEach, never restored), kiro's and workbuddy's (offline, set at
import, never restored). A file run after them got that fake:

- minimax's tests (27/27 alone) failed 19 after zcode's usage test: the
  plugin's requests to the local fake MiniMax went to zcode's offline and
  threw "no network in tests".
- qoder's cn.test.mjs takes globalThis.fetch as the real one when it loads;
  after kiro's or workbuddy's usage test that was offline, so every request
  meant for its Bun.serve stand-in threw. The CN sign-in, which polls on
  through errors, timed out at 10 s and kept polling, and the job-token test
  timed out too, so a full bun test never finished.

Each of the three now keeps the fetch it found and puts it back in
afterAll. Test-only; no package version changes. HOME=$(mktemp -d) bun
test: 341 pass, 0 fail across 42 files (8.5 s); bun scripts/check.mjs
passes.
2026-10-02 23:13:06 +08:00
yetone e2c72b2ae7 qoder 0.2.2, workbuddy 0.1.6: each model's credit rate goes to magpie (rate, rateWas), as magpie's built-ins read it (yetone/magpie 33acb6bc, v0.1.667)
magpie now shows each model's credit rate in the provider's model list and an agent's picker (01huadalang on Discord: pick the cheap models without opening Qoder or WorkBuddy); a plugin gives it beside free on each model its provider.models hook lists. Qoder and Qoder CN: rate is the price_factor (priceFactor); rateWas an active promotion's before_promotion_price_factor, else an original_price_factor above the price (Qwen3.8-Flash: 0x, 0.1x struck through); a promotion's 0 that isn't free is its price before times its discount_factor; a listing with no price gives none — the rule of internal/qoder/models.go's ModelInfo.free. WorkBuddy and WorkBuddy AI: rate is the model's credits ("x0.03" is 0.03; x0.00 stays free; an unreadable, negative or infinite rate is neither free nor rated), as wbCredits reads it.

usage.test.mjs in each package gets a test fed a fake listing / fake /v3/config (the cases of core's TestParseModelsRate and TestWBCreditsRate); both fail against the previous index.mjs and pass now. No request was made to Qoder or WorkBuddy. bun test (HOME a temp dir) and bun scripts/check.mjs pass.
2026-10-02 22:54:55 +08:00
yetone 01aee5da28 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. 2026-10-01 04:53:29 +08:00
yetone 0b425bee69 workbuddy 0.1.4: every refused meter status is an error with words, Go's http.StatusText in full (a 409 was an empty error), "HTTP <n>" for one Go has none for; a refusal in WorkBuddy's own {code, msg} reads its msg before the hint, as wbExplain's; a chat body handed over as bytes is read, so it still gets WorkBuddy's system message 2026-10-01 03:05:22 +08:00
yetone c8f4d448df Parity with magpie's built-ins: a failed sign-in says why, CLI-backed Command Code and Devin accounts follow the CLI's key, Factory's refused renewal is a 401 in the caller's API shape
- every {type:"failed"} carries an error reason magpie shows
- commandcode/devin: accounts taken from the CLI are marked metadata.cli and re-read its credentials on each request, usage and models
- factory: a refused refresh answers 401 authentication_error (Anthropic shape on /llm/a/, OpenAI's elsewhere) instead of throwing; the whoami back-off is per account; 403 hints name the account to sign in again
- versions: factory/devin/commandcode/cursor/kiro/mimo/zed/zcode 0.1.2, workbuddy 0.1.3
2026-10-01 00:55:50 +08:00
yetone 8c419105c0 workbuddy 0.1.2: usage shows as magpie's built-in did — plan, period, windows and what they count, balanceworkbuddy 2026-09-30 23:03:10 +08:00