Commit Graph
7089 Commits
Author SHA1 Message Date
ggbdpq cd0875f5a0 provider: a Claude sign-in whose keychain write fails leaves logins.json alone (#4563)
addLogin wrote logins.json before the credential was stored, and a
keychain write that failed (the login keychain out of reach over ssh)
left the account kept all the same: importing the same file again
reported it as already there. The credential is stored first now; the
login is written only once it is in.

Reviewed and applied from #4563 (ggbdpq, 7b42e98a1, SHA-256 matches).
The test runs in signIn's sandbox HOME with a fake `security` first on
PATH that exits 51. proc.Command looks PATH up at call time, so the real
Keychain is never reached. Switching to a saved login still writes its
On marks before the credential: #4592.

Broken by hand: signin.go back at main with the test kept, and
TestClaudeLoginKeychainWriteFailureKeepsLoginsFile fails.

Run (on mote, through mote-run):
- Full `go test -tags nogui -count=1 -timeout 45m ./...` with this stack
  on c30d3b7b6: 82 packages ok. internal/gui was red only on
  TestSettingsSaveKeepsWhatItDoesNotSend (#4514, SearchAll from
  b09349d17) and TestColdTurnsTaken (#4510). Both are filed, and neither
  touches this stack.
- Rebased onto 29d0ab39f, which changed internal/gateway since then:
  gofmt -l, go vet (darwin, GOOS=linux -tags nogui, GOOS=windows) and
  go test -count=1 ./internal/gateway ./internal/usage ./internal/provider
  ./internal/sessions all ok at the pushed head. go build ./... ok for
  darwin, linux (nogui) and windows.
- go test -race of the gateway tests this stack adds or touches, on
  the stack at fb29cd30f: ok.
2026-10-31 23:35:27 +08:00
ggbdpq d1b62f4604 usage: price a local session's call at the provider its file names
What changed

A call read from an agent's own session file (omp's model_usage, say) has
no billing provider of ours — its row reads session-unknown — so Pricer
priced it only through the maker lookups, which answer nothing for models
no vendor catalog lists as its own, even when the models.dev catalog
lists the model under the provider the file recorded (openrouter listing
typesafe/jev-1.14 at $0.042/M in, #4278). When the effective price is
unknown and the record is one of those, its session provider now prices
the call — but only what the catalog itself affirms: the very model id,
listed under that provider, with a price. A provider models.dev doesn't
know, a model it lists that provider without, and an entry with no price
stay unpriced, the CSV cost empty, rather than priced at another entry's
guess; the pricer's memo is keyed by the session provider too, so two
files naming different routes price apart.

Run

- go test -tags nogui -run 'TestUnknownProviderPricedBySessionProvider' ./internal/usage — red before (the named route stayed unpriced), green after
- go test -tags nogui ./internal/usage/... — ok
- gofmt -l internal/usage — clean

Generated-by: GLM-5.3-FlashX (ZCode)

Reviewed and applied from #4278 (ggbdpq, 645e80ab2). It differs from
the patch hashed on the issue only in its git-version trailer.

The reporter's own call stays unpriced for now. models.dev's default
api.json, which magpie fetches, does not list openrouter
typesafe/jev-1.14; only api.json?type=all does. #4278 stays open for
that. The Sessions page prices a session-unknown call through its own
priceOf, by model only: #4591.

Broken by hand: ledger.go back at main with the test kept, and
TestUnknownProviderPricedBySessionProvider fails.

Run (on mote, through mote-run):
- Full `go test -tags nogui -count=1 -timeout 45m ./...` with this stack
  on c30d3b7b6: 82 packages ok. internal/gui was red only on
  TestSettingsSaveKeepsWhatItDoesNotSend (#4514, SearchAll from
  b09349d17) and TestColdTurnsTaken (#4510). Both are filed, and neither
  touches this stack.
- Rebased onto 29d0ab39f, which changed internal/gateway since then:
  gofmt -l, go vet (darwin, GOOS=linux -tags nogui, GOOS=windows) and
  go test -count=1 ./internal/gateway ./internal/usage ./internal/provider
  ./internal/sessions all ok at the pushed head. go build ./... ok for
  darwin, linux (nogui) and windows.
- go test -race of the gateway tests this stack adds or touches, on
  the stack at fb29cd30f: ok.
2026-10-31 23:35:27 +08:00
yetone c8df9ecbbc gateway: a search round ended without its stop hands on its held text (#4562 review)
textCallRound holds text from where a written call may begin, and gives
it back at KStop. A round whose channel closes without a KStop is one
searchRounds takes as ended, and its held text was lost with it. The
routes without a search give it back at their reply's end
(gateway.go's held(), continuation.go's release), and the round now
does the same after its loop.

The previous commit's doc comment for textCallRound had also been put
between searchReply's comment and its func. searchReply's comment is
back on searchReply.

TestTextCallRoundReleasesHeldAtEnd: a round that sends "Let me look."
and the start of a DSML call, then closes.

Broken by hand: the t.release() taken out. Red: it handed on only
"Let me look.\n\n".

Run (on mote, through mote-run):
- Full `go test -tags nogui -count=1 -timeout 45m ./...` with this stack
  on c30d3b7b6: 82 packages ok. internal/gui was red only on
  TestSettingsSaveKeepsWhatItDoesNotSend (#4514, SearchAll from
  b09349d17) and TestColdTurnsTaken (#4510). Both are filed, and neither
  touches this stack.
- Rebased onto 29d0ab39f, which changed internal/gateway since then:
  gofmt -l, go vet (darwin, GOOS=linux -tags nogui, GOOS=windows) and
  go test -count=1 ./internal/gateway ./internal/usage ./internal/provider
  ./internal/sessions all ok at the pushed head. go build ./... ok for
  darwin, linux (nogui) and windows.
- go test -race of the gateway tests this stack adds or touches, on
  the stack at fb29cd30f: ok.
2026-10-31 23:35:27 +08:00
ggbdpq 90f8a10566 gateway: a search route's reply reads the calls written into its text (#4562)
searchReply's rounds answered a request that carried a hosted web
search — Messages' web_search_20250305, Chat's web_search_options,
Responses' web_search — for a model that can't search by itself, and
never ran the text-call recognizer: a call the model wrote into its
text (#823) reached the client as that text, while every route
without a search made it a call (streamTranslated, forwardTranslated
and the relayed Chat stream each wrap their reply in textCallSee or
textCallTidy). The three routes the reporter lists all pass through
searchReply, so its round is wrapped: textCallRound hands every
round's events through a textCallSee over the client's tools plus
magpie's own, and a call written out — the client's or the search
tool itself — is read as the call it is. A reply that made a call of
its own keeps the text as it came, as elsewhere.

A round with no tools keeps the round it was: textCallNames is nil
and the round passes unwrapped.

Verification on the branch's base 4f00a32ff, macOS arm64:
- RED before the fix, GREEN after: TestTextWrittenCallSearchRouted,
  new, asks a Chat fake that writes its Bash call out in DeepSeek's
  DSML through each of the three routes — Messages, Chat
  (web_search_options), Responses — and asks for the call, the text
  around it kept and the markup gone.
- Ablation: search.go back at 4f00a32ff, test kept, all three
  subtests fail again.

Generated-by: GLM-5.3-FlashX (ZCode)

Reviewed and applied from #4562 (ggbdpq, fff5d6435, SHA-256 matches).
The next commit fixes a held tail lost at a round's end, and moves
searchReply's doc comment back onto it.

Broken by hand: the line "ask = textCallRound(q.Tools, ask)" taken
out with the test kept. TestTextWrittenCallSearchRouted fails on
messages, chat and responses.

Run (on mote, through mote-run):
- Full `go test -tags nogui -count=1 -timeout 45m ./...` with this stack
  on c30d3b7b6: 82 packages ok. internal/gui was red only on
  TestSettingsSaveKeepsWhatItDoesNotSend (#4514, SearchAll from
  b09349d17) and TestColdTurnsTaken (#4510). Both are filed, and neither
  touches this stack.
- Rebased onto 29d0ab39f, which changed internal/gateway since then:
  gofmt -l, go vet (darwin, GOOS=linux -tags nogui, GOOS=windows) and
  go test -count=1 ./internal/gateway ./internal/usage ./internal/provider
  ./internal/sessions all ok at the pushed head. go build ./... ok for
  darwin, linux (nogui) and windows.
- go test -race of the gateway tests this stack adds or touches, on
  the stack at fb29cd30f: ok.
2026-10-31 23:35:27 +08:00
yetone f2ae7bdecc gateway: plainSchema judges a self-reference by whole segments (#4561 review)
The previous commit's selfRef took a $ref as a self-reference when the
walk's path began with the ref's pointer as a string. So
"#/properties/a" inside /properties/ab, a sibling, was cut down to
{"type":"object"} instead of being resolved. A self-reference is now
the pointer itself or one of its containers: path == ref, or path
begins with ref + "/".

A "#/…" pointer that names nothing where it points also falls back to
its last segment as a $defs or definitions name again, as every ref did
before pointers were walked ("#/components/schemas/Mode" with Mode in
$defs).

TestPlainSchemaSelfRefBySegment covers both.

Broken by hand: selfRef and localRef back to the previous commit, test
kept. Red: "inner" and "mode" both go out as {"type":"object"}.

Not tried: a real Antigravity request with dsh's tool schema. The
fix is in the flattening, and the gateway tests send the result
through a fake upstream.

Run (on mote, through mote-run):
- Full `go test -tags nogui -count=1 -timeout 45m ./...` with this stack
  on c30d3b7b6: 82 packages ok. internal/gui was red only on
  TestSettingsSaveKeepsWhatItDoesNotSend (#4514, SearchAll from
  b09349d17) and TestColdTurnsTaken (#4510). Both are filed, and neither
  touches this stack.
- Rebased onto 29d0ab39f, which changed internal/gateway since then:
  gofmt -l, go vet (darwin, GOOS=linux -tags nogui, GOOS=windows) and
  go test -count=1 ./internal/gateway ./internal/usage ./internal/provider
  ./internal/sessions all ok at the pushed head. go build ./... ok for
  darwin, linux (nogui) and windows.
- go test -race of the gateway tests this stack adds or touches, on
  the stack at fb29cd30f: ok.
2026-10-31 23:35:27 +08:00
ggbdpq abaf2c4e8f gateway: plainSchema resolves a $ref into properties (#4561)
A $ref that points inside the schema ("#/properties/func/properties/
triggers/items", as dsh's tool parameters carry one) is a local JSON
pointer like a "#/$defs/x" one, but plainSchema read a ref only by its
$defs or definitions name: the pointer's last segment named nothing
there, and the field it stood for went out as a bare {type: object} on
the Antigravity path, the tool losing that field's shape.

Any local pointer is resolved now, where it names; a self-reference —
a ref to the site or one of its containers — stops at the target's
type alone, as the plugin's googleSchema has it.

A test with the error's path fails on the old code.

Reviewed and applied from #4561 (ggbdpq, branch head ab39ddcbc; the
patch's SHA-256 matches the issue). A review fix follows in the next
commit: selfRef matched a pointer as a string prefix.

Broken by hand: plainSchema back at main with the test kept, and
TestPlainSchemaResolvesPointerIntoProperties fails ("again" goes out as a
bare {"type":"object"}).

Run (on mote, through mote-run):
- Full `go test -tags nogui -count=1 -timeout 45m ./...` with this stack
  on c30d3b7b6: 82 packages ok. internal/gui was red only on
  TestSettingsSaveKeepsWhatItDoesNotSend (#4514, SearchAll from
  b09349d17) and TestColdTurnsTaken (#4510). Both are filed, and neither
  touches this stack.
- Rebased onto 29d0ab39f, which changed internal/gateway since then:
  gofmt -l, go vet (darwin, GOOS=linux -tags nogui, GOOS=windows) and
  go test -count=1 ./internal/gateway ./internal/usage ./internal/provider
  ./internal/sessions all ok at the pushed head. go build ./... ok for
  darwin, linux (nogui) and windows.
- go test -race of the gateway tests this stack adds or touches, on
  the stack at fb29cd30f: ok.
2026-10-31 23:35:27 +08:00
yetone 29d0ab39fb sessions: Antigravity CLI (agy) sessions can be deleted (ysm119 on Discord)
ysm119 (#help) could delete Codex sessions on the Sessions page but not
agy's, and wanted to clear out empty ones. A delete now moves a
conversation to magpie's trash the way agy's own /resume delete (F4)
removes it: brain/<id>/, conversations/<id>.db with the -wal, -shm and
-journal SQLite leaves beside it, and annotations/<id>.pbtxt. Restore puts
them back.

What agy keeps of a conversation, read from real agy 1.4.12 in a sandbox
HOME against a fake Gemini endpoint (the live ~/.gemini was only read):
the files above, presence/<id>.lock, a row in conversation_summaries.db,
an entry in jetbox_summaries_proto.pb, and cache/last_conversations.json.
agy's own delete removes the files, the row and the jetbox entry. It
leaves the lock and last_conversations.json. magpie leaves the row and
jetbox entry too, because agy keeps both files open and jetbox is an
unknown protobuf. agy's /resume list leaves out a row whose files are
gone, so it never lists a deleted conversation.

A conversation agy has open is not deleted: agy flocks presence/<id>.lock
for as long as it has it open, idle too, and a held lock (or one that
can't be tried) is ErrActive. On Windows how agy locks it hasn't been seen,
so the minute since a write decides there alone.

Siblings: Hermes, Alma, OpenCode, ZCode, Cline, Grok Build, Kimi Code and
Claude Desktop (Cowork) sessions still can't be deleted. Each keeps an
index magpie would have to edit or leave stale; filed as #4595 with what
each needs.

Run at d018b9302 (on origin/main c30d3b7b6), then rebased onto 2cca11176,
which changes internal/gateway only; go test ./internal/sessions passed
again at the pushed head:
- mote: gofmt -l internal/sessions clean; go vet ./internal/sessions
  (darwin, GOOS=linux -tags nogui, GOOS=windows -tags nogui); go build
  ./... and the linux/windows nogui builds: ok.
- mote: go test -tags nogui -count=1 -timeout 45m ./...: 82 packages ok,
  internal/gui red only on TestSettingsSaveKeepsWhatItDoesNotSend (#4514)
  and TestColdTurnsTaken (#4510), both filed before and untouched here.
  go test ./internal/gui alone also showed TestMainWindowCorners (#3949).
- Windows (win-run): go test -run Agy ./internal/sessions: both new tests
  pass. TestAgySessions and TestAgyRowOnly are red there already (#4115,
  a /work cwd read as \work).
- Real agy 1.4.12 in a sandbox HOME, with a test binary built from this
  tree: Delete of one of three conversations moved its brain folder,
  .db and .pbtxt. agy's /resume then listed 2 of 3 and Other "No
  conversations available". Restore brought it back, and /resume listed 3.
  Before this, with the files moved by hand, `agy --conversation <id>`
  resumed a restored conversation and appended to it.

Broken by hand (each red in TestAgyDeleteRestore/TestAgyDeleteRowOnly):
agy taken out of Deletable; the presence-lock check turned off (a
conversation agy has open was deleted); only <id>.db moved, not its
-wal/-shm (a fresh -wal wasn't seen as recent, and they'd be left behind).

Not tried: agy on Windows or Linux for real; the GUI suite (no GUI file
changed: the Sessions page shows Delete from /api/sessions/manage's
deletable flag).
2026-10-31 23:10:48 +08:00
yetone 2cca111764 gateway: a 413 byte cap or an overflow tells Codex context_length_exceeded, so it compacts instead of reconnecting 5/5 (celestial_eagle_99230 on Discord)
A Codex user on a DeepSeek model kept getting "stream disconnected
before completion: 1017dp: 413 Request Entity Too Large: a web page,
not an API reply ... (request_too_large)" with "reconnecting 5/5".
The big body took the vendor past keepHeldAfter, so Codex's stream
had begun, and streamError sent response.failed with code
server_error. Codex (codex-api sse/responses_error.rs) reads any code
it doesn't know as Retryable, so it sent the same body five more
times. Each was refused the same way, and nothing compacted.
context_length_exceeded is the one code Codex stops on: it marks the
window full and compacts, and core compact.rs trims the oldest items
for as long as the compaction is refused too.

- streamError: a 413 on the Responses shape is code
  context_length_exceeded, for every Responses client. The text still
  says request_too_large for pi.
- failTo: Codex reads a 413 told by HTTP status as UnexpectedStatus,
  and a 400 context_length_exceeded as InvalidRequest
  (api_bridge.rs). Neither compacts. So when Codex (fromCodex, or
  Claude Code's Codex plugin) asked for a stream, a byte cap or an
  overflow goes to it in a stream even before one began
  (keptAlive.compactsInStream). A vendor's own overflow, released
  until now, goes this way too. Other clients keep the status they got
  before.
- Nothing changes for resting: a 413 still rests nobody, and a group
  still tries the next member first.

Tests: codex_byte_cap_test.go. It replays the reporter's nginx page
mid-stream and before the stream, plus a vendor overflow 400, and
checks a non-Codex client keeps its 413. Red on the old code:
TestCodexByteCapInStreamCompacts got "server_error" (the reporter's
exact text), and both TestCodexByteCapBeforeStreamCompacts cases got
a 413 or 400 JSON. TestStreamErrorByteCapInEveryShape now expects
context_length_exceeded for Responses.

Run on mote (mote-run, this tree): go test ./internal/gateway on the
byte-cap, stream-error, overflow, compact and Codex tests: ok. GOOS=linux
and GOOS=windows go vet ./internal/gateway: ok. gofmt -l: clean.
Full suite: mote-run go test -timeout 45m ./... at fb29cd30f plus this
change (before the gateway-routing.md paragraph, docs only): 82 packages
ok; internal/gui red in two tests this change doesn't reach, both filed:
TestSettingsSaveKeepsWhatItDoesNotSend (SearchAll not kept, #4514) and
TestMainWindowCorners/macOS_26_SDK (macOS 27 toolbar, #3949).

Not tried: a real Codex against a real 413 vendor. Codex's handling
was read from openai/codex main, not run. DeepSeek documents no
request-body byte limit, and whether 1017dp is DeepSeek's own API or
a relay in front of it is unknown.
2026-10-31 22:57:37 +08:00
yetone c30d3b7b63 plugin pages: a page the reader left is told, and let go after 10 minutes unless it keeps itself
A plugin's page kept its frame, with its scripts, timers and
connections, for as long as the window was open once it had been
looked at: show() only hid its view, and a frame in a hidden view isn't
hidden to itself (its visibilityState doesn't change), so a page
couldn't even pause on its own. Asked by the owner: is that by design?
Only the lazy first load was.

- The kernel's leave hook now reaches the page part: the page is told
  {event: "visibility", data: {visible}} as the reader leaves and comes
  back. The bridge has magpie.visible and magpie.onVisibility(fn); hello
  carries visible, for a page left before it said hello.
- A page left 10 minutes (IDLE_MS) has its frame removed and loads again
  when next opened. Back sooner, it is the same frame. Its hello timer is
  cleared, so nothing says it broke.
- magpie.page.keepAlive: true (plugin.PageSpec.KeepAlive, keepAlive in
  /api/plugin-pages) keeps a page however long, for one that works while
  no one looks at it. Anything but true is false, read as raw JSON so a
  wrong type never drops the package's page.
- plugin-runtime.md's page row says so.

Run on mote. The Go suite and most GUI files ran at this change on
557f51dbf. After rebasing onto 30cd39f19 (none of these files changed
upstream), the budgets, TestWindow* and the page GUI files ran again
at this tree:
- plugin-page-idle (new), plugin-page and plugin-panels, chromium and
  webkit: 14/14 at 557f51dbf. At the rebased tree, the first run was
  13/14: plugin-page's chromium "draws in its frame, shut in" was red
  once, and its assertion wasn't kept (#4589). After that: 42/42 over
  3 runs, then 16/16 chromium over 4.
- i18n-keys, plugin-actions, plugin-kinds-discover, plugin-kernel,
  plugin-replaced, plugin-proxy-page: 51/52. The red is i18n-keys'
  "Unmarked", the same on origin/main e0eb74987 (#4524).
- go test -timeout 45m ./...: every package ok except three reds, none in
  code touched here:
  - TestSettingsSaveKeepsWhatItDoesNotSend (#4514) and
    TestMainWindowCorners (#3949) fail the same on origin/main e0eb74987.
  - TestUnroutedHeldReportSaved (#4300) failed in the full run only.
    Alone, -count=5, it passes.
- go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet
  ./..., go build ./..., gofmt -l: clean.

Broken by hand: with the leave hook taken out of the page part, the new
test is red in both engines.

Not tried: a real plugin page in the desktop app or WebKitGTK. The
IDLE_MS length (10 minutes) is a judgement, not measured.
2026-10-31 22:39:37 +08:00
yetone b75fa328ce gui: the ban warning is said once, not again beside accounts signed in
The owner, on Claude Code's editor with four Claude accounts in it and
"Claude 账号可能被封禁" shown on Add another: "这里就不要显示可能被封禁了".
A subscription that warns before a sign-in (Claude, Antigravity and the
plugin-served ones with risk) now warns only while it has no account
signed in, and never to sign one of its accounts in again. startSignIn
asks hasLogins(agent), and its o.user, before the risk step. The import
box keeps its note.

What goes with it: Factory's warning offered "Use an API key instead…".
Factory is retired and the Add sheet leaves it out with no account, so
that warning was reachable only beside an account, and no longer is.
Its accounts list's "Add an account by API key…" row still offers the
key; factory-key.test.cjs now starts there. signin-close and
signin-proxy no longer click "Sign in anyway" in editors with accounts.

claude-risk.test.cjs: a new case opens a Claude editor with an account,
clicks Add another, and wants the sign-in asked at once with no warning
(chromium and webkit, en and zh). The first-account case is unchanged.

Run, on the Linux box (magpie-desktop):
- Broken by hand: the old app.js with the new test: red in both engines,
  nothing asked.
- All 46 GUI files that reach a sign-in or the warning, plus i18n-keys:
  739 ok, 2 red. login-import chromium en timed out waiting on its
  import box, then passed 4 of 4 alone. i18n-keys' "a plugin's words are
  its own" is red the same at origin/main fb29cd30f: #4524.
- An earlier run of the same files had claude-setup-token chromium zh
  and deprecated-subscriptions webkit zh red once each; both passed in
  the six-file rerun at this head (74 of 74).

At the pushed head (rebased on fb29cd30f): the four changed GUI files,
60 of 60 ok. go test ./internal/gui on mote: red only in
TestSettingsSaveKeepsWhatItDoesNotSend (#4514) and
TestMainWindowCorners/macOS_26_SDK (#3949), both red the same at
origin/main fb29cd30f.

Not tried: the real app, and macOS WebKit (mote's WebKit launches hang).
2026-10-31 22:39:21 +08:00
yetone fb29cd30f9 tray: the Mac's menu bar figures are regular weight, a lone one in the menu bar's own font (qingnianxiaozhe on X)
Beside Surge's speeds and another app's stacked "0 KB/s", magpie's
"93% / 98%" read visibly bolder, and a lone "98%" too small and too
heavy, so the reporter kept it out of the menu bar. mpRowFont drew two
stacked rows in 9.5pt semibold and one row in 11pt medium, both since
ef4edf8c5 (the first drawn image, no owner call on the weight). Now:

- two rows: monospacedDigitSystemFont 10pt regular (was 9.5pt
  semibold); row gap unchanged (3.5pt), the block 17.6pt as Surge's;
- one row: monospacedDigitSystemFont at menuBarFont(0)'s size (13pt
  on macOS 27, was 11pt), regular (was medium);
- the letter-in-a-ring stand-in for a logo, the template tint and the
  light/dark colours are unchanged. Linux shows the figures as the
  tray's text label (the panel's font) and Windows' tray shows none,
  so neither has a font to change.

Measured in the reporter's q1: magpie's digits were Surge's height
(13px) with stems 1.30x as wide (2.80 vs 2.16px). Rendered at 2x the
stems go 2.47 -> 2.04px for two rows (medium was 2.14; regular is the
closer of the two to Surge and the other app).

TestTrayRowFont (new): two rows 9.5-10.5pt, weight trait <= medium,
digits of one width; one row the menu bar font's size, weight 0, one
width. Red on the old fonts by hand (9.5pt weight 0.30; 11pt weight
0.23 vs the menu bar's 13pt). gui-shell.md says the new sizes.

Run on mote at the pushed head (rebased on origin/main), through
mote-run: gofmt -l internal/gui (empty); go vet ./internal/gui/;
GOOS=linux go vet -tags nogui, GOOS=windows go vet (with and without
nogui) ./internal/gui/; go test -count=1 ./internal/gui/ and with
-tags nogui: all pass but TestSettingsSaveKeepsWhatItDoesNotSend
(#4514, SearchAll) and TestMainWindowCorners/macOS_26_SDK (#3949,
macOS 27), both filed and red on origin/main too; the nogui run also
met TestColdTurnsTaken (#4510, the turn warm-up's race: 1 of 5 red
alone, then a hang to the timeout, at load ~35). Every TestTray* test
passes, run again alone with -v.

Compared visually: a throwaway test rendered the image through
trayImagePNG at 24pt 2x, light and dark, before and after, for two
rows and one, plain and beside a logo, and a mixed pair; laid beside
the reporter's crop of Surge's figures.

Not tried: the live menu bar beside Surge and iStat Menus (no real
app run; renders only), a non-Retina screen, and the full Go suite
and GUI suite (the change is AppKit drawing in one package).
2026-10-31 22:29:48 +08:00
yetone 30cd39f19b provider: Devin's plugin is 0.1.29 at least, its Claude models keep the client's cache marks (plugins#566)
Devin 0.1.28 asks its Claude models on Anthropic's Messages API and sends
each of the client's blocks as a prompt of its own, with Devin's cache
mark (prompt_cache_options EPHEMERAL) where the client put cache_control.
A grown Claude Code classifier history read 558 tokens from the cache
and wrote ~7.3k again; on a real account it now reads 7,318 and writes
the 560 it grew by (haiku-5-5 and opus-5-5). 0.1.29 says a failed tool
result in its text, "Error: " first, as the chat path does.

npm view @magpie-community/opencode-devin-auth version --prefer-online:
0.1.29 when this landed.

Run: mote-run go test -timeout 45m ./internal/provider/... ok (102.8s).
Not tried: a magpie gateway with Claude Code end to end on the new
plugin.
2026-10-31 22:28:02 +08:00
yetone 59ea5dc8f8 gateway: a failure with this computer off the network rests nobody (usrname1833)
usrname1833 on Discord: with the computer offline, a routing group's
members failed to connect one after another, each rested, and the first
stayed behind the others once the network was back.

A 502 whose error says no connection was made (dial, lookup, refused, no
route, TLS handshake timeout, and Bun's ConnectionRefused / ENOTFOUND
for a plugin's fetch) now asks whether this computer has a network,
unless any upstream answered in the last 15s: no interface up with a
global address means none; otherwise up to three hosts of the user's
other providers (not p's own, not proxied ones, not localhost / LAN) are
dialled at once (2s), and none taking the connection means offline. The
verdict is kept 5s and asked by one request at a time. Offline, the
member is passed over as a down proxy is (failProxy): no rest, no count,
the trace says Fail "offline". One provider that can't connect while
another's host takes a connection, or while replies came lately, still
rests as before.

Covered where every rest passes: restAfterMarked (so decide_group's and
count_tokens' rests too), the serve loop's next-member path, and the last
member's label. Routing page: "network down" tag and a story for the
next-member and last-member cases, in zh, zh-TW, ja and de.

Run (mote, at this tree):
- gofmt -l clean; go vet ./internal/gateway on darwin, GOOS=linux,
  GOOS=windows: ok
- go test -run 'TestOfflineRestsNobody|TestProxyDownDoesNotRest' -v
  ./internal/gateway: ok; go test -timeout 45m ./internal/gateway:
  ok (708s)
- GUI: routing-offline.test.cjs (new) 10/10 and routing-proxy 4/4,
  Chromium + WebKit, en zh zh-TW ja de. Every routing-*.test.cjs at once
  (load 30-44 on mote): 1997 pass, 29 fail. The untouched base 3d063e34f
  gives 1987 pass, 29 fail in the same files, with the subtests shuffled
  (#4585). i18n-keys: only "Unmarked" is red (#4524), as on the base.
Broken by hand: offlineFailure returning false -> TestOfflineRestsNobody
red ("nothing reachable" and "no interface up": Fail other, Rest set);
client.js at HEAD -> routing-offline 0/5 in Chromium.

Not tried: a real machine taken off the network; a plugin (Bun) fetch's
real offline error text (matched from Bun's error names only); providers
behind a proxy (left to failProxy and not dialled); a group whose
members all sit on the local network (near hosts aren't dialled, so
with an interface up their failures still rest); the full ./... suite.
2026-10-31 22:23:18 +08:00
yetone e0eb74987c plugins: a dist branch not read is unknown, not "not on npm", and its read isn't cut off by one ask
ferock on Discord (v0.1.2399): the Plugins page showed the Chat page
plugin (@magpie-community/page-chat, on the community repo's dist
branch only, never on npm) as Coming soon.

Cause: Info asks each package under npmEach (6s). npm said 404, and
npmAsk turned to distInfo -> distPkg, which read the ~1.6MB index.json
(GitHub and the jsDelivr mirror) under that same 6s context, holding
distMu. On a slow link the read was cut off, distPkg returned nil as if
the branch had no such package, and npmInfo kept "not on npm" (ok=true,
empty NPM) for an hour, saved to plugin-npm.json. distWait then held a
new read back for a minute.

Fix:
- distPkg returns (*distPackage, error): nil, nil only when the branch
  was read and lacks the package (or it is out of scope); an error
  wrapping errDistUnread when the branch couldn't be read (last read
  failed or not finished) and the kept index doesn't have it.
- The index is read in its own goroutine (readDist), apart from the
  asker's context, with its own distReadFor (2m). One read at a time
  (distReading); askers wait for it or their own ctx, distMu is not held
  across the network read. A read that ends after its asker stopped
  waiting is kept for the next ask.
- npmAsk: npm's errNotFound with the dist branch unknown becomes the
  dist error, so every caller that keeps "missing" (Info/npmInfo,
  newestOf in store.go, the update checks in updates.go) treats it as
  unknown and asks again. Readme says the branch couldn't be read instead
  of npm's not found. installDist returns the unread error rather than
  "has no".
- mendDist was checked: it reads only local files, no dist read.

Old data: a "not on npm" already kept in plugin-npm.json by an older
build is asked again once it is an hour old, as before.

Tests: TestDistReadSlowerThanAnAskIsntMissing (index.json held past
npmEach: not kept as missing, and the next Info after the read ends has
0.1.7) and TestDistReadFailedIsntMissing (index.json 503: unknown, asked
again; a read branch without the package is still errNotFound).
fakeDist's reset waits for a read under way (distSettled).

Run (mote-run; vet at base 2cfb8351d, tests again at this commit rebased
on origin/main 484b45d82, which changed no Go in plugin or gui; pushed on 7dc8a18d0, which
touches only internal/provider and internal/gateway):
- gofmt -l: nothing
- go vet ./internal/plugin/..., GOOS=windows go vet ./...,
  GOOS=linux go vet -tags nogui ./...: ok
- go test -count=1 -timeout 45m ./internal/plugin/... ./internal/gui/...:
  internal/plugin ok (103.6s). internal/gui FAIL, two tests only, both
  red the same on a fresh origin/main 484b45d82 run alone and filed:
  TestSettingsSaveKeepsWhatItDoesNotSend (SearchAll, #4514) and
  TestMainWindowCorners/macOS_26_SDK on mote's macOS 27 (#3949).

Broken by hand (mote-run, -run DistRead):
- npmAsk's errNotFound -> dist error override removed: both new tests
  red (the market kept an empty entry).
- readDist given the asker's ctx (the old cut-off): the slow test red
  (after the dist answered, still no version).

Not tried: a real slow link or ferock's machine; the real index.json
from the dist branch; the GUI page itself (actionFor already shows a
spinner for a package with no npm entry yet).
2026-10-31 22:22:12 +08:00
yetone 8e9da4e832 provider: Zed's plugin is 0.1.12 at least: a string message content goes as a text block (Been on Discord)
npm view @magpie-community/opencode-zed-auth version --prefer-online: 0.1.12
at landing. The plugin's change: magpie-community/plugins 3e940bc, bun test
49 pass on mote, its new test red 2 of 2 with the change reverted.
2026-10-31 22:21:44 +08:00
yetone 7dc8a18d0e provider: a plugin's Gemini model is tested on generateContent, as the gateway asks it
A plugin's @ai-sdk/google model is served by the gateway on Code Assist,
which it sends to the plugin's fetch as Gemini's generateContent. Test
models kept only chat, Responses, Anthropic and Gemini, so such a model was
sent the body of the plugin's first other API: Zed's cloud read a chat body
as a Google request and answered 400 "failed to parse Google AI request:
missing field contents" for every Gemini model (Been on Discord), while
agents were answered. Its test now goes through the gateway's translator
(testTranslated), with the plugin's longer wait.

Run (mote-run): go test ./internal/provider ./internal/gateway ok (120s,
710s) at e0bb3c30a; go vet ./internal/provider ./internal/gateway on
darwin, GOOS=linux and GOOS=windows ok; after rebasing on 484b45d82,
./internal/provider ok again.
Broken by hand: with the provider change reverted,
TestPluginGeminiModelTestedOnGenerateContent is red (fake-gemini tested on
chat, /v1/chat/completions reached).
Not tried: a real Zed account's Gemini model.
2026-10-31 22:21:29 +08:00
yetone 484b45d825 provider: WorkBuddy's mover asks for plugin 0.2.8, which lifts deepseek-v4.1-flash's 100k cap on copilot.tencent.com (plugins #561)
@magpie-community/opencode-workbuddy-auth 0.2.8 (plugins 42a5055) takes
0.2.7's 100000-token cap on deepseek-v4.1-flash off the China build: three
users' China Free-plan accounts took 110k to 992k-token prompts on it, and
the vendor's own refusal names 1048576 as the maximum. The cap made agents
compact at 100k. A prompt WorkBuddy does find too long is its own 400
"prompt is too long", passed on as it came, which overflowed() reads as an
overflow (no rest, not retried). keepMovedCurrent brings every moved user
to it.

Run: go test -timeout 45m ./internal/provider/... on mote at 63cb1af3c plus this
change: ok. npm view @magpie-community/opencode-workbuddy-auth version
--prefer-online: 0.2.8.

Not tried: a real copilot.tencent.com request (my CN sign-ins answer 401).
2026-10-31 22:16:57 +08:00
yetone 63cb1af3cb library: the MCP router's mark is the bird with its tail routed out to three ends
The owner asked for a mark that says MCP routing and picked, from three
generated drafts, magpie's bird whose tail fans out into lines ending in
dots. It is drawn as SVG on the bird itself, not a picture, so it stays
sharp at 17px and takes the theme's colour: the bird clipped short of its
tail (#bird-notail, beside #bird-tail in index.html), three strokes from
where the tail was and a dot at each end. Every place hubMark draws (the
Library's MCP router row, the Connect an app sheet) gets it.

Run on mote (macOS 27): library-mcp-hub now checks the clip, the three
routes and their ends (red on the old mark). library-*, i18n-keys and
old-webkit, both engines: 895 pass, 5 fail. The reds are i18n-keys
"a plugin's words are its own" (#4524) and library-row-remove's 3
subtests (#4304); both red the same at origin/main 2cfb8351d. Looked at
in dark and light at 17px, 34px and 220px.
2026-10-31 22:06:25 +08:00
yetone 557f51dbf0 library: a skill linked into an app version the update deleted follows it to the current one (tjhhhh on Discord)
tjhhhh: ego lite keeps its skills in its framework's Versions/<v>. After
the app updated, the skill was in the new version's folder, the old folder
was gone, and magpie still linked the old one. dccfefdf7 (#2635) linked new
imports through the app's own steady link (~/.local/share/ego/ego-skills, or
Versions/Current), but a skill brought in before then links straight to the
resolved Versions/<old> path. tjhhhh's case is that old link: an import
made since dccfefdf7 already follows the update
(TestImportedSkillFollowsAppUpdate).

followMovedSkills (skill_moved.go) runs on every read of the Library page,
under the read's link memo, which is restarted when a link is mended. It
also runs as the first step of every sync. For each library skill that is
a link:
- Target gone, and its first missing part named like a version: link the
  same place under the folder's Current/current/latest link. With no such
  link, use the highest version beside it that has a SKILL.md there
  (1.10 after 1.9).
- Target in Versions/<v> while the bundle's Versions/Current links to
  another version with the same skill: link it through Current.
Source.Dir follows. Only the link is replaced (os.Remove of the link, then
dirLink, and the old link is put back if the new one can't be made). A
folder of the library's own, a link the user deleted that isn't a version
(still shown missing), and the app's old version folder are left alone.
docs/subsystems/library.md says so.

Run (all on mote via mote-run):
- New tests on ego lite's real layout (egoLite: framework Versions/<v>,
  Current, ~/.local/share/ego links): TestOldImportFollowsDeletedVersion
  (0.5.1.13 deleted, then 0.6.0.12, then the next update to 0.7.0.1 by
  itself, plus the agents' link through the library),
  TestOldImportFollowsVersionsCurrent (old kept, through Sync()),
  TestOldImportFollowsHighestVersion, TestMovedSkillsLeaveTheRest and
  TestVersionLess. All pass, as do dccfefdf7's three tests.
- Broken by hand: with followMovedSkills returning false at once, the
  three OldImport tests are red.
- go vet -tags nogui ./..., GOOS=linux go vet -tags nogui ./... and
  GOOS=windows go vet ./...: clean. gofmt -l: nothing.
- Full go test -tags nogui -count=1 -timeout 45m ./... in a sandbox HOME:
  80 ok, 3 FAIL.
  - internal/library TestReadLooksAtEachFolderOnce was mine: the mend ran
    before the read's memo, so each skill link was looked at twice. Fixed
    (the memo starts first and restarts after a mend). The whole
    internal/library package then passed (75s).
  - internal/gui TestSettingsSaveKeepsWhatItDoesNotSend is red on
    origin/main 3ecc02b78 and ccc791231 alike (#4514, SearchAll).
  - internal/cli TestAgentFieldNameShowsIt failed once under load. It
    passes alone and in a whole internal/cli run, and its message was lost
    to my grep of the log (#4583).
  The full ./... was not run again after the memo fix.
- At the pushed head, rebased on a51776f9c (which changed internal/library
  too): go vet and the whole internal/library package ok (95s).

Not tried: tjhhhh's own machine and ego lite's real update (the layout is
the #2635 fixture, built from iomect's report). Windows junctions to a
deleted version (dirLink is the same call ImportSkill uses). An app that
renames the folder above the version is not followed: it stays missing.
2026-10-31 22:01:45 +08:00
yetone 49b8c64559 dsh: deepseek-acp gets magpie's route in settings.yaml, and the key store is owner-only
liby233 on Discord: dsh in an editor over ACP (deepseek-acp, CodeG, the
desktop app) listed only DeepSeek's own models. Checked against the real
packages from npm (deepseek-acp 0.9.0, dsh 0.2.1-rc.5): deepseek-acp
mounts FileSettings on $DSH_HOME/settings.yaml alone, never profiles/,
and loads the pi-ai plugin only when that file mentions "llm-pi-ai". Its
credentials-local store throws when .credentials.yaml is readable beyond
its owner ("run chmod 600"), so a 0644 store stops it from starting.

- settings.yaml gets llm-pi-ai.providers.magpie, built by the same code
  as the profiles' route (dshPutProviders), at 0600 when magpie creates
  it. It gets no agent-default-model of magpie's. The user's routes,
  other sections, comments, mode and the api they chose for magpie's
  route are kept. Disconnect takes only magpie's route out, and the
  section too when nothing else is left in it.
- dsh 0.2 renames settings.yaml to settings.yaml.imported (over the one
  before) at each full start and imports it into the profile. The
  serving round, Sync, Set and Unwire write it again. The user's own
  import from before magpie's first write is copied once to
  settings.yaml.imported.kept, so magpie's import never overwrites it.
- .credentials.yaml is made owner-only (go-rwx) on every write and every
  Sync, whoever made it 0644. In a WSL distro, a file written through
  \\wsl.localhost comes out 0644, so the chmod runs inside the distro:
  wsl.exe -d <distro> -e chmod go-rwx <path>. A failure is logged and
  doesn't fail the write.

Run:
- internal/agent on mote (ok) and its Dsh/WSL tests on Windows
  (xiaomi-gpu, ok); gofmt; go vet on darwin, GOOS=linux -tags nogui
  and GOOS=windows.
- The new tests (dsh_acp_test.go) were broken by hand, each turning red:
  dshSettingsAgain disabled, ownerOnly disabled, dshKeepImported
  disabled, and the round's call removed.
- Real runs on mote in a sandbox HOME (~/runs/realdsh-home), never a
  live ~/.dsh. After magpie's Pick, real deepseek-acp's session/new
  listed magpie::deepseek/pro and magpie::deepseek/flash; without
  settings.yaml it listed only DeepSeek's. With a 0644 store its boot
  failed with the credentials-local error, and it started once magpie
  had made the store 0600. `dsh --profile web --dump-config` shows
  agent-default-model magpie and the route. `dsh headless` ate
  settings.yaml into the headless profile, and magpie's round
  (dshWiredOnce) wrote it again, after which ACP listed magpie's models
  again.
- On magpie-desktop: `wsl.exe -d magpie-desktop -e chmod go-rwx` takes
  a file written through UNC from 644 to 600.

Not tried:
- magpie's own write into a real WSL distro end to end; only the
  command form above, and fakeWSL in tests.
- A WSL distro has no serving round, so after dsh eats settings.yaml
  there, it comes back only on magpie's next Sync or model pick.
- A dsh from before profiles (config.yaml only) is left as before.

Also: fakeWSL answers the chmod without recording it, since it is neither
a start nor a probe (TestWSLMoreAgentsStopped counts starts).
2026-10-31 22:00:28 +08:00
yetone a51776f9c3 gateway: a socket's turn writes its conversation once, not through json.Marshal twice
Codex sends each turn on its Responses WebSocket with only what came
after the reply before it, and the gateway put the conversation back
together and wrote the body the HTTP route would have had: json.Marshal
of the list, then json.Marshal of the body around it. encoding/json
writes a json.RawMessage through its scanner a byte at a time into a
buffer that doubles and is then copied out, so a 3.2 MB conversation
allocated 9.6 MB on every turn. marshalRaw (#1532) had fixed this for
the HTTP routes' rewrites; the socket's turn was left on json.Marshal.

turnBody writes the same bytes, keys sorted, each value checked by
jsonCheck and compacted with <, > and & and U+2028/2029 escaped, into
one slice sized for them: its length plus the five bytes each <, > and
& grows by, counted with bytes.Count, since code is full of them. A
value encoding/json would refuse still goes to json.Marshal, which says
why. Live heap on the owner's running app had 8.8 MB under this
json.Marshal between collections.

Run on mote (M5 Pro), at this tree:
- TestTurnBodyIsJSONMarshal: byte for byte json.Marshal's for 0, 1 and
  40 pretty-printed items with literal <, >, &, U+2028, U+2029, tabs
  and CJK; nil input is null; a broken item is refused.
- TestTurnBodyWrittenOnce: a 3,225,123-byte turn allocates 3,252,336
  bytes (1.01x); json.Marshal twice, 9,605,256.
  Broken by hand in the mote copy, each red: the escape count dropped
  (2.9x, the slice grew twice); values written without HTML escaping
  (bytes differ for all three sizes); json.Marshal back inside
  turnBody (3.0x).
- TestResponsesSocket* and TestCodexSocket*: ok.
- go vet ./internal/gateway/ for darwin, linux and windows; gofmt clean.
- The whole internal/gateway package at the parent, v0.1.2406: ok (772s).

Real use: this build (go build -tags nogui) in a sandbox HOME with the
owner's DeepSeek key only, magpie serve on 127.0.0.1:3581, and Node 22's
WebSocket on /v1/responses: a 30 KB first turn of 400 lines with
<ZEBRA&n> and code, asked for the last one, answered <ZEBRA&399>; the
second turn, previous_response_id and one new message, asked for the
first, answered <ZEBRA&0>. The log: 2 turns, 1 continued, 88003 bytes
sent on as whole requests.

Not tried: a real Codex CLI session on the socket (the client here
sends what Codex sends: response.create, previous_response_id, input).
2026-10-31 21:58:06 +08:00
yetone 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.
2026-10-31 21:52:54 +08:00
yetone ccc791231f gateway: a long turn sent to a Chat upstream is copied once, not five times
A 3.2 MB Codex /v1/responses request served by a Chat provider allocated
about 70 MB in the gateway, and that garbage, at GOGC 100 over the app's
live heap, set the peak footprint. Four copies went:

- unquoteJSON built an escaped string (any text with a newline) in a
  buffer and then copied it into a string; the buffer is the string now
  (unsafe.String, nothing writes to it again), with a copy only when
  \u escapes left more than a quarter of it unused.
- turnIn joined every user text of the conversation (userSaid) only to
  see whether any was there; saysAnything stops at the first.
- buildChat's user message grew a strings.Builder part by part across
  a merged turn; joinTexts sizes it once and takes a lone part as it is.
- marshalItems ran json.Marshal, whose buffer doubles and is then
  copied out, over one message that holds the whole turn. marshalSized
  sizes the maps, lists, strings, bools and ints a body is made of
  first and writes them into one slice of that size, as encoding/json
  writes them (HTML escaped, � for bad UTF-8, U+2028/2029); any
  other value is json.Marshal's own. A []any item, reached by its
  address, is a *any, which went to json.Marshal twice (to size, then
  to write) until it was dereferenced; TestMarshalBodyAllocatesTwoBodies
  caught that at 154 MiB for a 47 MiB body, now 52.

Run on mote (M5 Pro), at this tree:
- TestLongTurnCopiedFewTimes, a 2.0 MB 300-turn Responses body with
  CJK and newlines: read 6.72 MB -> 4.76 MB (3.4x -> 2.4x), turnIn
  1.93 MB -> 10 KB, buildChat 27.3 MB -> 6.06 MB (13.7x -> 3.0x).
  Broken by hand one at a time in the mote copy, each red on its own
  bound: unquote back to string(b) 3.4x; userSaid back in turnIn
  1.9 MB; the Builder back 7.4x; json.Marshal back 6.2x.
- TestMarshalSizedIsJSONMarshal: byte for byte against json.Marshal
  over all 256 bytes, bad UTF-8, a lone surrogate, U+2028/2029, HTML
  characters, keys needing escapes, nil maps and lists, floats,
  RawMessage, pointers, and a func json.Marshal refuses.
- go test -count=1 -timeout 45m ./internal/gateway/: ok (582.9s).
- go vet ./internal/gateway/ for darwin, linux and windows; gofmt clean.
- Gateway bench (120 requests of a 3.2 MB Responses body, 4 at a time,
  through a fake Chat provider, 200 MB ballast held live), 3 runs each,
  old/new: TotalAlloc 8368-8403 MB -> 5889-5891 MB (-30%), GCs 26-27
  -> 18-19, phys_footprint_peak 795/806/807 MB -> 763/762/749 MB,
  CPU 7.89-7.92 s -> 8.01-8.17 s (the size pass costs about what the
  copies saved).

Real use: this build (go build -tags nogui) in a sandbox HOME with the
owner's DeepSeek key only, magpie serve on 127.0.0.1:3581. A 180 KB
/v1/responses request (a long CJK turn with <tag> & "quotes" \ tabs,
a function_call and its output holding U+2028, then a question) to
deepseek/deepseek-flash, served through buildChat: answered with both
code words as sent (<ZEBRA&42>, MANGO), non-streamed and streamed.

Not tried: an Anthropic-in, Chat-out request, and the live app's own
peak (the bench stands in for it).
2026-10-31 21:39:37 +08:00
yetone 7d11f7d428 gui: Rex opens sessions in a Rex session of magpie's own, with none, one or several open (#4565, StringKe)
StringKe tried b9e5bc6cb with the real Rex (server 0.0.1793131181,
Rex Beta 0.1.0) on v0.1.2391: it opened only when Rex had exactly one
session. Outside Rex, `rex run` with no -s exits 3 both for no session
and for several ("session target default is ambiguous"), and exit 3
means not found or ambiguous; magpie then ran `rex new <t> --label <t>`,
and `rex new` has no --label (exit 2). run's --label also names the
block, not the tab, and the CLI can't tell which session the app shows.

Now magpie keeps a Rex session of its own, labelled magpie. openInRex
lists sessions with `rex ls --json` and takes the one labelled exactly
magpie (else magpie in another case), by its full ID since labels can be
shared. It runs `rex run -s <id> --label=<t> --json -- /bin/sh -c ...`
and names the new tab with `rex window rename -s <id> -- <window_id> <t>`
from run's JSON. With no such session, or a 3 from run because it ended
since the list, it runs `rex new magpie --window=<t> -- /bin/sh -c ...`,
whose first tab is so named. Labels go as --flag=value and the rename's
positionals after --, so a title starting with "-" stays a title. Exit 4
still says to open Rex. rexRun now gives stdout only (for the JSON), and
rex's stderr comes back through ExitError for the message.
docs/reference.md's Session terminal paragraph says it.

Every flag was checked against the real rex CLI, not the report: the
snapshot build 0.0.1793420730-g6d0d9a (rex-darwin-arm64.zip from
blob.superlogical.com, sha256 checked against the release API) on mote,
in a sandbox HOME and XDG_RUNTIME_DIR, where rex autostarts a server of
its own. `rex new --help`, `run --help`, `window rename --help`; by hand
with 0, 1, 2 sessions and two labelled magpie/MAGPIE: no -s exits 3
"not found: no sessions" with 0 and "ambiguous" with 2; `new --label`
exits 2; `run -s <full id>` works with any number; `-s magpie` with two
so labelled exits 3 ambiguous; `rex new magpie --window=<t>` names the
first tab; rename sets the tab's label.

Tests: TestOpenInRex runs a fake rex modelled on those answers (target
by full ID or any-case label, 3 for not found and ambiguous alike, 2 for
new --label) with no session, one other, two others, magpie's among two
and two labelled magpie, opening twice each: one magpie session made,
then used, both tabs named. Also a session that ends between ls and run,
exit 4 and exit 1. TestOpenInRexReal runs the same cases against the real
rex when MAGPIE_TEST_REX names one (skipped otherwise), with a server of
its own that it kills and stops at the end.
TestDiscoverTerminalsOffersRex uses the fake with two sessions.

Ran, through mote-run at this tree rebased on origin/main f85a221c9:
- MAGPIE_TEST_REX=<real rex> go test -count=1 ./internal/gui: every test
  ok, TestOpenInRexReal included, except TestSettingsSaveKeepsWhatItDoes-
  NotSend (#4514) and TestMainWindowCorners/macOS_26_SDK (#3949), both
  red the same run alone on a detached origin/main f85a221c9.
- gofmt -l; go vet ./internal/gui; GOOS=linux -tags nogui and
  GOOS=windows go vet ./internal/gui and go build .: ok.
- No rex server or /tmp/rx* left after the tests.

Broke by hand, each red, then restored: the old openInRex (run with no
-s, then new --label): every TestOpenInRex case, the discovery test and
TestOpenInRexReal red ("unknown flag: --label"); the session lookup made
to find none: a second magpie session each time, red in the fake and
the real test; the window rename left out: tabs "Window <id>", red in
both.

Not tried: the Rex app itself (its download needs a Discord sign-in),
so whether Rex.app switches to the magpie session when a tab is added
from outside is not seen; nor whether an autostarted CLI server could
differ from the app's when the app is closed. Not the full go test ./...
(only internal/gui changed), no GUI Playwright run (no JS changed), not
run on Linux or Windows.
2026-10-31 21:38:56 +08:00
yetone f85a221c96 plugins: a plugin installed twice says "another copy" once, not its own name per provider (plugins#565)
ferock (plugins#565) installed the CodeArts / OfficeAce plugin from two
specs. Each copy serves codearts and officeace, so each card got one
clash line per provider, built from the other copy's shownName, which
is the card's own name. In zh it read "CodeArts / OfficeAce 也登录 CodeArts;
由这个插件提供" and then again for OfficeAce.

clashLine is now given groups (clashGroups): a row's clashes grouped by
side (served here or by the other plugin) and by which specs they clash
with, with the provider names joined. When every other spec's name is
this row's own name, the line says another copy of this plugin ({spec})
does it. Otherwise several names use new plural keys, and one name uses
the old key. All four new keys are in zh, zh-TW, ja and de. The
existing zh and zh-TW singular line now reads "{other} 也能登录 {name},
现由这个插件提供" in place of the clipped "也登录 …;由这个插件提供".

Run on mote, at this tree rebased on origin/main 3d063e34f:
- plugin-clash.test.cjs: the new test, "one plugin installed twice
  says so once, not by its own name", covers both specs, every
  language, widths 1100 and 560, Chromium and WebKit. It passes, and
  with the old plugins.js and i18n.js (stashed) it is red, as are the
  zh and zh-TW `serves` lines.
- i18n-keys, gui-de/ja/zh-tw, dates-gui-lang and every plugin*.test.cjs
  in Chromium and WebKit. Before the rebase: 891/899 and 461/468 pass.
  origin/main 3d063e34f alone: 869/877 and 450/457. Every red is the
  same on main, and each is filed: gui-ja's {agent} (#4580, filed here),
  i18n-keys "Unmarked" (#4524), plugin-move-unserved Try again (#4392),
  plugin-card-update (#3079). plugin-namesake ja 440 and the
  "Install asks first" case were red once in the full run. Rerun at
  this head with plugin-card-update, plugin-replaced, i18n-keys,
  gui-zh-tw and gui-de in both engines, they pass (80/81, the one
  red is #4524).
- go test -tags nogui ./internal/gui: the only reds are
  TestSettingsSaveKeepsWhatItDoesNotSend (#4514) and TestColdTurnsTaken
  (#4510), both red at 3d063e34f alone. The budgets pass.

Not tried: the real app with the plugin installed twice. The full GUI
suite beyond the plugin and i18n files was not run either, since the change adds no
API call and no shared class or layout.

Rebased on 3ecc02b78 (nav-lamp only), then 73a12e8bf (wsl, no GUI files): after the rebase, plugin-clash and nav-lamp
pass in both engines (32/32 each) and the budget tests pass.
2026-10-31 21:31:09 +08:00
yetone 73a12e8bf6 wsl: a distro's agent folder that is a link is opened where it leads (#4502)
On Windows, adding a skill or switching RTK on for an agent in WSL failed
with `mkdir \\wsl.localhost\<distro>\root\.codex: Cannot create a file
when that file already exists` (linusxiong). In the distro ~/.codex is a
link to /mnt/c/Users/<user>/.codex. Through \\wsl.localhost Windows can't
follow a link the distro has: a mkdir of it says it exists, and nothing
below it can be made, written, read or listed. ggbdpq found and explained
the link (thanks); their patch, which takes that EEXIST as "there", wasn't
used: the writes below the link fail next (its test passed because a
symlink here is followed).

The fix, for every agent folder and every writer through \\wsl.localhost:
- The WSL probe asks `readlink -f` in the distro where each agent folder,
  its skills folder and the folders beside them lead (wslLinkPaths ->
  distro.Links; a $HOME that is itself through a link is left alone), and
  which drive each Windows mount is (win:/mnt/c C: -> distro.Drives).
- distro.open opens a path at or below a link where it leads: on a Windows
  drive, the drive's own path (C:\Users\<user>\.codex); elsewhere in the
  distro, through \\wsl.localhost again. native spells it back through
  the link, so the agent is told its own path.
- A link readlink couldn't resolve is never guessed at: distro.open
  errors, and the agent is unreached (Agent.Unreached: its notice says
  why; every field Set and Sync returns it).
- Writers: the agents' own files (place.join/place.open, every
  filepath.Join(at.home, ...) in internal/agent), the library's WSL
  targets (wslOpen/wslOpened; one "wsl" problem per agent and nothing
  written), RTK (rtkAt, rtkInstall checks agent.WSLOpen before its mkdir),
  the Sessions page's WSL reads (sessions.WSLHome.Open) and the Copilot
  CLI sign-in read (provider.CopilotWSLHomes -> CopilotWSLDirs).
- Not changed: magpie's image MCP server opens arbitrary paths an agent
  in WSL gives it the same way; filed as #4578. Links deeper than the
  probed paths (other than <agent dir>/skills) aren't resolved. A distro
  probed by an older magpie has no Links until probed again (each run).

Run:
- Real Windows box (xiaomi-gpu, distro magpie-desktop, sandbox
  /tmp/x4502/home with .codex -> /mnt/c/Users/yeton/runs/x4502-target/.codex,
  .claude -> /tmp/x4502/data/claude, .pi -> a missing folder), a throwaway
  Windows test running the real probe with that HOME: probe said
  link:.codex /mnt/c/..., link:.claude /tmp/x4502/data/claude, link:.pi,
  win:/mnt/c C:, win:/mnt/d D:. The old way, MkdirAll(\\wsl.localhost\
  magpie-desktop\tmp\x4502\home\.codex\skills\pdf) = "Cannot create a file
  when that file already exists" (the report's error). distro.open wrote
  SKILL.md to C:\Users\yeton\runs\x4502-target\.codex\skills\pdf and to
  \\wsl.localhost\magpie-desktop\tmp\x4502\data\claude\skills\pdf, both
  read back with cat in the distro through the links; .pi said "~/.pi in
  WSL magpie-desktop is a link magpie couldn't follow". Sandbox and target
  removed after.
- New tests with a fake distro whose ~/.codex and ~/.claude are links to
  /mnt/c/... that don't exist here, so, as through \\wsl.localhost,
  nothing below them can be made: TestWSLFolderIsALinkToC,
  TestWSLFolderLinkUnresolved, TestRTKWSLFolderIsALink,
  TestRTKWSLFolderLinkUnresolved (library); TestWSLProbeLinks (runs the
  probe script), TestWSLOpenThroughLinks, TestWSLAgentFolderIsALink
  (config and a Claude session read on C:), TestWSLAgentFolderLinkUnresolved
  (agent).
- Broken by hand: the library tests on the base (with a no-op
  FakeWSLDrives) fail with "mkdir .../home/me/.codex: file exists", the
  report's error; with ggbdpq's patch applied they still fail (the skill
  mkdir, and RTK's hook not written).
- mote: go build ./...; go vet of agent, library, sessions, provider for
  darwin, GOOS=windows (and linux for agent, library); gofmt -l clean;
  go test -timeout 45m ./internal/agent ./internal/library
  ./internal/sessions ./internal/provider: all ok.
- Windows (win-run): the same four packages. The new tests pass (the
  RTK ones skip: the fake distro runs sh). 32 tests are red, all already
  red at the base c63c2136b run on the same box, and filed (#4115, #2808:
  Hermes profiles, Codex keychain, Agy, desktop entries, ...); the Hermes
  ones fail alike on base and branch with -count=3.

- Rebased on origin/main 3ecc02b78 (it changed internal/agent): at this
  head on mote, go build ./..., go vet of the four packages for darwin,
  windows and linux, gofmt -l, go test ./internal/agent ./internal/library:
  ok.

Not tried: the full ./... suite; the GUI (no GUI change; the unreached
notice uses the existing Notice); a real Codex/Claude Code run against
the moved files in the distro.
2026-10-31 21:29:22 +08:00
yetone 3ecc02b78b agent: Claude Desktop is off magpie only when Desktop itself would be (dev_quj on X)
dev_quj on X: "magpie 一直提示Claude Desktop不经过magpie,我重启了依然还是
这个提示" — the Agents row said "已不经过 magpie:配置已变更" while
Desktop ran on magpie.

The check required deploymentMode "3p" in both Claude/ and
Claude-3p/claude_desktop_config.json. Desktop decides otherwise (m4 in
4.4212's and 2.7032's index.pre.js): with a 3p configuration applied it
starts in 3p when the profile has disableDeploymentModeChooser, whatever
deploymentMode says, and otherwise unless Claude-3p's file says "1p". The
Claude folder's deploymentMode is never read. And Desktop 4.4212 deletes
Claude-3p's deploymentMode itself: a stored "1p" with no claude.ai sign-in
is dropped at start (W5r -> "[custom-3p] deploymentMode written { mode:
undefined }") and Desktop relaunches in 3p on magpie. So a file left
without the key, by Desktop or another tool, was called off magpie, and
nothing magpie could do (Reconnect writes "3p" back) kept Desktop from
dropping it again.

desktop3p now asks Desktop's question with the applied profile (magpie's
or the user's for magpie's gateway). The appliedId, address and key
checks are as they were. appReads (the "restart Desktop" notice) reads
the same effective mode instead of the two files' words, so Desktop's own
write at start isn't a change to restart for.

Real Claude Desktop 4.4212.0 (macOS zip, on mote, sandbox
--user-data-dir, never the live config): three starts with magpie's
profile applied and Claude/ {} or "3p"; Claude-3p "1p" + chooser
disabled, "1p" + chooser not set, and {} — each ran in 3p with
apiHost=http://127.0.0.1:3425 in Claude-3p's main.log, and each left
Claude-3p's file without deploymentMode. The "1p", chooser-not-set case
started in 1p, logged "deploymentMode written { mode: undefined }" and
came back in 3p. An earlier start with both files "3p" kept them.

Run at the pushed head on mote (mote busy with other sessions' GUI and
gateway suites, so the touched package only, not the full suite):
go test -count=1 -timeout 45m ./internal/agent: ok
go vet, GOOS=linux go vet, GOOS=windows go vet ./internal/agent: ok
gofmt -l internal/agent: clean

Broken by hand: desktop3p put back to the old rule (both files "3p"):
TestClaudeDesktopModeAsDesktopReadsIt red on the dropped key, the Claude
folder's key gone, "1p" with the chooser disabled, and none with the
chooser on; TestClaudeDesktopChangedSince red too. Green with the fix.
TestClaudeDesktopMSIX and TestClaudeDesktopChangedSince's 1p cases now
turn the chooser on first, as Desktop needs for 1p to count.

Not tried: Windows' Desktop (MSIX or classic) and a real gateway request
from Desktop; a signed-in claude.ai cookie (Desktop keeps "1p" then,
which magpie says only with the chooser on); dev_quj's own files, so
this is the class the report is in, not their proven trigger. No other
desktop agent reads a mode the same way; Codex/WorkBuddy checks unchanged.
2026-10-31 21:11:45 +08:00
yetone ba7c890223 sidebar: the gateway's address at its foot is lit as by a torch too
The owner asked for the gateway address row under Settings to get the
torch light the page rows got in 841025836. It lights the same way:
brightest where the pointer is, falling off along the address, one row
at a time with the others.

- navlamp.js: #sideGw joins the rows the lamp follows.
- app.css: the address's resting ink (--muted) is the lit word's ground
  (--lo); its plain hover ink stands down while the lamp is on, as the
  other rows' does. Its hover ground is kept, as the page rows' is.

Tests: nav-lamp.test.cjs's page-row case gives the window a running
gateway (bootPrefs.sideGateway) and checks the address: lit after Settings,
Settings going out, brightest at the pointer's end by pixels, out off the
sidebar.

Run at this head (on 7e0fe83d4):
- nav-lamp, old-webkit, sidebar, side-toggle on xiaomi-gpu (Windows), both
  engines: 70 pass, 0 fail.
- sidebar-glide chromium is red 3 of 8 here and 3 of 10 on 7e0fe83d4 alone,
  10 of 10 at 841025836: a flake on main since, filed as #4577.

Broken by hand: #sideGw taken out of navlamp.js's selector, the page-row
case red; put back.

Not tried: the real app on Linux and Windows, the whole GUI suite.
2026-10-31 21:10:42 +08:00
yetone 3d063e34fd providers: the editor names a routing group listed alone that keeps a model from agents (hayden4608)
hayden4608 on Discord: with a provider's "Only through routing groups"
switched off, its models still weren't on the Agents page. Switching it
off does bring them back to every list (tried in a sandbox HOME on mote:
POST /api/provider/save unlisted:false, then /api/agent-models/codex,
/api/state's Codex options and provider.Catalog all list them; nothing
caches the old list). What still keeps them out, with the switch off,
is a routing group whose Model lists is "The group alone"
(Group.Unlists, #1783): its members leave every agent's list. The
editor said nothing of it, so the switch looked broken.

The provider's JSON now carries keptBy (provider.GroupKept: model ->
the names of the groups listed alone that keep it out, a signed-in
subscription's models excepted as Catalog excepts them), and the editor
says under the models, and on each chip, which group keeps which model
out and that its Model lists is changed on the Routing page. Words in
zh, zh-TW, ja and de. unlistedByGroups returns the groups' names now
instead of a bool; Catalog and Unlisted read it as before.

Not confirmed for hayden's own setup: the other reasons a model is
missing there are Codex's list in "Only models I pick" (the editor
already names that agent) and GitHub sync bringing the other device's
providers.json back (newer wins per part). The reply asks which.

Run on mote at e94fb18b8 + this change; at this head (rebased on c63c2136b,
which touched internal/provider/visible.go) the provider and gui packages
and the new GUI file ran again with the same results:
- gofmt -l internal/provider internal/gui: clean
- go vet -tags nogui (darwin, GOOS=linux, GOOS=windows) ./internal/provider ./internal/gui: ok
- go test -tags nogui -count=1 ./internal/provider: ok
- go test -tags nogui -count=1 ./internal/gui: one red, TestSettingsSaveKeepsWhatItDoesNotSend
  (SearchAll), filed as #4514, not this change
- GUI, Chromium and WebKit: unlisted-group-kept (new, en/zh/zh-TW/ja/de,
  1000 and 420px), agent-hides-editor, unlisted-models, group-unlists,
  i18n-keys: 67 of 68; the red is i18n-keys' "Unmarked", #4524, not this
  change
- core budget tests: ok (app.js 1,310,619 of 1,316,874, no raise)
Broken by hand: GroupKept's loop out of providerInfo makes
TestUnlistedGroupKeptSaid red (keptBy map[]); the old app.js makes the
new GUI file 0 of 20.
Not run: the full go test ./... (another session's full GUI suite was
on mote); no real Discord user's settings tried.
2026-10-31 21:00:55 +08:00
yetone c63c2136b2 agent: with Claude Code's own models hidden, a tier's model keeps its /model row and the switch rewrites settings.json at once (#4548)
Two gaps in the previous commit's replaceBuiltInOptions:

- writePicker leaves out the row of a model a tier is on at an effort
  (#1616), since Claude Code shows it as that tier's row. With
  replaceBuiltInOptions Claude Code drops the tier rows along with its
  built-in lineup (2.1.316: only the Default row and the picker's own
  stay), so such a model was in /model nowhere. While the switch hides
  Claude Code's own models, every model keeps its row.
- SetOwnModelsHidden saved the setting without catalog.Touched, unlike
  SetHiddenModels, so flipping the switch in the GUI left Claude Code's
  settings.json as it was until some other change re-synced it.

Tests: TestClaudePickerLeavesOutATiersModelAtItsEffort gains the
replace case (Terra on Haiku at max is listed); TestOwnModelsSwitchTellsTheAgents
counts catalog.Changed per flip.

Reviewed and run by yetone at the batch head over cac655c14 (this commit,
the four others from ggbdpq's #4495/#4548/#4512/#3260 patches and the
#4548 follow-up), on mote:
- gofmt -l clean; go vet ./... for darwin, linux (-tags nogui), windows;
  go build ./... for darwin and windows.
- go test -tags nogui -count=1 -timeout 45m ./...: every package ok but
  internal/gui, with two filed reds: TestSettingsSaveKeepsWhatItDoesNotSend
  (#4514), red alone at origin/main cac655c14 too, and TestColdTurnsTaken
  (#4510), red only in the full run. Rebased afterwards onto e94fb18b8,
  a usage-page change that touches none of these files.
- Windows (xiaomi-gpu): go test -run 'TestVSCode|TestClaudePicker'
  ./internal/agent ok. TestCopilotFolderFromAnIDEPluginIsNotTheCLI is red
  there at cac655c14 too (#1827).
- Broken by hand: each half reverted alone -> TestClaudePickerLeavesOutATiersModelAtItsEffort and TestOwnModelsSwitchTellsTheAgents red.
2026-10-31 20:54:37 +08:00
ggbdpq 509d8e7d14 agent: a portable VS Code reads its User folder in its data folder
YOUIMARK's Windows has Scoop's VS Code 1.143, a portable build: magpie
showed the editor, but its Dir stayed %APPDATA%\Code\User, which doesn't
exist — code.cmd on PATH was detection enough — so the provider, models
and settings.json magpie wrote went where the build never reads.

Before: vscodeUserDir always took the OS's place for the User folder,
%APPDATA% on Windows; only detection ever looked at the editor itself,
by its launcher alone, so any portable build was found and then read
and written in a folder it doesn't use.

Now: a build whose launcher has a data folder beside it is portable, as
VS Code itself takes a build for portable by that folder alone — a zip's
own data folder, or Scoop's, whose apps\vscode\current\data is the
persisted one, current a junction into apps\vscode. Its User folder is
data\user-data\User there: found, wired, connected and disconnected
there. The launcher is found as detection finds it, and a Scoop shim
stands for the launcher the .shim beside it names, which proc.Unwrap
doesn't read. Zoo Code, which keeps its settings in VS Code's User
folder, is laid out by the same function and follows it. An installed
build's launcher has no data folder beside it, and keeps the OS's place;
so does a portable build before its first run, whose launcher alone is
still detection enough, its writes then making the folder where it
reads. VSCodium portable is left as it was: its data folder is named by
its product.json, which no report asks after.

This is the other half of the branch the Copilot-launcher fix came from
(taken along with 6f435677c, since reworked); it shares no code with
that one — this half is only where a portable build keeps its User
folder, not what magpie takes a copilot launcher for.

Run at this head (parent 841025836):
- New TestVSCodePortableUserDir: an installed build with the launcher on
  PATH keeps the OS's User folder; with the data folder beside the
  program the build's Dir is data\user-data\User, it is detected before
  its first run has made the folder, connecting writes magpie's group in
  the data folder's chatLanguageModels.json and disconnecting takes it
  out. New TestVSCodePortableScoopShim: the same through scoop's shims
  folder, the .shim naming the launcher in apps\vscode\current\bin, and
  a shim with no data folder beside the launcher it names staying an
  installed build. Both are red with vscodeUserDir taken back to the
  OS's place ("the portable build's User folder is .../Application
  Support/Code/User", "Scoop's portable VS Code reads ...") and green
  with the change.
- go test -tags nogui ./internal/agent -count=1: green but for
  TestMothX, which fails the same without this change — this machine's
  PATH has a real mothx (fnm), which the test's LookPath finds.
- gofmt -l clean; go vet ./internal/agent for darwin, linux and windows;
  go build ./... for darwin and windows, and for linux ./internal/agent
  (the repo's linux build fails in wails's own code on this machine
  without this change too).

Issue: #3260
Generated-by: GLM-5.3-Flash (ZCode)

Reviewed and run by yetone at the batch head over cac655c14 (this commit,
the four others from ggbdpq's #4495/#4548/#4512/#3260 patches and the
#4548 follow-up), on mote:
- gofmt -l clean; go vet ./... for darwin, linux (-tags nogui), windows;
  go build ./... for darwin and windows.
- go test -tags nogui -count=1 -timeout 45m ./...: every package ok but
  internal/gui, with two filed reds: TestSettingsSaveKeepsWhatItDoesNotSend
  (#4514), red alone at origin/main cac655c14 too, and TestColdTurnsTaken
  (#4510), red only in the full run. Rebased afterwards onto e94fb18b8,
  a usage-page change that touches none of these files.
- Windows (xiaomi-gpu): go test -run 'TestVSCode|TestClaudePicker'
  ./internal/agent ok. TestCopilotFolderFromAnIDEPluginIsNotTheCLI is red
  there at cac655c14 too (#1827).
- Broken by hand: vscodeUserDir's portable branch off -> TestVSCodePortableUserDir and TestVSCodePortableScoopShim red. Checked against Scoop: extras/vscode.json puts appsscode
2026-10-31 20:54:37 +08:00
ggbdpq 6585315e32 gateway: a DeepSeek member's reasoning streams through once it has answered cleanly three times running (#4512)
c8f199695 holds a member's thinking back for a refusal after it, so
WorkBuddy's filter (plugins #540) never hands the agent a refused
reply's reasoning as if it were an answer. Held, though, DeepSeek group
members kept every request's whole thinking from the agent: its first
token landed only when the first answer delta did (#4512, with the
reporter's per-line SSE timings; direct connections were never held).

Claude's, GPT's and Gemini's thinking is still held whatever the member
has answered lately (#248). DeepSeek's now streams through as it comes
once the member has gone on from its thinking to an answer three times
running (thoughtCleanMost); one refusal takes the trust back, and a
content_filter stop with nothing said does too. The count is per
"<provider>/<model>", and #248's per-vendor split is why the trust is
DeepSeek-only: the held vendors refuse after thinking by design, the
one that hardly ever does is the one whose hold the agent keeps paying
for.

Tests: TestDeepSeekThinkingStreamsOnceTrusted (three clean thinking
replies, then reasoning deltas arrive before any answer delta) and
TestDeepSeekRefusalHoldsATrustedMemberAgain (a refusal re-holds the
next try) cover the trust and its withdrawal; the refusal-family tests
including TestDeepSeekRefusalAfterThinkingFailsOver keep the original
WorkBuddy hold intact.

Verification on the base 91ffe5429, macOS arm64, Go with pinned
GOFLAGS: 8 targeted hold/thinking tests ok; gateway package full
-tags nogui; gofmt, vet on darwin/linux/windows and builds on all
three platforms clean; pre-existing sandbox failures untouched.

Generated-by: GLM-5.3-Flash (ZCode)

Reviewed and run by yetone at the batch head over cac655c14 (this commit,
the four others from ggbdpq's #4495/#4548/#4512/#3260 patches and the
#4548 follow-up), on mote:
- gofmt -l clean; go vet ./... for darwin, linux (-tags nogui), windows;
  go build ./... for darwin and windows.
- go test -tags nogui -count=1 -timeout 45m ./...: every package ok but
  internal/gui, with two filed reds: TestSettingsSaveKeepsWhatItDoesNotSend
  (#4514), red alone at origin/main cac655c14 too, and TestColdTurnsTaken
  (#4510), red only in the full run. Rebased afterwards onto e94fb18b8,
  a usage-page change that touches none of these files.
- Windows (xiaomi-gpu): go test -run 'TestVSCode|TestClaudePicker'
  ./internal/agent ok. TestCopilotFolderFromAnIDEPluginIsNotTheCLI is red
  there at cac655c14 too (#1827).
- Broken by hand: thinkingShown back to !refusesAfterThinking(c.model) -> TestDeepSeekThinkingStreamsOnceTrusted and TestDeepSeekRefusalHoldsATrustedMemberAgain red in 1.5s (no hang). Not tried: a real DeepSeek member in a group. Trade-off kept: once trusted, a member's rare refusal after thinking reaches the agent once (nothing said) before it is held again; trust is per process and builds only from replies that report output tokens.
2026-10-31 20:54:37 +08:00
ggbdpq 2672ba429b agent: Claude Code's /model honors the own-models switch too (#4548)
The "show the agent's own models" switch filtered magpie's pickers
alone (agent.Picks, #1642): Claude Code's own /model rows stayed put,
because nothing magpie wrote for Claude Code looked at the switch —
while /model is fed by magpie all the same (modelPicker's rows are
writePicker's). raclen traced the whole chain (#4548).

writePicker now sets modelPicker.replaceBuiltInOptions (Claude Code's
own key: with it the /model picker shows only the listed rows) while
the switch is off, and drops the flag again when it is on, so the
whole picker is written either way. The Default row stays under both
settings: Claude Code keeps it as its own fallback.

Tests: TestClaudePickerOwnModelsSwitch writes a settings.json and
checks modelPicker carries the rows plus the flag with the switch
off, and the flag without it with the switch on.

Verification on the base 5d955a4d4, macOS arm64: agent package
-targets nogui; gofmt, vet on darwin/linux/windows and builds clean.
Claude Code's reading of the key is per its documented modelPicker
behavior (code.claude.com/docs, model-config); the Default-row
fallback shape is per the reporter's capture, not re-run here.

Generated-by: GLM-5.3-Flash (ZCode)

Reviewed and run by yetone at the batch head over cac655c14 (this commit,
the four others from ggbdpq's #4495/#4548/#4512/#3260 patches and the
#4548 follow-up), on mote:
- gofmt -l clean; go vet ./... for darwin, linux (-tags nogui), windows;
  go build ./... for darwin and windows.
- go test -tags nogui -count=1 -timeout 45m ./...: every package ok but
  internal/gui, with two filed reds: TestSettingsSaveKeepsWhatItDoesNotSend
  (#4514), red alone at origin/main cac655c14 too, and TestColdTurnsTaken
  (#4510), red only in the full run. Rebased afterwards onto e94fb18b8,
  a usage-page change that touches none of these files.
- Windows (xiaomi-gpu): go test -run 'TestVSCode|TestClaudePicker'
  ./internal/agent ok. TestCopilotFolderFromAnIDEPluginIsNotTheCLI is red
  there at cac655c14 too (#1827).
- Broken by hand: the replaceBuiltInOptions line dropped -> TestClaudePickerOwnModelsSwitch red. Not tried: a real Claude Code /model with the switch flipped (2.1.316's handling of the flag was read from its binary).
2026-10-31 20:54:37 +08:00
ggbdpq 7804dfbb03 gateway: drop the locked sampling fields for Kimi on Volcengine Ark too
Volcengine Ark's plans lock the sampling parameters of the Kimi models
they serve: any request carrying temperature != 1 is refused 400
"Volcengine Ark: `temperature` only 1 is allowed for this model"
(#4495, kimi-k3.1-pro / kimi-k3 / kimi-k2.8-preview at
ark.cn-beijing.volces.com/api/coding/v3), before any token is read —
clients that send their own defaults (Claude Code, Copilot) fail every
call, and a routing group spends its failover window on each try.

kimiLockedSampling already drops temperature and top_p for the locked
models on Moonshot's own endpoints (#1197), but its isKimi guard knows
only Moonshot's hosts and presets, so the same models behind an Ark
host went through with the fields. The refusal names the model ("for
this model"), not the path, and the preset's Agent Plan and pay-as-you-
go regions list the same kimi-kX.Y models, so the guard now also takes
isArk — the ark.<region>.volces.com check the draw and video code
already uses, which covers the preset's plans and a provider added by
hand — and kimiLockedSamplingModel keeps deciding per model, as it
already does for kimi-k2.5 and later, kimi-for-coding* and k3*. Ark's
other models (doubao, glm, deepseek, minimax) are untouched, as is
everyone not served by Moonshot or Ark.

Run: TestKimiLockedSampling in internal/gateway grew four cases (the
coding plan's chat and anthropic routes, an Ark model the server
doesn't lock, a provider added by hand on an Ark host): the three drop
cases fail on the unmodified code and pass with it, the keep case
passes throughout. go test -tags nogui ./internal/gateway ok (499s);
gofmt clean; go vet -tags nogui on darwin, linux and windows clean;
go build -tags nogui ./... on darwin, linux and windows ok.

Generated-by: GLM-5.3-Flash (ZCode)

Reviewed and run by yetone at the batch head over cac655c14 (this commit,
the four others from ggbdpq's #4495/#4548/#4512/#3260 patches and the
#4548 follow-up), on mote:
- gofmt -l clean; go vet ./... for darwin, linux (-tags nogui), windows;
  go build ./... for darwin and windows.
- go test -tags nogui -count=1 -timeout 45m ./...: every package ok but
  internal/gui, with two filed reds: TestSettingsSaveKeepsWhatItDoesNotSend
  (#4514), red alone at origin/main cac655c14 too, and TestColdTurnsTaken
  (#4510), red only in the full run. Rebased afterwards onto e94fb18b8,
  a usage-page change that touches none of these files.
- Windows (xiaomi-gpu): go test -run 'TestVSCode|TestClaudePicker'
  ./internal/agent ok. TestCopilotFolderFromAnIDEPluginIsNotTheCLI is red
  there at cac655c14 too (#1827).
- Broken by hand: guard back to !isKimi(p, to) -> three TestKimiLockedSampling subtests red (volcengine coding plan, its anthropic endpoint, a hand-added Ark host). Not tried: a real Volcengine Ark Kimi request.
2026-10-31 20:54:37 +08:00
yetone e94fb18b8f usage: a page's cells and the heatmap's days read strings where they were decoded (#2278)
partsOf, cellsBefore and heatDaysOf read each chunk through a chunkRows
that copied the chunk's whole string section first. What they keep is
unique's handles (a cell), a date made by Format and numbers (a day), so
the copy was thrown away chunk by chunk. They now read through
lentRows(), as newest and the Codex readers already do.

Run on mote:
- go test ./internal/usage/ -count=1 -timeout 45m: ok (40s).
- -race -count=3 on TestPartsReadStringsWhereDecoded,
  TestRowBufferKeptPastCollections, TestRequestCells*, *Heat*, *PageSplit*: ok.
- TestPartsReadStringsWhereDecoded (new): 8 packed chunks, 1.1MB of
  strings. With the three sites put back to `var rows chunkRows` by sed
  it is red: partsOf 1,188,672 bytes, cellsBefore 1,197,568, heatDaysOf
  1,187,616. Green with the change; the cells' names and the days' counts
  are right after the buffer was decoded over again.
- Real history copy (66GB, ~12k session files), magpie web in a sandbox
  HOME, heap profile 40s after start, two rounds each:
  unpackReusing 183MB / 174MB before, 106MB / 113MB after;
  partsOf 76MB / 78MB before, 55MB / 56MB after.
  A warm poll of every page reads cached parts and is unchanged.

Not tried: the Windows and Linux boxes (no OS-specific code).
2026-10-31 20:48:05 +08:00
yetone cac655c14f gateway: GET /v1/magpie/mcp lists magpie's own MCP servers that are on (ferock on Discord)
ferock on Discord: the community chat page's "use all of magpie's MCP
servers" gave a chat only the servers in library.json, never magpie's own
web search, image recognition or image generation. Nothing told an app
which of magpie's own servers are on, so the page couldn't add them.

GET /v1/magpie/mcp (OwnMCPPath, own_mcp.go) answers
{"servers":[{"name","title","path"}]} for the ones on now, each named
as its initialize names it: magpie-web-search while plugins/search serves
and something searches (canSearch), magpie-vision while a model sees
(seer: not Off), magpie-image while a model draws (drawer: not Off),
magpie-tools while plugins/tools serves and a plugin that is on gives a
tool (plugin.ToolsOn; a note that can't be read lists it). It holds no
secret, so a read-only gateway key may read it (readOnlyRoutes); it is
otherwise guarded as every /v1/magpie/* route is. It is in / "apis".
page-chat 0.1.7 (magpie-community/plugins) reads it in every route the
page takes its MCP list from (readMcp: the list, a chat's tools, a tool
call, the connection check). Documented in gateway-routing.md.

Run (mote, at e2a65cbc9 plus this change, before the rebase onto
2987f5e2b, which adds three commits in gateway/gui/provider that this
doesn't touch):
- gofmt -l: clean. go vet ./..., GOOS=linux go vet -tags nogui ./...,
  GOOS=windows go vet ./...: ok.
- go test -tags nogui -timeout 45m ./... in a sandbox HOME: 81 packages
  ok; internal/gateway ok. Two reds, neither in code this touches, both
  filed: internal/gui TestSettingsSaveKeepsWhatItDoesNotSend (SearchAll,
  #4514) and internal/update TestRelaunchOpenTriedAgain (#3881).
  The first run, at d6e111638, also had TestReadOnlyKeyEveryRoute red on
  the new route; it is in readOnlyRoutes now.
- At the pushed head (on 2987f5e2b): go vet ./internal/gateway and
  -run 'OwnMCP|ReadOnlyKey|ClientPath|ServingGates' ok.
- TestOwnMCP* (5 tests) red on the old code by hand: the route taken
  out, each answers 404.
- Real binary (go build -tags nogui, sandbox HOME, MAGPIE_ADDR
  127.0.0.1:3591, a fake vendor listing gpt-image-1 and gpt-4o): the list
  was magpie-image; tools/list on its path answered generate_image,
  generate_video, generation_result; with vision and imageGen "off" in
  settings.json the list was empty; a request with a foreign Origin got
  403.

Not tried: image recognition and web search listed by the real binary
(the fake vendor's gpt-4o wasn't known to see offline, and no search API
was set up; the unit tests cover both); a real vendor; the GUI (no GUI
change); Windows and Linux runs (vet only).
2026-10-31 20:37:19 +08:00
yetone 2987f5e2b7 gateway: a Chat usage's magpie_cache_unknown is read, as an Anthropic one's (#3991, #3979)
Trae CN users see cache read 0 / write 0 on every call. Trae's chat
token_usage stopped naming any cache count around 10-28 (modeyang's 786
trae-cn calls on 10-29 all at 0; plugins#434). opencode-trae-auth 0.2.26
now says magpie_cache_unknown on such a usage, as the Kiro plugin does,
but only aUsage read that flag: cUsage, which a Chat plugin's usage goes
through, dropped it, so the zero still counted as a 0% miss.

cUsage now reads magpie_cache_unknown into Usage.cacheUnknown, so the
route and the usage ledger mark the call's cache as unknown instead of a
miss. A counted 0 (prompt_tokens_details.cached_tokens: 0) stays a miss.
The flag is read, never told by chat(); a same-protocol reply is passed
through as it came, as Kiro's is on /v1/messages.

Test: TestChatCacheUnknownReachesTheRoute, with the plugin's Chat output
for chansee97's real token_usage (plugins#455): pi whole, pi streamed,
translated for Claude Code, and a counted miss.

Run (mote):
- go test -run 'CacheUnknown|CacheCounted' ./internal/gateway: ok
- broken by hand: the old chat.go fails 3 of 4 subtests (the counted
  miss stays green)
- go vet ./internal/gateway on darwin, GOOS=linux, GOOS=windows: ok
- gofmt -l internal/gateway: clean
- go test -timeout 45m ./internal/gateway: ok (641s), at base d6e111638 plus this change;
  rebased on d9845432f (4 commits, none in internal/gateway), where
  -run 'CacheUnknown|CacheCounted|Usage' ./internal/gateway: ok

Not tried: a real Trae CN account (none available), so whether Trae now
omits the cache fields or sends 0 is not confirmed; if it sends 0, the
call stays a 0% miss. Not run: the full ./... suite (the change is one
struct field in internal/gateway).
2026-10-31 20:35:12 +08:00
yetone d9845432f7 gui: a same-tagged answer is written twice, never held whole (#2278)
writeSame wrote each answer into a buffer to hash and send it, and kept
two such buffers between polls (answerLinger). The Sessions tab's stats
answers are ~6 MB each over a full history, so 12.5 MB of a warm start's
169 MB live heap was those buffers (heap profile, bytes.growSlice under
statsAnswer). Now write is given an io.Writer and called twice: once into
the hash for the tag, and once straight to rw (32 KB bufio) when the page
hasn't got that answer. statsAnswer encodes a part at a time into a small
buffer. The stats route still answers "same" from its kept tag without
encoding at all when nothing changed, so the second encode costs only on
a changed answer. answerBuffers, answerBuffer, keepAnswer go.

Run on mote (M5 Pro), from this tree:
- go vet ./internal/gui ok; gofmt -l clean.
- go test -count=1 ./internal/gui: FAIL only TestSettingsSaveKeepsWhatItDoesNotSend
  (#4514) and TestMainWindowCorners/macOS_26_SDK (#3949), both filed, both
  untouched by this change. TestStatsAnswerWritesWhatEncodeDid (bytes are
  the whole Encoder's) and the new TestSameAnswerNotHeldWhole pass.
- Broken by hand: writeSame's bufio sized 64 MB, TestSameAnswerNotHeldWhole
  red ("allocated 67117776 bytes for a 4194304-byte answer").
- Warm start on a copy of the owner's real history (11,925 Codex .zst,
  4,696 Claude .jsonl, 5,000 listed sessions), the page's 10 reads every
  5s, interleaved, load ~25-34:
    before (bb5eb83c3): footprint peak 267, 269, 274 MB; cpu 9.6-10.1s
    after:              footprint peak 255, 257, 258 MB; cpu 9.9-10.2s

Not tried: a cold start A/B (the buffers matter once polls begin).
2026-10-31 20:31:26 +08:00
yetone 3561697a40 provider: WorkBuddy's mover min is 0.2.7 (plugins #561, #563)
0.2.7 lists a "none" level for deepseek-v4.1-flash and -sg. WorkBuddy
takes it (0 reasoning tokens) though its config calls them onlyReasoning
(#563). On copilot.tencent.com, deepseek-v4.1-flash's context is capped
at 100000 tokens, the reporter's literal "prompt is too long" limit (#561).
npm shows 0.2.7 (npm view --prefer-online, at landing).

Run at e2a65cbc9 plus this change: go test -timeout 45m ./internal/provider/ on
mote: ok (214.9s). gofmt -l: clean.
Not run: the full suite. This is a one-line constant, and the provider
package holds the mover's tests.
2026-10-31 20:28:38 +08:00
yetone e2a65cbc9b dsh: a start on a found group's old id moves onto the id its route lists (zyh6036 on X)
zyh6036 on X: DeepSeek Harness Desktop showed no model after magpie
turned dsh on and the app restarted, while the profile's patch file was
full of magpie's gateway.

Cause: a dsh start (agent-default-model) magpie had set to a found
routing group keeps the id the group had then, group/auto-<slug>. Since
81a24cf8f the group is listed as auto/<model>, and that is the only id
magpie's routes list. dsh looks up the start by route and id, finds
nothing, and shows "Select model" with nothing picked. The owner's live
desktop profile was in this state: the start was
"group/auto-gpt-6-sol" and the route listed auto/gpt-6-sol.
renameFoundGroups never reached it, because it moves only values that
applied.json records, and there was no dsh record there.

Fix: dshStartOnItsRoute already moves a start onto the route its model
is on now. It now also moves a start whose id magpie no longer lists it
by (provider.PublicRef for a found group, provider.RenamedRef for a
renamed provider) onto the id the route lists. The effort and the other
keys in the entry stay. It runs on every route write, in every profile
(desktop, web, CLI) and in the home layer, so KeepDshWired repairs an
existing install within a round. The fix is not OS-specific.

Run at this head (rebased on bb5eb83c3), on mote (macOS) through mote-run:
- go test ./internal/agent ./internal/provider -count=1 -timeout 45m:
  ok (284s, 164s)
- go test ./internal/agent -run 'Dsh|FoundGroup|Drift|Keeps': ok
- GOOS=windows go vet ./...: ok
- GOOS=linux go vet ./internal/agent ./internal/provider: ok
  (a GOOS=linux vet of ./... from macOS stops in wails' cgo files)
- go vet ./internal/agent (darwin): ok
- gofmt -l: clean
The full suite was not run, so that another session's suite on mote
isn't held up (one full suite per machine). Only internal/agent changed.
The -run 'Dsh|...' subset ran before the rebase.

Broken by hand: with dsh.go at HEAD,
TestDshStartOnAFoundGroupsOldIdMovesOntoItsId fails, and the start
stays "group/auto-pro" in the web profile.

Real app: DeepSeek Harness 0.2.1-rc.5 on mote, each run in a sandbox
HOME and DSH_HOME:
- Fresh wiring shows magpie's models, whether the app was opened first
  or magpie wrote first.
- A copy of the owner's live desktop patch: every route is listed, but
  the seat reads "Select model".
- The same copy with the start as the fix writes it (auto/gpt-6-sol):
  the seat reads "GPT-6 Sol · routing group High", ticked in the picker.

Not tried:
- Running the fixed magpie binary itself against that copy. The unit
  test covers the magpie side.
- Windows' desktop app.
- Whether zyh6036's install was in this state. A store or key that
  doesn't resolve also empties the list (seen with no key at all), and
  their reply will say which.
2026-10-31 20:18:40 +08:00
yetone bb5eb83c3e gui: the Sessions list goes out a row at a time, never held whole (#2278)
writeJSONRows built the whole answer in a buffer to hash it and send it.
Over the owner's full history (16,600 sessions, 5.8 MB list) that buffer
grew to 25 MB, was kept between polls, and was 25 MB of a warm start's
183 MB live heap. Now a first pass encodes each row into one small
buffer for its hash and the answer's tag. What is sent is encoded again,
straight to the ResponseWriter through a 32 KiB bufio.Writer, and a delta
holds only the rows the page hasn't got. The bytes and the tag are the
same as before, so the page's delta and "same" answers don't change.

Run on mote (macOS 27), real history copy (~16,600 session files):
- warm start, 75 s of poll.sh (what an open window asks every 5 s):
  - before (v0.1.2382): steady footprint 240-265 MB, live heap 183-193 MB;
  - after: steady footprint 216-233 MB, live heap 168-178 MB.
  - The phys_footprint peak is about the same (257-267 vs 264-289 MB over
    3 interleaved pairs): a poll's own spike still sets it.
- /api/sessions from each binary on the same history: the same tag
  06a661d3…, the same sha256 of 5,842,606 bytes, X-Magpie-Same on its
  tag, and the full list for an unknown tag.
- TestJSONRowsNotHeldWhole is new: red on the old writeJSONRows (9.5 MB
  allocated for a 4.2 MB answer), green now. TestWriteJSONRowsWritesWhatMarshalDid
  (bytes and delta) is green.
- go test ./internal/gui: ok except three reds that are already filed.
  TestSettingsSaveKeepsWhatItDoesNotSend (#4514) and TestMainWindowCorners
  (#3949) are red the same way with the old api.go in the same copy.
  TestColdTurnsTaken (#4510) was red in the full run and passed 3 of 3
  alone.
Not run: the GUI (Playwright) suite. app.js isn't touched and the
answer's bytes are the same.
2026-10-31 20:15:15 +08:00
yetone d6e1116380 codex: each end of the Codex app's app-server says why, and list flaps are guarded (#4550)
70d50254c (v0.1.2387) took the model list out of the route the Codex
app's app-server is ended on. The effort the app saves on each pick
went into the catalog, the next sync rewrote it, and the route's hash
of the catalog changed, so the app-server was ended every few minutes
and the ChatGPT app read that as a crash (goto_nozomi on Discord,
ggbdpq on #4550). This adds two things on top of that.

- codexAppStep logs each end with what made the app-server stale:
  "codex: ended the Codex app's app-server [pid] for the app to start
  another: <why>". The reason is the ChatGPT account switched, the
  route changed, or the used-up takeover. Before this a successful end
  logged nothing, so a reported crash couldn't be put down to magpie or
  to the app (ggbdpq asked for it on #4550).
- TestCodexAppRouteKeepsThroughListFlaps runs in a sandbox HOME
  through SyncCatalog. A relay's list drops a model and has it back,
  the catalog is re-ranked in another order with other descriptions,
  and the catalog is caught half-written. Each must leave the route as
  it was. 70d50254c's tests cover an effort pick and a rename.

Product call, as 70d50254c made it: a list change alone never restarts
the app-server, not even once Codex has been idle for a while. The
restart is what crashes ChatGPT when an MCP server is slow, and idle
time doesn't make it safe. The new list is read at the app's next
launch, or on the Agents row's Restart (StaleCopies). Where requests
go (model_provider, openai_base_url, the magpie table's base_url,
requires_openai_auth, the used-up takeover) still restarts it, as
TestCodexAppRouteFollowsConnectAndDisconnect and
TestCodexAppRouteFollowsOpenAIAuth hold.

Run (mote):
- go vet, GOOS=linux go vet and GOOS=windows go vet of ./internal/agent
  and ./internal/provider: clean.
- go test -count=1 -timeout 45m ./internal/agent ./internal/provider on
  e484b1e93: ok. Rebased onto 5cc2eea2f (dsh in internal/agent), then
  go vet and go test -count=1 -timeout 45m ./internal/agent again, and
  -run CodexApp ./internal/provider: ok.
- gofmt -l on both packages: nothing.

Broken by hand:
- TestCodexAppRouteKeepsThroughListFlaps at 70d50254c^ (the route
  still hashed the catalog) is red three ways: a model dropped (:119),
  another order (:141) and a half-written catalog (:147) each changed
  the route.
- With the used-up reason taken out of codexAppStep,
  TestCodexAppEndSaysWhy is red ("... start another: where Codex's
  config sends it changed", want "used up").

Not tried:
- The real ChatGPT/Codex app. Nothing here changes when the app-server
  is ended, only what is logged.
- The whole ./... suite and the GUI suite. Neither package touches the
  GUI.
- Whether goto_nozomi's crashes stop on v0.1.2387. #4550 stays open
  for them to say, with the new log line asked for if any crash is
  left.
2026-10-31 19:55:12 +08:00
yetone 1dc22a37c5 gui: a custom provider's icon from an image URL, or its name's letters (usrname1833)
usrname1833 on Discord: many sites serve no {HOST}/favicon.ico, so a custom
provider's icon came out wrong or missing, with no way to give it one.

The provider editor's icon row now has Get icon, a pull-down that opens the
app's own menu (no native select) headed Icon:
- Automatic: the site's icon from the base URL, as before.
- Image URL…: a url box under the row, focused; Enter fetches the address,
  Escape puts it away and gives focus back to Get icon.
- Letter icon: the name's first letters on a coloured tile (letterIcon).

POST /api/icons/url (provider.IconFromURL) fetches the typed address the way
a favicon is fetched: guardClient (public addresses only), iconURL (https,
public host, no userinfo), fetchIcon's 15s timeout, MaxIcon 1 MB and the
type sniffed to PNG/JPEG/GIF/WebP/ICO/SVG. An address that can't be used
gives the letter tile with a warn note saying why, and the box stays for
another try. The old From the website button and its two strings are gone;
eight new strings in zh, zh-TW, ja and de. app.js +1,484 bytes to
1,309,847 (budget 1,316,874), core 1,534,839 (1,539,856); no budget raised.

Run at this tree (rebased on origin/main e484b1e93), on mote:
- gofmt -l clean; go vet ./internal/provider ./internal/gui on darwin,
  linux (nogui) and windows; go build ./..., linux nogui and windows builds.
- go test ./internal/provider: ok (TestIconFromURL new: a PNG kept; HTML,
  404, over 1 MB and a stalled server each give the letters with why; http,
  loopback, localhost and userinfo addresses refused; an empty name takes
  the base's site label).
- go test -run "Budget|Icon|Favicon|Provider|Settings" ./internal/gui:
  TestCoreScriptBudget ok; TestSettingsSaveKeepsWhatItDoesNotSend red, the
  same at a clean e484b1e93 (#4514).
- node --test icon-url (new), models-add-and-icons, i18n-keys: 27 of 28.
  icon-url is Chromium and WebKit x 420 and 1100 x en, zh, zh-TW, ja, de,
  20 of 20 (menu, posted bodies, warn note, Escape focus, no scroll, no
  spill at 420, Save sends the icon). The one red is i18n-keys' "Unmarked"
  in plugins/routing, the same at a clean e484b1e93 (#4524).
Screenshots of the menu and the warn note checked in both engines.

Broken by hand: no letter fallback on a failed fetch -> TestIconFromURL red
('"" isn't stored'); the exported path skipping iconURL -> red for all four
refused addresses; icon-url.test.cjs on main's app.js and i18n.js -> 0 of
10 in Chromium (no Get icon).

Not tried: a real image address on a live site from the built app, and the
whole GUI suite (mote was running another session's full suite).
2026-10-31 19:54:28 +08:00
yetone 5cc2eea2fe dsh: a dsh CLI that has booted no profile yet is wired in its web profile, not config.yaml (liby233)
liby233 on Discord: in WSL magpie wired dsh in ~/.dsh/config.yaml, and dsh
saw magpie's models only once they were written to its settings.yaml.
With no ~/.dsh/profiles, dshAt fell back to the "pre-0.1.5" config.yaml.
No dsh on npm reads that file. 0.0.1-rc.1 (the first), 0.0.1-rc.5,
0.1.0-rc.8, 0.1.1-rc.1/rc.2, 0.1.2-rc.1, 0.1.3-alpha.2 and 0.2.1-rc.5 all
boot $DSH_HOME/profiles/<name> (grepped from their npm tarballs). A dsh
makes no profile until one is first booted, so a fresh CLI install,
in a distro or not, was wired in a file that nothing reads.

- With no profile, and a dsh that is not from before profiles, magpie
  writes profiles/web/cordis.patch.yml as dsh's template, as it does
  for Desktop (#2279). dsh's initProfile adds package.json,
  pnpm-workspace.yaml and cordis.yml next to it and keeps the file.
- "Before profiles" is judged by the CLI's version where it is known
  (locally from its package.json; in a distro the WSL probe now asks
  dsh --version). Otherwise config.yaml is used only when it holds an
  entry that isn't magpie's. That keeps the legacy path for a genuinely
  old dsh.
- The sync carries a magpie model already wired in config.yaml (the
  reporter's state) into the profiles and drops magpie's entries from
  config.yaml. It does this whether or not dsh has since booted a bare
  web profile, and only where no profile has a model or wiring of its
  own.
- Disconnecting before dsh ever booted the web profile removes what
  magpie made, as for Desktop.

Tests: TestDshCLIWithNoProfileYet and TestDshConfigYamlCarriedToProfiles
(new), plus wslMore's dsh row, now profiles/web. All three are red on the
old dsh.go: "names .../.dsh/config.yaml, not the web profile's patch
list", and the web profile is left as dsh's bare template after the sync.
Tests pin dshVersion, so a dsh on the test machine decides nothing.

Run (go test -timeout 45m, logs teed and grepped):
- gofmt -l internal/agent: clean. go vet ./internal/agent on darwin,
  GOOS=linux and GOOS=windows (mote): ok.
- go test -run 'TestDsh|WSL' ./internal/agent: ok on mote (macOS),
  magpie-desktop (WSL Ubuntu 24.04, nogui) and xiaomi-gpu (Windows 11).
- Full suite `go test ./...` on mote at this change on origin/main
  8680ffa41: 82 packages ok; internal/gui red only in
  TestSettingsSaveKeepsWhatItDoesNotSend (#4514) and
  TestMainWindowCorners/macOS_26_SDK (#3949), both filed before this and
  in code this change doesn't reach.
- Rebased again onto origin/main 70d50254c (it changed internal/agent's
  new_session_effort and rename_group tests). At this pushed head: vet
  (darwin, linux, windows) ok, and internal/agent, internal/cli ok;
  internal/gui has the same two reds and no others.
- Rebased once more onto e484b1e93, which touches internal/provider only.
  At that head (the pushed one): go build ./..., go vet internal/agent and
  internal/provider, and go test -run 'TestDsh|WSL' ./internal/agent all
  ok on mote.
- Real dsh 0.2.1-rc.5 from npm in magpie-desktop, in sandbox HOMEs under
  ~/dshprobe (never the live ~/.dsh), with this commit's CLI built there
  (nogui):
  A. Empty HOME, `magpie dsh magpie/relay/glm-4.6`: only
     profiles/web/cordis.patch.yml was written, holding llm-pi-ai's
     magpie route, agent-default-model and web-search-deepseek.
     `dsh --profile web --dump-config` shows llm-pi-ai baseURL
     127.0.0.1:3425/v1 and agent-default-model relay/glm-4.6. dsh added
     package.json, pnpm-workspace.yaml and cordis.yml and kept magpie's
     entries. `magpie dsh default` then left dsh's bare template.
  B. origin/main's CLI wired config.yaml (the reporter's state). The
     dump showed no magpie route. `dsh --profile web --dump-config`
     booted web, then this CLI's `magpie sync` moved the route and model
     into profiles/web and emptied config.yaml, and the dump showed them.
  C. Wired and never booted: `magpie dsh default` removed profiles/.
Not tried: the reporter's own machine and dsh version, a running
`dsh web` session picking the model up live, the desktop app, and a
pre-npm dsh that reads config.yaml (none could be found).
2026-10-31 19:50:39 +08:00
yetone e484b1e936 provider: an account Codex holds in another of its folders can be removed in magpie (charliepu)
charliepu on Discord (Windows), after v0.1.2385: the account that read no
allowance couldn't be removed. Remove answered "<email> is signed in to
Codex in C:\Users\charl\.codex-db-backup-20260803: sign it out there
(CODEX_HOME=... codex logout) to remove it". That folder is a backup no
Codex runs in. appdir.CodexHomes finds it by name (".codex*" holding an
auth.json), and rememberLogins read its account back at every look, so
forgetLogin refused rather than have it come back.

Now Remove forgets the account and sets that folder's sign-in aside in a
record of magpie's own (codex-homes-removed.json: the folder to a sha256
of its refresh token, or of its access token when it has none).
codexHomeLogins passes over a folder while it holds that sign-in. The
folder's files are left as they are: nothing in it is written, moved or
deleted. A sign-in made
in that folder again (Codex run there, a new token) isn't named by the
record, and is listed again with no step of the user's. With the record
unreadable, which sign-ins were removed is unknown, and no other folder's
account is read that time (accounts saved already stay listed).

Not done: treating ".codex-db-backup-*" folders as not Codex homes by
name. They are found by the same rule as ~/.codex-work, and their
sessions/ are still read for Sessions and usage as before; a name rule
would guess at what a user's folder is for. Removing is the user's own
answer, and works for any such folder.

Run at this head (origin/main 70d50254c plus this change; the doc line
added after):
- mote: go test -timeout 45m -count=1 ./internal/provider ./internal/appdir: ok (provider 142s;
  135s at the earlier base e90a635a9)
- mote: GOOS=windows and GOOS=linux go vet ./internal/provider: ok
- xiaomi-gpu (Windows 11, win-run): go test ./internal/provider -run
  'TestCodexHeldFolderAccountRemoved|TestCodexOtherHome|TestCodexHeldInOtherFolder':
  all four pass
- gofmt -l internal/provider: empty

Broken by hand, each red:
- logins.go as on main: TestCodexHeldFolderAccountRemoved fails with the
  "codex logout) to remove it" refusal, and so does
  TestCodexOtherHomeAccountReadsQuota (its last check pinned the refusal;
  it now expects the removal to go through).
- codexHomeLogins ignoring the record: "removed, then read back from the
  backup folder".
- an unreadable record read as empty: "with the record unreadable, the
  removed account came back".

docs/subsystems/providers-accounts.md's "Codex's other folders" row
said such an account couldn't be removed; it now says what Remove and
v0.1.2385's Sign in again do.

Not tried: the real app on Windows with a real backup folder (the test
runs on Windows with a sandbox HOME); a real account. No GUI change: the
row's Remove posts login/forget as before, which now goes through.
2026-10-31 19:42:52 +08:00
yetone 70d50254cb codex: a change to the model list alone no longer ends the Codex app's app-server
The Codex app crashed and relaunched every few minutes (indekkusu141209
on X, #4550: 08:06, 08:12, 08:26).

Cause. KeepCodexAppOnItsProvider ends the app's app-server whenever
codexAppRoute changes. Since ca8a6f346 (lucis0116 on X) the route held a
hash of the bytes in the catalog that model_catalog_json names. The
ChatGPT app takes an ended app-server as a crash. Those bytes change far
more often than where requests go:

- Each model's default_reasoning_level follows config.toml's
  model_reasoning_effort (codexcat.ModelDefault, Creat.wu on Discord).
- The Codex app writes that key on every effort pick, and on a switch to
  a model with other levels. So does magpie's settle() when a pick moves
  the effort.
- The next SyncCatalog, set off by things like a plugin token refresh or
  a providers.json save, rewrote the catalog. 3s later the route had
  changed, and the app-server was ended once idle.

The route doc's own promise, "nothing the Codex app writes itself is in
route", was broken through the catalog.

The repro was in a sandbox HOME, not the live ~/.codex. A throwaway
gateway test diffed CodexDesktopCatalog's bytes:
- Two passes with nothing changed: same bytes.
- A model pick: same bytes.
- models_cache.json refetched with a new fetched_at/etag: same bytes.
- model_reasoning_effort low -> high: different bytes.
The new agent tests below show the same for magpie-models.json, and the
old route moved with it.

Change. The route is where requests go, and only that:
model_provider, openai_base_url, magpie's base_url and
requires_openai_auth, and AppOut. model_catalog_json and the catalog's
content are out, and codexCatalogTag (codex_app_route.go) is gone. A
list-only change (a provider renamed, a model added, an effort picked)
restarts nothing. The app reads the new list at its next launch. The
Agents row already shows a Codex app on an older list, with its Restart
(StaleCopies). Its digest compares slugs and visibility, so an effort
pick doesn't flag it. No new UI.

The effort in the catalog is kept. It is the Creat.wu fix, and with the
restart decoupled, a rewrite of a file the app reads only at start costs
nothing.

Trade-off: a provider renamed or a model added in magpie shows in a
running Codex app only after it is reopened, or after the Agents row's
Restart. Before this commit that happened on its own, which was
lucis0116's ask.

Siblings, all read:
- RestartCodexApp (Agents row), RestartSwitchedCodexApp (switch notice,
  46aa7e6b8) and RestartCodexAppWhenIdle (uninstall) are user-started or
  a real route change. None reads the catalog. Unchanged.
- KeepCodexDaemonCurrent restarts the CLI's managed daemon only with no
  codex session on it, on the slug digest. That is not the desktop app.
  Unchanged.
- No other agent hashes its catalog into a restart.
- zhangjian94cn's fix/4243-codex-lifecycle-boundary takes away all of
  magpie's restarts. That goes further than this commit, and no code was
  taken from it. #4243 (aresxu8866-hue) asked for the catalog to count
  only when it is magpie's, which this commit supersedes.

Tests:
- TestCodexEffortPickKeepsTheAppRunning (new): the reporter's case. An
  effort saved as the app saves it, then SyncCatalog. The catalog
  changes and the route does not.
- TestCodexAppRouteIgnoresARename replaces
  TestCodexAppRouteFollowsTheCatalog, whose guarantee is now reversed.
- Broken by hand: both new tests run on the old codexAppRoute are red
  ("an effort picked in the Codex app changed its route", "a provider
  renamed changed the Codex app's route"). Green with the change.

Run at this head (5b0bb1349's tree, rebased on e90a635a9), on mote:
- go test -tags nogui -count=1 -timeout 45m ./internal/agent
  ./internal/provider: ok, ok. The same before the rebase.
- gofmt -l .: nothing.
- go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows
  go vet ./..., go build ./...: ok. That run was before the rebase; vet
  on agent and provider was run again after it.

Not run: the full go test ./... suite. Another session's full suite held
mote, and the owner's rule is to ship without holding for it; it follows
after the push. Not tried: a real ChatGPT/Codex desktop app. Nothing on
the ChatGPT side was changed or measured (the MCP handshake ggbdpq
traced). docs/subsystems/agent-wiring.md was updated.
2026-10-31 19:39:38 +08:00
yetone b9e5bc6cb3 gui: Rex is a session terminal, opened through its rex CLI (#4565)
Rex (com.superlogical.rex) claims no .command file, so Launch Services
never listed it and `open -a` can't hand it a script (StringKe).
Sessions' terminal list now offers Rex when its CLI is found: a native
`rex` on PATH, or one inside a Rex*.app in /Applications or
~/Applications (Rex puts rex on PATH only in its own terminals). Perl's
Rex installs a script named rex too, so only a Mach-O or ELF program
counts. Resume, carry and an agent's Open then run
`rex run --label <title> -- /bin/sh -c '<command>; exec login shell'`:
no shell parses the label or the command on the way. With no session
to add a tab to (exit 3) it runs `rex new`; with Rex's server not
running (exit 4) the error says to open Rex. Rex is then brought
forward with `open -b`. The GUI already lists s.terminalApps, so no
JS changed. reference.md's Session terminal says it.

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

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

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

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

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

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

Not tried: a real Claude or Codex account, or the CLI command end to
end; the tests use sandbox fakes under a test HOME. Nothing here
touches ~/.claude or the Keychain.
2026-10-31 19:35:16 +08:00
yetone e90a635a9a provider: a Codex account held in another Codex folder offers Sign in again when its refresh is refused (charliepu)
charliepu on Discord (#general 1566029465107173518, Windows): a ChatGPT
account whose sign-in had lapsed had no button to sign in again in the
Providers editor. The account was one Codex keeps in another of its
folders (CODEX_HOME=C:\Users\...\.codex-db-backup-...). OpenAI refused
its refresh, but renewSaved only wrapped the refusal in "run CODEX_HOME=...
codex login", and codexSignInRead skipped marking it: a saved account's
refused refresh is marked by savedRefreshFailed, which never runs for a
folder-held one. So the row never got a lapse, and the GUI's Sign in
again (renderAccounts' signedOut, SIGN_IN_GONE) never showed.

- logins_on.go: renewSaved wraps such a refusal as codexHeldRefusal and
  names no command to run.
- login_usage.go: codexSignInRead marks a codexHeldRefusal signed out
  (markRevoked), as it does Codex's own, so the row reads "Sign-in
  required" with Sign in again, which runs magpie's Codex sign-in for
  that user (startSignIn), the flow every other revoked Codex account uses.
- signin.go: addLogin writes the new tokens back to the Codex folder that
  holds the account (codexHeldFolder, saveCodexLogin) and clears its gone
  mark, or the next look would read the dead tokens back over them.
  ~/.codex/auth.json is not touched.
- account.go: codexRefresh's failure says "sign in to this account again",
  not "run codex login".
- chatgpt_api.go (sibling): a ChatGPT API account's kept lapse is listed
  on its row too, so it gets the same Sign in again.

No GUI change: the row already shows Sign in again for a Codex lapse
(revoked-signin-account.test.cjs covers it); the backend never set one.

Run at origin/main 4f00a32ff plus this change; rebased after onto
8680ffa41, which touches internal/gateway only (not run again):
- mote: go test -timeout 45m -count=1 ./internal/provider: ok (114s)
- mote: GOOS=windows and GOOS=linux go vet ./internal/provider: ok
- gofmt -l internal/provider: empty
At the earlier base 0379f2610 (mote rebooted mid-run, so the rest went
to the WSL box magpie-desktop):
- WSL: go vet ./internal/provider (linux, windows, darwin): ok
- WSL: go test ./internal/provider ./internal/gateway: ok (gateway 488s);
  ./internal/gui doesn't build there (no webkitgtk-6.0 dev package)
- mote: go test ./internal/gui: two reds, both filed and untouched
  here: TestSettingsSaveKeepsWhatItDoesNotSend (#4514) and
  TestMainWindowCorners/macOS_26_SDK on macOS 27 (#3949)
- WSL, Playwright 1.62.0, Chromium and WebKit, every language, 420 and
  1100 wide: revoked-signin-account and codex-signout pass; i18n-keys
  passes except "a plugin's words are its own", the known red #4524
  (plugins/routing "Unmarked")

Broken by hand, each red with the new tests:
- codexSignInRead without the codexHeldRefusal exception:
  TestCodexHeldInOtherFolderSignedOutThenSignedInAgain fails "the row
  isn't signed out, so it has no Sign in again".
- addLogin with held = "": the same test fails "the new sign-in didn't
  reach the account's Codex folder".
- siwcLoginList without the saved lapse: TestSIWCLapsedListedOnItsRow fails.

Not tried: a real lapsed account, on Windows or anywhere (the refusal is
a fake token endpoint answering 400 invalid_grant); a real OpenAI
sign-in written back into a CODEX_HOME folder; the full ./... suite.
Not changed: codexTokenAsKept and codexTokenRenewing still say "run codex
login" when a folder has no access token at all (Codex itself signed out,
not a refused refresh).
2026-10-31 19:26:55 +08:00
yetone 8680ffa419 claude bridge: a caller's environment in a message is named by its folder, not as the last one given
packinggoods on Discord, a third time: a Mac Claude Code through a
Windows magpie's Claude subscription (remote-magpie/claude/
claude-opus-5-5) is still told to use PowerShell. The model sees the
Mac client's environment (darwin, zsh, /Users/...) and then a later one
from the Windows host (win32, PowerShell, C:\...\magpie-claude-work,
Windows 11), and follows the later one.

d77da5bff told such a caller's run "of the environments given in this
conversation, the last one given is the one every tool runs in", on the
premise that the run's own environment always comes first. It doesn't.
Captured from the real claude 2.1.316 with --model claude-opus-5-5
(sandbox HOME and CLAUDE_CONFIG_DIR, fake key, a local capture server
that answers 400): the run's own environment is a {role: "system"}
message after the run's first user message, so after everything magpie
tells the run, the caller's environment included. The same holds with
--system-prompt-file and with --exclude-dynamic-system-prompt-sections
(that flag moves only the memory section into the first message).
Claude Code has no flag or variable that leaves the section out
(--help, and the strings of the 2.1.316 binary:
CLAUDE_CODE_FORCE_MID_CONVERSATION_SYSTEM only forces the message
form), and 1f03d7546 saw it in the first message with 2.1.312, so its
place depends on the version and the model. The note pointed the model
straight at the Windows host.

Now envTurnsNote names the caller's environment by the working
directory it gives (Request.envDir, from clientNamedWorkPlace): "the
one whose working directory is <dir> is the one every tool runs in. Any
other one describes a computer no tool runs on: don't take a platform,
shell or path for a tool call from it." It holds whichever comes first.
It names no app and no vendor; the folder is the caller's own, already
in the conversation. The other notes (caller naming its folder in its
instructions, caller naming none) don't depend on order and are
unchanged. Nothing else of the request changes: no flag, header, env or
Claude Code prompt text.

Test: TestClaudeCallerEnvironmentInAMessageIsNamedByItsFolder (was
...IsTheLastGiven), lean off and on, now requires the folder-named note
and no "the last one given". On origin/main's claude_subscription.go
and ir.go it is red (mote-run, FAIL).

Run (mote-run, at this change on 0379f2610; rebased onto 4f00a32ff, which touches only GUI budgets): go test -timeout 45m -count=1
./internal/gateway ok (636s); go vet ./internal/gateway for darwin,
windows and linux (-tags nogui) ok; gofmt -l clean.
Not tried: a real model turn from a Mac client through a Windows
gateway (no Claude sign-in on xiaomi-gpu), so whether the model now
stops writing PowerShell is not measured. The full ./... suite was not
run (mote had just rebooted); only internal/gateway changed.
2026-10-31 19:25:17 +08:00