A self-organizing Obsidian vault that gives AI coding agents persistent memory.
TypeScript ai-agentsclaude-codecodex-cligemini-cliknowledge-managementobsidianobsidian-vaultpersistent-memorysecond-braintemplate
fix: health reports promotions that name a note but serve nothing (#192)
Brenno Ferrari756cb47ad557
diff --git a/.claude/scripts/lib/active-hygiene.ts b/.claude/scripts/lib/active-hygiene.tsindex ddc43cf..0ca7c8d 100644--- a/.claude/scripts/lib/active-hygiene.ts+++ b/.claude/scripts/lib/active-hygiene.ts@@ -39,6 +39,7 @@import { readdirSync, readFileSync, statSync, type Dirent } from "node:fs";import { join } from "node:path";import { escapeRegex } from "./regex.ts";+import { parsePromotedMarker, type PromotedRef } from "./memory-promoted.ts";import {extractFrontmatterField,isInfraFilename,@@ -98,6 +99,18 @@ export type InboxPressure = {readonly oldestDays: number;};+/**+ * The memory inbox additionally reports how many promotions are DECORATIVE.+ *+ * A separate type rather than an optional field on `InboxPressure`: the+ * meetings inbox has no promotion concept, and an optional field shared by two+ * producers is how one of them silently stops populating it.+ */+export type MemoryInboxPressure = InboxPressure & {+ /** Promoted captures whose marker carries no anchor, so nothing is servable. */+ readonly namedOnly: number;+};+export type ActiveHygieneReport = {// Vault-relative paths (e.g. "work/active/Foo.md").readonly completedInActive: readonly string[];@@ -105,7 +118,7 @@ export type ActiveHygieneReport = {readonly oversizedNotes: readonly OversizedNote[];readonly openLoops: readonly OpenLoop[];readonly inboxPressure: InboxPressure | null;- readonly memoryInbox: InboxPressure | null;+ readonly memoryInbox: MemoryInboxPressure | null;};// ---------------------------------------------------------------------------@@ -497,15 +510,29 @@ export function parseMemoryRoot(manifestJson: string | null): string {* pressure. This is the only edit a tool may make to a capture: the body, the* declared reach and the confidence are never touched.*/-function isPromoted(root: string, rel: string): boolean {+function promotionOf(root: string, rel: string): PromotedRef | null {let head: string;try {head = readFileSync(join(root, rel), "utf-8").slice(0, 2_000);} catch {- return false;+ return null;}const fm = head.match(/^---\n([\s\S]*?)\n---/);- return fm ? /^promoted:\s*\S/m.test(fm[1] ?? "") : false;+ if (!fm) return null;+ // `parsePromotedMarker`, not a local regex. This was the third independent+ // parser of one format — `facetsOf` and `parsePromotedMarker` being the other+ // two — and the local one answered only "is there a marker", which is why the+ // count could not tell a servable promotion from a decorative one. (#183)+ const line = (fm[1] ?? "").match(/^promoted:\s*(.+)$/m);+ return line ? parsePromotedMarker(unquoteScalar(line[1]!.trim())) : null;+}++/** Undo the quoting the capture writer applies, so the parser sees the path. */+function unquoteScalar(s: string): string {+ if (s.length >= 2 && ((s.startsWith('"') && s.endsWith('"')) || (s.startsWith("'") && s.endsWith("'")))) {+ return s.slice(1, -1);+ }+ return s;}/**@@ -524,14 +551,23 @@ function isPromoted(root: string, rel: string): boolean {* never fall, because the correct way to drain this inbox leaves every file* exactly where it is.*/-function findMemoryInbox(root: string, relDir: string, nowMs: number): InboxPressure | null {+function findMemoryInbox(root: string, relDir: string, nowMs: number): MemoryInboxPressure | null {let count = 0;let oldestDays = 0;+ let namedOnly = 0;for (const rel of walkMarkdown(root, relDir)) {// Same reasoning as the meetings scaffold (#155): a shipped README is not// a capture, and counting it makes the flag permanently unclearable.if (/\/readme\.md$/i.test(rel)) continue;- if (isPromoted(root, rel)) continue;+ const promoted = promotionOf(root, rel);+ if (promoted) {+ // Counted, never demanded. The inbox flag still falls on a bare marker —+ // forcing an anchor to clear hygiene would push anchors onto captures+ // whose promoted block is not fit to leave the vault. Reporting the split+ // makes the difference legible without making it mandatory. (#183)+ if (promoted.anchor === null) namedOnly++;+ continue;+ }let mtimeMs: number;try {mtimeMs = statSync(join(root, rel)).mtimeMs;@@ -542,7 +578,13 @@ function findMemoryInbox(root: string, relDir: string, nowMs: number): InboxPresconst ageDays = Math.floor((nowMs - mtimeMs) / 86_400_000);if (ageDays > oldestDays) oldestDays = ageDays;}- return count > 0 ? { count, oldestDays } : null;+ // `count > 0` ALONE, deliberately. `namedOnly` never revives the flag: a store+ // whose captures are all promoted with bare markers is correctly drained, and+ // gating on it would rebuild the permanently-unclearable inbox that #155 fixed+ // and that the note on `promotionOf` exists to prevent. The split is a DETAIL+ // of a flag already firing; `health` reports it unconditionally, because health+ // is a report rather than a pressure. (#183)+ return count > 0 ? { count, oldestDays, namedOnly } : null;}// ---------------------------------------------------------------------------@@ -678,6 +720,14 @@ export function formatActiveHygiene(report: ActiveHygieneReport): string[] {lines.push(`⚠️ ${memoryInbox.count} cross-repo memory capture(s) awaiting review (oldest ${memoryInbox.oldestDays}d). Promote a durable one by COPYING it into the right brain/ note and adding \`promoted: "brain/Note#^om-a1b2c3"\` to the capture's frontmatter, pointing at the block you copied — the entry stays, because recall reaches brain/ only THROUGH a capture, so deleting it takes the lesson away from every repo that cannot read brain/ at all. The ANCHOR is what lets recall serve the corrected text; a bare \`promoted: <note>\` clears this count but serves nothing.`,);+ // Evidence for the sentence above, from this vault rather than in the+ // abstract. Told once the flag is already firing — it never raises one of+ // its own, because a bare marker is a legitimate promotion. (#183)+ if (memoryInbox.namedOnly > 0) {+ lines.push(+ ` ${memoryInbox.namedOnly} already-promoted capture(s) here carry a bare marker, so recall serves none of them. Re-point one by adding the anchor of the block you copied.`,+ );+ }}return lines;diff --git a/.claude/scripts/lib/mcp-server.ts b/.claude/scripts/lib/mcp-server.tsindex 29ae62d..34bb060 100644--- a/.claude/scripts/lib/mcp-server.ts+++ b/.claude/scripts/lib/mcp-server.ts@@ -34,7 +34,12 @@ import { captureNote, findToolMarkup } from "./mcp-capture.ts";import { semanticMemoryOrder } from "./mcp-memory-bridge.ts";import { TOOLS } from "./mcp-tools.ts";import { recallFrom, readMemories, type MemoryEntry } from "./memory-recall.ts";-import { resolvePromoted, type PromotedResolution, type NoteCache } from "./memory-promoted.ts";+import {+ resolvePromotedRef,+ auditPromotions,+ type PromotedResolution,+ type NoteCache,+} from "./memory-promoted.ts";import { createMemoryIndex } from "./memory-index.ts";import { validateMemory, writeMemory, renderMemory, resolveLinks, neutralizeWikilinks } from "./memory-write.ts";import { findSimilar } from "./memory-similarity.ts";@@ -303,7 +308,7 @@ export function createHandlers(deps: ServerDeps): Handlers {// made between two recalls is never served stale.const noteCache: NoteCache = new Map();const rows = shown.map((m) => {- const promo = resolvePromoted(ctx.vaultRoot, policy, m.facets.promoted, noteCache);+ const promo = resolvePromotedRef(ctx.vaultRoot, policy, m.facets.promoted, noteCache);// A marker that exists but does not PARSE — a stray control character,// say — resolves to null, which would otherwise render as "not promoted// at all". Refusing to echo the string is right; refusing to mention@@ -315,7 +320,7 @@ export function createHandlers(deps: ServerDeps): Handlers {// `resolveExposedNote` is not cached at all, so every promoted row paid// a second realpath and a second `isPrivate` read. Measured at 25 rows// over a 20k-line note: 1.27ms/row became 2.25ms/row.- return { m, promo, unparsed: Boolean(m.facets.promoted) && promo === null };+ return { m, promo, unparsed: m.facets.promotedRaw !== null && promo === null };});const promotions = rows.map((r) => r.promo).filter((p): p is PromotedResolution => p !== null);@@ -693,7 +698,17 @@ export function createHandlers(deps: ServerDeps): Handlers {// health when a memory is missing, so this is routinely the FIRST call a// server serves — and "3 memories / 0 entries held" reads as a parse// failure when nothing is wrong.- const parsed = storeEntries().length;+ const entries = storeEntries();+ const parsed = entries.length;+ // Resolved HERE because this is the only surface a vault session reads.+ // `recall` has had the diagnostic since v8.3.0 and shows it to a foreign+ // repo, which cannot see `brain/` at all and so cannot fix a stale anchor+ // — the report was reaching the one party powerless to act on it. (#183)+ const promo = auditPromotions(+ ctx.vaultRoot,+ policy,+ entries.map((m) => ({ path: m.rel, facets: m.facets })),+ );const names = new Set(visibleFiles(ctx.vaultRoot, policy).map((f) => f.label));if (who.project) names.add(who.project);const h = health(ctx.vaultRoot, ctx.manifest, {@@ -726,8 +741,40 @@ export function createHandlers(deps: ServerDeps): Handlers {// Reporting the day's usage is what stands in for a limit: the answer to// "where did that go" has to exist somewhere, and this is where.`Reasoning today: ${reasonUsage(ctx.vaultRoot, ctx.manifest, now().toISOString().slice(0, 10), sumAuditField)}`,+ // Stated whenever anything is promoted, because "named only" is the+ // DEFAULT outcome of promoting by hand and is otherwise invisible: the+ // hygiene flag falls either way, so without this line a store where no+ // promotion serves anything looks identical to one where they all do.+ ...(promo.served + promo.namedOnly > 0+ ? [+ `Promotions: ${promo.served} servable, ${promo.namedOnly} named only${+ promo.namedOnly > 0 ? " (add an anchor — `promoted: \"brain/Note#^om-a1b2c3\"` — to serve the corrected text)" : ""+ }`,+ ]+ : []),"",- h.warnings.length ? `Warnings:\n${h.warnings.map((w) => `- ${w}`).join("\n")}` : "No warnings.",+ (() => {+ // A broken promotion is a warning; a bare marker never is. Serving is a+ // separate, deliberate act, and demanding an anchor would push one onto+ // captures whose promoted block is not fit to leave the vault.+ const mine = [+ ...promo.broken.map(+ (b) =>+ `promotion in ${b.path} names ${b.note} but ${+ b.status === "stale-anchor"+ ? "its anchor no longer resolves — the block was renamed, moved or removed"+ : b.status === "not-exposed"+ ? "that note is outside the exposed roots"+ : "that note is missing or unreadable"+ }. recall falls back to the raw capture body.`,+ ),+ ...promo.unparsed.map(+ (p) => `promotion marker in ${p} could not be parsed — it is invisible to every consumer.`,+ ),+ ];+ const all = [...h.warnings, ...mine];+ return all.length ? `Warnings:\n${all.map((w) => `- ${w}`).join("\n")}` : "No warnings.";+ })(),...(h.notes.length ? ["", `Notes:\n${h.notes.map((n) => `- ${n}`).join("\n")}`] : []),].join("\n");}diff --git a/.claude/scripts/lib/memory-promoted.ts b/.claude/scripts/lib/memory-promoted.tsindex 709d890..ef2960a 100644--- a/.claude/scripts/lib/memory-promoted.ts+++ b/.claude/scripts/lib/memory-promoted.ts@@ -472,7 +472,22 @@ export function resolvePromoted(raw: unknown,cache: NoteCache = new Map(),): PromotedResolution | null {- const ref = parsePromotedMarker(raw);+ return resolvePromotedRef(vaultRoot, policy, parsePromotedMarker(raw), cache);+}++/**+ * The same resolution, for a caller holding an already-parsed marker.+ *+ * `facetsOf` parses at read time so the marker format has ONE definition (see+ * `Facets.promoted`). Re-deriving the ref here would restore the second one that+ * change exists to remove, and the two would drift the moment either is edited.+ */+export function resolvePromotedRef(+ vaultRoot: string,+ policy: ExposurePolicy,+ ref: PromotedRef | null,+ cache: NoteCache = new Map(),+): PromotedResolution | null {if (!ref) return null;if (ref.anchor === null) return { status: "no-anchor", note: ref.note };@@ -543,3 +558,80 @@ export function resolvePromoted(truncated: hit.truncated,};}++// ---------------------------------------------------------------------------+// Store-wide audit+// ---------------------------------------------------------------------------++/** One capture, as much of it as an audit needs. Structural on purpose: */+/* importing MemoryEntry would make memory-recall → memory-promoted a cycle. */+export interface PromotedAuditable {+ readonly path: string;+ readonly facets: { readonly promoted: PromotedRef | null; readonly promotedRaw: string | null };+}++/** A promotion that names a note but cannot serve it. */+export interface BrokenPromotion {+ /** Store-relative path of the CAPTURE, which is the file to edit. */+ readonly path: string;+ readonly note: string;+ readonly status: "stale-anchor" | "not-exposed" | "unreadable";+}++export interface PromotionAudit {+ /** Markers that resolve to text. */+ readonly served: number;+ /** Bare `promoted: <note>` — legitimate, and deliberately not a warning. */+ readonly namedOnly: number;+ /** Present in frontmatter, rejected by the parser. */+ readonly unparsed: readonly string[];+ readonly broken: readonly BrokenPromotion[];+}++/**+ * Resolve every promotion in the store, so the party that can FIX a broken one+ * is the party that hears about it.+ *+ * The diagnostic already existed and only the recall renderer consumed it, which+ * put it in front of the one reader who cannot act: a foreign repo sees+ * `stale-anchor` and cannot see `brain/` at all. Meanwhile a vault session edits+ * a topic note, drops a `^om-…` id, and every recall elsewhere silently+ * downgrades to the raw capture body with nobody in the vault told. (#183)+ *+ * A bare marker is NOT broken. Promotion is additive and serving is a separate,+ * deliberate act — treating "named only" as a defect would push anchors onto+ * captures whose promoted block is not fit to leave the vault, which is the+ * disclosure risk the opt-in design is careful about. It is counted, not warned.+ */+export function auditPromotions(+ vaultRoot: string,+ policy: ExposurePolicy,+ entries: readonly PromotedAuditable[],+): PromotionAudit {+ // One cache for the whole sweep: a store with forty captures promoted into+ // six topic notes reads six files, not forty. Scoped to this call for the+ // same reason the recall cache is — a correction between two health calls+ // must never be served from the earlier one.+ const cache: NoteCache = new Map();+ const broken: BrokenPromotion[] = [];+ const unparsed: string[] = [];+ let served = 0;+ let namedOnly = 0;++ for (const e of entries) {+ if (e.facets.promoted === null) {+ // Declared but unparseable — a control character, a non-string. Worth+ // naming: the marker is invisible to every consumer, so from the vault's+ // side the capture looks unpromoted while the frontmatter says otherwise.+ if (e.facets.promotedRaw !== null) unparsed.push(e.path);+ continue;+ }+ const r = resolvePromotedRef(vaultRoot, policy, e.facets.promoted, cache);+ if (r === null) continue;+ if (r.status === "served") served++;+ else if (r.status === "no-anchor") namedOnly++;+ else broken.push({ path: e.path, note: r.note, status: r.status });+ }++ return { served, namedOnly, unparsed, broken };+}diff --git a/.claude/scripts/lib/memory-recall.ts b/.claude/scripts/lib/memory-recall.tsindex a306e42..3794c3d 100644--- a/.claude/scripts/lib/memory-recall.ts+++ b/.claude/scripts/lib/memory-recall.ts@@ -26,6 +26,7 @@import { readFileSync, readdirSync, statSync, existsSync } from "node:fs";import { join } from "node:path";import { MEMORY_ROOT, MEMORY_SOURCE } from "./memory-write.ts";+import { parsePromotedMarker, type PromotedRef } from "./memory-promoted.ts";// Re-exported so a reader can take the marker from the module it reads with,// while the writer that stamps it stays the one place it is defined.@@ -52,14 +53,28 @@ export interface Facets {* 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.+ * Since v8.3.0 an ANCHORED marker closes that gap: `resolvePromotedRef` serves+ * the promoted block itself, through the capture that still declares the+ * reach. A bare `promoted: <note>` keeps the older behaviour of naming the+ * corrected version without serving it, which stays legitimate — serving is a+ * separate and deliberate act, and requiring an anchor would push one onto+ * captures whose promoted block is not fit to leave the vault.+ *+ * **Parsed here so the marker format has ONE definition.** It had three — this+ * field as a raw string, `parsePromotedMarker`, and a regex in+ * `active-hygiene.ts` — and three parsers for one format drift the moment any+ * one of them is edited. (#183)+ */+ readonly promoted: PromotedRef | null;+ /**+ * The marker exactly as written, kept because `null` above is ambiguous.+ *+ * A capture with NO marker and a capture whose marker the parser REJECTED — a+ * stray control character, a non-string — both parse to `null`, and only the+ * second is a defect worth reporting. After the parse there is nothing left to+ * tell them apart, so the raw string is carried alongside.*/- readonly promoted: string | null;+ readonly promotedRaw: string | null;}export interface Caller {@@ -137,7 +152,8 @@ 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),+ promoted: parsePromotedMarker(fm?.promoted),+ promotedRaw: str(fm?.promoted),};}diff --git a/.claude/scripts/tests/active-hygiene.test.ts b/.claude/scripts/tests/active-hygiene.test.tsindex 42eccfb..53ceb5b 100644--- a/.claude/scripts/tests/active-hygiene.test.ts+++ b/.claude/scripts/tests/active-hygiene.test.ts@@ -329,6 +329,75 @@ describe("scanActiveHygiene — detectors", () => {}});+ /**+ * The gradient the count creates (#183).+ *+ * Clearing the flag and SERVING the lesson are different achievements, and a+ * bare marker buys the first for less work than the second. Hygiene reports+ * the split so the cheaper form is visible — but it must never gate on it, or+ * the flag stops being able to reach zero.+ */+ test("a bare marker is counted as named-only, and never revives the flag", () => {+ const solo = mkdtempSync(join(tmpdir(), "active-hygiene-memories-namedonly-"));+ try {+ mkdirSync(join(solo, "memories/2026/07"), { recursive: true });+ writeFileSync(+ join(solo, "memories/2026/07/bare.md"),+ '---\nscope: general\npromoted: "brain/Gotchas"\n---\n\n# bare\n',+ );+ writeFileSync(+ join(solo, "memories/2026/07/anchored.md"),+ '---\nscope: general\npromoted: "brain/Gotchas#^om-a1b2c3"\n---\n\n# anchored\n',+ );++ // Both are promoted, so there is no pressure at all — the flag reaches+ // zero exactly as before, which is the invariant #155 established.+ assert.equal(scanActiveHygiene(solo, NOW, DEFAULTS).memoryInbox, null);++ // Add one UNpromoted capture: the flag fires, and the split rides on it+ // as a detail rather than as a second warning of its own.+ writeFileSync(join(solo, "memories/2026/07/fresh.md"), "---\nscope: general\n---\n\n# fresh\n");+ const inbox = scanActiveHygiene(solo, NOW, DEFAULTS).memoryInbox;+ assert.equal(inbox?.count, 1, "only the unpromoted capture is pressure");+ assert.equal(inbox?.namedOnly, 1, "the bare marker counts, the anchored one does not");++ const text = formatActiveHygiene(scanActiveHygiene(solo, NOW, DEFAULTS)).join("\n");+ assert.match(text, /1 already-promoted capture\(s\) here carry a bare marker/);+ } finally {+ rmSync(solo, { recursive: true, force: true });+ }+ });++ test("quoting does not change the verdict — the writer stamps a YAML scalar", () => {+ // The capture writer emits `promoted: 'brain/X#^id'`, and hand-promotion+ // writes all three forms below. The count must not depend on which.+ //+ // This does NOT prove the quote stripping in `promotionOf`: an unstripped+ // `"brain/G#^om-a1"` still splits at the `#` and still reads as anchored,+ // so the verdict is identical either way. The stripping is there so the+ // returned ref's `note` is a real path rather than `"brain/G` — which no+ // caller reads today and every caller would assume tomorrow. What this+ // guards is the count, across the forms actually written.+ const solo = mkdtempSync(join(tmpdir(), "active-hygiene-memories-quoted-"));+ try {+ mkdirSync(join(solo, "memories/2026/07"), { recursive: true });+ writeFileSync(join(solo, "memories/2026/07/x.md"), "---\nscope: general\n---\n\n# x\n");+ for (const marker of ["'brain/G#^om-a1'", '"brain/G#^om-a1"', "brain/G#^om-a1"]) {+ writeFileSync(+ join(solo, "memories/2026/07/q.md"),+ `---\nscope: general\npromoted: ${marker}\n---\n\n# q\n`,+ );+ assert.equal(+ scanActiveHygiene(solo, NOW, DEFAULTS).memoryInbox?.namedOnly,+ 0,+ `anchored, however quoted: ${marker}`,+ );+ }+ } finally {+ rmSync(solo, { recursive: true, force: true });+ }+ });+test("an empty or misplaced promoted marker does not silence a capture", () => {const solo = mkdtempSync(join(tmpdir(), "active-hygiene-memories-badmark-"));try {@@ -352,7 +421,7 @@ describe("scanActiveHygiene — detectors", () => {oversizedNotes: [],openLoops: [],inboxPressure: null,- memoryInbox: { count: 4, oldestDays: 2 },+ memoryInbox: { count: 4, oldestDays: 2, namedOnly: 0 },});const text = lines.join("\n");assert.match(text, /COPYING it/);diff --git a/.claude/scripts/tests/memory-promoted.test.ts b/.claude/scripts/tests/memory-promoted.test.tsindex 64158c3..4077eba 100644--- a/.claude/scripts/tests/memory-promoted.test.ts+++ b/.claude/scripts/tests/memory-promoted.test.ts@@ -34,7 +34,9 @@ import {blockAtLines,sectionAt,resolvePromoted,+ auditPromotions,type NoteCache,+ type PromotedAuditable,} from "../lib/memory-promoted.ts";import type { ExposurePolicy } from "../lib/mcp-exposure.ts";@@ -738,3 +740,77 @@ describe("a refused marker does not probe outside the vault", () => {});});});++// ---------------------------------------------------------------------------+// The store-wide audit (#183)+// ---------------------------------------------------------------------------++/** Build the minimal shape `auditPromotions` reads, the way `facetsOf` would. */+function auditable(path: string, marker: string | null): PromotedAuditable {+ return { path, facets: { promoted: parsePromotedMarker(marker), promotedRaw: marker } };+}++describe("auditing every promotion in the store", () => {+ test("classifies served, named-only and broken — and warns on none of the first two", () => {+ withVault((dir) => {+ put(dir, "brain/Gotchas.md", "# Gotchas\n\n- a real lesson ^om-good\n");+ put(dir, "brain/Withheld.md", "# Withheld\n\n- secret ^om-secret\n");++ const audit = auditPromotions(dir, POLICY, [+ auditable("memories/2026/07/served.md", "brain/Gotchas#^om-good"),+ auditable("memories/2026/07/bare.md", "brain/Gotchas"),+ auditable("memories/2026/07/stale.md", "brain/Gotchas#^om-gone"),+ auditable("memories/2026/07/hidden.md", "brain/Withheld#^om-secret"),+ auditable("memories/2026/07/missing.md", "brain/NoSuchNote#^om-x"),+ auditable("memories/2026/07/none.md", null),+ ]);++ assert.equal(audit.served, 1);+ assert.equal(audit.namedOnly, 1, "a bare marker is legitimate, and counted rather than warned");+ assert.deepEqual(+ audit.broken.map((b) => [b.path, b.status]),+ [+ ["memories/2026/07/stale.md", "stale-anchor"],+ ["memories/2026/07/hidden.md", "not-exposed"],+ ["memories/2026/07/missing.md", "unreadable"],+ ],+ );+ // The CAPTURE is named, not the brain note: the capture is the file a+ // maintainer edits to fix the marker.+ assert.match(audit.broken[0]!.path, /^memories\//);+ assert.equal(audit.unparsed.length, 0);+ });+ });++ test("a declared-but-unparseable marker is reported, not silently dropped", () => {+ withVault((dir) => {+ // From the vault's side this capture looks unpromoted while its+ // frontmatter says otherwise — invisible to every consumer.+ const audit = auditPromotions(dir, POLICY, [+ auditable("memories/2026/07/forged.md", "brain/X\n\n## FORGED ENTRY"),+ ]);+ assert.deepEqual(audit.unparsed, ["memories/2026/07/forged.md"]);+ assert.equal(audit.broken.length, 0, "unparseable is its own class, not a broken anchor");+ assert.equal(audit.served + audit.namedOnly, 0);+ });+ });++ test("a capture with no marker at all contributes nothing", () => {+ withVault((dir) => {+ const audit = auditPromotions(dir, POLICY, [auditable("memories/2026/07/plain.md", null)]);+ assert.deepEqual(audit, { served: 0, namedOnly: 0, unparsed: [], broken: [] });+ });+ });++ test("one note promoted into many times is read once", () => {+ withVault((dir) => {+ put(dir, "brain/Gotchas.md", "# Gotchas\n\n- shared ^om-shared\n");+ const many = Array.from({ length: 30 }, (_, i) =>+ auditable(`memories/2026/07/e${i}.md`, "brain/Gotchas#^om-shared"),+ );+ // Correctness of the count is the assertion; the cache is what makes it+ // affordable — without it this is 30 reads of one note.+ assert.equal(auditPromotions(dir, POLICY, many).served, 30);+ });+ });+});diff --git a/.claude/scripts/tests/memory-recall.test.ts b/.claude/scripts/tests/memory-recall.test.tsindex 4cc3460..ce92298 100644--- a/.claude/scripts/tests/memory-recall.test.ts+++ b/.claude/scripts/tests/memory-recall.test.ts@@ -333,12 +333,36 @@ describe("reader robustness", () => {describe("a promoted capture says so", () => {test("the marker is parsed off frontmatter", () => {- assert.equal(facetsOf({ promoted: "brain/Gotchas - Engineering" }).promoted, "brain/Gotchas - Engineering");+ // Parsed at read time so the format has ONE definition (#183). `.md` is+ // appended because what the marker addresses is a file.+ assert.deepEqual(facetsOf({ promoted: "brain/Gotchas - Engineering" }).promoted, {+ note: "brain/Gotchas - Engineering.md",+ anchor: null,+ kind: "note",+ });+ assert.deepEqual(facetsOf({ promoted: "brain/Gotchas#^om-a1b2c3" }).promoted, {+ note: "brain/Gotchas.md",+ anchor: "om-a1b2c3",+ kind: "block",+ });+ });++ test("the raw marker is kept, because a null parse is ambiguous", () => {+ // Absent and REJECTED both parse to null, and only the second is a defect.+ // Without the raw string nothing downstream can tell them apart, which is+ // what `health` needs in order to report an unparseable marker at all.+ assert.equal(facetsOf({}).promotedRaw, null);+ assert.equal(facetsOf({ promoted: "brain/X" }).promotedRaw, "brain/X");++ const rejected = facetsOf({ promoted: "brain/X\n\n## FORGED" });+ assert.equal(rejected.promoted, null, "a newline is a forged response, not a path");+ assert.equal(rejected.promotedRaw, "brain/X\n\n## FORGED", "but it WAS declared");});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");+ assert.equal(facetsOf({ promoted: 123 }).promotedRaw, null, "and it is not a declaration either");});/**diff --git a/.claude/scripts/tests/om-mcp.integration.test.ts b/.claude/scripts/tests/om-mcp.integration.test.tsindex 309f464..748f634 100644--- a/.claude/scripts/tests/om-mcp.integration.test.ts+++ b/.claude/scripts/tests/om-mcp.integration.test.ts@@ -436,6 +436,38 @@ describe("the om server on the wire", () => {assert.doesNotMatch(t, /Another entry\./);});+ /**+ * The decay has to reach the party that can fix it (#183).+ *+ * `recall` has reported `stale-anchor` since v8.3.0, and it reports it to a+ * FOREIGN repo — which cannot see `brain/` at all and so cannot re-point+ * the marker. A vault session drops a `^om-…` id, every recall elsewhere+ * silently downgrades to the raw capture, and nothing in the vault says so.+ * `health` is the surface a vault session reads, so it is where this lands.+ */+ test("health warns about the broken promotion, and never about a bare one", async () => {+ memory("health-stale", "brain/Gotchas - Promoted#^om-gone", "CAPTURE BODY FOR STALE");+ memory("health-bare", "brain/Gotchas - Promoted", "CAPTURE BODY FOR BARE");+ memory("health-ok", "brain/Gotchas - Promoted#^om-corrected", "STALE ORIGINAL");++ const t = textOf(await call("tools/call", { name: "health", arguments: {} }));++ assert.match(t, /Warnings:/);+ assert.match(t, /health-stale/, "the CAPTURE is named — it is the file to edit");+ assert.match(t, /anchor no longer resolves/);+ assert.doesNotMatch(+ t,+ /health-bare/,+ "a bare marker is a legitimate promotion, never a warning",+ );++ // Counted rather than warned, so a store where nothing is servable is+ // distinguishable from one where everything is — the hygiene flag falls+ // either way, which is what made the difference invisible.+ assert.match(t, /Promotions: \d+ servable, \d+ named only/);+ assert.match(t, /add an anchor/);+ });+/*** The shapes that were served WRONG before the segmenter, over the wire.*diff --git a/ARCHITECTURE.md b/ARCHITECTURE.mdindex b50238b..7895ed7 100644--- a/ARCHITECTURE.md+++ b/ARCHITECTURE.md@@ -551,6 +551,18 @@ The audit line carries the promoted notes and their statuses. This is the only s**The residual risk, recorded rather than solved:** a promoted block can say more than the capture it came from. The capture's `scope` was declared for its own text, and once merged into a topic note the block sits beside other material. Opt-in-by-anchor is the mitigation, not a proof.+#### The incentive gradient, and who hears about decay++Opt-in has a cost that took a real vault to notice: **the cheapest way to clear the memory-inbox flag is the form that serves nothing.** Any non-empty `promoted:` drains the count, so a bare marker buys the same hygiene outcome as an anchored one for strictly less work. In a real store, 35 of 37 captures carried a marker and none carried an anchor — the serving path above was dead in production while every flag read as clean.++The fix is not to require an anchor. A bare marker is a *legitimate* promotion — it records that the lesson was copied — and forcing an anchor to clear hygiene would push anchors onto captures whose promoted block is not fit to leave the vault, which is the exact disclosure risk the paragraph above is careful about. So the gradient is made **visible** rather than mandatory:++- `health` reports `Promotions: N servable, M named only`, unconditionally. Without it a store where nothing is servable is indistinguishable from one where everything is, because the flag falls either way.+- `health` warns on genuinely **broken** promotions — a stale anchor, a withheld or missing target — and names the *capture* to edit rather than the `brain/` note, because the capture is the file that carries the marker.+- The hygiene line repeats the split only when the inbox flag is *already* firing. It never raises a flag of its own: `namedOnly` cannot revive the count, or the inbox stops being able to reach zero — the permanently-unclearable failure that additive promotion was designed around.++The diagnostic itself already existed; only `recall` consumed it, which put it in front of a foreign repo — the one party that cannot see `brain/` and therefore cannot fix anything. `health` is the surface a vault session reads, so it is where the report belongs.+### A `search` call, end to end```mermaid@@ -821,6 +833,8 @@ Every failure in this layer presents identically as **"no results"**. That is wh| a pinned `reason.model` is ignored | answers come from another model, silently | the answer names the model that actually ran, and flags the mismatch || a reasoning spawn ends early | would otherwise read as a complete answer | refused by name, with the turn count, the terminal reason and the evidence || a reasoning spawn hits the 300s timeout | looks identical to a spawn that never started | the kill signal is read, so the terminal reason is `timeout`, in the message and the log |+| a promoted anchor goes stale | recall quietly serves the raw capture instead of the corrected text | `health` names the CAPTURE to edit, and why |+| every promotion is decorative | the inbox flag clears and nothing is servable | `health` reports servable vs named-only; hygiene repeats it once the flag is already firing || the server exits mid-spawn | a session runs on with no bound and no audit line | shutdown kills every in-flight spawn || a promoted anchor no longer resolves | the capture body is served, silently older than the vault's own text | the facet line marks the anchor `STALE`; the audit line records `stale-anchor` || a promoted note is outside the exposed roots, `private`, or withheld by name | the capture body is served rather than the correction | the facet line says it is withheld; the audit line records `not-exposed` |