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 | 3x 8x 8x 8x 5x 5x 5x 5x 5x 73x 14x 14x 14x 59x 5x 5x 5x 54x 49x 17x 17x 32x 22x 2x 22x 10x 5x 3x 5x | /**
* @module scripts/agentic/gate-checks/swot-evidence
* @description Check 4a — Every bullet / table row inside a SWOT section of
* `swot-analysis.md` must carry a primary-source citation
* (a dok_id or a recognised URL host).
*
* @see .github/prompts/05-analysis-gate.md §Check 4 (SWOT 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 {
ANY_HEADING_RE,
BULLET_RE,
TABLE_ROW_RE,
TABLE_SEP_RE,
} from '../gate-shared/markdown-helpers.js';
import type { GateCheckResult } from '../gate-shared/types.js';
/** SWOT section headings that trigger per-line evidence enforcement. */
const SWOT_SECTION_RE = /^###\s+.*(Strengths|Weaknesses|Opportunities|Threats)\b/i;
/**
* Check swot-analysis.md: every bullet and table row inside a SWOT section
* must contain at least one evidence citation.
*/
export async function checkSwotEvidence(
analysisDir: string,
): Promise<GateCheckResult[]> {
const results: GateCheckResult[] = [];
const filePath = join(analysisDir, 'swot-analysis.md');
if (!existsSync(filePath)) return results;
const content = await readFile(filePath, 'utf-8');
const lines = content.split('\n');
let currentSection = '';
let tableRowCount = 0;
for (const line of lines) {
if (SWOT_SECTION_RE.test(line)) {
currentSection = line.trim();
tableRowCount = 0;
continue;
}
if (ANY_HEADING_RE.test(line)) {
currentSection = '';
tableRowCount = 0;
continue;
}
if (!currentSection) continue;
if (/^\s*$/.test(line)) {
tableRowCount = 0;
continue;
}
if (BULLET_RE.test(line)) {
if (!EVIDENCE_PATTERN.test(line)) {
results.push({
checkId: 'evidence-citations',
passed: false,
message: `swot-analysis.md ${currentSection}: bullet missing evidence (dok_id or primary-source URL): ${line.trim()}`,
artifact: 'swot-analysis.md',
});
}
continue;
}
Iif (TABLE_ROW_RE.test(line)) {
if (TABLE_SEP_RE.test(line)) continue;
tableRowCount++;
if (tableRowCount === 1) continue;
if (!EVIDENCE_PATTERN.test(line)) {
results.push({
checkId: 'evidence-citations',
passed: false,
message: `swot-analysis.md ${currentSection}: table row missing evidence (dok_id or primary-source URL): ${line.trim()}`,
artifact: 'swot-analysis.md',
});
}
}
}
if (results.length === 0) {
results.push({
checkId: 'evidence-citations',
passed: true,
message: 'swot-analysis.md: evidence citations present',
artifact: 'swot-analysis.md',
});
}
return results;
}
|