#!/usr/bin/env python3
"""Create the real Copilot ACP reproduction in an already running isolated dev app.
Prerequisites: fresh T3CODE_DEV_SEED=0 server, GitHub Copilot ACP Registry provider
(instance acpRegistry_github_copilot), authenticated Copilot CLI 1.0.121.
The server must inherit a Copilot-enabled credential. Never print its value.
Run this identically for each checkout; use a fresh thread for each variant.
"""
import argparse, json, subprocess
from pathlib import Path
p = argparse.ArgumentParser()
p.add_argument('--checkout', type=Path, required=True)
p.add_argument('--project', type=Path, required=True)
p.add_argument('--variant', choices=['stop', 'exit'], required=True)
a = p.parse_args()
a.project.mkdir(parents=True, exist_ok=True)
if not (a.project / '.git').exists():
    (a.project / 'README.md').write_text('# ACP lifecycle proof\n')
    for args in [['init','-q','-b','main'],['add','README.md'],['-c','user.name=Proof','-c','user.email=proof@example.invalid','commit','-qm','Initial commit']]:
        subprocess.run(['git', *args], cwd=a.project, check=True)
def cli(*args):
    return subprocess.run(['node','apps/server/src/bin.ts',*args,'--base-dir','.t3'], cwd=a.checkout, check=True, capture_output=True, text=True).stdout
print(cli('project','add',str(a.project),'--title','ACP lifecycle proof'))
seconds = 600 if a.variant == 'stop' else 900
prompt = (f'Use your task tool to launch ONE subagent with mode "background". Its task: run `sleep {seconds}` using your shell tool in synchronous mode, wait for it to finish, then reply Done. Do not use T3 delegation tools. After launching, reply exactly: Launched. and end your turn immediately without waiting for the subagent.')
print(cli('thread','start',str(a.project),prompt,'--title','Settled Stop proof' if a.variant=='stop' else 'Runtime exit proof','--provider','acpRegistry_github_copilot','--model','claude-sonnet-5.5','--json'))
