Files
plugins/packages
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
..
middleware: param-override, model-map, system-prompt, word-guard and think-tags — gateway middleware that magpie runs on every agent's requests and replies, mostly New API's channel settings with the same JSON (the owner) — magpie can now run a plugin as gateway middleware (onRequest, onEvent, onResponse, in-process on moejs), and these are the first ones: param-override is New API's param_override (both forms, operations with gjson paths and conditions, return_error); model-map is model_mapping (chains, /regex/ keys with $1) and puts the asked-for name back into replies; system-prompt adds a prompt in each API's own place, keeping an agent's own unless override (New API's semantics), by agent or model; word-guard is the sensitive-word filter (reject or mask the user's text, optionally replies); think-tags strips a leading <think>…</think> from replies across stream chunks, or puts Chat reasoning_content into the text (thinking_to_content). Each is one file with no imports, named @magpie-community/middleware-<name>, with magpie.options as the example the app's editor starts from; registry.json lists them with "kind": "middleware" and no providers; check.mjs skips middleware-only packages. scripts/middleware.mjs calls the hooks as the gateway does (events split, [DONE] passed by) and runs each package's cases.json. Tested with a real DeepSeek account and real Claude Code through magpie's gateway: a mapped model named back in message_start, max_tokens capped, a system prompt appended for claude only, a word turned away as a 400 in Anthropic's shape, return_error as a 403 in Chat's, <think> stripped from Chat and Responses streams and an Anthropic whole reply, reasoning_content moved into the text. bun test (61 for these five) and bun scripts/check.mjs pass; packages/devin's two image tests fail on this machine only, as on main. Their first npm version has to be published by hand (trusted publishing can't create a package); until then magpie shows them as Coming soon.
2026-10-05 20:49:42 +08:00
middleware: param-override, model-map, system-prompt, word-guard and think-tags — gateway middleware that magpie runs on every agent's requests and replies, mostly New API's channel settings with the same JSON (the owner) — magpie can now run a plugin as gateway middleware (onRequest, onEvent, onResponse, in-process on moejs), and these are the first ones: param-override is New API's param_override (both forms, operations with gjson paths and conditions, return_error); model-map is model_mapping (chains, /regex/ keys with $1) and puts the asked-for name back into replies; system-prompt adds a prompt in each API's own place, keeping an agent's own unless override (New API's semantics), by agent or model; word-guard is the sensitive-word filter (reject or mask the user's text, optionally replies); think-tags strips a leading <think>…</think> from replies across stream chunks, or puts Chat reasoning_content into the text (thinking_to_content). Each is one file with no imports, named @magpie-community/middleware-<name>, with magpie.options as the example the app's editor starts from; registry.json lists them with "kind": "middleware" and no providers; check.mjs skips middleware-only packages. scripts/middleware.mjs calls the hooks as the gateway does (events split, [DONE] passed by) and runs each package's cases.json. Tested with a real DeepSeek account and real Claude Code through magpie's gateway: a mapped model named back in message_start, max_tokens capped, a system prompt appended for claude only, a word turned away as a 400 in Anthropic's shape, return_error as a 403 in Chat's, <think> stripped from Chat and Responses streams and an Anthropic whole reply, reasoning_content moved into the text. bun test (61 for these five) and bun scripts/check.mjs pass; packages/devin's two image tests fail on this machine only, as on main. Their first npm version has to be published by hand (trusted publishing can't create a package); until then magpie shows them as Coming soon.
2026-10-05 20:49:42 +08:00