main
John Lauer
Adopt board28 low-voltage Q3/Q4 replacements with native evidence and recorded review; preserve qualification gates
2c70410
"""Isolate low-voltage-specified Q3/Q4 replacements and their reviewed nominal models."""
from pathlib import Path
import copy,json,hashlib,shutil
import sexp
root=Path(__file__).resolve().parents[1];out=root/'checkpoints/release-fet-review';out.mkdir(exist_ok=True);src=root/'aiflow/run/board-27.kicad_pcb';board=out/'release-fet-candidate.kicad_pcb'
for folder in ['3d','lib']:shutil.copytree(root/'aiflow/run'/folder,out/folder,dirs_exist_ok=True)
shutil.copyfile(root/'aiflow/run/fp-lib-table',out/'fp-lib-table')
for ext in ['kicad_pro','kicad_dru']:shutil.copyfile(src.with_suffix('.'+ext),board.with_suffix('.'+ext))
for f in (root/'kicad').glob('*.kicad_sch'):shutil.copyfile(f,out/f.name)
model=root/'components/nx3008nbk/nx3008nbk-etched.step';shutil.copyfile(model,out/'3d/nx3008nbk-etched.step');rows=[]
for source,dest,tag in [(src,board,'footprint'),(root/'kicad/protection.kicad_sch',out/'protection.kicad_sch','symbol')]:
t=sexp.parse(source.read_text());old=copy.deepcopy(t);changes=[]
for f in sexp.find(t,tag):
props={x[1]:x for x in sexp.find(f,'property')}
if props.get('Reference',[None,None,None])[2] not in ['Q3','Q4']:continue
ref=props['Reference'][2];assert props['MPN'][2]=='2N7002-7-F';before={k:props[k][2] for k in ['MPN','Value']};props['MPN'][2]='NX3008NBK,215';props['Value'][2]='NX3008NBK'
change={'reference':ref,'oldProperties':before}
if tag=='footprint':
m=sexp.find(f,'model');assert len(m)==1;change['oldModel']=m[0][1];m[0][1]='${KIPRJMOD}/3d/nx3008nbk-etched.step'
changes.append(change)
assert len(changes)==2;dest.write_text(sexp.dump(t)+'\n');assert sexp.parse(dest.read_text())==t
for f in sexp.find(t,tag):
props={x[1]:x for x in sexp.find(f,'property')};ref=props.get('Reference',[None,None,None])[2]
if ref not in ['Q3','Q4']:continue
change=next(c for c in changes if c['reference']==ref)
for k,v in change['oldProperties'].items():props[k][2]=v
if tag=='footprint':sexp.find(f,'model')[0][1]=change['oldModel']
assert t==old,'Unexpected copper/pin/transform edit'
rows.append({'source':str(source.relative_to(root)),'sourceSha256':hashlib.sha256(source.read_bytes()).hexdigest(),'candidate':str(dest.relative_to(root)),'candidateSha256':hashlib.sha256(dest.read_bytes()).hexdigest(),'changes':changes})
r={'adopted':False,'copperNetsPositionsPadsAndModelTransformsUnchanged':True,'files':rows,'candidateModelSha256':hashlib.sha256(model.read_bytes()).hexdigest(),'scope':'Q3/Q4 1.8V-specified replacement candidate; full hot/startup/brownout timing and hardware qualification remain open'};(out/'selection-review.json').write_text(json.dumps(r,indent=2)+'\n');print(json.dumps({'candidate':str(board),'changedRefs':['Q3','Q4']}))