magpie-image was kept in library.json with one computer's magpie by full path (os.Executable at install). A WebDAV sync carried C:\Users\...\Downloads\magpie-windows-amd64.exe to a Mac (and a Mac's app to Windows), and a magpie moved out of Downloads left its old path behind: the Library page said it couldn't start, and agents were given a program that isn't there. - heal (self_here.go): a server that is magpie's own -- `mcp ...` run by a program named magpie (magpie, magpie.exe, magpie-<os>-<arch>[.exe]) -- whose program isn't an existing absolute path here is pointed at this magpie, as the library is read (load) and after every change (so a bundle Put from another computer is healed before it is written into the agents). Every agent writer, project MCP files, the WSL side and CheckServers read through load, so all of them get it. A magpie program that does exist here (another build) and any server run by another program are left as they are. - Collect carries magpie's own server as plain "magpie": two computers with the same library carry the same bundle, so davsync's library hash matches and a sync doesn't write one's path over the other's. - The path given is update.Program (exported cliProgram): the AppImage rather than its mount, Homebrew's opt link rather than the Cellar. - TestWSLMagpieImage now says which magpie this (simulated Windows) computer runs. Verified: - New tests: TestOwnServerFromElsewhereRunsThisMagpie (Windows path read on macOS, a Mac path, an exe moved out of Downloads, a bare "magpie"), TestUsersOwnServerStaysAsItIs, TestCarriedOwnServerIsEachComputersMagpie. Broken by hand five ways (heal off; no heal in change; no marker in Collect; ownServer matching every server; existing magpie builds not kept) -- each went red with a FAIL naming the behaviour, green restored. - gofmt -l clean; go vet -tags nogui ./...; GOOS=linux and GOOS=windows go vet (library, update, davsync); go build, GOOS=linux -tags nogui and GOOS=windows builds; go test -tags nogui ./... green in a sandbox HOME. - Sandbox app (own HOME, ports 3561/3562) seeded with a library.json holding the reporter's Windows path for magpie-image plus a user's own missing Windows tool: on start library.json, Codex's config.toml and Claude Code's .claude.json got the running binary; /api/library/mcp/check answered magpie-image ok with 3 tools, the user's server unchanged and notfound. Not verified: on the Windows box, or a real two-computer WebDAV sync.
15 KiB
15 KiB
Library: instructions, MCP servers, skills and RTK
The library keeps what every agent should know in one place: the
instructions each agent reads before a conversation, the MCP servers it can
call, and the skills it can load. magpie writes these into each agent's own
files in that agent's format, and takes back only what it wrote. Everything
else in those files stays as it was. Package internal/library also gives
agents RTK, a CLI that cuts shell output down before the model reads it.
Responsibilities and sources of truth
| Part | Responsibility | Source |
|---|---|---|
| library.json | Library holds the instruction sets, the MCP servers, the skills, the projects, skill groups and copy settings. Applied records what magpie last wrote into each agent, so it only ever takes away its own. The instruction texts and skill folders live under Dir (library/ in magpie's config folder). |
library.go |
| One change | change locks the library, loads it, applies one edit, saves, syncs every agent and saves again. Every exported mutation (SaveServer, InstallSkills, SetSkillHow and the rest) goes through it. One change runs at a time, whether from the page or the CLI. |
library.go |
| Targets | Targets lists the detected agents (agent.Detected), plus apps like Claude Desktop, with where each keeps its instructions file (and an Override it reads instead), its MCP file and its skills folder. An agent in a running WSL distro has its places under the distro's home (wslTargetOf): Claude Code, Codex, Pi and OmO each by its own rule, and every agent that keeps all of them in its own folder (Hermes Agent, omp, OpenCode, Droid and the rest of ownFolder, #1323) by the same rule as on this machine, its MCP file marked as WSL's so a Windows program isn't given to it. |
targets.go |
| Sync | sync writes each target's instructions and MCP servers. It then takes edits made in agents' skill copies into the library (takeEdits) and links or copies the skills. ~/.agents/skills goes first, so an agent that reads it gets no second link. Then it syncs projects' skills. |
sync.go |
| Instructions | magpie's part of an agent's instructions file sits between two marker lines. The rest of the file is the user's. Several named sets can be switched between (#106). | instructions.go |
| MCP servers | A Server is a command or a URL (http, sse). mcpFile encodes it in each agent's own format (one mcpFormat per agent family) and merges it with the user's own fields for that entry. Also files get the same servers; Extra files are only read when importing. CheckServers connects as an agent would and keeps the result in memory only. A server that needs OAuth is signed in once in magpie, and agents reach it through the gateway's /mcp/<name> (#615). |
mcp.go, mcp_check.go, mcp_signin.go |
| Skills | A skill is a folder with a SKILL.md. It comes from GitHub, from a folder on this machine (linked, so editing the folder edits the skill) or from the market. Each agent gets a link or a marked copy (#896, SkillHow). An agent in a WSL distro always gets a copy. 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 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. |
skills.go, skill_how.go, skill_edits.go, skill_from.go |
| Skills market | MarketSkills lists skills.sh's most installed and what its search finds. magpie's own skills (featuredSkills) go first, marked official: magpie-quota, in magpie-community/plugins, lets an agent read magpie quota --json and wait with magpie quota wait. 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 |
| Skills a repository 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}). |
skillnew.go, skillcheck.go |
| Backups | Before a change first writes an agent file, backups copies it to BackupDir, one folder per change. The last keepBackups (30) changes are kept. |
backup.go |
| RTK | SetRTK runs rtk's own installer (rtk init -g …) for an agent being switched on. For one being switched off, it removes exactly what the installer wrote, using magpie's own code, which works even with rtk gone. ReadRTK reads each agent's files to say which have the hook. rtkSpec.blocked stops the installer where it would break an agent. A detected agent RTK has no hook for at all is still listed, from rtkNoHook, with the reason and a switch that can't be turned on (dsh: its hooks can allow or deny a command but not rewrite it, and rtk init has no --agent dsh). |
rtk.go |
Runtime path
- Edit. The Library page or
magpie librarycalls an exported function such asSaveServer,ServerAgents,InstallSkills,SkillAgentsorSetSkillHow. The skills and servers pages each have Select, Turn all on, Turn all off and Remove all. Select's bar callsSomeSkillsAgentsorSomeServersAgents(/api/library/{skills,servers}/agents-some), Turn all on or off callsEverySkillAgentsorEveryServerAgentsfor the agents shown, and Remove all callsRemoveSkillsorRemoveServers. Each of these is one change that takes every item out as a single removal would (#1027). - Change.
changeeditslibrary.jsonunder the lock and callssync. - Write. For each target,
syncInstructionsandsyncMCPwrite magpie's part in the agent's format and record it inApplied. Skills are linked or copied into the agent's skills folder. A copy edited since it was made is taken into the library first. - Result. The
Resultlists the agents changed, aProblemfor each thing that couldn't be given, and the backup folder.
Constraints and failure behavior
- magpie takes away only what
Appliedor its mark says it wrote. A folder of the user's with a skill's name is never touched. The user's own fields in an MCP entry are kept. - An edit never silently loses. When an agent's copy of a skill and the library both changed, the newest edit wins, and the losing one is kept with the backups.
- A failure for one agent is a
Problemin the result. It doesn't stop the others. - A server an agent can't reach is not written there, and
mcpFile.supportssays why. For example, Claude Desktop takes no remote server, and Codex, Goose, dsh, Grok, Command Code and Zed take no SSE. - A server's headers (remote) or environment (command) can name a variable as
${NAME}(#1250).library.jsonkeeps the placeholder, andrefsOfgives each MCP format the agent's own syntax, with the agent's source cited beside it:${NAME}for most,{env:NAME}for OpenCode and MiMo,${env:NAME}for Cursor, and Codex's own keys (bearer_token_env_var,env_http_headers,env_vars). Goose gets${NAME}plusenv_keys. dsh (DeepSeek Harness) gets a!!jsexpression it evaluates as it loads the server (#1435): a whole${NAME}is!!js process.env.NAME, and a value mixing text and variables is the text as JSON string literals joined with(process.env.NAME ?? ""), so the user's text is never run as code and an unset variable inside it is empty. A whole variable that isn't set makes dsh leave the server out as invalid. magpie reads only those forms back as${NAME}; any other!!jskeeps the entry the user's. An agent with no syntax (Claude Desktop, Antigravity, Kimi, Cline, ZCode, Zed, Devin, Alma, Pi with pi-mcp-extension) is never written the value:refsProblemmakessupportsrefuse the server, a magpie entry already there is taken out, andAgentView.NoEnvRefsgreys its chip with the reason. Codex and Goose's extra keys are magpie's only while the server names a variable there (refKeys), so the user's ownenv_varsorenv_keysare kept.CheckServersexpands the variable from magpie's own environment, and one that isn't set isnovar, naming it. - magpie's own MCP server (
magpie-image, and anymcp …run by a program named magpie) runs this computer's magpie (#1439).InstallServergives it magpie by full path (update.Program: the AppImage, not its mount; Homebrew's opt link, not the Cellar), and that path is right only on this computer. When the library is read, and after every change,healpoints such a server whose program isn't on this computer (another system's path, a magpie moved out of Downloads, a baremagpie) at this magpie, so the agents andCheckServersget it; a magpie program that is here (another build) and a server run by any other program stay as they are. A carried library (Collect, for a backup or a WebDAV or S3 sync) names it as plainmagpie, so two computers carry the same bundle and a sync doesn't write one's path over the other's;Putthen reads it as that computer's magpie.self_here.go - WorkBuddy's servers go in
$WORKBUDDY_CONFIG_DIR/mcp.json(default~/.workbuddy), and CodeBuddy Code's go in the first of.mcp.json,mcp.jsonand~/.codebuddy.jsonthat exists, asresolveMcpFilePathreads them (#1266). WorkBuddy connects a server only after the user has switched it on once in its own MCP settings. It keeps that approval inmcp-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 when a server is given to WorkBuddy. - Alma's servers go in
~/.config/alma/mcp.jsonon every system (its home, not its data folder), as its own MCP settings write them:command/args/env, orurl/headerswithtransport: "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. - Zed's servers go in
context_serversof the settings.json magpie sets its model in (agent.zed:~/.config/zedon macOS,$XDG_CONFIG_HOME/zedon Linux,%APPDATA%\Zedon Windows, or$MAGPIE_ZED_CONFIG_DIR), ascommand/args/envorurl/headers(ContextServerSettingsContent, zed-industries/zed 2c99f547). The file is JSONC: it is edited in place, so the user's comments, other settings and own servers stay, andenabled,remote,timeoutandoauthin magpie's entry are the user's. Zed speaks streamable HTTP only (itshttp.rsonly POSTs), so no SSE. An entry Zed's extensions configure (settingsand no command or url) is never written over: a server by that name is refused for Zed (mcpFile.foreign), and asks for another name. Zed reloads the file as it changes. - An agent with no place for an item is refused by
Takes, never recorded as given it. The refusal lists the agents here that take that item (takenBy), and says where it goes instead (noPlace): OpenChamber reads OpenCode's global AGENTS.md, skills folder and opencode.json (its server'sshared.js), so it gets them from OpenCode; Claude Desktop's chat keeps its instructions in its own settings, with the Claude account, and its Code tab reads Claude Code's. - Removing RTK never uses
rtk init --uninstall. That command deletes Gemini'sGEMINI.mdwhole and removes Claude Code, OpenCode and Cursor together. - CC Switch's own skills folder is only ever read.
- Skills installed together (
InstallSkills,InstallMarketSkill,AddNewSkills, throughinstallFromandinstallChange) install each on its own. One the library lists from the same source, or a folder in the library's own skills folder holding exactly that skill's files (left by an install that stopped before the library was saved), is had already and goes inResult.Had. Its files are never written, so the user's edits stay. Another skill by that name, listed or only in the folder, or a folder that can't be read, is left as it is and goes inResult.Skippedwith why. The rest are installed and named inResult.Installed. Only when nothing was installed or had does the change fail, with the first reason.
Verification
go test -tags nogui ./internal/library -run 'TestCheckSkillsFindsNewOnes|TestNewBase|TestTargets|TestServer|TestImportServer|TestCheck|TestInstructions|TestInstructionSets|TestSkill|TestRemoveFoundSkill|TestInstallSet|TestInstallLists|TestEverySkillAgents|TestEveryServerAgents|TestSomeServersAgents|TestRemoveServers|TestRTK|TestEnvRefs|TestDshRefRoundTrip|TestDshImportKeepsJS|TestAgentMCPFiles|TestCodeBuddyMCPFile|TestZedMCP|TestOwnServerFromElsewhereRunsThisMagpie|TestUsersOwnServerStaysAsItIs|TestCarriedOwnServerIsEachComputersMagpie'
go test -tags nogui ./internal/library
node --test internal/gui/tests/library-items.test.cjs internal/gui/tests/library-rtk-gain.test.cjs internal/gui/tests/library-rtk-nohook.test.cjs internal/gui/tests/library-servers-bulk.test.cjs internal/gui/tests/library-env-refs.test.cjs internal/gui/tests/library-zed-mcp.test.cjs internal/gui/tests/library-workbuddy-trust.test.cjs internal/gui/tests/skill-new-in-repo.test.cjs internal/gui/tests/remove-found-skill.test.cjs
The package's TestMain runs in a home of its own (testenv), never the
user's real agent files.