@probnaya/057-cli 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -655,4 +655,4 @@ fn fs_main(in: VOut) -> @location(0) vec4f {
|
|
|
655
655
|
let a = in.alpha * (1.0 - in.t);
|
|
656
656
|
return vec4f(in.color * a, a);
|
|
657
657
|
}
|
|
658
|
-
`,Qy=.34,Py=3.4,g0={zoom:1,cx:580,cy:406},rT=-260,lT=1420,uT=-260,oT=1300,cT=.58,fT=.72,uf=1.7,dT=1.45;function hT(n,i){return n==="strata"?i>fT?"environment":"strata":n==="proximity"?i<dT?"environment":"proximity":i<cT?"strata":i>uf?"proximity":"environment"}function pT(n){return n.width/wn.spanX}function Tn(n,i){return pT(i)*n.zoom}function mr(n){return n.zoom=Math.max(Qy,Math.min(Py,n.zoom)),n.cx=Math.max(rT,Math.min(lT,n.cx)),n.cy=Math.max(uT,Math.min(oT,n.cy)),n}function mT(n,i,s){const l=Tn(n,i),u=i.width/l,f=i.height/l;return s.x0=n.cx-u/2,s.y0=n.cy-f/2,s.x1=n.cx+u/2,s.y1=n.cy+f/2,s}function of(n,i,s,l){const u=Tn(s,l),f=l.width/u,d=l.height/u;return[s.cx-f/2+n/u,s.cy-d/2+i/u]}function Bc(n,i,s,l){const u=Tn(s,l),f=l.width/u,d=l.height/u;return[(n-(s.cx-f/2))*u,(i-(s.cy-d/2))*u]}function Gc(n,i,s,l,u){const[f,d]=of(s,l,n,u);n.zoom=Math.max(Qy,Math.min(Py,n.zoom*i));const h=Tn(n,u);n.cx=f-s/h+u.width/h/2,n.cy=d-l/h+u.height/h/2,mr(n)}function y0(n,i,s,l){const u=Tn(n,l);n.cx+=i/u,n.cy+=s/u,mr(n)}function gT(n,i,s,l=7){const u=1-Math.exp(-l*s),f=i.zoom-n.zoom,d=i.cx-n.cx,h=i.cy-n.cy;n.zoom+=f*u,n.cx+=d*u,n.cy+=h*u;const m=Math.abs(f)<.001&&Math.abs(d)<.4&&Math.abs(h)<.4;return m&&(n.zoom=i.zoom,n.cx=i.cx,n.cy=i.cy),m}function yT(n,i,s){return mr({zoom:s,cx:n,cy:i})}const $l=120,vT="field",bT=5,xT=2,v0=30;class ST{intervalMs=new Float32Array($l);cpuMs=new Float32Array($l);cursor=0;filled=0;lastFrameAt=0;frames=0;lastIntervalMs=0;lastCpuMs=0;gpuMs={};disturbances=0;fps=0;resolutionScale=1;get canAdapt(){return this.bakeSamples>0}lastEvalAt=0;pendingResize=!1;bakeSum=0;bakeSamples=0;sample(i,s,l){const u=this.gpuMs[vT];if(u!==void 0&&u>0&&(this.bakeSum+=u,this.bakeSamples++),this.lastFrameAt>0){const f=i-this.lastFrameAt;this.intervalMs[this.cursor]=f,this.cpuMs[this.cursor]=s,this.cursor=(this.cursor+1)%$l,this.filled<$l&&this.filled++,this.lastIntervalMs=f}this.lastFrameAt=i,this.lastCpuMs=s,this.frames++,this.disturbances=l,this.fps=this.averageInterval>0?1e3/this.averageInterval:0,this.maybeAdapt(i)}resetPacing(){this.lastFrameAt=0}get averageInterval(){if(this.filled===0)return 0;let i=0;for(let s=0;s<this.filled;s++)i+=this.intervalMs[s];return i/this.filled}get averageCpuMs(){if(this.filled===0)return 0;let i=0;for(let s=0;s<this.filled;s++)i+=this.cpuMs[s];return i/this.filled}get totalGpuMs(){let i=0;for(const s in this.gpuMs)i+=this.gpuMs[s];return i}bakeCost(){return this.bakeSamples<v0?0:this.bakeSum/this.bakeSamples}maybeAdapt(i){if(i-this.lastEvalAt<2e3||this.filled<45)return;const s=this.bakeCost();this.bakeSamples<v0||(this.lastEvalAt=i,this.bakeSum=0,this.bakeSamples=0,!(s<=0)&&(s>bT&&this.resolutionScale>.5?(this.resolutionScale=Math.max(.5,this.resolutionScale-.15),this.pendingResize=!0):s<xT&&this.resolutionScale<1&&(this.resolutionScale=Math.min(1,this.resolutionScale+.1),this.pendingResize=!0)))}wantsResize(){return this.pendingResize?(this.pendingResize=!1,!0):!1}snapshot(){return{fps:this.fps,intervalMs:this.averageInterval,cpuMs:this.averageCpuMs,gpuMs:this.totalGpuMs,frames:this.frames,scale:this.resolutionScale,disturbances:this.disturbances}}}const Pn=[{rows:22,step:11,amp:.5,alpha:.4,lw:.75,dz:-190,px:44,fill:[5,6,8,.9]},{rows:14,step:9,amp:.74,alpha:.72,lw:.9,dz:-92,px:18,fill:[5,6,8,.94]},{rows:9,step:7.5,amp:1,alpha:1,lw:1,dz:0,px:0,fill:[4,5,7,.965]}],b0={running:0,waiting:1,failed:2,completed:3,idle:4},x0={laptop:[214,176,116],desktop:[168,186,150],server:[150,190,175]},S0=512,wT=[3,2,2],w0=0,E0=1,Ji=2,A0=1,T0=2,ET=4,AT=1600,M0=.004;function TT(n){return n.msSinceInteraction<AT?A0:n.couplings>0||n.maxEnergy>M0?T0:n.maxSettling>M0?ET:n.dirty?A0:1/0}class MT{gpu;surf=null;output;residue;fieldTarget;gpuTimer=null;spans=null;layerSpans=[];probe=null;sheetVariants=new Map;linearSampler;residueFx;fieldFx;sheetDraw;coresDraw;strataDraw;paramsBufs=[];massBuf;distBuf;coupBuf;strataBuf;plinthBuf;params=new Float32Array(36);massArr=new Float32Array(f0*3*4);distArr=new Float32Array(d0*3*4);coupArr=new Float32Array(h0*4);strataArr=new Float32Array(S0*4);plinthArr=new Float32Array(lf*3*4);rect={x0:0,y0:0,x1:0,y1:0};landscape={time:0,masses:[],disturbances:[],plinths:[],couplings:[],strata:[]};massIndex=new Map;runtime=new Map;plinthRuntime=new Map;plinthStatics=new Map;frameSubscribers=new Set;generation=0;lastInstances=0;strataCount=0;disturbanceCount=0;couplingCount=0;massCount=0;plinthCount=0;raf=0;refreshCount=0;lastStride=1;lastDrawnAt=0;nextDrawAt=0;dirty=!0;running=!1;lastFrameAt=0;simTime=0;lastInteractionAt=0;disposed=!1;landscapeDirty=!0;perf=new ST;camera;canvas;headless;maxDpr;initGpu;view={width:1,height:1};constructor(i){if(this.canvas=i.canvas??null,this.headless=i.headless??null,this.camera=i.camera,this.maxDpr=i.maxDpr??1.25,this.initGpu=i.initGpu??(async()=>{try{return await c0({requiredFeatures:["timestamp-query"]})}catch{return await c0()}}),!this.canvas&&!this.headless)throw new Error("FieldRenderer needs either a canvas or a headless size")}async init(){this.gpu=await this.initGpu();try{const f=WA(this.gpu);this.gpuTimer=f,this.spans={residue:f.span("residue"),field:f.span("field"),sheet:f.span("sheet"),overlay:f.span("overlay")},this.layerSpans=[0,1,2].map(d=>f.span(`sheet${d}`)),f.onResults(d=>{this.perf.gpuMs=d,this.probe?.noteGpu(d)}),this.probe?.note("timestamp-query available")}catch(f){this.gpuTimer=null,this.spans=null,this.layerSpans=[],this.probe?.note(`timestamp-query unavailable: ${f instanceof Error?f.message:String(f)}`)}if(this.headless)this.output=s0(this.gpu,{size:[this.headless.width,this.headless.height],format:"rgba8unorm"});else{const f=this.canvas;await DT(f);const d=Math.min(this.maxDpr,globalThis.devicePixelRatio||1),[h,m]=this.cssSize();f.width=Math.round(h*d),f.height=Math.round(m*d),this.surf=EE(this.gpu,f,{dpr:d,autoResize:!0}),this.output=this.surf,this.view.width=h,this.view.height=m}this.residue=IA(this.gpu,p0,p0,{format:"rgba16float"});const[i,s]=this.fieldSize();this.fieldTarget=s0(this.gpu,{size:[i,s],format:"rgba16float"}),this.paramsBufs=Array.from({length:5},()=>Ya(this.gpu,this.params.byteLength,"read")),this.massBuf=Ya(this.gpu,this.massArr.byteLength,"read"),this.distBuf=Ya(this.gpu,this.distArr.byteLength,"read"),this.coupBuf=Ya(this.gpu,this.coupArr.byteLength,"read"),this.strataBuf=Ya(this.gpu,this.strataArr.byteLength,"read"),this.plinthBuf=Ya(this.gpu,this.plinthArr.byteLength,"read");const l=$E(this.gpu,{minFilter:"linear",magFilter:"linear"});this.linearSampler=l,this.residueFx=a0(this.gpu,nT,{set:{P:this.paramsBufs[w0],massData:this.massBuf,distData:this.distBuf,coupData:this.coupBuf,prevTex:this.residue.read,prevSamp:l}}),this.fieldFx=a0(this.gpu,iT,{set:{P:this.paramsBufs[E0],massData:this.massBuf,distData:this.distBuf,coupData:this.coupBuf,residueTex:this.residue.read,residueSamp:l,plinthData:this.plinthBuf}}),this.sheetDraw=Bl(this.gpu,{shader:m0,vertices:6,blend:"premultiplied",set:{P:this.paramsBufs[Ji],massData:this.massBuf,fieldTex:this.fieldTarget,fieldSamp:l}}),this.coresDraw=Bl(this.gpu,{shader:aT,vertices:6,blend:"additive",set:{P:this.paramsBufs[Ji],distData:this.distBuf}}),this.strataDraw=Bl(this.gpu,{shader:sT,vertices:6,blend:"premultiplied",set:{P:this.paramsBufs[Ji],massData:this.massBuf,strataData:this.strataBuf}});const u={colors:[this.output.format]};await Promise.all([this.residueFx.compile(this.residue.write),this.fieldFx.compile(this.fieldTarget),this.sheetDraw.compile(u),this.coresDraw.compile(u),this.strataDraw.compile(u)])}cssSize(){const i=this.canvas;if(!i)return[this.headless.width,this.headless.height];const s=i.parentElement,l=i.clientWidth||s?.clientWidth||1280,u=i.clientHeight||s?.clientHeight||720;return[Math.max(1,l),Math.max(1,u)]}fieldSize(){const i=this.perf.resolutionScale,s=this.headless?.width??this.canvas?.clientWidth??640,l=this.headless?.height??this.canvas?.clientHeight??480,u=Math.max(160,Math.round(Math.min(768,s)*i)),f=Math.max(120,Math.round(Math.min(576,l)*i));return[u,f]}attachProbe(i){this.probe=i}setLandscape(i){const s=this.probe?performance.now():0;this.landscape=i,this.landscapeDirty=!0,this.generation++,this.probe&&(this.probe.landscapes++,queueMicrotask(()=>this.probe?.landscapeMs.push(performance.now()-s)));const l=this.generation;for(const u of i.disturbances){let f=this.runtime.get(u.id);f||(f={energy:0,target:u.energy,status:u.status,statusSince:u.statusSince,seen:l},this.runtime.set(u.id,f)),f.target=u.energy,f.status=u.status,f.statusSince=u.statusSince,f.seen=l}for(const[u,f]of this.runtime)f.seen!==l&&(f.target=0,f.energy<.002&&this.runtime.delete(u));for(const u of i.plinths){let f=this.plinthRuntime.get(u.id);f||(f={presence:0,target:u.presence,x:u.x,y:u.y,extentX:u.extentX,extentY:u.extentY,toX:u.x,toY:u.y,toExtentX:u.extentX,toExtentY:u.extentY,seen:l},this.plinthRuntime.set(u.id,f)),f.target=u.presence,f.toX=u.x,f.toY=u.y,f.toExtentX=u.extentX,f.toExtentY=u.extentY,f.seen=l,this.plinthStatics.set(u.id,u)}for(const[u,f]of this.plinthRuntime)f.seen!==l&&(f.target=0,f.presence<.002&&(this.plinthRuntime.delete(u),this.plinthStatics.delete(u)))}noteInteraction(){this.lastInteractionAt=performance.now(),this.dirty=!0}onFrame(i){return this.frameSubscribers.add(i),()=>this.frameSubscribers.delete(i)}start(){if(this.running||this.disposed)return;this.running=!0,this.lastFrameAt=performance.now(),this.refreshCount=0,this.nextDrawAt=0;const i=s=>{if(!this.running)return;this.raf=requestAnimationFrame(i),this.refreshCount++;const l=this.currentStride(s);if(this.probe?.noteRefresh(s,l),l===1/0){this.perf.resetPacing(),this.lastDrawnAt=0,this.lastFrameAt=s,this.nextDrawAt=this.refreshCount+1;return}if(this.refreshCount<this.nextDrawAt)return;this.nextDrawAt=this.refreshCount+l;const u=s-this.lastFrameAt;this.lastFrameAt=s,this.lastStride=l;const f=this.probe?.debug.fixedDt??null,d=f!==null?f:Math.min(.1,u/1e3);this.renderFrame(d)};this.raf=requestAnimationFrame(i)}stop(){this.running=!1,this.raf&&cancelAnimationFrame(this.raf),this.raf=0}invalidate(){this.dirty=!0}currentStride(i){let s=0,l=0;for(const u of this.runtime.values()){u.energy>s&&(s=u.energy);const f=Math.abs(u.target-u.energy);f>l&&(l=f)}for(const u of this.plinthRuntime.values()){const f=Math.abs(u.target-u.presence);f>l&&(l=f)}return TT({dirty:this.dirty||this.landscapeDirty,msSinceInteraction:i-this.lastInteractionAt,couplings:this.couplingCount,maxEnergy:s,maxSettling:l})}stepPhysics(i){const s=this.simTime;for(const l of this.runtime.values()){let u=l.target;if(l.status==="failed"){const d=Math.max(0,s-l.statusSince/1e3);d<1.4?u=l.target*(1+.45*Math.sin(d*44)):u=l.target*Math.max(0,1-(d-1.4)/2.2)*.22}const f=u>l.energy?2.6:1.1;l.energy+=(u-l.energy)*(1-Math.exp(-f*i)),l.energy<5e-4&&u===0&&(l.energy=0)}for(const l of this.plinthRuntime.values()){const u=l.target>l.presence?1.8:.9;l.presence+=(l.target-l.presence)*(1-Math.exp(-u*i)),l.presence<5e-4&&l.target===0&&(l.presence=0);const f=1-Math.exp(-3*i);l.x+=(l.toX-l.x)*f,l.y+=(l.toY-l.y)*f,l.extentX+=(l.toExtentX-l.extentX)*f,l.extentY+=(l.toExtentY-l.extentY)*f}}packStatics(){const{masses:i,couplings:s,strata:l}=this.landscape;this.massIndex.clear(),this.massArr.fill(0),this.massCount=Math.min(i.length,f0);for(let u=0;u<this.massCount;u++){const f=i[u];this.massIndex.set(f.id,u);const d=u*12;this.massArr[d+0]=f.x,this.massArr[d+1]=f.y,this.massArr[d+2]=f.extentX,this.massArr[d+3]=f.extentY;const h=f.extentX/300;this.massArr[d+4]=72*h,this.massArr[d+5]=27*h,this.massArr[d+6]=30*h,this.massArr[d+7]=.34+f.seed*.12,this.massArr[d+8]=f.seed*Math.PI*2;const m=x0[f.kind]??x0.laptop;this.massArr[d+9]=m[0],this.massArr[d+10]=m[1],this.massArr[d+11]=m[2]}this.massBuf.write(this.massArr),this.coupArr.fill(0),this.couplingCount=0;for(const u of s){if(this.couplingCount>=h0)break;const f=this.massIndex.get(u.fromMassId),d=this.massIndex.get(u.toMassId);if(f===void 0||d===void 0)continue;const h=this.couplingCount*4;this.coupArr[h+0]=f,this.coupArr[h+1]=d,this.coupArr[h+2]=u.energy,this.couplingCount++}this.coupBuf.write(this.coupArr),this.strataArr.fill(0),this.strataCount=Math.min(l.length,S0);for(let u=0;u<this.strataCount;u++){const f=l[u],d=u*4;this.strataArr[d+0]=f.startFraction,this.strataArr[d+1]=f.endFraction,this.strataArr[d+2]=Math.min(f.lane,this.massCount-1),this.strataArr[d+3]=b0[f.status]}this.strataBuf.write(this.strataArr)}packDisturbances(){this.distArr.fill(0);let i=0;for(const s of this.landscape.disturbances){if(i>=d0)break;const l=this.runtime.get(s.id),u=l?l.energy:s.energy;if(u<=5e-4)continue;const f=30+s.extent*44,d=f*(.62+.22*s.extent),h=i*12;this.distArr[h+0]=s.x,this.distArr[h+1]=s.y,this.distArr[h+2]=f,this.distArr[h+3]=d*u,this.distArr[h+4]=.9+s.rate*1.15,this.distArr[h+5]=s.phase,this.distArr[h+6]=b0[s.status],this.distArr[h+7]=u,this.distArr[h+8]=s.articulation,this.distArr[h+9]=s.shoulder,i++}this.disturbanceCount=i,this.distBuf.write(this.distArr)}packPlinths(){this.plinthArr.fill(0);const i=[];let s=0;for(const[l,u]of this.plinthRuntime){if(s>=lf)break;if(u.presence<=5e-4)continue;const f=this.plinthStatics.get(l);if(!f)continue;const d=s*12;this.plinthArr[d+0]=u.x,this.plinthArr[d+1]=u.y,this.plinthArr[d+2]=u.extentX,this.plinthArr[d+3]=u.extentY,this.plinthArr[d+4]=u.presence,this.plinthArr[d+5]=f.articulation,this.plinthArr[d+7]=f.empty?1:0,this.plinthArr[d+8]=f.shoulder,i.push({id:l,parentId:f.parentId}),s++}for(let l=0;l<i.length;l++){const u=i[l].parentId,f=u?i.findIndex(d=>d.id===u):-1;this.plinthArr[l*12+6]=f+1,this.plinthArr[l*12+9]=f>=0?1:0}this.plinthCount=s,this.plinthBuf.write(this.plinthArr)}packParams(i,s,l,u){const f=this.params,d=Tn(this.camera,this.view);f[0]=this.rect.x0,f[1]=this.rect.y0,f[2]=this.rect.x1,f[3]=this.rect.y1,f[4]=this.view.width,f[5]=this.view.height,f[6]=d,f[7]=this.simTime,f[8]=this.massCount,f[9]=this.disturbanceCount,f[10]=this.couplingCount,f[11]=s;const h=Pn[u]??Pn[0];f[12]=h.rows,f[13]=h.step,f[14]=h.amp,f[15]=h.alpha,f[16]=h.lw,f[17]=h.dz,f[18]=h.px,f[19]=1,f[20]=this.colsFor(h.step,d),f[21]=this.rowsFor(h.rows,d),f[22]=Math.max(1,this.massCount),f[23]=this.plinthCount,f[24]=h.fill[0]/255*h.fill[3],f[25]=h.fill[1]/255*h.fill[3],f[26]=h.fill[2]/255*h.fill[3],f[27]=h.fill[3],f[28]=l.x0,f[29]=l.y0,f[30]=l.x1,f[31]=l.y1;const m=i>=Ji?wT[u]??0:0;f[32]=this.probe?.debug.fillReach??m,f[33]=0,f[34]=0,f[35]=0,this.paramsBufs[i].write(f)}colsFor(i,s){const l=i/s,u=this.rect.x1-this.rect.x0+l*4;return Math.max(2,Math.min(1024,Math.ceil(u/l)))}rowsFor(i,s){const l=i/s,f=Math.min(this.rect.y1,832)+90/s-(this.rect.y0-l*.6);return Math.max(2,Math.min(512,Math.ceil(f/l)))}renderOnce(i){this.renderFrame(Math.min(.25,i))}async debugField(){const i=await this.fieldTarget.readFloats();let s=1/0,l=-1/0,u=0;for(let f=0;f<i.length;f+=4){const d=i[f];Number.isNaN(d)?u++:(d<s&&(s=d),d>l&&(l=d))}return{min:s,max:l,nan:u,sample:Array.from(i.slice(0,16))}}stats(){return{runtimeEntries:this.runtime.size,disturbances:this.disturbanceCount,plinths:this.plinthCount,strata:this.strataCount,couplings:this.couplingCount,instances:this.lastInstances}}renderFrame(i){if(this.disposed)return;const s=performance.now();if(this.simTime+=i,mr(this.camera),this.headless){const[O,L]=this.output.size;this.view.width=O,this.view.height=L}else{const O=this.canvas;if(O&&(O.clientWidth===0||O.clientHeight===0)){this.perf.resetPacing(),this.lastDrawnAt=0;return}const[L,K]=this.cssSize();if(L!==this.view.width||K!==this.view.height){this.view.width=L,this.view.height=K;const G=Math.min(this.maxDpr,globalThis.devicePixelRatio||1);this.canvas.width=Math.round(L*G),this.canvas.height=Math.round(K*G),this.surf?.resize([L,K]);const[I,H]=this.fieldSize();this.fieldTarget.resize([I,H]),this.probe&&(this.probe.canvasResizes++,this.probe.note(`canvas ${L}×${K} css → ${O?.width}×${O?.height}, field ${I}×${H}`))}}mT(this.camera,this.view,this.rect),this.stepPhysics(i),this.landscapeDirty&&(this.packStatics(),this.landscapeDirty=!1),this.packDisturbances(),this.packPlinths();const l=(this.rect.x1-this.rect.x0)*.12,u=(this.rect.y1-this.rect.y0)*.16,f={x0:this.rect.x0-l,y0:this.rect.y0-u,x1:this.rect.x1+l,y1:this.rect.y1+u},d=Tn(this.camera,this.view);this.packParams(w0,i,sr,0),this.packParams(E0,i,f,0);for(let O=0;O<Pn.length;O++)this.packParams(Ji+O,i,f,O);const h=this.probe?this.probe.debug:null,m=h&&(h.skipFill||h.skipLine)?this.sheetVariantDraw(h):this.sheetDraw,g=this.probe?performance.now():0;let x=0;const b=[];TA(this.gpu,O=>{h?.skipResidue||(this.residueFx.set({prevTex:this.residue.read}),O.pass(this.spans?{target:this.residue.write,clear:!1,timer:this.spans.residue}:{target:this.residue.write,clear:!1},this.residueFx),x++),h?.skipField||(this.fieldFx.set({residueTex:this.residue.write}),O.pass(this.spans?{target:this.fieldTarget,clear:!0,timer:this.spans.field}:{target:this.fieldTarget,clear:!0},this.fieldFx),x++);let L=0;const K=(I,H)=>{const Z=Pn[H],de=this.colsFor(Z.step,d),M=this.rowsFor(Z.rows,d),E=de*M*2;this.probe&&b.push({cols:de,rows:M,instances:E}),!(h&&!h.layers[H])&&(L+=E,m.set({P:this.paramsBufs[Ji+H]}),I.draw(m,{instances:E}))},G=[.024,.027,.035,1];if(h?.splitLayers&&this.layerSpans.length===Pn.length){for(let I=0;I<Pn.length;I++)O.pass(I===0?{target:this.output,clear:G,timer:this.layerSpans[I]}:{target:this.output,clear:!1,timer:this.layerSpans[I]},H=>K(H,I)),x++;O.pass(this.spans?{target:this.output,clear:!1,timer:this.spans.overlay}:{target:this.output,clear:!1},I=>{this.strataCount>0&&!h?.skipStrata&&I.draw(this.strataDraw,{instances:this.strataCount}),this.disturbanceCount>0&&!h?.skipCores&&I.draw(this.coresDraw,{instances:this.disturbanceCount})}),x++}else O.pass(this.spans?{target:this.output,clear:G,timer:this.spans.sheet}:{target:this.output,clear:G},I=>{for(let H=0;H<Pn.length;H++)K(I,H);this.strataCount>0&&!h?.skipStrata&&I.draw(this.strataDraw,{instances:this.strataCount}),this.disturbanceCount>0&&!h?.skipCores&&I.draw(this.coresDraw,{instances:this.disturbanceCount})}),x++;this.lastInstances=L+this.strataCount+this.disturbanceCount}),this.residue.swap(),this.dirty=!1;const D=this.probe?performance.now():0;if(!h?.skipSubscribers)for(const O of this.frameSubscribers)O(this.view);const V=performance.now(),k=this.lastDrawnAt>0?s-this.lastDrawnAt:0;if(this.lastDrawnAt=s,this.perf.sample(s,V-s,this.disturbanceCount),this.probe&&(this.probe.noteFrame({interval:k,stride:this.lastStride,prep:g-s,encode:D-g,post:V-D,total:V-s}),this.captureScene(x,b)),this.perf.wantsResize()){const[O,L]=this.fieldSize(),[K,G]=this.fieldTarget.size;(O!==K||L!==G)&&(this.fieldTarget.resize([O,L]),this.probe&&(this.probe.fieldResizes++,this.probe.note(`field texture ${K}×${G} → ${O}×${L} (scale ${this.perf.resolutionScale.toFixed(2)})`)))}}sheetVariantDraw(i){const s=`${i.skipFill?"F":""}${i.skipLine?"L":""}`;let l=this.sheetVariants.get(s);return!l&&this.probe&&(l=Bl(this.gpu,{shader:this.probe.sheetVariant(m0,{skipFill:i.skipFill,skipLine:i.skipLine}),vertices:6,blend:"premultiplied",set:{P:this.paramsBufs[Ji],massData:this.massBuf,fieldTex:this.fieldTarget,fieldSamp:this.linearSampler}}),this.sheetVariants.set(s,l),this.probe.note(`sheet variant '${s}' compiled`)),l??this.sheetDraw}captureScene(i,s){if(!this.probe)return;const l=this.view.width,u=this.view.height,f=this.canvas?.width??this.output.size[0],d=this.canvas?.height??this.output.size[1],h=Tn(this.camera,this.view);let m=0;for(let x=0;x<Pn.length;x++){const D=Pn[x].rows/h,V=this.rect.y0-D*.6,k=s[x]?.rows??0;for(let O=0;O<k;O++){const L=(V+O*D-this.rect.y0)*h;L<u&&(m+=(u-Math.max(0,L))/u)}}let g=0;for(const x of s)g+=x.instances;this.probe.scene={cssW:l,cssH:u,canvasW:f,canvasH:d,dpr:this.surf?.dpr??1,devicePixelRatio:globalThis.devicePixelRatio??1,resolutionScale:this.perf.resolutionScale,fieldW:this.fieldTarget.size[0],fieldH:this.fieldTarget.size[1],zoom:this.camera.zoom,masses:this.massCount,disturbances:this.disturbanceCount,plinths:this.plinthCount,couplings:this.couplingCount,strata:this.strataCount,runtimeEntries:this.runtime.size,layers:s,instances:g+this.strataCount+this.disturbanceCount,passes:i,fillOverdraw:m,fillFragments:m*f*d}}dispose(){this.stop(),this.disposed=!0,this.runtime.clear(),this.plinthRuntime.clear(),this.plinthStatics.clear(),this.massIndex.clear(),this.frameSubscribers.clear(),this.gpuTimer?.dispose(),this.gpuTimer=null,this.probe?.dispose(),this.gpu?.dispose()}}function DT(n,i=2e3){return n.clientWidth>0&&n.clientHeight>0?Promise.resolve():new Promise(s=>{let l=!1;const u=()=>{l||(l=!0,f.disconnect(),clearTimeout(d),s())},f=new ResizeObserver(()=>{n.clientWidth>0&&n.clientHeight>0&&u()});f.observe(n);const d=setTimeout(u,i)})}const X={bg:"#050608",ink:"#e6e3db",accent:"#d9a441",accentBright:"#f0c374",hoverInk:"#f5cf8b",panel:"rgba(7,8,11,0.94)",panelBorder:"rgba(230,227,219,0.4)",hairline:"rgba(230,227,219,0.14)",chrome:"rgba(230,227,219,0.62)",chromeDim:"rgba(230,227,219,0.4)",chromeMid:"rgba(230,227,219,0.7)",chromeStrong:"rgba(230,227,219,0.82)",body:"rgba(230,227,219,0.88)"},at={running:"rgba(240,195,116,0.85)",waiting:"rgba(150,175,196,0.85)",failed:"rgba(206,104,90,0.9)",completed:"rgba(180,210,175,0.75)",idle:"rgba(230,227,219,0.62)"},Et="'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace",Za="0 0 6px rgba(5,6,8,0.95)",RT={backgroundImage:"radial-gradient(rgba(230,227,219,0.05) 0.5px, rgba(0,0,0,0) 0.6px)",backgroundSize:"3px 3px"},CT={background:"radial-gradient(96% 82% at 44% 56%, rgba(0,0,0,0) 42%, rgba(3,3,5,0.9) 100%)"},OT={background:"linear-gradient(to bottom, rgba(6,8,11,0.7), rgba(6,8,11,0))"};let $c=Promise.resolve();function zT({landscape:n,onHover:i,onSelect:s,anchor:l,children:u,onBand:f,onReady:d,depth:h,overlay:m,inset:g,keepVisible:x,compact:b=!1}){const D=Q.useRef(null),V=Q.useRef(null),k=Q.useRef(null),O=Q.useRef({...g0}),L=Q.useRef(n),K=Q.useRef(new Map),G=Q.useRef(null),I=Q.useRef(null),H=Q.useRef(null),Z=Q.useRef(null),de=Q.useRef(null),M=Q.useRef(new Map),E=Q.useRef(null),B=Q.useRef({key:"",w:0,h:0,label:!1}),[W,te]=Q.useState("init"),[le,$e]=Q.useState(null),[he,re]=Q.useState("environment"),[R,q]=Q.useState([]),[ae,Te]=Q.useState("grab");L.current=n,Q.useEffect(()=>{const ee=V.current;if(!ee)return;let J=!1,ye=null;const Ce=$c.then(async()=>{if(!J){if(ye=new MT({canvas:ee,camera:O.current}),await ye.init(),J){ye.dispose(),ye=null;return}k.current=ye,ye.setLandscape(L.current),ye.start(),te("ready"),d?.(ye)}}).catch(Ke=>{J||($e(Ke instanceof Error?Ke.message:String(Ke)),te("failed"))});return $c=Ce,()=>{J=!0,k.current=null,$c=Ce.then(()=>{ye?.dispose(),ye=null})}},[]),Q.useEffect(()=>{k.current?.setLandscape(n)},[n]),Q.useEffect(()=>{const ee=[];for(const J of n.masses)ee.push({id:`mass:${J.id}`,wx:J.x,wy:J.y+J.extentY+26,text:J.name,color:"rgba(230,227,219,0.78)",size:10});if(he==="proximity"){for(const J of n.disturbances)J.energy<.02&&J.status!=="completed"||ee.push({id:`dist:${J.id}`,wx:J.x,wy:J.y-30-J.extent*40,text:`${J.label} · ${J.status}`,color:at[J.status],size:9});for(const J of n.plinths)ee.push({id:`plinth:${J.id}`,wx:J.x,wy:J.y-J.extentY-16,text:`${J.parentId?"└ ":""}${J.label}${J.observers>1?` · ${J.observers} obs`:""}`,color:`rgba(240,195,116,${(.16+.5*J.articulation).toFixed(2)})`,size:9})}q(ee)},[n,he]),Q.useLayoutEffect(()=>{const ee=k.current;if(!ee)return;let J=0;const ye=Ce=>{const Ke=O.current,Qe=performance.now(),Kt=J===0?1/60:Math.min(.1,(Qe-J)/1e3);J=Qe,Z.current&&(gT(Ke,Z.current,Kt)&&(Z.current=null),ee.noteInteraction());const Ve=hT(Re.current,Ke.zoom);Ve!==Re.current&&(Re.current=Ve,re(Ve),f?.(Ve));for(const[At,ct]of K.current){const He=N.current.get(At);if(!He)continue;const[St,tt]=Bc(He.wx,He.wy,Ke,Ce),_i=St>-200&&St<Ce.width+200&&tt>-80&&tt<Ce.height+80;ct.style.visibility=_i?"visible":"hidden",ct.style.transform=`translate3d(${St}px, ${tt}px, 0) translate(-50%, -100%)`}const dn=G.current,xt=w.current;if(dn&&xt){const[At,ct]=Bc(xt.x,xt.y,Ke,Ce),He=dn.firstElementChild;He&&B.current.key!==xt.id&&(B.current={key:xt.id,w:He.offsetWidth,h:He.offsetHeight,label:He.dataset.anchorPlacement==="label"});const{w:St,h:tt,label:_i}=B.current;let Ui=_i?-St/2:18,ls=_i?-tt-14:-tt/2;!_i&&At+Ui+St>Ce.width-12&&(Ui=-St-18),Ui=Math.max(12-At,Ui),ls=Math.min(Math.max(12-ct,ls),Ce.height-12-tt-ct),dn.style.transform=`translate3d(${At+Ui}px, ${ct+ls}px, 0)`,dn.style.visibility=At>-300&&At<Ce.width+300&&ct>-300&&ct<Ce.height+300?"visible":"hidden"}const Lt=Ke.cy+Ce.height/Tn(Ke,Ce)/2,Dn=Lt>wn.strataTop+40,la=Lt>wn.strataTop+wn.strataHeight*.7,Rn=I.current,zi=Rn?.querySelector("[data-depth-label]");if(zi){const At=Dn?la?"FIELD — TODAY":"FIELD — SURFACE + TODAY":"FIELD — LIVE";zi.textContent!==At&&(zi.textContent=At)}if(Rn){const At=Rn.querySelector("[data-depth-summary]"),ct=Rn.querySelector("[data-depth-deep]");if(At&&(At.style.display=Dn?"inline-flex":"none"),ct){const He=ct.dataset.depthSuppressed==="true";ct.style.display=la&&!He?"block":"none"}}};return ee.onFrame(ye)},[W,f]);const Re=Q.useRef("environment"),w=Q.useRef(null),N=Q.useRef(new Map);w.current=l,Q.useEffect(()=>{N.current=new Map(R.map(ee=>[ee.id,ee]))},[R]);const Y=Q.useCallback(()=>{const ee=D.current;return{width:ee?.clientWidth??1,height:ee?.clientHeight??1}},[]),P=g?.right??0,ue=g?.bottom??0,fe=x?.id??null,me=x?.x??0,Ze=x?.y??0;Q.useEffect(()=>{const ee=k.current;if(!ee||!fe||P===0&&ue===0)return;const J=Y(),ye={...Z.current??O.current},Ce=Tn(ye,J);if(Ce<=0)return;const[Ke,Qe]=Bc(me,Ze,ye,J);let Kt=!1;if(P>0){const Ve=J.width-P-40;Ke>Ve&&(ye.cx+=(Ke-(J.width-P)/2)/Ce,Kt=!0)}if(ue>0){const Ve=J.height-ue-40;Qe>Ve&&(ye.cy+=(Qe-(Ve-60))/Ce,Kt=!0)}Qe<70&&(ye.cy-=(110-Qe)/Ce,Kt=!0),Kt&&(Z.current=mr(ye),ee.noteInteraction())},[fe,me,Ze,P,ue,Y]);const De=Q.useCallback(ee=>{const J=D.current.getBoundingClientRect();return[ee.clientX-J.left,ee.clientY-J.top]},[]),gn=Q.useCallback(ee=>{const J=k.current;if(!J)return;const[ye,Ce]=De(ee);Z.current=null,ee.ctrlKey||ee.metaKey?Gc(O.current,Math.exp(-ee.deltaY*.012),ye,Ce,Y()):y0(O.current,ee.deltaX,ee.deltaY,Y()),J.noteInteraction()},[De,Y]);Q.useEffect(()=>{const ee=D.current;if(!ee)return;const J=ye=>ye.preventDefault();return ee.addEventListener("wheel",J,{passive:!1}),()=>ee.removeEventListener("wheel",J)},[]);const Jn=Q.useCallback(ee=>{const J=De(ee);ee.isPrimary&&M.current.clear(),M.current.set(ee.pointerId,J),Z.current=null;try{D.current?.setPointerCapture(ee.pointerId)}catch{}if(M.current.size===1)H.current={x:J[0],y:J[1],moved:!1},Te("grabbing");else if(M.current.size===2){const[ye,Ce]=[...M.current.values()];E.current={distance:Math.hypot(ye[0]-Ce[0],ye[1]-Ce[1]),zoom:O.current.zoom},H.current=null}k.current?.noteInteraction()},[De]),Mt=Q.useCallback(ee=>{const J=k.current;if(!J)return;const ye=De(ee),Ce=M.current.has(ee.pointerId);Ce&&M.current.set(ee.pointerId,ye);const Ke=E.current;if(Ke&&M.current.size>=2){const[xt,Lt]=[...M.current.values()],Dn=Math.hypot(xt[0]-Lt[0],xt[1]-Lt[1]),la=(xt[0]+Lt[0])/2,Rn=(xt[1]+Lt[1])/2,zi=Ke.zoom*(Dn/Math.max(12,Ke.distance));Gc(O.current,zi/O.current.zoom,la,Rn,Y()),J.noteInteraction();return}const Qe=H.current;if(Ce&&Qe){const xt=ye[0]-Qe.x,Lt=ye[1]-Qe.y;(Math.abs(xt)>4||Math.abs(Lt)>4)&&(Qe.moved=!0),y0(O.current,-xt,-Lt,Y()),Qe.x=ye[0],Qe.y=ye[1],J.noteInteraction();return}if(ee.pointerType==="touch")return;const[Kt,Ve]=of(ye[0],ye[1],O.current,Y()),dn=Ym(L.current,Kt,Ve);Te(dn?"pointer":"grab"),(dn||de.current)&&J.noteInteraction(),de.current=dn,i(dn)},[De,i,Y]),Mn=Q.useCallback(ee=>{const J=M.current.get(ee.pointerId)??De(ee);M.current.delete(ee.pointerId),M.current.size<2&&(E.current=null);const ye=H.current;if(H.current=null,Te("grab"),!ye||ye.moved)return;const[Ce,Ke]=of(J[0],J[1],O.current,Y()),Qe=Ym(L.current,Ce,Ke);if(s(Qe),Qe&&Qe.kind!=="stratum"){const Kt=Qe.kind==="mass"?uf:uf+.5;Z.current=yT(Qe.x,Qe.y,Math.max(O.current.zoom,Kt))}k.current?.noteInteraction()},[De,s,Y]),be=Q.useCallback(()=>{H.current=null,E.current=null,M.current.clear(),Te("grab")},[]),yn=Q.useCallback(()=>{Z.current={...g0},k.current?.noteInteraction(),s(null)},[s]),fn=Q.useCallback(ee=>{const J=Y();Gc(O.current,ee,J.width/2,J.height/2,J),k.current?.noteInteraction()},[Y]);return v.jsxs("div",{style:{position:"relative",flex:1,minHeight:0},children:[v.jsxs("div",{ref:D,onWheel:gn,onPointerDown:Jn,onPointerMove:Mt,onPointerUp:Mn,onPointerCancel:Mn,onLostPointerCapture:ee=>{M.current.delete(ee.pointerId),M.current.size<2&&(E.current=null)},onPointerLeave:ee=>{ee.pointerType!=="touch"&&(be(),i(null))},style:{position:"absolute",inset:0,overflow:"hidden",background:X.bg,cursor:ae},children:[v.jsx("canvas",{ref:V,style:{display:"block",width:"100%",height:"100%"}}),v.jsx("div",{style:{position:"absolute",inset:0,pointerEvents:"none",...RT}}),v.jsx("div",{style:{position:"absolute",inset:0,pointerEvents:"none",...CT}}),v.jsx("div",{style:{position:"absolute",left:0,right:0,top:0,height:"16%",pointerEvents:"none",...OT}}),v.jsxs("div",{style:{position:"absolute",inset:0,pointerEvents:"none"},children:[R.map(ee=>v.jsx("div",{ref:J=>{J?K.current.set(ee.id,J):K.current.delete(ee.id)},style:{position:"absolute",left:0,top:0,willChange:"transform",visibility:"hidden",fontFamily:Et,fontSize:ee.size,letterSpacing:"0.22em",color:ee.color,whiteSpace:"nowrap",textTransform:"uppercase"},children:ee.text},ee.id)),l&&v.jsx("div",{ref:G,style:{position:"absolute",left:0,top:0,willChange:"transform",visibility:"hidden",pointerEvents:"auto"},children:u})]}),m&&v.jsx("div",{style:{position:"absolute",inset:0,pointerEvents:"none"},children:m}),h&&v.jsx("div",{ref:I,style:{position:"absolute",inset:0,pointerEvents:"none"},children:h}),W==="failed"&&v.jsx("div",{style:{position:"absolute",inset:0,display:"grid",placeItems:"center",fontFamily:Et,fontSize:11,letterSpacing:"0.18em",color:at.failed,textAlign:"center",padding:40},children:v.jsxs("div",{children:[v.jsx("div",{children:"FIELD UNAVAILABLE — WEBGPU DID NOT START"}),v.jsx("div",{style:{marginTop:10,color:X.chrome,letterSpacing:"0.08em"},children:le})]})})]}),v.jsx(_T,{onSurface:yn,onZoom:fn,compact:b})]})}function _T({onSurface:n,onZoom:i,compact:s}){if(s)return v.jsx("div",{style:{position:"absolute",right:14,bottom:18},children:v.jsx("button",{onClick:n,style:{width:52,height:52,borderRadius:"50%",background:"rgba(7,8,11,0.9)",border:"1px solid rgba(230,227,219,0.5)",color:X.ink,fontFamily:Et,fontSize:8.5,letterSpacing:"0.1em",cursor:"pointer"},children:"SURF"})});const l={background:"transparent",border:`1px solid ${X.chromeDim}`,color:X.chromeStrong,fontFamily:Et,fontSize:10,letterSpacing:"0.14em",padding:"7px 12px",cursor:"pointer"};return v.jsxs("div",{style:{position:"absolute",right:16,bottom:16,display:"flex",gap:8},children:[v.jsx("button",{style:l,onClick:()=>i(1.35),"aria-label":"Zoom in",children:"+"}),v.jsx("button",{style:l,onClick:()=>i(1/1.35),"aria-label":"Zoom out",children:"−"}),v.jsx("button",{style:l,onClick:n,children:"SURFACE"})]})}const D0="(no model)";function rn({name:n,value:i,measure:s,accent:l,note:u}){const f=s?.basis==="inferred";return v.jsxs("div",{title:f?s?.assumption:void 0,style:{display:"flex",flexDirection:"column",gap:5,padding:"12px 0",borderTop:`1px solid ${X.hairline}`,cursor:f?"help":"default"},children:[v.jsxs("div",{style:{fontSize:9.5,letterSpacing:"0.22em",color:X.chrome,display:"flex",alignItems:"baseline",gap:6},children:[n,f&&v.jsx("span",{style:{color:X.chromeDim,letterSpacing:"0.1em"},children:"inferred"})]}),v.jsx("div",{style:{fontSize:21,letterSpacing:"0.02em",color:l??X.ink,fontVariantNumeric:"tabular-nums"},children:i}),u&&v.jsx("div",{style:{fontSize:9.5,color:X.chromeDim},children:u})]})}function ea({title:n,children:i}){return v.jsxs("div",{style:{marginTop:40},children:[v.jsx("div",{style:{fontSize:9.5,letterSpacing:"0.24em",color:X.chrome},children:n}),v.jsx("div",{style:{marginTop:12},children:i})]})}function Zy({fraction:n,color:i}){return v.jsx("div",{style:{height:3,background:"rgba(230,227,219,0.08)",width:"100%"},children:v.jsx("div",{style:{height:"100%",width:`${Math.max(.5,Math.min(1,n)*100)}%`,background:i}})})}function Vc({rows:n,max:i,label:s,color:l}){return v.jsx("div",{style:{display:"flex",flexDirection:"column",gap:10},children:n.map(u=>v.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:5},children:[v.jsxs("div",{style:{display:"flex",justifyContent:"space-between",gap:16,fontSize:11,fontVariantNumeric:"tabular-nums"},children:[v.jsx("span",{style:{color:X.body},children:s(u.key)}),v.jsxs("span",{style:{color:X.chromeMid},children:[u.runs," ",u.runs===1?"run":"runs",u.tokenRuns>0?` · ${pt(u.tokens)} tok`:""," · ",Ye(u.computeMs),u.failed>0&&v.jsxs("span",{style:{color:at.failed},children:[" · ",u.failed," failed"]})]})]}),v.jsx(Zy,{fraction:i>0?u.computeMs/i:0,color:l})]},u.key))})}function UT({world:n}){const i=Q.useMemo(()=>j0(n),[n]),s=Q.useMemo(()=>G0(n,i),[n,i]),l=Q.useMemo(()=>Bx(n),[n]),u=Q.useMemo(()=>Gx(n),[n]),f=Q.useMemo(()=>$x(n),[n]),d=Q.useMemo(()=>Vx(n),[n]),h=Q.useMemo(()=>Oc(n,(G,I)=>I?.context),[n]),m=Q.useMemo(()=>Oc(n,G=>G.model??D0),[n]),g=Q.useMemo(()=>Oc(n,G=>G.machineId),[n]),x=Q.useMemo(()=>[...n.executions.values()].filter(G=>G.status==="failed").sort((G,I)=>I.startedAt-G.startedAt),[n]),b=i.longestFocus.value,D=Q.useMemo(()=>[...n.executions.values()].filter(G=>qt(G.measures)===void 0).length,[n]),V=h[0]?.computeMs??0,k=m[0]?.computeMs??0,O=g[0]?.computeMs??0,L=d.reduce((G,I)=>I.computeMs>G.computeMs?I:G,d[0]),K=[...n.executions.values()].filter(G=>G.depth>0).length;return v.jsxs("div",{style:{flex:1,overflowY:"auto",padding:"28px 48px 80px",fontFamily:Et,color:X.ink},children:[v.jsxs("div",{style:{marginBottom:34,maxWidth:900},children:[v.jsx("div",{style:{fontSize:9.5,letterSpacing:"0.24em",color:X.chrome},children:"WORK SHAPE"}),v.jsx("div",{style:{fontSize:34,letterSpacing:"0.08em",marginTop:10,color:X.accentBright},children:s.headline}),v.jsx("div",{style:{marginTop:14,display:"flex",flexDirection:"column",gap:7},children:s.clauses.map(G=>v.jsx("div",{style:{fontSize:12,lineHeight:1.65,color:X.body,letterSpacing:"0.02em"},children:G},G))})]}),v.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(190px, 1fr))",gap:"0 40px"},children:[v.jsx(rn,{name:"REQUESTS",value:pt(i.requests.value),measure:i.requests}),v.jsx(rn,{name:"RUNS",value:String(i.executions.value),measure:i.executions,note:K>0?`${K} of them sub-agents`:void 0}),v.jsx(rn,{name:"SESSIONS",value:String(i.sessions.value),measure:i.sessions}),v.jsx(rn,{name:"TOKENS",value:pt(i.tokens.value),measure:i.tokens,note:`${Math.round(l.cacheRead/Math.max(1,l.total)*100)}% cache reads`+(D>0?` · ${D} ${D===1?"run reports":"runs report"} no accounting`:"")}),v.jsx(rn,{name:"TOOL CALLS",value:pt(f.toolCalls),measure:i.toolCalls,note:f.toolErrors>0?`${f.toolErrors} failed`:void 0}),v.jsx(rn,{name:"AUTONOMOUS COMPUTE",value:Ye(i.autonomousCompute.value),measure:i.autonomousCompute}),v.jsx(rn,{name:"HUMAN + AGENT OVERLAP",value:Ye(i.humanAgentOverlap.value),measure:i.humanAgentOverlap,note:`${Math.round(i.humanAgentOverlap.value/Math.max(1,i.autonomousCompute.value)*100)}% of compute`}),v.jsx(rn,{name:"PEAK CONCURRENCY",value:i.peakConcurrency.value>0?`${i.peakConcurrency.value} · ${Ja(i.peakConcurrencyAt.value)}`:"0",measure:i.peakConcurrency}),v.jsx(rn,{name:"CONTEXT SWITCHES",value:String(i.contextSwitches.value),measure:i.contextSwitches,note:`across ${h.length} ${h.length===1?"context":"contexts"}`}),v.jsx(rn,{name:"LONGEST FOCUS",value:b?Ye(b.end-b.start):"—",measure:i.longestFocus,note:b?`${ur(b.context)} · ${Ja(b.start)}–${Ja(b.end)}`:void 0}),v.jsx(rn,{name:"WAITING ON YOU",value:Ye(i.waitingOnYou.value),measure:i.waitingOnYou,accent:i.waitingOnYou.value>0?at.waiting:void 0,note:u.count>0?`${u.count} ${u.count===1?"block":"blocks"} · longest ${Ye(u.longestMs)}`:void 0}),v.jsx(rn,{name:"FAILED",value:String(f.failed),accent:f.failed>0?at.failed:void 0,note:f.interrupted>0||f.retries>0?`${f.interrupted} stopped · ${f.retries} retries`:void 0})]}),d.length>0&&v.jsxs(ea,{title:"HOUR BY HOUR",children:[v.jsx("div",{style:{display:"flex",alignItems:"flex-end",gap:3,height:84},children:d.map((G,I)=>{const H=G.computeMs/36e5;return v.jsx("div",{title:`${String(G.hour).padStart(2,"0")}:00 — ${Ye(G.computeMs)} of compute, ${G.runs} runs, peak ${G.peak}`,style:{flex:1,minWidth:4,height:"100%",display:"flex",flexDirection:"column",justifyContent:"flex-end"},children:v.jsx("div",{style:{height:`${Math.max(1,H*100)}%`,background:G.peak>1?"rgba(240,195,116,0.75)":"rgba(214,176,116,0.38)"}})},I)})}),v.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginTop:6,fontSize:9,letterSpacing:"0.16em",color:X.chromeDim},children:[v.jsxs("span",{children:[String(d[0].hour).padStart(2,"0"),":00"]}),v.jsxs("span",{children:["busiest ",String(L.hour).padStart(2,"0"),":00 · ",Ye(L.computeMs)," ","of that hour"]}),v.jsxs("span",{children:[String(d[d.length-1].hour).padStart(2,"0"),":00"]})]})]}),v.jsx(ea,{title:"WHERE THE TIME WENT",children:v.jsx(Vc,{rows:h,max:V,label:ur,color:"rgba(240,195,116,0.6)"})}),g.length>0&&v.jsx(ea,{title:"BY MACHINE",children:v.jsx(Vc,{rows:g,max:O,label:G=>n.machines.get(G)?.name??G,color:"rgba(168,186,150,0.6)"})}),m.length>0&&v.jsx(ea,{title:"BY MODEL",children:v.jsx(Vc,{rows:m,max:k,label:G=>G===D0?"model not observed":G,color:"rgba(150,175,196,0.6)"})}),v.jsxs(ea,{title:"TOKEN COMPOSITION",children:[v.jsx("div",{style:{display:"flex",flexDirection:"column",gap:10},children:[["CACHE READS",l.cacheRead,"rgba(150,175,196,0.6)"],["INPUT",l.input,"rgba(240,195,116,0.6)"],["OUTPUT",l.output,"rgba(180,210,175,0.7)"],["REASONING",l.reasoning,"rgba(214,176,116,0.5)"]].map(([G,I,H])=>v.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:5},children:[v.jsxs("div",{style:{display:"flex",justifyContent:"space-between",fontSize:11,fontVariantNumeric:"tabular-nums"},children:[v.jsx("span",{style:{color:X.body},children:G}),v.jsxs("span",{style:{color:X.chromeMid},children:[pt(I)," · ",Math.round(I/Math.max(1,l.total)*100),"%"]})]}),v.jsx(Zy,{fraction:I/Math.max(1,l.total),color:H})]},G))}),v.jsx("div",{style:{marginTop:12,fontSize:10,lineHeight:1.7,color:X.chromeDim},children:"Cache reads are context replayed into each request, not work generated. They dominate the total, which is why the headline token figure is much larger than it feels."})]}),x.length>0&&v.jsx(ea,{title:"FAILURES",children:v.jsx("div",{style:{display:"flex",flexDirection:"column",gap:9},children:x.slice(0,12).map(G=>v.jsxs("div",{style:{display:"flex",gap:16,fontSize:11,borderTop:`1px solid ${X.hairline}`,paddingTop:8},children:[v.jsx("span",{style:{color:X.chromeMid,minWidth:46},children:Ja(G.startedAt)}),v.jsx("span",{style:{color:X.body,minWidth:160},children:G.label}),v.jsxs("span",{style:{color:at.failed},children:[G.failure?.code,": ",G.failure?.message]})]},G.id))})}),v.jsx(NT,{})]})}function NT(){return v.jsx(ea,{title:"NOT AVAILABLE FROM THESE SOURCES",children:v.jsxs("div",{style:{maxWidth:760,fontSize:10.5,lineHeight:1.8,color:X.chromeDim},children:[v.jsx("div",{children:"COST — every source here reports tokens or CPU time; none reports money. Converting one to the other needs a price table 057 does not have, so no cost figure is shown anywhere."}),v.jsx("div",{style:{marginTop:8},children:"TOKENS, FROM SOME SOURCES — Cursor persists no usage and 0x2F records none; their runs read NOT OBSERVED rather than 0, and the token totals sum only the runs that report."}),v.jsx("div",{style:{marginTop:8},children:"MACHINE-TO-MACHINE TRANSFER — every observed source is single-host. Transfers are modelled and the field renders them, but no real adapter emits one; only the synthetic source does."}),v.jsx("div",{style:{marginTop:8},children:"PROCESS EXITS — the OS collector samples; an exit is inferred from disappearance between samples, never witnessed."}),v.jsx("div",{style:{marginTop:8},children:"OUTCOME QUALITY — the log records that a run completed, not whether the work was any good."})]})})}const Ic=100,R0="58px minmax(180px,1.4fr) 104px 132px 84px 68px 62px 70px 56px";function LT(n){return n.outcome==="interrupted"?"STOPPED":n.status}function kT(n){return n.outcome==="interrupted"?X.chromeMid:at[n.status]}function Mi({children:n,align:i="left",color:s}){return v.jsx("div",{style:{textAlign:i,color:s??X.chromeMid,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:n})}function jT({p:n,session:i,onShowInField:s}){const l=qt(n.measures),u=n.startBasis==="inferred"||n.endBasis==="inferred",f=[["CONTEXT",i?i.context:"—"],["PROVIDER",n.executor],["MODEL",n.model??"not observed"],["STARTED",`${n.startBasis==="inferred"?"~":""}${new Date(n.startedAt).toLocaleTimeString()}`],["ENDED",n.endedAt?`${n.endBasis==="inferred"?"~":""}${new Date(n.endedAt).toLocaleTimeString()}`:"still open"],...l===void 0?[["TOKENS","not observed"]]:[["INPUT",pt(Wa(n.measures).input)],["OUTPUT",pt(Wa(n.measures).output)],["CACHE READ",pt(Wa(n.measures).cacheRead)],["REASONING",pt(Wa(n.measures).reasoning)]],["REQUESTS",String(ff(n))],["TOOL CALLS",es(un(n),"not observed")]];return ia(n)>0&&f.push(["TOOL ERRORS",String(ia(n)),at.failed]),Yc(n)>0&&f.push(["PROVIDER RETRIES",String(Yc(n)),at.waiting]),(n.waits.length>0||n.waitingMs>0)&&f.push(["BLOCKED ON YOU",`${Ye(n.waitingMs)} across ${n.waits.length||1}`,at.waiting]),n.depth>0&&f.push(["SUB-AGENT",`depth ${n.depth}`]),v.jsxs("div",{style:{gridColumn:"1 / -1",display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(180px, 1fr))",gap:"6px 28px",padding:"12px 0 14px 16px",borderLeft:`1px solid ${X.panelBorder}`,margin:"2px 0 6px",background:"rgba(230,227,219,0.02)"},children:[f.map(([d,h,m])=>v.jsxs("div",{style:{display:"flex",justifyContent:"space-between",gap:12},children:[v.jsx("span",{style:{fontSize:9.5,letterSpacing:"0.16em",color:X.chrome},children:d}),v.jsx("span",{style:{fontSize:10.5,color:m??X.body,fontVariantNumeric:"tabular-nums",overflow:"hidden",textOverflow:"ellipsis"},children:h})]},d)),n.failure&&v.jsxs("div",{style:{gridColumn:"1 / -1",fontSize:10.5,color:at.failed},children:[n.failure.code,": ",n.failure.message]}),u&&n.boundsAssumption&&v.jsxs("div",{style:{gridColumn:"1 / -1",fontSize:9.5,color:X.chromeMid},children:["timing inferred — ",n.boundsAssumption]}),v.jsx("div",{style:{gridColumn:"1 / -1",marginTop:4},children:v.jsx("button",{onClick:d=>{d.stopPropagation(),s()},style:{background:"transparent",border:`1px solid ${X.hairline}`,color:X.chromeMid,fontFamily:Et,fontSize:9,letterSpacing:"0.16em",padding:"5px 10px",cursor:"pointer"},children:"SHOW IN FIELD →"})})]})}function BT({world:n,selectedId:i,onSelect:s}){const[l,u]=Q.useState("all"),[f,d]=Q.useState("time"),[h,m]=Q.useState(Ic),[g,x]=Q.useState(null),b=Q.useMemo(()=>{let L=[...n.executions.values()];l==="stopped"?L=L.filter(I=>I.outcome==="interrupted"):l!=="all"&&(L=L.filter(I=>I.status===l&&I.outcome!=="interrupted"));const K=I=>(I.endedAt??n.now)-I.startedAt,G={time:(I,H)=>H.startedAt-I.startedAt,duration:(I,H)=>K(H)-K(I),tokens:(I,H)=>(qt(H.measures)??0)-(qt(I.measures)??0),tools:(I,H)=>(un(H)??0)-(un(I)??0),waited:(I,H)=>H.waitingMs-I.waitingMs};return L.sort(G[f])},[n,l,f]),D=Q.useMemo(()=>{const L={all:n.executions.size,stopped:0};for(const K of n.executions.values())K.outcome==="interrupted"?L.stopped++:L[K.status]=(L[K.status]??0)+1;return L},[n]),V=Q.useMemo(()=>{let L=0,K=0,G=0,I=0;for(const H of b)L+=qt(H.measures)??0,K+=(H.endedAt??n.now)-H.startedAt,G+=un(H)??0,I+=H.waitingMs;return{tokens:L,compute:K,tools:G,waited:I}},[b,n]),k=b.slice(0,h),O=(L,K,G="left")=>v.jsxs("div",{onClick:()=>d(L),style:{textAlign:G,cursor:"pointer",color:f===L?X.ink:X.chrome},children:[K,f===L?" ↓":""]});return v.jsxs("div",{style:{flex:1,overflowY:"auto",padding:"24px 48px 80px",fontFamily:Et,color:X.ink},children:[v.jsx("div",{style:{display:"flex",gap:10,flexWrap:"wrap",marginBottom:14},children:["all","running","waiting","idle","completed","failed","stopped"].map(L=>{const K=l===L,G=D[L]??0;return v.jsxs("button",{onClick:()=>{u(L),m(Ic)},style:{background:"transparent",border:`1px solid ${K?"rgba(230,227,219,0.6)":X.hairline}`,color:K?X.ink:X.chromeMid,fontFamily:Et,fontSize:9.5,letterSpacing:"0.16em",padding:"6px 11px",cursor:"pointer",textTransform:"uppercase"},children:[L," ",G>0&&v.jsx("span",{style:{color:X.chromeDim},children:G})]},L)})}),v.jsxs("div",{style:{fontSize:10,letterSpacing:"0.12em",color:X.chromeDim,marginBottom:14,fontVariantNumeric:"tabular-nums"},children:[b.length," ",b.length===1?"run":"runs"," shown · ",pt(V.tokens)," tok ·"," ",Ye(V.compute)," of run time · ",pt(V.tools)," tool calls",V.waited>0&&` · ${Ye(V.waited)} blocked on you`]}),v.jsxs("div",{style:{display:"grid",gridTemplateColumns:R0,gap:"0 14px",fontSize:9,letterSpacing:"0.18em",color:X.chrome,paddingBottom:8,borderBottom:`1px solid ${X.hairline}`},children:[O("time","START"),v.jsx("div",{children:"RUN"}),v.jsx("div",{children:"CONTEXT"}),v.jsx("div",{children:"MODEL"}),v.jsx("div",{children:"STATUS"}),O("duration","DUR","right"),O("tokens","TOKENS","right"),O("waited","WAITED","right"),O("tools","TOOLS","right")]}),k.map(L=>{const K=n.sessions.get(L.sessionId),G=L.id===i,I=g===L.id;return v.jsxs("div",{children:[v.jsxs("div",{onClick:()=>x(I?null:L.id),style:{display:"grid",gridTemplateColumns:R0,gap:"0 14px",fontSize:11,padding:"9px 0",borderBottom:"1px solid rgba(230,227,219,0.05)",cursor:"pointer",background:G||I?"rgba(240,195,116,0.07)":"transparent",fontVariantNumeric:"tabular-nums"},children:[v.jsx(Mi,{children:Ja(L.startedAt)}),v.jsxs(Mi,{color:G||I?X.accentBright:X.body,children:[L.depth>0&&v.jsx("span",{style:{color:X.chromeDim},children:"└ "}),L.label]}),v.jsx(Mi,{children:K?ur(K.context):"—"}),v.jsx(Mi,{color:L.model?void 0:X.chromeDim,children:L.model??"—"}),v.jsx("div",{style:{fontSize:9,letterSpacing:"0.14em",color:kT(L),textTransform:"uppercase"},children:LT(L)}),v.jsxs(Mi,{align:"right",children:[L.startBasis==="inferred"||L.endBasis==="inferred"?"~":"",Ye((L.endedAt??n.now)-L.startedAt)]}),v.jsx(Mi,{align:"right",color:qt(L.measures)===void 0?X.chromeDim:void 0,children:es(qt(L.measures),"—")}),v.jsx(Mi,{align:"right",color:L.waitingMs>0?at.waiting:X.chromeDim,children:L.waitingMs>0?Ye(L.waitingMs):"—"}),v.jsxs(Mi,{align:"right",color:un(L)===void 0?X.chromeDim:void 0,children:[es(un(L),"—"),ia(L)>0&&v.jsxs("span",{style:{color:at.failed},children:[" /",ia(L)]})]})]}),I&&v.jsx(jT,{p:L,session:K,onShowInField:()=>s(L.id)})]},L.id)}),b.length===0&&v.jsx("div",{style:{padding:"28px 0",fontSize:11,color:X.chromeMid},children:"Nothing matching in this window."}),b.length>h&&v.jsxs("button",{onClick:()=>m(L=>L+Ic),style:{marginTop:18,background:"transparent",border:`1px solid ${X.hairline}`,color:X.chromeMid,fontFamily:Et,fontSize:9.5,letterSpacing:"0.16em",padding:"8px 14px",cursor:"pointer"},children:["SHOW MORE — ",b.length-h," REMAINING"]})]})}const Fc={display:"flex",flexDirection:"column",gap:5,background:X.panel,borderLeft:`1px solid ${X.panelBorder}`,padding:"9px 13px",minWidth:170,maxWidth:320,fontFamily:Et,backdropFilter:"blur(2px)"};function Ue({name:n,detail:i,color:s,title:l,tag:u}){return v.jsxs("div",{title:l,style:{display:"flex",alignItems:"baseline",justifyContent:"space-between",gap:16,fontSize:10.5,cursor:l?"help":void 0},children:[v.jsxs("span",{style:{color:X.chromeMid,letterSpacing:"0.1em",whiteSpace:"nowrap"},children:[n,u&&v.jsxs("span",{style:{color:X.chromeDim,letterSpacing:"0.06em"},children:[" ",u]})]}),v.jsx("span",{style:{fontSize:10,fontWeight:500,letterSpacing:"0.14em",color:s??X.chromeStrong,whiteSpace:"nowrap",textAlign:"right",overflow:"hidden",textOverflow:"ellipsis",maxWidth:190},children:i})]})}function Hc({text:n,onClose:i}){return v.jsxs("div",{style:{display:"flex",alignItems:"baseline",justifyContent:"space-between",gap:14},children:[v.jsx("div",{style:{fontSize:10,letterSpacing:"0.18em",color:X.ink,textTransform:"uppercase"},children:n}),v.jsx("div",{onClick:i,role:"button",style:{fontSize:11,color:X.chromeMid,cursor:"pointer"},children:"×"})]})}function _f({label:n}){return v.jsx("div",{style:{marginTop:5,paddingTop:5,borderTop:"1px solid rgba(230,227,219,0.08)",fontSize:8.5,letterSpacing:"0.2em",color:X.chromeDim},children:n})}function GT(n){if(n.basis==="measured")return{label:"recorded",grade:"recorded"};const i=n.via?.split("|")[0];return i==="agent.session"?{label:"session identity",grade:"identity"}:i==="os.process"?{label:"process identity",grade:"identity"}:i==="fs.cwd"?{label:"directory overlap",grade:"contextual"}:{label:"inferred",grade:"contextual"}}function $T(n,i){switch(i.type){case"process":{const s=n.processes.get(i.id);return s?`PID ${s.pid} · ${s.command}`:i.id}case"session":return n.sessions.get(i.id)?.label??i.id;case"execution":return n.executions.get(i.id)?.label??i.id;case"machine":return n.machines.get(i.id)?.name??i.id;default:return i.id}}const C0={"ran-as":"RAN AS","same-as":"SAME AS",spawned:"SPAWNED",contains:"CONTAINS",produced:"PRODUCED"};function O0({world:n,subject:i}){const s=n.relationships.filter(l=>l.from.type===i.type&&l.from.id===i.id||l.to.type===i.type&&l.to.id===i.id);return s.length===0?null:v.jsxs(v.Fragment,{children:[v.jsx(_f,{label:"RELATED"}),s.slice(0,6).map((l,u)=>{const f=l.from.type===i.type&&l.from.id===i.id,d=f?l.to:l.from,h=f?C0[l.kind]:l.kind==="spawned"?"SPAWNED BY":C0[l.kind],m=GT(l);return v.jsx(Ue,{name:h,tag:m.grade==="contextual"?`${m.label} · inferred`:m.label,detail:$T(n,d),color:m.grade==="contextual"?X.chromeMid:void 0,title:l.assumption??(l.via?`via ${l.via}`:void 0)},`${l.kind}:${d.type}:${d.id}:${u}`)})]})}function VT({type:n,id:i}){const[s,l]=Q.useState(null);return Q.useEffect(()=>{let u=!1;l(null);const f=setTimeout(()=>{o1(n,i).then(({events:d})=>{u||l(IT(d))}).catch(()=>{u||l(null)})},180);return()=>{u=!0,clearTimeout(f)}},[n,i]),!s||s.facts.length===0&&!s.provenance?null:v.jsxs(v.Fragment,{children:[v.jsx(_f,{label:"NATIVE RECORD"}),s.facts.map(([u,f])=>v.jsx(Ue,{name:u,detail:f,color:X.chromeMid},u)),s.provenance&&v.jsxs("div",{title:s.provenance,style:{fontSize:8.5,letterSpacing:"0.04em",color:X.chromeDim,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",cursor:"help"},children:["read from ",s.provenance]})]})}function IT(n){const i=new Map;let s;for(const u of n){for(const[f,d]of Object.entries(u.attrs??{}))!f.includes(".")||d===void 0||d===null||d===""||i.set(f,d);!s&&u.provenance?.path&&(s=u.provenance.path)}return{facts:[...i.entries()].slice(0,10).map(([u,f])=>[u,typeof f=="object"?JSON.stringify(f):String(f)]),provenance:s}}function FT({p:n,now:i}){const s=(n.endedAt??i)-n.startedAt,l=n.startBasis==="inferred",u=n.endBasis==="inferred",f=l||u;return v.jsxs(v.Fragment,{children:[v.jsx(Ue,{name:"STARTED",tag:l?"inferred":void 0,detail:Ja(n.startedAt),title:l?n.boundsAssumption:void 0}),v.jsx(Ue,{name:"ELAPSED",tag:f?"inferred":void 0,detail:Ye(s),title:f?n.boundsAssumption:void 0})]})}function Uf({hit:n,world:i,landscape:s,band:l,density:u,onClose:f}){if(n.kind==="mass"){const k=i.machines.get(n.id);if(!k)return null;const O=[];let L=0,K;for(const H of i.executions.values()){if(H.machineId!==k.id)continue;const Z=qt(H.measures);Z!==void 0&&(K=(K??0)+Z),H.status==="running"||H.status==="waiting"?O.push({id:H.id,label:H.label,status:H.status}):L++}const G=i.processTotals,I=new Set;for(const H of i.relationships)H.kind==="ran-as"&&(H.from.type==="process"&&I.add(H.from.id),H.to.type==="process"&&I.add(H.to.id));return v.jsxs("div",{style:Fc,children:[v.jsx(Hc,{text:k.name,onClose:f}),O.length===0?v.jsx("div",{style:{fontSize:10,color:X.chrome},children:"idle — nothing active"}):O.slice(0,8).map(H=>v.jsx(Ue,{name:H.label,detail:H.status.toUpperCase(),color:at[H.status]},H.id)),v.jsx("div",{style:{height:4}}),v.jsx(Ue,{name:"RAN TODAY",detail:String(L)}),v.jsx(Ue,{name:"TOKENS",detail:es(K),title:K===void 0?"No execution in this window reported token accounting.":void 0}),G&&v.jsxs(v.Fragment,{children:[v.jsx(_f,{label:"MACHINE STRATUM"}),v.jsx(Ue,{name:"PROCESSES OBSERVED",detail:String(G.observed)}),v.jsx(Ue,{name:"SEEN IN LAST 5 MIN",detail:String(G.recentlySeen),title:"Processes with a liveness observation in the last five minutes. The sampler only records a process when it is doing something, and never witnesses an exit — so recency is the honest liveness signal, not an unexpired status."}),v.jsx(Ue,{name:"ATTRIBUTED",detail:`${I.size} of ${G.observed}`,title:"Processes tied to a session or execution by resolved identity. The rest are machine activity with no known semantic identity — observed, not explained."}),G.exitsInferred>0&&v.jsx(Ue,{name:"EXITS",tag:"inferred",detail:String(G.exitsInferred),title:"An exit is never witnessed by the sampler; it is inferred from disappearance between samples."})]})]})}if(n.kind==="coupling"){const k=i.transfers.get(n.id);if(!k)return null;const O=i.machines.get(k.fromMachineId)?.name??k.fromMachineId,L=i.machines.get(k.toMachineId)?.name??k.toMachineId;return v.jsxs("div",{style:Fc,children:[v.jsx(Hc,{text:`${O} → ${L}`,onClose:f}),v.jsx(Ue,{name:"STATUS",detail:"TRANSFERRING",color:at.running}),v.jsx(Ue,{name:"WHAT",detail:k.label}),v.jsx(Ue,{name:"SIZE",detail:Ix(k.bytes)}),v.jsx(Ue,{name:"ELAPSED",detail:Ye(i.now-k.startedAt)})]})}const d=i.executions.get(n.id);if(!d)return null;const h=i.sessions.get(d.sessionId),m=i.machines.get(d.machineId),g=s.disturbances.find(k=>k.id===n.id),x=u==="full"||u!=="compact"&&(l==="proximity"||n.kind==="stratum"),b=x,D=qt(d.measures),V=Wa(d.measures);return v.jsxs("div",{style:Fc,children:[v.jsx(Hc,{text:d.label,onClose:f}),v.jsx(Ue,{name:"STATUS",detail:d.status.toUpperCase(),color:at[d.status]}),v.jsx(Ue,{name:"MACHINE",detail:m?.name??d.machineId}),v.jsx(FT,{p:d,now:i.now}),b&&v.jsxs(v.Fragment,{children:[v.jsx(Ue,{name:"TOKENS",detail:es(D),title:D===void 0?"This source does not persist token accounting.":void 0}),v.jsx(Ue,{name:"REQUESTS",detail:String(ff(d))}),v.jsx(Ue,{name:"TOOL CALLS",detail:es(un(d)),title:un(d)===void 0?"This source does not count discrete operations.":void 0})]}),x&&v.jsxs(v.Fragment,{children:[v.jsx("div",{style:{height:4}}),h&&v.jsx(Ue,{name:"CONTEXT",detail:ur(h.context)}),v.jsx(Ue,{name:"PROVIDER",detail:d.executor}),v.jsx(Ue,{name:"MODEL",detail:d.model??"NOT OBSERVED",color:d.model?void 0:X.chromeMid,title:d.model?void 0:"This source does not record the model."}),D!==void 0&&v.jsxs(v.Fragment,{children:[v.jsx(Ue,{name:"CACHE READ",detail:pt(V.cacheRead)}),v.jsx(Ue,{name:"REASONING",detail:pt(V.reasoning)})]}),ia(d)>0&&v.jsx(Ue,{name:"TOOL ERRORS",detail:String(ia(d)),color:at.failed}),d.waitingMs>0&&v.jsx(Ue,{name:"WAITED ON YOU",detail:Ye(d.waitingMs),color:at.waiting}),d.depth>0&&v.jsx(Ue,{name:"SUB-AGENT",detail:`depth ${d.depth}`}),h?.parentId&&v.jsx(Ue,{name:"SESSION SPAWNED BY",tag:"recorded",detail:i.sessions.get(h.parentId)?.label??h.parentId,title:"The session's own runtime recorded which session started it."}),g&&v.jsx(Ue,{name:"FIELD ENERGY",detail:g.energy.toFixed(2)}),v.jsx(O0,{world:i,subject:{type:"execution",id:d.id}}),h&&v.jsx(O0,{world:i,subject:{type:"session",id:h.id}}),v.jsx(VT,{type:"execution",id:d.id})]}),d.failure&&v.jsxs("div",{style:{marginTop:4,fontSize:9.5,letterSpacing:"0.06em",color:at.failed,maxWidth:280},children:[d.failure.code,": ",d.failure.message]}),d.outcome==="interrupted"&&!d.failure&&v.jsx("div",{style:{marginTop:4,fontSize:9.5,color:X.chromeMid},children:"stopped before finishing"})]})}function HT({hit:n,world:i}){let s="",l="",u=X.chromeMid;if(n.kind==="mass")s=i.machines.get(n.id)?.name??n.id;else if(n.kind==="coupling"){const f=i.transfers.get(n.id),d=f?i.machines.get(f.fromMachineId)?.name??"":"",h=f?i.machines.get(f.toMachineId)?.name??"":"";s=`${d} → ${h}`,l="TRANSFERRING",u=at.running}else{const f=i.executions.get(n.id);if(!f)return null;s=f.label,l=f.status.toUpperCase(),u=at[f.status]}return v.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:2,pointerEvents:"none",whiteSpace:"nowrap",fontFamily:Et},children:[v.jsx("div",{style:{fontSize:10.5,fontWeight:500,letterSpacing:"0.18em",color:X.hoverInk,background:"rgba(5,6,8,0.88)",padding:"4px 9px"},children:s}),l&&v.jsx("div",{style:{fontSize:9.5,letterSpacing:"0.22em",color:u,textShadow:Za},children:l})]})}function qT(n){return[`${pt(n.requests.value)} REQ`,`${n.sessions.value} SESS`,`${Ye(n.autonomousCompute.value)}`,`${pt(n.tokens.value)} TOK`].join(" · ")}function YT(n){return[`${pt(n.requests.value)} REQUESTS`,`${n.sessions.value} SESSIONS`,`${Ye(n.autonomousCompute.value)} AUTONOMOUS`,`${Ye(n.humanAgentOverlap.value)} OVERLAP`,`PEAK ${n.peakConcurrency.value}`,`${n.contextSwitches.value} SWITCHES`,`${pt(n.tokens.value)} TOK`].join(" · ")}function XT({metrics:n,shape:i,compact:s=!1}){return v.jsxs("div",{style:{position:"absolute",left:20,bottom:16,right:s?82:236,display:"flex",flexDirection:"column",gap:8,pointerEvents:"none",fontFamily:Et},children:[v.jsxs("div",{"data-depth-deep":!0,"data-depth-suppressed":s?"true":void 0,style:{display:"none",maxWidth:720,background:"linear-gradient(to right, rgba(5,6,8,0.92) 0%, rgba(5,6,8,0.86) 70%, rgba(5,6,8,0) 100%)",padding:"10px 42px 10px 0",margin:"0 0 -2px -6px",paddingLeft:6},children:[v.jsxs("div",{style:{fontSize:9.5,letterSpacing:"0.24em",color:X.chrome,textShadow:Za},children:["WORK SHAPE — ",i.headline]}),v.jsx("div",{style:{marginTop:6,display:"flex",flexDirection:"column",gap:3},children:i.clauses.slice(0,3).map(l=>v.jsx("div",{style:{fontSize:10.5,lineHeight:1.6,color:X.chromeMid,textShadow:Za},children:l},l))}),v.jsx("div",{style:{marginTop:7,fontSize:9.5,lineHeight:1.6,color:X.chromeDim,textShadow:Za,maxWidth:620},children:"NOT AVAILABLE FROM THESE SOURCES — cost (every source reports tokens or CPU time, none reports money) and machine-to-machine transfer (every observed source is single-host)."})]}),v.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:10,flexWrap:"wrap",background:"linear-gradient(to right, rgba(5,6,8,0.92) 0%, rgba(5,6,8,0.86) 80%, rgba(5,6,8,0) 100%)",padding:"4px 42px 4px 6px",margin:"0 0 0 -6px"},children:[v.jsx("span",{"data-depth-label":!0,style:{fontSize:10.5,letterSpacing:"0.18em",color:"rgba(230,227,219,0.74)",textShadow:Za},children:"FIELD — LIVE"}),v.jsxs("span",{"data-depth-summary":!0,style:{display:"none",alignItems:"baseline",gap:10},children:[v.jsx("span",{style:{color:X.chromeDim},children:"·"}),v.jsx("span",{style:{fontSize:10.5,letterSpacing:"0.18em",color:"rgba(230,227,219,0.6)",textShadow:Za},children:s?qT(n):YT(n)})]})]})]})}const KT=560;function z0(n,i,s){return Math.min(n,i)<KT||s?i>=n?"portrait":"landscape":"desktop"}function QT(){const[n,i]=Q.useState(()=>typeof window>"u"?"desktop":z0(window.innerWidth,window.innerHeight,window.matchMedia("(pointer: coarse)").matches));return Q.useEffect(()=>{const s=window.matchMedia("(pointer: coarse)"),l=()=>i(z0(window.innerWidth,window.innerHeight,s.matches));return l(),window.addEventListener("resize",l),window.addEventListener("orientationchange",l),s.addEventListener("change",l),()=>{window.removeEventListener("resize",l),window.removeEventListener("orientationchange",l),s.removeEventListener("change",l)}},[]),n}const Wy=250,Jy=150;function PT(n,i,s,l){return i?n==="landscape"?{right:Wy,bottom:0}:n==="portrait"?{right:0,bottom:s?Math.round(l*.6):Jy}:{right:0,bottom:0}:{right:0,bottom:0}}const ev={fontSize:9,letterSpacing:"0.16em",color:X.chromeMid};function ZT(n){return v.jsxs("div",{style:{position:"absolute",right:0,top:0,bottom:0,width:Wy,boxSizing:"border-box",background:X.panel,borderLeft:`1px solid ${X.panelBorder}`,padding:"16px 16px 14px",display:"flex",flexDirection:"column",gap:10,fontFamily:Et,pointerEvents:"auto"},children:[v.jsx(Uf,{...n,density:"full"}),v.jsx("div",{style:{marginTop:"auto",...ev},children:"TAP FIELD TO DISMISS"})]})}function WT({detent:n,onToggleDetent:i,viewportHeight:s,...l}){const u=n==="expanded",f=u?Math.round(s*.6):Jy;return v.jsxs("div",{style:{position:"absolute",left:0,right:0,bottom:0,height:f,boxSizing:"border-box",background:"rgba(7,8,11,0.96)",borderTop:`1px solid ${X.panelBorder}`,padding:"10px 18px 18px",display:"flex",flexDirection:"column",gap:10,fontFamily:Et,pointerEvents:"auto",transition:"height 180ms ease-out"},children:[v.jsx("button",{onClick:i,"aria-label":u?"Collapse":"Expand",style:{alignSelf:"center",width:44,height:4,borderRadius:2,border:"none",padding:0,background:"rgba(230,227,219,0.42)",cursor:"pointer",marginBottom:2,flexShrink:0}}),v.jsx("div",{style:{overflow:"hidden",flex:1,minHeight:0},children:v.jsx(Uf,{...l,density:u?"full":"compact"})}),v.jsx("div",{style:{marginTop:"auto",...ev},children:u?"TAP HANDLE TO COLLAPSE":"TAP HANDLE FOR FULL TELEMETRY"})]})}function JT(){return"capture"}function eM(n){return`${n.message}. ${n.remedy} Nothing observed since this appeared has been saved.`}const qc={label:"TODAY",tone:"normal",detail:"Midnight to now."},tM={normal:X.chromeMid,warn:"rgba(240,195,116,0.9)",error:"rgba(206,104,90,0.9)"};function nM(){const n=Date.now(),i=new Date(n);return i.setHours(0,0,0,0),{start:i.getTime(),now:n}}const iM=250,aM={time:0,masses:[],disturbances:[],plinths:[],couplings:[],strata:[]};function sM(){const[n,i]=Q.useState(JT),[s,l]=Q.useState("field"),[u,f]=Q.useState(null),[d,h]=Q.useState(qc),[m,g]=Q.useState(aM),[x,b]=Q.useState(0),[D,V]=Q.useState(null),[k,O]=Q.useState(null),[L,K]=Q.useState("environment"),[G,I]=Q.useState(null),[H,Z]=Q.useState("peek"),de=QT(),M=Q.useRef(Vl(Date.now(),Date.now())),E=Q.useRef(null),B=Q.useRef(null),W=Q.useRef(!1);Q.useEffect(()=>{let w=!1,N=null;h(qc);async function Y(){if(n==="synthetic"||n==="fixture"){let be;if(be=new l1({seed:57}),h({label:"REPLAY",tone:"normal",detail:"A deterministic synthetic day, replayed at speed. Not your telemetry."}),w)return;const yn=be.bounds();M.current=Vl(yn.dayStart,yn.dayEnd),E.current=be,f(be.info()),O(null),V(null),N=be.subscribe(fn=>{Ox(M.current,fn),W.current=!0}),W.current=!0;return}const{start:P,now:ue}=nM();await Xc(P,ue);const fe=await u1();let me=await Kc(P,ue);if(me.world.executions.length===0&&me.world.sessions.length===0){const be=ue-2592e5;await Xc(be,ue),me=await Kc(be,ue),(me.world.executions.length>0||me.world.sessions.length>0)&&h({label:"LAST 72H",tone:"warn",detail:"Nothing ran today, so the window was widened to the last 72 hours."})}const Ze=Object.entries(fe.observation??{}).flatMap(([be,yn])=>Object.entries(yn.strata).filter(([fn,ee])=>ee==="partial"||ee==="failed"&&fn!=="live-semantics").map(([fn,ee])=>`${be} ${fn} ${ee}`)),De=Object.entries(fe.sources).filter(([,be])=>(be.presence??(be.available?"observing":"not-installed"))==="failed").map(([be])=>be),gn=Object.entries(fe.sources).filter(([,be])=>be.presence==="not-installed").map(([be])=>be),Jn=fe.store.bySource.filter(be=>be.source!=="host"),Mt=fe.health;fe.fault?h({label:"STORE LOST",tone:"error",detail:eM(fe.fault)}):Mt&&!Mt.store.ok?h({label:"STORE DEGRADED",tone:"error",detail:Mt.store.remedy??"Some stored rows could not be read."}):Mt&&Mt.failingSources.length>0?h({label:"SOURCE FAILING",tone:"error",detail:`Installed and failing every collection round: ${Mt.failingSources.join(", ")}. `+(Mt.collection[Mt.failingSources[0]]?.lastError??"")+" Other sources and captured history are unaffected."}):fe.mode==="os-only"?h({label:"OS ONLY",tone:"normal",detail:"Observing this machine’s processes. No AI runtime state was found here"+(gn.length?` (looked for ${gn.join(", ")})`:"")+" — that is a valid mode, not a fault. Install or use one and its sessions appear here."}):Jn.length===0?h({label:"NOTHING YET",tone:"warn",detail:"Nothing has been captured yet. OS processes are sampled locally every few seconds; AI runtime state is read from each runtime’s own files when it exists."}):(De.length||Ze.length)&&h({label:"PARTIAL",tone:"warn",detail:[De.length?`Installed but unreadable: ${De.join(", ")}.`:"",Ze.length?`Reduced observation depth: ${Ze.join("; ")}. The computation is still observed; some semantics are not.`:"","Captured history is intact."].filter(Boolean).join(" ")});const Mn=new d1(me,fe,{onTrouble:be=>{if(!w){if(!be)return h(qc);h(be.kind==="store-fault"?{label:"STORE LOST",tone:"error",detail:`${be.message} ${be.detail}`}:{label:"CAPTURE FAILING",tone:"error",detail:`${be.message}. ${be.detail}. The field is showing the last world it received.`})}}});w||(M.current=Vl(me.from,me.to),E.current=Mn,f(Mn.info()),O(null),V(null),N=Mn.subscribe(be=>{M.current=be,W.current=!0}),W.current=!0)}return Y().catch(P=>{w||h({label:"SOURCE FAILED",tone:"error",detail:P instanceof Error?P.message:String(P)})}),()=>{w=!0,E.current=null,N?.()}},[n]),Q.useEffect(()=>{const w=setInterval(()=>{const N=M.current,Y=E.current?.now()??Date.now();if(zx(N,Math.max(N.now,Y)),!W.current)return;W.current=!1;const P=n1(N);g(P),b(ue=>ue+1)},iM);return()=>clearInterval(w)},[]),Q.useEffect(()=>{const w=setInterval(()=>{const N=B.current?.perf.snapshot();N&&I({fps:N.fps,gpuMs:N.gpuMs,scale:N.scale})},1e3);return()=>clearInterval(w)},[]);const te=M.current,le=Q.useMemo(()=>j0(te),[x]),$e=Q.useMemo(()=>G0(te,le),[le]),he=Q.useCallback(w=>V(w),[]),re=Q.useCallback(w=>{const N=m.disturbances.find(P=>P.id===w),Y=m.strata.find(P=>P.id===w);!N&&!Y||(O({kind:N?"disturbance":"stratum",id:w,x:N?.x??0,y:N?.y??0}),l("field"))},[m]),R=k??D,q=de!=="desktop",ae=typeof window>"u"?800:window.innerHeight,Te=Q.useMemo(()=>PT(de,!!k,H==="expanded",ae),[de,k,H,ae]),Re=R&&(!k&&R.kind==="disturbance"?v.jsx("div",{"data-anchor-placement":"label",children:v.jsx(HT,{hit:R,world:te})}):v.jsx("div",{"data-anchor-placement":"panel",children:v.jsx(Uf,{hit:R,world:te,landscape:m,band:L,onClose:()=>O(null)})}));return v.jsxs("div",{style:{position:"fixed",inset:0,display:"flex",flexDirection:"column",background:X.bg,color:X.ink,fontFamily:Et},children:[v.jsx(rM,{view:s,setView:l,feed:n,setFeed:i,sourceInfo:u,window:d}),s==="today"&&v.jsx(UT,{world:te}),s==="log"&&v.jsx(BT,{world:te,selectedId:k?.id??null,onSelect:re}),v.jsx("div",{style:{display:s==="field"?"contents":"none"},children:v.jsx(zT,{landscape:m,onHover:he,onSelect:O,anchor:q?null:R,onBand:K,compact:q,inset:Te,keepVisible:k,overlay:q&&k?de==="landscape"?v.jsx(ZT,{hit:k,world:te,landscape:m,band:L,onClose:()=>O(null)}):v.jsx(WT,{hit:k,world:te,landscape:m,band:L,detent:H,onToggleDetent:()=>Z(w=>w==="peek"?"expanded":"peek"),viewportHeight:ae,onClose:()=>O(null)}):null,onReady:w=>{B.current=w},depth:v.jsx(XT,{metrics:le,shape:$e,compact:q}),children:Re})}),v.jsx(lM,{view:s,perf:G,touch:q})]})}function rM({view:n,setView:i,feed:s,setFeed:l,sourceInfo:u,window:f}){const d=(g,x)=>{const b=n===g;return v.jsx("button",{onClick:()=>i(g),style:{background:"transparent",border:"none",padding:0,cursor:"pointer",fontFamily:Et,letterSpacing:"0.22em",fontSize:b?12.5:9.5,color:b?X.ink:X.chromeDim},children:x},g)},h=s==="synthetic",m=[f.detail,u?.detail].filter(Boolean).join(" ");return v.jsxs("div",{style:{display:"flex",alignItems:"center",gap:14,padding:"16px 24px 15px",borderBottom:`1px solid ${X.hairline}`,flexWrap:"nowrap",overflow:"hidden"},children:[v.jsx("div",{style:{fontSize:11,letterSpacing:"0.3em",color:"rgba(230,227,219,0.5)",flexShrink:0},children:"057"}),v.jsx("div",{className:"hdr-tagline",style:{fontSize:8.5,letterSpacing:"0.24em",color:X.chromeDim,flexShrink:0,whiteSpace:"nowrap"},children:"PERSONAL COMPUTATIONAL TELEMETRY"}),v.jsx("div",{className:"hdr-tagline",style:{width:1,height:12,background:"rgba(230,227,219,0.12)",flexShrink:0,margin:"0 10px"}}),v.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:20,flexShrink:0},children:[d("field","FIELD"),d("today","TODAY"),d("log","PROCESS LOG")]}),v.jsxs("div",{style:{marginLeft:"auto",display:"flex",alignItems:"center",gap:22,minWidth:0},children:[v.jsxs("div",{title:m,style:{display:"flex",alignItems:"center",gap:9,flexShrink:0,cursor:"help"},children:[v.jsx("span",{style:{width:5,height:5,borderRadius:"50%",background:tM[f.tone],flexShrink:0}}),v.jsx("span",{style:{fontSize:10,letterSpacing:"0.2em",color:X.chromeStrong,whiteSpace:"nowrap"},children:f.label})]}),v.jsxs("button",{onClick:()=>l(h?"capture":"synthetic"),title:h?"Switch to CAPTURE":"Switch to SYNTHETIC",style:{background:"transparent",border:"none",padding:"3px 0",cursor:"pointer",display:"flex",alignItems:"center",gap:8,flexShrink:0},children:[v.jsx("span",{style:{fontSize:10,color:h?X.chromeDim:X.accent},children:h?"○":"●"}),v.jsx("span",{style:{fontSize:9.5,letterSpacing:"0.16em",color:X.chrome},children:h?"SYNTHETIC":"CAPTURE"})]})]})]})}function lM({view:n,perf:i,touch:s}){return v.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:14,padding:"10px 24px 14px",borderTop:`1px solid ${X.hairline}`,fontSize:10.5,letterSpacing:"0.16em",color:X.chrome,flexWrap:"wrap"},children:[v.jsx("span",{children:n==="field"?s?"DRAG TO PAN · PINCH TO ZOOM · TAP TO INSPECT":"SCROLL TO PAN · ⌃SCROLL / PINCH TO ZOOM · CLICK TO INSPECT · ZOOM OUT FOR TODAY":n==="log"?"CLICK A ROW FOR THE FULL RECORD · CLICK A COLUMN TO SORT":"HOVER AN INFERRED MEASURE FOR THE ASSUMPTION BEHIND IT"}),v.jsx("span",{style:{marginLeft:"auto",color:X.chromeDim,fontSize:9.5},children:n==="field"&&i&&i.fps>0?`${Math.round(i.fps)}FPS${i.gpuMs>0?` · ${i.gpuMs.toFixed(1)}MS GPU`:""}${i.scale<1?` · ${Math.round(i.scale*100)}%`:""}`:""})]})}Ex.createRoot(document.getElementById("root")).render(v.jsx(Q.StrictMode,{children:v.jsx(sM,{})}));
|
|
658
|
+
`,Qy=.34,Py=3.4,g0={zoom:1,cx:580,cy:406},rT=-260,lT=1420,uT=-260,oT=1300,cT=.58,fT=.72,uf=1.7,dT=1.45;function hT(n,i){return n==="strata"?i>fT?"environment":"strata":n==="proximity"?i<dT?"environment":"proximity":i<cT?"strata":i>uf?"proximity":"environment"}function pT(n){return n.width/wn.spanX}function Tn(n,i){return pT(i)*n.zoom}function mr(n){return n.zoom=Math.max(Qy,Math.min(Py,n.zoom)),n.cx=Math.max(rT,Math.min(lT,n.cx)),n.cy=Math.max(uT,Math.min(oT,n.cy)),n}function mT(n,i,s){const l=Tn(n,i),u=i.width/l,f=i.height/l;return s.x0=n.cx-u/2,s.y0=n.cy-f/2,s.x1=n.cx+u/2,s.y1=n.cy+f/2,s}function of(n,i,s,l){const u=Tn(s,l),f=l.width/u,d=l.height/u;return[s.cx-f/2+n/u,s.cy-d/2+i/u]}function Bc(n,i,s,l){const u=Tn(s,l),f=l.width/u,d=l.height/u;return[(n-(s.cx-f/2))*u,(i-(s.cy-d/2))*u]}function Gc(n,i,s,l,u){const[f,d]=of(s,l,n,u);n.zoom=Math.max(Qy,Math.min(Py,n.zoom*i));const h=Tn(n,u);n.cx=f-s/h+u.width/h/2,n.cy=d-l/h+u.height/h/2,mr(n)}function y0(n,i,s,l){const u=Tn(n,l);n.cx+=i/u,n.cy+=s/u,mr(n)}function gT(n,i,s,l=7){const u=1-Math.exp(-l*s),f=i.zoom-n.zoom,d=i.cx-n.cx,h=i.cy-n.cy;n.zoom+=f*u,n.cx+=d*u,n.cy+=h*u;const m=Math.abs(f)<.001&&Math.abs(d)<.4&&Math.abs(h)<.4;return m&&(n.zoom=i.zoom,n.cx=i.cx,n.cy=i.cy),m}function yT(n,i,s){return mr({zoom:s,cx:n,cy:i})}const $l=120,vT="field",bT=5,xT=2,v0=30;class ST{intervalMs=new Float32Array($l);cpuMs=new Float32Array($l);cursor=0;filled=0;lastFrameAt=0;frames=0;lastIntervalMs=0;lastCpuMs=0;gpuMs={};disturbances=0;fps=0;resolutionScale=1;get canAdapt(){return this.bakeSamples>0}lastEvalAt=0;pendingResize=!1;bakeSum=0;bakeSamples=0;sample(i,s,l){const u=this.gpuMs[vT];if(u!==void 0&&u>0&&(this.bakeSum+=u,this.bakeSamples++),this.lastFrameAt>0){const f=i-this.lastFrameAt;this.intervalMs[this.cursor]=f,this.cpuMs[this.cursor]=s,this.cursor=(this.cursor+1)%$l,this.filled<$l&&this.filled++,this.lastIntervalMs=f}this.lastFrameAt=i,this.lastCpuMs=s,this.frames++,this.disturbances=l,this.fps=this.averageInterval>0?1e3/this.averageInterval:0,this.maybeAdapt(i)}resetPacing(){this.lastFrameAt=0}get averageInterval(){if(this.filled===0)return 0;let i=0;for(let s=0;s<this.filled;s++)i+=this.intervalMs[s];return i/this.filled}get averageCpuMs(){if(this.filled===0)return 0;let i=0;for(let s=0;s<this.filled;s++)i+=this.cpuMs[s];return i/this.filled}get totalGpuMs(){let i=0;for(const s in this.gpuMs)i+=this.gpuMs[s];return i}bakeCost(){return this.bakeSamples<v0?0:this.bakeSum/this.bakeSamples}maybeAdapt(i){if(i-this.lastEvalAt<2e3||this.filled<45)return;const s=this.bakeCost();this.bakeSamples<v0||(this.lastEvalAt=i,this.bakeSum=0,this.bakeSamples=0,!(s<=0)&&(s>bT&&this.resolutionScale>.5?(this.resolutionScale=Math.max(.5,this.resolutionScale-.15),this.pendingResize=!0):s<xT&&this.resolutionScale<1&&(this.resolutionScale=Math.min(1,this.resolutionScale+.1),this.pendingResize=!0)))}wantsResize(){return this.pendingResize?(this.pendingResize=!1,!0):!1}snapshot(){return{fps:this.fps,intervalMs:this.averageInterval,cpuMs:this.averageCpuMs,gpuMs:this.totalGpuMs,frames:this.frames,scale:this.resolutionScale,disturbances:this.disturbances}}}const Pn=[{rows:22,step:11,amp:.5,alpha:.4,lw:.75,dz:-190,px:44,fill:[5,6,8,.9]},{rows:14,step:9,amp:.74,alpha:.72,lw:.9,dz:-92,px:18,fill:[5,6,8,.94]},{rows:9,step:7.5,amp:1,alpha:1,lw:1,dz:0,px:0,fill:[4,5,7,.965]}],b0={running:0,waiting:1,failed:2,completed:3,idle:4},x0={laptop:[214,176,116],desktop:[168,186,150],server:[150,190,175]},S0=512,wT=[3,2,2],w0=0,E0=1,Ji=2,A0=1,T0=2,ET=4,AT=1600,M0=.004;function TT(n){return n.msSinceInteraction<AT?A0:n.couplings>0||n.maxEnergy>M0?T0:n.maxSettling>M0?ET:n.dirty?A0:1/0}class MT{gpu;surf=null;output;residue;fieldTarget;gpuTimer=null;spans=null;layerSpans=[];probe=null;sheetVariants=new Map;linearSampler;residueFx;fieldFx;sheetDraw;coresDraw;strataDraw;paramsBufs=[];massBuf;distBuf;coupBuf;strataBuf;plinthBuf;params=new Float32Array(36);massArr=new Float32Array(f0*3*4);distArr=new Float32Array(d0*3*4);coupArr=new Float32Array(h0*4);strataArr=new Float32Array(S0*4);plinthArr=new Float32Array(lf*3*4);rect={x0:0,y0:0,x1:0,y1:0};landscape={time:0,masses:[],disturbances:[],plinths:[],couplings:[],strata:[]};massIndex=new Map;runtime=new Map;plinthRuntime=new Map;plinthStatics=new Map;frameSubscribers=new Set;generation=0;lastInstances=0;strataCount=0;disturbanceCount=0;couplingCount=0;massCount=0;plinthCount=0;raf=0;refreshCount=0;lastStride=1;lastDrawnAt=0;nextDrawAt=0;dirty=!0;running=!1;lastFrameAt=0;simTime=0;lastInteractionAt=0;disposed=!1;landscapeDirty=!0;perf=new ST;camera;canvas;headless;maxDpr;initGpu;view={width:1,height:1};constructor(i){if(this.canvas=i.canvas??null,this.headless=i.headless??null,this.camera=i.camera,this.maxDpr=i.maxDpr??1.25,this.initGpu=i.initGpu??(async()=>{try{return await c0({requiredFeatures:["timestamp-query"]})}catch{return await c0()}}),!this.canvas&&!this.headless)throw new Error("FieldRenderer needs either a canvas or a headless size")}async init(){this.gpu=await this.initGpu();try{const f=WA(this.gpu);this.gpuTimer=f,this.spans={residue:f.span("residue"),field:f.span("field"),sheet:f.span("sheet"),overlay:f.span("overlay")},this.layerSpans=[0,1,2].map(d=>f.span(`sheet${d}`)),f.onResults(d=>{this.perf.gpuMs=d,this.probe?.noteGpu(d)}),this.probe?.note("timestamp-query available")}catch(f){this.gpuTimer=null,this.spans=null,this.layerSpans=[],this.probe?.note(`timestamp-query unavailable: ${f instanceof Error?f.message:String(f)}`)}if(this.headless)this.output=s0(this.gpu,{size:[this.headless.width,this.headless.height],format:"rgba8unorm"});else{const f=this.canvas;await DT(f);const d=Math.min(this.maxDpr,globalThis.devicePixelRatio||1),[h,m]=this.cssSize();f.width=Math.round(h*d),f.height=Math.round(m*d),this.surf=EE(this.gpu,f,{dpr:d,autoResize:!0}),this.output=this.surf,this.view.width=h,this.view.height=m}this.residue=IA(this.gpu,p0,p0,{format:"rgba16float"});const[i,s]=this.fieldSize();this.fieldTarget=s0(this.gpu,{size:[i,s],format:"rgba16float"}),this.paramsBufs=Array.from({length:5},()=>Ya(this.gpu,this.params.byteLength,"read")),this.massBuf=Ya(this.gpu,this.massArr.byteLength,"read"),this.distBuf=Ya(this.gpu,this.distArr.byteLength,"read"),this.coupBuf=Ya(this.gpu,this.coupArr.byteLength,"read"),this.strataBuf=Ya(this.gpu,this.strataArr.byteLength,"read"),this.plinthBuf=Ya(this.gpu,this.plinthArr.byteLength,"read");const l=$E(this.gpu,{minFilter:"linear",magFilter:"linear"});this.linearSampler=l,this.residueFx=a0(this.gpu,nT,{set:{P:this.paramsBufs[w0],massData:this.massBuf,distData:this.distBuf,coupData:this.coupBuf,prevTex:this.residue.read,prevSamp:l}}),this.fieldFx=a0(this.gpu,iT,{set:{P:this.paramsBufs[E0],massData:this.massBuf,distData:this.distBuf,coupData:this.coupBuf,residueTex:this.residue.read,residueSamp:l,plinthData:this.plinthBuf}}),this.sheetDraw=Bl(this.gpu,{shader:m0,vertices:6,blend:"premultiplied",set:{P:this.paramsBufs[Ji],massData:this.massBuf,fieldTex:this.fieldTarget,fieldSamp:l}}),this.coresDraw=Bl(this.gpu,{shader:aT,vertices:6,blend:"additive",set:{P:this.paramsBufs[Ji],distData:this.distBuf}}),this.strataDraw=Bl(this.gpu,{shader:sT,vertices:6,blend:"premultiplied",set:{P:this.paramsBufs[Ji],massData:this.massBuf,strataData:this.strataBuf}});const u={colors:[this.output.format]};await Promise.all([this.residueFx.compile(this.residue.write),this.fieldFx.compile(this.fieldTarget),this.sheetDraw.compile(u),this.coresDraw.compile(u),this.strataDraw.compile(u)])}cssSize(){const i=this.canvas;if(!i)return[this.headless.width,this.headless.height];const s=i.parentElement,l=i.clientWidth||s?.clientWidth||1280,u=i.clientHeight||s?.clientHeight||720;return[Math.max(1,l),Math.max(1,u)]}fieldSize(){const i=this.perf.resolutionScale,s=this.headless?.width??this.canvas?.clientWidth??640,l=this.headless?.height??this.canvas?.clientHeight??480,u=Math.max(160,Math.round(Math.min(768,s)*i)),f=Math.max(120,Math.round(Math.min(576,l)*i));return[u,f]}attachProbe(i){this.probe=i}setLandscape(i){const s=this.probe?performance.now():0;this.landscape=i,this.landscapeDirty=!0,this.generation++,this.probe&&(this.probe.landscapes++,queueMicrotask(()=>this.probe?.landscapeMs.push(performance.now()-s)));const l=this.generation;for(const u of i.disturbances){let f=this.runtime.get(u.id);f||(f={energy:0,target:u.energy,status:u.status,statusSince:u.statusSince,seen:l,extent:u.extent,toExtent:u.extent},this.runtime.set(u.id,f)),f.target=u.energy,f.status=u.status,f.statusSince=u.statusSince,f.seen=l,f.toExtent=u.extent}for(const[u,f]of this.runtime)f.seen!==l&&(f.target=0,f.energy<.002&&this.runtime.delete(u));for(const u of i.plinths){let f=this.plinthRuntime.get(u.id);f||(f={presence:0,target:u.presence,x:u.x,y:u.y,extentX:u.extentX,extentY:u.extentY,toX:u.x,toY:u.y,toExtentX:u.extentX,toExtentY:u.extentY,seen:l},this.plinthRuntime.set(u.id,f)),f.target=u.presence,f.toX=u.x,f.toY=u.y,f.toExtentX=u.extentX,f.toExtentY=u.extentY,f.seen=l,this.plinthStatics.set(u.id,u)}for(const[u,f]of this.plinthRuntime)f.seen!==l&&(f.target=0,f.presence<.002&&(this.plinthRuntime.delete(u),this.plinthStatics.delete(u)))}noteInteraction(){this.lastInteractionAt=performance.now(),this.dirty=!0}onFrame(i){return this.frameSubscribers.add(i),()=>this.frameSubscribers.delete(i)}start(){if(this.running||this.disposed)return;this.running=!0,this.lastFrameAt=performance.now(),this.refreshCount=0,this.nextDrawAt=0;const i=s=>{if(!this.running)return;this.raf=requestAnimationFrame(i),this.refreshCount++;const l=this.currentStride(s);if(this.probe?.noteRefresh(s,l),l===1/0){this.perf.resetPacing(),this.lastDrawnAt=0,this.lastFrameAt=s,this.nextDrawAt=this.refreshCount+1;return}if(this.refreshCount<this.nextDrawAt)return;this.nextDrawAt=this.refreshCount+l;const u=s-this.lastFrameAt;this.lastFrameAt=s,this.lastStride=l;const f=this.probe?.debug.fixedDt??null,d=f!==null?f:Math.min(.1,u/1e3);this.renderFrame(d)};this.raf=requestAnimationFrame(i)}stop(){this.running=!1,this.raf&&cancelAnimationFrame(this.raf),this.raf=0}invalidate(){this.dirty=!0}currentStride(i){let s=0,l=0;for(const u of this.runtime.values()){u.energy>s&&(s=u.energy);const f=Math.abs(u.target-u.energy);f>l&&(l=f);const d=Math.abs(u.toExtent-u.extent);d>l&&(l=d)}for(const u of this.plinthRuntime.values()){const f=Math.abs(u.target-u.presence);f>l&&(l=f)}return TT({dirty:this.dirty||this.landscapeDirty,msSinceInteraction:i-this.lastInteractionAt,couplings:this.couplingCount,maxEnergy:s,maxSettling:l})}stepPhysics(i){const s=this.simTime;for(const l of this.runtime.values()){let u=l.target;if(l.status==="failed"){const d=Math.max(0,s-l.statusSince/1e3);d<1.4?u=l.target*(1+.45*Math.sin(d*44)):u=l.target*Math.max(0,1-(d-1.4)/2.2)*.22}const f=u>l.energy?2.6:1.1;l.energy+=(u-l.energy)*(1-Math.exp(-f*i)),l.energy<5e-4&&u===0&&(l.energy=0),l.extent+=(l.toExtent-l.extent)*(1-Math.exp(-3*i))}for(const l of this.plinthRuntime.values()){const u=l.target>l.presence?1.8:.9;l.presence+=(l.target-l.presence)*(1-Math.exp(-u*i)),l.presence<5e-4&&l.target===0&&(l.presence=0);const f=1-Math.exp(-3*i);l.x+=(l.toX-l.x)*f,l.y+=(l.toY-l.y)*f,l.extentX+=(l.toExtentX-l.extentX)*f,l.extentY+=(l.toExtentY-l.extentY)*f}}packStatics(){const{masses:i,couplings:s,strata:l}=this.landscape;this.massIndex.clear(),this.massArr.fill(0),this.massCount=Math.min(i.length,f0);for(let u=0;u<this.massCount;u++){const f=i[u];this.massIndex.set(f.id,u);const d=u*12;this.massArr[d+0]=f.x,this.massArr[d+1]=f.y,this.massArr[d+2]=f.extentX,this.massArr[d+3]=f.extentY;const h=f.extentX/300;this.massArr[d+4]=72*h,this.massArr[d+5]=27*h,this.massArr[d+6]=30*h,this.massArr[d+7]=.34+f.seed*.12,this.massArr[d+8]=f.seed*Math.PI*2;const m=x0[f.kind]??x0.laptop;this.massArr[d+9]=m[0],this.massArr[d+10]=m[1],this.massArr[d+11]=m[2]}this.massBuf.write(this.massArr),this.coupArr.fill(0),this.couplingCount=0;for(const u of s){if(this.couplingCount>=h0)break;const f=this.massIndex.get(u.fromMassId),d=this.massIndex.get(u.toMassId);if(f===void 0||d===void 0)continue;const h=this.couplingCount*4;this.coupArr[h+0]=f,this.coupArr[h+1]=d,this.coupArr[h+2]=u.energy,this.couplingCount++}this.coupBuf.write(this.coupArr),this.strataArr.fill(0),this.strataCount=Math.min(l.length,S0);for(let u=0;u<this.strataCount;u++){const f=l[u],d=u*4;this.strataArr[d+0]=f.startFraction,this.strataArr[d+1]=f.endFraction,this.strataArr[d+2]=Math.min(f.lane,this.massCount-1),this.strataArr[d+3]=b0[f.status]}this.strataBuf.write(this.strataArr)}packDisturbances(){this.distArr.fill(0);let i=0;for(const s of this.landscape.disturbances){if(i>=d0)break;const l=this.runtime.get(s.id),u=l?l.energy:s.energy;if(u<=5e-4)continue;const f=l?l.extent:s.extent,d=30+f*44,h=d*(.62+.22*f),m=i*12;this.distArr[m+0]=s.x,this.distArr[m+1]=s.y,this.distArr[m+2]=d,this.distArr[m+3]=h*u,this.distArr[m+4]=.9+s.rate*1.15,this.distArr[m+5]=s.phase,this.distArr[m+6]=b0[s.status],this.distArr[m+7]=u,this.distArr[m+8]=s.articulation,this.distArr[m+9]=s.shoulder,i++}this.disturbanceCount=i,this.distBuf.write(this.distArr)}packPlinths(){this.plinthArr.fill(0);const i=[];let s=0;for(const[l,u]of this.plinthRuntime){if(s>=lf)break;if(u.presence<=5e-4)continue;const f=this.plinthStatics.get(l);if(!f)continue;const d=s*12;this.plinthArr[d+0]=u.x,this.plinthArr[d+1]=u.y,this.plinthArr[d+2]=u.extentX,this.plinthArr[d+3]=u.extentY,this.plinthArr[d+4]=u.presence,this.plinthArr[d+5]=f.articulation,this.plinthArr[d+7]=f.empty?1:0,this.plinthArr[d+8]=f.shoulder,i.push({id:l,parentId:f.parentId}),s++}for(let l=0;l<i.length;l++){const u=i[l].parentId,f=u?i.findIndex(d=>d.id===u):-1;this.plinthArr[l*12+6]=f+1,this.plinthArr[l*12+9]=f>=0?1:0}this.plinthCount=s,this.plinthBuf.write(this.plinthArr)}packParams(i,s,l,u){const f=this.params,d=Tn(this.camera,this.view);f[0]=this.rect.x0,f[1]=this.rect.y0,f[2]=this.rect.x1,f[3]=this.rect.y1,f[4]=this.view.width,f[5]=this.view.height,f[6]=d,f[7]=this.simTime,f[8]=this.massCount,f[9]=this.disturbanceCount,f[10]=this.couplingCount,f[11]=s;const h=Pn[u]??Pn[0];f[12]=h.rows,f[13]=h.step,f[14]=h.amp,f[15]=h.alpha,f[16]=h.lw,f[17]=h.dz,f[18]=h.px,f[19]=1,f[20]=this.colsFor(h.step,d),f[21]=this.rowsFor(h.rows,d),f[22]=Math.max(1,this.massCount),f[23]=this.plinthCount,f[24]=h.fill[0]/255*h.fill[3],f[25]=h.fill[1]/255*h.fill[3],f[26]=h.fill[2]/255*h.fill[3],f[27]=h.fill[3],f[28]=l.x0,f[29]=l.y0,f[30]=l.x1,f[31]=l.y1;const m=i>=Ji?wT[u]??0:0;f[32]=this.probe?.debug.fillReach??m,f[33]=0,f[34]=0,f[35]=0,this.paramsBufs[i].write(f)}colsFor(i,s){const l=i/s,u=this.rect.x1-this.rect.x0+l*4;return Math.max(2,Math.min(1024,Math.ceil(u/l)))}rowsFor(i,s){const l=i/s,f=Math.min(this.rect.y1,832)+90/s-(this.rect.y0-l*.6);return Math.max(2,Math.min(512,Math.ceil(f/l)))}renderOnce(i){this.renderFrame(Math.min(.25,i))}async debugField(){const i=await this.fieldTarget.readFloats();let s=1/0,l=-1/0,u=0;for(let f=0;f<i.length;f+=4){const d=i[f];Number.isNaN(d)?u++:(d<s&&(s=d),d>l&&(l=d))}return{min:s,max:l,nan:u,sample:Array.from(i.slice(0,16))}}stats(){return{runtimeEntries:this.runtime.size,disturbances:this.disturbanceCount,plinths:this.plinthCount,strata:this.strataCount,couplings:this.couplingCount,instances:this.lastInstances}}renderFrame(i){if(this.disposed)return;const s=performance.now();if(this.simTime+=i,mr(this.camera),this.headless){const[O,L]=this.output.size;this.view.width=O,this.view.height=L}else{const O=this.canvas;if(O&&(O.clientWidth===0||O.clientHeight===0)){this.perf.resetPacing(),this.lastDrawnAt=0;return}const[L,K]=this.cssSize();if(L!==this.view.width||K!==this.view.height){this.view.width=L,this.view.height=K;const G=Math.min(this.maxDpr,globalThis.devicePixelRatio||1);this.canvas.width=Math.round(L*G),this.canvas.height=Math.round(K*G),this.surf?.resize([L,K]);const[I,H]=this.fieldSize();this.fieldTarget.resize([I,H]),this.probe&&(this.probe.canvasResizes++,this.probe.note(`canvas ${L}×${K} css → ${O?.width}×${O?.height}, field ${I}×${H}`))}}mT(this.camera,this.view,this.rect),this.stepPhysics(i),this.landscapeDirty&&(this.packStatics(),this.landscapeDirty=!1),this.packDisturbances(),this.packPlinths();const l=(this.rect.x1-this.rect.x0)*.12,u=(this.rect.y1-this.rect.y0)*.16,f={x0:this.rect.x0-l,y0:this.rect.y0-u,x1:this.rect.x1+l,y1:this.rect.y1+u},d=Tn(this.camera,this.view);this.packParams(w0,i,sr,0),this.packParams(E0,i,f,0);for(let O=0;O<Pn.length;O++)this.packParams(Ji+O,i,f,O);const h=this.probe?this.probe.debug:null,m=h&&(h.skipFill||h.skipLine)?this.sheetVariantDraw(h):this.sheetDraw,g=this.probe?performance.now():0;let x=0;const b=[];TA(this.gpu,O=>{h?.skipResidue||(this.residueFx.set({prevTex:this.residue.read}),O.pass(this.spans?{target:this.residue.write,clear:!1,timer:this.spans.residue}:{target:this.residue.write,clear:!1},this.residueFx),x++),h?.skipField||(this.fieldFx.set({residueTex:this.residue.write}),O.pass(this.spans?{target:this.fieldTarget,clear:!0,timer:this.spans.field}:{target:this.fieldTarget,clear:!0},this.fieldFx),x++);let L=0;const K=(I,H)=>{const Z=Pn[H],de=this.colsFor(Z.step,d),M=this.rowsFor(Z.rows,d),E=de*M*2;this.probe&&b.push({cols:de,rows:M,instances:E}),!(h&&!h.layers[H])&&(L+=E,m.set({P:this.paramsBufs[Ji+H]}),I.draw(m,{instances:E}))},G=[.024,.027,.035,1];if(h?.splitLayers&&this.layerSpans.length===Pn.length){for(let I=0;I<Pn.length;I++)O.pass(I===0?{target:this.output,clear:G,timer:this.layerSpans[I]}:{target:this.output,clear:!1,timer:this.layerSpans[I]},H=>K(H,I)),x++;O.pass(this.spans?{target:this.output,clear:!1,timer:this.spans.overlay}:{target:this.output,clear:!1},I=>{this.strataCount>0&&!h?.skipStrata&&I.draw(this.strataDraw,{instances:this.strataCount}),this.disturbanceCount>0&&!h?.skipCores&&I.draw(this.coresDraw,{instances:this.disturbanceCount})}),x++}else O.pass(this.spans?{target:this.output,clear:G,timer:this.spans.sheet}:{target:this.output,clear:G},I=>{for(let H=0;H<Pn.length;H++)K(I,H);this.strataCount>0&&!h?.skipStrata&&I.draw(this.strataDraw,{instances:this.strataCount}),this.disturbanceCount>0&&!h?.skipCores&&I.draw(this.coresDraw,{instances:this.disturbanceCount})}),x++;this.lastInstances=L+this.strataCount+this.disturbanceCount}),this.residue.swap(),this.dirty=!1;const D=this.probe?performance.now():0;if(!h?.skipSubscribers)for(const O of this.frameSubscribers)O(this.view);const V=performance.now(),k=this.lastDrawnAt>0?s-this.lastDrawnAt:0;if(this.lastDrawnAt=s,this.perf.sample(s,V-s,this.disturbanceCount),this.probe&&(this.probe.noteFrame({interval:k,stride:this.lastStride,prep:g-s,encode:D-g,post:V-D,total:V-s}),this.captureScene(x,b)),this.perf.wantsResize()){const[O,L]=this.fieldSize(),[K,G]=this.fieldTarget.size;(O!==K||L!==G)&&(this.fieldTarget.resize([O,L]),this.probe&&(this.probe.fieldResizes++,this.probe.note(`field texture ${K}×${G} → ${O}×${L} (scale ${this.perf.resolutionScale.toFixed(2)})`)))}}sheetVariantDraw(i){const s=`${i.skipFill?"F":""}${i.skipLine?"L":""}`;let l=this.sheetVariants.get(s);return!l&&this.probe&&(l=Bl(this.gpu,{shader:this.probe.sheetVariant(m0,{skipFill:i.skipFill,skipLine:i.skipLine}),vertices:6,blend:"premultiplied",set:{P:this.paramsBufs[Ji],massData:this.massBuf,fieldTex:this.fieldTarget,fieldSamp:this.linearSampler}}),this.sheetVariants.set(s,l),this.probe.note(`sheet variant '${s}' compiled`)),l??this.sheetDraw}captureScene(i,s){if(!this.probe)return;const l=this.view.width,u=this.view.height,f=this.canvas?.width??this.output.size[0],d=this.canvas?.height??this.output.size[1],h=Tn(this.camera,this.view);let m=0;for(let x=0;x<Pn.length;x++){const D=Pn[x].rows/h,V=this.rect.y0-D*.6,k=s[x]?.rows??0;for(let O=0;O<k;O++){const L=(V+O*D-this.rect.y0)*h;L<u&&(m+=(u-Math.max(0,L))/u)}}let g=0;for(const x of s)g+=x.instances;this.probe.scene={cssW:l,cssH:u,canvasW:f,canvasH:d,dpr:this.surf?.dpr??1,devicePixelRatio:globalThis.devicePixelRatio??1,resolutionScale:this.perf.resolutionScale,fieldW:this.fieldTarget.size[0],fieldH:this.fieldTarget.size[1],zoom:this.camera.zoom,masses:this.massCount,disturbances:this.disturbanceCount,plinths:this.plinthCount,couplings:this.couplingCount,strata:this.strataCount,runtimeEntries:this.runtime.size,layers:s,instances:g+this.strataCount+this.disturbanceCount,passes:i,fillOverdraw:m,fillFragments:m*f*d}}dispose(){this.stop(),this.disposed=!0,this.runtime.clear(),this.plinthRuntime.clear(),this.plinthStatics.clear(),this.massIndex.clear(),this.frameSubscribers.clear(),this.gpuTimer?.dispose(),this.gpuTimer=null,this.probe?.dispose(),this.gpu?.dispose()}}function DT(n,i=2e3){return n.clientWidth>0&&n.clientHeight>0?Promise.resolve():new Promise(s=>{let l=!1;const u=()=>{l||(l=!0,f.disconnect(),clearTimeout(d),s())},f=new ResizeObserver(()=>{n.clientWidth>0&&n.clientHeight>0&&u()});f.observe(n);const d=setTimeout(u,i)})}const X={bg:"#050608",ink:"#e6e3db",accent:"#d9a441",accentBright:"#f0c374",hoverInk:"#f5cf8b",panel:"rgba(7,8,11,0.94)",panelBorder:"rgba(230,227,219,0.4)",hairline:"rgba(230,227,219,0.14)",chrome:"rgba(230,227,219,0.62)",chromeDim:"rgba(230,227,219,0.4)",chromeMid:"rgba(230,227,219,0.7)",chromeStrong:"rgba(230,227,219,0.82)",body:"rgba(230,227,219,0.88)"},at={running:"rgba(240,195,116,0.85)",waiting:"rgba(150,175,196,0.85)",failed:"rgba(206,104,90,0.9)",completed:"rgba(180,210,175,0.75)",idle:"rgba(230,227,219,0.62)"},Et="'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace",Za="0 0 6px rgba(5,6,8,0.95)",RT={backgroundImage:"radial-gradient(rgba(230,227,219,0.05) 0.5px, rgba(0,0,0,0) 0.6px)",backgroundSize:"3px 3px"},CT={background:"radial-gradient(96% 82% at 44% 56%, rgba(0,0,0,0) 42%, rgba(3,3,5,0.9) 100%)"},OT={background:"linear-gradient(to bottom, rgba(6,8,11,0.7), rgba(6,8,11,0))"};let $c=Promise.resolve();function zT({landscape:n,onHover:i,onSelect:s,anchor:l,children:u,onBand:f,onReady:d,depth:h,overlay:m,inset:g,keepVisible:x,compact:b=!1}){const D=Q.useRef(null),V=Q.useRef(null),k=Q.useRef(null),O=Q.useRef({...g0}),L=Q.useRef(n),K=Q.useRef(new Map),G=Q.useRef(null),I=Q.useRef(null),H=Q.useRef(null),Z=Q.useRef(null),de=Q.useRef(null),M=Q.useRef(new Map),E=Q.useRef(null),B=Q.useRef({key:"",w:0,h:0,label:!1}),[W,te]=Q.useState("init"),[le,$e]=Q.useState(null),[he,re]=Q.useState("environment"),[R,q]=Q.useState([]),[ae,Te]=Q.useState("grab");L.current=n,Q.useEffect(()=>{const ee=V.current;if(!ee)return;let J=!1,ye=null;const Ce=$c.then(async()=>{if(!J){if(ye=new MT({canvas:ee,camera:O.current}),await ye.init(),J){ye.dispose(),ye=null;return}k.current=ye,ye.setLandscape(L.current),ye.start(),te("ready"),d?.(ye)}}).catch(Ke=>{J||($e(Ke instanceof Error?Ke.message:String(Ke)),te("failed"))});return $c=Ce,()=>{J=!0,k.current=null,$c=Ce.then(()=>{ye?.dispose(),ye=null})}},[]),Q.useEffect(()=>{k.current?.setLandscape(n)},[n]),Q.useEffect(()=>{const ee=[];for(const J of n.masses)ee.push({id:`mass:${J.id}`,wx:J.x,wy:J.y+J.extentY+26,text:J.name,color:"rgba(230,227,219,0.78)",size:10});if(he==="proximity"){for(const J of n.disturbances)J.energy<.02&&J.status!=="completed"||ee.push({id:`dist:${J.id}`,wx:J.x,wy:J.y-30-J.extent*40,text:`${J.label} · ${J.status}`,color:at[J.status],size:9});for(const J of n.plinths)ee.push({id:`plinth:${J.id}`,wx:J.x,wy:J.y-J.extentY-16,text:`${J.parentId?"└ ":""}${J.label}${J.observers>1?` · ${J.observers} obs`:""}`,color:`rgba(240,195,116,${(.16+.5*J.articulation).toFixed(2)})`,size:9})}q(ee)},[n,he]),Q.useLayoutEffect(()=>{const ee=k.current;if(!ee)return;let J=0;const ye=Ce=>{const Ke=O.current,Qe=performance.now(),Kt=J===0?1/60:Math.min(.1,(Qe-J)/1e3);J=Qe,Z.current&&(gT(Ke,Z.current,Kt)&&(Z.current=null),ee.noteInteraction());const Ve=hT(Re.current,Ke.zoom);Ve!==Re.current&&(Re.current=Ve,re(Ve),f?.(Ve));for(const[At,ct]of K.current){const He=N.current.get(At);if(!He)continue;const[St,tt]=Bc(He.wx,He.wy,Ke,Ce),_i=St>-200&&St<Ce.width+200&&tt>-80&&tt<Ce.height+80;ct.style.visibility=_i?"visible":"hidden",ct.style.transform=`translate3d(${St}px, ${tt}px, 0) translate(-50%, -100%)`}const dn=G.current,xt=w.current;if(dn&&xt){const[At,ct]=Bc(xt.x,xt.y,Ke,Ce),He=dn.firstElementChild;He&&B.current.key!==xt.id&&(B.current={key:xt.id,w:He.offsetWidth,h:He.offsetHeight,label:He.dataset.anchorPlacement==="label"});const{w:St,h:tt,label:_i}=B.current;let Ui=_i?-St/2:18,ls=_i?-tt-14:-tt/2;!_i&&At+Ui+St>Ce.width-12&&(Ui=-St-18),Ui=Math.max(12-At,Ui),ls=Math.min(Math.max(12-ct,ls),Ce.height-12-tt-ct),dn.style.transform=`translate3d(${At+Ui}px, ${ct+ls}px, 0)`,dn.style.visibility=At>-300&&At<Ce.width+300&&ct>-300&&ct<Ce.height+300?"visible":"hidden"}const Lt=Ke.cy+Ce.height/Tn(Ke,Ce)/2,Dn=Lt>wn.strataTop+40,la=Lt>wn.strataTop+wn.strataHeight*.7,Rn=I.current,zi=Rn?.querySelector("[data-depth-label]");if(zi){const At=Dn?la?"FIELD — TODAY":"FIELD — SURFACE + TODAY":"FIELD — LIVE";zi.textContent!==At&&(zi.textContent=At)}if(Rn){const At=Rn.querySelector("[data-depth-summary]"),ct=Rn.querySelector("[data-depth-deep]");if(At&&(At.style.display=Dn?"inline-flex":"none"),ct){const He=ct.dataset.depthSuppressed==="true";ct.style.display=la&&!He?"block":"none"}}};return ee.onFrame(ye)},[W,f]);const Re=Q.useRef("environment"),w=Q.useRef(null),N=Q.useRef(new Map);w.current=l,Q.useEffect(()=>{N.current=new Map(R.map(ee=>[ee.id,ee]))},[R]);const Y=Q.useCallback(()=>{const ee=D.current;return{width:ee?.clientWidth??1,height:ee?.clientHeight??1}},[]),P=g?.right??0,ue=g?.bottom??0,fe=x?.id??null,me=x?.x??0,Ze=x?.y??0;Q.useEffect(()=>{const ee=k.current;if(!ee||!fe||P===0&&ue===0)return;const J=Y(),ye={...Z.current??O.current},Ce=Tn(ye,J);if(Ce<=0)return;const[Ke,Qe]=Bc(me,Ze,ye,J);let Kt=!1;if(P>0){const Ve=J.width-P-40;Ke>Ve&&(ye.cx+=(Ke-(J.width-P)/2)/Ce,Kt=!0)}if(ue>0){const Ve=J.height-ue-40;Qe>Ve&&(ye.cy+=(Qe-(Ve-60))/Ce,Kt=!0)}Qe<70&&(ye.cy-=(110-Qe)/Ce,Kt=!0),Kt&&(Z.current=mr(ye),ee.noteInteraction())},[fe,me,Ze,P,ue,Y]);const De=Q.useCallback(ee=>{const J=D.current.getBoundingClientRect();return[ee.clientX-J.left,ee.clientY-J.top]},[]),gn=Q.useCallback(ee=>{const J=k.current;if(!J)return;const[ye,Ce]=De(ee);Z.current=null,ee.ctrlKey||ee.metaKey?Gc(O.current,Math.exp(-ee.deltaY*.012),ye,Ce,Y()):y0(O.current,ee.deltaX,ee.deltaY,Y()),J.noteInteraction()},[De,Y]);Q.useEffect(()=>{const ee=D.current;if(!ee)return;const J=ye=>ye.preventDefault();return ee.addEventListener("wheel",J,{passive:!1}),()=>ee.removeEventListener("wheel",J)},[]);const Jn=Q.useCallback(ee=>{const J=De(ee);ee.isPrimary&&M.current.clear(),M.current.set(ee.pointerId,J),Z.current=null;try{D.current?.setPointerCapture(ee.pointerId)}catch{}if(M.current.size===1)H.current={x:J[0],y:J[1],moved:!1},Te("grabbing");else if(M.current.size===2){const[ye,Ce]=[...M.current.values()];E.current={distance:Math.hypot(ye[0]-Ce[0],ye[1]-Ce[1]),zoom:O.current.zoom},H.current=null}k.current?.noteInteraction()},[De]),Mt=Q.useCallback(ee=>{const J=k.current;if(!J)return;const ye=De(ee),Ce=M.current.has(ee.pointerId);Ce&&M.current.set(ee.pointerId,ye);const Ke=E.current;if(Ke&&M.current.size>=2){const[xt,Lt]=[...M.current.values()],Dn=Math.hypot(xt[0]-Lt[0],xt[1]-Lt[1]),la=(xt[0]+Lt[0])/2,Rn=(xt[1]+Lt[1])/2,zi=Ke.zoom*(Dn/Math.max(12,Ke.distance));Gc(O.current,zi/O.current.zoom,la,Rn,Y()),J.noteInteraction();return}const Qe=H.current;if(Ce&&Qe){const xt=ye[0]-Qe.x,Lt=ye[1]-Qe.y;(Math.abs(xt)>4||Math.abs(Lt)>4)&&(Qe.moved=!0),y0(O.current,-xt,-Lt,Y()),Qe.x=ye[0],Qe.y=ye[1],J.noteInteraction();return}if(ee.pointerType==="touch")return;const[Kt,Ve]=of(ye[0],ye[1],O.current,Y()),dn=Ym(L.current,Kt,Ve);Te(dn?"pointer":"grab"),(dn||de.current)&&J.noteInteraction(),de.current=dn,i(dn)},[De,i,Y]),Mn=Q.useCallback(ee=>{const J=M.current.get(ee.pointerId)??De(ee);M.current.delete(ee.pointerId),M.current.size<2&&(E.current=null);const ye=H.current;if(H.current=null,Te("grab"),!ye||ye.moved)return;const[Ce,Ke]=of(J[0],J[1],O.current,Y()),Qe=Ym(L.current,Ce,Ke);if(s(Qe),Qe&&Qe.kind!=="stratum"){const Kt=Qe.kind==="mass"?uf:uf+.5;Z.current=yT(Qe.x,Qe.y,Math.max(O.current.zoom,Kt))}k.current?.noteInteraction()},[De,s,Y]),be=Q.useCallback(()=>{H.current=null,E.current=null,M.current.clear(),Te("grab")},[]),yn=Q.useCallback(()=>{Z.current={...g0},k.current?.noteInteraction(),s(null)},[s]),fn=Q.useCallback(ee=>{const J=Y();Gc(O.current,ee,J.width/2,J.height/2,J),k.current?.noteInteraction()},[Y]);return v.jsxs("div",{style:{position:"relative",flex:1,minHeight:0},children:[v.jsxs("div",{ref:D,onWheel:gn,onPointerDown:Jn,onPointerMove:Mt,onPointerUp:Mn,onPointerCancel:Mn,onLostPointerCapture:ee=>{M.current.delete(ee.pointerId),M.current.size<2&&(E.current=null)},onPointerLeave:ee=>{ee.pointerType!=="touch"&&(be(),i(null))},style:{position:"absolute",inset:0,overflow:"hidden",background:X.bg,cursor:ae},children:[v.jsx("canvas",{ref:V,style:{display:"block",width:"100%",height:"100%"}}),v.jsx("div",{style:{position:"absolute",inset:0,pointerEvents:"none",...RT}}),v.jsx("div",{style:{position:"absolute",inset:0,pointerEvents:"none",...CT}}),v.jsx("div",{style:{position:"absolute",left:0,right:0,top:0,height:"16%",pointerEvents:"none",...OT}}),v.jsxs("div",{style:{position:"absolute",inset:0,pointerEvents:"none"},children:[R.map(ee=>v.jsx("div",{ref:J=>{J?K.current.set(ee.id,J):K.current.delete(ee.id)},style:{position:"absolute",left:0,top:0,willChange:"transform",visibility:"hidden",fontFamily:Et,fontSize:ee.size,letterSpacing:"0.22em",color:ee.color,whiteSpace:"nowrap",textTransform:"uppercase"},children:ee.text},ee.id)),l&&v.jsx("div",{ref:G,style:{position:"absolute",left:0,top:0,willChange:"transform",visibility:"hidden",pointerEvents:"auto"},children:u})]}),m&&v.jsx("div",{style:{position:"absolute",inset:0,pointerEvents:"none"},children:m}),h&&v.jsx("div",{ref:I,style:{position:"absolute",inset:0,pointerEvents:"none"},children:h}),W==="failed"&&v.jsx("div",{style:{position:"absolute",inset:0,display:"grid",placeItems:"center",fontFamily:Et,fontSize:11,letterSpacing:"0.18em",color:at.failed,textAlign:"center",padding:40},children:v.jsxs("div",{children:[v.jsx("div",{children:"FIELD UNAVAILABLE — WEBGPU DID NOT START"}),v.jsx("div",{style:{marginTop:10,color:X.chrome,letterSpacing:"0.08em"},children:le})]})})]}),v.jsx(_T,{onSurface:yn,onZoom:fn,compact:b})]})}function _T({onSurface:n,onZoom:i,compact:s}){if(s)return v.jsx("div",{style:{position:"absolute",right:14,bottom:18},children:v.jsx("button",{onClick:n,style:{width:52,height:52,borderRadius:"50%",background:"rgba(7,8,11,0.9)",border:"1px solid rgba(230,227,219,0.5)",color:X.ink,fontFamily:Et,fontSize:8.5,letterSpacing:"0.1em",cursor:"pointer"},children:"SURF"})});const l={background:"transparent",border:`1px solid ${X.chromeDim}`,color:X.chromeStrong,fontFamily:Et,fontSize:10,letterSpacing:"0.14em",padding:"7px 12px",cursor:"pointer"};return v.jsxs("div",{style:{position:"absolute",right:16,bottom:16,display:"flex",gap:8},children:[v.jsx("button",{style:l,onClick:()=>i(1.35),"aria-label":"Zoom in",children:"+"}),v.jsx("button",{style:l,onClick:()=>i(1/1.35),"aria-label":"Zoom out",children:"−"}),v.jsx("button",{style:l,onClick:n,children:"SURFACE"})]})}const D0="(no model)";function rn({name:n,value:i,measure:s,accent:l,note:u}){const f=s?.basis==="inferred";return v.jsxs("div",{title:f?s?.assumption:void 0,style:{display:"flex",flexDirection:"column",gap:5,padding:"12px 0",borderTop:`1px solid ${X.hairline}`,cursor:f?"help":"default"},children:[v.jsxs("div",{style:{fontSize:9.5,letterSpacing:"0.22em",color:X.chrome,display:"flex",alignItems:"baseline",gap:6},children:[n,f&&v.jsx("span",{style:{color:X.chromeDim,letterSpacing:"0.1em"},children:"inferred"})]}),v.jsx("div",{style:{fontSize:21,letterSpacing:"0.02em",color:l??X.ink,fontVariantNumeric:"tabular-nums"},children:i}),u&&v.jsx("div",{style:{fontSize:9.5,color:X.chromeDim},children:u})]})}function ea({title:n,children:i}){return v.jsxs("div",{style:{marginTop:40},children:[v.jsx("div",{style:{fontSize:9.5,letterSpacing:"0.24em",color:X.chrome},children:n}),v.jsx("div",{style:{marginTop:12},children:i})]})}function Zy({fraction:n,color:i}){return v.jsx("div",{style:{height:3,background:"rgba(230,227,219,0.08)",width:"100%"},children:v.jsx("div",{style:{height:"100%",width:`${Math.max(.5,Math.min(1,n)*100)}%`,background:i}})})}function Vc({rows:n,max:i,label:s,color:l}){return v.jsx("div",{style:{display:"flex",flexDirection:"column",gap:10},children:n.map(u=>v.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:5},children:[v.jsxs("div",{style:{display:"flex",justifyContent:"space-between",gap:16,fontSize:11,fontVariantNumeric:"tabular-nums"},children:[v.jsx("span",{style:{color:X.body},children:s(u.key)}),v.jsxs("span",{style:{color:X.chromeMid},children:[u.runs," ",u.runs===1?"run":"runs",u.tokenRuns>0?` · ${pt(u.tokens)} tok`:""," · ",Ye(u.computeMs),u.failed>0&&v.jsxs("span",{style:{color:at.failed},children:[" · ",u.failed," failed"]})]})]}),v.jsx(Zy,{fraction:i>0?u.computeMs/i:0,color:l})]},u.key))})}function UT({world:n}){const i=Q.useMemo(()=>j0(n),[n]),s=Q.useMemo(()=>G0(n,i),[n,i]),l=Q.useMemo(()=>Bx(n),[n]),u=Q.useMemo(()=>Gx(n),[n]),f=Q.useMemo(()=>$x(n),[n]),d=Q.useMemo(()=>Vx(n),[n]),h=Q.useMemo(()=>Oc(n,(G,I)=>I?.context),[n]),m=Q.useMemo(()=>Oc(n,G=>G.model??D0),[n]),g=Q.useMemo(()=>Oc(n,G=>G.machineId),[n]),x=Q.useMemo(()=>[...n.executions.values()].filter(G=>G.status==="failed").sort((G,I)=>I.startedAt-G.startedAt),[n]),b=i.longestFocus.value,D=Q.useMemo(()=>[...n.executions.values()].filter(G=>qt(G.measures)===void 0).length,[n]),V=h[0]?.computeMs??0,k=m[0]?.computeMs??0,O=g[0]?.computeMs??0,L=d.reduce((G,I)=>I.computeMs>G.computeMs?I:G,d[0]),K=[...n.executions.values()].filter(G=>G.depth>0).length;return v.jsxs("div",{style:{flex:1,overflowY:"auto",padding:"28px 48px 80px",fontFamily:Et,color:X.ink},children:[v.jsxs("div",{style:{marginBottom:34,maxWidth:900},children:[v.jsx("div",{style:{fontSize:9.5,letterSpacing:"0.24em",color:X.chrome},children:"WORK SHAPE"}),v.jsx("div",{style:{fontSize:34,letterSpacing:"0.08em",marginTop:10,color:X.accentBright},children:s.headline}),v.jsx("div",{style:{marginTop:14,display:"flex",flexDirection:"column",gap:7},children:s.clauses.map(G=>v.jsx("div",{style:{fontSize:12,lineHeight:1.65,color:X.body,letterSpacing:"0.02em"},children:G},G))})]}),v.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(190px, 1fr))",gap:"0 40px"},children:[v.jsx(rn,{name:"REQUESTS",value:pt(i.requests.value),measure:i.requests}),v.jsx(rn,{name:"RUNS",value:String(i.executions.value),measure:i.executions,note:K>0?`${K} of them sub-agents`:void 0}),v.jsx(rn,{name:"SESSIONS",value:String(i.sessions.value),measure:i.sessions}),v.jsx(rn,{name:"TOKENS",value:pt(i.tokens.value),measure:i.tokens,note:`${Math.round(l.cacheRead/Math.max(1,l.total)*100)}% cache reads`+(D>0?` · ${D} ${D===1?"run reports":"runs report"} no accounting`:"")}),v.jsx(rn,{name:"TOOL CALLS",value:pt(f.toolCalls),measure:i.toolCalls,note:f.toolErrors>0?`${f.toolErrors} failed`:void 0}),v.jsx(rn,{name:"AUTONOMOUS COMPUTE",value:Ye(i.autonomousCompute.value),measure:i.autonomousCompute}),v.jsx(rn,{name:"HUMAN + AGENT OVERLAP",value:Ye(i.humanAgentOverlap.value),measure:i.humanAgentOverlap,note:`${Math.round(i.humanAgentOverlap.value/Math.max(1,i.autonomousCompute.value)*100)}% of compute`}),v.jsx(rn,{name:"PEAK CONCURRENCY",value:i.peakConcurrency.value>0?`${i.peakConcurrency.value} · ${Ja(i.peakConcurrencyAt.value)}`:"0",measure:i.peakConcurrency}),v.jsx(rn,{name:"CONTEXT SWITCHES",value:String(i.contextSwitches.value),measure:i.contextSwitches,note:`across ${h.length} ${h.length===1?"context":"contexts"}`}),v.jsx(rn,{name:"LONGEST FOCUS",value:b?Ye(b.end-b.start):"—",measure:i.longestFocus,note:b?`${ur(b.context)} · ${Ja(b.start)}–${Ja(b.end)}`:void 0}),v.jsx(rn,{name:"WAITING ON YOU",value:Ye(i.waitingOnYou.value),measure:i.waitingOnYou,accent:i.waitingOnYou.value>0?at.waiting:void 0,note:u.count>0?`${u.count} ${u.count===1?"block":"blocks"} · longest ${Ye(u.longestMs)}`:void 0}),v.jsx(rn,{name:"FAILED",value:String(f.failed),accent:f.failed>0?at.failed:void 0,note:f.interrupted>0||f.retries>0?`${f.interrupted} stopped · ${f.retries} retries`:void 0})]}),d.length>0&&v.jsxs(ea,{title:"HOUR BY HOUR",children:[v.jsx("div",{style:{display:"flex",alignItems:"flex-end",gap:3,height:84},children:d.map((G,I)=>{const H=G.computeMs/36e5;return v.jsx("div",{title:`${String(G.hour).padStart(2,"0")}:00 — ${Ye(G.computeMs)} of compute, ${G.runs} runs, peak ${G.peak}`,style:{flex:1,minWidth:4,height:"100%",display:"flex",flexDirection:"column",justifyContent:"flex-end"},children:v.jsx("div",{style:{height:`${Math.max(1,H*100)}%`,background:G.peak>1?"rgba(240,195,116,0.75)":"rgba(214,176,116,0.38)"}})},I)})}),v.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginTop:6,fontSize:9,letterSpacing:"0.16em",color:X.chromeDim},children:[v.jsxs("span",{children:[String(d[0].hour).padStart(2,"0"),":00"]}),v.jsxs("span",{children:["busiest ",String(L.hour).padStart(2,"0"),":00 · ",Ye(L.computeMs)," ","of that hour"]}),v.jsxs("span",{children:[String(d[d.length-1].hour).padStart(2,"0"),":00"]})]})]}),v.jsx(ea,{title:"WHERE THE TIME WENT",children:v.jsx(Vc,{rows:h,max:V,label:ur,color:"rgba(240,195,116,0.6)"})}),g.length>0&&v.jsx(ea,{title:"BY MACHINE",children:v.jsx(Vc,{rows:g,max:O,label:G=>n.machines.get(G)?.name??G,color:"rgba(168,186,150,0.6)"})}),m.length>0&&v.jsx(ea,{title:"BY MODEL",children:v.jsx(Vc,{rows:m,max:k,label:G=>G===D0?"model not observed":G,color:"rgba(150,175,196,0.6)"})}),v.jsxs(ea,{title:"TOKEN COMPOSITION",children:[v.jsx("div",{style:{display:"flex",flexDirection:"column",gap:10},children:[["CACHE READS",l.cacheRead,"rgba(150,175,196,0.6)"],["INPUT",l.input,"rgba(240,195,116,0.6)"],["OUTPUT",l.output,"rgba(180,210,175,0.7)"],["REASONING",l.reasoning,"rgba(214,176,116,0.5)"]].map(([G,I,H])=>v.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:5},children:[v.jsxs("div",{style:{display:"flex",justifyContent:"space-between",fontSize:11,fontVariantNumeric:"tabular-nums"},children:[v.jsx("span",{style:{color:X.body},children:G}),v.jsxs("span",{style:{color:X.chromeMid},children:[pt(I)," · ",Math.round(I/Math.max(1,l.total)*100),"%"]})]}),v.jsx(Zy,{fraction:I/Math.max(1,l.total),color:H})]},G))}),v.jsx("div",{style:{marginTop:12,fontSize:10,lineHeight:1.7,color:X.chromeDim},children:"Cache reads are context replayed into each request, not work generated. They dominate the total, which is why the headline token figure is much larger than it feels."})]}),x.length>0&&v.jsx(ea,{title:"FAILURES",children:v.jsx("div",{style:{display:"flex",flexDirection:"column",gap:9},children:x.slice(0,12).map(G=>v.jsxs("div",{style:{display:"flex",gap:16,fontSize:11,borderTop:`1px solid ${X.hairline}`,paddingTop:8},children:[v.jsx("span",{style:{color:X.chromeMid,minWidth:46},children:Ja(G.startedAt)}),v.jsx("span",{style:{color:X.body,minWidth:160},children:G.label}),v.jsxs("span",{style:{color:at.failed},children:[G.failure?.code,": ",G.failure?.message]})]},G.id))})}),v.jsx(NT,{})]})}function NT(){return v.jsx(ea,{title:"NOT AVAILABLE FROM THESE SOURCES",children:v.jsxs("div",{style:{maxWidth:760,fontSize:10.5,lineHeight:1.8,color:X.chromeDim},children:[v.jsx("div",{children:"COST — every source here reports tokens or CPU time; none reports money. Converting one to the other needs a price table 057 does not have, so no cost figure is shown anywhere."}),v.jsx("div",{style:{marginTop:8},children:"TOKENS, FROM SOME SOURCES — Cursor persists no usage and 0x2F records none; their runs read NOT OBSERVED rather than 0, and the token totals sum only the runs that report."}),v.jsx("div",{style:{marginTop:8},children:"MACHINE-TO-MACHINE TRANSFER — every observed source is single-host. Transfers are modelled and the field renders them, but no real adapter emits one; only the synthetic source does."}),v.jsx("div",{style:{marginTop:8},children:"PROCESS EXITS — the OS collector samples; an exit is inferred from disappearance between samples, never witnessed."}),v.jsx("div",{style:{marginTop:8},children:"OUTCOME QUALITY — the log records that a run completed, not whether the work was any good."})]})})}const Ic=100,R0="58px minmax(180px,1.4fr) 104px 132px 84px 68px 62px 70px 56px";function LT(n){return n.outcome==="interrupted"?"STOPPED":n.status}function kT(n){return n.outcome==="interrupted"?X.chromeMid:at[n.status]}function Mi({children:n,align:i="left",color:s}){return v.jsx("div",{style:{textAlign:i,color:s??X.chromeMid,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:n})}function jT({p:n,session:i,onShowInField:s}){const l=qt(n.measures),u=n.startBasis==="inferred"||n.endBasis==="inferred",f=[["CONTEXT",i?i.context:"—"],["PROVIDER",n.executor],["MODEL",n.model??"not observed"],["STARTED",`${n.startBasis==="inferred"?"~":""}${new Date(n.startedAt).toLocaleTimeString()}`],["ENDED",n.endedAt?`${n.endBasis==="inferred"?"~":""}${new Date(n.endedAt).toLocaleTimeString()}`:"still open"],...l===void 0?[["TOKENS","not observed"]]:[["INPUT",pt(Wa(n.measures).input)],["OUTPUT",pt(Wa(n.measures).output)],["CACHE READ",pt(Wa(n.measures).cacheRead)],["REASONING",pt(Wa(n.measures).reasoning)]],["REQUESTS",String(ff(n))],["TOOL CALLS",es(un(n),"not observed")]];return ia(n)>0&&f.push(["TOOL ERRORS",String(ia(n)),at.failed]),Yc(n)>0&&f.push(["PROVIDER RETRIES",String(Yc(n)),at.waiting]),(n.waits.length>0||n.waitingMs>0)&&f.push(["BLOCKED ON YOU",`${Ye(n.waitingMs)} across ${n.waits.length||1}`,at.waiting]),n.depth>0&&f.push(["SUB-AGENT",`depth ${n.depth}`]),v.jsxs("div",{style:{gridColumn:"1 / -1",display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(180px, 1fr))",gap:"6px 28px",padding:"12px 0 14px 16px",borderLeft:`1px solid ${X.panelBorder}`,margin:"2px 0 6px",background:"rgba(230,227,219,0.02)"},children:[f.map(([d,h,m])=>v.jsxs("div",{style:{display:"flex",justifyContent:"space-between",gap:12},children:[v.jsx("span",{style:{fontSize:9.5,letterSpacing:"0.16em",color:X.chrome},children:d}),v.jsx("span",{style:{fontSize:10.5,color:m??X.body,fontVariantNumeric:"tabular-nums",overflow:"hidden",textOverflow:"ellipsis"},children:h})]},d)),n.failure&&v.jsxs("div",{style:{gridColumn:"1 / -1",fontSize:10.5,color:at.failed},children:[n.failure.code,": ",n.failure.message]}),u&&n.boundsAssumption&&v.jsxs("div",{style:{gridColumn:"1 / -1",fontSize:9.5,color:X.chromeMid},children:["timing inferred — ",n.boundsAssumption]}),v.jsx("div",{style:{gridColumn:"1 / -1",marginTop:4},children:v.jsx("button",{onClick:d=>{d.stopPropagation(),s()},style:{background:"transparent",border:`1px solid ${X.hairline}`,color:X.chromeMid,fontFamily:Et,fontSize:9,letterSpacing:"0.16em",padding:"5px 10px",cursor:"pointer"},children:"SHOW IN FIELD →"})})]})}function BT({world:n,selectedId:i,onSelect:s}){const[l,u]=Q.useState("all"),[f,d]=Q.useState("time"),[h,m]=Q.useState(Ic),[g,x]=Q.useState(null),b=Q.useMemo(()=>{let L=[...n.executions.values()];l==="stopped"?L=L.filter(I=>I.outcome==="interrupted"):l!=="all"&&(L=L.filter(I=>I.status===l&&I.outcome!=="interrupted"));const K=I=>(I.endedAt??n.now)-I.startedAt,G={time:(I,H)=>H.startedAt-I.startedAt,duration:(I,H)=>K(H)-K(I),tokens:(I,H)=>(qt(H.measures)??0)-(qt(I.measures)??0),tools:(I,H)=>(un(H)??0)-(un(I)??0),waited:(I,H)=>H.waitingMs-I.waitingMs};return L.sort(G[f])},[n,l,f]),D=Q.useMemo(()=>{const L={all:n.executions.size,stopped:0};for(const K of n.executions.values())K.outcome==="interrupted"?L.stopped++:L[K.status]=(L[K.status]??0)+1;return L},[n]),V=Q.useMemo(()=>{let L=0,K=0,G=0,I=0;for(const H of b)L+=qt(H.measures)??0,K+=(H.endedAt??n.now)-H.startedAt,G+=un(H)??0,I+=H.waitingMs;return{tokens:L,compute:K,tools:G,waited:I}},[b,n]),k=b.slice(0,h),O=(L,K,G="left")=>v.jsxs("div",{onClick:()=>d(L),style:{textAlign:G,cursor:"pointer",color:f===L?X.ink:X.chrome},children:[K,f===L?" ↓":""]});return v.jsxs("div",{style:{flex:1,overflowY:"auto",padding:"24px 48px 80px",fontFamily:Et,color:X.ink},children:[v.jsx("div",{style:{display:"flex",gap:10,flexWrap:"wrap",marginBottom:14},children:["all","running","waiting","idle","completed","failed","stopped"].map(L=>{const K=l===L,G=D[L]??0;return v.jsxs("button",{onClick:()=>{u(L),m(Ic)},style:{background:"transparent",border:`1px solid ${K?"rgba(230,227,219,0.6)":X.hairline}`,color:K?X.ink:X.chromeMid,fontFamily:Et,fontSize:9.5,letterSpacing:"0.16em",padding:"6px 11px",cursor:"pointer",textTransform:"uppercase"},children:[L," ",G>0&&v.jsx("span",{style:{color:X.chromeDim},children:G})]},L)})}),v.jsxs("div",{style:{fontSize:10,letterSpacing:"0.12em",color:X.chromeDim,marginBottom:14,fontVariantNumeric:"tabular-nums"},children:[b.length," ",b.length===1?"run":"runs"," shown · ",pt(V.tokens)," tok ·"," ",Ye(V.compute)," of run time · ",pt(V.tools)," tool calls",V.waited>0&&` · ${Ye(V.waited)} blocked on you`]}),v.jsxs("div",{style:{display:"grid",gridTemplateColumns:R0,gap:"0 14px",fontSize:9,letterSpacing:"0.18em",color:X.chrome,paddingBottom:8,borderBottom:`1px solid ${X.hairline}`},children:[O("time","START"),v.jsx("div",{children:"RUN"}),v.jsx("div",{children:"CONTEXT"}),v.jsx("div",{children:"MODEL"}),v.jsx("div",{children:"STATUS"}),O("duration","DUR","right"),O("tokens","TOKENS","right"),O("waited","WAITED","right"),O("tools","TOOLS","right")]}),k.map(L=>{const K=n.sessions.get(L.sessionId),G=L.id===i,I=g===L.id;return v.jsxs("div",{children:[v.jsxs("div",{onClick:()=>x(I?null:L.id),style:{display:"grid",gridTemplateColumns:R0,gap:"0 14px",fontSize:11,padding:"9px 0",borderBottom:"1px solid rgba(230,227,219,0.05)",cursor:"pointer",background:G||I?"rgba(240,195,116,0.07)":"transparent",fontVariantNumeric:"tabular-nums"},children:[v.jsx(Mi,{children:Ja(L.startedAt)}),v.jsxs(Mi,{color:G||I?X.accentBright:X.body,children:[L.depth>0&&v.jsx("span",{style:{color:X.chromeDim},children:"└ "}),L.label]}),v.jsx(Mi,{children:K?ur(K.context):"—"}),v.jsx(Mi,{color:L.model?void 0:X.chromeDim,children:L.model??"—"}),v.jsx("div",{style:{fontSize:9,letterSpacing:"0.14em",color:kT(L),textTransform:"uppercase"},children:LT(L)}),v.jsxs(Mi,{align:"right",children:[L.startBasis==="inferred"||L.endBasis==="inferred"?"~":"",Ye((L.endedAt??n.now)-L.startedAt)]}),v.jsx(Mi,{align:"right",color:qt(L.measures)===void 0?X.chromeDim:void 0,children:es(qt(L.measures),"—")}),v.jsx(Mi,{align:"right",color:L.waitingMs>0?at.waiting:X.chromeDim,children:L.waitingMs>0?Ye(L.waitingMs):"—"}),v.jsxs(Mi,{align:"right",color:un(L)===void 0?X.chromeDim:void 0,children:[es(un(L),"—"),ia(L)>0&&v.jsxs("span",{style:{color:at.failed},children:[" /",ia(L)]})]})]}),I&&v.jsx(jT,{p:L,session:K,onShowInField:()=>s(L.id)})]},L.id)}),b.length===0&&v.jsx("div",{style:{padding:"28px 0",fontSize:11,color:X.chromeMid},children:"Nothing matching in this window."}),b.length>h&&v.jsxs("button",{onClick:()=>m(L=>L+Ic),style:{marginTop:18,background:"transparent",border:`1px solid ${X.hairline}`,color:X.chromeMid,fontFamily:Et,fontSize:9.5,letterSpacing:"0.16em",padding:"8px 14px",cursor:"pointer"},children:["SHOW MORE — ",b.length-h," REMAINING"]})]})}const Fc={display:"flex",flexDirection:"column",gap:5,background:X.panel,borderLeft:`1px solid ${X.panelBorder}`,padding:"9px 13px",minWidth:170,maxWidth:320,fontFamily:Et,backdropFilter:"blur(2px)"};function Ue({name:n,detail:i,color:s,title:l,tag:u}){return v.jsxs("div",{title:l,style:{display:"flex",alignItems:"baseline",justifyContent:"space-between",gap:16,fontSize:10.5,cursor:l?"help":void 0},children:[v.jsxs("span",{style:{color:X.chromeMid,letterSpacing:"0.1em",whiteSpace:"nowrap"},children:[n,u&&v.jsxs("span",{style:{color:X.chromeDim,letterSpacing:"0.06em"},children:[" ",u]})]}),v.jsx("span",{style:{fontSize:10,fontWeight:500,letterSpacing:"0.14em",color:s??X.chromeStrong,whiteSpace:"nowrap",textAlign:"right",overflow:"hidden",textOverflow:"ellipsis",maxWidth:190},children:i})]})}function Hc({text:n,onClose:i}){return v.jsxs("div",{style:{display:"flex",alignItems:"baseline",justifyContent:"space-between",gap:14},children:[v.jsx("div",{style:{fontSize:10,letterSpacing:"0.18em",color:X.ink,textTransform:"uppercase"},children:n}),v.jsx("div",{onClick:i,role:"button",style:{fontSize:11,color:X.chromeMid,cursor:"pointer"},children:"×"})]})}function _f({label:n}){return v.jsx("div",{style:{marginTop:5,paddingTop:5,borderTop:"1px solid rgba(230,227,219,0.08)",fontSize:8.5,letterSpacing:"0.2em",color:X.chromeDim},children:n})}function GT(n){if(n.basis==="measured")return{label:"recorded",grade:"recorded"};const i=n.via?.split("|")[0];return i==="agent.session"?{label:"session identity",grade:"identity"}:i==="os.process"?{label:"process identity",grade:"identity"}:i==="fs.cwd"?{label:"directory overlap",grade:"contextual"}:{label:"inferred",grade:"contextual"}}function $T(n,i){switch(i.type){case"process":{const s=n.processes.get(i.id);return s?`PID ${s.pid} · ${s.command}`:i.id}case"session":return n.sessions.get(i.id)?.label??i.id;case"execution":return n.executions.get(i.id)?.label??i.id;case"machine":return n.machines.get(i.id)?.name??i.id;default:return i.id}}const C0={"ran-as":"RAN AS","same-as":"SAME AS",spawned:"SPAWNED",contains:"CONTAINS",produced:"PRODUCED"};function O0({world:n,subject:i}){const s=n.relationships.filter(l=>l.from.type===i.type&&l.from.id===i.id||l.to.type===i.type&&l.to.id===i.id);return s.length===0?null:v.jsxs(v.Fragment,{children:[v.jsx(_f,{label:"RELATED"}),s.slice(0,6).map((l,u)=>{const f=l.from.type===i.type&&l.from.id===i.id,d=f?l.to:l.from,h=f?C0[l.kind]:l.kind==="spawned"?"SPAWNED BY":C0[l.kind],m=GT(l);return v.jsx(Ue,{name:h,tag:m.grade==="contextual"?`${m.label} · inferred`:m.label,detail:$T(n,d),color:m.grade==="contextual"?X.chromeMid:void 0,title:l.assumption??(l.via?`via ${l.via}`:void 0)},`${l.kind}:${d.type}:${d.id}:${u}`)})]})}function VT({type:n,id:i}){const[s,l]=Q.useState(null);return Q.useEffect(()=>{let u=!1;l(null);const f=setTimeout(()=>{o1(n,i).then(({events:d})=>{u||l(IT(d))}).catch(()=>{u||l(null)})},180);return()=>{u=!0,clearTimeout(f)}},[n,i]),!s||s.facts.length===0&&!s.provenance?null:v.jsxs(v.Fragment,{children:[v.jsx(_f,{label:"NATIVE RECORD"}),s.facts.map(([u,f])=>v.jsx(Ue,{name:u,detail:f,color:X.chromeMid},u)),s.provenance&&v.jsxs("div",{title:s.provenance,style:{fontSize:8.5,letterSpacing:"0.04em",color:X.chromeDim,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",cursor:"help"},children:["read from ",s.provenance]})]})}function IT(n){const i=new Map;let s;for(const u of n){for(const[f,d]of Object.entries(u.attrs??{}))!f.includes(".")||d===void 0||d===null||d===""||i.set(f,d);!s&&u.provenance?.path&&(s=u.provenance.path)}return{facts:[...i.entries()].slice(0,10).map(([u,f])=>[u,typeof f=="object"?JSON.stringify(f):String(f)]),provenance:s}}function FT({p:n,now:i}){const s=(n.endedAt??i)-n.startedAt,l=n.startBasis==="inferred",u=n.endBasis==="inferred",f=l||u;return v.jsxs(v.Fragment,{children:[v.jsx(Ue,{name:"STARTED",tag:l?"inferred":void 0,detail:Ja(n.startedAt),title:l?n.boundsAssumption:void 0}),v.jsx(Ue,{name:"ELAPSED",tag:f?"inferred":void 0,detail:Ye(s),title:f?n.boundsAssumption:void 0})]})}function Uf({hit:n,world:i,landscape:s,band:l,density:u,onClose:f}){if(n.kind==="mass"){const k=i.machines.get(n.id);if(!k)return null;const O=[];let L=0,K;for(const H of i.executions.values()){if(H.machineId!==k.id)continue;const Z=qt(H.measures);Z!==void 0&&(K=(K??0)+Z),H.status==="running"||H.status==="waiting"?O.push({id:H.id,label:H.label,status:H.status}):L++}const G=i.processTotals,I=new Set;for(const H of i.relationships)H.kind==="ran-as"&&(H.from.type==="process"&&I.add(H.from.id),H.to.type==="process"&&I.add(H.to.id));return v.jsxs("div",{style:Fc,children:[v.jsx(Hc,{text:k.name,onClose:f}),O.length===0?v.jsx("div",{style:{fontSize:10,color:X.chrome},children:"idle — nothing active"}):O.slice(0,8).map(H=>v.jsx(Ue,{name:H.label,detail:H.status.toUpperCase(),color:at[H.status]},H.id)),v.jsx("div",{style:{height:4}}),v.jsx(Ue,{name:"RAN TODAY",detail:String(L)}),v.jsx(Ue,{name:"TOKENS",detail:es(K),title:K===void 0?"No execution in this window reported token accounting.":void 0}),G&&v.jsxs(v.Fragment,{children:[v.jsx(_f,{label:"MACHINE STRATUM"}),v.jsx(Ue,{name:"PROCESSES OBSERVED",detail:String(G.observed)}),v.jsx(Ue,{name:"SEEN IN LAST 5 MIN",detail:String(G.recentlySeen),title:"Processes with a liveness observation in the last five minutes. The sampler only records a process when it is doing something, and never witnesses an exit — so recency is the honest liveness signal, not an unexpired status."}),v.jsx(Ue,{name:"ATTRIBUTED",detail:`${I.size} of ${G.observed}`,title:"Processes tied to a session or execution by resolved identity. The rest are machine activity with no known semantic identity — observed, not explained."}),G.exitsInferred>0&&v.jsx(Ue,{name:"EXITS",tag:"inferred",detail:String(G.exitsInferred),title:"An exit is never witnessed by the sampler; it is inferred from disappearance between samples."})]})]})}if(n.kind==="coupling"){const k=i.transfers.get(n.id);if(!k)return null;const O=i.machines.get(k.fromMachineId)?.name??k.fromMachineId,L=i.machines.get(k.toMachineId)?.name??k.toMachineId;return v.jsxs("div",{style:Fc,children:[v.jsx(Hc,{text:`${O} → ${L}`,onClose:f}),v.jsx(Ue,{name:"STATUS",detail:"TRANSFERRING",color:at.running}),v.jsx(Ue,{name:"WHAT",detail:k.label}),v.jsx(Ue,{name:"SIZE",detail:Ix(k.bytes)}),v.jsx(Ue,{name:"ELAPSED",detail:Ye(i.now-k.startedAt)})]})}const d=i.executions.get(n.id);if(!d)return null;const h=i.sessions.get(d.sessionId),m=i.machines.get(d.machineId),g=s.disturbances.find(k=>k.id===n.id),x=u==="full"||u!=="compact"&&(l==="proximity"||n.kind==="stratum"),b=x,D=qt(d.measures),V=Wa(d.measures);return v.jsxs("div",{style:Fc,children:[v.jsx(Hc,{text:d.label,onClose:f}),v.jsx(Ue,{name:"STATUS",detail:d.status.toUpperCase(),color:at[d.status]}),v.jsx(Ue,{name:"MACHINE",detail:m?.name??d.machineId}),v.jsx(FT,{p:d,now:i.now}),b&&v.jsxs(v.Fragment,{children:[v.jsx(Ue,{name:"TOKENS",detail:es(D),title:D===void 0?"This source does not persist token accounting.":void 0}),v.jsx(Ue,{name:"REQUESTS",detail:String(ff(d))}),v.jsx(Ue,{name:"TOOL CALLS",detail:es(un(d)),title:un(d)===void 0?"This source does not count discrete operations.":void 0})]}),x&&v.jsxs(v.Fragment,{children:[v.jsx("div",{style:{height:4}}),h&&v.jsx(Ue,{name:"CONTEXT",detail:ur(h.context)}),v.jsx(Ue,{name:"PROVIDER",detail:d.executor}),v.jsx(Ue,{name:"MODEL",detail:d.model??"NOT OBSERVED",color:d.model?void 0:X.chromeMid,title:d.model?void 0:"This source does not record the model."}),D!==void 0&&v.jsxs(v.Fragment,{children:[v.jsx(Ue,{name:"CACHE READ",detail:pt(V.cacheRead)}),v.jsx(Ue,{name:"REASONING",detail:pt(V.reasoning)})]}),ia(d)>0&&v.jsx(Ue,{name:"TOOL ERRORS",detail:String(ia(d)),color:at.failed}),d.waitingMs>0&&v.jsx(Ue,{name:"WAITED ON YOU",detail:Ye(d.waitingMs),color:at.waiting}),d.depth>0&&v.jsx(Ue,{name:"SUB-AGENT",detail:`depth ${d.depth}`}),h?.parentId&&v.jsx(Ue,{name:"SESSION SPAWNED BY",tag:"recorded",detail:i.sessions.get(h.parentId)?.label??h.parentId,title:"The session's own runtime recorded which session started it."}),g&&v.jsx(Ue,{name:"FIELD ENERGY",detail:g.energy.toFixed(2)}),v.jsx(O0,{world:i,subject:{type:"execution",id:d.id}}),h&&v.jsx(O0,{world:i,subject:{type:"session",id:h.id}}),v.jsx(VT,{type:"execution",id:d.id})]}),d.failure&&v.jsxs("div",{style:{marginTop:4,fontSize:9.5,letterSpacing:"0.06em",color:at.failed,maxWidth:280},children:[d.failure.code,": ",d.failure.message]}),d.outcome==="interrupted"&&!d.failure&&v.jsx("div",{style:{marginTop:4,fontSize:9.5,color:X.chromeMid},children:"stopped before finishing"})]})}function HT({hit:n,world:i}){let s="",l="",u=X.chromeMid;if(n.kind==="mass")s=i.machines.get(n.id)?.name??n.id;else if(n.kind==="coupling"){const f=i.transfers.get(n.id),d=f?i.machines.get(f.fromMachineId)?.name??"":"",h=f?i.machines.get(f.toMachineId)?.name??"":"";s=`${d} → ${h}`,l="TRANSFERRING",u=at.running}else{const f=i.executions.get(n.id);if(!f)return null;s=f.label,l=f.status.toUpperCase(),u=at[f.status]}return v.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:2,pointerEvents:"none",whiteSpace:"nowrap",fontFamily:Et},children:[v.jsx("div",{style:{fontSize:10.5,fontWeight:500,letterSpacing:"0.18em",color:X.hoverInk,background:"rgba(5,6,8,0.88)",padding:"4px 9px"},children:s}),l&&v.jsx("div",{style:{fontSize:9.5,letterSpacing:"0.22em",color:u,textShadow:Za},children:l})]})}function qT(n){return[`${pt(n.requests.value)} REQ`,`${n.sessions.value} SESS`,`${Ye(n.autonomousCompute.value)}`,`${pt(n.tokens.value)} TOK`].join(" · ")}function YT(n){return[`${pt(n.requests.value)} REQUESTS`,`${n.sessions.value} SESSIONS`,`${Ye(n.autonomousCompute.value)} AUTONOMOUS`,`${Ye(n.humanAgentOverlap.value)} OVERLAP`,`PEAK ${n.peakConcurrency.value}`,`${n.contextSwitches.value} SWITCHES`,`${pt(n.tokens.value)} TOK`].join(" · ")}function XT({metrics:n,shape:i,compact:s=!1}){return v.jsxs("div",{style:{position:"absolute",left:20,bottom:16,right:s?82:236,display:"flex",flexDirection:"column",gap:8,pointerEvents:"none",fontFamily:Et},children:[v.jsxs("div",{"data-depth-deep":!0,"data-depth-suppressed":s?"true":void 0,style:{display:"none",maxWidth:720,background:"linear-gradient(to right, rgba(5,6,8,0.92) 0%, rgba(5,6,8,0.86) 70%, rgba(5,6,8,0) 100%)",padding:"10px 42px 10px 0",margin:"0 0 -2px -6px",paddingLeft:6},children:[v.jsxs("div",{style:{fontSize:9.5,letterSpacing:"0.24em",color:X.chrome,textShadow:Za},children:["WORK SHAPE — ",i.headline]}),v.jsx("div",{style:{marginTop:6,display:"flex",flexDirection:"column",gap:3},children:i.clauses.slice(0,3).map(l=>v.jsx("div",{style:{fontSize:10.5,lineHeight:1.6,color:X.chromeMid,textShadow:Za},children:l},l))}),v.jsx("div",{style:{marginTop:7,fontSize:9.5,lineHeight:1.6,color:X.chromeDim,textShadow:Za,maxWidth:620},children:"NOT AVAILABLE FROM THESE SOURCES — cost (every source reports tokens or CPU time, none reports money) and machine-to-machine transfer (every observed source is single-host)."})]}),v.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:10,flexWrap:"wrap",background:"linear-gradient(to right, rgba(5,6,8,0.92) 0%, rgba(5,6,8,0.86) 80%, rgba(5,6,8,0) 100%)",padding:"4px 42px 4px 6px",margin:"0 0 0 -6px"},children:[v.jsx("span",{"data-depth-label":!0,style:{fontSize:10.5,letterSpacing:"0.18em",color:"rgba(230,227,219,0.74)",textShadow:Za},children:"FIELD — LIVE"}),v.jsxs("span",{"data-depth-summary":!0,style:{display:"none",alignItems:"baseline",gap:10},children:[v.jsx("span",{style:{color:X.chromeDim},children:"·"}),v.jsx("span",{style:{fontSize:10.5,letterSpacing:"0.18em",color:"rgba(230,227,219,0.6)",textShadow:Za},children:s?qT(n):YT(n)})]})]})]})}const KT=560;function z0(n,i,s){return Math.min(n,i)<KT||s?i>=n?"portrait":"landscape":"desktop"}function QT(){const[n,i]=Q.useState(()=>typeof window>"u"?"desktop":z0(window.innerWidth,window.innerHeight,window.matchMedia("(pointer: coarse)").matches));return Q.useEffect(()=>{const s=window.matchMedia("(pointer: coarse)"),l=()=>i(z0(window.innerWidth,window.innerHeight,s.matches));return l(),window.addEventListener("resize",l),window.addEventListener("orientationchange",l),s.addEventListener("change",l),()=>{window.removeEventListener("resize",l),window.removeEventListener("orientationchange",l),s.removeEventListener("change",l)}},[]),n}const Wy=250,Jy=150;function PT(n,i,s,l){return i?n==="landscape"?{right:Wy,bottom:0}:n==="portrait"?{right:0,bottom:s?Math.round(l*.6):Jy}:{right:0,bottom:0}:{right:0,bottom:0}}const ev={fontSize:9,letterSpacing:"0.16em",color:X.chromeMid};function ZT(n){return v.jsxs("div",{style:{position:"absolute",right:0,top:0,bottom:0,width:Wy,boxSizing:"border-box",background:X.panel,borderLeft:`1px solid ${X.panelBorder}`,padding:"16px 16px 14px",display:"flex",flexDirection:"column",gap:10,fontFamily:Et,pointerEvents:"auto"},children:[v.jsx(Uf,{...n,density:"full"}),v.jsx("div",{style:{marginTop:"auto",...ev},children:"TAP FIELD TO DISMISS"})]})}function WT({detent:n,onToggleDetent:i,viewportHeight:s,...l}){const u=n==="expanded",f=u?Math.round(s*.6):Jy;return v.jsxs("div",{style:{position:"absolute",left:0,right:0,bottom:0,height:f,boxSizing:"border-box",background:"rgba(7,8,11,0.96)",borderTop:`1px solid ${X.panelBorder}`,padding:"10px 18px 18px",display:"flex",flexDirection:"column",gap:10,fontFamily:Et,pointerEvents:"auto",transition:"height 180ms ease-out"},children:[v.jsx("button",{onClick:i,"aria-label":u?"Collapse":"Expand",style:{alignSelf:"center",width:44,height:4,borderRadius:2,border:"none",padding:0,background:"rgba(230,227,219,0.42)",cursor:"pointer",marginBottom:2,flexShrink:0}}),v.jsx("div",{style:{overflow:"hidden",flex:1,minHeight:0},children:v.jsx(Uf,{...l,density:u?"full":"compact"})}),v.jsx("div",{style:{marginTop:"auto",...ev},children:u?"TAP HANDLE TO COLLAPSE":"TAP HANDLE FOR FULL TELEMETRY"})]})}function JT(){return"capture"}function eM(n){return`${n.message}. ${n.remedy} Nothing observed since this appeared has been saved.`}const qc={label:"TODAY",tone:"normal",detail:"Midnight to now."},tM={normal:X.chromeMid,warn:"rgba(240,195,116,0.9)",error:"rgba(206,104,90,0.9)"};function nM(){const n=Date.now(),i=new Date(n);return i.setHours(0,0,0,0),{start:i.getTime(),now:n}}const iM=250,aM={time:0,masses:[],disturbances:[],plinths:[],couplings:[],strata:[]};function sM(){const[n,i]=Q.useState(JT),[s,l]=Q.useState("field"),[u,f]=Q.useState(null),[d,h]=Q.useState(qc),[m,g]=Q.useState(aM),[x,b]=Q.useState(0),[D,V]=Q.useState(null),[k,O]=Q.useState(null),[L,K]=Q.useState("environment"),[G,I]=Q.useState(null),[H,Z]=Q.useState("peek"),de=QT(),M=Q.useRef(Vl(Date.now(),Date.now())),E=Q.useRef(null),B=Q.useRef(null),W=Q.useRef(!1);Q.useEffect(()=>{let w=!1,N=null;h(qc);async function Y(){if(n==="synthetic"||n==="fixture"){let be;if(be=new l1({seed:57}),h({label:"REPLAY",tone:"normal",detail:"A deterministic synthetic day, replayed at speed. Not your telemetry."}),w)return;const yn=be.bounds();M.current=Vl(yn.dayStart,yn.dayEnd),E.current=be,f(be.info()),O(null),V(null),N=be.subscribe(fn=>{Ox(M.current,fn),W.current=!0}),W.current=!0;return}const{start:P,now:ue}=nM();await Xc(P,ue);const fe=await u1();let me=await Kc(P,ue);if(me.world.executions.length===0&&me.world.sessions.length===0){const be=ue-2592e5;await Xc(be,ue),me=await Kc(be,ue),(me.world.executions.length>0||me.world.sessions.length>0)&&h({label:"LAST 72H",tone:"warn",detail:"Nothing ran today, so the window was widened to the last 72 hours."})}const Ze=Object.entries(fe.observation??{}).flatMap(([be,yn])=>Object.entries(yn.strata).filter(([fn,ee])=>ee==="partial"||ee==="failed"&&fn!=="live-semantics").map(([fn,ee])=>`${be} ${fn} ${ee}`)),De=Object.entries(fe.sources).filter(([,be])=>(be.presence??(be.available?"observing":"not-installed"))==="failed").map(([be])=>be),gn=Object.entries(fe.sources).filter(([,be])=>be.presence==="not-installed").map(([be])=>be),Jn=fe.store.bySource.filter(be=>be.source!=="host"),Mt=fe.health;fe.fault?h({label:"STORE LOST",tone:"error",detail:eM(fe.fault)}):Mt&&!Mt.store.ok?h({label:"STORE DEGRADED",tone:"error",detail:Mt.store.remedy??"Some stored rows could not be read."}):Mt&&Mt.failingSources.length>0?h({label:"SOURCE FAILING",tone:"error",detail:`Installed and failing every collection round: ${Mt.failingSources.join(", ")}. `+(Mt.collection[Mt.failingSources[0]]?.lastError??"")+" Other sources and captured history are unaffected."}):fe.mode==="os-only"?h({label:"OS ONLY",tone:"normal",detail:"Observing this machine’s processes. No AI runtime state was found here"+(gn.length?` (looked for ${gn.join(", ")})`:"")+" — that is a valid mode, not a fault. Install or use one and its sessions appear here."}):Jn.length===0?h({label:"NOTHING YET",tone:"warn",detail:"Nothing has been captured yet. OS processes are sampled locally every few seconds; AI runtime state is read from each runtime’s own files when it exists."}):(De.length||Ze.length)&&h({label:"PARTIAL",tone:"warn",detail:[De.length?`Installed but unreadable: ${De.join(", ")}.`:"",Ze.length?`Reduced observation depth: ${Ze.join("; ")}. The computation is still observed; some semantics are not.`:"","Captured history is intact."].filter(Boolean).join(" ")});const Mn=new d1(me,fe,{onTrouble:be=>{if(!w){if(!be)return h(qc);h(be.kind==="store-fault"?{label:"STORE LOST",tone:"error",detail:`${be.message} ${be.detail}`}:{label:"CAPTURE FAILING",tone:"error",detail:`${be.message}. ${be.detail}. The field is showing the last world it received.`})}}});w||(M.current=Vl(me.from,me.to),E.current=Mn,f(Mn.info()),O(null),V(null),N=Mn.subscribe(be=>{M.current=be,W.current=!0}),W.current=!0)}return Y().catch(P=>{w||h({label:"SOURCE FAILED",tone:"error",detail:P instanceof Error?P.message:String(P)})}),()=>{w=!0,E.current=null,N?.()}},[n]),Q.useEffect(()=>{const w=setInterval(()=>{const N=M.current,Y=E.current?.now()??Date.now();if(zx(N,Math.max(N.now,Y)),!W.current)return;W.current=!1;const P=n1(N);g(P),b(ue=>ue+1)},iM);return()=>clearInterval(w)},[]),Q.useEffect(()=>{const w=setInterval(()=>{const N=B.current?.perf.snapshot();N&&I({fps:N.fps,gpuMs:N.gpuMs,scale:N.scale})},1e3);return()=>clearInterval(w)},[]);const te=M.current,le=Q.useMemo(()=>j0(te),[x]),$e=Q.useMemo(()=>G0(te,le),[le]),he=Q.useCallback(w=>V(w),[]),re=Q.useCallback(w=>{const N=m.disturbances.find(P=>P.id===w),Y=m.strata.find(P=>P.id===w);!N&&!Y||(O({kind:N?"disturbance":"stratum",id:w,x:N?.x??0,y:N?.y??0}),l("field"))},[m]),R=k??D,q=de!=="desktop",ae=typeof window>"u"?800:window.innerHeight,Te=Q.useMemo(()=>PT(de,!!k,H==="expanded",ae),[de,k,H,ae]),Re=R&&(!k&&R.kind==="disturbance"?v.jsx("div",{"data-anchor-placement":"label",children:v.jsx(HT,{hit:R,world:te})}):v.jsx("div",{"data-anchor-placement":"panel",children:v.jsx(Uf,{hit:R,world:te,landscape:m,band:L,onClose:()=>O(null)})}));return v.jsxs("div",{style:{position:"fixed",inset:0,display:"flex",flexDirection:"column",background:X.bg,color:X.ink,fontFamily:Et},children:[v.jsx(rM,{view:s,setView:l,feed:n,setFeed:i,sourceInfo:u,window:d}),s==="today"&&v.jsx(UT,{world:te}),s==="log"&&v.jsx(BT,{world:te,selectedId:k?.id??null,onSelect:re}),v.jsx("div",{style:{display:s==="field"?"contents":"none"},children:v.jsx(zT,{landscape:m,onHover:he,onSelect:O,anchor:q?null:R,onBand:K,compact:q,inset:Te,keepVisible:k,overlay:q&&k?de==="landscape"?v.jsx(ZT,{hit:k,world:te,landscape:m,band:L,onClose:()=>O(null)}):v.jsx(WT,{hit:k,world:te,landscape:m,band:L,detent:H,onToggleDetent:()=>Z(w=>w==="peek"?"expanded":"peek"),viewportHeight:ae,onClose:()=>O(null)}):null,onReady:w=>{B.current=w},depth:v.jsx(XT,{metrics:le,shape:$e,compact:q}),children:Re})}),v.jsx(lM,{view:s,perf:G,touch:q})]})}function rM({view:n,setView:i,feed:s,setFeed:l,sourceInfo:u,window:f}){const d=(g,x)=>{const b=n===g;return v.jsx("button",{onClick:()=>i(g),style:{background:"transparent",border:"none",padding:0,cursor:"pointer",fontFamily:Et,letterSpacing:"0.22em",fontSize:b?12.5:9.5,color:b?X.ink:X.chromeDim},children:x},g)},h=s==="synthetic",m=[f.detail,u?.detail].filter(Boolean).join(" ");return v.jsxs("div",{style:{display:"flex",alignItems:"center",gap:14,padding:"16px 24px 15px",borderBottom:`1px solid ${X.hairline}`,flexWrap:"nowrap",overflow:"hidden"},children:[v.jsx("div",{style:{fontSize:11,letterSpacing:"0.3em",color:"rgba(230,227,219,0.5)",flexShrink:0},children:"057"}),v.jsx("div",{className:"hdr-tagline",style:{fontSize:8.5,letterSpacing:"0.24em",color:X.chromeDim,flexShrink:0,whiteSpace:"nowrap"},children:"PERSONAL COMPUTATIONAL TELEMETRY"}),v.jsx("div",{className:"hdr-tagline",style:{width:1,height:12,background:"rgba(230,227,219,0.12)",flexShrink:0,margin:"0 10px"}}),v.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:20,flexShrink:0},children:[d("field","FIELD"),d("today","TODAY"),d("log","PROCESS LOG")]}),v.jsxs("div",{style:{marginLeft:"auto",display:"flex",alignItems:"center",gap:22,minWidth:0},children:[v.jsxs("div",{title:m,style:{display:"flex",alignItems:"center",gap:9,flexShrink:0,cursor:"help"},children:[v.jsx("span",{style:{width:5,height:5,borderRadius:"50%",background:tM[f.tone],flexShrink:0}}),v.jsx("span",{style:{fontSize:10,letterSpacing:"0.2em",color:X.chromeStrong,whiteSpace:"nowrap"},children:f.label})]}),v.jsxs("button",{onClick:()=>l(h?"capture":"synthetic"),title:h?"Switch to CAPTURE":"Switch to SYNTHETIC",style:{background:"transparent",border:"none",padding:"3px 0",cursor:"pointer",display:"flex",alignItems:"center",gap:8,flexShrink:0},children:[v.jsx("span",{style:{fontSize:10,color:h?X.chromeDim:X.accent},children:h?"○":"●"}),v.jsx("span",{style:{fontSize:9.5,letterSpacing:"0.16em",color:X.chrome},children:h?"SYNTHETIC":"CAPTURE"})]})]})]})}function lM({view:n,perf:i,touch:s}){return v.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:14,padding:"10px 24px 14px",borderTop:`1px solid ${X.hairline}`,fontSize:10.5,letterSpacing:"0.16em",color:X.chrome,flexWrap:"wrap"},children:[v.jsx("span",{children:n==="field"?s?"DRAG TO PAN · PINCH TO ZOOM · TAP TO INSPECT":"SCROLL TO PAN · ⌃SCROLL / PINCH TO ZOOM · CLICK TO INSPECT · ZOOM OUT FOR TODAY":n==="log"?"CLICK A ROW FOR THE FULL RECORD · CLICK A COLUMN TO SORT":"HOVER AN INFERRED MEASURE FOR THE ASSUMPTION BEHIND IT"}),v.jsx("span",{style:{marginLeft:"auto",color:X.chromeDim,fontSize:9.5},children:n==="field"&&i&&i.fps>0?`${Math.round(i.fps)}FPS${i.gpuMs>0?` · ${i.gpuMs.toFixed(1)}MS GPU`:""}${i.scale<1?` · ${Math.round(i.scale*100)}%`:""}`:""})]})}Ex.createRoot(document.getElementById("root")).render(v.jsx(Q.StrictMode,{children:v.jsx(sM,{})}));
|
package/dist/index.html
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32.png">
|
|
9
9
|
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16.png">
|
|
10
10
|
<!-- No web fonts. 057 makes no external request; see the type stack in src/ui/tokens.ts. -->
|
|
11
|
-
<script type="module" crossorigin src="/assets/index-
|
|
11
|
+
<script type="module" crossorigin src="/assets/index-BKBPp9Vh.js"></script>
|
|
12
12
|
<link rel="stylesheet" crossorigin href="/assets/index-57shDcHR.css">
|
|
13
13
|
</head>
|
|
14
14
|
<body>
|
package/dist-server/057.mjs
CHANGED
|
@@ -66,7 +66,7 @@ CREATE INDEX IF NOT EXISTS claims_event ON claims(event_id);
|
|
|
66
66
|
(SELECT id FROM events WHERE subject_type = ? AND subject_id = ?)`),fe=t.prepare("DELETE FROM events WHERE subject_type = ? AND subject_id = ?");let q=0,U=0,x=0;t.exec("BEGIN");try{for(const{type:N,id:F}of R.values()){x+=Number(P.run(N,F).changes);const ne=Number(fe.run(N,F).changes);yt.includes(N)?q+=ne:U+=ne}t.exec("COMMIT")}catch(N){throw t.exec("ROLLBACK"),N}return q+U>0&&y.checkpoint(),{processEvents:q,otherEvents:U,claims:x,subjects:R.size,retainedByDependents:_,processBefore:h,otherBefore:l}},checkpoint(){try{t.exec("PRAGMA wal_checkpoint(TRUNCATE)")}catch{}},sizeBytes(){const[d,m,h]=je(e).map(oo);return{db:d,wal:m,shm:h,total:d+m+h}},health(){const d=o.size;return d===0?{ok:!0,malformedRows:0,columns:[],since:null}:{ok:!1,malformedRows:d,columns:[...r].sort(),since:a,remedy:`${d} stored row(s) could not be read as JSON and lost their ${[...r].sort().join("/")} channel. Everything else is being used normally and nothing has been deleted. Run \`057 compact\` to rewrite the store; if the count keeps growing, back the store up and run \`057 reset\` to start a new one.`}},compact(){t.exec("VACUUM"),y.checkpoint(),We(e)},close(){y.checkpoint(),t.close()}};return y}function oo(e){try{return Ne(e).size}catch{return 0}}function Te(e,t,s){if(e!=null)try{const n=JSON.parse(String(e));if(n&&typeof n=="object")return n;t&&s?.(t);return}catch{t&&s?.(t);return}}function ro(e,t){const s=e,n=t?o=>t(o,String(s.id)):void 0;return{id:String(s.id),source:{id:String(s.source_id),instance:String(s.source_instance)},occurredAt:Number(s.occurred_at),observedAt:Number(s.observed_at),clock:s.clock,kind:s.kind,subject:{type:s.subject_type,id:String(s.subject_id)},core:Te(s.core,"core",n),attrs:Te(s.attrs,"attrs",n),basis:s.basis,assumption:s.assumption?String(s.assumption):void 0,stratum:s.stratum?s.stratum:void 0,provenance:Te(s.provenance,"provenance",n)}}const _e="os",io=(e,t)=>`os:${e}:${t.pid}:${t.startedAt}`,ao=e=>`The process was present in one ${Math.round(e/1e3)}s snapshot and absent from the next, so it exited somewhere in that window. The recorded instant is the last moment it was observed alive — a lower bound on the true exit. A process that started and exited entirely within one interval is never observed at all.`,co=250,uo=8*1024*1024;function lo(e,t,s){const n={source:{id:_e,instance:s.host},observedAt:s.observedAt,clock:"wall",stratum:"machine"},o=[],r=new Map;for(const a of t){const i=io(s.host,a);r.set(i,a);const u={ns:"os.process",parts:[s.host,a.pid],validFrom:a.startedAt,validTo:s.observedAt};if(!e.has(i)){o.push({...n,occurredAt:a.startedAt,kind:"began",subject:{type:"process",id:i},claims:[u],basis:"measured",core:{machineId:s.machineId,label:po(a.command),executor:a.command,measures:{[O.cpuMs]:a.cpuMs}},attrs:{"os.pid":a.pid,"os.ppid":a.ppid,"os.command":a.command,"os.rssBytes":a.rssBytes}});continue}const p=e.get(i),c=a.cpuMs-p.cpuMs>=co,f=Math.abs(a.rssBytes-p.rssBytes)>=uo;(c||f)&&o.push({...n,occurredAt:s.observedAt,seq:`obs:${s.observedAt}`,kind:"observed",subject:{type:"process",id:i},claims:[u],basis:"measured",core:{measures:{[O.cpuMs]:a.cpuMs}},attrs:{"os.rssBytes":a.rssBytes}})}for(const[a,i]of e)r.has(a)||o.push({...n,occurredAt:s.observedAt-s.intervalMs,kind:"ended",subject:{type:"process",id:a},basis:"inferred",assumption:ao(s.intervalMs),core:{outcome:"completed",measures:{[O.cpuMs]:i.cpuMs}},attrs:{"os.pid":i.pid}});return{envelopes:o,next:r}}function po(e){return(e.split("/").pop()??e).toUpperCase()}const fo=ys(gs);function mo(){return Tt().replace(/\.local$/i,"")}function ho(e){const t=[];for(const s of e.split(`
|
|
67
67
|
`)){const n=s.trim();if(!n)continue;const o=n.match(/^(\d+)\s+(\d+)\s+(\w{3}\s+\w{3}\s+\d+\s+[\d:]+\s+\d{4})\s+([\d:.]+)\s+(\d+)\s+(.*)$/);if(!o)continue;const[,r,a,i,u,p,c]=o,f=Date.parse(i);Number.isFinite(f)&&t.push({pid:Number(r),ppid:Number(a),startedAt:f,cpuMs:bo(u),rssBytes:Number(p)*1024,command:c.trim()})}return t}function bo(e){const[t,s]=e.includes("-")?e.split("-"):["0",e],n=s.split(":").map(Number);let o=0;for(const r of n)o=o*60+(Number.isFinite(r)?r:0);return Math.round((o+Number(t)*86400)*1e3)}async function go(){const{stdout:e}=await fo("ps",["-Ao","pid=,ppid=,lstart=,time=,rss=,comm="],{maxBuffer:8388608});return ho(e)}const At=5e3;function yo(e,t){const s=mo();let n=new Map,o=null,r=0,a=null,i,u=!1;async function p(){if(u)return[];u=!0;try{const c=Date.now(),f=await go(),{envelopes:E,next:g}=lo(n,f,{machineId:t,host:s,observedAt:c,intervalMs:At}),y=E.map(G);return e.append(y),n=g,r++,a=c,i=void 0,y}catch(c){return i=c instanceof Error?c.message:String(c),[]}finally{u=!1}}return{sample:p,start(){o||(p(),o=setInterval(()=>{p()},At),o.unref?.())},stop(){o&&clearInterval(o),o=null},get running(){return o!==null},stats(){return{samples:r,tracked:n.size,lastSampleAt:a,lastError:i}}}}const Qt={info:e=>console.log(e),warn:e=>console.warn(e),error:e=>console.error(e)},vo=36e5,wo=15e3,Ao=3;function Ye(e={}){const t=e.log??Qt,s=e.path??ze(),n=e.retention??zt(),o=no(s),r=o.stats();t.info(r.events>0?`[057] store ${s}: opened with ${r.events} events`:`[057] store ${s}: NEW EMPTY STORE — if history existed before, it was lost, not carried`);const a=Kt();a&&t.warn(`[057] a store from a previous layout exists at ${a} and is NOT in use. Run 057 with O57_STORE=${a} to keep using it, or move it to ${s}.`);const i=se();o.append([G({source:{id:"host",instance:i.id},occurredAt:0,observedAt:Date.now(),clock:"wall",kind:"began",stratum:"machine",subject:{type:"machine",id:i.id},basis:"measured",core:{machineName:i.name,machineKind:i.kind},seq:"host"})]);const u=yo(o,i.id),p=new Map;function c(l){for(const b of l){const A=p.get(b.id)??{consecutiveFailures:0,totalFailures:0,failing:!1};b.ok?(A.consecutiveFailures=0,A.failing=!1,A.lastSuccessAt=Date.now()):(A.consecutiveFailures++,A.totalFailures++,A.lastFailureAt=Date.now(),A.lastError=b.error,A.consecutiveFailures>=Ao&&!A.failing&&(A.failing=!0,t.warn(`[057] source ${b.id} has failed ${A.consecutiveFailures} collection rounds in a row: ${b.error??"unknown error"}`))),p.set(b.id,A)}}const f=Et(s);let E=null;function g(l){return E||(E=l,t.error(`[057] ${l.message} — ${l.remedy}`),u.stop()),E}function y(){if(E)return E;if(s===":memory:")return null;if(!C(s))return g({kind:"unlinked",message:`the store at ${s} no longer exists on disk; captured events are going to an orphaned file and will be lost`,remedy:"Stop 057 and start it again. It will open a new store at the same path.",since:Date.now()});const l=Et(s);return f!==null&&l!==null&&l!==f?g({kind:"replaced",message:`the store at ${s} was replaced by a different file while 057 was running; captured events are going to the old one`,remedy:"Stop 057 and start it again so it opens the file that is actually there.",since:Date.now()}):null}e.observe!==!1&&u.start();const d=o.sweep(n);d.processEvents+d.otherEvents>0&&t.info(`[057] retention: removed ${d.processEvents} process and ${d.otherEvents} semantic events (${Me(n)})`);const m=setInterval(()=>{if(!E)try{o.sweep(n),We(s)}catch(l){t.warn(`[057] retention sweep failed: ${String(l)}`)}},vo);m.unref?.();const h=setInterval(()=>{y()},wo);return h.unref?.(),{store:o,machine:i,os:u,path:s,retention:n,fault:()=>E,sweep:l=>o.sweep(n,l),checkStore:y,recordCollection:c,collectionHealth:()=>Object.fromEntries(p),stop(){clearInterval(m),clearInterval(h),u.stop(),o.close()}}}function Et(e){try{return Ne(e).ino}catch{return null}}const Eo=[{id:_t,collect:(e,t)=>Ps(e,t)},{id:Ue,collect:(e,t)=>Ks(e,t)},{id:le,collect:(e,t)=>cn(e,t)},{id:ke,collect:(e,t)=>yn(e,t)},{id:ge,collect:(e,t)=>_n(e,t)},{id:Ie,collect:(e,t)=>Dn(e,t)}],kt=10*365*24*36e5,Ee=2e5,ko=24*36e5;function So(e,t,s){const n=t.startsWith("/api/");if(s){const i=(e.headers.host??"").toLowerCase(),u=i.startsWith("[")?i.slice(0,i.indexOf("]")+1):i.split(":")[0];if(!s.includes(u))return`refusing a request for host "${i}"; 057 answers only on ${s.join(", ")}`}const o=e.headers.origin;if(typeof o=="string"&&o!=="null"){const i=(e.headers.host??"").toLowerCase();let u="";try{u=new URL(o).host.toLowerCase()}catch{return"refusing a request with an unparseable Origin"}if(u!==i)return`refusing a cross-origin request from ${o}`}const r=e.headers["sec-fetch-site"],a=String(e.headers["sec-fetch-dest"]??"");if(Io.has(a))return`refusing to be embedded as ${a}`;if(typeof r=="string"&&r!==""){if(r!=="same-origin"&&r!=="none")return`refusing a ${r} request`;if(r==="none"&&n)return"refusing a directly-navigated API request"}else if(n&&t==="/api/collect")return"refusing a state-changing request that carries no fetch metadata";return null}const Io=new Set(["iframe","frame","embed","object","fencedframe"]);function Ke(e){e.setHeader("x-frame-options","DENY"),e.setHeader("content-security-policy","frame-ancestors 'none'")}function To(e,t){const s=(r,a)=>{const i=e.get(r);if(i===null||i==="")return a;const u=Number(i);return Number.isSafeInteger(u)?u:null},n=s("from",t-864e5),o=s("to",t);return n===null||o===null?{error:"from and to must be integer epoch millis"}:o<n?{error:"to must not precede from"}:o>t+ko?{error:"to is too far in the future"}:o-n>kt?{error:`window must not exceed ${kt} ms`}:{from:n,to:o}}function H(e,t,s){e.statusCode=t,e.setHeader("content-type","application/json"),e.setHeader("cache-control","no-store"),e.setHeader("x-content-type-options","nosniff"),Ke(e),e.end(JSON.stringify(s))}function Zt(e,t,s,n){const o=e.query(t,s,n),r=new Set,a=new Set,i=c=>{const f=`${c.subject.type}:${c.subject.id}`;c.kind==="began"?r.add(f):a.add(f),c.core?.sessionId&&a.add(`session:${c.core.sessionId}`),c.core?.machineId&&a.add(`machine:${c.core.machineId}`)};for(const c of o)i(c);const u=[];for(let c=0;c<4;c++){const f=[...a].filter(g=>!r.has(g));if(f.length===0)break;const E=e.begansFor(f);if(E.length===0)break;for(const g of E)u.push(g.occurredAt<t?{...g,occurredAt:t}:g),i(g),r.add(`${g.subject.type}:${g.subject.id}`)}return{events:[...u,...o].sort((c,f)=>c.occurredAt-f.occurredAt||St(c)-St(f)),relationships:$s(e,t,s).relationships}}function _o(e,t,s){const n=performance.now(),{events:o,relationships:r}=Zt(e,t,s),a=performance.now()-n,i=performance.now(),u=Pn(t,s);Vn(u,o),Gn(u,s);const p=performance.now()-i,c=performance.now(),f=Yn(u,r),E=performance.now()-c;return{world:f,meta:{events:o.length,readMs:Math.round(a*10)/10,deriveMs:Math.round(p*10)/10,serializeMs:Math.round(E*10)/10}}}function St(e){if(e.kind==="ended")return 5;switch(e.subject.type){case"machine":return 0;case"session":return 1;case"execution":case"process":return e.kind==="began"?2:3;default:return 4}}function Ro(e){const t=e.problems.filter(s=>s.path.includes("/sessions/")).length;return{identity:e.identityAvailable?t===0?"available":e.registryEntries>0?"partial":"failed":"unavailable","stored-semantics":e.storedAvailable?e.transcriptsFailed===0?"available":e.transcriptsRead>0?"partial":"failed":"unavailable","live-semantics":"unavailable"}}function Le(e){return{"stored-semantics":e.storedAvailable?e.failed===0?"available":e.read>0?"partial":"failed":"unavailable","live-semantics":"unavailable"}}function $o(e){return e.error?"failed":e.available?"observing":e.present?"installed-no-data":"not-installed"}function Oo(e){const t=e.home??e.globalStorage;if(typeof t=="string")return t;const s=e.roots;return Array.isArray(s)?s.join(", "):void 0}function ae(e){return{available:e.available,present:e.present??!1,presence:$o(e),origin:Oo(e),error:e.error}}function No(e){const{runtime:t,log:s}=e;return async function(o,r){const a=o.url??"";if(!a.startsWith("/api/"))return!1;const i=new URL(a,"http://localhost"),u=So(o,i.pathname,e.allowedHosts);if(u)return s.warn(`[057] ${u}`),H(r,403,{error:u}),!0;const p=t.store,c=Date.now(),f=To(i.searchParams,c);if("error"in f)return H(r,400,{error:f.error}),!0;const{from:E,to:g}=f;try{if(i.pathname==="/api/state"){const[y,d,m,h,l,b]=await Promise.all([Bs().catch(x=>({available:!1,error:String(x)})),Qs().catch(x=>({available:!1,error:String(x)})),un().catch(x=>({available:!1,error:String(x)})),vn().catch(x=>({available:!1,error:String(x)})),Rn().catch(x=>({available:!1,error:String(x)})),Fn().catch(x=>({available:!1,error:String(x)}))]),[A,v,S,R]=await Promise.all([Dt(E,g).catch(()=>null),Pt(E,g).catch(()=>null),Wt(E,g).catch(()=>null),Gt(E,g).catch(()=>null)]),I={strata:{"stored-semantics":"failed"}},$={"claude-code":A?{strata:Ro(A),registryEntries:A.registryEntries,transcriptsRead:A.transcriptsRead,transcriptsFailed:A.transcriptsFailed,problems:A.problems.slice(0,20)}:{strata:{identity:"failed"}},codex:v?{strata:Le({storedAvailable:v.storedAvailable,read:v.rolloutsRead,failed:v.rolloutsFailed}),rolloutsRead:v.rolloutsRead,rolloutsFailed:v.rolloutsFailed,problems:v.problems.slice(0,20)}:I,cursor:S?{strata:Le({storedAvailable:S.storedAvailable,read:S.composersRead,failed:S.composersFailed}),composersRead:S.composersRead,composersFailed:S.composersFailed,problems:S.problems.slice(0,20)}:I,gemini:R?{strata:Le({storedAvailable:R.storedAvailable,read:R.sessionsRead,failed:R.sessionsFailed}),sessionsRead:R.sessionsRead,sessionsFailed:R.sessionsFailed,problems:R.problems.slice(0,20)}:I},w={deepseek:ae(y),"0x2f":ae(d),"claude-code":ae(m),codex:ae(h),cursor:ae(l),gemini:ae(b)},k=t.collectionHealth();for(const[x,N]of Object.entries(w)){const F=k[x];F?.failing&&(N.presence="failed",N.error??=F.lastError)}const T=t.os.stats(),P=Object.values(w).filter(x=>x.available).length>0?"observing":T.samples>0?"os-only":"empty",fe=Object.entries(k).filter(([,x])=>x.failing).map(([x])=>x),q=p.health(),U={ok:fe.length===0&&q.ok&&!t.fault()&&!T.lastError,failingSources:fe,collection:k,store:q,os:T.lastError?{failing:!0,lastError:T.lastError}:{failing:!1}};return H(r,200,{machine:t.machine,mode:P,fault:t.fault()??void 0,health:U,store:{...p.stats(),path:p.path,schemaVersion:p.schemaVersion,bytes:p.sizeBytes(),retention:{...t.retention,description:Me(t.retention)}},os:{...T,running:t.os.running,source:_e},sources:w,observation:$}),!0}if(i.pathname==="/api/collect"){const y=t.checkStore();if(y)return H(r,503,{error:y.message,fault:y}),!0;const d=await Rs(p,Eo,E,g);t.recordCollection(d.sources);const m=await t.os.sample();return t.recordCollection([{id:_e,ok:!t.os.stats().lastError,error:t.os.stats().lastError}]),H(r,200,{...d,sources:[...d.sources,{id:_e,ok:!t.os.stats().lastError,collected:m.length,inserted:m.length,duplicate:0,error:t.os.stats().lastError,ms:0}]}),!0}if(i.pathname==="/api/world")return H(r,200,{from:E,to:g,now:c,..._o(p,E,g)}),!0;if(i.pathname==="/api/detail"){const y=i.searchParams.get("type")??"",d=i.searchParams.get("id")??"";if(!rt.includes(y)||!d)return H(r,400,{error:"detail needs type=<entity type> and id"}),!0;if(d.length>512)return H(r,400,{error:"id is too long"}),!0;const m=p.subjectEvents(y,d);return H(r,200,{type:y,id:d,events:m.slice(0,Ee),truncated:m.length>Ee}),!0}if(i.pathname==="/api/events"){const y=i.searchParams.get("subject"),d=y?y.split(",").filter(h=>rt.includes(h)):void 0,m=Zt(p,E,g,d);return H(r,200,{from:E,to:g,now:c,events:m.events.slice(0,Ee),truncated:m.events.length>Ee,relationships:m.relationships}),!0}return H(r,404,{error:"unknown endpoint"}),!0}catch(y){return s.error(`[057] ${String(y)}`),H(r,500,{error:String(y)}),!0}}}const Qe=5057,ye="127.0.0.1",Mo=["localhost","127.0.0.1","[::1]","::1"],jo=10,xo={".html":"text/html; charset=utf-8",".js":"text/javascript; charset=utf-8",".css":"text/css; charset=utf-8",".json":"application/json; charset=utf-8",".svg":"image/svg+xml",".woff2":"font/woff2",".png":"image/png",".ico":"image/vnd.microsoft.icon"};function It(e,t,s){let n;try{n=decodeURIComponent(t)}catch{return!1}if(n.includes("\0"))return!1;const o=ve(e,`.${ls(n)}`);if(o!==e&&!o.startsWith(e+ps)||!C(o)||!Ne(o).isFile())return!1;const r=xo[fs(o).toLowerCase()]??"application/octet-stream";return s.statusCode=200,s.setHeader("content-type",r),s.setHeader("x-content-type-options","nosniff"),Ke(s),s.setHeader("cache-control",t.startsWith("/assets/")?"public, max-age=31536000, immutable":"no-store"),rs(o).pipe(s),!0}function Co(e,t,s,n){return new Promise((o,r)=>{let a=n,i=t;const u=p=>{if(p.code==="EADDRINUSE"&&a>1){a--,i++,e.listen(i,s);return}e.off("error",u),r(p)};e.on("error",u),e.once("listening",()=>{e.off("error",u);const p=e.address();o(typeof p=="object"&&p?p.port:i)}),e.listen(i,s)})}function Do(e,t){const s=String(e.headers["sec-fetch-dest"]??"");if(Fo.has(s))return`refusing to be embedded as ${s}`;const n=e.headers["sec-fetch-site"];return typeof n=="string"&&n!==""&&n!=="same-origin"&&n!=="none"?`refusing a ${n} request for ${t}`:null}const Fo=new Set(["iframe","frame","embed","object","fencedframe"]);async function Lo(e){const t=e.log??Qt,s=ve(e.root),n=e.host??ye,o=n===ye||n==="::1"||n==="localhost",r=e.runtime??Ye({path:e.storePath,log:t,retention:e.retention,observe:e.observe}),a=No({runtime:r,log:t,allowedHosts:o?Mo:null}),i=cs((c,f)=>{(async()=>{try{if(await a(c,f))return;if(c.method!=="GET"&&c.method!=="HEAD"){f.statusCode=405,f.setHeader("allow","GET, HEAD"),f.end();return}const E=new URL(c.url??"/","http://localhost").pathname,g=Do(c,E);if(g){t.warn(`[057] ${g}`),f.statusCode=403,f.setHeader("content-type","text/plain; charset=utf-8"),Ke(f),f.end(`${g}
|
|
68
68
|
`);return}if(It(s,E==="/"?"/index.html":E,f)||!E.startsWith("/assets/")&&It(s,"/index.html",f))return;f.statusCode=404,f.setHeader("content-type","text/plain; charset=utf-8"),f.end(`not found
|
|
69
|
-
`)}catch(E){t.error(`[057] request failed: ${String(E)}`),f.headersSent||(f.statusCode=500),f.end()}})()}),u=await Co(i,e.port??Qe,n,jo).catch(c=>{throw r.stop(),c});return{url:`http://${o?"localhost":n}:${u}`,port:u,host:n,runtime:r,server:i,close(){return new Promise(c=>{i.close(()=>{r.stop(),c()}),i.closeAllConnections?.()})}}}function Uo(e){return ve(ms(new URL(".",e)),"..","dist")}const es="0.1.
|
|
69
|
+
`)}catch(E){t.error(`[057] request failed: ${String(E)}`),f.headersSent||(f.statusCode=500),f.end()}})()}),u=await Co(i,e.port??Qe,n,jo).catch(c=>{throw r.stop(),c});return{url:`http://${o?"localhost":n}:${u}`,port:u,host:n,runtime:r,server:i,close(){return new Promise(c=>{i.close(()=>{r.stop(),c()}),i.closeAllConnections?.()})}}}function Uo(e){return ve(ms(new URL(".",e)),"..","dist")}const es="0.1.2";function Po(e){const t={command:"serve",open:!1,yes:!1},s=[...e],n=s[0];if(n&&!n.startsWith("-"))if(n==="status"||n==="compact"||n==="reset")t.command=n,s.shift();else return{...t,command:"help",error:`unknown command: ${n}`};for(;s.length;){const o=s.shift(),[r,a]=o.includes("=")?Bo(o,"="):[o,void 0],i=()=>a??s.shift();switch(r){case"-h":case"--help":t.command="help";break;case"-v":case"--version":t.command="version";break;case"--open":t.open=!0;break;case"--yes":case"-y":t.yes=!0;break;case"--port":{const u=i(),p=Number(u);if(!Number.isInteger(p)||p<0||p>65535)return{...t,command:"help",error:`--port needs a port number, got ${u}`};t.port=p;break}case"--host":{const u=i();if(!u)return{...t,command:"help",error:"--host needs a value"};t.host=u;break}case"--store":{const u=i();if(!u)return{...t,command:"help",error:"--store needs a path"};t.store=u;break}default:return{...t,command:"help",error:`unknown option: ${r}`}}}return t}function Bo(e,t){const s=e.indexOf(t);return[e.slice(0,s),e.slice(s+1)]}const Ho=`057 — a spatial interface for observing the shape of a computational workday
|
|
70
70
|
|
|
71
71
|
057 observe this machine and serve the interface
|
|
72
72
|
057 status where the store is, what it holds, what is observed
|