A self-organizing Obsidian vault that gives AI coding agents persistent memory.
TypeScript ai-agentsclaude-codecodex-cligemini-cliknowledge-managementobsidianobsidian-vaultpersistent-memorysecond-braintemplate
fix: keep the engine's own tree out of the vault listing (#165)
Brenno Ferrari78282de2f7ce
diff --git a/.claude/scripts/lib/active-hygiene.ts b/.claude/scripts/lib/active-hygiene.tsindex 93adacf..8cc279e 100644--- a/.claude/scripts/lib/active-hygiene.ts+++ b/.claude/scripts/lib/active-hygiene.ts@@ -43,6 +43,7 @@ import {extractFrontmatterField,isInfraFilename,isMarkdownFilename,+ MACHINERY_DIRS,} from "./session-start.ts";const ACTIVE_REL = "work/active";@@ -279,19 +280,10 @@ export function isMonolithExempt(filename: string): boolean {return filename.includes("Archive");}-// Never walked for oversize: machinery and non-note trees.-const OVERSIZE_SKIP_DIRS = new Set([- ".git",- ".obsidian",- ".claude",- ".codex",- ".gemini",- ".github",- ".shardmind",- ".qmd",- "node_modules",- "templates",-]);+// Never walked for oversize: machinery (shared with the SessionStart+// listing, so the two can't drift — see MACHINERY_DIRS) plus `templates/`,+// whose files are scaffold rather than notes.+const OVERSIZE_SKIP_DIRS = new Set([...MACHINERY_DIRS, "templates"]);// Recursively collect .md files under a directory, returning paths relative// to `root`. Tolerates a missing directory (returns []). Shared by everydiff --git a/.claude/scripts/lib/session-start.ts b/.claude/scripts/lib/session-start.tsindex 029f68e..a5548b2 100644--- a/.claude/scripts/lib/session-start.ts+++ b/.claude/scripts/lib/session-start.ts@@ -291,6 +291,38 @@ export function isSkippedPath();}+/**+ * Root-level directories that hold machinery, never vault notes: VCS+ * internals, editor and agent config, the ShardMind engine's own tree,+ * installed dependencies.+ *+ * Shared because two consumers of the same idea drifted apart. The oversize+ * scan already knew the full set while the SessionStart listing skipped only+ * a four-entry subset, so an *installed* vault walked `.shardmind/` and+ * injected the engine's cached template copy plus every pre-update backup+ * snapshot as if they were the user's notes (#156). One list, so the next+ * machinery directory is hidden from both the moment it is added here.+ *+ * Callers append their own list-specific entries rather than editing this+ * one: `thinking/` is hidden from the listing but still size-scanned, and+ * `templates/` is the reverse. Only what is machinery for BOTH belongs here.+ *+ * Note `.github` earns its own entry — `isSkippedPath` matches on segment+ * boundaries, so `.git` deliberately does not cover it.+ */+export const MACHINERY_DIRS: readonly string[] = [+ ".git",+ ".github",+ ".obsidian",+ ".claude",+ ".claude-plugin",+ ".codex",+ ".gemini",+ ".shardmind",+ ".qmd",+ "node_modules",+];+/*** Find the closing `---` delimiter of a YAML frontmatter block. The input* is assumed to start with `---` (caller checks). Returns the index of thediff --git a/.claude/scripts/session-start.ts b/.claude/scripts/session-start.tsindex aa3cc20..2319299 100644--- a/.claude/scripts/session-start.ts+++ b/.claude/scripts/session-start.ts@@ -29,6 +29,7 @@ import {formatActiveWork,formatRecentChanges,isSkippedPath,+ MACHINERY_DIRS,extractFrontmatterField,formatBrainIndex,stripFrontmatter,@@ -410,12 +411,9 @@ function activeWork(): string {return formatActiveWork(files, 10);}-const SKIP_PREFIXES: readonly string[] = [- ".git",- ".obsidian",- "thinking",- ".claude",-];+// Machinery (shared with the oversize scan) plus `thinking/` — scratchpads+// are real notes, just not orientation material for the listing.+const SKIP_PREFIXES: readonly string[] = [...MACHINERY_DIRS, "thinking"];// Dirs that collapse to one count line regardless of size (#107): the// archive is orientation noise whether it holds 3 notes or 300 — Glob ordiff --git a/.claude/scripts/tests/session-start.test.ts b/.claude/scripts/tests/session-start.test.tsindex 044e664..2341852 100644--- a/.claude/scripts/tests/session-start.test.ts+++ b/.claude/scripts/tests/session-start.test.ts@@ -29,6 +29,7 @@ import {formatActiveWork,formatRecentChanges,isSkippedPath,+ MACHINERY_DIRS,extractFrontmatterField,formatBrainIndex,stripFrontmatter,@@ -159,6 +160,27 @@ describe("session-start entry — env export cannot be hand-rolled", () => {);});+ // SKIP_PREFIXES is module-private and the entry runs on import, so the+ // wiring can only be pinned at the source level. Without this, #156+ // regresses silently: MACHINERY_DIRS keeps its entries and its own tests+ // keep passing while the listing walks a hardcoded list again.+ const SKIP_DEF = /const SKIP_PREFIXES[^=]*=\s*\[\s*\.\.\.MACHINERY_DIRS\s*,/;++ test("builds SKIP_PREFIXES from the shared machinery list (#156)", () => {+ assert.match(+ entry,+ SKIP_DEF,+ "the listing walk must spread MACHINERY_DIRS, not re-list dirs by hand",+ );+ });++ test("GUARD IS NOT VACUOUS — the pattern rejects a hand-listed set", () => {+ // The exact pre-#156 definition, which is what let .shardmind through.+ const regression =+ 'const SKIP_PREFIXES: readonly string[] = [\n\t".git",\n\t".obsidian",\n\t"thinking",\n\t".claude",\n];';+ assert.doesNotMatch(regression, SKIP_DEF, "guard must reject the old literal");+ });+// A guard that cannot fail is worse than no guard: it reads as coverage// while proving nothing. These assert the patterns above actually fire on// the regressions they exist to catch, including the exact pre-#145 line.@@ -370,6 +392,51 @@ describe("isSkippedPath", () => {});});+describe("MACHINERY_DIRS", () => {+ // The listing walk is filesystem-level and does not read .gitignore, so+ // the engine's own tree has to be skipped by name.+ test("skips the ShardMind engine tree an installed vault carries (#156)", () => {+ // The cached template copy and every pre-update backup snapshot —+ // engine artifacts that outnumbered real notes 3:1 on a v7.0.1 install.+ assert.equal(+ isSkippedPath(".shardmind/templates/CLAUDE.md", MACHINERY_DIRS),+ true,+ );+ assert.equal(+ isSkippedPath(+ ".shardmind/backups/update-2026-07-01T00:00:00Z/work/Index.md",+ MACHINERY_DIRS,+ ),+ true,+ );+ assert.equal(isSkippedPath(".shardmind", MACHINERY_DIRS), true);+ });++ test("skips .github, which the segment boundary excludes from .git", () => {+ assert.equal(+ isSkippedPath(".github/pull_request_template.md", MACHINERY_DIRS),+ true,+ );+ });++ test("leaves user content alone", () => {+ for (const p of [+ "work/active/Note.md",+ "brain/Patterns.md",+ "templates/Work Note.md", // scaffold, but the listing does show it+ ]) {+ assert.equal(isSkippedPath(p, MACHINERY_DIRS), false);+ }+ });++ test("holds only what is machinery for BOTH consumers", () => {+ // `thinking/` and `templates/` are each skipped by exactly one+ // consumer, so neither belongs in the shared list.+ assert.equal(MACHINERY_DIRS.includes("thinking"), false);+ assert.equal(MACHINERY_DIRS.includes("templates"), false);+ });+});+describe("extractFrontmatterField", () => {test("extracts double-quoted string value", () => {const content = '---\ndescription: "hello world"\ntags:\n - brain\n---\n\n# body';