From 61a04f42a2f84f282fdc93d14ee5f6fbb888b92c Mon Sep 17 00:00:00 2001 From: yetone Date: Wed, 11 Nov 2026 13:26:46 +0800 Subject: [PATCH] library: a project's Skills menu groups the skills by source, a heading ticks the whole group (Elorynth on X) The project card's Skills menu listed every library skill flat. It now lists them as the Library does (skillGroups(true): by repository or the user's own group, this computer's last, whatever sort the list has), with a heading over each group. Pressing a heading ticks all of the group's skills, or unticks them when all are in; it is half-ticked while some are. A typed filter keeps a group's heading over the skills it finds, and matches a skill by its group's name. One group only stays the flat list. openProtoMenu takes a `group` option (the values it ticks) for this. Paid for in app.js by five comments cut, no budget raise. Run on the Windows box (mote's Chromium launch hung, SSH refused at times): project-skills-groups.test.cjs, new, in chromium and webkit, en/zh/zh-TW/ja/de at 400px wide: red on the old code (6 of 6), green after. With project-*, i18n-*, menu-*, proto-menu-overflow and skill-group* GUI files in both engines: all green except menu-input-scroll and menu-scroll (14 chromium, 13 webkit), which are red the same at origin/main aa2ea5c90 on the Windows box (commented on #3402). TestCoreScriptBudget ok at the rebased head. Not tried: the full suite, the real Linux app (WebKitGTK). Part 2 of the report (instruction presets bundled into a toolkit) is not built: a project has no instructions of its own yet. --- docs/subsystems/library.md | 2 +- internal/gui/assets/app.css | 4 + internal/gui/assets/app.js | 56 ++++---- internal/gui/assets/plugins/library/client.js | 26 ++-- .../gui/tests/project-skills-groups.test.cjs | 120 ++++++++++++++++++ 5 files changed, 168 insertions(+), 40 deletions(-) create mode 100644 internal/gui/tests/project-skills-groups.test.cjs diff --git a/docs/subsystems/library.md b/docs/subsystems/library.md index dce377069..8d5d1ea20 100644 --- a/docs/subsystems/library.md +++ b/docs/subsystems/library.md @@ -21,7 +21,7 @@ Pi's extensions and packages. | 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. 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`). | [`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) | +| 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) | | Instructions | magpie's part of an agent's instructions file sits between two marker lines. The rest of the file is the user's. Several named sets can be switched between (#106). A set can be kept in a file of the user's own instead of `instruction-sets/` (`InstrSet.File`, 新v学员 on Discord): `~/.agents/AGENTS.md`, which Droid and omp read too. `textPath` reads it, `putText` keeps it aside and writes it but never removes it, removing the set lets go of it, and `linkable` refuses a file magpie writes into (an agent's own instructions, a file with the marker line), the library's own and another set's. The app's `KeepLinked` looks at the file every 30 s and writes a change into the agents (`SyncLinked`). A set's text is read without magpie's part (`setText`), and an agent whose instructions file is, links followed, the file the set on is kept in (`isSetFile`: `instructions.md` linked to `~/.claude/CLAUDE.md`, or both linked to one dotfile) gets no part written into it, and one written before is taken out with every part nested in it: read with its part, each sync wrote the whole file into that part again and it doubled, to gigabytes (#2349, `TestInstructionsSetLinkedToAgentsFile`). `Collect` carries the set's text, not where its file is; `Put` keeps this computer's file for the set and never empties it for a text not carried. Alma's file is `~/.config/alma/USER.md`, which its main chat reads into its system prompt as its owner's profile (0.4.164's `out/main/index.js`; a workspace's `USER.md` is read instead), and whose leading front matter (`name`, `telegram_id`, `discord_id`) is who its bots answer to (#2315, Jie211). The target is a `Profile`: magpie's part goes after the user's, so the front matter stays first, and `ImportInstructions` refuses it, as moving it out would take that front matter out of the file and into every agent's (`TestAlmaInstructionsKeepTheProfile`, `TestAlmaProfileIsNotImported`, `library-alma-profile.test.cjs`). MiniMax Code reads `AGENTS.md` in its data folder (`$MINIMAX_DATA_DIR`, else `~/.minimax`) before every conversation, so its target is that file (`TestMiniMaxCodeInstructions`). WorkBuddy and WorkBuddy AI keep theirs as a string in a JSON file: `personalization.customPrompt` in `app/app-config.json` of their folder, the Custom Instructions of the app's Personalization settings (`Target.Field`, `instr_field.go`). magpie's part goes into that string between the same marker lines, after the user's own prompt, and a `Field` write goes through `edit.SetJSON`, so every other key, its order and its indentation stay as the app wrote them; taking the part back leaves the file as it was, the field (and a `personalization` object nothing else is in) going out when it holds nothing. A file that is not JSON, or a field that holds something other than text, is unknown: it is reported and written over by nothing (`TestWorkBuddyInstructionsAreAJSONField`, `TestWorkBuddyInstructionsFromNothing`, `TestWorkBuddyInstructionsUnreadFileIsLeftAlone`, `TestWorkBuddyInstructionsImport`). The app's config service loads the file as it starts and writes it whole on a save (`AppConfigService`, 5.5.6's app.asar), so a change made while it runs may need a restart of the app, and may be lost to its next save of any setting; this has not been tried against a running app. | [`instructions.go`](../../internal/library/instructions.go) | | MCP servers | A `Server` is a command or a URL (`http`, `sse`). `mcpFile` encodes it in each agent's own format (one `mcpFormat` per agent family) and merges it with the user's own fields for that entry. A server's `StartupTimeout` (#3168) goes to Codex alone, as `startup_timeout_sec` in seconds (`RawMcpServerConfig` in codex-rs/config's mcp_types.rs; 0 leaves Codex's own 30s), in the user-wide config.toml and a project's alike. magpie keeps the value it wrote (`Applied.Startup`, `Project.Startup`): one in the entry other than that, or a `startup_timeout_ms`, is the user's and stays as it is (`startupTheirs`), and once it is taken out magpie's goes in again. The editor shows the field only when an agent that takes it is here (`AgentView.Startup`, `mcp_startup_test.go`, `mcp-startup-timeout.test.cjs`). `Also` files get the same servers; `Extra` files are only read when importing. `CheckServers` connects as an agent would and keeps the result in memory only: with each tool's name and the first paragraph of its description (`ToolList`, at most `maxToolList`, a description cut at `maxToolDesc` runes), which the page lists when the server's "N tools" is clicked, following tools/list's `nextCursor` up to `maxToolPages` pages (`listTools`). Each step (initialize, notifications/initialized, tools/list; connect for SSE) has its own budget, 60s for a URL and 30s for a command (`remoteStep`, `stdioStep`), and a timeout names its `Step` and how long it `Waited`; a timeout isn't kept, so the next look asks again (#1467). A command named bare that magpie's PATH lacks is started from where `proc.FindTool` finds it (fnm's Nodes on Windows among the folders), with that folder on the check's PATH, since npx's package runs the node beside it by name (`stdioProgram`, #2685, `TestStdioProgramFindsWhatPathLacks`). The page asks once a session for the servers some agent or project has (`inUse` in plugins/library/client.js); one no agent has shows "not checked" and is checked only when its status is clicked (#1597, `library-mcp-health.test.cjs`). A server checked once is checked again when it changes, its sign-in included, so a server signed in to after a click's "needs sign-in" isn't left showing both (新v学员 on Discord, `mcp-signin-health.test.cjs`). The check sends magpie's sign-in as the gateway does: on a 401 it renews the token once and asks again, and a server that refuses even the renewed token has the sign-in marked run out (`mcpauth.Rejected`, also from the gateway's `/mcp/`), which `ServerHealth.SignIn` carries back so the row's tag says "Sign-in ran out" rather than "Signed in" beside "needs sign-in". A server that refuses the check (401 or 403) but that an agent signed in to on its own is named so (`ServerHealth.AgentSignIn`, `readOwnSignIns` in `mcp_agent_signin.go`): each Claude Code target's `.credentials.json` beside its settings.json, a WSL distro's under the distro's home, is read for a `mcpOAuth` entry of the server's name and URL with a token, and each Codex target's `.credentials.json` beside its config.toml for a flattened entry of them, the file codex-rs falls back to when its config's `mcp_oauth_credentials_store` is `file` or the keyring is missing, whose executor's own entries are no `codex mcp login` (#3508); and the row says "signed in in Claude Code (Ubuntu)" — or Codex — instead of "needs sign-in" (CyberCaius on Discord: signed in to with Claude Code's /mcp in WSL). The tokens are never sent or kept; a file that can't be read or parsed names nobody, a stopped distro isn't started for it, and on a Mac only the file is read, never the Keychain Claude Code keeps them in nor Codex's keyring store. They are part of the check's key, so a sign-in in the agent since is checked anew (`TestCheckNamesAgentsSignedInThemselves`, `library-mcp-health-wsl.test.cjs`). A server that needs OAuth is signed in once in magpie, and agents reach it through the gateway's `/mcp/` (#615). The editor's Sign in saves the form first only when the sign-in is to another server than the saved one (a new server, a name or URL changed), and its button then reads "Save and sign in"; anything else edited (headers, env, arguments) stays unsaved until Save, so Cancel leaves the server as it was (新v学员 on Discord, `mcp-editor-cancel.test.cjs`). A server whose authorization server refuses magpie's dynamic client registration with 401 or 403 admits only the clients it lists (Figma's, #1619): the sign-in fails with `mcpauth.ErrClientRefused`, which says so and that each agent signs in itself, and the agents keep the server's own address. A server whose authorization server has no registration endpoint at all (GitHub's remote server, 新v学员 on Discord) fails with `mcpauth.ErrNoRegistration`, which says to make an OAuth app with the vendor and give it in the editor; the editor then opens its "OAuth app" fields. The app is the server's `oauth` (`OAuthApp`: `clientId`, `clientSecret`, `callbackPort`, Claude Code's names for `--client-id`, `--client-secret` and `--callback-port`), checked on save (HTTP only, a client ID, a port from 1 to 65535), and `SignInServer` signs in as it through `mcpauth.StartWith` without registering. The callback is Claude Code's, `http://localhost:/callback` (its docs' "Use pre-configured OAuth credentials"; 2.1.296 builds it so), listened for on 127.0.0.1 alone as Claude Code does, so an app made for Claude Code signs magpie in as it is; a server that matches the registered URL exactly refuses another host, which is why Claude Code's 2.1.231 went back to `localhost` from 2.1.229's `127.0.0.1` (`TestAppMadeForClaudeCode`). Without a `callbackPort` the port is any free one, which a loopback callback registered without a port takes (GitHub's, RFC 8252); a fixed `callbackPort` is for a vendor that matches the port too. magpie's own registration, when a server has one, still names `127.0.0.1`. The client secret is kept in library.json, as a header's or env's value is: a backup without keys leaves it out, and `WithSecrets` puts back this computer's secret only for the same client ID; no agent is given the app, and the TUI's editor, which doesn't show it, keeps it. GitHub answers a token request's error with a 200 and `error` in the body (`bad_refresh_token`, `incorrect_client_credentials`), which `tokenRequest` reads as the error it is, and a dead refresh token marks the sign-in run out (`github_app_test.go`, `mcp-oauth-app.test.cjs`). magpie never registers under another client's name; one that reaches the gateway from another machine (a WSL distro under NAT) is given it with the LAN sharing key as its `Authorization` (`agent.KeyAt`), as its models are, which the gateway takes in place of a sign-in and never passes on; turning sharing on or off, or a new key (`access.LANChanged`), writes such entries again. `ConfigOfServers` is the servers picked as an agent's project file (`projectMCPFiles`) would hold them, written by the same code into a folder of its own and read back, with those the agent can't take there named; the page's Copy config… puts it on the clipboard for a project magpie doesn't keep (#1478). The editor's command is a box that wraps, so a long line is read whole, and Enter still saves it (hema_17384 on Discord). Its Form | JSON switch shows the server as JSON in Claude Code's `.mcp.json` shape, the one Copy config… gives for it (`jsonOf` in plugins/library/client.js), with `${NAME}` references as written. An edit there is read as a paste is (`serversIn`) and becomes the form's at once. JSON that isn't one server's keeps the dialog from saving or going back to the form, and counts as unsaved. The note, the agents and sync stay in the form (`library-mcp-json.test.cjs`). A server's and a skill's `Note` (youyo.p_10001 on Discord) is the user's own word on what it is for: one line of at most `maxNote` (200) characters, whitespace run together (`checkNote`), as a hook's description is. The row shows it in place of the command or description, and its tooltip still gives that line. The skills' filter reads it too. A sync carries it (a server whole, a skill as `CarriedSkill.Note`), and no agent is given it, through the MCP router or not (`TestNoteNeverGiven`, `TestNoteCarried`). A skill's is set by itself (`SkillNote`, `skills/note`) from the skill's reader. Each listed tool has a switch: the tools turned off are the server's `DisabledTools`, set by `ServerTools`, and written into each agent given the server that can leave out a single tool (see the constraint below). A server run as `npx -y args` (a registry package, no other npx flag) is given to an agent on this machine as `node args` (`npxDirect`): magpie installs the package with npm into a folder of its own under `mcp-npm` in the background, the next sync writes the node form, and until then, or when npm fails (tried again after an hour), the agent keeps npx. npx otherwise stays as the server's parent for its whole life, a node and two cmd.exe beside each instance on Windows (#3885). An unpinned spec is installed again after a day, as npx would fetch the newer one; an install no library server runs goes a day after its last. The library, a server's check, Copy config… and agents in WSL keep npx (`TestNpxServerRunsByNode`, `TestReadNpx`). | [`mcp.go`](../../internal/library/mcp.go), [`mcp_npx.go`](../../internal/library/mcp_npx.go), [`mcp_check.go`](../../internal/library/mcp_check.go), [`mcp_signin.go`](../../internal/library/mcp_signin.go), [`mcp_agent_signin.go`](../../internal/library/mcp_agent_signin.go), [`mcp_copy.go`](../../internal/library/mcp_copy.go), [`mcp_tools_off.go`](../../internal/library/mcp_tools_off.go) | | MCP server on/off | `ServerOn` (`POST /api/library/servers/on` with `name` and `on`, `magpie library mcp off|on `) turns a server off for everyone without removing it (swang20201 on X, Docker gateway mode, where a server ticked for no agent is still given to every app at the MCP router's address). Off, it is `Hidden` with its agents kept in `Paused` and `Agents` empty, as a plugin's server hidden from agents is (`PluginServerOn`, [Plugin tools](plugin-tools.md)): no agent's file has it, no project's (`syncProjectMCP` skips it, keeping the project's own agents for it), no subagent names it (`renderSubagent`), the router lists and calls it for nobody, and a process the router held for it ends, since `Hidden` and `Paused` are part of its `hubKey`. Its command, URL, env, headers, sign-in, `DisabledTools` and note stay in library.json. On, the agents in `Paused` get it back (none when it had none, so the router gives it to other apps again), as before it was turned off; giving it agents (`ServerAgents`, the CLI's `mcp agents`) turns it on with those (`save`), while Turn all on (`EveryServerAgents` with every agent) leaves it off. The row's switch sits after its agent chips (`serverSwitch` in plugins/library/client.js); off, the row is dimmed, its chips take no click, and it is health-checked only on a click (`TestServerOnKeepsAndRestores`, `TestLibraryMCPOffOn`, `library-mcp-on.test.cjs`). | [`mcp_on.go`](../../internal/library/mcp_on.go), [`project_mcp.go`](../../internal/library/project_mcp.go), [`subagents.go`](../../internal/library/subagents.go) | diff --git a/internal/gui/assets/app.css b/internal/gui/assets/app.css index fbf090c45..ee6214422 100644 --- a/internal/gui/assets/app.css +++ b/internal/gui/assets/app.css @@ -3179,6 +3179,10 @@ body.window .ag-sk-icon { width: 22px; height: 22px; border-radius: 6px; } /* a menu of actions, where nothing is or can be ticked, keeps no room for a tick: its items line up with its heading */ .proto-menu.pm-bare .pm-tick { display: none; } +/* a group's heading in a menu of many: it ticks all of its items */ +.proto-menu .pm-group { margin-top: 3px; } +.proto-menu .pm-group .pm-name { font-size: 11px; font-weight: 600; color: var(--muted); } +.proto-menu .pm-group.mixed .pm-tick::before { content: ""; width: 8px; height: 1.5px; border-radius: 1px; background: currentColor; } .proto-menu .pm-words { display: grid; gap: 1px; min-width: 0; } .proto-menu .pm-name { font-size: 12.5px; font-weight: 500; line-height: 16px; } .proto-menu .pm-note { font-size: 11px; color: var(--muted); line-height: 15px; } diff --git a/internal/gui/assets/app.js b/internal/gui/assets/app.js index 33f9ef706..768a4236b 100644 --- a/internal/gui/assets/app.js +++ b/internal/gui/assets/app.js @@ -4236,12 +4236,8 @@ async function load(again) { // the panel's allowances asked beside the state, not after it (#3134) const early = mode === "panel" && !load.done; if (early) panelQuotasNow(again); - // the first load draws the state magpie kept from its last read while - // the fresh one is read (#1519, fatkun): reading every agent's config, - // and a WSL distro's through \\wsl.localhost, took seconds after a - // start or after light mode let the window go. The fresh state - // replaces it the moment it is in, so an agent leaves the list only - // once that says it is gone. + // the first load draws the state kept from the last read while the + // fresh one (seconds, #1519) is read; an agent leaves only once that says so let relang = false, shown = null; if (!load.done) { const last = await Promise.race([api("state?last=1").catch(() => null), asked.then(() => null, () => null)]); @@ -4511,11 +4507,8 @@ function updateStuck(u) { } // ---------- what's new ---------- -// After an update the window (or magpie web's page) shows what changed in -// every release since the one last run, once (a Discord user: to see if -// their issue was fixed). Not in the tray's panel, where a dialog has no -// room; Settings' version row opens it again, and with an update waiting, -// that one's notes first. +// After an update the window (or magpie web) shows each release's changes +// since the one last run, once; Settings' version row opens it again. const ISSUES = "https://github.com/yetone/magpie/issues/"; let whatsNewAsked = false; // cliBehindOnce: the terminal's magpie is a copy, not the installer's @@ -5408,10 +5401,8 @@ function renderList() { // fastToggle: a model with a fast mode (a ChatGPT account's GPT, Cursor's // -fast, …) is sent in it, or not, for the agent the picker is of (#954), -// switched by the model as a routing group's member is; the pick itself -// stays as it is. Where an account offers it Ultrafast too (ultraOk, -// #1954), a click steps usual → Fast → Ultrafast → usual, as a camera's -// flash button steps its modes +// switched by the model as a routing group's member is. Where ultraOk +// (#1954), a click steps usual → Fast → Ultrafast → usual const BOLT = "M9.25 1.75 3.75 9h4l-1 5.25L12.25 7h-4z"; function fastToggle(o) { const b = el("button", "fast" + (o.fast ? " on" : "") + (o.fast && o.ultra ? " ultra" : "")); @@ -7544,11 +7535,9 @@ function providerDirty() { (active?.matches(".editor .mprice input") && active.value !== active.defaultValue)); } // backdropClick(el, on) says whether a click on el is one on its backdrop: -// pressed and let go both where on(e) says the backdrop is. A press inside -// the dialog let go out over the backdrop, a selection dragged out of a -// field (#1373), clicks the two's nearest shared ancestor, the backdrop, so -// the click's own target can't tell it apart. Every dialog that closes from -// its backdrop asks this. +// pressed and let go both where on(e) says the backdrop is: a selection +// dragged out of a field (#1373) clicks the backdrop too. Every dialog that +// closes from its backdrop asks this. function backdropClick(el, on = (e) => e.target === el) { let down = false, up = false; el.addEventListener("pointerdown", (e) => { down = on(e); up = false; }, true); @@ -15280,7 +15269,8 @@ function openProtoMenu(anchor, opts, value, choose, head = "Protocol this key sp const multi = Array.isArray(value); let picked = multi ? [...value] : null; // an item with its own ticked (true or false) is a setting beside the pick - const isOn = (v, o) => typeof o?.ticked === "boolean" ? o.ticked : !multi ? v === value : v === "" ? !picked.length : picked.includes(v); + // a group heading (o.group, its values) is ticked when all of them are + const isOn = (v, o) => o?.group ? o.group.every((g) => picked.includes(g)) : typeof o?.ticked === "boolean" ? o.ticked : !multi ? v === value : v === "" ? !picked.length : picked.includes(v); const box = el("div", "pop proto-menu" + (cls ? " " + cls : "")); box.setAttribute("role", "menu"); box.append(el("div", "pm-head", t(head))); @@ -15295,14 +15285,15 @@ function openProtoMenu(anchor, opts, value, choose, head = "Protocol this key sp } const tick = (b, o) => { b.classList.toggle("on", isOn(o.v, o)); + if (o.group) b.classList.toggle("mixed", !isOn(o.v, o) && o.group.some((g) => picked.includes(g))); b.setAttribute("aria-checked", isOn(o.v, o)); b.firstChild.replaceChildren(...(isOn(o.v, o) ? [svg(CHECK, 12, 1.9)] : [])); }; const items = opts.map((o) => { - const b = el("button", "pm-item"); + const b = el("button", "pm-item" + (o.group ? " pm-group" : "")); b.type = "button"; if (o.title) b.title = o.title; - b.setAttribute("role", multi && o.v && o.v !== "\x00" || typeof o.ticked === "boolean" ? "menuitemcheckbox" : "menuitemradio"); + b.setAttribute("role", o.group || multi && o.v && o.v !== "\x00" || typeof o.ticked === "boolean" ? "menuitemcheckbox" : "menuitemradio"); const words = el("span", "pm-words"); words.append(el("span", "pm-name", o.literalName ? o.name : t(o.name)), el("span", "pm-note", t(o.note))); b.append(el("span", "pm-tick"), words); @@ -15310,6 +15301,12 @@ function openProtoMenu(anchor, opts, value, choose, head = "Protocol this key sp b.onclick = (e) => { e.stopPropagation(); if (!multi) { closeProtoMenu(); choose(o.v, e); return; } + if (o.group) { + picked = isOn(o.v, o) ? picked.filter((v) => !o.group.includes(v)) : [...new Set([...picked, ...o.group])]; + items.forEach((it, i) => tick(it, opts[i])); + if (live) choose(opts.map((o) => o.v).filter((v) => picked.includes(v))); + return; + } if (o.v === "\x00") return; if (!o.v) { picked = []; closeProtoMenu(); if (live) choose([]); return; } picked = picked.includes(o.v) ? picked.filter((v) => v !== o.v) : [...picked, o.v]; @@ -15326,7 +15323,8 @@ function openProtoMenu(anchor, opts, value, choose, head = "Protocol this key sp bareTicks(box, items); if (filter) filter.oninput = () => { const q = filter.value.trim().toLocaleLowerCase(); - items.forEach((b, i) => { b.hidden = !opts[i].always && !(opts[i].name + " " + (opts[i].find || "")).toLocaleLowerCase().includes(q); }); + items.forEach((b, i) => { if (!opts[i].group) b.hidden = !opts[i].always && !(opts[i].name + " " + (opts[i].find || "")).toLocaleLowerCase().includes(q); }); + items.forEach((b, i) => { if (opts[i].group) b.hidden = !opts[i].group.some((v) => items.some((m, j) => opts[j].v === v && !m.hidden)); }); }; document.body.append(box); placeMenu(box, anchor, align); @@ -15344,7 +15342,7 @@ function openProtoMenu(anchor, opts, value, choose, head = "Protocol this key sp if (e.key === "ArrowDown" || e.key === "ArrowUp") { stepFocus(e, shown, i); } else if (filter && e.key === "Enter" && document.activeElement === filter) { - const first = shown.find((b) => !opts[items.indexOf(b)].always); + const first = shown.find((b) => !opts[items.indexOf(b)].always && !opts[items.indexOf(b)].group); if (first) { e.preventDefault(); first.click(); } } else if (filter && (e.key === "Home" || e.key === "End") && i >= 0) { e.preventDefault(); @@ -22758,11 +22756,9 @@ function prefsKeep(s) { } // savePrefs sends what the page was drawn with (prefsBase) and the choice -// made on it. The saves go one after another, each with the choices before -// it: two made quickly (a theme, then a language) each sent the page as it -// was drawn, the second undoing the first, and their answers could come -// back in either order. The page is painted and drawn again once the last -// is in. +// made on it. Saves go one after another, each with the choices before it: +// two quick ones (a theme, then a language) undid each other. The page is +// drawn again once the last is in. let prefsBase = {}, prefsQueue = Promise.resolve(), prefsQueued = 0; function savePrefs(body) { const change = Object.fromEntries(Object.entries(body).filter(([k, v]) => JSON.stringify(v) !== JSON.stringify(prefsBase[k]))); diff --git a/internal/gui/assets/plugins/library/client.js b/internal/gui/assets/plugins/library/client.js index 05566f9d6..3754488cf 100644 --- a/internal/gui/assets/plugins/library/client.js +++ b/internal/gui/assets/plugins/library/client.js @@ -4874,16 +4874,17 @@ magpie.plugin("library", (ctx) => { const SKILL_SORTS = () => [["source", t("By source")], ...NAME_SORTS]; // the groups, and each skill's text to filter by, worked out once for // each answer from magpie and each pick - let grouped = null; - function skillGroups() { - const pick = sortOf("libSkills", SKILL_SORTS()); - if (grouped?.lib === lib && grouped.pick === pick) return grouped.groups; + let grouped = {}; // sort → { lib, groups } + // bySource: the project picker's grouping, whatever sort the list has + function skillGroups(bySource = false) { + const pick = bySource ? "source" : sortOf("libSkills", SKILL_SORTS()); + if (grouped[pick]?.lib === lib) return grouped[pick].groups; if (pick !== "source") { const skills = [...lib.skills].sort(byName(pick)); const g = { key: "flat", repo: "", skills, parts: null, text: new Map(skills.map((s) => [s, (s.name + " " + (s.note || "") + " " + (s.description || "") + " " + skillRepo(s)).toLowerCase()])) }; - grouped = { lib, pick, groups: [g] }; - return grouped.groups; + grouped[pick] = { lib, groups: [g] }; + return grouped[pick].groups; } // the user's own groups first, in the order made, each skill in its // group rather than its source's (#791) @@ -4932,7 +4933,7 @@ magpie.plugin("library", (ctx) => { g.text = new Map(g.skills.map((s) => [s, (s.name + " " + (s.note || "") + " " + (s.description || "") + " " + (g.mine || (g.owner ? skillRepo(s) : g.repo))).toLowerCase()])); g.parts = g.mine ? null : partsOf(g); } - grouped = { lib, pick, groups }; + grouped[pick] = { lib, groups }; return groups; } @@ -5943,7 +5944,14 @@ magpie.plugin("library", (ctx) => { const global = (s) => (s.agents || []).filter((id) => offIds.includes(id) && !routedOff(agentOf(id) || { name: id }, s)); const inherited = (s) => !p.skills[s.name]?.length && global(s).some((id) => !(p.skillsOff?.[s.name] || []).includes(id)); const now = lib.skills.filter((s) => p.skills[s.name]?.length || p.problems?.[s.name] || inherited(s)).map((s) => s.name); - const opts = lib.skills.map((s) => ({ v: s.name, name: s.name, literalName: true, note: "" })); + // by source, as the Library lists them, a heading ticking its group + const gs = skillGroups(true); + const opts = gs.length < 2 ? lib.skills.map((s) => ({ v: s.name, name: s.name, literalName: true, note: "" })) + : gs.flatMap((g) => { + const title = g.mine || g.repo || t("On this computer"); + return [{ v: "\x00" + g.key, group: g.skills.map((s) => s.name), name: title, literalName: true, note: "" }, + ...g.skills.map((s) => ({ v: s.name, name: s.name, literalName: true, note: "", find: title }))]; + }); openProtoMenu(b, opts, now, async (next) => { const byName = (n) => lib.skills.find((s) => s.name === n); let adds = next.filter((n) => !now.includes(n)), outs = now.filter((n) => !next.includes(n)); @@ -5977,7 +5985,7 @@ magpie.plugin("library", (ctx) => { ? t("{skill} is out of {name}", { skill: outs[0], name: p.name }) : t("{skills} are out of {name}", { skills: names(outs), name: p.name })); } - }, "Pick the skills it gets", "", "right", false, opts.length > 8 ? "Find a skill" : ""); + }, "Pick the skills it gets", "", "right", false, lib.skills.length > 8 ? "Find a skill" : ""); }); b.setAttribute("aria-expanded", "false"); if (!lib.skills.length || !all.length) b.disabled = true; diff --git a/internal/gui/tests/project-skills-groups.test.cjs b/internal/gui/tests/project-skills-groups.test.cjs new file mode 100644 index 000000000..27c9aac23 --- /dev/null +++ b/internal/gui/tests/project-skills-groups.test.cjs @@ -0,0 +1,120 @@ +// Run with Node's test runner and Playwright on the module path; see README.md. +// Elorynth on X: adding skills to a project, show them grouped by source as +// the Library does, with a click on a group's heading for the whole group. +// The project's Skills menu lists the library's skills by source, a heading +// over each group that ticks (and unticks) all of its skills in one click, +// half-ticked while some are in. Typing a repository finds its skills. With +// one group only, the menu is the flat list it was. In every language, at +// phone width. No backend: the API is faked. +const assert = require("node:assert/strict"); +const fs = require("node:fs/promises"); +const path = require("node:path"); +const { test } = require("node:test"); +const { chromium, webkit } = require("playwright"); + +const assets = path.resolve(__dirname, "../assets"); +const HOME = "/Users/emo"; +const APP = HOME + "/code/app", WEB = HOME + "/code/web"; +const agent = (id, name, more = {}) => ({ id, name, icon: "", skills: `${HOME}/.${id}/skills`, ...more }); +const sk = (name, repo) => ({ name, description: name + " things", agents: ["claude", "codex"], ...(repo ? { kind: "github", source: "https://github.com/" + repo + "/tree/main/" + name } : {}) }); + +function server(lang, posts) { + const projects = { + [APP]: { "kit-a": ["codex"] }, + [WEB]: {}, + }; + const lib = () => ({ + dir: `${HOME}/.magpie/library`, backups: `${HOME}/.magpie/backups`, home: HOME, + agents: [ + agent("claude", "Claude Code", { projectSkills: ".claude/skills" }), + agent("codex", "Codex", { projectSkills: ".agents/skills" }), + agent("goose", "Goose"), + ], + instructions: { agents: [] }, servers: [], skills: [sk("pdf"), sk("l1"), sk("l2"), sk("l3"), sk("l4"), sk("l5"), sk("kit-a", "acme/kit"), sk("kit-b", "acme/kit"), sk("tool-c", "beta/tools")], foundServers: [], foundSkills: [], + projects: Object.entries(projects).map(([dir, skills]) => ({ dir, name: path.basename(dir), copy: false, skills: { ...skills }, placed: [], servers: {}, wrote: {} })), + }); + 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/library") return route.fulfill({ json: lib() }); + if (url.pathname === "/api/library/projects/skills") { + const b = req.postDataJSON(); + posts.push(b); + for (const n of b.names) { + if (b.agents.length) projects[b.dir][n] = b.agents; + else delete projects[b.dir][n]; + } + return route.fulfill({ json: { ...lib(), result: { changed: [], problems: [] } } }); + } + if (url.pathname === "/api/plugins") return route.fulfill({ json: { plugins: [] } }); + 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 heads = { en: "On this computer", zh: "本机", "zh-TW": "本機", ja: "このコンピュータ", de: "Auf diesem Computer" }; + +for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) { + test(engine + ": a project's Skills menu is grouped by source", 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 Object.keys(heads)) { + await t.test(lang, async () => { + const posts = []; + const ctx = await browser.newContext({ viewport: { width: 400, height: 2400 } }); + await ctx.addInitScript(() => { try { localStorage.setItem("magpie.libTab", "skills"); } catch {} }); + const page = await ctx.newPage(); + page.setDefaultTimeout(5000); + page.setDefaultNavigationTimeout(60000); + page.on("pageerror", (e) => errors.push(e.message)); + await page.route("**/*", server(lang, posts)); + await page.goto("http://magpie.test/"); + await page.locator('button[data-view="library"]').click(); + const app = page.locator("#view-library .lib-project").filter({ hasText: "~/code/app" }); + await app.waitFor(); + await app.locator(".lib-projhead").click(); + await app.locator(".lib-projskill").first().waitFor(); + const menu = page.locator(".proto-menu"); + await app.locator(".lib-projpick").click(); + await menu.waitFor(); + const state = () => menu.locator(".pm-item").evaluateAll((bs) => bs.map((b) => [b.textContent.trim(), b.getAttribute("aria-checked"), b.classList.contains("mixed")])); + assert.deepEqual((await state()).slice(0, 5), [ + ["acme/kit", "false", true], ["kit-a", "true", false], ["kit-b", "false", false], + ["beta/tools", "false", false], ["tool-c", "false", false], + ], "a heading over each source, half-ticked while some of its skills are in"); + assert.equal((await state())[5][0], heads[lang], "this computer's skills last"); + const box = await menu.boundingBox(); + assert(box.x >= 0 && box.x + box.width <= 400, "the menu fits a phone"); + + // one click ticks the whole group, the next takes it out + await menu.locator(".pm-group", { hasText: "acme/kit" }).click(); + assert.deepEqual((await state()).slice(0, 3), [["acme/kit", "true", false], ["kit-a", "true", false], ["kit-b", "true", false]]); + await menu.locator(".pm-group", { hasText: "beta/tools" }).click(); + await menu.locator(".pm-group", { hasText: "beta/tools" }).click(); + assert.equal(posts.length, 0, "nothing is written while the menu is open"); + await menu.locator(".pm-group", { hasText: "acme/kit" }).click(); + assert.deepEqual((await state()).slice(0, 3), [["acme/kit", "false", false], ["kit-a", "false", false], ["kit-b", "false", false]]); + await menu.locator(".pm-group", { hasText: "acme/kit" }).click(); + + // the repository typed finds its skills, under their heading + const q = menu.locator(".sc-q"); + await q.fill("beta"); + assert.deepEqual(await menu.locator(".pm-item:not([hidden])").evaluateAll((bs) => bs.map((b) => b.textContent.trim())), ["beta/tools", "tool-c"]); + await q.fill(""); + await page.keyboard.press("Escape"); + await page.waitForFunction(() => document.querySelector("#status")?.textContent.trim()); + assert.deepEqual(posts, [{ dir: APP, names: ["kit-b"], agents: ["codex"] }], "the group's other skill goes in for the project's agents"); + assert.deepEqual(errors, []); + await ctx.close(); + }); + } + }); +}