import json, pathlib, subprocess, textwrap
root=pathlib.Path(__file__).parent
for side,sha in [('base','a18a458f25'),('head','383db06685')]:
    events=[json.loads(x) for x in (root/f'{side}.jsonl').read_text().splitlines()]
    for tick in range(23):
        lines=[f'{"BEFORE" if side=="base" else "AFTER"} | {sha} | Linux real-process ACP service',
               'Timed transcript playback (not a client UI recording)',f'Elapsed: {tick:02d} seconds','']
        for e in events:
            if e['seconds']<=tick:
                lines.extend(textwrap.wrap(f"[{e['seconds']:6.3f}s] {e['message']}", width=102, subsequent_indent='          '))
        target=root/f'{side}-{tick:02d}.png'
        subprocess.run(['convert','-size','1440x900','xc:#101820','-font','DejaVu-Sans-Mono','-pointsize','21','-fill','#e6edf3','-gravity','NorthWest','-annotate','+32+30','\n'.join(lines).replace(chr(92), chr(92)*2),str(target)],check=True)
    subprocess.run(['ffmpeg','-y','-loglevel','error','-framerate','1','-i',str(root/f'{side}-%02d.png'),'-c:v','libx264','-pix_fmt','yuv420p','-r','10',str(root/f'{side}.mp4')],check=True)
