gui: Library is a plugin's page, its script, style and words in plugins/library

P2 of docs/subsystems/plugin-runtime.md, the second page after Sessions.

- library.js and library.css move to assets/plugins/library/ (client.js,
  library.css). The script registers with the kernel
  (magpie.plugin("library")) and adds its page to the "page" slot. Its
  hooks: open and relang load, redraw, close (its modal), dirty, discard.
  What it set up at load (list scroll and resize, the modal's backdrop
  and Escape, beforeunload, the stuck header, a quiet reload on focus)
  runs in mount.
- app.js calls those through magpie.call instead of window.loadLibrary,
  redrawLibrary, closeLibraryModal, libraryDirty and discardLibrary. It
  no longer lists library in its title map, hide loop or OPEN_VIEWS; the
  kernel's pages are in them.
- index.html: <main id="view-library"> goes, the kernel makes it.
  library.css keeps its place in the cascade.
- The 560 strings only Library says move from i18n.js to
  plugins/library/i18n.js (4 languages). i18n.js: 18826 → 16584 lines.
- plugins/library/library.go lists the client files.
- Tests that read i18n.js for a Library string read strings.cjs (i18n.js
  and the plugins'): 8 library tests and mcp-editor-cancel,
  mcp-oauth-app, mcp-signin-health. font-cascade, win-fonts and
  assets_revalidate_test.go name the new paths.
- "Check again" stays in i18n.js: Library said it alone when the words
  were split, and a5d72a095 (Settings' search keys) says it too since.
  i18n-keys has a new test, "a plugin's words are its own": a key in a
  plugin's i18n.js that any file outside the plugin's folder says fails
  it, naming the file. It was red on this key, and search-keys.test.cjs
  said "Check again" had no zh translation.
- docs: library.md, gui-shell.md, plugin-runtime.md.

Run, at this tree:
- 101 GUI test files touching Library, skills, MCP, the plugins, the
  shell and every language (gui-de/ja/zh-tw, i18n-keys, page-width,
  view-no-sideways, mobile-web, text-size, …): Chromium and WebKit, 4 at
  a time, all green but one. text-size's "zh: 100% picked at the foot"
  failed once in Chromium under load ("scrolled from 160 to 109 (max
  115)"); it passed alone, 6 at once here and on origin/main 8f34bbcd1,
  and at 6× and 12× CPU throttling. It's the Settings page, already
  "fixed" by 50dd39104, so I filed it as #2058.
- After rebasing onto origin/main 75cbc7e1e: i18n-keys, search-keys,
  library-mcp-tools, library-all, gui-de, mono-icon-redraw,
  group-first-token, Chromium and WebKit, green.
- go test ./internal/gui/ ./internal/pluginrt/ ./plugins/...; gofmt;
  go vet on darwin, GOOS=linux -tags nogui, GOOS=windows: clean.
This commit is contained in:
yetone
2026-10-14 08:33:25 +08:00
parent 5b76aa4da7
commit 8da304767a
25 changed files with 2383 additions and 2321 deletions
+1 -1
View File
@@ -15,7 +15,7 @@ three.
| 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). `stopServing` drains requests in flight. | [`backend.go`](../../internal/gui/backend.go) |
| API and assets | `Handler` serves `assets/` (embedded with `//go:embed assets`) and the `/api/*` routes, such as `/api/state`, `/api/set` and `/api/agents/{action}/{id}`. `held` lets one API request's reads share one catalog build (`provider.Hold`), and drops it after any write. `revalidated` and `versionedPage` name each script by its content hash, so a cache never serves an old `app.js` under a new page; a file asked for under its current hash (`?v=`) is cached for good (`immutable`), anything else is revalidated by its ETag. | [`api.go`](../../internal/gui/api.go) |
| Browser mode | `StartWeb` serves the page and the gateway for `magpie web`. The browser signs in with a run key in a link. Gateway mode shows Providers, Gateway, Routing, Usage, Sessions, Plugins and Settings on a machine that is only a gateway. `webHandler` gzips the page's text files and the API's JSON for a browser that takes gzip (`webCompressed`, with a `-gzip` ETag that still answers 304); the app's own windows read the page in-process and get it uncompressed. | [`web.go`](../../internal/gui/web.go), [`gatewaymode.go`](../../internal/gui/gatewaymode.go) |
| The page | `app.js` keeps one state object per view and renders it into a list, with no framework. The views have their own files: `routing.js`, `library.js`, `plugins.js` and `context.js`, and those a plugin adds under `assets/plugins/<id>/` (the Gateway and Sessions pages, see [plugin runtime](plugin-runtime.md)) (Usage's Context tab, and the context window card the Routing page draws under a request's story, fed by `/api/context` in `context.go`, which scores and tags each agent; clicking a part, a cell or an item opens its text from `/api/context/text`, the last 10 requests' masked bodies in memory (`openCtxText`), rendered 100 items and 20000 characters at a time; its "Tuned for you" cards are fed by `/api/tune` in `tune.go`, see [agent wiring](agent-wiring.md)). Strings go through `t()` with translations in `i18n.js`, and a plugin's own in its `i18n.js` (zh, zh-TW, ja and de; the English text is the key and the fallback). zh-TW is Traditional Chinese with Taiwan's words; a system language of zh-TW, zh-HK, zh-MO or any zh-Hant picks it, and the tray menu and notifications follow (`trayLang`). Dropdowns use `openProtoMenu`. Every app menu (`openProtoMenu`, `openRowMenu`, `openSessCombo`) is placed by `placeMenu`: under its anchor, or over it when the window runs out below; one that fits neither way takes the larger room, its height held to it, and scrolls inside itself, and a scroll inside a menu doesn't close it (#1437, `removed-groups-menu-scroll.test.cjs`). The highest any popover goes is `popTop`: 8px under `header.top` on a Mac window, where the traffic lights are drawn over the page, and 8px from the top elsewhere; `placeMenu`, the field picker's `placePop` (which also holds `#pop`'s height to that room) and an agent's model list (`openAgentModels`) all use it (#1573, `popover-mac-chrome.test.cjs`). Scrolling is done only by `scrollOnPurpose(e)` with the reader's event. | [`assets/app.js`](../../internal/gui/assets/app.js), [`assets/i18n.js`](../../internal/gui/assets/i18n.js) |
| 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: `routing.js`, `plugins.js` and `context.js`, and those a plugin adds under `assets/plugins/<id>/` (the Gateway, Sessions and Library pages, see [plugin runtime](plugin-runtime.md)) (Usage's Context tab, and the context window card the Routing page draws under a request's story, fed by `/api/context` in `context.go`, which scores and tags each agent; clicking a part, a cell or an item opens its text from `/api/context/text`, the last 10 requests' masked bodies in memory (`openCtxText`), rendered 100 items and 20000 characters at a time; its "Tuned for you" cards are fed by `/api/tune` in `tune.go`, see [agent wiring](agent-wiring.md)). Strings go through `t()` with translations in `i18n.js`, and a plugin's own in its `i18n.js` (zh, zh-TW, ja and de; the English text is the key and the fallback). zh-TW is Traditional Chinese with Taiwan's words; a system language of zh-TW, zh-HK, zh-MO or any zh-Hant picks it, and the tray menu and notifications follow (`trayLang`). Dropdowns use `openProtoMenu`. Every app menu (`openProtoMenu`, `openRowMenu`, `openSessCombo`) is placed by `placeMenu`: under its anchor, or over it when the window runs out below; one that fits neither way takes the larger room, its height held to it, and scrolls inside itself, and a scroll inside a menu doesn't close it (#1437, `removed-groups-menu-scroll.test.cjs`). The highest any popover goes is `popTop`: 8px under `header.top` on a Mac window, where the traffic lights are drawn over the page, and 8px from the top elsewhere; `placeMenu`, the field picker's `placePop` (which also holds `#pop`'s height to that room) and an agent's model list (`openAgentModels`) all use it (#1573, `popover-mac-chrome.test.cjs`). Scrolling is done only by `scrollOnPurpose(e)` with the reader's event. | [`assets/app.js`](../../internal/gui/assets/app.js), [`assets/i18n.js`](../../internal/gui/assets/i18n.js) |
| Window navigation | In the window from 1024 points wide (`SIDE_AT`, the same width as app.css's `side-nav` rules), `layoutNav` moves the brand, the pages (`#nav`) and Settings into the sidebar (`#side`): the pages in four groups (Work, Models, Insights, Extend; a group none of whose pages shows, as in gateway mode, leaves out its name), the gateway's address at its foot (`sideGwRead`, read from `/api/providers` only while there is a sidebar), and the header a breadcrumb (`renderCrumb`). The open page's own tabs (`NAV_SUBS`: Usage, Library, Plugins, Settings) are listed under it as `.nav-s` rows (`role="tab"`, `data-of` the page tab's id) and the page's strip is hidden; a row's click clicks that tab at once, the selection (`.nav-hl`) having set off as the row was pressed (`navSubGlide`; back if the press leaves the row), and is the list's only shape: a row hovered or pressed has no ground of its own, and a `MutationObserver` draws the list again when the strip changes. A page's tabs share its one scroll, so a row that picks another tab opens it at its top (`scrollOnPurpose` with the row's click); the tab already open, picked again, leaves the page where it is (`sidebar-tab-top.test.cjs`). The list opens and folds with an iOS-like spring (`navSubEnter`, `navSubLeave`; none under reduced motion), and a folding list is out of reach at once. Narrower, the page beside a sidebar would be narrower than Usage's requests table needs (768 points), so they go back into the header's row, as a Mac sidebar gives way in a narrow window. At every width the reader can pick the sidebar or the header's tabs from the title bar's button (`#sideToggle`, ⌃⌘S or Ctrl+Shift+S; `toggleSideNav`), kept in localStorage `magpie.navLayout` (`side` or `top`) and so laid out from the first frame; none picked, the sidebar comes from `SIDE_AT`. Picked in a narrow window the sidebar is narrower (184 points under 860), and magpie web on a phone keeps its own tab bar and has no button. The two layouts trade places in a view transition (`navMorph`, app.css `.nav-morph`): the sidebar slides, each page's tab flies to its place in the other, and the page slides as one (its old image dropped, so no line prints twice); without view transitions, under reduced motion, or in the Linux app the change is at once: WebKitGTK with compositing off (`WEBKIT_DISABLE_COMPOSITING_MODE`, which `webkit_linux.go` sets under Wayland) crashes in a view transition. Elsewhere a transition still going after `MORPH_MAX` (1.5s) is skipped, so a webview that never ends one can't leave the window on the old layout's picture. See `side-toggle.test.cjs`. A window made wider or narrower drops what a click held (`heldWidth`): the page laid out again isn't the click's doing. The reader's own place is kept instead for a second while the page is laid out again (`relaid`, a `ResizeObserver` on the open page's parts calling `backToReader`): crossing `SIDE_AT` the browser clamps the scroll to each layout it passes through, and the page ended short of its foot (#1672, `text-size.test.cjs`). See `sidebar.test.cjs`. A sidebar longer than a short window keeps no scroll bar beside its pages: the native bars of `.side-scroll` and `.side-foot` are hidden, and `sideBars` lays a thin bar over each box's edge that shows while it scrolls, fades about a second after it stops (kept while hovered or dragged), can be dragged or clicked to page, and is gone when the box fits, the same in WebKit, WebView2 and WebKitGTK. See `sidebar-overlay-scrollbar.test.cjs`. The window opens on the page the reader last left, as a Mac app comes back as it was (molvqingtai and lc on Discord): `show` keeps the page in localStorage `magpie.lastView` (which the app's webview keeps across restarts, as it keeps `magpie.navLayout`), and `keptView` opens it at start. A page asked for in the address (`?view=`, the tray's links, a reload) wins, Agents too; a kept name that is no page opens the first page, and one gateway mode leaves out opens Providers (`show`). Opening on it scrolls nothing. See `last-page.test.cjs`. | [`assets/app.js`](../../internal/gui/assets/app.js), [`assets/app.css`](../../internal/gui/assets/app.css) |
| 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 page (Essential). A plugin on with settings has their rows under its row, drawn from its schema by the kernel's `ui.form`, and a change posts `{id, config}`. The Gateway page is drawn by its plugin's own scripts through the window's kernel (`kernel.js`, `assets/plugins/gateway/`); see the [plugin runtime](plugin-runtime.md), "The window's kernel". They are `plugins/*` registered with the [plugin runtime](plugin-runtime.md); `GET /api/plugins/builtin` says each one (`builtinJSON`: on is active, the user's own choice, what of it is in use) and `POST {id, on}` (or `{id, config}`) writes plugins.yml. A page marks what goes with a plugin `data-feature="<id>"`. Off, `featureStyle` hides everything so marked (rows drawn later too), `navHides` leaves its page's tab out of the sidebar and the header, `show` opens Agents for an address kept for it, and `setSetTab`, `partShows` and `findSettings` leave its Settings tab and rows out, of the search too. One in use stays on: its switch is disabled and the row says what uses it, and the POST refuses it off. A plugins.yml that doesn't parse is said above the list and no switch moves. `boot.js` says which are off (`featuresOff`) and their settings (`pluginConfig`) before the first paint, and `settings.builtins` carries the list on every state read. The TUI doesn't follow them. See `builtins.test.cjs`, `builtins_test.go`. | [`builtins.go`](../../internal/gui/builtins.go), [`assets/plugins.js`](../../internal/gui/assets/plugins.js), [`assets/app.js`](../../internal/gui/assets/app.js) |
| No GUI build | `-tags nogui` builds magpie without the GUI: `hasGUI` is false and `runGUI` says to use `magpie tui`. The files of `internal/gui` that need Wails build under `!nogui`. | [`gui_off.go`](../../internal/cli/gui_off.go) |
File diff suppressed because one or more lines are too long
+14 -2
View File
@@ -92,7 +92,9 @@ the head, each with its `?v=`.
Each page moves in a commit of its own, whole: its code into
`assets/plugins/<id>/client.js`, its styles beside it, and the words only it
says from i18n.js into its `i18n.js` (a key app.js, another page, index.html
or Go also says stays in i18n.js).
or Go also says stays in i18n.js). It stays so after: `i18n-keys`' "a
plugin's words are its own" fails when anything outside a plugin's folder
says one of its words, which goes back to i18n.js.
- **Sessions** (`plugins/sessions`, `Client: i18n.js, sessions.css,
client.js`): the page that was `sessions.js`, its markup all drawn by its
@@ -102,6 +104,15 @@ or Go also says stays in i18n.js).
so with no Sessions plugin it does nothing. Still in app.js: the Usage
page's Sessions tab (`/api/sessions`) and Settings' session terminal row
(`data-feature="sessions"`).
- **Library** (`plugins/library`, `Client: i18n.js, library.css,
client.js`): the page that was `library.js`. Its code runs at `mount`
only, where it wires its listeners (the dialog's backdrop and Escape,
focus and visibility reading it again, its lists' scroll), since the
script is in before app.js. Its hooks: `open` and `relang` read
`/api/library`, `redraw` draws it again once the state says which agents
are hidden, and `close`, `dirty` and `discard` are what `show()` asks
before the reader leaves it. `window.loadLibrary`, `redrawLibrary`,
`closeLibraryModal`, `libraryDirty` and `discardLibrary` are gone.
## Source of truth and composing
@@ -167,7 +178,8 @@ remembering its layer (`Source`):
- `go test ./internal/gui/ -run 'TestBuiltin|TestBootSaysBuiltinsOff'`
(`TestBuiltinConfig`, `TestBuiltinClientsLoaded`).
- `i18n-keys`, `gui-de`, `gui-ja`, `gui-zh-tw`, and a moved page's own
tests (`sessions-*`, `session-*`, `sess-*`) in Chromium and WebKit.
tests (`sessions-*`, `session-*`, `sess-*`; `library-*`, `skill-*`,
`mcp-*`, `found-skill-*`) in Chromium and WebKit.
- `internal/gui/tests/builtins.test.cjs` (the settings form) and
`plugin-kernel.test.cjs` (the boundary, Try again, `callsPage` from
boot.js and from a change) in Chromium and WebKit, every language, 1100,
+7 -9
View File
@@ -3845,12 +3845,11 @@ async function load(again) {
// the library may have drawn itself before the saved language was known
if (applyPrefs(state.settings, state.fx) || relang) {
again = false; // the Usage page too is drawn again, in the new language
if (view === "library") window.loadLibrary?.();
if (view === "plugins") window.loadPlugins?.();
magpie.call(view, "relang"); // a plugin's page
}
// a Library drawn before the state came counted the hidden agents too
else if (view === "library" && hiddenIds().join() !== hid) window.redrawLibrary?.();
else if (view === "library" && hiddenIds().join() !== hid) magpie.call("library", "redraw");
tintPanel();
tintTitleBar();
renderAgents();
@@ -23920,21 +23919,21 @@ async function show(v) {
if (!await cancelEdit(true)) return false;
} else if (!$("#modal").hidden && !$("#modal").classList.contains("out")) {
if (view === "library" && modalFormDirty() && !(await confirmDiscard())) return false;
if (view === "library") window.closeLibraryModal?.(); else closeModal();
if (view === "library") magpie.call("library", "close"); else closeModal();
}
if (view === "routing" && window.routingDirty?.()) {
if (!(await confirmDiscard())) return false;
window.discardRouting?.();
}
if (view === "library" && window.libraryDirty?.()) {
if (view === "library" && magpie.call("library", "dirty")) {
if (!(await confirmDiscard())) return false;
window.discardLibrary?.();
magpie.call("library", "discard");
}
}
view = v;
// 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 = magpie.page(v)?.title ?? ({ agents: "Agents", providers: "Providers", routing: "Routing", usage: "Usage", library: "Library", plugins: "Plugins", settings: "Settings" })[v];
const title = magpie.page(v)?.title ?? ({ agents: "Agents", providers: "Providers", routing: "Routing", usage: "Usage", plugins: "Plugins", settings: "Settings" })[v];
$("#pageTitle").dataset.en = title;
$("#pageTitle").textContent = t(title);
if (mode === "window") {
@@ -23948,7 +23947,7 @@ async function show(v) {
$("#prefs").classList.toggle("on", v === "settings");
if (v === "settings") $("#prefs").setAttribute("aria-current", "page"); else $("#prefs").removeAttribute("aria-current");
navSubs();
for (const id of ["agents", "providers", "routing", "usage", "library", "plugins", "settings", ...magpie.pages()]) $("#view-" + id).hidden = v !== id;
for (const id of ["agents", "providers", "routing", "usage", "plugins", "settings", ...magpie.pages()]) $("#view-" + id).hidden = v !== id;
// back to where the reader was in it, and again once it has what it loads
const back = () => backToReader($("#view-" + v));
requestAnimationFrame(back);
@@ -23963,7 +23962,6 @@ async function show(v) {
if (v === "routing" && (!quotas || Date.now() - quotasAt > 60e3)) loadQuotas();
if (v === "usage") loadUsage(true).then(back, (e) => status(e.message, "err"));
if (v === "settings") loadSettings().then(back, (e) => status(e.message, "err"));
if (v === "library") window.loadLibrary?.()?.then(back);
if (v === "plugins") window.loadPlugins?.()?.then(back);
syncTitle();
syncURL();
@@ -25106,7 +25104,7 @@ navHides(); // the pages built-in plugins switched off have, from boot.js
// from the tray or a reload) first, then the one kept; a page gateway mode
// leaves out, or one there is no longer, gives way to the first page.
// the pages the window can open on besides the first (Agents)
const OPEN_VIEWS = ["providers", "routing", "usage", "library", "plugins", "settings", ...magpie.pages()];
const OPEN_VIEWS = ["providers", "routing", "usage", "plugins", "settings", ...magpie.pages()];
function keptView() {
const asked = params.get("view");
if (asked === "agents" || OPEN_VIEWS.includes(asked)) return asked;
File diff suppressed because it is too large Load Diff
+3 -3
View File
@@ -10,7 +10,7 @@
<script src="omarchy.js"></script>
<link rel="stylesheet" href="app.css">
<link rel="stylesheet" href="routing.css">
<link rel="stylesheet" href="library.css">
<link rel="stylesheet" href="plugins/library/library.css">
<link rel="stylesheet" href="plugins.css">
<link rel="stylesheet" href="plugins/sessions/sessions.css">
<link rel="stylesheet" href="context.css">
@@ -245,7 +245,6 @@
</main>
<main class="view" id="view-library" hidden></main>
<main class="view" id="view-plugins" hidden></main>
@@ -558,10 +557,11 @@
<script src="plugins/gateway/client.js"></script>
<script src="plugins/sessions/i18n.js"></script>
<script src="plugins/sessions/client.js"></script>
<script src="plugins/library/i18n.js"></script>
<script src="plugins/library/client.js"></script>
<script src="purposes.js"></script>
<script src="app.js"></script>
<script src="routing.js"></script>
<script src="library.js"></script>
<script src="plugins.js"></script>
<script src="context.js"></script>
</body>
@@ -3,9 +3,13 @@
// own folder and writes each agent's files from it; what the user has in
// those files besides stays theirs, and every file is kept aside before
// magpie writes it. Everything shown here comes from /api/library.
(() => {
const page = $("#view-library");
if (!page) return;
//
// A page the Library plugin adds to the window (kernel.js): mount wires it
// up, open and relang read the library again, redraw draws it again as it
// is, and close, dirty and discard are what app.js asks of it before the
// reader leaves it.
magpie.plugin("library", (ctx) => {
let page = null;
let lib = null; // the page, as /api/library gives it
let taken = 0; // how many times lib was set, for a read to tell a newer answer came first
@@ -466,11 +470,6 @@
status(e.message, "err");
}
}
window.loadLibrary = load;
// drawn again as it is: the agents hidden are known only from the state,
// which can come after the page was drawn (it counted them, and Turn all
// on gave them the servers)
window.redrawLibrary = () => { if (lib) render(); };
// the library as the page shows it: what a change did is said once, not shown
const seen = (v) => JSON.stringify({ ...v, result: undefined });
@@ -3307,13 +3306,15 @@
// and while the page scrolls, its lists say so (library.css, .scrolling)
let still = 0;
const settled = () => { still = 0; for (const w of lists) w.el.classList.remove("scrolling"); };
page.addEventListener("scroll", () => {
queueLists();
if (!still) for (const w of lists) w.el.classList.add("scrolling");
clearTimeout(still);
still = setTimeout(settled, 150);
}, { passive: true });
window.addEventListener("resize", queueLists);
function wireLists() {
page.addEventListener("scroll", () => {
queueLists();
if (!still) for (const w of lists) w.el.classList.add("scrolling");
clearTimeout(still);
still = setTimeout(settled, 150);
}, { passive: true });
window.addEventListener("resize", queueLists);
}
// The filling: one list's next few rows per idle moment, the lists in turn.
const FILL = 20;
@@ -4923,31 +4924,45 @@
closeModal().then(() => { if (!modal) $("#modal").classList.remove("lib"); });
return true;
}
window.closeLibraryModal = () => { if (modal) closeLibModal(true); else closeModal(); };
window.libraryDirty = () => !!lib && dirty();
window.discardLibrary = () => discard(true);
// The dialog is the providers page's; while the library has it, its
// backdrop and Escape close it here.
$("#modal").addEventListener("click", (e) => {
if (modal && modalBackdrop(e)) { e.stopImmediatePropagation(); closeLibModal(); }
}, true);
document.addEventListener("keydown", (e) => {
if (!confirmationPending && modal && e.key === "Escape") { e.preventDefault(); e.stopImmediatePropagation(); closeLibModal(); }
}, true);
// leaving the page with the shared text not saved asks first
window.addEventListener("beforeunload", (e) => { if (lib && dirty()) e.preventDefault(); });
// Back to the window, the library is read again — it may have changed
// in another window or through the CLI meanwhile. Not over an open dialog,
// unsaved text, or a lookup under way.
page.addEventListener("scroll", () => page.querySelector(".lib-head")?.classList.toggle("stuck", page.scrollTop > 0), { passive: true });
// What changed there changes what the market calls added, too: take asks it again.
async function quietLoad() {
if (page.hidden || modal || dirty() || probing) return;
await load(true);
}
const shelf = () => JSON.stringify([lib?.servers?.map((x) => x.name), lib?.skills?.map((x) => x.name)]);
document.addEventListener("visibilitychange", () => { if (!document.hidden) quietLoad(); });
window.addEventListener("focus", quietLoad);
// opened on ?view=library: app.js showed the page before this was here
if (!page.hidden) load();
})();
ctx.slots.add("page", {
key: "library",
title: "Library",
mount(main) {
page = main;
wireLists();
// The dialog is the providers page's; while the library has it, its
// backdrop and Escape close it here.
$("#modal").addEventListener("click", (e) => {
if (modal && modalBackdrop(e)) { e.stopImmediatePropagation(); closeLibModal(); }
}, true);
document.addEventListener("keydown", (e) => {
if (!confirmationPending && modal && e.key === "Escape") { e.preventDefault(); e.stopImmediatePropagation(); closeLibModal(); }
}, true);
// leaving the page with the shared text not saved asks first
window.addEventListener("beforeunload", (e) => { if (lib && dirty()) e.preventDefault(); });
page.addEventListener("scroll", () => page.querySelector(".lib-head")?.classList.toggle("stuck", page.scrollTop > 0), { passive: true });
document.addEventListener("visibilitychange", () => { if (!document.hidden) quietLoad(); });
window.addEventListener("focus", quietLoad);
},
open: () => load(),
relang: () => load(),
// drawn again as it is: the agents hidden are known only from the state,
// which can come after the page was drawn (it counted them, and Turn all
// on gave them the servers)
redraw: () => { if (lib) render(); },
// the reader leaving the page: its dialog closed, and what isn't saved
close: () => { if (modal) closeLibModal(true); else closeModal(); },
dirty: () => !!lib && dirty(),
discard: () => discard(true),
});
});
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -98,7 +98,7 @@ func TestPageNamesItsFilesByContent(t *testing.T) {
t.Errorf("/: Content-Type %q", ct)
}
body := page.Body.String()
for _, f := range []string{"app.js", "routing.js", "library.js", "plugins.js", "plugins/sessions/client.js", "plugins/sessions/sessions.css", "context.js", "i18n.js", "compat.js", "app.css", "routing.css", "context.css"} {
for _, f := range []string{"app.js", "routing.js", "plugins.js", "plugins/sessions/client.js", "plugins/sessions/sessions.css", "plugins/library/client.js", "plugins/library/library.css", "context.js", "i18n.js", "compat.js", "app.css", "routing.css", "context.css"} {
b, err := fs.ReadFile(staticFS(), f)
if err != nil {
t.Fatal(err)
+1 -1
View File
@@ -9,7 +9,7 @@ const choice = (family, weight, style) => ({ family, name: "Chosen", weight, sty
for (const [name, engine] of [["chromium", chromium], ["webkit", webkit]]) {
test(`${name}: font reset restores the original cascade and explicit emphasis`, async () => {
const css = (await Promise.all(["app.css", "library.css", "routing.css", "plugins/sessions/sessions.css", "plugins.css"].map(f => fs.readFile(path.join(assets, f), "utf8")))).join("\n");
const css = (await Promise.all(["app.css", "plugins/library/library.css", "routing.css", "plugins/sessions/sessions.css", "plugins.css"].map(f => fs.readFile(path.join(assets, f), "utf8")))).join("\n");
const js = await fs.readFile(path.join(assets, "fonts.js"), "utf8");
const browser = await engine.launch();
try {
@@ -15,6 +15,7 @@ const fs = require("node:fs/promises");
const path = require("node:path");
const { test } = require("node:test");
const { chromium, webkit } = require("playwright");
const { strings } = require("./strings.cjs");
const assets = path.resolve(__dirname, "../assets");
const HOME = "/Users/me";
@@ -35,8 +36,7 @@ const STUCK = "the folder couldn't be moved: permission denied";
let I18N;
async function loadI18N() {
const src = await fs.readFile(path.join(assets, "i18n.js"), "utf8");
I18N = new Function(src.slice(0, src.indexOf("\n};") + 3) + "; return I18N;")();
I18N = strings().I18N; // i18n.js's and the plugins'
}
function tr(lang, key, vars = {}) {
let s = key;
+29
View File
@@ -32,3 +32,32 @@ test("a plugin's words are said in every language", () => {
for (const lang of ["zh-TW", "ja", "de"]) assert.deepEqual(Object.keys(dict[lang]).sort(), [...zh].sort(), `${file} ${lang}`);
}
});
test("a plugin's words are its own", () => {
// A word the core or another plugin says too belongs in i18n.js: in a
// plugin's file, it is English wherever that plugin is off, and a
// word a later change starts saying elsewhere ("Check again", Library's
// and then Settings' search keys) went untranslated there
const fs = require("node:fs"), path = require("node:path");
const repo = path.resolve(__dirname, "../../.."), assets = path.join(repo, "internal/gui/assets");
const texts = [];
const walk = (d) => {
for (const e of fs.readdirSync(d, { withFileTypes: true })) {
const p = path.join(d, e.name);
if (e.isDirectory()) {
if (!["node_modules", ".git", "site", "tests", "testdata", "docs"].includes(e.name)) walk(p);
} else if (/\.(go|js|html|css)$/.test(e.name) && e.name !== "i18n.js") texts.push([p, fs.readFileSync(p, "utf8")]);
}
};
walk(repo);
const shared = [];
for (const { file, dict } of strings().files.slice(1)) {
const own = path.join(assets, path.dirname(file)) + path.sep;
const rest = texts.filter(([p]) => !p.startsWith(own));
for (const k of Object.keys(dict.zh)) {
const at = rest.find(([, s]) => s.includes(k) || s.includes(JSON.stringify(k).slice(1, -1)));
if (at) shared.push(`${file} ${JSON.stringify(k)}: ${path.relative(repo, at[0])} says it too`);
}
}
assert.deepEqual(shared, []);
});
+2 -2
View File
@@ -14,6 +14,7 @@ const fs = require("node:fs/promises");
const path = require("node:path");
const { test } = require("node:test");
const { chromium, webkit } = require("playwright");
const { strings } = require("./strings.cjs");
const assets = path.resolve(__dirname, "../assets");
const HOME = "/Users/emo";
@@ -26,8 +27,7 @@ const lib = (servers) => ({
let I18N;
async function loadI18N() {
const src = await fs.readFile(path.join(assets, "i18n.js"), "utf8");
I18N = new Function(src.slice(0, src.indexOf("\n};") + 3) + "; return I18N;")();
I18N = strings().I18N; // i18n.js's and the plugins'
}
function tr(lang, key, vars = {}) {
let s = key;
+2 -2
View File
@@ -22,6 +22,7 @@ const fs = require("node:fs/promises");
const path = require("node:path");
const { test } = require("node:test");
const { chromium, webkit } = require("playwright");
const { strings } = require("./strings.cjs");
const assets = path.resolve(__dirname, "../assets");
const HOME = "/Users/allen";
@@ -43,8 +44,7 @@ const lib = (hooks) => ({
let I18N;
async function loadI18N() {
const src = await fs.readFile(path.join(assets, "i18n.js"), "utf8");
I18N = new Function(src.slice(0, src.indexOf("\n};") + 3) + "; return I18N;")();
I18N = strings().I18N; // i18n.js's and the plugins'
}
// the words the page says in lang; a string missing from a language fails
function tr(lang, key, vars = {}) {
@@ -13,6 +13,7 @@ const fs = require("node:fs/promises");
const path = require("node:path");
const { test } = require("node:test");
const { chromium, webkit } = require("playwright");
const { strings } = require("./strings.cjs");
const assets = path.resolve(__dirname, "../assets");
const HOME = "/Users/xz";
@@ -34,8 +35,7 @@ const FILES = {
let I18N;
async function loadI18N() {
const src = await fs.readFile(path.join(assets, "i18n.js"), "utf8");
I18N = new Function(src.slice(0, src.indexOf("\n};") + 3) + "; return I18N;")();
I18N = strings().I18N; // i18n.js's and the plugins'
}
function tr(lang, key, vars = {}) {
let s = key;
@@ -16,6 +16,7 @@ const fs = require("node:fs/promises");
const path = require("node:path");
const { test } = require("node:test");
const { chromium, webkit } = require("playwright");
const { strings } = require("./strings.cjs");
const assets = path.resolve(__dirname, "../assets");
const HOME = "/Users/me";
@@ -31,8 +32,7 @@ const STUCK = "the folder couldn't be moved: permission denied";
let I18N;
async function loadI18N() {
const src = await fs.readFile(path.join(assets, "i18n.js"), "utf8");
I18N = new Function(src.slice(0, src.indexOf("\n};") + 3) + "; return I18N;")();
I18N = strings().I18N; // i18n.js's and the plugins'
}
// the words the page says in lang; a string missing from a language fails
function tr(lang, key, vars = {}) {
@@ -20,6 +20,7 @@ const fs = require("node:fs/promises");
const path = require("node:path");
const { test } = require("node:test");
const { chromium, webkit } = require("playwright");
const { strings } = require("./strings.cjs");
const assets = path.resolve(__dirname, "../assets");
const HOME = "/Users/emo";
@@ -33,8 +34,7 @@ const lib = (servers) => ({
let I18N;
async function loadI18N() {
const src = await fs.readFile(path.join(assets, "i18n.js"), "utf8");
I18N = new Function(src.slice(0, src.indexOf("\n};") + 3) + "; return I18N;")();
I18N = strings().I18N; // i18n.js's and the plugins'
}
// the words the page says in lang; a string missing from a language fails
function tr(lang, key, vars = {}) {
@@ -11,6 +11,7 @@ const fs = require("node:fs/promises");
const path = require("node:path");
const { test } = require("node:test");
const { chromium, webkit } = require("playwright");
const { strings } = require("./strings.cjs");
const assets = path.resolve(__dirname, "../assets");
const HOME = "/Users/emo";
@@ -23,8 +24,7 @@ const lib = (servers) => ({
let I18N;
async function loadI18N() {
const src = await fs.readFile(path.join(assets, "i18n.js"), "utf8");
I18N = new Function(src.slice(0, src.indexOf("\n};") + 3) + "; return I18N;")();
I18N = strings().I18N; // i18n.js's and the plugins'
}
function tr(lang, key, vars = {}) {
let s = key;
+2 -2
View File
@@ -12,6 +12,7 @@ const fs = require("node:fs/promises");
const path = require("node:path");
const { test } = require("node:test");
const { chromium, webkit } = require("playwright");
const { strings } = require("./strings.cjs");
const assets = path.resolve(__dirname, "../assets");
const HOME = "/Users/emo";
@@ -28,8 +29,7 @@ const lib = (servers) => ({
let I18N;
async function loadI18N() {
const src = await fs.readFile(path.join(assets, "i18n.js"), "utf8");
I18N = new Function(src.slice(0, src.indexOf("\n};") + 3) + "; return I18N;")();
I18N = strings().I18N; // i18n.js's and the plugins'
}
function tr(lang, key, vars = {}) {
let s = key;
@@ -11,13 +11,12 @@
// sideways. No backend: the API is faked here.
const assert = require("node:assert/strict");
const fs = require("node:fs/promises");
const fsSync = require("node:fs");
const path = require("node:path");
const { test } = require("node:test");
const { chromium, webkit } = require("playwright");
const assets = path.resolve(__dirname, "../assets");
const I18N = new Function(fsSync.readFileSync(path.join(assets, "i18n.js"), "utf8") + ";return I18N;")();
const { I18N } = require("./strings.cjs").strings(); // i18n.js's and the plugins'
const tr = (lang, s) => (lang === "en" ? s : I18N[lang][s]) || s;
const HOME = "/Users/xv";
const agent = (id, name) => ({ id, name, icon: "", skills: `${HOME}/.${id}/skills`, mcp: `${HOME}/.${id}/mcp.json` });
+1 -2
View File
@@ -10,13 +10,12 @@
// backend: the API is faked here.
const assert = require("node:assert/strict");
const fs = require("node:fs/promises");
const fsSync = require("node:fs");
const path = require("node:path");
const { test } = require("node:test");
const { chromium, webkit } = require("playwright");
const assets = path.resolve(__dirname, "../assets");
const I18N = new Function(fsSync.readFileSync(path.join(assets, "i18n.js"), "utf8") + ";return I18N;")();
const { I18N } = require("./strings.cjs").strings(); // i18n.js's and the plugins'
const tr = (lang, s, vars = {}) => ((lang === "en" ? s : I18N[lang][s]) || s).replace(/\{(\w+)\}/g, (_, k) => vars[k]);
const HOME = "/Users/xv";
const agent = (id, name) => ({ id, name, icon: "", skills: `${HOME}/.${id}/skills`, mcp: `${HOME}/.${id}/mcp.json` });
@@ -9,13 +9,12 @@
// faked here.
const assert = require("node:assert/strict");
const fs = require("node:fs/promises");
const fsSync = require("node:fs");
const path = require("node:path");
const { test } = require("node:test");
const { chromium, webkit } = require("playwright");
const assets = path.resolve(__dirname, "../assets");
const I18N = new Function(fsSync.readFileSync(path.join(assets, "i18n.js"), "utf8") + ";return I18N;")();
const { I18N } = require("./strings.cjs").strings(); // i18n.js's and the plugins'
const tr = (lang, s, vars = {}) => ((lang === "en" ? s : I18N[lang][s]) || s).replace(/\{(\w+)\}/g, (_, k) => vars[k]);
const HOME = "/Users/xv";
const agent = (id, name) => ({ id, name, icon: "", skills: `${HOME}/.${id}/skills`, mcp: `${HOME}/.${id}/mcp.json` });
+1 -1
View File
@@ -10,7 +10,7 @@ const { test } = require("node:test");
const { chromium, webkit } = require("playwright");
const assets = path.resolve(__dirname, "../assets");
const sheets = ["app.css", "library.css", "routing.css", "plugins/sessions/sessions.css", "plugins.css"];
const sheets = ["app.css", "plugins/library/library.css", "routing.css", "plugins/sessions/sessions.css", "plugins.css"];
test("no stylesheet names a monospace stack of its own", async () => {
for (const f of sheets) {
+3 -2
View File
@@ -13,7 +13,8 @@ func init() {
ID: "library", API: "^1", Requires: []string{"window"},
Name: "Library", Sub: "Instructions, MCP servers, skills and hooks, kept once and given to every agent",
One: "1 item given to agents", Many: "{n} items given to agents",
InUse: lib.InUse,
Parts: []pluginrt.Part{{Slot: "nav.page", Key: "library"}},
InUse: lib.InUse,
Parts: []pluginrt.Part{{Slot: "nav.page", Key: "library"}},
Client: []string{"i18n.js", "library.css", "client.js"},
})
}