library: an agent's profiles are one chip on a row, picked in the app menu (Yanzhongixuy on X)
With several Hermes profiles the Library listed each as its own icon on every skill/MCP row (~20 identical glyphs). Profiles of one agent family (hermes#, omp#, claude#, qwenpaw#, WSL variants too) now collapse into one chip with a count; a click opens the app menu (openProtoMenu, multi-tick, live) to pick profiles one by one. All still toggles every profile. Rows only; the By agent view is unchanged. Other multi-profile agents (omp, claude, qwenpaw) had the same problem and go through the same code. Run on mote at the branch head: library-profile-chip.test.cjs (new, 12 cases, chromium + webkit, en/zh/zh-TW/ja/de), red 12 of 12 with profileChip broken by hand; library-*, group-skill-chips, skill-*, mcp-*, i18n-*, hermes-*, omp-*, project-* GUI files: all green except library-loading (Claude plugins tab, already #6204) and one webkit billion-context card case that passed alone (load flake). Not tried: a real Hermes install with 20 profiles, Linux WebKitGTK.
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -284,17 +284,29 @@ magpie.plugin("library", (ctx) => {
|
||||
function agentChips(all, on, onChange, opts = {}) {
|
||||
on ||= [];
|
||||
const box = el("div", "lib-agents");
|
||||
box.style.setProperty("--lib-agent-count", all.length);
|
||||
// a row's profiles of one agent (hermes#coder, omp#work…) are one chip
|
||||
// that opens a menu of them, not one icon each (Yanzhongixuy on X: 20
|
||||
// Hermes glyphs in a row)
|
||||
const fams = onChange.rows ? profileFamilies(all) : new Map();
|
||||
const shown = [], made = new Set();
|
||||
for (const a of all) {
|
||||
const f = familyOf(a.id);
|
||||
if (!fams.has(f)) shown.push({ a });
|
||||
else if (!made.has(f)) { made.add(f); shown.push({ family: f, members: fams.get(f) }); }
|
||||
}
|
||||
box.style.setProperty("--lib-agent-count", shown.length);
|
||||
// the row it is put in says so (.with-agents), for its name's room:
|
||||
// Safari before 15.4 has no :has(). Every caller appends it at once.
|
||||
queueMicrotask(() => box.parentElement?.classList.contains("lib-row") && box.parentElement.classList.add("with-agents"));
|
||||
for (const [i, a] of all.entries()) {
|
||||
for (const [i, g] of shown.entries()) {
|
||||
if (g.family) { box.append(profileChip(g, i, shown.length, all, on, onChange, opts)); continue; }
|
||||
const a = g.a;
|
||||
const always = opts.always?.(a) || "";
|
||||
const has = on.includes(a.id) || !!always;
|
||||
const c = el("button", "lib-ag" + (has ? " on" : "") + (always ? " always" : ""));
|
||||
c.dataset.agent = a.id;
|
||||
// how many chips are to its right, how far it slides into the hand
|
||||
c.style.setProperty("--k", all.length - 1 - i);
|
||||
c.style.setProperty("--k", shown.length - 1 - i);
|
||||
c.append(agentIcon(a.icon));
|
||||
if (opts.names) c.append(el("span", "n", a.name));
|
||||
const problem = !always && opts.problems?.[a.id];
|
||||
@@ -330,10 +342,76 @@ magpie.plugin("library", (ctx) => {
|
||||
};
|
||||
box.append(c);
|
||||
}
|
||||
if (opts.all) allChip(box, all, on, onChange);
|
||||
if (opts.all) allChip(box, all, on, onChange, opts);
|
||||
return box;
|
||||
}
|
||||
|
||||
// The agent a profile belongs to: hermes#coder and hermes are Hermes,
|
||||
// omp#work@wsl:Ubuntu and omp@wsl:Ubuntu are omp in that distro.
|
||||
const familyOf = (id) => id.replace(/#[^@]*/, "");
|
||||
// Three or more of an agent's own and its profiles are one chip; fewer
|
||||
// fit the row as they are.
|
||||
function profileFamilies(all) {
|
||||
const by = new Map();
|
||||
for (const a of all) {
|
||||
const f = familyOf(a.id);
|
||||
if (!by.has(f)) by.set(f, []);
|
||||
by.get(f).push(a);
|
||||
}
|
||||
for (const [f, ms] of [...by]) if (ms.length < 3 || !ms.some((a) => a.id !== f)) by.delete(f);
|
||||
return by;
|
||||
}
|
||||
// The agents a chip stands for: its own, or the profiles of a group.
|
||||
const idsOf = (x) => x.dataset.members ? x.dataset.members.split("\t") : x.dataset.agent ? [x.dataset.agent] : [];
|
||||
const isChip = (x) => !!(x.dataset.agent || x.dataset.members);
|
||||
const memberOn = (x) => x.dataset.members ? (x.dataset.lit ? x.dataset.lit.split("\t") : []) : x.getAttribute("aria-pressed") === "true" ? [x.dataset.agent] : [];
|
||||
// A group's chip: lit when any profile has the item, dashed while only
|
||||
// some do, with how many in the corner.
|
||||
function paintProfiles(c, lit) {
|
||||
const n = lit.length, total = idsOf(c).length - (c.dataset.fixed ? c.dataset.fixed.split("\t").length : 0);
|
||||
c.dataset.lit = lit.join("\t");
|
||||
const has = n > 0 || !!c.dataset.fixed;
|
||||
c.classList.toggle("on", has);
|
||||
c.classList.toggle("some", n > 0 && n < total);
|
||||
c.setAttribute("aria-pressed", has ? "true" : "false");
|
||||
const k = c.querySelector(":scope > .cnt");
|
||||
if (k) k.textContent = n + (c.dataset.fixed ? c.dataset.fixed.split("\t").length : 0) || "";
|
||||
}
|
||||
function profileChip(g, i, count, all, on, onChange, opts) {
|
||||
const ms = g.members, main = ms.find((a) => a.id === g.family) || ms[0];
|
||||
const always = new Map(ms.map((a) => [a.id, opts.always?.(a) || ""]).filter(([, w]) => w));
|
||||
const fixed = ms.filter((a) => always.has(a.id) || a.unseen).map((a) => a.id);
|
||||
const lit = ms.filter((a) => on.includes(a.id) && !fixed.includes(a.id)).map((a) => a.id);
|
||||
const name = main.id === g.family ? main.name : main.name.split(" · ")[0];
|
||||
const c = el("button", "lib-ag profiles");
|
||||
c.dataset.members = ms.map((a) => a.id).join("\t");
|
||||
c.dataset.fixed = fixed.join("\t");
|
||||
c.style.setProperty("--k", count - 1 - i);
|
||||
c.append(agentIcon(main.icon));
|
||||
if (opts.names) c.append(el("span", "n", name));
|
||||
c.append(el("span", "cnt"));
|
||||
paintProfiles(c, lit);
|
||||
const problems = ms.filter((a) => opts.problems?.[a.id]);
|
||||
if (problems.length) c.classList.add("warn");
|
||||
c.setAttribute("aria-haspopup", "menu");
|
||||
c.title = problems.length ? name + ": " + problems.map((a) => a.name + ": " + opts.problems[a.id]).join("\n") : name;
|
||||
c.onclick = (e) => {
|
||||
e.stopPropagation();
|
||||
const me = e.currentTarget;
|
||||
const pick = ms.filter((a) => !fixed.includes(a.id) && !opts.blocked?.(a));
|
||||
const stuck = ms.filter((a) => !fixed.includes(a.id) && opts.blocked?.(a) && memberOn(me).includes(a.id)).map((a) => a.id);
|
||||
const menu = [{ v: "\x00" + g.family, group: pick.map((a) => a.id), name, literalName: true, note: "" },
|
||||
...pick.map((a) => ({ v: a.id, name: a.name, literalName: true, note: "", title: opts.problems?.[a.id] || "" }))];
|
||||
openProtoMenu(me, menu, memberOn(me).filter((id) => !stuck.includes(id)), (next) => {
|
||||
const now = [...stuck, ...next.filter((id) => pick.some((a) => a.id === id))];
|
||||
paintProfiles(me, now);
|
||||
const litAll = litOf(me.parentElement);
|
||||
onChange([...keptOf(me.parentElement, all, on), ...litAll], me);
|
||||
}, name, "", "left", true);
|
||||
};
|
||||
return c;
|
||||
}
|
||||
|
||||
// cannot says a chip's agent can't be given the item, or has it whatever
|
||||
// is ticked: a click says why rather than switching it
|
||||
const cannot = (c) => c.getAttribute("aria-disabled") === "true";
|
||||
@@ -341,13 +419,14 @@ magpie.plugin("library", (ctx) => {
|
||||
// The agents a row's chips have lit by a click: not one lit because it
|
||||
// has the item whatever is ticked.
|
||||
function litOf(box) {
|
||||
return [...box.children].filter((x) => x.dataset.agent && !x.classList.contains("always") && !x.classList.contains("unseen") && x.getAttribute("aria-pressed") === "true").map((x) => x.dataset.agent);
|
||||
return [...box.children].filter((x) => isChip(x) && !x.classList.contains("always") && !x.classList.contains("unseen")).flatMap(memberOn);
|
||||
}
|
||||
// What a click leaves as it was: an agent not shown, one that has the
|
||||
// item whatever is ticked, whose chip can't be clicked, and one in a
|
||||
// stopped distro magpie can't show the ticks of (unseen).
|
||||
function keptOf(box, all, on) {
|
||||
const fixed = [...box.children].filter((x) => x.classList.contains("always") || x.classList.contains("unseen")).map((x) => x.dataset.agent);
|
||||
const fixed = [...box.children].filter((x) => x.classList.contains("always") || x.classList.contains("unseen")).map((x) => x.dataset.agent)
|
||||
.concat([...box.children].flatMap((x) => x.dataset.fixed ? x.dataset.fixed.split("\t") : []));
|
||||
return on.filter((id) => !all.some((x) => x.id === id) || fixed.includes(id));
|
||||
}
|
||||
|
||||
@@ -358,8 +437,8 @@ magpie.plugin("library", (ctx) => {
|
||||
// choose the agents before an item is added (installing skills, adding or
|
||||
// bringing in servers) have it too (#1531): most start with every agent
|
||||
// lit, and one agent alone was a click on each of the others.
|
||||
function allChip(box, all, on, onChange) {
|
||||
const can = [...box.children].filter((c) => !cannot(c) && !c.classList.contains("gone")).map((c) => c.dataset.agent);
|
||||
function allChip(box, all, on, onChange, opts = {}) {
|
||||
const can = [...box.children].filter((c) => !cannot(c) && !c.classList.contains("gone")).flatMap((c) => c.dataset.members ? idsOf(c).filter((id) => !c.dataset.fixed?.split("\t").includes(id) && !opts.blocked?.(all.find((a) => a.id === id))) : [c.dataset.agent]);
|
||||
if (can.length < 2) return;
|
||||
const c = el("button", "lib-ag all", t("All"));
|
||||
c.dataset.all = "1";
|
||||
@@ -378,7 +457,9 @@ magpie.plugin("library", (ctx) => {
|
||||
const c = box.querySelector(":scope > .lib-ag.all");
|
||||
if (!c) return;
|
||||
const can = [...box.children].filter((x) => x.dataset.agent && !cannot(x) && !x.classList.contains("gone"));
|
||||
const n = can.length, full = can.every((x) => x.getAttribute("aria-pressed") === "true");
|
||||
const groups = [...box.children].filter((x) => x.dataset.members);
|
||||
const n = can.length + groups.reduce((k, g) => k + idsOf(g).length - (g.dataset.fixed ? g.dataset.fixed.split("\t").length : 0), 0);
|
||||
const full = can.every((x) => x.getAttribute("aria-pressed") === "true") && groups.every((g) => g.dataset.lit.split("\t").filter(Boolean).length === idsOf(g).length - (g.dataset.fixed ? g.dataset.fixed.split("\t").length : 0));
|
||||
c.classList.toggle("on", full);
|
||||
c.setAttribute("aria-pressed", full ? "true" : "false");
|
||||
c.title = full ? t("Every agent that can take it has it — click to take it from all {n}", { n }) : t("Give it to all {n} agents that can take it", { n });
|
||||
@@ -396,10 +477,14 @@ magpie.plugin("library", (ctx) => {
|
||||
const writing = new Map(); // path + name → { list, name, want, box } while a row's agents are written
|
||||
let refused = 0; // when a row's write last failed, whose error another row's "Written" doesn't cover
|
||||
function chipsChange(path, name, list, rowOf) {
|
||||
return async (next, c) => {
|
||||
const go = async (next, c) => {
|
||||
// All lights or darkens every chip of the row, a chip only itself
|
||||
const every = !!c.dataset.all;
|
||||
for (const x of every ? [...c.parentElement.children].filter((y) => y.dataset.agent && !y.classList.contains("always")) : [c]) {
|
||||
for (const x of every ? [...c.parentElement.children].filter((y) => isChip(y) && !y.classList.contains("always")) : [c]) {
|
||||
if (x.dataset.members) {
|
||||
paintProfiles(x, idsOf(x).filter((id) => next.includes(id) && !x.dataset.fixed?.split("\t").includes(id)));
|
||||
continue;
|
||||
}
|
||||
const on = next.includes(x.dataset.agent);
|
||||
x.classList.toggle("on", on);
|
||||
if (on || x === c) x.classList.remove("via");
|
||||
@@ -437,12 +522,14 @@ magpie.plugin("library", (ctx) => {
|
||||
if (!me.box.isConnected) { if (failed) render(); } // drawn again meanwhile, from the clicks
|
||||
else if (fresh && !morphChips(me.box, fresh)) me.box.replaceWith(fresh);
|
||||
};
|
||||
go.rows = true; // its chips are a row's: an agent's profiles go into one
|
||||
return go;
|
||||
}
|
||||
// What All did, said of the item: on for how many of the agents it went
|
||||
// to, and which of them couldn't be given it, and why.
|
||||
function reportAll(v, me) {
|
||||
const what = ({ servers: "mcp:", hooks: "hook:", env: "env:", subagents: "subagent:" }[me.list] || "skill:") + me.name;
|
||||
const shown = [...me.box.children].filter((x) => x.dataset.agent && !cannot(x)).map((x) => x.dataset.agent);
|
||||
const shown = [...me.box.children].filter((x) => isChip(x) && !cannot(x)).flatMap((x) => idsOf(x).filter((id) => !x.dataset.fixed?.split("\t").includes(id)));
|
||||
const n = shown.filter((id) => me.want.includes(id)).length;
|
||||
const bad = (v.result?.problems || []).filter((p) => p.what === what && shown.includes(p.agent));
|
||||
if (!bad.length) {
|
||||
@@ -486,9 +573,11 @@ magpie.plugin("library", (ctx) => {
|
||||
}
|
||||
function morphChips(box, fresh) {
|
||||
const was = [...box.children], now = [...fresh.children];
|
||||
if (was.length !== now.length || was.some((c, i) => c.dataset.agent !== now[i].dataset.agent)) return false;
|
||||
const key = (c) => c.dataset.agent || c.dataset.members;
|
||||
if (was.length !== now.length || was.some((c, i) => key(c) !== key(now[i]))) return false;
|
||||
was.forEach((c, i) => {
|
||||
const n = now[i];
|
||||
if (n.dataset.members) { c.dataset.lit = n.dataset.lit; c.dataset.fixed = n.dataset.fixed; c.querySelector(":scope > .cnt")?.replaceWith(n.querySelector(":scope > .cnt").cloneNode(true)); }
|
||||
c.className = n.className;
|
||||
c.title = n.title;
|
||||
if (cannot(n)) c.setAttribute("aria-disabled", "true"); else c.removeAttribute("aria-disabled");
|
||||
|
||||
@@ -919,3 +919,8 @@ input.lib-memq:focus, input.lib-memtags:focus, input.lib-memwhy:focus { border-c
|
||||
.lib-acct-act { display: flex; gap: 8px; }
|
||||
@media (hover: hover) and (pointer: fine) { .lib-acct:not(.on):hover { background: var(--hover, var(--accent-soft)); } }
|
||||
@media (prefers-reduced-motion: reduce) { .lib-acct, .lib-acct-dot { transition: none; } }
|
||||
|
||||
/* an agent's profiles as one chip: how many have the item, in the corner */
|
||||
.lib-ag.profiles .cnt { position: absolute; right: -3px; bottom: -3px; min-width: 12px; height: 12px; padding: 0 3px; border-radius: 6px; box-sizing: border-box; background: var(--card); border: 1px solid var(--line); color: var(--fg-2); font-size: 9px; line-height: 10px; text-align: center; font-variant-numeric: tabular-nums; pointer-events: none; }
|
||||
.lib-ag.profiles .cnt:empty { display: none; }
|
||||
.lib-ag.profiles.open { background: var(--pill); }
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
// Run with Node's test runner and Playwright on the module path; see README.md.
|
||||
// An agent's profiles (hermes#coder, hermes#work, ...) are one chip in a
|
||||
// row, not an icon each (Yanzhongixuy on X: twenty Hermes glyphs in every
|
||||
// skill row). The chip opens an app menu of the profiles, ticked as the row
|
||||
// has them, and a tick writes the whole list. Agents with fewer than three
|
||||
// entries keep their own chips. English, Chinese, Traditional Chinese,
|
||||
// Japanese and German; 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 assets = path.resolve(__dirname, "../assets");
|
||||
const HOME = "/Users/me";
|
||||
const agent = (id, name, icon) => ({ id, name, icon, skills: `${HOME}/.${id}/skills`, mcp: `${HOME}/.${id}/mcp.json` });
|
||||
const AGENTS = [agent("claude", "Claude Code", "claudecode-color"), agent("hermes", "Hermes Agent", "hermes"),
|
||||
...["coder", "work", "play", "ops", "docs"].map((n) => agent("hermes#" + n, "Hermes · " + n, "hermes")),
|
||||
agent("omp", "omp", "omp"), agent("omp#a", "omp · a", "omp")];
|
||||
const ALL = AGENTS.map((a) => a.id);
|
||||
|
||||
const sent = [];
|
||||
function server(lang, lib) {
|
||||
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/providers") return json({ providers: [], presets: [], excluded: [], gateway: { running: true, window: true }, plugins: [] });
|
||||
if (url.pathname === "/api/groups") return json({ groups: [], pools: [] });
|
||||
if (url.pathname === "/api/usage/quotas") return json([]);
|
||||
if (url.pathname === "/api/library/servers/agents") { sent.push(route.request().postDataJSON()); lib.servers[0].agents = route.request().postDataJSON().agents; return json(lib); }
|
||||
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 lib = () => ({
|
||||
dir: `${HOME}/.magpie/library`, backups: `${HOME}/.magpie/backups`, home: HOME,
|
||||
agents: structuredClone(AGENTS),
|
||||
instructions: { agents: [], sets: [] }, foundServers: [], projects: [], foundSkills: [], problems: [], skills: [],
|
||||
servers: [{ name: "context7", transport: "stdio", command: "npx", args: ["-y", "@upstash/context7-mcp"], agents: ["claude", "hermes", "hermes#work"] }],
|
||||
});
|
||||
|
||||
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
||||
test(engine + ": an agent's profiles are one chip with a menu", async (t) => {
|
||||
assert(["chromium", "webkit"].includes(engine), "BROWSER must be chromium or webkit");
|
||||
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"]) {
|
||||
await t.test(lang, async () => {
|
||||
sent.length = 0;
|
||||
const ctx = await browser.newContext({ viewport: { width: 1000, height: 700 } });
|
||||
await ctx.addInitScript(() => { try { localStorage.setItem("magpie.libTab", "mcp"); } catch {} });
|
||||
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, lib()));
|
||||
try {
|
||||
await page.goto("http://magpie.test/");
|
||||
await page.locator('button[data-view="library"]').click();
|
||||
const strip = page.locator("#view-library .lib-row > .lib-agents").first();
|
||||
await strip.locator(".lib-ag.profiles").waitFor();
|
||||
// claude, one Hermes chip, omp and omp#a as they were: 4 chips (+ All)
|
||||
assert.equal(await strip.locator(".lib-ag[data-agent]").count(), 3);
|
||||
assert.equal(await strip.locator(".lib-ag.profiles").count(), 1);
|
||||
assert.equal(await strip.locator('.lib-ag[data-agent^="hermes"]').count(), 0);
|
||||
const chip = strip.locator(".lib-ag.profiles");
|
||||
assert.equal(await chip.locator(".cnt").textContent(), "2");
|
||||
assert(await chip.evaluate((c) => c.classList.contains("on") && c.classList.contains("some")));
|
||||
await chip.click();
|
||||
const menu = page.locator(".proto-menu");
|
||||
await menu.waitFor();
|
||||
// the heading ticks all; then each of the six
|
||||
assert.equal(await menu.locator(".pm-item").count(), 7);
|
||||
assert.equal(await menu.locator('.pm-item.on').count(), 2);
|
||||
await menu.locator(".pm-item", { hasText: "coder" }).click();
|
||||
await page.waitForFunction(() => document.querySelector(".lib-ag.profiles .cnt")?.textContent === "3");
|
||||
await page.waitForFunction(() => true);
|
||||
await page.waitForTimeout(100);
|
||||
assert.deepEqual([...sent.at(-1).agents].sort(), ["claude", "hermes", "hermes#coder", "hermes#work"].sort());
|
||||
// the heading takes them all
|
||||
await menu.locator(".pm-group").click();
|
||||
await page.waitForFunction(() => document.querySelector(".lib-ag.profiles .cnt")?.textContent === "6");
|
||||
await page.waitForTimeout(100);
|
||||
assert.deepEqual([...sent.at(-1).agents].sort(), ["claude", "hermes", "hermes#coder", "hermes#docs", "hermes#ops", "hermes#play", "hermes#work"].sort());
|
||||
assert(!(await chip.evaluate((c) => c.classList.contains("some"))));
|
||||
assert.deepEqual(errors, []);
|
||||
} finally {
|
||||
await ctx.close();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user