A self-organizing Obsidian vault that gives AI coding agents persistent memory.
TypeScript ai-agentsclaude-codecodex-cligemini-cliknowledge-managementobsidianobsidian-vaultpersistent-memorysecond-braintemplate
fix: a memory whose title outruns the slug is linkable by its title (#226)
Brenno Ferrari45d86bd290ac
diff --git a/.claude/scripts/lib/memory-write.ts b/.claude/scripts/lib/memory-write.tsindex 2067261..eac846d 100644--- a/.claude/scripts/lib/memory-write.ts+++ b/.claude/scripts/lib/memory-write.ts@@ -555,6 +555,21 @@ export function renderMemory(value: MemoryValue, links: readonly string[] = []):`projects: ${yamlList(value.projects)}`,];if (value.platforms.length) fm.push(`platforms: ${yamlList(value.platforms)}`);+ // An alias whenever the filename cannot carry the whole title.+ //+ // `slugify` truncates at SLUG_MAX and the comment there says a long title is+ // "still fine as the H1" — true for READING, false for LINKING. Obsidian+ // resolves a link target against filenames and aliases; an H1 is never a link+ // target. So a memory whose title outran the slug could not be cited by the+ // one string anyone would naturally use: its own stated claim.+ //+ // Titles run long as a RULE rather than as an exception here, because the+ // `remember` contract asks for the lesson "stated as a claim" and a+ // claim-shaped sentence passes 60 characters more often than not.+ //+ // Emitted only when the slug actually lost something, so a short-titled+ // memory keeps the frontmatter it has always had and no existing note churns.+ if (slugify(value.title) !== value.title) fm.push(`aliases: ${yamlList([value.title])}`);fm.push(`confidence: ${value.confidence}`);if (value.claimed_confidence) fm.push(`claimed_confidence: ${value.claimed_confidence}`);// Markers make the contract operational: a Base can list every weak claim indiff --git a/.claude/scripts/tests/memory-write.test.ts b/.claude/scripts/tests/memory-write.test.tsindex f7769f1..bea6623 100644--- a/.claude/scripts/tests/memory-write.test.ts+++ b/.claude/scripts/tests/memory-write.test.ts@@ -10,6 +10,7 @@*/import { test, describe } from "node:test";+import { extractAliases, buildResolver } from "../lib/wikilinks.ts";import assert from "node:assert/strict";import { mkdtempSync, rmSync, existsSync, readFileSync, mkdirSync, writeFileSync } from "node:fs";import { tmpdir } from "node:os";@@ -639,3 +640,60 @@ describe("reachability guard", () => {}});});++/**+ * A memory has to be citable by the one string anyone would use: its own claim.+ *+ * `slugify` truncates at SLUG_MAX and its comment says a long title is "still+ * fine as the H1" — true for reading, false for LINKING. Obsidian resolves a+ * link target against filenames and aliases; an H1 is never a link target, so a+ * memory whose title outran the slug was addressable by nothing a reader would+ * naturally type. Titles run long as a rule here, because the contract asks for+ * the lesson stated as a claim.+ */+describe("a long-titled memory stays linkable by its title", () => {+ const LONG =+ "A gate can be wrong about its situation as well as its assertion, and only mutation separates the two";++ const render = (title: string): string =>+ renderMemory({+ title,+ body: "b".repeat(120),+ date: new Date(2026, 6, 26),+ scope: "general",+ projects: [],+ platforms: [],+ confidence: "inferred",+ flags: [],+ origin: null,+ downgraded_from: null,+ } as never);++ test("the title is emitted as an alias when the filename cannot carry it", () => {+ const md = render(LONG);+ assert.notEqual(slugify(LONG), LONG, "fixture must actually be truncated");+ assert.match(md, /^aliases: \[/m, "no alias emitted, so the memory is uncitable by name");+ // The property that actually matters. Asserting only that SOME alias was+ // emitted would pass against a truncated or re-quoted one, which would+ // still not resolve.+ assert.deepEqual(extractAliases(md), [LONG]);+ });++ test("a link written with the title resolves against the rendered memory", () => {+ const md = render(LONG);+ const rel = `memories/2026/07/2026-07-26 ${slugify(LONG)}.md`;+ const resolves = buildResolver([rel], new Map([[rel, extractAliases(md)]]));+ assert.equal(resolves(LONG, "some/note.md"), true);+ });++ test("a short title emits no alias — the filename already carries it", () => {+ const short = "short enough";+ assert.equal(slugify(short), short);+ assert.doesNotMatch(render(short), /^aliases:/m);+ });++ test("a title carrying a quote still round-trips through the alias", () => {+ const tricky = `The writer's "two facts" rule, restated at length so the slug must truncate it`;+ assert.deepEqual(extractAliases(render(tricky)), [tricky]);+ });+});