diff --git a/docs/subsystems/library.md b/docs/subsystems/library.md index aa140f59b..5577d0517 100644 --- a/docs/subsystems/library.md +++ b/docs/subsystems/library.md @@ -28,7 +28,7 @@ Pi's extensions and packages. | MCP server on/off | `ServerOn` (`POST /api/library/servers/on` with `name` and `on`, `magpie library mcp off|on `) turns a server off for everyone without removing it (swang20201 on X, Docker gateway mode, where a server ticked for no agent is still given to every app at the MCP router's address). Off, it is `Hidden` with its agents kept in `Paused` and `Agents` empty, as a plugin's server hidden from agents is (`PluginServerOn`, [Plugin tools](plugin-tools.md)): no agent's file has it, no project's (`syncProjectMCP` skips it, keeping the project's own agents for it), no subagent names it (`renderSubagent`), the router lists and calls it for nobody, and a process the router held for it ends, since `Hidden` and `Paused` are part of its `hubKey`. Its command, URL, env, headers, sign-in, `DisabledTools` and note stay in library.json. On, the agents in `Paused` get it back (none when it had none, so the router gives it to other apps again), as before it was turned off; giving it agents (`ServerAgents`, the CLI's `mcp agents`) turns it on with those (`save`), while Turn all on (`EveryServerAgents` with every agent) leaves it off. The row's switch sits after its agent chips (`serverSwitch` in plugins/library/client.js); off, the row is dimmed, its chips take no click, and it is health-checked only on a click (`TestServerOnKeepsAndRestores`, `TestLibraryMCPOffOn`, `library-mcp-on.test.cjs`). | [`mcp_on.go`](../../internal/library/mcp_on.go), [`project_mcp.go`](../../internal/library/project_mcp.go), [`subagents.go`](../../internal/library/subagents.go) | | MCP router | With `MCPHub` on, `syncMCP` gives each agent that can take it one entry, `magpie`, at the gateway's `/mcp/magpie/hub/`, in place of the servers ticked for it; magpie runs those servers itself, once for every agent. | [MCP router](mcp-router.md), [`mcp_hub.go`](../../internal/library/mcp_hub.go) | | MCP market | `MarketServers` lists the featured servers that match a search, then the MCP Registry's; a search that is an address (a repository, a page, an endpoint, a package; `market_addr.go`) finds the ones at it, and `CustomAt` offers one to fill in by hand when none is. The registry lists no server by a repository's folder, so a GitHub address naming one (`#subdirectory=`, `/tree//…`, `parseRepoAt`) is read first: the folder's `pyproject.toml` names the program, and the README's `"env": {…}` examples the keys, offered as `uvx --from git+https://github.com/o/r#subdirectory=p ` (`fromRepo`, CyberCaius on Discord: volcengine/mcp-server's askecho search). A bare repository is read so only when the registry has nothing at it, and a PyPI page, or a one-word search naming mcp the registry lists nothing by, asks PyPI (`fromPyPI`, `uvx `). Of several README keys none is required, since a README often has the user pick one way to sign in (`envInputs`; `TestMarketServerInRepoFolder`). Only Python projects are read from a folder; a Node one there still gets the blank form. A registry package is started the way its entry says (`launchLine`): its `runtimeArguments` are the runner's options (`uvx -p 3.13`, `npx --package`, docker's mounts) and the program's own words (Serena's `start-mcp-server`), then its `packageArguments`; an executable not named after the package is reached with `uvx --from ` or `npx --package `. The shipped crawl keeps each package's executables (`bins`, from npm's `bin` and the wheel's console scripts); a package with none, several with none standing out (`pickBin`), or a required option magpie can't fill isn't offered. A server installed from the market before, still on the line magpie gave it then, is given the new one on load (`healMarketLines`; fwxkogaia on X, `TestRegistryLaunchLines`, `TestInstalledMarketLineHealed`). | [`market.go`](../../internal/library/market.go), [`market_launch.go`](../../internal/library/market_launch.go), [`market_repo.go`](../../internal/library/market_repo.go) | -| Skills | A skill is a folder with a `SKILL.md`. It goes by the `name` its front matter gives, made fit for a file name (ASCII letters, digits, `_` and `-`); a name that would lose a letter or digit that way (one in another script, `CTF•密码学`) or none goes by its folder's name instead, and a skill at a repository's top by the repository's (`nameFor`, `srcFolder`). A front matter setting `disable-model-invocation: true` marks it "Manual only" in the page, in the library and in the agents' own (`meta.Manual`, `SkillView.Manual`, `FoundSkill.Manual`; sunset3279 on Discord): Claude Code runs such a skill only on the user's `/name`. A front matter that doesn't parse, or a value that isn't a bool, is not known to be, and gets no mark (`TestSkillManualFromFrontMatter`, `skill-manual.test.cjs`). Two skills a probe names alike are listed once (`unhiddenFirst`), so names that fell to `CTF`, `Strix` and nothing listed asdfgh1445/ctf-super-hub's 35 skills as 16 (tnt1223 on Discord, `TestSkillsNamedInAnotherScriptAllListed`). It comes from GitHub, from any other git repository, from a folder on this machine (linked, so editing the folder edits the skill) or from the market. A git repository (`kind: git`, sunset on Discord: GitLab, a company's own GitLab) is any https, http, ssh or `file://` address, `git@host:group/repo.git`, a bare `host.name/group/repo`, or a GitLab or Gitea page of a folder (`/-/tree//`, `/-/blob/…`, `/src/branch/…`; a branch with a `/` in its name is read as its first segment) (`gitSource`). It is fetched by the user's own `git` (`proc.FindTool`), so their credential helpers and SSH keys reach an intranet host: `git init`, then `fetch --depth 1 --no-tags -- ` and `checkout FETCH_HEAD` into a `magpie-skill-*` folder, then its `.git` is removed (`fetchGit`). What the user typed is data: an address starting with `-` and a `transport::` address (`ext::`, `fd::`, `file::`) are refused before git runs, the address follows `--`, git runs with `protocol.ext.allow=never` and `core.symlinks=false`, no shell, `GIT_TERMINAL_PROMPT=0` and (unless the user set an SSH command) `ssh -o BatchMode=yes`, so a sign-in it can't make fails instead of waiting. An address with a password or token in it is refused: library.json is shown and backed up. Git missing, a sign-in refused, a host key unknown, a branch missing and a host unreachable each say so (`gitError`; `TestGitSourceReads`, `TestInstallFromGitRepo`, `TestGitTreeURLInstallsFolder`, `TestGitMissingSaysSo`, `TestGitSignInRefusedSaysSo`, `TestGitRefusesOptionsAndTransports`, `TestGitErrorsSaid`). Each agent gets a link or a marked copy (#896, `SkillHow`). An agent in a WSL distro gets a link too, to the distro's one copy of the skill, magpie's, in `~/.local/share/magpie/skills` (`Target.Store`, `storeSkill`; cutemmuu on X): the distro can't follow a link to the library's folder on Windows, and a link Windows makes through `\\wsl.localhost` is an empty folder in the distro, which in turn shows Windows its own links as entries it can't read, follow or remove, so the link is made, read and taken away in the distro by wsl.exe (`agent.WSLSymlink`, `WSLReadlink`, `WSLRemoveLink`; `TestWSLLinksLive` and `TestWSLSkillsLinkedLive` on a real distro with `MAGPIE_WSL_TEST_DISTRO`). An edit made through the link is in the distro's copy, which `takeEdits` reads as any copy of magpie's (`TestWSLEditThroughLinkReachesTheLibrary`); a copy no agent there links to or is given any more goes, to the backups when edited (`sweepWSLStores`, `TestWSLStoreSweepKeepsEdits`); a folder there that isn't magpie's is never touched, and each agent it is in the way of says so. The copy isn't put in the distro's `~/.agents/skills`, since every agent there reading that folder would get each skill, ticked for it or not. An agent set to copies gets one of its own, as does one whose skills folder or the store is on a Windows drive (#4502), where the distro's link is one Windows can't read. A copy an agent there was given before is made a link on the next sync, its edit taken first and a losing edit set aside (`wslRelink`, `TestWSLOldCopiesBecomeLinks`). A copy's mark keeps the hash of what was copied, so a sync knows a copy unchanged since then is current without reading its files (`copyIsFresh`, #1031); other copies are hashed. A skill of the user's own is made with `CreateSkill` (`POST /api/library/skills/create`, Skills > New skill; josephBenchap on X): a name (`checkName`, and not one the library or an agent has, compared without case, nor a folder in the way) and a one-line description of at most 1024 characters make `skills//SKILL.md` with `name` and `description` front matter, listed with no source and given to the agents picked; the page then opens it in the reader (`TestCreateSkill`, `library-new-skill.test.cjs`). A skill an agent has of its own (`foundSkills`, the page's "In your agents") is brought in with `ImportSkill`, or taken out of every agent that has it with `RemoveFoundSkill` (#1303): its folders and copies of the very same files, its shared `~/.agents/skills` entry and a folder of it in the library's own folder go to the backups, its links are taken away, and a folder elsewhere it only links to, or another skill by that name, stays. Several go at once with `RemoveFoundSkills` (`POST /api/library/skills/remove-found-some`, wongxy on Discord): the "In your agents" heading's own Select picks them, and Remove… asks once, naming the count, before one change takes each out as `RemoveFoundSkill` would. A name that can't be taken out is left as it was, in `Result.Unremoved`, and stays picked with its error in its row's place (`foundErrs`); when none can go the change fails and nothing is touched. This Select and the library's are never on together: while one is on the other is dimmed, saying why, so neither click takes the other's bar away from above the pointer (`TestRemoveFoundSkills`, `found-skill-pick-remove.test.cjs`). A repository is fetched as one tarball of at most `maxFetch` (200 MB); a bigger one is fetched file by file from its tree (`fetchSkillFiles`), only as far as the caller reads: a link to a folder and an update ask GitHub for that folder's own list (`treeUnder`, git's `ref:path`; the whole list when that fails), the market fetches only the skills whose folder is the one it installs (#2794, sickn33/agentic-awesome-skills' 8,589 skills are 287 MB together), and a fetcher keeps such a part apart from another skill's of the same repository, which would otherwise read as removed (`fetcher.get`, `TestMarketSkillFromAHugeRepository`). GitHub's list is read up to `maxTree` (64 MB; that repository's is 11 MB) and an answer over the cap a caller gives `apiGet`, or one cut off, is an error saying so, never a body cut short for JSON to trip on (ye4241's `TestRepoTreeBigList`, `TestApiGetWholeAnswer`); a list GitHub truncated itself is too big (`TestTruncatedListIsTooBig`). And a skill over 200 MB on its own is left out rather than failing the rest: the probe lists the others and names it in `Probe.Left`, under the list in the page and in the TUI's flash. Only when every skill is too big does the fetch fail (#2062, mikubaka88/CCFA-Skills' 297 MB ccf-paper-writer; `TestOneSkillTooBigLeavesTheOthers`, `skill-too-big.test.cjs`). A probe keeps its download for the install from it for 15 minutes (`keepProbe`, `probeLife`), and removes it when it is probed again or that time is up, not at the next probe, which may never come. A download a magpie that quit left in the temp dir goes at the next probe once it is an hour old (`sweepStaleDownloads`). The package's TestMain gives the tests a temp dir of their own and fails a run that leaves a `magpie-skill-*` in it (#2321, `TestProbeDownloadEndsWithIt`, `TestStaleDownloadsSwept`). | [`skilltree.go`](../../internal/library/skilltree.go), [`skills.go`](../../internal/library/skills.go), [`skillgit.go`](../../internal/library/skillgit.go), [`skill_how.go`](../../internal/library/skill_how.go), [`skill_edits.go`](../../internal/library/skill_edits.go), [`skill_from.go`](../../internal/library/skill_from.go), [`skill_beside.go`](../../internal/library/skill_beside.go) | +| Skills | A skill is a folder with a `SKILL.md`. It goes by the `name` its front matter gives, made fit for a file name (ASCII letters, digits, `_` and `-`); a name that would lose a letter or digit that way (one in another script, `CTF•密码学`) or none goes by its folder's name instead, and a skill at a repository's top by the repository's (`nameFor`, `srcFolder`). A front matter setting `disable-model-invocation: true` marks it "Manual only" in the page, in the library and in the agents' own (`meta.Manual`, `SkillView.Manual`, `FoundSkill.Manual`; sunset3279 on Discord): Claude Code runs such a skill only on the user's `/name`. A front matter that doesn't parse, or a value that isn't a bool, is not known to be, and gets no mark (`TestSkillManualFromFrontMatter`, `skill-manual.test.cjs`). Two skills a probe names alike are listed once (`unhiddenFirst`), so names that fell to `CTF`, `Strix` and nothing listed asdfgh1445/ctf-super-hub's 35 skills as 16 (tnt1223 on Discord, `TestSkillsNamedInAnotherScriptAllListed`). It comes from GitHub, from any other git repository, from a folder on this machine (linked, so editing the folder edits the skill) or from the market. A git repository (`kind: git`, sunset on Discord: GitLab, a company's own GitLab) is any https, http, ssh or `file://` address, `git@host:group/repo.git`, a bare `host.name/group/repo`, or a GitLab or Gitea page of a folder (`/-/tree//`, `/-/blob/…`, `/src/branch/…`; a branch with a `/` in its name is read as its first segment) (`gitSource`). It is fetched by the user's own `git` (`proc.FindTool`), so their credential helpers and SSH keys reach an intranet host: `git init`, then `fetch --depth 1 --no-tags -- ` and `checkout FETCH_HEAD` into a `magpie-skill-*` folder, then its `.git` is removed (`fetchGit`). What the user typed is data: an address starting with `-` and a `transport::` address (`ext::`, `fd::`, `file::`) are refused before git runs, the address follows `--`, git runs with `protocol.ext.allow=never` and `core.symlinks=false`, no shell, `GIT_TERMINAL_PROMPT=0` and (unless the user set an SSH command) `ssh -o BatchMode=yes`, so a sign-in it can't make fails instead of waiting. An address with a password or token in it is refused: library.json is shown and backed up. Git missing, a sign-in refused, a host key unknown, a branch missing and a host unreachable each say so (`gitError`; `TestGitSourceReads`, `TestInstallFromGitRepo`, `TestGitTreeURLInstallsFolder`, `TestGitMissingSaysSo`, `TestGitSignInRefusedSaysSo`, `TestGitRefusesOptionsAndTransports`, `TestGitErrorsSaid`). Each agent gets a link or a marked copy (#896, `SkillHow`). On Windows, Antigravity (the app and agy) and Crush get copies only (`junctionBlind`, `skipsJunctions`, `Target.Copy`; #5107, #6610): they are Go programs that keep a skills-folder entry only when it is a folder or a symlink, and Go lists a junction, magpie's link where the user may not make a symlink, as neither (`ModeIrregular`), so a junctioned skill never showed there; GetAllSkills of Antigravity 2.30's language server and Crush 0.101's prompt list a folder and a symlink and leave out a junction, and agy 1.5.8 on macOS takes a symlink leading out of its folder. A junction in `~/.agents/skills` is no skill to them either (`inShared`), and a project entry one of them reads is a copy too (`syncFolder`); an edit in a project's copy goes to the library as one in an agent's copy does (`takeEdits`). An agent in a WSL distro gets a link too, to the distro's one copy of the skill, magpie's, in `~/.local/share/magpie/skills` (`Target.Store`, `storeSkill`; cutemmuu on X): the distro can't follow a link to the library's folder on Windows, and a link Windows makes through `\\wsl.localhost` is an empty folder in the distro, which in turn shows Windows its own links as entries it can't read, follow or remove, so the link is made, read and taken away in the distro by wsl.exe (`agent.WSLSymlink`, `WSLReadlink`, `WSLRemoveLink`; `TestWSLLinksLive` and `TestWSLSkillsLinkedLive` on a real distro with `MAGPIE_WSL_TEST_DISTRO`). An edit made through the link is in the distro's copy, which `takeEdits` reads as any copy of magpie's (`TestWSLEditThroughLinkReachesTheLibrary`); a copy no agent there links to or is given any more goes, to the backups when edited (`sweepWSLStores`, `TestWSLStoreSweepKeepsEdits`); a folder there that isn't magpie's is never touched, and each agent it is in the way of says so. The copy isn't put in the distro's `~/.agents/skills`, since every agent there reading that folder would get each skill, ticked for it or not. An agent set to copies gets one of its own, as does one whose skills folder or the store is on a Windows drive (#4502), where the distro's link is one Windows can't read. A copy an agent there was given before is made a link on the next sync, its edit taken first and a losing edit set aside (`wslRelink`, `TestWSLOldCopiesBecomeLinks`). A copy's mark keeps the hash of what was copied, so a sync knows a copy unchanged since then is current without reading its files (`copyIsFresh`, #1031); other copies are hashed. A skill of the user's own is made with `CreateSkill` (`POST /api/library/skills/create`, Skills > New skill; josephBenchap on X): a name (`checkName`, and not one the library or an agent has, compared without case, nor a folder in the way) and a one-line description of at most 1024 characters make `skills//SKILL.md` with `name` and `description` front matter, listed with no source and given to the agents picked; the page then opens it in the reader (`TestCreateSkill`, `library-new-skill.test.cjs`). A skill an agent has of its own (`foundSkills`, the page's "In your agents") is brought in with `ImportSkill`, or taken out of every agent that has it with `RemoveFoundSkill` (#1303): its folders and copies of the very same files, its shared `~/.agents/skills` entry and a folder of it in the library's own folder go to the backups, its links are taken away, and a folder elsewhere it only links to, or another skill by that name, stays. Several go at once with `RemoveFoundSkills` (`POST /api/library/skills/remove-found-some`, wongxy on Discord): the "In your agents" heading's own Select picks them, and Remove… asks once, naming the count, before one change takes each out as `RemoveFoundSkill` would. A name that can't be taken out is left as it was, in `Result.Unremoved`, and stays picked with its error in its row's place (`foundErrs`); when none can go the change fails and nothing is touched. This Select and the library's are never on together: while one is on the other is dimmed, saying why, so neither click takes the other's bar away from above the pointer (`TestRemoveFoundSkills`, `found-skill-pick-remove.test.cjs`). A repository is fetched as one tarball of at most `maxFetch` (200 MB); a bigger one is fetched file by file from its tree (`fetchSkillFiles`), only as far as the caller reads: a link to a folder and an update ask GitHub for that folder's own list (`treeUnder`, git's `ref:path`; the whole list when that fails), the market fetches only the skills whose folder is the one it installs (#2794, sickn33/agentic-awesome-skills' 8,589 skills are 287 MB together), and a fetcher keeps such a part apart from another skill's of the same repository, which would otherwise read as removed (`fetcher.get`, `TestMarketSkillFromAHugeRepository`). GitHub's list is read up to `maxTree` (64 MB; that repository's is 11 MB) and an answer over the cap a caller gives `apiGet`, or one cut off, is an error saying so, never a body cut short for JSON to trip on (ye4241's `TestRepoTreeBigList`, `TestApiGetWholeAnswer`); a list GitHub truncated itself is too big (`TestTruncatedListIsTooBig`). And a skill over 200 MB on its own is left out rather than failing the rest: the probe lists the others and names it in `Probe.Left`, under the list in the page and in the TUI's flash. Only when every skill is too big does the fetch fail (#2062, mikubaka88/CCFA-Skills' 297 MB ccf-paper-writer; `TestOneSkillTooBigLeavesTheOthers`, `skill-too-big.test.cjs`). A probe keeps its download for the install from it for 15 minutes (`keepProbe`, `probeLife`), and removes it when it is probed again or that time is up, not at the next probe, which may never come. A download a magpie that quit left in the temp dir goes at the next probe once it is an hour old (`sweepStaleDownloads`). The package's TestMain gives the tests a temp dir of their own and fails a run that leaves a `magpie-skill-*` in it (#2321, `TestProbeDownloadEndsWithIt`, `TestStaleDownloadsSwept`). | [`skilltree.go`](../../internal/library/skilltree.go), [`skills.go`](../../internal/library/skills.go), [`skillgit.go`](../../internal/library/skillgit.go), [`skill_how.go`](../../internal/library/skill_how.go), [`skill_edits.go`](../../internal/library/skill_edits.go), [`skill_from.go`](../../internal/library/skill_from.go), [`skill_beside.go`](../../internal/library/skill_beside.go) | | Skills market | `MarketSkills` lists skills.sh's most installed and what its search finds. magpie's own skills (`featuredSkills`), in [magpie-community/plugins](https://github.com/magpie-community/plugins/tree/main/skills), go first, marked official: `magpie-setup` has an agent set magpie up as the user asks through its commands (providers, accounts, agents, routing groups and rules, gateway keys and limits, models, the library), and `magpie-quota` lets an agent read `magpie quota --json` and wait with `magpie quota wait`. Their commands live in magpie's CLI, so a change to a command either uses gets the skill updated in that repository. Until skills.sh lists one it has no count of installs and no skills.sh link (`featured`). `InstallMarketSkill` installs any of them from its repository. | [`market.go`](../../internal/library/market.go) | | Skills a repository or folder added | A check for updates (`CheckSkills`) also asks, for each GitHub repository and ref the library has skills from, GitHub's list of its files (`repoTree`, one API request, free when the ETag still matches). Only when that list has a skill folder beside the installed ones (under `newBase`, their deepest common folder) that the library doesn't have and hasn't offered does `findNew` fetch the repository for the skills' names and descriptions. `SeenSkills` records per `repo@ref` the paths the install picker showed and the ones set aside, so they aren't offered again. The finds live in memory (`newFound`) and reach the page as `View.NewSkills`; `AddNewSkills` gives each to the agents that have its repository's other skills, and `IgnoreNewSkills` sets it aside (`/api/library/skills/{add-new,ignore-new}`). A git repository on another host has no such list: when `git ls-remote` gives its ref a head, `findNewGit` reads the fetch the check shares (`fetcher`), once per head while its finds are kept (`gitLooked`), and offers the skills under `newBase` with the address as the library has it, `.git` and all, so an Add keeps the same `repo@ref`. A folder the user added linked skills from is kept as `folder:` in `SeenSkills` (`offered`, at install), which is also how the library knows which folder to look in again: `findNewFolder` reads it as Add from folder does and offers a skill folder there the library doesn't link, hasn't offered, and has no skill by that name of; a folder that can't be read keeps what was found. `View.CheckFolders` (`addedFromFolders`, which reads no folder) puts Check for updates on the page with only linked skills, and makes `checkDue` true. A check never adds or writes a skill: each is offered, and one the user removed or set aside isn't offered again. A folder added before this kept no `folder:` key and is looked in only once the user adds from it again (refeccd on Discord; `TestCheckSkillsFindsNewInGitRepo`, `TestCheckSkillsFindsNewInFolder`, `skill-new-in-repo.test.cjs`). | [`skillnew.go`](../../internal/library/skillnew.go), [`skillcheck.go`](../../internal/library/skillcheck.go) | | Skill groups | The page groups skills by `SkillView.Repo`, the repository each came from (`tracer.repoOf`): its GitHub source, CC Switch's `Origin`, `From`, the skills CLI's lock or the git checkout a linked folder is in. That checkout is the one git finds (`provider.GitAt` in `gitRepoOf`): an empty `.git` between the skill and its checkout is passed over, as git passes it over, and a `.git` file that names no repository (a worktree left behind) is none (#3675, `TestSkillRepoTraced`). A lock entry of `sourceType: well-known` (a site's kit at its `/.well-known/agent-skills/`) is grouped by its `sourceBaseUrl` as host/path (`wellKnownBase`), not by each skill's own `sourceUrl`: Feishu's lark-* skills are one group and Fish Audio's another, while two kits under one host with different base URLs stay apart. An older entry with no base URL takes the part of its `sourceUrl` before `/.well-known/`, and one with neither is grouped by its `sourceUrl` as before. Such a kit is never fetched from GitHub by Group again, even when it reads like owner/repo (a GitHub owner has no dot), and its heading's link opens the site (#1862, `TestWellKnownKitGrouped`). `From` is written when a repository is probed (installing from it again, `noteFrom`): for a skill with the very same `SKILL.md`, and for one traced to nowhere by a name the repository has when the library has others from there, since a pack added a while ago is mostly older copies edited there since (White Immortal on Discord: 20 of mattpocock/skills' 38). Group again (`RegroupSkills`, `POST /api/library/skills/regroup`) fetches each GitHub repository the skills are traced to and does the same; it fails only when none could be fetched. A skill traced to another repository is never moved. A group's (or part's, or the Select bar's) agent chips count, give and take only the skills magpie decides for each agent: one kept in `~/.agents/skills` is in `SkillView.Always` for the agents that read that folder themselves, so a chip's `agents-some` for such an agent leaves it out, its tooltip and the status after a click say how many it still reads itself, and an agent that reads every one of them itself has a lit, locked chip as the row's is, which sends nothing (`groupChips` in plugins/library/client.js). The heading says how many of its skills are in `~/.agents/skills`. A row's locked chip is lit with a lock on its corner, not greyed like a chip that can't be given the skill (#1862, `skill-group-shared.test.cjs`). Collapse all / Expand all, beside the sort, folds or opens every group the list shows at once (`foldAllButton`): without a filter it sets each group's kept fold (`magpie.libSkillFolds`), as a click on each heading would; while filtering, only the groups the filter shows, till the filter changes (`unfiltered`), leaving the kept folds alone. It reads Collapse all while any shown group is open, is hidden with fewer than two groups (A→Z, or a filter one group matches), leaves a part's own fold as it is and sends nothing (#1862, `skill-fold-all.test.cjs`). A group's, part's, project's or agent's heading opened or folded stays where it was clicked, its rows coming in below it (jinpwng on X, `library-group-steady.test.cjs`). | [`skill_from.go`](../../internal/library/skill_from.go), [`plugins/library/client.js`](../../internal/gui/assets/plugins/library/client.js) | diff --git a/internal/library/dirlink_windows.go b/internal/library/dirlink_windows.go index 93c1e7a32..cea048e0d 100644 --- a/internal/library/dirlink_windows.go +++ b/internal/library/dirlink_windows.go @@ -13,9 +13,11 @@ import ( // dirLink makes link a link to the folder target. Windows lets a user make // a symlink only with Developer Mode on or as an administrator (#973); -// without that it is a junction, which every user can make and every -// program follows as it does a symlink to a folder. A junction can't point -// at a network share: that is still the symlink's error. +// without that it is a junction, which every user can make and most +// programs follow as they do a symlink to a folder; a Go program's walk +// may not, so the agents that skip one get copies (skipsJunctions). A +// junction can't point at a network share: that is still the symlink's +// error. func dirLink(target, link string) error { err := os.Symlink(target, link) if err == nil || !errors.Is(err, windows.ERROR_PRIVILEGE_NOT_HELD) { diff --git a/internal/library/dirlink_windows_test.go b/internal/library/dirlink_windows_test.go index 1ffde62c0..ade50e8e8 100644 --- a/internal/library/dirlink_windows_test.go +++ b/internal/library/dirlink_windows_test.go @@ -46,3 +46,46 @@ func TestJunctionIsALink(t *testing.T) { t.Errorf("a failed junction left %s: %v", q, err) } } + +// #6610: Antigravity skips a junction, so its junction from an older +// magpie is made a copy, a real folder (not ModeIrregular to a Go walk), +// in its own folder and in a project's .agents/skills. +func TestJunctionBlindJunctionBecomesCopy(t *testing.T) { + h, cfg := antigravity(t) + src := filepath.Join(h, "src/skills") + skill(t, filepath.Join(src, "pdf"), "pdf", "Read PDFs") + ok(t)(InstallSkills(src, []string{"pdf"}, []string{"agy"})) + proj := filepath.Join(t.TempDir(), "app") + write(t, filepath.Join(proj, ".git", "HEAD"), "ref: refs/heads/main\n") + ok(t)(AddProject(proj)) + ok(t)(ProjectSkill(proj, "pdf", []string{"agy"})) + ps := []string{filepath.Join(cfg, "skills/pdf"), filepath.Join(proj, ".agents/skills/pdf")} + for _, p := range ps { + if err := os.RemoveAll(p); err != nil { + t.Fatal(err) + } + if err := junction(skillDir("pdf"), p); err != nil { + t.Fatal(err) + } + } + ok(t)(Sync()) + for _, p := range ps { + fi, err := os.Lstat(p) + if err != nil || !fi.IsDir() || fi.Mode()&(os.ModeIrregular|os.ModeSymlink) != 0 || !ours(p, "pdf") { + t.Errorf("%s: %v %v", p, fi, err) + continue + } + es, err := os.ReadDir(filepath.Dir(p)) + if err != nil { + t.Fatal(err) + } + for _, e := range es { + if e.Name() == "pdf" && !e.IsDir() { + t.Errorf("%s: a walk doesn't see a folder: %v", p, e.Type()) + } + } + if _, err := os.Stat(filepath.Join(p, "SKILL.md")); err != nil { + t.Error(err) + } + } +} diff --git a/internal/library/junction_blind_test.go b/internal/library/junction_blind_test.go new file mode 100644 index 000000000..9aa6fd4bb --- /dev/null +++ b/internal/library/junction_blind_test.go @@ -0,0 +1,157 @@ +package library + +import ( + "os" + "path/filepath" + "runtime" + "slices" + "strings" + "testing" + "time" +) + +// onWindowsLinks makes the sync judge links as it does on Windows, where +// magpie's link may be a junction (skipsJunctions). +func onWindowsLinks(t *testing.T) { + t.Helper() + old := linkOS + linkOS = "windows" + t.Cleanup(func() { linkOS = old }) +} + +// #6610, #5107: on Windows, Antigravity and Crush skip a junction in their +// skills folder, so they get marked copies, made again when the library's +// changes; an edit made in one goes to the library and to the agents +// given links. Elsewhere they get links. +func TestJunctionBlindAgentsGetCopies(t *testing.T) { + h, cfg := antigravity(t) + write(t, filepath.Join(h, ".config/crush/crush.json"), "{}") + for _, id := range []string{"agy", "crush"} { + if tg := targetByID(id); tg == nil || tg.Copy != (runtime.GOOS == "windows") { + t.Fatalf("%s here: %+v", id, tg) + } + } + onWindowsLinks(t) + for _, id := range []string{"agy", "crush"} { + if tg := targetByID(id); tg == nil || !tg.Copy { + t.Fatalf("%s on Windows: %+v", id, tg) + } + } + if tg := targetByID("claude"); tg == nil || tg.Copy { + t.Fatalf("claude on Windows: %+v", tg) + } + + src := filepath.Join(h, "src/skills") + skill(t, filepath.Join(src, "pdf"), "pdf", "Read PDFs") + ok(t)(InstallSkills(src, []string{"pdf"}, []string{"agy", "crush", "claude"})) + ag, cr, cl := filepath.Join(cfg, "skills/pdf"), filepath.Join(h, ".config/crush/skills/pdf"), filepath.Join(h, ".claude/skills/pdf") + for _, p := range []string{ag, cr} { + if isLink(t, p) || !ours(p, "pdf") { + t.Fatalf("%s isn't magpie's copy", p) + } + } + if runtime.GOOS != "windows" && !isLink(t, cl) { + t.Fatal("Claude Code's isn't a link") + } + v, err := Read(nil) + if err != nil { + t.Fatal(err) + } + for _, a := range v.Agents { + if (a.ID == "agy" || a.ID == "crush") && (!a.MustCopy || a.How != HowCopy) { + t.Errorf("%s: must copy %v, how %q", a.ID, a.MustCopy, a.How) + } + } + + // the user edits Antigravity's copy, then syncs (twice: the next start) + time.Sleep(20 * time.Millisecond) + write(t, filepath.Join(ag, "SKILL.md"), "---\nname: pdf\ndescription: Edited in Antigravity\n---\n") + for range 2 { + ok(t)(Sync()) + for _, p := range []string{ag, cr, cl, filepath.Join(src, "pdf")} { + if s := read(t, filepath.Join(p, "SKILL.md")); !strings.Contains(s, "Edited in Antigravity") { + t.Fatalf("%s after a sync:\n%s", p, s) + } + } + if isLink(t, ag) || !ours(ag, "pdf") { + t.Fatal("Antigravity's isn't magpie's copy any more") + } + } + + // the library's changes: the copies are behind till a sync + time.Sleep(20 * time.Millisecond) + write(t, filepath.Join(src, "pdf/SKILL.md"), "---\nname: pdf\ndescription: Changed\n---\n") + v, _ = Read(nil) + if b := v.Skills[0].Behind; !slices.Equal(b, []string{"agy", "crush"}) { + t.Fatalf("behind: %v", b) + } + ok(t)(Sync()) + for _, p := range []string{ag, cr} { + if s := read(t, filepath.Join(p, "SKILL.md")); !strings.Contains(s, "Changed") { + t.Errorf("%s wasn't copied again:\n%s", p, s) + } + } +} + +// Crush reads ~/.agents/skills besides its own folder; magpie's link +// there is no skill to it on Windows, so it gets its own copy. +func TestJunctionBlindAgentSkipsSharedLink(t *testing.T) { + h := sandbox(t) + write(t, filepath.Join(h, ".config/crush/crush.json"), "{}") + src := filepath.Join(h, "src/skills") + skill(t, filepath.Join(src, "pdf"), "pdf", "Read PDFs") + ok(t)(SetSkillsWhere(SkillsInShared)) + ok(t)(InstallSkills(src, []string{"pdf"}, []string{"crush"})) + shared, cr := filepath.Join(sharedSkillsDir(), "pdf"), filepath.Join(h, ".config/crush/skills/pdf") + if !isLink(t, shared) { + t.Fatal("no link in ~/.agents/skills") + } + if runtime.GOOS != "windows" { + if _, err := os.Lstat(cr); !os.IsNotExist(err) { + t.Fatalf("Crush got a second one beside ~/.agents/skills: %v", err) + } + } + onWindowsLinks(t) + ok(t)(Sync()) + if isLink(t, cr) || !ours(cr, "pdf") { + t.Fatal("Crush has no copy of its own on Windows") + } +} + +// A project's .agents/skills entry that Antigravity reads is a copy on +// Windows, and an edit made in it goes to the library; one no such agent +// reads is a link again. +func TestJunctionBlindProjectCopies(t *testing.T) { + h, proj := projectLib(t) + onWindowsLinks(t) + ok(t)(ProjectSkill(proj, "pdf", []string{"agy", "claude"})) + sh, cl := filepath.Join(proj, ".agents/skills/pdf"), filepath.Join(proj, ".claude/skills/pdf") + if isLink(t, sh) || !ours(sh, "pdf") { + t.Fatal(".agents/skills/pdf isn't magpie's copy") + } + if runtime.GOOS != "windows" && !isLink(t, cl) { + t.Fatal(".claude/skills/pdf isn't a link") + } + + // the user edits the project's copy, then syncs + time.Sleep(20 * time.Millisecond) + write(t, filepath.Join(sh, "SKILL.md"), "---\nname: pdf\ndescription: Edited in the project\n---\n") + for range 2 { + ok(t)(Sync()) + for _, p := range []string{sh, cl, filepath.Join(h, "src/pdf")} { + if s := read(t, filepath.Join(p, "SKILL.md")); !strings.Contains(s, "Edited in the project") { + t.Fatalf("%s after a sync:\n%s", p, s) + } + } + } + if isLink(t, sh) || !ours(sh, "pdf") { + t.Fatal("the project's copy isn't magpie's any more") + } + + // Antigravity unticked: Codex's entry is a link again (on Windows a + // copy as fresh as the library's stands for one) + ok(t)(ProjectSkill(proj, "pdf", []string{"codex"})) + if runtime.GOOS != "windows" && !isLink(t, sh) { + t.Error(".agents/skills/pdf is still a copy") + } +} diff --git a/internal/library/projects.go b/internal/library/projects.go index 22f057a19..ec238164f 100644 --- a/internal/library/projects.go +++ b/internal/library/projects.go @@ -162,13 +162,20 @@ func (l *Library) syncFolder(p *Project, res *Result, hubs map[string]*Server) { res.Problems = append(res.Problems, Problem{Agent: p.Dir, What: "project:" + name, Error: err.Error()}) } want := map[string]string{} // entry → the skill + // the entries given as copies: all of them in a project that takes + // copies, else those an agent reads that skips a junction + // (skipsJunctions), which is magpie's link on Windows without the + // right to make a symlink + copies := map[string]bool{} for name, agents := range p.Skills { if l.skill(name) == nil { continue } for _, id := range agents { if d := ProjectSkillsDir(id); d != "" { - want[d+"/"+name] = name + e := d + "/" + name + want[e] = name + copies[e] = copies[e] || p.Copy || skipsJunctions(id) } } } @@ -195,7 +202,7 @@ func (l *Library) syncFolder(p *Project, res *Result, hubs map[string]*Server) { }) for _, e := range entries { name := want[e] - switch err := p.place(e, name); { + switch err := p.place(e, name, copies[e]); { case err == nil: placed = append(placed, e) case errors.Is(err, errForeign): @@ -241,7 +248,7 @@ var errForeign = errors.New("not magpie's") // place puts a skill at e in the project: a link to the library's, or a // copy made again whenever the library's differs from it. -func (p *Project) place(e, name string) error { +func (p *Project) place(e, name string, asCopy bool) error { abs := filepath.Join(p.Dir, filepath.FromSlash(e)) if fi, err := os.Lstat(abs); err == nil { if !ours(abs, name) { @@ -249,7 +256,7 @@ func (p *Project) place(e, name string) error { } link := linkEntry(fi) // a copy stands for a link on Windows without the right to make one - if !p.Copy && link { + if !asCopy && link { return nil } if !link { @@ -257,7 +264,7 @@ func (p *Project) place(e, name string) error { if err != nil { return err } - if (p.Copy || runtime.GOOS == "windows") && current { + if (asCopy || runtime.GOOS == "windows") && current { return nil } } @@ -265,7 +272,7 @@ func (p *Project) place(e, name string) error { if err := p.mkdirs(filepath.Dir(abs)); err != nil { return err } - if !p.Copy { + if !asCopy { if err := unlink(abs); err != nil { return err } diff --git a/internal/library/skill_edits.go b/internal/library/skill_edits.go index 3594a4372..2eda88970 100644 --- a/internal/library/skill_edits.go +++ b/internal/library/skill_edits.go @@ -78,27 +78,48 @@ func (l *Library) takeEdits(targets []*Target, res *Result) { } edits = append(edits, edit{t.Agent.ID, p, at}) } - // the shared copy too (#4958): an edit made in ~/.agents/skills, - // where no link could be made (Windows without the right to), is - // the library's to take as one in an agent's copy is — before - // syncShared sets the stale copy aside. An agent whose own folder - // that is has had its copy read above. + // a copy outside an agent's own folder: an edit made there is the + // library's to take as one in an agent's copy is + // (a project's that can't be read is said by its sync, as one) + other := func(agent, p string) { + if seen[realDir(p)] || !ours(p, s.Name) || linked(p) { + return + } + seen[realDir(p)] = true + made, ok := copiedAt(p) + if !ok { + return + } + at, err := changedAt(p) + switch { + case err != nil: + if agent != "project" { + failed(agent, s.Name, p, err) + } + case !at.After(made): + if l.untouched == nil { + l.untouched = map[string]bool{} + } + l.untouched[p] = true + case !sameTree(p, lib): + edits = append(edits, edit{agent, p, at}) + } + } + // the shared copy (#4958), in ~/.agents/skills where no link could + // be made (Windows without the right to), before syncShared sets + // the stale copy aside. An agent whose own folder that is has had + // its copy read above. if !seen[realDir(sharedSkillsDir())] { - p := filepath.Join(sharedSkillsDir(), s.Name) - if ours(p, s.Name) && !linked(p) { - made, ok := copiedAt(p) - if ok { - at, err := changedAt(p) - switch { - case err != nil: - failed("agents", s.Name, p, err) - case !at.After(made): - if l.untouched == nil { - l.untouched = map[string]bool{} - } - l.untouched[p] = true - case !sameTree(p, lib): - edits = append(edits, edit{"agents", p, at}) + other("agents", filepath.Join(sharedSkillsDir(), s.Name)) + } + // a project's copies: of a project that takes copies, and those + // of an agent that skips a junction (#6610), where a link was + // edited in place in the library's own folder + for _, p := range l.Projects { + for _, f := range append([]*Project{p}, p.Trees...) { + for _, e := range f.Placed { + if filepath.Base(filepath.FromSlash(e)) == s.Name { + other("project", filepath.Join(f.Dir, filepath.FromSlash(e))) } } } diff --git a/internal/library/skill_how.go b/internal/library/skill_how.go index 73133533e..208d311ef 100644 --- a/internal/library/skill_how.go +++ b/internal/library/skill_how.go @@ -121,7 +121,7 @@ func relink(agent, p, name string) (bool, error) { func (l *Library) behind(targets []*Target) map[string][]string { out := map[string][]string{} for _, t := range targets { - if t.Skills == "" || t.Desktop != nil || t.Agent.WSL != "" || l.howOf(t.Agent.ID) != HowCopy { + if t.Skills == "" || t.Desktop != nil || t.Agent.WSL != "" || l.howOf(t.Agent.ID) != HowCopy && !skipsJunctions(t.Agent.ID) { continue } for _, s := range l.Skills { diff --git a/internal/library/skills.go b/internal/library/skills.go index de352a178..d19bf92a4 100644 --- a/internal/library/skills.go +++ b/internal/library/skills.go @@ -722,6 +722,11 @@ func (l *Library) syncSkills(t *Target, res *Result, all []*Target) { if s == nil || !t.readsSharedDir() || realDir(t.Skills) == shared { return false } + // a link there is no skill to an agent that skips a junction + // (skipsJunctions): it gets its own copy + if skipsJunctions(id) && linked(filepath.Join(sharedSkillsDir(), s.Name)) { + 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) || l.inSharedHere(s) { diff --git a/internal/library/targets.go b/internal/library/targets.go index a0e2e8263..06ec6b117 100644 --- a/internal/library/targets.go +++ b/internal/library/targets.go @@ -4,6 +4,7 @@ import ( "fmt" "os" "path/filepath" + "runtime" "slices" "strings" @@ -43,7 +44,8 @@ type Target struct { Note string // Copy is an agent that gets a copy of each skill, made again when // the library's changes, rather than a link: one in a WSL distro whose - // skills folder is on a Windows drive (wslStored). + // skills folder is on a Windows drive (wslStored), LiveAgent, and on + // Windows one that skips a junction (skipsJunctions). Copy bool // Store, for an agent in a WSL distro, is magpie's folder there // (wslStoreRel) holding one copy of each skill given to the distro's @@ -205,6 +207,7 @@ func targetOf(a *agent.Agent) *Target { t.Instructions = filepath.Join(d, "GEMINI.md") t.MCP = &mcpFile{Path: filepath.Join(d, "mcp_config.json"), Format: fmtAntigravity} t.Skills = filepath.Join(d, "skills") + t.Copy = skipsJunctions(a.ID) case "opencode", "deveco": // DevEco Code is OpenCode's fork and reads as it does: AGENTS.md // in its config folder, else Claude Code's CLAUDE.md, skills there @@ -313,6 +316,7 @@ func targetOf(a *agent.Agent) *Target { t.MCP = &mcpFile{Path: a.Path, Format: fmtCrush} t.Skills = filepath.Join(filepath.Dir(a.Path), "skills") t.SkillsAlso = []string{"claude"} + t.Copy = skipsJunctions(a.ID) case "zcode": // ZCode's own servers are its cli/config.json's mcp.servers (the // app's MCP settings write there); AGENTS.md and skills beside it @@ -1057,6 +1061,29 @@ func (l *Library) held(have []*Target) []*Target { return out } +// junctionBlind are the agents that, on Windows, skip a junction in a +// skills folder while they take a folder or a symlink there: Go programs +// whose walk keeps an entry only when it IsDir or is a ModeSymlink, and Go +// from 1.23 lists a junction as neither but ModeIrregular. Antigravity, +// the app and agy alike (customizations' discoverInSubDirsFiltered, #5107, +// #6610), and Crush (internal/skills on fastwalk with Follow, which follows +// only a ModeSymlink). magpie's link on Windows is a junction when the +// user may not make a symlink (dirLink, #973), so these get copies there: +// GetAllSkills of Antigravity 2.30's language server and Crush 0.101's +// prompt list a skill in a folder or behind a symlink, and not one behind +// a junction. +var junctionBlind = []string{"agy", "antigravity", "crush"} + +// linkOS is the system magpie's links are made on, runtime.GOOS but in a +// test. +var linkOS = runtime.GOOS + +// skipsJunctions is whether the agent skips magpie's links in its skills +// folders on this system (junctionBlind). +func skipsJunctions(id string) bool { + return linkOS == "windows" && slices.Contains(junctionBlind, id) +} + // 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). OmO's engine, senpi, a fork of