From a5c97cd83a6175a2a8456811127055f762eede71 Mon Sep 17 00:00:00 2001 From: yetone Date: Sun, 8 Nov 2026 18:45:46 +0800 Subject: [PATCH] plugins: a tool plugin's Hide from agents sits with Switch off and Remove The button was on the tools line, pushed right with margin-left: auto, so in a two-line row (x: "Tools for agents: x_search, x_read") it sat a line below Switch off and Remove, which the row centres. It is now one of the row's buttons (toolsFlip), before Options, Switch off and Remove, as a text button like them. Run (mote): plugin-tools 22/22, both engines, en/zh/zh-TW/ja/de, 980 and 420; its new check that every row button shares one centre line fails on the old plugins.js/css (red in every language). plugin*.test.cjs, i18n-keys, old-webkit, library-mcp-tool*: 1134 pass, 6 red: plugin-move-unserved's "Try again" x4 is red on unchanged 8fa3c60f8 too (#4410); i18n-keys "a plugin's words are its own" is red on 8fa3c60f8 (#5332, #5482); plugin-panels chromium timed out once under load and passed when run again. Not tried: the real app with the x plugin installed. --- internal/gui/assets/plugins.css | 1 - internal/gui/assets/plugins.js | 24 +++++++++++++++--------- internal/gui/tests/plugin-tools.test.cjs | 17 +++++++++++------ 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/internal/gui/assets/plugins.css b/internal/gui/assets/plugins.css index a6da0db10..ef0eb6fe0 100644 --- a/internal/gui/assets/plugins.css +++ b/internal/gui/assets/plugins.css @@ -316,4 +316,3 @@ body.window .pm-manual { --bleed-l: 16px; } .pm-card.ghost .sk, .pm-ghlook, .pm-ghlook .dots i, .pm-arrive .pm-card { animation: none; } .pm-ghlook .dots i { opacity: .5; } } -.pm-tools > .pm-tools-flip { flex: none; margin-left: auto; padding: 0 2px; } diff --git a/internal/gui/assets/plugins.js b/internal/gui/assets/plugins.js index 2f0127cba..de984926e 100644 --- a/internal/gui/assets/plugins.js +++ b/internal/gui/assets/plugins.js @@ -1320,6 +1320,8 @@ r.append(val); return r; } + const flip = e.tools?.length && !e.off && toolsFlip(e); + if (flip) val.append(flip); if ((e.isGateway || (mw && !mw.error) || ownOpts) && !e.off && editing?.pkg !== pkg) { const o = el("button", "text", t("Options")); o.title = e.options ? t("The options it runs with") : t("It runs with no options; its package suggests some"); @@ -1479,17 +1481,21 @@ const b = copyBtn(url, t("MCP server address")); b.title = t("Copy the MCP server's address ({url}): add it to an agent as an MCP server (Streamable HTTP)", { url }); d.append(b); - if (sv && !gatewayMode && !featuresOff.has("library")) { - const f = el("button", "link pm-tools-flip", t(sv.on ? "Hide from agents" : "Give to agents")); - f.onclick = (ev) => { - ev.stopPropagation(); - f.disabled = true; - api("library/servers/plugin-on", { name: sv.plugin, on: !sv.on }).then(refresh, (err) => { f.disabled = false; statusErr(err); }); - }; - d.append(f); - } return d; } + // toolsFlip gives a plugin's tools to every agent or hides them, among + // the row's buttons (on the tools line it sat a line below them) + function toolsFlip(e) { + const sv = e.toolsServer; + if (!sv || gatewayMode || featuresOff.has("library")) return null; + const f = el("button", "text pm-tools-flip", t(sv.on ? "Hide from agents" : "Give to agents")); + f.onclick = (ev) => { + ev.stopPropagation(); + f.disabled = true; + api("library/servers/plugin-on", { name: sv.plugin, on: !sv.on }).then(refresh, (err) => { f.disabled = false; statusErr(err); }); + }; + return f; + } // what a plugin's page may read of magpie's: what its package.json's // magpie.permissions declares, each a read with no secret in it diff --git a/internal/gui/tests/plugin-tools.test.cjs b/internal/gui/tests/plugin-tools.test.cjs index 468d52215..ad785628d 100644 --- a/internal/gui/tests/plugin-tools.test.cjs +++ b/internal/gui/tests/plugin-tools.test.cjs @@ -110,18 +110,23 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", shown.length = 0; const vline = row("video").locator(".pm-tools"); assert.equal((await vline.locator("span").first().innerText()).trim(), w.given); - const flip = vline.locator(".pm-tools-flip"); + const vval = row("video").locator(".val"); + const flip = vval.locator(".pm-tools-flip"); assert.equal((await flip.innerText()).trim(), w.hide); await flip.click(); - await vline.locator(".pm-tools-flip", { hasText: w.give }).waitFor(); + await vval.locator(".pm-tools-flip", { hasText: w.give }).waitFor(); assert.equal((await vline.locator("span").first().innerText()).trim(), w.hidden); assert.deepEqual(shown, [{ name: VIDEO, on: false }]); assert.ok(!(await row("video").innerText()).includes("Off\n"), "the plugin itself stays on"); - await vline.locator(".pm-tools-flip").click(); - await vline.locator(".pm-tools-flip", { hasText: w.hide }).waitFor(); + await vval.locator(".pm-tools-flip").click(); + await vval.locator(".pm-tools-flip", { hasText: w.hide }).waitFor(); assert.deepEqual(shown, [{ name: VIDEO, on: false }, { name: VIDEO, on: true }]); - const [fb, vb] = await Promise.all([vline.locator(".pm-tools-flip").boundingBox(), row("video").boundingBox()]); - assert.ok(fb.x + fb.width <= vb.x + vb.width + 1, "the line's button overflows its row"); + assert.equal(await vline.locator("button.pm-tools-flip").count(), 0, "the flip sits with the row's buttons, not on the tools line"); + // on one line with Switch off and Remove (it sat a line below them, 11-08) + const [fb, vb] = await Promise.all([vval.locator(".pm-tools-flip").boundingBox(), row("video").boundingBox()]); + assert.ok(fb.x + fb.width <= vb.x + vb.width + 1, "the row's button overflows its row"); + const mids = await vval.locator("button").evaluateAll((bs) => bs.map((b) => { const r = b.getBoundingClientRect(); return r.top + r.height / 2; })); + for (const m of mids) assert.ok(Math.abs(m - mids[0]) <= 1, "row buttons off one line: " + mids.join(", ")); const over = await page.evaluate(() => document.scrollingElement.scrollWidth - document.scrollingElement.clientWidth); assert.ok(over <= 0, "page scrolls sideways by " + over);