All files / src/constants analysis-constants.ts

0% Statements 0/7
0% Branches 0/5
0% Functions 0/2
0% Lines 0/6

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                                                                                                                                             
// SPDX-FileCopyrightText: 2024-2026 Hack23 AB
// SPDX-License-Identifier: Apache-2.0
 
/**
 * @module Constants/AnalysisConstants
 * @description Shared constants for the analysis pipeline. Kept in a standalone
 * module (outside generators/ and utils/) so that both `analysis-builders.ts`
 * and `intelligence-analysis.ts` can import it without introducing circular
 * ESM dependencies.
 */
 
/**
 * Marker for fields that require AI-generated political intelligence analysis.
 *
 * Scripts construct the structural scaffolding from data (what/who/when,
 * counts, identifiers, Mermaid charts) and may also derive some neutral,
 * factual descriptions directly from parliamentary data.
 *
 * Any narrative or interpretive analysis text (for example: why, outlook,
 * impact assessments, stakeholder reasoning, or mistake/consequence
 * explanations) that is LEFT AS THIS MARKER is expected to be generated by
 * the AI agent in the agentic workflow, not by code.
 */
export const AI_MARKER = '[AI_ANALYSIS_REQUIRED]';
 
/**
 * Check whether a text value is the AI analysis placeholder marker.
 *
 * Used by rendering functions to detect unfilled AI analysis fields and
 * display a user-friendly "analysis pending" notice rather than the raw
 * marker string.
 *
 * Recognises three marker formats:
 * - `[AI_ANALYSIS_REQUIRED]` — the current standard marker (v3.0+)
 * - `[REQUIRED]` — legacy marker used in template stubs before v3.0
 * - `[?]` — shorthand used in some early methodology templates
 *
 * @param text - Text to test
 * @returns `true` when the text is the AI placeholder marker
 */
export function isAiMarker(text: string | null | undefined): boolean {
  if (!text) return false;
  const trimmed = text.trim();
  return trimmed === AI_MARKER || trimmed === '[REQUIRED]' || trimmed === '[?]';
}
 
/**
 * CSS class applied to sections rendered with pending AI analysis content.
 * Used to visually indicate that the section awaits AI completion.
 */
export const AI_PENDING_CLASS = 'ai-analysis-pending';
 
/**
 * Test whether a text string is placeholder/fallback content that should be
 * excluded from user-visible metadata (e.g. SEO keywords, descriptions).
 *
 * Matches known placeholder patterns including:
 * - "placeholder" (case-insensitive)
 * - "data unavailable" / "data_unavailable" / "data-unavailable"
 * - "Example motion", "Example amendment", "Example group"
 *
 * Keep this regex in sync with the shell quality-gate patterns in the
 * gh-aw workflow files (`.github/workflows/news-*.md`).
 *
 * @param text - Candidate text to test
 * @returns `true` when the text matches known placeholder patterns
 */
export function isPlaceholderText(text: string): boolean {
  return /placeholder|data[\s._-]unavailable|example\s+(motion|amendment|group)/i.test(text);
}