library: an agent whose CLI is gone (only its config folder left) is no Library write target, and nothing it already has is removed (#2254, ggbdpq)
After an agent is uninstalled, the Agents page shows "CLI not found"
(d0fcb8bc), but Library still offered it for skills, MCP servers, shared
instructions and rtk, and a sync wrote into a folder nothing reads.
- library.Targets() leaves out an agent whose CLI is missing
(agent.CLIMissing: false for WSL, plugin and detect agents), so sync,
the read view, market, instructions, skills and found servers all
drop it at their one upstream.
- Takes() refuses a gone agent by name, so `library mcp add ...
agents=hermes` says "Hermes Agent's CLI isn't installed here; nothing
reads its MCP servers until it is installed again" instead of "every
agent already has it".
- The guards that must still see a gone agent's files (projects'
notGlobal for skills and MCP, instructions' own-file check) read
everyTarget(), so a set kept in the agent's own file is still refused.
- rtk: a gone agent isn't offered rtk; one that still has the hook is
listed so the hook can be taken out.
- Nothing a user wrote is removed: sync acts per target, so a gone
agent's skills, servers and AGENTS.md stay as they are, and the client
keeps agent ids it doesn't show.
Run:
- Sandbox HOME, real binaries: old wrote mcp_servers into a gone
~/.hermes/config.yaml; new refuses with the message above, exit 1.
- New tests TestTargetsLeaveGoneAgentsOut, TestGoneAgentKeepsWhatItHas,
TestRTKLeavesGoneAgentsOut; each broken by hand (Targets check,
Takes refusal, everyTarget in instructions, rtk gate) goes red.
- go test -tags nogui ./internal/library ./internal/tui ./internal/cli
./internal/gui: ok. Fixtures that relied on a gone CLI now place one
(holdCLI, TestRTKHermesHome, TestRTKOffPath), and so do profile's
and davsync's sandboxes, whose library syncs to claude and codex
(TestOldProfiles, TestProfileCarriesLibrary, TestSyncLibrary went red
in the full run without them).
- gofmt -l clean; go vet -tags nogui darwin/linux/windows clean.
- go test -tags nogui -p 4 ./... at the pushed head: see the last
commit of this push.
Not tried: the real GUI with an uninstalled agent on a live machine.
Co-authored-by: ggbdpq <ggbdpq@gmail.com>
This commit is contained in:
@@ -14,7 +14,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`), 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. 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`), 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, and what is already written there stays. `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) |
|
||||
| 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`). `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. | [`instructions.go`](../../internal/library/instructions.go) |
|
||||
@@ -26,7 +26,7 @@ agents RTK, a CLI that cuts shell output down before the model reads it.
|
||||
| Skill updates | A skill from GitHub (`kind: github`, a market install among them) keeps the commit it was fetched at and `Hash`, the hash of its files as fetched. `CheckSkills` asks GitHub for each one's last commit and keeps the result in memory; `View.CheckDue` says none was checked since magpie started, or not for `checkEvery` (12 hours), and the page then checks by itself as the skills open (#1449). `editState` says a skill was changed here when the library's folder no longer hashes to `Hash` (`.DS_Store` aside), or an agent's copy was edited since its mark and not yet taken in; the view's `edited` says so. `UpdateSkill` refuses such a skill with `*EditedError` unless told to replace it (the page's own Update asks first; the CLI takes `--replace-edits`), and `UpdateSkills`/`UpdateSomeSkills` leave it as it is, in `Unupdated`. A replaced version that was changed, or that can't be told (no `Hash`), is moved to the backups (`keepReplaced`). Skills the skills CLI manages (`npx skills`, `~/.agents/.skill-lock.json`) are only grouped: the CLI updates them (`npx skills update`). A linked folder, a skill imported from an agent and a `From`-only skill have no remote to check; one CC Switch installed (`Origin`) can be updated by hand but isn't checked. | [`skill_changed.go`](../../internal/library/skill_changed.go), [`skillcheck.go`](../../internal/library/skillcheck.go), [`skills.go`](../../internal/library/skills.go) |
|
||||
| Hooks | A `Hook` (#1790) is a command, an event, an optional matcher, a timeout and the agents ticked for it. Its optional `Description` (#2011) says what it is for in any language, since its name is letters, digits, - and _: one line of at most `maxHookDescription` (200) characters, shown under the name; only library.json keeps it, and no agent is given it. Its event is portable (`HookEvents`: turn-end, after-tool, before-tool, prompt, session-start, each under the agent's own name) or an agent's own (`"codex:PermissionRequest"`), which only that agent is given. A portable tool event can be narrowed to shell or edit tools, each agent's own tool names for them. `syncHooks` writes each into the agent's own file and shape (`hookSpecOf`): Claude Code `<claude dir>/settings.json`, Codex `hooks.json` beside its config.toml, Gemini CLI `~/.gemini/settings.json` (timeout in ms), Cursor `~/.cursor/hooks.json` (flat entries, `version: 1`), and Grok Build `~/.grok/config.toml` and Grok App `agent-home/config.toml` as `[[hooks.<Event>]]` array tables with a `[[hooks.<Event>.hooks]]` child. Grok Build and Grok App run the one CLI, so a `grok:<Event>` own event goes to both (`sameHookFamily`). Every other agent, and an agent in WSL, is refused with why, and the page greys its chip with that reason. The page also says when an agent has every hook turned off (`hooksOff`: Claude Code's `disableAllHooks`, Gemini's `hooksConfig.enabled`, Codex's `[features] hooks`). | [`hooks.go`](../../internal/library/hooks.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. The Backups button at the top of every tab, beside Library folder, opens that folder (`libHead`; Dade on Discord found it at the foot of a long page). | [`backup.go`](../../internal/library/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. `rtkSpec.env` tells the installer the agent's folder where rtk would pick another: Hermes Agent's is `appdir.HermesHome` (`%LOCALAPPDATA%\hermes` on Windows), which rtk is given as `HERMES_HOME`, since rtk 0.51 knows only `$HERMES_HOME` and `~/.hermes`. Antigravity CLI (`agy`, #2202) gets rtk 0.51's own plugin for Antigravity, `plugins/rtk` in its global customization folder `~/.gemini/config` (`plugin.json`, `hooks.json` with `PreToolUse` → `rtk hook antigravity`, `rules/AGENTS.md`), which `agy plugin list` lists; switching it off takes that one folder out. rtk 0.50 knows Antigravity only per project and fails `rtk init -g --agent antigravity`, so an older rtk is `blocked` (`agyBlocked`) and the row says to update RTK. 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`; Grok Build and Grok App: `rtk init` has no Grok or Grok App agent, so both are listed with the switch off). | [`rtk.go`](../../internal/library/rtk.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. An agent gone for its CLI (`CLIMissing`, #2254) isn't offered rtk, but one that still has the hook is listed so it can be taken out. `rtkSpec.blocked` stops the installer where it would break an agent. `rtkSpec.env` tells the installer the agent's folder where rtk would pick another: Hermes Agent's is `appdir.HermesHome` (`%LOCALAPPDATA%\hermes` on Windows), which rtk is given as `HERMES_HOME`, since rtk 0.51 knows only `$HERMES_HOME` and `~/.hermes`. Antigravity CLI (`agy`, #2202) gets rtk 0.51's own plugin for Antigravity, `plugins/rtk` in its global customization folder `~/.gemini/config` (`plugin.json`, `hooks.json` with `PreToolUse` → `rtk hook antigravity`, `rules/AGENTS.md`), which `agy plugin list` lists; switching it off takes that one folder out. rtk 0.50 knows Antigravity only per project and fails `rtk init -g --agent antigravity`, so an older rtk is `blocked` (`agyBlocked`) and the row says to update RTK. 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`; Grok Build and Grok App: `rtk init` has no Grok or Grok App agent, so both are listed with the switch off). | [`rtk.go`](../../internal/library/rtk.go) |
|
||||
|
||||
## Runtime path
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package davsync
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/yetone/magpie/internal/testenv"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
@@ -143,7 +144,17 @@ func (c computer) use(t *testing.T) {
|
||||
t.Setenv("USERPROFILE", string(c))
|
||||
t.Setenv("XDG_CONFIG_HOME", filepath.Join(string(c), ".config"))
|
||||
t.Setenv("XDG_CACHE_HOME", filepath.Join(string(c), ".cache"))
|
||||
t.Setenv("PATH", "")
|
||||
// Claude Code's and Codex's CLIs are here: an agent whose CLI is gone
|
||||
// is no Library target (#2254), and a computer's library is synced to
|
||||
// them
|
||||
bin := filepath.Join(string(c), "bin")
|
||||
for _, cli := range []string{"claude", "codex"} {
|
||||
testenv.Program(t, filepath.Join(bin, cli), "#!/bin/sh\n")
|
||||
if err := os.WriteFile(filepath.Join(bin, cli+".exe"), nil, 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
t.Setenv("PATH", bin)
|
||||
for _, v := range agentenv.Vars {
|
||||
t.Setenv(v, "")
|
||||
}
|
||||
|
||||
@@ -175,6 +175,9 @@ func TestAgentMCPFiles(t *testing.T) {
|
||||
}
|
||||
p := filepath.Join(h, c.file)
|
||||
write(t, p, c.user)
|
||||
// omp, Cline and CodeBuddy have an install command, so with the
|
||||
// MCP file alone each is gone (#2177): its CLI beside the folder
|
||||
holdCLI(t, h, map[string]string{"omp": "omp", "cline": "cline", "codebuddy": "codebuddy"}[c.id])
|
||||
parse := func() map[string]entry {
|
||||
t.Helper()
|
||||
var doc map[string]any
|
||||
@@ -294,6 +297,7 @@ func TestAgentMCPFiles(t *testing.T) {
|
||||
func TestCodeBuddyMCPFile(t *testing.T) {
|
||||
h := sandbox(t)
|
||||
write(t, filepath.Join(h, ".codebuddy/models.json"), "")
|
||||
holdCLI(t, h, "codebuddy") // the folder alone is gone (#2177)
|
||||
tg := targetByID("codebuddy")
|
||||
if tg == nil || tg.MCP == nil || tg.MCP.Path != filepath.Join(h, ".codebuddy/.mcp.json") {
|
||||
t.Fatalf("with no file: %+v", tg)
|
||||
|
||||
@@ -20,6 +20,10 @@ func TestAgentsSkillsFolders(t *testing.T) {
|
||||
".hermes/config.yaml", ".grok/config.toml", ".qoder/settings.json", ".workbuddy/models.json", ".fx/settings.json", ".config/devin/config.json"} {
|
||||
write(t, filepath.Join(h, f), "")
|
||||
}
|
||||
// hermes and Cline installed: the CLI beside the folder (the folder
|
||||
// alone is gone, #2177, and no target — TestTargetsLeaveGoneAgentsOut)
|
||||
holdCLI(t, h, "hermes")
|
||||
holdCLI(t, h, "cline")
|
||||
want := map[string]string{
|
||||
"kimi": ".agents/skills",
|
||||
"goose": ".agents/skills",
|
||||
@@ -133,7 +137,11 @@ func TestSharedSkillsWrittenOnce(t *testing.T) {
|
||||
// a word of its "own skill by that name".
|
||||
func TestImportSharedSkillForKimi(t *testing.T) {
|
||||
h := sandbox(t)
|
||||
// goose off: its folder and, since the sandbox puts the agents' CLIs
|
||||
// beside them (#2177), its CLI too
|
||||
os.RemoveAll(filepath.Join(h, ".config/goose"))
|
||||
os.Remove(filepath.Join(h, "bin/goose"))
|
||||
os.Remove(filepath.Join(h, "bin/goose.exe"))
|
||||
write(t, filepath.Join(h, ".kimi/config.toml"), "")
|
||||
shared := filepath.Join(h, ".agents/skills/orca")
|
||||
skill(t, shared, "orca", "Orca")
|
||||
@@ -290,6 +298,7 @@ func TestSiblingInstructionsMore(t *testing.T) {
|
||||
write(t, filepath.Join(h, ".qoder", "settings.json"), "{}")
|
||||
write(t, filepath.Join(h, ".commandcode", "settings.json"), "{}")
|
||||
write(t, filepath.Join(h, ".codebuddy", "settings.json"), "{}")
|
||||
holdCLI(t, h, "codebuddy") // the folder alone is gone (#2177)
|
||||
write(t, filepath.Join(h, ".codebuddy", "CODEBUDDY.mdc"), "# Mine\n")
|
||||
want := map[string]string{
|
||||
"qoder": filepath.Join(h, ".qoder", "AGENTS.md"),
|
||||
@@ -375,6 +384,7 @@ func TestPiInstructionsFirstThere(t *testing.T) {
|
||||
pi := filepath.Join(h, ".pi", "agent")
|
||||
omo := filepath.Join(h, ".omo", "agent")
|
||||
write(t, filepath.Join(omo, "settings.json"), "{}")
|
||||
holdCLI(t, h, "omo") // the folder alone is gone (#2177)
|
||||
for _, d := range []string{pi, omo} {
|
||||
if tg := targetByID(map[string]string{pi: "pi", omo: "omo"}[d]); tg == nil ||
|
||||
tg.Instructions != filepath.Join(d, "AGENTS.md") || tg.Override != filepath.Join(d, "AGENTS.override.md") {
|
||||
|
||||
@@ -35,6 +35,7 @@ func TestHermesMCP(t *testing.T) {
|
||||
t.Setenv("HERMES_HOME", dir)
|
||||
p := filepath.Join(dir, "config.yaml")
|
||||
write(t, p, hermesConfig)
|
||||
holdCLI(t, h, "hermes") // the config alone is gone (#2173, #2177)
|
||||
|
||||
tg := targetByID("hermes")
|
||||
if tg == nil || tg.MCP == nil || tg.MCP.Path != p {
|
||||
@@ -130,9 +131,10 @@ func TestHermesMCP(t *testing.T) {
|
||||
|
||||
// A server Hermes has that the library doesn't is found, to bring in.
|
||||
func TestHermesMCPFound(t *testing.T) {
|
||||
sandbox(t)
|
||||
h := sandbox(t)
|
||||
dir := appdir.HermesHome()
|
||||
write(t, filepath.Join(dir, "config.yaml"), strings.Replace(hermesConfig, "toolsets:", " remote:\n url: https://r.example/sse\n transport: sse\ntoolsets:", 1))
|
||||
holdCLI(t, h, "hermes") // the config alone is gone (#2173, #2177)
|
||||
l, err := load()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
||||
@@ -563,7 +563,7 @@ func (l *Library) linkable(file string) (string, error) {
|
||||
return "", fmt.Errorf("the set %q is kept in %s already", s.Name, file)
|
||||
}
|
||||
}
|
||||
for _, t := range Targets() {
|
||||
for _, t := range everyTarget() {
|
||||
for _, p := range []string{t.Instructions, t.Override} {
|
||||
if p != "" && realBelow(p) == real {
|
||||
return "", fmt.Errorf("%s is %s's own instructions, which magpie writes into: a set can't be kept there", file, t.Agent.Name)
|
||||
|
||||
@@ -35,6 +35,18 @@ func sandbox(t *testing.T) string {
|
||||
bin := filepath.Join(h, "bin")
|
||||
testenv.Program(t, filepath.Join(bin, "gemini"), "#!/bin/sh\n")
|
||||
write(t, filepath.Join(bin, "gemini.exe"), "")
|
||||
// the other fixture agents' CLIs beside their folders, as on a machine
|
||||
// where they are really installed: with the folder alone each would be
|
||||
// gone (CLIMissing, #2177) and no target of the library's. Only these:
|
||||
// a stand-in for an agent no folder here keeps would have it detected
|
||||
// by its binary alone in every test.
|
||||
for _, name := range []string{
|
||||
"claude", "codex", "opencode", "mimo", "deveco", "pi", "goose",
|
||||
"cursor-agent", "copilot", "crush", "dsh",
|
||||
} {
|
||||
testenv.Program(t, filepath.Join(bin, name), "#!/bin/sh\n")
|
||||
write(t, filepath.Join(bin, name+".exe"), "")
|
||||
}
|
||||
t.Setenv("PATH", bin)
|
||||
// never the machine's global node_modules
|
||||
roots := piGlobalRoots
|
||||
@@ -73,6 +85,19 @@ func write(t *testing.T, p, s string) {
|
||||
}
|
||||
}
|
||||
|
||||
// holdCLI puts a CLI of the given name in the sandbox's bin, beside the
|
||||
// agent folder the test wrote: the folder alone is an uninstall that left
|
||||
// it behind (#2177), and no target of the library's. An empty name is
|
||||
// nothing, for an agent with no install command, which is never gone.
|
||||
func holdCLI(t *testing.T, h, bin string) {
|
||||
t.Helper()
|
||||
if bin == "" {
|
||||
return
|
||||
}
|
||||
testenv.Program(t, filepath.Join(h, "bin", bin), "#!/bin/sh\n")
|
||||
write(t, filepath.Join(h, "bin", bin+".exe"), "")
|
||||
}
|
||||
|
||||
func read(t *testing.T, p string) string {
|
||||
t.Helper()
|
||||
b, err := os.ReadFile(p)
|
||||
|
||||
@@ -58,6 +58,7 @@ func TestToolsOffInTheEntry(t *testing.T) {
|
||||
h := sandbox(t)
|
||||
t.Setenv("HERMES_HOME", filepath.Join(h, "hermes-home"))
|
||||
write(t, filepath.Join(h, "hermes-home", "config.yaml"), "model:\n default: x\n")
|
||||
holdCLI(t, h, "hermes") // the config alone is gone (#2173, #2177)
|
||||
agents := []string{"codex", "crush", "gemini", "hermes"}
|
||||
keys := map[string]string{"codex": "disabled_tools", "crush": "disabled_tools", "gemini": "excludeTools", "hermes": "exclude"}
|
||||
ok(t)(SaveServer("", Server{Name: "fs", Transport: "stdio", Command: "npx", Args: []string{"-y", "@mcp/fs"}, Agents: agents}))
|
||||
|
||||
@@ -14,6 +14,7 @@ func TestOmoTarget(t *testing.T) {
|
||||
h := sandbox(t)
|
||||
d := filepath.Join(h, ".omo", "agent")
|
||||
write(t, filepath.Join(d, "settings.json"), "{}")
|
||||
holdCLI(t, h, "omo") // the folder alone is gone (#2177)
|
||||
tg := targetByID("omo")
|
||||
if tg == nil || tg.MCP == nil || tg.MCP.Path != filepath.Join(d, "mcp.json") || tg.MCP.Format != fmtPiNative ||
|
||||
tg.Instructions != filepath.Join(d, "AGENTS.md") || tg.Skills != filepath.Join(d, "skills") {
|
||||
|
||||
@@ -350,7 +350,7 @@ func notGlobal(dir string) error {
|
||||
if realDir(dir) == realDir(home()) {
|
||||
return fmt.Errorf("the home folder's skills are every project's: give skills to the agents themselves instead")
|
||||
}
|
||||
for _, t := range Targets() {
|
||||
for _, t := range everyTarget() {
|
||||
if t.Skills == "" {
|
||||
continue
|
||||
}
|
||||
@@ -360,7 +360,7 @@ func notGlobal(dir string) error {
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, t := range Targets() {
|
||||
for _, t := range everyTarget() {
|
||||
if t.MCP == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -660,7 +660,11 @@ func rtkAgents(agents []*agent.Agent) []*agent.Agent {
|
||||
}
|
||||
var out []*agent.Agent
|
||||
for _, a := range agents {
|
||||
if _, ok := rtkSpecs[a.ID]; ok {
|
||||
sp, ok := rtkSpecs[a.ID]
|
||||
// an uninstall that left the folder behind (#2254) isn't given rtk,
|
||||
// as the library gives it nothing (Targets); one with rtk's hook
|
||||
// still shows, so the hook can be taken out
|
||||
if ok && (!a.CLIMissing() || sp.has(a)) {
|
||||
out = append(out, a)
|
||||
}
|
||||
}
|
||||
@@ -687,7 +691,7 @@ func ReadRTK() *RTKView {
|
||||
v.Agents = append(v.Agents, ra)
|
||||
}
|
||||
for _, a := range agents {
|
||||
if why, ok := rtkNoHook[a.ID]; ok {
|
||||
if why, ok := rtkNoHook[a.ID]; ok && !a.CLIMissing() {
|
||||
v.Agents = append(v.Agents, RTKAgent{ID: a.ID, Name: a.Name, Icon: a.Icon, Blocked: why, NoHook: true})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,9 @@ func TestRTKOffPath(t *testing.T) {
|
||||
testenv.Program(t, filepath.Join(local, "rtk"), fakeRTK)
|
||||
tools := filepath.Join(h, "tools")
|
||||
testenv.Program(t, filepath.Join(tools, "curl"), "#!/bin/sh\n")
|
||||
// Claude Code's CLI on this PATH too: its folder alone is gone (#2254)
|
||||
testenv.Program(t, filepath.Join(tools, "claude"), "#!/bin/sh\n")
|
||||
write(t, filepath.Join(tools, "claude.exe"), "")
|
||||
t.Setenv("PATH", tools)
|
||||
|
||||
v := ReadRTK()
|
||||
|
||||
@@ -467,6 +467,7 @@ func TestRTKHermesHome(t *testing.T) {
|
||||
h := sandbox(t)
|
||||
bin := filepath.Join(h, "bin")
|
||||
testenv.Program(t, filepath.Join(bin, "rtk"), fakeRTKHermes)
|
||||
holdCLI(t, h, "hermes") // the config alone is gone (#2254)
|
||||
t.Setenv("PATH", bin)
|
||||
for _, c := range []struct{ name, env string }{
|
||||
// the reporter's layout: Hermes's folder isn't ~/.hermes
|
||||
|
||||
@@ -24,8 +24,11 @@ func symlink(t *testing.T, to, at string) {
|
||||
// shared folder as it is.
|
||||
func TestSharedAgentsSkills(t *testing.T) {
|
||||
h := sandbox(t)
|
||||
// no agent here whose own folder the shared one is (Goose's)
|
||||
// no agent here whose own folder the shared one is (Goose's): its CLI
|
||||
// of the sandbox too, since that alone would have it here (#2177)
|
||||
os.RemoveAll(filepath.Join(h, ".config/goose"))
|
||||
os.Remove(filepath.Join(h, "bin/goose"))
|
||||
os.Remove(filepath.Join(h, "bin/goose.exe"))
|
||||
shared := filepath.Join(h, ".agents/skills")
|
||||
// a skill kept elsewhere (D:\aimer-skills\…) linked into the shared folder
|
||||
ext := filepath.Join(h, "aimer-skills/grilling")
|
||||
|
||||
@@ -650,7 +650,14 @@ func apps() []*agent.Agent {
|
||||
|
||||
// Targets are the agents on this machine that magpie can give any of the
|
||||
// three to, in the order the rest of magpie lists them.
|
||||
func Targets() []*Target {
|
||||
func Targets() []*Target { return targets(false) }
|
||||
|
||||
// everyTarget is Targets with the agents gone for their CLI too: a folder
|
||||
// an uninstall left behind is still that agent's own, which a project or
|
||||
// an instruction set is never kept in.
|
||||
func everyTarget() []*Target { return targets(true) }
|
||||
|
||||
func targets(gone bool) []*Target {
|
||||
var out []*Target
|
||||
own := map[string]bool{}
|
||||
for _, a := range apps() {
|
||||
@@ -662,6 +669,12 @@ func Targets() []*Target {
|
||||
if own[a.ID] {
|
||||
continue
|
||||
}
|
||||
// an uninstall that left the folder behind (#2177, #2173): the
|
||||
// Agents page calls the agent gone and offers none of its settings,
|
||||
// since nothing reads them; the library gives nothing to it either
|
||||
if !gone && a.CLIMissing() {
|
||||
continue
|
||||
}
|
||||
if t := targetOf(a); t != nil && t.open() {
|
||||
out = append(out, t)
|
||||
}
|
||||
@@ -750,9 +763,14 @@ func Takes(q, kind string) (string, error) {
|
||||
return "", err
|
||||
}
|
||||
}
|
||||
what := map[string]string{"instructions": "instructions", "mcp": "MCP servers", "skills": "skills"}[kind]
|
||||
// gone for its CLI, as Targets leaves it out (#2254): told so, not
|
||||
// recorded and then given nothing ("every agent already has it")
|
||||
if a.CLIMissing() {
|
||||
return "", fmt.Errorf("%s's CLI isn't installed here; nothing reads its %s until it is installed again%s", a.Name, what, takenBy(kind, what))
|
||||
}
|
||||
t := targetOf(a)
|
||||
var has bool
|
||||
what := map[string]string{"instructions": "instructions", "mcp": "MCP servers", "skills": "skills"}[kind]
|
||||
if t == nil && a.WSL != "" && (a.Home == "" || !agent.WSLRunning(a.WSL)) {
|
||||
return "", fmt.Errorf("WSL %s isn't running: start it, and %s can be given %s", a.WSL, a.Name, what)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,106 @@
|
||||
package library
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"slices"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/yetone/magpie/internal/testenv"
|
||||
)
|
||||
|
||||
// An agent uninstalled outside magpie leaves its folder behind (#2177,
|
||||
// #2173): the Agents page calls it gone (CLIMissing) and offers none of
|
||||
// its settings, since nothing reads them. The Library kept it as a place
|
||||
// to give skills, MCP servers and instructions to, and sync carried on
|
||||
// writing there.
|
||||
func TestTargetsLeaveGoneAgentsOut(t *testing.T) {
|
||||
h := sandbox(t)
|
||||
// Hermes by its config.yaml alone (the reporter's 37 bytes): its
|
||||
// folder is kept by nothing here — no hermes on the sandbox's PATH,
|
||||
// no hermes-agent checkout beside the config
|
||||
write(t, filepath.Join(h, ".hermes", "config.yaml"), "custom_providers: []\nmcp_servers: {}\n")
|
||||
if got := ids(Targets()); slices.Contains(got, "hermes") {
|
||||
t.Fatalf("hermes is a target with its CLI gone: %v", got)
|
||||
}
|
||||
// named for one (magpie library mcp add … agents=hermes), it is
|
||||
// refused, not recorded and then given nothing
|
||||
if _, err := Takes("hermes", "mcp"); err == nil || !strings.Contains(err.Error(), "isn't installed") {
|
||||
t.Fatalf("Takes(hermes, mcp) with its CLI gone: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// An agent that goes keeps what magpie and the user wrote into its folder:
|
||||
// a later change writes nothing there and takes nothing away, and its
|
||||
// instructions file is still its own, never a file a set is kept in.
|
||||
func TestGoneAgentKeepsWhatItHas(t *testing.T) {
|
||||
h := sandbox(t)
|
||||
shared := "Be brief."
|
||||
ok(t)(SaveInstructions(InstructionsChange{Shared: &shared, Agents: []string{"codex"}}))
|
||||
file := filepath.Join(h, ".codex/AGENTS.md")
|
||||
write(t, file, "my own notes\n"+read(t, file))
|
||||
before := read(t, file)
|
||||
if !strings.Contains(before, "Be brief.") {
|
||||
t.Fatalf("codex wasn't given the instructions:\n%s", before)
|
||||
}
|
||||
for _, f := range []string{"codex", "codex.exe"} {
|
||||
if err := os.Remove(filepath.Join(h, "bin", f)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
if slices.Contains(ids(Targets()), "codex") {
|
||||
t.Fatal("codex is a target with its CLI gone")
|
||||
}
|
||||
other := "Be thorough."
|
||||
ok(t)(SaveInstructions(InstructionsChange{Shared: &other}))
|
||||
if got := read(t, file); got != before {
|
||||
t.Errorf("a change after codex went rewrote its instructions:\n%s\nwas:\n%s", got, before)
|
||||
}
|
||||
// with no part of magpie's in it, only its being codex's own refuses it
|
||||
write(t, file, "my own notes\n")
|
||||
if _, err := SaveInstructions(InstructionsChange{Create: &InstrSet{ID: "b", Name: "B", File: file}}); err == nil {
|
||||
t.Error("a set was kept in a gone agent's own instructions file")
|
||||
}
|
||||
}
|
||||
|
||||
// rtk is a Library page's too (#2254): a gone agent isn't offered it, and
|
||||
// one left with rtk's hook still shows, for the hook to be taken out.
|
||||
func TestRTKLeavesGoneAgentsOut(t *testing.T) {
|
||||
if runtime.GOOS == "windows" {
|
||||
t.Skip("the fake rtk is a shell script")
|
||||
}
|
||||
h := sandbox(t)
|
||||
bin := filepath.Join(h, "bin")
|
||||
testenv.Program(t, filepath.Join(bin, "rtk"), fakeRTK)
|
||||
for _, f := range []string{"codex", "codex.exe"} {
|
||||
if err := os.Remove(filepath.Join(bin, f)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
listed := func() bool {
|
||||
return slices.ContainsFunc(ReadRTK().Agents, func(a RTKAgent) bool { return a.ID == "codex" })
|
||||
}
|
||||
if listed() {
|
||||
t.Fatal("codex is offered rtk with its CLI gone")
|
||||
}
|
||||
if _, err := SetRTK("codex", true); err == nil {
|
||||
t.Fatal("rtk was given to codex with its CLI gone")
|
||||
}
|
||||
hooks := filepath.Join(h, ".codex", "hooks.json")
|
||||
write(t, hooks, `{"hooks":{"PreToolUse":[{"matcher":"Bash","hooks":[{"type":"command","command":"rtk hook codex"}]}]}}`)
|
||||
if !listed() {
|
||||
t.Fatal("codex, left with rtk's hook, isn't shown to take it out")
|
||||
}
|
||||
ok := func(v *RTKView, err error) {
|
||||
t.Helper()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
ok(SetRTK("codex", false))
|
||||
if strings.Contains(read(t, hooks), "rtk hook codex") {
|
||||
t.Fatalf("rtk's hook is still in codex:\n%s", read(t, hooks))
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package profile
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/yetone/magpie/internal/testenv"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
@@ -21,7 +22,14 @@ func sandbox(t *testing.T) string {
|
||||
t.Setenv("HOME", h)
|
||||
t.Setenv("USERPROFILE", h)
|
||||
t.Setenv("XDG_CONFIG_HOME", filepath.Join(h, ".config"))
|
||||
t.Setenv("PATH", "")
|
||||
// Claude Code's and Codex's CLIs are here: an agent whose CLI is gone
|
||||
// is no Library target (#2254), and these tests carry its library
|
||||
bin := filepath.Join(h, "bin")
|
||||
for _, cli := range []string{"claude", "codex"} {
|
||||
testenv.Program(t, filepath.Join(bin, cli), "#!/bin/sh\n")
|
||||
write(t, filepath.Join(bin, cli+".exe"), "")
|
||||
}
|
||||
t.Setenv("PATH", bin)
|
||||
for _, k := range agentenv.Vars {
|
||||
t.Setenv(k, "")
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
"github.com/yetone/magpie/internal/agentenv"
|
||||
"github.com/yetone/magpie/internal/library"
|
||||
"github.com/yetone/magpie/internal/provider"
|
||||
"github.com/yetone/magpie/internal/testenv"
|
||||
)
|
||||
|
||||
// home is a sandbox: a home of its own with Claude Code and Codex in it,
|
||||
@@ -24,7 +25,6 @@ func home(t *testing.T) string {
|
||||
t.Setenv("USERPROFILE", h)
|
||||
t.Setenv("XDG_CONFIG_HOME", filepath.Join(h, ".config"))
|
||||
t.Setenv("XDG_CACHE_HOME", filepath.Join(h, ".cache"))
|
||||
t.Setenv("PATH", "")
|
||||
t.Setenv("XDG_DATA_HOME", filepath.Join(h, ".local", "share"))
|
||||
for _, k := range agentenv.Vars {
|
||||
t.Setenv(k, "")
|
||||
@@ -35,6 +35,15 @@ func home(t *testing.T) string {
|
||||
for _, f := range []string{".claude/settings.json", ".codex/config.toml"} {
|
||||
write(t, filepath.Join(h, f), "")
|
||||
}
|
||||
// their CLIs beside the folders, as on a machine where they are really
|
||||
// installed: the folder alone is an uninstall that left it behind
|
||||
// (#2177), gone for the agents page and no target of the library's
|
||||
bin := filepath.Join(h, "bin")
|
||||
for _, name := range []string{"claude", "codex"} {
|
||||
testenv.Program(t, filepath.Join(bin, name), "#!/bin/sh\n")
|
||||
write(t, filepath.Join(bin, name+".exe"), "")
|
||||
}
|
||||
t.Setenv("PATH", bin)
|
||||
for _, p := range []provider.Provider{
|
||||
{ID: "a", Name: "A", Key: "ka", Models: []string{"m", "claude-opus-5-5"}, Chat: "http://127.0.0.1:1/v1"},
|
||||
{ID: "b", Name: "B", Key: "kb", Models: []string{"gpt-5.5"}, Chat: "http://127.0.0.1:1/v1"},
|
||||
|
||||
Reference in New Issue
Block a user