In this section
- File interaction · kuiper-belt / editions/202611021017/modules/202611020832-file.js lines 578–840
- Kuiper Belt — Editions Page render · kuiper-belt / editions/202611021201/index.html lines 1–437
File
A JavaScript file in the editions folder of Kuiper Belt that closes panel (`closePanel`) and then (`closeThen`), syncs layers (`syncLayers`) and draws on a canvas (units: kV), using SHA-256.
interactionkuiper-belt / editions/202611021017/modules/202611020832-file.js · lines 578–840 of 840 · version 2026-11-02 08:32 (continued from section 1520) · Not reached from any entry point (candidate for review) · pattern capturePainter (shared by 2 files)
- What it does
- It draws its content. Defines 84 functions or classes, including mk, shell, closePanel, closeThen, pop. 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 (repository name word 'kuiper'): AI-agent memory, coordination and code audit (the multi-agent journey named in Ventus Ltd's brief). README: "Edition 11 is the same page, keys and modules with one module added: the File menu (`modules/202611020832-file.js`, sha256 `5fc4e307dbe089b2b2a35e7e09b22c0e6322da30e9764e0cec56a801d1a06c05`, Opus team 6, NL-010 step 6, the GridAtlas lesson of the File menu)."
- Inputs & outputs
- In: JSON file keys.json; JSON file keys-min.json; JSON file modules.json; JSON file layers.json; JSON file editions.json. Out: canvas drawing.
- What it achieves
- It closes panel (`closePanel`), closes then (`closeThen`) and reads text (`readText`). No GridAtlas bytes are copied verbatim but the words of two row labels. It reads `keys.json`. It responds to popstate, keydown and hashchange events.
- Why it matters
- No other file in the estate was found to import it.
- Application
- kuiper-belt · editions/202611021017/modules · script
- Uses
- none found
- Used by
- none found
- Produces
- mk, shell, closePanel, closeThen, pop, layersApi, cardApi, fmt, pairs, parse, readText, enc
- Defines here
- wireBackspace, installStyle, row, heading, form, go, keyNow, cmd, buildFile, sayRow, fillEditions, fillApps, measureEvidence, onFileOpen, build, readout, install, inspect
- Cannot conclude
- Whether this code runs, is used by a live app today, or is correct. This is a static reading.
- Evidence
- kuiper-belt@26fba12ab1b5bab8e71934ab86c58273e5f32682 editions/202611021017/modules/202611020832-file.js:578-840 · blob 856d657dbdd0f0663ca2ce8b40f523f02afb8ed8 · 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
var r = row('Paste a link…', function () { openPaste(); return true; }, 'ky-edit-paste');
r.setAttribute('data-ky-edit', 'paste');
editPanel.appendChild(r); return r;
}
// ---- Backspace (whole wafer) clears every field but `layers` (6.3, 6.5)
function wireBackspace() {
addEventListener('keydown', function (e) {
if (e.key !== 'Backspace' || Hc.gbox.style.display === 'block') return;
var t = e.target; if (t && (t.isContentEditable || /^(INPUT|TEXTAREA|SELECT)$/.test(t.tagName))) return;
st.backspace++;
if (Lk && typeof Lk.clear === 'function') Lk.clear(['layers']);
});
}
return {
install: function (K, link) { KYc = K; Hc = K.hooks; Lk = link; K.draw.add(capturePainter, CAPTURE_ORDER); wireFind(); wireBackspace(); },
exportRows: exportRows, pasteRow: pasteRow, copyText: copyText, exportImage: exportImage, printView: printView,
takePaste: takePaste, looksBlank: looksBlank, footLines: footLines,
inspect: function () { return JSON.parse(JSON.stringify(st)); },
strings: { blank: BLANK_WORDS, licence: LICENCE_LINE, placeholder: PLACEHOLDER_LINK }
};
})();
// ==== SECTION C end
// ======================================================================== SECTION B: the FILE rows (6.1, 6.2) (LEAD)
var CSS_ID = 'ky-file-css';
function installStyle() {
if (document.getElementById(CSS_ID)) return;
var P = '#kuiper-menu-bar .gm-panel ', s = mk('style'); s.id = CSS_ID;
s.textContent = [
P + '.ky-file-form{display:flex;align-items:center;gap:6px;min-height:44px;margin:0 0 3px;padding:0 0 0 10px;box-sizing:border-box;flex-wrap:wrap}',
P + '.ky-file-form .ky-file-label{flex:0 0 auto;white-space:nowrap}',
P + '.ky-file-form input,' + P + 'input.ky-file-payload{flex:1 1 120px;min-width:0;height:44px;box-sizing:border-box;background:#02080b;color:#cfeef6;',
'border:1px solid rgba(80,220,240,.32);border-radius:2px;font:inherit;padding:0 8px}',
P + 'input.ky-file-payload{display:block;width:100%;margin:0 0 3px;color:#fff;border-color:#2ee6e6}',
P + '.ky-file-form button.ky-go{width:56px;flex:0 0 56px;justify-content:center;margin:0;border:1px solid rgba(80,220,240,.32)}',
// the shell's rev 3 (202611020243) gives its row look to a panel's direct children only, so FILE's rows inside its
// group carry the same look here (kuiper-shell.js:139-148 values), and GO keeps a 44 px target
P + '#ky-file button.gm-row,' + P + '#ky-file a.gm-row{display:flex;align-items:center;width:100%;min-height:44px;box-sizing:border-box;',
'margin:0 0 3px;padding:7px 10px;border:0;border-radius:2px;background:transparent;color:#cfeef6;',
'font:11px/1.35 ui-monospace,SFMono-Regular,Menlo,monospace;text-align:left;letter-spacing:.03em;text-transform:none;cursor:pointer;text-decoration:none}',
'@media (hover:hover){' + P + '#ky-file button.gm-row:hover,' + P + '#ky-file a.gm-row:hover{background:rgba(80,220,240,.14);color:#fff}}',
P + '#ky-file .ky-file-form button.ky-go{display:flex;align-items:center;min-height:44px;box-sizing:border-box;background:transparent;color:#cfeef6;font:inherit;cursor:pointer;border-radius:2px}',
P + '.ky-file-why{display:block;color:#ffb000;padding:2px 10px 4px;white-space:normal;overflow-wrap:anywhere}',
P + '.ky-file-why:empty{display:none}',
P + '.gm-row .gm-hint.ky-file-why{color:#ffb000;margin-left:8px}',
P + '.ky-sub{display:none;margin:0 0 3px 12px;border-left:1px solid rgba(80,220,240,.25)}',
P + '.ky-sub.ky-open{display:block}',
P + '.ky-row2{display:flex;flex-direction:column;align-items:flex-start!important;justify-content:center}',
P + '.ky-row2 .gm-hint{margin:2px 0 0;opacity:.75;font-size:10px}',
P + '.ky-lit{background:rgba(80,220,240,.16)!important;color:#fff!important}',
P + '[aria-disabled="true"]{opacity:.55;cursor:default}',
P + '.ky-missing .gm-hint{color:#ffb000!important;opacity:1}'
].join('\n');
document.head.appendChild(s);
}
// row(label, onTap, id, hint): a 44 px <button> row in the shell's face. onTap(el) runs; the panel closes unless it
// returns true (kuiper-shell.js row() keeps the same rule).
function row(label, onTap, id, hint) {
var b = mk('button', 'gm-row'); b.type = 'button'; if (id) b.id = id;
b.appendChild(mk('span', 'ky-file-label', label)); if (hint) b.appendChild(mk('span', 'gm-hint', hint));
b.addEventListener('click', function (e) { e.stopPropagation(); var keep = false; try { keep = onTap && onTap(b, e) === true; } finally { if (!keep) closePanel(); } });
st.rows++; return b;
}
function heading(parent, text) { var h = mk('div', 'gm-layer-group', text); h.setAttribute('data-ky-file-group', text); parent.appendChild(h); st.groups.push(text); return h; }
function form(label, id, attrs, onGo) {
var f = mk('div', 'ky-file-form'); f.id = id;
var l = mk('label', 'ky-file-label', label), i = mk('input'), g = mk('button', 'ky-go', 'GO'), why = mk('span', 'ky-file-why');
i.type = 'text'; i.id = id + '-in'; l.htmlFor = i.id; i.autocomplete = 'off'; i.spellcheck = false; i.setAttribute('autocapitalize', 'off');
Object.keys(attrs).forEach(function (k) { i.setAttribute(k, attrs[k]); });
g.type = 'button'; g.setAttribute('aria-label', label.replace(/…$/, '') + ': go');
function go() { why.textContent = ''; onGo(i.value.trim(), why); }
g.addEventListener('click', function (e) { e.stopPropagation(); go(); });
// the engine's single-key commands (r n e / Backspace, index.html:614-618) never fire from these fields
i.addEventListener('keydown', function (e) { e.stopPropagation(); if (e.key === 'Enter') { e.preventDefault(); go(); } else if (e.key === 'Escape') closePanel(); });
f.appendChild(l); f.appendChild(i); f.appendChild(g);
var wrap = mk('div'); wrap.appendChild(f); wrap.appendChild(why); st.rows++;
return { el: wrap, input: i, why: why };
}
function keyNow() { return st.fields.key || null; }
function cmd(k) { return 'python tools/key.py ' + k; }
var refs = {};
function buildFile(group) {
// ---- OPEN
heading(group, 'Open');
var ok = form('Open a key…', 'ky-file-key', { inputmode: 'numeric', enterkeyhint: 'go', pattern: '[0-9]*', placeholder: 'a key, digits only' }, function (v, why) {
var d = v.replace(/[ ,_]/g, '');
if (!/^\d{1,15}$/.test(d)) { why.textContent = v ? 'key ' + v + ' is not on this wafer (SPACE ' + H.SPACE + ')' : 'type a key: digits only'; return; }
var k = +d;
if (k >= H.SPACE) { why.textContent = 'key ' + d + ' is not on this wafer (SPACE ' + H.SPACE + ')'; st.refused.push(why.textContent); return; }
st.opened.push('key ' + d); closeThen(function () { openKey(k); });
});
group.appendChild(ok.el); refs.keyForm = ok;
// its second line: the command that gives the bytes from a clone (GridAtlas's one runnable command, menu-bar.js:707-733)
refs.keyCmd = row(cmd('<k>'), function (el) { var k = ok.input.value.replace(/[ ,_]/g, '') || keyNow(); if (!/^\d{1,15}$/.test(k || '')) { C.copyText(el, cmd('<k>')); return true; } C.copyText(el, cmd(k)); return true; }, 'ky-file-key-cmd', '⧉ copy');
ok.input.addEventListener('input', function () { var k = ok.input.value.replace(/[ ,_]/g, ''); refs.keyCmd.querySelector('.ky-file-label').textContent = cmd(/^\d{1,15}$/.test(k) ? k : (keyNow() || '<k>')); });
group.appendChild(refs.keyCmd);
var ol = form('Open a line…', 'ky-file-line', { inputmode: 'text', enterkeyhint: 'go', placeholder: 'blob:line, e.g. 0048802…729d:5' }, function (v, why) {
if (!/^[0-9a-f]{40}:\d+$/.test(v)) { why.textContent = 'line ' + (v || '…') + ' is not in this edition\'s keys.json'; return; }
why.textContent = 'opening…';
loadBodies().then(function () {
var i = indexOfId(v);
if (i < 0) { why.textContent = 'line ' + v + ' is not in this edition\'s keys.json'; return; }
why.textContent = ''; st.opened.push('line ' + v); closeThen(function () { openIndex(i); });
}, function (e) { why.textContent = 'line ' + v + ': ' + (e && e.message || e); });
});
group.appendChild(ol.el); refs.lineForm = ol;
var eds = mk('div', 'ky-sub'); eds.id = 'ky-file-editions';
refs.editionsRow = row('Open an edition ▸', function () { var on = eds.classList.toggle('ky-open'); if (on) fillEditions(eds); refs.editionsRow.setAttribute('aria-expanded', String(on)); return true; }, 'ky-file-open-edition');
refs.editionsRow.setAttribute('aria-expanded', 'false'); refs.editionsRow.setAttribute('aria-controls', eds.id);
group.appendChild(refs.editionsRow); group.appendChild(eds);
var apps = mk('div', 'ky-sub'); apps.id = 'ky-file-apps';
refs.appsRow = row('Open an app ▸', function () {
var A = KY.modules.apps && KY.modules.apps.api;
if (A && typeof A.open === 'function') { closePanel(); A.open(); st.opened.push('apps launcher'); return true; } // step 7's launcher
var on = apps.classList.toggle('ky-open'); if (on) fillApps(apps); refs.appsRow.setAttribute('aria-expanded', String(on)); return true;
}, 'ky-file-open-app');
refs.appsRow.setAttribute('aria-expanded', 'false'); refs.appsRow.setAttribute('aria-controls', apps.id);
group.appendChild(refs.appsRow); group.appendChild(apps);
// ---- LINK
heading(group, 'Link');
group.appendChild(row('Copy a link to this view', function (el) { writeNow(); C.copyText(el, link.url()); return true; }, 'ky-file-copy-link'));
refs.copyKey = row('Copy the key', function (el) { var k = keyNow(); if (!k) { sayRow(el, 'no key is open: open a key first'); return true; } C.copyText(el, k); return true; }, 'ky-file-copy-key');
group.appendChild(refs.copyKey);
refs.copyCmd = row('Copy ' + cmd('<k>'), function (el) { var k = keyNow(); if (!k) { sayRow(el, 'no key is open: open a key first'); return true; } C.copyText(el, cmd(k)); return true; }, 'ky-file-copy-cmd');
group.appendChild(refs.copyCmd);
// ---- EVIDENCE: every row an <a download> to this edition's own file, same origin; the byte count is measured
heading(group, 'Evidence');
refs.evidence = EVIDENCE.map(function (p) {
var a = mk('a', 'gm-row ky-row2'); a.href = p; a.setAttribute('download', p.split('/').pop()); a.setAttribute('data-ky-evidence', p);
a.appendChild(mk('span', 'ky-file-label', p + ' · ' + EVIDENCE_WHAT[p]));
var h = mk('span', 'gm-hint', 'bytes: measured when FILE opens'); a.appendChild(h);
a.addEventListener('click', function (e) { e.stopPropagation(); if (a.getAttribute('aria-disabled') === 'true') e.preventDefault(); });
group.appendChild(a); st.rows++; return a;
});
// ---- EXPORT (the builder's SECTION C)
heading(group, 'Export');
C.exportRows(group, row);
}
function sayRow(el, words) { var h = el.querySelector('.ky-file-why'); if (!h) { h = mk('span', 'gm-hint ky-file-why'); el.appendChild(h); } h.textContent = words; }
// the editions, from data/editions.json (Opus 3's data), read when the row is opened; newest first; this one inert
function fillEditions(box) {
if (box.getAttribute('data-filled')) return;
box.setAttribute('data-filled', 'loading'); box.textContent = '';
fetch('data/editions.json').then(function (r) { if (!r.ok) throw new Error('data/editions.json HTTP ' + r.status); return r.json(); }).then(function (j) {
var list = (j.editions || []).slice().sort(function (a, b) { return String(b.stamp).localeCompare(String(a.stamp)); });
st.editions = 'OK · ' + list.length;
list.forEach(function (e) {
var label = 'Kuiper Edition ' + e.number + ' · ' + e.stamp;
if (e.stamp === KY.edition) {
var cur = mk('button', 'gm-row', label + ' · this edition'); cur.type = 'button'; cur.disabled = true; // inert, 44 px like its neighbours
cur.setAttribute('aria-disabled', 'true'); cur.setAttribute('aria-current', 'page');
cur.setAttribute('data-ky-edition', e.stamp); box.appendChild(cur); return;
}
var a = mk('a', 'gm-row', label); a.setAttribute('data-ky-edition', e.stamp); a.href = editionTarget(e.stamp, '');
a.addEventListener('click', function (ev) { ev.stopPropagation(); ev.preventDefault(); syncLayers(); var h = hashText(); a.href = editionTarget(e.stamp, e.stamp === '202610311905' ? '' : h); st.opened.push('edition ' + e.stamp); leave(a.href); });
box.appendChild(a);
});
var ptr = mk('a', 'gm-row', 'editions/ · the newest edition'); ptr.setAttribute('data-ky-edition', 'pointer'); ptr.href = '../';
ptr.addEventListener('click', function (ev) { ev.stopPropagation(); ev.preventDefault(); syncLayers(); var h = hashText(); ptr.href = '../' + (h ? '#' + h : ''); leave(ptr.href); });
box.appendChild(ptr); box.setAttribute('data-filled', 'ok');
}).catch(function (e) {
st.editions = 'FAIL · ' + (e && e.message || e); box.setAttribute('data-filled', '');
var w = mk('div', 'ky-file-why', 'the editions list did not load: ' + (e && e.message || e)); box.appendChild(w);
});
}
function fillApps(box) {
box.textContent = '';
appsList().forEach(function (a) {
var el = mk('a', 'gm-row' + (a.star ? ' ky-lit' : ''), a.name); el.setAttribute('data-ky-app', a.id); el.href = a.link;
el.addEventListener('click', function (ev) {
ev.stopPropagation();
var f = {}; if (a.id === 'see-through') { if (st.sub) f.sub = st.sub; else if (st.fields.key) f.key = st.fields.key; }
else if (st.fields.key) f.key = st.fields.key;
ev.preventDefault(); el.href = appLink(a.id, f) || a.link; st.opened.push('app ' + a.id); leave(el.href);
});
box.appendChild(el);
});
}
// HEAD each evidence file once, when FILE first opens (no fetch at install, 6.2); a missing file is said in its row
var evidenceAsked = false;
function measureEvidence() {
if (evidenceAsked) return; evidenceAsked = true;
refs.evidence.forEach(function (a) {
var p = a.getAttribute('data-ky-evidence'), h = a.querySelector('.gm-hint');
fetch(p, { method: 'HEAD', cache: 'no-store' }).then(function (r) {
var n = r.headers.get('content-length');
if (!r.ok) { a.classList.add('ky-missing'); a.setAttribute('aria-disabled', 'true'); h.textContent = 'missing · HTTP ' + r.status; st.evidence[p] = { status: r.status }; return; }
h.textContent = (n != null ? fmt(+n) + ' bytes' : 'size not given'); a.setAttribute('data-ky-bytes', n == null ? '' : n);
st.evidence[p] = { status: r.status, bytes: n == null ? null : +n };
}).catch(function (e) { a.classList.add('ky-missing'); h.textContent = 'missing · ' + (e && e.message || e); st.evidence[p] = { error: String(e && e.message || e) }; });
});
}
function onFileOpen() {
measureEvidence();
var k = keyNow();
refs.copyCmd.querySelector('.ky-file-label').textContent = 'Copy ' + cmd(k || '<k>');
refs.copyKey.querySelector('.ky-file-label').textContent = 'Copy the key' + (k ? ' · ' + k : '');
if (!refs.keyForm.input.value) refs.keyCmd.querySelector('.ky-file-label').textContent = cmd(k || '<k>');
}
function build() {
var sh = shell(), filePanel = sh && sh.panel ? sh.panel('file') : null;
var group = filePanel ? filePanel.querySelector('.gm-group[data-group="file"]') : null;
if (!group && filePanel) { group = mk('div', 'gm-group'); group.setAttribute('data-group', 'file'); filePanel.appendChild(group); }
if (!group) { // no shell: FILE is a panel of Edition 4's own (KY.panels)
filePanel = mk('div'); filePanel.id = 'ky-file-panel'; group = mk('div', 'gm-group'); filePanel.appendChild(group);
KY.panels.add('file', filePanel, 'File'); st.panel = 'KY.panels (no shell)';
} else st.panel = 'kuiper-shell FILE';
group.id = 'ky-file';
buildFile(group);
// FILE opened: measure the evidence, refresh the key rows (the shell toggles the panel's hidden attribute)
try { new MutationObserver(function () { if (!filePanel.hidden && filePanel.offsetParent !== null) onFileOpen(); })
.observe(filePanel, { attributes: true, attributeFilter: ['hidden', 'class'] }); } catch (e) {}
// EDIT: `Paste a link…` (6.5); ABOUT: the one sentence (6.4)
var edit = sh && sh.panel ? sh.panel('edit') : null; if (edit) C.pasteRow(edit, row);
var about = sh && sh.panel ? sh.panel('about') : null;
if (about) { var p = mk('p', 'gm-prose', ABOUT_SENTENCE); p.setAttribute('data-owner', 'file'); p.style.margin = '6px 0 0'; about.appendChild(p); }
}
// the readout: refusals named once, in #hud after the engine's own text (draw rewrites it each frame)
function readout() { if (st.said.length) H.hud.textContent += '\n' + st.said.join('\n'); }
// ======================================================================== install, registration (LEAD)
function install(K) {
KY = K; H = K.hooks;
C.install(K, link); // SECTION C first: its find-box link intercept runs before watchFind
installStyle(); watchCard(); watchFind(); wireHashchange();
// the shell installs when the engine has built Edition 4's #bar (kuiper-shell.js whenEngine, 250 ms x 160): FILE waits
// for it on the same clock, then builds once; without a shell after 40 s, FILE is a panel of Edition 4's own
var tries = 0;
(function waitShell() {
var s = shell(); if (s && s.panel && s.panel('file')) { build(); return; }
if (++tries >= 160) { build(); return; }
setTimeout(waitShell, 250);
})();
K.draw.add(readout, 40);
st.installed = true;
// arrival: after the wafer admitted its data (index.html:208, the wafer promise), the reader runs once
H.wafer.then(function () { return readLocation('arrival'); }).catch(function (e) { st.last_read = { error: String(e && e.message || e) }; });
return api;
}
function inspect() {
var o = JSON.parse(JSON.stringify(st)); o.link = link.inspect(); o.c = C.inspect(); o.hash = location.hash; return o;
}
var api = Object.freeze({ schema: SCHEMA, generation: GEN, link: link, inspect: inspect,
openKey: function (k) { return openKey(+k); }, openLine: function (id) { return apply({ line: String(id) }, { from: 'api' }); },
exportImage: function () { return C.exportImage(document.getElementById('kuiper-export-image')); },
looksBlank: C.looksBlank, footLines: C.footLines, strings: C.strings, about: ABOUT_SENTENCE });
window.KY.register({ schema: 'kuiper.module.v1', id: ID, generation: GEN,
requires: ['keyPlace', 'address', 'describe', 'goKey', 'lightTime', 'home', 'flyTo', 'safeBox', 'fmt', 'card', 'gbox', 'gin',
'SPACE', 'N', 'repos', 'wafer', 'cv', 'ov', 'hud', 'big', 'panels', 'draw', 'redraw', 'cam', 'lit', 'sel', 'layers'],
provides: ['file', 'link'],
install: install, inspect: inspect });
})();Kuiper Belt — Editions Page
A web page that converts to world (`toWorld`), steps anim (`stepAnim`), places panels (`placePanels`) and calculates planar distances, using SHA-256. Published at https://ventusltd.github.io/kuiper-belt/editions/202611021201/.
renderkuiper-belt / editions/202611021201/index.html · lines 1–437 of 961 · version 2026-11-02 12:01 · Entry point · pattern loadEdition (shared by 2 files)
- What it does
- It draws its content. Defines 62 functions or classes, including fmt, words, refuse, prog, U. Side effects: changes the web page (DOM); makes network requests.
- Why it exists in the grid workflow
- Domain stage agent_infra (repository name word 'kuiper'): AI-agent memory, coordination and code audit (the multi-agent journey named in Ventus Ltd's brief). README: "the stamp is written in three places in `index.html` (meta refresh, the link, `location.replace`), as `learn-the-kuiper/index.html` does."
- Inputs & outputs
- In: JSON file keys-min.json; JSON file keys.json; JSON file modules.json; form fields (user input). Out: web page; WebGL/WebGPU drawing.
- Downstream impact
- Used directly by 2 files: Kuiper Belt — Editions Page (kuiper-belt, https://ventusltd.github.io/kuiper-belt/editions/); After (neural-link-between-agents). Reached from 1 other entry point, including GlobalGrid2050 — Kuiper Editions Page (globalgrid2050, https://globalgrid2050.com/kuiper-editions/). It is itself an entry point, published at https://ventusltd.github.io/kuiper-belt/editions/202611021201/.
- What it achieves
- It shows new (`showNew`), loads edition (`loadEdition`) and draws edition (`drawEdition`). Its `describe` function gives human readable address description from resolved address and repository metadata (VEDIC: explain). It reads `modules.json`. It responds to webglcontextlost, resize and pointerdown events.
- Why it matters
- Loaded by the page of the same name at https://ventusltd.github.io/kuiper-belt/editions/. Also imported by After, from Neural Link Between Agents.
- Application
- kuiper-belt · editions/202611021201 · page
- VEDIC
- EXPLAIN (GG2050-VEDIC-000040): Kuiper / Code navigation · Computer science / Interactive visualisation. resolved_address, repository_metadata → human_readable_address_description
- VEDIC
- RECENT (GG2050-VEDIC-000041): Kuiper / Code navigation · Computer science / Interactive visualisation. hours, ordered_commits → recent_band_animation_state
- VEDIC
- PERIOD (GG2050-VEDIC-000042): Kuiper / Code navigation · Computer science / Interactive visualisation. year, month_optional, day_optional, ordered_commits → commit_period_summary_or_null
- Uses
- none found
- Used by
- linked from Kuiper Belt — Editions Page (link), named by URL in After (estate URL)
- Produces
- fmt, words, refuse, prog, U, tsv, narrow, resize, flyTo, layout, safeBox, homeCamera
- Defines here
- fmt, words, refuse, prog, U, tsv, narrow, resize, flyTo, layout, safeBox, homeCamera, home, keyPlace, findBy, address, describe, issuedBelow, ownerAt, widestRunPx, span, linesByRunningTotals, keyAt, frame, draw, read, toWorld, show, goKey, showNew
- Cannot conclude
- Whether this code runs, is used by a live app today, or is correct. This is a static reading.
- Evidence
- kuiper-belt@26fba12ab1b5bab8e71934ab86c58273e5f32682 editions/202611021201/index.html:1-437 · blob b12bd24b2d6a250aa1467229dc056db51b8df943 · GitHub at these lines
- State
- achieves: code · context: readme_derived · stage: output · effects: dom, network · domain stage: agent_infra · users: ai_agent · canonical: unknown
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no,viewport-fit=cover">
<title>Kuiper Edition 12</title>
<style>
:root{--bg:#090c13;--ink:#d5dcea;--dim:#7d8799;--line:#1a2030;--hot:#e8b36a}
*{box-sizing:border-box}
html,body{margin:0;height:100%;background:var(--bg);color:var(--ink);
font:12px/1.55 ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;overflow:hidden;
overscroll-behavior:none;-webkit-text-size-adjust:100%}
canvas{position:fixed;inset:0;width:100%;height:100%;display:block;touch-action:none}
#c{z-index:1} #o{z-index:3;pointer-events:none}
#top{position:fixed;top:0;left:0;padding:10px 14px;z-index:10;pointer-events:none;max-width:60vw;background:#090c13d9;border-bottom-right-radius:6px}
#big{font-size:19px;letter-spacing:.03em} #sub{color:var(--dim);margin-top:2px}
#hud{position:fixed;top:0;right:0;padding:10px 14px;z-index:10;color:var(--dim);text-align:right;white-space:pre-line;max-width:38vw;background:#090c13d9;border-bottom-left-radius:6px}
#card{position:fixed;left:14px;bottom:64px;z-index:10;color:var(--ink);background:#090c13ee;
border:1px solid var(--line);padding:9px 12px;white-space:pre-line;display:none;max-width:min(680px,92vw)}
#card b{color:var(--hot);font-weight:600}
#foot{position:fixed;left:0;right:0;bottom:0;padding:8px 14px;color:var(--dim);border-top:1px solid var(--line);
background:#090c13ee;z-index:10;line-height:1.7}
#foot b{color:var(--ink);font-weight:600} a{color:#66ccff}
#goto{position:fixed;left:50%;top:38%;transform:translateX(-50%);z-index:20;display:none;background:var(--bg);
border:1px solid var(--dim);padding:10px 12px;min-width:min(520px,86vw)}
#goto input{width:100%;background:var(--bg);color:var(--ink);border:0;outline:0;font:14px ui-monospace,Consolas,monospace}
/* SCADA MEANINGS, one colour one meaning: x-ray grey is the record, cyan is the instrument,
green is energised (lit), amber is attention (new), magenta is selected. */
:root{--cy:#2ee6e6;--gn:#22ee77;--am:#ffb000;--mg:#ff2bd6}
#big{color:var(--cy);text-transform:uppercase;letter-spacing:.16em;font-size:15px}
#top,#hud{border:1px solid #12414a;border-top:0} #top{border-left:0} #hud{border-right:0;color:#8fb3bd}
#card{border-color:#1d6470} #card b{color:var(--am)} #foot{border-top-color:#12414a} #foot b{color:var(--cy)}
#goto{border-color:var(--cy)}
/* THE PHONE. These are read on an iPhone in portrait. Nothing fixed may sit over the wafer, so
on a narrow screen every panel becomes a full width strip at the top or the bottom and the
camera is given the rectangle that is left (safeBox in the script). The long subtitle would
eat a third of the screen, so it collapses and opens on a tap; nothing is deleted. The
keyboard commands get tap targets, because a phone has no n, no r and no slash. */
#keys{display:flex;gap:6px;flex-wrap:wrap;margin-bottom:6px}
#keys button{background:#0b1a20;color:#8fb3bd;border:1px solid #12414a;padding:7px 10px;font:inherit;
text-transform:uppercase;letter-spacing:.06em;cursor:pointer;touch-action:manipulation}
#keys button:hover,#keys button:active{border-color:var(--cy);color:var(--cy)}
#top{cursor:pointer}
@media (max-width:640px){
html,body{font-size:11px}
#top,#hud{left:0;right:0;max-width:none;border-radius:0;border-left:0;border-right:0;padding:7px 10px}
#hud{text-align:left;border-right:0}
#big{font-size:13px;letter-spacing:.10em}
#sub{max-height:0;overflow:hidden;margin-top:0}
#top.open #sub{max-height:38vh;overflow:auto;margin-top:4px}
#card{left:8px;right:8px;max-width:none;max-height:34vh;overflow:auto}
#foot{padding:7px 10px}
#foot .long{display:none}
#keys button{padding:9px 11px}
#goto{min-width:0;left:8px;right:8px;transform:none;top:30%}
}
/* EDITION 3: the bar is the only thing on screen at rest; every panel is a layer under it */
#bar{position:fixed;top:0;left:0;right:0;z-index:12;display:flex;gap:4px;align-items:center;padding:6px 8px;
background:#090c13e6;border-bottom:1px solid #12414a;overflow-x:auto;white-space:nowrap}
#barname{color:var(--cy);letter-spacing:.14em;font-size:12px;margin-right:8px;text-transform:uppercase}
#bar .gm-title{appearance:none;border:1px solid #12414a;background:transparent;color:#8fb3bd;font:inherit;
text-transform:uppercase;letter-spacing:.08em;padding:6px 10px;cursor:pointer;touch-action:manipulation}
#bar .gm-title:hover,#bar .gm-title.gm-on{background:rgba(80,220,240,.16);color:#fff;border-color:var(--cy)}
#top,#hud,#foot,#lines{display:none}
#top.gm-open,#hud.gm-open,#foot.gm-open,#lines.gm-open{display:block}
#top,#hud,#foot,#lines{position:fixed;top:40px;left:0;right:auto;bottom:auto;max-width:min(680px,96vw);max-height:60vh;overflow:auto;
z-index:11;background:#090c13f2;border:1px solid #1d6470;border-radius:0 0 6px 6px;padding:10px 12px;pointer-events:auto;text-align:left}
#hud{right:0;left:auto;max-width:min(560px,96vw)} #foot{border-top:1px solid #1d6470}
#top #sub{max-height:none;overflow:visible;margin-top:4px}
#lines{left:0;right:0;max-width:none;width:min(720px,96vw)}
#linesctl{display:flex;gap:8px;flex-wrap:wrap;align-items:center;margin-bottom:8px}
#linesctl label{color:#8fb3bd} #linesctl input[type=text],#linesctl #lyFind{flex:1 1 180px;background:var(--bg);color:var(--ink);border:1px solid #12414a;padding:5px 8px;font:inherit}
#linesctl button{background:#0b1a20;color:#8fb3bd;border:1px solid #12414a;padding:5px 9px;font:inherit;text-transform:uppercase;cursor:pointer}
#lineslist .ln{padding:5px 6px;border-top:1px solid #121a26;cursor:pointer;color:var(--dim);content-visibility:auto;contain-intrinsic-size:auto 44px} /* EDITION 5 (perf): rows out of view are not laid out */ #lineslist .ln b{color:var(--ink);font-weight:600}
#lineslist .ln.focus b{color:var(--gn)} #lineslist .ln.sel{background:rgba(255,43,214,.12)} #lineslist .ln:hover{background:rgba(80,220,240,.10)}
#card{bottom:12px!important;z-index:13;max-height:30vh;overflow:auto;padding:8px 36px 8px 12px;position:fixed}
#card .cx{position:absolute;right:6px;top:4px;width:26px;height:26px;border:1px solid #12414a;color:#8fb3bd;background:transparent;font:inherit;cursor:pointer;touch-action:manipulation}
#card .cq{color:#cde;border-left:2px solid #3a4150;padding-left:8px;margin:4px 0;white-space:pre-wrap}
#card .cd{display:none;color:var(--dim);margin-top:6px;border-top:1px solid #121a26;padding-top:6px}
#card.open .cd{display:block}
#card .ct{color:var(--cy);cursor:pointer;text-decoration:underline dotted}
@media (max-width:640px){ #card{left:6px;right:6px;bottom:6px!important;max-height:34vh;font-size:11px} }
/* EDITION 5 (robust): a refusal is said on screen, not only in a hidden panel; the details toggle is a button */
#refuse,noscript .refuse{position:fixed;left:12px;right:12px;top:36%;z-index:30;background:#090c13f2;border:1px solid var(--am);color:var(--ink);
padding:12px 14px;font-size:13px;white-space:pre-line;max-width:min(640px,96vw);margin:0 auto}
#card button.ct{appearance:none;background:none;border:0;padding:0;margin:0;font:inherit;color:var(--cy);cursor:pointer;text-decoration:underline dotted}
@media (prefers-reduced-motion:reduce){ #top.open #sub,#top #sub{transition:none} }
@media (max-width:640px){ #bar{flex-wrap:wrap;white-space:normal;overflow:visible} #barname{font-size:11px;margin-right:4px} #bar .gm-title{padding:5px 8px}
#top,#hud,#foot,#lines{top:calc(var(--barh,46px) + 0px);left:0;right:0;max-width:none;max-height:62vh} #hud{text-align:left} }
/* EDITION 5, TOUCH: the wafer owns every gesture on the canvas (touch-action:none, above); everything else may
pan but never pinch-zoom or double-tap-zoom the page, so the browser's zoom cannot wreck the layout. The
canvas and the bar are not text: no selection handles, no callout, no context menu on a long press. */
html,body{touch-action:pan-x pan-y}
#bar,#top,#hud,#foot,#lines,#card,#goto,#bar .gm-title,#keys button,#linesctl button,#card .cx{touch-action:pan-x pan-y}
canvas,#bar{user-select:none;-webkit-user-select:none;-webkit-touch-callout:none}
</style>
</head>
<body>
<noscript><div class="refuse" role="alert">KUIPER EDITION 6 needs JavaScript and WebGL2 to draw the wafer. Nothing is drawn without them; the verified lines are listed in keys.json and README.md in this folder.</div></noscript>
<canvas id="c"></canvas><canvas id="o"></canvas>
<div id="top"><div id="big">loading</div><div id="sub"> </div></div>
<div id="hud">starting</div>
<div id="card"></div>
<div id="goto"><input id="gotoin" autocomplete="off" spellcheck="false" placeholder="a key, or a repository name to send light through"></div>
<div id="foot">
<div id="keys"><button data-k="n">new code</button><button data-k="r">random line</button><button
data-k="/">find</button><button data-k="e">next verified line</button><button data-k="Backspace">whole wafer</button></div>
<span class="long"><b>KUIPER EDITION 6</b>: the verified lines of Edition 1 drawn as green sparks at their own keys on this wafer; <b>e</b> steps through them, tap one for its line and its GitHub link · <b>n</b> show new code · <b>r</b> random line · <b>/</b> a key, a repository, or a period like 2026-07 · <b>click</b> lights the repository under the
pointer through all of time · drag · scroll · <b>backspace</b> whole wafer · one law at every zoom:
r = √key, θ = key × golden angle · dark rings are silence between commits, measured · unresolved
pixels are computed from the law, not drawn · provided as is, without warranty of any kind; a chart, not a design
· <a href="https://github.com/Ventusltd/law">the laws</a></span>
</div>
<script type="module">
// THE KUIPER BELT AS ONE WAFER. Every line in every file in every commit, one key each, in the
// order time issued them.
//
// THE LAW, and there is only one, at every zoom:
// key k -> r = sqrt(k), theta = 2 pi frac(k G / 2^32), G = 2654435769
// It inverts, k = r squared, so the number of keys in any annulus is arithmetic. Nothing is ever
// drawn 38,000 times into a pixel to discover a number the law already states.
//
// THE RINGS ARE TIME. Before each commit a run of keys is left UNISSUED in proportion to the
// silence since the commit before it (tools/wafer_keys.py, a declared constant). A night is a dark
// ring. The dark fraction of every pixel is computed exactly from a prefix sum of issued keys, so
// even the rings are arithmetic. A line not yet written already has its place, on the rim, the
// way an address in RAM exists before anything is stored at it.
//
// UNRESOLVED pixels state a computed count as a shade. RESOLVED fields draw exactly the issued keys
// whose radius can be on screen, each at its own place. There is no sampling and no white flash,
// because a pixel is never asked to be more than it is.
const G32 = 2654435769, TW = 4096;
const cv = document.getElementById('c'), ov = document.getElementById('o'), o2 = ov.getContext('2d');
const gl = cv.getContext('webgl2', { antialias:false, alpha:false, powerPreference:'high-performance' });
const hud = document.getElementById('hud'), big = document.getElementById('big'),
sub = document.getElementById('sub'), card = document.getElementById('card');
const fmt = n => Math.round(n).toLocaleString('en-GB');
function words(n){ if (n >= 1e9) return (n/1e9).toFixed(2)+' billion'; if (n >= 1e6) return (n/1e6).toFixed(2)+' million';
if (n >= 1e3) return (n/1e3).toFixed(1)+' thousand'; return n >= 10 ? n.toFixed(0) : n.toFixed(2); }
function refuse(m, slot){ slot = slot || 'engine'; if (slot === 'engine') hud.textContent = m; const said = refuse.said = refuse.said || {};
if (m) said[slot] = m; else delete said[slot]; let d = document.getElementById('refuse'); const t = Object.values(said).join('\n');
if (!t) { if (d) d.remove(); return; } if (!d) { d = document.createElement('div'); d.id = 'refuse'; d.setAttribute('role', 'alert'); document.body.appendChild(d); } d.textContent = t; }
if (!gl) { refuse('WebGL2 is not available in this browser. Refusing rather than drawing a fraction of the wafer. The verified lines are in keys.json and README.md in this folder.'); throw new Error('WebGL2 is not available'); }
const VS_FULL = `#version 300 es
void main(){ vec2 p = vec2(float((gl_VertexID<<1)&2), float(gl_VertexID&2)); gl_Position = vec4(p*2.0-1.0,0.0,1.0); }`;
const FS_FIELD = `#version 300 es
precision highp float; precision highp sampler2D;
uniform vec2 u_res, u_center; uniform float u_zoom, u_R, u_points;
uniform sampler2D u_commits; uniform int u_n, u_litRepo; uniform float u_pulse, u_flash, u_newR; uniform vec2 u_litK;
out vec4 o;
vec4 C(int i){ return texelFetch(u_commits, ivec2(i % ${TW}, i / ${TW}), 0); } // k0, k1, issued before, repo
int find(float k){ int lo = 0, hi = u_n - 1;
for (int s = 0; s < 16; ++s){ if (lo >= hi) break; int m = (lo+hi+1)/2; if (C(m).r <= k) lo = m; else hi = m-1; } return lo; }
// how many ISSUED keys lie below address k: a prefix sum, so any annulus is one subtraction
float issuedBelow(float k){ vec4 c = C(find(k)); return c.b + clamp(k - c.r, 0.0, c.g - c.r); }
void main(){
vec2 w = u_center + (gl_FragCoord.xy - 0.5*u_res) / u_zoom;
float r = length(w), h = 0.75 / u_zoom;
vec3 bg = vec3(0.035,0.047,0.075), dust = vec3(0.79,0.83,0.90);
if (r > u_R + h) { float rim = smoothstep(2.5/u_zoom, 0.0, abs(r - u_R)); o = vec4(bg + rim*0.10, 1.0); return; }
float ka = max(r-h, 0.0), kb = r+h; ka *= ka; kb *= kb;
float cov = clamp((issuedBelow(kb) - issuedBelow(ka)) / max(kb - ka, 1.0), 0.0, 1.0); // issued share of this pixel
float perPx = cov / (3.14159265 * u_zoom * u_zoom); // issued keys in this pixel
float v = (u_points > 0.5) ? 0.0 : clamp(0.24 + 0.13*log(1.0+perPx)/2.302585, 0.0, 0.88) * pow(cov, 0.55);
vec3 col = mix(bg, dust, v);
// THE LIGHT. Which repository owns the key at the centre of this pixel. This one is a tap, not
// a count: it says where a repository's work lies in time, and no number is read off it.
if (u_litRepo >= 0) { float kc = r*r; vec4 c = C(find(kc)); if (kc <= c.g && int(c.a + 0.5) == u_litRepo)
col = mix(col, vec3(0.13,0.93,0.47), u_points > 0.5 ? 0.10 : 0.72); }
// A PERIOD IS A BAND. Keys run in time order, so a month or a day is one contiguous annulus.
if (u_litK.x >= 0.0 && r + h >= u_litK.x && r - h <= u_litK.y && cov > 0.0)
col = mix(col, vec3(0.13,0.93,0.47), u_points > 0.5 ? 0.10 : 0.72);
// THE PULSE travels outward from the centre, which on this wafer is forward through time. It is
// the instrument's sweep, not data, so it is faint over silence and bright over work.
if (u_pulse >= 0.0) { float d = abs(r - u_pulse) * u_zoom; col += vec3(0.45,0.95,1.0) * exp(-d*d/160.0) * (0.25 + 0.75*cov); }
// THE FLASH lights only keys issued at or after the boundary, and only where keys were issued.
if (u_flash > 0.0 && r + h >= u_newR && cov > 0.0) col = mix(col, vec3(1.0,0.69,0.0), u_flash);
o = vec4(col, 1.0);
}`;
const VS_KEYS = `#version 300 es
precision highp float;
uniform uint u_k0lo; uniform float u_R0, u_zoom, u_hot; uniform vec2 u_center, u_res;
out float v_hot;
void main(){
float d = float(gl_VertexID);
float r = u_R0 + (d + 0.5) / (u_R0 + sqrt(u_R0*u_R0 + d + 0.5) + 1e-9); // sqrt(k0+d+.5), kept precise
uint m = (u_k0lo + uint(gl_VertexID)) * ${G32}u;
float A = 6.283185307179586 * float(m >> 16) / 65536.0, B = 6.283185307179586 * float(m & 0xFFFFu) / 4294967296.0;
vec2 cs = vec2(cos(A)*cos(B) - sin(A)*sin(B), sin(A)*cos(B) + cos(A)*sin(B));
gl_Position = vec4((r*cs - u_center) * u_zoom / (0.5*u_res), 0.0, 1.0);
gl_PointSize = clamp(u_zoom * 0.34, 1.0, 9.0); v_hot = u_hot;
}`;
const FS_KEYS = `#version 300 es
precision highp float; in float v_hot; out vec4 o;
void main(){ if (length(gl_PointCoord-0.5) > 0.5) discard;
o = vec4(v_hot > 1.5 ? vec3(1.0,0.69,0.0) : (v_hot > 0.5 ? vec3(0.13,0.93,0.47) : vec3(0.79,0.83,0.90)), 1.0); }`;
function prog(vs, fs){ const p = gl.createProgram();
for (const [t,s] of [[gl.VERTEX_SHADER,vs],[gl.FRAGMENT_SHADER,fs]]) { const sh = gl.createShader(t);
gl.shaderSource(sh,s); gl.compileShader(sh);
if (!gl.getShaderParameter(sh, gl.COMPILE_STATUS)) throw new Error(gl.getShaderInfoLog(sh)); gl.attachShader(p,sh); }
gl.linkProgram(p); if (!gl.getProgramParameter(p, gl.LINK_STATUS)) throw new Error(gl.getProgramInfoLog(p)); return p; }
const PF = prog(VS_FULL, FS_FIELD), PK = prog(VS_KEYS, FS_KEYS);
const U = (p, n) => gl.getUniformLocation(p, n);
gl.bindVertexArray(gl.createVertexArray());
let lost = false;
cv.addEventListener('webglcontextlost', e => { e.preventDefault(); lost = true;
refuse('CONTEXT LOST. Nothing on screen is a count. Reload.'); });
// --------------------------------------------------------------------------------- the data
// cosmos/wafer.tsv: every commit in time order with its measured lines and the unissued keys
// before it. One file, about 400 kB, and then nothing else is ever fetched to draw the whole.
let N = 0, SPACE = 0, repos = [], commits = [];
let kyWaferOk, kyWaferNo; const kyWafer = new Promise((ok, no) => { kyWaferOk = ok; kyWaferNo = no; }); kyWafer.catch(() => {}); // KY.hooks.wafer (step 4)
async function tsv(url){ const r = await fetch(url); if (!r.ok) throw new Error(url);
return (await r.text()).split('\n').filter(l => l && l[0] !== '#').map(l => l.split('\t')); }
Promise.all([tsv('../../cosmos/repos.tsv'), tsv('../../cosmos/wafer.tsv')]).then(([rr, ww]) => {
repos = rr.map(p => ({ i:+p[0], name:p[1], lines:+p[2], seen:0, commits:0 }));
let k = 0, issued = 0;
commits = ww.map(p => { k += +p[4]; const c = { unix:+p[0], lines:+p[1], repo:+p[2], sha:p[3], gap:+p[4], k0:k, cum:issued };
k += c.lines; issued += c.lines; c.k1 = k; repos[c.repo].seen += c.lines; repos[c.repo].commits++; return c; });
const bad = repos.find(r => r.seen !== r.lines);
if (bad) { refuse('REFUSED: the commits of ' + bad.name + ' sum to ' + fmt(bad.seen) + ', the belt says ' + fmt(bad.lines)); kyWaferNo(new Error(hud.textContent)); return; }
N = issued; SPACE = k; kyWaferOk({ N, SPACE });
const H = Math.ceil(commits.length / TW), a = new Float32Array(TW * H * 4);
commits.forEach((c, i) => { a[i*4] = c.k0; a[i*4+1] = c.k1; a[i*4+2] = c.cum; a[i*4+3] = c.repo; });
gl.activeTexture(gl.TEXTURE0); gl.bindTexture(gl.TEXTURE_2D, gl.createTexture());
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA32F, TW, H, 0, gl.RGBA, gl.FLOAT, a);
big.textContent = words(N) + ' lines · one wafer';
sub.textContent = fmt(N) + ' keys issued, one per line in every file in every commit · ' + fmt(commits.length) + ' commits in '
+ repos.length + ' repositories, in the order time issued them · ' + words(SPACE - N) + ' keys left unissued as silence · '
+ new Date(commits[0].unix*1000).toISOString().slice(0,10) + ' at the centre, ' + new Date(commits[commits.length-1].unix*1000).toISOString().slice(0,10)
+ ' at the rim, and the next line ever written lands beyond it';
home(); dirty = true; loadEdition();
{ const st = new URLSearchParams(location.search).get('selftest') || '', mt = st.match(/^(20\d\d)-(\d\d)$/);
if (mt) setTimeout(() => { tween = null; const R = Math.sqrt(SPACE); cx = 0; cy = 0; zoom = (Math.min(cv.width, cv.height)/2)*0.80/R;
const got = lightTime(+mt[1], +mt[2], 0); tween = null; cx = 0; cy = 0; zoom = (Math.min(cv.width, cv.height)/2)*0.80/R; draw();
let direct = 0; if (got) for (let i = got.i0; i < got.i1; i++) direct += commits[i].lines;
// A lit period contains its own nights, so one pixel proves nothing: the first version of this
// test sampled the middle of July, landed on a silent ring and failed correctly for the wrong
// reason. Scan right across the band. Work must be green, silence must be dark, nothing else.
const px = new Uint8Array(4); let green = 0, dark = 0, other = 0; const seen = [];
const xa = Math.round(cv.width/2 + litK[0]*zoom), xb = Math.round(cv.width/2 + litK[1]*zoom);
for (let x = xa; x <= xb; x++) { gl.readPixels(x, Math.round(cv.height/2), 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, px);
const g = px[1] > 120 && px[1] > px[0] + 40 && px[1] > px[2] + 30, d = px[0] < 60 && px[1] < 60 && px[2] < 70;
if (g) green++; else if (d) dark++; else other++; if (seen.length < 12) seen.push([px[0], px[1], px[2]]); }
const T = { period: st, commits: got ? got.i1 - got.i0 : 0, lines_by_running_total: got ? got.lines : 0, lines_added_directly: direct,
T1_running_total_equals_direct_sum: !!got && got.lines === direct,
T2_work_is_green_and_silence_is_dark: green > 0 && other === 0, pixels_across_band: { green, dark, other }, first_pixels: seen };
T.PASS = T.T1_running_total_equals_direct_sum && T.T2_work_is_green_and_silence_is_dark; window.__selftest = T; document.title = 'selftest ' + (T.PASS ? 'PASS' : 'FAIL'); }, 400); }
if (new URLSearchParams(location.search).get('selftest') === 'new') { selftest = {}; tween = null; setTimeout(() => showNew(24), 300); }
if (new URLSearchParams(location.search).get('selftest') === 'phone') setTimeout(phoneSelftest, 500);
{ const mr = (new URLSearchParams(location.search).get('selftest') || '').match(/^repo:(.+)$/);
if (mr) setTimeout(() => repoSelftest(decodeURIComponent(mr[1])), 500); }
}).catch(() => { refuse('../../cosmos/wafer.tsv did not load. The wafer will not invent its keys.'); kyWaferNo(new Error('../../cosmos/wafer.tsv did not load. The wafer will not invent its keys.')); });
// ------------------------------------------------------------------------ camera and address
let cx = 0, cy = 0, zoom = 1, dirty = true, tween = null, litRepo = -1, target = null;
let pulse = -1, flash = 0, newFrom = -1, anim = null, selftest = null, litK = [-1,-1], litCi = null;
let atHome = true; // true while the camera has not been moved by hand
const elHudTop = hud, elTop = document.getElementById('top'), elFoot = document.getElementById('foot');
const narrow = () => innerWidth <= 640; // one number, used by the layout and by the test
function resize(){ cv.width = ov.width = innerWidth; cv.height = ov.height = innerHeight; gl.viewport(0,0,cv.width,cv.height);
if (typeof layout === 'function') layout();
if (atHome && SPACE) { const h = homeCamera(); cx = h.x; cy = h.y; zoom = h.z; tween = null; } // turning the phone re-fits, moving by hand does not
dirty = true; }
addEventListener('resize', resize); resize();
function flyTo(x, y, z){ tween = { t0:performance.now(), x0:cx, y0:cy, z0:zoom, x1:x, y1:y, z1:z, dur:900 }; }
// THE SAFE RECTANGLE. The panels are position:fixed, so the wafer cannot be centred on the window
// and be clear of them at the same time. layout() measures the panels as they really are after
// every change of text or size, and safeBox() returns what is left. Nothing here is assumed: the
// numbers come from getBoundingClientRect, which is what the browser actually laid out.
function layout(){
elHudTop.style.top = narrow() ? elTop.offsetHeight + 'px' : '0px'; // on a phone the HUD sits under the header, not beside it
card.style.bottom = (elFoot.offsetHeight + 10) + 'px'; // the card never hides the commands
}
function safeBox(){
layout();
let top = 0, bot = innerHeight;
for (const el of [elTop, elHudTop]) { const r = el.getBoundingClientRect(); if (r.width > 0 && r.height > 0) top = Math.max(top, r.bottom); }
const f = elFoot.getBoundingClientRect(); if (f.height > 0) bot = Math.min(bot, f.top);
return { x0:8, x1:innerWidth - 8, y0:top + 8, y1:Math.max(top + 24, bot - 8) };
}
// home() puts the whole wafer inside that rectangle, not inside the window: the circle is as big
// as the clear space allows and its centre is the centre of the clear space, which on a phone is
// above the middle of the screen.
function homeCamera(){
const s = safeBox(), R = Math.min(s.x1 - s.x0, s.y1 - s.y0) / 2 * 0.80;
const z = R / Math.sqrt(SPACE), mx = (s.x0 + s.x1)/2, my = (s.y0 + s.y1)/2;
return { z, x:(innerWidth/2 - mx)/z, y:(my - innerHeight/2)/z };
}
function home(){ const h = homeCamera(); atHome = true; flyTo(h.x, h.y, h.z); }
function keyPlace(k){ const m = Math.imul((k % 4294967296) >>> 0, G32) >>> 0, th = 2*Math.PI*m/4294967296, r = Math.sqrt(k + 0.5);
return [r*Math.cos(th), r*Math.sin(th)]; }
function findBy(field, v){ let lo = 0, hi = commits.length - 1; while (lo < hi) { const m = (lo+hi+1)>>1; if (commits[m][field] <= v) lo = m; else hi = m-1; } return lo; }
// an address key resolves to a commit by binary search; no walking, and silence is an answer too
function address(k){ if (!(k >= 0) || k >= SPACE) return null; const i = findBy('k0', k), c = commits[i];
return (k >= c.k0 && k < c.k1) ? { k, i, c, m:k - c.k0 } : { k, i, c, silent:true, next:commits[i + (k < c.k0 ? 0 : 1)] }; }
function describe(a){
if (!a) return '';
if (a.silent) { const n = a.next; return 'key <b>' + fmt(a.k) + '</b> was never issued\nsilence' + (n ? ' of ' + words((n.gap/ (n.gap ? 1 : 1))) + ' keys before ' + repos[n.repo].name + ' / ' + n.sha + ', '
+ new Date(n.unix*1000).toISOString().slice(0,16) + 'Z' : ''); }
const r = repos[a.c.repo];
return 'key <b>' + fmt(a.k) + '</b> · line ' + fmt(a.c.cum + a.m + 1) + ' of ' + fmt(N) + ' ever issued\n' + r.name + ' (' + words(r.lines) + ' lines in ' + fmt(r.commits) + ' commits)'
+ '\ncommit <b>' + a.c.sha + '</b> ' + new Date(a.c.unix*1000).toISOString().slice(0,16) + 'Z · line ' + fmt(a.m + 1) + ' of ' + fmt(a.c.lines)
+ '\nthe text itself: python tools/key.py ' + a.k;
}
// THE SAME ARITHMETIC THE SHADER USES, written out in the page so it can be checked against it.
// issuedBelow(k) is how many keys were issued below address k: a running total to the start of the
// commit that owns k, plus however far into that commit k lies. The fragment shader computes this
// exact expression for every pixel to decide its shade, so if these two ever disagree the picture
// is wrong, and proof 7 is the check that they do not.
function issuedBelow(k){ const c = commits[findBy('k0', k)]; return c.cum + Math.min(Math.max(k - c.k0, 0), c.k1 - c.k0); }
// which repository owns the key at radius r: -1 is silence, -2 is off the wafer
function ownerAt(r){ const kc = r*r; if (!(kc < SPACE)) return -2; const c = commits[findBy('k0', kc)];
return (kc >= c.k0 && kc <= c.k1) ? c.repo : -1; }
// a repository's lines counted through the running totals alone, never by adding its commits up
// HOW WIDE A REPOSITORY IS ON THE SCREEN. A key at radius r sits in a ring of 2 r dr addresses,
// so one pixel holds 2 r / zoom addresses and a commit of L lines is L zoom / 2 r pixels wide.
// Under one pixel, not one pixel centre can fall inside it and the light is invisible. That is a
// fact about the wafer, not a fault in the drawing, and the page says it rather than hiding it.
function widestRunPx(ri, z){
const span = (k0, k1) => (k1 - k0) * z / (2 * Math.sqrt((k0 + k1)/2));
let w = 0, a = -1, b = -1;
for (const c of commits) {
if (c.repo === ri && a >= 0 && c.k0 === b) { b = c.k1; } // no silence between them: one unbroken run
else if (c.repo === ri) { if (a >= 0) w = Math.max(w, span(a, b)); a = c.k0; b = c.k1; }
else if (a >= 0) { w = Math.max(w, span(a, b)); a = -1; }
}
return a >= 0 ? Math.max(w, span(a, b)) : w; }
function linesByRunningTotals(ri){ let t = 0; for (const c of commits) if (c.repo === ri) t += issuedBelow(c.k1) - issuedBelow(c.k0); return t; }
function keyAt(wx, wy){ const r = Math.hypot(wx, wy), kc = Math.round(r*r), span = Math.ceil(6*r + 8); let best = -1, bd = 0.6;
for (let k = Math.max(0, kc - span); k <= Math.min(SPACE-1, kc + span); k++) { const p = keyPlace(k), d = Math.hypot(p[0]-wx, p[1]-wy); if (d < bd) { bd = d; best = k; } }
return best; }
// --------------------------------------------------------------------------------- the frame
const POINTS_FROM = 1.0, MAX_CALLS = 3000;
function frame(){
if (lost) return;
if (tween) { const u = Math.min(1, (performance.now()-tween.t0)/tween.dur), e = u<0.5 ? 2*u*u : 1-Math.pow(-2*u+2,2)/2;
zoom = Math.exp(Math.log(tween.z0) + (Math.log(tween.z1)-Math.log(tween.z0))*e);
cx = tween.x0 + (tween.x1-tween.x0)*e; cy = tween.y0 + (tween.y1-tween.y0)*e; dirty = true; if (u >= 1) tween = null; }
if (anim) stepAnim();
if (dirty && N) { draw(); dirty = false; }
requestAnimationFrame(frame);
}
function draw(){
const R = Math.sqrt(SPACE), W = cv.width, H = cv.height;
const x0 = cx - W/2/zoom, x1 = cx + W/2/zoom, y0 = cy - H/2/zoom, y1 = cy + H/2/zoom;
const dx = x0 > 0 ? x0 : (x1 < 0 ? -x1 : 0), dy = y0 > 0 ? y0 : (y1 < 0 ? -y1 : 0);
const rmin = Math.hypot(dx, dy), rmax = Math.max(Math.hypot(x0,y0), Math.hypot(x1,y0), Math.hypot(x0,y1), Math.hypot(x1,y1));
const ka = Math.min(SPACE, Math.floor(rmin*rmin)), kb = Math.min(SPACE, Math.ceil(rmax*rmax));
// the screen's radii are a contiguous run of addresses; the issued ones among them are whole commits and two part commits
let i0 = findBy('k0', ka), segs = [], total = 0;
if (zoom >= POINTS_FROM) for (let i = i0; i < commits.length && commits[i].k0 < kb && segs.length <= MAX_CALLS; i++) {
const s0 = Math.max(commits[i].k0, ka), s1 = Math.min(commits[i].k1, kb); if (s1 > s0) { segs.push([s0, s1, commits[i].repo, i]); total += s1 - s0; } }
const points = zoom >= POINTS_FROM && segs.length <= MAX_CALLS && total < 1.6e9;
gl.useProgram(PF);
gl.uniform2f(U(PF,'u_res'), W, H); gl.uniform2f(U(PF,'u_center'), cx, cy); gl.uniform1f(U(PF,'u_zoom'), zoom);
gl.uniform1f(U(PF,'u_R'), R); gl.uniform1f(U(PF,'u_points'), points ? 1 : 0);
gl.uniform2f(U(PF,'u_litK'), litK[0], litK[1]);
gl.uniform1f(U(PF,'u_pulse'), pulse); gl.uniform1f(U(PF,'u_flash'), flash);
gl.uniform1f(U(PF,'u_newR'), newFrom >= 0 ? Math.sqrt(commits[newFrom].k0) : 1e30);
gl.uniform1i(U(PF,'u_commits'), 0); gl.uniform1i(U(PF,'u_n'), commits.length); gl.uniform1i(U(PF,'u_litRepo'), litRepo);
gl.drawArrays(gl.TRIANGLES, 0, 3);
if (selftest && selftest.wantPixels && flash > 0.5 && !points) {
const px = new Uint8Array(4), R0 = Math.sqrt(commits[newFrom].k0), rm = (R0 + R) / 2;
const read = (wx) => { gl.readPixels(Math.round(W/2 + (wx - cx)*zoom), Math.round(H/2 + (0 - cy)*zoom), 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, px); return [px[0], px[1], px[2]]; };
selftest.newBandPixel = read(rm); selftest.pupilPixel = read(0); selftest.wantPixels = false; }
let ms = 0;
if (points) { const t0 = performance.now(); gl.useProgram(PK);
gl.uniform1f(U(PK,'u_zoom'), zoom); gl.uniform2f(U(PK,'u_center'), cx, cy); gl.uniform2f(U(PK,'u_res'), W, H);
for (const [s0, s1, rp, ci] of segs) { gl.uniform1f(U(PK,'u_hot'), (newFrom >= 0 && ci >= newFrom) ? 2 : ((rp === litRepo || (litCi && ci >= litCi[0] && ci < litCi[1])) ? 1 : 0));
for (let off = s0; off < s1; off += 4000000) { // bounded calls; the driver watchdog is real
gl.uniform1ui(U(PK,'u_k0lo'), (off % 4294967296) >>> 0); gl.uniform1f(U(PK,'u_R0'), Math.sqrt(off));
gl.drawArrays(gl.POINTS, 0, Math.min(4000000, s1 - off)); } }
gl.finish(); ms = performance.now() - t0; }
const L = [];
L.push(points ? 'RESOLVED · every issued key whose radius is in the field, drawn at its own place'
: 'UNRESOLVED · up to ' + words(1/(Math.PI*zoom*zoom)) + ' keys to a pixel · each pixel’s issued count is computed from the law, not drawn');
if (points) L.push(fmt(total) + ' issued keys from ' + fmt(segs.length) + ' commits passed to the GPU in ' + ms.toFixed(0) + ' ms');
L.push('the whole · ' + fmt(N) + ' issued + ' + fmt(SPACE - N) + ' silent = ' + fmt(SPACE) + ' addresses');
if (litRepo >= 0) { const rt = linesByRunningTotals(litRepo), rr = repos[litRepo];
// the number on screen is the one the shading is made of, not the one the belt declared; if
// they differ the HUD says so rather than picking the prettier of the two
L.push('LIGHT · ' + rr.name + ' · ' + words(rt) + ' lines in ' + fmt(rr.commits) + ' commits, wherever in time they fall'
+ (rt === rr.lines ? ' · running totals agree with the belt' : ' · DISAGREEMENT: the belt says ' + fmt(rr.lines) + ', the running totals say ' + fmt(rt)));
const wpx = widestRunPx(litRepo, zoom);
// Said exactly, because 269 pixels of a repository whose widest run is a tenth of a pixel are
// lit: the runs are so close together that pixel centres keep landing inside them. The claim
// is about the run, not about the light.
if (wpx < 1) L.push('FINER THAN ONE PIXEL at this zoom · its widest unbroken run is ' + wpx.toFixed(4)
+ ' px across · it can light a pixel only where one happens to fall inside it · zoom in to see it whole'); }
L.push(zoom >= 1 ? 'zoom ' + zoom.toFixed(1) + ' px per key spacing' : 'zoom 1 px = ' + words(1/zoom) + ' units');
hud.textContent = L.join('\n');
o2.clearRect(0,0,ov.width,ov.height);
{ const x0 = (0 - cx)*zoom + ov.width/2, y0 = ov.height/2 + cy*zoom, M = ['JAN','FEB','MAR','APR','MAY','JUN','JUL','AUG','SEP','OCT','NOV','DEC'];
const a = new Date(commits[0].unix*1000), b = new Date(commits[commits.length-1].unix*1000); let lastPx = -99;
o2.font = '10px ui-monospace,Consolas,monospace'; o2.lineWidth = 1;
for (let y = a.getUTCFullYear(), m = a.getUTCMonth() + 1; y < b.getUTCFullYear() || (y === b.getUTCFullYear() && m <= b.getUTCMonth()); m++) {
if (m > 11) { m = 0; y++; }
const t = Date.UTC(y, m, 1)/1000, i = Math.min(commits.length-1, findBy('unix', t - 1) + 1), rp = Math.sqrt(commits[i].k0)*zoom;
if (rp - lastPx < 26 || rp > 6000) continue; lastPx = rp;
o2.strokeStyle = 'rgba(46,230,230,.30)'; o2.beginPath(); o2.arc(x0, y0, rp, 0, 6.2832); o2.stroke();
o2.fillStyle = 'rgba(46,230,230,.85)'; o2.fillText(M[m] + ' ' + String(y).slice(2), x0 + rp*0.5 + 4, y0 - rp*0.866 - 3); } }
if (target && target.boundary && zoom >= POINTS_FROM) {
// at this zoom the boundary circle is straight across the screen: perpendicular to the radius
const x = (target.x - cx)*zoom + ov.width/2, y = ov.height/2 - (target.y - cy)*zoom, rr = Math.hypot(target.x, target.y) || 1;
const tx = -target.y/rr, ty = target.x/rr, Lp = Math.hypot(ov.width, ov.height);
o2.strokeStyle = 'rgba(255,199,107,.95)'; o2.lineWidth = 2; o2.setLineDash([10,6]); o2.beginPath();
o2.moveTo(x - tx*Lp, y + ty*Lp); o2.lineTo(x + tx*Lp, y - ty*Lp); o2.stroke(); o2.setLineDash([]);
o2.font = '12px ui-monospace,Consolas,monospace'; o2.fillStyle = 'rgba(255,199,107,1)';
// outward is newer, and which way outward points on screen depends on where this key sits, so
// the words are placed along the real radius rather than assumed to read left to right
const ox = target.x/rr, oy = -target.y/rr;
o2.textAlign = 'center';
o2.fillText('NEW CODE', x + ox*110, y + oy*110); o2.fillStyle = 'rgba(213,220,234,.85)';
o2.fillText('older', x - ox*110, y - oy*110); o2.fillStyle = 'rgba(255,199,107,1)';
o2.fillText('the boundary', x + tx*150, y - ty*150 - 8); o2.textAlign = 'start'; }
if (target) { const x = (target.x - cx)*zoom + ov.width/2, y = ov.height/2 - (target.y - cy)*zoom;
o2.strokeStyle = 'rgba(255,43,214,.98)'; o2.lineWidth = 1.5; o2.beginPath();
for (const [a,b,c,d] of [[-16,0,-6,0],[6,0,16,0],[0,-16,0,-6],[0,6,0,16]]) { o2.moveTo(x+a,y+b); o2.lineTo(x+c,y+d); } o2.stroke(); }
}
// ------------------------------------------------------------------------------ the controls
function toWorld(px, py){ return [cx + (px - innerWidth/2)/zoom, cy - (py - innerHeight/2)/zoom]; }
function show(a){ card.style.display = 'block'; card.innerHTML = describe(a); if (a && !a.silent) litRepo = a.c.repo; dirty = true; }
function goKey(k){ const p = keyPlace(k); target = { x:p[0], y:p[1] }; show(address(k)); flyTo(p[0], p[1], 14); }
// SHOW NEW CODE. "New" is measured from the newest commit, not from the wall clock, so the same
// page gives the same answer tomorrow. Keys run in time order, so what is new is always one
// contiguous band at the rim: the boundary is a single circle, and that circle is drawn.
function showNew(hours){
const last = commits[commits.length-1].unix, cut = last - hours*3600;