# GUI app shell The desktop app has a tray (menu bar) icon whose click drops a compact panel, and a regular window. Both show one small web UI served from embedded assets. The page talks to Go over a JSON API on the same handler, with no binding generator and no bundler. `magpie web` serves the same page to a browser for a machine with no desktop. Package `internal/gui` hosts all three. ## Responsibilities and sources of truth | Part | Responsibility | Source | | --- | --- | --- | | Native host | `Run` starts the Wails v3 app: the tray icon, the panel, the main window, single-instance handover, `magpie://` import links and open at login. magpie claims `magpie://` only. v0.1.3981 to v0.1.4454 also claimed CC Switch's `ccswitch://` (Info.plist, `HKCU\Software\Classes\ccswitch`, `magpie-ccswitch.desktop`), and a start leaves what they wrote. A `ccswitch://` link that still reaches magpie that way (`magpie ccswitch://…` on Windows and Linux, before anything is read or started; the URL event on the Mac) is opened with CC Switch when it is installed, and the claim goes back to it: Launch Services registers magpie's bundle again from its Info.plist (`lsregister -f`), the per-user handler that runs this magpie is pointed at CC Switch's exe as its MSI writes it, and the desktop default that is `magpie-ccswitch.desktop` goes to CC Switch's entry, with magpie's entry removed while it runs this magpie or a gone one. With no CC Switch the link and the claim are left as they are (`ccswitchlink.ErrNotInstalled`; [`ccswitchlink`](../../internal/ccswitchlink/link.go)). `host` implements `Windows` for the API: show and hide, open URLs and folders, copy to the clipboard, fit and tint the panel, and set the text size. A copy on Linux sets PRIMARY before CLIPBOARD, since GTK 3 serves CLIPBOARD empty when PRIMARY is set after it on a compositor with no primary selection (KDE Plasma with middle-click paste off, #1881); on Wayland the copy is read back through the compositor, and one that doesn't read back whole answers `/api/copy` with 501, so the page tries its clipboard API, then the copy command, then says the copy failed with the text to copy by hand (`copy-fallback.test.cjs`). On Windows, Wails reads the screens again on each display change (`WM_DISPLAYCHANGE`, and `WM_SETTINGCHANGE` for the work area) through `w32.GetAllScreens`, which makes a new Win32 callback each time; Go never frees one and throws past about 2000, killing the app and its gateway after hours of display changes (1111_13879 on Discord). `screensWndProc`, the app's `WndProcInterceptor`, takes those messages on Wails' main-thread window first and reads the screens with one callback made once (`allScreens`), then hands them to `Screen.LayoutScreens` as Wails would; see `TestScreensReadFarPastTheCallbackLimit`, `TestDisplayChangesAreReadOnWailsWindowOnly` (Windows) and `TestWailsScreensAreReadOnTheMainThreadWindow`, which fails when a Wails upgrade changes what that relies on. On Windows `appWndProc` also installs a thread-local `WH_CBT` hook (`hookNoActivate`, `noActivateCBT` in `noactivate_windows.go`) on Wails' main thread to turn down `HCBT_ACTIVATE` for hidden windows and windows shown quietly (`showQuietly`, `showMinimised`), and unhooks it (`unhookNoActivate`) when the main-thread window is destroyed or the app shuts down so `ExitProcess`'s FLS cleanup (`msctf!CicFlsCallback`) cannot call back into Go while `runtime.exit` holds `runtime.finlock` (#6705, `TestUnhookNoActivatePreventsExitDeadlock`). | [`app.go`](../../internal/gui/app.go), [`screens_windows.go`](../../internal/gui/screens_windows.go), [`noactivate_windows.go`](../../internal/gui/noactivate_windows.go), [`clipboard_gtk3.go`](../../internal/gui/clipboard_gtk3.go), [`clipboard_gtk3.h`](../../internal/gui/clipboard_gtk3.h), [`mainwindow.go`](../../internal/gui/mainwindow.go), [`traymenu.go`](../../internal/gui/traymenu.go) | | Backend | `startBackend` starts the gateway this process serves, unless another magpie already serves it. In that case this process only shows the other one's status (`gw` is nil), and `watchGateway` looks at it again every 15 s (`gatewayWatch`). A magpie of another version there (`otherServes` in `gateway_older.go`) is told the page as `gatewayOther` in `/api/state` and said over the Agents list (`gatewaySkewLine` in `plugins/gateway/client.js`), in the panel and the window: pi got 404 for a model the newer app had written it while an older copy of the app kept the gateway, and only the Gateway page said so (matrix0487 on Discord). An older released copy of the app (`serves` app or tray, with a pid) is this app's own predecessor: once its `/v1/magpie/concurrency` says nothing is in flight (`gateway.ServedBusy`; unknown is never idle) the app quits it as the Gateway page's button does (`quitMagpieOnPort`, a magpie only) and serves the gateway, so no stream is cut; at most three times a run (`replaceMost`), and a quit that fails is left to the button. Any other (magpie serve or the service, `magpie web`, a TUI, a newer magpie, a build of its own) is left running, with what to do; a dev build of this magpie says nothing. A request that starts between the idle read and the quit gets the older app's short drain. See `TestAppReplacesItsOlderGatewayOnceIdle`, `TestGatewaySkewOfAnotherIsSaidNotQuit` and `gateway-skew.test.cjs`. `magpie serve` (the service's, launchd's `com.yetone.magpie.serve` or systemd's) does the same beside a magpie serving or another program holding the port: before it moves or starts anything (`startUp`), it waits, looking every 15 s, and serves once the port is free (`awaitGatewayFree` in [`serve_wait.go`](../../internal/cli/serve_wait.go); `--web` excepted, which shows the other one). Before, it ran the start-up moves, the plugin host and every account's model fetch, failed to bind, exited 1 and was started again by the service, 6,035 times in two days with a 279MB serve.log and requests 504 behind it (#4938, `TestServeWaitsForTheGatewayBeforeStartingUp`). `stopServing` drains requests in flight. A restart to update can hand the listening socket to the new version instead (see [A restart to update hands the gateway over](#a-restart-to-update-hands-the-gateway-over)). | [`backend.go`](../../internal/gui/backend.go), [`gateway_older.go`](../../internal/gui/gateway_older.go) | | API and assets | `Handler` serves `assets/` (embedded with `//go:embed assets`) and the `/api/*` routes, such as `/api/state`, `/api/set`, `/api/agents/{action}/{id}` and `/api/agents/restart/{id}` (a desktop app's Restart, after the row's confirm). `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) | | Settings from the terminal | `POST /api/settings` saves through `settingsapi.Apply` (`internal/settingsapi`, outside the GUI so the `nogui` build has it): the carry of keys a page leaves out (`Merge`), the vision, image and searcher checks, `settings.Save`'s own checks, and `catalog.Touched`. `magpie settings list\|get\|set\|reset` (#4745) builds the same body with `settingsapi.Body` (the whole file with one key changed, so a key the save keeps when it isn't sent is set even to off) and calls the same `Apply`; a refused value writes nothing. `settingsapi.Keys` names what the save writes; `TestKeysAreWhatTheSaveWrites` fails when a field of `settings.Settings` is saved without it, `TestSettingsCLISetsWhatTheWindowSaves` when a key the page's `savePrefs` sends isn't one, and `TestEveryRouteHasACommandOrIsNamed` when an `/api` route has neither a command nor a reason in `notYet` (`internal/cli/settings_parity_test.go`). The running app's in-process follow-ups (fonts, Dock, tray menu, alerts, language, update check) run only from the window's save; a change from the terminal is read from the file. | [`internal/settingsapi/settingsapi.go`](../../internal/settingsapi/settingsapi.go), [`settings_cli.go`](../../internal/cli/settings_cli.go) | | Browser mode | `StartWeb` serves the page and the gateway for `magpie web`. The browser signs in with a run key in a link. On a LazyCat box `MAGPIE_WEB_SIGN_IN=lazycat` lets the box's administrators in without it, signed in to the box (`webBoxSignIn`, `lazyCatSignIn`): the box's ingress names the account, its role and what sent the request (`X-HC-User-ID`, `X-HC-User-Role`, `X-HC-Source`) in place of the caller's own, and an `ADMIN` from a browser (`client`), each named once, gets in with no cookie of the page's own, asked for each request. The box's sign-in is the box's cookie, which a browser may send with another app's page's requests (the box's apps are one site), so it takes only what the page or a browser opening it asked for (`boxFetched`: Sec-Fetch-Site same-origin or none, or a GET or HEAD navigation to a document from another page); any other request, and one from a browser without Fetch Metadata, is turned away with the reason. `StartWeb` refuses another value, and lazycat without `LAZYCAT_APP_DOMAIN`, where no box's ingress sets those headers; that is all it can check: the setting is the package's word that the ingress is the only way to the page's port. The app's Browser access page takes its key alone (`apppage.go`), and the client routes on the page's port never take the box's sign-in. See `TestLazyCatSignInOpensThePage`, `TestLazyCatSignInTurnsAway`, `TestLazyCatSignInAsksWhereFrom`, `TestLazyCatSignInIsAskedEachTime`, `TestLazyCatSignInIsNoGatewayKey` and `TestWebBoxSignInChecksItsValue`. Added to a phone's home screen the page opens as an app of its own, with no browser bars (ninja_s6114 on Discord): `index.html` names `manifest.json` (display standalone), an apple-touch-icon and the iOS meta tags, the status bar keeps its own ground (`default`), and its theme colours match only `(display-mode: standalone)`, so a browser's tab and the app's windows take none. `webGuard` serves those three files (`webAppFiles`: the manifest, `icons/apple-touch-icon.png`, `icons/icon-512.png`) without the key, to GET and HEAD at those exact paths alone, as a home screen may ask without the cookie; see `TestWebAppAddsToHomeScreen` and `web-app-standalone.test.cjs`. The cookie is SameSite=Lax, which a browser sends with any request from the same site, other ports and sibling subdomains included, so `webOwnPage` answers `/api` for the page's own origin only: a write goes through net/http's `CrossOriginProtection` (Sec-Fetch-Site same-origin or none; from a browser without it, an Origin that is absent or names the Host or `MAGPIE_PUBLIC_URL`), and any request whose Sec-Fetch-Site says another origin sent it is refused, a GET too; see `TestWebAPIAnswersItsOwnPageOnly`. The desktop window's `/api` is in-process with no cookie and isn't held to it. Gateway mode shows every page but Agents on a machine that is only a gateway (`GATEWAY_HIDES`); the Library has its MCP servers and the MCP router, for other computers' apps to reach with a gateway key (treeman_26897 on Discord, `gateway-mode.test.cjs`, `library-mcp-agentless.test.cjs`), and its Skills and Instructions with nothing of agents, for a Remote magpie's clients to take (fenglian980510 on X, `library-agentless-skills.test.cjs`). `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; never an event stream, which gzip would hold back until its buffer fills); the app's own windows read the page in-process and get it uncompressed. The page's port answers the gateway's client routes too (`onePort`, `gateway.ClientPath`: `/v1/…`, `/v1beta/…`, `/mcp/…`, the Codex backend path and the routes without `/v1`; never `/api/*` or `/_magpie/*`, never a path that isn't clean), so one reverse-proxy location serves the page and the agents (zgcwkj on Discord). They skip the page's key and gzip and go to the gateway's own guards, always as a request from another machine (`gateway.FromPagePort`, the `X-Magpie-Page-Port` mark: `local` is false for it, from loopback too and under `MAGPIE_TRUST_PROXY`, so magpie must be shared and the request carry an enabled gateway key), since a raw TCP forward or a proxy that adds no forwarding header reaches this port from loopback looking like an agent here (reported privately by Coffemon); agents here use the gateway's own port. `Server.Front` (lanGuard over Handler) serves them in process when this process serves the gateway, or `toGateway`, a reverse proxy to `gateway.URL()`, when another magpie does; it keeps the Host, the forwarding headers and the mark, adds X-Forwarded-For for a peer that isn't loopback, and the peer's loopback address as X-Forwarded-For when none came, so a gateway of an older magpie that doesn't know the mark still asks for a key. `lanGuard` moves the mark into the request's context and takes the header off, so it never goes upstream. The page itself calls no client route. See `TestWebOnePortServedHere`, `TestWebOnePortServedElsewhere`, `TestWebOnePortAgentsHereUseTheGatewayPort`, `TestPagePortMarkIsNeverLocal` and `TestClientPathCoversHandler`. | [`web.go`](../../internal/gui/web.go), [`web_lazycat.go`](../../internal/gui/web_lazycat.go), [`gatewaymode.go`](../../internal/gui/gatewaymode.go), [`oneport.go`](../../internal/gateway/oneport.go) | | The app's page in a browser | Settings › Network and sharing › Browser access (`renderWebPage` in `plugins/gateway/settings.js`, drawn with the Web pages rows) has the app serve its own page to a browser while it runs, so a tunnel (Cloudflare Tunnel, SSH) or a computer on the network can reach it without `magpie web` kept running in a terminal (jiakun_zhao on X). Off, This computer (`127.0.0.1`, which a tunnel's service points at) or Local network (every address; a "Not encrypted" row without `--tls-cert`). It is `magpie web`'s page and guard, not a second kind: `startAppPage` (from `Run`, after `startBackend`) serves `webServed` over a `Handler` of its own, whose `Windows` is `appWebHost` (a browser tab for `isWeb`, but not `ownWeb`, so the app's windows aren't taken for `magpie web`'s: `webPage` and gateway mode stay the app's; quitting quits the app, and a restart to update from it brings back the windows the app has up, `restartFrom`). The key is always asked for: no mode serves without it. It lives with the mode and port in `web-page.json` beside settings.json (0600, never in settings.json, so sync and backup don't carry it), is made the first time the page is turned on, kept across restarts (a browser's cookie stays good), and replaced by New key, which turns away every browser signed in with the old one (the guard is swapped atomically, `appPage.cur`). A file that can't be read, or names no known mode, is off and says why; Settings rewrites it only given a whole choice. A port another program holds (`magpie web`; the magpie before a restart to update) is said and tried again every 4 s (`appPageRetry`); the port must be 1024 up and not the gateway's. `GET/POST /api/web-page` are on the app's own windows' API only, never a browser's, so a browser on the page can neither read the key it came in without nor turn the page off under itself. `magpie web` on the port the app serves prints the app's link and opens it rather than starting a second (`gui.AppPage`, `samePort`). Sessions are warmed once a process however many `Handler`s there are (`warmOnce`). See `TestAppPageServesOnlyWithItsKey`, `TestAppPageWaitsForABusyPort`, `TestAppPageUnreadFileServesNothing`, `TestAppPageTurnsDownBadChoices`, `TestAppPageBrowserIsATab` and `browser-access.test.cjs`. | [`apppage.go`](../../internal/gui/apppage.go), [`web_cli.go`](../../internal/cli/web_cli.go) | | Another magpie in a window | Settings › Network and sharing › Another magpie (`renderRemote` in `plugins/gateway/settings.js`) opens a magpie elsewhere, a server's (`magpie daemon install --web`, `magpie web`, another app's Browser access), in a window of the app's own, so its routing and usage are read from the desktop (xuanwo on X). The window (`OpenRemote`, `remote_app.go`) loads that magpie's own web page with `?k=` and signs in through its `webGuard` as a browser does: nothing is served here, and the page in it reaches that magpie alone (a remote page gets no bound calls). The address is the link that magpie printed (its `k=` taken out as the key) or a bare address, https:// when no scheme is typed; plain http only to an IP, localhost, a `.local` or a one-word name (`remoteAddr`), as a Mac's webview allows, so the key never crosses the internet in the clear. Before the window opens, `remoteProbe` asks for the link without following it: only a 303 setting a `magpie_web_*` cookie is that magpie taking the key; a 401, a 403 (allowed addresses), an untrusted certificate, no answer or anything else is said in Settings. Address and key live in `remote-magpie.json` beside settings.json (0600, never in settings.json); `GET /api/remote` says the address and whether a key is kept, never the key, and `POST /api/remote` with no key uses the one kept for the same address. The routes are on the app's own windows' API only (`!isWeb`), and a host that can't open windows refuses. See `TestRemoteAddr`, `TestRemoteOpensTheOtherMagpie`, `TestRemoteNotMagpie`, `TestRemoteNotOnBrowserPages` and `another-magpie.test.cjs`. | [`remote.go`](../../internal/gui/remote.go), [`remote_app.go`](../../internal/gui/remote_app.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//` (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; a client whose User-Agent names only an HTTP library, a runtime or an API SDK (`usage.IsLibrary`: curl, Bun, python-httpx, Go-http-client, OpenAI/Python), or nothing (`other`), is no agent and goes on one card, `scripts`, named Scripts with its libraries listed, read from each route's kept agent so older history folds too, while the Usage page's Agents list keeps each by its own name (theforeveriris on X, `context_scripts_test.go`, `context-scripts.test.cjs`); clicking a part, a cell or an item opens its text from `/api/context/text`, the last 10 requests' masked bodies in memory, else the request archive's copy masked the same way, with a 404 saying why there is none (`archive`: off, missing, cut, unread; `context_archive.go`), and its Reply the reply from `/api/context/reply` (`openCtxText`, in `ctxtext.js`, `context-text.test.cjs`), rendered 100 items and 20000 characters at a time; a session's details on the Sessions page and Usage's Sessions list draw a Context line of its requests from `/api/context/session`, which reads only the days from its first to its last (30 at most) and keeps that one session, so the tab's 80-session cap never leaves it out (`sessCtxLine` in `plugins/usage/page.js`, liang_yongxiang on Discord, `context_session_test.go`, `sessions-context-line.test.cjs`); 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, or drawn at once from boot.js's `sideGateway`; on a page other machines open, `magpie web`, it is `MAGPIE_PUBLIC_URL` while they are let in, as the Gateway page's address and About's Gateway URL are, noahhrreion on Discord; a port applied in Settings redraws it), 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; Settings' are listed above its button at the foot, which is laid from its end (`.side-foot`'s `column-reverse`, its rows kept whole and scrolled from the end when the window is too short), so the list grows up from the button and the button and the gateway's line stay where they were clicked (jen_celeus on X, `sidebar-settings-steady.test.cjs`); 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 row folds its list and unfolds it, as a Mac sidebar's disclosure (hkwok06 on X: Settings' list unrolled and only another page, the gateway, put it away): the row carries a muted chevron (`.nav-fold`, `aria-expanded`), turned down to the list while it shows (up for Settings', which opens above its button) and to the side while folded, and the row clicked again, or Enter on it, folds or unfolds the list and leaves the page and its tab as they were (`navFold` and `navFoldRows` in `navicons.js`, imported with the first list; `navSubs` asks `navList("Folded")`). A folded list stays folded, per page, in localStorage `magpie.navFolded`, until its row opens it again. See `nav-sub-fold.test.cjs`. 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. That tab bar (`phoneWeb`, app.css `body.web .top #nav`) lies at the window's foot, as an iPhone app's, over the home indicator's inset (`--tabbar`), with each page's icon over its name. It holds five tabs: with more pages shown than that, the first four and More, whose app menu lists the rest with their icons and ticks the open one, and More is marked while one of them is open and carries a page's dot (`phonetabs.js`, imported by `layoutNav` the first time the page is a phone's; a `MutationObserver` fits it again when a page is shown, left out or opened). Before it the tabs were a strip that scrolled sideways with nothing saying it did, and Agents and the Library lay past its edge (geraldpppppp on X). Status messages sit above the bar. See `phone-tabs.test.cjs`. 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`). Settings › General › Sidebar pages (`navpages.js`, loaded when Settings draws; youimark on X) leaves pages out of the sidebar for this browser alone: localStorage `magpie.navHidden`, read by `navMine` (through `navList`, which reads `magpie.navFolded` too), which `navHides` asks beside gateway mode and the built-in plugins. A hidden page's link, `?view=` or search hit still opens it (`offView` redirects only a page gateway mode or a switched-off plugin leaves out); only the window's kept place gives way, to the first page or Providers when Agents is hidden too (`keptView` in `start.js`), and Providers cannot be hidden (`nav-pages-hidden.test.cjs`). The same menu puts the built-in pages in the reader's order (chet030714 on X): a row dragged by its grip (with a mouse, a finger or a pen: `dragRows` through `dragListen`, which cancels only on the row's own `lostpointercapture`, since a finger's implicit capture on the grip is lost to the row and bubbles up; 40 points wide where the pointer is coarse), or moved with Alt+↑/↓, is kept in localStorage `magpie.navOrder`; `navArrange` in `navorder.js` (which `navHides` imports only once an order is kept, and `navpages.js` with the menu) moves the `#nav` buttons into it, so the sidebar, the header's tabs and a phone's tab bar (`phonetabs.js`: the first four, the rest under More) all follow, and while the order isn't the home one the groups' names are taken out of `#nav`. `navOrder` puts a page the kept order doesn't name (new in an update) after the page it follows at home; Default order removes the key. Plugin pages keep their own order in their group (`nav-pages-order.test.cjs`). 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`, with *Never mask* and *Masked words* drawn a value a row by `wordList` in `plugins/redact/settings.js`, saved as the same list of strings the one comma-separated box saved, `redact-words-list.test.cjs`), *Try it* (`renderMaskTry`, the text as the vendor would get it from `/api/masking/preview`, kept in no storage) and *Sharing*. *Agents' session history* (`renderSessionReads`, read from `/api/sessions/reads` only while the Privacy part is shown) has *Agents found later* and a row per agent found, the choice the Sessions page asks first on a fresh install; see [gateway sessions](gateway-sessions.md#which-agents-sessions-magpie-reads). While anything is masked, *Instead of masking, send to* (`redactRouteRow` in `plugins/redact/settings.js`, the redact plugin's part of Settings, which wraps `renderRedact` so app.js carries none of it) picks, in the app menu, a model a request masking would change goes to as written: Off by default, and only the models `/api/settings` lists as `maskRouteModels` (every route of theirs unmasked, `gateway.MaskRoute`), saved with `POST /api/settings/redact-route` (`redact-route.test.cjs`). 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=""`. 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. Settings' search lists the built-ins themselves after its own rows, off or on, by name, line or a setting in their schema (Gateway's Recent calls at a time is on its own page), and Open lights the row in Plugins › Built-in (`setFeatsFind` in the lazy [`setfeats.js`](../../internal/gui/assets/setfeats.js), `settings-search.test.cjs`). Its provider links are drawn the first time a search wants them (`provlinks.js`). A part is found by its name, not its tab's id ("usage" no longer brings all of Allowances; Observability also answers to otel). A hit under a folded Advanced is unfolded while the search lasts and folded again when it ends (`setFolds`). The settings an agent's sheet or the Claude editor builds only when opened (Claude Code's prompt cache and commit signature, an agent's own fields, the run mode) have links there too, whose Open opens the sheet or editor and lights the row (`sheetLinks`, `lightWhen`; `settings-search-reach.test.cjs`). 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) | | The app's log | `runGUI` and `runPanel` (so `magpie`, `app`, `tray`, `panel`, a window view and a `magpie:` link) call `startLog` before `gui.Run`: `applog.Start` sends the standard logger, which the gateway, the plugin host and Wails' error handler write to, to `app.log` in `appdir.Logs` as well as stderr (`quiet`, which never fails, first, since io.MultiWriter stops at a failed writer and an app opened from Explorer has no stderr), and points `debug.SetCrashOutput` at it, so a panic is in it. Opened from the Finder, the Dock or the Start menu the app has no terminal, and wrote its log nowhere (rayem1w on X, 0.1.2330). The folder is `~/Library/Logs/magpie` on macOS (beside the launch agent's `serve.log`, which launchd writes for `magpie serve`: the two processes never share a file), `%LOCALAPPDATA%\magpie\logs` on Windows, `$XDG_STATE_HOME/magpie` (`~/.local/state/magpie`) elsewhere, and `logs` in a portable data folder. The file is 0600. At 5 MiB (`Limit`) it becomes `app.old.log`; when another magpie (an update's new process) rotated it already (`os.SameFile` of the open file and the path differs), it is only opened again, and when it can't be moved it is emptied. Each line goes through `scrub`, which masks bearer and basic credentials, key and token query parameters, and `sk-`, `AIza`, `gh?_` and JWT shapes, though nothing logged is meant to carry one. Settings › About's Log row (`#logRow`, `settingsJSON.Log` from `applog.Current`, so `magpie web`, which writes no file, shows none) has its path and an Open (`POST /api/settings/log/reveal`) that shows its folder; `magpie log` prints where every log is, `-n` the last lines, `-f` follows across a rotation (`TestTheAppWritesItsLog`, `TestLogFollows`). | [`internal/applog/applog.go`](../../internal/applog/applog.go), [`gui_on.go`](../../internal/cli/gui_on.go), [`log_cli.go`](../../internal/cli/log_cli.go) | | 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) | | The terminal quitting | `magpie tui` that served the gateway with an agent connected hands the gateway on as it quits, on Linux where nothing opens magpie at login (a WSL distro, a server over SSH; zaidu259434 on X): `keepGateway` starts magpie's service when it is installed, installs it (`daemon.Install`) when the user never removed it (`daemon.Removed`, a mark `magpie daemon uninstall` leaves), and otherwise starts `magpie serve` in its own session (`serveInBackground`, log in magpie's cache). Elsewhere, or with nothing connected, it only says the gateway stopped. Where magpie opens at login (`autostart.Enabled`, which on Linux counts a package's own autostart entry, also on a box no desktop logs into) it leaves the gateway to the app, and the note says `magpie autostart off` has the terminal hand it on where no desktop logs in (`atLoginNote`, #3756). | [`keep.go`](../../internal/tui/keep.go) | | The app quitting | A Quit the user chooses (the tray's Quit, the panel's and window's Quit, Command-Q on the Mac) while agents are connected to the gateway this process serves asks first (see [A Quit asks while agents go through magpie](#a-quit-asks-while-agents-go-through-magpie)). Closing the window only hides it: magpie stays in the menu bar or the system tray and the gateway keeps serving, on Windows too. | [`quitask.go`](../../internal/gui/quitask.go), [`quitask_app.go`](../../internal/gui/quitask_app.go), [`quitask.js`](../../internal/gui/assets/quitask.js) | ## Runtime path 1. `magpie` with no arguments, `magpie app` or `magpie tray` calls `runGUI`, which starts the app's log (`startLog`, above) and calls `gui.Run`. A `nogui` build runs the TUI instead. A second launch hands over to the instance already running. On Windows, before any window is made, `webView2Check` asks Wails whether the WebView2 runtime is there (`Env.Info().PlatformInfo["WebView2"]`, "" when its lookup fails; a key Wails doesn't set counts as there). Without it Wails would exit on the first window with nothing on screen, so magpie logs it, shows a Windows message box in the reader's language naming the runtime, Microsoft's download page (`webView2Page`) and `magpie web` / `magpie tui`, opens the page on Yes, and `Run` ends (#1806, `webview2.go`, `TestWebView2MissingFromWails` on Windows). The box can't come from `ErrorHandler`, which runs on the thread Wails makes its windows on. 2. `startBackend` brings up the gateway, or finds another magpie serving it. 3. The panel and the window load `index.html` from `Handler`. `boot.js` passes the saved language, theme, colorblind mode, text size and desktop font choices before the first paint. It also puts in the look of the reader's own (`appearance.go`, CHENGJIAHEGOXIS on X): Settings › General's Accent color (`accent`, `#rrggbb`; `accentVars` darkens it on the light theme and lightens it on the dark one until it reads as text at 4.5:1; it also sets `--mark`, the ink of what is chosen: the open page's sidebar icon, a switch's or tab's chosen option, Library's switches and radios. `--mark` is `var(--fg)`, graphite, until the user picks an accent, so a picked colour shows on the page it is picked on. A picked colour also tints the theme's grounds, the window's and the tray panel's (`--bg`, `--card`, the pills, lines and the dark menus' `--pop-bg`; `tintVars`): each takes 5% (light) or 8% (dark) of the colour's hue, its own lightness kept, so a grey pick changes nothing and text keeps its contrast. A dark pick, one whose OKLab lightness is under 0.4 (Graphite and every preset are lighter), takes the dark grounds as far toward black as it is dark (`ground`, `darkness`), losing app.css's cool grey cast and taking more of the pick's hue as they go: black draws a #000000 page with its cards, pills, lines and menus the same neutral steps above it, and a deep navy a near-black navy page (`TestDarkPickDarkensPage`). Black's ink starts most of the way to white (`lifted`, by `depth`), so it is not Graphite's grey; on the light theme black is black ink, and white the light theme's dark ink (`TestBlackIsBlack`); with no accent, or under Omarchy, they are app.css's own. `TestTintBasesAreAppCSS` holds the Go bases to app.css, and `TestLookFixture` the GUI tests' `fixtures/look-accents.json` to `lookCSS`) and Background image (a PNG, JPEG, GIF or WebP of 16 MB at most, saved as `wallpaper` in magpie's folder by `POST /api/appearance/wallpaper` as base64 JSON, `{remove: true}` to take it away; `settings.Wallpaper` is its stamp), drawn behind the window's pages under a veil of the theme's background, never in the tray panel or under Omarchy. `bootPrefs.look` says which look was drawn; `applyPrefs` asks `/api/appearance/css` again only when the settings' look differs, and the rows are drawn by the lazy `appearance.js` (`appearance-look.test.cjs`, `appearance_test.go`). 4. The page reads `GET /api/state` and writes through `POST` routes. Each write answers with the new state, built under `held`. 5. Closing the window hides it. On the Mac a full-screen window first leaves full screen (`closeStep`). The system's close on the panel (a title bar's X, Alt+F4, a window manager's close key) hides it as Escape does, so the tray icon opens it again; a panel lightweight mode let go, no longer `h.panel`, closes (`makePanel`, `TestPanelCloseHidesIt`). A hidden macOS window keeps its WKWebView's page marked visible, so `hideWebview` tells the page it is out of sight before `orderOut`; that makes `document.hidden` and `visibilityState` true, stops the page's polling and frame loops, and pauses CSS animations. `showWebview` tells it it is visible again (#4293). Lightweight mode lets go only of a window closed this way: one covered by another app's window, minimised, or open as magpie was hidden is still open (`windowUp`, not Wails' `IsVisible`, which is the occlusion state), and so is it for the Dock while the window is open and for a restart (#1381, `TestCoveredWindowStaysUp`). On the Mac the tray icon and a usage cell close an open panel by the same test (`windowOpen` in `togglePanelNow` and `trayCellClick`, not Wails' `ToggleWindow`), so under a window over the whole screen, such as a remote-desktop server's privacy curtain, the icon still closes the panel instead of showing it again (#1661, `TestTrayCellClickReleasedPanel`). On Windows a hidden window's WebView2 is put on its low memory target (`lowWhileHidden`, [`memtarget_windows.go`](../../internal/gui/memtarget_windows.go): `ICoreWebView2_19::put_MemoryUsageTargetLevel`, on each hide, on a page that comes while hidden, and back to normal on each show), so the panel and the window kept loaded in the tray stop holding what they last drew; the page stays loaded and running, unlike lightweight mode. In the tray the WebView2 processes' private working set went from ~170 MB to 20 to 40 MB, while their commit charge stayed where it was (molamaker11 on X). WKWebView and WebKitGTK have nothing magpie can set for it. 6. The window opens as it was last left. Its settled size and whether it was maximised are kept in `settings.Window` and `settings.WindowMaximised` (`settle`; per machine, see `KeepOwn`). A maximised window keeps the size it restores to. `makeMain` opens it at that size (`openSize`). On its first show, `placeMain` maximises it again on the Mac and Windows (on Windows once the page has come). On Linux, `makeMain` makes it maximised with `StartState`. On Windows a size larger than the screen's work area is fitted and centred (`fitRoom`), and the larger size stays kept. Where it was left is kept too, in `settings.WindowAt` (its top left corner across every screen, in the system's coordinates), so after a restart or an update it opens there rather than in the middle (jorbenzhu on Discord). `keepAt` saves it once a move or resize has rested for half a second, unless the window is maximised, full screen, minimised or hidden; `settings.Save` writes through temp and rename, and a settings file that can't be read is left alone. On its first show `placeMain` puts it back (`putBack`): `openAt` takes the screen holding most of the window, moves the window fully onto that screen's work area, and leaves it centred when no screen holds any of it, such as a monitor that is gone, or when the screens or the file can't be read (`TestOpenAt`). Under Wayland a window can't place itself, so nothing is kept or put back there unless GDK_BACKEND is x11 (`keepsPlace`, `TestKeepsPlace`). The pin in the window's title bar, between Refresh and Settings (`#pin`, `renderOnTop`; NovaStudiosss on X, to watch Usage and Routing while working in another app), keeps the window above other apps' windows: `POST /api/window/ontop?on=1` (or `0`) saves `settings.OnTop` (`SetOnTop`, this computer's own, kept through a Settings save) and calls `SetAlwaysOnTop`, and `makeMain` opens the window pinned when it is set. boot.js says whether there is a pin (`pin`, `pinnable` in `ontop.go`) and whether it is pressed (`onTop`) before the first paint. There is none in the panel, in a browser page or `magpie web`, or under Wayland (the same `keepsPlace`: GTK's keep-above does nothing there), and the route refuses there with 400 and saves nothing (`TestPinKeepsWindowOnTop`, `TestPinRefusedWithoutAWindowToPin`, `window-pin.test.cjs`). The tray's panel isn't kept: on the Mac and Windows it opens under the tray icon, and on Linux where the click was. 7. The page's header is the window's title bar. `plainTitlebar` sets it up once the app has started, and again on a window lightweight mode made again (`madeAgain`). On Linux it hides GTK's title bar and keeps the shadow and the resize edges; GTK 3 leaves the corners square. On the Mac the traffic lights are inset into the header (`MacTitleBarHiddenInset`). In the design of macOS 26 a window with a toolbar has larger corners than one with a plain title bar, so `insetLights` ([`titlebar_darwin.go`](../../internal/gui/titlebar_darwin.go)) takes the toolbar off, and `MagpieLights` keeps the lights and the title bar's height where the toolbar had them: after a resize, a new title, light or dark, more contrast or less transparency, and leaving full screen. A sheet, such as the folder chooser, still begins below the title bar. A first press while another app is in front still moves the window from anywhere in that title bar (`firstPress`), as AppKit moved it with the toolbar; AppKit itself now does so only in a plain title bar's top 32pt. AppKit gives a program that design from macOS 26 when the program is linked against the macOS 26 SDK or a later one and its Info.plist doesn't ask for the earlier design (`UIDesignRequiresCompatibility`); `designOf26` reads each at run time, as the SDK depends on the toolchain that built magpie. The toolbar stays where it doesn't change the corners: in the earlier design, and on macOS 27, which gives a window with a toolbar a plain title bar's 16pt corners (`toolbarRounder` holds the window's radius against a window of its style with no toolbar, never shown); with the lights on the right (a right-to-left language), or when the title bar isn't laid out as expected; this is decided once, when the window is set up. A toolbar that stays has no menu: a right-click on the title bar offered *Icon and Text*, *Icon Only* and *Text Only* for it (AlanWang1027713 on X), so `quietToolbar` turns off `allowsDisplayModeCustomization` on macOS 15 and later and AppKit's own `_setWantsToolbarContextMenu:` before that, each looked up at run time; `TestMainWindowCorners` and `TestMainWindowRightToLeft` check the menu a right-click by the lights gets from the window frame. In full screen the title bar is AppKit's own. On Windows the main window is frameless (`mainFrameless` in [`mainwindow.go`](../../internal/gui/mainwindow.go)), so a wallpaper or the page's colour runs to its top instead of stopping under a separate strip (258a14 on X). Wails keeps the frame's styles, so it still has its shadow and Windows 11's rounded corners, and snaps with Win+arrows and by dragging to a screen's edge. Wails' frameless window has no frame left to resize from, only a band 4px wide inside the page, and the page's scrollbar covers it on the right (Puremilk_chun on X), so the main window keeps Windows' own resize border on its left, right and bottom, outside the page as on a framed window (`mainFrameCalc` in [`mainframe_windows.go`](../../internal/gui/mainframe_windows.go), asked first by `appWndProc`; `keepResizeFrame` names the window once Wails' runtime is ready; `TestMainWindowKeepsResizeBorder`). Its top is still the page's, resized by Wails' band; maximised or in full screen Wails sizes it as before. The page draws the caption buttons at the header's right (`#wincap`, shown by app.css under `html.win` from `layout.js` in the window and not on the web, run by `wincap.js`, which app.js imports in that window alone, Segoe Fluent Icons' glyphs, Close red on hover); they minimise, maximise or restore, and close (hide; the tray stays), and stay over a dialog's scrim (`wincap.js` undoes the `inert` that `modalBackground` sets on them). The header's own tools sit left of them. A double click on anything that drags the window maximises or restores it. The app tells the page whether the window is maximised (`captionJS`, on Wails' runtime ready and on a resize that changes it), which swaps maximise for restore and keeps Wails' resize edges inside the page off while maximised, so the top-right pixel is Close's (`TestCaptionKeepsEdgesOffWhileMaximised`, `win-caption.test.cjs`). Windows 11's snap layouts flyout over maximise isn't shown: it needs Wails' composition hosting (`--wails-non-client-region`), which forwards input by `SendMouseInput` only. The panel keeps its own window as before. 8. On the Mac, Settings › Show in Dock puts magpie in the Dock never (`DockNever`), while the window is open (the default; `DockWindow` records it chosen, for an older magpie that took none for never) or always (`Dock`, which wins). The default was never until ShouguangCao on X found the open window out of Command-Tab, so going back to it to paste a key copied elsewhere took the menu bar; a new install (no settings.json) reads With window, and Hide is a choice of its own (`inDock`, `dockChoice` in app.js, `TestDockFollowsWindowByDefault`, `dock-choice.test.cjs`). A file written before that has no `dockSettled`, and stored Hide as nothing, so a user who chose Hide can't be told from one who never chose: such a file with no Dock choice reads as Hide, and the first save writes it so with `dockSettled` (`settleDock`, `TestOlderSettingsKeepHide`, `TestNewInstallFollowsWindow`). A file nobody can read reads the same way. The page never sends `dockSettled`; the save keeps the file's (`TestSettingsSaveKeepsDockReading`). It is this computer's own, as the Dock choice is (`KeepOwn`). A full-screen window joins it whatever the setting (`inDock`, `dockOnFullscreen`). `openMain` joins before it shows the window (`setDock` runs on the main thread at once). An app activated out of the Dock (the quick panel's focus) that then joins it stays last in Command-Tab's order though it is in front, so joining to the front activates magpie by way of the Dock (`dockStep`, `activateAgain`; #1381, `TestDockStep`, `TestDockJoinLeadsCommandTab`). It does so without asking NSApp whether magpie is active: the Mac makes it the front app at once, and NSApp says so only once the main thread has taken that in, after the join on a busy Mac (#1651). 9. Settings › General › Quick panel shortcut binds a key combination that opens the tray's panel from any app (ben hanks on Discord); none is set by default. The page records the keys and posts them to `POST /api/settings/panel-shortcut`, which checks them (`panelShortcut`: a letter, digit, Space or F1–F20 with Ctrl, Alt/Option or Cmd/Super, or an F key alone, written as Wails' accelerator), has the running app bind them (`onPanelShortcut`, `bindPanelKey` through Wails' `GlobalShortcut`: Carbon's hot keys on the Mac, `RegisterHotKey` on Windows, `XGrabKey` on X11) and saves them only once bound. One the system refuses (on Windows and X11, another app holding it) is not saved and the old one stays bound; one saved but refused as magpie starts is retried after a handed-over magpie exits and else said in the row (`panelKeysJSON.Taken`). A pressed shortcut toggles the panel as a tray click does (`togglePanel`). The Mac's Carbon hot keys don't refuse a combination another app registered too, so there both are taken and magpie can't tell the user. The shortcut is per computer (`KeepOwn`), and the Mac's old process lets go of it as it hands over (`leaveMenuBar`). On Wayland no app may grab keys itself, so the field is off and the row says the command to bind in the desktop's own keyboard settings (`magpie panel`); Wails' GlobalShortcuts portal is not used, since the compositor decides its keys and Hyprland binds none unless configured. From there a not-connected Claude Code's or Codex's opened row switches its account (shuizhuyu on X, [Switch accounts only](providers-accounts.md)). 10. A click on the tray icon opens the quick panel, or the main window when Settings › General › Click the tray icon to says so. On the Mac the item takes its left clicks itself (`trayOwnClicks`, `mpOwnClicks`: a local monitor that sends the action and drops the mouse-down) from the moment the tray is made, not when the panel is: the panel is made the first time it is opened (`panelOnFirstOpen`), and that first click after each start, going through the button's own mouse-down tracking, showed the panel and hid it again (Refeccd on Discord, `TestTrayOwnsClicksBeforeThePanel`). The panel opens the main window from one control, on its edge nearest the tray (isaac_bai on Discord): hung below its icon (the Mac's menu bar, a taskbar or bar at the top) it is the header's icon (`#open`, named "Open the main window"); standing above it (Windows' taskbar at the bottom, a bottom panel on Linux) it is the foot's "Open the main window" left of Quit (`#openMain`), and the header has no icon. The two are never shown together (yogurt36 on Discord). Once `togglePanelNow` has placed and shown the panel, `tellPanelSide` reads the panel's bounds and its screen's and sends `magpiePanelOpenAt("foot")` when the panel is nearer the screen's bottom, `"head"` otherwise (`panelOpenAt`; the Mac is always `head`). Under Wayland a window can't read where the compositor put it, and until the app says, layout.js sets `body[data-open-at]` by the system: `foot` on Windows, `head` elsewhere ([`panelside.go`](../../internal/gui/panelside.go), `TestPanelOpensTheWindowFromTheEdgeNearestTheTray`, `panel-open-once.test.cjs`). On Windows a double-click on the icon opens the main window too (isaac_bai on Discord): Wails passes the icon's `WM_LBUTTONDBLCLK` on as `OnDoubleClick`, the panel its first click opened is hidden by `openMain`, and the `WM_LBUTTONUP` that ends the double-click is swallowed once (`trayDouble`, within `trayDoubleRelease`) so it does not open the panel over the window. The Mac's status item calls its action on each mouse-down with no click count, and Linux's StatusNotifierItem has only `Activate`, so there a double-click is two clicks and is left as such (`trayDoubleClicks`, `TestTrayDoubleClickOpensTheWindowOnWindowsOnly`, `TestTrayDoubleClickReleaseSwallowedOnce`; [`traydouble.go`](../../internal/gui/traydouble.go)). ## Constraints and failure behavior ### First opening of an agent's Details In the main window, `expandLink` in [`app.js`](../../internal/gui/assets/app.js) reads an agent's own settings and loads its Long conversations controls before drawing and measuring its opened row. While these are loading, Details shows Loading and is disabled. A failed read keeps the row closed, reports the error and allows retry. A later agent click or leaving Agents supersedes the pending opening. Once prepared, the row slides to its full height; reduced motion opens it at once. Later openings reuse the settings and controls already loaded. `agent-details-ready.test.cjs` holds both responses and checks the final animation frame against the natural height in both engines and five languages. ### Allowance card refreshes A card refresh applies only the requested account from the API's full card list. A whole-page read begun before that refresh completed keeps the newer card when its older response arrives; other cards still update, and a later whole-page read can replace or remove the card. This also keeps two different card refreshes from undoing each other's results. If a refresh first supplies the account's name, its provider's cards are replaced while newer card refreshes and other providers stay. The replaced keys are protected too: an older whole-page response cannot restore an unnamed card or erase its newly named replacement. Only a completed whole-page read retires the ordering markers it no longer needs. A remote magpie's summary can likewise become its namespaced child cards; refreshing it preserves local providers and other remote magpies. `keepRefreshedQuotas` and `quotaRefresh` in [`app.js`](../../internal/gui/assets/app.js) own this publication order; `quota-refresh-order.test.cjs` covers held responses and failures, and `usage-card-refresh.test.cjs` checks the real button in both browser engines and all five languages. A cached `readDeferred` card says no refresh was requested this time; a failed read retains its failure notice. The tray panel's Allowances cards use the same `quotaRefresh`, at the start of the line under the account (the reset deadline, the error, or a balance's name), opened as the card is hovered or the button is focused. That line names the deadline ("Resets 14:26"), so no bare `↻` stands for it; `renderPanelQuota` puts the focus back on the button after the redraw. `panel-quota-refresh.test.cjs` covers it in both engines, all five languages, at 440 and 360px. Redrawing the cards preserves their refresh controls and any running turn. A read of every card (`loadQuotas`) draws the cards again in one go, as their reset countdowns need, but keeps each card's logo node (`keepIcons` in `renderQuotas`): a logo made afresh blinks out while its picture loads. While such a read is on its way for longer than 200 ms, `#subscriptionUsage` is `.reading` and each card's refresh turns (`quotaReading` in `plugins/usage/page.js`). The Overview's skeleton (`renderUsageLoading`) is put up only for a first read or another period or zone (`usageFor`); its tab pressed again while it shows that read reads quietly (`refreshUsage`), so no card leaves and the scroll stays put, and the refresh beside the period turns while it reads. Its lists keep their logos too. See `usage-quiet-refresh.test.cjs` (jiabubu on Discord). The reply updates the reading immediately; the icon then finishes its current full turn before stopping (no rotation under reduced motion). A manual refresh whose HTTP reply succeeds but whose requested card has an error reports that error through the status line too (#4817), including when the card already showed it. Errors on other cards in the reply do not become the requested account's error. An unnamed provider or remote summary that gains named cards reports only failures accepted from that reply; an older error replaced by a newer reading is not reported again. Claude Code's first-run screens are gone through by the helper itself (claude-subscription-bridge.md); one it can't get past ends the read, and that is said on the editor row, Usage card, tray card and refresh notice: finish Claude Code's first-run setup, then refresh; `magpie claude-code` names the executable, including a build magpie downloaded. The original error stays in the card's tooltip, and the read never falls back to `-p`. `claude-quota-onboarding.test.cjs` presses the active account's button in both engines and all five languages, with an account error in a successful HTTP reply, then a successful read after setup and an unrelated card error. ### Streamed output speed Usage rows and aggregates use `Record.Decode` and `DecodeOf` in [`internal/usage/usage.go`](../../internal/usage/usage.go). Routing uses `decodeOf` in [`plugins/routing/client.js`](../../internal/gui/assets/plugins/routing/client.js); Usage rows use `ledDecode` in [`plugins/usage/page.js`](../../internal/gui/assets/plugins/usage/page.js). A reply's speed counts all its output tokens as the vendor's usage counts them, reasoning and tool-call arguments included (Archivemylife on X), from its first output of any kind to its end: the earlier of its first content (`TTFT`) and its first sign of reasoning (`FirstReasoning`). That sign is `firstToken.reasoningMs` in [`ttft.go`](../../internal/gateway/ttft.go), in every protocol: a Responses reasoning item's start, an Anthropic thinking or redacted-thinking block's start, sealed thinking, or reasoning deltas spread over 100 ms or more (deltas that came at once are a buffered burst and tell none). A summary is no sign (`summaryPart`: a Responses reasoning summary's words, a Gemini thought, or one translated from another protocol, `summarized`), as it is written after some of the reasoning it sums up (#1463). A reply that reasoned with no sign of when counts only its answer, its output less the reasoning, from its first text, and none with no text. The burst and held-content checks judge the answer's part: from its first text when it reasoned, else from its first token. These are receive-side timing checks, not access to the vendor's generation clock: a relay that releases a buffered reply evenly can still look paced. `Record.FirstReasoning` (`first_reasoning_ms`) and the corresponding `Call`, `Route` and `Try` field (`firstReasoning`) record this evidence with the same origin as their duration. Historical records have no evidence and keep their previous speed. Request-page caches and compressed snapshots preserve the optional field; the packed row keeps `ReasoningHidden` in its own `Flags` bit (`rowReasoningHidden`), apart from pricing's `swapKnown`, which every priced row carries. `ReasoningHidden` (`reasoning_hidden` in the ledger, `reasoningHidden` in traces) suppresses a no-text speed even when redacted/encrypted thinking has no reported reasoning-token count. A Responses summary is marked this way on its own-login path too, and after an endpoint fallback, where the try's protocol still names the first endpoint, by the upstream that answered (`summaryUpstream` in [`continuation.go`](../../internal/gateway/continuation.go)). Optional OTel attributes carry the evidence without response text. The existing burst and held-content limits in `DecodeOf` still apply, and hidden reasoning does not enter average speed. A streamed request's duration (`Millis`, which ends every speed window) ends when its last try's reply ended, not when `serve` returns: what the gateway writes down after an answer (`answered`'s sticks, the provider's last answer in `NoteServed`) goes to disk, and on a busy disk took seconds, which made a paced reply read as held back and tell no speed (#1939, `TestSpeedEndsWithTheReply`). A decision group's row is timed the same way. `TestVisibleReasoningSpeed`, `TestReasoningSpeedEvidence`, `TestReasoningSpeedThroughGateway`, `TestMixedRedactedReasoning`, `TestHiddenReasoningThroughTranslation`, `TestSlowReleasedReasoningIsUntimed`, `TestPricedRowKeepsReasoningEvidence`, `TestSummaryAfterEndpointFallbackStaysHidden` and [`reasoning-speed.test.cjs`](../../internal/gui/tests/reasoning-speed.test.cjs) cover the calculation, cache round trip, translated streams and both pages. ### Routing purpose filter The request heading's purpose menu in [`plugins/routing/client.js`](../../internal/gui/assets/plugins/routing/client.js) uses `openProtoMenu`'s live checkbox selection: each tick immediately shows requests matching any selected purpose, with the menu kept open. An empty selection, All purposes or Clear filter restores every purpose without changing the day or request/session view. A live menu stays open when its redraw clamps the list's scroll; the reader scrolling outside still dismisses it. Choosing All purposes closes the menu and returns keyboard focus to the purpose button without scrolling; unticking the last checkbox keeps the menu open and focused on that checkbox. A Claude Code subagent's turn has the Subagent tag (`tagKind`, `Route.SubagentID`) and no kind, so it stays under Unmarked, as on the Usage page. Counts, the current story and replay follow the same filtered list. Selected purposes remain available when a day has no matching requests. Opening a request from another page clears the filter only when that request is excluded. Usage's purpose picker remains a single choice sent to the ledger API. See `purpose-filter.test.cjs` and `routing-purpose-state.test.cjs`. ### Routing group lookup caches The routing script's `groupIndexOf` in [`plugins/routing/client.js`](../../internal/gui/assets/plugins/routing/client.js) lazily indexes the current `/api/groups` response by model, group and account ID and caches parsed member IDs. Exact model IDs take precedence over reasoning suffixes; duplicate IDs retain the first match, as array lookup did. A new response replaces the indexes on the next lookup. The maps reference response objects, not copies. They serve both Routing and Routing groups, and are released after both pages have been out of sight for five minutes (including a hidden browser tab); returning cancels expiry. A later lookup rebuilds them from current data. This changes no saved configuration or routing behavior. `group-index.test.cjs` checks lookup work, member semantics, data replacement and expiry with a controlled clock. `hayMatches` caches each group's lower-case search text in that same cache. Queries retain AND and substring matching over group names, IDs, refs, patterns and member labels (including accounts, reasoning and fast/free). Changing the language discards the text cache; a new groups response also invalidates it, including model/provider/account renames and membership changes. Default routing settings and quota readings do not affect search text. `group-search-cache.test.cjs` verifies reuse and invalidation. The group's input event and Escape use `drawGroups`' filter-only path: matching cards are retained, unmatched cards detached and reused if the query changes back. The toolbar, settings and provider pools are left in place, and an open editor and import text keep their live DOM and draft. Bulk selection still drops groups outside the query and rebuilds its selection controls for the shown list. A data, language, settings or quota redraw discards the row cache; filtering also falls back to a full redraw when the data or language changed since the last one. A filter-only draw does not mark new quota readings as painted: after the input loses focus, the usual quota tick refreshes the cards. Detached cards are released with the lookup cache after five minutes away. This is display only; saving, ordering and routing semantics are unchanged. The Hide plans button follows the filtered cards: it appears only when a shown card has a quota line, and its folded choice survives filtering. `group-filter-render.test.cjs` exercises node reuse, drafts and expiry with 4,000 models in both browser engines and all five languages; existing `filter-ime`, `group-pick-filter`, `group-bulk-remove`, `group-arrange`, `group-import-replace` and `group-morph` tests cover their neighboring flows. ### Routing mode chip The stage's chip and the Accounts and keys heading in [`plugins/routing/client.js`](../../internal/gui/assets/plugins/routing/client.js) name how a route routes only where that can be changed: a group, or a provider in `/api/groups`' `pools` (two or more accounts or keys on). There they are `.rt-go` controls (`goTo`, `goRouting`) that bring the group's card or the provider's row under Several accounts or keys into view through `scrollOnPurpose`, mark it (`rt-found`) and focus its routing. A provider with one on names no routing, and the mode paragraph says how to get one (`LONE`). The header is drawn again when the groups come in (`headOf`). See `routing-mode-goes.test.cjs`. ### Routing key and account folds Three or more API keys, or three or more accounts, of one provider standing next to each other for one model (same fixed effort, fallback and group-in-group heading) fold into one stage row, `li.rt-fold` in [`plugins/routing/client.js`](../../internal/gui/assets/plugins/routing/client.js) (`FOLD_AT`, `rebuild`). It shows the count and their state together: the one that is lit and what it is doing, how many are available and how many rest (`together`). Requests that land on a folded seat fly to the fold (`shownRow`). Clicking it (or Enter / Space) shows each in place, wired from the fold. Accounts and keys folds a provider's keys, and its accounts, into one `.rt-keys` row each with their summed tally. A folded fold of accounts, live, also says what they have left together, first in its line, with a bar under it like an account row's (`foldQuota`, chen2652 on Discord): the Usage page's readings of its accounts (`cardOf`) put together by quotaall.js's `mergeQuotas`, the same as the Usage page's "All N accounts" strip, its tightest window that says a share as the figure and the bar, then when that window first starts again, the soonest of the accounts' ("renews in 2h", as an account's row says it; Sdsi134a on X), every window and when the first of them resets on hover. Only when every account in it was read, none is free, and all are on one plan; otherwise, while the fold is open or a kept day is shown, and while the groups page's Hide plans is on (`plansHidden`, `magpie.routingGroupPlans`), it says nothing of it and each account's row has its own. See `routing-fold-accounts-together.test.cjs`. A group in the group's heading (`li.rt-sub`, `subNode`) folds the same way (`toggleSub`): folded, it says how many it routes to and what they do together, a request to any seat under it flies to the heading (`row.shut`), and its wire is the last one drawn (`wiresTo`). Keys start folded. Accounts and group-in-group headings start open when they hold fewer than `LONG` (6), folded otherwise (Aiirobyte on Discord: a group of many accounts took the page). What the reader opens is kept in localStorage `magpie.routingKeysOpen` and what they fold in `magpie.routingFolded` (`keepOpen`, `isOpen`), keyed `provider/model` for keys and `provider/model@` for accounts on the stage, `provider/*` and `provider/@` in the list, and `group/` for a heading. Display only: the gateway's order and choice of seat don't change. Two stay two rows. See `routing-keys-fold.test.cjs` and `routing-group-fold.test.cjs`. How far the stage opens is the reader's to pick (ipsikent on X: often only which model a route uses matters). Expand, at the end of the stage's top line (`#rtDepth`, `DEPTHS`, `openTo`), offers Automatic (as above), Models (two or more accounts or keys of a provider fold, `foldAt`, and start folded) and Accounts (every fold starts open). Both open every group in the group. It is kept in localStorage `magpie.routingDepth`, and picking one forgets what was opened or folded on the stage (the keys without a trailing `/@` or `/*`), so every row follows it at once; a row clicked after it is kept as before. Accounts and keys isn't changed by it. See `routing-depth.test.cjs`. ### Routing account windows A subscription account's row in Accounts and keys shows the one figure routing went by, and each of its windows, with when each resets ("5 hours 40% used · resets in 2h"), on hover over that figure (the `.st`'s title), as the Usage page reads them (#1833). A row with no figure of its own (a remote's, or an account not read yet) shows its windows as its one line instead (`.wins`, cut to one line, all of it on hover). `cardOf` in [`plugins/routing/client.js`](../../internal/gui/assets/plugins/routing/client.js) matches the route's account to app.js's `quotas`: a card of this computer (no `from`) whose `kind` is `subscription` or none (`/api/usage/quotas` sends this computer's cards with no kind; only a remote's are told one, so asking for `subscription` alone matched none in the app) whose provider is the account's `agent` (a plugin's provider id) or its provider, and whose user is the account's, ignoring case. `winsOf` names them with `familyWindows`, `quotaText` and `resetInText`. Nothing new is read: opening Routing asks `/api/usage/quotas` in the ordinary way (`show`, when the readings are missing or over a minute old), never `?asked=1`. A kept day's list shows none, since those requests were weighed by readings long gone. See `routing-account-windows.test.cjs`. A Claude (or Codex) joined over the network, a Remote magpie provider's row, shows the windows of the accounts signed in on that computer the same way (`remoteWinsOf` in `client.js`): the Usage page's cards with `from` whose provider id is the remote's, a slash and the card's. The computer that holds the account tells its usage; this one reads nothing new. A Claude model's row is told Claude's cards alone and a ChatGPT model's Codex's; with more than one card the account's user leads each window. A remote whose read failed, or whose card of the row's family failed there (the remote read, its Claude's read didn't), shows "Allowance unavailable" with the reason on hover, never a figure and never nothing; a remote that holds this computer's key tells why the same way (`errRemoteHeld`). See `routing-remote-windows.test.cjs`. The refresh beside the Accounts and keys heading (`#rtReadAllowances`, #1834) reads them again by hand: `loadQuotas(true)`, the asked read the Usage page's Refresh now makes. It turns while the read is on its way, and a click then asks nothing more. Nothing on the page reads again by itself. It shows only live, with a subscription account listed. See `routing-read-allowances.test.cjs`. On the stage, an account's seat tells the same windows in its tooltip, under its id (`render`, #1835). The row itself keeps one line: the fullest window while idle, what it is doing while it answers. See `routing-seat-windows.test.cjs`. ### Routing account cards Each row under Accounts and keys is one cell like the others: a dot, its name, plan and Try now on one line, and under it what is left (or its rest) in full (ferock4669 and iyou00 on Discord: many keys ran the list on and on). The dot is green for the one in use (of a provider's rows not resting, the one that answered last), amber resting, red for what the reader has to do (`.act`: sign in again, a restriction or verification, a key failing with no answer), grey otherwise. Red is only on `.act` rows: a quota rest or old failures are muted (danzi002 on Discord, "显示的好 乱"). How it fares (tried, answered, failed, last answered) is a line of its own only on a row with nothing else to say or one to act on; on the others (`.said`) it is in the tooltip with the models it answered, under its id. A folded row of keys or accounts names no models. Columns are `min(240px, 40vw)` wide, so a name and its Try now share a line (`routing-acts-calm.test.cjs`). They aren't CSS columns: `packActs` places each provider's box (`.rt-pgrp`) with `--px`/`--py` under `.rt-acts.packed`, in order down a column and on into the next, the columns' ends as level as they go, and a `.long` box's rows run on into the next column, its heading never last in one. CSS columns balanced every row again on each layout, ~24ms a layout in WebKit with a hundred rows, and dragging the window's edge stuttered (lexrus on X). It places on the window's resize, before the frame is drawn, on a render, and a frame after a box changes its height. Beside the requests (`min1150`, not `solo`) the list is one scrolled column and nothing is placed. An account's windows line up with the rows of its own provider (`--wk`, `--wv`, `--wr` per provider), and no part runs past its row: a width the whole list's widest window asked for ran the resets over the column beside. See `routing-account-windows-fit.test.cjs`. `renderActs` in [`plugins/routing/client.js`](../../internal/gui/assets/plugins/routing/client.js) shows the first `ACTS_SHOWN` (8) rows of a longer list and puts the rest behind "Show N more" at its foot (`.rt-acts-foot`), kept across a reload in localStorage `magpie.routingActsAll`. The button clicked stays where it is on the screen while rows come in or go above it (`actMore.onclick` scrolls the page by what it moved). Never behind it: a row that needs the reader (to sign in again, resting, a model resting, failures with no answer, a remote whose allowance can't be read), the rows under a fold the reader opened themselves, and the heading of a provider with a row shown. A row to sign in again is drawn under its fold even while the fold is shut. Two more alone aren't folded. "View usage" beside it opens the Usage page's Overview (`window.openUsageOverview` in `plugins/usage/page.js`), where each account's card says it all, without keeping that tab as the reader's own. See `routing-acts-compact.test.cjs`. ### A provider's accounts together A Usage card of several accounts (not a card of keys, which has its sum) has "All N accounts" under its head, and the tray panel's group of several the same strip above its cards (`quotaAll`, CryptoSarom on X). A routing group's row has a line for each provider among its members: what is left of that provider's accounts together (`groupQuota` in `plugins/routing/client.js`, drawn again when `quotas` is new). `quotaAll` and `mergeQuotas` are in `quotaall.js`, which app.js imports once a provider has two accounts (`quotaAllJS`) and the Routing page once a group's member has readings, so they weigh nothing on the core; each place is drawn again once it is in. All three come from `mergeQuotas`, which puts together only what reads alike: - a counted window (`limit`) of one name and unit adds its amounts and limits, its share the share of the sum; a wallet (`balance`) adds its balances in one unit; - a window said only as a share is the mean of the accounts on one plan, the same allowance each; two plans are never averaged, and a window more than one plan has is named with its plan; - a share is never added to a count; `text` windows are left out; unlimited only where every account read says so; - an account whose reading failed is unknown, not 0, and is counted ("1 couldn't be read"); a window an `asOf` reading stands in for, whose reset has passed, is left out and counted in its tooltip; - a window the account can't spend counts as used up: its `heldBy` (`provider.WithHeldWindows`, set on `/api/usage/quotas`) names another window that stops the account for every model, is used up and starts again after it, as 7 days at 0% left holds 5 hours at 100% (#4791). Not the other way: a week with room behind five hours used up keeps it. The tooltip counts how many were held; each account's own card still shows the vendor's figure; - only what two or more accounts have goes together; family and pool stay, so `familyWindows` folds the result as an account's. No account is named in it, and each account stays below it as it was. There is no switch: it is additive, and the figure follows used or left with the rest. See `usage-merge.test.cjs` (the merge) and `usage-all-accounts.test.cjs` (the three places). Below the strip each account of a card with several is a card of its own inside the provider's (`.subscription-acct`, a box on `--card-2` with a hairline all round; normalcoder_ on X: a hairline between accounts didn't tell them apart). A card of keys keeps its keys as lines, as does a card of one account. The account's menu (`quotaCardMenu`) is found from the box's first row, its name. See `usage-account-subcards.test.cjs`. On the Usage card and in the panel, a click on the strip or its chevron (`.quota-all-fold`, the accounts' own ⌄ with `aria-expanded`) folds that provider's accounts away under it, open by default (justfreefall on X). It is remembered by provider for the window and the panel alike (`magpie.usageAllFolded`, `quotaAllFolded` in `quotaall.js`). Folded, the card's "Show … accounts" button keeps its room but is hidden and inert, so the strip stays where it was. A menu bar cell asking for one of the accounts unfolds them (`focusQuotaCard`). See `usage-all-fold.test.cjs`. The Usage page's allowances are cards, or a table when the reader picks Table in the Allowances head (`#quotaView`; zysicyj on X: a dozen-plus accounts were hard to scan as cards). The pick is kept in localStorage `magpie.quotaView` on this computer and nothing is written until it is made, so the default stays cards. The table (`quotaTable` in `quotatable.js`, which app.js imports once it is picked) has a row per account in the cards' order, so what the cards hide or merge is hidden or merged here too, with the subscription, the account, the four windows most accounts have (each as its used or left share, a bar and when it resets, from the same `quotaFill` and `quotaText` as the cards, so Used/Left turns both) and the rest of an account's windows in a last column; a failed read and a balance say so across the windows. A head sorts by it (most used first for a window, A first for a name), again the other way, a third time back to the cards' order; accounts with nothing in that column stay last. A column is what its windows are of, not their names (`columnOf`; normalcoder_ on X: Antigravity's "Gemini · 5 hours" sat in the last column beside an empty Gemini one). A pooled window goes to its pool's column (`poolWord`, "Claude & GPT" under Claude), naming its window in the cell; any other window goes by its span (`spanOf`: "Weekly", "7 days" and "7d" share one column, headed by the name most rows use, a number on a tie), and a window with no span by its name. A provider with several accounts (grouped as its card groups them) is one row (jay68xu on X, #6740): its name, how many accounts, and each column's share averaged over the accounts that have one; its accounts are rows under it, without the provider's name again, folded until the row is clicked. What is open is kept by provider in localStorage `magpie.quotaTableOpen`. Sorting orders providers by that mean (a name or account by its first account) and accounts within each. A column no row fills is left out (Account when no account is named; the window columns and Other only exist when some row has one). It scrolls in its own box at a narrow width, the subscription held at the left. See `usage-quota-table.test.cjs` and `usage-table-groups.test.cjs`. ### The Sessions page's folders The Sessions page lists an agent's project folders as one list, newest session first ([`client.js`](../../internal/gui/assets/plugins/sessions/client.js)). A row says the folder's name, the folder it is in (home as `~`, from the manage reply's `home`), its newest session's title, when, and how many. Temporary folders, the disk's root and apps' hidden folders under home (`scratch`) wait folded under Other folders at the end; a search, or a session opened from elsewhere, unfolds them. A ZCode session started without a project runs in a folder ZCode made for that one session (`~/.zcode/workspace/draft-` or `-`, ZCode 3.17.2's host): one folder each was 40 folders of one session each, folded under Other folders. They stand as one Draft sessions group after the projects, and a row's tooltip gives the folder it ran in (flandern1211_58540 on Discord, #5754; `sessions-zcode-drafts.test.cjs`). Checkboxes and the Delete bar come only with Select, and Done lets the pick go. Relocate project and Delete all sessions are in a folder's ⋯ menu, shown on hover (always on a touch screen) and on a right-click. See `sessions-folder-list.test.cjs`. ### Routing day tallies Live, an account's row under Accounts and keys counts its tried, answered and failed over the day's whole history, not over the last few requests the gateway keeps (#3351): the two said different things by orders of magnitude, and the day tabs above the section count the day. The counts come with the history read the page already polls (`/api/gateway/history` with no day, its `tallies`), counted by `DayTallies` in [`internal/gateway/history.go`](../../internal/gateway/history.go) from the same files the Usage page reads, keyed as the page groups accounts (provider and user, a key or provider by its id). Each look folds in only the whole lines added to today's files since the last one: a busy day's file is hundreds of MB (#3383), and the page asks every 15 seconds. A request done since the last look is counted at the next one. The note under the heading says the counts are today's. What the history cannot say — the readings the latest request was weighed by, the rests, one model resting alone, the accounts in the kept requests — the page still takes from the trace over these tallies; a day picked, or a purpose picked, counts its own list as before, and the note then points at that list. An older answer without tallies counts the kept requests as it did. See `routing-day-tallies.test.cjs`. ### Stored agent sessions in WSL The Sessions page uses `sessions.ListAgent`; Usage → Sessions uses `sessions.List` and `StatsFor` through the handlers in [`sessions.go`](../../internal/gui/sessions.go) and [`sessions_manage.go`](../../internal/gui/sessions_manage.go). `ListAgent` also lists a session nothing was said in, so it can be cleared away; `List` leaves such a session out. The routes a row opens (conversation, Markdown, Terminal) look the session up with `sessions.Find`. `Find` finds every session `ListAgent` lists, empty ones included, so such a row doesn't answer "no such session" (#2273, `TestFindEmptySession`, `TestEmptySessionOpens`). On Windows, [`internal/sessions/wsl.go`](../../internal/sessions/wsl.go) reads running distros through their WSL shared paths. A stopped distro keeps its cached listing and is not opened; running distros are relisted at most every 30 seconds. For omp, [`ompRootsIn`](../../internal/sessions/omp.go) includes both `~/.omp/agent/sessions` and `~/.omp/profiles//agent/sessions`. Subagents and advisor files count in their parent session. A profile session's Resume command selects its own profile with `omp --profile --resume `, including when resumed through `wsl.exe`. Delete and Restore preserve its original profile path and artifacts. Windows does not discover arbitrary stores selected by a distro's `PI_CODING_AGENT_DIR`, XDG variables or `--session-dir`. ### Desktop fonts Settings → General offers independent interface and code fonts, each with the installed family's actual styles. `GET /api/fonts` calls [`fonts.List`](../../internal/fonts/fonts.go): DirectWrite on Windows, CoreText on macOS and Fontconfig on Linux. Discovery is lazy, cached in the handler, and refreshed by the menu. It returns names and CSS traits, never font files or paths. A failed refresh answers 503 and preserves the previous collection; an empty successful collection is distinct from failure. A `nogui` build can't read the catalogue and answers the app 404. A browser tab (`magpie web`, or the app's page opened in a browser) always has the same rows (Norcleeh on Discord). Its choice is the browser's own, kept in `localStorage` under `magpie.fonts` and applied by `fonts.js` before the first paint: the tab can be on another computer, so it neither changes nor takes the app's `settings.UIFont`/`CodeFont`. A tab's `/api/fonts` is the server's families (none in a nogui build such as Docker or `magpie-cli`, and none when reading them fails, never an error) plus `commonFamilies` in `internal/gui/fonts.go`, in regular and bold. The tab keeps those it draws (`webFonts.drawn` in `webfonts.js`: text in the family measures apart from a generic family's on a canvas), so another computer's fonts, and Safari's user-installed ones, aren't offered. When none is kept, the rows still offer System default. Those are the server's names, so fonts installed only on the browser's computer were missing (Norcleeh again, magpie in Docker). `webfonts.js`, which only a tab loads (app.js `loadFonts` imports it; the app's windows never need it, and it is outside the core script budget), adds them: where the Local Font Access API is (Chromium on https or localhost), `queryLocalFonts()` is called in the press that opens a family menu, once a page, and at load when the `local-fonts` permission is already given; its style names ("SemiBold Condensed Italic") become weight, slope and width. Elsewhere (Safari, Firefox, a plain-http LAN address, a refused permission) the menu's search also takes a typed family: "Use “name”" is offered when the canvas probe says this browser draws it, and greyed out when not. A chosen family the server doesn't list stays in the tab's list on later loads while the browser draws it, so `desktopFonts.available` keeps applying it. Until 10-28 the rows were gated on a boot `fonts` flag, so a nogui server had none, and what "flashed and vanished" on a refresh was Text size: the rows a tab never shows (Text size, the tray click, Open at login, the menu bar's allowances) are `.app-only`, which `body.web` hides before the first paint. `settings.UIFont` and `settings.CodeFont` keep the family, style name, OpenType weight, CSS slope and width percentage. A missing choice keeps the platform default. A settings POST can restore that default with an explicit null; omitting the field preserves it, as does every browser-mode save. `KeepOwn` preserves this computer's choices during sync and backup restore. Invalid traits reject the save without replacing the previous settings. [`fonts.js`](../../internal/gui/assets/fonts.js) applies choices at boot and through `applyPrefs`. After a successful font change `host.fontsChanged` notifies both existing webviews through `receiveFonts`, without waiting for the other window to gain focus; a released lightweight webview uses boot settings when recreated. An in-flight local save ignores the notification and finishes its own queue. The selected family precedes the existing platform fallback stack. The interface and code traits apply independently; explicit component weights still mark emphasis. A choice takes precedence over Omarchy's font, while restoring the default follows the theme again. If discovery finds a saved face missing, the page retains its name, explains the fallback and uses the default until the face is available or the user chooses another. A discovery error never clears a saved choice. The browser's own typography is unchanged. The menus support search, keyboard selection and refresh. Styles are ordered by weight, then normal, italic and oblique; width and name break remaining ties. Family changes keep a matching style where possible, otherwise the nearest regular face; named variable instances are offered without arbitrary axis controls. ### Instance name A browser tab's title names the magpie it shows (starballl on X: several deployed, every tab titled "magpie"): ` · magpie`, plain "magpie" with none. The name is `settings.Name`, set in Settings › Network and sharing › Advanced › Name (`instancename.js`, imported when Settings is drawn), else `MAGPIE_NAME` (`settings.InstanceName`, `EnvName`). The env var only fills in for an empty field and is never written to the file, so a name typed in Settings always wins. `CleanName` keeps it one line of at most 60 characters. boot.js passes the name (`name`) and the env's (`nameEnv`) and, to a browser tab only, sets `document.title` itself for the first paint, so app.js's core carries no code for it; `applyPrefs` sets the title again from every settings read. Only a browser page (`web`) is retitled; the app's windows keep "magpie". The name is this computer's own (`KeepOwn`): sync and a restored backup never bring another magpie's. A Settings save that leaves `name` out keeps it (`settingsapi.Merge`). See `TestInstanceName*` and `instance-name.test.cjs`. ### Recent-call bodies `providersState` in [`providers.go`](../../internal/gui/providers.go) sends recent-call metadata without request or response bodies, including after provider writes (#1521: forty calls' bodies made `/api/providers` about 20 MB). Each call in the gateway's 40-call ring has an `id`, numbered in `Server.record`. Opening a recent call on Gateway fetches its captured previews from `GET /api/gateway/call?id=…` (`Server.RecentCall`), sent `Cache-Control: no-store`. The route sits on the same mux as the rest of the API, so `magpie web`'s key guard covers it. The bodies are the ones the ring kept, masked as the request was (`redacted`); the route doesn't fetch S3 or change capture, export or archival. A call evicted from the ring, or a gateway served by another magpie, returns 404. The page keys a row by that id (`callRow`), keeps fetched bodies in memory while their calls remain in the list, preserves them across summary refreshes, and offers a retry after a failed read. See `TestRecentCallBodiesOnDemand` and `recent-call-bodies.test.cjs`. A request on the Routing page opens to the same bodies (Fate on Discord): its story's head has "Request and response", which fetches `GET /api/gateway/call?route=…` (`Server.RouteCall`) only when pressed. A call carries the Routing request it was (`Call.Route`, the trace's `Route.ID`, set where `serve`, the Codex backend, a refused title and a System One request an app sends (`/v1/systemone`, `serveDecideTries`) record it; the Codex backend's refused key and empty failure too, but not a compaction's, which opens no route: `TestCodexKeyRefusedCarriesItsRoute`); a route id is not a call id. When the ring no longer has it, the story shows the request archive's copy through `archivePanel` if the route names one (`Route.Archive`, `call.archiveName()`, set only when the archive was on for that request), and otherwise says how to turn the archive on; with the archive on (`gateway.archive.on` in `/api/providers`) it says instead that this request isn't in it, made while the archive was off or not saved (wangb on Discord). With the archive on, `/v1/systemone` is kept as a chat request is, and a routing group's Jev classifier, which magpie asks itself, is kept as it went (`archiveOwn` in `systemOne`; its usage row names it): `TestArchiveKeepsSystemOne`, `TestArchiveKeepsJevClassifier`. Still not archived: the Codex backend, draw, embeddings and video, and replies magpie writes itself (`answeredHere`). The Routing page captures nothing of its own. The archive's switch (`POST /api/settings/archive`) sets `RequestArchive` while sync has an S3 bucket and `RequestArchiveLocal` while it has none; `GET /api/archive?name=…` reads this computer's copy first and then the bucket's (`TestArchiveSwitchKeepsOnThisComputer`, `request-archive.test.cjs`). See `TestRoutingRequestOpensItsBodies`, `TestArchiveWholeBodies` and `routing-bodies.test.cjs`. Under the bodies, on Gateway and on Routing, "HTTP headers" folds open a call's headers both ways (usrname1833 on Discord: 查看原始请求和原始响应的 http头): the client's, as they reached magpie, then each request magpie sent upstream for the call, its method, address and headers, and the status, protocol, headers and time of its answer, or the error in place of one (`wireHeadersView` in plugins/usage/page.js; `headers` in `/api/gateway/call`, `Call.Headers`, [`wire_headers.go`](../../internal/gateway/wire_headers.go)). The client's are taken by `headerLogged` in `Handler()` for every request that isn't a GET, HEAD or OPTIONS; what goes upstream by `rpmTransport`, under `s.client`, as it is sent (so a header Go's transport adds itself, `Accept-Encoding` or `Content-Length`, isn't there), and by `provider.SendsThroughPlugin` for an account served by a plugin, which is shown as handed to the plugin: the plugin sends it on to its vendor with headers of its own that magpie doesn't see, and the view says so. A call keeps its first 8 upstream requests (`headerTriesMost`) and a count of the rest. Recording is a copy of each header map; nothing is masked as a request goes. Secrets are taken out when the headers are read, by what each header is (`redact.SecretHeader`: Authorization, cookies, `x-api-key`, any `*-Key`, `*-Token`, `*-Secret`, `*-Auth`, `*-Signature` but `Idempotency-Key` and a count of tokens such as `anthropic-ratelimit-tokens-remaining`), any Bearer or Basic value, and any secret `redact.Scrub` finds in the rest; an address loses its password, a secret-named query value (`?key=`) and its fragment (`scrubURL`). They live with the call in the 40-call ring, and the request archive keeps the upstream ones as `upstream` beside the request's and response's headers, masked the same way; magpie's own requests (System One's decision, a title, a search) keep none. See `TestRecentCallHeadersBothWays`, `TestRecentCallHeadersEachTry`, `TestPluginHandOffHeaders`, `TestSecretHeaderRealNames` and `call-headers.test.cjs`. ### Plugin check-in switches A plugin's Usage-card Auto check-in button reads the persisted `settings.pluginCheckins[provider]` first (`pluginCheckinOn` in [`app.js`](../../internal/gui/assets/app.js)). `/api/state` returns that map without the derived `checkinPlugins` list included by `/api/settings`. An explicit saved false wins over the list; when no saved choice exists, the list's resolved vendor default remains the fallback, and without the list (a state refresh) the switch of the built-in check-in the plugin took over is (`PLUGIN_CHECKIN_INHERITS`, the ids `provider.PluginCheckinOn` names; a test reads both). This keeps a saved switch on through a focus refresh and lets the next click turn it off. [`plugin-checkin.test.cjs`](../../internal/gui/tests/plugin-checkin.test.cjs) covers both response shapes, refreshes and the subsequent toggle. ### Plugin options A plugin provider's editor shows the options its plugin declares (`pluginOptionsField` in [`app.js`](../../internal/gui/assets/app.js); see [provider-plugins.md](provider-plugins.md#a-plugins-own-options)). The plugin's label, description and `confirm` text go in as text, never as HTML. A change is kept in `draft.pluginOptions` until Save, which posts each one to `POST /api/settings/plugin-option` before the provider's own save. An option switched back to where it was is dropped from the draft, so it isn't posted and doesn't make the editor dirty. [`plugin-options.test.cjs`](../../internal/gui/tests/plugin-options.test.cjs) covers it. ### A plugin's own page A community plugin that declares `magpie.page` gets a tab in a Plugins group at the sidebar's foot (`pluginpages.js`, loaded after `plugins.js`), listed from `GET /api/plugin-pages` and again whenever Plugins reloads its list (`window.loadPluginPages`). The tab's title is the plugin's own and is not translated; `renderCrumb` and the sub-nav's label read its plain `` where a built-in tab has `span[data-t]`. The frame is made the first time the page opens and fills the view (`.view.plugin-page`, `.plugin-frame`). The theme and language reach it on every change of `data-theme`, `lang`, `class` or `style` on `:root`. A page gone off or away loses its tab, and the window goes to Plugins if it was on it. The security model, the bridge and the reads are in [plugin-runtime.md](plugin-runtime.md#p4-community-plugins-at-every-point). [`plugin-page.test.cjs`](../../internal/gui/tests/plugin-page.test.cjs) covers it in both engines, every language and a narrow window. ### Shared UI rules - Windows desktop windows and tray panels keep the modal's dimming veil without backdrop blur or saturation: full-window filtering can stall WebView2 while a provider test or sign-in dialog is open. The existing `win` marker from [`layout.js`](../../internal/gui/assets/layout.js) scopes the rule in [`app.css`](../../internal/gui/assets/app.css) to the desktop app; browser pages and other platforms keep their existing effect. `modal-backdrop.test.cjs` checks the computed filter and veil in both engines and modes. - Settings → General is laid out as macOS System Settings is (1ooogle on X): a row says its name alone when that says enough (Appearance, Colorblind mode, Language, Text size, the fonts, the tray click, Open at login, Show in Dock), and keeps one short line where the setting isn't clear from its name or has a consequence (Lightweight mode, Prevent sleep, Session terminal). Codex's, Claude Code's and Grok Build's own settings (Codex subagents, Long conversations, which is all of Grok Build's, background compaction, thread titles and descriptions, composer predictions, the auto-review and memories models) aren't here: they are in the agent's opened row on the Agents page (`AGENT_PREFS`, `connectPanel`), the panel's row has a Settings line that opens them in a sheet (`openAgentPrefs`), as does the agent's menu, and Settings' search finds them with a row that opens that sheet (`#agentPrefLinks`). Each row is one element moved between its places, so its handlers and state go with it (the owner, 10-20; `agent-prefs.test.cjs`). Long conversations is the exception with no Codex, Claude Code or Grok Build here, in gateway mode or a magpie in Docker: it sets the windows the gateway serves, which agents on other computers read, so it stays in General (`renderAgentPrefLinks`, Linka on Discord). A font row's line shows only while its fonts load or fail; the text size keys are the choices' tooltip, and Colorblind mode's note is its Off/On control's (`#colorblindSegs`). Colorblind mode (`settings.Colorblind`, `data-colorblind="1"` on `:root`, #2073) switches the chart series (`--c1`…`--c7`) in both light and dark themes to an Okabe–Ito palette where adjacent series differ in hue and lightness. On a quota curve each window (`data-series`, its index mod 7, set by `drawQuotaPlot` and `quotaCurve`'s legend only) gets a dash of its own on `path.qc-line`, its legend key shows a sample of that line (`.qc-sample`) for the dot, and the even paces (`line.qc-even`) are dotted; the curve's tooltip says so. The balance curve sets no `data-series` and keeps its solid line, dashed fit and dot. The Context tab's "good" grade, which takes `--c2` as a colour rather than a series, keeps a blue (`--c1`). Language is one menu button showing the language picked, opened in the app's menu (`renderLangPick`). See `settings-general.test.cjs` and `quota-curve.test.cjs`. Open at login reads `autostart.Enabled`, which on macOS 13 and later also asks Background Task Management about magpie's launch agent (`SMAppService.statusForLegacyURL:`, matched by the plist's Label, not its path); a record the user switched off in System Settings › General › Login Items reads as needing allowing, and the row keeps On with one line saying so and a button that opens Login Items (`/api/open` allows that one `x-apple.systempreferences` URL). The status read again when the window comes back to the front clears the line. On macOS 12, in a build without cgo, or when the system can't be asked, the plist alone decides, as before (#2120, `login-allow.test.cjs`, `login_allow_test.go`). On Linux it reads the autostart entry the desktop starts: the user's own over a package's in `$XDG_CONFIG_DIRS` (/etc/xdg when unset), as the XDG Autostart spec has it. Off over a package's entry that starts magpie writes a Hidden entry of the user's over it, and on takes that away rather than writing this copy's path (#3372, `autostart_other.go`). - A setting row's line under its name (`.row.pref .sub`, in Settings, Plugins › Built-in and an agent's own settings) wraps whole beside its control, never cut to one line with an ellipsis (arculongus on Discord, `settings-lines-wrap.test.cjs`). - Settings' search-provider picker offers **Off**, saved as `searcher: "off"`. Its help explains API-only search and suppresses provider fallback/own-search hints while off; the search priority row is hidden because no provider competes with the APIs. See [gateway search behavior](gateway-routing.md#turning-provider-search-off), [`renderSearcher`](../../internal/gui/assets/plugins/search/settings.js), `TestSettingsSearchProviderOff` and `searcher-pick.test.cjs`. - A searcher named there gets an "If it fails" row right under it (`renderSearcherThen`). The row holds numbered chips for `searcherThen`, the providers that search in its place, in order. Add offers every searcher but the one named and the ones already listed. A chip's picker changes it or removes it. The row isn't shown for Automatic or Off. The failure line names the one that searched instead (`searchFailed.instead`), or says the ones after it failed too. See `searcher-then.test.cjs`. A picker's item is pressed through `pickItem` in `reader.cjs`, which waits for the list drawn again after `/api/model-speeds` answers (#4274). - Settings' search APIs are asked in their listed order: each API's row (with its keys' row) is dragged as one, or moved with Alt+↑/↓, and has a switch that turns it off without removing its key (#2286). See [the search APIs' order](gateway-routing.md#the-search-apis-order-and-one-switched-off), `searchArrange` in [`plugins/search/settings.js`](../../internal/gui/assets/plugins/search/settings.js) and `search-order.test.cjs`. - Settings' Search APIs add row has a base URL field under the key for every API (#1580): the vendor's own address is its placeholder, picking an API already added fills in its saved URL so a new key alone keeps it, and Add with no key changes only the URL. See [a search API's base URL](gateway-routing.md#a-search-apis-base-url), [`renderSearch`](../../internal/gui/assets/plugins/search/settings.js) and `search-api.test.cjs`. - Every user-visible string has zh, zh-TW, ja and de translations with the same placeholders. `gui-zh-tw.test.cjs`, `gui-ja.test.cjs` and `gui-de.test.cjs` fail on a missing one; `gui-zh-tw.test.cjs` also fails on a zh-TW string with a Simplified character left in it. - A click never moves the page. Code scrolls a view only with the reader's event in hand (`scrollOnPurpose`); `click-scroll.test.cjs` guards this. A click is taken where the reader left the view: a scroll not theirs made just before it, whose scroll event the browser sends only at the next frame, after the click, is put back first (`backToReader` in the click guard, #1554). What was clicked is held where it was (`hold`); a view at its top when clicked stays at its top, and what comes in above the control moves it down instead (#2134, `update-auto.test.cjs`), as long as it moves less than half its own height and so stays under the pointer. When what the click does leaves the page shorter under it (a list emptied), the view keeps room at its foot for it to stay (`.view-room`), room that goes as the reader scrolls back. A control under what it unrolls (`data-unrolls`, "Show 7 more") goes down with what it opens: what's held is the part it is in, so the rows open downwards. A heading drawn anew whose only neighbour above is a zero-height pad (the first part of a skill group's windowed list) is marked so too: the hold passes over a neighbour with no height, so it held the next part's heading, which the rows opened pushed down, and the clicked one went off the top (jinpwng on X, `partHead` in plugins/library/client.js, `library-group-steady.test.cjs`). 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 page scrolled a screen down shows Scroll to top and Scroll to bottom (emo172, #1090): a small capsule of two chevron buttons at the open page's lower right, in its right margin when a wide window leaves one, else over its corner; above Providers' sticky Add buttons. It goes again near the page's top and over a dialog, and, over the corner, at the page's foot, where the last row can't scroll out from under it, unless it has the pointer or focus. It is placed again on a scroll, a resize, a page shown or hidden, and whenever the open page or one of its own children changes size (a `ResizeObserver`, so a Routing group opened or closed moves it off the editor with no scroll, Jiabubu; see `view-ends-relayout.test.cjs`). It never changes the page's height, which the guard below measures. A press is the reader's scroll (`scrollOnPurpose`, then `arrived` once the page stands still), smooth unless motion is reduced; Scroll to bottom is `aria-disabled` at the foot. Each button's name and tooltip are in every language. The code is [`scrollends.js`](../../internal/gui/assets/scrollends.js), imported on the window's first scroll so the core doesn't carry it; the tray panel has none. Home and End scroll a page as before. See `view-ends.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. - The Usage page's allowance cards come in at different times (each vendor's read while `X-Magpie-Reading` asks again, then the curves' history), and a card drawn above the one being read used to push it down the screen (liuzhengdong99 on X). Overview keeps the card being read in place (`keepInView(..., true)` in `plugins/usage/page.js`: the highest card, or part of the page under them, starting in sight; found again by its `data-key` once `renderQuotas` draws the cards anew, and followed after every `packUsage`). Such a view leaves the browser's own anchoring on while it keeps nothing (at its top, on another tab, and while the cards are dragged or moved by keys: `unpin`, so a card lands where its slot showed). Each card's height drawn in full is kept by its key (`usageTall`, localStorage `magpie.usageCardTall`), and a card still waiting on its read or its curve (`usageWaiting`; the history's first answer ends the wait, an empty one too, `loadQuotaHist`) is packed at least that tall, and packed in the number of columns they were last drawn whole in at that width (`usageTall["#" + most]`), since the heights kept are that layout's; so on the next start the cards fill in without the page moving. See `usage-cards-steady.test.cjs`. - 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`. - An agent's model list (`openAgentModels`) shows every model by default; an agent with none shown can't connect and says so (AllHiddenError opens the list), so the default stays and a saved list is never changed. In its rail of providers (more than two providers, 600px or wider) each row has a tri-state tick at its end (`.am-rk`, `role=checkbox`, `aria-checked` true, mixed or false): a click shows or hides every model of that provider without picking it, a model in use staying shown as Hide all keeps it; *All providers*' tick is the foot's Show all / Hide all, asked twice (coolAndyHe on X, `agent-models-provider-ticks.test.cjs`). - There are no native `