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.
- compiler/VERSION +1 -0
- compiler/__init__.py +1 -0
- compiler/atoms/__init__.py +54 -0
- compiler/atoms/error_codes.py +160 -0
- compiler/atoms/errors.py +125 -0
- compiler/atoms/fqdn.py +204 -0
- compiler/atoms/invariants.py +106 -0
- compiler/atoms/phase.py +99 -0
- compiler/atoms/pipeline.py +51 -0
- compiler/atoms/snapshot_gate.py +51 -0
- compiler/atoms/sorting.py +125 -0
- compiler/cli.py +637 -0
- compiler/diagnostics/__init__.py +6 -0
- compiler/diagnostics/determination.py +148 -0
- compiler/diagnostics/machine_block_health.py +199 -0
- compiler/governance/__init__.py +6 -0
- compiler/governance_engine/__init__.py +0 -0
- compiler/governance_engine/artifact_kinds.py +221 -0
- compiler/governance_engine/assertions/__init__.py +0 -0
- compiler/governance_engine/assertions/handlers/__init__.py +200 -0
- compiler/governance_engine/assertions/handlers/assert_ac_declaration_well_formed_v0.py +70 -0
- compiler/governance_engine/assertions/handlers/assert_actor_authority_separation_v0.py +17 -0
- compiler/governance_engine/assertions/handlers/assert_artifact_content_hash_declared_v0.py +60 -0
- compiler/governance_engine/assertions/handlers/assert_assert_not_runtime_referenced_v0.py +49 -0
- compiler/governance_engine/assertions/handlers/assert_assert_parity_v0.py +169 -0
- compiler/governance_engine/assertions/handlers/assert_atom_output_purity_v0.py +186 -0
- compiler/governance_engine/assertions/handlers/assert_authority_constituted_v0.py +56 -0
- compiler/governance_engine/assertions/handlers/assert_authority_required_for_execution_v0.py +16 -0
- compiler/governance_engine/assertions/handlers/assert_authority_state_well_formed_v0.py +17 -0
- compiler/governance_engine/assertions/handlers/assert_binding_integrity_v0.py +64 -0
- compiler/governance_engine/assertions/handlers/assert_binding_surface_closed_v0.py +92 -0
- compiler/governance_engine/assertions/handlers/assert_cc_capability_binding_valid_v0.py +85 -0
- compiler/governance_engine/assertions/handlers/assert_cc_inputs_satisfied_v0.py +89 -0
- compiler/governance_engine/assertions/handlers/assert_cc_no_implicit_chaining_v0.py +89 -0
- compiler/governance_engine/assertions/handlers/assert_cc_no_missing_dependencies_v0.py +89 -0
- compiler/governance_engine/assertions/handlers/assert_cc_no_unused_outputs_v0.py +81 -0
- compiler/governance_engine/assertions/handlers/assert_cc_storage_op_conformance_v0.py +74 -0
- compiler/governance_engine/assertions/handlers/assert_compiler_governance_declared_v0.py +65 -0
- compiler/governance_engine/assertions/handlers/assert_compiler_no_execution_v0.py +86 -0
- compiler/governance_engine/assertions/handlers/assert_concern_not_authority_v0.py +51 -0
- compiler/governance_engine/assertions/handlers/assert_conformance_assertion_mode_valid_v0.py +35 -0
- compiler/governance_engine/assertions/handlers/assert_cryptographic_trust_declared_v0.py +51 -0
- compiler/governance_engine/assertions/handlers/assert_cs_isolated_execution_v0.py +35 -0
- compiler/governance_engine/assertions/handlers/assert_cs_surface_closed_v0.py +241 -0
- compiler/governance_engine/assertions/handlers/assert_cs_traceable_v0.py +35 -0
- compiler/governance_engine/assertions/handlers/assert_ct_output_contract_match_v0.py +167 -0
- compiler/governance_engine/assertions/handlers/assert_ct_surface_closed_v0.py +173 -0
- compiler/governance_engine/assertions/handlers/assert_ct_surface_derived_closed_v0.py +108 -0
- compiler/governance_engine/assertions/handlers/assert_ct_test_data_outcome_declared_v0.py +112 -0
- compiler/governance_engine/assertions/handlers/assert_ev_append_only_v0.py +70 -0
- compiler/governance_engine/assertions/handlers/assert_ev_schema_required_v0.py +59 -0
- compiler/governance_engine/assertions/handlers/assert_execution_placement_declared_v0.py +51 -0
- compiler/governance_engine/assertions/handlers/assert_execution_scheduling_declared_v0.py +51 -0
- compiler/governance_engine/assertions/handlers/assert_fqdn_namespace_authorized_v0.py +38 -0
- compiler/governance_engine/assertions/handlers/assert_fqdn_only_references_v0.py +89 -0
- compiler/governance_engine/assertions/handlers/assert_governance_declaration_resolves_v0.py +126 -0
- compiler/governance_engine/assertions/handlers/assert_handler_registry_closed_v0.py +75 -0
- compiler/governance_engine/assertions/handlers/assert_identity_authority_separation_v0.py +19 -0
- compiler/governance_engine/assertions/handlers/assert_identity_fqdn_consistency.py +75 -0
- compiler/governance_engine/assertions/handlers/assert_implementation_admissible_v0.py +66 -0
- compiler/governance_engine/assertions/handlers/assert_in_no_execution_logic_v0.py +82 -0
- compiler/governance_engine/assertions/handlers/assert_in_schema_required_v0.py +74 -0
- compiler/governance_engine/assertions/handlers/assert_in_workflow_binding_v0.py +101 -0
- compiler/governance_engine/assertions/handlers/assert_inspection_capability_read_only_v0.py +114 -0
- compiler/governance_engine/assertions/handlers/assert_no_ambient_authority_v0.py +17 -0
- compiler/governance_engine/assertions/handlers/assert_no_runtime_authorization_v0.py +18 -0
- compiler/governance_engine/assertions/handlers/assert_no_runtime_topology_synthesis_v0.py +18 -0
- compiler/governance_engine/assertions/handlers/assert_no_smart_execution_v0.py +102 -0
- compiler/governance_engine/assertions/handlers/assert_no_undeclared_behavior_surface_v0.py +52 -0
- compiler/governance_engine/assertions/handlers/assert_no_workflow_authorization_logic_v0.py +18 -0
- compiler/governance_engine/assertions/handlers/assert_protocol_surface_closed_v0.py +119 -0
- compiler/governance_engine/assertions/handlers/assert_rb_binding_policy_conformance_v0.py +124 -0
- compiler/governance_engine/assertions/handlers/assert_rb_cs_only_v0.py +68 -0
- compiler/governance_engine/assertions/handlers/assert_rb_no_logic_v0.py +81 -0
- compiler/governance_engine/assertions/handlers/assert_rb_parameters_declared_v0.py +117 -0
- compiler/governance_engine/assertions/handlers/assert_rb_storage_subdomain_owned_v0.py +118 -0
- compiler/governance_engine/assertions/handlers/assert_runtime_invariant_wired_v0.py +163 -0
- compiler/governance_engine/assertions/handlers/assert_schema_conformance_v0.py +64 -0
- compiler/governance_engine/assertions/handlers/assert_schema_description_well_formed_v0.py +97 -0
- compiler/governance_engine/assertions/handlers/assert_security_domain_declared_v0.py +51 -0
- compiler/governance_engine/assertions/handlers/assert_structure_paths_well_formed_v0.py +118 -0
- compiler/governance_engine/assertions/handlers/assert_superseded_not_referenced_v0.py +134 -0
- compiler/governance_engine/assertions/handlers/assert_test_data_match_ct_output_v0.py +134 -0
- compiler/governance_engine/assertions/handlers/assert_topology_acyclic_v0.py +53 -0
- compiler/governance_engine/assertions/handlers/assert_topology_authority_orthogonal_v0.py +110 -0
- compiler/governance_engine/assertions/handlers/assert_topology_capability_reference_unique_v0.py +63 -0
- compiler/governance_engine/assertions/handlers/assert_topology_contract_closed_v0.py +113 -0
- compiler/governance_engine/assertions/handlers/assert_topology_immutable_after_compilation_v0.py +17 -0
- compiler/governance_engine/assertions/handlers/assert_topology_input_reference_declared_v0.py +112 -0
- compiler/governance_engine/assertions/handlers/assert_topology_routing_complete_v0.py +82 -0
- compiler/governance_engine/assertions/handlers/assert_topology_step_declared_v0.py +77 -0
- compiler/governance_engine/assertions/handlers/assert_topology_step_id_unique_v0.py +60 -0
- compiler/governance_engine/assertions/handlers/assert_topology_surface_canonical_v0.py +180 -0
- compiler/governance_engine/assertions/handlers/assert_topology_transport_orthogonal_v0.py +113 -0
- compiler/governance_engine/assertions/handlers/assert_trace_authority_binding_required_v0.py +18 -0
- compiler/governance_engine/assertions/handlers/assert_transport_canonical_normalization_v0.py +83 -0
- compiler/governance_engine/assertions/handlers/assert_transport_no_dynamic_routing_v0.py +93 -0
- compiler/governance_engine/assertions/handlers/assert_transport_no_workflow_semantics_v0.py +106 -0
- compiler/governance_engine/assertions/handlers/assert_transport_operation_identity_independence_v0.py +56 -0
- compiler/governance_engine/assertions/handlers/assert_transport_response_projection_external_v0.py +38 -0
- compiler/governance_engine/assertions/handlers/assert_transport_result_class_protocol_independence_v0.py +48 -0
- compiler/governance_engine/assertions/handlers/assert_transport_target_exists_v0.py +132 -0
- compiler/governance_engine/assertions/handlers/assert_unique_artifact_id_v0.py +58 -0
- compiler/governance_engine/assertions/handlers/assert_vocabulary_symbols_well_formed_v0.py +163 -0
- compiler/governance_engine/assertions/handlers/assert_wf_announcement_distinct_v0.py +85 -0
- compiler/governance_engine/assertions/handlers/assert_wf_cc_only_nodes_v0.py +60 -0
- compiler/governance_engine/assertions/handlers/assert_wf_entry_intent_v0.py +68 -0
- compiler/governance_engine/assertions/handlers/assert_wf_execution_path_valid_v0.py +89 -0
- compiler/governance_engine/assertions/handlers/assert_wf_node_key_binding_unique_v0.py +107 -0
- compiler/governance_engine/platform_root.py +102 -0
- compiler/governance_engine/structure/__init__.py +56 -0
- compiler/governance_engine/structure/discovery/__init__.py +28 -0
- compiler/governance_engine/structure/discovery/artifact_locator.py +210 -0
- compiler/governance_engine/structure/exceptions.py +113 -0
- compiler/governance_engine/structure/loading/__init__.py +88 -0
- compiler/governance_engine/structure/loading/fs_reader.py +225 -0
- compiler/governance_engine/structure/loading/markdown_parser.py +148 -0
- compiler/governance_engine/structure/loading/protocol_loader.py +587 -0
- compiler/governance_engine/structure/loading/test_case_provider.py +125 -0
- compiler/governance_engine/structure/loading/trace_reader.py +98 -0
- compiler/governance_engine/structure/loading/vocabulary_loader.py +174 -0
- compiler/governance_engine/structure/loading/yaml_parser.py +209 -0
- compiler/governance_engine/structure/resolution/__init__.py +22 -0
- compiler/governance_engine/structure/resolution/domain_resolver.py +124 -0
- compiler/governance_engine/structure/resolution/layer_resolver.py +572 -0
- compiler/governance_engine/structure/resolution/path_registry.py +1054 -0
- compiler/graph/__init__.py +38 -0
- compiler/graph/addressing.py +153 -0
- compiler/graph/edge.py +100 -0
- compiler/graph/evidence.py +637 -0
- compiler/graph/graph.py +269 -0
- compiler/graph/hashing.py +89 -0
- compiler/graph/node.py +134 -0
- compiler/graph/query.py +215 -0
- compiler/graph/state.py +237 -0
- compiler/graph/trace.py +97 -0
- compiler/graph/types.py +71 -0
- compiler/projections/__init__.py +207 -0
- compiler/projections/artifact_index.py +225 -0
- compiler/projections/canonical.py +173 -0
- compiler/projections/dispatch.py +532 -0
- compiler/projections/evidence.py +170 -0
- compiler/projections/handlers.py +224 -0
- compiler/projections/ipm.py +388 -0
- compiler/projections/reverse.py +165 -0
- compiler/projections/tokenized.py +135 -0
- compiler/projections/vocabulary.py +108 -0
- compiler/stages/__init__.py +28 -0
- compiler/stages/s1_extract.py +867 -0
- compiler/stages/s2_canonicalize.py +516 -0
- compiler/stages/s3_semantic_addressing.py +66 -0
- compiler/stages/s4_govern.py +754 -0
- compiler/stages/s5_construct.py +537 -0
- compiler/stages/s6_project.py +94 -0
- compiler/stages/s7_materialize.py +1170 -0
- compiler/stages/s8_verify.py +643 -0
- compiler/stages/s9_attest.py +184 -0
- compiler/structure_loader.py +132 -0
- compiler/visualization/__init__.py +12 -0
- compiler/visualization/consumers/__init__.py +28 -0
- compiler/visualization/consumers/evidence_projection.py +162 -0
- compiler/visualization/consumers/evidence_query.py +296 -0
- compiler/visualization/consumers/evidence_reader.py +127 -0
- compiler/visualization/views/__init__.py +70 -0
- compiler/visualization/views/_png_writer.py +45 -0
- compiler/visualization/views/artifact_lineage.py +180 -0
- compiler/visualization/views/family_view.py +164 -0
- compiler/visualization/views/materialization_view.py +150 -0
- compiler/visualization/views/structural_dag.py +158 -0
- compiler/visualization/wf_graph_generator.py +534 -0
- pgc_compiler-2.0.0.dist-info/METADATA +203 -0
- pgc_compiler-2.0.0.dist-info/RECORD +177 -0
- pgc_compiler-2.0.0.dist-info/WHEEL +5 -0
- pgc_compiler-2.0.0.dist-info/entry_points.txt +2 -0
- pgc_compiler-2.0.0.dist-info/licenses/LICENSE +67 -0
- pgc_compiler-2.0.0.dist-info/licenses/NOTICE +11 -0
- pgc_compiler-2.0.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
"""
|
|
2
|
+
ASSERT_ATOM_OUTPUT_PURITY_V0 Handler
|
|
3
|
+
|
|
4
|
+
Validates CT atoms return explicit outputs in all cases, never raise business logic exceptions.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import ast
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
from typing import Any
|
|
10
|
+
|
|
11
|
+
from compiler.governance_engine.structure.resolution.layer_resolver import LayerResolver
|
|
12
|
+
from compiler.governance_engine.structure.resolution.path_registry import bootstrap
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def execute(artifacts: list[dict], compilation_context: dict) -> dict:
|
|
16
|
+
"""
|
|
17
|
+
Verify CT atoms are pure functions returning explicit outputs.
|
|
18
|
+
|
|
19
|
+
Args:
|
|
20
|
+
artifacts: All validated artifacts
|
|
21
|
+
compilation_context: Not used
|
|
22
|
+
|
|
23
|
+
Returns:
|
|
24
|
+
{
|
|
25
|
+
"assert_count": int,
|
|
26
|
+
"violations": list[dict]
|
|
27
|
+
}
|
|
28
|
+
"""
|
|
29
|
+
violations = []
|
|
30
|
+
|
|
31
|
+
# Filter to CT artifacts only
|
|
32
|
+
ct_artifacts = [
|
|
33
|
+
a for a in artifacts
|
|
34
|
+
if a.get("frontmatter", {}).get("artifact_kind") == "CAPABILITY_TRANSFORM"
|
|
35
|
+
]
|
|
36
|
+
|
|
37
|
+
for ct_artifact in ct_artifacts:
|
|
38
|
+
fqdn = ct_artifact["fqdn_id"]
|
|
39
|
+
artifact_code = ct_artifact.get("artifact_code")
|
|
40
|
+
|
|
41
|
+
# Find implementation file
|
|
42
|
+
impl_path = _find_ct_implementation(artifact_code)
|
|
43
|
+
|
|
44
|
+
if not impl_path or not impl_path.exists():
|
|
45
|
+
# Skip if implementation not found (handled by other assertion)
|
|
46
|
+
continue
|
|
47
|
+
|
|
48
|
+
# Parse implementation
|
|
49
|
+
try:
|
|
50
|
+
source = impl_path.read_text(encoding="utf-8")
|
|
51
|
+
tree = ast.parse(source)
|
|
52
|
+
|
|
53
|
+
# Find execute() function
|
|
54
|
+
for node in ast.walk(tree):
|
|
55
|
+
if isinstance(node, ast.FunctionDef) and node.name == "execute":
|
|
56
|
+
# Check for business logic exceptions
|
|
57
|
+
purity_violations = _check_purity_violations(node, source)
|
|
58
|
+
|
|
59
|
+
if purity_violations:
|
|
60
|
+
for violation_msg, line_num in purity_violations:
|
|
61
|
+
violations.append({
|
|
62
|
+
"fqdn": fqdn,
|
|
63
|
+
"rule": "capability_transforms::INVARIANT_ATOM_OUTPUT_PURITY_V0",
|
|
64
|
+
"message": f"{impl_path.name}:{line_num} - {violation_msg}",
|
|
65
|
+
"fix": "Return error status in output dict instead of raising business logic exception"
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
except Exception as e:
|
|
69
|
+
violations.append({
|
|
70
|
+
"fqdn": fqdn,
|
|
71
|
+
"rule": "capability_transforms::INVARIANT_ATOM_OUTPUT_PURITY_V0",
|
|
72
|
+
"message": f"Failed to parse implementation file {impl_path.name}: {str(e)}",
|
|
73
|
+
"fix": "Fix Python syntax errors in CT implementation file"
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
if violations:
|
|
77
|
+
return {
|
|
78
|
+
"assert_count": len(ct_artifacts),
|
|
79
|
+
"violations": violations,
|
|
80
|
+
"status": "FAILED"
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return {
|
|
84
|
+
"assert_count": len(ct_artifacts),
|
|
85
|
+
"violations": [],
|
|
86
|
+
"status": "PASSED"
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def _find_ct_implementation(artifact_code: str) -> Path | None:
|
|
91
|
+
"""Find CT implementation file (flat PGC layout: capability_transforms/implementation/ct_x.py)."""
|
|
92
|
+
from compiler.governance_engine.platform_root import ct_implementation_root
|
|
93
|
+
impl_path = ct_implementation_root() / f"{artifact_code.lower()}.py"
|
|
94
|
+
return impl_path if impl_path.exists() else None
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def _check_purity_violations(func_node: ast.FunctionDef, source: str) -> list[tuple[str, int]]:
|
|
98
|
+
"""
|
|
99
|
+
Check for purity violations in execute() function.
|
|
100
|
+
|
|
101
|
+
Returns list of (violation_message, line_number) tuples.
|
|
102
|
+
"""
|
|
103
|
+
violations = []
|
|
104
|
+
source_lines = source.split("\n")
|
|
105
|
+
|
|
106
|
+
# Find input validation block (first few lines, before business logic starts)
|
|
107
|
+
# We allow exceptions in input validation only
|
|
108
|
+
input_validation_end_line = _find_input_validation_end(func_node, source_lines)
|
|
109
|
+
|
|
110
|
+
for node in ast.walk(func_node):
|
|
111
|
+
if isinstance(node, ast.Raise):
|
|
112
|
+
# Check if raise is after input validation block
|
|
113
|
+
if node.lineno > input_validation_end_line:
|
|
114
|
+
line_content = source_lines[node.lineno - 1].strip() if node.lineno <= len(source_lines) else ""
|
|
115
|
+
|
|
116
|
+
# Check if it's a business logic exception (not input validation)
|
|
117
|
+
if _is_business_logic_exception(line_content):
|
|
118
|
+
violations.append((
|
|
119
|
+
f"Business logic exception detected: {line_content}",
|
|
120
|
+
node.lineno
|
|
121
|
+
))
|
|
122
|
+
|
|
123
|
+
return violations
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def _find_input_validation_end(func_node: ast.FunctionDef, source_lines: list[str]) -> int:
|
|
127
|
+
"""
|
|
128
|
+
Find line number where input validation ends.
|
|
129
|
+
|
|
130
|
+
Heuristic: Input validation is typically the first ~20 lines of execute().
|
|
131
|
+
Look for patterns like:
|
|
132
|
+
- if "field" not in inputs: raise ValueError
|
|
133
|
+
- if not isinstance(...): raise TypeError
|
|
134
|
+
|
|
135
|
+
Returns line number after which business logic starts.
|
|
136
|
+
"""
|
|
137
|
+
# Default: first 20 lines of function are input validation
|
|
138
|
+
func_start = func_node.lineno
|
|
139
|
+
return func_start + 20
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
def _is_business_logic_exception(line: str) -> bool:
|
|
143
|
+
"""
|
|
144
|
+
Check if exception is for business logic vs input validation.
|
|
145
|
+
|
|
146
|
+
Business logic exceptions contain domain terms like:
|
|
147
|
+
- "Quota exhausted"
|
|
148
|
+
- "Training not completed"
|
|
149
|
+
- "Insufficient balance"
|
|
150
|
+
|
|
151
|
+
Input validation exceptions contain:
|
|
152
|
+
- "missing required input"
|
|
153
|
+
- "must be int/str/bool"
|
|
154
|
+
- "invalid type"
|
|
155
|
+
"""
|
|
156
|
+
business_logic_patterns = [
|
|
157
|
+
"quota",
|
|
158
|
+
"training",
|
|
159
|
+
"balance",
|
|
160
|
+
"exhausted",
|
|
161
|
+
"completed",
|
|
162
|
+
"available",
|
|
163
|
+
"eligible",
|
|
164
|
+
]
|
|
165
|
+
|
|
166
|
+
input_validation_patterns = [
|
|
167
|
+
"missing",
|
|
168
|
+
"required",
|
|
169
|
+
"must be",
|
|
170
|
+
"invalid type",
|
|
171
|
+
"type mismatch",
|
|
172
|
+
]
|
|
173
|
+
|
|
174
|
+
line_lower = line.lower()
|
|
175
|
+
|
|
176
|
+
# If contains input validation patterns, it's OK
|
|
177
|
+
if any(pattern in line_lower for pattern in input_validation_patterns):
|
|
178
|
+
return False
|
|
179
|
+
|
|
180
|
+
# If contains business logic patterns, it's a violation
|
|
181
|
+
if any(pattern in line_lower for pattern in business_logic_patterns):
|
|
182
|
+
return True
|
|
183
|
+
|
|
184
|
+
# Default: assume it's a violation if we can't categorize
|
|
185
|
+
# (Conservative approach - fail safe)
|
|
186
|
+
return False
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"""
|
|
2
|
+
ASSERT_AUTHORITY_CONSTITUTED_V0 - Handler
|
|
3
|
+
|
|
4
|
+
Every authority an artifact declares must be constituted by a declared constituting act.
|
|
5
|
+
|
|
6
|
+
`2e` CA-2: an authority "MUST NOT be constituted by need, precedence, containment, naming, or
|
|
7
|
+
classification." An authority that exists because artifacts name it is constituted by need.
|
|
8
|
+
|
|
9
|
+
Not an allowlist. The condition is enforced, never a permitted set — CA-3 and the ruling's clause 5
|
|
10
|
+
both refuse a whitelist.
|
|
11
|
+
|
|
12
|
+
CONSTITUTIONAL: Pure rule checker — reads artifact frontmatter only
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
RULE = "ASSERT_AUTHORITY_CONSTITUTED_V0"
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def _fm(artifact: dict) -> dict:
|
|
19
|
+
return artifact.get("frontmatter") or {}
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def execute(artifacts: list[dict], compilation_context: dict) -> dict:
|
|
23
|
+
constituted: set[str] = set()
|
|
24
|
+
for a in artifacts:
|
|
25
|
+
declared = _fm(a).get("constitutes_authority")
|
|
26
|
+
if isinstance(declared, str):
|
|
27
|
+
constituted.add(declared)
|
|
28
|
+
elif isinstance(declared, list):
|
|
29
|
+
constituted.update(x for x in declared if isinstance(x, str))
|
|
30
|
+
|
|
31
|
+
violations = []
|
|
32
|
+
checked = 0
|
|
33
|
+
for a in artifacts:
|
|
34
|
+
authority = _fm(a).get("authority")
|
|
35
|
+
if not authority:
|
|
36
|
+
continue
|
|
37
|
+
checked += 1
|
|
38
|
+
if authority not in constituted:
|
|
39
|
+
violations.append({
|
|
40
|
+
"fqdn": a.get("fqdn_id", "UNKNOWN"),
|
|
41
|
+
"rule": "federation::INVARIANT_AUTHORITY_CONSTITUTED_V0",
|
|
42
|
+
"message": (
|
|
43
|
+
f"declares authority {authority!r}, which no constituting act declares. "
|
|
44
|
+
f"An authority constituted by being named is constituted by need (2e CA-2)."
|
|
45
|
+
),
|
|
46
|
+
"fix": (
|
|
47
|
+
f"Declare `constitutes_authority: {authority}` on the CONSTITUTION that "
|
|
48
|
+
f"constitutes it, or declare an authority that exists."
|
|
49
|
+
),
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
return {
|
|
53
|
+
"assert_count": checked,
|
|
54
|
+
"violations": violations,
|
|
55
|
+
"status": "FAILED" if violations else "PASSED",
|
|
56
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"""
|
|
2
|
+
ASSERT_AUTHORITY_REQUIRED_FOR_EXECUTION_V0
|
|
3
|
+
|
|
4
|
+
Phase 1 stub — governance-layer artifact only.
|
|
5
|
+
Full enforcement (every WF_ must declare an authority requirement) is implemented in Phase 4.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def execute(artifacts: list[dict], compilation_context: dict) -> dict:
|
|
10
|
+
# Phase 1: stub — authority governance artifacts are governance-layer only.
|
|
11
|
+
# Full admissibility boundary enforcement implemented in Phase 4.
|
|
12
|
+
return {
|
|
13
|
+
"assert_count": 0,
|
|
14
|
+
"violations": [],
|
|
15
|
+
"status": "PASSED",
|
|
16
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"""
|
|
2
|
+
ASSERT_AUTHORITY_STATE_WELL_FORMED_V0
|
|
3
|
+
|
|
4
|
+
Phase 1 stub — governance-layer artifact only.
|
|
5
|
+
Full enforcement (authority state envelope schema validation against
|
|
6
|
+
SCHEMA_AUTHENTICATED_AUTHORITY_STATE_V0) is implemented in Phase 2.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def execute(artifacts: list[dict], compilation_context: dict) -> dict:
|
|
11
|
+
# Phase 1: stub — authority governance artifacts are governance-layer only.
|
|
12
|
+
# Schema validation against SCHEMA_AUTHENTICATED_AUTHORITY_STATE_V0 implemented in Phase 2.
|
|
13
|
+
return {
|
|
14
|
+
"assert_count": 0,
|
|
15
|
+
"violations": [],
|
|
16
|
+
"status": "PASSED",
|
|
17
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"""
|
|
2
|
+
ASSERT_BINDING_INTEGRITY_V0 Handler
|
|
3
|
+
|
|
4
|
+
Validates RB binding integrity:
|
|
5
|
+
1. All binding keys must be FQDNs (contain '::')
|
|
6
|
+
2. All binding keys must reference artifacts that exist in the compiled graph
|
|
7
|
+
|
|
8
|
+
CONSTITUTIONAL: Binding surfaces must be structurally sound at compile time.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def execute(artifacts: list[dict], compilation_context: dict) -> dict:
|
|
13
|
+
"""
|
|
14
|
+
Validate RB binding integrity via pre-computed analysis.
|
|
15
|
+
|
|
16
|
+
Args:
|
|
17
|
+
artifacts: All validated artifacts
|
|
18
|
+
compilation_context: Contains pre-computed rb_binding_integrity
|
|
19
|
+
|
|
20
|
+
Returns:
|
|
21
|
+
Standardized result dict with assert_count, violations, status
|
|
22
|
+
"""
|
|
23
|
+
violations = []
|
|
24
|
+
rb_count = 0
|
|
25
|
+
|
|
26
|
+
rb_integrity = compilation_context.get("rb_binding_integrity")
|
|
27
|
+
|
|
28
|
+
if rb_integrity is None:
|
|
29
|
+
return {
|
|
30
|
+
"assert_count": 0,
|
|
31
|
+
"violations": [{
|
|
32
|
+
"fqdn": "runtime_binding::ASSERT_BINDING_INTEGRITY_V0",
|
|
33
|
+
"rule": "COMPILATION_CONTEXT_COMPLETE",
|
|
34
|
+
"message": "Compilation context missing rb_binding_integrity",
|
|
35
|
+
"fix": "Compiler must pre-compute RB binding analysis before assert phase"
|
|
36
|
+
}],
|
|
37
|
+
"status": "FAILED"
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
for artifact in artifacts:
|
|
41
|
+
if artifact.get("artifact_type") != "RB":
|
|
42
|
+
continue
|
|
43
|
+
|
|
44
|
+
rb_count += 1
|
|
45
|
+
fqdn = artifact["fqdn_id"]
|
|
46
|
+
result = rb_integrity.get(fqdn)
|
|
47
|
+
|
|
48
|
+
if not result:
|
|
49
|
+
continue
|
|
50
|
+
|
|
51
|
+
if result.get("status") == "FAILED":
|
|
52
|
+
for structural_violation in result.get("violations", []):
|
|
53
|
+
violations.append({
|
|
54
|
+
"fqdn": fqdn,
|
|
55
|
+
"rule": "runtime_binding::INVARIANT_BINDING_INTEGRITY_V0",
|
|
56
|
+
"message": structural_violation.get("violation", "Unknown RB binding violation"),
|
|
57
|
+
"fix": structural_violation.get("fix", "Fix RB binding reference")
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
return {
|
|
61
|
+
"assert_count": rb_count,
|
|
62
|
+
"violations": violations,
|
|
63
|
+
"status": "FAILED" if violations else "PASSED"
|
|
64
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"""
|
|
2
|
+
ASSERT_BINDING_SURFACE_CLOSED_V0 - Handler
|
|
3
|
+
|
|
4
|
+
Enforces INVARIANT_BINDING_SURFACE_CLOSED_V0 at compile time.
|
|
5
|
+
|
|
6
|
+
Validates WF-level binding surface for all WF artifacts:
|
|
7
|
+
- All $.payload.<field> bindings reference declared IN payload schema fields
|
|
8
|
+
- All $.results.<NODE>.<field> bindings reference an existing WF CC node
|
|
9
|
+
with that field declared in the CC's core.outputs
|
|
10
|
+
- No unrecognized binding grammar (any other $ prefix)
|
|
11
|
+
|
|
12
|
+
CONSTITUTIONAL: Pure rule checker — reads pre-computed wf_binding_surface from context.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def execute(artifacts: list[dict], compilation_context: dict) -> dict:
|
|
17
|
+
"""
|
|
18
|
+
Assert WF binding surface is closed against pre-computed structural analysis.
|
|
19
|
+
|
|
20
|
+
Args:
|
|
21
|
+
artifacts: All validated artifacts
|
|
22
|
+
compilation_context: Contains pre-computed wf_binding_surface
|
|
23
|
+
|
|
24
|
+
Returns:
|
|
25
|
+
{
|
|
26
|
+
"assert_count": int,
|
|
27
|
+
"violations": list[dict],
|
|
28
|
+
"status": "PASSED/FAILED"
|
|
29
|
+
}
|
|
30
|
+
"""
|
|
31
|
+
wf_binding_surface = compilation_context.get("wf_binding_surface")
|
|
32
|
+
|
|
33
|
+
if wf_binding_surface is None:
|
|
34
|
+
return {
|
|
35
|
+
"assert_count": 0,
|
|
36
|
+
"violations": [{
|
|
37
|
+
"fqdn": "runtime_binding::ASSERT_BINDING_SURFACE_CLOSED_V0",
|
|
38
|
+
"rule": "COMPILATION_CONTEXT_COMPLETE",
|
|
39
|
+
"message": "Compilation context missing wf_binding_surface",
|
|
40
|
+
"fix": (
|
|
41
|
+
"Compiler must pre-compute WF binding surface analysis "
|
|
42
|
+
"before assert phase"
|
|
43
|
+
)
|
|
44
|
+
}],
|
|
45
|
+
"status": "FAILED"
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
violations = []
|
|
49
|
+
wf_count = 0
|
|
50
|
+
|
|
51
|
+
for artifact in artifacts:
|
|
52
|
+
if artifact.get("artifact_type") != "WF":
|
|
53
|
+
continue
|
|
54
|
+
|
|
55
|
+
wf_count += 1
|
|
56
|
+
fqdn = artifact["fqdn_id"]
|
|
57
|
+
surface_result = wf_binding_surface.get(fqdn)
|
|
58
|
+
|
|
59
|
+
if not surface_result:
|
|
60
|
+
violations.append({
|
|
61
|
+
"fqdn": fqdn,
|
|
62
|
+
"rule": "runtime_binding::INVARIANT_BINDING_SURFACE_CLOSED_V0",
|
|
63
|
+
"message": "Missing binding surface analysis for WF artifact",
|
|
64
|
+
"fix": "Compiler must analyze all WF artifacts for binding surface"
|
|
65
|
+
})
|
|
66
|
+
continue
|
|
67
|
+
|
|
68
|
+
if surface_result.get("status") == "VIOLATION":
|
|
69
|
+
for structural_violation in surface_result.get("violations", []):
|
|
70
|
+
violations.append({
|
|
71
|
+
"fqdn": fqdn,
|
|
72
|
+
"rule": "runtime_binding::INVARIANT_BINDING_SURFACE_CLOSED_V0",
|
|
73
|
+
"message": structural_violation.get(
|
|
74
|
+
"violation", "Unknown binding surface violation"
|
|
75
|
+
),
|
|
76
|
+
"fix": structural_violation.get(
|
|
77
|
+
"fix", "Correct the binding reference"
|
|
78
|
+
)
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
if violations:
|
|
82
|
+
return {
|
|
83
|
+
"assert_count": wf_count,
|
|
84
|
+
"violations": violations,
|
|
85
|
+
"status": "FAILED"
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return {
|
|
89
|
+
"assert_count": wf_count,
|
|
90
|
+
"violations": [],
|
|
91
|
+
"status": "PASSED"
|
|
92
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"""
|
|
2
|
+
ASSERT_CC_CAPABILITY_BINDING_VALID_V0 Handler
|
|
3
|
+
|
|
4
|
+
Validates CC pipeline step capability bindings:
|
|
5
|
+
- Each step must bind exactly ONE capability (CT or CS, not both, not zero)
|
|
6
|
+
- Referenced capabilities must exist in compilation graph
|
|
7
|
+
|
|
8
|
+
CONSTITUTIONAL: Pure rule checker - reads pre-computed structure from context
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def execute(artifacts: list[dict], compilation_context: dict) -> dict:
|
|
13
|
+
"""
|
|
14
|
+
Validate all CC capability bindings against pre-computed structural analysis.
|
|
15
|
+
|
|
16
|
+
Args:
|
|
17
|
+
artifacts: All validated artifacts
|
|
18
|
+
compilation_context: Contains pre-computed cc_bindings
|
|
19
|
+
|
|
20
|
+
Returns:
|
|
21
|
+
{
|
|
22
|
+
"assert_count": int,
|
|
23
|
+
"violations": list[dict], # Standardized schema
|
|
24
|
+
"status": "PASSED/FAILED"
|
|
25
|
+
}
|
|
26
|
+
"""
|
|
27
|
+
violations = []
|
|
28
|
+
cc_count = 0
|
|
29
|
+
|
|
30
|
+
# STRICT INVERSION OF CONTROL: Compiler must provide complete context
|
|
31
|
+
cc_bindings = compilation_context.get("cc_bindings")
|
|
32
|
+
|
|
33
|
+
if cc_bindings is None:
|
|
34
|
+
return {
|
|
35
|
+
"assert_count": 0,
|
|
36
|
+
"violations": [{
|
|
37
|
+
"fqdn": "capability_contracts::ASSERT_CC_CAPABILITY_BINDING_VALID_V0",
|
|
38
|
+
"rule": "COMPILATION_CONTEXT_COMPLETE",
|
|
39
|
+
"message": "Compilation context missing cc_bindings",
|
|
40
|
+
"fix": "Compiler must pre-compute CC binding analysis before assert phase"
|
|
41
|
+
}],
|
|
42
|
+
"status": "FAILED"
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
# Check rules against pre-computed structure
|
|
46
|
+
for artifact in artifacts:
|
|
47
|
+
if artifact.get("artifact_type") != "CC":
|
|
48
|
+
continue
|
|
49
|
+
|
|
50
|
+
cc_count += 1
|
|
51
|
+
fqdn = artifact["fqdn_id"]
|
|
52
|
+
binding_result = cc_bindings.get(fqdn)
|
|
53
|
+
|
|
54
|
+
if not binding_result:
|
|
55
|
+
violations.append({
|
|
56
|
+
"fqdn": fqdn,
|
|
57
|
+
"rule": "capability_contracts::INVARIANT_CC_CAPABILITY_BINDING_VALID_V0",
|
|
58
|
+
"message": "Missing capability binding analysis for CC artifact",
|
|
59
|
+
"fix": "Compiler must analyze all CC artifacts"
|
|
60
|
+
})
|
|
61
|
+
continue
|
|
62
|
+
|
|
63
|
+
# Translate structural violations to standardized rule violations
|
|
64
|
+
if binding_result.get("status") == "FAILED":
|
|
65
|
+
for structural_violation in binding_result.get("violations", []):
|
|
66
|
+
violations.append({
|
|
67
|
+
"fqdn": fqdn,
|
|
68
|
+
"rule": "capability_contracts::INVARIANT_CC_CAPABILITY_BINDING_VALID_V0",
|
|
69
|
+
"message": structural_violation.get("violation", "Unknown CC binding violation"),
|
|
70
|
+
"fix": structural_violation.get("fix", "Fix CC capability binding")
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
# Return standardized result
|
|
74
|
+
if violations:
|
|
75
|
+
return {
|
|
76
|
+
"assert_count": cc_count,
|
|
77
|
+
"violations": violations,
|
|
78
|
+
"status": "FAILED"
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return {
|
|
82
|
+
"assert_count": cc_count,
|
|
83
|
+
"violations": [],
|
|
84
|
+
"status": "PASSED"
|
|
85
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"""
|
|
2
|
+
ASSERT_CC_INPUTS_SATISFIED_V0 - Handler
|
|
3
|
+
|
|
4
|
+
Enforces INVARIANT_CC_INPUTS_SATISFIED_V0 at compile time.
|
|
5
|
+
|
|
6
|
+
Validates JSONPath reference availability for all WF artifacts:
|
|
7
|
+
- All $.payload.* references exist in IN payload schema
|
|
8
|
+
- All $.results.step_name.* references point to earlier steps with valid outputs
|
|
9
|
+
|
|
10
|
+
Validation Scope: AVAILABILITY ONLY (not type safety, not schema conformance)
|
|
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 inputs satisfaction against pre-computed structural analysis.
|
|
19
|
+
|
|
20
|
+
Args:
|
|
21
|
+
artifacts: All validated artifacts
|
|
22
|
+
compilation_context: Contains pre-computed cc_inputs_satisfied
|
|
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_inputs_satisfied = compilation_context.get("cc_inputs_satisfied")
|
|
36
|
+
|
|
37
|
+
if cc_inputs_satisfied is None:
|
|
38
|
+
return {
|
|
39
|
+
"assert_count": 0,
|
|
40
|
+
"violations": [{
|
|
41
|
+
"fqdn": "capability_contracts::ASSERT_CC_INPUTS_SATISFIED_V0",
|
|
42
|
+
"rule": "COMPILATION_CONTEXT_COMPLETE",
|
|
43
|
+
"message": "Compilation context missing cc_inputs_satisfied",
|
|
44
|
+
"fix": "Compiler must pre-compute CC inputs satisfaction analysis before assert phase"
|
|
45
|
+
}],
|
|
46
|
+
"status": "FAILED"
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
# Validation is per-WF: the validator resolves CC input references within WF context
|
|
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
|
+
inputs_result = cc_inputs_satisfied.get(fqdn)
|
|
57
|
+
|
|
58
|
+
if not inputs_result:
|
|
59
|
+
violations.append({
|
|
60
|
+
"fqdn": fqdn,
|
|
61
|
+
"rule": "capability_contracts::INVARIANT_CC_INPUTS_SATISFIED_V0",
|
|
62
|
+
"message": "Missing inputs satisfaction 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 inputs_result.get("status") in ("FAILED", "VIOLATION"):
|
|
69
|
+
for structural_violation in inputs_result.get("violations", []):
|
|
70
|
+
violations.append({
|
|
71
|
+
"fqdn": fqdn,
|
|
72
|
+
"rule": "capability_contracts::INVARIANT_CC_INPUTS_SATISFIED_V0",
|
|
73
|
+
"message": structural_violation.get("violation", "Unknown CC inputs violation"),
|
|
74
|
+
"fix": structural_violation.get("fix", "Ensure all CC inputs 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
|
+
}
|