library: a repository that keeps its skills again under a plugin's folder lists each once (碳碳双键 on Discord)

tw93/waza keeps its eight skills in skills/ and again in
plugins/waza/skills/. Some of the plugin copies lag the top ones.
Typing "tw93/waza" in Library → Skills listed "16 skills", each one
twice. unhiddenFirst only folded a copy in a hidden folder (.claude/
skills, #1964) into the unhidden one; two unhidden copies both stayed.

It now keeps one copy of each skill. It prefers the copy outside hidden
folders, then the one fewest folders deep, then the first. That covers
both candidates (the probe and install) and skillDirsIn (the new-skill
check).

Run:
- TestRepoWithAPluginCopyListsEachSkillOnce uses waza's real paths.
  Against the old skills.go it is red (9 lines: 16 candidates, the
  plugin's descriptions, 16 tree dirs); with the fix it is green.
  TestMarketInstallsASkillKeptInClaudesFolder (#1964) is green too.
- Real use: ProbeSkills("tw93/waza") against GitHub in a sandbox HOME
  lists skills/check … skills/write, 8 in all, each once.
- gofmt -l clean; go vet -tags nogui ./... clean for darwin, linux and
  windows.
- Full suite: go test -timeout 45m ./... at load average ~115 (other
  sessions' suites). 63 packages ok. internal/agent and internal/gateway
  timed out at 45m with no test hung (TestOpenCodeAndCrushKeep… and
  TestStrictAffinity… had each run 0s), and go list -deps shows that
  neither imports internal/library. internal/gui's
  TestPanelJoinsFullScreenSpaces is #2450, red on main already.
This commit is contained in:
yetone
2026-10-16 15:35:20 +08:00
parent e72b6a3327
commit 6b3ee5a03b
3 changed files with 73 additions and 11 deletions
+2 -2
View File
@@ -115,8 +115,8 @@ type gitEntry struct {
// skillDirsIn are the folders with a SKILL.md under base in a repository's
// tree, as candidates would find them: a few folders deep, none in
// node_modules, a hidden folder only through its skills folder, and none
// inside another skill or a copy of one outside hidden folders.
// node_modules, a hidden folder only through its skills folder, none
// inside another skill, and each skill once (unhiddenFirst).
func skillDirsIn(t *gitTree, base string) []string {
var dirs []string
for _, e := range t.Tree {
+43
View File
@@ -322,3 +322,46 @@ func TestMarketInstallsASkillKeptInClaudesFolder(t *testing.T) {
t.Errorf("skills in the tree %v, want %v", got, want)
}
}
// 碳碳双键's report on Discord: tw93/waza keeps its eight skills in skills/
// and again in plugins/waza/skills/ (some copies behind the top ones), and
// typing "tw93/waza" listed 16 skills, each twice. The paths are the
// repository's own.
func TestRepoWithAPluginCopyListsEachSkillOnce(t *testing.T) {
sandbox(t)
names := []string{"check", "health", "hunt", "learn", "read", "think", "ui", "write"}
files := map[string]string{}
for _, n := range names {
files["skills/"+n+"/SKILL.md"] = "---\nname: " + n + "\ndescription: the top one\n---\n"
files["plugins/waza/skills/"+n+"/SKILL.md"] = "---\nname: " + n + "\ndescription: the plugin's copy\n---\n"
}
fakeSkillRepo(t, files)
p, err := ProbeSkills("tw93/waza")
if err != nil {
t.Fatal(err)
}
var paths []string
for _, c := range p.Candidates {
paths = append(paths, c.Path)
if c.Description != "the top one" {
t.Errorf("%s: %q, want the top one", c.Path, c.Description)
}
}
var want []string
for _, n := range names {
want = append(want, "skills/"+n)
}
if !slices.Equal(paths, want) {
t.Errorf("candidates %v, want %v", paths, want)
}
tree := &gitTree{}
for p := range files {
tree.Tree = append(tree.Tree, gitEntry{Path: p, Type: "blob"})
}
sort.Slice(tree.Tree, func(i, j int) bool { return tree.Tree[i].Path < tree.Tree[j].Path })
if got := skillDirsIn(tree, ""); !slices.Equal(got, want) {
t.Errorf("skills in the tree %v, want %v", got, want)
}
}
+28 -9
View File
@@ -877,8 +877,8 @@ func untar(r io.Reader, dst string) error {
// looked for a few folders deep, and not inside another skill. A hidden
// folder is an agent's own (.claude, .agents) and is looked in only for its
// skills folder: some repositories keep their skill only in
// .claude/skills (#1964, UFO404). A skill found there that the repository
// also has outside a hidden folder is that one, listed once.
// .claude/skills (#1964, UFO404). A skill the repository holds twice, in a
// hidden folder or a plugin's, is listed once (unhiddenFirst).
func candidates(root, sub string) []Candidate {
base := filepath.Join(root, filepath.FromSlash(sub))
var out []Candidate
@@ -926,17 +926,36 @@ func inHidden(path string) bool {
return slices.ContainsFunc(strings.Split(path, "/"), func(p string) bool { return strings.HasPrefix(p, ".") })
}
// unhiddenFirst drops a skill in a hidden folder that is the same skill as
// one outside every hidden folder, or as a hidden one listed before it: an
// agent's folder often holds a copy of the repository's own skills.
// unhiddenFirst lists each skill once: of copies of the same skill it keeps
// the one outside every hidden folder, then the one fewest folders deep,
// then the first. An agent's folder often holds a copy of the repository's
// own skills, and a repository that is also a plugin often holds another
// under its plugin's folder: tw93/waza has skills/check and
// plugins/waza/skills/check, and every skill was listed twice (碳碳双键 on
// Discord).
func unhiddenFirst[T any](list []T, path func(T) string, same func(a, b T) bool) []T {
depth := func(c T) int { return strings.Count(path(c), "/") }
before := func(o T, j int, c T, i int) bool {
if ho, hc := inHidden(path(o)), inHidden(path(c)); ho != hc {
return !ho
}
if do, dc := depth(o), depth(c); do != dc {
return do < dc
}
return j < i
}
out := make([]T, 0, len(list))
for i, c := range list {
if inHidden(path(c)) && (slices.ContainsFunc(list, func(o T) bool { return !inHidden(path(o)) && same(o, c) }) ||
slices.ContainsFunc(list[:i], func(o T) bool { return inHidden(path(o)) && same(o, c) })) {
continue
dup := false
for j, o := range list {
if j != i && same(o, c) && before(o, j, c, i) {
dup = true
break
}
}
if !dup {
out = append(out, c)
}
out = append(out, c)
}
return out
}