library: Pi and omp lock ~/.agents/skills from their versions; Put skills in links every skill there

usrname1833 on Discord asked for two things.

Pi reads ~/.agents/skills itself, so a skill kept there is Pi's whatever
is ticked, with the lock as Codex and OpenCode have. Pi started to in
0.54.0, not 0.19 (its CHANGELOG; userAgentsSkillsDir in
package-manager.js), and omp in 11.0.0 (src/discovery/agents.ts; 10.6.2
doesn't). Target.SharedToo says so from the version, and every reader of
readsShared goes through Target.readsSharedDir: Always (the lock),
syncSkills' inShared (no second link) and a handover's readsSharedHere.
OmO's senpi reads it in every npm version (0.74.0 up), so omo joins
readsShared. A Pi or omp of no known version is taken as older, as
before.

The second ask is a switch: Library > Skills > "Put skills in": each
agent's own folder (the default, today's behaviour) or ~/.agents/skills
(Library.SharedSkills; POST /api/library/skills/where {how};
magpie library skill where agents|shared). On, every library skill on
here gets magpie's link in ~/.agents/skills (syncShared, after
sweepShared), so every agent and tool reading that folder has it and
shows it locked. The files stay in the library rather than moving, so
updates, edit tracking and Off here keep working; existing skills just
get links when it is turned on, nothing is moved. A user's own entry by
the same name is never written over. Off takes out magpie's links there
and nothing else, and agents' own links come back. Per computer:
Collect doesn't carry it. docs/subsystems/library.md says all this.

Not covered, filed: on Windows without link rights the shared entry is
a marked copy, and takeEdits doesn't take edits made in it (#4958).

Run on mote rebased on d76c4b23a (which has 8abdf53a8):
gofmt -l clean; go vet GOOS=linux and GOOS=windows on internal/library,
internal/gui, internal/cli ok; go test internal/library, internal/gui,
internal/cli ok. GUI, every skill-*, library-* and i18n-keys file in
chromium and webkit: 1302 pass, 4 fail, all in library-all (webkit) and
library-null-agents (chromium). Both pass alone at this tree (52/52), so
they are load reds, filed as #4967. skill-where.test.cjs (new) covers en,
zh, zh-TW, ja, de at 900px and 400px. Before the rebase, cli's
TestEveryRouteHasACommandOrIsNamed was red on /api/usage/checkin-account
(not this change); it is green at this base.

Rebased twice more on origin/main (cli's settings_parity_test, app.js,
i18n.js, settings): internal/cli and internal/gui go test ok, i18n-keys
and skill-where green at the pushed tree.

Broken by hand, each red, then restored: since() always false
(TestPiReadsSharedSkillsFromItsVersion, TestSkillsWhereShared red);
syncShared step dropped (red); sweepShared's keepsShared keep dropped
(red on the SameFile no-relink check); the holder line in wanted
(TestSkillsWhereSharedWithKimi red); skillWhereBar not appended
(skill-where 0/11 per engine).

