main
John Lauer Correct R7 clamp fault power on board27; publish exact resistor assets, simulations and forming-study evidence without… 11c16d0
"""Synchronize only the adopted R7 correction; retain historical checkpoints."""
from pathlib import Path
import json,csv,shutil,hashlib
p=Path(__file__).resolve().parents[1];run=p/'aiflow/run';r=json.load(open(run/'run.json'));assert Path(r['boards'][-1]).name=='board-27.kicad_pcb';board=p/r['boards'][-1];assert hashlib.sha256(board.read_bytes()).hexdigest()=='84ba05db36d9e8d7183e5c39bed57bc67daf6735372f5a68fbac6c69aed54550'
# Native schematic candidate was validated from the complete hierarchy.
shutil.copyfile(p/'kicad/servo.kicad_sch',p/'checkpoints/r7-fault-review/servo-before-adoption.kicad_sch')
shutil.copyfile(p/'checkpoints/r7-fault-review/servo.kicad_sch',p/'kicad/servo.kicad_sch')
n=json.load(open(p/'design/netlist.json'));c=next(c for c in n['components'] if c['ref']=='R7');assert c['value']=='1k' and c['mpn']=='CR0402-FX-1001GLF';c['value']='4.7k';c['mpn']='ERJ-2RKF4701X';(p/'design/netlist.json').write_text(json.dumps(n,indent=2)+'\n')
f=p/'tools/netlist.py';s=f.read_text();old="r('R7','1k','SERVO_OUT','GATE','servo')";assert old in s;s=s.replace(old,"r('R7','4.7k','SERVO_OUT','GATE','servo',mpn='ERJ-2RKF4701X')");f.write_text(s)
with (p/'design/bom.csv').open(newline='') as f:rd=csv.DictReader(f);names=rd.fieldnames;rows=list(rd)
c=next(c for c in rows if c['ref']=='R7');assert c['mpn']=='CR0402-FX-1001GLF';hit=json.load(open(p/'components/erj-2rkf4701x/sourcing.json'))['mouser']['hits'][0]
c.update(value='4.7k',mpn='ERJ-2RKF4701X',manufacturer='Panasonic Industry',source='Mouser',vendor_pn=hit['vendor_pn'],stock_snapshot=str(hit['stock']),stock_checked_on='2026-10-11',unit_price_usd='0.11',product_url=hit['product_url'],note='API listing only; 0.1W at70C required, derating applies; no order or hardware qualification')
with (p/'design/bom.csv').open('w',newline='') as f:w=csv.DictWriter(f,fieldnames=names);w.writeheader();w.writerows(rows)
f=p/'design/cost-summary.json';s=json.load(open(f));s['priced_electrical_subtotal_usd']=round(sum(float(x['unit_price_usd']) for x in rows if x['unit_price_usd']),2);s['unpriced_refs']=[x for x in s['unpriced_refs'] if x!='R7'];s['r7_update']={'date':'2026-10-11','mpn':'ERJ-2RKF4701X','unitListingUsd':.11,'evidence':'components/erj-2rkf4701x/sourcing.json'};f.write_text(json.dumps(s,indent=2)+'\n')
r['remoteBoard']='C:/Users/john/adom-projects/adom-custom-electronic-load/review/r7-candidate/r7-candidate.kicad_pcb';(run/'run.json').write_text(json.dumps(r,indent=2)+'\n')
f=p/'checkpoints/r7-fault-review/selection-review.json';s=json.load(open(f));s['adopted']=True;s['adoptedBoard']='aiflow/run/board-27.kicad_pcb';f.write_text(json.dumps(s,indent=2)+'\n')
print(json.dumps({'board':str(board),'r7':'4.7k ERJ-2RKF4701X','pricedElectricalSubtotalUsd':json.load(open(p/'design/cost-summary.json'))['priced_electrical_subtotal_usd']}))