From 4b1bfec9bd48017fea8f03d803f3d1034086471b Mon Sep 17 00:00:00 2001 From: Sam Catlow Date: Sun, 4 Oct 2026 03:07:39 +1100 Subject: [PATCH] refactor(skill): delete Yaegi skill scripts and the run_go_script tool No shipped skill used plugins/. The agent request drops its Plugins field with the staging code behind it. --- internal/agentexec/modelloop/loop_runner.go | 77 --------------- internal/app/agentworker/persistent_runner.go | 19 +--- internal/domain/agentrun/protocol.go | 10 -- internal/domain/workflow/agent.go | 26 +---- internal/domain/workflow/workflow.go | 5 - internal/skill/plugin.go | 94 ------------------- internal/skill/skill.go | 1 - internal/skillscript/yaegi.go | 90 ------------------ internal/storage/storage.go | 31 +----- 9 files changed, 4 insertions(+), 349 deletions(-) delete mode 100644 internal/skill/plugin.go delete mode 100644 internal/skillscript/yaegi.go diff --git a/internal/agentexec/modelloop/loop_runner.go b/internal/agentexec/modelloop/loop_runner.go index 84315e2db..7485bef1b 100644 --- a/internal/agentexec/modelloop/loop_runner.go +++ b/internal/agentexec/modelloop/loop_runner.go @@ -6,19 +6,14 @@ import ( "fmt" "log/slog" "maps" - "path/filepath" "slices" - "strings" "github.com/samcharles93/ai-sdk/agentloop" "github.com/samcharles93/ai-sdk/core" "github.com/samcharles93/ai-sdk/runtime" - "github.com/samcharles93/ai-sdk/toolkit" "github.com/samcharles93/archie-core/internal/agentexec" "github.com/samcharles93/archie-core/internal/domain/agentrun" - "github.com/samcharles93/archie-core/internal/skill" - "github.com/samcharles93/archie-core/internal/skillscript" "github.com/samcharles93/archie-core/internal/tools" ) @@ -78,11 +73,6 @@ func (r *LoopRunner) Run(ctx context.Context, workspace string, req agentrun.Req return agentrun.Result{}, fmt.Errorf("build central tool set: %w", err) } captureTools := captureToolSet(req.CaptureTools, captures) - scriptTools := scriptToolSet(workspace) - pluginTools, err := pluginToolSet(req, workspace, centralTools, captureTools, scriptTools) - if err != nil { - return agentrun.Result{}, err - } res, err := r.run(ctx, agentloop.Config{ Runtime: r.runtime, ModelRef: req.Model, @@ -108,8 +98,6 @@ func (r *LoopRunner) Run(ctx context.Context, workspace string, req agentrun.Req Extra: mergeToolSets( allowedTools(centralTools, r.AllowTools), captureTools, - allowedTools(scriptTools, r.AllowTools), - allowedTools(pluginTools, r.AllowTools), ), Logger: r.logger(req), }) @@ -153,43 +141,6 @@ func resultFromRun(req agentrun.Request, res agentloop.Result, appended []string return result } -func pluginToolSet(req agentrun.Request, workspace string, occupied ...core.ToolSet) (core.ToolSet, error) { - if req.ReadOnly || len(req.Protection.Suffixes)+len(req.Protection.Globs) > 0 || len(req.Gate.Commands) > 0 { - return nil, nil - } - builtins := toolkit.NewRegistry() - if err := toolkit.RegisterBuiltins(builtins, workspace); err != nil { - return nil, fmt.Errorf("register built-in tools for plugin collision check: %w", err) - } - reserved := map[string]struct{}{"finish": {}, "write_note": {}} - for _, name := range builtins.Names() { - reserved[name] = struct{}{} - } - set := make(core.ToolSet, len(req.Plugins)) - for _, spec := range req.Plugins { - if _, exists := reserved[spec.Name]; exists { - return nil, fmt.Errorf("plugin tool %q conflicts with an agent-loop tool", spec.Name) - } - for _, tools := range occupied { - if _, exists := tools[spec.Name]; exists { - return nil, fmt.Errorf("plugin tool %q conflicts with an existing tool", spec.Name) - } - } - plugin := skill.Plugin{Name: spec.Name, Src: spec.Src} - set[spec.Name] = core.NewTypedTool( - spec.Name, - "Run the project-bundled "+spec.Name+" plugin.", - func(_ context.Context, args struct { - Input string `json:"input"` - }, - ) (string, error) { - return plugin.Run(args.Input) - }, - ) - } - return set, nil -} - func (r *LoopRunner) logger(req agentrun.Request) *slog.Logger { if r.log == nil { return slog.New(slog.DiscardHandler) @@ -236,34 +187,6 @@ func makeCaptureHandler(spec agentrun.CaptureTool, captures map[string][]json.Ra } } -// scriptToolSet exposes run_go_script, which runs a Yaegi Go script from the -// workspace and returns its output. -func scriptToolSet(workspace string) core.ToolSet { - return core.ToolSet{ - "run_go_script": core.NewTypedTool( - "run_go_script", - "Run a Yaegi-interpreted Go script (e.g. a skill's bundled scripts/*.go helper) and return everything it printed.", - func(ctx context.Context, args struct { - Path string `json:"path" jsonschema:"description=Path to the .go script, relative to the workspace root."` - }, - ) (string, error) { - if strings.TrimSpace(args.Path) == "" { - return "run_go_script rejected: arguments must be a JSON object with a non-empty path field", nil - } - full := filepath.Join(workspace, args.Path) - if rel, err := filepath.Rel(workspace, full); err != nil || strings.HasPrefix(rel, "..") { - return "run_go_script rejected: path escapes the workspace", nil //nolint:nilerr // rejection feedback lets the model retry with a valid path - } - out, err := skillscript.RunContext(ctx, full) - if err != nil { - return fmt.Sprintf("run_go_script failed: %v\n%s", err, out), nil - } - return out, nil - }, - ), - } -} - // allowedTools keeps the tools allow names; an empty allow keeps them all. func allowedTools(set core.ToolSet, allow []string) core.ToolSet { if len(allow) == 0 { diff --git a/internal/app/agentworker/persistent_runner.go b/internal/app/agentworker/persistent_runner.go index c3b5288b2..b9b9b8ed8 100644 --- a/internal/app/agentworker/persistent_runner.go +++ b/internal/app/agentworker/persistent_runner.go @@ -3,7 +3,6 @@ package agentworker import ( "context" "fmt" - "os" "strings" "github.com/samcharles93/archie-core/internal/domain/agentrun" @@ -15,7 +14,6 @@ type persistentRunner struct { enabled bool sessionPath string memoryPath string - pluginsDir string } type memoryRecord struct { @@ -50,28 +48,13 @@ func (r persistentRunner) Run(ctx context.Context, workspace string, request age if !r.enabled { return r.Runner.Run(ctx, workspace, request, report) } - sessionPath, memoryPath, pluginsDir := r.sessionPath, r.memoryPath, r.pluginsDir + sessionPath, memoryPath := r.sessionPath, r.memoryPath if sessionPath == "" { sessionPath = storage.SessionPath } if memoryPath == "" { memoryPath = storage.MemoryPath } - if pluginsDir == "" { - pluginsDir = storage.PluginsDir - } - for i := range request.Plugins { - plugin := &request.Plugins[i] - filename := plugin.Name + ".go" - if err := storage.StagePlugin(pluginsDir, filename, []byte(plugin.Src)); err != nil { - return agentrun.Result{}, fmt.Errorf("stage plugin %s: %w", plugin.Name, err) - } - source, err := os.ReadFile(pluginsDir + "/" + filename) - if err != nil { - return agentrun.Result{}, fmt.Errorf("read staged plugin %s: %w", plugin.Name, err) - } - plugin.Src = string(source) - } result, runErr := r.Runner.Run(ctx, workspace, request, report) if runErr != nil { diff --git a/internal/domain/agentrun/protocol.go b/internal/domain/agentrun/protocol.go index 5d9052d46..44c76fa9c 100644 --- a/internal/domain/agentrun/protocol.go +++ b/internal/domain/agentrun/protocol.go @@ -78,10 +78,6 @@ type Request struct { Protection Protection `json:"protection"` Notes string `json:"notes,omitempty"` CaptureTools []CaptureTool `json:"capture_tools,omitempty"` - // Plugins are bundled Yaegi plugins from the skill's plugins/ directory. - // Each entry carries the name and source so the agent can register them as - // tools. - Plugins []PluginSpec `json:"plugins,omitempty"` // Harness, when set, runs the stage on an external coding-agent CLI // instead of the built-in loop. The worker in a Kit container is the // daemon's own archie-agent build, so it always understands this field. @@ -112,12 +108,6 @@ type HarnessSpec struct { MCPConfig []string `json:"mcp_config,omitempty"` } -// PluginSpec is a bundled Yaegi plugin passed from daemon to agent. -type PluginSpec struct { - Name string `json:"name"` - Src string `json:"src"` -} - // Validate rejects requests that this runner cannot safely interpret. func (r Request) Validate() error { if r.Version != ProtocolVersion { diff --git a/internal/domain/workflow/agent.go b/internal/domain/workflow/agent.go index 0cf903bf5..88f0b7c34 100644 --- a/internal/domain/workflow/agent.go +++ b/internal/domain/workflow/agent.go @@ -145,7 +145,6 @@ func (a AgentStage) buildRequest(tc *TaskContext, modelRef string) (agentrun.Req Protection: protection, Notes: tc.Task.Notes, CaptureTools: captureTools, - Plugins: pluginSpecs(tc.SkillPlugins), }, nil } @@ -286,18 +285,6 @@ func GateFromRepo(repo config.Repo, budgets config.Budgets) agentrun.Gate { return agentrun.Gate{Commands: cmds, MaxConsecutiveFailures: budgets.GateMaxFailures} } -// pluginSpecs converts skill.Plugin to agentrun.PluginSpec for transport. -func pluginSpecs(plugins []skill.Plugin) []agentrun.PluginSpec { - if len(plugins) == 0 { - return nil - } - out := make([]agentrun.PluginSpec, len(plugins)) - for i, p := range plugins { - out[i] = agentrun.PluginSpec{Name: p.Name, Src: p.Src} - } - return out -} - // missionWithSkill prepends the skill body (loaded from SKILL.md) to the // stage's mission. When no skill is loaded, the mission is returned unchanged. func missionWithSkill(tc *TaskContext, mission string) string { @@ -307,9 +294,8 @@ func missionWithSkill(tc *TaskContext, mission string) string { return "Follow these project-specific guidelines:\n\n" + tc.SkillBody + "\n\n---\n\n" + mission } -// loadSkillBody loads the SKILL.md body and plugins for the current workflow, -// matched by metadata.archie.workflow. Listed plugins load in declared order; -// otherwise every *.go file is loaded. +// loadSkillBody loads the SKILL.md body for the current workflow, matched by +// metadata.archie.workflow. func loadSkillBody(tc *TaskContext) string { catalog, _ := skill.Catalog(tc.Dir) entry := skill.SkillForWorkflow(catalog, tc.Task.Workflow) @@ -327,13 +313,5 @@ func loadSkillBody(tc *TaskContext) string { return "" } body = strings.TrimSpace(body) - if body != "" && tc.SkillPlugins == nil { - var pluginNames []string - if fm.Metadata.Archie != nil { - pluginNames = fm.Metadata.Archie.Plugins - } - plugins, _ := skill.LoadPlugins(tc.Dir, entry.Dir, pluginNames) - tc.SkillPlugins = plugins - } return body } diff --git a/internal/domain/workflow/workflow.go b/internal/domain/workflow/workflow.go index 2f0b04615..cb12b3265 100644 --- a/internal/domain/workflow/workflow.go +++ b/internal/domain/workflow/workflow.go @@ -14,7 +14,6 @@ import ( "github.com/samcharles93/archie-core/internal/domain/agentrun" "github.com/samcharles93/archie-core/internal/domain/workflow/task" "github.com/samcharles93/archie-core/internal/events" - "github.com/samcharles93/archie-core/internal/skill" "github.com/samcharles93/archie-core/internal/taskstate" "github.com/samcharles93/archie-core/internal/tools" ) @@ -104,10 +103,6 @@ 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 diff --git a/internal/skill/plugin.go b/internal/skill/plugin.go deleted file mode 100644 index 2249556a0..000000000 --- a/internal/skill/plugin.go +++ /dev/null @@ -1,94 +0,0 @@ -package skill - -import ( - "fmt" - "os" - "path/filepath" - "sort" - "strings" - - "github.com/traefik/yaegi/interp" - - "github.com/samcharles93/archie-core/internal/yaegiutil" -) - -// Plugin is a discovered Yaegi-interpreted .go file in a skill's plugins/ -// directory. The source must be a valid Go package exporting a Run function: -// -// func Run(input string) string -type Plugin struct { - Name string // filename without .go extension - Path string // full path to the .go file - Src string // source code content -} - -// Run interprets the plugin source via Yaegi and calls its Run function -// with the given input. The plugin runs with full standard library access. -func (p *Plugin) Run(input string) (string, error) { - i, err := yaegiutil.New(interp.Options{}) - if err != nil { - return "", fmt.Errorf("plugin %s: %w", p.Name, err) - } - // Plugins must use package main -- the convention for runnable Yaegi scripts. - fn, err := yaegiutil.Resolve[func(string) string](i, p.Src, "main.Run") - if err != nil { - return "", fmt.Errorf("plugin %s: %w", p.Name, err) - } - return fn(input), nil -} - -// LoadPlugins loads a skill's plugins: the allowed files in order, or every -// *.go file in plugins/ alphabetically when allowed is empty. A listed file -// that is missing is an error. -func LoadPlugins(dir, skillName string, allowed []string) ([]Plugin, error) { - pluginsDir := filepath.Join(dir, skillsDir, skillName, "plugins") - entries, err := os.ReadDir(pluginsDir) - if os.IsNotExist(err) { - // Skill exists but has no plugins directory -- not an error. - return nil, nil - } - if err != nil { - return nil, fmt.Errorf("read plugins dir %s: %w", pluginsDir, err) - } - - // Build an on-disk set for existence checks when filtering. - onDisk := make(map[string]struct{}, len(entries)) - for _, e := range entries { - if !e.IsDir() && strings.HasSuffix(e.Name(), ".go") { - onDisk[e.Name()] = struct{}{} - } - } - - var names []string - if len(allowed) == 0 { - // Fallback: glob all *.go files alphabetically. - for name := range onDisk { - names = append(names, name) - } - sort.Strings(names) - } else { - // Use the frontmatter list; strip "plugins/" prefix. - for _, a := range allowed { - a = strings.TrimPrefix(a, "plugins/") - if _, ok := onDisk[a]; !ok { - return nil, fmt.Errorf("plugin %q listed in metadata.archie.plugins not found on disk", a) - } - names = append(names, a) - } - } - - plugins := make([]Plugin, 0, len(names)) - for _, name := range names { - path := filepath.Join(pluginsDir, name) - src, err := os.ReadFile(path) - if err != nil { - return nil, fmt.Errorf("read plugin %s: %w", path, err) - } - plugins = append(plugins, Plugin{ - Name: strings.TrimSuffix(name, ".go"), - Path: path, - Src: string(src), - }) - } - return plugins, nil -} diff --git a/internal/skill/skill.go b/internal/skill/skill.go index 19f713a0e..eeb1ddf78 100644 --- a/internal/skill/skill.go +++ b/internal/skill/skill.go @@ -22,7 +22,6 @@ type Frontmatter struct { Archie *struct { Tools []string `yaml:"tools"` Engine string `yaml:"engine"` - Plugins []string `yaml:"plugins,omitempty"` Workflow string `yaml:"workflow,omitempty"` } `yaml:"archie"` } `yaml:"metadata"` diff --git a/internal/skillscript/yaegi.go b/internal/skillscript/yaegi.go deleted file mode 100644 index 79041e48a..000000000 --- a/internal/skillscript/yaegi.go +++ /dev/null @@ -1,90 +0,0 @@ -// Package skillscript runs skill-bundled Go scripts -// via Yaegi. Unlike the gate and workflow-stage extension surfaces, these -// scripts only need the Go standard library -- they wrap external tools -// (gitleaks, trivy, ...) the way a shell script would -- so no -// archie-core-specific symbol table is required here. -package skillscript - -import ( - "bytes" - "context" - "fmt" - "os" - "time" - - "github.com/traefik/yaegi/interp" - "github.com/traefik/yaegi/stdlib/unrestricted" - - "github.com/samcharles93/archie-core/internal/yaegiutil" -) - -// defaultTimeout protects callers that use Run (the legacy, context-free -// signature) from a script that blocks forever. Callers that have a -// context should use RunContext instead. -const defaultTimeout = 1 * time.Second - -// Run interprets the Go script at path and executes its main function, -// returning everything it wrote to stdout and stderr. The script runs -// in-process (interpreted, not sandboxed) with unrestricted symbols -// (os/exec included -- these scripts wrap external tools the way a shell -// script would), so a panic inside it is recovered and returned as an -// error rather than taking down the daemon. -// -// Run is a convenience wrapper around RunContext with a short built-in -// timeout. Callers that need precise cancellation or a different deadline -// should use RunContext directly. -func Run(path string) (string, error) { - ctx, cancel := context.WithTimeout(context.Background(), defaultTimeout) - defer cancel() - return RunContext(ctx, path) -} - -// RunContext interprets the Go script at path and executes its main -// function, returning everything it wrote to stdout and stderr. -// The script is executed in a goroutine; if ctx is cancelled or exceeds -// its deadline before the script finishes, RunContext returns the -// context error and abandons the goroutine (yaegi does not support -// external cancellation of an in-progress eval). -func RunContext(ctx context.Context, path string) (string, error) { - if _, statErr := os.Stat(path); statErr != nil { - return "", statErr - } - - // Check context before spawning the goroutine. - if err := ctx.Err(); err != nil { - return "", err - } - - type result struct { - output string - err error - } - - ch := make(chan result, 1) - go func() { - out, err := yaegiutil.Safe(path, func() (string, error) { - var buf bytes.Buffer - i, err := yaegiutil.New(interp.Options{Stdout: &buf, Stderr: &buf}, unrestricted.Symbols) - if err != nil { - return "", err - } - - // EvalPath treats a package-main source file the way `go run` does: - // evaluating it executes its main() directly. Unlike `go build`, it - // does not complain about a missing main() -- such a script simply - // produces no output. - if _, err := i.EvalPath(path); err != nil { - return "", fmt.Errorf("yaegi: run %s: %w", path, err) - } - return buf.String(), nil - }) - ch <- result{out, err} - }() - - select { - case r := <-ch: - return r.output, r.err - case <-ctx.Done(): - return "", ctx.Err() - } -} diff --git a/internal/storage/storage.go b/internal/storage/storage.go index cc384ab19..2e793969f 100644 --- a/internal/storage/storage.go +++ b/internal/storage/storage.go @@ -106,34 +106,6 @@ func ReadJSONLines[T any](path string, fn func(T) error) error { return nil } -// StagePlugin writes a bundled plugin unless persistent project storage -// already contains a plugin with the same filename. Persistent copies are -// operator-owned overrides and therefore win over daemon-staged source. -func StagePlugin(dir, name string, source []byte) error { - if filepath.Base(name) != name || name == "." || name == "" { - return fmt.Errorf("invalid plugin filename %q", name) - } - if err := os.MkdirAll(dir, 0o755); err != nil { - return fmt.Errorf("create plugin directory: %w", err) - } - path := filepath.Join(dir, name) - f, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE|os.O_EXCL, 0o600) - if errors.Is(err, os.ErrExist) { - return nil - } - if err != nil { - return fmt.Errorf("create staged plugin: %w", err) - } - if _, err := f.Write(source); err != nil { - _ = f.Close() - return fmt.Errorf("write staged plugin: %w", err) - } - if err := f.Close(); err != nil { - return fmt.Errorf("close staged plugin: %w", err) - } - return nil -} - // WorktreeMountDir is the fixed container path where a task's worktree is // bind-mounted. archie-agent uses this path directly rather than the host // path archied's worktree.Manager reports -- the two processes see the same @@ -141,12 +113,11 @@ func StagePlugin(dir, name string, source []byte) error { const WorktreeMountDir = "/data/worktree" // Persistent storage paths share the per-repository volume so session output, -// project memory, and staged plugins survive individual task containers. +// and project memory survive individual task containers. const ( PersistentMountDir = "/data/repo" SessionPath = PersistentMountDir + "/session.jsonl" MemoryPath = PersistentMountDir + "/memory.jsonl" - PluginsDir = PersistentMountDir + "/plugins" ) // MCPNPMCacheMountDir is where the npm cache for npx MCP servers is mounted