sessions: every agent in the Agent menu and in Continue in shows its icon
The Sessions page's agent picker showed the chosen agent's icon on its button, but the menu it opened listed bare names. Each item now carries its icon between the tick and the name, level with the name; the "Continue in another agent" menu does the same. The icons are drawn by the sessions plugin after the menu opens, so the core scripts stay within TestCoreScriptBudget (a first try in openProtoMenu went 116 bytes over). Run: sessions-toolbar and sessions-talk GUI tests, chromium and webkit, en and zh, light and dark: 8 pass. Broken by hand (no icons drawn): sessions-toolbar red in chromium, "every agent in the menu has its icon". go test ./internal/gui/ -run 'TestCoreScriptBudget|Plugin' ok. Looked at the webkit zh dark menu screenshot. Not run: the whole GUI suite (load ~380 on this machine).
This commit is contained in:
@@ -359,11 +359,12 @@ magpie.plugin("sessions", (ctx) => {
|
||||
pick.onclick = (e) => {
|
||||
e.stopPropagation();
|
||||
if (pick.classList.contains("open")) return closeProtoMenu();
|
||||
const opts = data.agents.map((x) => ({ v: x.agent, name: x.name, note: String(x.count), literalName: true }));
|
||||
const opts = data.agents.map((x) => ({ v: x.agent, name: x.name, icon: x.icon, note: String(x.count), literalName: true }));
|
||||
openProtoMenu(pick, opts, data.agent, (name) => {
|
||||
pick.focus({ preventScroll: true });
|
||||
chooseAgent(name);
|
||||
}, "Agent", "sm-agent-menu");
|
||||
iconItems(opts);
|
||||
};
|
||||
}
|
||||
wrap.append(tabs, pick);
|
||||
@@ -1081,6 +1082,8 @@ magpie.plugin("sessions", (ctx) => {
|
||||
|
||||
// agentOf is an agent as the page names it: of those with sessions, else
|
||||
// by its id
|
||||
// iconItems gives each agent in the menu just opened its icon, as its button has
|
||||
const iconItems = (opts) => document.querySelectorAll(".proto-menu .pm-item").forEach((b, i) => opts[i]?.icon && b.firstChild.after(icon(opts[i].icon)));
|
||||
const agentOf = (id) => data?.agents.find((x) => x.agent === id) || { agent: id, name: id, icon: id };
|
||||
|
||||
// carryPick is the other agents that can carry a session on from its
|
||||
@@ -1098,9 +1101,9 @@ magpie.plugin("sessions", (ctx) => {
|
||||
if (b.classList.contains("open")) return closeProtoMenu();
|
||||
const opts = [];
|
||||
for (const c of s.carry) {
|
||||
const name = agentOf(c.agent).name;
|
||||
opts.push({ v: "copy\x01" + c.agent, name, literalName: true, note: "Copy the command", title: c.command });
|
||||
if (data.terminal) opts.push({ v: "term\x01" + c.agent, name, literalName: true, note: "Open in session terminal", title: c.command });
|
||||
const { name, icon: ic } = agentOf(c.agent);
|
||||
opts.push({ v: "copy\x01" + c.agent, name, icon: ic, literalName: true, note: "Copy the command", title: c.command });
|
||||
if (data.terminal) opts.push({ v: "term\x01" + c.agent, name, icon: ic, literalName: true, note: "Open in session terminal", title: c.command });
|
||||
}
|
||||
openProtoMenu(b, opts, "", (v) => {
|
||||
b.focus({ preventScroll: true });
|
||||
@@ -1110,6 +1113,7 @@ magpie.plugin("sessions", (ctx) => {
|
||||
if (how === "copy") copy(c.command, t("Command"));
|
||||
else api("sessions/terminal", { agent: s.agent, id: s.id, in: to }).then(() => status(t("Opening in session terminal"), "ok"), (err) => status(err.message, "err"));
|
||||
}, "Continue in another agent", "sess-carry-menu", "right");
|
||||
iconItems(opts);
|
||||
};
|
||||
return b;
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
.sm-agent-pick .ic { width: 13px; height: 13px; flex: none; }
|
||||
.sm-agent-pick em, .sm-agents em, .sm-trash-btn em { font-style: normal; font-size: 10.5px; color: var(--faint); font-variant-numeric: tabular-nums; }
|
||||
.pop.proto-menu.sm-agent-menu { width: min(280px, calc(100vw - 16px)); max-height: min(360px, 70vh); overflow-y: auto; background: var(--card); }
|
||||
.sm-agent-menu .pm-item { align-items: center; }
|
||||
.sm-agent-menu .pm-words { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex: 1; }
|
||||
.sm-agent-menu .pm-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.sm-agent-menu .pm-note { flex: none; font-variant-numeric: tabular-nums; }
|
||||
|
||||
@@ -127,6 +127,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
await menu.waitFor();
|
||||
assert.equal((await menu.locator(".pm-head").textContent()).trim(), w.head);
|
||||
assert.deepEqual(await menu.locator(".pm-item .pm-name").allTextContents(), ["omp", "omp"]);
|
||||
assert.deepEqual(await menu.locator(".pm-item > .ic").evaluateAll((l) => l.map((e) => e.dataset.icon)), ["omp", "omp"], "each agent to continue in shows its icon");
|
||||
assert.deepEqual(await menu.locator(".pm-item .pm-note").allTextContents(), [w.copyNote, w.termNote]);
|
||||
assert.equal(await page.locator("select").count(), 0, "no native select");
|
||||
assert.equal(await carry.getAttribute("aria-expanded"), "true");
|
||||
|
||||
@@ -115,6 +115,14 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
await menu.waitFor();
|
||||
await menu.evaluate((e) => Promise.all(e.getAnimations().map((a) => a.finished.catch(() => {}))));
|
||||
assert.equal(await menu.getByRole("menuitemradio").count(), agents.length);
|
||||
// each agent in the menu shows its icon, as the picker does, level with its name
|
||||
const marks = await menu.locator(".pm-item").evaluateAll((items) => items.map((b) => {
|
||||
const ic = b.querySelector(":scope > .ic"), n = b.querySelector(".pm-name");
|
||||
const i = ic?.getBoundingClientRect(), r = n.getBoundingClientRect();
|
||||
return { icon: ic?.dataset.icon, w: i?.width, mid: i ? Math.abs(i.top + i.height / 2 - (r.top + r.height / 2)) : 99, before: i ? i.right <= r.left : false };
|
||||
}));
|
||||
assert.deepEqual(marks.map((m) => m.icon), agents.map((a) => a.icon), "every agent in the menu has its icon");
|
||||
assert(marks.every((m) => m.w === 16 && m.mid <= 1 && m.before), `icons sit 16px wide, level with and before the name: ${JSON.stringify(marks)}`);
|
||||
assert.equal(await picker.getAttribute("aria-expanded"), "true");
|
||||
const mb = await menu.boundingBox();
|
||||
assert(mb.x >= 0 && mb.x + mb.width <= 320, "the open menu fits a narrow window");
|
||||
|
||||
Reference in New Issue
Block a user