#!/usr/bin/env python3
"""Run once per commit against its running, freshly initialized T3 dev server.
Usage: python3 reproduce.py CHECKOUT NEW_PROJECT_DIRECTORY prompt-timing.txt
Prerequisites: vp i; T3CODE_DEV_SEED=0 vp run dev; enabled OpenCode provider
using @opencode/cli 2.3.0 and isolated XDG directories containing only the
provider connection settings needed for openai/gpt-5.6-luna.
Open the returned link on the matching dev web origin, already paired.
Capture Chromium at 1440x1200, light theme, DPR 2. Record the turn through
completion. Captures crop the timeline (x280,y0,w860,h850 CSS pixels) to exclude
machine identity in the surrounding shell. No timeline content is edited.
The fixed answer is deliberately long enough to keep generation active while
the four-second background job completes; use identical prompt on both sides.
"""
import json
import pathlib
import subprocess
import sys
import time

checkout, project, prompt = map(pathlib.Path, sys.argv[1:])
project.mkdir(parents=True, exist_ok=False)
subprocess.run(['git', 'init', str(project)], check=True, capture_output=True)
cli = ['node', 'apps/server/src/bin.ts']
def t3(*args):
    return subprocess.run(cli + list(args), cwd=checkout, check=True, text=True,
                          capture_output=True).stdout.strip()
print(t3('project', 'add', '--base-dir', '.t3', '--title', 'Background note proof', str(project)))
run = subprocess.run(cli + ['thread', 'start', '--base-dir', '.t3', '--provider',
    'opencode', '--model', 'openai/gpt-5.6-luna', '--title',
    'Answer and completion note', str(project), '-'], cwd=checkout,
    input=prompt.read_text(), text=True, capture_output=True, check=True)
thread = run.stdout.strip()
print(thread)
print('Open the thread in the paired browser immediately and record until Done.')
print(t3('thread', 'show', '--base-dir', '.t3', thread, '--json'))
