Skip to content

A self-organizing Obsidian vault that gives AI coding agents persistent memory.

fix: drop backticks from memory filenames so a wikilink to them resolves (#297)

Brenno Ferrarid0c87fdea93e
diff --git a/.claude/scripts/lib/memory-write.ts b/.claude/scripts/lib/memory-write.ts
index f89f753..88248a6 100644
--- a/.claude/scripts/lib/memory-write.ts
+++ b/.claude/scripts/lib/memory-write.ts
@@ -145,7 +145,14 @@ export function slugify(title: unknown): string {
// Replaced with a space rather than deleted, so `Flag #7 set` becomes
// `Flag 7 set` and not `Flag7 set`. The whitespace collapse below tidies
// the double space that leaves.
- .replace(/[[\]#]/g, " ")
+ //
+ // The backtick is not a terminator, but it breaks a link the same way
+ // from the other side: the link reader strips inline code before it
+ // reads links (so a `[[x]]` inside code is not counted), and a code span
+ // INSIDE `[[...]]` is stripped out of the target, leaving a name that
+ // does not exist. Keeping code spans would bring that miscount back, so
+ // the filename gives the backtick up instead.
+ .replace(/[[\]#`]/g, " ")
.replace(/\.{2,}/g, " ")
.replace(/\s+/g, " ")
.trim();
diff --git a/.claude/scripts/tests/memory-write.test.ts b/.claude/scripts/tests/memory-write.test.ts
index 27e4013..0cd79e2 100644
--- a/.claude/scripts/tests/memory-write.test.ts
+++ b/.claude/scripts/tests/memory-write.test.ts
@@ -10,7 +10,7 @@
*/
import { test, describe } from "node:test";
-import { extractAliases, buildResolver } from "../lib/wikilinks.ts";
+import { extractAliases, buildResolver, extractWikilinkTargets } from "../lib/wikilinks.ts";
import assert from "node:assert/strict";
import { mkdtempSync, existsSync, readFileSync, mkdirSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
@@ -390,6 +390,22 @@ describe("slug and path safety", () => {
assert.ok(!/\s{2,}/.test(s), `double space left behind: ${s}`);
});
+ /**
+ * A backtick in the filename made the note unaddressable: the link reader
+ * strips inline code first, and a code span inside `[[...]]` took part of
+ * the target with it.
+ */
+ test("a code span in the title leaves no backtick, and its words survive", () => {
+ // A space, not nothing, and the collapse tidies the double space.
+ assert.equal(slugify("Porting a bash `jq '.'` gate"), "Porting a bash jq '.' gate");
+ });
+
+ test("a wikilink to a slug made from a code-span title resolves to that slug", () => {
+ const stem = `2026-09-01 ${slugify("Porting a bash `jq '.'` gate")}`;
+ const targets = extractWikilinkTargets(`see [[${stem}|Capture]]`);
+ assert.deepEqual(targets, [stem]);
+ });
+
test("widening the class does not start eating ordinary titles", () => {
// The risk of a wider removal class is that it reaches titles it was never
// aimed at. A title whose words survive must keep all of them.