pgc-compiler 2.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (177) hide show
  1. compiler/VERSION +1 -0
  2. compiler/__init__.py +1 -0
  3. compiler/atoms/__init__.py +54 -0
  4. compiler/atoms/error_codes.py +160 -0
  5. compiler/atoms/errors.py +125 -0
  6. compiler/atoms/fqdn.py +204 -0
  7. compiler/atoms/invariants.py +106 -0
  8. compiler/atoms/phase.py +99 -0
  9. compiler/atoms/pipeline.py +51 -0
  10. compiler/atoms/snapshot_gate.py +51 -0
  11. compiler/atoms/sorting.py +125 -0
  12. compiler/cli.py +637 -0
  13. compiler/diagnostics/__init__.py +6 -0
  14. compiler/diagnostics/determination.py +148 -0
  15. compiler/diagnostics/machine_block_health.py +199 -0
  16. compiler/governance/__init__.py +6 -0
  17. compiler/governance_engine/__init__.py +0 -0
  18. compiler/governance_engine/artifact_kinds.py +221 -0
  19. compiler/governance_engine/assertions/__init__.py +0 -0
  20. compiler/governance_engine/assertions/handlers/__init__.py +200 -0
  21. compiler/governance_engine/assertions/handlers/assert_ac_declaration_well_formed_v0.py +70 -0
  22. compiler/governance_engine/assertions/handlers/assert_actor_authority_separation_v0.py +17 -0
  23. compiler/governance_engine/assertions/handlers/assert_artifact_content_hash_declared_v0.py +60 -0
  24. compiler/governance_engine/assertions/handlers/assert_assert_not_runtime_referenced_v0.py +49 -0
  25. compiler/governance_engine/assertions/handlers/assert_assert_parity_v0.py +169 -0
  26. compiler/governance_engine/assertions/handlers/assert_atom_output_purity_v0.py +186 -0
  27. compiler/governance_engine/assertions/handlers/assert_authority_constituted_v0.py +56 -0
  28. compiler/governance_engine/assertions/handlers/assert_authority_required_for_execution_v0.py +16 -0
  29. compiler/governance_engine/assertions/handlers/assert_authority_state_well_formed_v0.py +17 -0
  30. compiler/governance_engine/assertions/handlers/assert_binding_integrity_v0.py +64 -0
  31. compiler/governance_engine/assertions/handlers/assert_binding_surface_closed_v0.py +92 -0
  32. compiler/governance_engine/assertions/handlers/assert_cc_capability_binding_valid_v0.py +85 -0
  33. compiler/governance_engine/assertions/handlers/assert_cc_inputs_satisfied_v0.py +89 -0
  34. compiler/governance_engine/assertions/handlers/assert_cc_no_implicit_chaining_v0.py +89 -0
  35. compiler/governance_engine/assertions/handlers/assert_cc_no_missing_dependencies_v0.py +89 -0
  36. compiler/governance_engine/assertions/handlers/assert_cc_no_unused_outputs_v0.py +81 -0
  37. compiler/governance_engine/assertions/handlers/assert_cc_storage_op_conformance_v0.py +74 -0
  38. compiler/governance_engine/assertions/handlers/assert_compiler_governance_declared_v0.py +65 -0
  39. compiler/governance_engine/assertions/handlers/assert_compiler_no_execution_v0.py +86 -0
  40. compiler/governance_engine/assertions/handlers/assert_concern_not_authority_v0.py +51 -0
  41. compiler/governance_engine/assertions/handlers/assert_conformance_assertion_mode_valid_v0.py +35 -0
  42. compiler/governance_engine/assertions/handlers/assert_cryptographic_trust_declared_v0.py +51 -0
  43. compiler/governance_engine/assertions/handlers/assert_cs_isolated_execution_v0.py +35 -0
  44. compiler/governance_engine/assertions/handlers/assert_cs_surface_closed_v0.py +241 -0
  45. compiler/governance_engine/assertions/handlers/assert_cs_traceable_v0.py +35 -0
  46. compiler/governance_engine/assertions/handlers/assert_ct_output_contract_match_v0.py +167 -0
  47. compiler/governance_engine/assertions/handlers/assert_ct_surface_closed_v0.py +173 -0
  48. compiler/governance_engine/assertions/handlers/assert_ct_surface_derived_closed_v0.py +108 -0
  49. compiler/governance_engine/assertions/handlers/assert_ct_test_data_outcome_declared_v0.py +112 -0
  50. compiler/governance_engine/assertions/handlers/assert_ev_append_only_v0.py +70 -0
  51. compiler/governance_engine/assertions/handlers/assert_ev_schema_required_v0.py +59 -0
  52. compiler/governance_engine/assertions/handlers/assert_execution_placement_declared_v0.py +51 -0
  53. compiler/governance_engine/assertions/handlers/assert_execution_scheduling_declared_v0.py +51 -0
  54. compiler/governance_engine/assertions/handlers/assert_fqdn_namespace_authorized_v0.py +38 -0
  55. compiler/governance_engine/assertions/handlers/assert_fqdn_only_references_v0.py +89 -0
  56. compiler/governance_engine/assertions/handlers/assert_governance_declaration_resolves_v0.py +126 -0
  57. compiler/governance_engine/assertions/handlers/assert_handler_registry_closed_v0.py +75 -0
  58. compiler/governance_engine/assertions/handlers/assert_identity_authority_separation_v0.py +19 -0
  59. compiler/governance_engine/assertions/handlers/assert_identity_fqdn_consistency.py +75 -0
  60. compiler/governance_engine/assertions/handlers/assert_implementation_admissible_v0.py +66 -0
  61. compiler/governance_engine/assertions/handlers/assert_in_no_execution_logic_v0.py +82 -0
  62. compiler/governance_engine/assertions/handlers/assert_in_schema_required_v0.py +74 -0
  63. compiler/governance_engine/assertions/handlers/assert_in_workflow_binding_v0.py +101 -0
  64. compiler/governance_engine/assertions/handlers/assert_inspection_capability_read_only_v0.py +114 -0
  65. compiler/governance_engine/assertions/handlers/assert_no_ambient_authority_v0.py +17 -0
  66. compiler/governance_engine/assertions/handlers/assert_no_runtime_authorization_v0.py +18 -0
  67. compiler/governance_engine/assertions/handlers/assert_no_runtime_topology_synthesis_v0.py +18 -0
  68. compiler/governance_engine/assertions/handlers/assert_no_smart_execution_v0.py +102 -0
  69. compiler/governance_engine/assertions/handlers/assert_no_undeclared_behavior_surface_v0.py +52 -0
  70. compiler/governance_engine/assertions/handlers/assert_no_workflow_authorization_logic_v0.py +18 -0
  71. compiler/governance_engine/assertions/handlers/assert_protocol_surface_closed_v0.py +119 -0
  72. compiler/governance_engine/assertions/handlers/assert_rb_binding_policy_conformance_v0.py +124 -0
  73. compiler/governance_engine/assertions/handlers/assert_rb_cs_only_v0.py +68 -0
  74. compiler/governance_engine/assertions/handlers/assert_rb_no_logic_v0.py +81 -0
  75. compiler/governance_engine/assertions/handlers/assert_rb_parameters_declared_v0.py +117 -0
  76. compiler/governance_engine/assertions/handlers/assert_rb_storage_subdomain_owned_v0.py +118 -0
  77. compiler/governance_engine/assertions/handlers/assert_runtime_invariant_wired_v0.py +163 -0
  78. compiler/governance_engine/assertions/handlers/assert_schema_conformance_v0.py +64 -0
  79. compiler/governance_engine/assertions/handlers/assert_schema_description_well_formed_v0.py +97 -0
  80. compiler/governance_engine/assertions/handlers/assert_security_domain_declared_v0.py +51 -0
  81. compiler/governance_engine/assertions/handlers/assert_structure_paths_well_formed_v0.py +118 -0
  82. compiler/governance_engine/assertions/handlers/assert_superseded_not_referenced_v0.py +134 -0
  83. compiler/governance_engine/assertions/handlers/assert_test_data_match_ct_output_v0.py +134 -0
  84. compiler/governance_engine/assertions/handlers/assert_topology_acyclic_v0.py +53 -0
  85. compiler/governance_engine/assertions/handlers/assert_topology_authority_orthogonal_v0.py +110 -0
  86. compiler/governance_engine/assertions/handlers/assert_topology_capability_reference_unique_v0.py +63 -0
  87. compiler/governance_engine/assertions/handlers/assert_topology_contract_closed_v0.py +113 -0
  88. compiler/governance_engine/assertions/handlers/assert_topology_immutable_after_compilation_v0.py +17 -0
  89. compiler/governance_engine/assertions/handlers/assert_topology_input_reference_declared_v0.py +112 -0
  90. compiler/governance_engine/assertions/handlers/assert_topology_routing_complete_v0.py +82 -0
  91. compiler/governance_engine/assertions/handlers/assert_topology_step_declared_v0.py +77 -0
  92. compiler/governance_engine/assertions/handlers/assert_topology_step_id_unique_v0.py +60 -0
  93. compiler/governance_engine/assertions/handlers/assert_topology_surface_canonical_v0.py +180 -0
  94. compiler/governance_engine/assertions/handlers/assert_topology_transport_orthogonal_v0.py +113 -0
  95. compiler/governance_engine/assertions/handlers/assert_trace_authority_binding_required_v0.py +18 -0
  96. compiler/governance_engine/assertions/handlers/assert_transport_canonical_normalization_v0.py +83 -0
  97. compiler/governance_engine/assertions/handlers/assert_transport_no_dynamic_routing_v0.py +93 -0
  98. compiler/governance_engine/assertions/handlers/assert_transport_no_workflow_semantics_v0.py +106 -0
  99. compiler/governance_engine/assertions/handlers/assert_transport_operation_identity_independence_v0.py +56 -0
  100. compiler/governance_engine/assertions/handlers/assert_transport_response_projection_external_v0.py +38 -0
  101. compiler/governance_engine/assertions/handlers/assert_transport_result_class_protocol_independence_v0.py +48 -0
  102. compiler/governance_engine/assertions/handlers/assert_transport_target_exists_v0.py +132 -0
  103. compiler/governance_engine/assertions/handlers/assert_unique_artifact_id_v0.py +58 -0
  104. compiler/governance_engine/assertions/handlers/assert_vocabulary_symbols_well_formed_v0.py +163 -0
  105. compiler/governance_engine/assertions/handlers/assert_wf_announcement_distinct_v0.py +85 -0
  106. compiler/governance_engine/assertions/handlers/assert_wf_cc_only_nodes_v0.py +60 -0
  107. compiler/governance_engine/assertions/handlers/assert_wf_entry_intent_v0.py +68 -0
  108. compiler/governance_engine/assertions/handlers/assert_wf_execution_path_valid_v0.py +89 -0
  109. compiler/governance_engine/assertions/handlers/assert_wf_node_key_binding_unique_v0.py +107 -0
  110. compiler/governance_engine/platform_root.py +102 -0
  111. compiler/governance_engine/structure/__init__.py +56 -0
  112. compiler/governance_engine/structure/discovery/__init__.py +28 -0
  113. compiler/governance_engine/structure/discovery/artifact_locator.py +210 -0
  114. compiler/governance_engine/structure/exceptions.py +113 -0
  115. compiler/governance_engine/structure/loading/__init__.py +88 -0
  116. compiler/governance_engine/structure/loading/fs_reader.py +225 -0
  117. compiler/governance_engine/structure/loading/markdown_parser.py +148 -0
  118. compiler/governance_engine/structure/loading/protocol_loader.py +587 -0
  119. compiler/governance_engine/structure/loading/test_case_provider.py +125 -0
  120. compiler/governance_engine/structure/loading/trace_reader.py +98 -0
  121. compiler/governance_engine/structure/loading/vocabulary_loader.py +174 -0
  122. compiler/governance_engine/structure/loading/yaml_parser.py +209 -0
  123. compiler/governance_engine/structure/resolution/__init__.py +22 -0
  124. compiler/governance_engine/structure/resolution/domain_resolver.py +124 -0
  125. compiler/governance_engine/structure/resolution/layer_resolver.py +572 -0
  126. compiler/governance_engine/structure/resolution/path_registry.py +1054 -0
  127. compiler/graph/__init__.py +38 -0
  128. compiler/graph/addressing.py +153 -0
  129. compiler/graph/edge.py +100 -0
  130. compiler/graph/evidence.py +637 -0
  131. compiler/graph/graph.py +269 -0
  132. compiler/graph/hashing.py +89 -0
  133. compiler/graph/node.py +134 -0
  134. compiler/graph/query.py +215 -0
  135. compiler/graph/state.py +237 -0
  136. compiler/graph/trace.py +97 -0
  137. compiler/graph/types.py +71 -0
  138. compiler/projections/__init__.py +207 -0
  139. compiler/projections/artifact_index.py +225 -0
  140. compiler/projections/canonical.py +173 -0
  141. compiler/projections/dispatch.py +532 -0
  142. compiler/projections/evidence.py +170 -0
  143. compiler/projections/handlers.py +224 -0
  144. compiler/projections/ipm.py +388 -0
  145. compiler/projections/reverse.py +165 -0
  146. compiler/projections/tokenized.py +135 -0
  147. compiler/projections/vocabulary.py +108 -0
  148. compiler/stages/__init__.py +28 -0
  149. compiler/stages/s1_extract.py +867 -0
  150. compiler/stages/s2_canonicalize.py +516 -0
  151. compiler/stages/s3_semantic_addressing.py +66 -0
  152. compiler/stages/s4_govern.py +754 -0
  153. compiler/stages/s5_construct.py +537 -0
  154. compiler/stages/s6_project.py +94 -0
  155. compiler/stages/s7_materialize.py +1170 -0
  156. compiler/stages/s8_verify.py +643 -0
  157. compiler/stages/s9_attest.py +184 -0
  158. compiler/structure_loader.py +132 -0
  159. compiler/visualization/__init__.py +12 -0
  160. compiler/visualization/consumers/__init__.py +28 -0
  161. compiler/visualization/consumers/evidence_projection.py +162 -0
  162. compiler/visualization/consumers/evidence_query.py +296 -0
  163. compiler/visualization/consumers/evidence_reader.py +127 -0
  164. compiler/visualization/views/__init__.py +70 -0
  165. compiler/visualization/views/_png_writer.py +45 -0
  166. compiler/visualization/views/artifact_lineage.py +180 -0
  167. compiler/visualization/views/family_view.py +164 -0
  168. compiler/visualization/views/materialization_view.py +150 -0
  169. compiler/visualization/views/structural_dag.py +158 -0
  170. compiler/visualization/wf_graph_generator.py +534 -0
  171. pgc_compiler-2.0.0.dist-info/METADATA +203 -0
  172. pgc_compiler-2.0.0.dist-info/RECORD +177 -0
  173. pgc_compiler-2.0.0.dist-info/WHEEL +5 -0
  174. pgc_compiler-2.0.0.dist-info/entry_points.txt +2 -0
  175. pgc_compiler-2.0.0.dist-info/licenses/LICENSE +67 -0
  176. pgc_compiler-2.0.0.dist-info/licenses/NOTICE +11 -0
  177. pgc_compiler-2.0.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,89 @@
1
+ """
2
+ ASSERT_CC_NO_IMPLICIT_CHAINING_V0 Handler
3
+
4
+ Validates CC artifacts contain no orchestration logic:
5
+ - No next_step field (explicit chaining)
6
+ - No next field (state transitions)
7
+ - No transitions field (workflow logic)
8
+ - No flow field (control flow)
9
+ - No conditional field (branching)
10
+ - No loop field (iteration)
11
+
12
+ CONSTITUTIONAL: Pure rule checker - reads pre-computed structure from context
13
+ """
14
+
15
+
16
+ def execute(artifacts: list[dict], compilation_context: dict) -> dict:
17
+ """
18
+ Validate all CC artifacts for absence of orchestration logic against pre-computed analysis.
19
+
20
+ Args:
21
+ artifacts: All validated artifacts
22
+ compilation_context: Contains pre-computed cc_chaining
23
+
24
+ Returns:
25
+ {
26
+ "assert_count": int,
27
+ "violations": list[dict], # Standardized schema
28
+ "status": "PASSED/FAILED"
29
+ }
30
+ """
31
+ violations = []
32
+ cc_count = 0
33
+
34
+ # STRICT INVERSION OF CONTROL: Compiler must provide complete context
35
+ cc_chaining = compilation_context.get("cc_chaining")
36
+
37
+ if cc_chaining is None:
38
+ return {
39
+ "assert_count": 0,
40
+ "violations": [{
41
+ "fqdn": "capability_contracts::ASSERT_CC_NO_IMPLICIT_CHAINING_V0",
42
+ "rule": "COMPILATION_CONTEXT_COMPLETE",
43
+ "message": "Compilation context missing cc_chaining",
44
+ "fix": "Compiler must pre-compute CC chaining analysis before assert phase"
45
+ }],
46
+ "status": "FAILED"
47
+ }
48
+
49
+ # Check rules against pre-computed structure
50
+ for artifact in artifacts:
51
+ if artifact.get("artifact_type") != "CC":
52
+ continue
53
+
54
+ cc_count += 1
55
+ fqdn = artifact["fqdn_id"]
56
+ chaining_result = cc_chaining.get(fqdn)
57
+
58
+ if not chaining_result:
59
+ violations.append({
60
+ "fqdn": fqdn,
61
+ "rule": "capability_contracts::INVARIANT_CC_NO_IMPLICIT_CHAINING_V0",
62
+ "message": "Missing chaining analysis for CC artifact",
63
+ "fix": "Compiler must analyze all CC artifacts"
64
+ })
65
+ continue
66
+
67
+ # Translate structural violations to standardized rule violations
68
+ if chaining_result.get("status") == "FAILED":
69
+ for structural_violation in chaining_result.get("violations", []):
70
+ violations.append({
71
+ "fqdn": fqdn,
72
+ "rule": "capability_contracts::INVARIANT_CC_NO_IMPLICIT_CHAINING_V0",
73
+ "message": structural_violation.get("violation", "Unknown CC chaining violation"),
74
+ "fix": structural_violation.get("fix", "Remove orchestration fields from CC")
75
+ })
76
+
77
+ # Return standardized result
78
+ if violations:
79
+ return {
80
+ "assert_count": cc_count,
81
+ "violations": violations,
82
+ "status": "FAILED"
83
+ }
84
+
85
+ return {
86
+ "assert_count": cc_count,
87
+ "violations": [],
88
+ "status": "PASSED"
89
+ }
@@ -0,0 +1,89 @@
1
+ """
2
+ ASSERT_CC_NO_MISSING_DEPENDENCIES_V0 - Handler
3
+
4
+ Enforces INVARIANT_CC_NO_MISSING_DEPENDENCIES_V0 at compile time.
5
+
6
+ Validates CC dependency ordering and reachability for all WF artifacts:
7
+ - No forward references (CC_B references CC_C that appears later)
8
+ - No cross-branch references (CC_B references CC_C on different branch)
9
+
10
+ Validation Scope: ORDERING and REACHABILITY ONLY (not field existence, not FQDN resolution)
11
+
12
+ CONSTITUTIONAL: Pure rule checker - reads pre-computed structure from context
13
+ """
14
+
15
+
16
+ def execute(artifacts: list[dict], compilation_context: dict) -> dict:
17
+ """
18
+ Validate CC dependency ordering against pre-computed structural analysis.
19
+
20
+ Args:
21
+ artifacts: All validated artifacts
22
+ compilation_context: Contains pre-computed cc_dependencies
23
+
24
+ Returns:
25
+ {
26
+ "assert_count": int,
27
+ "violations": list[dict], # Standardized schema
28
+ "status": "PASSED/FAILED"
29
+ }
30
+ """
31
+ violations = []
32
+ wf_count = 0
33
+
34
+ # STRICT INVERSION OF CONTROL: Compiler must provide complete context
35
+ cc_dependencies = compilation_context.get("cc_dependencies")
36
+
37
+ if cc_dependencies is None:
38
+ return {
39
+ "assert_count": 0,
40
+ "violations": [{
41
+ "fqdn": "capability_contracts::ASSERT_CC_NO_MISSING_DEPENDENCIES_V0",
42
+ "rule": "COMPILATION_CONTEXT_COMPLETE",
43
+ "message": "Compilation context missing cc_dependencies",
44
+ "fix": "Compiler must pre-compute CC dependency analysis before assert phase"
45
+ }],
46
+ "status": "FAILED"
47
+ }
48
+
49
+ # Check rules against pre-computed structure
50
+ for artifact in artifacts:
51
+ if artifact.get("artifact_type") != "WF":
52
+ continue
53
+
54
+ wf_count += 1
55
+ fqdn = artifact["fqdn_id"]
56
+ deps_result = cc_dependencies.get(fqdn)
57
+
58
+ if not deps_result:
59
+ violations.append({
60
+ "fqdn": fqdn,
61
+ "rule": "capability_contracts::INVARIANT_CC_NO_MISSING_DEPENDENCIES_V0",
62
+ "message": "Missing dependency analysis for WF artifact",
63
+ "fix": "Compiler must analyze all WF artifacts"
64
+ })
65
+ continue
66
+
67
+ # Translate structural violations to standardized rule violations
68
+ if deps_result.get("status") == "FAILED":
69
+ for structural_violation in deps_result.get("violations", []):
70
+ violations.append({
71
+ "fqdn": fqdn,
72
+ "rule": "capability_contracts::INVARIANT_CC_NO_MISSING_DEPENDENCIES_V0",
73
+ "message": structural_violation.get("violation", "Unknown CC dependency violation"),
74
+ "fix": structural_violation.get("fix", "Ensure all CC dependencies are satisfied")
75
+ })
76
+
77
+ # Return standardized result
78
+ if violations:
79
+ return {
80
+ "assert_count": wf_count,
81
+ "violations": violations,
82
+ "status": "FAILED"
83
+ }
84
+
85
+ return {
86
+ "assert_count": wf_count,
87
+ "violations": [],
88
+ "status": "PASSED"
89
+ }
@@ -0,0 +1,81 @@
1
+ """
2
+ ASSERT_CC_NO_UNUSED_OUTPUTS_V0 - Handler
3
+
4
+ Enforces INVARIANT_CC_NO_UNUSED_OUTPUTS_V0 at compile time.
5
+
6
+ Detects unused CC outputs as code smell indicator:
7
+ - Outputs produced but never consumed
8
+ - Potential optimization opportunities
9
+ - Incomplete workflow indicators
10
+
11
+ Enforcement Level: WARNING (not ERROR)
12
+ - Build succeeds with warnings
13
+ - Warnings logged for author review
14
+
15
+ CONSTITUTIONAL: Pure rule checker - reads pre-computed structure from context
16
+ """
17
+
18
+
19
+ def execute(artifacts: list[dict], compilation_context: dict) -> dict:
20
+ """
21
+ Check for unused CC outputs against pre-computed structural analysis.
22
+
23
+ Args:
24
+ artifacts: All validated artifacts
25
+ compilation_context: Contains pre-computed cc_unused_outputs
26
+
27
+ Returns:
28
+ Assertion result with warnings (not violations)
29
+ """
30
+ wf_count = 0
31
+ all_warnings = []
32
+
33
+ # STRICT INVERSION OF CONTROL: Compiler must provide complete context
34
+ cc_unused_outputs = compilation_context.get("cc_unused_outputs")
35
+
36
+ if cc_unused_outputs is None:
37
+ return {
38
+ "assert_count": 0,
39
+ "violations": [{
40
+ "fqdn": "capability_contracts::ASSERT_CC_NO_UNUSED_OUTPUTS_V0",
41
+ "rule": "COMPILATION_CONTEXT_COMPLETE",
42
+ "message": "Compilation context missing cc_unused_outputs",
43
+ "fix": "Compiler must pre-compute CC unused outputs analysis before assert phase"
44
+ }],
45
+ "status": "FAILED"
46
+ }
47
+
48
+ # Check WF artifacts for unused outputs
49
+ for artifact in artifacts:
50
+ if artifact.get("artifact_type") != "WF":
51
+ continue
52
+
53
+ wf_count += 1
54
+
55
+ # Aggregate warnings from all per-WF analyses
56
+ for wf_fqdn, result in cc_unused_outputs.items():
57
+ warnings = result.get("warnings", [])
58
+ if warnings:
59
+ for warning in warnings:
60
+ all_warnings.append({
61
+ "fqdn": wf_fqdn,
62
+ "rule": "capability_contracts::INVARIANT_CC_NO_UNUSED_OUTPUTS_V0",
63
+ "message": warning.get("violation", warning.get("message", "Unknown unused output warning")),
64
+ "fix": warning.get("fix", "Remove unused output or connect it to a consumer")
65
+ })
66
+
67
+ if all_warnings:
68
+ return {
69
+ "assert_count": wf_count,
70
+ "violations": [], # No violations - warnings are not blocking
71
+ "warnings": all_warnings,
72
+ "warning_count": len(all_warnings),
73
+ "status": "PASSED" # PASSED with warnings
74
+ }
75
+
76
+ return {
77
+ "assert_count": wf_count,
78
+ "violations": [],
79
+ "warnings": [],
80
+ "status": "PASSED"
81
+ }
@@ -0,0 +1,74 @@
1
+ """
2
+ ASSERT_CC_STORAGE_OP_CONFORMANCE_V0 Handler
3
+
4
+ Validates that every CC pipeline step with a side_effect binding declares an op
5
+ that exists in the target CS's core.policy.operations list.
6
+
7
+ CONSTITUTIONAL: Pure rule checker — reads pre-computed structure from context.
8
+ """
9
+
10
+
11
+ def execute(artifacts: list[dict], compilation_context: dict) -> dict:
12
+ """
13
+ Validate all CC op declarations against pre-computed CS operation conformance.
14
+
15
+ Args:
16
+ artifacts: All validated artifacts
17
+ compilation_context: Contains pre-computed cc_op_conformance
18
+
19
+ Returns:
20
+ {
21
+ "assert_count": int,
22
+ "violations": list[dict],
23
+ "status": "PASSED/FAILED"
24
+ }
25
+ """
26
+ violations = []
27
+ cc_count = 0
28
+
29
+ cc_op_conformance = compilation_context.get("cc_op_conformance")
30
+
31
+ if cc_op_conformance is None:
32
+ return {
33
+ "assert_count": 0,
34
+ "violations": [{
35
+ "fqdn": "capability_contracts::ASSERT_CC_STORAGE_OP_CONFORMANCE_V0",
36
+ "rule": "COMPILATION_CONTEXT_COMPLETE",
37
+ "message": "Compilation context missing cc_op_conformance",
38
+ "fix": "Compiler must pre-compute CC op conformance analysis before assert phase"
39
+ }],
40
+ "status": "FAILED"
41
+ }
42
+
43
+ for artifact in artifacts:
44
+ if artifact.get("artifact_type") != "CC":
45
+ continue
46
+
47
+ cc_count += 1
48
+ fqdn = artifact["fqdn_id"]
49
+ conformance_result = cc_op_conformance.get(fqdn)
50
+
51
+ if not conformance_result:
52
+ continue # CC has no CS-binding steps — exempt
53
+
54
+ if conformance_result.get("status") == "FAILED":
55
+ for structural_violation in conformance_result.get("violations", []):
56
+ violations.append({
57
+ "fqdn": fqdn,
58
+ "rule": "capability_contracts::INVARIANT_CC_STORAGE_OP_CONFORMANCE_V0",
59
+ "message": structural_violation.get("violation", "Unknown op conformance violation"),
60
+ "fix": structural_violation.get("fix", "Correct op to match CS declared operations"),
61
+ })
62
+
63
+ if violations:
64
+ return {
65
+ "assert_count": cc_count,
66
+ "violations": violations,
67
+ "status": "FAILED"
68
+ }
69
+
70
+ return {
71
+ "assert_count": cc_count,
72
+ "violations": [],
73
+ "status": "PASSED"
74
+ }
@@ -0,0 +1,65 @@
1
+ """
2
+ ASSERT_COMPILER_GOVERNANCE_DECLARED_V0 Handler
3
+
4
+ Verifies CONSTITUTION_COMPILER_V0 is present in the compiled artifact set
5
+ and declares a non-empty rules list — enforcing COMPILER_SELF_APPLICABLE.
6
+ """
7
+
8
+ from typing import Any
9
+
10
+ _COMPILER_CONSTITUTION_FQDN = "compiler::CONSTITUTION_COMPILER_V0"
11
+
12
+
13
+ def execute(artifacts: list[dict], compilation_context: dict) -> dict:
14
+ """
15
+ Verify CONSTITUTION_COMPILER_V0 is present and well-formed.
16
+
17
+ Args:
18
+ artifacts: All compiled artifacts
19
+ compilation_context: Not used
20
+
21
+ Returns:
22
+ {
23
+ "assert_count": int,
24
+ "violations": list[dict],
25
+ "status": str
26
+ }
27
+ """
28
+ violations = []
29
+
30
+ # Locate CONSTITUTION_COMPILER_V0 in compiled set
31
+ constitution = next(
32
+ (a for a in artifacts if a.get("fqdn_id") == _COMPILER_CONSTITUTION_FQDN),
33
+ None,
34
+ )
35
+
36
+ if constitution is None:
37
+ violations.append({
38
+ "fqdn": _COMPILER_CONSTITUTION_FQDN,
39
+ "rule": "compiler::INVARIANT_COMPILER_GOVERNANCE_DECLARED_V0",
40
+ "message": (
41
+ f"COMPILER_SELF_APPLICABLE violated: {_COMPILER_CONSTITUTION_FQDN} "
42
+ "is absent from the compiled artifact set"
43
+ ),
44
+ "fix": (
45
+ "Ensure the STRUCTURE declaration includes compiler as a "
46
+ "governed boundary so CONSTITUTION_COMPILER_V0 is discovered and compiled"
47
+ ),
48
+ })
49
+ # The emptiness check that stood here is retired: SCHEMA_CONSTITUTION_V0 requires a
50
+ # non-empty rules list on every constitution, and ASSERT_GOVERNANCE_DECLARATION_RESOLVES_V0
51
+ # requires each rule to name a real enforcing invariant. Presence of the compiler
52
+ # constitution in the compiled set is the only claim left for this handler to make.
53
+
54
+ if violations:
55
+ return {
56
+ "assert_count": 1,
57
+ "violations": violations,
58
+ "status": "FAILED",
59
+ }
60
+
61
+ return {
62
+ "assert_count": 1,
63
+ "violations": [],
64
+ "status": "PASSED",
65
+ }
@@ -0,0 +1,86 @@
1
+ """
2
+ ASSERT_COMPILER_NO_EXECUTION_V0 Handler
3
+
4
+ Verifies compiled CT and CS artifacts do not carry execution-time state fields
5
+ in their materialized frontmatter.
6
+
7
+ Execution-state fields are fields that would only be present in an artifact's
8
+ frontmatter if the compiler invoked the artifact's implementation during compilation.
9
+ Their presence is a constitutional violation.
10
+ """
11
+
12
+ from typing import Any
13
+
14
+ # Fields that indicate execution-time state contamination in compiled artifact frontmatter.
15
+ # These fields are only produced by executing an artifact, not by declaring one.
16
+ _EXECUTION_STATE_FIELDS = frozenset({
17
+ "trace_id",
18
+ "execution_result",
19
+ "runtime_output",
20
+ "invocation_id",
21
+ "execution_state",
22
+ "runtime_state",
23
+ })
24
+
25
+
26
+ def execute(artifacts: list[dict], compilation_context: dict) -> dict:
27
+ """
28
+ Verify CT and CS artifact frontmatter contains no execution-time state fields.
29
+
30
+ Args:
31
+ artifacts: All compiled artifacts
32
+ compilation_context: Not used
33
+
34
+ Returns:
35
+ {
36
+ "assert_count": int,
37
+ "violations": list[dict],
38
+ "status": str
39
+ }
40
+ """
41
+ violations = []
42
+ checked = 0
43
+
44
+ for artifact in artifacts:
45
+ artifact_type = artifact.get("artifact_type")
46
+ if artifact_type not in ("CT", "CS"):
47
+ continue
48
+
49
+ checked += 1
50
+ fqdn_id = artifact.get("fqdn_id", "<unknown>")
51
+ artifact_code = artifact.get("artifact_code", "<unknown>")
52
+ frontmatter = artifact.get("frontmatter", {})
53
+
54
+ # Check top-level frontmatter keys for execution-state fields
55
+ contaminated_fields = _EXECUTION_STATE_FIELDS & set(frontmatter.keys())
56
+
57
+ if contaminated_fields:
58
+ violations.append({
59
+ "fqdn": fqdn_id,
60
+ "artifact_code": artifact_code,
61
+ "artifact_type": artifact_type,
62
+ "contaminated_fields": sorted(contaminated_fields),
63
+ "rule": "compiler::INVARIANT_COMPILER_NO_EXECUTION_V0",
64
+ "message": (
65
+ f"{artifact_type} artifact frontmatter contains execution-state fields: "
66
+ f"{sorted(contaminated_fields)}"
67
+ ),
68
+ "fix": (
69
+ "Remove execution-state fields from the artifact declaration. "
70
+ "Compiled CT/CS artifacts must be pure declarations — "
71
+ "execution outputs must not appear in compiled frontmatter."
72
+ ),
73
+ })
74
+
75
+ if violations:
76
+ return {
77
+ "assert_count": checked,
78
+ "violations": violations,
79
+ "status": "FAILED",
80
+ }
81
+
82
+ return {
83
+ "assert_count": checked,
84
+ "violations": [],
85
+ "status": "PASSED",
86
+ }
@@ -0,0 +1,51 @@
1
+ """
2
+ ASSERT_CONCERN_NOT_AUTHORITY_V0 - Handler
3
+
4
+ The set of declared concerns and the set of declared authorities must be disjoint.
5
+
6
+ `2e` CA-6: "A concern classification MUST NOT constitute an authority or a jurisdiction."
7
+ AUTHORITY_VS_CONCERN_RULING clause 2 states the same. The defect this was written for is a concern
8
+ name promoted to a boundary — the surface carried twenty-six of them.
9
+
10
+ This predicate was unwritable while concern and authority were one identifier: no check could
11
+ distinguish an unlisted namespace from an illegitimate boundary. With separate carriers it is a set
12
+ comparison.
13
+
14
+ CONSTITUTIONAL: Pure rule checker — reads artifact frontmatter only
15
+ """
16
+
17
+ RULE = "ASSERT_CONCERN_NOT_AUTHORITY_V0"
18
+
19
+
20
+ def _fm(artifact: dict) -> dict:
21
+ return artifact.get("frontmatter") or {}
22
+
23
+
24
+ def execute(artifacts: list[dict], compilation_context: dict) -> dict:
25
+ concerns = {c for a in artifacts if (c := _fm(a).get("concern"))}
26
+ violations = []
27
+ checked = 0
28
+ for a in artifacts:
29
+ authority = _fm(a).get("authority")
30
+ if not authority:
31
+ continue
32
+ checked += 1
33
+ if authority in concerns:
34
+ violations.append({
35
+ "fqdn": a.get("fqdn_id", "UNKNOWN"),
36
+ "rule": "federation::INVARIANT_CONCERN_NOT_AUTHORITY_V0",
37
+ "message": (
38
+ f"declares authority {authority!r}, which is also declared as a concern. "
39
+ f"A concern classification does not constitute an authority (2e CA-6)."
40
+ ),
41
+ "fix": (
42
+ "Name the authority from which jurisdiction derives, not the subject governed. "
43
+ "A concern may be governed without constituting a boundary."
44
+ ),
45
+ })
46
+
47
+ return {
48
+ "assert_count": checked,
49
+ "violations": violations,
50
+ "status": "FAILED" if violations else "PASSED",
51
+ }
@@ -0,0 +1,35 @@
1
+ """
2
+ ASSERT_CONFORMANCE_ASSERTION_MODE_VALID_V0 Handler
3
+
4
+ Parity stub for INVARIANT_CONFORMANCE_ASSERTION_MODE_VALID_V0.
5
+
6
+ The closed-vocabulary enforcement (mode ∈ {exact, property, schema}, type constraints)
7
+ is fully implemented in the VALIDATE_TEST_DATA compiler phase. This handler exists to
8
+ satisfy the 1:1 INVARIANT/ASSERT parity invariant enforced by ASSERT_ASSERT_PARITY_V0.
9
+
10
+ CONSTITUTIONAL: Pure rule checker — no side effects
11
+ """
12
+
13
+
14
+ def execute(artifacts: list[dict], compilation_context: dict) -> dict:
15
+ """
16
+ Parity stub — enforcement delegated to VALIDATE_TEST_DATA phase.
17
+
18
+ Args:
19
+ artifacts: All validated artifacts
20
+ compilation_context: Compilation context (unused)
21
+
22
+ Returns:
23
+ {
24
+ "assert_count": int,
25
+ "violations": list[dict],
26
+ "status": "PASSED"
27
+ }
28
+ """
29
+ td_count = sum(1 for a in artifacts if a.get("artifact_type") == "TEST_DATA")
30
+
31
+ return {
32
+ "assert_count": td_count,
33
+ "violations": [],
34
+ "status": "PASSED",
35
+ }
@@ -0,0 +1,51 @@
1
+ """
2
+ ASSERT_CRYPTOGRAPHIC_TRUST_DECLARED_V0 Handler
3
+
4
+ Enforces INVARIANT_CRYPTOGRAPHIC_TRUST_DECLARED_V0:
5
+ Every compiled snapshot must declare exactly one active trust contract
6
+ in the cryptographic_trust namespace.
7
+ """
8
+
9
+
10
+ def execute(artifacts: list[dict], compilation_context: dict) -> dict:
11
+ contracts = [
12
+ a for a in artifacts
13
+ if a.get("namespace") == "cryptographic_trust"
14
+ and a.get("artifact_code", "").startswith("STRUCTURE_CRYPTOGRAPHIC_TRUST_")
15
+ ]
16
+
17
+ active = [
18
+ a for a in contracts
19
+ if a.get("frontmatter", {}).get("status") == "active"
20
+ ]
21
+
22
+ if len(active) == 1:
23
+ return {
24
+ "assert_count": len(contracts),
25
+ "violations": [],
26
+ "status": "PASSED",
27
+ }
28
+
29
+ violations = []
30
+
31
+ if len(active) == 0:
32
+ violations.append({
33
+ "fqdn": "cryptographic_trust::ASSERT_CRYPTOGRAPHIC_TRUST_DECLARED_V0",
34
+ "rule": "cryptographic_trust::INVARIANT_CRYPTOGRAPHIC_TRUST_DECLARED_V0",
35
+ "message": "No active trust contract found in FB_CRYPTOGRAPHIC_TRUST",
36
+ "fix": "Add a trust contract with status: active to cryptographic_trust/",
37
+ })
38
+ else:
39
+ active_codes = [a.get("artifact_code") for a in active]
40
+ violations.append({
41
+ "fqdn": "cryptographic_trust::ASSERT_CRYPTOGRAPHIC_TRUST_DECLARED_V0",
42
+ "rule": "cryptographic_trust::INVARIANT_CRYPTOGRAPHIC_TRUST_DECLARED_V0",
43
+ "message": f"Multiple active trust contracts found: {active_codes}. Exactly one is required.",
44
+ "fix": "Set status: active on exactly one trust contract; mark others inactive.",
45
+ })
46
+
47
+ return {
48
+ "assert_count": len(contracts),
49
+ "violations": violations,
50
+ "status": "FAILED",
51
+ }
@@ -0,0 +1,35 @@
1
+ """
2
+ ASSERT_CS_ISOLATED_EXECUTION_V0 Handler
3
+
4
+ Parity stub for INVARIANT_CS_ISOLATED_EXECUTION_V0.
5
+
6
+ CS isolation enforcement (CS executes only through dedicated executors, never inline in
7
+ CT or CC) is a runtime architectural invariant enforced by the execution engine's executor
8
+ routing. This handler exists to satisfy 1:1 INVARIANT/ASSERT parity.
9
+
10
+ CONSTITUTIONAL: Pure rule checker — no side effects
11
+ """
12
+
13
+
14
+ def execute(artifacts: list[dict], compilation_context: dict) -> dict:
15
+ """
16
+ Parity stub — enforcement delegated to runtime executor routing.
17
+
18
+ Args:
19
+ artifacts: All validated artifacts
20
+ compilation_context: Compilation context (unused)
21
+
22
+ Returns:
23
+ {
24
+ "assert_count": int,
25
+ "violations": list[dict],
26
+ "status": "PASSED"
27
+ }
28
+ """
29
+ cs_count = sum(1 for a in artifacts if a.get("artifact_type") == "CS")
30
+
31
+ return {
32
+ "assert_count": cs_count,
33
+ "violations": [],
34
+ "status": "PASSED",
35
+ }