library: a skill the user has in ~/.agents/skills under another folder or with other files is not given a second time
math_milian (Discord #feedback, 11-06) still saw skills twice afterd487aaab7. That commit kept the library's link out of a reader's own folder only when ~/.agents/skills held the same files under the same folder name. Pi, Codex, Gemini, Kimi Code and the other readers of that folder still got a second copy when the user's entry there: - had other files (an update through `npx skills`, a local edit), or - sat under another folder name with the same SKILL.md name (Pi goes by the frontmatter name; real Pi 1.4.0 warns `name "hunk-review" collision` for both cases with magpie's link beside it, and loads the user's alone with no diagnostics once the link is gone). readSharedOwn/sharedOwn.rival now finds the user's entry by folder name or SKILL.md name. A same-tree one counts as the library's (as before). A differing one gets no second copy: it raises the Own problem ("{agent} already has a skill of its own called X"), whose Use the library's sets the shared entry aside with the backups and gives the link, and whose Keep {agent}'s unticks it. Agents that don't read the folder (Claude Code) keep their link. Old users' second links go on the next sync (the GUI syncs at start), through the existing unlink. TestKimiSweepLeavesTheUsersOwnSharedSkills and TestSkillsWhereShared assumed a differing same-name user skill gave the library's again; they now expect the Own problem and no second link. Run (mote, at this tree oncd9c52c16): - go test -tags nogui -count=1 ./internal/library ./internal/cli ./internal/gui: ok - GOOS=linux/windows go vet -tags nogui ./internal/library, go vet: ok; gofmt -l clean - win-run: TestSharedCopy*, TestSharedOwn*, TestSkillsWhereShared, TestKimiSweep*: ok - probe in a sandbox HOME, skill ticked for claude, codex, pi, gemini, opencode: same tree / other files / other folder name / shared link elsewhere; before, the last-but-one two gave pi, codex, gemini a second entry; after, none (OpenCode merges ~/.claude/skills with ~/.agents/skills by id, so it never shows two) - real Pi 1.4.0 loader on mote for the two cases, before and after Broken by hand: - rival matching same-tree only: TestSharedCopyNotGivenTwice and TestSharedOwnSettled red - readSharedOwn keyed by folder name only: TestSharedCopyOtherFolderName red (.pi, .codex, .gemini still have a second one) Not tried: the reporter's own tree (asked for), the real GUI's Use/Keep buttons on this problem, WSL/Linux runs, a Pi or omp of unknown version (still given its own, in docs' Not covered). Reported-by: math_milian
This commit is contained in:
@@ -74,8 +74,8 @@ agents RTK, a CLI that cuts shell output down before the model reads it.
|
||||
- An MCP server can be kept to this computer (`Server.Local`; the editor's "Sync to your other computers" switch, off for a local one (it said "This computer only", which bin.90 on Discord read as sharing), the row tagged "Not synced", `magpie library mcp add --local`, `magpie library mcp local <name> on|off`; huhuy72219405 on X). `Collect` never carries it (`carriedServers`), so a sync or a backup file never takes it to another computer, and turning a shared server local takes it out of what is carried: the other computers drop it at their next sync. `Put` (sync, join, Restore, Undo, a backup file) keeps every local server here, with its agents, and clears `Local` on what comes in (`putServers`). Another computer's server by the name of a local one doesn't take its place: it goes to `Library.Away`, given to no agent, not in the router, not checked, and carried on as it came, so a push from here never takes it from the computers that have it. `settleAway` runs on every change: while the name is local here the away copy stays; once no server of that name is left here (removed or renamed) it comes in as a sync would bring it; once a shared server has the name (local turned off) this computer's is the one carried. The router serves local servers like any other, since it runs on this computer. A carried subagent names its servers, a local one too; a computer without that server leaves it out of the agents' files, as any server the library hasn't. The TUI keeps the flag on edit and marks the row. (`TestLocalServerNotCarried`, `TestPutKeepsLocalServer`, `TestPutSameNameAsLocal`, `TestRestoreKeepsLocalServer`, `TestLocalServerThroughSync`, `mcp-local-server.test.cjs`) [`mcp_local.go`](../../internal/library/mcp_local.go), [`carry.go`](../../internal/library/carry.go)
|
||||
- A skill brought in from a link into a folder an app keeps per version (ego lite's framework `Versions/<v>`, #2635) is linked through the app's own steady link, or through `Versions/Current` when Current is that version (`linkVia`, `currentVersion`; `TestImportedSkillFollowsAppUpdate`, `TestImportedSkillThroughVersionsCurrent`). One brought in before that links straight to `Versions/<old>`, which the app's update deletes (tjhhhh on Discord). Every read of the page (looking at each link once, `readParts`, and starting that over when a link was mended) and the first step of every sync mend such links (`followMovedSkills`): a library skill that is a link, whose target isn't there, and whose first missing part is named like a version (`versionName`) is linked to the same place under that folder's `Current`, `current` or `latest` link, else under the highest version beside it that has a `SKILL.md` there (`movedVersion`, `versionLess`); one whose target is in `Versions/<v>` while the bundle's `Versions/Current` is a link to another version with the same skill is linked through Current (`laterCurrent`). `Source.Dir` follows. Only the library's link is replaced (`os.Remove` of the link, then `dirLink`; put back as it was when the new link can't be made). A folder of the library's own, a link to a folder the user deleted that isn't a version (shown missing as before) and the app's old version folder are left as they are (`TestOldImportFollowsDeletedVersion`, `TestOldImportFollowsVersionsCurrent`, `TestOldImportFollowsHighestVersion`, `TestMovedSkillsLeaveTheRest`). The app's own steady link can be left naming the version its update deleted (ego's `active_version_dir` still at 0.6.2.5 with only 0.6.2.7 on disk, tjhhhh again): the app's links are its own and never written to. When the library's link dangles and its target isn't in a version folder, the links on the way are followed as far as they are there (`linkedEnd`) and `movedVersion` is asked of where they end; the library links to the folder found, and keeps the steady link as `Source.Via`. Once the steady link leads to a `SKILL.md` again, the library links through it once more and `Via` is cleared (`TestSteadyLinkLeftOnDeletedVersion`, `TestSteadyLinkLeftOnDeletedVersionNoOther`). [`skill_moved.go`](../../internal/library/skill_moved.go)
|
||||
- A skill kept in `~/.agents/skills` is handed over to the library on the user's click (`HandOverSkills`, `POST /api/library/skills/hand-over` with `names`; the row's Manage in magpie in its source line, Manage {n} in magpie in the skills' heading, each asking first; `magpie library skill hand-over <name…>|--all`; tnt1223 on Discord). "Kept there" is `sharedEntry`: the entry in that folder that is the library skill's own folder, by its name or, for a library link into it under another folder's name, by that folder's (`SkillView.Shared`; `SharedElsewhere` when the entry only links to a folder kept elsewhere). Every reader of `sharedHas`/`sharedEntry` follows: `Always`, `syncSkills`' `inShared`, and the shared folder's own target (Goose, Kimi Code, Cindy), which is given no second link beside such an entry (`TestSharedUnderAnotherName`). Handed over, a folder in `~/.agents/skills` moves into the library's skills folder (`moveIn`: renamed, or copied, read back the same with `sameTree` and only then set aside with the backups; a failure leaves it where it was and the library's link as it was, `TestHandOverFailureKeepsOriginal`), and an entry that only links elsewhere is taken away while the library links past it to that folder. The user's own links to it in agents' folders, which would point at nothing, go too. Every agent here that read it (`readsSharedHere`, and the agent of each such link) is ticked, so each keeps it, now from the library, till it is unticked or turned off here. A skill found there and not in the library yet is brought in first. One that can't be handed over is left as it was, in `Result.Unmoved`, and the others are handed over all the same. `HandBackSkill` (`magpie library skill hand-back <name>`, CLI only; the sheet names it) moves the folder back and links the library to it, its ticks as they are. Not covered: another computer whose skill is still in its own `~/.agents/skills` gets the library's copy from a sync beside its own, until it is handed over there too; and the skills CLI's lock (`npx skills update`) may put the entry back (`TestHandOverSharedFolder`, `TestHandOverSharedLink`, `TestHandOverFound`, `TestHandOverWithGoose`, `TestLibrarySkillHandOver`, `skill-handover.test.cjs`). [`skill_handover.go`](../../internal/library/skill_handover.go)
|
||||
- The agents that read `~/.agents/skills` themselves are `readsShared` (Codex, Gemini CLI, OpenCode, DevEco Code, Crush, dsh, Command Code, Devin, Droid, Cline, Grok Build, Grok App, fx, Alma, Kimi Code, ZCode and OmO) and, from the version that started to, `Target.SharedToo`: Pi from 0.54.0 (its CHANGELOG; `userAgentsSkillsDir` in package-manager.js) and omp from 11.0.0 (`discovery/agents.ts`; 10.6.2 doesn't). OmO runs on senpi, whose oldest version on npm (0.74.0) already reads it. A Pi or omp whose version isn't known is taken as older, as before. Every reader goes through `Target.readsSharedDir`: `Always` (the row's lock), `syncSkills`' `inShared` (no second link in its own folder) and `readsSharedHere` for a handover (usrname1833 on Discord; `TestPiReadsSharedSkillsFromItsVersion`). A user's own copy of the library skill's very files in `~/.agents/skills` (another installer's, or copied by hand: not magpie's, not the library's own folder) counts too (`sharedCopy`, by `sameTree`): such a reader gets nothing in its own folder, and magpie's link or marked copy there goes on the next sync, since Pi drops a skill read twice only when both paths are one file (`realPathSet` in dist/core/skills.js) and warned of a collision for the two trees. The user's copy is never touched; once it differs from the library's, the library's is given again (math_milian on Discord; `TestSharedCopyNotGivenTwice`). Not covered: a library skill that is a link to the agent's own folder (brought in from there) beside such a copy keeps both, since that folder is the library's; and a Pi or omp of unknown version is given its own as before.
|
||||
- Put skills in (`Library.SharedSkills`; `SetSkillsWhere`, `POST /api/library/skills/where` with `how` `agents` or `shared`; `magpie library skill where agents|shared`; the Skills tab's bar under How, `skillWhereBar` in plugins/library/client.js; usrname1833 on Discord). Off, the default and what a library.json from before reads as, each agent gets the skills ticked for it in its own folder. On, every library skill on here (`keepsShared`: not `OffHere`, its folder there) also gets magpie's link in `~/.agents/skills` (`syncShared`, run after `sweepShared`), so every agent and tool that reads that folder has it, ticked or not, and is in its `Always`. The files stay in the library, so updates, checks, edit tracking and Off here work as before, and nothing is moved when it is turned on: existing skills just get links. An entry of the user's own by a skill's name is left alone, silently, and the agents ticked for the library's skill still get it in their own folders, unless it holds the library's very files and they read the folder themselves (`sharedCopy`, above). A sync leaves an existing link as it is. A skill given to the folder's own agent (Kimi Code, Goose, Cindy) is that agent's sync's. Turned off, `sweepShared` takes out magpie's links there and nothing else, and each agent's own links come back. It is this computer's: `Collect` never carries it (`TestSkillsWhereShared`, `TestSkillsWhereSharedWithKimi`, `skill-where.test.cjs`). Not covered: on Windows without the right to make links the entry is a marked copy; a stale one is set aside and copied again, but `takeEdits` doesn't take edits made in that copy into the library, so they go to the backups when the setting is turned off or the skill changes (#4958). [`skills_shared.go`](../../internal/library/skills_shared.go)
|
||||
- The agents that read `~/.agents/skills` themselves are `readsShared` (Codex, Gemini CLI, OpenCode, DevEco Code, Crush, dsh, Command Code, Devin, Droid, Cline, Grok Build, Grok App, fx, Alma, Kimi Code, ZCode and OmO) and, from the version that started to, `Target.SharedToo`: Pi from 0.54.0 (its CHANGELOG; `userAgentsSkillsDir` in package-manager.js) and omp from 11.0.0 (`discovery/agents.ts`; 10.6.2 doesn't). OmO runs on senpi, whose oldest version on npm (0.74.0) already reads it. A Pi or omp whose version isn't known is taken as older, as before. Every reader goes through `Target.readsSharedDir`: `Always` (the row's lock), `syncSkills`' `inShared` (no second link in its own folder) and `readsSharedHere` for a handover (usrname1833 on Discord; `TestPiReadsSharedSkillsFromItsVersion`). A user's own skill in `~/.agents/skills` by the library skill's name (another installer's, such as the skills CLI's, or copied by hand: not magpie's link or marked copy, not the library's own folder) counts too, under that folder name or another whose `SKILL.md` gives the name (`readSharedOwn`, `sharedOwn.rival`), since Pi 1.4.0 knows a skill by that name and drops one read twice only when both paths are one file (`realPathSet` in dist/core/skills.js): it warned of a collision for the two trees. Such a reader gets nothing in its own folder, and magpie's link or marked copy there, an older magpie's too, goes on the next sync. When it holds the library's very files (`sameTree`) the reader has the library's already. When it holds other files the reader has a skill of its own by that name, an `Own` problem settled as one in its own folder: Keep {agent}'s unticks it, Use the library's sets the shared entry aside with the backups (every other reader of the folder loses it too) and gives the library's (math_milian on Discord; `TestSharedCopyNotGivenTwice`, `TestSharedCopyOtherFolderName`, `TestSharedOwnSettled`). The user's entry is otherwise never touched. Not covered: a library skill that is a link to the agent's own folder (brought in from there) beside such a copy keeps both, since that folder is the library's; OpenCode reads Claude Code's folder and the shared one into one map by name, so it finds Claude Code's link and the user's copy as one skill; and a Pi or omp of unknown version is given its own as before.
|
||||
- Put skills in (`Library.SharedSkills`; `SetSkillsWhere`, `POST /api/library/skills/where` with `how` `agents` or `shared`; `magpie library skill where agents|shared`; the Skills tab's bar under How, `skillWhereBar` in plugins/library/client.js; usrname1833 on Discord). Off, the default and what a library.json from before reads as, each agent gets the skills ticked for it in its own folder. On, every library skill on here (`keepsShared`: not `OffHere`, its folder there) also gets magpie's link in `~/.agents/skills` (`syncShared`, run after `sweepShared`), so every agent and tool that reads that folder has it, ticked or not, and is in its `Always`. The files stay in the library, so updates, checks, edit tracking and Off here work as before, and nothing is moved when it is turned on: existing skills just get links. An entry of the user's own by a skill's name is left alone, silently, and the agents ticked for the library's skill still get it in their own folders, unless they read the folder themselves (`sharedOwn.rival`, above). A sync leaves an existing link as it is. A skill given to the folder's own agent (Kimi Code, Goose, Cindy) is that agent's sync's. Turned off, `sweepShared` takes out magpie's links there and nothing else, and each agent's own links come back. It is this computer's: `Collect` never carries it (`TestSkillsWhereShared`, `TestSkillsWhereSharedWithKimi`, `skill-where.test.cjs`). Not covered: on Windows without the right to make links the entry is a marked copy; a stale one is set aside and copied again, but `takeEdits` doesn't take edits made in that copy into the library, so they go to the backups when the setting is turned off or the skill changes (#4958). [`skills_shared.go`](../../internal/library/skills_shared.go)
|
||||
- A skill's files are read and edited in the page (refeccd on Discord: skills handed over from `~/.agents/skills` had nowhere else to be edited). `GET /api/library/skill?name=&file=` answers `ReadSkillFile`: the file (`SKILL.md` when none is named), its text, the skill's folder and `files`, its text files (`skillTextFiles`: UTF-8 with no NUL, up to 1 MB each and 200 in all, `SKILL.md` first, leaving out links, hidden folders, `skipInSkill`'s entries and what installing writes, `fromInstall`). `SaveSkillFile` (`POST /api/library/skills/save` with `name`, `file`, `text` and `was`) goes through `change`: it writes only a regular file already in the skill's folder, never through a link or out of the folder (`skillFilePath`), refuses when the file no longer holds `was`, the text the page opened, keeps a file's CRLF line ends, and writes with `edit.WriteAtomic`. It writes the library's folder, so a linked agent reads it at once and the sync that follows copies it again into each copy; a copy edited in an agent before it is older than the save, so `takeEdits` keeps that edit aside with the backups. A skill from GitHub or git saved here reads as changed here (`editState`), so an update asks before it replaces the edit. The page (`viewSkill`, `rendered` in plugins/library/client.js) draws a Markdown file with the Plugins page's renderer (`window.mdRender`, `markdown` in plugins.js) and its front matter as rows, any other file as its text; Edit swaps in a text box, ⌘S or Save sends it, and the skill's other files are the app's menu under its name (`TestSavedSkillFileReachesEveryAgent`, `TestSkillFileSaveRefusesAChangedFile`, `TestSkillFileStaysInTheSkill`, `TestSkillFileKeepsLineEnds`, `skill-edit.test.cjs`). Not covered: the TUI and CLI have no editor; a new file can't be made, and a file can't be renamed or removed, here. [`skill_file.go`](../../internal/library/skill_file.go)
|
||||
- WorkBuddy's servers go in `$WORKBUDDY_CONFIG_DIR/mcp.json` (default `~/.workbuddy`; WorkBuddy AI, the international build, keeps its own in `~/.workbuddy-ai`, #1494), and CodeBuddy Code's go in the first of `.mcp.json`, `mcp.json` and `~/.codebuddy.json` that exists, as `resolveMcpFilePath` reads them (#1266). WorkBuddy connects a server only after the user has switched it on once in its own MCP settings. It keeps that approval in `mcp-approvals.json`, keyed by the command, args and env names or the URL's origin, so changing those asks again. magpie never writes the approval, and the servers page says so, by the build's name, when a server is given to WorkBuddy or WorkBuddy AI.
|
||||
- Alma's servers go in `~/.config/alma/mcp.json` on every system (its home, not its data folder), as its own MCP settings write them: `command`/`args`/`env`, or `url`/`headers` with `transport: "sse"` only for SSE (#1292). Alma reads the file as it starts and when its MCP settings refresh, so a server given to it while it runs reaches it after one of those.
|
||||
|
||||
@@ -111,7 +111,15 @@ func TestKimiSweepLeavesTheUsersOwnSharedSkills(t *testing.T) {
|
||||
src := filepath.Join(h, "src/skills")
|
||||
skill(t, filepath.Join(src, "pdf"), "pdf", "Read PDFs")
|
||||
skill(t, filepath.Join(src, "orca"), "orca", "Orca")
|
||||
ok(t)(InstallSkills(src, []string{"pdf"}, []string{"kimi"}))
|
||||
// the user's own pdf there is Kimi Code's own by that name: no second
|
||||
// one beside it, the user's to settle
|
||||
if r, err := InstallSkills(src, []string{"pdf"}, []string{"kimi"}); err != nil || len(r.Problems) != 1 || r.Problems[0].Agent != "kimi" || !r.Problems[0].Own {
|
||||
t.Fatalf("pdf: %+v %v", r, err)
|
||||
}
|
||||
if _, err := os.Lstat(filepath.Join(h, ".kimi-code/skills/pdf")); !os.IsNotExist(err) {
|
||||
t.Errorf("Kimi Code has the library's pdf beside the user's: %v", err)
|
||||
}
|
||||
ok(t)(KeepAgentSkill("pdf", "kimi"))
|
||||
ok(t)(InstallSkills(src, []string{"orca"}, []string{"kimi", "codex"}))
|
||||
ok(t)(Sync())
|
||||
ok(t)(Sync())
|
||||
|
||||
+104
-17
@@ -586,19 +586,76 @@ func sharedEntry(name string) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
// sharedCopy is whether p, the entry in ~/.agents/skills by a library
|
||||
// skill's name, is the user's own copy of the library's very files: not
|
||||
// one magpie made (ours), not the library's own folder (sharedEntry), and
|
||||
// holding what the library's holds.
|
||||
func sharedCopy(p, name string) bool {
|
||||
if _, err := os.Lstat(p); err != nil || ours(p, name) {
|
||||
return false
|
||||
// sharedOwn is the user's own skills in ~/.agents/skills (another
|
||||
// installer's, such as the skills CLI's, or copied by hand) by the name an
|
||||
// agent reading that folder knows each by: its SKILL.md's name, else its
|
||||
// folder's. Pi, Codex and Gemini CLI go by that name, so a library skill
|
||||
// by it given to such an agent in its own folder too is the skill twice
|
||||
// (math_milian: Pi's "hunk-review" collision). magpie's own entries there
|
||||
// (a link into the library, a marked copy) and the library's own folders
|
||||
// aren't the user's and aren't in it.
|
||||
type sharedOwn map[string][]string
|
||||
|
||||
func readSharedOwn() sharedOwn {
|
||||
out := sharedOwn{}
|
||||
dir := sharedSkillsDir()
|
||||
es, err := os.ReadDir(dir)
|
||||
if err != nil {
|
||||
return out
|
||||
}
|
||||
lib := realDir(skillsDir())
|
||||
for _, e := range es {
|
||||
q := filepath.Join(dir, e.Name())
|
||||
if to, ok := linkTarget(q); ok && within(filepath.Clean(to), skillsDir()) || within(realDir(q), lib) {
|
||||
continue
|
||||
}
|
||||
if _, err := os.Stat(filepath.Join(q, marker)); err == nil {
|
||||
continue
|
||||
}
|
||||
m, ok := readMeta(q)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
n := m.Name
|
||||
if n == "" {
|
||||
n = e.Name()
|
||||
}
|
||||
// the entry by the folder's own name first
|
||||
if e.Name() == n {
|
||||
out[n] = append([]string{q}, out[n]...)
|
||||
} else {
|
||||
out[n] = append(out[n], q)
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// rival is the user's own entry in ~/.agents/skills an agent reading that
|
||||
// folder finds by the library skill's name (or the name its SKILL.md
|
||||
// gives), and whether it holds the library's very files. "" when none.
|
||||
func (o sharedOwn) rival(name string) (p string, same bool) {
|
||||
lib := skillDir(name)
|
||||
if _, err := os.Stat(lib); err != nil || realDir(p) == realDir(lib) {
|
||||
return false
|
||||
if _, err := os.Stat(lib); err != nil {
|
||||
return "", false
|
||||
}
|
||||
return sameTree(p, lib)
|
||||
names := []string{name}
|
||||
if m, ok := readMeta(lib); ok && m.Name != "" && m.Name != name {
|
||||
names = append(names, m.Name)
|
||||
}
|
||||
for _, n := range names {
|
||||
for _, q := range o[n] {
|
||||
if realDir(q) == realDir(lib) {
|
||||
continue
|
||||
}
|
||||
if sameTree(q, lib) {
|
||||
return q, true
|
||||
}
|
||||
if p == "" {
|
||||
p = q
|
||||
}
|
||||
}
|
||||
}
|
||||
return p, false
|
||||
}
|
||||
|
||||
// within is whether p is dir or inside it.
|
||||
@@ -643,6 +700,14 @@ func (l *Library) syncSkills(t *Target, res *Result, all []*Target) {
|
||||
// its own too would be the skill twice
|
||||
shared := realDir(sharedSkillsDir())
|
||||
isShared := realDir(t.Skills) == shared
|
||||
// the user's own skills there, read once for this agent
|
||||
var own sharedOwn
|
||||
rivals := func() sharedOwn {
|
||||
if own == nil {
|
||||
own = readSharedOwn()
|
||||
}
|
||||
return own
|
||||
}
|
||||
inShared := func(s *Skill) bool {
|
||||
if s == nil || !t.readsSharedDir() || realDir(t.Skills) == shared {
|
||||
return false
|
||||
@@ -658,13 +723,18 @@ func (l *Library) syncSkills(t *Target, res *Result, all []*Target) {
|
||||
}) && (ours(p, s.Name) || realDir(p) == realDir(skillDir(s.Name))) {
|
||||
return true
|
||||
}
|
||||
// the user's own copy of the very same files kept in the shared
|
||||
// folder (another installer's, or one copied by hand): the agent
|
||||
// finds it there, and a link or copy of the library's in its own
|
||||
// folder too is a second tree by that name. pi loads both and
|
||||
// warns of a collision, since it drops a skill read twice only
|
||||
// when both paths lead to one file (realpath, dist/core/skills.js)
|
||||
return sharedCopy(p, s.Name)
|
||||
// the user's own skill by that name kept in the shared folder
|
||||
// (another installer's, or one copied by hand), under that folder
|
||||
// name or another: the agent finds it there, and a link or copy of
|
||||
// the library's in its own folder too is a second skill by that
|
||||
// name. Pi loads both and warns of a collision, since it drops a
|
||||
// skill read twice only when both paths lead to one file
|
||||
// (realpath, dist/core/skills.js), and goes by the SKILL.md name.
|
||||
// The very same files: the agent has the library's already. Other
|
||||
// files: it has one of its own by that name, which the user
|
||||
// settles (UseLibrarySkill, KeepAgentSkill)
|
||||
q, _ := rivals().rival(s.Name)
|
||||
return q != ""
|
||||
}
|
||||
var mine []string
|
||||
for _, name := range a.Skills {
|
||||
@@ -727,6 +797,13 @@ func (l *Library) syncSkills(t *Target, res *Result, all []*Target) {
|
||||
}
|
||||
}
|
||||
if inShared(s) {
|
||||
// the user's own skill by that name in ~/.agents/skills, not the
|
||||
// library's files: the agent has a skill of its own called so,
|
||||
// the user's to settle as for one in its own folder
|
||||
if q, same := rivals().rival(s.Name); q != "" && !same {
|
||||
res.Problems = append(res.Problems, Problem{Agent: id, What: "skill:" + s.Name, Own: true,
|
||||
Error: fmt.Sprintf("%s already has a skill of its own called %s, in %s", t.Agent.Name, s.Name, q)})
|
||||
}
|
||||
// a copy of its own of the very same files would be the skill
|
||||
// twice as much as a link: kept aside, as it would be for one
|
||||
if _, err := os.Lstat(p); err == nil && !ours(p, s.Name) && realDir(p) != realDir(skillDir(s.Name)) && sameTree(p, skillDir(s.Name)) {
|
||||
@@ -2091,6 +2168,16 @@ func UseLibrarySkills(names []string, agentID string) (*Result, error) {
|
||||
return err
|
||||
}
|
||||
}
|
||||
// its own by that name is the user's in ~/.agents/skills, which
|
||||
// it reads besides its own folder: that one is set aside (every
|
||||
// other reader of the folder had it as its own too)
|
||||
if t.readsSharedDir() && realDir(t.Skills) != realDir(sharedSkillsDir()) {
|
||||
if q, same := readSharedOwn().rival(name); q != "" && !same {
|
||||
if _, err := setAside(t.Agent.ID, q); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
if !slices.Contains(s.Agents, t.Agent.ID) && !slices.ContainsFunc(sharing(t), func(o string) bool { return slices.Contains(s.Agents, o) }) {
|
||||
s.Agents = set(s.Agents, t.Agent.ID, true)
|
||||
}
|
||||
|
||||
@@ -52,15 +52,27 @@ func TestSharedCopyNotGivenTwice(t *testing.T) {
|
||||
t.Error("the user's copy in ~/.agents/skills was touched")
|
||||
}
|
||||
|
||||
// the user's copy changes: it is another skill by that name,
|
||||
// and the library's is given again
|
||||
// the user's copy changes: it is a skill of each reader's own by
|
||||
// that name, which the user settles; a second one beside it is
|
||||
// still the skill twice
|
||||
write(t, filepath.Join(shared, "SKILL.md"), "---\nname: hunk-review\ndescription: Mine\n---\n")
|
||||
ok(t)(Sync())
|
||||
r, err := Sync()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, p := range []string{pi, cx} {
|
||||
if !ours(p, "hunk-review") {
|
||||
t.Errorf("%s hasn't the library's again", p)
|
||||
if _, err := os.Lstat(p); !os.IsNotExist(err) {
|
||||
t.Errorf("%s has the library's beside the user's own: %v", p, err)
|
||||
}
|
||||
}
|
||||
for _, id := range []string{"pi", "codex"} {
|
||||
if !ownProblem(r, id, "hunk-review") {
|
||||
t.Errorf("%s isn't said to have its own hunk-review: %+v", id, r.Problems)
|
||||
}
|
||||
}
|
||||
if ownProblem(r, "claude", "hunk-review") || !ours(cl, "hunk-review") {
|
||||
t.Error("claude reads no ~/.agents/skills, yet was touched")
|
||||
}
|
||||
if read(t, filepath.Join(shared, "SKILL.md")) != "---\nname: hunk-review\ndescription: Mine\n---\n" {
|
||||
t.Error("the user's changed copy was touched")
|
||||
}
|
||||
@@ -83,3 +95,106 @@ func TestSharedCopyOldPiKeepsItsOwn(t *testing.T) {
|
||||
t.Error("pi 0.53 lost its own link")
|
||||
}
|
||||
}
|
||||
|
||||
func ownProblem(r *Result, agent, name string) bool {
|
||||
for _, p := range r.Problems {
|
||||
if p.Agent == agent && p.What == "skill:"+name && p.Own {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// The user's own copy kept in ~/.agents/skills under another folder name
|
||||
// (hunk-review-main, as a repository's checkout names it): Pi, Codex and
|
||||
// Gemini CLI know a skill by its SKILL.md's name, so the library's in
|
||||
// their own folder too is the skill twice. A magpie link left there by an
|
||||
// older magpie goes on the next sync.
|
||||
func TestSharedCopyOtherFolderName(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, "1.4.0")
|
||||
src := filepath.Join(h, "src/skills")
|
||||
skill(t, filepath.Join(src, "hunk-review"), "hunk-review", "Review hunks")
|
||||
ok(t)(InstallSkills(src, []string{"hunk-review"}, []string{"claude", "codex", "pi", "gemini"}))
|
||||
pi := filepath.Join(h, ".pi/agent/skills/hunk-review")
|
||||
if !ours(pi, "hunk-review") {
|
||||
t.Fatal("pi isn't given it")
|
||||
}
|
||||
shared := filepath.Join(h, ".agents/skills/hunk-review-main")
|
||||
skill(t, shared, "hunk-review", "Review hunks")
|
||||
ok(t)(Sync())
|
||||
for _, d := range []string{".pi/agent/skills", ".codex/skills", ".gemini/skills"} {
|
||||
if _, err := os.Lstat(filepath.Join(h, d, "hunk-review")); !os.IsNotExist(err) {
|
||||
t.Errorf("%s still has a second one: %v", d, err)
|
||||
}
|
||||
}
|
||||
if !ours(filepath.Join(h, ".claude/skills/hunk-review"), "hunk-review") {
|
||||
t.Error("claude lost it")
|
||||
}
|
||||
if !exists(filepath.Join(shared, "SKILL.md")) {
|
||||
t.Error("the user's copy was touched")
|
||||
}
|
||||
}
|
||||
|
||||
// The user's own hunk-review in ~/.agents/skills differs from the
|
||||
// library's (the skills CLI updated it): each reader has one of its own,
|
||||
// and the user settles it. Use the library's sets the shared one aside
|
||||
// with the backups and gives the library's; Keep leaves the reader the
|
||||
// user's, with nothing of the library's beside it.
|
||||
func TestSharedOwnSettled(t *testing.T) {
|
||||
for _, how := range []string{"use", "keep"} {
|
||||
t.Run(how, func(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, "1.4.0")
|
||||
src := filepath.Join(h, "src/skills")
|
||||
skill(t, filepath.Join(src, "hunk-review"), "hunk-review", "Review hunks")
|
||||
shared := filepath.Join(h, ".agents/skills/hunk-review")
|
||||
skill(t, shared, "hunk-review", "Review hunks, older")
|
||||
r, err := InstallSkills(src, []string{"hunk-review"}, []string{"codex", "pi"})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !ownProblem(r, "pi", "hunk-review") || !ownProblem(r, "codex", "hunk-review") {
|
||||
t.Fatalf("not said: %+v", r.Problems)
|
||||
}
|
||||
pi := filepath.Join(h, ".pi/agent/skills/hunk-review")
|
||||
if _, err := os.Lstat(pi); !os.IsNotExist(err) {
|
||||
t.Fatalf("pi got a second one: %v", err)
|
||||
}
|
||||
if how == "keep" {
|
||||
r, err := KeepAgentSkill("hunk-review", "pi")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if ownProblem(r, "pi", "hunk-review") {
|
||||
t.Error("pi still asked after keeping its own")
|
||||
}
|
||||
if _, err := os.Lstat(pi); !os.IsNotExist(err) || !exists(filepath.Join(shared, "SKILL.md")) {
|
||||
t.Error("keeping its own changed something")
|
||||
}
|
||||
return
|
||||
}
|
||||
r, err = UseLibrarySkill("hunk-review", "pi")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if ownProblem(r, "pi", "hunk-review") || ownProblem(r, "codex", "hunk-review") {
|
||||
t.Errorf("still asked: %+v", r.Problems)
|
||||
}
|
||||
if _, err := os.Lstat(shared); !os.IsNotExist(err) {
|
||||
t.Error("the user's own wasn't set aside")
|
||||
}
|
||||
for _, p := range []string{pi, filepath.Join(h, ".codex/skills/hunk-review")} {
|
||||
if !ours(p, "hunk-review") {
|
||||
t.Errorf("%s hasn't the library's", p)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -168,15 +168,26 @@ func TestSkillsWhereShared(t *testing.T) {
|
||||
}
|
||||
|
||||
// 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")
|
||||
// theirs stays; an agent that doesn't read the folder gets the
|
||||
// library's, and one that does (Pi) has a skill of its own by that
|
||||
// name, the user's to settle, with no second one beside it
|
||||
r, err := InstallSkills(src, []string{"mine"}, []string{"claude", "pi"})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(r.Problems) != 1 || r.Problems[0].Agent != "pi" || !r.Problems[0].Own {
|
||||
t.Errorf("problems: %+v", r.Problems)
|
||||
}
|
||||
if _, err := os.Lstat(filepath.Join(h, ".pi/agent/skills/mine")); !os.IsNotExist(err) {
|
||||
t.Errorf("pi has the library's mine beside the user's: %v", err)
|
||||
}
|
||||
if !ours(filepath.Join(h, ".claude/skills/mine"), "mine") {
|
||||
t.Error("claude 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")
|
||||
}
|
||||
ok(t)(KeepAgentSkill("mine", "pi"))
|
||||
|
||||
// off on this computer: out of ~/.agents/skills, and pi's own is back
|
||||
ok(t)(SkillHere("pdf", false))
|
||||
@@ -196,7 +207,7 @@ func TestSkillsWhereShared(t *testing.T) {
|
||||
|
||||
// back to each agent's folder: magpie's links there go, nothing else
|
||||
ok(t)(SkillAgents("pdf", []string{"claude", "pi"}))
|
||||
r, err := SetSkillsWhere(SkillsInAgents)
|
||||
r, err = SetSkillsWhere(SkillsInAgents)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user