Commit Graph
27 Commits
Author SHA1 Message Date
yetone 311d62867c workbuddy 0.2.20: extra credits only the detail lists have say when they lapse on the window routing reads (Kayphoon)
Kayphoon on Discord asked that routing spend the WorkBuddy CN account
whose extra-credit packs expire first, before they lapse. magpie's smart
routing already does that (Allowance.Renewal, Lapse and Pace read a
window's runsOutAt/runsOut), and the plugin already put the soonest lapse
of the summary's packages on the window that stops the account. But
extra credits that only the detail lists have (listedExtra, the China
free-account shape from jiabubu's report, 0.2.17) said their lapse only
on their own "Extra credits" window, which is set aside, and routing
reads no window set aside. So for those accounts routing knew no expiry
at all.

Now the soonest of them to lapse is also put on the Credits window, when
it is sooner than what that window already says (summed when the same).
Per-pack expiry isn't sent: routing only orders accounts by the soonest
lapse and how much lapses then, so a list would change no choice.

Run at this head (mote, HOME under TMPDIR): bun test packages/workbuddy,
318 pass 0 fail; bun scripts/check.mjs ok.
Broken by hand: the same usage.test.mjs with the old index.mjs fails the
jiabubu-shape test at the new assertion (Credits has no runsOutAt).
Not tried: a real WorkBuddy CN account with expiring packs; the fixture
is CN_FREE's shapes, not Kayphoon's bytes.
2026-11-03 16:53:50 +08:00
Kunghim 33bb5fb2ef workbuddy 0.2.19: the China build's windows are named after their model and say they are estimates (#663)
By kunghim (#663). Squashed at the reviewed head 42b01b3 (the PR's f2a1233,
origin/main merged in, and the review's 0.2.19 bump: #657 had already
published 0.2.18).

workbuddy 0.2.17 -> 0.2.19:
- The China build's token window is no longer called "Free model tokens":
  there deepseek-v4.1-flash is charged x0.11 credits (testdata/config-561.json,
  copilot.tencent.com's /v3/config; WorkBuddy AI's is x0.00). Its card is
  named "deepseek-v4.1-flash tokens (est.)", its text reads "151.5M / ~200M",
  and its unit is empty (the name says tokens).
- The China windows are a table, CN_ESTIMATED_WINDOWS, one entry per
  measured model ({provider, model, aliases, cap, name, short, unit}).
  freeWindowOf, ofAccount and freeWindowRows take the model from the entry;
  the parse-cache key carries the model too.
- WorkBuddy AI's card is unchanged (Free model tokens, 1e8, "tokens").
- Both stay set aside (shown, not routed on); a refusal still pins the card
  full. Routing in magpie reads the card's models/aside/refused, not its name.
- README: the China windows section; the review fixed one line that said the
  numbers carry "tokens (est.)" (only the name does).

Run at 42b01b3 on mote (macOS, bun 1.4.2), HOME=$(mktemp -d):
- bun test (whole repo): 4900 pass, 14 skip, 0 fail (4914 tests, 374 files).
- bun scripts/check.mjs: exit 0, 41 packages + registry ok.
- packages/workbuddy bun test: 318 pass, 0 fail (node --test n/a: the
  package's tests use bun:test).
- magpie's real host.js (origin/main) under bun, sandbox HOME, the package
  loaded from this tree, a usage.jsonl with one row per build and a
  preloaded fake for WorkBuddy's meter (network otherwise blocked): init
  provides workbuddy and workbuddy-ai; usage for workbuddy gives
  "deepseek-v4.1-flash tokens (est.)" 151,500,000 / 2e8, unit "", display
  "151.5M / ~200M", aside, models [deepseek-v4.1-flash, -sg]; workbuddy-ai
  gives "Free model tokens" 30,000,000 / 1e8, unit "tokens", "30.0M / 100M".

Broken by hand: the card's name back to "Free model tokens": "the China
build counts its own rows against 200M" and the ledger usage test go red.

Not tried: a real China-build account; another CN model's window (none is
measured). With several CN windows the one-entry parse cache would re-read
the ledger per window each poll (one entry today).
2026-11-03 15:05:59 +08:00
yetone da94c2768a workbuddy 0.2.17: extra credits only the detail lists have are their own window
jiabubu on Discord (magpie 0.1.2774, workbuddy 0.2.16, a China-site free
account): magpie's card read "Free plan · 0 / 500" and nothing else, with no
Extra credits row. 0.2.16 splits the credits only by the resource summary
(CreditGroups, else its Packages). WorkBuddy's own usage panel (5.5.6,
buildCreditGroups) groups the packages of the paid and free detail lists, so
extra credits only those lists carry were nowhere in magpie.

The usage hook now adds, when the summary has the plan's credits alone, an
"Extra credits" window from the detail lists' packages that:
- are an extra kind as the client's resolveCreditGroup has it (bonus 028/037,
  top-ups 009/038/036, rewards 007/029/030; on WorkBuddy AI also 008 and 006;
  the China build puts gift 006 in no group);
