import pathlib,subprocess,sys,time,json
out=pathlib.Path(sys.argv[1]);label=sys.argv[2];workspace=pathlib.Path(sys.argv[3]);file=sys.argv[4];log=pathlib.Path(sys.argv[5]);tools=pathlib.Path(__file__).parent
out.mkdir(parents=True,exist_ok=True)
def ad(*args):
 p=subprocess.run(['agent-device',*args,'--session','evidence25872'],capture_output=True,text=True,check=True)
 print(p.stdout,flush=True);return p.stdout
def capture(suffix): subprocess.run(['python3',str(tools/'capture.py'),str(out),label+'-'+suffix],check=True)
def checkpoint(suffix):subprocess.run(['python3',str(tools/'checkpoint.py'),str(log),str(out/'query-checkpoints.jsonl'),label+'-'+suffix],check=True)
capture('start');checkpoint('start')
ad('record','start',str(out/(label+'.mp4')),'--fps','15','--hide-touches')
time.sleep(1)
if file!='none':
 with (workspace/file).open('a') as f:f.write(f'Additional review line for {file}\n')
 print('APPENDED: Additional review line for '+file,flush=True)
ad('press','label="Select diff"','--settle')
ad('press','text="Refresh current diff"','--settle')
time.sleep(5)
capture('refreshed');checkpoint('refreshed')
ad('record','stop')
