Skip to main content

omena_transform_passes/
model.rs

1//! Public transform planning, execution, provenance, and context contracts.
2//!
3//! These data models are the stable JSON-facing boundary for Omena CSS transform
4//! passes. Runtime modules own mutation execution, while this module keeps the
5//! pass registry, execution summaries, semantic-removal witnesses, fuzz reports,
6//! and cross-file transform context shapes serializable for `omena-query`,
7//! bindings, CLI runners, and release gates.
8
9use omena_incremental::{IncrementalComputationPlanV0, IncrementalSnapshotV0};
10use omena_smt::CanonicalSmtInputV0;
11use omena_transform_cst::{TransformDagEdgeV0, TransformPassContractV0};
12use serde::{Deserialize, Serialize};
13use serde_json::Value;
14
15#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]
16#[serde(rename_all = "camelCase")]
17pub enum TransformPassExecutionStatus {
18    RegistryAndPlannerReady,
19}
20
21#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
22#[serde(rename_all = "camelCase")]
23pub struct TransformPassRegistryEntryV0 {
24    pub contract: TransformPassContractV0,
25    pub module_family: &'static str,
26    pub query_family: &'static str,
27    pub execution_status: TransformPassExecutionStatus,
28}
29
30#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
31#[serde(rename_all = "camelCase")]
32pub struct TransformPassesBoundarySummaryV0 {
33    pub schema_version: &'static str,
34    pub product: &'static str,
35    pub registry_entries: Vec<TransformPassRegistryEntryV0>,
36    pub dag_edges: Vec<TransformDagEdgeV0>,
37    pub pass_count: usize,
38    pub full_catalog_registered: bool,
39    pub semantic_aware_pass_count: usize,
40    pub cascade_aware_pass_count: usize,
41    pub planner_enforces_dag_edges: bool,
42    pub execution_runtime_ready: bool,
43    pub incremental_execution_runtime_ready: bool,
44    pub implemented_mutation_pass_ids: Vec<&'static str>,
45    pub next_surfaces: Vec<&'static str>,
46}
47
48#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
49#[serde(rename_all = "camelCase")]
50pub struct TransformPassPlanV0 {
51    pub schema_version: &'static str,
52    pub product: &'static str,
53    pub requested_pass_ids: Vec<&'static str>,
54    pub ordered_pass_ids: Vec<&'static str>,
55    pub satisfied_dag_edge_count: usize,
56    pub violated_dag_edge_count: usize,
57    pub all_requested_registered: bool,
58}
59
60#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]
61#[serde(rename_all = "camelCase")]
62pub enum TransformPassRuntimeStatus {
63    Applied,
64    NoChange,
65    PlannedOnly,
66}
67
68#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
69#[serde(rename_all = "camelCase")]
70pub struct TransformPassExecutionOutcomeV0 {
71    pub pass_id: &'static str,
72    pub status: TransformPassRuntimeStatus,
73    pub input_byte_len: usize,
74    pub output_byte_len: usize,
75    pub mutation_count: usize,
76    pub provenance_preserved: bool,
77    pub detail: &'static str,
78}
79
80#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
81#[serde(rename_all = "camelCase")]
82pub struct TransformProvenanceDerivationForestV0 {
83    pub schema_version: &'static str,
84    pub product: &'static str,
85    pub root_count: usize,
86    pub node_count: usize,
87    pub nodes: Vec<TransformProvenanceDerivationNodeV0>,
88}
89
90#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
91#[serde(rename_all = "camelCase")]
92pub struct TransformProvenanceDerivationNodeV0 {
93    pub node_index: usize,
94    pub parent_index: Option<usize>,
95    pub pass_id: &'static str,
96    pub status: TransformPassRuntimeStatus,
97    pub input_byte_len: usize,
98    pub output_byte_len: usize,
99    pub source_span_start: usize,
100    pub source_span_end: usize,
101    pub generated_span_start: usize,
102    pub generated_span_end: usize,
103    pub mutation_spans: Vec<TransformProvenanceMutationSpanV0>,
104    pub mutation_count: usize,
105    pub provenance_preserved: bool,
106    pub detail: &'static str,
107}
108
109#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
110#[serde(rename_all = "camelCase")]
111pub struct TransformProvenanceMutationSpanV0 {
112    pub source_span_start: usize,
113    pub source_span_end: usize,
114    pub generated_span_start: usize,
115    pub generated_span_end: usize,
116}
117
118#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
119#[serde(rename_all = "camelCase")]
120pub struct TransformExecutionSummaryV0 {
121    pub schema_version: &'static str,
122    pub product: &'static str,
123    pub input_byte_len: usize,
124    pub output_byte_len: usize,
125    pub requested_pass_ids: Vec<&'static str>,
126    pub ordered_pass_ids: Vec<&'static str>,
127    pub executed_pass_ids: Vec<&'static str>,
128    pub planned_only_pass_ids: Vec<&'static str>,
129    pub mutation_count: usize,
130    pub provenance_preserved: bool,
131    pub output_css: String,
132    pub css_module_evaluation: Option<TransformModuleEvaluationV0>,
133    pub css_import_inlines: Vec<TransformImportInlineV0>,
134    pub css_module_composes_exports: Vec<TransformCssModuleComposesResolutionV0>,
135    pub design_token_routes: Vec<TransformDesignTokenRouteV0>,
136    pub semantic_removals: Vec<TransformSemanticRemovalV0>,
137    pub cascade_proof_obligations: TransformCascadeProofObligationReportV0,
138    pub provenance_derivation_forest: TransformProvenanceDerivationForestV0,
139    pub outcomes: Vec<TransformPassExecutionOutcomeV0>,
140    pub pass_plan: TransformPassPlanV0,
141}
142
143#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
144#[serde(rename_all = "camelCase")]
145pub struct TransformCascadeProofObligationReportV0 {
146    pub schema_version: &'static str,
147    pub product: &'static str,
148    pub obligation_count: usize,
149    pub accepted_count: usize,
150    pub blocked_count: usize,
151    pub checked_pass_ids: Vec<&'static str>,
152    pub obligations: Vec<TransformCascadeProofObligationV0>,
153}
154
155#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
156#[serde(rename_all = "camelCase")]
157pub struct TransformCascadeProofObligationV0 {
158    pub pass_id: &'static str,
159    pub proof_product: &'static str,
160    pub accepted: bool,
161    pub blocked_reason: Option<String>,
162    pub provenance_preserved: bool,
163    pub cascade_safe_witness: String,
164    pub source_span_start: Option<usize>,
165    pub source_span_end: Option<usize>,
166    pub checked_obligations: Vec<&'static str>,
167    #[serde(skip_serializing_if = "Option::is_none")]
168    pub canonical_smt_input: Option<CanonicalSmtInputV0>,
169    pub proof_payload: Value,
170}
171
172#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
173#[serde(rename_all = "camelCase")]
174pub struct TransformSemanticRemovalV0 {
175    pub pass_id: &'static str,
176    pub symbol_kind: &'static str,
177    pub name: String,
178    pub source_span_start: usize,
179    pub source_span_end: usize,
180    pub reason: &'static str,
181    pub certainty: &'static str,
182    pub derivation_steps: Vec<&'static str>,
183}
184
185#[derive(Debug, Clone, PartialEq, Eq)]
186pub(crate) struct TransformSemanticRemovalCandidate {
187    pub(crate) symbol_kind: &'static str,
188    pub(crate) name: String,
189    pub(crate) source_span_start: usize,
190    pub(crate) source_span_end: usize,
191    pub(crate) reason: &'static str,
192}
193
194impl TransformSemanticRemovalCandidate {
195    pub(crate) fn into_public(self, pass_id: &'static str) -> TransformSemanticRemovalV0 {
196        TransformSemanticRemovalV0 {
197            pass_id,
198            symbol_kind: self.symbol_kind,
199            name: self.name,
200            source_span_start: self.source_span_start,
201            source_span_end: self.source_span_end,
202            reason: self.reason,
203            certainty: "high",
204            derivation_steps: vec![
205                "closedStyleWorld",
206                "reachableRootSetComputed",
207                "symbolNotMarkedReachable",
208                "sourceRangeRemoved",
209            ],
210        }
211    }
212}
213
214#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
215#[serde(rename_all = "camelCase")]
216pub struct TransformIncrementalExecutionSummaryV0 {
217    pub schema_version: &'static str,
218    pub product: &'static str,
219    pub incremental_engine: &'static str,
220    pub query_model: &'static str,
221    pub reuse_policy: &'static str,
222    pub reused_previous_execution: bool,
223    pub incremental_plan: IncrementalComputationPlanV0,
224    pub next_snapshot: IncrementalSnapshotV0,
225    pub execution: TransformExecutionSummaryV0,
226    pub ready_surfaces: Vec<&'static str>,
227}
228
229#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
230#[serde(rename_all = "camelCase")]
231pub struct TransformCascadeSafetyFuzzCaseV0 {
232    pub seed: u64,
233    pub pass_count: usize,
234}
235
236#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
237#[serde(rename_all = "camelCase")]
238pub struct TransformCascadeSafetyFuzzResultV0 {
239    pub seed: u64,
240    pub pass_count: usize,
241    pub requested_pass_ids: Vec<&'static str>,
242    pub executed_pass_ids: Vec<&'static str>,
243    pub output_byte_len: usize,
244    pub output_token_count: usize,
245    pub output_error_count: usize,
246    pub provenance_node_count: usize,
247    pub passed: bool,
248}
249
250#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
251#[serde(rename_all = "camelCase")]
252pub struct TransformFuzzSeedReportV0 {
253    pub schema_version: &'static str,
254    pub product: &'static str,
255    pub case_count: usize,
256    pub passed_count: usize,
257    pub failed_count: usize,
258    pub results: Vec<TransformCascadeSafetyFuzzResultV0>,
259}
260
261#[derive(Debug, Clone, Default, PartialEq, Eq, Deserialize, Serialize)]
262#[serde(default, rename_all = "camelCase")]
263pub struct TransformExecutionContextV0 {
264    pub closed_style_world: bool,
265    pub drop_dark_mode_media_queries: bool,
266    pub reachable_class_names: Vec<String>,
267    pub reachable_keyframe_names: Vec<String>,
268    pub reachable_value_names: Vec<String>,
269    pub reachable_custom_property_names: Vec<String>,
270    pub scss_module_evaluation: Option<TransformModuleEvaluationV0>,
271    pub less_module_evaluation: Option<TransformModuleEvaluationV0>,
272    pub import_inlines: Vec<TransformImportInlineV0>,
273    pub class_name_rewrites: Vec<TransformClassNameRewriteV0>,
274    pub css_module_composes_resolutions: Vec<TransformCssModuleComposesResolutionV0>,
275    pub css_module_value_resolutions: Vec<TransformCssModuleValueResolutionV0>,
276    pub design_token_routes: Vec<TransformDesignTokenRouteV0>,
277}
278
279#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
280#[serde(rename_all = "camelCase")]
281pub struct TransformModuleEvaluationV0 {
282    pub evaluator: String,
283    pub evaluated_css: String,
284}
285
286#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
287#[serde(rename_all = "camelCase")]
288pub struct TransformImportInlineV0 {
289    pub import_source: String,
290    pub replacement_css: String,
291}
292
293#[derive(Debug, Clone, PartialEq, Eq)]
294pub struct TransformLessInlineLiteralPlaceholderV0 {
295    pub placeholder: String,
296    pub literal_css: String,
297}
298
299#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
300#[serde(rename_all = "camelCase")]
301pub struct TransformClassNameRewriteV0 {
302    pub original_name: String,
303    pub rewritten_name: String,
304}
305
306#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
307#[serde(rename_all = "camelCase")]
308pub struct TransformCssModuleComposesResolutionV0 {
309    pub local_class_name: String,
310    pub exported_class_names: Vec<String>,
311}
312
313#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
314#[serde(rename_all = "camelCase")]
315pub struct TransformCssModuleValueResolutionV0 {
316    pub local_name: String,
317    pub resolved_value: String,
318}
319
320#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
321#[serde(rename_all = "camelCase")]
322pub struct TransformDesignTokenRouteV0 {
323    pub token_name: String,
324    pub routed_value: String,
325}