Commit Graph
263 Commits
Author SHA1 Message Date
yetone b9e5bc6cb3 gui: Rex is a session terminal, opened through its rex CLI (#4565)
Rex (com.superlogical.rex) claims no .command file, so Launch Services
never listed it and `open -a` can't hand it a script (StringKe).
Sessions' terminal list now offers Rex when its CLI is found: a native
`rex` on PATH, or one inside a Rex*.app in /Applications or
~/Applications (Rex puts rex on PATH only in its own terminals). Perl's
Rex installs a script named rex too, so only a Mach-O or ELF program
counts. Resume, carry and an agent's Open then run
`rex run --label <title> -- /bin/sh -c '<command>; exec login shell'`:
no shell parses the label or the command on the way. With no session
to add a tab to (exit 3) it runs `rex new`; with Rex's server not
running (exit 4) the error says to open Rex. Rex is then brought
forward with `open -b`. The GUI already lists s.terminalApps, so no
JS changed. reference.md's Session terminal says it.

Parts 2 to 4 of #4565 (accounts run per account, OSC 7501 status,
folder mapping) build on #992, which isn't merged; not done here.

Ran, at this tree on origin/main e90a635a9, through mote-run:
- go test ./internal/gui -run 'TestFindRex|TestOpenInRex|
  TestDiscoverTerminals|TestTerminalOpenArgs|TestAgentOpen': ok.
  TestOpenInRex runs the real sh script with SHELL=/usr/bin/true and
  checks the command ran in its folder, and a label holding $(...) and
  quotes stays one argument.
- go vet ./...; GOOS=linux (-tags nogui) and GOOS=windows go vet and
  go build: ok (at the pre-rebase head; go vet ./... again rebased).
