library: a Claude plugin's parts keep their own agents through sync, and each says which plugin it came with
givePlugin gives every part of a Claude plugin (skills, MCP servers,
hooks, subagents) the plugin's agents. putPlugins' settle ran it on every
sync put, even when the plugin's own agents and switch hadn't changed.
So an agent ticked or unticked on a part's own row was put back on the
next sync without a word. Now settle gives the parts the plugin's agents
only when those agents or the switch change. A part's own edit stays
until then.
The Library never showed `bundle`, so nothing on a part's row said it
belonged to a plugin. Each such row (Skills, MCP, Hooks, Subagents) now
carries an "In {plugin}" tag. Its tooltip says that changing the
plugin's agents, or turning the plugin off and on, gives the part to the
plugin's agents again. The tag is in en, zh, zh-TW, ja and de.
Tests:
- TestPluginPartOwnAgentsKeptBySync: tdd set to claude alone survives a
sync of the same plugin, and changing the plugin's agents gives tdd
the plugin's agents again.
- library-plugin-parts.test.cjs (new): one bundled part and one own part
on every tab. Each bundled part has the tag, with its text and tooltip
in each language, and the own part has none. Nothing is wider than the
window at 1100 and 420. Chromium and WebKit.
Run (mica, at this tree on 32a181868):
- go test ./internal/gui -run 'TestCoreScriptBudget|TestI18n|TestCSS': ok.
- go test ./internal/library: ok.
- every library-*.test.cjs plus i18n-keys, both engines: 1900 pass,
10 red.
- library-open-again's 1100px cases are red on origin/main 98355866f
too, run alone (#6751).
- library-commands' WebKit de case (#7035) and library-pi-market's
Chromium case (#7036) were red under load 110. Run again alone,
they pass on this tree and on origin/main.
Broken by hand, each red, then put back:
- settle giving the parts on every put (`if moved || true`):
TestPluginPartOwnAgentsKeptBySync red ("tdd's agents: claude,codex,
want its own claude").
- withPlugin never tagging (`if (false && x.bundle)`):
library-plugin-parts 82 red of 82.
Not tried: the real app window, or a real Claude plugin's sync between
two computers.
Run again after a rebase on 888d4eba5 (mica): the go test guards and ./internal/library ok; library-plugin-parts, library-plugins, agent-disconnect, agent-bulk-visibility, agent-visibility-saving, plugin-tools, i18n-keys, gui-de, gui-ja and gui-zh-tw, both engines: 155 pass, 0 fail.
At the pushed head, on cb1fe6d5d (mica): the go test guards, ./internal/library -run TestPlugin, i18n-keys and agent-disconnect ok.
This commit is contained in:
@@ -2769,6 +2769,13 @@ magpie.plugin("library", (ctx) => {
|
||||
if (title) s.title = title;
|
||||
return s;
|
||||
}
|
||||
// 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 })));
|
||||
return nm;
|
||||
};
|
||||
|
||||
// ---------- MCP servers ----------
|
||||
|
||||
@@ -3338,6 +3345,7 @@ magpie.plugin("library", (ctx) => {
|
||||
else if (s.signIn?.signedIn) nm.append(tag(t("Signed in"), "lib-signed", t("The agents given it use magpie's sign-in")));
|
||||
// kept to this computer: sync carries it nowhere (huhuy72219405 on X)
|
||||
// a plugin's tools say whose they are, where they are turned off too
|
||||
withPlugin(nm, s);
|
||||
if (s.plugin) nm.append(tag(t("Plugin"), "lib-local lib-plugin", t("{plugin}'s tools. Plugins can hide them from every agent, keeping the plugin; sync never carries them to your other computers", { plugin: s.plugin })));
|
||||
else if (s.local) nm.append(tag(t("Not synced"), "lib-local", s.bridge ? bridgedWhy() : t("Sync never carries it to your other computers")));
|
||||
// out of the hub, each agent's own entry (#4382): said only while the hub is on
|
||||
@@ -4691,7 +4699,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(el("div", "name mono", h.name));
|
||||
who.append(withPlugin(el("div", "name mono", h.name), h));
|
||||
// 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)));
|
||||
@@ -5010,7 +5018,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(el("div", "name mono", s.name));
|
||||
who.append(withPlugin(el("div", "name mono", s.name), s));
|
||||
who.append(el("div", "lib-subagentdesc", s.description));
|
||||
const line = subagentLine(s);
|
||||
if (line) who.append(el("div", "sub lib-subagentuses", line));
|
||||
@@ -7863,7 +7871,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 = el("div", "name", s.name);
|
||||
const nm = withPlugin(el("div", "name", s.name), s);
|
||||
const c = s.check;
|
||||
const gone = isGone(s);
|
||||
if (gone) {
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
// kernel adds them to i18n.js's (magpie.strings).
|
||||
magpie.strings({
|
||||
zh: {
|
||||
"In {plugin}": "属于 {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} 放回?",
|
||||
"It leaves the library and goes back to {agents} as it was before you brought it in.": "它会离开资源库,按导入前的样子放回 {agents}。",
|
||||
@@ -1100,6 +1102,8 @@ magpie.strings({
|
||||
"{agents} reads no project instructions file magpie knows of.": "{agents} 没有 magpie 已知的项目指令文件。",
|
||||
},
|
||||
"zh-TW": {
|
||||
"In {plugin}": "屬於 {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} 放回?",
|
||||
"It leaves the library and goes back to {agents} as it was before you brought it in.": "它會離開資源庫,依匯入前的樣子放回 {agents}。",
|
||||
@@ -2198,6 +2202,8 @@ magpie.strings({
|
||||
"{agents} reads no project instructions file magpie knows of.": "{agents} 沒有 magpie 已知的專案指令檔案。",
|
||||
},
|
||||
ja: {
|
||||
"In {plugin}": "{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} を戻しますか?",
|
||||
"It leaves the library and goes back to {agents} as it was before you brought it in.": "ライブラリから外れ、取り込む前の状態で {agents} に戻ります。",
|
||||
@@ -3296,6 +3302,8 @@ magpie.strings({
|
||||
"{agents} reads no project instructions file magpie knows of.": "{agents} は magpie が把握しているプロジェクトの指示ファイルを読みません。",
|
||||
},
|
||||
de: {
|
||||
"In {plugin}": "Teil von {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.": "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?",
|
||||
"It leaves the library and goes back to {agents} as it was before you brought it in.": "Er verlässt die Bibliothek und kommt so zu {agents} zurück, wie er vor dem Übernehmen war.",
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
// Run with Node's test runner and Playwright on the module path; see README.md.
|
||||
// A part a Claude plugin brought says so on its own row, under Skills, MCP
|
||||
// servers, Hooks and Subagents: "In code-kit", with why its agents follow
|
||||
// the plugin's when those change (library/plugin.go givePlugin). A part of
|
||||
// no plugin has no such tag. Every language, both engines, at 420 and 1100;
|
||||
// nothing wider than the window. No backend: the API is faked.
|
||||
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"] }],
|
||||
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) {
|
||||
return async (route) => {
|
||||
const url = new URL(route.request().url());
|
||||
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"], ["mcp", ".lib-server", "code-kit-docs", "own-server"],
|
||||
["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 part says which plugin it came with", 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 = [];
|
||||
page.on("pageerror", (e) => errors.push(e.message));
|
||||
await page.route("**/*", server(lang));
|
||||
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: name }) }).first();
|
||||
await row(part).waitFor();
|
||||
const badge = row(part).locator(".lib-bundle");
|
||||
assert.equal(await badge.count(), 1, `${part} has no plugin tag`);
|
||||
assert.equal((await badge.textContent()).trim(), tr(lang, "In {plugin}", { plugin: "code-kit" }));
|
||||
assert.equal(await badge.getAttribute("title"), tr(lang, "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: "code-kit" }));
|
||||
assert.equal(await row(own).locator(".lib-bundle").count(), 0, `${own} is tagged as a plugin's`);
|
||||
const over = await page.evaluate(() => {
|
||||
const w = document.documentElement.clientWidth, out = [];
|
||||
for (const e of document.querySelectorAll("#view-library .lib-bundle")) {
|
||||
const r = e.getBoundingClientRect();
|
||||
if (r.right > w + 0.5 || r.left < -0.5) out.push(Math.round(r.left) + "–" + Math.round(r.right));
|
||||
}
|
||||
if (document.documentElement.scrollWidth > w) out.push("page " + document.documentElement.scrollWidth);
|
||||
return out;
|
||||
});
|
||||
assert.deepEqual(over, []);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -226,13 +226,19 @@ func (l *Library) putPlugins(in []*CarriedPlugin, stage string) (fetch []*Carrie
|
||||
gone = append(gone, p.Name)
|
||||
}
|
||||
}
|
||||
// a part's own agents, set on its row, stay: only a change to the
|
||||
// plugin's agents or switch gives every part the plugin's again
|
||||
settle := func(p *Plugin, c *CarriedPlugin) {
|
||||
p.Agents, p.Off = slices.Clone(orNone(c.Agents)), c.Off
|
||||
agents := slices.Clone(orNone(c.Agents))
|
||||
moved := p.Off != c.Off || !slices.Equal(orNone(p.Agents), agents)
|
||||
p.Agents, p.Off = agents, c.Off
|
||||
if c.Description != "" {
|
||||
p.Description = c.Description
|
||||
}
|
||||
takeOut(l, p, c.Taken)
|
||||
l.givePlugin(p)
|
||||
if moved {
|
||||
l.givePlugin(p)
|
||||
}
|
||||
}
|
||||
for _, c := range in {
|
||||
have := l.plugin(c.Name)
|
||||
|
||||
@@ -293,3 +293,36 @@ func TestPluginFromFilesEitherOS(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// A part of a plugin given to fewer agents on its own row keeps that
|
||||
// through a sync that brings the plugin as it was: only a change to the
|
||||
// plugin's agents or its switch gives every part the plugin's again.
|
||||
func TestPluginPartOwnAgentsKeptBySync(t *testing.T) {
|
||||
h := sandbox(t)
|
||||
pluginAgents(t, h)
|
||||
src := filepath.Join(h, "work", "acme")
|
||||
writePlugin(t, src)
|
||||
ok(t)(InstallPlugins(src, nil, []string{"claude", "codex"}))
|
||||
ok(t)(SkillAgents("tdd", []string{"claude"}))
|
||||
b, err := Collect()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
agentsOf := func() string {
|
||||
for _, s := range View0(t).Skills {
|
||||
if s.Name == "tdd" {
|
||||
return strings.Join(s.Agents, ",")
|
||||
}
|
||||
}
|
||||
return "gone"
|
||||
}
|
||||
putJSON(t, mustJSON(t, b))
|
||||
if got := agentsOf(); got != "claude" {
|
||||
t.Errorf("after a sync of the same plugin, tdd's agents: %s, want its own claude", got)
|
||||
}
|
||||
(*b.Plugins)[0].Agents = []string{"codex"}
|
||||
putJSON(t, mustJSON(t, b))
|
||||
if got := agentsOf(); got != "codex" {
|
||||
t.Errorf("after the plugin's agents changed, tdd's agents: %s, want the plugin's codex", got)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user