diff --git a/docs/reference.md b/docs/reference.md index ab6d2356d..d788e0209 100644 --- a/docs/reference.md +++ b/docs/reference.md @@ -554,6 +554,8 @@ OpenCode ignores: host, which magpie fetches once and keeps, or a `data:image/…` URI; PNG, JPEG, GIF, WebP, ICO or SVG, at most 1 MB. Anything else is ignored, and the icon the plugin market lists for the plugin is shown instead. + The `package.json` icon is also the card's picture under Discover → + Unofficial, on GitHub for a repository tagged `magpie-plugin`. - **An API key's field**: a `type: "api"` method's `label` titles the key's field, as OpenCode's dialog does (one that only says "API key" reads " API key"), and its `placeholder` is the hint inside the field diff --git a/internal/gui/assets/plugins.js b/internal/gui/assets/plugins.js index cdb57fca9..6a7389efb 100644 --- a/internal/gui/assets/plugins.js +++ b/internal/gui/assets/plugins.js @@ -115,7 +115,7 @@ // spec (its npm name when its author published it there from the // repository, else github:owner/repo) const ghListing = (r) => ({ - package: r.spec, name: r.repo.split("/")[1], kind: r.kind, github: r, + package: r.spec, name: r.repo.split("/")[1], kind: r.kind, github: r, icon: r.icon || undefined, summary: r.description ? { en: r.description } : undefined, npm: { version: r.version || "", publisher: r.owner, repository: r.url, license: r.license, weekly: 0 }, }); diff --git a/internal/gui/plugins.go b/internal/gui/plugins.go index 742218f01..d9c216baa 100644 --- a/internal/gui/plugins.go +++ b/internal/gui/plugins.go @@ -256,7 +256,13 @@ func pluginRoutes(mux *http.ServeMux, w Windows) { // repositories on GitHub tagged magpie-plugin: nobody's list, shown // apart as not reviewed, installed from the repository mux.HandleFunc("GET /api/plugins/github", func(rw http.ResponseWriter, r *http.Request) { - writeJSON(rw, map[string]any{"repos": plugin.TaggedRepos(r.Context()), "topic": plugin.Topic}) + // each one's own picture as the page can show it, kept here as an + // installed plugin's is (a data URI isn't sent on to the page) + repos := append([]plugin.Tagged(nil), plugin.TaggedRepos(r.Context())...) + for i := range repos { + repos[i].Icon = provider.RepoIcon(repos[i].Icon) + } + writeJSON(rw, map[string]any{"repos": repos, "topic": plugin.Topic}) }) mux.HandleFunc("GET /api/plugins/npm", func(rw http.ResponseWriter, r *http.Request) { names := []string{} diff --git a/internal/gui/tests/plugin-github.test.cjs b/internal/gui/tests/plugin-github.test.cjs index c762c7ae9..a6d6e3d62 100644 --- a/internal/gui/tests/plugin-github.test.cjs +++ b/internal/gui/tests/plugin-github.test.cjs @@ -22,7 +22,7 @@ const { chromium, webkit } = require("playwright"); const assets = path.resolve(__dirname, "../assets"); const REPOS = [ - { spec: "opencode-claude-auth", repo: "griffinmartin/opencode-claude-auth", url: "https://github.com/griffinmartin/opencode-claude-auth", owner: "griffinmartin", ownerAvatar: "https://avatars.githubusercontent.com/u/1090329?v=4", description: "OpenCode plugin that uses your existing Claude Code credentials — no separate login needed. ", stars: 1301, license: "MIT", pushed: "2026-09-22T23:47:15Z", package: "opencode-claude-auth", version: "2.2.1" }, + { spec: "opencode-claude-auth", repo: "griffinmartin/opencode-claude-auth", url: "https://github.com/griffinmartin/opencode-claude-auth", owner: "griffinmartin", ownerAvatar: "https://avatars.githubusercontent.com/u/1090329?v=4", description: "OpenCode plugin that uses your existing Claude Code credentials — no separate login needed. ", stars: 1301, license: "MIT", pushed: "2026-09-22T23:47:15Z", package: "opencode-claude-auth", version: "2.2.1", icon: "file:claude-auth.svg" }, { spec: "@slkiser/opencode-quota", repo: "slkiser/opencode-quota", url: "https://github.com/slkiser/opencode-quota", owner: "slkiser", ownerAvatar: "https://avatars.githubusercontent.com/u/35721408?v=4", description: "OpenCode quota & tokens usage with zero context window pollution. Supports OpenCode Go, Cursor, GitHub Copilot, OpenAl, Kimi Code, Alibaba Coding Plan, Chutes Al, Google Antigravity, Z.ai Coding Plan and more.", stars: 1000, license: "MIT", pushed: "2026-10-06T13:25:50Z", package: "@slkiser/opencode-quota", version: "5.0.2" }, { spec: "github:keli-wen/agy-staff", repo: "keli-wen/agy-staff", url: "https://github.com/keli-wen/agy-staff", owner: "keli-wen", ownerAvatar: "https://avatars.githubusercontent.com/u/103916249?v=4", description: "Hire Google's Antigravity CLI (agy) as a fast Gemini staffer for Claude Code and OpenAI Codex.", stars: 723, license: "MIT", pushed: "2026-10-06T16:29:15Z", package: "agy-staff", version: "0.7.4" }, { spec: "@rama_nigg/open-cursor", repo: "Nomadcxx/opencode-cursor", url: "https://github.com/Nomadcxx/opencode-cursor", owner: "Nomadcxx", ownerAvatar: "https://avatars.githubusercontent.com/u/143774106?v=4", description: "Use Cursor Pro models in OpenCode via HTTP proxy with OAuth", stars: 704, license: "BSD-3-Clause", pushed: "2026-10-02T12:34:45Z", package: "@rama_nigg/open-cursor", version: "2.5.11" }, @@ -65,6 +65,7 @@ function server(lang, asked) { return json(state()); } if (url.pathname === "/api/open") { asked.push(["open", body()]); return route.fulfill({ status: 204 }); } + if (url.pathname === "/api/icons/claude-auth.svg") return route.fulfill({ contentType: "image/svg+xml", body: '' }); if (url.pathname.startsWith("/api/")) return json({}); if (!/^\/[\w./-]*$/.test(url.pathname) || url.host !== "magpie.test") { asked.push(["fetched", url.href]); return route.fulfill({ status: 404, body: "" }); } const file = path.join(assets, url.pathname === "/" ? "index.html" : url.pathname); @@ -120,6 +121,11 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", const c = cards.first(); assert.equal((await c.locator(".pm-by").innerText()).trim(), "griffinmartin"); + // the picture its package.json gives (magpie.icon), as magpie keeps it; one that gives none, the puzzle + assert.equal(await c.locator(".pm-logo img").getAttribute("src"), "/api/icons/claude-auth.svg"); + assert.equal(await cards.nth(2).locator(".pm-logo img").count(), 0); + // a provider and a middleware part by hue (yetone: 中间件和供应商稍微有点区分吧) + assert.equal(await c.locator(".pm-chip.kind.pv").count(), 1); assert.equal((await c.locator(".pm-chip.warn").innerText()).trim(), w.chip); assert.match(await c.locator(".pm-chip.warn").getAttribute("title"), /magpie-plugin/); assert.equal((await c.locator(".pm-dl").innerText()).trim(), "1.3k"); diff --git a/internal/plugin/github.go b/internal/plugin/github.go index d6fb5c7c1..a41d2eaf8 100644 --- a/internal/plugin/github.go +++ b/internal/plugin/github.go @@ -38,6 +38,9 @@ type Tagged struct { Package string `json:"package,omitempty"` Version string `json:"version,omitempty"` Kind string `json:"kind,omitempty"` // "middleware" when that is all it is + // its package.json's magpie.icon, as an installed plugin gives its + // provider one: an https URL or a data:image URI, as it is written + Icon string `json:"icon,omitempty"` } // Where GitHub is asked, moved by tests. @@ -196,7 +199,7 @@ func askTagged(ctx context.Context) ([]Tagged, error) { if branch == "" { branch = "HEAD" } - pb, err := fetchJSON(pc, githubRaw+"/"+t.Repo+"/"+url.PathEscape(branch)+"/package.json", 256<<10) + pb, err := fetchJSON(pc, githubRaw+"/"+t.Repo+"/"+url.PathEscape(branch)+"/package.json", 2<<20) if err != nil { read = errors.Is(err, errNotFound) return @@ -208,6 +211,7 @@ func askTagged(ctx context.Context) ([]Tagged, error) { Exports json.RawMessage `json:"exports"` Magpie struct { Middleware string `json:"middleware"` + Icon string `json:"icon"` } `json:"magpie"` } if json.Unmarshal(pb, &pj) != nil || !pkgName.MatchString(pj.Name) { @@ -215,6 +219,11 @@ func askTagged(ctx context.Context) ([]Tagged, error) { return } t.Package, t.Version = pj.Name, pj.Version + // a picture, as host.js's iconOf takes one: magpie checks and + // keeps it before the page shows it (the GUI's /api/plugins/github) + if ic := strings.TrimSpace(pj.Magpie.Icon); len(ic) <= 3<<19 && (strings.HasPrefix(strings.ToLower(ic), "https://") || strings.HasPrefix(strings.ToLower(ic), "data:image/")) { + t.Icon = ic + } if strings.TrimSpace(pj.Magpie.Middleware) != "" && pj.Main == "" && len(pj.Exports) == 0 { t.Kind = "middleware" } diff --git a/internal/plugin/github_test.go b/internal/plugin/github_test.go index 6249913c3..accddea3c 100644 --- a/internal/plugin/github_test.go +++ b/internal/plugin/github_test.go @@ -142,6 +142,14 @@ func TestTaggedRepos(t *testing.T) { if x := byRepo["someone/flaky-entry"]; x.License != "" { t.Fatalf("NOASSERTION is no license: %+v", x) } + // its own picture, package.json's magpie.icon, as an installed + // plugin's provider has it; none when it gives none + if x := byRepo["someone/flaky-entry"]; !strings.HasPrefix(x.Icon, "data:image/svg+xml;base64,") { + t.Fatalf("magpie.icon: %q", x.Icon) + } + if c.Icon != "" { + t.Fatalf("no magpie.icon, yet %q", c.Icon) + } if x := byRepo["someone/word-guard"]; x.Kind != "middleware" || x.Package != "@magpie-community/middleware-word-guard" || x.License != "" { t.Fatalf("a middleware alone: %+v", x) } diff --git a/internal/plugin/testdata/github/raw/someone/flaky-entry/main/package.json b/internal/plugin/testdata/github/raw/someone/flaky-entry/main/package.json index 242d8e5bd..9204fead4 100644 --- a/internal/plugin/testdata/github/raw/someone/flaky-entry/main/package.json +++ b/internal/plugin/testdata/github/raw/someone/flaky-entry/main/package.json @@ -2,5 +2,6 @@ "name": "flaky-entry", "version": "0.1.0", "type": "module", - "main": "./index.js" + "main": "./index.js", + "magpie": { "icon": "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxNiAxNiI+PGNpcmNsZSBjeD0iOCIgY3k9IjgiIHI9IjYiLz48L3N2Zz4=" } } diff --git a/internal/provider/plugin_icon.go b/internal/provider/plugin_icon.go index 4357819de..a75028b50 100644 --- a/internal/provider/plugin_icon.go +++ b/internal/provider/plugin_icon.go @@ -112,6 +112,11 @@ func pluginOwnIcon(said string) string { return "" } +// RepoIcon is the Icon value of the picture a plugin not installed yet +// gives in its package.json (a repository tagged magpie-plugin), checked +// and kept as an installed plugin's is: "" while there is none to show. +func RepoIcon(said string) string { return pluginOwnIcon(said) } + // keptPluginIcons are the names of the stored pictures plugins gave, which // pruneIcons leaves. func keptPluginIcons() []string { diff --git a/site/public/docs/ja/plugins.html b/site/public/docs/ja/plugins.html index 1c044050d..7df9e33a0 100644 --- a/site/public/docs/ja/plugins.html +++ b/site/public/docs/ja/plugins.html @@ -581,7 +581,7 @@ m plugin logout acme "summary": { "en": "Your Acme Coding Plan.", "zh": "使用你的 Acme Coding Plan。" } } ミドルウェアのエントリには "kind": "middleware" を書き、providers は書きません。ゲートウェイミドルウェア の下に表示されます。MAGPIE_PLUGIN_MARKET=<url> は magpie に別の一覧を参照させます(自分の一覧の確認に便利です)。off にすると内蔵のコピーだけを使います。 -
  • GitHub のトピック。GitHub で magpie-plugin トピックを付けたリポジトリは、プラグイン → 発見 → 非公式 · GitHub に、スターの多い順に、誰もレビューしていないものとして表示されます。package.json はリポジトリのルートに置いてください。repository がそのリポジトリを指す形で npm に公開されていれば npm からインストールされ、そうでなければリポジトリの現在のコードがインストールされます。そのため読み込むファイルはコミットしておく必要があり、dist を公開時にしかビルドしないリポジトリは表示されません。フォーク、アーカイブ済みのリポジトリ、magpie-community 自身のものも表示されません。magpie が GitHub に問い合わせるのは最大で 10 分に 1 回なので、トピックを付けたリポジトリは数分で表示されます。
  • +
  • GitHub のトピック。GitHub で magpie-plugin トピックを付けたリポジトリは、プラグイン → 発見 → 非公式 · GitHub に、スターの多い順に、誰もレビューしていないものとして表示されます。package.json はリポジトリのルートに置いてください。repository がそのリポジトリを指す形で npm に公開されていれば npm からインストールされ、そうでなければリポジトリの現在のコードがインストールされます。そのため読み込むファイルはコミットしておく必要があり、dist を公開時にしかビルドしないリポジトリは表示されません。フォーク、アーカイブ済みのリポジトリ、magpie-community 自身のものも表示されません。magpie が GitHub に問い合わせるのは最大で 10 分に 1 回なので、トピックを付けたリポジトリは数分で表示されます。カードには package.json の "magpie": { "icon": "…" } で指定したアイコンが表示され、ない場合はパズルのアイコンになります。
  • コミュニティのパッケージ。magpie-community/plugins に貢献するには: