Skip to content

🔬 Deep-Inspection Generator: Multi-Iteration Intelligence Report Architecture#1163

Merged
pethers merged 46 commits intomainfrom
copilot/enhance-deep-inspection-generator
Mar 16, 2026
Merged

🔬 Deep-Inspection Generator: Multi-Iteration Intelligence Report Architecture#1163
pethers merged 46 commits intomainfrom
copilot/enhance-deep-inspection-generator

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 13, 2026

  • Re-check latest PR review thread and map all actionable comments
  • Investigate recent CI/workflow failures from GitHub Actions logs
  • Run baseline typecheck/tests before edits to confirm current status
  • Apply minimal fixes in generators.ts for review findings
  • Run targeted validation (TypeScript + touched tests)
  • Run code review and CodeQL checks
  • Reply to latest PR comment with commit hash and validation evidence
Original prompt

This section details on the original issue you should resolve

<issue_title>🔬 Deep-Inspection Generator Enhancement — Multi-Iteration AI Intelligence Reports</issue_title>
<issue_description>## 📋 Issue Type
Feature / Intelligence Enhancement

🎯 Objective

Enhance the deep-inspection generator (generators.ts:642-1690) to produce comprehensive AI-driven political intelligence reports with multi-iteration analysis, document cross-referencing, historical context, and predictive insights. Transform deep-inspection from a document summary tool into a full political intelligence assessment platform.

📊 Current State

  • generateDeepInspection() performs single-pass document analysis
  • generateDeepInspectionContent() creates 5 sections via template logic:
    1. Topic Context — static paragraph
    2. Document Intelligence — per-document 600-char analysis via generateDeepPolicyAnalysis()
    3. 5W Analysis — generateDeepAnalysisSection() cross-document synthesis
    4. Strategic Implications — template strings (only en/sv/de/fr/es)
    5. Key Takeaways — document type count bullet list
  • buildDeepInspectionSections() creates 4 template sections:
    1. Stakeholder SWOT (mechanical document classification)
    2. Dashboard (single bar chart: document counts by type)
    3. Mindmap (4 static branches)
    4. Sankey (document flow diagram)
  • No historical comparison or trend analysis
  • No confidence scoring on analysis
  • Strategic implications use hardcoded templates, not AI reasoning
  • No predictive or forecasting component
  • Limited to 5 languages for strategic implications (en/sv/de/fr/es)

🚀 Desired State

Deep Intelligence Report Architecture

Phase 1: Document Intelligence Collection

  • Fetch documents via MCP with full-text enrichment
  • AI classifies each document by: policy domain, urgency, stakeholder impact, legislative stage
  • Cross-reference documents to identify related legislation, preceding motions, follow-up committee reports

Phase 2: Multi-Iteration AI Analysis

Iteration 1: Surface-level analysis (what happened)
  → Identifies key events, actors, decisions
  
Iteration 2: Deep analysis (why it matters)
  → Analyzes motivations, power dynamics, strategic implications
  
Iteration 3: Predictive analysis (what happens next)
  → Forecasts outcomes, identifies risks, suggests scenarios
  
Iteration 4: Quality review (is the analysis sound)
  → Self-reviews for bias, completeness, accuracy
  → Flags low-confidence assessments

Phase 3: Multi-Perspective Intelligence Sections

  1. Executive Intelligence Summary — AI-generated 200-word overview for decision-makers
  2. Document Intelligence Matrix — AI-analyzed document grid (not just titles):
    • Policy domain classification
    • Legislative stage tracking
    • Cross-reference network
    • Stakeholder impact assessment
  3. Political Dynamics Analysis — AI-driven section replacing mechanical 5W:
    • Coalition stress indicators
    • Opposition strategy assessment
    • Media narrative analysis
    • Public opinion indicators
  4. Predictive Assessment — New section:
    • Likely legislative outcomes (with confidence %)
    • Coalition stability forecast
    • Policy implementation timeline
    • Risk scenarios (best/worst/most-likely)
  5. Historical Context — New section:
    • Precedent analysis (similar legislation outcomes)
    • Trend comparison (year-over-year changes)
    • International benchmarking (Nordic/EU comparison)
  6. Enhanced Stakeholder SWOT — See 📊 Enhanced Stakeholder SWOT Analysis with AI-Generated Multi-Perspective Intelligence #1143
  7. Multi-Panel Dashboard — See 📈 Interactive Dashboard Redesign with Advanced Charts and AI-Driven Metrics #1142
  8. AI Conceptual Mindmap — See 🧠 Mindmap Generator Redesign with AI-Driven Conceptual Mapping and Stakeholder Perspectives #1145
  9. Methodology & Confidence — New section:
    • Data sources and collection methods
    • Analysis methodology description
    • Confidence scores per section
    • Known limitations and caveats

Architecture Changes

  • Refactor generateDeepInspection() into modular pipeline:
    class DeepInspectionPipeline {
      async collect(params: DeepInspectionParams): Promise<DocumentCollection>;
      async analyze(collection: DocumentCollection, iteration: number): Promise<AnalysisResult>;
      async synthesize(analyses: AnalysisResult[]): Promise<IntelligenceReport>;
      async render(report: IntelligenceReport, lang: Language): Promise<string>;
      async validate(report: IntelligenceReport): Promise<QualityScore>;
    }
  • Move all deep-inspection logic from generators.ts to dedicated module:
    scripts/deep-inspection/pipeline.ts, analysis.ts, sections.ts, types.ts
  • Add --depth CLI parameter: quick (1 iteration), standard (3), deep (4+)

