from PIL import Image,ImageDraw,ImageFont
from pathlib import Path
import textwrap
root=Path(__file__).parent
run=root/'run-20261116T000031Z'
font=ImageFont.truetype('/usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf',19)
for side,sha in [('before','06150a08ec'),('after','c9a30d8ac5')]:
    title=('Before' if side=='before' else 'After')+' | '+sha+' | Real CLI transcript (paths redacted)'
    raw=(run/(side+'.txt')).read_text().splitlines()
    lines=[title,'']
    for line in raw:
        lines.extend(textwrap.wrap(line,116,replace_whitespace=False,drop_whitespace=False) or [''])
    im=Image.new('RGB',(1450,32+len(lines)*27),'#10151c');d=ImageDraw.Draw(im)
    for i,line in enumerate(lines):
        color='#e4eaf0'
        if 'Memory protection:' in line or 'Only the OOM scores' in line or line.startswith('Protected T3 Code'):color='#ffcc66' if side=='before' else '#83e0b0'
        if line.startswith('$ '):color='#91baff'
        d.text((24,16+i*27),line,font=font,fill=color)
    im.save(run/(side+'.png'))
