diff --git a/config.example.toml b/config.example.toml index 3546330c4..c2023f597 100644 --- a/config.example.toml +++ b/config.example.toml @@ -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] diff --git a/internal/config/config.go b/internal/config/config.go index c017dc180..ec309363f 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -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. diff --git a/internal/infrastructure/configuration/defaults.go b/internal/infrastructure/configuration/defaults.go index e8f80e492..5d1cf168c 100644 --- a/internal/infrastructure/configuration/defaults.go +++ b/internal/infrastructure/configuration/defaults.go @@ -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 diff --git a/internal/infrastructure/configuration/defaults_test.go b/internal/infrastructure/configuration/defaults_test.go index a3dae7858..480fb37d4 100644 --- a/internal/infrastructure/configuration/defaults_test.go +++ b/internal/infrastructure/configuration/defaults_test.go @@ -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") + } +} diff --git a/internal/infrastructure/configuration/validate.go b/internal/infrastructure/configuration/validate.go index 7a3c73fe3..92a37d56d 100644 --- a/internal/infrastructure/configuration/validate.go +++ b/internal/infrastructure/configuration/validate.go @@ -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 diff --git a/internal/infrastructure/configuration/validate_test.go b/internal/infrastructure/configuration/validate_test.go index 41dcc0873..fa735c689 100644 --- a/internal/infrastructure/configuration/validate_test.go +++ b/internal/infrastructure/configuration/validate_test.go @@ -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) + } +}