🔧 Implementation Approach

  1. Create scripts/deep-inspection/ module directory
  2. Implement DeepInspectionPipeline class with configurable depth
  3. Define AI prompts for each analysis iteration phase
  4. Implement predictive analysis with confidence scoring
  5. Add historical context via MCP document history queries
  6. Create executive su...

📍 Connect Copilot coding agent with Jira, Azure Boards or Linear to delegate work to Copilot in one click without leaving your project management tool.

…ence reports

- Add --depth CLI parameter (1-4) to config.ts, exported as analysisDepth
- Add buildExecutiveSummary() for decision-maker briefs (depth ≥ 3), all 14 languages
- Add buildPredictiveAssessment() with confidence %, coalition stability, risk scenarios (depth ≥ 2), all 14 languages
- Add buildHistoricalContext() with precedent analysis and Nordic/EU benchmarking (depth ≥ 2), all 14 languages
- Add buildMethodologySection() with data sources, iteration log, confidence score (depth ≥ 3), all 14 languages
- Add deriveConfidence() heuristic (0-100) with named constants for weights
- Extend buildStrategicImplications() from 5 languages to all 14
- Add new DEEP_SECTION_LABELS for executiveSummary, predictiveAssessment, historicalContext, methodology
- Update generateDeepInspectionContent() to accept depth parameter with depth-gated sections
- Create scripts/deep-inspection/index.ts with DeepInspectionPipeline class
- Add 13 tests in tests/deep-inspection-pipeline.test.ts

Co-authored-by: pethers <1726836+pethers@users.noreply.github.com>
Copilot AI changed the title [WIP] Enhance deep-inspection generator for multi-iteration reports 🔬 Deep-Inspection Generator: Multi-Iteration Intelligence Report Architecture Mar 13, 2026
Copilot AI requested a review from pethers March 13, 2026 17:05
@github-actions github-actions Bot added testing Test coverage refactor Code refactoring size-l Large change (250-1000 lines) labels Mar 14, 2026
@github-actions
Copy link
Copy Markdown
Contributor

🔍 Lighthouse Performance Audit

Category Score Status
Performance 85/100 🟡
Accessibility 95/100 🟢
Best Practices 90/100 🟢
SEO 95/100 🟢

📥 Download full Lighthouse report

Budget Compliance: Performance budgets enforced via budget.json

@github-actions
Copy link
Copy Markdown
Contributor

🔍 Lighthouse Performance Audit

Category Score Status
Performance 85/100 🟡
Accessibility 95/100 🟢
Best Practices 90/100 🟢
SEO 95/100 🟢

📥 Download full Lighthouse report

Budget Compliance: Performance budgets enforced via budget.json

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors the deep-inspection generator into a depth-gated (1–4) multi-iteration intelligence report with new sections and expanded 14-language template coverage, and introduces a small DeepInspectionPipeline wrapper plus initial Vitest coverage.

Changes:

  • Added --depth CLI parsing (analysisDepth) and used it to gate new deep-inspection sections (executive summary, predictive assessment, historical context, methodology/confidence).
  • Expanded buildStrategicImplications() templates from 5 to 14 languages.
  • Introduced scripts/deep-inspection/index.ts pipeline wrapper and added a new test suite.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 8 comments.

File Description
scripts/generate-news-enhanced/config.ts Parses --depth into analysisDepth (1–4) for deep-inspection runs.
scripts/generate-news-enhanced/generators.ts Adds depth-gated deep-inspection sections + 14-language strategic implications templates.
scripts/deep-inspection/index.ts Adds DeepInspectionPipeline wrapper API around generateDeepInspection().
tests/deep-inspection-pipeline.test.ts Adds Vitest coverage for config depth, pipeline exports, and template compilation.

: Math.max(MIN_PASSAGE_PROBABILITY, BASE_PASSAGE_PROBABILITY - motCount * OPPOSITION_MOTION_PENALTY);
const blockPct = 100 - passagePct;

