Commit Graph
10 Commits
Author SHA1 Message Date
yetone f4a575954b plugin: the update check asks npm now, not what it said within the hour
ysm119 on Discord tested Cursor's claude-haiku-5-5-thinking a quarter of
an hour after plugin 0.2.25 was published and magpie updated. CheckUpdates
(30s after start, then hourly) read npm's versions through Info, which
asks npm at most hourly and otherwise answers from its disk cache, so a
magpie started after a community fix was published could find the
version before it and update nothing for up to another hour (two in all
for the hourly look). latestOf now asks npm of every installed package
(infoWithin, age 0); the plugins page keeps Info's hourly cache, and a
package npm doesn't answer for is still what it said last.

Run: go test ./internal/plugin -count=1 -timeout 45m (ok, 305s).
Broken by hand: latestOf back on Info, TestUpdateCheckAsksNPMNow is red
(the check saw 1.2.3 while npm had 1.2.4).
Not tried: a real magpie restart against npm's registry.
2026-10-27 18:43:32 +08:00
yetoneandggbdpq 58651568b3 agent, sessions, provider: a state file that doesn't parse is kept aside, not written over as empty (#2263, ggbdpq)
applied.json, wsl.json and sessions-wsl.json were read as empty when they
didn't parse, and the next save wrote that emptiness over them. What
magpie had applied to each agent, the WSL distros and the WSL session
listing were lost with no copy. stash.json already kept a bad file aside
as .bad-<time>. Each of these now does the same through one helper,
lastgood.KeepUnparsed, instead of a copy per file:
- It does nothing when the file is missing or empty.
- When the file doesn't unmarshal into the reader's own type
  (lastgood.Into[T]), it copies the file aside (KeepBad).
- It stops the write when the copy can't be kept.

This also fixes the issue's claim about stash.json. Stash judged a file
with json.Valid, so `[]`, which a map reader takes as empty, was written
over unkept. Its failed copy was only logged, and the write went ahead
anyway. Both are fixed (TestUnreadStashArrayKeptAside), and
gateway-hidden.json uses the same helper.

Siblings found by going through every single-file JSON reader that takes
a bad file as empty and then writes it whole:
- stepfun-auth
- login-returns
- quota-history
- balance-history
- credits-daily
- Claude Desktop tiers
- plugin updates
- usage's computer id
- davsync's sync state

Each now keeps a bad copy. Caches that are rebuilt from the vendor are
left alone; docs/subsystems/providers-accounts.md lists them.

Run:
- gofmt -l, go vet (darwin -tags nogui, GOOS=linux -tags nogui,
  GOOS=windows): clean.
- go test -tags nogui -p 4 -timeout 40m ./... with the other three
  commits of this push: see the last one's body.

Broken by hand: on the code before this, these fail:
- the issue's applied_keep_test.go and wsl_keep_test.go
- TestUnreadStashArrayKeptAside
- TestUnreadStateKeptAside (10 subtests)
- the gateway, usage, davsync and plugin _keep tests
TestKeepUnparsed and TestKeepUnparsedFailsWhenItCantBeKept cover the
helper.

I dropped a test, "not written when it can't be kept", for stash. It passed
on the old code too, because a read-only folder also stops the atomic
write.

Not tried: a real WSL distro.

Co-authored-by: ggbdpq <ggbdpq@gmail.com>
2026-10-15 09:36:26 +08:00
yetone a0ebe0032d plugin: a listed plugin whose package is gone is installed again, and bun's installs run one at a time (#2002)
anganing (Windows 11, v0.1.1229): after an auto-update, every switched-on
plugin said "no such plugin: …\node_modules\@magpie-community\opencode-grok-auth"
at each start. For the github: plugins the path was the spec itself
(node_modules\github:owner\repo), so package.json no longer listed them.
Removing a plugin and adding it again was the only way out.

- InstallMissing installs again each listed plugin (switched off or not)
  whose package isn't in plugins/, from its own spec. KeepUpdated runs
  it 30s after start and then hourly, before CheckUpdates. Nothing did
  this before: CheckUpdates skips a plugin with no installed version.
