All files / scripts/agentic/gate-checks intelligence-assessment.ts

90.47% Statements 19/21
80% Branches 12/15
100% Functions 2/2
89.47% Lines 17/19

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                                            7x 7x 7x   5x   5x 49x 5x 5x 1x               5x     5x 7x                 5x 5x                 5x 4x               5x    
/**
 * @module scripts/agentic/gate-checks/intelligence-assessment
 * @description Check 7b — Validate intelligence-assessment.md structure
 *              (≥3 Key Judgments, ≥3 confidence labels, PIR reference).
 *
 * @see .github/prompts/05-analysis-gate.md §Check 7 (intelligence-assessment)
 * @author Hack23 AB
 * @license Apache-2.0
 */
 
import { readFile } from 'node:fs/promises';
import { existsSync } from 'node:fs';
import { join } from 'node:path';
 
import type { GateCheckResult } from '../gate-shared/types.js';
 
/**
 * Check intelligence-assessment.md for Key Judgments, confidence labels, PIR.
 */
export async function checkIntelligenceAssessment(
  analysisDir: string,
): Promise<GateCheckResult[]> {
  const results: GateCheckResult[] = [];
  const filePath = join(analysisDir, 'intelligence-assessment.md');
  if (!existsSync(filePath)) return results;
 
  const content = await readFile(filePath, 'utf-8');
 
  const kjPattern = /(Key\s+Judgment|KJ-?\d+)/;
  const kjLines = content.split('\n').filter((line) => kjPattern.test(line));
  const kjCount = kjLines.length;
  if (kjCount < 3) {
    results.push({
      checkId: 'family-c-structure',
      passed: false,
      message: `intelligence-assessment.md: fewer than 3 Key Judgments (found ${kjCount})`,
      artifact: 'intelligence-assessment.md',
    });
  }
 
  const confMatches = content.match(
    /\b(VERY\s+HIGH|VERY\s+LOW|HIGH|MEDIUM|LOW)\b/g,
  );
  const confCount = confMatches ? confMatches.length : 0;
  Iif (confCount < 3) {
    results.push({
      checkId: 'family-c-structure',
      passed: false,
      message: `intelligence-assessment.md: fewer than 3 confidence labels (found ${confCount})`,
      artifact: 'intelligence-assessment.md',
    });
  }
 
  const hasPir = /PIR/i.test(content);
  Iif (!hasPir) {
    results.push({
      checkId: 'family-c-structure',
      passed: false,
      message: 'intelligence-assessment.md: no PIR reference',
      artifact: 'intelligence-assessment.md',
    });
  }
 
  if (kjCount >= 3 && confCount >= 3 && hasPir) {
    results.push({
      checkId: 'family-c-structure',
      passed: true,
      message: 'intelligence-assessment.md: structure valid',
      artifact: 'intelligence-assessment.md',
    });
  }
 
  return results;
}