test(confidence-engine): use canonical focused deconstruction

This commit is contained in:
2026-10-06 17:28:40 +01:00
parent 9362c78f81
commit 814360e368
2 changed files with 107 additions and 29 deletions
+45 -20
View File
@@ -272,23 +272,9 @@ async function runLiveExperiment({ graph, previousQuestion, answer, findings = [
* - findingsCheckpoint with accurate post-episode accumulated findings count
*/
/**
* Deterministically derive a canonical Contribution from the fixed answer
* when the caller does not supply one. Mirrors production appendFocusedContribution
* shape: id, targetNodeId, question, answer, sequence, observations, etc.
* Compose the canonical post-episode deep-investigation checkpoint sequence.
* Uses production-focused deconstruct for Contribution derivation (not synthetic raw-answer path).
*/
function _deriveContributionFromAnswer({ answer, previousQuestion, targetNodeId, sequence }) {
return {
id: `contrib-ep-${String(sequence).padStart(4, "0")}`,
targetNodeId: targetNodeId ?? null,
question: previousQuestion ?? "",
answer: answer ?? "",
sequence: sequence,
observations: [answer],
uncertainties: [],
possibleFollowUpQuestions: [],
};
}
async function composeDeepInvestigationCheckpoint({ situationGraph, previousQuestion, answer, findings = [], contributions = [], targetNodeId, episodeMode }) {
dotenv.config({ path: ".env.local" });
@@ -328,15 +314,54 @@ async function composeDeepInvestigationCheckpoint({ situationGraph, previousQues
/* ── Production-equivalent focused-episode seam: targetNodeId triggers the same path as executeEpisodeDone → handleEpisodeMode ─── */
// Derive a canonical Contribution from the fixed answer when none supplied.
// Mirrors production appendFocusedContribution: user answer → canonical Contribution
/* ── Canonical deconstruction: use focusedDeconstruct for Contribution derivation ─── */
const effectiveContributions = contributions.length > 0 ? [...contributions] : [];
let newFindingsFromContributions = [];
if (effectiveContributions.length === 0 && answer && targetNodeId) {
const contribSeq = effectiveContributions.length + 1;
const derivedContrib = _deriveContributionFromAnswer({ answer, previousQuestion, targetNodeId, sequence: contribSeq });
/* ── Load production deconstruction seam (dynamic import to resolve ESM path aliases) ─── */
const { focusedDeconstruct } = await import("../../lib/graph/focused-investigation.js");
// Extract node context for deconstruction prompt
const targetNode = situationGraph.nodes.find(n => n.id === targetNodeId);
const targetLabel = targetNode?.label ?? "";
const targetDescription = targetNode?.description ?? "";
const centralStatement = situationGraph.centralStatement ?? "";
// Call production-focused deconstruct — exactly one provider generation
const focused = focusedDeconstruct({
provider,
modelName: model,
targetNodeId,
targetLabel,
targetDescription,
centralStatement,
question: previousQuestion ?? "",
answer,
});
if (!focused.success) {
throw new Error(`focusedDeconstruct failed for episode ${contribSeq}: ${JSON.stringify(focused.errors)}`);
}
// Map deconstruction result → canonical Contribution shape
const derivedContrib = {
id: `contrib-ep-${String(contribSeq).padStart(4, "0")}`,
targetNodeId: focused.targetNodeId ?? targetNodeId,
question: previousQuestion ?? "",
answer: answer,
sequence: contribSeq,
observations: focused.observations,
uncertainties: focused.uncertainties,
assumptions: focused.assumptions,
relationships: focused.relationships,
possibleFollowUpQuestions: focused.possibleFollowUpQuestions,
};
effectiveContributions.push(derivedContrib);
// Derive canonical Findings from the Contribution (production seam)
// Derive canonical Findings from the deconstruction-derived Contribution (production seam)
newFindingsFromContributions = deriveFindingsFromContributions([derivedContrib]).findings;
}