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,100 @@
|
|
|
1
|
+
"""Immutable in-memory index for derived audit trails."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass, field
|
|
6
|
+
from types import MappingProxyType
|
|
7
|
+
from typing import Any, Iterable, Mapping
|
|
8
|
+
|
|
9
|
+
from core_runtime.core.audit_event import (
|
|
10
|
+
AuditEvent,
|
|
11
|
+
compute_audit_fingerprint,
|
|
12
|
+
canonical_event_sort_key,
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def _freeze_event_group_map(groups: dict[Any, tuple[AuditEvent, ...]]) -> Mapping[Any, tuple[AuditEvent, ...]]:
|
|
17
|
+
return MappingProxyType(dict(sorted(groups.items(), key=lambda item: str(item[0]))))
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@dataclass(frozen=True)
|
|
21
|
+
class AuditTrailIndex:
|
|
22
|
+
events: tuple[AuditEvent, ...] = field(default_factory=tuple)
|
|
23
|
+
by_id: Mapping[str, AuditEvent] = field(default_factory=dict)
|
|
24
|
+
by_correlation: Mapping[str, tuple[AuditEvent, ...]] = field(default_factory=dict)
|
|
25
|
+
by_type: Mapping[str, tuple[AuditEvent, ...]] = field(default_factory=dict)
|
|
26
|
+
by_tick: Mapping[int, tuple[AuditEvent, ...]] = field(default_factory=dict)
|
|
27
|
+
|
|
28
|
+
def __post_init__(self) -> None:
|
|
29
|
+
events = tuple(sorted(self.events, key=canonical_event_sort_key))
|
|
30
|
+
|
|
31
|
+
by_id: dict[str, AuditEvent] = {}
|
|
32
|
+
by_correlation: dict[str, list[AuditEvent]] = {}
|
|
33
|
+
by_type: dict[str, list[AuditEvent]] = {}
|
|
34
|
+
by_tick: dict[int, list[AuditEvent]] = {}
|
|
35
|
+
|
|
36
|
+
for event in events:
|
|
37
|
+
if event.event_id in by_id:
|
|
38
|
+
raise ValueError(f"Duplicate audit event_id detected: {event.event_id}")
|
|
39
|
+
by_id[event.event_id] = event
|
|
40
|
+
by_correlation.setdefault(event.correlation_id, []).append(event)
|
|
41
|
+
by_type.setdefault(event.event_type, []).append(event)
|
|
42
|
+
by_tick.setdefault(event.logical_tick, []).append(event)
|
|
43
|
+
|
|
44
|
+
object.__setattr__(self, "events", events)
|
|
45
|
+
object.__setattr__(self, "by_id", MappingProxyType(by_id))
|
|
46
|
+
object.__setattr__(self, "by_correlation", _freeze_event_group_map({
|
|
47
|
+
key: tuple(sorted(value, key=canonical_event_sort_key))
|
|
48
|
+
for key, value in by_correlation.items()
|
|
49
|
+
}))
|
|
50
|
+
object.__setattr__(self, "by_type", _freeze_event_group_map({
|
|
51
|
+
key: tuple(sorted(value, key=canonical_event_sort_key))
|
|
52
|
+
for key, value in by_type.items()
|
|
53
|
+
}))
|
|
54
|
+
object.__setattr__(self, "by_tick", MappingProxyType({
|
|
55
|
+
key: tuple(sorted(value, key=canonical_event_sort_key))
|
|
56
|
+
for key, value in sorted(by_tick.items(), key=lambda item: item[0])
|
|
57
|
+
}))
|
|
58
|
+
|
|
59
|
+
@classmethod
|
|
60
|
+
def from_events(cls, events: Iterable[AuditEvent]) -> "AuditTrailIndex":
|
|
61
|
+
return cls(events=tuple(events))
|
|
62
|
+
|
|
63
|
+
def lookup_event(self, event_id: str) -> AuditEvent | None:
|
|
64
|
+
return self.by_id.get(event_id)
|
|
65
|
+
|
|
66
|
+
def lookup_correlation(self, correlation_id: str) -> tuple[AuditEvent, ...]:
|
|
67
|
+
return self.by_correlation.get(correlation_id, ())
|
|
68
|
+
|
|
69
|
+
def lookup_type(self, event_type: str) -> tuple[AuditEvent, ...]:
|
|
70
|
+
return self.by_type.get(event_type, ())
|
|
71
|
+
|
|
72
|
+
def lookup_tick(self, logical_tick: int) -> tuple[AuditEvent, ...]:
|
|
73
|
+
return self.by_tick.get(logical_tick, ())
|
|
74
|
+
|
|
75
|
+
def to_dict(self) -> dict[str, Any]:
|
|
76
|
+
return {
|
|
77
|
+
"events": [event.to_dict() for event in self.events],
|
|
78
|
+
"by_id": {event_id: event.to_dict() for event_id, event in self.by_id.items()},
|
|
79
|
+
"by_correlation": {
|
|
80
|
+
correlation_id: [event.to_dict() for event in events]
|
|
81
|
+
for correlation_id, events in self.by_correlation.items()
|
|
82
|
+
},
|
|
83
|
+
"by_type": {
|
|
84
|
+
event_type: [event.to_dict() for event in events]
|
|
85
|
+
for event_type, events in self.by_type.items()
|
|
86
|
+
},
|
|
87
|
+
"by_tick": {
|
|
88
|
+
str(logical_tick): [event.to_dict() for event in events]
|
|
89
|
+
for logical_tick, events in self.by_tick.items()
|
|
90
|
+
},
|
|
91
|
+
"fingerprint": self.fingerprint(),
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
def fingerprint(self) -> str:
|
|
95
|
+
return compute_audit_fingerprint(
|
|
96
|
+
{
|
|
97
|
+
"events": [event.to_dict() for event in self.events],
|
|
98
|
+
"schema_version": "4.9.0",
|
|
99
|
+
}
|
|
100
|
+
)
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"""Canonical serialization and ordering helpers.
|
|
2
|
+
|
|
3
|
+
These helpers centralize the ordering rules used by deterministic
|
|
4
|
+
serializers, graph fingerprints, and regression tests.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import json
|
|
10
|
+
import hashlib
|
|
11
|
+
from typing import Any
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def canonical_json_dumps(payload: Any) -> str:
|
|
15
|
+
"""Serialize payload with canonical JSON formatting."""
|
|
16
|
+
return json.dumps(
|
|
17
|
+
payload,
|
|
18
|
+
sort_keys=True,
|
|
19
|
+
separators=(",", ":"),
|
|
20
|
+
ensure_ascii=False,
|
|
21
|
+
default=str,
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def canonical_json_hash(payload: Any) -> str:
|
|
26
|
+
"""Hash the canonical JSON serialization of a payload."""
|
|
27
|
+
return hashlib.sha256(canonical_json_dumps(payload).encode("utf-8")).hexdigest()
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def canonical_graph_node_key(node: Any) -> tuple[int, str, str]:
|
|
31
|
+
"""Return the canonical ordering key for graph nodes."""
|
|
32
|
+
return (
|
|
33
|
+
int(getattr(node, "logical_order", 0)),
|
|
34
|
+
str(getattr(node, "node_type", "")),
|
|
35
|
+
str(getattr(node, "node_id", "")),
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def canonical_graph_edge_key(edge: Any) -> tuple[str, str, str]:
|
|
40
|
+
"""Return the canonical ordering key for graph edges."""
|
|
41
|
+
return (
|
|
42
|
+
str(getattr(edge, "source_id", "")),
|
|
43
|
+
str(getattr(edge, "target_id", "")),
|
|
44
|
+
str(getattr(edge, "edge_type", "flow")),
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def canonical_graph_nodes(nodes: list[Any] | tuple[Any, ...]) -> list[Any]:
|
|
49
|
+
"""Return nodes ordered canonically."""
|
|
50
|
+
return sorted(nodes, key=canonical_graph_node_key)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def canonical_graph_edges(edges: list[Any] | tuple[Any, ...]) -> list[Any]:
|
|
54
|
+
"""Return edges ordered canonically."""
|
|
55
|
+
return sorted(edges, key=canonical_graph_edge_key)
|