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/prepare-ddr-d13-host-parent.ts
/** Exact local D13 escape replay on the explicit current parent. */
import{verifyDdrCapture}from'./ddr-capture-provenance';import{readFileSync,writeFileSync,mkdirSync,copyFileSync}from'node:fs';import{resolve}from'node:path';import{objectHash as hash}from'./improve-ddr-a9-power-launches';import{applyFacingExitReplacements}from'./ddr-facing-context';import{auditCompositeHostTopology}from'./ddr-composite-routing-context';import{auditDdrLocalEscapeContacts}from'./audit-ddr-local-escape-contacts';import{verifyDdrSystemCopper,auditDdrTraceJunctions}from'./check-ddr-system-copper';import{auditRouteAngles}from'./check-route-angles';
const bound=new Map<string,string>();verifyDdrCapture('dist/ddr-system/host-taps-54af3e346b5e');
const [parentArg='dist/ddr-nineteen-d10-connected',localArg='dist/ddr-eighteen-d13-facing',outArg='dist/ddr-nineteen-d13-facing']=process.argv.slice(2);const parent=resolve(parentArg),local=resolve(localArg),out=resolve(outArg),read=(p:string)=>{const v=JSON.parse(readFileSync(p,'utf8'));if(!p.startsWith(out+'/'))bound.set(p,hash(v));return v},c=read(parent+'/candidate.circuit.json'),h=read(parent+'/host-bundle.json'),prior=read(parent+'/report.json'),input=read(parent+'/routing-input.json'),changes=read(local+'/replacements.json'),candidate=applyFacingExitReplacements(c,changes),connections=input.connections.map((n:any)=>({...n,pointsToConnect:n.pointsToConnect.map((p:any)=>p.pointId===changes.breakoutPoints[0].before.pcb_breakout_point_id?{...p,x:changes.breakoutPoints[0].after.x,y:changes.breakoutPoints[0].after.y,layer:changes.breakoutPoints[0].after.layer}:p)})),topology=auditCompositeHostTopology(candidate,h.traces,connections),fresh=[...h.traces,changes.traces[0].after],ids=new Set(fresh.map((t:any)=>t.pcb_trace_id)),physical=verifyDdrSystemCopper(candidate.filter((e:any)=>!ids.has(e.pcb_trace_id)),fresh,connections,{}),localContacts=auditDdrLocalEscapeContacts(candidate,changes.traces[0].after,connections),angles=auditRouteAngles(candidate.filter((e:any)=>e.type==='pcb_trace')),joins=auditDdrTraceJunctions(candidate,connections);if(hash(c)!==prior.candidateCircuitSha256||h.traces.length<19||!topology.valid||!localContacts.valid||!angles.valid||!joins.valid||physical.errors.length||physical.violations.length){mkdirSync(out,{recursive:true});writeFileSync(out+'/replay-diagnostic.json',JSON.stringify({accepted:false,parentHash:hash(c),expectedParentHash:prior.candidateCircuitSha256,topology,localContacts,angles,joins,physical},null,2));throw Error('D13replayinvalid')};
const localTrace=changes.traces[0].after,end=localTrace.route.at(-1),previous=[...localTrace.route].reverse().find((p:any)=>p.route_type==='wire'&&p.layer===end.layer&&Math.hypot(p.x-end.x,p.y-end.y)>1e-7),d=Math.hypot(end.x-previous.x,end.y-previous.y),collar={route_type:'wire',x:end.x+.2*(end.x-previous.x)/d,y:end.y+.2*(end.y-previous.y)/d,layer:end.layer,width:end.width};
const collarPhysical=verifyDdrSystemCopper(candidate.filter((e:any)=>!ids.has(e.pcb_trace_id)),[...h.traces,{...localTrace,route:[...localTrace.route,collar]}],connections,{});if(collarPhysical.errors.length||collarPhysical.violations.length)throw Error('Rebased outward collar fails');
mkdirSync(out,{recursive:true});const write=(n:string,v:any)=>writeFileSync(out+'/'+n,JSON.stringify(v,null,2)+'\n'),manifest={captureHash:prior.captureHash,parentDirectory:parent,parentCircuitSha256:hash(c),candidateCircuitSha256:hash(candidate),replacements:[...changes.traces,...changes.breakoutPoints].map((r:any)=>({...r,beforeSha256:hash(r.before),afterSha256:hash(r.after)}))};write('replacements.json',changes);write('candidate.circuit.json',candidate);write('host-bundle.json',h);write('routing-input.json',{...input,traces:h.traces,connections});write('original-copper-replacements.json',manifest);write('report.json',{...prior,candidateCircuitSha256:hash(candidate),supportCircuitSha256:hash(candidate),fullCandidateAngles:angles,fixedJunctionAudit:joins,hostTracesSha256:hash(h.traces),originalCopperReplacementsSha256:hash(manifest),ramByte1CacheSha256:hash(read(local+'/ram-byte1-facing-progress.trace-paths.json')),hostBundleSha256:hash(h),outwardCollarEvidence:{lengthMm:.2,physical:collarPhysical},physical,topology,localContacts,allAngles:angles,allJunctions:joins,connectedHostCount:h.traces.length,preservedHostCount:h.traces.length,scope:`Isolated ${h.traces.length}-host board with exact local escape override; no new host accepted.`});const sourcePort=c.find((e:any)=>e.type==='source_port'&&e.source_port_id===changes.breakoutPoints[0].before.source_port_id),ball=sourcePort?.name?.replace('ball_','');if(!['E7','E8'].includes(ball))throw Error('Unsupported exact local ball');const currentCache=read(parent+'/ram-byte1-facing-progress.trace-paths.json'),localCache=read(local+'/ram-byte1-facing-progress.trace-paths.json'),selected=localCache.find((p:any)=>p.connection===`U1.ball_${ball}`);if(!selected)throw Error('Missing D13 cache');const placement=verifyDdrCapture('dist/ddr-system/host-taps-54af3e346b5e').snapshot.placements[1],expected=localTrace.route.map((p:any)=>p.route_type==='wire'?{route_type:'wire',x:placement.pcbX-p.x,y:placement.pcbY-p.y,layer:p.layer,width:p.width}:{route_type:'via',x:placement.pcbX-p.x,y:placement.pcbY-p.y,from_layer:p.from_layer,to_layer:p.to_layer,via_diameter:p.via_diameter,via_hole_diameter:p.via_hole_diameter});if(hash(selected.route)!==hash(expected))throw Error('Selected cache differs from exact physical replacement');const merged=currentCache.map((p:any)=>p.connection===selected.connection?selected:p);write('ram-byte1-facing-progress.trace-paths.json',merged);for(const n of['ram-byte0-facing-progress.trace-paths.json','source-provenance.json'])copyFileSync(parent+'/'+n,out+'/'+n);const baseContract=read(parent+'/ram-byte1-exit-contract.json'),localContract=read(local+'/ram-byte1-exit-contract.json'),changedBalls=[...new Set([...baseContract.changedBalls,ball])];write('ram-byte1-exit-contract.json',{...baseContract,changedBalls,unchangedPaths:72-changedBalls.length,ramByte1CacheSha256:hash(merged),exits:[...baseContract.exits.filter((p:any)=>p.ball!==ball),localContract.exits.find((p:any)=>p.ball===ball)],candidateCircuitSha256:hash(candidate),scope:`Isolated current board with additional ${ball} facing escape; host remains unconnected.`});write('exit-contract.json',{...read(parent+'/exit-contract.json'),candidateCircuitSha256:hash(candidate)});console.log(JSON.stringify({out,hosts:h.traces.length,candidateSha:hash(candidate)}))
for(const argv of [['scripts/audit-ddr-global-power-launches.ts',out,'dist/ddr-system/host-taps-54af3e346b5e'],['scripts/audit-ddr-host-reference-coverage.ts',out],['scripts/audit-ddr-current-byte-budgets.ts','dist/ddr-system/host-taps-54af3e346b5e',out,out+'/current-byte-budgets.json']]){const p=Bun.spawn(['bun',...argv],{stdout:'ignore',stderr:'inherit'});if(await p.exited!==0)throw Error('Fresh audit failed')}
for(const[p,h]of bound)if(hash(JSON.parse(readFileSync(p,'utf8')))!==h)throw Error('Parent input changed');verifyDdrCapture('dist/ddr-system/host-taps-54af3e346b5e');const power=read(out+'/ram-power-launch-audit.json'),parentPower=read(parent+'/ram-power-launch-audit.json');if(power.launchQualified<parentPower.launchQualified||power.total!==parentPower.total||parentPower.rows.filter((r:any)=>r.planeContact&&r.launchWithin1524Mm).some((r:any)=>!power.rows.some((q:any)=>q.byte===r.byte&&q.terminal===r.terminal&&q.padId===r.padId&&q.planeContact&&q.launchWithin1524Mm)))throw Error('Power launch regression');write('report.json',{...read(out+'/report.json'),inputObjectHashes:Object.fromEntries(bound),launchQualified:power.launchQualified,launchAuditSha256:hash(power),hostReferenceCoverageSha256:hash(read(out+'/host-reference-coverage.json'))});
const cacheEnvelope=(paths:any[])=>{if(paths.length!==72)throw Error('Incomplete cache');const q=paths.flatMap(p=>p.route).map(p=>{const dia=p.route_type==='via'?p.via_diameter:p.width;if(!Number.isFinite(dia)||dia<=0)throw Error('Missing physical radius');return {...p,r:dia/2}});return{minX:Math.min(...q.map(p=>p.x-p.r)),maxX:Math.max(...q.map(p=>p.x+p.r)),minY:Math.min(...q.map(p=>p.y-p.r)),maxY:Math.max(...q.map(p=>p.y+p.r))}}
const cacheEvidence=[0,1].map(byte=>{const cacheName=`ram-byte${byte}-facing-progress.trace-paths.json`,cache=read(out+'/'+cacheName),before=read(parent+'/'+cacheName),a=cacheEnvelope(before),b=cacheEnvelope(cache),growth={left:Math.max(0,a.minX-b.minX),right:Math.max(0,b.maxX-a.maxX),bottom:Math.max(0,a.minY-b.minY),top:Math.max(0,b.maxY-a.maxY)};if(Object.values(growth).some(x=>x>1e-7))throw Error('Physical cache envelope grew');const ctName=byte===0?'exit-contract.json':'ram-byte1-exit-contract.json',ct=read(out+'/'+ctName),next={...ct,scope:`${h.traces.length} geometrically connected hosts; ${50-h.traces.length} interface nets remain unconnected. RAM${byte}: ${ct.changedBalls.length} changed paths and ${72-ct.changedBalls.length} unchanged paths versus frozen capture. ${ball} local escape is prepared but its host is unconnected. Zero cached-copper envelope growth; full DDR qualification remains incomplete.`,candidateCircuitSha256:hash(candidate),ramCacheSha256:hash(cache),metadataProvenance:{inheritedContractSha256:hash(ct),parentDirectory:parent,candidateCircuitSha256:hash(candidate),cacheSha256:hash(cache)}};write(ctName,next);return{byte,parentEnvelope:a,newEnvelope:b,paddingGrowthMm:growth,scope:'All72 cache trace widths and via radii; unchanged pads/support outside cache excluded.',cacheSha256:hash(cache),contractSha256:hash(next)}})
write('cache-envelope-audit.json',{candidateCircuitSha256:hash(candidate),bytes:cacheEvidence});write('report.json',{...read(out+'/report.json'),ramByte1CacheSha256:cacheEvidence[1].cacheSha256,exitContractProvenance:{parentDirectory:parent,candidateCircuitSha256:hash(candidate),contracts:cacheEvidence.map(e=>({byte:e.byte,contractSha256:e.contractSha256,cacheSha256:e.cacheSha256}))},cacheEnvelopeAuditSha256:hash(read(out+'/cache-envelope-audit.json'))});
const finalBudget=Bun.spawn(['bun','scripts/audit-ddr-current-byte-budgets.ts','dist/ddr-system/host-taps-54af3e346b5e',out,out+'/current-byte-budgets.json'],{stdout:'ignore',stderr:'inherit'});if(await finalBudget.exited!==0)throw Error('Final metadata-bound budget audit failed');
write('source-provenance.json',{inherited:read(parent+'/source-provenance.json'),parentDirectory:parent,parentCircuitSha256:hash(c),candidateCircuitSha256:hash(candidate),currentManifestSha256:hash(manifest),inputObjectHashes:Object.fromEntries(bound)});
await (await import('./finalize-ddr-evidence-metadata')).finalizeDdrEvidenceMetadata(out,'dist/ddr-system/host-taps-54af3e346b5e');