Commit Graph
23 Commits
Author SHA1 Message Date
zhou.hanandyetihan 93cb4fe1c0 autoclaw 0.2.22: Linux overseas chat omits X-Tm; wallets decides a bare forbidden (#979)
Fixes #367.

On Linux the overseas chat leaves X-Tm out: the gateway refuses the
official "linux" value for plugin-only accounts (#367; menhouran got 200
with only X-Tm removed on x64; on arm64 only the platform values were
tried, not omission). Sign-in, refresh, wallets, check-in, CN chat and
macOS/Windows keep their headers.

An exact uncoded 403 "forbidden" (JSON or plain text) on both chat hosts
no longer reads as a dead token on its own: the wallets route decides.
It takes the token: 403 permission_error, sign-in kept. Every host
refuses it: 401, expired. Mixed or failed check: the upstream 403 goes
through with no X-Magpie-Sign-In, which magpie leaves unmarked.
signInHolds now says false only when every wallets host refused; for
sizeRefusal false and null already led to the same answer. 0.2.22.

Run at cd6da42dd (no live AutoClaw request, no credentials):
- WSL Ubuntu 24.04, Bun 1.4.2, temp HOME: bun test packages/autoclaw
  117 pass 0 fail; root bun test 8189 pass 19 skip 0 fail;
  bun scripts/check.mjs ok.
- Merged with origin/main f85f9ad0b: autoclaw 117 pass; root bun test
  8192 pass 0 fail; check.mjs ok.
- Windows 11, temp HOME/USERPROFILE: autoclaw 117 pass 0 fail; check ok.

Broken by hand on WSL, one at a time, each red: X-Tm always set (2),
exact-message guard dropped (1), uncoded guard dropped (1), classifier
off (3), plain-text path off (1), wallets check skipped (3), unknown
read as expired (1), wallets refusal kept (1), signInHolds' any refusal
as false (1), unknown dropping the upstream body (1), res2 status guard
off (1), only host 2's fingerprint read (1).

Not caught: reading only host 1's fingerprint (a bare forbidden on host
2 alone after a different 403 on host 1) passes all tests.
Not tried: a real AutoClaw account; omission on arm64.

Co-authored-by: yetihan <roc.han@nio.com>
2026-11-11 17:41:59 +08:00
yetone 1bdc4d4b63 autoclaw: mask DeepSeek Harness throughout system, not only its first line (#924)
DeepSeek Harness names itself three times in system: the identity line
("You are an AI agent powered by DeepSeek Harness.") and, from its dev
context, "The runtime context names the DeepSeek Harness implementation
checkout.", "...through the DeepSeek Harness Web GUI..." and "Current
DeepSeek Harness implementation checkout: ...". FLAGGED rewrote the first
only. The reporter's replay (five sends each) was still 406 with the
identity line rewritten and 200 five of five with every occurrence masked.

autoclaw 0.2.21:
- the identity line, its comma optional, becomes "You are an AI agent
  powered by a local coding harness."; every other "DeepSeek Harness" in
  system or developer text becomes "DeepSeek" (the reporter's proposal,
  which their replay measured; no product name in the replacement).
- "powered by the glm-<x> model" in any case is written "powered by the
  GLM-<x> model", the form probed to pass on 11-03. Only that sentence:
  model ids, paths and code naming glm-5.3 are left. The reporter's other
  sentence ("powered by the model glm-5.3-flash") was already rewritten
  case-insensitively before this.
- Same roles as before: system and developer only (string content and
  text parts); user messages, tool results and tool arguments untouched,
  and a test checks that on both gateways.

Fixtures are dsh's own strings byte for byte (@deepseek-ai/dsh
0.2.1-rc.2: dsh-system-prompt harness:identity, dsh-harness-dev-context
HARNESS_SOURCE_PROMPT, WEB_SURFACE_PROMPT and its runtime line), plus the
reporter's comma line and lowercase GLM sentence. The reporter quoted the
Web GUI line without the product name; dsh's source has it.

Run: lockf ~/suite.lock mote-run -C <worktree> bash -lc 'bun install
--frozen-lockfile; bun test packages/autoclaw && bun scripts/check.mjs':
112 pass 0 fail, check.mjs ok.
Broken by hand, each on mote, each restored (cmp against the saved file):
- origin/main's index.mjs with the new tests: 4 fail (the three new
  tests and the all-lines table).
- the "DeepSeek Harness" -> "DeepSeek" rule removed: 3 fail (full-text,
  loader, table).
- unflag applied to every role: 5 fail, the new loader test among them
  (user and tool text would change).
Not tried: a real request to AutoClaw; the 406 -> 200 is the reporter's
measurement and was not reproduced here. Whether the gateway refuses a
lowercase "glm" where it takes "GLM" is the reporter's word, not probed.
Not run: the full bun test.

