// SPDX-License-Identifier: Apache-2.0 // © 2026 Lutar, Stephen P. Jr. — SZL Holdings · ORCID 0009-0001-0110-4173 · Doctrine v11 // // surfaces/brainbody.js — ANATOMY · BODY LIT BY THE BRAIN (Wave O, Dev 3). // // The founder's vision: "I want my Brain harnessing and giving energy to the whole // ecosystem." This surface renders that literally — a central BRAIN CORE pulses and // radiates light down "nerves" to a ring of organs, and EACH ORGAN'S BRIGHTNESS is // driven by the real Brain pulse (Dev-1 GET /api/a11oy/v1/brain/pulse) and its energy // allocation (Dev-2 GET /api/a11oy/v1/brain/energy), composed server-side by // GET /api/a11oy/v1/frontier/brainbody (this Dev's thin backend, szl_brainbody.py). // // WHAT IS LIT BY THE BRAIN: // - BRAIN CORE — pulses at the pulse's activity; teal + bright when the pulse is // LIVE, dim grey when UNAVAILABLE. It is the light SOURCE. // - EACH ORGAN — a node on the body ring whose emissive brightness = its per-organ // value from the pulse (activity) blended with its energy allocation. A pulse of // light travels the nerve from the Brain to each LIT organ every beat. // - HONEST PER-ORGAN LABELS — every organ shows LIVE / MODELED / UNAVAILABLE // VERBATIM. An UNAVAILABLE organ is DARK + still; it is NEVER shown alive. // // HONESTY (Zero-Bandaid Law): the Brain hub/energy PRs may not be merged in this // runtime. The backend composes with a guarded fallback and returns honest // UNAVAILABLE when a source is absent — so this surface renders a DARK body rather // than a fabricated living one. Nothing here fabricates a pulse, a joule, or a lit // organ. Λ = Conjecture 1 (advisory, grey, never green); trust ceiling 0.97 (never // 1.0). Nothing touches the locked-8. ZERO PURPLE. three via ctx.THREE (0 CDN). // // Surface export shape mirrors sovereign.js / evalarena.js exactly: // export default { id, title, endpoints, mount, unmount } import { createShowcase } from "./_showcase.js"; const ID = "brainbody"; const TITLE = "Anatomy · Body lit by the Brain"; const EP_PANEL = "/api/a11oy/v1/frontier/brainbody"; // this Dev's composer const EP_PULSE = "/api/a11oy/v1/brain/pulse"; // Dev-1 (read server-side) const EP_ENERGY = "/api/a11oy/v1/brain/energy"; // Dev-2 (read server-side) // data-viz hues — purple BANNED const C_LIVE = 0x3af4c8; // proof-teal (LIVE — organ lit by the Brain) const C_MODELED = 0x5b8dee; // lattice-blue (MODELED — dimmer, honest) const C_DOWN = 0x2b3542; // dark slate (UNAVAILABLE — dark, never alive) const C_BRAIN = 0x8fdcff; // light blue (Brain core — the light source) const C_NERVE = 0x1b3a44; // nerve edge (idle) const BRAIN_R = 1.05, RING_R = 5.4; let _stage=null,_THREE=null,_ctx=null,_group=null,_overlay=null; let _frameReg=false,_polls=[],_badge=null,_plain=false,_t0=0,_show=null; let _brain=null,_brainGlow=null,_nerves=[],_organs=[]; // _organs: [{mesh,glow,nerve,comet,data}] const S = { label:"UNAVAILABLE", state:"init", pulseOk:false, pulseLabel:"UNAVAILABLE", pulseSource:null, pulseNote:null, energyOk:false, energyLabel:"UNAVAILABLE", energySource:null, energyNote:null, organs:[], // [{id,organ,role,label,brightness,activity,energy_alloc,lit_by_brain}] summary:{organs_total:0,organs_lit:0,live:0,modeled:0,unavailable:0}, signMode:null, signed:false, }; function _colFor(label){ if(label==="LIVE") return C_LIVE; if(label==="MODELED") return C_MODELED; return C_DOWN; } function mount(ctx){ _ctx=ctx; _stage=ctx.stage; _THREE=ctx.THREE; _group=new _THREE.Group(); _stage.scene.add(_group); try{ _stage.camera.position.set(0,3.5,14); }catch(_){} try{ if(_stage.controls&&_stage.controls.target){ _stage.controls.target.set(0,0.2,0); _stage.controls.update(); } }catch(_){} try{ _stage.setBloom&&_stage.setBloom(true); }catch(_){} _t0=(typeof performance!=="undefined"?performance.now():Date.now()); _badge=ctx.live.createBadge(); _buildOverlay(ctx); _buildBrain(); // GET the composed panel — the CORE poll. It reads the Brain pulse (Dev-1) + energy // (Dev-2) server-side and returns per-organ lighting; degrades to honest UNAVAILABLE. _polls.push(ctx.live.poll(EP_PANEL, 8000, _onPanel, { badge:_badge, onState:(m)=>{ S.state=m.state; _paintOverlay(); }, })); if(!_frameReg&&_stage.onFrame){ _stage.onFrame(_animate); _frameReg=true; } _paintOverlay(); return { id:ID, started:true }; } function _readLabel(j){ const l=(j&&j.label!=null)?j.label:"UNAVAILABLE"; return String(l).toUpperCase(); } function _onPanel(j){ if(!j){ S.state="error"; _paintOverlay(); return; } S.label=_readLabel(j); const pu=j.pulse||{}, en=j.energy||{}; S.pulseOk=(pu.ok===true); S.pulseLabel=String(pu.label||"UNAVAILABLE").toUpperCase(); S.pulseSource=pu.source||null; S.pulseNote=pu.note||pu.dependency||null; S.energyOk=(en.ok===true); S.energyLabel=String(en.label||"UNAVAILABLE").toUpperCase(); S.energySource=en.source||null; S.energyNote=en.note||en.dependency||null; S.organs=Array.isArray(j.organs)?j.organs:[]; S.summary=j.summary||S.summary; const sr=j.signed_receipt||{}; S.signMode=sr.sign_mode||null; S.signed=(sr.signed===true); _rebuildOrgans(); _paintScene(); _paintOverlay(); } // --------------------------------------------------------------------------- // scene // --------------------------------------------------------------------------- function _buildBrain(){ const cg=new _THREE.SphereGeometry(BRAIN_R,40,40); const cm=new _THREE.MeshStandardMaterial({ color:C_DOWN,emissive:C_DOWN,emissiveIntensity:0.2,metalness:0.12,roughness:0.45 }); _brain=new _THREE.Mesh(cg,cm); _brain.position.set(0,0,0); _brain.userData={role:"brain-core"}; _group.add(_brain); const gg=new _THREE.SphereGeometry(BRAIN_R*1.5,24,24); const gm=new _THREE.MeshBasicMaterial({ color:C_BRAIN,transparent:true,opacity:0.06,blending:_THREE.AdditiveBlending,depthWrite:false }); _brainGlow=new _THREE.Mesh(gg,gm); _group.add(_brainGlow); } function _disposeOrgans(){ _organs.forEach((o)=>{ [o.mesh,o.glow,o.nerve,o.comet].forEach((m)=>{ if(!m)return; try{ if(m.geometry&&m.geometry.dispose)m.geometry.dispose(); }catch(_){} try{ const ms=Array.isArray(m.material)?m.material:[m.material]; ms.forEach((x)=>{if(x&&x.dispose)x.dispose();}); }catch(_){} try{ _group.remove(m); }catch(_){} }); }); _organs=[]; _nerves=[]; } function _rebuildOrgans(){ if(!_group||!_THREE)return; _disposeOrgans(); const n=S.organs.length||1; S.organs.forEach((d,i)=>{ const ang=(i/n)*Math.PI*2; const px=Math.cos(ang)*RING_R, pz=Math.sin(ang)*RING_R, py=0.6*Math.sin(ang*1.3); const col=_colFor(d.label); // organ node const og=new _THREE.SphereGeometry(0.5,22,22); const om=new _THREE.MeshStandardMaterial({ color:col,emissive:col,emissiveIntensity:0.25,metalness:0.1,roughness:0.5,transparent:true,opacity:0.92 }); const mesh=new _THREE.Mesh(og,om); mesh.position.set(px,py,pz); mesh.userData={role:"organ",id:d.id}; _group.add(mesh); // organ glow const gg=new _THREE.SphereGeometry(0.7,16,16); const gm=new _THREE.MeshBasicMaterial({ color:col,transparent:true,opacity:0.05,blending:_THREE.AdditiveBlending,depthWrite:false }); const glow=new _THREE.Mesh(gg,gm); glow.position.set(px,py,pz); _group.add(glow); // nerve from Brain core to organ const pts=[new _THREE.Vector3(0,0,0), new _THREE.Vector3(px,py,pz)]; const ng=new _THREE.BufferGeometry().setFromPoints(pts); const nm=new _THREE.LineBasicMaterial({ color:C_NERVE,transparent:true,opacity:0.5 }); const nerve=new _THREE.Line(ng,nm); _group.add(nerve); // pulse comet that travels the nerve when the organ is lit by the Brain const cg=new _THREE.SphereGeometry(0.11,10,10); const cm=new _THREE.MeshBasicMaterial({ color:col,transparent:true,opacity:0.0,blending:_THREE.AdditiveBlending,depthWrite:false }); const comet=new _THREE.Mesh(cg,cm); _group.add(comet); // billboard label — organ name + VERBATIM honesty label let sprite=null; try{ sprite=_ctx.label.billboard(_THREE, d.label, { text:(d.organ||d.id)+" · "+d.label, scale:1.15, position:[px,py+1.0,pz] }); if(sprite)_group.add(sprite); }catch(_){} _organs.push({ mesh, glow, nerve, comet, sprite, data:d, ang, base:new _THREE.Vector3(px,py,pz) }); }); } function _paintScene(){ const live=(S.pulseLabel==="LIVE"); const bcol=live?C_BRAIN:C_DOWN; if(_brain&&_brain.material){ _brain.material.color.setHex(bcol); _brain.material.emissive.setHex(bcol); _brain.material.emissiveIntensity=live?0.6:0.18; } if(_brainGlow&&_brainGlow.material){ _brainGlow.material.color.setHex(bcol); _brainGlow.material.opacity=live?0.14:0.04; } _organs.forEach((o)=>{ const d=o.data, col=_colFor(d.label), b=(typeof d.brightness==="number")?d.brightness:0.06; if(o.mesh&&o.mesh.material){ o.mesh.material.color.setHex(col); o.mesh.material.emissive.setHex(col); o.mesh.material.emissiveIntensity=b; o.mesh.material.opacity=(d.label==="UNAVAILABLE")?0.35:0.92; } if(o.glow&&o.glow.material){ o.glow.material.color.setHex(col); o.glow.material.opacity=(d.label==="UNAVAILABLE")?0.02:(0.04+0.10*b); } if(o.nerve&&o.nerve.material){ o.nerve.material.color.setHex(d.lit_by_brain?col:C_NERVE); o.nerve.material.opacity=d.lit_by_brain?(0.35+0.4*b):0.18; } }); } function _animate(){ if(!_group)return; const now=(typeof performance!=="undefined"?performance.now():Date.now()); const t=(now-_t0)/1000; const live=(S.pulseLabel==="LIVE"); // Brain core breathes with the pulse. if(_brain&&_brain.material){ _brain.material.emissiveIntensity=(live?0.5:0.16)+(live?0.25:0.05)*Math.abs(Math.sin(t*1.8)); } if(_brainGlow){ const s=1.0+(live?0.10:0.03)*Math.sin(t*1.8); _brainGlow.scale.setScalar(s); } // Organs pulse in proportion to their brightness; comet of light travels the nerve. _organs.forEach((o,i)=>{ const d=o.data, b=(typeof d.brightness==="number")?d.brightness:0.06; const lit=d.lit_by_brain; if(o.mesh&&o.mesh.material&&lit){ o.mesh.material.emissiveIntensity=b*(0.75+0.25*Math.sin(t*2.2+i)); } if(o.comet&&o.comet.material){ if(lit){ const phase=((t*0.6+i*0.13)%1); // 0..1 along the nerve o.comet.position.copy(o.base).multiplyScalar(phase); o.comet.material.opacity=0.7*(1-Math.abs(0.5-phase)*1.4); } else { o.comet.material.opacity=0.0; } } // gentle bob if(o.mesh){ o.mesh.position.y=o.base.y+0.12*Math.sin(t*0.9+i); if(o.glow)o.glow.position.y=o.mesh.position.y; } }); _group.rotation.y=t*0.05; } // --------------------------------------------------------------------------- // overlay / HUD — mobile-friendly (flex-wrap, small fonts, matches sovereign.js) // --------------------------------------------------------------------------- function _buildOverlay(ctx){ _show=createShowcase(ctx,{ id:ID, title:TITLE, accent:"#3af4c8", badge:_badge, chips:[{label:"UNAVAILABLE", name:"label"},{label:"Λ=Conjecture 1", name:"lambda"}], }); _overlay=document.createElement("div"); _overlay.style.cssText="font:12px/1.5 ui-monospace,Menlo,monospace;color:#cfe3ea;"; _overlay.innerHTML= '
/brain/pulse) and its energy allocation (Dev-2 /brain/energy). If the Brain endpoints aren\'t merged yet, organs read UNAVAILABLE + go dark — never a fabricated living body.GET "+EP_PANEL+", a thin composer (szl_brainbody.py) that reads the Brain pulse ("+EP_PULSE+", Dev-1 feat/brain-hub) and the Brain energy allocation ("+EP_ENERGY+", Dev-2 feat/brain-energy) server-side \u2014 preferring the in-process module so it agrees with the routed endpoint by construction, else a same-origin HTTP read. Each organ\u2019s brightness is a deterministic function of its per-organ pulse activity blended with its energy allocation. An organ is LIVE only when a real per-organ pulse value backed it THIS request; MODELED when only a modeled/derived signal (energy share or a global pulse) is present; UNAVAILABLE (dark, still) when no signal is present. No label is ever upgraded and no organ is shown alive without a real value (Zero-Bandaid Law).feat/brain-hub ("+EP_PULSE+")feat/brain-energy ("+EP_ENERGY+")