main
John Lauer
Record exact-part catalog audit, Q1 fit finding, reviewed model clip and verified automatic continuation
091557c
"""Bind exact catalog identities without claiming CAD/geometry qualification."""
import json,subprocess,re
from pathlib import Path
from concurrent.futures import ThreadPoolExecutor
root=Path(__file__).resolve().parents[1];out=root/'design/component-catalog-audit'
report=json.loads((out/'report.json').read_text())
def norm(x):return re.sub('[^a-z0-9]','',x.lower())
def fetch(g):
candidates=[c for c in g.get('candidates',[]) if norm(c['slug'])==norm(g['mpn'])]
matches=[]
for c in candidates:
target=out/(c['slug']+'.page.json')
p=subprocess.run(['adom-wiki','repo','show',c['owner']+'/'+c['slug'],'page.json','--out',str(target),'--json'],capture_output=True,text=True,timeout=60)
if p.returncode:continue
page=json.loads(target.read_text());component=page.get('component',{})
if component.get('mpn','').upper()==g['mpn'].upper():matches.append({'url':c['url'],'mpn':component['mpn'],'metadata':str(target.relative_to(root)),'parts':component.get('parts',{})})
return {**g,'exactIdentityMatches':matches}
with ThreadPoolExecutor(max_workers=4) as pool:groups=list(pool.map(fetch,report['groups']))
report['groups']=groups;(out/'report.json').write_text(json.dumps(report,indent=2)+'\n')
path=root/'aiflow/run/components.json';data=json.loads(path.read_text());before=path.read_bytes();(out/'register-before-catalog-links.json').write_bytes(before)
lookup={ref:g for g in groups for ref in g['references']};linked=0
for part in data['components']:
g=lookup.get(part['reference'],{});matches=g.get('exactIdentityMatches',[])
if len(matches)==1:
review=part['review'];review['wikiPage']=matches[0]['url']
review['catalogIdentityEvidence']=matches[0]['metadata']
# Existing status remains pending/stale until actual per-board review.
linked+=1
path.write_text(json.dumps(data,indent=2)+'\n')
print(json.dumps({'referencesLinked':linked,'exactCatalogGroups':sum(len(g.get('exactIdentityMatches',[]))==1 for g in groups),'passedReviewsAdded':0}))