from PIL import Image, ImageDraw, ImageFont
from pathlib import Path
import textwrap
root=Path(__file__).parent/'20261118T114429Z'
font=ImageFont.truetype('/usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf',18)
for side in ['before','after']:
 raw=(root/f'{side}.txt').read_text()
 lines=[raw.splitlines()[0], 'Captured CLI output excerpts (full transcript attached)', 'Linux / Python 3.12.3 / Node 26.13.1 / synthetic config', '']
 for section in raw.split('=== ')[1:]:
  label,body=section.split(' ===',1)
  lines += [label]
  for line in body.splitlines():
   if line.startswith('$ pnpm') or line.startswith('Exit:') or line.startswith('KeyError:') or line.startswith('FileNotFoundError:') or 'Error: No Codex' in line or line.startswith('Endpoint requests:'):
    lines.extend(textwrap.wrap(line,100,replace_whitespace=False))
  lines += ['']
 if side=='after': lines+=['Endpoint returns HTTP 400 deliberately; model completion is unverified.']
 im=Image.new('RGB',(1260,len(lines)*27+50),'#101820'); draw=ImageDraw.Draw(im)
 for i,line in enumerate(lines): draw.text((25,25+27*i),line,font=font,fill='#e4edf2')
 im.save(root/f'{side}.png')
