- Introduce `-config-overlay` flag and `config.LoadOverlay()` to merge a base config with an overlay file, only overriding fields the overlay sets. This enables docker-compose to mount the base config from the host and apply only deployment-specific overrides. - Create `internal/natsrpc` package with reusable NATS request/reply primitives (Envelope, Client, Call, RegisterAll, Respond). Migrate storerpc, worktreerpc, and forgerpc to use it, eliminating duplicated marshal/unmarshal and error handling. - Create `internal/yaegiutil` package with shared interpreter construction (stdlib + extra symbols), generic export resolution (Resolve), and panic recovery (Safe). Migrate all Yaegi-based surfaces (gate scripts, daemon plugins, skill plugins, workflow stages, skill scripts) to use it, reducing boilerplate and centralizing panic safety. - Simplify `config.docker.toml` to contain only overlay fields (paths, container config) and remove the duplicated repos list – the base config is now the single source of truth. - Update docker-compose.yml to pass both -config and -config-overlay flags and mount the base config from the host. - Add tests for LoadOverlay, DockerConfigOverlaysExampleConfig, Envelope, and yaegiutil utilities.
78 lines
2.2 KiB
Go
78 lines
2.2 KiB
Go
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
|
|
}
|
|
|
|
// DiscoverPlugins scans dir/.agents/skills/<skillName>/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) {
|
|
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)
|
|
}
|
|
|
|
var names []string
|
|
for _, e := range entries {
|
|
if !e.IsDir() && strings.HasSuffix(e.Name(), ".go") {
|
|
names = append(names, e.Name())
|
|
}
|
|
}
|
|
sort.Strings(names)
|
|
|
|
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
|
|
}
|