Commit Graph
74 Commits
Author SHA1 Message Date
yetone 3cabaab54f update: the install-folder check removes only folders it made, and refuses a folder it can't look at
Installable (the Windows install-location dialog's check) walked up from
the chosen folder to the first one exists() said was there, and removed
the topmost one below it with os.RemoveAll. exists() was os.Stat == nil,
so a folder whose Stat failed for any other reason than "not there"
(access denied, a share that doesn't answer) counted as one the check
had made, and was removed with everything in it, up to a drive root.

Now:
- present(p) tells "there", "not there" (fs.ErrNotExist only) and
  unknown apart; statPath is os.Stat, swapped by tests.
- Installable refuses with "can't tell whether X is there" when any
  folder on the way is unknown, before making anything. It makes the
  missing folders one by one with os.Mkdir, records only those it made
  (one made by someone else meanwhile, ErrExist, isn't recorded), and
  removes them deepest first with os.Remove, so nothing it didn't make,
  and no folder that got content, is removed.
- settle's "is magpie.exe there" before installFresh (which renames
  over to) refuses too when the answer is unknown; the download runs on.
- The other exists() callers were checked: RemoveStaleNew skips a
  staged file it can't look at, writeCom moves a magpie.com aside only
  when it is seen there, keepWebView only writes a note, installed()
  and EnsureCompanion remove nothing. Unknown already meant "leave it"
  there, so they keep exists().

Tests (internal/update/install_unknown_test.go): a Stat that answers
permission denied for an existing ancestor holding a file, for the
chosen folder itself holding a file, and for an installed magpie.exe;
each asserts the folder and file survive (checked before the error).
Plus folders made are removed while existing ones with files stay, and
present's three answers.

Run at this tree (parent 80ccaba64):
- mote-run go test -count=1 -timeout 45m ./internal/update ./internal/gui:
  ok update 141s, ok gui 261s.
- gofmt -l internal/: nothing.
- mote-run GOOS=windows go vet ./...: ok. GOOS=linux go vet ./... fails
  in wails' linux files (cgo off when cross-compiling, the same at any
  tree); GOOS=linux go vet -tags nogui ./... (the code standards' form):
  ok. GOOS=windows go build: ok.
- win-run go test -count=1 ./internal/update on xiaomi-gpu: every test
  passes but TestPackagedByDpkg, red the same on origin/main 80ccaba64
  (its magpie:amd64.list fixture is an NTFS stream name), filed as #4603.

Broken by hand: Installable put back to the walk-up + RemoveAll and
settle back to !exists(to), with the injectable stat kept. All three
new tests went red: Tools/notes.txt and magpie/settings.json "is gone",
and magpie.exe held "MZ new download" instead of "MZ installed".
Restored, green.

Not tried: the real Windows dialog against an access-denied folder or a
dead network share (the permission error is injected); a folder getting
content between Mkdir and the cleanup (no hook there, os.Remove refusing
a non-empty folder is relied on); the full go test ./... suite.
2026-11-09 10:41:34 +08:00
yetone 9d366f15b9 update: a file the feed names off GitHub goes on to its github.com address, then the API
The feed is about to name usemagpie.ai's copy of each release file on
Cloudflare R2, with the file's github.com address beside it (`github`).
The app, `magpie update` and install.sh now try, in order: the feed's
url; github.com's address (Asset.GitHub), through the user's mirror when
one is set (a mirror is still only put before a github.com address); then
GitHub's API route, looked up from the github.com address, never through
a mirror. A route is left once it answers busy, or for the last tries
after connections that broke. The error names each route that failed.
Every file is checked against the feed's SHA-256 as before.

Run:
- mote: go test -count=1 ./internal/update ok; gofmt -l clean; go vet,
  GOOS=linux go vet -tags nogui, GOOS=windows go vet of ./internal/update ok.
- wsl (magpie-desktop): go test ./internal/update ok; node --test
  site/install.test.mjs ok.
- mote: node --test site/*.test.mjs 104/104.
- win-run: go test ./internal/update has one red, TestPackagedByDpkg,
  the same on origin/main 82ca554be (#4603).

Broken by hand: toGitHub forced false, five new Go tests red
(TestDownloadGoesToGitHubWhenTheSiteIsBusy and the four beside it);
install.sh's github.com step skipped, two new install tests red.

Not tried: a real update against R2 (the site change is the next commit).
2026-11-09 05:48:23 +08:00
yetone c66cdbea97 update: a release file github.com won't serve comes through GitHub's API
On 2026-11-08 github.com answered 504 for every file of
yetone/magpie-releases (…/releases/download/<tag>/<file>) for hours, while
api.github.com/repos/yetone/magpie-releases/releases/assets/<id>, asked
with Accept: application/octet-stream, redirected to the same bytes.
Every self-update and the install script failed (kurutodenzeru, wjbdx,
isee1_1 on Discord). Retrying the same address (a46190e1f) can't help.
The site's feed was stuck at 0.1.3318 too: its SHA256SUMS read went to
the same address.

- internal/update: download() goes to the API route at the first busy
  status (5xx/429), or for the last try after connection errors. The
  feed's new per-asset `api` is used as it is; without it the address is
  looked up from the release's tag (apiroute.go). The file is checked
  exactly as before: the feed's SHA-256, and Stage's signing-team check on
  the Mac. A mirror the user set keeps precedence: through one, no API
  route is tried (its whole point is that GitHub isn't reachable). This is
  the one download every caller uses: the app's update, the CLI's
  `magpie update` and serve's auto-update.
- site/public/install.sh: when the feed's github.com URL fails and no
  mirror is set, it downloads through the feed's `api` (else looks it up
  with curl+sed, no jq), and checks the same SHA-256.
- site/worker.js: the feed lists `api` per asset. SHA256SUMS is read
  through the API when github.com fails. While it does, each file's `url`
  is usemagpie.ai/dl/<tag>/<file>, which 302s to the address GitHub's API
  gives (only *.githubusercontent.com or github.com, https), so an older
  magpie, which follows `url` only, updates too, still checked against the
  feed's SHA-256. That feed is cached 60s instead of 300s, so it goes
  back to github.com's URLs soon after github.com recovers.
- docs/reference.md: the API route, and that a mirror keeps precedence.

Run:
- mote: go test -tags nogui -count=1 ./internal/update (ok 20.3s).
- mote: node --test site/install.test.mjs site/worker.test.mjs
  site/stable.test.mjs: 76 pass.
- gofmt -l internal/update: clean. mote: GOOS=linux go vet -tags nogui
  ./..., GOOS=windows go vet -tags nogui ./..., GOOS=windows go vet
  ./internal/update ./internal/cli ./internal/gui: clean.
- Real, on the Linux box (wsl-run, magpie-desktop) at 10:50Z: a nogui
  build stamped 0.1.3000, `magpie update` in a sandbox HOME
  (MAGPIE_ADDR=127.0.0.1:9). MAGPIE_UPDATE_FEED was a local feed whose
  magpie-cli-linux-amd64 url answered 504, with the real `api` of
  v0.1.3319 and the sha256 from the real SHA256SUMS. The download address
  was asked once and got 504. The file came through api.github.com, and
  the binary was replaced with exactly 89fff184… and reports 0.1.3319.
- Real: install.sh's apiroute sed against api.github.com's full
  v0.1.3319 description found the right asset id for 5 files
  (723602745 for magpie-cli-linux-amd64, the same as Go's lookup).
- Full suite: not run at push; it runs after.

Broken by hand:
- No switch to the API route in download(): 3 of the 4 new Go tests red
  ("504 Gateway Timeout, on every try").
- Mirror check and the octet-stream Accept removed:
  TestMirrorKeepsPrecedenceOverTheAPIRoute red, and
  TestDownloadGoesThroughTheAPIWhenGitHubIsBusy red (checksum: GitHub's
  JSON description instead of the file).
- worker: no API read of SHA256SUMS, no /dl location cache, and no check
  of the redirect's host: each red.
- install.sh: no API fallback, then no mirror guard: each new install
  test red.

Not tried:
- The real outage itself: github.com had recovered (302, slowly) by the
  real run, so the 504 was a local server's and the API route was real.
- An old magpie through the deployed /dl route against a failing
  github.com; it is covered by the worker test only.
- install.sh end to end against the real API (only its lookup); the Mac
  app's Stage through the API route (only the fake tests, which keep the
  signing-team check unchanged).
2026-11-08 18:52:32 +08:00
yetone a46190e1f5 update: a busy download host (502, 503, 504, 500, 429) is tried again
The owner's About page: "0.1.3316 下载失败 · download
magpie-darwin-arm64.zip: 504 Gateway Timeout". Only a connection that
broke was tried again; any status but 200/206 failed the download at
once, though a 504 from GitHub's asset host (or a mirror's) is its edge
timing out, and the next ask usually goes through. Such a reply is now
a NetError: download asks again after each of retryWaits (2s to 30s),
over HTTP/1.1 and keeping what came, as for a dropped connection. When
every try is busy it says "download <file>: 504 Gateway Timeout, on
every try", and the About row says the download broke off, a network
problem, with Check to try again. A 404 or 403 is still asked once.

Run (mote): go test ./internal/update ok; -run Update|Download|Mirror
in internal/gui and internal/cli ok; GOOS=linux and windows go vet
./internal/update ok; gofmt clean.
Broken by hand: with the busy case off, TestDownloadRetriesABusyHost
fails at the first 504 and TestDownloadBusyEveryTryAndMissingOnce sees
1 try of 6.
Not tried: a real 504 from GitHub; the host's answer is faked.
2026-11-08 17:54:36 +08:00
yetone e484b4ff26 update: a slow download still moving is never ended by a total time; Bun, Claude Code and pf-serve too
#5572: since 80a47abba a silent download is broken off after 30s and
tried again, but the update's download still had a 10-minute total
(the update client's Timeout, the GUI run's ctx, `magpie update`'s ctx).
A download under ~140 KB/s, still receiving bytes, failed the 83 MB
Windows exe at 10 minutes part way. The stall timer is what ends a dead
one now; nothing ends one that is still moving.

- internal/update: fetch downloads through fileClient, the client without
  its Timeout. The feed and notes keep the 10-minute client. fetch's stall
  timer runs from the ask to the last byte, so a server that never answers
  still ends at stallAfter (30s), and download's retries stay bounded
  (len(retryWaits)+1 = 6 tries), so a connection that keeps going silent
  ends in about 4 minutes.
- internal/gui (Mac Stage, Windows/Linux StageBinary): run's 10 minutes
  (checkWait, a var for tests) bound only LatestIn; the download runs
  under a ctx with no deadline.
- internal/cli `magpie update` (Mac Stage, Windows/Linux ReplaceBinary):
  the same split.
- Siblings with the same fixed cap:
  - new internal/stall: Start(ctx, after) gives a ctx that ends with
    ErrStalled once `after` goes by with no byte read through w.Reader.
  - Bun (internal/plugin getURLOnce): watched with a 60s stall;
    KeepBunUpdated's 10-minute ctx around CheckBun is gone.
  - Claude Code (internal/claudecode downloadOnce, ~200 MB): watched with
    a 60s stall; keepOnce's 30-minute ctx around install is gone.
  - pf-serve (internal/pii upgrade): its 10-minute ctx is gone; get
    already had a 60s stall and the client a 60s header timeout, as the
    model's download (no total) does.
- Left as they are: plugin installs and npm updates (KeepUpdated's 10
  minutes) run `bun install`, whose network is Bun's own, small tarballs;
  rtk (5 min client), skills (2 min client), skilltree and market reads
  are small files; Grok CLI install has no cap of its own (its caller's
  ctx). None of them carries a large download behind a wall-clock total.

Run on mote (mote-run), at 49f207c78 + this change; the targeted
set again after rebasing on d4a221f79 (ok):
- go test ./internal/stall ./internal/update ./internal/claudecode
  ./internal/pii -run 'Stall|Slow|Silen|TestDownload|TestInstall|TestKeep';
  go test ./internal/plugin -run Bun; go test ./internal/gui -run
  TestUpdate: ok
- new: TestSlowButMovingIsReadWhole, TestSilenceIsAStall (no answer, part
  way), TestDownloadSlowButMovingOutlastsTheClientTimeout (client Timeout
  300ms, body ~1.2s: one try, no retry), TestUpdateSlowDownloadOutlastsTheCheckBound
  (checkWait 200ms, body ~600ms: ready), TestDownloadThatGoesSilentIsAStall
  (claudecode), TestBunDownloadThatGoesSilentIsAStall. The silent server
  after its retries stays covered by TestDownloadStallEveryTimeSaysSo
  (6 tries, errStalled).
- go test -race -count=3 ./internal/stall ./internal/update -run
  'Stall|Slow|Silen': ok
- win-run (Windows 11): ./internal/stall ./internal/update
  ./internal/claudecode ./internal/plugin with the same -run, and
  ./internal/gui -run 'TestUpdateSlowDownload|TestUpdateDownloadSaysStepAndSpeed': ok
- wsl-run (Ubuntu 24.04), -tags nogui: the same packages and ./internal/gui
  -run TestUpdate: ok
- gofmt -l; go vet ./...; GOOS=linux go vet -tags nogui ./...;
  GOOS=windows go vet ./...; go build; GOOS=linux go build -tags nogui;
  GOOS=windows go build: clean
- Full suite: run after the push under the suite lock.

Broken by hand: fetch back on `client` fails
TestDownloadSlowButMovingOutlastsTheClientTimeout ("broke off ...
Client.Timeout or context cancellation while reading body"); the GUI's
download back under the check's ctx fails
TestUpdateSlowDownloadOutlastsTheCheckBound (state error, "context
deadline exceeded"); stall's reader not putting the timer off fails
TestSlowButMovingIsReadWhole (50 of 120 bytes); Bun's and Claude Code's
downloads unwatched fail their silent tests at the 20s bound ("context
deadline exceeded").

Not tried: a real update over a slow or throttled link, on any OS; a real
Bun or Claude Code download over one. The Mac's unpack and signature
check now run with no deadline (they had the 10 minutes before).

Fixes #5572
2026-11-07 06:09:42 +08:00
yetone 80a47abba8 update: a download says its speed and each step after it, and a silent connection is tried again (esir_tech)
esir_tech on Discord: after clicking Update the progress sat on 17% and
looked stuck. Cause: nothing watched a download that stopped sending. A
connection GitHub's asset host keeps open but silent (seen from some
networks) held the percent still until the client's 10-minute timeout,
then failed. The waits between retries showed the same still percent, and
after the bytes the Mac's unpack and codesign check showed a stale 100%.

- internal/update: fetch cancels a body that sends nothing for 30s
  (stallAfter) as a network error, so download's existing retry resumes it
  with Range. A step callback (update.WithStep) names download, retry,
  verify, unpack and signature.
- internal/gui: /api/update's downloading answer carries step, and speed
  (bytes/s over the last ~5s; it falls to 0 when bytes stop).
- app.js: the pill says "Downloading… 50% · 1.5 MB/s", "Reconnecting…",
  then "Verifying…", "Unpacking…", "Checking signature…"; its tooltip
  carries the text where the tight header hides it. Settings' Version row
  says the same after its MB count. i18n in zh, zh-TW, ja, de. Comments
  cut to stay under the core script budget (not raised).

Run on mote (mote-run):
- go test ./internal/update ./internal/gui -run 'TestDownload|TestUpdate|TestStage|Budget': ok
- new: TestDownloadStallIsTriedAgain, TestDownloadStallEveryTimeSaysSo,
  TestUpdateDownloadSaysStepAndSpeed, TestUpdateSpeedFallsWhenStalled
- GUI, chromium and webkit: update-download-steps (new: en, zh, zh-TW, ja,
  de at 900 and 420px), update-download-percent, update-download,
  update-row-steady, update-stuck, update-network, update-mirror: 178 pass
- i18n-en-no-cjk, header-relang: pass. i18n-keys "a plugin's words are
  its own" is red on origin/main 0d70f335e too (plugins/library,
  routing, usage i18n.js vs Go strings), untouched here.
- gofmt -l; go vet ./...; GOOS=linux go vet -tags nogui ./...;
  GOOS=windows go vet ./...: clean

Broken by hand: with the idle timer a no-op, TestDownloadStallIsTriedAgain
and TestDownloadStallEveryTimeSaysSo fail at their 20s bound (context
deadline exceeded); with speed left out of the answer
TestUpdateDownloadSaysStepAndSpeed fails ("never said how fast"); on the
old app.js/i18n.js update-download-steps fails in every case.

Not tried: a real update on a stalling network, a real Mac unpack and
codesign step (tests cover download/verify only), Windows/Linux runs.
The 10-minute total cap (client Timeout, GUI run ctx, CLI update) is
unchanged, so a moving download slower than ~140KB/s for the 83MB
Windows exe still fails at 10 minutes.

Reported-by: esir_tech
2026-11-07 05:02:02 +08:00
yetone 1fd0bb9670 update: a download whose HTTP/2 transfer broke off tries again over HTTP/1.1
biubiu8802 on X (tweet 2118719081872540038): behind their proxy every
update failed with "download broke off, a network problem", while the
same proxy carried ordinary downloads. Confirmed in the code: download()
retried up to 5 times with Range, but each try went through
netproxy.Dispatch over HTTP/2 again; Dispatch moves a host to HTTP/1.1
only on a TLS record error (recordError: bad record MAC and kin), and
"unexpected EOF" or a stream reset is not one. So a proxy that cuts
HTTP/2 streams part way cut every try the same way.

- netproxy: OverHTTP1(ctx) sends every request under ctx through
  Dispatch's HTTP/1.1 copy (route.h1), kept through With.
  BrokeOff(err) says a transfer broke off (net.Error, unexpected EOF,
  HTTP/2 stream error / GOAWAY / lost connection, a reset; not a
  context that ended). AgainOverHTTP1 runs a download once more over
  HTTP/1.1 after such a failure.
- update: the tries after a broken one go over HTTP/1.1, and still
  resume with Range from the bytes kept.
- Siblings, the other big downloads through Dispatch's client: the
  masking model and pf-serve (pii.fetch, one more try over HTTP/1.1
  from what is on the .part file), Bun's zip (plugin getURLFrom),
  Claude Code's binary (claudecode.download) and the Grok CLI
  (grokDownload) each try once more over HTTP/1.1.
- docs/subsystems/providers-accounts.md names it.

Run (mote, Go 1.26.8, at this tree, base 80ae904c2 = origin/main fetched
just before push):
- TestDownloadBrokenOverHTTP2TriesHTTP1 (httptest TLS HTTP/2 server
  that resets each HTTP/2 stream after 100KB, serves HTTP/1.1 whole):
  red with the update.go line taken out, all six tries over HTTP/2
  ("stream error: ... INTERNAL_ERROR"); green after, asked
  ["HTTP/2.0 ", "HTTP/1.1 bytes=102400-"].
- TestOverHTTP1EveryHost, TestAgainOverHTTP1, TestBrokeOff: green.
- go test ./internal/netproxy ./internal/update ./internal/pii
  ./internal/claudecode ./internal/plugin ./internal/provider: ok.
- go test ./... -count=1 -timeout 45m: 86 ok, gateway 795s and agent
  303s ok; internal/gui red only on two AppKit tests already filed for
  mote's macOS 27: TestMainWindowCorners/macOS_26_SDK (#3949) and
  TestPanelHiddenByWailsMarksPageOutOfSight (#5322). Nothing in gui is
  touched here.
- gofmt -l clean; GOOS=linux and GOOS=windows go vet of the touched
  packages clean.

Not tried: a real proxy that cuts HTTP/2 (the reporter's); the retry of
pii, Bun, Claude Code and Grok against a real host (unit-covered by
AgainOverHTTP1 only); Windows/Linux test runs.
2026-11-06 23:44:58 +08:00
yetone 49c9491b73 update: the Windows app asks where to install, the first time
The Windows exe opened from Downloads (or the Desktop, or temp)
installed itself into %LOCALAPPDATA%\Programs\magpie without a word.
Now, the first time, with nothing installed yet, Windows' task dialog
asks "Install magpie in this folder?". It shows the folder and offers
Install, Change… and Cancel, in the tray's language (en, zh, zh-TW,
ja, de).

- Change… opens the system folder picker. A picked folder gets
  "magpie" added unless it is already named that (update.InstallDir).
- A folder other than the default is recorded at HKCU\Software\magpie
  InstallLocation. So the next exe downloaded replaces the copy there
  in place and asks nothing (installed(), forwards()).
- Cancel runs the exe where it is, as a portable copy, and nothing is
  recorded.
- Uninstall forgets the record (update.ForgetInstallDir, a new System
  step).
- The shortcut, App Paths, autostart, magpie://, the PATH entry and
  self-update already take the running exe's folder, so they follow
  the choice.

Program Files and other folders only an administrator can write to
are refused in the dialog (update.Installable test-writes and maps a
permission error to ErrNeedsAdmin). They are not elevated into.
magpie installs per user (HKCU Run, the user's PATH), and its
self-update replaces the exe without elevation (CanElevate is false on
Windows). So an admin folder would make every update fail, or would
need a UAC prompt on each one. A downloads folder is refused too.
Refusing is the simplest correct choice: it costs a user nothing they
had before, and keeps updates silent. Any folders the test-write made
are removed again.

Docs: gui-shell.md, "Where Windows installs magpie".

Run (mote, at this head on origin/main f9e6061b8):
- gofmt -l is clean.
- go build ./... and go vet of update, uninstall and gui.
- GOOS=windows go vet of gui, update and uninstall.
- GOOS=windows GOARCH=arm64 go build ./....
- GOOS=linux go vet -tags nogui of the same packages.
- go test -count=1 ./internal/update ./internal/uninstall, and
  -run TestInstallWords|TestTrayLang ./internal/gui: ok.

Run (win-run, xiaomi-gpu):
- internal/uninstall ok, and gui TestInstallWordsEveryLanguage ok.
- internal/update: one red, TestPackagedByDpkg. It is red on
  origin/main too: an NTFS stream from the fixture name
  magpie:amd64.list (#4603).

Real Windows 11 run (xiaomi-gpu, a sandbox USERPROFILE/LOCALAPPDATA
under C:\Users\yeton\magpie-idir, MAGPIE_ADDR on 3481, exe in its
Downloads, driven over UI Automation and TDM_CLICK_BUTTON):
- The dialog came up in Chinese, with the app icon and the default
  folder.
- Change… → C:\Program Files was refused with the administrator note
  and the warning icon, and no folder was left behind. C:\Windows was
  refused the same way.
- Change… → …\Tools gave …\Tools\magpie. Install put magpie.exe and
  magpie.com there, and the app ran from there.
- Afterwards InstallLocation, the user's PATH, App Paths and
  magpie:// all named …\Tools\magpie. `magpie version` from a fresh
  PATH resolved to …\Tools\magpie\magpie.com. `magpie autostart on`
  wrote Run = "…\Tools\magpie\magpie.exe" tray.
- Upgrade: a 0.1.9001 build downloaded into Downloads asked nothing.
  It replaced …\Tools\magpie\magpie.exe (FileVersion 0.1.9001) and ran
  from there.
- `magpie uninstall --yes` removed autostart, App Paths, the scheme
  and the record, and deleted the sandbox data. The next exe asked
  again.
- Cancel ran the exe from Downloads and recorded nothing.
- The registry and folders were put back as they were before the run,
  checked by a snapshot diff.

Broken by hand:
- recordedDir's lookup turned off: TestSettleInstallsWhereTheUserChose
  and TestSettleOffersTheChosenFolderAgain went red.
- AskFolder skipped: those two and TestSettleDeclinedRunsHere went red.

Not tried:
- The in-app self-update download. There is no newer release to
  download; the in-place replace path was run with a downloaded exe.
- The en, ja, de and zh-TW dialogs on screen. Their words are checked
  by TestInstallWordsEveryLanguage only.
- arm64 Windows.
- A Downloads folder moved by OneDrive.
- The Start-menu shortcut. The box's real App Paths already held
  another session's magpie, so shortcut.ensure took the shortcut as
  removed by the user. This is existing behaviour.

Not changed: uninstall still leaves the PATH entry and the exe, as
before for every install (#5500). Related to #2663, which asks for a
first-run choice of where magpie lives.

Reported-by: feng_21795_78266 (Discord)
2026-11-06 17:34:48 +08:00
yetone f9e6061b85 claude: claude-magpie runs Claude Code through magpie, a plain claude left on the user's account
baranwang on X (11-06): `claude` stays on the user's own Claude account,
`claude-magpie` goes through magpie, and nothing is switched back and
forth.

`claude-magpie` runs `magpie claude run [args…]`. That writes a settings
file of magpie's own, <config>/claude-launch/settings.json, connected as
Connect connects Claude Code (the gateway, its key, the shared LAN key when
sharing is on, the model, the tiers) and starts
`claude --settings <file> args…`. Claude Code puts a --settings file's env
and model over the user's settings.json, a claude.ai sign-in and the
shell's variables (tried on 2.1.318), so ~/.claude/settings.json is never
rewritten. ANTHROPIC_API_KEY and the cloud switches (Bedrock, Vertex…) are
blanked in the file, so neither the user's file nor the shell can take a
request past magpie. The file is the agent `claude#launch`, listed nowhere:
the Agents page, Check and Notice see only the user's file. It is set again
when the gateway moved or its key changed.

- /model in a claude-magpie session saves to the user's settings.json
  (Claude Code never writes a --settings file). After the session a magpie
  model picked there moves into the launch file, for the next claude-magpie,
  and the user's file gets its model back. A Claude alias (sonnet) stays.
- Claude Code's own one-time `opus` -> `opus[1m]` rewrite of the user's
  file (migration_opus_to_opus1m), which the launch file's 1M opus tier sets
  off, is undone the same way. Found in the end-to-end run below.
- claude runs as a child so that can happen: on Unix a stopped child stops
  magpie too (^Z, fg; proc.WaitFollowingStops reaps it with WUNTRACED, as
  cmd.Wait can't see a stop), and claude's exit code is magpie's. On Windows magpie
  ignores Ctrl+C while claude has it.
- The command: a launcher beside the `magpie` command. Settings › Command
  line (AddCLI) writes it; `magpie claude launcher [add|remove]` adds it for
  a command put there before. It is a `#!/bin/sh` exec of magpie's stable
  path, or on Windows a .cmd running "%~dp0magpie". A file by that name
  without "written by magpie" is never written over.
- Docs: agent-wiring.md, and the start page in en/zh/ja.

Run at this commit (rebased on origin/main 218b38c59):
- mote: gofmt -l clean; go vet ./...; GOOS=linux go vet -tags nogui ./...;
  GOOS=windows go vet ./...; go build for darwin, linux (nogui), windows;
  go test ./... -timeout 45m: 85 packages ok; red only
  TestMainWindowCorners (#3949) and TestRenewLoginsKeepsClaudeReading
  (#5481), both red alone on origin/main b020ae102. The run before at
  f22a9ae61 also had proc's TestEveryStartedCommandIsWaited red on this
  change's own Wait4 loop, fixed here by moving it into proc.
- Windows (xiaomi-gpu): go test ./internal/update ./internal/cli: cli ok;
  update red only in TestPackagedByDpkg, red the same on origin/main
  f47390bf3, filed as #4603.
- Real Claude Code 2.1.318 in WSL (magpie-desktop), sandbox HOME, a built
  magpie (`serve` on its own port), a fake Anthropic upstream:
  - `magpie claude run -p "say hi"`: PONG, exit 0; upstream got
    claude-opus-4-6 with the provider's key. A user settings.json with its
    own ANTHROPIC_API_KEY and "model": "opus" kept both values.
  - Interactive in tmux under bash -i: `/model fakeco/glm-4.6` then /exit:
    the user's file is back on opus, the launch file on fakeco/glm-4.6.
    ^Z stops both magpie and claude (T), fg resumes both.
  - `magpie claude launcher add` wrote ~/bin/claude-magpie, and running it
    answered PONG.
- Real Claude Code 2.1.281 on Windows: claude-magpie.cmd beside a built
  magpie.exe, `claude-magpie --version` printed the version through
  `claude --settings <launch file>`, exit 0.

Broken by hand, each red: the blanks dropped; the launch dir override; the
stale-address check; ClaudeLaunchAfter returning early; the opus[1m]
rewrite check; WaitFollowingStops answering 0 for a signal; "$@" turned into $* in the launcher; the model mark check;
AddCLI's launcher loop; --settings dropped from the args; the restore call
dropped.

Not tried: macOS with a real Claude Code (the Unix path ran in WSL only);
Windows interactive (Ctrl+C, /model restore); a real Claude subscription or
API key upstream (a fake upstream only). Known limits: a session that ends
by a crash or kill skips the restore; managed settings (policy) outrank
--settings; magpie has to be running (claude-magpie warns when it isn't);
Claude Code itself reformats the user's settings.json when it runs its
opus migration, values kept.
2026-11-06 17:31:04 +08:00
yetone 6abacd46c3 update: an Intel magpie under Rosetta updates to the Apple silicon build
cdredfox on Discord saw magpie at 150% of a core. Their goroutine dump
shows AstrLink Guard running in Go (guard.geluRow) in a darwin/amd64
build on an 8-core Mac. That is the Intel build under Rosetta: no
CoreML, and Go's kernels are translated, several times slower than
Apple silicon's build. AppAsset and BinaryAsset named runtime.GOARCH,
so every update fetched the Intel build again, with no way off it.

- internal/rosetta: Translated (sysctl.proc_translated), moved out of
  pii so the updater reads the same thing. pii's translated is now that
  var; its tests still replace it.
- update: arch() is arm64 for darwin/amd64 under Rosetta. AppAsset and
  BinaryAsset (the darwin CLI) use it. goos/goarch/translated are vars
  that tests set.
  Checked before switching: Stage downloads the zip, ditto unpacks it,
  sameSigner wants the same team, and Install renames it over the
  bundle. Nothing there reads the architecture, and the CLI's
  InstallBinary is a rename too. An arm64 build runs natively on every
  Mac that runs Rosetta.
- pii: Status.Rosetta, set on AstrLink Guard's Now() only. Privacy
  Filter's pf-serve is already Apple silicon's there (target).
- GUI: Settings > Privacy's local model line, while AstrLink Guard runs
  under Rosetta, says "On, slowly under Rosetta: the next update
  installs magpie for Apple silicon" in place of "On, on the CPU". It
  is the same one sub-line, with no new element. en/zh/zh-TW/ja/de.

Not done, as decided: skipping tool outputs for the model, or capping
its cores.

Run (on mote unless named):
- go test -count=1 ./internal/update ./internal/rosetta ./internal/pii:
  ok. On WSL magpie-desktop: the same three, plus go vet of them, ok.
  On Windows (xiaomi-gpu): -run "Rosetta|Asset|GuardNow" on update and
  pii, ok.
- go vet ./... (darwin) and CGO_ENABLED=0 GOOS=windows go vet ./...: ok.
  A Linux cross vet needs cgo for Wails, and WSL has no gtk4, so Linux
  vet covered the changed packages only. gofmt -l: clean.
- node --test privacy-model, i18n-keys, i18n-en-no-cjk (chromium +
  webkit, 5 languages, 1100/640px): 91 of 92. The new rosetta case
  passed in every engine, language and width. The one red is "a
  download is cancelled" (chromium). It passes alone, 1/1 at origin/main
  8eb219354 and 2/2 with this change. Filed as #5292 (wheelTo/viewOf
  return "" after a reload).
- go test -run "Budget|I18n|Lang" ./internal/gui: ok. Core scripts are
  1,530,017, under 1,533,802; no raise.

Broken by hand:
- arch() always the build's: TestRosettaUpdatesToAppleSilicon red (4
  cases), and TestRosettaStagesAppleSiliconsApp red, with Intel's
  2.0-amd64 app installed.
- No Rosetta in guardModel.Now(): TestGuardNowSaysRosetta red.
- The app.js line off: privacy-model's rosetta case red ("On, on the
  CPU").

Not tried:
- A real Rosetta process. mote has no Rosetta (no oahd); an x86_64 test
  binary built there didn't start. The translated check is the sysctl
  pii has used since the pf-serve fix, but this commit never saw it
  return 1.
- A real update from an Intel release to an arm64 one. The stage test
  swaps ad-hoc signed fake bundles through the real
  Stage/sameSigner/Install.
2026-11-05 08:25:53 +08:00
yetone a9a8f11e7f plugin, proc: a plugin host is waited for when it ends, not when its stdout does
acezan on Discord (v0.1.2819, Linux x86_64, a systemd service): after
47 hours, 57 <defunct> magpie-bun children of magpie, growing toward the
unit's TasksMax until a restart.

One cause: the plugin host's only cmd.Wait ran in host.read after its
stdout reached EOF. A program a plugin started that kept a copy of the
host's stdout (Bun.spawn given Bun.stdout, which host.js's spawn guard
doesn't catch, #5063; a daemon left behind) held that pipe open past the
host's end, so EOF never came, Wait never ran, the host was never marked
dead, and every host stopped (Restart, a moved proxy, hostStale) stayed a
zombie until magpie quit. Reproduced on Linux (WSL magpie-desktop,
Bun 1.4.2): one more Z-state bun under the test process per Restart,
1, 2, 3, 4 over four rounds. The other cause, magpie web's restart to
update leaving the running host behind its exec (#3285), is the next
commit.

- proc.Output (new, internal/proc/output.go) gives a command's stdout and
  stderr pipes of magpie's own and waits for the command the moment it
  ends. Its readers then have OutputGrace (2s) to read the last lines;
  the pipes are closed after that, which ends a read held up by a
  grandchild. startOn uses it, and a reap goroutine fails the host when
  its child ends. host.read no longer calls Wait. The tests' fake hosts
  (no child) keep cmd.Wait.
- Every other start that wasn't waited for now goes through
  proc.StartReaped (Start, then go cmd.Wait()). Process.Release doesn't
  reap on Unix: codexrelay.Start (a relay that can end while magpie
  runs), tui serveInBackground, uninstall's startAfter, update's
  runAfterExit and OpenBeside (no Wait at all), and Windows' Reexec.
- TestEveryStartedCommandIsWaited (internal/proc) parses every non-test
  .go file. In each function, an x.Start() on a command needs an
  x.Wait(), or x handed on (a call's argument, a struct field), and
  .Process.Release() is refused. It found exactly the sites above.
- docs/subsystems/provider-plugins.md says how the host is reaped.

Checked and left as they are (each waits): the StartTree callers
(provider/install, library mcp_run and mcp_check, gateway claude_warmup
and claude_subscription), pii/serve, provider grok and claude_signin,
claudetui child_unix and wslread, awake, every other bun start (bun.go,
bunupdate, store, dist use Output/CombinedOutput).

Run at 82460a2f9 (on origin/main 40a287b21):
- mote (macOS): gofmt -l clean; go vet on the touched packages,
  GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet ./...: ok.
  go test -count=1 -timeout 45m ./internal/plugin ./internal/proc
  ./internal/codexrelay ./internal/tui ./internal/uninstall
  ./internal/update: all ok. -race -count=3 of the new proc tests: ok.
- WSL magpie-desktop (Linux): the same six packages ok, including
  TestHostReapedWhileItsChildHoldsStdout with a real Bun host; -race
  -count=3 of it and the Output tests: ok.
- Windows (xiaomi-gpu), at the tree before the rebase (base 5ee5274bd):
  proc and codexrelay ok. plugin and update had TestPiPackage,
  TestLoadConcurrentWithSavesAndEdits and TestPackagedByDpkg red; each
  fails the same at untouched origin/main 40a287b21 on that box, 3 of 3,
  and is filed (#4115, #1827, #4603).

Broken by hand, each red:
- host.go back to StdoutPipe with Wait only after EOF:
  TestHostReapedWhileItsChildHoldsStdout fails on Linux ("the host isn't
  marked ended 15s after Restart").
- Output.Start waiting for the readers before Wait:
  TestOutputWaitsPastWhatHoldsIt fails (not waited for in 10s).
- codexrelay back to Process.Release: TestEveryStartedCommandIsWaited
  names relay.go:89 and :92.

Not tried: a full go test ./... (mote and WSL were each running other
sessions' package runs, load 39 and 110); a real magpie serve or web
running for hours on Linux; the host test on macOS (no /proc; the
Output test runs there). Not changed: killing what a host left behind
(its process group) when it is stopped; an orphan like the sleep above
stays in the service's cgroup until it ends on its own.

Reported by acezan on Discord.
2026-11-03 17:58:31 +08:00
yetone db7c576706 update: a list of the newest 40 says how many releases there are in all
sujingshen on X, v0.1.2606 to v0.1.2762: the update sheet read "40 个版本"
for about 156 releases. The app keeps only the newest update.MostNotes
(40) and counted the list it kept, so the line named the cap, not the gap.

update.NotesBetweenTotal returns the count of every release in the range
beside the capped list. /api/update/notes and /api/whatsnew send it as
`total` when it is more than the list, and mergedNotes then reads
"156 releases · the newest 40 shown, v… – v…" (en, zh, zh-TW, ja, de).
Settings' What's new, where withWaiting puts pending releases first and
cuts again, sends no total, since that count was of the installed ones.

Run on mote at this tree: gofmt -l internal clean; GOOS=windows go vet
and GOOS=linux go vet -tags nogui of internal/gui and internal/update ok
(the cgo Linux vet needs gtk4/webkitgtk dev packages neither mote nor
magpie-desktop has); go test ./internal/update ok (new
TestNotesBetweenTotalPastTheCap: 56 releases keep 40 with total 56, 6
keep 6 with total 6); go test ./internal/gui ok except
TestMainWindowCorners, the macOS 27 red of #3949. GUI files in chromium
and webkit: update-notes-ask 16/16 (new: a list cut short says how many,
en and zh), whats-new 4/4 (new case: 156 in all), whats-new-range 12/12,
whats-new-failed 4/4, i18n-keys 4/4.

Not tried: a real update from an install 156 releases back.
2026-11-03 06:35:33 +08:00
ggbdpq e43d67d743 test(update): TestRelaunchOpenTriedAgain waits the relaunch out before cleanup (#3881)
The test's polling loop returned as soon as the fake open had written
`opened`, but the relaunch's shell writes its note for that try only
after open returns: under load the test could be gone and TempDir's
RemoveAll with it while the shell was still appending that note to the
log in the third TempDir, and the cleanup failed with "unlinkat
.../003: directory not empty" (yetone, at machine load 50-95). Once the
note for the open that went through is in the log, the shell has
nothing left to write (it only exits), so the test now waits for it
before returning, the way the gateway's tests wait out the writes of
what they started (#1524, #1543). The cleanup assertion itself is
untouched: it is what guards against a test leaving files behind.

Run: with a shell made to write 20000 files into the log's TempDir
between the open that goes through and its note, the test failed with
the issue's "directory not empty" every time without the wait and
passed 5 of 5 with it (the write-tail injection was for the runs only,
not committed). Without it, -count=5 and the package's -tags nogui
suite pass.

Reviewed and landed as one batch of 12 commits (gua's #4593, #3269,
#3881, #2887, #3289, #2718, #2855, Edward4226's #2718 key-path
sibling, and four review follow-ups). Run for the batch, whose last
commit's tree is 5d58a75f3:
- Full suite before the rebase (base d307aa648, wsl-run magpie-desktop,
  go test -tags nogui -count=1 -timeout 45m ./...): 81 packages ok. Reds,
  all with issues and none in code this batch touches: internal/agent
  TestInstalledVersion, TestGrokInstalled, TestOmpDetectedWithPiDir
  (#4033, #3548, #3141); gateway TestUnroutedHeldReportSaved (#4300);
  gui TestSettingsSaveKeepsWhatItDoesNotSend (#4514) and
  TestColdTurnsTaken (#4510); provider
  TestClaudeAccountServesModelsListedSinceItsFetch (#3174). Run alone at
  origin/main 573b21f4b, TestGrokInstalled, TestOmpDetectedWithPiDir
  and TestSettingsSaveKeepsWhatItDoesNotSend are red there too. The
  other four pass there alone.
- After the rebase onto origin/main 573b21f4b, at this tree:
  internal/usage, update, gateway and provider ok. In internal/agent,
  the #4033/#3141 install-detection reds plus TestCopilotFolderFrom-
  AnIDEPluginIsNotTheCLI and TestZedAppPath. Those two are flaky the
  same way at origin/main (-count=10 alone: 4 and 5 of 10 red) and are
  already listed in #4033. The #3269 tests (TestCopilotLauncher*) pass
  5 of 5.
- Rebased onto origin/main ef63ef4a2. The #2855 commit met 0b9727ec9
  (#2974) in responses.go: the streamed item's done now takes both, the
  upstream's own id (thinkUp) and the made-over item; and in
  gateway-routing.md main's paragraph is kept with #2855's clause. That
  matches gua's latest head (range-diff: context only). At tree d7c76c6fa:
  internal/gateway, provider, usage, redact and update ok; vet
  GOOS=linux -tags nogui ./internal/..., darwin and GOOS=windows for
  gateway and provider.
- Rebased last onto origin/main d8f7d089f (5 commits: internal/agent
  and GUI files only). At tree 0d4bfd8c8, the pushed one: internal/agent's
  TestCopilotLauncher*, TestClaude*, TestOwn* and TestVSCode* ok, -count=3;
  TestCopilotFolderFromAnIDEPluginIsNotTheCLI red once there, as it is at
  main (#4033). Vet of internal/agent: darwin, linux and windows.
- gofmt -l clean. On mote: go vet darwin, GOOS=linux -tags nogui and
  GOOS=windows.
- Broken by hand, each turning its guard red: the lift gate
  (TestReadingKeepsARefusalsRest, TestAutoVisionKeepsOffARefusedAccount);
  the named-time condition (TestNamedQuotaTimeReplacesAGuess); the
  filter-chain hop (WholeReply/glm-5.3-flash); Edward's aAt
  (TestKeyAllowanceElapsedResetStartsAgain); and the old
  magpieMadeReasoning, which panics in TestMadeReasoningSaysItsTextOnce/
  no_summary. Every new test of gua's is red at base d307aa648.
Not tried: real OpenAI, DeepSeek, GLM or ChatGPT accounts; a real VS Code
1.144 install on Windows; a GUI run (no GUI files are touched).

Generated-by: GLM-5.3-Flash (ZCode)
2026-11-01 07:06:19 +08:00
yetone b81956189a update: a Windows update held by a scanner recovers instead of failing 416 on every try (mycf_711 on Discord)
mycf_711 (Win11 26200, 0.1.2364 -> 0.1.2404): the first try failed at the
trial start with "fork/exec ...\magpie.exe.new: The process cannot access
the file because it is being used by another process", and every try
after it failed at once with 416. Both confirmed on xiaomi-gpu with the
old code and a real handle held on the download.

Cause: something (often an antivirus) holds the staged magpie.exe.new.
CreateProcess fails with a sharing violation and that was reported as a
BlockedError (a policy block, which stops the clock checks). download()
dropped os.Remove's error, so the held, complete file stayed, and fetch
resumed it with "Range: bytes=<size>-", which no host can satisfy.

Changes in internal/update:
- download clears the earlier file through clearFile; a held file gives a
  clear error ("another program has it open...") instead of being ignored,
  and every other Remove error is returned, not dropped.
- fetch: a leftover that is already whole and matches the hash is used with
  no request; one that is whole but of other bytes starts over; a 416 starts
  over from zero once.
- binaryStage takes a fresh name (magpie.exe.new-*) when the usual one is
  held, and stagedFiles/RemoveStaleNew find and clear those too.
- the trial start waits while the download is held (waitHeld, as the aside
  moves do); still held after the wait is an ordinary error that keeps the
  download, not a BlockedError.
These run on macOS and Linux too (the held case can't happen there, the 416
and whole-leftover cases can).

Run at 003e55115 (on origin/main 7428f3229):
- mote: gofmt -l clean; go vet ./... for darwin, linux and windows; builds;
  go test -tags nogui -count=1 -timeout 45m ./...: every package ok except
  internal/gui, red on TestSettingsSaveKeepsWhatItDoesNotSend (#4514) and
  TestColdTurnsTaken (#4510), both filed and in files this change doesn't
  touch.
- xiaomi-gpu (win-run go test ./internal/update/...): 88 PASS, -count=3 of
  the new tests ok; TestPackagedByDpkg red, the same on main (#4603: the
  fixture name magpie:amd64.list is an NTFS stream).
- xiaomi-gpu internal/gui update tests: TestUpdateThatWontStart red, the
  same on main (#4115).
- wsl-run (magpie-desktop) go test -tags nogui ./internal/update/...: ok.

Rebased on origin/main e40675cc1 (9 commits, none in internal/update) and
rerun there: mote vet (darwin, windows) and go test ./internal/update/... ok;
xiaomi-gpu the same, red only on TestPackagedByDpkg (#4603).

Broken by hand: origin/main's update.go with only the removeFile shim added
(scratchpad oldcode copy). mote: 5 red (WholeFileAsksNoRangePastTheEnd,
WholeFileOfOtherBytesStartsOver, 416StartsOverOnce, SaysAHeldLeftover,
StageStepsRoundAHeldLeftover). Windows: 8 red, those 5 plus
StageStepsRoundAFileHeldOpen ("416 ... asked [bytes=19-]") and both Trial
tests, with the reporter's own fork/exec message as a BlockedError.

Not tried: a real release update end to end on the reporter's machine, or
with a real antivirus holding the file; which program held it isn't known.
macOS Stage shares only the fetch changes.

Users already on 0.1.2364-0.1.2421 run the old updater: after a reboot (the
hold ends) Check for updates usually gets through; otherwise download
magpie from https://usemagpie.ai and open it.
2026-11-01 02:21:55 +08:00
yetone 0ac26fb52d update: a magpie a package manager installed leaves updating to it (shuhai on Discord, AUR magpie-bin)
shuhai (Arch) installs magpie from the AUR's magpie-bin, which puts the
desktop build at /usr/bin/magpie. magpie's own updater saw a folder it
can't write and pkexec on the machine, so it downloaded the release and,
on restart, replaced the package's file as root. pacman's database then
no longer matched the file, and the next `yay` upgrade (magpie-bin lags
the releases, 0.1.2342 against 0.1.2357 today) put an older magpie back.
The two updaters fought each other.

Now magpie asks first who owns the binary it runs from
(update.PackagedBy): pacman's local database, dpkg's .list files, rpm
(`rpm -qf`, only where /var/lib/rpm exists), a Homebrew Cellar path or
/nix/store. Only a system path counts (/usr but not /usr/local, /bin,
/sbin, /opt), with merged-/usr aliases, and packages named magpie* are
looked at first. A packaged binary:

- GUI: the update is shown as available with "pacman installed magpie
  (magpie-bin), so pacman updates it, not magpie: yay -S magpie-bin"
  (apt, dnf, brew likewise; Nix with no command). Nothing is downloaded,
  there is no Download or Install, the Update pill isn't lit, and
  /api/update/install does nothing (state available, stuck "package").
- `magpie update` says the same and exits 1 before downloading. This
  takes the place of the Homebrew-only check it had.

An unpackaged magpie (~/.local/bin, /usr/local/bin, a file pacman doesn't
list in /opt) updates itself as before.

Run:
- mote: go test -tags nogui -run 'Packaged|Homebrew|NotWritable|InContainer'
  ./internal/update ./internal/gui ./internal/cli ok; full
  go test -tags nogui -count=1 -timeout 45m ./... at b1a1b950f: 81 ok, 3
  red. Two are on main and filed: TestNoCommandBypassesProc (claudetui,
  #4491) and TestSettingsSaveKeepsWhatItDoesNotSend (SearchAll, #4514).
  The third, TestCoreScriptBudget, was this change: app.js is now 460
  bytes more (its comments cut to one line, one helper call per path),
  and both budgets are raised by exactly that, with no room added. After
  the rebase on bb5e68cea: TestCoreScriptBudget and the Packaged,
  NotWritable, InContainer and Homebrew tests ok on mote.
- mote: gofmt -l clean; go vet ./...; GOOS=linux go vet -tags nogui ./...;
  GOOS=windows go vet ./...; go build for darwin, linux (nogui), windows.
- WSL magpie-desktop (Ubuntu 24.04), real package: built a 0.1.2300
  nogui magpie, packaged it as a .deb (magpie-aurpk-test) at
  /usr/bin/magpie, dpkg -i. `magpie update` as the user, through
  /bin/magpie, and as root each printed "magpie 0.1.2355 is out" and
  "this magpie was installed with apt (package magpie-aurpk-test), which
  updates it, not magpie: sudo apt install --only-upgrade
  magpie-aurpk-test", exit 1; the file's sha256 was unchanged and
  dpkg -V clean. Package removed after. An unpackaged copy in ~ still
  checked and offered the update.
- WSL GUI, both engines: every update-* file, i18n-keys, gui-de/ja/zh-tw,
  whats-new*, about-*: 390 pass. Reds: i18n-keys "Unmarked" (#4524, on
  main) and update-check's WebKit ResizeObserver notice (the previous
  commit). Rerun of every update-* file after it: 294 pass, 4 red, all
  timing reds filed as #4554 and #4555, none in update-stuck. After
  app.js was cut down, after the rebase: update-stuck, update-auto,
  update-hide and i18n-keys, both engines: 93 pass, 1 red (#4524).

Broken by hand:
- placeExe's and the CLI's package check turned off:
  TestUpdatePackagedLeavesItToTheManager red ("a packaged binary is to be
  replaced"), TestUpdatePackagedSaysTheManager red (it went on to the
  download).
- origin's app.js: the new update-stuck case times out (no text); only
  the pill condition reverted: red in WebKit.

Not tried:
- A real pacman/Arch install: the omarchy VM didn't answer ssh (banner
  exchange timed out twice), so pacman detection is from the database
  layout in tests only.
- rpm and Nix on a real system; Homebrew only through the existing path
  test.
- The whole GUI suite.
2026-10-31 17:28:37 +08:00
yetone 244cf49371 update: a restart magpie makes by itself comes back as it was, without taking focus
xyxyxy_15591 (Discord #feedback) asked for a silent auto-update: once an
update is in, the window shouldn't pop up. With "Restart automatically"
(Settings, beside Version) on, the window state was already kept (a
closed window came back as the tray icon only), and What's New stays
quiet after an in-app restart. What did show was magpie taking focus:

- macOS relaunched with `open -n` and no `-g`, so LaunchServices brought
  magpie to the front even when only the menu-bar icon came back;
- with the window open, showHere's Focus() activated the app (every OS);
- joining the Dock activated magpie, and with Dock on Wails' Regular
  policy activated it at launch.

Now a restart magpie makes by itself (AutoRestart, `magpie update` from
a terminal) writes a one-shot restart-quiet mark (read once, good for
10 minutes). The next start reads it: `open -n -g`, no Focus(), the Dock
joined without activating, Accessory policy at launch and the Dock set
afterwards. A restart the user clicks removes any mark and comes to the
front as before. `open` gets -g also whenever no window is wanted. No
new setting: zero-config, the existing switch is the one asked for.

Run (base 841326709, rebased on ced880ef0, no upstream change to
these files):
- mote: gofmt -l clean; go vet ./internal/gui ./internal/update
  ./internal/cli; GOOS=linux go vet -tags nogui ./...; GOOS=windows go
  vet on gui/update/cli: clean. internal/update ok;
  TestRestartBySelfComesBackQuietly, TestUpdateThatWontStart,
  TestWhatsNew*, *Handover* ok, except
  TestHandoverLeavesTheMenuBarIconForTheNextMagpie, killed at 30s the
  same at origin/main 7b09d2c95 (AppKit on mote, #4125).
- Windows (win-run, CGO_ENABLED=0): internal/update ok; internal/gui
  reds the same set as origin/main 7b09d2c95 (#4115, #1827, #2958,
  #4514).
- WSL (wsl-run): full `go test -tags nogui -timeout 45m ./...`, 80 ok;
  reds TestInstalledVersion, TestGrokInstalled, TestOmpDetectedWithPiDir
  (#4033, #3548), TestNoCommandBypassesProc (#4491),
  TestSettingsSaveKeepsWhatItDoesNotSend (#4514) all red the same at
  origin/main 7b09d2c95; TestColdTurnsTaken (#4510) passed there alone.
  internal/gui + internal/update rerun at this head: internal/update ok; internal/gui red only TestSettingsSaveKeepsWhatItDoesNotSend (#4514) and TestColdTurnsTaken (#4510).

Broken by hand: without -g, TestRelaunchOpen and
TestRelaunchOpenTriedAgain fail; without markQuietRestart,
TestRestartBySelfComesBackQuietly fails "window true: the start after a
restart by itself isn't quiet"; without the unmark on a clicked restart,
it fails "a restart the user asked for is marked quiet".

Not tried: a real update restart on any OS (`open` of a GUI app over
ssh on mote fails, RBSRequestErrorDomain 5), so -g and no-focus weren't
seen in a real session. Windows' ShowWindow inside Wails may still
bring the window forward when it was open; Linux window managers were
not tried. No GUI assets changed, so no Playwright run.
2026-10-31 15:56:40 +08:00
yetone 482e883142 update: a Windows magpie on the Desktop leaves no magpie.exe.new or magpie.com there
nianshou5 on Discord (#help, Windows): magpie.com and magpie.exe.new
showed on the Desktop and came back after being deleted. Both were
written beside magpie.exe:

- magpie.exe.new is the update the GUI downloads as soon as it is out
  and swaps in at the next restart. StageBinary put it beside the
  program whenever that folder was writable, so it sat on the Desktop
  until a restart, and a deleted one was downloaded again by the next
  check.
- magpie.com (#3737) is written at every start while the app's folder
  is on PATH, and Settings > Command line's Add puts that folder on
  PATH, so deleting it on the Desktop lasted until the next start.

Now:

- StageBinary downloads into magpie's cache, in a folder of this
  program's own (update/<hash of the exe path>), when a rename from
  there reaches the program's folder (renamesInto, a real probe: the
  swap must stay one rename on one volume). With the cache on another
  volume it goes into a hidden .magpie-update folder beside the program
  (FILE_ATTRIBUTE_HIDDEN on Windows). A folder magpie may not write is
  unchanged (cache, moved in as administrator). The stage folder is
  removed after the swap or a failed download.
- At start RemoveStaleNew looks in every place a download may be,
  magpie.exe.new beside the program included, and removes one no newer
  than the running version (same bytes, or an older file version); a
  newer one stays, as before.
- Settled (the installed copy opened from a Desktop/Downloads one)
  also removes the update downloaded for that one, which nothing will
  put in now.
- In a download folder (Desktop, Downloads, a temp folder, as
  isDownloadFolder already says) a start only keeps an existing
  magpie.com up to date and never writes a missing one; Add still
  writes it. Any other folder on PATH is as before. A Desktop
  magpie.exe that opens the installed one (Settle) already wrote none.

Run:
- Windows (win-run, xiaomi-gpu, sandbox HOME from testenv), a repro
  test with the running test binary standing for magpie.exe on a
  Desktop on PATH: at origin/main 72ed121fd StageBinary staged
  test.test.exe.new beside it, and magpie.com came back after delete +
  start; with this change the download was in
  AppData\Local\magpie\update\<hash>\ and magpie.com stayed gone.
- Windows: a real program (whoami.exe) staged into the cache passed the
  real trial start (canStart) and was swapped in for a Desktop
  magpie.exe with the real moveAside/moveIn; the stage folder was gone
  after.
- At the pushed head (rebased on d6beb9975): go test ./internal/update
  on mote and on Windows: ok. Before the rebase also on Linux (wsl-run). gofmt, go vet ./internal/update (darwin, linux, windows),
  GOOS=windows go vet ./internal/gui ./internal/cli: clean.
- go test ./internal/gui ./internal/cli on Windows: TestUpdateThatWontStart,
  TestLodyImportHandoff, TestImportStatusUnreadableIsUnknown,
  TestAionUiImportRow (#4115), TestGatewayHeldByAContainer (#2107,
  #3649) and TestLibraryMCPHub (#4140) red, the same 6 when run at
  origin/main 72ed121fd.
- Full suite on mote (-timeout 45m): started at the pre-rebase tree
  (same update changes, base 72ed121fd) and still running at push; its
  result and any red go in a follow-up.

Broken by hand: staging back beside the exe, the download-folder rule
in EnsureCompanion off, removeStaged out of Settled: the new tests
(TestUpdateStagedOutOfTheProgramsFolder, TestUpdateStagedHiddenWithoutTheCache,
TestStartClearsAnOlderDownloadBeside, TestNoCompanionPutBackOnTheDesktop,
TestSettledClearsOnlyMagpiesFiles, TestNoCompanionBesideAForwardingDownload)
went red.

Not tried: a real GUI self-update of a release build on the Windows
desktop, a cache and Desktop on separate real volumes (the hidden
fallback was tested with no cache), the reporter's own machine, and a
real terminal's `magpie` (unchanged code outside download folders).
2026-10-31 00:21:26 +08:00
yetone a3b9dd1127 windows: the app opened from Downloads installs itself in Programs\magpie
lucky_eagle_38 on Discord: Windows magpie is one exe that lands in
Downloads, the user moves it around, and the `magpie` command came from
a magpie.com ("ms-dos" file) magpie wrote beside it there. They asked
for a fixed install folder, with the command coming from PATH.

Before: wherever the exe ran, the Start menu Magpie.lnk, App Paths,
Open at login (HKCU Run "magpie") and updates named it there. Settings >
Command line put that folder on the user PATH and wrote magpie.com (or
magpie.cmd) beside it, and EnsureCompanion kept writing magpie.com there.

Now (update.Settle, first thing in gui.Run): the desktop app run from
Downloads, the Desktop or a temp folder (an exe opened inside a zip)
copies itself to %LOCALAPPDATA%\Programs\magpie\magpie.exe, per-user and
with no admin. It puts that folder first on the HKCU PATH with its
magpie.com (cliPlace, with WM_SETTINGCHANGE as before) and opens the
copy (Forward waits for its MAGPIE_STARTED, then passes that on, so an
update restart waiting on the download isn't rolled back). The copy's
shortcut.Ensure re-points the Start menu lnk and App Paths. Its updates
replace the installed exe in place. The download quits.
- Run again: the download opens the installed copy. If its RT_VERSION
  is newer than the installed one, it first goes in place of that copy
  (InstallBinaryAside, as an update does). An older or unversioned
  download never replaces it.
- Open at login: the Run value is re-pointed only when it named the
  download (autostart.Repoint). Task Manager's StartupApproved off flag
  is kept.
- Leftovers beside the download (update.Settled, in the installed copy):
  - Removed: what updates moved aside (.old). Also magpie.com and
    magpie.cmd, but only when magpie wrote them for that exe (comRuns
    and shimRuns check the marker and target).
  - Never removed: the download itself and any other file.
  - EnsureCompanion writes no magpie.com beside a download that forwards.
- WebView2's profile is keyed by exe name. The old profile
  (%APPDATA%\magpie-windows-amd64.exe) is kept through a webview-profile
  note beside the install, which appdir.WebView reads. magpie uninstall
  removes that noted profile too (only a folder directly in %APPDATA%
  with an EBWebView in it).

Not moved:
- an exe in a folder the user chose (D:\Tools, a USB drive, the home
  folder, Documents, a subfolder of Downloads);
- a portable copy (a data folder or .portable beside it);
- any copy run with MAGPIE_NO_INSTALL=1;
- CLI runs (only the desktop app installs).

Left for old users: the Downloads entry an earlier Command line put on
the HKCU PATH stays. The user may have added it themselves, and it now
comes after the install folder. Taskbar pins still name the download,
which opens the installed copy.

Run:
- Real run on xiaomi-gpu (Windows 11) as a throwaway local user,
  through a scheduled task (the user is deleted now; its profile hive
  was still held at cleanup and is removed on the next unload):
  - Seeded with the real v0.1.2124 in Downloads, its folder on PATH, its
    magpie.com, a Run value with the off flag, the lnk and App Paths on
    it, a .old, a user's own magpie.cmd and notes.txt.
  - Then ran release-built (make release-windows) v0.1.2000 from
    Downloads with `tray`:
    - Programs\magpie got magpie.exe 0.1.2000, magpie.com and the note.
    - PATH is that folder first.
    - Run, lnk and App Paths now name it. The off flag is kept.
    - Downloads lost magpie.com and the .old and kept the exe, the
      user's magpie.cmd and notes.txt.
    - The download exited 0, and the installed copy ran.
  - Again: forwarded, nothing changed.
  - v0.1.2001 from Downloads: it replaced the installed 0.1.2000.
  - The registry PATH's `magpie` is Programs\magpie\magpie.com, and
    `magpie version` gives v0.1.2001.
  - Ran a copy at ~\Tools\magpie.exe: it ran there and the install was
    not touched.
  - The installed copy's `magpie update` went to the real v0.1.2126
    in place (magpie.exe.old aside).
- win-run (Windows): go test ./internal/update ./internal/autostart
  ./internal/appdir ./internal/shortcut ok. ./internal/gui has 5 reds:
  TestGatewayHeldByAContainer, TestLodyImportHandoff,
  TestImportStatusUnreadableIsUnknown, TestAionUiImportRow and
  TestUpdateThatWontStart. They fail the same alone on origin/main
  4a4a90c23 and are filed in #4115.
- mote: go vet ./..., GOOS=windows go vet ./..., GOOS=linux go vet
  -tags nogui ./... and GOOS=windows go build all OK. go test -tags
  nogui -timeout 45m ./... gives 80 ok, no FAIL, at 9e8c22dad + this.
  After rebasing onto fce294c5a (gui assets, pii, sessions, WorkBuddy
  min), the vets and the gui, uninstall, update and sessions packages
  ran again on mote: all ok. On Windows, uninstall, update, autostart
  and appdir ran ok at that head. TestCoreScriptBudget was red at
  6db21d869, the upstream head then, and fce294c5a fixed it.
- Broken by hand on Windows, each one red:
  - no forwards check in EnsureCompanion:
    TestNoCompanionBesideAForwardingDownload;
  - always replace: TestSettleKeepsTheInstalledVersion;
  - the shim always removed: TestSettledClearsOnlyMagpiesFiles;
  - no download-folder check: TestSettleLeavesAChosenPlace;
  - the original marker passed on: TestForwardWaitsForTheInstalledOne;
  - no keepWebView: TestSettleKeepsTheWebViewProfile;
  - a case-sensitive Run path: TestRepointed;
  - uninstall without the noted profile: TestProfilesTakeTheNotedOne.

Not tried:
- the GUI on an interactive desktop: the real run was in a batch logon,
  where WebView2 did start;
- a OneDrive-moved Downloads (it is read from the known folder);
- an exe opened from inside a zip;
- taskbar pins.
Not changed: magpie uninstall still leaves the exe, magpie.com and the
PATH entry, now in Programs\magpie. #2663 is open for the uninstall
flow that cleans them.
2026-10-30 11:28:32 +08:00
yetone eed140c4d9 update: a Mac update no longer leaves a second magpie in Spotlight (#3965)
Stage unpacked the new app to /Applications/.magpie-update/app/magpie.app
and Install moved the old one to .magpie-update/old.app. LaunchServices
registers a folder ending in .app in /Applications within seconds, and
Install only deleted the folder, so Spotlight kept listing the gone path
as another magpie.

- Stage ditto's the zip (one top folder, magpie.app, checked against the
  real v0.1.2119 zip: no FinderInfo bundle bit, no __MACOSX) into
  .magpie-update/unzip and renames magpie.app to .magpie-update/payload
  at once, then has lsregister -u forget the unzip path in case it was
  seen in that moment. codesign verifies a bundle named payload the same
  (checked on the real zip: verify ok, a tampered copy fails).
- Install and InstallAsAdmin move the old app to <stage>/old, and remove
  filepath.Dir(staged), which is still .magpie-update (or the cache's
  update folder on the admin path); renames stay on one volume.
- ForgetOldStaging runs once from the GUI's updater start, in a
  goroutine: lsregister -u on .magpie-update/app/magpie.app and
  .magpie-update/old.app beside the app and in ~/Library/Caches/magpie/
  update. lsregister is /System/Library/Frameworks/CoreServices.framework/
  Frameworks/LaunchServices.framework/Support/lsregister (present on
  macOS 27.2); failures are ignored, a 10s cap, marker in magpie's cache.
  /Volumes/magpie (an old DMG) is left alone.

Run at this head (base ffa07395e):
- mote (macOS 27.2): gofmt -l clean; go build, GOOS=windows go build,
  GOOS=linux go build -tags nogui; go vet, GOOS=windows go vet and
  GOOS=linux go vet -tags nogui on internal/update, internal/gui,
  internal/cli; go test internal/update internal/gui internal/proc
  internal/appdir: build and vet ok;
  update, proc, appdir ok; gui FAIL only in TestMainWindowCorners/
  macOS_26_SDK (the titlebar toolbar on macOS 27), already filed as
  #3949 and not in code this touches
- win-run (xiaomi-gpu, Windows 11): go test ./internal/update ok.
- wsl-run (magpie-desktop): go test ./internal/update ok.
- Real LaunchServices on mote, a fake bundle id (com.example...) in
  /Applications/lstest-3965, not magpie.app: the old flow by hand
  registered .magpie-update/app/magpie.app within 30s and kept it after
  the folder was deleted. A throwaway test running this Stage + Install
  with the real lsregister: after 45s staged and 15s installed,
  lsregister -dump shows only lstest-3965/magpie.app; with stagedName
  set back to magpie.app the same run shows .magpie-update/magpie.app
  registered (red). ForgetOldStaging with the real lsregister removed
  both registered .magpie-update paths after their folders were deleted.
  Everything registered was unregistered and the folder removed.

Broken by hand, each red: asideName "old.app" (TestInstallAsAdminAside-
IsNoApp), stagedName "magpie.app" (TestInstallStagesNoApp, TestStage-
UnpacksNoApp), RemoveAll two folders up as before (TestInstallStagesNoApp:
the Applications folder went with it), no unregister of the unzip path
(TestStageUnpacksNoApp), no marker (TestForgetOldStaging).

Not tried: a real magpie update of the installed /Applications/magpie.app
with Spotlight's UI (the fake bundle stood in), the administrator-password
path for real, the full go test ./... suite.
2026-10-30 09:23:35 +08:00
yetone 5be581a1c3 gui: a magpie folder the user can't write gets a one-click Repair (YouWhat)
YouWhat on Discord (macOS): adding a custom provider failed with
"mkdir ~/.config/magpie: permission denied". ~/.config wasn't the user's
(a command run under sudo makes it root's), so magpie couldn't make its
folder. The app still ran because reads of a missing file mean "none",
but every save failed. The GUI saves showed the raw error; the
background writes (usage, quotas, caches) dropped theirs.

Now:
- appdir.Blocked() names the folder that keeps magpie from writing its
  config or cache folder: the folder itself, or the first one above it
  when it doesn't exist yet. Only folders inside the home folder are
  named. Unix only; on Windows it is "".
- /api/state carries configBlocked. A failed save whose error is a
  permission refusal comes back with code config_blocked. The window asks
  once a load, and again over the editor whose save failed. "Not now"
  returns to that editor as it was left. The tray panel doesn't ask.
- Repair (POST /api/config/repair): a folder the user owns gets u+rwx with
  no prompt. Another user's folder is chowned to the user, through the
  system's password prompt (update.AsAdmin, the updater's: osascript on a
  Mac, pkexec on Linux). That chown is not recursive for ~/.config, so the
  other apps' folders inside it stay as they are; magpie's own folder is
  chowned -R, since everything in it is magpie's. magpie web shows no
  prompt; it names the sudo command instead. Data never moves: every
  reader keeps the one path, so nothing splits.
- Words in en, zh, zh-TW, ja and de.
- The core-script budget goes up by 1,112 bytes (app.js stays under its
  own), with no room added.

Run (on mote via mote-run, at this tree, based on 17114b505):
- gofmt -l: empty. go vet ./... (darwin), GOOS=linux go vet -tags nogui
  ./..., GOOS=windows go vet ./...: clean.
- go test -timeout 45m ./internal/appdir ./internal/update
  ./internal/gui ./internal/proc: appdir, update and proc ok. gui fails
  only TestMainWindowCorners/macOS_26_SDK, which fails the same on
  origin/main 17114b505 on mote (open: #3949). TestCoreScriptBudget's
  first red led to the raise above, and it passes after.
- Red on old code: TestBlockedConfigIsRepairedInOneClick at 17114b505
  fails with "failed save = 400 {"error":"mkdir …/.config/magpie:
  permission denied"}; want code config_blocked". Its sandbox HOME has
  .config at chmod 555, which is the reporter's error. With the change it
  passes: the save names ~/.config, Repair returns 204, the same save goes
  through into ~/.config/magpie/providers.json, and state clears.
  TestRepairOfAnotherUsersFolderAsksAnAdmin fakes another owner and checks
  that the script is "chown <uid>:<gid> '<~/.config>' && chmod u+rwx",
  with no -R, that magpie's own folder gets -R, and that web shows no
  prompt.
- GUI: config-blocked.test.cjs, cli-behind.test.cjs and i18n-keys.test.cjs
  in Chromium and WebKit (en, zh), 12/12 ok. The new file checks the keys
  in zh, zh-TW, ja and de. It is red on the old assets (2/2 not ok in
  Chromium).

Not tried: a real root-owned ~/.config and the real osascript or pkexec
prompt (no sudo on the test boxes). The script runs through the updater's
AsAdmin, which already runs a privileged script. The TUI and CLI don't
offer the repair yet: #4287.
2026-10-29 22:10:21 +08:00
yetone 6b253dbb3f windows: magpie.com is written again only when the launcher changes, not on every update
lucky_eagle_38410 on Discord (#general, 10-28): every run of the command
line wrote a new magpie.com. magpie.com is the console launcher from
2afacd7d1 (#3737): PowerShell and cmd run magpie.com before magpie.exe
(PATHEXT), and wait for it, so a prompt, a password and the exit code
reach the terminal; the GUI-linked magpie.exe alone gives the prompt back
at once. It is needed, and writeCom already writes it only when its bytes
differ.

They differed on every release. `make release-windows` built the
launcher from the git checkout with Go's default -buildvcs, which stamps
vcs.revision and vcs.time into the binary, so each release carried a
different magpie.com though the launcher's source hadn't changed, and the
first `magpie` after each update (several a day) wrote it again, moving a
running one aside as magpie.com.old. The launcher is now built with
-buildvcs=false, so magpie.com changes only when the launcher does.

Run:
- Windows box (xiaomi-gpu, PowerShell 5.1 over a ConPTY, sandbox
  USERPROFILE/APPDATA, a folder of its own on PATH), the app run as
  magpie.exe, then through magpie.com, then the next version copied over
  magpie.exe and run again:
  - real releases v0.1.1861 -> v0.1.1862: magpie.com 5F55B8D4... ->
    2E6AD7D9..., rewritten on the update.
  - make release-windows at origin/main 6e080ca04, at two commits of the
    same tree: B26668C1... -> 15AD7512..., rewritten.
  - make release-windows with this change, the same two commits:
    782517C6... both times, mtime unchanged.
- mote: go test -tags nogui ./internal/update/...: ok. GOOS=windows and
  GOOS=linux go vet ./internal/update/: ok. gofmt -l: clean.
- win-run: TestLauncherSameAtEveryCommit, TestWriteCom, TestComOwner,
  TestEnsureCompanion, TestFindCLIPrefersCom pass on Windows.

Broken by hand: the Makefile without -buildvcs=false makes
TestLauncherSameAtEveryCommit red ("the launcher built at the next
commit differs ([-trimpath -ldflags=-s -w])"). The test builds a
program with the Makefile's launcher flags in a scratch git repo at two
commits and compares the bytes.

Not tried:
- A real release build in magpie-releases; the next tag is the first.
  The first update to it still writes magpie.com once (its bytes change
  from the stamped one); after that only a launcher change does.
- The arm64 build on a real ARM machine.
- The full go test ./...; only internal/update changed (a Makefile flag,
  a comment and a test).
2026-10-28 17:32:28 +08:00
yetone 2afacd7d18 windows: a terminal waits for magpie, through a magpie.com beside the app (#3737)
The Windows app is linked with -H windowsgui so a double click opens no
console, and PowerShell and cmd don't wait for a GUI program. The prompt
came back before magpie printed, and `magpie plugin login`'s password
keys went to the shell as well as to magpie (tom047784 / TomXPRIME on
Discord, 10-27; the handle error in the same report was 9298d2a).

A shell looks for `magpie` by PATHEXT, which lists .COM before .EXE. So
magpie now writes magpie.com beside the app. It is a 1.9MB console program
(internal/update/launcher), built and embedded by `make release-windows`
(the comlauncher tag). The shell waits for it. It runs the app with its own
std handles, passes MAGPIE_COM=1, waits, and exits with the app's code. The
app keeps those handles and borrows the console for the streams Windows
dropped (a GUI child gets no console handles), so redirection, pipes and
hidden prompts work. A command that opens the window (none, app, gui, tray,
panel, -Embedding, magpie: links) is started DETACHED, and the shell isn't
held. A double click and the Start menu still open magpie.exe.

Why this, and not a console-subsystem copy or a magpie-cli.exe: the
running process is still magpie.exe, so autostart, shortcuts, relaunch and
every os.Executable() use are unchanged. There is no new release asset (still
16), and magpie-releases needs no change. The trailer names the app, so a
download kept as magpie-windows-amd64.exe is run by its own name.

Where it is written:
- Settings › Command line's Add (cliPlace) writes it instead of magpie.cmd
  in a build that carries it.
- A terminal command run as magpie.exe writes it when the folder is on PATH
  or has a magpie.com or magpie.cmd, so existing users get it on their next
  `magpie <cmd>`.
- The app's start (placeExe) writes it again when the bytes differ, so an
  update brings it along.
- A running magpie.com is moved aside and cleared on the next run.
- A copy beside a magpie.exe leaves `magpie` to it (comOwner).
- The Command line row reads magpie.com as this app, with "(which runs
  magpie.exe)".

Run, at 2e165fe9d (main since then touches none of these files):
- gofmt -l: clean
- go vet ./...; GOOS=linux go vet -tags nogui ./...; GOOS=windows go vet ./...
- go build for darwin, linux -tags nogui and windows
- make release-windows: amd64 and arm64 are PE subsystem 2 (GUI), as before
- go test -tags nogui -count=1 -timeout 45m ./internal/update/...
  ./internal/cli/ ./internal/gui/ ./internal/proc/: all ok
- cli-path.test.cjs in chromium and webkit (11 + 11 pass); i18n-keys,
  gui-zh-tw, gui-ja, gui-de pass
- The Windows box, with GOOS=windows test binaries: launcher's TestArgsOf,
  TestOpensWindow and TestTargetName pass; update's TestWriteCom,
  TestComOwner, TestEnsureCompanion, TestFindCLIPrefersCom and
  TestCLIShim pass. TestComMagicIsTheLaunchers reads the source, so it
  can't run from a copied binary there; it passes on macOS.
- The Windows box, sandbox HOME, release build, interactive ConPTY over
  ssh -tt with typed keys:
  - Old v0.1.1675 in PowerShell 7.5.4: the prompt comes back before
    "magpie 0.1.1675", $LASTEXITCODE is empty, `> out.txt` is empty, and
    backup's passphrase is split between the shell and magpie.
  - New build in PowerShell 7.5.4: the first `magpie` as magpie.exe wrote
    magpie.com, and Get-Command then resolves it. `magpie version` prints
    before the next line, with exit 0. A bad command gives 1. `> out.txt`
    holds the version. backup reads "Passphrase for the backup:" and
    "Again:" typed. restore reads "Passphrase:" typed. A piped passphrase
    is read (wrong passphrase, exit 1).
  - New build in cmd: `where` lists magpie.com first. The same version,
    ERRORLEVEL 0 and 1, and typed backup and restore passphrases work.
    Ctrl+C at a prompt ends it with 0xC000013A and leaves no magpie.exe.
  - The update: an older magpie.com in place was moved aside and rewritten
    by the first command of the new build, and the .old was gone after the
    next one.

Broken by hand, red:
- writeCom always rewriting: TestWriteCom
- EnsureCompanion ignoring PATH: TestEnsureCompanion
- comOwner always true: TestComOwner
- app.js's old shim-only condition: the "magpie.com is said to run the app"
  case in en and zh

Not tried:
- A real double click or the Start menu on the box. magpie.exe is still
  GUI-subsystem and is what they open, but no window was opened there. The
  sandbox app would share the gateway's port with the box's own magpie.
- Windows Terminal itself; the ConPTY ssh -tt gives is what it uses.
- The arm64 build on a real ARM machine.
- The full go test ./... at this head. Another session's agent and
  gateway suite was running on the machine (load ~115), so only the
  touched packages and internal/proc ran.
2026-10-27 12:08:16 +08:00
yetone cc9d68ffd3 agent: Antigravity CLI in a WSL distro is found and wired
mimi001234 (Discord, #general): agy installed in a WSL distro never
showed on the Agents page. wslKinds had no agy, so the distro probe never
looked for it.

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

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

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

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

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

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

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

Not tried: PowerShell on Windows for real (vet only); WSL; a user's own
`alias agy` (an alias beats the function); a terminal already open needs
the copied command; macOS bash started non-login reads .bashrc, which
isn't written; a Documents folder redirected outside the profile isn't
written.
2026-10-27 07:30:16 +08:00
yetone 6335625a60 update: a download that breaks off is tried five more times, from where it stopped
AIMetaPhD on X: on Windows, 0.1.1615 couldn't download 0.1.1618;
GitHub's asset host dropped the connection ("EOF"). The download was
tried three times, two and four seconds apart, each time from byte zero,
and then it gave up. The error also carried the full signed redirect
URL, which the GUI showed.

Now a try the network breaks off (the connect, or the body part way) is
tried again after 2, 4, 8, 16 and 30 seconds. Each later try asks with
Range for the bytes still missing. A host that sends 200 instead has the
file written again from the start, and a 206 whose Content-Range doesn't
start where the file ends is refused. The SHA-256 from the feed is
checked over the whole file read back from disk, so the bytes from
earlier tries are covered. A failure that isn't the network's (a 404, a
checksum mismatch, a write that fails) is not tried again, and the file
is removed. The error is a NetError that names the file and the cause
("the download of magpie.exe.new broke off (EOF)"), never the address.

Release timing was checked and is not the cause. v0.1.1618's
magpie-releases release was created at 16:32:48Z, its assets were
uploaded from 16:36:13Z to 16:36:17Z, and it was published at
16:36:18Z. The feed reads only releases/latest, which skips drafts, and
needs SHA256SUMS, so it couldn't name 1618 before its files were there.
The URL in the screenshot is the asset host's redirect, which exists
only for an uploaded asset.

Run: go test ./internal/update ./internal/cli (ok); gofmt -l clean;
GOOS=linux and GOOS=windows go vet ./internal/update. New tests run on
httptest servers: a body cut mid-stream twice (resumed with
bytes=102400- and bytes=307200-, file and progress whole), a resume
with the wrong bytes (checksum fails, nothing kept), a connection hung
up before any answer behind a redirect to a ?sig=&jwt= URL (six tries,
and the error holds no URL), and a 404 (one try).

Broken by hand: without the Range header the resume test is red
(ranges "" "" ""); with the NetError keeping the url.Error the address
test is red (the signed URL in the text); with three tries it is red
(tries = 3, want 6).

Not tried: a real self-update on this machine or the Windows box, or a
real cut connection to GitHub. The China mirror and the user's
UpdateMirror get the same Range header; a mirror that ignores it sends
200 and the file is written again from the start.
2026-10-27 01:34:26 +08:00
yetone 4a33cf0a98 update: a Stable channel in Settings → About, and magpie update channel
ssharpcc on X reads every changelog before updating, for fear of a ban
when behind, and with many releases a day that is a lot of reading.
Settings → About → Update channel (zh: 更新渠道, 稳定版 / 每个版本) picks
Every version, the default and today's behaviour, or Stable: one version
a week, the newest that had been out three days as the week began
(Monday 00:00 UTC), and an urgent release at once. usemagpie.ai chooses
it from the release list (the previous commit); a release is urgent when
a line of its notes starts with "**Urgent release:**", which
magpie-releases' release run writes from an `Urgent: <why>` trailer
(magpie-releases 73f6cff).

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

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

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

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

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

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

Requested by ssharpcc on X.
2026-10-26 21:09:44 +08:00
yetone 761904b5ab whatsnew: Settings' What's new can show this version and the 10, 20, 50 or 100 before it (Linka)
Linka (linkaww, Discord, 10-25): 希望「关于 - 更新内容」加个可选项,查看
「上次更新以来 / 当前版本前 10 / 20 / 50 / 100 个版本」的更新说明.

Settings › About › What's new now has a pill in its head (the app's
menu, sess-pick, never a native select): "Since the last update", the
default and what it showed before, or "This version and {n} before" for
10, 20, 50 and 100. The dialog shown by itself after an update has no
pill and is unchanged.

- site/worker.js: /api/notes takes limit=, the newest that many after
  upto, so a request for 11 isn't answered with 100.
- internal/update: NotesBack(ctx, upto, n, lang) asks upto and limit
  n+1; Back(notes, upto, n) keeps upto and the n releases before it,
  newest first, Install sections stripped, empties dropped. It is not
  capped at MaxNotes (40), which only Between keeps.
- internal/gui/whatsnew.go: /api/whatsnew?all=1&last=N, for N in
  10/20/50/100 only (anything else is the default). Cached per language,
  the longest range asked kept, and a shorter one cut from it, so
  picking 10 after 100 asks nothing and a reopen asks nothing. A failed
  fetch is unknown: the reply carries error and whatever range was had
  before.
- app.js: openWhatsNew(b, last) and wnRange. A pick that fails keeps
  the notes last shown, says "Couldn't load the release notes" with Try
  again above them, and Try again asks the same range.
- The archive helpers (archivedCalls, headersPanel, downloadArchive,
  archiveBodyPanel), used only by the Usage page, moved to
  plugins/usage/page.js as d08b6118b did, so app.js stays under its
  budget (1,319,177 of 1,321,336); no budget raised.
- i18n: three strings in zh, zh-TW, ja and de.

Run at the pushed head (rebased on origin/main 0d2a10116):
- go test -count=1 -tags nogui ./internal/update/ ./internal/gui/ in a
  sandbox HOME: ok (TestNotesBack, TestWhatsNewBackRanges,
  TestCoreScriptBudget among them).
- gofmt -l: none. go build ./...; go vet ./...; GOOS=linux go vet -tags
  nogui ./...; GOOS=windows go vet ./...: ok.
- node --test site/worker.test.mjs: 21 pass (new: limit keeps the
  newest that many up to upto; "", 0, x and -1 mean no limit).
- GUI at this head, both engines: whats-new-range (new), whats-new,
  whats-new-failed, i18n-keys, ledger-cache-unknown, request-archive and
  request-archive-usage (the Usage page holds the moved helpers): 50 of
  50. whats-new-range.test.cjs alone is 12 of 12: five languages x two
  engines plus the post-update dialog in both. Covers the default label
  and no last= asked, the menu's head and five items, 10 then 100,
  the same pick asking nothing, a failed 50 keeping the 100 shown with
  the error above, Try again, no scroll, no left-border accent, and a
  440px window with the pill inside the dialog.
- Whole GUI suite (869 files), chromium then webkit, concurrency 4:
  still running at push time, started at 1f156ba40 (the same change on
  e57e78563); the tree was rebased under it at 01:45. Chromium at 01:46:
  1725 top-level tests passed, 7 red, none in a What's new or Usage file:
  agents' sign-ins, Plugins › Built-in, zh-TW 420px context map, gateway
  mode, an MCP server out of the library, and "a menu opened from a long
  text box's rule stays open" (en, zh). They will be checked against
  origin/main and filed or fixed when the run ends. Before the rebase,
  usage-ledger's "newest live route needs no return-to-live button" was
  red here and on an origin/main e57e78563 copy alike (#3104, #3001).

Broken by hand, each red, then restored:
- the pill not added to the head: whats-new-range red.
- the kept notes not used on a failure: red at "the notes shown before
  are kept".
- the ?last= route skipped: TestWhatsNewBackRanges red.
- Back not cutting to n+1: TestNotesBack red.

Not tried:
- the real site: the test fakes /api/notes and /api/whatsnew. The site
  holds GitHub's newest 100 releases, so "100 before" on the newest
  version can show at most 100. An undeployed site ignores limit; the
  app cuts the list itself.
- the real app window (Wails/WebKitGTK); only Playwright's engines.
- go test ./... in full was not run: the machine had a queue of other
  sessions' full suites, and the owner's rule is not to hold a verified
  commit behind one.

Known limits: a range view carries no pending (waiting update) notes;
if a longer cached range dropped an Install-only release, a range cut
from it can reach one release further back than a fresh ask would.
2026-10-25 01:46:55 +08:00
yetone 8c62702442 whatsnew: Settings lists every release up to the waiting update, not its notes alone
小八 on Discord (10-24): on 0.1.1398 with 0.1.1409 out, Settings › About ›
What's new showed 0.1.1409, then 0.1.1398 and older; 0.1.1399 to
0.1.1408 were missing.

Cause: openWhatsNew (app.js) took /api/whatsnew?all=1, which lists the
running version's notes (or those since the last upgrade), and put the
waiting update's own notes (/api/update's u.notes) on top. Nothing asked
for the releases between the running version and the update. The site's
/api/notes had them (checked live: after=0.1.1398&upto=0.1.1409 returns
all ten, 0.1.1407 was never released).

Fix: /api/whatsnew?all=1 now puts first, while an update waits (ready,
available, downloading, found), the notes of every release after the
running version up to it (withWaiting, through fetchNotes as the restart
dialog's update/notes has them), each marked pending ("Not installed
yet"); the site out of reach leaves the update's own notes, as before.
update.Note gets Pending. The page shows what the app sends, so
openWhatsNew no longer asks /api/update or merges (app.js 265 bytes
smaller). Not changed: the restart dialog (confirmUpdate) already asks
update/notes for the range; the popup after an upgrade lists after..now
through Between, which was right; the site's degraded path (API refused:
the Atom feed's newest 10 plus the last whole list) can still leave a gap
when more than 10 releases came out since the list was last whole.

Run (worktree at origin/main 0df6a3aba, sandbox HOME, caches pinned):
- TestWhatsNewListsEveryReleaseUpToTheWaitingUpdate (new): the site's
  list shaped as magpie-releases had it (0.1.1396 to 0.1.1411, no
  0.1.1407, Install sections), running 0.1.1398 with 0.1.1409 waiting in
  each of the four states: 1409..1399 pending, then 1398 and older; site
  down: the update's own then the kept; nothing waiting: none pending.
  Broken by hand (route without withWaiting): FAIL "ready: pending [],
  want [0.1.1409 ... 0.1.1399]"; restored: ok.
- go test -tags nogui ./internal/gui/ ok (175s, TestCoreScriptBudget
  included). ./internal/update/: TestRelaunchStartsTheBundleWhenOpenNeverWorks
  red once at 30s while the disk was full and load ~50; -count=3 alone
  ok; filed #3499.
- GUI (Playwright 1.62.0, Chromium and WebKit, en and zh):
  whats-new (now a waiting 0.1.607 with 0.1.605/0.1.606 between, all three
  badged), whats-new-failed: 8/8 pass. segs-glide, update-check,
  update-hide, update-notes-ask, update-stuck, update-row-held,
  update-wait, i18n-keys, menu-scroll: 160/160 pass.
- gofmt -l clean; go vet ./...; GOOS=linux go vet -tags nogui and
  GOOS=windows go vet on gui and update; go build, GOOS=linux -tags
  nogui build, GOOS=windows build: all ok.

Not tried: the full go test ./... (the disk was full; other sessions'
builds hit ENOSPC); the real app against the live site with an update
waiting; gui-zh-tw/ja/de runs (no strings changed).
2026-10-24 22:54:36 +08:00
yetone 2b4c0664ee update: the fake open in the relaunch test keeps -n on Linux
TestRelaunchOpenTriedAgain was red on ubuntu CI at 27a8255fd (run
40004148936): opened "<bundle> --args tray", want "-n <bundle> --args
tray". The relaunch passed -n; the test's fake `open` lost it. It wrote
its arguments with echo "$@", and ubuntu's /bin/sh is dash, whose echo
takes a leading -n as its own flag. macOS's sh is bash, so it passed
there. The fake now writes them with printf '%s\n' "$*".

Run: in Docker golang:1.26.8 (GOTOOLCHAIN=local, -tags nogui) the old
test fails the same way as CI and the new one passes go test
./internal/update -run TestRelaunch; on macOS go test ./internal/update
-run TestRelaunch passes. Test-only change, no release.
2026-10-24 02:47:28 +08:00
yetone 27a8255fd7 update: the Mac relaunch opens a new instance (open -n), not a reopen of the gone one (Linka on Discord)
Linka's log (Discord, macOS 27.0.1, v0.1.1308) shows the cause of the
"magpie stays closed after updating itself" report that molvqingtai also
hit with the screen locked. After the old process's "Termination
complete", open found LaunchServices still holding the gone app as
running ("Specified target process 41267 does not exist"), so it sent
that process a reopen Apple event (aevt/rapp) instead of launching the
bundle, and failed with -600 procNotFound ("LAUNCH: Launch failed in
CSUI"). The retries from fb23bca5c asked for the same reopen each time.

Fix (internal/update/update.go): relaunchOpen is `open -n <bundle>`,
with `--args tray` when no window was up. -n asks LaunchServices for a
new instance, so it launches the bundle rather than look for a running
one. The retries and f3eb92924's direct start of the bundle's program
stay as the backup, with relaunch.log.

A magpie that really is up still has one instance: the new process
takes internal/gui's instance lock (a flock on app-<hash>.lock, keyed by
the program's path), finds it held and hands over (runningAlready): a
tray start ends, a window start asks the running one to show its window.

Other opens, checked: OpenBeside (a95f0b83f, the handover restart) uses
open -n already, and when it never starts the new version the handover
falls back to Relaunch after helloWait. The Codex app restart
(673651e8d, internal/agent/codex_app.go) opens another app and is
unchanged, as are the link and `open -b` handovers in instance_darwin.go.

Tests: TestRelaunchOpen wants -n in both commands, and
TestRelaunchOpenTriedAgain's fake open records its arguments and wants
"-n <bundle> --args tray". fakeOpen names the .app argument in its -600
text rather than $1. Red by hand: with -n dropped from relaunchOpen,
TestRelaunchOpen failed for both commands and TestRelaunchOpenTriedAgain
failed with opened "<bundle> --args tray"; green with it.

Real run: a scratch Lock.app (LSUIElement, ad-hoc signed) whose program
takes the same flock as holdInstance and logs its args. Real
`open -n Lock.app --args tray` twice, 1.5s apart: the first got
args=[tray] and held the lock, the second got args=[tray], found the
lock held and handed over. With one instance up, a plain
`open Lock.app --args tray` exited 0 and started nothing (routed to
the running one), the shape of Linka's reopen. The scratch app was
unregistered from LaunchServices afterwards.

Run at 17a2b00ef plus this change: gofmt -l internal/ (clean);
go vet ./... (darwin); GOOS=linux go vet -tags nogui ./...;
GOOS=windows go vet ./...; go test -count=1 ./internal/update (ok).
Rebased onto f4640c0ae (sessions GUI only); go test -count=1
./internal/update ok again at the pushed tree.

Not tried: a real update with LaunchServices holding a stale
registration (Linka's case) or with the screen locked; the real magpie
binary under open -n (the handover's OpenBeside has run that way since
a95f0b83f).
2026-10-24 02:32:29 +08:00
yetone a95f0b83ff gui: a restart to update hands the gateway to the new version (xuanwo on X)
Before, a restart to update ended the gateway, so it waited until no
agent request was in flight (#577). An agent busy for hours held the
update back, and Restart now cut its replies off. On a Mac and on Linux
the restart now starts the new version beside the old one and hands it
the gateway's listening socket. The new version takes every new
connection at once. The old one stops accepting, finishes the requests
it has (up to 15 minutes, as `make dev` already gave), then quits.
Nothing an agent sends is refused or cut short.

How (docs/subsystems/gui-shell.md, "A restart to update hands the
gateway over"):
- internal/handoff, new, darwin and linux. The old magpie opens a unix
  socket in a 0700 temporary folder and writes handover.json (fresh for
  2 minutes) in its config folder. The new one finds it, says Hello, and
  gets the listening socket by SCM_RIGHTS with the address, its pid and
  a callbacks socket. Only the same program (same path, same uid) is
  given it. When TMPDIR is too long for a socket path (sun_path is 104
  bytes on a Mac), the folder goes in /tmp (sockDir).
- gateway: Inherit/Listen serve on the socket given, and acknowledge
  once serving. HandOff gives the old one handedOffDrain (15m) instead
  of the 2s an ordinary end gives. A Claude Code run of the old magpie
  whose helper calls its tools on the port gets those calls passed back
  to the old one over the callbacks socket (forwardCallback, mcpCall,
  ownCallback). The bridge's turns are counted on their own
  (Busy.Bridge, BridgeLast).
- gui: restartInto calls beginHandover (OpenBeside `open -n` on a Mac,
  StartBeside for the binary on Linux). On the new version's ack, the
  old one hides its menu bar icon, panel, window and Dock icon (Mac),
  ends its backend, waits for its requests, and quits. OnShutdown
  leaves Codex's failover, the thread port and the install to the new
  one, which serves the gateway they point at.
- Never two on screen. Mac: the old one lets go of its instance lock
  just before giving the socket and takes it back if the handover
  fails, then hides on the ack. Linux: Wails holds the D-Bus name until
  exit, so the new one serves the gateway at once but puts its tray up
  only once the old pid has exited (awaitExit, 16m at most). Until
  then the old tray stays.
- What a handover can't carry: the subscription bridge's Claude Code
  turns live in the old process, so the restart still waits for those
  (restartBusy = blocking(Busy, true)), along with turns parked on
  tools. Every other request is not waited for. The update badge, the
  Updates page and Settings' "Restart automatically" say so, in every
  language in i18n.js.
- A handover that isn't made restarts as before: socket not opened,
  new version not started, no hello in 60s, no ack in 90s. Because the
  restart didn't wait for the requests in flight, it now waits for
  gatewayBusy to be idle (fallbackWait, 15m at most) before it quits
  and relaunches, so a failed handover never cuts a request.
- The overlap. The instance lock is handled as above. Both processes
  write: the sticky routing is flushed before the hand (FlushSticks),
  and files go through the existing locked or atomic writes. Counters
  (RPM, concurrency) are per process for the overlap (gateway-routing
  Constraints). OAuth refresh: the previous commit locks Codex's and
  the ChatGPT API's refreshes across processes. The rest were already
  locked or don't rotate (providers-accounts Constraints).
- Not changed: Windows (no SCM_RIGHTS; it restarts as before and still
  waits for idle, #577), `magpie web` (re-execs in place), and
  `make dev` (its own Handover). MAGPIE_NO_HANDOVER=1 turns it off.

Found by the sandbox run, fixed here: in run 2 the sandbox's long TMPDIR
made the socket bind fail ("bind: invalid argument"). The restart fell
back at once, cut the stream at chunk 6 (curl exit 18), and 4 of 381
requests got no answer over ~2s. Two fixes: sockDir (/tmp fallback), and
the fallback that waits for idle.

Tests (each red when broken by hand or on the old code):
- gateway/handover_test.go: TestHandedOverGatewayFinishesItsStream
  (drainFor without handedOff: "the old one ended with a stream in
  flight"; takeAck off: "the new one never said it serves").
  TestToolCallOfTheMagpieBeforeGoesToIt (mcpCall forward off: 404;
  ownCallback forwarding off: 401). TestInheritedForAnotherAddressIsLetGo,
  TestCallbacksSocketServesOnlyToolCalls, TestBridgeTurnsCount,
  TestSameAddr.
- handoff/handoff_test.go: TestHandOverListener, TestNoAckKeepsTheSocket,
  TestTakeOnlyAFreshOfferForThisProgram, TestCloseRemovesOnlyItsPointer,
  and TestOpenWithALongTemporaryFolder (red on the old Open: "bind:
  invalid argument").
- gui/handover_unix_test.go: TestRestartHandsTheGatewayOver, cross-
  process. The test binary re-execs as the new magpie. A stream through
  the old one finishes whole, requests during the restart are all
  answered, the next ones reach the new pid, and the old one quits only
  after its stream. On the old restart it is red: "quit with a reply
  streaming". TestHandoverNotMadeRestartsAsBeforeOnceIdle ("never says
  hello", "doesn't start") is red on the code before the fallback
  drain: "quit with a reply streaming" / "the restart didn't try to
  hand over".
- gui/handover_test.go: TestRestartWaitsForWhatAHandoverCantCarry,
  TestHandsOverOnlyWhereItCan.
- update/relaunch_open_test.go: TestOpenBeside,
  TestStartBesideWaitsForNothing.
- GUI: update-wait.test.cjs (the handover wording on the badge and
  page), update-restart.test.cjs (Settings' description).

Real run, Mac, sandbox (env -i, HOME and XDG_CONFIG_HOME in a scratch
folder, a long TMPDIR, MAGPIE_ADDR 127.0.0.1:63249, MAGPIE_UPDATE_FEED
pointed at a fake feed). The app is -tags production, ad-hoc signed,
bundle id com.yetone.magpie.sbhandover, built as 0.1.9001 and 0.1.9002.
autoRestart is on. A fake upstream streams 100 one-second chunks. The
real app found the update, downloaded and staged it, and restarted with
the stream in flight (run 3, at this change's tree before the rebase):
- 18:31:43, pid 59833 serves. 18:31:51, the new pid 60477 serves; v1
  logged "magpie 0.1.9002 (pid 60477) serves the gateway now".
- Requests: 375, failed 0. 19 were answered by 59833, then 356 by 60477.
- The stream got all 100 chunks, END and [DONE] at 18:33:24, curl exit
  0, 92s after the hand. 59833 exited within 3s of the stream's end.

Run at the pushed head (7a5bca443's tree, on origin/main f3eb92924),
one suite at a time, each log tee'd:
- gofmt -l internal/ cmd/: none. go vet ./... (darwin), GOOS=linux go
  vet -tags nogui ./..., GOOS=windows go vet ./...: clean.
- go test -count=1 -timeout 45m: internal/handoff ok, internal/update
  ok, internal/gui ok (95s), internal/provider ok, internal/gateway ok
  (367s).
- TestCoreScriptBudget: app.js is 1,338,901 of its 1,338,929. My
  additions first went 372 bytes over after the rebase; the badge's two
  wordings now share one args object and the comments I added were cut,
  with no budget raised.
- GUI (NODE_PATH playwright 1.62.0, both engines): i18n-keys, every
  update-*.test.cjs (update-wait 22/22, update-restart 22/22, update-stuck
  40/40 among them), gui-de, gui-ja, gui-zh-tw: all pass.
- f3eb92924 (the Mac relaunch's exec fallback) landed under this. A
  handover that never gets its hello falls back to update.Relaunch, which
  now carries that fallback; OpenBeside keeps open's tries only, since
  the old one is still running then and the fallback follows.
- Linux, Docker golang:1.26.8 with -tags gtk3 (before the rebase): the
  handoff package, the gui handover tests including the cross-process
  TestRestartHandsTheGatewayOver, and the gateway handover tests pass.
- Full GUI suite at f09e9a066 (before the rebases, load ~250 from other
  sessions): 11958 tests, 61 failed in 22 files. 13 pass alone (fonts,
  plugin-updates, rail-tip, routing-keys-fold, routing-mode-goes,
  routing-model-rest, routing-rule-remove, routing-went-on, search-keys,
  segment-press-dialog, sidebar-overlay-scrollbar, usage-overview-fold,
  usage-pack); load reds of this kind are #3393. 9 fail the same on
  origin/main 843417957, each filed: library-mcp-health-wsl #3350,
  quota-count-wrap and quota-name-translated #2228, quota-reads #2150,
  s3-sync #2448, usage-agents-hide #2276, usage-checkin #2549/#3091,
  usage-fold #2163, usage-ledger #3104.

Not tried:
- Windows: unchanged by design, nothing to run there beyond vet.
- A real Linux desktop app. The tests ran in Docker (above); the D-Bus
  wait (awaitExit) was not seen in a real tray.
- Whether the menu bar showed two birds for a moment on the Mac. B's
  tray goes up as it starts, and A hides on the ack, which follows B's
  first listen. They are close, but not ordered, and I didn't capture
  the screen.
- The Mac's real bundle id and LaunchServices registration
  (com.yetone.magpie), the real signed and notarised update, and real
  accounts (the run used a fake upstream).
2026-10-24 02:20:38 +08:00
yetone f3eb92924e update: the Mac relaunch starts the bundle's program when open never works (molvqingtai on Discord)
molvqingtai (Discord, 10-24): on macOS, magpie's restart after a
self-update still leaves it closed on versions after fb23bca5c, and only
while the screen is locked. Their 10-22 log (v0.1.1314) had the old
process exit 0 and `open` of the bundle fail ~160ms later with -600
(procNotFound), LaunchServices still sending to the gone process.
fb23bca5c tried that open again for ~13.5s (8 tries), and the report
says that isn't enough: LaunchServices can go on refusing for as long as
the session is locked, and the relaunch had nothing but LaunchServices
to start magpie with. With magpie closed, Prevent sleep is off too: the
Mac sleeps and the agents lose their connection.

Cause, as far as it could be checked: every route back went through
LaunchServices. A locked session was not reproduced here (the screen was
never locked), so "refuses for as long as it is locked" is the report's
shape, not something observed.

Fix (internal/update/update.go): relaunchCommand is now relaunchScript
over openWaits. The same open with the same pauses runs first; once the
last try has failed, the bundle's own program (Contents/MacOS/<the
CFBundleExecutable its Info.plist names, else this one's name, else
magpie>) is exec'd by the helper shell with RelaunchArgs: `tray` when no
window was up, `gui` when one was. That is what the Open at login launch
agent runs (ProgramArguments: Contents/MacOS/magpie tray), so it needs
nothing from LaunchServices. The shell is runAfterExit's, in a session of
its own (#2362); `exec` makes it the new magpie, so there is no shell
left to exit and take it with it. The instance lock is a flock on a file
keyed by the program's path, the same for open and for this start, so a
late open from LaunchServices hands over to the one already running.

Each try is written to relaunch.log in magpie's own folder
(appdir.Config(), ~/.config/magpie on the Mac): "magpie has exited;
opening <bundle>", then per try "open try N: exit S <open's stderr on
one line>", then "open gave up after N tries; starting <program> <args>"
or "no executable at <path>". The file is moved to relaunch.log.old past
64KB. A missing log folder writes nothing and changes nothing else.

Tests (internal/update/relaunch_fallback_test.go), with fakeOpen from
relaunch_retry_test.go first on PATH answering with the -600 text and a
fake bundle whose program writes the arguments it got:
- TestRelaunchStartsTheBundleWhenOpenNeverWorks: through runAfterExit
  after a gone pid, open refused every time; the program runs with tray
  (no window) and gui (window), after len(waits)+1 opens.
- TestRelaunchLogsEachTry: the log has the opening line, each try's exit
  status with open's -600 text, and the fallback's program and args.
- TestRelaunchOpenedStartsNothingElse: open working on try 2 is the
  whole relaunch; the program isn't also run; the log says exit 0.
- TestRelaunchNoProgramIsLogged: a bundle without its program is
  logged and the shell exits non-zero.
- TestRelaunchRunsTheProgramInfoPlistNames: "magpie dev" from
  Info.plist, in a bundle path with a quote in it.
- TestRelaunchLogInMagpiesFolder: the log is under XDG_CONFIG_HOME's
  magpie, and is moved to .old past 64KB.
Red by hand: with the fallback replaced by the old `|| exit 1`,
StartsTheBundle timed out at 30s ("the new version starting never
happened"), and LogsEachTry, NoProgramIsLogged and
RunsTheProgramInfoPlistNames failed; with note() a no-op, LogsEachTry, OpenedStartsNothingElse
and NoProgramIsLogged failed. All green with the fix.

Real run: a relauncher built from this tree calling update.Relaunch on
a scratch Scratch.app (CFBundleExecutable scratch, a script writing a
marker), under env -i with a sandbox HOME and an `open` first on PATH
that always fails with the -600 text. The relauncher exited at once;
relaunch.log under the sandbox's ~/.config/magpie had 8 tries 02:02:45
to 02:02:59, each "exit 1 _LSOpenURLsWithCompletionHandler() ... -600.",
then "open gave up after 8 tries; starting '.../scratch' 'tray'". The
marker: args=tray ppid=1 pgid=pid (own group), no tty, and still alive
3s later, after the relauncher and its shell were gone.

Run at 843417957 plus this change: gofmt -l internal/ (clean);
go vet ./... (darwin); GOOS=linux go vet -tags nogui ./...;
GOOS=windows go vet ./...; go test -count=1 ./internal/update (ok).
The full suite (-timeout 45m) was started on this tree before the push
and had not finished; per the owner's ship-at-once rule this didn't wait
for it.

Not tried: a real update with the screen locked (the screen here was
never locked), so whether the program started by path comes up under a
locked session is not seen, only that the login agent starts it the
same way. Not tried with the real magpie binary in the scratch bundle
(it would read the Keychain): the tray and the instance lock under this
start are the login agent's path, not observed here. An open that exits
0 while magpie doesn't come up isn't covered; relaunch.log will show it.
2026-10-24 02:05:05 +08:00
yetone fb23bca5c9 update: the Mac relaunch tries open again while it fails
molvqingtai's system log (Discord): v0.1.1314 updated itself at 00:43:49,
the old process exited 0, and ~160ms later `open` of the bundle failed
with -600 (procNotFound): LaunchServices still sent to the process that
had exited (the screen was locked). runAfterExit ran open once, nothing
looked at its status, and magpie stayed closed until a manual launch at
09:45.

Relaunch now runs relaunchCommand: the same open, tried again after
pauses of 0.5 1 1 2 2 3 4 seconds (13.5s, 8 tries) while it exits
non-zero, and not again once it succeeds. The detached own-session
shell (#2362) is unchanged. The new instance is not confirmed running
beyond open's exit 0.

Sibling, not changed: RelaunchBinary (Windows, Linux) starts the new
binary itself while this one is still up, with no open after exit; on
Windows with the old binary moved aside, startChecked already waits 20s
for the new one to say it is up and puts the old back otherwise. ayu's
"restart to update needs several clicks" is not this shape (candidates:
the install held by another program, or the busy-gateway wait) and needs
its own look.

Tests (internal/update/relaunch_retry_test.go): a fake `open` first on
PATH refuses its first tries with the -600 text.
- TestRelaunchOpenTriedAgain: relaunchCommand after a gone pid opens on
  the third try. Old code: FAIL "open was tried 1 times and the new
  version never opened" (30.04s).
- TestRelaunchOpenGivesUp: a refusing open ends after len(waits)+1 tries;
  one that works on the second is not run again. Broken by hand (no
  `&& exit 0`): FAIL "open tried 4 times, want 2".
- TestOpenWaitsTotal: waits add to 10-15s. Broken (0.5 1): FAIL "waits
  add to 1.5s".
Real open: the same loop with /usr/bin/open on a scratch .app that
appeared after 2s failed 3 times ("does not exist", exit 1) and opened
it on the 4th, the app got --args tray.

Record for this push: 13 commits on origin/main ca4a1cde0, head tree
539c84e92. Go 1.26.8, sandbox HOME, GOMODCACHE/GOCACHE pinned. The full Go
run and vet were at tree d6393dfc8, the same Go code as this head: only
app.js comments (cut under the core script budget) and one ja string
changed after it.
- gofmt -l: nothing. go build ./...; go vet ./... (darwin), GOOS=linux
  go vet -tags nogui ./..., GOOS=windows go vet ./...: clean.
- go test -timeout 45m ./..., through tee, one suite on the machine:
  68 packages ok. The one red was internal/gui's
  TestCoreScriptBudget: app.js 1,335,314 > 1,335,000, since main grew
  app.js under the stack. The autoscroll commit's own comments were cut
  (to 1,334,629) rather than the budget raised, and go test -count=1
  ./internal/gui is ok at this head (113s). Packages the run took from
  Go's test cache had the same inputs.
- GUI: the 18 files this stack touches or names, both engines,
  202 of 204 pass (tree 068acf128, this push less the last commit). The
  two reds: gui-ja, red on main since c2636b7b5 and fixed by this push's
  last commit (gui-ja and i18n-keys 6 of 6 there), and usage-fold's
  chromium "several accounts" (#2163, red on main the same way).
- internal/update ok, with TestRelaunchOpenTriedAgain, TestRelaunchOpenGivesUp
  and TestOpenWaitsTotal. GOOS=linux and windows builds are covered by vet.
  The whole GUI suite ran at 1c1fc7183 (this stack's first 12 commits on
  0ddcf28a1): 11713 of 11769 pass. Each of the 21 red files was then run
  alone at the stack and at origin/main 8278fd9b0. Eight are red the same
  way on main: plugin-card-update (#3079), quota-count-wrap and
  quota-name-translated (#2228), s3-sync (#2448), usage-agents-hide
  (#2276), usage-checkin (#3091), usage-fold's chromium "several
  accounts" (#2163), usage-ledger (#3104). The other 13 pass alone on both
  and were red only under that run's load (50 to 335): currency #3101,
  plugin-github #3218, provider-fetch-again #3292, rest-try-now #2564,
  routing-auto-reset #3293, routing-keys-fold #1612, routing-steady #1804,
  routing-wb-restricted #1905, sessions-folder-delete #2218,
  sessions-manage #3294, switch-only #3295, text-size #1866, usage-pack
  #3296.

Not tried: a real update on a real Mac, or a real -600 from
LaunchServices; nothing on Windows.
2026-10-23 01:58:00 +08:00
yetone 86254d4049 tests: an unreachable upstream is 127.0.0.1:1, not a closed server's port
TestCodexOwnModelUnreached went red on ubuntu CI at 0ddcf28a1 (run
39742463965, shard 2): it closed an httptest server and pointed
codexAPIBase at its URL, Linux handed that port to another test's server
at once, and its fake answered "pong" with 200 instead of the dial error
the test is about. The same class as 9a852ae9d and d0ccbbebc.

Both tests that took a dead URL from a closed server now use
http://127.0.0.1:1: refused at once on every OS, and no test can listen
on it (privileged on Linux and macOS, unused on Windows). The sibling is
TestMirrorFailuresAreTheMirrors in internal/update, whose "gone" mirror
had the same race.

Run at this tree: go test -count=3 -run
'TestCodexOwnModelUnreached|TestMirrorFailuresAreTheMirrors'
./internal/gateway ./internal/update: ok; go test ./internal/update: ok;
gofmt -l none; go vet for darwin, linux, windows: ok. The reuse itself
wasn't injected; the CI log's 200 "pong" body is the evidence.
2026-10-22 16:27:54 +08:00
yetone 40dee51751 update: on Windows a download an antivirus holds is waited for up to 30s, and a restart tried again doesn't trial-start it again (白菜 on Discord)
白菜 (Discord #general, 10-19): with magpie on the Desktop, every click
on Update says it is restarting and then offers the update again;
clicking again never gets it in, only a fresh download from the site
does.

Cause, as far as could be shown: the install starts the download
suspended first (canStart, #894). An antivirus that checks a program as
it starts holds the file a while after, and the move into place gave up
after asideWaits' ~3s (#2272's fix). The swap failed, the old exe was
put back, the state stayed ready and the pill said 更新失败, with the
reason only in its tooltip. A click again ran the trial start again, so
the antivirus held the same file again and it failed the same way every
time.

Change:
- moveIn and moveAside go on trying, at the last pause (1.5s), while
  Windows says the file is held open (errors 32/33), up to heldFor (30s)
  from the first try. Other errors still stop after the short pauses.
- InstallBinaryAside trial-starts a download once: the same path, size
  and mtime that passed isn't started again on a retry. A new download
  is.
- A download still held after that says so ("another program still has
  the download open (often an antivirus checking it): let magpie through
  it…"), without the paths, in the version row and the pill's tooltip.
  It still unwraps to the *os.LinkError and the sharing violation.

Tests:
- TestMoveAsideWaitsOutALongHold (all OSes): 10 held tries then success.
  A permission error still stops at 4.
- TestInstallBinaryWaitsOutALongHold (Windows): a real handle holds the
  download for 600ms against 2 short pauses.
- TestInstallBinaryTrialsADownloadOnce (Windows): one trial for a retried
  download, a second for a new one, and the new error text.
- Existing tests that hold a file for good set heldFor to 0.

What was run:
- Broken by hand (no wait past asideWaits, trial on every try): all
  three new tests red on the Windows box. TestMoveAsideWaitsOutALongHold
  is red on macOS too. Restored: green.
- Windows box (10.0.26200, Defender on), cross-compiled update.test.exe
  in a sandbox USERPROFILE/APPDATA/TEMP: the whole internal/update
  package PASS (41 tests).
- Real GUI on the box: a production build (v0.1.9000) at
  C:\Users\yeton\Desktop\magpie-windows-amd64.exe, a sandbox home, a
  local feed offering v0.1.9001. The .new was held open from PowerShell
  (FileShare Read) for 12s, then POST /api/update/install {when:now}:
  - origin/main's build: install failed, "rename … being used by another
    process", state ready, old process ran on;
  - this build: the new version started 1s after the hold was let go,
    and the Desktop exe's hash is 9001's.
- The same setup without a hold, origin/main's build, worked: plain
  Desktop, and a Desktop folder named 白菜 测试 with "(1)" in the exe
  name. A non-ASCII path or the Desktop alone is not the cause.
- gofmt clean. go vet ./... clean for darwin, linux -tags nogui and
  windows.
- HOME=<sandbox> go test -timeout 45m ./... at load ~260-290: every
  package ok except these.
  - internal/agent and internal/gateway timed out at 45m. Already filed
    as #2544 and #2870.
  - internal/gui's TestSetAnswersWhileDevinAndProvidersHang (19.8s set
    under load) is filed as #1375. Rerun alone with the update, restart,
    install and relaunch tests: ok.
  - internal/update was rerun separately, because its source was swapped
    to origin/main's for ~1 min mid-run to build the comparison exe: ok.

Not tried:
- A real third-party antivirus (360, Huorong). The hold is injected. The
  user's version, antivirus and exact error are still unknown, and were
  asked for on Discord.
- A OneDrive-redirected Desktop.
2026-10-20 01:16:38 +08:00
yetone c68270dae7 update: a Mac opened from the Dock or Finder comes back after "Update and Restart", not quits for good (#2362, danbo610)
update.Relaunch left the shell that waits for magpie to exit and then
runs `open` in magpie's own process group. launchd ends a job's process
group when its process exits, so the shell died with magpie and the new
version never opened. ee16c657 fixed this for the Open at login agent
only (AbandonProcessGroup in the plist magpie writes). The job
LaunchServices makes for an app opened from the Dock or Finder carries
no such key, and on the reporter's macOS 13 (Intel, 0.1.1250) the
restart quit and nothing came back until a manual launch. The shell now
starts in a session of its own (detach, as RelaunchBinary's helper on
Windows and Linux already does). That holds for both job kinds, however
the previous version was started.

Tried on this Mac (macOS 26.2) with throwaway jobs, all removed after:
- A LaunchAgent without AbandonProcessGroup (a Go parent starting the
  same wait-then-run shell, then exiting): the shell in the parent's
  group never ran; one with Setsid did.
- A Cocoa .app opened with `open`, relaunching itself through the same
  shell: macOS 26 didn't kill the group, and both inherit and setsid
  relaunched. The application-job half is the reporter's macOS 13
  observation (their isolated A/B matches the agent case above). It
  was not reproduced on this OS.
- A setsid shell's `open` relaunched the .app fine (open rc 0, new pid).
Not tried: a real magpie update on macOS 13. No such machine here.

Siblings: RelaunchBinary (Windows, Linux) already detaches its child
through launch. Reexec (magpie web) runs in place. No other code
waits for magpie's pid and then opens it.

Tested: TestRelaunchOutlivesItsJobsGroup. A child of the test leads a
process group as a job's process does, starts the helper through
runAfterExit and exits. The test then kills the group as launchd does,
and the helper must still run its command. With detach(cmd) removed it
fails: "the relaunch helper died with the job's process group: the new
version was never opened" (15s). Restored, it passes (1.06s, 3 of 3).
go test -tags nogui -p 1 ./internal/update ok. gofmt -l clean. go vet
-tags nogui (darwin, GOOS=linux) and GOOS=windows go vet on
./internal/update ok.

Full suite: SUITE_LINE
2026-10-15 23:08:02 +08:00
yetone c644d9f1d2 update: the downloaded binary is moved into place again while something still holds it after the trial start, not failed at once (#2272, JasonBuildAI)
InstallBinaryAside starts the download suspended (trialStart), ends
it, sets the running exe aside and renames the download over it. A
program that checks an executable as its process starts (an antivirus)
can hold the file a moment after the process has ended, and the rename
then fails with a sharing violation; the report says the first install
of every update failed this way. The rename (and the put-back of the
old exe on failure) now goes through moveIn, which tries again over
asideWaits (100 ms to 1.5 s) while Windows says the file is held
(errors 32/33), as moveAside already does for the running exe. Any
other failure is returned at once. The Windows CI step now runs the
trial tests too (TestTrialStart and the new ones).

What was run:
- Windows box (Windows 10.0.26200 x64, Defender real-time on, a
  cross-compiled update.test.exe in a temp dir with a sandbox
  USERPROFILE/APPDATA/LOCALAPPDATA/TEMP):
  - TestInstallBinaryWaitsForHeldDownload (new; the download held open
    for 150 ms): old update.go FAIL "rename ...magpie.exe.new
    ...magpie.exe: The process cannot access the file because it is
    being used by another process."; new PASS (0.31 s).
  - TestInstallBinaryRightAfterTheTrial (new; real trialStart, then the
    install) and TestTrialStart pass on old and new code there.
  - The whole update package passes; the CI pattern
    ^(TestInstallBinary|TestMoveAside|TestTrialStart) passes.
  - Rollback tests now use 1 ms waits so a file held for good fails
    fast.
- The real update, in a sandbox: v0.1.1243's magpie-windows-amd64.exe
  run as `magpie update` twice in separate sandbox homes: both updated
  to 0.1.1244, exit 0.
- macOS: gofmt -l clean; go vet darwin, GOOS=linux -tags nogui,
  GOOS=windows clean; go test -p 4 ./... (see the last commit of this
  push for the result).
Not reproduced: the hold itself. On this box the real trial-then-
install path succeeded every time (10/10 with a 12 MB exe, 10/10 with
a 74 MB magpie.exe, 2/2 real updates), and origin/main's TestTrialStart
passed 3/3. The fix is verified with an injected hold, not a real
antivirus one.
2026-10-15 10:10:18 +08:00
yetone fbb7e2cbd4 gui, update: Settings' Restart automatically restarts into a downloaded update once no agent request is in flight (#2096, xiaozhu1337)
#2096 asks for a setting that installs and restarts whenever an update is
there. Settings > About gets "Restart automatically" (Off/On), off by
default: a restart ends the window, and whatever an agent sends during it
waits for the gateway to come back.

When on, and Automatic updates is on, the updater's minute loop sees a
"ready" update and starts the same idle wait the Install-when-idle button
uses (waitIdle: 10s with nothing in flight, at most 1h). Cancelling that
wait from the GUI skips that version, so the next one is restarted into
again. The app (window or tray) and `magpie web` are covered; serve and
daemon have no in-process updater and are not. On the Mac, a restart the
app made by itself reopens to the menu bar icon only (`open … --args tray`)
when no window was shown, rather than popping a window up unasked
(update.Relaunch takes a window flag; relaunchOpen builds the command).
With Automatic updates off the row is dimmed and reads "While automatic
updates are on", like Check every.

Run:
- go test: internal/gui (-tags nogui, full package, 273s), internal/update,
  internal/settings, internal/cli — ok, with set -o pipefail.
- New: TestAutoRestartWaitsForIdle, TestAutoRestartNeedsAReadyUpdate,
  TestAutoRestartCalledOff, TestRelaunchOpen.
- Broken by hand: without autoTick, WaitsForIdle and CalledOff fail;
  without the autoSkip assignment, CalledOff fails; restarting without
  the idle wait fails WaitsForIdle and CalledOff; without prefsKeep's
  autoRestart, update-restart.test.cjs fails 11 of 11.
- gofmt -l clean; go vet and go build for darwin, GOOS=linux -tags nogui
  and GOOS=windows on internal/gui, update, settings, cli.
- GUI: new update-restart.test.cjs, chromium and webkit, 1100 and 420,
  en/zh/zh-TW/ja/de (22 pass, twice); update-*, i18n-keys and settings*
  in both engines: 253 pass, 0 fail.
- Found on the way, filed as #2134: in WebKit at 420, turning Automatic
  updates off scrolls a view at its top by ~2px (the Version row's sub
  grows). The test checks the clicked control holds still instead.

Not tried: a real update or relaunch (no real install was touched), the
tray-only reopen on a real bundle, Windows/Linux restarts by hand.
2026-10-14 15:19:14 +08:00
yetone fa44fde461 netproxy: a proxy's user and password stay out of every log line, error and status that names it (#1886)
What: netproxy.Redact is the one place a proxy address is made fit to
show. It is the rule 708ae4144 (#852) gave the Settings status
(proxyAddress, now Redact): the userinfo is left out, the rest kept as
written (no scheme added to one written without), a malformed address
"". Every place a proxy value reached text now goes through it:
- provider/logins.go: the switch's "Claude Code sessions ... go through
  <user>'s proxy" log line (#1886's first).
- provider/claude_proxy_env.go: "<user>'s proxy is SOCKS" (#1886's
  second).
- agent/codex_proxy.go + reach.go: the proxied drift's Detail and Addr,
  shown in the GUI's pill and dialog; Codex's proxy comes from
  HTTP_PROXY/ALL_PROXY/the system, which can carry a user:password.
- update/mirror.go: CheckProxy's error echoed the raw --proxy value
  ("not %q"); it now names it redacted, or not at all when malformed.
- netproxy.Describe already went through it.

Why: an account proxy like http://alice:s3cret@10.0.0.2:8080 landed in
magpie's log, which users paste into issues and Discord.

Swept and left alone: settings.CheckProxy's error names no value;
netproxy.DialSOCKS's error names the host only; Go's transport errors
(proxyconnect, socks connect) name host:port, not userinfo; the GUI's
provider editor and Settings field return the proxy whole as the
user's own editable value; env injection (EnvWith, ForBun, wslrun)
must carry it whole.

Tests place the credential where the user writes it: http, https,
socks5, socks5h, with and without a scheme, percent-encoded user and
password, user alone, malformed. TestRedactLeavesOutUserAndPassword,
TestClaudeAccountProxyLogsNoCredentials (captures the log over real
switches; Claude Code's HTTPS_PROXY still gets the proxy whole),
TestCodexProxiedDriftShowsNoCredentials (the probe still goes through
the whole proxy), TestCheckProxyErrorShowsNoCredentials.

Run: each site reverted alone turns its test red (logins.go,
claude_proxy_env.go, reach.go, codex_proxy.go, mirror.go; Redact
keeping the userinfo turns Redact and Describe's tests red). gofmt -l
clean; go vet ./... on darwin, GOOS=linux -tags nogui, GOOS=windows.
go test ./... at 0dd821c13 + this, sandbox HOME: 47 packages ok;
agent, gateway and library timed out at 10m on a machine at load ~20,
then on rerun hit ENOSPC (the disk filled from other sessions). Rerun
with space: library ok in full; agent's TestClaudeOutputTokens and
gateway's TestGroupFirstTokenFailsOver (the ENOSPC ones) ok, with
every Proxy/Proxied test in both. Not tried in the GUI by hand.
2026-10-13 10:49:44 +08:00
yetone 6876125a19 agent, library: an npm agent or winget's RTK under Program Files updates after Windows' administrator prompt, and says why when it can't (新v学员 on Discord)
On Windows the official Node.js installer leaves npm's global prefix at
C:\Program Files\nodejs, which only an administrator can change. magpie
runs as the user, and writable() on Windows always said true, so the
Agents page offered the update and npm failed with EPERM (mkdir
...\node_modules\@scope), with nothing saying why. The same user then
reported RTK and other actions needing elevation all failing, and asked
for a setting to run magpie as administrator. There is no such setting:
an elevated magpie would write the agents' configs as the administrator,
couldn't start with Windows without a UAC prompt at each login, and
widens what can go wrong. Instead each action that needs an administrator
asks Windows for one, alone.

- agent: writable() on Windows makes and removes a file in the folder
  (update.Writable) instead of always saying yes. An npm CLI in a folder
  the user can't write in is still offered on Windows, marked Admin, and
  its update runs through update.RunElevated, never as the user. Elsewhere
  (/usr/lib, would want sudo) nothing is offered, as before.
- update: RunElevated (Windows) runs the command through
  ShellExecuteEx "runas" on a .cmd script that sets the env that differs
  from an elevated process's own plus PATH, cds to the folder, and sends
  output to a log read back; the exit code comes from GetExitCodeProcess
  (a non-zero one is update.ExitError, for its code). A declined prompt is
  ErrCanceled; no prompt to be had is the new ErrNoAdmin. Other systems:
  CanRunElevated false.
- library: RTK installed by winget for every user (under Program Files)
  is upgraded through the same prompt when only an administrator can
  change rtk's folder; the card's Upgrade title says Windows asks first.
  Install, and an upgrade whose folder looked writable, run winget as the
  user and go through the prompt only when winget answers 0x8A150019
  (command requires admin). winget's codes from the elevated run are read
  as before (0x8A15002B: no newer RTK, no failure).
- A declined or impossible prompt is agent.AdminError (Via npm or
  winget); the GUI answers it with code needs_admin and says, in the
  reader's language, what needs an administrator and what to do: try
  again and allow it, or run the command in a terminal opened as
  administrator, and for npm also moving npm's prefix
  (npm config set prefix "%APPDATA%\npm") and reinstalling.
- Install another agent: its npm commands note when npm's prefix
  (npm prefix -g, memoized) is such a folder.
- Checked, not changed: autostart uses HKCU's Run key, no admin needed;
  magpie never runs npm uninstall; plugins install into magpie's own
  folder with bun; agent CLIs update only on a click; RTK's PATH fix
  writes HKCU's Environment and rtk init -g the user's own agent folders;
  the library's only other exec is the MCP server check.

Run:
- go test -tags nogui ./internal/agent ./internal/update ./internal/library
  (and the full ./... under the lock). TestNPMUpdateNeedsAdmin fails with
  the admin branch removed and with runAdmin bypassed;
  TestRTKUpgradeAsksForAdmin and TestRTKInstallRetriesAsAdmin fail with
  runRTKInstaller never elevating (checked by hand).
- gofmt -l; go vet (darwin), GOOS=linux and GOOS=windows go vet.
- GUI, Chromium and WebKit: cli-update-admin (en, zh), library-rtk-admin
  (en, zh exact; ja, de, zh-TW translated, no npm advice; fails with the
  old Upgrade title), library-rtk-upgrade/-path/-nohook/-gain, gui-ja,
  gui-de, gui-zh-tw, cli-update, i18n-keys.
- Windows box (10.0.0.132): TestWritableSeesDeniedFolder passes, and fails
  on the old writable(). A portable Node 22 with Program Files' ACL
  (Users RX, Administrators F): as a non-elevated token (runas
  /trustlevel:0x20000) npm install -g failed with the reporter's EPERM,
  Writable said false, and dsh's CLI() said Via npm, Admin true; elevated
  it said Admin false. RunElevated from the elevated ssh session installed
  @deepseek-ai/dsh into that folder for real, and a missing version came
  back as exit status 1 with npm's ETARGET output. The library's RTK tests
  ran there too (TestRTKInstallRetriesAsAdmin passes; the shell-fake ones
  skip on Windows).
- Not tried: the UAC prompt itself, allowing or declining it, as nobody
  sits at the box; the ErrNoAdmin path on a real system; a real
  machine-scope winget RTK (none is installed on the box).
2026-10-11 05:33:23 +08:00
yetone 9bad11449b proc, update: an agent installed in a folder only fish's config adds is found when the terminal opens fish but the login shell is zsh or bash (John on Discord)
John on Discord: 二进制文件没有从用户环境变量找到,我终端环境使用的fish. The desktop
app gets launchd's PATH and asks the login shell ($SHELL) for its own.
fish isn't a POSIX shell, so many keep zsh or bash as the login shell and
have the terminal open fish (its profile setting, or exec fish from
.zshrc). magpie then asked only zsh, and a claude or codex in a folder
config.fish adds (fish_add_path, set -gx PATH) wasn't seen.

The suspected cause, fish joining "$PATH" with spaces, isn't it: PATH is a
path variable in fish and is joined with ':' in double quotes. Checked with
real fish 4.9.3 (macOS), 3.6 and 4.0.2 (Debian, Docker) under -ilc with
the probe's printf and \0: PATH whole, the variables in place. With
SHELL=fish the old code already found the agent.

- shellEnv asks fish and nushell too, in parallel with the login shell,
  when they are installed and their config folder exists (each makes it
  on its first run) and they aren't the login shell. Their PATH folders
  come after the login shell's; a variable of agentenv.Vars the login
  shell leaves empty is taken from them.
- proc.FindShell finds a shell in the system's, Homebrew's, MacPorts',
  Nix's, ~/.local/bin and cargo's folders, then /etc/shells, then PATH.
  Settings > Command line (update.installedShells) uses it too, so a fish
  from MacPorts or Nix is listed there as well.
- The shellProbe comment now says why fish's "$PATH" is right.

Tests: TestShellEnvAsksFishBesideLoginShell (a fake fish answering with
the bytes real fish 4.9.3 printed) and TestShellEnvRealFish (real fish,
skipped where it isn't installed) fail on the old shellEnv:
  PATH = "/from/zsh:/usr/bin:/bin", want the login shell's first and
  fish's folder after
  PATH = "/usr/bin:/bin", want fish's ".../fish bin" in it
TestShellEnvLeavesUnusedFish and TestShellEnvFishLogin cover fish with no
config and fish as the login shell.

Run: internal/proc shell tests on macOS with the downloaded fish 4.9.3 and
on Linux (golang:1.26.8 + Debian fish 4.0.2) all pass; go test ./...
under a temp HOME: all pass except gateway (10m timeout under load; the
failing TestClaudeUnloadableSessionStartsAnew passes alone) and gui
TestOTelPreferencesAPI (TempDir cleanup race, passes alone -count=3),
neither touching this code; gofmt -l clean; go vet and GOOS=linux,
GOOS=windows go vet on internal/proc and internal/update clean.
Real use: a sandbox magpie (go build -tags dev, own HOME, ports
3486/3487, launchd-like PATH=/usr/bin:/bin:/usr/sbin:/sbin, SHELL=/bin/zsh
with no .zshrc, fish at ~/.local/bin/fish, a fake claude only in a folder
config.fish adds with fish_add_path): the old build reports no claude in
/api/agents/cli and /api/state; this one finds it (version 2.1.99 of the
fake). With SHELL=fish both builds find it.
2026-10-10 21:42:00 +08:00
yetone e5f04f38e8 plugin: a plugin on a pre-release whose release is out shows the update on its row, as the Plugins dot already did; versions are ordered as semver orders pre-releases, in Go and in the page
The Plugins dot comes from update.Newer, and the Installed rows (chip,
Update, Update all) from plugins.js's own newer(). They disagreed:

- newer() read only x.y.z, so 2.0.0-beta.1 with 2.0.0 out had the dot
  and no row to update it from. Real case: opencode-antigravity-auth,
  whose latest is 1.6.0 after 1.6.0-beta.0..2.
- update.Newer compared pre-releases as strings, so 1.0.0-beta.10 came
  before 1.0.0-beta.9 (and 1.6.0-10 before 1.6.0-9): a missed update,
  and the other way round, an "update" to an older beta.
- update.Newer didn't parse build metadata, so 1.0.1+build.1 was never
  newer than anything.

Both now order as semver §11: no pre-release comes after any;
identifiers compared one by one, numbers as numbers, a number before a
word, and a shorter list before a longer one it starts. Build metadata
is ignored. A version that isn't x.y.z is never newer, as before.

Tests:
- internal/update TestNewer gains the pairs. On the old Newer 4 fail
  (beta.10/beta.9 both ways, 1.6.0-10/-9, +build).
- internal/gui/tests/plugin-prerelease.test.cjs: seven installed
  plugins, the dot's waiting list as update.Newer gives it, and each
  row's chip and Update button, plus the Update all count, must match.
  On the old plugins.js it fails at "v2.0.0 out" in both engines. No
  strings change, so it's English only.

Reproduced in a sandbox HOME with the real package:
`magpie plugin add opencode-antigravity-auth@1.6.0-beta.2`, then Check
for updates. Before: /api/plugins/updates listed it, and the Plugins
nav had the dot, but the row had no chip and no Update, and there was no
Update all. After: the row shows "v1.6.0 out", Update, and Update all (1).
Update all then installed 1.6.0 and the waiting list emptied.

Run: gofmt; go vet -tags nogui for darwin, linux and windows on
internal/update, internal/plugin, internal/gui and the root package; go
test -tags nogui of the root package, internal/{gui,plugin,provider,
stats,update} under a temp HOME; GUI tests plugin-prerelease,
plugin-updates, plugin-card-update, plugin-check-updates, plugin-market,
plugin-release, plugin-git and plugin-local in Chromium and WebKit.
2026-10-10 10:28:49 +08:00
yetone 599d784f59 library: magpie-image runs this computer's magpie, whatever path another computer or an old install saved (#1439, dawn1095)
magpie-image was kept in library.json with one computer's magpie by full
path (os.Executable at install). A WebDAV sync carried
C:\Users\...\Downloads\magpie-windows-amd64.exe to a Mac (and a Mac's app
to Windows), and a magpie moved out of Downloads left its old path behind:
the Library page said it couldn't start, and agents were given a program
that isn't there.

- heal (self_here.go): a server that is magpie's own -- `mcp ...` run by a
  program named magpie (magpie, magpie.exe, magpie-<os>-<arch>[.exe]) --
  whose program isn't an existing absolute path here is pointed at this
  magpie, as the library is read (load) and after every change (so a
  bundle Put from another computer is healed before it is written into
  the agents). Every agent writer, project MCP files, the WSL side and
  CheckServers read through load, so all of them get it. A magpie program
  that does exist here (another build) and any server run by another
  program are left as they are.
- Collect carries magpie's own server as plain "magpie": two computers
  with the same library carry the same bundle, so davsync's library hash
  matches and a sync doesn't write one's path over the other's.
- The path given is update.Program (exported cliProgram): the AppImage
  rather than its mount, Homebrew's opt link rather than the Cellar.
- TestWSLMagpieImage now says which magpie this (simulated Windows)
  computer runs.

Verified:
- New tests: TestOwnServerFromElsewhereRunsThisMagpie (Windows path read
  on macOS, a Mac path, an exe moved out of Downloads, a bare "magpie"),
  TestUsersOwnServerStaysAsItIs, TestCarriedOwnServerIsEachComputersMagpie.
  Broken by hand five ways (heal off; no heal in change; no marker in
  Collect; ownServer matching every server; existing magpie builds not
  kept) -- each went red with a FAIL naming the behaviour, green restored.
- gofmt -l clean; go vet -tags nogui ./...; GOOS=linux and GOOS=windows
  go vet (library, update, davsync); go build, GOOS=linux -tags nogui and
  GOOS=windows builds; go test -tags nogui ./... green in a sandbox HOME.
- Sandbox app (own HOME, ports 3561/3562) seeded with a library.json
  holding the reporter's Windows path for magpie-image plus a user's own
  missing Windows tool: on start library.json, Codex's config.toml and
  Claude Code's .claude.json got the running binary; /api/library/mcp/check
  answered magpie-image ok with 3 tools, the user's server unchanged and
  notfound.
Not verified: on the Windows box, or a real two-computer WebDAV sync.
2026-10-10 01:30:40 +08:00
yetone 06420a7121 tests: a fake program is a file macOS has already let run (testenv.Program), so a fake's first start no longer eats a test's wait under load
macOS checks a newly written executable before its first exec: 0.27s
alone, 2-5s while other new programs start (a go test ./... starting its
test binaries). The same file again takes 0.009s, and the pass is kept
across a rename and an in-place rewrite. 108852b4 worked round this for one
test with /bin/sh -c; the class was every test that writes a `#!/bin/sh`
fake and times its answer.

testenv.Program(t, path, script) replaces os.WriteFile(path, script, 0o755)
for fakes. On macOS it renames a file that has run once from a pool to path
and writes the script into it in place; at the test's cleanup the file goes
back to the pool (only a path the test created; a stand-in it wrote over
stays). Fakes still end with their tests: nothing about how they are
started or waited on changed. Run (and gateway's TestMain) remove the pool
at the end. TestMain's PATH stand-ins are run once in the background
(testenv.StandIns). Other systems write the file as before.

Converted every `#!/bin/sh` fake written by tests under internal/ (agent,
gateway, gui, library, plugin, proc, provider, update). Windows, binary
and node/bun fakes are unchanged.

Under the same load (3 loops each starting 8 freshly written scripts at a
time), 4 rounds each, before (108852b4 / origin/main) vs after:
- provider TestSavedButSignedOutClaudeServed: 4/4 fail (8.01s) -> 4/4 pass
- provider TestClaudeSignInOverStaleCredentials: 4/4 fail (5.00s) -> 4/4 pass
- provider TestDevinSignedInOnlyInMagpie: 3/4 fail ("CLI's own []") -> 4/4 pass
- gateway TestClaudeRunEndsWhenTheClientLeaves: 4/4 fail -> 4/4 pass
  (and 3/3 fail -> 3/3 pass at a third of that load)
- gateway TestClientGoneRecordedAsCanceled: 4/4 fail -> 4/4 pass
- gui TestProvidersAnswerWhileListsComeIn ("cursor found false" at 3.03s):
  4/4 fail -> 4/4 pass. The same class, not bfe8bcaf's test order.
- proc TestUserPath (login shell's PATH never came, 7.01s): 4/4 fail ->
  4/4 pass
Unloaded, every touched package passes; no pool directory or process is
left after a run.
2026-10-07 03:00:47 +08:00
yetone 90b1ac7956 update, gui: Add to PATH on Windows writes a magpie.cmd beside an app not named magpie.exe, so the site's magpie-windows-amd64.exe runs as magpie in a new terminal, and says so (#942, mintonight)
Add to PATH put the portable download's folder first in the user's PATH, but a terminal looks for magpie by that name only, so the command was never found. cliPlace now writes magpie.cmd beside a program not named magpie.exe: it runs %~dp0<the program's name> %*, which an update keeps, since it replaces the program where it is under its name. ReadCLI reads that magpie.cmd as this app (shimRuns), and the GUI says, in Add's tooltip, the row and the status, that magpie.cmd runs magpie-windows-amd64.exe. Going through cmd also makes PowerShell wait for the GUI-linked program and gives it the console. TestCLIShim and cli-path.test.cjs's new case fail without the change.
2026-10-06 02:18:07 +08:00
yetone 9ca64d104f update, gui: a new version Windows won't start is never left in place — tried before it goes in, and a restart into one that doesn't say it is up puts the running one back; that version isn't downloaded again by the clock, and Settings › About › Version says why (#894, hisiling) — on Windows 11 with Smart App Control on, the update put the new unsigned exe in place of the running one and restarted into it; CodeIntegrity (3033/3077) refused it, magpie never started again and the working version sat in .old. Now, on Windows, the downloaded exe is first started suspended with no window and ended at once (Windows checks a program when its process is created), and one refused stays out: the running exe isn't moved. At the restart the new process is given MAGPIE_STARTED, a file it writes first thing (AwaitPredecessor); the old one waits up to 20s for it and, if the start fails (ERROR_SYSTEM_INTEGRITY_POLICY_VIOLATION 4551, 1260 or any other), the new process quits before saying so, or it says nothing in time (then it is ended), puts the running exe back over the new one (the new one renamed .blocked if it can't go) and keeps running instead of quitting; nothing notes it as updated in the app. The version is noted in the config folder (update-blocked.json, this machine's only, never synced; gone once a version at least as new runs); the clock's checks leave it alone and show why, a Check clicked downloads and tries it once more. Settings › About › Version: for an application control policy, "0.1.x didn't start on this computer: Windows' Smart App Control (or another app control policy) blocked the new version, which isn't signed. magpie stays on 0.1.y. Download it and run it yourself, or turn Smart App Control off and check again", else the reason, with Download and Check; the error in full on hover. en/zh/ja/de. A user who double-clicks the refused exe is refused by Windows before magpie runs; only signing helps there. TestRelaunchRefusedPutsBack (4551 at the start), TestRelaunchSilentPutsBack (no word in time, killed; quit at once), TestRelaunchReportedStays, TestReportStarted, TestBlockedNote and TestUpdateThatWontStart (the restart doesn't quit, the note, the clock not downloading it again, a Check that does) are new and fail without the change; on Windows TestInstallBinaryRefusedStaysOut, TestTrialStart and TestStartCheckedPutsBackForReal (real processes: not a program, quits at once, runs on silent) pass on the Windows 11 test box with the whole internal/update package (Smart App Control itself isn't on there, so the refusal is simulated). update-blocked.test.cjs (Chromium and WebKit, en and zh: the reason and both versions, full error on hover, Download opens the release, Check downloads, the other reason, no select, no scroll, no left border) fails without the change; update-check, update-mirror, update-auto, update-wait and update-download-percent pass in WebKit; click-scroll's request-list case fails now and then the same on main. go vet, go build (darwin, GOOS=linux nogui, GOOS=windows) and go test -tags nogui ./... under a temp HOME pass. 2026-10-05 19:43:31 +08:00
yetone dab887db57 update, gui: Settings › About › Download source sets the update mirror, and a download that failed through it offers GitHub (#893, M3chD09) — the mirror updates could come through was only magpie update mirror in a terminal, and the GUI never said where updates came from or that a failed download was the mirror's. About now has a Download source row: GitHub, or the mirror set (the same UpdateMirror setting the CLI writes); Use a mirror… takes a full https:// address (http, a bare host or a malformed one refused, with the reason in the row and the draft kept), Change edits it, Use GitHub takes it away in one click; Enter saves, Esc cancels, no click scrolls. POST /api/settings/update-mirror sets it; the Settings page's own save keeps it. A download through the mirror that doesn't answer, answers other than 200, or sends a file whose SHA-256 isn't usemagpie.ai's feed's is an update.MirrorError (never installed, the file removed, as before); /api/update's error carries the mirror, and the Version row says the download failed through that mirror and offers Download from GitHub, which takes the mirror away and downloads again. magpie names no mirror or CDN of its own. en/zh/ja/de. TestMirrorFailuresAreTheMirrors (tampered, 404 and closed mirrors each the mirror's, no file kept; a direct failure no mirror's; CheckMirrorURL) and TestUpdateMirrorSetting (set trimmed, http/bare/ftp/empty-host refused, Settings save keeps it, off, an updater failing through a 404 mirror reports it with retry, a new check clears it) are new; update-mirror.test.cjs (WebKit, en and zh: GitHub shown, http refused with the reason, https saved with Enter, Use GitHub posts "", a failed download through the mirror offers GitHub, which posts "" then update/install; no select, no left border, no scroll) fails without the change; update-auto, cli-path, cli-behind, settings-sections and click-scroll pass in WebKit. go vet, go build (darwin, GOOS=linux nogui, GOOS=windows) and go test -tags nogui ./... under a temp HOME pass. 2026-10-05 18:49:04 +08:00
yetone d6daa40ce3 update, gui: Settings › About › Command line says what magpie runs in a new terminal and adds it (PAMI on Discord) — the app downloaded from the site, and every Windows one, left terminals without the magpie command, and nothing in the GUI said whether it was there. A Command line row now asks each shell installed (zsh, bash, fish and the login shell; PowerShell and cmd on Windows) for its PATH and says, with a dot each, whether its magpie runs this app, another copy (with that copy's version, read from its .app's Info.plist or Homebrew Cellar folder, never by running it), or none. Add to PATH links this app's program (Homebrew's opt link, the AppImage) into the folder on the default shell's PATH whose magpie runs first, else ~/.local/bin or the like when on PATH, replacing another copy there as install.sh's ln -sf does; on Windows it puts the app's folder first in HKCU\Environment Path and broadcasts WM_SETTINGCHANGE. A shell whose PATH lacks that folder gets its own button naming its profile (~/.zshrc, ~/.bash_profile on the Mac or ~/.bashrc, fish's config.fish), which links into ~/.local/bin and adds that folder with one marked line, once; no profile is written otherwise. A translocated or disk-image app is told to move first and gets no button. It says new terminals take the change (on Windows: new PowerShell/cmd windows, restart Windows Terminal). GET/POST /api/cli; en/zh/ja/de. TestCLIOnPath (temp HOME, stubbed shells: link, fish profile once, a shadowing copy replaced, no folder → zsh's profile kept and appended, an unknown shell refused, plist version, translocated refused) and TestPathFirst are new; cli-path.test.cjs (WebKit, en and zh: per-shell dots, Add posts {} and turns green, fish's button posts fish alone, Windows lists PowerShell and cmd, translocated gets no button, no scroll, no select, no left border, translations) fails without the change; cli-behind and update-auto pass. Not tried on a real Windows machine. go vet, go build (darwin, GOOS=linux nogui, GOOS=windows) and go test -tags nogui ./... under a temp HOME pass (TestOTelWholeWaterfallFallback and TestDevinSignedInOnlyInMagpie failed once each under load and pass alone). 2026-10-05 17:49:20 +08:00
tobitege 21702d01ff Add German translation; harden paths against unset env vars (#770)
* Add German translation and harden paths against unset env vars

Add a German locale to the GUI, tray menu, usage alerts and website home page, and refuse to start when the home folder is unset or relative so nothing is written under the working folder; the pi plugin no longer adopts the user's PI_CODING_AGENT_DIR, and an inherited APPIMAGE no longer selects portable mode. Scripts refuse to run from the wrong folder or empty a shared out folder, and a new internal/testenv sandboxes every test package from the user's real files, which also fixes the Claude picker and Termux installer tests on Windows.

* Makefile: know magpie's folder by its go.mod, so paths with spaces work

The check compared $(CURDIR) with $(dir $(abspath …)), which make splits on spaces, so a checkout under 'My Projects' or 'John Doe' refused every target. It now reads go.mod relative to the working folder and wants magpie's module there: make -C and a symlinked Makefile work, make -f from another folder still stops before any recipe runs.

* i18n: German for the strings main added since, with a parity test

75 strings main added (group order, patterns, slow-start wait, usage caps, RTK savings …) get their German, and two that main dropped go. gui-de.test.cjs checks, as gui-ja does, that de has every zh string with its placeholders and tags, and that the window reads in German when picked or on a German system.

* appdir: ignore relative folder variables when reading, keep them for children

CheckEnv no longer unsets anything. magpie reads the XDG folders, APPDATA/LOCALAPPDATA and every agent's folder variable through appdir.Getenv/LookupEnv, which pass over a relative value; the environment stays as it is, so the agents magpie starts get the variable as the user set it. That covers what proc.UserPath lends from the login shell too, which is set after main's check and reached the desktop app unchecked. On Windows a path rooted on the current drive (\Users\x, Git Bash's /c/x) counts as usable, and magpie version and help answer without a home, before run makes any folder.

* Sandbox the tests main added since

internal/wslrun gets testenv's TestMain, and four tests main added that set HOME alone set their home with testenv.SetHome, so on Windows they don't read the runner's profile through USERPROFILE.

* agentenv: PI_CONFIG_DIR and OPENCODE_DB take relative names on purpose

omp puts $PI_CONFIG_DIR under the home and OpenCode a relative $OPENCODE_DB in its data folder, so neither depends on the working folder: appdir no longer passes them over.

* i18n: German for the Library's multi-select and System One's decision API

The 19 strings main added since (#791's skill multi-select, the decision API snippets) get their German; the one main replaced (four APIs → five APIs) goes.

* appdir: tidy the import into magpie's group; say what Go makes of /c/x

The appdir import joins the group of magpie's own imports where a file has one. rooted's comment now says that Go takes a Git Bash path like /c/x as \c\x on the current drive, not C:\x.
2026-10-04 23:30:56 +08:00
yetone bc141ad834 update: install.sh and magpie update take --proxy and --mirror, and magpie update mirror keeps one for the app's updates too (akic404 on Discord: 安装和update如果没有梯子也是麻烦事,能否在install.sh和magpie update后加子选项?--proxy等可自定义或默认ghproxy) — install.sh had no options and fetched with curl alone, and magpie update took none; without a way out to GitHub both failed. Now both take --proxy <url> (http, https, socks5, socks5h; install.sh also MAGPIE_PROXY=) for the feed and the download, and --mirror <prefix> (or MAGPIE_MIRROR=), a GitHub download mirror the release file is fetched from as <prefix>https://github.com/…; only github.com / githubusercontent.com URLs are put through it. No mirror is used unless one is given: magpie names none and has none by default. The feed with each file's SHA-256 is always fetched from usemagpie.ai, never through the mirror, so a file the mirror changed is refused and deleted ("… from the mirror X does not match its checksum from https://usemagpie.ai; not installed"); macOS still checks the app's signing team. magpie update mirror <prefix>|off saves Settings' updateMirror (http(s) only), which the app's own background update follows too; magpie update --mirror off skips it once; the Settings page's save keeps it. The app's update already followed Settings → Proxy (#294); magpie update --proxy overrides it for one run. The environment's ALL_PROXY / all_proxy is now honoured when HTTPS_PROXY / HTTP_PROXY are unset (Go's ProxyFromEnvironment ignores it), with NO_PROXY as curl reads it. magpie update takes --flag value or --flag=value, and an unknown word is an error instead of an update. The help, README and the docs' FAQ (en/zh/ja) say how. install.test.mjs's proxy, mirror and tampered-mirror tests, TestAllProxyFromTheEnvironment, TestUpdateThroughAMirror, TestUpdateThroughAProxyGiven and TestUpdateFlags fail on the old code and pass; TestSettingsSaveKeepsWhatItDoesNotSend covers updateMirror. A dry run of install.sh as Linux amd64 into a temp HOME installed the real 0.1.773 with its SHA-256 checked, refused a local mirror serving a wrong file, and with --proxy to a closed port failed reaching the site through it. go vet, builds (darwin, GOOS=linux, GOOS=windows), sh -n, node --test site/install.test.mjs and go test -tags nogui -count=1 ./... under a temp HOME pass but TestClaudeIdentityServedWhileAsked, a timing test that passes alone. Not tried through a real proxy server or a real public mirror; no install.ps1 exists for Windows, and the app has no field for the mirror. 2026-10-04 00:19:47 +08:00