Gateway middleware and agent plugins run on moejs. alpha.11 moves the
module to github.com/MoeForge/moejs; every other API change since
alpha.4 is an addition. What magpie gets: faster calls, loops, property
lookups and JSON.parse, allocation-free await, a bytecode verifier, a
correct default.pgo, and Intl / toLocaleString in plugin code.
Checked against both tags' source: every name magpie uses (NewRuntime,
Options, Compile, Link, Hook, Value, Arg, Undefined, NativeFunc,
Referrer, the Promise results, Exception) has the same signature, and
Options' defaults (shared frozen builtins, no timers) are unchanged.
fetch, Streams, URL, node:fs and node:buffer live in the separate
webapi and node packages, installed only on request; magpie installs
neither, so a plugin still reaches no network or file.
Intl's CLDR, Unicode, ICU and V8 material is compiled into every build,
and moejs asks a program that includes it to carry sections 1 to 4 of
its notices. THIRD_PARTY_NOTICES holds them verbatim. Release archives
ship no LICENSE today either; that is not changed here.
Doc and site links (docs/, site/public/docs/{,zh/,ja/}plugins.html)
point at the new repo.
Run on mote at this tree: gofmt; go build -trimpath -s -w (60,670,658
bytes on origin/main 58fb3a778, 62,329,250 now, +1.66MB); go vet of
middleware, jsmod, agentplug for darwin, linux and windows; go test
./internal/middleware/... ./internal/jsmod/... ./internal/agentplug/...
ok; go test -run 'Middleware|Strateg|OnUsage|JSPlugin|Agentplug|AgentPlug'
./internal/gateway ./internal/provider ./internal/plugin ./internal/gui
ok.
Not run: the full suite, the GUI suite, a real request through a
middleware in a running gateway.
AstrLink Guard (QuantumNous/astrlink-guard, Apache-2.0, on Microsoft's
MIT Multilingual-MiniLM-L12-H384) is a 36.9M-parameter BERT token
classifier for Chinese and English: 21 BIO labels (email, phone,
account, payment_card, ip_address, url, common_secret, private_address,
private_date, private_person), 512-token windows overlapping by 128,
a 0.8 score floor. Its int8 ONNX is 37 MB.
This package runs it with no new dependency and nothing native: an ONNX
protobuf reader for the graph and its external data (onnx.go), the
XLM-R Unigram tokenizer from tokenizer.json (tokenizer.go), and the
encoder with int8 x int8 matmuls (bert.go) on NEON/SDOT kernels on
arm64, SSE2 on amd64 and Go elsewhere (kernel*). Word embeddings stay
quantized (15 MB in memory, not 61 MB). uax29 moves from an indirect to
a direct requirement for the tokenizer's pre-split.
Checked against onnxruntime on the publisher's files: the same spans
on 69 of 71 eval texts, 232 of 234 real code segments and 24 of 25
positive samples; the rest differ by a span edge at the score floor.
One 512-token window takes ~0.5s CPU on arm64 and ~1.2s under Rosetta
on amd64, on a box at load ~100.
Run: go test ./internal/pii/guard (kernels against the Go reference,
tokenizer against the publisher's tokenizer on testdata/tokens.json),
gofmt -l, go vet, GOOS=linux go vet -tags nogui and GOOS=windows go
vet on amd64 and arm64, at the pushed head.
A webview keeps every picture on the page decoded at its own size. The
Plugins page draws 152 icons at 20 to 64 points, and some stored icons
are 1254x1254, so opening Plugins alone added ~122 MiB to the renderer.
GET /api/icons/{name} now sends a PNG, JPEG or WebP longer than 256px
as a PNG copy scaled to 256 on its longest side (CatmullRom), made on
its first ask under the cache dir (icons-small) through temp-and-rename
and kept. SVGs, small pictures, pictures over 64M pixels and anything
that fails to decode are sent as they are. pruneIcons drops a copy
whose original is gone. golang.org/x/image goes from indirect v0.41.0
to direct v0.43.0 (needs only x/text v0.38, nothing else bumped).
Measured in Chromium (WebView2's engine) on a dev backend with a copy
of the real library and its 111 stored icons (6.2 MB):
- renderer RSS after opening Plugins: 369 -> 304 MiB
- renderer after visiting every page, on Settings: 310 -> 290 MiB
- decoded image area on Plugins: 18.5 -> 6.5 megapixels
- 15 scaled copies made, 596 KB in all
What is left on Plugins is SVGs, which rasterise at draw size.
Run at this head (before rebase onto 634cbf587, which touches only
internal/agent):
- go test ./internal/provider -count=1 -timeout 45m
-skip '^TestUnreadLoginsWriteErrorsKeepCredentials$' (#3632): ok 95s
- go test ./internal/gui -count=1 -run 'Icon|Plugin': ok
- GOOS=linux and GOOS=windows go vet -tags nogui on both packages: ok
- gofmt -l internal/: clean
Broken by hand: with scaling turned off in scaledIcon,
TestBigIconServedScaled goes red ("want a scaled copy").
Not tried: WebView2 itself on Windows, and WebKitGTK.
An idle magpie still woke a dozen times on each 5s beat: the loops that
follow plugins.yml, settings.json, providers.json, the plugin list, tools
and access each looked at the disk for what the CLI or a second magpie
wrote. The gateway now watches those files' folders (fsnotify: FSEvents,
inotify, ReadDirectoryChangesW), and a change from another process wakes
the same loops at once, as magpie's own writes do (filememo.Written).
With the watch running the loops look for a change they missed only once
a minute (OthersEvery); where the folders can't be watched, or the watch
errs, they go on looking every 5s.
Run at 466cafa0c + this change. The rebase onto 13f9c7fca brought in
internal/gateway's claude bridge and redact files, none of the files here;
after it, go build ./... and the filememo, pluginrt, awake tests ran again ok:
- go test -timeout 45m ./internal/filememo ./internal/pluginrt
./internal/middleware ./internal/otlp ./internal/gateway: all ok
(gateway 384s).
- TestWatchWakesOnOthersWrites -count=3 ok; red with wake() taken out.
- gofmt -l clean; GOOS=linux and GOOS=windows go vet -tags nogui on the
changed packages ok.
- Real gateway, sandbox HOME, idle: proc_pid_rusage wakeups over 120s
after a 90s warm-up, two rounds each: v0.1.1561 2.1 / 2.7 per second,
this 1.9 / 2.0 (and 1.8 in a third run).
- Same gateway: plugins.yml replaced from outside with broken YAML; the
gateway logged "plugins: ... doesn't parse" 0.02s after the write
(it could take up to 5s before). File restored after.
Not tried: Linux and Windows real runs (vet only).
brickhao on Discord: long Codex turns through magpie died with "stream
closed before response.completed". Their network (FlClash) cuts a
streamed HTTP reply from chatgpt.com at about 120 s: 120.7 s through
magpie, 121.5 s over HTTP without magpie. Codex's own WebSocket to the
same backend ran to the end twice (124.5 s, 131.4 s). magpie has no
120 s timer of its own (no WriteTimeout, 10 min to the first header).
The cut is on the leg from magpie to chatgpt.com, which was always
HTTP. Codex answers magpie's 426 by falling back to HTTP, and over
loopback that is harmless.
What changed: codexSocket, first in upstreamTransport, sends a POST to
CodexBase/responses with "stream":true over the backend's WebSocket, as
codex-rs does (ResponseCreateWsRequest, build_websocket_headers).
- Handshake: the turn's headers plus OpenAI-Beta:
responses_websockets=2026-02-06. x-codex-turn-state and the
responses-lite header go in client_metadata instead. The message is
the body (zstd decoded) with "type":"response.create" ahead of it.
- Frames come back as the SSE the HTTP route sends.
codex.rate_limits and codex.response.metadata are also given as the
x-codex-* and x-codex-turn-state headers. websocket_timing is dropped.
- An error frame ahead of the reply becomes its HTTP status and body,
so account rests and failover work as before.
- These go over HTTP: a refused handshake (and the host stays on HTTP
for 10 min, unless the refusal was 401/429/5xx),
websocket_connection_limit_reached, and a body that isn't a streamed
turn.
- A socket closed before the end reads as a cut stream.
- Both Codex's own sign-in passthrough and magpie's ChatGPT accounts
take this path. Codex identity, instructions and prompts are
unchanged. coder/websocket is now a direct dependency (it was
indirect).
Run:
- gofmt -l clean; go vet darwin, GOOS=linux -tags nogui, GOOS=windows ok.
- go test -race -count=3 of the five new tests: ok.
- go test -timeout 45m at 1a5911612 (rebased on origin/main c551a2299),
sandbox HOME: internal/gateway ok 760.9s, internal/agent ok 596.8s,
internal/provider ok 172.5s. The rest of ./... was not run before the push.
- Real: a sandbox magpie (this tree, 127.0.0.1:3488, sandbox HOME and
CODEX_HOME, a copy of the Codex access token with the refresh token
blanked so nothing could rotate). A curl turn on gpt-6-luna came back
200 with codex.rate_limits in the SSE (which only the socket sends)
and the x-codex-* headers. Real Codex CLI 0.162.1 (codex exec,
xhigh) through it: a 6121-word reply over 165 s ended whole, exit 0.
Codex logged its own 426 from magpie and fell back, as expected.
Broken by hand:
- socket off in the tests: all four socket tests red (the reply cut
before response.completed, no handshake, 200 not 429).
- error-frame mapping off: TestCodexSocketErrorIsItsStatus red.
- turn-state into client_metadata off: TestCodexTurnGoesOverWebSocket
red.
Not tried:
- brickhao's network: this network doesn't cut at 120 s, so the 165 s
turn shows the socket carries a long turn whole, not that it gets
past their cut.
- A real turn on a magpie-saved ChatGPT account (fake only).
- Through an HTTP or SOCKS proxy for real.
- Windows/Linux runs.
A magpie started from Alfred under the MacSec DLP tool quit about two
seconds after launch, exit 1, no crash report. Its environment held an
entry with no "=" ("hains/MacSec/libesafenet.dylib", a fragment of the
tool's injected dylib path). The first SQLite open (a session scan)
reads SQLITE_TMPDIR through modernc's libc, whose getenv on darwin,
windows and the BSDs (libc.go, not the musl build Linux uses) hits that
entry, calls todo() and os.Exit(1): "libc.go:1816:getenv: TODOTODO
"SQLITE_TMPDIR" "hains/MacSec/libesafenet.dylib"", the reporter's line.
New package internal/sqlitedb is the one importer of modernc.org/sqlite
in magpie's own code (it replaces the blank imports in
internal/provider/importapps.go and internal/agent/cindy.go, the only
two). Its init hands libc.SetEnviron a copy of os.Environ with the
entries that have no "=" left out, before any open and before any
goroutine, which also keeps libc's unlocked first-use SetEnviron from
racing. modernc.org/libc becomes a direct requirement (v1.67.6, same
version). Snapshot timing: libc's copy is now taken at init, not at the
first open; nothing in magpie sets SQLITE_TMPDIR, TMPDIR or TZ, the
only variables SQLite reads.
Run (worktree at origin/main 01c41e8ba, sandbox HOME, go1.26.8 darwin):
- internal/sqlitedb: TestSQLiteSurvivesMalformedEnv starts the test
binary again with the reporter's entry first in a raw Env and opens
and reads a database there; TestWellFormed; and
TestOnlyThisPackageReachesSQLite (no non-test file outside
internal/sqlitedb imports modernc.org/sqlite or modernc.org/libc).
- Broken by hand: with init's SetEnviron call removed,
TestSQLiteSurvivesMalformedEnv goes red with the child's exit 1 and
the reporter's exact TODOTODO line. With cindy.go importing
modernc.org/sqlite again, the import guard goes red naming it.
- go test -p 1 -count=1 -tags nogui ./internal/sqlitedb ./internal/agent
./internal/provider ./internal/sessions ./internal/proc: all ok.
- gofmt -l: clean. go vet -tags nogui on the three packages for
GOOS=darwin, linux, windows: clean. go mod verify: ok.
- Real binary: go build -tags nogui, then execve'd (python ctypes, raw
envp) as `magpie sessions` with the reporter's entry and a sandbox
HOME holding an opencode.db: exit 0, it listed. The hand-broken
binary for comparison couldn't be linked (disk full), so that run
shows only that the fixed binary survives, not that this command
reached SQLite; the test above is what goes red on the old code.
- Not tried: the reporter's Alfred + MacSec machine, Windows.
- Linux getenv (musl-based) already skips such entries; the test passes
there either way.
Full suite: SUITE_LINE
An agent that mounted magpie's web search over MCP (Cursor, Claude Desktop)
found pages it couldn't open: it has no fetch tool of its own. web_fetch
(url, max_chars, offset) reads one.
- The URL is the agent's, so the page is downloaded the way a caller's
image is (publicClient): public addresses only, every resolved address
checked and pinned, redirects (at most 5) checked the same, a request
from this computer included; only http and https. 30 s and 5 MiB at most.
- HTML is decoded from its charset (x/net/html/charset; golang.org/x/net
added) and given as Markdown: title, headings, lists, links made
absolute, code and pre; script, style, hidden elements dropped. Other
text as it is; anything else, or a 4xx/5xx, is the tool's error.
- 20000 characters by default (at most 100000) from offset, with the
offset the rest starts at.
- Each call reserves the gateway key's limit, as a search does.
- The tool description is neutral (names neither magpie nor a vendor).
- GUI: the MCP row's text names both tools (en, zh, zh-TW, ja, de).
Docs: gateway-routing's MCP section, README (en, zh-CN).
Run: go test -tags nogui ./internal/gateway -run 'WebFetch|SearchMCP';
GOOS=linux/windows go vet ./internal/gateway; gofmt -l clean. GUI:
search-mcp, i18n-keys, gui-ja, gui-de, gui-zh-tw 32/32 (chromium +
webkit). Broken by hand: webFetchClient = http.DefaultClient turns
TestWebFetchOnlyPublic red (the local test server was reached).
Tried by hand (a throwaway test, not committed) against go.dev/doc,
en.wikipedia.org/wiki/Magpie and http://github.com/yetone (redirected to
https; links come out by name, not the pinned address: the first try gave
https://216.239.34.21:443/..., fixed by taking each redirect's URL from
CheckRedirect), and an httpbin redirect to 127.0.0.1, refused.
Full suite: SUITE_LINE
macOS race CI failed now and then with "write |1: file already closed"
on a Claude subscription run's first prompt
(TestClaudeAuthFailureFallsBackWithoutRetryingTheLogin in 37605014029,
TestClaudeLastWordsAreRead in 37464400652; 37612795871 got the same
failure as "broken pipe"). The Claude Code stand-in had already ended
when the first prompt was written, and Wait had closed its stdin.
It never ran. On the fork's macOS runners, a debug build that recorded
the process's status at the failed write caught 8 cases in 10 jobs.
Each was "signal: segmentation fault", under 1ms of CPU, nothing on
stderr, with no magpie abort or group kill. The crash report
(gateway.race-*.ips) says "crashed on child side of fork pre-exec":
__tsan::TraceSwitchPartImpl
syscall.rawSyscall
syscall.forkAndExecInChild
syscall.forkExec
os.StartProcess
exec.(*Cmd).Start
proc.StartTree
gateway.(*subscriptionRun).launch
This is golang/go#79804. From Go 1.26.0, darwin's raw syscall wrappers
are instrumented under -race, and forkAndExecInChild calls them in the
child of fork. Go 1.26.5 marks them //go:norace (#79806); go.mod's
1.26.3, which setup-go builds CI with, has the bug. Only -race test
binaries on macOS are affected, so released builds never were. Any
os/exec start in a macOS race test could hit it; the Claude
subscription tests were where it surfaced. Local runs on go1.27.1
couldn't reproduce it, because that release already has the fix.
1.26.8 is the latest 1.26 patch release.
A vendor or relay can hand out a ready-made provider as a link. The app
registers the magpie scheme (Info.plist on macOS, HKCU on Windows, a
.desktop handler on Linux), a second launch hands the link to the running
one, and the window shows what the link would add, with the hosts the
prompts and key would go to, before anything is saved. `magpie import`
does the same in a terminal.
The product, module path (github.com/yetone/magpie), binaries, env vars
(MAGPIE_ADDR, MAGPIE_DEV_UI, MAGPIE_THEME, MAGPIE_DEBUG), config and cache
folders (~/.config/magpie, ~/.cache/magpie), bundle id (com.yetone.magpie),
gateway provider id and token, and every UI string now say magpie.
On first run magpie copies ~/.config/dial and ~/.cache/dial to the new
folders when they don't exist yet (copy, not move, so a still-running dial
keeps working; the old folders can be deleted by hand later).
The logo is a small round magpie in profile: one path for the header and
the tray, and the app tile adds the white belly and the blue-green tail.
The header mark is drawn in ink rather than the accent colour, which
fought the text in light mode.
Wails v3 tray panel and window, TUI and CLI. Switches model, effort and
provider for Claude Code, Codex, Gemini CLI, OpenCode, Pi, Goose, Cursor,
Copilot CLI and Crush with format-preserving config edits. Providers page
and registry, stored keys, live vendor model lists, profiles.
Co-Authored-By: Claude <noreply@anthropic.com>