From 6f4e420b3a2572812c49b914ad6fad49d6045ab4 Mon Sep 17 00:00:00 2001 From: Sam Catlow Date: Tue, 15 Sep 2026 13:08:43 +1000 Subject: [PATCH 1/4] 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") From 27f7053351108b937dd0186fdb0450c7bcb6a3d6 Mon Sep 17 00:00:00 2001 From: Sam Catlow Date: Tue, 15 Sep 2026 13:10:51 +1000 Subject: [PATCH 2/4] refactor(skillbuild): delete dead AugmentRegistry path DELETE: no document in docs/architecture/ or docs/prds/ names AugmentRegistry as a consumer. The live per-task registry construction is skillbuild.BuildRegistry(workDir) at internal/app/agentworker/ task_execution.go; AugmentRegistry was an unwired alternate merge-over- base path (with collision/override and nil-base semantics) that only tests exercised. mergeSkillWorkflows remains reachable through BuildCatalog/BuildRegistry. --- .../domain/workflow/skillbuild/skillbuild.go | 21 - .../workflow/skillbuild/skillbuild_test.go | 476 ------------------ 2 files changed, 497 deletions(-) diff --git a/internal/domain/workflow/skillbuild/skillbuild.go b/internal/domain/workflow/skillbuild/skillbuild.go index 15c133c5d..c8e34d0b5 100644 --- a/internal/domain/workflow/skillbuild/skillbuild.go +++ b/internal/domain/workflow/skillbuild/skillbuild.go @@ -6,7 +6,6 @@ import ( "context" "fmt" "log/slog" - "maps" "os" "path/filepath" "sort" @@ -76,26 +75,6 @@ type SkillWorkflow struct { Dir string // skill directory name } -// AugmentRegistry scans a worktree directory for skills that declare -// workflows, builds each from its stage plugins, and returns a new -// registry with worktree workflows merged over the base. The base -// registry is not mutated. -// -// This is the per-task complement to BuildRegistry: BuildRegistry -// runs once at startup against a shared skills directory (or the -// workdir root); AugmentRegistry runs at process time against a -// specific cloned worktree so that per-repo skills are discovered -// without restarting the daemon. -func AugmentRegistry(worktree string, base workflow.Registry) (workflow.Registry, error) { - // Copy base -- never mutate the caller's registry. - reg := make(workflow.Registry, len(base)) - maps.Copy(reg, base) - if err := mergeSkillWorkflows(worktree, reg, nil); err != nil { - return nil, err - } - return reg, nil -} - // mergeSkillWorkflows scans worktree for skill catalog entries that // declare a workflow, builds each from its stage plugins, and merges the // result into reg in place. A skill whose workflow has no stages yet diff --git a/internal/domain/workflow/skillbuild/skillbuild_test.go b/internal/domain/workflow/skillbuild/skillbuild_test.go index 8af7ec93e..b697ddd01 100644 --- a/internal/domain/workflow/skillbuild/skillbuild_test.go +++ b/internal/domain/workflow/skillbuild/skillbuild_test.go @@ -358,372 +358,6 @@ func TestBuildRegistryEmptySkillsDirReturnsBuiltins(t *testing.T) { } } -// ── per-worktree registry augmentation ─────────────────────────────── - -func TestAugmentRegistryAddsWorktreeWorkflows(t *testing.T) { - // When a worktree contains .agents/skills/ with workflow-declaring - // skills, AugmentRegistry must add those workflows to the base - // registry. Workflows already in the base are not duplicated. - - worktree := t.TempDir() - skillDir := filepath.Join(worktree, ".agents", "skills", "archie-wf-custom") - pluginsDir := filepath.Join(skillDir, "plugins") - if err := os.MkdirAll(pluginsDir, 0o755); err != nil { - t.Fatal(err) - } - if err := os.WriteFile(filepath.Join(skillDir, "SKILL.md"), []byte(`--- -name: archie-wf-custom -description: Custom workflow from worktree -version: 1.0.0 -metadata: - archie: - workflow: custom ---- -Custom worktree workflow. -`), 0o644); err != nil { - t.Fatal(err) - } - if err := os.WriteFile(filepath.Join(pluginsDir, "01-do.go"), []byte(`package main - -import ( - "context" - "github.com/samcharles93/archie-core/internal/domain/workflow" -) - -func Stage() (string, func(context.Context, *workflow.TaskContext) error) { - return "do", func(ctx context.Context, tc *workflow.TaskContext) error { - tc.BuildSummary = "worktree-custom-ran" - return nil - } -} -`), 0o644); err != nil { - t.Fatal(err) - } - - base := workflow.Registry{"default": {Name: "default", Stages: nil}} - aug, err := AugmentRegistry(worktree, base) - if err != nil { - t.Fatal(err) - } - - // Base entries preserved. - if _, ok := aug["default"]; !ok { - t.Error("'default' missing from augmented registry") - } - - // Worktree workflow added. - wf, ok := aug["custom"] - if !ok { - t.Fatal("'custom' workflow not found in augmented registry -- worktree skill was not discovered") - } - if wf.Name != "custom" { - t.Errorf("Workflow.Name = %q, want custom", wf.Name) - } - if len(wf.Stages) != 1 { - t.Fatalf("got %d stages, want 1", len(wf.Stages)) - } - if wf.Stages[0].Name != "do" { - t.Errorf("stage[0].Name = %q, want do", wf.Stages[0].Name) - } - - // Run the worktree workflow. - tc := &workflow.TaskContext{BuildSummary: ""} - if err := wf.Stages[0].Run(context.Background(), tc); err != nil { - t.Fatal(err) - } - if tc.BuildSummary != "worktree-custom-ran" { - t.Errorf("BuildSummary = %q, want 'worktree-custom-ran'", tc.BuildSummary) - } -} - -func TestAugmentRegistryWorktreeOverridesBase(t *testing.T) { - // A worktree skill declaring the same workflow name as a base entry - // must take precedence. Worktree skills ARE the repo's workflow - // definition. - - worktree := t.TempDir() - skillDir := filepath.Join(worktree, ".agents", "skills", "archie-wf-implement") - pluginsDir := filepath.Join(skillDir, "plugins") - if err := os.MkdirAll(pluginsDir, 0o755); err != nil { - t.Fatal(err) - } - if err := os.WriteFile(filepath.Join(skillDir, "SKILL.md"), []byte(`--- -name: archie-wf-implement -description: Repo-specific implement workflow -version: 1.0.0 -metadata: - archie: - workflow: implement ---- -Repo-custom implement. -`), 0o644); err != nil { - t.Fatal(err) - } - if err := os.WriteFile(filepath.Join(pluginsDir, "01-repo-plan.go"), []byte(`package main - -import ( - "context" - "github.com/samcharles93/archie-core/internal/domain/workflow" -) - -func Stage() (string, func(context.Context, *workflow.TaskContext) error) { - return "repo-plan", func(ctx context.Context, tc *workflow.TaskContext) error { - tc.BuildSummary = "repo-implement-override" - return nil - } -} -`), 0o644); err != nil { - t.Fatal(err) - } - - // Base has "implement" as a built-in. - base := workflow.Registry{"implement": {Name: "implement", Stages: []workflow.Stage{ - {Name: "builtin-plan", Run: func(ctx context.Context, tc *workflow.TaskContext) error { - tc.BuildSummary = "builtin-implement" - return nil - }}, - }}} - aug, err := AugmentRegistry(worktree, base) - if err != nil { - t.Fatal(err) - } - - wf, ok := aug["implement"] - if !ok { - t.Fatal("'implement' missing from augmented registry") - } - if len(wf.Stages) != 1 { - t.Fatalf("got %d stages, want 1 from worktree override", len(wf.Stages)) - } - if wf.Stages[0].Name != "repo-plan" { - t.Errorf("stage[0].Name = %q, want 'repo-plan' from worktree override", wf.Stages[0].Name) - } - - // Run it -- must use worktree version. - tc := &workflow.TaskContext{BuildSummary: ""} - if err := wf.Stages[0].Run(context.Background(), tc); err != nil { - t.Fatal(err) - } - if tc.BuildSummary != "repo-implement-override" { - t.Errorf("BuildSummary = %q, want 'repo-implement-override' (worktree override)", tc.BuildSummary) - } -} - -func TestAugmentRegistryDoesNotModifyBase(t *testing.T) { - // AugmentRegistry returns a NEW registry -- the caller's base must - // not be mutated. - base := workflow.Registry{"keep": {Name: "keep"}} - worktree := t.TempDir() - - aug, err := AugmentRegistry(worktree, base) - if err != nil { - t.Fatal(err) - } - - // Augmented has the entry. - if _, ok := aug["keep"]; !ok { - t.Fatal("'keep' missing from augmented registry") - } - - // Mutating augmented must not affect base. - aug["keep"] = workflow.Workflow{Name: "modified"} - if base["keep"].Name != "keep" { - t.Error("AugmentRegistry mutated the base registry -- must return a copy") - } -} - -func TestAugmentRegistryNonexistentWorktreeReturnsBase(t *testing.T) { - base := workflow.Registry{"default": {Name: "default"}} - aug, err := AugmentRegistry("/nonexistent/worktree/path", base) - if err != nil { - t.Fatal(err) - } - if len(aug) != len(base) { - t.Errorf("got %d entries, want %d (nonexistent worktree adds nothing)", len(aug), len(base)) - } -} - -func TestAugmentRegistryWorktreeWithNoSkillsReturnsBase(t *testing.T) { - // A worktree without .agents/skills/ must not error -- returns - // a copy of the base unchanged. - worktree := t.TempDir() - base := workflow.Registry{"default": {Name: "default"}} - aug, err := AugmentRegistry(worktree, base) - if err != nil { - t.Fatal(err) - } - if len(aug) != len(base) { - t.Errorf("got %d entries, want %d (no skills in worktree)", len(aug), len(base)) - } -} - -func TestAugmentRegistryWorktreeSkillWithNoStagesDoesNotOverride(t *testing.T) { - // A skill that declares a workflow but has no plugins must not - // override the base entry -- it would produce an empty workflow. - worktree := t.TempDir() - skillDir := filepath.Join(worktree, ".agents", "skills", "archie-wf-empty") - if err := os.MkdirAll(skillDir, 0o755); err != nil { - t.Fatal(err) - } - if err := os.WriteFile(filepath.Join(skillDir, "SKILL.md"), []byte(`--- -name: archie-wf-empty -description: Workflow with no stages -version: 1.0.0 -metadata: - archie: - workflow: implement ---- -No plugins here. -`), 0o644); err != nil { - t.Fatal(err) - } - - base := workflow.Registry{"implement": {Name: "implement", Stages: []workflow.Stage{ - {Name: "builtin", Run: func(ctx context.Context, tc *workflow.TaskContext) error { return nil }}, - }}} - aug, err := AugmentRegistry(worktree, base) - if err != nil { - t.Fatal(err) - } - - wf := aug["implement"] - if len(wf.Stages) == 0 { - t.Error("worktree skill with no stages overrode base -- must keep base when skill is empty") - } - if wf.Stages[0].Name != "builtin" { - t.Error("base stage was replaced by empty worktree skill") - } -} - -// ── AugmentRegistry adversarial tests ──────────────────────────────── - -func TestAugmentRegistryConcurrentAccess(t *testing.T) { - // AugmentRegistry must be safe to call concurrently from different - // goroutines (e.g. multiple tasks processed in parallel). - worktree := t.TempDir() - skillDir := filepath.Join(worktree, ".agents", "skills", "archie-wf-concurrent") - pluginsDir := filepath.Join(skillDir, "plugins") - if err := os.MkdirAll(pluginsDir, 0o755); err != nil { - t.Fatal(err) - } - if err := os.WriteFile(filepath.Join(skillDir, "SKILL.md"), []byte(`--- -name: archie-wf-concurrent -description: Concurrent test -version: 1.0.0 -metadata: - archie: - workflow: concurrent ---- -Concurrent. -`), 0o644); err != nil { - t.Fatal(err) - } - if err := os.WriteFile(filepath.Join(pluginsDir, "01-step.go"), []byte(`package main - -import ( - "context" - "github.com/samcharles93/archie-core/internal/domain/workflow" -) - -func Stage() (string, func(context.Context, *workflow.TaskContext) error) { - return "step", func(ctx context.Context, tc *workflow.TaskContext) error { - return nil - } -} -`), 0o644); err != nil { - t.Fatal(err) - } - - base := workflow.Registry{"default": {Name: "default"}} - - // Run 10 concurrent augmentations -- none should panic or corrupt state. - errs := make(chan error, 10) - for range 10 { - go func() { - aug, err := AugmentRegistry(worktree, base) - if err != nil { - errs <- err - return - } - if _, ok := aug["concurrent"]; !ok { - errs <- nil // would use sentinel but keeping simple - return - } - errs <- nil - }() - } - for range 10 { - if err := <-errs; err != nil { - t.Error("concurrent AugmentRegistry failed:", err) - } - } - - // Base must still be unmodified. - if _, ok := base["concurrent"]; ok { - t.Error("base registry was mutated by concurrent augmentation") - } -} - -func TestAugmentRegistryBrokenSkillMDIsSkipped(t *testing.T) { - // A SKILL.md with invalid YAML must not crash augmentation -- the - // skill is simply skipped (skill.Catalog skips parse errors). - worktree := t.TempDir() - skillDir := filepath.Join(worktree, ".agents", "skills", "archie-wf-broken") - if err := os.MkdirAll(skillDir, 0o755); err != nil { - t.Fatal(err) - } - if err := os.WriteFile(filepath.Join(skillDir, "SKILL.md"), []byte(`--- -this is not valid: [[[ YAML {{{ ---- -Body. -`), 0o644); err != nil { - t.Fatal(err) - } - - base := workflow.Registry{"default": {Name: "default"}} - aug, err := AugmentRegistry(worktree, base) - if err != nil { - t.Fatal("AugmentRegistry errored on broken SKILL.md:", err) - } - if len(aug) != len(base) { - t.Errorf("got %d entries, want %d (broken SKILL.md adds nothing)", len(aug), len(base)) - } -} - -func TestAugmentRegistryWorktreeWithNoSkillsDir(t *testing.T) { - // A worktree that exists but has no .agents/ directory at all - // must not error. - worktree := t.TempDir() - // Don't create .agents/skills/ -- just a bare worktree. - if err := os.WriteFile(filepath.Join(worktree, "README.md"), []byte(`# repo`), 0o644); err != nil { - t.Fatal(err) - } - - base := workflow.Registry{"default": {Name: "default"}} - aug, err := AugmentRegistry(worktree, base) - if err != nil { - t.Fatal("AugmentRegistry errored on worktree without .agents/: ", err) - } - if len(aug) != len(base) { - t.Errorf("got %d entries, want %d", len(aug), len(base)) - } -} - -func TestAugmentRegistryNilBaseReturnsEmpty(t *testing.T) { - // A nil base registry must be treated as empty -- not panic. - worktree := t.TempDir() - aug, err := AugmentRegistry(worktree, nil) - if err != nil { - t.Fatal("AugmentRegistry errored with nil base:", err) - } - if aug == nil { - t.Error("AugmentRegistry returned nil for nil base -- want empty registry") - } - if len(aug) != 0 { - t.Errorf("got %d entries with nil base and no skills, want 0", len(aug)) - } -} - func TestBuildRegistryNoStagesReturnsEmptyWorkflow(t *testing.T) { dir := t.TempDir() skillDir := filepath.Join(dir, ".agents", "skills", "archie-wf-empty") @@ -1146,116 +780,6 @@ func Stage() (string, func(context.Context, *workflow.TaskContext) error) { } } -// TestAugmentRegistry_WarnsOnTwoWorktreeSkillsSameWorkflow verifies that -// AugmentRegistry warns when two worktree skills declare the same workflow -// name, while not warning on a normal builtin override. -func TestAugmentRegistry_WarnsOnTwoWorktreeSkillsSameWorkflow(t *testing.T) { - dir := t.TempDir() - - // Skill 1: declares "custom" - skill1 := filepath.Join(dir, ".agents", "skills", "archie-wf-custom-a") - plugins1 := filepath.Join(skill1, "plugins") - if err := os.MkdirAll(plugins1, 0o755); err != nil { - t.Fatal(err) - } - if err := os.WriteFile(filepath.Join(skill1, "SKILL.md"), []byte(`--- -name: archie-wf-custom-a -description: First custom -version: 1.0.0 -metadata: - archie: - workflow: custom ---- -First. -`), 0o644); err != nil { - t.Fatal(err) - } - if err := os.WriteFile(filepath.Join(plugins1, "01-a.go"), []byte(`package main - -import ( - "context" - "github.com/samcharles93/archie-core/internal/domain/workflow" -) - -func Stage() (string, func(context.Context, *workflow.TaskContext) error) { - return "a", func(ctx context.Context, tc *workflow.TaskContext) error { - return nil - } -} -`), 0o644); err != nil { - t.Fatal(err) - } - - // Skill 2: also declares "custom" - skill2 := filepath.Join(dir, ".agents", "skills", "archie-wf-custom-b") - plugins2 := filepath.Join(skill2, "plugins") - if err := os.MkdirAll(plugins2, 0o755); err != nil { - t.Fatal(err) - } - if err := os.WriteFile(filepath.Join(skill2, "SKILL.md"), []byte(`--- -name: archie-wf-custom-b -description: Second custom -version: 1.0.0 -metadata: - archie: - workflow: custom ---- -Second. -`), 0o644); err != nil { - t.Fatal(err) - } - if err := os.WriteFile(filepath.Join(plugins2, "01-b.go"), []byte(`package main - -import ( - "context" - "github.com/samcharles93/archie-core/internal/domain/workflow" -) - -func Stage() (string, func(context.Context, *workflow.TaskContext) error) { - return "b", func(ctx context.Context, tc *workflow.TaskContext) error { - return nil - } -} -`), 0o644); err != nil { - t.Fatal(err) - } - - capture := setSlogCapture(t) - - base := builtins() - aug, err := AugmentRegistry(dir, base) - if err != nil { - t.Fatal(err) - } - - wf, ok := aug["custom"] - if !ok { - t.Fatal("'custom' missing from augmented registry") - } - if wf.Stages[0].Name != "b" { - t.Errorf("stage[0].Name = %q, want b (last-write-wins)", wf.Stages[0].Name) - } - - // Must have a duplicate warning for skill-vs-skill conflict. - var warnings []slog.Record - for _, r := range capture.records { - if r.Level >= slog.LevelWarn && strings.Contains(r.Message, "duplicate") { - warnings = append(warnings, r) - } - } - if len(warnings) != 1 { - t.Fatalf("got %d duplicate warnings, want exactly 1 for skill-vs-skill conflict", len(warnings)) - } - - // No warning for builtin overrides (the base has all 5 built-ins). - for _, r := range capture.records { - if r.Level >= slog.LevelWarn && strings.Contains(r.Message, "duplicate") { - continue // the one we already verified - } - // No other warnings should mention builtin names in a duplicate context. - } -} - func TestBuildRegistrySkipsBrokenSkill(t *testing.T) { // R2: a skill with broken plugins must not prevent other skills // from registering -- and must not block daemon startup. From 41ad0d48eccf22af4e7f41f43d45a7d54c8ee0e1 Mon Sep 17 00:00:00 2001 From: Sam Catlow Date: Tue, 15 Sep 2026 13:12:22 +1000 Subject: [PATCH 3/4] refactor(binding): delete dead Matcher.Overlaps method DELETE: no document in docs/architecture/ or docs/prds/ specifies a consumer for binding.Matcher.Overlaps, and it has no caller or test caller. The store enforces the overlap invariant with its own SQL (internal/store/bindings.go InsertBinding/UpdateBinding), which is out of this lane's ownership and left untouched. The doc comment's empty-Source rule is already covered by Binding.validateCommon's "matcher.source is required" check, so nothing needs moving. --- internal/domain/binding/binding.go | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/internal/domain/binding/binding.go b/internal/domain/binding/binding.go index fb9455a7d..92fa0a728 100644 --- a/internal/domain/binding/binding.go +++ b/internal/domain/binding/binding.go @@ -138,18 +138,6 @@ func (m Matcher) Matches(source string, authenticated bool) bool { return m.Source == source } -// Overlaps reports whether two matchers cover any plausible event -// together. With a single-string matcher this collapses to: both have -// a non-empty Source equal to each other. Two empty matchers would -// overlap trivially; Validate rejects empty Sources upstream so this -// case cannot arise in practice. -func (m Matcher) Overlaps(other Matcher) bool { - if m.Source == "" || other.Source == "" { - return false - } - return m.Source == other.Source -} - // Normalize clamps an arbitrary string into a recognised Status, falling // back to StatusDraft for any unknown value. The DB CHECK constraint // already rejects bad strings at write time; Normalize is the API-edge From 2a6b9f928448422176dc6fae50c8107ce11e9593 Mon Sep 17 00:00:00 2001 From: Sam Catlow Date: Tue, 15 Sep 2026 13:13:55 +1000 Subject: [PATCH 4/4] refactor(forge): delete dead CreateIssue surface DELETE: no document in docs/architecture/ or docs/prds/ specifies a production consumer for forge.IssueForge.CreateIssue. It has no production caller -- the remaining repo matches are the GitHub CreateIssueReaction and Gitea CreateIssueComment SDK methods. Removing the interface method and the GitHub/Gitea/Noop implementations; the other fakes that still define CreateIssue are test-only and out of lane ownership, and an interface with one fewer method keeps them satisfying. RepliesAfter and forge.Reply are untouched (a parallel FLAG record). --- internal/forge/forge.go | 3 --- internal/forge/gitea.go | 9 --------- internal/forge/gitea_methods_test.go | 15 --------------- internal/forge/github.go | 14 -------------- internal/forge/noop.go | 4 ---- internal/forge/noop_test.go | 5 ----- 6 files changed, 50 deletions(-) diff --git a/internal/forge/forge.go b/internal/forge/forge.go index 64126b4ea..329bed5f7 100644 --- a/internal/forge/forge.go +++ b/internal/forge/forge.go @@ -60,9 +60,6 @@ type IssueForge interface { // CloseIssue closes an issue with an optional final comment. CloseIssue(ctx context.Context, owner, repo string, number int, comment string) error - // CreateIssue opens a new issue and returns its number. - CreateIssue(ctx context.Context, owner, repo, title, body string, labels []string) (int, error) - // React adds an emoji reaction to an issue. React(ctx context.Context, owner, repo string, number int, reaction string) error diff --git a/internal/forge/gitea.go b/internal/forge/gitea.go index 19fb7382e..816d384b1 100644 --- a/internal/forge/gitea.go +++ b/internal/forge/gitea.go @@ -294,15 +294,6 @@ func (c *GiteaClient) CloseIssue(ctx context.Context, owner, repo string, number return err } -// CreateIssue opens a new issue and returns its number. -func (c *GiteaClient) CreateIssue(ctx context.Context, owner, repo, title, body string, labels []string) (int, error) { - iss, _, err := c.cli.CreateIssue(owner, repo, gitea.CreateIssueOption{Title: title, Body: body}) - if err != nil { - return 0, err - } - return int(iss.Index), nil -} - // React adds an emoji reaction to an issue. func (c *GiteaClient) React(ctx context.Context, owner, repo string, number int, reaction string) error { _, _, err := c.cli.PostIssueReaction(owner, repo, int64(number), reaction) diff --git a/internal/forge/gitea_methods_test.go b/internal/forge/gitea_methods_test.go index a78db7071..c20c09b1a 100644 --- a/internal/forge/gitea_methods_test.go +++ b/internal/forge/gitea_methods_test.go @@ -230,21 +230,6 @@ func TestGiteaCloseIssueWithoutComment(t *testing.T) { } } -func TestGiteaCreateIssue(t *testing.T) { - c, mux := newTestGiteaClient(t) - mux.HandleFunc("POST /api/v1/repos/o/r/issues", func(w http.ResponseWriter, r *http.Request) { - writeJSON(t, w, map[string]any{"number": 11}) - }) - - num, err := c.CreateIssue(t.Context(), "o", "r", "title", "body", nil) - if err != nil { - t.Fatal(err) - } - if num != 11 { - t.Fatalf("num = %d, want 11", num) - } -} - func TestGiteaReact(t *testing.T) { c, mux := newTestGiteaClient(t) var got string diff --git a/internal/forge/github.go b/internal/forge/github.go index e1011b244..98d52be40 100644 --- a/internal/forge/github.go +++ b/internal/forge/github.go @@ -302,20 +302,6 @@ func (c *GitHubClient) LinkBranch(ctx context.Context, owner, repo string, issue return nil } -// CreateIssue opens a new issue and returns its number. -func (c *GitHubClient) CreateIssue(ctx context.Context, owner, repo, title, body string, labels []string) (int, error) { - req := &github.IssueRequest{ - Title: &title, - Body: &body, - Labels: &labels, - } - iss, _, err := c.gh.Issues.Create(ctx, owner, repo, req) - if err != nil { - return 0, fmt.Errorf("create issue %s/%s: %w", owner, repo, err) - } - return iss.GetNumber(), nil -} - // State labels mirror the task lifecycle onto the forge so archie's // status is visible at a glance. SQLite remains the source of truth; // labels are the human-facing projection -- and removing the parked diff --git a/internal/forge/noop.go b/internal/forge/noop.go index 08d45e9bb..2a2389c7f 100644 --- a/internal/forge/noop.go +++ b/internal/forge/noop.go @@ -38,10 +38,6 @@ func (n *NoopForge) CloseIssue(ctx context.Context, owner, repo string, number i return nil } -func (n *NoopForge) CreateIssue(ctx context.Context, owner, repo, title, body string, labels []string) (int, error) { - return 0, nil -} - func (n *NoopForge) React(ctx context.Context, owner, repo string, number int, reaction string) error { return nil } diff --git a/internal/forge/noop_test.go b/internal/forge/noop_test.go index 628e245cc..3000fb30c 100644 --- a/internal/forge/noop_test.go +++ b/internal/forge/noop_test.go @@ -40,11 +40,6 @@ func TestNoopForgeIsAllZeroValue(t *testing.T) { t.Errorf("CloseIssue() = %v, want nil", err) } - num, err := f.CreateIssue(ctx, "o", "r", "title", "body", nil) - if num != 0 || err != nil { - t.Errorf("CreateIssue() = (%d, %v), want (0, nil)", num, err) - } - if err := f.React(ctx, "o", "r", 1, "+1"); err != nil { t.Errorf("React() = %v, want nil", err) }