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-d3-connected.ts

/** Exact witness assembly for the D3 host plus declared DQ0 and plane changes. */
import{readFileSync,writeFileSync,mkdirSync}from'node:fs'
import{resolve}from'node:path'
import{createHash}from'node:crypto'
import{objectHash}from'./improve-ddr-a9-power-launches'
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,railParentDir,out]=process.argv.slice(2);if(!out)throw Error('Usage: capture D3-parent routed-output selfcontained-DQ0-parent output')
const hashes=new Map<string,string>(),fh=(p:string)=>createHash('sha256').update(readFileSync(p)).digest('hex'),read=(p:string)=>{p=resolve(p);hashes.set(p,fh(p));return JSON.parse(readFileSync(p,'utf8'))},bind=(hs:any)=>{for(const[p,h]of Object.entries(hs)){if(fh(p)!==h)throw Error(`Input hash changed ${p}`);hashes.set(p,h as string)}}
const{captureHash}=verifyDdrCapture(capture),parent=read(resolve(parentDir,'candidate.circuit.json')),parentReport=read(resolve(parentDir,'report.json')),priorHost=read(resolve(parentDir,'host-bundle.json')),input=read(resolve(parentDir,'routing-input.json')),cache=read(resolve(parentDir,'ram-byte0-facing-progress.trace-paths.json')),contract=read(resolve(parentDir,'exit-contract.json')),rawCandidate=read(resolve(routeDir,'candidate.circuit.json')),host=read(resolve(routeDir,'host-bundle.json')),raw=read(resolve(routeDir,'raw-traces.json')),routeReport=read(resolve(routeDir,'report.json')),railParent=read(resolve(railParentDir,'candidate.circuit.json')),railReport=read(resolve(railParentDir,'report.json'))
if(!routeReport.accepted||!parentReport.accepted||[routeReport,parentReport,host,railReport].some(r=>r.captureHash!==captureHash)||parentReport.candidateCircuitSha256!==objectHash(parent)||railReport.candidateCircuitSha256!==objectHash(railParent)||raw.length!==1||raw[0].source_trace_id!=='source_trace_578'||host.traces.length!==12||host.layerSpace!=='physical'||parentReport.ramCacheSha256!==objectHash(cache))throw Error('D3 assembly provenance mismatch')
bind(routeReport.inputHashes);bind(parentReport.inputFileHashes)
const d0=routeReport.dq0Replacement;if(d0.captureHash!==captureHash||d0.replacements.length!==1)throw Error('Missing exact DQ0 manifest');const change=d0.replacements[0];if(objectHash(parent.find((e:any)=>e.type==='pcb_trace'&&e.pcb_trace_id===change.before.pcb_trace_id))!==objectHash(change.before)||objectHash(railParent.find((e:any)=>e.type==='pcb_trace'&&e.pcb_trace_id===change.after.pcb_trace_id))!==objectHash(change.after))throw Error('DQ0 before/after witness mismatch')
const planes=rawCandidate.filter((e:any)=>e.type==='pcb_copper_pour'),priorPlanes=parent.filter((e:any)=>e.type==='pcb_copper_pour');if(planes.length!==3||objectHash(priorPlanes)!==objectHash(railParent.filter((e:any)=>e.type==='pcb_copper_pour')))throw Error('Unexpected reference plane baseline')
const planeChanges=planes.map((after:any)=>{const before=priorPlanes.find((p:any)=>p.pcb_copper_pour_id===after.pcb_copper_pour_id);if(!before||before.layer!==after.layer||before.source_net_id!==after.source_net_id)throw Error('Reference plane identity changed');return{id:`pcb_copper_pour:${before.pcb_copper_pour_id}`,before,after}}),replacements=[change,...planeChanges],candidate=[...parent.map((e:any)=>replacements.find((r:any)=>e.type===r.before.type&&e[`${e.type}_id`]===r.before[`${e.type}_id`])?.after??e),...raw]
const sorted=(xs:any[])=>xs.map(objectHash).sort();if(objectHash(sorted(candidate))!==objectHash(sorted(rawCandidate))||objectHash(host.traces)!==objectHash([...priorHost.traces.map((t:any)=>t.pcb_trace_id===change.before.pcb_trace_id?change.after:t),...raw]))throw Error('Undeclared routed-candidate geometry')
const topology=auditCompositeHostTopology(candidate,host.traces,input.connections),allAngles=auditRouteAngles(candidate.filter((e:any)=>e.type==='pcb_trace')),allJunctions=auditDdrTraceJunctions(candidate,input.connections),terminal=checkHostTerminalContract(host.traces,input.connections.filter((c:any)=>host.traces.some((t:any)=>t.connection_name===c.name))),planeAudit=refreshDdrPlaneContacts(railReport.planeAudit,planes,candidate)
if(!topology.valid||!allAngles.valid||!allJunctions.valid||!terminal.valid||topology.physical.connectivity.filter(c=>c.connected).length!==12||!auditRouteAngles(cache).valid||cache.length!==72)throw Error('Actual twelve-host assembly fails checks')
const manifest={captureHash,parentDirectory:resolve(parentDir),parentCircuitSha256:objectHash(parent),candidateCircuitSha256:objectHash(candidate),replacements,additions:raw,allOtherElementsExact:true,ordering:'Original parent order retained; declared new D3 host appended.',sourceDq0Manifest:d0,sourceD3ExitManifest:read(resolve(parentDir,'replacements.json')),inputHashes:Object.fromEntries(hashes)}
const assertUnchanged=()=>{verifyDdrCapture(capture);for(const[p,h]of hashes)if(fh(p)!==h)throw Error('D3 assembly source changed')};assertUnchanged();mkdirSync(out,{recursive:true});const write=(n:string,v:any)=>writeFileSync(resolve(out,n),JSON.stringify(v,null,2)+'\n')
const report={...railReport,accepted:true,captureHash,candidateCircuitSha256:objectHash(candidate),supportCircuitSha256:objectHash(candidate),hostTracesSha256:objectHash(host.traces),hostBundleSha256:objectHash(host),originalCopperReplacementsSha256:objectHash(manifest),connectedHostCount:12,preservedHostCount:10,physical:topology.physical,topology,terminalContract:terminal,fullCandidateAngles:allAngles,fixedJunctionAudit:allJunctions,planeAudit,ramCacheSha256:objectHash(cache),d3Evidence:routeReport,inputFileHashes:Object.fromEntries(hashes),scope:'Twelve physical endpoint-only hosts; DQ0 retuned and D3 connected through one full-depth via. D3 remains short of byte target. Signal via reference changes and return-path/stackup/SI qualification unresolved. Four RAM power launches and remaining DDR interface unresolved.'}
write('candidate.circuit.json',candidate);write('host-bundle.json',host);write('routing-input.json',{...input,traces:host.traces,obstacles:undefined});write('original-copper-replacements.json',manifest);write('report.json',report);write('host-route-report.json',routeReport);write('source-provenance.json',{inputHashes:Object.fromEntries(hashes),parentReport,railParentReportSha256:objectHash(railReport),routeReportSha256:objectHash(routeReport)});write('ram-byte0-facing-progress.trace-paths.json',cache);write('exit-contract.json',{...contract,candidateCircuitSha256:objectHash(candidate),scope:'Actual experimental72-path RAM0 cache including revised D3; twelve hosts now connected, full DDR qualification incomplete.'})
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(`Audit 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 qualification changed');assertUnchanged();write('report.json',{...report,launchAuditSha256:objectHash(power),launchQualified:56,totalRamPowerPads:60});console.log(JSON.stringify({out,hosts:12,power:56,d3FullMm:routeReport.fullPlanarMm}))