Every agent's model. One place. Codex on DeepSeek, Claude Code on Kimi, from the menu bar.
gui: the sidebar's open page moves from row to row on a spring, as iOS's selection does
yetone17a2b00efba5
diff --git a/docs/subsystems/gui-shell.md b/docs/subsystems/gui-shell.mdindex bdea3c79c..16feb1b34 100644--- a/docs/subsystems/gui-shell.md+++ b/docs/subsystems/gui-shell.md@@ -16,7 +16,7 @@ three.| API and assets | `Handler` serves `assets/` (embedded with `//go:embed assets`) and the `/api/*` routes, such as `/api/state`, `/api/set` and `/api/agents/{action}/{id}`. `held` lets one API request's reads share one catalog build (`provider.Hold`), and drops it after any write. `revalidated` and `versionedPage` name each script by its content hash, so a cache never serves an old `app.js` under a new page; a file asked for under its current hash (`?v=`) is cached for good (`immutable`), anything else is revalidated by its ETag. | [`api.go`](../../internal/gui/api.go) || Browser mode | `StartWeb` serves the page and the gateway for `magpie web`. The browser signs in with a run key in a link. Gateway mode shows Providers, Gateway, Routing, Usage, Sessions, Plugins and Settings on a machine that is only a gateway. `webHandler` gzips the page's text files and the API's JSON for a browser that takes gzip (`webCompressed`, with a `-gzip` ETag that still answers 304); the app's own windows read the page in-process and get it uncompressed. | [`web.go`](../../internal/gui/web.go), [`gatewaymode.go`](../../internal/gui/gatewaymode.go) || The page | `app.js` keeps one state object per view and renders it into a list, with no framework. The views have their own files: `plugins.js` and `context.js`, and those a plugin adds under `assets/plugins/<id>/` (the Gateway, Sessions, Library, Routing and Usage pages, see [plugin runtime](plugin-runtime.md)) (Usage's Context tab, and the context window card the Routing page draws under a request's story, fed by `/api/context` in `context.go`, which scores and tags each agent; clicking a part, a cell or an item opens its text from `/api/context/text`, the last 10 requests' masked bodies in memory (`openCtxText`), rendered 100 items and 20000 characters at a time; its "Tuned for you" cards are fed by `/api/tune` in `tune.go`, see [agent wiring](agent-wiring.md)). Strings go through `t()` with translations in `i18n.js`, and a plugin's own in its `i18n.js` (zh, zh-TW, ja and de; the English text is the key and the fallback). zh-TW is Traditional Chinese with Taiwan's words; a system language of zh-TW, zh-HK, zh-MO or any zh-Hant picks it, and the tray menu and notifications follow (`trayLang`). Dropdowns use `openProtoMenu`. Every app menu (`openProtoMenu`, `openRowMenu`, `openSessCombo`) is placed by `placeMenu`: under its anchor, or over it when the window runs out below; one that fits neither way takes the larger room, its height held to it, and scrolls inside itself, and a scroll inside a menu doesn't close it (#1437, `removed-groups-menu-scroll.test.cjs`). The highest any popover goes is `popTop`: 8px under `header.top` on a Mac window, where the traffic lights are drawn over the page, and 8px from the top elsewhere; `placeMenu`, the field picker's `placePop` (which also holds `#pop`'s height to that room) and an agent's model list (`openAgentModels`) all use it (#1573, `popover-mac-chrome.test.cjs`). Scrolling is done only by `scrollOnPurpose(e)` with the reader's event. | [`assets/app.js`](../../internal/gui/assets/app.js), [`assets/i18n.js`](../../internal/gui/assets/i18n.js) |-| Window navigation | In the window from 1024 points wide (`SIDE_AT`, the same width as app.css's `side-nav` rules), `layoutNav` moves the brand, the pages (`#nav`) and Settings into the sidebar (`#side`): the pages in four groups (Work, Models, Insights, Extend; a group none of whose pages shows, as in gateway mode, leaves out its name), the gateway's address at its foot (`sideGwRead`, read from `/api/providers` only while there is a sidebar), and the header a breadcrumb (`renderCrumb`). A page whose head holds only its tools (Library, Plugins, Settings) has them in the title bar after the breadcrumb, `tools` setting the room between it and the window's own buttons. When they don't fit there the tools show their icons alone (`tools-tight`; each keeps its name as `aria-label` and in its tooltip), then the breadcrumb drops its leading parts, and last the page's name is cut at its end, so no tool lies over the title (#2625, `title-bar-tools.test.cjs`). The open page's own tabs (`NAV_SUBS`: Usage, Library, Plugins, Settings) are listed under it as `.nav-s` rows (`role="tab"`, `data-of` the page tab's id) and the page's strip is hidden; a row's click clicks that tab at once, the selection (`.nav-hl`) having set off as the row was pressed (`navSubGlide`; back if the press leaves the row), and is the list's only shape: a row hovered or pressed has no ground of its own, and a `MutationObserver` draws the list again when the strip changes. A page's tabs share its one scroll, so a row that picks another tab opens it at its top (`scrollOnPurpose` with the row's click); the tab already open, picked again, leaves the page where it is (`sidebar-tab-top.test.cjs`). The list opens and folds with an iOS-like spring (`navSubEnter`, `navSubLeave`; none under reduced motion), and a folding list is out of reach at once. Narrower, the page beside a sidebar would be narrower than Usage's requests table needs (768 points), so they go back into the header's row, as a Mac sidebar gives way in a narrow window. At every width the reader can pick the sidebar or the header's tabs from the title bar's button (`#sideToggle`, ⌃⌘S or Ctrl+Shift+S; `toggleSideNav`), kept in localStorage `magpie.navLayout` (`side` or `top`) and so laid out from the first frame; none picked, the sidebar comes from `SIDE_AT`. Picked in a narrow window the sidebar is narrower (184 points under 860), and magpie web on a phone keeps its own tab bar and has no button. The two layouts trade places in a view transition (`navMorph`, app.css `.nav-morph`): the sidebar slides, each page's tab flies to its place in the other, and the page slides as one (its old image dropped, so no line prints twice); without view transitions, under reduced motion, or in the Linux app the change is at once: WebKitGTK with compositing off (`WEBKIT_DISABLE_COMPOSITING_MODE`, which `webkit_linux.go` sets under Wayland) crashes in a view transition. Elsewhere a transition still going after `MORPH_MAX` (1.5s) is skipped, so a webview that never ends one can't leave the window on the old layout's picture. See `side-toggle.test.cjs`. A window made wider or narrower drops what a click held (`heldWidth`): the page laid out again isn't the click's doing. The reader's own place is kept instead for a second while the page is laid out again (`relaid`, a `ResizeObserver` on the open page's parts calling `backToReader`): crossing `SIDE_AT` the browser clamps the scroll to each layout it passes through, and the page ended short of its foot (#1672, `text-size.test.cjs`). See `sidebar.test.cjs`. A sidebar longer than a short window keeps no scroll bar beside its pages: the native bars of `.side-scroll` and `.side-foot` are hidden, and `sideBars` lays a thin bar over each box's edge that shows while it scrolls, fades about a second after it stops (kept while hovered or dragged), can be dragged or clicked to page, and is gone when the box fits, the same in WebKit, WebView2 and WebKitGTK. See `sidebar-overlay-scrollbar.test.cjs`. The window opens on the page the reader last left, as a Mac app comes back as it was (molvqingtai and lc on Discord): `show` keeps the page in localStorage `magpie.lastView` (which the app's webview keeps across restarts, as it keeps `magpie.navLayout`), and `keptView` opens it at start. A page asked for in the address (`?view=`, the tray's links, a reload) wins, Agents too; a kept name that is no page opens the first page, and one gateway mode leaves out opens Providers (`show`). Opening on it scrolls nothing. See `last-page.test.cjs`. | [`assets/app.js`](../../internal/gui/assets/app.js), [`assets/app.css`](../../internal/gui/assets/app.css) |+| Window navigation | In the window from 1024 points wide (`SIDE_AT`, the same width as app.css's `side-nav` rules), `layoutNav` moves the brand, the pages (`#nav`) and Settings into the sidebar (`#side`): the pages in four groups (Work, Models, Insights, Extend; a group none of whose pages shows, as in gateway mode, leaves out its name), the gateway's address at its foot (`sideGwRead`, read from `/api/providers` only while there is a sidebar), and the header a breadcrumb (`renderCrumb`). A page whose head holds only its tools (Library, Plugins, Settings) has them in the title bar after the breadcrumb, `tools` setting the room between it and the window's own buttons. When they don't fit there the tools show their icons alone (`tools-tight`; each keeps its name as `aria-label` and in its tooltip), then the breadcrumb drops its leading parts, and last the page's name is cut at its end, so no tool lies over the title (#2625, `title-bar-tools.test.cjs`). The open page's own tabs (`NAV_SUBS`: Usage, Library, Plugins, Settings) are listed under it as `.nav-s` rows (`role="tab"`, `data-of` the page tab's id) and the page's strip is hidden; a row's click clicks that tab at once, the selection (`.nav-hl`) having set off as the row was pressed (`navSubGlide`; back if the press leaves the row), and is the list's only shape: a row hovered or pressed has no ground of its own, and a `MutationObserver` draws the list again when the strip changes. A page's tabs share its one scroll, so a row that picks another tab opens it at its top (`scrollOnPurpose` with the row's click); the tab already open, picked again, leaves the page where it is (`sidebar-tab-top.test.cjs`). The list opens and folds with an iOS-like spring (`navSubEnter`, `navSubLeave`; none under reduced motion), and a folding list is out of reach at once. The open page's own row is marked the same way, by one shape (`.nav-top-hl`, the rows' own ground given up to it, hovered or pressed too) that `navTopGo` moves to the row picked on a damped spring, as iOS moves a selection (`NAV_SPRING`, SwiftUI's response 0.42s and damping 0.84; `navTopStep` steps it each frame): it sets off as the row is pressed and comes back if the press leaves the row or the page isn't left, turns with the speed it has when the press changes its mind, and follows its row while the list above it folds, landing where the row ends up. It is put in place, not sent, when the window opens on a page or the rows move under it at rest (a `ResizeObserver`), is away while Settings is open (it has its own selection at the foot), comes back fading in on its row, jumps under reduced motion, and isn't drawn in the header's tabs, which have their `.thumb`. `#nav` is `position: relative` in the sidebar for it, so `.seg`'s centring `left` and `top` are reset. See `sidebar-glide.test.cjs`. Narrower, the page beside a sidebar would be narrower than Usage's requests table needs (768 points), so they go back into the header's row, as a Mac sidebar gives way in a narrow window. At every width the reader can pick the sidebar or the header's tabs from the title bar's button (`#sideToggle`, ⌃⌘S or Ctrl+Shift+S; `toggleSideNav`), kept in localStorage `magpie.navLayout` (`side` or `top`) and so laid out from the first frame; none picked, the sidebar comes from `SIDE_AT`. Picked in a narrow window the sidebar is narrower (184 points under 860), and magpie web on a phone keeps its own tab bar and has no button. The two layouts trade places in a view transition (`navMorph`, app.css `.nav-morph`): the sidebar slides, each page's tab flies to its place in the other, and the page slides as one (its old image dropped, so no line prints twice); without view transitions, under reduced motion, or in the Linux app the change is at once: WebKitGTK with compositing off (`WEBKIT_DISABLE_COMPOSITING_MODE`, which `webkit_linux.go` sets under Wayland) crashes in a view transition. Elsewhere a transition still going after `MORPH_MAX` (1.5s) is skipped, so a webview that never ends one can't leave the window on the old layout's picture. See `side-toggle.test.cjs`. A window made wider or narrower drops what a click held (`heldWidth`): the page laid out again isn't the click's doing. The reader's own place is kept instead for a second while the page is laid out again (`relaid`, a `ResizeObserver` on the open page's parts calling `backToReader`): crossing `SIDE_AT` the browser clamps the scroll to each layout it passes through, and the page ended short of its foot (#1672, `text-size.test.cjs`). See `sidebar.test.cjs`. A sidebar longer than a short window keeps no scroll bar beside its pages: the native bars of `.side-scroll` and `.side-foot` are hidden, and `sideBars` lays a thin bar over each box's edge that shows while it scrolls, fades about a second after it stops (kept while hovered or dragged), can be dragged or clicked to page, and is gone when the box fits, the same in WebKit, WebView2 and WebKitGTK. See `sidebar-overlay-scrollbar.test.cjs`. The window opens on the page the reader last left, as a Mac app comes back as it was (molvqingtai and lc on Discord): `show` keeps the page in localStorage `magpie.lastView` (which the app's webview keeps across restarts, as it keeps `magpie.navLayout`), and `keptView` opens it at start. A page asked for in the address (`?view=`, the tray's links, a reload) wins, Agents too; a kept name that is no page opens the first page, and one gateway mode leaves out opens Providers (`show`). Opening on it scrolls nothing. See `last-page.test.cjs`. | [`assets/app.js`](../../internal/gui/assets/app.js), [`assets/app.css`](../../internal/gui/assets/app.css) || Settings › Privacy | The page opens on what masking kept from vendors (`drawMaskObs` in app.js, fed by `/api/masking/summary`): the values masked over 7 or 30 days with a chart of the days, the kinds, what only the local model found, agents to providers, and the values masked most, each shown only while pointed at (`maskTip`, `/api/masking/value`, which says it is gone after a restart). Its records (`drawMaskRecs`, `/api/masking/records` and `/api/masking/record`) take the page's place, filtered by kind, finder, agent or provider, a day at a time, each opening on the text the vendor saw with its placeholders marked. `maskedBadge`, on the Gateway page's recent calls and the Routing page's log, opens a request's own record (`openMaskRecord`), in amber with the count sent as written when every value found was on Warn. Below the card, *What to mask*, *How it's found* (the rules, always on while anything is masked, and the local model on top of them), *When a value is found* (Mask, Warn or Block per kind, the secret kinds first and the personal ones behind *Show all kinds*, and the *Never mask* list; `renderMaskActions`), *Try it* (`renderMaskTry`, the text as the vendor would get it from `/api/masking/preview`, kept in no storage) and *Sharing*. See [gateway routing](gateway-routing.md) for what is recorded. | [`assets/app.js`](../../internal/gui/assets/app.js), [`masking.go`](../../internal/gui/masking.go) || Built-in plugins | Plugins › Built-in, the page's first tab (`drawBuiltin` in `plugins.js`, rows by `renderBuiltins` in `app.js`), lists magpie's built-in plugins, each with a name, a line on what it is and a switch: Routing groups, Library, Observability, Sessions, Warm-up and check-in, and the Gateway and Routing pages (Essential). A plugin on with settings has their rows under its row, drawn from its schema by the kernel's `ui.form`, and a change posts `{id, config}`. The Gateway page is drawn by its plugin's own scripts through the window's kernel (`kernel.js`, `assets/plugins/gateway/`); see the [plugin runtime](plugin-runtime.md), "The window's kernel". They are `plugins/*` registered with the [plugin runtime](plugin-runtime.md); `GET /api/plugins/builtin` says each one (`builtinJSON`: on is active, the user's own choice, what of it is in use) and `POST {id, on}` (or `{id, config}`) writes plugins.yml. A page marks what goes with a plugin `data-feature="<id>"`. Off, `featureStyle` hides everything so marked (rows drawn later too), `navHides` leaves its page's tab out of the sidebar and the header, `show` opens Agents for an address kept for it, and `setSetTab`, `partShows` and `findSettings` leave its Settings tab and rows out, of the search too. One in use stays on: its switch is disabled and the row says what uses it, and the POST refuses it off. A plugins.yml that doesn't parse is said above the list and no switch moves. `boot.js` says which are off (`featuresOff`) and their settings (`pluginConfig`) before the first paint, and `settings.builtins` carries the list on every state read. The TUI doesn't follow them. See `builtins.test.cjs`, `builtins_test.go`. | [`builtins.go`](../../internal/gui/builtins.go), [`assets/plugins.js`](../../internal/gui/assets/plugins.js), [`assets/app.js`](../../internal/gui/assets/app.js) || No GUI build | `-tags nogui` builds magpie without the GUI: `hasGUI` is false and `runGUI` says to use `magpie tui`. The files of `internal/gui` that need Wails build under `!nogui`. | [`gui_off.go`](../../internal/cli/gui_off.go) |diff --git a/internal/gui/assets/app.css b/internal/gui/assets/app.cssindex e1c29aa37..80a191892 100644--- a/internal/gui/assets/app.css+++ b/internal/gui/assets/app.css@@ -374,7 +374,7 @@ body.window:not(.mac):not(.linux):not(.web) .side-top { height: 10px; }.side-bar > i { position: absolute; right: 2px; top: 0; width: 6px; min-height: 24px; border-radius: 3px; background: var(--muted); opacity: .55; transition: width .15s ease, opacity .15s ease; touch-action: none; }.side-bar:hover > i, .side-bar.drag > i { width: 8px; opacity: .75; border-radius: 4px; }@media (prefers-reduced-motion: reduce) { .side-bar, .side-bar > i { transition: none; } }-body.side-nav #nav { position: static; transform: none; display: flex; flex-direction: column; gap: 1px; padding: 0; border-radius: 0; }+body.side-nav #nav { position: relative; left: auto; top: auto; transform: none; display: flex; flex-direction: column; gap: 1px; padding: 0; border-radius: 0; }body.side-nav .nav-gl { display: block; padding: 14px 8px 4px; font-size: 11px; font-weight: 500; letter-spacing: .04em; color: var(--muted); }body.side-nav .nav-gl:first-child { padding-top: 2px; }body.side-nav :is(#nav button[data-view], #prefs) {@@ -385,6 +385,15 @@ body.side-nav :is(#nav button[data-view], #prefs) {body.side-nav :is(#nav button[data-view], #prefs) > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; }body.side-nav :is(#nav button[data-view], #prefs):hover:not(.on) { background: var(--pill); color: var(--fg); }body.side-nav :is(#nav button[data-view], #prefs).on { background: var(--card); color: var(--fg); box-shadow: var(--seg-edge); font-weight: 500; }+/* the open page's row: one shape that moves from row to row on a spring+ (app.js navTopGo), the rows' own ground given up to it. As with the+ sub-rows', a row hovered or pressed has no ground of its own, which+ would lie over the shape as it comes */+.nav-top-hl { display: none; }+body.side-nav #nav > .nav-top-hl:not([hidden]) { display: block; position: absolute; z-index: 0; top: 0; left: 0; right: 0; height: 30px; border-radius: 7px; background: var(--card); box-shadow: var(--seg-edge); pointer-events: none; will-change: transform; }+body.side-nav #side #nav.hl-on button[data-view]:is(.on, :hover, :active) { background: transparent; box-shadow: none; }+body.side-nav #nav.hl-on button[data-view] { transition: color .22s var(--ease); }+body.side-nav #nav.hl-on button[data-view] .nav-ic { transition: color .22s var(--ease); }body.side-nav .nav-ic { display: block; flex: none; color: var(--muted); }body.side-nav #prefs svg { flex: none; width: 15px; height: 15px; margin: 0 .5px; color: var(--muted); }/* graphite, as a Mac sidebar is: no colour of its own, the page open in thediff --git a/internal/gui/assets/app.js b/internal/gui/assets/app.jsindex 3fb43370b..f2c1119fc 100644--- a/internal/gui/assets/app.js+++ b/internal/gui/assets/app.js@@ -24145,6 +24145,7 @@ async function show(v) {if (on) b.setAttribute("aria-current", "page"); else b.removeAttribute("aria-current");}if (!sideNav()) { slide($("#nav"), "nav"); navInSight(); }+ else navTopGo($("#nav").querySelector("button[data-view].on"), true);}$("#prefs").classList.toggle("on", v === "settings");if (v === "settings") $("#prefs").setAttribute("aria-current", "page"); else $("#prefs").removeAttribute("aria-current");@@ -24180,7 +24181,15 @@ function syncURL() {const s = q.size ? "?" + q : location.pathname;if (s !== location.search) history.replaceState(null, "", s);}-if (mode === "window") for (const b of $("#nav").querySelectorAll("button[data-view]")) b.onclick = () => { show(b.dataset.view); b.blur(); };+if (mode === "window") for (const b of $("#nav").querySelectorAll("button[data-view]")) {+ // beside the sidebar the selection goes as the finger comes down, as the+ // sub-rows' does; let go off the row, or the page kept (a draft not+ // given up), it goes back+ b.onpointerdown = (e) => { if (e.button === 0) navTopGo(b, true); };+ b.onpointercancel = () => navTopGo(navTopOn(), true);+ b.onpointerleave = (e) => { if (e.buttons & 1) navTopGo(navTopOn(), true); };+ b.onclick = () => { show(b.dataset.view).then((went) => { if (!went) navTopGo(navTopOn(), true); }); b.blur(); };+}// setGatewayMode shows or leaves out gateway mode's pages' tabs; the page// open, one of them, gives way to Providersfunction setGatewayMode(on) {@@ -24507,6 +24516,7 @@ function layoutNav() {navSubs();navSubs.quiet = false;if (!on) { slide(nav, "nav"); navInSight(); } else { sideGwRead(); renderSideGw(); }+ navTopGo(navTopOn(), false);sideWidth();renderSideToggle();fitTop();@@ -24786,6 +24796,86 @@ function navSubGlide(box, row) {hl.style.transform = `translateY(${row.offsetTop}px)`;hl.style.height = row.offsetHeight + "px";}+// The open page's row beside the sidebar is marked by one shape too+// (.nav-top-hl), which moves to the row picked on a spring, as iOS moves a+// selection: quick off the mark, settling softly with the least overshoot.+// Being physics, not a timed curve, it is never thrown: a press that+// changes its mind turns it with the speed it has, and it follows its row+// while a list above folds away, landing where the row ends up rather+// than where it was when the press came.+var NAV_SPRING = { response: 0.42, damping: 0.84 }; // seconds, fraction: SwiftUI's terms+var navTop = { row: null, y: 0, h: 0, vy: 0, vh: 0, at: 0, raf: 0, seen: false };+const navTopOn = () => $("#nav")?.querySelector("button[data-view].on") || null;+function navTopHl() {+ const nav = $("#nav");+ let hl = nav.querySelector(":scope > .nav-top-hl");+ if (!hl) {+ hl = el("i", "nav-top-hl");+ hl.hidden = true;+ nav.append(hl);+ // the rows moved at rest (the window, the language, a page left out):+ // the shape stays on its row+ new ResizeObserver(() => { if (!navTop.raf && navTop.row && !hl.hidden) navTopPut(hl, navTop.row); }).observe(nav);+ }+ return hl;+}+function navTopDraw(hl) {+ hl.style.transform = `translateY(${navTop.y}px)`;+ hl.style.height = navTop.h + "px";+}+function navTopPut(hl, row) {+ Object.assign(navTop, { y: row.offsetTop, h: row.offsetHeight, vy: 0, vh: 0 });+ navTopDraw(hl);+}+// navTopGo sends the shape to row, still unless glide+function navTopGo(row, glide) {+ if (mode !== "window" || !$("#nav")) return;+ const nav = $("#nav"), hl = navTopHl();+ const to = sideNav() && row && !row.hidden && row.offsetParent ? row : null;+ nav.classList.toggle("hl-on", !!to);+ // the same row, the shape still: the rows moved under it, not a pick, so+ // it stays on its row. And one not on screen yet (the window opening on+ // the page it was left on) is put there, not sent+ if (to && ((to === navTop.row && !navTop.raf) || !navTop.seen)) glide = false;+ navTop.row = to;+ if (!to) { cancelAnimationFrame(navTop.raf); navTop.raf = 0; hl.hidden = true; return; }+ const appearing = hl.hidden;+ hl.hidden = false;+ if (!navTop.seen) requestAnimationFrame(() => requestAnimationFrame(() => { navTop.seen = !hl.hidden; }));+ if (appearing || !glide || navCalm()) {+ cancelAnimationFrame(navTop.raf);+ navTop.raf = 0;+ navTopPut(hl, to);+ // back from Settings, whose row is at the foot: it comes up in place+ if (appearing && glide && !navCalm()) hl.animate([{ opacity: 0 }, { opacity: 1 }], { duration: 240, easing: NAV_EASE });+ return;+ }+ if (!navTop.raf) { navTop.at = performance.now(); navTop.raf = requestAnimationFrame(navTopStep); }+}+function navTopStep(now) {+ const nav = $("#nav"), hl = nav?.querySelector(":scope > .nav-top-hl"), row = navTop.row;+ if (!hl || !row?.isConnected) { navTop.raf = 0; return; }+ const dt = Math.min(1 / 30, Math.max(0, (now - navTop.at) / 1000));+ navTop.at = now;+ const k = (2 * Math.PI / NAV_SPRING.response) ** 2, c = 4 * Math.PI * NAV_SPRING.damping / NAV_SPRING.response;+ const ty = row.offsetTop, th = row.offsetHeight;+ // a few small steps a frame keep the spring true at any frame rate+ for (let i = 0, d = dt / 4; i < 4; i++) {+ navTop.vy += (k * (ty - navTop.y) - c * navTop.vy) * d;+ navTop.y += navTop.vy * d;+ navTop.vh += (k * (th - navTop.h) - c * navTop.vh) * d;+ navTop.h += navTop.vh * d;+ }+ const still = Math.abs(ty - navTop.y) < 0.25 && Math.abs(navTop.vy) < 4 && Math.abs(th - navTop.h) < 0.25 && Math.abs(navTop.vh) < 4;+ // at rest once there, and nothing above it still folding+ if (still && !nav.querySelector(".nav-sub.moving, .nav-sub.leaving")) {+ navTopPut(hl, row);+ navTop.raf = 0;+ return;+ }+ navTopDraw(hl);+ navTop.raf = requestAnimationFrame(navTopStep);+}function navSubEnter(box) {if (navCalm()) return;const cs = getComputedStyle(box);diff --git a/internal/gui/assets/omarchy.css b/internal/gui/assets/omarchy.cssindex 4e9412c45..13b970e82 100644--- a/internal/gui/assets/omarchy.css+++ b/internal/gui/assets/omarchy.css@@ -67,4 +67,6 @@ html.omarchy .icon.winclose:hover { background: var(--red-soft); color: var(--rehtml.omarchy ::selection { background: var(--om-sel); color: var(--accent); }html.omarchy body.side-nav :is(#nav button[data-view], #prefs).on { background: var(--om-sel); box-shadow: inset 0 0 0 1px var(--om-sel-line); color: var(--accent); }html.omarchy .nav-hl { background: var(--om-sel); }+html.omarchy body.side-nav #nav > .nav-top-hl { background: var(--om-sel); box-shadow: inset 0 0 0 1px var(--om-sel-line); }+html.omarchy body.side-nav #nav.hl-on button[data-view].on { background: transparent; box-shadow: none; }html.omarchy .nav-s.cur { color: var(--accent); }diff --git a/internal/gui/core_budget_test.go b/internal/gui/core_budget_test.goindex 59471f263..76329a8f6 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_338_929 // 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)- coreScriptBudget = 1_530_689 // 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+ appScriptBudget = 1_343_324 // 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)+ coreScriptBudget = 1_535_084 // 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)func TestCoreScriptBudget(t *testing.T) {diff --git a/internal/gui/tests/routing-idle-frame.test.cjs b/internal/gui/tests/routing-idle-frame.test.cjsindex b2e64ac9a..ed9569c07 100644--- a/internal/gui/tests/routing-idle-frame.test.cjs+++ b/internal/gui/tests/routing-idle-frame.test.cjs@@ -98,7 +98,9 @@ const init = () => {// the live dot's pulse, running or notwindow.__pulses = () => [...document.querySelectorAll(".rt-livedot")].filter((d) => d.getAnimations().some((a) => a.playState === "running")).length;window.requestAnimationFrame = (cb) => {- const self = typeof cb === "function" && /requestAnimationFrame\s*\(\s*([A-Za-z_$][\w$]*)/.test(cb.toString()) && new RegExp(`\\b${RegExp.$1}\\s*\\(`).test(cb.toString());+ // a loop of the core's (app.js's sidebar spring, navTopStep) is a+ // global; the Routing plugin's is in its own scope+ const self = typeof cb === "function" && window[cb.name] !== cb && /requestAnimationFrame\s*\(\s*([A-Za-z_$][\w$]*)/.test(cb.toString()) && new RegExp(`\\b${RegExp.$1}\\s*\\(`).test(cb.toString());if (typeof cb === "function" && (cb.name === "frame" || self)) window.__seenFrame = true;return raf((ts) => { if (cb.name === "step") window.__steps++; if (typeof cb === "function" && (cb.name === "frame" || self)) window.__frames++; cb(ts); });};diff --git a/internal/gui/tests/sidebar-glide.test.cjs b/internal/gui/tests/sidebar-glide.test.cjsnew file mode 100644index 000000000..9cec63512--- /dev/null+++ b/internal/gui/tests/sidebar-glide.test.cjs@@ -0,0 +1,140 @@+// Run with Node's test runner and Playwright on the module path; see README.md.+// Beside the sidebar the open page's row is marked by one shape (app.js+// navTopGo) that moves to the row picked on a spring, as iOS moves a+// selection, the way the sub-rows' selection slides: it sets off as the row+// is pressed, goes back when the press is let go off the row, follows its+// row while the list of the page left folds away above it, and lands on+// it. The rows have no ground of their own under it, hovered or not.+// Settings, at the foot, has its own; the shape is away while it is open.+// With reduced motion it is put there at once. In the header's tabs it+// isn't drawn. Both engines, two languages, two widths.+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 = path.resolve(__dirname, "../assets");++function serve(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:${JSON.stringify(lang)},theme:"light",web:false};` });+ if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });+ if (url.pathname === "/api/state") return json({ agents: [], profiles: [], settings: { lang, theme: "light" } });+ if (url.pathname === "/api/providers") return json({ providers: [], presets: [], excluded: [], gateway: { url: "http://127.0.0.1:3425", running: true, window: true }, plugins: [] });+ if (url.pathname === "/api/groups") return json({ groups: [], pools: [] });+ if (url.pathname.startsWith("/api/")) return json({});+ if (!/^\/[\w./-]*$/.test(url.pathname) || url.host !== "magpie.test") return route.fulfill({ status: 404, body: "" });+ const file = path.join(assets, url.pathname === "/" ? "index.html" : url.pathname);+ const contentType = { ".html": "text/html", ".js": "text/javascript", ".css": "text/css", ".svg": "image/svg+xml", ".png": "image/png" }[path.extname(file)];+ try { await route.fulfill({ body: await fs.readFile(file), contentType }); } catch { await route.fulfill({ status: 404, body: "" }); }+ };+}++// the shape's top and height, and a row's, in the sidebar's list+const shape = (page) => page.evaluate(() => {+ const hl = document.querySelector("#nav > .nav-top-hl");+ if (!hl || hl.hidden || getComputedStyle(hl).display === "none") return null;+ const b = hl.getBoundingClientRect();+ return { top: b.top, h: b.height };+});+const rowOf = (page, v) => page.evaluate((v) => {+ const b = document.querySelector(`#nav button[data-view="${v}"]`).getBoundingClientRect();+ return { top: b.top, h: b.height };+}, v);+// the shape's tops, one a frame, until it has been still for 20 frames+const watch = (page) => page.evaluate(() => { window.__tops = []; const f = () => { const hl = document.querySelector("#nav > .nav-top-hl"); window.__tops.push(hl.getBoundingClientRect().top); const t = window.__tops; if (t.length < 400 && !(t.length > 20 && t.slice(-20).every((y) => y === t[t.length - 1]))) requestAnimationFrame(f); else window.__still = true; }; window.__still = false; requestAnimationFrame(f); });+const settled = async (page) => { await page.waitForFunction(() => window.__still); return page.evaluate(() => window.__tops); };+const on = async (page, v) => {+ const [s, r] = [await shape(page), await rowOf(page, v)];+ assert(s, `the shape is drawn for ${v}`);+ assert(Math.abs(s.top - r.top) < 0.5 && Math.abs(s.h - r.h) < 0.5, `the shape on ${v}'s row: ${JSON.stringify(s)} vs ${JSON.stringify(r)}`);+};++for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {+ test(`${engine}: the sidebar's open page is one shape that springs from row to row`, async (t) => {+ const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));+ t.after(() => browser.close());+ for (const lang of ["en", "zh"]) for (const width of [1024, 1440]) await t.test(`${lang} ${width}`, async () => {+ const context = await browser.newContext({ viewport: { width, height: 800 } });+ const page = await context.newPage();+ page.setDefaultTimeout(5000);+ const errors = [];+ page.on("pageerror", (e) => errors.push(e.message));+ await page.route("**/*", serve(lang));+ await page.goto("http://magpie.test/?view=providers");+ await page.waitForSelector("#nav > .nav-top-hl:not([hidden])");+ assert.ok(await page.evaluate(() => document.body.classList.contains("side-nav")), "a sidebar at " + width);+ await on(page, "providers");+ // the list where it was before the shape: in the sidebar, at its edge+ const [side, nav, hl] = await page.evaluate(() => ["#side", "#nav", "#nav > .nav-top-hl"].map((q) => { const b = document.querySelector(q).getBoundingClientRect(); return { l: b.left, r: b.right }; }));+ assert(nav.l - side.l < 16 && nav.r <= side.r && hl.l === nav.l && hl.r === nav.r, `the list in the sidebar: ${JSON.stringify({ side, nav, hl })}`);+ const ground = (v) => page.locator(`#nav button[data-view="${v}"]`).evaluate((b) => getComputedStyle(b).backgroundColor);+ assert.equal(await ground("providers"), "rgba(0, 0, 0, 0)", "the open row's ground is the shape's");++ // hovered, a row has no ground of its own+ await page.locator('#nav button[data-view="agents"]').hover();+ assert.equal(await ground("agents"), "rgba(0, 0, 0, 0)", "no block under the pointer ahead of the shape");++ // pressed, the shape sets off before the press ends; let go off the+ // row, it goes back and the page stays+ const usage = await page.locator('#nav button[data-view="usage"]').boundingBox();+ await page.mouse.move(usage.x + 20, usage.y + usage.height / 2);+ await watch(page);+ await page.mouse.down();+ await page.waitForFunction((from) => Math.abs(document.querySelector("#nav > .nav-top-hl").getBoundingClientRect().top - from) > 2, (await shape(page)).top);+ assert.equal(await page.locator("#nav button.on").getAttribute("data-view"), "providers", "the page changes only on the click");+ await page.mouse.move(usage.x + usage.width + 300, usage.y + 200);+ await page.mouse.up();+ await settled(page);+ assert.equal(await page.locator("#nav button.on").getAttribute("data-view"), "providers");+ await on(page, "providers");++ // to Usage, then up to Agents while Usage's tabs fold away under it:+ // it moves by frames, never at once, and lands on its row+ for (const v of ["usage", "agents"]) {+ const from = (await shape(page)).top, to = (await rowOf(page, v)).top;+ await watch(page);+ await page.locator(`#nav button[data-view="${v}"]`).click();+ const tops = await settled(page);+ await on(page, v);+ const moving = tops.filter((y) => Math.abs(y - from) > 0.5 && Math.abs(y - (tops[tops.length - 1])) > 0.5);+ assert(moving.length >= 3, `${v}: the shape moves by frames, not at once: ${tops.map(Math.round).join(" ")}`);+ const end = tops[tops.length - 1], past = Math.max(...tops.map((y) => Math.sign(end - from) * (y - end)));+ assert(past < 3, `${v}: it settles with at most a little overshoot (${past.toFixed(2)}px): ${tops.map(Math.round).join(" ")}`);+ if (v === "usage") assert(Math.abs(end - to) < 0.5);+ }++ // Settings has its own; back, the shape is on the row picked+ await page.locator("#prefs").click();+ await page.waitForFunction(() => document.querySelector("#nav > .nav-top-hl").hidden);+ assert.notEqual(await page.locator("#prefs").evaluate((b) => getComputedStyle(b).backgroundColor), "rgba(0, 0, 0, 0)", "Settings keeps its own selection");+ await page.locator('#nav button[data-view="routing"]').click();+ await page.waitForTimeout(300);+ await on(page, "routing");++ // reduced motion: there at once+ await page.emulateMedia({ reducedMotion: "reduce" });+ await page.locator('#nav button[data-view="gateway"]').click();+ await on(page, "gateway");+ assert.deepEqual(errors, []);+ await context.close();+ });++ await t.test("the header's tabs draw none", async () => {+ const context = await browser.newContext({ viewport: { width: 900, height: 700 } });+ const page = await context.newPage();+ page.setDefaultTimeout(5000);+ await page.route("**/*", serve("en"));+ await page.goto("http://magpie.test/?view=providers");+ await page.waitForSelector("#nav button.on");+ assert.ok(!(await page.evaluate(() => document.body.classList.contains("side-nav"))));+ await page.locator('#nav button[data-view="usage"]').click();+ assert.equal(await shape(page), null);+ assert.notEqual(await page.locator("#nav > .thumb").count(), 0, "the header's own thumb");+ await context.close();+ });+ });+}diff --git a/internal/gui/tests/sidebar.test.cjs b/internal/gui/tests/sidebar.test.cjsindex 8f2da1208..c244d07ee 100644--- a/internal/gui/tests/sidebar.test.cjs+++ b/internal/gui/tests/sidebar.test.cjs@@ -84,7 +84,9 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",await page.mouse.move(box.x + box.width + 400, box.y);await page.mouse.up();assert.equal(tf, "none", `${sel} pressed is not squeezed`);- assert.notEqual(pressed, bg, `${sel} pressed darkens`);+ // a page's row has the open page's shape come to it instead+ // (sidebar-glide.test.cjs); Settings, at the foot, darkens+ if (sel === "#prefs") assert.notEqual(pressed, bg, `${sel} pressed darkens`);}// the gateway's address at the foot, read once the window has settled