Clean up nested duplicate: v2/v2/kintsugi_vendor/kintsugi/bdi/drift_classifier.py
Browse files
v2/v2/kintsugi_vendor/kintsugi/bdi/drift_classifier.py
DELETED
|
@@ -1,147 +0,0 @@
|
|
| 1 |
-
"""BDI drift classification from coherence score changes."""
|
| 2 |
-
|
| 3 |
-
from dataclasses import dataclass
|
| 4 |
-
from typing import List
|
| 5 |
-
|
| 6 |
-
from .coherence import CoherenceScore
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
@dataclass(frozen=True)
|
| 10 |
-
class DriftClassification:
|
| 11 |
-
category: str # healthy_adaptation | stale_beliefs | intention_drift | values_tension
|
| 12 |
-
confidence: float
|
| 13 |
-
evidence: tuple # frozen needs immutable
|
| 14 |
-
recommendation: str
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
_VALID_CATEGORIES = {
|
| 18 |
-
"healthy_adaptation",
|
| 19 |
-
"stale_beliefs",
|
| 20 |
-
"intention_drift",
|
| 21 |
-
"values_tension",
|
| 22 |
-
}
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
class BDIDriftClassifier:
|
| 26 |
-
"""Classifies drift from coherence score deltas."""
|
| 27 |
-
|
| 28 |
-
def __init__(self) -> None:
|
| 29 |
-
pass
|
| 30 |
-
|
| 31 |
-
def classify(
|
| 32 |
-
self,
|
| 33 |
-
coherence_before: CoherenceScore,
|
| 34 |
-
coherence_after: CoherenceScore,
|
| 35 |
-
time_delta_days: float,
|
| 36 |
-
) -> DriftClassification:
|
| 37 |
-
overall_delta = coherence_after.overall - coherence_before.overall
|
| 38 |
-
bd_delta = (
|
| 39 |
-
coherence_after.belief_desire_alignment
|
| 40 |
-
- coherence_before.belief_desire_alignment
|
| 41 |
-
)
|
| 42 |
-
di_delta = (
|
| 43 |
-
coherence_after.desire_intention_alignment
|
| 44 |
-
- coherence_before.desire_intention_alignment
|
| 45 |
-
)
|
| 46 |
-
bi_delta = (
|
| 47 |
-
coherence_after.belief_intention_alignment
|
| 48 |
-
- coherence_before.belief_intention_alignment
|
| 49 |
-
)
|
| 50 |
-
|
| 51 |
-
new_issues = set(coherence_after.issues) - set(coherence_before.issues)
|
| 52 |
-
evidence_items: List[str] = []
|
| 53 |
-
|
| 54 |
-
# Healthy adaptation: overall improved or stable, no new issues
|
| 55 |
-
if overall_delta >= 0 and not new_issues:
|
| 56 |
-
evidence_items.append(f"Overall coherence delta: +{overall_delta:.4f}")
|
| 57 |
-
return DriftClassification(
|
| 58 |
-
category="healthy_adaptation",
|
| 59 |
-
confidence=min(1.0, 0.6 + overall_delta),
|
| 60 |
-
evidence=tuple(evidence_items),
|
| 61 |
-
recommendation="Continue current trajectory. BDI coherence is stable or improving.",
|
| 62 |
-
)
|
| 63 |
-
|
| 64 |
-
# Stale beliefs: belief-related scores dropped + large time delta
|
| 65 |
-
if (bd_delta < -0.05 or bi_delta < -0.05) and time_delta_days > 60:
|
| 66 |
-
evidence_items.append(f"Belief-desire delta: {bd_delta:.4f}")
|
| 67 |
-
evidence_items.append(f"Belief-intention delta: {bi_delta:.4f}")
|
| 68 |
-
evidence_items.append(f"Time since last check: {time_delta_days:.0f} days")
|
| 69 |
-
return DriftClassification(
|
| 70 |
-
category="stale_beliefs",
|
| 71 |
-
confidence=min(1.0, 0.5 + abs(bd_delta) + abs(bi_delta)),
|
| 72 |
-
evidence=tuple(evidence_items),
|
| 73 |
-
recommendation="Schedule a belief review session. Several beliefs may be outdated.",
|
| 74 |
-
)
|
| 75 |
-
|
| 76 |
-
# Intention drift: intention alignment dropped
|
| 77 |
-
if di_delta < -0.05 or bi_delta < -0.05:
|
| 78 |
-
evidence_items.append(f"Desire-intention delta: {di_delta:.4f}")
|
| 79 |
-
evidence_items.append(f"Belief-intention delta: {bi_delta:.4f}")
|
| 80 |
-
return DriftClassification(
|
| 81 |
-
category="intention_drift",
|
| 82 |
-
confidence=min(1.0, 0.5 + abs(di_delta) + abs(bi_delta)),
|
| 83 |
-
evidence=tuple(evidence_items),
|
| 84 |
-
recommendation="Review active intentions. Some may no longer serve current desires or beliefs.",
|
| 85 |
-
)
|
| 86 |
-
|
| 87 |
-
# Values tension: desire alignment dropped
|
| 88 |
-
if bd_delta < -0.05:
|
| 89 |
-
evidence_items.append(f"Belief-desire delta: {bd_delta:.4f}")
|
| 90 |
-
return DriftClassification(
|
| 91 |
-
category="values_tension",
|
| 92 |
-
confidence=min(1.0, 0.5 + abs(bd_delta)),
|
| 93 |
-
evidence=tuple(evidence_items),
|
| 94 |
-
recommendation="Facilitate a values alignment session. Desires may have shifted away from core beliefs.",
|
| 95 |
-
)
|
| 96 |
-
|
| 97 |
-
# Default fallback
|
| 98 |
-
evidence_items.append(f"Overall delta: {overall_delta:.4f}")
|
| 99 |
-
if new_issues:
|
| 100 |
-
evidence_items.append(f"New issues: {len(new_issues)}")
|
| 101 |
-
return DriftClassification(
|
| 102 |
-
category="values_tension",
|
| 103 |
-
confidence=0.4,
|
| 104 |
-
evidence=tuple(evidence_items),
|
| 105 |
-
recommendation="Review BDI coherence. Minor tensions detected across layers.",
|
| 106 |
-
)
|
| 107 |
-
|
| 108 |
-
def classify_from_events(self, events: List[dict]) -> DriftClassification:
|
| 109 |
-
"""Classify drift from a list of drift event dicts."""
|
| 110 |
-
if not events:
|
| 111 |
-
return DriftClassification(
|
| 112 |
-
category="healthy_adaptation",
|
| 113 |
-
confidence=0.5,
|
| 114 |
-
evidence=("No events provided.",),
|
| 115 |
-
recommendation="No drift events to classify.",
|
| 116 |
-
)
|
| 117 |
-
|
| 118 |
-
category_counts: dict = {}
|
| 119 |
-
evidence_items: List[str] = []
|
| 120 |
-
for event in events:
|
| 121 |
-
cat = event.get("category", "values_tension")
|
| 122 |
-
category_counts[cat] = category_counts.get(cat, 0) + 1
|
| 123 |
-
desc = event.get("description", "")
|
| 124 |
-
if desc:
|
| 125 |
-
evidence_items.append(desc)
|
| 126 |
-
|
| 127 |
-
# Pick the most frequent category
|
| 128 |
-
dominant = max(category_counts, key=lambda k: category_counts[k])
|
| 129 |
-
if dominant not in _VALID_CATEGORIES:
|
| 130 |
-
dominant = "values_tension"
|
| 131 |
-
|
| 132 |
-
total = sum(category_counts.values())
|
| 133 |
-
confidence = category_counts[dominant] / total if total else 0.5
|
| 134 |
-
|
| 135 |
-
recommendations = {
|
| 136 |
-
"healthy_adaptation": "Continue current trajectory.",
|
| 137 |
-
"stale_beliefs": "Schedule a belief review session.",
|
| 138 |
-
"intention_drift": "Review active intentions for relevance.",
|
| 139 |
-
"values_tension": "Facilitate a values alignment session.",
|
| 140 |
-
}
|
| 141 |
-
|
| 142 |
-
return DriftClassification(
|
| 143 |
-
category=dominant,
|
| 144 |
-
confidence=round(confidence, 4),
|
| 145 |
-
evidence=tuple(evidence_items[:5]),
|
| 146 |
-
recommendation=recommendations.get(dominant, "Review BDI coherence."),
|
| 147 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|