Part of archie-core-1786637499206 (skill curator reference implementation), under the curator engine epic. docs/prds/skill-curator.md records the design decision this needed before coding (no settled design existed for what "review, prune, and improve skill definitions" means as concrete Pass() behavior): v1 is mechanical validation and safe whitespace normalization only. No LLM-authored rewrites of skill content, no automatic deletion -- an autonomous process editing or deleting a user's skill has no undo path today, and the epic's actual purpose for this issue is proving the curator contract holds for a second, structurally different consumer (files-as-skills vs. observations-as-memory), not solving "what makes a skill good." internal/infrastructure/skillcurator/store.go: a curator.SkillStore implementation over one root's .agents/skills/*/SKILL.md files. Not internal/skill.Discover directly -- Discover parses every skill up front and fails the WHOLE call if any one of them doesn't parse (correct for "load the catalog to boot the daemon", wrong for "review each skill and report what's wrong with it individually"). This store lists/reads raw bytes per skill; the curator itself parses each one so one bad skill's parse failure becomes one Action, not an aborted pass. internal/infrastructure/skillcurator/skillcurator.go: the CuratorEngine. Check is a cheap directory-listing bool. Pass classifies each skill into exactly one of: skill.invalid (frontmatter parse failure, left untouched), skill.incomplete (missing required name/description, untouched), skill.normalized (trailing whitespace / missing final newline, written back), or nothing (already clean). Manifest declares only Skills -- no Tools, no MemoryEngine -- since nothing here needs either. Wired into internal/app/archied/bootstrap.go:setupCurators, rooted the same way loadWorkflows already resolves skillsBase (cfg.SkillsDir falling back to cfg.WorkDir) -- one local root, not the full multi-root catalog a chat turn reads. Skills is now a shared registrar-level service (alongside Events/MemoryEngines), narrowed out of a curator's view by registry.filter when undeclared, same as every other capability. task check is green (full Go suite + dashboard tests); go test ./... is green.
164 lines
5.1 KiB
Go
164 lines
5.1 KiB
Go
package skillcurator
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"strings"
|
|
"time"
|
|
|
|
"github.com/samcharles93/archie-core/internal/domain/curator"
|
|
"github.com/samcharles93/archie-core/internal/skill"
|
|
)
|
|
|
|
// Name is the identifier this curator registers under.
|
|
const Name = "skill"
|
|
|
|
// DefaultInterval is the check-in cadence used when nothing more specific
|
|
// configures one. No config surface for per-curator intervals exists yet
|
|
// (this is the first real curator registered); this constant is the
|
|
// obvious place a future one would read from.
|
|
const DefaultInterval = time.Hour
|
|
|
|
const (
|
|
// ActionInvalid records a skill whose SKILL.md failed to parse.
|
|
ActionInvalid = "skill.invalid"
|
|
// ActionIncomplete records a skill that parsed but is missing a
|
|
// required frontmatter field.
|
|
ActionIncomplete = "skill.incomplete"
|
|
// ActionNormalized records a skill whose content was rewritten by
|
|
// whitespace normalization.
|
|
ActionNormalized = "skill.normalized"
|
|
)
|
|
|
|
// Curator implements domain/curator.CuratorEngine. See
|
|
// docs/prds/skill-curator.md for what a pass does and why: mechanical
|
|
// validation and safe whitespace normalization only -- no LLM-authored
|
|
// rewrites, no deletion.
|
|
type Curator struct {
|
|
interval time.Duration
|
|
host curator.Registrar
|
|
}
|
|
|
|
// New builds a skill curator that checks in every interval.
|
|
func New(interval time.Duration) *Curator {
|
|
return &Curator{interval: interval}
|
|
}
|
|
|
|
func (c *Curator) Name() string { return Name }
|
|
func (c *Curator) Version() string { return "1" }
|
|
|
|
func (c *Curator) Manifest() curator.Manifest {
|
|
return curator.Manifest{Interval: c.interval, Skills: true}
|
|
}
|
|
|
|
func (c *Curator) Bind(host curator.Registrar) { c.host = host }
|
|
|
|
func (c *Curator) Start(context.Context) error { return nil }
|
|
|
|
func (c *Curator) Health(context.Context) curator.Health {
|
|
return curator.Health{Status: curator.HealthHealthy}
|
|
}
|
|
|
|
func (c *Curator) Stop(context.Context) error { return nil }
|
|
|
|
// Check reports whether there is anything to review. Cheap by
|
|
// construction: a directory listing, no model calls, no parsing.
|
|
func (c *Curator) Check(ctx context.Context) (bool, error) {
|
|
refs, err := c.host.Skills.List(ctx)
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
return len(refs) > 0, nil
|
|
}
|
|
|
|
// Pass reviews every skill currently on disk. There is no per-skill
|
|
// "already reviewed" state: each pass re-checks everything, which is
|
|
// cheap (file reads, no model calls) and errs toward catching a
|
|
// regression over missing one. See docs/prds/skill-curator.md for the
|
|
// exact classification rules.
|
|
func (c *Curator) Pass(ctx context.Context, in curator.PassInput) (curator.PassResult, error) {
|
|
refs, err := c.host.Skills.List(ctx)
|
|
if err != nil {
|
|
return curator.PassResult{}, err
|
|
}
|
|
|
|
var actions []curator.Action
|
|
for _, ref := range refs {
|
|
acts, err := c.reviewOne(ctx, ref.Name)
|
|
if err != nil {
|
|
return curator.PassResult{}, fmt.Errorf("skill %q: %w", ref.Name, err)
|
|
}
|
|
actions = append(actions, acts...)
|
|
}
|
|
return curator.PassResult{Actions: actions}, nil
|
|
}
|
|
|
|
// reviewOne classifies a single skill and, for a normalizable one,
|
|
// writes the cleaned content back. It never returns more than one
|
|
// Action: a parse failure and a missing field can't both be reported for
|
|
// the same skill in the same pass (a Frontmatter that failed to parse
|
|
// has no fields to check), and a normalization is reported once even
|
|
// though it may have fixed multiple lines.
|
|
func (c *Curator) reviewOne(ctx context.Context, name string) ([]curator.Action, error) {
|
|
sk, err := c.host.Skills.Read(ctx, name)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
fm, _, parseErr := skill.Parse([]byte(sk.Content))
|
|
if parseErr != nil {
|
|
return []curator.Action{{
|
|
Type: ActionInvalid,
|
|
Detail: name,
|
|
Reason: parseErr.Error(),
|
|
}}, nil
|
|
}
|
|
|
|
if missing := missingField(fm); missing != "" {
|
|
return []curator.Action{{
|
|
Type: ActionIncomplete,
|
|
Detail: name,
|
|
Reason: "missing " + missing,
|
|
}}, nil
|
|
}
|
|
|
|
normalized := normalizeWhitespace(sk.Content)
|
|
if normalized == sk.Content {
|
|
return nil, nil
|
|
}
|
|
if err := c.host.Skills.Write(ctx, curator.Skill{Name: name, Content: normalized}); err != nil {
|
|
return nil, err
|
|
}
|
|
return []curator.Action{{
|
|
Type: ActionNormalized,
|
|
Detail: name,
|
|
Reason: "trailing whitespace or missing final newline",
|
|
}}, nil
|
|
}
|
|
|
|
// missingField returns the name of the first required frontmatter field
|
|
// fm lacks, or "" if both are present. Order (name before description)
|
|
// only affects which single reason is reported when both are missing;
|
|
// either is worth flagging on its own.
|
|
func missingField(fm *skill.Frontmatter) string {
|
|
if strings.TrimSpace(fm.Name) == "" {
|
|
return "name"
|
|
}
|
|
if strings.TrimSpace(fm.Description) == "" {
|
|
return "description"
|
|
}
|
|
return ""
|
|
}
|
|
|
|
// normalizeWhitespace trims trailing whitespace from every line and
|
|
// ensures the content ends in exactly one newline. It never touches
|
|
// leading whitespace (meaningful in YAML frontmatter and Markdown list
|
|
// nesting) or blank-line structure.
|
|
func normalizeWhitespace(content string) string {
|
|
lines := strings.Split(content, "\n")
|
|
for i, line := range lines {
|
|
lines[i] = strings.TrimRight(line, " \t")
|
|
}
|
|
return strings.TrimRight(strings.Join(lines, "\n"), "\n") + "\n"
|
|
}
|