- write-notes-like-deepseek 从三个子仓库的重复副本改为 meta 唯一副本 - 新增 .agents/scripts/verify-notes.ts,从 meta 视角一次校验四个笔记根 - workspace-layout 补「共有技能单一来源」的落位与理由 - .rgignore 排除 archived 历史快照
57 lines
1.9 KiB
TypeScript
57 lines
1.9 KiB
TypeScript
/**
|
|
* Verify tree: lifecycle/class/filename/INDEX and internal relative markdown links.
|
|
* Run: node <skill-dir>/scripts/verify-agent-note-tree.ts
|
|
*/
|
|
import { existsSync, readFileSync } from "node:fs";
|
|
import { dirname, resolve, sep } from "node:path";
|
|
import { agentNoteRoot, walkAgentNoteTree } from "./agent-note-tree.ts";
|
|
|
|
const { notes, errors } = walkAgentNoteTree();
|
|
|
|
// Check relative markdown links inside active notes
|
|
const LINK_REGEX = /\[([^\]]+)\]\(([^)]+)\)/g;
|
|
|
|
for (const note of notes) {
|
|
const noteFullPath = resolve(agentNoteRoot, note.rel);
|
|
const content = readFileSync(noteFullPath, "utf8");
|
|
let match: RegExpExecArray | null;
|
|
|
|
while ((match = LINK_REGEX.exec(content)) !== null) {
|
|
let rawTarget = match[2]?.trim();
|
|
if (!rawTarget) continue;
|
|
|
|
// Support CommonMark angle bracket destinations: [text](<path>)
|
|
if (rawTarget.startsWith("<") && rawTarget.endsWith(">")) {
|
|
rawTarget = rawTarget.slice(1, -1).trim();
|
|
}
|
|
|
|
// Ignore web links, intra-page anchors and ellipsis placeholders
|
|
if (rawTarget.startsWith("http://") || rawTarget.startsWith("https://") || rawTarget.startsWith("#") || rawTarget.startsWith("mailto:") || rawTarget.includes("…")) {
|
|
continue;
|
|
}
|
|
|
|
// Strip anchor fragment if present
|
|
const fileTarget = rawTarget.split("#")[0];
|
|
if (!fileTarget) continue;
|
|
|
|
const resolvedTarget = resolve(dirname(noteFullPath), fileTarget);
|
|
|
|
// Only verify internal links within agentNoteRoot (boundary-aware: a
|
|
// sibling like .agents/notes-backup/ must not prefix-match)
|
|
if (!resolvedTarget.startsWith(agentNoteRoot + sep)) {
|
|
continue;
|
|
}
|
|
|
|
if (!existsSync(resolvedTarget)) {
|
|
errors.push(`link: ${note.rel} -> "${rawTarget}" target file does not exist`);
|
|
}
|
|
}
|
|
}
|
|
|
|
if (errors.length) {
|
|
for (const e of errors) console.error(e);
|
|
process.exit(1);
|
|
}
|
|
|
|
console.log(`ok: ${notes.length} note(s) tree and relative links verified`);
|