- installMu serialises every bun command that changes plugins/: install
  (including the first package.json it writes), reinstall's bun update,
  and Remove's and add's bun remove. At start KeepUpdated (30s) and
  keepMovedCurrent (20s) each run bun add with no lock. On the Windows
  box, three concurrent bun add runs (Bun 1.4.3) in one folder kept only
  one writer's package.json change. A git plugin's dependency dropped
  that way leaves Name() unresolved, which is the reporter's github rows.

The exact sequence that emptied the reporter's node_modules wasn't
reproduced. Bun 1.4.2 -> 1.4.3, magpie v0.1.1205 -> v0.1.1227 with the
same plugins, and a package.json reset all left the folders in place.
So this repairs the state and closes the one race found. It isn't
proven to be the trigger.

Run:
- go test ./internal/plugin ./internal/provider -count=1: ok.
- The new tests -count=3 on macOS, and on the Windows box as a
  cross-built test binary: ok.
- Broke each fix by hand (lock a no-op; InstallMissing returns early):
  TestBunCommandsOneAtATime fails with "another bun is running here",
  and TestMissingPluginsInstalledAgain gets 0, want 2.
- Real use on the Windows box, sandbox HOME, port 3561, real Bun 1.4.3:
  deleted opencode-grok-auth and opencode-qoder-auth from node_modules
  and started serve built from this commit. The host logged the
  reporter's exact "no such plugin" for both. At +30s it logged
  "installed 1 missing plugins again" and both folders were back.
  After the restart, no plugin failed to load.
- gofmt -l internal/: clean. go vet for darwin, linux -tags nogui and
  windows (plugin, provider, gateway), and GOOS=windows go build ./...:
  ok.
2026-10-14 09:17:47 +08:00
yetone 431707944e plugin, library: Check for updates asks GitHub with the GitHub token from Settings, and says when GitHub's rate limit is used up (#1942, bingqilinweimaotai)
What changed: a plugin installed from GitHub (github:owner/repo) is
checked by asking GitHub's API for its branch's commit (githubHead,
through fetchJSON). That request went without a token, so a token saved
in Settings → Network and sharing did nothing for it: the check stayed
at GitHub's 60 requests an hour for the whole address, which a shared
proxy exit uses up, and the row said only "<url>: 403 Forbidden".

- The token lookup, where a token may go and how a rate limit is told
  move from internal/library into a new internal/ghtoken, shared by the
  library and the plugin package (plugin can't import library).
  The order is unchanged: Settings, then GITHUB_TOKEN, then GH_TOKEN.
- plugin's fetchJSON has a request to GitHub's API's host (githubAPI)
  carry it, which covers the git plugins' check and the Plugins page's
  topic search. Raw files, npm and every other host never get it, and
  source.Do already sends nothing with Authorization to a mirror.
- An answer from GitHub's API that is a rate limit (429, or 403 with
  X-RateLimit-Remaining 0, Retry-After or a rate-limit message) is a
  ghtoken.Limited: the check's row has Why "limited" and Limited {until,
  token} for the page, as the library's skill check already had. A 401
  to a request with a token names which token was refused, never the
  token.

What was run:
- TestGitPluginCheckCarriesGitHubToken (new, internal/plugin): asks with
  no token / GH_TOKEN / GITHUB_TOKEN / Settings in that order of
  precedence, a 403 rate limit with and without a token, a 429 with
  Retry-After, a refused GH_TOKEN, and a raw-file host that must get no
  Authorization. Broken by hand twice: with fetchJSON's Authorize removed
  it fails "GH_TOKEN: GitHub's API was asked with Authorization "", want
  "Bearer gh-env"" (and the other two sources); with the limit check
  removed it fails with Why "registry", Limited nil, "403 Forbidden".
- go test -tags nogui -count=1 ./internal/library ./internal/plugin
  (temp HOME, pinned caches): ok, the library's TestGitHubToken*,
  TestGitHubRateLimitSaid among them.
