"""Run from a checkout whose isolated dev server is already running.
Usage: python3 seed.py HOME WORKSPACE restart|forms
Start the server with T3CODE_DEV_SEED=0 T3CODE_ENVIRONMENT_LABEL='Test environment'
vp run dev --home-dir HOME. Use a new HOME for each commit.
In the web client, open the returned thread directly, keep the sidebar expanded,
close the thread details panel, and verify Maintenance > Continue threads after
restarts is enabled. Record the task's Details, dismiss it, show Maintenance,
return to the thread, stop the retained dev session with Ctrl-C, and start the
same dev command again. Do not send another message during recovery.
For forms, inspect Background work > Details for each task's exact command.
"""
import json, subprocess, sys
home, workspace, case = sys.argv[1:]
prompts = {
'restart': 'Use Bash to run exactly sleep 900; date with run_in_background: true and description Sleep 900 seconds then print date. Then end your turn with Timer armed without calling t3_background_wait or TaskOutput. If a restart cancels the task, say Restart cancellation received, restart the same timer once, and end your turn.',
'forms': 'Run these four exact Bash commands as separate run_in_background: true jobs, with the matching description: (1) sleep 900 — Plain sleep timer; (2) sleep "900" && printf "timer; ready\\n" — Quoted report timer; (3) sleep 900 && node -e "setInterval(()=>{},1000)" — Long running command; (4) sleep 900; echo "$(date)" — Report with substitution. Then end your turn with Four jobs armed. Do not call t3_background_wait or TaskOutput. Do not run any other command.'
}
cli = ['node', 'apps/server/src/bin.ts']
added = subprocess.run(cli+['project','add',workspace,'--title','Timer demo','--base-dir',home],capture_output=True,text=True)
if added.returncode and 'ProjectAlreadyExistsError' not in added.stderr + added.stdout:
    raise RuntimeError(added.stderr + added.stdout)
subprocess.run(cli+['thread','start',workspace,prompts[case],'--provider','claudeAgent','--model','claude-haiku-5-5','--title',{'restart':'Sleep timer restart','forms':'Sleep command forms'}[case],'--base-dir',home,'--json'],check=True)
