Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | 3x 3x 8x 8x 8x 5x 5x 5x 5x 5x 47x 2x 2x 2x 45x 2x 2x 43x 6x 2x 2x 37x 14x 14x 23x 2x 2x 21x 8x 6x 6x 4x 5x 3x 5x | /**
* @module scripts/agentic/gate-checks/significance-scoring
* @description Check 4b — Every ranked bullet / list item / table row
* (outside Mermaid) in `significance-scoring.md` must contain
* a primary-source citation. Mermaid node labels are also
* checked unless they are structural keywords.
*
* @see .github/prompts/05-analysis-gate.md §Check 4 (significance half)
* @author Hack23 AB
* @license Apache-2.0
*/
import { readFile } from 'node:fs/promises';
import { existsSync } from 'node:fs';
import { join } from 'node:path';
import { EVIDENCE_PATTERN } from '../artifact-inventory.js';
import { TABLE_ROW_RE, TABLE_SEP_RE } from '../gate-shared/markdown-helpers.js';
import type { GateCheckResult } from '../gate-shared/types.js';
/** Mermaid structural keywords — these lines are never checked for evidence. */
const MERMAID_STRUCTURAL_RE =
/^\s*(%%|style\b|classDef\b|class\b|linkStyle\b|subgraph\b|end\b|graph\b|flowchart\b|quadrantChart\b|mindmap\b|timeline\b|journey\b|gantt\b|pie\b|xychart-beta\b|sequenceDiagram\b|stateDiagram(-v2)?\b|erDiagram\b|sankey-beta\b|gitGraph\b|requirementDiagram\b|block-beta\b)/;
/** Mermaid node/label content — lines with bracket/paren/curly-enclosed content indicate node labels. */
const MERMAID_NODE_RE = /\[[^\]\n]+\]|\([^)\n]+\)|\{[^}\n]+\}/;
/**
* Check significance-scoring.md: every ranked bullet/list item and table
* row (outside Mermaid) must contain evidence. Mermaid node labels are
* also checked unless they are structural keywords.
*/
export async function checkSignificanceScoringEvidence(
analysisDir: string,
): Promise<GateCheckResult[]> {
const results: GateCheckResult[] = [];
const filePath = join(analysisDir, 'significance-scoring.md');
if (!existsSync(filePath)) return results;
const content = await readFile(filePath, 'utf-8');
const lines = content.split('\n');
let inMermaid = false;
let tableRowCount = 0;
for (const line of lines) {
if (/^```mermaid\s*$/.test(line)) {
inMermaid = true;
tableRowCount = 0;
continue;
}
if (inMermaid && /^```\s*$/.test(line)) {
inMermaid = false;
continue;
}
if (inMermaid) {
if (MERMAID_STRUCTURAL_RE.test(line)) continue;
Iif (MERMAID_NODE_RE.test(line) && !EVIDENCE_PATTERN.test(line)) {
results.push({
checkId: 'evidence-citations',
passed: false,
message: `significance-scoring.md Mermaid node missing evidence (dok_id or primary-source URL): ${line.trim()}`,
artifact: 'significance-scoring.md',
});
}
continue;
}
if (/^\s*$/.test(line)) {
tableRowCount = 0;
continue;
}
if (/^\s*([0-9]+\.\s+|[-*]\s+)/.test(line) && !EVIDENCE_PATTERN.test(line)) {
results.push({
checkId: 'evidence-citations',
passed: false,
message: `significance-scoring.md ranked item missing evidence (dok_id or primary-source URL): ${line.trim()}`,
artifact: 'significance-scoring.md',
});
continue;
}
if (TABLE_ROW_RE.test(line)) {
if (TABLE_SEP_RE.test(line)) continue;
tableRowCount++;
if (tableRowCount === 1) continue;
Iif (!EVIDENCE_PATTERN.test(line)) {
results.push({
checkId: 'evidence-citations',
passed: false,
message: `significance-scoring.md ranking table row missing evidence (dok_id or primary-source URL): ${line.trim()}`,
artifact: 'significance-scoring.md',
});
}
}
}
if (results.length === 0) {
results.push({
checkId: 'evidence-citations',
passed: true,
message: 'significance-scoring.md: evidence citations present',
artifact: 'significance-scoring.md',
});
}
return results;
}
|