Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
cb04da3
feat: enhance deep-inspection generator with multi-iteration intellig…
Copilot Mar 13, 2026
63122c3
Merge branch 'main' into copilot/enhance-deep-inspection-generator
pethers Mar 14, 2026
fd4b967
fix: address PR review comments and CI test failure
Copilot Mar 14, 2026
f129c1d
Merge branch 'main' into copilot/enhance-deep-inspection-generator
pethers Mar 14, 2026
f560779
fix: address round-2 review — SFS detection, enrichment counting, pip…
Copilot Mar 14, 2026
2d1b505
fix: address round-3 review — enrichment count, Dutch plural, Swedish…
Copilot Mar 14, 2026
44cb3d9
fix: address round-4 review — Swedish grammar, pipeline params, label…
Copilot Mar 15, 2026
d5a3d07
fix: address round-5 review — Swedish grammar, depth validation, test…
Copilot Mar 15, 2026
32f067b
Merge branch 'main' into copilot/enhance-deep-inspection-generator
pethers Mar 15, 2026
3e211e0
Merge branch 'main' into copilot/enhance-deep-inspection-generator
pethers Mar 15, 2026
1e8f9a2
fix: use topicStr unconditionally in predictive assessment + add 5W t…
Copilot Mar 15, 2026
86fc91a
Merge branch 'main' into copilot/enhance-deep-inspection-generator
pethers Mar 15, 2026
666732f
Merge branch 'main' into copilot/enhance-deep-inspection-generator
pethers Mar 15, 2026
8b7d5ad
fix: normalize invalid --depth to 1, fix EN singular verb, fix mock p…
Copilot Mar 15, 2026
848abb2
Merge branch 'main' into copilot/enhance-deep-inspection-generator
pethers Mar 15, 2026
c8c14c7
fix: switch enrichment counting from fullText/fullContent to contentF…
Copilot Mar 15, 2026
2d02ca0
Merge branch 'main' into copilot/enhance-deep-inspection-generator
pethers Mar 15, 2026
4ad7b5c
fix: handle no-legislative-signal case in buildExecutiveSummary
Copilot Mar 15, 2026
c3f4ca2
fix: use conditional clause building in DA/NO/FI/JA/KO templates
Copilot Mar 15, 2026
e05fd7e
Merge branch 'main' into copilot/enhance-deep-inspection-generator
pethers Mar 15, 2026
6174daa
refactor: unexport deepLabel, extract isSfsDoc helper, assert hasMult…
Copilot Mar 15, 2026
64ea398
fix: remove misleading inline comment in label test loop
Copilot Mar 15, 2026
addf441
Merge branch 'main' into copilot/enhance-deep-inspection-generator
pethers Mar 15, 2026
03a2c9a
fix: use fileURLToPath(import.meta.url) for ESM-compatible __dirname …
Copilot Mar 15, 2026
0d52849
Merge branch 'main' into copilot/enhance-deep-inspection-generator
pethers Mar 15, 2026
30d2909
fix: remove duplicate ol numbering, handle empty --depth=, add depth-…
Copilot Mar 15, 2026
14d56be
refactor: rename depthPresent → depthArgProvided, generatorsSrcForDep…
Copilot Mar 15, 2026
8bb1aac
Merge branch 'main' into copilot/enhance-deep-inspection-generator
pethers Mar 16, 2026
2e16f94
Merge branch 'main' into copilot/enhance-deep-inspection-generator
pethers Mar 16, 2026
cd30e5e
Merge branch 'main' into copilot/enhance-deep-inspection-generator
pethers Mar 16, 2026
7a2bbab
Fix English clause joining (Oxford comma), broaden methodology data-s…
Copilot Mar 16, 2026
7b3a113
Merge branch 'main' into copilot/enhance-deep-inspection-generator
pethers Mar 16, 2026
ee4b14d
Changes before error encountered
Copilot Mar 16, 2026
ad6c8d0
Merge branch 'main' into copilot/enhance-deep-inspection-generator
pethers Mar 16, 2026
ceb5999
Merge branch 'main' into copilot/enhance-deep-inspection-generator
pethers Mar 16, 2026
2bbd562
Merge branch 'main' into copilot/enhance-deep-inspection-generator
pethers Mar 16, 2026
038667f
Merge branch 'main' into copilot/enhance-deep-inspection-generator
pethers Mar 16, 2026
5fb0a47
Address review round 15: effectiveType consistency, noLegSignal inclu…
Copilot Mar 16, 2026
575e6db
Merge branch 'main' into copilot/enhance-deep-inspection-generator
pethers Mar 16, 2026
02056de
test/docs: address round 16 review feedback for deep-inspection PR
Copilot Mar 16, 2026
48e63d5
test: make deep-inspection and MCP query assertions less brittle
Copilot Mar 16, 2026
c573215
Merge branch 'main' into copilot/enhance-deep-inspection-generator
pethers Mar 16, 2026
33a5793
Merge branch 'main' into copilot/enhance-deep-inspection-generator
pethers Mar 16, 2026
ac8364d
fix: resolve duplicate config imports and deep-inspection compile reg…
Copilot Mar 16, 2026
c726890
Merge branch 'main' into copilot/enhance-deep-inspection-generator
pethers Mar 16, 2026
6602e5e
fix: resolve deep-inspection generator compile blockers from review
Copilot Mar 16, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions scripts/deep-inspection/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/**
* @module deep-inspection
* @description DeepInspectionPipeline — thin programmatic entrypoint wrapper
* around `generateDeepInspection()`.
*
* The underlying generator performs collection, analysis, synthesis, and
* rendering internally. This class intentionally does not re-implement those
* phases; it only delegates execution and returns enriched run metadata.
*
* @example
* ```typescript
* const pipeline = new DeepInspectionPipeline();
* const result = await pipeline.run();
* ```
*
* @author Hack23 AB
* @license Apache-2.0
*/

