feat(brain): structured wing/hall taxonomy + obsidian-compatible layout
Adds a two-dimensional address (wing, hall) to brain notes. A wing is a
topic domain (e.g. jepa-fx, hyperguild); a hall is one of a closed
vocabulary of memory types (facts, decisions, failures, hypotheses,
sources). Notes route to brain/wiki/<wing>/<hall>/<slug>.md with
wing/hall/created_at YAML frontmatter, making the directory a valid
Obsidian vault.
Changes:
- new package ingestion/internal/brain (NotePath, ValidHalls, Sanitise,
BuildWingIndex, BuildAllWingIndexes)
- api.WriteNote refactored to WriteNoteOptions; wing+hall routes to
brain/wiki/, otherwise falls back to brain/knowledge/ (legacy)
- search.Query → QueryOptions with optional Wing/Hall filtering; Result
carries wing/hall extracted from frontmatter or path segments
- MCP tools brain_write and brain_query gain optional wing/hall params
(hall enum-validated); new brain_index tool regenerates _index.md MOC
- POST /index REST endpoint mirrors brain_index
- brain_write auto-rebuilds the wing's _index.md after a wing+hall write
- scripts/migrate-brain-halls.sh migrates flat brain/wiki/{concepts,entities}/
into the new layout (dry-run by default, --commit applies)
All existing tests pass; new tests cover wing/hall write routing, scope
filtering, invalid hall rejection, _index.md generation, and migration
script paths.
Closes hyperguild#1.
This commit is contained in:
@@ -27,7 +27,7 @@ func TestSearch_ReturnsMatchingPages(t *testing.T) {
|
||||
0o644,
|
||||
))
|
||||
|
||||
results, err := search.Query(dir, "retry transient", 5)
|
||||
results, err := search.Query(dir, search.QueryOptions{Query: "retry transient", Limit: 5})
|
||||
require.NoError(t, err)
|
||||
require.Len(t, results, 1)
|
||||
assert.Equal(t, "knowledge/retry-logic.md", results[0].Path)
|
||||
@@ -36,6 +36,49 @@ func TestSearch_ReturnsMatchingPages(t *testing.T) {
|
||||
assert.Contains(t, results[0].Excerpt, "Retry")
|
||||
}
|
||||
|
||||
func TestSearch_WingHallScoping(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
for _, p := range []struct{ rel, body string }{
|
||||
{"wiki/jepa-fx/decisions/val-vol.md", "---\nwing: jepa-fx\nhall: decisions\n---\nval-vol-r2 keyword.\n"},
|
||||
{"wiki/jepa-fx/facts/architecture.md", "---\nwing: jepa-fx\nhall: facts\n---\nval-vol-r2 keyword in facts.\n"},
|
||||
{"wiki/hyperguild/decisions/routing.md", "---\nwing: hyperguild\nhall: decisions\n---\nval-vol-r2 reference.\n"},
|
||||
{"knowledge/loose.md", "---\n---\nval-vol-r2 in knowledge.\n"},
|
||||
} {
|
||||
full := filepath.Join(dir, p.rel)
|
||||
require.NoError(t, os.MkdirAll(filepath.Dir(full), 0o755))
|
||||
require.NoError(t, os.WriteFile(full, []byte(p.body), 0o644))
|
||||
}
|
||||
|
||||
// No filter: walk both knowledge/ and wiki/ — all 4 match.
|
||||
got, err := search.Query(dir, search.QueryOptions{Query: "val-vol-r2", Limit: 10})
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, got, 4)
|
||||
|
||||
// Wing scope: 2 jepa-fx hits, no hyperguild, no knowledge.
|
||||
got, err = search.Query(dir, search.QueryOptions{Query: "val-vol-r2", Limit: 10, Wing: "jepa-fx"})
|
||||
require.NoError(t, err)
|
||||
require.Len(t, got, 2)
|
||||
for _, r := range got {
|
||||
assert.Equal(t, "jepa-fx", r.Wing)
|
||||
}
|
||||
|
||||
// Wing+Hall scope: 1 hit.
|
||||
got, err = search.Query(dir, search.QueryOptions{Query: "val-vol-r2", Limit: 10, Wing: "jepa-fx", Hall: "decisions"})
|
||||
require.NoError(t, err)
|
||||
require.Len(t, got, 1)
|
||||
assert.Equal(t, "jepa-fx", got[0].Wing)
|
||||
assert.Equal(t, "decisions", got[0].Hall)
|
||||
assert.Equal(t, "wiki/jepa-fx/decisions/val-vol.md", got[0].Path)
|
||||
|
||||
// Invalid hall rejected.
|
||||
_, err = search.Query(dir, search.QueryOptions{Query: "x", Wing: "jepa-fx", Hall: "garbage"})
|
||||
require.Error(t, err)
|
||||
|
||||
// Hall without wing rejected.
|
||||
_, err = search.Query(dir, search.QueryOptions{Query: "x", Hall: "facts"})
|
||||
require.Error(t, err)
|
||||
}
|
||||
|
||||
func TestSearch_RespectsLimit(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
require.NoError(t, os.MkdirAll(filepath.Join(dir, "knowledge"), 0o755))
|
||||
@@ -46,7 +89,7 @@ func TestSearch_RespectsLimit(t *testing.T) {
|
||||
0o644,
|
||||
))
|
||||
}
|
||||
results, err := search.Query(dir, "retry", 3)
|
||||
results, err := search.Query(dir, search.QueryOptions{Query: "retry", Limit: 3})
|
||||
require.NoError(t, err)
|
||||
assert.LessOrEqual(t, len(results), 3)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user