Reported-by: connoryang331
2026-11-10 12:06:55 +08:00
yetone 89fcfb2ea6 autoclaw 0.2.20: a 401 for a body larger than any answered, its sign-in holding, is a 413 (#891)
The CN managed gateway answers a ~200k-token request 401 "AutoClaw 登录状态失效"
while the same token gets 200 seconds before and after (hj01857655: 401 at
207k and 218k tokens, every 200 that day at most 129k). The plugin read it
as expired, so magpie marked the account signed out and stopped.

Now each provider remembers the largest chat body its gateway answered. A
401/403 (not quota, not ban) for a larger body has its sign-in checked on
the wallets route; a sign-in that holds there turns it into 413
request_too_large with X-Magpie-Sign-In: kept, so magpie's gateway asks
another member (a byte cap rests nobody) or tells the agent to compact.
No threshold is guessed. A body no larger than one answered, nothing
answered yet, a sign-in refused on wallets, or a check that fails stays
the sign-in, as before. Same rule on the overseas path (both hosts
refusing) since both providers share the fetch.

Run: lockf ~/suite.lock mote-run bun test packages/autoclaw, 109 pass
0 fail. Broken by hand (sizeRefusal returns null at once), wsl-run
bun test packages/autoclaw: the CN and overseas 413 tests red, 107 pass
2 fail; restored.
Not run: the full bun test (left at the coordinator's call, lock queue
long). Not tried: a real ~200k request on the CN gateway; the fixture is
the reporter's 401 body.

Reported-by: hj01857655
2026-11-09 17:22:25 +08:00
yetone 40c9725666 autoclaw 0.2.19: rewrite Grok CLI's identity line for the CN gateway (#875)
Grok CLI through AutoClaw 国内 got four 406s in a row on 11-08. Its system
prompt opens "You are Grok released by xAI. You are an interactive CLI
tool ...", and FLAGGED had no rule for it, so the line went out as written.

Grok CLI writes that line in two shapes. Its own system_prompt.txt files
(grok 1.0.67, in ~/.grok/sessions on this Mac) show "You are Grok released
by xAI." for a model it doesn't know, and "You are Grok 4.7 released by
xAI." for one it does, in the interactive and autonomous variants alike.
The reporter's suggested regex matched only the first. The new rule takes
both: "You are the Grok[ 4.7] assistant released by xAI". It touches only
the "released by xAI" sentence, so "You are Grok-Mini." or "You are Grok,
a helpful assistant." are not changed. REFUSED_HINT now names Grok CLI.

Run (on mote): bun test packages/autoclaw gives 104 pass, 0 fail. The
new tests use the reporter's line byte for byte, plus the versioned and
autonomous lines from Grok CLI's own files.
Broken by hand: with origin/main's index.mjs and the new tests, 3 fail:
the Grok rewrite test, the all-lines table and the CN loader test.
Not tried: a real AutoClaw 国内 request. There's no account here, so
nobody has checked that the rewritten line passes the gateway. The same
pattern has passed for ZCode and Codex.

Reported-by: hj01857655
2026-11-09 09:51:34 +08:00
我是一条没有名字的区 1df427773b autoclaw 0.2.18: the README reads like a manual, and the sign-in's non-2xx guard gets its tests (#836)
autoclaw 0.2.18 (yunwang2442-creator, #836): the README is rewritten around
what a user does, with an English README.en.md shipped in `files`, and
dailySignin's non-2xx guard gets three tests. No change to index.mjs.

Reviewed at 699e545112c77938c4274368ef505017ed902e2e, merged onto main
b8100001 (mote, Bun 1.4.2, temp HOME):
- packages/autoclaw `bun test`: 103 pass, 0 fail
- `bun scripts/check.mjs autoclaw` and `bun scripts/check.mjs`: ok
- repo root `bun test`: 6820 pass, 20 skip, 0 fail (496 files)
- broken by hand (at 2ac00cee, same test file): removing
  `if (!res.ok) return null` turns exactly the three new tests red
- README facts checked against index.mjs (CHAT_PATH, X-Authorization,
  refreshShared's 60 s share and rotatedMemo, recordBalance's any-rise cycle)
- CI run 42378290789 green
Not tried: a real AutoClaw sign-in; the README in magpie's Plugins page.
2026-11-07 22:06:16 +08:00
我是一条没有名字的区 b475f33187 autoclaw 0.2.17: name the campaign points on the card, and stop the check-in from signing out healthy accounts (#774)
The usage card gets a campaign-points row (剩 / 已领 / 过期(近期)) read
from ledgers_std?wallet_scope=campaign, re-filtered client-side, counted
per wallet instance and never carrying `balance`; cached per account for
10 minutes, a failed read not cached, capped at 100 settled entries.

Check-in fixes after 0.2.15: dailySignin never throws, so a 401 no longer
escapes auth.refresh and signs out a healthy account; the CAS write-back
never resurrects a logged-out record; a quota 403 at task-list keeps the
sign-in; a second 401 right after renewal is a retryable failure; every
rotation is remembered and an expired memo is refreshed over the wire;
refresh survives a network error on the first host; maybeSignin dedupes
by the Beijing day; the config dir falls back to USERPROFILE/homedir on
Windows. The day-boundary test restores Bun's clock with setSystemTime()
(no argument), and a guard test fails if the clock is left frozen.

Version 0.2.17 (0.2.16 is #800's; 0.2.17 is in neither npm nor dist).

Reviewed head 749603160c184901a918a8f48a79b719431181ae, merged onto
origin/main 049295f5 (clean). Bun 1.4.2, HOME=$(mktemp -d) each run:
- mote (macOS): bun test packages/autoclaw 100 pass, 0 fail; check.mjs
  autoclaw ok; check.mjs exit 0; repo-root bun test 6613 pass, 20 skip,
  0 fail (475 files)
- WSL2 Ubuntu 24.04: bun test packages/autoclaw 100 pass, 3 runs of 3

Broken by hand, one at a time, each red: setSystemTime(new Date()) as the
reset, and no reset (the clock guard); the UTC day (2 tests); evicting an
in-flight entry; no cap; the old CAS; no memo record on success (2); the
quota-403 classification; the post-renewal degrade (2); the USERPROFILE
fallback; the memo expiry. Green, so untested: dailySignin's
`if (!res.ok) return null`.

Not tried by the reviewer: a real AutoClaw account (the author reports a
read-only check on two Windows accounts), Windows.
2026-11-07 12:45:44 +08:00
zxy20250120 0469390a89 autoclaw 0.2.16: two more identity lines rewritten, and an opt-in 406 dump of the system prompt
Three fixes from live 406s on 11-03 to 11-05.

- The Fable harness's model line "You are powered by the model glm-5.3-flash[1m]." is rewritten to "You are powered by the GLM-5.3-flash model." in the author's own case. A bare model name without GLM is left as written.
- The subagent opening "You are an agent for Claude Code, …" becomes "You are an agent for the Claude Code CLI, …". A `(?! CLI)` lookahead keeps an already-rewritten line from getting a second CLI.
- An opt-in 406 dump. It is off by default. `AUTOCLAW_406_DUMP_DIR` (any directory) or `"dump406": true` (strictly boolean; the default dir is $XDG_CONFIG_HOME, else HOME, USERPROFILE or os.homedir(), then /.config/magpie/autoclaw-406) turns it on. A 406 then writes the rewritten system and developer messages plus `model` (never user, assistant or tool content) to `autoclaw-406-<stamp>-<rand>-<provider>.json`, mode 0600 in a 0700 directory. Only the 10 newest are kept, by mtime. Rotation matches that whole name, so other files in the directory are never touched. A dump that fails never changes the 406. The README documents the switch and says a system prompt can carry the working directory, git status and an email.

Reviewed head 390024c2, merged onto main 367edb50, run on macOS (Bun 1.4.2) with a fresh mktemp -d HOME:
- bun test packages/autoclaw: 67 pass, 0 fail. Nothing was written into HOME.
- Repo bun test: 6570 pass, 20 skip, 0 fail. bun scripts/check.mjs autoclaw: ok.
- Broken by hand, each red: the rotation filter as endsWith(".json"), a truthy dump406, the file's 0600, the dir's 0700, no rotation, no name prefix (and, in the earlier round, the user/tool filter, the default-off check, name-order rotation, both loaders' sent body, the (?! CLI) lookahead, and ?? for XDG_CONFIG_HOME). Loosening the name regex to autoclaw-406-.*\.json stays green; it is covered by a probe only.
- Probes: 21 foreign files and near-miss names, each backdated an hour, all survived eleven 406s, and 10 dumps were kept. dump406 set to "false", "true", 0, 1, "1", {}, [], null or undefined stays off. The user turn is in no dump.
- Not tried: Windows modes and the USERPROFILE fallback on a real Windows GUI process, and a real AutoClaw 406.
2026-11-07 10:29:57 +08:00
我是一条没有名字的区 6fa3f487be autoclaw 0.2.15: campaign rewards need the desktop client's user-info, not task-complete (#769)
autoclaw's native check-in now calls POST /userapi/v1/user-info with the
desktop client's header set (X-Channel AutoClaw20, 2.2.0, win-x64) and the
account's current access token, own host first, before task-list ->
task-complete. That call is what records autoclaw_user_active, which the
login-reward campaigns pay on (yetone/magpie#3681). A user-info failure on
both hosts never blocks the daily check-in; the message says the campaign
wasn't triggered.

Only a 401/403 from task-list (now marked signIn: expired) spends the
refresh token, once, through a per-refresh-token single flight shared with
auth.refresh. The write-back is CAS-guarded against a re-sign-in, and a
rotated pair whose write fails is kept in memory under the spent token for
the next renewal. task-list failing on both hosts now throws (failed, retried
in 30 min) instead of answering inactive (yetone/magpie#3326).
callEnvelope gets a 20s abort. 0.2.14 -> 0.2.15 (dist branch only; the
package isn't on npm).

Run at 15542cb7 on mote (Bun 1.4.2):
- HOME=$(mktemp -d) bun test (whole repo): 6184 pass, 0 fail.
- bun scripts/check.mjs: ok.
- The PR's 13 new tests against main's index.mjs: 9 red (the 4 that pass
  hold behaviour main already had); on the PR all green.
- Five more review tests (not committed): concurrent check-ins whose refresh
  fails share one try and the next run refreshes again; a failed write-back
  is used by the next check-in with no second refresh and then saved; two
  accounts expiring together refresh once each into their own records;
  check-in only reaches AutoClaw's two hosts and user-info never carries the
  refresh token; a CN account asks the CN host first. All green on the PR,
  all red on main.
- Broken by hand, each turned tests red: user-info removed, user-info host
  order reversed, plain X-Channel, refresh token sent to user-info, a
  user-info throw escaping, inactive restored, rememberRotated removed, CAS
  removed, the in-flight join dropped, signIn: expired dropped, refresh on
  every check-in.

Not covered by a test: the 20s abort (removing it stays green), and the
"evict only my own gate" guard, which nothing in production reaches. Not
tried: a real AutoClaw account (the author's live run on 5 accounts is in
the PR); macOS.
2026-11-06 03:48:10 +08:00
yetone 17e5ef7457 all: load on OpenCode 2.x through a default {id, setup} (#657)
nbczw8750 (#657): trae 0.2.26 on OpenCode 2.2.5 fails with "Plugin
must export a default definition with an id and an effect or setup
function. (cause: SchemaError(Missing key at ["default"]))". 2.x
imports a package's exports["."] (a plugin dir and an npm install
alike) and has no V1 path at all, so every package here that serves
models failed the same way, not only trae.

Every one of the 32 model packages now has:
- opencode2.mjs, exports["."]: a copy of scripts/opencode2.mjs, an
  adapter that runs the package's V1 plugins inside 2.x's promise
  API. Config providers become 2.x providers (package pinned so the
  aisdk sdk hook runs), V1 auth methods become integration methods
  (oauth auto/code with forms; api without authorize as a key method),
  V1 credentials are kept in metadata.v1, the loader's baseURL,
  apiKey, headers and fetch are applied through the sdk hook, an
  auth.set renewal is stored per credential, and credential.switched
  /updated reload the account's own model list.
- opencode.mjs, main: re-exports the V1 plugin functions only.
  OpenCode 1.x and magpie's host.js take main. On 1.x, trae 0.2.26's
  main exported a non-plugin (_internal) and 1.19.5 refused it ("Plugin
  export is not a function"); the new main fixes that too.
- both files in "files"; patch version bumped. devin already had 2.x
  and is unchanged.

scripts/check.mjs fails a model package whose 2.x entry has no default
{id, setup}, whose opencode2.mjs differs from the canonical one, whose
entry is missing from files, or whose main exports a non-plugin.

Run at this head (mote):
- HOME=$(mktemp -d) bun test, as CI runs it: 4900 pass, 0 fail
  (4914 tests, 374 files). A first run set globalThis.fetch for the
  whole process from opencode2.test and failed 528 tests in other
  packages; the block is now set and put back around that file's tests.
- bun scripts/check.mjs: every package passes. With the network
  blocked cloudflare-workers-ai fails on its fetched catalog, the same
  on origin/main.
- Real OpenCode 2.2.5 (npm opencode-ai), sandbox HOME, packed trae
  0.2.27: loads with no error; /api/integration lists trae-cn "Trae CN"
  and trae-global "Trae Global" with their browser sign-ins; `auth
  login` starts the trae.cn authorization and waits (cancelled there);
  with a fake credential POSTed to /api/credential, `opencode models`
  lists trae-cn's six models.
- Real 2.2.5 with a fake V1 key plugin through the same adapter
  against a local fake server: `auth login` with a key, `models`,
  `opencode run` reached /real/v1/chat/completions with the loader's
  "Bearer loader-sk-fake" and header, and printed the fake's reply;
  with @ai-sdk/anthropic it reached /real/v1/messages with x-api-key
  from the loader. This run found the key method missing after 2.x's
  second integration transform (a once-only flag outside the
  transform); fixed, and opencode2.test checks a rebuild.
- Real OpenCode 1.19.5, sandbox HOME, trae 0.2.27: `opencode models`
  lists trae-cn and trae-global models; 0.2.26 failed there.

Broken by hand (scratch copy, bun test scripts/ and check.mjs):
- trae's exports back to "./index.mjs": the trae 2.x test fails
  (default.id undefined), check fails trae with "OpenCode 2.x:
  ./index.mjs has no default {id, setup} (plugins#657)".
- zed's opencode2.mjs changed: the copies test fails, check fails zed
  "differs from scripts/opencode2.mjs".
- the key flag back outside the transform: the 1.x plugin test fails
  on the rebuilt sign-ins (key missing).

Not tried: a real sign-in with a real account on 2.x; Windows (the
reporter's OS); chat.headers, chat.params, usage and tool hooks, which
the adapter doesn't carry to 2.x; the tools/pages packages (calc,
goanyapi, layerfs, search1api, aelios, agent-console, chat,
fingerprint, nowledge-mem, kimi-desktop), which still load only on 1.x.
2026-11-03 13:54:26 +08:00
yetone acb85ed880 autoclaw 0.2.13: Hermes Agent's identity lines are rewritten, not a 406
01huadalang (Discord #feedback, 10-30) runs Hermes Agent 0.22.1 through
magpie on AutoClaw 国内 (autoclaw-cn), and every chat came back
"406 Not Acceptable" with REFUSED_HINT: FLAGGED had no entry for Hermes.

Hermes opens every chat with its SOUL.md. Its seeded text (DEFAULT_SOUL_MD
in hermes_cli/default_soul.py, the same as DEFAULT_AGENT_IDENTITY in
agent/prompt_builder.py, read at tags v0.22.1 and v0.22.5) starts "You are
Hermes Agent, built by Nous Research.", and HERMES_AGENT_HELP_GUIDANCE adds
"You run on Hermes Agent (by Nous Research)". The run the gateway matches
wasn't probed (no AutoClaw account here), so both are broken, the way
"DeepSeek Harness" is:
- "You are Hermes" / "You are Hermes Agent" -> "You are the agent Hermes"
- "Hermes Agent" elsewhere -> "Hermes-Agent"
"Nous Research" is left as written: nothing shows the gateway matches it.

The class: agents magpie connects whose opening line names them as
"You are <name>", read from their own source, get an entry too, though
none has been seen refused: Gemini CLI (packages/core/src/prompts/
snippets.ts @2245ebd), the Python kimi-cli ("You are Kimi Code CLI",
agents/default/system.md @9ab1286) and goose ("You are goose",
prompts/tiny_model_system.md @361003e; its main "an AI agent called
goose" is left alone). Not covered, source closed or not read: Grok
Build, the new Kimi Code, Droid, Qoder, Copilot and the other agents in
magpie's internal/agent. REFUSED_HINT names Hermes Agent only, the one
seen refused.

As before: system and developer messages only, fixed strings so a cached
prefix stays put, both channels.

Run (mote, HOME in the run's folder): bun test packages/autoclaw: 48 pass,
0 fail; bun scripts/check.mjs autoclaw: ok.
Broken by hand: HEAD's index.mjs with the new tests: both new tests red;
the "Hermes Agent" entry alone removed: both red.
Not tried: a real AutoClaw request (no AutoClaw account here), so the
rewritten line is not yet confirmed a 200 on the gateway.
2026-10-30 02:38:29 +08:00
yetone 744e1e26f3 autoclaw 0.2.12: the overseas chat sends the official 2.0.3 fingerprint, and X-Tm "linux" on Linux as the official client does (#367)
menhouran captured the official AutoClaw 2.0.3 Linux chat request and
corrected the report behind 0.2.7: the official client sends X-Tm "linux",
not "linux-x64". The overseas gateway refuses "linux" only beside a
non-official fingerprint (X-Channel AutoClaw4, X-Version 1.18.1, no
X-Auth-*); "linux-x64" got through only because it isn't the one value
checked.

Read from the official client itself: AutoClaw-2.0.3-x64.AppImage from
autoclaw.z.ai's Linux download (sha512 matches latest-linux.yml),
resources/app/dist/main.cjs, extracted with 7zz and never run.
createZworkManagedRequestHeaders and createZworkManagedModelRequestResolvers
build the chat headers:
- X-Tm from managedPlatform(): darwin mac, win32 win, else process.platform
  as is (Linux is "linux" on x64 and arm64);
- X-Auth-Sign = md5("100003&<seconds>&<appKey>"), the same identity and
  signature the plugin already sends on its sign-in/wallet paths;
- X-Channel official, X-Version app.getVersion() (2.0.3), X-Lang the
  product language (en in the reporter's capture), X-Product autoclaw,
  X-Client-Type pc, x_trace_id autoclaw-desktop;
- X-Request-Id = X-Trace-Id = a randomUUID per attempt; X-Session-Id the
  session's UUID; X-Authorization Bearer, no Authorization;
- the request goes through the OpenAI SDK 6.26.0 in Electron 42.6.1
  (Node v24.18.0), which adds User-Agent "OpenAI/JS 6.26.0" and
  X-Stainless-* (OS/Arch through the SDK's own normalizers).

The overseas chat now sends that set. X-Session-Id is a UUID derived from
the conversation's first non-system message, so it stays the same across a
conversation's turns as the official one does. The caller's own
X-Stainless-* headers are dropped. bizHeaders (sign-in, refresh, wallet,
check-in) keep AutoClaw4/1.18.1 and send X-Tm "linux" again, as before
0.2.7, when they worked on Linux. README says what is sent and that
linux-x64 was a bypass.

Not changed: the overseas chat path keeps /v1/chat/completions, which the
reporter verified; the official client posts to .../autoclaw/chat/completions.
X-Stainless-Timeout is 600, the SDK default when no per-request timeout is
passed; whether zwork passes one wasn't traced to the end.

Run: HOME=$(mktemp -d) bun test in packages/autoclaw on mote, 46 pass;
bun scripts/check.mjs autoclaw ok; the same suite on Linux (wsl-run,
magpie-desktop) 46 pass. The new tests on origin/main's index.mjs: 4 fail
(the three #367 tests and the UA check in the 406 test).
Not tried: a real overseas account (none here), on Linux or anywhere; the
reporter is asked to confirm on #367.
2026-10-29 01:46:07 +08:00
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
yetone d8cfee3bba autoclaw 0.2.10: WorkBuddy's "powered by GLM-x" opening line and "You are CodeBuddy Code" are rewritten, not a 406 (#466)
larrylinli (plugins#466, Windows, magpie 0.1.1844, autoclaw 0.2.9,
autoclaw-cn/zaicoding_glm-5.3) had every first WorkBuddy 5.9.3 request
fail with 406 in 0 / out 0. WorkBuddy renders a custom GLM model into
the system prompt's opening line, "This conversation is powered by
GLM-5.3 · AutoClaw 国内 (Zhipu)", which is ZCode's opening-line wording.
The reporter bisected the real 163,730-byte request against the CN
gateway: "This conversation is powered by GLM-<version>" is a 406 in any
case and anywhere, while a bare "GLM", "ChatGLM-5.3", "The conversation
..." and "powered by the GLM-5.3 model" are 200; the whole request
replayed with only that line rewritten is a 200. A second string,
"You are CodeBuddy Code" (WorkBuddy's CLI template), is also a 406 in
their probes; "You are CodeBuddy" passes.

So the request content is refused, not the account or the model: a
small request on the same account and channel 0.4s earlier was a 200.
FLAGGED gets both, with the rewrites the reporter found answered:
- "This conversation is powered by GLM-<v>" -> "... by the GLM-<v>
  model" (the version stops before a sentence's closing period);
- "You are CodeBuddy Code" -> "You are the CodeBuddy Code CLI".
Like every FLAGGED entry they apply to system and developer messages on
both channels; a user message is left as written.

This is not the workbuddy plugin: WorkBuddy is the client here, sending
to magpie, and the provider is AutoClaw. workbuddy 0.1.43's effort and
gzip change is unrelated.

Run (mote): HOME=$(mktemp -d) bun test packages/autoclaw (40 pass);
bun scripts/check.mjs autoclaw green.
Broken by hand: HEAD's index.mjs with the new test: red (Received "This
conversation is powered by GLM-5.3 · AutoClaw 国内 (Zhipu)").
Not tried: the real AutoClaw gateway (no AutoClaw account here); the
406/200 table is the reporter's. Not changed: a general shape-based
fallback (#236) instead of one entry per string.
2026-10-28 22:46:17 +08:00
yetone 26502bf93e autoclaw 0.2.9: a history the chat gateway can't read goes put right, not as a bare 500 (#437)
tmuer (plugins#437, Windows 11, autoclaw-cn, zaicoding_glm-5.3, plugin
0.2.8) had one dsh request in 48,799 fail after 65s with AutoClaw's 500
{"message":"parse response failed"}, in 0 / out 0. Sent straight to the
CN gateway with the plugin's headers, each of six body fragments got
that same 500, while a bad model name got 400 "非法模型".

Of the six, those an agent's history can hold are now put right before
the body goes, on both channels (tidyBody):
- a message's null or missing content goes as "";
- an earlier turn's reasoning_content is left off (AutoClaw's own client
  sends none back);
- a tool call's arguments that aren't a string go as their JSON, "{}"
  for none (the call is kept, so its tool result still pairs);
- tools that aren't a non-empty list are left off with tool_choice.
Not changed: an empty messages list (the plugin always puts the system
prompt first, so none reaches the gateway) and a tool schema's
parameters.type (no agent sends "nonsense"; the reporter found every
real schema shape answered 200). $schema and strict stay, as the
reporter's own tests had them answered. max_tokens is still left off:
the gateway turns it away.

Retry on a 500 is magpie's: a plugin's 500 is retryable there
(gateway/fallback.go retryable, status >= 500) and the next member of
the group is asked when there is one. The plugin doesn't retry it.

Run: packages/autoclaw `bun test` (39 pass); `bun scripts/check.mjs`
all green.
Broken by hand: index.mjs at HEAD with the new test: red.
Not tried: the real AutoClaw gateway (no AutoClaw account here); which
of the shapes the reporter's one 65s failure had is not in its record.
2026-10-28 00:04:17 +08:00
yetone 1bd45a8d17 autoclaw 0.2.8: the credit balance is the card's balance, not a meter reading "剩余 100%" (#376)
moxuanchen: AutoClaw's credits are a bare balance with no limit and no
amount used, but usage() also sent them as a window with used: 0, so the
card read "500 积分 · 剩余 100%" whatever was left. The total, and the
wallets it breaks into, now go in balance only ("1234 积分(赠送积分 500 ·
会员积分 734)"). The daily check-in row stays a window.

Not changed here: magpie's card gives every window a share, so an aside
row that only carries text (the check-in row here, and the same pattern
in cline, cursor, factory and zcode) still shows "· 0% used / 100% left".
That is magpie's rendering, not this plugin's.

Run: HOME=<scratch> bun test packages/autoclaw, 38 pass; the new test is
red on 0.2.7. bun scripts/check.mjs autoclaw ok. Not tried against the
real API.
2026-10-25 14:25:33 +08:00
yetone ae2ed19e47 autoclaw 0.2.7: on Linux, X-Tm is "linux-x64" as the official client sends, not the "linux" the overseas gateway refuses (#367)
menhouran found that autoglm-api.autoglm.ai answers X-Tm "linux" with
403 {"message":"forbidden"} for a valid token, and "linux-x64" (what the
official AutoClaw Linux client sends) with 200. The plugin built X-Tm
from process.platform, so every overseas chat on Linux failed and read as
"AutoClaw 登录已失效". X-Tm is now mac / win / linux-x64; the User-Agent
keeps "(linux-x64)" from process.platform and process.arch as before.

Not changed: both hosts answering 403 is still reported as an expired
sign-in. The plugin's tests deliberately treat a bare 403 that way, and
what an expired token gets from this gateway hasn't been seen, so the
mapping is left alone.

Run: HOME=<scratch> bun test packages/autoclaw, 37 pass; the new test is
red on 0.2.6. bun scripts/check.mjs autoclaw ok. Not tried against the
real API or on Linux.
2026-10-25 14:25:33 +08:00
yetone a9b57b6fb9 autoclaw 0.2.6: user-profile carries the account's own device id, not "magpie-plugin" (#355)
fetchUserProfile sent `device_id: "magpie-plugin"`. AutoClaw 1.18.5's own
client (app.asar, getUserInfoWithAccessToken -> withWebInfo) sends the
device id the account signed in with (getAuthState().deviceId), a 64-hex
id. The plugin already generates such an id per login (newDeviceId) and
sends it with the login; the server writes it into the tokens' device_id
claim. user-profile now sends that id: the login's own at sign-in, the
refresh token's claim on refresh (old accounts included), "" only when no
token carries one, as refreshTokens already does.

Found by the new test: the global chat path forwarded magpie's x-magpie-*
hint headers to the vendor. They are now dropped there (the CN path builds
its own headers).

Run:
- bun test (packages/autoclaw): 36 pass, 0 fail
- bun scripts/check.mjs: ok
- no-magpie.test.mjs against HEAD's index.mjs: 2 of 2 red (device_id
  "magpie-plugin", then the hint headers)

Not tried: a live run. There is no AutoClaw account to sign in with.
2026-10-24 17:37:27 +08:00
yetone dd8caac45b autoclaw 0.2.5: a banned account keeps its sign-in and says the ban, not 登录已失效
小八 (Discord, 2026-10-23): a banned AutoClaw account answers
HTTP 403 {"code":410004,"message":"The account has been banned"}.
The plugin read every 401/403 as an expired sign-in, so magpie dropped
the token from plugin-auth.json and the user never saw why. Signing in
again gets the same account and the same refusal.

A body whose code field is 410004, or whose code/message field (message,
msg, error.message) names a ban or account restriction (banned, 封禁,
封号, 账号异常, account suspended/frozen/disabled/blocked/restricted,
账号被冻结/停用/禁用), is now the account's refusal, not the sign-in.
Only those fields are read, never the whole body. A true token expiry
(401/403 with any other code or message) is still expired.

Every route that mapped 401/403 to expired:
- overseas loader: 403 permission_error with the vendor's words and
  X-Magpie-Sign-In: kept; the second host isn't asked (a ban is the
  account's on every host, as a spent quota already was).
- CN managed loader: the same.
- refresh: an envelope ban throws "AutoClaw: <message>" with signIn
  "kept"; a non-envelope 401/403 naming a ban does too, every other one
  stays expired.
- usage: the wallets read said "积分接口无数据" for a ban; it now returns
  the vendor's words with signIn "kept".
- check-in: taskList threw 登录已失效 for any 403; a ban now says the ban
  and stops the host rotation.
- models: provider.models makes no request, nothing to change.

Siblings with "every 401/403 is expired" and no vendor-shaped ban
evidence, listed and left alone: qoder (refreshJob, patSignIn),
codearts (withSignInMark, 403 on chat), cline (clineApi default lapsed),
minimax (accountCall), kiro (refresh 400/401/403), opendesign (usage
preflight, models), trae (refresh 400/401/403).

Run at this head (worktree from origin/main 929a8b3):
- packages/autoclaw: bun test (sandbox TMPDIR/HOME) 34 pass, 0 fail.
- repo root: bun test 2157 pass, 0 fail across 188 files.
- bun scripts/check.mjs: exit 0.
- Broken by hand, each red: overseas loader back to quotaRefusal only,
  CN loader back to quotaRefusal only, refresh envelope ban check off,
  refresh non-envelope back to "expired", usage wallets ban throw off,
  check-in break-on-ban off, 410004 dropped from the codes. The new tests
  against origin/main's index.mjs: 6 of 6 red.
Not tried: a real banned account (none at hand); the bytes are the
reporter's.
2026-10-23 02:04:23 +08:00
yetone f906a22600 autoclaw 0.2.4: a 403 for a spent quota is a 429 with the gateway's words, not 登录已失效 (#274)
The CN managed gateway answers an exhausted free quota with
403 {"code":810000,"message":"GLM-5.3 免费额度已用完,开通连续包月会员继续使用"};
the reporter's same token got as far as "400 非法模型" with an unknown model,
so the sign-in is good. Both chat paths read every 401/403 as a dead
sign-in, so magpie showed 登录已失效 and sent the user to sign in again.

A 403 whose JSON body carries code 810000, or a message saying the quota or
balance is spent (额度, 余额不足, 用完, 用尽, quota, exhausted), now goes on as
a 429 with "AutoClaw: <the gateway's message>" and X-Magpie-Sign-In: kept. On
the overseas path such a 403 isn't asked of the second host. A 401, and any
other 403 (no body, another code), is still the sign-in, as before.

Run at this commit on origin/main 5ec8377: bun test in packages/autoclaw 28
pass 0 fail; bun scripts/check.mjs autoclaw ok. Broken by hand: with
0.2.3's index.mjs both new tests fail. The fixture is the reporter's body;
not tried against a live AutoClaw account (none here).
2026-10-20 22:10:42 +08:00
yetone 57fc069410 autoclaw 0.2.3: usage-path signing remembers each sign-in, not the provider (#254)
With signinOnUsage on, maybeSignin remembered a day's success under the
provider id, so after the first AutoClaw account signed in, every other
account of that provider was skipped until the next day. #254's reporter
has four sign-ins under two default display names and saw exactly one
extra account signed this way. The key is now the sign-in's uid, or a
hash of its refresh token for an old account that has none, for both the
refresh and the usage path.

magpie's own daily check-in (the native checkin hook) skipping same-name
accounts is the main part of #254 and is fixed in magpie itself.

Run:
- bun test packages/autoclaw: 26 pass, 0 fail. The new test drives usage()
  for four accounts sharing one display name (two with uid, two without);
  on the old index.mjs it fails at the second account ("今日未签(+400)").
- HOME=$(mktemp -d) bun test (whole repo): 1865 pass, 1 fail + errors in
  packages/devin's CLI tests (30s timeouts) and a trae stream connection
  reset, at load average ~168; neither package is touched here. Rerun of
  devin+trae alone: 252 pass, 1 devin timeout.
- bun scripts/check.mjs: all packages ok.
2026-10-20 16:26:17 +08:00
yetone dff29df402 autoclaw 0.2.2: ZCode's and pi's identity lines are rewritten for the CN managed gateway (#245, #236)
autoclaw-cn's managed gateway (autoglm-acceleration-api.zhipuai.cn) answers
406 when the system text carries an agent identity line FLAGGED doesn't
cover. Two more entries, in the table's own style:

- "You are ZCode" (any case, anywhere; #245's probes) -> "You are the ZCode
  agent". #245 found "You are an interactive ZCode agent ..." answered 200,
  so the gateway reads the literal run, which the rewrite breaks.
- "operating inside pi, a coding agent harness" -> "operating inside the pi
  coding agent harness" (#236). pi's line wasn't probed, so the rewrite
  breaks both "inside pi" and "pi, a coding agent harness" and keeps pi's
  name for the model.

Both rewrites are fixed strings, so the same prompt always leaves the same
way and a cached prefix stays put. Only system and developer messages are
rewritten, as before. Claude Code's entry is unchanged. REFUSED_HINT names
ZCode and pi.

No general fallback: agents such as opencode put the user's own AGENTS.md
into the system text, so a pattern like "You are X, a ... agent" would
rewrite the user's words, and nothing shows the gateway matches that shape.

Tests use each reporter's literal line: unflagged, unflag's role scoping
(ZCode in a system part rewritten, the same line in a user message and pi's
in a tool message untouched), and the CN managed path end to end.

Run (worktree at origin/main 47fbf63):
- bun test packages/autoclaw/: 23 pass, 0 fail
- bun scripts/check.mjs autoclaw: ok
- HOME=$(mktemp -d) bun test: 1808 pass, 1 fail, the trae stream.test
  "connection reset" under the full suite (#124, open); packages/trae/
  alone 160/160 three times
- broken by hand: ZCode entry removed -> 3 red; pi entry removed -> 2 red;
  unflag's role check removed -> 2 red
- not tried against the real gateway: no autoclaw-cn account is signed in
  here
2026-10-19 17:42:06 +08:00
EuraxluoandHuHong_Tao f6adc99a9c autoclaw 0.2.1: CN managed gateway, request shaping on both paths, OAuth guide opened by the host (#197)
Brings together #191 (CN managed gateway), #196 (request shaping and identity lines) and the #183 sign-in fix.

- autoclaw-cn chat goes to AutoClaw 2.1.0's managed gateway (autoglm-acceleration-api.zhipuai.cn/autoclaw-proxy/proxy/autoclaw/chat/completions, on Zhipu's domain) with 2.1.0's headers and its four-model catalog. A 401/403 there marks the sign-in expired.
- Both providers get the same request shaping:
  - the official one-sentence system prefix, merged into the caller's system message (string or array);
  - max_tokens and max_completion_tokens dropped;
  - other agents' identity lines in system/developer messages rewritten (FLAGGED/unflag, from #196);
  - no X-Harness-Type.
- On the overseas path, a 406 explains itself and keeps the sign-in. Overseas chat now sends AutoClaw's own User-Agent instead of the host's. Its catalog drops zai_glm-5-turbo and the tdpsk models (400 upstream) and keeps the old limits.
- Overseas OAuth: authorize returns the loopback guide URL once the listener is up, and the host opens it, so there is no shell spawn any more. Navigating to the authorization page no longer aborts the session.
- autoclaw 0.2.0 -> 0.2.1.

What was run at 1fe91be (reviewer):
- bun test packages/autoclaw: 21 pass, 0 fail. bun scripts/check.mjs autoclaw: ok. git diff --check: clean. Merges cleanly onto main.
- magpie plugin host (magpie main cb05dc2d1), sandbox HOME, with a copy whose three hosts point at a local fake:
  - overseas: authorize gave http://127.0.0.1:18432/, the guide returned 200, and /open-auth plus /auth/callback-google finished the sign-in;
  - CN: SMS sign-in worked;
  - streamed chat on both providers returned 200;
  - the fake received the prefix with "You are Claude Code" rewritten and no max_tokens on both paths; User-Agent AutoClaw/2.1.0 on CN and AutoClaw/1.18.1 overseas; no X-Harness-Type.
- Not tried: real accounts or the live gateways (no credentials used).

Co-authored-by: HuHong_Tao <3596843010@qq.com>
2026-10-17 16:59:42 +08:00
hubo 423e78e49c autoclaw 0.1.0: AutoClaw (Zhipu OpenClaw) provider plugin (#53, hubo1989)
Adds packages/autoclaw, @magpie-community/opencode-autoclaw-auth, for AutoClaw (Zhipu OpenClaw).
- Providers autoclaw (oversea, web sign-in through Google or z.ai) and autoclaw-cn (CN, phone SMS).
- Reads the credit balance and runs the daily check-in through auth.checkin.

Since the 10-08 review, this fixes:
- The OAuth callback takes a code only with the state the authorize page handed out (login CSRF). The legacy /callback is gone.
- The local server closes after 10 minutes even if magpie never calls callback, so port 18432 isn't held.
- The registry entry no longer uses ZCode's icon.
- The User-Agent names the real arch.
- The check-in row's used is 0.
- A 401 or 403 the upstream answers without an envelope marks the sign-in expired.
- New tests with a fake fetch cover loader().fetch, refreshTokens and the callback's state check.

What was run, at 356fb53 (8a0fd3a plus a merge of origin/main 118cf2e; the merge resolved registry.json, raccoon's entry beside autoclaw's):
- HOME=$(mktemp -d) bun test packages/autoclaw: 9 pass, 0 fail.
- Whole repo, HOME=$(mktemp -d) bun test: 1584 pass, 0 fail.
- bun scripts/check.mjs: all ✓.
- Broken by hand, each turning a test red:
  - Dropping the callback's state comparison: 1 fail.
  - Dropping the expired mark on a non-envelope 401: 1 fail.
- The package isn't on npm yet. magpie serves it from the dist branch until an owner publishes its first version.

Not verified: a real AutoClaw account, and the 10-minute server close (read, not tested).
2026-10-16 15:04:41 +08:00