# Start on Choose project for a saved Demo draft.
# Set DEVICE_SESSION, DEMO_ROOT; optionally DISMISS=1.
import subprocess,time,pathlib,sys,os
out=pathlib.Path(sys.argv[1]);out.mkdir(parents=True,exist_ok=False)
def ad(*args):
 r=subprocess.run(['agent-device',*args,'--session',os.environ['DEVICE_SESSION']],capture_output=True,text=True)
 with (out/'transcript.txt').open('a') as f:f.write(r.stdout+'\n'+r.stderr)
 if r.returncode:raise RuntimeError(r.stderr)
 return r.stdout
ad('record','start',str(out/'raw.mp4'),'--hide-touches')
ad('press','label="No project, Start a task without a project"','--settle')
ad('back','--settle') if os.environ.get('DISMISS') else ad('press',f'label="Demo, {os.environ["DEMO_ROOT"]}"','--settle')
ad('snapshot','-i')
time.sleep(25)
ad('snapshot','-i')
ad('screenshot',str(out/'final-1.png'))
time.sleep(.5)
ad('screenshot',str(out/'final-2.png'))
ad('record','stop')
print(out)
