A self-organizing Obsidian vault that gives AI coding agents persistent memory.
TypeScript ai-agentsclaude-codecodex-cligemini-cliknowledge-managementobsidianobsidian-vaultpersistent-memorysecond-braintemplate
feat: recall says when a memory has a corrected version it cannot serve
Brenno Ferrarifd440b009df6
diff --git a/.claude/scripts/lib/mcp-server.ts b/.claude/scripts/lib/mcp-server.tsindex 24aa3f1..7b6c290 100644--- a/.claude/scripts/lib/mcp-server.ts+++ b/.claude/scripts/lib/mcp-server.ts@@ -268,6 +268,11 @@ export function createHandlers(deps: ServerDeps): Handlers {m.facets.platforms.length ? `platforms: ${m.facets.platforms.join(", ")}` : null,m.facets.date ? `as of ${m.facets.date}` : null,m.facets.superseded_by.length ? `SUPERSEDED by ${m.facets.superseded_by.join("; ")}` : null,+ // Named per entry rather than only in the footer, because a caller+ // quoting one memory out of five needs to know THIS one has a+ // corrected twin — a footer applies to the response, not to the line+ // being copied.+ m.facets.promoted ? `promoted to ${m.facets.promoted}` : null,m.why ? `why: ${m.why}` : null,].filter(Boolean);// Body headings are demoted so the only `##` lines in the response are@@ -278,6 +283,28 @@ export function createHandlers(deps: ServerDeps): Handlers {return `## ${m.title ?? "(untitled)"}\n${m.rel}\n(${facets.join(" · ")})\n\n${body}`;});+ // What a promoted entry costs the reader, said once, at the bottom.+ //+ // `recall` reads only the memory root; `search` and `expand` see+ // everything but. So a promoted lesson exists in two places and this+ // caller can only reach one of them — the raw capture, which may predate a+ // correction that was swept through the promoted version. Silence here+ // would present the older text as the current answer.+ //+ // This does not serve the `brain/` note (an ordinary note declares no+ // scope, so returning one would discard the boundary the memory layer+ // enforces). It names it, which is what a caller needs to ask for it by+ // path or to weigh what it just read.+ const promoted = shown.filter((m) => m.facets.promoted);+ if (promoted.length) {+ lines.push(+ `\n---\n${promoted.length} of these ${promoted.length === 1 ? "has" : "have"} been promoted into the vault's \`brain/\` notes, ` ++ `named above. **The promoted note wins on any conflict** — it is the corrected, correction-swept version, ` ++ `and what you are reading here is the capture as first written. This surface cannot serve it; ` ++ `ask a vault session, or request the note by path, before relying on a detail that looks wrong.`,+ );+ }+if (explain && result.withheld.length) {// Counts and reasons only. Naming a withheld memory would put another// project's material into this caller's context — the noise the scopediff --git a/.claude/scripts/lib/memory-recall.ts b/.claude/scripts/lib/memory-recall.tsindex 529c5d1..a306e42 100644--- a/.claude/scripts/lib/memory-recall.ts+++ b/.claude/scripts/lib/memory-recall.ts@@ -43,6 +43,23 @@ export interface Facets {readonly session: string | null;readonly superseded_by: string[];readonly source: string | null;+ /**+ * The `brain/` note this capture was promoted into, if any.+ *+ * `recall` reads only the memory root and `search`/`expand` see everything+ * but, so the two surfaces are disjoint: a promoted lesson exists twice, and+ * a foreign repo can only ever reach this copy. That copy is the raw capture,+ * which may predate a correction the promoted version has already had swept+ * through it.+ *+ * Serving the `brain/` note through `recall` is the real fix and is not this:+ * an ordinary note declares no `scope` or `projects`, so returning one would+ * either discard the boundary the memory layer exists to enforce or require+ * reach metadata to survive promotion. That work is tracked, and until it+ * lands the honest interim is to say the corrected version exists and name+ * it, rather than to serve a raw capture as though nothing had superseded it.+ */+ readonly promoted: string | null;}export interface Caller {@@ -120,6 +137,7 @@ export function facetsOf(fm: Record<string, unknown> | null | undefined): Facetssession: str(fm?.session),superseded_by: list(fm?.superseded_by),source: str(fm?.source),+ promoted: str(fm?.promoted),};}diff --git a/.claude/scripts/tests/memory-recall.test.ts b/.claude/scripts/tests/memory-recall.test.tsindex cb0c9f4..4cc3460 100644--- a/.claude/scripts/tests/memory-recall.test.ts+++ b/.claude/scripts/tests/memory-recall.test.ts@@ -326,3 +326,34 @@ describe("reader robustness", () => {});});++// ---------------------------------------------------------------------------+// Promotion is visible to the caller (#179, partial)+// ---------------------------------------------------------------------------++describe("a promoted capture says so", () => {+ test("the marker is parsed off frontmatter", () => {+ assert.equal(facetsOf({ promoted: "brain/Gotchas - Engineering" }).promoted, "brain/Gotchas - Engineering");+ });++ test("an unpromoted capture reports null rather than a falsy string", () => {+ assert.equal(facetsOf({}).promoted, null);+ assert.equal(facetsOf({ promoted: 123 }).promoted, null, "a non-string marker is not a note name");+ });++ /**+ * Promotion must not change who can see a memory. The marker records that a+ * corrected copy exists in `brain/`; it says nothing about reach, and reading+ * it as a reach signal would silently widen or narrow the scope contract.+ */+ test("promotion does not alter visibility", () => {+ const scoped = { scope: "project", projects: ["atlas"] };+ for (const caller of Object.values(CALLERS)) {+ assert.equal(+ isVisibleTo(facetsOf({ ...scoped, promoted: "brain/Gotchas" }), caller),+ isVisibleTo(facetsOf(scoped), caller),+ "the marker must be inert to the visibility rule",+ );+ }+ });+});