Files
archie/internal/skillscript/yaegi.go
T
sam a9641276e1 feat: parse SKILL.md frontmatter, inject skill body into agent context
Adds internal/skill package with YAML frontmatter parsing and skill
discovery from .agents/skills/ (agentskills.io spec convention).

- Frontmatter struct with name, description, version, metadata.archie
- Parse() extracts YAML frontmatter delimited by --- markers
- Discover() scans .agents/skills/*/SKILL.md (follows wfeval pattern)
- LoadBody() for single-skill lazy loading

Skills moved from .archie/skills/ to .agents/skills/ per the
agentskills.io specification.

Wiring: TaskContext.SkillBody field, lazy-loaded on first agent stage
from worktree. When non-empty, prepended to Mission as "Follow these
project-specific guidelines" context. Hardcoded Mission templates stay
(task-specific formatting). Backward compatible: empty when no skill
found.
2026-07-22 02:23:20 +10:00

54 lines
1.8 KiB
Go

// Package skillscript runs skill-bundled Go scripts (.agents/skills/<skill>/scripts/*.go)
// 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"
"fmt"
"os"
"github.com/traefik/yaegi/interp"
"github.com/traefik/yaegi/stdlib"
"github.com/traefik/yaegi/stdlib/unrestricted"
)
// 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.
func Run(path string) (output string, err error) {
if _, statErr := os.Stat(path); statErr != nil {
return "", statErr
}
defer func() {
if r := recover(); r != nil {
err = fmt.Errorf("yaegi: %s panicked: %v", path, r)
}
}()
var buf bytes.Buffer
i := interp.New(interp.Options{Stdout: &buf, Stderr: &buf})
if err := i.Use(stdlib.Symbols); err != nil {
return "", fmt.Errorf("yaegi: load stdlib symbols: %w", err)
}
if err := i.Use(unrestricted.Symbols); err != nil {
return "", fmt.Errorf("yaegi: load unrestricted symbols: %w", 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
}