{"version":3,"file":"mission-checkpoint.d.ts","sourceRoot":"","sources":["../../../src/core/context-runtime/mission-checkpoint.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,eAAO,MAAM,yCAAyC,GAAa,CAAC;AAEpE,MAAM,WAAW,cAAc;IAC9B,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,aAAa;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,0EAA0E;IAC1E,WAAW,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,SAAS;IACzB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,+EAA+E;IAC/E,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;IACzC,WAAW,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,iBAAiB;IACjC,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,wBAAwB;IACxC,aAAa,EAAE,OAAO,yCAAyC,CAAC;IAChE,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,SAAS,EAAE,cAAc,EAAE,CAAC;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,QAAQ,EAAE,aAAa,EAAE,CAAC;IAC1B,YAAY,EAAE,iBAAiB,EAAE,CAAC;IAClC,SAAS,EAAE,SAAS,CAAC;IACrB,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB;;;OAGG;IACH,mBAAmB,EAAE,sBAAsB,CAAC;CAC5C;AAED,MAAM,WAAW,eAAe;IAC/B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB,SAAS,CAAC,EAAE,cAAc,EAAE,CAAC;IAC7B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB,QAAQ,CAAC,EAAE,aAAa,EAAE,CAAC;IAC3B,YAAY,CAAC,EAAE,iBAAiB,EAAE,CAAC;IACnC,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;CACvB;AAED,wBAAgB,8BAA8B,CAC7C,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,eAAe,EACtB,OAAO,GAAE;IAAE,GAAG,CAAC,EAAE,MAAM,CAAA;CAAO,GAC5B,wBAAwB,CAqB1B;AAwBD;;;;GAIG;AACH,wBAAgB,6BAA6B,CAAC,IAAI,EAAE,OAAO,GAAG,wBAAwB,CAsCrF;AAED;;;;GAIG;AACH,wBAAgB,+BAA+B,CAAC,UAAU,EAAE,wBAAwB,GAAG,MAAM,CAsE5F","sourcesContent":["/**\n * Durable mission-level cognitive checkpoint (L2 warm memory).\n *\n * This is a *bounded operational projection* over Jensen's already-durable\n * state (MissionRuntime, session memory, todos, tasks, file operations). It is\n * NOT a new authority surface and can never fabricate mission success: the\n * Reliability Kernel / Completion Gate remain the sole authority for completion.\n *\n * The checkpoint is versioned, keyed to mission/session identity, corruption\n * safe, and provider-independent. It is the semantic bridge that lets a\n * rehydrated context continue the same mission without replaying the full\n * transcript.\n */\n\nexport const MISSION_CONTEXT_CHECKPOINT_SCHEMA_VERSION = 1 as const;\n\nexport interface DecisionRecord {\n\tdecision: string;\n\trationale: string;\n}\n\nexport interface FindingRecord {\n\tsubject: string;\n\tdetail: string;\n\t/** Deterministic evidence id or file:line reference, never fabricated. */\n\tevidenceRef?: string;\n}\n\nexport interface TestState {\n\tcommand?: string;\n\t/** lastPassing/failing evidence references (observations, not conclusions). */\n\tlastResult?: \"pass\" | \"fail\" | \"unknown\";\n\tevidenceRef?: string;\n}\n\nexport interface EvidenceReference {\n\tevidenceId: string;\n\tsummary: string;\n}\n\nexport interface MissionContextCheckpoint {\n\tschemaVersion: typeof MISSION_CONTEXT_CHECKPOINT_SCHEMA_VERSION;\n\tmissionId: string;\n\trevision: number;\n\tupdatedAtMs: number;\n\tobjective: string;\n\tconstraints: string[];\n\tdecisions: DecisionRecord[];\n\tplan: string;\n\tcompletedSteps: string[];\n\tpendingSteps: string[];\n\tactiveFiles: string[];\n\tfindings: FindingRecord[];\n\tevidenceRefs: EvidenceReference[];\n\ttestState: TestState;\n\tblockers: string[];\n\tnextActions: string[];\n\t/**\n\t * Explicit authority marker. Context persistence must never promote mission\n\t * state; completion authority is always \"mission-runtime-only\".\n\t */\n\tcompletionAuthority: \"mission-runtime-only\";\n}\n\nexport interface CheckpointPatch {\n\tobjective?: string;\n\tconstraints?: string[];\n\tdecisions?: DecisionRecord[];\n\tplan?: string;\n\tcompletedSteps?: string[];\n\tpendingSteps?: string[];\n\tactiveFiles?: string[];\n\tfindings?: FindingRecord[];\n\tevidenceRefs?: EvidenceReference[];\n\ttestState?: TestState;\n\tblockers?: string[];\n\tnextActions?: string[];\n}\n\nexport function createMissionContextCheckpoint(\n\tmissionId: string,\n\tpatch: CheckpointPatch,\n\toptions: { now?: number } = {},\n): MissionContextCheckpoint {\n\tconst now = options.now ?? Date.now();\n\treturn {\n\t\tschemaVersion: MISSION_CONTEXT_CHECKPOINT_SCHEMA_VERSION,\n\t\tmissionId,\n\t\trevision: 1,\n\t\tupdatedAtMs: now,\n\t\tobjective: patch.objective ?? \"\",\n\t\tconstraints: [...(patch.constraints ?? [])],\n\t\tdecisions: (patch.decisions ?? []).map((d) => ({ ...d })),\n\t\tplan: patch.plan ?? \"\",\n\t\tcompletedSteps: [...(patch.completedSteps ?? [])],\n\t\tpendingSteps: [...(patch.pendingSteps ?? [])],\n\t\tactiveFiles: [...(patch.activeFiles ?? [])],\n\t\tfindings: (patch.findings ?? []).map((f) => ({ ...f })),\n\t\tevidenceRefs: (patch.evidenceRefs ?? []).map((e) => ({ ...e })),\n\t\ttestState: { ...(patch.testState ?? {}) },\n\t\tblockers: [...(patch.blockers ?? [])],\n\t\tnextActions: [...(patch.nextActions ?? [])],\n\t\tcompletionAuthority: \"mission-runtime-only\",\n\t};\n}\n\nfunction isStringArray(value: unknown): value is string[] {\n\treturn Array.isArray(value) && value.every((v) => typeof v === \"string\");\n}\n\nfunction isDecisionRecord(value: unknown): value is DecisionRecord {\n\tif (typeof value !== \"object\" || value === null) return false;\n\tconst d = value as Record<string, unknown>;\n\treturn typeof d.decision === \"string\" && typeof d.rationale === \"string\";\n}\n\nfunction isFindingRecord(value: unknown): value is FindingRecord {\n\tif (typeof value !== \"object\" || value === null) return false;\n\tconst f = value as Record<string, unknown>;\n\treturn typeof f.subject === \"string\" && typeof f.detail === \"string\";\n}\n\nfunction isEvidenceReference(value: unknown): value is EvidenceReference {\n\tif (typeof value !== \"object\" || value === null) return false;\n\tconst e = value as Record<string, unknown>;\n\treturn typeof e.evidenceId === \"string\" && typeof e.summary === \"string\";\n}\n\n/**\n * Deserialize a checkpoint. Fails closed (throws) on structural corruption so\n * a partial/truncated document can never fabricate state, decisions, evidence,\n * or success.\n */\nexport function parseMissionContextCheckpoint(data: unknown): MissionContextCheckpoint {\n\tif (typeof data !== \"object\" || data === null) {\n\t\tthrow new Error(\"MissionContextCheckpoint must be an object\");\n\t}\n\tconst doc = data as Record<string, unknown>;\n\tif (doc.schemaVersion !== MISSION_CONTEXT_CHECKPOINT_SCHEMA_VERSION) {\n\t\tthrow new Error(`Unsupported MissionContextCheckpoint schema version: ${String(doc.schemaVersion)}`);\n\t}\n\tif (typeof doc.missionId !== \"string\" || doc.missionId.length === 0) {\n\t\tthrow new Error(\"MissionContextCheckpoint is missing missionId\");\n\t}\n\tif (typeof doc.objective !== \"string\") {\n\t\tthrow new Error(\"MissionContextCheckpoint is missing objective\");\n\t}\n\tif (doc.completionAuthority !== \"mission-runtime-only\") {\n\t\tthrow new Error(\"MissionContextCheckpoint has invalid completionAuthority\");\n\t}\n\n\treturn createMissionContextCheckpoint(\n\t\tdoc.missionId,\n\t\t{\n\t\t\tobjective: doc.objective,\n\t\t\tconstraints: isStringArray(doc.constraints) ? doc.constraints : [],\n\t\t\tdecisions: Array.isArray(doc.decisions) ? doc.decisions.filter(isDecisionRecord) : [],\n\t\t\tplan: typeof doc.plan === \"string\" ? doc.plan : \"\",\n\t\t\tcompletedSteps: isStringArray(doc.completedSteps) ? doc.completedSteps : [],\n\t\t\tpendingSteps: isStringArray(doc.pendingSteps) ? doc.pendingSteps : [],\n\t\t\tactiveFiles: isStringArray(doc.activeFiles) ? doc.activeFiles : [],\n\t\t\tfindings: Array.isArray(doc.findings) ? doc.findings.filter(isFindingRecord) : [],\n\t\t\tevidenceRefs: Array.isArray(doc.evidenceRefs) ? doc.evidenceRefs.filter(isEvidenceReference) : [],\n\t\t\ttestState: typeof doc.testState === \"object\" && doc.testState !== null ? (doc.testState as TestState) : {},\n\t\t\tblockers: isStringArray(doc.blockers) ? doc.blockers : [],\n\t\t\tnextActions: isStringArray(doc.nextActions) ? doc.nextActions : [],\n\t\t},\n\t\t{\n\t\t\tnow: typeof doc.updatedAtMs === \"number\" ? doc.updatedAtMs : undefined,\n\t\t},\n\t);\n}\n\n/**\n * Deterministic, bounded rehydration preamble. Contains the operational facts a\n * model needs to continue the SAME mission after a context rollover — never\n * raw reasoning, never raw transcripts, never secrets.\n */\nexport function checkpointToRehydrationPreamble(checkpoint: MissionContextCheckpoint): string {\n\tconst lines: string[] = [];\n\tlines.push(\"<mission-context-checkpoint>\");\n\tlines.push(`mission-id: ${checkpoint.missionId}`);\n\tlines.push(`revision: ${checkpoint.revision}`);\n\tlines.push(`objective: ${checkpoint.objective}`);\n\n\tif (checkpoint.constraints.length > 0) {\n\t\tlines.push(\"constraints:\");\n\t\tfor (const c of checkpoint.constraints) lines.push(`- ${c}`);\n\t}\n\n\tif (checkpoint.decisions.length > 0) {\n\t\tlines.push(\"decisions:\");\n\t\tfor (const d of checkpoint.decisions) lines.push(`- ${d.decision} (rationale: ${d.rationale})`);\n\t}\n\n\tif (checkpoint.plan) {\n\t\tlines.push(`plan: ${checkpoint.plan}`);\n\t}\n\n\tif (checkpoint.completedSteps.length > 0) {\n\t\tlines.push(\"completed:\");\n\t\tfor (const s of checkpoint.completedSteps) lines.push(`- [x] ${s}`);\n\t}\n\n\tif (checkpoint.pendingSteps.length > 0) {\n\t\tlines.push(\"pending:\");\n\t\tfor (const s of checkpoint.pendingSteps) lines.push(`- [ ] ${s}`);\n\t}\n\n\tif (checkpoint.activeFiles.length > 0) {\n\t\tlines.push(\"active-files:\");\n\t\tfor (const f of checkpoint.activeFiles) lines.push(`- ${f}`);\n\t}\n\n\tif (checkpoint.findings.length > 0) {\n\t\tlines.push(\"findings:\");\n\t\tfor (const f of checkpoint.findings) {\n\t\t\tlines.push(`- ${f.subject}: ${f.detail}${f.evidenceRef ? ` [ref: ${f.evidenceRef}]` : \"\"}`);\n\t\t}\n\t}\n\n\tif (checkpoint.evidenceRefs.length > 0) {\n\t\tlines.push(\"evidence-refs:\");\n\t\tfor (const e of checkpoint.evidenceRefs) lines.push(`- ${e.evidenceId}: ${e.summary}`);\n\t}\n\n\tif (checkpoint.testState.command || checkpoint.testState.lastResult) {\n\t\tlines.push(\n\t\t\t`test-state: ${checkpoint.testState.command ?? \"(no command)\"} -> ${checkpoint.testState.lastResult ?? \"unknown\"}`,\n\t\t);\n\t\tif (checkpoint.testState.evidenceRef) lines.push(`test-evidence: ${checkpoint.testState.evidenceRef}`);\n\t}\n\n\tif (checkpoint.blockers.length > 0) {\n\t\tlines.push(\"blockers:\");\n\t\tfor (const b of checkpoint.blockers) lines.push(`- ${b}`);\n\t}\n\n\tif (checkpoint.nextActions.length > 0) {\n\t\tlines.push(\"next-actions:\");\n\t\tfor (const a of checkpoint.nextActions) lines.push(`- ${a}`);\n\t}\n\n\tlines.push(\n\t\t\"authority: completion remains governed by the Reliability Kernel; this checkpoint cannot certify success.\",\n\t);\n\tlines.push(\"</mission-context-checkpoint>\");\n\treturn lines.join(\"\\n\");\n}\n"]}