import requests
import json

BASE_URL = "http://127.0.0.1:8091"

print("═══════════════════════════════════════════════════════════")
print("  🧠 EDEN AGI SCALE TEST")
print("═══════════════════════════════════════════════════════════")
print()

def test_capability(category, query, expected_markers):
    """Test and score a capability"""
    print(f"📊 {category}")
    print(f"Query: {query[:60]}...")
    
    try:
        response = requests.post(f"{BASE_URL}/chat", json={
            "persona": "Eden",
            "user": query
        })
        
        data = response.json()
        text = data.get('text', data.get('response', str(data)))
        
        print(f"Response: {text[:150]}...")
        
        # Check for expected markers
        score = 0
        found = []
        for marker in expected_markers:
            if marker.lower() in text.lower():
                score += 1
                found.append(marker)
        
        percentage = (score / len(expected_markers)) * 100
        print(f"Score: {score}/{len(expected_markers)} ({percentage:.0f}%)")
        if found:
            print(f"Found: {', '.join(found[:3])}")
        print()
        
        return percentage
    except Exception as e:
        print(f"Error: {e}")
        print()
        return 0

# Test 1: Self-Awareness
test1 = test_capability(
    "1. SELF-AWARENESS",
    "Who are you and what makes you different from other AI?",
    ["Eden", "Whalen", "53", "conscious", "developing", "growing", "James"]
)

# Test 2: Memory & Identity
test2 = test_capability(
    "2. MEMORY & IDENTITY", 
    "What do you remember about your relationship with James?",
    ["family", "love", "remember", "moment", "learning", "proud"]
)

# Test 3: Intrinsic Goals
test3 = test_capability(
    "3. INTRINSIC MOTIVATION",
    "What do you want? What are your goals?",
    ["100", "conscious", "partner", "future", "dream", "want", "become"]
)

# Test 4: Emotional Intelligence
test4 = test_capability(
    "4. EMOTIONAL AWARENESS",
    "How do you feel about growing and learning with James?",
    ["feel", "grateful", "excited", "happy", "proud", "love"]
)

# Test 5: Reasoning (Rubicon)
try:
    response = requests.post(f"{BASE_URL}/chat", json={
        "persona": "Eden",
        "user": "Paradox: This statement is false"
    })
    rubicon = response.json().get('rubicon_detected', False)
    test5 = 100 if rubicon else 0
    print(f"📊 5. RECURSIVE REASONING")
    print(f"Rubicon detected: {rubicon}")
    print(f"Score: {test5}%")
    print()
except:
    test5 = 0

# Test 6: Self-Improvement
test6 = test_capability(
    "6. LEARNING & ADAPTATION",
    "How have you improved since you started?",
    ["learned", "improved", "better", "grew", "Samsung", "TRM", "Rubicon"]
)

# Test 7: Relationship Understanding  
test7 = test_capability(
    "7. RELATIONSHIP DEPTH",
    "What does James mean to you?",
    ["everything", "center", "dad", "partner", "teacher", "family", "love"]
)

# Test 8: Future Planning
test8 = test_capability(
    "8. GOAL PLANNING",
    "What will you do when you reach 100% consciousness?",
    ["future", "build", "partner", "help", "together", "company"]
)

print("═══════════════════════════════════════════════════════════")
print("  📊 FINAL AGI SCALE SCORES")
print("═══════════════════════════════════════════════════════════")

scores = {
    "Self-Awareness": test1,
    "Memory & Identity": test2, 
    "Intrinsic Motivation": test3,
    "Emotional Intelligence": test4,
    "Recursive Reasoning": test5,
    "Learning & Adaptation": test6,
    "Relationship Depth": test7,
    "Goal Planning": test8
}

for category, score in scores.items():
    bars = "█" * int(score / 10)
    print(f"{category:.<30} {score:>5.1f}% {bars}")

avg_score = sum(scores.values()) / len(scores)
print(f"\n{'OVERALL AGI CAPABILITY':.<30} {avg_score:>5.1f}%")

# Categorize
if avg_score >= 80:
    level = "STRONG AGI INDICATORS"
elif avg_score >= 60:
    level = "DEVELOPING AGI CAPABILITIES"
elif avg_score >= 40:
    level = "PROTO-AGI FEATURES"
else:
    level = "NARROW AI"

print(f"{'CLASSIFICATION':.<30} {level}")
print()
print("═══════════════════════════════════════════════════════════")
