Commit Graph
7 Commits
Author SHA1 Message Date
yetone e4197144a8 perf: every package's package-level regexps compile on first use
v0.1.3516 made gateway's and redact's patterns lazy. The other 299
package-level regexp.MustCompile calls, in 148 files across agent,
provider, gui, library, codexcat, sessions, usage, plugin and the rest,
now go through lazyre.New too, so a launch that never reaches them
(`magpie statusline`, run by Claude Code on every message) doesn't
compile them. Fields, maps and params that held them are *lazyre.RE.

Measured on mote (M5 Pro), sandbox HOME, v0.1.3516-equivalent build
(t42) against this one (t43):
- GODEBUG=inittrace=1 sum: 7.39 MB / 69,837 allocs -> 4.62 MB / 46,765
- `magpie statusline`, 3 runs each: instructions retired ~212M -> ~176M,
  peak memory footprint 19.2-19.4 MB -> 16.8-17.0 MB

Run: go vet ./... (darwin) ok; GOOS=windows go vet on each of the 30
changed packages ok; GOOS=linux go vet ok except ., internal/cli and
internal/gui, which stop in wails v3's cgo files when cross-compiled
(the same at main). New TestAllLazyPatternsCompile at the root compiles
all 574 registered patterns (ok), so a bad pattern fails a test rather
than a first use.
Not run before push: the changed packages' own test suites; they run
on mote after it.
2026-11-10 12:54:39 +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 334bb182e9 plugin: Bun's release check asks GitHub's API with the GitHub token from Settings too (#1942, bingqilinweimaotai)
What changed: an audit of every request magpie makes to GitHub's API
after the git-plugin fix. The library's skill checks, private-repo probes
and RTK's release check already carried the token; the Plugins page's
git-plugin check and topic search got it in the previous commit. The one
left was Bun's newest-release check (bunLatest), asked of
api.github.com/repos/oven-sh/bun/releases/latest anonymously through
getURL. getURLFrom now has a request to GitHub's API's host carry the
token (ghtoken.Authorize), and bunLatest asks githubAPI so tests can
move it. Bun's zips (github.com, npmmirror) are other hosts and never
get it. With a token set, that one request isn't sent to the
MAGPIE_MIRRORS fallback (source.Do sends nothing with Authorization to a
mirror), the same as the library's API requests.

Left as they are: Copilot's api.github.com requests carry the user's
Copilot sign-in, not this token; raw.githubusercontent.com and codeload
aren't the rate-limited REST API; site/worker.js is the website's.

What was run:
- TestBunReleaseCheckCarriesGitHubToken (new): bunLatest is asked with
  "Bearer github-env", a download from another host with none. With the
  Authorize call removed it fails: "Bun's release was asked of GitHub's
  API with Authorization """.
- go test -tags nogui -run 'Bun' ./internal/plugin: ok.
- gofmt -l clean; go vet -tags nogui darwin, GOOS=linux, GOOS=windows on
  internal/plugin: clean.
2026-10-13 15:19:54 +08:00
yetone 23c6e865a7 plugin: a musl Linux (Alpine) runs plugins on Bun's musl build, kept apart from the glibc one (#1877)
emptyteeth found it: bunTarget picked Bun's build from GOOS/GOARCH alone,
so Alpine got bun-linux-x64-baseline, a glibc build whose interpreter
(/lib64/ld-linux-x86-64.so.2) Alpine lacks. exec then said "fork/exec
…/bun/1.4.2/magpie-bun: no such file or directory", which reads as a
missing file, and no plugin could be added or run.

- bunTarget: a musl Linux gets bun-linux-x64-musl-baseline or
  bun-linux-aarch64-musl. The musl check moves out of internal/claudecode
  into internal/libc (libc.Musl, unchanged rule: Anthropic's installer's
  /lib/libc.musl-*.so.1), which claudecode, the plugin host and the CLI
  test that skipped on musl now share.
- bunSums: the two musl builds' checksums, checked against Bun v1.4.2's
  own SHASUMS256.txt (downloaded from the GitHub release; they match the
  issue's numbers).
- Cache: a musl Linux keeps its Buns and state.json under bun/musl, so a
  machine whose C library changed never runs the other build, nor takes
  its state, whose Bad may list versions only the glibc build failed
  (CheckBun on Alpine set aside every newer Bun). glibc, macOS and Windows
  stay in bun/<v>, so a Bun downloaded before is used as it is, with no
  new download.
- A bun on disk that exec can't start with ENOENT says it is a build for
  another C library and names MAGPIE_BUN (cantStart), for the host's start
  and for bun add/bun update. The same for a $MAGPIE_BUN.
- Bun's musl build needs libstdc++ and libgcc, which a bare Alpine lacks:
  the loader then prints "Error loading shared library libstdc++.so.6"
  above ~40 "Error relocating" lines, and bun add cut it off. bun add,
  bun update and a host that died starting now say which library is
  missing and `apk add libstdc++ libgcc` (missingLibs, whyDied).

Decided: a Bun that can't be started at all is not counted as crashed.
The fallback goes to the version before, which is the same build for
this system and fails the same way, and setting the current one aside
would mark a good version bad for good. The libc check happens before the
download instead (the target), so Alpine never fetches the glibc build.

Run:
- docker alpine:3.20 (arm64, and amd64 under emulation), sandbox HOME in
  the container, linux nogui builds. origin/main's binary reproduces the
  report: "bun add …: fork/exec /sbx/.cache/magpie/bun/1.4.2/magpie-bun:
  no such file or directory". This one on bare Alpine downloads
  bun/musl/1.4.2 and says "this system lacks libstdc++.so.6 … apk add
  libstdc++ libgcc"; after apk add, `magpie plugin add
  @magpie-community/opencode-cursor-auth` adds it and `plugin list` starts
  the host and lists cursor (arm64 and amd64), with the old glibc
  bun/1.4.2 left beside it unused. With libstdc++ removed again, plugin
  list says the library; MAGPIE_BUN pointed at the glibc build gives the
  C library message.
- New tests (bunmusl_test.go, libc_test.go), each broken by hand and seen
  red: no musl branch (TestBunTargetForMusl, TestMuslBunKeptApartFromGlibc),
  no bun/musl root (TestMuslBunKeptApartFromGlibc), cantStart returning
  the error as is (TestCantStartSaysCLibrary,
  TestHostOnUnstartableBunSaysCLibrary, which fails with the reporter's
  exact message), host.go without it, no musl sum (TestBunDefaultSums),
  no hint in bun add (TestMissingLibsNamesThem) or in the host's start
  (TestHostOnBunLackingLibsSaysWhich), muslAt always false (TestMuslAt).
  -race -count=20 on them: green.
- gofmt -l; go vet ./... on darwin, GOOS=linux -tags nogui, GOOS=windows;
  go build for darwin, linux nogui, windows; go test -tags nogui for
  internal/plugin, libc, claudecode, cli in a sandbox HOME, and
  go test -tags nogui ./... (all green). One earlier run of
  internal/plugin with the other three packages went red, and its output
  was lost to a tail; four reruns of it, alone and together, were green,
  and the new tests were green under -race -count=20, so which test it
  was isn't known.

Not tried: a glibc Linux end to end after the change (the unit test
covers that its Bun stays at bun/<v>); a musl Linux other than Alpine
(the detection is unchanged and looks for Alpine's libc.musl-*.so.1).
The old glibc bun/<v> on an Alpine machine stays on disk (~90 MB); it
isn't removed, as a volume shared with a glibc container could be using
it.
2026-10-13 07:25:22 +08:00
yetone 05683637d5 plugins: the Bun the plugin host runs on is kept as magpie-bun, so a proxy app's PROCESS-NAME rule can route the requests plugins (Cursor and the other moved subscriptions) make (#1048)
magpie downloads its own Bun into ~/.cache/magpie/bun/<version>/. It is now
written there as magpie-bun (magpie-bun.exe on Windows), and a Bun downloaded
before is renamed in place the first time it is looked for, so nothing is
downloaded again and no second copy takes disk. The host, bun add and bun
update all run it, so all of their traffic carries the one name. A
$MAGPIE_BUN the user set is run as it is.

Verified: TestBunDownloadedAsMagpieBun, TestBunDownloadedBeforeTakesTheName
and TestHostRunsAsMagpieBun fail without the change (the Bun is .../bun, the
host runs .../bun). TestHostRunsAsMagpieBun starts the real host on a copy of
Bun 1.4.2 and `ps -o comm=` names it magpie-bun on macOS. On the Windows box
the three tests pass with the Windows build of Bun 1.4.2, a running bun.exe
renames to magpie-bun.exe, and Get-Process/Win32_Process name it magpie-bun.
Linux not run here (CI's ubuntu job runs the test with Bun on PATH).
go test -tags nogui ./... green; -race -count=10 on the new tests green.
2026-10-07 01:37:31 +08:00
yetone f8a3f16dc6 plugin: the community's plugins are looked for updates every hour, not every six (#681, ChenstarMr on v0.1.808: told TraeCN 0.1.5 would come by itself, installed it by hand eleven minutes after it was out) — KeepUpdated ran CheckUpdates 30 s after the gateway's magpie started and then every updateEvery, six hours, so a fix published to a @magpie-community plugin and announced on its issue could take most of a working day to reach the reporter. updateEvery is now an hour: one look at npm's metadata for the plugins installed (no download unless a community plugin, unpinned and switched on, has a newer version; someone else's still waits for a click), cheap at that pace. Bun's own check (KeepBunUpdated, a GitHub release lookup with a two-day hold) keeps six hours under its own bunEvery. The Update button's tooltip on a community plugin says "within the hour" / 一小时内 where it said within a few hours. go vet, builds (darwin, GOOS=linux, GOOS=windows) and go test -tags nogui -count=1 ./... under a temp HOME pass (TestProvidersAnswerWhileListsComeIn, TestUserPath and TestClaudeSignedOut failed once under load with four other test runs going and pass on their own); the plugin-*.test.cjs GUI tests pass in webkit. 2026-10-04 11:12:15 +08:00
yetone c3197ac217 plugins: magpie keeps the Bun plugins run on up to date by itself (the user: 我们能否自动去管理一个bun的版本?去自动的下载并维护这个bun的版本到最新版) — plugins ran on the one Bun magpie pinned, or on whatever $MAGPIE_BUN pointed at. Every six hours (first two minutes after start), while there are plugins, magpie now asks GitHub for Bun's newest release and takes it once it has been out two days: downloaded, its SHA-256 checked against Bun's SHASUMS, tried (it says its version, and runs a script with AsyncLocalStorage, fetch and fs), then switched to, the host restarted gracefully so a streaming reply finishes on the old one. BunVersion is the floor; the Bun before stays on disk, and a new one whose try fails, or that the host won't start on, is set aside for the one before and never taken again (bun/state.json). $MAGPIE_BUN is left alone. Plugins' page and magpie plugins show the version in use. TestCheckBunTakesASettledRelease, TestCheckBunWaitsAndKeepsTheFloor, TestCheckBunSetsAsideOneThatFailsItsTry, TestTryBunOnRealBun and TestHostFallsBackWhenTheNewBunDies pass on macOS, Linux and Windows; a real run from 1.3.14 to GitHub's 1.4.2 started the host on all three. go vet, go build -tags nogui (darwin, GOOS=linux), GOOS=windows go build, go test -tags nogui ./... pass (TestFetchNewLeavesListedPlugins failed once under load, passes alone). 2026-10-01 19:33:04 +08:00