feat(config): config surface for memory engine selection

Part of archie-core-1786637490043 (config surface for memory engine
selection and settings).

config.MemoryConfig gets an Engine field selecting among the
domain/memory engine family, plus toml tags on every field -- Provider,
ProviderConfig, and SessionTTL had none before, yaml/json only, which
didn't match repo convention.

Engine and Provider are kept as two separate fields rather than one:
they select between two different mechanisms (the new engine family vs.
the legacy external-provider path, archie-core-1786637499161-356-e424e40d.1),
and conflating them would mean a value meant for one silently getting
read by the other once both are wired.

applyMemoryDefaults resolves an absent engine to "builtin" so
unconfigured and explicitly-builtin are the same state everywhere after
defaulting. validateMemory rejects an unrecognised engine name in the
same style as forge.type's existing validation -- named constant list,
"%w: field %q (want %s)" shape, wired into the same validate() chain.
config.example.toml documents the new field.

Not yet wired to anything: nothing reads cfg.Memory.Engine at daemon
boot yet to actually select and start an engine through
domain/memory.Registry. That's bootstrap wiring, tracked as the
remaining half of archie-core-1786637499480 (ship the builtin store as
the default engine).
This commit is contained in:
sam committed 2026-09-02 02:40:10 +10:00
1 parent 4252897fa8
commit be03844df8
6 files changed
+104 -8

No files matched your search

