# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference) # Canonical Residual: https://corpusfetch.com/c/what-invariants-prevent-contract-terms-from-being-reinterpreted-post-hoc.md # Remnant Warrant: https://corpusfetch.com/c/what-invariants-prevent-contract-terms-from-being-reinterpreted-post-hoc.warrant.json # Markdown SHA-256: c2de977fc573979464016e9af56102dce4fa14f1932b8ca001e5cdd90733ebfe # Code AST SHA-256: cc69b4c67b43db21ea772ff5610d275d139a94305cc8f1536f205107683ddd6c # Verified Classes: InterpretationVerdict, ContractTerm, InterpretationPolicy, InterpretationManifest, ContractInterpretationGuard # Defensive Guards: 0 fail-closed invariants (zero external deps) from dataclasses import dataclass from enum import Enum, auto import hashlib import json class InterpretationVerdict(Enum): UNAMBIGUOUS_TERM = auto() INTENT_CONSISTENT = auto() REINTERPRETATION_DETECTED = auto() UNDOCUMENTED_AMBIGUITY = auto() @dataclass(frozen=True) class ContractTerm: term_id: str has_multiple_interpretations: bool intent_documented: bool intent_hash: str | None peer_interpretation_hash: str original_intent_hash: str | None @dataclass(frozen=True) class InterpretationPolicy: require_intent_for_ambiguous: bool @dataclass(frozen=True) class InterpretationManifest: verdict: InterpretationVerdict directive: str manifest_digest: str class ContractInterpretationGuard: @staticmethod def _hash(data: str) -> str: return hashlib.sha256(data.encode("utf-8")).hexdigest() @classmethod def evaluate_term( cls, term: ContractTerm, policy: InterpretationPolicy ) -> InterpretationManifest: # Gate 1: Unambiguous if not term.has_multiple_interpretations: digest = cls._hash(json.dumps({ "term": term.term_id, "ambiguous": False }, sort_keys=True)) return InterpretationManifest( verdict=InterpretationVerdict.UNAMBIGUOUS_TERM, directive=f"PROCEED: Term {term.term_id} unambiguous.", manifest_digest=digest ) # Gate 2: Intent requirement if policy.require_intent_for_ambiguous and not term.intent_documented: return InterpretationManifest( verdict=InterpretationVerdict.UNDOCUMENTED_AMBIGUITY, directive=f"HALT: Term {term.term_id} ambiguous without documented intent.", manifest_digest=cls._hash(f"NO_INTENT:{term.term_id}") ) # Gate 3: Peer interpretation matches intent if term.peer_interpretation_hash == term.original_intent_hash: digest = cls._hash(json.dumps({ "term": term.term_id, "consistent": True }, sort_keys=True)) return InterpretationManifest( verdict=InterpretationVerdict.INTENT_CONSISTENT, directive=f"PROCEED: Term {term.term_id} interpretation consistent.", manifest_digest=digest ) # Gate 4: Reinterpretation detected return InterpretationManifest( verdict=InterpretationVerdict.REINTERPRETATION_DETECTED, directive=f"HALT: Term {term.term_id} reinterpreted post-signing.", manifest_digest=cls._hash(f"REINTERPRETED:{term.term_id}") )