Template
feat(tools): 站外官方依据登记表 external-sources.json 与校验
This commit is contained in:
@@ -14,6 +14,8 @@
|
||||
* 8. **依据真实性**:`依据` 中的 documentId 必须已登记于 tools/doc-ids.json 且 verified=true
|
||||
* 9. **依据引文**:被本次改动触及的规则条目,其 `依据` 必须附原文引文且**引文能在该文档中命中**
|
||||
* —— 把"依据是否支持结论"从不可验证的判断降级为字符串命中
|
||||
* 10. **站外官方依据**:`- **官方变更公告(站外)**` 类条目里的 URL 必须登记于 tools/external-sources.json
|
||||
* (未登记 = 报错;核实日期超 365 天 = 提示;登记后无规则引用 = 提示)
|
||||
*
|
||||
* 用法:
|
||||
* node tools/check-rules-index.mjs # 结构校验(快,供日常/门禁)
|
||||
@@ -173,6 +175,9 @@ for (const name of files) {
|
||||
}
|
||||
|
||||
/* ---------- 第二遍:引用解析 / URL / 退役编号 ---------- */
|
||||
/** 站外官方依据的合法落点:`- **官方变更公告(站外)**:… <URL>`(USE-007 允许的例外)。 */
|
||||
const EXTERNAL_LABEL_RE = /^\s*-\s*\*\*[^*]{0,24}(变更公告|发布说明|站外|外部公告)/;
|
||||
const externalCitations = []; // { loc, url }
|
||||
for (const [rel, text] of rawText) {
|
||||
let inFence = false;
|
||||
text.split(/\r?\n/).forEach((line, idx) => {
|
||||
@@ -181,7 +186,10 @@ for (const [rel, text] of rawText) {
|
||||
// 代码块内的 URL 属示例数据(如 'https://example.com'),不按引用判定
|
||||
if (/https?:\/\//.test(line) && !inFence) {
|
||||
if (/依据/.test(line)) errors.push(`[web URL] ${loc} 依据行含 web URL(USE-007 禁止)`);
|
||||
else warnings.push(`[示例 URL] ${loc} 非依据行出现 URL(请确认非引用)`);
|
||||
else if (EXTERNAL_LABEL_RE.test(line)) {
|
||||
const u = line.match(/https?:\/\/[^\s<>"'))】]+/);
|
||||
externalCitations.push({ loc, url: u ? u[0] : '' });
|
||||
} else warnings.push(`[示例 URL] ${loc} 非依据行出现 URL(请确认非引用)`);
|
||||
}
|
||||
if (/^\s*retired\s*:/.test(line)) return; // frontmatter 的退役声明本身不是引用
|
||||
for (const m of line.matchAll(/\b([A-Z]{2,6})-(\d{3})\b/g)) {
|
||||
@@ -195,6 +203,53 @@ for (const [rel, text] of rawText) {
|
||||
});
|
||||
}
|
||||
|
||||
/* ---------- 站外官方依据:必须登记于 tools/external-sources.json ---------- */
|
||||
const EXTERNAL_PATH = join(ROOT, 'tools', 'external-sources.json');
|
||||
const EXTERNAL_MAX_AGE_DAYS = 365;
|
||||
let externalRegistry = {};
|
||||
if (existsSync(EXTERNAL_PATH)) {
|
||||
try {
|
||||
const parsed = JSON.parse(readFileSync(EXTERNAL_PATH, 'utf8'));
|
||||
externalRegistry = parsed.sources || {};
|
||||
} catch (e) {
|
||||
errors.push(`[外部来源] tools/external-sources.json 解析失败:${e.message}`);
|
||||
}
|
||||
} else if (externalCitations.length) {
|
||||
errors.push('[外部来源] tools/external-sources.json 不存在——站外官方依据必须登记(title / claims / verifiedAt)');
|
||||
}
|
||||
const citedExternal = new Set();
|
||||
/** 登记键不含 URL 锚点(锚点只用于定位小节,见 external-sources.json 的 _readme)。 */
|
||||
const normalizeExternal = u => u.replace(/[,。;、))】\]/.!?]+$/, '').replace(/#.*$/, '');
|
||||
for (const c of externalCitations) {
|
||||
if (!c.url) {
|
||||
errors.push(`[外部来源] ${c.loc} 官方公告行里没找到 URL`);
|
||||
continue;
|
||||
}
|
||||
const key = normalizeExternal(c.url);
|
||||
citedExternal.add(key);
|
||||
const rec = externalRegistry[key] || externalRegistry[c.url.replace(/[,。;、))】\]/.!?]+$/, '')];
|
||||
if (!rec) {
|
||||
errors.push(`[外部来源] ${c.loc} 站外官方依据未登记:${key}`
|
||||
+ ' → 在 tools/external-sources.json 登记 title / claims / verifiedAt');
|
||||
continue;
|
||||
}
|
||||
if (!rec.title || !Array.isArray(rec.claims) || !rec.claims.length) {
|
||||
errors.push(`[外部来源] ${c.loc} 登记项缺少 title 或 claims:${key}`);
|
||||
}
|
||||
const ts = Date.parse(rec.verifiedAt || '');
|
||||
if (!rec.verifiedAt || Number.isNaN(ts)) {
|
||||
errors.push(`[外部来源] ${c.loc} 登记项缺少合法 verifiedAt(YYYY-MM-DD):${key}`);
|
||||
} else if ((Date.now() - ts) / 86400000 > EXTERNAL_MAX_AGE_DAYS) {
|
||||
warnings.push(`[外部来源] ${c.loc} 核实日期已 ${Math.floor((Date.now() - ts) / 86400000)} 天未更新`
|
||||
+ `(${rec.verifiedAt})→ 核对公告是否仍有效后改 verifiedAt:${key}`);
|
||||
}
|
||||
}
|
||||
for (const url of Object.keys(externalRegistry)) {
|
||||
if (!citedExternal.has(normalizeExternal(url))) {
|
||||
warnings.push(`[外部来源] 已登记但没有任何规则引用,可考虑移除:${url}`);
|
||||
}
|
||||
}
|
||||
|
||||
/* ---------- 依据真实性:documentId 必须在已核验白名单内 ---------- */
|
||||
const DOC_MAP_PATH = join(ROOT, 'tools', 'doc-ids.json');
|
||||
if (!existsSync(DOC_MAP_PATH)) {
|
||||
@@ -505,7 +560,8 @@ if (!existsSync(agentsPath)) {
|
||||
}
|
||||
|
||||
/* ---------- 汇总 ---------- */
|
||||
console.log(`扫描 ${files.length} 份文档,已定义规则 ${defined.size} 条,登记前缀 ${PREFIXES.size} 个。`);
|
||||
console.log(`扫描 ${files.length} 份文档,已定义规则 ${defined.size} 条,登记前缀 ${PREFIXES.size} 个`
|
||||
+ `,站外官方依据 ${externalCitations.length} 处(已登记 ${citedExternal.size} 个来源)。`);
|
||||
if (DIFF_MODE || ALL_MODE) {
|
||||
console.log(`证据校验:引文命中 ${verifiedQuotes} 条、术语对账通过 ${verifiedTerms} 条、术语显式豁免 ${exemptedTerms} 项`
|
||||
+ `${DIFF_MODE ? `;跳过未改动条目 ${legacyNoQuote} 条(存量渐进回填中)` : ''}。`);
|
||||
|
||||
Reference in New Issue
Block a user