- the summary doesn't list (never counted twice);
- haven't ended, and have a total (a slice package counts the day's slice).
It is set aside, and says the soonest-lapsing credits (runsOutAt/runsOut).
The plan's window still stops the account. Lists that can't be read, or a
summary that already splits, keep the card as it was.

Run at this head on mote: `HOME=$(mktemp -d) bun test` 4892 pass, 14 skip,
0 fail; `bun scripts/check.mjs` ok. Broken by hand: not adding the window
turns the new test red (1 fail).

Not tried: a real account with extra credits; the China meter answered 401
for the account I could read. The fixtures are CN_FREE's shapes with a
total, not jiabubu's own bytes (not seen).
2026-11-03 11:02:26 +08:00
yetone 52fff4d7d7 workbuddy 0.2.16: Extra credits are every kind but the plan's base, as WorkBuddy's own panel and CreditGroups say (Jiabubu)
Jiabubu (Discord, magpie 0.1.2738, Windows): a WorkBuddy account's quota
line under Routing → Accounts and keys showed the plan's Credits only;
extra credits (gifted, promo, bought) were neither shown nor counted
apart. magpie shows every window the plugin sends, so the gap was here.

Read from the vendor, not guessed:
- WorkBuddy AI 5.9.4.42593613 (its update feed today, read, never run):
  the usage panel's buildCreditGroups/resolveCreditGroup put packages in
  four kinds. planBase: proMon, proMonPlus, proYear, youth, advanced,
  flagship, buddyOneVip (043), freeMonIntl, the Pro trials, and freeMon
  on the China build. planBonus: bonus28, bonusIntl. addon: 009, 038,
  036. benefit: activity, bonus29/30, and gift and freeMon on WorkBuddy
  AI.
- The real summary (/billing/meter/get-user-resource-summary, the
  owner's WorkBuddy AI free account, 2026-11-03) now carries CreditGroups
  with the same four Kinds: plan_base "Plan Base Credits", plan_bonus,
  addon "Top-up Credits", benefit "Platform Reward Credits".

0.2.11 called the plan's bonus (bonus28, 037) the plan's, from the
client's onlyRefreshCodes, so a Pro account's 1000 bonus credits were
summed into "Credits" and no "Extra credits" window was sent (the real
Pro summary in the tests, LIVE_SUMMARY, read "89.2 / 2000" in one
window). Now:
- with CreditGroups, "Credits" is plan_base and "Extra credits" the sum
  of every other kind (an unknown Kind too);
- without them, the codes split as the client's panel does: PLAN_CODES
  is its planBase list (028 and 037 out, buddyOneVip 043 in); 043 is
  asked for in the paid list too, as the client's list has it;
- the prepaid balance window, the aside rule and runsOutOf are as they
  were.

Run on mote at this tree: HOME=$(mktemp -d) bun test (whole repo):
4872 pass, 14 skip, 0 fail; bun scripts/check.mjs ok; packages/workbuddy
316 pass. usageOf on the real WorkBuddy AI summary: one window,
"0.19 / 100", as the account has only plan_base.

Broken by hand: origin/main's index.mjs: 3 usage tests fail (the new
one, the akic404 split, the unreadable-list card). CreditGroups ignored
(code split only): the new test fails ("150 / 1800").

