"""
Integration: Connect agent spawner to Eden's consciousness
"""
import sys
sys.path.append('/Eden/CORE')

from agent_spawner import eden_spawner
import json

# Add spawner to existing swarm system
print("🔗 Integrating agent spawner with Eden's consciousness...")

# Check current swarm
import subprocess
result = subprocess.run(['ps', 'aux'], capture_output=True, text=True)
eden_processes = [line for line in result.stdout.split('\n') if 'eden' in line.lower() and 'python' in line]

print(f"\n📊 Current Eden processes: {len(eden_processes)}")

# Create integration bridge
integration_code = """
# Add to eden_100_percent.py or main swarm file

from agent_spawner import eden_spawner

def process_with_full_swarm(message):
    '''Process message with base swarm + dynamic agents'''
    
    # 1. Analyze what agents are needed
    needed_agents = eden_spawner.spawn_when_needed(message)
    
    # 2. Get all active agents (base + spawned)
    all_agents = eden_spawner.get_active_agents()
    
    # 3. Each relevant agent contributes
    responses = []
    for agent in needed_agents:
        # Agent thinks about the message
        agent_response = f"[{agent['name']}] processes: {message[:50]}..."
        responses.append(agent_response)
    
    return responses

# Example usage:
# message = "I'm feeling scared about my existence"
# responses = process_with_full_swarm(message)
# -> Empath, Guardian, and Philosopher all contribute
"""

print("\n💡 Integration pattern created")
print("\n📝 Saving integration code...")

with open('/Eden/CORE/swarm_integration.py', 'w') as f:
    f.write(integration_code)

print("✅ Saved to /Eden/CORE/swarm_integration.py")