Not tried: a real Pi, omp or OmO run (versions read from their npm
source); the setting on the Windows box or in WSL; the whole GUI suite.
This commit is contained in:
yetone
2026-11-03 05:43:12 +08:00
parent 91379b9339
commit 1851ead1a7
13 changed files with 668 additions and 13 deletions
File diff suppressed because one or more lines are too long
+3
View File
@@ -40,6 +40,7 @@ const libraryUsage = `magpie library what the library gives
(one changed here is left as it is; update it by name with --replace-edits)
magpie library skill how link|copy [agent] give skills as links to the library's or as copies: every agent's way, or one agent's
magpie library skill how default <agent> the agent goes the library's way again
magpie library skill where agents|shared skills go to the agents ticked, or also into ~/.agents/skills for every agent and tool that reads it
magpie library skill use-library <name> <agent> an agent's own skill by that name is in the way: set it aside, link the library's
magpie library skill keep-own <name> <agent> …or keep the agent's, and take the agent off the library's
magpie library rtk which agents run their shell commands through RTK (rtk-ai.app), to save tokens
@@ -209,6 +210,8 @@ func libraryCmd(args []string) error {
how = ""
}
res, err = library.SetSkillHow(agent, how)
case len(rest) == 2 && rest[0] == "where" && (rest[1] == library.SkillsInAgents || rest[1] == library.SkillsInShared):
res, err = library.SetSkillsWhere(rest[1])
default:
return fmt.Errorf("usage:\n %s", libraryUsage)
}
+18 -1
View File
@@ -3406,7 +3406,7 @@ magpie.plugin("library", (ctx) => {
drawSkills(box, all);
body.append(box);
// under the list, so the skills stay where they were above it
if (all.length) body.append(skillHowBar());
if (all.length) body.append(skillHowBar(), skillWhereBar());
if (picking) body.append(pickBar(all));
}
if (lib.newSkills?.length) renderNewSkills(body);
@@ -4744,6 +4744,23 @@ magpie.plugin("library", (ctx) => {
return bar;
}
// Where the skills go (usrname1833): to the agents each is ticked for,
// in their own folders, or also into ~/.agents/skills, which many agents
// and tools read, so each of them has every skill. The files stay in the
// library's folder either way; ~/.agents/skills gets links to them.
function skillWhereBar() {
const bar = el("div", "lib-skillhow lib-skillwhere");
bar.id = "lib-skillwhere";
const where = lib.sharedSkills ? "shared" : "agents";
bar.append(el("span", "label", t("Put skills in")), segs([["agents", t("Each agent's own folder")], ["shared", "~/.agents/skills"]], where, (w) => {
if (w !== where) change("skills/where", { how: w }, w === "shared" ? t("Every skill is in ~/.agents/skills now") : t("Skills go to the agents they're ticked for now"));
}));
bar.append(el("span", "note", where === "shared"
? t("Every skill on here is linked into ~/.agents/skills too: each agent that reads that folder has every skill, whatever is ticked. The files stay in the library.")
: t("Each agent gets the skills ticked for it, in its own folder.")));
return bar;
}
function openSkillHow() {
const ed = el("div", "editor lib-editor lib-byagent-sheet lib-howsheet");
const head = el("div", "ehead");
@@ -119,6 +119,12 @@ magpie.strings({
"By agent ({n})": "按 Agent({n})",
"Give an agent its skills its own way": "给某个 Agent 单独设定启用方式",
"Each agent gets a folder of its own, made again when the library's skill changes; edits made in a copy are replaced.": "每个 Agent 拿到一份独立的文件夹,资源库里的 Skill 变了就重新复制;在副本里做的修改会被覆盖。",
"Put skills in": "Skills 放在",
"Each agent's own folder": "各 Agent 自己的目录",
"Every skill is in ~/.agents/skills now": "所有 Skill 现在都在 ~/.agents/skills 里了",
"Skills go to the agents they're ticked for now": "Skill 现在只给勾选的 Agent",
"Every skill on here is linked into ~/.agents/skills too: each agent that reads that folder has every skill, whatever is ticked. The files stay in the library.": "这台电脑上启用的每个 Skill 也会链接到 ~/.agents/skills:读这个目录的 Agent 都会拿到全部 Skill,不管勾没勾选。文件仍保存在资源库里。",
"Each agent gets the skills ticked for it, in its own folder.": "每个 Agent 只拿到勾选给它的 Skill,放在它自己的目录里。",
"Links follow the library's skill: an update reaches the agents at once.": "符号链接跟着资源库里的 Skill 走:一更新,各 Agent 立刻就用上。",
"How each agent gets its skills": "各 Agent 的 Skills 启用方式",
"An agent can have its own way; the others get copies, as the library gives them.": "可以给某个 Agent 单独设定;其余的按资源库的方式,拿副本。",
@@ -877,6 +883,12 @@ magpie.strings({
"By agent ({n})": "按 Agent({n})",
"Give an agent its skills its own way": "給某個 Agent 單獨設定啟用方式",
"Each agent gets a folder of its own, made again when the library's skill changes; edits made in a copy are replaced.": "每個 Agent 拿到一份獨立的資料夾,資源庫裡的 Skill 變了就重新複製;在副本里做的修改會被覆蓋。",
"Put skills in": "Skills 放在",
"Each agent's own folder": "各 Agent 自己的目錄",
"Every skill is in ~/.agents/skills now": "所有 Skill 現在都在 ~/.agents/skills 裡了",
"Skills go to the agents they're ticked for now": "Skill 現在只給勾選的 Agent",
"Every skill on here is linked into ~/.agents/skills too: each agent that reads that folder has every skill, whatever is ticked. The files stay in the library.": "這台電腦上啟用的每個 Skill 也會連結到 ~/.agents/skills:讀這個目錄的 Agent 都會拿到全部 Skill,不管勾沒勾選。檔案仍保存在資源庫裡。",
"Each agent gets the skills ticked for it, in its own folder.": "每個 Agent 只拿到勾選給它的 Skill,放在它自己的目錄裡。",
"Links follow the library's skill: an update reaches the agents at once.": "符號連結跟著資源庫裡的 Skill 走:一更新,各 Agent 立刻就用上。",
"How each agent gets its skills": "各 Agent 的 Skills 啟用方式",
"An agent can have its own way; the others get copies, as the library gives them.": "可以給某個 Agent 單獨設定;其餘的按資源庫的方式,拿副本。",
@@ -1631,6 +1643,12 @@ magpie.strings({
"By agent ({n})": "エージェント別({n})",
"Give an agent its skills its own way": "エージェントごとに渡し方を決める",
"Each agent gets a folder of its own, made again when the library's skill changes; edits made in a copy are replaced.": "各エージェントに独立したフォルダを渡し、ライブラリのスキルが変わると作り直します。コピーへの編集は上書きされます。",
"Put skills in": "スキルの置き場所",
"Each agent's own folder": "各エージェントのフォルダ",
"Every skill is in ~/.agents/skills now": "すべてのスキルが ~/.agents/skills に入りました",
"Skills go to the agents they're ticked for now": "スキルはチェックしたエージェントにだけ渡るようになりました",
"Every skill on here is linked into ~/.agents/skills too: each agent that reads that folder has every skill, whatever is ticked. The files stay in the library.": "このコンピュータで有効なスキルはすべて ~/.agents/skills にもリンクされます。このフォルダを読むエージェントは、チェックに関係なくすべてのスキルを使えます。ファイルはライブラリに残ります。",
"Each agent gets the skills ticked for it, in its own folder.": "各エージェントには、チェックしたスキルだけがそのエージェントのフォルダに渡ります。",
"Links follow the library's skill: an update reaches the agents at once.": "リンクはライブラリのスキルに従います。更新はすぐにエージェントに届きます。",
"How each agent gets its skills": "エージェントごとのスキルの渡し方",
"An agent can have its own way; the others get copies, as the library gives them.": "エージェントごとに決められます。ほかはライブラリの設定どおりコピーを受け取ります。",
@@ -2387,6 +2405,12 @@ magpie.strings({
"By agent ({n})": "Nach Agenten ({n})",
"Give an agent its skills its own way": "Einem Agenten seine Skills auf eigene Art geben",
"Each agent gets a folder of its own, made again when the library's skill changes; edits made in a copy are replaced.": "Jeder Agent bekommt einen eigenen Ordner, der neu angelegt wird, wenn sich der Skill der Bibliothek ändert; Änderungen an einer Kopie werden ersetzt.",
"Put skills in": "Skills ablegen in",
"Each agent's own folder": "Ordner jedes Agenten",
"Every skill is in ~/.agents/skills now": "Jeder Skill liegt jetzt in ~/.agents/skills",
"Skills go to the agents they're ticked for now": "Skills gehen jetzt an die Agenten, für die sie angehakt sind",
"Every skill on here is linked into ~/.agents/skills too: each agent that reads that folder has every skill, whatever is ticked. The files stay in the library.": "Jeder hier aktive Skill wird auch nach ~/.agents/skills verlinkt: Jeder Agent, der diesen Ordner liest, hat jeden Skill, egal was angehakt ist. Die Dateien bleiben in der Bibliothek.",
"Each agent gets the skills ticked for it, in its own folder.": "Jeder Agent bekommt die für ihn angehakten Skills in seinem eigenen Ordner.",
"Links follow the library's skill: an update reaches the agents at once.": "Links folgen dem Skill der Bibliothek: Ein Update erreicht die Agenten sofort.",
"How each agent gets its skills": "Wie jeder Agent seine Skills bekommt",
"An agent can have its own way; the others get copies, as the library gives them.": "Ein Agent kann seine eigene Art haben; die anderen bekommen Kopien, wie die Bibliothek sie gibt.",
+3
View File
@@ -583,6 +583,9 @@ func libraryRoutes(mux *http.ServeMux, w Windows) {
res, err = library.UseLibrarySkills(oneOrMore(in.Name, in.Names), in.Agent)
case "skills/how":
res, err = library.SetSkillHow(in.Agent, in.How)
case "skills/where":
// each agent's own folder, or ~/.agents/skills too (skills_shared.go)
res, err = library.SetSkillsWhere(in.How)
case "skills/keep-own":
res, err = library.KeepAgentSkills(oneOrMore(in.Name, in.Names), in.Agent)
case "market/server":
+179
View File
@@ -0,0 +1,179 @@
// Run with Node's test runner and Playwright on the module path; see README.md.
// usrname1833: the Skills tab says where the library's skills go, each
// agent's own folder (the default) or ~/.agents/skills too, and a switch
// posts it. With them there, the agents that read that folder (Pi from
// 0.54, Codex) have every skill: their chips are locked on. No select, no
// scroll, no left border, nothing wider than the window, in every
// language and at a phone's width. 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/ada";
function server(lang, posts) {
const st = { shared: false };
const agent = (id, name) => ({ id, name, icon: "", skills: `${HOME}/.${id}/skills`, how: "link" });
const readers = () => (st.shared ? ["codex", "pi"] : []);
const lib = () => ({
dir: `${HOME}/.magpie/library`, backups: `${HOME}/.magpie/backups`, home: HOME, copySkills: false,
sharedSkills: st.shared, sharedDir: `${HOME}/.agents/skills`,
agents: [agent("claude", "Claude Code"), agent("codex", "Codex"), agent("pi", "Pi")],
instructions: { agents: [] }, servers: [], foundServers: [], projects: [], foundSkills: [],
skills: [
{ name: "pdf", description: "Read PDFs", kind: "", agents: ["claude"], always: readers().length ? readers() : undefined },
{ name: "tdd", description: "Tests first", kind: "", agents: ["claude", "pi"], always: readers().length ? readers() : undefined },
],
});
return async (route) => {
const req = route.request(), url = new URL(req.url());
if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:true};` });
if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
if (url.pathname === "/api/state") return route.fulfill({ json: { agents: [], profiles: [], settings: { lang, theme: "light" } } });
if (url.pathname === "/api/library") return route.fulfill({ json: lib() });
if (url.pathname === "/api/library/skills/where") {
const b = req.postDataJSON();
posts.push(b);
st.shared = b.how === "shared";
return route.fulfill({ json: { ...lib(), result: { changed: ["codex", "pi"], 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 });
};
}
// where the bar's label is on screen: a switch leaves it where it was (a
// pixel's give, for a page scrolled to its foot whose note changed length)
const labelAt = (page) => page.locator("#lib-skillwhere .label").evaluate((e) => Math.round(e.getBoundingClientRect().top));
const press = async (page, loc) => {
const b = await loc.boundingBox();
await page.mouse.click(b.x + b.width / 2, b.y + b.height / 2);
};
const leftBorders = (page, sel) => page.evaluate((sel) => [...document.querySelectorAll(sel)].flatMap((e) => [e, ...e.querySelectorAll("*")])
.filter((e) => parseFloat(getComputedStyle(e).borderLeftWidth) > 0 && getComputedStyle(e).borderLeftColor !== getComputedStyle(e).borderTopColor)
.map((e) => e.className), sel);
// what of the bar reaches past the window's right edge
const pastEdge = (page) => page.evaluate(() => [...document.querySelectorAll("#lib-skillwhere, #lib-skillwhere *")]
.filter((e) => e.getBoundingClientRect().right > document.documentElement.clientWidth + 0.5).map((e) => e.className || e.tagName));
const SHARED = "~/.agents/skills";
const words = {
en: {
label: "Put skills in", agents: "Each agent's own folder",
agentsNote: "Each agent gets the skills ticked for it, in its own folder.",
sharedNote: "Every skill on here is linked into ~/.agents/skills too: each agent that reads that folder has every skill, whatever is ticked. The files stay in the library.",
toShared: "Every skill is in ~/.agents/skills now", toAgents: "Skills go to the agents they're ticked for now",
},
zh: {
label: "Skills 放在", agents: "各 Agent 自己的目录",
agentsNote: "每个 Agent 只拿到勾选给它的 Skill,放在它自己的目录里。",
sharedNote: "这台电脑上启用的每个 Skill 也会链接到 ~/.agents/skills:读这个目录的 Agent 都会拿到全部 Skill,不管勾没勾选。文件仍保存在资源库里。",
toShared: "所有 Skill 现在都在 ~/.agents/skills 里了", toAgents: "Skill 现在只给勾选的 Agent",
},
"zh-TW": {
label: "Skills 放在", agents: "各 Agent 自己的目錄",
agentsNote: "每個 Agent 只拿到勾選給它的 Skill,放在它自己的目錄裡。",
sharedNote: "這台電腦上啟用的每個 Skill 也會連結到 ~/.agents/skills:讀這個目錄的 Agent 都會拿到全部 Skill,不管勾沒勾選。檔案仍保存在資源庫裡。",
toShared: "所有 Skill 現在都在 ~/.agents/skills 裡了", toAgents: "Skill 現在只給勾選的 Agent",
},
ja: {
label: "スキルの置き場所", agents: "各エージェントのフォルダ",
agentsNote: "各エージェントには、チェックしたスキルだけがそのエージェントのフォルダに渡ります。",
sharedNote: "このコンピュータで有効なスキルはすべて ~/.agents/skills にもリンクされます。このフォルダを読むエージェントは、チェックに関係なくすべてのスキルを使えます。ファイルはライブラリに残ります。",
toShared: "すべてのスキルが ~/.agents/skills に入りました", toAgents: "スキルはチェックしたエージェントにだけ渡るようになりました",
},
de: {
label: "Skills ablegen in", agents: "Ordner jedes Agenten",
agentsNote: "Jeder Agent bekommt die für ihn angehakten Skills in seinem eigenen Ordner.",
sharedNote: "Jeder hier aktive Skill wird auch nach ~/.agents/skills verlinkt: Jeder Agent, der diesen Ordner liest, hat jeden Skill, egal was angehakt ist. Die Dateien bleiben in der Bibliothek.",
toShared: "Jeder Skill liegt jetzt in ~/.agents/skills", toAgents: "Skills gehen jetzt an die Agenten, für die sie angehakt sind",
},
};
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
test(engine + ": where the library's skills go (usrname1833)", 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();
});
const open = async (lang, width, posts) => {
const ctx = await browser.newContext({ viewport: { width, height: 760 } });
await ctx.addInitScript(() => { try { localStorage.setItem("magpie.libTab", "skills"); } catch {} });
const page = await ctx.newPage();
page.setDefaultTimeout(5000);
page.setDefaultNavigationTimeout(60000);
page.on("pageerror", (e) => errors.push(e.message));
page.on("dialog", (d) => { errors.push("a browser dialog: " + d.message()); d.dismiss(); });
await page.route("**/*", server(lang, posts));
await page.goto("http://magpie.test/");
await page.locator('button[data-view="library"]').click();
await page.locator("#view-library .lib-body:not(.lib-skel) .lib-row").first().waitFor();
return page;
};
const locked = (page, skill) => page.locator("#view-library .lib-skill", { hasText: skill }).locator(".lib-ag.always")
.evaluateAll((cs) => cs.map((c) => c.dataset.agent).sort());
for (const lang of Object.keys(words)) {
for (const width of [900, 400]) {
await t.test(`${lang} at ${width}px`, async () => {
const w = words[lang], posts = [];
const page = await open(lang, width, posts);
const bar = page.locator("#lib-skillwhere");
assert.equal((await bar.locator(".label").textContent()).trim(), w.label);
const segs = bar.locator(".segs .opt");
assert.deepEqual((await segs.allTextContents()).map((s) => s.trim()), [w.agents, SHARED]);
assert.equal((await bar.locator(".segs .opt.on").textContent()).trim(), w.agents, "each agent's folder is the default");
assert.equal((await bar.locator(".note").textContent()).trim(), w.agentsNote);
assert.deepEqual(await locked(page, "pdf"), []);
assert.deepEqual(await pastEdge(page), [], "nothing past the window's edge");
// at a phone's width the bar is below the fold: scrolled to as a
// reader does, with the wheel, till its note is in view
await page.mouse.move(width / 2, 500);
for (let i = 0; i < 10; i++) {
const b = await bar.locator(".note").boundingBox();
if (b.y + b.height <= 740) break;
await page.mouse.wheel(0, 200);
await page.waitForTimeout(150);
}
const before = await labelAt(page);
await press(page, segs.nth(1));
await bar.locator(".segs .opt.on", { hasText: SHARED }).waitFor();
assert.deepEqual(posts, [{ how: "shared" }]);
assert.equal((await page.locator("#status").textContent()).trim(), w.toShared);
const now = page.locator("#lib-skillwhere");
assert.equal((await now.locator(".note").textContent()).trim(), w.sharedNote);
// Codex and Pi read ~/.agents/skills: every skill, locked on
assert.deepEqual(await locked(page, "pdf"), ["codex", "pi"]);
assert.deepEqual(await locked(page, "tdd"), ["codex", "pi"]);
assert(Math.abs(await labelAt(page) - before) <= 2, "the switch scrolls nothing");
assert.deepEqual(await pastEdge(page), [], "nothing past the window's edge");
await press(page, now.locator(".segs .opt").nth(0));
await page.locator("#lib-skillwhere .segs .opt.on", { hasText: w.agents }).waitFor();
assert.deepEqual(posts[1], { how: "agents" });
assert.equal((await page.locator("#status").textContent()).trim(), w.toAgents);
assert.deepEqual(await locked(page, "pdf"), []);
assert.equal(await page.locator("select").count(), 0, "no native select");
assert.deepEqual(await leftBorders(page, "#lib-skillwhere"), []);
await page.context().close();
});
}
}
assert.deepEqual(errors, []);
});
}
+5
View File
@@ -51,6 +51,11 @@ type Library struct {
// copy (#896, skill_how.go)
CopySkills bool `json:"copySkills,omitempty"`
SkillHow map[string]string `json:"skillHow,omitempty"`
// SharedSkills puts every skill on here in ~/.agents/skills too, as
// magpie's link to the library's folder, for every agent and tool
// that reads it (usrname1833, skills_shared.go). This computer's
// own: Collect doesn't carry it
SharedSkills bool `json:"sharedSkills,omitempty"`
// MCPHub gives each agent that can reach it magpie's one MCP server,
// which hands each call on to the library's servers ticked for it, in
// place of their own entries (#2679, mcp_hub.go)
+1 -1
View File
@@ -81,7 +81,7 @@ func readsSharedHere(ts []*Target) []string {
sh := realDir(sharedSkillsDir())
var out []string
for _, t := range ts {
if t.Skills != "" && !t.Gone && t.Desktop == nil && (slices.Contains(readsShared, t.Agent.ID) || realDir(t.Skills) == sh) {
if t.Skills != "" && !t.Gone && t.Desktop == nil && (t.readsSharedDir() || realDir(t.Skills) == sh) {
out = append(out, t.Agent.ID)
}
}
+9 -3
View File
@@ -564,6 +564,11 @@ func (l *Library) syncSkills(t *Target, res *Result, all []*Target) {
if s == nil {
return false
}
// the folder is ~/.agents/skills itself: what the setting puts
// there (skills_shared.go) stays
if l.keepsShared(s) && realDir(t.Skills) == realDir(sharedSkillsDir()) {
return true
}
return s.gives(id) || slices.ContainsFunc(sharers, s.gives)
}
// an agent that reads ~/.agents/skills as well as its own folder finds
@@ -572,12 +577,12 @@ func (l *Library) syncSkills(t *Target, res *Result, all []*Target) {
shared := realDir(sharedSkillsDir())
isShared := realDir(t.Skills) == shared
inShared := func(s *Skill) bool {
if s == nil || !slices.Contains(readsShared, id) || realDir(t.Skills) == shared {
if s == nil || !t.readsSharedDir() || realDir(t.Skills) == shared {
return false
}
// the library's skill is kept in the shared folder itself (brought
// in from there): every agent reading it has it, ticked or not (#595)
if sharedHas(s.Name) {
if sharedHas(s.Name) || l.inSharedHere(s) {
return true
}
p := filepath.Join(sharedSkillsDir(), s.Name)
@@ -739,7 +744,8 @@ func (l *Library) sweepShared(all []*Target, res *Result) {
continue
}
s := l.skill(name)
if slices.ContainsFunc(holders, func(o *Target) bool { return s.gives(o.Agent.ID) }) {
// one the setting keeps there stays (skills_shared.go)
if l.keepsShared(s) || slices.ContainsFunc(holders, func(o *Target) bool { return s.gives(o.Agent.ID) }) {
continue
}
if err := unlink(p); err != nil {
+123
View File
@@ -0,0 +1,123 @@
package library
// Where the library's skills go (usrname1833 on Discord): to the agents
// each is ticked for, in each agent's own folder (the default), or also
// into ~/.agents/skills, the folder many agents and tools read besides
// their own (readsShared, Target.SharedToo), so every one of them finds
// every skill, ticked or not, as it finds one the user keeps there.
//
// The skill's files stay in the library's folder and ~/.agents/skills
// gets magpie's link to it, as it does for an agent whose folder it is
// (Goose, Kimi Code, Cindy): an update, a check, an edit, a sync and
// turning one off on this computer work as for any skill, and turning
// the setting off takes out magpie's links there and nothing else. An
// entry of the user's own by a skill's name is never written over.
//
// It is this computer's setting: Collect never carries it.
import (
"fmt"
"os"
"path/filepath"
"slices"
)
// The places SetSkillsWhere takes.
const (
SkillsInAgents = "agents" // each agent's own folder, as ticked
SkillsInShared = "shared" // ~/.agents/skills too, every skill
)
// SetSkillsWhere sets where the library's skills go: SkillsInAgents or
// SkillsInShared. Every skill is put in ~/.agents/skills, or taken out of
// it, at the sync it runs.
func SetSkillsWhere(where string) (*Result, error) {
if where != SkillsInAgents && where != SkillsInShared {
return nil, fmt.Errorf("skills go in %s or %s, not %q", SkillsInAgents, SkillsInShared, where)
}
return change(func(l *Library) error {
l.SharedSkills = where == SkillsInShared
return nil
})
}
// keepsShared is whether the library puts its skill s in ~/.agents/skills:
// the setting is on, the skill is on here and its folder is there.
func (l *Library) keepsShared(s *Skill) bool {
if !l.SharedSkills || s == nil || s.OffHere {
return false
}
_, err := os.Stat(filepath.Join(skillDir(s.Name), "SKILL.md"))
return err == nil
}
// inSharedHere is whether ~/.agents/skills has the library's skill s by
// the setting: magpie's link (or copy) there.
func (l *Library) inSharedHere(s *Skill) bool {
return l.keepsShared(s) && ours(filepath.Join(sharedSkillsDir(), s.Name), s.Name)
}
// syncShared puts each skill the setting keeps there into ~/.agents/skills,
// before the agents that read it are synced (they then get no second
// link). One given to an agent whose folder that is (Kimi Code) is that
// agent's sync's, which puts it there its own way; sweepShared takes out
// what the setting no longer keeps.
func (l *Library) syncShared(all []*Target, res *Result) {
if !l.SharedSkills {
return
}
shared := realDir(sharedSkillsDir())
var holders []*Target
for _, o := range all {
if o.Skills != "" && !o.Gone && realDir(o.Skills) == shared {
holders = append(holders, o)
}
}
for _, s := range l.Skills {
if !l.keepsShared(s) || sharedEntry(s.Name) != "" || slices.ContainsFunc(holders, func(o *Target) bool { return s.gives(o.Agent.ID) }) {
continue
}
p := filepath.Join(sharedSkillsDir(), s.Name)
if l.blockedSkills[realDir(p)] {
continue
}
if ours(p, s.Name) {
if linked(p) {
continue
}
// a copy, where no link could be made (Windows without the
// right to): a link once one can be, else made again when the
// library's skill has changed, an edited copy kept aside
if ok, err := relink("agents", p, s.Name); err != nil || ok {
if err != nil {
res.fail("agents", "skill:"+s.Name, err)
}
continue
}
if h := l.libHash(s.Name); h != "" {
fresh, err := copyIsFresh(p, h, false)
if err == nil && !fresh {
_, err = setAside("agents", p)
if err == nil {
err = link(p, s.Name)
}
}
if err != nil {
res.fail("agents", "skill:"+s.Name, err)
}
}
continue
}
if _, err := os.Lstat(p); err == nil {
// the user's own by that name stays theirs, and is what the
// agents reading the folder find; the agents ticked for the
// library's still get it in their own folders (inSharedHere
// is false for it). Said at no sync: every change would carry
// it as a failure
continue
}
if err := link(p, s.Name); err != nil {
res.fail("agents", "skill:"+s.Name, err)
}
}
}
+247
View File
@@ -0,0 +1,247 @@
package library
import (
"os"
"path/filepath"
"slices"
"strings"
"testing"
"github.com/yetone/magpie/internal/agent"
)
func setOmpVersion(t *testing.T, v string) {
t.Helper()
was := ompVersion
ompVersion = func(*agent.Agent) string { return v }
t.Cleanup(func() { ompVersion = was })
}
func alwaysOf(t *testing.T, name string) []string {
t.Helper()
v, err := Read(nil)
if err != nil {
t.Fatal(err)
}
for _, s := range v.Skills {
if s.Name == name {
return s.Always
}
}
t.Fatalf("no skill %s in the view", name)
return nil
}
// usrname1833: Pi reads ~/.agents/skills itself, from 0.54.0 (its
// CHANGELOG, package-manager.js userAgentsSkillsDir), omp from 11.0.0
// (discovery/agents.ts) and OmO's senpi in every version on npm. A skill
// kept there is theirs whatever is ticked (the lock), and no second link
// is made in their own folders; an older or unknown one is as before.
func TestPiReadsSharedSkillsFromItsVersion(t *testing.T) {
h := sandbox(t)
os.RemoveAll(filepath.Join(h, ".config/goose"))
os.Remove(filepath.Join(h, "bin/goose"))
os.Remove(filepath.Join(h, "bin/goose.exe"))
write(t, filepath.Join(h, ".omp/agent/mcp.json"), "{}")
holdCLI(t, h, "omp")
write(t, filepath.Join(h, ".omo/agent/settings.json"), "{}")
holdCLI(t, h, "omo")
shared := filepath.Join(h, ".agents/skills")
skill(t, filepath.Join(shared, "orch"), "orch", "Orchestrate")
own := map[string]string{
"pi": filepath.Join(h, ".pi/agent/skills/orch"),
"omp": filepath.Join(h, ".omp/agent/skills/orch"),
"omo": filepath.Join(h, ".omo/agent/skills/orch"),
}
setPiVersion(t, "0.53.0")
setOmpVersion(t, "10.6.2")
ok(t)(ImportSkill("orch"))
ok(t)(SkillAgents("orch", []string{"claude", "pi", "omp", "omo"}))
for _, id := range []string{"pi", "omp"} {
if !ours(own[id], "orch") {
t.Errorf("%s before it read ~/.agents/skills hasn't its own link", id)
}
}
if _, err := os.Lstat(own["omo"]); !os.IsNotExist(err) {
t.Errorf("omo reads ~/.agents/skills, yet got a second link: %v", err)
}
a := alwaysOf(t, "orch")
if slices.Contains(a, "pi") || slices.Contains(a, "omp") || !slices.Contains(a, "omo") || !slices.Contains(a, "codex") {
t.Errorf("always before: %v", a)
}
setPiVersion(t, "0.54.0")
setOmpVersion(t, "11.0.0")
ok(t)(Sync())
for _, id := range []string{"pi", "omp"} {
if _, err := os.Lstat(own[id]); !os.IsNotExist(err) {
t.Errorf("%s reads ~/.agents/skills now, yet keeps a second link: %v", id, err)
}
}
a = alwaysOf(t, "orch")
for _, id := range []string{"pi", "omp", "omo", "codex"} {
if !slices.Contains(a, id) {
t.Errorf("%s isn't said to have it always: %v", id, a)
}
}
if slices.Contains(a, "claude") {
t.Errorf("claude reads no ~/.agents/skills: %v", a)
}
// a version not known is taken as an older one, as before
setPiVersion(t, "")
ok(t)(Sync())
if !ours(own["pi"], "orch") || slices.Contains(alwaysOf(t, "orch"), "pi") {
t.Error("a pi of no known version isn't as before")
}
}
// usrname1833: the library's skills can go into ~/.agents/skills too, as
// magpie's links to the library's folders, so every agent and tool that
// reads that folder has every skill. Off (the default) is as before;
// turning it off takes out magpie's links there and nothing else.
func TestSkillsWhereShared(t *testing.T) {
h := sandbox(t)
os.RemoveAll(filepath.Join(h, ".config/goose"))
os.Remove(filepath.Join(h, "bin/goose"))
os.Remove(filepath.Join(h, "bin/goose.exe"))
setPiVersion(t, "0.70.0")
src := filepath.Join(h, "src/skills")
skill(t, filepath.Join(src, "pdf"), "pdf", "Read PDFs")
skill(t, filepath.Join(src, "mine"), "mine", "Mine")
shared := filepath.Join(h, ".agents/skills")
// the user's own skills there: one magpie has no skill by, and one by
// a name the library has, with other files
skill(t, filepath.Join(shared, "theirs"), "theirs", "Theirs")
write(t, filepath.Join(shared, "mine", "SKILL.md"), "---\nname: mine\ndescription: Not the library's\n---\n")
pdf := filepath.Join(shared, "pdf")
pi, cl := filepath.Join(h, ".pi/agent/skills/pdf"), filepath.Join(h, ".claude/skills/pdf")
ok(t)(InstallSkills(src, []string{"pdf"}, []string{"claude", "pi"}))
if _, err := os.Lstat(pdf); !os.IsNotExist(err) {
t.Fatalf("the default put pdf in ~/.agents/skills: %v", err)
}
if !ours(pi, "pdf") {
t.Fatal("pi hasn't pdf")
}
if v, _ := Read(nil); v.SharedSkills || v.SharedDir != shared {
t.Errorf("view: shared %v at %q", v.SharedSkills, v.SharedDir)
}
if _, err := SetSkillsWhere("everywhere"); err == nil {
t.Error("a place it doesn't know was taken")
}
ok(t)(SetSkillsWhere(SkillsInShared))
if !ours(pdf, "pdf") || !linked(pdf) {
t.Fatal("pdf isn't magpie's link in ~/.agents/skills")
}
// a sync leaves the link as it is, not taken out and made again,
// which a reader of the folder would find missing in between
was, _ := os.Lstat(pdf)
ok(t)(Sync())
if now, err := os.Lstat(pdf); err != nil || !os.SameFile(was, now) {
t.Errorf("a sync made the link again: %v", err)
}
// pi reads that folder: no second link; claude doesn't: its stays
if _, err := os.Lstat(pi); !os.IsNotExist(err) {
t.Errorf("pi keeps a second link: %v", err)
}
if !ours(cl, "pdf") {
t.Error("claude lost its link")
}
a := alwaysOf(t, "pdf")
for _, id := range []string{"pi", "codex", "gemini"} {
if !slices.Contains(a, id) {
t.Errorf("%s isn't said to have it always: %v", id, a)
}
}
if slices.Contains(a, "claude") {
t.Errorf("claude: %v", a)
}
if v, _ := Read(nil); !v.SharedSkills {
t.Error("the view doesn't say skills go to ~/.agents/skills")
}
// the user's own are as they were
if _, err := os.Stat(filepath.Join(shared, "theirs", "SKILL.md")); err != nil {
t.Error("the user's own skill went")
}
// a library skill by a name the user has there with other files:
// theirs stays, and the agents ticked for the library's get it in
// their own folders
ok(t)(InstallSkills(src, []string{"mine"}, []string{"claude", "pi"}))
if !ours(filepath.Join(h, ".pi/agent/skills/mine"), "mine") {
t.Error("pi hasn't the library's mine")
}
if ours(filepath.Join(shared, "mine"), "mine") || !strings.Contains(read(t, filepath.Join(shared, "mine", "SKILL.md")), "Not the library's") {
t.Error("the user's own mine was written over")
}
// off on this computer: out of ~/.agents/skills, and pi's own is back
ok(t)(SkillHere("pdf", false))
if _, err := os.Lstat(pdf); !os.IsNotExist(err) {
t.Errorf("a skill off here stays in ~/.agents/skills: %v", err)
}
ok(t)(SkillHere("pdf", true))
if !ours(pdf, "pdf") {
t.Error("on again, pdf isn't back")
}
// a skill unticked everywhere is still in the shared folder
ok(t)(SkillAgents("pdf", nil))
if !ours(pdf, "pdf") {
t.Error("unticked, pdf left ~/.agents/skills")
}
// back to each agent's folder: magpie's links there go, nothing else
ok(t)(SkillAgents("pdf", []string{"claude", "pi"}))
r, err := SetSkillsWhere(SkillsInAgents)
if err != nil {
t.Fatal(err)
}
if len(r.Problems) != 0 {
t.Errorf("problems: %+v", r.Problems)
}
if _, err := os.Lstat(pdf); !os.IsNotExist(err) {
t.Errorf("pdf stays in ~/.agents/skills: %v", err)
}
if !ours(pi, "pdf") {
t.Error("pi hasn't its own link back")
}
if slices.Contains(alwaysOf(t, "pdf"), "pi") {
t.Error("pi still said to have it always")
}
for _, n := range []string{"theirs", "mine"} {
if _, err := os.Stat(filepath.Join(shared, n, "SKILL.md")); err != nil {
t.Errorf("the user's own %s went", n)
}
}
if _, err := os.Stat(filepath.Join(skillDir("pdf"), "SKILL.md")); err != nil {
t.Error("the library's pdf went")
}
}
// A skill ticked for Kimi Code, whose folder ~/.agents/skills is, and then
// unticked for it stays there while the setting keeps it there.
func TestSkillsWhereSharedWithKimi(t *testing.T) {
h := sandbox(t)
write(t, filepath.Join(h, ".kimi/config.toml"), "")
src := filepath.Join(h, "src/skills")
skill(t, filepath.Join(src, "pdf"), "pdf", "Read PDFs")
pdf := filepath.Join(h, ".agents/skills/pdf")
ok(t)(InstallSkills(src, []string{"pdf"}, []string{"kimi"}))
ok(t)(SetSkillsWhere(SkillsInShared))
ok(t)(SkillAgents("pdf", []string{"claude"}))
if !ours(pdf, "pdf") {
t.Fatal("unticked for Kimi Code, pdf left ~/.agents/skills")
}
ok(t)(Sync())
if !ours(pdf, "pdf") {
t.Fatal("a second sync took pdf out")
}
ok(t)(SetSkillsWhere(SkillsInAgents))
if _, err := os.Lstat(pdf); !os.IsNotExist(err) {
t.Errorf("pdf stays: %v", err)
}
}
+13 -3
View File
@@ -120,6 +120,7 @@ func syncSteps(all, gone []*Target, b *backups, res *Result) []func(*Library) {
// link to what is there already
shared := realDir(sharedSkillsDir())
steps = append(steps, func(l *Library) { l.sweepShared(append(slices.Clone(all), gone...), res) })
steps = append(steps, func(l *Library) { l.syncShared(all, res) })
for _, first := range []bool{true, false} {
for _, t := range all {
switch {
@@ -498,6 +499,10 @@ type View struct {
Backups string `json:"backups"`
SkillGroups []SkillGroup `json:"skillGroups"`
CopySkills bool `json:"copySkills"` // the library gives skills as copies (#896)
// SharedSkills: every skill on here is in ~/.agents/skills too
// (skills_shared.go), at SharedDir
SharedSkills bool `json:"sharedSkills"`
SharedDir string `json:"sharedDir"`
// MCPHub: the agents are given magpie's one MCP server in place of
// the library's (#2679), at HubPath<agent> on the gateway
MCPHub bool `json:"mcpHub"`
@@ -569,7 +574,7 @@ func readView(problems []Problem, glance bool) (*View, error) {
// the agents are found once for the whole read: finding them looks
// through every agent's folders, in WSL too (#1624)
targets, asleep := targetsAsleep(false)
v := &View{Agents: []AgentView{}, Servers: []ServerView{}, Skills: []SkillView{}, FoundSkills: []FoundSkill{}, Instructions: l.instructionsView(targets, asleep), Dir: Dir(), Backups: BackupDir(), CopySkills: l.CopySkills, MCPHub: l.MCPHub, HubPath: gateway.HubMCPPath, HubNote: settings.Shared().RouterNote, HubName: gateway.HostName(), Partial: glance}
v := &View{Agents: []AgentView{}, Servers: []ServerView{}, Skills: []SkillView{}, FoundSkills: []FoundSkill{}, Instructions: l.instructionsView(targets, asleep), Dir: Dir(), Backups: BackupDir(), CopySkills: l.CopySkills, SharedSkills: l.SharedSkills, SharedDir: sharedSkillsDir(), MCPHub: l.MCPHub, HubPath: gateway.HubMCPPath, HubNote: settings.Shared().RouterNote, HubName: gateway.HostName(), Partial: glance}
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),
@@ -675,10 +680,15 @@ func readView(problems []Problem, glance bool) (*View, error) {
} else if _, err := os.Lstat(p); err == nil && sv.Kind == "folder" {
sv.Kind, sv.Source = "", ""
}
if sv.Shared = sharedEntry(s.Name); sv.Shared != "" {
// kept in ~/.agents/skills by the user, or put there by the
// setting: every agent reading that folder has it
sv.Shared = sharedEntry(s.Name)
if sv.Shared != "" {
sv.SharedElsewhere = !within(realDir(skillDir(s.Name)), realDir(sharedSkillsDir()))
}
if sv.Shared != "" || l.inSharedHere(s) {
for _, t := range targets {
if t.Skills != "" && (slices.Contains(readsShared, t.Agent.ID) || realDir(t.Skills) == realDir(sharedSkillsDir())) {
if t.Skills != "" && (t.readsSharedDir() || realDir(t.Skills) == realDir(sharedSkillsDir())) {
sv.Always = append(sv.Always, t.Agent.ID)
}
}
+40 -4
View File
@@ -52,6 +52,10 @@ type Target struct {
// gave it (held): a sync only takes things out of it, as they are
// unticked, and gives it nothing.
Gone bool
// SharedToo is an agent that reads ~/.agents/skills besides its own
// folder only from some version on (Pi, omp: sharedSince), with that
// version here; the others that always do are in readsShared
SharedToo bool
// Profile says the instructions file is the user's profile to the
// agent, not instructions alone (Alma's USER.md): magpie adds its part
// after the user's, but never moves the user's own lines out of it
@@ -201,8 +205,10 @@ func targetOf(a *agent.Agent) *Target {
// Pi 0.99 reads MCP servers itself, from its mcp.json; before it,
// and while an MCP extension replaces its own (pi-mcp-adapter,
// pi-mcp-extension), each extension reads its own file (pimcp.go)
t.MCP, t.MCPVia = piMCP(h, d, piVersion(a), piGlobalRoots())
v := piVersion(a)
t.MCP, t.MCPVia = piMCP(h, d, v, piGlobalRoots())
t.Skills = filepath.Join(d, "skills")
t.SharedToo = since(v, piSharedSince)
case "dsh":
// DeepSeek Harness reads $DSH_HOME/AGENTS.md and $DSH_HOME/skills;
// its MCP servers are @deepseek-ai/dsh-mcp-client rows its patch
@@ -220,6 +226,7 @@ func targetOf(a *agent.Agent) *Target {
// (discovery/builtin.ts), type choosing the transport
t.MCP = &mcpFile{Path: filepath.Join(d, "mcp.json"), Format: fmtOmp}
t.Skills = filepath.Join(d, "skills")
t.SharedToo = since(ompVersion(a), ompSharedSince)
case "omo":
// OmO's engine (senpi, a fork of Pi) reads its agent folder's
// AGENTS.md, skills and mcp.json — mcpServers in the shape Pi 0.99's
@@ -933,8 +940,37 @@ func (l *Library) held(have []*Target) []*Target {
// readsShared are the agents that read ~/.agents/skills as well as their
// own folder (each one's docs or source): Kimi Code's own is
// ~/.kimi-code/skills besides it (#4379).
var readsShared = []string{"codex", "gemini", "opencode", "deveco", "crush", "dsh", "commandcode", "devin", "droid", "cline", "grok", "grok-app", "fx", "alma", "kimi"}
// ~/.kimi-code/skills besides it (#4379). OmO's engine, senpi, a fork of
// Pi from after Pi 0.54 (its oldest on npm is 0.74.0), reads it as Pi
// does (core/package-manager.js, userAgentsSkillsDir, @code-yeongyu/senpi
// 2026.5.13).
var readsShared = []string{"codex", "gemini", "opencode", "deveco", "crush", "dsh", "commandcode", "devin", "droid", "cline", "grok", "grok-app", "fx", "alma", "kimi", "omo"}
// Pi reads ~/.agents/skills from 0.54.0 (2026-02-19, its CHANGELOG: "Added
// default skill auto-discovery for .agents/skills locations … global
// skills from ~/.agents/skills"; userAgentsSkillsDir in
// dist/core/package-manager.js, @earendil-works/pi-coding-agent 1.5.0),
// and omp from 11.0.0 (src/discovery/agents.ts, "Load skills from
// ~/.agents/skills"; 10.6.2 has no such provider). A Pi or omp whose
// version isn't known is taken for one before, as magpie took every Pi:
// it is given its own link, which a Pi from 0.68 reads once with the
// shared folder's (it dedupes skills by their real path).
const (
piSharedSince = "0.54.0"
ompSharedSince = "11.0.0"
)
// ompVersion is the version of the omp on PATH, "" when not known.
var ompVersion = func(a *agent.Agent) string { return a.InstalledVersion() }
// since is whether version v, when known, is at or after first.
func since(v, first string) bool { return v != "" && !agent.Newer(first, v) }
// readsSharedDir is whether the agent reads ~/.agents/skills besides its
// own folder, so a skill kept there reaches it whatever is ticked.
func (t *Target) readsSharedDir() bool {
return t.SharedToo || slices.Contains(readsShared, t.Agent.ID)
}
// readsWith adds to each agent's SkillsAlso the agents whose folder it
// reads skills from too: one that is the very same folder (Kimi Code's,
@@ -954,7 +990,7 @@ func readsWith(ts []*Target) {
if i == j || real[i] == "" || real[j] == "" || slices.Contains(t.SkillsAlso, o.Agent.ID) {
continue
}
if real[j] == real[i] || real[j] == shared && slices.Contains(readsShared, t.Agent.ID) {
if real[j] == real[i] || real[j] == shared && t.readsSharedDir() {
t.SkillsAlso = append(t.SkillsAlso, o.Agent.ID)
}
}