library: an agent's profile id (claude#magpie-desktop) is an agent's id on every route
@AXmake110 on X: on Library > Claude plugins, clicking the chip of a Claude Code config folder (claude#magpie-desktop) answered `agent "claude#magpie-desktop": not an agent's id`, so the plugin couldn't be turned off for it. The page draws a chip for each profile agent (claude#, hermes#, omp#), and the library already writes skills, MCP servers and instructions to them (targets.go), but checkAgent took only name or name@wsl:distro. checkAgent is the one place an agent id is validated in the library. It now takes name[#profile][@wsl:distro], the profile a plain file name like a distro's. That fixes each route through it: plugins/agents (PluginAgents), an agent's own instructions (SaveInstructions Extra, setup.go's extras), skills/how (SetSkillHow) and carry.go's import. The other chip routes (skills, servers, hooks, env, subagents agents) never called it and already took profile ids. No GUI change. Run on mica (mote at load ~130): - TestLibraryTakesAProfilesAgentID (new): with origin/main's library.go put back it FAILs at the plugin's off for the profile with `agent "claude#magpie-desktop": not an agent's id`; passes with the change. It also checks bad ids (claude#, #work, claude#../x, claude#a/b, claude#a#b, claude#.x) are still refused. - gofmt -l internal/library: nothing; go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet ./...: ok. - go test -tags nogui ./internal/library ./internal/gui -count=1: ok. Not run: the full go test ./... (mica had another session's gateway run and GUI suite going), the GUI suite (no GUI file changed), a real Claude Desktop profile. Run at base534b1a334, then rebased onto1ab2c3984(tray/usage files only, nothing in internal/library).
This commit is contained in:
@@ -314,12 +314,19 @@ func checkName(kind, name string) error {
|
||||
}
|
||||
|
||||
// An agent's id is a name, or one in a WSL distro's
|
||||
// (codex@wsl:Ubuntu-24.04): distroRe is the distro's name.
|
||||
// (codex@wsl:Ubuntu-24.04): distroRe is the distro's name. Either can be
|
||||
// one of the agent's profiles, agent#profile (claude#magpie-desktop, a
|
||||
// Claude Code config folder; hermes#work, omp#work): the Library's pages
|
||||
// show those as agents of their own, so every route that takes an agent
|
||||
// takes them (@AXmake110 on X: a plugin couldn't be turned off for
|
||||
// claude#magpie-desktop). distroRe is the profile's name too: a plain
|
||||
// file name, as the id names files of the agent's (fileName).
|
||||
var distroRe = capre.MustCompile(`^[A-Za-z0-9][A-Za-z0-9._-]*$`, 64)
|
||||
|
||||
func checkAgent(id string) error {
|
||||
name, distro, wsl := strings.Cut(id, "@wsl:")
|
||||
if !nameRe.MatchString(name) || wsl && !distroRe.MatchString(distro) {
|
||||
name, profile, prof := strings.Cut(name, "#")
|
||||
if !nameRe.MatchString(name) || prof && !distroRe.MatchString(profile) || wsl && !distroRe.MatchString(distro) {
|
||||
return fmt.Errorf("agent %q: not an agent's id", id)
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -241,3 +241,54 @@ func View0(t *testing.T) *View {
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// @AXmake110 on X: the Claude plugins page shows a chip for each Claude
|
||||
// Code config folder (claude#magpie-desktop), and turning the plugin off
|
||||
// for one answered `agent "claude#magpie-desktop": not an agent's id`.
|
||||
// Every route that takes an agent's id takes a profile's: the plugin's
|
||||
// agents, an agent's own instructions and how it is given skills.
|
||||
func TestLibraryTakesAProfilesAgentID(t *testing.T) {
|
||||
h := sandbox(t)
|
||||
pluginAgents(t, h)
|
||||
write(t, filepath.Join(h, ".claude-magpie-desktop/settings.json"), "{}\n")
|
||||
const prof = "claude#magpie-desktop"
|
||||
src := filepath.Join(t.TempDir(), "acme")
|
||||
writePlugin(t, src)
|
||||
ok(t)(InstallPlugins(src, nil, []string{"claude", prof}))
|
||||
skill := filepath.Join(h, ".claude-magpie-desktop/skills/tdd")
|
||||
if _, err := os.Lstat(skill); err != nil {
|
||||
t.Fatalf("the profile's skill: %v", err)
|
||||
}
|
||||
|
||||
// off for the profile alone
|
||||
ok(t)(PluginAgents("acme-kit", []string{"claude"}))
|
||||
if _, err := os.Lstat(skill); err == nil {
|
||||
t.Errorf("the skill stays in the profile it was turned off for")
|
||||
}
|
||||
if _, err := os.Lstat(filepath.Join(h, ".claude/skills/tdd")); err != nil {
|
||||
t.Errorf("claude's own skill went too: %v", err)
|
||||
}
|
||||
// and on again
|
||||
ok(t)(PluginAgents("acme-kit", []string{"claude", prof}))
|
||||
if _, err := os.Lstat(skill); err != nil {
|
||||
t.Errorf("on again: %v", err)
|
||||
}
|
||||
|
||||
ok(t)(SetSkillHow(prof, HowCopy))
|
||||
extra := "Answer in Chinese."
|
||||
ok(t)(SaveInstructions(InstructionsChange{Extra: map[string]*string{prof: &extra}}))
|
||||
if got := strings.TrimSpace(read(t, extraPath(prof))); got != extra {
|
||||
t.Errorf("the profile's own instructions: %q", got)
|
||||
}
|
||||
|
||||
for _, id := range []string{"claude", "codex@wsl:Ubuntu-24.04", prof, "hermes#work", "omp#work@wsl:Ubuntu"} {
|
||||
if err := checkAgent(id); err != nil {
|
||||
t.Errorf("%s refused: %v", id, err)
|
||||
}
|
||||
}
|
||||
for _, id := range []string{"claude#", "#work", "claude#../x", "claude#a/b", `claude#a\b`, "claude#a#b", "claude#.x"} {
|
||||
if checkAgent(id) == nil {
|
||||
t.Errorf("%q taken for an agent's id", id)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user