main
John Lauer Cooling clearance revision: native probe/fan relocation, checked copper cleanup, fitted-body screen and recorded review… 04019ce
"""Apply only the prechecked cooling-clearance relocation to the named native board.
The main AIFlow placement visit records the actual action. Field cleanup is a separate saved-file step.
"""
import json,subprocess
from pathlib import Path
p=Path(__file__).resolve().parents[1];out=p/'design/cooling-live';out.mkdir(exist_ok=True)
board='C:/Users/john/adom-projects/adom-custom-electronic-load/kicad/adom-custom-electronic-load.kicad_pcb'
def ab(name,args,label):
 d=json.loads(subprocess.check_output(['adom-bridge','--target','AdomLapper','--ai-thread','adom-custom-load',name,json.dumps(args)],text=True));(out/(label+'.json')).write_text(json.dumps(d,indent=2))
 if d.get('success')is False or d.get('error'):raise RuntimeError(str(d)[:1400])
 return d
s=ab('kicad_routing_state',{'filePath':board},'before');rev=s['revision'];assert rev=='da4ce842abc3113716b275794e42b380920b95f3a32f32ef82257adba3ee3e3f'
gate=json.load(open(p/'checkpoints/cooling-clearance/run-v9/gate.json'));assert gate['errors']==0 and gate['unconnected']==0
changes=json.load(open(p/'checkpoints/cooling-clearance/cooling-clearance-changes.json'));plan=json.load(open(p/'checkpoints/cooling-clearance/run-v9/plan-route.json'))
def mutate(name,args,label):
 global rev
 d=ab(name,dict(filePath=board,expectedRevision=rev,**args),label);rev=d.get('revision')or ab('kicad_routing_state',{'filePath':board},label+'-state')['revision'];return d
mutate('kicad_move_footprint',{'refs':[{'ref':ref,'x':x,'y':y,'rotation':rot}for ref,x,y,rot in changes['moves']]},'move-probes-and-fan')
seen=set()
for i,j in enumerate(changes['junctions']):
 key=json.dumps(j,sort_keys=True)
 if key in seen:continue
 seen.add(key)
 if 'viaAt'in j:
  x,y=j['viaAt'];args={'net':j['net'],'width':.25,'viaSize':.6,'viaDrill':.3,'paths':[[{'x':x,'y':y,'layer':'F.Cu'},{'x':x,'y':y,'layer':'B.Cu'}]],'validate':False}
 else:args={'net':j['net'],'width':.25,'layer':j['layer'],'paths':[[j['start'],j['end']]],'validate':False}
 mutate('kicad_route_net',args,f'junction-{i}')
for i,e in enumerate(plan['nets']):mutate('kicad_route_net',dict(e,validate=False),f'route-{i}-{e["net"]}')
ab('kicad_zone_state',{'filePath':board,'refill':True},'refill-request')
print('Native relocation and copper complete. Await stable fill, saved-file field cleanup and final validation.')