import json,subprocess,time
from pathlib import Path
root=Path(__file__).parent/'ios-resume-short'/time.strftime('%Y%m%d-%H%M%S');root.mkdir(parents=True)
def run(*args,capture=False):
 r=subprocess.run(['agent-device',*args,'--session','proof-32137-ios'],text=True,check=True,stdout=subprocess.PIPE if capture else None)
 return r.stdout
run('record','start',str(root/'flow.mp4'),'--hide-touches')
raw=json.loads(run('snapshot','--json',capture=True))['data']['nodes']
saved=[n for n in raw if n.get('label','').startswith('First line of the saved draft Second line')]
run('press','@'+saved[0]['ref'],'--settle')
run('press','role=text-view','--settle')
run('press','label="Back"','--settle')
run('record','stop')
print(root)
