feat(daemon): wire the domain/memory engine registry at boot

Completes archie-core-1786637499480 (ship the file-writing store as
the default memory engine): cfg.Memory.Engine now actually selects and
starts an engine, closing the gap the previous commit's message called
out as remaining.

setupMemoryEngine builds a domain/memory.Registry, registers
infraMemory.BuiltinEngine for "builtin" (and the empty/unconfigured
case, matching applyMemoryDefaults' resolution) rooted at
workDir/memory-engine -- separate from the legacy provider's
workDir/memory, so the two can never collide on the same files while
both exist -- starts the registry, and stops it on daemon shutdown.
cfg.Memory.Engine is already validated against the same set at config
load (configuration.validateMemory), so the switch's default case only
guards the two lists drifting apart, not live operator input.

setupMemory and setupMemoryEngine are both called through a new
setupMemoryAll from Run(), which was already at its cyclomatic
complexity budget -- a genuine grouping (both are memory-subsystem
startup), not two unrelated steps merged just to hit a number.
setupMemoryEngine deliberately does not thread Run()'s ctx through to
registry.Start, matching setupMemory's own existing choice for the same
reason (Start is a synchronous startup step, not a subscription that
needs the daemon's lifetime the way setupCurators' WakeOnPrimaryInput
does) -- also what avoids a contextcheck trip that threading ctx through
setupMemoryAll produced during development.

Not yet done: internal/memory.Manager (the live system-prompt/tool-call
path) does not read through this registry -- the two memory systems run
in parallel, per archie-core-1786637490069-11-e245c170's explicit "do
not extend the legacy system in place" scoping. That convergence is
future work, not part of this issue.
This commit is contained in:
sam committed 2026-09-02 02:44:12 +10:00
1 parent f3abcb859e
commit 538b29aa0f
2 files changed
+59 -1

No files matched your search

+58
View File
@@ -30,6 +30,7 @@ import (
"github.com/samcharles93/archie-core/internal/container"
"github.com/samcharles93/archie-core/internal/daemon"
"github.com/samcharles93/archie-core/internal/domain/curator"
domainmemory "github.com/samcharles93/archie-core/internal/domain/memory"
"github.com/samcharles93/archie-core/internal/domain/workflow"
"github.com/samcharles93/archie-core/internal/domain/workflow/skillbuild"
"github.com/samcharles93/archie-core/internal/domain/workintake"
@@ -40,6 +41,7 @@ import (
"github.com/samcharles93/archie-core/internal/infrastructure/configuration"
"github.com/samcharles93/archie-core/internal/infrastructure/configuration/overlay"
"github.com/samcharles93/archie-core/internal/infrastructure/eventbus/nats"
infraMemory "github.com/samcharles93/archie-core/internal/infrastructure/memory"
"github.com/samcharles93/archie-core/internal/infrastructure/modelcatalog"
"github.com/samcharles93/archie-core/internal/logging"
"github.com/samcharles93/archie-core/internal/memory"
@@ -125,6 +127,7 @@ type boot struct {
worktreeGrants *worktreerpc.Grants
identityRunners []*daemon.IdentityRunner
memManager *memory.Manager
memEngines *domainmemory.Registry
curatorRegistry *curator.Registry
curatorRuntime *curator.Runtime
guardrails *tools.GuardrailEngine
@@ -756,6 +759,61 @@ func (b *boot) setupMemory() error {
return nil
}
// setupMemoryEngine wires the domain/memory engine family
// (archie-core-1786637499161-356-e424e40d), separate from and not yet
// consulted by the legacy memory manager set up in setupMemory above.
// cfg.Memory.Engine is validated at config load
// (configuration.validateMemory) against the same set this switch covers,
// so an unrecognised value cannot reach here -- this only guards against
// the two lists drifting apart.
//
// Rooted at workDir/memory-engine, a directory separate from the legacy
// provider's workDir/memory, so the two paths can never collide on the
// same files while both exist.
func (b *boot) setupMemoryEngine() error {
cfg, log := b.cfg, b.log
registry := domainmemory.NewRegistry(domainmemory.Registrar{})
switch cfg.Memory.Engine {
case infraMemory.EngineName, "":
root := filepath.Join(cfg.WorkDir, "memory-engine")
if err := registry.Register(infraMemory.NewBuiltinEngine(root, 0)); err != nil {
return fmt.Errorf("register memory engine %q: %w", infraMemory.EngineName, err)
}
default:
return fmt.Errorf("memory.engine %q has no registered implementation", cfg.Memory.Engine)
}
// Not b's own ctx: matches setupMemory's identical choice just above,
// and Start here is a synchronous startup step, not a subscription
// that needs to live and later be cancelled with the daemon's context
// the way setupCurators' WakeOnPrimaryInput does.
if err := registry.Start(context.Background()); err != nil {
return fmt.Errorf("start memory engine registry: %w", err)
}
b.memEngines = registry
b.addCleanup(func() {
shutdownCtx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
if err := registry.Stop(shutdownCtx); err != nil {
log.Error("memory engine registry shutdown", "err", err)
}
})
log.Info("memory engine started", "engine", cfg.Memory.Engine)
return nil
}
// setupMemoryAll runs both memory setup phases -- the legacy manager and
// the new engine family -- as one step. Kept as a single call from Run()
// rather than two: they are always run together and Run() is already at
// its cyclomatic complexity budget.
func (b *boot) setupMemoryAll() error {
if err := b.setupMemory(); err != nil {
return err
}
return b.setupMemoryEngine()
}
// setupCurators wires the curator engine family. The registry owns
// curator registration, lifecycle and shutdown ordering. The runtime
// loop (archie-core-89x) and the reference curators (archie-core-i7i,
+1 -1
View File
@@ -367,7 +367,7 @@ func Run() int {
if err := b.registerNATSRPC(); err != nil {
return 1
}
if err := b.setupMemory(); err != nil {
if err := b.setupMemoryAll(); err != nil {
return 1
}
b.setupCurators(ctx)