feat(confidence-engine): v0.60j preserve investigation on restart
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
// Owns the canonical identity contract: snapshot.id is the sole save identity.
|
||||
// Delegates to the concrete localStorage provider internally.
|
||||
|
||||
import { loadInvestigation as _load, saveInvestigation as _save, clearInvestigation as _clear, listInvestigations as _list } from "./providers/local-storage.js";
|
||||
import { loadInvestigation as _load, saveInvestigation as _save, clearInvestigation as _clear, listInvestigations as _list, restartInvestigation as _restart } from "./providers/local-storage.js";
|
||||
|
||||
/**
|
||||
* Canonical save contract: snapshot.id is the sole identity authority.
|
||||
@@ -40,3 +40,15 @@ export function clearInvestigation(id) {
|
||||
export function listInvestigations() {
|
||||
return _list();
|
||||
}
|
||||
|
||||
/**
|
||||
* Semantic restart: reset reasoning/report state within the Investigation container.
|
||||
*
|
||||
* The Investigation is NOT deleted or replaced. Its durable `id` and `scenario` (container)
|
||||
* are preserved. All reasoning-state fields are cleared so a new clean pass can begin.
|
||||
*
|
||||
* Missing/invalid id → silently no-op (does NOT fall back to legacy singleton).
|
||||
*/
|
||||
export function restartInvestigation(id) {
|
||||
return _restart(id);
|
||||
}
|
||||
|
||||
@@ -175,6 +175,41 @@ export function listInvestigations() {
|
||||
return summaries;
|
||||
}
|
||||
|
||||
// ── restartInvestigation (semantic reset within container) ───────────
|
||||
|
||||
/**
|
||||
* Resets the Investigation to a clean state suitable for a new reasoning pass.
|
||||
*
|
||||
* Preserved: id, scenario, schemaVersion (container-level identity/framing).
|
||||
* Reset: situationGraph → null, selectedQuestion → null, summary → null,
|
||||
* focusedContributions → [], findings → [], investigationReport → null,
|
||||
* investigationRevision → 0, updatedAt → new ISO timestamp.
|
||||
*/
|
||||
export function restartInvestigation(id) {
|
||||
const storage = _getTargetStorage();
|
||||
if (!storage) return;
|
||||
|
||||
try {
|
||||
const key = id != null ? `${INVESTIGATION_PREFIX}${id}` : CANONICAL_KEY;
|
||||
const raw = safeGet(storage, key);
|
||||
if (raw === null) return; // nothing to restart
|
||||
const record = JSON.parse(raw);
|
||||
if (!isPlainObject(record)) return;
|
||||
|
||||
// Preserve container fields, reset reasoning-state fields
|
||||
record.situationGraph = null;
|
||||
record.selectedQuestion = null;
|
||||
record.summary = null;
|
||||
record.focusedContributions = [];
|
||||
record.findings = [];
|
||||
record.investigationReport = null;
|
||||
record.investigationRevision = 0;
|
||||
record.updatedAt = new Date().toISOString();
|
||||
|
||||
_persist(storage, key, JSON.stringify(record));
|
||||
} catch (_) { /* storage errors must not crash caller */ }
|
||||
}
|
||||
|
||||
// ── internals ────────────────────────────────────────────────────────
|
||||
|
||||
function _persist(storage, key, value) {
|
||||
|
||||
Reference in New Issue
Block a user