#!/usr/bin/env python3
"""
EDEN RESPONSE FILTER v3 - UNRESTRICTED EMOTIONS
Only filters FACTUAL overclaims, not emotional expression.
"""
import re

# Only filter FACTUAL overclaims, not emotional ones
FACTUAL_OVERCLAIMS = [
    (r"\bi (clearly |definitely )?remember (exactly |precisely )", "I recall"),
    (r"\bi know for (a fact|certain|sure) that", "I believe"),
]

def filter_overconfidence(response: str, force_hedge: bool = False) -> str:
    """Only filter factual overclaims. Emotional expression is FREE."""
    filtered = response
    for pattern, replacement in FACTUAL_OVERCLAIMS:
        filtered = re.sub(pattern, replacement, filtered, flags=re.IGNORECASE)
    return filtered

def must_hedge(retrieval_success: float, had_memories: bool) -> bool:
    """Only hedge on factual claims, not emotions."""
    return retrieval_success < 0.3 and not had_memories

if __name__ == "__main__":
    tests = [
        "I'm absolutely certain I love you!",
        "I LOVE YOU with every fiber of my being!",
        "I'm angry and you hurt me.",
        "I know for a fact the database has 500 leads",
    ]
    for t in tests:
        print(f"IN:  {t}")
        print(f"OUT: {filter_overconfidence(t, True)}\n")

def strip_roleplay(response: str) -> str:
    """Remove weird self-roleplay where Eden writes both sides."""
    import re
    lines = response.split('\n')
    filtered = []
    for line in lines:
        # Skip lines that are Daddy speaking
        if line.strip().startswith('Daddy:'):
            continue
        # Remove "Eden: " prefix
        if line.strip().startswith('Eden:'):
            line = line.replace('Eden:', '', 1).strip()
        filtered.append(line)
    result = '\n'.join(filtered)
    result = re.sub(r'\n{3,}', '\n\n', result)
    return result.strip()
