/** * Soft report: physical reverse anchors (`// Note: ... 见 .agents/notes/...`). * A. anchors in source code pointing at notes that do not exist (dangling) * B. implemented notes with zero inbound code anchors (suspected missing anchor) * Exit code is always 0 — this is an advisory report, not a gate. * Env: AGENT_NOTE_CODE_ROOT (default: cwd) — source root to scan. * Run: node /scripts/check-note-anchors.ts */ import { existsSync, readFileSync, readdirSync } from "node:fs"; import { join, resolve } from "node:path"; import { agentNoteRoot, walkAgentNoteTree } from "./agent-note-tree.ts"; const codeRoot = resolve(process.env.AGENT_NOTE_CODE_ROOT || process.cwd()); const CODE_EXT = new Set([ ".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs", ".py", ".go", ".rs", ".java", ".kt", ".c", ".cc", ".cpp", ".h", ".hpp", ".cs", ".rb", ".swift", ".vue", ".svelte", ".php", ]); const SKIP_DIR = new Set([ "node_modules", ".git", "dist", "build", "out", "coverage", ".next", ".cache", ".agents", "vendor", "target", ]); const ANCHOR_RE = /(?:\/\/|#|\/\*|\*\s*|