feat(brain): seed MEMORY.md files only
Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
f4a3b79d1a
commit
cff7a90dfb
2 changed files with 42 additions and 14 deletions
|
|
@ -4,6 +4,7 @@ package agentic
|
|||
|
||||
import (
|
||||
"context"
|
||||
iofs "io/fs"
|
||||
"sort"
|
||||
|
||||
core "dappco.re/go/core"
|
||||
|
|
@ -11,7 +12,7 @@ import (
|
|||
|
||||
const brainSeedMemoryDefaultAgent = "virgil"
|
||||
|
||||
const brainSeedMemoryDefaultPath = "~/.claude/projects/*/memory/"
|
||||
const brainSeedMemoryDefaultPath = "~/.claude/projects"
|
||||
|
||||
type BrainSeedMemoryInput struct {
|
||||
WorkspaceID int
|
||||
|
|
@ -89,7 +90,7 @@ func (s *PrepSubsystem) cmdBrainSeedMemoryLike(options core.Options, commandName
|
|||
}
|
||||
|
||||
if output.Files == 0 {
|
||||
core.Print(nil, "No markdown files found in: %s", output.Path)
|
||||
core.Print(nil, "No MEMORY.md files found in: %s", output.Path)
|
||||
return core.Result{Value: output, OK: true}
|
||||
}
|
||||
|
||||
|
|
@ -174,10 +175,10 @@ func brainSeedMemoryScanPath(path string) string {
|
|||
if trimmed == "" {
|
||||
return brainSeedMemoryExpandHome(brainSeedMemoryDefaultPath)
|
||||
}
|
||||
if fs.IsFile(trimmed) || core.HasSuffix(trimmed, ".md") {
|
||||
if fs.IsFile(trimmed) {
|
||||
return trimmed
|
||||
}
|
||||
return core.JoinPath(trimmed, "*.md")
|
||||
return trimmed
|
||||
}
|
||||
|
||||
func brainSeedMemoryExpandHome(path string) string {
|
||||
|
|
@ -192,10 +193,39 @@ func brainSeedMemoryFiles(scanPath string) []string {
|
|||
return nil
|
||||
}
|
||||
if fs.IsFile(scanPath) {
|
||||
return []string{scanPath}
|
||||
if core.PathBase(scanPath) == "MEMORY.md" {
|
||||
return []string{scanPath}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
files := core.PathGlob(scanPath)
|
||||
var files []string
|
||||
var walk func(string)
|
||||
|
||||
walk = func(dir string) {
|
||||
r := fs.List(dir)
|
||||
if !r.OK {
|
||||
return
|
||||
}
|
||||
|
||||
entries, ok := r.Value.([]iofs.DirEntry)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
for _, entry := range entries {
|
||||
next := core.JoinPath(dir, entry.Name())
|
||||
if entry.IsDir() {
|
||||
walk(next)
|
||||
continue
|
||||
}
|
||||
if core.PathBase(next) == "MEMORY.md" {
|
||||
files = append(files, next)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
walk(scanPath)
|
||||
sort.Strings(files)
|
||||
return files
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ func TestBrainSeedMemory_CmdBrainSeedMemory_Good(t *testing.T) {
|
|||
home := t.TempDir()
|
||||
t.Setenv("CORE_HOME", home)
|
||||
|
||||
projectsDir := core.JoinPath(home, ".claude", "projects")
|
||||
memoryDir := core.JoinPath(home, ".claude", "projects", "-Users-snider-Code-eaas", "memory")
|
||||
require.True(t, fs.EnsureDir(memoryDir).OK)
|
||||
require.True(t, fs.Write(core.JoinPath(memoryDir, "MEMORY.md"), "# Memory\n\n## Architecture\nUse Core.Process().\n\n## Decision\nPrefer named actions.").OK)
|
||||
|
|
@ -42,19 +43,19 @@ func TestBrainSeedMemory_CmdBrainSeedMemory_Good(t *testing.T) {
|
|||
|
||||
result := subsystem.cmdBrainSeedMemory(core.NewOptions(
|
||||
core.Option{Key: "workspace", Value: "42"},
|
||||
core.Option{Key: "path", Value: memoryDir},
|
||||
core.Option{Key: "path", Value: projectsDir},
|
||||
core.Option{Key: "agent", Value: "virgil"},
|
||||
))
|
||||
|
||||
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, core.JoinPath(memoryDir, "*.md"), output.Path)
|
||||
require.Len(t, bodies, 3)
|
||||
assert.Equal(t, projectsDir, output.Path)
|
||||
require.Len(t, bodies, 2)
|
||||
|
||||
assert.Equal(t, float64(42), bodies[0]["workspace_id"])
|
||||
assert.Equal(t, "virgil", bodies[0]["agent_id"])
|
||||
|
|
@ -65,9 +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_CmdBrainIngest_Good(t *testing.T) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue