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-dqs1-shorter.ts
/** Exactly replace two DQS1 hosts; no saved copper, exits or planes change. */
import{readFileSync,writeFileSync,mkdirSync,existsSync}from'node:fs'
import{resolve}from'node:path'
import{createHash}from'node:crypto'
import{verifyDdrCapture}from'./ddr-capture-provenance'
import{objectHash}from'./improve-ddr-a9-power-launches'
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'
const[capture,parent,proposal,out]=process.argv.slice(2);if(!out)throw Error('Usage: capture parent shortened-pair output')
const hashes:Record<string,string>={},fh=(p:string)=>createHash('sha256').update(readFileSync(p)).digest('hex'),read=(p:string)=>{p=resolve(p);hashes[p]=fh(p);return JSON.parse(readFileSync(p,'utf8'))}
const{captureHash}=verifyDdrCapture(capture),before=read(resolve(parent,'candidate.circuit.json')),prior=read(resolve(parent,'report.json')),oldHost=read(resolve(parent,'host-bundle.json')),input=read(resolve(parent,'routing-input.json')),r=read(resolve(proposal,'report.json')),changes=read(resolve(proposal,'replacements.json')),candidate=read(resolve(proposal,'candidate.circuit.json')),host=read(resolve(proposal,'host-bundle.json'))
if(!r.accepted||r.captureHash!==captureHash||r.parentCandidateSha256!==objectHash(before)||prior.candidateCircuitSha256!==objectHash(before)||oldHost.captureHash!==captureHash||host.captureHash!==captureHash||changes.length!==2)throw Error('Stale pair proposal')
for(const[p,h]of Object.entries(r.inputHashes??{})){if(fh(p)!==h)throw Error('Stale pair input');hashes[p]=h as string}
for(const c of changes){const{route:old,...om}=c.before,{route:next,...nm}=c.after;if(!['source_trace_675','source_trace_676'].includes(c.before.source_trace_id)||objectHash(om)!==objectHash(nm)||objectHash(old[0])!==objectHash(next[0])||objectHash(old.at(-1))!==objectHash(next.at(-1))||next.some((p:any)=>p.route_type!=='wire'||p.layer!=='inner4'||p.width!==.12)||objectHash(before.find((e:any)=>e.type==='pcb_trace'&&e.pcb_trace_id===c.before.pcb_trace_id))!==objectHash(c.before))throw Error('Pair identity/endpoint/layer change')}
if(new Set(changes.map((c:any)=>c.before.source_trace_id)).size!==2)throw Error('Duplicate pair member')
const replay=(xs:any[])=>xs.map((e:any)=>e.type==='pcb_trace'?changes.find((c:any)=>c.before.pcb_trace_id===e.pcb_trace_id)?.after??e:e)
if(objectHash(replay(before))!==objectHash(candidate)||objectHash({...oldHost,traces:replay(oldHost.traces)})!==objectHash(host))throw Error('Undeclared pair changes')
const topology=auditCompositeHostTopology(candidate,host.traces,input.connections),angles=auditRouteAngles(candidate.filter((e:any)=>e.type==='pcb_trace')),junctions=auditDdrTraceJunctions(candidate,input.connections),terminal=checkHostTerminalContract(host.traces,input.connections.filter((c:any)=>host.traces.some((t:any)=>t.connection_name===c.name)))
const auditPath=resolve('/Users/ankan/Documents/Codex/2026-09-10/what-x20/outputs/mt41k512m8da-107-it-p-fanout/scripts/audit-am3352-dqs-pair.ts');hashes[auditPath]=fh(auditPath);if(hashes[auditPath]!==r.externalPairAuditorSha256)throw Error('Pair auditor changed')
const{verifyHostDqsPair}=await import(auditPath),pairConnections=input.connections.filter((c:any)=>c.ramByte===1&&['DQS_P','DQS_N'].includes(c.ramTerminal)),pairTraces=pairConnections.map((c:any)=>host.traces.find((t:any)=>t.connection_name===c.name)),hostIds=new Set(host.traces.map((t:any)=>t.pcb_trace_id)),pair=verifyHostDqsPair({...input,connections:pairConnections},candidate.filter((e:any)=>!hostIds.has(e.pcb_trace_id)),pairTraces)
if(!topology.valid||!angles.valid||!junctions.valid||!terminal.valid||topology.physical.connectivity.filter((c:any)=>c.connected).length!==host.traces.length||pair.status!=='pair-geometry-pass'||pair.metrics.length!==2||pair.metrics.some((m:any)=>!Number.isFinite(m.fullLengthMm)||m.fullLengthMm>r.nominalMm+1e-7))throw Error('Pair actual gates failed')
const copied:Record<string,any>={};for(const n of['ram-byte0-facing-progress.trace-paths.json','ram-byte1-facing-progress.trace-paths.json','exit-contract.json','ram-byte1-exit-contract.json'])if(existsSync(resolve(parent,n))){copied[n]=read(resolve(parent,n));if(n.includes('contract'))copied[n]={...copied[n],candidateCircuitSha256:objectHash(candidate)}}
const manifest={captureHash,parentDirectory:resolve(parent),parentCircuitSha256:objectHash(before),candidateCircuitSha256:objectHash(candidate),replacements:changes.map((c:any)=>({...c,id:`pcb_trace:${c.before.pcb_trace_id}`})),allOtherElementsExact:true,inputHashes:hashes}
const report={...prior,accepted:true,captureHash,candidateCircuitSha256:objectHash(candidate),supportCircuitSha256:objectHash(candidate),hostTracesSha256:objectHash(host.traces),hostBundleSha256:objectHash(host),originalCopperReplacementsSha256:objectHash(manifest),physical:topology.physical,topology,fullCandidateAngles:angles,fixedJunctionAudit:junctions,terminalContract:terminal,dqs1Evidence:{pair,targetMm:r.targetMm,nominalMm:r.nominalMm},inputFileHashes:hashes,scope:'DQS1 shortened below nominal maximum with paired geometry retained. Data matching, missing signals, four power launches and full electrical qualification remain incomplete.'}
const unchanged=()=>{verifyDdrCapture(capture);for(const[p,h]of Object.entries(hashes))if(fh(p)!==h)throw Error('Assembly input changed')};unchanged();mkdirSync(out,{recursive:true});const write=(n:string,v:any)=>writeFileSync(resolve(out,n),JSON.stringify(v,null,2)+'\n')
write('candidate.circuit.json',candidate);write('host-bundle.json',host);write('routing-input.json',{...input,traces:host.traces,obstacles:undefined});write('report.json',report);write('original-copper-replacements.json',manifest);write('source-provenance.json',{captureHash,inputHashes:hashes,proposalReport:r});for(const[n,v]of Object.entries(copied))write(n,v)
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!==0)throw Error(`Failed ${script}`)}
const power=JSON.parse(readFileSync(resolve(out,'ram-power-launch-audit.json'),'utf8'));if(power.launchQualified!==56||power.total!==60)throw Error('Power regression');unchanged();write('report.json',{...report,launchAuditSha256:objectHash(power),launchQualified:56});console.log(JSON.stringify({accepted:true,out,pair:pair.metrics}))