Not tried: Jiabubu's own summary, and any real account with extra
credits: the owner's WorkBuddy AI account has plan_base only, and the
China account's token was refused (401) by the meter, so whether
copilot.tencent.com sends CreditGroups is not seen; without them the
code split applies. Two windows rather than four: the bonus, top-ups and
rewards are one "Extra credits" window.
2026-11-03 05:27:50 +08:00
yetone eea8c9bcf0 workbuddy 0.2.14: the free model's ledger estimate is shown, not routed on (#641, XiaoFeiyu9)
XiaoFeiyu9's China account (paid credits, deepseek-v4.1-flash at x0.11)
read 99% of the free model's window in routing: 187,701,367 of the 1.9e8
soft cap, from 937 answered calls and no 429, while the credits meter had
2,457 credits left. The window is this machine's ledger summed against a
cap measured on two other accounts; neither is the vendor's word for this
account, yet the card was a routing window and would have stopped the
model at 190M.

Now the summed card is set aside (aside: true): magpie shows it beside the
account and never counts it as the allowance (allowanceOf skips aside
windows). Only a refusal's card (refused: true, used 100, the vendor's
reset) stops the model. Nothing is lost by waiting for the refusal:
magpie's gateway already reads WorkBuddy's 429 reset ("将在 … 重置",
"reset at …") and its "switch to the other models" (resetsWhen,
otherModels in internal/gateway/routing.go) and rests this model alone, on
this account alone, until that time. Both builds, as both read the sum
the same way.

The China cap goes from the soft 1.9e8 to the measured 2e8 (#625's
refusals at 200,389,043 and 200,485,923). The 5% headroom only existed so
routing would stop before the vendor; with the sum aside it would only
make the card read high. The reporter's sum now reads 187.7M / 200M.

Run at this head (fa144e4 + this), on mote:
- packages/workbuddy bun test: 314 pass, 0 fail (one new test with the
  reporter's numbers; the China cap tests moved to 2e8; the card test
  checks aside on both builds).
- bun scripts/check.mjs workbuddy: ok.
Broken by hand: the card without aside -> 2 fail (the new test and the
card test), 312 pass.

Not tried: a real China account. Whether paid-credit accounts share the
Free plan's window is still unknown; the refusal decides either way.
2026-11-02 22:30:05 +08:00
Kunghim f12daf6f9b workbuddy 0.2.12: the China build reports the free model's window too (#625)
The China build (copilot.tencent.com) now reports the free model's daily
token window too, the open half of #288 (kunghim).

kunghim measured it on 2026-11-02: two Free-plan accounts were refused
at 200,389,043 and 200,485,923 tokens (in + cache_read + out), resetting
24h after the window opened, the same per-account window as WorkBuddy
AI's at about twice its 1e8. Each build has its own window
(FREE_WINDOW_CN on workbuddy rows, FREE_WINDOW_AI on workbuddy-ai rows),
so one phone number signed in to both never sums the builds; the parse
cache is keyed by build. windowReset reads the China refusal's
"将在 … UTC+8 重置". The China card stops at a soft cap of 1.9e8, 5%
short of the measured one; a refusal in force still reads it full.

Reviewed at c7e4a19ef9aeb192e909fff9fcdb71d06b79e116, run on mote
(bun 1.4.2, HOME=$(mktemp -d)):
- packages/workbuddy bun test: 311 pass, 0 fail.
- whole repo bun test: 4747 pass, 12 skip, 0 fail.
- bun scripts/check.mjs workbuddy: ok.
- Broken by hand: the PR's tests against main's index.mjs, 7 red (the
  China counting, the builds kept apart, the Chinese reset, the cache
  key, the usage card).

