"""Prepare the same attachment-only draft on either checkout, starting at its project picker."""
import subprocess,sys,re
session=sys.argv[1]
def device(*args):
 r=subprocess.run(['agent-device',*args,'--session',session],text=True,capture_output=True,check=True)
 print(r.stdout,flush=True)
 return r.stdout
device('press',sys.argv[2],'--settle')
device('wait','label="Add attachment"','15000')
device('press','label="Add attachment"','--settle')
device('press','text="Choose Files"','--settle')
device('wait','label="Recent files"','15000')
snapshot=device('snapshot','-i')
ref=re.search(r'(@e\d+) \[group\] "a.png,',snapshot).group(1)
device('press',ref,'--settle')
device('wait','role="text-field"','15000')
device('fill','role="text-field"','','--settle')
device('keyboard','dismiss')
snapshot=device('snapshot','-i')
if 'Model and reasoning settings, Showcase' not in snapshot:
 label=re.search(r'\[button\] "(Model and reasoning settings,[^"]+)"',snapshot).group(1)
 device('press',f'label="{label}"','--settle')
 device('press','label="Replay (dev), 8 models"','--settle')
 device('press','label="Showcase"','--settle')
 device('press','label="Save"','--settle')
