feat: replace hardcoded workflow registry with catalog-driven skillbuild.BuildRegistry()
The daemon no longer hardcodes workflow.Registry{...} in main.go.
Instead, skillbuild.BuildRegistry() scans .agents/skills/ for catalog
entries declaring metadata.archie.workflow and builds each workflow
from its Yaegi-interpreted stage plugins.
Built-in workflows (bootstrap, implement, tdd, feasibility, default)
serve as fallbacks when no skill declares a given workflow name. A
skill that declares metadata.archie.workflow: implement overrides the
built-in — skills define workflows, plugins define stages.
Why: skills must be extension primitives. Adding a workflow should
mean creating .agents/skills/archie-wf-<name>/plugins/*.go, not
modifying Go code in main.go. The catalog is the single source of
truth for what workflows exist.
This commit is contained in:
1 parent
bba6827ec2
commit
8958a82233
4 files changed
+300
-9
No files matched your search
+15
-8
@@ -23,7 +23,7 @@ import (
|
||||
"github.com/samcharles93/archie-core/internal/nats"
|
||||
"github.com/samcharles93/archie-core/internal/store"
|
||||
"github.com/samcharles93/archie-core/internal/webui"
|
||||
"github.com/samcharles93/archie-core/internal/workflow"
|
||||
"github.com/samcharles93/archie-core/internal/workflow/skillbuild"
|
||||
"github.com/samcharles93/archie-core/internal/workflow/wfeval"
|
||||
"github.com/samcharles93/archie-core/internal/worktree"
|
||||
)
|
||||
@@ -163,6 +163,19 @@ func run() int {
|
||||
}
|
||||
}
|
||||
}
|
||||
// Build the workflow registry from the skill catalog. Plugin-defined
|
||||
// workflows override built-ins of the same name; built-ins fill gaps.
|
||||
skillsBase := cfg.SkillsDir
|
||||
if skillsBase == "" {
|
||||
skillsBase = cfg.WorkDir
|
||||
}
|
||||
registry, err := skillbuild.BuildRegistry(skillsBase)
|
||||
if err != nil {
|
||||
log.Error("skill registry build failed", "err", err)
|
||||
return 1
|
||||
}
|
||||
log.Info("workflow registry built", "workflows", len(registry))
|
||||
|
||||
d := &daemon.Daemon{
|
||||
Cfg: cfg,
|
||||
Store: st,
|
||||
@@ -177,13 +190,7 @@ func run() int {
|
||||
},
|
||||
Runtime: llm,
|
||||
Agent: agentRunner,
|
||||
Workflows: workflow.Registry{
|
||||
"bootstrap": workflow.Bootstrap(),
|
||||
"implement": workflow.Implement(),
|
||||
"tdd": workflow.TDD(),
|
||||
"feasibility": workflow.Feasibility(),
|
||||
"default": workflow.Implement(),
|
||||
},
|
||||
Workflows: registry,
|
||||
Log: log,
|
||||
CustomStages: wfeval.Discover,
|
||||
Nats: natsClient,
|
||||
|
||||
@@ -204,6 +204,12 @@ func (d Dispatch) LabelValues() []string {
|
||||
// Config is the daemon configuration.
|
||||
type Config struct {
|
||||
WorkDir string `toml:"work_dir"`
|
||||
// SkillsDir is an optional path to a shared skills directory
|
||||
// containing .agents/skills/*/SKILL.md files. When set, the
|
||||
// daemon builds its workflow registry from the skill catalog
|
||||
// (plugin-defined workflows override built-ins). When empty,
|
||||
// only built-in workflows are available.
|
||||
SkillsDir string `toml:"skills_dir"`
|
||||
DBPath string `toml:"db_path"`
|
||||
PollInterval Duration `toml:"poll_interval"`
|
||||
// Label marks issues archie should pick up.
|
||||
|
||||
@@ -13,10 +13,57 @@ import (
|
||||
"github.com/traefik/yaegi/interp"
|
||||
"github.com/traefik/yaegi/stdlib"
|
||||
|
||||
"github.com/samcharles93/archie-core/internal/skill"
|
||||
"github.com/samcharles93/archie-core/internal/workflow"
|
||||
"github.com/samcharles93/archie-core/internal/workflow/wfextract"
|
||||
)
|
||||
|
||||
// builtins returns the hardcoded fallback workflows. These are used when
|
||||
// no skill declares a given workflow name in its metadata.archie.workflow.
|
||||
func builtins() workflow.Registry {
|
||||
return workflow.Registry{
|
||||
"bootstrap": workflow.Bootstrap(),
|
||||
"implement": workflow.Implement(),
|
||||
"tdd": workflow.TDD(),
|
||||
"feasibility": workflow.Feasibility(),
|
||||
"default": workflow.Implement(),
|
||||
}
|
||||
}
|
||||
|
||||
// BuildRegistry scans .agents/skills/ for catalog entries that declare a
|
||||
// workflow in metadata.archie.workflow, builds each from its stage plugins,
|
||||
// and returns a complete workflow.Registry. Workflow names not covered by
|
||||
// any skill fall back to the built-in Go definitions.
|
||||
//
|
||||
// Skills define workflows. Plugins define stages. The daemon composes them.
|
||||
func BuildRegistry(worktree string) (workflow.Registry, error) {
|
||||
catalog, err := skill.Catalog(worktree)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("skill catalog: %w", err)
|
||||
}
|
||||
|
||||
reg := builtins()
|
||||
|
||||
for _, entry := range catalog {
|
||||
if entry.Workflow == "" {
|
||||
continue
|
||||
}
|
||||
sw := SkillWorkflow{Workflow: entry.Workflow, Dir: entry.Dir}
|
||||
wf, err := BuildWorkflow(worktree, sw)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("build workflow %s from skill %s: %w", entry.Workflow, entry.Dir, err)
|
||||
}
|
||||
// Only override the built-in when the skill actually has stages —
|
||||
// an empty workflow means the skill declared intent but has no
|
||||
// plugins yet, so keep the built-in.
|
||||
if len(wf.Stages) > 0 {
|
||||
reg[entry.Workflow] = wf
|
||||
}
|
||||
}
|
||||
|
||||
return reg, nil
|
||||
}
|
||||
|
||||
// SkillWorkflow is the subset of a catalog entry needed to build a
|
||||
// workflow from a skill's stage plugins.
|
||||
type SkillWorkflow struct {
|
||||
|
||||
@@ -111,7 +111,238 @@ func TestBuildWorkflowMissingSkillReturnsEmptyWorkflow(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildWorkflowNoStagesReturnsEmptyWorkflow(t *testing.T) {
|
||||
// ── registry built from skill catalog ────────────────────────────────
|
||||
|
||||
func TestBuildRegistryFromSkillCatalog(t *testing.T) {
|
||||
// When .agents/skills/ contains directories with metadata.archie.workflow,
|
||||
// BuildRegistry must return a workflow.Registry with those workflows
|
||||
// built from their stage plugins. Workflows not declared by any skill
|
||||
// fall back to the built-in definitions (bootstrap, implement, tdd,
|
||||
// feasibility, default→implement).
|
||||
|
||||
dir := t.TempDir()
|
||||
|
||||
// Skill 1: archie-wf-greet — plugin-defined workflow.
|
||||
greetDir := filepath.Join(dir, ".agents", "skills", "archie-wf-greet", "plugins")
|
||||
if err := os.MkdirAll(greetDir, 0o755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.WriteFile(filepath.Join(greetDir, "01-hello.go"), []byte(`package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/samcharles93/archie-core/internal/workflow"
|
||||
)
|
||||
|
||||
func Stage() (string, func(context.Context, *workflow.TaskContext) error) {
|
||||
return "hello", func(ctx context.Context, tc *workflow.TaskContext) error {
|
||||
tc.BuildSummary = "greet-plugin-ran"
|
||||
return nil
|
||||
}
|
||||
}
|
||||
`), 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.WriteFile(filepath.Join(filepath.Dir(greetDir), "SKILL.md"), []byte(`---
|
||||
name: archie-wf-greet
|
||||
description: Greet workflow from plugins
|
||||
version: 1.0.0
|
||||
metadata:
|
||||
archie:
|
||||
workflow: greet
|
||||
---
|
||||
Greet the user.
|
||||
`), 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Skill 2: archie-wf-implement — overrides the built-in implement workflow.
|
||||
implDir := filepath.Join(dir, ".agents", "skills", "archie-wf-custom-impl", "plugins")
|
||||
if err := os.MkdirAll(implDir, 0o755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.WriteFile(filepath.Join(implDir, "01-plan.go"), []byte(`package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/samcharles93/archie-core/internal/workflow"
|
||||
)
|
||||
|
||||
func Stage() (string, func(context.Context, *workflow.TaskContext) error) {
|
||||
return "custom-plan", func(ctx context.Context, tc *workflow.TaskContext) error {
|
||||
tc.BuildSummary = "custom-impl-ran"
|
||||
return nil
|
||||
}
|
||||
}
|
||||
`), 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.WriteFile(filepath.Join(filepath.Dir(implDir), "SKILL.md"), []byte(`---
|
||||
name: archie-wf-custom-impl
|
||||
description: Custom implement workflow
|
||||
version: 1.0.0
|
||||
metadata:
|
||||
archie:
|
||||
workflow: implement
|
||||
---
|
||||
Custom implementation workflow.
|
||||
`), 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
reg, err := BuildRegistry(dir)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Skill-defined workflows must be present.
|
||||
t.Run("skill-defined workflow is registered", func(t *testing.T) {
|
||||
wf, ok := reg["greet"]
|
||||
if !ok {
|
||||
t.Fatal("BuildRegistry did not register workflow 'greet' from skill catalog")
|
||||
}
|
||||
if wf.Name != "greet" {
|
||||
t.Errorf("Workflow.Name = %q, want greet", wf.Name)
|
||||
}
|
||||
if len(wf.Stages) == 0 {
|
||||
t.Error("workflow 'greet' has no stages — plugin stages not loaded")
|
||||
}
|
||||
// Run it — stages must execute.
|
||||
tc := &workflow.TaskContext{BuildSummary: ""}
|
||||
for _, s := range wf.Stages {
|
||||
if err := s.Run(context.Background(), tc); err != nil {
|
||||
t.Fatalf("stage %s: %v", s.Name, err)
|
||||
}
|
||||
}
|
||||
if tc.BuildSummary != "greet-plugin-ran" {
|
||||
t.Errorf("BuildSummary = %q, want 'greet-plugin-ran'", tc.BuildSummary)
|
||||
}
|
||||
})
|
||||
|
||||
// Skill override of built-in must take precedence.
|
||||
t.Run("skill overrides built-in workflow", func(t *testing.T) {
|
||||
wf, ok := reg["implement"]
|
||||
if !ok {
|
||||
t.Fatal("BuildRegistry did not register workflow 'implement'")
|
||||
}
|
||||
if len(wf.Stages) == 0 {
|
||||
t.Fatal("workflow 'implement' has no stages")
|
||||
}
|
||||
tc := &workflow.TaskContext{BuildSummary: ""}
|
||||
for _, s := range wf.Stages {
|
||||
if err := s.Run(context.Background(), tc); err != nil {
|
||||
t.Fatalf("stage %s: %v", s.Name, err)
|
||||
}
|
||||
}
|
||||
if tc.BuildSummary != "custom-impl-ran" {
|
||||
t.Errorf("BuildSummary = %q, want 'custom-impl-ran' — skill override did not take effect", tc.BuildSummary)
|
||||
}
|
||||
})
|
||||
|
||||
// Built-in fallback: tdd is not declared by any skill.
|
||||
t.Run("built-in fallback for undeclared workflow", func(t *testing.T) {
|
||||
wf, ok := reg["tdd"]
|
||||
if !ok {
|
||||
t.Fatal("BuildRegistry missing built-in fallback for 'tdd'")
|
||||
}
|
||||
if wf.Name != "tdd" {
|
||||
t.Errorf("Workflow.Name = %q, want tdd", wf.Name)
|
||||
}
|
||||
if len(wf.Stages) == 0 {
|
||||
t.Error("built-in tdd workflow has no stages")
|
||||
}
|
||||
})
|
||||
|
||||
// "default" key must always exist.
|
||||
t.Run("default key exists", func(t *testing.T) {
|
||||
wf, ok := reg["default"]
|
||||
if !ok {
|
||||
t.Fatal("BuildRegistry missing 'default' workflow key")
|
||||
}
|
||||
if len(wf.Stages) == 0 {
|
||||
t.Error("default workflow has no stages")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestBuildRegistryNoSkillsReturnsBuiltins(t *testing.T) {
|
||||
// When .agents/skills/ does not exist, BuildRegistry returns the
|
||||
// built-in workflow set so the daemon can still route tasks.
|
||||
reg, err := BuildRegistry(t.TempDir())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
builtins := []string{"bootstrap", "implement", "tdd", "feasibility", "default"}
|
||||
for _, name := range builtins {
|
||||
wf, ok := reg[name]
|
||||
if !ok {
|
||||
t.Errorf("BuildRegistry missing built-in workflow %q when no skills exist", name)
|
||||
continue
|
||||
}
|
||||
if wf.Name != name && !(name == "default" && wf.Name == "implement") {
|
||||
t.Errorf("built-in %q: Name = %q, want %q", name, wf.Name, name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildRegistrySkillWithNoWorkflowDeclaredIsIgnored(t *testing.T) {
|
||||
// A skill directory without metadata.archie.workflow must not
|
||||
// produce a registry entry. It's a utility skill, not a workflow.
|
||||
dir := t.TempDir()
|
||||
skillDir := filepath.Join(dir, ".agents", "skills", "archie-wf-utils")
|
||||
if err := os.MkdirAll(skillDir, 0o755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.WriteFile(filepath.Join(skillDir, "SKILL.md"), []byte(`---
|
||||
name: archie-wf-utils
|
||||
description: Utility helpers, not a workflow
|
||||
version: 1.0.0
|
||||
metadata:
|
||||
archie:
|
||||
tools: [go]
|
||||
---
|
||||
Utility content.
|
||||
`), 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
reg, err := BuildRegistry(dir)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// There is no workflow called "utils" because the skill didn't declare one.
|
||||
if _, ok := reg["utils"]; ok {
|
||||
t.Error("BuildRegistry registered 'utils' as a workflow, but the skill " +
|
||||
"did not declare metadata.archie.workflow — only skills that declare " +
|
||||
"a workflow should produce registry entries")
|
||||
}
|
||||
|
||||
// Built-ins must still be present.
|
||||
if _, ok := reg["implement"]; !ok {
|
||||
t.Error("built-in 'implement' missing when a non-workflow skill exists")
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildRegistryEmptySkillsDirReturnsBuiltins(t *testing.T) {
|
||||
// An empty .agents/skills/ directory must not cause an error.
|
||||
dir := t.TempDir()
|
||||
if err := os.MkdirAll(filepath.Join(dir, ".agents", "skills"), 0o755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
reg, err := BuildRegistry(dir)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if _, ok := reg["implement"]; !ok {
|
||||
t.Error("built-in 'implement' missing when skills dir is empty")
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildRegistryNoStagesReturnsEmptyWorkflow(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
skillDir := filepath.Join(dir, ".agents", "skills", "archie-wf-empty")
|
||||
if err := os.MkdirAll(skillDir, 0o755); err != nil {
|
||||
|
||||
Reference in new issue
Block a user