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.
Files changed (96) hide show
  1. core_runtime/__init__.py +10 -0
  2. core_runtime/__version__.py +17 -0
  3. core_runtime/cli/__init__.py +7 -0
  4. core_runtime/cli/__main__.py +22 -0
  5. core_runtime/cli/bump_version.py +176 -0
  6. core_runtime/cli/contract_preflight.py +69 -0
  7. core_runtime/cli/create_domain.py +66 -0
  8. core_runtime/cli/doctor.py +44 -0
  9. core_runtime/cli/inventory.py +85 -0
  10. core_runtime/cli/lint.py +8 -0
  11. core_runtime/cli/main.py +579 -0
  12. core_runtime/cli/release_check.py +65 -0
  13. core_runtime/cli/repair_artifact_paths.py +48 -0
  14. core_runtime/cli/sync_template.py +67 -0
  15. core_runtime/cli/validate.py +73 -0
  16. core_runtime/core/__init__.py +34 -0
  17. core_runtime/core/audit_event.py +760 -0
  18. core_runtime/core/audit_trail_index.py +100 -0
  19. core_runtime/core/canonicalization.py +55 -0
  20. core_runtime/core/contract_evaluator.py +945 -0
  21. core_runtime/core/contract_executability.py +307 -0
  22. core_runtime/core/contract_loader.py +57 -0
  23. core_runtime/core/contract_probes.py +630 -0
  24. core_runtime/core/contract_program.py +131 -0
  25. core_runtime/core/contract_program_registry.py +104 -0
  26. core_runtime/core/contract_program_v2.py +126 -0
  27. core_runtime/core/dsk_v3.py +142 -0
  28. core_runtime/core/explainability.py +2115 -0
  29. core_runtime/core/numeric_normalization.py +120 -0
  30. core_runtime/core/rule_anchor.py +1388 -0
  31. core_runtime/core/schema_fingerprint.py +69 -0
  32. core_runtime/core/sensor_evidence.py +548 -0
  33. core_runtime/data/contracts/CoreAnchor.sol +109 -0
  34. core_runtime/data/contracts/CoreRuleAnchor.abi.json +111 -0
  35. core_runtime/data/contracts/CoreRuleAnchor.bin +1 -0
  36. core_runtime/data/contracts/CoreRuleAnchor.build.json +20 -0
  37. core_runtime/data/contracts/CoreRuleAnchor.runtime.bin +1 -0
  38. core_runtime/data/contracts/CoreRuleAnchor.sol +74 -0
  39. core_runtime/data/package_data_manifest.v1.json +173 -0
  40. core_runtime/data/schemas/core/causal_trace.v1.json +141 -0
  41. core_runtime/data/schemas/core/context_gate.v1.json +38 -0
  42. core_runtime/data/schemas/core/context_threshold.v1.json +46 -0
  43. core_runtime/data/schemas/core/contract_program.v1.json +186 -0
  44. core_runtime/data/schemas/core/contract_program.v2.json +187 -0
  45. core_runtime/data/schemas/core/control_decision.v1.json +114 -0
  46. core_runtime/data/schemas/core/dsk.v3.json +105 -0
  47. core_runtime/data/schemas/core/effect_result.v1.json +39 -0
  48. core_runtime/data/schemas/core/entropy_signal.v1.json +108 -0
  49. core_runtime/data/schemas/core/execution_receipt.v1.json +93 -0
  50. core_runtime/data/schemas/core/frozen_release_manifest.v1.json +87 -0
  51. core_runtime/data/schemas/core/frozen_release_manifest.v2.json +72 -0
  52. core_runtime/data/schemas/core/frozen_release_manifest.v3.json +38 -0
  53. core_runtime/data/schemas/core/frozen_release_manifest.v4.json +72 -0
  54. core_runtime/data/schemas/core/frozen_release_manifest.v5.json +38 -0
  55. core_runtime/data/schemas/core/frozen_release_manifest.v6.json +116 -0
  56. core_runtime/data/schemas/core/frozen_release_manifest.v7.json +37 -0
  57. core_runtime/data/schemas/core/frozen_release_manifest.v8.json +114 -0
  58. core_runtime/data/schemas/core/frozen_rule_set.v1.json +282 -0
  59. core_runtime/data/schemas/core/memory_artifact.v1.json +120 -0
  60. core_runtime/data/schemas/core/memory_generation_result.v1.json +37 -0
  61. core_runtime/data/schemas/core/operational_learning_event.v1.json +63 -0
  62. core_runtime/data/schemas/core/pattern_candidate.v1.json +114 -0
  63. core_runtime/data/schemas/core/physical_safety_assurance_case.v1.json +676 -0
  64. core_runtime/data/schemas/core/policy_lifecycle.v1.json +99 -0
  65. core_runtime/data/schemas/core/retention_manifest.v1.json +53 -0
  66. core_runtime/data/schemas/core/reversibility_policy.v1.json +107 -0
  67. core_runtime/data/schemas/core/rule_anchor_batch.v1.json +93 -0
  68. core_runtime/data/schemas/core/rule_anchor_chain_evidence.v1.json +56 -0
  69. core_runtime/data/schemas/core/rule_approval.v1.json +49 -0
  70. core_runtime/data/schemas/core/rule_approval_request.v1.json +42 -0
  71. core_runtime/data/schemas/core/state_transition.v1.json +115 -0
  72. core_runtime/data/schemas/core/task_closeout.v1.json +47 -0
  73. core_runtime/data/schemas/core/template_promotion_candidate.v1.json +83 -0
  74. core_runtime/data/schemas/core/unsigned_rule_anchor_deployment.v1.json +106 -0
  75. core_runtime/data/schemas/core/unsigned_rule_anchor_transaction.v1.json +116 -0
  76. core_runtime/tooling/__init__.py +48 -0
  77. core_runtime/tooling/bump_version.py +900 -0
  78. core_runtime/tooling/contract_preflight.py +293 -0
  79. core_runtime/tooling/create_domain.py +254 -0
  80. core_runtime/tooling/diagnostics.py +129 -0
  81. core_runtime/tooling/doctor.py +482 -0
  82. core_runtime/tooling/file_inventory.py +182 -0
  83. core_runtime/tooling/json_checks.py +100 -0
  84. core_runtime/tooling/release_check.py +1017 -0
  85. core_runtime/tooling/repair_artifact_paths.py +458 -0
  86. core_runtime/tooling/report_writer.py +176 -0
  87. core_runtime/tooling/repository_inventory.py +399 -0
  88. core_runtime/tooling/safety_checks.py +172 -0
  89. core_runtime/tooling/sync_template.py +303 -0
  90. core_runtime/tooling/validation.py +507 -0
  91. core_runtime/tooling/version_inventory.py +256 -0
  92. core_runtime_engine-11.5.1.dist-info/METADATA +35 -0
  93. core_runtime_engine-11.5.1.dist-info/RECORD +96 -0
  94. core_runtime_engine-11.5.1.dist-info/WHEEL +5 -0
  95. core_runtime_engine-11.5.1.dist-info/entry_points.txt +2 -0
  96. core_runtime_engine-11.5.1.dist-info/top_level.txt +1 -0
