Skip to content

Every agent's model. One place. Codex on DeepSeek, Claude Code on Kimi, from the menu bar.

library: a Pi in WSL is given MCP servers, and so are seven more WSL agents

yetonee29ddc407fce
diff --git a/docs/subsystems/library.md b/docs/subsystems/library.md
index 7e9104b44..b79167540 100644
--- a/docs/subsystems/library.md
+++ b/docs/subsystems/library.md
@@ -15,7 +15,7 @@ agents RTK, a CLI that cuts shell output down before the model reads it.
| --- | --- | --- |
| 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`](../../internal/library/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`](../../internal/library/library.go) |
-| Targets | `Targets` lists the detected agents (`agent.Detected`), a folder an agent shares with its vendor's other app when only that app is here (`agent.SharedHere`: the Cursor editor's `~/.cursor`, whose `mcp.json` and skills it reads, listed as Cursor; `TestCursorEditorAloneKeepsItsLibraryRow`), 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 whose CLI is gone (`CLIMissing`: an uninstall that left the folder behind, #2177, #2254) is no target: it is given nothing it can't read. One that isn't a target but still has skills, servers or hooks magpie gave it (in `Applied`, or listed in an item's `Agents`) is held (`held`, a `Target` with `Gone`): a sync takes edits from its copies and then only takes out of it (`syncSkills`, `syncMCP` and `syncHooks` give a gone target nothing new), and `Read` lists it with `gone: true` while it has any. The page shows a gone agent's chip only on the rows of what it has, lit, so a click takes it out (`withGone` in plugins/library/client.js), leaves it out of All, the per-agent How sheet and every picker, and lists it in By agent as Not installed here with Turn all on off (@jiahao_jayden on X: an uninstalled WorkBuddy was on every skill's row; `TestGoneAgentListedToTakeOut`, `library-gone-agents.test.cjs`). On a Mac WorkBuddy and WorkBuddy AI are detected by their apps' bundle ids (`com.tencent.workbuddy.mac`, `com.workbuddy.workbuddy-ai`, `macBundle`), not by `~/.workbuddy`, which an uninstall leaves and magpie itself writes into (`TestWorkBuddyOnMacIsItsApp`); off a Mac the folder still counts. `everyTarget` keeps it for the guards that refuse an agent's own places: a project folder whose skills folder or MCP file is the agent's, and an instruction set kept in its instructions file. 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. An agent a plugin adds (`a.Plugin`) has the places its plugin's `agent.library` names (`pluginTarget`): an instructions file, an MCP file in one of `agentplug.MCPFormats` (each the `mcpFormat` of the agent it is named for, `pluginMCP`) and a skills folder, `~` and `$VAR` expanded as its config is; one that names none is no target. Before, a plugin's agent got models and keys only. | [`targets.go`](../../internal/library/targets.go) |
+| Targets | `Targets` lists the detected agents (`agent.Detected`), a folder an agent shares with its vendor's other app when only that app is here (`agent.SharedHere`: the Cursor editor's `~/.cursor`, whose `mcp.json` and skills it reads, listed as Cursor; `TestCursorEditorAloneKeepsItsLibraryRow`), 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 whose CLI is gone (`CLIMissing`: an uninstall that left the folder behind, #2177, #2254) is no target: it is given nothing it can't read. One that isn't a target but still has skills, servers or hooks magpie gave it (in `Applied`, or listed in an item's `Agents`) is held (`held`, a `Target` with `Gone`): a sync takes edits from its copies and then only takes out of it (`syncSkills`, `syncMCP` and `syncHooks` give a gone target nothing new), and `Read` lists it with `gone: true` while it has any. The page shows a gone agent's chip only on the rows of what it has, lit, so a click takes it out (`withGone` in plugins/library/client.js), leaves it out of All, the per-agent How sheet and every picker, and lists it in By agent as Not installed here with Turn all on off (@jiahao_jayden on X: an uninstalled WorkBuddy was on every skill's row; `TestGoneAgentListedToTakeOut`, `library-gone-agents.test.cjs`). On a Mac WorkBuddy and WorkBuddy AI are detected by their apps' bundle ids (`com.tencent.workbuddy.mac`, `com.workbuddy.workbuddy-ai`, `macBundle`), not by `~/.workbuddy`, which an uninstall leaves and magpie itself writes into (`TestWorkBuddyOnMacIsItsApp`); off a Mac the folder still counts. `everyTarget` keeps it for the guards that refuse an agent's own places: a project folder whose skills folder or MCP file is the agent's, and an instruction set kept in its instructions file. An agent in a running WSL distro has its places under the distro's home (`wslTargetOf`): Claude Code, Codex, Pi, OmO, Gemini CLI, Antigravity CLI, Crush, Cline, CodeBuddy Code, Kimi Code and Goose each by its own rule, never reading this machine's variables (Kimi Code's and Goose's shared `~/.agents/skills` there isn't given), Pi's MCP file chosen by `piMCP` as on this machine from the version the distro's `pi --version` gave its probe (`InstalledVersion`) and the distro's npm folders (`wslPiRoots`; leokon on Discord: only the Windows Pi was offered MCP servers, `TestWSLPiMCP`, `TestWSLMCPSiblings`), 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. An agent a plugin adds (`a.Plugin`) has the places its plugin's `agent.library` names (`pluginTarget`): an instructions file, an MCP file in one of `agentplug.MCPFormats` (each the `mcpFormat` of the agent it is named for, `pluginMCP`) and a skills folder, `~` and `$VAR` expanded as its config is; one that names none is no target. Before, a plugin's agent got models and keys only. | [`targets.go`](../../internal/library/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`](../../internal/library/sync.go) |
| Projects | A project (`Project`) is a folder given some of the library's skills and MCP servers, each for some agents. A skill is linked (or copied) into the folder the agent reads a project's skills from (`projectSkillsDirs`): `.claude/skills` for Claude Code, `.qoder/skills` for Qoder and Qoder CN, `.codebuddy/skills` for CodeBuddy Code, `.commandcode/skills` for Command Code, and `.agents/skills` for Codex, Gemini CLI, OpenCode, Pi, Cursor, Copilot CLI, Antigravity, Kimi, Goose, Grok, Droid and Cline. A server is written into the file the agent reads a project's servers from (`projectMCPFiles`), in the shape its user-wide file has: `.mcp.json` for Claude Code and CodeBuddy Code (CodeBuddy's `mcp.json` when the project has that and no `.mcp.json`, since it reads only the first of the two), `.codex/config.toml`, `.gemini/settings.json`, `.cursor/mcp.json`, `opencode.json`, `.zcode/config.json`, `.pi/mcp.json`, `.qoder/settings.json`'s `mcpServers` for Qoder and Qoder CN, and `.factory/mcp.json` for Droid. Claude Code, Qoder and CodeBuddy ask the user to approve a project's server before using it. Only targets whose vendor source or docs name them are listed (each map's comment cites them); an agent with none (Copilot CLI's MCP, Zed, WorkBuddy, Command Code's MCP, whose `.mcp.json` has its own `transport` shape) can't be picked for a project (eirc on Discord). `Placed`, `Wrote`, `Made` and `MadeFiles` record what magpie put there, the only things it takes away, and what it made is listed in the project's `.gitignore`. | [`projects.go`](../../internal/library/projects.go), [`project_mcp.go`](../../internal/library/project_mcp.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). A set can be kept in a file of the user's own instead of `instruction-sets/` (`InstrSet.File`, 新v学员 on Discord): `~/.agents/AGENTS.md`, which Droid and omp read too. `textPath` reads it, `putText` keeps it aside and writes it but never removes it, removing the set lets go of it, and `linkable` refuses a file magpie writes into (an agent's own instructions, a file with the marker line), the library's own and another set's. The app's `KeepLinked` looks at the file every 30 s and writes a change into the agents (`SyncLinked`). A set's text is read without magpie's part (`setText`), and an agent whose instructions file is, links followed, the file the set on is kept in (`isSetFile`: `instructions.md` linked to `~/.claude/CLAUDE.md`, or both linked to one dotfile) gets no part written into it, and one written before is taken out with every part nested in it: read with its part, each sync wrote the whole file into that part again and it doubled, to gigabytes (#2349, `TestInstructionsSetLinkedToAgentsFile`). `Collect` carries the set's text, not where its file is; `Put` keeps this computer's file for the set and never empties it for a text not carried. Alma's file is `~/.config/alma/USER.md`, which its main chat reads into its system prompt as its owner's profile (0.4.164's `out/main/index.js`; a workspace's `USER.md` is read instead), and whose leading front matter (`name`, `telegram_id`, `discord_id`) is who its bots answer to (#2315, Jie211). The target is a `Profile`: magpie's part goes after the user's, so the front matter stays first, and `ImportInstructions` refuses it, as moving it out would take that front matter out of the file and into every agent's (`TestAlmaInstructionsKeepTheProfile`, `TestAlmaProfileIsNotImported`, `library-alma-profile.test.cjs`). | [`instructions.go`](../../internal/library/instructions.go) |
@@ -76,7 +76,7 @@ agents RTK, a CLI that cuts shell output down before the model reads it.
## Verification
```sh
-go test -tags nogui ./internal/library -run 'TestGit|TestInstallFromGitRepo|TestReadLooksAtEachFolderOnce|TestLinkChangedBetweenVisitsShows|TestUnreadablePartIsLookedAtAgain|TestCheckSkillsFindsNewOnes|TestNewBase|TestUpdateKeeps|TestCheckDue|TestCheckSkillsMarksItDone|TestTargets|TestServer|TestImportServer|TestCheck|TestInstructions|TestInstructionsSetLinkedToAgentsFile|TestInstructionSets|TestTakesAlma|TestAlma|TestLinkedSet|TestLinkRefused|TestSkill|TestRemoveFoundSkill|TestInstallSet|TestInstallLists|TestEverySkillAgents|TestEveryServerAgents|TestSomeServersAgents|TestRemoveServers|TestRTK|TestEnvRefs|TestDshRefRoundTrip|TestDshImportKeepsJS|TestAgentMCPFiles|TestCodeBuddyMCPFile|TestZedMCP|TestOwnServerFromElsewhereRunsThisMagpie|TestUsersOwnServerStaysAsItIs|TestCarriedOwnServerIsEachComputersMagpie|TestCarry|TestPageReadDoesntReadUnchangedSkillsAgain|TestJustWrittenSkillIsReadAgain|TestUnreadableSkillIsntRememberedAsDifferent|TestGlanceLeavesOutTheAgentsSkills|TestPluginAgent|TestPluginMCPFormatsAreWritten|TestToolsOff|TestOffList|TestHooks|TestSubagent|TestCheckRenewsMagpiesSignIn|TestCheckWSLOnlyServerInItsDistro|TestCheckWindowsServerHere|TestCheckMixedServerEachSide|TestCheckSaysSignInRanOut|TestCheckNamesAgentsSignedInThemselves|TestSignInAsTheUsersOwnApp|TestOAuthAppChecked|TestOAuthAppSecretCarried|TestGoneAgentListedToTakeOut|TestUpdateFindsSkillsRemovedUpstream|TestGoneFromNeedsTheSourceRead'
+go test -tags nogui ./internal/library -run 'TestGit|TestInstallFromGitRepo|TestReadLooksAtEachFolderOnce|TestLinkChangedBetweenVisitsShows|TestUnreadablePartIsLookedAtAgain|TestCheckSkillsFindsNewOnes|TestNewBase|TestUpdateKeeps|TestCheckDue|TestCheckSkillsMarksItDone|TestTargets|TestWSLPiMCP|TestWSLMCPSiblings|TestServer|TestImportServer|TestCheck|TestInstructions|TestInstructionsSetLinkedToAgentsFile|TestInstructionSets|TestTakesAlma|TestAlma|TestLinkedSet|TestLinkRefused|TestSkill|TestRemoveFoundSkill|TestInstallSet|TestInstallLists|TestEverySkillAgents|TestEveryServerAgents|TestSomeServersAgents|TestRemoveServers|TestRTK|TestEnvRefs|TestDshRefRoundTrip|TestDshImportKeepsJS|TestAgentMCPFiles|TestCodeBuddyMCPFile|TestZedMCP|TestOwnServerFromElsewhereRunsThisMagpie|TestUsersOwnServerStaysAsItIs|TestCarriedOwnServerIsEachComputersMagpie|TestCarry|TestPageReadDoesntReadUnchangedSkillsAgain|TestJustWrittenSkillIsReadAgain|TestUnreadableSkillIsntRememberedAsDifferent|TestGlanceLeavesOutTheAgentsSkills|TestPluginAgent|TestPluginMCPFormatsAreWritten|TestToolsOff|TestOffList|TestHooks|TestSubagent|TestCheckRenewsMagpiesSignIn|TestCheckWSLOnlyServerInItsDistro|TestCheckWindowsServerHere|TestCheckMixedServerEachSide|TestCheckSaysSignInRanOut|TestCheckNamesAgentsSignedInThemselves|TestSignInAsTheUsersOwnApp|TestOAuthAppChecked|TestOAuthAppSecretCarried|TestGoneAgentListedToTakeOut|TestUpdateFindsSkillsRemovedUpstream|TestGoneFromNeedsTheSourceRead'
go test -tags nogui ./internal/cli -run 'TestLibrarySkillRm'
go test -race ./internal/mcpauth
go test -tags nogui ./internal/library
diff --git a/internal/agent/agent.go b/internal/agent/agent.go
index 44fdf21c7..10ccc4d61 100644
--- a/internal/agent/agent.go
+++ b/internal/agent/agent.go
@@ -295,6 +295,9 @@ type Agent struct {
// whether there is one. A WSL network's address answers from Windows
// whatever its firewall lets in from WSL, so only this tells.
reachFrom func(base string) (ok, known bool)
+ // wslVersion is an agent in a WSL distro's CLI's version, as the
+ // distro's probe asked it (wslKind.version); "" when not asked
+ wslVersion string
// move, when set, points the agent's config at to where it names the
// gateway at from: an address of WSL's that changed (#1013).
move func(from, to string) error
diff --git a/internal/agent/cliupdate.go b/internal/agent/cliupdate.go
index c50209f10..9e1f1df57 100644
--- a/internal/agent/cliupdate.go
+++ b/internal/agent/cliupdate.go
@@ -832,8 +832,13 @@ func (a *Agent) CLI() (c CLI, ok bool) {
// InstalledVersion is what the agent's CLI on PATH says its version is: ""
// for an agent without a CLI magpie knows, one not on PATH, or one that
-// didn't say. Asked once per binary, like CLI's; nothing is fetched.
+// didn't say. Asked once per binary, like CLI's; nothing is fetched. An
+// agent in a WSL distro's is what the distro's own CLI said at its probe,
+// for the kinds that ask (wslKind.version), never this machine's.
func (a *Agent) InstalledVersion() string {
+ if a.WSL != "" {
+ return a.wslVersion
+ }
bin, _ := a.cliBin()
if bin == "" {
return ""
diff --git a/internal/agent/wsl.go b/internal/agent/wsl.go
index e076c30d2..f060b89f8 100644
--- a/internal/agent/wsl.go
+++ b/internal/agent/wsl.go
@@ -319,7 +319,9 @@ var wslKinds = []wslKind{
}
return nil
}},
- {id: "pi", name: "Pi", dir: ".pi", bin: "pi", in: piIn,
+ // its version says which file its MCP servers go in (Pi 0.99 reads
+ // mcp.json itself, library's piMCP)
+ {id: "pi", name: "Pi", dir: ".pi", bin: "pi", in: piIn, version: true,
asleep: func(key string) func(map[string]string) []Option {
if key == "model" {
// the providers of its auth.json are the distro's files
@@ -708,8 +710,10 @@ func wslPi(d distro) *Agent { return wslAgent(wslKindOf("pi"), d) }
// access to its files starts it. Picking a value starts it, as asked.
func wslAgent(k wslKind, d distro) *Agent {
id := k.id + "@wsl:" + d.Name
- a := k.in(d.place(id))
+ at := d.place(id)
+ a := k.in(at)
a.ID, a.Name, a.Aliases, a.Bin, a.UA, a.WSL = id, k.name+" · WSL "+d.Name, nil, "", nil, d.Name
+ a.wslVersion = at.version
a.Gateway = d.base
a.reachFrom = func(base string) (ok, known bool) {
if !d.live() {
diff --git a/internal/library/pimcp.go b/internal/library/pimcp.go
index 62dddaad3..7c47ef1ed 100644
--- a/internal/library/pimcp.go
+++ b/internal/library/pimcp.go
@@ -97,6 +97,23 @@ var piGlobalRoots = func() []string {
"/usr/local/lib/node_modules", "/opt/homebrew/lib/node_modules", "/usr/lib/node_modules")
}
+// wslPiRoots are piGlobalRoots for a Pi in a WSL distro whose home magpie
+// opens at h (\\wsl.localhost\<distro>\home\<user>): the distro's own
+// npm folders, under its root, never this machine's. npm's prefix there is
+// the distro's variable, which isn't read.
+func wslPiRoots(h string) []string {
+ out := []string{filepath.Join(h, ".npm-global", "lib", "node_modules")}
+ lh := linuxHome(h)
+ if lh == "" || !strings.HasSuffix(filepath.ToSlash(h), lh) {
+ return out
+ }
+ root := h[:len(h)-len(lh)]
+ for _, r := range []string{"/usr/local/lib/node_modules", "/usr/lib/node_modules"} {
+ out = append(out, root+filepath.FromSlash(r))
+ }
+ return out
+}
+
// piPackageName is the package a settings.json packages entry installs, and
// the version it is pinned to: npm:[email protected], git:host/owner/[email protected],
// https://host/owner/name.git, or a folder.
@@ -125,7 +142,11 @@ func piPackageName(spec string) (name, pin string) {
// #1097, sydney on Discord: a pi-mcp-adapter left there with `packages: []`
// sent the servers to mcp-adapter.json, which Pi 1.0 never reads); those
// folders only tell a loaded adapter's version.
-func piDetect(d string) piPlugins {
+func piDetect(d string) piPlugins { return piDetectIn(d, piGlobalRoots()) }
+
+// piDetectIn is piDetect with roots as npm's global folders: this
+// machine's, or a WSL distro's for the Pi there (wslPiRoots).
+func piDetectIn(d string, roots []string) piPlugins {
var p piPlugins
var settings struct {
Packages []json.RawMessage
@@ -211,7 +232,7 @@ func piDetect(d string) piPlugins {
dirs = append(dirs, filepath.Join(d, "npm", "node_modules", "pi-mcp-adapter"))
git, _ := filepath.Glob(filepath.Join(d, "git", "*", "*", "pi-mcp-adapter"))
dirs = append(dirs, git...)
- for _, r := range piGlobalRoots() {
+ for _, r := range roots {
dirs = append(dirs, filepath.Join(r, "pi-mcp-adapter"))
}
found := ""
@@ -230,8 +251,8 @@ func piDetect(d string) piPlugins {
}
// piMCP is the file Pi's MCP servers go in, and the extension Pi reads them
-// through ("" for its own), h being the home, d Pi's agent folder and
-// version the Pi on PATH's:
+// through ("" for its own), h being the home, d Pi's agent folder, version
+// the Pi on PATH's and roots npm's global folders where Pi is (piDetectIn):
// - Pi 0.99 or later, or a Pi whose version isn't known, with no MCP
// extension loaded and its own MCP on: mcp.json, as Pi has it. With
// nothing loaded only Pi's own MCP reads servers, and every Pi since
@@ -245,8 +266,8 @@ func piDetect(d string) piPlugins {
// ignored).
// - otherwise, as before 0.99 — pi-mcp-adapter, loaded, stands in for
// Pi's own MCP (piFiles).
-func piMCP(h, d, version string) (*mcpFile, string) {
- p := piDetect(d)
+func piMCP(h, d, version string, roots []string) (*mcpFile, string) {
+ p := piDetectIn(d, roots)
native := piNative(version) || version == ""
if native && !p.adapter && !p.ext && !p.noBuiltin {
native, adapter := filepath.Join(d, "mcp.json"), filepath.Join(d, "mcp-adapter.json")
diff --git a/internal/library/targets.go b/internal/library/targets.go
index a985cb96d..9b90f2f17 100644
--- a/internal/library/targets.go
+++ b/internal/library/targets.go
@@ -87,6 +87,12 @@ func codebuddyMCP(dir string) string {
if base == "" {
base = home()
}
+ return codebuddyMCPIn(dir, base)
+}
+
+// codebuddyMCPIn is codebuddyMCP with base as where .codebuddy.json is
+// beside: a WSL distro's home for the CodeBuddy Code there.
+func codebuddyMCPIn(dir, base string) string {
all := []string{filepath.Join(dir, ".mcp.json"), filepath.Join(dir, "mcp.json"), filepath.Join(base, ".codebuddy.json")}
for _, p := range all {
if _, err := os.Stat(p); err == nil {
@@ -175,7 +181,7 @@ func targetOf(a *agent.Agent) *Target {
// Pi 0.99 reads MCP servers itself, from its mcp.json; before it,
// and while an MCP extension replaces its own (pi-mcp-adapter,
// pi-mcp-extension), each extension reads its own file (pimcp.go)
- t.MCP, t.MCPVia = piMCP(h, d, piVersion(a))
+ t.MCP, t.MCPVia = piMCP(h, d, piVersion(a), piGlobalRoots())
t.Skills = filepath.Join(d, "skills")
case "dsh":
// DeepSeek Harness reads $DSH_HOME/AGENTS.md and $DSH_HOME/skills;
@@ -597,31 +603,81 @@ func wslTargetOf(a *agent.Agent) *Target {
case "claude":
d := filepath.Join(h, ".claude")
t.Instructions = filepath.Join(d, "CLAUDE.md")
- t.MCP = &mcpFile{Path: filepath.Join(h, ".claude.json"), Format: fmtClaude, WSL: true, Distro: a.WSL, Home: linuxHome(h)}
+ t.MCP = &mcpFile{Path: filepath.Join(h, ".claude.json"), Format: fmtClaude}
t.Skills = filepath.Join(d, "skills")
t.Settings = filepath.Join(d, "settings.json")
case "codex":
d := filepath.Join(h, ".codex")
t.Instructions = filepath.Join(d, "AGENTS.md")
t.Override = filepath.Join(d, "AGENTS.override.md")
- t.MCP = &mcpFile{Path: filepath.Join(d, "config.toml"), Format: fmtCodex, WSL: true, Distro: a.WSL, Home: linuxHome(h)}
+ t.MCP = &mcpFile{Path: filepath.Join(d, "config.toml"), Format: fmtCodex}
t.Skills = filepath.Join(d, "skills")
case "pi":
- // its MCP servers go where the Pi installed there reads them,
- // which its version decides (piMCP), and that isn't known here
+ // its MCP servers go where the Pi installed there reads them, as on
+ // this machine (piMCP): its version is what the distro's pi said
+ // at the probe, and its extensions are those its settings.json and
+ // the distro's npm folders have (leokon on Discord: only the
+ // Windows Pi was offered MCP servers)
d := filepath.Join(h, ".pi", "agent")
t.Instructions = firstThere(d, "AGENTS.md", "AGENTS.MD", "CLAUDE.md", "CLAUDE.MD")
t.Override = filepath.Join(d, "AGENTS.override.md")
+ t.MCP, t.MCPVia = piMCP(h, d, piVersion(a), wslPiRoots(h))
t.Skills = filepath.Join(d, "skills")
case "omo":
d := filepath.Join(h, ".omo", "agent")
t.Instructions = firstThere(d, "AGENTS.md", "AGENTS.MD", "CLAUDE.md", "CLAUDE.MD")
t.Override = filepath.Join(d, "AGENTS.override.md")
- t.MCP = &mcpFile{Path: filepath.Join(d, "mcp.json"), Format: fmtPiNative, WSL: true, Distro: a.WSL, Home: linuxHome(h)}
+ t.MCP = &mcpFile{Path: filepath.Join(d, "mcp.json"), Format: fmtPiNative}
+ t.Skills = filepath.Join(d, "skills")
+ case "gemini":
+ // as targetOf's, under the distro's home
+ d := filepath.Join(h, ".gemini")
+ t.Instructions = filepath.Join(d, "GEMINI.md")
+ t.MCP = &mcpFile{Path: filepath.Join(d, "settings.json"), Format: fmtGemini}
+ t.Skills = filepath.Join(d, "skills")
+ case "agy":
+ d := filepath.Join(h, ".gemini", "config")
+ 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")
+ case "crush":
+ // its crush.json is the distro's ~/.config/crush's (agent.crushIn),
+ // CRUSH.md and skills beside it
+ d := filepath.Dir(a.Path)
+ t.Instructions = filepath.Join(d, "CRUSH.md")
+ t.MCP = &mcpFile{Path: a.Path, Format: fmtCrush}
t.Skills = filepath.Join(d, "skills")
+ t.SkillsAlso = []string{"claude@" + strings.SplitN(a.ID, "@", 2)[1]}
+ case "cline":
+ // beside its providers.json; the distro's CLINE_MCP_SETTINGS_PATH
+ // isn't read
+ t.MCP = &mcpFile{Path: filepath.Join(filepath.Dir(a.Path), "cline_mcp_settings.json"), Format: fmtCline}
+ t.Skills = filepath.Join(a.Dir, "skills")
+ case "codebuddy":
+ t.MCP = &mcpFile{Path: codebuddyMCPIn(a.Dir, h), Format: fmtClaude}
+ t.Skills = filepath.Join(a.Dir, "skills")
+ t.Instructions = firstThere(a.Dir, "CODEBUDDY.md", "CODEBUDDY.mdc")
+ case "kimi":
+ // its folder is the distro's (agent.kimiDir); the new Kimi Code's
+ // AGENTS.md is in it. The skills it shares with other agents (the
+ // distro's ~/.agents/skills) aren't given here
+ t.MCP = &mcpFile{Path: filepath.Join(a.Dir, "mcp.json"), Format: fmtKimi}
+ if filepath.Base(a.Dir) == ".kimi-code" {
+ t.Instructions = filepath.Join(a.Dir, "AGENTS.md")
+ }
+ case "goose":
+ // its config.yaml is the distro's ~/.config/goose's; the skills it
+ // reads first are the distro's ~/.agents/skills, which aren't
+ // given here
+ t.Instructions = filepath.Join(filepath.Dir(a.Path), ".goosehints")
+ t.MCP = &mcpFile{Path: a.Path, Format: fmtGoose}
default:
return wslOwnFolder(a)
}
+ if t.MCP != nil {
+ // a Windows program isn't given to it (mcpFile.side)
+ t.MCP.WSL, t.MCP.Distro, t.MCP.Home = true, a.WSL, linuxHome(h)
+ }
return t
}
diff --git a/internal/library/wsl_mcp_test.go b/internal/library/wsl_mcp_test.go
new file mode 100644
index 000000000..e3ada6321
--- /dev/null
+++ b/internal/library/wsl_mcp_test.go
@@ -0,0 +1,162 @@
+package library
+
+import (
+ "os"
+ "path/filepath"
+ "strings"
+ "testing"
+
+ "github.com/yetone/magpie/internal/agent"
+)
+
+// A Pi in a WSL distro is offered MCP servers, written where the Pi there
+// reads them: as on this machine, by the version the distro's pi gave its
+// probe and the extensions its settings.json and the distro's npm folders
+// have (leokon on Discord: only the Windows Pi was listed under MCP).
+func TestWSLPiMCP(t *testing.T) {
+ sandbox(t)
+ root := map[string]string{"Ubuntu": t.TempDir(), "Debian": t.TempDir(), "Arch": t.TempDir()}
+ homeOf := func(d string) string { return filepath.Join(root[d], "home", "me") }
+ // Ubuntu: Pi 1.2.0, MCP of its own; Debian: Pi 0.98, before it, with
+ // no extension; Arch: Pi 0.98 with pi-mcp-adapter 2, from the
+ // distro's npm global folder (settings.json doesn't pin it)
+ write(t, filepath.Join(homeOf("Ubuntu"), ".pi", "agent", "settings.json"), "{}\n")
+ write(t, filepath.Join(homeOf("Debian"), ".pi", "agent", "settings.json"), "{}\n")
+ write(t, filepath.Join(homeOf("Arch"), ".pi", "agent", "settings.json"), `{"packages": ["npm:pi-mcp-adapter"]}`+"\n")
+ write(t, filepath.Join(homeOf("Arch"), ".npm-global", "lib", "node_modules", "pi-mcp-adapter", "package.json"), `{"name": "pi-mcp-adapter", "version": "2.4.0"}`)
+ t.Cleanup(agent.FakeWSL(map[string]string{
+ "Ubuntu": "home:/home/me\ndir:.pi\nbin:pi /usr/local/bin/pi\nver:pi 1.2.0\n",
+ "Debian": "home:/home/me\ndir:.pi\nbin:pi /usr/local/bin/pi\nver:pi 0.98.0\n",
+ "Arch": "home:/home/me\ndir:.pi\nbin:pi /usr/local/bin/pi\nver:pi 0.98.0\n",
+ }, root))
+
+ want := map[string]struct {
+ file string
+ format mcpFormat
+ via string
+ }{
+ "Ubuntu": {".pi/agent/mcp.json", fmtPiNative, ""},
+ "Debian": {".pi/agent/mcp-adapter.json", fmtPi, "pi-mcp-adapter"},
+ "Arch": {".pi/agent/mcp.json", fmtPi, "pi-mcp-adapter"},
+ }
+ var all []string
+ for d, w := range want {
+ id := "pi@wsl:" + d
+ all = append(all, id)
+ tg := targetByID(id)
+ if tg == nil {
+ t.Fatalf("%s isn't a target: %v", id, ids(Targets()))
+ }
+ if tg.MCP == nil || tg.MCP.Path != filepath.Join(homeOf(d), w.file) || tg.MCP.Format != w.format || tg.MCPVia != w.via ||
+ !tg.MCP.WSL || tg.MCP.Distro != d {
+ t.Errorf("%s: mcp %+v via %q, want %+v", id, tg.MCP, tg.MCPVia, w)
+ }
+ }
+ // the page lists it under MCP: its view names the file
+ view, err := Read(nil)
+ if err != nil {
+ t.Fatal(err)
+ }
+ for _, v := range view.Agents {
+ if strings.HasPrefix(v.ID, "pi@wsl:") && v.MCP == "" {
+ t.Errorf("%s has no MCP file in the page's view", v.ID)
+ }
+ }
+
+ ok(t)(SaveServer("", Server{Name: "fetch", Transport: "stdio", Command: "uvx", Args: []string{"mcp-server-fetch"}, Agents: all}))
+ for d, w := range want {
+ if s := read(t, filepath.Join(homeOf(d), w.file)); !strings.Contains(s, `"fetch"`) || !strings.Contains(s, `"uvx"`) {
+ t.Errorf("pi@wsl:%s %s:\n%s", d, w.file, s)
+ }
+ }
+ if b, _ := os.ReadFile(filepath.Join(home(), ".pi", "agent", "mcp.json")); strings.Contains(string(b), "fetch") {
+ t.Error("this machine's Pi got the server")
+ }
+ // a Windows program is nothing it can start
+ res, err := SaveServer("", Server{Name: "win", Transport: "stdio", Command: `C:\Program Files\nodejs\npx.cmd`, Args: []string{"x"}, Agents: []string{"pi@wsl:Ubuntu"}})
+ if err != nil {
+ t.Fatal(err)
+ }
+ if len(res.Problems) != 1 || res.Problems[0].Agent != "pi@wsl:Ubuntu" {
+ t.Errorf("problems: %+v", res.Problems)
+ }
+ if strings.Contains(read(t, filepath.Join(homeOf("Ubuntu"), ".pi/agent/mcp.json")), `"win"`) {
+ t.Error("the Windows program was given to pi@wsl")
+ }
+}
+
+// Every other agent this machine's MCP servers reach that magpie finds in a
+// WSL distro is given them there too, in its own file under the distro's
+// home and never a Windows program: Gemini CLI, Antigravity CLI, Crush,
+// Cline, CodeBuddy Code, Kimi Code and Goose (each was set up in WSL but
+// left out of the library).
+func TestWSLMCPSiblings(t *testing.T) {
+ sandbox(t)
+ root := t.TempDir()
+ h := filepath.Join(root, "home", "me")
+ for _, f := range []string{
+ ".gemini/settings.json", ".gemini/antigravity-cli/settings.json", ".config/crush/crush.json",
+ ".cline/data/settings/providers.json", ".codebuddy/models.json", ".kimi-code/config.toml", ".config/goose/config.yaml",
+ } {
+ content := "{}\n"
+ if strings.HasSuffix(f, ".toml") || strings.HasSuffix(f, ".yaml") {
+ content = ""
+ }
+ write(t, filepath.Join(h, f), content)
+ }
+ t.Cleanup(agent.FakeWSL(map[string]string{
+ "Ubuntu": "home:/home/me\nbin:gemini /usr/bin/gemini\ndir:.gemini/antigravity-cli\nbin:agy /usr/bin/agy\n" +
+ "dir:.config/crush\nbin:crush /usr/bin/crush\ndir:.cline\nbin:cline /usr/bin/cline\n" +
+ "dir:.codebuddy\nbin:codebuddy /usr/bin/codebuddy\ndir:.kimi-code\nbin:kimi /usr/bin/kimi\ndir:.config/goose\n",
+ }, map[string]string{"Ubuntu": root}))
+
+ want := map[string]string{
+ "gemini@wsl:Ubuntu": ".gemini/settings.json",
+ "agy@wsl:Ubuntu": ".gemini/config/mcp_config.json",
+ "crush@wsl:Ubuntu": ".config/crush/crush.json",
+ "cline@wsl:Ubuntu": ".cline/data/settings/cline_mcp_settings.json",
+ "codebuddy@wsl:Ubuntu": ".codebuddy/.mcp.json",
+ "kimi@wsl:Ubuntu": ".kimi-code/mcp.json",
+ "goose@wsl:Ubuntu": ".config/goose/config.yaml",
+ }
+ var all []string
+ for id, f := range want {
+ all = append(all, id)
+ tg := targetByID(id)
+ if tg == nil {
+ t.Errorf("%s isn't a target: %v", id, ids(Targets()))
+ continue
+ }
+ if tg.MCP == nil || tg.MCP.Path != filepath.Join(h, f) || !tg.MCP.WSL || tg.MCP.Distro != "Ubuntu" || !tg.Copy {
+ t.Errorf("%s: mcp %+v", id, tg.MCP)
+ }
+ // nothing it is given is this machine's
+ for _, p := range []string{tg.Instructions, tg.Skills} {
+ if p != "" && !strings.HasPrefix(p, h) {
+ t.Errorf("%s: %s isn't in the distro", id, p)
+ }
+ }
+ }
+ if tg := targetByID("crush@wsl:Ubuntu"); tg != nil && (len(tg.SkillsAlso) != 1 || tg.SkillsAlso[0] != "claude@wsl:Ubuntu") {
+ t.Errorf("crush@wsl reads skills of %v", tg.SkillsAlso)
+ }
+
+ ok(t)(SaveServer("", Server{Name: "fetch", Transport: "stdio", Command: "uvx", Args: []string{"mcp-server-fetch"}, Agents: all}))
+ for id, f := range want {
+ if s := read(t, filepath.Join(h, f)); !strings.Contains(s, "fetch") || !strings.Contains(s, "uvx") {
+ t.Errorf("%s %s:\n%s", id, f, s)
+ }
+ }
+ res, err := SaveServer("", Server{Name: "win", Transport: "stdio", Command: `C:\Program Files\nodejs\npx.cmd`, Args: []string{"x"}, Agents: all})
+ if err != nil {
+ t.Fatal(err)
+ }
+ if len(res.Problems) != len(all) {
+ t.Errorf("problems: %+v", res.Problems)
+ }
+ for id, f := range want {
+ if strings.Contains(read(t, filepath.Join(h, f)), "npx.cmd") {
+ t.Errorf("the Windows program was given to %s", id)
+ }
+ }
+}
diff --git a/internal/library/wsl_test.go b/internal/library/wsl_test.go
index 9cfca8a23..67d02dfe4 100644
--- a/internal/library/wsl_test.go
+++ b/internal/library/wsl_test.go
@@ -42,7 +42,7 @@ func TestWSLTargets(t *testing.T) {
want := map[string][3]string{ // instructions, MCP, skills
wslCodex: {".codex/AGENTS.md", ".codex/config.toml", ".codex/skills"},
wslClaude: {".claude/CLAUDE.md", ".claude.json", ".claude/skills"},
- wslPi: {".pi/agent/AGENTS.md", "", ".pi/agent/skills"},
+ wslPi: {".pi/agent/AGENTS.md", ".pi/agent/mcp.json", ".pi/agent/skills"},
wslOmO: {".omo/agent/AGENTS.md", ".omo/agent/mcp.json", ".omo/agent/skills"},
}
for id, w := range want {