Files
magpie/internal/library/agent_skills_test.go
T
yetone c9d9652380 library: an agent whose folder is a file isn't written, and skills reach 13 more agents with one link in ~/.agents/skills for those that share it (neiko on Discord: with DeepSeek Harness not installed the Library kept failing on "open ~/.dsh/AGENTS.md: not a directory" and ~/.dsh/config.yaml; inaction: the skills list is short of the Agents page, Kimi Code has none). An agent counted as there when its folder path existed or its command was on PATH, never asking whether the path was a folder — a file at ~/.dsh, or another dsh, made DeepSeek Harness look installed. Now an agent whose folder is a file (or under one) isn't detected (agent.Taken; Goose's, Cindy's and Claude Desktop's own checks want a folder too), a Library target leaves out each place a file stands in the way of, one with none left isn't listed, and an agent given no MCP server with none of magpie's isn't read. Skills: Kimi Code, Goose and Cindy get ~/.agents/skills (Kimi's ~/.config/agents/skills when there, as Kimi reads it first; never ~/.kimi/skills, which would hide Claude Code's from it); Command Code, Devin, Hermes, Droid, Cline, Qoder, Qoder CN, Grok, WorkBuddy, Hanako and fx their own skills folder; Kimi, Goose and Grok a project's .agents/skills. The shared folder is filled first, and an agent that reads ~/.agents/skills besides its own (Codex, Gemini CLI, OpenCode, Crush, DeepSeek Harness and those above) gets no second link to a skill already there. Tested with new taken_test.go (neiko's two errors without the change) and agent_skills_test.go (skills folders, written once, a shared skill imported for Kimi), in sandbox HOMEs; library-items and shared-skills 24/24 in Chromium and WebKit; go vet, go build (-tags nogui, GOOS=linux, GOOS=windows), go test -tags nogui ./... pass. Not tried with real Kimi Code, Goose or Cindy.
2026-09-30 14:40:41 +08:00

124 lines
4.3 KiB
Go

package library
import (
"os"
"path/filepath"
"slices"
"testing"
)
// Every agent on the Agents page that reads skills has a place for them in
// the library (Kimi Code had none, so a skill never reached it): each its
// own folder, but Kimi Code, whose own would hide Claude Code's from it,
// the shared ~/.agents/skills.
func TestAgentsSkillsFolders(t *testing.T) {
h := sandbox(t)
for _, f := range []string{".kimi/config.toml", ".commandcode/settings.json", ".factory/settings.json", ".cline/data/globalState.json",
".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), "")
}
want := map[string]string{
"kimi": ".agents/skills",
"goose": ".agents/skills",
"commandcode": ".commandcode/skills",
"droid": ".factory/skills",
"cline": ".cline/skills",
"hermes": ".hermes/skills",
"grok": ".grok/skills",
"qoder": ".qoder/skills",
"workbuddy": ".workbuddy/skills",
"fx": ".fx/skills",
"devin": ".config/devin/skills",
}
for id, d := range want {
tg := targetByID(id)
if tg == nil || tg.Skills != filepath.Join(h, d) {
t.Errorf("%s: %+v", id, tg)
}
}
// what Kimi Code reads first of the shared ones, when it's there
os.MkdirAll(filepath.Join(h, ".config/agents/skills"), 0o755)
if tg := targetByID("kimi"); tg == nil || tg.Skills != filepath.Join(h, ".config/agents/skills") {
t.Errorf("kimi with ~/.config/agents/skills: %+v", tg)
}
if ProjectSkillsDir("kimi") != ".agents/skills" {
t.Error("kimi reads a project's .agents/skills")
}
}
// A skill given to Kimi Code is one link in ~/.agents/skills, which Goose
// shares; Codex and Gemini CLI, which read that folder as well, get no
// second link in their own, and get one again once it's not there.
func TestSharedSkillsWrittenOnce(t *testing.T) {
h := sandbox(t)
write(t, filepath.Join(h, ".kimi/config.toml"), "")
src := filepath.Join(h, "src/skills")
skill(t, filepath.Join(src, "pdf"), "pdf", "Read PDFs")
shared := filepath.Join(h, ".agents/skills/pdf")
cx, cl := filepath.Join(h, ".codex/skills/pdf"), filepath.Join(h, ".claude/skills/pdf")
ok(t)(InstallSkills(src, []string{"pdf"}, []string{"claude", "codex", "kimi"}))
if !ours(shared, "pdf") {
t.Error("~/.agents/skills/pdf isn't the library's")
}
if !ours(cl, "pdf") {
t.Error("claude hasn't it")
}
if _, err := os.Lstat(cx); !os.IsNotExist(err) {
t.Error("codex has a second link to it")
}
v, err := Read(nil)
if err != nil {
t.Fatal(err)
}
also := map[string][]string{}
for _, a := range v.Agents {
also[a.ID] = a.SkillsAlso
}
for id, w := range map[string]string{"codex": "kimi", "gemini": "goose", "kimi": "goose", "goose": "kimi"} {
if !slices.Contains(also[id], w) {
t.Errorf("%s reads %s's skills too: %v", id, w, also[id])
}
}
if slices.Contains(also["claude"], "kimi") {
t.Errorf("claude reads no ~/.agents/skills: %v", also["claude"])
}
// Kimi Code (and Goose) off: Codex gets its own again, the shared goes
ok(t)(SkillAgents("pdf", []string{"claude", "codex"}))
if !ours(cx, "pdf") {
t.Error("codex hasn't it")
}
if _, err := os.Lstat(shared); !os.IsNotExist(err) {
t.Error("~/.agents/skills still has it")
}
// on again: codex's own goes, not the skill
ok(t)(SkillAgents("pdf", []string{"claude", "codex", "goose"}))
if _, err := os.Lstat(cx); !os.IsNotExist(err) || !ours(shared, "pdf") {
t.Error("not once in ~/.agents/skills")
}
if _, err := os.Stat(filepath.Join(src, "pdf/SKILL.md")); err != nil {
t.Error("the user's folder went")
}
}
// A skill of the user's own in ~/.agents/skills brought into the library
// stays there as it is, and Kimi Code, whose folder it is, has it without
// a word of its "own skill by that name".
func TestImportSharedSkillForKimi(t *testing.T) {
h := sandbox(t)
os.RemoveAll(filepath.Join(h, ".config/goose"))
write(t, filepath.Join(h, ".kimi/config.toml"), "")
shared := filepath.Join(h, ".agents/skills/orca")
skill(t, shared, "orca", "Orca")
ok(t)(ImportSkill("orca"))
if fi, err := os.Lstat(shared); err != nil || !fi.IsDir() {
t.Errorf("the shared folder's skill: %v", err)
}
v, _ := Read(nil)
if len(v.Skills) != 1 || !slices.Equal(v.Skills[0].Agents, []string{"kimi"}) || len(v.Skills[0].Problems) != 0 {
t.Errorf("skills: %+v", v.Skills)
}
ok(t)(Sync())
}