main
John Lauer
Preserve adopted board30 and validated resistor library candidates with native-render dependency
7fa0c9c
"""Synchronize adopted prototype connector/grid correction; preserve qualification limits."""
from pathlib import Path
import json,csv,shutil,hashlib
import sexp
R=Path(__file__).resolve().parents[1];O=R/'checkpoints/sensor-gh-review-v8';run=R/'aiflow/run';r=json.loads((run/'run.json').read_text());assert Path(r['boards'][-1]).name=='board-30.kicad_pcb';board=R/r['boards'][-1];sha=hashlib.sha256(board.read_bytes()).hexdigest();assert sha=='ef27c06ea96dcbdd41283c49c6c42a4cf3b1da39029a5bdf75dee1ac59c3d6c9'
backup=O/'before-adoption';backup.mkdir(exist_ok=True)
for name in ['kicad/mechanical.kicad_sch','kicad/lib/Load.kicad_sym','design/netlist.json','design/spec.json','design/bom.csv','design/cost-summary.json']:
src=R/name;dst=backup/name;dst.parent.mkdir(parents=True,exist_ok=True);assert not dst.exists(),'One-shot sync: inspect already-written backup before rerun';shutil.copy2(src,dst)
shutil.copy2(O/'mechanical.kicad_sch',R/'kicad/mechanical.kicad_sch');shutil.copy2(O/'lib/Load.kicad_sym',R/'kicad/lib/Load.kicad_sym')
shutil.copy2(O/'lib/Load.pretty/JST_GH_BM03B-GHS-TBT_1x03-1MP_P1.25mm_Vertical.kicad_mod',R/'kicad/lib/Load.pretty/JST_GH_BM03B-GHS-TBT_1x03-1MP_P1.25mm_Vertical.kicad_mod')
n=json.loads((R/'design/netlist.json').read_text())
for c in n['components']:
if c['ref']=='J10':assert c['mpn']=='M20-9990246';c.update(mpn='BM03B-GHS-TBT',value='JST GH case sensor',fp='Load:JST_GH_BM03B-GHS-TBT_1x03-1MP_P1.25mm_Vertical');c['pins']['3']=None
if c['ref']in ['MP2','MP4']:c['fixed']['x']=64
if c['ref']in ['MP3','MP4']:c['fixed']['y']=72
n['molecule'].update(pin_span_mm=[64,72],board_mm=[68,76],medium_contact_pitch_mm=8)
(R/'design/netlist.json').write_text(json.dumps(n,indent=2)+'\n')
f=R/'tools/netlist.py';s=f.read_text().replace("part('J10','Case sensor connector','Connector_PinHeader_2.54mm:PinHeader_1x02_P2.54mm_Vertical',{1:'TEMP_SENSE',2:'GND'},'mechanical','M20-9990246')","part('J10','JST GH case sensor','Load:JST_GH_BM03B-GHS-TBT_1x03-1MP_P1.25mm_Vertical',{1:'TEMP_SENSE',2:'GND',3:None},'mechanical','BM03B-GHS-TBT')").replace("('MP2',60,0),('MP3',0,68),('MP4',60,68)","('MP2',64,0),('MP3',0,72),('MP4',64,72)").replace("'pin_span_mm':[60,68],'board_mm':[64,72]","'pin_span_mm':[64,72],'board_mm':[68,76],'medium_contact_pitch_mm':8");f.write_text(s)
spec=json.loads((R/'design/spec.json').read_text());spec['board']='Adom electronic load R0, 68 x 76 mm, 2 layers; engineering prototype';spec['molecule']['mediumContactPitchMm']=8
b=sexp.parse(board.read_text());pours=[]
for z in sexp.find(b,'zone'):
if sexp.find(z,'keepout'):continue
net=sexp.first(z,'net')[-1];name=sexp.first(z,'name')[1];layer=sexp.first(z,'layer')[1];cp=sexp.first(z,'connect_pads');assert cp[1]=='yes','Review non-solid connection before syncing';poly=sexp.first(sexp.first(z,'polygon'),'pts');priority=sexp.find(z,'priority')
pours.append({'name':name,'net':net,'layers':[layer],'polygon':[[float(v[1]),float(v[2])]for v in poly[1:]],'priority':int(priority[0][1])if priority else 0,'connection':'solid','clearance':float(sexp.first(cp,'clearance')[1]),'minThickness':float(sexp.first(z,'min_thickness')[1])})
spec['pours']=pours;spec['adoptedGeometryEvidence']={'board':'aiflow/run/board-30.kicad_pcb','sha256':sha,'source':'checkpoints/sensor-gh-review-v8/adoption-evidence.json','limits':'Prototype geometry correction only; copper manufacturing, thermal, crimp and physical fit remain open.'};(R/'design/spec.json').write_text(json.dumps(spec,indent=2)+'\n')
with (R/'design/bom.csv').open(newline='')as f:rd=csv.DictReader(f);names=rd.fieldnames;rows=list(rd)
hit=json.loads((R/'design/component-catalog-audit/jst-gh-threeway-header-sourcing.json').read_text())['digikey']['hits'][0];assert hit['mpn']=='BM03B-GHS-TBT'
for c in rows:
if c['ref']=='J10':c.update(value='JST GH case sensor',mpn=hit['mpn'],manufacturer='JST',source='DigiKey',vendor_pn=hit['vendor_pn'],stock_snapshot=str(hit['stock']),stock_checked_on='2026-10-11',unit_price_usd='0.36',product_url=hit['product_url'],note='API listing, not quote; three-position header with position3NC; housing/contacts separate; crimp and physical qualification pending')
with (R/'design/bom.csv').open('w',newline='')as f:w=csv.DictWriter(f,fieldnames=names);w.writeheader();w.writerows(rows)
p=R/'design/cost-summary.json';cost=json.loads(p.read_text());cost['priced_electrical_subtotal_usd']=round(sum(float(x['unit_price_usd'])for x in rows if x['unit_price_usd']),2);cost['sensor_header_update']={'date':'2026-10-11','mpn':hit['mpn'],'unitListingUsd':.36,'evidence':'design/component-catalog-audit/jst-gh-threeway-header-sourcing.json','housingContactsAndAssemblyExcluded':True};p.write_text(json.dumps(cost,indent=2)+'\n')
previous=r['remoteBoard'];r['remoteBoard']='C:/Users/john/adom-projects/adom-custom-electronic-load/review/sensor-gh-candidate/sensor-gh-candidate.kicad_pcb';r['liveBoardBinding']={'board':'aiflow/run/board-30.kicad_pcb','remoteBoard':r['remoteBoard'],'previousRemoteBoard':previous,'evidence':'checkpoints/sensor-gh-review-v8/adoption-evidence.json','note':'Native-saved adopted board; no physical qualification implied.'};(run/'run.json').write_text(json.dumps(r,indent=2)+'\n')
(O/'adoption-sync.json').write_text(json.dumps({'board':'aiflow/run/board-30.kicad_pcb','sha256':sha,'J10':hit['mpn'],'cornerSpanMm':[64,72],'outlineMm':[68,76],'copperPoursReconciled':len(pours),'electricalSubtotalUsd':cost['priced_electrical_subtotal_usd'],'physicalQualification':False},indent=2)+'\n');print('Canonical schematic, library, circuit, BOM, spec and live binding synchronized; gates remain open.')