From 6f4e420b3a2572812c49b914ad6fad49d6045ab4 Mon Sep 17 00:00:00 2001 From: Sam Catlow Date: Tue, 15 Sep 2026 13:08:43 +1000 Subject: [PATCH] refactor(skill): delete dead Discover/DiscoverPlugins/Skill path DELETE: no document in docs/architecture/ or docs/prds/ specifies a consumer for skill.Discover, skill.DiscoverPlugins, or the skill.Skill type. Live per-skill loading is reimplemented inline in internal/domain/workflow/agent.go loadSkillBody via Catalog/SkillForWorkflow/Parse/LoadPlugins, and daemon startup and webui use Catalog/CatalogRoots. The parallel fully-tested path had no caller to keep it honest, so it is removed together with its now-dead tests. --- internal/skill/catalog_test.go | 98 -------------------- internal/skill/plugin.go | 8 -- internal/skill/plugin_test.go | 161 +-------------------------------- internal/skill/skill.go | 56 ------------ internal/skill/skill_test.go | 73 --------------- 5 files changed, 2 insertions(+), 394 deletions(-) diff --git a/internal/skill/catalog_test.go b/internal/skill/catalog_test.go index 4379db673..d00966a5a 100644 --- a/internal/skill/catalog_test.go +++ b/internal/skill/catalog_test.go @@ -12,7 +12,6 @@ import ( func TestCatalogReturnsNameAndDescriptionOnly(t *testing.T) { // Catalog tier (~100 tokens per skill): name + description loaded at // daemon startup. Full body is Tier 2, loaded on skill activation. - // Currently Discover() returns the full Skill (frontmatter + body). // Catalog() must return only the catalog entries without bodies. dir := t.TempDir() @@ -169,100 +168,3 @@ func TestCatalogEntryHasRequiredFields(t *testing.T) { t.Error("CatalogEntry must have non-empty Name and Description") } } - -// ── bundled plugin demo skill ──────────────────────────────────────── - -func TestBundledPluginSkillIsDiscoverableAndRunnable(t *testing.T) { - // A skill must be able to ship bundled Yaegi plugins in its plugins/ - // directory. When metadata.archie.plugins is present, only the listed - // plugins are loaded in declared order; unlisted *.go files are ignored. - - dir := t.TempDir() - skillsDir := filepath.Join(dir, ".agents", "skills", "archie-wf-tdd") - pluginsDir := filepath.Join(skillsDir, "plugins") - if err := os.MkdirAll(pluginsDir, 0o755); err != nil { - t.Fatal(err) - } - if err := os.WriteFile(filepath.Join(skillsDir, "SKILL.md"), []byte(`--- -name: archie-wf-tdd -description: TDD bugfix workflow with security checks -version: 1.0.0 -metadata: - archie: - tools: [go, golangci-lint] - engine: any - plugins: - - plugins/security-check.go - - plugins/lint-check.go ---- -Full body content. -`), 0o644); err != nil { - t.Fatal(err) - } - - // Write the listed plugins. - if err := os.WriteFile(filepath.Join(pluginsDir, "security-check.go"), []byte(`package main - -import "strings" - -func Run(input string) string { - if strings.Contains(input, "TODO") { - return "found TODO" - } - return "clean" -} -`), 0o644); err != nil { - t.Fatal(err) - } - if err := os.WriteFile(filepath.Join(pluginsDir, "lint-check.go"), []byte(`package main - -func Run(input string) string { - return "linted: " + input -} -`), 0o644); err != nil { - t.Fatal(err) - } - // Write an unlisted plugin -- it must NOT be loaded. - if err := os.WriteFile(filepath.Join(pluginsDir, "extra.go"), []byte(`package main - -func Run(input string) string { - return "extra" -} -`), 0o644); err != nil { - t.Fatal(err) - } - - // Discover the skill -- must include only the listed plugins in declared order. - skills, err := Discover(dir) - if err != nil { - t.Fatal(err) - } - if len(skills) != 1 { - t.Fatalf("got %d skills, want 1", len(skills)) - } - s := skills["archie-wf-tdd"] - if len(s.Plugins) != 2 { - t.Fatalf("skill has %d plugins, want 2 -- Discover() must honor metadata.archie.plugins", len(s.Plugins)) - } - if s.Plugins[0].Name != "security-check" { - t.Errorf("plugin[0].Name = %q, want security-check (declared order)", s.Plugins[0].Name) - } - if s.Plugins[1].Name != "lint-check" { - t.Errorf("plugin[1].Name = %q, want lint-check (declared order)", s.Plugins[1].Name) - } - - // The plugin must be runnable. - out, err := s.Plugins[0].Run("code with TODO") - if err != nil { - t.Fatal(err) - } - if out != "found TODO" { - t.Errorf("plugin output = %q, want 'found TODO'", out) - } - - // The frontmatter must declare the plugin. - if s.Frontmatter.Metadata.Archie == nil || len(s.Frontmatter.Metadata.Archie.Plugins) != 2 { - t.Error("Frontmatter.Metadata.Archie.Plugins is empty -- " + - "the SKILL.md must declare bundled plugins in the metadata.archie.plugins list") - } -} diff --git a/internal/skill/plugin.go b/internal/skill/plugin.go index b64ed5072..55e069164 100644 --- a/internal/skill/plugin.go +++ b/internal/skill/plugin.go @@ -37,14 +37,6 @@ func (p *Plugin) Run(input string) (string, error) { return fn(input), nil } -// DiscoverPlugins scans dir/.agents/skills//plugins/*.go and -// returns the discovered plugins sorted by filename. Returns nil if the -// skill directory does not exist. Returns an empty slice if the skill -// exists but has no plugins/ directory. -func DiscoverPlugins(dir, skillName string) ([]Plugin, error) { - return LoadPlugins(dir, skillName, nil) -} - // LoadPlugins loads plugins from dir/.agents/skills//plugins/. // // When allowed is non-empty, only the listed filenames are loaded in diff --git a/internal/skill/plugin_test.go b/internal/skill/plugin_test.go index d1f30a623..5c85a04b1 100644 --- a/internal/skill/plugin_test.go +++ b/internal/skill/plugin_test.go @@ -6,114 +6,6 @@ import ( "testing" ) -func TestDiscoverPlugins(t *testing.T) { - dir := t.TempDir() - skillsDir := filepath.Join(dir, ".agents", "skills", "my-skill") - pluginsDir := filepath.Join(skillsDir, "plugins") - if err := os.MkdirAll(pluginsDir, 0o755); err != nil { - t.Fatal(err) - } - - // Write a SKILL.md so the skill directory is valid. - if err := os.WriteFile(filepath.Join(skillsDir, "SKILL.md"), []byte(`--- -name: my-skill -description: A test skill -version: 1.0.0 ---- -Body. -`), 0o644); err != nil { - t.Fatal(err) - } - - // Write two plugin files. - checkGo := `package main - -import "fmt" - -func Run(input string) string { - return "checked: " + input -} -` - if err := os.WriteFile(filepath.Join(pluginsDir, "check.go"), []byte(checkGo), 0o644); err != nil { - t.Fatal(err) - } - - lintGo := `package main - -import "strings" - -func Run(input string) string { - if strings.Contains(input, "TODO") { - return "found TODO" - } - return "clean" -} -` - if err := os.WriteFile(filepath.Join(pluginsDir, "lint.go"), []byte(lintGo), 0o644); err != nil { - t.Fatal(err) - } - - plugins, err := DiscoverPlugins(dir, "my-skill") - if err != nil { - t.Fatal(err) - } - if len(plugins) != 2 { - t.Fatalf("got %d plugins, want 2", len(plugins)) - } - - // Plugins are returned sorted by name. - if plugins[0].Name != "check" { - t.Errorf("plugin[0].Name = %q, want check", plugins[0].Name) - } - if plugins[1].Name != "lint" { - t.Errorf("plugin[1].Name = %q, want lint", plugins[1].Name) - } - - // Verify source content is loaded. - if plugins[0].Src != checkGo { - t.Errorf("check plugin source mismatch") - } - if plugins[1].Src != lintGo { - t.Errorf("lint plugin source mismatch") - } -} - -func TestDiscoverPluginsNone(t *testing.T) { - dir := t.TempDir() - skillsDir := filepath.Join(dir, ".agents", "skills", "no-plugins") - if err := os.MkdirAll(skillsDir, 0o755); err != nil { - t.Fatal(err) - } - if err := os.WriteFile(filepath.Join(skillsDir, "SKILL.md"), []byte(`--- -name: no-plugins -description: desc -version: 1.0.0 ---- -Body. -`), 0o644); err != nil { - t.Fatal(err) - } - - plugins, err := DiscoverPlugins(dir, "no-plugins") - if err != nil { - t.Fatal(err) - } - if len(plugins) != 0 { - t.Fatalf("got %d plugins, want 0", len(plugins)) - } -} - -func TestDiscoverPluginsMissingSkill(t *testing.T) { - dir := t.TempDir() - plugins, err := DiscoverPlugins(dir, "nonexistent") - if err != nil { - t.Fatal(err) - } - if plugins != nil { - t.Fatalf("got %v, want nil for missing skill", plugins) - } -} - func TestPluginRun(t *testing.T) { dir := t.TempDir() skillsDir := filepath.Join(dir, ".agents", "skills", "runner") @@ -141,7 +33,7 @@ func Run(input string) string { t.Fatal(err) } - plugins, err := DiscoverPlugins(dir, "runner") + plugins, err := LoadPlugins(dir, "runner", nil) if err != nil { t.Fatal(err) } @@ -159,55 +51,6 @@ func Run(input string) string { } } -func TestDiscoverIncludesPlugins(t *testing.T) { - // Verify that Discover() populates the Plugins field on Skill. - dir := t.TempDir() - skillsDir := filepath.Join(dir, ".agents", "skills", "full-skill") - pluginsDir := filepath.Join(skillsDir, "plugins") - if err := os.MkdirAll(pluginsDir, 0o755); err != nil { - t.Fatal(err) - } - if err := os.WriteFile(filepath.Join(skillsDir, "SKILL.md"), []byte(`--- -name: full-skill -description: Has plugins -version: 1.0.0 -metadata: - archie: - tools: [go] - engine: any ---- -Skill body here. -`), 0o644); err != nil { - t.Fatal(err) - } - if err := os.WriteFile(filepath.Join(pluginsDir, "gate.go"), []byte(`package main - -func Run(input string) string { - return "gated" -} -`), 0o644); err != nil { - t.Fatal(err) - } - - skills, err := Discover(dir) - if err != nil { - t.Fatal(err) - } - if len(skills) != 1 { - t.Fatalf("got %d skills, want 1", len(skills)) - } - s := skills["full-skill"] - if s.Body != "Skill body here." { - t.Errorf("Body = %q", s.Body) - } - if len(s.Plugins) != 1 { - t.Fatalf("got %d plugins, want 1", len(s.Plugins)) - } - if s.Plugins[0].Name != "gate" { - t.Errorf("plugin name = %q, want gate", s.Plugins[0].Name) - } -} - func TestLoadPluginsWithAllowlist(t *testing.T) { // When allowed is non-empty, only those plugins are loaded in declared order. dir := t.TempDir() @@ -268,7 +111,7 @@ func Run(input string) string { return "ok" } } func TestLoadPluginsEmptyAllowlist(t *testing.T) { - // Nil or empty allowlist falls back to glob-all (same as DiscoverPlugins). + // Nil or empty allowlist falls back to glob-all. dir := t.TempDir() skillsDir := filepath.Join(dir, ".agents", "skills", "glob") pluginsDir := filepath.Join(skillsDir, "plugins") diff --git a/internal/skill/skill.go b/internal/skill/skill.go index bec0a60e7..e61bc38f5 100644 --- a/internal/skill/skill.go +++ b/internal/skill/skill.go @@ -160,15 +160,6 @@ func SkillForWorkflow(catalog []CatalogEntry, workflow string) *CatalogEntry { return nil } -// Skill is a parsed SKILL.md file with its frontmatter, body, and any -// bundled Yaegi plugins found in the skill's plugins/ directory. -type Skill struct { - Frontmatter Frontmatter - Body string - Dir string // skill directory name (e.g. "tdd-bugfix") - Plugins []Plugin // bundled Yaegi plugins from plugins/*.go -} - const skillsDir = ".agents/skills" // Parse extracts YAML frontmatter and body from SKILL.md content. @@ -197,53 +188,6 @@ func Parse(src []byte) (*Frontmatter, string, error) { return &fm, body, nil } -// Discover scans dir/.agents/skills/*/SKILL.md and returns a map of skill -// directory name to parsed Skill. Missing directory returns an empty map. -func Discover(dir string) (map[string]Skill, error) { - skillsPath := filepath.Join(dir, skillsDir) - entries, err := os.ReadDir(skillsPath) - if os.IsNotExist(err) { - return nil, nil - } - if err != nil { - return nil, fmt.Errorf("read skills dir %s: %w", skillsPath, err) - } - - names := make([]string, 0, len(entries)) - for _, e := range entries { - if e.IsDir() { - names = append(names, e.Name()) - } - } - sort.Strings(names) - - out := make(map[string]Skill, len(names)) - for _, name := range names { - skillPath := filepath.Join(skillsPath, name, "SKILL.md") - data, err := os.ReadFile(skillPath) - if err != nil { - if os.IsNotExist(err) { - continue // directory exists but no SKILL.md - } - return nil, fmt.Errorf("read %s: %w", skillPath, err) - } - fm, body, err := Parse(data) - if err != nil { - return nil, fmt.Errorf("parse %s: %w", skillPath, err) - } - var pluginNames []string - if fm.Metadata.Archie != nil { - pluginNames = fm.Metadata.Archie.Plugins - } - plugins, err := LoadPlugins(dir, name, pluginNames) - if err != nil { - return nil, fmt.Errorf("plugins %s: %w", name, err) - } - out[name] = Skill{Frontmatter: *fm, Body: body, Dir: name, Plugins: plugins} - } - return out, nil -} - // LoadBody loads the raw SKILL.md body for a specific skill directory name. // Returns "" if the skill directory or SKILL.md does not exist. func LoadBody(dir, skillDirName string) string { diff --git a/internal/skill/skill_test.go b/internal/skill/skill_test.go index b0efdbf1f..b56f0a935 100644 --- a/internal/skill/skill_test.go +++ b/internal/skill/skill_test.go @@ -62,79 +62,6 @@ No YAML frontmatter here. } } -func TestDiscover(t *testing.T) { - dir := t.TempDir() - skillsDir := filepath.Join(dir, ".agents", "skills") - - // Create tdd-bugfix skill. - tddDir := filepath.Join(skillsDir, "tdd-bugfix") - if err := os.MkdirAll(tddDir, 0o755); err != nil { - t.Fatal(err) - } - if err := os.WriteFile(filepath.Join(tddDir, "SKILL.md"), []byte(`--- -name: tdd-bugfix -description: TDD bugfix workflow -version: 1.0.0 -metadata: - archie: - tools: [go] - engine: any ---- - -Body content here. -`), 0o644); err != nil { - t.Fatal(err) - } - - // Create ecosystem-node skill. - nodeDir := filepath.Join(skillsDir, "ecosystem-node") - if err := os.MkdirAll(nodeDir, 0o755); err != nil { - t.Fatal(err) - } - if err := os.WriteFile(filepath.Join(nodeDir, "SKILL.md"), []byte(`--- -name: ecosystem-node -description: Node conventions -version: 1.0.0 -metadata: - archie: - tools: [node, npm] - engine: any ---- - -Node stuff. -`), 0o644); err != nil { - t.Fatal(err) - } - - skills, err := Discover(dir) - if err != nil { - t.Fatal(err) - } - if len(skills) != 2 { - t.Fatalf("got %d skills, want 2", len(skills)) - } - if _, ok := skills["tdd-bugfix"]; !ok { - t.Error("missing tdd-bugfix") - } - if _, ok := skills["ecosystem-node"]; !ok { - t.Error("missing ecosystem-node") - } - if skills["tdd-bugfix"].Body != "Body content here." { - t.Errorf("tdd body: got %q", skills["tdd-bugfix"].Body) - } -} - -func TestDiscoverMissing(t *testing.T) { - dir := t.TempDir() - skills, err := Discover(dir) - if err != nil { - t.Fatal(err) - } - if skills != nil { - t.Errorf("expected nil map for missing dir, got %v", skills) - } -} - func TestLoadBody(t *testing.T) { dir := t.TempDir() skillsDir := filepath.Join(dir, ".agents", "skills", "tdd-bugfix")