feat: add v0.3 normalised comparison reasoning

Add explicit reasoning guidance for normalising counts by exposure/denominator,
distinguishing total count from rate, and avoiding correlation-as-causation errors.

Changes:
- prompts/reconstruct-v0.3.md: new prompt with normalisation discipline
- lib/reconstruction/prompt.js: v0.3 loader + env var override support
- lib/analysis.js: defer DEFAULT_PROMPT_VERSION to prompt module (defaults to v0.3)
- PROMPT_VERSIONS extended to [v0.1, v0.2, v0.3]
- tests/v03-reasoning.test.js: 34 focused tests covering prompt loading, schema validation, guidance completeness, and target scenario fixture
- playwright.config.js + tests/smoke.test.js: minimal UI smoke test for browser rendering
- package.json: add @playwright/test as devDependency

Default switches to v0.3; v0.2 selectable via promptVersion or RECONSTRUCTION_PROMPT_VERSION env var.
This commit is contained in:
2026-08-01 15:39:30 +01:00
parent d72c7c5465
commit 79ea2f6824
8 changed files with 914 additions and 8 deletions
+1 -2
View File
@@ -5,14 +5,13 @@
import { getConfig } from "../lib/config.js";
import { getProvider } from "../lib/llm/provider.js";
import { buildPrompt, PROMPT_VERSIONS } from "../lib/reconstruction/prompt.js";
import { buildPrompt, PROMPT_VERSIONS, DEFAULT_PROMPT_VERSION } from "../lib/reconstruction/prompt.js";
import {
reconstructionV2Schema,
reconstructionSchema as reconstructionV1Schema,
} from "../lib/reconstruction/schema.js";
const MAX_SCENARIO_LENGTH = 10000;
const DEFAULT_PROMPT_VERSION = "v0.2";
/**
* Analyse a scenario string through the full pipeline.
+28 -4
View File
@@ -7,7 +7,14 @@ const __dirname = dirname(__filename);
const PROMPTS_DIR = join(__dirname, "../../prompts");
/** Available prompt versions */
export const PROMPT_VERSIONS = ["v0.1", "v0.2"];
export const PROMPT_VERSIONS = ["v0.1", "v0.2", "v0.3"];
/** Default prompt version (override via RECONSTRUCTION_PROMPT_VERSION env var) */
const defaultVersionFromEnv = process.env.RECONSTRUCTION_PROMPT_VERSION;
export const DEFAULT_PROMPT_VERSION =
defaultVersionFromEnv && PROMPT_VERSIONS.includes(defaultVersionFromEnv)
? defaultVersionFromEnv
: "v0.3";
/** Build a v0.1 (extraction-only) prompt inline for backward compatibility */
function buildV1Prompt(scenario) {
@@ -56,20 +63,37 @@ async function buildV2Prompt(scenario) {
}
}
/** Load a versioned prompt from disk and substitute {{SCENARIO}} */
async function buildV3Prompt(scenario) {
try {
const content = await fs.readFile(
join(PROMPTS_DIR, "reconstruct-v0.3.md"),
"utf-8",
);
return content.replace("{{SCENARIO}}", scenario);
} catch {
// Fall back to v0.2 prompt if v0.3 file is missing
return buildV2Prompt(scenario);
}
}
/**
* Build an analysis prompt for the given version.
* @param {"v0.1" | "v0.2"} [version="v0.2"]
* @param {"v0.1" | "v0.2" | "v0.3"} [version="v0.3"]
* @returns {Promise<{prompt: string, version: string}>}
*/
export async function buildPrompt(scenario, version = "v0.2") {
export async function buildPrompt(scenario, version = "v0.3") {
let prompt;
switch (version) {
case "v0.1":
prompt = buildV1Prompt(scenario);
break;
default: // v0.2
case "v0.2":
prompt = await buildV2Prompt(scenario);
break;
default: // v0.3
prompt = await buildV3Prompt(scenario);
break;
}
const strongJsonHint =