core-runtime-engine 11.5.1__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.
- core_runtime/__init__.py +10 -0
- core_runtime/__version__.py +17 -0
- core_runtime/cli/__init__.py +7 -0
- core_runtime/cli/__main__.py +22 -0
- core_runtime/cli/bump_version.py +176 -0
- core_runtime/cli/contract_preflight.py +69 -0
- core_runtime/cli/create_domain.py +66 -0
- core_runtime/cli/doctor.py +44 -0
- core_runtime/cli/inventory.py +85 -0
- core_runtime/cli/lint.py +8 -0
- core_runtime/cli/main.py +579 -0
- core_runtime/cli/release_check.py +65 -0
- core_runtime/cli/repair_artifact_paths.py +48 -0
- core_runtime/cli/sync_template.py +67 -0
- core_runtime/cli/validate.py +73 -0
- core_runtime/core/__init__.py +34 -0
- core_runtime/core/audit_event.py +760 -0
- core_runtime/core/audit_trail_index.py +100 -0
- core_runtime/core/canonicalization.py +55 -0
- core_runtime/core/contract_evaluator.py +945 -0
- core_runtime/core/contract_executability.py +307 -0
- core_runtime/core/contract_loader.py +57 -0
- core_runtime/core/contract_probes.py +630 -0
- core_runtime/core/contract_program.py +131 -0
- core_runtime/core/contract_program_registry.py +104 -0
- core_runtime/core/contract_program_v2.py +126 -0
- core_runtime/core/dsk_v3.py +142 -0
- core_runtime/core/explainability.py +2115 -0
- core_runtime/core/numeric_normalization.py +120 -0
- core_runtime/core/rule_anchor.py +1388 -0
- core_runtime/core/schema_fingerprint.py +69 -0
- core_runtime/core/sensor_evidence.py +548 -0
- core_runtime/data/contracts/CoreAnchor.sol +109 -0
- core_runtime/data/contracts/CoreRuleAnchor.abi.json +111 -0
- core_runtime/data/contracts/CoreRuleAnchor.bin +1 -0
- core_runtime/data/contracts/CoreRuleAnchor.build.json +20 -0
- core_runtime/data/contracts/CoreRuleAnchor.runtime.bin +1 -0
- core_runtime/data/contracts/CoreRuleAnchor.sol +74 -0
- core_runtime/data/package_data_manifest.v1.json +173 -0
- core_runtime/data/schemas/core/causal_trace.v1.json +141 -0
- core_runtime/data/schemas/core/context_gate.v1.json +38 -0
- core_runtime/data/schemas/core/context_threshold.v1.json +46 -0
- core_runtime/data/schemas/core/contract_program.v1.json +186 -0
- core_runtime/data/schemas/core/contract_program.v2.json +187 -0
- core_runtime/data/schemas/core/control_decision.v1.json +114 -0
- core_runtime/data/schemas/core/dsk.v3.json +105 -0
- core_runtime/data/schemas/core/effect_result.v1.json +39 -0
- core_runtime/data/schemas/core/entropy_signal.v1.json +108 -0
- core_runtime/data/schemas/core/execution_receipt.v1.json +93 -0
- core_runtime/data/schemas/core/frozen_release_manifest.v1.json +87 -0
- core_runtime/data/schemas/core/frozen_release_manifest.v2.json +72 -0
- core_runtime/data/schemas/core/frozen_release_manifest.v3.json +38 -0
- core_runtime/data/schemas/core/frozen_release_manifest.v4.json +72 -0
- core_runtime/data/schemas/core/frozen_release_manifest.v5.json +38 -0
- core_runtime/data/schemas/core/frozen_release_manifest.v6.json +116 -0
- core_runtime/data/schemas/core/frozen_release_manifest.v7.json +37 -0
- core_runtime/data/schemas/core/frozen_release_manifest.v8.json +114 -0
- core_runtime/data/schemas/core/frozen_rule_set.v1.json +282 -0
- core_runtime/data/schemas/core/memory_artifact.v1.json +120 -0
- core_runtime/data/schemas/core/memory_generation_result.v1.json +37 -0
- core_runtime/data/schemas/core/operational_learning_event.v1.json +63 -0
- core_runtime/data/schemas/core/pattern_candidate.v1.json +114 -0
- core_runtime/data/schemas/core/physical_safety_assurance_case.v1.json +676 -0
- core_runtime/data/schemas/core/policy_lifecycle.v1.json +99 -0
- core_runtime/data/schemas/core/retention_manifest.v1.json +53 -0
- core_runtime/data/schemas/core/reversibility_policy.v1.json +107 -0
- core_runtime/data/schemas/core/rule_anchor_batch.v1.json +93 -0
- core_runtime/data/schemas/core/rule_anchor_chain_evidence.v1.json +56 -0
- core_runtime/data/schemas/core/rule_approval.v1.json +49 -0
- core_runtime/data/schemas/core/rule_approval_request.v1.json +42 -0
- core_runtime/data/schemas/core/state_transition.v1.json +115 -0
- core_runtime/data/schemas/core/task_closeout.v1.json +47 -0
- core_runtime/data/schemas/core/template_promotion_candidate.v1.json +83 -0
- core_runtime/data/schemas/core/unsigned_rule_anchor_deployment.v1.json +106 -0
- core_runtime/data/schemas/core/unsigned_rule_anchor_transaction.v1.json +116 -0
- core_runtime/tooling/__init__.py +48 -0
- core_runtime/tooling/bump_version.py +900 -0
- core_runtime/tooling/contract_preflight.py +293 -0
- core_runtime/tooling/create_domain.py +254 -0
- core_runtime/tooling/diagnostics.py +129 -0
- core_runtime/tooling/doctor.py +482 -0
- core_runtime/tooling/file_inventory.py +182 -0
- core_runtime/tooling/json_checks.py +100 -0
- core_runtime/tooling/release_check.py +1017 -0
- core_runtime/tooling/repair_artifact_paths.py +458 -0
- core_runtime/tooling/report_writer.py +176 -0
- core_runtime/tooling/repository_inventory.py +399 -0
- core_runtime/tooling/safety_checks.py +172 -0
- core_runtime/tooling/sync_template.py +303 -0
- core_runtime/tooling/validation.py +507 -0
- core_runtime/tooling/version_inventory.py +256 -0
- core_runtime_engine-11.5.1.dist-info/METADATA +35 -0
- core_runtime_engine-11.5.1.dist-info/RECORD +96 -0
- core_runtime_engine-11.5.1.dist-info/WHEEL +5 -0
- core_runtime_engine-11.5.1.dist-info/entry_points.txt +2 -0
- core_runtime_engine-11.5.1.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
"""Repository audit proving that public contracts have executable semantics."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import copy
|
|
6
|
+
import importlib
|
|
7
|
+
import json
|
|
8
|
+
from importlib.resources import files
|
|
9
|
+
from typing import Any
|
|
10
|
+
|
|
11
|
+
from core_runtime.core.canonicalization import canonical_json_hash
|
|
12
|
+
from core_runtime.core.contract_evaluator import (
|
|
13
|
+
SEMANTIC_RULE_IDS,
|
|
14
|
+
evaluate_contract_payload,
|
|
15
|
+
executable_contract_versions,
|
|
16
|
+
validate_contract_structure,
|
|
17
|
+
)
|
|
18
|
+
from core_runtime.core.contract_loader import SCHEMA_ROOT, available_contracts, load_contract_schema
|
|
19
|
+
from core_runtime.core.contract_probes import executable_contract_probes
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
STANDALONE_EXECUTABLE_CONTRACTS: dict[str, tuple[str, str]] = {
|
|
24
|
+
"core.frozen_release_manifest.v1": (
|
|
25
|
+
"scripts.validate_frozen_release_manifest",
|
|
26
|
+
"validate_frozen_release_manifest",
|
|
27
|
+
),
|
|
28
|
+
"core.frozen_release_manifest.v2": (
|
|
29
|
+
"scripts.validate_frozen_release_manifest_v11_2",
|
|
30
|
+
"validate_v11_2_release_manifest",
|
|
31
|
+
),
|
|
32
|
+
"core.frozen_release_manifest.v3": (
|
|
33
|
+
"scripts.validate_frozen_release_manifest_v11_2_frozen",
|
|
34
|
+
"validate_v11_2_frozen_release_manifest",
|
|
35
|
+
),
|
|
36
|
+
"core.frozen_release_manifest.v4": (
|
|
37
|
+
"scripts.validate_frozen_release_manifest_v11_3",
|
|
38
|
+
"validate_v11_3_release_manifest",
|
|
39
|
+
),
|
|
40
|
+
"core.frozen_release_manifest.v5": (
|
|
41
|
+
"scripts.validate_frozen_release_manifest_v11_3_frozen",
|
|
42
|
+
"validate_v11_3_frozen_release_manifest",
|
|
43
|
+
),
|
|
44
|
+
"core.frozen_release_manifest.v6": (
|
|
45
|
+
"scripts.validate_frozen_release_manifest_v11_4",
|
|
46
|
+
"validate_v11_4_release_manifest",
|
|
47
|
+
),
|
|
48
|
+
"core.frozen_release_manifest.v7": (
|
|
49
|
+
"scripts.validate_frozen_release_manifest_v11_5",
|
|
50
|
+
"validate_v11_5_release_manifest",
|
|
51
|
+
),
|
|
52
|
+
"core.frozen_release_manifest.v8": (
|
|
53
|
+
"scripts.validate_frozen_release_manifest_v11_5_1",
|
|
54
|
+
"validate_v11_5_1_release_manifest",
|
|
55
|
+
),
|
|
56
|
+
"core.frozen_release_manifest.v8": (
|
|
57
|
+
"scripts.validate_frozen_release_manifest_v11_5_1",
|
|
58
|
+
"validate_v11_5_1_release_manifest",
|
|
59
|
+
),
|
|
60
|
+
"core.dsk.v3": (
|
|
61
|
+
"core_runtime.core.dsk_v3",
|
|
62
|
+
"evaluate_dsk_v3",
|
|
63
|
+
),
|
|
64
|
+
"core.dsk.v3": (
|
|
65
|
+
"core_runtime.core.dsk_v3",
|
|
66
|
+
"evaluate_dsk_v3",
|
|
67
|
+
),
|
|
68
|
+
"core.contract_program.v2": (
|
|
69
|
+
"core_runtime.core.contract_program_v2",
|
|
70
|
+
"evaluate_contract_v2",
|
|
71
|
+
),
|
|
72
|
+
"core.frozen_rule_set.v1": (
|
|
73
|
+
"scripts.validate_frozen_rule_set",
|
|
74
|
+
"validate_frozen_rule_set",
|
|
75
|
+
),
|
|
76
|
+
"core.rule_anchor_batch.v1": (
|
|
77
|
+
"scripts.validate_rule_anchor_batch",
|
|
78
|
+
"validate_rule_anchor_batch",
|
|
79
|
+
),
|
|
80
|
+
"core.rule_anchor_chain_evidence.v1": (
|
|
81
|
+
"core_runtime.core.rule_anchor",
|
|
82
|
+
"validate_rule_anchor_chain_evidence_payload",
|
|
83
|
+
),
|
|
84
|
+
"core.rule_approval.v1": (
|
|
85
|
+
"scripts.validate_rule_approval",
|
|
86
|
+
"validate_rule_approval",
|
|
87
|
+
),
|
|
88
|
+
"core.rule_approval_request.v1": (
|
|
89
|
+
"core_runtime.core.rule_anchor",
|
|
90
|
+
"validate_approval_request_payload",
|
|
91
|
+
),
|
|
92
|
+
"core.unsigned_rule_anchor_transaction.v1": (
|
|
93
|
+
"scripts.validate_unsigned_rule_anchor_transaction",
|
|
94
|
+
"validate_unsigned_transaction",
|
|
95
|
+
),
|
|
96
|
+
"core.unsigned_rule_anchor_deployment.v1": (
|
|
97
|
+
"scripts.validate_unsigned_rule_anchor_deployment",
|
|
98
|
+
"validate_unsigned_deployment",
|
|
99
|
+
),
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def _entry(code: str, message: str, field: str = "$", **extra: Any) -> dict[str, Any]:
|
|
104
|
+
item: dict[str, Any] = {"code": code, "message": message, "field": field}
|
|
105
|
+
item.update(extra)
|
|
106
|
+
return item
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def _schema_version(schema: dict[str, Any]) -> str | None:
|
|
110
|
+
value = schema.get("properties", {}).get("schema_version", {}).get("const")
|
|
111
|
+
return value if isinstance(value, str) else None
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def _open_object_paths(schema: Any, field: str = "$", seen: set[int] | None = None) -> list[str]:
|
|
115
|
+
if seen is None:
|
|
116
|
+
seen = set()
|
|
117
|
+
if not isinstance(schema, dict) or id(schema) in seen:
|
|
118
|
+
return []
|
|
119
|
+
seen.add(id(schema))
|
|
120
|
+
paths: list[str] = []
|
|
121
|
+
if schema.get("type") == "object" and isinstance(schema.get("properties"), dict):
|
|
122
|
+
if schema.get("additionalProperties") is not False:
|
|
123
|
+
paths.append(field)
|
|
124
|
+
for key in ("properties", "definitions", "$defs"):
|
|
125
|
+
children = schema.get(key)
|
|
126
|
+
if isinstance(children, dict):
|
|
127
|
+
for child_name, child in children.items():
|
|
128
|
+
paths.extend(_open_object_paths(child, f"{field}.{key}.{child_name}", seen))
|
|
129
|
+
items = schema.get("items")
|
|
130
|
+
if isinstance(items, dict):
|
|
131
|
+
paths.extend(_open_object_paths(items, f"{field}.items", seen))
|
|
132
|
+
for key in ("oneOf", "anyOf", "allOf"):
|
|
133
|
+
branches = schema.get(key)
|
|
134
|
+
if isinstance(branches, list):
|
|
135
|
+
for index, branch in enumerate(branches):
|
|
136
|
+
paths.extend(_open_object_paths(branch, f"{field}.{key}[{index}]", seen))
|
|
137
|
+
return paths
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def _public_schema_inventory() -> tuple[list[dict[str, Any]], list[dict[str, Any]]]:
|
|
141
|
+
rows: list[dict[str, Any]] = []
|
|
142
|
+
errors: list[dict[str, Any]] = []
|
|
143
|
+
generic_versions = set(executable_contract_versions())
|
|
144
|
+
for path in sorted((item for item in SCHEMA_ROOT.iterdir() if item.name.endswith(".json")), key=lambda item: item.name):
|
|
145
|
+
try:
|
|
146
|
+
schema = json.loads(path.read_text(encoding="utf-8"))
|
|
147
|
+
except (OSError, json.JSONDecodeError) as exc:
|
|
148
|
+
errors.append(_entry("schema_unreadable", exc.__class__.__name__, f"core_runtime/data/schemas/core/{path.name}"))
|
|
149
|
+
continue
|
|
150
|
+
version = _schema_version(schema)
|
|
151
|
+
if version in generic_versions:
|
|
152
|
+
mechanism = "generic_semantic_evaluator"
|
|
153
|
+
elif version in STANDALONE_EXECUTABLE_CONTRACTS:
|
|
154
|
+
mechanism = "standalone_semantic_validator"
|
|
155
|
+
else:
|
|
156
|
+
mechanism = "unclassified"
|
|
157
|
+
errors.append(
|
|
158
|
+
_entry(
|
|
159
|
+
"unclassified_public_contract",
|
|
160
|
+
"Every public schema requires an executable semantic mechanism.",
|
|
161
|
+
f"core_runtime/data/schemas/core/{path.name}",
|
|
162
|
+
schema_version=version,
|
|
163
|
+
)
|
|
164
|
+
)
|
|
165
|
+
open_paths = _open_object_paths(schema)
|
|
166
|
+
rows.append(
|
|
167
|
+
{
|
|
168
|
+
"schema_version": version,
|
|
169
|
+
"schema_path": f"core_runtime/data/schemas/core/{path.name}",
|
|
170
|
+
"mechanism": mechanism,
|
|
171
|
+
"shape_profile": "closed_native" if not open_paths else "legacy_open_closed_by_strict_evaluator",
|
|
172
|
+
"open_object_count": len(open_paths),
|
|
173
|
+
}
|
|
174
|
+
)
|
|
175
|
+
return rows, errors
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
def _standalone_mechanism_errors() -> list[dict[str, Any]]:
|
|
179
|
+
errors: list[dict[str, Any]] = []
|
|
180
|
+
for version, (module_name, symbol_name) in sorted(STANDALONE_EXECUTABLE_CONTRACTS.items()):
|
|
181
|
+
try:
|
|
182
|
+
module = importlib.import_module(module_name)
|
|
183
|
+
except ImportError as exc:
|
|
184
|
+
errors.append(_entry("validator_import_failed", exc.__class__.__name__, version))
|
|
185
|
+
continue
|
|
186
|
+
if not callable(getattr(module, symbol_name, None)):
|
|
187
|
+
errors.append(
|
|
188
|
+
_entry(
|
|
189
|
+
"validator_symbol_missing",
|
|
190
|
+
"Declared standalone semantic validator is not callable.",
|
|
191
|
+
version,
|
|
192
|
+
module=module_name,
|
|
193
|
+
symbol=symbol_name,
|
|
194
|
+
)
|
|
195
|
+
)
|
|
196
|
+
return errors
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
def audit_contract_executability() -> dict[str, Any]:
|
|
200
|
+
"""Execute positive and schema-valid negative probes for every contract."""
|
|
201
|
+
|
|
202
|
+
errors: list[dict[str, Any]] = []
|
|
203
|
+
warnings: list[dict[str, Any]] = []
|
|
204
|
+
results: list[dict[str, Any]] = []
|
|
205
|
+
probes = executable_contract_probes()
|
|
206
|
+
probe_versions = {probe.schema_version for probe in probes}
|
|
207
|
+
evaluator_versions = set(executable_contract_versions())
|
|
208
|
+
loader_versions = {
|
|
209
|
+
_schema_version(load_contract_schema(contract_name))
|
|
210
|
+
for contract_name in available_contracts()
|
|
211
|
+
}
|
|
212
|
+
loader_versions.discard(None)
|
|
213
|
+
|
|
214
|
+
if probe_versions != evaluator_versions or evaluator_versions != loader_versions:
|
|
215
|
+
errors.append(
|
|
216
|
+
_entry(
|
|
217
|
+
"contract_registry_drift",
|
|
218
|
+
"Loader, evaluator, and executable-probe registries must contain the same contracts.",
|
|
219
|
+
"registry",
|
|
220
|
+
loader_only=sorted(loader_versions - evaluator_versions),
|
|
221
|
+
evaluator_without_probe=sorted(evaluator_versions - probe_versions),
|
|
222
|
+
probe_without_loader=sorted(probe_versions - loader_versions),
|
|
223
|
+
)
|
|
224
|
+
)
|
|
225
|
+
|
|
226
|
+
for probe in sorted(probes, key=lambda item: item.schema_version):
|
|
227
|
+
accepted_structure = validate_contract_structure(probe.accepted)
|
|
228
|
+
accepted_first = evaluate_contract_payload(probe.accepted)
|
|
229
|
+
accepted_second = evaluate_contract_payload(probe.accepted)
|
|
230
|
+
negative = copy.deepcopy(probe.accepted)
|
|
231
|
+
probe.mutate(negative)
|
|
232
|
+
negative_structure = validate_contract_structure(negative)
|
|
233
|
+
negative_result = evaluate_contract_payload(negative)
|
|
234
|
+
negative_codes = {item["code"] for item in negative_result["errors"]}
|
|
235
|
+
|
|
236
|
+
probe_errors: list[str] = []
|
|
237
|
+
if accepted_structure:
|
|
238
|
+
probe_errors.append("accepted_probe_schema_failed")
|
|
239
|
+
if accepted_first["status"] != "passed":
|
|
240
|
+
probe_errors.append("accepted_probe_semantics_failed")
|
|
241
|
+
if accepted_first != accepted_second:
|
|
242
|
+
probe_errors.append("nondeterministic_result")
|
|
243
|
+
if negative_structure:
|
|
244
|
+
probe_errors.append("negative_probe_not_schema_valid")
|
|
245
|
+
if negative_result["status"] != "failed":
|
|
246
|
+
probe_errors.append("semantic_negative_probe_accepted")
|
|
247
|
+
if probe.expected_error not in negative_codes:
|
|
248
|
+
probe_errors.append("expected_semantic_error_missing")
|
|
249
|
+
if not SEMANTIC_RULE_IDS.get(probe.schema_version):
|
|
250
|
+
probe_errors.append("semantic_rule_inventory_missing")
|
|
251
|
+
if accepted_first.get("execution_authorized") is not False:
|
|
252
|
+
probe_errors.append("execution_authority_leak")
|
|
253
|
+
if accepted_first.get("deployment_authorized") is not False:
|
|
254
|
+
probe_errors.append("deployment_authority_leak")
|
|
255
|
+
|
|
256
|
+
result = {
|
|
257
|
+
"schema_version": probe.schema_version,
|
|
258
|
+
"status": "passed" if not probe_errors else "failed",
|
|
259
|
+
"accepted_input_fingerprint": accepted_first["input_fingerprint"],
|
|
260
|
+
"accepted_report_fingerprint": accepted_first["report_fingerprint"],
|
|
261
|
+
"semantic_rule_count": len(SEMANTIC_RULE_IDS.get(probe.schema_version, ())),
|
|
262
|
+
"negative_probe_schema_valid": not negative_structure,
|
|
263
|
+
"expected_rejection_code": probe.expected_error,
|
|
264
|
+
"observed_rejection_codes": sorted(negative_codes),
|
|
265
|
+
"probe_errors": probe_errors,
|
|
266
|
+
}
|
|
267
|
+
results.append(result)
|
|
268
|
+
for code in probe_errors:
|
|
269
|
+
errors.append(
|
|
270
|
+
_entry(
|
|
271
|
+
code,
|
|
272
|
+
"Contract executability probe failed.",
|
|
273
|
+
probe.schema_version,
|
|
274
|
+
)
|
|
275
|
+
)
|
|
276
|
+
|
|
277
|
+
inventory, inventory_errors = _public_schema_inventory()
|
|
278
|
+
errors.extend(inventory_errors)
|
|
279
|
+
errors.extend(_standalone_mechanism_errors())
|
|
280
|
+
for row in inventory:
|
|
281
|
+
if row["open_object_count"]:
|
|
282
|
+
warnings.append(
|
|
283
|
+
_entry(
|
|
284
|
+
"legacy_open_schema",
|
|
285
|
+
"Published compatibility schema remains open; strict executable evaluation closes declared object shapes without rewriting history.",
|
|
286
|
+
row["schema_path"],
|
|
287
|
+
open_object_count=row["open_object_count"],
|
|
288
|
+
)
|
|
289
|
+
)
|
|
290
|
+
|
|
291
|
+
report: dict[str, Any] = {
|
|
292
|
+
"schema": "core.contract_executability_audit.v1",
|
|
293
|
+
"status": "passed" if not errors else "failed",
|
|
294
|
+
"authority": "validation_only",
|
|
295
|
+
"truth_claimed": False,
|
|
296
|
+
"execution_authorized": False,
|
|
297
|
+
"contract_count": len(results),
|
|
298
|
+
"passed_count": sum(result["status"] == "passed" for result in results),
|
|
299
|
+
"failed_count": sum(result["status"] == "failed" for result in results),
|
|
300
|
+
"public_schema_count": len(inventory),
|
|
301
|
+
"results": results,
|
|
302
|
+
"public_schema_inventory": inventory,
|
|
303
|
+
"errors": errors,
|
|
304
|
+
"warnings": warnings,
|
|
305
|
+
}
|
|
306
|
+
report["report_fingerprint"] = f"sha256:{canonical_json_hash(report)}"
|
|
307
|
+
return report
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"""Load public CORE v10 contract schemas from the repository tree."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
from importlib.resources import files
|
|
7
|
+
from typing import Any
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
SCHEMA_ROOT = files("core_runtime").joinpath("data", "schemas", "core")
|
|
11
|
+
CONTRACT_SCHEMAS = {
|
|
12
|
+
"causal_trace.v1": "causal_trace.v1.json",
|
|
13
|
+
"contract_program.v1": "contract_program.v1.json",
|
|
14
|
+
"entropy_signal.v1": "entropy_signal.v1.json",
|
|
15
|
+
"control_decision.v1": "control_decision.v1.json",
|
|
16
|
+
"execution_receipt.v1": "execution_receipt.v1.json",
|
|
17
|
+
"pattern_candidate.v1": "pattern_candidate.v1.json",
|
|
18
|
+
"memory_artifact.v1": "memory_artifact.v1.json",
|
|
19
|
+
"task_closeout.v1": "task_closeout.v1.json",
|
|
20
|
+
"effect_result.v1": "effect_result.v1.json",
|
|
21
|
+
"memory_generation_result.v1": "memory_generation_result.v1.json",
|
|
22
|
+
"operational_learning_event.v1": "operational_learning_event.v1.json",
|
|
23
|
+
"policy_lifecycle.v1": "policy_lifecycle.v1.json",
|
|
24
|
+
"context_threshold.v1": "context_threshold.v1.json",
|
|
25
|
+
"context_gate.v1": "context_gate.v1.json",
|
|
26
|
+
"retention_manifest.v1": "retention_manifest.v1.json",
|
|
27
|
+
"reversibility_policy.v1": "reversibility_policy.v1.json",
|
|
28
|
+
"state_transition.v1": "state_transition.v1.json",
|
|
29
|
+
"template_promotion_candidate.v1": "template_promotion_candidate.v1.json",
|
|
30
|
+
"physical_safety_assurance_case.v1": "physical_safety_assurance_case.v1.json",
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def available_contracts() -> tuple[str, ...]:
|
|
35
|
+
"""Return the known public contract names in stable order."""
|
|
36
|
+
|
|
37
|
+
return tuple(sorted(CONTRACT_SCHEMAS))
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def contract_schema_path(contract_name: str) -> Any:
|
|
41
|
+
"""Resolve the schema file for a known contract name."""
|
|
42
|
+
|
|
43
|
+
filename = CONTRACT_SCHEMAS.get(contract_name)
|
|
44
|
+
if filename is None:
|
|
45
|
+
raise KeyError(f"unknown contract schema: {contract_name}")
|
|
46
|
+
return SCHEMA_ROOT / filename
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def load_contract_schema(contract_name: str) -> dict[str, Any]:
|
|
50
|
+
"""Load and parse a public contract schema from `schemas/core/`."""
|
|
51
|
+
|
|
52
|
+
path = contract_schema_path(contract_name)
|
|
53
|
+
with path.open("r", encoding="utf-8") as handle:
|
|
54
|
+
payload = json.load(handle)
|
|
55
|
+
if not isinstance(payload, dict):
|
|
56
|
+
raise ValueError(f"contract schema must be a JSON object: {path}")
|
|
57
|
+
return payload
|