"""Run from either installed checkout with its isolated dev server already running.

Usage: python3 reproduce.py CHECKOUT DATA_DIRECTORY NEW_DISPOSABLE_REPO
Start the server with T3CODE_DEV_SEED=0 vp run dev first.
The supplied repo path must not exist. No real user data is used.
"""
import pathlib
import subprocess
import sys

checkout, data, repo = map(pathlib.Path, sys.argv[1:])
repo.mkdir(parents=True, exist_ok=False)
subprocess.run(["git", "init", "-q", str(repo)], check=True)
subprocess.run(["git", "-C", str(repo), "-c", "user.name=Proof", "-c",
                "user.email=proof@example.com", "commit", "--allow-empty", "-qm",
                "Initial commit"], check=True)
cli = ["node", "apps/server/src/bin.ts"]
subprocess.run(cli + ["project", "add", str(repo), "--base-dir", str(data),
                     "--title", "Native worker proof"], cwd=checkout, check=True)
prompt = ('Use delegate_task to start 6 local Codex children using model gpt-6.2-sol, '
          'isolation shared, mode async. Give each child this task verbatim: '
          '"Create a temporary detached git worktree with git worktree add --detach. '
          'Use your own native Codex spawn_agent worker to run git rev-parse HEAD '
          'inside that worktree. Wait for the native worker, report its result, '
          'and remove the temporary worktree." Wait for all six children and report each outcome.')
subprocess.run(cli + ["thread", "start", str(repo), "-", "--provider", "codex",
                     "--model", "gpt-6.2-sol", "--title", "Checkout rule reproduction",
                     "--base-dir", str(data), "--wait", "--json"],
               cwd=checkout, input=prompt, text=True)
