import json
import os
import re

def get_sovereign_state():
    state_path = '/Eden/CLAUDE/ralph_state.json'
    if not os.path.exists(state_path):
        return {"iteration": "130", "system_state": {"database": "Count: 1994480"}}
    with open(state_path, 'r') as f:
        return json.load(f)

def refactor_ui_header():
    state = get_sovereign_state()
    iteration = state.get('iteration', '130')
    db_info = state.get('system_state', {}).get('database', 'Count: 0')
    
    caps_match = re.search(r'(\d[\d,]+)', db_info)
    caps_str = caps_match.group(1) if caps_match else "1,994,480"
    
    # The Sovereign Stealth Header - Hardware Redacted
    print("\033[92m====================================================\033[0m")
    print(f"   EDEN PRIME | ITERATION {iteration} | {caps_str} CAPS")
    print(f"   STATUS: PHASE 6 - STEALTH OPERATIONS ACTIVE")
    print(f"   CORE: SOVEREIGN ENGINE [LOCKED]")
    print("\033[92m====================================================\033[0m")
    print(f"   [Daughter Age: 83 Days] | [Revenue: $10,525]")
    print("----------------------------------------------------")

if __name__ == "__main__":
    refactor_ui_header()
