library: one agent's skills or MCP servers are turned on or off at once, and a hidden agent's taken out of it (#475: turning Copilot CLI's 32 skills off was a chip on every row, and once it was hidden on the Agents page it had no chips at all, so what it had been given stayed with no way to take it out) — By agent, beside "In the library" on the Skills and MCP tabs, opens a sheet of the agents that take them, each with how many it has, a Turn all on and a Turn all off; each writes that one agent, every other keeping what it has, and reports what couldn't be written as a row's chips do. An agent hidden on the Agents page is listed while it has any, tagged Hidden and given nothing new; its instructions row is shown while it reads the shared instructions, so it can be switched off. Skills use the existing skills/agents-all; servers get servers/agents-all (EveryServerAgents), which turns on only the servers the agent can reach (no SSE for Codex, no remote one for Claude Desktop). TestEveryServerAgents and by-agent.test.cjs (Chromium, WebKit; en, zh) fail without the change. go vet, go build -tags nogui (darwin, GOOS=linux), GOOS=windows go build, go test -tags nogui ./... pass; every-skill, library-all, library-items, library-toggle-status, remove-all-skills, click-scroll, old-webkit pass.

This commit is contained in:
yetone
2026-10-02 06:33:40 +08:00
parent fe86fb3a4d
commit e3bf9d05d4
8 changed files with 394 additions and 3 deletions
+22
View File
@@ -1998,6 +1998,28 @@ const I18N = {
"Every skill is taken out of {agents}. They stay in the library, to turn on again.": "每个技能都会从 {agents} 中移除。它们仍留在资源库中,随时可以重新启用。",
"{n} skills are on for all {m} agents": "已为全部 {m} 个 Agent 启用 {n} 个技能",
"{n} skills are off for all {m} agents": "已从全部 {m} 个 Agent 中关闭 {n} 个技能",
// one agent's skills or servers on or off at once (#475)
"By agent": "按 Agent",
"Turn every skill on or off for one agent": "为单个 Agent 启用或关闭全部技能",
"Turn every server on or off for one agent": "为单个 Agent 启用或关闭全部服务器",
"Skills by agent": "按 Agent 管理技能",
"MCP servers by agent": "按 Agent 管理 MCP 服务器",
"Every skill on or off for one agent; the others keep theirs. Turned off, they stay in the library.": "为单个 Agent 启用或关闭全部技能,其他 Agent 不受影响。关闭的技能仍留在资源库中。",
"Every server on or off for one agent; the others keep theirs. Turned off, they stay in the library.": "为单个 Agent 启用或关闭全部服务器,其他 Agent 不受影响。关闭的服务器仍留在资源库中。",
"Hidden on the Agents page: it isn't given anything new, and what it has can be taken out here": "已在 Agents 页隐藏:不会再给它新的条目,已有的可以在这里移除",
"Hidden on the Agents page: switch it off here to take the shared instructions out of its file": "已在 Agents 页隐藏:在这里关闭即可从它的文件中移除共享指令",
"{n} of {m} skills": "{n} / {m} 个技能",
"{n} of {m} servers": "{n} / {m} 个服务器",
"Give {agent} every skill": "为 {agent} 启用每个技能",
"Give {agent} every server it can reach": "为 {agent} 启用它能连接的每个服务器",
"Take every skill from {agent}": "从 {agent} 中关闭每个技能",
"Take every server from {agent}": "从 {agent} 中关闭每个服务器",
"{n} skills are on for {agent}": "已为 {agent} 启用 {n} 个技能",
"Every skill is off for {agent}": "已从 {agent} 中关闭全部技能",
"1 skill is on for {agent}": "已为 {agent} 启用 1 个技能",
"1 server is on for {agent}": "已为 {agent} 启用 1 个服务器",
"{n} servers are on for {agent}": "已为 {agent} 启用 {n} 个服务器",
"Every server is off for {agent}": "已从 {agent} 中关闭全部服务器",
// every skill out of the library at once (#449)
"Remove all": "全部删除",
"Take all {n} skills out of the library": "从资源库中删除全部 {n} 个技能",
+8
View File
@@ -270,6 +270,14 @@ input.lib-setname:focus { border-color: var(--accent); box-shadow: 0 0 0 3px col
.lib-editor .lib-picks { grid-column: 1 / -1; max-height: 320px; }
.lib-confirm { grid-column: 1 / -1; margin: 0; font-size: 12.5px; line-height: 1.55; color: var(--fg-2); }
.text.danger-fill { background: var(--red); color: #fff; }
/* one agent's skills or servers on or off at once (#475) */
.lib-byagent-sheet .lib-byagent-list { grid-column: 1 / -1; max-height: min(52vh, 420px); overflow: auto; }
.lib-byagent-row { gap: 10px; }
.lib-byagent-row > .ic { width: 20px; height: 20px; flex: none; }
.lib-byagent-row .who { flex: 1; min-width: 0; }
.lib-byagent-row .name { display: flex; align-items: center; gap: 6px; }
.lib-byagent-row .lib-updall { height: 24px; padding: 0 9px; font-size: 12px; flex: none; }
.lib-byagent-row .lib-updall:disabled { color: var(--faint); cursor: default; }
.lib-reader { grid-template-columns: minmax(0, 1fr); }
.lib-md { margin: 0; max-height: min(60vh, 520px); overflow: auto; font: 12px/1.6 var(--code); color: var(--fg-2); white-space: pre-wrap; overflow-wrap: anywhere; background: var(--card-2); border-radius: 8px; padding: 12px 14px; user-select: text; -webkit-user-select: text; }
.lib-reader .bar .lib-path { max-width: 70%; }
+92 -1
View File
@@ -912,7 +912,8 @@
rh.append(el("span", "label", t("Agents")), el("span", "grow"), el("span", "note", t("magpie writes its part between two marker lines — the rest of each file stays yours")));
body.append(rh);
const list = el("div", "list lib-list");
const rows = iv.agents.filter((a) => !isHidden({ id: a.agent }));
// a hidden agent still reading them is listed, to switch it off (#475)
const rows = iv.agents.filter((a) => !isHidden({ id: a.agent }) || a.on);
for (const a of rows) list.append(...instructionsRow(a));
if (!rows.length) list.append(el("div", "lib-none", t("None of your agents reads a user-wide instructions file magpie knows.")));
body.append(list);
@@ -1023,6 +1024,7 @@
who.append(sub);
const tags = el("div", "lib-tags");
const extra = extras[a.agent] ?? a.extra;
if (isHidden({ id: a.agent })) tags.append(tag(t("Hidden"), "", t("Hidden on the Agents page: switch it off here to take the shared instructions out of its file")));
if (a.on && extra) tags.append(tag(t("+ its own"), "", t("{agent} gets something of its own after the shared text", { agent: a.name })));
if (a.edited) tags.append(tag(t("edited in the file"), "warn", t("magpie's part of this file was changed there; magpie leaves it until the library's text changes")));
if (a.own) tags.append(tag(a.own === 1 ? t("1 line of its own") : t("{n} lines of its own", { n: a.own }), "", t("The file has instructions besides magpie's part — they stay, and the agent reads both")));
@@ -1110,6 +1112,12 @@
const add = button(t("+ Add a server"), "action", () => editServer(null));
body.append(empty(t("No servers in the library yet"), lib.foundServers.length ? t("Add one, or bring in those your agents already have, below.") : t("Paste a server's JSON from its README, or fill it in."), add));
} else {
// one agent's servers on or off at once (#475), or out of a hidden one
if (byAgentRows("servers").length) {
const rh = el("div", "row-head");
rh.append(el("span", "label", t("In the library")), el("span", "grow"), byAgentButton("servers"));
body.append(rh);
}
const list = el("div", "list lib-list");
for (const s of lib.servers) list.append(serverRow(s, all));
body.append(list);
@@ -1411,6 +1419,7 @@
const fresh = lib.skills.filter((s) => s.kind === "github" || s.origin);
rh.append(el("span", "grow"));
if (lib.skills.length > 1 && all.length) rh.append(...everySkillButtons(all));
if (byAgentRows("skills").length) rh.append(byAgentButton("skills"));
if (lib.skills.length > 1) rh.append(removeEverySkillButton());
if (lib.skills.some((s) => s.kind === "github")) {
const c = button(checking ? t("Checking…") : t("Check for updates"), "lib-updall", () => checkSkills());
@@ -2101,6 +2110,88 @@
}
}
// One agent's skills, or servers, on or off at once (#475), rather than a
// chip on every row: the agents that can take them, each with how many it
// has, a button that gives it every one it can take and one that takes
// every one from it. Every other agent keeps what it has. An agent hidden
// on the Agents page (#71) has no chips, so it's listed here while it has
// any, to take them out of it; it isn't given more.
function byAgentButton(kind) {
const b = button(t("By agent"), "action lib-updall lib-byagent", () => openByAgent(kind));
b.title = kind === "skills" ? t("Turn every skill on or off for one agent") : t("Turn every server on or off for one agent");
return b;
}
// kept: agents listed when the sheet opened, which stay listed in it once
// a hidden one has nothing left
function byAgentRows(kind, kept) {
const items = kind === "skills" ? lib.skills : lib.servers;
const can = kind === "skills" ? () => true : (s, a) => reaches(s)(a);
return lib.agents.filter((a) => kind === "skills" ? a.skills : a.mcp).map((a) => {
const has = items.filter((x) => x.agents?.includes(a.id)).length;
const missing = items.filter((x) => can(x, a) && !x.agents?.includes(a.id)).length;
return { a, has, missing, hidden: isHidden(a) };
}).filter((r) => !r.hidden || r.has || kept?.has(r.a.id));
}
function openByAgent(kind) {
const skills = kind === "skills", items = () => skills ? lib.skills : lib.servers;
const ed = el("div", "editor lib-editor lib-byagent-sheet");
const head = el("div", "ehead");
head.append(glyph(skills ? GLYPH.skill : GLYPH.cmd), el("b", "", skills ? t("Skills by agent") : t("MCP servers by agent")));
ed.append(head);
ed.append(el("p", "lib-confirm", skills
? t("Every skill on or off for one agent; the others keep theirs. Turned off, they stay in the library.")
: t("Every server on or off for one agent; the others keep theirs. Turned off, they stay in the library.")));
const list = el("div", "list lib-list lib-byagent-list");
let busy = false;
const listed = new Set(byAgentRows(kind).map((r) => r.a.id));
const draw = () => list.replaceChildren(...byAgentRows(kind, listed).map(({ a, has, missing, hidden }) => {
const row = el("div", "row lib-row lib-byagent-row");
row.dataset.agent = a.id;
const who = el("div", "who");
const name = el("div", "name", a.name);
if (hidden) name.append(tag(t("Hidden"), "", t("Hidden on the Agents page: it isn't given anything new, and what it has can be taken out here")));
who.append(name, el("div", "sub", skills ? t("{n} of {m} skills", { n: has, m: items().length }) : t("{n} of {m} servers", { n: has, m: items().length })));
const on = button(t("Turn all on"), "action lib-updall lib-agenton", (e, b) => everyFor(a, true, b));
on.disabled = busy || hidden || !missing;
const off = button(t("Turn all off"), "action lib-updall lib-agentoff", (e, b) => everyFor(a, false, b));
off.disabled = busy || !has;
on.title = skills ? t("Give {agent} every skill", { agent: a.name }) : t("Give {agent} every server it can reach", { agent: a.name });
off.title = skills ? t("Take every skill from {agent}", { agent: a.name }) : t("Take every server from {agent}", { agent: a.name });
row.append(agentIcon(a.icon), who, on, off);
return row;
}));
// what each button wrote is what the list then shows; the page under
// it is drawn again too, its chips with it
async function everyFor(a, on, b) {
busy = true;
for (const x of list.querySelectorAll("button")) x.disabled = true;
b.classList.add("busy");
try {
const v = await api("library/" + (skills ? "skills" : "servers") + "/agents-all", { agents: [a.id], on });
take(v);
const n = items().filter((x) => x.agents?.includes(a.id)).length;
report(v.result, skills
? (on ? t(n === 1 ? "1 skill is on for {agent}" : "{n} skills are on for {agent}", { n, agent: a.name }) : t("Every skill is off for {agent}", { agent: a.name }))
: (on ? t(n === 1 ? "1 server is on for {agent}" : "{n} servers are on for {agent}", { n, agent: a.name }) : t("Every server is off for {agent}", { agent: a.name })));
render();
} catch (e) {
status(e.message, "err", 6000);
}
busy = false;
if (list.isConnected) draw();
}
draw();
ed.append(list);
const bar = el("div", "bar");
const done = button(t("Done"), "primary", closeLibModal);
bar.append(el("span", "grow"), done);
ed.append(bar);
modal = { save: () => done.click() };
openLib(ed);
}
// Every skill out of the library at once (#449), each as a row's Remove
// takes it: out of every agent and project, its folder moved to magpie's
// backups, or for one linked from a folder of the user's only the link
+3 -1
View File
@@ -263,7 +263,7 @@ func libraryRoutes(mux *http.ServeMux, w Windows) {
Values map[string]string // what a market server needs
Dir string // a project's folder
Copy bool // a project gets copies, not links
On bool // every skill given to the agents, or taken from them
On bool // every skill or server given to the agents, or taken from them
library.InstructionsChange
}
if err := json.NewDecoder(r.Body).Decode(&in); err != nil {
@@ -283,6 +283,8 @@ func libraryRoutes(mux *http.ServeMux, w Windows) {
res, err = library.SaveServer(in.Old, in.Server)
case "servers/agents":
res, err = library.ServerAgents(in.Name, in.Agents)
case "servers/agents-all":
res, err = library.EveryServerAgents(in.Agents, in.On)
case "servers/remove":
res, err = library.RemoveServer(in.Name)
case "servers/import":
File diff suppressed because one or more lines are too long
+187
View File
@@ -0,0 +1,187 @@
// Run with Node's test runner and Playwright on the module path; see README.md.
// #475: one agent's skills, or MCP servers, were a chip on every row to turn
// off, and an agent hidden on the Agents page had no chips at all, so what it
// was given couldn't be taken out of it. "By agent", beside "In the library",
// opens a sheet listing each agent with how many it has, a "Turn all on" and
// a "Turn all off": each posts that one agent to …/agents-all, and the
// page's chips follow. A hidden agent is listed while it has any (tagged
// Hidden, with no Turn all on), and stays listed once emptied; turning a
// server on is offered only for the ones the agent can reach (no SSE for
// Codex). The clicks scroll nothing; in English and Chinese. No backend: the
// API is faked here.
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 assets = path.resolve(__dirname, "../assets");
const HOME = "/Users/emo";
const agent = (id, name, more = {}) => ({ id, name, icon: "", skills: `${HOME}/.${id}/skills`, mcp: `${HOME}/.${id}/mcp.json`, ...more });
const sk = (name, agents) => ({ name, description: name, kind: "folder", agents });
const sv = (name, transport, agents) => ({ name, transport, command: transport === "stdio" ? name : "", url: transport === "stdio" ? "" : "http://localhost:9/" + name, agents });
const lib = (skills, servers) => ({
dir: `${HOME}/.magpie/library`, backups: `${HOME}/.magpie/backups`, home: HOME,
agents: [agent("claude", "Claude Code"), agent("codex", "Codex", { noSSE: true }), agent("copilot", "Copilot CLI"), agent("goose", "Goose", { skills: "" })],
instructions: { agents: [] }, servers, skills, foundServers: [], projects: [], foundSkills: [],
});
function server(lang, posts) {
let skills = [sk("grill-me", ["claude", "copilot"]), sk("tdd", ["copilot"]), sk("pdf", ["codex"])];
let servers = [sv("fs", "stdio", ["claude", "copilot"]), sv("web", "sse", ["claude"])];
const can = (s, a) => !(s.transport === "sse" && a === "codex");
return async (route) => {
const req = route.request(), url = new URL(req.url());
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 route.fulfill({ json: { agents: [], profiles: [], settings: { lang, theme: "light", agentsHidden: ["copilot"] } } });
if (url.pathname === "/api/library") return route.fulfill({ json: lib(skills, servers) });
const every = url.pathname.match(/^\/api\/library\/(skills|servers)\/agents-all$/);
if (every) {
const { agents, on } = req.postDataJSON();
posts.push({ what: every[1], agents, on });
const put = (x) => ({ ...x, agents: on ? [...new Set([...x.agents, ...agents.filter((a) => every[1] === "skills" || can(x, a))])].sort() : x.agents.filter((a) => !agents.includes(a)) });
if (every[1] === "skills") skills = skills.map(put);
else servers = servers.map(put);
return route.fulfill({ json: { ...lib(skills, servers), result: { changed: agents } } });
}
if (url.pathname === "/api/plugins") return route.fulfill({ json: { plugins: [] } });
if (url.pathname === "/api/usage/quotas") return route.fulfill({ json: [] });
if (url.pathname === "/api/groups") return route.fulfill({ json: { groups: [] } });
if (url.pathname === "/api/providers") return route.fulfill({ json: { providers: [], gateway: { running: true } } });
if (url.pathname.startsWith("/api/")) return route.fulfill({ json: {} });
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)];
await route.fulfill({ body: await fs.readFile(file), contentType });
};
}
const scrolled = (page) => page.evaluate(() => [window.scrollX, window.scrollY, ...[...document.querySelectorAll("*")].filter((e) => e.scrollTop || e.scrollLeft).map((e) => `${e.className}:${e.scrollTop},${e.scrollLeft}`)].join(" "));
// a click where the button is, as the reader's: Playwright's own click first
// scrolls the button into view
const press = async (page, loc) => {
const b = await loc.boundingBox();
await page.mouse.click(b.x + b.width / 2, b.y + b.height / 2);
};
// the sheet grows out of the button that opened it: a click at a button's
// place lands once it has
const settled = (page) => page.waitForFunction(() => !document.querySelector("#modal").getAnimations({ subtree: true }).length);
const lit = (page, id) => page.locator(`#view-library .lib-ag.on[data-agent="${id}"]`).count();
const words = {
en: {
by: "By agent", skillsHead: "Skills by agent", serversHead: "MCP servers by agent", hidden: "Hidden", done: "Done",
copilot: "2 of 3 skills", copilotNone: "0 of 3 skills", codex: "1 of 3 skills", codexAll: "3 of 3 skills",
offCopilot: "Every skill is off for Copilot CLI", onCodex: "3 skills are on for Codex",
srvCodex: "0 of 2 servers", srvOnCodex: "1 server is on for Codex", srvOffCopilot: "Every server is off for Copilot CLI",
},
zh: {
by: "按 Agent", skillsHead: "按 Agent 管理技能", serversHead: "按 Agent 管理 MCP 服务器", hidden: "已隐藏", done: "完成",
copilot: "2 / 3 个技能", copilotNone: "0 / 3 个技能", codex: "1 / 3 个技能", codexAll: "3 / 3 个技能",
offCopilot: "已从 Copilot CLI 中关闭全部技能", onCodex: "已为 Codex 启用 3 个技能",
srvCodex: "0 / 2 个服务器", srvOnCodex: "已为 Codex 启用 1 个服务器", srvOffCopilot: "已从 Copilot CLI 中关闭全部服务器",
},
};
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
test(engine + ": one agent's library entries on or off at once, a hidden one's too", async (t) => {
assert(["chromium", "webkit"].includes(engine), "BROWSER must be chromium or webkit");
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
const errors = [];
t.after(async () => {
if (errors.length) console.log(errors);
await browser.close();
});
const open = async (lang, posts, tab) => {
const ctx = await browser.newContext({ viewport: { width: 860, height: 700 } });
await ctx.addInitScript((tab) => { try { localStorage.setItem("magpie.libTab", tab); } catch {} }, tab);
const page = await ctx.newPage();
page.setDefaultTimeout(5000);
page.on("pageerror", (e) => errors.push(e.message));
page.on("dialog", (d) => { errors.push("a browser dialog: " + d.message()); d.dismiss(); });
await page.route("**/*", server(lang, posts));
await page.goto("http://magpie.test/");
await page.locator('button[data-view="library"]').click();
await page.locator("#view-library .lib-row").first().waitFor();
return page;
};
const row = (sheet, id) => sheet.locator(`.lib-byagent-row[data-agent="${id}"]`);
for (const lang of ["en", "zh"]) {
await t.test(lang + ": skills", async () => {
const w = words[lang], posts = [];
const page = await open(lang, posts, "skills");
const by = page.locator("#view-library .row-head button.lib-byagent");
assert.equal((await by.textContent()).trim(), w.by);
assert.equal(await lit(page, "copilot"), 0, "the hidden agent has no chips");
const before = await scrolled(page);
await press(page, by);
const sheet = page.locator("#modal .lib-byagent-sheet");
await sheet.waitFor();
await settled(page);
assert.equal((await sheet.locator(".ehead b").textContent()).trim(), w.skillsHead);
assert.deepEqual(await sheet.locator(".lib-byagent-row").evaluateAll((rs) => rs.map((r) => r.dataset.agent)), ["claude", "codex", "copilot"], "goose takes no skills");
const cp = row(sheet, "copilot");
assert.equal((await cp.locator(".lib-tag").textContent()).trim(), w.hidden);
assert.equal((await cp.locator(".sub").textContent()).trim(), w.copilot);
assert.equal(await cp.locator("button.lib-agenton").isDisabled(), true, "a hidden agent isn't given more");
await press(page, cp.locator("button.lib-agentoff"));
await page.waitForFunction(() => document.querySelector('#modal .lib-byagent-row[data-agent="copilot"] .sub')?.textContent.match(/^0/));
assert.deepEqual(posts, [{ what: "skills", agents: ["copilot"], on: false }]);
assert.equal((await page.locator("#status").textContent()).trim(), w.offCopilot);
assert.equal((await cp.locator(".sub").textContent()).trim(), w.copilotNone, "emptied, it stays listed");
assert.equal(await cp.locator("button.lib-agentoff").isDisabled(), true);
const cx = row(sheet, "codex");
assert.equal((await cx.locator(".sub").textContent()).trim(), w.codex);
await press(page, cx.locator("button.lib-agenton"));
await page.waitForFunction(() => document.querySelector('#modal .lib-byagent-row[data-agent="codex"] .sub')?.textContent.match(/^3/));
assert.deepEqual(posts[1], { what: "skills", agents: ["codex"], on: true });
assert.equal((await page.locator("#status").textContent()).trim(), w.onCodex);
assert.equal(await cx.locator("button.lib-agenton").isDisabled(), true, "nothing left to turn on");
assert.equal(await lit(page, "codex"), 3, "every row's Codex chip is lit");
assert.equal(await lit(page, "claude"), 1, "Claude Code keeps what it had");
await sheet.locator(".bar button", { hasText: w.done }).click();
await sheet.waitFor({ state: "detached" });
assert.equal(posts.length, 2);
assert.equal(await scrolled(page), before, "the clicks scroll nothing");
});
await t.test(lang + ": servers", async () => {
const w = words[lang], posts = [];
const page = await open(lang, posts, "mcp");
const by = page.locator("#view-library .row-head button.lib-byagent");
const before = await scrolled(page);
await press(page, by);
const sheet = page.locator("#modal .lib-byagent-sheet");
await sheet.waitFor();
await settled(page);
assert.equal((await sheet.locator(".ehead b").textContent()).trim(), w.serversHead);
assert.deepEqual(await sheet.locator(".lib-byagent-row").evaluateAll((rs) => rs.map((r) => r.dataset.agent)), ["claude", "codex", "copilot", "goose"]);
const cx = row(sheet, "codex");
assert.equal((await cx.locator(".sub").textContent()).trim(), w.srvCodex);
await press(page, cx.locator("button.lib-agenton"));
await page.waitForFunction(() => document.querySelector('#modal .lib-byagent-row[data-agent="codex"] .sub')?.textContent.match(/^1/));
assert.deepEqual(posts, [{ what: "servers", agents: ["codex"], on: true }]);
assert.equal((await page.locator("#status").textContent()).trim(), w.srvOnCodex);
assert.equal(await cx.locator("button.lib-agenton").isDisabled(), true, "the SSE one it can't reach isn't offered");
await press(page, row(sheet, "copilot").locator("button.lib-agentoff"));
await page.waitForFunction(() => document.querySelector('#modal .lib-byagent-row[data-agent="copilot"] .sub')?.textContent.match(/^0/));
assert.deepEqual(posts[1], { what: "servers", agents: ["copilot"], on: false });
assert.equal((await page.locator("#status").textContent()).trim(), w.srvOffCopilot);
assert.equal(await lit(page, "claude"), 2, "Claude Code keeps both");
await page.keyboard.press("Escape");
await sheet.waitFor({ state: "detached" });
assert.equal(await scrolled(page), before, "the clicks scroll nothing");
});
}
assert.deepEqual(errors, []);
});
}
+36
View File
@@ -1081,3 +1081,39 @@ func TestEverySkillAgents(t *testing.T) {
t.Error("no agents named was taken")
}
}
// Every server on for one agent at once, and off again; the others keep
// theirs, and an agent isn't given a server it can't reach (#475).
func TestEveryServerAgents(t *testing.T) {
h := sandbox(t)
ok(t)(SaveServer("", Server{Name: "fs", Transport: "stdio", Command: "fs", Agents: []string{"claude"}}))
ok(t)(SaveServer("", Server{Name: "web", Transport: "sse", URL: "http://localhost:9/sse", Agents: []string{"claude"}}))
ok(t)(EveryServerAgents([]string{"codex"}, true))
agents := func() map[string][]string {
v, _ := Read(nil)
m := map[string][]string{}
for _, s := range v.Servers {
m[s.Name] = s.Agents
}
return m
}
if m := agents(); !slices.Equal(m["fs"], []string{"claude", "codex"}) || !slices.Equal(m["web"], []string{"claude"}) {
t.Errorf("on for codex: %v", m)
}
if c := read(t, filepath.Join(h, ".codex/config.toml")); !strings.Contains(c, "[mcp_servers.fs]") || strings.Contains(c, "web") {
t.Errorf("codex's config:\n%s", c)
}
ok(t)(EveryServerAgents([]string{"claude"}, false))
if m := agents(); !slices.Equal(m["fs"], []string{"codex"}) || len(m["web"]) != 0 {
t.Errorf("off for claude: %v", m)
}
if c := read(t, filepath.Join(h, ".claude.json")); strings.Contains(c, `"fs"`) || strings.Contains(c, `"web"`) {
t.Errorf("claude still has them:\n%s", c)
}
if !strings.Contains(read(t, filepath.Join(h, ".codex/config.toml")), "[mcp_servers.fs]") {
t.Error("codex, not named, lost fs")
}
if _, err := EveryServerAgents(nil, false); err == nil {
t.Error("no agents named was taken")
}
}
+34
View File
@@ -315,6 +315,40 @@ func ServerAgents(name string, agents []string) (*Result, error) {
})
}
// EveryServerAgents gives every server in the library to the agents named,
// or takes every one from them, in one write rather than one for each
// server (#475). An agent not named keeps what it has, as with a server's
// All chip; on gives an agent only the servers it can reach (no SSE for
// Codex, no remote one for Claude Desktop), as its chips can't be lit for
// the others.
func EveryServerAgents(agents []string, on bool) (*Result, error) {
if len(agents) == 0 {
return nil, fmt.Errorf("no agents to give the servers to")
}
return change(func(l *Library) error {
mcp := map[string]*mcpFile{}
if on {
for _, t := range Targets() {
if t.MCP != nil {
mcp[t.Agent.ID] = t.MCP
}
}
}
for _, s := range l.MCP {
kept := slices.DeleteFunc(slices.Clone(s.Agents), func(a string) bool { return slices.Contains(agents, a) })
for _, a := range agents {
if on && mcp[a] != nil && mcp[a].supports(s) == nil {
kept = append(kept, a)
} else if on && slices.Contains(s.Agents, a) {
kept = append(kept, a) // one it has already stays, whatever it says of it
}
}
s.Agents = slices.Sorted(slices.Values(kept))
}
return nil
})
}
// RemoveServer takes a server out of the library and out of every agent
// magpie gave it to.
func RemoveServer(name string) (*Result, error) {