In this section
- Kuiper Programs render · globalgrid2050 / kuiper-grid/i0091/cartridges/009100000000-kuiper-programs.js lines 3501–3725
- Kuiper Grid — I0091 Page render · globalgrid2050 / kuiper-grid/i0091/index.html lines 1–108
- Kuiper Programs render · globalgrid2050 / kuiper-grid/i0092/cartridges/009200000000-kuiper-programs.js lines 1–367
Kuiper Programs
A JavaScript module in the cartridges folder of GlobalGrid2050 covering cables, solar, substations and transformers, using IEC 62446-1 and SHA-256, and uses data from the faraday repository.
renderglobalgrid2050 / kuiper-grid/i0091/cartridges/009100000000-kuiper-programs.js · lines 3501–3725 of 3725 (continued from section 1413) · Not reached from any entry point (candidate for review) · pattern needSize (shared by 9 files)
- What it does
- It draws cables, solar, substations and transformers. Defines 201 functions or classes, including reFire, closestPair, blackSky, nameInLines, makeBody. Side effects: changes the web page (DOM); reads or writes files; makes network requests.
- Why it exists in the grid workflow
- Domain stage agent_infra (path word 'kuiper'): AI-agent memory, coordination and code audit (the multi-agent journey named in Ventus Ltd's brief). Domain terms in the code: cables, solar, substations, transformers, 400kV, 1500V.
- Inputs & outputs
- In: data source: faraday data; JSON file current.json. Out: canvas drawing. Voltage levels named: 400kV, 1500V.
- What it achieves
- It makes body (`makeBody`), sets tag (`setTag`) and merges menu (`mergeMenu`). A cartridge of the Kuiper shell. Its code works with 352 kVA, 295 kVA and 320 kVA. It responds to click, keydown and pointerdown events.
- Why it matters
- No other file in the estate was found to import it.
- Application
- globalgrid2050 · kuiper-grid/i0091/cartridges · JavaScript module
- Uses
- Faraday — Index Page (estate URL), Wafer Development Environment — Proof S0004 Page (estate URL), ./fire.js
- Used by
- none found
- Produces
- reFire, closestPair, blackSky, nameInLines, makeBody, bodyTo, labels, bodyJump, bodyMove, bodyDrawnDiameter, bodyDotPx, sheet
- Defines here
- put2, shapeAsk, shapeTrack, netPieces, line, ring, sym, netFinal, bad, net
- Cannot conclude
- Whether this code runs, is used by a live app today, or is correct. This is a static reading.
- Evidence
- globalgrid2050@0aca5121f0795e469b6cf4fc3d3b628edba8d883 kuiper-grid/i0091/cartridges/009100000000-kuiper-programs.js:3501-3725 · blob 9e8b847c0f465e8e0554f0338569ded56e2985cd · GitHub at these lines
- State
- achieves: comment · context: readme_derived · stage: output · effects: dom, filesystem, network · domain stage: agent_infra · users: ai_agent · canonical: unreached_review
if (seg.length < 2 || !onScreen(seg)) continue;
const wN = Math.max(2.2, (D.wiring ? Math.max(1.5, Math.min(3.2, perM * 0.022)) : fine * (L.s.weight || 1)) * 1.1) * amps;
ctx.shadowBlur = wN * 2.6;
path(seg); ctx.lineWidth = wN * 2.1; ctx.strokeStyle = 'rgba(86,214,255,0.22)'; ctx.stroke();
path(seg); ctx.lineWidth = wN; ctx.strokeStyle = 'rgba(224,250,255,0.92)'; ctx.stroke(); }
else if (L.mod && onScreen(L.mod.pts)) { // box to box THROUGH the module: its own outline lights
ctx.shadowBlur = 7 * amps;
path(L.mod.pts); ctx.closePath(); ctx.lineWidth = Math.max(1.4, fine * 1.2) * amps;
ctx.strokeStyle = 'rgba(120,232,255,0.55)'; ctx.stroke(); } }
ctx.restore(); ctx.shadowBlur = 0; }
}
// 3. THE GAP, and what it is short by, said in metres
for (const s of D.shapes) { if (s.role !== 'gap' || !onScreen(s.pts) || true) continue;
const a = S(s.pts[0]), b = S(s.pts[1]);
ctx.setLineDash([2.5, 3.5]); ctx.beginPath(); ctx.moveTo(a[0], a[1]); ctx.lineTo(b[0], b[1]);
ctx.lineWidth = hair; ctx.strokeStyle = SHAPE_WARN; ctx.stroke(); ctx.setLineDash([]);
for (const p of [a, b]) { ctx.beginPath(); ctx.arc(p[0], p[1], 1.9, 0, 6.2832); ctx.fillStyle = SHAPE_WARN; ctx.fill(); }
// WHAT IT IS SHORT BY, only when there is room for it to be read and never over a module's name.
if (false) {
} }
// 5. THE BOXES AND WHAT SITS ON THEM, over the cable ends, so a cable is seen to enter its box.
for (const s of D.shapes) {
if (s.role === 'box') { if (!onScreen(s.pts)) continue;
// A BOX TOO SMALL TO BE A BOX IS A DOT, NOT A SMALLER BOX. Under six pixels across, a rectangle
// with an outline and a fill is three grey pixels that say nothing; what a reader wants at that
// distance is only WHERE the boxes are, so one dot is drawn and the box itself is dropped. This is
// the macro rule and it is crossed by zooming, not by the word: pinch in and the dots become boxes
// at the same threshold either way.
{ const aa = S(s.pts[0]), bb2 = S(s.pts[2]);
const bpx = Math.min(Math.abs(bb2[0] - aa[0]), Math.abs(bb2[1] - aa[1]));
if (bpx < 6) { const cx2 = (aa[0] + bb2[0]) / 2, cy2 = (aa[1] + bb2[1]) / 2;
ctx.beginPath(); ctx.arc(Math.round(cx2), Math.round(cy2), 1.3, 0, 6.2832);
ctx.fillStyle = SHEET ? '#55606e' : SHAPE_PENCIL; ctx.fill(); continue; } }
path(s.pts); ctx.closePath(); ctx.fillStyle = BOXFILL; ctx.fill();
ctx.lineWidth = fine; ctx.strokeStyle = INK; ctx.stroke();
// THE MIDDLE BOX HAS NO CABLE: it carries a bypass diode, and it is drawn as one so that nobody
// takes it for a third connection.
// EACH OF THE THREE BOXES HOLDS ONE BYPASS DIODE, one per cell string. The two outer boxes carry a
// smaller mark of the same symbol, kept clear of the box edge where the lead lands.
if (s.diodeOnly || s.diode) { const a = S(s.pts[0]), b = S(s.pts[2]);
const cxm = (a[0] + b[0]) / 2, cym = (a[1] + b[1]) / 2, r2 = Math.min(Math.abs(b[0] - a[0]), Math.abs(b[1] - a[1])) * (s.diodeOnly ? 0.30 : 0.22);
if (r2 > 2) { ctx.beginPath(); ctx.moveTo(cxm - r2, cym - r2); ctx.lineTo(cxm - r2, cym + r2); ctx.lineTo(cxm + r2, cym);
ctx.closePath(); ctx.lineWidth = Math.max(0.8, fine * 0.6); ctx.strokeStyle = EDGE2; ctx.stroke();
ctx.beginPath(); ctx.moveTo(cxm + r2, cym - r2); ctx.lineTo(cxm + r2, cym + r2); ctx.stroke(); } }
continue; }
if (s.role === 'terminal' && s.pts.length > 1) { if (!onScreen(s.pts)) continue;
path(s.pts); ctx.lineWidth = fine; ctx.strokeStyle = INK; ctx.stroke(); continue; }
if (s.role === 'tube') { if (!onScreen(s.pts)) continue;
path(s.pts); ctx.lineWidth = hair; ctx.strokeStyle = EDGE2; ctx.stroke(); continue; }
if (s.role === 'landing' && false) { const q = S(s.pts[0]);
if (q[0] < -20 || q[0] > innerWidth + 20 || q[1] < -20 || q[1] > innerHeight + 20) continue;
// THE DOT ON THE BOX where the cable lands. Small, but it is the difference between a cable that
// joins a box and a line that happens to pass near one.
const r2 = Math.max(1.6, Math.min(4, perM * 0.018));
ctx.beginPath(); ctx.arc(q[0], q[1], r2, 0, 6.2832);
ctx.fillStyle = s.plus ? (SHEET ? '#c0271a' : SHAPE_RED) : (SHEET ? '#20262f' : '#cfe0ee'); ctx.fill(); continue; }
if (s.role === 'plug') { const q = S(s.pts[0]);
if (q[0] < -20 || q[0] > innerWidth + 20 || q[1] < -20 || q[1] > innerHeight + 20) continue;
// A CONNECTOR IS AN OBJECT, and the two halves are different objects: a plug is a barrel with a
// collar, a socket is a sleeve with two latches. Facing each other across a gap, they say what is
// wrong better than any words: these two were meant to meet and they do not.
const a2 = s.along || [1, 0], L2 = Math.max(1e-6, Math.hypot(a2[0], a2[1]));
const ux = a2[0] / L2, uy = a2[1] / L2, nx = -uy, ny = ux;
const len = Math.max(7, Math.min(26, perM * 0.16)), rad = len * 0.30;
const put2 = (px2, py2) => [q[0] + ux * px2 + nx * py2, q[1] + uy * px2 + ny * py2];
ctx.lineWidth = Math.max(0.8, fine * 0.7); ctx.strokeStyle = INK; ctx.fillStyle = SHEET ? '#f3f5f8' : '#10151d';
ctx.beginPath();
if (s.male) { const a = put2(0, -rad), b = put2(len * 0.75, -rad * 0.55), c2 = put2(len * 0.75, rad * 0.55), d2 = put2(0, rad);
ctx.moveTo(a[0], a[1]); ctx.lineTo(b[0], b[1]); ctx.lineTo(c2[0], c2[1]); ctx.lineTo(d2[0], d2[1]); ctx.closePath(); }
else { const a = put2(0, -rad), b = put2(-len * 0.8, -rad), c2 = put2(-len * 0.8, rad), d2 = put2(0, rad);
ctx.moveTo(a[0], a[1]); ctx.lineTo(b[0], b[1]); ctx.lineTo(c2[0], c2[1]); ctx.lineTo(d2[0], d2[1]); ctx.closePath(); }
ctx.fill(); ctx.stroke();
{ const e = s.male ? put2(len * 0.3, 0) : put2(-len * 0.45, 0), f = s.male ? put2(len * 0.3, 0) : put2(-len * 0.45, 0);
ctx.beginPath(); ctx.moveTo(e[0] + nx * rad, e[1] + ny * rad); ctx.lineTo(f[0] - nx * rad, f[1] - ny * rad);
ctx.lineWidth = Math.max(0.8, fine * 0.5); ctx.strokeStyle = SHAPE_EDGE; ctx.stroke(); }
continue; }
if (s.role === 'mate') { const q = S(s.pts[0]);
if (q[0] < -20 || q[0] > innerWidth + 20 || q[1] < -20 || q[1] > innerHeight + 20) continue;
// WHERE RED BECOMES BLACK: the mated pair, as a small lozenge across the cable, so a reader can
// see that two leads meet here rather than one cable changing its mind about its colour.
const a2 = s.along || [1, 0], L2 = Math.max(1e-6, Math.hypot(a2[0], a2[1]));
const ux = a2[0] / L2, uy = -a2[1] / L2, r2 = Math.max(2.6, Math.min(7, perM * 0.035)), r3 = r2 * 0.5;
ctx.beginPath();
ctx.moveTo(q[0] + ux * r2, q[1] + uy * r2); ctx.lineTo(q[0] - uy * r3, q[1] + ux * r3);
ctx.lineTo(q[0] - ux * r2, q[1] - uy * r2); ctx.lineTo(q[0] + uy * r3, q[1] - ux * r3);
ctx.closePath(); ctx.fillStyle = SHEET ? '#f3f5f8' : '#0a0d13'; ctx.fill();
ctx.lineWidth = Math.max(0.8, fine * 0.8); ctx.strokeStyle = INK; ctx.stroke(); continue; }
if (s.role === 'slack') { if (!onScreen(s.pts)) continue;
path(s.pts); ctx.lineWidth = fine + 0.9; ctx.strokeStyle = SHAPE_EDGE; ctx.stroke();
path(s.pts); ctx.lineWidth = fine; ctx.strokeStyle = SHAPE_BLACK; ctx.stroke(); continue; }
if (s.role === 'joint' && perM > 18) { const p = S(s.pts[0]);
if (p[0] < -20 || p[0] > innerWidth + 20) continue;
ctx.beginPath(); ctx.arc(p[0], p[1], 1.7, 0, 6.2832); ctx.fillStyle = '#0a0d13'; ctx.fill();
ctx.lineWidth = hair; ctx.strokeStyle = SHAPE_INK; ctx.stroke(); } }
// 5. THE MARKS: - and + beside every box and terminal, and the module's name under it, on whole pixels
// WORDS ARE DROPPED, NEVER OVERLAPPED. The polarity marks and the module names go down first, then
// the numbers on the links, nearest the near end first; anything that would land on something already
// written is simply not written. A crowded drawing loses labels; it never turns into a smear.
ctx.textBaseline = 'middle';
const placed = [];
const order2 = D.marks.map((m, i) => [m, i]).sort((a, b) => ((a[0].rank || 0) - (b[0].rank || 0)) || (a[0].x - b[0].x));
// NO WORD IS EVER SHRUNK. Nine pixels is the floor for a word on this drawing: under it the word is
// not written at all. The MACRO words - M1, M10, M20, M30 and the inverter - are the only ones
// written when the whole string is on the screen, and they fade out as the near names fade in, so
// pinching from one view to the other is a change of what is worth saying and not a flicker.
const MACRO_OFF = 46;
// A WORD IS PAINTED IN THE GLASS'S OWN PIXELS. The rest of the drawing is laid out in css px on a
// layer scaled by the device ratio, which is right for a line: a hairline stays a hairline. A word is
// not a line. A word has one true size - the size it arrives at the eye - and that size is counted in
// the pixels the panel actually has. So for the marks alone the layer's scale is dropped, the word is
// asked for at its css size times the device ratio, and it lands where it would have landed anyway.
// The floor is then the floor the reader sees: NINE CSS PIXELS, in this one place, and under it the
// word is not written at all. Dropped, never shrunk - a word too small to read is worse than none.
const TEXT_FLOOR_PX = 9;
ctx.setTransform(1, 0, 0, 1, 0, 0);
for (const [m] of order2) {
const sizeCss = m.size || 11;
if (sizeCss < TEXT_FLOOR_PX) continue;
if (m.macro) { if (perM > MACRO_OFF) continue; }
else if (perM < (m.minPx || 0)) continue;
const p = S([m.x, m.y]); if (p[0] < -40 || p[0] > innerWidth + 40 || p[1] < -20 || p[1] > innerHeight + 20) continue;
ctx.globalAlpha = m.macro ? Math.max(0, Math.min(1, (MACRO_OFF - perM) / 12)) : 1;
ctx.font = '600 ' + (sizeCss * dpr) + 'px ui-monospace,Menlo,Consolas,monospace';
const px = Math.round(p[0] * dpr), py = Math.round(p[1] * dpr);
const w2 = ctx.measureText(m.text).width, h2 = (sizeCss + 3) * dpr;
const x0 = px - (m.mid ? w2 / 2 : 0), y0 = py - h2 / 2;
const box2 = [x0 - dpr, y0, x0 + w2 + dpr, y0 + h2];
if (m.dodge) { let clash = false;
for (const q of placed) if (box2[0] < q[2] && box2[2] > q[0] && box2[1] < q[3] && box2[3] > q[1]) { clash = true; break; }
if (clash) continue; }
placed.push(box2);
ctx.textAlign = m.mid ? 'center' : 'left';
ctx.fillStyle = SHEET ? (m.colour === SHAPE_RED ? '#b3271a' : m.colour === SHAPE_WARN ? '#8a6100' : '#10151c') : m.colour;
ctx.fillText(m.text, px, py); }
ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
ctx.globalAlpha = 1;
ctx.textAlign = 'left'; ctx.textBaseline = 'alphabetic';
ctx.restore();
}
// ---- what the pointer is over -----------------------------------------------------------------
// A HOVER OR A TAP LIGHTS ONE WHOLE LINK AND NAMES IT. It never takes the pointer: this layer has no
// pointer events at all, the window listens, and the shell's own tap on a dot is untouched.
function shapeAsk(px0, py0){
const D = sldShapes; if (!D) return null;
let best = null, bd = 14;
for (const s of D.shapes) { if (!s.hit || !s.pts || s.pts.length < 2) continue;
const pts = s.pts.map(shapePoint);
for (let i = 1; i < pts.length; i++) { const a = pts[i-1], b = pts[i];
const dx = b[0] - a[0], dy = b[1] - a[1], L = dx*dx + dy*dy;
let t = L > 0 ? ((px0 - a[0]) * dx + (py0 - a[1]) * dy) / L : 0; t = Math.max(0, Math.min(1, t));
const d = Math.hypot(px0 - (a[0] + t*dx), py0 - (a[1] + t*dy));
if (d < bd) { bd = d; best = s; } } }
return best;
}
function shapeTrack(e){
if (!sldShapes || !body || !body.sld || !body.shown || bodyAnim) { if (shapeHover) { shapeHover = null; dirty = true; } return; }
const s = shapeAsk(e.clientX, e.clientY), node = s ? s.node : null;
if (node === shapeHover) return;
shapeHover = node; sldShapes.saying = s ? s.says : null; dirty = true; placeSldNames();
}
addEventListener('pointermove', shapeTrack, { passive:true });
addEventListener('pointerdown', shapeTrack, { passive:true });
// AFTER EVERY FRAME THE SHELL DRAWS, not on a loop of this file's own and not on a guessed list of
// events: the shell says it has drawn, and the words and the drawing are put where the dots are.
try { if (window.__wafer && window.__wafer.onDraw) window.__wafer.onDraw.add(function(){ try { stringClampMicro(); placeSldNames(); drawSldShapes(); } catch (_) {} }); } catch (_) {}
// ===== ANY RADIAL NETWORK, DRAWN BY THE DOTS: fire network {"seed":N} ==========================
// The generator's network (a star, a chain, a tree, sub-boards) laid out as a single line diagram: the busbar on top, every
// substation in its own column, a branch leaving its parent's tee sideways and then down, so no two lines ever share a place.
function netPieces(net){
const P = [], subs = net.subs, n = subs.length, kids = {}; subs.forEach(s => (kids[s.parent] = kids[s.parent] || []).push(s.n));
const col = {}, depth = {}; let c = 0;
(function walk(p, d){ for (const k of (kids[p] || [])) { col[k] = c++; depth[k] = d; walk(k, d + 1); } })(0, 1);
const maxD = Math.max(...Object.values(depth)), dy = Math.min(0.17, 1.05 / maxD), X = k => n === 1 ? 0 : -0.9 + 1.8 * col[k] / (n - 1), Y = k => 0.37 - dy * (depth[k] - 1) - 0.05;
const line = (tag, d, x0, y0, x1, y1) => { const len = Math.hypot(x1 - x0, y1 - y0); if (len > 1e-6) P.push({ tag, d, kind:'line', x0, y0, x1, y1, len }); return d + len; };
const ring = (tag, d, cx, cy, r) => P.push({ tag, d, kind:'ring', cx, cy, r, len:2 * Math.PI * r });
ring('grid', 0, 0, 0.9, 0.06); let d0 = line('poc', 0.06, 0, 0.83, 0, 0.66); line('poc', d0, -0.06, 0.65, 0.06, 0.65); d0 = line('board', d0, 0, 0.63, 0, 0.45);
line('bus', d0, -0.95, 0.43, 0.95, 0.43); line('bus', d0, -0.95, 0.405, 0.95, 0.405);
const teeD = { 0: d0 };
const sym = (tagT, tagL, tagP, d, x, y, s, r) => { // transformer, load and any solar, hanging from (x, y)
let dd = line(tagT, d, x, y - 0.012, x, y - 0.04); ring(tagT, dd, x, y - 0.04 - r, r); ring(tagT, dd + 0.05, x, y - 0.04 - 3 * r - 0.012, r);
const yl = y - 0.04 - 4 * r - 0.024; dd = line(tagT, dd + 0.1, x, yl, x, yl - 0.05);
line(tagL, dd, x - 0.03, yl - 0.06, x, yl - 0.105); line(tagL, dd, x + 0.03, yl - 0.06, x, yl - 0.105);
if (s.pv_kw > 0) { const sx = x + 0.06; line(tagP, dd, x + 0.012, yl - 0.025, sx - 0.03, yl - 0.025); ring(tagP, dd + 0.05, sx, yl - 0.025, 0.026); ring(tagP, dd + 0.05, sx, yl - 0.025, 0.009); }
if (net.generator_at === s.n && net.generator_kw > 0) { const gx = x - 0.06; line('gen', dd, x - 0.012, yl - 0.025, gx + 0.03, yl - 0.025); ring('gen', dd + 0.05, gx, yl - 0.025, 0.028); } };
if (net.generator_at === 0 && net.generator_kw > 0) { line('gen', d0, -0.75, 0.455, -0.75, 0.56); ring('gen', d0 + 0.15, -0.75, 0.62, 0.06); }
const r = Math.min(0.032, 0.6 / n / 2.4 + 0.012);
(function walk(p){ for (const k of (kids[p] || [])) { const s = subs[k - 1], x = X(k), y = Y(k), t = 'hv' + k; let d;
if (p === 0) d = line(t, teeD[0] + Math.abs(x), x, 0.393, x, y);
else { d = line(t, teeD[p], X(p) + 0.012, Y(p), x, Y(p)); d = line(t, d, x, Y(p) - 0.012, x, y); }
teeD[k] = d; sym('tx' + k, 'load' + k, 'pv' + k, d, x, y, s, r); walk(k); } })(0);
let far = 0; for (const p of P) far = Math.max(far, p.kind === 'ring' ? Math.hypot(p.cx, p.cy) + p.r : Math.max(Math.hypot(p.x0, p.y0), Math.hypot(p.x1, p.y1)));
const k = 0.98 / Math.max(0.98, far); // the whole drawing inside the disc
for (const p of P) { if (p.kind === 'ring') { p.cx *= k; p.cy *= k; p.r *= k; } else { p.x0 *= k; p.y0 *= k; p.x1 *= k; p.y1 *= k; } p.len *= k; }
return P;
}
function netFinal(model, tag){
const net = model.net, r = model.solved, e = r.each, c = window.FIRE.topo.C, over = Math.max(0, -r.p) > net.export_limit_kw, aMax = Math.max(1e-9, r.amps);
const bad = v => v > c.volts_high_pu || v < c.volts_low_pu;
return tag.map(t => { if (t === 'grid') return 0.95; if (t === 'poc') return over ? 2 : 0.95; if (t === 'board') return 0.9; if (t === 'bus') return bad(e.volts.board) ? 2 : 0.95;
if (t === 'gen') return model.inputs.generator ? 1 : -1;
const k = t.replace(/\D/g, '');
if (t.startsWith('pv')) return (model.inputs.solar === undefined ? 1 : model.inputs.solar) > 0 ? 1 : -1;
if (t.startsWith('load')) return bad(e.volts['lv' + k]) ? 2 : 0.85;
if (t.startsWith('tx')) return e.tx['lv' + k] > 100 ? 2 : 0.3 + 0.65 * Math.min(1, e.tx['lv' + k] / 100);
return bad(e.volts['hv' + k]) ? 2 : 0.3 + 0.65 * Math.min(1, e.amps['hv' + k] / aMax); });
}
// ===== THE POINTER IS ALWAYS LET GO ==============================================================
// THE FAULT: the shell answers a tap on body dot j with commits[iso.idx[j]] and calls pointerGone(e)
// AFTERWARDS. A drawn diagram has 896 dots and an application has however many pieces of work it has,
// so for most dots iso.idx[j] was undefined, reading .k0 of undefined threw, pointerGone never ran,
// the pointer stayed in the map and the disc went on following a mouse whose button was up. The cure
// above gives every diagram dot its own piece of work, so nothing throws. THIS is the second belt:
// whatever any handler does, the pointer is let go. A listener added here runs AFTER the shell's own
// (they are on the same target in the same phase, and an exception in one listener never stops the
// next), so a throw anywhere in the shell's answer can no longer leave a button pressed for ever.
// It is registered from a timer so that it is registered after the shell's, whatever the load order.
setTimeout(function(){
var net = function(e){ try { if (typeof pointerGone === 'function') pointerGone(e); } catch (_) {} };
addEventListener('pointerup', net);
addEventListener('pointercancel', net);
addEventListener('pointerout', function(e){ if (e.pointerType === 'mouse' && !e.relatedTarget && e.buttons === 0) net(e); });
addEventListener('blur', function(){ try { if (typeof pts !== 'undefined' && pts.clear) pts.clear();
if (typeof drag !== 'undefined') drag = null; if (typeof pinch !== 'undefined') pinch = null; } catch (_) {} });
}, 0);Kuiper Grid — I0091 Page
A web page in GlobalGrid2050 that uses SHA-256. Published at https://globalgrid2050.com/kuiper-grid/i0091/. It is built from the must step (`must`), the attr step (`attr`) and the sha256 step (`sha256`).
Set aside from the main view: 98% of its lines are the same as kuiper-grid/i0073/index.html (globalgrid2050), which stays. (near-copy-of, proposed by families.py). 98% of lines shared with Kuiper Grid — I0097 Page; read that one first. All set-aside files, with reasons. Nothing was deleted.
Evidence
- line-jaccard 0.9802 to globalgrid2050@0aca5121f0795e469b6cf4fc3d3b628edba8d883 kuiper-grid/i0073/index.html:1-108 073cc692d3750aac95d1654f9a0b315d2b568d11
- sha256 edbbc603db74d94d88942252ef57818dda0acc446f730e216d10a39bf259b1c2
- target sha256 fb96bcf6b8a812967bfc0fc386a3d015e90f507f76ce774101a57ea29aba253a
- group of 16 (identity.json near-copy edges >= 0.9)
- canonical rule: reachable, newest stamp, core repo, most lines
- re-pointed by apply.py version rule from file 3650 to file 3695; similarity was measured to file 3650
renderglobalgrid2050 / kuiper-grid/i0091/index.html · lines 1–108 of 108 · Entry point
- What it does
- It draws its content. Defines must, attr, sha256. Uses libraries …/NAME, ' + attr(url.href) + '. Side effects: changes the web page (DOM); makes network requests.
- Why it exists in the grid workflow
- Domain stage agent_infra (path word 'kuiper'): AI-agent memory, coordination and code audit (the multi-agent journey named in Ventus Ltd's brief).
- Inputs & outputs
- In: JSON file current.json. Out: web page.
- Downstream impact
- Used directly by 1 file: GlobalGrid2050 — Kuiper Grid Page (globalgrid2050, https://globalgrid2050.com/kuiper-grid/). Reached from 108 other entry points, including GlobalGrid2050 Historical Builds (globalgrid2050, https://globalgrid2050.com/historical_builds.html); GlobalGrid2050 Homepage Before Four Nests (globalgrid2050, https://globalgrid2050.com/homepage-before-four-nests-20260925.html); GlobalGrid2050 — Compute Page (globalgrid2050, https://globalgrid2050.com/compute/). It is itself an entry point, published at https://globalgrid2050.com/kuiper-grid/i0091/.
- What it achieves
- THE WAY OUT. This page is a composer: with script off, or with a refused record, it renders nothing a reader can click. It reads `./current.json`.
- Why it matters
- Loaded by the Kuiper Grid page at https://globalgrid2050.com/kuiper-grid/.
- Application
- globalgrid2050 · kuiper-grid/i0091 · page
- Uses
- Manual (link), GlobalGrid2050 — Plant Page (link), GlobalGrid2050 — Kuiper Grid Page (link), GlobalGrid2050 — Compute Page (link), …/NAME, ' + attr(url.href) + '
- Used by
- linked from GlobalGrid2050 — Kuiper Grid Page (link)
- Produces
- must, attr, sha256
- Defines here
- must, attr, sha256
- Cannot conclude
- Whether this code runs, is used by a live app today, or is correct. This is a static reading.
- Evidence
- globalgrid2050@0aca5121f0795e469b6cf4fc3d3b628edba8d883 kuiper-grid/i0091/index.html:1-108 · blob a53c5e2f8281a5593ae378faeec30e802d745af1 · GitHub at these lines
- State
- achieves: comment · context: readme_derived · stage: output · effects: dom, network · domain stage: agent_infra · users: ai_agent · canonical: production_core
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>globalgrid2050</title>
<style>
html,body{margin:0;background:#0b0d12;color:#d8dee9;font:13px/1.5 ui-monospace,Menlo,Consolas,monospace}
#composer{display:grid;place-items:center;min-height:50vh;padding:24px;text-align:center}
#composer strong{color:#5ec8f2;letter-spacing:.1em}
#composer small{color:#8b93a7}
#waysout{max-width:44rem;margin:0 auto;padding:0 20px 40px;border-top:1px solid #1b2030}
#waysout h2{font-size:14px;color:#5ec8f2;letter-spacing:.06em;text-transform:uppercase;margin:24px 0 8px}
#waysout p{color:#8b93a7;margin:8px 0}
#waysout ul{margin:10px 0;padding-left:1.1rem}
#waysout li{margin:7px 0;color:#8b93a7}
#waysout a{color:#5ec8f2;font-weight:600}
#waysout .small{font-size:12px;color:#6f7789}
</style>
</head>
<body data-composer="loading">
<main id="composer"><div><strong>GLOBALGRID2050</strong><br>checking this page against its record…<br><small>provided as is, without warranty of any kind; a chart, not a design</small></div></main>
<!-- THE WAY OUT. This page is a composer: with script off, or with a refused
record, it renders nothing a reader can click. Plain anchors, in the
served bytes, so this build is never a dead end. -->
<nav id="waysout">
<h2>Build i0091 — part of the Kuiper</h2>
<p>This address loads one development build. If it has not loaded, or you have script switched off, start from the plain pages:</p>
<ul>
<li><a href="/kuiper-grid/manual.html">The manual</a> — what this is, what to type, what the answer means, and what it refuses</li>
<li><a href="/plant/">Will this string go over 1500 V on the coldest morning?</a> — three commands ready to copy</li>
<li><a href="/kuiper-grid/">All development builds</a></li>
<li><a href="/compute/">Independent compute</a> · <a href="/">Everything else published here</a></li>
</ul>
<p class="small">A development build. Two of the four limits this engine measures a design against have no source in any document, and a verdict that turns on one of them is provisional. <a href="/kuiper-grid/manual.html#unsourced">The manual says which.</a></p>
<p class="small">A chart, not a design. Not a connection offer, not a constructability assessment, not a consenting design. No output of it is engineering.</p>
</nav>
<script type="module">
// THE COMPOSER. GridAtlas's pattern as it stands (gridatlas/atlas/index.html): one frozen shell, features as hashed
// cartridges, and current.json, the pointer, saying which. This page is the ONE ADDRESS that never changes. It reads
// the pointer, fetches the shell, fetches every cartridge the pointer names, and lets a cartridge in ONLY if its
// bytes hash to what the pointer says. A release is a change to the pointer; a rollback is the pointer put back;
// the shell is never edited. If anything does not match, nothing runs and the page says so in plain words.
//
// Two slots: replace-script the shell's <script src="…/NAME"> is pointed at the cartridge instead
// import-map an import of NAME anywhere in the shell resolves to the cartridge instead
// A cartridge is ONE file with no imports of its own neighbours: one file, one job.
const CLOSE = '</scr' + 'ipt>';
const box = document.getElementById('composer');
const must = (ok, why) => { if (!ok) throw new Error(why); };
const attr = v => String(v).replace(/&/g, '&').replace(/"/g, '"').replace(/</g, '<');
const sha256 = async bytes => [...new Uint8Array(await crypto.subtle.digest('SHA-256', bytes))].map(b => b.toString(16).padStart(2, '0')).join('');
try {
const r = await fetch('./current.json', { cache: 'no-store' });
must(r.ok, 'the record of this page could not be read (' + r.status + ')');
const cur = await r.json();
must(cur && cur.schema === 'globalgrid.current.v1', 'the record of this page is in a form this page does not know');
must(cur.architecture === 'IMMUTABLE_SHELL_PLUS_HASHED_CARTRIDGES', 'the record of this page names another architecture');
must(Array.isArray(cur.cartridge_order) && Array.isArray(cur.cartridges) && cur.shell, 'the record of this page is incomplete');
const shellUrl = new URL(cur.shell.index, location.href), shellBase = new URL(cur.shell.base, location.href).href;
const sr = await fetch(shellUrl, { cache: 'no-store' });
must(sr.ok, 'the page itself could not be fetched (' + sr.status + ')');
const shellBytes = await sr.arrayBuffer();
must(await sha256(shellBytes) === cur.shell.sha256, 'the page itself is not the one that was released');
let html = new TextDecoder('utf-8').decode(shellBytes);
must(/<head\b/i.test(html) && /<body\b/i.test(html), 'the page itself is not a page');
const byId = new Map(cur.cartridges.map(c => [c.id, c])), loaded = [], imports = {};
const tags = new RegExp('<script\\b([^>]*)\\bsrc=(["\'])([^"\']+)\\2([^>]*)>\\s*<\\/script>', 'gi');
for (const id of cur.cartridge_order) {
const c = byId.get(id);
must(c, 'a part named in the record is missing from it: ' + id);
must(/^[a-f0-9]{64}$/.test(c.sha256 || ''), id + ': the record holds no fingerprint for it');
must(c.slot === 'replace-script' || c.slot === 'import-map', id + ': a slot this page does not have');
must(typeof c.replaces === 'string' && c.replaces, id + ': the record does not say what it replaces');
const url = new URL(c.path, location.href);
const cr = await fetch(url, { cache: 'no-store' });
must(cr.ok, id + ' could not be fetched (' + cr.status + ')');
must(await sha256(await cr.arrayBuffer()) === c.sha256, id + ' is not the file that was released');
if (c.slot === 'import-map') imports[new URL(c.replaces, shellBase).href] = url.href;
else {
let done = false;
html = html.replace(tags, (full, a, q, src, b) => {
if (done || String(src).split(/[?#]/)[0].split('/').pop() !== c.replaces) return full; // matched by file name
done = true;
return '<script' + a + 'data-cartridge="' + attr(id) + '" src="' + attr(url.href) + '"' + b + '>' + CLOSE;
});
must(done, id + ': the page has no place for it (' + c.replaces + ')');
}
loaded.push({ id, generation: c.generation, sha256: c.sha256 });
}
const state = JSON.stringify({ schema: cur.schema, generation: cur.generation, shell: cur.shell, cartridges: loaded }).replace(/</g, '\\u003c');
const head = '\n<base href="' + attr(shellBase) + '">'
+ (Object.keys(imports).length ? '\n<script type="importmap">' + JSON.stringify({ imports }).replace(/</g, '\\u003c') + CLOSE : '')
+ '\n<script>window.__COMPOSED__=' + state + ';document.documentElement.dataset.generation=' + JSON.stringify(cur.generation) + ';' + CLOSE;
html = html.replace(/<head([^>]*)>/i, m => m + head);
document.open(); document.write(html); document.close();
} catch (e) {
console.error('[composer]', e);
document.body.dataset.composer = 'refused';
box.innerHTML = '<div><strong>THIS PAGE DID NOT OPEN</strong><br>' + String(e && e.message || e).replace(/[<>&]/g, '')
+ '<br><small>Nothing was run. The released page has not been changed. The plain pages below still work.<br>provided as is, without warranty of any kind; a chart, not a design</small></div>';
}
</script>
</body>
</html>Kuiper Programs
A JavaScript module in the cartridges folder of GlobalGrid2050 covering cables, solar, substations and transformers, using IEC 62446-1 and SHA-256, and uses data from the faraday repository.
Set aside from the main view: 96% of its lines are the same as kuiper-grid/drawing/kuiper-programs.js (globalgrid2050), which stays. (near-copy-of, proposed by families.py). 95% of lines shared with Kuiper Programs; read that one first. All set-aside files, with reasons. Nothing was deleted.
Evidence
- line-jaccard 0.9581 to globalgrid2050@0aca5121f0795e469b6cf4fc3d3b628edba8d883 kuiper-grid/drawing/kuiper-programs.js:1-4071 1702c188389e3667e255bb51ecb3b75e61fe14a0
- sha256 5ef6d7a83db25ee53d8d90e936e2cc85e828ca4767ffbb7a21333711649c55c2
- target sha256 b62e9418bc019fbd2c39144827ac5bf415cb0b57d8ced8cd973d196e0e20144b
- group of 8 (identity.json near-copy edges >= 0.9)
- canonical rule: reachable, newest stamp, core repo, most lines
renderglobalgrid2050 / kuiper-grid/i0092/cartridges/009200000000-kuiper-programs.js · lines 1–367 of 3948 · Not reached from any entry point (candidate for review) · pattern needSize (shared by 9 files)
- What it does
- It draws cables, solar, substations and transformers. Defines 205 functions or classes, including reFire, closestPair, blackSky, nameInLines, makeBody. Side effects: changes the web page (DOM); reads or writes files; makes network requests.
- Why it exists in the grid workflow
- Domain stage agent_infra (path word 'kuiper'): AI-agent memory, coordination and code audit (the multi-agent journey named in Ventus Ltd's brief). Domain terms in the code: cables, solar, substations, transformers, 400kV, 1500V.
- Inputs & outputs
- In: data source: faraday data; JSON file current.json. Out: canvas drawing. Voltage levels named: 400kV, 1500V.
- What it achieves
- It makes body (`makeBody`), sets tag (`setTag`) and merges menu (`mergeMenu`). A cartridge of the Kuiper shell. Its code works with 352 kVA, 295 kVA and 320 kVA. It responds to click, keydown and pointerdown events.
- Why it matters
- No other file in the estate was found to import it.
- Application
- globalgrid2050 · kuiper-grid/i0092/cartridges · JavaScript module
- Uses
- Faraday — Index Page (estate URL), Wafer Development Environment — Proof S0004 Page (estate URL), ./fire.js
- Used by
- mentioned in Standalone (comment link)
- Produces
- reFire, closestPair, blackSky, nameInLines, makeBody, bodyTo, labels, bodyJump, bodyMove, bodyDrawnDiameter, bodyDotPx, sheet
- Defines here
- reFire, closestPair, blackSky, nameInLines, makeBody, bodyTo, labels, bodyJump, bodyMove, bodyDrawnDiameter, bodyDotPx, sheet, setTag, revealCode, sparksTo, ensureGlow, mergeMenu, makeAppButtons, isolateNow, isolate, raiseTile, endIsolate, unisolate, appCard, closeCard, codeWindow, lh, padTop, place, rate
- Cannot conclude
- Whether this code runs, is used by a live app today, or is correct. This is a static reading.
- Evidence
- globalgrid2050@0aca5121f0795e469b6cf4fc3d3b628edba8d883 kuiper-grid/i0092/cartridges/009200000000-kuiper-programs.js:1-367 · blob 7a6975d16582613226c69ad98d250b68f26a61ec · GitHub at these lines
- State
- achieves: comment · context: readme_derived · stage: output · effects: dom, filesystem, network · domain stage: agent_infra · users: ai_agent · canonical: unreached_review
'use strict';
// kuiper-programs.js - a cartridge of the Kuiper shell. Cut from the whole page with no change of behaviour;
// replaced, when it is, by a newer file the pointer names and the composer checks by its hash.
let ASM = null, gatherAnim = null, homeAnim = null;
// the live answer window and the way back to a preset: declared here because the bar is built long
// before the part of this file that uses them has run
let fireLive = null, fireAgain = null;
// CHANGE ONE INPUT AND FIRE AGAIN, keeping everything else the reader has set. The view buttons use it.
function reFire(extra){
if (!fireLive || !fireLive.boxes) return;
Object.assign(fireLive.boxes.vals, extra);
fireCommand(fireLive.boxes.cmd(), fireLive.rec, true);
}
// ===== THE BODY: a smaller Kuiper of one application's own work =====================================
let body = null, bodyAnim = null, BP = null, bodyBuf = null;
// THE PALETTE OF THE ONE PULSE. The ring that sweeps the disc is white and ice blue; what it leaves lit is
// the same light, at full brightness. No second look: the saturated green was one, and it is gone.
const FARADAY = [0.80, 0.96, 1.0];
// THE BODY FILLS THE INNER DISC, so a third of the gap is a bigger dot and the body reads from across a
// room without a single dot breaking the rule that makes it a population and not a patch.
const BODY_RADIUS = 0.55, BODY_RADIUS_MAX = 0.92, DOT_MAX_PX = 5, DOT_MIN_PX = 1.0;
const VS_BODY = `#version 300 es
precision highp float;
in vec2 a_pos; uniform float u_zoom, u_size, u_sld; uniform vec2 u_center, u_res; uniform vec4 u_val[224]; out float v_val;
void main(){ gl_Position = vec4((a_pos - u_center) * u_zoom / (0.5*u_res), 0.0, 1.0); gl_PointSize = u_size;
int i = min(gl_VertexID, 895); v_val = u_sld > 0.5 ? u_val[i >> 2][i & 3] : 1.0; }`;
// A DOT IS A DISC WITH A HARD EDGE, AND IT IS NOT ADDED TO WHAT IS UNDER IT. Light that adds is how
// neighbours merge into a white patch; here a dot covers what it covers and nothing more.
const FS_BODY = `#version 300 es
precision highp float; uniform vec3 u_on; uniform float u_sld; in float v_val; out vec4 o;
// A DIAGRAM'S DOT CARRIES A VALUE: under 0 disconnected, 0 to 1 how bright, about 1.25 the front of a pulse, 2 over a limit.
void main(){ if (length(gl_PointCoord - 0.5) > 0.5) discard; vec3 c = u_on;
if (u_sld > 0.5 && v_val < -1.5) discard; // melted away: a solid shapes drawing keeps no loose dots
if (u_sld > 0.5) { c = v_val < 0.0 ? vec3(0.09, 0.12, 0.15) : v_val > 1.6 ? vec3(1.0, 0.62, 0.15) : v_val > 1.1 ? vec3(1.0) : mix(vec3(0.10, 0.16, 0.20), u_on, v_val); }
o = vec4(c, 1.0); }`;
// THE GAP, MEASURED. The nearest two centres among the places the module returned, found with a grid
// so a large application costs no more than a small one. Nothing here is judged by eye.
function closestPair(pos){
const m = pos.length / 2; if (m < 2) return Infinity;
let x0 = 1e300, x1 = -1e300, y0 = 1e300, y1 = -1e300;
for (let q = 0; q < pos.length; q += 2) { x0 = Math.min(x0, pos[q]); x1 = Math.max(x1, pos[q]); y0 = Math.min(y0, pos[q+1]); y1 = Math.max(y1, pos[q+1]); }
const cell = Math.max(1e-9, Math.sqrt(Math.max(1e-18, (x1 - x0) * (y1 - y0)) / m)), grid = new Map();
let best = Infinity;
for (let j = 0; j < m; j++) { const gx = Math.floor((pos[2*j] - x0) / cell), gy = Math.floor((pos[2*j+1] - y0) / cell);
for (let dx = -1; dx <= 1; dx++) for (let dy = -1; dy <= 1; dy++) { const cellm = grid.get((gx + dx) + ':' + (gy + dy)); if (!cellm) continue;
for (const k of cellm) { const d = Math.hypot(pos[2*j] - pos[2*k], pos[2*j+1] - pos[2*k+1]); if (d < best) best = d; } }
const key = gx + ':' + gy; (grid.get(key) || grid.set(key, []).get(key)).push(j); }
return best;
}
// THE BLACK SKY RULE, as one question any body can be asked: are all centres at least three dot radii
// apart? It is the same function the page obeys and the test plants a too tight body against.
function blackSky(pos, dotRadius){ const gap = closestPair(pos); return { gap, dotRadius, ok: gap >= 3 * dotRadius * (1 - 1e-4) }; } // exactly a third is allowed; the margin is for rounding, not for squeezing
function nameInLines(words){ const w = String(words).split(' '); if (String(words).length <= 9 || w.length < 2) return String(words);
const half = Math.ceil(w.length / 2); return w.slice(0, half).join(' ') + ' / ' + w.slice(half).join(' '); }
function makeBody(st){
if (!ASM || !st.idx.length) return null;
if (st.prog.sld) { const d = makeSldBody(st); if (d) return d; }
const seq = (st.prog.on.sequence && st.prog.on.sequence.length) ? st.prog.on.sequence : (st.prog.on.shape ? [{ shape:st.prog.on.shape }] : []);
if (!seq.length) return null;
const m = st.idx.length, R = Math.sqrt(SPACE), from = new Float32Array(2 * m);
// ONE DOT FOR EVERY PIECE OF WORK, IN ORDER OF KEY: the module puts dot j at place j, and place 0 is
// the middle, so the oldest work is the middle of the small Kuiper and the newest is its rim.
st.idx.forEach((ci, j) => { const c0 = commits[ci], p = keyPlace(c0.k0 + Math.floor((c0.k1 - c0.k0) / 2)); from[2*j] = p[0]; from[2*j+1] = p[1]; });
// THE SIZE THE SHOW WILL REALLY BE SEEN AT. On a phone the short tile rises under the picture and the
// disc is refitted smaller above it, so what resolves is decided for THAT size, not for the empty screen.
const zHome = homeCamera().z * (narrow() ? 0.62 : 1), states = [];
for (const step of seq) { const shape = step.shape === 'text' ? 'text:' + nameInLines(st.app.button) : step.shape;
// A NAME NEEDS ENOUGH DOTS TO BE A NAME: about six to a letter. Nine pieces of work cannot spell
// two words, and a scatter that means nothing is worse than the small Kuiper it would replace.
// A NAME ONLY WHEN IT CAN BE READ. A letter is a shape of squares and needs a dot for every one of them;
// with fewer, letters lose strokes (85 pieces of work spelt CABL S). Counted from the module's own
// lettering, not estimated.
if (step.shape === 'text') { const ink = ASM.raster ? ASM.raster(nameInLines(st.app.button)) : null;
const squares = ink ? ink.on.reduce((t, v) => t + v, 0) : 1e9; if (m < squares) continue; }
let unit; try { unit = ASM.targets(shape, m); } catch (e) { continue; }
const unitGap = closestPair(unit);
// large enough that a dot a third of the gap wide is at least a pixel; never larger than the disc
let frac = BODY_RADIUS; const need = DOT_MIN_PX * 3 / Math.max(1e-12, unitGap * R * zHome);
if (need > frac) frac = Math.min(BODY_RADIUS_MAX, need);
const to = new Float32Array(unit.length); for (let q = 0; q < unit.length; q++) to[q] = unit[q] * R * frac;
const gap = unitGap * R * frac;
const unresolved = gap * zHome / 3 < DOT_MIN_PX * 0.999;
// WHAT CANNOT BE RESOLVED IS NOT SHOWN AS IF IT COULD. A state that would need dots under a pixel is
// left out, and the show ends on the last state that does resolve: the work gathers and STAYS, it
// is never simply gone from the middle of the disc, which is what a phone showed.
if (unresolved && states.length) continue;
states.push({ shape, to, gap, frac, hold:step.hold_ms || 0, unresolved }); }
if (!states.length) return null;
return { n:m, from, pos:new Float32Array(from), states, k:-1, gap:0, shown:false };
}
function bodyTo(arr){ if (body) body.live = closestPair(arr);
if (!BP) { BP = prog(VS_BODY, FS_BODY); bodyBuf = gl.createBuffer(); }
gl.bindBuffer(gl.ARRAY_BUFFER, bodyBuf); gl.bufferData(gl.ARRAY_BUFFER, arr, gl.DYNAMIC_DRAW); gl.bindBuffer(gl.ARRAY_BUFFER, null);
sldUniforms(); if (body && body.sld) sldStart(); }
function labels(show){ const o = document.getElementById('o'); if (o) o.style.visibility = show ? 'visible' : 'hidden'; }
function bodyJump(k){ if (!body) return; labels(false); const stt = body.states[k]; body.pos.set(stt.to); body.k = k; body.gap = stt.gap; body.shown = true; bodyAnim = null; bodyTo(body.pos); dirty = true; }
function bodyMove(k){ if (!body) return; labels(false); bodyAnim = { k, t0:performance.now(), from:new Float32Array(body.pos), gap0:body.shown ? body.gap : body.states[k].gap, phase:'move' };
body.shown = true; dirty = true;
// A ROW SEVERAL SCREENS WIDE IS SHOWN WHOLE WHILE THE WORK GATHERS ALONG IT, and only then is the
// reader taken to the near end, where the inverter and the first modules can actually be read.
if (body.sld && sldShapes && sldShapes.kind === 'string') { try { stringWholeView(); } catch (_) {} } }
// the dot's radius ON THE SCREEN, from the measured gap and the zoom of this moment: a third of the
// gap, never more, however the visitor zooms
// THE SIZE FOLLOWS THE CANVAS, NOT THE SCREEN. This canvas is as many pixels as the window is wide, so a
// point size is already in the units the gap is measured in. Multiplying by the screen's pixel ratio
// drew every dot at twice its size on a real screen and at its right size in every test.
function bodyDrawnDiameter(){ return Math.max(1, 2 * bodyDotPx() * (cv.width / Math.max(1, innerWidth))); }
// A THIRD OF THE GAP AS THE DOTS ARE NOW. At rest the gap is the state's own; in flight it is measured
// from where the dots are at that frame, because leaving the rim they are almost on top of one another
// and no resting spacing describes them.
function bodyDotPx(){ const gap = body.sld ? body.sldGap : body.live !== undefined ? body.live : body.gap; // a diagram's dot is sized by the spacing along its lines, where a junction would make every dot a speck // measured every time the dots are placed
// A WIRING DRAWING'S DOTS ARE THE ENTRANCE AND NOTHING MORE, so they are held to a fine weight: on a
// drawing several screens wide the same rule would grow them into discs sitting on top of the words.
const cap = (body.sld && body.fineDots) ? 1.6 : DOT_MAX_PX;
return Math.max(0.5, Math.min(cap, gap * zoom / 3)); }
// BESIDE THE SHELL, NOT BESIDE THIS FILE. Released, this part lives in a folder of parts and the module lives
// beside the shell; a script asks for a module relative to its own address, so './assemble.mjs' asked for a
// file that is not there. The page's base address is the shell's folder, with the composer or without it.
// AND A FAILED LOAD SAYS SO. The catch used to swallow it, and on the live address the dots simply never
// gathered, with nothing on the page or in the console to say why.
let asmWhy = null;
const asmReady = import(new URL('assemble.mjs', document.baseURI).href).then(m => { ASM = m; })
.catch(e => { ASM = null; asmWhy = String(e && e.message || e); console.error('[kuiper] the gathering animation could not be loaded:', asmWhy); });
const GATHER_RADIUS = 0.30; // of the record's own radius: a body, with the dark disc still around it
function sheet(title, sub){
const mine = ++cardToken;
card.classList.remove('short');
card.replaceChildren();
card.style.display = 'block';
card.scrollTop = 0;
const x = el('button', 'cc-x', '\u00d7'); x.type = 'button'; x.setAttribute('aria-label', 'close');
x.addEventListener('click', closeCard);
card.append(x, el('span', 'cc-title', title));
if (sub) card.append(el('span', 'cc-grey', sub));
const tagLine = el('div', 'cc-tagline'), tag = el('span', 'cc-tag'), msg = el('span', 'cc-grey');
tagLine.append(tag, msg); card.append(tagLine);
const body = el('div', 'cc-body'); card.append(body);
// THE SINGLE WRITER OF THE STATE. Nothing else touches the chip, and a writer for a card that has
// been replaced does nothing at all.
const setTag = (st, text) => { if (mine !== cardToken) return false;
tag.dataset.s = st; tag.textContent = st; if (text != null) msg.textContent = text; return true; };
dirty = true;
return { mine, body, setTag, live: () => mine === cardToken };
}
function revealCode(){
const w = cardShown && cardShown.window; if (!w) return;
const cr = card.getBoundingClientRect(), pr = w.node.getBoundingClientRect();
if (pr.bottom > cr.bottom - 4) card.scrollTop += pr.bottom - cr.bottom + 8;
else if (pr.top < cr.top) card.scrollTop -= cr.top - pr.top + 8;
w.scrollToTarget();
}
function sparksTo(arr){ ensureGlow(); gl.bindBuffer(gl.ARRAY_BUFFER, glowBuf);
gl.bufferData(gl.ARRAY_BUFFER, arr, gl.DYNAMIC_DRAW); gl.bindBuffer(gl.ARRAY_BUFFER, null); }
function ensureGlow(){ if (!PG) { PG = prog(VS_GLOW, FS_GLOW); glowBuf = gl.createBuffer(); } }
// ===== ISOLATE AN APPLICATION =================================================================
// ===== THE MENU: BUTTONS ADDED AS DATA =========================================================
// The shell's own buttons come from cosmos/apps.tsv and cosmos/programs.json, which are inside the frozen shell.
// A button added after the shell was frozen is ONE ENTRY HERE: the same two records the shell reads, and nothing
// else. select.repository lights every piece of work of that repository that is on this record.
const MENU = [
{ app: { app:'tests', button:'TESTS', repo:'ventusltd/faraday', prefixes:[], live:'https://ventusltd.github.io/faraday/' },
program: { name:'tests', button:'TESTS', select:{ app:'tests', repository:'faraday' }, pulse:{ origin:'centre', seconds:1.5 }, off:{ dim:0.1 },
on:{ colour:[0.80,0.96,1.0], size:0, bright:0, sparks:1, sequence:[{ shape:'cluster', hold_ms:1500 }, { shape:'text', hold_ms:900 }] },
end:{ tile:'https://ventusltd.github.io/faraday/' },
says:'Every test we have run. Choose a sentence in the bar below and it runs again here, on your device.' } },
// A CORRECTION TO A BUTTON THE SHELL CARRIES. The shell's REAL SYSTEMS row points at a folder two builds old, and its sentence
// ("a single line view of a real system") describes a different page from the one that opens. The work it lights stays the nine
// pieces the frozen record holds for it; that is put right when the record is next cut, not here.
{ override:true,
app: { app:'real-systems', live:'https://globalgrid2050.com/testcode/wafer-development-environment/202609192215-proof-s0004/' },
program: { name:'real-systems', end:{ tile:'https://globalgrid2050.com/testcode/wafer-development-environment/202609192215-proof-s0004/' },
says:'The wafer development environment: every numbered line of the estate, and a box that draws the grid, a substation or a fault study from one sentence.' } }
];
// THE PROGRAM A FIRED COMMAND RUNS: no button of its own and no tile; its shape is the network of the command that fired it.
// It is in the list of programs only for the moment it is started, so the row of buttons and its checks never see it.
const FIRE_PROGRAM = { name:'fire', button:'TESTS', select:{ app:'tests', repository:'faraday' }, pulse:{ origin:'centre', seconds:1.0 }, off:{ dim:0.06 },
on:{ colour:[0.80,0.96,1.0], size:0, bright:0, sparks:0, sequence:[{ shape:'sld', hold_ms:0 }] }, end:{} };
function mergeMenu(){
for (const m of MENU) {
if (m.override) { const a = apps.find(x => x.app === m.app.app), p = programs.find(x => x.name === m.program.name);
if (a) Object.assign(a, m.app); if (p && m.program.end) p.end = m.program.end;
if (a && m.program.says) whatItDoes[a.live] = m.program.says.replace(/\.$/, ''); continue; }
if (!apps.find(x => x.app === m.app.app)) apps.push(m.app);
if (!programs.find(x => x.name === m.program.name)) programs.push(m.program);
if (m.program.says && !whatItDoes[m.app.live]) whatItDoes[m.app.live] = m.program.says.replace(/\.$/, '');
if (!(appWork[m.app.app] || []).length) { const ri = repos.findIndex(r => r.name === m.program.select.repository);
appWork[m.app.app] = ri < 0 ? [] : commits.filter(c => c.repo === ri).map(c => c.sha); }
}
}
function makeAppButtons(){
mergeMenu();
const bar = document.getElementById('apps'); bar.replaceChildren();
for (const pr of programs) { const ap = apps.find(x => x.app === pr.select.app);
if (!ap || !(appWork[ap.app] || []).length) continue; // nothing of it on this record: no button
const b = el('button', null, pr.button); b.type = 'button'; b.setAttribute('data-app', pr.name);
b.addEventListener('click', e => { e.stopPropagation(); isolate(pr.name); }); bar.append(b); }
if (typeof layout === 'function') layout();
makeFireBar();
}
// THE STATE ITSELF, with no animation, so it can be arrived at by a link and asked for by a test.
function isolateNow(name, front){
const asData = programs.find(x => x.name === name); if (!asData) return null;
const prog = Object.assign({}, asData, { on:Object.assign({}, asData.on, { colour:FARADAY }) });
const ap = apps.find(x => x.app === prog.select.app); if (!ap) return null;
name = ap.app;
const idx = []; for (const sha of (appWork[name] || [])) { const i = bySha.get(sha); if (i !== undefined) idx.push(i); }
idx.sort((x, y) => x - y);
litRepo = -1; litK = [-1,-1]; litCi = null; newFrom = -1; flash = 0; litPath = null; target = null; arrow = null;
iso = { app:ap, prog, front:front === undefined ? 1e30 : front, idx, set:new Set(idx), lit:idx.length, dark:commits.length - idx.length,
first:idx.length ? commits[idx[0]].unix : 0, last:idx.length ? commits[idx[idx.length - 1]].unix : 0 };
raiseFlags(idx);
{ // A FEW SPARKS FOR EVERY PIECE OF WORK, spread through its own lines so a big piece of work is a
// scatter around its ring and a small one a point or two. Never more than the program allows.
const per = Math.max(1, Math.min(24, (prog.on.sparks | 0) || 8)), pts = [];
for (const i of idx) { const c0 = commits[i], len = Math.max(1, c0.k1 - c0.k0), take = Math.min(per, len);
for (let j = 0; j < take; j++) { const p = keyPlace(c0.k0 + Math.floor((j + 0.5) * len / take)); pts.push(p[0], p[1]); } }
ensureGlow();
iso.from = new Float32Array(pts); iso.pos = iso.from; iso.to = null;
glowCount = pts.length / 2; iso.sparks = glowCount; sparksTo(iso.from); }
body = makeBody(iso);
// arrived at by a link, or asked for outright: the END of the program, with no waiting
if (front === undefined && body) bodyJump(body.states.length - 1);
for (const b of document.querySelectorAll('#apps button')) b.classList.toggle('on', b.getAttribute('data-app') === prog.name);
if (front === undefined) raiseTile();
dirty = true;
return iso;
}
// PRESS: the pulse runs out through the record, which on this picture is forward through time, and
// where it has passed the rest goes dark. The pulse is the page's own; nothing new is animated.
function isolate(name){
const prog = programs.find(x => x.name === name); if (!prog) return;
closeCard(); { const fc = document.getElementById('firecard'); if (fc && name !== 'fire') fc.style.display = 'none'; } // the answer of a fired command leaves with it
unisolate(true); anim = null; flash = 0; newFrom = -1; target = null; arrow = null;
{ const h = homeCamera(); cx = h.x; cy = h.y; zoom = h.z; tween = null; atHome = true; }
// the selection is made at once and the FRONT starts at the origin with nothing switched; each dot
// switches when the front reaches it, so the darkening is seen to travel
if (!isolateNow(name, 0)) return;
bodyAnim = null; if (body) body.shown = false;
isoAnim = { name, t0:performance.now(), R:Math.sqrt(SPACE), ms:Math.max(200, (prog.pulse.seconds || 1.5) * 1000) }; dirty = true;
}
function raiseTile(){ if (!iso || !(iso.prog.end && iso.prog.end.tile)) return;
appCard(iso); if (atHome) { const h = homeCamera(); flyTo(h.x, h.y, h.z); } dirty = true; }
// ANY OTHER ACTION FIRST ENDS THE ISOLATE. Called by everything that shows something else, before it
// does anything, so the darkening can never outlive the thing it was for.
function endIsolate(){ if (iso || isoAnim || bodyAnim) { unisolate(true); closeCard(); } }
function unisolate(quiet){ labels(true); sldNow = null; sldNames = null; { const el = document.getElementById('sldnames'); if (el) el.replaceChildren(); }
if (typeof shapesGone === 'function') shapesGone();
if (sldLoop) { cancelAnimationFrame(sldLoop); sldLoop = 0; } iso = null; isoAnim = null; gatherAnim = null; homeAnim = null; body = null; bodyAnim = null; pulse = -1;
for (const b of document.querySelectorAll('#apps button')) b.classList.remove('on');
if (!quiet) dirty = true; }
// THE TILE OF AN ISOLATED APPLICATION: its name, what it does for a project, OPEN. Then how much of
// the record is lit and how much has gone dark, because the two must make the whole.
function appCard(st){
cardToken++; cardShown = null; card.replaceChildren(); card.style.display = 'block'; card.scrollTop = 0;
card.classList.add('short');
const x = el('button', 'cc-x', '\u00d7'); x.type = 'button'; x.setAttribute('aria-label', 'close');
x.addEventListener('click', () => { card.style.display = 'none'; dirty = true; });
const t = el('a', 'cc-tile cc-app'); t.href = st.app.live; t.target = '_blank'; t.rel = 'noopener'; t.setAttribute('data-app', st.app.app);
t.append(el('div', 'cc-tile-name', st.app.button));
if (whatItDoes[st.app.live]) t.append(el('div', 'cc-tile-what', whatItDoes[st.app.live] + '.'));
t.append(el('span', 'cc-tile-open', 'OPEN ' + st.app.button));
const brand = el('div', 'scada-brand'), inner = el('div');
inner.append(el('div', 'scada-brand-main', 'Ventus'), el('div', 'scada-brand-sub', 'Cables & Connectivity\u00ae')); brand.append(inner);
const plain = el('div', 'cc-plain cc-count', fmt(st.lit) + ' pieces of work lit, ' + fmt(st.dark) + ' gone dark, '
+ fmt(st.lit + st.dark) + ' in all \u00b7 ' + day(st.first) + ' to ' + day(st.last));
card.append(x, t, brand, plain);
if (!ASM && asmWhy) card.append(el('div', 'cc-refuse', 'The gathering could not be loaded, so this work stays where it is: ' + asmWhy));
if (typeof layout === 'function') layout();
}
function closeCard(){ cardToken++; card.style.display = 'none'; card.replaceChildren();
target = null; cardShown = null; dirty = true; }
addEventListener('keydown', e => {
if (e.key === 'Escape' && card.style.display !== 'none') { e.preventDefault(); closeCard(); } });
function codeWindow(lines, a, b, at){
const pre = el('pre', 'cc-code');
pre.setAttribute('aria-label', 'the code around this line');
const bar = el('div', 'cc-hi cc-hi-target');
const out = [];
for (let i = a; i <= b; i++) out.push(String(i).padStart(6) + ' ' + lines[i - 1]);
pre.append(bar, document.createTextNode(out.join('\n')));
const lh = () => parseFloat(getComputedStyle(pre).lineHeight) || 16;
const padTop = () => parseFloat(getComputedStyle(pre).paddingTop) || 0;
const place = () => { bar.style.top = (padTop() + (at - a) * lh()) + 'px'; bar.style.height = lh() + 'px'; };
return { node:pre, bar, place, first:a, last:b, at,
scrollToTarget(){ place(); pre.scrollTop = Math.max(0, (at - a) * lh() - pre.clientHeight/2 + lh()/2); } };
}
// WHAT A TAP OPENS. One way in for every kind of answer: the work and the day it was done, a state
// chip saying how much of it is proved, and, where the code for that line is carried on this site,
// the code itself with the tapped line marked. Nothing here sends a reader to GitHub to READ code;
// the link is there for the detail and the history, which is what GitHub is good for.
// ===== THE COMMANDS THAT RUN ON THE VISITOR'S DEVICE: Ventusltd/faraday bench/fire.js and bench/fire_site.js, carried whole ==========
// Checked against every saved record by faraday bench/fire_check.mjs (2,278 of 2,278). Carried inside this file so the pointer's hash covers them.
// bench/fire.js - the pop commands that RUN IN THE VISITOR'S BROWSER. Plain JavaScript, no library, nothing leaves the device.
// Each function is a port of the Python in bench/*_cases.py and is checked against the saved records by bench/fire_check.mjs:
// same inputs, same numbers, or the port is wrong. A command is: fire <name> {inputs as JSON}
(function (root) {
const R20 = { al: { 50: 0.641, 70: 0.443, 95: 0.320, 120: 0.253, 150: 0.206, 185: 0.164, 240: 0.125, 300: 0.100, 400: 0.0778, 500: 0.0605, 630: 0.0469 },
cu: { 50: 0.387, 70: 0.268, 95: 0.193, 120: 0.153, 150: 0.124, 185: 0.0991, 240: 0.0754, 300: 0.0601, 400: 0.0470, 500: 0.0366, 630: 0.0283 } };
const K = { al: 94.0, cu: 143.0 }, ALPHA = { al: 0.00403, cu: 0.00393 };
const RATE_AL = { 50: 150, 70: 185, 95: 220, 120: 250, 150: 280, 185: 320, 240: 370, 300: 420, 400: 480, 500: 545, 630: 615 };
const rate = (m, s) => m === 'al' ? RATE_AL[s] : Math.round(RATE_AL[s] * 1.28);
// as Python's round(): the number as it is actually held decides; only an EXACT half goes to the even side
const r = (x, d) => { const up = Number(x.toFixed(d)), t = Math.abs(x).toFixed(d + 25), tail = t.slice(t.indexOf('.') + 1 + d);
if (!/^50*$/.test(tail)) return up;
const k = Math.pow(10, d), n = Math.round(Math.abs(up) * k); return n % 2 === 0 ? up : Number((up - Math.sign(x) / k).toFixed(d)); };
const need = (o, keys) => { for (const k of keys) if (o[k] === undefined) throw new Error('this command needs "' + k + '"'); };
const RUN = {
'cable-withstand': { family: 'CABLE CHECK', run(i) { need(i, ['metal', 'size_mm2', 'seconds', 'fault_ka']);
if (!K[i.metal]) throw new Error('metal is "al" or "cu"');
const limit = K[i.metal] * i.size_mm2 / Math.sqrt(i.seconds) / 1000, ok = i.fault_ka <= limit;
return { numbers: { withstand_ka: r(limit, 2), fault_ka: i.fault_ka, margin_pct: r((limit / i.fault_ka - 1) * 100, 1) },
said: 'withstands ' + limit.toFixed(2) + ' kA; asked for ' + i.fault_ka + ' kA: ' + (ok ? 'survives' : 'DOES NOT SURVIVE: a larger conductor or faster protection'),
how: 'adiabatic rule: k x area / square root of time, k = ' + K[i.metal] }; } },
'cable-run': { family: 'CABLE CHECK', run(i) { need(i, ['metal', 'size_mm2', 'amps', 'metres', 'kv', 'derate']);
if (!R20[i.metal] || !R20[i.metal][i.size_mm2]) throw new Error('sizes: ' + Object.keys(R20.al).join(', ') + ' mm2; metal "al" or "cu"');
const rh = R20[i.metal][i.size_mm2] * (1 + ALPHA[i.metal] * 70), x = 0.08;
const vd = Math.sqrt(3) * i.amps * (rh * 0.95 + x * Math.sqrt(1 - 0.95 * 0.95)) * i.metres / 1000, pct = vd / (i.kv * 1000) * 100;
const use = i.amps / (rate(i.metal, i.size_mm2) * i.derate) * 100, flags = [];
if (use > 100) flags.push('over its derated rating'); else if (use > 85) flags.push('within 15 per cent of its derated rating: commission a buried cable thermal study');
if (pct > 1.5) flags.push('voltage drop ' + pct.toFixed(2) + '% is over 1.5%');
return { numbers: { volt_drop_pct: r(pct, 3), loading_pct: r(use, 1), loss_kw: r(3 * i.amps * i.amps * rh * i.metres / 1000 / 1000, 2) },
said: 'drop ' + pct.toFixed(2) + '%, loaded to ' + use.toFixed(0) + '% of its derated rating; ' + (flags.length ? flags.join('; ') : 'inside both limits'),
how: 'resistance at 20 C raised to 90 C; drop = root three x amps x (r cos + x sin) x length; rating x derating (ratings are CANDIDATE round figures)' }; } },
'national-day': { family: 'NATIONAL DAY', run(i) { need(i, ['firm_gw', 'round_trip']);
const raw = []; for (let h = 0; h < 48; h++) raw.push(24.25 + 6.25 * Math.sin(Math.PI * (h / 2 - 7) / 12));
const k = 604 / (raw.reduce((a, b) => a + b, 0) / 2), d = raw.map(v => v * k);
const short = d.reduce((a, v) => a + Math.max(0, v - i.firm_gw), 0) / 2, spare = d.reduce((a, v) => a + Math.max(0, i.firm_gw - v), 0) / 2, inp = short / i.round_trip;
return { numbers: { storage_delivers_gwh: r(short, 1), must_be_put_in_gwh: r(inp, 1), spare_generation_that_day_gwh: r(spare, 1), day_low_gw: r(Math.min(...d), 1), day_high_gw: r(Math.max(...d), 1) },
said: 'storage delivers ' + short.toFixed(0) + ' GWh and needs ' + inp.toFixed(0) + ' GWh put in; the steady generation has ' + spare.toFixed(0) + ' GWh to spare that day: ' + (spare >= inp ? 'enough to refill it' : 'NOT enough to refill it'),
how: '48 half hours of a 604 GWh spring day; demand above the steady generation comes from storage' }; } },
'dc-traction-chain': { family: 'DC TRACTION', run(i) { need(i, ['inverter', 'transformer', 'rectifier', 'dc_converter']);
const ac = i.inverter * i.transformer * i.rectifier, s = i.dc_converter - ac;
return { numbers: { reaches_rail_by_ac_route_pct: r(ac * 100, 2), reaches_rail_by_dc_route_pct: r(i.dc_converter * 100, 2), saved_pct_of_the_solar: r(s * 100, 2) },
said: (ac * 100).toFixed(1) + '% arrives by the usual route, ' + (i.dc_converter * 100).toFixed(1) + '% by the direct route: ' + (s * 100).toFixed(1) + '% of the SOLAR is saved',
how: 'multiplied the efficiencies along each route' }; } },
'dc-traction-scale': { family: 'DC TRACTION', run(i) { need(i, ['solar_gwh', 'saving_share']);
const traction = 1216 * 0.825, saved = i.solar_gwh * i.saving_share;
return { numbers: { traction_gwh: r(traction, 1), saved_gwh: r(saved, 2), solar_share_of_traction_pct: r(i.solar_gwh / traction * 100, 1), average_kw_per_substation: Math.round(traction * 1e6 / 300 / 8760) },
said: 'saves ' + saved.toFixed(1) + ' GWh a year; the solar is ' + (i.solar_gwh / traction * 100).toFixed(1) + '% of traction energy',
how: 'traction = total x 82.5%; saving = solar x share saved' }; } },
};
function parse(text) {
const m = String(text).trim().match(/^fire\s+([a-z0-9-]+)\s*(\{[\s\S]*\})?\s*$/i);
if (!m) throw new Error('a command looks like: fire cable-withstand {"metal":"al","size_mm2":185,"seconds":1,"fault_ka":16}');
let inputs = {}; if (m[2]) { try { inputs = JSON.parse(m[2]); } catch (e) { throw new Error('the part in { } is not valid: ' + e.message); } }
return { name: m[1].toLowerCase(), inputs };
}
function fire(text) { const c = parse(text), f = RUN[c.name]; if (!f) return { name: c.name, inputs: c.inputs, ran: false }; const o = f.run(c.inputs); return Object.assign({ name: c.name, inputs: c.inputs, ran: true, family: f.family, boxes: f.inputs || null }, o); }
// another file may add commands: FIRE.register('site-pulse', 'SITE PULSE', inputs => ({ numbers, said, how }), boxes)
// EVERY COMMAND DECLARES ITS OWN INPUTS, and that declaration is part of the protocol, not an extra:
// { key, label, unit, kind:'number'|'choice', min, max, step, choices:[[value, words], ...] }
// The window builds a labelled box for each one, so a command written next year gets its boxes free.
function register(name, family, run, inputs) { RUN[name] = { family, run, inputs: inputs || null }; }
root.FIRE = { fire, parse, register, inputsOf: n => (RUN[n] && RUN[n].inputs) || null, get names() { return Object.keys(RUN); } };
if (typeof module !== 'undefined') module.exports = root.FIRE;
})(typeof window !== 'undefined' ? window : globalThis);
// bench/fire_site.js - SITE PULSE in the visitor's browser: a port of solve() and record() in bench/site_cases.py.
// Plain JavaScript, no library. JavaScript has no complex numbers, so every volt, amp and ohm is a pair [re, im].
// Checked against every saved SITE PULSE and SITE SURVEY record by bench/fire_check.mjs. Load after fire.js.
(function (root) {
const CANDIDATE = { kv: 11.0, grid_fault_mva: 150.0, grid_x_over_r: 10.0, hv_cable_r: 0.20, hv_cable_x: 0.09, tx_z_pct: 5.5, tx_x_over_r: 5.0,