diff --git a/internal/skillserve/catalog.go b/internal/skillserve/catalog.go index c1db7e524..e34cc6699 100644 --- a/internal/skillserve/catalog.go +++ b/internal/skillserve/catalog.go @@ -104,6 +104,14 @@ func (b *Builder) Build() (*Catalog, error) { if j := slices.IndexFunc(unserved, func(o string) bool { return strings.HasPrefix(o, s.RelPath+"/") }); reason == "" && j >= 0 { reason = fmt.Sprintf("contains %s, which is not served", unserved[j]) } + // A parent lists its nested skills' files under the same URIs. If one changed + // between the two reads, the entries disagree; serve the parent next refresh + // rather than overwrite what the nested skill advertises. + for uri, f := range files { + if old, ok := c.byFile[uri]; reason == "" && ok && old.digest != f.digest { + reason = "a nested skill changed while it was read; it is served after the next refresh" + } + } if reason != "" { c.Skipped = append(c.Skipped, Skip{Path: s.RelPath, Reason: reason}) unserved = append(unserved, s.RelPath) diff --git a/internal/skillserve/catalog_test.go b/internal/skillserve/catalog_test.go index 0fea8e969..6daa12cb2 100644 --- a/internal/skillserve/catalog_test.go +++ b/internal/skillserve/catalog_test.go @@ -122,6 +122,22 @@ func TestBuild_SkipsParentOfExcludedNestedSkill(t *testing.T) { } } +// A parent and its nested skill list the same files under the same URIs; an +// unchanged tree serves both. +func TestBuild_ServesParentAndNestedSkillTogether(t *testing.T) { + src := t.TempDir() + writeFile(t, filepath.Join(src, "suite/SKILL.md"), skillMD("suite")) + writeFile(t, filepath.Join(src, "suite/child/SKILL.md"), skillMD("child")) + + c, err := (&Builder{Source: src}).Build() + if err != nil { + t.Fatal(err) + } + if len(c.Skills) != 2 { + t.Errorf("skills=%v warnings=%v, want suite and suite/child served", c.Skills, c.Skipped) + } +} + func TestBuild_SkipsParentOfInvalidNestedSkill(t *testing.T) { src := t.TempDir() writeFile(t, filepath.Join(src, "suite/SKILL.md"), skillMD("suite"))