Skip to main content

forge_pilot/
types.rs

1//! Shared types for loop reports, decision audits, and verification artifacts.
2//!
3//! These types are serialized into loop iteration reports and consumed
4//! by downstream verification and adjudication surfaces.
5
6use schemars::JsonSchema;
7use semantic_memory_forge::{ExactnessLevelV1, ExecutionContextV1};
8use serde::{Deserialize, Serialize};
9use verification_control::{CheapCheckStatusV1, ProofProfileV1};
10
11/// The canonical verification case class for a target.
12#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
13#[serde(rename_all = "snake_case")]
14pub enum CanonicalCaseClass {
15    ContradictionInvestigation,
16    PromotionCandidate,
17    ThinExportGap,
18    SupersessionVerification,
19    ComparabilityDrift,
20    CalibrationCaveat,
21    ScopeFreshness,
22}
23
24/// Execution budget tier assigned to a verification target.
25#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
26#[serde(rename_all = "snake_case")]
27pub enum BudgetClass {
28    Micro,
29    Standard,
30    Expensive,
31}
32
33/// An individual verification step in the lawful step ladder for a target.
34#[derive(
35    Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize, JsonSchema,
36)]
37#[serde(rename_all = "snake_case")]
38pub enum LawfulStepKind {
39    ContractSchemaCheck,
40    ProvenanceReceiptAudit,
41    TemporalConsistencyCheck,
42    ExactReplay,
43    PairedComparativeCheck,
44    ExactOracleSlice,
45    ConservativeOracleSlice,
46    MinimalPerturbationRefuter,
47    NuisanceComparabilityAudit,
48    HumanReviewRequest,
49    CanonicalExportRequest,
50    CanonicalImportRequest,
51}
52
53/// Normalized representation of a target for cross-iteration comparability.
54#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
55pub struct TargetNormalization {
56    pub stable_target_key: String,
57    pub canonical_case_class: CanonicalCaseClass,
58    pub bounded_region_digest: String,
59    #[serde(default)]
60    pub required_artifact_families: Vec<String>,
61    pub budget_class: BudgetClass,
62    pub comparability_required: bool,
63    pub nuisance_sensitive: bool,
64    pub missing_falsifier: bool,
65}
66
67/// A single step in a verification plan with its cost and artifact requirements.
68#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
69pub struct PlannedStep {
70    pub step_kind: LawfulStepKind,
71    pub cost_rank: u8,
72    #[serde(default)]
73    pub required_artifact_families: Vec<String>,
74}
75
76/// Record of a verification step that was blocked and the reason why.
77#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
78pub struct BlockedStepRecord {
79    pub step_kind: LawfulStepKind,
80    pub reason: String,
81}
82
83/// Audit record capturing the decision rationale for a selected target.
84#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
85pub struct DecisionAudit {
86    pub stable_target_key: String,
87    pub canonical_case_class: CanonicalCaseClass,
88    pub budget_class: BudgetClass,
89    pub target_exactness: ExactnessLevelV1,
90    pub cheapest_admissible: Option<LawfulStepKind>,
91    #[serde(default)]
92    pub fallback_steps: Vec<PlannedStep>,
93    #[serde(default)]
94    pub blocked_steps: Vec<BlockedStepRecord>,
95    #[serde(default)]
96    pub cheap_check_ladder: Vec<CheapCheckStatusV1>,
97    pub advisory_only: bool,
98}
99
100/// Lineage receipt linking a verification case to its consumed and produced artifacts.
101#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
102pub struct ExecutionLineageReceipt {
103    pub case_id: String,
104    pub plan_id: String,
105    pub attempt_id: String,
106    pub target_key: String,
107    pub execution_context_ref: String,
108    #[serde(default)]
109    pub consumed_artifact_refs: Vec<String>,
110    #[serde(default)]
111    pub produced_artifact_refs: Vec<String>,
112    #[serde(default)]
113    pub degradation_markers: Vec<String>,
114    pub outcome_summary: String,
115}
116
117/// Trace record for the export-import roundtrip of an action's evidence bundle.
118#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
119pub struct ExportActionTraceV1 {
120    pub case_id: String,
121    pub plan_id: String,
122    pub attempt_id: String,
123    pub action_family: String,
124    pub bridge_roundtrip_completed: bool,
125    pub import_completed: bool,
126    #[serde(default)]
127    pub produced_artifact_refs: Vec<String>,
128}
129
130/// Evaluation of the loop stop rule at the end of an iteration.
131#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
132pub struct StopRuleEvaluation {
133    pub halt_reason: String,
134    pub retry_cap_reached: bool,
135    pub cooldown_applied: bool,
136    pub damping_applied: bool,
137    pub degraded: bool,
138    pub advisory_only: bool,
139}
140
141/// Classification of a repair action taken during or after a loop iteration.
142#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
143#[serde(rename_all = "snake_case")]
144pub enum RepairClassV1 {
145    IdentityRepair,
146    TemporalRepair,
147    SupersessionRepair,
148    RollbackRepair,
149    BundleImportRepair,
150    ScopeWideningRepair,
151    VerificationStateRepair,
152}
153
154/// Serializable verification plan artifact emitted per iteration.
155///
156/// Captures proof obligations, admissible evidence, cheapest check ladders,
157/// and policy blockers for downstream adjudication.
158#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
159#[schemars(title = "VerificationPlanArtifactV1")]
160pub struct VerificationPlanArtifact {
161    pub schema_version: String,
162    pub plan_id: String,
163    #[serde(default, skip_serializing_if = "Option::is_none")]
164    pub proof_profile: Option<ProofProfileV1>,
165    #[serde(default)]
166    pub cheapest_checks: Vec<String>,
167    #[serde(default)]
168    pub cheap_check_ladder: Vec<CheapCheckStatusV1>,
169    #[serde(default)]
170    pub replay_recipe: Vec<String>,
171    #[serde(default)]
172    pub replay_preconditions: Vec<String>,
173    #[serde(default)]
174    pub blocked_checks: Vec<String>,
175    #[serde(default)]
176    pub proof_obligations_remaining: Vec<String>,
177    #[serde(default)]
178    pub admissible_evidence: Vec<String>,
179    #[serde(default)]
180    pub refutation_suggestions: Vec<String>,
181    #[serde(default)]
182    pub degradation_flags: Vec<String>,
183    #[serde(default)]
184    pub policy_blockers: Vec<String>,
185    pub promotion_blocked_on_missing_proof: bool,
186    pub target_exactness: ExactnessLevelV1,
187    #[serde(default, skip_serializing_if = "Option::is_none")]
188    pub expires_at: Option<String>,
189}
190
191/// Structured record of a repair action applied to verification state.
192///
193/// Includes blast radius, reversibility, and a link back to the
194/// execution context that triggered the repair.
195#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
196#[schemars(title = "RepairRecordV1")]
197pub struct RepairRecordV1 {
198    pub schema_version: String,
199    pub repair_record_id: String,
200    #[serde(default)]
201    pub affected_identities: Vec<String>,
202    pub repair_class: RepairClassV1,
203    #[serde(default)]
204    pub trigger_artifacts: Vec<String>,
205    pub blast_radius: String,
206    pub reversibility: String,
207    pub action: String,
208    pub execution_context: ExecutionContextV1,
209    pub opened_at: String,
210    #[serde(default, skip_serializing_if = "Option::is_none")]
211    pub resolved_at: Option<String>,
212    pub unchanged_statement: String,
213}