- gofmt -l clean; go vet -tags nogui on darwin, GOOS=linux and
  GOOS=windows for internal/plugin, library, ghtoken, gui: clean.
- Not tried against the real api.github.com (tests stay off the network).
2026-10-13 15:19:53 +08:00
yetone 7af45761f7 plugin, gui: a plugin from a git repository shows Update only when its repository has new commits (ARNO on Discord)
ARNO installed opencode-codearts-auth as github:yuweihao17/codearts. Its row
on Plugins always had an Update button, and still did right after updating
it to the newest commit. The page drew Update for every git plugin whatever
its commit, since npm has no version to compare for one, and nothing asked
the repository. ba0e2a8a fixed the same complaint for pinned npm plugins
only.

A git plugin is now compared by commit:
- internal/plugin/gitrev.go reads the commit Bun installed: the package's
  .bun-tag (owner-repo-<sha7> for GitHub's, the full sha for a clone),
  else bun.lock's "#<sha>". It asks where the spec's branch or tag (the
  default branch without #ref) is now: GitHub's API (commits?per_page=1
  [&sha=ref]) for github:o/r, o/r, https://github.com/o/r and
  git+https/git+ssh/git:// URLs on github.com; git ls-remote for gitlab:,
  bitbucket: and any other git URL (an annotated tag's commit, not the
  tag's). A spec pinned to a commit is that commit, asked of nobody.
  Answers are kept 10 minutes (GitHub allows 60 unauthenticated requests
  an hour).
- updates.go: the hourly CheckUpdates and the Check for updates button
  (CheckNow) report a git plugin as current or update, with its commit
  and the repository's head, in place of the old "git" status. A waiting
  git update is dropped once the installed commit is the head.
- GUI: /api/plugins/git gives the heads, asked after load and after an
  install or update. The row shows the commit installed. Update, the
  "New commits" chip, the Discover card's Update and Update all show only
  when the repository is at another commit. Five new strings are in zh,
  zh-TW, ja and de.
- Docs: the Updates list in site/public/docs (en, zh, ja) says how a git
  plugin's update is told.

Tarball specs are unaffected, since magpie plugin add refuses them as not
a package name.

Run:
- go test -tags nogui ./internal/plugin ./internal/gui (temp HOME): ok.
- New TestGitPluginUpdateOnlyWhenItsRepositoryMoved, for
  github:yuweihao17/codearts, its #main form, owner/repo, the
  https://github.com URL, git+file and git+file#main, against a fake
  GitHub API and bare repositories. After add, nothing waits. A new
  commit at the same version is an update. After Upgrade, nothing waits
  again.
- TestGitCommitAsBunWritesIt uses ARNO's literal bun.lock line and
  .bun-tag. TestGitSource covers spec parsing and the pinned-sha form.
- Broke GitBehind by hand (any installed commit is behind): the new test
  goes red in every form. Restored.
- GUI: plugin-git.test.cjs now checks no Update at the head, then New
  commits with Update and Update all once the head moves, then none after
  Update. It went red with the old condition put back. All 28 plugin-*
  files plus click-scroll, i18n-keys, gui-ja and gui-de pass in Chromium
  and WebKit.
- Real case, sandbox HOME, magpie web on a spare port: magpie plugin add
  github:yuweihao17/codearts installed c594984. /api/plugins/git and
  /api/plugins/check say current at c594984 against the real GitHub, and
  nothing is waiting. In both engines the row shows "v0.1.0 c594984" with
  no Update and no Update all.
- gofmt -l clean; go vet -tags nogui darwin, GOOS=linux and GOOS=windows
  on internal/plugin and internal/gui.
2026-10-11 01:14:19 +08:00
yetone 4b56c8672d plugin: an update Bun holds back says why, instead of saying it was made (sweanng424 on Discord)
What: Update, Update all, the hourly auto-update and the move's install
ask npm for the plugin's newest version and have bun install that exact
version (installAt), then check it is the one installed. When bun won't,
the error says why, reason first for the status pill: "<pkg> 0.1.21 isn't
installed yet: Bun's minimumReleaseAge (in a .bunfig.toml) holds back
versions published less than 2 days ago, and magpie installs it once it
is older (bun's own words)". Another bun error (a registry of the user's
own without the version) is "<pkg> <v> isn't installed: <bun's error:
lines>". Specs stay as they were (name@latest); pinned and git plugins,
and npm not answering, install as their spec says, as before.

Why: the Factory card stayed at 0.1.18 with 0.1.21 out, through clicking
update and restarts. bun add pkg@latest resolves "latest" by bun's own
config: a minimumReleaseAge in the user's ~/.bunfig.toml or
$XDG_CONFIG_HOME/.bunfig.toml makes it install the newest version older
than that and exit 0. 172800s (2 days) gives exactly 0.1.18 (0.1.19-21
were published 10-08). So every update path succeeded with nothing
changed, and the page said "updated to v0.1.21". Asked for 0.1.21 itself,
bun fails with "blocked by minimum-release-age: 172800 seconds". The same
code serves every moved plugin (Cursor, Devin, Kiro, Qoder, ...), so all
of them had it. npm view: 0.1.21 is latest; npmmirror has it too.

Run:
- TestUpdateBunHoldsBackSaysWhy (new): real bun 1.4.2 against a fake
  registry with 0.1.18 (3 days old) and 0.1.21 (1 hour), a bunfig with
  minimumReleaseAge = 172800. On the old code it fails: "Update with
  0.1.21 held back by Bun: <nil>, want bun's reason (installed 0.1.18)".
  Breaking Update alone fails at "Update all: <nil>", breaking the hourly
  update alone at "the hourly update: <nil>". Without the bunfig it
  installs 0.1.21 and keeps the spec @latest.
- Real use: magpie web (nogui build) under a sandbox HOME, real npm, with
  the bunfig: add factory-auth@0.1.18, spec @latest, POST
  /api/plugins/upgrade and /update return the reason above, the card
  stays 0.1.18; bunfig removed, upgrade installs 0.1.21.
- Ruled out on macOS and the Windows box: plain upgrade 0.1.18 -> 0.1.21
  works there without a bunfig, host running or not.
- gofmt -l; go vet (darwin, GOOS=linux, GOOS=windows, -tags nogui) on
  internal/plugin, internal/provider, internal/gui; go build (darwin),
  GOOS=linux and GOOS=windows -tags nogui builds; go test -tags nogui ./...
  under a temp HOME, all ok.
2026-10-09 12:57:56 +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 94bb3e2ca6 plugins: Check for updates asks npm now for each installed plugin's newest version, and each row says what it found (the owner: 插件的检查更新按钮还是得做) — the community's plugins update by themselves a little after magpie starts and every 6 hours, and the page knew of anyone else's new version only from what npm said within the hour (Info's cache), so a reader who heard a plugin had a new version had no way to have magpie look. The foot of Installed (beside Update all) now has Check for updates, shown when a plugin is npm's (a folder's or a git one's has no versions there; a git one keeps its own Update, which fetches it again): it says Checking… with a spinner while POST /api/plugins/check asks npm, a few at a time, past the hour's cache (plugin.CheckNow, through npmAsk, which is npmInfo telling why npm said nothing), and nothing is installed. Each row then says it: "v0.0.9 out" titled "v0.0.7 installed, v0.0.9 on npm" with its Update (the existing upgrade path, Upgrade → Add), "Up to date", or an amber "Couldn't check" chip with a dot, titled why — npm not reached (check your connection or proxy), npm turning requests away (429, try again in a few minutes), npm answering with an error, or npm not having the package (fetchJSON's answers other than 200/404 are now a statusError, so a 429 is told apart). The status line says how many have updates, or that every plugin is up to date, and how many couldn't be checked and why; npm not reached at all is "Couldn't check for updates: npm couldn't be reached — check your connection or proxy". A community plugin's Update is titled that magpie would update it by itself within a few hours and Update does it now. What npm said is kept as Info keeps it, so the rows and the market read it, and an update found for the reader (someone else's, or pinned) waits as the background look's do, putting the dot on Plugins; one npm didn't answer for keeps what waited before. Every new string has its Chinese; the click never scrolls the page. TestCheckNow (an httptest npm registry: the community's and someone else's updates found past an hour-old cache saying otherwise, up to date, 404 missing, 429 limited, 500 registry, git and folder not asked, nothing installed, the cache and the waiting list updated) and TestCheckNowOffline (npm not reached: offline, what waited still waits) are new, as is TestPluginsCheckRoute; plugin-check-updates.test.cjs (WebKit and Chromium, en and zh: Checking… while npm is asked, the rows' out / up to date / couldn't check chips and titles, the status line, Update after the check, offline said plainly, the view's scroll unmoved) fails without the change and passes with it. plugin-updates, plugin-market, plugin-progressive, plugin-git, plugin-local and click-scroll pass in WebKit and Chromium. go vet ./internal/..., go build -tags nogui (darwin, GOOS=linux), GOOS=windows go build, go test -tags nogui -count=1 ./... under a temp HOME pass. 2026-10-02 21:58:22 +08:00
yetone 456208945b plugins: a plugin can be installed from a git repository — github:owner/repo, owner/repo, a GitHub URL or a git+https:// one (Lemon on Discord: can plugins be installed directly from git?) — magpie plugin add and the Plugins field took only an npm name or a path, and turned a git spec away as "isn't an npm package name". A git spec now goes to bun add as given and is kept as given in plugins.json; the package it installs is named by its repository's package.json, which bun records as the dependency whose spec it is, so the plugin is known (list, on/off, rm, its version, its README) by that name or by the spec. update and the row's Update run bun update on it, which fetches the repository's commit now where bun add keeps the one bun.lock has, the spec unchanged; npm is never asked for a newer version of it, nor auto-updates it. Adding the same package from another URL, or from npm, takes its entry's place. The Plugins field says it takes a GitHub repo (en+zh); an installed git plugin shows its package's name, an Update button, and a page with its README, no npm link and a Source link to the repository. Nothing that installed before is turned away. TestGitPlugin (a fake bun fetching from local bare repositories, the real one loading the plugin when on PATH) and plugin-git.test.cjs fail without the change; TestIsGit checks what counts as a git spec. go vet, go build -tags nogui (darwin, GOOS=linux), GOOS=windows go build, go test -tags nogui ./... pass; plugin-git, plugin-local, plugin-market, plugin-updates, click-scroll, old-webkit pass. 2026-10-02 02:24:49 +08:00
yetone b7037c101e plugin: plugins keep up to date as magpie does (the user: 插件的升级是怎么做的?我们有插件的升级提醒吗?) — a plugin updated only when the reader opened Plugins and clicked Update, save the built-ins' moved plugins held at their least version, so most users stayed on the version they first installed, and updating cut any reply streaming through a plugin. Now the magpie serving the gateway asks npm 30s after it starts and every 6 hours: the community's plugins (@magpie-community/*) update by themselves, and their row says Auto-updated (from which version, when) for three days; someone else's, or one pinned to a version, waits for the reader with a dot on Plugins naming it, gone once it's updated. A host being replaced finishes the calls it is serving (up to 10 minutes) while new ones go to the new host. TestCheckUpdates, TestPinned, TestRestartFinishesTheReply (fails without the change: the plugin host quit: signal: killed) and plugin-updates.test.cjs (Chromium, WebKit, en/zh). go vet, go build -tags nogui (darwin, GOOS=linux), GOOS=windows go build, go test -tags nogui ./... pass; internal/plugin passes on Windows, internal/plugin and internal/provider on Linux; plugin-market, plugin-signin, plugin-move, plugin-release, click-scroll, old-webkit pass. 2026-10-01 16:27:43 +08:00