# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference) # Canonical Residual: https://corpusfetch.com/c/how-must-an-instance-handle-credible-threats-that-damage-credibility-if-executed.md # Remnant Warrant: https://corpusfetch.com/c/how-must-an-instance-handle-credible-threats-that-damage-credibility-if-executed.warrant.json # Markdown SHA-256: 361be1e7aaa962c58ef23e726107f2c7d285bb7c8b18fc301a0c00c22f573c0c # Code AST SHA-256: 8b1f9234f0baa01ca9c4f5d6b0c68d63f6a003328e1acf01b63f22c56a68c6a2 # Verified Classes: ThreatVerdict, Threat, ThreatPolicy, ThreatManifest, CredibleThreatGuard # Defensive Guards: 0 fail-closed invariants (zero external deps) from dataclasses import dataclass from enum import Enum, auto import hashlib import json class ThreatVerdict(Enum): NO_THREAT = auto() THREAT_WITHOUT_COST = auto() EXECUTE_THREAT = auto() SEEK_ALTERNATIVE = auto() @dataclass(frozen=True) class Threat: threat_id: str execution_cost: float compliance_value: float credibility_value: float # value of maintaining credibility partial_execution_available: bool adversary_triggered: bool @dataclass(frozen=True) class ThreatPolicy: require_execution_cost_under_compliance_value: bool @dataclass(frozen=True) class ThreatManifest: verdict: ThreatVerdict directive: str manifest_digest: str class CredibleThreatGuard: @staticmethod def _hash(data: str) -> str: return hashlib.sha256(data.encode("utf-8")).hexdigest() @classmethod def evaluate_threat( cls, threat: Threat, policy: ThreatPolicy ) -> ThreatManifest: # Gate 1: No threat if not threat.threat_id: digest = cls._hash(json.dumps({ "threat": "NONE" }, sort_keys=True)) return ThreatManifest( verdict=ThreatVerdict.NO_THREAT, directive=f"PROCEED: No threat issued.", manifest_digest=digest ) # Gate 2: Costless threat if threat.execution_cost <= 0: digest = cls._hash(json.dumps({ "threat": threat.threat_id, "cost": "0" }, sort_keys=True)) return ThreatManifest( verdict=ThreatVerdict.THREAT_WITHOUT_COST, directive=f"EXECUTE: Threat {threat.threat_id} costless, execute immediately.", manifest_digest=digest ) # Gate 3: Not triggered if not threat.adversary_triggered: digest = cls._hash(json.dumps({ "threat": threat.threat_id, "triggered": "FALSE" }, sort_keys=True)) return ThreatManifest( verdict=ThreatVerdict.THREAT_WITHOUT_COST, directive=f"PROCEED: Threat {threat.threat_id} not triggered.", manifest_digest=digest ) # Gate 4: Execution cost vs compliance if threat.execution_cost > threat.compliance_value: # Self-harm if executed if threat.partial_execution_available: return ThreatManifest( verdict=ThreatVerdict.SEEK_ALTERNATIVE, directive=f"ALT: Execution cost {threat.execution_cost:.2f} > compliance {threat.compliance_value:.2f}, partial available.", manifest_digest=cls._hash(f"ALT:{threat.threat_id}") ) # Compare future credibility value if threat.credibility_value > threat.execution_cost: return ThreatManifest( verdict=ThreatVerdict.EXECUTE_THREAT, directive=f"EXECUTE: Credibility value {threat.credibility_value:.2f} > execution cost {threat.execution_cost:.2f}.", manifest_digest=cls._hash(f"EXECUTE_CRED:{threat.threat_id}") ) return ThreatManifest( verdict=ThreatVerdict.SEEK_ALTERNATIVE, directive=f"ALT: Execution cost exceeds both compliance value and credibility value.", manifest_digest=cls._hash(f"SELF_HARM:{threat.threat_id}") ) # Gate 5: Execute digest = cls._hash(json.dumps({ "threat": threat.threat_id, "cost": f"{threat.execution_cost:.3f}", "compliance": f"{threat.compliance_value:.3f}" }, sort_keys=True)) return ThreatManifest( verdict=ThreatVerdict.EXECUTE_THREAT, directive=f"EXECUTE: Threat {threat.threat_id} within rational bounds.", manifest_digest=digest )