library: Claude Code's own plugins list their skills, hooks and subagents (#7266)
A plugin installed with `claude plugin install` showed nowhere in the
Library's Skills, Hooks or Subagents, and a project's whole-plugin choice
(Library > Projects, Claude Code plugins) named it with nothing of what it
brings (jinpwng, v0.1.4572). ReadNative had readers for Codex and Pi only.
- claudeNative reads Claude Code's installed_plugins.json (v2): every
record whose installPath is there, user scope as the user's, project and
local scope with their projectPath. Enabled comes from enabledPlugins in
the scope's own settings (settings.json, the project's
.claude/settings.json or settings.local.json); unknown stays unknown.
- Parts come from the plugin's .claude-plugin/plugin.json and Claude's
default places (skills/, hooks/hooks.json, .mcp.json, agents/*.md), the
manifest's own paths added; subagents are a new part kind, read with
the library's subagent reader, a .md with no front matter skipped.
- The GUI lists them read-only on Skills, MCP, Hooks and Subagents with
plugin id and scope (the project's folder for a project one), and a
project card's Claude Code plugin row says what the plugin brings.
magpie writes nothing: Claude Code keeps loading them.
- `magpie library native` names Claude Code too.
Run (mote): go test ./internal/library -run TestNative -count=1: ok.
node --test on 115 GUI files (every library-* and project-* file, plus
builtins, nav, sidebar, phone-no-sideways, i18n-keys and the other files
that reach these tabs), chromium and webkit: 2330 tests, 2320 ok, 10 red. library-open-again is red the same way alone on origin/main 7dc85f26e (#6751); project-pi, library-bili and billion-context were red only under the full run at load ~24 and pass alone.
Real Claude Code 2.1.327 in a sandbox HOME/CLAUDE_CONFIG_DIR: marketplace
add, plugin install at user and at project scope, plugin validate ok;
ReadNative on that record listed both, with their skill, hook and
subagent. Before this change the same record listed nothing for Claude.
Broken by hand: with claudeNative out of ReadNative,
TestNativeClaudePlugins is red; with nativeSection("subagent") and the
parts line out of client.js, library-native and project-claude-plugins
are red (28 fail).
Not tried: the reporter's own plugin.
This commit is contained in:
@@ -51,7 +51,7 @@ Pi's extensions and packages.
|
||||
| billion-context.json | The tab's Settings (@Luxzinw on X) change bili's own config, found by bili's `src/paths.ts`: `BILI_CONFIG_FILE`, else `$XDG_CONFIG_HOME` (or `~/.config`, `%USERPROFILE%\.config` on Windows) then `billion-context/billion-context.json` (`BiliConfigFile`). `ReadBiliSettings` reads it as JSONC; `SetBiliSettings` changes five of its `compress` keys and nothing else, through `edit.PatchJSON` (comments, BOM and every other key kept) and a temporary file renamed in: `nudgeGrowthTokens` (1000 to 10,000,000; empty takes it out, bili's 50000), `requireNudge` (off takes it out), `externalSummary` (`enabled` with `targets`, the picked one first, at most 16) and `prompts.compressPhilosophy` with `acknowledgePromptsRisk`, which bili needs before it reads a prompt override (under Advanced). `visibilityMarkers` (@JamesYu32 on X, under Advanced): bili's 📦/❌ lines after a compress, decompress or search_context call, on by default; off writes `false`, on takes the key out, and a provider's or model's own `compress.visibilityMarkers` is left as it is. bili turns off the whole compress section on one bad value, so magpie writes only values bili accepts and refuses a summary with no target. A model of magpie's is a recipe `providers.magpie` (`api: openai`, the gateway's `/v1`, `credentialRef: magpie`), its key the gateway's for the agent `billion-context` saved in bili's own credential store `<config>.summary-credentials.json` the way bili writes it (0600, an `O_EXCL` `.lock`, a temporary file renamed in); a user's own `providers.magpie` is never taken over. A file bili can't read is said so and left alone. After a change every running bili (`biliOrigins`, loopback only) is asked `POST /__bili/config/reload`; bili reloads routes and compress there, and the page says when none did. The file is carried in the library part (see [sync and backup](sync-backup.md)), the credential store never. `TestBiliConfigFileWhereBiliLooks`, `TestBiliSettingsChanged`, `TestBiliSettingsRefused`, `TestBiliMarkersSwitch`, `TestBiliKeyStoreKeptPrivate`, `TestBiliSettingsRoute`; the page is `biliSettings` (library-bili-settings.test.cjs). | [`bili_config.go`](../../internal/library/bili_config.go) |
|
||||
| Pi extensions | Each Pi here, this computer's and each WSL distro's (`piPlaces`), with the extensions and packages it loads, read by Pi's own rules (`@earendil-works/pi-coding-agent` 1.4: `resolveExtensionEntries`, `isEnabledByOverrides`, `applyPatterns`). An extension is a `.ts`/`.js` file or a folder (package.json `pi.extensions`, else `index.ts`, else `index.js`) in `<agentDir>/extensions`, or a path its settings.json `extensions` lists; a package is an entry of settings.json `packages`. Built-in extensions (`builtin:mcp` and the rest) aren't listed: `builtin:mcp` carries the MCP servers magpie gives Pi. `SetPiExtension` writes what `pi config` writes (`-path` off; the `-` taken out and `+path` only where still excluded, on); `SetPiPackage` sets a package's four filters to `[]` (off) or takes them out (on), and refuses an entry that already picks some parts (`filtered`, changed in `pi config`). `CopyPi` gives a package to another Pi as its settings.json entry, which Pi installs itself when it next starts (npm into `<agentDir>/npm`, git into `<agentDir>/git`), never as copied files; it refuses a local package, and one the other Pi has already by Pi's identity (npm name, git host/path). An extension is copied as its file or folder into the other's `extensions`, leaving out `node_modules`, `.git` and symlinks, never over one of the same name, and the page says to run `npm install` there when it has dependencies (leokon3 on Discord). A settings.json that can't be parsed lists nothing and is never written; a stopped distro is never started (`asleep`); every write is backed up first. `GET`/`POST /api/library/pi`, `POST /api/library/pi/copy`; the Library's Pi packages tab, shown while a Pi is here (`renderPi` in plugins/library/client.js; library-pi-extensions.test.cjs). | [`piext.go`](../../internal/library/piext.go) |
|
||||
| Pi market | `MarketPiPackages` lists npm's packages with the keyword `pi-package`, the way pi.dev's gallery finds them: the 500 most downloaded (two pages of npm's search, sorted by last month's downloads), cached 6h in memory and on disk, else the bundled `market_pi.json`; a search of two or more characters adds npm's own `keywords:pi-package <q>` search, and a search npm doesn't answer keeps the popular matches with a `SearchError` (the page says so). Every name is held to npm's rules (`piNameRe`), and a repository link is https only. `InstallPiPackage` runs `pi install npm:<name>` with `PI_CODING_AGENT_DIR` set to that Pi's folder (`piRun`), then checks settings.json lists it; `RemovePiPackage` runs `pi remove <source>`, which drops every entry of the same identity and uninstalls it. A Pi with no `pi` here (a WSL distro's, or this computer's with no CLI on PATH) gets the settings.json entry written, or taken out, instead, and Pi installs it when it next starts (`pending`). Both refuse an unreadable settings.json, install refuses a package the Pi has by Pi's identity, and each write is backed up first. `GET /api/library/market/pi`, `POST /api/library/pi/install`, `POST /api/library/pi/remove`; Discover under the Pi packages tab (`piCard`, `installPi`, `confirmRemovePi` in plugins/library/client.js; library-pi-market.test.cjs) marks a package every running Pi has Installed, and Install asks which Pi when several lack it (nineruiing on X). | [`pimarket.go`](../../internal/library/pimarket.go) |
|
||||
| Native inventory | `ReadNative` (`GET /api/library/native`, `magpie library native`; #7244, jinpwng) lists what the plugins Codex installed itself and the packages Pi installed itself declare, so the skills, MCP servers and hooks they bring are in the Library's tabs once, with their origin and scope. Read only: nothing is copied, linked or registered, the agent keeps loading them, and `Loaded` is always `unknown` because only a session shows it. Codex (`codexNative`, codex-rs `core-plugins` loader.rs): `plugins/cache/<marketplace>/<plugin>/<version>/.codex-plugin/plugin.json` (`.claude-plugin` and `.cursor-plugin` too); the version folder stands for the plugin, a `latest` copy only when alone; skills are the manifest's `skills` folders, else `skills/`; servers its `mcpServers` (a file or inline), else `.mcp.json`; hooks its `hooks` (files or inline objects, as chrome's), else `hooks/hooks.json`; every path stays inside the plugin (`inside`); `[plugins."p@m"] enabled` in config.toml is `Enabled`, unset is nil. Pi (`piNativePlugins`): each package in a Pi's settings.json that is on disk (`packageDir`, shared with `installed`), its skills from package.json `pi.skills` (with `!` drops matched against each skill's path) or `skills/` when it has no `pi` object, and the `.pi/settings.json` packages of the library's projects with scope `project` and `Enabled` unknown (Pi loads them only once it trusts the project). Neither agent has subagents in a plugin, and a Pi package declares no servers or hooks here, so only skills, servers and hooks are listed. Asked for when a tab is drawn, not part of the polled `/api/library`. | [`native.go`](../../internal/library/native.go) |
|
||||
| Native inventory | `ReadNative` (`GET /api/library/native`, `magpie library native`; #7244, jinpwng) lists what the plugins Codex installed itself and the packages Pi installed itself declare, so the skills, MCP servers and hooks they bring are in the Library's tabs once, with their origin and scope. Read only: nothing is copied, linked or registered, the agent keeps loading them, and `Loaded` is always `unknown` because only a session shows it. Codex (`codexNative`, codex-rs `core-plugins` loader.rs): `plugins/cache/<marketplace>/<plugin>/<version>/.codex-plugin/plugin.json` (`.claude-plugin` and `.cursor-plugin` too); the version folder stands for the plugin, a `latest` copy only when alone; skills are the manifest's `skills` folders, else `skills/`; servers its `mcpServers` (a file or inline), else `.mcp.json`; hooks its `hooks` (files or inline objects, as chrome's), else `hooks/hooks.json`; every path stays inside the plugin (`inside`); `[plugins."p@m"] enabled` in config.toml is `Enabled`, unset is nil. Pi (`piNativePlugins`): each package in a Pi's settings.json that is on disk (`packageDir`, shared with `installed`), its skills from package.json `pi.skills` (with `!` drops matched against each skill's path) or `skills/` when it has no `pi` object, and the `.pi/settings.json` packages of the library's projects with scope `project` and `Enabled` unknown (Pi loads them only once it trusts the project). Claude Code (`claudeNative`, #7266, jinpwng): each record of `plugins/installed_plugins.json` whose `installPath` is on disk, one for each scope (`user`, or `project`/`local` with its `projectPath`; a managed or unknown scope isn't listed), named by its `<plugin>@<marketplace>` id; its parts read as Claude Code reads a plugin, the manifest's paths added to the default `skills/`, `agents/`, `hooks/hooks.json` and `.mcp.json` rather than read instead (`manifestParts` with `also`), and its `agents` Markdown files with a description are `subagent` parts; `Enabled` is `enabledPlugins.<id>` in `settings.json` (user), the project's `.claude/settings.json` (project) or `.claude/settings.local.json` (local), unset nil. The Subagents tab lists them under its own, and a project's row for a Claude Code plugin (#7254's whole-plugin choice) says the parts it brings (`claudeNativeParts`). Codex has no subagents in a plugin, and a Pi package declares no servers or hooks here. Asked for when a tab is drawn (Skills, MCP, Hooks, Subagents, Plugins), not part of the polled `/api/library` (`TestNativeClaudePlugins`, `library-native.test.cjs`, `project-claude-plugins.test.cjs`). | [`native.go`](../../internal/library/native.go) |
|
||||
|
||||
## Runtime path
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ const libraryUsage = `magpie library what the library gives
|
||||
magpie library skill use-library <name> <agent> an agent's own skill by that name is in the way: set it aside, link the library's
|
||||
magpie library skill keep-own <name> <agent> …or keep the agent's, and take the agent off the library's
|
||||
magpie library project … a project folder's own skills (Library › Projects): magpie library project help
|
||||
magpie library native what plugins Codex and packages Pi installed themselves declare (read only; the agent loads them)
|
||||
magpie library native what plugins Codex and Claude Code and packages Pi installed themselves declare (read only; the agent loads them)
|
||||
magpie library rtk which agents run their shell commands through RTK (rtk-ai.app), to save tokens
|
||||
magpie library rtk on|off <agent> switch it (on with RTK's own installer; off works with RTK gone)
|
||||
magpie library rtk install install RTK (Homebrew, winget, or RTK's own script)
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
)
|
||||
|
||||
// libraryNativeCmd is magpie library native: what the plugins Codex and
|
||||
// the packages Pi installed themselves declare. It reads and writes
|
||||
// Claude Code (#7266) and the packages Pi installed themselves declare. It reads and writes
|
||||
// nothing; the agent loads them, and whether one is loaded in a session
|
||||
// isn't known from its files.
|
||||
func libraryNativeCmd(rest []string) error {
|
||||
@@ -16,7 +16,7 @@ func libraryNativeCmd(rest []string) error {
|
||||
}
|
||||
v := library.ReadNative()
|
||||
if len(v) == 0 {
|
||||
fmt.Println(muted.Render("no plugins or packages installed through Codex or Pi"))
|
||||
fmt.Println(muted.Render("no plugins or packages installed through Codex, Claude Code or Pi"))
|
||||
return nil
|
||||
}
|
||||
for _, p := range v {
|
||||
@@ -30,7 +30,7 @@ func libraryNativeCmd(rest []string) error {
|
||||
}
|
||||
fmt.Printf("%s %s %s (%s, %s)\n", p.AgentName, p.Name, p.Version, where, state)
|
||||
for _, x := range p.Parts {
|
||||
fmt.Printf(" %-5s %s", x.Kind, x.Name)
|
||||
fmt.Printf(" %-8s %s", x.Kind, x.Name)
|
||||
if x.Detail != "" && x.Kind != "skill" {
|
||||
fmt.Printf(" %s", x.Detail)
|
||||
}
|
||||
|
||||
@@ -992,7 +992,7 @@ magpie.plugin("library", (ctx) => {
|
||||
// Pi's extensions too: one installed or changed outside magpie since
|
||||
if (id === "pi" && piView) loadPi();
|
||||
// and the plugins and packages the agents installed themselves
|
||||
if (["skills", "mcp", "hooks"].includes(id) && nativeView) loadNative();
|
||||
if (NATIVE_TABS.includes(id) && nativeView) loadNative();
|
||||
// memory too: agents save to it while the page is open
|
||||
if (id === "memory" && mem) loadMemory();
|
||||
if (!lib) return page.querySelector(":scope > .lib-skel")?.replaceWith(skeleton(id));
|
||||
@@ -2209,6 +2209,9 @@ magpie.plugin("library", (ctx) => {
|
||||
// registers nothing, and whether a session loads one isn't known from
|
||||
// its files. Asked for when a tab that lists them is drawn, not part of
|
||||
// /api/library, which is polled.
|
||||
// Claude Code's own plugins too (#7266): their subagents on Subagents,
|
||||
// and their parts beside a project's whole-plugin choice on Plugins
|
||||
const NATIVE_TABS = ["skills", "mcp", "hooks", "subagents", "plugins"];
|
||||
let nativeView = null; // /api/library/native
|
||||
let nativeLoading = false;
|
||||
async function loadNative() {
|
||||
@@ -2223,7 +2226,16 @@ magpie.plugin("library", (ctx) => {
|
||||
// a list that can't be read is not drawn, never a wrong one
|
||||
}
|
||||
nativeLoading = false;
|
||||
if (nativeView && ["skills", "mcp", "hooks"].includes(tab)) render();
|
||||
if (nativeView && NATIVE_TABS.includes(tab)) render();
|
||||
}
|
||||
// a Claude Code plugin's parts, from any of its installed records, in
|
||||
// the words a library plugin's are said in
|
||||
function claudeNativeParts(id) {
|
||||
if (!nativeView) { if (!nativeLoading) loadNative(); return ""; }
|
||||
const p = nativeView.find((x) => x.agent === "claude" && x.name === id);
|
||||
if (!p) return "";
|
||||
const of = (kind) => (p.parts || []).filter((x) => x.kind === kind).map((x) => x.name);
|
||||
return pluginParts({ skills: of("skill"), mcp: of("mcp"), hooks: of("hook"), subagents: of("subagent") });
|
||||
}
|
||||
function nativeSection(kind) {
|
||||
if (agentless()) return [];
|
||||
@@ -2243,7 +2255,7 @@ magpie.plugin("library", (ctx) => {
|
||||
if (p.project) origin.append(pathLink(p.project));
|
||||
origin.title = p.source || "";
|
||||
who.append(origin);
|
||||
row.append(glyph(GLYPH[kind === "mcp" ? "web" : kind === "hook" ? "cmd" : "skill"]), who);
|
||||
row.append(glyph(GLYPH[{ mcp: "web", hook: "cmd", subagent: "subagent" }[kind] || "skill"]), who);
|
||||
if (p.enabled === false) row.append(tag(t("Off in {agent}", { agent: p.agentName }), "warn", t("{agent}'s own settings turn this plugin off", { agent: p.agentName })));
|
||||
rows.push(row);
|
||||
}
|
||||
@@ -5028,6 +5040,7 @@ magpie.plugin("library", (ctx) => {
|
||||
const skip = all.filter((a) => subagentAgentOf(a.id).no);
|
||||
if (skip.length) body.append(el("p", "lib-aside lib-subagents-no", t("magpie can't give subagents to {agents} yet: their chips are greyed, and say why.", { agents: skip.map((a) => a.name).join(", ") })));
|
||||
if (!agentless() && (subs.length || lib.projects.length)) renderProjects(body, "subagents");
|
||||
body.append(...nativeSection("subagent"));
|
||||
}
|
||||
|
||||
// subagents from a repository (CHENGJIAHEGOXIS on X): a link to one,
|
||||
@@ -7485,6 +7498,10 @@ magpie.plugin("library", (ctx) => {
|
||||
const row = el("div", "row lib-row lib-projskill lib-projplugin lib-projclaude");
|
||||
const w = el("div", "who");
|
||||
w.append(el("div", "name mono", c.id));
|
||||
// what it brings, as Claude Code's record of it declares (#7266):
|
||||
// read once the native list is in, and only listed, never written
|
||||
const n = claudeNativeParts(c.id);
|
||||
if (n) w.append(el("div", "sub lib-projclaude-parts", n));
|
||||
row.append(glyph(GLYPH.folder), w);
|
||||
const say = (next) => next.length
|
||||
? t("{item} is in {name} for {agents}", { item: c.id, name: p.name, agents: nameOf("claude") })
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
// Run with Node's test runner and Playwright on the module path; see README.md.
|
||||
// jinpwng (#7244): a plugin Codex installed from a marketplace and a package
|
||||
// Pi installed list their skills, MCP servers and hooks in the Library's own
|
||||
// tabs, once, with where they came from. Read only: nothing there to switch,
|
||||
// tabs, once, with where they came from. A plugin Claude Code installed
|
||||
// itself (#7266) too, its subagents on the Subagents tab. Read only: nothing there to switch,
|
||||
// copy or remove, and no row twice. In every language, both engines, at a
|
||||
// phone's width too. No backend: the API is faked here, with the shapes
|
||||
// the Go reader returns for Codex's real cache layout (chrome's inline
|
||||
@@ -16,7 +17,7 @@ const assets = path.resolve(__dirname, "../assets");
|
||||
const HOME = "/Users/me";
|
||||
const lib = () => ({
|
||||
dir: `${HOME}/.magpie/library`, backups: `${HOME}/.magpie/backups`, home: HOME,
|
||||
agents: [{ id: "codex", name: "Codex", icon: "", skills: `${HOME}/.codex/skills`, mcp: true, hooks: true }],
|
||||
agents: [{ id: "codex", name: "Codex", icon: "", skills: `${HOME}/.codex/skills`, mcp: true, hooks: true }, { id: "claude", name: "Claude Code", icon: "", skills: `${HOME}/.claude/skills`, mcp: true, hooks: true }],
|
||||
instructions: { agents: [], sets: [] }, foundServers: [], projects: [], foundSkills: [], skills: [], servers: [], hooks: [],
|
||||
});
|
||||
const native = [
|
||||
@@ -31,6 +32,14 @@ const native = [
|
||||
agent: "codex", agentName: "Codex", name: "codex-app-tools", version: "26.1029.61003", source: "openai-bundled", scope: "user", dir: `${HOME}/.codex/plugins/cache/openai-bundled/codex-app-tools/26.1029.61003`, loaded: "unknown",
|
||||
parts: [{ kind: "mcp", name: "codex_app", detail: "stdio" }],
|
||||
},
|
||||
{
|
||||
agent: "claude", agentName: "Claude Code", name: "fixture@fixmarket", version: "0.1.0", source: "fixmarket", scope: "project", project: `${HOME}/work/app`, dir: `${HOME}/.claude/plugins/cache/fixmarket/fixture/0.1.0`, enabled: true, loaded: "unknown",
|
||||
parts: [
|
||||
{ kind: "skill", name: "fix-skill", detail: "A fixture skill" },
|
||||
{ kind: "hook", name: "SessionStart", detail: "/usr/bin/true" },
|
||||
{ kind: "subagent", name: "fix-agent", detail: "A fixture agent" },
|
||||
],
|
||||
},
|
||||
{
|
||||
agent: "pi", agentName: "Pi", name: "proj-kit", version: "2.0.0", source: "npm:proj-kit", scope: "project", project: `${HOME}/work/app`, dir: `${HOME}/work/app/.pi/npm/node_modules/proj-kit`, loaded: "unknown",
|
||||
parts: [{ kind: "skill", name: "review", detail: "Review code" }],
|
||||
@@ -65,9 +74,10 @@ const words = {
|
||||
};
|
||||
// the tab, and the rows of its kind the fake lists
|
||||
const tabs = {
|
||||
skills: ["chrome", "review"],
|
||||
skills: ["chrome", "fix-skill", "review"],
|
||||
mcp: ["codex_app"],
|
||||
hooks: ["Stop"],
|
||||
hooks: ["Stop", "SessionStart"],
|
||||
subagents: ["fix-agent"],
|
||||
};
|
||||
|
||||
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
||||
@@ -97,11 +107,18 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
assert.equal(await v.locator(".lib-nativebox .label").textContent(), w.head);
|
||||
// each row says where it came from, once, with its scope
|
||||
const first = (await rows.first().textContent());
|
||||
assert(first.includes("Codex · " + (tab === "mcp" ? "codex-app-tools" : "chrome") + " 26.1029.61003"), first);
|
||||
if (tab === "subagents") {
|
||||
// Claude Code's, with its plugin id and scope, and its description
|
||||
assert(first.includes("Claude Code · fixture@fixmarket 0.1.0 · " + w.project), first);
|
||||
assert(first.includes("A fixture agent"), first);
|
||||
assert.equal(await rows.first().locator("svg").count(), 1);
|
||||
} else assert(first.includes("Codex · " + (tab === "mcp" ? "codex-app-tools" : "chrome") + " 26.1029.61003"), first);
|
||||
if (tab === "hooks") assert((await rows.nth(1).textContent()).includes("Claude Code · fixture@fixmarket 0.1.0"));
|
||||
if (tab === "skills") {
|
||||
assert(first.includes(w.user), first);
|
||||
assert((await rows.nth(1).textContent()).includes(w.project), await rows.nth(1).textContent());
|
||||
assert((await rows.nth(1).textContent()).includes("proj-kit 2.0.0"));
|
||||
assert((await rows.nth(1).textContent()).includes("Claude Code · fixture@fixmarket 0.1.0 · " + w.project), await rows.nth(1).textContent());
|
||||
assert((await rows.nth(2).textContent()).includes(w.project), await rows.nth(2).textContent());
|
||||
assert((await rows.nth(2).textContent()).includes("proj-kit 2.0.0"));
|
||||
// chrome's own settings turn it off
|
||||
assert.equal(await rows.first().locator(".lib-tag").textContent(), w.off);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
// Run with Node's test runner and Playwright on the module path; see README.md.
|
||||
// (#7254, jinpwng on X) A project's Claude plugins tab lists the plugins
|
||||
// Claude Code has installed itself, each with one Claude chip that posts to
|
||||
// projects/claude-plugin; no chip left takes it out. In English and Chinese.
|
||||
// projects/claude-plugin; no chip left takes it out. Each row says what the
|
||||
// plugin brings, as Claude Code's own record declares it (#7266), from
|
||||
// /api/library/native. In English and Chinese.
|
||||
// No backend: the API is faked here.
|
||||
const assert = require("node:assert/strict");
|
||||
const fs = require("node:fs/promises");
|
||||
@@ -27,6 +29,16 @@ const lib = (given) => ({
|
||||
projects: [{ dir: DIR, name: "app", copy: false, skills: {}, placed: [], servers: {}, subagents: {}, plugins: {}, claudePlugins: given, wrote: {} }],
|
||||
});
|
||||
|
||||
// fmt@acme as ReadNative lists Claude Code's user install of it
|
||||
const NATIVE = [{
|
||||
agent: "claude", agentName: "Claude Code", name: "fmt@acme", version: "0.1.0", source: "acme", scope: "user", dir: `${HOME}/.claude/plugins/cache/acme/fmt/0.1.0`, enabled: true, loaded: "unknown",
|
||||
parts: [
|
||||
{ kind: "skill", name: "fix-skill", detail: "A fixture skill" },
|
||||
{ kind: "hook", name: "SessionStart", detail: "/usr/bin/true" },
|
||||
{ kind: "subagent", name: "fix-agent", detail: "A fixture agent" },
|
||||
],
|
||||
}];
|
||||
|
||||
function server(lang, posts) {
|
||||
let given = [];
|
||||
return async (route) => {
|
||||
@@ -43,6 +55,7 @@ function server(lang, posts) {
|
||||
if (b.agents.length) given.push(b.name);
|
||||
return route.fulfill({ json: { ...lib(given), result: { changed: [], problems: [] } } });
|
||||
}
|
||||
if (url.pathname === "/api/library/native") return route.fulfill({ json: NATIVE });
|
||||
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: [] } });
|
||||
@@ -82,8 +95,8 @@ const chip = async (page, loc) => {
|
||||
|
||||
|
||||
const words = {
|
||||
en: { on: "fmt@acme is in app for Claude Code", out: "fmt@acme is out of app", note: "The plugins above are Claude Code's own, turned on for this project in .claude/settings.local.json. They stay installed through Claude Code." },
|
||||
zh: { on: "fmt@acme 已在 app 中对 Claude Code 开启", out: "fmt@acme 已从 app 中移除", note: "上面的插件是 Claude Code 自带的,在 .claude/settings.local.json 里只为这个项目启用,仍由 Claude Code 安装。" },
|
||||
en: { parts: "Skills: fix-skill · Hooks: SessionStart · Subagents: fix-agent", on: "fmt@acme is in app for Claude Code", out: "fmt@acme is out of app", note: "The plugins above are Claude Code's own, turned on for this project in .claude/settings.local.json. They stay installed through Claude Code." },
|
||||
zh: { parts: "技能:fix-skill · Hooks:SessionStart · 子代理:fix-agent", on: "fmt@acme 已在 app 中对 Claude Code 开启", out: "fmt@acme 已从 app 中移除", note: "上面的插件是 Claude Code 自带的,在 .claude/settings.local.json 里只为这个项目启用,仍由 Claude Code 安装。" },
|
||||
};
|
||||
|
||||
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
||||
@@ -115,6 +128,10 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
assert.deepEqual(await rows.first().locator(".lib-ag").evaluateAll((cs) => cs.map((c) => c.dataset.agent)), ["claude"]);
|
||||
assert.equal((await card.locator(".lib-projclaude-note").textContent()).trim(), w.note);
|
||||
const row = () => card.locator(".lib-projclaude").filter({ hasText: "fmt@acme" });
|
||||
// its parts, once the native list is in; lint@acme isn't in it and says none
|
||||
await page.waitForFunction(() => document.querySelector("#view-library .lib-projclaude-parts"));
|
||||
assert.equal(await row().locator(".lib-projclaude-parts").textContent(), w.parts);
|
||||
assert.equal(await card.locator(".lib-projclaude").filter({ hasText: "lint@acme" }).locator(".lib-projclaude-parts").count(), 0);
|
||||
await chip(page, row().locator('.lib-ag[data-agent="claude"]'));
|
||||
await page.waitForFunction(() => document.querySelectorAll('#view-library .lib-projclaude .lib-ag.on').length === 1);
|
||||
await page.waitForFunction((s) => document.querySelector("#status").textContent.trim() === s, w.on);
|
||||
|
||||
+149
-6
@@ -3,6 +3,7 @@ package library
|
||||
import (
|
||||
"encoding/json"
|
||||
"io/fs"
|
||||
"maps"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
@@ -10,6 +11,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/pelletier/go-toml/v2"
|
||||
"github.com/tidwall/gjson"
|
||||
)
|
||||
|
||||
// What the agents' own plugins and packages declare (jinpwng, #7244). A
|
||||
@@ -40,10 +42,22 @@ import (
|
||||
// has no "pi" object; Pi has no MCP servers, hooks or subagents of a
|
||||
// package's. A project's packages load only once Pi trusts the project, so
|
||||
// they are listed with Enabled unknown.
|
||||
//
|
||||
// Claude Code (#7266, jinpwng), under its config folder:
|
||||
//
|
||||
// plugins/installed_plugins.json {"version": 2, "plugins": {"<plugin>@<marketplace>":
|
||||
// [{"scope": "user"|"project"|"local", "installPath", "version", "projectPath"}]}}
|
||||
// settings.json enabledPlugins (user scope)
|
||||
// <project>/.claude/settings.json, settings.local.json enabledPlugins (project, local)
|
||||
//
|
||||
// One record for each scope an id is installed in. The parts are read from
|
||||
// installPath as Claude Code reads a plugin: what plugin.json names is
|
||||
// added to the default folders (skills/, agents/, hooks/hooks.json,
|
||||
// .mcp.json), not read instead of them. Subagents are agents/*.md.
|
||||
|
||||
// NativePart is one thing a native plugin or package declares.
|
||||
type NativePart struct {
|
||||
// Kind is skill, mcp or hook
|
||||
// Kind is skill, mcp, hook or subagent
|
||||
Kind string `json:"kind"`
|
||||
Name string `json:"name"`
|
||||
// Detail is a skill's description, a server's transport, a hook's
|
||||
@@ -79,6 +93,7 @@ const nativePartsMax = 500
|
||||
// writes nothing and starts nothing.
|
||||
func ReadNative() []NativePlugin {
|
||||
out := codexNative()
|
||||
out = append(out, claudeNative()...)
|
||||
out = append(out, piNativePlugins()...)
|
||||
if out == nil {
|
||||
out = []NativePlugin{}
|
||||
@@ -180,11 +195,18 @@ func codexVersion(dir string) (string, map[string]any) {
|
||||
}
|
||||
|
||||
func codexParts(root string, man map[string]any) []NativePart {
|
||||
return manifestParts(root, man, false)
|
||||
}
|
||||
|
||||
// manifestParts are the parts a plugin's manifest declares. Codex reads
|
||||
// the default files only when the manifest names none; Claude Code reads
|
||||
// them too (also).
|
||||
func manifestParts(root string, man map[string]any, also bool) []NativePart {
|
||||
var parts []NativePart
|
||||
// skills
|
||||
roots := pathsOf(man["skills"])
|
||||
if len(roots) == 0 {
|
||||
roots = []string{"skills"}
|
||||
if len(roots) == 0 || also {
|
||||
roots = append([]string{"skills"}, roots...)
|
||||
}
|
||||
for _, r := range roots {
|
||||
if d, ok := inside(root, r); ok && isDir(d) {
|
||||
@@ -193,18 +215,23 @@ func codexParts(root string, man map[string]any) []NativePart {
|
||||
}
|
||||
// MCP servers: a file or the servers inline, else .mcp.json
|
||||
var docs []map[string]any
|
||||
named := true
|
||||
switch v := man["mcpServers"].(type) {
|
||||
case string:
|
||||
docs = nativeJSONFiles(root, []string{v})
|
||||
case map[string]any:
|
||||
docs = []map[string]any{v}
|
||||
default:
|
||||
docs = nativeJSONFiles(root, []string{".mcp.json"})
|
||||
named = false
|
||||
}
|
||||
if !named || also {
|
||||
docs = append(docs, nativeJSONFiles(root, []string{".mcp.json"})...)
|
||||
}
|
||||
for _, d := range docs {
|
||||
parts = append(parts, nativeServers(d)...)
|
||||
}
|
||||
// hooks: files or inline objects, else hooks/hooks.json
|
||||
named = true
|
||||
switch v := man["hooks"].(type) {
|
||||
case string:
|
||||
docs = nativeJSONFiles(root, []string{v})
|
||||
@@ -223,14 +250,130 @@ func codexParts(root string, man map[string]any) []NativePart {
|
||||
}
|
||||
docs = append(docs, nativeJSONFiles(root, files)...)
|
||||
default:
|
||||
docs = nativeJSONFiles(root, []string{"hooks/hooks.json"})
|
||||
docs, named = nil, false
|
||||
}
|
||||
if !named || also {
|
||||
docs = append(docs, nativeJSONFiles(root, []string{"hooks/hooks.json"})...)
|
||||
}
|
||||
for _, d := range docs {
|
||||
parts = append(parts, nativeHooks(d)...)
|
||||
}
|
||||
if also {
|
||||
parts = append(parts, nativeSubagents(root, man)...)
|
||||
}
|
||||
return nativeUnique(parts)
|
||||
}
|
||||
|
||||
// nativeSubagents are a Claude Code plugin's agents/*.md and the files or
|
||||
// folders its manifest's "agents" names: each Markdown file with a
|
||||
// description in its front matter is one.
|
||||
func nativeSubagents(root string, man map[string]any) []NativePart {
|
||||
var files []string
|
||||
for _, rel := range append([]string{"agents"}, pathsOf(man["agents"])...) {
|
||||
d, ok := inside(root, rel)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
if fi, err := os.Stat(d); err == nil && !fi.IsDir() {
|
||||
files = append(files, d)
|
||||
} else if es, err := os.ReadDir(d); err == nil {
|
||||
for _, e := range es {
|
||||
if !e.IsDir() && strings.HasSuffix(strings.ToLower(e.Name()), ".md") {
|
||||
files = append(files, filepath.Join(d, e.Name()))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
slices.Sort(files)
|
||||
var out []NativePart
|
||||
for _, f := range slices.Compact(files) {
|
||||
s, _ := readSubagentAt(f)
|
||||
if s == nil {
|
||||
continue
|
||||
}
|
||||
name := s.Name
|
||||
if name == "" {
|
||||
name = strings.TrimSuffix(filepath.Base(f), filepath.Ext(f))
|
||||
}
|
||||
out = append(out, NativePart{Kind: "subagent", Name: name, Detail: s.Description})
|
||||
}
|
||||
sort.SliceStable(out, func(i, j int) bool { return out[i].Name < out[j].Name })
|
||||
return out
|
||||
}
|
||||
|
||||
// ---- Claude Code ------------------------------------------------------------
|
||||
|
||||
func claudeNative() []NativePlugin {
|
||||
raw, err := readClaudeJSON(claudeInstalled())
|
||||
if err != nil || raw == nil {
|
||||
return nil
|
||||
}
|
||||
var doc struct {
|
||||
Plugins map[string][]struct {
|
||||
Scope string `json:"scope"`
|
||||
InstallPath string `json:"installPath"`
|
||||
Version string `json:"version"`
|
||||
ProjectPath string `json:"projectPath"`
|
||||
} `json:"plugins"`
|
||||
}
|
||||
if json.Unmarshal(raw, &doc) != nil {
|
||||
return nil
|
||||
}
|
||||
settings := map[string][]byte{}
|
||||
enabled := func(file, id string) *bool {
|
||||
b, ok := settings[file]
|
||||
if !ok {
|
||||
b, _ = readClaudeJSON(file)
|
||||
settings[file] = b
|
||||
}
|
||||
v := gjson.GetBytes(b, "enabledPlugins."+gjson.Escape(id))
|
||||
if !v.IsBool() {
|
||||
return nil
|
||||
}
|
||||
on := v.Bool()
|
||||
return &on
|
||||
}
|
||||
var out []NativePlugin
|
||||
for _, id := range slices.Sorted(maps.Keys(doc.Plugins)) {
|
||||
name, market, ok := strings.Cut(id, "@")
|
||||
if !ok || name == "" {
|
||||
continue
|
||||
}
|
||||
for _, e := range doc.Plugins[id] {
|
||||
if e.InstallPath == "" || !isDir(e.InstallPath) {
|
||||
continue
|
||||
}
|
||||
man, _ := readJSONFile(filepath.Join(e.InstallPath, ".claude-plugin", "plugin.json"))
|
||||
p := NativePlugin{Agent: "claude", AgentName: "Claude Code", Name: id, Version: e.Version,
|
||||
Source: market, Scope: "user", Dir: e.InstallPath, Loaded: "unknown"}
|
||||
if p.Version == "" {
|
||||
p.Version = plStr(man["version"])
|
||||
}
|
||||
switch e.Scope {
|
||||
case "user", "":
|
||||
p.Enabled = enabled(claudeSettings(), id)
|
||||
case "project", "local":
|
||||
if e.ProjectPath == "" {
|
||||
continue
|
||||
}
|
||||
p.Scope, p.Project = "project", e.ProjectPath
|
||||
file := "settings.json"
|
||||
if e.Scope == "local" {
|
||||
file = "settings.local.json"
|
||||
}
|
||||
p.Enabled = enabled(filepath.Join(e.ProjectPath, ".claude", file), id)
|
||||
default:
|
||||
// managed, or a scope this magpie doesn't know: not listed
|
||||
// as one the user or a project chose
|
||||
continue
|
||||
}
|
||||
p.Parts = manifestParts(e.InstallPath, man, true)
|
||||
out = append(out, p)
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// nativeJSONFiles reads the files a manifest names inside the plugin's
|
||||
// folder: one that leaves it, or can't be read as an object, is skipped.
|
||||
func nativeJSONFiles(root string, names []string) []map[string]any {
|
||||
@@ -357,7 +500,7 @@ func nativeUnique(parts []NativePart) []NativePart {
|
||||
seen[p] = true
|
||||
out = append(out, p)
|
||||
}
|
||||
kinds := map[string]int{"skill": 0, "mcp": 1, "hook": 2}
|
||||
kinds := map[string]int{"skill": 0, "mcp": 1, "hook": 2, "subagent": 3}
|
||||
sort.SliceStable(out, func(i, j int) bool { return kinds[out[i].Kind] < kinds[out[j].Kind] })
|
||||
return out
|
||||
}
|
||||
|
||||
@@ -267,3 +267,78 @@ func TestNativeNothingIsEmptyList(t *testing.T) {
|
||||
t.Errorf("%#v", v)
|
||||
}
|
||||
}
|
||||
|
||||
// A plugin Claude Code installed itself (`claude plugin install`, #7266)
|
||||
// is listed for each scope installed_plugins.json records, named by its
|
||||
// id, with the skills, hooks and subagents its manifest adds to the
|
||||
// default folders, and whether that scope's settings turn it on. The
|
||||
// record is the shape Claude Code 2.1.327 wrote for a user and a project
|
||||
// install of one fixture plugin; nothing is written.
|
||||
func TestNativeClaudePlugins(t *testing.T) {
|
||||
home := sandbox(t)
|
||||
cc := filepath.Join(home, ".claude")
|
||||
inst := filepath.Join(cc, "plugins", "cache", "fixmarket", "fixture", "0.1.0")
|
||||
proj := t.TempDir()
|
||||
write(t, filepath.Join(cc, "plugins", "installed_plugins.json"), `{
|
||||
"version": 2,
|
||||
"plugins": {
|
||||
"fixture@fixmarket": [
|
||||
{"scope": "user", "installPath": "`+inst+`", "version": "0.1.0", "installedAt": "2026-11-20T02:39:31.789Z"},
|
||||
{"scope": "project", "installPath": "`+inst+`", "version": "0.1.0", "projectPath": "`+proj+`"}
|
||||
],
|
||||
"gone@fixmarket": [{"scope": "user", "installPath": "`+filepath.Join(cc, "nowhere")+`", "version": "1.0.0"}]
|
||||
}
|
||||
}`)
|
||||
write(t, filepath.Join(cc, "settings.json"), `{"enabledPlugins": {"fixture@fixmarket": true}}`)
|
||||
write(t, filepath.Join(proj, ".claude", "settings.json"), `{"enabledPlugins": {"fixture@fixmarket": false}}`)
|
||||
write(t, filepath.Join(inst, ".claude-plugin", "plugin.json"), `{"name": "fixture", "version": "0.1.0",
|
||||
"skills": "./extra/", "agents": ["./more/fix-agent.md"],
|
||||
"hooks": {"hooks": {"SessionStart": [{"hooks": [{"type": "command", "command": "/usr/bin/true"}]}]}}}`)
|
||||
write(t, filepath.Join(inst, "skills", "fix-skill", "SKILL.md"), "---\nname: fix-skill\ndescription: A fixture skill\n---\n")
|
||||
write(t, filepath.Join(inst, "extra", "more-skill", "SKILL.md"), "---\nname: more-skill\ndescription: Another\n---\n")
|
||||
write(t, filepath.Join(inst, "more", "fix-agent.md"), "---\nname: fix-agent\ndescription: A fixture agent\n---\nYou review.\n")
|
||||
write(t, filepath.Join(inst, "agents", "plain.md"), "---\nname: plain\ndescription: Default folder\n---\nHi.\n")
|
||||
write(t, filepath.Join(inst, "agents", "notes.md"), "no front matter\n")
|
||||
write(t, filepath.Join(inst, "hooks", "hooks.json"), `{"hooks": {"Stop": [{"matcher": "", "hooks": [{"type": "command", "command": "echo done"}]}]}}`)
|
||||
write(t, filepath.Join(inst, ".mcp.json"), `{"mcpServers": {"fixdb": {"url": "https://x.example/mcp"}}}`)
|
||||
before := dirDump(t, cc)
|
||||
|
||||
var got []NativePlugin
|
||||
for _, p := range ReadNative() {
|
||||
if p.Agent == "claude" {
|
||||
got = append(got, p)
|
||||
}
|
||||
}
|
||||
if len(got) != 2 {
|
||||
t.Fatalf("want the user and the project record, got %+v", got)
|
||||
}
|
||||
user, pr := got[0], got[1]
|
||||
if user.Name != "fixture@fixmarket" || user.Scope != "user" || user.Project != "" || user.Version != "0.1.0" ||
|
||||
user.Source != "fixmarket" || user.AgentName != "Claude Code" || user.Loaded != "unknown" || user.Enabled == nil || !*user.Enabled {
|
||||
t.Errorf("user: %+v", user)
|
||||
}
|
||||
if pr.Scope != "project" || pr.Project != proj || pr.Enabled == nil || *pr.Enabled {
|
||||
t.Errorf("project (its settings.json turns it off): %+v", pr)
|
||||
}
|
||||
names := func(kind string) (out []string) {
|
||||
for _, x := range partsOf(user, kind) {
|
||||
out = append(out, x.Name+"="+x.Detail)
|
||||
}
|
||||
return
|
||||
}
|
||||
if s := strings.Join(names("skill"), ","); s != "fix-skill=A fixture skill,more-skill=Another" {
|
||||
t.Errorf("skills (skills/ and the manifest's): %s", s)
|
||||
}
|
||||
if s := strings.Join(names("subagent"), ","); s != "fix-agent=A fixture agent,plain=Default folder" {
|
||||
t.Errorf("subagents (agents/ and the manifest's): %s", s)
|
||||
}
|
||||
if s := strings.Join(names("hook"), ","); s != "SessionStart=/usr/bin/true,Stop=echo done" {
|
||||
t.Errorf("hooks (inline and hooks/hooks.json): %s", s)
|
||||
}
|
||||
if s := strings.Join(names("mcp"), ","); s != "fixdb=http" {
|
||||
t.Errorf("servers: %s", s)
|
||||
}
|
||||
if after := dirDump(t, cc); after != before {
|
||||
t.Errorf("reading changed Claude's folder")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user