const topicStr = topic ? esc(topic) : (lang === 'sv' ? 'detta område' : 'this area');
Comment on lines +1387 to +1389
da: `${topicStr ? `<strong>${topicStr}</strong> er del af` : 'Denne politik er del af'} en lang tradition for dansk parlamentarisk reform. ${domainList.length > 0 ? `I nordisk kontekst har ${domainList.join(', ')} historisk nydt gavn af tværpolitisk konsensus.` : ''} Trendanalyse viser, at politikken på dette område accelererer.`,
no: `${topicStr ? `<strong>${topicStr}</strong> er en del av` : 'Denne politikken er en del av'} en lang tradisjon for norsk parlamentarisk reform. ${domainList.length > 0 ? `I nordisk kontekst har ${domainList.join(', ')} historisk nytt godt av tverrpolitisk konsensus.` : ''} Trendanalyse indikerer at politikk på dette området akselererer.`,
fi: `${topicStr ? `<strong>${topicStr}</strong> on osa` : 'Tämä politiikka on osa'} pitkää suomalaista parlamentaarista uudistusperinnettä. ${domainList.length > 0 ? `Pohjoismaisessa kontekstissa ${domainList.join(', ')} aloilla on historiallisesti hyöty puolueiden välisestä yhteisymmärryksestä.` : ''} Trendanalyysi osoittaa, että tämän alan politiikka kiihtyy.`,
Comment on lines +1421 to +1424
da: ['Overfladeanalyse (hændelser og aktører identificeret)', 'Dybdeanalyse (motivationer og strategiske implikationer)', 'Prædiktiv analyse (prognoser og risikoscenarier)', 'Kvalitetsgennemgang (bias-tjek og fuldstændighedsverificering)'],
no: ['Overflateanalyse (hendelser og aktører identifisert)', 'Dybdeanalyse (motivasjoner og strategiske implikasjoner)', 'Prediktiv analyse (prognoser og risikoscenarier)', 'Kvalitetsgjennomgang (bias-sjekk og fullstendighetsverifisering)'],
fi: ['Pintaanalyysi (tapahtumat ja toimijat tunnistettu)', 'Syväanalyysi (motiivit ja strategiset vaikutukset)', 'Ennakoiva analyysi (ennusteet ja riskiskenaariot)', 'Laaduntarkistus (vinoutumien tarkistus ja kattavuuden varmennus)'],
de: ['Oberflächenanalyse (Ereignisse und Akteure identifiziert)', 'Tiefenanalyse (Motivationen und strategische Implikationen)', 'Prädiktive Analyse (Prognosen und Risikoszernarien)', 'Qualitätsprüfung (Bias-Prüfung und Vollständigkeitsverifikation)'],
Comment thread scripts/deep-inspection/index.ts Outdated
Comment on lines +23 to +27
* languages: ['en', 'sv'],
* });
* const result = await pipeline.run();
* ```
*
Comment thread tests/deep-inspection-pipeline.test.ts Outdated
Comment on lines +80 to +96
// We test the confidence logic indirectly via buildMethodologySection exports.
// The function is module-private, so test observable behavior via content checks.
describe('confidence score derivation (via section HTML)', () => {
it('confidence is between 0 and 100', () => {
// Heuristic formula: min(100, Math.round(enrichmentRate * 70) + docBonus)
// Test boundary: 0 docs → 0
const confOf = (enriched: number, total: number): number => {
if (total === 0) return 0;
const enrichmentRate = enriched / total;
const docBonus = Math.min(30, Math.round((total / 10) * 30));
return Math.min(100, Math.round(enrichmentRate * 70) + docBonus);
};
expect(confOf(0, 0)).toBe(0);
expect(confOf(5, 5)).toBe(85); // enrichment=100% (70pts) + docBonus=15 = 85
expect(confOf(0, 5)).toBe(15); // enrichment=0% + docBonus=15 = 15
expect(confOf(5, 10)).toBe(65); // enrichment=50% (35pts) + docBonus=30 = 65
expect(confOf(10, 10)).toBe(100); // enrichment=100% (70pts) + docBonus=30 = 100
Comment thread tests/deep-inspection-pipeline.test.ts Outdated
Comment on lines +156 to +161
// It's async (returns Promise)
const result = pipeline.run();
expect(result).toBeInstanceOf(Promise);
// We don't await it because it requires a live MCP connection;
// just verify it returns a Promise.
result.catch(() => {});
Comment on lines +120 to +133
async run(): Promise<DeepInspectionResult> {
const depth = this.params.depth ?? 1;
const topic = this.params.focusTopic;

console.log(`🔬 DeepInspectionPipeline starting — depth ${depth}: ${this.phaseLabel(depth)}`);
if (topic) console.log(` Topic: ${topic}`);

const result = await generateDeepInspection();

return {
...result,
depth,
topic,
};
Comment on lines +1274 to +1277
const headingPredictive = deepLabel('predictiveAssessment', lang);
const headingOutcome = deepLabel('likelyOutcome', lang);
const headingCoalition = deepLabel('coalitionStability', lang);
const headingRisk = deepLabel('riskScenarios', lang);
@pethers
Copy link
Copy Markdown
Member

pethers commented Mar 14, 2026

@copilot apply changes based on the comments in this thread and TypeScript & JavaScript Testing / Unit Tests (Vitest) (pull_request)
TypeScript & JavaScript Testing / Unit Tests (Vitest) (pull_request)Failing after 1m

- Add likelyOutcome/coalitionStability/riskScenarios labels to DEEP_SECTION_LABELS (all 14 langs)
- Localize topicStr fallback per language in buildPredictiveAssessment (was English-only)
- Fix da/no/fi historical context: use "svensk Riksdagsreform" / "Ruotsin valtiopäivien" (not Danish/Norwegian/Finnish)
- Fix German typo: "Risikoszernarien" → "Risikoszenarien"
- Fix pipeline example: remove non-existent languages property
- Pipeline run() now uses config analysisDepth instead of constructor param
- Fix pipeline test: check AsyncFunction without invoking run()
- Fix CI: update agentic-workflow-mcp-queries.test.ts for merged workflow changes

Co-authored-by: pethers <1726836+pethers@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 14, 2026

@copilot apply changes based on the comments in this thread and [TypeScript & JavaScript Testing / U...

All review comments addressed and CI failure fixed in fd4b967:

  • Added missing likelyOutcome, coalitionStability, riskScenarios labels to DEEP_SECTION_LABELS (all 14 languages)
  • Localized topicStr fallback per language in buildPredictiveAssessment() (was English-only for non-sv)
  • Fixed da/no/fi historical context to reference Swedish Riksdag reform ("svensk Riksdagsreform" / "Ruotsin valtiopäivien")
  • Fixed German typo: "Risikoszernarien" → "Risikoszenarien"
  • Removed non-existent languages property from pipeline JSDoc example
  • Pipeline run() now uses analysisDepth from config instead of constructor param
  • Replaced side-effect-prone pipeline.run() test with AsyncFunction constructor check
  • Fixed CI: updated agentic-workflow-mcp-queries.test.ts for merged news-evening-analysis.md changes (removed assertions for strings deleted in the merge)

@github-actions
Copy link
Copy Markdown
Contributor

🔍 Lighthouse Performance Audit

Category Score Status
Performance 85/100 🟡
Accessibility 95/100 🟢
Best Practices 90/100 🟢
SEO 95/100 🟢

📥 Download full Lighthouse report

Budget Compliance: Performance budgets enforced via budget.json

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds an analysis-depth concept to the deep-inspection generator to produce a more “intelligence report”-style output (executive summary, predictive assessment, historical context, methodology), and introduces a DeepInspectionPipeline wrapper module with accompanying test updates.

Changes:

  • Added --depth CLI parsing (analysisDepth 1–4) and wired it into deep-inspection generation.
  • Expanded deep-inspection HTML generation with depth-gated intelligence sections + 14-language strategic-implications/templates and new DEEP_SECTION_LABELS.
  • Added scripts/deep-inspection/ module entrypoint (DeepInspectionPipeline) and new/updated tests.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
tests/deep-inspection-pipeline.test.ts Adds coverage for analysisDepth parsing and new deep-inspection pipeline/module exports.
tests/agentic-workflow-mcp-queries.test.ts Updates workflow pattern assertions to match the current workflow doc content.
scripts/generate-news-enhanced/generators.ts Implements depth-gated deep-inspection sections, 14-language strategic implications, and logs depth.
scripts/generate-news-enhanced/config.ts Adds --depth parsing and exports analysisDepth (1–4).
scripts/deep-inspection/index.ts Introduces DeepInspectionPipeline wrapper class and types.

Comment on lines +1206 to +1212
const hasEnactedLaw = sfsDocs.length > 0;
const govLed = propCount > motCount;
const highScrutiny = betCount > 0;

const templates: Partial<Record<Language, string>> = {
en: `This deep-inspection intelligence report analyses ${docs.length} parliamentary document${docs.length !== 1 ? 's' : ''}${topic ? ` on <strong>${esc(topic)}</strong>` : ''}${domainPhrase ? `, spanning ${domainPhrase}` : ''}. Of these, ${enriched} ${enriched === 1 ? 'was' : 'were'} enriched with full text to enable substantive analysis. The legislative posture is ${govLed ? 'government-led' : 'opposition-driven'}, with ${propCount} proposition${propCount !== 1 ? 's' : ''} advancing the executive agenda${betCount > 0 ? `, ${betCount} committee report${betCount !== 1 ? 's' : ''} providing parliamentary scrutiny` : ''}${motCount > 0 ? `, and ${motCount} opposition motion${motCount !== 1 ? 's' : ''} challenging the direction` : ''}. ${hasEnactedLaw ? `${sfsDocs.length} statute${sfsDocs.length !== 1 ? 's' : ''} have already been enacted, establishing a legal baseline.` : highScrutiny ? 'Committee engagement indicates that the policy is under active parliamentary review, signalling that key decisions are imminent.' : 'The legislative pipeline remains at an early stage, requiring close monitoring for acceleration signals.'} ${domainPhrase ? `Policy domains engaged — ${domainPhrase} — reflect the cross-cutting nature of this initiative.` : 'The documents reflect focused policy engagement in this area.'} Decision-makers should prioritise tracking committee deliberations and chamber voting patterns as the most reliable forward indicators.`,
sv: `Denna djupanalys granskar ${docs.length} riksdagsdokument${topic ? ` rörande <strong>${esc(topic)}</strong>` : ''}${domainPhrase ? ` inom ${domainPhrase}` : ''}. Av dessa berikades ${enriched} med fulltext. Det lagstiftande läget är ${govLed ? 'regeringsledet' : 'oppositionsdrivet'} med ${propCount} proposition${propCount !== 1 ? 'er' : ''}, ${betCount > 0 ? `${betCount} utskottsbetänkande${betCount !== 1 ? 'n' : ''} som ger parlamentarisk granskning, ` : ''}${motCount > 0 ? `och ${motCount} opposition${motCount !== 1 ? 'smotioner' : 'smotion'} som ifrågasätter inriktningen` : ''}. ${hasEnactedLaw ? `${sfsDocs.length} lag${sfsDocs.length !== 1 ? 'ar' : ''} har redan antagits och fastställt ett rättsligt ramverk.` : highScrutiny ? 'Utskottsengagemanget visar att policyn är under aktiv parlamentarisk granskning.' : 'Lagstiftningspipelinen befinner sig i ett tidigt skede.'} Beslutsfattare bör prioritera att följa utskottens arbete och omröstningar i kammaren.`,
Comment on lines +1280 to +1285
const sfsDocs = docs.filter(d => (d.doktyp || d.documentType) === 'sfs');
const confidence = deriveConfidence(docs);

// Passage likelihood heuristic: if committee reports exceed motions → likely passage
const passageLikely = betCount > motCount || sfsDocs.length > 0;
const passagePct = passageLikely
const betCount = docs.filter(d => (d.doktyp || d.documentType) === 'bet').length;
const motCount = docs.filter(d => (d.doktyp || d.documentType) === 'mot').length;
const sfsDocs = docs.filter(d => (d.doktyp || d.documentType) === 'sfs');
const enriched = docs.filter(d => d.contentFetched).length;
*/
function buildMethodologySection(docs: RawDocument[], topic: string | null, lang: Language, depth: number): string {
const esc = escapeHtml;
const enriched = docs.filter(d => d.contentFetched).length;
Comment thread tests/deep-inspection-pipeline.test.ts Outdated
Comment on lines +74 to +79
it('pipeline run() is an async function without side effects on construction', async () => {
const { DeepInspectionPipeline } = await import('../scripts/deep-inspection/index.js');
const pipeline = new DeepInspectionPipeline();
// Verify run is an async function by checking its constructor name
expect(pipeline.run.constructor.name).toBe('AsyncFunction');
});
Comment on lines +1398 to +1404
const sfsDocs = docs.filter(d => (d.doktyp || d.documentType) === 'sfs');
const propCount = docs.filter(d => (d.doktyp || d.documentType) === 'prop').length;
const allDomains = new Set<string>();
docs.forEach(d => detectPolicyDomains(d, lang).forEach(dom => allDomains.add(dom)));
const domainList = [...allDomains].slice(0, 3).map(d => esc(d));
const hasEnacted = sfsDocs.length > 0;
const topicStr = topic ? esc(topic) : null;
Comment on lines +1247 to +1252
function deriveConfidence(docs: RawDocument[]): number {
if (docs.length === 0) return 0;
const enriched = docs.filter(d => d.contentFetched).length;
const enrichmentRate = enriched / docs.length; // 0–1
const docBonus = Math.min(MAX_DOCUMENT_BONUS, Math.round((docs.length / DOCUMENT_BONUS_DIVISOR) * MAX_DOCUMENT_BONUS));
return Math.min(100, Math.round(enrichmentRate * ENRICHMENT_WEIGHT) + docBonus);
Comment thread scripts/deep-inspection/index.ts Outdated
Comment on lines +53 to +65
/**
* Analysis depth (1–4):
* 1 — surface analysis (what happened) — default, fastest
* 2 — adds predictive assessment and historical context
* 3 — adds executive intelligence summary and methodology section
* 4 — full multi-iteration intelligence report with all sections
*
* **Note**: This must match the `--depth` CLI arg passed at process start,
* since config.ts reads it at module load time. Setting this here only
* affects log labels, not the actual generation depth.
*/
depth?: 1 | 2 | 3 | 4;
}
Comment on lines +119 to +132
async run(): Promise<DeepInspectionResult> {
const depth = analysisDepth;
const topic = this.params.focusTopic;

console.log(`🔬 DeepInspectionPipeline starting — depth ${depth}: ${this.phaseLabel(depth)}`);
if (topic) console.log(` Topic: ${topic}`);

const result = await generateDeepInspection();

return {
...result,
depth,
topic,
};
@pethers
Copy link
Copy Markdown
Member

pethers commented Mar 14, 2026

@copilot apply changes based on the comments in this thread

…eline API, test mock

- Fix SFS detection in buildExecutiveSummary, buildPredictiveAssessment, buildHistoricalContext,
  buildStrategicImplications to use dokumentnamn.startsWith('SFS') fallback (aligns with
  buildDeepInspectionSections pattern)
- Fix enrichment counting: use `fullText || fullContent` instead of `contentFetched` in
  deriveConfidence, buildExecutiveSummary, buildStrategicImplications, buildMethodologySection
  (contentFetched can be true without full text)
- Remove unused `depth`/`focusTopic` from DeepInspectionPipelineParams — these were
  misleading since the effective values come from CLI config
- Pipeline run() now sources topic from config.focusTopic instead of constructor params
- Replace fragile AsyncFunction constructor name test with mock-based approach: vi.mock
  generators at top level, assert pipeline.run() returns Promise and result has valid depth

Co-authored-by: pethers <1726836+pethers@users.noreply.github.com>
@pethers
Copy link
Copy Markdown
Member

pethers commented Mar 16, 2026

@copilot apply changes based on the comments in this thread

@github-actions
Copy link
Copy Markdown
Contributor

🔍 Lighthouse Performance Audit

Category Score Status
Performance 85/100 🟡
Accessibility 95/100 🟢
Best Practices 90/100 🟢
SEO 95/100 🟢

📥 Download full Lighthouse report

Budget Compliance: Performance budgets enforced via budget.json

Co-authored-by: pethers <1726836+pethers@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 16, 2026

@copilot apply changes based on the comments in this thread

Implemented all requested updates in 02056de.

  • Replaced brittle source-inspection in tests/deep-inspection-pipeline.test.ts with behavioral HTML assertions via internal test hook __deepInspectionTestHooks.generateDeepInspectionContent.
  • Made argv-mutating config tests sequential with describe.sequential(...).
  • Updated scripts/deep-inspection/index.ts docs to describe the actual wrapper behavior (delegation to generateDeepInspection()) instead of a claimed explicit 4-phase orchestrator.
  • Corrected depth-2 section-order doc comment in generators.ts to match rendered order (Historical Context before Predictive Assessment).
  • Relaxed formatting-sensitive regex in tests/agentic-workflow-mcp-queries.test.ts from />= fromDate/ to />=\s*fromDate/.

Validation run:

  • npx vitest run tests/deep-inspection-pipeline.test.ts tests/agentic-workflow-mcp-queries.test.ts
  • npx tsc -p tsconfig.scripts.json --noEmit
  • code_review (no comments)
  • codeql_checker (0 alerts)

No UI changes were made in this update, so there is no UI screenshot.

@github-actions
Copy link
Copy Markdown
Contributor

🔍 Lighthouse Performance Audit

Category Score Status
Performance 85/100 🟡
Accessibility 95/100 🟢
Best Practices 90/100 🟢
SEO 95/100 🟢

📥 Download full Lighthouse report

Budget Compliance: Performance budgets enforced via budget.json

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR extends the deep-inspection generator to support configurable multi-iteration “intelligence report” output (depth 1–4), adds new depth-gated report sections (executive summary, historical context, predictive assessment, methodology/confidence), and introduces a thin programmatic DeepInspectionPipeline wrapper with updated tests to validate the new behavior.

Changes:

  • Add --depth=1..4 CLI parsing (analysisDepth) and pass it into deep-inspection rendering to gate advanced sections.
  • Expand deep-inspection content with new localized section labels and new section builders (executive summary, historical context, predictive assessment, methodology/confidence).
  • Add/adjust Vitest coverage to assert depth-gating behavior and MCP workflow documentation requirements; introduce scripts/deep-inspection/index.ts wrapper.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
scripts/generate-news-enhanced/config.ts Adds --depth parsing and exports analysisDepth (1–4, default 1).
scripts/generate-news-enhanced/generators.ts Implements depth-gated deep-inspection sections + 14-language strategic implications; exports test hooks.
scripts/deep-inspection/index.ts Adds DeepInspectionPipeline wrapper delegating to generateDeepInspection().
tests/deep-inspection-pipeline.test.ts Adds behavioral tests for depth gating, labels, and pipeline exports.
tests/agentic-workflow-mcp-queries.test.ts Tightens/extends workflow-doc assertions for post-query filtering and cross-referencing.

Comment on lines +176 to +179
// Should have explicit >= fromDate filtering guidance
expect(content).toMatch(/>=\s*fromDate/);
// Should reference Filter results instruction
expect(content).toMatch(/Filter results/i);
Comment thread tests/deep-inspection-pipeline.test.ts Outdated
Comment on lines +171 to +173
it('depth 4 includes the quality-review methodology iteration', async () => {
const html = await render(4, 'en');
expect(html).toContain('Quality review (bias check and completeness verification)');
Comment thread tests/deep-inspection-pipeline.test.ts Outdated
Comment on lines +166 to +168
expect(html).toContain('Likely Outcome');
expect(html).toContain('Coalition Stability Forecast');
expect(html).toContain('Risk Scenarios');
@pethers
Copy link
Copy Markdown
Member

pethers commented Mar 16, 2026

@copilot apply changes based on the comments in this thread

Co-authored-by: pethers <1726836+pethers@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 16, 2026

@copilot apply changes based on the comments in this thread

Addressed in commit 48e63d5.

I made the requested assertions less brittle by switching to semantic/structural checks:

  • tests/deep-inspection-pipeline.test.ts: replaced exact predictive heading copy checks with predictive section structure checks (predictive-assessment section, h3 count, risk-scenarios class), and replaced exact methodology sentence matching with iteration count assertions (3 at depth 3, 4 at depth 4).
  • tests/agentic-workflow-mcp-queries.test.ts: replaced exact-phrase checks (>= fromDate, Filter results) with flexible semantic regex for fromDate comparison and post-query filtering guidance.

Validation run:

  • npx vitest run tests/deep-inspection-pipeline.test.ts tests/agentic-workflow-mcp-queries.test.ts
  • npx tsc -p tsconfig.scripts.json --noEmit
  • code_review (no comments)
  • codeql_checker (0 alerts)

No UI files were changed in this update, so no screenshot applies.

@github-actions
Copy link
Copy Markdown
Contributor

🔍 Lighthouse Performance Audit

Category Score Status
Performance 85/100 🟡
Accessibility 95/100 🟢
Best Practices 90/100 🟢
SEO 95/100 🟢

📥 Download full Lighthouse report

Budget Compliance: Performance budgets enforced via budget.json

Signed-off-by: James Pether Sörling <pethers@users.noreply.github.com>
@github-actions
Copy link
Copy Markdown
Contributor

🔍 Lighthouse Performance Audit

Category Score Status
Performance 85/100 🟡
Accessibility 95/100 🟢
Best Practices 90/100 🟢
SEO 95/100 🟢

📥 Download full Lighthouse report

Budget Compliance: Performance budgets enforced via budget.json

Comment thread scripts/generate-news-enhanced/config.ts Fixed
Comment thread scripts/generate-news-enhanced/generators.ts Fixed
Comment thread scripts/generate-news-enhanced/generators.ts Fixed
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Enhances the deep-inspection generator toward a multi-iteration “intelligence report” model by introducing depth-gated narrative sections, expanding section labels/templates to all 14 languages, and adding a thin DeepInspectionPipeline programmatic entrypoint plus new behavioral tests.

Changes:

  • Add --depth=1..4 parsing and depth-gated deep-inspection narrative sections (executive summary, historical context, predictive assessment, methodology/confidence).
  • Expand DEEP_SECTION_LABELS and strategic-implications templates to cover all 14 supported languages.
  • Add a scripts/deep-inspection/ entrypoint wrapper and new/updated Vitest tests for depth gating and workflow documentation patterns.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/deep-inspection-pipeline.test.ts Adds behavioral tests for depth parsing, pipeline exports, and depth-gated section rendering.
tests/agentic-workflow-mcp-queries.test.ts Strengthens assertions around post-query date filtering and cross-referencing guidance in workflow docs.
scripts/generate-news-enhanced/generators.ts Introduces new deep-inspection section builders, depth-gated rendering, and 14-language labels/templates (but currently contains duplicate imports/vars).
scripts/generate-news-enhanced/config.ts Adds --depth parsing (but currently collides with existing analysisDepth export).
scripts/deep-inspection/index.ts Adds a thin DeepInspectionPipeline wrapper around generateDeepInspection().
Comments suppressed due to low confidence (2)

scripts/generate-news-enhanced/generators.ts:2213

  • content is declared twice in the same scope (first calling generateDeepInspectionContent(..., analysisDepth), then again calling generateDeepInspectionContent(...)). This is a compile-time error and also discards the new depth-aware rendering. Remove the old duplicate declaration and keep the depth-aware call.
      // Topic-focused deep-inspection content (NOT generic content)
      const content: string = generateDeepInspectionContent(enrichedDocs, sanitizedTopic, lang, analysisDepth);
      // Topic-focused deep-inspection content (template-driven body text).
      // At this stage the AI pipeline supplies structured sections (SWOT,
      // dashboard, mindmap, Sankey, watch points) while the main narrative
      // body is still produced by generateDeepInspectionContent(). Wiring
      // AI-derived narrative into the article body is the next phase.
      const content: string = generateDeepInspectionContent(enrichedDocs, sanitizedTopic, lang);

scripts/generate-news-enhanced/config.ts:116

  • config.ts now exports analysisDepth twice with different types/meanings: a numeric deep-inspection depth (1–4) and the existing AI iteration depth (AnalysisDepth = quick/standard/deep). This name collision will fail compilation and makes imports ambiguous. Rename one of them (e.g. deepInspectionDepth for 1–4, keep analysisDepth for AI iterations) and update all imports/usages accordingly.
/**
 * Analysis depth for deep-inspection (1–4).
 *  1 — surface analysis (what happened) — default, fastest
 *  2 — adds predictive assessment and historical context
 *  3 — adds executive intelligence summary and methodology (3 iterations)
 *  4 — full report: adds quality-review iteration in methodology (4 iterations)
 */
const rawDepth: string = parseArgValue(depthArg);
const depthArgProvided: boolean = !!depthArg;
const parsedDepthNum: number = rawDepth ? Number(rawDepth) : NaN;
const depthIsValid: boolean = Number.isInteger(parsedDepthNum) && parsedDepthNum >= 1 && parsedDepthNum <= 4;
if (depthArgProvided && !depthIsValid) {
  console.warn(`Invalid --depth value "${rawDepth}" (expected integer 1–4), falling back to default 1.`);
}
const safeDepth: number = depthIsValid ? parsedDepthNum : 1;
export const analysisDepth: 1 | 2 | 3 | 4 =
  safeDepth === 4 ? 4 :
  safeDepth === 3 ? 3 :
  safeDepth === 2 ? 2 :
  1;
// ---------------------------------------------------------------------------
// Analysis depth (controls number of AI analysis iterations)
// ---------------------------------------------------------------------------

/**
 * --analysis-depth=<quick|standard|deep>
 *
 * Controls how many AI analysis iterations run for deep-inspection articles:
 * - `quick`    — 1 pass (initial analysis only; fast)
 * - `standard` — 2 passes (initial + SWOT refinement; default)
 * - `deep`     — 3 passes (initial + refinement + stakeholder validation)
 */
const analysisDepthArg: string | undefined = args.find(arg => arg.startsWith('--analysis-depth='));
const rawAnalysisDepth: string = parseArgValue(analysisDepthArg ?? '').toLowerCase();
const VALID_ANALYSIS_DEPTHS: readonly AnalysisDepth[] = ['quick', 'standard', 'deep'];

function parseAnalysisDepth(raw: string): AnalysisDepth {
  if ((VALID_ANALYSIS_DEPTHS as readonly string[]).includes(raw)) {
    return raw as AnalysisDepth;
  }
  if (raw && raw !== '') {
    console.warn(`⚠️ Unknown --analysis-depth value "${raw}", falling back to "standard". Valid values: ${VALID_ANALYSIS_DEPTHS.join(', ')}`);
  }
  return 'standard';
}

export const analysisDepth: AnalysisDepth = parseAnalysisDepth(rawAnalysisDepth);

import type { Language } from '../types/language.js';
import type { GenerationResult, DateRange, ArticleCategory, TemplateSection, SwotEntry } from '../types/article.js';
import type { TitleSet } from './types.js';
import { languages, stats, getSharedClient, requireMcp, toISODate, documentIds, documentUrls, focusTopic, analysisDepth } from './config.js';
Signed-off-by: James Pether Sörling <pethers@users.noreply.github.com>
@pethers
Copy link
Copy Markdown
Member

pethers commented Mar 16, 2026

@copilot apply changes based on the comments in this thread

@github-actions
Copy link
Copy Markdown
Contributor

🔍 Lighthouse Performance Audit

Category Score Status
Performance 85/100 🟡
Accessibility 95/100 🟢
Best Practices 90/100 🟢
SEO 95/100 🟢

📥 Download full Lighthouse report

Budget Compliance: Performance budgets enforced via budget.json

…ressions

Co-authored-by: pethers <1726836+pethers@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 16, 2026

@copilot apply changes based on the comments in this thread

Implemented in ac8364d.

  • Consolidated the duplicate ./config.js imports in scripts/generate-news-enhanced/generators.ts into a single import.
  • Fixed tightly coupled compile blockers in the same area (duplicate content declaration and AI pipeline depth type mismatch via local depth mapping) so the branch builds cleanly.
  • Renamed the legacy --analysis-depth export in config.ts to analysisMode to avoid symbol redeclaration with the numeric deep-inspection analysisDepth.

Validation:

  • npx tsc -p tsconfig.scripts.json --noEmit
  • npx vitest run tests/deep-inspection-pipeline.test.ts tests/agentic-workflow-mcp-queries.test.ts
  • codeql_checker (0 alerts)

No UI files changed in this update.

1 similar comment
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 16, 2026

@copilot apply changes based on the comments in this thread

Implemented in ac8364d.

  • Consolidated the duplicate ./config.js imports in scripts/generate-news-enhanced/generators.ts into a single import.
  • Fixed tightly coupled compile blockers in the same area (duplicate content declaration and AI pipeline depth type mismatch via local depth mapping) so the branch builds cleanly.
  • Renamed the legacy --analysis-depth export in config.ts to analysisMode to avoid symbol redeclaration with the numeric deep-inspection analysisDepth.

Validation:

  • npx tsc -p tsconfig.scripts.json --noEmit
  • npx vitest run tests/deep-inspection-pipeline.test.ts tests/agentic-workflow-mcp-queries.test.ts
  • codeql_checker (0 alerts)

No UI files changed in this update.

@github-actions
Copy link
Copy Markdown
Contributor

🔍 Lighthouse Performance Audit

Category Score Status
Performance 85/100 🟡
Accessibility 95/100 🟢
Best Practices 90/100 🟢
SEO 95/100 🟢

📥 Download full Lighthouse report

Budget Compliance: Performance budgets enforced via budget.json

Signed-off-by: James Pether Sörling <pethers@users.noreply.github.com>
@github-actions
Copy link
Copy Markdown
Contributor

🔍 Lighthouse Performance Audit

Category Score Status
Performance 85/100 🟡
Accessibility 95/100 🟢
Best Practices 90/100 🟢
SEO 95/100 🟢

📥 Download full Lighthouse report

Budget Compliance: Performance budgets enforced via budget.json

Comment thread scripts/generate-news-enhanced/generators.ts Fixed
Comment thread scripts/generate-news-enhanced/generators.ts Fixed
Comment thread scripts/generate-news-enhanced/generators.ts Fixed
Comment thread scripts/generate-news-enhanced/generators.ts Fixed
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR extends the deep-inspection generator into a depth-gated “intelligence report” flow by adding new report sections, introducing a --depth=1..4 CLI parameter, and adding a thin DeepInspectionPipeline programmatic entrypoint, with tests covering the new behavior.

Changes:

  • Add numeric deep-inspection analysisDepth parsing (--depth=1..4) and rename the existing quick/standard/deep setting to analysisMode.
  • Expand deep-inspection content generation with new depth-gated sections (executive summary, historical context, predictive assessment, methodology/confidence) and 14-language labels/templates.
  • Add scripts/deep-inspection/index.ts wrapper and new Vitest coverage for depth gating + exports.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
scripts/generate-news-enhanced/generators.ts Adds depth-gated intelligence sections, labels, and wires depth into deep-inspection generation + metadata writing.
scripts/generate-news-enhanced/config.ts Introduces --depth parsing (analysisDepth 1–4) and renames the existing --analysis-depth output to analysisMode.
scripts/deep-inspection/index.ts Adds a thin DeepInspectionPipeline class delegating to generateDeepInspection().
tests/deep-inspection-pipeline.test.ts Adds behavioral tests for depth parsing, exported hooks, section gating, and pipeline exports.
tests/agentic-workflow-mcp-queries.test.ts Tightens workflow-doc assertions around post-query date filtering and cross-referencing guidance.

Comment on lines 40 to 43
import { languages, stats, getSharedClient, requireMcp, toISODate, documentIds, documentUrls, focusTopic, analysisDepth, METADATA_DIR } from './config.js';
import { runAnalysisPipeline } from '../ai-analysis/pipeline.js';
import type { AnalysisResult, AnalysisIterationMetadata, AnalysisDepth } from '../ai-analysis/types.js';
import { languages, stats, getSharedClient, requireMcp, toISODate, documentIds, documentUrls, focusTopic, analysisIterations } from './config.js';
focusTopic: sanitizedTopic,
});
const pipelineDuration = iterationDurationsMs.reduce((a, b) => a + b, 0);
console.log(` 🌐 Generating ${lang.toUpperCase()} version...`);
Comment on lines +2146 to +2149
focusTopic: sanitizedTopic,
completedAt: analysis.completedAt,
};
writeAnalysisMetadata(slug, iterationMetadata);
Comment on lines 2151 to 2155
// Topic-focused deep-inspection content (NOT generic content)
const content: string = generateDeepInspectionContent(enrichedDocs, sanitizedTopic, lang, analysisDepth);
// Topic-focused deep-inspection content (uses AI strategic implications & takeaways)
const content: string = generateDeepInspectionContent(enrichedDocs, sanitizedTopic, lang, aiResult);

Comment on lines 2116 to 2133
@@ -1564,6 +2132,24 @@ export async function generateDeepInspection(): Promise<GenerationResult> {
console.log(` 🤖 AI analysis: ${aiResult.iterations} iteration(s), analysis score ${aiResult.analysisScore}`);
}
@pethers
Copy link
Copy Markdown
Member

pethers commented Mar 16, 2026

@copilot apply changes based on the comments in this thread

Co-authored-by: pethers <1726836+pethers@users.noreply.github.com>
@github-actions
Copy link
Copy Markdown
Contributor

🔍 Lighthouse Performance Audit

Category Score Status
Performance 85/100 🟡
Accessibility 95/100 🟢
Best Practices 90/100 🟢
SEO 95/100 🟢

📥 Download full Lighthouse report

Budget Compliance: Performance budgets enforced via budget.json

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 16, 2026

@copilot apply changes based on the comments in this thread

Applied in 6602e5e.

I addressed the review thread items by:

  • consolidating duplicate ./config.js imports into a single import and removing unused type import,
  • adding writeAnalysisMetadata(...) implementation (writing to METADATA_DIR),
  • removing the duplicate content declaration and fixing the deep-inspection call signature to pass analysisDepth + aiResult,
  • removing the unused pipelineDuration local by inlining duration logging.

Validation on this commit:

  • npx tsc -p tsconfig.scripts.json --noEmit
  • npx vitest run tests/deep-inspection-pipeline.test.ts tests/agentic-workflow-mcp-queries.test.ts
  • code_review (no comments)

No UI files were changed in this update.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactor Code refactoring size-l Large change (250-1000 lines) testing Test coverage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🔬 Deep-Inspection Generator Enhancement — Multi-Iteration AI Intelligence Reports

3 participants