#!/usr/bin/env python3
"""Run from a checkout with a fresh dev server (T3CODE_DEV_SEED=0).
Usage: seed.py <synthetic-git-project> <provider-model>
The model argument selects the installed Claude provider's inexpensive model.
Creates real history through the running app's CLI, including real compaction.
Then open the printed thread in the web client, edit the third prompt, choose
Revert and keep changes, append the follow-up below, and submit:
What is the retained code word? Reply with only that word. Do not use tools.
Restart the server, edit the second prompt, choose Revert and keep changes,
replace the draft with the following prompt, and submit:
After restart and earlier rollback, what is the retained code word? Reply with only that word. Do not use tools.
"""
import json, pathlib, subprocess, sys
project, model = sys.argv[1:]
def cli(*args):
    p = subprocess.run(['node','apps/server/src/bin.ts',*args], text=True, capture_output=True)
    if p.returncode:
        raise RuntimeError(p.stderr)
    return p.stdout
cli('project','add','--base-dir','.t3','--title','Compaction proof',project)
first=json.loads(cli('thread','start','--base-dir','.t3','--provider','claudeAgent','--model',model,'--title','Compaction rollback proof','--wait','--json',project,'Remember the code word MARIGOLD. Reply only with the code word. Do not use tools.'))
thread=first['threadId']
for message in ['Second checkpoint. Say READY and keep remembering the code word. Do not use tools.','Third checkpoint. Say SET and keep remembering the code word. Do not use tools.','/compact','After compaction checkpoint. Reply AFTER. Do not use tools.']:
    result=json.loads(cli('thread','send','--base-dir','.t3','--wait','--json',thread,message))
    print(json.dumps({'status':result['status'],'reply':result['reply']}),flush=True)
print(thread)
