Every agent's model. One place. Codex on DeepSeek, Claude Code on Kimi, from the menu bar.
gui: a wheel or coast macOS 13's WebKit never tells the page of still scrolls the view (issenn on Discord)
yetone30d3001a0451
diff --git a/docs/subsystems/gui-shell.md b/docs/subsystems/gui-shell.mdindex 24e9f2933..a0a6e1ec9 100644--- a/docs/subsystems/gui-shell.md+++ b/docs/subsystems/gui-shell.md@@ -374,8 +374,8 @@ covers it in both engines, every language and a narrow window.- Settings' search APIs are asked in their listed order: each API's row (with its keys' row) is dragged as one, or moved with Alt+↑/↓, and has a switch that turns it off without removing its key (#2286). See [the search APIs' order](gateway-routing.md#the-search-apis-order-and-one-switched-off), `searchArrange` in [`app.js`](../../internal/gui/assets/app.js) and `search-order.test.cjs`.- 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. 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 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 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`.- 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 491f22bf9..a55649234 100644--- a/internal/gui/assets/app.js+++ b/internal/gui/assets/app.js@@ -23204,19 +23204,10 @@ function savePrefs(body) {// anchoring), WebKit scrolls a field it focuses to the middle of the view,// and code sets scrollTop.// - What the reader clicks stays where it is on the screen while what the-// click does redraws around it — the part above it grown or shrunk, the-// control itself drawn again, a load come in — till the reader scrolls or-// clicks again, or it has settled. A click is never a scroll: a tab, a-// filter, a day, a toggle leaves the page where it was. When what it does-// leaves the page shorter under it (a list emptied), the view keeps room-// at its foot for it to stay, room that goes as the reader scrolls back.-// A control under what it unrolls (data-unrolls: "Show 7 more") is the-// exception: it goes down with what it opens, and what's held is the-// part it is in, so the rows open downwards rather than the page riding-// up past them. A view at its top stays at its top: what comes in above-// the control there moves it down instead of scrolling itself out of sight,-// as long as that leaves it under the pointer (less than half its height);-// what comes in larger above it (a day's stage on Routing) is scrolled past.+// click does redraws around it, till they scroll or click again or it has+// settled: a click is never a scroll. A page left shorter under it keeps+// room at its foot; a data-unrolls control goes down with what it opens;+// a view at its top stays there (gui-shell.md, "A click never moves").//// Code moves a view only in answer to a click that asks to go somewhere, and// shows that with the reader's event: scrollOnPurpose(e). Called without one@@ -23259,17 +23250,26 @@ function keyboardFocus(e) {if ((r.top < b.top || r.bottom > b.bottom) && scrollOnPurpose(e, 400)) focused.scrollIntoView({ block: "nearest" });}));}-// A wheel or a touch can scroll the view before the page is told of it: the-// browser scrolls off the main thread, and a busy page gets the scroll event-// first and the wheel after (WebKit, a loaded Mac). That scroll was put back-// as no one's, and the reader lost a wheel step. What was put back is kept-// for a moment, and a wheel or touch that came in before it was put back, the-// same way, gives it back to the reader.-let putBack = []; // { v, by: px put back, at }, the last second's+// A wheel or a touch can scroll the view before the page is told of it (the+// browser scrolls off the main thread; WebKit, a loaded Mac): put back as no+// one's, the reader lost a step. What was put back is kept a moment, and a+// wheel or touch made before it, the same way, gives it back.+// 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.+let putBack = [], run = null; // { v, by: px put back, at, h: held }, the last second'sfunction puttingBack(v, from) {- const by = from - v.scrollTop, at = performance.now();+ const by = from - v.scrollTop, at = performance.now(), d = Math.sign(by), h = held?.v === v;putBack = putBack.filter((p) => at - p.at < 1000);- if (Math.abs(by) >= 1) putBack.push({ v, by, at });+ if (Math.abs(by) < 1) return;+ putBack.push({ v, by, at, h });+ if (h) return;+ const mine = putBack.filter((p) => p.v === v && !p.h && Math.sign(p.by) === d);+ if (mine.length < 3 && !(run?.v === v && run.d === d && at - run.at < 1000)) return;+ run = { v, d, at }; putBack = putBack.filter((p) => !mine.includes(p)); flings();+ for (const p of mine) v.scrollTop += p.by;}// Given back is what was put back after the reader's input was made (its// timeStamp is when it was made, not when the page was told) and went thediff --git a/internal/gui/tests/view-wheel-unheard.test.cjs b/internal/gui/tests/view-wheel-unheard.test.cjsnew file mode 100644index 000000000..005c1a2c7--- /dev/null+++ b/internal/gui/tests/view-wheel-unheard.test.cjs@@ -0,0 +1,125 @@+// Run with Node's test runner and Playwright on the module path; see README.md.+// On macOS 13.7.8, whose WebKit is Safari 16.6's (18615), no page of the window+// scrolled, by trackpad or mouse wheel; a trackpad's scroll shook and snapped+// back, and only dragging the bar moved it (issenn on Discord). The view guard+// puts back every scroll outside a window the reader's own events open, and+// that WebKit scrolls a view under a wheel the page is never told of, so each+// scroll was the guard's to put back. Here the page is kept from hearing the+// wheel (a capture listener before app.js's stops it), as there: the wheels+// must still scroll the view all the way they ask, a scroll by code at rest+// is still put back, and so is one a click holds against.+// English and Chinese, Chromium and WebKit.+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_UNHEARD_ASSETS || path.resolve(__dirname, "../assets");+const AGENTS = Array.from({ length: 14 }, (_, 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" }] }],+}));++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: [], settings: { lang, theme: "light" } });+ if (url.pathname === "/api/providers") return json({ providers: [], gateway: { running: true, window: true } });+ 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 page at rest: its scrollTop the same across a few frames' 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 DEAF = `addEventListener("wheel", (e) => e.stopImmediatePropagation(), { capture: true, passive: true });`;++for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {+ test(engine + ": a wheel the page never hears still scrolls the view", { timeout: 120000 }, 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 of ["en", "zh"]) {+ await t.test(lang, async () => {+ const ctx = await browser.newContext({ viewport: { width: 440, height: 620 }, 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); });+ 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 rested(p, view);+ const over = await view.evaluate((v) => v.scrollHeight - v.clientHeight);+ assert(over > 400, `the page must be tall enough to scroll: ${over}`);+ const r = await view.boundingBox();+ await p.mouse.move(r.x + r.width / 2, r.y + r.height / 2);+ assert.equal(await p.evaluate(() => { let heard = 0; addEventListener("wheel", () => heard++, { capture: true }); window.__heard = () => heard; return 0; }), 0);++ // a run of wheels down, as fingers on the pad or a wheel turned+ for (let i = 0; i < 10; i++) { await p.mouse.wheel(0, 20); await p.waitForTimeout(16); }+ // a wheel turned slowly, a notch every 400ms (a run broken on a loaded+ // Mac looks the same): every notch still lands+ const before = await rested(p, view);+ for (let i = 0; i < 5; i++) { await p.mouse.wheel(0, 20); await p.waitForTimeout(400); }+ assert(await rested(p, view) >= before + 95, "five slow notches of 20px land");+ for (let i = 0; i < 5; i++) { await p.mouse.wheel(0, -20); await p.waitForTimeout(400); }+ const down = await rested(p, view);+ assert.equal(await p.evaluate(() => window.__heard()), 0, "the page heard none of the wheels");+ assert(down >= 190, `ten wheels of 20px scroll the view the page never heard them in: left at ${down}`);+ // and back up+ for (let i = 0; i < 6; i++) { await p.mouse.wheel(0, -20); await p.waitForTimeout(16); }+ const up = await rested(p, view);+ assert(up <= down - 110, `six wheels up scroll it back: from ${down} to ${up}`);++ // at rest, past the second a run of the reader's goes on for, a scroll+ // by code is put back as before, twice in a row too+ await p.waitForTimeout(1100);+ await view.evaluate((v) => { v.scrollTop -= 60; });+ await p.waitForTimeout(100);+ await view.evaluate((v) => { v.scrollTop -= 60; });+ 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+ const [x, y] = await p.evaluate(([x, y]) => {+ const row = window.__clicked = document.elementFromPoint(x, y)?.closest(".row.agent");+ const b = row?.getBoundingClientRect();+ return b ? [b.left + 3, b.top + b.height / 2] : [0, 0];+ }, [r.x + r.width / 2, r.y + r.height / 2]);+ assert(x > 0, "an agent's row is in the middle of the window");+ 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 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`);+ assert.deepEqual(errors, []);+ await ctx.close();+ });+ }+ });+}