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/assemble-ddr-d8-connected.ts

/** One exactly witnessed host addition; both RAM profile caches remain unchanged. */
import{readFileSync,writeFileSync,mkdirSync}from'node:fs'
import{resolve}from'node:path'
import{createHash}from'node:crypto'
import{verifyDdrCapture}from'./ddr-capture-provenance'
import{auditCompositeHostTopology}from'./ddr-composite-routing-context'
import{auditRouteAngles}from'./check-route-angles'
import{auditDdrTraceJunctions}from'./check-ddr-system-copper'
import{checkHostTerminalContract}from'./route-ddr-sequential'
import{refreshDdrPlaneContacts}from'./ddr-plane-contact-audit'
const[capture,parentDir,routeDir,out]=process.argv.slice(2),bound:Record<string,string>={},fh=(p:string)=>createHash('sha256').update(readFileSync(p)).digest('hex'),read=(p:string)=>{p=resolve(p);bound[p]=fh(p);return JSON.parse(readFileSync(p,'utf8'))},hash=(x:any)=>createHash('sha256').update(JSON.stringify(x)).digest('hex'),{captureHash}=verifyDdrCapture(capture),parent=read(resolve(parentDir,'candidate.circuit.json')),prior=read(resolve(parentDir,'report.json')),ph=read(resolve(parentDir,'host-bundle.json')),input=read(resolve(parentDir,'routing-input.json')),route=read(resolve(routeDir,'candidate.circuit.json')),rh=read(resolve(routeDir,'host-bundle.json')),rr=read(resolve(routeDir,'report.json')),m=read(resolve(routeDir,'original-copper-replacements.json'))
if([prior,ph,rh,rr,m].some(x=>x.captureHash!==captureHash)||!rr.accepted||hash(parent)!==m.parentCircuitSha256||hash(parent)!==prior.candidateCircuitSha256||hash(route)!==m.candidateCircuitSha256||m.removals.length!==0||m.additions.length!==1||m.additions[0].source_trace_id!=='source_trace_686'||m.replacements.length!==3||ph.traces.length!==16||rh.traces.length!==17)throw Error('D8 provenance/count differs')
for(const[p,h]of Object.entries(rr.inputHashes)){if(fh(p)!==h)throw Error('Stale routing input');bound[p]=h as string}
for(const w of m.replacements)if(w.before.type!=='pcb_copper_pour'||w.after.type!=='pcb_copper_pour'||w.before.pcb_copper_pour_id!==w.after.pcb_copper_pour_id||hash(parent.find((e:any)=>e.pcb_copper_pour_id===w.before.pcb_copper_pour_id))!==hash(w.before))throw Error('Unexpected plane replacement')
const candidate=[...parent.map((e:any)=>e.type==='pcb_copper_pour'?m.replacements.find((w:any)=>w.before.pcb_copper_pour_id===e.pcb_copper_pour_id).after:e),m.additions[0]],sorted=(a:any[])=>a.map(hash).sort();if(hash(sorted(candidate))!==hash(sorted(route))||hash(rh.traces)!==hash([...ph.traces,...m.additions]))throw Error('Undeclared D8 source/host change')
const topology=auditCompositeHostTopology(candidate,rh.traces,input.connections),angles=auditRouteAngles(candidate.filter((e:any)=>e.type==='pcb_trace')),junctions=auditDdrTraceJunctions(candidate,input.connections),terminal=checkHostTerminalContract(rh.traces,input.connections.filter((c:any)=>rh.traces.some((t:any)=>t.connection_name===c.name))),planeAudit=refreshDdrPlaneContacts(prior.planeAudit,candidate.filter((e:any)=>e.type==='pcb_copper_pour'),candidate)
if(!topology.valid||!angles.valid||!junctions.valid||!terminal.valid||topology.physical.connectivity.filter(c=>c.connected).length!==17||rr.fullPlanarMm>27.3001+1e-7)throw Error('D8 actual geometry/nominal failure')
mkdirSync(out,{recursive:true});const write=(n:string,v:any)=>writeFileSync(resolve(out,n),JSON.stringify(v,null,2)+'\n'),manifest={...m,parentDirectory:resolve(parentDir),candidateCircuitSha256:hash(candidate),inputHashes:bound},report={...prior,accepted:true,captureHash,candidateCircuitSha256:hash(candidate),supportCircuitSha256:hash(candidate),hostTracesSha256:hash(rh.traces),hostBundleSha256:hash(rh),originalCopperReplacementsSha256:hash(manifest),connectedHostCount:17,preservedHostCount:16,physical:topology.physical,topology,fullCandidateAngles:angles,fixedJunctionAudit:junctions,terminalContract:terminal,planeAudit,d8Evidence:{fullPlanarMm:rr.fullPlanarMm,nominalMm:27.3001,hostViaCount:1},inputFileHashes:bound,scope:'Seventeen geometrically connected hosts. D8 original RAM escape preserved, CPUtop-to-RAMinner4 host via at(-5.5,1). D8below nominal butnot DQS1matched; several other lengths also unmatched.33signals/fourpowerlaunches and complete electrical qualification remain unresolved.'}
write('candidate.circuit.json',candidate);write('host-bundle.json',rh);write('routing-input.json',{...input,traces:rh.traces,obstacles:undefined});write('report.json',report);write('host-route-report.json',rr);write('original-copper-replacements.json',manifest);write('source-provenance.json',{captureHash,inputHashes:bound,parentReportSha256:hash(prior),routeManifest:m});for(const n of['ram-byte0-facing-progress.trace-paths.json','ram-byte1-facing-progress.trace-paths.json']){const c=read(resolve(parentDir,n));if(c.length!==72||!auditRouteAngles(c).valid)throw Error('RAM cache invalid');write(n,c)}for(const n of['exit-contract.json','ram-byte1-exit-contract.json'])write(n,{...read(resolve(parentDir,n)),candidateCircuitSha256:hash(candidate),scope:report.scope})
for(const script of['audit-ddr-global-power-launches.ts','audit-ddr-host-reference-coverage.ts']){const p=Bun.spawn(['bun',`scripts/${script}`,resolve(out),resolve(capture)],{stdout:'inherit',stderr:'inherit'});if(await p.exited)throw Error(`Audit failed ${script}`)}const power=read(resolve(out,'ram-power-launch-audit.json')),reference=read(resolve(out,'host-reference-coverage.json'));if(power.launchQualified!==56||power.total!==60)throw Error('Power changed');for(const[p,h]of Object.entries(bound))if(fh(p)!==h)throw Error('Inputs changed');verifyDdrCapture(capture);write('report.json',{...report,launchQualified:56,launchAuditSha256:hash(power),hostReferenceCoverageSha256:hash(reference)});const budgets=Bun.spawn(['bun','scripts/audit-ddr-current-byte-budgets.ts',resolve(capture),resolve(out),resolve(out,'current-byte-budgets.json')],{stdout:'inherit',stderr:'inherit'});if(await budgets.exited)throw Error('Byte audit failed');console.log(JSON.stringify({hosts:17,power:56,fullPlanarMm:rr.fullPlanarMm,candidateCircuitSha256:hash(candidate)}))