library: a plugin's tag shows only what that plugin brought (#7280)

Skills, Hooks and Subagents tag a part a Claude plugin brought "In
<plugin>", but nothing on those tabs could narrow to a plugin: typing
its name in the skills' filter found nothing (jinpwng).

- On Skills, Hooks and Subagents the tag is now a button. It shows only
  that plugin's items, under a bar naming it ("Only what code-kit
  brings") with Show all. The pick is per tab and in memory only;
  nothing is written. It clears itself once the plugin brings none of
  the tab's items. MCP keeps the plain tag.
- The skills' filter matches a skill's plugin name too.
- A clickable tag on a library row wraps under a long name instead of
  being cut off by the name's ellipsis. At 420px in zh, zh-TW, ja and
  de the tag was clipped and could not be clicked. This also covers
  "Update available".
- New string in zh, zh-TW, ja and de.

Run (mote, load ~30-45 from other sessions' suites): node --test
library-plugin-filter (new: each tab, tag to bar to Show all, the skills
filter by plugin name, no write, no dialog, no page error; en, zh,
zh-TW, ja and de at 420 and 1100, chromium and webkit), skill-where,
skill-auto-update, skill-update-edited, skill-update-feedback,
phone-no-sideways and library-plugin-parts: 210 of 210 ok. Before the
wrap rule, library-plugins, library-hooks, library-subagents(-import),
skill-groups, skill-parts and i18n-keys were run too. Only
library-plugin-filter's 420 non-English cases failed there (the clipped
tag, now fixed), plus one webkit skill-where "ResizeObserver loop" page
error that passed on the rerun.
Broken by hand: with the tag's onclick setting nothing,
library-plugin-filter is 0 of 62.
Not tried: a real Claude plugin in the app; the faked API has one.
This commit is contained in:
yetone
2026-11-20 12:06:44 +08:00
parent 57c90f9f27
commit ac456d819f
5 changed files with 174 additions and 15 deletions
File diff suppressed because one or more lines are too long
+45 -14
View File
@@ -2897,11 +2897,36 @@ magpie.plugin("library", (ctx) => {
}
// a part a Claude plugin brought: its agents follow the plugin's when
// those change (library/plugin.go givePlugin)
const withPlugin = (nm, x) => {
if (x.bundle) nm.append(tag(t("In {plugin}", { plugin: x.bundle }), "lib-bundle",
t("Comes with the Claude plugin {plugin}. Changing the plugin's agents, or turning it off and on, gives this to the plugin's agents again.", { plugin: x.bundle })));
// On Skills, Hooks and Subagents (kind) the tag shows only what that
// plugin brought, the rest back with the bar's Show all (#7280, jinpwng)
const withPlugin = (nm, x, kind) => {
if (!x.bundle) return nm;
const b = tag(t("In {plugin}", { plugin: x.bundle }), "lib-bundle",
t("Comes with the Claude plugin {plugin}. Changing the plugin's agents, or turning it off and on, gives this to the plugin's agents again.", { plugin: x.bundle }));
if (kind) {
b.classList.add("link");
b.dataset.bundle = x.bundle;
b.onclick = (e) => { e.stopPropagation(); bundleOnly[kind] = x.bundle; render(); };
}
nm.append(b);
return nm;
};
// what a tab shows of a plugin's, picked from its tag: nothing once the
// plugin brings none of the tab's items any more
const bundleOnly = {};
const onlyBundle = (kind, items) => {
const b = bundleOnly[kind];
if (b && !items.some((x) => x.bundle === b)) delete bundleOnly[kind];
return bundleOnly[kind] ? items.filter((x) => x.bundle === bundleOnly[kind]) : items;
};
function bundleBar(kind) {
const b = bundleOnly[kind];
if (!b) return [];
const bar = el("div", "row-head lib-bundleonly");
bar.append(el("span", "label", t("Only what {plugin} brings", { plugin: b })), el("span", "grow"),
button(t("Show all"), "lib-bundleall", () => { delete bundleOnly[kind]; render(); }));
return [bar];
}
// ---------- MCP servers ----------
@@ -4811,8 +4836,8 @@ magpie.plugin("library", (ctx) => {
body.append(rh);
}
const list = el("div", "list lib-list");
list.append(...[...hooks].sort((a, b) => a.name.localeCompare(b.name)).map((h) => hookRow(h, all)));
body.append(list);
list.append(...onlyBundle("hooks", [...hooks]).sort((a, b) => a.name.localeCompare(b.name)).map((h) => hookRow(h, all)));
body.append(...bundleBar("hooks"), list);
if (picking) body.append(pickBar(all));
const after = el("div", "after-list");
after.append(button(t("+ Add hook"), "", () => editHook(null)));
@@ -4839,7 +4864,7 @@ magpie.plugin("library", (ctx) => {
function hookRow(h, all) {
const row = el("div", "row lib-row click lib-hook");
const who = el("div", "who");
who.append(withPlugin(el("div", "name mono", h.name), h));
who.append(withPlugin(el("div", "name mono", h.name), h, "hooks"));
// what it is for, in the user's own words (#2011)
if (h.description) who.append(el("div", "lib-hookdesc", h.description));
who.append(el("div", "sub lib-hookev", hookLine(h)));
@@ -5020,8 +5045,8 @@ magpie.plugin("library", (ctx) => {
body.append(empty(t("No subagents in the library yet"), t("Add one, and pick the agents that can hand it a task."), button(t("+ Add a subagent"), "action", () => editSubagent(null))));
} else {
const list = el("div", "list lib-list");
list.append(...[...subs].sort((a, b) => a.name.localeCompare(b.name)).map((s) => subagentRow(s, all)));
body.append(list);
list.append(...onlyBundle("subagents", [...subs]).sort((a, b) => a.name.localeCompare(b.name)).map((s) => subagentRow(s, all)));
body.append(...bundleBar("subagents"), list);
const after = el("div", "after-list");
after.append(button(t("+ Add subagent"), "", () => editSubagent(null)));
body.append(after);
@@ -5159,7 +5184,7 @@ magpie.plugin("library", (ctx) => {
function subagentRow(s, all) {
const row = el("div", "row lib-row click lib-subagent");
const who = el("div", "who");
who.append(withPlugin(el("div", "name mono", s.name), s));
who.append(withPlugin(el("div", "name mono", s.name), s, "subagents"));
who.append(el("div", "lib-subagentdesc", s.description));
const line = subagentLine(s);
if (line) who.append(el("div", "sub lib-subagentuses", line));
@@ -5953,7 +5978,8 @@ magpie.plugin("library", (ctx) => {
null,
many && [removeEveryButton("skills"), GLYPH.trash],
]));
body.append(rh);
onlyBundle("skills", lib.skills);
body.append(rh, ...bundleBar("skills"));
drawSkills(box, all);
body.append(box);
// under the list, so the skills stay where they were above it
@@ -6136,7 +6162,7 @@ magpie.plugin("library", (ctx) => {
if (pick !== "source") {
const skills = [...lib.skills].sort(byName(pick));
const g = { key: "flat", repo: "", skills, parts: null,
text: new Map(skills.map((s) => [s, (s.name + " " + (s.note || "") + " " + (s.description || "") + " " + skillRepo(s)).toLowerCase()])) };
text: new Map(skills.map((s) => [s, (s.name + " " + (s.note || "") + " " + (s.description || "") + " " + (s.bundle || "") + " " + skillRepo(s)).toLowerCase()])) };
grouped[pick] = { lib, groups: [g] };
return grouped[pick].groups;
}
@@ -6184,7 +6210,7 @@ magpie.plugin("library", (ctx) => {
...mine.filter((g) => g.skills.length && mineHere(g)), ...down.sort(byRepo), ...(by.has("local") ? [by.get("local")] : [])];
for (const g of groups) {
g.skills.sort((a, b) => a.name.localeCompare(b.name));
g.text = new Map(g.skills.map((s) => [s, (s.name + " " + (s.note || "") + " " + (s.description || "") + " " + (g.mine || (g.owner ? skillRepo(s) : g.repo))).toLowerCase()]));
g.text = new Map(g.skills.map((s) => [s, (s.name + " " + (s.note || "") + " " + (s.description || "") + " " + (s.bundle || "") + " " + (g.mine || (g.owner ? skillRepo(s) : g.repo))).toLowerCase()]));
g.parts = g.mine ? null : partsOf(g);
}
grouped[pick] = { lib, groups };
@@ -6281,7 +6307,12 @@ magpie.plugin("library", (ctx) => {
// What a group shows: its skills the filter matches, and whether it's
// folded. While filtering a group is open unless folded since the filter
// changed; else as the user last left it, or folded when there are many.
const skillHits = (g, q) => (q ? g.skills.filter((s) => g.text.get(s).includes(q)) : g.skills);
// the filter matches a skill's plugin too (#7280), and a plugin's tag
// picked shows only what it brought
const skillHits = (g, q) => {
const b = bundleOnly.skills;
return q || b ? g.skills.filter((s) => (!b || s.bundle === b) && (!q || g.text.get(s).includes(q))) : g.skills;
};
const groupFolded = (g, q) => (q ? unfiltered.has(g.key) : folds[g.key] ?? lib.skills.length > MANY);
// Collapse all / Expand all (#1862, WardLu): every group the list shows
@@ -8371,7 +8402,7 @@ magpie.plugin("library", (ctx) => {
function skillRow(s, all) {
const row = el("div", "row lib-row click lib-skill" + (s.missing ? " missing" : "") + (s.source ? " src" : "") + (s.offHere ? " offhere" : ""));
const who = el("div", "who");
const nm = withPlugin(el("div", "name", s.name), s);
const nm = withPlugin(el("div", "name", s.name), s, "skills");
const c = s.check;
const gone = isGone(s);
if (gone) {
@@ -9,6 +9,7 @@ magpie.strings({
"Installed in the agents themselves": "Agent 自己安装的内容",
"Listed as the agents' plugins and packages declare them. The agent loads them: magpie copies and changes nothing, and a session shows what is loaded.": "按 Agent 的插件和包所声明的内容列出。由 Agent 自己加载:magpie 不复制也不改动,会话中才能看到实际加载了什么。",
"In {plugin}": "属于 {plugin}",
"Only what {plugin} brings": "只看 {plugin} 带来的",
"Comes with the Claude plugin {plugin}. Changing the plugin's agents, or turning it off and on, gives this to the plugin's agents again.": "随 Claude 插件 {plugin} 安装。改动插件的 Agent,或把插件关掉再打开,会把它重新给到插件的 Agent。",
"Put back in {agents}": "放回 {agents}",
"Put {name} back?": "把 {name} 放回?",
@@ -1168,6 +1169,7 @@ magpie.strings({
"Installed in the agents themselves": "Agent 自己安裝的內容",
"Listed as the agents' plugins and packages declare them. The agent loads them: magpie copies and changes nothing, and a session shows what is loaded.": "依 Agent 的外掛與套件所宣告的內容列出。由 Agent 自己載入:magpie 不複製也不改動,工作階段中才看得到實際載入了什麼。",
"In {plugin}": "屬於 {plugin}",
"Only what {plugin} brings": "只看 {plugin} 帶來的",
"Comes with the Claude plugin {plugin}. Changing the plugin's agents, or turning it off and on, gives this to the plugin's agents again.": "隨 Claude 外掛 {plugin} 安裝。變更外掛的 Agent,或把外掛關閉再開啟,會把它重新給到外掛的 Agent。",
"Put back in {agents}": "放回 {agents}",
"Put {name} back?": "把 {name} 放回?",
@@ -2327,6 +2329,7 @@ magpie.strings({
"Installed in the agents themselves": "エージェント自身がインストールしたもの",
"Listed as the agents' plugins and packages declare them. The agent loads them: magpie copies and changes nothing, and a session shows what is loaded.": "エージェントのプラグインとパッケージが宣言する内容を一覧にしています。読み込むのはエージェント自身で、magpie はコピーも変更もしません。実際に読み込まれたものはセッションで分かります。",
"In {plugin}": "{plugin} の一部",
"Only what {plugin} brings": "{plugin} に含まれるものだけ",
"Comes with the Claude plugin {plugin}. Changing the plugin's agents, or turning it off and on, gives this to the plugin's agents again.": "Claude プラグイン {plugin} と一緒に入りました。プラグインのエージェントを変えるか、オフにしてオンに戻すと、プラグインのエージェントに改めて渡されます。",
"Put back in {agents}": "{agents} に戻す",
"Put {name} back?": "{name} を戻しますか?",
@@ -3486,6 +3489,7 @@ magpie.strings({
"Installed in the agents themselves": "Von den Agents selbst installiert",
"Listed as the agents' plugins and packages declare them. The agent loads them: magpie copies and changes nothing, and a session shows what is loaded.": "So aufgelistet, wie die Plugins und Pakete der Agents sie angeben. Der Agent lädt sie selbst: magpie kopiert und ändert nichts, und eine Sitzung zeigt, was geladen ist.",
"In {plugin}": "Teil von {plugin}",
"Only what {plugin} brings": "Nur, was {plugin} mitbringt",
"Comes with the Claude plugin {plugin}. Changing the plugin's agents, or turning it off and on, gives this to the plugin's agents again.": "Kommt mit dem Claude-Plugin {plugin}. Werden die Agenten des Plugins geändert oder wird es aus- und wieder eingeschaltet, geht dies erneut an die Agenten des Plugins.",
"Put back in {agents}": "Zurück zu {agents}",
"Put {name} back?": "{name} zurückgeben?",
@@ -235,9 +235,14 @@ button.row.lib-hubfolded:hover { background: var(--pill); }
.lib-tag.warn::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
/* what a check for updates found, beside a skill's name */
.lib-row .name .lib-tag { height: 17px; padding: 0 6px; margin-left: 7px; font-size: 10.5px; font-weight: 500; vertical-align: 1px; }
/* a tag that can be clicked wraps under a long name instead of being cut off
by its ellipsis, where a narrow window or a long translation needs it */
.lib-row .name:has(> .lib-tag.link) { white-space: normal; text-overflow: clip; overflow-wrap: anywhere; }
.lib-tag.lib-new { color: var(--accent); background: var(--accent-soft); }
.lib-tag.lib-new::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.lib-tag.lib-new.link { cursor: pointer; }
.lib-tag.lib-bundle.link { cursor: pointer; }
@media (hover: hover) and (pointer: fine) { .lib-tag.lib-bundle.link:hover { color: var(--fg); } }
.lib-tag.lib-new.link:hover { background: color-mix(in srgb, var(--accent) 22%, var(--accent-soft)); }
.lib-tag.lib-unchecked { color: var(--faint); font-weight: 400; }
.lib-tag.lib-unchecked.link { cursor: pointer; }
@@ -0,0 +1,119 @@
// Run with Node's test runner and Playwright on the module path; see README.md.
// #7280 (jinpwng): Skills, Hooks and Subagents show only what one plugin
// brought when its "In code-kit" tag is clicked, under a bar naming it;
// Show all brings the rest back, and nothing is given or taken from an
// agent on the way. The skills' filter matches the plugin's name too.
// Every language, both engines, at 420 and 1100. No backend: the API is
// faked, and any write to it fails the test.
const assert = require("node:assert/strict");
const fs = require("node:fs/promises");
const path = require("node:path");
const { test } = require("node:test");
const { chromium, webkit } = require("playwright");
const { strings } = require("./strings.cjs");
const assets = path.resolve(__dirname, "../assets");
const HOME = "/Users/chuan";
const agent = (id, name) => ({ id, name, icon: "", skills: `${HOME}/.${id}/skills`, mcp: `${HOME}/.${id}/mcp.json` });
const kit = { bundle: "code-kit" };
const lib = () => ({
dir: `${HOME}/.magpie/library`, backups: `${HOME}/.magpie/backups`, home: HOME,
agents: [agent("claude", "Claude Code"), agent("codex", "Codex")],
instructions: { agents: [] }, foundServers: [], projects: [], foundSkills: [], problems: [],
skills: [{ name: "code-kit-tdd", description: "Test first", kind: "", agents: ["claude"], ...kit }, { name: "own-skill", description: "Mine", kind: "", agents: ["claude"] },
...[1, 2, 3, 4, 5, 6, 7, 8].map((n) => ({ name: "own-skill-" + n, description: "Mine too", kind: "", agents: ["claude"] }))],
servers: [{ name: "code-kit-docs", transport: "stdio", command: "/bin/docs", agents: ["claude"], ...kit }, { name: "own-server", transport: "stdio", command: "/bin/own", agents: ["claude"] }],
hooks: [{ name: "code-kit-lint", event: "turn-end", command: "lint", agents: ["claude"], ...kit }, { name: "own-hook", event: "turn-end", command: "own", agents: ["claude"] }],
hookAgents: [{ id: "claude", events: ["turn-end"] }],
subagents: [{ name: "code-kit-reviewer", description: "Reviews", agents: ["claude"], ...kit }, { name: "own-agent", description: "Mine", agents: ["claude"] }],
subagentAgents: [{ id: "claude", dir: `${HOME}/.claude/agents` }],
plugins: [{ name: "code-kit", agents: ["claude"], skills: ["code-kit-tdd"], mcp: ["code-kit-docs"], hooks: ["code-kit-lint"], subagents: ["code-kit-reviewer"] }],
});
let I18N;
function tr(lang, key, vars = {}) {
let s = key;
if (lang !== "en") {
assert.equal(typeof I18N[lang][key], "string", `${lang} has no ${JSON.stringify(key)}`);
s = I18N[lang][key];
}
return s.replace(/\{(\w+)\}/g, (m, k) => (k in vars ? String(vars[k]) : m));
}
function server(lang, writes) {
return async (route) => {
const url = new URL(route.request().url());
if (route.request().method() !== "GET" && url.pathname.startsWith("/api/library")) writes.push(url.pathname);
const json = (data) => route.fulfill({ json: data });
if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:true};` });
if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
if (url.pathname === "/api/state") return json({ agents: [], profiles: [], settings: { lang, theme: "light" } });
if (url.pathname === "/api/library") return json(lib());
if (url.pathname === "/api/plugins") return json({ plugins: [] });
if (url.pathname === "/api/usage/quotas") return json([]);
if (url.pathname === "/api/groups") return json({ groups: [] });
if (url.pathname === "/api/providers") return json({ providers: [], gateway: { running: true } });
if (url.pathname.startsWith("/api/")) return json({});
if (url.host !== "magpie.test") return route.fulfill({ status: 404, body: "" });
const file = path.join(assets, url.pathname === "/" ? "index.html" : url.pathname);
const contentType = { ".html": "text/html", ".js": "text/javascript", ".css": "text/css", ".svg": "image/svg+xml", ".png": "image/png" }[path.extname(file)];
try { await route.fulfill({ body: await fs.readFile(file), contentType }); } catch { await route.fulfill({ status: 404, body: "" }); }
};
}
const TABS = [["skills", ".lib-skill", "code-kit-tdd", "own-skill"],
["hooks", ".lib-hook", "code-kit-lint", "own-hook"], ["subagents", ".lib-subagent", "code-kit-reviewer", "own-agent"]];
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
test(engine + ": a plugin's tag shows only what it brought", async (t) => {
I18N = strings().I18N;
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: process.env.PLAYWRIGHT_CHANNEL || "chromium" }));
t.after(() => browser.close());
for (const lang of ["en", "zh", "zh-TW", "ja", "de"]) for (const width of [1100, 420]) for (const [tab, cls, part, own] of TABS) {
await t.test(`${lang} ${width} ${tab}`, async () => {
const ctx = await browser.newContext({ viewport: { width, height: 900 }, reducedMotion: "reduce" });
t.after(() => ctx.close());
await ctx.addInitScript((tab) => { try { localStorage.setItem("magpie.libTab", tab); } catch {} }, tab);
const page = await ctx.newPage();
page.setDefaultTimeout(5000);
page.setDefaultNavigationTimeout(60000);
const errors = [], writes = [];
page.on("pageerror", (e) => errors.push(e.message));
await page.route("**/*", server(lang, writes));
await page.goto("http://magpie.test/");
await page.locator('button[data-view="library"]').click();
const v = page.locator("#view-library");
const row = (name) => v.locator(cls).filter({ has: page.locator(".name", { hasText: new RegExp("^" + name + "(?!-)") }) }).first();
const bar = v.locator(".lib-bundleonly");
await row(part).waitFor();
await row(own).waitFor();
assert.equal(await bar.count(), 0);
await row(part).locator(".lib-bundle").click();
await bar.waitFor();
assert.equal((await bar.locator(".label").textContent()).trim(), tr(lang, "Only what {plugin} brings", { plugin: "code-kit" }));
await row(own).waitFor({ state: "detached" });
assert.equal(await v.locator(cls).count(), 1, "only the plugin's row is left");
assert.equal(await row(part).count(), 1);
// the tag picks; it doesn't open the row's editor
assert.equal(await page.locator(".modal, .sheet, dialog[open]").filter({ visible: true }).count(), 0);
await bar.locator(".lib-bundleall").click();
await row(own).waitFor();
assert.equal(await bar.count(), 0);
assert.equal(await row(part).count(), 1);
if (tab === "skills") {
const q = v.locator(".lib-skillq");
await q.fill("code-kit");
await row(own).waitFor({ state: "detached" });
assert.equal(await row(part).count(), 1, "the filter matches the plugin's name");
await q.fill("");
await row(own).waitFor();
}
assert.deepEqual(writes, [], "a pick wrote to the library");
assert.deepEqual(errors, []);
});
}
});
}