Skip to content

Every agent's model. One place. Codex on DeepSeek, Claude Code on Kimi, from the menu bar.

gui: every scroller in every stylesheet is held to keep the wheel; Safari 15 too

yetone1d7ca4c6b7de
diff --git a/docs/subsystems/gui-shell.md b/docs/subsystems/gui-shell.md
index 7c5e88ff0..200656422 100644
--- a/docs/subsystems/gui-shell.md
+++ b/docs/subsystems/gui-shell.md
@@ -399,7 +399,7 @@ covers it in both engines, every language and a narrow window.
- 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 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`. The parts `h.lay` measures are those still in the page that scroll with it: a part drawn again since (the Usage page's tabs, the agents' list under an agent opened or closed) is a redraw once, not at every scroll, and a sticky one (Settings' tabs at a narrow width) is left out, as it sits still while the page scrolls; `view-wheel-after-redraw.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`).
-- A box that scrolls inside a page keeps the wheel at its ends: wheeled past its top or foot, the page stays where it was (碳碳双键 on Discord, Requests' list on Usage). `holds` in app.js marks every box between the pointer and its `.view` that scrolls vertically and overflows (`.holds`), on `pointerover` and on each wheel, and app.css gives `.holds` `overscroll-behavior-y: contain` (the Mac's bounce stays, on the box). It is not one CSS rule for every box because Chromium (WebView2, magpie web) holds the wheel in a box told to contain even when it doesn't overflow, and in one that scrolls only sideways, so a short list or a wide table would stop the page. `.holds` is under `:where()`, so a rule that passes the wheel on still does (`.mchips` in a short window, #833). The page itself (`.view`) and the document chain as before. See `inner-scroll-contain.test.cjs`.
+- A box that scrolls inside a page keeps the wheel at its ends: wheeled past its top or foot, the page stays where it was (碳碳双键 on Discord, Requests' list on Usage). `holds` in app.js marks every box between the pointer and its `.view` that scrolls vertically and overflows (`.holds`), on `pointerover` and on each wheel, and app.css gives `.holds` `overscroll-behavior-y: contain` (the Mac's bounce stays, on the box). It is not one CSS rule for every box because Chromium (WebView2, magpie web) holds the wheel in a box told to contain even when it doesn't overflow, and in one that scrolls only sideways, so a short list or a wide table would stop the page. `.holds` is under `:where()`, so a rule that passes the wheel on still does (`.mchips` in a short window, #833). The page itself (`.view`) and the document chain as before. An engine with no `overscroll-behavior` (Safari 15, macOS 12's WebKit until Safari is updated; Safari 16+, WebKitGTK and Chromium have it) gets the same from `compat.js`: a wheel over a `.holds` box at its end in the wheel's direction is cancelled, so there the Mac's bounce at the box's end is lost. A guard in `inner-scroll-contain.test.cjs` builds every rule in every stylesheet under assets that scrolls a box vertically from its own selector, fills it and points at it, and fails naming the file and selector of one that doesn't hold the wheel (a rule that sets `overscroll-behavior` back to auto, or a box `holds` doesn't reach). See `inner-scroll-contain.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`.
- The Usage page's cards and the tray panel's Allowances tab share one order, `settings.UsageOrder` (`byUsageOrder`). In the panel a balance-only card stands where that order puts it, and balances next to each other share one *Balances* grid (`panelBalances`, #1510); none is gathered after the plans. The panel's *Arrange* (`panelArrange`) moves rows in it and hides subscriptions from that tab alone (`settings.PanelUsageHidden`); both save through `POST /api/usage/arrange`, which changes only the field it is sent, and the Settings save keeps both. Hiding is display only: a menu bar cell's card shows though hidden (`panelPeek`). See `TestUsageArrangePanelHidden`, `panel-arrange.test.cjs` and `panel-balance-order.test.cjs`.
diff --git a/internal/gui/assets/app.js b/internal/gui/assets/app.js
index c25815c8f..7b1f66dda 100644
--- a/internal/gui/assets/app.js
+++ b/internal/gui/assets/app.js
@@ -360,6 +360,8 @@ function icon(name, lazy) {
return e;
}
+// a change done: its line, with the agent's notice (a warning) when there is one
+const saidOk = (msg, ms) => state.notice ? status(withNotice(msg, state.notice), "warn", 9000) : status(msg, "ok", ms);
function status(msg, kind = "", ms = kind === "err" ? 8000 : 3500) {
const s = $("#status");
s.textContent = msg;
@@ -1156,9 +1158,7 @@ function connectSwitch(a) {
state = await api("agents/connect/" + a.id, {});
renderAgents();
const msg = connectedSaid(a, state.connected);
- if (state.notice) status(withNotice(msg, state.notice), "warn", 9000);
- else if (msg !== t("{agent} is connected to magpie", { agent: a.name })) status(msg, "ok", 7000);
- else status(msg, "ok");
+ saidOk(msg, msg !== t("{agent} is connected to magpie", { agent: a.name }) ? 7000 : undefined);
} catch (err) {
s.disabled = false;
s.classList.remove("on");
@@ -1753,8 +1753,7 @@ async function guideConnect(a, ev) {
guideBusy = "";
renderAgents();
const msg = connectedSaid(a, state.connected);
- if (state.notice) status(withNotice(msg, state.notice), "warn", 9000);
- else status(msg, "ok", 7000);
+ saidOk(msg, 7000);
} catch (err) {
guideBusy = "";
guideRedraw();
@@ -2262,8 +2261,7 @@ function askDisconnect(a) {
if (agentExpanded === a.id) agentExpanded = null;
renderAgents();
const msg = t(offline ? "Saved settings restored; magpie was removed from {agent}" : "{agent} no longer goes through magpie; its own settings are back", { agent: a.name });
- if (state.notice) status(withNotice(msg, state.notice), "warn", 9000);
- else status(msg, "ok");
+ saidOk(msg);
} catch (err) {
go.disabled = false;
go.classList.remove("busy");
@@ -2300,8 +2298,7 @@ async function reapplyAgent(a, btn) {
renderAgents();
document.querySelector(`.agent[data-id="${CSS.escape(a.id)}"] .field`)?.classList.add("flash");
const msg = t("{agent} goes through magpie again", { agent: a.name });
- if (state.notice) status(withNotice(msg, state.notice), "warn", 9000);
- else status(msg, "ok");
+ saidOk(msg);
} catch (e) {
btn?.classList.remove("busy");
status(e.message, "err");
@@ -4775,8 +4772,7 @@ function ultracodeToggle(a, f) {
state = await api("set", { agent: a.id, field: f.key, value: on ? "" : "on" });
renderAgents();
const msg = t("{agent} ultracode → {value}", { agent: a.name, value: t(on ? "off" : "on") });
- if (state.notice) status(withNotice(msg, state.notice), "warn", 9000);
- else status(msg, "ok");
+ saidOk(msg);
} catch (e) { status(e.message, "err"); }
};
return b;
@@ -5058,8 +5054,7 @@ function effortSeg(a, f) {
// open Claude Code session keeps the level it started with.
function effortSaid(a, f, o) {
const msg = `${a.name} ${t(f.label)} → ${effortName(o)}`;
- if (state.notice) status(withNotice(msg, state.notice), "warn", 9000);
- else status(msg, "ok");
+ saidOk(msg);
}
function renderEffortPicker() {
diff --git a/internal/gui/assets/compat.js b/internal/gui/assets/compat.js
index 841c4a5b5..a07cce9c8 100644
--- a/internal/gui/assets/compat.js
+++ b/internal/gui/assets/compat.js
@@ -33,3 +33,9 @@ if (!Object.hasOwn) {
if (!window.structuredClone) {
window.structuredClone = (v) => (v === undefined ? v : JSON.parse(JSON.stringify(v)));
}
+// Safari 16: overscroll-behavior. A box app.js marks .holds, wheeled past
+// an end, would scroll the page; it keeps the wheel here instead
+if (!CSS.supports("overscroll-behavior-y", "contain")) addEventListener("wheel", (e) => {
+ const b = e.target.closest?.(".holds");
+ if (b && e.deltaY && (e.deltaY < 0 ? b.scrollTop < 1 : b.scrollTop >= b.scrollHeight - b.clientHeight - 1)) e.preventDefault();
+}, { passive: false });
diff --git a/internal/gui/tests/README.md b/internal/gui/tests/README.md
index d0f6831ea..c5f919acb 100644
--- a/internal/gui/tests/README.md
+++ b/internal/gui/tests/README.md
@@ -2565,4 +2565,8 @@ and zh, two sizes), and boxes of each kind added to the same page (calls'
bodies, Sessions' talk, model lists, Library picks, diffs, and a new box
naming no rule). A list too short to scroll and boxes that scroll only
sideways still let the wheel move the page, and the model chips in a short
-window still pass it on (#833). Chromium and WebKit.
+window still pass it on (#833). Every rule in every stylesheet under assets
+that scrolls a box vertically is built from its selector, filled and pointed
+at, and has to hold the wheel; one that doesn't is named by file and
+selector. With the engine made to lack overscroll-behavior (Safari 15),
+compat.js still keeps Requests' list's wheel. Chromium and WebKit.
diff --git a/internal/gui/tests/inner-scroll-contain.test.cjs b/internal/gui/tests/inner-scroll-contain.test.cjs
index d8b49437d..ff2eca841 100644
--- a/internal/gui/tests/inner-scroll-contain.test.cjs
+++ b/internal/gui/tests/inner-scroll-contain.test.cjs
@@ -200,3 +200,171 @@ for (const engine of engines) {
await short.close();
});
}
+
+// The guard: every rule in every stylesheet under assets that makes a box
+// scroll vertically (overflow or overflow-y auto or scroll) is built from
+// its own selector, filled past its height and pointed at, and has to hold
+// the wheel at its ends (overscroll-behavior-y contain). A new scroller
+// held by nothing, or a rule that sets a box's overscroll-behavior back to
+// auto, is red here, named by its file and selector. The page itself
+// (.view) is the one box that chains as before.
+const PAGES = new Set([".view", "body.window #view-usage", "body.window #view-routing"]);
+// a selector as the elements it names, one per compound, the last the box:
+// :where() and :is() take their first choice; :not() and other
+// pseudo-classes are left out
+function compounds(sel) {
+ const out = [];
+ let cur = "", depth = 0, comb = null;
+ const flush = () => { if (cur) { out.push({ comb: comb || " ", text: cur }); cur = ""; comb = null; } };
+ for (const ch of sel.trim()) {
+ if (ch === "(" || ch === "[") depth++;
+ else if (ch === ")" || ch === "]") depth--;
+ if (!depth && /\s/.test(ch)) { flush(); continue; }
+ if (!depth && /[>+~]/.test(ch)) { flush(); comb = ch; continue; }
+ cur += ch;
+ }
+ flush();
+ return out.map(({ comb, text }) => {
+ text = text.replace(/:(?:where|is)\(\s*([^,()]+)[^()]*\)/g, "$1").replace(/:not\([^()]*\)/g, "").replace(/::?[a-z-]+(\([^()]*\))?/g, "");
+ return {
+ comb,
+ tag: /^[a-z][a-z0-9-]*/i.exec(text)?.[0] || "div",
+ id: /#([\w-]+)/.exec(text)?.[1],
+ cls: [...text.matchAll(/\.([\w-]+)/g)].map((m) => m[1]),
+ attrs: [...text.matchAll(/\[([\w-]+)(?:[~|^$*]?=["']?([^"'\]]*)["']?)?\]/g)].map((m) => [m[1], m[2] ?? ""]),
+ };
+ });
+}
+// the box a selector names, built at the foot of the page, filled past
+// its height and pointed at: what it holds
+function tryBox({ parts }) {
+ const stage = document.createElement("div");
+ stage.style.cssText = "flex:none;position:relative";
+ document.querySelector("#view-routing").append(stage);
+ const added = [];
+ let at = stage, box = null;
+ for (const p of parts) {
+ if (p.tag === "html") continue;
+ if (p.tag === "body") { for (const c of p.cls) if (!document.body.classList.contains(c)) { document.body.classList.add(c); added.push(c); } continue; }
+ const e = document.createElement(p.tag);
+ if (p.id) e.id = p.id;
+ e.classList.add(...p.cls);
+ for (const [k, v] of p.attrs) e.setAttribute(k, v);
+ if ((p.comb === "+" || p.comb === "~") && at !== stage) at.after(e); else at.append(e);
+ at = box = e;
+ }
+ const done = (r) => { stage.remove(); for (const c of added) document.body.classList.remove(c); return r; };
+ if (!box) return done({ skip: "names no element" });
+ // its size, so it overflows wherever it sits, and shown
+ for (const [k, v] of [["height", "200px"], ["min-height", "0"], ["max-height", "200px"]]) box.style.setProperty(k, v, "important");
+ for (let e = box; e !== stage; e = e.parentElement) if (getComputedStyle(e).display === "none") e.style.setProperty("display", "block", "important");
+ if (box.tagName === "TEXTAREA") box.value = Array.from({ length: 60 }, (_, i) => "line " + i).join("\n");
+ else for (let i = 0; i < 40; i++) {
+ const row = document.createElement(/^[UO]L$/.test(box.tagName) ? "li" : "div");
+ row.style.cssText = "display:block;flex:0 0 100%;width:100%;height:28px";
+ row.textContent = "row " + i;
+ box.append(row);
+ }
+ const overflowY = getComputedStyle(box).overflowY, overflows = box.scrollHeight > box.clientHeight + 1;
+ box.dispatchEvent(new PointerEvent("pointerover", { bubbles: true, composed: true }));
+ return done({ overflowY, overflows, overscroll: getComputedStyle(box).overscrollBehaviorY });
+}
+
+for (const engine of engines) {
+ test(`${engine}: every scroller in every stylesheet holds the wheel at its ends`, async () => {
+ const browser = await launch(engine);
+ try {
+ const page = await browser.newPage({ viewport: { width: 1300, height: 800 } });
+ page.setDefaultTimeout(5000);
+ await page.route("**/*", serve("en"));
+ await page.goto("http://magpie.test/?view=routing");
+ await page.locator("#view-routing .rt-req").nth(39).waitFor();
+ // every stylesheet under assets, added where the page doesn't link it
+ const sheets = (await fs.readdir(assets, { recursive: true })).map((f) => f.split(path.sep).join("/")).filter((f) => f.endsWith(".css")).sort();
+ await page.evaluate((files) => {
+ const have = new Set([...document.styleSheets].map((s) => s.href && new URL(s.href).pathname.slice(1)));
+ return Promise.all(files.filter((f) => !have.has(f)).map((f) => new Promise((ok) => {
+ const l = document.createElement("link");
+ l.rel = "stylesheet"; l.href = f; l.onload = l.onerror = ok;
+ document.head.append(l);
+ })));
+ }, sheets);
+ // the rules that scroll a box vertically, each selector of a list
+ const rules = await page.evaluate(() => {
+ const out = [];
+ const walk = (list, file, media) => {
+ for (const r of list) {
+ if (r instanceof CSSStyleRule) {
+ if (/auto|scroll|overlay/.test(r.style.overflowY)) for (const sel of r.selectorText.split(/,(?![^(]*\))/)) out.push({ file, sel: sel.trim(), media });
+ } else if (r.cssRules) walk(r.cssRules, file, r.media ? r.media.mediaText : r.conditionText || media);
+ }
+ };
+ for (const s of document.styleSheets) if (s.href) walk(s.cssRules, new URL(s.href).pathname.slice(1), "");
+ return out;
+ });
+ const files = new Set(rules.map((r) => r.file));
+ for (const f of ["app.css", "plugins/routing/routing.css", "plugins/sessions/sessions.css", "plugins/library/library.css"]) assert.ok(files.has(f), `scrollers read from ${f}: ${[...files]}`);
+
+ const bad = [], held = [];
+ for (const r of rules) {
+ if (PAGES.has(r.sel.replace(/\s+/g, " "))) continue;
+ const name = `${r.file}: ${r.media ? "@media " + r.media + " " : ""}${r.sel}`;
+ // a rule under @media is tried at a size it holds for
+ if (r.media) {
+ let fits = false;
+ for (const [width, height] of [[1300, 800], [600, 800], [1300, 560], [360, 640]]) {
+ await page.setViewportSize({ width, height });
+ if (await page.evaluate((m) => matchMedia(m).matches, r.media)) { fits = true; break; }
+ }
+ if (!fits) { bad.push(`${name}: no window size here that its @media holds for`); continue; }
+ }
+ const got = await page.evaluate(tryBox, { parts: compounds(r.sel) });
+ await page.setViewportSize({ width: 1300, height: 800 });
+ if (got.skip) bad.push(`${name}: ${got.skip}`);
+ else if (!/auto|scroll|overlay/.test(got.overflowY)) bad.push(`${name}: built from its selector, but the rule didn't take (overflow-y ${got.overflowY})`);
+ else if (!got.overflows) bad.push(`${name}: filled, but doesn't overflow`);
+ else if (got.overscroll !== "contain") bad.push(`${name}: overscroll-behavior-y ${got.overscroll}, so the wheel at its ends moves the page`);
+ else held.push(name);
+ }
+ assert.deepEqual(bad, [], `${held.length} scrollers hold the wheel; these don't`);
+ assert.ok(held.length >= 30, `scrollers checked: ${held.length}`);
+ } finally {
+ await browser.close();
+ }
+ });
+}
+
+// Safari 15 (macOS 12's WebKit unless Safari was updated, #220) has no
+// overscroll-behavior: compat.js keeps the wheel at a held box's ends
+// itself. Here the engine is made to lack it: CSS.supports says no and
+// every box's overscroll-behavior is auto.
+for (const engine of engines) {
+ test(`${engine}: without overscroll-behavior, Requests' list still keeps the wheel at its ends`, async () => {
+ const browser = await launch(engine);
+ try {
+ const ctx = await browser.newContext({ viewport: { width: 900, height: 560 }, reducedMotion: "reduce" });
+ await ctx.addInitScript(() => {
+ const supports = CSS.supports.bind(CSS);
+ CSS.supports = (...a) => !/overscroll/.test(a.join(" ")) && supports(...a);
+ document.addEventListener("DOMContentLoaded", () => document.head.append(Object.assign(document.createElement("style"), { textContent: "* { overscroll-behavior: auto !important; }" })));
+ });
+ const page = await ctx.newPage();
+ page.setDefaultTimeout(5000);
+ await page.route("**/*", serve("en"));
+ await page.goto("http://magpie.test/?view=routing");
+ const view = page.locator("#view-routing");
+ await page.locator("#view-routing .rt-req").nth(39).waitFor();
+ const list = page.locator("#view-routing .rt-reqs").first();
+ assert.equal(await list.evaluate((l) => getComputedStyle(l).overscrollBehaviorY), "auto", "the engine is made to lack it");
+ await heldAtEnds(page, view, list, "the requests' list");
+ // the page's own wheel still moves it, over its gutter
+ const vb = await view.boundingBox(), before = await view.evaluate((v) => v.scrollTop);
+ await page.mouse.move(vb.x + 3, vb.y + vb.height / 2);
+ await page.mouse.wheel(0, 200);
+ await page.waitForTimeout(400);
+ assert.notEqual(await view.evaluate((v) => v.scrollTop), before, "the page itself still scrolls");
+ } finally {
+ await browser.close();
+ }
+ });
+}