import subprocess,sys,time,json
from pathlib import Path
session,platform,side=sys.argv[1:4]
root=Path(__file__).parent
log=[]
def ad(*args):
 r=subprocess.run(["agent-device",*args,"--session",session],capture_output=True,text=True)
 log.append({"args":args,"returncode":r.returncode,"stdout":r.stdout,"stderr":r.stderr})
 (root/f"{platform}-{side}-driver.json").write_text(json.dumps(log,indent=2))
 if r.returncode: raise RuntimeError(r.stdout+r.stderr)
 return r.stdout
def tap(label):ad("press",f'label="{label}"',"--settle")
def still(label):
 r=subprocess.run([sys.executable,str(root/"stable.py"),session,f"{platform}-{side}-{label}"],capture_output=True,text=True)
 print(r.stdout,flush=True)
 if r.returncode: raise RuntimeError(r.stderr+r.stdout)
back="Back" if platform=="ios" else "Navigate up"
ad("record","start",str(root/f"{platform}-{side}.mp4"),"--hide-touches")
time.sleep(2)
tap("doc.md · L645–647, doc.md L645-647")
still("wrap-L645")
tap("File actions")
tap("Disable word wrap")
tap(back)
tap("doc.md · L645–647, doc.md L645-647")
still("nowrap-L645")
ad("record","stop")
print("completed",platform,side,flush=True)
