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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Core types for the Governed Decomposition Pipeline.
|
| 3 |
+
|
| 4 |
+
These mirror the kernel's Rust types (kernel governance types)
|
| 5 |
+
as Python dataclasses for pipeline processing. The kernel is the authority;
|
| 6 |
+
these are the pipeline's working copies.
|
| 7 |
+
|
| 8 |
+
SPEC-PIPELINE-001 Part B.3: Interface Contract with Kernel.
|
| 9 |
+
"""
|
| 10 |
+
|
| 11 |
+
from __future__ import annotations
|
| 12 |
+
|
| 13 |
+
from dataclasses import dataclass, field
|
| 14 |
+
from datetime import datetime
|
| 15 |
+
from enum import Enum, IntEnum
|
| 16 |
+
from hashlib import sha256
|
| 17 |
+
from typing import Optional
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 21 |
+
# 15 GROUNDING OPERATORS β mirrors kernel GroundingOperator
|
| 22 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 23 |
+
|
| 24 |
+
class Op(IntEnum):
|
| 25 |
+
"""15 grounding operators in admissibility DAG order."""
|
| 26 |
+
THIS = 0
|
| 27 |
+
GOES_WITH = 1
|
| 28 |
+
MANY_ONE = 2
|
| 29 |
+
EVERY_SOME = 3
|
| 30 |
+
NO = 4
|
| 31 |
+
IF_THEN = 5
|
| 32 |
+
BECAUSE = 6
|
| 33 |
+
SAME_NOT_SAME = 7
|
| 34 |
+
INSIDE_OUTSIDE = 8
|
| 35 |
+
CAN_CANNOT = 9
|
| 36 |
+
MAYBE = 10
|
| 37 |
+
MUST_LET = 11
|
| 38 |
+
TOGETHER_ALONE = 12
|
| 39 |
+
MORE_LESS = 13
|
| 40 |
+
NEAR_FAR = 14
|
| 41 |
+
|
| 42 |
+
@property
|
| 43 |
+
def canonical_name(self) -> str:
|
| 44 |
+
return _OP_NAMES[self.value]
|
| 45 |
+
|
| 46 |
+
@classmethod
|
| 47 |
+
def from_name(cls, name: str) -> Optional[Op]:
|
| 48 |
+
return _OP_BY_NAME.get(name)
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
_OP_NAMES = [
|
| 52 |
+
"THIS", "GOES-WITH", "MANY/ONE", "EVERY/SOME", "NO",
|
| 53 |
+
"IF/THEN", "BECAUSE", "SAME/NOT-SAME", "INSIDE/OUTSIDE",
|
| 54 |
+
"CAN/CANNOT", "MAYBE", "MUST/LET", "TOGETHER/ALONE",
|
| 55 |
+
"MORE/LESS", "NEAR/FAR",
|
| 56 |
+
]
|
| 57 |
+
_OP_BY_NAME = {name: Op(i) for i, name in enumerate(_OP_NAMES)}
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 61 |
+
# 7 THEOREM-DERIVED WITNESSES β mirrors kernel InterrogativeWitness
|
| 62 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 63 |
+
|
| 64 |
+
class Witness(IntEnum):
|
| 65 |
+
"""7 interrogative witnesses (theorem-derived, NOT folk WHO/WHY)."""
|
| 66 |
+
WHAT = 0
|
| 67 |
+
WHERE = 1
|
| 68 |
+
WHICH = 2
|
| 69 |
+
WHEN = 3
|
| 70 |
+
FOR_WHAT = 4
|
| 71 |
+
HOW = 5
|
| 72 |
+
WHENCE = 6
|
| 73 |
+
|
| 74 |
+
@property
|
| 75 |
+
def canonical_name(self) -> str:
|
| 76 |
+
return _WIT_NAMES[self.value]
|
| 77 |
+
|
| 78 |
+
@property
|
| 79 |
+
def modality(self) -> str:
|
| 80 |
+
"""governed modality per Universal Interrogative Theorem: G(WHENCE,WHEN), S(WHAT,WHERE,WHICH), F(FOR-WHAT,HOW)."""
|
| 81 |
+
return _WIT_MODALITY[self.value]
|
| 82 |
+
|
| 83 |
+
@property
|
| 84 |
+
def is_bridge_axis(self) -> bool:
|
| 85 |
+
"""FOR-WHAT x WHERE = unique global cut set (Fragility Topology Theorem 16)."""
|
| 86 |
+
return self in (Witness.FOR_WHAT, Witness.WHERE)
|
| 87 |
+
|
| 88 |
+
@property
|
| 89 |
+
def fragility_tier(self) -> int:
|
| 90 |
+
"""Tier 1 (descriptive: WHAT,WHICH,HOW) persists after normative collapse. Tier 2 = rest."""
|
| 91 |
+
return 1 if self in (Witness.WHAT, Witness.WHICH, Witness.HOW) else 2
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
_WIT_NAMES = ["WHAT", "WHERE", "WHICH", "WHEN", "FOR-WHAT", "HOW", "WHENCE"]
|
| 95 |
+
_WIT_MODALITY = ["S", "S", "S", "G", "F", "F", "G"]
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 99 |
+
# CORPUS TIERS
|
| 100 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 101 |
+
|
| 102 |
+
class Tier(str, Enum):
|
| 103 |
+
T1 = "T1" # EDA tool output
|
| 104 |
+
T2 = "T2" # RTL design documents
|
| 105 |
+
T3 = "T3" # Formal property specifications
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 109 |
+
# PROVENANCE β SPEC-PIPELINE-001 Part A.4
|
| 110 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 111 |
+
|
| 112 |
+
@dataclass
|
| 113 |
+
class SourceProvenance:
|
| 114 |
+
source_id: str
|
| 115 |
+
tier: Tier
|
| 116 |
+
url: str
|
| 117 |
+
commit_or_version: str
|
| 118 |
+
license: str
|
| 119 |
+
acquired_at: str # ISO 8601
|
| 120 |
+
artifact_sha256: str
|
| 121 |
+
acquired_by: str = "Devon Generally"
|
| 122 |
+
|
| 123 |
+
|
| 124 |
+
# οΏ½οΏ½οΏ½ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 125 |
+
# OPERATOR EXPRESSIONS + governed EXAMPLE
|
| 126 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 127 |
+
|
| 128 |
+
@dataclass
|
| 129 |
+
class OperatorExpression:
|
| 130 |
+
operator: Op
|
| 131 |
+
arguments: list[str] = field(default_factory=list)
|
| 132 |
+
evidence: str = ""
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
@dataclass
|
| 136 |
+
class OperatorSequence:
|
| 137 |
+
expressions: list[OperatorExpression] = field(default_factory=list)
|
| 138 |
+
|
| 139 |
+
def verify_ordering(self) -> bool:
|
| 140 |
+
for i in range(1, len(self.expressions)):
|
| 141 |
+
if self.expressions[i].operator < self.expressions[i - 1].operator:
|
| 142 |
+
return False
|
| 143 |
+
return True
|
| 144 |
+
|
| 145 |
+
|
| 146 |
+
@dataclass
|
| 147 |
+
class ModalityGrounding:
|
| 148 |
+
"""A single governed modality's operator sequence."""
|
| 149 |
+
modality: str # "G", "S", "F"
|
| 150 |
+
operators: OperatorSequence = field(default_factory=OperatorSequence)
|
| 151 |
+
|
| 152 |
+
|
| 153 |
+
@dataclass
|
| 154 |
+
class WitnessAttestation:
|
| 155 |
+
witness: Witness
|
| 156 |
+
attested: bool
|
| 157 |
+
evidence: str = ""
|
| 158 |
+
reason: str = "" # if withheld
|
| 159 |
+
|
| 160 |
+
|
| 161 |
+
@dataclass
|
| 162 |
+
class WitnessBundle:
|
| 163 |
+
attestations: dict[Witness, WitnessAttestation] = field(default_factory=dict)
|
| 164 |
+
|
| 165 |
+
def is_unanimous(self) -> bool:
|
| 166 |
+
if len(self.attestations) != len(Witness):
|
| 167 |
+
return False
|
| 168 |
+
return all(a.attested for a in self.attestations.values())
|
| 169 |
+
|
| 170 |
+
|
| 171 |
+
@dataclass
|
| 172 |
+
class FrameExample:
|
| 173 |
+
provenance: SourceProvenance
|
| 174 |
+
channel_a: ModalityGrounding
|
| 175 |
+
channel_b: ModalityGrounding
|
| 176 |
+
channel_c: ModalityGrounding
|
| 177 |
+
witnesses: WitnessBundle
|
| 178 |
+
content_hash: str = ""
|
| 179 |
+
|
| 180 |
+
def compute_hash(self) -> str:
|
| 181 |
+
h = sha256()
|
| 182 |
+
h.update(self.provenance.source_id.encode())
|
| 183 |
+
for g in [self.channel_a, self.channel_b, self.channel_c]:
|
| 184 |
+
for expr in g.operators.expressions:
|
| 185 |
+
h.update(bytes([expr.operator.value]))
|
| 186 |
+
h.update(expr.evidence.encode())
|
| 187 |
+
return h.hexdigest()
|
| 188 |
+
|
| 189 |
+
|
| 190 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 191 |
+
# EXCLUSION MANIFEST β SPEC-PIPELINE-001 Part C
|
| 192 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 193 |
+
|
| 194 |
+
class ExclusionReason(str, Enum):
|
| 195 |
+
LICENSE_HEADER = "LicenseHeader"
|
| 196 |
+
CHANGELOG = "Changelog"
|
| 197 |
+
FORMATTING = "FormattingArtifact"
|
| 198 |
+
EDITORIAL = "EditorialNote"
|
| 199 |
+
BOILERPLATE = "Boilerplate"
|
| 200 |
+
WHITESPACE = "WhitespaceOnly"
|
| 201 |
+
DUPLICATE = "DuplicateContent"
|
| 202 |
+
UNTRANSLATABLE = "Untranslatable"
|
| 203 |
+
|
| 204 |
+
|
| 205 |
+
class Classifier(str, Enum):
|
| 206 |
+
RULE = "RULE"
|
| 207 |
+
ORACLE = "ORACLE"
|
| 208 |
+
|
| 209 |
+
|
| 210 |
+
@dataclass
|
| 211 |
+
class ExclusionRecord:
|
| 212 |
+
source_id: str
|
| 213 |
+
byte_range: tuple[int, int]
|
| 214 |
+
segment_text: str
|
| 215 |
+
reason: ExclusionReason
|
| 216 |
+
classified_by: Classifier
|
| 217 |
+
classified_at: str = "" # ISO 8601
|
| 218 |
+
|
| 219 |
+
|
| 220 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 221 |
+
# ORACLE β SPEC-PIPELINE-001 Part D
|
| 222 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 223 |
+
|
| 224 |
+
class PipelineStage(str, Enum):
|
| 225 |
+
S2_CLASSIFY = "S2_CLASSIFY"
|
| 226 |
+
S4_VALIDATE = "S4_VALIDATE"
|
| 227 |
+
|
| 228 |
+
|
| 229 |
+
class OracleVerdict(str, Enum):
|
| 230 |
+
TECHNICAL = "TECHNICAL"
|
| 231 |
+
NON_TECHNICAL = "NON_TECHNICAL"
|
| 232 |
+
ACCEPT_AS_IS = "ACCEPT_AS_IS"
|
| 233 |
+
REVISE = "REVISE"
|
| 234 |
+
REJECT = "REJECT"
|
| 235 |
+
|
| 236 |
+
|
| 237 |
+
@dataclass
|
| 238 |
+
class OracleReviewItem:
|
| 239 |
+
item_id: str
|
| 240 |
+
source: SourceProvenance
|
| 241 |
+
segment_text: str
|
| 242 |
+
pipeline_stage: PipelineStage
|
| 243 |
+
automated_verdict: str
|
| 244 |
+
escalation_reason: str
|
| 245 |
+
|
| 246 |
+
|
| 247 |
+
@dataclass
|
| 248 |
+
class OracleDecision:
|
| 249 |
+
item_id: str
|
| 250 |
+
decision: OracleVerdict
|
| 251 |
+
revised_example: Optional[FrameExample] = None
|
| 252 |
+
exclusion_reason: Optional[ExclusionReason] = None
|
| 253 |
+
notes: str = ""
|
| 254 |
+
decided_at: str = ""
|
| 255 |
+
decided_by: str = "Devon Generally"
|