- Full suite, go test -tags nogui -timeout 45m ./..., at the
  pre-rebase head: every package ok but internal/gui, red on
  TestSettingsSaveKeepsWhatItDoesNotSend (#4514, red the same on
  origin/main e90a635a9) and TestColdTurnsTaken (#4510). Rebased,
  internal/gui and internal/provider whole again: red on #4514 only.

Broke by hand, each red, then restored: withRex taken out of
discovery (TestDiscoverTerminalsOffersRex); the exit-3 fallback to
rex new turned off (TestOpenInRex: "rex: Error: no session"); the
native-program check dropped for PATH (TestFindRex took the Perl
script).

Not tried: the real Rex app or rex binary. Its installer needs a
Discord sign-in, so the CLI was driven from Rex's docs only; whether
`rex run` with no -s from outside Rex targets the shown session or
exits 3 is not confirmed. Not run on Linux or Windows (Rex's Linux
build, and the tests skip on Windows). No GUI Playwright run, as no
JS changed.
2026-10-31 19:35:16 +08:00
yetone 01813c681a accounts: switch next takes accounts that are off too, as Use does (#4532)
`magpie accounts switch claude next` (v0.1.2376) took only accounts
switched On. An account the user signed in to themselves, picked up by
rememberLogins, starts off, so next said there was nothing to switch to
while the switch list and the GUI's Use took that same account
(StringKe). On is whether the gateway routes to an account beside the
one signed in, not whether the agent may be signed in to it, so
NextInOrder now takes every switchable account (no token, no home of
its own) that isn't the signed-in one and isn't spent, On or not.
NextLogin, the automatic switch when one is used up, still moves only
to accounts that are On; that is unchanged. reference.md and
providers-accounts.md say so.

Ran, at this tree on origin/main e90a635a9, through mote-run:
- go test ./internal/provider -run 'TestNext|TestSwitch': ok;
  TestNextTakesAccountsThatAreOff (codex and claude: accounts left
  off as picked up; next takes the first, then the second once the
  first is at 99; NextLogin doesn't move to an off one) and
  TestNextInOrder's new cases.
- go vet ./...; GOOS=linux (-tags nogui) and GOOS=windows go vet and
  go build: ok (at the pre-rebase head on 0379f2610; go vet ./...
  again at the rebased head).
- Full suite, go test -tags nogui -timeout 45m ./..., at the
  pre-rebase head: every package ok but internal/gui, red on
  TestSettingsSaveKeepsWhatItDoesNotSend (#4514, red the same on
  origin/main e90a635a9, run alone) and TestColdTurnsTaken (#4510,
  red only in full gui runs). After the rebase internal/provider and
  internal/gui ran whole again: provider ok, gui red on #4514 only.

Broke by hand: put the l.On filter back in NextInOrder.
TestNextInOrder and TestNextTakesAccountsThatAreOff went red ("codex
has no other account in magpie to switch to", wrong picks). Restored.

Not tried: a real Claude or Codex account, or the CLI command end to
end; the tests use sandbox fakes under a test HOME. Nothing here
touches ~/.claude or the Keychain.
2026-10-31 19:35:16 +08:00
yetone d8cf4f74f9 plugins: a plugin's package.json names its row with magpie.name (#4558, MYCF711)
A plugin installed from git whose package.json says
"magpie": { "name": "华为云 HUAWEI" } read as its dependency key
(magpie-officeace) on Settings → Plugins. Bun takes no non-ASCII key, so
a package outside the community's list had no way to show a readable
name. magpie.name was never read at all: #3608's route (MYCF711's branch
1cc33700) didn't reach main, so no release has it, git or npm.

plugin.InstalledName reads magpie.name from the installed package's own
package.json, beside magpie.icon (installedOwn, one parse for both): one
line of at most 80 bytes, no control or format characters (a bidi
override would show it as another name), else nothing. /api/plugins gives
each row it as ownName, and plugins.js's shownName takes it after the
community list's name and before the git package or the spec, so a
listed package is still named by the list. The row's page, the "is up to
date" status and every message that names the row (options, prefer, Update
all) go through shownName; a page plugin's sidebar tab takes it when the
page names no title (windowParts). It is never used to resolve a name and
never shown with the community badge. Not changed: the CLI's plugin list
(the dependency key, as the reporter expects), Discover's cards for
uninstalled GitHub/npm packages, and magpie.summary. Documented in
docs/reference.md and site/public/docs (en, zh, ja).

Run:
- mote: go test -timeout 45m ./internal/plugin/ ./internal/gui/ — plugin
  ok; gui red only in TestSettingsSaveKeepsWhatItDoesNotSend (#4514) and
  the AppKit window tests killed at their deadline (TestPanelCloseHidesIt,
  TestPluginPageLoadsItsFilesInTheWindow, TestMainWindowCorners, …;
  #4125, #2645). The first three run the same red on origin/main 7aa67e9e5.
- mote: go vet, GOOS=linux go vet -tags nogui, GOOS=windows go vet on
  internal/plugin and internal/gui: clean. gofmt -l internal/: nothing.
- wsl-run (magpie-desktop): plugin-own-name.test.cjs, Chromium and
  WebKit, en/zh/zh-TW/ja/de at 980 and 420: 22/22. Every plugin*,
  plugins-*, agent-plugin*, account-plugin*, signin-paste-plugin,
  sidebar* and i18n-keys file (67): all green but i18n-keys "a plugin's words are its own" (#4524), plugin-card-update webkit en/zh (#3079) and plugin-github-filter webkit ja 420px (#4564, filed now), each red the same at origin/main 7aa67e9e5
- Rebased on origin/main 7b883cc61, mote: -run "Budget|OwnName|TestPluginsState|
  TestWindowParts" on internal/gui and internal/plugin: ok (core scripts
  under the budget, no raise).

Broken by hand:
- InstalledName returning "": TestPluginsStateGivesAGitPackagesOwnName red
  (ownName "", and the sidebar title magpie-officeace).
- shownName without e.ownName: plugin-own-name.test.cjs red, the row
  reads 'magpie-officeace'.

Not tried: the desktop window itself, and a real git repository with
magpie.name (the fixture is shaped from the reporter's installed
package.json: name magpie-officeace, version 0.2.4).
2026-10-31 18:30:39 +08:00
yetone 64cdb68035 accounts: import claude reads claude-swap's export (#4532)
StringKe (#4532) is moving from claude-swap (cswap 0.29.0) to magpie,
and `magpie accounts import claude` didn't read cswap's export. It does
now: parseLoginImport takes cswap's format-1 envelope ({version: 1,
swapVersion, encrypted, accounts: [...]}, read from cswap 0.29.0's
transfer.py) and cswapEntry reads each account's
credentials.claudeAiOauth and config.oauthAccount: email, account and
organization uuid, and the organization's name. The tokens are kept as
the file has them; magpie asks Anthropic nothing.

Refused, each with what to do: an encrypted export (decrypt with gpg -d
first), another format version, a Codex entry, and an API-key entry
(added as a key instead). An entry with no refresh token is accessOnly,
as for every other file. cswap's alias becomes the account's name in
magpie (importNames) when the account was added or updated, has no name
yet, and no other account is called that or signed in as it, so the
name stays a selector for one account (the previous commit's rule).

testdata/cswap_0.29.0_export.json is claude-swap 0.29.0's own `cswap
export` output, made from its source in a sandbox HOME in WSL with two
accounts and fake tokens (cswap's add step asked Anthropic once with
the fake refresh token, which it called dead; no real account was
involved).

Run (mote unless said):
- At this commit's tree (on origin/main 47173f593):
  gofmt -l clean; GOOS=linux go vet -tags nogui ./... and GOOS=windows
  go vet ./... ok; go test -timeout 45m ./internal/provider (ok 100.7s),
  ./internal/cli (ok 31.8s), ./internal/gui: red on 11 real-window
  AppKit tests killed at their deadline on mote over ssh (#4125, #2645)
  and TestSettingsSaveKeepsWhatItDoesNotSend's SearchAll, red on main
  (#4514); none touches accounts.
- Rebased on origin/main 7aa67e9e5 (4 commits, none in accounts), then
  at the pushed tree: go test ./internal/provider (ok 163.5s),
  ./internal/cli (ok 55.8s), ./internal/gui -run 'Budget|I18n|Key'
  (ok), gofmt -l clean.
- TestImportCswapExport, TestImportCswapRefusals. Broken by hand, each
  red: no cswapEntry, no importNames, the taken-name check off (red on
  "the team seat took pro's name"), the encrypted check off, no
  organization name.
- CLI in a sandbox HOME in WSL: import of the fixture adds max@x.com and
  team@x.com, a second import says both are in magpie already, the alias
  "work" is team's name, `accounts forget claude work` picks it;
  `accounts import --help`, a missing file and an unknown agent each say
  what's wrong.
- On mote over ssh the same import added one account and failed the
  other on the Keychain ("Unable to obtain authorization", no GUI
  session there), and the failed one was still saved, so the second
  import called it "in magpie already". That's addLogin writing
  logins.json before signing Claude Code in, the same for every import
  and sign-in, not this change; not changed here.
- GUI: login-import in Chromium and WebKit on Linux (WSL), green.

Not tried: an export from a real cswap install with real accounts,
Claude Code running on an imported account, or cswap's encrypted export
decrypted and imported. A cswap account's plan (subscriptionType) isn't
carried: magpie reads it on the first usage read, as for CLIProxyAPI.
2026-10-31 18:22:02 +08:00
yetone a7b47d57ec accounts: removing the account Claude Code is signed in to switches it to another first (#4532)
StringKe (#4532): removing the signed-in Claude account was refused with
SignedInError, while Codex's switched away first. ForgetLogin now does
the same for Claude Code: nextOnForget picks another account (on first,
then one whose sign-in holds), SwitchLogin signs Claude Code in to it,
and only then is this one forgotten. If that switch fails, nothing is
removed and the error says why.

nextOnForget leaves out accounts Claude Code or Codex can't be signed in
to (switchable: not a setup-token account, not a Codex account held in
another folder). Claude Code is never signed out: when the account is
the only one it can be signed in to, it is kept, with
SignedInError{Only} (GUI code signed_in_only), which says to add another
account first or sign out in Claude Code. The GUI gives the signed-in
Claude row a Remove when another account it can use exists, and no
Remove or Sign out otherwise. Claude Code's own credential is never
deleted; forgetClaudeDir removes only the forgotten account's own
folder and its folder's Keychain item, and claudeHolders' check of
other records holding the same token is unchanged.

Tests: TestForgetLiveClaudeSwitchesFirst, TestForgetOnlyClaudeIsKept
(replacing TestClaudeInUseStillRefused, which held the old refusal);
codex-signout.test.cjs gets three Claude cases (Remove with another;
only + setup-token: no Remove, reason in zh/zh-TW/ja/de; the
signed_in_only refusal in en/zh).

Run (mote, sandbox HOME through the test helpers):
- go test ./internal/provider ./internal/cli, vet and gofmt at the
  stack head: in the next commit's body (one tree, same run).
- Broken by hand, each red: Claude not switched first
  (TestForgetLiveClaudeSwitchesFirst), Only left false, a setup-token
  account counted as another, nextOnForget unfiltered
  (TestForgetOnlyClaudeIsKept).
- GUI on Linux (WSL magpie-desktop), Chromium and WebKit: codex-signout,
  own-signin-remove, saved-signedout-remove, login-import, claude-signin,
  account-alias and i18n-keys all pass but i18n-keys' "a plugin's words
  are its own", red on main (#4524). On mote, codex-signout passed in
  Chromium; its WebKit launches were killed with mote at load ~25 under
  other sessions' suites (#4125), so WebKit's record is Linux's.

CLI in a sandbox HOME (WSL, file credentials): forget of the signed-in
account by its name switched Claude Code to the other (.claude.json then
says max@x.com); forget of the only one was refused with the message
above and left it signed in.

Not tried: a real Claude Code switch on removal with real accounts, or
in the CLI against a live ~/.claude (sandbox only).
2026-10-31 18:18:37 +08:00
yetone 149e763e9e accounts: a name you gave an account picks it wherever an email does (#4532)
StringKe (#4532): `magpie accounts switch claude work` failed when "work"
was the alias; accountNamed matched the email only.

provider.AccountByName resolves a name (magpie accounts alias) among an
agent's accounts. It refuses a name two accounts share, and a name that
is another account's email or email part, so a name never picks the wrong
account. It is used by:
- accountNamed: accounts switch/on/off/remove/alias/cap and the rest
  that take <email>;
- provider pool --accounts;
- accountRef (GUI and account-cap): the exact email first, then a name,
  so another account's alias never shadows an email;
- account-cap's display, through AccountRefOf (it filtered by email).

Run (mote, at this commit):
- go test -timeout 45m -count=1 ./internal/provider ./internal/cli: ok
  (104.9s, 33.2s).
- TestAccountsAliasPicksTheAccount, new: switch, alias, pool --accounts
  and account-cap by name; a shared name and another account's email
  refused. Red with each part removed by hand: the accountNamed call,
  pool's resolution, the clash check, the shared-name check, accountRef's
  name step.

Not run: the GUI suite (no GUI file changed); real accounts.
2026-10-31 18:18:37 +08:00
yetone 15b83901ac accounts: switch to the next account with room, or the one with the most left (#4532)
StringKe (#4532), comparing magpie with cswap 0.29.0: there was no "switch
to the next account", and when every account was past its line the
automatic switch stayed on the spent one, where cswap moves to the account
with the most room left.

- `magpie accounts switch <claude|codex> next` (provider.NextInOrder) takes
  the other accounts that are on in magpie, from the one after the account
  the agent is on, wrapping round: the first whose allowance is known and
  has room, else the one with the most room left, and says it is past its
  line. A saved Claude account not read yet is read first (readSpare), as
  the automatic switch's spares are. With no reading of any it refuses
  rather than guess; for any other agent it asks for the account by name.
- NextLogin (shared by Codex and Claude Code): when the account the agent
  is on is spent and every spare is past its line too, it moves to the
  spare with the most room left (roomLeft: the fullest stopping window's
  distance below the switch share, or the account's own cap when lower),
  when that has at least roomMargin (1 point) more than the one it is on,
  so two all but even accounts don't trade the agent each look. A held,
  failed or unknown reading is never moved to. One model's own window
  still counts for nothing, as before.
- docs: reference.md (the automatic switch and `next`; its "a Claude
  account magpie knows nothing of is not moved to" was stale since
  readSpare), providers-accounts.md's Used-up switch row, the en/zh/ja
  start pages' command table, `magpie help`.

Run (on mote, sandbox HOME through the packages' TestMain):
- go test -timeout 45m -count=1 ./internal/provider ./internal/cli: ok
  (144s, 44s), at this change's tree before the next commit's edits.
- TestNextLoginTakesTheMostRoomWhenAllArePast and TestNextInOrder, each
  over codex and claude with three accounts: green; red with the fallback
  taken out of NextLogin (the two "most room" cases, both agents) and with
  NextInOrder not starting after the signed-in account ("the one after
  it", both agents). The "none has more by the margin" case fails without
  roomMargin.
- Built the nogui binary and ran in a fresh sandbox HOME on mote:
  `accounts switch claude next --help` (prints the accounts help),
  `switch claude next` and `switch codex next` with no accounts ("has no
  other account that is on"), `switch gemini next` (asks for a name),
  `switch claude nxt` (no such account), `switch claude` (usage).
- gofmt -l clean. Cross-OS vet: run at the head of this stack.

Not tried: a real switch between real Claude or Codex accounts; the CLI
`next` with real saved accounts (the provider tests cover the choice).
2026-10-31 18:18:37 +08:00
yetone a511b11d8b sync: an agent's model set back on a computer after a sync stays that computer's (hayden4608)
hayden4608 on Discord syncs two computers through GitHub, both with
Codex, and wants each one's Codex default model kept apart. Until now
the agents part carried every agent field ("codex.model", effort,
provider...) as one set: A's pick went up, B's sync brought it over B's,
B's pick went up again and A's next sync took it back. The two
computers fought, and the only way out was turning "agents' models"
off for every agent.

Now a sync that brings an agent field over this computer's value
records what it brought (Brought) and what it wrote over (Replaced,
only when that was picked here, not itself brought). If the user then
sets the field back to the value the sync replaced, the field is this
computer's own (Own): it leaves the hashes, a sync no longer brings it,
and a push keeps the server's value, so the other computer is not
changed either. Every other new pick is an ordinary pick and still goes
both ways, so a computer that changes the model for everyone (and
TestSyncAgentDefaults' reset) still reaches the rest. Nothing to set
up: the user's own act on this computer decides it, and a synced value
never overrides it again.

Settings > Sync lists the kept fields in one row ("Kept on this
computer: Codex model ...") with a "Follow the others" button
(davsync/follow), which brings the server's values on the next sync and
ends the keeping. Restore brings everything and ends it too. The row is
drawn only while sync and agents' models are on and something is kept;
plain row and button, no new layout. app.js grew 623 bytes; the budgets
are raised by that with a note.

Tests:
- internal/davsync/own_model_test.go TestOwnModelStaysOnEachComputer:
  two sandbox HOMEs (CODEX_HOME per computer) on the GitHub fixture.
  A picks a1, B joins and gets it, B picks b1 (goes up), A gets b1, A
  sets a1 back (own; the server keeps b1), B picks b2 + effort +
  provider (A gets effort and provider, keeps a1), A picks a2 and a
  Claude model (both go up, B gets them), A follows (gets b2), B's b3
  reaches A. TestNewPicksStillGoBothWays: alternating new picks always
  reach the other computer.
- internal/gui/tests/sync-own-fields.test.cjs: the row in en, zh,
  zh-TW, ja, de at 420px, no overflow, Follow posts once and the row
  goes, no scroll; no row without own fields or with agents off.

Broken by hand, each red: noticeOwn off (own_model_test:122); any pick
after a sync counts as own (TestSyncAgentDefaults and own test:106);
keepServersOwn off (:166); the bring ignoring Own (:146); withoutOwn
off in the hashes (:143, a notice); Follow off (:182).

Run at this head (rebased on 47173f593) on mote:
gofmt -l internal/davsync internal/gui clean; go vet ./..., GOOS=linux
go vet -tags nogui ./..., GOOS=windows go vet ./... ok; go test
./internal/davsync ok, ./internal/backup ok, ./internal/gui ok but
TestSettingsSaveKeepsWhatItDoesNotSend (#4514, red on main) and the
eleven real-window AppKit tests (dock, panel, tray, corners), which
time out on mote at origin/main 47173f593 too (#4125, #2645);
-run 'Budget|Sync|Backup|Settings' passes TestCoreScriptBudget.
GUI (node --test): sync-own-fields, sync-note-show, github-sync,
s3-sync, sync-other-kind, sync-not-backup, sync-auto-restore,
sync-usage-error, i18n-keys. Chromium on mote: all pass but
sync-not-backup and sync-usage-error, whose chromium.launch({channel:
"chromium"}) segfaults on mote at origin/main 47173f593 too; on the
WSL box (magpie-desktop) they pass, 25 of 25 with sync-own-fields.
WebKit on mote hangs on launch for every file, untouched ones too; on
WSL all nine files ran: 49 of 52, the reds being i18n-keys' "a
plugin's words are its own" (#4524, red on main) and the first
page.goto of sync-own-fields and sync-note-show at 5s under nine
files at once, which pass run alone (9 of 9).
Red on main and not from this change: TestSettingsSaveKeepsWhatItDoesNotSend
(#4514), i18n-keys "Unmarked" (#4524).

Not tried: a real GitHub repo and a real Codex on two computers; the
CLI has no follow command (only the GUI and Restore end the keeping);
Undo after a Restore doesn't bring Own back.
2026-10-31 18:01:04 +08:00
yetone f68ddca370 install.sh: a Linux desktop gets the desktop app, or the command that installs its WebKitGTK; --gui and --tui choose (shuhai)
shuhai on Discord: on a Linux desktop install.sh installed the terminal
build, and a desktop user expects the app. The script chose by
`ldconfig -p` alone, and on Debian a user's PATH has no /sbin, so
ldconfig wasn't found and every Debian desktop got the terminal build
even with WebKitGTK 4.1 installed. Without the libraries, the only hint
was a line mid-output.

Now, with nothing asked (curl | sh stays unattended):
- the libraries are looked up with ldconfig from PATH, /sbin or /usr/sbin,
  and in the usual lib folders when there is no cache (NixOS, Guix);
  GTK 3 is checked beside WebKitGTK 4.1, which brings the rest the app
  links (readelf -d of v0.1.2359's magpie-linux-amd64: gtk-3, webkit2gtk-4.1,
  soup-3.0, javascriptcoregtk-4.1, glib, X11, wayland-client, glibc);
- libraries there: the desktop app, as before;
- a desktop without them: the terminal build, and last in the output the
  distribution's command (apt/dnf/pacman/zypper/xbps/emerge from
  os-release ID and ID_LIKE), "run this again", or --gui. A desktop is
  DISPLAY, WAYLAND_DISPLAY, XDG_CURRENT_DESKTOP/XDG_SESSION_DESKTOP/
  DESKTOP_SESSION, XDG_SESSION_TYPE x11/wayland, the user's logind
  Display session when its Type is x11/wayland/mir (over ssh; logind
  falls back to a tty login, which doesn't count), or a session file in
  xsessions/wayland-sessions under XDG_DATA_DIRS;
- headless without them: the terminal build, with no desktop advice;
- --gui: the app even before its libraries, with the package to add;
  --tui (or MAGPIE_CLI=1, kept) the terminal build on a desktop too;
- musl (Alpine): always the terminal build; --gui refuses, since the
  app is built against glibc.
Docs: reference.md Install, README en/zh, docs start FAQ (en/zh/ja,
#linux-build).

Run:
- shellcheck -s sh: only SC2010 at the uninstall's `ls | grep`, there
  before this change. sh -n and dash -n clean.
- site/install.test.mjs (5 new tests): 19/19 on mote (macOS sh) and on
  magpie-desktop through wsl-run (dash); CI's site step
  (sh -n + node --test site/*.test.mjs) 58/58 on magpie-desktop and 58/58
  on mote.
- Red on the old install.sh: tests 16-19 fail (desktop advice, headless
  advice, --gui, --tui). With the logind Type check taken out by hand,
  the headless test fails on login "135 tty".
- Real installs on magpie-desktop (Ubuntu 24.04, XFCE, WSLg, /bin/sh =
  dash), `cat install.sh | env ... sh -s`, stdin a pipe, into a /tmp
  sandbox HOME/XDG dirs/MAGPIE_BIN_DIR, each removed after, v0.1.2360
  downloaded from the real feed and `magpie version` run:
  session with DISPLAY/WAYLAND_DISPLAY: desktop app + menu entry;
  env -i with PATH=/usr/local/bin:/usr/bin:/bin: desktop app (the old
  script gave the terminal build here, run the same way);
  an ldconfig whose cache lacks the libs + DISPLAY=:0, and the same in
  env -i (found by /usr/share/xsessions): terminal build + the apt line;
  that with XDG_DATA_DIRS=/nonexistent: terminal build, quiet; --gui
  there: desktop app + the apt line; --tui in the session: terminal build.
  The first run found the tty-login fallback (logind's Display=135 is
  this WSL user's pts session), fixed before commit.
- site/install.test.mjs on Windows (win-run): 0/19, the same 14 old
  tests too: the box has no sh for spawnSync; CI runs this file on Linux
  only.

Not tried: a real Debian, Fedora, Arch or openSUSE box, or a box without
WebKitGTK installed (simulated with a fake ldconfig); the package names
were checked against each index (Ubuntu noble, Debian bookworm, Arch,
Fedora mdapi, Tumbleweed oss, void-packages, Gentoo), not installed. The
installed app wasn't opened (only `magpie version`), to keep off ports
other sessions use there. Termux and macOS paths are unchanged and their
tests pass.
2026-10-31 17:27:55 +08:00
yetone 33a284497e plugin options: a switch a provider plugin declares is saved where the plugin reads it (plugins#550)
`magpie plugin options cursor '{"wire_trace": true}'` wrote the entry's
options in plugins.json (a middleware's ctx.options), while a provider
plugin's switches (auth.options, the editor's Plugin options) are read
from settings' PluginOptions (input.magpie.option). The command said
"options set" and Wire trace stayed off.

Now a key that the plugin declares as a switch for one of its providers
(from the providers last listed, else asked of the plugin host) goes to
PluginOptions for that provider, through settings.EditPluginOptions, and
a running host is handed it (SetProviderOptions, 5s, best effort). Only
true or false is taken for a switch. The other keys go to plugins.json
as before; set with switches only, a middleware's options stay, less a
switch written there before. `off` puts every switch back to the
plugin's default and clears plugins.json's options. Shown with no value,
each switch is listed with its value. docs/reference.md and the plugins
page (en, zh, ja) say so.

Run at this head on mote: go test ./internal/cli ./internal/settings
./internal/plugin ok; gofmt -l clean; go vet darwin and GOOS=windows ok;
Linux go vet -tags gtk3 in WSL (magpie-desktop) ok.
Broken by hand: no key read as declared, and both new tests went red
(PluginOptions empty, the old switch left in plugins.json).
Not tried: the real CLI against a running magpie with the Cursor plugin
installed; a plugin not listed yet (the host path) is not in a test.
2026-10-31 16:46:14 +08:00
yetone ceeb73a0f1 app: the desktop app writes its log to app.log; magpie log and Settings › About › Log find it
rayem1w on X (0.1.2330, macOS) was asked for ~/Library/Logs/magpie/serve.log
while chasing a Codex "hit a snag" through the gateway, and had no such
folder. Only the launch agent (magpie daemon install, written by launchd)
and a gateway magpie tui left running wrote a log; the app opened from the
Finder, the Dock or the Start menu logged to a stderr nobody reads, on
every system.

Now runGUI and runPanel (magpie, app, tray, panel, a window view, a
magpie: link) call applog.Start before gui.Run. It sends the standard
logger (the gateway, the plugin host, providers and Wails' error handler
all log through it) to app.log as well as stderr, and points
debug.SetCrashOutput at it so a panic's trace is there too:

  macOS    ~/Library/Logs/magpie/app.log
  Windows  %LOCALAPPDATA%\magpie\logs\app.log
  Linux    $XDG_STATE_HOME/magpie/app.log, else ~/.local/state/magpie/app.log
  portable data/logs/app.log

app.log, not serve.log: on a Mac launchd writes serve.log for the service,
another process. The file is 0600. At 5 MiB it becomes app.old.log (two
files at most); when another magpie (an update's new process) rotated it
already, it is only opened again; when it can't be moved it is emptied.
stderr goes first, through a writer that never fails, since io.MultiWriter
stops at a failed writer and an app opened from Explorer has no stderr.

Secrets: the log calls name header names and paths without queries; no
key or token was found logged (grep of log.Print* in gateway, provider,
plugin, gui, agent). scrub masks bearer/basic credentials, key/token query
parameters and sk-, AIza, gh?_ and JWT shapes anyway.

How a user finds it: Settings › About › Log, with the path, Copy and an
Open that shows its folder (POST /api/settings/log/reveal; the row is
hidden in magpie web, which writes no file). magpie log prints where every
log is (the app's, app.old.log, the service's, the tui's background
serve.log); --path the app's alone, -n N its last lines, -f follows it
across a rotation. Docs: reference.md, gui-shell.md, site start (FAQ "Where
is magpie's log?" and the CLI table) and privacy (files on your computer),
en/zh/ja.

Run:
At 227ce6074 on origin/main fbb1b36d1:
- mote: go test ./internal/applog ./internal/appdir ./internal/cli ok;
  -run TestCoreScriptBudget ./internal/gui ok; GOOS=windows go vet
  ./internal/... and GOOS=linux go vet -tags nogui ./internal/... ok;
  gofmt -l clean. GUI, chromium: about-log (5 languages x 1100/420, and
  no row without a log), about-website, i18n-keys: 24 of 25, the one red
  "a plugin's words are its own" ("Unmarked") is the same at origin/main
  fbb1b36d1 (#4524).
- WSL (magpie-desktop), webkit: about-log and about-website 21 of 21.
- Windows (win-run): applog, appdir, tui ok; cli ok but
  TestLibraryMCPHub's TempDir cleanup (#4140, mcp-npm, not this change).
- WSL full go test -tags nogui -timeout 45m ./... at the previous base
  03f609e3f: every package ok but reds that fail the same at origin/main
  03f609e3f alone: TestSettingsSaveKeepsWhatItDoesNotSend (#4514),
  TestNoCommandBypassesProc (#4491), internal/agent's install-detection
  tests (#4033, #3548), and TestCoreScriptBudget, which was this change
  (app.js 321 over): its comment is cut to one line and both budgets
  are raised by the remaining 124 bytes, with no room added.
- Broken by hand: with startLog left out of runGUI, TestTheAppWritesItsLog
  is red ("app wrote no log: open .../Library/Logs/magpie/app.log: no such
  file or directory"); with proc.UserPath taken out of openApp,
  TestGatewayStartsGetUserPath is red ("runGUI doesn't call
  proc.UserPath"). The guard now follows a start into a function or func
  var of this package, since the Wails start sits behind openApp for the
  test.
- Real use on mote: the GUI build, magpie app in a sandbox HOME, wrote
  ~/Library/Logs/magpie/app.log (0600) with its "started" line; magpie
  log and magpie log -n 3 printed it.
Not tried: the app opened from Windows Explorer or a Linux desktop
launcher for real (the paths are unit-tested per OS, the writer on
Windows and Linux); the full GUI suite (running on WSL after the push,
reds filed if they fail at origin/main too).
2026-10-31 14:45:22 +08:00
yetone 3e5aa11519 provider: Qwen Cloud, Alibaba's international Qwen platform, is a preset with its regions and Token Plan (judi0713)
judi0713 on Discord (v0.1.2288) asked for Qwen Cloud (qwencloud.com).
Its keys are its own, made at home.qwencloud.com, and serve neither
DashScope's nor Bailian's hosts, so none of magpie's Qwen presets took
them.

Two presets, the way Alibaba's other pay-as-you-go/Token Plan pair is
modelled, because each key gets 401 at the other's host:

- qwencloud: pay as you go, sk-ws- keys, at
  https://{region}.maas.qwencloudapi.com/compatible-mode/v1 (Chat) and
  /apps/anthropic (Messages), in six regions named by their ids as
  Alibaba's docs name them: ap-southeast-1 (the default), us-east-1,
  eu-central-1, ap-northeast-1, cn-hongkong, cn-beijing. Catalog alibaba.
- qwencloud-token-plan: sk-sp- keys, token-plan.maas.qwencloudapi.com,
  Singapore only, with the plan overview's text models.

Endpoints, regions, key prefixes and the plan's models are from
docs.qwencloud.com ("Regions and endpoints" and the Token Plan
overview), not guessed. Responses is left out, as in the other
Qwen presets.

The gateway's dashScope() now knows both presets and the
*.maas.qwencloudapi.com hosts, so a Qwen Cloud stream gets the same
enable_thinking handling a DashScope one does. Import (presetAt), the
CLI's region= and magpie://import?preset=qwencloud&region=... map to it.
docs/reference.md, the CLI help and the site's import page (en, zh, ja)
name them. Region names are ids, so no string is new to i18n.js and
nothing in the GUI changed.

Run (mote, at 708213f65 on c272e5582; after it the commit was rebased on
876d477d7, which touches none of these files, and the new helpers' comment
was moved above bedrockRegions' doc comment, no code changed; at the pushed
head the provider tests below ran again, ok):
- gofmt -l: clean.
- go vet -tags nogui ./..., GOOS=linux go vet -tags nogui ./...,
  GOOS=windows go vet ./...: ok.
- go test -tags nogui ./... -timeout 45m -count=1: every package ok
  (gateway 804s, provider 205s) except two reds already filed, in files
  this doesn't touch: internal/proc TestNoCommandBypassesProc
  (claudetui/child_unix.go's exec.Command, #4491) and internal/update
  TestRelaunchOpenTriedAgain (TempDir cleanup not empty, #3881).
- At the pushed head: go test ./internal/provider -run
  'TestQwenCloud|TestQwenTokenPlan|Preset|TestParseImport': ok.
- No GUI change, so no GUI run.

Broken by hand:
- Preset ids renamed: TestQwenCloud red ("no preset qwencloud-token-plan").
- gateway.go's dashScope() back to main: TestDashScopeHosts red on the 5
  new Qwen Cloud entries; the maas.qwencloudapi.com.example case stays
  not-DashScope.

Not tried:
- No real Qwen Cloud key: no request went to qwencloudapi.com.
- The decision model (decide.go's bailianDecides hosts) doesn't know
  Qwen Cloud, and image models on these presets are the next commit's.
- The site isn't deployed by this commit.
2026-10-31 09:58:04 +08:00
yetone 7bc602236b library: the MCP hub is called the MCP router
The owner asked why it was a "hub". Composio calls the same thing a Tool
Router; "router" says what it does (one server that routes each call to
the right one), and "gateway" is taken by magpie's LLM gateway. Only
the words change: MCP router / MCP 路由 / MCP 路由 / MCP ルーター /
MCP-Router, "Router address", and the CLI's `magpie library mcp router
on|off`, where `hub` still works. The URL /mcp/magpie/hub, the mcpHub
setting, the servers/hub API and the Go names stay, so nothing a user
or an agent config holds changes. docs/subsystems/mcp-hub.md moves to
mcp-router.md and the pages that link it follow.

#4382's new words follow too: "Through the MCP router", "Not through
the router" and their hints in every language, and the CLI's
`magpie library mcp router <name> shared|direct` (`hub` works there
too; library_hub_test.go says router for direct, hub for shared).

Run at e2583df31 (this stack on 86fef947e), on mote: gofmt -l clean;
go vet for darwin, linux (-tags nogui) and windows; go build ./...;
go test -tags nogui ./... -timeout 45m, 81 packages ok, 0 FAIL;
library, gateway, imagemcp, sessions, cli and gui again alone, ok;
site's node --test, 49 of 49. GUI on xiaomi-gpu (Windows; mote's
browsers crashed under other sessions' suites): library-*, image*,
mcp-hub-direct, i18n-keys, list-sort and plugin-tools, both engines and
every language, 1055 of 1056: i18n-keys found "{name} is given to each
agent directly" dropped from the library's strings in the rebase. Put
back in the first commit; at the pushed head i18n-keys, mcp-hub-direct
and library-mcp-hub are 48 of 48. That is the only difference from
e2583df31.
Broken by hand at e2583df31: imagemcp ignoring magpie/roots fails
TestHubCallSavesInTheCallersProject; the router asking anything but
roots/list fails TestHubAsksTheAgentItsRoots and TestHubRootsUnasked;
inHub leaving magpie-image out fails TestHubGivesMagpieImage.
The CLI's TestProviderAddressMovesALocalServer red at -count=3 was
the same on origin/main 380032cda and is fixed in 65c792410.
Rebased once more onto 2570efb5f, which changed library-mcp-hub,
list-sort, mcp-hub-direct and gateway-routing.md. Run at the pushed
head: go build; gateway, library, cli and imagemcp tests ok; the GUI
budget tests ok; on xiaomi-gpu i18n-keys, mcp-hub-direct,
library-mcp-hub and list-sort, 51 of 54. The three reds were WebKit
420px library-mcp-hub cases with no Connect sheet after a reload.
origin/main d77da5bff goes red the same way (de 420px, 9 of 11). In a
second run of library-mcp-hub on WebKit at this head, 11 of 11 passed.
Filed as #4483.
2026-10-31 02:49:08 +08:00
yetone 06d36d4142 gateway: Stays: Session spreads new sessions over the accounts (connor_yang)
connor_yang on Discord: three sessions on one provider's three accounts,
Stays: Session (整个会话), ended up on two accounts. Under Smart routing a
conversation nobody had answered yet went wherever routing put first,
whatever other sessions were on; only In turn counted the sessions each
account holds (leastHeld, #946).

Kept for the whole session (Stays: Session or Strict) under a routing that
picks by what is left (Smart, Least used first, Weekly pace;
spreadsSessions), a new conversation now goes to the key, account or
group member the fewest other conversations of the last 30 minutes are on.
It passes over one routing keeps new conversations off (readyForNew:
resting, an aside key, a fallback while the provider's own model leads,
one used past lowShare), counts leads only, and keeps routing's order on a
tie. A Claude Code subagent's first request goes to its lead's account
(withLead), not to another as a session of its own. An answered
conversation is kept as before, and resting, spent and the rest/quota
fallback are unchanged. In order, By weight, Free first, Speed first,
Cheapest, Manual and plugin routings keep their order. Docs: reference,
gateway-routing, site start.html (en, zh, ja).

Run (mote, at this head on 2604d68db): go test ./internal/gateway -run
'TestWholeSession|TestInOrderKeepsNew|TestSpreadsSessionsOnly|
TestRotateSpreads|Affinity|Strict|Subagent|Lone|LoginSwitch|ChatGPT' ok;
GOOS=linux and GOOS=windows go vet ./internal/gateway ok; gofmt clean.
The full Go suite (-timeout 45m) was started at this head after the push.

Broken by hand: spreadsSessions always false (the old code's behaviour):
TestWholeSessionSpreadsNewSessions red, "s2 went to k1, which s1 is on"
for session and strict. Subagent sent through leastHeld instead of
withLead: red, "s2's subagent went to k1, not s2's k2". readyForNew
without the fallback and lowShare checks: TestWholeSessionSpreadLeaves
TheNearlyUsedAndFallbacks red.

Not tried: real subscription accounts (the tests use three API keys on one
provider, the same candidate path); a group of different providers end to
end (leastHeld's group path is the one In turn has used); the reporter's
exact provider and agent; sessions idle more than 30 minutes no longer
count as holding their account.
2026-10-31 01:05:44 +08:00
yetone d6beb9975a agent: T3 Code gets magpie on Codex too, picked in T3's model picker
karissasel_ on X: T3 Code through magpie could only run Claude Code; the
harness couldn't be chosen. T3 runs a thread on the driver of the provider
instance its model is picked under, and magpie wrote only a claudeAgent
instance. It now also writes `magpie-codex` ("magpie · Codex", driver
codex) in ~/.t3/userdata/settings.json. Its config.launchArgs (T3's
CodexSettings key, passed to `codex app-server`, and its -c pairs to
`codex exec`) are Codex's own -c overrides: model_provider=magpie, the
same model_providers.magpie table codex.go writes, and model_catalog_json
pointing at magpie-codex-models.json beside settings.json. Values are
quoted for T3's tokenizeCliArgs. ~/.codex/config.toml is not written. A
binaryPath/homePath the user gave T3's own codex instance is carried over.

The user's name, on/off and unknown keys are kept; launch args and catalog
are magpie's, and Check says when they no longer reach the gateway
(the base_url read back through T3's tokenizer; a reverse proxy to magpie
the user put there counts, reachesMagpie, as for every agent). An
older Claude-only wiring gets the instance once on Sync; one the user
removed stays removed (stash t3code.codex) until magpie is turned on for
T3 again. Turning magpie off removes both instances and the catalog. The
option's note says where to pick (4 languages); reference.md and
agent-wiring.md describe it.

Run (on mote, the tree as committed):
- real end to end, sandbox HOME (~/t3e2e/home): settings written by this
  code, magpie serve on 127.0.0.1:47811 with a fake Responses upstream,
  T3 Code server 0.1.5 (npm t3) and @openai/codex 0.165.0.
  `t3 thread start . "Reply with the word pong." --provider magpie-codex
  --model fake/fake-model --wait` answered PONG-T3-CODEX; the upstream saw
  POST /v1/responses, model fake-model, stream true, with the provider's
  own key (sent by magpie's gateway).
- go test -tags nogui ./internal/agent -count=1 -timeout 45m: ok
- gofmt -l; go vet (darwin, GOOS=linux, GOOS=windows) ./internal/agent
- node --test internal/gui/tests/i18n-keys.test.cjs: ok

Broken by hand, each red then restored: no escaping in t3Arg
(TestT3CodeCodexInstance red); Sync without t3CodexSync (both new tests
red); no stash check (TestT3CodeCodexInstanceAddedOnce red); t3CodexOff
never reporting (TestT3CodeCodexInstance red). The first full run
was red in TestReverseProxyIsStillMagpie, Check comparing the launch
args by string; that red is the break for the proxy rule.

Not tried: T3's desktop app window (the server CLI is what it runs); the
Windows quoting on a Windows box; a real vendor upstream (fake one only);
T3's other drivers (cursor, opencode, pi, grok, ...), which are off by
default in T3 and not wired.
2026-10-31 00:11:10 +08:00
yetone 4f2d5fc7e0 routing: a group can put its cheapest member first, by each one's price at that hour
liyuanzheng (#general) and lam_em (#feedback) both asked for the same
thing. Off-peak, DeepSeek's own API should come first for deepseek-flash.
At DeepSeek's peak (weekdays 01-04 and 06-10 UTC, billed 2x since
v0.1.2173), another provider should come first, Ollama say. A schedule
editor would make the user copy DeepSeek's hours into magpie. Instead,
a group gets one more routing, "Cheapest first" (`cheap`). Each request
sorts the members by what they cost right then: input + output price per
million, at the peak rate when it is peak hours. A tie goes to the lower
cache-read price. Free models count as 0. A member with no known price
keeps its listed place after the priced ones. Prices come from the same
priceOf the usage ledger bills with, so the user's own ModelPrices,
list prices and maker prices all count, and so does a provider's rate
windows.

- routes: Seat carries Priced/Cost/CacheCost; Strategy.ByPrice; Cheapest
  is a stable sort, so equal prices keep the user's order.
- gateway: weighRouted prices each seat at priceClock() (time.Now; a test
  holds it) through the new provider.PriceAt. The trace's Weighed row
  gets a price (input/output/cacheRead/peak) so Routing can say why.
- It is a group's alone, like Manual. A provider saved with it drops it,
  and `magpie provider set … routing=cheap` refuses it. Groups take it in
  the GUI menu (one more item, no new controls), the TUI and
  `magpie group set <id> routing=cheap` (aliases cheapest, price, cost).
- Routing's mode line says why the first one is first, e.g. "Cheapest
  first: deepseek-v4-flash costs least on ollama-cloud now — $0.150 in,
  $0.600 out a million tokens.", with peak and unpriced variants.
  en/zh/zh-TW/ja/de.
- Docs: gateway-routing, plugin-runtime, reference (it also points at
  Time window and Pause rules for a fixed schedule) and the site's start
  pages (en/zh/ja).

Run, at f7f2d75f2 (this change rebased onto it):
- Red on the old code: TestCheapestFirstGroupFollowsPeakHours (deepseek
  vs ollama with ModelPrices, priceClock held at 14:00 UTC off-peak and
  02:00 UTC peak) and TestCheapestOrdersByPriceNow did not compile
  without Cheapest. TestCheapestFirstIsAGroupsOnly checks that a provider
  drops it and a group keeps it.
- Broken by hand: without `pr = pr.In(at)` the gateway test is red ("at
  DeepSeek's peak ... went to deepseek"). With Cheapest returning the
  order unchanged, both the routes test and the gateway test are red.
  Both were restored.
- Full Go suite on mote (-count=1 -timeout 45m ./..., log kept): every
  package ok except two. internal/provider had
  TestQuotaSpanCarriesEveryWindowField, which is red on origin/main (#4457,
  fixed since in ccbefe2a2). internal/gui had ten AppKit window tests
  killed at their 20-40s deadlines (TestPanelCloseHidesIt,
  TestMainWindowCorners and others). Three of them are red the same way
  on a fresh origin/main f7f2d75f2 copy, under #2645/#4125 (mote has
  several GUI suites running). After the rebase, go vet and the Cheapest,
  SpeedFirstGroup, ParseRouting, ApplyGroupPairs and ProviderRouting tests
  are ok. go vet darwin, GOOS=linux -tags nogui and GOOS=windows are ok,
  and gofmt is clean.
- GUI on WSL (Linux, chromium + webkit): routing-cheapest-first (new,
  3 scenes x en/zh/zh-TW/ja/de x 2 engines), routing-group-strategy,
  builtins, i18n-keys and routing-speed-first gave 95 of 96. The one red,
  routing-group-strategy "webkit en light ... the pick moved nothing", is
  a wheel-scroll timing red. It fails 3 of 3 on origin/main and 1 of 3 here
  (#4459). Core-script budget ok (app.js +9 bytes).
- The whole GUI suite (1025 files) was started on WSL at this tree and
  was still running when this was pushed, at load ~160.

Not tried: real DeepSeek or Ollama accounts, and a real request during
DeepSeek's peak hours. Ollama Cloud's price here is the catalog's, not
checked against a bill.
2026-10-30 23:59:31 +08:00
yetone c84c3e1c03 gateway: a key's holder sees its own usage and setup at /me
zytszone on X runs one magpie's gateway for a whole department, whose
people can't be given the admin's app. Each now opens the gateway's /me
at the address they reach it at, types the gateway key they were given,
and sees that key's own name, limits and what is spent of them, its
usage over today, 7 and 30 days with its most used models, the models
it may use, and copy-ready setup for Claude Code (settings.json env),
Codex (config.toml provider, /v1, responses), any OpenAI-compatible
client and a curl test. The base URL is the address the page was
opened at, never 127.0.0.1; the key is a placeholder until "Put my key
in the setup" is ticked. Strings in en, zh, zh-TW, ja and de.

- GET /me (keypage.html, embedded) is the same bytes for everyone and
  holds no data, so lanGuard serves exactly GET/HEAD /me (no escaped
  path) to another machine without a key, after the allow list, the
  rebinding check and the not-shared 403, which still apply. Its CSP
  loads nothing from elsewhere, posts no form and forbids framing.
- GET /v1/magpie/me (keyInfo) answers access.Caller's own key only. No
  key, a wrong one, one turned off and magpie's own token are 401
  alike; ?key= is refused 400 so a key never sits in an address or a
  log. It names no account, other key, provider or secret; its models
  are /v1/models' for that key (keyAllowed), none for a read-only key.
  The page sends the key as Authorization to its own origin with
  credentials omitted and keeps it in sessionStorage only.
- Both are in readOnlyRoutes, /me in clientPrefixes (magpie web's page
  port), and Gateway -> Gateway keys shows the page's address
  (MAGPIE_PUBLIC_URL, else the LAN address offered) with a Copy, while
  shared and with a key. Docs: gateway-routing.md, reference.md.

Run:
- mote: go build -tags nogui ./...; go vet -tags nogui gateway+gui;
  GOOS=linux and GOOS=windows go vet -tags nogui ./internal/gateway;
  go test -tags nogui -count=1 ./internal/gateway ./internal/gui: ok
  (gateway 732s). gofmt -l clean. Rebased onto 18b63fe5f after that;
  there: build, vet, and the KeyPage, read-only, client path, page
  port, LAN guard, caller usage and core script budget tests ok.
- Key page Go tests, through the real lanGuard(Handler()) chain, from
  the network and from loopback: the key sees its own name, usage, top
  model, limits and allowed models and nothing of Bob, Bob's secret,
  the upstream key or magpie's token; no key, wrong key, turned-off key
  (Bearer and x-api-key), magpie's Token, ?key=, Origin null, an
  evil.localhost page, a foreign origin with a good key and a rebound
  Host all get nothing; the page opens without a key, not on POST,
  /me/x or /%6De, and not while unshared; a read-only key gets no
  models.
- GUI, key-page.test.cjs: Chromium on mote and WebKit on the Linux box
  (magpie-desktop), 390px, all five languages, 24 of 24; i18n-keys ok.
  The 46 Gateway/caller-key GUI files and i18n-keys on the Linux box,
  both engines: 645 pass, 11 red at concurrency 4. Serially 6 stay red,
  and the same tests are red on origin/main a0cb8b646 there:
  api-key-theme "system", gateway-key-limit webkit en/zh,
  connect-snippet-shell, gateway-key-models (#4120), phone-rows (#4218).
Broken by hand, each red then restored: lanGuard's /me exemption
removed (page 401); the KeyID check removed (no key/wrong/off/Token got
data); keyAllowed dropped (Alice saw plan/m2); the RawPath check dropped
(/%6De served); the ?key refusal dropped (200 with Alice's data).
Not tried: a real Claude Code or Codex pointed at a shared gateway with
the page's snippets; WebKit on macOS (every WebKit launch on mote hangs
right now, for every session, a bare launch included); the whole GUI
suite and a full go test ./... (one suite per machine; mote is running
other sessions' suites).
2026-10-30 22:52:05 +08:00
yetone 99ad38b7c8 vertex: Claude models on Anthropic's Messages API at the project
A user on X wanted to spend GCP credit on Claude through Vertex AI. Claude
Code does it with CLAUDE_CODE_USE_VERTEX, ANTHROPIC_VERTEX_PROJECT_ID and
CLOUD_ML_REGION, but magpie's Vertex provider only spoke Gemini. Now a
Vertex provider with just a project and a region serves claude-* ids
(claude-sonnet-5-5, claude-sonnet-4-5@20250929, ...) on every client
protocol: Chat, Responses, Anthropic Messages and Gemini.

The request shape follows the AnthropicVertex SDK bundled in Claude Code
2.1.314 and Google's Vertex docs for Claude:
- a message goes to .../publishers/anthropic/models/{model}:streamRawPredict
  when it streams and :rawPredict when it doesn't, with model taken out of
  the body;
- a count goes to .../publishers/anthropic/models/count-tokens:rawPredict
  with the model kept;
- the body gets anthropic_version "vertex-2023-10-16" when it has none;
- no ?beta=true query; the bearer is the existing Google OAuth token;
- the advanced-tool-use-2025-11-20 beta goes as tool-search-tool-2025-10-19,
  as Claude Code sends it to Vertex (the Bedrock rename table, now for
  Vertex too; Bedrock's refused betas stay Bedrock only).

How:
- provider: VertexClaude(model) and VertexClaudeRequest(path, body).
  Base(Anthropic) is the Vertex project base, so a Vertex provider speaks
  chat, anthropic and gemini; ListedAPIs gives a Claude id Anthropic only,
  so the model id alone picks the publisher. No GUI change.
- gateway: forwardOnce, the one place every Anthropic upstream request
  passes, rewrites path and body for Vertex. Gemini's effort mapping
  (none -> minimal, xhigh -> high) skips Claude. countTokens takes any
  provider with an Anthropic base.
- provider Test stays on Gemini (Claude needs Model Garden enablement);
  TestModels asks a Claude id on rawPredict with max_tokens 16.
- preset lists claude-opus-5-5, claude-sonnet-5-5, claude-haiku-5-5 and
  claude-fable-5-1 at global. Docs: reference.md, providers-accounts.md,
  gateway-routing.md.

Run (darwin, mote):
- gofmt -l: nothing. go build ./...: ok.
- go vet ./... ok; GOOS=linux go vet -tags nogui ./... ok;
  GOOS=windows go vet ./... ok.
- go test -tags nogui -count=1 -timeout 45m before the rebase:
  internal/provider ok 100s, internal/gateway ok 497s, internal/gui ok 58s,
  internal/cli ok 33s, internal/tui ok 9s.
- After rebasing on origin/main (36 new commits, six in provider/gateway):
  internal/provider ok 112s and internal/gateway ok 578s again, at the
  rebased tree (d53336d9e before this message was written), gofmt clean.
- New tests: TestVertexClaudeModel (gateway, fake Vertex server: chat,
  anthropic, responses streamed and not, two id forms, a Gemini client,
  effort xhigh and none, Claude Code's ?beta=true with the tool-search
  beta, count_tokens, a Gemini model still on streamGenerateContent),
  TestVertexClaudeModels and TestVertexClaudeRequest (provider).
- GUI (no asset changed; files the provider list reaches):
  vertex-editor and i18n-keys in Chromium on mote, 18/18. WebKit on mote
  fails to launch at all (180s launch timeout under load), so WebKit ran
  on the Linux box (wsl-run): vertex-editor 14/14 in four of five
  runs. The first run had 13/14 with one failure whose name was lost
  (log not kept, my fault); three runs with logs kept since were 0 fail,
  so it isn't named or filed. No GUI asset changed here.

Broken by hand, each red, then restored:
- forwardOnce rewrite off: 502 on every Claude request.
- vertexEffort exclusion removed: xhigh reaches Vertex as high.
- beta rename off for Vertex: beta arrives unrenamed.
- countTokens back to c.p.Anthropic: the count goes to streamRawPredict.
- ListedAPIs Claude branch removed: the model is asked on gemini.

Not tried:
- No real GCP project was available: no real Vertex request, no Model
  Garden enablement, no real Claude Code session against Vertex through
  magpie. The shape is checked against the SDK and docs only.
- Claude is listed at global only; regional availability per model isn't
  listed.
- Whether Vertex accepts a 1h cache_control TTL is unverified.
2026-10-30 18:29:45 +08:00
yetone 88e6fb9cf7 provider: a signed-in subscription's models stay in every agent's list with a group listing alone on
士奇 on Discord (Simplified Chinese GUI, the third report of this): with
routing groups off, Hermes Agent's and WorkBuddy's model lists had the
ChatGPT subscription's GPT models. With routing groups on, they were gone.

Cause: the user's group names those models and lists itself alone
(Group.Unlists, the routing plugin's option for that, #1783). While the
group is on, catalogKeeping drops what it names from Catalog(), and every
agent's list starts from Catalog(). With groups gated off the group's
Unlists goes away, so the models came back. a3ee00c05 kept them for the
Codex agent only; its body said other agents still didn't see them.

Fix, at the one point every agent's list starts from: catalogOf(agent)
keeps a signed-in subscription's own models (SubscriptionKept: no group
entry, Provider.Account set, the provider not kept for routing groups)
for every agent, so a group is added on top of what agents had. A client
that is no agent ("" on /v1/models) still gets the group alone, as #1783
asked. Provider.Unlisted ("Only through routing groups") still hides the
provider's models from agents other than Codex. Unlisted() no longer names
a kept subscription model, so the picker's note doesn't call it kept for
groups.

Siblings: every agent writer reaches catalogOf through CatalogFor and
ListedFor. Two gateway lookups read Catalog() directly and now use the
agent's catalog (CatalogOf): /v1/models/{id} and Claude Desktop/Science's
alias lookup. agent.go and codex.go read Catalog() only for error text or
a fallback and are left alone. The routing plugin's hint for that option
says, in every language, that a signed-in subscription's models stay in
agents' lists.

Test: TestSubscriptionModelsStayInEveryAgentsListWithGroupOn signs in a
ChatGPT account in a sandbox and switches on a group naming its 5 models
that lists itself alone. For every agent that lists the group (68,
including hermes, workbuddy, claude and codex), the agent's list and
CatalogFor have the models, and a picker offering the group offers them.
Catalog() and CatalogFor("") still don't. With the provider set to
Unlisted, Hermes doesn't list them. TestCodexOwnModelsListedOnlyThroughGroups
now expects Claude Code to keep the models under a group alone.

Run (on mote):
- Broken by hand: catalogOf reverted to a3ee00c05's Codex-only version.
  The new test went red with 340 errors across 68 agents, e.g.
  "codex/gpt-5.5 not in hermes's list map[group/mygpt:true]", and the
  same for workbuddy, claude and claude-desktop. Green with the fix back.
- gofmt -l; go vet on darwin, linux (nogui) and windows; builds: clean.
- go test -timeout 45m ./... at 035d87b80 (this change on 4a4a90c23,
  before a test comment was reworded): every package ok except
  - internal/gui TestMainWindowCorners/macOS_26_SDK: #3949, red on
    origin/main accb951ab on mote too (macOS 27);
  - internal/provider TestClaudeAccountServesModelsListedSinceItsFetch:
    #3174 (red in a full run, green alone). 5 of 5 green alone and
    green in a whole internal/provider run at that head.
- At this commit on b26fa0903: gofmt -l on the
  changed Go files, go vet of provider, gateway and gui on darwin, linux
  (nogui) and windows: clean. internal/provider whole: ok.
  internal/gui and internal/gateway with -run
  "Codex|Group|Subscription|Unlist|Catalog|AgentModel": gui ok; gateway
  red on TestAntigravityTurnsCodexsGPT5ThreadAwayOnce and
  TestCodexSpentGrokFailingIsTold, both red the same way on origin/main
  b26fa0903 (3 of 3) and filed as #4362.
- GUI files the change reaches, on b26fa0903: agent-model*, group-unlists and
  i18n-keys: every Chromium case and i18n-keys pass (46); every WebKit
  case timed out launching the browser (180s, #4125: WebKit doesn't start
  on mote right now). The same files at 035d87b80 passed in both engines
  but i18n-keys, whose one red (the new test quoted a routing-plugin
  word) is fixed here.
- Rebased on 101775657 (main had moved models.go and gateway.go): gofmt,
  go build for darwin, linux (nogui) and windows, go vet of provider,
  gateway and gui on all three: clean. go test -run
  "Codex|Group|Subscription|Unlist|Catalog|AgentModel" ./internal/gui
  ./internal/provider and -run "Model|Desktop|Alias|Catalog"
  ./internal/gateway: ok.
- The whole GUI suite (1004 files) at fd50ed116 was still running when
  this was pushed (mote shared with other sessions' suites). Reds it
  shows get their own issue unless already red on main.

Not tried: no live ChatGPT account and no real GUI app run (the test signs
in a sandbox account). No separate gateway test for /v1/models/{id} or the
Desktop alias lookup. Provider.Unlisted stays honoured, on purpose.
2026-10-30 15:38:06 +08:00
yetone 46fb0c1b93 gui: the tray panel switches a Claude Code's or Codex's account (shuizhuyu on X)
shuizhuyu asked for a global shortcut to switch accounts. v0.1.2143's
Quick panel shortcut opens the tray panel, but the panel had no account
switch: switchable() returned null there, because the panel reads no
provider list (a fresh /api/providers reads every sign-in, seconds after
a start, #1519).

Now a Claude Code or Codex not connected has an "account" line in its
opened panel row (switchEntry, the window's Switch accounts only menu).
The line is drawn from the list kept from the last read
(GET /api/providers?last=1, no keychain read; panelAccounts in app.js),
read fresh only when nothing is kept. Opening the menu does one fresh
read and opens on what it says. Manage accounts… and a lapsed pick open
the window's Providers (window/main?view=providers). The provider and
login actions now keep their answer as the last list (keepProviders), so
a switch made in the window or the panel is in the next kept read.

app.js stays under its budget with no raise: my own comments and two
older ones (the usage accounts note, the sidebar note) were cut down.

Run:
- GUI, Windows box (xiaomi-gpu, win-run), Chromium + WebKit: 31 files
  (panel-*, panel-switch-accounts, agent-switch-accounts, switch-only,
  claude-switch-only, keep-login, agent-failover, agent-row-disclose,
  getting-started, click-scroll, i18n-keys, gui-zh-tw, gui-ja, gui-de):
  503 of 503 pass. Not the whole GUI suite.
- mote: no browser could launch there (pboard down, #4125; every WebKit
  and later Chromium launch timed out at 180s), so the GUI runs there
  were cut short. agent-panel-name-width, red there in both engines, is
  red on origin/main too (#4304, #4203), and this change doesn't draw
  the closed rows it measures.
- mote: go vet ./internal/gui; go test -run 'TestKeptProvidersFollowActions|
  TestLastKnownProviders|Budget|TestProvider' ./internal/gui ok (includes
  TestCoreScriptBudget). gofmt -l clean. GOOS=windows go vet ./... ok.
  GOOS=linux go vet ./... fails only in wails/v3 pkg/application (cgo
  off when cross-compiling), the same on origin/main 32f5c3369 (#4406).

At the pushed head (rebased on origin/main 32f5c3369, whose switchEntry
now leaves setup-token logins out of the menu; kept): the Go run above
again ok, TestCoreScriptBudget at the new 1,536,586 included, app.js
1,314,856 of 1,315,316; on the Windows box, panel-switch-accounts,
agent-switch-accounts, switch-only, claude-switch-only, keep-login,
agent-failover, i18n-keys, panel-fold and panel-effort: 178 of 178.

Broken by hand:
- panel-switch-accounts on origin/main's assets: 12 of 12 red in
  Chromium (no account line).
- Panel always reading fresh (laziness removed): 11 of 12 red.
- keepProviders removed from the provider action:
  TestKeptProvidersFollowActions red.

Not tried: real Claude Code or Codex accounts; the real Wails panel
opened by the shortcut; the login/{action} keep has no test of its own.
2026-10-30 15:26:03 +08:00
yetone dafe4af822 gateway: the ChatGPT backend's "auto"/"default" tier is recorded as unknown (jjt on Discord)
The ChatGPT Codex backend says service_tier "auto" in response.created
and "default" in response.completed whether priority ran or not. jjt's
measurements on gpt-6.1-sol with a Plus account: Fast decodes at about
200 tok/s, without it about 110, and the reply says "default" both times
(real-priority.sse, speed-plus.txt). magpie copied that into tier_served,
so the usage log, its CSV and /v1/magpie/route said served = default for
requests that ran Fast.

servedTierAt (tier_record.go) leaves those two words empty when the
reply came from CodexBase's host. It is applied once per routed try, in
attempt (gateway.go, a defer, so every return path and the route's tries
see it), and on the relay of Codex's own sign-in (codexUpstreamOn).
OpenAI's API, where service_tier means what it says, keeps it as given:
a provider at api.openai.com and Codex with an sk- key relayed to it.
"priority" or "ultrafast" said by the ChatGPT backend is still kept.

Display: tier_served is shown by the CSV (an empty cell), the JSON log
and /v1/magpie/route (omitempty). No GUI page or TUI shows a tier
(grep of internal/gui/assets and internal/tui for tier_served,
tier_asked, tierServed: none), so no strings changed. docs/reference.md
and docs/subsystems/gateway-routing.md say it.

Tests:
- TestChatGPTBackendTierUnknown (new): the backend says auto, then
  default (jjt's events, cut to the fields read); a routed try asked
  priority and one asked nothing, and Codex's own sign-in relayed, all
  record "" in usage and the route.
- TestOpenAIAPITierKept (new): api.openai.com's "priority" and
  "default" kept, routed and through the sk- relay.
- TestTierRecordedPerTry: its "none asked" case on the ChatGPT backend
  now expects "" where it expected "default".

Run on mote (mote-run; the wider run at base cc81ad4ea, the tier run
again after the rebase, at this commit on c37b8b659: ok, 22 pass):
- go test ./internal/gateway -run 'Tier|ChatGPTBackend|OpenAIAPI'
  -count=1 -v: ok, 22 tests pass.
- go test ./internal/usage: ok. go test ./internal/gateway -run
  'Codex|Usage|Route|Tier': two reds, TestAntigravityTurnsCodexs-
  GPT5ThreadAwayOnce and TestCodexSpentGrokFailingIsTold, red the same
  on a fresh origin/main c37b8b659 and filed as #4362; the rest ok.
- go vet ./internal/gateway, GOOS=linux and GOOS=windows: clean.
- gofmt -l internal/gateway: clean.
Broken by hand: servedTierAt returning t unchanged -> TestChatGPT-
BackendTierUnknown and TestTierRecordedPerTry red ("served default");
the host check removed -> TestOpenAIAPITierKept red (served "", want
"default"). Both green again with the fix.

Not tried: a real ChatGPT account through the built gateway; the full
Go suite (the coordinator asked for the targeted run under mote's load
of ~200); Windows and Linux test runs (vet only). No GUI file reads the
tier, so no GUI test was run.
2026-10-30 13:57:36 +08:00
yetone ffa07395eb gateway: Codex talks Responses to magpie over a WebSocket, turns after the first as a delta (#4058)
Codex names previous_response_id and sends only the new input on its
WebSocket path alone; magpie answered the upgrade 426 (a87dc1ff2), so
Codex fell back to HTTP and re-sent the whole conversation, images
included, every turn (kevinzhow and neighbads on X).

/v1/responses, /responses and /backend-api/codex/responses now accept the
socket (responses_ws.go), with Codex's protocol (codex-rs 2f1e4f9,
responses_websocket.rs):
- each response.create frame is replayed as the POST it stands for through
  the outermost handler the upgrade came in on (socketEntry wraps Front and
  Handler), so the allow list, rebound Host check, key, corsGuard,
  keyLimited, routing, failover, usage and log judge every turn;
- previous_response_id resolves to the socket's own last two replies
  (input + output items); the provider gets the whole conversation, so a
  switch of account or provider mid-chain loses nothing. An id the socket
  doesn't hold is previous_response_not_found (Codex reconnects with
  everything);
- generate:false (warmup) is answered locally; response.interrupt cancels
  the turn (accepted + incomplete/interrupted, or failed); errors are
  Codex's error frame with status and the headers it acts on;
  response.metadata, codex.response.metadata (x-models-etag, magpie's tag)
  and codex.rate_limits are sent as the backend does;
- shutdown drains sockets with 1001 and refuses new ones 503.
Codex needs no config change: magpie's wiring points the built-in openai
provider at /backend-api/codex, which Codex already speaks WS to. Other
Codex backend paths still answer 426. Docs: gateway-routing (new section
"A Responses WebSocket"), providers-accounts, reference.

Run at the pushed head (rebased on origin/main 430005726), on mote:
gofmt -l clean; go vet ./internal/gateway for darwin, linux, windows;
go test -timeout 45m ./internal/gateway: ok (480s).

Real Codex (codex-cli 0.165.0, sandbox HOME/CODEX_HOME with a copy of the
owner's ChatGPT auth, sandbox magpie on 127.0.0.1:3481, gpt-5.6-luna, a
task with three tool calls). At the pushed head, built on mote: exit 0,
right answer, 5 turns on one socket, 4 continued, 75480 B received vs
278210 B sent on as whole requests, no fallback to HTTP. Before the
rebase, with a temporary per-turn log: exit 0, right answer. 5 turns on one socket,
4 continued with previous_response_id; frames 58073 B (first), then 4465,
3051, 3093 B, against 58.7-66.6 KB had each been a whole request. 70185 B
received over the socket vs 255379 B sent on as whole requests.

Broken by hand:
- serveResponsesSocket returning false (the old 426): 9 of the new tests
  red.
- turns sent straight to the Responses handler with the upgrade's
  post-guard context: TestResponsesSocketGuards red (a key turned off
  still served; a 700-token limit not held).

Not tried: images in a real run; Codex on Windows/Linux. Not done: the
leg magpie -> vendor still sends the whole conversation each turn (for
ChatGPT, keeping an upstream socket per client socket would save that);
the saving is Codex's upload to magpie. A socket's conversation does not
survive the socket or a restart (Codex then resends everything).
2026-10-30 08:51:03 +08:00
yetone 55299ee304 agents: Switch accounts only, the account a Claude Code or Codex not connected is signed in to, a click from another
Users asked for an entry named 仅切换账号 (growaiskills), for the current
account to always show, for a clear sign that a switch took, and for the
switch away from the proxy settings that put them off (Rennix7t). The owner
said to build it.

On the Agents page, a Claude Code or Codex row that magpie doesn't connect now
shows the account the agent is signed in to as a button in its status line
(switchEntry). Clicking it opens the app menu, headed "Switch accounts only",
with:
- every sign-in;
- "Only switch {agent}'s sign-in", a ticked item (menuitemcheckbox). Claude
  always gets it; Codex gets it only with more than one usable account;
- "Manage accounts…", which opens the provider editor.
Picking another account goes through /api/login/switch, or through
/api/provider/keeplogin when the provider keeps a login. The button then
shows "Switched" for 5s, and the status line says that new sessions use the
account and an open one keeps its account until it is restarted. A pure
switcher (Claude kept to its own accounts with nothing else in magpie, the
"empty" connect kind) used to show only "Add a key or a subscription
first", so it couldn't switch from the page. It now gets the entry, and
switch-only reads "Not connected · switching accounts only". The failover
line's "ChatGPT accounts" button is gone, since this entry replaces it. A
connected agent, the tray panel and the WSL twin get no entry. Strings are
in zh, zh-TW, ja and de. Docs: providers-accounts.md and reference.md.

The core budget is raised by this change's bytes only (app.js 1,315,316,
core 1,536,357), after cutting comments and dropping a key.

Run on mote at 9f299d54e (rebased on 0c12662f2):
- GUI files agent-switch-accounts, agent-failover, i18n-keys, gui-zh-tw,
  gui-ja, gui-de, click-scroll, agent-connect-no-models, switch-only,
  claude-switch-only and keep-login: 177 of 177 pass. agent-panel-name-width,
  run beside them, is 0 of 32, the same on origin/main 0c12662f2 alone
  (#4203, commented)
- go test ./internal/gui: only TestMainWindowCorners/macOS_26_SDK red, #3949
- Earlier, at ad9f269c9 on 8cbd0a9c9, the whole GUI suite (concurrency 4)
  ran 508 tests before I stopped it, since it ran very slowly under load.
  The only red was agent-panel-name-width (chromium and webkit), a
  panel-only test where this entry is never drawn. It is #4203, and it is
  still red at this head and on main with 0f391a7a7 (above). The rest of
  the suite was not reached.
- A Linux full run (wsl-run, magpie-desktop) is not a valid environment:
  410 GUI reds at concurrency 8, mostly WebKit timeouts, and the Go builds
  fail without gtk4/webkitgtk. internal/gateway passed; internal/agent had
  6 that need tools installed there (TestInstalledVersion,
  TestGrokInstalled, …). Nothing in this change touches Go.

Broken by hand, each turned red, then restored:
- not setting accountSwitched: "Switched shows on the button" went red in
  every engine and language;
- login/switch in place of keeplogin: the kept-login test went red;
- removing the empty-kind bypass: 11 of 12 chromium tests went red.

Not tried:
- a real switch with real accounts in a sandbox HOME. On macOS Claude
  Code's credentials are in the login Keychain, which a sandbox HOME doesn't
  isolate, and the Linux box has no signed-in accounts. The endpoints are
  unchanged and were already used by Settings' switch.
- the real app on Windows and Linux (WebKitGTK);
- the tray panel, which reads no provider list, and the WSL twin rows,
  which get no entry;
- the rest of the whole GUI suite past 508 tests.
2026-10-30 04:01:35 +08:00
yetone 05a6087e1f access: a key with accounts and no model may use only its accounts' providers' models
Linka on Discord (#feedback): in a gateway key's "Models this key can
use", ticking only an account and no model let the key list and use
every model of every provider.

Cause: Key.Models empty meant "every model", and Key.Accounts (#905)
held only the providers it names, so every other provider stayed open.

Change: access.HeldModels gives a key with accounts and no models the
models "<provider>/*" of each account's provider. Authenticate builds
the Identity with it, so every route's existing model gate narrows:
/v1/models, /v1beta/models, chat, responses, messages, Gemini,
count_tokens, embeddings, images, the Codex backend path, System One,
groups and fallbacks. A key that lists models is unchanged (#905: its
accounts still hold only the providers they name); a key with neither
is unchanged. The CLI's MODELS column and `gateway-key models` say so,
and the GUI editor's hint, the "not used" notes on providers no model
or account reaches, and the save status follow (en, zh, zh-TW, ja, de).

Tests:
- TestGatewayKeyAccountsOnlyHoldTheModels: each route above is 403 for
  the accounts-only key and no upstream call reaches the other
  provider, the decider or the image provider; its own provider, a
  group of it and a key that also lists models work. Red on the old
  code on every route (list showed spare/m2, chat/count_tokens/
  embeddings/systemone 200).
- TestHeldModels (access).
- gateway-key-accounts.test.cjs: hint, notes and status; 4/4 red on
  the old assets, green on the new.
- TestGatewayKeyAccountsListModels / SystemOne / OfANamedProvider and
  TestHeldKeyToldItsOwnQuotas now encode the new rule (the held key is
  told only its own provider's quotas).

Run on mote: gofmt -l clean; go vet darwin, linux -tags nogui, windows
on access, cli, gateway, gui ok; go test -timeout 45m ./internal/access
./internal/cli ./internal/gui ./internal/gateway: ok except gui's
TestMainWindowCorners/macOS_26_SDK (#3949, not this change) and
gateway's TestHeldKeyToldItsOwnQuotas, updated and rerun ok. After the
rebase on 1f03d7546 the key tests ran again ok. GUI: gateway-key*,
i18n-keys, gui-de, gui-ja, gui-zh-tw in Chromium and WebKit: 131 pass.

Not tried: a plugin-served provider (same model gate), a real
account, Windows and Linux test runs (vet only).
2026-10-30 01:25:57 +08:00
yetone fd5c631cbe image mcp: generate_image and generate_video take the model to use (XYenon)
XYenon on Discord asked whether an agent can pick the model magpie's
image/video MCP draws with. Both tools now take an optional `model`,
as provider/model:

- The schema lists the models that may be asked (the Settings default
  first, then each on provider's OfferedDrawers or Videomakers), only
  those the calling gateway key may use. Up to 40 of them form an enum;
  past that, the description names three.
- Left out, the Settings default is used, as before.
- A bare id only one provider has, a ChatGPT account's other GPT Image
  name (ListedDrawer), or a newer family model (drawsFamily,
  grokVideoFamily) is accepted. Anything else is a tool error naming the
  models the key may use, and nothing is drawn. It never falls back.
- The chosen model goes into the images/videos request's `model`, so
  the APIs' own key check (keyHolds, keyModelError, #882) refuses one
  the key may not use: the same check /v1/images makes.
- The stdio Magpie Image server copies the gateway's `model` property
  from its tools/list, and asks the hidden JSON-RPC method
  magpie/media_model which model a call means. An older gateway
  (-32601) passes the model through as named.
- `magpie tool generate_image --model ...` works through the schema;
  the usage text says so.

Docs: gateway-routing.md (image MCP section), reference.md.

Run (mote, via mote-run, at this tree):
- gofmt -l: clean.
- go vet ./... for darwin, GOOS=linux -tags nogui, GOOS=windows: ok.
- go test -count=1 -timeout 45m ./internal/gateway/ ./internal/imagemcp/
  ./internal/cli/: ok.
Broken by hand: with `req["model"] = ref` dropped in imageMCPDraw and
imageMCPFilm, TestImageMCPDrawsWithTheModelAsked,
TestImageMCPModelHeldToTheKey and TestImageMCPVideoModelAsked go red
(the default was drawn instead); restored, they pass.
Not tried: a real vendor account. The fakes are easeled's art provider
and the fake Grok. GUI files not run: no GUI file changed.
2026-10-29 22:16:56 +08:00
yetone f6263439af gateway: serve OpenAI's text to speech, POST /v1/audio/speech
liuyuexue2020 on X (tweet 2115742181734445238) wanted audio models
(Mistral among them) behind magpie, and the gateway had no
/v1/audio/speech.

POST /v1/audio/speech (and the bare /audio/speech) takes OpenAI's JSON
body and goes through serveRetrieval, as transcriptions (#2053) and
embeddings do: routed (a group's members, a provider's keys and
accounts, pause rules, key limits), metered against MaxRPM, recorded
(usage operation "speech", Routing, recent calls). Only "model" is
rewritten to the provider's own id; every other field goes as sent, so
Mistral's voice_id and ref_audio pass too.

The answer is never held whole: a speech request's 2xx answer is left
unread by the new retrieveOpen (retrieveAs now wraps it) and copied to
the client as it comes, flushed per read, in the vendor's own
Content-Type: audio (mp3/opus/aac/flac/wav/pcm), SSE for
stream_format=sse, or a vendor's JSON (Mistral answers
{"audio_data": base64}). No Accept: application/json is sent for it.
The usage in SSE's speech.audio.done event is counted from the last
16KB. A vendor's error is read and passed on as before, and a failing
member still falls over to the next.

Masking: "input" and "instructions" are masked as the settings say,
as text (maskTextHits), each where it sits; nothing else in the body
is (voice, formats, a voice-cloning clip are no text of the user's).
Nothing is put back: the answer is audio, so a masked value is read
aloud as its placeholder (docs/reference.md says so).

Mistral: its API has POST https://api.mistral.ai/v1/audio/speech
(voxtral-mini-tts-3-0), at the OpenAI path but not OpenAI's shape:
voice_id instead of voice, and JSON {"audio_data": base64} back, not
raw audio. Both pass through as sent; a client must speak Mistral's
shape to it. OpenAI, Groq and other OpenAI-style TTS vendors (vLLM-Omni
included) are served as they are.

Also: the 404 message's list, /v1's "apis", remote_magpie's suffix
list, cors_test and lan_test route lists, docs/reference.md,
gateway-routing.md, plugin-runtime.md, site remote.html (en/zh/ja).

Run (mote-run, at this commit):
- go vet ./... (darwin), GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet ./..., go build ./...: ok; gofmt -l clean
- go test -timeout 45m -count=1 ./internal/gateway ./internal/provider at 7bc52d44e^{tree} (= this tree, origin/main 65bd4e4f7): gateway ok 497.9s, provider ok 88.7s
- go test ./internal/gateway -run 'Speech|Transcri|Embedding|Rerank|CORS|LAN|ReplyHeaders': ok

Broken by hand (mote-run, each red, then restored):
- the two mux lines removed: all five TestSpeech* red
- streams() false (answer read whole): TestSpeechStreamsAsItComes red
  (first event never reached the client while the vendor held the rest)
- "instructions" left out of the masked fields: TestSpeechInputMasked red

Not tried: a real vendor (OpenAI, Groq, Mistral) through a sandbox
magpie; only the fake upstream in speech_test.go. Not run on the
Windows or Linux boxes (vet only).
2026-10-29 19:25:40 +08:00
yetone 3c6b7d585f agent: OpenClaw is wired up like the other agents
arthur041691 (Discord #help) runs OpenClaw for WhatsApp and asked for it in
Agents. Connecting writes magpie as a custom provider of OpenClaw's own, in
openclaw.json, and makes the picked model agents.defaults.model's primary.

What is written, from OpenClaw's source at 5bab0c14 (npm 2026.10.8, dc2523e):
- the file: OPENCLAW_CONFIG_PATH, else $OPENCLAW_STATE_DIR/openclaw.json,
  else ~/.openclaw-<profile> for a named OPENCLAW_PROFILE, else
  ~/.openclaw; ~ is OPENCLAW_HOME when set (src/config/paths.ts,
  src/config/state-dir.ts, src/cli/profile-utils.ts). OPENCLAW_PROFILE is
  a name, not a path (agentenv.NotPaths); the other three expand a
  leading ~, as resolveUserPath does (appdir.usable).
- models.providers.magpie: baseUrl (the gateway's /v1), apiKey (the
  OpenClaw-named gateway key), api "openai-completions", and every model
  magpie serves with id, name, input, reasoning and contextWindow
  (src/config/zod-schema.core.ts, docs/gateway/config-tools/custom-providers.md).
  A user's own keys on a model entry (headers, maxTokens…) stay on Sync.
- agents.defaults.model keeps its shape (string or {primary, fallbacks});
  agents.defaults.models gets the ref's {} entry as `openclaw models set`
  adds it (src/commands/models/shared.ts), only when that map exists; a
  non-empty modelPolicy.allow gets "magpie/*" when nothing there lets
  magpie's models in (src/agents/model-selection-normalize.ts).
- Model changes are hot-reloaded (docs/gateway/configuration/hot-reload.md);
  a chat that already has a model keeps it (docs/concepts/models.md), so
  the notice says to send /model default there. Translated in every
  language.
- The file is written through temp-and-rename; a new one is 0600 in a
  0700 folder, as OpenClaw makes it (src/config/io.write.ts). A file that
  isn't JSON after comments are blanked (JSON5's bare keys) is left alone
  with an error, never read as empty.
- Disconnect puts back the model there was, removes magpie's provider,
  its {} entries, the allow entry and any object magpie made, and the
  file itself if magpie made it.

Icon: a mask drawn from OpenClaw's ui/public/favicon.svg (MIT).

Run, on mote at this tree:
- go test -tags nogui ./internal/agent -run OpenClaw plus the every-agent
  tests (drift, port move, sync on another machine, reverse proxy, LAN,
  pinned key per writer, notices translated), ./internal/appdir,
  ./internal/agentenv: ok.
- Broken by hand, each red then green again: no stash restore
  (TestOpenClaw, Shapes, AllowList), user keys dropped
  (SyncKeepsTheirs), no allow entry (AllowList), no JSON5 guard
  (JSON5LeftAlone), profile ignored (Paths), OPENCLAW_PROFILE back as a
  path variable (Paths).
- Real OpenClaw 2026.10.8 from npm, Node 24.22.2, sandbox HOME on mote:
  onboard --non-interactive made the file (its bytes are the test
  fixture); magpie's code connected it; `openclaw config validate` ok;
  `openclaw models list` shows magpie/kimi/k2 as default; `openclaw agent
  --local` sent POST /v1/chat/completions with Bearer magpie-openclaw and
  model kimi/k2 to a fake gateway on 3425 and showed its reply; no
  agents/*/models.json override was written; Disconnect gave the file
  back byte for byte and it validates.
- GUI: i18n-keys, agent-notice-lang, icon-tile, about-notices,
  agent-connect (Chromium and WebKit): 53/53.
- gofmt -l clean; go vet darwin, GOOS=linux -tags nogui, GOOS=windows ok.
- Full suite, go test -tags nogui -timeout 45m ./... at fe05f0a72 + this
  change: 76 packages ok; internal/provider red on
  TestClaudeAccountServesModelsListedSinceItsFetch only, green alone
  -count=5: the known #3174 (untouched here).
- Rebased on b2d005bf3 (grok.go, i18n.js changed there): internal/agent,
  appdir, agentenv, gui and the five GUI files above again, all ok.

Not tried: per-agent model overrides (agents.list[].model), a config
split with $include, a chat already pinned to a model, Windows and Linux
OpenClaw installs, a real WhatsApp channel.
2026-10-29 05:06:50 +08:00
yetone ec3dad75ae provider, gateway, gui, cli: Claude's accounts can be kept to Claude Code's own sign-in, magpie serving nothing on them (myduso)
myduso on Discord asked for an exclusive mode on Claude's subscription:
switch the credentials locally and proxy no traffic, since Claude Code
is used on its own and the SDK run magpie's bridge makes spends more of
the allowance than the interactive client.

The switch-only setting Codex has (#1907) now also takes claude. On it,
Provider.KeptToAgent is true and On() false, so the gateway, catalog,
groups, fallbacks, search, draw and embeddings serve nothing on the
Claude accounts, and a request naming them is refused 404 saying they
are kept to Claude Code's own sign-in and how to undo it (switchedOff).
Switching Claude Code's sign-in when an account is used up, and reading
usage, go on: both are gated by leftAlone on the raw Off, which this
doesn't set. Groups magpie found keep their Claude members
(heldOffEntries). Nothing is sent as Claude Code: magpie only writes and
restores Claude Code's own credentials as it already did.

GUI: the tick under Claude's accounts, shown with one account too, drawn
by the block Codex's tick had (one block now, its strings picked by
agent). app.js stays under its budget with no raise (1,311,711 of
1,311,735). CLI: magpie accounts switch-only <codex|claude> [on|off].
Docs: reference.md, subsystems/providers-accounts.md.

Run on mote at this tree on 06950fbbb; then rebased on aeacc6358 (two
app.js comments shorter) and go test -run TestCoreScriptBudget ./internal/gui
run again at the pushed head: ok.
- gofmt -l internal: clean. GOOS=linux go vet -tags nogui ./internal/...
  and GOOS=windows go vet ./internal/...: ok.
- go test -tags nogui -count=1 -timeout 45m ./internal/provider
  ./internal/gateway ./internal/cli ./internal/gui: all ok.
- node --test (Chromium + WebKit, every language the file covers):
  claude-switch-only (new), switch-only, keep-login, i18n-keys, gui-ja,
  gui-de, gui-zh-tw: 85 of 93 in one run beside other sessions' full GUI
  suites (load 23-73); the 8 reds (claude-switch-only chromium en/zh,
  gui-de and gui-ja in both engines) were not captured, and those files
  then passed alone twice (35 of 35 each run).
- Earlier, at ecbd694a2 (on ddf31ca30): internal/agent ok; add-sheet,
  api-key-usage pass; account-models and account-proxy 40/40 alone after
  8 browserType.launch timeouts at load 40-70 from other sessions.

Broken by hand, watched red:
- On() without the KeptToAgent term: TestClaudeSwitchOnlyServesNothing-
  AndStillSwitches and TestClaudeKeptToClaudeCodeServesNothing fail (the
  gateway ran Claude Code through the bridge, 200).
- SetSwitchOnly refusing claude: both fail.
- app.js without the claude branch: claude-switch-only 16/16 red in
  Chromium, switch-only (Codex) 16/16 green.

Not tried: real Claude accounts or a real Claude Code (the switch itself
is the existing path, tested with a fake claude in a sandbox HOME); the
whole GUI suite (only the files that open Claude's or a provider's
editor, plus the i18n ones); Linux and Windows test runs (vet only).
2026-10-29 04:15:56 +08:00
yetone e0ea15b8e8 library: an MCP hub, one magpie server in place of every library server (#2679)
With Library → MCP → "MCP hub" on (off by default), each agent that takes
an MCP server over HTTP is given one entry, magpie, at
/mcp/magpie/hub/<agent>, in place of the library servers ticked for it.
magpie runs those servers itself, once for every agent: a command starts
on its first call and ends after 10 idle minutes, a URL server is reached
with its headers and MCP sign-in. Tools are <server>__<tool>; a tool off
in the library is neither listed nor run. Any other app connects at
/mcp/magpie/hub, which serves every library server. Both are guarded as
/mcp/magpie/tools is (local or a gateway key, no foreign page, 4 MiB,
the key's limit per call). An agent that reaches no server over HTTP
(Claude Desktop), has a magpie entry of its own, or sits beside a library
server called magpie keeps each server's own entry, and the page says why.
Off gives every agent its servers back and ends every process the hub
started.

GUI: a switch under the MCP list, a line of what it serves, the address,
and a Connect… sheet. The sheet lists every agent magpie detects that
takes MCP (not a fixed four), each with where it stands; one given none of
the hub's servers has a Connect that ticks it for every server it can
reach (servers/agents-all), so it gets the entry, and the sheet stays
open. Then any other app: Cursor (when it isn't a detected agent), VS
Code, Other, with the JSON and, in the app, "Add to …" through the app's
own install link built in Go (servers/hub-open; the page never sends a
link). CLI: magpie library mcp hub on|off. Design: docs/subsystems/mcp-hub.md.

With #3885 (62045475b): with the hub on, Codex is given the one magpie
URL entry, and the servers behind it never reach runVia, which takes a
command server only; with the hub off Codex gets /mcp/run/<name> as before.
Rebased onto it; the one conflict was both commits declaring base in
syncMCP.

Run:
- At 62045475b + this (the pushed tree), on mote: gofmt -l, go vet,
  GOOS=windows go vet, GOOS=linux go vet -tags nogui clean; go test
  -timeout 45m internal/library (108s), gateway (510s), cli (50s) ok.
  The GUI files and internal/gui weren't run again: 62045475b touches
  neither, and the rebase changed nothing in them.
- At ddf31ca30 + this: go test -timeout 45m for
  internal/library, gateway, cli and gui on mote; gofmt -l; go vet,
  GOOS=windows go vet, GOOS=linux go vet -tags nogui; win-run of
  library-mcp-hub and i18n-keys (both engines, en zh zh-TW ja de, 420px).
  gofmt and the three vets clean; library, gateway (554s) and cli ok;
  gui ok but TestMainWindowCorners, red the same on origin/main ddf31ca30
  on mote (#3949); GUI 26 of 26 pass.
- Earlier base (582bd8036, before TestHubConnectAnAgent and the oneport
  consts): full go test ./... on mote, every package ok but gateway's
  TestClientPathCoversHandler (fixed here: HubMCPPath, HubMCPAll and
  {agent} added to its consts; passes) and internal/gui's AppKit tests.
  Of those, TestMainWindowCorners fails the same on origin/main ddf31ca30
  on mote's macOS 27 (#3949); the other six (dock, panel, plugin page,
  right-to-left) passed rerun alone at load ~95 (#2645).
- win-run of every library-*, gui-*, i18n*, click-scroll and menu-scroll
  GUI file: 49 files, 839 tests, 839 pass.
- Real use in WSL (magpie-desktop), sandbox HOME, real echo MCP server:
  hub on, Cursor given servers → ~/.cursor/mcp.json holds only magpie at
  /mcp/magpie/hub/cursor; initialize, tools/list (echo__echo) and two
  calls ran on one server pid; a foreign Origin got 403; hub off → the
  echo process ended, tools [].

Broken by hand: Connect button removed → 6 GUI cases red; the old row
wrap rule → 6 red (icon on its own line at 420px); EveryServerAgents
call removed from TestHubConnectAnAgent → red (hub "").

Not run: the whole GUI suite (~960 files); Windows agents (VS Code, Cursor
on Windows) against a real hub; an "Add to Cursor" click in the real app
(the link is built and tested, the app's own confirm wasn't driven).
2026-10-29 03:17:58 +08:00
yetone 40f206dff1 vertex: partner models (DeepSeek V4.1 Flash, GLM, gpt-oss) go to Google's OpenAI-compatible chat completions
Dani Ariyanto (Discord) asked for Vertex AI's partner/open models, such as
DeepSeek V4.1 Flash, beside Gemini. Google serves them (Model as a Service)
on an OpenAI-compatible chat completions endpoint in the same project,
https://<host>/v1/projects/<p>/locations/<loc>/endpoints/openapi/chat/completions,
with the same OAuth token. The model goes in the body as publisher/model
(deepseek-ai/deepseek-v4.1-flash-maas). Source: Google's
maas/call-open-model-apis page.

An existing Vertex provider needs no change. A model id with a slash
(VertexPartner) is a partner model, as is every publisher/model id that
models.dev lists for google-vertex as @ai-sdk/openai-compatible. It is
asked on Base(Chat) = <project base>/endpoints/openapi (ListedAPIs, so
ModelAPI can't move it). Gemini ids have no slash and stay on
streamGenerateContent. Speaks is now [chat, gemini].
- vertexEffort (Gemini's levels) no longer applies to a partner model.
  Before, a Codex xhigh was clamped to high.
- The provider's own test probes Gemini only. A partner model answers
  only after the project enables it in Model Garden, so an unenabled
  partner model would turn every Gemini user's test red. A partner model
  is tested by its own model test.
- tinyBody's chat probe uses Base(Chat), so the probe goes to the openapi
  address. That address is the only one Sign lets the token go to.
- A test as Codex is refused for Vertex, as it already is for Claude Code
  ("only of a relay").

The global list adds the three partner models that Google's docs list as
live at global on 2026-10-28:
- deepseek-ai/deepseek-v4.1-flash-maas (Preview, global only)
- zai-org/glm-5.2-maas
- openai/gpt-oss-120b-maas

Left out of the list: Gemma 4 (Experimental) and the models retired on
10-21 (v3.x, glm-4.7/5, qwen3, llama-3.3...). Gemma 4 still routes when
typed in by its full id. us/eu/regions are unchanged.

Docs: providers-accounts.md and gateway-routing.md Vertex rows;
reference.md (the global row, how a partner id routes, Model Garden
enablement, typing one in).

Run (on mote via mote-run):
- go test -tags nogui -run TestVertex ./internal/provider ./internal/gateway: ok.
- New: TestVertexPartnerModel (gateway). It covers Chat, Anthropic and
  Responses clients, streamed and whole, against a fake openapi endpoint
  answering in the shape of Google's docs. It checks the path, the Bearer
  token, the body model and the client's text, that Gemini stays on
  streamGenerateContent, and that xhigh is kept.
- New: TestVertexPartnerModels (provider). It covers Speaks/Base,
  APIs per model, the global list, no partner model at us/us-central1,
  that Test() probes Gemini alone, and TestModels on openapi with the
  minted token.
- TestVertexProviderListed now pins Speaks [chat gemini].
- go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet
  ./..., go build ./...: all ok; gofmt -l clean.
- Full suite: go test -tags nogui -count=1 -timeout 45m ./... at
  80f2bda50 (this change on cb167fcbd): SUITE-EXIT=0, 77 packages ok.
- An earlier full run at base 396e0e463 was red only in
  TestPluginStreamsPastTheBudgetWait. That is #3946, fixed in 7fd77a944
  after that base. It passed 3 of 3 alone at origin/main cb167fcbd.
- The final rebase onto b5d2858f4 (usage, a gateway test, LESSONS) was
  followed by go build and the TestVertex runs again; the suite was not
  run again.

Broken by hand:
- All nine non-test files restored to main, with VertexPartner kept so
  the tests compile: TestVertexPartnerModel red (asked
  publishers/google/models/deepseek-ai/...:streamGenerateContent with a
  Gemini body), TestVertexPartnerModels and TestVertexProviderListed red
  (speaks [gemini]).
- vertexEffort guard removed: red, "effort xhigh sent ... as high".
- Test()'s Vertex chat skip removed: TestVertexTestRequest and
  TestVertexPartnerModels red (a chat probe of the partner model).
- tinyBody back to q.Chat: TestVertexPartnerModels red ("asked only at
  Vertex AI, at its project's address").

Not tried:
- No real Vertex AI account or project here. Nothing reached Google:
  the endpoint, auth and response shapes come from Google's docs only.
- Per-model thinking controls (chat_template_kwargs: DeepSeek thinking,
  GLM enable_thinking) are not mapped. A partner model gets the generic
  chat completions reasoning_effort, and gpt-oss takes it natively.
- Claude on Vertex (publishers/anthropic rawPredict) is out of scope. It
  takes its own request shape and its ids have no slash.
- No GUI change (the API picker reads URL fields, which Vertex has
  none of), so no GUI suite was run.
2026-10-29 00:33:50 +08:00
yetone 6ecc65b6db agent: the CodeBuddy IDE is CodeBuddy too, found with no CLI
bjzhangwn on X: magpie supported CodeBuddy only as its CLI, not the IDE.
The CodeBuddy IDE (4.12.2, codebuddy.ai's CodeBuddy.app,
com.tencent.codebuddy, and codebuddy.cn's CodeBuddy CN.app,
com.tencent.codebuddycn) reads the file magpie already writes for the
CLI: its genie extension's CustomModelsProductProvider loads
~/.codebuddy/models.json's "models" (a string id and url each) and
"availableModels", and lists them in its own picker. So one row,
renamed CodeBuddy, stands for both. desktopApps gets a "codebuddy"
entry, with a "more" list for the second build's bundle id. A `sign`
lists the row with only the IDE installed. That row shows the IDE's
version, is never "CLI not found", and the CLI isn't offered for install.

Tests: TestCodeBuddyIDEIsCodeBuddy uses the real Info.plist bytes of
both builds, cut to their first keys. TestCodeBuddyIDEReadsMagpieModels
reads the written models.json the way the IDE's loader does.

Run (mote, macOS 27):
- gofmt -l: clean.
- GOOS=linux and GOOS=windows go vet of ./internal/agent/... and
  ./internal/sessions/..., plus GOOS=windows -tags nogui ./internal/gui:
  ok.
- go test -timeout 45m -count=1 ./... at d4f1d6480 plus this change:
  76 packages ok. One red, internal/gui TestMainWindowCorners/macOS_26_SDK,
  is #3949 (macOS 27, same output, untouched here).
- Rebased on origin/main 2ff85f8a2: internal/agent and internal/sessions
  ok again at the pushed head.
- Broken by hand, TestCodeBuddyIDEIsCodeBuddy goes red each way: with
  the sign off, and with the CN bundle id wrong.

Real app: the 4.12.2 builds (intl, then CN) ran on mote under a sandbox
HOME with --user-data-dir. Both logged "Loaded custom models config from
user: <home>/.codebuddy/models.json, valid=1" for magpie's entry.

Not tried:
- Hot reload is unconfirmed. In the not-signed-in sandbox, neither a
  rename nor an in-place edit made it load again (the cloud product
  fetch never finished), though its code fs.watches the file and
  debounces a sync.
- No chat through the gateway: it needs a CodeBuddy sign-in.
- The IDE's Windows and Linux install paths, so off a Mac it is found
  by ~/.codebuddy alone.
- The IDE ignores CODEBUDDY_CONFIG_DIR.
2026-10-28 22:48:07 +08:00
yetone 60520ddb3b moejs: v0.1.0-alpha.11, at its new module path github.com/MoeForge/moejs
Gateway middleware and agent plugins run on moejs. alpha.11 moves the
module to github.com/MoeForge/moejs; every other API change since
alpha.4 is an addition. What magpie gets: faster calls, loops, property
lookups and JSON.parse, allocation-free await, a bytecode verifier, a
correct default.pgo, and Intl / toLocaleString in plugin code.

Checked against both tags' source: every name magpie uses (NewRuntime,
Options, Compile, Link, Hook, Value, Arg, Undefined, NativeFunc,
Referrer, the Promise results, Exception) has the same signature, and
Options' defaults (shared frozen builtins, no timers) are unchanged.
fetch, Streams, URL, node:fs and node:buffer live in the separate
webapi and node packages, installed only on request; magpie installs
neither, so a plugin still reaches no network or file.

Intl's CLDR, Unicode, ICU and V8 material is compiled into every build,
and moejs asks a program that includes it to carry sections 1 to 4 of
its notices. THIRD_PARTY_NOTICES holds them verbatim. Release archives
ship no LICENSE today either; that is not changed here.

Doc and site links (docs/, site/public/docs/{,zh/,ja/}plugins.html)
point at the new repo.

Run on mote at this tree: gofmt; go build -trimpath -s -w (60,670,658
bytes on origin/main 58fb3a778, 62,329,250 now, +1.66MB); go vet of
middleware, jsmod, agentplug for darwin, linux and windows; go test
./internal/middleware/... ./internal/jsmod/... ./internal/agentplug/...
ok; go test -run 'Middleware|Strateg|OnUsage|JSPlugin|Agentplug|AgentPlug'
./internal/gateway ./internal/provider ./internal/plugin ./internal/gui
ok.
Not run: the full suite, the GUI suite, a real request through a
middleware in a running gateway.
2026-10-28 14:36:17 +08:00
yetone 6ce0f14b98 gui: magpie web's page port judges every gateway route as from another machine (reported privately by Coffemon)
Since 1b32bdcf (v0.1.1444) the page port of `magpie web` / `serve --web`
hands the gateway's client routes to the gateway. The gateway counts a
loopback request with no forwarding header as an agent on this computer,
which needs no key. A request reaching the page port over loopback without
such a header was answered that way, so the page port gave the gateway's
routes without a gateway key, with sharing off. Before 1b32bdcf every
request there needed the page's key.

Now every request the page port hands over is marked
(gateway.FromPagePort, the X-Magpie-Page-Port header) and local() is false
for it: answered only while magpie is shared (or on the network), with an
enabled gateway key, from loopback too, under any Host or browser marks,
and with MAGPIE_TRUST_PROXY set. While not shared lanGuard refuses it 403,
saying to use the gateway's own address. lanGuard moves the mark into the
request's context and drops the header, so it never goes upstream.
toGateway (another magpie serves the gateway) passes the mark on and adds
the loopback peer as X-Forwarded-For when no forwarding header came, so an
older gateway that doesn't know the mark still asks for a key. Agents on
this computer keep the gateway's own port (3425), key-free from loopback as
before. The page itself calls no client route (checked app.js and
plugins.js: the /mcp and /v1 addresses there are copied, not fetched), so
nothing in the GUI needs a key on the page port. The routes covered are
all of gateway.ClientPath (/v1, /v1beta, the routes without /v1, the Codex
backend path, the search path, /mcp), since the mark is set in onePort for
each of them.

docs/reference.md's one-port paragraph, gui-shell.md and
gateway-routing.md now say the page port answers these routes as from
another machine and that agents here use the gateway's port; the old text
said a same-machine proxy's requests carry forwarding headers, which a
forward that adds none doesn't.

Tests:
- TestWebOnePortServedHere / ServedElsewhere: a loopback request with no
  key and no forwarding header to /v1/chat/completions, /chat/completions,
  /v1/responses, /v1/messages, /v1/models, /v1beta/models, /mcp/github,
  /mcp/magpie/web-search and the Codex backend, under Host 127.0.0.1:3430,
  127.0.0.1, localhost:3430 and a public name, with a browser's marks, a
  CLI's user agent and an IPv6 loopback peer: 403 not shared, 401 shared.
  Red on the old code (404 "knows no model" / "isn't signed in to an MCP
  server": the handlers were reached). The old "for an agent here" 200 is
  now 401; loopback with a gateway key 200. Origin null, foreign Origin
  and rebound Host without a key now 401 (lanGuard asks the key first);
  a foreign Origin with a key still 403. A 429 from the process's
  failed-key bucket counts as the 401 it replaces.
- TestWebOnePortAgentsHereUseTheGatewayPort: the gateway's own Front from
  loopback without a key 200; the page port 403 with the reason and the
  gateway's URL; MAGPIE_TRUST_PROXY=1 doesn't make it local.
- TestPagePortMarkIsNeverLocal (gateway): marked requests never local
  under MAGPIE_TRUST_PROXY; refused unshared; with a key the handler sees
  no header and local false.

Broken by hand, each red, then restored:
- onePort not marking: ServedHere and AgentsHere red; ServedElsewhere
  stays green on the X-Forwarded-For fallback alone (the older-gateway
  path).
- local() ignoring the mark: ServedHere, AgentsHere, PagePortMark red.
- lanGuard not taking the header off: PagePortMark red (handler saw it).

Real try (built binaries, sandbox HOME, MAGPIE_NO_ACCOUNTS=1,
MAGPIE_TEST_SANDBOX; gateway 127.0.0.1:3561, page 3562, a raw TCP
forwarder (a Go listen/dial/copy loop, as socat would be) on 3563 -> 3562,
a fake OpenAI-compatible upstream on 3564 added as a provider):
- `serve --web` (gateway in process), origin/main c37bcdbfc binary: through
  the forward with no key, chat 200 (upstream called), /v1/models 200,
  /v1/responses and /v1/messages reached the provider, /mcp/magpie/web-search
  with Host 127.0.0.1 200; the page's /api/settings 401. 5 upstream calls.
  This change: every one of those 403 with the page-port reason; the
  gateway port's agent chat 200; 1 upstream call (the agent's).
- `serve` plus a separate `magpie web` (served elsewhere): old binary 200
  for chat and MCP through the forward, shared or not, with no key or the
  page's cookie only. This change: 403 not shared; shared, 401 with no key
  and with the page's cookie only, 200 with a gateway key; the page signs
  in through the forward and /api/settings is 200 with its cookie; the
  upstream request carries no X-Magpie-Page-Port.

Run at this head (rebased on origin/main f0ffee34c):
- go test ./internal/gui ./internal/gateway -run 'TestWebOnePort|TestClientPath|TestWebAssets|TestPagePortMark|TestAllowList|TestLAN|TestRebound|TestProxied' -count=1: ok
- gofmt -l internal/gateway internal/gui: empty; go vet (darwin),
  GOOS=linux go vet -tags nogui ./... and GOOS=windows go vet -tags nogui
  ./... (before the rebase), GOOS=linux/windows go vet of gateway, gui and
  cli at this head: ok
- The full suite (go test -tags nogui -count=1 -timeout 45m ./..., one per
  machine, waiting behind another session's run) was not run before this
  push: a security fix ships at once. It runs at this head next; any red it
  names gets its own commit.

Not tried: Windows and Linux beyond vet; nginx (its XFF path is unchanged
and covered by the "through a proxy" cases); a real vendor account; the
GUI suite (no GUI asset changed).
2026-10-27 15:15:29 +08:00
yetone 5215108e53 gui: magpie web shows MAGPIE_PUBLIC_URL at the sidebar's foot and in About's Gateway URL, as the Gateway page does (noahhrreion on Discord)
noahhrreion runs magpie in Docker and sets the gateway's address with
MAGPIE_PUBLIC_URL; the address at the foot of the page didn't show it.
Since #1551 a page other machines open (magpie web) shows
MAGPIE_PUBLIC_URL, while they are let in, as the gateway's address on the
Gateway page, starts Connect and its snippets at it, and uses it for
Settings' MCP addresses. Two places still said the container's loopback:
- the sidebar's gateway line (renderSideGw): it drew providers' and
  boot.js's `url` only. It now draws `publicURL` in magpie web, and
  boot.js's `sideGateway` carries it (same rule as settingsState: shared,
  or MAGPIE_ADDR on the network, as the image's 0.0.0.0 is)
- Settings › About's Gateway URL: in magpie web it is the public URL,
  and the separate Public address row, then the same, is left out
In the app on this computer both stay the local address that agents here
are pointed at, as before. The address list in Share on local network
already gives MAGPIE_PUBLIC_URL alone, and Connect and the copy buttons
were already at it.

Run (worktree at origin/main 11dcc743f + this, darwin/arm64, load ~150):
- go test -count=1 ./internal/gui/: ok (TestBootSaysWhereItsGatewayListens
  now checks publicURL is in sideGateway on the network and absent on
  loopback; the script budget tests pass, not raised)
- gofmt -l clean; go vet darwin and windows on internal/gui. The linux vet
  of internal/gui doesn't build Wails without cgo on this Mac, in Wails
  itself, as on main
- public-url-default.test.cjs, Chromium and WebKit, en zh zh-TW ja de,
  1100 and 420 wide: 26 pass
- the 18 GUI files on the changed caller-keys fixture plus sidebar,
  gateway-port, i18n-keys, settings-general, settings-sections and
  settings-search, 3 wide: 322 pass, 4 fail. Rerun 1 wide, 3 passed and
  gateway-caller-keys webkit stayed red at line 137; it is red 4 of 5
  on 11dcc743f without this change too, #3797. gateway-key-models webkit
  (#2648) and gateway-own-key zh 440 (#3842, filed now) passed alone.
Broken by hand:
- renderSideGw back on g.url: public-url-default's magpie web test red
  at 1100 wide
- About back on s.gateway: red at both widths
- boot.js without publicURL: TestBootSaysWhereItsGatewayListens red
Not tried: a real Docker container with MAGPIE_PUBLIC_URL; the page was
driven with a faked API. Not asked of the reporter yet: whether they open
magpie web, or the desktop app, which keeps the local address.
2026-10-27 13:30:16 +08:00
yetone 19dc5b9252 routing: accounts renewing together spend first the one whose credits left lapse first (zhaocai_83020 on Discord)
zhaocai_83020 on Discord asked how to make several WorkBuddy accounts
spend the credits that expire soonest first. Smart, the default routing,
already took a window's runsOutAt (plugin 0.1.14, cdredfox on X) as its
renewal, but only when it came before the window's reset. Since plugin
0.1.35 (windy on Discord) a WorkBuddy free account's Credits window
resets at the month's end, the same moment on every account (cycleOf,
packages/workbuddy usage.test.mjs CN_FREE: 10-31 23:59:59 +08), so given
credits lapsing after that end ranked alike and kept the accounts'
listed order: the account whose credits were lost first wasn't spent
first.

Allowance.Lapse is the soonest RunsOut in the future of a window that
counts the model, carried to routes.Seat.Lapse. Smart goes by it, to the
hour, only when the renewals tie: the one lapsing first goes first, one
telling none after those that do, the same hour keeps the listed order.
The share-used tiers and the renewal still decide before it. It is read
from the window's structure (RunsOut), not the provider's name; only the
WorkBuddy plugin sends runsOutAt today. Weekly pace and the other
routings are unchanged, as before. The gateway-strategy plugin seat
(middleware/points.go) doesn't carry it, as it carries no Free, Credits
or speed either.

Docs: reference.md (How magpie picks an account), gateway-routing.md,
site docs start.html en/zh/ja (not deployed by this commit).

Run at 2e165fe9d + this change; rebased onto 50606d8c0, which changes only internal/sessions:
  go test -tags nogui -timeout 45m ./internal/routes/ ./internal/gateway/  ok
  go test -tags nogui -timeout 45m ./internal/provider/ -skip
    TestUnreadLoginsWriteErrorsKeepCredentials  ok
    (that test crashes the package with "close of synctest channel from
    outside bubble" in filememo.Forget, untouched here: #3632, open,
    with patches under review there)
  go vet, GOOS=linux go vet -tags nogui, GOOS=windows go vet on
    ./internal/routes/ ./internal/provider/ ./internal/gateway/  ok
  gofmt -l on the changed files  clean
New TestSmartSpendsCreditsLapsingFirstWhenRenewingTogether: with
strategies.go put back to origin/main by hand it fails "lapsing first
goes first: ab"; green with the change. The windows are the plugin's
for a real China-site free account (reset at the month's end over 31
days, given credits lapsing on their own day).
Not tried: a real move of requests over several real WorkBuddy free
accounts (no such accounts on this machine), and a GUI run (no GUI
change).
2026-10-27 11:56:05 +08:00
yetone e7173958e9 agent: NewMax, magpie's models in its model picker (jwaitq on Discord)
jwaitq asked in #general (10-27) for NewMax (newmax.cc), an Electron app
built on the Claude Agent SDK. NewMax keeps its settings in
~/.newmax/newmax.db ($NEWMAX_USER_DATA_DIR wins), a SQLite table
settings(key, value) whose "app" row is JSON.stringify of every setting.
Connect adds one Anthropic-format provider, id magpie-gateway, with
magpie's gateway root (NewMax adds /v1/messages itself), its key and up to
20 models (NewMax's MAX_MODELS), appends it to providerOrder and, when
the user had kept NewMax's default, picks it. The row is edited by
splicing raw JSON in one immediate transaction, so every other byte the
user has stays as written. Disconnect removes the entry and its order id,
puts providerId/model back to "default" when they were magpie's, and
deletes the row when magpie made it. NewMax holds settings in memory and
writes the whole row on any change, so magpie refuses to write while
NewMax runs (macOS/Linux, matched on the program, not on a folder named
newmax) and says why in every language.

Run:
- go test -tags nogui -count=1 -timeout 45m ./internal/agent
  ./internal/agentenv ./internal/appdir ./internal/sessions at this head
  (rebased on 5e3dd1d52): ok
- gofmt -l clean; go vet darwin, linux (nogui) and windows on the touched
  packages
- GUI i18n-keys and agent-notice-lang, Chromium and WebKit: 15/15 each
Broken by hand, each red: user entry's name/off overwritten
(TestNewMaxProvider), running check removed (TestNewMaxLeavesAlone), row
kept after off (TestNewMaxMakesItsRow), pick left on magpie
(TestNewMaxProvider), no model cap (TestNewMaxModelCap), the first
process pattern that matched a shell in a newmax folder
(TestNewMaxProcess).

Real use: NewMax 1.1.22 (macOS dmg) in a sandbox HOME and
NEWMAX_USER_DATA_DIR, with this magpie on a sandbox port. Connect was
refused while NewMax ran; after quitting it wrote the row; on relaunch
NewMax's picker listed and picked magpie's models, its ClaudeProxy sent
to magpie's /v1/messages, and "Reply with exactly: pong" came back
"pong" through magpie to a fake Anthropic upstream. NewMax's own 58KB
row afterwards (47 providers) kept magpie's entry as written; disconnect
then removed only that entry, its order id and the pick
(live/deepseek/deepseek-flash -> default), every other byte the same.

Not tried: NewMax on Linux or Windows (Windows has no running check, as
pgrep isn't there); a real vendor reply through NewMax (the sandbox used
a fake upstream).
2026-10-27 11:03:41 +08:00
yetone cc9d68ffd3 agent: Antigravity CLI in a WSL distro is found and wired
mimi001234 (Discord, #general): agy installed in a WSL distro never
showed on the Agents page. wslKinds had no agy, so the distro probe never
looked for it.

agy is now a WSL kind (bin agy, dir .gemini/antigravity-cli), with the
model field offered for a stopped distro too. agy takes magpie only from
how it is started, and no magpie runs inside the distro, so a magpie pick
writes an agy shell function into the distro's own profiles: .bashrc,
plus .zshrc or fish's config.fish when the login shell in the distro's
/etc/passwd is zsh or fish. The function reads settings.json's model at
run time. It adds --model only for a magpie model the user didn't name
themselves, and sets GOOGLE_GEMINI_BASE_URL to place.gw() (the NAT
address, never 127.0.0.1) and GEMINI_API_KEY to the distro's WSL key.
Default removes the block. Check flags a function whose address has
moved, and Sync rewrites it. update.ShellFunction gained ShellFunctionAt,
DropShellFunctionAt and ShellFunctionInAt for profiles given by path
(fnProfile is now ShellProfile). This machine's own agy function is
unchanged. The restart notice is translated (de, zh, zh-TW, ja).
agent-wiring.md and reference.md are updated.

Run at c272f3799 + this change, then at this head (rebased on
65ee8c65c, which touched only gateway and plugin): the whole of
internal/agent and internal/update again, ok, and go build ok.
- go test -tags nogui -timeout 45m ./internal/agent/... ./internal/update/...
  ./internal/cli/...: update and cli ok. agent was red only on
  TestEveryNoticeIsTranslated (the new notice wasn't in i18n.js); after
  adding it, TestEveryNoticeIsTranslated and TestWSLAgy* are ok.
- go test -tags nogui ./internal/gui: ok.
- GUI, chromium and webkit: i18n-keys, agent-notice-lang and
  wsl-agents-setting all pass.
- gofmt -l on the changed files; go vet ./...; GOOS=linux go vet -tags
  nogui ./...; GOOS=windows go vet ./...; go build for darwin, linux
  (nogui) and windows: all clean.
- The bash and zsh functions are sourced in the test with a fake agy. The
  fish function was run in docker alpine:3.20 with fish.

Broken by hand, each red:
- bin "agyx" in the wsl kind: TestWSLAgyFound and TestWSLAgyStopped fail.
- 127.0.0.1 instead of at.gw(): TestWSLAgyPick and TestWSLAgyFunctionRuns
  fail.
- default not dropping the function: TestWSLAgyPick fails on .bashrc.

Not tried: real WSL. The Windows box (10.0.0.132) didn't answer ssh.
Fish wasn't tried inside a real distro.
2026-10-27 09:24:43 +08:00
yetone 9ae7912210 agent: plain agy starts Antigravity CLI on magpie in a new terminal
agy takes magpie's gateway, key (GEMINI_API_KEY, GOOGLE_GEMINI_BASE_URL)
and --model only from how it is started, so a user on magpie had to copy
the launch command at every start (bestony on Discord). Now:

- magpie agy run [args…] execs the real agy with the env and --model when
  agy's settings.json is on magpie's model (a --model/-model the user
  gives wins), and runs agy untouched otherwise. On Windows agy is a child
  through proc and its exit code is passed through. It refuses when "agy"
  on PATH resolves to magpie itself. magpie agy env prints what run adds
  (PowerShell's function reads it, since the desktop exe has no console).
- update.ShellFunction puts a function named agy in a marked block
  (# >>> magpie agy >>> … # <<< magpie agy <<<) of each shell profile
  cliShells finds: .zshrc (ZDOTDIR), the bash profile a terminal reads
  (.bash_profile, or .bash_login/.profile on macOS when that is missing),
  config.fish once its folder exists, and the PowerShell 7 / Windows
  PowerShell profiles where the execution policy runs them. Only the block
  is written, in place, temp-and-rename, CRLF and BOM kept; a profile that
  can't be read is not written; only files inside the home are. The
  function falls back to `command agy` when the magpie it names is gone.
- Set to a magpie model writes the block, stepping out takes it out (the
  file comes back byte for byte), and Sync at start writes it for users
  already wired.
- Notice, Launch tooltip and the connect panel say plain agy works in a
  new terminal, with the command for a terminal open now. Strings in
  i18n.js for zh, zh-TW, ja, de. docs/reference.md and
  docs/subsystems/agent-wiring.md updated.

Run at this head (base a3d4f8c5c, origin/main just fetched):
- go test -tags nogui -count=1 -timeout 45m ./internal/agent/...
  ./internal/cli/... ./internal/update/... ./internal/gui/...
  ./internal/proc/... : all ok.
- go vet ./... (darwin), GOOS=linux go vet -tags nogui ./...,
  GOOS=windows go vet ./... : clean. gofmt -l on the changed files: none.
- GUI (node --test, chromium + webkit): agy-launch, cursor-local-launch,
  agent-connect, agent-connect-no-models, agent-connect-all-hidden,
  agent-connected-unfolded, connect-address-kept, connect-snippet-shell,
  agent-notice-lang, agent-leave-magpie, agent-disconnect, copy-command,
  i18n-keys, gui-de, gui-ja, gui-zh-tw: 0 fail. Not the whole GUI suite.
- Real try, sandbox HOME under the scratchpad, nogui build, fake agy on
  PATH printing its args and the two env vars, env -i:
  magpie provider add deepseek + magpie agy deepseek/deepseek-chat wrote
  the block after the user's two .zshrc lines; `zsh -i -c 'agy -p hi'` got
  --model magpie/deepseek/deepseek-chat, GEMINI_API_KEY=magpie-agy and
  GOOGLE_GEMINI_BASE_URL=http://127.0.0.1:38712; `agy --model x` kept x;
  wiring again left .zshrc's mtime alone and added .bash_profile once it
  existed, and `bash -l -i -c 'agy -p hi'` got the same; `magpie agy env x`
  refused; magpie agy default took both blocks out, .zshrc equal to the
  original, and plain agy ran with no env and no --model.

Broken by hand, each red, then restored:
- no fnInHome check: TestShellFunction, TestShellProfiles red.
- block appended instead of replaced in place: TestShellFunction red.
- unreadable profile treated as empty: TestShellFunction red.
- blank line before the block left on removal: TestShellFunction,
  TestWithFnBlock red.
- --model always added: TestAgyRun red.
- Sync without agyShell: TestAgyShell red. Stepping out without
  agyShell(false): TestAgyShell red.
- app.js typed row off, typed tooltip off: agy-launch 4 of 10 red each.

Not tried: PowerShell on Windows for real (vet only); WSL; a user's own
`alias agy` (an alias beats the function); a terminal already open needs
the copied command; macOS bash started non-login reads .bashrc, which
isn't written; a Documents folder redirected outside the profile isn't
written.
2026-10-27 07:30:16 +08:00
yetone 1885c607e2 gateway: Antigravity answers Codex's switched threads and Hermes' old persona with no setup
Antigravity answers some agents' system prompts with a fake 429 "Resource
has been exhausted", whatever quota is left. Jodiezzzzzz on X (10-27): a
Codex thread begun on GPT-5.x and switched to an Antigravity model got 429
again and again. zgoodz on X: "antigravity在Hermes里一样429". v0.1.1625
told the Codex case as a 400 with "start a new chat", which isn't zero
setup.

What Google matches, each tried on a real Antigravity account on 10-27
(in the system instruction, any case):
- "x-anthropic-billing-header:" (Claude Code)
- "built on Anthropic's Claude Agent SDK" ("running within the Claude
  Agent SDK" goes through)
- "You are Codex, an agent based on GPT-5" / "..., a coding agent based
  on GPT-5"
- new: "Hermes Agent, an intelligent AI assistant created by Nous
  Research", Hermes' earlier default SOUL.md, kept by anyone who edited
  their SOUL.md. Hermes' current default ("You are Hermes Agent, built by
  Nous Research") goes through.
Each goes through with a zero-width space after its first letter.
"Y​ou are Hermes Agent, an intelligent..." still fails, so the
break goes inside the matched phrase itself.

Now codeAssistBody puts that zero-width space into each matched line
(antigravityCloak), in the system instruction only, and only for an
Antigravity account. Gemini CLI's account on the same envelope, and
every other provider and protocol, get the prompt as the agent wrote
it. The text added names nothing; it is one U+200B per line.
`magpie provider set antigravity prompt=as-written` (PromptAsWritten,
kept through Save/withPicks and the GUI's save) turns it off. Then the
v0.1.1625/#2156 fallback stands: a 400 with a hint (now one for Hermes
too, in the Routing page's five languages) and Antigravity skipped for
6h in a group.

Default-on, as the community antigravity-cloak middleware's README
says, changes what Google is sent so a request it means to refuse goes
through. That may be against Antigravity's terms. The owner asked for
it ("破解过 antigravity 提示词让其可以在别的 agent 中使用"), and it is
scoped to Antigravity accounts with an off switch.

Run at this tree (rebased on origin/main):
- go test -count=1 -timeout 45m ./internal/gateway/ ./internal/provider/
  ./internal/cli/ ./internal/gui/: gateway, cli and gui ok; provider
  died in TestUnreadLoginsWriteErrorsKeepCredentials ("close of synctest
  channel from outside bubble" in filememo.Forget), #3632, red on main
  since 091153bf; with -skip of that test, provider ok.
- gofmt -l: nothing. go vet ./..., GOOS=linux go vet -tags nogui ./...,
  GOOS=windows go vet ./...: ok. go build: ok.
- GUI (node --test, Playwright 1.62, chromium and webkit):
  routing-ag-turned-away, i18n-keys, gui-ja, gui-de, gui-zh-tw,
  routing-js, panel-routing: 45 pass, 0 fail.
- Broken by hand: with the cloak skipped, TestAntigravityAnswersHermes
  AndCodexByDefault and TestOnlyAntigravityIsSentThePromptBrokenUp go
  red; without withPicks' line, "prompt=as-written isn't kept".
- Real account, sandbox HOME with only the Antigravity login copied,
  this build on 127.0.0.1:3496:
  - real Hermes Agent (AIAgent, sandbox SOUL.md = the old persona plus
    one line): "OK", 200. With prompt=as-written: 400 with the Hermes
    hint. Back on default: 200.
  - real Codex 0.162.1: a thread begun on gpt-5.5 (against a local
    fake Responses server), then `codex exec resume <id> -m
    antigravity/gemini-3-flash` through this build: "OK". With
    prompt=as-written: 400 with the Codex hint.
  - a synthetic switched Codex Responses thread, with and without
    web_search: 200.
  - opencode, droid, kimi, pi, gemini-cli, qwen, crush, goose, amp and
    openclaw identity sentences: never refused, as written.
Not tried: Claude models on Antigravity (the sandbox account's Claude
quota is spent, so the Claude Code lines were checked on Gemini 3
Flash only); other agents' whole prompts, only their identity lines;
the Windows box; the whole GUI suite.

The plugins repo's antigravity-cloak 0.1.2 adds the Hermes line for
magpies before this one.
2026-10-27 04:16:20 +08:00
yetone 3fd7e16983 agent: PenguinHarness is installed from the Agents page and served by magpie with nothing to set up
rankyurky asked on Discord #feedback for PenguinHarness (npm
@prismshadow/penguin-cli, command penguin). Every value comes from
Penguin's own source (0.2.17):

- Config: $PENGUIN_HOME (else ~/.penguin/data, every OS) /
  $PENGUIN_PROJECT_ID (else default_project) /.project_config.toml.
  magpie writes [providers.magpie] (base_url, client_type, api_key),
  one [[models]] entry per magpie model (context_window, vision,
  max_tokens, [models.pricing] in usd_per_mtok) and default_model in
  Penguin's own inline spelling. Penguin's server reads the file again
  when its mtime changes, so no restart; a default naming no entry is
  refused by Penguin, so Check fails when one is missing.
- A file magpie creates is 0600 in a 0700 folder, as Penguin keeps it.
  Disconnect restores the user's own default_model (or none), drops a
  magpie vision model, and removes the file when magpie made it.
  Penguin's own entries, providers and command_policy rules are kept.
- A sync that changes nothing writes nothing (bytes and mtime kept), so
  Penguin's watcher isn't woken.
- Install: curl -fsSL https://penguin.ooo/install.sh | sh, or
  irm https://penguin.ooo/install.ps1 | iex on Windows; update: npm, or
  penguin update --yes for the tarball, except on Windows where
  update.ts refuses it.
- WSL: a penguin kind with no restart notice; the WSL test now expects
  an empty Notice for a kind with no restart.
- agentenv: PENGUIN_HOME, PENGUIN_PROJECT_ID; the project id is in
  NotPaths, or appdir dropped a value like "work" as a relative path.
- edit.SetTOMLArrayTables: replaces every [[name]] entry with key =
  value (with child tables) by blocks, or removes them; blank lines
  between replaced entries go with them, and an unchanged result isn't
  written.
- GUI: penguin-color.svg icon; README (en, zh-CN), docs/reference.md
  and docs/subsystems/agent-wiring.md.

Run (worktree at ca9b5048e, GOMODCACHE/GOCACHE pinned):
- go test -tags nogui -timeout 45m ./internal/agent ./internal/edit
  ./internal/agentenv ./internal/appdir ./internal/usage: all ok but
  TestWSLMoreAgentsPick (penguin has no restart notice), fixed in the
  test; rerun -run 'TestWSL|TestPenguin|TestEveryAgent|TestFolderVars|
  TestEveryNotice' ok.
- internal/gui: TestCoreScriptBudget, TestAssetTypesHoldAgainstTheRegistry,
  icon and i18n guards ok; no budget raised.
- GUI Playwright, chromium and webkit: i18n-keys, getting-started,
  agent-cli-missing, agent-update-all, gui-ja, gui-de, gui-zh-tw:
  123 tests, 123 pass. The icon renders in colour in both engines.
- gofmt -l internal/ clean; go vet -tags nogui ./... with GOOS linux,
  windows and darwin clean.
- Real Penguin 0.2.17 (npm, Node 25) in a sandbox HOME against a sandbox
  magpie serve and a fake upstream: penguin run -m "Say PONG" answered
  "PONG from fake" through magpie (usage agent "penguin",
  /v1/responses -> /v1/chat/completions); switching the model in magpie
  took effect with no Penguin restart; a no-op sync kept bytes and
  mtime; magpie penguin default restored the user's custom/my-own and
  left no magpie line; with no prior file it was created 0600 and
  removed on disconnect. The fixture is the file Penguin itself wrote.

- Rebased on origin/main d9a8148d7 and run again there: internal/agent -run
  'TestPenguin|TestWSL|TestEveryAgent|TestFolderVars|TestEveryNotice|
  TestSync', internal/edit, internal/agentenv and the internal/gui
  guards ok; gofmt clean.

Broken by hand, each went red: the no-op skip (mtime test), the 0600
create, the inline default_model spelling, the own-default restore,
removing magpie's file, dropping the vision model, the NotPaths entry,
and both SetTOMLArrayTables fixes (blank-line growth, unchanged write).

Not tried: the full ./... suite (machine load ~190-200, as asked); a
Windows or WSL real binary; Penguin's desktop app; a real vendor key
through Penguin. Penguin sends the openai SDK's User-Agent, so the
agent is named from its key, not its UA.
2026-10-27 01:38:45 +08:00
yetone d9a8148d7c routing: Speed first sends a request to the provider or key that answered the model fastest lately
joeliu96872540 on X: when one model is reachable through several API
channels, they want an option that sends each request to whichever has
been answering fastest, because they compare channel speeds by hand
today. Speed first (`fast`; `fastest` and `speed` also work) is a new
routing beside Free first. It applies to a provider's keys and accounts
(provider editor › Routing) and to a group of one model on several
providers (Routing page › group › Routing).

How it decides. When a streamed answer ends, gateway/speed.go records two
numbers for that account or key and model (restID): the time to first
token and the output tokens per second, as usage.DecodeOf computes them
for the Requests page. Each is a decayed average with a 20m half-life.
After an hour with no answer the record goes stale, and the store holds
at most 4096 records. This is O(1) at the answer choke point, beside
servedCandidate. For a pool routed by BySpeed, weighRouted reads one map
entry per candidate, and only for that pool. The usage history is never
read on a request.

routes.Fastest ranks each awake seat by its estimated time to a
200-token reply: TTFT + 200/TPS. A seat that reported no TPS gets the
median TPS of the others. Seats within 10% of the fastest in their band
keep their listed order, so near-ties don't swap on every request.
Seats with no recent measurement go after the measured ones. One request
in five, counted per pool, goes first to an unmeasured seat, rotating
among them, so each gets measured again. Resting seats go behind the
awake ones, and used-up seats behind those. Rests and failover are the
same as for every other routing.

The request trace gets lateTtft and lateTps, and the row-story sentence
says "answered m fastest lately: first token in 0.8s, 60 tokens a
second". It has a variant for a probe turn and one for when no seat has
been measured yet. i18n covers zh, zh-TW, ja and de. Also updated: the
CLI (`magpie group|provider set <id> routing=fast`, plus a new
`routing=` pair on provider set that refuses manual), the TUI name, the
rotation plugin's Sub, docs/subsystems/gateway-routing.md,
plugin-runtime.md, docs/reference.md and site start.html (en, zh, ja).
There is no new layout: it is one more item in the existing pickers.
app.js stays under its budget with no raise.

Tests:
- routes/fastest_test.go:
  - ordering: fastest first, slow writer loses, alike keep order,
    resting and used-up, median pace, none measured;
  - the probe turn at 5, 10, 15 and 20, rotating between seats;
  - a resting seat never gets a probe turn.
- gateway/speed_test.go:
  - decay, staleness and per-model records, with an injected clock;
  - a group of slowv and fastv routed fast: after the speeds are
    measured and seeded, the request goes to fastv with lateTtft set;
  - the same group routed in order still goes to slowv.
- cli: parseRouting and the provider routing= pair.
- GUI routing-speed-first.test.cjs: the row story for measured,
  no-pace, probe and none, in en, zh, zh-TW, ja and de, in chromium and
  webkit: 40/40.

Broken by hand:
- Fastest returning the listed order: the routes tests and the gateway
  group test go red.
- noteTrySpeed removed: "the streamed answer wasn't measured".
- The client.js case renamed: routing-speed-first 0/20 in chromium.

Run at b5a5caff2 (base 5b4dec58e):
- `go test ./... -count=1 -timeout 45m`, alone on the machine, at load
  130-230. Every package is ok except:
  - internal/provider: TestUnreadLoginsWriteErrorsKeepCredentials
    crashes with "close of synctest channel from outside bubble"
    (#3632, open);
  - internal/gui: TestMainWindowCorners and
    TestTrayCellClickReleasedPanel are killed at their deadline under
    load (#1936, #2645).
- gofmt -l is empty. go vet is ok on darwin, on GOOS=linux with -tags
  nogui, and on GOOS=windows for ./internal/....
- GUI files the change reaches, both engines, every language they test,
  all ok: i18n-keys, gui-de, gui-ja, gui-zh-tw, routing-save,
  routing-save-keeps-the-row, builtins, panel-routing,
  panel-routing-pick, panel-routing-providers, panel-routing-hidden,
  routing-key-windows, key-weight, key-weight-fit, group-member-weight,
  routing-weight-chip, account-arrange and routing-speed-first (40/40).
- routing-group-strategy was 4/18: the menu now has 9 items and the test
  still counted 8. Fixed in this commit; rerun, it is 18/18.
- routing-save-blank (a webkit click timeout) and routing-columns (zh
  "side by side") each failed one subtest at load ~200. Rerun alone,
  they are 4/4 each. Both are already filed (#1924, #1612).

Rebased on 8f023b511, where upstream changed gateway.go, app.js, client.js,
the routing plugin's i18n.js and gateway-routing.md; the rebase was clean.
At this head I reran gofmt, go build ./... and go vet (darwin, linux
nogui, windows) on routes, gateway and cli, and go test for routes, cli,
provider and gateway (the routing and speed tests) and for gui -run
Budget: all ok. The GUI files i18n-keys (4/4), routing-speed-first
(40/40) and routing-group-strategy (18/18) also passed.

Not tried:
- A real run against several channels of one model. Speeds come from
  real answers, so the first minutes after a start are in listed order
  plus probes.
- A non-streamed reply is not measured, a sub-millisecond TTFT is not
  counted, and a restart forgets every speed.
- The Windows runtime: only go vet ran for it.
2026-10-27 01:37:38 +08:00
yetone 4a33cf0a98 update: a Stable channel in Settings → About, and magpie update channel
ssharpcc on X reads every changelog before updating, for fear of a ban
when behind, and with many releases a day that is a lot of reading.
Settings → About → Update channel (zh: 更新渠道, 稳定版 / 每个版本) picks
Every version, the default and today's behaviour, or Stable: one version
a week, the newest that had been out three days as the week began
(Monday 00:00 UTC), and an urgent release at once. usemagpie.ai chooses
it from the release list (the previous commit); a release is urgent when
a line of its notes starts with "**Urgent release:**", which
magpie-releases' release run writes from an `Urgent: <why>` trailer
(magpie-releases 73f6cff).

- settings: updateChannel, "" or "stable"; anything else is refused.
- update: on Stable the feed is asked with channel=stable; What's new
  shows every release since the installed one (up to 1500) instead of
  the newest 40, so a week's notes read as one list.
- gui: the row is segs, never a <select>; a save that doesn't send the
  channel keeps it; switching asks the feed again at once, and a
  download from every version newer than Stable's pick is dropped,
  never restarted into. What's new's notes are kept per channel.
- cli: magpie update channel [stable|every] ("all" too), and it says
  which with nothing after it.
- docs: reference.md's Update channel (the rule and the marker); the
  privacy pages (en, zh, ja) name ?channel=stable on /api/latest.

The full Go and GUI suites were not run: the disk was at 3 GB free and
other sessions had GUI suites and a 45-minute gateway run going the
whole time.

Run, at this tree before the rebase:
- gofmt -l (clean); go vet on darwin, GOOS=linux -tags nogui and
  GOOS=windows for ./internal/update/... ./internal/cli/...
  ./internal/settings/... ./internal/gui/.
- go test -count=1 ./internal/update/... ./internal/cli/...
  ./internal/settings/...: ok. ./internal/gui -run
  'TestUpdateChannelSwitch|TestWhatsNewKeyedByChannel|TestCoreScriptBudget':
  ok (the app.js budget passes).
- GUI, chromium and webkit: update-channel (22: en, zh, zh-TW, ja, de at
  900 and 420 wide: default lit, Stable saved, kept by another save,
  kept over a reload, Every saved back, no click scrolls, no sideways
  scroll at 420), i18n-keys, gui-ja, gui-de, gui-zh-tw and every
  update-*.test.cjs: 253 of 253 pass.
- The live feed: /api/latest?channel=stable answers 0.1.1327 (out
  2026-10-22 21:55 UTC, the last before Friday 10-23 00:00) with 15
  assets after the first real cron run filled the ledger (400 releases
  back to 10-10); /api/notes 0.1.1200..0.1.1327 gives 124 notes, none
  empty (1213 and 1218 were never published).

After rebasing on afc99490f: TestCoreScriptBudget, the channel Go tests
(update, cli, gui) and GUI i18n-keys + update-channel (both engines,
26 of 26) pass again.

Broken by hand, each red: the feed asked without channel=stable
(TestLatestAsksTheChannel); Stable capped at 40 (TestStableNotesAreAll);
any channel saved (TestUpdateChannelSaved); "all" dropped
(TestUpdateChannelCmd); a save without the field clearing it, no new ask
on a switch, the newer download kept (TestUpdateChannelSwitch); one
notes key for both channels, What's new capped at 40 on Stable
(TestWhatsNewKeyedByChannel); app.js's other saves dropping the channel,
Stable's click saving "" (update-channel 11 of 11 red); the zh label or
a de subtitle taken out (update-channel and i18n-keys red).

Not tried: the full go test ./... and the whole GUI suite (above); a
real app switching channel against the live feed; Windows and Linux
runs (vet only); a real urgent release.

Requested by ssharpcc on X.
2026-10-26 21:09:44 +08:00
yetone ea1f9492bc cli: magpie tools lists, and magpie tool calls, the tools magpie's MCP servers give agents (iwinux)
iwinux on Discord (#feedback) wanted magpie's image generation, image
recognition and web search without going through an agent's MCP, and had
written a Python script for generate_image. magpie now has it:

  magpie tools [<name>]
  magpie tool <name> [--<param> <value>…] [<words>…] [-o <file|folder>] [--json]

Both ask the running gateway's own MCP servers (gateway.OwnMCPServers:
image, vision, web-search, plugin tools) over HTTP, with the local token
and the magpie-tool/1 User-Agent, so the tools, schemas, models from
Settings and usage counting are the ones an agent gets. Nothing is
started besides (#3318: the cases sit before startUp, beside mcp).

- Parameters are read against the tool's inputSchema: types (integer,
  number, boolean, array given once per item, object as JSON), enum, -
  and _ alike, --p v or --p=v. The words left over are the tool's one
  required text, else its prompt. An unknown flag or parameter, a missing
  required one, a bad value, a value given twice or both words and the
  same --param are refused with "nothing was called"; no request is sent.
- A file path a parameter takes (its description says file and path)
  is made absolute, since the gateway doesn't know the current folder.
- --help prints toolUsage (static): help is handled before anything runs.
- A still-being-made answer is waited on with generation_result (1s
  between asks, 30 min at most). The gateway's image server now says so
  in _meta too: usemagpie.ai/pending is the id, usemagpie.ai/files the
  files made ({url, inline}); an older gateway is read from its text.
- Images and videos are saved through imagemcp.Target (now exported):
  -o file or folder, else the current folder named from the prompt,
  numbered when more than one, never over a file that is there; a file
  not inline is downloaded by its path from the gateway asked (the token
  goes nowhere else). --json prints the raw answer and saves nothing.
- No magpie at the address: "magpie isn't running at <url>: open the app
  or run magpie serve". MAGPIE_GATEWAY=<url> points at another.

Docs: usage lines in magpie help, docs/reference.md (Use), the gateway
routing subsystem page (_meta and the CLI), README en/zh, site docs start
page en/zh/ja.

Tests (internal/cli/tool_cli_test.go, never the network; every test sets
MAGPIE_GATEWAY to its own httptest server):
- TestToolsListsTheServersTools, TestToolReadsParameters,
  TestToolRefusesWhatItDoesntKnowAndCallsNothing (no tools/call, no file),
  TestToolHelpCallsNothing (no request at all), TestToolSavesTheImage,
  TestToolWaitsOnWhatIsStillMade (pending _meta, then the old text form,
  download with the key from the gateway asked, not the URL's host),
  TestToolErrorIsSaid, TestToolSaysMagpieIsntRunning,
  TestToolDrawsThroughTheGateway (the real gateway.New().Handler() with a
  fake vendor: lists, draws, saves the vendor's PNG).
- TestImageMCPDrawsAndServesTheImage, ...SlowDrawingIsWaitedOn and
  ...MakesVideos now check the _meta. Red on the old behaviour: with
  withMeta setting nothing (what main answers) all three fail ("_meta
  map[], want pending img_…").
- Broken by hand: dropping the unknown-parameter check makes
  TestToolRefuses… red (the --model call was made); saving an inline
  image by its URL instead makes TestToolSavesTheImage red. Both restored.
- TestHelpOnEveryCommandDoesNothing covers tool and tools.

Run with this change on origin/main 630fd1d69, then rebased on cebd0d4c3
(internal/pii, internal/gui, docs and site/ changed between, nothing
this change touches): there
gofmt, go vet of cli/gateway/imagemcp, internal/cli, internal/imagemcp and
the gateway's TestImageMCP/TestVisionMCP/TestSearchMCP again, ok.
At 630fd1d69:
- gofmt -l: nothing. go vet ./...; GOOS=linux go vet -tags nogui
  ./internal/...; GOOS=windows go vet ./internal/...: clean.
- go test ./... -timeout 45m: internal/gateway, imagemcp and the rest ok;
  ten packages failed with "no space left on device" (the machine's disk
  was full from other runs). Those rerun when space was back: agent, cli,
  davsync, gui, library, sessions, settings, tui, usage, usageapi,
  wslrun, plugins/... ok. internal/provider crashes in
  TestUnreadLoginsWriteErrorsKeepCredentials with "close of synctest
  channel from outside bubble" (filememo.Forget), twice: that is #3632,
  open, on main since 091153bf7, nothing this change touches.
- Real try: a nogui build of this head as magpie serve on 127.0.0.1:3482
  under a scratch HOME, a custom provider pointed at a local fake images
  API. magpie tools listed image, vision and web-search with their
  parameters; generate_image "…" --size 1024x1024 -o hero.png saved a PNG
  and the vendor got prompt and size; --n 2 --quality high saved two
  numbered files; --model was refused before calling; analyze_image and
  web_search said what to set up (no vision model or search API there);
  --help asked nothing. Usage counted the calls as magpie's own.

Not tried: a real image vendor, a real vision or search model, a video,
a plugin's tool through magpie tool, Windows and Linux runs (vet only).
2026-10-26 18:42:35 +08:00
yetone a7072926d6 agent: connecting Kiro Crew connects the harness it is set to (wuping9525)
wuping9525 (Discord, Windows): Kiro Crew's Agent Harness was Claude Code,
Claude Code was installed but not connected to magpie, and turning Kiro
Crew on refused with "connect Codex, Claude Code, ... first". On a Mac it
worked only because a harness (Codex/Claude Code) was already connected;
Crew's home is found the same way on Windows (USERPROFILE\.kiro\crew).

Now, when agent.acp_backend names one of magpie's harnesses (codex,
claude, opencode, pi, goose) and that agent is installed but not
connected, connecting Kiro Crew connects it in the same action and runs
Crew on it; the notice says so. The stash's kirocrew.joined records it.
Kiro Crew's Disconnect disconnects that agent again only if magpie
connected it and the user hasn't disconnected it since (kiroCrewUserLeft
in Agent.Disconnect); a disconnect the user made before stays recorded as
theirs. A failed Crew write undoes the join. config.local.json pins,
kas/kiro/deepseek and harnesses not installed behave as before.

Windows: the adapter search also tries npm's .cmd/.exe/.bat shim names,
and the app is detected by ~\.kirocrew-app\.venv\Scripts\kirocrew.exe.
New notice translated in zh, zh-TW, ja, de; docs/subsystems/agent-wiring.md
and docs/reference.md updated.

Run (macOS, sandbox HOME, GOMODCACHE/GOCACHE pinned), at base 11c3fbb19;
after rebasing on 2921471de (no change under internal/agent or internal/gui
since), go vet and go test -run 'KiroCrew|Disconnect' ./internal/agent
again: ok.
- go test -tags nogui -timeout 45m ./internal/agent ./internal/gui: ok
  (252s, 62s)
- new tests: TestKiroCrewConnectsItsHarness (real Claude Code wiring in a
  sandbox), TestKiroCrewLeavesTheUsersHarness (connected before, taken
  back after, off before), TestKiroCrewHarnessNotHere, TestKiroCrewOnWindows
  (kiroCrewOS forced to windows, PATH emptied)
- gofmt -l clean; go vet nogui for darwin, linux, windows; windows build
- GUI: agent-kiro-crew-lang, i18n-keys, gui-de, gui-ja, gui-zh-tw in
  chromium and webkit: 35/35 pass

Broken by hand, each red: no join (ConnectsItsHarness, taken back after,
off before), no kiroCrewUserLeft hook (taken back after), always forgetting
the user's disconnect (off before), no .cmd names and no venv exe
(OnWindows), no leave on Disconnect (ConnectsItsHarness, off before);
notice dropped from the NOTICES list: agent-kiro-crew-lang 9 red.

Not tried: a real Kiro Crew or Windows machine (the Windows box's ssh
timed out); the disconnect preview doesn't show the joined harness's
files, since it copies only Crew's folder.
2026-10-26 16:31:14 +08:00
yetone ef0a03e137 otel: Langfuse is set up from its host and the project's two keys
A user on X asked for Langfuse built in. magpie could already export to
Langfuse over OTLP, but Settings › Observability had the user type the
endpoint .../api/public/otel and a percent-encoded
Authorization=Basic%20<base64(pk:sk)> header by hand.

Settings › Observability now has a Collector row: OTLP or Langfuse.
With Langfuse, the user picks the host (Cloud EU, Cloud US, or
Self-hosted with an address, which also covers Langfuse's JP and HIPAA
regions) and fills in the public and secret keys. Once both keys are
there, magpie saves:
- the endpoint <host>/api/public/otel;
- Authorization: Basic base64(pk:sk), in otel.headers as before, so the
  secret is stored where it was and a backup without keys leaves it out;
- on a first setup, also x-langfuse-ingestion-version: 4, metrics off and
  export on. langfuse.com/docs/opentelemetry/get-started (read 10-26)
  gives the same header for every region and for self-hosted, and says
  that without it OTLP data can arrive up to 10 minutes late.
A Langfuse endpoint set up by hand opens in this view with its keys
decoded into the fields. Opening it saves nothing. Changing a key or the
host keeps the user's other headers, their metrics and export choices,
and an ingestion header they set or left out. Switching from another
collector leaves that collector's headers behind and does not send them
to Langfuse.

The Observability page moved from app.js into the otel plugin
(assets/plugins/otel/page.js, with i18n.js for its words, in Client),
because app.js had 13 bytes of budget left. The app.js and core budgets
are lowered to what is left (1,321,319 and 1,537,645; app.js is
1,321,313 after rebasing on 2620dc319). "Collector" and "Secret key" go
in the core i18n.js because other files use the same words.

Docs: reference.md's Langfuse paragraph (with the env form for magpie
serve) and the en/zh/ja privacy pages.

Run (macOS):
- go test ./... -timeout 45m -count=1 at the pre-rebase head (parent
  e5dd86965): every package ok but internal/provider, which crashed in
  TestUnreadLoginsWriteErrorsKeepCredentials with "close of synctest
  channel from outside bubble" in filememo.Forget. That is #3632, red on
  main since 091153bf7.
- The whole GUI suite (make test-ui, concurrency 4, Chromium and WebKit)
  at the same head: 16 reds. Each red file was run alone here and at the
  parent e5dd86965. The same reds came back at both: menu-input-scroll
  (#3402), old-webkit (#3403) and plugin-card-update's webkit Update
  (#3079). The parent also failed fonts' webkit run. page-width,
  api-key-theme, panel-arrange, panel-balance-order, own-requests,
  library-mcp-health-wsl and plugin-list-error passed alone here: 137
  passes, 7 fails, all of them the three filed above.
- At the pushed head (rebased on origin/main c87a0179b): the budget
  tests; otel, otel-langfuse, i18n-keys, settings-sections, builtins,
  idle-ticks and page-width, both engines, 58 pass; go test
  ./internal/otlp ./plugins/otel ./internal/gui, all ok except
  TestRestartHandsTheGatewayOver (#3451). That test failed 1 of 8 here
  and 1 of 8 on origin/main dce7fe609.
- Before the rebase: otel-langfuse (new: first setup, US, self-hosted,
  hand setup kept, another collector's headers dropped, 5 languages at
  1100/520/360px) with otel, i18n-keys, settings-sections, builtins,
  readable-focus, segs-press-redraw, ux-safety, dialog-backdrop-drag and
  mono-icon-redraw: 113 pass. go vet for darwin, linux and windows on the
  touched packages; gofmt -l clean.
- Broken by hand: with every save treated as a first setup and the old
  collector's headers carried over, otel-langfuse's "set up by hand keeps
  its values" and "another collector's headers" went red.
- New TestOTelLangfuseSetup: settings saved as the page writes them reach
  a fake collector at /api/public/otel/v1/traces with the Basic header and
  ingestion version 4, and nothing on /v1/metrics.
- Real app: a -tags dev build in a sandbox HOME (ports 3461/3462). I
  drove its real Settings page with Playwright: Langfuse, then
  Self-hosted http://127.0.0.1:3463, then both keys. settings.json got the
  endpoint, Basic header, version 4 and enabled. A gateway request then
  reached a local fake collector at /api/public/otel/v1/traces with
  Authorization Basic base64(pk-lf-real-ui:sk-lf-real-ui) and
  x-langfuse-ingestion-version 4.

Not tried: a real Langfuse Cloud or self-hosted project (no account here),
so Langfuse accepting the spans and how they show in its UI aren't checked.
The TUI and magpie serve still have no Langfuse shortcut; serve takes the
env form in reference.md. The Linux app (WebKitGTK) and Windows weren't
tried; the change is form fields and segs, with no motion.
2026-10-26 15:11:37 +08:00
yetone 7499ebb5ef gateway: magpie goroutines answers ahead of the locks a stuck request holds
Two users on X (v0.1.1549 to v0.1.1557, Windows, Codex routing) see
/api/hello answer while /v1/models, Providers and agent requests hang.
`magpie goroutines` (b18a6a080, #3362, since v0.1.1404) can capture the
stuck process, but its route sat behind lanGuard's allow list
(settings.json's file lock) and holdCatalog (provider.Hold, filememo),
so a request stuck holding any of them would hang the dump too.

dumpFirst serves GET /v1/magpie/goroutines, for callers
goroutinesRefused lets in, ahead of lanGuard in Front and ahead of
counted/holdCatalog in Handler. It reads only the request, the
environment and the runtime. Every refused or other request goes on
as before; a caller it lets in is one lanGuard and corsGuard already
let in (loopback, unproxied, no browser marks, loopback Host).

docs/reference.md now says how to run it from an app install, where
magpie isn't on PATH unless Settings > Command line adds it:
macOS /Applications/magpie.app/Contents/MacOS/magpie goroutines;
Windows PowerShell
  & (Get-ItemPropertyValue 'HKCU:\Software\Microsoft\Windows\CurrentVersion\App Paths\magpie.exe' '(default)') goroutines | Out-Host
(| Out-Host so PowerShell waits for the GUI-subsystem exe), or a
portable copy's own path.

Run, at this tree on c0985122b:
- go test -tags nogui -count=1 -timeout 45m ./internal/cli ./internal/gateway:
  ok cli 36.2s, ok gateway 388.7s
- TestGoroutineDumpAnswersWhileRequestsWait -count=3: ok
- gofmt -l: clean; GOOS=linux and GOOS=windows go vet -tags nogui
  ./internal/...: exit 0

Broken by hand:
- Front back to lanGuard(s.Handler()): the new test is red at 20.02s
  ("the dump didn't answer while settings.json's lock was held").
- Both refusal checks (dumpFirst and goroutineDump) removed:
  TestGoroutineDumpOnlyToThisComputer red, 25 failure lines.

Real use, Windows box: v0.1.1558 magpie-windows-amd64.exe (SHA256
matches SHA256SUMS) serving a sandbox home on :3447; the App Paths
one-liner above saved the dump and printed "goroutines 41", exit 0;
`& exe goroutines` with and without | Out-Host both saved it.

Not tried: a really stuck app; this build on Windows or macOS (the
real-use run above was v0.1.1558, without dumpFirst); an interactive
PowerShell console without | Out-Host; the Handler-only path has no
red test, since provider.held can't be held from the gateway package.
2026-10-26 05:53:34 +08:00
yetone 0152f66966 provider: a Remote magpie's model list follows the other magpie's, fetched every 10m (6igsteven on Discord)
6igsteven (Discord, 10-24/10-25): GLM-5.3-Trial and GLM-5.3-Flash-Trial
are listed on the magpie that runs the ZCode plugin, and not on the
magpie that uses it as a Remote magpie. The trial entries come from the
ZCode plugin once it reads the account's gift (zcode 0.1.26), and the
other magpie's /v1/models lists them as it lists every catalog entry.
But a Remote magpie is a provider of keys: its list was fetched when it
was added and then only when Fetch models was pressed in its editor
(KeepListsFresh asks only providers with a RefreshEvery, FetchNew only
accounts). So anything listed there later (the trial models, a new
provider, plugin or routing group) never reached this magpie.

A Remote magpie with no RefreshEvery now has a 10m schedule
(RemoteMagpieEvery, RefreshSchedule), so KeepListsFresh refetches it
through the same Refetch as Fetch models. `magpie provider refresh-every
<id> off` on a Remote magpie is kept as "off" rather than "" so the
user's off isn't read as unset. CLI show/refresh-every print the
schedule in force. Other providers are unchanged: no schedule means
only when asked.

Run: TestRemoteMagpieListFollowsTheOtherMagpie (new) with
TestKeepListsFreshFetchesWhatIsDue, TestParseRefreshEvery,
TestSaveKeepsTheListsScheduleAndRules: ok, sandbox HOME, Go caches
pinned. Broken by hand: RefreshSchedule returning RefreshEvery alone
(the old behaviour) fails the new test with "asked [], want [office]";
restored, ok. gofmt -l clean.
Then, at this commit: go test ./internal/provider ./internal/cli ok
(140s, 58s); go vet ./... on darwin, GOOS=linux -tags nogui and
GOOS=windows ok; darwin, linux (nogui) and windows builds ok.
Not run: go test ./... - the machine's disk had under 1GB free
(other sessions' work) and load ~200, so a full suite would not fit.
Not tried: a real two-computer setup with a live ZCode gift. A Remote
magpie whose user curated its picks (left a listed model unpicked)
still doesn't take new models by itself (withNewlyListed, by design).
2026-10-25 16:30:48 +08:00
yetone a2ff7e6cab plugin: add takes a community plugin's name (WorkBuddy, think-tags, qoder-cn)
Atlas on Discord (#help, 10-25, Linux): `magpie plugin add WorkBuddy`
said "isn't an npm package name". Worse, a bare `workbuddy` passed the
npm-name check and installed npm's unscoped workbuddy@latest, not
@magpie-community/opencode-workbuddy-auth.

plugin.Add, which the CLI, the Plugins page's field (/api/plugins/add)
and the movers all go through, now resolves a bare name first
(internal/plugin/resolve.go). Case aside, a name one community listing
goes by is its package, at the version given: the package or its bare
name, the short name (workbuddy, think-tags), the shown name (WorkBuddy,
Command Code), a provider id it serves or the subscription it replaces,
and a retired subscription's id through its mover (qoder-cn; provider
sets plugin.SubscriptionPlugin = MovePackage). The CLI says which
package it picked. A name two listings go by, or none that isn't an npm
name, is refused with the community plugins listed. A name no listing
goes by is npm's own package (opencode-gemini-auth keeps working), but
only when the list was fetched within the six hours: when the fetch
fails, the copy kept or built in may not name a newer plugin, so the
name is refused with why, and npm:<name> installs npm's package as
written. market() now says whether its list is a fresh fetch (marketErr).
Scoped names, paths and git specs are unchanged. A backup's or a sync's
plugins go in by their own spec (plugin.AddExact via addPluginExact),
never resolved, so a restore isn't held by GitHub being unreachable.
Update, Upgrade and InstallMissing use add with stored specs, unchanged.

Tests (fake registry over httptest, fake bun; no network):
TestResolveCommunityNames, TestResolveRefusesWhatItCantName,
TestResolveListUnread, TestAddByCommunityName. TestUpdateAllUpdatesAPinnedPlugin
adds an unscoped third-party name, so it now serves a registry.

Broken by hand: Add without resolve -> TestAddByCommunityName red with
the reporter's own error ("WorkBuddy" isn't an npm package name) and
workbuddy -> workbuddy@latest. The unread-list rule turned off (valid
name goes to npm regardless) -> TestResolveListUnread red.

Real use, sandbox HOME, built binary, real npm and GitHub:
`plugin add WorkBuddy` -> installed @magpie-community/opencode-workbuddy-auth@latest,
listed workbuddy and workbuddy-ai; `think-tags` -> middleware-think-tags;
`opencode-gemini-auth` -> npm's, google-plugin listed; `qoder-cn` with
MAGPIE_PLUGIN_MARKET=off -> opencode-qoder-auth; "Work Buddy Pro" ->
refused with the 38 community plugins listed; `twinz` with the list off
or at a dead URL -> refused, saying why and npm:twinz.

Run at this head (rebased on origin/main 42976f9a0): gofmt -l clean;
go vet (darwin) and GOOS=linux / GOOS=windows -tags nogui vet of
plugin, provider, cli, backup, gui clean; go test -timeout 45m
./internal/plugin ok (120s, after the pinned-update fix),
./internal/provider ./internal/cli ./internal/backup ./internal/gui ok.

Not tried: the full ./... suite; Windows and Linux runs of the tests.
No GUI JS changed: the Plugins page's field goes through the same Add,
and its status still says "<typed name> is installed" rather than the
package picked; the installed list shows the package.
2026-10-25 11:52:02 +08:00
yetone 402577c15a gateway: image generation is an MCP server on the gateway, /mcp/magpie/image
JonahFu on X runs magpie in Docker in gateway mode, so he has no Library and
no stdio Magpie Image server, while image recognition is an HTTP MCP server
on the gateway (/mcp/magpie/vision). Now image generation is one too, with
the stdio server's tools: generate_image, generate_video and
generation_result, drawing with Settings › Images › Image generation.

- image_mcp.go: served by serveMCP, so it is guarded as the vision server
  is (local or a shared magpie's caller, a refused Origin 403, POST only,
  the key's limit reserved per call). A drawing is s.images run in-process
  on a clone of the request (caller and key kept), so routing, key models,
  usage and the timeout setting are draw.go's own. It runs as a job (15
  min at most); the tool answers within 20s or gives an id that
  generation_result waits on. Images come back as MCP image content (5 MB
  each at most) and at /mcp/magpie/image/files/<name>, kept in memory an
  hour, 256 MB at most, readable only by the key that made them. Videos
  go through videosCreate/videosGet in-process and are given as
  /v1/videos/<id>/content. Image generation Off is a tool error naming
  where to turn it on, before the arguments are read.
- Input images go through the vision server's reader, now mcpImageSrc
  (vision_mcp.go), so a file path is read only for a local caller.
- The tool schemas live in the gateway (ImageToolProps, VideoToolProps,
  ResultToolProps); internal/imagemcp takes them and adds only its path
  argument. Its tools/list JSON was compared byte for byte with the old one.
- Settings › Models: #imageMcpRow under #visionMcpRow with the address and
  a copy button; the gateway-mode Image generation sub now points at it.
  en, zh, zh-TW, ja, de.
  The two rows are drawn by one helper (mcpRow), which took the vision
  row's own code, so the row costs 462 bytes of app.js.
- core_budget_test: appScriptBudget 1,321,336 -> 1,321,424 and
  coreScriptBudget 1,528,525 -> 1,528,972, the exact sizes with the row,
  with no room added (10-25). Nothing moved out: the row is Settings'
  own, which the core draws.
- search-api.test.cjs: the new row pushed the search row partly below the
  1400px window at 420px, where scrollIntoViewIfNeeded leaves it, and
  magpie puts back a scroll the reader didn't make, so the test's
  coordinate clicks missed. It now brings the whole row on screen with
  the wheel and checks it is still there a second later. Red with the new
  row before this, green after; green on origin/main's GUI either way.
- oneport_test knows ImageMCPPath and ImageMCPFiles (ClientPath covers
  them).

Run (worktree at this commit, on origin/main 94503901c):
- go test -tags nogui -run 'ImageMCP|VisionMCP|ClientPath|SearchMCP'
  ./internal/gateway/ ok; ./internal/imagemcp ok; the image and vision MCP
  tests with -race -count=3 ok.
- Red on the old code: TestImageMCPDrawsAndServesTheImage (the route is
  404).
- Broken by hand, each red: no route (DrawsAndServes), no key check on
  files (Guarded), no Off check (SaysWhenOff), no reserveFor
  (HeldToKeyLimit), no local-only file read in mcpImageSrc (Guarded).
- GUI, chromium and webkit, every language, at this commit: image-mcp,
  vision-mcp, i18n-keys, images-library-way, search-api,
  settings-sections, gui-de, gui-ja, gui-zh-tw (123/123). Before the
  helper and the rebase: image-mcp, vision-mcp,
  images-library-way, images-codex-one, image-timeout-setting,
  images-missing, i18n-keys, gui-de, gui-ja, gui-zh-tw, settings-sections,
  vision-not-marked (201/201); claude-lean-prompt-setting,
  classify-timeout-setting, disabled-models, member-model-setting,
  loop-guard-setting, refusal-retries-setting, search-first, search-order,
  search-mcp, searcher-pick, side-effort, search-api, search-keys (198/198
  after the search-api fix; search-api alone 8/8 twice).
- gofmt -l clean; go vet darwin, GOOS=linux -tags nogui, GOOS=windows ok.
- Full suite (go test -tags nogui -timeout 45m ./...): the run before the
  helper was red only in TestCoreScriptBudget, fixed above; a run at this
  commit was started and not finished at push (pushed at once, the
  owner's rule), its result goes on the push report.
- Real: magpie serve (nogui) in a sandbox HOME on 127.0.0.1:3592, its
  Image generation a provider pointed at the live gateway's
  codex/gpt-image-2.5. curl: initialize (Magpie Image), tools/list (the
  three tools), Origin https://evil.example 403, GET 405, an unknown file
  404, GET /v1 lists /mcp/magpie/image, Off answers the Off text for both
  tools. generate_image reached Codex through the live gateway and came
  back as the tool error "yetoneful@gmail.com's sign-in has expired".

Not tried: a real image drawn end to end (the only drawing account's
sign-in has expired; image content and file URLs are covered by fake
upstreams), a real video, a call from another computer with a gateway key
(the remote and key paths are covered by TestImageMCPGuarded), Docker.
2026-10-25 06:42:03 +08:00
yetone e3491e2bb0 docs: point dsh's own DeepSeek row at magpie by hand (#3298)
tom047784 (Discord) wants dsh's llm-deepseek row, which keeps DeepSeek's
cache across in-history prompt and tool updates and uploads images
through the Files API, to go through magpie. magpie doesn't take that
row over (the key would mean two things, it would override the user's
own entry, and a file_id belongs to one account while magpie fails
over), so this documents the entry a user writes themselves:
docs/reference.md under "Notes on some agents", and a FAQ entry in
site/public/docs start.html (en, zh, ja).

Checked against @deepseek-ai/dsh-llm-deepseek 0.2.1-rc.2's source
(npm pack into a scratchpad, read only): messagesApiRoot adds /v1 to
baseURL unless it ends in /v1; apiKeyEnv is a credential reference read
from dsh's credentials and then the environment; an explicit models list
replaces DEFAULT_MODELS, whose in-history/addition-only settings are on
deepseek-flash only; any Files failure rebuilds the request inline,
bounded by maxInlineRequestImageBytes (20 MiB) against
maxRequestFilesBytes (128 MiB). Against magpie: internal/agent/dsh.go
drops only magpie-marked llm-deepseek entries and removes
MAGPIE_GATEWAY_KEY on Disconnect; POST /v1/files answers 404; the
catalog ids are deepseek/deepseek-flash and deepseek/deepseek-v4-pro.

Tried: real dsh 0.2.1-rc.2, `dsh --profile headless`, sandbox DSH_HOME
and HOME, a magpie built from this tree on its own port. Through a fake
Anthropic upstream: "say pong" answered; the upstream got
output_config.effort, thinking, tools, dsh_session_log and
dsh_plugin_packages as sent, the provider's key, and no
x-deepseek-harness-* header. A mid-history system message with
tool_addition and the mid-conversation-tool-changes anthropic-beta went
through unchanged (curl). With a real DeepSeek key copied into the
sandbox: dsh read a file with a tool, three calls all 200, cache_read
5760 on a later call; a system message added in the history after two
turns was followed and cache_read_input_tokens was 3456. Usage rows had
agent dsh, /v1/messages and dsh's session; x-deepseek-harness-compact: 1
recorded kind compact.

Not tried: an image turn through dsh (the inline fallback is from the
source and the 404), the desktop app and its Models-page key entry,
Windows.
2026-10-25 05:50:34 +08:00