gui: the Library's Backups button is at the top of every tab, after Library folder (Dade on Discord)
Dade: each Library tab's 备份 (Backups) sat at the very foot of the page,
under the whole list, and was hard to find. It is now a button in the
Library's head strip, on every tab (Instructions, MCP servers, Skills,
RTK). That strip stays at the top as the page scrolls. The button sits
right after 资源库文件夹 (Library folder) and looks the same: a small
glyph (a clock with a turning arrow, as macOS draws backups) and a label.
- It opens magpie's backups folder.
- Its tooltip keeps the sentence the foot had ("magpie keeps a copy of
every file before it writes it.") with the folder's path.
- It is disabled until the library has loaded, as Library folder is.
The foot line and its .lib-foot/.lib-link styles are removed. Two
messages that pointed to "Backups, at the foot of the Library" now say
"at the top", in all five languages. The page with no agents, which had
no foot, now has Backups too.
Run:
- library-backups-top.test.cjs covers chromium and webkit,
en/zh/zh-TW/ja/de, each of the four tabs, and browser 1000/420px plus
window 1000/800/560px. It checks the button comes right after Library
folder on the same line and looks the same, waits for the library, has
a label that doesn't wrap, has no left border, causes no sideways
scroll and nothing at the foot, opens the backups folder, and doesn't
move the page on click. 10/10 pass. Without the button appended, red.
- library-loading, library-discover-jump, library-all, library-items,
library-rtk-gain and library-own-folder pass (138).
- go test ./internal/gui -count=1 under a sandbox HOME: ok.
- mobile-web.test.cjs: the phone widths pass. Its desktop 900/1280
comparison with origin/main fails only on the library page (about 650
pixels: the new button in the strip). Its before/after screenshots show
nothing else changed, and it matches again once this is on main.
This commit is contained in:
@@ -24,7 +24,7 @@ agents RTK, a CLI that cuts shell output down before the model reads it.
|
||||
| Skill groups | The page groups skills by `SkillView.Repo`, the repository each came from (`tracer.repoOf`): its GitHub source, CC Switch's `Origin`, `From`, the skills CLI's lock or the git checkout a linked folder is in. `From` is written when a repository is probed (installing from it again, `noteFrom`): for a skill with the very same `SKILL.md`, and for one traced to nowhere by a name the repository has when the library has others from there, since a pack added a while ago is mostly older copies edited there since (White Immortal on Discord: 20 of mattpocock/skills' 38). Group again (`RegroupSkills`, `POST /api/library/skills/regroup`) fetches each GitHub repository the skills are traced to and does the same; it fails only when none could be fetched. A skill traced to another repository is never moved. | [`skill_from.go`](../../internal/library/skill_from.go), [`library.js`](../../internal/gui/assets/library.js) |
|
||||
| Skill updates | A skill from GitHub (`kind: github`, a market install among them) keeps the commit it was fetched at and `Hash`, the hash of its files as fetched. `CheckSkills` asks GitHub for each one's last commit and keeps the result in memory; `View.CheckDue` says none was checked since magpie started, or not for `checkEvery` (12 hours), and the page then checks by itself as the skills open (#1449). `editState` says a skill was changed here when the library's folder no longer hashes to `Hash` (`.DS_Store` aside), or an agent's copy was edited since its mark and not yet taken in; the view's `edited` says so. `UpdateSkill` refuses such a skill with `*EditedError` unless told to replace it (the page's own Update asks first; the CLI takes `--replace-edits`), and `UpdateSkills`/`UpdateSomeSkills` leave it as it is, in `Unupdated`. A replaced version that was changed, or that can't be told (no `Hash`), is moved to the backups (`keepReplaced`). Skills the skills CLI manages (`npx skills`, `~/.agents/.skill-lock.json`) are only grouped: the CLI updates them (`npx skills update`). A linked folder, a skill imported from an agent and a `From`-only skill have no remote to check; one CC Switch installed (`Origin`) can be updated by hand but isn't checked. | [`skill_changed.go`](../../internal/library/skill_changed.go), [`skillcheck.go`](../../internal/library/skillcheck.go), [`skills.go`](../../internal/library/skills.go) |
|
||||
| Hooks | A `Hook` (#1790) is a command, an event, an optional matcher, a timeout and the agents ticked for it. Its event is portable (`HookEvents`: turn-end, after-tool, before-tool, prompt, session-start, each under the agent's own name) or an agent's own (`"codex:PermissionRequest"`), which only that agent is given. A portable tool event can be narrowed to shell or edit tools, each agent's own tool names for them. `syncHooks` writes each into the agent's own file and shape (`hookSpecOf`): Claude Code `<claude dir>/settings.json`, Codex `hooks.json` beside its config.toml, Gemini CLI `~/.gemini/settings.json` (timeout in ms), Cursor `~/.cursor/hooks.json` (flat entries, `version: 1`). Every other agent, and an agent in WSL, is refused with why, and the page greys its chip with that reason. The page also says when an agent has every hook turned off (`hooksOff`: Claude Code's `disableAllHooks`, Gemini's `hooksConfig.enabled`, Codex's `[features] hooks`). | [`hooks.go`](../../internal/library/hooks.go) |
|
||||
| Backups | Before a change first writes an agent file, `backups` copies it to `BackupDir`, one folder per change. The last `keepBackups` (30) changes are kept. | [`backup.go`](../../internal/library/backup.go) |
|
||||
| Backups | Before a change first writes an agent file, `backups` copies it to `BackupDir`, one folder per change. The last `keepBackups` (30) changes are kept. The Backups button at the top of every tab, beside Library folder, opens that folder (`libHead`; Dade on Discord found it at the foot of a long page). | [`backup.go`](../../internal/library/backup.go) |
|
||||
| RTK | `SetRTK` runs rtk's own installer (`rtk init -g …`) for an agent being switched on. For one being switched off, it removes exactly what the installer wrote, using magpie's own code, which works even with rtk gone. `ReadRTK` reads each agent's files to say which have the hook. `rtkSpec.blocked` stops the installer where it would break an agent. A detected agent RTK has no hook for at all is still listed, from `rtkNoHook`, with the reason and a switch that can't be turned on (dsh: its hooks can allow or deny a command but not rewrite it, and `rtk init` has no `--agent dsh`). | [`rtk.go`](../../internal/library/rtk.go) |
|
||||
|
||||
## Runtime path
|
||||
|
||||
@@ -3896,7 +3896,7 @@ const I18N = {
|
||||
"They are taken out of the library and out of {agents}.": "它们会从资源库中删除,并从 {agents} 中移除。",
|
||||
"They are taken out of the library; no agent has any of them.": "将从资源库中删除;没有 Agent 启用它们。",
|
||||
"The skills magpie placed in {n} projects are taken away too.": "magpie 放进 {n} 个项目的这些技能也会一并移除。",
|
||||
"{n} folders are moved to magpie's backups (Backups, at the foot of the Library), not deleted.": "{n} 个技能文件夹将移到 magpie 的备份(资源库底部的「备份」),不会删除。",
|
||||
"{n} folders are moved to magpie's backups (Backups, at the top of the Library), not deleted.": "{n} 个技能文件夹将移到 magpie 的备份(资源库顶部的「备份」),不会删除。",
|
||||
"{n} linked from folders of your own are only unlinked: those folders stay where they are.": "{n} 个链接自你文件夹的技能只取消链接,原文件夹保留。",
|
||||
"Remove all {n}": "删除全部 {n} 个",
|
||||
"{n} skills removed": "已删除 {n} 个技能",
|
||||
@@ -4154,7 +4154,7 @@ const I18N = {
|
||||
"You changed it since it was fetched from GitHub. Updating asks before it replaces your changes.": "从 GitHub 获取后你在本地改动过它。更新前会先询问,不会直接覆盖你的改动。",
|
||||
"Changed here: asks before it replaces your changes": "本地已改动:更新前会先询问,不会直接覆盖",
|
||||
"Replace your changes to {name}?": "用 GitHub 的版本替换你对 {name} 的改动?",
|
||||
"You changed {name} here since it was fetched from GitHub. Updating puts GitHub's version in its place. Yours is kept in magpie's backups (Backups, at the foot of the Library).": "从 GitHub 获取 {name} 后你在本地改动过它。更新会用 GitHub 的版本替换它,你的版本会保存在 magpie 的备份里(资源库底部的「备份」)。",
|
||||
"You changed {name} here since it was fetched from GitHub. Updating puts GitHub's version in its place. Yours is kept in magpie's backups (Backups, at the top of the Library).": "从 GitHub 获取 {name} 后你在本地改动过它。更新会用 GitHub 的版本替换它,你的版本会保存在 magpie 的备份里(资源库顶部的「备份」)。",
|
||||
"Keep mine": "保留我的",
|
||||
"{name} is up to date; your version is in the backups": "{name} 已是最新,你的版本已存入备份",
|
||||
"Kept as you changed them: {names}. Update each from its row to replace your changes.": "已保留你改动过的:{names}。如要用 GitHub 的版本替换,请在各自的行里单独更新。",
|
||||
@@ -8316,7 +8316,7 @@ const I18N = {
|
||||
"They are taken out of the library and out of {agents}.": "它們會從資源庫中刪除,並從 {agents} 中移除。",
|
||||
"They are taken out of the library; no agent has any of them.": "將從資源庫中刪除;沒有 Agent 啟用它們。",
|
||||
"The skills magpie placed in {n} projects are taken away too.": "magpie 放進 {n} 個專案的這些技能也會一併移除。",
|
||||
"{n} folders are moved to magpie's backups (Backups, at the foot of the Library), not deleted.": "{n} 個技能資料夾將移到 magpie 的備份(資源庫底部的「備份」),不會刪除。",
|
||||
"{n} folders are moved to magpie's backups (Backups, at the top of the Library), not deleted.": "{n} 個技能資料夾將移到 magpie 的備份(資源庫頂部的「備份」),不會刪除。",
|
||||
"{n} linked from folders of your own are only unlinked: those folders stay where they are.": "{n} 個連結自你資料夾的技能只取消連結,原資料夾保留。",
|
||||
"Remove all {n}": "刪除全部 {n} 個",
|
||||
"{n} skills removed": "已刪除 {n} 個技能",
|
||||
@@ -8570,7 +8570,7 @@ const I18N = {
|
||||
"You changed it since it was fetched from GitHub. Updating asks before it replaces your changes.": "從 GitHub 取得後你在本機改動過它。更新前會先詢問,不會直接覆蓋你的改動。",
|
||||
"Changed here: asks before it replaces your changes": "本機已改動:更新前會先詢問,不會直接覆蓋",
|
||||
"Replace your changes to {name}?": "用 GitHub 的版本取代你對 {name} 的改動?",
|
||||
"You changed {name} here since it was fetched from GitHub. Updating puts GitHub's version in its place. Yours is kept in magpie's backups (Backups, at the foot of the Library).": "從 GitHub 取得 {name} 後你在本機改動過它。更新會用 GitHub 的版本取代它,你的版本會保存在 magpie 的備份裡(資源庫底部的「備份」)。",
|
||||
"You changed {name} here since it was fetched from GitHub. Updating puts GitHub's version in its place. Yours is kept in magpie's backups (Backups, at the top of the Library).": "從 GitHub 取得 {name} 後你在本機改動過它。更新會用 GitHub 的版本取代它,你的版本會保存在 magpie 的備份裡(資源庫頂部的「備份」)。",
|
||||
"Keep mine": "保留我的",
|
||||
"{name} is up to date; your version is in the backups": "{name} 已是最新,你的版本已存入備份",
|
||||
"Kept as you changed them: {names}. Update each from its row to replace your changes.": "已保留你改動過的:{names}。如要用 GitHub 的版本取代,請在各自的列中單獨更新。",
|
||||
@@ -12755,7 +12755,7 @@ const I18N = {
|
||||
"They are taken out of the library and out of {agents}.": "ライブラリから削除され、{agents} からも外されます。",
|
||||
"They are taken out of the library; no agent has any of them.": "ライブラリから削除されます。これらを持っているエージェントはありません。",
|
||||
"The skills magpie placed in {n} projects are taken away too.": "magpie が {n} 個のプロジェクトに置いたスキルも取り除かれます。",
|
||||
"{n} folders are moved to magpie's backups (Backups, at the foot of the Library), not deleted.": "{n} 個のフォルダは削除されず、magpie のバックアップ(ライブラリ下部の「バックアップ」)に移されます。",
|
||||
"{n} folders are moved to magpie's backups (Backups, at the top of the Library), not deleted.": "{n} 個のフォルダは削除されず、magpie のバックアップ(ライブラリ上部の「バックアップ」)に移されます。",
|
||||
"{n} linked from folders of your own are only unlinked: those folders stay where they are.": "自分のフォルダからリンクされた {n} 個はリンクが解除されるだけで、そのフォルダはそのまま残ります。",
|
||||
"Remove all {n}": "{n} 個すべて削除",
|
||||
"{n} skills removed": "{n} 個のスキルを削除しました",
|
||||
@@ -13012,7 +13012,7 @@ const I18N = {
|
||||
"You changed it since it was fetched from GitHub. Updating asks before it replaces your changes.": "GitHub から取得した後、ここで変更されています。更新は変更を置き換える前に確認します。",
|
||||
"Changed here: asks before it replaces your changes": "ローカルで変更済み:変更を置き換える前に確認します",
|
||||
"Replace your changes to {name}?": "{name} への変更を GitHub の版で置き換えますか?",
|
||||
"You changed {name} here since it was fetched from GitHub. Updating puts GitHub's version in its place. Yours is kept in magpie's backups (Backups, at the foot of the Library).": "{name} は GitHub から取得した後、ここで変更されています。更新すると GitHub の版に置き換わります。あなたの版は magpie のバックアップ(ライブラリ下部の「バックアップ」)に残ります。",
|
||||
"You changed {name} here since it was fetched from GitHub. Updating puts GitHub's version in its place. Yours is kept in magpie's backups (Backups, at the top of the Library).": "{name} は GitHub から取得した後、ここで変更されています。更新すると GitHub の版に置き換わります。あなたの版は magpie のバックアップ(ライブラリ上部の「バックアップ」)に残ります。",
|
||||
"Keep mine": "自分の版を残す",
|
||||
"{name} is up to date; your version is in the backups": "{name} は最新です。あなたの版はバックアップにあります",
|
||||
"Kept as you changed them: {names}. Update each from its row to replace your changes.": "変更済みのため残しました:{names}。変更を置き換えるには、それぞれの行から更新してください。",
|
||||
@@ -17197,7 +17197,7 @@ const I18N = {
|
||||
"They are taken out of the library and out of {agents}.": "Sie werden aus der Bibliothek und aus {agents} entfernt.",
|
||||
"They are taken out of the library; no agent has any of them.": "Sie werden aus der Bibliothek entfernt; kein Agent hat einen davon.",
|
||||
"The skills magpie placed in {n} projects are taken away too.": "Die Skills, die magpie in {n} Projekten abgelegt hat, werden ebenfalls entfernt.",
|
||||
"{n} folders are moved to magpie's backups (Backups, at the foot of the Library), not deleted.": "{n} Ordner werden in die Backups von magpie verschoben (Backups, unten in der Bibliothek), nicht gelöscht.",
|
||||
"{n} folders are moved to magpie's backups (Backups, at the top of the Library), not deleted.": "{n} Ordner werden in die Backups von magpie verschoben (Backups, oben in der Bibliothek), nicht gelöscht.",
|
||||
"{n} linked from folders of your own are only unlinked: those folders stay where they are.": "Bei {n} aus eigenen Ordnern verlinkten wird nur der Link entfernt: Diese Ordner bleiben, wo sie sind.",
|
||||
"Remove all {n}": "Alle {n} entfernen",
|
||||
"{n} skills removed": "{n} Skills entfernt",
|
||||
@@ -17454,7 +17454,7 @@ const I18N = {
|
||||
"You changed it since it was fetched from GitHub. Updating asks before it replaces your changes.": "Du hast ihn geändert, seit er von GitHub geholt wurde. Ein Update fragt, bevor es deine Änderungen ersetzt.",
|
||||
"Changed here: asks before it replaces your changes": "Hier geändert: fragt, bevor es deine Änderungen ersetzt",
|
||||
"Replace your changes to {name}?": "Deine Änderungen an {name} ersetzen?",
|
||||
"You changed {name} here since it was fetched from GitHub. Updating puts GitHub's version in its place. Yours is kept in magpie's backups (Backups, at the foot of the Library).": "Du hast {name} hier geändert, seit er von GitHub geholt wurde. Das Update setzt die Version von GitHub an seine Stelle. Deine bleibt in den Backups von magpie (Backups, unten in der Bibliothek).",
|
||||
"You changed {name} here since it was fetched from GitHub. Updating puts GitHub's version in its place. Yours is kept in magpie's backups (Backups, at the top of the Library).": "Du hast {name} hier geändert, seit er von GitHub geholt wurde. Das Update setzt die Version von GitHub an seine Stelle. Deine bleibt in den Backups von magpie (Backups, oben in der Bibliothek).",
|
||||
"Keep mine": "Meine behalten",
|
||||
"{name} is up to date; your version is in the backups": "{name} ist aktuell; deine Version liegt in den Backups",
|
||||
"Kept as you changed them: {names}. Update each from its row to replace your changes.": "Behalten, wie du sie geändert hast: {names}. Aktualisiere jeden in seiner Zeile, um deine Änderungen zu ersetzen.",
|
||||
|
||||
@@ -29,16 +29,16 @@ body.window .lib-head { top: -2px; margin: -2px 0 0; padding: 8px 0 4px; --bleed
|
||||
--bleed-l: var(--view-left); --bleed-r: var(--view-right);
|
||||
}
|
||||
body.web .lib-tabs { max-width: 100%; flex-wrap: wrap; }
|
||||
body.web .lib-more, body.web .lib-discover { flex: none; }
|
||||
body.web .lib-more, body.web .lib-discover, body.web .lib-backups { flex: none; }
|
||||
}
|
||||
/* a window too narrow for the tabs and the buttons beside them (Discover,
|
||||
Library folder) on one line has the buttons on a line of their own, at
|
||||
Library folder, Backups) on one line has the buttons on a line of their own, at
|
||||
its end */
|
||||
.lib-head { flex-wrap: wrap; row-gap: 4px; }
|
||||
.lib-headacts { display: flex; align-items: center; gap: 8px; margin-left: auto; flex-wrap: wrap; justify-content: flex-end; }
|
||||
.lib-head.stuck::before { box-shadow: 0 1px 0 var(--line-2); }
|
||||
.lib-tabs .opt { height: 24px; padding: 0 12px; font-size: 12.5px; }
|
||||
.lib-more, .lib-discover { display: inline-flex; align-items: center; gap: 5px; }
|
||||
.lib-more, .lib-discover, .lib-backups { display: inline-flex; align-items: center; gap: 5px; }
|
||||
.lib-mini { display: inline-grid; place-items: center; color: var(--muted); }
|
||||
.lib-mini svg { width: 13px; height: 13px; }
|
||||
.lib-body { display: flex; flex-direction: column; flex: none; }
|
||||
@@ -46,9 +46,6 @@ body.window .lib-head { top: -2px; margin: -2px 0 0; padding: 8px 0 4px; --bleed
|
||||
.lib-intro { margin: 8px 2px 10px; font-size: 12px; line-height: 1.5; color: var(--muted); max-width: 640px; }
|
||||
.lib-aside { margin: 8px 4px 0; font-size: 11.5px; line-height: 1.5; color: var(--faint); }
|
||||
.lib-aside.center { text-align: center; margin-top: 14px; }
|
||||
.lib-foot { margin: auto 0 0; padding: 18px 4px 6px; font-size: 11px; color: var(--faint); flex: none; }
|
||||
.lib-link { font-size: 11px; color: var(--muted); text-decoration: underline; text-decoration-color: var(--line); text-underline-offset: 2px; }
|
||||
.lib-link:hover { color: var(--fg); text-decoration-color: currentColor; }
|
||||
|
||||
/* the glyph at the front of a row: drawn, in the text colour */
|
||||
.lib-glyph { flex: none; width: 26px; height: 26px; border-radius: 7px; display: grid; place-items: center; color: var(--fg-2); background: var(--pill); }
|
||||
|
||||
@@ -41,6 +41,8 @@
|
||||
person: "M8 3a2.5 2.5 0 1 0 0 5 2.5 2.5 0 0 0 0-5z M3.5 13.5c.6-2.4 2.3-3.6 4.5-3.6s3.9 1.2 4.5 3.6",
|
||||
back: "m9.5 4.5-3 3.5 3 3.5",
|
||||
hook: "M10.5 2.5v6.5a3 3 0 0 1-6 0V7.5 M3 9l1.5-1.5L6 9",
|
||||
// a clock with an arrow going back round it, as macOS draws backups
|
||||
backup: "M3.2 8a4.8 4.8 0 1 0 1.4-3.4 M2.8 2.6v2.4h2.4 M8 5.3V8l1.9 1.2",
|
||||
};
|
||||
|
||||
const tilde = (p) => (lib?.home && p?.startsWith(lib.home) ? "~" + p.slice(lib.home.length) : p || "");
|
||||
@@ -695,7 +697,13 @@
|
||||
more.append(glyph(GLYPH.folder, "lib-mini"), el("span", "", t("Library folder")));
|
||||
if (lib) more.title = tilde(lib.dir);
|
||||
else more.disabled = true;
|
||||
acts.append(more);
|
||||
// magpie's backups beside it, on every tab: at the foot of a long
|
||||
// page they were hard to find (Dade on Discord: 备份在最底部)
|
||||
const back = button("", "lib-backups", () => lib && reveal(lib.backups));
|
||||
back.append(glyph(GLYPH.backup, "lib-mini"), el("span", "", t("Backups")));
|
||||
if (lib) back.title = t("magpie keeps a copy of every file before it writes it.") + "\n" + tilde(lib.backups);
|
||||
else back.disabled = true;
|
||||
acts.append(more, back);
|
||||
head.append(acts);
|
||||
return head;
|
||||
}
|
||||
@@ -729,12 +737,6 @@
|
||||
else renderSkills(body);
|
||||
page.append(body);
|
||||
for (const n of body.querySelectorAll(".row-head .note")) n.title = n.textContent;
|
||||
const foot = el("p", "lib-foot");
|
||||
foot.append(el("span", "", t("magpie keeps a copy of every file before it writes it.") + " "));
|
||||
const b = el("button", "lib-link", t("Backups"));
|
||||
b.onclick = () => reveal(lib.backups);
|
||||
foot.append(b);
|
||||
page.append(foot);
|
||||
for (const f of fits.splice(0)) f();
|
||||
page.scrollTop = top;
|
||||
syncLists(); // a long list's rows where the view is, before it's painted
|
||||
@@ -3665,7 +3667,7 @@
|
||||
const linked = skills.filter((s) => s.kind === "folder").length, kept = n - linked;
|
||||
const projects = (lib.projects || []).filter((p) => names.some((x) => p.skills?.[x]?.length)).length;
|
||||
const where = [];
|
||||
if (kept) where.push(t("{n} folders are moved to magpie's backups (Backups, at the foot of the Library), not deleted.", { n: kept }));
|
||||
if (kept) where.push(t("{n} folders are moved to magpie's backups (Backups, at the top of the Library), not deleted.", { n: kept }));
|
||||
if (linked) where.push(t("{n} linked from folders of your own are only unlinked: those folders stay where they are.", { n: linked }));
|
||||
confirmRemoveEvery("skills", names, t("Remove all {n} skills?", { n }), [
|
||||
takenFrom(skills),
|
||||
@@ -3975,7 +3977,7 @@
|
||||
const head = el("div", "ehead");
|
||||
head.append(glyph(GLYPH.up), el("b", "", t("Replace your changes to {name}?", { name: s.name })));
|
||||
ed.append(head);
|
||||
ed.append(el("p", "lib-confirm", t("You changed {name} here since it was fetched from GitHub. Updating puts GitHub's version in its place. Yours is kept in magpie's backups (Backups, at the foot of the Library).", { name: s.name })));
|
||||
ed.append(el("p", "lib-confirm", t("You changed {name} here since it was fetched from GitHub. Updating puts GitHub's version in its place. Yours is kept in magpie's backups (Backups, at the top of the Library).", { name: s.name })));
|
||||
const bar = el("div", "bar");
|
||||
const go = button(t("Update"), "primary", async () => {
|
||||
go.disabled = true;
|
||||
|
||||
@@ -0,0 +1,133 @@
|
||||
// Run with Node's test runner and Playwright on the module path; see README.md.
|
||||
// Dade on Discord: on the Library pages each tab's Backups (备份) sat at the
|
||||
// very foot, under a long list, and was hard to find. It is at the top of
|
||||
// every tab now, in the strip that stays as the page scrolls, right after
|
||||
// Library folder, with the same look; nothing is left at the foot. It
|
||||
// opens magpie's backups folder, waits for the library like Library folder
|
||||
// does, fits a narrow window and browser without wrapping, and has no left
|
||||
// border. In every language, in both engines. No backend: the API is faked
|
||||
// here.
|
||||
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/tester";
|
||||
const agent = (id, name, icon) => ({ id, name, icon, skills: `${HOME}/.${id}/skills`, mcp: `${HOME}/.${id}/mcp.json` });
|
||||
const skills = Array.from({ length: 40 }, (_, i) => ({ name: `skill-${String(i).padStart(2, "0")}`, kind: "folder", description: `Skill number ${i}`, agents: ["claude"], source: `${HOME}/skills/skill-${i}` }));
|
||||
const servers = Array.from({ length: 30 }, (_, i) => ({ name: `server-${String(i).padStart(2, "0")}`, transport: "stdio", command: "npx", args: ["-y", `server-${i}`], agents: ["claude"] }));
|
||||
const view = {
|
||||
dir: `${HOME}/.magpie/library`, backups: `${HOME}/.magpie/backups`, home: HOME,
|
||||
agents: [agent("claude", "Claude Code", "claudecode-color")],
|
||||
instructions: { agents: [], sets: [] }, servers, foundServers: [], projects: [], foundSkills: [], skills, problems: [],
|
||||
hooks: Array.from({ length: 30 }, (_, i) => ({ name: `hook-${String(i).padStart(2, "0")}`, event: "turn-end", command: `echo ${i}`, agents: ["claude"] })),
|
||||
};
|
||||
|
||||
const words = {
|
||||
en: { backups: "Backups", folder: "Library folder", note: "magpie keeps a copy of every file before it writes it." },
|
||||
zh: { backups: "备份", folder: "资源库文件夹", note: "magpie 写入任何文件前都会先备份一份。" },
|
||||
"zh-TW": { backups: "備份", folder: "資源庫資料夾", note: "magpie 寫入任何檔案前都會先備份一份。" },
|
||||
ja: { backups: "バックアップ", folder: "ライブラリフォルダ", note: "magpie はファイルに書き込む前に必ずコピーを保存します。" },
|
||||
de: { backups: "Backups", folder: "Bibliotheksordner", note: "magpie sichert jede Datei, bevor es sie schreibt." },
|
||||
};
|
||||
|
||||
function serve(lang, web, opened, held) {
|
||||
return async (route) => {
|
||||
const req = route.request(), url = new URL(req.url());
|
||||
const json = (data) => route.fulfill({ json: data });
|
||||
if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:${web}};` });
|
||||
if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
|
||||
if (url.pathname === "/api/state") return json({ agents: [], profiles: [], settings: { lang, theme: "light" } });
|
||||
if (url.pathname === "/api/plugins") return json({ plugins: [] });
|
||||
if (url.pathname === "/api/library") { await held; return json(view); }
|
||||
if (url.pathname === "/api/library/rtk") return json({ path: `${HOME}/.local/bin/rtk`, version: "0.51.0", url: "https://www.rtk-ai.app", agents: [{ id: "claude", name: "Claude Code", icon: "", on: true }] });
|
||||
if (url.pathname === "/api/library/reveal") { opened.push(req.postDataJSON()); return json({}); }
|
||||
if (url.pathname === "/api/library/market/servers" || url.pathname === "/api/library/market/skills") return json({ items: [] });
|
||||
if (url.pathname === "/api/groups") return json({ groups: [] });
|
||||
if (url.pathname === "/api/providers") return json({ providers: [], gateway: { running: true } });
|
||||
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)];
|
||||
const body = await fs.readFile(file).catch(() => null);
|
||||
await (body ? route.fulfill({ body, contentType }) : route.fulfill({ status: 404, body: "" }));
|
||||
};
|
||||
}
|
||||
|
||||
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
||||
for (const lang of Object.keys(words)) {
|
||||
const w = words[lang];
|
||||
test(`${engine} ${lang}: Backups is at the top of every Library tab, after Library folder`, async (t) => {
|
||||
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
||||
t.after(() => browser.close());
|
||||
for (const [web, width] of [[true, 1000], [true, 420], [false, 1000], [false, 800], [false, 560]]) {
|
||||
for (const tab of ["instructions", "mcp", "skills", "hooks", "rtk"]) {
|
||||
const where = `${web ? "browser" : "window"} ${width}px ${tab}`;
|
||||
const context = await browser.newContext({ viewport: { width, height: 700 }, reducedMotion: "reduce" });
|
||||
await context.addInitScript((tb) => { try { localStorage.setItem("magpie.libTab", tb); } catch {} }, tab);
|
||||
const page = await context.newPage();
|
||||
page.setDefaultTimeout(5000);
|
||||
const errors = [];
|
||||
page.on("pageerror", (e) => errors.push(e.message));
|
||||
page.on("console", (m) => { if (/scroll not asked for/.test(m.text())) errors.push(m.text()); });
|
||||
const opened = [];
|
||||
let release;
|
||||
const held = new Promise((r) => { release = r; });
|
||||
await page.route("**/*", serve(lang, web, opened, held));
|
||||
await page.goto("http://magpie.test/?view=library");
|
||||
const v = page.locator("#view-library");
|
||||
const head = v.locator(".lib-head");
|
||||
const back = head.locator(".lib-backups");
|
||||
|
||||
// it waits for the library, as Library folder does
|
||||
await back.waitFor();
|
||||
assert.ok(await back.isDisabled(), `${where}: Backups waits for the library`);
|
||||
release();
|
||||
await head.locator(".lib-backups:not([disabled])").waitFor();
|
||||
await v.locator(".lib-body").first().waitFor({ state: "attached" }).catch((e) => { throw new Error(where + ": " + e.message); });
|
||||
|
||||
const got = await head.evaluate((h) => {
|
||||
const b = h.querySelector(".lib-backups"), f = h.querySelector(".lib-more"), vw = h.closest(".view");
|
||||
const r = b.getBoundingClientRect(), fr = f.getBoundingClientRect();
|
||||
const c = getComputedStyle(b);
|
||||
return {
|
||||
label: b.textContent, title: b.title, after: b.previousElementSibling === f, sameRow: Math.abs(r.top - fr.top) < 2,
|
||||
look: ["fontSize", "height", "color"].every((k) => getComputedStyle(f)[k] === c[k]),
|
||||
inView: r.left >= 0 && r.right <= innerWidth + 0.5 && r.width > 0,
|
||||
wrapped: b.querySelector("span:last-child").getClientRects().length > 1 || b.scrollWidth > b.clientWidth + 1,
|
||||
stripe: c.borderLeftWidth !== c.borderRightWidth || c.borderLeftColor !== c.borderRightColor,
|
||||
side: vw.scrollWidth - vw.clientWidth, pageSide: document.scrollingElement.scrollWidth - innerWidth,
|
||||
foot: document.querySelectorAll("#view-library .lib-foot, #view-library .lib-link").length,
|
||||
icon: !!b.querySelector(".lib-mini svg"),
|
||||
};
|
||||
});
|
||||
assert.equal(got.label, w.backups, where);
|
||||
assert.equal(got.title, w.note + "\n~/.magpie/backups", where);
|
||||
assert(got.after, `${where}: Backups comes right after ${w.folder}`);
|
||||
assert(got.sameRow, `${where}: Backups sits on Library folder's line`);
|
||||
assert(got.look, `${where}: Backups looks like Library folder`);
|
||||
assert(got.icon, `${where}: Backups has its glyph`);
|
||||
assert(got.inView, `${where}: Backups runs out of the window`);
|
||||
assert(!got.wrapped, `${where}: Backups' label wraps`);
|
||||
assert(!got.stripe, `${where}: Backups has a left border`);
|
||||
assert.equal(got.side, 0, `${where}: the view scrolls sideways`);
|
||||
assert(got.pageSide <= 1, `${where}: the page scrolls sideways`);
|
||||
assert.equal(got.foot, 0, `${where}: something is left at the foot`);
|
||||
assert.equal(await head.getByRole("button", { name: w.folder, exact: true }).count(), 1, `${where}: Library folder by its name`);
|
||||
|
||||
// it opens the backups folder, and the page stays where it was
|
||||
const top = await v.evaluate((e) => e.scrollTop);
|
||||
await Promise.all([
|
||||
page.waitForResponse((r) => new URL(r.url()).pathname === "/api/library/reveal"),
|
||||
head.getByRole("button", { name: w.backups, exact: true }).click(),
|
||||
]);
|
||||
assert.deepEqual(opened, [{ path: view.backups }], where);
|
||||
assert.equal(await v.evaluate((e) => e.scrollTop), top, `${where}: the click moved the page`);
|
||||
assert.deepEqual(errors, [], where);
|
||||
await context.close();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user