Every agent's model. One place. Codex on DeepSeek, Claude Code on Kimi, from the menu bar.
gui: a page wheeled right after a click scrolls on macOS 13's WebKit too (issennknight on Discord)
yetonea6d7e02c7717
diff --git a/docs/subsystems/gui-shell.md b/docs/subsystems/gui-shell.mdindex 37b7ee14a..7cf7e1467 100644--- a/docs/subsystems/gui-shell.md+++ b/docs/subsystems/gui-shell.md@@ -375,7 +375,7 @@ covers it in both engines, every language and a narrow window.- Settings' Search APIs add row has a base URL field under the key for every API (#1580): the vendor's own address is its placeholder, picking an API already added fills in its saved URL so a new key alone keeps it, and Add with no key changes only the URL. See [a search API's base URL](gateway-routing.md#a-search-apis-base-url), [`renderSearch`](../../internal/gui/assets/app.js) and `search-api.test.cjs`.- Every user-visible string has zh, zh-TW, ja and de translations with the same placeholders. `gui-zh-tw.test.cjs`, `gui-ja.test.cjs` and `gui-de.test.cjs` fail on a missing one; `gui-zh-tw.test.cjs` also fails on a zh-TW string with a Simplified character left in it.- A click never moves the page. Code scrolls a view only with the reader's event in hand (`scrollOnPurpose`); `click-scroll.test.cjs` guards this. A click is taken where the reader left the view: a scroll not theirs made just before it, whose scroll event the browser sends only at the next frame, after the click, is put back first (`backToReader` in the click guard, #1554). What was clicked is held where it was (`hold`); a view at its top when clicked stays at its top, and what comes in above the control moves it down instead (#2134, `update-auto.test.cjs`), as long as it moves less than half its own height and so stays under the pointer. When what the click does leaves the page shorter under it (a list emptied), the view keeps room at its foot for it to stay (`.view-room`), room that goes as the reader scrolls back. A control under what it unrolls (`data-unrolls`, "Show 7 more") goes down with what it opens: what's held is the part it is in, so the rows open downwards. Anything larger above it, as the stage a day picked on Routing brings in above the bar, is scrolled past, and the control stays where it was clicked (`routing-days-fit.test.cjs`, `routing-failed-open.test.cjs`).-- A scroll not the reader's is put back, so every way the reader scrolls has to count as theirs: the wheel and a trackpad's coast after the lift (WebKit on the Mac plays the coast itself and the page hears its scrolls with no wheel for each, so the wheel starts the same chain a touch fling does, `flings`/`flingUntil`: each scroll keeps the next one the reader's till it rests, and a click ends it; issenn on Discord, `view-trackpad-coast.test.cjs`), a wheel or coast the page is never told of (macOS 13's WebKit, Safari 16.6's, scrolled a view under wheels it never dispatched, so every scroll was put back and only the bar's drag moved the page: three scrolls put back the same way within a second, with no click holding, are taken as the reader's run and given back, and so is each one after it that goes on the same way within a second of the last, so a wheel turned slowly or on a loaded Mac loses no step; a scroll by code is one, not a run, and two at rest are still put back; issenn on Discord, `view-wheel-unheard.test.cjs`), a touch and its fling, the keys, a drag, the scrollbar's own drag (`barDrag`, #1089) and the middle button's autoscroll (`panning`, 多喝热水 on Discord). Chromium and WebView2 give the autoscroll a press of button 1 and then no event of the reader's while it scrolls; from that press the view follows it till Chromium ends it, on the next press (which reaches the page only as a pointerup), a key (a keyup), or the lift after the mouse moved while held. A field the guard brings back into view after putting a scroll back is one focused since the reader last scrolled that view, not one they scrolled away from (`scrolledFrom`): the middle press focuses the button under it. See `view-middle-autoscroll.test.cjs`.+- A scroll not the reader's is put back, so every way the reader scrolls has to count as theirs: the wheel and a trackpad's coast after the lift (WebKit on the Mac plays the coast itself and the page hears its scrolls with no wheel for each, so the wheel starts the same chain a touch fling does, `flings`/`flingUntil`: each scroll keeps the next one the reader's till it rests, and a click ends it; issenn on Discord, `view-trackpad-coast.test.cjs`), a wheel or coast the page is never told of (macOS 13's WebKit, Safari 16.6's, scrolled a view under wheels it never dispatched, so every scroll was put back and only the bar's drag moved the page: three scrolls put back the same way within a second are taken as the reader's run and given back, and so is each one after it that goes on the same way within a second of the last, so a wheel turned slowly or on a loaded Mac loses no step; a scroll by code is one, not a run, and two at rest are still put back; issenn on Discord, `view-wheel-unheard.test.cjs`. Under a click's 4s hold the same holds: only a put-back that comes with the page redrawn since the hold last held (`redrawn`: the view's height or where the first held parts sit moved from `h.lay`) is the hold's and never counts toward a run, so a profile opened on the Agents page and wheeled through at once scrolls, issennknight on Discord, `view-wheel-after-click.test.cjs`), a touch and its fling, the keys, a drag, the scrollbar's own drag (`barDrag`, #1089) and the middle button's autoscroll (`panning`, 多喝热水 on Discord). Chromium and WebView2 give the autoscroll a press of button 1 and then no event of the reader's while it scrolls; from that press the view follows it till Chromium ends it, on the next press (which reaches the page only as a pointerup), a key (a keyup), or the lift after the mouse moved while held. A field the guard brings back into view after putting a scroll back is one focused since the reader last scrolled that view, not one they scrolled away from (`scrolledFrom`): the middle press focuses the button under it. See `view-middle-autoscroll.test.cjs`.- Typing never moves the page either. A textarea that grows with its text (the Library's `autosize` in plugins/library/client.js: a set's text, an agent's own text, a skill's description, a subagent's fields) is measured at height auto with what holds it kept at its height, so the page never goes short for a moment: a page gone short has its view's scroll clamped by the browser at every input, an input method's every composing step included, and the guard's putting it back pulled a textarea taller than the view to one of its edges (#2636, `library-ime-scroll.test.cjs`).- There are no native `<select>` elements and no colored left-border stripes. State is shown with a dot or a swatch.- What the window shows can be selected and copied, its controls can't, as in a Mac app (Outvi V on Discord: nothing could be copied into a bug report). The page is `user-select: none`, and two `:where()` rules after `body` in `app.css` make text content selectable (paragraphs, `pre` and `code`, a detail's values, hints and notes, every error class, a conversation, a request's story on Routing) and keep every control unselectable with what is in it (buttons, labels, tabs, menus, the navigation, grips). Both have no specificity, so a view's own rule still decides, as a list being sorted does; a field stays selectable. See `user-select.test.cjs`.diff --git a/internal/gui/assets/app.js b/internal/gui/assets/app.jsindex f18368c5b..74d19e748 100644--- a/internal/gui/assets/app.js+++ b/internal/gui/assets/app.js@@ -23014,11 +23014,12 @@ function keyboardFocus(e) {// macOS 13's WebKit (16.6) may scroll a view under a wheel or a coast it never// tells the page of: every scroll was put back, the page shook and only the// bar's drag moved it (issenn). Three put back the same way in a second, no-// click holding, are the reader's: given back, and so is each one after-// that goes on the same way within a second. Code scrolls once; not a run.+// redraw under a click's hold (h) moving them, are the reader's: given back,+// and so is each one after that goes on the same way within a second. Code+// scrolls once; not a run.let putBack = [], run = null; // { v, by: px put back, at, h: held }, the last second's-function puttingBack(v, from) {- const by = from - v.scrollTop, at = performance.now(), d = Math.sign(by), h = held?.v === v;+function puttingBack(v, from, h) {+ const by = from - v.scrollTop, at = performance.now(), d = Math.sign(by);putBack = putBack.filter((p) => at - p.at < 1000);if (Math.abs(by) < 1) return;putBack.push({ v, by, at, h });@@ -23233,13 +23234,17 @@ function standIn(h) {if (s && s !== c[0] && s.tagName === c[0].tagName && s.classList[0] === c[0].classList[0] && atRest(s)) { c[0] = s; return c; }}}+// where the held parts are in the page, and how tall it is: what the hold+// left (h.lay), and a redraw changes, a scroll not+const laid = (h) => [h.v.scrollHeight, ...h.chain.slice(0, 3).map(([n]) => n.isConnected ? onScreen(n, h.v) + h.v.scrollTop : NaN)];+const redrawn = (h) => !h.lay || laid(h).some((x, i) => !(Math.abs(x - h.lay[i]) < 1.5));function hold(h) {// held by what can be seen: an empty part (a row's value with nothing in it// yet) has no height, so "moved by less than half its height" below never// held, and Add to PATH on Settings' About slid the view 11px off its top// once the page was a little taller than the window (#2296)const a = h.chain.find(([n]) => atRest(n) && n.offsetHeight) || h.chain.find(([n]) => atRest(n)) || (h.chain.some(([n]) => n.isConnected) ? null : standIn(h));- if (!a) return;+ if (!a) { h.lay = laid(h); return; }const v = h.v, d = onScreen(a[0], v) - a[1];if (Math.abs(d) >= 1) {let want = v.scrollTop + d;@@ -23270,6 +23275,7 @@ function hold(h) {}fitRoom(v);readerLeaves(v);+ h.lay = laid(h);}let holding = false; // one frame loop, whatever the clicks// A window made wider or narrower lays the whole page out again, the sidebar@@ -23351,9 +23357,14 @@ for (const v of document.querySelectorAll(".view")) {if (panning?.v === v) readerScrolls(250);if (performance.now() < purposeUntil || barDrag === v) { fitRoom(v); readerLeaves(v); scrolledFrom.set(v, document.activeElement); return; }const from = v.scrollTop;+ // a click's hold takes what a redraw moved; a scroll with the page laid+ // out as the hold left it is put back as at rest, so the reader's run+ // is theirs a click before it too (issennknight: a profile opened, then+ // wheeled through, held still for 4s)+ const h = held?.v === v && redrawn(held);if (held?.v === v) hold(held);else backToReader(v);- puttingBack(v, from);+ puttingBack(v, from, h);}, { passive: true });}diff --git a/internal/gui/tests/view-wheel-after-click.test.cjs b/internal/gui/tests/view-wheel-after-click.test.cjsnew file mode 100644index 000000000..5061b7236--- /dev/null+++ b/internal/gui/tests/view-wheel-after-click.test.cjs@@ -0,0 +1,151 @@+// Run with Node's test runner and Playwright on the module path; see README.md.+// issennknight on Discord (macOS, trackpad): every page scrolled again, but a+// saved profile opened on the Agents page and then scrolled through often+// stayed where it was. macOS 13's WebKit scrolls a view under a wheel it never+// tells the page of, and the view guard takes a run of such scrolls as the+// reader's only with no click holding: a click holds what it clicked for up+// to 4s, and every scroll in that time was put back. Here the wheel goes+// over the profile just opened, right after the click, heard and unheard:+// the page must follow it down, to its foot and back up, with details longer+// than the window and shorter, and nothing but the view scrolls.+// Chromium and WebKit, a narrow and a wide window, every language.+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 = process.env.MAGPIE_AFTER_CLICK_ASSETS || path.resolve(__dirname, "../assets");+const LANGS = ["en", "zh", "zh-TW", "ja", "de"];+const AGENTS = Array.from({ length: 10 }, (_, i) => ({+ id: "a" + i, name: "Agent " + i, path: "/t/a" + i + ".json", icon: "generic", wired: true,+ fields: [{ key: "model", label: "model", value: "m", options: [{ value: "m", label: "M", ref: "a/m" }] }],+}));+const group = (i) => ({ id: "g" + i, name: "Agent " + i, fields: [{ key: "model", label: "model", value: "magpie/x/m" + i }, { key: "effort", label: "effort", value: "high" }] });+// "long" holds more than a window shows, "short" a few lines+const PROFILES = [+ ...Array.from({ length: 4 }, (_, i) => ({ name: "p" + i, summary: "", agents: [] })),+ { name: "long", summary: "", agents: Array.from({ length: 16 }, (_, i) => group(i)) },+ { name: "short", summary: "", agents: [group(0)] },+];++function server(lang) {+ 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: AGENTS, profiles: PROFILES, settings: { lang, theme: "light", guideHidden: true } });+ if (url.pathname === "/api/providers") return json({ providers: [], gateway: { running: true, window: true } });+ 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)];+ await route.fulfill({ body: await fs.readFile(file), contentType });+ };+}++// the view at rest: its scrollTop the same across a few looks+async function rested(p, view, ms = 3000) {+ let last = NaN, same = 0;+ const until = Date.now() + ms;+ while (Date.now() < until) {+ const t = await view.evaluate((v) => v.scrollTop);+ same = t === last ? same + 1 : 0;+ if (same >= 3) return t;+ last = t;+ await p.waitForTimeout(50);+ }+ return last;+}++const wheels = async (p, n, dy) => { for (let i = 0; i < n; i++) { await p.mouse.wheel(0, dy); await p.waitForTimeout(16); } };+// what scrolled besides the view: the document, and any part of the page+const others = (p) => p.evaluate(() => [document.scrollingElement, ...document.querySelectorAll("#view-agents *")]+ .filter((n) => n.scrollTop > 0).map((n) => n.id || n.className));+// the chip's name: ↻ and × are at its other end+const clickChip = async (p, name) => {+ const b = await p.locator("#profiles .chip", { hasText: new RegExp("^" + name) }).boundingBox();+ await p.mouse.click(b.x + 12, b.y + b.height / 2);+};++const DEAF = `addEventListener("wheel", (e) => e.stopImmediatePropagation(), { capture: true, passive: true });`;+const RUNS = [];+for (const lang of LANGS) for (const width of [420, 1000]) RUNS.push({ lang, width, deaf: true });+RUNS.push({ lang: "en", width: 420, deaf: false }, { lang: "zh", width: 1000, deaf: false });++for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {+ test(engine + ": a wheel right after a click scrolls the view", { timeout: 600000 }, async (t) => {+ assert(["chromium", "webkit"].includes(engine), "BROWSER must be chromium or webkit");+ const browser = await (engine === "webkit" ? webkit : chromium).launch();+ t.after(() => browser.close());+ for (const { lang, width, deaf } of RUNS) {+ await t.test(`${lang}, ${width}px, ${deaf ? "a wheel the page never hears" : "a wheel heard"}`, async () => {+ const ctx = await browser.newContext({ viewport: { width, height: 600 }, reducedMotion: "reduce" });+ const p = await ctx.newPage();+ p.setDefaultTimeout(8000);+ const errors = [];+ p.on("pageerror", (e) => { if (!/^ResizeObserver loop/.test(e.message)) errors.push(e.message); });+ if (deaf) await p.addInitScript(DEAF);+ await p.route("**/*", server(lang));+ const view = p.locator("#view-agents");+ await p.goto("http://magpie.test/?view=agents");+ await p.locator("#view-agents .ag-lead").first().waitFor();+ await p.locator("#profiles .chip").first().waitFor();+ await rested(p, view);+ const r = await view.boundingBox();+ const max = () => view.evaluate((v) => v.scrollHeight - v.clientHeight);++ // down to the profiles at the page's foot, as the reader would+ await p.mouse.move(r.x + r.width / 2, r.y + r.height / 2);+ await wheels(p, 40, 40);+ const foot = await rested(p, view);+ assert(foot >= (await max()) - 1 && foot > 100, `the wheel takes the page to its foot: ${foot} of ${await max()}`);++ // the long profile opened, and wheeled through at once: the page+ // follows, the pointer over the chip and then the details+ await clickChip(p, "long");+ await p.locator(".prof-detail").waitFor();+ const tall = await max();+ assert(tall > foot + 300, `the long profile's details run past the window: ${foot} → ${tall}`);+ await wheels(p, 10, 30);+ const down = await rested(p, view);+ assert(down >= foot + 250, `ten wheels of 30px right after the click scroll the page: from ${foot} to ${down}`);+ // and on to its foot, where the wheel has nothing further to take+ await wheels(p, 40, 40);+ const end = await rested(p, view);+ assert(end >= tall - 1, `the wheel reaches the details' end: ${end} of ${tall}`);+ await wheels(p, 5, 40);+ assert.equal(await rested(p, view), end, "past its end the page stays at its foot");+ await wheels(p, 10, -30);+ const up = await rested(p, view);+ assert(up <= end - 250, `and back up: from ${end} to ${up}`);+ assert.deepEqual(await others(p), [], "nothing but the view scrolls");++ // the short one, opened at the foot once the long one is closed: the+ // details fit in the window, and the page still goes up and down+ // under the wheel+ await p.keyboard.press("Escape");+ await p.locator(".prof-detail").waitFor({ state: "detached" });+ await p.waitForTimeout(1100);+ await wheels(p, 20, 40);+ await rested(p, view);+ const b = await p.locator("#profiles .chip", { hasText: /^short/ }).boundingBox();+ assert(b && b.y > r.y && b.y + b.height < r.y + r.height, "the short profile's chip is in sight");+ await clickChip(p, "short");+ await p.locator(".prof-detail").waitFor();+ const at = await rested(p, view);+ const fits = await p.locator(".prof-detail").evaluate((d) => d.offsetHeight);+ assert(fits < r.height / 2, `the short profile's details fit in the window: ${fits}`);+ await wheels(p, 10, -30);+ const higher = await rested(p, view);+ assert(at > 100 && higher <= Math.max(0, at - 250), `ten wheels up right after the click scroll the page: from ${at} to ${higher}`);+ await wheels(p, 10, 30);+ assert(await rested(p, view) >= Math.min(higher + 250, (await max()) - 1), "and down again");+ assert.deepEqual(await others(p), [], "nothing but the view scrolls");+ assert.deepEqual(errors, []);+ await ctx.close();+ });+ }+ });+}diff --git a/internal/gui/tests/view-wheel-unheard.test.cjs b/internal/gui/tests/view-wheel-unheard.test.cjsindex 005c1a2c7..989bc5718 100644--- a/internal/gui/tests/view-wheel-unheard.test.cjs+++ b/internal/gui/tests/view-wheel-unheard.test.cjs@@ -102,8 +102,9 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",await p.waitForTimeout(300);assert.equal(await rested(p, view), up, "a scroll by code at rest is put back");- // a click holds what it clicked: scrolls by code each frame after it- // are no reader's, and are put back+ // a click holds what it clicked: a scroll by code after it is no+ // reader's, and is put back. (A run of scrolls with nothing redrawn+ // is the reader's, a click before it or not: view-wheel-after-click.)const [x, y] = await p.evaluate(([x, y]) => {const row = window.__clicked = document.elementFromPoint(x, y)?.closest(".row.agent");const b = row?.getBoundingClientRect();@@ -113,7 +114,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",const rowTop = () => p.evaluate(() => window.__clicked.getBoundingClientRect().top);await p.mouse.click(x, y);const at = await rowTop();- await view.evaluate((v) => new Promise((done) => { let n = 0; const step = () => { if (n++ > 30) return done(); v.scrollTop += 4; requestAnimationFrame(step); }; requestAnimationFrame(step); }));+ await view.evaluate((v) => { v.scrollTop += 120; });await rested(p, view);const after = await rowTop();assert(Math.abs(after - at) <= 12, `the row clicked stays: at ${at} after the click, ${after} once at rest`);