diff --git a/docs/subsystems/gui-shell.md b/docs/subsystems/gui-shell.md index b48553962..b53d8a494 100644 --- a/docs/subsystems/gui-shell.md +++ b/docs/subsystems/gui-shell.md @@ -19,7 +19,7 @@ three. | 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 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`). Opening on it scrolls nothing. See `last-page.test.cjs`. | [`assets/app.js`](../../internal/gui/assets/app.js), [`assets/app.css`](../../internal/gui/assets/app.css) | +| Window navigation | In the window from 1024 points wide (`SIDE_AT`, the same width as app.css's `side-nav` rules), `layoutNav` moves the brand, the pages (`#nav`) and Settings into the sidebar (`#side`): the pages in four groups (Work, Models, Insights, Extend; a group none of whose pages shows, as in gateway mode, leaves out its name), the gateway's address at its foot (`sideGwRead`, read from `/api/providers` only while there is a sidebar, 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 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`, which `navHides` and `offView` ask beside gateway mode and the built-in plugins, so a hidden page's link or kept place opens Providers (Agents hidden: `start.js`), and Providers cannot be hidden (`nav-pages-hidden.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`). 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) | diff --git a/internal/gui/assets/app.js b/internal/gui/assets/app.js index 3349dfd65..fef052922 100644 --- a/internal/gui/assets/app.js +++ b/internal/gui/assets/app.js @@ -19988,6 +19988,7 @@ function renderSettings() { $("#birdSegs").replaceChildren(segs([["off", t("Off")], ["on", t("On")]], s.noBird ? "off" : "on", (v) => savePrefs({ ...keep, noBird: v === "off" }))); renderLangPick(s, keep); renderGatewayMode(s); + window.renderNavPages ? renderNavPages() : import("./navpages.js").then(() => renderNavPages(), () => {}); // a browser tab has its own zoom, and magpie leaves it to it $("#textSizeRow").hidden = web; // the keys that do it too, in the choices' tooltip @@ -20217,9 +20218,6 @@ function renderSettings() { setSetTab(setTab); } -// Gateway mode's switch, in magpie web alone (gatewaymode.go): Automatic -// (on with --gateway or no agents here), On or Off. Turned, the tabs follow -// at once. function renderGatewayMode(s) { $("#gatewayModeRow").hidden = !web; if (!web) return; @@ -23193,9 +23191,7 @@ async function show(v) { jumpNext = false; // a built-in page a plugin's page replaces (magpie.page.replaces) opens that v = magpie.replacing?.(v) || v; - // a page gateway mode leaves out (a link to it, an address kept) opens Providers if (gatewayMode && GATEWAY_HIDES.includes(v)) v = "providers"; - // and one a built-in plugin switched off has, offView v = offView(v); if (v !== view) { if (v === "plugins" && pluginUpdates) window.pluginTabTo?.("installed"); @@ -23223,7 +23219,6 @@ async function show(v) { view = v; renderBack(); window.hideAccounts?.page(); - // the page the reader leaves is the one the window opens on next (keptView) if (mode === "window") { try { localStorage.setItem("magpie.lastView", v); } catch { /* not kept */ } } const title = pageName(v); $("#pageTitle").dataset.en = title; @@ -23289,23 +23284,18 @@ function setGatewayMode(on) { } // offView: v, or the page a plugin switched off sends it to (yyddbds) function offView(v) { - if (!featureHides($(`#nav button[data-view="${v}"]`))) return v; - if (v === "groups" && !featureHides($('#nav button[data-view="routing"]'))) return "routing"; - return gatewayMode ? "providers" : "agents"; + const gone = (x) => featureHides($(`#nav button[data-view="${x}"]`)) || navMine().includes(x); + if (!gone(v)) return v; + if (v === "groups" && !gone("routing")) return "routing"; + return gatewayMode || gone("agents") ? "providers" : "agents"; } -// navHides leaves out the tabs of the pages gateway mode or a built-in -// plugin switched off leaves out +const navMine = () => { try { return JSON.parse(localStorage.getItem("magpie.navHidden") || "[]"); } catch { return []; } }; // navpages.js function navHides() { if (mode !== "window") return; - for (const b of $("#nav").querySelectorAll("button[data-view]")) b.hidden = (gatewayMode && GATEWAY_HIDES.includes(b.dataset.view)) || featureHides(b); + for (const b of $("#nav").querySelectorAll("button[data-view]")) b.hidden = (gatewayMode && GATEWAY_HIDES.includes(b.dataset.view)) || featureHides(b) || navMine().includes(b.dataset.view); } -// applyFeatures takes the built-in plugins' state from a read of the -// settings, or a switch on Plugins › Built-in: -// what is off leaves the window, and the page open, if it went, gives way -// to Agents (Providers in gateway mode) function applyFeatures(list) { if (!Array.isArray(list)) return; - // each plugin's settings to its code in the page (kernel.js) for (const f of list) if (f.schema) magpie.configure(f.id, f.config); const off = new Set(list.filter((f) => !f.on).map((f) => f.id)); if (off.size === featuresOff.size && [...off].every((id) => featuresOff.has(id))) return; @@ -23320,8 +23310,6 @@ function applyFeatures(list) { setSetTab(setTab); navSubs(); } -// Plugins › Built-in: a row and a switch each (plugins.yml, builtins.go); -// one in use can't be switched off; its settings under it (ui.form) function renderBuiltins(box, list, done) { const broken = list.find((f) => f.broken)?.broken; const rows = list.flatMap((f) => { diff --git a/internal/gui/assets/i18n.js b/internal/gui/assets/i18n.js index df864c8b9..da1e5555c 100644 --- a/internal/gui/assets/i18n.js +++ b/internal/gui/assets/i18n.js @@ -781,6 +781,8 @@ const I18N = { "Drag to put them in the order {agent} lists them; new models go last": "拖动排列 {agent} 列表中的顺序;新模型排在最后", "Drag to put them in the order magpie hands them to {agent}; new models go last": "拖动排列 magpie 交给 {agent} 的模型顺序;新模型排在最后", "{n} hidden": "已隐藏 {n} 个", + "Sidebar pages": "侧边栏页面", + "All shown": "全部显示", "{n} at 0": "{n} 个为 0", "Fold the ones at 0": "收起为 0 的", "Nothing left here: every window used up, or a balance of 0": "已没有剩余额度的账号和密钥:每个额度窗口都已用完,或余额为 0", @@ -5852,6 +5854,8 @@ const I18N = { "Drag to put them in the order {agent} lists them; new models go last": "拖動排列 {agent} 列表中的順序;新模型排在最後", "Drag to put them in the order magpie hands them to {agent}; new models go last": "拖動排列 magpie 交給 {agent} 的模型順序;新模型排在最後", "{n} hidden": "已隱藏 {n} 個", + "Sidebar pages": "側邊欄頁面", + "All shown": "全部顯示", "{n} at 0": "{n} 個為 0", "Fold the ones at 0": "收起為 0 的", "Nothing left here: every window used up, or a balance of 0": "已沒有剩餘額度的帳號和金鑰:每個額度時段都已用完,或餘額為 0", @@ -10888,6 +10892,8 @@ const I18N = { "Drag to put them in the order {agent} lists them; new models go last": "ドラッグで {agent} の一覧の並び順を変更。新しいモデルは末尾に追加されます", "Drag to put them in the order magpie hands them to {agent}; new models go last": "ドラッグで magpie が {agent} に渡すモデルの並び順を変更。新しいモデルは末尾に追加されます", "{n} hidden": "{n} 件非表示", + "Sidebar pages": "サイドバーのページ", + "All shown": "すべて表示", "{n} at 0": "{n} 件が 0", "Fold the ones at 0": "0 のものをたたむ", "Nothing left here: every window used up, or a balance of 0": "残りがないアカウントとキー:すべてのウィンドウを使い切ったか、残高が 0", @@ -15942,6 +15948,8 @@ const I18N = { "Drag to put them in the order {agent} lists them; new models go last": "Ziehen, um die Reihenfolge in {agent} festzulegen; neue Modelle kommen ans Ende", "Drag to put them in the order magpie hands them to {agent}; new models go last": "Ziehen, um die Reihenfolge festzulegen, in der magpie {agent} die Modelle übergibt; neue Modelle kommen ans Ende", "{n} hidden": "{n} ausgeblendet", + "Sidebar pages": "Seiten in der Seitenleiste", + "All shown": "Alle sichtbar", "{n} at 0": "{n} bei 0", "Fold the ones at 0": "Die bei 0 einklappen", "Nothing left here: every window used up, or a balance of 0": "Konten und Schlüssel ohne Rest: jedes Zeitfenster aufgebraucht oder ein Guthaben von 0", diff --git a/internal/gui/assets/index.html b/internal/gui/assets/index.html index 2cf3f6192..9732618e2 100644 --- a/internal/gui/assets/index.html +++ b/internal/gui/assets/index.html @@ -193,6 +193,9 @@
Gateway mode
+
Text size
diff --git a/internal/gui/assets/navpages.js b/internal/gui/assets/navpages.js new file mode 100644 index 000000000..9d1932fb5 --- /dev/null +++ b/internal/gui/assets/navpages.js @@ -0,0 +1,36 @@ +// Settings › General › Sidebar pages (youimark on X: a docker gateway has +// no use for Agents or Library): which pages this browser leaves out of +// the sidebar, kept in localStorage magpie.navHidden as this reader's own +// (navMine in app.js reads it). app.js imports this when Settings draws, +// so it weighs nothing on the core. +window.renderNavPages = function () { + const row = $("#navPagesRow"); + if (!row) return; + const pages = [...$("#nav").querySelectorAll("button[data-view]")] + .filter((b) => b.dataset.view !== "providers" && !(gatewayMode && GATEWAY_HIDES.includes(b.dataset.view)) && !featureHides(b)) + .map((b) => ({ v: b.dataset.view, name: b.querySelector("[data-t]")?.dataset.en || b.textContent.trim() })); + row.hidden = mode !== "window" || !pages.length; + if (row.hidden) return; + const mine = navMine(); + const n = pages.filter((p) => mine.includes(p.v)).length; + let b = row.querySelector(".nav-pages-pick"); + if (!b) { + b = el("button", "sess-pick pref-pick nav-pages-pick"); + b.type = "button"; + menuOf(b); + b.onclick = () => { + const now = navMine(); + openProtoMenu(b, pages.map((p) => ({ v: p.v, name: p.name })), pages.map((p) => p.v).filter((v) => !now.includes(v)), (shown) => { + const keep = now.filter((v) => !pages.some((p) => p.v === v)); + const hide = [...keep, ...pages.map((p) => p.v).filter((v) => !shown.includes(v))]; + try { localStorage.setItem("magpie.navHidden", JSON.stringify(hide)); } catch { /* not kept */ } + navHides(); + if (offView(view) !== view) show(offView(view)); + else if (!sideNav()) slide($("#nav"), "nav"); + window.renderNavPages(); + }, "Sidebar pages", "", "left", true); + }; + row.append(b); + } + b.textContent = n ? t("{n} hidden", { n }) : t("All shown"); +}; diff --git a/internal/gui/assets/start.js b/internal/gui/assets/start.js index 7430abade..2d320c94d 100644 --- a/internal/gui/assets/start.js +++ b/internal/gui/assets/start.js @@ -17,7 +17,7 @@ function keptView() { try { v = localStorage.getItem("magpie.lastView") || ""; } catch { /* none kept */ } return OPEN_VIEWS.includes(v) ? v : ""; // one gateway mode leaves out, show() makes Providers } -const firstView = mode === "window" ? keptView() : ""; +const firstView = mode === "window" ? keptView() || (navMine().includes("agents") ? "providers" : "") : ""; // from the tray panel's More in Plugins (q): Discover, once show() picked the tab (#3579) if (OPEN_VIEWS.includes(firstView)) show(firstView).then(() => view === "plugins" && params.has("q") && window.pluginQuery?.(params.get("q"))); else if (mode === "window" && !gatewayMode && !sideNav()) slide($("#nav"), "nav"); diff --git a/internal/gui/tests/nav-pages-hidden.test.cjs b/internal/gui/tests/nav-pages-hidden.test.cjs new file mode 100644 index 000000000..5b8934f7a --- /dev/null +++ b/internal/gui/tests/nav-pages-hidden.test.cjs @@ -0,0 +1,74 @@ +// Run with Node's test runner and Playwright on the module path; see README.md. +// Settings › General › Sidebar pages (youimark on X: a docker gateway has no +// use for Agents or Library): the pages ticked off leave the sidebar, are +// kept for this browser (localStorage magpie.navHidden), and the window +// that would open on one opens Providers. Chromium and WebKit. No backend: +// the API is faked. +const assert = require("node:assert/strict"); +const fs = require("node:fs/promises"); +const path = require("node:path"); +const { test } = require("node:test"); +const { chromium, webkit } = require("playwright"); + +const assets = path.resolve(__dirname, "../assets"); +const BASE = "http://magpie.test/"; + +function server({ web = false, gateway = false } = {}) { + return async (route) => { + const url = new URL(route.request().url()); + const json = (d) => route.fulfill({ json: d }); + if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"en",theme:"light",web:${web}${gateway ? ",gateway:true" : ""}};` }); + if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" }); + if (url.pathname === "/api/state") return json({ agents: [], profiles: [], settings: { lang: "en", theme: "light" } }); + if (url.pathname === "/api/settings") return json({ theme: "light", lang: "en", version: "0.1.400", gateway: "http://127.0.0.1:3425", web, gatewayOn: web && gateway, visionModels: [], imageGenModels: [], lanURLs: [] }); + if (url.pathname === "/api/providers") return json({ providers: [], presets: [], excluded: [], gateway: { running: true, window: true } }); + if (url.pathname === "/api/plugins") return json({ plugins: [] }); + if (url.pathname === "/api/usage/quotas") return json([]); + if (url.pathname === "/api/groups") return json({ groups: [], models: [] }); + if (url.pathname === "/api/window/fit") return route.fulfill({ status: 204 }); + if (url.pathname.startsWith("/api/")) return json({}); + const file = path.join(assets, url.pathname === "/" ? "index.html" : url.pathname); + const contentType = { ".html": "text/html", ".js": "text/javascript", ".css": "text/css", ".svg": "image/svg+xml", ".png": "image/png" }[path.extname(file)]; + try { await route.fulfill({ body: await fs.readFile(file), contentType }); } catch { await route.fulfill({ status: 404, body: "" }); } + }; +} + + +for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) { + test(`${engine}: a page left out of the sidebar stays out, for this browser`, async (t) => { + const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" })); + t.after(() => browser.close()); + const context = await browser.newContext({ viewport: { width: 1100, height: 700 }, reducedMotion: "reduce" }); + const page = await context.newPage(); + page.setDefaultTimeout(5000); + page.setDefaultNavigationTimeout(60000); + const errors = []; + page.on("pageerror", (e) => errors.push(e.message)); + await page.route("**/*", server()); + const hidden = () => page.evaluate(() => [...document.querySelectorAll("#nav button[data-view]")].filter((b) => b.hidden).map((b) => b.dataset.view)); + await page.goto(BASE + "?view=settings"); + await page.waitForSelector("#navPagesRow:not([hidden]) .nav-pages-pick"); + assert.deepEqual(await hidden(), [], "all shown at first"); + assert.match(await page.locator(".nav-pages-pick").innerText(), /All shown/); + await page.locator(".nav-pages-pick").click(); + await page.locator(".pm-item", { hasText: /^Agents/ }).click(); + await page.locator(".pm-item", { hasText: /^Library/ }).click(); + await page.keyboard.press("Escape"); + assert.deepEqual((await hidden()).sort(), ["agents", "library"]); + assert.match(await page.locator(".nav-pages-pick").innerText(), /2 hidden/); + // kept: a reload, and the window opening on Agents, gives way to Providers + await page.evaluate(() => localStorage.removeItem("magpie.lastView")); // as a window opened fresh + await page.goto(BASE); + await page.waitForSelector("#nav button.on"); + assert.deepEqual((await hidden()).sort(), ["agents", "library"]); + assert.equal(await page.evaluate(() => document.querySelector("#nav button.on").dataset.view), "providers"); + // and put back + await page.goto(BASE + "?view=settings"); + await page.waitForSelector(".nav-pages-pick"); + await page.locator(".nav-pages-pick").click(); + await page.locator(".pm-item", { hasText: /^Agents/ }).click(); + await page.keyboard.press("Escape"); + assert.deepEqual(await hidden(), ["library"]); + assert.deepEqual(errors, []); + }); +}