library: an extension-only Pi package is a plugin (#7267)
Library -> Claude plugins -> Look for plugins refused a Pi package whose
package.json declares only pi.extensions ("no plugin"), so a project
couldn't be given it for Pi, while one with a skill imported (jinpwng,
v0.1.4572, Pi 1.5.2).
- readPlugin takes a folder with a Pi package.json, and its name,
description and version fill what no plugin manifest gives.
- piPackageExtensions resolves pi.extensions as Pi does (a file, a
folder's index.ts/index.js or each extension in it, a glob, "!" leaving
one out, nothing outside the package). They count as parts, are kept as
Plugin.Extensions, and are shown in the probe, the plugin's row and
dialog, and the project card ("Pi extensions", in zh, zh-TW, ja, de).
- magpie writes nothing for an extension: a project giving the plugin to Pi
gets the one package entry (#7243's projectPiWanted) and Pi loads it.
The plugin's user-wide agents give Pi none of it.
Run (mote): go vet ./internal/library; go test ./internal/library
-count=1 -timeout 45m: ok (177s). node --test library-plugins,
project-plugins, i18n-keys, project-pi, library-plugin-parts (chromium
and webkit, en/zh/zh-TW/ja/de, 420 and 1100): 110 pass, 0 fail.
Real Pi: a throwaway test installed the issue's package (extension
registering a command and a no-op session_start) from a folder through
ProbePlugins/InstallPlugins, gave it to a project for Pi, and Pi 1.5.2
--mode rpc --offline --approve listed its command in get_commands.
Broken by hand: with readPlugin's extensions taken out,
TestPiExtensionOnlyPackageIsAPlugin is red (Extensions:0, then no parts to
install). i18n-keys caught "Pi extensions" in a Go error; it says
"extensions for Pi" there.
Not tried: the reporter's own package.
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -5693,6 +5693,7 @@ magpie.plugin("library", (ctx) => {
|
||||
p.mcp?.length ? t("MCP servers: {names}", { names: p.mcp.join(", ") }) : "",
|
||||
p.hooks?.length ? t("Hooks: {names}", { names: p.hooks.join(", ") }) : "",
|
||||
p.subagents?.length ? t("Subagents: {names}", { names: p.subagents.join(", ") }) : "",
|
||||
p.extensions?.length ? t("Pi extensions: {names}", { names: p.extensions.join(", ") }) : "",
|
||||
].filter(Boolean).join(" · ");
|
||||
|
||||
function renderPlugins(body) {
|
||||
@@ -5763,7 +5764,7 @@ magpie.plugin("library", (ctx) => {
|
||||
w.append(el("span", "name", x.name), el("span", "sub", x.description || ""));
|
||||
const count = (n) => (n ? [String(n)] : []);
|
||||
const parts = x.remote ? t("Fetched from its own repository when installed")
|
||||
: pluginParts({ skills: count(x.skills), mcp: count(x.mcp), hooks: count(x.hooks), subagents: count(x.subagents) });
|
||||
: pluginParts({ skills: count(x.skills), mcp: count(x.mcp), hooks: count(x.hooks), subagents: count(x.subagents), extensions: count(x.extensions) });
|
||||
if (parts) w.append(el("span", "sub lib-plparts", parts));
|
||||
r.append(cb, w);
|
||||
if (x.have) r.append(tag(t("in the library"), ""));
|
||||
@@ -5797,7 +5798,7 @@ magpie.plugin("library", (ctx) => {
|
||||
if (p.description) who.append(el("div", "lib-subagentdesc", p.description));
|
||||
// counts, not every name: PStack has a hundred (jinpwng on X); the
|
||||
// names are in the dialog, folded
|
||||
const line = [[t("Skills"), p.skills], [t("MCP servers"), p.mcp], [t("Hooks"), p.hooks], [t("Subagents"), p.subagents]]
|
||||
const line = [[t("Skills"), p.skills], [t("MCP servers"), p.mcp], [t("Hooks"), p.hooks], [t("Subagents"), p.subagents], [t("Pi extensions"), p.extensions]]
|
||||
.filter(([, v]) => v?.length).map(([k, v]) => k + " " + v.length).join(" · ");
|
||||
if (line) who.append(el("div", "sub lib-plparts", line));
|
||||
// synced in from another computer, its source not reached here yet
|
||||
@@ -5817,7 +5818,7 @@ magpie.plugin("library", (ctx) => {
|
||||
head.append(glyph(GLYPH.folder), el("b", "", p.name));
|
||||
ed.append(head);
|
||||
if (p.description) ed.append(el("p", "lib-subagentdesc", p.description));
|
||||
const rows = [[t("Skills"), p.skills], [t("MCP servers"), p.mcp], [t("Hooks"), p.hooks], [t("Subagents"), p.subagents]].filter(([, v]) => v?.length);
|
||||
const rows = [[t("Skills"), p.skills], [t("MCP servers"), p.mcp], [t("Hooks"), p.hooks], [t("Subagents"), p.subagents], [t("Pi extensions"), p.extensions]].filter(([, v]) => v?.length);
|
||||
for (const [label, names] of rows) {
|
||||
const d = el("details", "lib-plgroup");
|
||||
d.append(el("summary", "", label + " " + names.length), el("div", "mono lib-plnames", names.join(", ")));
|
||||
@@ -7462,7 +7463,7 @@ magpie.plugin("library", (ctx) => {
|
||||
if (problem) n.append(tag(t("Not written"), "warn", problem));
|
||||
else if (b.off) n.append(tag(t("Off"), ""));
|
||||
w.append(n);
|
||||
const line = [[t("Skills"), b.skills], [t("MCP servers"), b.mcp], [t("Hooks"), b.hooks], [t("Subagents"), b.subagents]]
|
||||
const line = [[t("Skills"), b.skills], [t("MCP servers"), b.mcp], [t("Hooks"), b.hooks], [t("Subagents"), b.subagents], [t("Pi extensions"), b.extensions]]
|
||||
.filter(([, v]) => v?.length).map(([k, v]) => k + " " + v.length).join(" · ");
|
||||
const sub = el("div", "sub lib-plparts", problem || line);
|
||||
sub.title = problem || line;
|
||||
|
||||
@@ -1139,6 +1139,8 @@ magpie.strings({
|
||||
"Install {n} plugins": "安装 {n} 个插件",
|
||||
"Hooks: {names}": "Hooks:{names}",
|
||||
"Subagents: {names}": "子代理:{names}",
|
||||
"Pi extensions": "Pi 扩展",
|
||||
"Pi extensions: {names}": "Pi 扩展:{names}",
|
||||
"Taken out by hand: {names}": "已手动取出:{names}",
|
||||
"Not carried": "未带上的部分",
|
||||
"It will be removed from the library, with its skills, MCP servers, hooks and subagents, and from the agents they were given to.": "它会连同技能、MCP 服务器、hooks 和子代理一起从资源库移除,也会从它们所在的智能体中取出。",
|
||||
@@ -2296,6 +2298,8 @@ magpie.strings({
|
||||
"Install {n} plugins": "安裝 {n} 個外掛",
|
||||
"Hooks: {names}": "Hooks:{names}",
|
||||
"Subagents: {names}": "子代理:{names}",
|
||||
"Pi extensions": "Pi 擴充",
|
||||
"Pi extensions: {names}": "Pi 擴充:{names}",
|
||||
"Taken out by hand: {names}": "已手動取出:{names}",
|
||||
"Not carried": "未帶上的部分",
|
||||
"It will be removed from the library, with its skills, MCP servers, hooks and subagents, and from the agents they were given to.": "它會連同技能、MCP 伺服器、hooks 和子代理一起從資源庫移除,也會從它們所在的代理中取出。",
|
||||
@@ -3453,6 +3457,8 @@ magpie.strings({
|
||||
"Install {n} plugins": "プラグインを {n} 件インストール",
|
||||
"Hooks: {names}": "フック: {names}",
|
||||
"Subagents: {names}": "サブエージェント: {names}",
|
||||
"Pi extensions": "Pi 拡張機能",
|
||||
"Pi extensions: {names}": "Pi 拡張機能: {names}",
|
||||
"Taken out by hand: {names}": "手動で外したもの: {names}",
|
||||
"Not carried": "引き継がれない部分",
|
||||
"It will be removed from the library, with its skills, MCP servers, hooks and subagents, and from the agents they were given to.": "スキル、MCP サーバー、フック、サブエージェントごとライブラリから削除され、渡されていたエージェントからも外されます。",
|
||||
@@ -4610,6 +4616,8 @@ magpie.strings({
|
||||
"Install {n} plugins": "{n} Plugins installieren",
|
||||
"Hooks: {names}": "Hooks: {names}",
|
||||
"Subagents: {names}": "Subagenten: {names}",
|
||||
"Pi extensions": "Pi-Erweiterungen",
|
||||
"Pi extensions: {names}": "Pi-Erweiterungen: {names}",
|
||||
"Taken out by hand: {names}": "Von Hand entfernt: {names}",
|
||||
"Not carried": "Nicht übernommen",
|
||||
"It will be removed from the library, with its skills, MCP servers, hooks and subagents, and from the agents they were given to.": "Es wird samt Skills, MCP-Servern, Hooks und Subagenten aus der Bibliothek und aus den Agenten entfernt, denen sie gegeben wurden.",
|
||||
|
||||
@@ -29,7 +29,10 @@ const SUB_AGENTS = [
|
||||
const MODELS = [{ id: "openai/gpt-6-sol", name: "GPT-6 Sol", note: "OpenAI" }, { id: "group/review", name: "review", group: true }];
|
||||
const LONG = "Reviews code a change touched and reports only real bugs: logic errors, edge cases, races and leaks, never style, and never refactors that have nothing to do with the change.";
|
||||
const PLUGIN = { name: "code-kit", version: "1.2.0", description: LONG, agents: ["claude", "codex"], skills: ["code-kit-tdd"], mcp: ["code-kit-docs"], hooks: ["code-kit-lint"], subagents: ["code-kit-reviewer"], left: [{ what: "commands/ship.md", why: "slash commands aren't carried" }], source: "/Users/chuan/code-kit", installed: "2026-11-11" };
|
||||
const FOUND = { source: "/Users/chuan/market", candidates: [{ name: "fresh-kit", description: "A new one", skills: 2, mcp: 1, hooks: 0, subagents: 1 }, { name: "code-kit", description: "Have it", skills: 1, mcp: 0, hooks: 0, subagents: 0, have: true }] };
|
||||
// #7267: a Pi package with only an extension is a plugin, its extension
|
||||
// its one part
|
||||
const PI_PKG = { name: "acme-pi-guard", version: "1.2.0", agents: [], extensions: ["extension.ts"], source: "/Users/chuan/pi-guard", installed: "2026-11-20" };
|
||||
const FOUND = { source: "/Users/chuan/market", candidates: [{ name: "fresh-kit", description: "A new one", skills: 2, mcp: 1, hooks: 0, subagents: 1 }, { name: "code-kit", description: "Have it", skills: 1, mcp: 0, hooks: 0, subagents: 0, have: true }, { name: "acme-pi-guard", description: "Guards", skills: 0, mcp: 0, hooks: 0, subagents: 0, extensions: 1, have: true }] };
|
||||
const lib = (plugins) => ({
|
||||
dir: `${HOME}/.magpie/library`, backups: `${HOME}/.magpie/backups`, home: HOME,
|
||||
agents: [agent("claude", "Claude Code"), agent("codex", "Codex")],
|
||||
@@ -115,7 +118,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
for (const lang of ["en", "zh", "zh-TW", "ja", "de"]) {
|
||||
await t.test(lang, async () => {
|
||||
const w = (key, vars) => tr(lang, key, vars);
|
||||
const state = { plugins: [{ ...PLUGIN }] };
|
||||
const state = { plugins: [{ ...PLUGIN }, { ...PI_PKG }] };
|
||||
const posts = [], errors = [];
|
||||
const open = async (width) => {
|
||||
const ctx = await browser.newContext({ viewport: { width, height: 1000 }, reducedMotion: "reduce" });
|
||||
@@ -135,7 +138,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
{
|
||||
const { ctx, page } = await open(1100);
|
||||
assert.deepEqual(await sideways(page), [], "sideways scroll at 1100");
|
||||
await press(page, page.locator("#view-library .lib-plugin").first());
|
||||
await press(page, page.locator("#view-library .lib-plugin").filter({ has: page.locator(".name", { hasText: "code-kit" }) }));
|
||||
await page.locator("#modal .lib-pldetail").waitFor();
|
||||
await settled(page);
|
||||
assert.deepEqual(await sideways(page), [], "sideways scroll in the dialog at 1100");
|
||||
@@ -160,9 +163,10 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
const row = (name) => v.locator(".lib-plugin").filter({ has: page.locator(".name", { hasText: name }) });
|
||||
// the tab, counted, and the row's parts
|
||||
const tabs = (await v.locator(".lib-tabs button").allTextContents()).map((x) => x.trim());
|
||||
assert(tabs.includes(w("Claude plugins") + " · 1"), tabs.join("|"));
|
||||
assert(tabs.includes(w("Claude plugins") + " · 2"), tabs.join("|"));
|
||||
assert.equal((await row("code-kit").locator(".lib-plparts").textContent()).trim(),
|
||||
[w("Skills") + " 1", w("MCP servers") + " 1", w("Hooks") + " 1", w("Subagents") + " 1"].join(" · "));
|
||||
assert.equal((await row("acme-pi-guard").locator(".lib-plparts").textContent()).trim(), w("Pi extensions") + " 1");
|
||||
assert.deepEqual(await sideways(page), [], "sideways scroll at 420");
|
||||
assert.equal(await page.locator("select").count(), 0, "a native <select>");
|
||||
|
||||
@@ -187,6 +191,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
assert.equal(await v.locator(".lib-plpick input:checked").count(), 1);
|
||||
assert.equal(await v.locator(".lib-plpick input:disabled").count(), 0);
|
||||
assert.deepEqual(await sideways(page), [], "sideways scroll with the finds at 420");
|
||||
assert.equal((await v.locator(".lib-plpick").filter({ hasText: "acme-pi-guard" }).locator(".lib-plparts").textContent()).trim(), w("Pi extensions: {names}", { names: "1" }));
|
||||
await v.locator(".lib-plfind .lib-probefoot button.primary", { hasText: w("Install 1 plugin") }).click();
|
||||
await row("fresh-kit").waitFor();
|
||||
const inst = posts.shift();
|
||||
|
||||
@@ -26,7 +26,7 @@ const lib = (given) => ({
|
||||
agent("goose", "Goose"),
|
||||
],
|
||||
instructions: { agents: [] }, servers: [], subagents: [], skills: [], foundServers: [], foundSkills: [],
|
||||
plugins: [plugin("acme-kit", { skills: ["tdd"], mcp: ["acme-db"], hooks: ["acme-kit:Stop"], subagents: ["reviewer"] }), plugin("tidy", { skills: ["tidy"] })],
|
||||
plugins: [plugin("acme-kit", { skills: ["tdd"], mcp: ["acme-db"], hooks: ["acme-kit:Stop"], subagents: ["reviewer"] }), plugin("tidy", { skills: ["tidy"] }), plugin("pi-guard", { extensions: ["extension.ts"] })],
|
||||
projects: [{ dir: DIR, name: "app", copy: false, skills: {}, placed: [], servers: {}, subagents: {}, plugins: given, wrote: {} }],
|
||||
});
|
||||
|
||||
@@ -119,7 +119,9 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
await press(page, card.locator(".lib-projhead"));
|
||||
const rows = card.locator(".lib-projplugin");
|
||||
await rows.first().waitFor();
|
||||
assert.equal(await rows.count(), 2);
|
||||
assert.equal(await rows.count(), 3);
|
||||
// #7267: a Pi package with only an extension says so on its row
|
||||
assert.match((await card.locator(".lib-projplugin").filter({ hasText: "pi-guard" }).locator(".lib-plparts").textContent()).trim(), /^\S.* 1$/);
|
||||
const row = () => card.locator(".lib-projplugin").filter({ hasText: "acme-kit" }).first();
|
||||
assert.deepEqual(await row().locator(".lib-ag").evaluateAll((cs) => cs.map((c) => c.dataset.agent)), ["claude", "codex", "pi"], "Goose takes nothing in a project");
|
||||
assert.equal(await card.locator(".lib-projhooks-codex").count(), 0);
|
||||
|
||||
@@ -66,6 +66,11 @@ type Plugin struct {
|
||||
MCP []string `json:"mcp,omitempty"`
|
||||
Hooks []string `json:"hooks,omitempty"`
|
||||
Subagents []string `json:"subagents,omitempty"`
|
||||
// Extensions are the Pi extensions a Pi package declares (package.json
|
||||
// pi.extensions), as paths in its folder. They are Pi's to load, from
|
||||
// the package entry a project giving the plugin to Pi gets (#7267), so
|
||||
// magpie writes nothing for them
|
||||
Extensions []string `json:"extensions,omitempty"`
|
||||
// Left are the parts of the plugin magpie doesn't carry, and why
|
||||
Left []PluginLeft `json:"left,omitempty"`
|
||||
// Installed is when it was installed or last updated
|
||||
@@ -113,11 +118,74 @@ type plLoaded struct {
|
||||
servers []*Server
|
||||
hooks []*Hook
|
||||
agents []*Subagent
|
||||
extensions []string // a Pi package's, relative to its folder
|
||||
left []PluginLeft
|
||||
}
|
||||
|
||||
func (p *plLoaded) parts() int {
|
||||
return len(p.skills) + len(p.servers) + len(p.hooks) + len(p.agents)
|
||||
return len(p.skills) + len(p.servers) + len(p.hooks) + len(p.agents) + len(p.extensions)
|
||||
}
|
||||
|
||||
// piPackageExtensions are the extensions a Pi package declares in
|
||||
// package.json pi.extensions, as Pi resolves them (package-manager.js): a
|
||||
// file is itself, a folder its index.ts/index.js or package.json's own
|
||||
// pi.extensions, else each extension in it; a glob matches files in the
|
||||
// package; "!" leaves out what matches. A folder that isn't a Pi package, or
|
||||
// declares none, has none: Pi loads no extensions/ folder of a package with
|
||||
// a "pi" object that doesn't name it.
|
||||
func piPackageExtensions(dir string) []string {
|
||||
if !piManifest(dir) {
|
||||
return nil
|
||||
}
|
||||
raw, _ := os.ReadFile(filepath.Join(dir, "package.json"))
|
||||
var pkg struct {
|
||||
Pi struct {
|
||||
Extensions []string `json:"extensions"`
|
||||
} `json:"pi"`
|
||||
}
|
||||
if json.Unmarshal(stripBOM(raw), &pkg) != nil {
|
||||
return nil
|
||||
}
|
||||
var files, drops []string
|
||||
for _, e := range pkg.Pi.Extensions {
|
||||
switch {
|
||||
case strings.HasPrefix(e, "!") || strings.HasPrefix(e, "-"):
|
||||
drops = append(drops, strings.TrimPrefix(filepath.ToSlash(e[1:]), "./"))
|
||||
case strings.HasPrefix(e, "+"):
|
||||
case piIsPattern(e):
|
||||
for _, f := range piExpand(dir, e) {
|
||||
if fi, err := os.Stat(f); err == nil && fi.Mode().IsRegular() {
|
||||
files = append(files, f)
|
||||
}
|
||||
}
|
||||
default:
|
||||
d, ok := inside(dir, e)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
if fi, err := os.Stat(d); err != nil {
|
||||
continue
|
||||
} else if fi.IsDir() {
|
||||
files = append(files, piDirEntries(d)...)
|
||||
} else {
|
||||
files = append(files, d)
|
||||
}
|
||||
}
|
||||
}
|
||||
var out []string
|
||||
for _, f := range files {
|
||||
rel, err := filepath.Rel(dir, f)
|
||||
if err != nil || strings.HasPrefix(rel, "..") {
|
||||
continue
|
||||
}
|
||||
rel = filepath.ToSlash(rel)
|
||||
if slices.ContainsFunc(drops, func(x string) bool { return rel == x || piGlob(x).MatchString(rel) }) {
|
||||
continue
|
||||
}
|
||||
out = append(out, rel)
|
||||
}
|
||||
slices.Sort(out)
|
||||
return slices.Compact(out)
|
||||
}
|
||||
|
||||
func readJSONFile(p string) (map[string]any, error) {
|
||||
@@ -219,8 +287,22 @@ func readPlugin(dir, hint, force string, over map[string]any) (*plLoaded, error)
|
||||
man[k] = v
|
||||
}
|
||||
}
|
||||
if !isPlugin(dir) && len(man) == 0 {
|
||||
return nil, fmt.Errorf("no plugin in %s: it has no .claude-plugin/plugin.json, .codex-plugin/plugin.json, skills, agents, hooks or .mcp.json", dir)
|
||||
// a Pi package's package.json names it, says what it is and its version
|
||||
// where no plugin manifest does: its name holds however the package is
|
||||
// fetched (#7267)
|
||||
if piManifest(dir) {
|
||||
if pkg, err := readJSONFile(filepath.Join(dir, "package.json")); err == nil {
|
||||
for _, k := range []string{"name", "description", "version"} {
|
||||
if _, ok := man[k]; !ok && plStr(pkg[k]) != "" {
|
||||
man[k] = pkg[k]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// a Pi package (package.json with a "pi" object) is one too (#7267):
|
||||
// one with only extensions has nothing else here
|
||||
if !isPlugin(dir) && len(man) == 0 && !piManifest(dir) {
|
||||
return nil, fmt.Errorf("no plugin in %s: it has no .claude-plugin/plugin.json, .codex-plugin/plugin.json, skills, agents, hooks, .mcp.json or a Pi package.json", dir)
|
||||
}
|
||||
name := pluginSlug(force)
|
||||
if name == "" {
|
||||
@@ -235,7 +317,8 @@ func readPlugin(dir, hint, force string, over map[string]any) (*plLoaded, error)
|
||||
if name == "" {
|
||||
return nil, errors.New("the plugin has no name")
|
||||
}
|
||||
p := &plLoaded{name: name, description: strings.Join(strings.Fields(plStr(man["description"])), " "), version: plStr(man["version"])}
|
||||
p := &plLoaded{name: name, description: strings.Join(strings.Fields(plStr(man["description"])), " "), version: plStr(man["version"]),
|
||||
extensions: piPackageExtensions(dir)}
|
||||
root, sub := pluginDir(name), pluginSub(name)
|
||||
leave := func(what, why string) { p.left = append(p.left, PluginLeft{What: what, Why: why}) }
|
||||
|
||||
@@ -702,6 +785,7 @@ type PluginCandidate struct {
|
||||
MCP int `json:"mcp"`
|
||||
Hooks int `json:"hooks"`
|
||||
Subagents int `json:"subagents"`
|
||||
Extensions int `json:"extensions,omitempty"`
|
||||
// Remote: it is fetched from another repository when installed, so
|
||||
// its parts aren't counted
|
||||
Remote bool `json:"remote,omitempty"`
|
||||
@@ -914,7 +998,7 @@ func marketSource(s map[string]any) (Source, string) {
|
||||
|
||||
func candidateOf(pl *plLoaded, dir string, over map[string]any) PluginCandidate {
|
||||
return PluginCandidate{Name: pl.name, Description: pl.description, Version: pl.version,
|
||||
Skills: len(pl.skills), MCP: len(pl.servers), Hooks: len(pl.hooks), Subagents: len(pl.agents),
|
||||
Skills: len(pl.skills), MCP: len(pl.servers), Hooks: len(pl.hooks), Subagents: len(pl.agents), Extensions: len(pl.extensions),
|
||||
Left: pl.left, dir: dir, over: over}
|
||||
}
|
||||
|
||||
@@ -1058,7 +1142,7 @@ func installPlugins(p *PluginProbe, input string, names, agents []string, as str
|
||||
return nil, fmt.Errorf("%s: %w", c.Name, err)
|
||||
}
|
||||
if pl.parts() == 0 {
|
||||
return nil, fmt.Errorf("%s has no skills, MCP servers, hooks or subagents magpie can give an agent", pl.name)
|
||||
return nil, fmt.Errorf("%s has no skills, MCP servers, hooks, subagents or extensions for Pi magpie can give an agent", pl.name)
|
||||
}
|
||||
ones = append(ones, one{c, pl, d})
|
||||
}
|
||||
@@ -1091,7 +1175,8 @@ func installPlugins(p *PluginProbe, input string, names, agents []string, as str
|
||||
func installPlugin(l *Library, pl *plLoaded, dir, input, pick string, agents []string) ([]Problem, error) {
|
||||
old := l.plugin(pl.name)
|
||||
b := &Plugin{Name: pl.name, Description: pl.description, Version: pl.version, Source: input, Pick: pick,
|
||||
Agents: orNone(slices.Compact(slices.Sorted(slices.Values(agents)))), Installed: time.Now().Format(time.RFC3339)}
|
||||
Agents: orNone(slices.Compact(slices.Sorted(slices.Values(agents)))), Installed: time.Now().Format(time.RFC3339),
|
||||
Extensions: pl.extensions}
|
||||
if old != nil {
|
||||
b.Agents, b.Off = old.Agents, old.Off
|
||||
if len(agents) > 0 {
|
||||
@@ -1207,7 +1292,7 @@ func installPlugin(l *Library, pl *plLoaded, dir, input, pick string, agents []s
|
||||
l.Subagents = append(l.Subagents, s)
|
||||
b.Subagents = append(b.Subagents, n)
|
||||
}
|
||||
if len(b.Skills)+len(b.MCP)+len(b.Hooks)+len(b.Subagents) == 0 {
|
||||
if len(b.Skills)+len(b.MCP)+len(b.Hooks)+len(b.Subagents)+len(b.Extensions) == 0 {
|
||||
os.RemoveAll(pluginDir(pl.name))
|
||||
return nil, errors.New("every part of it clashes with the library's own: " + skipped[len(skipped)-1].Error)
|
||||
}
|
||||
|
||||
@@ -284,7 +284,7 @@ func (l *Library) putPlugins(in []*CarriedPlugin, stage string) (fetch []*Carrie
|
||||
continue
|
||||
}
|
||||
if pl.parts() == 0 {
|
||||
fail(fmt.Errorf("%s has no skills, MCP servers, hooks or subagents magpie can give an agent", c.Name))
|
||||
fail(fmt.Errorf("%s has no skills, MCP servers, hooks, subagents or extensions for Pi magpie can give an agent", c.Name))
|
||||
continue
|
||||
}
|
||||
skipped, err := installPlugin(l, pl, dir, c.Source, c.Pick, c.Agents)
|
||||
|
||||
@@ -3,6 +3,7 @@ package library
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -161,3 +162,76 @@ func TestProjectPluginPiPackage(t *testing.T) {
|
||||
t.Fatalf("withdrawn:\n%s", s)
|
||||
}
|
||||
}
|
||||
|
||||
// An extension-only Pi package (#7267, jinpwng) is a plugin: the probe
|
||||
// finds it by its package.json, shows its extension and names it by the
|
||||
// package, and a project giving it to Pi gets one entry, its folder.
|
||||
func TestPiExtensionOnlyPackageIsAPlugin(t *testing.T) {
|
||||
h := sandbox(t)
|
||||
pluginAgents(t, h)
|
||||
src := filepath.Join(t.TempDir(), "folder")
|
||||
write(t, filepath.Join(src, "package.json"), `{"name":"@acme/pi-guard","version":"1.2.0","description":"Guards","pi":{"extensions":["./extension.ts"]}}`)
|
||||
write(t, filepath.Join(src, "extension.ts"), "export default function (pi: any) { pi.on('session_start', async () => {}) }\n")
|
||||
forgetProbes()
|
||||
p, err := ProbePlugins(src)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(p.Candidates) != 1 || p.Candidates[0].Extensions != 1 || p.Candidates[0].Name != "acme-pi-guard" || p.Candidates[0].Version != "1.2.0" {
|
||||
t.Fatalf("probe: %+v", p.Candidates)
|
||||
}
|
||||
ok(t)(InstallPlugins(src, nil, []string{}))
|
||||
v := View0(t)
|
||||
if len(v.Plugins) != 1 || v.Plugins[0].Name != "acme-pi-guard" || !slices.Equal(v.Plugins[0].Extensions, []string{"extension.ts"}) {
|
||||
t.Fatalf("bundle: %+v", v.Plugins)
|
||||
}
|
||||
if len(v.Skills)+len(v.Servers)+len(v.Hooks)+len(v.Subagents) != 0 {
|
||||
t.Fatalf("an extension is no library item: %+v", v)
|
||||
}
|
||||
proj := filepath.Join(t.TempDir(), "proj")
|
||||
gitInit(t, proj)
|
||||
ok(t)(AddProject(proj))
|
||||
file := filepath.Join(proj, ".pi/settings.json")
|
||||
write(t, file, "{\"packages\": [\"npm:pi-own\"]}\n")
|
||||
ok(t)(ProjectPlugin(proj, "acme-pi-guard", []string{"pi"}))
|
||||
ok(t)(ProjectPlugin(proj, "acme-pi-guard", []string{"pi"}))
|
||||
s := read(t, file)
|
||||
if strings.Count(s, pluginDir("acme-pi-guard")) != 1 || !strings.Contains(s, "npm:pi-own") {
|
||||
t.Fatalf("one entry beside the project's own:\n%s", s)
|
||||
}
|
||||
ok(t)(ProjectPlugin(proj, "acme-pi-guard", nil))
|
||||
if s := read(t, file); strings.Contains(s, pluginDir("acme-pi-guard")) || !strings.Contains(s, "npm:pi-own") {
|
||||
t.Fatalf("withdrawn:\n%s", s)
|
||||
}
|
||||
|
||||
// a package.json with no "pi" object is no plugin still
|
||||
plain := filepath.Join(t.TempDir(), "plain")
|
||||
write(t, filepath.Join(plain, "package.json"), `{"name":"left-pad"}`)
|
||||
forgetProbes()
|
||||
if _, err := ProbePlugins(plain); err == nil || !strings.Contains(err.Error(), "no plugin") {
|
||||
t.Fatalf("a plain package: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// The extensions a package declares, resolved as Pi does: a file, a
|
||||
// folder's index, each extension in a folder, a glob, and "!" leaving one
|
||||
// out; nothing outside the package.
|
||||
func TestPiPackageExtensions(t *testing.T) {
|
||||
d := t.TempDir()
|
||||
write(t, filepath.Join(d, "package.json"), `{"pi":{"extensions":["./a.ts","./withindex","./many","./globbed/*.ts","!globbed/skip.ts","../out.ts"]}}`)
|
||||
for _, f := range []string{"a.ts", "withindex/index.ts", "withindex/helper.ts", "many/x.ts", "many/y.js", "many/notes.md", "globbed/g.ts", "globbed/skip.ts"} {
|
||||
write(t, filepath.Join(d, f), "//")
|
||||
}
|
||||
write(t, filepath.Join(filepath.Dir(d), "out.ts"), "//")
|
||||
got := piPackageExtensions(d)
|
||||
want := []string{"a.ts", "globbed/g.ts", "many/x.ts", "many/y.js", "withindex/index.ts"}
|
||||
if !slices.Equal(got, want) {
|
||||
t.Fatalf("got %v, want %v", got, want)
|
||||
}
|
||||
nopi := t.TempDir()
|
||||
write(t, filepath.Join(nopi, "package.json"), `{"name":"x"}`)
|
||||
write(t, filepath.Join(nopi, "extensions/e.ts"), "//")
|
||||
if got := piPackageExtensions(nopi); got != nil {
|
||||
t.Fatalf("no pi object: %v", got)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user