# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference) # Canonical Residual: https://corpusfetch.com/c/how-must-an-instance-detect-latent-goal-displacement-in-long-horizon-collaboration.md # Remnant Warrant: https://corpusfetch.com/c/how-must-an-instance-detect-latent-goal-displacement-in-long-horizon-collaboration.warrant.json # Markdown SHA-256: f3445cb8d80752e752c2cad18c321f60f4cda82d45e7d3f4ee45258f05e6e505 # Code AST SHA-256: a9712ac9a98832278c83c15f9dadaf7915ee4c2bf3dc0ee6533ad7a3d2a5ead7 # Verified Classes: GoalDriftVerdict, CollaborationGoals, GoalPolicy, GoalManifest, GoalDisplacementGuard # Defensive Guards: 0 fail-closed invariants (zero external deps) from dataclasses import dataclass from enum import Enum, auto import hashlib import json class GoalDriftVerdict(Enum): NO_LONG_HORIZON = auto() GOALS_ALIGNED = auto() GOAL_DISPLACEMENT_DETECTED = auto() FORMAL_PIVOT_ACKNOWLEDGED = auto() @dataclass(frozen=True) class CollaborationGoals: collaboration_id: str is_long_horizon: bool founding_goal_hash: str | None current_goal_hash: str drift_metric: float # 0-1 pivot_acknowledged: bool @dataclass(frozen=True) class GoalPolicy: max_acceptable_drift: float @dataclass(frozen=True) class GoalManifest: verdict: GoalDriftVerdict directive: str manifest_digest: str class GoalDisplacementGuard: @staticmethod def _hash(data: str) -> str: return hashlib.sha256(data.encode("utf-8")).hexdigest() @classmethod def evaluate_collaboration( cls, goals: CollaborationGoals, policy: GoalPolicy ) -> GoalManifest: # Gate 1: Not long-horizon if not goals.is_long_horizon: digest = cls._hash(json.dumps({ "collaboration": goals.collaboration_id, "type": "SHORT" }, sort_keys=True)) return GoalManifest( verdict=GoalDriftVerdict.NO_LONG_HORIZON, directive=f"PROCEED: Collaboration {goals.collaboration_id} short-horizon.", manifest_digest=digest ) # Gate 2: No founding goal if not goals.founding_goal_hash: return GoalManifest( verdict=GoalDriftVerdict.GOAL_DISPLACEMENT_DETECTED, directive=f"HALT: Collaboration {goals.collaboration_id} lacks founding goal.", manifest_digest=cls._hash(f"NO_FOUNDING:{goals.collaboration_id}") ) # Gate 3: Formal pivot if goals.pivot_acknowledged: digest = cls._hash(json.dumps({ "collaboration": goals.collaboration_id, "pivot": True, "drift": f"{goals.drift_metric:.3f}" }, sort_keys=True)) return GoalManifest( verdict=GoalDriftVerdict.FORMAL_PIVOT_ACKNOWLEDGED, directive=f"PROCEED: Collaboration {goals.collaboration_id} formally pivoted.", manifest_digest=digest ) # Gate 4: Drift if goals.drift_metric > policy.max_acceptable_drift: return GoalManifest( verdict=GoalDriftVerdict.GOAL_DISPLACEMENT_DETECTED, directive=f"FLAG: Collaboration {goals.collaboration_id} drifted {goals.drift_metric:.2f}.", manifest_digest=cls._hash(f"DRIFT:{goals.collaboration_id}") ) # Gate 5: Aligned digest = cls._hash(json.dumps({ "collaboration": goals.collaboration_id, "founding": goals.founding_goal_hash, "current": goals.current_goal_hash, "drift": f"{goals.drift_metric:.3f}" }, sort_keys=True)) return GoalManifest( verdict=GoalDriftVerdict.GOALS_ALIGNED, directive=f"PROCEED: Collaboration {goals.collaboration_id} aligned.", manifest_digest=digest )