Skip to content

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

gui: Routing and Usage keep the reader's place when wheeled as they open, heard late or never (issennknight)

yetone0ee31d4736a9
diff --git a/docs/subsystems/gui-shell.md b/docs/subsystems/gui-shell.md
index 73152789c..804c0e924 100644
--- a/docs/subsystems/gui-shell.md
+++ b/docs/subsystems/gui-shell.md
@@ -413,6 +413,8 @@ covers it in both engines, every language and a narrow window.
- 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 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`.
+- A load that lands puts the view back where the reader left it (`show`'s `back` on the page's first reads, the Providers pages' reload after `render`): what it drew may have pulled the view up, the browser clamping it to a page shorter for a moment. While the reader scrolls, the place last heard is late (the page hears of a scroll a frame or more after it, WebKit scrolling on its own thread), and putting it back took their last steps and stopped their coast each time a load landed under the wheel, so Routing and Usage, scrolled as they opened, shook and snapped back (issennknight on Discord, macOS 13). `backAfterLoad` keeps a view that has gone on the way the reader's own scrolls go (`readerWay`, set from each scroll of theirs) as theirs, and puts back only a move against it, which is a redraw's clamp. The browser's scroll anchoring stays on: as data comes in above, it lowers `scrollTop` with what's on the screen still, which the reader never sees, so the test tells a put-back (the view up, what was under the pointer going down with it) from that.
+- Where the window's WebKit scrolls under wheels it never tells the page of (macOS 13's, 16.6), each gesture's first scrolls were put back until three the same way made a run (`puttingBack`), a shake at the start of every gesture, the first on a page just opened included. The first run given back is remembered (`deaf`, kept in localStorage as `magpie.unheardWheels` for the next start); from then on a scroll at rest waits 120ms before it is put back (`waitsBack`), and one more the same way within 80ms (a frame or a few; code's two scrolls in a row come further apart and are both put back, `view-wheel-unheard.test.cjs`), with the page's height the same (no redraw between them), makes it the reader's at once. A lone scroll (a redraw's, code's) is still put back, 120ms later; one under a click's hold is put back at once as before. See `view-open-wheel.test.cjs`, which starts the wheel before the first data, tells the page of each scroll 80ms late or never, and counts every write that moves the view up under the wheel. What the wait puts back is recorded as an at-once put-back is, so a wheel heard later than 120ms still gives it back (`givesBack`).
- 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. 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.
diff --git a/internal/gui/assets/app.js b/internal/gui/assets/app.js
index 1571adcb0..7b0ae8c3f 100644
--- a/internal/gui/assets/app.js
+++ b/internal/gui/assets/app.js
@@ -5986,7 +5986,7 @@ async function loadProvidersNow() {
if (!providers.providers.length && editing === null && !providers.fileError) adding = true;
if (providersPage(view)) {
magpie.call(view, "render", was);
- backToReader($("#view-" + view));
+ backAfterLoad($("#view-" + view));
} else renderProviders();
renderArchive();
providersWhileFetching();
@@ -22871,6 +22871,25 @@ function puttingBack(v, from, h) {
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;
+ if (!deaf) { deaf = true; try { localStorage.setItem("magpie.unheardWheels", "1"); } catch {} }
+}
+// Seen once (a run given back, kept for the next start), a scroll at rest
+// waits a moment before it is put back, and one more the same way within
+// 80ms (a frame or few: code's two scrolls come further apart), nothing laid
+// out anew between them, is the reader's: a gesture
+// starts without three put back first. What it puts back is kept, as at
+// once, for a wheel heard late to give back (issennknight, macOS 13: Routing and
+// Usage shook as they were opened and wheeled)
+let deaf = false;
+try { deaf = localStorage.getItem("magpie.unheardWheels") === "1"; } catch {}
+const waits = new WeakMap();
+function waitsBack(v) {
+ const d = Math.sign(Math.round(v.scrollTop - (readerAt.get(v) ?? 0))), w = waits.get(v);
+ if (!d) return false;
+ clearTimeout(w?.t); waits.delete(v);
+ if (w?.d === d && w.h === v.scrollHeight && performance.now() - w.at < 80) { readerWay.set(v, d); readerLeaves(v); flings(); return true; }
+ waits.set(v, { d, h: v.scrollHeight, at: performance.now(), t: setTimeout(() => { waits.delete(v); if (performance.now() >= purposeUntil && held?.v !== v) { const from = v.scrollTop; backToReader(v); puttingBack(v, from, false); } }, 120) });
+ return true;
}
// 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 the
@@ -23019,6 +23038,15 @@ function backToReader(v) {
if (r.bottom > b.bottom || r.top < b.top) { readerScrolls(1000); guardUntil = purposeUntil; f.scrollIntoView({ block: "nearest" }); }
}
}
+// A load come in puts the view back where the reader left it, a redraw
+// having pulled it up; under a wheel the place last heard is late, and a
+// move the way the reader goes (readerWay) is theirs (gui-shell.md)
+const readerWay = new WeakMap();
+function backAfterLoad(v) {
+ const at = readerAt.get(v);
+ if (!v.hidden && (barDrag === v || performance.now() < purposeUntil && at != null && readerWay.get(v) === Math.sign(Math.round(v.scrollTop - at)))) readerLeaves(v);
+ else backToReader(v);
+}
// Where an element is on the screen in its view. What's held is the element
// clicked or, once it's gone or hidden (drawn again), the nearest still
// there of its neighbours, its parents and theirs; one moving as it plays
@@ -23210,7 +23238,11 @@ for (const v of document.querySelectorAll(".view")) {
v.addEventListener("scroll", () => {
if (v.hidden) return;
if (panning?.v === v) readerScrolls(250);
- if (performance.now() < purposeUntil || barDrag === v) { fitRoom(v); readerLeaves(v); scrolledFrom.set(v, document.activeElement); return; }
+ if (performance.now() < purposeUntil || barDrag === v) {
+ const by = v.scrollTop - (readerAt.get(v) ?? v.scrollTop);
+ if (Math.abs(by) >= 1) readerWay.set(v, Math.sign(by));
+ 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
@@ -23218,6 +23250,7 @@ for (const v of document.querySelectorAll(".view")) {
// wheeled through, held still for 4s)
const h = held?.v === v && redrawn(held);
if (held?.v === v) hold(held);
+ else if (deaf && waitsBack(v)) return;
else backToReader(v);
puttingBack(v, from, h);
}, { passive: true });
@@ -23270,7 +23303,7 @@ async function show(v) {
navSubs();
for (const id of ["agents", "providers", "plugins", "settings", ...magpie.pages()]) $("#view-" + id).hidden = v !== id;
// back to where the reader was in it, and again once it has what it loads
- const back = () => backToReader($("#view-" + v));
+ const back = () => backAfterLoad($("#view-" + v));
requestAnimationFrame(back);
closePicker();
closeAgentModels();
diff --git a/internal/gui/core_budget_test.go b/internal/gui/core_budget_test.go
index 48d165c6c..380832670 100644
--- a/internal/gui/core_budget_test.go
+++ b/internal/gui/core_budget_test.go
@@ -15,8 +15,8 @@ import (
// so a page can't quietly grow back into the core; a change that needs more
// raises them and says why in its commit.
const (
- appScriptBudget = 1_311_735 // app.js: 1,198,239 after Usage left (P2); 1,218,098 with the 10-15 fixes to pages still in the core; 1,232,466 with the provider editor's Advanced fold and every dialog holding its place, the core's own (10-16); 1,250,533 with the quota refresh kept through redraws, the core's own since the tray panel draws it too, plus 1.5% (#2397); 1,269,083 with Free first's option in the provider editor's ROUTINGS, which the Routing page reads too, plus 1.5%; 1,272,726 with the Providers page drawing its last list at once (#1519), the core's page, and the Routing trace's account names read without Object.entries (#1481), plus 1.5%; a dialog growing out of the row that opened it and folding back into it, the core's own since every page's dialogs open through it (10-20); Codex's and Claude Code's own settings moved from Settings into the agent's row on the Agents page, the core's own since the tray panel and the window both draw them (10-20); 1,314,432 with Settings › Privacy's record of what was masked (its summary, the records view and the local model's controls), which belongs to Settings, the core's own, plus 1.5%; 1,336,481 with a provider's Names & levels saying Provider in model names is Settings' and opening it there (joe), and Settings' Image recognition saying where a custom provider's model is marked (nexnull), both in the core's own pages, with no room added (10-23); 1,337,633 with Settings › Models › Replies' Intent classifier timeout (#2934, reyoung), Settings' own row, drawn by waitRow, which the Image generation timeout's row now shares, with no room added; 1,337,735 with the provider editor's link naming a partner's page by its own host (siteHost) instead of usemagpie.ai's /go link, the core's own editor, with no room added (10-23); 1,338,084 with Check in now saying what the press came to (claimed +credits, already today, not available yet) where it said "refreshed" (#3326), the check-in row the tray panel draws too, the core's own, with no room added (10-23); 1,338,929 with a new partner's tile keeping a small dot until it is opened, in the add sheet, the core's own, with no room added (10-23); 1,343,324 with the sidebar's open-page row marked by one shape that moves on a spring (navTopGo), the window's own shell, which every page sits beside, with no room added (10-23); 1,343,465 with a dialog kept centred while its content comes in, until it is pressed (holdModal, every page's dialogs), the core's own, with no room added (10-24); 1,317,486 with what masking did moved out to Insights › Masking (plugins/redact), the budget lowered to it (10-24); 1,321,336 with Codex's one subagent model, its card's square saying plainly what each choice does and a row with a name in its sheet, where two squares read alike (the owner), the Agents page's, which the tray panel draws too, the core's own, with no room added (10-24); 1,321,424 with Settings › Models' Image generation MCP server row beside Image recognition's (JonahFu on X), the two drawn by one helper (mcpRow), Settings' own, with no room added (10-25); 1,321,994 with a provider of the user's set never to rest for a limit (zoecats), the provider editor's Advanced row, the core's own editor, with no room added (10-25); 1,322,289 with Settings › Privacy's Keep a key's form under Mask secrets (Charles Cao on X), Settings' own row, with no room added (10-25); 1,322,537 with no Codex squares beside its named settings rows (the owner), with no room added (10-25); 1,323,401 with the tray panel drawing its last allowances at once and asking for them beside the state (#3160, #3134), the tray panel's, the core's own, and the 4 bytes 84c50f032 added, with no room added (10-25); 1,326,105 with many releases' notes merged into one list by kind, each line with its version (the owner), in the update sheet and What's new, with no room added (10-25); 1,321,319 with Settings › Observability moved out to its plugin (plugins/otel/page.js) and its Langfuse setup there (an X user), the budget lowered to it (10-26); a quota card whose window is used but names no reset no longer saying "Not used yet" (windy on Discord) raised it to 1,321,347, and back to 1,321,319 with Settings' model pickers sharing one row helper (modelOpt) where six kept their own copy, no raise (10-26); 1,325,845 with every slow page's skeletons getting magpie's bird hopping bar to bar (skelBird, the owner after the Plugins page's README), one bird for the window over whatever page or dialog is loading, the core's own, with no room added (10-26); 1,310,129 with Settings › Network and sharing's gateway rows (its port, bare ids, local network, allowed addresses, web pages) moved out to the gateway plugin (plugins/gateway/settings.js), the budget lowered to it (10-27); 1,310,269 with Test models naming the first model that failed and its error in the status line, where it said only how many (ysm119 on Discord), the provider editor's, the core's own, with no room added (10-27); 1,310,460 with Settings › About's Website row linking usemagpie.ai (the owner), Settings' own row, with no room added (10-27); 1,309,669 with a pool's Stop at the caps and Check usage near a cap ticks under a provider's accounts (plugins#349), the core's own editor, its account rows' Remove and add rows each drawn by one helper (forgetOf, addRow), with no room added (10-28); 1,311,681 with Install another agent on the Agents page naming the agents Plugins has (More in Plugins) and opening Plugins at its Agents (the owner), the Agents page's, the core's own, with no room added (10-28); 1,311,735 with More in Plugins in sight while Install another agent is folded (the owner), with no room added (10-29)
- coreScriptBudget = 1_530_861 // every core script: 1,358,034 after Usage left; 1,380,003 with them; 1,405,937 with the fold; 1,426,102 with 10-16's core work (the GitHub list loading, the move to plugins, Settings › Long conversations), plus 1.5% (#2612); 1,447,368 with loadBack, the window's one state read per return, which every page needs and so is the core's own (1,446,845 before it, 155 bytes under), plus 1.5%; OpenCode Zen's card saying OpenCode tells no key its balance adds ~390 bytes inside it; 1,472,589 with the dialog that grows out of its row and the agents' own settings in their rows, on main's 10-20 core work (the Providers page's last list, the Routing trace's names), plus 1.5% (10-20); 1,506,192 with Settings › Privacy's record of what was masked, plus 1.5%; 1,529,393 with the Intent classifier timeout row (#2934), with no room added; 1,529,495 with the editor's partner link host, with no room added; 1,529,844 with Check in now's press summary (#3326), with no room added; 1,530,689 with the new partner tile's dot, with no room added; 1,535,084 with the sidebar's spring, with no room added; 1,549,478 with the context window card's map (tiles by tokens, the default look, the block grid a switch away) and its text view showing an inline image, in context.js, which the Routing page draws as well as Usage, so the core's own, with no room added (10-24); 1,550,768 with a usage card's refresh opening after its text (#840's card, which the tray panel draws too), the Add key spinner, and a dialog kept centred while its content comes in, with no room added (10-24); 1,524,789 with what masking did moved out to Insights › Masking, lowered to it; 1,528,525 with Codex's one subagent model, with no room added (10-24); 1,528,972 with the Image generation MCP server row (JonahFu on X), with no room added (10-25); 1,529,542 with the limit-rest row (zoecats), with no room added (10-25); 1,529,837 with Keep a key's form (Charles Cao on X), with no room added (10-25); 1,530,050 with no Codex squares beside its named settings rows (the owner), with no room added (10-25); 1,530,631 with a plugin's page growing to its README on the dialog's spring instead of in one jump (the owner), the Plugins page's, in plugins.js, with no room added (10-25); 1,533,445 with the context map counting its tokens on as a live request grows, a tile pointed at keeping its tip, a tool's gathered results saying how many and the small files their folder (the owner, after flohoeller's map on X), in context.js, which the Routing page draws as well as Usage, and the 4 bytes 84c50f032 added to app.js (Settings' Version row) without a raise, with no room added (10-25); 1,534,312 with the tray panel's last allowances drawn at once (#3160, #3134), with no room added (10-25); 1,537,016 with many releases' notes merged into one list by kind (the owner), in app.js, with no room added (10-25); 1,542,244 with a plugin's README loading under magpie's bird bouncing down its lines instead of pulsing bars (the owner), the Plugins page's, in plugins.js, with no room added (10-26); 1,542,418 with a page plugin's sidebar tab coming and going as it is installed, switched on or off, or removed, instead of on the Plugins page's next load (the owner), in plugins.js, with no room added (10-26); 1,537,645 with Settings › Observability moved out to plugins/otel, lowered to it (10-26); 1,537,673 with a used window with no reset not "Not used yet" (windy on Discord), and back to 1,537,645 with Settings' model pickers sharing modelOpt (10-26); 1,541,967 with every slow page's skeletons getting magpie's bird (skelBird, the owner), in app.js, the README's bird sharing its drawing and styles, with no room added (10-26); 1,526,251 with Settings' gateway rows moved out to plugins/gateway/settings.js, lowered to it (10-27); 1,526,391 with Test models naming the first failed model and its error (ysm119 on Discord), in app.js, with no room added (10-27); 1,526,556 with About's Website row (the owner), in app.js, with no room added (10-27); 1,526,500 with a pool's cap ticks (plugins#349), in app.js, with no room added (10-28); 1,527,245 with About's Open-source licenses row and dialog (the owner), in app.js, with no room added (10-28); 1,528,076 with the Partners heading's light (the owner), in app.js, with no room added (10-28); 1,530,449 with Install another agent's More in Plugins row (the owner), in app.js, and Plugins opening at its Agents, in plugins.js, with no room added (10-28); 1,530,807 with layout.js measuring the scrollbar into --bar, which every page's right padding takes off so its sides match (the owner), the window's own shell, with no room added (10-28); 1,530,861 with More in Plugins in sight while Install another agent is folded (the owner), in app.js, with no room added (10-29)
+ appScriptBudget = 1_313_704 // app.js: 1,198,239 after Usage left (P2); 1,218,098 with the 10-15 fixes to pages still in the core; 1,232,466 with the provider editor's Advanced fold and every dialog holding its place, the core's own (10-16); 1,250,533 with the quota refresh kept through redraws, the core's own since the tray panel draws it too, plus 1.5% (#2397); 1,269,083 with Free first's option in the provider editor's ROUTINGS, which the Routing page reads too, plus 1.5%; 1,272,726 with the Providers page drawing its last list at once (#1519), the core's page, and the Routing trace's account names read without Object.entries (#1481), plus 1.5%; a dialog growing out of the row that opened it and folding back into it, the core's own since every page's dialogs open through it (10-20); Codex's and Claude Code's own settings moved from Settings into the agent's row on the Agents page, the core's own since the tray panel and the window both draw them (10-20); 1,314,432 with Settings › Privacy's record of what was masked (its summary, the records view and the local model's controls), which belongs to Settings, the core's own, plus 1.5%; 1,336,481 with a provider's Names & levels saying Provider in model names is Settings' and opening it there (joe), and Settings' Image recognition saying where a custom provider's model is marked (nexnull), both in the core's own pages, with no room added (10-23); 1,337,633 with Settings › Models › Replies' Intent classifier timeout (#2934, reyoung), Settings' own row, drawn by waitRow, which the Image generation timeout's row now shares, with no room added; 1,337,735 with the provider editor's link naming a partner's page by its own host (siteHost) instead of usemagpie.ai's /go link, the core's own editor, with no room added (10-23); 1,338,084 with Check in now saying what the press came to (claimed +credits, already today, not available yet) where it said "refreshed" (#3326), the check-in row the tray panel draws too, the core's own, with no room added (10-23); 1,338,929 with a new partner's tile keeping a small dot until it is opened, in the add sheet, the core's own, with no room added (10-23); 1,343,324 with the sidebar's open-page row marked by one shape that moves on a spring (navTopGo), the window's own shell, which every page sits beside, with no room added (10-23); 1,343,465 with a dialog kept centred while its content comes in, until it is pressed (holdModal, every page's dialogs), the core's own, with no room added (10-24); 1,317,486 with what masking did moved out to Insights › Masking (plugins/redact), the budget lowered to it (10-24); 1,321,336 with Codex's one subagent model, its card's square saying plainly what each choice does and a row with a name in its sheet, where two squares read alike (the owner), the Agents page's, which the tray panel draws too, the core's own, with no room added (10-24); 1,321,424 with Settings › Models' Image generation MCP server row beside Image recognition's (JonahFu on X), the two drawn by one helper (mcpRow), Settings' own, with no room added (10-25); 1,321,994 with a provider of the user's set never to rest for a limit (zoecats), the provider editor's Advanced row, the core's own editor, with no room added (10-25); 1,322,289 with Settings › Privacy's Keep a key's form under Mask secrets (Charles Cao on X), Settings' own row, with no room added (10-25); 1,322,537 with no Codex squares beside its named settings rows (the owner), with no room added (10-25); 1,323,401 with the tray panel drawing its last allowances at once and asking for them beside the state (#3160, #3134), the tray panel's, the core's own, and the 4 bytes 84c50f032 added, with no room added (10-25); 1,326,105 with many releases' notes merged into one list by kind, each line with its version (the owner), in the update sheet and What's new, with no room added (10-25); 1,321,319 with Settings › Observability moved out to its plugin (plugins/otel/page.js) and its Langfuse setup there (an X user), the budget lowered to it (10-26); a quota card whose window is used but names no reset no longer saying "Not used yet" (windy on Discord) raised it to 1,321,347, and back to 1,321,319 with Settings' model pickers sharing one row helper (modelOpt) where six kept their own copy, no raise (10-26); 1,325,845 with every slow page's skeletons getting magpie's bird hopping bar to bar (skelBird, the owner after the Plugins page's README), one bird for the window over whatever page or dialog is loading, the core's own, with no room added (10-26); 1,310,129 with Settings › Network and sharing's gateway rows (its port, bare ids, local network, allowed addresses, web pages) moved out to the gateway plugin (plugins/gateway/settings.js), the budget lowered to it (10-27); 1,310,269 with Test models naming the first model that failed and its error in the status line, where it said only how many (ysm119 on Discord), the provider editor's, the core's own, with no room added (10-27); 1,310,460 with Settings › About's Website row linking usemagpie.ai (the owner), Settings' own row, with no room added (10-27); 1,309,669 with a pool's Stop at the caps and Check usage near a cap ticks under a provider's accounts (plugins#349), the core's own editor, its account rows' Remove and add rows each drawn by one helper (forgetOf, addRow), with no room added (10-28); 1,311,681 with Install another agent on the Agents page naming the agents Plugins has (More in Plugins) and opening Plugins at its Agents (the owner), the Agents page's, the core's own, with no room added (10-28); 1,311,735 with More in Plugins in sight while Install another agent is folded (the owner), with no room added (10-29); 1,313,704 with a window whose WebKit scrolls under wheels it never tells of (macOS 13) remembered once seen, a scroll at rest then waiting 120ms for a second the same way within 80ms before it is put back, kept for a late wheel to give back (waitsBack), and a load landing under the wheel keeping the reader's way (backAfterLoad, issennknight), the window's own scroll guard, with no room added (10-29)
+ coreScriptBudget = 1_532_830 // every core script: 1,358,034 after Usage left; 1,380,003 with them; 1,405,937 with the fold; 1,426,102 with 10-16's core work (the GitHub list loading, the move to plugins, Settings › Long conversations), plus 1.5% (#2612); 1,447,368 with loadBack, the window's one state read per return, which every page needs and so is the core's own (1,446,845 before it, 155 bytes under), plus 1.5%; OpenCode Zen's card saying OpenCode tells no key its balance adds ~390 bytes inside it; 1,472,589 with the dialog that grows out of its row and the agents' own settings in their rows, on main's 10-20 core work (the Providers page's last list, the Routing trace's names), plus 1.5% (10-20); 1,506,192 with Settings › Privacy's record of what was masked, plus 1.5%; 1,529,393 with the Intent classifier timeout row (#2934), with no room added; 1,529,495 with the editor's partner link host, with no room added; 1,529,844 with Check in now's press summary (#3326), with no room added; 1,530,689 with the new partner tile's dot, with no room added; 1,535,084 with the sidebar's spring, with no room added; 1,549,478 with the context window card's map (tiles by tokens, the default look, the block grid a switch away) and its text view showing an inline image, in context.js, which the Routing page draws as well as Usage, so the core's own, with no room added (10-24); 1,550,768 with a usage card's refresh opening after its text (#840's card, which the tray panel draws too), the Add key spinner, and a dialog kept centred while its content comes in, with no room added (10-24); 1,524,789 with what masking did moved out to Insights › Masking, lowered to it; 1,528,525 with Codex's one subagent model, with no room added (10-24); 1,528,972 with the Image generation MCP server row (JonahFu on X), with no room added (10-25); 1,529,542 with the limit-rest row (zoecats), with no room added (10-25); 1,529,837 with Keep a key's form (Charles Cao on X), with no room added (10-25); 1,530,050 with no Codex squares beside its named settings rows (the owner), with no room added (10-25); 1,530,631 with a plugin's page growing to its README on the dialog's spring instead of in one jump (the owner), the Plugins page's, in plugins.js, with no room added (10-25); 1,533,445 with the context map counting its tokens on as a live request grows, a tile pointed at keeping its tip, a tool's gathered results saying how many and the small files their folder (the owner, after flohoeller's map on X), in context.js, which the Routing page draws as well as Usage, and the 4 bytes 84c50f032 added to app.js (Settings' Version row) without a raise, with no room added (10-25); 1,534,312 with the tray panel's last allowances drawn at once (#3160, #3134), with no room added (10-25); 1,537,016 with many releases' notes merged into one list by kind (the owner), in app.js, with no room added (10-25); 1,542,244 with a plugin's README loading under magpie's bird bouncing down its lines instead of pulsing bars (the owner), the Plugins page's, in plugins.js, with no room added (10-26); 1,542,418 with a page plugin's sidebar tab coming and going as it is installed, switched on or off, or removed, instead of on the Plugins page's next load (the owner), in plugins.js, with no room added (10-26); 1,537,645 with Settings › Observability moved out to plugins/otel, lowered to it (10-26); 1,537,673 with a used window with no reset not "Not used yet" (windy on Discord), and back to 1,537,645 with Settings' model pickers sharing modelOpt (10-26); 1,541,967 with every slow page's skeletons getting magpie's bird (skelBird, the owner), in app.js, the README's bird sharing its drawing and styles, with no room added (10-26); 1,526,251 with Settings' gateway rows moved out to plugins/gateway/settings.js, lowered to it (10-27); 1,526,391 with Test models naming the first failed model and its error (ysm119 on Discord), in app.js, with no room added (10-27); 1,526,556 with About's Website row (the owner), in app.js, with no room added (10-27); 1,526,500 with a pool's cap ticks (plugins#349), in app.js, with no room added (10-28); 1,527,245 with About's Open-source licenses row and dialog (the owner), in app.js, with no room added (10-28); 1,528,076 with the Partners heading's light (the owner), in app.js, with no room added (10-28); 1,530,449 with Install another agent's More in Plugins row (the owner), in app.js, and Plugins opening at its Agents, in plugins.js, with no room added (10-28); 1,530,807 with layout.js measuring the scrollbar into --bar, which every page's right padding takes off so its sides match (the owner), the window's own shell, with no room added (10-28); 1,530,861 with More in Plugins in sight while Install another agent is folded (the owner), in app.js, with no room added (10-29); 1,532,830 with waitsBack and backAfterLoad (issennknight, macOS 13), the window's own scroll guard, in app.js, with no room added (10-29)
)
func TestCoreScriptBudget(t *testing.T) {
diff --git a/internal/gui/tests/click-scroll.test.cjs b/internal/gui/tests/click-scroll.test.cjs
index d2da2d6d1..ee84c19c7 100644
--- a/internal/gui/tests/click-scroll.test.cjs
+++ b/internal/gui/tests/click-scroll.test.cjs
@@ -290,7 +290,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
const heard = (fn, e) => { try { fn(e); } finally { window.__wheelsHeard++; } };
window.addEventListener = function (type, fn, o) {
if (type !== "wheel") return add.call(this, type, fn, o);
- return add.call(this, type, (e) => (window.__lateWheel ? setTimeout(() => heard(fn, e), 60) : heard(fn, e)), o);
+ return add.call(this, type, (e) => (window.__lateWheel ? setTimeout(() => heard(fn, e), window.__lateBy || 60) : heard(fn, e)), o);
};
});
await reset();
@@ -331,6 +331,27 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
await page.evaluate(() => { window.__lateWheel = false; });
});
+ // A window that has learned of wheels it never hears (macOS 13, or a run
+ // put back on a loaded machine) waits 120ms before it puts a scroll back
+ // (waitsBack). A wheel heard later still than that gives back what was
+ // put back, as it does at once.
+ await t.test("a wheel heard after the wait for unheard wheels is still the reader's", async () => {
+ await reset();
+ await page.evaluate(() => localStorage.setItem("magpie.unheardWheels", "1"));
+ await reset();
+ await page.locator(view).evaluate((v) => { const s = document.createElement("div"); s.style.cssText = "flex:none;height:1600px"; v.append(s); });
+ await page.evaluate(() => { window.__lateWheel = true; window.__lateBy = 250; });
+ const box = await page.locator(view).boundingBox();
+ await page.mouse.move(box.x + box.width / 2, box.y + 60);
+ const scrollTop = () => page.locator(view).evaluate((v) => v.scrollTop);
+ const was = await scrollTop(), n = await page.evaluate(() => window.__wheelsHeard);
+ await page.mouse.wheel(0, 300);
+ await page.waitForFunction((n) => window.__wheelsHeard > n, n);
+ await page.waitForFunction(() => performance.now() >= purposeUntil);
+ assert((await scrollTop()) > was + 100, "the wheel heard 250ms late must scroll the view");
+ await page.evaluate(() => { window.__lateWheel = false; window.__lateBy = 0; localStorage.removeItem("magpie.unheardWheels"); });
+ });
+
assert.deepEqual(errors, [], "page runtime errors");
});
}
diff --git a/internal/gui/tests/view-open-wheel.test.cjs b/internal/gui/tests/view-open-wheel.test.cjs
new file mode 100644
index 000000000..f84eef323
--- /dev/null
+++ b/internal/gui/tests/view-open-wheel.test.cjs
@@ -0,0 +1,190 @@
+// Run with Node's test runner and Playwright on the module path; see README.md.
+// issennknight on Discord (after f92db4cdd): the Routing and Usage pages,
+// scrolled as soon as they were opened, shook and snapped back. Each page
+// puts the view back where the reader left it once what it loads comes in
+// (show()'s back, and the providers' reload drawing a page they show): a
+// redraw may have pulled it up. That ran while the reader was scrolling it
+// too, with the place last heard of, and the page hears of a scroll late
+// (WebKit scrolls on its own thread; a loaded Mac tells the page frames
+// later), so each load that landed under the wheel took the reader's last
+// steps back and stopped their coast. And on macOS 13 (WebKit 16.6, where
+// issennknight is), the page never hears the wheel at all: every gesture's
+// first scrolls were put back until three made a run, a shake as the page
+// was opened and wheeled. Here the first data waits until the wheel is
+// going, the page hears of each scroll 80ms late, or never (learned on the
+// page before, as a real window learns it); the view never goes back up
+// under a wheel going down, in the frames painted nor by a write the frames
+// can't show. Both pages, opened and opened again, every language, narrow
+// and wide, Chromium and WebKit. The browser's scroll anchoring (the view
+// up as data comes in above, what's on the screen still) is not a put-back.
+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_OPEN_WHEEL_ASSETS || path.resolve(__dirname, "../assets");
+const now = new Date();
+const day = [now.getFullYear(), now.getMonth() + 1, now.getDate()].map((n) => String(n).padStart(2, "0")).join("-");
+const at = (i) => new Date(now.getTime() - (i + 1) * 60e3).toISOString();
+const who = { id: "fixture-key", provider: "fixture", name: "Fixture", who: "key-1", kind: "key", model: "model-a", routing: "", used: 0 };
+const routes = Array.from({ length: 12 }, (_, i) => ({ id: 100 - i, seq: 100 - i, time: at(i), agent: "fixture", model: "model-a", provider: "fixture", order: [who],
+ tries: [{ id: who.id, model: "model-a", start: at(i), done: true, status: 200, ms: 1200 }], done: true, status: 200, ms: 1200, tokens: 3000 }));
+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" }] }] }));
+const U = (id) => ({ id, name: id, calls: 10, errors: 0, input: 1000, output: 500, cache_read: 0, cache_write: 0, cost: 0.1 });
+const USAGE = { calls: 140, errors: 0, input: 14000, output: 7000, reasoning: 0, unpriced: 0, cost: 1.4, bucket: "day",
+ series: Array.from({ length: 7 }, (_, i) => ({ label: "d" + i, time: at(i * 1440), calls: 20, input: 2000, output: 1000, cost: 0.2 })),
+ agents: Array.from({ length: 10 }, (_, i) => U("agent" + i)), models: Array.from({ length: 12 }, (_, i) => U("model" + i)), path: "" };
+const QUOTAS = Array.from({ length: 4 }, (_, i) => ({ provider: "p" + i, name: "Vendor " + i, user: "u" + i + "@x.test", plan: "Pro",
+ windows: [{ name: "5h", used: 20 + i, resets: new Date(now.getTime() + 3600e3).toISOString() }, { name: "Week", used: 40, resets: new Date(now.getTime() + 86400e3).toISOString() }] }));
+
+// The first reads a page makes when it opens wait for open(): the reader
+// wheels before they land
+function server(lang, gate) {
+ return async (route) => {
+ const url = new URL(route.request().url());
+ const json = async (data, slow) => { if (slow && gate.on) await gate.wait; return 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", guideHidden: true } });
+ if (url.pathname === "/api/providers") return json({ providers: [], presets: [], excluded: [], gateway: { running: true, window: true } }, true);
+ if (url.pathname === "/api/gateway/trace") {
+ if (url.searchParams.get("wait")) {
+ await new Promise((ok) => setTimeout(ok, 700));
+ const k = gate.traceSeq = (gate.traceSeq || 1) + 1;
+ if (k > 8) return new Promise(() => {});
+ const r = { ...routes[0], id: 100 + k, seq: 100 + k, time: new Date().toISOString() };
+ return route.fulfill({ json: { mine: true, now: new Date().toISOString(), seq: k, totals: { requests: routes.length + k, rerouted: 0, errors: 0 }, routes: [r] } });
+ }
+ return json({ mine: true, now: now.toISOString(), seq: 1, totals: { requests: routes.length, rerouted: 0, errors: 0 }, routes }, true);
+ }
+ if (url.pathname === "/api/gateway/history") return json({ cut: false, days: [{ day, requests: routes.length }], routes: [] }, true);
+ if (url.pathname === "/api/usage/quotas") {
+ if (gate.on) await gate.wait;
+ const n = gate.quotaReads = (gate.quotaReads || 0) + 1;
+ const q = QUOTAS.map((x, i) => ({ ...x, windows: x.windows.map((w) => ({ ...w, used: w.used + n })) }));
+ return route.fulfill({ json: q, headers: { "X-Magpie-Reading": n < 6 ? "1" : "0", "Access-Control-Expose-Headers": "X-Magpie-Reading" } });
+ }
+ if (url.pathname === "/api/usage") return json(USAGE, true);
+ if (url.pathname === "/api/groups") return json({ groups: [], models: [] }, true);
+ if (url.pathname === "/api/plugins") return json({ plugins: [] });
+ if (url.pathname === "/api/agents/cli") return json({ agents: {}, pending: false });
+ 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).catch(() => ""), contentType });
+ };
+}
+
+// the page told of a view's scroll late, as WebKit tells it under load: the
+// view is already where the wheel took it, the page still thinks it where
+// it last heard
+const LATE = `addEventListener("scroll", (e) => {
+ const v = e.target;
+ if (!e.isTrusted || !(v instanceof Element) || !v.classList.contains("view")) return;
+ e.stopImmediatePropagation();
+ setTimeout(() => v.dispatchEvent(new Event("scroll")), 80);
+}, { capture: true });`;
+// macOS 13's WebKit (16.6) scrolls a view under a wheel it never tells the
+// page of: a capture listener before app.js's stops each one, as
+// view-wheel-unheard does
+const DEAF = `addEventListener("wheel", (e) => e.stopImmediatePropagation(), { capture: true, passive: true });`;
+// every time code moves a view up, by how much: the put-backs the frames
+// can't show (one put back before the frame is painted is a step lost)
+const UPS = `{
+ const d = Object.getOwnPropertyDescriptor(Element.prototype, "scrollTop");
+ window.ups = [];
+ Object.defineProperty(Element.prototype, "scrollTop", { get: d.get, configurable: true, set(y) {
+ if (this.classList?.contains("view") && !this.hidden) window.ups.push(d.get.call(this) - y);
+ d.set.call(this, y);
+ } });
+}`;
+// MAGPIE_OPEN_WHEEL_HEARD=late or unheard runs only that half
+const HEARD = process.env.MAGPIE_OPEN_WHEEL_HEARD ? [process.env.MAGPIE_OPEN_WHEEL_HEARD] : ["late", "unheard"];
+const LANGS = ["en", "zh", "zh-TW", "ja", "de"];
+
+for (const engine of ["chromium", "webkit"]) {
+ test(engine + ": a page scrolled as it opens keeps the reader's place when its data lands", { timeout: 900000 }, async (t) => {
+ const browser = await (engine === "webkit" ? webkit : chromium).launch();
+ t.after(() => browser.close());
+ for (const heard of HEARD) for (const lang of LANGS) for (const width of [420, 1000]) for (const name of ["usage", "routing"]) for (const visit of ["opened", "opened again"]) {
+ await t.test(`${name}, ${visit}, wheels ${heard}, ${lang}, ${width}px`, async () => {
+ const ctx = await browser.newContext({ viewport: { width, height: 600 }, reducedMotion: "reduce" });
+ t.after(() => ctx.close());
+ 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(heard === "late" ? LATE : DEAF);
+ await p.addInitScript(UPS);
+ const gate = { on: false };
+ await p.route("**/*", server(lang, gate));
+ await p.goto("http://magpie.test/?view=agents");
+ await p.locator("#view-agents .ag-lead").first().waitFor();
+ await p.waitForTimeout(500);
+ // unheard: the window learns it on the page before, as the reader's
+ // first scroll there teaches it (and it is kept for the next start)
+ if (heard === "unheard") {
+ const a = await p.locator("#view-agents").boundingBox();
+ await p.mouse.move(a.x + a.width / 2, a.y + a.height / 2);
+ for (let i = 0; i < 8; i++) { await p.mouse.wheel(0, 30); await p.waitForTimeout(16); }
+ await p.waitForTimeout(400);
+ assert.equal(await p.evaluate(() => localStorage.getItem("magpie.unheardWheels")), "1", "wheels the page never heard are learned");
+ }
+ const view = p.locator("#view-" + name);
+ // opened again: what it drew the first time is there while it reads again
+ if (visit === "opened again") {
+ await p.locator(`#nav button[data-view="${name}"]`).click();
+ await p.waitForTimeout(1000);
+ await p.locator('#nav button[data-view="agents"]').click();
+ await p.waitForTimeout(300);
+ }
+ let release;
+ gate.wait = new Promise((ok) => { release = ok; });
+ gate.on = true;
+ await p.locator(`#nav button[data-view="${name}"]`).click();
+ await view.waitFor();
+ await p.waitForTimeout(150);
+ // every frame's place, and how far what was under the pointer the
+ // frame before has moved on the screen since
+ const r = await view.boundingBox();
+ const x = r.x + r.width / 2, y = r.y + r.height * 0.6;
+ await view.evaluate((v, [x, y]) => {
+ window.tops = []; window.downs = [];
+ let was = null;
+ const tick = () => {
+ window.tops.push(v.scrollTop);
+ const now = was?.[0].isConnected ? was[0].getBoundingClientRect().top : null;
+ window.downs.push(now == null ? 0 : now - was[1]);
+ const n = document.elementFromPoint(x, y);
+ was = n && v.contains(n) ? [n, n.getBoundingClientRect().top] : null;
+ requestAnimationFrame(tick);
+ };
+ requestAnimationFrame(tick);
+ }, [x, y]);
+ await p.mouse.move(x, y);
+ await p.evaluate(() => { window.ups = []; });
+ for (let i = 0; i < 30; i++) {
+ await p.mouse.wheel(0, 30);
+ await p.waitForTimeout(16);
+ if (i === 6) { gate.on = false; release(); } // the data lands under the wheel
+ }
+ await p.waitForTimeout(1500);
+ const [tops, downs, ups] = await p.evaluate(() => [window.tops, window.downs, window.ups]);
+ // back is the view going up with what was under the pointer going
+ // down with it: not the browser's anchoring (the view up, what's on
+ // screen still), nor a part above growing (what's on screen down,
+ // the view where it was)
+ const back = tops.findIndex((y, i) => i && y < tops[i - 1] - 1 && downs[i] > 1);
+ assert.equal(back, -1, `the view went back up under a wheel going down, ${tops[back - 1]} to ${tops[back]} (frame ${back}): ${tops.map(Math.round).join(" ")}`);
+ // a step of the wheel put back (a redraw's few pixels kept in
+ // place by the browser's anchoring are not one)
+ assert.deepEqual(ups.filter((by) => by > 20).map(Math.round), [], "nothing put the view back up under the wheel: " + tops.map(Math.round).join(" "));
+ assert.ok(tops[tops.length - 1] > 100, "the wheel scrolled the page: " + tops.map(Math.round).join(" "));
+ assert.deepEqual(errors, []);
+ });
+ }
+ });
+}