+9 -5
View File
@@ -206,13 +206,17 @@ listen = "127.0.0.1:8484"
# level = "info" # "debug" | "info" | "warn" | "error"
# quiet = false # true suppresses stderr once a file is configured
# The built-in file-backed memory provider (MEMORY.md + USER.md under
# The built-in file-backed memory engine (MEMORY.md + USER.md under
# work_dir) is always on -- nothing here is required to get memory at all.
# [memory] exists to register an EXTERNAL provider alongside it, but as of
# this writing that wiring (memory.Manager.RegisterExternal) is not called
# anywhere in cmd/archied, so setting this section currently has no effect.
# Left here so the schema is documented, not because it does anything yet.
# engine selects among the domain/memory engine family; "builtin" (the
# default, same as leaving it unset) is the only one implemented so far.
# provider is a separate, older mechanism: an external provider identifier
# for internal/memory.Manager.RegisterExternal. As of this writing that
# wiring is not called anywhere in cmd/archied, so setting provider
# currently has no effect -- left here so the schema is documented, not
# because it does anything yet.
# [memory]
# engine = "builtin" # "builtin" is the only engine implemented so far
# provider = "" # external provider identifier; currently unwired
# session_ttl = "0s"
# [memory.provider_config]
+11 -3
View File
@@ -285,9 +285,17 @@ func (d Dispatch) LabelValues() []string {
// MemoryConfig holds memory provider configuration.
type MemoryConfig struct {
Provider string `yaml:"provider" json:"provider"`
ProviderConfig map[string]string `yaml:"provider_config" json:"provider_config"`
SessionTTL Duration `yaml:"session_ttl" json:"session_ttl"`
// Engine selects among the domain/memory engine family
// (internal/domain/memory). Empty resolves to "builtin", the
// file-writing store under work_dir -- the same behaviour as an
// absent [memory] section entirely.
Engine string `toml:"engine" yaml:"engine" json:"engine"`
// Provider is the legacy external-provider identifier consumed by
// internal/memory.Manager.RegisterExternal, a separate, older
// mechanism than Engine. See archie-core-1786637499161-356-e424e40d.1.
Provider string `toml:"provider" yaml:"provider" json:"provider"`
ProviderConfig map[string]string `toml:"provider_config" yaml:"provider_config" json:"provider_config"`
SessionTTL Duration `toml:"session_ttl" yaml:"session_ttl" json:"session_ttl"`
}
// MCPServer describes one MCP server connection.
@@ -67,6 +67,17 @@ func (l *Loader) applyDefaults(cfg *config.Config) {
applyToolPolicyDefaults(cfg)
applyCaptureDefaults(cfg)
applyNATSDefaults(cfg)
applyMemoryDefaults(cfg)
}
// applyMemoryDefaults fills an absent engine choice with the builtin
// engine, so "nothing configured" and "explicitly builtin" are the same
// resolved state everywhere after this point -- validateMemory and every
// later reader see one value, not two that happen to mean the same thing.
func applyMemoryDefaults(cfg *config.Config) {
if cfg.Memory.Engine == "" {
cfg.Memory.Engine = memoryEngineBuiltin
}
}
// applyCaptureDefaults fills the webhook capture endpoint's settings. See
@@ -129,3 +129,21 @@ func TestApplyCaptureDefaultsLeavesExplicitValuesAlone(t *testing.T) {
t.Errorf("Capture.RateBurst = %d, want unchanged 9", cfg.Capture.RateBurst)
}
}
func TestApplyMemoryDefaultsFillsAbsentEngineWithBuiltin(t *testing.T) {
cfg := &config.Config{}
applyMemoryDefaults(cfg)
if cfg.Memory.Engine != memoryEngineBuiltin {
t.Errorf("Memory.Engine = %q, want %q", cfg.Memory.Engine, memoryEngineBuiltin)
}
}
func TestApplyMemoryDefaultsLeavesExplicitEngineAlone(t *testing.T) {
cfg := &config.Config{Memory: config.MemoryConfig{Engine: "honcho"}}
applyMemoryDefaults(cfg)
if cfg.Memory.Engine != "honcho" {
t.Errorf("Memory.Engine = %q, want unchanged %q", cfg.Memory.Engine, "honcho")
}
}
@@ -23,6 +23,11 @@ const (
dispatchTriggerAssignee = "assignee"
dispatchTriggerLabel = "label"
dispatchTriggerEither = "either"
// memoryEngineBuiltin is the only domain/memory engine implemented so
// far (internal/infrastructure/memory.BuiltinEngine). Extend
// memoryEngines, not this list of one, as further engines land.
memoryEngineBuiltin = "builtin"
)
var (
@@ -30,6 +35,7 @@ var (
dispatchTriggers = []string{dispatchTriggerAssignee, dispatchTriggerLabel, dispatchTriggerEither}
natsModes = []string{config.NATSModeEmbedded, config.NATSModeExternal}
forgeIntakes = []string{config.ForgeIntakePoll, config.ForgeIntakeWebhook, config.ForgeIntakeBoth}
memoryEngines = []string{memoryEngineBuiltin}
)
// Validate runs the same checks Loader applies before accepting a config,
@@ -78,9 +84,26 @@ func validate(cfg *config.Config) error {
if err := validateContainers(cfg); err != nil {
return err
}
if err := validateMemory(cfg); err != nil {
return err
}
return validateCapture(cfg)
}
// validateMemory rejects an engine name outside memoryEngines. Empty is
// valid input to Validate (applyDefaults resolves it to memoryEngineBuiltin
// before this runs on the real load path); it is not "unknown" so it does
// not error here.
func validateMemory(cfg *config.Config) error {
if cfg.Memory.Engine == "" {
return nil
}
if !oneOf(cfg.Memory.Engine, memoryEngines) {
return fmt.Errorf("%w: memory.engine %q (want %s)", ErrInvalidInput, cfg.Memory.Engine, list(memoryEngines))
}
return nil
}
// validateCapture rejects negative capture settings. applyDefaults fills
// every zero value with a positive default, so this only fires on an
// explicit negative value -- which would make time.Duration/AddDate math
@@ -3,6 +3,7 @@ package configuration
import (
"errors"
"os"
"strings"
"testing"
"time"
@@ -137,6 +138,21 @@ func TestValidate_RejectsTheSameProblemsAsLoaderLoad(t *testing.T) {
},
wantErr: true,
},
{
name: "unrecognised memory.engine",
mutate: func(cfg *config.Config) { cfg.Memory.Engine = "not-a-real-engine" },
wantErr: true,
},
{
name: "recognised memory.engine",
mutate: func(cfg *config.Config) { cfg.Memory.Engine = "builtin" },
wantErr: false,
},
{
name: "empty memory.engine is not unrecognised",
mutate: func(cfg *config.Config) { cfg.Memory.Engine = "" },
wantErr: false,
},
{
name: "negative capture.retention",
mutate: func(cfg *config.Config) { cfg.Capture.Retention = config.Duration(-time.Hour) },
@@ -324,3 +340,19 @@ type = "none"
t.Fatalf("Loader.File(equivalent config on disk) = %v, want nil", err)
}
}
// TestValidateMemoryNamesTheValidSet pins the AC this satisfies: an
// unknown memory.engine is rejected with a clear error naming the valid
// set, in the same style forge.type already uses.
func TestValidateMemoryNamesTheValidSet(t *testing.T) {
cfg := minimalValidConfig()
cfg.Memory.Engine = "not-a-real-engine"
err := validateMemory(&cfg)
if !errors.Is(err, ErrInvalidInput) {
t.Fatalf("validateMemory(unknown engine) = %v, want wrapping ErrInvalidInput", err)
}
if got, want := err.Error(), `memory.engine "not-a-real-engine" (want builtin)`; !strings.Contains(got, want) {
t.Errorf("error text = %q, want it to contain %q", got, want)
}
}