From ac456d819f1bf2bd52e4c8fbc98a5b620e0736ec Mon Sep 17 00:00:00 2001 From: yetone Date: Fri, 20 Nov 2026 12:00:36 +0800 Subject: [PATCH] library: a plugin's tag shows only what that plugin brought (#7280) Skills, Hooks and Subagents tag a part a Claude plugin brought "In ", but nothing on those tabs could narrow to a plugin: typing its name in the skills' filter found nothing (jinpwng). - On Skills, Hooks and Subagents the tag is now a button. It shows only that plugin's items, under a bar naming it ("Only what code-kit brings") with Show all. The pick is per tab and in memory only; nothing is written. It clears itself once the plugin brings none of the tab's items. MCP keeps the plain tag. - The skills' filter matches a skill's plugin name too. - A clickable tag on a library row wraps under a long name instead of being cut off by the name's ellipsis. At 420px in zh, zh-TW, ja and de the tag was clipped and could not be clicked. This also covers "Update available". - New string in zh, zh-TW, ja and de. Run (mote, load ~30-45 from other sessions' suites): node --test library-plugin-filter (new: each tab, tag to bar to Show all, the skills filter by plugin name, no write, no dialog, no page error; en, zh, zh-TW, ja and de at 420 and 1100, chromium and webkit), skill-where, skill-auto-update, skill-update-edited, skill-update-feedback, phone-no-sideways and library-plugin-parts: 210 of 210 ok. Before the wrap rule, library-plugins, library-hooks, library-subagents(-import), skill-groups, skill-parts and i18n-keys were run too. Only library-plugin-filter's 420 non-English cases failed there (the clipped tag, now fixed), plus one webkit skill-where "ResizeObserver loop" page error that passed on the rerun. Broken by hand: with the tag's onclick setting nothing, library-plugin-filter is 0 of 62. Not tried: a real Claude plugin in the app; the faked API has one. --- docs/subsystems/library.md | 2 +- internal/gui/assets/plugins/library/client.js | 59 ++++++--- internal/gui/assets/plugins/library/i18n.js | 4 + .../gui/assets/plugins/library/library.css | 5 + .../gui/tests/library-plugin-filter.test.cjs | 119 ++++++++++++++++++ 5 files changed, 174 insertions(+), 15 deletions(-) create mode 100644 internal/gui/tests/library-plugin-filter.test.cjs diff --git a/docs/subsystems/library.md b/docs/subsystems/library.md index cfc759a07..9fac043e7 100644 --- a/docs/subsystems/library.md +++ b/docs/subsystems/library.md @@ -43,7 +43,7 @@ Pi's extensions and packages. | Slash commands | A `Command` (miantiao_me on X) is a name (lowercase letters, digits, - and _), a one-line description and a prompt, given to the agents ticked for it, and typed as /name there. The prompt says `$ARGUMENTS` for every word typed after the name and `$1`, `$2`… for the first, second… of them. `syncCommands` writes it as a file of its own in each agent's user-level folder, in that agent's shape (`commandSpecOf`): `/commands/.md` (front matter `description`; `$n` becomes Claude Code's `$ARGUMENTS[n-1]`, counted from 0), OpenCode's `commands/.md` beside its config and Pi's `/prompts/.md` (`$ARGUMENTS` and `$n` as magpie's), `~/.gemini/commands/.toml` (`description`, `prompt`, `$ARGUMENTS` as `{{args}}`), Qwen Code's `commands/.md` (`{{args}}`) and `~/.factory/commands/.md` (`$ARGUMENTS`). Gemini CLI, Qwen Code and Droid take no words by place, so a command that uses `$1`… isn't written for them: the agent gets a problem, the editor names them under the prompt while it uses one, and the tab says so under the list. Codex is listed but greyed: Codex 0.165 has no loader of `~/.codex/prompts` any more, its skills took their place. An agent in a WSL distro gets none. The page lists, per agent, its folder and whether it takes `$1`… (`CommandAgentView`). There is no CLI for them yet. | [`commands.go`](../../internal/library/commands.go), `TestCommandsEachAgentsFile`, `TestCommandsWordsByPlace` | | Slash commands from the agents | The Slash commands tab's "Find in agents" (miantiao_me on X: "can the ones I defined in Pi be imported?") lists the commands the user already made in each agent here (`ProbeCommands`), read where that agent reads them, at the folder's top only: Pi's `prompts/*.md`, Claude Code's `commands/*.md`, OpenCode's `commands/*.md` and `command/*.md`, Gemini CLI's `commands/*.toml`, Qwen Code's `commands/*.md` and `*.toml` (its FileCommandLoader reads both) and Droid's `commands/*.md`. The file's name is the command's; the description is the front matter's (a TOML's `description`), the prompt the body (a TOML's `prompt`), and each agent's way of saying the words typed in reads back as magpie's: Claude Code's `$ARGUMENTS[n]` and `$n`, counted from 0, as `$n+1` (the `\$0` magpie writes as `$0`), Pi's `$@` and Gemini's and Qwen's `{{args}}` as `$ARGUMENTS`; Pi's `${@:N}` is left as written. A name magpie can't take, a file over 1 MB or one with no prompt is listed as left out, with why. A file magpie wrote, still as it wrote it (`Applied.Commands`), isn't listed. One name saying the same in several agents is one candidate for all of them; saying different things, each is listed, tagged, and only one can be picked. A name the library has saying the same is tagged and joins (the import ticks these agents too); one the library has for another command can't be picked, and the user's file stays as it is. `ImportCommands` takes the paths picked, reads them again, and ticks the agents each was found in. Each command keeps the files it came from (`Command.Taken`, per agent: path, bytes, and a hash of what they said): while the command says the same, `syncCommands` writes those bytes at that path, so `syncOwnFiles` takes the user's own file as magpie's byte for byte, and nothing is doubled or written over (OpenCode's `command/` file stays there). After an edit here, the command is written in the agent's shape at the same path when its extension is the one magpie writes, else at magpie's own path. A rename drops `Taken`. Unticking or removing an imported command takes its file away, into the backups, as with any file of magpie's. `Taken` is this computer's: never in `Bundle.Commands` or the page's view, and a bundle put here keeps it for a command of the same name. | [`command_import.go`](../../internal/library/command_import.go), `TestCommandImportPiPrompts` (Pi's own `.pi/prompts` files in `testdata/pi-prompts`), `TestCommandImportArgs`, `TestCommandImportByName`, `TestCommandImportNotCarried`, `library-commands-import.test.cjs` | | Rules | A `Rule` (JonahFu on X) is a name (as a slash command's), a Markdown body and, if wanted, `Paths`: globs, one a line in the editor, that keep it to the files they match. `syncRules` writes it as `.md` in each ticked agent's own folder of rules (`ruleSpecOf`), through the shared `syncOwnFiles`: Claude Code's `/rules` (front matter `paths`, the only key it reads; checked against the memory docs and v2.1.327, which reads every .md under the folder, loads one without `paths` at launch and one with them when Read/Write/Edit touches a match), Cline's `/rules` (CLINE_DIR, else ~/.cline; Cline 3.0.70 reads every rule always and has no paths key, so a rule with paths isn't written for it: the agent gets a problem (`noPaths`), and the editor names it under the paths) and Kiro CLI's steering folder beside its AGENTS.md (`inclusion: fileMatch` and `fileMatchPattern` for paths, else always; a rule called `agents` is refused there, as it would be AGENTS.md on a disk that ignores case). A body starting with `---` gets an empty front matter first, so it isn't read as one. Cursor (user rules live in its settings, `.cursor/rules` is per project), Codex (its rules are execpolicy) and Droid (command permissions) read no such folder and aren't listed; nor are Gemini CLI, Qwen Code and OpenCode, which read only their instructions file. An agent in a WSL distro gets none. The editor lists each agent's file as a path to show (`revealable`). Bundles carry them as slash commands; there is no CLI yet. | [`rules.go`](../../internal/library/rules.go), `TestRulesEachAgentsFile`, `TestRulesKeptToTheirPaths`, `TestRulesLeaveTheUsersFiles`, `TestRulesCarried`, `library-rules.test.cjs` | -| Claude plugins | A `Plugin` (FakeshadowzZ on X) is a Claude Code plugin kept as one item: `.claude-plugin/plugin.json` (or Codex's `.codex-plugin/plugin.json`, #7255: its `skills`, `mcpServers` and `hooks` read the same way, Claude's fields winning where both name one; the hooks it names are Codex's own, kept as written as `codex:` and given to Codex alone, an event Codex has none called is left out; `plugin_codex_test.go`), `skills//SKILL.md`, `agents/*.md`, `hooks/hooks.json` and `.mcp.json`, from a folder, a git address or a marketplace.json (`ProbePlugins`, `InstallPlugins`; a marketplace entry with a relative path, or a github/url/git source, is fetched when installed). Its files are copied to `/plugins/`; `${CLAUDE_PLUGIN_ROOT}` is that folder and `${CLAUDE_PLUGIN_DATA}` is `/plugin-data/`, which an update keeps. No agent sets either variable outside Claude Code's plugin runtime, so every reference is resolved before a part is written out ([`plugin_env.go`](../../internal/library/plugin_env.go)): `${NAME}`/`$NAME` in a hook command, a server's command, args and env, a subagent's prompt and a copied SKILL.md become the folder; a hook program's own read (`process.env.NAME`, `Bun.env`, `Deno.env.get`, Python's `os.environ`/`os.getenv`, Ruby's `ENV`) becomes a quoted string literal of the folder with forward slashes, and PowerShell's `$env:NAME` and cmd's `%NAME%` the folder (ponytail's hooks threw at every start without it, @AXmake110 on X); a command server is given both variables in its env, as Claude Code gives them. Parts a magpie before this wrote with the variables in them are resolved at load (`healPluginRefs`) and written out again at the next sync; a SKILL.md copied before is fixed by Update or a reinstall. Exec-form hooks (`args`) and `CLAUDE_PLUGIN_OPTION_` are not carried yet (#6682). Its parts are ordinary library skills, MCP servers, hooks and subagents, each tagged `Bundle: `, so every agent gets them through the code of its kind and the old tabs go on working; the plugin holds the names, its agents and `Off`. `PluginAgents` sets every part's agents, `PluginOn` clears them (kept in `Agents` for turning it on again) or gives them back, `RemovePlugin` removes the parts (and takes the plugin out of every project), `ProjectPlugin` gives it to a project (see Projects), and `UpdatePlugin` reads the source again. A plugin at the top of a git or GitHub download is named after the repository (`rootName`: `file:///srv/acme-pi.git` is `acme-pi`), never after the download's temp folder (`magpie-skill-…`), and an update of a one-plugin source keeps the bundle's own name, so the folder, the projects that have it and the Pi entry they were given (`.pi/settings.json`'s `packages`) stay the same and load the new files; one named `magpie-skill-…` by a magpie before this keeps that name (#7269, jinpwng; `TestPiPackageFromGitUpdatesInPlace`, `TestPluginUpdateKeepsItsName`, `TestPluginRootName`). A Pi package (`package.json` with a `pi` object) is a plugin too, one with only extensions included (#7267, jinpwng): its package.json gives the name, description and version a plugin manifest doesn't, and the extensions it declares (`piPackageExtensions`: `pi.extensions` resolved as Pi does, a file, a folder's index or each extension in it, a glob, `!` leaving one out) are listed as `Plugin.Extensions` and shown as its parts. magpie writes nothing for them: they reach Pi only through the package entry a project giving the plugin to Pi gets (`projectPiWanted`), and the plugin's own agents (user-wide) give Pi none of them (`TestPiExtensionOnlyPackageIsAPlugin`, `TestPiPackageExtensions`, `library-plugins.test.cjs`, `project-plugins.test.cjs`). A hook whose Claude event and matcher have a portable event becomes it (Stop turn-end, PostToolUse after-tool, PreToolUse before-tool, UserPromptSubmit prompt, SessionStart session-start; Bash is shell, Edit/Write/MultiEdit is edit); any other event is `claude:`, for Claude Code only. Subagents go to the agents in `SubagentAgents`. A part whose name the library has gets the prefix `-`: the user's own item is never written over or removed. Slash commands, LSP servers and hooks that aren't a command are listed in `Left` and shown, not carried. A plugin goes to another computer whole, by sync or a backup file (#6685, JJasonsun on Discord; [`plugin_carry.go`](../../internal/library/plugin_carry.go)): `Bundle.Plugins` carries each record (name, version, source, pick, agents, `Off`, and the parts taken out by hand), never its parts, which name this computer's folder. A plugin from a GitHub or git link goes as that source, and the other computer installs it from there as `UpdatePlugin` does, outside the library's lock; one it can't fetch yet is kept with `Pending`, its old parts if any, and a problem, the row says so, and Update or the next sync tries again. A plugin from a folder, or a link holding a sign-in (whose link isn't carried), goes with its files, on the skills' budget, and is installed from them. Either way that computer reads the parts again, so every hook, server and skill names its own `/plugins/`, Windows' too. A plugin the bundle no longer has is removed with its folder. A bundle from a magpie before this has no `plugins`, and this computer's plugins keep their parts over the same-named items it carries. A marketplace entry's own fields (`strict: false`) aren't carried, so a local marketplace plugin is read from its files alone there. A plugin installed from a marketplace under a name other than its manifest's names that folder in its parts too (`TestPluginCarriedWhole`, `TestPluginCarriedBySource`, `TestPluginOldBundleKeepsPlugins`, `TestPluginMarketplaceNameIsItsFolder`, davsync's `TestSyncLibraryPlugins`, `TestPluginImportCarryOnOffRemove`, `TestPluginHookReadsRootFromItsProgram`, `TestPluginHookWrittenBeforeIsResolved`, `TestPluginPartsGetItsFolders`, `TestPluginNameClashKeepsTheUsersOwn`, `TestPluginMarketplaceAndUpdate`, `TestPluginRefusesWhatIsNone`, `library-plugins.test.cjs`). | [`plugin.go`](../../internal/library/plugin.go), [`plugins/library/client.js`](../../internal/gui/assets/plugins/library/client.js) | +| Claude plugins | A `Plugin` (FakeshadowzZ on X) is a Claude Code plugin kept as one item: `.claude-plugin/plugin.json` (or Codex's `.codex-plugin/plugin.json`, #7255: its `skills`, `mcpServers` and `hooks` read the same way, Claude's fields winning where both name one; the hooks it names are Codex's own, kept as written as `codex:` and given to Codex alone, an event Codex has none called is left out; `plugin_codex_test.go`), `skills//SKILL.md`, `agents/*.md`, `hooks/hooks.json` and `.mcp.json`, from a folder, a git address or a marketplace.json (`ProbePlugins`, `InstallPlugins`; a marketplace entry with a relative path, or a github/url/git source, is fetched when installed). Its files are copied to `/plugins/`; `${CLAUDE_PLUGIN_ROOT}` is that folder and `${CLAUDE_PLUGIN_DATA}` is `/plugin-data/`, which an update keeps. No agent sets either variable outside Claude Code's plugin runtime, so every reference is resolved before a part is written out ([`plugin_env.go`](../../internal/library/plugin_env.go)): `${NAME}`/`$NAME` in a hook command, a server's command, args and env, a subagent's prompt and a copied SKILL.md become the folder; a hook program's own read (`process.env.NAME`, `Bun.env`, `Deno.env.get`, Python's `os.environ`/`os.getenv`, Ruby's `ENV`) becomes a quoted string literal of the folder with forward slashes, and PowerShell's `$env:NAME` and cmd's `%NAME%` the folder (ponytail's hooks threw at every start without it, @AXmake110 on X); a command server is given both variables in its env, as Claude Code gives them. Parts a magpie before this wrote with the variables in them are resolved at load (`healPluginRefs`) and written out again at the next sync; a SKILL.md copied before is fixed by Update or a reinstall. Exec-form hooks (`args`) and `CLAUDE_PLUGIN_OPTION_` are not carried yet (#6682). Its parts are ordinary library skills, MCP servers, hooks and subagents, each tagged `Bundle: `, so every agent gets them through the code of its kind and the old tabs go on working; the plugin holds the names, its agents and `Off`. `PluginAgents` sets every part's agents, `PluginOn` clears them (kept in `Agents` for turning it on again) or gives them back, `RemovePlugin` removes the parts (and takes the plugin out of every project), `ProjectPlugin` gives it to a project (see Projects), and `UpdatePlugin` reads the source again. A plugin at the top of a git or GitHub download is named after the repository (`rootName`: `file:///srv/acme-pi.git` is `acme-pi`), never after the download's temp folder (`magpie-skill-…`), and an update of a one-plugin source keeps the bundle's own name, so the folder, the projects that have it and the Pi entry they were given (`.pi/settings.json`'s `packages`) stay the same and load the new files; one named `magpie-skill-…` by a magpie before this keeps that name (#7269, jinpwng; `TestPiPackageFromGitUpdatesInPlace`, `TestPluginUpdateKeepsItsName`, `TestPluginRootName`). A Pi package (`package.json` with a `pi` object) is a plugin too, one with only extensions included (#7267, jinpwng): its package.json gives the name, description and version a plugin manifest doesn't, and the extensions it declares (`piPackageExtensions`: `pi.extensions` resolved as Pi does, a file, a folder's index or each extension in it, a glob, `!` leaving one out) are listed as `Plugin.Extensions` and shown as its parts. magpie writes nothing for them: they reach Pi only through the package entry a project giving the plugin to Pi gets (`projectPiWanted`), and the plugin's own agents (user-wide) give Pi none of them (`TestPiExtensionOnlyPackageIsAPlugin`, `TestPiPackageExtensions`, `library-plugins.test.cjs`, `project-plugins.test.cjs`). A hook whose Claude event and matcher have a portable event becomes it (Stop turn-end, PostToolUse after-tool, PreToolUse before-tool, UserPromptSubmit prompt, SessionStart session-start; Bash is shell, Edit/Write/MultiEdit is edit); any other event is `claude:`, for Claude Code only. Subagents go to the agents in `SubagentAgents`. A part whose name the library has gets the prefix `-`: the user's own item is never written over or removed. Slash commands, LSP servers and hooks that aren't a command are listed in `Left` and shown, not carried. A plugin goes to another computer whole, by sync or a backup file (#6685, JJasonsun on Discord; [`plugin_carry.go`](../../internal/library/plugin_carry.go)): `Bundle.Plugins` carries each record (name, version, source, pick, agents, `Off`, and the parts taken out by hand), never its parts, which name this computer's folder. A plugin from a GitHub or git link goes as that source, and the other computer installs it from there as `UpdatePlugin` does, outside the library's lock; one it can't fetch yet is kept with `Pending`, its old parts if any, and a problem, the row says so, and Update or the next sync tries again. A plugin from a folder, or a link holding a sign-in (whose link isn't carried), goes with its files, on the skills' budget, and is installed from them. Either way that computer reads the parts again, so every hook, server and skill names its own `/plugins/`, Windows' too. A plugin the bundle no longer has is removed with its folder. A bundle from a magpie before this has no `plugins`, and this computer's plugins keep their parts over the same-named items it carries. A marketplace entry's own fields (`strict: false`) aren't carried, so a local marketplace plugin is read from its files alone there. A plugin installed from a marketplace under a name other than its manifest's names that folder in its parts too (`TestPluginCarriedWhole`, `TestPluginCarriedBySource`, `TestPluginOldBundleKeepsPlugins`, `TestPluginMarketplaceNameIsItsFolder`, davsync's `TestSyncLibraryPlugins`, `TestPluginImportCarryOnOffRemove`, `TestPluginHookReadsRootFromItsProgram`, `TestPluginHookWrittenBeforeIsResolved`, `TestPluginPartsGetItsFolders`, `TestPluginNameClashKeepsTheUsersOwn`, `TestPluginMarketplaceAndUpdate`, `TestPluginRefusesWhatIsNone`, `library-plugins.test.cjs`). A part a plugin brought is tagged "In " on Skills, MCP, Hooks and Subagents (`withPlugin`). On Skills, Hooks and Subagents the tag is a button: the tab shows only that plugin's, under a bar naming it whose Show all brings the rest back (`bundleOnly`, per tab; nothing is written), and the skills' filter matches a skill's plugin too (jinpwng, #7280, `library-plugin-filter.test.cjs`). | [`plugin.go`](../../internal/library/plugin.go), [`plugins/library/client.js`](../../internal/gui/assets/plugins/library/client.js) | | 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. An rtk.exe in one of winget's folders that winget has no record of (`winget list` says so, or its records name another folder; netube99 on X, 0x8A150014) is upgraded from rtk's own Windows release over the file a `WinGet\Links` link points to, not by `winget upgrade`. `ReadRTK` reads each agent's files to say which have the hook. An agent gone for its CLI (`CLIMissing`, #2254) isn't offered rtk, but one that still has the hook is listed so it can be taken out. `rtkSpec.blocked` stops the installer where it would break an agent. `rtkSpec.env` tells the installer the agent's folder where rtk would pick another: Hermes Agent's is `appdir.HermesHome` (`%LOCALAPPDATA%\hermes` on Windows), which rtk is given as `HERMES_HOME`, since rtk 0.51 knows only `$HERMES_HOME` and `~/.hermes`. Antigravity CLI (`agy`, #2202) gets rtk 0.51's own plugin for Antigravity, `plugins/rtk` in its global customization folder `~/.gemini/config` (`plugin.json`, `hooks.json` with `PreToolUse` → `rtk hook antigravity`, `rules/AGENTS.md`), which `agy plugin list` lists; switching it off takes that one folder out. rtk 0.50 knows Antigravity only per project and fails `rtk init -g --agent antigravity`, so an older rtk is `blocked` (`agyBlocked`) and the row says to update RTK. OpenCode 2 loads only the plugin rtk 0.52 on writes (one default object with `id` and `setup()`, rtk-ai/rtk#4187); an older rtk's plugin is for OpenCode 1 and OpenCode 2 refuses it, so with an OpenCode 2 here an older rtk is `blocked` (`openCodeBlocked`) and the row says to update RTK (#2295). Under OpenCode 2, an old plugin left from before an rtk update counts as off once the rtk here can write the new one (`openCodeHas`), so switching it on writes the new one over it; with an older rtk it counts as on, so it can be switched off. Factory's Droid (lml0664 on Discord) gets rtk's own `rtk init -g --agent droid`, given Droid's folder as `FACTORY_HOME_OVERRIDE`; rtk puts its `Execute` group (`rtk hook droid`) in the root `hooks.json`, or in `settings.json`'s `hooks.PreToolUse` where Droid's hooks already are, so `droidHookFiles` reads and switches off all three places rtk 1.1.0 may use (`hooks.json`, `hooks/hooks.json`, `settings.json`), leaving the user's own hooks. rtk before 0.44 has no Droid agent, so it is `blocked` (`droidBlocked`). 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`; Grok Build and Grok App: `rtk init` has no Grok or Grok App agent, so both are listed with the switch off; Qoder and Qoder CN: rtk 1.1.0 has no Qoder agent; Cline and Kimi Code: `rtk init --agent cline|kimi` writes only one project's `.clinerules` or `AGENTS.md`, instructions with no hook, and Kimi's refuses `-g`). RTK 1.1.0's Trae, Windsurf, Kilo Code and Mistral Vibe have no magpie agent. The page's No RTK hook tag gives each agent's own reason and rtk-ai/rtk issue (`rtkNoHookWhy` in plugins/library/client.js: dsh #3847, Grok Build and Grok App #2136, Qoder and Qoder CN #1327, Cline #3841), and an agent with no entry gets no link; `TestRTKNoHookIssuesAreEachAgents` fails when the page and `rtkNoHook` cite different issues, or two agents cite the same ones without a reason in `sharedRTKIssues`. | [`rtk.go`](../../internal/library/rtk.go) | | RTK in WSL | An agent in a WSL distro (`claude@wsl:Ubuntu`) is listed by its kind (`rtkKind`), and its hook runs in the distro, where Windows' rtk.exe is no command, so it gets the distro's own rtk (lex on Discord). `rtkDistroOf` asks the distro with `wsl.exe -d -e sh -lc` where rtk is (a login or interactive shell's PATH; else `~/.local/bin` or `~/.cargo/bin`, `offPath`), kept 15s; `ReadRTK` lists one `RTKDistro` for each distro its agents are in. Install RTK in WSL `` (`InstallRTKIn`, `POST /api/library/rtk/install` with `distro`, `magpie library rtk install `) runs RTK's own Linux installer in the distro (`curl -fsSL …/install.sh \| sh`, wget where there's no curl). Switching an agent on runs the distro's rtk there (`rtkInstallWSL`: `rtk init -g …` with its folder on PATH, Claude Code pointed at a folder of its own for the OpenCode and Cursor installers), and reads and edits its files under the distro's home as magpie opens it (`rtkClaudeDir`, `rtkCodexDir`, `rtkHome`). A distro that isn't running is never started (#3896): `rtkWSLLive` and `rtkDistroOf` check `agent.WSLRunning` first, its agents are listed `asleep` with the switch off, and switching or installing says to start it (`TestRTKWSLAsleep`). The page gives each distro a card (`rtkDistroCard` in plugins/library/client.js; library-rtk-wsl.test.cjs). | [`rtk_wsl.go`](../../internal/library/rtk_wsl.go) | diff --git a/internal/gui/assets/plugins/library/client.js b/internal/gui/assets/plugins/library/client.js index 2370ee426..6dca0fddc 100644 --- a/internal/gui/assets/plugins/library/client.js +++ b/internal/gui/assets/plugins/library/client.js @@ -2897,11 +2897,36 @@ magpie.plugin("library", (ctx) => { } // a part a Claude plugin brought: its agents follow the plugin's when // those change (library/plugin.go givePlugin) - const withPlugin = (nm, x) => { - if (x.bundle) nm.append(tag(t("In {plugin}", { plugin: x.bundle }), "lib-bundle", - t("Comes with the Claude plugin {plugin}. Changing the plugin's agents, or turning it off and on, gives this to the plugin's agents again.", { plugin: x.bundle }))); + // On Skills, Hooks and Subagents (kind) the tag shows only what that + // plugin brought, the rest back with the bar's Show all (#7280, jinpwng) + const withPlugin = (nm, x, kind) => { + if (!x.bundle) return nm; + const b = tag(t("In {plugin}", { plugin: x.bundle }), "lib-bundle", + t("Comes with the Claude plugin {plugin}. Changing the plugin's agents, or turning it off and on, gives this to the plugin's agents again.", { plugin: x.bundle })); + if (kind) { + b.classList.add("link"); + b.dataset.bundle = x.bundle; + b.onclick = (e) => { e.stopPropagation(); bundleOnly[kind] = x.bundle; render(); }; + } + nm.append(b); return nm; }; + // what a tab shows of a plugin's, picked from its tag: nothing once the + // plugin brings none of the tab's items any more + const bundleOnly = {}; + const onlyBundle = (kind, items) => { + const b = bundleOnly[kind]; + if (b && !items.some((x) => x.bundle === b)) delete bundleOnly[kind]; + return bundleOnly[kind] ? items.filter((x) => x.bundle === bundleOnly[kind]) : items; + }; + function bundleBar(kind) { + const b = bundleOnly[kind]; + if (!b) return []; + const bar = el("div", "row-head lib-bundleonly"); + bar.append(el("span", "label", t("Only what {plugin} brings", { plugin: b })), el("span", "grow"), + button(t("Show all"), "lib-bundleall", () => { delete bundleOnly[kind]; render(); })); + return [bar]; + } // ---------- MCP servers ---------- @@ -4811,8 +4836,8 @@ magpie.plugin("library", (ctx) => { body.append(rh); } const list = el("div", "list lib-list"); - list.append(...[...hooks].sort((a, b) => a.name.localeCompare(b.name)).map((h) => hookRow(h, all))); - body.append(list); + list.append(...onlyBundle("hooks", [...hooks]).sort((a, b) => a.name.localeCompare(b.name)).map((h) => hookRow(h, all))); + body.append(...bundleBar("hooks"), list); if (picking) body.append(pickBar(all)); const after = el("div", "after-list"); after.append(button(t("+ Add hook"), "", () => editHook(null))); @@ -4839,7 +4864,7 @@ magpie.plugin("library", (ctx) => { function hookRow(h, all) { const row = el("div", "row lib-row click lib-hook"); const who = el("div", "who"); - who.append(withPlugin(el("div", "name mono", h.name), h)); + who.append(withPlugin(el("div", "name mono", h.name), h, "hooks")); // what it is for, in the user's own words (#2011) if (h.description) who.append(el("div", "lib-hookdesc", h.description)); who.append(el("div", "sub lib-hookev", hookLine(h))); @@ -5020,8 +5045,8 @@ magpie.plugin("library", (ctx) => { body.append(empty(t("No subagents in the library yet"), t("Add one, and pick the agents that can hand it a task."), button(t("+ Add a subagent"), "action", () => editSubagent(null)))); } else { const list = el("div", "list lib-list"); - list.append(...[...subs].sort((a, b) => a.name.localeCompare(b.name)).map((s) => subagentRow(s, all))); - body.append(list); + list.append(...onlyBundle("subagents", [...subs]).sort((a, b) => a.name.localeCompare(b.name)).map((s) => subagentRow(s, all))); + body.append(...bundleBar("subagents"), list); const after = el("div", "after-list"); after.append(button(t("+ Add subagent"), "", () => editSubagent(null))); body.append(after); @@ -5159,7 +5184,7 @@ magpie.plugin("library", (ctx) => { function subagentRow(s, all) { const row = el("div", "row lib-row click lib-subagent"); const who = el("div", "who"); - who.append(withPlugin(el("div", "name mono", s.name), s)); + who.append(withPlugin(el("div", "name mono", s.name), s, "subagents")); who.append(el("div", "lib-subagentdesc", s.description)); const line = subagentLine(s); if (line) who.append(el("div", "sub lib-subagentuses", line)); @@ -5953,7 +5978,8 @@ magpie.plugin("library", (ctx) => { null, many && [removeEveryButton("skills"), GLYPH.trash], ])); - body.append(rh); + onlyBundle("skills", lib.skills); + body.append(rh, ...bundleBar("skills")); drawSkills(box, all); body.append(box); // under the list, so the skills stay where they were above it @@ -6136,7 +6162,7 @@ magpie.plugin("library", (ctx) => { 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()])) }; + text: new Map(skills.map((s) => [s, (s.name + " " + (s.note || "") + " " + (s.description || "") + " " + (s.bundle || "") + " " + skillRepo(s)).toLowerCase()])) }; grouped[pick] = { lib, groups: [g] }; return grouped[pick].groups; } @@ -6184,7 +6210,7 @@ magpie.plugin("library", (ctx) => { ...mine.filter((g) => g.skills.length && mineHere(g)), ...down.sort(byRepo), ...(by.has("local") ? [by.get("local")] : [])]; for (const g of groups) { g.skills.sort((a, b) => a.name.localeCompare(b.name)); - 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.text = new Map(g.skills.map((s) => [s, (s.name + " " + (s.note || "") + " " + (s.description || "") + " " + (s.bundle || "") + " " + (g.mine || (g.owner ? skillRepo(s) : g.repo))).toLowerCase()])); g.parts = g.mine ? null : partsOf(g); } grouped[pick] = { lib, groups }; @@ -6281,7 +6307,12 @@ magpie.plugin("library", (ctx) => { // What a group shows: its skills the filter matches, and whether it's // folded. While filtering a group is open unless folded since the filter // changed; else as the user last left it, or folded when there are many. - const skillHits = (g, q) => (q ? g.skills.filter((s) => g.text.get(s).includes(q)) : g.skills); + // the filter matches a skill's plugin too (#7280), and a plugin's tag + // picked shows only what it brought + const skillHits = (g, q) => { + const b = bundleOnly.skills; + return q || b ? g.skills.filter((s) => (!b || s.bundle === b) && (!q || g.text.get(s).includes(q))) : g.skills; + }; const groupFolded = (g, q) => (q ? unfiltered.has(g.key) : folds[g.key] ?? lib.skills.length > MANY); // Collapse all / Expand all (#1862, WardLu): every group the list shows @@ -8371,7 +8402,7 @@ magpie.plugin("library", (ctx) => { function skillRow(s, all) { const row = el("div", "row lib-row click lib-skill" + (s.missing ? " missing" : "") + (s.source ? " src" : "") + (s.offHere ? " offhere" : "")); const who = el("div", "who"); - const nm = withPlugin(el("div", "name", s.name), s); + const nm = withPlugin(el("div", "name", s.name), s, "skills"); const c = s.check; const gone = isGone(s); if (gone) { diff --git a/internal/gui/assets/plugins/library/i18n.js b/internal/gui/assets/plugins/library/i18n.js index 706c8edac..029f2d49c 100644 --- a/internal/gui/assets/plugins/library/i18n.js +++ b/internal/gui/assets/plugins/library/i18n.js @@ -9,6 +9,7 @@ magpie.strings({ "Installed in the agents themselves": "Agent 自己安装的内容", "Listed as the agents' plugins and packages declare them. The agent loads them: magpie copies and changes nothing, and a session shows what is loaded.": "按 Agent 的插件和包所声明的内容列出。由 Agent 自己加载:magpie 不复制也不改动,会话中才能看到实际加载了什么。", "In {plugin}": "属于 {plugin}", + "Only what {plugin} brings": "只看 {plugin} 带来的", "Comes with the Claude plugin {plugin}. Changing the plugin's agents, or turning it off and on, gives this to the plugin's agents again.": "随 Claude 插件 {plugin} 安装。改动插件的 Agent,或把插件关掉再打开,会把它重新给到插件的 Agent。", "Put back in {agents}": "放回 {agents}", "Put {name} back?": "把 {name} 放回?", @@ -1168,6 +1169,7 @@ magpie.strings({ "Installed in the agents themselves": "Agent 自己安裝的內容", "Listed as the agents' plugins and packages declare them. The agent loads them: magpie copies and changes nothing, and a session shows what is loaded.": "依 Agent 的外掛與套件所宣告的內容列出。由 Agent 自己載入:magpie 不複製也不改動,工作階段中才看得到實際載入了什麼。", "In {plugin}": "屬於 {plugin}", + "Only what {plugin} brings": "只看 {plugin} 帶來的", "Comes with the Claude plugin {plugin}. Changing the plugin's agents, or turning it off and on, gives this to the plugin's agents again.": "隨 Claude 外掛 {plugin} 安裝。變更外掛的 Agent,或把外掛關閉再開啟,會把它重新給到外掛的 Agent。", "Put back in {agents}": "放回 {agents}", "Put {name} back?": "把 {name} 放回?", @@ -2327,6 +2329,7 @@ magpie.strings({ "Installed in the agents themselves": "エージェント自身がインストールしたもの", "Listed as the agents' plugins and packages declare them. The agent loads them: magpie copies and changes nothing, and a session shows what is loaded.": "エージェントのプラグインとパッケージが宣言する内容を一覧にしています。読み込むのはエージェント自身で、magpie はコピーも変更もしません。実際に読み込まれたものはセッションで分かります。", "In {plugin}": "{plugin} の一部", + "Only what {plugin} brings": "{plugin} に含まれるものだけ", "Comes with the Claude plugin {plugin}. Changing the plugin's agents, or turning it off and on, gives this to the plugin's agents again.": "Claude プラグイン {plugin} と一緒に入りました。プラグインのエージェントを変えるか、オフにしてオンに戻すと、プラグインのエージェントに改めて渡されます。", "Put back in {agents}": "{agents} に戻す", "Put {name} back?": "{name} を戻しますか?", @@ -3486,6 +3489,7 @@ magpie.strings({ "Installed in the agents themselves": "Von den Agents selbst installiert", "Listed as the agents' plugins and packages declare them. The agent loads them: magpie copies and changes nothing, and a session shows what is loaded.": "So aufgelistet, wie die Plugins und Pakete der Agents sie angeben. Der Agent lädt sie selbst: magpie kopiert und ändert nichts, und eine Sitzung zeigt, was geladen ist.", "In {plugin}": "Teil von {plugin}", + "Only what {plugin} brings": "Nur, was {plugin} mitbringt", "Comes with the Claude plugin {plugin}. Changing the plugin's agents, or turning it off and on, gives this to the plugin's agents again.": "Kommt mit dem Claude-Plugin {plugin}. Werden die Agenten des Plugins geändert oder wird es aus- und wieder eingeschaltet, geht dies erneut an die Agenten des Plugins.", "Put back in {agents}": "Zurück zu {agents}", "Put {name} back?": "{name} zurückgeben?", diff --git a/internal/gui/assets/plugins/library/library.css b/internal/gui/assets/plugins/library/library.css index a93a43169..b8e92024f 100644 --- a/internal/gui/assets/plugins/library/library.css +++ b/internal/gui/assets/plugins/library/library.css @@ -235,9 +235,14 @@ button.row.lib-hubfolded:hover { background: var(--pill); } .lib-tag.warn::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: currentColor; } /* what a check for updates found, beside a skill's name */ .lib-row .name .lib-tag { height: 17px; padding: 0 6px; margin-left: 7px; font-size: 10.5px; font-weight: 500; vertical-align: 1px; } +/* a tag that can be clicked wraps under a long name instead of being cut off + by its ellipsis, where a narrow window or a long translation needs it */ +.lib-row .name:has(> .lib-tag.link) { white-space: normal; text-overflow: clip; overflow-wrap: anywhere; } .lib-tag.lib-new { color: var(--accent); background: var(--accent-soft); } .lib-tag.lib-new::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: currentColor; } .lib-tag.lib-new.link { cursor: pointer; } +.lib-tag.lib-bundle.link { cursor: pointer; } +@media (hover: hover) and (pointer: fine) { .lib-tag.lib-bundle.link:hover { color: var(--fg); } } .lib-tag.lib-new.link:hover { background: color-mix(in srgb, var(--accent) 22%, var(--accent-soft)); } .lib-tag.lib-unchecked { color: var(--faint); font-weight: 400; } .lib-tag.lib-unchecked.link { cursor: pointer; } diff --git a/internal/gui/tests/library-plugin-filter.test.cjs b/internal/gui/tests/library-plugin-filter.test.cjs new file mode 100644 index 000000000..ee70e26a2 --- /dev/null +++ b/internal/gui/tests/library-plugin-filter.test.cjs @@ -0,0 +1,119 @@ +// Run with Node's test runner and Playwright on the module path; see README.md. +// #7280 (jinpwng): Skills, Hooks and Subagents show only what one plugin +// brought when its "In code-kit" tag is clicked, under a bar naming it; +// Show all brings the rest back, and nothing is given or taken from an +// agent on the way. The skills' filter matches the plugin's name too. +// Every language, both engines, at 420 and 1100. No backend: the API is +// faked, and any write to it fails the test. +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 { strings } = require("./strings.cjs"); + +const assets = path.resolve(__dirname, "../assets"); +const HOME = "/Users/chuan"; +const agent = (id, name) => ({ id, name, icon: "", skills: `${HOME}/.${id}/skills`, mcp: `${HOME}/.${id}/mcp.json` }); +const kit = { bundle: "code-kit" }; +const lib = () => ({ + dir: `${HOME}/.magpie/library`, backups: `${HOME}/.magpie/backups`, home: HOME, + agents: [agent("claude", "Claude Code"), agent("codex", "Codex")], + instructions: { agents: [] }, foundServers: [], projects: [], foundSkills: [], problems: [], + skills: [{ name: "code-kit-tdd", description: "Test first", kind: "", agents: ["claude"], ...kit }, { name: "own-skill", description: "Mine", kind: "", agents: ["claude"] }, + ...[1, 2, 3, 4, 5, 6, 7, 8].map((n) => ({ name: "own-skill-" + n, description: "Mine too", kind: "", agents: ["claude"] }))], + servers: [{ name: "code-kit-docs", transport: "stdio", command: "/bin/docs", agents: ["claude"], ...kit }, { name: "own-server", transport: "stdio", command: "/bin/own", agents: ["claude"] }], + hooks: [{ name: "code-kit-lint", event: "turn-end", command: "lint", agents: ["claude"], ...kit }, { name: "own-hook", event: "turn-end", command: "own", agents: ["claude"] }], + hookAgents: [{ id: "claude", events: ["turn-end"] }], + subagents: [{ name: "code-kit-reviewer", description: "Reviews", agents: ["claude"], ...kit }, { name: "own-agent", description: "Mine", agents: ["claude"] }], + subagentAgents: [{ id: "claude", dir: `${HOME}/.claude/agents` }], + plugins: [{ name: "code-kit", agents: ["claude"], skills: ["code-kit-tdd"], mcp: ["code-kit-docs"], hooks: ["code-kit-lint"], subagents: ["code-kit-reviewer"] }], +}); + +let I18N; +function tr(lang, key, vars = {}) { + let s = key; + if (lang !== "en") { + assert.equal(typeof I18N[lang][key], "string", `${lang} has no ${JSON.stringify(key)}`); + s = I18N[lang][key]; + } + return s.replace(/\{(\w+)\}/g, (m, k) => (k in vars ? String(vars[k]) : m)); +} + +function server(lang, writes) { + return async (route) => { + const url = new URL(route.request().url()); + if (route.request().method() !== "GET" && url.pathname.startsWith("/api/library")) writes.push(url.pathname); + 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(lib()); + if (url.pathname === "/api/plugins") return json({ plugins: [] }); + if (url.pathname === "/api/usage/quotas") return json([]); + 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({}); + 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 TABS = [["skills", ".lib-skill", "code-kit-tdd", "own-skill"], + ["hooks", ".lib-hook", "code-kit-lint", "own-hook"], ["subagents", ".lib-subagent", "code-kit-reviewer", "own-agent"]]; + +for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) { + test(engine + ": a plugin's tag shows only what it brought", async (t) => { + I18N = strings().I18N; + const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: process.env.PLAYWRIGHT_CHANNEL || "chromium" })); + t.after(() => browser.close()); + for (const lang of ["en", "zh", "zh-TW", "ja", "de"]) for (const width of [1100, 420]) for (const [tab, cls, part, own] of TABS) { + await t.test(`${lang} ${width} ${tab}`, async () => { + const ctx = await browser.newContext({ viewport: { width, height: 900 }, reducedMotion: "reduce" }); + t.after(() => ctx.close()); + await ctx.addInitScript((tab) => { try { localStorage.setItem("magpie.libTab", tab); } catch {} }, tab); + const page = await ctx.newPage(); + page.setDefaultTimeout(5000); + page.setDefaultNavigationTimeout(60000); + const errors = [], writes = []; + page.on("pageerror", (e) => errors.push(e.message)); + await page.route("**/*", server(lang, writes)); + await page.goto("http://magpie.test/"); + await page.locator('button[data-view="library"]').click(); + const v = page.locator("#view-library"); + const row = (name) => v.locator(cls).filter({ has: page.locator(".name", { hasText: new RegExp("^" + name + "(?!-)") }) }).first(); + const bar = v.locator(".lib-bundleonly"); + await row(part).waitFor(); + await row(own).waitFor(); + assert.equal(await bar.count(), 0); + + await row(part).locator(".lib-bundle").click(); + await bar.waitFor(); + assert.equal((await bar.locator(".label").textContent()).trim(), tr(lang, "Only what {plugin} brings", { plugin: "code-kit" })); + await row(own).waitFor({ state: "detached" }); + assert.equal(await v.locator(cls).count(), 1, "only the plugin's row is left"); + assert.equal(await row(part).count(), 1); + // the tag picks; it doesn't open the row's editor + assert.equal(await page.locator(".modal, .sheet, dialog[open]").filter({ visible: true }).count(), 0); + + await bar.locator(".lib-bundleall").click(); + await row(own).waitFor(); + assert.equal(await bar.count(), 0); + assert.equal(await row(part).count(), 1); + + if (tab === "skills") { + const q = v.locator(".lib-skillq"); + await q.fill("code-kit"); + await row(own).waitFor({ state: "detached" }); + assert.equal(await row(part).count(), 1, "the filter matches the plugin's name"); + await q.fill(""); + await row(own).waitFor(); + } + assert.deepEqual(writes, [], "a pick wrote to the library"); + assert.deepEqual(errors, []); + }); + } + }); +}