from pathlib import Path
import subprocess,re,json,tarfile
root=Path('/tmp/issue-lead-27080-r2/evidence-capture')
run=root/'run-20261029T233700Z'
files=[]
for p in sorted(run.iterdir()):
 if re.match(r'^(before|after)-R[123]-(1280|1440|390)-(dark|light)\.png$',p.name) or re.match(r'^R[123]-\d+-(dark|light)-diff(0|T16)\.png$',p.name) or re.match(r'^(before|after)-R[123]\.mp4$',p.name) or p.name.startswith('sheet-') or p.name.startswith('caret-sheet-'):
  files.append(p)
files.extend([run/'final-manifest.json',run/'diff-statistics.json',root/'fixture-matrix.md'])
files.extend(sorted(p for p in root.iterdir() if p.suffix in ['.js','.sh','.py','.md'] and p.name!='fixture-matrix.md'))
# Preserve every raw capture and diagnostic without exposing the private startup logs.
with tarfile.open(root/'raw-captures.tar.gz','w:gz') as tar:
 for p in sorted(run.iterdir()):tar.add(p,arcname=p.name)
files.append(root/'raw-captures.tar.gz')
result=subprocess.run(['ghdrop','upload','-m',*[str(p) for p in files]],check=True,text=True,capture_output=True)
(root/'uploads-verbatim.md').write_text(result.stdout)
links={}
for line in result.stdout.splitlines():
 match=re.match(r'!?\[([^\]]+)\]\(([^)]+)\)',line)
 if match:links[match[1]]=dict(markdown=line,url=match[2])
(root/'uploads.json').write_text(json.dumps(links,indent=2))
print(result.stdout,end='')
