main
John Lauer Preserve board29, component assets and scaffold-fit correction candidate with reviewed footage c54169e
"""Isolate 64x72mm corner span correction; preserve electrical placements and rules."""
from pathlib import Path
import copy,shutil,json,hashlib
import sexp
R=Path(__file__).resolve().parents[1];O=R/'checkpoints/scaffold-fit-review';src=R/'aiflow/run/board-29.kicad_pcb';dst=O/'scaffold-fit-candidate.kicad_pcb'
b=sexp.parse(src.read_text());before=copy.deepcopy(b);changes=[]
for f in sexp.find(b,'footprint'):
 p={v[1]:v[2]for v in sexp.find(f,'property')};ref=p['Reference']
 if ref in ['MP2','MP3','MP4']:
  at=sexp.first(f,'at');old=at[1:3].copy()
  if ref in ['MP2','MP4']:assert float(at[1])==160;at[1]=sexp.Sym('164')
  if ref in ['MP3','MP4']:assert float(at[2])==32;at[2]=sexp.Sym('28')
  changes.append({'reference':ref,'oldXYmm':old,'newXYmm':at[1:3]})
for tag in ['gr_line','gr_arc']:
 for g in sexp.find(b,tag):
  if sexp.first(g,'layer')!=['layer','Edge.Cuts']:continue
  for key in ['start','mid','end']:
   q=sexp.first(g,key)
   if q:
    if float(q[1])>=160:q[1]=sexp.Sym(str(float(q[1])+4))
    if float(q[2])<=32:q[2]=sexp.Sym(str(float(q[2])-4))
for z in sexp.find(b,'zone'):
 if sexp.first(z,'net')==['net','GND']:
  for poly in sexp.find(z,'polygon'):
   for q in sexp.find(sexp.first(poly,'pts'),'xy'):
    if float(q[1])==161.7:q[1]=sexp.Sym('165.7')
    if float(q[2])==30.3:q[2]=sexp.Sym('26.3')
 # Old filled polygons are invalid after boundary changes; native refill required.
 z[:]=[v for v in z if not(isinstance(v,list) and v and v[0] in ['filled_polygon','fill_segments'])]
assert sexp.find(b,'segment')==sexp.find(before,'segment')
assert sexp.find(b,'via')==sexp.find(before,'via')
for folder in ['3d','lib']:shutil.copytree(R/'aiflow/run'/folder,O/folder,dirs_exist_ok=True)
shutil.copy2(R/'aiflow/run/fp-lib-table',O/'fp-lib-table')
for ext in ['kicad_pro','kicad_dru']:shutil.copy2(src.with_suffix('.'+ext),dst.with_suffix('.'+ext))
dst.write_text(sexp.dump(b)+'\n');assert sexp.parse(dst.read_text())==b
r={'adopted':False,'source':str(src.relative_to(R)),'sourceSha256':hashlib.sha256(src.read_bytes()).hexdigest(),'candidate':str(dst.relative_to(R)),'candidateSha256':hashlib.sha256(dst.read_bytes()).hexdigest(),'pinChanges':changes,'outlineMm':[68,76],'cornerSpanMm':[64,72],'tracksAndViasUnchanged':True,'changedZoneBoundaries':['Top return and shield','Power return and signal reference'],'nativeRefillRequired':True,'openDependencies':['Native DRC and ground connection check','Right cooling carrier clamps must move4mm with board edge','Updated molecule spec/fixed interface and actual scaffold fit','Full mechanical and electrical revalidation before adoption']}
(O/'candidate-review.json').write_text(json.dumps(r,indent=2)+'\n');print(json.dumps(r))