Files
plugins/packages
Yandre97 f02894d3a0 autoclaw 0.2.11: the points balance is a prepaid wallet window, and spend rides on local balance deltas (#445)
AutoClaw has no points ledger upstream (wallets.v2 is a balance only), so usage() now reports the balance as a prepaid wallet window, {name: "积分余额", balance, unit: "积分"} (magpie >= v0.1.1790, #3950), which routing reads as what is left; an empty wallet counts as used up. A display-only "本轮消耗" window (aside) is worked out from local balance deltas: any rise, from 0 too, opens a new cycle, and the Beijing day keeps its spent/gained sums. The ledger is keyed by signinAccountKey (#254), lives in $XDG_CONFIG_HOME/magpie/autoclaw-usage.json (temp file + rename, 30-day expiry), and a null/""/non-numeric total_balance is unknown and never recorded. The unsigned fallback reward reads 200 (was 400). Version 0.2.11, on top of main's 0.2.10 (#466, d8cfee3, whose FLAGGED rewrites are kept).

The reviewer pushed 6418906 on top of fb334b8: main merged in (no conflicts), version 0.2.10 -> 0.2.11, the README paragraph rewritten to match the code (it still described state in the package folder and a routing spend window), and an aside assertion on the spend window test.

Run at 6418906cb7387c5e6892f326c9a2d913cc252881, on mote (mote-run, HOME=$(mktemp -d)):
- bun test packages/autoclaw: 44 pass, 0 fail; nothing left in packages/autoclaw or $HOME/.config.
- bun scripts/check.mjs autoclaw: ok. Full bun test: 3050 pass, 8 skip, 0 fail (257 files).
- The merged tree's packages/autoclaw diff against main is exactly the PR's own diff plus the version line; FLAGGED's "CodeBuddy Code" entries are there.
- Broken by hand, one at a time, each red then restored: `last > 0` back in balanceObserve (balanceObserve test), the old key uid ?? accountId (same-name accounts test), the null guard dropped (unreadable balance test), `if (false)` for the spend window (two-reads test), aside removed (two-reads test, with the new assertion; it passed without it), the balance window removed (4 tests).
- npm pack 0.2.11 and imported the packed index.mjs (AutoclawAuthPlugin, AutoclawCnAuthPlugin, _internal).

Not tried: a real AutoClaw account (none here); the balance shapes and the routing order rest on the author's run with magpie v0.1.1876. Not known: whether an account at 0 积分 is still served (e.g. a member's GLM-5.3 allowance); magpie now benches it at 0.
2026-10-28 23:46:06 +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