feat(confidence-engine): persist canonical investigation state

This commit is contained in:
2026-08-27 16:21:41 +01:00
parent bc35e05253
commit 166ee91698
3 changed files with 293 additions and 1 deletions
+27
View File
@@ -313,6 +313,33 @@ export default function ScenarioForm() {
}
}, []);
/* ── Canonical autosave — persist whenever state changes (Phase 2) ── */
useEffect(() => {
if (typeof window === "undefined") return;
// Guard: no valid investigation yet → skip autosave during idle/start flows.
// Also prevents overwriting an existing saved investigation with the initial
// empty state of a fresh ScenarioForm instance (hydration race guard).
if (!result?.situationGraph) return;
void saveInvestigation({
scenario,
situationGraph: result.situationGraph,
selectedQuestion: result.selectedQuestion,
summary: currentUnderstanding,
updatedAt: new Date().toISOString(),
focusedContributions,
findings,
});
}, [
scenario,
result?.situationGraph,
result?.selectedQuestion,
currentUnderstanding,
focusedContributions,
findings,
]);
/* Restore facilitator dismiss preference (Experiment 05) ─── */
useEffect(() => {
if (typeof window === "undefined") return;