euparliamentmonitor 0.8.19 → 0.8.21
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/package.json +7 -7
- package/scripts/constants/language-articles.d.ts +4 -0
- package/scripts/constants/language-articles.js +20 -0
- package/scripts/constants/language-ui.d.ts +8 -8
- package/scripts/constants/language-ui.js +64 -64
- package/scripts/constants/languages.d.ts +2 -2
- package/scripts/constants/languages.js +2 -2
- package/scripts/generators/news-enhanced.js +13 -3
- package/scripts/generators/pipeline/analysis-classification.d.ts +49 -0
- package/scripts/generators/pipeline/analysis-classification.js +333 -0
- package/scripts/generators/pipeline/analysis-existing.d.ts +67 -0
- package/scripts/generators/pipeline/analysis-existing.js +547 -0
- package/scripts/generators/pipeline/analysis-helpers.d.ts +140 -0
- package/scripts/generators/pipeline/analysis-helpers.js +266 -0
- package/scripts/generators/pipeline/analysis-risk.d.ts +49 -0
- package/scripts/generators/pipeline/analysis-risk.js +417 -0
- package/scripts/generators/pipeline/analysis-stage.d.ts +19 -39
- package/scripts/generators/pipeline/analysis-stage.js +219 -1704
- package/scripts/generators/pipeline/analysis-threats.d.ts +41 -0
- package/scripts/generators/pipeline/analysis-threats.js +142 -0
- package/scripts/generators/pipeline/fetch-stage.d.ts +25 -15
- package/scripts/generators/pipeline/fetch-stage.js +293 -117
- package/scripts/generators/strategies/article-strategy.d.ts +126 -7
- package/scripts/generators/strategies/article-strategy.js +491 -1
- package/scripts/generators/strategies/breaking-news-strategy.js +98 -8
- package/scripts/generators/strategies/committee-reports-strategy.js +23 -2
- package/scripts/generators/strategies/month-ahead-strategy.js +23 -2
- package/scripts/generators/strategies/monthly-review-strategy.js +13 -1
- package/scripts/generators/strategies/motions-strategy.js +15 -1
- package/scripts/generators/strategies/propositions-strategy.js +15 -1
- package/scripts/generators/strategies/week-ahead-strategy.js +19 -1
- package/scripts/generators/strategies/weekly-review-strategy.js +17 -1
- package/scripts/generators/synthesis-summary.d.ts +93 -0
- package/scripts/generators/synthesis-summary.js +364 -0
- package/scripts/index.d.ts +5 -2
- package/scripts/index.js +6 -1
- package/scripts/mcp/ep-mcp-client.d.ts +34 -1
- package/scripts/mcp/ep-mcp-client.js +110 -2
- package/scripts/mcp/mcp-connection.d.ts +3 -1
- package/scripts/mcp/mcp-connection.js +35 -4
- package/scripts/templates/article-template.js +24 -22
- package/scripts/templates/section-builders.js +2 -5
- package/scripts/types/index.d.ts +2 -1
- package/scripts/types/mcp.d.ts +7 -0
- package/scripts/types/political-classification.d.ts +1 -1
- package/scripts/types/quality.d.ts +9 -6
- package/scripts/types/significance.d.ts +130 -0
- package/scripts/types/significance.js +4 -0
- package/scripts/utils/article-quality-scorer.d.ts +13 -11
- package/scripts/utils/article-quality-scorer.js +36 -23
- package/scripts/utils/file-utils.d.ts +2 -2
- package/scripts/utils/file-utils.js +2 -2
- package/scripts/utils/html-sanitize.d.ts +10 -0
- package/scripts/utils/html-sanitize.js +32 -0
- package/scripts/utils/political-classification.d.ts +8 -7
- package/scripts/utils/political-classification.js +8 -7
- package/scripts/utils/political-risk-assessment.d.ts +1 -1
- package/scripts/utils/political-risk-assessment.js +1 -1
- package/scripts/utils/significance-scoring.d.ts +97 -0
- package/scripts/utils/significance-scoring.js +190 -0
|
@@ -0,0 +1,547 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2024-2026 Hack23 AB
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
/**
|
|
4
|
+
* @module Generators/Pipeline/AnalysisExisting
|
|
5
|
+
* @description Existing analysis method builders for the analysis pipeline.
|
|
6
|
+
*
|
|
7
|
+
* Contains markdown builders for the **Existing** analysis method group and
|
|
8
|
+
* cross-cutting meta methods:
|
|
9
|
+
* - `deep-analysis` — deep multi-perspective analysis
|
|
10
|
+
* - `stakeholder-analysis` — stakeholder impact analysis
|
|
11
|
+
* - `coalition-analysis` — coalition cohesion analysis
|
|
12
|
+
* - `voting-patterns` — voting pattern trend analysis
|
|
13
|
+
* - `cross-session-intelligence` — cross-session coalition intelligence
|
|
14
|
+
* - `synthesis-summary` — aggregated synthesis from all per-file analyses
|
|
15
|
+
* - `document-analysis` — per-document intelligence analysis (opt-in)
|
|
16
|
+
*/
|
|
17
|
+
import path from 'path';
|
|
18
|
+
import { detectVotingTrends, computeCrossSessionCoalitionStability, } from '../../utils/intelligence-analysis.js';
|
|
19
|
+
import { assessPoliticalSignificance } from '../../utils/political-classification.js';
|
|
20
|
+
import { assessPoliticalThreats } from '../../utils/political-threat-assessment.js';
|
|
21
|
+
import { buildQuantitativeSWOT, createScoredSWOTItem, createScoredOpportunityOrThreat, } from '../../utils/political-risk-assessment.js';
|
|
22
|
+
import { ensureDirectoryExists } from '../../utils/file-utils.js';
|
|
23
|
+
import { buildSynthesisSummary, formatSynthesisMarkdown } from '../synthesis-summary.js';
|
|
24
|
+
import { sanitizeCell, sanitizeDocumentId, DOCUMENT_FEED_KEYS, extractDocumentId, extractDocumentTitle, safeArr, toClassificationInput, toThreatInput, buildMarkdownHeader, writeTextFile, } from './analysis-helpers.js';
|
|
25
|
+
/** Analysis method identifier for synthesis summary */
|
|
26
|
+
export const METHOD_SYNTHESIS_SUMMARY_ID = 'synthesis-summary';
|
|
27
|
+
/** Analysis method identifier for per-document intelligence analysis */
|
|
28
|
+
export const METHOD_DOCUMENT_ANALYSIS = 'document-analysis';
|
|
29
|
+
// ─── Per-method markdown builders ────────────────────────────────────────────
|
|
30
|
+
/**
|
|
31
|
+
* Build markdown for the deep multi-perspective analysis.
|
|
32
|
+
* Outputs raw data metrics per stakeholder group for AI agent enrichment.
|
|
33
|
+
*
|
|
34
|
+
* @param fetchedData - Raw fetched EP data
|
|
35
|
+
* @param date - Analysis date
|
|
36
|
+
* @returns Markdown content string
|
|
37
|
+
*/
|
|
38
|
+
export function buildDeepAnalysisMarkdown(fetchedData, date) {
|
|
39
|
+
const header = buildMarkdownHeader('deep-analysis', date, 'high');
|
|
40
|
+
const events = safeArr(fetchedData, 'events');
|
|
41
|
+
const procedures = safeArr(fetchedData, 'procedures');
|
|
42
|
+
const documents = safeArr(fetchedData, 'documents');
|
|
43
|
+
const adoptedTexts = safeArr(fetchedData, 'adoptedTexts');
|
|
44
|
+
const questions = safeArr(fetchedData, 'questions');
|
|
45
|
+
const mepUpdates = safeArr(fetchedData, 'mepUpdates');
|
|
46
|
+
const total = events.length +
|
|
47
|
+
procedures.length +
|
|
48
|
+
documents.length +
|
|
49
|
+
adoptedTexts.length +
|
|
50
|
+
questions.length +
|
|
51
|
+
mepUpdates.length;
|
|
52
|
+
return (header +
|
|
53
|
+
`# Deep Multi-Perspective Analysis
|
|
54
|
+
|
|
55
|
+
## Pipeline Data Context
|
|
56
|
+
|
|
57
|
+
> **Note:** This section contains script-generated data inventory for reference. The AI agent must replace everything starting from the "AI Agent Instructions" heading below with substantive political intelligence analysis.
|
|
58
|
+
|
|
59
|
+
| Data Source | Count |
|
|
60
|
+
|-------------|-------|
|
|
61
|
+
| Events | ${events.length} |
|
|
62
|
+
| Procedures | ${procedures.length} |
|
|
63
|
+
| Documents | ${documents.length} |
|
|
64
|
+
| Adopted Texts | ${adoptedTexts.length} |
|
|
65
|
+
| Questions | ${questions.length} |
|
|
66
|
+
| MEP Updates | ${mepUpdates.length} |
|
|
67
|
+
| **Total** | **${total}** |
|
|
68
|
+
|
|
69
|
+
| Stakeholder Group | Data Points Available |
|
|
70
|
+
|-------------------|---------------------|
|
|
71
|
+
| Political Groups | ${procedures.length + adoptedTexts.length} (procedures + adopted texts) |
|
|
72
|
+
| Civil Society | ${documents.length + questions.length} (documents + questions) |
|
|
73
|
+
| Industry | ${procedures.length} (procedures) |
|
|
74
|
+
| National Governments | ${adoptedTexts.length} (adopted texts) |
|
|
75
|
+
| Citizens | ${questions.length + mepUpdates.length} (questions + MEP updates) |
|
|
76
|
+
| EU Institutions | ${events.length + procedures.length} (events + procedures) |
|
|
77
|
+
|
|
78
|
+
---
|
|
79
|
+
|
|
80
|
+
## AI Agent Instructions
|
|
81
|
+
|
|
82
|
+
> **Instructions for AI Agent (Opus 4.6):** Read ALL methodology documents in analysis/methodologies/ before writing. Using the data inventory above and the raw EP MCP data files, produce a deep multi-perspective analysis following the political-style-guide.md depth Level 3 format. Your analysis MUST:
|
|
83
|
+
>
|
|
84
|
+
> 1. **Identify the 3-5 most politically significant items** from the available data, citing specific document IDs
|
|
85
|
+
> 2. **Analyse each from ≥3 stakeholder perspectives** (Political Groups, Civil Society, Industry, National Governments, Citizens, EU Institutions)
|
|
86
|
+
> 3. **Apply the SWOT framework** to the overall parliamentary activity pattern for this date
|
|
87
|
+
> 4. **Assess coalition dynamics** — which groups are aligning/diverging based on the adopted texts?
|
|
88
|
+
> 5. **Rate confidence** for each analytical claim: HIGH / MEDIUM / LOW
|
|
89
|
+
> 6. **Provide forward-looking indicators** — what should be monitored in the next 7-14 days?
|
|
90
|
+
> 7. **Never leave scaffold markers** — replace this entire section with real analysis
|
|
91
|
+
>
|
|
92
|
+
> Evidence requirement: ≥3 citations per section from EP MCP data (document IDs, vote references, procedure numbers).
|
|
93
|
+
> Quality gate: minimum 500 words of original analytical prose with evidence citations.
|
|
94
|
+
> When done, REMOVE this instructions section entirely and write analysis prose directly.
|
|
95
|
+
|
|
96
|
+
[TO BE FILLED BY AI AGENT — This section must contain substantive political intelligence analysis, not data summaries. Quality gate: minimum 500 words of original analytical prose with evidence citations.]
|
|
97
|
+
|
|
98
|
+
## Date: ${date}
|
|
99
|
+
`);
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Build markdown for the stakeholder impact analysis.
|
|
103
|
+
*
|
|
104
|
+
* @param fetchedData - Raw fetched EP data
|
|
105
|
+
* @param date - Analysis date
|
|
106
|
+
* @returns Markdown content string
|
|
107
|
+
*/
|
|
108
|
+
export function buildStakeholderAnalysisMarkdown(fetchedData, date) {
|
|
109
|
+
const header = buildMarkdownHeader('stakeholder-analysis', date, 'high');
|
|
110
|
+
const procedures = safeArr(fetchedData, 'procedures');
|
|
111
|
+
const adoptedTexts = safeArr(fetchedData, 'adoptedTexts');
|
|
112
|
+
const documents = safeArr(fetchedData, 'documents');
|
|
113
|
+
const events = safeArr(fetchedData, 'events');
|
|
114
|
+
const questions = safeArr(fetchedData, 'questions');
|
|
115
|
+
const mepUpdates = safeArr(fetchedData, 'mepUpdates');
|
|
116
|
+
const votingRecords = safeArr(fetchedData, 'votingRecords');
|
|
117
|
+
const coalitions = safeArr(fetchedData, 'coalitions');
|
|
118
|
+
return (header +
|
|
119
|
+
`# Stakeholder Impact Analysis
|
|
120
|
+
|
|
121
|
+
## Data Available for Stakeholder Assessment (Script-Generated Context)
|
|
122
|
+
| Stakeholder Group | Primary Data Sources | Data Points |
|
|
123
|
+
|-------------------|---------------------|-------------|
|
|
124
|
+
| Political Groups | Procedures, Adopted Texts, Voting Records, Coalitions | ${procedures.length + adoptedTexts.length + votingRecords.length + coalitions.length} |
|
|
125
|
+
| Civil Society | Documents, Questions, Events | ${documents.length + questions.length + events.length} |
|
|
126
|
+
| Industry | Procedures, Adopted Texts | ${procedures.length + adoptedTexts.length} |
|
|
127
|
+
| National Governments | Adopted Texts, Procedures, Coalitions | ${adoptedTexts.length + procedures.length + coalitions.length} |
|
|
128
|
+
| Citizens | Questions, MEP Updates, Events | ${questions.length + mepUpdates.length + events.length} |
|
|
129
|
+
| EU Institutions | Events, Procedures, Adopted Texts, Voting Records | ${events.length + procedures.length + adoptedTexts.length + votingRecords.length} |
|
|
130
|
+
|
|
131
|
+
## Data Source Summary
|
|
132
|
+
| Source | Count |
|
|
133
|
+
|--------|-------|
|
|
134
|
+
${Object.keys(fetchedData)
|
|
135
|
+
.filter((k) => Array.isArray(fetchedData[k]))
|
|
136
|
+
.map((k) => `| ${k} | ${fetchedData[k].length} |`)
|
|
137
|
+
.join('\n')}
|
|
138
|
+
|
|
139
|
+
## AI Agent Instructions
|
|
140
|
+
|
|
141
|
+
> **Instructions for AI Agent (Opus 4.6):** Read ALL methodology documents in analysis/methodologies/. Using the stakeholder-impact.md template and the data inventory above, produce a stakeholder impact analysis for each of the 6 stakeholder groups. For each group:
|
|
142
|
+
>
|
|
143
|
+
> 1. **Impact direction**: positive / negative / neutral / mixed
|
|
144
|
+
> 2. **Impact severity**: high / medium / low
|
|
145
|
+
> 3. **Specific evidence**: Cite ≥2 specific EP documents, votes, or procedures that affect this stakeholder
|
|
146
|
+
> 4. **Reasoning**: 2-3 sentences explaining WHY this stakeholder is affected and HOW
|
|
147
|
+
> 5. **Action items**: What should this stakeholder watch or do in response?
|
|
148
|
+
> 6. **Confidence level**: HIGH / MEDIUM / LOW
|
|
149
|
+
>
|
|
150
|
+
> Focus on the MOST RECENT adopted texts and procedures. Do not produce generic stakeholder descriptions — every assessment must be grounded in specific EP data from this date period.
|
|
151
|
+
> When done, REMOVE this instructions section entirely and write analysis prose directly.
|
|
152
|
+
|
|
153
|
+
[TO BE FILLED BY AI AGENT — Each stakeholder group must have impact direction, severity, evidence citations, and reasoning. Quality gate: minimum 300 words of original analytical prose.]
|
|
154
|
+
|
|
155
|
+
## Date: ${date}
|
|
156
|
+
`);
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Build markdown for coalition cohesion analysis.
|
|
160
|
+
*
|
|
161
|
+
* @param fetchedData - Raw fetched EP data
|
|
162
|
+
* @param date - Analysis date
|
|
163
|
+
* @returns Markdown content string
|
|
164
|
+
*/
|
|
165
|
+
export function buildCoalitionAnalysisMarkdown(fetchedData, date) {
|
|
166
|
+
const header = buildMarkdownHeader('coalition-analysis', date, 'high');
|
|
167
|
+
const rawPatterns = Array.isArray(fetchedData['patterns']) ? fetchedData['patterns'] : [];
|
|
168
|
+
const stabilityReport = computeCrossSessionCoalitionStability(rawPatterns);
|
|
169
|
+
return (header +
|
|
170
|
+
`# Coalition Cohesion Analysis
|
|
171
|
+
|
|
172
|
+
## Computed Metrics (Script-Generated Context)
|
|
173
|
+
- **Overall Stability**: ${(stabilityReport.overallStability * 100).toFixed(1)}%
|
|
174
|
+
- **Forecast**: ${stabilityReport.forecast}
|
|
175
|
+
- **Patterns Analysed**: ${stabilityReport.patternCount}
|
|
176
|
+
- **Stable Groups**: ${stabilityReport.stableGroups.length > 0 ? stabilityReport.stableGroups.join(', ') : 'No stable groups identified from voting data'}
|
|
177
|
+
- **Declining Groups**: ${stabilityReport.decliningGroups.length > 0 ? stabilityReport.decliningGroups.join(', ') : 'No declining groups identified from voting data'}
|
|
178
|
+
- **Raw Patterns Evaluated**: ${rawPatterns.length}
|
|
179
|
+
|
|
180
|
+
## AI Agent Instructions
|
|
181
|
+
|
|
182
|
+
> **Instructions for AI Agent (Opus 4.6):** Read ALL methodology documents in analysis/methodologies/. Using the political-risk-methodology.md coalition risk framework and the computed metrics above, produce a coalition intelligence analysis. Your analysis MUST:
|
|
183
|
+
>
|
|
184
|
+
> 1. **Assess the Grand Coalition** (EPP + S&D + Renew): Is it holding? What are the stress points?
|
|
185
|
+
> 2. **Identify emerging alliances**: Are ECR, PfE, or Greens/EFA forming tactical voting blocs?
|
|
186
|
+
> 3. **Analyse abstention patterns**: High abstention rates signal internal group conflicts — identify which groups and why
|
|
187
|
+
> 4. **Cross-party voting**: Identify any cases where MEPs voted against their group line on recent adopted texts
|
|
188
|
+
> 5. **Predict coalition evolution**: Based on current patterns, which coalitions will strengthen/weaken in the next month?
|
|
189
|
+
> 6. **Confidence levels**: Rate each coalition assessment as HIGH / MEDIUM / LOW
|
|
190
|
+
>
|
|
191
|
+
> If voting data is limited (patterns analysed = 0), use adopted texts and political landscape data to infer coalition dynamics from the policy positions embedded in recent legislation.
|
|
192
|
+
> When done, REMOVE this instructions section entirely and write analysis prose directly.
|
|
193
|
+
|
|
194
|
+
[TO BE FILLED BY AI AGENT — Substantive coalition dynamics analysis with evidence citations, confidence levels, and forward-looking predictions. Quality gate: minimum 400 words.]
|
|
195
|
+
|
|
196
|
+
## Date: ${date}
|
|
197
|
+
`);
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Build markdown for voting pattern analysis.
|
|
201
|
+
*
|
|
202
|
+
* @param fetchedData - Raw fetched EP data
|
|
203
|
+
* @param date - Analysis date
|
|
204
|
+
* @returns Markdown content string
|
|
205
|
+
*/
|
|
206
|
+
export function buildVotingPatternsMarkdown(fetchedData, date) {
|
|
207
|
+
const header = buildMarkdownHeader('voting-patterns', date, 'high');
|
|
208
|
+
const rawRecords = Array.isArray(fetchedData['votingRecords'])
|
|
209
|
+
? fetchedData['votingRecords']
|
|
210
|
+
: [];
|
|
211
|
+
const trends = detectVotingTrends(rawRecords);
|
|
212
|
+
const trendsText = trends
|
|
213
|
+
.map((t) => `| ${t.trendId} | ${t.direction} | ${(t.confidence * 100).toFixed(0)}% | ${t.recordCount} records |`)
|
|
214
|
+
.join('\n');
|
|
215
|
+
return (header +
|
|
216
|
+
`# Voting Pattern Analysis
|
|
217
|
+
|
|
218
|
+
## Detected Trends (Script-Generated Context)
|
|
219
|
+
| Trend ID | Direction | Confidence | Data Points |
|
|
220
|
+
|----------|-----------|------------|-------------|
|
|
221
|
+
${trendsText || '| No trend data available from voting records | — | — | — |'}
|
|
222
|
+
|
|
223
|
+
## Computed Summary
|
|
224
|
+
- **Trends identified**: ${trends.length}
|
|
225
|
+
- **Records analysed**: ${rawRecords.length}
|
|
226
|
+
|
|
227
|
+
## AI Agent Instructions
|
|
228
|
+
|
|
229
|
+
> **Instructions for AI Agent (Opus 4.6):** Read ALL methodology documents in analysis/methodologies/. Using the voting pattern data above and the adopted texts from EP MCP feeds, produce a voting pattern intelligence analysis. Your analysis MUST:
|
|
230
|
+
>
|
|
231
|
+
> 1. **Identify voting blocs**: Which groups consistently vote together on recent adopted texts?
|
|
232
|
+
> 2. **Detect anomalies**: Any unexpected votes, close margins (<50 vote difference), or high abstention rates?
|
|
233
|
+
> 3. **Analyse by policy domain**: Do voting patterns differ between economic, environmental, and social legislation?
|
|
234
|
+
> 4. **Group discipline assessment**: Rate each major group's internal cohesion (high/medium/low) with evidence
|
|
235
|
+
> 5. **Trend detection**: Compare recent voting patterns to historical trends — is the Parliament becoming more/less fragmented?
|
|
236
|
+
> 6. **Forward-looking**: Which upcoming votes are likely to be contested based on current alignment patterns?
|
|
237
|
+
>
|
|
238
|
+
> If voting records are limited, analyse the adopted texts' policy positions to infer likely voting alignments and coalition patterns.
|
|
239
|
+
> When done, REMOVE this instructions section entirely and write analysis prose directly.
|
|
240
|
+
|
|
241
|
+
[TO BE FILLED BY AI AGENT — Substantive voting pattern analysis with specific vote references, group cohesion ratings, and anomaly detection. Quality gate: minimum 300 words.]
|
|
242
|
+
|
|
243
|
+
## Date: ${date}
|
|
244
|
+
`);
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Build markdown for cross-session intelligence analysis.
|
|
248
|
+
*
|
|
249
|
+
* @param fetchedData - Raw fetched EP data
|
|
250
|
+
* @param date - Analysis date
|
|
251
|
+
* @returns Markdown content string
|
|
252
|
+
*/
|
|
253
|
+
export function buildCrossSessionIntelligenceMarkdown(fetchedData, date) {
|
|
254
|
+
const header = buildMarkdownHeader('cross-session-intelligence', date, 'high');
|
|
255
|
+
const rawPatterns = Array.isArray(fetchedData['patterns']) ? fetchedData['patterns'] : [];
|
|
256
|
+
const stabilityReport = computeCrossSessionCoalitionStability(rawPatterns);
|
|
257
|
+
return (header +
|
|
258
|
+
`# Cross-Session Coalition Intelligence
|
|
259
|
+
|
|
260
|
+
## Computed Stability Metrics (Script-Generated Context)
|
|
261
|
+
- **Overall Stability**: ${(stabilityReport.overallStability * 100).toFixed(1)}%
|
|
262
|
+
- **Forecast**: ${stabilityReport.forecast}
|
|
263
|
+
- **Patterns Analysed**: ${stabilityReport.patternCount}
|
|
264
|
+
- **Stable Groups**: ${stabilityReport.stableGroups.length > 0 ? stabilityReport.stableGroups.join(', ') : 'None identified from voting data'}
|
|
265
|
+
- **Declining Groups**: ${stabilityReport.decliningGroups.length > 0 ? stabilityReport.decliningGroups.join(', ') : 'None identified from voting data'}
|
|
266
|
+
|
|
267
|
+
## AI Agent Instructions
|
|
268
|
+
|
|
269
|
+
> **Instructions for AI Agent (Opus 4.6):** Read ALL methodology documents in analysis/methodologies/. Using the cross-session stability metrics above and the adopted texts/voting records from recent plenary sessions, produce a cross-session intelligence synthesis. Your analysis MUST:
|
|
270
|
+
>
|
|
271
|
+
> 1. **Compare coalition patterns** across the last 3-5 plenary sessions — are alliances strengthening or fragmenting?
|
|
272
|
+
> 2. **Identify session-over-session trends**: Which policy areas show increasing/decreasing consensus?
|
|
273
|
+
> 3. **Detect coalition realignment signals**: Are new voting blocs forming? Is the Grand Coalition showing stress?
|
|
274
|
+
> 4. **Institutional dynamics**: How are EP-Council-Commission dynamics evolving based on recent legislative outcomes?
|
|
275
|
+
> 5. **Predictive assessment**: Based on cross-session patterns, forecast likely coalition behavior for upcoming votes
|
|
276
|
+
> 6. **Confidence levels**: Rate each finding as HIGH / MEDIUM / LOW
|
|
277
|
+
>
|
|
278
|
+
> Cross-reference with adopted texts from the most recent plenary session to ground the analysis in specific legislative outcomes.
|
|
279
|
+
> When done, REMOVE this instructions section entirely and write analysis prose directly.
|
|
280
|
+
|
|
281
|
+
[TO BE FILLED BY AI AGENT — Cross-session trend analysis with specific plenary session references, coalition evolution assessment, and predictive indicators. Quality gate: minimum 400 words.]
|
|
282
|
+
|
|
283
|
+
## Date: ${date}
|
|
284
|
+
`);
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Build markdown for the synthesis-summary method.
|
|
288
|
+
* Aggregates all per-file analyses into a synthesis summary.
|
|
289
|
+
*
|
|
290
|
+
* @param fetchedData - Raw fetched EP data (includes _dateOutputDir)
|
|
291
|
+
* @param date - Analysis date
|
|
292
|
+
* @returns Markdown content string
|
|
293
|
+
*/
|
|
294
|
+
export function buildSynthesisSummaryMarkdown(fetchedData, date) {
|
|
295
|
+
const dateOutputDir = String(fetchedData['_dateOutputDir'] ?? '');
|
|
296
|
+
if (!dateOutputDir) {
|
|
297
|
+
const header = buildMarkdownHeader(METHOD_SYNTHESIS_SUMMARY_ID, date, 'low');
|
|
298
|
+
return `${header}# 🧩 Synthesis Summary — ${date}\n\nNo output directory available for synthesis.\n`;
|
|
299
|
+
}
|
|
300
|
+
const summary = buildSynthesisSummary(dateOutputDir, date);
|
|
301
|
+
return formatSynthesisMarkdown(summary);
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* Build comprehensive analysis markdown for a single document.
|
|
305
|
+
*
|
|
306
|
+
* @param item - Raw document item from feed data
|
|
307
|
+
* @param docId - Document identifier
|
|
308
|
+
* @param title - Document title
|
|
309
|
+
* @param category - Feed category the document came from
|
|
310
|
+
* @param date - Analysis date
|
|
311
|
+
* @param significance - Precomputed global political significance
|
|
312
|
+
* @param threats - Precomputed global threat assessment
|
|
313
|
+
* @returns Markdown content for single document analysis
|
|
314
|
+
*/
|
|
315
|
+
function buildSingleDocumentAnalysis(item, docId, title, category, date, significance, threats) {
|
|
316
|
+
const docType = typeof item['type'] === 'string' ? item['type'] : category;
|
|
317
|
+
const docDate = typeof item['date'] === 'string' ? item['date'] : date;
|
|
318
|
+
const docStatus = typeof item['status'] === 'string' ? item['status'] : 'unknown';
|
|
319
|
+
const docStage = typeof item['stage'] === 'string' ? item['stage'] : 'N/A';
|
|
320
|
+
const docDescription = typeof item['description'] === 'string'
|
|
321
|
+
? item['description']
|
|
322
|
+
: typeof item['summary'] === 'string'
|
|
323
|
+
? item['summary']
|
|
324
|
+
: 'No description available';
|
|
325
|
+
const docStrengths = [
|
|
326
|
+
createScoredSWOTItem(`Document ${sanitizeDocumentId(docId)} available in ${category} feed`, 3, [`Document ID: ${docId}`, `Category: ${category}`, `Status: ${docStatus}`], 'medium', 'stable'),
|
|
327
|
+
];
|
|
328
|
+
const docWeaknesses = [
|
|
329
|
+
createScoredSWOTItem(`Document stage: ${docStage}, status: ${docStatus}`, 2, [`Current stage: ${docStage}`, `Type: ${docType}`, `Date: ${docDate}`], 'medium', 'stable'),
|
|
330
|
+
];
|
|
331
|
+
const docOpportunities = [
|
|
332
|
+
createScoredOpportunityOrThreat(`${category} document with ID ${sanitizeDocumentId(docId)}`, 'possible', 'moderate', [`Category: ${category}`, `Date: ${docDate}`], 'medium', 'stable'),
|
|
333
|
+
];
|
|
334
|
+
const docThreats = [
|
|
335
|
+
createScoredOpportunityOrThreat(`Document ${sanitizeDocumentId(docId)} — pipeline risk assessment`, 'possible', 'moderate', [`Stage: ${docStage}`, `Status: ${docStatus}`], 'medium', 'stable'),
|
|
336
|
+
];
|
|
337
|
+
const docSwot = buildQuantitativeSWOT(`SWOT: ${title}`, docStrengths, docWeaknesses, docOpportunities, docThreats);
|
|
338
|
+
return `---
|
|
339
|
+
method: ${METHOD_DOCUMENT_ANALYSIS}
|
|
340
|
+
documentId: ${JSON.stringify(docId)}
|
|
341
|
+
category: ${JSON.stringify(category)}
|
|
342
|
+
date: ${JSON.stringify(date)}
|
|
343
|
+
confidence: medium
|
|
344
|
+
generated: ${JSON.stringify(new Date().toISOString())}
|
|
345
|
+
---
|
|
346
|
+
|
|
347
|
+
# Document Analysis: ${sanitizeCell(title)}
|
|
348
|
+
|
|
349
|
+
## Document Metadata
|
|
350
|
+
|
|
351
|
+
| Field | Value |
|
|
352
|
+
|-------|-------|
|
|
353
|
+
| **Document ID** | ${sanitizeCell(docId)} |
|
|
354
|
+
| **Title** | ${sanitizeCell(title)} |
|
|
355
|
+
| **Type** | ${sanitizeCell(docType)} |
|
|
356
|
+
| **Category** | ${sanitizeCell(category)} |
|
|
357
|
+
| **Date** | ${sanitizeCell(docDate)} |
|
|
358
|
+
| **Status** | ${sanitizeCell(docStatus)} |
|
|
359
|
+
| **Stage** | ${sanitizeCell(docStage)} |
|
|
360
|
+
|
|
361
|
+
## Description
|
|
362
|
+
|
|
363
|
+
${sanitizeCell(docDescription)}
|
|
364
|
+
|
|
365
|
+
## Political Significance Assessment
|
|
366
|
+
|
|
367
|
+
- **Overall Significance**: ${significance.toUpperCase()}
|
|
368
|
+
- **Context**: Document ${sanitizeCell(docId)} within ${category} feed
|
|
369
|
+
|
|
370
|
+
## Document-Specific SWOT Analysis
|
|
371
|
+
|
|
372
|
+
### Strategic Position Score: ${docSwot.strategicPositionScore.toFixed(1)}/10
|
|
373
|
+
|
|
374
|
+
| Category | Score | Assessment |
|
|
375
|
+
|----------|-------|------------|
|
|
376
|
+
| Strengths | ${docSwot.strengths.reduce((s, i) => s + i.score, 0).toFixed(1)} | ${docSwot.strengths.map((s) => s.description).join('; ')} |
|
|
377
|
+
| Weaknesses | ${docSwot.weaknesses.reduce((s, i) => s + i.score, 0).toFixed(1)} | ${docSwot.weaknesses.map((w) => w.description).join('; ')} |
|
|
378
|
+
| Opportunities | ${docSwot.opportunities.reduce((s, i) => s + i.score, 0).toFixed(1)} | ${docSwot.opportunities.map((o) => o.description).join('; ')} |
|
|
379
|
+
| Threats | ${docSwot.threats.reduce((s, i) => s + i.score, 0).toFixed(1)} | ${docSwot.threats.map((t) => t.description).join('; ')} |
|
|
380
|
+
|
|
381
|
+
## Threat Assessment
|
|
382
|
+
|
|
383
|
+
- **Threat Dimensions Evaluated**: ${threats.threatDimensions.length}
|
|
384
|
+
- **Overall Threat Level**: ${threats.overallThreatLevel}
|
|
385
|
+
- **Assessment Date**: ${threats.date}
|
|
386
|
+
|
|
387
|
+
## Stakeholder Impact
|
|
388
|
+
|
|
389
|
+
| Stakeholder Group | Impact Level |
|
|
390
|
+
|-------------------|-------------|
|
|
391
|
+
| Political Groups | ${significance === 'routine' ? 'Low' : 'Medium'} |
|
|
392
|
+
| Civil Society | ${significance === 'routine' ? 'Low' : 'Medium'} |
|
|
393
|
+
| Industry | ${String(docType).toLowerCase() === 'resolution' || String(docType).toLowerCase() === 'directive' ? 'Medium' : 'Low'} |
|
|
394
|
+
| National Governments | ${String(docStage).toLowerCase() === 'trilogue' ? 'High' : 'Low'} |
|
|
395
|
+
| Citizens | Low |
|
|
396
|
+
| EU Institutions | ${significance === 'critical' || significance === 'historic' ? 'High' : 'Low'} |
|
|
397
|
+
|
|
398
|
+
## Intelligence Summary
|
|
399
|
+
|
|
400
|
+
| Metric | Value |
|
|
401
|
+
|--------|-------|
|
|
402
|
+
| Document | ${sanitizeCell(docId)} |
|
|
403
|
+
| Category | ${sanitizeCell(category)} |
|
|
404
|
+
| Type | ${sanitizeCell(docType)} |
|
|
405
|
+
| Stage | ${sanitizeCell(docStage)} |
|
|
406
|
+
| Status | ${sanitizeCell(docStatus)} |
|
|
407
|
+
| Significance | ${significance} |
|
|
408
|
+
| SWOT Score | ${docSwot.strategicPositionScore.toFixed(1)}/10 |
|
|
409
|
+
| Overall Assessment | ${docSwot.overallAssessment} |
|
|
410
|
+
| Threat Dimensions | ${threats.threatDimensions.length} |
|
|
411
|
+
| Overall Threat Level | ${threats.overallThreatLevel} |
|
|
412
|
+
|
|
413
|
+
## Analysis Date: ${date}
|
|
414
|
+
`;
|
|
415
|
+
}
|
|
416
|
+
/**
|
|
417
|
+
* Process a single feed item: deduplicate, write per-document files, and
|
|
418
|
+
* collect the index entry.
|
|
419
|
+
*
|
|
420
|
+
* @param raw - Raw feed item
|
|
421
|
+
* @param feedKey - Feed category key
|
|
422
|
+
* @param date - Analysis date string
|
|
423
|
+
* @param analyzedIds - Set of already-processed document IDs for deduplication
|
|
424
|
+
* @param docDir - Output directory for per-document markdown
|
|
425
|
+
* @param rawDataDir - Output directory for raw JSON data
|
|
426
|
+
* @param significance - Precomputed global political significance
|
|
427
|
+
* @param threats - Precomputed global threat assessment
|
|
428
|
+
* @returns Document entry for the index, or undefined if skipped
|
|
429
|
+
*/
|
|
430
|
+
function processDocumentItem(raw, feedKey, date, analyzedIds, docDir, rawDataDir, significance, threats) {
|
|
431
|
+
if (!raw || typeof raw !== 'object')
|
|
432
|
+
return undefined;
|
|
433
|
+
const item = raw;
|
|
434
|
+
const docId = extractDocumentId(item);
|
|
435
|
+
const dedupeKey = docId.toLowerCase().trim();
|
|
436
|
+
if (analyzedIds.has(dedupeKey))
|
|
437
|
+
return undefined;
|
|
438
|
+
analyzedIds.add(dedupeKey);
|
|
439
|
+
const title = extractDocumentTitle(item);
|
|
440
|
+
const safeId = sanitizeDocumentId(docId);
|
|
441
|
+
const filename = `${sanitizeDocumentId(feedKey)}-${safeId}-analysis.md`;
|
|
442
|
+
if (docDir) {
|
|
443
|
+
const docContent = buildSingleDocumentAnalysis(item, docId, title, feedKey, date, significance, threats);
|
|
444
|
+
writeTextFile(path.join(docDir, filename), docContent);
|
|
445
|
+
const rawJsonFilename = `${sanitizeDocumentId(feedKey)}-${safeId}-raw.json`;
|
|
446
|
+
writeTextFile(path.join(rawDataDir, rawJsonFilename), JSON.stringify(item, null, 2));
|
|
447
|
+
}
|
|
448
|
+
return { category: feedKey, id: docId, title, filename };
|
|
449
|
+
}
|
|
450
|
+
/**
|
|
451
|
+
* Build per-document intelligence analysis index and files.
|
|
452
|
+
*
|
|
453
|
+
* @param fetchedData - Raw fetched EP data
|
|
454
|
+
* @param date - Analysis date
|
|
455
|
+
* @returns Markdown index content string
|
|
456
|
+
*/
|
|
457
|
+
export function buildDocumentAnalysisMarkdown(fetchedData, date) {
|
|
458
|
+
const header = buildMarkdownHeader(METHOD_DOCUMENT_ANALYSIS, date, 'medium');
|
|
459
|
+
const dateOutputDir = fetchedData['_dateOutputDir'];
|
|
460
|
+
const outputBase = typeof dateOutputDir === 'string' ? dateOutputDir : '';
|
|
461
|
+
const docDir = outputBase ? path.join(outputBase, 'documents') : '';
|
|
462
|
+
const rawDataDir = outputBase ? path.join(outputBase, 'documents', 'raw-data') : '';
|
|
463
|
+
if (docDir)
|
|
464
|
+
ensureDirectoryExists(docDir);
|
|
465
|
+
if (rawDataDir)
|
|
466
|
+
ensureDirectoryExists(rawDataDir);
|
|
467
|
+
const globalInput = toClassificationInput(fetchedData);
|
|
468
|
+
const globalSignificance = assessPoliticalSignificance(globalInput);
|
|
469
|
+
const globalThreatInput = toThreatInput(fetchedData);
|
|
470
|
+
const globalThreats = assessPoliticalThreats(globalThreatInput);
|
|
471
|
+
const analyzedIds = new Set();
|
|
472
|
+
const documentEntries = [];
|
|
473
|
+
for (const feedKey of DOCUMENT_FEED_KEYS) {
|
|
474
|
+
const items = safeArr(fetchedData, feedKey);
|
|
475
|
+
for (const raw of items) {
|
|
476
|
+
const entry = processDocumentItem(raw, feedKey, date, analyzedIds, docDir, rawDataDir, globalSignificance, globalThreats);
|
|
477
|
+
if (entry)
|
|
478
|
+
documentEntries.push(entry);
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
Object.defineProperty(fetchedData, '_analyzedDocumentIds', {
|
|
482
|
+
value: [...analyzedIds],
|
|
483
|
+
writable: false,
|
|
484
|
+
configurable: true,
|
|
485
|
+
enumerable: false,
|
|
486
|
+
});
|
|
487
|
+
const tableRows = documentEntries.length > 0
|
|
488
|
+
? documentEntries
|
|
489
|
+
.map((d) => `| ${sanitizeCell(d.id)} | ${sanitizeCell(d.title.slice(0, 60))} | ${sanitizeCell(d.category)} | [${d.filename}](${d.filename}) |`)
|
|
490
|
+
.join('\n')
|
|
491
|
+
: '| — | No documents available | — | — |';
|
|
492
|
+
return (header +
|
|
493
|
+
`# Per-Document Intelligence Analysis Index
|
|
494
|
+
|
|
495
|
+
## Executive Summary
|
|
496
|
+
|
|
497
|
+
Full per-document political intelligence analysis for ${documentEntries.length} unique documents
|
|
498
|
+
across ${DOCUMENT_FEED_KEYS.length} feed categories. Each document has been individually
|
|
499
|
+
analyzed from fetched European Parliament data with comprehensive significance assessment,
|
|
500
|
+
SWOT analysis, and threat profiling.
|
|
501
|
+
|
|
502
|
+
- **Total Documents Analyzed**: ${documentEntries.length}
|
|
503
|
+
- **Feed Categories Scanned**: ${DOCUMENT_FEED_KEYS.length}
|
|
504
|
+
- **Duplicates Deduplicated**: ${[...DOCUMENT_FEED_KEYS].reduce((s, k) => s + safeArr(fetchedData, k).length, 0) - documentEntries.length}
|
|
505
|
+
- **Date**: ${date}
|
|
506
|
+
|
|
507
|
+
## Document Analysis Index
|
|
508
|
+
|
|
509
|
+
| Document ID | Title | Category | Analysis File |
|
|
510
|
+
|-------------|-------|----------|---------------|
|
|
511
|
+
${tableRows}
|
|
512
|
+
|
|
513
|
+
## Category Breakdown
|
|
514
|
+
|
|
515
|
+
${DOCUMENT_FEED_KEYS.map((k) => `- **${k}**: ${safeArr(fetchedData, k).length} items (${documentEntries.filter((d) => d.category === k).length} unique analyzed)`).join('\n')}
|
|
516
|
+
|
|
517
|
+
## Methodology
|
|
518
|
+
|
|
519
|
+
Each document receives:
|
|
520
|
+
1. **Raw Data Storage** — Full document JSON stored in \`documents/raw-data/\` for complete data preservation
|
|
521
|
+
2. **Significance Classification** — Political importance on 5-level scale
|
|
522
|
+
3. **SWOT Assessment** — Strengths, weaknesses, opportunities, threats specific to the document
|
|
523
|
+
4. **Threat Profiling** — Political threat landscape analysis for disruption potential
|
|
524
|
+
5. **Stakeholder Impact** — Projected effects on key stakeholder groups
|
|
525
|
+
6. **Intelligence Summary** — Key findings and actionable insights
|
|
526
|
+
|
|
527
|
+
## Document Storage
|
|
528
|
+
|
|
529
|
+
All ${documentEntries.length} documents have been stored in their entirety:
|
|
530
|
+
- **Analysis files**: \`documents/{category}-{id}-analysis.md\`
|
|
531
|
+
- **Raw JSON data**: \`documents/raw-data/{category}-{id}-raw.json\`
|
|
532
|
+
- **Deduplication**: Documents appearing in multiple feed categories are stored once with primary category reference
|
|
533
|
+
|
|
534
|
+
## Date: ${date}
|
|
535
|
+
`);
|
|
536
|
+
}
|
|
537
|
+
/** All existing analysis method builders keyed by their AnalysisMethod identifier */
|
|
538
|
+
export const EXISTING_BUILDERS = {
|
|
539
|
+
'deep-analysis': buildDeepAnalysisMarkdown,
|
|
540
|
+
'stakeholder-analysis': buildStakeholderAnalysisMarkdown,
|
|
541
|
+
'coalition-analysis': buildCoalitionAnalysisMarkdown,
|
|
542
|
+
'voting-patterns': buildVotingPatternsMarkdown,
|
|
543
|
+
'cross-session-intelligence': buildCrossSessionIntelligenceMarkdown,
|
|
544
|
+
[METHOD_SYNTHESIS_SUMMARY_ID]: buildSynthesisSummaryMarkdown,
|
|
545
|
+
[METHOD_DOCUMENT_ANALYSIS]: buildDocumentAnalysisMarkdown,
|
|
546
|
+
};
|
|
547
|
+
//# sourceMappingURL=analysis-existing.js.map
|