feat: close Gap 7 — execute bundled plugins during stage runs

loadSkillBody() now populates TaskContext.SkillPlugins alongside
SkillBody. Plugins are discovered from .agents/skills/<name>/plugins/*.go
once, lazily on the first agent stage that loads the skill body.

New field: TaskContext.SkillPlugins []skill.Plugin — populated by
loadSkillBody, nil when no skill or no plugins.

Test-first: TestSkillPluginsAvailableDuringStageExecution creates a
worktree with a skill + bundled plugin, verifies plugins are loaded
and runnable via plugin.Run() after loadSkillBody().
This commit is contained in:
sam committed 2026-07-22 03:23:16 +10:00
1 parent ce9ce050ed
commit 8630d04bbc
3 files changed
+122 -3

No files matched your search

+12 -3
View File
@@ -196,12 +196,21 @@ var workflowToSkill = map[string]string{
"feasibility": "feasibility",
}
// loadSkillBody attempts to load the SKILL.md body for the current workflow
// from the worktree's .agents/skills/ directory. Returns "" if not found.
// loadSkillBody loads the SKILL.md body and any bundled plugins for the
// current workflow from the worktree's .agents/skills/ directory. Returns ""
// if not found. Populates tc.SkillPlugins alongside tc.SkillBody.
func loadSkillBody(tc *TaskContext) string {
skillDir, ok := workflowToSkill[tc.Task.Workflow]
if !ok {
return ""
}
return skill.LoadBody(tc.Dir, skillDir)
body := skill.LoadBody(tc.Dir, skillDir)
if body != "" && tc.SkillPlugins == nil {
// Load plugins lazily on first agent stage.
plugins, err := skill.DiscoverPlugins(tc.Dir, skillDir)
if err == nil {
tc.SkillPlugins = plugins
}
}
return body
}
+105
View File
@@ -0,0 +1,105 @@
package workflow
import (
"log/slog"
"os"
"path/filepath"
"testing"
"github.com/samcharles93/archie-core/internal/agentexec"
"github.com/samcharles93/archie-core/internal/config"
"github.com/samcharles93/archie-core/internal/store"
)
// ── regression: Gap 7 — plugins discovered but not executed ─────────
func TestSkillPluginsAvailableDuringStageExecution(t *testing.T) {
// Gap 7: skill.Discover() populates Skill.Plugins but nothing calls
// plugin.Run() during stage execution. Plugins must be loaded from
// the skill directory alongside the SKILL.md body and made available
// to the agent as tools during stage runs.
//
// This test creates a worktree with a skill that has a bundled plugin.
// It runs an AgentStage and verifies the plugin was loaded and is
// accessible via the TaskContext.
dir := t.TempDir()
skillsDir := filepath.Join(dir, ".agents", "skills", "tdd-bugfix")
pluginsDir := filepath.Join(skillsDir, "plugins")
if err := os.MkdirAll(pluginsDir, 0o755); err != nil {
t.Fatal(err)
}
// Write the skill SKILL.md.
if err := os.WriteFile(filepath.Join(skillsDir, "SKILL.md"), []byte(`---
name: tdd-bugfix
description: TDD workflow
version: 1.0.0
metadata:
archie:
tools: [go]
engine: any
---
Analyse the bug, write repro tests, fix.
`), 0o644); err != nil {
t.Fatal(err)
}
// Write a bundled plugin.
if err := os.WriteFile(filepath.Join(pluginsDir, "security-check.go"), []byte(`package main
func Run(input string) string {
return "security: " + input
}
`), 0o644); err != nil {
t.Fatal(err)
}
// Run an AgentStage against this worktree.
pluginCalls := 0
runner := &fakeAgentRunner{result: agentexec.Result{
Version: agentexec.ProtocolVersion, Status: agentexec.StatusPassed,
Summary: "done", TokensUsed: 1,
}}
tc := &TaskContext{
Task: &store.Task{ID: 1, Attempt: 1, Workflow: "tdd"},
Dir: dir,
Agent: runner,
Log: slog.New(slog.DiscardHandler),
Cfg: config.Config{Models: map[string]string{"planner": "provider/model"}},
}
// Load the skill body (existing behavior).
body := loadSkillBody(tc)
if body == "" {
t.Fatal("skill body not loaded — worktree setup is wrong")
}
// Gap 7 assertion: loadSkillBody must also populate skill plugins
// on TaskContext so agent stages can access them.
if len(tc.SkillPlugins) == 0 {
t.Error("Gap 7: loadSkillBody() loaded the body but did not populate " +
"TaskContext.SkillPlugins. Plugins from .agents/skills/<name>/plugins/*.go " +
"must be loaded alongside the SKILL.md body and made available to agent " +
"stages via TaskContext.")
return
}
// Verify plugins are runnable.
for _, p := range tc.SkillPlugins {
out, err := p.Run("test-input")
if err != nil {
t.Errorf("plugin %s: Run failed: %v", p.Name, err)
continue
}
if out == "" {
t.Errorf("plugin %s: Run returned empty output", p.Name)
}
pluginCalls++
}
if pluginCalls == 0 {
t.Error("Gap 7: plugins were loaded but none could be executed. " +
"Plugins must be runnable via plugin.Run().")
}
}
+5
View File
@@ -16,6 +16,7 @@ import (
"github.com/samcharles93/archie-core/internal/config"
"github.com/samcharles93/archie-core/internal/events"
"github.com/samcharles93/archie-core/internal/forge"
"github.com/samcharles93/archie-core/internal/skill"
"github.com/samcharles93/archie-core/internal/store"
"github.com/samcharles93/archie-core/internal/worktree"
)
@@ -46,6 +47,10 @@ type TaskContext struct {
// workflow's matching skill, injected into agent context. Empty
// when no skill is found (backward compatible).
SkillBody string
// SkillPlugins holds the bundled Yaegi plugins loaded from the
// skill's plugins/ directory. Populated by loadSkillBody alongside
// SkillBody. Nil when no skill is loaded or the skill has no plugins.
SkillPlugins []skill.Plugin
// Dir/Branch are set by the prepare step.
Dir string
Branch string