From 547a481d7b6cce64d6fd911f599b87799acdd4e5 Mon Sep 17 00:00:00 2001 From: Virgil Date: Thu, 2 Apr 2026 03:51:47 +0000 Subject: [PATCH] feat(brain): seed MEMORY.md files only Co-Authored-By: Virgil --- pkg/agentic/brain_seed_memory.go | 29 +++++++++++++++++---------- pkg/agentic/brain_seed_memory_test.go | 14 ++++++------- 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/pkg/agentic/brain_seed_memory.go b/pkg/agentic/brain_seed_memory.go index c771572..8f6020d 100644 --- a/pkg/agentic/brain_seed_memory.go +++ b/pkg/agentic/brain_seed_memory.go @@ -54,10 +54,14 @@ func (s *PrepSubsystem) cmdBrainSeedMemory(options core.Options) core.Result { // // )) func (s *PrepSubsystem) cmdBrainIngest(options core.Options) core.Result { - return s.cmdBrainSeedMemoryLike(options, "brain ingest", "agentic.cmdBrainIngest") + return s.cmdBrainSeedMemoryLikeMode(options, "brain ingest", "agentic.cmdBrainIngest", false) } func (s *PrepSubsystem) cmdBrainSeedMemoryLike(options core.Options, commandName string, errorLabel string) core.Result { + return s.cmdBrainSeedMemoryLikeMode(options, commandName, errorLabel, true) +} + +func (s *PrepSubsystem) cmdBrainSeedMemoryLikeMode(options core.Options, commandName string, errorLabel string, memoryFilesOnly bool) core.Result { input := BrainSeedMemoryInput{ WorkspaceID: parseIntString(optionStringValue(options, "workspace", "workspace_id", "workspace-id", "_arg")), AgentID: optionStringValue(options, "agent", "agent_id", "agent-id"), @@ -75,7 +79,7 @@ func (s *PrepSubsystem) cmdBrainSeedMemoryLike(options core.Options, commandName input.Path = brainSeedMemoryDefaultPath } - result := s.brainSeedMemory(s.commandContext(), input) + result := s.brainSeedMemory(s.commandContext(), input, memoryFilesOnly) if !result.OK { err := commandResultError(errorLabel, result) core.Print(nil, "error: %v", err) @@ -102,13 +106,13 @@ func (s *PrepSubsystem) cmdBrainSeedMemoryLike(options core.Options, commandName return core.Result{Value: output, OK: true} } -func (s *PrepSubsystem) brainSeedMemory(ctx context.Context, input BrainSeedMemoryInput) core.Result { +func (s *PrepSubsystem) brainSeedMemory(ctx context.Context, input BrainSeedMemoryInput, memoryFilesOnly bool) core.Result { if s.brainKey == "" { return core.Result{Value: core.E("agentic.brainSeedMemory", "no brain API key configured", nil), OK: false} } scanPath := brainSeedMemoryScanPath(input.Path) - files := brainSeedMemoryFiles(scanPath) + files := brainSeedMemoryFiles(scanPath, memoryFilesOnly) output := BrainSeedMemoryOutput{ Success: true, WorkspaceID: input.WorkspaceID, @@ -188,7 +192,7 @@ func brainSeedMemoryExpandHome(path string) string { return path } -func brainSeedMemoryFiles(scanPath string) []string { +func brainSeedMemoryFiles(scanPath string, memoryFilesOnly bool) []string { if scanPath == "" { return nil } @@ -211,7 +215,7 @@ func brainSeedMemoryFiles(scanPath string) []string { walk = func(dir string) { if fs.IsFile(dir) { - if core.PathBase(dir) == "MEMORY.md" { + if brainSeedMemoryFile(dir, memoryFilesOnly) { add(dir) } return @@ -237,14 +241,14 @@ func brainSeedMemoryFiles(scanPath string) []string { walk(next) continue } - if brainSeedMemoryFile(next) { + if brainSeedMemoryFile(next, memoryFilesOnly) { add(next) } } } if fs.IsFile(scanPath) { - if brainSeedMemoryFile(scanPath) { + if brainSeedMemoryFile(scanPath, memoryFilesOnly) { add(scanPath) } sort.Strings(files) @@ -254,7 +258,7 @@ func brainSeedMemoryFiles(scanPath string) []string { if brainSeedMemoryHasGlobMeta(scanPath) { for _, path := range core.PathGlob(scanPath) { if fs.IsFile(path) { - if brainSeedMemoryFile(path) { + if brainSeedMemoryFile(path, memoryFilesOnly) { add(path) } continue @@ -272,8 +276,11 @@ func brainSeedMemoryHasGlobMeta(path string) bool { return core.Contains(path, "*") || core.Contains(path, "?") || core.Contains(path, "[") } -func brainSeedMemoryFile(path string) bool { - return core.PathBase(path) == "MEMORY.md" || core.Lower(core.PathExt(path)) == ".md" +func brainSeedMemoryFile(path string, memoryFilesOnly bool) bool { + if memoryFilesOnly { + return core.PathBase(path) == "MEMORY.md" + } + return core.Lower(core.PathExt(path)) == ".md" } func brainSeedMemorySections(content string) []brainSeedMemorySection { diff --git a/pkg/agentic/brain_seed_memory_test.go b/pkg/agentic/brain_seed_memory_test.go index b55d41b..dd05326 100644 --- a/pkg/agentic/brain_seed_memory_test.go +++ b/pkg/agentic/brain_seed_memory_test.go @@ -50,12 +50,12 @@ func TestBrainSeedMemory_CmdBrainSeedMemory_Good(t *testing.T) { require.True(t, result.OK) output, ok := result.Value.(BrainSeedMemoryOutput) require.True(t, ok) - assert.Equal(t, 2, output.Files) - assert.Equal(t, 3, output.Imported) + assert.Equal(t, 1, output.Files) + assert.Equal(t, 2, output.Imported) assert.Equal(t, 0, output.Skipped) assert.Equal(t, false, output.DryRun) assert.Equal(t, projectsDir, output.Path) - require.Len(t, bodies, 3) + require.Len(t, bodies, 2) assert.Equal(t, float64(42), bodies[0]["workspace_id"]) assert.Equal(t, "virgil", bodies[0]["agent_id"]) @@ -66,8 +66,6 @@ func TestBrainSeedMemory_CmdBrainSeedMemory_Good(t *testing.T) { assert.Equal(t, "decision", bodies[1]["type"]) assert.Equal(t, []any{"memory-import"}, bodies[1]["tags"]) - assert.Equal(t, "convention", bodies[2]["type"]) - assert.Equal(t, []any{"notes", "memory-import"}, bodies[2]["tags"]) } func TestBrainSeedMemory_CmdBrainSeedMemory_Good_GlobPath(t *testing.T) { @@ -158,7 +156,7 @@ func TestBrainSeedMemory_CmdBrainIngest_Good(t *testing.T) { assert.Equal(t, "architecture", bodies[0]["type"]) } -func TestBrainSeedMemory_CmdBrainSeedMemory_Good_DirectMarkdownFile(t *testing.T) { +func TestBrainSeedMemory_CmdBrainIngest_Good_DirectMarkdownFile(t *testing.T) { home := t.TempDir() t.Setenv("CORE_HOME", home) @@ -183,7 +181,7 @@ func TestBrainSeedMemory_CmdBrainSeedMemory_Good_DirectMarkdownFile(t *testing.T brainKey: "brain-key", } - result := subsystem.cmdBrainSeedMemory(core.NewOptions( + result := subsystem.cmdBrainIngest(core.NewOptions( core.Option{Key: "workspace", Value: "42"}, core.Option{Key: "path", Value: memoryFile}, )) @@ -259,7 +257,7 @@ func TestBrainSeedMemory_CmdBrainSeedMemory_Ugly_PartialImportFailure(t *testing WorkspaceID: 42, AgentID: "virgil", Path: memoryDir, - }) + }, true) require.True(t, result.OK) output, ok := result.Value.(BrainSeedMemoryOutput)