import { generateDeepInspection } from '../generate-news-enhanced/generators.js';
import { analysisDepth, focusTopic } from '../generate-news-enhanced/config.js';
import type { GenerationResult } from '../types/article.js';

/**
* Result produced by a pipeline run.
* Extends GenerationResult with optional depth and topic metadata.
*/
export interface DeepInspectionResult extends GenerationResult {
/** Effective analysis depth used. */
depth: 1 | 2 | 3 | 4;
/** Focus topic if provided. */
topic?: string;
}

/**
* DeepInspectionPipeline delegates execution to
* `generateDeepInspection()` in generators.ts, which
* reads targeting parameters and `analysisDepth` from CLI config. When used
* programmatically via this class, those CLI values are already set at module
* load time — so `run()` simply invokes the generator and enriches the result.
*
* All targeting (document IDs, URLs) and analysis depth are controlled via CLI
* arguments parsed by `config.ts` at module load time. This class provides a
* clean programmatic entrypoint without duplicating CLI parameter handling.
*/
Comment on lines +35 to +45
export class DeepInspectionPipeline {
/**
* Phase labels for logging purposes.
* @internal
*/
private phaseLabel(depth: 1 | 2 | 3 | 4): string {
const labels: Record<1 | 2 | 3 | 4, string> = {
1: 'Surface analysis — events & actors',
2: 'Predictive + historical context',
3: 'Full report with executive summary & methodology',
4: 'Full multi-iteration intelligence report',
};
return labels[depth];
}

/**
* Run deep-inspection generation via the underlying generator wrapper.
*
* @returns DeepInspectionResult with success status, file count, and slug
*/
async run(): Promise<DeepInspectionResult> {
const depth = analysisDepth;
const topic = focusTopic || undefined;

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 +66 to +79
Comment on lines +66 to +79
}
}

export default DeepInspectionPipeline;
29 changes: 25 additions & 4 deletions scripts/generate-news-enhanced/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,11 @@ export const skipExistingArg: boolean = args.includes('--skip-existing');
export const batchSize: number = batchSizeArg ? parseInt(parseArgValue(batchSizeArg) || '0', 10) : 0;
const qualityThresholdArg: string | undefined = args.find(arg => arg.startsWith('--quality-threshold='));

// Deep-inspection arguments: document IDs, URLs, and focus topic for targeted analysis
// Deep-inspection arguments: document IDs, URLs, focus topic, and analysis depth
const documentIdsArg: string | undefined = args.find(arg => arg.startsWith('--document-ids='));
const documentUrlsArg: string | undefined = args.find(arg => arg.startsWith('--document-urls='));
const focusTopicArg: string | undefined = args.find(arg => arg.startsWith('--focus-topic='));
const depthArg: string | undefined = args.find(arg => arg.startsWith('--depth='));

/** Comma-separated Riksdag document IDs for deep-inspection (e.g. H901FiU1,H901JuU25) */
const rawDocumentIds: string = parseArgValue(documentIdsArg);
Expand All @@ -65,6 +66,26 @@ export const documentUrls: string[] = rawDocumentUrls
/** Specific policy topic to focus deep-inspection analysis on */
export const focusTopic: string = parseArgValue(focusTopicArg);

/**
* 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 =
Comment thread
github-code-quality[bot] marked this conversation as resolved.
Fixed
safeDepth === 4 ? 4 :
safeDepth === 3 ? 3 :
safeDepth === 2 ? 2 :
1;
Comment on lines +76 to +88
Comment on lines +84 to +88
// --iterations=N: number of AI analysis iterations for deep-inspection (default: 3)
const iterationsArg: string | undefined = args.find(arg => arg.startsWith('--iterations='));
const DEFAULT_ITERATIONS = 3;
Expand Down Expand Up @@ -93,8 +114,8 @@ export const analysisIterations: number = parsedIterations;
* - `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 analysisModeArg: string | undefined = args.find(arg => arg.startsWith('--analysis-depth='));
const rawAnalysisMode: string = parseArgValue(analysisModeArg ?? '').toLowerCase();
const VALID_ANALYSIS_DEPTHS: readonly AnalysisDepth[] = ['quick', 'standard', 'deep'];

function parseAnalysisDepth(raw: string): AnalysisDepth {
Expand All @@ -107,7 +128,7 @@ function parseAnalysisDepth(raw: string): AnalysisDepth {
return 'standard';
}

export const analysisDepth: AnalysisDepth = parseAnalysisDepth(rawAnalysisDepth);
export const analysisMode: AnalysisDepth = parseAnalysisDepth(rawAnalysisMode);

const DEFAULT_QUALITY_THRESHOLD = 40;
let parsedQualityThreshold: number = DEFAULT_QUALITY_THRESHOLD;
Expand Down
Loading
Loading