import datetime,json,pathlib,subprocess,sys
root=pathlib.Path('/tmp/lead-33624-r1/evidence-capture')
batch=root/(datetime.datetime.now(datetime.timezone.utc).strftime('%Y%m%dT%H%M%S.%fZ')+'-matrix');batch.mkdir()
manifest=[]
for row in ['F2','F3','F4','F5','F8']:
 for side in ['before','after']:
  runtime='/home/ubuntu/wt/pr-33624/apps/desktop/node_modules/electron/dist/electron' if row=='F5' else '/home/ubuntu/.local/share/vite-plus/js_runtime/node/26.12.1/bin/node'
  cmd=[sys.executable,str(root/'capture.py'),'--side',side,'--row',row,'--trials','5','--runtime',runtime]
  output=batch/(row+'-'+side+'-launcher.txt')
  with output.open('w') as f:
   result=subprocess.run(cmd,stdout=f,stderr=subprocess.STDOUT)
  lines=output.read_text().splitlines()
  paths=[line[11:] for line in lines if line.startswith('TRANSCRIPT=')]
  record={'row':row,'side':side,'returncode':result.returncode,'transcript':paths[-1] if paths else None,'launcher':str(output)}
  manifest.append(record)
  (batch/'manifest.json').write_text(json.dumps(manifest,indent=2)+'\n')
  print(json.dumps(record),flush=True)
print('MANIFEST='+str(batch/'manifest.json'),flush=True)
