Files
archie/internal/domain/curator/registry.go
T
sam 6a25153659 docs(vale): reject em dashes, and remove the ones on the tree (#2149)
AGENTS.md forbids em dashes in prose, comments and user-facing strings, and
nothing checked it: Google.EmDash only flags a dash with a space on both sides,
so a bare U+2014 passed.

Archie.EmDash rejects U+2014 for Markdown, templates and Go, with a message
naming the alternatives. The 40 occurrences it finds are rewritten as a comma,
a colon, brackets or a second sentence, and scratch trees are out of scope so a
run over the repository reports on what the repository holds.
2026-11-27 19:33:06 +11:00

130 lines
4.0 KiB
Go

package curator
import (
"errors"
"time"
"github.com/samcharles93/archie-core/internal/domain/lifecycle"
)
// Registry errors.
var (
ErrDuplicate = lifecycle.ErrDuplicate
ErrStarted = lifecycle.ErrStarted
)
// Registry owns curator registration and lifecycle. A curator's failure
// affects only that curator.
type Registry struct {
*lifecycle.Registry[CuratorEngine, Registrar]
host Registrar
// activity tracks recent per-curator run history for observability.
// It has its own mutex.
activity *activityTracker
}
// NewRegistry builds the family registry. A nil Clock is replaced with the
// system clock; every other nil service is valid until a curator declares
// the capability that requires it.
func NewRegistry(host Registrar) *Registry {
if host.Clock == nil {
host.Clock = systemClock{}
}
return &Registry{
Registry: lifecycle.New[CuratorEngine, Registrar]("curator", host.Log),
host: host,
activity: newActivityTracker(),
}
}
// RecordActivity records one pass's outcome for the named curator.
func (r *Registry) RecordActivity(name string, at time.Time, actions []Action) {
r.activity.record(name, at, actions)
}
// Activity returns the named curator's recorded activity, if any has been
// recorded yet.
func (r *Registry) Activity(name string) (Activity, bool) {
return r.activity.snapshot(name)
}
// Register validates the curator's manifest and binds it to a filtered host
// view. Failures affect only that curator.
func (r *Registry) Register(c CuratorEngine) error {
if lifecycle.IsNil(c) {
return errors.New("curator: nil engine")
}
m := c.Manifest()
if err := m.Validate(); err != nil {
return err
}
if err := r.validateDeclared(m); err != nil {
return err
}
return r.Add(c, r.filter(c, m))
}
// Host returns the raw registrar bundle the registry was built with. The
// daemon itself is never part of it.
func (r *Registry) Host() Registrar {
return r.host
}
// validateDeclared enforces "only the host services a curator's declared
// shape requires": a declared capability must have a host service behind it.
// A curator can never discover the daemon or an untyped hook map here: the
// registrar is the only channel.
func (r *Registry) validateDeclared(m Manifest) error {
if len(m.Tools) > 0 && r.host.Tools == nil {
return errors.New("curator manifest: declares tools but the registrar has no ToolBuilder")
}
if m.Skills && r.host.Skills == nil {
return errors.New("curator manifest: declares the skills capability but the registrar has no SkillStore")
}
if m.MemoryEngine != "" && r.host.MemoryEngines == nil {
return errors.New("curator manifest: declares a memory engine but the registrar has no MemoryEngineSource")
}
if m.Conversations && r.host.Conversations == nil {
return errors.New("curator manifest: declares conversation history but the registrar has no ConversationSource")
}
return nil
}
// filter returns the registrar view narrowed to the curator's declared
// capabilities. Events and Clock are always present (activity must stay
// attributable and time is universal); model access is present for every
// curator whose pass calls the model (see agentic); every capability service
// is present only when declared.
func (r *Registry) filter(c CuratorEngine, m Manifest) Registrar {
v := r.host
if !agentic(c, m) {
v.LLM = nil
}
if len(m.Tools) == 0 {
v.Tools = nil
}
if !m.Skills {
v.Skills = nil
}
if m.MemoryEngine == "" {
v.MemoryEngines = nil
}
if !m.Conversations {
v.Conversations = nil
}
return v
}
// agentic reports whether the curator's pass calls the model, so the
// registrar view must keep the model runner. The definition engine always
// does, even for an instruction-only definition with no declared capability;
// any other engine is agentic only when it declares tools, skills, memory or
// conversation history.
func agentic(c CuratorEngine, m Manifest) bool {
if _, ok := c.(*DefinitionEngine); ok {
return true
}
return len(m.Tools) > 0 || m.Skills || m.MemoryEngine != "" || m.Conversations
}