From f5124ea1792e1e82e627d5ee51b5d6c41fe8d9f2 Mon Sep 17 00:00:00 2001 From: yetone Date: Wed, 11 Nov 2026 21:46:26 +0800 Subject: [PATCH] library: a computer that follows the server says its changes are replaced (JiuLiaowkvn on X) With Settings > Sync > This computer set to Follows the server, a skill or MCP server added in the Library is replaced by the next sync, and the reporter read that as the update deleting their skills. The Library now says it in one line above Instructions, MCP, Skills, Hooks, Subagents and Plugins (Memory too while memory is synced), with a link that opens the This computer row. Nothing is said when sync is off, the part isn't synced, or the computer syncs both ways. en, zh, zh-TW, ja, de. Run on mote: library-follow-server.test.cjs (new, 48 cases x en/zh, 1100 and 420px) in chromium and webkit; broken by hand (note not appended) it goes 29 red. Also green in both engines: i18n-keys, i18n-en-no-cjk, sync-follow-server, library-items, library-intro-width, library-hooks, library-all (chromium). Not tried: the full suite, the real app, a real sync server. --- docs/subsystems/sync-backup.md | 4 + internal/gui/assets/plugins/library/client.js | 24 +++++ internal/gui/assets/plugins/library/i18n.js | 8 ++ .../gui/assets/plugins/library/library.css | 1 + .../gui/tests/library-follow-server.test.cjs | 97 +++++++++++++++++++ 5 files changed, 134 insertions(+) create mode 100644 internal/gui/tests/library-follow-server.test.cjs diff --git a/docs/subsystems/sync-backup.md b/docs/subsystems/sync-backup.md index 11836d89f..6175a42e1 100644 --- a/docs/subsystems/sync-backup.md +++ b/docs/subsystems/sync-backup.md @@ -149,6 +149,10 @@ kept in the sync folder like a join's and said in the notice (`Notice.Followed`). The join rules still hold: an `unset` part on the server leaves this computer's, and own agent fields and agents only here stay. Following a server with no file yet is an error, nothing sent. +The Library page says so above its Instructions, MCP, Skills, Hooks, +Subagents and Plugins tabs (and Memory while memory is synced), with a link +to that setting (`followNote` in `plugins/library/client.js`, +`library-follow-server.test.cjs`). `Configure` keeps the choice, as it keeps `AutoEvery`. The computer followed is an ordinary two-way one (`TestFollowServer`, `TestFollowServerSendsNoSignIn`, `sync-follow-server.test.cjs`). diff --git a/internal/gui/assets/plugins/library/client.js b/internal/gui/assets/plugins/library/client.js index 1461f7303..2c9b87b36 100644 --- a/internal/gui/assets/plugins/library/client.js +++ b/internal/gui/assets/plugins/library/client.js @@ -511,6 +511,7 @@ magpie.plugin("library", (ctx) => { // the glance left out, so the others aren't drawn again for it. async function load(quiet) { let glanced = false; + readFollow(); if (!lib) { renderLoading(); const at = taken; @@ -919,6 +920,8 @@ magpie.plugin("library", (ctx) => { if (problems) page.append(problems); const body = el("div", "lib-body" + (shown !== tab ? " enter" : "")); shown = tab; + const fnote = followNote(); + if (fnote) body.append(fnote); if (tab === "instructions") renderInstructions(body); else if (tab === "mcp") renderServers(body); else if (tab === "rtk") renderRTK(body); @@ -949,6 +952,27 @@ magpie.plugin("library", (ctx) => { function intro(text) { return el("p", "lib-intro", text); } + // A computer that follows the server (Settings → Sync → This computer) + // has what it changes in the Library replaced by the next sync: said + // above the tabs the sync carries, with the way to that setting (a + // report on X: a skill added here was taken for deleted by the update). + let follow = null; // davsync's view, while this computer follows + async function readFollow() { + let v = null; + try { v = await api("davsync"); } catch {} + const was = follow; + follow = v && v.on && v.followServer ? { library: !!v.library, memory: !!v.memory } : null; + if (JSON.stringify(follow) !== JSON.stringify(was) && lib && page.isConnected) render(); + } + function followNote() { + const part = tab === "memory" ? "memory" : ["instructions", "mcp", "skills", "hooks", "subagents", "plugins"].includes(tab) ? "library" : ""; + if (!part || !follow?.[part]) return null; + const p = el("p", "lib-intro lib-follow", t("This computer follows the server: what you change here is replaced by the next sync.") + " "); + const go = button(t("Sync settings"), "link", (e) => openSettingsAt(e, "sync", "#syncList .sync-follows")); + p.append(go); + return p; + } + // ---------- memory ---------- // What the agents know about the user and their projects, shared by all diff --git a/internal/gui/assets/plugins/library/i18n.js b/internal/gui/assets/plugins/library/i18n.js index cb26bc595..3fd2963bb 100644 --- a/internal/gui/assets/plugins/library/i18n.js +++ b/internal/gui/assets/plugins/library/i18n.js @@ -2,6 +2,8 @@ // kernel adds them to i18n.js's (magpie.strings). magpie.strings({ zh: { + "This computer follows the server: what you change here is replaced by the next sync.": "这台电脑跟随服务器:你在这里的改动会被下一次同步替换。", + "Sync settings": "同步设置", "Stop picking memories": "不再选择记忆", "Learned in {projects}": "在 {projects} 中学到", "Use everywhere": "在所有项目中使用", @@ -973,6 +975,8 @@ magpie.strings({ "{name} read again from its source": "已重新从来源读取 {name}", }, "zh-TW": { + "This computer follows the server: what you change here is replaced by the next sync.": "這台電腦跟隨伺服器:你在這裡的變更會被下一次同步取代。", + "Sync settings": "同步設定", "Stop picking memories": "不再選擇記憶", "Learned in {projects}": "在 {projects} 中學到", "Use everywhere": "在所有專案中使用", @@ -1944,6 +1948,8 @@ magpie.strings({ "{name} read again from its source": "已重新從來源讀取 {name}", }, ja: { + "This computer follows the server: what you change here is replaced by the next sync.": "このコンピュータはサーバーに従います。ここでの変更は次の同期で置き換えられます。", + "Sync settings": "同期の設定", "Stop picking memories": "メモリの選択を終える", "Learned in {projects}": "{projects} で学んだこと", "Use everywhere": "すべてのプロジェクトで使う", @@ -2915,6 +2921,8 @@ magpie.strings({ "{name} read again from its source": "{name} をソースから読み直しました", }, de: { + "This computer follows the server: what you change here is replaced by the next sync.": "Dieser Computer folgt dem Server: Änderungen hier werden bei der nächsten Synchronisierung ersetzt.", + "Sync settings": "Sync-Einstellungen", "Stop picking memories": "Keine Erinnerungen mehr auswählen", "Learned in {projects}": "Gelernt in {projects}", "Use everywhere": "Überall verwenden", diff --git a/internal/gui/assets/plugins/library/library.css b/internal/gui/assets/plugins/library/library.css index 0d8210cc8..8905fb12a 100644 --- a/internal/gui/assets/plugins/library/library.css +++ b/internal/gui/assets/plugins/library/library.css @@ -900,3 +900,4 @@ body.window .lib-list .lib-row { --lib-indent: 38px; } .lib-memdetail .lib-memwhy { height: 28px; } input.lib-memq, input.lib-memtags, input.lib-memwhy { padding: 0 9px; border-radius: 7px; border: 1px solid var(--line); background: var(--card); color: var(--fg); font-size: 12.5px; outline: none; box-sizing: border-box; transition: border-color .12s, box-shadow .12s; } input.lib-memq:focus, input.lib-memtags:focus, input.lib-memwhy:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); } +.lib-follow .link { font-size: inherit; padding: 0; margin-left: 2px; } diff --git a/internal/gui/tests/library-follow-server.test.cjs b/internal/gui/tests/library-follow-server.test.cjs new file mode 100644 index 000000000..114e58b33 --- /dev/null +++ b/internal/gui/tests/library-follow-server.test.cjs @@ -0,0 +1,97 @@ +// Run with Node's test runner and Playwright on the module path; see README.md. +// A computer that follows the server (Settings > Sync > This computer) has +// what it changes in the Library replaced by the next sync (a report on X: +// a skill added there was taken for deleted by the update). Skills, MCP, +// Instructions, Hooks, Subagents and Plugins say so in one line above their +// body with a link to that setting; Memory says it while memory is synced; +// RTK says nothing; nothing is said when the computer is not following. +// The link opens Settings > Sync with the This computer row. English, Chinese, +// Chromium and WebKit, 1100 and 420px. 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 HOME = "/Users/emo"; +const agent = (id, name) => ({ id, name, icon: "", skills: `${HOME}/.${id}/skills`, mcp: `${HOME}/.${id}/mcp.json` }); +const lib = () => ({ + dir: `${HOME}/.magpie/library`, backups: `${HOME}/.magpie/backups`, home: HOME, + agents: [agent("codex", "Codex")], + instructions: { agents: [], sets: [] }, foundServers: [], projects: [], foundSkills: [], skills: [], servers: [], +}); + +function server(lang, sync) { + return async (route) => { + const req = route.request(), url = new URL(req.url()); + if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:true};` }); + if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" }); + if (url.pathname === "/api/state") return route.fulfill({ json: { agents: [], profiles: [], settings: { lang, theme: "light" } } }); + if (url.pathname === "/api/plugins") return route.fulfill({ json: { plugins: [] } }); + if (url.pathname === "/api/library") return route.fulfill({ json: lib() }); + if (url.pathname === "/api/library/rtk") { + return route.fulfill({ json: { path: `${HOME}/.local/bin/rtk`, version: "0.51.0", url: "https://www.rtk-ai.app", agents: [{ id: "codex", name: "Codex", icon: "", on: true }], gain: { commands: 42, input: 9000, saved: 8000, pct: 88.9 } } }); + } + if (url.pathname === "/api/memory") return route.fulfill({ json: { agents: [], memories: [], digest: false, total: 0, counts: {}, scopes: [] } }); + if (url.pathname === "/api/davsync") return route.fulfill({ json: sync }); + if (url.pathname === "/api/usage/quotas") return route.fulfill({ json: [] }); + if (url.pathname === "/api/groups") return route.fulfill({ json: { groups: [] } }); + if (url.pathname === "/api/providers") return route.fulfill({ json: { providers: [], gateway: { running: true } } }); + if (url.pathname.startsWith("/api/")) return route.fulfill({ json: {} }); + const file = path.join(assets, url.pathname === "/" ? "index.html" : url.pathname); + const contentType = { ".html": "text/html", ".js": "text/javascript", ".css": "text/css", ".svg": "image/svg+xml", ".png": "image/png" }[path.extname(file)]; + await route.fulfill({ body: await fs.readFile(file), contentType }); + }; +} + +const follows = { on: true, kind: "webdav", keys: true, agents: true, library: true, memory: false, followServer: true, auto: 3 }; +const cases = [ + ["skills", follows, true], ["mcp", follows, true], ["instructions", follows, true], + ["hooks", follows, true], ["subagents", follows, true], ["plugins", follows, true], + ["rtk", follows, false], ["memory", follows, false], + ["memory", { ...follows, memory: true }, true], + ["skills", { ...follows, followServer: undefined }, false], + ["skills", { ...follows, on: false }, false], + ["skills", { ...follows, library: false }, false], +]; + +for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) { + test(engine + ": Library says a following computer's changes are replaced", async (t) => { + const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" })); + const errors = []; + t.after(async () => { if (errors.length) console.log(errors); await browser.close(); }); + for (const lang of ["en", "zh"]) { + for (const width of [1100, 420]) { + for (const [tab, sync, shown] of cases) { + await t.test(`${lang} ${width} ${tab} ${JSON.stringify(sync)}`, async () => { + const ctx = await browser.newContext({ viewport: { width, height: 800 } }); + await ctx.addInitScript((tab) => { try { localStorage.setItem("magpie.libTab", tab); } catch {} }, tab); + const page = await ctx.newPage(); + page.setDefaultTimeout(5000); + page.setDefaultNavigationTimeout(60000); + page.on("pageerror", (e) => errors.push(e.message)); + await page.route("**/*", server(lang, sync)); + await page.goto("http://magpie.test/"); + await page.locator('button[data-view="library"]').click(); + const v = page.locator("#view-library"); + await v.locator(".lib-body").waitFor(); + await page.waitForTimeout(400); // davsync's read, drawn in place + const note = v.locator(".lib-follow"); + assert.equal(await note.count(), shown ? 1 : 0, `${lang} ${tab}: note ${shown ? "missing" : "shown"}`); + if (shown) { + assert((await note.textContent()).length > 20); + const sideways = await page.evaluate(() => document.documentElement.scrollWidth - document.documentElement.clientWidth); + assert(sideways <= 0, `page scrolls sideways by ${sideways}px`); + if (width === 1100 && tab === "skills") { + await note.locator("button").click(); + await page.locator("#setPage-sync").waitFor({ state: "visible" }); + } + } + await ctx.close(); + }); + } + } + } + }); +}