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 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 | 1x 1x 1x | /**
* @module Intelligence/EditorialFramework
* @description Article type profiles defining AI analysis depth, editorial sections,
* and quality thresholds for each article type in the Riksdagsmonitor news pipeline.
*
* Each profile specifies:
* - SWOT analysis requirements (full, condensed, quick, none)
* - Dashboard chart requirements (Chart.js visualizations)
* - Mindmap requirements (CSS mindmap sections)
* - Minimum stakeholder count for analysis
* - Number of AI analysis iterations required
* - Minimum word count thresholds
* - Required editorial sections
*
* @author Hack23 AB
* @license Apache-2.0
*/
import type { ArticleType } from './types/article.js';
/**
* SWOT analysis depth for an article type.
* - 'full': Complete SWOT with 5+ stakeholder perspectives per quadrant
* - 'condensed': Abbreviated SWOT with 3 stakeholder perspectives
* - 'quick': Single-paragraph SWOT overview
* - 'none': No SWOT required
*/
export type SwotDepth = 'full' | 'condensed' | 'quick' | 'none';
/**
* Analysis depth tier for AI iteration control.
* - 'standard': 1–2 AI iterations; suitable for routine coverage
* - 'deep': 2–3 AI iterations; suitable for complex multi-stakeholder topics
* - 'comprehensive': 3+ AI iterations; suitable for flagship investigative pieces
*/
export type AnalysisDepth = 'standard' | 'deep' | 'comprehensive';
/**
* Editorial section identifiers required per article type.
* Each identifier maps to a named section that must appear in the generated HTML.
*/
export type EditorialSection =
| 'executive-summary'
| 'stakeholder-impact'
| 'swot-analysis'
| 'policy-dashboard'
| 'policy-mindmap'
| 'deep-analysis'
| 'watch-points'
| 'sources-methodology';
/**
* Profile describing the editorial requirements for a single article type.
*/
export interface ArticleTypeProfile {
/** Human-readable label for this article type */
label: string;
/** SWOT analysis depth requirement */
swot: SwotDepth;
/** Whether a Chart.js policy dashboard section is required */
dashboard: boolean;
/** Minimum number of charts to include when dashboard is required */
minCharts: number;
/** Whether a CSS mindmap section is required */
mindmap: boolean;
/** Minimum number of stakeholder perspectives to include */
minStakeholders: number;
/** Number of AI analysis iterations required to meet quality standards */
aiIterations: number;
/** Minimum word count for the generated article */
minWordCount: number;
/** Default analysis depth for workflow_dispatch input */
defaultAnalysisDepth: AnalysisDepth;
/** Ordered list of required editorial sections */
requiredSections: EditorialSection[];
/** Quality gate thresholds that must be met before PR creation */
qualityThresholds: {
/** Minimum quality score (0.0–1.0) matching article-quality-enhancer.ts scale */
minQualityScore: number;
/** Minimum number of policy domains detected */
minPolicyDomains: number;
/** Whether stakeholder diversity check is required */
requireStakeholderDiversity: boolean;
};
}
/**
* Constrained union of all valid editorial profile keys.
* Covers the canonical ArticleType union plus 'evening-analysis' which is
* workflow-specific but not a routable article type.
*/
export type EditorialProfileKey = ArticleType | 'evening-analysis';
/**
* Editorial profiles for all 11 article types supported by the news generation pipeline.
*
* Profiles are ordered by analysis complexity from most to least intensive.
*/
export const ARTICLE_TYPE_PROFILES: Readonly<Record<EditorialProfileKey, ArticleTypeProfile>> = {
'deep-inspection': {
label: 'Deep Inspection',
swot: 'full',
dashboard: true,
minCharts: 4,
mindmap: true,
minStakeholders: 7,
aiIterations: 3,
minWordCount: 2000,
defaultAnalysisDepth: 'comprehensive',
requiredSections: [
'executive-summary',
'stakeholder-impact',
'swot-analysis',
'policy-dashboard',
'policy-mindmap',
'deep-analysis',
'watch-points',
'sources-methodology',
],
qualityThresholds: {
minQualityScore: 0.70,
minPolicyDomains: 3,
requireStakeholderDiversity: true,
},
},
'monthly-review': {
label: 'Monthly Review',
swot: 'full',
dashboard: true,
minCharts: 4,
mindmap: true,
minStakeholders: 7,
aiIterations: 3,
minWordCount: 1800,
defaultAnalysisDepth: 'deep',
requiredSections: [
'executive-summary',
'stakeholder-impact',
'swot-analysis',
'policy-dashboard',
'policy-mindmap',
'deep-analysis',
'watch-points',
'sources-methodology',
],
qualityThresholds: {
minQualityScore: 0.65,
minPolicyDomains: 3,
requireStakeholderDiversity: true,
},
},
'committee-reports': {
label: 'Committee Reports',
swot: 'full',
dashboard: true,
minCharts: 2,
mindmap: true,
minStakeholders: 5,
aiIterations: 2,
minWordCount: 800,
defaultAnalysisDepth: 'deep',
requiredSections: [
'executive-summary',
'stakeholder-impact',
'swot-analysis',
'policy-dashboard',
'policy-mindmap',
'deep-analysis',
'watch-points',
'sources-methodology',
],
qualityThresholds: {
minQualityScore: 0.55,
minPolicyDomains: 2,
requireStakeholderDiversity: true,
},
},
'propositions': {
label: 'Government Propositions',
swot: 'full',
dashboard: true,
minCharts: 2,
mindmap: true,
minStakeholders: 5,
aiIterations: 2,
minWordCount: 800,
defaultAnalysisDepth: 'deep',
requiredSections: [
'executive-summary',
'stakeholder-impact',
'swot-analysis',
'policy-dashboard',
'policy-mindmap',
'deep-analysis',
'watch-points',
'sources-methodology',
],
qualityThresholds: {
minQualityScore: 0.55,
minPolicyDomains: 2,
requireStakeholderDiversity: true,
},
},
'weekly-review': {
label: 'Weekly Review',
swot: 'condensed',
dashboard: true,
minCharts: 2,
mindmap: true,
minStakeholders: 5,
aiIterations: 2,
minWordCount: 1000,
defaultAnalysisDepth: 'standard',
requiredSections: [
'executive-summary',
'stakeholder-impact',
'swot-analysis',
'policy-dashboard',
'policy-mindmap',
'deep-analysis',
'watch-points',
'sources-methodology',
],
qualityThresholds: {
minQualityScore: 0.50,
minPolicyDomains: 2,
requireStakeholderDiversity: false,
},
},
'motions': {
label: 'Opposition Motions',
swot: 'condensed',
dashboard: true,
minCharts: 1,
mindmap: false,
minStakeholders: 4,
aiIterations: 2,
minWordCount: 700,
defaultAnalysisDepth: 'standard',
requiredSections: [
'executive-summary',
'stakeholder-impact',
'swot-analysis',
'policy-dashboard',
'deep-analysis',
'watch-points',
'sources-methodology',
],
qualityThresholds: {
minQualityScore: 0.50,
minPolicyDomains: 1,
requireStakeholderDiversity: false,
},
},
'interpellations': {
label: 'Interpellation Debates',
swot: 'condensed',
dashboard: true,
minCharts: 1,
mindmap: false,
minStakeholders: 4,
aiIterations: 2,
minWordCount: 700,
defaultAnalysisDepth: 'standard',
requiredSections: [
'executive-summary',
'stakeholder-impact',
'swot-analysis',
'policy-dashboard',
'deep-analysis',
'watch-points',
'sources-methodology',
],
qualityThresholds: {
minQualityScore: 0.50,
minPolicyDomains: 1,
requireStakeholderDiversity: false,
},
},
'month-ahead': {
label: 'Month Ahead',
swot: 'condensed',
dashboard: true,
minCharts: 2,
mindmap: true,
minStakeholders: 5,
aiIterations: 2,
minWordCount: 900,
defaultAnalysisDepth: 'standard',
requiredSections: [
'executive-summary',
'stakeholder-impact',
'swot-analysis',
'policy-dashboard',
'policy-mindmap',
'watch-points',
'sources-methodology',
],
qualityThresholds: {
minQualityScore: 0.50,
minPolicyDomains: 2,
requireStakeholderDiversity: false,
},
},
'week-ahead': {
label: 'Week Ahead',
swot: 'quick',
dashboard: true,
minCharts: 2,
mindmap: false,
minStakeholders: 3,
aiIterations: 1,
minWordCount: 600,
defaultAnalysisDepth: 'standard',
requiredSections: [
'executive-summary',
'swot-analysis',
'policy-dashboard',
'watch-points',
'sources-methodology',
],
qualityThresholds: {
minQualityScore: 0.40,
minPolicyDomains: 1,
requireStakeholderDiversity: false,
},
},
'evening-analysis': {
label: 'Evening Analysis',
swot: 'quick',
dashboard: true,
minCharts: 1,
mindmap: false,
minStakeholders: 3,
aiIterations: 1,
minWordCount: 600,
defaultAnalysisDepth: 'standard',
requiredSections: [
'executive-summary',
'stakeholder-impact',
'swot-analysis',
'policy-dashboard',
'deep-analysis',
'watch-points',
'sources-methodology',
],
qualityThresholds: {
minQualityScore: 0.40,
minPolicyDomains: 1,
requireStakeholderDiversity: false,
},
},
'breaking': {
label: 'Breaking News',
swot: 'quick',
dashboard: false,
minCharts: 0,
mindmap: false,
minStakeholders: 3,
aiIterations: 1,
minWordCount: 400,
defaultAnalysisDepth: 'standard',
requiredSections: [
'executive-summary',
'stakeholder-impact',
'watch-points',
'sources-methodology',
],
qualityThresholds: {
minQualityScore: 0.40,
minPolicyDomains: 1,
requireStakeholderDiversity: false,
},
},
} as const;
/**
* Get the profile for an article type.
*
* @param articleType - The article type identifier (accepts arbitrary strings from external workflow inputs; unrecognized types fall back to 'breaking')
* @returns The editorial profile, or the 'breaking' profile as a safe fallback
*/
export function getArticleTypeProfile(articleType: string): ArticleTypeProfile {
// articleType comes from external sources (workflow_dispatch, CLI) and may not be
// in EditorialProfileKey. Use Object.hasOwn to guard against prototype keys
// ('__proto__', 'constructor', etc.) that would bypass the intended lookup.
if (Object.hasOwn(ARTICLE_TYPE_PROFILES, articleType)) {
return (ARTICLE_TYPE_PROFILES as Readonly<Record<string, ArticleTypeProfile>>)[articleType];
}
return ARTICLE_TYPE_PROFILES['breaking'];
}
/**
* Resolve the effective AI iteration count based on the requested depth and profile.
*
* @param articleType - The article type identifier
* @param requestedDepth - The analysis depth requested via workflow_dispatch input
* @returns Number of AI analysis iterations to perform
*/
export function resolveAiIterations(
articleType: string,
requestedDepth: AnalysisDepth,
): number {
const profile = getArticleTypeProfile(articleType);
switch (requestedDepth) {
case 'standard':
// standard caps at 2 iterations even if profile has more (1–2 range)
return Math.min(2, Math.max(1, profile.aiIterations));
case 'deep':
// deep enforces 2–3 iterations
return Math.min(3, Math.max(2, profile.aiIterations));
case 'comprehensive':
// comprehensive uses the full profile iteration count (minimum 3, no cap)
return Math.max(3, profile.aiIterations);
default: {
// Exhaustive guard — if a new AnalysisDepth value is added, this will error at compile time
const _exhaustive: never = requestedDepth;
throw new Error(`Unknown analysis depth: ${String(_exhaustive)}`);
}
}
}
/**
* Check whether a given analysis depth string is a valid AnalysisDepth value.
*
* @param depth - The string to validate
* @returns true if valid, false otherwise
*/
export function isValidAnalysisDepth(depth: unknown): depth is AnalysisDepth {
return depth === 'standard' || depth === 'deep' || depth === 'comprehensive';
}
/**
* Minimum quality thresholds shared across all article types as a floor.
* Individual profiles are expected to meet or exceed these values, though
* no runtime validation currently enforces this constraint.
*/
export const GLOBAL_QUALITY_FLOOR = {
minWordCount: 400,
minQualityScore: 0.40,
minPolicyDomains: 1,
} as const;
/**
* Editorial framework version for cache-busting and compatibility tracking.
*/
export const EDITORIAL_FRAMEWORK_VERSION = '1.0.0';
|