Self-hosted MCP server + dashboard giving Claude Code, Cursor & Hermes agents shared long-term memory over a git-backed markdown vault. Agent-native, Obsidian-compatible second brain — markdown RAG, no vector DB.
TypeScript agent-memoryai-agentsanthropicclaude-codecursorgitknowledge-baseknowledge-graphllmmarkdownmcpmcp-servermodel-context-protocolnote-takingobsidianpkmragsecond-brainself-hostedzettelkasten
fix(vault): [[Note#Heading]] links never resolved
Ronalds Palacis405e554da519
diff --git a/lib/vault/parse.ts b/lib/vault/parse.tsindex 2e0ffb0..ce28bb0 100644--- a/lib/vault/parse.ts+++ b/lib/vault/parse.ts@@ -22,10 +22,21 @@ export function folderOf(relPath: string): string {return seg.length > 1 ? seg[0] : "root";}-/** Resolve a wikilink target to a bare filename stem (path portion is a hint only). */+/**+ * Resolve a wikilink target to a bare filename stem (path portion is a hint only).+ *+ * Order matters. The alias goes first because an alias may itself contain a `#`+ * (`[[Pricing#Tiers|our #1 objection]]`). Then the heading/block anchor: `[[Pricing#Tiers]]`+ * points at a *section of* Pricing, so it must resolve to the note, not to the un-openable+ * stem "Pricing#Tiers" — leaving it on dropped every anchored link out of the graph and every+ * backlink it should have produced. Then `.md`, which can only be stripped once the anchor is+ * gone (`Pricing.md#Tiers` does not end in `.md`). A pure self-anchor `[[#Tiers]]` yields "",+ * which matches no note — correct, it addresses the current note rather than another one.+ */export function stemOf(target: string): string {- const noAlias = target.split("|")[0].trim();- const base = noAlias.split("/").pop() || noAlias;+ const noAlias = target.split("|")[0];+ const noAnchor = noAlias.split("#")[0].trim();+ const base = noAnchor.split("/").pop() || noAnchor;return base.replace(/\.md$/i, "").trim();}diff --git a/lib/vault/stems.test.ts b/lib/vault/stems.test.tsnew file mode 100644index 0000000..2188a06--- /dev/null+++ b/lib/vault/stems.test.ts@@ -0,0 +1,51 @@+import { test, expect, beforeEach } from "bun:test";+import fs from "node:fs";+import path from "node:path";+import { TEST_VAULT } from "../../test/setup";+import { stemOf } from "./parse";+import { rebuildIndex, getBacklinks } from "./store";++function write(rel: string, body: string) {+ const abs = path.join(TEST_VAULT, rel);+ fs.mkdirSync(path.dirname(abs), { recursive: true });+ fs.writeFileSync(abs, body);+}++beforeEach(() => {+ fs.rmSync(TEST_VAULT, { recursive: true, force: true });+ fs.mkdirSync(TEST_VAULT, { recursive: true });+});++test("stemOf strips alias, heading anchor, folder hint and extension", () => {+ expect(stemOf("Pricing")).toBe("Pricing");+ expect(stemOf("Pricing.md")).toBe("Pricing");+ expect(stemOf("docs/Pricing")).toBe("Pricing");+ expect(stemOf("Pricing|alias")).toBe("Pricing");++ // Anchors: the link addresses a section of the note, so it resolves to the note.+ expect(stemOf("Pricing#Tiers")).toBe("Pricing");+ expect(stemOf("Pricing#^block-id")).toBe("Pricing");+ expect(stemOf("docs/Pricing.md#Tiers")).toBe("Pricing");++ // An alias may contain its own '#' — the alias must be removed before the anchor.+ expect(stemOf("Pricing#Tiers|our #1 objection")).toBe("Pricing");++ // A pure self-anchor addresses the current note, so it names no other note.+ expect(stemOf("#Tiers")).toBe("");+});++test("an anchored wikilink produces a real backlink", () => {+ write("pricing.md", "# Pricing\n\n## Tiers\n\nfloor + share\n");+ write("leads/acme.md", "# Acme\n\nquoted from [[pricing#Tiers]] on the call\n");+ rebuildIndex();++ // Before the anchor fix this stem was "pricing#Tiers", which matched no note, so the+ // link vanished: no backlink, no graph edge, silently.+ expect(getBacklinks("pricing.md").map((b) => b.path)).toContain("leads/acme.md");+});++test("a self-anchor does not invent a link", () => {+ write("pricing.md", "# Pricing\n\njump to [[#Tiers]]\n\n## Tiers\n\nfloor + share\n");+ rebuildIndex();+ expect(getBacklinks("pricing.md")).toEqual([]);+});