Files
plugins/packages
yetone dea9e4e3b3 codearts 0.3.10: the international station and signing in from the CodeArts Agent (#998)
What changed
- Stations. A STATIONS table (mainland, international) is now where the
  signing fence comes from: SIGNED_HOSTS is every station's API hosts
  (https, default port, exact name), and each credential is signed only for
  its own station's hosts. An international credential reaches only
  snap-access.ap-southeast-1.myhuaweicloud.com and a mainland one never
  reaches it. Console hosts are never signed. The plugin's mainland snap URLs
  (and a config `api` on the mainland snap host) are rewritten to the
  credential's station at the fetch choke points. A lookalike host is not
  rewritten, and is refused.
- International usage. When `package.is_token_package` is true,
  statistics/plugin's usageTokenChatMessages is a "Tokens" window:
  usage_token_num of package_token_amount (e.g. "131 / 5.0M"), resetting at
  end_date, span start_date to end_date. The plan is package_name_en there
  (package_name_cn on the mainland). The international station has no opengw,
  credit batches or daily check-in in the issue's probes, so none of them is
  asked there; check-in answers "inactive". The loader's baseURL is the
  station's /api/v2.
- Sign in from the CodeArts Agent on this machine. A second method, offered
  only while the IDE's state.vscdb exists (macOS ~/Library/Application
  Support, Windows %APPDATA%, Linux $XDG_CONFIG_HOME or ~/.config, then
  codearts-agent/User/globalStorage/state.vscdb; MAGPIE_CODEARTS_IDE_STATE
  overrides). Key huaweicloud.codearts-snap, userInfoKey.originData, as in
  the issue. The file (and its -wal/-journal) is copied to a temp folder and
  only the copy is opened; its statement is finalized before the close so
  Windows can remove the copy. A missing, unreadable, half-written or
  incomplete file, or an unknown stationType, is "unknown": no method, or a
  failed sign-in saying why, never with a secret. The credential is checked
  once against current/user on its station. It has no refresh token, so it
  is renewed by reading the IDE's file again, never through STS; until the
  IDE has renewed it (or when the IDE is on another account or station) a
  renewal fails for now only, and the sign-in is kept. The account is the
  IDE's domainId.
- README (en and zh) documents both. The browser method keeps index 0.

What ran (this tree; the root suite at base 740e1af2, the package and
check again after the rebase onto b4916d41, which touched window-warmup only)
- WSL magpie-desktop: HOME=$(mktemp -d) bun test packages/codearts
  (194 pass), bun scripts/check.mjs codearts (ok), root HOME=$(mktemp -d)
  bun test: 8315 pass, 19 skip, 0 fail across 584 files
- Windows (win-run): bun test packages/codearts, 194 pass, including
  ideStatePath on this system (%APPDATA%) and the temp-copy cleanup.
- macOS (mote-run): bun test packages/codearts, 194 pass.

Broken by hand, each red and then restored
- signing by the shared host set instead of the credential's station:
  "a credential is signed only for its own station's hosts" and the
  international end-to-end test
- prefix host match: the lookalike test (...ap-southeast-1...com.evil.com)
  and the existing host test
- onStation by prefix: its lookalike test
- token window without the is_token_package gate: the token window test
- SQLite on the IDE's own file instead of the copy: the locked-database test
- IDE renewal through STS: the never-by-STS test and the end-to-end test
- an unchanged IDE file taken as a renewal: the never-by-STS test
- the IDE method always offered: the offered-only-while-there test
- a stored sign-in without a security token accepted: the unknown-cases test
- no finalize before close (Windows): "leaves no copy of the sign-in behind"
  (passes on Linux and macOS either way; Windows is the case it is about)

Not tried
- No real CodeArts international account and no real CodeArts Agent install
  were used; every test uses fake fetch and temp-dir sqlite fixtures.
- The international chat path: the plugin sends /api/v2/chat/completions as
  on the mainland; the issue's probes used /v1/chat/chat.
- The international model list (/v1/model/builtin there); the built-in
  catalog is the fallback.
- The macOS and Linux IDE paths follow the VS Code/Electron convention; the
  issue's evidence is a Windows path. Mainland stationType words are a guess
  (empty is mainland).

Reported-by: AyakaChen1
2026-11-11 20:59:18 +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