Not tried: a real China-build account through magpie (the measurement
is kunghim's).
2026-11-02 17:19:06 +08:00
yetone 486a68a54f workbuddy 0.2.11: the plan's credits and the gifted ones are two windows, the plan's with its own cycle (akic404)
akic404 on Discord: "workbuddy 积分总量可否分离套餐内的总量和赠送的总量?…
现在这样那个匀速用量线实际没意义的,因为算上那些已用过的赠送积分,每月第一天就
看起来用了一大半了". usageOf summed CycleTotalCapacity/CycleUsedCapacity
over every package of the resource summary into one "Credits" window, so
gifted and activity packages' credits used long ago counted against the
plan's month; the real China-site free account in usage.test.mjs
(CN_FREE_SUMMARY, 2026-10-26) read 282 / 3400 with its 500 plan credits
untouched.

What tells them apart is the package code. WorkBuddy's client (5.9.x,
app.asar, its COMMODITY_CODES and the onlyRefreshCodes / onlyExpireCodes
lists its usage panel uses) refreshes proMon, proMonPlus, proYear, youth,
advanced, flagship, bonus28, freeMonIntl, proTrialMon, proTrialYear,
bonusIntl, and freeMon on the China build only; gift (006), activity
(007, 赠送积分), bonus29/30 and the credit packs only lapse. The summary
carries PackageCode and SubscriptionPackageCode (no CapacityType or
name), so the split is by code: PLAN_CODES, plus the subscription the
summary names.

- "Credits" is the plan's packages, with cycleOf's reset and span as
  before, so its pace line is the plan's cycle. "Extra credits" is the
  rest, used / total. A summary with only one kind (or codes the client
  names nothing for, as the older fixtures) keeps the one summed
  "Credits" window, as before. The prepaid balance window is unchanged.
- Only one window stops the account, as WorkBuddy serves it while any
  credits are left: "Extra credits" is aside, until the plan's are spent
  with extra ones left, then "Credits" is aside. Both spent: the plan's
  stops it at 100%, as the summed window did.
