From f1f512c1ec09dfee002f87f222678e3651cae28f Mon Sep 17 00:00:00 2001 From: yetone Date: Fri, 13 Nov 2026 01:42:52 +0800 Subject: [PATCH] library: a repository's heading folds an agent's profiles into one chip, and a row's profiles chip lines up with the hand (Yanzhongixuy on X) 0.1.3926, several Hermes profiles: the Skills page's source headings (anthropics/skills ...) drew one icon per profile, a long strip, and the one chip 2a1111cba made on a row sat out of line. That commit said "Rows only": groupChips never set change.rows, so headings kept every profile. The row's chip had data-members, not data-agent, so the fan/stack translate rules in library.css never reached it. groupChips now sets change.rows, and its profiles chip is half lit when a profile has some of the skills. library.css applies the fan rules to [data-members] chips too. docs/subsystems/library.md says so. Files: plugins/library/client.js, plugins/library/library.css, tests/library-profile-group.test.cjs (new), docs/subsystems/library.md. Run on mote: library-profile-group.test.cjs (new; chromium + webkit, en/zh/ zh-TW/ja/de, 420 and 980px, 22 cases): 22 of 22 green; broken by hand (old client.js and library.css) 22 of 22 red (13 Hermes chips, not 1); old library.css alone 22 of 22 red (chips out of line). The Library GUI files, group-skill-chips and i18n-keys ran in both engines: the only reds are library-loading's chromium and webkit cases, red on origin/main 8c7328f3a6c47c0931cfc43510b2eae79b5a8b7c too (run there alone, 2 of 6 red), filed as #6204. Not run: the full Go suite and the 113-file GUI run's final tally (still running when pushed), Linux WebKitGTK, a real Hermes install with many profiles. --- docs/subsystems/library.md | 2 +- internal/gui/assets/plugins/library/client.js | 13 +- .../gui/assets/plugins/library/library.css | 6 +- .../gui/tests/library-profile-group.test.cjs | 118 ++++++++++++++++++ 4 files changed, 133 insertions(+), 6 deletions(-) create mode 100644 internal/gui/tests/library-profile-group.test.cjs diff --git a/docs/subsystems/library.md b/docs/subsystems/library.md index 37cc05c79..4fae71b3b 100644 --- a/docs/subsystems/library.md +++ b/docs/subsystems/library.md @@ -19,7 +19,7 @@ Pi's extensions and packages. | library.json | `Library` holds the instruction sets, the MCP servers, the skills, the projects, skill groups and copy settings. `Applied` records what magpie last wrote into each agent, so it only ever takes away its own. The instruction texts and skill folders live under `Dir` (`library/` in magpie's config folder). | [`library.go`](../../internal/library/library.go) | | A Remote magpie's skills and prompts | A Remote magpie provider's editor has a switch, Use its skills and prompts (`borrowOn` in library.json, `SetBorrow`; KoiLx0 on X: manage them once on the remote machine). The remote serves its Library at `GET /v1/magpie/library` (`gateway.SharedLibrary` = `library.Shared`, to `local` or `sharedWith` callers; a held key is refused; no MCP servers, which the MCP switch covers; borrowed items are never passed on). `keepBorrowed` (10 minutes, and once on switching on) fetches it with the provider's key (`provider.RemoteLibrary`) and `Borrow` adds each skill and each instruction set as `remote--`, recording a hash of what it wrote (`Borrowed`). It only ever changes what still matches that hash: a skill or set of the user's by the same name, one the user edited, and one the user removed after it was taken stay as they are (`Kept`, shown under the switch); an update or a drop moves the old copy to the backups; switching off takes out what is unchanged. The first set becomes the active one only when nothing is active. `Collect`/`Put` (sync backups) still carry borrowed items as ordinary ones. | [`borrow.go`](../../internal/library/borrow.go), [`remote_library.go`](../../internal/provider/remote_library.go), `TestBorrowRemoteLibrary` | | One change | `change` locks the library, loads it, applies one edit, saves, syncs every agent and saves again. Every exported mutation (`SaveServer`, `InstallSkills`, `SetSkillHow` and the rest) goes through it. One change runs at a time, whether from the page or the CLI. | [`library.go`](../../internal/library/library.go) | -| Targets | `Targets` lists the detected agents (`agent.Detected`), a folder an agent shares with its vendor's other app when only that app is here (`agent.SharedHere`: the Cursor editor's `~/.cursor`, whose `mcp.json` and skills it reads, listed as Cursor; `TestCursorEditorAloneKeepsItsLibraryRow`), plus apps like Claude Desktop, with where each keeps its instructions file (and an `Override` it reads instead), its MCP file and its skills folder. An agent whose CLI is gone (`CLIMissing`: an uninstall that left the folder behind, #2177, #2254) is no target: it is given nothing it can't read. One that isn't a target but still has skills, servers or hooks magpie gave it (in `Applied`, or listed in an item's `Agents`) is held (`held`, a `Target` with `Gone`): a sync takes edits from its copies and then only takes out of it (`syncSkills`, `syncMCP` and `syncHooks` give a gone target nothing new), and `Read` lists it with `gone: true` while it has any. On a row, an agent's profiles (`hermes#name`, `omp#name`, `claude#name`, `qwenpaw#id`, WSL ones included) are one chip with a count, when an agent has more than one (`profileChip` in plugins/library/client.js, Yanzhongixuy on X: about twenty identical Hermes glyphs on every skill row); a click opens the app menu to pick profiles singly, and All still means every profile (`library-profile-chip.test.cjs`). The page shows a gone agent's chip only on the rows of what it has, lit, so a click takes it out (`withGone` in plugins/library/client.js), leaves it out of All, the per-agent How sheet and every picker, and lists it in By agent as Not installed here with Turn all on off (@jiahao_jayden on X: an uninstalled WorkBuddy was on every skill's row; `TestGoneAgentListedToTakeOut`, `library-gone-agents.test.cjs`). On a Mac WorkBuddy and WorkBuddy AI are detected by their apps' bundle ids (`com.tencent.workbuddy.mac`, `com.workbuddy.workbuddy-ai`, `macBundle`), not by `~/.workbuddy`, which an uninstall leaves and magpie itself writes into (`TestWorkBuddyOnMacIsItsApp`); off a Mac the folder still counts. `everyTarget` keeps it for the guards that refuse an agent's own places: a project folder whose skills folder or MCP file is the agent's, and an instruction set kept in its instructions file. An agent in a running WSL distro has its places under the distro's home (`wslTargetOf`): Claude Code, Codex, Pi, OmO, Gemini CLI, Antigravity CLI, Crush, Cline, CodeBuddy Code, Kimi Code and Goose each by its own rule, never reading this machine's variables (Kimi Code's and Goose's shared `~/.agents/skills` there isn't given), Pi's MCP file chosen by `piMCP` as on this machine from the version the distro's `pi --version` gave its probe (`InstalledVersion`) and the distro's npm folders (`wslPiRoots`; leokon on Discord: only the Windows Pi was offered MCP servers, `TestWSLPiMCP`, `TestWSLMCPSiblings`), and every agent that keeps all of them in its own folder (Hermes Agent, omp, OpenCode, Droid and the rest of `ownFolder`, #1323) by the same rule as on this machine, its MCP file marked as WSL's so a Windows program isn't given to it. A place below a folder the distro has as a link is opened where the link leads (`wslOpen`, agent-wiring's WSL folders that are links, #4502); a link the distro couldn't resolve gives that agent one `wsl` problem and nothing is written to it (`TestWSLFolderIsALinkToC`, `TestWSLFolderLinkUnresolved`). An agent a plugin adds (`a.Plugin`) has the places its plugin's `agent.library` names (`pluginTarget`): an instructions file, an MCP file in one of `agentplug.MCPFormats` (each the `mcpFormat` of the agent it is named for, `pluginMCP`) and a skills folder, `~` and `$VAR` expanded as its config is; one that names none is no target. Before, a plugin's agent got models and keys only. Every built-in agent is a target or is in `noLibrary` with why: OpenBot was added with neither and was in no picker (SSNQT on X), so `TestEveryAgentInLibrary` fails a new agent until it gets one (34 were in no picker when it landed, listed there under #5897). | [`targets.go`](../../internal/library/targets.go) | +| Targets | `Targets` lists the detected agents (`agent.Detected`), a folder an agent shares with its vendor's other app when only that app is here (`agent.SharedHere`: the Cursor editor's `~/.cursor`, whose `mcp.json` and skills it reads, listed as Cursor; `TestCursorEditorAloneKeepsItsLibraryRow`), plus apps like Claude Desktop, with where each keeps its instructions file (and an `Override` it reads instead), its MCP file and its skills folder. An agent whose CLI is gone (`CLIMissing`: an uninstall that left the folder behind, #2177, #2254) is no target: it is given nothing it can't read. One that isn't a target but still has skills, servers or hooks magpie gave it (in `Applied`, or listed in an item's `Agents`) is held (`held`, a `Target` with `Gone`): a sync takes edits from its copies and then only takes out of it (`syncSkills`, `syncMCP` and `syncHooks` give a gone target nothing new), and `Read` lists it with `gone: true` while it has any. On a row, an agent's profiles (`hermes#name`, `omp#name`, `claude#name`, `qwenpaw#id`, WSL ones included) are one chip with a count, when an agent has more than one (`profileChip` in plugins/library/client.js, Yanzhongixuy on X: about twenty identical Hermes glyphs on every skill row); a click opens the app menu to pick profiles singly, and All still means every profile (`library-profile-chip.test.cjs`). A repository's, part's or pick's heading folds them the same way (`groupChips` sets `change.rows`; its chip is half lit when a profile has some of the skills), and the profiles chip takes part in the row's fan like any other (`[data-members]` in library.css), so the hand stays in line (Yanzhongixuy on X, 0.1.3926; `library-profile-group.test.cjs`). The page shows a gone agent's chip only on the rows of what it has, lit, so a click takes it out (`withGone` in plugins/library/client.js), leaves it out of All, the per-agent How sheet and every picker, and lists it in By agent as Not installed here with Turn all on off (@jiahao_jayden on X: an uninstalled WorkBuddy was on every skill's row; `TestGoneAgentListedToTakeOut`, `library-gone-agents.test.cjs`). On a Mac WorkBuddy and WorkBuddy AI are detected by their apps' bundle ids (`com.tencent.workbuddy.mac`, `com.workbuddy.workbuddy-ai`, `macBundle`), not by `~/.workbuddy`, which an uninstall leaves and magpie itself writes into (`TestWorkBuddyOnMacIsItsApp`); off a Mac the folder still counts. `everyTarget` keeps it for the guards that refuse an agent's own places: a project folder whose skills folder or MCP file is the agent's, and an instruction set kept in its instructions file. An agent in a running WSL distro has its places under the distro's home (`wslTargetOf`): Claude Code, Codex, Pi, OmO, Gemini CLI, Antigravity CLI, Crush, Cline, CodeBuddy Code, Kimi Code and Goose each by its own rule, never reading this machine's variables (Kimi Code's and Goose's shared `~/.agents/skills` there isn't given), Pi's MCP file chosen by `piMCP` as on this machine from the version the distro's `pi --version` gave its probe (`InstalledVersion`) and the distro's npm folders (`wslPiRoots`; leokon on Discord: only the Windows Pi was offered MCP servers, `TestWSLPiMCP`, `TestWSLMCPSiblings`), and every agent that keeps all of them in its own folder (Hermes Agent, omp, OpenCode, Droid and the rest of `ownFolder`, #1323) by the same rule as on this machine, its MCP file marked as WSL's so a Windows program isn't given to it. A place below a folder the distro has as a link is opened where the link leads (`wslOpen`, agent-wiring's WSL folders that are links, #4502); a link the distro couldn't resolve gives that agent one `wsl` problem and nothing is written to it (`TestWSLFolderIsALinkToC`, `TestWSLFolderLinkUnresolved`). An agent a plugin adds (`a.Plugin`) has the places its plugin's `agent.library` names (`pluginTarget`): an instructions file, an MCP file in one of `agentplug.MCPFormats` (each the `mcpFormat` of the agent it is named for, `pluginMCP`) and a skills folder, `~` and `$VAR` expanded as its config is; one that names none is no target. Before, a plugin's agent got models and keys only. Every built-in agent is a target or is in `noLibrary` with why: OpenBot was added with neither and was in no picker (SSNQT on X), so `TestEveryAgentInLibrary` fails a new agent until it gets one (34 were in no picker when it landed, listed there under #5897). | [`targets.go`](../../internal/library/targets.go) | | Stopped WSL distro | A stopped distro's agents are no targets: opening their files would start the distro, or the read fails (#3896). While a distro runs, `keepShape` keeps each agent's places and what its MCP file takes in `wsl.json` (`agent.WSLKeep`, key `library:`). While it is stopped, `Read` lists its agents from that (`asleepView`, `asleep: `), ticks as library.json has them; one magpie never saw there is listed only on the rows that name it, as `unseen`, its ticks not shown (cybercaius on Discord: the MCP page knew a distro's agents only once WSL had started). A tick on a stopped agent is kept in library.json as any is (`Takes` accepts one with a known shape; `serversAgents` judges it by `shape.reaches`), nothing is written and nothing in the distro runs; `Woken`, from `KeepLinked`'s loop (and the app's start-up sync), syncs when a distro the library names is seen go from stopped to running (`wsl.exe -l --running`, which starts nothing). The page greys a stopped agent's chip, says so in its tooltip and in one line per distro (`.lib-asleep`); an unseen chip is `aria-disabled` and kept by every click on its row (`keptOf`). The CLI says the same on stderr (`AsleepIn`). Queued, not a start button: a start costs the memory #3896 is about, and All or a bulk tick would start every distro. The Instructions page lists them too (`asleepInstructions`, #4182), at the instructions file the shape keeps, switched on as library.json has them, with what each gets besides (magpie's own folder) and nothing read from the file: its own lines and edits aren't counted then, and its path is plain text, not a reveal, which would open the distro. One switched on whose file magpie never saw is listed as `unseen`, its switch greyed out and kept by every other switch; before, a switch on the page sent the agents without the stopped distro's and took them off. A switch on one is written by `Woken`, which watches a distro named in `Instructions.Agents`, or whose agent still has magpie's part (`Applied.Instructions`), so one switched off has it taken out. The Hooks page lists the stopped agents with a shape as it does while the distro runs (`hooksView`, #4237): greyed, since magpie gives no agent in WSL hooks yet (`wslNoHooks`), and a hook given one says so; there is nothing for `Woken` to write. So does the Subagents page for the kinds it lists (`subagentsView`, `wslNoSubagents`, #4238). | [`wsl_asleep.go`](../../internal/library/wsl_asleep.go), [`targets.go`](../../internal/library/targets.go), [`plugins/library/client.js`](../../internal/gui/assets/plugins/library/client.js) | | Sync | `sync` writes each target's instructions and MCP servers. It then takes edits made in agents' skill copies into the library (`takeEdits`) and links or copies the skills. `~/.agents/skills` goes first (`sweepShared`, then `syncShared` for the Put skills in setting), so an agent that reads it gets no second link. Then it syncs projects' skills. | [`sync.go`](../../internal/library/sync.go) | | Projects | A project (`Project`) is a folder given some of the library's skills and MCP servers, each for some agents. A skill is linked (or copied) into the folder the agent reads a project's skills from (`projectSkillsDirs`): `.claude/skills` for Claude Code, `.qoder/skills` for Qoder and Qoder CN, `.codebuddy/skills` for CodeBuddy Code, `.commandcode/skills` for Command Code, and `.agents/skills` for Codex, Gemini CLI, OpenCode, Pi, Cursor, Copilot CLI, Antigravity, Kimi, Goose, Grok, Droid, Cline and DeepSeek Harness (which reads it, and `.dsh/skills`, at the nearest folder up with a `.git`, else where it runs: a project folder inside a repository but not at its root doesn't reach it, #5172). A server is written into the file the agent reads a project's servers from (`projectMCPFiles`), in the shape its user-wide file has: `.mcp.json` for Claude Code and CodeBuddy Code (CodeBuddy's `mcp.json` when the project has that and no `.mcp.json`, since it reads only the first of the two), `.codex/config.toml`, `.gemini/settings.json`, `.cursor/mcp.json`, `opencode.json`, `.zcode/config.json`, `.pi/mcp.json`, `.qoder/settings.json`'s `mcpServers` for Qoder and Qoder CN, and `.factory/mcp.json` for Droid. Claude Code, Qoder and CodeBuddy ask the user to approve a project's server before using it. Only targets whose vendor source or docs name them are listed (each map's comment cites them); an agent with none (Copilot CLI's MCP, Zed, WorkBuddy, Command Code's MCP, whose `.mcp.json` has its own `transport` shape, DeepSeek Harness's MCP, whose servers are rows in its profiles' patch layers with no project layer) can't be picked for a project (eirc on Discord). `Placed`, `Wrote`, `Made` and `MadeFiles` record what magpie put there, the only things it takes away. Nothing of magpie's goes into the project's git: what it placed is listed in the repository's own `info/exclude` (`writeExclude`, one block per project between `excludeBegin(dir)` and `ignoreEnd`, read by every worktree, never committed), and the project's `.gitignore` is left as it is (a block an older magpie wrote there is taken out, `TestProjectKeptOutOfGitByExclude`). A folder outside git gets no ignore file; once it is `git init`ed, `treesChanged` sees no block and the next `KeepLinked` writes it (`TestProjectOutsideGit`). A project is the global set ± its own (WhyULose0 on X): `ServersOff` and `SkillsOff` turn a global server or skill off in the project for some agents (`ProjectServerOff`, `ProjectSkillsOff`; `POST /api/library/projects/server-off` and `skill-off` with `dir`, `name`/`names`, `agents`; none gives it back). Each is done the way the agent reads it for a folder (`project_scope.go`): Claude Code's record of the project in `~/.claude.json` (`projects[
]`, `claudeRoot`) gets the name in `disabledMcpServers`, where magpie takes out only names it added (`Claude.Off`); Codex gets `[mcp_servers.] enabled = false` in the project's `.codex/config.toml`, only for a server in its own config (`CodexOff`); a skill is `skillOverrides. = "off"` in the project's `.claude/settings.local.json` (`Overrides`), a value the user set there is theirs (`TestProjectServerOff`, `TestProjectSkillOff`). Only those (`ProjectOffAgents`, `ProjectSkillOffAgents`) can take an off, and a skill an agent reaches through the [skill router](skill-router.md) can't; the card shows a global agent that can't as always on, with why. With the [MCP router](mcp-router.md) on, a project that adds or turns off a server the router serves gives Claude Code and Codex their own hub entry, `~` (`projectHubs`): Claude Code's in its record's `mcpServers` (local scope), Codex's in the project's `.codex/config.toml`; the server added isn't written into `.mcp.json` then (`TestProjectSetThroughRouter`). Claude Code keys its record by the repository's main top folder, so a project in a subfolder turns its offs on for the whole repository. A git worktree of the project's repository follows the project (`treeDirs`, `Trees`): the project's folder in each worktree gets the same skills, servers and offs, and is let go when the worktree is removed; `KeepLinked` checks for new ones (`keepProjectTrees`, `TestProjectWorktreeFollows`). `magpie library project …` (#5193, [`library_project_cli.go`](../../internal/cli/library_project_cli.go)) adds and removes a project and its skills through the same calls as the page (`AddProject`, `RemoveProject`, `ProjectSkills`, `ProjectSkill`, `ProjectCopy`); a skill added with no `agents=` goes to the agents the page's Skills menu picks (those the project's skills are for already, else every agent here with a project skills folder), and one not placed exits 1 with why (`TestLibraryProjectCmd`). A project card's Skills menu lists the skills by source as the Library does (`skillGroups(true)`, whatever sort the list has; one group is the flat list), a heading over each that ticks or unticks the whole group (`group` in `openProtoMenu`, half-ticked while some are in; Elorynth on X, `project-skills-groups.test.cjs`). | [`projects.go`](../../internal/library/projects.go), [`project_mcp.go`](../../internal/library/project_mcp.go), [`project_scope.go`](../../internal/library/project_scope.go), [`project_git.go`](../../internal/library/project_git.go) | diff --git a/internal/gui/assets/plugins/library/client.js b/internal/gui/assets/plugins/library/client.js index 061c5e723..87e573209 100644 --- a/internal/gui/assets/plugins/library/client.js +++ b/internal/gui/assets/plugins/library/client.js @@ -5616,7 +5616,7 @@ magpie.plugin("library", (ctx) => { for (const g of by.values()) v = await api("library/" + kind + "/agents-some", { names: g.names, agents: g.agents, on }); return v; }; - const box = agentChips(all, full, async (next) => { + const change = async (next) => { const on = next.filter((id) => !full.includes(id)), off = full.filter((id) => !next.includes(id)); box.classList.add("busy"); try { @@ -5640,11 +5640,20 @@ magpie.plugin("library", (ctx) => { status(e.message, "err", 6000); } render(); - }, { all: true, blocked: servers ? (a) => (reach(a) ? "" : n === 1 ? sseBlocked(skills[0])(a) : t("{agent} can reach none of these servers", { agent: a.name })) + }; + // an agent's profiles are one chip here too (Yanzhongixuy on X: a + // repository's heading drew an icon for each of twenty Hermes profiles) + change.rows = true; + const box = agentChips(all, full, change, { all: true, blocked: servers ? (a) => (reach(a) ? "" : n === 1 ? sseBlocked(skills[0])(a) : t("{agent} can reach none of these servers", { agent: a.name })) : hooks ? (a) => (reach(a) ? "" : n === 1 ? hookBlocked(skills[0])(a) : t("{agent} can run none of these hooks", { agent: a.name })) : null, always: servers || hooks || !n ? null : (a) => (reach(a) ? "" : n === 1 ? alwaysFor(skills[0])(a) : t("{agent} reads ~/.agents/skills itself, where all of these are kept — it has them whatever is ticked here", { agent: a.name })) }); box.classList.add("lib-groupchips"); + // a profiles chip is half lit when a profile of it has some of the skills + for (const c of box.querySelectorAll(".lib-ag[data-members]")) { + const ms = idsOf(c).map((id) => all.find((x) => x.id === id)).filter((a) => a && reach(a)); + if (ms.some((a) => count(a) && count(a) < reach(a)) || (ms.some((a) => count(a)) && !c.classList.contains("on"))) c.classList.add("some"); + } for (const c of box.querySelectorAll(".lib-ag[data-agent]")) { const a = all.find((x) => x.id === c.dataset.agent), k = count(a), m = reach(a); if (!m) continue; diff --git a/internal/gui/assets/plugins/library/library.css b/internal/gui/assets/plugins/library/library.css index 5644276c7..5e3f526e8 100644 --- a/internal/gui/assets/plugins/library/library.css +++ b/internal/gui/assets/plugins/library/library.css @@ -358,13 +358,13 @@ input.lib-setname:focus { border-color: var(--accent); box-shadow: 0 0 0 3px col it never move. The cards are dealt out one after another, the one with the furthest to go first, so none passes over another, and go back together, quicker. Transform stays free for the press. */ -.lib-row > .lib-agents .lib-ag[data-agent] { translate: calc(var(--k, 0) * (var(--lib-fan) - var(--lib-stack))) 0; } -.lib-row > .lib-agents:hover .lib-ag[data-agent], .lib-row > .lib-agents:focus-within .lib-ag[data-agent] { translate: 0 0; transition-delay: 0s, 0s, 0s, 0s, 0s, calc((var(--lib-agent-count, 1) - 1 - var(--k, 0)) * var(--lib-step)); } +.lib-row > .lib-agents .lib-ag[data-agent], .lib-row > .lib-agents .lib-ag[data-members] { translate: calc(var(--k, 0) * (var(--lib-fan) - var(--lib-stack))) 0; } +.lib-row > .lib-agents:hover .lib-ag[data-agent], .lib-row > .lib-agents:focus-within .lib-ag[data-agent], .lib-row > .lib-agents:hover .lib-ag[data-members], .lib-row > .lib-agents:focus-within .lib-ag[data-members] { translate: 0 0; transition-delay: 0s, 0s, 0s, 0s, 0s, calc((var(--lib-agent-count, 1) - 1 - var(--k, 0)) * var(--lib-step)); } .lib-row > .lib-agents .lib-ag { flex: none; width: 24px; min-width: 0; height: 24px; padding: 0 0 0 4px; justify-content: flex-start; background: var(--card); border-color: var(--line-2); box-shadow: none; transition: background .14s, border-color .14s, transform .14s var(--ease), outline-color .2s, box-shadow .2s, translate .22s cubic-bezier(.32, .72, 0, 1); } .lib-row > .lib-agents:hover .lib-ag, .lib-row > .lib-agents:focus-within .lib-ag { transition-duration: .14s, .14s, .14s, .2s, .2s, .3s; transition-timing-function: ease, ease, var(--ease), ease, ease, cubic-bezier(.23, 1, .32, 1); } .lib-row > .lib-agents { --lib-step: min(16ms, calc(120ms / max(1, var(--lib-agent-count, 1) - 1))); } @media (prefers-reduced-motion: reduce) { - .lib-row > .lib-agents .lib-ag[data-agent], .lib-row > .lib-agents:hover .lib-ag[data-agent], .lib-row > .lib-agents:focus-within .lib-ag[data-agent] { transition-duration: .14s, .14s, .14s, .2s, .2s, 0s; transition-delay: 0s; } + .lib-row > .lib-agents .lib-ag[data-agent], .lib-row > .lib-agents:hover .lib-ag[data-agent], .lib-row > .lib-agents:focus-within .lib-ag[data-agent], .lib-row > .lib-agents .lib-ag[data-members], .lib-row > .lib-agents:hover .lib-ag[data-members], .lib-row > .lib-agents:focus-within .lib-ag[data-members] { transition-duration: .14s, .14s, .14s, .2s, .2s, 0s; transition-delay: 0s; } } .lib-row > .lib-agents .lib-ag .ic { width: 14px; height: 14px; } /* the ring in the card's colour that cuts each chip out of the one under diff --git a/internal/gui/tests/library-profile-group.test.cjs b/internal/gui/tests/library-profile-group.test.cjs new file mode 100644 index 000000000..e5ba8d3b5 --- /dev/null +++ b/internal/gui/tests/library-profile-group.test.cjs @@ -0,0 +1,118 @@ +// Run with Node's test runner and Playwright on the module path; see README.md. +// With several Hermes profiles a repository's heading in the Library's +// skills drew an icon for each of them, and the one chip a row made of them +// sat out of line with the others (Yanzhongixuy on X, 0.1.3926: "显示很长且 +// 错位"). Both are one chip with a count that opens a menu of the profiles, +// in line with the hand of chips. A tick in the menu gives the repository's +// skills to that profile alone. 420px and 980px, English, Chinese, +// Traditional Chinese, Japanese and German; 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/me"; +const agent = (id, name, icon) => ({ id, name, icon, skills: `${HOME}/.${id}/skills`, mcp: `${HOME}/.${id}/mcp.json` }); +const gh = (repo, name, agents) => ({ name, kind: "github", source: `https://github.com/${repo}/tree/main/skills/${name}`, description: "d", agents }); + +function server(lang, state, posts) { + return async (route) => { + const req = route.request(); + const 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: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, theme: "light" } }); + if (url.pathname === "/api/library") return json(state.lib); + if (url.pathname === "/api/library/skills/agents-some") { + const b = req.postDataJSON(); + posts.push(b); + for (const s of state.lib.skills) { + if (!b.names.includes(s.name)) continue; + const kept = s.agents.filter((a) => !b.agents.includes(a)); + s.agents = (b.on ? [...kept, ...b.agents] : kept).sort(); + } + return json({ ...state.lib, result: { changed: b.agents } }); + } + if (url.pathname === "/api/providers") return json({ providers: [], presets: [], excluded: [], gateway: { running: true, window: true }, plugins: [] }); + if (url.pathname === "/api/groups") return json({ groups: [], pools: [] }); + if (url.pathname === "/api/usage/quotas") return json([]); + if (url.pathname.startsWith("/api/")) return json({}); + if (url.host !== "magpie.test") return route.fulfill({ status: 404, body: "" }); + 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: "" }); } + }; +} + + +const NAMES = ["coder", "work", "play", "ops", "docs", "a", "b", "c", "d", "e", "f", "g"]; +const PROFILES = NAMES.map((n) => agent("hermes#" + n, "Hermes · " + n, "hermes")); + +for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) { + test(engine + ": a repository's heading folds an agent's profiles into one chip", async (t) => { + assert(["chromium", "webkit"].includes(engine), "BROWSER must be chromium or webkit"); + const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: process.env.PLAYWRIGHT_CHANNEL || "chromium" })); + t.after(() => browser.close()); + for (const width of [420, 980]) for (const lang of ["en", "zh", "zh-TW", "ja", "de"]) { + await t.test(lang + " " + width, async () => { + const state = { + lib: { + dir: `${HOME}/.magpie/library`, backups: `${HOME}/.magpie/backups`, home: HOME, + agents: [agent("claude", "Claude Code", "claudecode-color"), agent("hermes", "Hermes Agent", "hermes"), ...PROFILES, agent("codex", "Codex", "openai")], + instructions: { agents: [], sets: [] }, servers: [], foundServers: [], projects: [], foundSkills: [], problems: [], + skills: [gh("acme/kit", "mango", ["claude", "hermes", "hermes#coder"]), gh("acme/kit", "cherry", ["claude", "hermes", "hermes#coder", "hermes#work"]), gh("zed/tools", "pear", [])], + }, + }; + const posts = []; + const ctx = await browser.newContext({ viewport: { width, height: 760 }, reducedMotion: "reduce" }); + await ctx.addInitScript(() => { try { localStorage.setItem("magpie.libTab", "skills"); } catch {} }); + const page = await ctx.newPage(); + page.setDefaultTimeout(5000); + page.setDefaultNavigationTimeout(60000); + const errors = []; + page.on("pageerror", (e) => errors.push(e.message)); + await page.route("**/*", server(lang, state, posts)); + await page.goto("http://magpie.test/"); + await page.locator('button[data-view="library"]').click(); + const head = page.locator("#view-library .lib-grouphead").filter({ has: page.locator(".name", { hasText: /^acme\/kit$/ }) }); + await head.waitFor(); + if (!(await head.evaluate((h) => h.classList.contains("open")))) await head.locator(".name").click(); + const row = page.locator("#view-library .lib-skill > .lib-agents").first(); + await row.waitFor(); + const strip = head.locator(".lib-groupchips"); + + // the heading: claude, one Hermes chip, codex; not a chip per profile + assert.equal(await strip.locator('.lib-ag[data-agent^="hermes"]').count(), 0); + assert.equal(await strip.locator(".lib-ag.profiles").count(), 1); + assert.equal(await strip.locator(".lib-ag[data-agent]").count(), 2); + const chip = strip.locator(".lib-ag.profiles"); + // hermes and #coder have both skills; #work has one + assert.equal(await chip.locator(".cnt").textContent(), "2"); + assert(await chip.evaluate((c) => c.classList.contains("some"))); + + // a row's chips are one hand: each the same step from the last + for (const box of [strip, row]) { + await page.mouse.move(2, 2); + await page.waitForTimeout(400); + const lefts = await box.locator(".lib-ag:not(.all)").evaluateAll((cs) => cs.map((c) => c.getBoundingClientRect().left)); + const steps = lefts.slice(1).map((x, i) => Math.round((x - lefts[i]) * 2) / 2); + assert(steps.length >= 2); + assert(steps.every((d) => Math.abs(d - steps[0]) <= 0.5), "chips are out of line: " + steps); + } + + // a tick gives that profile every skill of the repository + await chip.click(); + const menu = page.locator(".proto-menu"); + await menu.waitFor(); + await menu.locator(".pm-item", { hasText: "play" }).click(); + await page.waitForTimeout(150); + assert.deepEqual(posts.shift(), { names: ["cherry", "mango"], agents: ["hermes#play"], on: true }); + assert.deepEqual(errors, []); + await ctx.close(); + }); + } + }); +}