library: a project takes a whole Claude plugin, and gives it back (jinpwng on X)
A project can now have a library Claude plugin for chosen agents (projects/plugin). Its skills, MCP servers and subagents go where the project's own do (withPlugins adds them for a sync and puts the project's own sets back after), and its hooks are written entry by entry into .claude/settings.local.json and .codex/hooks.json (HookRecs). Taking the plugin out deletes it from Plugins, and only what magpie placed or wrote comes out; an entry the user changed stays. Removing a plugin from the library drops it from every project. The Library plugins tab gets a Project plugins section with per-agent chips, in en, zh, zh-TW, ja, de. Run, on mote at the pushed head (rebased on origin/main5d4f9862c): - go test -count=1 ./internal/library ./internal/gui: both ok (204.9s, 181.3s); the same two ok at the earlier base352b124b3. - gofmt -l on internal/library and internal/gui: clean. Not run before this push (mote and mica were both at load 27 to 51 under other sessions' full suites; pushed at the owner's word to ship at once): the full go test ./..., Linux and Windows vet, the whole GUI suite in Chromium and WebKit. They are queued behind those runs and their result will be filed as an issue per red. Not tried with a real project and a real plugin outside the tests.
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -5646,6 +5646,7 @@ magpie.plugin("library", (ctx) => {
|
||||
const list = el("div", "list lib-list");
|
||||
list.append(...[...plugins].sort((a, b) => a.name.localeCompare(b.name)).map((p) => pluginRow(p, all)));
|
||||
body.append(list);
|
||||
if (!agentless()) renderProjects(body, "plugins");
|
||||
}
|
||||
|
||||
function pluginFind() {
|
||||
@@ -6989,7 +6990,7 @@ magpie.plugin("library", (ctx) => {
|
||||
|
||||
function renderProjects(body, kind) {
|
||||
const rh = el("div", "row-head");
|
||||
rh.append(el("span", "label", kind === "skills" ? t("Project skills") : kind === "subagents" ? t("Project subagents") : kind === "instructions" ? t("Project instructions") : t("Project servers")), el("span", "grow"));
|
||||
rh.append(el("span", "label", kind === "skills" ? t("Project skills") : kind === "subagents" ? t("Project subagents") : kind === "plugins" ? t("Project plugins") : kind === "instructions" ? t("Project instructions") : t("Project servers")), el("span", "grow"));
|
||||
if (!addingProject) rh.append(button(t("Add a project"), "action lib-updall", () => { addingProject = { dir: "" }; render(); }));
|
||||
body.append(rh);
|
||||
if (addingProject) body.append(addProjectCard(kind));
|
||||
@@ -6998,6 +6999,8 @@ magpie.plugin("library", (ctx) => {
|
||||
? t("Give a project instructions of its own: magpie writes them into the AGENTS.md, CLAUDE.md or the like each agent reads there, leaving the rest of each file as it is.")
|
||||
: kind === "subagents"
|
||||
? t("Give a project's agents some of these subagents as the project's own: magpie writes them into its .claude/agents and the like, and keeps them out of git.")
|
||||
: kind === "plugins"
|
||||
? t("Give a project a whole plugin: magpie writes each part where its agents read the project's own, and taking the plugin out takes out only what it wrote.")
|
||||
: kind === "mcp"
|
||||
? t("Give a project's agents some of these servers as the project's own: magpie writes them into its {files}, leaving the rest of each file as it is.", { files: projectFiles() })
|
||||
: t("Give a project's agents some of these skills as the project's own: magpie links them into its .claude/skills and .agents/skills and keeps them out of git.")));
|
||||
@@ -7045,7 +7048,7 @@ magpie.plugin("library", (ctx) => {
|
||||
addingProject = null;
|
||||
const p = lib.projects.find((x) => !was.has(x.dir));
|
||||
if (p) openProjects.add(p.dir);
|
||||
status(kind === "instructions" ? t("{name} added — write its instructions", { name: p?.name || dir }) : kind === "subagents" ? t("{name} added — pick the subagents it gets", { name: p?.name || dir }) : kind === "mcp" ? t("{name} added — pick the servers it gets", { name: p?.name || dir }) : t("{name} added — pick the skills it gets", { name: p?.name || dir }), "ok");
|
||||
status(kind === "instructions" ? t("{name} added — write its instructions", { name: p?.name || dir }) : kind === "plugins" ? t("{name} added — pick the plugins it gets", { name: p?.name || dir }) : kind === "subagents" ? t("{name} added — pick the subagents it gets", { name: p?.name || dir }) : kind === "mcp" ? t("{name} added — pick the servers it gets", { name: p?.name || dir }) : t("{name} added — pick the skills it gets", { name: p?.name || dir }), "ok");
|
||||
} catch (e) {
|
||||
a.busy = false;
|
||||
a.error = e.message;
|
||||
@@ -7056,19 +7059,19 @@ magpie.plugin("library", (ctx) => {
|
||||
}
|
||||
|
||||
function projectCard(p, kind) {
|
||||
const mcp = kind === "mcp", sub = kind === "subagents", ins = kind === "instructions";
|
||||
const mcp = kind === "mcp", sub = kind === "subagents", ins = kind === "instructions", plg = kind === "plugins";
|
||||
const card = el("div", "list lib-card lib-project" + (p.missing ? " missing" : ""));
|
||||
const isOpen = openProjects.has(p.dir);
|
||||
const head = el("div", "row lib-row click lib-projhead" + (isOpen ? " open" : ""));
|
||||
const who = el("div", "who");
|
||||
const nm = el("div", "name", p.name);
|
||||
if (p.missing) nm.append(tag(t("Folder is gone"), "warn"));
|
||||
else if (p.copy && !mcp && !sub && !ins) nm.append(tag(t("Copies"), ""));
|
||||
else if (p.copy && !mcp && !sub && !ins && !plg) nm.append(tag(t("Copies"), ""));
|
||||
who.append(nm);
|
||||
const src = el("div", "lib-src");
|
||||
src.append(pathLink(p.dir));
|
||||
who.append(src);
|
||||
const names = Object.keys((sub ? p.subagents : mcp ? p.servers : p.skills) || {}).sort();
|
||||
const names = Object.keys((plg ? p.plugins : sub ? p.subagents : mcp ? p.servers : p.skills) || {}).sort();
|
||||
const pills = el("div", "lib-tags");
|
||||
if (!isOpen && ins) {
|
||||
const first = (projTexts[p.dir] ?? p.instr ?? "").split("\n").find((l) => l.trim())?.replace(/^#+\s*/, "") || "";
|
||||
@@ -7081,7 +7084,7 @@ magpie.plugin("library", (ctx) => {
|
||||
} else if (!isOpen) {
|
||||
for (const n of names.slice(0, 4)) pills.append(tag(n, "lib-dot"));
|
||||
if (names.length > 4) pills.append(tag("+" + (names.length - 4), ""));
|
||||
if (!names.length) pills.append(tag(sub ? t("No subagents yet") : mcp ? t("No servers yet") : t("No skills yet"), "lib-unchecked"));
|
||||
if (!names.length) pills.append(tag(plg ? t("No Claude plugins yet") : sub ? t("No subagents yet") : mcp ? t("No servers yet") : t("No skills yet"), "lib-unchecked"));
|
||||
}
|
||||
const acts = el("div", "lib-rowacts");
|
||||
const rm = button("", "lib-icon danger", () => confirmRemoveProject(p));
|
||||
@@ -7092,12 +7095,13 @@ magpie.plugin("library", (ctx) => {
|
||||
chev.append(svg(CHEV_R, 11, 1.7));
|
||||
head.append(glyph(GLYPH.folder), who, pills, acts, chev);
|
||||
head.onclick = () => { isOpen ? openProjects.delete(p.dir) : openProjects.add(p.dir); projectShown.delete(p.dir); render(); };
|
||||
head.title = ins ? (isOpen ? t("Hide its instructions") : t("Write its instructions")) : sub ? (isOpen ? t("Hide its subagents") : t("Pick the subagents it gets")) : mcp ? (isOpen ? t("Hide its servers") : t("Pick the servers it gets")) : isOpen ? t("Hide its skills") : t("Pick the skills it gets");
|
||||
head.title = ins ? (isOpen ? t("Hide its instructions") : t("Write its instructions")) : plg ? (isOpen ? t("Hide its plugins") : t("Pick the plugins it gets")) : sub ? (isOpen ? t("Hide its subagents") : t("Pick the subagents it gets")) : mcp ? (isOpen ? t("Hide its servers") : t("Pick the servers it gets")) : isOpen ? t("Hide its skills") : t("Pick the skills it gets");
|
||||
card.append(head);
|
||||
if (p.problems?.[""]) card.append(el("div", "lib-err", p.problems[""]));
|
||||
if (!isOpen) return card;
|
||||
if (mcp) return projectServers(p, card);
|
||||
if (sub) return projectSubagents(p, card);
|
||||
if (plg) return projectPlugins(p, card);
|
||||
if (ins) return projectInstructions(p, card);
|
||||
|
||||
const opts = el("div", "lib-projopts");
|
||||
@@ -7324,6 +7328,40 @@ magpie.plugin("library", (ctx) => {
|
||||
return card;
|
||||
}
|
||||
|
||||
// The project's card, open on the Claude plugins tab: each library
|
||||
// plugin with the chips of the agents that take some part of it in a
|
||||
// project. A chip gives the agent every part it can take there; none
|
||||
// takes the plugin out, and only what magpie wrote for it (jinpwng on X).
|
||||
function projectPlugins(p, card) {
|
||||
const all = shownAgents().filter((a) => a.projectSkills || a.projectMCP || a.projectSubagents || a.projectHooks);
|
||||
const plugins = [...(lib.plugins || [])].sort((a, b) => a.name.localeCompare(b.name));
|
||||
for (const b of plugins) {
|
||||
const row = el("div", "row lib-row lib-projskill lib-projplugin" + (b.off ? " off" : ""));
|
||||
const w = el("div", "who");
|
||||
const n = el("div", "name mono", b.name);
|
||||
// a part not written says so on its plugin's row
|
||||
const keys = [...(b.skills || []), ...(b.mcp || []).map((x) => "mcp:" + x), ...(b.hooks || []).map((x) => "hook:" + x), ...(b.subagents || []).map((x) => "subagent:" + x)];
|
||||
const problem = keys.map((k) => p.problems?.[k]).find(Boolean);
|
||||
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]]
|
||||
.filter(([, v]) => v?.length).map(([k, v]) => k + " " + v.length).join(" · ");
|
||||
const sub = el("div", "sub lib-plparts", problem || line);
|
||||
sub.title = problem || line;
|
||||
w.append(sub);
|
||||
const on = (p.plugins?.[b.name] || []).filter((id) => all.some((a) => a.id === id));
|
||||
const say = (next) => next.length
|
||||
? t("{item} is in {name} for {agents}", { item: b.name, name: p.name, agents: next.map(nameOf).join(", ") })
|
||||
: t("{item} is out of {name}", { item: b.name, name: p.name });
|
||||
row.append(glyph(GLYPH.folder), w, agentChips(all, on, projectChange("projects/plugin", p.dir, b.name, say)));
|
||||
card.append(row);
|
||||
}
|
||||
card.append(el("p", "lib-aside lib-projfoot", t("Its skills, servers and subagents go where the project's own do, and its hooks into .claude/settings.local.json and .codex/hooks.json. A file there that isn't magpie's, or an entry you changed, is left as it is.")));
|
||||
if (plugins.some((b) => b.hooks?.length && (p.plugins?.[b.name] || []).includes("codex"))) card.append(el("p", "lib-aside lib-projfoot lib-projhooks-codex", t("Codex runs a project's hooks only in a project you trust, once you've reviewed them in /hooks.")));
|
||||
return card;
|
||||
}
|
||||
|
||||
// The agents a project's first instructions are for: those here that
|
||||
// read a project's instructions file and have the shared ones on, else
|
||||
// every one of them here.
|
||||
|
||||
@@ -783,6 +783,14 @@ magpie.strings({
|
||||
"Claude Desktop shows skill changes once its window is reloaded ({keys}). It gets a copy of each skill, and one you change in Desktop is left as it is.": "Claude Desktop 刷新窗口({keys})后才显示技能变化。它使用技能的副本,在 Desktop 中改过的副本不会被覆盖。",
|
||||
"Project servers": "项目服务器",
|
||||
"Project subagents": "项目子代理",
|
||||
"Project plugins": "项目插件",
|
||||
"Give a project a whole plugin: magpie writes each part where its agents read the project's own, and taking the plugin out takes out only what it wrote.": "把整个插件给一个项目:magpie 把每个部分写到它的 Agent 读取项目自身配置的位置,移除插件时只移除它写入的内容。",
|
||||
"{name} added — pick the plugins it gets": "已添加 {name},选择它要用的插件",
|
||||
"No Claude plugins yet": "还没有 Claude 插件",
|
||||
"Hide its plugins": "收起插件",
|
||||
"Pick the plugins it gets": "选择它要用的插件",
|
||||
"Its skills, servers and subagents go where the project's own do, and its hooks into .claude/settings.local.json and .codex/hooks.json. A file there that isn't magpie's, or an entry you changed, is left as it is.": "它的技能、服务器和子代理放在项目自己的那些位置,hooks 写进 .claude/settings.local.json 和 .codex/hooks.json。那里不是 magpie 写的文件、你改过的条目,都保持原样。",
|
||||
"Codex runs a project's hooks only in a project you trust, once you've reviewed them in /hooks.": "Codex 只在你信任的项目里运行项目的 hooks,并且要先在 /hooks 中审阅。",
|
||||
"Give a project's agents some of these subagents as the project's own: magpie writes them into its .claude/agents and the like, and keeps them out of git.": "把这些子代理作为项目自己的给项目里的 Agent:magpie 写进它的 .claude/agents 等文件夹,并让它们不进 git。",
|
||||
"{name} added — pick the subagents it gets": "已添加 {name},选择它要用的子代理",
|
||||
"No subagents yet": "还没有子代理",
|
||||
@@ -1917,6 +1925,14 @@ magpie.strings({
|
||||
"Claude Desktop shows skill changes once its window is reloaded ({keys}). It gets a copy of each skill, and one you change in Desktop is left as it is.": "Claude Desktop 重新整理視窗({keys})後才顯示技能變化。它使用技能的副本,在 Desktop 中改過的副本不會被覆蓋。",
|
||||
"Project servers": "專案伺服器",
|
||||
"Project subagents": "專案子代理",
|
||||
"Project plugins": "專案外掛",
|
||||
"Give a project a whole plugin: magpie writes each part where its agents read the project's own, and taking the plugin out takes out only what it wrote.": "把整個外掛給一個專案:magpie 把每個部分寫到它的 Agent 讀取專案自身設定的位置,移除外掛時只移除它寫入的內容。",
|
||||
"{name} added — pick the plugins it gets": "已新增 {name},選擇它要用的外掛",
|
||||
"No Claude plugins yet": "還沒有 Claude 外掛",
|
||||
"Hide its plugins": "收起外掛",
|
||||
"Pick the plugins it gets": "選擇它要用的外掛",
|
||||
"Its skills, servers and subagents go where the project's own do, and its hooks into .claude/settings.local.json and .codex/hooks.json. A file there that isn't magpie's, or an entry you changed, is left as it is.": "它的技能、伺服器和子代理放在專案自己的那些位置,hooks 寫進 .claude/settings.local.json 和 .codex/hooks.json。那裡不是 magpie 寫的檔案、你改過的條目,都保持原樣。",
|
||||
"Codex runs a project's hooks only in a project you trust, once you've reviewed them in /hooks.": "Codex 只在你信任的專案裡執行專案的 hooks,並且要先在 /hooks 中審閱。",
|
||||
"Give a project's agents some of these subagents as the project's own: magpie writes them into its .claude/agents and the like, and keeps them out of git.": "把這些子代理作為專案自己的給專案裡的 Agent:magpie 寫進它的 .claude/agents 等資料夾,並讓它們不進 git。",
|
||||
"{name} added — pick the subagents it gets": "已新增 {name},選擇它要用的子代理",
|
||||
"No subagents yet": "還沒有子代理",
|
||||
@@ -3042,6 +3058,14 @@ magpie.strings({
|
||||
"Claude Desktop shows skill changes once its window is reloaded ({keys}). It gets a copy of each skill, and one you change in Desktop is left as it is.": "Claude Desktop はウィンドウを再読み込み({keys})するとスキルの変更を表示します。各スキルのコピーを受け取り、Desktop で変更したものはそのまま残ります。",
|
||||
"Project servers": "プロジェクトのサーバー",
|
||||
"Project subagents": "プロジェクトのサブエージェント",
|
||||
"Project plugins": "プロジェクトのプラグイン",
|
||||
"Give a project a whole plugin: magpie writes each part where its agents read the project's own, and taking the plugin out takes out only what it wrote.": "プラグインをまるごとプロジェクトに渡します。magpie は各パーツを、Agent がプロジェクト自身の設定を読む場所に書き込み、プラグインを外すときは書き込んだものだけを取り除きます。",
|
||||
"{name} added — pick the plugins it gets": "{name} を追加しました。渡すプラグインを選んでください",
|
||||
"No Claude plugins yet": "Claude プラグインはまだありません",
|
||||
"Hide its plugins": "プラグインを隠す",
|
||||
"Pick the plugins it gets": "渡すプラグインを選ぶ",
|
||||
"Its skills, servers and subagents go where the project's own do, and its hooks into .claude/settings.local.json and .codex/hooks.json. A file there that isn't magpie's, or an entry you changed, is left as it is.": "スキル、サーバー、サブエージェントはプロジェクト自身のものと同じ場所に、フックは .claude/settings.local.json と .codex/hooks.json に書き込まれます。magpie のものではないファイルや、あなたが変更した項目はそのまま残ります。",
|
||||
"Codex runs a project's hooks only in a project you trust, once you've reviewed them in /hooks.": "Codex は信頼したプロジェクトでのみ、/hooks で確認した後にプロジェクトのフックを実行します。",
|
||||
"Give a project's agents some of these subagents as the project's own: magpie writes them into its .claude/agents and the like, and keeps them out of git.": "これらのサブエージェントをプロジェクト専用として渡します。magpie が .claude/agents などに書き込み、git には入れません。",
|
||||
"{name} added — pick the subagents it gets": "{name} を追加しました。渡すサブエージェントを選んでください",
|
||||
"No subagents yet": "サブエージェントはまだありません",
|
||||
@@ -4172,6 +4196,14 @@ magpie.strings({
|
||||
"Claude Desktop shows skill changes once its window is reloaded ({keys}). It gets a copy of each skill, and one you change in Desktop is left as it is.": "Claude Desktop zeigt Skill-Änderungen erst nach dem Neuladen des Fensters ({keys}). Es erhält von jedem Skill eine Kopie, und eine in Desktop geänderte bleibt unverändert.",
|
||||
"Project servers": "Projektserver",
|
||||
"Project subagents": "Projekt-Subagenten",
|
||||
"Project plugins": "Projekt-Plugins",
|
||||
"Give a project a whole plugin: magpie writes each part where its agents read the project's own, and taking the plugin out takes out only what it wrote.": "Gib einem Projekt ein ganzes Plugin: magpie schreibt jeden Teil dorthin, wo seine Agents die eigenen Einstellungen des Projekts lesen, und nimmt beim Entfernen nur heraus, was es geschrieben hat.",
|
||||
"{name} added — pick the plugins it gets": "{name} hinzugefügt — wähle die Plugins, die es bekommt",
|
||||
"No Claude plugins yet": "Noch keine Claude-Plugins",
|
||||
"Hide its plugins": "Plugins ausblenden",
|
||||
"Pick the plugins it gets": "Wähle die Plugins, die es bekommt",
|
||||
"Its skills, servers and subagents go where the project's own do, and its hooks into .claude/settings.local.json and .codex/hooks.json. A file there that isn't magpie's, or an entry you changed, is left as it is.": "Skills, Server und Subagenten kommen dorthin, wo die eigenen des Projekts liegen, Hooks in .claude/settings.local.json und .codex/hooks.json. Eine Datei dort, die nicht von magpie ist, oder ein Eintrag, den du geändert hast, bleibt, wie er ist.",
|
||||
"Codex runs a project's hooks only in a project you trust, once you've reviewed them in /hooks.": "Codex führt die Hooks eines Projekts nur in einem Projekt aus, dem du vertraust, und erst, nachdem du sie in /hooks geprüft hast.",
|
||||
"Give a project's agents some of these subagents as the project's own: magpie writes them into its .claude/agents and the like, and keeps them out of git.": "Gib den Agenten eines Projekts einige dieser Subagenten als eigene: magpie schreibt sie in dessen .claude/agents und Ähnliches und hält sie aus git heraus.",
|
||||
"{name} added — pick the subagents it gets": "{name} hinzugefügt – wähle die Subagenten dafür",
|
||||
"No subagents yet": "Noch keine Subagenten",
|
||||
|
||||
@@ -938,6 +938,8 @@ func libraryRoutes(mux *http.ServeMux, w Windows) {
|
||||
res, err = library.ProjectSubagents(in.Dir, oneOrMore(in.Name, in.Names), in.Agents)
|
||||
case "projects/server":
|
||||
res, err = library.ProjectServer(in.Dir, in.Name, in.Agents)
|
||||
case "projects/plugin":
|
||||
res, err = library.ProjectPlugin(in.Dir, in.Name, in.Agents)
|
||||
case "projects/server-off":
|
||||
// a Library server turned off in this project only
|
||||
res, err = library.ProjectServerOff(in.Dir, in.Name, in.Agents)
|
||||
|
||||
@@ -0,0 +1,150 @@
|
||||
// Run with Node's test runner and Playwright on the module path; see README.md.
|
||||
// (jinpwng on X) The Claude plugins tab lists the projects: a card opens to
|
||||
// each library plugin with chips for the agents that take some part of a
|
||||
// plugin in a project (skills, servers, subagents or hooks), and a chip posts
|
||||
// that project's agents for the plugin to projects/plugin; no chip left takes
|
||||
// it out. An agent that takes none in a project has no chip, and the note on
|
||||
// Codex's /hooks review shows once Codex gets a plugin with hooks. The click
|
||||
// scrolls nothing; in English and Chinese. No backend: the API is faked here.
|
||||
const assert = require("node:assert/strict");
|
||||
const fs = require("node:fs/promises");
|
||||
const path = require("node:path");
|
||||
const { test } = require("node:test");
|
||||
const { chromium, webkit } = require("playwright");
|
||||
|
||||
const assets = path.resolve(__dirname, "../assets");
|
||||
const HOME = "/Users/emo";
|
||||
const DIR = HOME + "/code/app";
|
||||
const agent = (id, name, more = {}) => ({ id, name, icon: "", skills: `${HOME}/.${id}/skills`, mcp: `${HOME}/.${id}/mcp.json`, ...more });
|
||||
const plugin = (name, more) => ({ name, version: "1.0.0", description: "", agents: [], skills: [], mcp: [], hooks: [], subagents: [], ...more });
|
||||
const lib = (given) => ({
|
||||
dir: `${HOME}/.magpie/library`, backups: `${HOME}/.magpie/backups`, home: HOME,
|
||||
agents: [
|
||||
agent("claude", "Claude Code", { projectSkills: ".claude/skills", projectMCP: ".mcp.json", projectSubagents: ".claude/agents", projectHooks: ".claude/settings.local.json" }),
|
||||
agent("codex", "Codex", { projectMCP: ".codex/config.toml", projectSubagents: ".codex/agents", projectHooks: ".codex/hooks.json" }),
|
||||
agent("pi", "Pi", { projectSkills: ".agents/skills", projectMCP: ".pi/mcp.json" }),
|
||||
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"] })],
|
||||
projects: [{ dir: DIR, name: "app", copy: false, skills: {}, placed: [], servers: {}, subagents: {}, plugins: given, wrote: {} }],
|
||||
});
|
||||
|
||||
function server(lang, posts) {
|
||||
let given = {};
|
||||
return async (route) => {
|
||||
const req = route.request(), url = new URL(req.url());
|
||||
if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:true};` });
|
||||
if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
|
||||
if (url.pathname === "/api/state") return route.fulfill({ json: { agents: [], profiles: [], settings: { lang, theme: "light" } } });
|
||||
if (url.pathname === "/api/library") return route.fulfill({ json: lib(given) });
|
||||
if (url.pathname === "/api/library/projects/plugin") {
|
||||
const b = req.postDataJSON();
|
||||
posts.push(b);
|
||||
if (posts.hold) await posts.hold;
|
||||
given = { ...given, [b.name]: b.agents };
|
||||
if (!b.agents.length) delete given[b.name];
|
||||
return route.fulfill({ json: { ...lib(given), result: { changed: [], problems: [] } } });
|
||||
}
|
||||
if (url.pathname === "/api/plugins") return route.fulfill({ json: { plugins: [] } });
|
||||
if (url.pathname === "/api/usage/quotas") return route.fulfill({ json: [] });
|
||||
if (url.pathname === "/api/groups") return route.fulfill({ json: { groups: [] } });
|
||||
if (url.pathname === "/api/providers") return route.fulfill({ json: { providers: [], gateway: { running: true } } });
|
||||
if (url.pathname.startsWith("/api/")) return route.fulfill({ json: {} });
|
||||
const file = path.join(assets, url.pathname === "/" ? "index.html" : url.pathname);
|
||||
const contentType = { ".html": "text/html", ".js": "text/javascript", ".css": "text/css", ".svg": "image/svg+xml", ".png": "image/png" }[path.extname(file)];
|
||||
await route.fulfill({ body: await fs.readFile(file), contentType });
|
||||
};
|
||||
}
|
||||
|
||||
const scrolled = (page) => page.evaluate(() => [window.scrollX, window.scrollY, ...[...document.querySelectorAll("*")].filter((e) => e.scrollTop || e.scrollLeft).map((e) => `${e.className}:${e.scrollTop},${e.scrollLeft}`)].join(" "));
|
||||
// a click where the element is, as the reader's: Playwright's own click
|
||||
// first scrolls it into view
|
||||
const press = async (page, loc) => {
|
||||
const b = await loc.boundingBox();
|
||||
await page.mouse.click(b.x + b.width / 2, b.y + b.height / 2);
|
||||
};
|
||||
// a chip: the chips fan out under the pointer first, as a reader's hand
|
||||
// does, and the chip is pressed where it is then
|
||||
// (a render after the last write may replace it under the pointer, so it
|
||||
// is found again until it stays)
|
||||
const box = async (loc) => {
|
||||
for (;;) {
|
||||
await loc.waitFor({ state: "visible" });
|
||||
const b = await loc.boundingBox();
|
||||
if (b) return b;
|
||||
}
|
||||
};
|
||||
const chip = async (page, loc) => {
|
||||
const a = await box(loc);
|
||||
await page.mouse.move(a.x + a.width / 2, a.y + a.height / 2);
|
||||
await page.waitForTimeout(350);
|
||||
const b = await box(loc);
|
||||
await page.mouse.click(b.x + b.width / 2, b.y + b.height / 2);
|
||||
};
|
||||
|
||||
const words = {
|
||||
en: { head: "Project plugins", none: "No Claude plugins yet", one: "acme-kit is in app for Claude Code", on: "acme-kit is in app for Claude Code, Codex", out: "acme-kit is out of app", codex: "Codex runs a project's hooks only in a project you trust, once you've reviewed them in /hooks." },
|
||||
zh: { head: "项目插件", none: "还没有 Claude 插件", one: "acme-kit 已在 app 中对 Claude Code 开启", on: "acme-kit 已在 app 中对 Claude Code, Codex 开启", out: "acme-kit 已从 app 中移除", codex: "Codex 只在你信任的项目里运行项目的 hooks,并且要先在 /hooks 中审阅。" },
|
||||
};
|
||||
|
||||
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
||||
test(engine + ": a project's plugins, agent by agent", async (t) => {
|
||||
assert(["chromium", "webkit"].includes(engine), "BROWSER must be chromium or webkit");
|
||||
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
||||
const errors = [];
|
||||
t.after(async () => {
|
||||
if (errors.length) console.log(errors);
|
||||
await browser.close();
|
||||
});
|
||||
for (const lang of ["en", "zh"]) {
|
||||
await t.test(lang, async () => {
|
||||
const w = words[lang], posts = [];
|
||||
const ctx = await browser.newContext({ viewport: { width: 860, height: 700 } });
|
||||
await ctx.addInitScript(() => { try { localStorage.setItem("magpie.libTab", "plugins"); } catch {} });
|
||||
const page = await ctx.newPage();
|
||||
page.setDefaultTimeout(5000);
|
||||
page.setDefaultNavigationTimeout(60000);
|
||||
page.on("pageerror", (e) => errors.push(e.message));
|
||||
await page.route("**/*", server(lang, posts));
|
||||
await page.goto("http://magpie.test/");
|
||||
await page.locator('button[data-view="library"]').click();
|
||||
const card = page.locator("#view-library .lib-project");
|
||||
await card.waitFor();
|
||||
assert.equal((await card.locator(".lib-tags").textContent()).trim(), w.none);
|
||||
assert.ok((await page.locator("#view-library .row-head .label").allTextContents()).includes(w.head));
|
||||
|
||||
await card.locator(".lib-projhead").scrollIntoViewIfNeeded();
|
||||
const before = await scrolled(page);
|
||||
await press(page, card.locator(".lib-projhead"));
|
||||
const rows = card.locator(".lib-projplugin");
|
||||
await rows.first().waitFor();
|
||||
assert.equal(await rows.count(), 2);
|
||||
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);
|
||||
|
||||
await chip(page, row().locator('.lib-ag[data-agent="claude"]'));
|
||||
await page.waitForFunction(() => document.querySelectorAll('#view-library .lib-projplugin .lib-ag.on[data-agent="claude"]').length === 1);
|
||||
await page.waitForFunction((s) => document.querySelector("#status").textContent.trim() === s, w.one);
|
||||
await chip(page, row().locator('.lib-ag[data-agent="codex"]'));
|
||||
await page.waitForFunction(() => document.querySelectorAll('#view-library .lib-projplugin .lib-ag.on').length === 2);
|
||||
await page.waitForFunction((s) => document.querySelector("#status").textContent.trim() === s, w.on);
|
||||
assert.equal((await card.locator(".lib-projhooks-codex").textContent()).trim(), w.codex);
|
||||
// no chip left takes the plugin out of the project
|
||||
await chip(page, row().locator('.lib-ag[data-agent="claude"]'));
|
||||
await page.waitForFunction(() => document.querySelectorAll('#view-library .lib-projplugin .lib-ag.on').length === 1);
|
||||
await chip(page, row().locator('.lib-ag[data-agent="codex"]'));
|
||||
await page.waitForFunction(() => document.querySelectorAll('#view-library .lib-projplugin .lib-ag.on').length === 0);
|
||||
await page.waitForFunction((s) => document.querySelector("#status").textContent.trim() === s, w.out);
|
||||
assert.deepEqual(posts, [
|
||||
{ dir: DIR, name: "acme-kit", agents: ["claude"] }, { dir: DIR, name: "acme-kit", agents: ["claude", "codex"] },
|
||||
{ dir: DIR, name: "acme-kit", agents: ["codex"] }, { dir: DIR, name: "acme-kit", agents: [] },
|
||||
]);
|
||||
assert.equal(await scrolled(page), before, "the clicks scroll nothing");
|
||||
assert.deepEqual(errors, []);
|
||||
await ctx.close();
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
+100
-44
@@ -261,30 +261,44 @@ func hookSpecOf(t *Target) (*hookSpec, string) {
|
||||
return sp, why
|
||||
}
|
||||
|
||||
// claudeHookSpec is how Claude Code keeps hooks in a settings file at path:
|
||||
// its own settings.json, or a project's .claude/settings.local.json.
|
||||
func claudeHookSpec(path string) *hookSpec {
|
||||
return &hookSpec{
|
||||
path: path,
|
||||
events: map[string]string{"turn-end": "Stop", "after-tool": "PostToolUse", "before-tool": "PreToolUse",
|
||||
"prompt": "UserPromptSubmit", "session-start": "SessionStart"},
|
||||
native: claudeHookEvents,
|
||||
tools: map[string]string{"shell": "Bash", "edit": "Edit|Write|MultiEdit"},
|
||||
agent: "claude",
|
||||
}
|
||||
}
|
||||
|
||||
// codexHookSpec is how Codex keeps hooks in a hooks.json at path, whose
|
||||
// events are codex-rs/hooks' HookEventName's: the one beside its
|
||||
// config.toml, or a project's .codex/hooks.json.
|
||||
func codexHookSpec(path string) *hookSpec {
|
||||
return &hookSpec{
|
||||
path: path,
|
||||
events: map[string]string{"turn-end": "Stop", "after-tool": "PostToolUse", "before-tool": "PreToolUse",
|
||||
"prompt": "UserPromptSubmit", "session-start": "SessionStart"},
|
||||
native: []string{"PreToolUse", "PermissionRequest", "PostToolUse", "PreCompact", "PostCompact", "SessionStart", "SessionEnd",
|
||||
"UserPromptSubmit", "SubagentStart", "SubagentStop", "Stop", "Interrupt"},
|
||||
tools: map[string]string{"shell": "Bash", "edit": "apply_patch"},
|
||||
agent: "codex",
|
||||
}
|
||||
}
|
||||
|
||||
func hookSpecFor(t *Target) (*hookSpec, string) {
|
||||
if t.Agent.WSL != "" {
|
||||
return nil, wslNoHooks(t.Agent)
|
||||
}
|
||||
switch t.Agent.ID {
|
||||
case "claude":
|
||||
return &hookSpec{
|
||||
path: filepath.Join(claudeDir(), "settings.json"),
|
||||
events: map[string]string{"turn-end": "Stop", "after-tool": "PostToolUse", "before-tool": "PreToolUse",
|
||||
"prompt": "UserPromptSubmit", "session-start": "SessionStart"},
|
||||
native: claudeHookEvents,
|
||||
tools: map[string]string{"shell": "Bash", "edit": "Edit|Write|MultiEdit"},
|
||||
}, ""
|
||||
return claudeHookSpec(filepath.Join(claudeDir(), "settings.json")), ""
|
||||
case "codex":
|
||||
// codex-rs/hooks: hooks.json beside config.toml, whose events are
|
||||
// HookEventName's
|
||||
return &hookSpec{
|
||||
path: filepath.Join(codexDir(), "hooks.json"),
|
||||
events: map[string]string{"turn-end": "Stop", "after-tool": "PostToolUse", "before-tool": "PreToolUse",
|
||||
"prompt": "UserPromptSubmit", "session-start": "SessionStart"},
|
||||
native: []string{"PreToolUse", "PermissionRequest", "PostToolUse", "PreCompact", "PostCompact", "SessionStart", "SessionEnd",
|
||||
"UserPromptSubmit", "SubagentStart", "SubagentStop", "Stop", "Interrupt"},
|
||||
tools: map[string]string{"shell": "Bash", "edit": "apply_patch"},
|
||||
}, ""
|
||||
// codex-rs/hooks: hooks.json beside config.toml
|
||||
return codexHookSpec(filepath.Join(codexDir(), "hooks.json")), ""
|
||||
case "gemini":
|
||||
// gemini-cli packages/core/src/hooks/types.ts, HookEventName
|
||||
return &hookSpec{
|
||||
@@ -678,20 +692,66 @@ func (l *Library) syncHooks(t *Target, b *backups, res *Result) {
|
||||
}
|
||||
return
|
||||
}
|
||||
w := &hookWrite{id: id, sp: sp, want: want, recs: a.Hooks, gone: t.Gone,
|
||||
keep: func(path string) error { return b.keep(id, path) },
|
||||
fail: func(what string, err error) { res.fail(id, what, err) }}
|
||||
if id == "codex" {
|
||||
w.rekeyCfg = filepath.Join(codexDir(), "config.toml")
|
||||
}
|
||||
recs, changed, ok := w.run()
|
||||
if changed {
|
||||
res.changed(id)
|
||||
}
|
||||
if ok {
|
||||
a.Hooks = recs
|
||||
}
|
||||
}
|
||||
|
||||
// hookWrite is one agent's hooks file brought to what it should hold: the
|
||||
// entries of want written in, those of recs (what magpie wrote before) no
|
||||
// longer wanted taken out, and an entry the user changed or wrote
|
||||
// themselves left as it is. The agent's own file (syncHooks) and a
|
||||
// project's (project_plugins.go) are both brought up this way.
|
||||
type hookWrite struct {
|
||||
id string
|
||||
sp *hookSpec
|
||||
want []*Hook
|
||||
recs []HookEntry
|
||||
gone bool // the agent is gone from here: nothing new is written
|
||||
// keep backs a file up before it is written; nil writes it as it is
|
||||
keep func(path string) error
|
||||
// rekeyCfg is Codex's config.toml, whose trust of each hook moves
|
||||
// with the entries left after one taken out; "" for another agent
|
||||
rekeyCfg string
|
||||
fail func(what string, err error)
|
||||
}
|
||||
|
||||
// run writes the file, and says what magpie's records of it are now,
|
||||
// whether it was written, and false when they should stay as they were
|
||||
// (the file couldn't be read or written).
|
||||
func (w *hookWrite) run() (recs []HookEntry, changed, ok bool) {
|
||||
sp, want := w.sp, w.want
|
||||
failAll := func(err error) {
|
||||
for _, h := range want {
|
||||
res.fail(id, "hook:"+h.Name, err)
|
||||
w.fail("hook:"+h.Name, err)
|
||||
}
|
||||
if len(want) == 0 {
|
||||
res.fail(id, "hooks", err)
|
||||
w.fail("hooks", err)
|
||||
}
|
||||
}
|
||||
keep := func(path string) error {
|
||||
if w.keep == nil {
|
||||
return nil
|
||||
}
|
||||
return w.keep(path)
|
||||
}
|
||||
id, gone := w.id, w.gone
|
||||
var doc []byte
|
||||
if !sp.toml {
|
||||
d, err := readHooksFile(sp.path)
|
||||
if err != nil {
|
||||
failAll(err)
|
||||
return
|
||||
return nil, false, false
|
||||
}
|
||||
doc = d
|
||||
}
|
||||
@@ -725,11 +785,11 @@ func (l *Library) syncHooks(t *Target, b *backups, res *Result) {
|
||||
_, err = startMatcher(id, h.Matcher)
|
||||
}
|
||||
if err != nil {
|
||||
res.fail(id, "hook:"+h.Name, err)
|
||||
w.fail("hook:"+h.Name, err)
|
||||
continue
|
||||
}
|
||||
if _, err := listOf(ev); err != nil {
|
||||
res.fail(id, "hook:"+h.Name, err)
|
||||
w.fail("hook:"+h.Name, err)
|
||||
continue
|
||||
}
|
||||
ws = append(ws, &wanted{h: h, ev: ev, entry: sp.entry(h, ev)})
|
||||
@@ -753,9 +813,9 @@ func (l *Library) syncHooks(t *Target, b *backups, res *Result) {
|
||||
var kept []HookEntry
|
||||
drop := map[string][]int{} // event → the entries to take out
|
||||
var unread []HookEntry // records of an event whose list can't be read now
|
||||
for _, rec := range a.Hooks {
|
||||
for _, rec := range w.recs {
|
||||
if _, err := listOf(rec.Event); err != nil {
|
||||
res.fail(id, "hook:"+rec.Name, err)
|
||||
w.fail("hook:"+rec.Name, err)
|
||||
unread = append(unread, rec)
|
||||
continue
|
||||
}
|
||||
@@ -778,7 +838,7 @@ func (l *Library) syncHooks(t *Target, b *backups, res *Result) {
|
||||
for _, w := range ws {
|
||||
// an agent gone from here is given nothing new; what it has stays
|
||||
// its until unticked
|
||||
if w.done || t.Gone {
|
||||
if w.done || gone {
|
||||
continue
|
||||
}
|
||||
// the same entry of the user's own already runs: it isn't written
|
||||
@@ -790,13 +850,12 @@ func (l *Library) syncHooks(t *Target, b *backups, res *Result) {
|
||||
added = append(added, HookEntry{Name: w.h.Name, Event: w.ev, Entry: w.entry})
|
||||
}
|
||||
if len(drop) == 0 && len(add) == 0 {
|
||||
a.Hooks = append(kept, unread...)
|
||||
return
|
||||
return append(kept, unread...), false, true
|
||||
}
|
||||
if sp.toml {
|
||||
if err := b.keep(id, sp.path); err != nil {
|
||||
if err := keep(sp.path); err != nil {
|
||||
failAll(err)
|
||||
return
|
||||
return nil, false, false
|
||||
}
|
||||
err := os.MkdirAll(filepath.Dir(sp.path), 0o755)
|
||||
if err == nil {
|
||||
@@ -820,11 +879,9 @@ func (l *Library) syncHooks(t *Target, b *backups, res *Result) {
|
||||
}
|
||||
if err != nil {
|
||||
failAll(fmt.Errorf("%s: %w", sp.path, err))
|
||||
return
|
||||
return nil, false, false
|
||||
}
|
||||
res.changed(id)
|
||||
a.Hooks = append(append(kept, added...), unread...)
|
||||
return
|
||||
return append(append(kept, added...), unread...), true, true
|
||||
}
|
||||
// what each list becomes, and where each entry left in it moves to
|
||||
var set []edit.KV
|
||||
@@ -864,26 +921,26 @@ func (l *Library) syncHooks(t *Target, b *backups, res *Result) {
|
||||
set = append(set, edit.KV{Path: "hooks." + ev, Value: next})
|
||||
}
|
||||
}
|
||||
if err := b.keep(id, sp.path); err != nil {
|
||||
if err := keep(sp.path); err != nil {
|
||||
failAll(err)
|
||||
return
|
||||
return nil, false, false
|
||||
}
|
||||
// Codex trusts a hook by where it is (codex-rs/hooks: hook_key, the
|
||||
// file's path, the event, the group's and the handler's index): an
|
||||
// entry taken out from before the user's own would leave their trust
|
||||
// on the wrong ones, so it is moved with them
|
||||
var rekey func() error
|
||||
if id == "codex" && len(drop) > 0 {
|
||||
cfg := filepath.Join(codexDir(), "config.toml")
|
||||
if w.rekeyCfg != "" && len(drop) > 0 {
|
||||
cfg := w.rekeyCfg
|
||||
f, err := codexRekey(cfg, sp.path, moved)
|
||||
if err != nil {
|
||||
failAll(err)
|
||||
return
|
||||
return nil, false, false
|
||||
}
|
||||
if f != nil {
|
||||
if err := b.keep(id, cfg); err != nil {
|
||||
if err := keep(cfg); err != nil {
|
||||
failAll(err)
|
||||
return
|
||||
return nil, false, false
|
||||
}
|
||||
rekey = f
|
||||
}
|
||||
@@ -912,15 +969,14 @@ func (l *Library) syncHooks(t *Target, b *backups, res *Result) {
|
||||
}
|
||||
if err != nil {
|
||||
failAll(fmt.Errorf("%s: %w", sp.path, err))
|
||||
return
|
||||
return nil, false, false
|
||||
}
|
||||
res.changed(id)
|
||||
if rekey != nil {
|
||||
if err := rekey(); err != nil {
|
||||
res.fail(id, "hooks", fmt.Errorf("the hooks are written, but Codex's trust of the ones after them couldn't be moved: review them in Codex's /hooks (%w)", err))
|
||||
w.fail("hooks", fmt.Errorf("the hooks are written, but Codex's trust of the ones after them couldn't be moved: review them in Codex's /hooks (%w)", err))
|
||||
}
|
||||
}
|
||||
a.Hooks = append(append(kept, added...), unread...)
|
||||
return append(append(kept, added...), unread...), true, true
|
||||
}
|
||||
|
||||
// codexState is a [hooks.state."<key>"] header line in Codex's config.toml.
|
||||
|
||||
@@ -226,16 +226,20 @@ func hubServers(agentID string) []*Server {
|
||||
func (l *Library) hubServers(agentID string) []*Server {
|
||||
id, key, scoped := strings.Cut(agentID, gateway.HubProjectSep)
|
||||
var p *Project
|
||||
var given map[string][]string // the project's servers, its plugins' too
|
||||
if scoped {
|
||||
p = l.projectByKey(key)
|
||||
}
|
||||
if p != nil {
|
||||
_, given, _ = l.withPlugins(p)
|
||||
}
|
||||
var out []*Server
|
||||
for _, s := range l.MCP {
|
||||
on := id == "" && !s.Hidden || slices.Contains(s.Agents, id)
|
||||
if p != nil {
|
||||
if slices.Contains(p.ServersOff[s.Name], id) {
|
||||
on = false
|
||||
} else if !s.Hidden && slices.Contains(p.Servers[s.Name], id) {
|
||||
} else if !s.Hidden && slices.Contains(given[s.Name], id) {
|
||||
on = true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1225,6 +1225,7 @@ func RemovePlugin(name string) (*Result, error) {
|
||||
return fmt.Errorf("no plugin called %s", name)
|
||||
}
|
||||
removePluginParts(l, b)
|
||||
l.dropProjectPlugin(name)
|
||||
l.Plugins = slices.DeleteFunc(l.Plugins, func(x *Plugin) bool { return x.Name == name })
|
||||
return nil
|
||||
})
|
||||
|
||||
@@ -0,0 +1,262 @@
|
||||
package library
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"sort"
|
||||
)
|
||||
|
||||
// A project's plugins (jinpwng on X): a plugin the library keeps is given
|
||||
// to a project whole, for some of its agents, and taken out of it whole.
|
||||
// Its skills, MCP servers and subagents go where the project's own do
|
||||
// (projects.go, project_mcp.go, project_subagents.go), beside them: for
|
||||
// a sync, syncProject adds them to the project's own sets (withPlugins),
|
||||
// and puts those back as they were after. So a part the project also has
|
||||
// of its own stays when the plugin goes, and taking the plugin out is
|
||||
// only deleting it from Plugins: what magpie placed or wrote for it,
|
||||
// and nothing else, comes out on that sync, by the records each part
|
||||
// keeps already (Placed, Wrote, AgentFiles). Its hooks are written in the
|
||||
// project's own hooks file (projectHookFiles), entry by entry, as the
|
||||
// agent's own are (hookWrite): an entry the user changed since is theirs
|
||||
// and stays.
|
||||
|
||||
// projectHookFiles are the files, in a project, an agent reads hooks
|
||||
// from that magpie writes a project's plugins' hooks into: Claude Code's
|
||||
// .claude/settings.local.json (its local project settings, which it
|
||||
// keeps out of git itself), and Codex's .codex/hooks.json, which
|
||||
// codex-rs/hooks loads from a project's .codex folder in a project the
|
||||
// user trusts, each hook in it once the user has reviewed it in /hooks.
|
||||
var projectHookFiles = map[string]string{
|
||||
"claude": claudeSettingsRel,
|
||||
"codex": ".codex/hooks.json",
|
||||
}
|
||||
|
||||
// ProjectHooksFile is the file in a project an agent reads hooks from:
|
||||
// "" for one magpie can't give a project's hooks to.
|
||||
func ProjectHooksFile(agent string) string { return projectHookFiles[agent] }
|
||||
|
||||
// projectPluginTakes says whether an agent takes any part of a plugin in
|
||||
// a project.
|
||||
func projectPluginTakes(id string) bool {
|
||||
return ProjectSkillsDir(id) != "" || ProjectMCPFile(id) != "" || ProjectSubagentsDir(id) != "" || ProjectHooksFile(id) != ""
|
||||
}
|
||||
|
||||
func projectHookSpec(p *Project, id string) *hookSpec {
|
||||
rel := projectHookFiles[id]
|
||||
abs := filepath.Join(p.Dir, filepath.FromSlash(rel))
|
||||
switch id {
|
||||
case "claude":
|
||||
return claudeHookSpec(abs)
|
||||
case "codex":
|
||||
return codexHookSpec(abs)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// withPlugins are the project's skills, servers and subagents with the
|
||||
// parts of its plugins added, each for those of the plugin's agents that
|
||||
// take it in a project: new maps, the project's own left as they are. A
|
||||
// plugin turned off, or gone from the library, gives nothing; a part
|
||||
// taken out of the library one by one, or one that is another's by now,
|
||||
// isn't the plugin's.
|
||||
func (l *Library) withPlugins(p *Project) (skills, servers, subagents map[string][]string) {
|
||||
if len(p.Plugins) == 0 {
|
||||
return p.Skills, p.Servers, p.Subagents
|
||||
}
|
||||
clone := func(m map[string][]string) map[string][]string {
|
||||
out := make(map[string][]string, len(m))
|
||||
for k, v := range m {
|
||||
out[k] = slices.Clone(v)
|
||||
}
|
||||
return out
|
||||
}
|
||||
skills, servers, subagents = clone(p.Skills), clone(p.Servers), clone(p.Subagents)
|
||||
add := func(m map[string][]string, name string, agents []string, takes func(string) bool) {
|
||||
for _, a := range agents {
|
||||
if takes(a) {
|
||||
m[name] = set(m[name], a, true)
|
||||
}
|
||||
}
|
||||
}
|
||||
for name, agents := range p.Plugins {
|
||||
b := l.plugin(name)
|
||||
if b == nil || b.Off {
|
||||
continue
|
||||
}
|
||||
for _, n := range b.Skills {
|
||||
if s := l.skill(n); s != nil && s.Bundle == b.Name {
|
||||
add(skills, n, agents, func(a string) bool { return ProjectSkillsDir(a) != "" })
|
||||
}
|
||||
}
|
||||
for _, n := range b.MCP {
|
||||
if s := l.server(n); s != nil && s.Bundle == b.Name {
|
||||
add(servers, n, agents, func(a string) bool { return ProjectMCPFile(a) != "" })
|
||||
}
|
||||
}
|
||||
for _, n := range b.Subagents {
|
||||
if s := l.subagent(n); s != nil && s.Bundle == b.Name {
|
||||
add(subagents, n, agents, func(a string) bool { return ProjectSubagentsDir(a) != "" })
|
||||
}
|
||||
}
|
||||
}
|
||||
return skills, servers, subagents
|
||||
}
|
||||
|
||||
// projectHooks are, by agent, the hooks the project's plugins give it.
|
||||
func (l *Library) projectHooks(p *Project) map[string][]*Hook {
|
||||
out := map[string][]*Hook{}
|
||||
for _, name := range slices.Sorted(func(yield func(string) bool) {
|
||||
for k := range p.Plugins {
|
||||
if !yield(k) {
|
||||
return
|
||||
}
|
||||
}
|
||||
}) {
|
||||
b := l.plugin(name)
|
||||
if b == nil || b.Off {
|
||||
continue
|
||||
}
|
||||
for _, n := range b.Hooks {
|
||||
h := l.hook(n)
|
||||
if h == nil || h.Bundle != b.Name {
|
||||
continue
|
||||
}
|
||||
for _, a := range p.Plugins[name] {
|
||||
if ProjectHooksFile(a) != "" && hookTakes(h, a) && !slices.Contains(out[a], h) {
|
||||
out[a] = append(out[a], h)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// syncProjectHooks writes the hooks of the project's plugins in each
|
||||
// agent's project hooks file, and takes out those magpie wrote there that
|
||||
// no plugin gives any more. A file magpie made is taken away again once
|
||||
// nothing is left in it.
|
||||
func (l *Library) syncProjectHooks(p *Project, fail func(what string, err error)) {
|
||||
want := l.projectHooks(p)
|
||||
ids := map[string]bool{}
|
||||
for id := range want {
|
||||
ids[id] = true
|
||||
}
|
||||
for id := range p.HookRecs {
|
||||
ids[id] = true
|
||||
}
|
||||
for _, id := range slices.Sorted(func(yield func(string) bool) {
|
||||
for k := range ids {
|
||||
if !yield(k) {
|
||||
return
|
||||
}
|
||||
}
|
||||
}) {
|
||||
rel := projectHookFiles[id]
|
||||
sp := projectHookSpec(p, id)
|
||||
if sp == nil {
|
||||
// an agent magpie wrote hooks for once and no longer can:
|
||||
// its records go, the entries stay the user's
|
||||
delete(p.HookRecs, id)
|
||||
continue
|
||||
}
|
||||
if err := p.inside(sp.path); err != nil {
|
||||
for _, h := range want[id] {
|
||||
fail("hook:"+h.Name, err)
|
||||
}
|
||||
continue
|
||||
}
|
||||
made := false
|
||||
if len(want[id]) > 0 && !exists(sp.path) {
|
||||
if err := p.mkdirs(filepath.Dir(sp.path)); err != nil {
|
||||
for _, h := range want[id] {
|
||||
fail("hook:"+h.Name, err)
|
||||
}
|
||||
continue
|
||||
}
|
||||
made = true
|
||||
}
|
||||
w := &hookWrite{id: id, sp: sp, want: want[id], recs: p.HookRecs[id], fail: fail}
|
||||
if id == "codex" {
|
||||
w.rekeyCfg = filepath.Join(codexDir(), "config.toml")
|
||||
}
|
||||
recs, _, ok := w.run()
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
if made && exists(sp.path) && !slices.Contains(p.MadeFiles, rel) {
|
||||
p.MadeFiles = append(p.MadeFiles, rel)
|
||||
sort.Strings(p.MadeFiles)
|
||||
}
|
||||
if len(recs) == 0 {
|
||||
delete(p.HookRecs, id)
|
||||
// Claude Code's file holds the skills the project turns off
|
||||
// too (syncSkillsOff)
|
||||
if id != "claude" || len(p.Overrides) == 0 {
|
||||
p.dropMadeFile(rel)
|
||||
}
|
||||
continue
|
||||
}
|
||||
if p.HookRecs == nil {
|
||||
p.HookRecs = map[string][]HookEntry{}
|
||||
}
|
||||
p.HookRecs[id] = recs
|
||||
}
|
||||
if len(p.HookRecs) == 0 {
|
||||
p.HookRecs = nil
|
||||
}
|
||||
}
|
||||
|
||||
// ProjectPlugin sets which agents get a library plugin in a project: each
|
||||
// of its parts goes to those of them that take it there. None takes the
|
||||
// plugin out of the project, and with it only what magpie wrote for it.
|
||||
func ProjectPlugin(dir, name string, agents []string) (*Result, error) {
|
||||
for _, a := range agents {
|
||||
if err := checkAgent(a); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return change(func(l *Library) error {
|
||||
p := l.project(dir)
|
||||
if p == nil {
|
||||
return fmt.Errorf("no project %s", dir)
|
||||
}
|
||||
if name == "" {
|
||||
return errors.New("no plugin given")
|
||||
}
|
||||
var ids []string
|
||||
for _, id := range agents {
|
||||
if !projectPluginTakes(id) {
|
||||
return fmt.Errorf("magpie knows of nowhere %s reads a project's skills, servers, subagents or hooks from", id)
|
||||
}
|
||||
ids = set(ids, id, true)
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
delete(p.Plugins, name)
|
||||
if len(p.Plugins) == 0 {
|
||||
p.Plugins = nil
|
||||
}
|
||||
return nil
|
||||
}
|
||||
if l.plugin(name) == nil {
|
||||
return fmt.Errorf("no plugin called %s", name)
|
||||
}
|
||||
if p.Plugins == nil {
|
||||
p.Plugins = map[string][]string{}
|
||||
}
|
||||
p.Plugins[name] = ids
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
// dropProjectPlugin takes a plugin out of every project, and their
|
||||
// worktrees: it is leaving the library.
|
||||
func (l *Library) dropProjectPlugin(name string) {
|
||||
for _, p := range l.Projects {
|
||||
delete(p.Plugins, name)
|
||||
if len(p.Plugins) == 0 {
|
||||
p.Plugins = nil
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,207 @@
|
||||
package library
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// pluginProjects is a sandbox with the acme-kit plugin in the library,
|
||||
// given to no agent user-wide, and two projects.
|
||||
func pluginProjects(t *testing.T) (h, a, b string) {
|
||||
t.Helper()
|
||||
h = sandbox(t)
|
||||
pluginAgents(t, h)
|
||||
src := filepath.Join(t.TempDir(), "acme")
|
||||
writePlugin(t, src)
|
||||
ok(t)(InstallPlugins(src, nil, []string{}))
|
||||
a, b = filepath.Join(t.TempDir(), "a"), filepath.Join(t.TempDir(), "b")
|
||||
for _, d := range []string{a, b} {
|
||||
gitInit(t, d)
|
||||
ok(t)(AddProject(d))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func there(t *testing.T, path string) {
|
||||
t.Helper()
|
||||
if _, err := os.Lstat(path); err != nil {
|
||||
t.Errorf("%s: %v", path, err)
|
||||
}
|
||||
}
|
||||
|
||||
// A plugin given to a project (jinpwng on X) puts each of its parts where
|
||||
// each agent reads a project's own, in that agent's shape, and nowhere
|
||||
// else; taken out, all of it comes out again, the files magpie made too.
|
||||
func TestProjectPluginEachPartInTheProject(t *testing.T) {
|
||||
h, a, b := pluginProjects(t)
|
||||
res := ok(t)(ProjectPlugin(a, "acme-kit", []string{"claude", "codex", "pi"}))
|
||||
if len(res.Problems) > 0 {
|
||||
t.Fatalf("problems: %+v", res.Problems)
|
||||
}
|
||||
for _, rel := range []string{".claude/skills/tdd", ".agents/skills/tdd", ".claude/agents/reviewer.md", ".codex/agents/reviewer.toml"} {
|
||||
there(t, filepath.Join(a, rel))
|
||||
}
|
||||
for _, rel := range []string{".mcp.json", ".codex/config.toml", ".pi/mcp.json"} {
|
||||
if got := read(t, filepath.Join(a, rel)); !strings.Contains(got, "acme-db") {
|
||||
t.Errorf("%s lacks the plugin's server:\n%s", rel, got)
|
||||
}
|
||||
}
|
||||
claude := read(t, filepath.Join(a, ".claude/settings.local.json"))
|
||||
for _, want := range []string{"echo done", "lint.sh", "compacting", `"Bash"`} {
|
||||
if !strings.Contains(claude, want) {
|
||||
t.Errorf(".claude/settings.local.json lacks %q:\n%s", want, claude)
|
||||
}
|
||||
}
|
||||
codex := read(t, filepath.Join(a, ".codex/hooks.json"))
|
||||
if !strings.Contains(codex, "echo done") || !strings.Contains(codex, "lint.sh") {
|
||||
t.Errorf(".codex/hooks.json lacks the plugin's hooks:\n%s", codex)
|
||||
}
|
||||
if strings.Contains(codex, "compacting") {
|
||||
t.Errorf("codex was given Claude Code's own event:\n%s", codex)
|
||||
}
|
||||
// nothing user-wide, nothing in the other project
|
||||
if got := read(t, filepath.Join(h, ".claude/settings.json")); strings.Contains(got, "echo done") {
|
||||
t.Errorf("the user-wide settings got the plugin's hooks:\n%s", got)
|
||||
}
|
||||
for _, p := range []string{filepath.Join(h, ".claude/skills/tdd"), filepath.Join(h, ".codex/hooks.json"), filepath.Join(h, ".claude/agents/reviewer.md")} {
|
||||
gone(t, p)
|
||||
}
|
||||
for _, rel := range []string{".claude", ".codex", ".agents", ".pi", ".mcp.json"} {
|
||||
gone(t, filepath.Join(b, rel))
|
||||
}
|
||||
// kept out of git
|
||||
g, _ := gitOf(a)
|
||||
ex := read(t, filepath.Join(g.Common, "info", "exclude"))
|
||||
for _, rel := range []string{".codex/hooks.json", ".mcp.json", ".claude/skills/tdd"} {
|
||||
if !strings.Contains(ex, "/"+rel+"\n") {
|
||||
t.Errorf("%s isn't in info/exclude:\n%s", rel, ex)
|
||||
}
|
||||
}
|
||||
v := View0(t)
|
||||
if len(v.Projects) != 2 || len(v.Projects[0].Plugins["acme-kit"])+len(v.Projects[1].Plugins["acme-kit"]) != 3 {
|
||||
t.Errorf("the page's projects: %+v", v.Projects)
|
||||
}
|
||||
|
||||
res = ok(t)(ProjectPlugin(a, "acme-kit", nil))
|
||||
if len(res.Problems) > 0 {
|
||||
t.Fatalf("problems taking it out: %+v", res.Problems)
|
||||
}
|
||||
for _, rel := range []string{".claude", ".codex", ".agents", ".pi", ".mcp.json"} {
|
||||
gone(t, filepath.Join(a, rel))
|
||||
}
|
||||
}
|
||||
|
||||
// Taking a plugin out of a project takes out only what magpie wrote for
|
||||
// it: the user's own entries and files in the same files stay, one of the
|
||||
// plugin's the user edited since stays as they left it, and a skill the
|
||||
// project has of its own stays though the plugin had it too.
|
||||
func TestProjectPluginWithdrawLeavesTheUsers(t *testing.T) {
|
||||
_, a, _ := pluginProjects(t)
|
||||
write(t, filepath.Join(a, ".claude/settings.local.json"), `{
|
||||
// mine
|
||||
"permissions": {"allow": ["Bash(ls)"]},
|
||||
"hooks": {"Stop": [{"hooks": [{"type": "command", "command": "echo mine"}]}]}
|
||||
}
|
||||
`)
|
||||
write(t, filepath.Join(a, ".mcp.json"), `{"mcpServers":{"mine":{"command":"mine"}}}`)
|
||||
ok(t)(ProjectSkill(a, "tdd", []string{"claude"}))
|
||||
ok(t)(ProjectPlugin(a, "acme-kit", []string{"claude", "codex"}))
|
||||
settings := filepath.Join(a, ".claude/settings.local.json")
|
||||
got := read(t, settings)
|
||||
if !strings.Contains(got, "echo mine") || !strings.Contains(got, "echo done") {
|
||||
t.Fatalf("settings.local.json:\n%s", got)
|
||||
}
|
||||
// the user edits one of the plugin's hooks, and its subagent
|
||||
write(t, settings, strings.Replace(got, `"echo done"`, `"echo done && say hi"`, 1))
|
||||
rev := filepath.Join(a, ".claude/agents/reviewer.md")
|
||||
write(t, rev, read(t, rev)+"\nAlso check the tests.\n")
|
||||
|
||||
res := ok(t)(ProjectPlugin(a, "acme-kit", []string{}))
|
||||
if len(res.Problems) > 0 {
|
||||
t.Fatalf("problems: %+v", res.Problems)
|
||||
}
|
||||
got = read(t, settings)
|
||||
for _, want := range []string{"// mine", "Bash(ls)", "echo mine", "echo done && say hi"} {
|
||||
if !strings.Contains(got, want) {
|
||||
t.Errorf("settings.local.json lost %q:\n%s", want, got)
|
||||
}
|
||||
}
|
||||
if strings.Contains(got, "lint.sh") || strings.Contains(got, "compacting") {
|
||||
t.Errorf("the plugin's other hooks stayed:\n%s", got)
|
||||
}
|
||||
if !strings.Contains(read(t, rev), "Also check the tests.") {
|
||||
t.Error("the edited subagent was taken away")
|
||||
}
|
||||
there(t, filepath.Join(a, ".claude/skills/tdd"))
|
||||
gone(t, filepath.Join(a, ".agents/skills/tdd"))
|
||||
gone(t, filepath.Join(a, ".codex/agents/reviewer.toml"))
|
||||
gone(t, filepath.Join(a, ".codex/hooks.json"))
|
||||
mcp := read(t, filepath.Join(a, ".mcp.json"))
|
||||
if !strings.Contains(mcp, `"mine"`) || strings.Contains(mcp, "acme-db") {
|
||||
t.Errorf(".mcp.json:\n%s", mcp)
|
||||
}
|
||||
// nothing left of magpie's records of the hooks
|
||||
l := loadT(t)
|
||||
if p := l.project(a); p == nil || len(p.HookRecs) > 0 || len(p.Plugins) > 0 {
|
||||
t.Errorf("records left: %+v", p)
|
||||
}
|
||||
}
|
||||
|
||||
// A plugin turned off gives a project nothing while it is off, and one
|
||||
// removed from the library leaves every project it was in.
|
||||
func TestProjectPluginFollowsTheLibrary(t *testing.T) {
|
||||
_, a, _ := pluginProjects(t)
|
||||
ok(t)(ProjectPlugin(a, "acme-kit", []string{"claude"}))
|
||||
there(t, filepath.Join(a, ".claude/settings.local.json"))
|
||||
ok(t)(PluginOn("acme-kit", false))
|
||||
for _, rel := range []string{".claude", ".mcp.json"} {
|
||||
gone(t, filepath.Join(a, rel))
|
||||
}
|
||||
ok(t)(PluginOn("acme-kit", true))
|
||||
there(t, filepath.Join(a, ".claude/skills/tdd"))
|
||||
there(t, filepath.Join(a, ".claude/settings.local.json"))
|
||||
ok(t)(RemovePlugin("acme-kit"))
|
||||
for _, rel := range []string{".claude", ".mcp.json"} {
|
||||
gone(t, filepath.Join(a, rel))
|
||||
}
|
||||
if p := loadT(t).project(a); p == nil || len(p.Plugins) > 0 {
|
||||
t.Errorf("the project still has it: %+v", p)
|
||||
}
|
||||
}
|
||||
|
||||
// Codex reads a project's hooks only from its own .codex/hooks.json, and
|
||||
// trusts each by where it is: an entry of the plugin's taken out from
|
||||
// before one of the user's moves the user's trust with it.
|
||||
func TestProjectPluginCodexTrustFollows(t *testing.T) {
|
||||
h, a, _ := pluginProjects(t)
|
||||
ok(t)(ProjectPlugin(a, "acme-kit", []string{"codex"}))
|
||||
hooks := filepath.Join(a, ".codex/hooks.json")
|
||||
got := read(t, hooks)
|
||||
// the user adds a Stop hook of their own after the plugin's, and
|
||||
// trusts it
|
||||
got = strings.Replace(got, `"command": "echo done"`, `"command": "echo done"}]},{"hooks":[{"type":"command","command":"echo mine"`, 1)
|
||||
if !strings.Contains(got, "echo mine") {
|
||||
t.Fatalf("couldn't add the user's hook:\n%s", read(t, hooks))
|
||||
}
|
||||
write(t, hooks, got)
|
||||
cfg := filepath.Join(h, ".codex/config.toml")
|
||||
write(t, cfg, "[hooks.state.\""+hooks+":stop:1:0\"]\ntrusted_hash = \"sha256:x\"\n")
|
||||
ok(t)(ProjectPlugin(a, "acme-kit", nil))
|
||||
if got := read(t, hooks); !strings.Contains(got, "echo mine") || strings.Contains(got, "echo done") {
|
||||
t.Errorf("hooks.json:\n%s", got)
|
||||
}
|
||||
if got := read(t, cfg); !strings.Contains(got, hooks+":stop:0:0") {
|
||||
t.Errorf("the user's trust didn't move with their hook:\n%s", got)
|
||||
}
|
||||
}
|
||||
|
||||
func loadT(t *testing.T) *Library {
|
||||
t.Helper()
|
||||
l, err := load()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return l
|
||||
}
|
||||
@@ -414,7 +414,8 @@ func (l *Library) syncSkillsOff(p *Project, fail func(what string, err error)) {
|
||||
}
|
||||
sort.Strings(mine)
|
||||
p.Overrides = mine
|
||||
if len(mine) == 0 {
|
||||
// the file holds the project's plugins' hooks too (project_plugins.go)
|
||||
if len(mine) == 0 && len(p.HookRecs["claude"]) == 0 {
|
||||
p.dropMadeFile(claudeSettingsRel)
|
||||
}
|
||||
}
|
||||
@@ -460,7 +461,7 @@ func (l *Library) syncTrees(p *Project, res *Result, hubs map[string]*Server) {
|
||||
t = &Project{Dir: d}
|
||||
}
|
||||
t.Copy, t.Skills, t.Servers, t.ServersOff, t.SkillsOff, t.Subagents = p.Copy, p.Skills, p.Servers, p.ServersOff, p.SkillsOff, p.Subagents
|
||||
t.Instr, t.InstrAgents = p.Instr, p.InstrAgents
|
||||
t.Instr, t.InstrAgents, t.Plugins = p.Instr, p.InstrAgents, p.Plugins
|
||||
l.syncFolder(t, res, hubs)
|
||||
trees = append(trees, t)
|
||||
}
|
||||
@@ -474,7 +475,7 @@ func (l *Library) syncTrees(p *Project, res *Result, hubs map[string]*Server) {
|
||||
// no longer one of the repository's worktrees, or no longer the
|
||||
// project's: what magpie put there comes out
|
||||
t.Skills, t.Servers, t.ServersOff, t.SkillsOff, t.Subagents = nil, nil, nil, nil, nil
|
||||
t.Instr, t.InstrAgents = "", nil
|
||||
t.Instr, t.InstrAgents, t.Plugins = "", nil, nil
|
||||
l.syncFolder(t, res, nil)
|
||||
if t.holds() {
|
||||
trees = append(trees, t)
|
||||
@@ -497,7 +498,7 @@ func (p *Project) tree(dir string) *Project {
|
||||
|
||||
// holds says whether magpie has anything of its own in the folder still.
|
||||
func (p *Project) holds() bool {
|
||||
return len(p.Placed) > 0 || len(p.Wrote) > 0 || len(p.CodexOff) > 0 || len(p.Overrides) > 0 || len(p.MadeFiles) > 0 || len(p.AgentFiles) > 0 || len(p.InstrFiles) > 0
|
||||
return len(p.Placed) > 0 || len(p.Wrote) > 0 || len(p.CodexOff) > 0 || len(p.Overrides) > 0 || len(p.MadeFiles) > 0 || len(p.AgentFiles) > 0 || len(p.InstrFiles) > 0 || len(p.HookRecs) > 0
|
||||
}
|
||||
|
||||
// ignored are the files and folders of the project magpie put there, which
|
||||
@@ -532,7 +533,7 @@ func (l *Library) treesChanged() bool {
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(p.Skills)+len(p.Servers)+len(p.ServersOff)+len(p.SkillsOff)+len(p.Subagents)+len(p.InstrAgents) == 0 && len(p.Trees) == 0 {
|
||||
if len(p.Skills)+len(p.Servers)+len(p.ServersOff)+len(p.SkillsOff)+len(p.Subagents)+len(p.InstrAgents)+len(p.Plugins) == 0 && len(p.Trees) == 0 {
|
||||
continue
|
||||
}
|
||||
dirs := p.treeDirs()
|
||||
|
||||
@@ -71,6 +71,12 @@ type Project struct {
|
||||
Instr string `json:"instr,omitempty"`
|
||||
InstrAgents []string `json:"instrAgents,omitempty"`
|
||||
InstrFiles []InstrFile `json:"instrFiles,omitempty"`
|
||||
// Plugins are the library's plugins the project has, and for which
|
||||
// agents: each part goes to those of them that take it in a project,
|
||||
// beside the project's own (project_plugins.go). HookRecs are, by
|
||||
// agent, the hook entries magpie wrote in the project's file for them
|
||||
Plugins map[string][]string `json:"plugins,omitempty"`
|
||||
HookRecs map[string][]HookEntry `json:"hookRecs,omitempty"`
|
||||
}
|
||||
|
||||
// projectSkillsDirs is where, in a project, each agent reads skills of its
|
||||
@@ -145,11 +151,16 @@ func (l *Library) syncProjects(res *Result) {
|
||||
|
||||
func (l *Library) syncProject(p *Project, res *Result) {
|
||||
if fi, err := os.Stat(p.Dir); err != nil || !fi.IsDir() {
|
||||
if len(p.Skills) > 0 || len(p.Servers) > 0 || len(p.Subagents) > 0 || len(p.ServersOff) > 0 || len(p.SkillsOff) > 0 || p.Instr != "" && len(p.InstrAgents) > 0 || p.holds() {
|
||||
if len(p.Skills) > 0 || len(p.Servers) > 0 || len(p.Subagents) > 0 || len(p.Plugins) > 0 || len(p.ServersOff) > 0 || len(p.SkillsOff) > 0 || p.Instr != "" && len(p.InstrAgents) > 0 || p.holds() {
|
||||
res.Problems = append(res.Problems, Problem{Agent: p.Dir, What: "project:", Error: "the folder is gone"})
|
||||
}
|
||||
return
|
||||
}
|
||||
// the parts of its plugins are given as its own are, for this sync:
|
||||
// what it has of its own is kept as it was
|
||||
own := [3]map[string][]string{p.Skills, p.Servers, p.Subagents}
|
||||
p.Skills, p.Servers, p.Subagents = l.withPlugins(p)
|
||||
defer func() { p.Skills, p.Servers, p.Subagents = own[0], own[1], own[2] }()
|
||||
hubs := l.projectHubs(p)
|
||||
l.syncFolder(p, res, hubs)
|
||||
l.syncClaudeLocal(p, hubs["claude"], func(what string, err error) {
|
||||
@@ -234,6 +245,7 @@ func (l *Library) syncFolder(p *Project, res *Result, hubs map[string]*Server) {
|
||||
l.syncSkillsOff(p, fail)
|
||||
l.syncProjectSubagents(p, func(what string, err error) { fail(what, err) })
|
||||
l.syncProjectInstr(p, fail)
|
||||
l.syncProjectHooks(p, fail)
|
||||
p.tidy()
|
||||
}
|
||||
|
||||
@@ -533,7 +545,7 @@ func RemoveProject(dir string, keep bool) (*Result, error) {
|
||||
l.Projects = slices.DeleteFunc(l.Projects, func(x *Project) bool { return x == p })
|
||||
return nil
|
||||
}
|
||||
p.Skills, p.Servers, p.ServersOff, p.SkillsOff, p.Subagents, p.InstrAgents = nil, nil, nil, nil, nil, nil
|
||||
p.Skills, p.Servers, p.ServersOff, p.SkillsOff, p.Subagents, p.InstrAgents, p.Plugins = nil, nil, nil, nil, nil, nil, nil
|
||||
l.syncProject(p, &Result{})
|
||||
if !p.holds() && p.Claude == nil && !slices.ContainsFunc(p.Trees, (*Project).holds) {
|
||||
l.Projects = slices.DeleteFunc(l.Projects, func(x *Project) bool { return x == p })
|
||||
@@ -627,7 +639,10 @@ type ProjectView struct {
|
||||
Instr string `json:"instr"`
|
||||
InstrAgents []string `json:"instrAgents"`
|
||||
InstrFiles []string `json:"instrFiles"`
|
||||
Missing bool `json:"missing,omitempty"` // the folder is gone
|
||||
// Plugins are the library's plugins the project has, for the agents
|
||||
// named
|
||||
Plugins map[string][]string `json:"plugins"`
|
||||
Missing bool `json:"missing,omitempty"` // the folder is gone
|
||||
// Problems are, by skill ("" for the project's own), what couldn't be done
|
||||
Problems map[string]string `json:"problems,omitempty"`
|
||||
}
|
||||
@@ -665,6 +680,10 @@ func projectViews(l *Library, problems []Problem) []ProjectView {
|
||||
for k, a := range p.Subagents {
|
||||
v.Subagents[k] = append([]string{}, a...)
|
||||
}
|
||||
v.Plugins = map[string][]string{}
|
||||
for k, a := range p.Plugins {
|
||||
v.Plugins[k] = append([]string{}, a...)
|
||||
}
|
||||
for _, t := range p.Trees {
|
||||
v.Trees = append(v.Trees, t.Dir)
|
||||
}
|
||||
|
||||
@@ -412,6 +412,9 @@ type AgentView struct {
|
||||
ProjectMCP string `json:"projectMCP,omitempty"`
|
||||
// ProjectSubagents is the folder in a project it reads subagents from
|
||||
ProjectSubagents string `json:"projectSubagents,omitempty"`
|
||||
// ProjectHooks is the file in a project it reads hooks from, which a
|
||||
// project's plugins' hooks are written into (project_plugins.go)
|
||||
ProjectHooks string `json:"projectHooks,omitempty"`
|
||||
// ProjectInstructions is the file in a project it reads the
|
||||
// project's instructions from, when there is none yet
|
||||
ProjectInstructions string `json:"projectInstructions,omitempty"`
|
||||
@@ -695,7 +698,7 @@ func readView(problems []Problem, glance bool) (*View, error) {
|
||||
}
|
||||
for _, t := range targets {
|
||||
av := AgentView{ID: t.Agent.ID, Name: t.Agent.Name, Icon: t.Agent.Icon, Instructions: t.Instructions, Skills: t.Skills,
|
||||
SkillsAlso: t.SkillsAlso, Note: t.Note, MCPVia: t.MCPVia, ProjectSkills: ProjectSkillsDir(t.Agent.ID), ProjectMCP: ProjectMCPFile(t.Agent.ID), ProjectSubagents: ProjectSubagentsDir(t.Agent.ID),
|
||||
SkillsAlso: t.SkillsAlso, Note: t.Note, MCPVia: t.MCPVia, ProjectSkills: ProjectSkillsDir(t.Agent.ID), ProjectMCP: ProjectMCPFile(t.Agent.ID), ProjectSubagents: ProjectSubagentsDir(t.Agent.ID), ProjectHooks: ProjectHooksFile(t.Agent.ID),
|
||||
ProjectInstructions: ProjectInstrFile(t.Agent.ID),
|
||||
ProjectOff: slices.Contains(projectOffAgents, t.Agent.ID), ProjectSkillOff: slices.Contains(projectSkillOffAgents, t.Agent.ID),
|
||||
ProjectNoSSE: ProjectNoSSE(t.Agent.ID)}
|
||||
|
||||
Reference in New Issue
Block a user