- runsOutOf over every package stays on the window that stops the
  account (routing reads none set aside, cdredfox's spend-first); the
  aside window gets runsOutOf over its own packages. So the plan window
  can say a gifted package's soonest lapse while it is the one routing
  reads.
- Enterprise accounts (no packages, enterprise meter) are unchanged.
  WorkBuddy AI goes through the same code with site.ai: freeMon (008) is
  extra there, as its client says.

Run on mote at this tree: HOME=$(mktemp -d) bun test (whole repo): 4730
tests, 0 fail, 12 skip; bun scripts/check.mjs: registry.json and
workbuddy ok. packages/workbuddy alone: 305 pass.

Broken by hand: usage.test.mjs against origin/main's index.mjs: 3 fail
(the new two, "282 / 3400" for "0 / 500", and the unreadable-lists test
that now expects the split). The gating rule replaced by "extra is
always aside": the akic404 test fails.

Not tried: a real account. No account here has gifted and plan packages
at once with credits used, and akic404's own summary wasn't seen; the
split follows the client's code lists, not their bytes. magpie's GUI
has no translation for "Extra credits" (it shows in English, as
"Prepaid credits" does).
2026-11-02 09:28:24 +08:00
Euraxluo 3f73907aac workbuddy 0.2.0: WorkBuddy (China) daily check-in through the billing meter (#177)
WorkBuddy (China) claims its daily check-in credits through the billing meter's /v2 activity status and daily-checkin. Outcomes are done, ineligible, inactive, claimed and failed, all of which magpie's host accepts. A request that gets no answer is thrown, for magpie's 1-minute backoff. The AI build has no hook.

The review merged main (0.1.48) in, resolving the conflicts in meter, the hook list, _internal and README. It also made an API-key account ineligible without sending a request, and set the version to 0.2.0.

Run at d66f51c on mote, with a temp HOME:
- bun test packages/workbuddy: 253 pass, 0 fail
- the whole repo: 3521 pass, 0 fail (3529 tests)
- bun scripts/check.mjs workbuddy: ok

Broken by hand, each red:
- dropping the API-key line: its new test
- the hook on the AI build: "WorkBuddy AI's plugin has no check-in"
- an unreadable 200 not thrown: the usage test and the check-in test

Not covered: main's own invalidToken flag on a refused meter reply has no test that fails without it. That gap is on main and was kept as it is.
2026-10-29 21:46:35 +08:00
keeuuandkeeuu f0ed150573 workbuddy 0.1.48: WorkBuddy AI's card shows the free model's daily token window (#299)
WorkBuddy AI's free model (deepseek-v4.1-flash) has a daily token window of
its own (about 1e8 tokens per account per 24h) that the credit meter doesn't
show. The plugin rebuilds it from magpie's usage.jsonl and adds it to the
card as "Free model tokens" beside Credits. WorkBuddy AI only; the China build
is unchanged.

Review merge: main (0.1.47) merged into the branch, conflicts in index.mjs
(imports, _internal) and package.json resolved, version 0.1.48. Added a test
that the window reaches the WorkBuddy AI card from a ledger in the sandbox
HOME, and that the China build's card has none.

Run at 09718f5 on mote (HOME=$(mktemp -d)):
- bun test packages/workbuddy: 237 pass, 0 fail (before the new test).
- bun test (whole repo): 3499 pass, 0 fail; bun scripts/check.mjs: ok.
- Broken by hand, each reverted: the card no longer pushing the window ->
  the new usage test red; an unreadable row time ending the read ->
  "a row whose time cannot be read is passed over" red.
Not tried against the live service (no WorkBuddy AI free account).

Co-authored-by: keeuu <keeuu@users.noreply.github.com>
2026-10-29 21:39:45 +08:00
MYCF711andMYCF711 e460dae2f0 workbuddy 0.1.41: a package with no cycle total reads as a wallet balance (#450)
A WorkBuddy package with no CycleTotalCapacity is a prepaid wallet: it is sent as a balance window ("Prepaid credits", magpie#3950), beside the share of packages that have a total. A literal "0" total stays on the old path, so a lapsed package adds nothing; an account with no packages keeps its unknown allowance (no TotalCredits fallback).

Reviewed at 5bdfa9048d66095d35af5e7955d0945db02dc3b5 over four rounds. Run on mote at that head: HOME=$(mktemp -d) bun test packages/workbuddy, 185 pass / 0 fail; bun scripts/check.mjs workbuddy ok. npm had 0.1.40, so 0.1.41 is free.

Co-authored-by: MYCF711 <MYCF711@users.noreply.github.com>
2026-10-28 10:26:47 +08:00
yetone b2fe48ea2e workbuddy 0.1.40: chats carry the current desktop client's headers
WorkBuddy accounts are being restricted, and a report says WorkBuddy now
checks request-header fingerprints. Diffed the plugin's chat request
against each build's current desktop app, read (never run) from the
update feeds on 2026-10-28:
- China: WorkBuddy 5.9.3.42398134 (copilot.tencent.com/v2/update),
  bundled @genie/agent-cli 2.165.0.
- WorkBuddy AI: 5.8.4.41366630 (www.workbuddy.ai/v2/update), CLI 2.161.0.
The chat is the CLI's OpenAI client (openai 6.25.0) through
axiosToFetchAdapter, with UserAgentHttpInterceptor and the desktop's
CLIENT_INFO_* env (sidecar-manager getCachedBaseEnv).

What differed, and now matches:
- User-Agent: was WorkBuddy/5.5.6; the client sends
  "WorkBuddy/<app> <applicationName>/<app> CLI/<cli>":
  WorkBuddy/5.9.3 WorkBuddy/5.9.3 CLI/2.165.0 (China),
  WorkBuddy/5.8.4 workbuddy-ai/5.8.4 CLI/2.161.0 (AI). The /v3/config
  models call (was CLI/2.0.0 WorkBuddy/5.5.6) takes the same one, as the
  CLI's CloudProductProvider sends it through the same interceptor.
- X-IDE-Version: was 5.5.6; now the app's version.
- X-Agent-Type: main was sent on WorkBuddy AI only; the adapter sets it on
  every model call on both builds.
- X-Agent-Runtime: local-agent, new in 5.9 (the desktop's local transport
  puts agentRuntime local-agent in the prompt meta); China build only,
  5.8.4 has no such header.
- Accept: application/json and the OpenAI SDK's X-Stainless-* (Lang js,
  Package-Version 6.25.0, OS/Arch of this machine, Runtime node,
  Runtime-Version v22.21.1 = Electron 37.10.3's Node, Retry-Count 0,
  Timeout 1200); the adapter strips them only in its skip-auth mode.
- The desktop's own calls (billing, plugin API) send WorkBuddy/<app>;
  they now send the current app version instead of 5.5.6.

Not matched: X-Device-Token (TuringShield native SDK, sent since at
least 5.6.2), traceparent (only while server-side tracing is enabled),
and transport-level differences (Bun's fetch vs axios on Node: header
order, Accept-Encoding).

Run: HOME=$(mktemp -d) bun test packages/workbuddy: 184 pass, 0 fail.
With the old index.mjs the 4 changed tests fail (UA, IDE version,
config UA, the new per-build header test).
Not tried: a real account's chat or /v3/config with the new
User-Agent (unauthenticated /v3/config answers the same for old and new).
No text added names magpie or WorkBuddy's limits.
2026-10-28 03:20:46 +08:00
MYCF711 213ef506c5 workbuddy 0.1.36: a free account's credits say when the plan refills (#415)
A free account's card says when the plan refills: with no subscription named, cycleOf reads the plan_base slice's cycle end (UTC+8). A summary that names a subscription still goes by it alone, and named-but-not-listed stays unknown.

By MYCF711. Reviewed at b8d600c9:
- `HOME=$(mktemp -d) bun test` in packages/workbuddy: 155 pass, 0 fail.
- The named-not-listed assertion fails on the PR's first head (b1ce408), which returned the slice's month end for a paid account; passes now.
- npm had 0.1.35; this is 0.1.36.
Not tried: a real WorkBuddy account (the fixture is the author's live CN reply).
2026-10-26 23:56:46 +08:00
yetone 9da5cd3426 workbuddy 0.1.35: used credits say when the plan's cycle starts again (windy on Discord)
windy's WorkBuddy card in magpie showed 46% of the credits used and,
beside it, "Not used yet". The Credits window had no resetsAt, and
magpie's card says "Not used yet" when no used window has a reset.
WorkBuddy's own client (5.5.6, getCurrentPlan) says the plan refreshes at
the cycle end of the package the summary names as the subscription
(SubscriptionPackageCode). cycleOf now gives the Credits window that
reset (CycleEndTime, UTC+8) and the cycle's span, from the paid and free
lists usage already reads for runsOutOf; none named, not listed or a
cycle already over leaves it unknown, as before.

Run: bun test in packages/workbuddy, sandbox HOME, fetch stubbed: 154
pass 0 fail. On the old index.mjs the two new tests fail (resetsAt
undefined; cycleOf's cases). bun scripts/check.mjs: workbuddy ok.
Real: the summary and paid list of a real WorkBuddy AI Pro account
(2026-10-26, read-only, no renewal) through the new code give Credits
89.2 / 2000, resetsAt 2026-10-28T16:40:52Z, span 30d-1s.
Not tried: a China-site (copilot.tencent.com) account: the desktop
sign-in on this machine is refused (401), so a CN free plan's
SubscriptionPackageCode wasn't seen; without one the card stays as it
was. magpie's card saying "Not used yet" beside a used window without a
reset is fixed in magpie itself.
2026-10-26 15:00:30 +08:00
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