90bf96a23d74a8d9804fba8eb3ee28fa7ee374b0
294
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
90bf96a23d |
search: a plugin can give a web search API (its search hook)
treeman on Discord #help asked for web search to be pluggable so users can
add search vendors. A plugin's `search` hook, {search: {<id>: {name, keysURL?,
keyOptional?, url?, execute({query, count, key, url}, ctx)}}}, adds an API to
Settings > Models > Web search as `<plugin>:<id>`. It is added, keyed, ordered,
switched off and removed like Tavily or Brave. The built-in APIs stay built in.
How: host.js collects the hook's entries (id [a-z0-9-], an execute) into
Loaded.Searches and runs one with the `search` op (timeout from ctx, an error
with a numeric status comes back as a refusal). The host notes them in
plugin-searches.json (internal/plugin/search.go); provider.AllSearchVendors
adds the noted ones of plugins that are on to SearchVendors, so Ready, check,
the CLI and the GUI list see them. askSearchAPI hands a plugin vendor to
askPluginSearch below askSearchAPIKeys, so keys, rest on 401/402/403/429,
order, the masked query and the request-log row are the built-ins' own.
Run (mote, on this tree, whose base
|
||
|
|
df7c94bdf5 |
gateway: inline image descriptions survive a restart (#5121)
The vision description cache (Server.sights) was in memory only, so a restart, update or handover described every image of a long conversation again (62 calls in 2.5 minutes in the report). Completed descriptions of inline images are now appended to vision-cache.jsonl (0600) in the config dir before their waiters are released, and New restores them under the same 2048-entry LRU. URL images stay in memory (their bytes can change); failures are never written. Appends and compaction go through a file lock, a corrupt or truncated line is skipped (and backed up before compaction), and shutdown waits for pending saves within the drain window. Patch by MYCF711, applied clean on main. One change: the Unix permission test now makes the config folder before it pre-creates the file (it failed on a fresh sandbox, where the folder doesn't exist yet). Run (mote, at this tree): go test ./internal/gateway filtered to the vision/sight/cache tests, ok; gofmt -l clean; go vet ./internal/gateway for linux and windows, clean. Broken by hand: saveSight call removed from see(), TestDescriptionSurvivesGatewayRestart red (2 descriptions, want 1), green again with it back. Windows: the same filtered tests on xiaomi-gpu via win-run. Not tried: full go test ./..., go vet ./... for linux (wails cgo doesn't build off-platform on mote), a real process kill or a real handover, a real gateway with a real vision model. Co-authored-by: MYCF711 <323101370+MYCF711@users.noreply.github.com> |
||
|
|
0e1054ce19 |
statusline: the gateway serves Claude Code's status line to another computer (steven_4422)
steven_4422 (Discord) runs magpie in Docker and Claude Code on the host.
The status line square writes the host's settings.json, which the
container can't reach, with a command naming a binary inside the container.
GET or POST /v1/magpie/statusline answers the line `magpie statusline`
prints, as text/plain, so the host needs only curl:
curl -fsS -m 1 -H 'Authorization: Bearer <key>' --data-binary @- http://<host>:3425/v1/magpie/statusline || true
Claude Code's stdin JSON (session_id) adds the model, as /v1/magpie/route
does; ?session= and ?only= work too. The renderer moved to
provider.StatuslineText, shared by the CLI and the endpoint. A caller that
isn't this computer needs a gateway key (lanGuard, unchanged; the handler
also refuses a non-local caller without one). A read-only key is allowed
(GET and POST in readOnlyRoutes) and gets the windows without the model; a
key held to budget, models or accounts sees only its own (scopeQuotas).
corsGuard and origin checks are untouched.
magpie web shows the command in Settings -> About (en, zh, zh-TW, ja, de).
Docs: reference.md, agent-wiring.md, gateway-routing.md, docker pages en/zh/ja.
Run at this head (rebased on
|
||
|
|
d136d0fe98 |
gateway-key: rotating a key can give it a value of the user's own (isaac_bai)
isaac_bai on Discord: a gateway key's value is random, and only rotate changes it, to another random one; they want to set one easy to pass on. Adding a key could take an own value since 6b6113aa; an existing key couldn't. - access: rotate-key takes Change.Secret. Given, it is checked as an added key's own value (ownSecret: 8-256 printable ASCII, no space, not sk-magpie-, no other key's value; its own current value is allowed); empty, magpie makes one as before. The key keeps its id, name, limits, models and accounts, and Named counts a request from this computer with it as that key. - ownSecret now refuses a value that is one of the user's provider keys (a provider's Key or any of its Keys, constant-time), for add-key too: a client sending it would spend that provider directly. - CLI: `magpie gateway-key rotate <id> --key <value|->`; docs/reference.md. - GUI (plugins/gateway/keys.js, outside the core budget): the Rotate key dialog has a hidden "Your own key (optional)" field; Enter rotates, Escape cancels; an own value says "Gateway key changed. Clients that send this key reach magpie now." Strings in zh, zh-TW, ja, de. Tests: TestRotateToOwnValue (bad values refused, old value still works after a refusal, trimmed own value authenticates as the same key, is Named, listed masked; empty makes a new key; add-key refuses a provider key). TestRotatedOwnValueKeepsTheKeysLimit: after rotating to an own value the old one is 401 from another computer, the own one 200 from another computer and from 127.0.0.1, and a 700-token day limit stops the third request from either (429), every record under the key. gateway-key-own-rotate.test.cjs: chromium and webkit, en/zh/zh-TW/ja/de, 1000 and 400px. Run (mote): at the pushed head: TestCoreScriptBudget ok, ./internal/access ok, the own-key/caller-key gateway tests ok. At |
||
|
|
6c201095d8 |
gateway: in Docker, other containers on the host are shown the host's Docker bridge address
jiezhengj (Discord #feedback) runs magpie in Docker on a NAS at 192.168.31.218. The web UI's host address, http://192.168.31.218:3425, works for other devices. Other containers on the NAS couldn't use it, and not the container's own 172.17.0.x either. What works for them is the host's Docker bridge address, http://172.17.0.1:3425. On Linux, host.docker.internal is there only in a container given extra_hosts. magpie showed no such address. - gateway.ContainerHostURL: in a container on a bridge network, the gateway of /proc/net/route's default route (172.17.0.1 on the default bridge, a compose network's own otherwise), on the gateway's port. It is "" outside a container and on the host's network (`network_mode: host`, told by the host's docker0/br-*/veth*/podman* interfaces). In that case ContainerAddrs is false too, since the addresses are the host's own. - The GUI gets it as /api/providers' gateway.containerHost, /api/settings' lanContainerHost and boot's sideGateway.containerHost. - settings.js lanShown is fed by the new gwLAN(g) for Gateway, Connect, the sidebar and the key page. Each case lists: - Opened at the host: the host's address first, then the bridge address, labelled "Other containers on this host". - At localhost: the bridge address alone, with that label, and a line that the host's own is MAGPIE_PUBLIC_URL's. - No default route: as before. The container's own 172.17.0.x is no longer offered beside them. The sidebar line and the key page prefer an address other machines reach. The scheme comes from the URL, not a hard-coded http. Three new strings are in zh, zh-TW, ja and de. - CLI: `magpie web` and the share banner print "other containers on this host <url>". - docs/reference.md and site docs/docker (en, zh, ja): the log example and a new "Other containers on the same host" paragraph. Run on mote, at this change on |
||
|
|
d1cdce1302 |
provider: the group alone keeps subscription models out of agents' lists (shaoyang.)
shaoyang. on Discord (#general, 11-03): with a routing group's Model lists set to the group alone (its card's 成员模型不单独列出), the model list fetched still had every model of the group. Cause: |
||
|
|
5ee5274bd9 |
quotas: a remote magpie's Codex reset is used from its card here (#3850)
prgrmrwy runs magpie on a home server and uses it from work through a remote magpie (and DSH). The remote Codex card said "1 reset", but the reset could only be used from the GUI of the computer that holds the sign-in. What changed: - Gateway: POST /v1/magpie/quotas/codex-reset?user=<email>[&credit=<id>] (Server.codexReset) spends one of that account's resets with provider.SpendCodexReset. That is the Usage page's own code (UseCodexResetCard, then AwaitAllowance), moved out of internal/gui/usage.go so both use it. A reset can't be undone, so the route needs an enabled gateway key with full access, from loopback too. No key gets 401, and that covers every corsGuard exemption that has no key: Origin null, app schemes, *.localhost and a missing Origin. A read-only key gets 403 gateway_key_read_only (readOnlyGuard, which readOnlyRefused now lists, and again in the handler). A held key gets 403 gateway_key_held, even one told quotas. The account must be named (400 otherwise). One ask runs per account at a time (409). When the reset is used, that card is read again. - Remote client: UseRemoteCodexReset (remote_quotas.go) asks the remote with the provider's key. remoteJSON's status mapping is shared through remoteBody. A read-only key there is told as such, and a 404 as a remote too old. With no answer in time it says the reset may have been used, and it never asks again by itself. A remote Codex card now keeps its Resets; a GLM team's (byWindow) and every check-in are still dropped. - GUI: "Use a reset" / "Use one..." show on a remote Codex card (codexResetCard). They open the same in-app confirmation sheet, with a line saying which computer's magpie uses it, and send the card's provider to /api/usage/codex-reset. The remote's errors are put in the user's words. New strings are in all 5 languages. - DSH: no code here. Its provider plugin reads /v1/magpie/quotas/cards and can call the new route with a full key. - resetOutcome (a reset's result in words) moved from app.js into resetask.js, the only place that says it, so the core's scripts stay in TestCoreScriptBudget's 1,533,802 with no raise (1,533,003 after; origin/main |
||
|
|
69167bc299 |
usage: a reply let go under a second after a wait four times longer tells no speed
pluviophile714 on Discord: a gpt-6.1-sol row on Routing read 1,539 tok/s (input 21,617, output 392, first token 8.2 s, total 8.3 s), where another monitor measures ~70. The reply came whole about 255 ms after an 8.2 s wait. Its content was spread over that short window (flow 230 ms), so the HeldShare flow check passed, and so did the 100 ms floor, and 392/0.255 s read as 1,539 tok/s. New rule, usage.HeldWindowMs: a window under 1,000 ms whose start (first token, first text or first reasoning) is more than HeldShare (4) times the window tells no speed. One rule in every place that computes one: - usage.DecodeOf: the Usage page's speed and totals, the CLI, the GUI's model speeds, and the gateway's Speed first pacing (noteTrySpeed); - routing/client.js decodeOf: the Routing row's speed and its story line; - usage/page.js ledDecode, plus a ledNoSpeed_ reason for the dash's tooltip, in en, zh, zh-TW, ja and de. docs/reference.md and docs/subsystems/gateway-sessions.md say so. On the owner's usage.jsonl (read only), 103 of the 106 rows over 600 tok/s were such windows (e.g. 448 tokens in 107 ms after 8.1 s) and are dropped. The 3 that stay have windows of 2 to 5 s. The overall speed goes from 103.8 to 97.9 tok/s. What it costs: a short reply that really streamed after a long wait tells no speed either. The live visible-reasoning fixture (76 tokens over 731 ms after 6.8 s, ~104 tok/s) and #2637's grok record (307 tokens 403 ms after a 4.6 s first token, 531 tok/s) now read "—". Their tests keep their guarantees with the same timings after a short wait, and also check the long-wait case. Tests: - New: internal/usage TestShortWindowAfterLongWaitTellsNoSpeed (the reporter's numbers, a reasoned row from the ledger, the boundary, a second after a long wait, Totals) and internal/gateway TestShortWindowAfterLongWaitNotesNoPace. - GUI: usage-speed-every-row has the reporter's row (dash, and the tooltip in all five languages); routing-burst-speed has it (first token 8.2 s, no tok/s). - Updated to the new rule: TestVisibleReasoningSpeed's decode-minimum and max-speed cases (short wait now), TestCodexTurnMeasured...'s gateway/Claude rows, TestLiveVisibleReasoningFixture and TestUsageIngestTellsSpeed. Run on mote at this tree (rebased on |
||
|
|
bc10a61985 |
agents: Claude Code's status line, the 5h and 7d use, is a switch on its row (steven_4422)
steven_4422 on Discord asked for the 5h and 7d account use in Claude Code. magpie has had `magpie statusline` since #1997 (kensenzhao), but it was found only in docs/reference.md and needed a hand-written settings.json entry naming a `magpie` the app doesn't put on PATH. Claude Code's row now has a "status line" square beside ultracode (the same toggle, now a table, TOGGLES in app.js), and `magpie claude statusline on|off` in the CLI. On writes settings.json's statusLine as {type: command, command: "<this magpie's full path> statusline"}, quoted for a POSIX shell (Git Bash on Windows, forward slashes). The command reads the gateway's kept windows with a 1s timeout and prints nothing when it can't, as before. - A status line of the user's own is never written over: the square isn't offered while one is there, on is refused, and off and Disconnect leave it byte for byte. Ours is a single plain command whose program is magpie/magpie-* and first argument statusline, so a hand-written one from the reference counts and a compound (&&, |, ;, $(...)) is the user's. - An unreadable settings.json is not written over. - Disconnect takes magpie's status line out with the rest. - Quiet: Claude Code reruns a changed statusLine command in its open sessions, so no restart notice. - Not offered for a WSL distro, and a distro's settings.json isn't read for the options (a stopped one would start, #3896). A stopped distro's fields fall back to magpie's models as options, so without a case in wsl.go its square would have listed models (TestWSLClaudeNoStatusLine). Run on mote (go1.26.8, load ~400): - at f33e6d112 (rebased on |
||
|
|
8819beeb0e |
gateway: a display reads routing as it happens at /v1/magpie/route-events (#3387)
joe21_eee (sywyyhykkk on GitHub) wrote this for an ESP32 screen that shows each agent's requests live: started, each try, the first content, fallback, done. Ported from their route-events branch (42e1fa43f) with the changes below. What a display gets (route_events.go): - GET /v1/magpie/route-events/snapshot: cursor, active, routes (every request the trace has that is still going). - GET /v1/magpie/route-events?after=<cursor> (or Last-Event-ID): SSE, one "route" event a change, id = cursor, from a 512-change ring under trace.mu, so a short request is told step by step. 409 snapshot_required for a cursor not this process's or too old, "event: reset" for a reader that fell behind, a heartbeat every 15s, a 10s write deadline. - A route is routeActivity, an allow list: trace id (base 36), time, agent label, the provider of the seat the last try went to (never the seat id, which names an account or a key fingerprint), model, attempt, fallback, phase, status, failed, ms, ttft_ms. No session, account, key, folder, prompt, reply or error text. - firstToken.onFirst tells the first content as it comes (serve and the ChatGPT backend's reads), written to an unexported Try.firstMs so the full trace's TTFT is unchanged. Changed from the branch: - No new key type. The branch added an "sk-magpie-route-" key, its CLI flag and its own Authenticate path through access, identifyCaller and corsGuard. main has read-only keys now (readOnlyGuard), and the feed is answered as /v1/magpie/usage is: this computer, and another machine with an enabled key while shared; a held key is refused (refuseHeld). Both GETs are in readOnlyRoutes, so the display gets `magpie gateway-key add Screen --read-only`. A full key already reads more than this (every call's usage). access, cli, cors.go and lan.go are untouched. - A route the trace drops unfinished (drop: an unrouted request's stand-in once its own route begins; trim past twice traceKeep) is told request_dropped and marked offFeed. The branch kept its own active map that only "done" cleared, so a stand-in stayed going forever. The snapshot is read from t.routes, no second map. - A stream ends when the gateway stops serving (Server.streamsEnding, closed first thing in ListenAndServe's drain). Before, an open stream held srv.Shutdown for its whole drain, 15 minutes on a handover. - Revocation is access.On(KeyID) (identifyCaller swaps the secret out before handlers see it), asked at most once a second when there are changes and at every heartbeat, and remoteKeyed for a remote reader. A rotated key keeps its id, so its open stream goes on until it reconnects (said in the docs). Docs: gateway-routing.md "Route events for a display" and the read-only key's route list; reference.md beside the usage API. Run at the pushed head on mote (Go 1.26.8): - At daaafeb6e (rebased on |
||
|
|
95d0c97bf9 |
routing: "Use before expiry" counts credits that expire before the reset (lcyksp)
lcyksp on Discord: the 「重置前用完」 strategy (pace) ranked a WorkBuddy
account by its monthly 500 credits ("积分 0 / 500 · 已用 0% · 28 天后重置").
WorkBuddy spends check-in credits first because they expire sooner
("70.85 积分 将于 2026/11/3 09:28:52 过期"), and the account was ranked as
if nothing would be lost for 28 days.
What changed:
- provider.Allowance.Pace takes a budget window's soonest expiry into
account (Limit.RunsOut, from QuotaWindow.RunsOutAt, which the
WorkBuddy plugin and others set on the credits window). When that
expiry comes before the window's reset, the window's pace is the
higher of:
- what is left per hour until the reset;
- the share that expires (QuotaWindow.RunsOut, now carried as
Limit.RunsOutLeft) per hour until it expires. When the amount isn't
told, all that is left counts. A share is capped at 100%, and the
hours at no less than one.
The account whose credits are lost soonest per hour goes first.
Expiry at or after the reset, or already past, changes nothing.
Zero-config: nothing new to set.
- The trace says DueBy "expiry" when the expiry set the deadline. The
Routing page's reason then reads "Use before expiry: {who} has the most
credits expiring per hour until they expire — {n} of its allowance
expires in {d}."
- Label: "Weekly pace" / 重置前用完 / 週ペース / Wochentempo becomes
"Use before expiry" / 到期前用完 (zh, zh-TW) / 期限前に使い切る /
Vor Ablauf aufbrauchen. Product call: the strategy's goal was always
"lose nothing at the deadline". A reset and an expiry are both such a
deadline, and "到期" covers both, where 「重置」 names only one. The id
stays pace, so saved groups are unchanged.
- The descriptions (Routing, Settings, group editor), docs/reference.md,
docs/subsystems/gateway-routing.md and the site's start page (en, zh,
ja) say the same.
Go, run on mote at base
|
||
|
|
5f0a84a003 |
agent: Air in JetBrains IDEs gets magpie's Magpie agent in ~/.jetbrains/acp.json (Jumy on Discord)
Jumy asked for the "air-plugin" new in IntelliJ IDEA 2026.3 (Settings ›
AI › Air). magpie's air agent wrote the Air app's acp.json, in
~/Library/Application Support/JetBrains/Air, which the IDE plugin never
reads: the plugin (com.intellij.air, air-plugin-262.8665.521-mac-arm64
from JetBrains Marketplace) loads its custom ACP agents in
AcpConfigurationLoader (intellij.air.backend.acp.runtime) from
user.home/.jetbrains/acp.json on every system, the file AI Assistant's
custom agents use too; AgentServerConfig takes command, args, env,
use_idea_mcp and use_custom_mcp. The standalone app (Air-262.1037.14,
Fleet-based) reads acp.json from its own configs folder
(genericAcpConfigPath), so the two are separate files.
Air's own agents have no base URL: JetBrains AI, the agent's own login,
or an Anthropic, OpenAI, Gemini or OpenRouter key under AI › Air ›
Accounts. So the IDE gets the same route as the app: a new air-ide agent
("Air (JetBrains IDEs)", aliases air-plugin, air-in-ides) writes a
Magpie entry (opencode acp, OPENCODE_CONFIG naming magpie-opencode.json
beside acp.json) and nothing else; the user's agents and
default_mcp_settings stay, and disconnecting takes out that entry and
that file. air and air-ide share airAt. air-ide shows for an IDE config
folder of 2026.2 or later (the plugin is bundled from 2026.3), or with
its entry already in acp.json. Notice in en, zh, zh-TW, ja, de; README,
reference and agent-wiring rows.
Run at this head (rebased on
|
||
|
|
1aca55909f |
gateway keys: a key given a model is not given a routing group of it the user never handed out (kautism)
kautism on Discord: a gateway key held to gemini 3.8 alone was shown, and could use, a routing group the user made of gemini 3.8 alone, though the user never gave the key that group. groupAllowed let a key use any group whose every member it may use (the #882 rule), so the group leaked into /v1/models and every route that asks it. - key_models.go groupAllowed, the one check every route asks (the model lists' entryAllowed, serve on every API, countHeld, embeddings, images, videos, decision groups, a subagent's and masking's route): a group of the user's own is a key's only when the key names it (group/<id> or group/*). A group magpie found (auto/<model>, one model several providers serve; foundGroup) still passes when the key may use every member, as it is that model. A key that names accounts and no model (Linka, access.HeldModels gives it "<provider>/*") still may use a group of those providers' models alone, as it may every such model: access.Identity.AccountModels says so, for an issued key too. - keyGroupFor: a bare name that is both a group of the user's the key may not use and a model it may use is that model for the key (a group the user called "Gemini 3.8", id gemini-3-8, would otherwise have turned the key's bare gemini-3.8 into a 403). serve's grouped and countHeld use it. - Decision models (v0.1.2681) unchanged: a group the key names still asks its own Jev; TestGatewayKeyHeldToAGroupKeepsItsDecider passes. - A group named inside one the key doesn't name no longer makes the outer one the key's (TestGatewayKeyModelsNameAGroup updated); the key names the outer group to use it. - docs/reference.md and gateway-routing.md say so. TestGatewayKeyGivenAModelIsNotGivenItsGroup is the reporter's case: a key given google/gemini-3.8 alone, a group "Only 3.8" and one "Gemini 3.8" of that model alone. Neither is listed in /v1/models nor found at /v1/models/{id}; each is refused on chat completions, messages and count_tokens, by id and by name; the model is served by id and bare; a found group of two providers' gemini-3.8 is still listed and served to a key given both; a key naming group/only-38 is given it. TestGatewayKeyModelsHoldAKey, TestKeyListSeesChangesNextRequest updated from the old rule. Broken by hand: groupAllowed back to the old rule: the new test, TestGatewayKeyModelsHoldAKey and TestGatewayKeyModelsNameAGroup red. The bare-name fallback off: the new test red (chat gemini-3.8 403). The accounts-only exception off: TestGatewayKeyAccountsOnlyHoldTheModels red. Run on mote at this commit (rebased on origin/main |
||
|
|
2b938b170d |
gateway keys: the key editor offers decision models (Jev, Clef) beside the groups
Kautism on Discord: a gateway key held to a few routing groups couldn't use Clef or Jev, and they showed nowhere for it. A decision model is a model: /v1/systemone and the decision list another magpie asks for (DecidersHeader) hold a key to it as to any model, which stays so (the restriction covers both routes). But GET /api/caller-keys/models listed only provider.Catalog, which has no decision models, so the only way to let a held key ask one was All models. - caller_keys.go: the picker's list now has OfferedDeciders, each after its provider's chat models, marked decides. - keys.js: such a model's note says it is a decision model that a routing group asks whatever the key may use, and that picking it lets the key ask it itself; en, zh, zh-TW, ja, de. - A group the key names still asks its own Jev for every turn with no key check (askJev); TestGatewayKeyHeldToAGroupKeepsItsDecider holds that, and that the key is refused Jev at /v1/systemone and not listed it until it names it, then allowed and listed. - docs/reference.md and gateway-routing.md say so. Run on mote at the pre-rebase head; at the pushed head (rebased on |
||
|
|
066ece93bb |
provider: LongCat is a vendor preset, Meituan's LongCat API platform with chat completions, Responses and Anthropic messages (hoobnn on Discord)
LongCat makes its own models (LongCat-2.5, launched 11-02) and serves them
at api.longcat.chat. magpie had LongCat's icon but no preset for it.
The new preset is longcat ("LongCat", KindVendor, icon longcat, catalog
models.dev's longcat). It uses:
- chat completions and Responses at https://api.longcat.chat/openai/v1;
- Anthropic messages at https://api.longcat.chat/anthropic;
- docs at longcat.chat/platform/docs/zh/api-docs, keys at
longcat.chat/platform/api_keys.
The key goes as a Bearer. magpie sends both headers, and the docs ask for
Bearer on both endpoints; x-api-key alone gets "missing_api_key". The model
list is /openai/v1/models. longcat.chat's and longcat.ai's accounts use the
same API host (both sites' api-docs pages name api.longcat.chat).
An entry at those endpoints imports as the preset, for example CC Switch's
Claude Code and Codex entries from LongCat's cc-switch page. OpenCode's
auth.json "longcat" (models.dev's id) maps to the preset too. The README
(en, zh), docs/reference.md and the site's import pages (en, zh, ja, and
import.html, with the icon) list it.
Sources, read 11-02: api-docs, api/models, api/model, api/model-params,
api/chat, api/messages, image-video-understanding, cc-switch, pricing/
longcat-2.5, change-log, faq.
Probed without a key, from this machine: /openai/v1/models and
/anthropic/v1/models answer 401 authentication_error "missing_api_key".
/openai/v1/chat/completions, /openai/v1/responses and
/anthropic/v1/messages with a bad Bearer answer 401 "incorrect api key".
Run at this head (base
|
||
|
|
ad53a23dc8 |
gateway: X-Magpie-Account takes a percent-encoded name (plugins#615)
StockRabbit (magpie-community/plugins#615, Magpie 0.1.2587, Windows): pinning the Fingerprint page to the WorkBuddy account 北冥 failed every sample with "Header 'X-Magpie-Account' has invalid value". A header value is ASCII on the wire and fetch refuses any other, and the gateway matched the header only against the account's user (北冥) or its trace id (workbuddy@北冥/…), so no ASCII form could name that account. pinTo now matches the value as written or percent-decoded (pinnedName: url.PathUnescape, kept only when it decodes to valid UTF-8). The trace's Pinned, the call's error and the 404's "no account %q" name it decoded. gateway.go:2701 is the one place that reads the value; codex_backend.go, codex_relay.go and gateway.go:2523 test only that it is present, so they need nothing. docs/reference.md and the gateway-routing page say how to send such a name. Run at this head (rebased on |
||
|
|
611ce90d15 |
agent: OpenBot, magpie's models in its model picker (jiezhengj)
OpenBot (nightly-labs/openbot, openbot.run, v0.58.0) is a new row on the
Agents page. jiezhengj on Discord asked for it: today they type magpie's
address into OpenBot by hand and add each model one at a time.
OpenBot lists the user's own OpenAI-compatible endpoints from
openbot-custom-providers-v1.json in its userData folder:
~/Library/Application Support/OpenBot, %APPDATA%\OpenBot, or
~/.config/OpenBot. Connecting adds an entry with id "magpie" pointing at
the gateway's /v1 and holding the models picked for OpenBot, with
secret null. OpenBot seals an entry's key in safeStorage, which magpie
doesn't open, so the entry has no key. OpenBot hands it to OpenCode
keyless, and the gateway accepts it as a request from this computer.
What the entry keeps to:
- OpenBot's decoders drop the whole list over one bad entry. So the entry
has at most 64 models, only ids OpenBot accepts as magpie/<id>, and a
context window only inside 1,024 to 100,000,000.
- The user's other entries stay. The name, harness and secret they give
magpie's entry in OpenBot stay too.
- A sync with nothing to change doesn't write.
- A file whose version isn't the number 1, or whose providers isn't a
list, is one OpenBot refuses itself, so magpie leaves it alone.
- Disconnect takes out magpie's entry, and the file too when only the
version and an empty list are left.
OpenBot reads the file at start, so while it runs, a notice says to
restart it. The notice is in every language.
OpenBot is detected by its userData folder, OpenBot.app
(app.openbot.desktop), or OpenBot.exe under %LOCALAPPDATA%\Programs or
%ProgramFiles%. Docs updated: agent-wiring.md, reference.md, and both
READMEs.
Run at the pushed head, on mote:
- gofmt -l: clean.
- go vet -tags nogui for internal/agent and internal/gui, and for ./...
with GOOS=linux and GOOS=windows: ok.
- go test -tags nogui -count=1 -timeout 45m on internal/agent and every
package that imports it (., backup, cli, davsync, gui, library,
profile, stats, tui, uninstall, plugins/...): ok.
- GUI: agent-notice-lang, i18n-keys, header-relang and about-notices in
Chromium and WebKit: 58 of 58 pass.
After rebasing on
|
||
|
|
2503520f82 |
codexcat: each Codex model takes official Codex's own instructions for it (#3759, #4008, #4783)
Every magpie model in Codex's catalog (model_catalog_json) carried
gpt-5.2-codex_prompt.md ("You are Codex, based on GPT-5"), so a magpie
GPT-6 model, the auto group's included, ran on a GPT-5.2-era prompt while
official Codex sends GPT-6's own template. magpie still writes no words of
its own into the prompt and leaves the identity line alone: each entry now
takes the text official Codex sends that model, word for word.
- A model's slug (the id's last segment) is matched as Codex 0.166
matches one (longest prefix of an official slug): first in the entries
the user's ChatGPT account handed this Codex (models_cache.json), whose
base_instructions and model_messages go over as sent; then in Codex
rust-v0.166.0's bundled models.json (instructions_template only, as an
older Codex may not read 0.166's model_messages), embedded as
codex_instructions.json.
- Any other model, and a routing group, takes Codex's prompt for a model
it doesn't know (models-manager/prompt.md, model_info_from_slug), which
replaces codex_prompt.md: that is what official Codex sends it.
- ownEntry with no base_instructions, and internal/provider's
codexInstructions fallback, take the same official text.
- testdata holds Codex's models.json and prompt.md at rust-v0.166.0;
TestBundledIsCodexOwn fails when the embedded copies drift from them.
- GET /v1/codex/models (a remote Codex's model_catalog_url): entries are
now ~21 KB, so Codex before 0.166's 1 MiB cap holds about 48 of them
(was ~125). Codex 0.166 reads the catalog whole (models_endpoint.rs
passes no body limit), and it sends ?client_version=, so the cap now
applies only to a Codex below 0.166 or one that doesn't say
(codexReadsWholeCatalog). docs/reference.md says so.
- docs/subsystems/agent-wiring.md: a "Codex instructions" row. The
Antigravity cloak's comment no longer calls the GPT-5 prompt magpie's.
Run (mote's disk is full, 100% with other sessions' runs, so on WSL
magpie-desktop through wsl-run):
- go test ./internal/codexcat/: ok. go vet -tags nogui ./... and
GOOS=windows go vet ./...: ok. gofmt -l: clean.
- go test -tags nogui -count=1 -timeout 45m codexcat, provider, agent,
gui, gateway (every package that imports codexcat): codexcat, provider,
gui ok. agent: TestGrokInstalled and TestOmpDetectedWithPiDir red, the
same at origin/main
|
||
|
|
ec104b8625 |
gateway: a Codex account can spend its credits before magpie moves to another account (jojonas_xyz on X)
jojonas_xyz on X: "我账号额度用完了自动给我切了别的号…找不到怎么关掉设置…你怎么知道 我不是想用 credits 呢". (Roughly: "my account ran out of quota and magpie switched me to another account by itself; I can't find a setting to turn that off; how do you know I didn't want to use the credits?") Cause. At 90% or 98% of a window, smart routing's tier put the account behind every account that still had room, whether or not it had ChatGPT credits. Codex's own sign-in (NextLogin / SwitchWhenSpent) moved at the spent share in the same way. The account's credits were spent only once every other account was used up, and the switch was a log line. The Use credits switches that existed (on, and "Only after other accounts" from |
||
|
|
9d08993c8b |
routing: Cheapest first prices Ollama Cloud's DeepSeek models at double from 12:00 to 18:00 UTC on weekdays (hayden4608)
hayden4608 on Discord asked that time-of-day routing use the gap between peak and off-peak prices, citing https://ollama.com/pricing. That page (read live on 11-01) gives Off-Peak rows for two models only, deepseek-v4.1-flash ($0.30/$1.20 peak, $0.15/$0.60 off-peak) and deepseek-v4-pro ($1.32/$3.96 peak, $0.66/$1.98), and says off-peak is "outside 12:00 and 18:00 UTC on weekdays and all day on weekends". models.dev's ollama-cloud catalog lists the off-peak prices, so magpie priced Ollama Cloud's peak hours at half. - catalog: a new Peak kind, PeakOllama. Its hours are 12:00 to 18:00 UTC, Monday to Friday, with no holidays. PeakFactor (2) matches the page for both models, cache reads included. - provider: a peakBill for ollama.com (preset/catalog ollama-cloud) that names the two models. Dated tags (deepseek-v4-pro:1017) count as their model; the bare name before ':' is compared without allocating. Every other model there (glm-5.3, gpt-oss...) and every other vendor stays flat. A local Ollama, a relay that names itself ollama-cloud, and an ollama.com.evil host are not matched. - GUI: a model's price tooltip names Ollama's hours for peak "ollama". The Cheapest first and rate-window texts no longer say that only DeepSeek's hours count, in en, zh, zh-TW, ja and de. - docs/reference.md, site docs (en, zh, ja) and the gateway-routing and providers-accounts subsystem pages say the same. Run (on mote through mote-run, at this tree rebased on |
||
|
|
5dfbca6274 |
cli: magpie settings list|get|set|reset, through the window's own save (#4745)
Stage 1 of #4745 (StringKe): every setting POST /api/settings saves can be read and set from the terminal. - internal/settingsapi holds the save the handler made: Merge (the carry of keys a page leaves out, moved verbatim from api.go, plus upstream's RouterNote line), the vision/imageGen/searcher checks, settings.Save's own checks, catalog.Touched. POST /api/settings and `magpie settings` both call settingsapi.Apply, so a value is checked and saved one way. It sits outside internal/gui so the nogui build has it. - `magpie settings` (list, the default, with value, default and choices; get; set; reset to settings.Defaults()), --json on list and get. Body sends the whole file with one key changed, so a key the save keeps when absent (noBird, refusalRetries, ...) is set even to off. A flag where a key or value goes, an unknown key (with near matches named) or a refused value writes nothing and exits 1; --help prints usage. - Parity guards: TestKeysAreWhatTheSaveWrites (each Settings field sent changed on its own; what the save takes must equal Keys), TestSettingsCLISetsWhatTheWindowSaves (every key the page's prefsKeep and savePrefs send is a key), TestEveryRouteHasACommandOrIsNamed (each /api route has a command or a reason in notYet, which later stages shrink; 36 have one now). - Item 3 of the stage (per-provider CLI-only fields in the window) is left for stage 2. - The open app's in-process follow-ups (fonts, Dock, tray menu, alerts, language, update re-check) run only from the window's save: #4752. Run (mote, at the pushed head |
||
|
|
994cd4fb68 |
gui: Rex switches to the tab magpie opens, through the app's session.select (#4565, StringKe)
StringKe tried v0.1.2446 on the real Rex app (Rex Beta 0.1.0 (1696)):
the tab opens, but the app keeps showing the tab the user was on. The
new tab shows only in the sidebar, and `open -b` only brings the window
forward. The app's own session.select action, sent to the app client,
does switch to it.
After `rex run` (reused magpie session) or `rex new` (now with --json,
for session_id and initial_windows[0].window_id), openInRex brings Rex
forward and then calls rexSelect. rexSelect reads `rex client list
--json`, takes the client of info.kind "app" whose session_ids hold the
session, else the last app connected, and skips one whose
connection_state is "lost". Then it runs `rex -C <client_id> do
session.select session_id=<id> window_id=<window>`. App actions need
Remote Control on in Rex's settings. With no app, a failed list, a
refused do or no answer within 3s (rexSelectWait), the open still
succeeds, the same way a failed rename is ignored. docs/reference.md's
Rex paragraph says this.
Command shapes come from the real rex CLI, snapshot 0.0.1793420730-
g6d0d9a, on mote with a sandbox HOME and XDG_RUNTIME_DIR: `rex --help`
(-C is a global flag, label or ID), `rex do --help`, `rex client ls
--help`, `rex api describe client.list` (client_id, info.kind
app|cli|agent|other, connection_state connected|lost, session_ids),
`rex new --json` output. With no app connected, `do` without -C exits 3
("no app client is connected"), and -C <unknown> exits 3. A client that
doesn't answer keeps `do` waiting 10s ("did not answer within 10s").
That is why the select runs after open -b and has its own 3s bound.
Tests: TestOpenInRexSelectsTheTab runs a fake rex program (a sh script,
so arguments go through a real exec), with a new session and with
magpie's session reused. It checks that the app attached to the session
is picked over another, that a lost app is never asked, and that no
app, a failing client list, a refused do (exit 1) or a do that never
answers (exec sleep 30, killed at the bound) leave the open a success
within its time. The in-process fakeRex answers client list (no app)
and new --json. TestOpenInRexReal runs these paths against the real rex
server, with no app client.
Ran, through mote-run, on this tree before the rebase onto
|
||
|
|
f2f75ee4ae |
provider: Volcengine Ark's System One API, in beta, as a decider (axelburks on Discord)
Ark answers System One at https://ark.cn-beijing.volces.com/api/v1/systemone (and /api/v3/systemone) only with the beta header ark-beta-systemone-api: true; without it the reply is a bare 404. The new volcengine-decision preset asks it with an Ark API key, and magpie sets the header (DecideHeaders) on Ark's own host only, ark.<region>.volces.com, in both the gateway's /v1/systemone and the provider's Test. Its decision model, doubao-seed-2-1-lite-260915 (ArkDecision), is kept apart from Ark's chat list as Bailian's is (vendorDecision), since no /models names it. Learnt from the real API on 11-01 with the owner's Ark key (read from magpie's config, never printed): only doubao-seed-2-1-lite-260915 answers; doubao-seed-2-1-pro-260628, doubao-seed-2-0-lite-260428 and deepseek-v4-1-flash are refused 400 "does not support the SystemOne API". The Coding and Agent Plans' paths (/api/coding/v3, /api/plan/v3, their v1s) answer an empty 404 even with the header, so it bills as pay as you go. An image in the request was left unread (a red square came back 0.48, input tokens as for no image), so images are off. The tests' replies are the real response bytes. Run: - Real: a magpie built from this tree on mote, in a sandbox HOME: `magpie provider add volcengine-decision <key>` and `provider test` (decide ok, 413 ms), then `magpie serve` on a free port and POST /v1/systemone through it: a real 200 with Ark's choice. - gofmt -l internal/: clean. go vet darwin, linux, windows of internal/provider and internal/gateway: ok. - mote-run go test -count=1 -timeout 45m ./internal/provider/ ./internal/gateway/ ./internal/gui/ ./internal/cli/ at base |
||
|
|
e84870f173 |
plugins: an option's words in the window's language, and a filtered model list says so (plugins#590)
anewuser6937 (Discord, plugins#590) saw one model in WorkBuddy's editor
and took the plugin for broken. They had turned on "Free models only"
themselves, but its label and description read in English in the Chinese
window, and nothing by the models said the list was filtered.
A plugin option (auth.options, magpie's own field; OpenCode's AuthHook is
provider/loader/methods and never reads it) may now give `labels`,
`descriptions` and `confirms`, each keyed by the window's language
("zh", "zh-TW", "ja", "de"), beside the plain strings, as a page's
`titles` do. The host keeps only non-empty strings under language names
of 16 or less, 16 languages at most, each capped as the plain one is
(60/300/300). The editor shows the exact language, then its first part
(zh-TW reads zh), else the plain words, in the row, the hint, and the
confirm dialog and its title. `filtersModels: true` says the plugin's
model list leaves models out while the switch is on; while one is on, as
saved, the Models field says under the chips "Only some models are
listed: the plugin option “…” is on." (zh 只列出部分模型:插件选项「…」已开启。,
zh-TW, ja, de too). An older plugin shows what it showed before, and an
older magpie shows a new plugin's plain words with no note.
WorkBuddy 0.2.10 gives "Free models only" in all four languages with
filtersModels (magpie-community/plugins aec58ae, on npm: `npm view
@magpie-community/opencode-workbuddy-auth@0.2.10 --prefer-online` on mote
says 0.2.10, latest), and the mover's min is raised to it so every moved
user gets it. The CLI's `magpie plugin options` stays English, as the CLI is.
The core scripts would have gone 608 bytes over their budget; three of the
provider editor's comments in app.js are cut down instead, no raise
(1,532,865 of 1,533,105).
Run, on mote (mote-run), at this tree:
- node --test plugin-option-words.test.cjs (new): Chromium and WebKit,
1100 and 420 wide, en/zh/zh-TW/ja/de, switch on and off: each
language's label and description, zh-TW falling back to zh and ja/de to
the plain words for a zh-only option, the note exactly once under the
chips in a .hint inside the editor with no sideways scroll, none while
off, the confirm in the language. With app.js put back: 19 of 21 red
in Chromium (only "en off" passes, both widths).
- With plugin-options.test.cjs and i18n-keys.test.cjs, both engines:
68 pass, 0 fail.
- go test ./internal/plugin ./internal/provider ./internal/cli: ok.
TestPluginOptions with host.js put back: red (empty maps, FiltersModels
false). The real WorkBuddy 0.2.10 index.mjs loaded into this host
(a temporary test, not kept): plugin.Providers lists free_only for
workbuddy and workbuddy-ai with all four languages and filtersModels true.
- go test ./internal/gui: TestCoreScriptBudget ok after the cut. Red,
and red the same at origin/main
|
||
|
|
2b067434d7 |
provider: a Kimi Code membership's k3.1-pro and k3.1-pro-highspeed are priced at the Kimi API's (#4635)
hlyx1's fix (#4635, branch hlyx1/magpie kimi-code-k31-pro-price), asked to be expedited by matrix0487 on Discord. Kimi Code's plans serve k3.1-pro and k3.1-pro-highspeed, which models.dev's kimi-code-plan-* catalogs list at the membership's $0. Neither id was in kimiCodeAPI, so a membership's call on either was unpriced on Usage. They now map to kimi-k3.1-pro and kimi-k3.1-pro-highspeed, like k3 to kimi-k3, and the Requests list names that model (PricedNameFor). Checked: Kimi Code's own /models answer (internal/catalog/testdata/ kimi-code-cn-models-2026-10-31.json) lists k3.1-pro "K3.1 Pro" and k3.1-pro-highspeed "K3.1 Pro Highspeed". Kimi's pricing page (platform.kimi.ai/docs/pricing/chat, read 2026-11-01) and models.dev's live moonshotai entry both give kimi-k3.1-pro $2 in / $10 out / $0.20 cached / $2 5m write, and kimi-k3.1-pro-highspeed $4 / $20 / $0.20 / $4. The fixture's new entries match models.dev's api.json in id, name, cost and canonical_model_id. The alias stays Kimi Code's (kimiCodePlans): the test's relay catalog now lists a k3.1-pro of its own at $0.50/$1, which keeps that price, and PricedNameFor(relay, k3.1-pro) stays k3.1-pro. Docs: docs/reference.md, docs/subsystems/providers-accounts.md. Run on mote (Go 1.26.8), at this change rebased on |
||
|
|
733fac48fb |
qwenpaw: each model says how its thinking is set, and the editor sets the level (Pkh)
Pkh (Discord, 0.1.2509 on Linux, QwenPaw 2.2.2.post1): QwenPaw's
thinking strength did nothing on magpie's models.
Cause, from QwenPaw 2.2.2.post1's own source:
- providers/provider.py thinking_control() takes a model's
thinking_control, else its thinking_param_style; with neither it is
ThinkingControl() of kind "unknown".
- providers/thinking.py resolve_thinking drops an unknown control to
inherit, so agent.json's thinking_level was never sent.
- magpie wrote neither key in magpie.json's models, so every magpie
model was "unknown".
Change:
- qwenpawModelJSON writes thinking_param_style "effort" and
reasoning_effort_options for a model whose catalog efforts include
levels QwenPaw names (minimal, low, medium, high, xhigh, max), in
QwenPaw's order. "none" is left out: QwenPaw's off sends
enable_thinking / thinking extra_body, which the gateway strips for
some upstreams.
- Both keys are magpie-owned. A model whose efforts go away has them
taken back. A null magpie writes where it never wrote is dropped,
so a user's own config_overrides are kept.
- The QwenPaw agent editor gets an effort field over agent.json's
thinking_level. "" writes inherit. Setting a level drops
thinking_budget, which QwenPaw's validator requires. A budget or
off level the user set is shown and kept.
- Docs: agent-wiring.md and reference.md.
Run:
- gofmt -l: clean.
- go vet darwin, windows, and linux (-tags nogui): clean (mote).
- go test -timeout 45m ./internal/agent/...: ok (mote).
- go test ./internal/gui: 3 reds, also red on origin/main
|
||
|
|
699ddf1524 |
gateway: a Codex account can spend its credits only after every other account, key and fallback (gokoshiki on Discord)
gokoshiki wants a Codex subscription first, then an OpenAI API key, then the subscription's credits. Until now an account at 100% that holds credits either kept its place and spent them there (on) or was held (off). This adds a third way per account, "last": - settings: CodexCreditsLast []string, empty by default, so a setting saved before it keeps its order. provider.CodexCreditsLast, CodexCreditsMode and SetCodexCreditsMode(user, on|last|off); SetCodexCredits(on) still means "in its place" and clears last. - gateway: candidate.creditsLast is true for such an account once a window for the model is used up and it is going on its credits (a call ChatGPT counts in no window stays in its place). restLast orders ready, then resting, then those, and marks Weighed.CreditsLast. restLast runs over the asides too, so such an account goes behind a provider's reserves (Accounts at once, |
||
|
|
93879515a0 |
agent: QwenPaw, each of its agents' active_model one of magpie's (pkh1585 on Discord)
pkh1585 asked for QwenPaw (AgentScope, github.com/agentscope-ai/QwenPaw)
on Discord. Read in its source, 2.2.2.post1, as data:
- Its folder is QWENPAW_WORKING_DIR, else ~/.copaw when that exists (the
old name), else ~/.qwenpaw; WORKING_DIR/.env is loaded without
overriding the environment. config.json's agents.profiles lists the
agents, each with a workspace_dir whose agent.json holds active_model
{provider_id, model}, read again on each message.
- Providers are no plain config: SECRET_DIR (QWENPAW_SECRET_DIR, else
"<WORKING_DIR>.secret") holds providers/{builtin,custom}/<id>.json,
read once at start. A plain api_key there is encrypted to "ENC:" at
start, so that is the place QwenPaw itself keeps keys.
What magpie does now:
- `magpie qwenpaw <model>` and the GUI: a row per QwenPaw agent
(qwenpaw#<id>, the default one as plain qwenpaw), skipping agents whose
backend is ACP (another CLI runs those) and agents turned off.
- Connecting writes providers/custom/magpie.json (mode 600, the gateway's
/v1 and the magpie-qwenpaw key, magpie's models as extra_models with
their window, output and tool use) and sets that agent's active_model
to {magpie, <provider>/<model>}. The old active_model is stashed as it
was and put back verbatim on disconnect, absent and null included.
The provider file is removed only when no QwenPaw agent still uses it.
- A sync after QwenPaw re-saved the provider (encrypted key, discovered
models, its own defaults) keeps what QwenPaw wrote and changes only
what magpie owns, so a second connect leaves the file as it is.
- The notice says QwenPaw reads providers at start-up: restart it once
after connecting and after magpie's models change. New text in every
locale.
- appdir: QWENPAW_WORKING_DIR and QWENPAW_SECRET_DIR take ~/ as QwenPaw's
expanduser does; agentenv clears them in tests.
- README (en, zh), docs/reference.md, agent-wiring.md, the site's agent
list and start pages (en, zh, ja), icon.
Run:
- internal/agent's QwenPaw tests (Connect, AgentsAreRows, SyncKeeps-
WhatQwenPawChanged, Check, NotStartedYet, Folders, OwnModelAfter-
Magpies, SyncAfterQwenPawSaved, NullModelRestored) on mote, and the
all-agent tests (applied, rewire, lan_kept, proxy_kept, spelled) with
a QwenPaw fixture.
- Broken by hand, each red: always rewriting the key
(SyncKeepsWhatQwenPawChanged), removing the provider while another
agent uses it (AgentsAreRows), no backend filter (AgentsAreRows lists
qwenpaw#coder), dropping the keep of QwenPaw's own fields
(SyncAfterQwenPawSaved), IsObject for Exists (NullModelRestored).
- Real QwenPaw 2.2.2.post1 (Python 3.12 via uv) in a sandbox HOME on
the Linux box (WSL magpie-desktop), magpie on 3741, a fake OpenAI
upstream on 3742: first start wrote config.json and agent.json;
`magpie provider add fake …`, `magpie serve`, `magpie qwenpaw
magpie/fake/echo-1`; after a restart QwenPaw encrypted the key (ENC:)
and `qwenpaw agents chat` answered "PAWPAW-OK from the fake upstream",
its log "built agent … model=magpie/fake/echo-1"; the upstream saw
/v1/chat/completions model echo-1 streamed, magpie's usage.jsonl
agent qwenpaw status 200. A second connect and `magpie models` left
the provider file unchanged. `magpie qwenpaw default` took
active_model back out (the only diff in agent.json) and removed the
provider; QwenPaw started clean after.
- gofmt -l clean; go vet darwin, GOOS=linux and GOOS=windows -tags nogui.
- Full suite on mote (go test -tags nogui -count=1 -timeout 45m ./...)
at 9554883db on
|
||
|
|
e40675cc19 |
middleware: onAccount can pass an account over for a request (bm_rabbit)
bm_rabbit (Discord) is building MOD_Probe, a middleware that tells
Codex accounts apart and needs to keep some requests off some of them.
onProvider could only change a try's body, never which account took
it.
A JS middleware may now export onAccount(account, ctx). The gateway
calls it before each try on a subscription account, at the top of the
candidate loop (accountSkipped). That is before anything of the try is
done: no Codex reset is spent, no body is built, nothing is sent.
account is {ref, provider, name, kind, model}. ref is 32 hex
characters: an HMAC-SHA256 of the middleware's name and the account's
agent, lower-cased user and plan. Its key is random, made once per
install in account-ref.key in magpie's config folder. It is written to
a temp file and linked into place, so it never writes over a key that
is there. The ref is the same on every request and after a restart,
and different for each middleware. The email can't be found from it
without the key. A key file that can't be read is never overwritten:
that process uses a key of its own and logs it.
{skip: true} passes the account over for this request. The next
candidate is asked, as past an account that can't be used. The call's
fallback gets a "passed over by middleware <name>" line, and the
account is not rested or held against. When the last candidate is
passed over, nothing is sent (no fail-open). The agent gets the
failure of a candidate asked before it, or, if there was none, the
usual 404 "none of <model>'s models is ready".
Anything else uses the account: undefined, {}, null, a throw, or going
past the 250ms limit. The last three count as failures. A key's try
asks no onAccount. ctx.account holds the same object for the hooks
after it on that try, and is taken away on a key's try. ownAsk clears
the Accounts runs with the Tried ones.
Note: the plan is part of the ref, so a plan change gives the account
a new ref.
Docs: docs/subsystems/gateway-middleware.md (runtime path step 4,
limits, fail open, verification), docs/reference.md,
docs/integrating.md, and site/public/docs/{,zh/,ja/}plugins.html (an
onAccount row in the hooks table). The Bun plugin host is unchanged:
middleware runs in moejs in the gateway, not in host.js.
Tests:
- internal/middleware TestOnAccount: the ref is stable across runs and
a key reload; it differs between two middlewares, users, plans and
kinds, and is the same when only case differs; no email or plan
reaches the hook. {skip:true} names the middleware; undefined,
{skip:false}, throw and null use the account (2 failures counted);
ctx.account reaches onProvider; a key's try clears it.
- internal/middleware TestAccountRefKey: the key file is made at 0600,
read back, never written over when unreadable, and no temp file is
left behind.
- internal/gateway TestOnAccountSkipMovesToNextAccount: two Codex
accounts, Ordered. The first is passed over, only acct-2 is sent
the request, acct-1 doesn't rest, and the same holds on a second
request.
- internal/gateway TestOnAccountSkipEveryAccount: every account passed
over gives a 404 "…models is ready", nothing is sent, nobody rests.
Broken by hand, each on mote, each red, then restored:
- skip ignored in accountSkipped: both gateway tests red (acct-1
reached; 200 instead of 404)
- fail open on the last candidate: SkipEveryAccount red (200)
- the skipped account rested: both gateway tests red (rests)
- a random key per ref: TestOnAccount (refs changed between requests)
and TestAccountRefKey red
- the middleware name left out of the hash: TestOnAccount red (two
middlewares told one ref)
- an unreadable key overwritten: TestAccountRefKey red
Run at this commit's tree (rebased on origin/main
|
||
|
|
2cfb8351d0 |
install.sh: a Linux desktop without WebKitGTK 4.1 has it installed through sudo, then gets the desktop app (shuhai)
shuhai on Discord, on f68ddca37's hint: "为什么不能帮用户直接装好?" On a
desktop without WebKitGTK 4.1 the installer put in the terminal build and
told the user to `sudo apt install libwebkit2gtk-4.1-0` and run it again.
Now, on a desktop without the libraries (and with --gui), when someone is
at the terminal, the script installs WebKitGTK 4.1 (GTK 3 comes with it)
with the distribution's package manager, says first in one line what and
why, and installs the desktop app:
- apt-get install -y libwebkit2gtk-4.1-0 (Debian/Ubuntu family), and when
that fails, apt-get update and once more (lists missing or stale);
- dnf install -y webkit2gtk4.1 (Fedora/RHEL family);
- pacman -S --needed --noconfirm webkit2gtk-4.1 (Arch family; no -Sy, so
no partial upgrade);
- zypper --non-interactive install libwebkit2gtk-4_1-0 (openSUSE).
Through sudo, which asks for the password itself; as root, without it.
"At the terminal" is /dev/tty opening (in a subshell, since a failed
redirection would end the script): curl | sh gives the script the pipe
for stdin, so every package command reads /dev/tty too, never the script.
No terminal, no sudo, the package manager missing, Void/Gentoo/another
distribution, or the install failing: the terminal build and the command,
as before, with "didn't work (see above)" when it was tried. --tui and
MAGPIE_CLI=1 install no package; a headless computer neither.
MAGPIE_TTY points the check at another file for the tests.
Docs: reference.md Install, README en/zh, docs start (en/zh/ja).
Run:
- sh -n, dash -n; shellcheck -s sh: only SC2010 at the uninstall's
ls | grep, there before.
- site/install.test.mjs, 5 new tests (fake sudo, id and package managers;
every distro's command, root without sudo, no tty, no sudo on PATH,
Void, NixOS, a failing install, apt's update-and-retry, --gui, --tui,
MAGPIE_CLI, headless): red on origin/main's install.sh (the 5 new fail,
19 pass), green after. CI's site step (sh -n + node --test
site/*.test.mjs) at this head, rebased on origin/main: 63/63 on mote
(macOS sh) and 63/63 on magpie-desktop through wsl-run (/bin/sh = dash).
- Real installs in fresh containers (Docker on xiaomi-gpu, amd64), a user
u with sudo, DISPLAY=:0, `cat install.sh | sh` (stdin a pipe), the
terminal kept with setpriv (su -c starts a session without one),
v0.1.2399/2400 from the real feed; then ldd (nothing missing),
`magpie version`, and the package query:
- Debian 12, sudo with a password, typed by expect at sudo's prompt,
package lists deleted first: install failed "Unable to locate", apt-get
update, retry ok, desktop app, libwebkit2gtk-4.1-0 installed;
- Ubuntu 24.04 (NOPASSWD): libwebkit2gtk-4.1-0, desktop app;
- Fedora 44, password via expect: webkit2gtk4.1, desktop app;
- Arch (archlinux:latest): webkit2gtk-4.1 2.54.2, desktop app;
- openSUSE Tumbleweed and Leap 15.6: libwebkit2gtk-4_1-0, desktop app;
- Debian 12 as root: apt-get without sudo, desktop app;
- Ubuntu 24.04 --gui: installed, desktop app; --tui: terminal build,
nothing installed;
- Debian 12 without -t (no terminal): terminal build + the apt line, no
install tried; without sudo at a terminal: the same;
- Ubuntu 20.04 (no WebKitGTK 4.1 in focal): install, update, retry all
fail "Unable to locate", then the terminal build and the "didn't work
(see above)" hint.
Not tried: a real desktop VM (the containers fake one with DISPLAY=:0);
the installed app wasn't opened, only `magpie version`. Void and Gentoo
stay hint-only (Gentoo would build WebKit from source). Debian 11 failed
in the container's own setup (archives unreachable), so focal stood in
for a distribution without 4.1. A held dpkg lock (unattended-upgrades)
would fail the install and fall back; not reproduced. On focal the hint
still names libwebkit2gtk-4.1-0, which focal lacks, as before.
|
||
|
|
7d11f7d428 |
gui: Rex opens sessions in a Rex session of magpie's own, with none, one or several open (#4565, StringKe)
StringKe tried |
||
|
|
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 |
||
|
|
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 |
||
|
|
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
|
||
|
|
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 |
||
|
|
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). |
||
|
|
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. |
||
|
|
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). |
||
|
|
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
|
||
|
|
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. |
||
|
|
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.
|
||
|
|
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 |
||
|
|
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®ion=... 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
|
||
|
|
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 |
||
|
|
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
|
||
|
|
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.
|
||
|
|
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 |
||
|
|
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 |
||
|
|
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.
|
||
|
|
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. |