A self-organizing Obsidian vault that gives AI coding agents persistent memory.
TypeScript ai-agentsclaude-codecodex-cligemini-cliknowledge-managementobsidianobsidian-vaultpersistent-memorysecond-braintemplate
feat: phantom-edge findings ride the policyResults contract (#137)
Brenno Ferrari0189a8b9db53
diff --git a/.claude/scripts/lib/frontmatter.ts b/.claude/scripts/lib/frontmatter.tsindex 79c9ec7..6889930 100644--- a/.claude/scripts/lib/frontmatter.ts+++ b/.claude/scripts/lib/frontmatter.ts@@ -107,20 +107,27 @@ export function validateContent(content: string): string[] {);}- // Ticket IDs are not notes — [[PROJ-12345]] creates a phantom graph edge- // that a broken-link gate then trips on (#108). Matches the bare form and- // the table-escaped-pipe forms. Plain text or a tracker URL, never a- // wikilink.- const ticketLinks = content.match(/\[\[[A-Z]{2,10}-\d+(\\\||||\||\]\])/g);- if (ticketLinks && ticketLinks.length > 0) {+ const ticketLinks = countTicketIdWikilinks(content);+ if (ticketLinks > 0) {warnings.push(- `${ticketLinks.length} ticket-ID wikilink(s) (e.g. [[PROJ-…]]) — ticket IDs are plain text or tracker links, never wikilinks (they are not notes)`,+ `${ticketLinks} ticket-ID wikilink(s) (e.g. [[PROJ-…]]) — ticket IDs are plain text or tracker links, never wikilinks (they are not notes)`,);}return warnings;}+/**+ * Count [[PROJ-12345]]-shaped wikilinks — ticket IDs are not notes, and+ * these phantom edges are what a broken-link gate later trips on (#108).+ * Matches the bare form and the table-escaped-pipe forms. Exported so+ * validate-write can emit the machine-readable policy result (#117) from+ * the same decision validateContent's prose comes from.+ */+export function countTicketIdWikilinks(content: string): number {+ return content.match(/\[\[[A-Z]{2,10}-\d+(\\\||||\||\]\])/g)?.length ?? 0;+}+/*** Read a file from disk and validate it. Returns null on read error* (caller should treat null as "skip silently" per hook protocol).diff --git a/.claude/scripts/tests/validate-write.test.ts b/.claude/scripts/tests/validate-write.test.tsindex 2c7f99f..703a452 100644--- a/.claude/scripts/tests/validate-write.test.ts+++ b/.claude/scripts/tests/validate-write.test.ts@@ -234,3 +234,28 @@ describe("validate-write — robustness to bad input", () => {assert.equal(stderr, "");});});++describe("phantom-edge policy result (#117)", () => {+ test("ticket-ID wikilinks emit the machine-readable finding next to the prose", () => {+ const path = makeMd(+ '---\ntags: [x]\ndescription: "d"\ndate: 2026-01-01\n---\n' ++ "[[Real Note]] and a phantom [[PROJ-1234]] edge.\n",+ "phantom.md",+ );+ const { stdout } = runOn(path);+ const parsed = JSON.parse(stdout) as {+ hookSpecificOutput: {+ additionalContext: string;+ policyResults?: Array<{ policy_id: string; classification: string }>;+ };+ };+ assert.match(parsed.hookSpecificOutput.additionalContext, /ticket-ID/);+ assert.ok(+ parsed.hookSpecificOutput.policyResults?.some(+ (r) =>+ r.policy_id === "phantom-edge" &&+ r.classification === "ticket-id-wikilink",+ ),+ );+ });+});diff --git a/.claude/scripts/validate-write.ts b/.claude/scripts/validate-write.tsindex d5d2a94..cf51996 100644--- a/.claude/scripts/validate-write.ts+++ b/.claude/scripts/validate-write.ts@@ -10,7 +10,7 @@import { basename, dirname, join, resolve as resolvePath } from "node:path";import { fileURLToPath } from "node:url";-import { realpathSync, statSync } from "node:fs";+import { readFileSync, realpathSync, statSync } from "node:fs";import {debug,readStdinJson,@@ -18,9 +18,10 @@ import {type PolicyResult,} from "./lib/hook-io.ts";import {+ countTicketIdWikilinks,isBlockedMemoryPath,shouldSkipFile,- validateFile,+ validateContent,} from "./lib/frontmatter.ts";import {MONOLITH_BYTES,@@ -143,15 +144,23 @@ if (shouldSkipFile(filePath)) {process.exit(0);}-const warnings = validateFile(filePath);-if (warnings === null) {+// Single read: prose warnings AND policy results derive from the same+// content snapshot — no second read, no TOCTOU window between them.+let content: string;+try {+ content = readFileSync(filePath, { encoding: "utf-8" });+} catch {debug(`validate: could not read ${filePath}`);process.exit(0);}+const warnings = validateContent(content);debug(`validate: ${filePath} — ${warnings.length} warning(s)`);const blocks: string[] = [];const policyResults: PolicyResult[] = [];+const relPath = filePathFwd.startsWith(vaultRoot + "/")+ ? filePathFwd.slice(vaultRoot.length + 1)+ : filePathFwd;if (warnings.length > 0) {const hintList = warnings.map((w) => ` - ${w}`).join("\n");@@ -159,6 +168,16 @@ if (warnings.length > 0) {blocks.push(`Vault hygiene warnings for \`${base}\`:\n${hintList}\nFix these before moving on.`,);+ // Phantom-edge findings ride the #117 contract like every other+ // detector — counted from the SAME content snapshot the prose came from.+ if (countTicketIdWikilinks(content) > 0) {+ policyResults.push({+ policy_id: "phantom-edge",+ path: relPath,+ classification: "ticket-id-wikilink",+ action: "warn",+ });+ }}// Write-time organization flags (#103): the same detectors the scan hooks@@ -166,9 +185,6 @@ if (warnings.length > 0) {// oversized (or added the note that completes a cluster) has the context// to organize it NOW. Each detector is isolated so a future unguarded// edit inside one can't kill the sibling checks in the same write.-const relPath = filePathFwd.startsWith(vaultRoot + "/")- ? filePathFwd.slice(vaultRoot.length + 1)- : filePathFwd;try {const size = statSync(filePath).size;if (