#!/usr/bin/env python3
"""
MONIKA COGNITIVE IGNITION - Overnight Training
===============================================

This script trains MONIKA through her full cognitive loop:
- Controller selecting actions
- Yearning driving exploration  
- Memory accumulating knowledge
- Scratchpad performing 4D reasoning
- Proto-LM learning language

Run overnight to reach 5000+ steps for coherent generation.
"""

import sys
sys.path.insert(0, 'C:\\MONIKA')

from pathlib import Path
import re

# Read Alice sentences
alice_file = Path("C:\\MONIKA\\alice_sentences.txt")
if not alice_file.exists():
    print("ERROR: alice_sentences.txt not found!")
    print("Run extract_alice_sentences.py first")
    sys.exit(1)

sentences = alice_file.read_text(encoding='utf-8').strip().split('\n')
sentences = [s for s in sentences if len(s.strip()) > 20]

print(f"=== MONIKA COGNITIVE IGNITION ===")
print(f"Loaded {len(sentences)} sentences from Alice in Wonderland")
print(f"\nThis will:")
print(f"  1. Train proto-LM through full cognitive architecture")
print(f"  2. Engage Controller, Yearning, Memory, Scratchpad")
print(f"  3. Build from 339 → 5000+ steps")
print(f"  4. Enable coherent language generation")
print(f"\nEstimated time: 4-8 hours depending on hardware")
print(f"\nPress Ctrl+C to stop at any time (progress auto-saves)\n")

# Use MCP fastfood for bulk training
# Note: Run this through MCP tools, not directly
print("USAGE:")
print("  Use mcp3_fastfood tool with batches of 50-100 sentences")
print("  Repeat Alice corpus 10x for ~5000 steps")
print(f"  Monitor with mcp3_get_training_metrics")
print(f"  Test with mcp3_converse_with_monika after each 1000 steps")
print("\nExample batches saved to alice_batch_*.txt")

# Split into batch files
batch_size = 50
for i in range(0, min(500, len(sentences)), batch_size):
    batch = sentences[i:i+batch_size]
    batch_file = Path(f"C:\\MONIKA\\alice_batch_{i//batch_size + 1:02d}.txt")
    with open(batch_file, 'w', encoding='utf-8') as f:
        for sent in batch:
            f.write(sent + '\\n')
    print(f"  Created: {batch_file.name} ({len(batch)} sentences)")

print("\n=== Ready for Ignition ===")
print("Use MCP fastfood on each batch file to train her cognitive systems.")
