feat(confidence-engine): strengthen initial reconstruction contract

This commit is contained in:
2026-09-05 10:43:57 +01:00
parent 37245a8e28
commit 13fbceee7a
4 changed files with 350 additions and 7 deletions
+21 -4
View File
@@ -7,14 +7,14 @@ const __dirname = dirname(__filename);
const PROMPTS_DIR = join(__dirname, "../../prompts");
/** Available prompt versions */
export const PROMPT_VERSIONS = ["v0.1", "v0.2", "v0.3"];
export const PROMPT_VERSIONS = ["v0.1", "v0.2", "v0.3", "v0.4"];
/** 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";
: "v0.4";
/** Build a v0.1 (extraction-only) prompt inline for backward compatibility */
function buildV1Prompt(scenario) {
@@ -77,15 +77,29 @@ async function buildV3Prompt(scenario) {
}
}
/** Load a versioned prompt from disk and substitute {{SCENARIO}} */
async function buildV4Prompt(scenario) {
try {
const content = await fs.readFile(
join(PROMPTS_DIR, "reconstruct-v0.4.md"),
"utf-8",
);
return content.replace("{{SCENARIO}}", scenario);
} catch {
// Fall back to v0.3 prompt if v0.4 file is missing
return buildV3Prompt(scenario);
}
}
/**
* Build an analysis prompt for the given version.
* @param {string} scenario - The scenario text
* @param {"v0.1" | "v0.2" | "v0.3"} [version="v0.3"] - Prompt version
* @param {"v0.1" | "v0.2" | "v0.3" | "v0.4"} [version="v0.4"] - Prompt version
* @param {object} [opts] - Optional experimental parameters
* @param {string} [opts.experimentInstruction] - Bounded experimental instruction block appended to the base prompt (production prompt is never replaced)
* @returns {Promise<{prompt: string, version: string}>}
*/
export async function buildPrompt(scenario, version = "v0.3", opts = {}) {
export async function buildPrompt(scenario, version = "v0.4", opts = {}) {
let prompt;
switch (version) {
case "v0.1":
@@ -94,6 +108,9 @@ export async function buildPrompt(scenario, version = "v0.3", opts = {}) {
case "v0.2":
prompt = await buildV2Prompt(scenario);
break;
case "v0.4":
prompt = await buildV4Prompt(scenario);
break;
default: // v0.3
prompt = await buildV3Prompt(scenario);
break;