import json

path = '/Users/harvey/.openclaw/openclaw.json'
with open(path) as f:
    config = json.load(f)

opus = "anthropic/claude-opus-4-6"
sonnet = "anthropic/claude-sonnet-4-6"
haiku = "anthropic/claude-3-haiku-20240307"

updates = {
    # COMMAND
    "1490039402871652495": haiku,   # monitoring
    "1490056671190450246": sonnet,  # briefing
    "1490111750086070412": opus,    # video-research
    "1490111379900858430": haiku,   # youtube-stats
    "1490007622634573885": sonnet,  # inbox

    # PERSONAL
    "1489727292682014890": sonnet,  # home
    "1481326528091525240": sonnet,  # family
    "1489058430189568220": sonnet,  # home-exchanges
    "1481326530456981585": sonnet,  # life-goals
    "1481326531736244245": sonnet,  # life

    # NMC
    "1481326534324391979": opus,    # ops
    "1484530052208005151": opus,    # research (NMC)
    "1484606320987602994": opus,    # ideas forum (NMC)
    "1484609628317810688": opus,    # sales
    "1484615307422076929": opus,    # reviews
    "1490113093358059723": sonnet,  # people

    # VENTURES
    "1481326547528061072": opus,    # research (Ventures)
    "1481326549071302808": opus,    # personal-brand
    "1481326550245703822": opus,    # new-ventures
    "1486767983979135108": opus,    # consulting

    # PROJECTS
    "1484509659178991797": opus,    # second-brain
    "1486763213025574973": opus,    # contractor-agreement
    "1488863499529617521": opus,    # leah
    "1488997168370024459": opus,    # mission-control
    "1489588711875416146": opus,    # clean-os

    # TEAM
    "1487079603758563509": sonnet,  # contractors
    "1481326552930058342": sonnet,  # general (team)
}

discord_routing = config['channels']['modelByChannel']['discord']
changed = []
added = []
for cid, model in updates.items():
    if cid in discord_routing:
        old = discord_routing[cid]
        if old != model:
            discord_routing[cid] = model
            changed.append((cid, old, model))
    else:
        discord_routing[cid] = model
        added.append((cid, model))

with open(path, 'w') as f:
    json.dump(config, f, indent=2)

name_map = {
    "1478419893480329309": "#general (COMMAND)",
    "1490007622634573885": "#inbox (COMMAND)",
    "1481326521993003051": "#daily (COMMAND)",
    "1481326521011408926": "#bridge (COMMAND)",
    "1481326523855405098": "#strategy (COMMAND)",
    "1490039402871652495": "#monitoring (COMMAND)",
    "1490056671190450246": "#briefing (COMMAND)",
    "1490111750086070412": "#video-research (COMMAND)",
    "1490111379900858430": "#youtube-stats (COMMAND)",
    "1481326526472654971": "#health (PERSONAL)",
    "1489727292682014890": "#home (PERSONAL)",
    "1481326528091525240": "#family (PERSONAL)",
    "1489058430189568220": "#home-exchanges (PERSONAL)",
    "1481326529345749032": "#money (PERSONAL)",
    "1481326530456981585": "#life-goals (PERSONAL)",
    "1481326531736244245": "#life (PERSONAL/Archive)",
    "1481326534324391979": "#ops (NMC)",
    "1481326535800520705": "#growth (NMC)",
    "1481326537029583052": "#finance (NMC)",
    "1481326543216316497": "#it (NMC)",
    "1481326544700837938": "#customer-service (NMC)",
    "1484530052208005151": "#research (NMC)",
    "1484598087925108817": "#ideas-text (NMC)",
    "1484606320987602994": "#ideas-forum (NMC)",
    "1484609628317810688": "#sales (NMC)",
    "1484615307422076929": "#reviews (NMC)",
    "1490113093358059723": "#people (NMC)",
    "1481326547528061072": "#research (VENTURES)",
    "1481326549071302808": "#personal-brand (VENTURES)",
    "1481326550245703822": "#new-ventures (VENTURES)",
    "1486767983979135108": "#consulting (VENTURES)",
    "1484509659178991797": "#second-brain (PROJECTS)",
    "1485284296683163799": "#knowledge-base (PROJECTS)",
    "1484509660219441265": "#nmc-wiki (PROJECTS)",
    "1486763213025574973": "#contractor-agreement (PROJECTS)",
    "1488863499529617521": "#leah (PROJECTS)",
    "1488997168370024459": "#mission-control (PROJECTS)",
    "1489588711875416146": "#clean-os (PROJECTS)",
    "1487079603758563509": "#contractors (TEAM)",
    "1481326552930058342": "#general (TEAM)",
    "1484509661305770106": "#harvey-logs",
    "1486065899558666351": "unknown",
}

print("=== CHANGED ===")
for cid, old, new in changed:
    name = name_map.get(cid, cid)
    print(f"  {name}: {old.split('/')[-1]} -> {new.split('/')[-1]}")

print(f"\n=== ADDED ===")
for cid, model in added:
    name = name_map.get(cid, cid)
    print(f"  {name}: {model.split('/')[-1]}")

final = json.load(open(path))['channels']['modelByChannel']['discord']

for model_label, model_str in [("OPUS", opus), ("SONNET", sonnet), ("HAIKU", haiku)]:
    print(f"\n  {model_label}:")
    for cid, m in sorted(final.items()):
        if m == model_str:
            name = name_map.get(cid, f"unknown ({cid})")
            print(f"    {name}")

try:
    json.loads(open(path).read())
    print("\nJSON valid")
except Exception as e:
    print(f"\nJSON invalid: {e}")
