114 lines
5.6 KiB
JavaScript
114 lines
5.6 KiB
JavaScript
import { existsSync, globSync, readFileSync } from 'node:fs';
|
|
import { join, posix, resolve } from 'node:path';
|
|
import { pathToFileURL } from 'node:url';
|
|
import { parseArgs } from 'node:util';
|
|
|
|
const controlledDocuments = [
|
|
'AGENTS.md', 'CLAUDE.md', 'README.md', 'PRODUCT.md', 'DESIGN.md',
|
|
'.claude/**/*.md', '.kiro/steering/**/*.md',
|
|
'apps/detail-photocraft/AGENTS.md', 'apps/detail-photocraft/JIANSUN.md',
|
|
];
|
|
|
|
// Remove resolved entries when the pointer documents are cleaned up.
|
|
const baseline = new Set([
|
|
".claude/Claude-命令速查.md -> uploads/temp/",
|
|
".claude/Claude-命令速查.md -> uploads/assembled/",
|
|
".claude/Claude-命令速查.md -> ./deploy-remote-build.ps1",
|
|
".claude/skills/cleanup-temp.md -> uploads/temp/",
|
|
".claude/skills/cleanup-temp.md -> uploads/assembled/",
|
|
".claude/skills/cleanup-temp.md -> uploads/cleanup/",
|
|
".claude/skills/cleanup-temp.md -> uploads/materials/",
|
|
".claude/skills/cleanup-temp.md -> uploads/",
|
|
".kiro/steering/项目记忆库.md -> 由壹点AI/",
|
|
".kiro/steering/项目记忆库.md -> download/",
|
|
".kiro/steering/项目记忆库.md -> transcode/",
|
|
".kiro/steering/项目记忆库.md -> deploy-with-log.ps1",
|
|
".kiro/steering/项目记忆库.md -> ./deploy-remote-build.ps1",
|
|
".kiro/steering/项目记忆库.md -> deploy-local-build.ps1",
|
|
".kiro/steering/项目记忆库.md -> deploy-git-build.ps1",
|
|
"AGENTS.md -> .private/gongxiangp2-完整敏感接管清单-2026-08-13.md",
|
|
"CLAUDE.md -> TeamFunctionsDashboard.tsx",
|
|
"CLAUDE.md -> PermissionGroupsDashboard.tsx",
|
|
"CLAUDE.md -> UserPermissionsDashboard.tsx",
|
|
"CLAUDE.md -> 由壹点AI/",
|
|
"CLAUDE.md -> deploy-remote-build.ps1",
|
|
"CLAUDE.md -> upload-sessions.ts",
|
|
"DESIGN.md -> .impeccable/surfaces/app-assets-detail-generator-page-tsx.md",
|
|
"DESIGN.md -> .impeccable/surfaces/components-admin-aimodelmanagementpanel-tsx.md",
|
|
"README.md -> release.json",
|
|
"apps/detail-photocraft/AGENTS.md -> corpus/",
|
|
"apps/detail-photocraft/AGENTS.md -> src/macos.rs",
|
|
"apps/detail-photocraft/AGENTS.md -> src/windows.rs",
|
|
"apps/detail-photocraft/AGENTS.md -> crates/ui-egui/src/parity.rs",
|
|
"apps/detail-photocraft/AGENTS.md -> ui-egui/src/state.rs",
|
|
"apps/detail-photocraft/AGENTS.md -> log/devlog.md",
|
|
"apps/detail-photocraft/AGENTS.md -> engine/src/lib.rs",
|
|
"apps/detail-photocraft/AGENTS.md -> engine/src/commands.rs",
|
|
"apps/detail-photocraft/AGENTS.md -> ui-egui/src/menus.rs",
|
|
"apps/detail-photocraft/AGENTS.md -> plan/",
|
|
"apps/detail-photocraft/AGENTS.md -> log/",
|
|
"apps/detail-photocraft/AGENTS.md -> contributors.json",
|
|
"apps/detail-photocraft/AGENTS.md -> storytold/craft-common-actions",
|
|
"apps/detail-photocraft/JIANSUN.md -> jiansun/accounts/",
|
|
"apps/detail-photocraft/JIANSUN.md -> target/",
|
|
"apps/detail-photocraft/JIANSUN.md -> agent/node.exe",
|
|
"apps/detail-photocraft/JIANSUN.md -> agent/src/desktop-host.mjs",
|
|
"apps/detail-photocraft/JIANSUN.md -> jiansun/lifecycle/",
|
|
]);
|
|
|
|
function pointer(text) {
|
|
const candidate = text.replaceAll('\\', '/').replace(/(?::\d+(?:[-,]\d+)*|#[\p{L}\w-]+)$/u, '');
|
|
if (/[\r\n*?[\]{}<>|"'$:=]|^\/|\s--?/u.test(candidate)) return;
|
|
if (/^\d+\/(?:tcp|udp)$/i.test(candidate) || /(?:^|\/)\.\.\.(?:\/|$)/.test(candidate) ||
|
|
/^[\w.-]+\.(?:com|net|org|vip|hk)\//i.test(candidate)) return;
|
|
if (/^(?:\.\.?\/|\.private(?:\/|$)|[\p{L}\w.@-]+\/)/u.test(candidate) ||
|
|
/^[\w.-]+\.(?:md|json|mjs|js|ts|tsx|toml|ya?ml|txt|sh|ps1|prisma|css)$/i.test(candidate)) {
|
|
return candidate;
|
|
}
|
|
}
|
|
|
|
export function documentReferenceIssues(root, files = globSync(controlledDocuments, { cwd: root })) {
|
|
const issues = [];
|
|
for (const file of files.map(name => name.replaceAll('\\', '/')).sort()) {
|
|
const source = readFileSync(join(root, file), 'utf8');
|
|
let fence = '';
|
|
for (const line of source.split(/\r?\n/)) {
|
|
const marker = line.match(/^\s{0,3}(~~~+|```+)/)?.[1];
|
|
if (marker && !fence) { fence = marker; continue; }
|
|
if (fence) {
|
|
if (marker?.[0] === fence[0] && marker.length >= fence.length) fence = '';
|
|
continue;
|
|
}
|
|
for (const [, text] of line.matchAll(/(?<!`)`([^`]+)`(?!`)/g)) {
|
|
const reference = pointer(text);
|
|
if (!reference) continue;
|
|
const relativeToDoc = posix.normalize(posix.join(posix.dirname(file), reference));
|
|
const repositoryPath = /^\.\.?\//.test(reference)
|
|
? relativeToDoc : posix.normalize(reference);
|
|
const candidates = /^\.\.?\//.test(reference) ? [repositoryPath] : [repositoryPath, relativeToDoc];
|
|
const forbidden = candidates.some(name => /^(?:\.\.(?:\/|$))|(?:^|\/)\.private(?:\/|$)/i.test(name));
|
|
const exists = !forbidden && candidates.some(name => !/^资料(?:\/|$)/.test(name) && existsSync(join(root, name)));
|
|
if (!exists) issues.push({ file, reference, reason: forbidden ? 'outside-repository' : 'missing' });
|
|
}
|
|
}
|
|
}
|
|
return [...new Map(issues.map(issue => [referenceKey(issue), issue])).values()];
|
|
}
|
|
|
|
function referenceKey({ file, reference }) {
|
|
return file + ' -> ' + reference;
|
|
}
|
|
|
|
export function newDocumentReferenceIssues(root) {
|
|
return documentReferenceIssues(root).filter(issue => !baseline.has(referenceKey(issue)));
|
|
}
|
|
|
|
if (process.argv[1] && pathToFileURL(resolve(process.argv[1])).href === import.meta.url) {
|
|
const { values } = parseArgs({ options: { files: { type: 'string', multiple: true }, strict: { type: 'boolean' } } });
|
|
const issues = values.files || values.strict
|
|
? documentReferenceIssues(process.cwd(), values.files)
|
|
: newDocumentReferenceIssues(process.cwd());
|
|
for (const issue of issues) console.error(referenceKey(issue) + ' (' + issue.reason + ')');
|
|
if (issues.length) process.exitCode = 1;
|
|
}
|