ccb75030aaba3cf7359ea2dd784c00ecc7e80c19
14
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
75d63a1545 |
plugin: Discover no longer keeps a stale read from just after a push (#4067)
The Plugins page's Discover lists the repositories tagged magpie-plugin, and keeps what each one's package.json, npm and the file it names made of it by `owner/repo@pushed_at`, so a repository is read once a push. raw.githubusercontent.com can answer from before a push for a while after it (its answers, a 404 too, say they stand five minutes): the package.json or the file it names missing, or the package.json as it was. A read then was kept for the push, so a repository read as missing stayed out of the list until magpie started again or the repository was pushed to again (MengXiangxi on #3821, #4067). Now a read less than rawFresh, ten minutes, after the push is shown as any read is, and read again at the next ask; one rawFresh or more after the push is kept for the push, as before. When it was read is what counts: a whole list stands ten minutes, so the next ask is often past rawFresh, and judged then, a 404 read a minute after the push would be kept. A read again that comes in after the page stops waiting is shown at the ask after, as any late read is; one that gets no answer leaves the repository as it was read. A list is asked again when its time is up: ten minutes for a whole one, 20 seconds for one cut short, a minute after a failed search, and at once on Try again when it isn't whole. So such a repository is read about once more. raw's answers have no Age, and their Expires is each answer's own date plus five minutes, but they carry Source-Age, how long raw's cache has held them, a 404's too: 2s after a push, raw's 404 had Source-Age 20, cached before the push (below). This reads no headers (fetchJSON keeps none) and goes by the time since the push. What was run (tree 00637ea4, on origin/main |
||
|
|
5957d45ac1 |
plugin: a GitHub listing takes package.json's licence when GitHub names none (plugins#468)
GitHub's search gives NOASSERTION for a LICENSE file it can't match to a licence (MIT's text with a line of credit added) and nothing for none; magpie drops NOASSERTION, so such a card on Plugins > Discover had no licence, while the same package from npm shows package.json's. readTagged keeps package.json's license (a string) as PkgLicense, and License falls back to it, on a fresh read and across searches (fresh). Run (mote, at this tree): gofmt -l clean; vet on three OSes; go test -tags nogui -timeout 45m ./... (go test -tags nogui -timeout 45m ./... at base |
||
|
|
e4ccf67b11 |
plugin: GitHub's search gets 60s a page, and a mirror is asked without the token (#3923)
MYCF711 (#3923) measured a page of GitHub's search from mainland China: 29-36s straight to api.github.com, 3-7s through gh-proxy. The Plugins page's GitHub list was empty there, for two reasons: - askTagged's taggedWait (8s) bounded the search pages as well as the wait for the repositories' reads. The first page timed out, the ask failed whole, and nothing was cached. Each search page now has its own taggedSearch (60s). taggedWait starts after the search and bounds only the reads, as before. Through a mirror, candidateContext gives the official address half of the 60s and the mirror the rest. - source.Do never used a mirror for a request carrying Authorization, and ghtoken sets it on every api.github.com request when a GitHub token is set. With a token in Settings, MAGPIE_MIRRORS did nothing. A request to a GitHub host whose only credential is Authorization (bare) now goes to the official address with the token and to the mirror without it. A cookie, a key header, a token in the query, URL userinfo, or any other host still keeps the request official. The caller's request keeps its header. - ghtoken.Do now reads who answered from resp.Request: a mirror's answer to the bare request doesn't count as carrying the token, and a 401 from a mirror doesn't mark the token refused. Tests: - TestTaggedReposSlowSearch: a search answering after 3x taggedWait still lists; one that never answers fails at taggedSearch. - TestDoKeepsCredentialsOfficial, rewritten to the new contract: the official address gets the token, the mirror gets none, and the caller's request is unchanged. Cookie, query token and npm still stay official. - TestMirrorAnswerIsNotTheToken (ghtoken). Run on mote: - go test -tags nogui -count=1 ./internal/source ./internal/ghtoken ./internal/plugin ./internal/library: all ok. - Broken by hand: with the old source.go, ghtoken.go and github.go, all three tests went red ("requests = [https://api.github.com/repos/o/r]"; "token=true"; "context deadline exceeded" at taggedWait). - Locally: gofmt -l clean; go vet for linux and windows on the three packages; go build -tags nogui ./... Not tried: - The real network from mainland China. - A live gh-proxy answer to an anonymous api.github.com search. - Not changed: the mirror for api.github.com still waits for MAGPIE_MIRRORS. Without it, the 60s alone covers the ~30s page. - No GUI file was run: the page's fixtures fake /api/plugins/github, and nothing in the window changed. Reported by MYCF711. |
||
|
|
0f044e9447 |
plugins: a GITHUB_TOKEN GitHub refuses is dropped for anonymous requests, not shown as an error (till on Discord)
till's Plugins page said "无法连接 GitHub: GitHub refused GITHUB_TOKEN (no GitHub token is set in Settings → Network and sharing)". ghtoken.Token falls back to the environment's GITHUB_TOKEN / GH_TOKEN, and a stale one there made every GitHub read fail, though GitHub serves the same reads without a token. ghtoken.Do now sends a GitHub API request with the token. When the token came from the environment and GitHub answers 401, it remembers that token as refused for the rest of the process (Token() skips it, so GH_TOKEN is still tried after a refused GITHUB_TOKEN, and Settings no longer shows it) and asks once more without Authorization, returning that answer. A token set in Settings is never dropped: its 401 is still Refused()'s error. An anonymous rate limit after the drop is said by LimitedBy as before. Every caller goes through it: plugin fetchJSONFrom (tagged-repo search, git plugin checks, githubHead) and getURLFrom (Bun), and library apiGet, skills fetch, skilltree fetchBlob and latestRTK via doGitHub. internal/davsync/github.go stays strict: its token is the one the user gave sync to write a private repo, outside ghtoken, and an anonymous retry can't write there, so it would only hide why sync failed. Tests (httptest only): ghtoken_test covers an env token refused then asked again without, not sent again (and GH_TOKEN tried next), a Settings token refused stays an error, an env token refused then an anonymous rate limit is reported, and another host untouched. plugin TestTaggedReposStaleEnvTokenDropped is till's case: TaggedRepos with GITHUB_TOKEN=stale-till lists 7 repos, no error. github_token_test and library TestGitHubRateLimitSaid now expect the env token dropped and the Settings token still refused. Broken by hand, each red: (a) no anonymous retry: every new env test, the plugin and library tests red, and TestTaggedReposStaleEnvTokenDropped shows till's exact error; (b) no memory of the refusal: NotSentAgain, the plugin and library tests red; (c) a Settings token also retried: SettingsTokenRefusedStaysAnError, the plugin and library tests red. Run on the commit before the rebase (base |
||
|
|
fb101b0d57 |
plugins: a GitHub list that couldn't be read says why with Try again, instead of the section vanishing (till on Discord)
till (Windows, v0.1.1293, Belarus network) saw no "Unofficial plugins ·
GitHub" section in Plugins › Discover; a magpie in Japan shows it. On
v0.1.1293 the section shows its loading skeleton and then disappears
whenever GitHub can't be read: plugin.TaggedRepos returned the last list
(or nothing) with no error when the topic search failed, and an empty
list with no error when the search answered but every package.json read
from raw.githubusercontent.com failed or timed out. /api/plugins/github
answered 200 {repos:[]}, and the page showed ghFailed only on an HTTP
error, never in a search, and never once a list had been had.
Now:
- TaggedRepos returns the error with what it has. A failed search keeps
the last list and says why (held a minute, like before); repositories
the search found but that couldn't be read come back as a
*TaggedMissing with their count and the last read error.
- /api/plugins/github sends error and missing beside repos; ?again asks
GitHub again at once when the last answer had an error.
- The page shows the reason and Try again: in place of the section when
nothing could be read (in Discover and in a search), and as a line over
the cards when some were read or an older list is kept. Try again keeps
the cards while it asks. zh, zh-TW, ja and de strings added.
No Windows-only cause was found in the code: the fetch goes through the
same netproxy on every OS (a PAC-only system proxy isn't read anywhere).
The likely cause is the network reaching api.github.com or
raw.githubusercontent.com, or the unauthenticated search limit; the page
now names which.
Run (worktree on
|
||
|
|
ba132d68b6 |
plugin: the GitHub plugin list reads every page of the search, not the top 50 (@HoGee_xxl on X)
@HoGee_xxl on X: the Plugins page's GitHub list showed 50 repositories
while the opencode-plugin topic held 59. askTagged asked GitHub's search
for one page of 50 and stopped, so every repository past the 50th by
stars never showed. It now reads pages of 100 until a short page or
total_count, up to the 1000 GitHub's search answers, and a repository
that moves between two pages (starred in between) is listed once.
Run:
- TestTaggedReposEveryPage (new): a fake search of 7 repositories served
2 a page; all 7 listed, in order, once. Red with the page loop broken by
hand (stop after page 1): only the first 2 listed.
- Full suite at
|
||
|
|
b6533893a7 |
plugins: Discover lists tools and page plugins, and the intro links to the plugin docs
Every kind of plugin magpie runs now has its place on the Plugins page, so
someone looking to extend magpie finds what exists and how to write one:
- Discover has "Tools for agents" (market kind "tools") and "Pages" (kind
"page") sections beside Subscriptions, Gateway middleware and Agents,
each card with its own chip (a new Tools chip, the Page chip). Before,
both kinds fell under Subscriptions as Providers.
- A GitHub repository tagged magpie-plugin whose package.json has
magpie.page.file is a Page, and that file must be committed, as a
provider's entry must (TaggedRepos).
- An installed plugin that only gives tools wears the Tools chip.
- The intro says what a plugin can be (provider, gateway middleware,
routing strategy, tools, an agent, a page) and its "Write a plugin" link
opens usemagpie.ai/docs/plugins in the window's language (zh and zh-TW
to zh/, ja to ja/), outside the window.
- The docs' Publishing section lists the "tools", "page" and "agent"
registry kinds and the community package names for each, in en, zh, ja.
Run at the reviewed head (on origin/main
|
||
|
|
3857376a2f |
tests: the slow-read list's immediate re-ask is asked within its own retry window (#1889)
TestTaggedReposSlowRead 在负载下(load ~28)误报一次:晚到读取的轮询上限 10s 与 taggedRetry=1s 重叠,轮询加首次调用超过 retry 窗口后,被截断的列表 被(正确地)再问,测试把它当成 bug。按 LESSONS 注入 1.2s 延迟复现 ("asked again at once: 3"),随后修复并保持延迟下通过。 修法:把「不重问」断言放在它自己的 retry 窗口内——断言前将 taggedAt 移到 now,断言后(含 Fatal 分支)还原。窗口与轮询耗时不重叠,测试两边留余量 (code standards: a timing test leaves room on both sides)。「past taggedRetry」步骤仍用还原后的真实窗口,sleep 与断言语义不变。 验证:注入延迟下旧代码 FAIL(asked again at once: 3)、新代码 PASS; -count=3 通过;TestTaggedRepos 不受影响。 Changed on review: moving taggedAt to now made the step ask about a whole list (held ten minutes), so a cut-short list no longer held for taggedRetry passed the test. The step now marks the list cut short now, as TaggedRepos does, and the hold itself is checked right after the cut-short ask: held till between ask-start+taggedRetry and ask-end+taggedRetry, bounds from the clock with no slack to outgrow. Run: old test + 1.2s injected before the step: FAIL "asked again at once: 3"; new test + the same delay: ok. Hold broken by hand (-taggedTTL) and doubled (2*taggedRetry): both FAIL at the new bound. -count=5 TestTaggedRepos*: ok. Full internal/plugin (-tags nogui): ok, 649s under load. |
||
|
|
48e59c5b89 |
plugin: the unofficial plugins on GitHub aren't cut short through a slow proxy, and a list cut short is asked again in 20s, not kept ten minutes (larchsis on X)
larchsis (Windows, no system proxy, magpie's own proxy on) saw no
unofficial plugins on the Plugins page, and saw them with the system
proxy on and magpie's set to automatic.
No request bypasses magpie's proxy. Every listing and install read
(market.json, npm info and search, GitHub's search, package.json and
README, Bun's download, plugin icons) goes through http.DefaultClient or
DefaultTransport, which netproxy.Install routes through settings.Proxy,
else the environment, else the system proxy (HKCU Internet Settings on
Windows). Checked with a counting CONNECT proxy in a sandbox magpie on
macOS and on the Windows box: every connection to api.github.com,
raw.githubusercontent.com and registry.npmjs.org went through it, and
lsof / Get-NetTCPConnection showed none going direct.
The cause is timing. askTagged gave the whole listing 8s, six package.json
reads at once, each bounded by that same 8s, and a repository whose read
hadn't finished was left out. The cut list was then kept ten minutes, and
on disk for a restart. Through a sandbox proxy that adds latency per
chunk: no delay 29 repos, 150ms 21, 300ms 6. A slow proxy loses most of
"Unofficial, on GitHub", and when it loses all of them the section is gone.
The two setups differ in latency and in what was cached, not in proxy
handling.
Now:
- Reads go on past the page's wait (taggedEach 20s each, 12 at once), on a
context detached from the request. They are kept by repository and push,
as before, so the next ask has them.
- A repository whose read didn't come in time is as the last list had it
(in memory, else on disk), with the search's current stars and
description.
- A list that left one out is asked again after 20s, not ten minutes. Its
copy on disk is dated so that a restarted magpie asks again too.
Run:
- TestTaggedReposSlowRead (new) holds word-guard's package.json past a
300ms wait. It fails on the old code (5 repos, word-guard missing). It
also fails with each part broken by hand: no fallback to the last list,
a partial list kept 10 minutes, reads cancelled at the wait, and the disk
copy not aged back.
- Sandbox magpie web (own HOME, own ports, proxy 127.0.0.1:3481 with
injected latency), no cache: at 300ms 11 repos at 8s, then all 29 25s
later (the old code kept 6 for ten minutes). At 1s none at first, all 29
25s later.
- go test ./... on
|
||
|
|
61c40b80bb |
plugin: a GitHub-tagged agent plugin is listed as an agent, not left out
TaggedRepos knew a package.json's magpie.middleware but not magpie.agent (cb406c84's new kind). An agent package has no main and no index.js, so it was looked for at index.js, not found, and dropped from Plugins › Discover. It is now kind "agent", its entry checked at magpie.agent, and the GUI's kindOf already shows it under Agents. Fixture: someone/agent-aider, the bytes of magpie-community's packages/aider package.json and aider.agent.js. Run: go test -tags nogui ./internal/plugin ./internal/gui ok; TestTaggedRepos fails on the old github.go (agent-aider missing); gofmt; GOOS=linux/windows go vet ./internal/plugin. |
||
|
|
a3a8e25792 |
plugins: a repository tagged magpie-plugin shows the icon its package.json gives (yetone: 非官方的插件能否支持 icon)
magpie.icon, an https URL or a data:image URI, is read with the rest of package.json and kept through pluginOwnIcon as an installed plugin's is; the card shows it, else the puzzle piece. Ran: go test ./internal/plugin ./internal/gui ./internal/provider; the plugin GUI tests in Chromium and WebKit (en/zh/ja/de, 980 and 440). |
||
|
|
cdf325f178 |
plugins: a package that is only a command (an MCP server like magpie-x-search) isn't listed under Unreviewed, isn't added as a plugin, and one added before says what it is instead of a host stack (#1327, congee949)
A repository tagged magpie-plugin whose npm copy (from that repository) names no file to load (no main, no exports) was listed and installed from npm without the entry check the GitHub route has; it then failed every host start with "has no entry" and a stack. Now: - the Unreviewed list checks npm's copy the same way: one that names no file needs the index.js the repository's own route needs (askTagged); - `magpie plugin add` / the Plugins page refuse a package that names no file, has no index file and is neither pi's nor a middleware, take the package just installed for it out again, and say it isn't an OpenCode or magpie plugin, and, for one with a bin, to add an MCP server under Library → MCP servers (notPlugin); - the host says the same, without a stack, for one already on the list. Run: TestCommandOnlyPackageIsNoPlugin (magpie-x-search 1.2.0's real package.json) fails without the change (Add = <nil>; with only host.js reverted, the stack message), TestTaggedRepos with the real GitHub package.json and npm latest of cyberElar/magpie-x-search fails without it (listed), both pass with it; TestNotPluginKeepsPlugins (index.mjs, main, exports, middleware, pi, a file stay plugins). go test -tags nogui ./internal/plugin under a temp HOME ok; go vet -tags nogui for darwin, linux, windows. The built binary in a sandbox HOME: `magpie plugin add magpie-x-search@latest` from real npm prints the new error, and plugins/package.json no longer lists it. Co-Authored-By: Claude <noreply@anthropic.com> |
||
|
|
a12f6fc13a |
plugins: a repository tagged magpie-plugin shows within ten minutes, not up to six hours later (lee04052822 on X: tagged it, and magpie didn't show it)
GitHub's search was asked at most every six hours. An author who had opened the Plugins page before tagging their repository, as lee04052822 had, didn't see it until the six hours were up. It is now asked at most every ten minutes. A search is one request of the ten a minute that GitHub allows without a token. What each repository's package.json, npm and entry file said is kept while its last push stays the same, so asking again costs one request, not three per repository. An answer GitHub or npm didn't give (a 503 for the entry, say) isn't kept, and is asked again next time. Against real GitHub: the topic has two repositories, mu-zi-lee/magpie-doubao-translate and SadWood/magpie-gaccode. Both are listed as github: installs, the first time in 3.8s and in 0.2s once the ten minutes are up. Both installed and loaded in a sandbox magpie, giving the Doubao Translation and GACCode providers. TestTaggedRepos checks that asking again after ten minutes reads only flaky-entry again, and it fails with 21 reads when the per-repository cache is turned off. go test -race -count=2 ./internal/plugin and go vet pass. |
||
|
|
f6f960e42c |
plugins: a GitHub repository tagged magpie-plugin shows on the Plugins page under Discover, as an unofficial plugin nobody at magpie has reviewed
GitHub's search for topic:magpie-plugin (not archived, not a fork, not magpie-community's own, which the market lists) is asked at most every six hours and kept on disk, so a restart or GitHub being down shows what it said last. Each repository is read from its package.json on the default branch. When npm has that package published from the same repository, it is installed from npm, because a repository often builds its dist only to publish and Bun runs no build for a git install. Otherwise it is installed as github:owner/repo, and only if the file it loads (exports, main or magpie.middleware) is in the repository. Its page warns that it is unofficial, says whether npm or the repository is what gets installed, and shows the repository's README until it is installed. MAGPIE_PLUGIN_MARKET=off asks GitHub nothing. Checked against real GitHub with the topic set to opencode-plugin in a sandbox: 43 repositories came back, and 32 were kept (30 from npm, 2 from git). github:ndom91/open-plan-annotator, one of the git ones, really installed and loaded. alfaoz/opencode-see-image, whose dist isn't in its repository, failed to load before the entry check and is now left out. The test fixtures are GitHub's and npm's real answers. Ran: go test -race -count=3 ./internal/plugin, go test ./internal/gui, go vet, and plugin-github.test.cjs (Chromium and WebKit, 980/440, en/zh/ja/de, 18/18). The full GUI suite passed 3343 of 3348. The 5 failures were WebKit number-units, purpose-filter and routing-failed-open, which pass 3/3 on their own and don't touch the Plugins page. |