import subprocess,sys,pathlib,json,time
session,seed_file,out_dir,side=sys.argv[1:]
out=pathlib.Path(out_dir); out.mkdir(parents=True,exist_ok=True)
workspace=json.loads(pathlib.Path(seed_file).read_text())['workspace']
events=[]
def run(*args):
 start=time.time()
 result=subprocess.run(['agent-device',*args,'--session',session],text=True,capture_output=True)
 events.append({'args':list(args),'started':start,'ended':time.time(),'code':result.returncode})
 (out/f'{side}-actions.json').write_text(json.dumps(events,indent=2))
 print(result.stdout,result.stderr,flush=True)
 result.check_returncode()
def capture(name):
 subprocess.run([sys.executable,str(pathlib.Path(__file__).with_name('capture-stable.py')),session,str(out/f'mobile-{side}-{name}.png')],check=True)
run('record','start',str(out/f'mobile-{side}.mp4'),'--fps','10','--hide-touches')
run('press','label="New chat"','--settle')
run('press','label="alpha"','--settle')
run('fill','role=text-view','Plan the next project','--settle')
run('press','label="alpha"','--settle')
run('press','label="Add project"','--settle')
run('press','label="new folder, Local folder, Browse a folder on disk, Forward"','--settle')
run('fill','role=text-field',workspace+'/next','--settle')
run('press','label="Add project"','--settle')
run('snapshot','-i')
capture('after-add')
# Fill the same message on both commits so the sent thread can be compared with Unsent.
run('fill','role=text-view','Plan the next project','--settle')
run('press','label="Send"','--settle')
run('wait','text','I added clamp next to sum and the tests pass.')
run('record','stop','--json')
run('press','label="Back"','--settle')
run('snapshot','-i')
capture('home')
