/** * Mission Execution State Machine v1. * * Governs the lifecycle of one Mission Contract execution through * a deterministic, replayable state machine. Every transition is * caller-supplied (executionId, transitionId, expectedRevision) and * the machine derives the destination state internally. * * Trusted completion (APPROVE_COMPLETION) requires a genuine * contract-bound TrustedValidationContext. The generic CLI cannot * mint one and must reject APPROVE_COMPLETION atomically. * * Full requirement-evidence completion gate deferred to LH-5. */ import { type ReadinessInput } from "./adaptive/readiness.js"; import { type TrustedValidationContext } from "./trusted-context.js"; import type { MissionContractV1 } from "./types.js"; export declare const MISSION_EXECUTION_RECORD_VERSION: 1; export type MissionExecutionState = "PLANNING" | "EXECUTION" | "VERIFICATION" | "COMPLETION_REVIEW" | "BLOCKED" | "COMPLETED" | "FAILED" | "CANCELLED"; /** States from which execution can resume after BLOCKED. */ export type ResumableMissionExecutionState = Extract; export declare const TERMINAL_STATES: ReadonlySet; export declare const RESUABLE_STATES: ReadonlySet; export type MissionExecutionTransitionKind = "START_EXECUTION" | "REQUEST_VERIFICATION" | "RETURN_TO_EXECUTION" | "REQUEST_COMPLETION_REVIEW" | "RETURN_TO_VERIFICATION" | "APPROVE_COMPLETION" | "BLOCK" | "RESUME" | "FAIL" | "CANCEL"; export interface MissionExecutionTransitionRecordV1 { /** Caller-supplied. Must be unique, non-empty, trimmed. */ transitionId: string; /** The kind of transition requested. */ kind: MissionExecutionTransitionKind; /** The state before this transition was applied. */ fromState: MissionExecutionState; /** The state after this transition was applied (derived by the machine). */ toState: MissionExecutionState; /** The revision before the transition. revisionAfter = revisionBefore + 1. */ revisionBefore: number; /** The revision after the transition. */ revisionAfter: number; } export interface MissionExecutionRecordV1 { readonly executionVersion: 1; /** Caller-supplied execution identifier. Must be non-empty, trimmed. */ readonly executionId: string; /** The canonical SHA-256 digest of the bound Mission Contract. */ readonly contractDigest: string; /** Monotonically increasing revision counter. Starts at 0. */ readonly revision: number; /** Current execution state. */ readonly state: MissionExecutionState; /** * The exact active state when BLOCKED was entered. * Present only when state === BLOCKED. */ readonly blockedFromState?: ResumableMissionExecutionState; /** Append-only transition history. */ readonly transitions: readonly MissionExecutionTransitionRecordV1[]; } export declare const MISSION_EXECUTION_RECORD_KEYS: ReadonlySet; export declare const MISSION_EXECUTION_TRANSITION_KEYS: ReadonlySet; export interface MissionExecutionTransitionRequestV1 { /** Caller-supplied. Must be unique, non-empty, trimmed. */ transitionId: string; /** The expected current revision. Rejected if mismatch. */ expectedRevision: number; /** The transition kind. */ kind: MissionExecutionTransitionKind; } export type MissionExecutionValidationResult = { readonly valid: true; } | { readonly valid: false; readonly error: string; }; export type MissionExecutionInspectionResult = { readonly valid: true; readonly executionId: string; readonly contractDigest: string; readonly state: MissionExecutionState; readonly revision: number; readonly transitionCount: number; readonly blockedFromState?: ResumableMissionExecutionState; readonly completionApproved: "unavailable"; } | { readonly valid: false; readonly error: string; }; export type MissionExecutionTransitionResult = { readonly ok: true; readonly record: MissionExecutionRecordV1; } | { readonly ok: false; readonly error: string; readonly code: MissionExecutionErrorCode; }; export type MissionExecutionErrorCode = "INVALID_EXECUTION_RECORD" | "INVALID_TRANSITION" | "STALE_REVISION" | "DUPLICATE_TRANSITION_ID" | "TERMINAL_STATE" | "ILLEGAL_TRANSITION" | "SELF_TRANSITION" | "BLOCK_WHILE_BLOCKED" | "RESUME_WHILE_NOT_BLOCKED" | "RESUME_STATE_NOT_RESUMABLE" | "TRUSTED_VALIDATION_CONTEXT_REQUIRED" | "EXECUTION_COMPLETION_CAPABILITY_REQUIRED" | "READINESS_GATE_BLOCKED" | "CONTRACT_DIGEST_MISMATCH" | "UNKNOWN_SEMANTIC_FIELD" | "INTERNAL_ERROR"; export declare const EXECUTION_COMPLETION_CAPABILITY: "execution:complete"; /** * Validate a MissionExecutionRecordV1 against its bound Mission Contract. * Performs deep structural validation, unknown-field rejection, and * full transition-history replay. */ export declare function validateMissionExecutionRecord(contract: MissionContractV1, record: unknown): MissionExecutionValidationResult; /** * Create a new MissionExecutionRecordV1 with revision 0 and state PLANNING. * The executionId and contractDigest are caller-supplied and deterministic. */ export declare function initializeMissionExecution(contract: MissionContractV1, executionId: string): MissionExecutionRecordV1; /** * Inspect a MissionExecutionRecordV1 structurally without requiring * trusted provenance. Never claims completion approval. */ export declare function inspectMissionExecution(_contract: MissionContractV1, record: unknown): MissionExecutionInspectionResult; /** * Apply a deterministic transition to a MissionExecutionRecordV1. * * Every mutation requires expectedRevision, caller-supplied transitionId, * and a transition kind. The destination state is derived by the state * machine from the current state and the transition kind. * * APPROVE_COMPLETION requires a genuine contract-bound * TrustedValidationContext. Without one, the transition is rejected. */ export declare function applyMissionExecutionTransition(contract: MissionContractV1, record: MissionExecutionRecordV1, request: MissionExecutionTransitionRequestV1, options?: { trustedValidationContext?: TrustedValidationContext; /** Adaptive readiness gate. When present and not ready, APPROVE_COMPLETION is blocked. */ readinessGate?: ReadinessInput; }): MissionExecutionTransitionResult; //# sourceMappingURL=execution-state-machine.d.ts.map