@@ -0,0 +1,120 @@
1
+ """CORE v4.1 — Numeric Normalization (QUANTIZATION LAYER).
2
+
3
+ ALL float values used in fingerprints, hashes, EventLog payloads,
4
+ KB facts, projections, replay, and compliance MUST be quantized
5
+ before serialization or hashing.
6
+
7
+ Rationale:
8
+ FFT, MFCC, RMS, filters, and any floating-point computation
9
+ can diverge across CPUs, BLAS, SIMD, compilers, and operation
10
+ ordering. This breaks CORE's fundamental guarantee:
11
+ "same input = same hash".
12
+
13
+ Quantization to a fixed decimal precision (default 8) eliminates
14
+ float-induced non-determinism in all hash-producing paths.
15
+
16
+ precision=8 means: round(value, 8) → stable across IEEE 754
17
+ implementations for values with up to 8 significant decimal digits.
18
+
19
+ IMPORTANT:
20
+ - Call quantize_float() BEFORE json.dumps() in any fingerprint/hash
21
+ - Call quantize_vector() for any list[float] before serialization
22
+ - Call quantize_dict() for any dict that may contain nested floats
23
+ - NEVER skip quantization for values entering EventLog, KB, or replay
24
+ """
25
+
26
+ from __future__ import annotations
27
+
28
+ import json
29
+ from types import MappingProxyType
30
+ from typing import Any
31
+
32
+ # Default precision: 8 decimal digits (sufficient for most engineering values)
33
+ DEFAULT_FLOAT_PRECISION = 8
34
+
35
+
36
+ def quantize_float(value: float, precision: int = DEFAULT_FLOAT_PRECISION) -> float:
37
+ """Quantize a single float to a fixed decimal precision.
38
+
39
+ This eliminates IEEE 754 representation differences across
40
+ platforms, BLAS implementations, and SIMD configurations.
41
+
42
+ Args:
43
+ value: The float to quantize.
44
+ precision: Number of decimal digits to keep.
45
+
46
+ Returns:
47
+ The quantized float (rounded to `precision` decimal places).
48
+ """
49
+ return round(float(value), precision)
50
+
51
+
52
+ def quantize_vector(
53
+ values: list[float],
54
+ precision: int = DEFAULT_FLOAT_PRECISION,
55
+ ) -> list[float]:
56
+ """Quantize a list of floats.
57
+
58
+ Args:
59
+ values: List of floats to quantize.
60
+ precision: Number of decimal digits to keep.
61
+
62
+ Returns:
63
+ New list with quantized values.
64
+ """
65
+ return [quantize_float(v, precision) for v in values]
66
+
67
+
68
+ def quantize_dict(
69
+ data: dict[str, Any],
70
+ precision: int = DEFAULT_FLOAT_PRECISION,
71
+ ) -> dict[str, Any]:
72
+ """Recursively quantize all float values in a dict.
73
+
74
+ Walks the dict recursively. Any float value (including those
75
+ inside nested dicts or lists) is quantized.
76
+
77
+ Args:
78
+ data: Dict that may contain floats at any nesting level.
79
+ precision: Number of decimal digits to keep.
80
+
81
+ Returns:
82
+ New dict with all floats quantized.
83
+ """
84
+ return _quantize_value(data, precision)
85
+
86
+
87
+ def _quantize_value(value: Any, precision: int) -> Any:
88
+ """Recursively quantize floats in any nested structure."""
89
+ if isinstance(value, float):
90
+ return quantize_float(value, precision)
91
+ if isinstance(value, (dict, MappingProxyType)):
92
+ return {k: _quantize_value(v, precision) for k, v in sorted(value.items())}
93
+ if isinstance(value, (list, tuple)):
94
+ quantized = [_quantize_value(item, precision) for item in value]
95
+ return type(value)(quantized) # type: ignore[call-arg]
96
+ # int, str, bool, None — pass through unchanged
97
+ return value
98
+
99
+
100
+ def quantize_for_hash(data: Any, precision: int = DEFAULT_FLOAT_PRECISION) -> str:
101
+ """Quantize any serializable data and return deterministic JSON string.
102
+
103
+ This is the canonical way to prepare data for SHA-256 hashing.
104
+ It quantizes all floats, sorts all keys, and produces a stable
105
+ JSON string regardless of platform or float representation.
106
+
107
+ Args:
108
+ data: Any JSON-serializable data (dict, list, etc.).
109
+ precision: Float quantization precision.
110
+
111
+ Returns:
112
+ Deterministic JSON string suitable for hashing.
113
+ """
114
+ if isinstance(data, dict):
115
+ quantized = quantize_dict(data, precision)
116
+ elif isinstance(data, (list, tuple)):
117
+ quantized = _quantize_value(data, precision)
118
+ else:
119
+ quantized = _quantize_value(data, precision)
120
+ return json.dumps(quantized, sort_keys=True, default=str)