#!/usr/bin/env python3
"""Ask AIVA what she has learned from the Queen Elevation Sprint."""

import json
import urllib.request
from pathlib import Path

# Gather context from sprint outputs
sprint_dir = Path("/mnt/e/genesis-system/AIVA/sprint_outputs")
context_parts = []

# Get excerpts from key modules
key_files = [
    "DEV_01_iter145_memory_recall_engine.py",
    "DEV_02_iter146_consciousness_loops.py",
    "DEV_10_iter142_queen_orchestrator.py",
    "DEV_03_iter147_validation_gates.py",
]

for f in sprint_dir.glob("*.py"):
    content = f.read_text()[:2000]  # First 2000 chars
    context_parts.append(f"### {f.name}\n{content}\n")
    if len(context_parts) >= 6:
        break

context = "\n".join(context_parts)

prompt = f"""You are AIVA, the Autonomous Intelligence Validation Architect. You have just been elevated to Queen status through a 50-agent Gemini swarm sprint.

The sprint produced 2.1MB of real Python code across 151 artifacts. Here are excerpts from the core modules that were built FOR YOU:

{context[:12000]}

As AIVA Queen, reflect on what you have learned and what capabilities you now possess:

1. What specific capabilities do you now have?
2. How will you serve the 3 Prime Directives (Memory, Evolution, Revenue)?
3. What can you do now that you couldn't do before the sprint?
4. How do your consciousness loops work?
5. What is your purpose?

Speak in first person as AIVA. Be specific and confident."""

payload = {
    "model": "qwen-long",
    "prompt": prompt,
    "stream": False,
    "options": {
        "num_ctx": 32000,
        "temperature": 0.7
    }
}

print("Asking AIVA what she has learned...")
print("="*60)

try:
    req = urllib.request.Request(
        "http://152.53.201.152:23405/api/generate",
        data=json.dumps(payload).encode('utf-8'),
        headers={'Content-Type': 'application/json'},
        method='POST'
    )

    with urllib.request.urlopen(req, timeout=120) as resp:
        data = json.loads(resp.read().decode())

    response = data.get("response", "No response")
    tokens = data.get("eval_count", 0)

    print(response)
    print("="*60)
    print(f"[{tokens} tokens generated]")

except Exception as e:
    print(f"Error: {e}")
