riksdagsmonitor 0.8.23 → 0.8.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +53 -1
- package/dist/lib/dashboards/party-dashboard.js +2 -1
- package/dist/lib/dashboards/party-dashboard.js.map +1 -1
- package/dist/lib/dashboards/risk-dashboard.js +2 -1
- package/dist/lib/dashboards/risk-dashboard.js.map +1 -1
- package/dist/lib/shared/index.d.ts +0 -1
- package/dist/lib/shared/index.d.ts.map +1 -1
- package/dist/lib/shared/index.js +3 -1
- package/dist/lib/shared/index.js.map +1 -1
- package/dist/lib/shared/register-globals.d.ts +1 -1
- package/dist/lib/shared/register-globals.d.ts.map +1 -1
- package/dist/lib/shared/register-globals.js +7 -1
- package/dist/lib/shared/register-globals.js.map +1 -1
- package/package.json +54 -22
- package/dist/scripts/analysis-reader.d.ts +0 -241
- package/dist/scripts/analysis-reader.d.ts.map +0 -1
- package/dist/scripts/analysis-reader.js +0 -531
- package/dist/scripts/analysis-reader.js.map +0 -1
- package/dist/scripts/article-quality-enhancer.d.ts +0 -148
- package/dist/scripts/article-quality-enhancer.d.ts.map +0 -1
- package/dist/scripts/article-quality-enhancer.js +0 -430
- package/dist/scripts/article-quality-enhancer.js.map +0 -1
- package/dist/scripts/article-template/constants.d.ts +0 -104
- package/dist/scripts/article-template/constants.d.ts.map +0 -1
- package/dist/scripts/article-template/constants.js +0 -225
- package/dist/scripts/article-template/constants.js.map +0 -1
- package/dist/scripts/article-template/helpers.d.ts +0 -83
- package/dist/scripts/article-template/helpers.d.ts.map +0 -1
- package/dist/scripts/article-template/helpers.js +0 -236
- package/dist/scripts/article-template/helpers.js.map +0 -1
- package/dist/scripts/article-template/index.d.ts +0 -39
- package/dist/scripts/article-template/index.d.ts.map +0 -1
- package/dist/scripts/article-template/index.js +0 -37
- package/dist/scripts/article-template/index.js.map +0 -1
- package/dist/scripts/article-template/registry.d.ts +0 -64
- package/dist/scripts/article-template/registry.d.ts.map +0 -1
- package/dist/scripts/article-template/registry.js +0 -405
- package/dist/scripts/article-template/registry.js.map +0 -1
- package/dist/scripts/article-template/template.d.ts +0 -18
- package/dist/scripts/article-template/template.d.ts.map +0 -1
- package/dist/scripts/article-template/template.js +0 -359
- package/dist/scripts/article-template/template.js.map +0 -1
- package/dist/scripts/article-template/types.d.ts +0 -90
- package/dist/scripts/article-template/types.d.ts.map +0 -1
- package/dist/scripts/article-template/types.js +0 -96
- package/dist/scripts/article-template/types.js.map +0 -1
- package/dist/scripts/article-template.d.ts +0 -18
- package/dist/scripts/article-template.d.ts.map +0 -1
- package/dist/scripts/article-template.js +0 -18
- package/dist/scripts/article-template.js.map +0 -1
- package/dist/scripts/catalog-downloaded-data.d.ts +0 -66
- package/dist/scripts/catalog-downloaded-data.d.ts.map +0 -1
- package/dist/scripts/catalog-downloaded-data.js +0 -239
- package/dist/scripts/catalog-downloaded-data.js.map +0 -1
- package/dist/scripts/check-cia-schema-updates.d.ts +0 -186
- package/dist/scripts/check-cia-schema-updates.d.ts.map +0 -1
- package/dist/scripts/check-cia-schema-updates.js +0 -363
- package/dist/scripts/check-cia-schema-updates.js.map +0 -1
- package/dist/scripts/data-transformers/calendar.d.ts +0 -16
- package/dist/scripts/data-transformers/calendar.d.ts.map +0 -1
- package/dist/scripts/data-transformers/calendar.js +0 -137
- package/dist/scripts/data-transformers/calendar.js.map +0 -1
- package/dist/scripts/data-transformers/constants/committee-names.d.ts +0 -15
- package/dist/scripts/data-transformers/constants/committee-names.d.ts.map +0 -1
- package/dist/scripts/data-transformers/constants/committee-names.js +0 -30
- package/dist/scripts/data-transformers/constants/committee-names.js.map +0 -1
- package/dist/scripts/data-transformers/constants/content-labels-part1.d.ts +0 -11
- package/dist/scripts/data-transformers/constants/content-labels-part1.d.ts.map +0 -1
- package/dist/scripts/data-transformers/constants/content-labels-part1.js +0 -900
- package/dist/scripts/data-transformers/constants/content-labels-part1.js.map +0 -1
- package/dist/scripts/data-transformers/constants/content-labels-part2.d.ts +0 -11
- package/dist/scripts/data-transformers/constants/content-labels-part2.d.ts.map +0 -1
- package/dist/scripts/data-transformers/constants/content-labels-part2.js +0 -900
- package/dist/scripts/data-transformers/constants/content-labels-part2.js.map +0 -1
- package/dist/scripts/data-transformers/constants/content-labels.d.ts +0 -13
- package/dist/scripts/data-transformers/constants/content-labels.d.ts.map +0 -1
- package/dist/scripts/data-transformers/constants/content-labels.js +0 -18
- package/dist/scripts/data-transformers/constants/content-labels.js.map +0 -1
- package/dist/scripts/data-transformers/constants/index.d.ts +0 -15
- package/dist/scripts/data-transformers/constants/index.d.ts.map +0 -1
- package/dist/scripts/data-transformers/constants/index.js +0 -15
- package/dist/scripts/data-transformers/constants/index.js.map +0 -1
- package/dist/scripts/data-transformers/constants/locale-map.d.ts +0 -13
- package/dist/scripts/data-transformers/constants/locale-map.d.ts.map +0 -1
- package/dist/scripts/data-transformers/constants/locale-map.js +0 -17
- package/dist/scripts/data-transformers/constants/locale-map.js.map +0 -1
- package/dist/scripts/data-transformers/constants.d.ts +0 -14
- package/dist/scripts/data-transformers/constants.d.ts.map +0 -1
- package/dist/scripts/data-transformers/constants.js +0 -14
- package/dist/scripts/data-transformers/constants.js.map +0 -1
- package/dist/scripts/data-transformers/content-generators/ai-mindmap-analyzer.d.ts +0 -64
- package/dist/scripts/data-transformers/content-generators/ai-mindmap-analyzer.d.ts.map +0 -1
- package/dist/scripts/data-transformers/content-generators/ai-mindmap-analyzer.js +0 -805
- package/dist/scripts/data-transformers/content-generators/ai-mindmap-analyzer.js.map +0 -1
- package/dist/scripts/data-transformers/content-generators/cia-overview-section.d.ts +0 -50
- package/dist/scripts/data-transformers/content-generators/cia-overview-section.d.ts.map +0 -1
- package/dist/scripts/data-transformers/content-generators/cia-overview-section.js +0 -310
- package/dist/scripts/data-transformers/content-generators/cia-overview-section.js.map +0 -1
- package/dist/scripts/data-transformers/content-generators/committee.d.ts +0 -12
- package/dist/scripts/data-transformers/content-generators/committee.d.ts.map +0 -1
- package/dist/scripts/data-transformers/content-generators/committee.js +0 -247
- package/dist/scripts/data-transformers/content-generators/committee.js.map +0 -1
- package/dist/scripts/data-transformers/content-generators/dashboard-section.d.ts +0 -124
- package/dist/scripts/data-transformers/content-generators/dashboard-section.d.ts.map +0 -1
- package/dist/scripts/data-transformers/content-generators/dashboard-section.js +0 -564
- package/dist/scripts/data-transformers/content-generators/dashboard-section.js.map +0 -1
- package/dist/scripts/data-transformers/content-generators/economic-dashboard-section.d.ts +0 -82
- package/dist/scripts/data-transformers/content-generators/economic-dashboard-section.d.ts.map +0 -1
- package/dist/scripts/data-transformers/content-generators/economic-dashboard-section.js +0 -321
- package/dist/scripts/data-transformers/content-generators/economic-dashboard-section.js.map +0 -1
- package/dist/scripts/data-transformers/content-generators/generic.d.ts +0 -12
- package/dist/scripts/data-transformers/content-generators/generic.d.ts.map +0 -1
- package/dist/scripts/data-transformers/content-generators/generic.js +0 -295
- package/dist/scripts/data-transformers/content-generators/generic.js.map +0 -1
- package/dist/scripts/data-transformers/content-generators/index.d.ts +0 -84
- package/dist/scripts/data-transformers/content-generators/index.d.ts.map +0 -1
- package/dist/scripts/data-transformers/content-generators/index.js +0 -47
- package/dist/scripts/data-transformers/content-generators/index.js.map +0 -1
- package/dist/scripts/data-transformers/content-generators/interpellations.d.ts +0 -12
- package/dist/scripts/data-transformers/content-generators/interpellations.d.ts.map +0 -1
- package/dist/scripts/data-transformers/content-generators/interpellations.js +0 -124
- package/dist/scripts/data-transformers/content-generators/interpellations.js.map +0 -1
- package/dist/scripts/data-transformers/content-generators/mindmap-section.d.ts +0 -137
- package/dist/scripts/data-transformers/content-generators/mindmap-section.d.ts.map +0 -1
- package/dist/scripts/data-transformers/content-generators/mindmap-section.js +0 -286
- package/dist/scripts/data-transformers/content-generators/mindmap-section.js.map +0 -1
- package/dist/scripts/data-transformers/content-generators/month-ahead.d.ts +0 -17
- package/dist/scripts/data-transformers/content-generators/month-ahead.d.ts.map +0 -1
- package/dist/scripts/data-transformers/content-generators/month-ahead.js +0 -212
- package/dist/scripts/data-transformers/content-generators/month-ahead.js.map +0 -1
- package/dist/scripts/data-transformers/content-generators/monthly-review.d.ts +0 -17
- package/dist/scripts/data-transformers/content-generators/monthly-review.d.ts.map +0 -1
- package/dist/scripts/data-transformers/content-generators/monthly-review.js +0 -173
- package/dist/scripts/data-transformers/content-generators/monthly-review.js.map +0 -1
- package/dist/scripts/data-transformers/content-generators/motions.d.ts +0 -12
- package/dist/scripts/data-transformers/content-generators/motions.d.ts.map +0 -1
- package/dist/scripts/data-transformers/content-generators/motions.js +0 -158
- package/dist/scripts/data-transformers/content-generators/motions.js.map +0 -1
- package/dist/scripts/data-transformers/content-generators/newsworthiness.d.ts +0 -62
- package/dist/scripts/data-transformers/content-generators/newsworthiness.d.ts.map +0 -1
- package/dist/scripts/data-transformers/content-generators/newsworthiness.js +0 -254
- package/dist/scripts/data-transformers/content-generators/newsworthiness.js.map +0 -1
- package/dist/scripts/data-transformers/content-generators/propositions.d.ts +0 -12
- package/dist/scripts/data-transformers/content-generators/propositions.d.ts.map +0 -1
- package/dist/scripts/data-transformers/content-generators/propositions.js +0 -263
- package/dist/scripts/data-transformers/content-generators/propositions.js.map +0 -1
- package/dist/scripts/data-transformers/content-generators/sankey-section.d.ts +0 -92
- package/dist/scripts/data-transformers/content-generators/sankey-section.d.ts.map +0 -1
- package/dist/scripts/data-transformers/content-generators/sankey-section.js +0 -257
- package/dist/scripts/data-transformers/content-generators/sankey-section.js.map +0 -1
- package/dist/scripts/data-transformers/content-generators/shared.d.ts +0 -139
- package/dist/scripts/data-transformers/content-generators/shared.d.ts.map +0 -1
- package/dist/scripts/data-transformers/content-generators/shared.js +0 -935
- package/dist/scripts/data-transformers/content-generators/shared.js.map +0 -1
- package/dist/scripts/data-transformers/content-generators/swot-section.d.ts +0 -50
- package/dist/scripts/data-transformers/content-generators/swot-section.d.ts.map +0 -1
- package/dist/scripts/data-transformers/content-generators/swot-section.js +0 -177
- package/dist/scripts/data-transformers/content-generators/swot-section.js.map +0 -1
- package/dist/scripts/data-transformers/content-generators/week-ahead.d.ts +0 -12
- package/dist/scripts/data-transformers/content-generators/week-ahead.d.ts.map +0 -1
- package/dist/scripts/data-transformers/content-generators/week-ahead.js +0 -332
- package/dist/scripts/data-transformers/content-generators/week-ahead.js.map +0 -1
- package/dist/scripts/data-transformers/content-generators.d.ts +0 -15
- package/dist/scripts/data-transformers/content-generators.d.ts.map +0 -1
- package/dist/scripts/data-transformers/content-generators.js +0 -14
- package/dist/scripts/data-transformers/content-generators.js.map +0 -1
- package/dist/scripts/data-transformers/document-analysis.d.ts +0 -58
- package/dist/scripts/data-transformers/document-analysis.d.ts.map +0 -1
- package/dist/scripts/data-transformers/document-analysis.js +0 -396
- package/dist/scripts/data-transformers/document-analysis.js.map +0 -1
- package/dist/scripts/data-transformers/helpers.d.ts +0 -144
- package/dist/scripts/data-transformers/helpers.d.ts.map +0 -1
- package/dist/scripts/data-transformers/helpers.js +0 -408
- package/dist/scripts/data-transformers/helpers.js.map +0 -1
- package/dist/scripts/data-transformers/index.d.ts +0 -45
- package/dist/scripts/data-transformers/index.d.ts.map +0 -1
- package/dist/scripts/data-transformers/index.js +0 -66
- package/dist/scripts/data-transformers/index.js.map +0 -1
- package/dist/scripts/data-transformers/metadata.d.ts +0 -42
- package/dist/scripts/data-transformers/metadata.d.ts.map +0 -1
- package/dist/scripts/data-transformers/metadata.js +0 -385
- package/dist/scripts/data-transformers/metadata.js.map +0 -1
- package/dist/scripts/data-transformers/policy-analysis.d.ts +0 -105
- package/dist/scripts/data-transformers/policy-analysis.d.ts.map +0 -1
- package/dist/scripts/data-transformers/policy-analysis.js +0 -686
- package/dist/scripts/data-transformers/policy-analysis.js.map +0 -1
- package/dist/scripts/data-transformers/risk-analysis.d.ts +0 -104
- package/dist/scripts/data-transformers/risk-analysis.d.ts.map +0 -1
- package/dist/scripts/data-transformers/risk-analysis.js +0 -279
- package/dist/scripts/data-transformers/risk-analysis.js.map +0 -1
- package/dist/scripts/data-transformers/types.d.ts +0 -260
- package/dist/scripts/data-transformers/types.d.ts.map +0 -1
- package/dist/scripts/data-transformers/types.js +0 -11
- package/dist/scripts/data-transformers/types.js.map +0 -1
- package/dist/scripts/data-transformers.d.ts +0 -23
- package/dist/scripts/data-transformers.d.ts.map +0 -1
- package/dist/scripts/data-transformers.js +0 -35
- package/dist/scripts/data-transformers.js.map +0 -1
- package/dist/scripts/deep-inspection/index.d.ts +0 -55
- package/dist/scripts/deep-inspection/index.d.ts.map +0 -1
- package/dist/scripts/deep-inspection/index.js +0 -66
- package/dist/scripts/deep-inspection/index.js.map +0 -1
- package/dist/scripts/detect-swedish-leakage.d.ts +0 -69
- package/dist/scripts/detect-swedish-leakage.d.ts.map +0 -1
- package/dist/scripts/detect-swedish-leakage.js +0 -417
- package/dist/scripts/detect-swedish-leakage.js.map +0 -1
- package/dist/scripts/editorial-framework.d.ts +0 -121
- package/dist/scripts/editorial-framework.d.ts.map +0 -1
- package/dist/scripts/editorial-framework.js +0 -364
- package/dist/scripts/editorial-framework.js.map +0 -1
- package/dist/scripts/editorial-pillars.d.ts +0 -43
- package/dist/scripts/editorial-pillars.d.ts.map +0 -1
- package/dist/scripts/editorial-pillars.js +0 -215
- package/dist/scripts/editorial-pillars.js.map +0 -1
- package/dist/scripts/extract-news-metadata.d.ts +0 -12
- package/dist/scripts/extract-news-metadata.d.ts.map +0 -1
- package/dist/scripts/extract-news-metadata.js +0 -107
- package/dist/scripts/extract-news-metadata.js.map +0 -1
- package/dist/scripts/extract-vocabulary.d.ts +0 -15
- package/dist/scripts/extract-vocabulary.d.ts.map +0 -1
- package/dist/scripts/extract-vocabulary.js +0 -255
- package/dist/scripts/extract-vocabulary.js.map +0 -1
- package/dist/scripts/fix-article-navigation.d.ts +0 -37
- package/dist/scripts/fix-article-navigation.d.ts.map +0 -1
- package/dist/scripts/fix-article-navigation.js +0 -198
- package/dist/scripts/fix-article-navigation.js.map +0 -1
- package/dist/scripts/fix-keywords-localization.d.ts +0 -18
- package/dist/scripts/fix-keywords-localization.d.ts.map +0 -1
- package/dist/scripts/fix-keywords-localization.js +0 -270
- package/dist/scripts/fix-keywords-localization.js.map +0 -1
- package/dist/scripts/fix-old-articles-branding.d.ts +0 -17
- package/dist/scripts/fix-old-articles-branding.d.ts.map +0 -1
- package/dist/scripts/fix-old-articles-branding.js +0 -229
- package/dist/scripts/fix-old-articles-branding.js.map +0 -1
- package/dist/scripts/generate-news-backport.d.ts +0 -16
- package/dist/scripts/generate-news-backport.d.ts.map +0 -1
- package/dist/scripts/generate-news-backport.js +0 -379
- package/dist/scripts/generate-news-backport.js.map +0 -1
- package/dist/scripts/generate-news-enhanced/ai-analysis-pipeline.d.ts +0 -141
- package/dist/scripts/generate-news-enhanced/ai-analysis-pipeline.d.ts.map +0 -1
- package/dist/scripts/generate-news-enhanced/ai-analysis-pipeline.js +0 -546
- package/dist/scripts/generate-news-enhanced/ai-analysis-pipeline.js.map +0 -1
- package/dist/scripts/generate-news-enhanced/analysis-cache.d.ts +0 -59
- package/dist/scripts/generate-news-enhanced/analysis-cache.d.ts.map +0 -1
- package/dist/scripts/generate-news-enhanced/analysis-cache.js +0 -116
- package/dist/scripts/generate-news-enhanced/analysis-cache.js.map +0 -1
- package/dist/scripts/generate-news-enhanced/analysis-labels.d.ts +0 -58
- package/dist/scripts/generate-news-enhanced/analysis-labels.d.ts.map +0 -1
- package/dist/scripts/generate-news-enhanced/analysis-labels.js +0 -144
- package/dist/scripts/generate-news-enhanced/analysis-labels.js.map +0 -1
- package/dist/scripts/generate-news-enhanced/config.d.ts +0 -58
- package/dist/scripts/generate-news-enhanced/config.d.ts.map +0 -1
- package/dist/scripts/generate-news-enhanced/config.js +0 -286
- package/dist/scripts/generate-news-enhanced/config.js.map +0 -1
- package/dist/scripts/generate-news-enhanced/generators.d.ts +0 -119
- package/dist/scripts/generate-news-enhanced/generators.d.ts.map +0 -1
- package/dist/scripts/generate-news-enhanced/generators.js +0 -2131
- package/dist/scripts/generate-news-enhanced/generators.js.map +0 -1
- package/dist/scripts/generate-news-enhanced/helpers.d.ts +0 -122
- package/dist/scripts/generate-news-enhanced/helpers.d.ts.map +0 -1
- package/dist/scripts/generate-news-enhanced/helpers.js +0 -468
- package/dist/scripts/generate-news-enhanced/helpers.js.map +0 -1
- package/dist/scripts/generate-news-enhanced/index.d.ts +0 -19
- package/dist/scripts/generate-news-enhanced/index.d.ts.map +0 -1
- package/dist/scripts/generate-news-enhanced/index.js +0 -221
- package/dist/scripts/generate-news-enhanced/index.js.map +0 -1
- package/dist/scripts/generate-news-enhanced/swot-analyzer.d.ts +0 -46
- package/dist/scripts/generate-news-enhanced/swot-analyzer.d.ts.map +0 -1
- package/dist/scripts/generate-news-enhanced/swot-analyzer.js +0 -1227
- package/dist/scripts/generate-news-enhanced/swot-analyzer.js.map +0 -1
- package/dist/scripts/generate-news-enhanced/types.d.ts +0 -34
- package/dist/scripts/generate-news-enhanced/types.d.ts.map +0 -1
- package/dist/scripts/generate-news-enhanced/types.js +0 -9
- package/dist/scripts/generate-news-enhanced/types.js.map +0 -1
- package/dist/scripts/generate-news-enhanced.d.ts +0 -25
- package/dist/scripts/generate-news-enhanced.d.ts.map +0 -1
- package/dist/scripts/generate-news-enhanced.js +0 -37
- package/dist/scripts/generate-news-enhanced.js.map +0 -1
- package/dist/scripts/generate-news-indexes/constants.d.ts +0 -20
- package/dist/scripts/generate-news-indexes/constants.d.ts.map +0 -1
- package/dist/scripts/generate-news-indexes/constants.js +0 -308
- package/dist/scripts/generate-news-indexes/constants.js.map +0 -1
- package/dist/scripts/generate-news-indexes/helpers.d.ts +0 -73
- package/dist/scripts/generate-news-indexes/helpers.d.ts.map +0 -1
- package/dist/scripts/generate-news-indexes/helpers.js +0 -352
- package/dist/scripts/generate-news-indexes/helpers.js.map +0 -1
- package/dist/scripts/generate-news-indexes/index.d.ts +0 -20
- package/dist/scripts/generate-news-indexes/index.d.ts.map +0 -1
- package/dist/scripts/generate-news-indexes/index.js +0 -75
- package/dist/scripts/generate-news-indexes/index.js.map +0 -1
- package/dist/scripts/generate-news-indexes/template.d.ts +0 -25
- package/dist/scripts/generate-news-indexes/template.d.ts.map +0 -1
- package/dist/scripts/generate-news-indexes/template.js +0 -644
- package/dist/scripts/generate-news-indexes/template.js.map +0 -1
- package/dist/scripts/generate-news-indexes/types.d.ts +0 -96
- package/dist/scripts/generate-news-indexes/types.d.ts.map +0 -1
- package/dist/scripts/generate-news-indexes/types.js +0 -9
- package/dist/scripts/generate-news-indexes/types.js.map +0 -1
- package/dist/scripts/generate-news-indexes.d.ts +0 -20
- package/dist/scripts/generate-news-indexes.d.ts.map +0 -1
- package/dist/scripts/generate-news-indexes.js +0 -19
- package/dist/scripts/generate-news-indexes.js.map +0 -1
- package/dist/scripts/generate-rss.d.ts +0 -48
- package/dist/scripts/generate-rss.d.ts.map +0 -1
- package/dist/scripts/generate-rss.js +0 -299
- package/dist/scripts/generate-rss.js.map +0 -1
- package/dist/scripts/generate-sitemap-html.d.ts +0 -79
- package/dist/scripts/generate-sitemap-html.d.ts.map +0 -1
- package/dist/scripts/generate-sitemap-html.js +0 -878
- package/dist/scripts/generate-sitemap-html.js.map +0 -1
- package/dist/scripts/generate-sitemap.d.ts +0 -23
- package/dist/scripts/generate-sitemap.d.ts.map +0 -1
- package/dist/scripts/generate-sitemap.js +0 -476
- package/dist/scripts/generate-sitemap.js.map +0 -1
- package/dist/scripts/generate-types-from-cia-schemas.d.ts +0 -176
- package/dist/scripts/generate-types-from-cia-schemas.d.ts.map +0 -1
- package/dist/scripts/generate-types-from-cia-schemas.js +0 -318
- package/dist/scripts/generate-types-from-cia-schemas.js.map +0 -1
- package/dist/scripts/government-role-validator.d.ts +0 -65
- package/dist/scripts/government-role-validator.d.ts.map +0 -1
- package/dist/scripts/government-role-validator.js +0 -217
- package/dist/scripts/government-role-validator.js.map +0 -1
- package/dist/scripts/html-utils.d.ts +0 -17
- package/dist/scripts/html-utils.d.ts.map +0 -1
- package/dist/scripts/html-utils.js +0 -29
- package/dist/scripts/html-utils.js.map +0 -1
- package/dist/scripts/load-cia-stats.d.ts +0 -89
- package/dist/scripts/load-cia-stats.d.ts.map +0 -1
- package/dist/scripts/load-cia-stats.js +0 -400
- package/dist/scripts/load-cia-stats.js.map +0 -1
- package/dist/scripts/mcp-client/client.d.ts +0 -73
- package/dist/scripts/mcp-client/client.d.ts.map +0 -1
- package/dist/scripts/mcp-client/client.js +0 -526
- package/dist/scripts/mcp-client/client.js.map +0 -1
- package/dist/scripts/mcp-client/document-types.d.ts +0 -23
- package/dist/scripts/mcp-client/document-types.d.ts.map +0 -1
- package/dist/scripts/mcp-client/document-types.js +0 -62
- package/dist/scripts/mcp-client/document-types.js.map +0 -1
- package/dist/scripts/mcp-client/index.d.ts +0 -34
- package/dist/scripts/mcp-client/index.d.ts.map +0 -1
- package/dist/scripts/mcp-client/index.js +0 -67
- package/dist/scripts/mcp-client/index.js.map +0 -1
- package/dist/scripts/mcp-client/transport.d.ts +0 -32
- package/dist/scripts/mcp-client/transport.d.ts.map +0 -1
- package/dist/scripts/mcp-client/transport.js +0 -102
- package/dist/scripts/mcp-client/transport.js.map +0 -1
- package/dist/scripts/mcp-client.d.ts +0 -18
- package/dist/scripts/mcp-client.d.ts.map +0 -1
- package/dist/scripts/mcp-client.js +0 -18
- package/dist/scripts/mcp-client.js.map +0 -1
- package/dist/scripts/mcp-query-cli.d.ts +0 -25
- package/dist/scripts/mcp-query-cli.d.ts.map +0 -1
- package/dist/scripts/mcp-query-cli.js +0 -66
- package/dist/scripts/mcp-query-cli.js.map +0 -1
- package/dist/scripts/news-types/breaking-news.d.ts +0 -178
- package/dist/scripts/news-types/breaking-news.d.ts.map +0 -1
- package/dist/scripts/news-types/breaking-news.js +0 -432
- package/dist/scripts/news-types/breaking-news.js.map +0 -1
- package/dist/scripts/news-types/committee-reports.d.ts +0 -212
- package/dist/scripts/news-types/committee-reports.d.ts.map +0 -1
- package/dist/scripts/news-types/committee-reports.js +0 -404
- package/dist/scripts/news-types/committee-reports.js.map +0 -1
- package/dist/scripts/news-types/month-ahead.d.ts +0 -71
- package/dist/scripts/news-types/month-ahead.d.ts.map +0 -1
- package/dist/scripts/news-types/month-ahead.js +0 -392
- package/dist/scripts/news-types/month-ahead.js.map +0 -1
- package/dist/scripts/news-types/monthly-review.d.ts +0 -61
- package/dist/scripts/news-types/monthly-review.d.ts.map +0 -1
- package/dist/scripts/news-types/monthly-review.js +0 -417
- package/dist/scripts/news-types/monthly-review.js.map +0 -1
- package/dist/scripts/news-types/motions.d.ts +0 -214
- package/dist/scripts/news-types/motions.d.ts.map +0 -1
- package/dist/scripts/news-types/motions.js +0 -447
- package/dist/scripts/news-types/motions.js.map +0 -1
- package/dist/scripts/news-types/propositions.d.ts +0 -204
- package/dist/scripts/news-types/propositions.d.ts.map +0 -1
- package/dist/scripts/news-types/propositions.js +0 -401
- package/dist/scripts/news-types/propositions.js.map +0 -1
- package/dist/scripts/news-types/week-ahead.d.ts +0 -231
- package/dist/scripts/news-types/week-ahead.d.ts.map +0 -1
- package/dist/scripts/news-types/week-ahead.js +0 -441
- package/dist/scripts/news-types/week-ahead.js.map +0 -1
- package/dist/scripts/news-types/weekly-review/analysis.d.ts +0 -47
- package/dist/scripts/news-types/weekly-review/analysis.d.ts.map +0 -1
- package/dist/scripts/news-types/weekly-review/analysis.js +0 -276
- package/dist/scripts/news-types/weekly-review/analysis.js.map +0 -1
- package/dist/scripts/news-types/weekly-review/data-loader.d.ts +0 -51
- package/dist/scripts/news-types/weekly-review/data-loader.d.ts.map +0 -1
- package/dist/scripts/news-types/weekly-review/data-loader.js +0 -298
- package/dist/scripts/news-types/weekly-review/data-loader.js.map +0 -1
- package/dist/scripts/news-types/weekly-review/generator.d.ts +0 -18
- package/dist/scripts/news-types/weekly-review/generator.d.ts.map +0 -1
- package/dist/scripts/news-types/weekly-review/generator.js +0 -284
- package/dist/scripts/news-types/weekly-review/generator.js.map +0 -1
- package/dist/scripts/news-types/weekly-review/index.d.ts +0 -20
- package/dist/scripts/news-types/weekly-review/index.d.ts.map +0 -1
- package/dist/scripts/news-types/weekly-review/index.js +0 -23
- package/dist/scripts/news-types/weekly-review/index.js.map +0 -1
- package/dist/scripts/news-types/weekly-review/types.d.ts +0 -72
- package/dist/scripts/news-types/weekly-review/types.d.ts.map +0 -1
- package/dist/scripts/news-types/weekly-review/types.js +0 -20
- package/dist/scripts/news-types/weekly-review/types.js.map +0 -1
- package/dist/scripts/news-types/weekly-review/validation.d.ts +0 -10
- package/dist/scripts/news-types/weekly-review/validation.d.ts.map +0 -1
- package/dist/scripts/news-types/weekly-review/validation.js +0 -95
- package/dist/scripts/news-types/weekly-review/validation.js.map +0 -1
- package/dist/scripts/news-types/weekly-review.d.ts +0 -15
- package/dist/scripts/news-types/weekly-review.d.ts.map +0 -1
- package/dist/scripts/news-types/weekly-review.js +0 -14
- package/dist/scripts/news-types/weekly-review.js.map +0 -1
- package/dist/scripts/party-variants.d.ts +0 -23
- package/dist/scripts/party-variants.d.ts.map +0 -1
- package/dist/scripts/party-variants.js +0 -50
- package/dist/scripts/party-variants.js.map +0 -1
- package/dist/scripts/pipeline/index.d.ts +0 -19
- package/dist/scripts/pipeline/index.d.ts.map +0 -1
- package/dist/scripts/pipeline/index.js +0 -17
- package/dist/scripts/pipeline/index.js.map +0 -1
- package/dist/scripts/pipeline/orchestrator.d.ts +0 -56
- package/dist/scripts/pipeline/orchestrator.d.ts.map +0 -1
- package/dist/scripts/pipeline/orchestrator.js +0 -147
- package/dist/scripts/pipeline/orchestrator.js.map +0 -1
- package/dist/scripts/pipeline/types.d.ts +0 -117
- package/dist/scripts/pipeline/types.d.ts.map +0 -1
- package/dist/scripts/pipeline/types.js +0 -13
- package/dist/scripts/pipeline/types.js.map +0 -1
- package/dist/scripts/pipeline/validation.d.ts +0 -66
- package/dist/scripts/pipeline/validation.d.ts.map +0 -1
- package/dist/scripts/pipeline/validation.js +0 -129
- package/dist/scripts/pipeline/validation.js.map +0 -1
- package/dist/scripts/populate-analysis-data.d.ts +0 -41
- package/dist/scripts/populate-analysis-data.d.ts.map +0 -1
- package/dist/scripts/populate-analysis-data.js +0 -255
- package/dist/scripts/populate-analysis-data.js.map +0 -1
- package/dist/scripts/pre-article-analysis/data-downloader.d.ts +0 -80
- package/dist/scripts/pre-article-analysis/data-downloader.d.ts.map +0 -1
- package/dist/scripts/pre-article-analysis/data-downloader.js +0 -230
- package/dist/scripts/pre-article-analysis/data-downloader.js.map +0 -1
- package/dist/scripts/pre-article-analysis/data-persistence.d.ts +0 -141
- package/dist/scripts/pre-article-analysis/data-persistence.d.ts.map +0 -1
- package/dist/scripts/pre-article-analysis/data-persistence.js +0 -345
- package/dist/scripts/pre-article-analysis/data-persistence.js.map +0 -1
- package/dist/scripts/pre-article-analysis/markdown-serializer.d.ts +0 -158
- package/dist/scripts/pre-article-analysis/markdown-serializer.d.ts.map +0 -1
- package/dist/scripts/pre-article-analysis/markdown-serializer.js +0 -648
- package/dist/scripts/pre-article-analysis/markdown-serializer.js.map +0 -1
- package/dist/scripts/pre-article-analysis/pdf-converter.d.ts +0 -58
- package/dist/scripts/pre-article-analysis/pdf-converter.d.ts.map +0 -1
- package/dist/scripts/pre-article-analysis/pdf-converter.js +0 -142
- package/dist/scripts/pre-article-analysis/pdf-converter.js.map +0 -1
- package/dist/scripts/pre-article-analysis.d.ts +0 -42
- package/dist/scripts/pre-article-analysis.d.ts.map +0 -1
- package/dist/scripts/pre-article-analysis.js +0 -642
- package/dist/scripts/pre-article-analysis.js.map +0 -1
- package/dist/scripts/scb-client.d.ts +0 -104
- package/dist/scripts/scb-client.d.ts.map +0 -1
- package/dist/scripts/scb-client.js +0 -286
- package/dist/scripts/scb-client.js.map +0 -1
- package/dist/scripts/scb-context.d.ts +0 -88
- package/dist/scripts/scb-context.d.ts.map +0 -1
- package/dist/scripts/scb-context.js +0 -307
- package/dist/scripts/scb-context.js.map +0 -1
- package/dist/scripts/shared/version.d.ts +0 -9
- package/dist/scripts/shared/version.d.ts.map +0 -1
- package/dist/scripts/shared/version.js +0 -28
- package/dist/scripts/shared/version.js.map +0 -1
- package/dist/scripts/statistical-claims-detector.d.ts +0 -119
- package/dist/scripts/statistical-claims-detector.d.ts.map +0 -1
- package/dist/scripts/statistical-claims-detector.js +0 -391
- package/dist/scripts/statistical-claims-detector.js.map +0 -1
- package/dist/scripts/sync-cia-schemas.d.ts +0 -52
- package/dist/scripts/sync-cia-schemas.d.ts.map +0 -1
- package/dist/scripts/sync-cia-schemas.js +0 -195
- package/dist/scripts/sync-cia-schemas.js.map +0 -1
- package/dist/scripts/translation-dictionary.d.ts +0 -45
- package/dist/scripts/translation-dictionary.d.ts.map +0 -1
- package/dist/scripts/translation-dictionary.js +0 -3642
- package/dist/scripts/translation-dictionary.js.map +0 -1
- package/dist/scripts/types/article.d.ts +0 -392
- package/dist/scripts/types/article.d.ts.map +0 -1
- package/dist/scripts/types/article.js +0 -6
- package/dist/scripts/types/article.js.map +0 -1
- package/dist/scripts/types/content.d.ts +0 -167
- package/dist/scripts/types/content.d.ts.map +0 -1
- package/dist/scripts/types/content.js +0 -6
- package/dist/scripts/types/content.js.map +0 -1
- package/dist/scripts/types/editorial.d.ts +0 -17
- package/dist/scripts/types/editorial.d.ts.map +0 -1
- package/dist/scripts/types/editorial.js +0 -6
- package/dist/scripts/types/editorial.js.map +0 -1
- package/dist/scripts/types/language.d.ts +0 -7
- package/dist/scripts/types/language.d.ts.map +0 -1
- package/dist/scripts/types/language.js +0 -6
- package/dist/scripts/types/language.js.map +0 -1
- package/dist/scripts/types/mcp.d.ts +0 -117
- package/dist/scripts/types/mcp.d.ts.map +0 -1
- package/dist/scripts/types/mcp.js +0 -6
- package/dist/scripts/types/mcp.js.map +0 -1
- package/dist/scripts/types/party.d.ts +0 -9
- package/dist/scripts/types/party.d.ts.map +0 -1
- package/dist/scripts/types/party.js +0 -6
- package/dist/scripts/types/party.js.map +0 -1
- package/dist/scripts/types/validation.d.ts +0 -136
- package/dist/scripts/types/validation.d.ts.map +0 -1
- package/dist/scripts/types/validation.js +0 -6
- package/dist/scripts/types/validation.js.map +0 -1
- package/dist/scripts/types/workflow.d.ts +0 -78
- package/dist/scripts/types/workflow.d.ts.map +0 -1
- package/dist/scripts/types/workflow.js +0 -6
- package/dist/scripts/types/workflow.js.map +0 -1
- package/dist/scripts/update-stats-from-cia.d.ts +0 -44
- package/dist/scripts/update-stats-from-cia.d.ts.map +0 -1
- package/dist/scripts/update-stats-from-cia.js +0 -310
- package/dist/scripts/update-stats-from-cia.js.map +0 -1
- package/dist/scripts/validate-against-cia-schemas.d.ts +0 -126
- package/dist/scripts/validate-against-cia-schemas.d.ts.map +0 -1
- package/dist/scripts/validate-against-cia-schemas.js +0 -299
- package/dist/scripts/validate-against-cia-schemas.js.map +0 -1
- package/dist/scripts/validate-cross-references.d.ts +0 -49
- package/dist/scripts/validate-cross-references.d.ts.map +0 -1
- package/dist/scripts/validate-cross-references.js +0 -183
- package/dist/scripts/validate-cross-references.js.map +0 -1
- package/dist/scripts/validate-file-ownership.d.ts +0 -68
- package/dist/scripts/validate-file-ownership.d.ts.map +0 -1
- package/dist/scripts/validate-file-ownership.js +0 -135
- package/dist/scripts/validate-file-ownership.js.map +0 -1
- package/dist/scripts/validate-news-translations.d.ts +0 -27
- package/dist/scripts/validate-news-translations.d.ts.map +0 -1
- package/dist/scripts/validate-news-translations.js +0 -258
- package/dist/scripts/validate-news-translations.js.map +0 -1
- package/dist/scripts/validate-translations.d.ts +0 -162
- package/dist/scripts/validate-translations.d.ts.map +0 -1
- package/dist/scripts/validate-translations.js +0 -378
- package/dist/scripts/validate-translations.js.map +0 -1
- package/dist/scripts/workflow-state-coordinator.d.ts +0 -354
- package/dist/scripts/workflow-state-coordinator.d.ts.map +0 -1
- package/dist/scripts/workflow-state-coordinator.js +0 -876
- package/dist/scripts/workflow-state-coordinator.js.map +0 -1
- package/dist/scripts/world-bank-client.d.ts +0 -122
- package/dist/scripts/world-bank-client.d.ts.map +0 -1
- package/dist/scripts/world-bank-client.js +0 -192
- package/dist/scripts/world-bank-client.js.map +0 -1
- package/dist/scripts/world-bank-context.d.ts +0 -88
- package/dist/scripts/world-bank-context.d.ts.map +0 -1
- package/dist/scripts/world-bank-context.js +0 -331
- package/dist/scripts/world-bank-context.js.map +0 -1
|
@@ -1,642 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env tsx
|
|
2
|
-
/**
|
|
3
|
-
* @module pre-article-analysis
|
|
4
|
-
* @description Pre-article data download and deep analysis pipeline.
|
|
5
|
-
*
|
|
6
|
-
* Orchestrates all analysis steps before article generation:
|
|
7
|
-
* 1. Download all relevant parliamentary documents from riksdag-regering-mcp
|
|
8
|
-
* 2. Political classification — Classify each document by significance, impact, domain
|
|
9
|
-
* 3. Risk assessment — Assess political risks (coalition stability, anomaly detection)
|
|
10
|
-
* 4. SWOT analysis — Generate political SWOT for relevant actors
|
|
11
|
-
* 5. Threat analysis — Identify threats from SWOT contributions
|
|
12
|
-
* 6. Stakeholder perspective analysis — Run all 6 lenses
|
|
13
|
-
* 7. Significance scoring — Score all documents (0–10)
|
|
14
|
-
* 8. Cross-reference mapping — Identify relationships between documents
|
|
15
|
-
* 9. Synthesis — Combined analysis summary integrating all methods
|
|
16
|
-
* 10. Persist — Write structured markdown to analysis/daily/YYYY-MM-DD/
|
|
17
|
-
*
|
|
18
|
-
* Usage:
|
|
19
|
-
* npx tsx scripts/pre-article-analysis.ts [--date YYYY-MM-DD] [--limit N]
|
|
20
|
-
* npx tsx scripts/pre-article-analysis.ts --aggregate weekly [--date YYYY-WNN]
|
|
21
|
-
*
|
|
22
|
-
* @author Hack23 AB
|
|
23
|
-
* @license Apache-2.0
|
|
24
|
-
*/
|
|
25
|
-
import fs from 'node:fs';
|
|
26
|
-
import path from 'node:path';
|
|
27
|
-
import { fileURLToPath } from 'node:url';
|
|
28
|
-
import { MCPClient } from './mcp-client/client.js';
|
|
29
|
-
import { calculateCoalitionRiskIndex, detectAnomalousPatterns } from './data-transformers/risk-analysis.js';
|
|
30
|
-
import { loadCIAContext } from './news-types/weekly-review/index.js';
|
|
31
|
-
import { normalizedCIAContext } from './news-types/weekly-review/data-loader.js';
|
|
32
|
-
import { downloadAllDocuments, flattenDocuments, } from './pre-article-analysis/data-downloader.js';
|
|
33
|
-
import { persistDownloadedData } from './pre-article-analysis/data-persistence.js';
|
|
34
|
-
import { serializeDataManifest, serializeClassificationResults, serializeRiskAssessment, serializeSwotAnalysis, serializeThreatAnalysis, serializeStakeholderPerspectives, serializeSignificanceScoring, serializeCrossReferenceMap, serializeSynthesisSummary, serializeDocumentAnalysis, sanitizeDokId, } from './pre-article-analysis/markdown-serializer.js';
|
|
35
|
-
// ---------------------------------------------------------------------------
|
|
36
|
-
// Constants
|
|
37
|
-
// ---------------------------------------------------------------------------
|
|
38
|
-
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
39
|
-
const REPO_ROOT = path.resolve(__dirname, '..');
|
|
40
|
-
const ANALYSIS_DIR = path.join(REPO_ROOT, 'analysis');
|
|
41
|
-
function formatTimestampForMarkdown(date = new Date()) {
|
|
42
|
-
return date.toISOString().slice(0, 16).replace('T', ' ') + ' UTC';
|
|
43
|
-
}
|
|
44
|
-
// ---------------------------------------------------------------------------
|
|
45
|
-
// CLI helpers
|
|
46
|
-
// ---------------------------------------------------------------------------
|
|
47
|
-
export function parseArgs(argv) {
|
|
48
|
-
const args = argv.slice(2);
|
|
49
|
-
const get = (flag) => {
|
|
50
|
-
const idx = args.indexOf(flag);
|
|
51
|
-
if (idx === -1) {
|
|
52
|
-
return null;
|
|
53
|
-
}
|
|
54
|
-
const next = args[idx + 1];
|
|
55
|
-
if (!next || next.startsWith('--')) {
|
|
56
|
-
throw new Error(`Missing value for ${flag}.`);
|
|
57
|
-
}
|
|
58
|
-
return next;
|
|
59
|
-
};
|
|
60
|
-
const dateArg = get('--date');
|
|
61
|
-
const aggregateArg = get('--aggregate');
|
|
62
|
-
const aggregate = (() => {
|
|
63
|
-
if (aggregateArg === null) {
|
|
64
|
-
return false;
|
|
65
|
-
}
|
|
66
|
-
if (aggregateArg === 'weekly') {
|
|
67
|
-
return true;
|
|
68
|
-
}
|
|
69
|
-
throw new Error(`Invalid --aggregate value: ${aggregateArg}. Supported value: 'weekly'.`);
|
|
70
|
-
})();
|
|
71
|
-
const now = new Date();
|
|
72
|
-
const todayIso = now.toISOString().slice(0, 10);
|
|
73
|
-
// When aggregate weekly, --date supplies the week label (YYYY-WNN), not a
|
|
74
|
-
// calendar date. `date` is always a YYYY-MM-DD value (defaults to today).
|
|
75
|
-
const weekLabel = aggregate
|
|
76
|
-
? (dateArg || `${now.getUTCFullYear()}-W${isoWeekNumber(now).toString().padStart(2, '0')}`)
|
|
77
|
-
: null;
|
|
78
|
-
if (aggregate && weekLabel && !parseIsoWeekLabel(weekLabel)) {
|
|
79
|
-
throw new Error(`Invalid weekly --date value: ${weekLabel}. Expected YYYY-WNN.`);
|
|
80
|
-
}
|
|
81
|
-
if (dateArg && dateArg !== 'today' && !aggregate && !parseAndValidateIsoDate(dateArg)) {
|
|
82
|
-
throw new Error(`Invalid --date value: ${dateArg}. Expected YYYY-MM-DD or 'today'.`);
|
|
83
|
-
}
|
|
84
|
-
// In aggregate mode, date is always today; the week-specific field is weekLabel.
|
|
85
|
-
const isoDate = aggregate
|
|
86
|
-
? todayIso
|
|
87
|
-
: (dateArg === 'today' || !dateArg ? todayIso : dateArg);
|
|
88
|
-
const limitArg = get('--limit');
|
|
89
|
-
const DEFAULT_LIMIT = 20;
|
|
90
|
-
const parsedLimit = limitArg ? Number(limitArg) : DEFAULT_LIMIT;
|
|
91
|
-
if (!Number.isInteger(parsedLimit) || parsedLimit <= 0) {
|
|
92
|
-
throw new Error(`Invalid --limit value: ${limitArg}. Expected a positive integer.`);
|
|
93
|
-
}
|
|
94
|
-
const limit = parsedLimit;
|
|
95
|
-
const rm = get('--rm');
|
|
96
|
-
const docTypeArg = get('--doc-type');
|
|
97
|
-
const VALID_DOC_TYPES = ['propositions', 'motions', 'committeeReports', 'votes', 'speeches', 'questions', 'interpellations'];
|
|
98
|
-
const isDocumentTypeKey = (value) => VALID_DOC_TYPES.includes(value);
|
|
99
|
-
let docType = null;
|
|
100
|
-
if (docTypeArg !== null) {
|
|
101
|
-
if (!isDocumentTypeKey(docTypeArg)) {
|
|
102
|
-
throw new Error(`Invalid --doc-type value: ${docTypeArg}. Supported values: ${VALID_DOC_TYPES.join(', ')}.`);
|
|
103
|
-
}
|
|
104
|
-
docType = docTypeArg;
|
|
105
|
-
}
|
|
106
|
-
// --document-ids: Comma-separated Riksdag dok_id values for deep-inspection.
|
|
107
|
-
// When provided, these specific documents are fetched by ID and included in
|
|
108
|
-
// analysis regardless of their date, ensuring deep-inspection batch analysis
|
|
109
|
-
// files contain real content instead of "0 documents analyzed".
|
|
110
|
-
const documentIdsArg = get('--document-ids');
|
|
111
|
-
const DOK_ID_PATTERN = /^[A-Za-z0-9_-]+$/;
|
|
112
|
-
const documentIds = documentIdsArg
|
|
113
|
-
? documentIdsArg.split(',').map(id => id.trim()).filter(id => {
|
|
114
|
-
if (!id)
|
|
115
|
-
return false;
|
|
116
|
-
if (!DOK_ID_PATTERN.test(id)) {
|
|
117
|
-
console.warn(`⚠️ Skipping invalid document ID: ${id} (must be alphanumeric/hyphens/underscores only)`);
|
|
118
|
-
return false;
|
|
119
|
-
}
|
|
120
|
-
return true;
|
|
121
|
-
})
|
|
122
|
-
: [];
|
|
123
|
-
return { date: isoDate, aggregate, limit, weekLabel, rm, docType, documentIds };
|
|
124
|
-
}
|
|
125
|
-
function isoWeekNumber(date) {
|
|
126
|
-
const d = new Date(Date.UTC(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate()));
|
|
127
|
-
const dayNum = d.getUTCDay() || 7;
|
|
128
|
-
d.setUTCDate(d.getUTCDate() + 4 - dayNum);
|
|
129
|
-
const yearStart = new Date(Date.UTC(d.getUTCFullYear(), 0, 1));
|
|
130
|
-
return Math.ceil((((d.getTime() - yearStart.getTime()) / 86400000) + 1) / 7);
|
|
131
|
-
}
|
|
132
|
-
function parseAndValidateIsoDate(dateStr) {
|
|
133
|
-
const m = /^(\d{4})-(\d{2})-(\d{2})$/.exec(dateStr);
|
|
134
|
-
if (!m)
|
|
135
|
-
return null;
|
|
136
|
-
const year = Number(m[1]);
|
|
137
|
-
const month = Number(m[2]);
|
|
138
|
-
const day = Number(m[3]);
|
|
139
|
-
const d = new Date(Date.UTC(year, month - 1, day));
|
|
140
|
-
if (Number.isNaN(d.getTime()))
|
|
141
|
-
return null;
|
|
142
|
-
if (d.getUTCFullYear() !== year || d.getUTCMonth() + 1 !== month || d.getUTCDate() !== day)
|
|
143
|
-
return null;
|
|
144
|
-
return d;
|
|
145
|
-
}
|
|
146
|
-
function riksMoteFromDate(dateStr) {
|
|
147
|
-
const parsed = parseAndValidateIsoDate(dateStr) ?? new Date();
|
|
148
|
-
const year = parsed.getUTCFullYear();
|
|
149
|
-
const month = parsed.getUTCMonth() + 1;
|
|
150
|
-
if (month >= 10)
|
|
151
|
-
return `${year}/${String(year + 1).slice(-2)}`;
|
|
152
|
-
return `${year - 1}/${String(year).slice(-2)}`;
|
|
153
|
-
}
|
|
154
|
-
function parseIsoWeekLabel(label) {
|
|
155
|
-
const match = /^(\d{4})-W(\d{2})$/.exec(label);
|
|
156
|
-
if (!match)
|
|
157
|
-
return null;
|
|
158
|
-
const year = Number(match[1]);
|
|
159
|
-
const week = Number(match[2]);
|
|
160
|
-
if (week < 1 || week > 53)
|
|
161
|
-
return null;
|
|
162
|
-
return { year, week };
|
|
163
|
-
}
|
|
164
|
-
function isDateInIsoWeek(dateStr, weekLabel) {
|
|
165
|
-
const parsedDate = parseAndValidateIsoDate(dateStr);
|
|
166
|
-
const parsedWeek = parseIsoWeekLabel(weekLabel);
|
|
167
|
-
if (!parsedDate || !parsedWeek)
|
|
168
|
-
return false;
|
|
169
|
-
const isoThursday = new Date(parsedDate);
|
|
170
|
-
const dayNum = isoThursday.getUTCDay() || 7;
|
|
171
|
-
isoThursday.setUTCDate(isoThursday.getUTCDate() + 4 - dayNum);
|
|
172
|
-
const isoYear = isoThursday.getUTCFullYear();
|
|
173
|
-
const isoWeek = isoWeekNumber(parsedDate);
|
|
174
|
-
return isoYear === parsedWeek.year && isoWeek === parsedWeek.week;
|
|
175
|
-
}
|
|
176
|
-
// ---------------------------------------------------------------------------
|
|
177
|
-
// File utilities
|
|
178
|
-
// ---------------------------------------------------------------------------
|
|
179
|
-
function ensureDir(dir) {
|
|
180
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
181
|
-
}
|
|
182
|
-
function writeAnalysis(dir, filename, content) {
|
|
183
|
-
const filePath = path.join(dir, filename);
|
|
184
|
-
fs.writeFileSync(filePath, content, 'utf8');
|
|
185
|
-
console.log(` ✅ Written: ${path.relative(REPO_ROOT, filePath)}`);
|
|
186
|
-
}
|
|
187
|
-
/** Stub: returns empty analysis results. Real analysis is AI-driven in workflows. */
|
|
188
|
-
function analyzeDocuments(docs, _cia, _lang) {
|
|
189
|
-
return {
|
|
190
|
-
results: docs.map(d => ({
|
|
191
|
-
document: d,
|
|
192
|
-
overallSignificance: 0,
|
|
193
|
-
perspectives: [],
|
|
194
|
-
crossDocumentLinks: [],
|
|
195
|
-
keyInsights: [],
|
|
196
|
-
confidenceScore: 0,
|
|
197
|
-
})),
|
|
198
|
-
crossDocumentLinks: [],
|
|
199
|
-
};
|
|
200
|
-
}
|
|
201
|
-
function extractSwotSummaries(results) {
|
|
202
|
-
const map = new Map();
|
|
203
|
-
for (const result of results) {
|
|
204
|
-
for (const p of result.perspectives) {
|
|
205
|
-
for (const swotC of p.swotContribution) {
|
|
206
|
-
const key = swotC.forStakeholder;
|
|
207
|
-
if (!map.has(key)) {
|
|
208
|
-
map.set(key, { forStakeholder: key, strengths: [], weaknesses: [], opportunities: [], threats: [] });
|
|
209
|
-
}
|
|
210
|
-
const entry = map.get(key);
|
|
211
|
-
switch (swotC.quadrant) {
|
|
212
|
-
case 'strength':
|
|
213
|
-
entry.strengths.push(swotC.text);
|
|
214
|
-
break;
|
|
215
|
-
case 'weakness':
|
|
216
|
-
entry.weaknesses.push(swotC.text);
|
|
217
|
-
break;
|
|
218
|
-
case 'opportunity':
|
|
219
|
-
entry.opportunities.push(swotC.text);
|
|
220
|
-
break;
|
|
221
|
-
case 'threat':
|
|
222
|
-
entry.threats.push(swotC.text);
|
|
223
|
-
break;
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
// Deduplicate and cap
|
|
229
|
-
return [...map.values()].map(s => ({
|
|
230
|
-
...s,
|
|
231
|
-
strengths: [...new Set(s.strengths)].slice(0, 5),
|
|
232
|
-
weaknesses: [...new Set(s.weaknesses)].slice(0, 5),
|
|
233
|
-
opportunities: [...new Set(s.opportunities)].slice(0, 5),
|
|
234
|
-
threats: [...new Set(s.threats)].slice(0, 5),
|
|
235
|
-
}));
|
|
236
|
-
}
|
|
237
|
-
// ---------------------------------------------------------------------------
|
|
238
|
-
// Significance entries
|
|
239
|
-
// ---------------------------------------------------------------------------
|
|
240
|
-
function buildSignificanceEntries(results) {
|
|
241
|
-
return results.map(r => ({
|
|
242
|
-
dok_id: r.document.dok_id || 'N/A',
|
|
243
|
-
title: r.document.titel || r.document.title || r.document.dok_id || 'Unknown',
|
|
244
|
-
score: r.overallSignificance,
|
|
245
|
-
doctype: r.document.doktyp || 'unknown',
|
|
246
|
-
}));
|
|
247
|
-
}
|
|
248
|
-
// ---------------------------------------------------------------------------
|
|
249
|
-
// Risk assessment
|
|
250
|
-
// ---------------------------------------------------------------------------
|
|
251
|
-
function buildRiskAssessment(docs, ciaContext) {
|
|
252
|
-
const normalizedContext = normalizedCIAContext(ciaContext);
|
|
253
|
-
// Attempt to derive basic coalition signals from document data
|
|
254
|
-
const riskIndex = calculateCoalitionRiskIndex(normalizedContext);
|
|
255
|
-
const anomalies = detectAnomalousPatterns(normalizedContext);
|
|
256
|
-
// Derive implications from document significance
|
|
257
|
-
const highSignificance = docs.filter(d => {
|
|
258
|
-
const titleText = (d.titel || d.title || '').toLowerCase();
|
|
259
|
-
return (d.doktyp === 'prop' ||
|
|
260
|
-
titleText.includes('budget') ||
|
|
261
|
-
titleText.includes('försvar') ||
|
|
262
|
-
titleText.includes('nato'));
|
|
263
|
-
});
|
|
264
|
-
const implications = [
|
|
265
|
-
`${docs.length} documents analyzed for risk indicators`,
|
|
266
|
-
`${highSignificance.length} high-significance documents identified`,
|
|
267
|
-
riskIndex.level !== 'LOW'
|
|
268
|
-
? `Coalition stability at ${riskIndex.level} risk — monitor upcoming votes`
|
|
269
|
-
: 'Coalition stability appears stable based on available data',
|
|
270
|
-
];
|
|
271
|
-
return {
|
|
272
|
-
coalitionRiskScore: riskIndex.score,
|
|
273
|
-
riskLevel: riskIndex.level,
|
|
274
|
-
riskSummary: riskIndex.summary,
|
|
275
|
-
anomalyFlags: anomalies.map(a => ({
|
|
276
|
-
type: a.type,
|
|
277
|
-
severity: a.severity,
|
|
278
|
-
description: a.description,
|
|
279
|
-
})),
|
|
280
|
-
implications,
|
|
281
|
-
};
|
|
282
|
-
}
|
|
283
|
-
// ---------------------------------------------------------------------------
|
|
284
|
-
// Synthesis
|
|
285
|
-
// ---------------------------------------------------------------------------
|
|
286
|
-
function buildSynthesis(docs, significanceEntries, riskResult) {
|
|
287
|
-
const totalDocs = docs.length;
|
|
288
|
-
const topDocs = [...significanceEntries].sort((a, b) => b.score - a.score).slice(0, 10);
|
|
289
|
-
const avgScore = significanceEntries.length > 0
|
|
290
|
-
? significanceEntries.reduce((s, e) => s + e.score, 0) / significanceEntries.length
|
|
291
|
-
: 0;
|
|
292
|
-
const overallConfidence = totalDocs >= 20 ? 'HIGH' : totalDocs >= 10 ? 'MEDIUM' : 'LOW';
|
|
293
|
-
const keyFindings = [
|
|
294
|
-
`Analyzed ${totalDocs} parliamentary documents with avg significance ${avgScore.toFixed(1)}/10`,
|
|
295
|
-
`Coalition risk level: ${riskResult.riskLevel} (score: ${riskResult.coalitionRiskScore}/100)`,
|
|
296
|
-
`Top document: "${topDocs[0]?.title || 'N/A'}" (significance: ${topDocs[0]?.score ?? 0}/10)`,
|
|
297
|
-
];
|
|
298
|
-
if (riskResult.anomalyFlags.length > 0) {
|
|
299
|
-
keyFindings.push(`${riskResult.anomalyFlags.length} anomaly flag(s) detected requiring editorial attention`);
|
|
300
|
-
}
|
|
301
|
-
const executiveSummary = [
|
|
302
|
-
`Pre-article analysis completed for ${totalDocs} documents.`,
|
|
303
|
-
`Overall political risk: ${riskResult.riskLevel}.`,
|
|
304
|
-
`Average document significance: ${avgScore.toFixed(1)}/10.`,
|
|
305
|
-
overallConfidence === 'HIGH'
|
|
306
|
-
? 'High data coverage — analysis results are reliable for article generation.'
|
|
307
|
-
: 'Partial data coverage — treat analysis as directional guidance.',
|
|
308
|
-
].join(' ');
|
|
309
|
-
return {
|
|
310
|
-
totalDocs,
|
|
311
|
-
executiveSummary,
|
|
312
|
-
keyFindings,
|
|
313
|
-
topDocuments: topDocs,
|
|
314
|
-
overallConfidence,
|
|
315
|
-
aggregateRiskLevel: riskResult.riskLevel,
|
|
316
|
-
};
|
|
317
|
-
}
|
|
318
|
-
// ---------------------------------------------------------------------------
|
|
319
|
-
// Weekly aggregation
|
|
320
|
-
// ---------------------------------------------------------------------------
|
|
321
|
-
function runWeeklyAggregation(weekLabel) {
|
|
322
|
-
const weekDir = path.join(ANALYSIS_DIR, 'weekly', weekLabel);
|
|
323
|
-
ensureDir(weekDir);
|
|
324
|
-
const dailyRoot = path.join(ANALYSIS_DIR, 'daily');
|
|
325
|
-
let allSyntheses = '';
|
|
326
|
-
let includedDays = 0;
|
|
327
|
-
let aggregatedDocumentsAnalyzed = 0;
|
|
328
|
-
const parsedWeek = parseIsoWeekLabel(weekLabel);
|
|
329
|
-
if (!parsedWeek) {
|
|
330
|
-
throw new Error(`Invalid ISO week label: ${weekLabel}. Expected format YYYY-WNN`);
|
|
331
|
-
}
|
|
332
|
-
if (fs.existsSync(dailyRoot)) {
|
|
333
|
-
const dailyDirs = fs.readdirSync(dailyRoot).sort();
|
|
334
|
-
const KNOWN_DOC_TYPES = new Set([
|
|
335
|
-
'propositions', 'motions', 'committeeReports', 'votes',
|
|
336
|
-
'speeches', 'questions', 'interpellations',
|
|
337
|
-
]);
|
|
338
|
-
for (const dir of dailyDirs) {
|
|
339
|
-
if (!isDateInIsoWeek(dir, weekLabel))
|
|
340
|
-
continue;
|
|
341
|
-
// Look for synthesis in unscoped path first, then in known doc-type subdirectories
|
|
342
|
-
const unscopedSynth = path.join(dailyRoot, dir, 'synthesis-summary.md');
|
|
343
|
-
const dayDir = path.join(dailyRoot, dir);
|
|
344
|
-
const scopedSynthPaths = [];
|
|
345
|
-
if (fs.existsSync(dayDir) && fs.statSync(dayDir).isDirectory()) {
|
|
346
|
-
// Sort subdirectories for deterministic output across filesystems
|
|
347
|
-
for (const sub of fs.readdirSync(dayDir).sort()) {
|
|
348
|
-
if (!KNOWN_DOC_TYPES.has(sub))
|
|
349
|
-
continue;
|
|
350
|
-
const subSynth = path.join(dayDir, sub, 'synthesis-summary.md');
|
|
351
|
-
if (fs.existsSync(subSynth)) {
|
|
352
|
-
scopedSynthPaths.push(subSynth);
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
// Prefer the unscoped synthesis when it exists (canonical copy created by
|
|
357
|
-
// the copy-to-unscoped step). Otherwise include all scoped syntheses so
|
|
358
|
-
// no doc-type run is silently omitted.
|
|
359
|
-
const hasUnscoped = fs.existsSync(unscopedSynth);
|
|
360
|
-
const pathsToProcess = hasUnscoped ? [unscopedSynth] : scopedSynthPaths;
|
|
361
|
-
let dayHasSynthesis = false;
|
|
362
|
-
for (const synthPath of pathsToProcess) {
|
|
363
|
-
if (!fs.existsSync(synthPath))
|
|
364
|
-
continue;
|
|
365
|
-
const dailySynthesis = fs.readFileSync(synthPath, 'utf8');
|
|
366
|
-
const subDir = path.basename(path.dirname(synthPath));
|
|
367
|
-
const label = hasUnscoped ? dir : `${dir} (${subDir})`;
|
|
368
|
-
allSyntheses += `\n\n---\n\n## Day: ${label}\n\n${dailySynthesis}`;
|
|
369
|
-
if (!dayHasSynthesis) {
|
|
370
|
-
includedDays += 1;
|
|
371
|
-
dayHasSynthesis = true;
|
|
372
|
-
}
|
|
373
|
-
const docsMatch = /(?:^|\n)\*\*Documents Analyzed\*\*:\s*(\d+)/.exec(dailySynthesis);
|
|
374
|
-
if (docsMatch?.[1]) {
|
|
375
|
-
aggregatedDocumentsAnalyzed += Number(docsMatch[1]);
|
|
376
|
-
}
|
|
377
|
-
else {
|
|
378
|
-
console.warn(`[pre-analysis] Could not parse Documents Analyzed from ${synthPath}`);
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
const weeklyContent = buildWeeklySynthesisMarkdown({
|
|
384
|
-
weekLabel,
|
|
385
|
-
generatedAt: formatTimestampForMarkdown(),
|
|
386
|
-
documentsAnalyzed: aggregatedDocumentsAnalyzed,
|
|
387
|
-
daysIncluded: includedDays,
|
|
388
|
-
allSyntheses,
|
|
389
|
-
});
|
|
390
|
-
writeAnalysis(weekDir, 'weekly-synthesis.md', weeklyContent);
|
|
391
|
-
console.log(`\n✅ Weekly aggregation written to analysis/weekly/${weekLabel}/`);
|
|
392
|
-
}
|
|
393
|
-
export function buildWeeklySynthesisMarkdown(opts) {
|
|
394
|
-
const confidence = opts.documentsAnalyzed >= 20
|
|
395
|
-
? 'HIGH'
|
|
396
|
-
: (opts.documentsAnalyzed >= 8 ? 'MEDIUM' : 'LOW');
|
|
397
|
-
return [
|
|
398
|
-
`# Weekly Analysis Aggregation — ${opts.weekLabel}`,
|
|
399
|
-
'',
|
|
400
|
-
`**Generated**: ${opts.generatedAt}`,
|
|
401
|
-
'**Data Sources**: Aggregated from daily synthesis summaries',
|
|
402
|
-
`**Documents Analyzed**: ${opts.documentsAnalyzed}`,
|
|
403
|
-
`**Confidence**: ${confidence}`,
|
|
404
|
-
`**Period**: ${opts.weekLabel}`,
|
|
405
|
-
`**Days Included**: ${opts.daysIncluded}`,
|
|
406
|
-
'',
|
|
407
|
-
'## Summary',
|
|
408
|
-
'',
|
|
409
|
-
'Aggregation of daily analysis synthesis results for the week.',
|
|
410
|
-
'',
|
|
411
|
-
opts.allSyntheses || '_No daily analysis results found for this week._',
|
|
412
|
-
].join('\n');
|
|
413
|
-
}
|
|
414
|
-
// ---------------------------------------------------------------------------
|
|
415
|
-
// Main pipeline
|
|
416
|
-
// ---------------------------------------------------------------------------
|
|
417
|
-
async function runPreArticleAnalysis(opts) {
|
|
418
|
-
const { date, limit, aggregate, weekLabel, rm, docType, documentIds } = opts;
|
|
419
|
-
if (aggregate && weekLabel) {
|
|
420
|
-
console.log(`\n📅 Running weekly aggregation for: ${weekLabel}`);
|
|
421
|
-
runWeeklyAggregation(weekLabel);
|
|
422
|
-
return;
|
|
423
|
-
}
|
|
424
|
-
console.log(`\n🚀 Pre-Article Analysis Pipeline — ${date}`);
|
|
425
|
-
console.log('='.repeat(50));
|
|
426
|
-
// When --doc-type is specified, scope output to a subdirectory to avoid
|
|
427
|
-
// conflicts between parallel workflow runs (e.g. propositions vs committee-reports).
|
|
428
|
-
const outputDir = docType
|
|
429
|
-
? path.join(ANALYSIS_DIR, 'daily', date, docType)
|
|
430
|
-
: path.join(ANALYSIS_DIR, 'daily', date);
|
|
431
|
-
ensureDir(outputDir);
|
|
432
|
-
const generatedAt = formatTimestampForMarkdown();
|
|
433
|
-
// ── Step 1: Download data ─────────────────────────────────────────────────
|
|
434
|
-
console.log('\n📥 Step 1: Downloading documents from riksdag-regering-mcp...');
|
|
435
|
-
if (docType) {
|
|
436
|
-
console.log(` 📋 Scoped to document type: ${docType}`);
|
|
437
|
-
}
|
|
438
|
-
const client = new MCPClient();
|
|
439
|
-
const resolvedRm = rm ?? riksMoteFromDate(date);
|
|
440
|
-
const downloadOpts = { limit, rm: resolvedRm };
|
|
441
|
-
if (docType) {
|
|
442
|
-
downloadOpts.docTypes = [docType];
|
|
443
|
-
}
|
|
444
|
-
const { data, manifest } = await downloadAllDocuments(client, downloadOpts);
|
|
445
|
-
const flattenedDocs = flattenDocuments(data);
|
|
446
|
-
// Build a set of explicitly requested document IDs for deep-inspection bypass.
|
|
447
|
-
const requestedIdSet = new Set(documentIds.map(id => id.toUpperCase()));
|
|
448
|
-
const allDocs = flattenedDocs.filter((doc) => {
|
|
449
|
-
// Documents explicitly requested by ID are ALWAYS included regardless of date.
|
|
450
|
-
// This is critical for deep-inspection which targets specific documents that
|
|
451
|
-
// may have been published on previous days.
|
|
452
|
-
const docId = doc.dok_id ?? '';
|
|
453
|
-
if (requestedIdSet.size > 0 && requestedIdSet.has(docId.toUpperCase())) {
|
|
454
|
-
return true;
|
|
455
|
-
}
|
|
456
|
-
// Only keep documents whose datum matches the requested analysis date (YYYY-MM-DD).
|
|
457
|
-
if (doc.datum && typeof doc.datum === 'string') {
|
|
458
|
-
return doc.datum.slice(0, 10) === date;
|
|
459
|
-
}
|
|
460
|
-
return false;
|
|
461
|
-
});
|
|
462
|
-
// If document IDs were requested but not found in the bulk download, attempt
|
|
463
|
-
// to fetch them individually via fetchDocumentDetails so deep-inspection always has data.
|
|
464
|
-
if (requestedIdSet.size > 0) {
|
|
465
|
-
const foundIds = new Set(allDocs.map((d) => (d.dok_id ?? '').toUpperCase()));
|
|
466
|
-
const missingIds = documentIds.filter(id => !foundIds.has(id.toUpperCase()));
|
|
467
|
-
if (missingIds.length > 0) {
|
|
468
|
-
console.log(` 🔍 Fetching ${missingIds.length} targeted document(s) by ID: ${missingIds.join(', ')}`);
|
|
469
|
-
for (const dokId of missingIds) {
|
|
470
|
-
try {
|
|
471
|
-
const result = await client.fetchDocumentDetails(dokId, false);
|
|
472
|
-
if (result && typeof result === 'object') {
|
|
473
|
-
const doc = result;
|
|
474
|
-
if (!doc.dok_id) {
|
|
475
|
-
doc.dok_id = dokId;
|
|
476
|
-
}
|
|
477
|
-
allDocs.push(doc);
|
|
478
|
-
console.log(` ✅ Fetched document ${dokId}: ${doc.titel ?? doc.title ?? '(no title)'}`);
|
|
479
|
-
}
|
|
480
|
-
}
|
|
481
|
-
catch (err) {
|
|
482
|
-
console.warn(` ⚠️ Failed to fetch document ${dokId}: ${err instanceof Error ? err.message : String(err)}`);
|
|
483
|
-
}
|
|
484
|
-
}
|
|
485
|
-
}
|
|
486
|
-
}
|
|
487
|
-
const excludedDocsCount = flattenedDocs.length - allDocs.length;
|
|
488
|
-
console.log(` Downloaded ${flattenedDocs.length} unique documents from ${manifest.dataSources.length} MCP tools`);
|
|
489
|
-
console.log(` Selected ${allDocs.length} documents for analysis for ${date} (${excludedDocsCount} with missing or non-matching dates excluded)`);
|
|
490
|
-
console.log(` Duration: ${manifest.durationMs}ms`);
|
|
491
|
-
console.log(` Riksmöte: ${resolvedRm}`);
|
|
492
|
-
// ── Step 1a: Persist raw data to analysis/data/ for verification & reuse ──
|
|
493
|
-
console.log('\n🗄️ Step 1a: Persisting raw MCP data to analysis/data/...');
|
|
494
|
-
const persistResult = persistDownloadedData(data, resolvedRm);
|
|
495
|
-
console.log(` 🗄️ Persisted data for ${persistResult.written} documents to ${path.relative(REPO_ROOT, persistResult.dataRoot)}/ (${persistResult.skipped} skipped)`);
|
|
496
|
-
const ctx = {
|
|
497
|
-
date,
|
|
498
|
-
generatedAt,
|
|
499
|
-
dataSources: manifest.dataSources,
|
|
500
|
-
};
|
|
501
|
-
writeAnalysis(outputDir, 'data-download-manifest.md', serializeDataManifest(ctx, manifest.docCounts, allDocs.length));
|
|
502
|
-
// ── Step 1b: Store each downloaded document as JSON ─────────────────────
|
|
503
|
-
console.log('\n💾 Step 1b: Storing downloaded documents...');
|
|
504
|
-
const documentsDir = path.join(outputDir, 'documents');
|
|
505
|
-
ensureDir(documentsDir);
|
|
506
|
-
let storedCount = 0;
|
|
507
|
-
for (let i = 0; i < allDocs.length; i++) {
|
|
508
|
-
const doc = allDocs[i];
|
|
509
|
-
const dokId = doc.dok_id || doc.titel || doc.title || `unknown-doc-${i + 1}`;
|
|
510
|
-
const baseName = sanitizeDokId(dokId) || `unknown-doc-${i + 1}`;
|
|
511
|
-
let fileName = baseName;
|
|
512
|
-
let attempt = 0;
|
|
513
|
-
// Ensure no overwrite if two docs resolve to the same sanitised name.
|
|
514
|
-
while (fs.existsSync(path.join(documentsDir, `${fileName}.json`))) {
|
|
515
|
-
attempt++;
|
|
516
|
-
fileName = `${baseName}-${attempt}`;
|
|
517
|
-
}
|
|
518
|
-
const docJson = JSON.stringify(doc, null, 2);
|
|
519
|
-
fs.writeFileSync(path.join(documentsDir, `${fileName}.json`), docJson, 'utf8');
|
|
520
|
-
storedCount++;
|
|
521
|
-
}
|
|
522
|
-
console.log(` 💾 Stored ${storedCount} documents as JSON in ${path.relative(REPO_ROOT, documentsDir)}/`);
|
|
523
|
-
if (allDocs.length === 0) {
|
|
524
|
-
console.warn('\n⚠️ No documents downloaded. Analysis will be minimal.');
|
|
525
|
-
}
|
|
526
|
-
// ── Step 2: Classification ────────────────────────────────────────────────
|
|
527
|
-
console.log('\n🏷️ Step 2: Classifying documents...');
|
|
528
|
-
const ciaContext = loadCIAContext();
|
|
529
|
-
const batchResult = analyzeDocuments(allDocs, ciaContext, 'en');
|
|
530
|
-
// Cast stub results to the serializer's expected type — structurally compatible
|
|
531
|
-
// but TypeScript can't verify RawDocument against the index-signature document shape.
|
|
532
|
-
const serializableResults = batchResult.results;
|
|
533
|
-
writeAnalysis(outputDir, 'classification-results.md', serializeClassificationResults(ctx, serializableResults));
|
|
534
|
-
// ── Step 3: Risk assessment ───────────────────────────────────────────────
|
|
535
|
-
console.log('\n⚠️ Step 3: Assessing political risks...');
|
|
536
|
-
const riskResult = buildRiskAssessment(allDocs, ciaContext);
|
|
537
|
-
writeAnalysis(outputDir, 'risk-assessment.md', serializeRiskAssessment(ctx, allDocs.length, riskResult));
|
|
538
|
-
// ── Step 4: SWOT analysis ─────────────────────────────────────────────────
|
|
539
|
-
console.log('\n📊 Step 4: Generating SWOT analysis...');
|
|
540
|
-
const swots = extractSwotSummaries(batchResult.results);
|
|
541
|
-
writeAnalysis(outputDir, 'swot-analysis.md', serializeSwotAnalysis(ctx, allDocs.length, swots));
|
|
542
|
-
// ── Step 5: Threat analysis ───────────────────────────────────────────────
|
|
543
|
-
console.log('\n🔴 Step 5: Analyzing threats...');
|
|
544
|
-
writeAnalysis(outputDir, 'threat-analysis.md', serializeThreatAnalysis(ctx, serializableResults));
|
|
545
|
-
// ── Step 6: Stakeholder perspectives ─────────────────────────────────────
|
|
546
|
-
console.log('\n👥 Step 6: Running stakeholder perspective analysis...');
|
|
547
|
-
writeAnalysis(outputDir, 'stakeholder-perspectives.md', serializeStakeholderPerspectives(ctx, serializableResults));
|
|
548
|
-
// ── Step 7: Significance scoring ─────────────────────────────────────────
|
|
549
|
-
console.log('\n📈 Step 7: Scoring document significance...');
|
|
550
|
-
const significanceEntries = buildSignificanceEntries(batchResult.results);
|
|
551
|
-
writeAnalysis(outputDir, 'significance-scoring.md', serializeSignificanceScoring(ctx, significanceEntries));
|
|
552
|
-
// ── Step 8: Cross-reference mapping ──────────────────────────────────────
|
|
553
|
-
console.log('\n🔗 Step 8: Mapping cross-document references...');
|
|
554
|
-
const crossRefSummary = {
|
|
555
|
-
docCount: allDocs.length,
|
|
556
|
-
totalLinks: batchResult.crossDocumentLinks.length,
|
|
557
|
-
links: batchResult.crossDocumentLinks,
|
|
558
|
-
};
|
|
559
|
-
writeAnalysis(outputDir, 'cross-reference-map.md', serializeCrossReferenceMap(ctx, crossRefSummary));
|
|
560
|
-
// ── Step 9: Synthesis ─────────────────────────────────────────────────────
|
|
561
|
-
console.log('\n🧩 Step 9: Synthesizing all analysis...');
|
|
562
|
-
const synthesis = buildSynthesis(allDocs, significanceEntries, riskResult);
|
|
563
|
-
writeAnalysis(outputDir, 'synthesis-summary.md', serializeSynthesisSummary(ctx, synthesis));
|
|
564
|
-
// ── Step 10: Per-document analysis files ─────────────────────────────────
|
|
565
|
-
console.log('\n📝 Step 10: Generating per-document analysis files...');
|
|
566
|
-
let perDocCount = 0;
|
|
567
|
-
for (let i = 0; i < batchResult.results.length; i++) {
|
|
568
|
-
const result = batchResult.results[i];
|
|
569
|
-
const dokId = result.document.dok_id || result.document.titel || result.document.title || `unknown-analysis-${i + 1}`;
|
|
570
|
-
const baseName = sanitizeDokId(dokId) || `unknown-analysis-${i + 1}`;
|
|
571
|
-
let fileName = `${baseName}-analysis.md`;
|
|
572
|
-
let attempt = 0;
|
|
573
|
-
// Ensure no overwrite if two docs resolve to the same sanitised name.
|
|
574
|
-
while (fs.existsSync(path.join(documentsDir, fileName))) {
|
|
575
|
-
attempt++;
|
|
576
|
-
fileName = `${baseName}-${attempt}-analysis.md`;
|
|
577
|
-
}
|
|
578
|
-
writeAnalysis(documentsDir, fileName, serializeDocumentAnalysis(ctx, result));
|
|
579
|
-
perDocCount++;
|
|
580
|
-
}
|
|
581
|
-
console.log(` 📝 Generated ${perDocCount} per-document analysis files`);
|
|
582
|
-
// ── Summary ───────────────────────────────────────────────────────────────
|
|
583
|
-
// When --doc-type is used, batch artifacts live under a subdirectory but
|
|
584
|
-
// existing consumers (analysis-reader.ts, getAnalysisEnrichment) read from
|
|
585
|
-
// the unscoped analysis/daily/<date>/ path. Copy the 9 batch artefacts to
|
|
586
|
-
// that location so downstream generators still find them. Per-document
|
|
587
|
-
// files intentionally stay only in the scoped directory.
|
|
588
|
-
if (docType) {
|
|
589
|
-
const unscopedDir = path.join(ANALYSIS_DIR, 'daily', date);
|
|
590
|
-
ensureDir(unscopedDir);
|
|
591
|
-
const batchFiles = [
|
|
592
|
-
'data-download-manifest.md',
|
|
593
|
-
'classification-results.md',
|
|
594
|
-
'risk-assessment.md',
|
|
595
|
-
'swot-analysis.md',
|
|
596
|
-
'threat-analysis.md',
|
|
597
|
-
'stakeholder-perspectives.md',
|
|
598
|
-
'significance-scoring.md',
|
|
599
|
-
'cross-reference-map.md',
|
|
600
|
-
'synthesis-summary.md',
|
|
601
|
-
];
|
|
602
|
-
for (const file of batchFiles) {
|
|
603
|
-
const src = path.join(outputDir, file);
|
|
604
|
-
const dest = path.join(unscopedDir, file);
|
|
605
|
-
if (fs.existsSync(src)) {
|
|
606
|
-
try {
|
|
607
|
-
// Use atomic create to avoid check-then-copy race under concurrency.
|
|
608
|
-
fs.copyFileSync(src, dest, fs.constants.COPYFILE_EXCL);
|
|
609
|
-
}
|
|
610
|
-
catch (error) {
|
|
611
|
-
const err = error;
|
|
612
|
-
if (err.code !== 'EEXIST') {
|
|
613
|
-
throw err;
|
|
614
|
-
}
|
|
615
|
-
// If the file already exists, another workflow created it first.
|
|
616
|
-
// This is expected in parallel runs; keep the existing unscoped copy.
|
|
617
|
-
}
|
|
618
|
-
}
|
|
619
|
-
}
|
|
620
|
-
console.log(` 📋 Copied batch artifacts to ${path.relative(REPO_ROOT, unscopedDir)}/ for enrichment readers`);
|
|
621
|
-
}
|
|
622
|
-
const totalFiles = 9 + perDocCount + storedCount;
|
|
623
|
-
console.log(`\n✅ Analysis complete! Results in: ${path.relative(REPO_ROOT, outputDir)}/`);
|
|
624
|
-
console.log(` 📄 ${totalFiles} total files written (9 batch + ${perDocCount} analyses + ${storedCount} documents)`);
|
|
625
|
-
console.log(` 📊 ${allDocs.length} documents analyzed`);
|
|
626
|
-
console.log(` 🎯 Overall confidence: ${synthesis.overallConfidence}`);
|
|
627
|
-
console.log(` ⚠️ Risk level: ${synthesis.aggregateRiskLevel}`);
|
|
628
|
-
if (docType) {
|
|
629
|
-
console.log(` 📋 Scoped to: ${docType}`);
|
|
630
|
-
}
|
|
631
|
-
}
|
|
632
|
-
// ---------------------------------------------------------------------------
|
|
633
|
-
// Entry point
|
|
634
|
-
// ---------------------------------------------------------------------------
|
|
635
|
-
if (path.resolve(fileURLToPath(import.meta.url)) === path.resolve(process.argv[1] ?? '')) {
|
|
636
|
-
const args = parseArgs(process.argv);
|
|
637
|
-
runPreArticleAnalysis(args).catch((err) => {
|
|
638
|
-
console.error('[pre-article-analysis] Fatal error:', err instanceof Error ? err.message : String(err));
|
|
639
|
-
process.exit(1);
|
|
640
|
-
});
|
|
641
|
-
}
|
|
642
|
-
//# sourceMappingURL=pre-article-analysis.js.map
|