#!/usr/bin/env python3
"""Update MCP stages based on ruthless evaluation results."""

import json
from datetime import datetime

# Load current state
with open('/Users/jakeshore/.clawdbot/workspace/mcp-command-center/state.json', 'r') as f:
    state = json.load(f)

# Evaluation results mapped to state.json stages:
# Eval Stage → State Stage
# 9 (Production) → 11 (Edge Case Testing) - has passing tests
# 8 (Integration Ready) → 8 (Integration Complete) - tools + apps, no tests
# 7 (Has Apps) → 7 (UI Apps Built)
# 5 (Tools Work) → 6 (Core Tools Built)
# 4 (Compiles) → 5 (Server Scaffolded)
# 3 (Broken) → 5 but flagged
# 1 (Dead) → 1 (Identified)

stage_corrections = {
    # Stage 9 → 11 (Production ready with tests)
    "GoHighLevel MCP": 11,
    "gohighlevel": 11,
    
    # Stage 8 → 8 (Integration complete, no tests)
    "manim-mcp": 8,
    "manim": 8,
    "Meta Ads MCP": 8,
    "meta-ads": 8,
    "Twilio MCP": 8,
    "twilio": 8,
    "Google Ads MCP": 8,
    "google-ads": 8,
    
    # Stage 7 → 7 (Has apps)
    "CloseBot MCP": 7,
    "closebot": 7,
    "Google Console MCP": 7,
    "google-console": 7,
    
    # Stage 5 → 6 (Tools work)
    "Competitor Research MCP": 6,
    "competitor-research": 6,
    "Acuity Scheduling": 6,
    "BambooHR": 6,
    "Basecamp": 6,
    "BigCommerce": 6,
    "Brevo": 6,
    "Calendly": 6,
    "ClickUp": 6,
    "Close CRM": 6,
    "Clover": 6,
    "Constant Contact": 6,
    "Pipedrive": 6,
    "Rippling": 6,
    "ServiceTitan": 6,
    "Squarespace": 6,
    "Toast": 6,
    "TouchBistro": 6,
    "Trello": 6,
    "Wave": 6,
    "Wrike": 6,
    "Zendesk": 6,
    "FieldEdge": 6,
    "Freshdesk": 6,
    "Housecall Pro": 6,
    "Mailchimp": 6,
    
    # Stage 4 → 5 (Compiles only)
    "FreshBooks": 5,
    "Gusto": 5,
    "Help Scout": 5,
    "Jobber": 5,
    "Keap": 5,
    "Lightspeed": 5,
    
    # Stage 1 → 1 (Dead/concept)
    "Reonomy MCP": 1,
    "reonomy": 1,
}

# Update MCPs
updated = []
for mcp in state.get('mcps', []):
    name = mcp.get('name', '')
    mcp_id = mcp.get('id', '')
    old_stage = mcp.get('stage', 0)
    
    new_stage = stage_corrections.get(name) or stage_corrections.get(mcp_id) or old_stage
    
    if new_stage != old_stage:
        updated.append(f"{name}: {old_stage} → {new_stage}")
        mcp['stage'] = new_stage
        mcp['stageNote'] = f"Downgraded by ruthless eval {datetime.now().strftime('%Y-%m-%d')}"

state['lastUpdated'] = datetime.utcnow().isoformat() + 'Z'
state['updatedBy'] = 'ruthless-evaluation-agents'

# Save
with open('/Users/jakeshore/.clawdbot/workspace/mcp-command-center/state.json', 'w') as f:
    json.dump(state, f, indent=2)

print(f"Updated {len(updated)} MCPs:")
for u in updated:
    print(f"  {u}")
