gui: Settings' search finds by a part's name, unfolds an Advanced around a hit, and reaches the settings sheets build

Three gaps in Settings' search (the UI/UX scan's item 12):
- every part matched its tab's id too, so "usage" brought all of
  Allowances (id usage), rows that never say it included. A part is now
  found by its name; Observability still answers to "otel".
- a hit under a folded Advanced (Network and sharing's Name) stayed
  folded, so the part showed with nothing in it to see. It is unfolded
  while the search lasts and folded again when it ends (setFolds, in the
  lazy provlinks.js, so the core grows by two calls).
- what an agent's sheet or the Claude editor draws only when opened
  wasn't in the page to be found: Claude Code's prompt cache (main and
  subagents), its commit signature (Co-Authored-By), an agent's own
  fields (permission mode) and the Claude editor's run mode (claude -p).
  Each has a link row now, in the agent's or provider's name; Open opens
  the sheet or editor and lights the row, again if the editor draws it
  anew once the provider list is in (lightWhen).

docs/subsystems/gui-shell.md says so.

Run (mote, at this tree, rebased on origin/main 98355866f):
- settings-search-reach (new), settings-search, provider-prefs,
  provider-prefs-layout, settings-groups, settings-back,
  settings-tabs-stick, settings-hints, i18n-keys, gui-de, claude-mode,
  claude-cache, claude-attribution, claude-permission-mode,
  claude-lean-prompt-setting, claude-extra-usage-setting, agent-prefs,
  sync-own-fields, update-row-steady, win-caption; Chromium and WebKit,
  every language: 349 of 355 pass. The 6 red are settings-groups' "warm-ups
  and check-in" (an extra "Spend extra usage" row), red the same on
  origin/main 98355866f and filed as #6597.
- go test ./internal/gui -run 'TestCoreScriptBudget|TestI18n|TestCSS':
  ok, no budget raised.

Broken by hand, each red in both engines and every language (12 of 12),
then put back:
- the old code (origin/main): "usage" brings Menu bar cost.
- the tab's id put back in a part's words: the same.
- setFolds' unfold removed: "its Advanced unfolded".
- the fold-back on clear removed: "folded again after the search".
- sheetLinks not called: "Co-Authored" finds nothing.
- the run mode's link left out: "claude -p" finds nothing.
- lightWhen lighting only its first find: the editor's run-mode row is
  never lit (the editor draws it anew).

Not tried: the real app window; agents other than Claude Code with own
fields (the rows come from the same a.own list).
This commit is contained in:
yetone
2026-11-18 13:16:18 +08:00
parent fefab53d22
commit de321cc92e
4 changed files with 226 additions and 29 deletions
File diff suppressed because one or more lines are too long
+3 -1
View File
@@ -19964,7 +19964,7 @@ function findSettings() {
let any = false;
for (const id of SET_TABS) {
const page = $("#setPage-" + id), tab = $("#setTab-" + id);
const part = setText(tab) + " " + id;
const part = setText(tab) + (id === "otel" ? " otel" : ""); // not "usage" for Allowances
let hits = 0, head = "";
const lit = new Set();
for (const n of page.querySelectorAll(".row-head, .row")) {
@@ -19999,6 +19999,7 @@ function findSettings() {
page.hidden = !hits;
any ||= hits > 0;
}
window.setFolds?.(v); // a hit under a folded Advanced (provlinks.js)
// the built-ins that match (setfeats.js)
if (window.setFeatsFind) any = setFeatsFind(words) > 0 || any;
else import("./setfeats.js").then(() => setQuery && findSettings(), () => {});
@@ -20012,6 +20013,7 @@ function searchSettings(q) {
const v = $("#view-settings");
v.classList.remove("set-searching");
for (const n of v.querySelectorAll(".set-miss")) n.classList.remove("set-miss");
window.setFolds?.(v, 1);
$("#setNone").hidden = true;
window.setFeatsFind?.([]);
setSetTab(setTab);
+85 -27
View File
@@ -3,10 +3,91 @@
// opening the provider's editor. They show only while searching, so
// app.js imports this when a search first wants them, and it weighs
// nothing on the core. A row goes with its list's plugin (warm-ups), and
// with no such provider to open (findSettings, by its agents).
// with no such provider to open (findSettings, by its agents). The
// settings an agent's sheet builds when it opens (Claude Code's prompt
// cache and commit signature, its own fields under Advanced) and the
// Claude editor's run mode, which aren't in the page until then, have
// rows here too.
const prefLink = (name, en, where, says, open) => {
const row = el("div", "row pref agent-pref-link"), who = el("div", "who"), n = el("div", "name", name);
n.dataset.en = en || name;
who.append(n, el("div", "sub", where));
if (says) {
const w = el("span", "", says[0]);
w.hidden = true;
w.dataset.en = says[1] || says[0];
who.append(w);
}
const go = el("button", "text", t("Open"));
go.type = "button";
go.onclick = open;
row.append(who, go);
return row;
};
// opened, the row it names is brought into sight and lit once drawn, and
// again if the page draws it anew (the editor once the list is in)
const lightWhen = (find) => {
let n = 0;
const look = () => {
const r = find();
if (r && !r.classList.contains("flash")) {
const fold = r.closest("details:not([open])");
if (fold) fold.open = true;
r.scrollIntoView({ block: "center" });
r.classList.add("flash");
}
if (++n < 40) setTimeout(look, 50);
};
look();
};
// an agent's sheet's own rows, by the class compactFill gives them
const SHEET_ROWS = {
claude: [["Prompt cache · main conversation", ".claude-cache", 0], ["Prompt cache · subagents", ".claude-cache", 1], ["Commit signature (Co-Authored-By)", ".claude-attribution", 0]],
};
function sheetLinks(box) {
const by = new Map();
for (const a of state.agents) {
if (a.id.includes("@wsl:") || !agentPrefsOf(a)) continue;
const rows = [...(SHEET_ROWS[kindOf(a)] || []).map(([label, sel, i]) => ({ label, sel, i })),
...(a.own || []).map((f) => ({ label: f.label[0].toUpperCase() + f.label.slice(1), own: true }))];
for (const r of rows) {
const k = r.label + "\n" + (r.sel || "own");
by.has(k) ? by.get(k).agents.push(a) : by.set(k, { ...r, agents: [a] });
}
}
for (const { label, sel, i, own, agents } of by.values()) {
box.append(prefLink(t(label), label, t("In {agent}'s settings, on the Agents page", { agent: agents.map((a) => a.name).join(", ") }), null, async () => {
if (await show("agents") === false) return;
await openAgentPrefs(agents[0]);
lightWhen(() => own ? [...document.querySelectorAll("#modal .own-fields .row")].find((r) => r.querySelector(".name")?.textContent === t(label)) : document.querySelectorAll("#modal " + sel)[i]);
}));
}
}
// opens the editor of the first provider of these agents, Advanced open
async function openIn(agents, find) {
if (!await show("providers")) return;
const p = providers?.providers.find((x) => agents.includes(x.account?.agent));
if (!p) return;
advanced = { of: p.id, open: true };
await openProvider(p.id);
lightWhen(find);
}
// Settings' search: a hit under a folded Advanced is unfolded while the
// search lasts (findSettings), and folded again when it ends
window.setFolds = (v, end) => {
for (const d of v.querySelectorAll(end ? "details[data-found]" : "details:not([open]):not([hidden])")) {
if (end) delete d.dataset.found, d.open = false;
else if ([...d.querySelectorAll(".row:not(.set-miss)")].some((r) => !r.closest("[hidden]") && !featureHides(r))) d.open = d.dataset.found = true;
}
};
window.provPrefLinksDraw = function () {
const box = $("#provPrefLinks");
box.replaceChildren();
// the Claude editor's run mode, drawn as the editor opens
const run = prefLink(t("Claude Code runs as"), "Claude Code runs as", t("In {provider}'s editor, on the Providers page", { provider: subNames(["claude"]) }),
[t("Interactive mode (TUI)") + " claude -p", "Interactive mode (TUI) claude -p"], () => openIn(["claude"], () => $(".editor .claude-mode")));
run.agents = ["claude"];
box.append(run);
const ids = [...new Set(Object.values(PROV_PREFS).flat())];
const by = (list) => list.classList.contains("ci-plugin") ? [list.dataset.provider] : Object.keys(PROV_PREFS).filter((k) => PROV_PREFS[k].includes(list.id));
for (const list of [...ids.map((id) => $("#" + id)), ...$("#pluginCheckinList").children]) {
@@ -15,36 +96,13 @@ window.provPrefLinksDraw = function () {
for (const r of list.querySelectorAll(":scope > .row.pref:not(.ci-acct):not(.ci-now-row):not(.warm-now):not([hidden])")) {
const name = r.querySelector(".who > .name");
if (!name) continue;
const row = el("div", "row pref agent-pref-link");
const sub = r.querySelector(".sub:not(.err)");
const row = prefLink(name.textContent, name.dataset.en, t("In {provider}'s editor, on the Providers page", { provider: subNames(agents.slice(0, 1)) }), sub && [sub.textContent, sub.dataset.en], () => openIn(agents, () => r.isConnected && r));
const f = list.closest("[data-feature]")?.dataset.feature;
if (f) row.dataset.feature = f;
row.agents = agents;
const who = el("div", "who");
const n = el("div", "name", name.textContent);
n.dataset.en = name.dataset.en || name.textContent;
who.append(n, el("div", "sub", t("In {provider}'s editor, on the Providers page", { provider: subNames(agents.slice(0, 1)) })));
const sub = r.querySelector(".sub:not(.err)");
if (sub) {
const says = el("span", "", sub.textContent);
says.hidden = true;
says.dataset.en = sub.dataset.en || sub.textContent;
who.append(says);
}
const go = el("button", "text", t("Open"));
go.type = "button";
go.onclick = async () => {
if (!await show("providers")) return;
const p = providers?.providers.find((x) => agents.includes(x.account?.agent));
if (!p) return;
// its field is under the editor's Advanced: opened, and the row lit
advanced = { of: p.id, open: true };
await openProvider(p.id);
if (!r.isConnected) return;
r.scrollIntoView({ block: "center" });
r.classList.add("flash");
};
row.append(who, go);
box.append(row);
}
}
sheetLinks(box);
};
@@ -0,0 +1,137 @@
// Run with Node's test runner and Playwright on the module path; see README.md.
// What Settings' search reaches beyond the rows drawn in its page:
// - a tab's id is not a word of it: "usage" doesn't bring all of
// Allowances (its id), only the rows that say it;
// - a hit under a folded Advanced (Network and sharing's Name) is
// unfolded while the search lasts, and folded again when it ends;
// - the settings an agent's sheet builds as it opens (Claude Code's
// prompt cache and commit signature, its own fields) and the Claude
// editor's run mode (claude -p) are found as links, and Open reaches
// the row, lit.
// Every language, Chromium and WebKit; 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 { provPrefsProviders, agentRow } = require("./reader.cjs");
const assets = path.resolve(__dirname, "../assets");
function server(lang, posts) {
const cur = {
theme: "light", lang, tray: "panel", quotaLeft: false, currency: "usd", textSize: 100,
proxy: "", redact: false, redactPersonal: false, redactWords: [], trayUsage: "", trayUsageEvery: 3,
version: "0.1.400", dir: "~/.config/magpie", gateway: "http://127.0.0.1:3425",
proxyNow: "none", proxySource: "none", visionModels: [], imageGenModels: [], workbuddyCheckins: [], lanURLs: [],
claudeCache: [{ knob: "cache_ttl", value: "1h" }, { knob: "subagent_cache_ttl" }],
fx: { rate: 7.2, at: new Date().toISOString(), stale: false },
};
const claude = { ...agentRow("claude", "Claude Code"), own: [{ key: "permissions.defaultMode", label: "permission mode", value: "", options: [{ value: "plan" }] }] };
return async (route) => {
const req = route.request(), url = new URL(req.url());
const json = (data) => route.fulfill({ json: data });
if (req.method() !== "GET" && url.pathname !== "/api/update/using" && url.pathname !== "/api/page-away") posts.push(url.pathname);
if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:false,textSize:100};` });
if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
if (url.pathname === "/api/state") return json({ agents: [claude, agentRow("codex", "Codex")], profiles: [], settings: { lang, theme: "light", textSize: 100 }, fx: cur.fx });
if (url.pathname === "/api/settings") return json(cur);
if (url.pathname === "/api/claude/mode") return json({ why: "", tui: true });
if (url.pathname === "/api/plugins") return json({ plugins: [] });
if (url.pathname === "/api/providers") return json(provPrefsProviders(["codex", "claude"], { codex: "ChatGPT", claude: "Claude" }));
if (url.pathname === "/api/usage/quotas") return json([]);
if (url.pathname === "/api/groups") return json({ groups: [], models: [] });
if (url.pathname === "/api/window/fit") return route.fulfill({ status: 204 });
if (url.pathname.startsWith("/api/")) return 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)];
try { await route.fulfill({ body: await fs.readFile(file), contentType }); } catch { await route.fulfill({ status: 404, body: "" }); }
};
}
const parts = (page) => page.evaluate(() => [...document.querySelectorAll("#view-settings > [role=tabpanel]")].filter((p) => p.getClientRects().length).map((p) => p.id.replace("setPage-", "")));
const seen = (page, sel) => page.locator(sel).first().evaluate((e) => !!e.getClientRects().length && getComputedStyle(e).visibility !== "hidden");
const LANGS = ["en", "zh", "zh-TW", "ja", "de"];
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
test(engine + ": what Settings' search reaches", async (t) => {
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
t.after(() => browser.close());
const open = async (lang, posts) => {
const context = await browser.newContext({ viewport: { width: 900, height: 700 }, reducedMotion: "reduce" });
const page = await context.newPage();
page.setDefaultTimeout(5000);
page.setDefaultNavigationTimeout(60000);
page.errors = [];
page.on("pageerror", (e) => { if (engine === "webkit" && /due to access control checks/.test(e.message)) return; page.errors.push(e.message); });
await page.route("**/*", server(lang, posts));
await page.goto("http://magpie.test/?view=settings&tab=general");
await page.locator("#themeSegs .opt").first().waitFor();
await page.locator("#netMoreList .instance-name-row").waitFor({ state: "attached" });
return page;
};
const type = async (page, s) => {
await page.locator("#setQ").fill(s);
await page.waitForTimeout(150);
};
const link = (page, name) => page.locator("#provPrefLinks .agent-pref-link:visible", { has: page.locator(".name", { hasText: name }) });
for (const lang of LANGS) {
await t.test(lang, async () => {
const posts = [];
const page = await open(lang, posts);
const tr = (s, vars) => page.evaluate(([s, vars]) => t(s, vars), [s, vars]);
// "usage" is Allowances' id, not a word of it: its rows that don't
// say it stay out
await type(page, "usage");
assert.equal(await seen(page, "#trayCostSegs"), false, "Menu bar cost isn't brought by the tab's id");
// a hit under Network and sharing's folded Advanced is unfolded
assert.equal(await page.locator("#netMore").evaluate((d) => d.open), false);
await type(page, await tr("Shown in the browser tab’s title"));
assert((await parts(page)).includes("network"), "under Network and sharing");
assert.equal(await page.locator("#netMore").evaluate((d) => d.open), true, "its Advanced unfolded");
assert(await seen(page, "#netMoreList .instance-name-row"), "the Name row shows");
// and folded again when the search ends
await type(page, "");
assert.equal(await page.locator("#netMore").evaluate((d) => d.open), false, "folded again after the search");
// Claude Code's sheet's rows, found as links
for (const [word, name] of [["Co-Authored", "Commit signature (Co-Authored-By)"], [(await tr("Prompt cache · subagents")).split(" · ")[0], "Prompt cache · subagents"], [await tr("Permission mode"), "Permission mode"]]) {
await type(page, word);
const l = link(page, await tr(name));
assert.equal(await l.count(), 1, `"${word}" finds ${name}`);
assert.equal(await l.locator(".sub").textContent(), await tr("In {agent}'s settings, on the Agents page", { agent: "Claude Code" }));
}
// and the Claude editor's run mode, by claude -p
await type(page, "claude -p");
assert.equal(await link(page, await tr("Claude Code runs as")).count(), 1, "claude -p finds Claude Code's run mode");
assert.deepEqual(posts, [], "searching posts nothing");
// Open reaches the row in the sheet, lit
await type(page, "Co-Authored");
await link(page, await tr("Commit signature (Co-Authored-By)")).locator("button").click();
await page.locator("#modal .claude-attribution.flash").waitFor();
await page.keyboard.press("Escape");
await page.locator("#modal").waitFor({ state: "hidden" });
// its own field, under the sheet's folded Advanced, unfolded
await page.goto("http://magpie.test/?view=settings&tab=general");
await page.locator("#themeSegs .opt").first().waitFor();
await type(page, await tr("Permission mode"));
await link(page, await tr("Permission mode")).locator("button").click();
await page.locator("#modal .own-fields[open] .own-field.flash").waitFor();
await page.keyboard.press("Escape");
await page.locator("#modal").waitFor({ state: "hidden" });
// the run mode's Open reaches the Claude editor's row
await page.goto("http://magpie.test/?view=settings&tab=general");
await page.locator("#themeSegs .opt").first().waitFor();
await type(page, "claude -p");
await link(page, await tr("Claude Code runs as")).locator("button").click();
await page.locator(".editor .claude-mode.flash").waitFor();
assert.deepEqual(page.errors, []);
await page.context().close();
});
}
});
}