0hmX/am3352

This code suite comprises TypeScript scripts that analyze, verify, and assemble complex DDR memory interface hardware, focusing on physical routing, via and pad placement, electrical clearance, and physical constraints, often involving precise geometric calculations and consistent provenance tracking.

Version
1.0.5
License
unset
Stars
0

scripts/repair-ddr-cpu-supply-junction.ts

/** One explicit CPU supply replacement on an isolated integrated candidate. */
import{readFileSync,writeFileSync,copyFileSync,mkdirSync}from'node:fs'
import{resolve}from'node:path'
import{spawnSync}from'node:child_process'
import{createHash}from'node:crypto'
import{verifyDdrCapture}from'./ddr-capture-provenance'
import{objectHash,validateDeclaredDdrReplacements}from'./improve-ddr-a9-power-launches'
import{verifyDdrSystemCopper,auditDdrTraceJunctions}from'./check-ddr-system-copper'
import{auditRouteAngles}from'./check-route-angles'
import{refreshDdrPlaneContacts}from'./ddr-plane-contact-audit'
const read=(p:string)=>JSON.parse(readFileSync(p,'utf8'))
export function repairK6Trace(before:any,source:any){
 if(before.type!=='pcb_trace'||before.pcb_trace_id!=='pcb_trace_3'||before.source_trace_id!=='source_trace_3'||source.source_trace_id!=='source_trace_3'||source.name!=='FIXED_DROP_K6'||objectHash(source.connected_source_port_ids)!==objectHash(['source_port_167','source_port_488']))throw Error('CPU source identity mismatch')
 const xy=[[9.2,-.4],[9.2,-1.2],[9.6,-1.6],[9.6,-1.6]]
 if(before.route.length!==xy.length||before.route.some((p:any,i:number)=>p.route_type!=='wire'||p.layer!=='top'||p.width!==.08128||Math.hypot(p.x-xy[i]![0]!,p.y-xy[i]![1]!)>1e-8)||before.route[0].start_pcb_port_id!=='pcb_port_167'||before.route.at(-1).end_pcb_port_id!=='pcb_port_488')throw Error('CPU source geometry/endpoints changed')
 const route=[structuredClone(before.route[0]),{route_type:'wire',x:9,y:-.6,width:.08128,layer:'top'},{route_type:'wire',x:9,y:-1,width:.08128,layer:'top'},structuredClone(before.route[1]),structuredClone(before.route[2]),structuredClone(before.route[3])]
 for(const p of route)p.width=.1016
 return{...structuredClone(before),route,trace_length:route.slice(1).reduce((sum,p,i)=>sum+Math.hypot(p.x-route[i].x,p.y-route[i].y),0)}
}
export async function repairCpuSupply(parentDir:string,outDir:string,captureDir:string){
 if(resolve(parentDir)===resolve(outDir))throw Error('Output must be isolated')
 const fileHash=(p:string)=>createHash('sha256').update(readFileSync(p)).digest('hex'),inputHashes=Object.fromEntries(['candidate.circuit.json','report.json','host-bundle.json','routing-input.json','ram-power-launch-audit.json'].map(n=>[resolve(parentDir,n),fileHash(resolve(parentDir,n))])),capture=verifyDdrCapture(captureDir)
 const parent=read(`${parentDir}/candidate.circuit.json`),prior=read(`${parentDir}/report.json`),host=read(`${parentDir}/host-bundle.json`),input=read(`${parentDir}/routing-input.json`),oldPower=read(`${parentDir}/ram-power-launch-audit.json`),index=parent.findIndex((e:any)=>e.type==='pcb_trace'&&e.pcb_trace_id==='pcb_trace_3'),before=parent[index],source=parent.find((e:any)=>e.type==='source_trace'&&e.source_trace_id==='source_trace_3')
 if(capture.captureHash!==prior.captureHash||prior.launchAuditSha256!==objectHash(oldPower))throw Error('Capture/power provenance mismatch')
 for(const [path,hash] of Object.entries(prior.inputFileHashes??{}))if(fileHash(path)!==hash)throw Error(`Parent input changed ${path}`)
 if(prior.candidateCircuitSha256!==objectHash(parent)||host.captureHash!==prior.captureHash||host.traces.length!==11||oldPower.launchQualified!==56)throw Error('Expected exact11host/56power parent')
 const after=repairK6Trace(before,source),child=structuredClone(parent);child[index]=after
 const pad=parent.find((e:any)=>e.type==='pcb_smtpad'&&e.pcb_port_id==='pcb_port_167'),ports=['pcb_port_167','pcb_port_488'].map(id=>parent.find((e:any)=>e.type==='pcb_port'&&e.pcb_port_id===id)),supplyVia=parent.find((e:any)=>e.type==='pcb_via'&&e.pcb_via_id==='pcb_via_0')
 if(!pad||!supplyVia||ports.some((p:any,i:number)=>!p||p.source_port_id!==source.connected_source_port_ids[i])||!source.connected_source_net_ids.includes(supplyVia.source_net_id)||Math.hypot(pad.x-after.route[0].x,pad.y-after.route[0].y)>1e-8||Math.hypot(supplyVia.x-after.route.at(-1).x,supplyVia.y-after.route.at(-1).y)>1e-8)throw Error('Actual pad/source-owned supply via mismatch')
 const endpointWitness={pad,ports,supplyVia,continuousSourceOwnedTrace:true},planeHash=objectHash(parent.filter((e:any)=>e.type==='pcb_copper_pour'))
 const manifest={captureHash:prior.captureHash,parentDirectory:resolve(parentDir),parentCircuitSha256:objectHash(parent),candidateCircuitSha256:objectHash(child),endpointWitness,planeHash,inputHashes,sourceWitness:source,sourceWitnessSha256:objectHash(source),replacements:[{id:'pcb_trace:pcb_trace_3',before,after,beforeSha256:objectHash(before),afterSha256:objectHash(after),reason:'Approach L6 branch diagonally through two45degree turns; widen entire revised supply trace from0.08128 to0.1016mm; retain actual K6 and supply endpoint identities.'}]},preservation=validateDeclaredDdrReplacements(parent,child,manifest)
 const hostIds=new Set(host.traces.map((t:any)=>t.pcb_trace_id)),actualHosts=child.filter((e:any)=>e.type==='pcb_trace'&&hostIds.has(e.pcb_trace_id)),fresh=[...actualHosts,after],freshIds=new Set(fresh.map((t:any)=>t.pcb_trace_id)),physical=verifyDdrSystemCopper(child.filter((e:any)=>e.type!=='pcb_trace'||!freshIds.has(e.pcb_trace_id)),fresh,input.connections,{}),allJunctions=auditDdrTraceJunctions(child,input.connections),allAngles=auditRouteAngles(child.filter((e:any)=>e.type==='pcb_trace'))
 if(host.traces.some((t:any)=>objectHash(t)!==objectHash(actualHosts.find((e:any)=>e.pcb_trace_id===t.pcb_trace_id))))throw Error('Actual host bundle geometry differs')
 const accepted=!physical.errors.length&&!physical.violations.length&&physical.angles.valid&&!physical.joinedBends.length&&allJunctions.valid&&allAngles.valid&&actualHosts.length===11&&actualHosts.every((t:any)=>physical.connectivity.some((c:any)=>c.name===t.connection_name&&c.connected))
 mkdirSync(outDir,{recursive:true});const write=(n:string,v:any)=>writeFileSync(`${outDir}/${n}`,JSON.stringify(v,null,2))
 write('repair-evidence.json',{endpointWitness,unchangedPlanesSha256:planeHash,inputHashes,captureHash:prior.captureHash,accepted,preservation,manifest,physical,allJunctions,allAngles})
 if(!accepted)throw Error(`CPU supply repair rejected; inspect ${outDir}/repair-evidence.json`)
 if(Object.entries(inputHashes).some(([path,hash])=>fileHash(path)!==hash)||verifyDdrCapture(captureDir).captureHash!==capture.captureHash)throw Error('Inputs changed during physical verification')
 const planeAudit=refreshDdrPlaneContacts(prior.planeAudit,child.filter((e:any)=>e.type==='pcb_copper_pour'),child)
 write('candidate.circuit.json',child);write('original-copper-replacements.json',manifest)
 for(const n of['host-bundle.json','routing-input.json','exit-contract.json','ram-byte0-facing-progress.trace-paths.json'])copyFileSync(`${parentDir}/${n}`,`${outDir}/${n}`)
 const report={...prior,candidateCircuitSha256:objectHash(child),parentReportSha256:objectHash(prior),inputHashes,endpointWitness,unchangedPlanesSha256:planeHash,supportValidation:preservation,originalCopperReplacementsSha256:objectHash(manifest),physical,fullCandidateAngles:allAngles,fixedJunctionAudit:allJunctions,planeAudit,scope:'One explicitly witnessed CPU K6 supply trace replacement. All11host routes,56qualifiedRAMpower paths, source objects, components, planes and other copper exact; all-candidate angles/junctions checked.'};write('report.json',report)
 const run=spawnSync(process.execPath,[resolve(import.meta.dir,'audit-ddr-global-power-launches.ts'),outDir,captureDir],{encoding:'utf8'});if(run.status!==0)throw Error(run.stderr)
 const power=read(`${outDir}/ram-power-launch-audit.json`)
 if(power.total!==60||power.launchQualified!==56||power.planeConnected!==56||oldPower.rows.some((r:any)=>r.launchWithin1524Mm&&!power.rows.some((n:any)=>n.byte===r.byte&&n.ball===r.ball&&n.launchWithin1524Mm)))throw Error('RAM power preservation audit failed')
 Object.assign(report,{launchAuditSha256:objectHash(power)});write('report.json',report)
 return{output:resolve(outDir),candidateCircuitSha256:objectHash(child),accepted,changedObjects:1,connectedHosts:11,qualifiedPower:56,minClearanceMm:physical.minClearanceMm,errors:physical.errors.length,violations:physical.violations.length,allJunctionViolations:allJunctions.joinedBends.length,allAngleViolations:allAngles.violations.length}
}
if(import.meta.main){const [parent='dist/ddr-facing-progress',out='dist/ddr-facing-progress-45',capture='dist/ddr-system/host-taps-54af3e346b5e']=process.argv.slice(2);console.log(JSON.stringify(await repairCpuSupply(parent,out,capture),null,2))}