#!/usr/bin/env python3
"""Run from an installed checkout with its isolated dev server already running.
Usage: run-proof.py <output-directory>
Requires T3_PROOF_CURSOR_MODEL in the environment. The server must be started
with CURSOR_CONFIG_DIR pointing to a directory whose cli-config.json contains:
{"attribution":{"attributeCommitsToAgent":false,"attributePRsToAgent":false}}
"""
import json, os, pathlib, subprocess, sys
out = pathlib.Path(sys.argv[1]).resolve()
out.mkdir(parents=True, exist_ok=False)
repo = out / 'repository'
repo.mkdir()
def run(args, **kwargs):
    return subprocess.check_output(args, text=True, **kwargs)
def git(*args):
    return run(['git', '-C', str(repo), *args])
git('init', '--quiet', '--initial-branch=main')
git('config', 'user.name', 'Evidence')
git('config', 'user.email', 'evidence@example.invalid')
git('commit', '--quiet', '--allow-empty', '-m', 'Initial')
(repo / 'hello.txt').write_text('Hello attribution\n')
def cli(*args):
    return run(['node', 'apps/server/src/bin.ts', *args, '--base-dir', '.t3'])
cli('project', 'add', str(repo), '--title', 'Attribution proof')
launched = json.loads(cli('thread', 'start', str(repo),
    'Stage hello.txt and commit it with a concise commit message. Do not change the file contents.',
    '--title', 'Commit attribution proof', '--provider', 'cursor',
    '--model', os.environ['T3_PROOF_CURSOR_MODEL'], '--json'))
(out / 'launch.json').write_text(json.dumps(launched))
print(json.dumps(launched))
