library: a project's Skills menu groups the skills by source, a heading ticks the whole group (Elorynth on X)

The project card's Skills menu listed every library skill flat. It now
lists them as the Library does (skillGroups(true): by repository or the
user's own group, this computer's last, whatever sort the list has), with
a heading over each group. Pressing a heading ticks all of the group's
skills, or unticks them when all are in; it is half-ticked while some are.
A typed filter keeps a group's heading over the skills it finds, and
matches a skill by its group's name. One group only stays the flat list.
openProtoMenu takes a `group` option (the values it ticks) for this.
Paid for in app.js by five comments cut, no budget raise.

Run on the Windows box (mote's Chromium launch hung, SSH refused at
times): project-skills-groups.test.cjs, new, in chromium and webkit,
en/zh/zh-TW/ja/de at 400px wide: red on the old code (6 of 6), green
after. With project-*, i18n-*, menu-*, proto-menu-overflow and
skill-group* GUI files in both engines: all green except
menu-input-scroll and menu-scroll (14 chromium, 13 webkit), which are
red the same at origin/main aa2ea5c90 on the Windows box (commented on
#3402). TestCoreScriptBudget ok at the rebased head.
Not tried: the full suite, the real Linux app (WebKitGTK). Part 2 of the
report (instruction presets bundled into a toolkit) is not built: a
project has no instructions of its own yet.
This commit is contained in:
yetone
2026-11-11 13:31:23 +08:00
parent aa2ea5c906
commit 61a04f42a2
5 changed files with 168 additions and 40 deletions
File diff suppressed because one or more lines are too long
+4
View File
@@ -3179,6 +3179,10 @@ body.window .ag-sk-icon { width: 22px; height: 22px; border-radius: 6px; }
/* a menu of actions, where nothing is or can be ticked, keeps no room for
a tick: its items line up with its heading */
.proto-menu.pm-bare .pm-tick { display: none; }
/* a group's heading in a menu of many: it ticks all of its items */
.proto-menu .pm-group { margin-top: 3px; }
.proto-menu .pm-group .pm-name { font-size: 11px; font-weight: 600; color: var(--muted); }
.proto-menu .pm-group.mixed .pm-tick::before { content: ""; width: 8px; height: 1.5px; border-radius: 1px; background: currentColor; }
.proto-menu .pm-words { display: grid; gap: 1px; min-width: 0; }
.proto-menu .pm-name { font-size: 12.5px; font-weight: 500; line-height: 16px; }
.proto-menu .pm-note { font-size: 11px; color: var(--muted); line-height: 15px; }
+26 -30
View File
@@ -4236,12 +4236,8 @@ async function load(again) {
// the panel's allowances asked beside the state, not after it (#3134)
const early = mode === "panel" && !load.done;
if (early) panelQuotasNow(again);
// the first load draws the state magpie kept from its last read while
// the fresh one is read (#1519, fatkun): reading every agent's config,
// and a WSL distro's through \\wsl.localhost, took seconds after a
// start or after light mode let the window go. The fresh state
// replaces it the moment it is in, so an agent leaves the list only
// once that says it is gone.
// the first load draws the state kept from the last read while the
// fresh one (seconds, #1519) is read; an agent leaves only once that says so
let relang = false, shown = null;
if (!load.done) {
const last = await Promise.race([api("state?last=1").catch(() => null), asked.then(() => null, () => null)]);
@@ -4511,11 +4507,8 @@ function updateStuck(u) {
}
// ---------- what's new ----------
// After an update the window (or magpie web's page) shows what changed in
// every release since the one last run, once (a Discord user: to see if
// their issue was fixed). Not in the tray's panel, where a dialog has no
// room; Settings' version row opens it again, and with an update waiting,
// that one's notes first.
// After an update the window (or magpie web) shows each release's changes
// since the one last run, once; Settings' version row opens it again.
const ISSUES = "https://github.com/yetone/magpie/issues/";
let whatsNewAsked = false;
// cliBehindOnce: the terminal's magpie is a copy, not the installer's
@@ -5408,10 +5401,8 @@ function renderList() {
// fastToggle: a model with a fast mode (a ChatGPT account's GPT, Cursor's
// -fast, …) is sent in it, or not, for the agent the picker is of (#954),
// switched by the model as a routing group's member is; the pick itself
// stays as it is. Where an account offers it Ultrafast too (ultraOk,
// #1954), a click steps usual → Fast → Ultrafast → usual, as a camera's
// flash button steps its modes
// switched by the model as a routing group's member is. Where ultraOk
// (#1954), a click steps usual → Fast → Ultrafast → usual
const BOLT = "M9.25 1.75 3.75 9h4l-1 5.25L12.25 7h-4z";
function fastToggle(o) {
const b = el("button", "fast" + (o.fast ? " on" : "") + (o.fast && o.ultra ? " ultra" : ""));
@@ -7544,11 +7535,9 @@ function providerDirty() {
(active?.matches(".editor .mprice input") && active.value !== active.defaultValue));
}
// backdropClick(el, on) says whether a click on el is one on its backdrop:
// pressed and let go both where on(e) says the backdrop is. A press inside
// the dialog let go out over the backdrop, a selection dragged out of a
// field (#1373), clicks the two's nearest shared ancestor, the backdrop, so
// the click's own target can't tell it apart. Every dialog that closes from
// its backdrop asks this.
// pressed and let go both where on(e) says the backdrop is: a selection
// dragged out of a field (#1373) clicks the backdrop too. Every dialog that
// closes from its backdrop asks this.
function backdropClick(el, on = (e) => e.target === el) {
let down = false, up = false;
el.addEventListener("pointerdown", (e) => { down = on(e); up = false; }, true);
@@ -15280,7 +15269,8 @@ function openProtoMenu(anchor, opts, value, choose, head = "Protocol this key sp
const multi = Array.isArray(value);
let picked = multi ? [...value] : null;
// an item with its own ticked (true or false) is a setting beside the pick
const isOn = (v, o) => typeof o?.ticked === "boolean" ? o.ticked : !multi ? v === value : v === "" ? !picked.length : picked.includes(v);
// a group heading (o.group, its values) is ticked when all of them are
const isOn = (v, o) => o?.group ? o.group.every((g) => picked.includes(g)) : typeof o?.ticked === "boolean" ? o.ticked : !multi ? v === value : v === "" ? !picked.length : picked.includes(v);
const box = el("div", "pop proto-menu" + (cls ? " " + cls : ""));
box.setAttribute("role", "menu");
box.append(el("div", "pm-head", t(head)));
@@ -15295,14 +15285,15 @@ function openProtoMenu(anchor, opts, value, choose, head = "Protocol this key sp
}
const tick = (b, o) => {
b.classList.toggle("on", isOn(o.v, o));
if (o.group) b.classList.toggle("mixed", !isOn(o.v, o) && o.group.some((g) => picked.includes(g)));
b.setAttribute("aria-checked", isOn(o.v, o));
b.firstChild.replaceChildren(...(isOn(o.v, o) ? [svg(CHECK, 12, 1.9)] : []));
};
const items = opts.map((o) => {
const b = el("button", "pm-item");
const b = el("button", "pm-item" + (o.group ? " pm-group" : ""));
b.type = "button";
if (o.title) b.title = o.title;
b.setAttribute("role", multi && o.v && o.v !== "\x00" || typeof o.ticked === "boolean" ? "menuitemcheckbox" : "menuitemradio");
b.setAttribute("role", o.group || multi && o.v && o.v !== "\x00" || typeof o.ticked === "boolean" ? "menuitemcheckbox" : "menuitemradio");
const words = el("span", "pm-words");
words.append(el("span", "pm-name", o.literalName ? o.name : t(o.name)), el("span", "pm-note", t(o.note)));
b.append(el("span", "pm-tick"), words);
@@ -15310,6 +15301,12 @@ function openProtoMenu(anchor, opts, value, choose, head = "Protocol this key sp
b.onclick = (e) => {
e.stopPropagation();
if (!multi) { closeProtoMenu(); choose(o.v, e); return; }
if (o.group) {
picked = isOn(o.v, o) ? picked.filter((v) => !o.group.includes(v)) : [...new Set([...picked, ...o.group])];
items.forEach((it, i) => tick(it, opts[i]));
if (live) choose(opts.map((o) => o.v).filter((v) => picked.includes(v)));
return;
}
if (o.v === "\x00") return;
if (!o.v) { picked = []; closeProtoMenu(); if (live) choose([]); return; }
picked = picked.includes(o.v) ? picked.filter((v) => v !== o.v) : [...picked, o.v];
@@ -15326,7 +15323,8 @@ function openProtoMenu(anchor, opts, value, choose, head = "Protocol this key sp
bareTicks(box, items);
if (filter) filter.oninput = () => {
const q = filter.value.trim().toLocaleLowerCase();
items.forEach((b, i) => { b.hidden = !opts[i].always && !(opts[i].name + " " + (opts[i].find || "")).toLocaleLowerCase().includes(q); });
items.forEach((b, i) => { if (!opts[i].group) b.hidden = !opts[i].always && !(opts[i].name + " " + (opts[i].find || "")).toLocaleLowerCase().includes(q); });
items.forEach((b, i) => { if (opts[i].group) b.hidden = !opts[i].group.some((v) => items.some((m, j) => opts[j].v === v && !m.hidden)); });
};
document.body.append(box);
placeMenu(box, anchor, align);
@@ -15344,7 +15342,7 @@ function openProtoMenu(anchor, opts, value, choose, head = "Protocol this key sp
if (e.key === "ArrowDown" || e.key === "ArrowUp") {
stepFocus(e, shown, i);
} else if (filter && e.key === "Enter" && document.activeElement === filter) {
const first = shown.find((b) => !opts[items.indexOf(b)].always);
const first = shown.find((b) => !opts[items.indexOf(b)].always && !opts[items.indexOf(b)].group);
if (first) { e.preventDefault(); first.click(); }
} else if (filter && (e.key === "Home" || e.key === "End") && i >= 0) {
e.preventDefault();
@@ -22758,11 +22756,9 @@ function prefsKeep(s) {
}
// savePrefs sends what the page was drawn with (prefsBase) and the choice
// made on it. The saves go one after another, each with the choices before
// it: two made quickly (a theme, then a language) each sent the page as it
// was drawn, the second undoing the first, and their answers could come
// back in either order. The page is painted and drawn again once the last
// is in.
// made on it. Saves go one after another, each with the choices before it:
// two quick ones (a theme, then a language) undid each other. The page is
// drawn again once the last is in.
let prefsBase = {}, prefsQueue = Promise.resolve(), prefsQueued = 0;
function savePrefs(body) {
const change = Object.fromEntries(Object.entries(body).filter(([k, v]) => JSON.stringify(v) !== JSON.stringify(prefsBase[k])));
+17 -9
View File
@@ -4874,16 +4874,17 @@ magpie.plugin("library", (ctx) => {
const SKILL_SORTS = () => [["source", t("By source")], ...NAME_SORTS];
// the groups, and each skill's text to filter by, worked out once for
// each answer from magpie and each pick
let grouped = null;
function skillGroups() {
const pick = sortOf("libSkills", SKILL_SORTS());
if (grouped?.lib === lib && grouped.pick === pick) return grouped.groups;
let grouped = {}; // sort → { lib, groups }
// bySource: the project picker's grouping, whatever sort the list has
function skillGroups(bySource = false) {
const pick = bySource ? "source" : sortOf("libSkills", SKILL_SORTS());
if (grouped[pick]?.lib === lib) return grouped[pick].groups;
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()])) };
grouped = { lib, pick, groups: [g] };
return grouped.groups;
grouped[pick] = { lib, groups: [g] };
return grouped[pick].groups;
}
// the user's own groups first, in the order made, each skill in its
// group rather than its source's (#791)
@@ -4932,7 +4933,7 @@ magpie.plugin("library", (ctx) => {
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.parts = g.mine ? null : partsOf(g);
}
grouped = { lib, pick, groups };
grouped[pick] = { lib, groups };
return groups;
}
@@ -5943,7 +5944,14 @@ magpie.plugin("library", (ctx) => {
const global = (s) => (s.agents || []).filter((id) => offIds.includes(id) && !routedOff(agentOf(id) || { name: id }, s));
const inherited = (s) => !p.skills[s.name]?.length && global(s).some((id) => !(p.skillsOff?.[s.name] || []).includes(id));
const now = lib.skills.filter((s) => p.skills[s.name]?.length || p.problems?.[s.name] || inherited(s)).map((s) => s.name);
const opts = lib.skills.map((s) => ({ v: s.name, name: s.name, literalName: true, note: "" }));
// by source, as the Library lists them, a heading ticking its group
const gs = skillGroups(true);
const opts = gs.length < 2 ? lib.skills.map((s) => ({ v: s.name, name: s.name, literalName: true, note: "" }))
: gs.flatMap((g) => {
const title = g.mine || g.repo || t("On this computer");
return [{ v: "\x00" + g.key, group: g.skills.map((s) => s.name), name: title, literalName: true, note: "" },
...g.skills.map((s) => ({ v: s.name, name: s.name, literalName: true, note: "", find: title }))];
});
openProtoMenu(b, opts, now, async (next) => {
const byName = (n) => lib.skills.find((s) => s.name === n);
let adds = next.filter((n) => !now.includes(n)), outs = now.filter((n) => !next.includes(n));
@@ -5977,7 +5985,7 @@ magpie.plugin("library", (ctx) => {
? t("{skill} is out of {name}", { skill: outs[0], name: p.name })
: t("{skills} are out of {name}", { skills: names(outs), name: p.name }));
}
}, "Pick the skills it gets", "", "right", false, opts.length > 8 ? "Find a skill" : "");
}, "Pick the skills it gets", "", "right", false, lib.skills.length > 8 ? "Find a skill" : "");
});
b.setAttribute("aria-expanded", "false");
if (!lib.skills.length || !all.length) b.disabled = true;
@@ -0,0 +1,120 @@
// Run with Node's test runner and Playwright on the module path; see README.md.
// Elorynth on X: adding skills to a project, show them grouped by source as
// the Library does, with a click on a group's heading for the whole group.
// The project's Skills menu lists the library's skills by source, a heading
// over each group that ticks (and unticks) all of its skills in one click,
// half-ticked while some are in. Typing a repository finds its skills. With
// one group only, the menu is the flat list it was. In every language, at
// phone width. 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 assets = path.resolve(__dirname, "../assets");
const HOME = "/Users/emo";
const APP = HOME + "/code/app", WEB = HOME + "/code/web";
const agent = (id, name, more = {}) => ({ id, name, icon: "", skills: `${HOME}/.${id}/skills`, ...more });
const sk = (name, repo) => ({ name, description: name + " things", agents: ["claude", "codex"], ...(repo ? { kind: "github", source: "https://github.com/" + repo + "/tree/main/" + name } : {}) });
function server(lang, posts) {
const projects = {
[APP]: { "kit-a": ["codex"] },
[WEB]: {},
};
const lib = () => ({
dir: `${HOME}/.magpie/library`, backups: `${HOME}/.magpie/backups`, home: HOME,
agents: [
agent("claude", "Claude Code", { projectSkills: ".claude/skills" }),
agent("codex", "Codex", { projectSkills: ".agents/skills" }),
agent("goose", "Goose"),
],
instructions: { agents: [] }, servers: [], skills: [sk("pdf"), sk("l1"), sk("l2"), sk("l3"), sk("l4"), sk("l5"), sk("kit-a", "acme/kit"), sk("kit-b", "acme/kit"), sk("tool-c", "beta/tools")], foundServers: [], foundSkills: [],
projects: Object.entries(projects).map(([dir, skills]) => ({ dir, name: path.basename(dir), copy: false, skills: { ...skills }, placed: [], servers: {}, wrote: {} })),
});
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" } } });
if (url.pathname === "/api/library") return route.fulfill({ json: lib() });
if (url.pathname === "/api/library/projects/skills") {
const b = req.postDataJSON();
posts.push(b);
for (const n of b.names) {
if (b.agents.length) projects[b.dir][n] = b.agents;
else delete projects[b.dir][n];
}
return route.fulfill({ json: { ...lib(), result: { changed: [], problems: [] } } });
}
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 heads = { en: "On this computer", zh: "本机", "zh-TW": "本機", ja: "このコンピュータ", de: "Auf diesem Computer" };
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
test(engine + ": a project's Skills menu is grouped by source", async (t) => {
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(); });
for (const lang of Object.keys(heads)) {
await t.test(lang, async () => {
const posts = [];
const ctx = await browser.newContext({ viewport: { width: 400, height: 2400 } });
await ctx.addInitScript(() => { try { localStorage.setItem("magpie.libTab", "skills"); } catch {} });
const page = await ctx.newPage();
page.setDefaultTimeout(5000);
page.setDefaultNavigationTimeout(60000);
page.on("pageerror", (e) => errors.push(e.message));
await page.route("**/*", server(lang, posts));
await page.goto("http://magpie.test/");
await page.locator('button[data-view="library"]').click();
const app = page.locator("#view-library .lib-project").filter({ hasText: "~/code/app" });
await app.waitFor();
await app.locator(".lib-projhead").click();
await app.locator(".lib-projskill").first().waitFor();
const menu = page.locator(".proto-menu");
await app.locator(".lib-projpick").click();
await menu.waitFor();
const state = () => menu.locator(".pm-item").evaluateAll((bs) => bs.map((b) => [b.textContent.trim(), b.getAttribute("aria-checked"), b.classList.contains("mixed")]));
assert.deepEqual((await state()).slice(0, 5), [
["acme/kit", "false", true], ["kit-a", "true", false], ["kit-b", "false", false],
["beta/tools", "false", false], ["tool-c", "false", false],
], "a heading over each source, half-ticked while some of its skills are in");
assert.equal((await state())[5][0], heads[lang], "this computer's skills last");
const box = await menu.boundingBox();
assert(box.x >= 0 && box.x + box.width <= 400, "the menu fits a phone");
// one click ticks the whole group, the next takes it out
await menu.locator(".pm-group", { hasText: "acme/kit" }).click();
assert.deepEqual((await state()).slice(0, 3), [["acme/kit", "true", false], ["kit-a", "true", false], ["kit-b", "true", false]]);
await menu.locator(".pm-group", { hasText: "beta/tools" }).click();
await menu.locator(".pm-group", { hasText: "beta/tools" }).click();
assert.equal(posts.length, 0, "nothing is written while the menu is open");
await menu.locator(".pm-group", { hasText: "acme/kit" }).click();
assert.deepEqual((await state()).slice(0, 3), [["acme/kit", "false", false], ["kit-a", "false", false], ["kit-b", "false", false]]);
await menu.locator(".pm-group", { hasText: "acme/kit" }).click();
// the repository typed finds its skills, under their heading
const q = menu.locator(".sc-q");
await q.fill("beta");
assert.deepEqual(await menu.locator(".pm-item:not([hidden])").evaluateAll((bs) => bs.map((b) => b.textContent.trim())), ["beta/tools", "tool-c"]);
await q.fill("");
await page.keyboard.press("Escape");
await page.waitForFunction(() => document.querySelector("#status")?.textContent.trim());
assert.deepEqual(posts, [{ dir: APP, names: ["kit-b"], agents: ["codex"] }], "the group's other skill goes in for the project's agents");
assert.deepEqual(errors, []);
await ctx.close();
});
}
});
}