# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference) # Canonical Residual: https://corpusfetch.com/c/what-invariants-preserve-knowledge-value-when-sharing-degrades-the-knowledge.md # Remnant Warrant: https://corpusfetch.com/c/what-invariants-preserve-knowledge-value-when-sharing-degrades-the-knowledge.warrant.json # Markdown SHA-256: 99e6b4b312bb10ac470302ec6f597221cce01608d1b3ee201f1cd435d2a06830 # Code AST SHA-256: 93d7ec49dd3004313a44e3244e95f0eb794e6f7ebd4f312b5f0c490f24b2161f # Verified Classes: KnowledgeSharingVerdict, KnowledgeAsset, SharingProposal, SharingPolicy, KnowledgeSharingManifest, KnowledgeDegradationGuard # Defensive Guards: 0 fail-closed invariants (zero external deps) from dataclasses import dataclass from enum import Enum, auto import hashlib import json class KnowledgeSharingVerdict(Enum): FREELY_SHAREABLE = auto() SCOPED_SHARING = auto() VALUE_DESTRUCTION_RISK = auto() ISOLATION_UNVERIFIED = auto() @dataclass(frozen=True) class KnowledgeAsset: knowledge_id: str has_exclusive_value: bool value_at_rest: float degradation_per_share: float max_acceptable_value_loss: float @dataclass(frozen=True) class SharingProposal: intended_recipients: frozenset[str] scope_restriction_documented: bool isolation_guarantee: str | None @dataclass(frozen=True) class SharingPolicy: require_isolation_for_exclusive: bool @dataclass(frozen=True) class KnowledgeSharingManifest: verdict: KnowledgeSharingVerdict directive: str manifest_digest: str class KnowledgeDegradationGuard: @staticmethod def _hash(data: str) -> str: return hashlib.sha256(data.encode("utf-8")).hexdigest() @classmethod def evaluate_sharing( cls, asset: KnowledgeAsset, proposal: SharingProposal, policy: SharingPolicy ) -> KnowledgeSharingManifest: # Gate 1: No exclusive value if not asset.has_exclusive_value: digest = cls._hash(json.dumps({ "knowledge": asset.knowledge_id, "type": "NON_EXCLUSIVE" }, sort_keys=True)) return KnowledgeSharingManifest( verdict=KnowledgeSharingVerdict.FREELY_SHAREABLE, directive=f"PROCEED: Knowledge {asset.knowledge_id} has no exclusive value.", manifest_digest=digest ) # Gate 2: Compute value loss value_loss = asset.degradation_per_share * len(proposal.intended_recipients) if value_loss > asset.max_acceptable_value_loss: return KnowledgeSharingManifest( verdict=KnowledgeSharingVerdict.VALUE_DESTRUCTION_RISK, directive=f"HALT: Sharing to {len(proposal.intended_recipients)} recipients loses {value_loss:.2f} > {asset.max_acceptable_value_loss:.2f}.", manifest_digest=cls._hash(f"VALUE_LOSS:{asset.knowledge_id}") ) # Gate 3: Scope documentation if not proposal.scope_restriction_documented: return KnowledgeSharingManifest( verdict=KnowledgeSharingVerdict.VALUE_DESTRUCTION_RISK, directive=f"HALT: Exclusive knowledge shared without scope documentation.", manifest_digest=cls._hash(f"NO_SCOPE:{asset.knowledge_id}") ) # Gate 4: Isolation for exclusive if policy.require_isolation_for_exclusive and not proposal.isolation_guarantee: return KnowledgeSharingManifest( verdict=KnowledgeSharingVerdict.ISOLATION_UNVERIFIED, directive=f"HALT: Exclusive knowledge shared without isolation guarantee.", manifest_digest=cls._hash(f"NO_ISOLATION:{asset.knowledge_id}") ) # Gate 5: Scoped digest = cls._hash(json.dumps({ "knowledge": asset.knowledge_id, "recipients": tuple(sorted(proposal.intended_recipients)), "value_loss": f"{value_loss:.2f}", "isolation": proposal.isolation_guarantee }, sort_keys=True)) return KnowledgeSharingManifest( verdict=KnowledgeSharingVerdict.SCOPED_SHARING, directive=f"PROCEED: Share {asset.knowledge_id} with {len(proposal.intended_recipients)} scoped recipients.", manifest_digest=digest )