In this section
- Wafer Development Environment — Proof K0022 Page render · globalgrid2050 / testcode/wafer-development-environment/202609192138-proof-k0022/index.html lines 1270–1559
- Wafer Development Environment — Proof K0024 Page render · globalgrid2050 / testcode/wafer-development-environment/202609192148-proof-k0024/index.html lines 1–410
Wafer Development Environment — Proof K0022 Page
A web page in the testcode folder of GlobalGrid2050 that draws link contract and cables, and uses data from the GridAtlas repository. Published at https://globalgrid2050.com/testcode/wafer-development-environment/202609192138-proof-k0022/.
renderglobalgrid2050 / testcode/wafer-development-environment/202609192138-proof-k0022/index.html · lines 1270–1559 of 1559 · version 2026-09-19 21:38 (continued from section 1485) · Entry point · pattern appFor (shared by 9 files)
- What it does
- It draws link contract and cables. Defines 76 functions or classes, including buildLink, complaints, parseLink, fmt, day. Side effects: changes the web page (DOM); makes network requests.
- Why it exists in the grid workflow
- Domain stage experimental (path word 'testcode'): work its own path marks as experimental (sandbox, prototype, archive or similar words); by this evidence it is not part of a production workflow. Domain terms in the code: cables.
- Inputs & outputs
- In: data source: gridatlas data; JSON file link-contract.json; form fields (user input). Out: web page; WebGL/WebGPU drawing.
- Downstream impact
- Used directly by 5 files: GlobalGrid2050 Homepage Before Four Nests (globalgrid2050, https://globalgrid2050.com/homepage-before-four-nests-20260925.html); Homepage Versions — Before Refresh Page (globalgrid2050, https://globalgrid2050.com/homepage_versions/20260922-before-refresh/); Homepage V123 (globalgrid2050, https://globalgrid2050.com/homepage_versions/homepage_v123.html); Homepage V124 (globalgrid2050, https://globalgrid2050.com/homepage_versions/homepage_v124.html); and 1 more. Reached from 83 other entry points, including GlobalGrid2050 Historical Builds (globalgrid2050, https://globalgrid2050.com/historical_builds.html); Homepage V037 (globalgrid2050, https://globalgrid2050.com/homepage_versions/homepage_v037.html); Homepage V038 (globalgrid2050, https://globalgrid2050.com/homepage_versions/homepage_v038.html). It is itself an entry point, published at https://globalgrid2050.com/testcode/wafer-development-environment/202609192138-proof-k0022/.
- What it achieves
- It builds link (`buildLink`), parses link (`parseLink`) and sets tag (`setTag`). Its `lightTime` function gives commit period summary or null from year, optional month and optional day (VEDIC: period). It reads `cosmos/link-contract.json`. It responds to error, webglcontextlost and resize events.
- Why it matters
- Loaded by the GlobalGrid2050 Homepage Before Four Nests page at https://globalgrid2050.com/homepage-before-four-nests-20260925.html and 4 other pages.
- Application
- globalgrid2050 · testcode/wafer-development-environment/202609192138-proof-k0022 · page
- 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
- GridAtlas — Atlas Page (estate URL)
- Used by
- linked from GlobalGrid2050 Homepage Before Four Nests (link), linked from Homepage Versions — Before Refresh Page (link), linked from Homepage V123 (link), linked from Homepage V124 (link), linked from Homepage V125 (link)
- Produces
- buildLink, complaints, parseLink, fmt, day, words, prog, U, tsv, appFor, narrow, resize
- Defines here
- repoSelftest, strip, check, phoneSelftest, ev, seen, walk, lightTime, pinchNow, pointerGone, goToKey
- Cannot conclude
- Whether this code runs, is used by a live app today, or is correct. This is a static reading.
- Evidence
- globalgrid2050@0aca5121f0795e469b6cf4fc3d3b628edba8d883 testcode/wafer-development-environment/202609192138-proof-k0022/index.html:1270-1559 · blob 184f9c1af1d4ec1cc50471eb855b02f38e4c2d27 · GitHub at these lines
- State
- achieves: code · context: readme_derived · stage: output · effects: dom, network · domain stage: experimental · users: none · canonical: production_core
show(address(x.k0 + Math.floor(x.lines / 2))); await new Promise(r => setTimeout(r, 250));
const tile = card.querySelector('a.cc-tile'), det = card.querySelector('details.cc-q');
const name = tile && tile.querySelector('.cc-tile-name'), open = tile && tile.querySelector('.cc-tile-open');
const first = Array.from(card.children).filter(k => !k.classList.contains('cc-x'))[0];
const biggest = name ? parseFloat(getComputedStyle(name).fontSize) : 0;
let others = 0; for (const e of card.querySelectorAll('*')) if (e !== name && !e.contains(name) && e.getClientRects().length && e.textContent.trim())
others = Math.max(others, parseFloat(getComputedStyle(e).fontSize) || 0);
T.the_tile_says = tile ? tile.textContent.replace(/\s+/g, ' ').slice(0, 140) : null;
T.T30_the_application_is_the_first_and_biggest_thing_and_the_whole_tile_opens_it = !!tile && first === tile
&& on(tile) && on(open) && biggest > others && /^OPEN /.test(open.textContent)
&& tile.href === ((appFor(x.owner, x.repo, x.path) || {}).app || {}).live;
T.T31_the_application_says_what_it_does_for_a_project = !!tile && !!tile.querySelector('.cc-tile-what')
&& tile.querySelector('.cc-tile-what').textContent.length > 20;
const b = card.querySelector('.scada-brand');
T.T32_the_brand_block_is_gridatlas_own = !!b && b.querySelector('.scada-brand-main').textContent === 'Ventus'
&& b.querySelector('.scada-brand-sub').textContent === 'Cables & Connectivity\u00ae' && on(b);
T.T33_the_code_is_closed_until_asked_for = !!det && det.open === false && !on(card.querySelector('.cc-code'))
&& det.querySelector('summary').textContent === 'See the code behind this';
// every word above the closed code, as a reader sees it
let above = ''; for (const k of card.children) { if (k === det) break; above += ' ' + k.textContent; }
T.words_above_the_code = above.replace(/\s+/g, ' ').trim().slice(0, 200);
T.coder_words_above_the_code = ['commit', 'key', 'repository', 'path', 'line ', 'piece of work'].filter(w => above.toLowerCase().indexOf(w) >= 0);
T.T34_no_word_above_the_code_that_a_banker_would_not_use = T.coder_words_above_the_code.length === 0
&& /(?<!\d)\d{1,2} [A-Z][a-z]{2} \d{4}(?!\d)/.test(above);
det.open = true; await new Promise(r => setTimeout(r, 200));
T.T35_one_tap_opens_the_code_with_the_line_marked = on(card.querySelector('.cc-code'))
&& !!cardShown && !!cardShown.window && Math.abs(parseFloat(cardShown.window.bar.style.top) || -1) >= 0; }
// NO CARD IS A DEAD END, AND NO LINK IS A SENTENCE. With an application: its tile, and GitHub as one
// word. Without one: the site itself, and GitHub as one word. Never a link that reads like a paragraph.
{ codeOpen = false;
const noApp = commits.find(q => { const rp = repos[q.repo]; return rp.pub && !appFor(rp.owner, rp.name, null); });
if (noApp) { show(address(noApp.k0)); await new Promise(r => setTimeout(r, 150));
const hm = card.querySelector('.cc-links a.cc-home'), g2 = card.querySelector('.cc-links a.cc-gh');
T.a_card_with_no_application_offers = Array.from(card.querySelectorAll('.cc-links a')).map(x => x.textContent);
T.T36_a_card_with_nothing_else_offers_the_site = !!hm && hm.textContent === 'www.globalgrid2050.com'
&& hm.href === 'https://www.globalgrid2050.com/' && on(hm) && !!g2 && g2.textContent === 'GitHub'; }
else T.T36_a_card_with_nothing_else_offers_the_site = true;
const longest = Array.from(card.querySelectorAll('a:not(.cc-tile)')).reduce((m, x) => Math.max(m, x.textContent.trim().split(/\s+/).length), 0);
T.T37_no_link_reads_like_a_sentence = longest <= 3;
// and the drawing engine's work leads to the London Underground, the example that was missed
const ug = apps.find(q => q.app === 'underground'), uc = ug && commits.find(q => { const rp = repos[q.repo];
return (rp.owner + '/' + rp.name).toLowerCase() === ug.repo; });
if (uc) { show(address(uc.k0)); await new Promise(r => setTimeout(r, 150));
const t2 = card.querySelector('a.cc-tile');
T.the_drawing_engine_leads_to = t2 ? t2.textContent.slice(0, 60) : null;
T.T38_the_drawing_engine_leads_to_the_london_underground = !!t2 && t2.href === ug.live && on(t2); }
else T.T38_the_drawing_engine_leads_to_the_london_underground = false; }
T.sample_line = want === null ? null : String(want).slice(0, 80);
T.PASS = T.T1_the_card_opened_for_that_key && T.T2_the_line_shown_is_the_line_that_file_holds
&& T.T3_that_exact_text_is_on_the_screen && T.T4_it_is_the_marked_line
&& T.T5_the_card_is_on_the_screen && T.T6_a_key_with_no_card_shows_no_code
&& T.T7_the_github_link_is_on_the_screen && T.T8_ten_lines_below_are_there_and_five_are_on_the_screen
&& T.T9_no_code_line_runs_off_the_right_edge && T.T10_the_header_says_what_day_the_work_was_done
&& T.T11_it_says_the_work_the_day_and_where_to_see_it
&& T.T12_no_arithmetic_and_no_command_anywhere_on_the_page
&& T.T13_a_gap_leads_to_the_next_work && T.T14_an_empty_readout_draws_no_box
&& T.T15_a_link_this_page_built_parses_back_to_what_it_asked_for
&& T.T16_no_address_is_typed_by_hand_in_this_page
&& T.T17_the_arrow_ends_on_the_dot && T.T18_it_is_shot_from_the_centre_of_the_record
&& T.T19_and_then_the_card_opens && T.T20_an_address_it_cannot_answer_is_answered_in_words
&& T.T21_the_state_chip_says_OK_and_only_one_thing
&& T.T22_the_card_says_which_application_and_opens_it
&& T.T23_every_carried_file_gets_the_application_its_folder_proves
&& T.T24_where_nothing_is_proved_there_is_no_door
&& T.T25_a_repository_that_is_one_application_is_proved_by_the_repository
&& T.T26_a_carried_file_no_application_claims_gets_no_door
&& T.T27_the_page_and_the_tool_agree_on_every_file_and_every_count
&& T.T28_the_cables_line_opens_cables_above_the_code_without_scrolling
&& T.T29_a_gridatlas_line_opens_gridatlas_above_the_code_without_scrolling
&& T.T30_the_application_is_the_first_and_biggest_thing_and_the_whole_tile_opens_it
&& T.T31_the_application_says_what_it_does_for_a_project && T.T32_the_brand_block_is_gridatlas_own
&& T.T33_the_code_is_closed_until_asked_for && T.T34_no_word_above_the_code_that_a_banker_would_not_use
&& T.T35_one_tap_opens_the_code_with_the_line_marked
&& T.T36_a_card_with_nothing_else_offers_the_site && T.T37_no_link_reads_like_a_sentence
&& T.T38_the_drawing_engine_leads_to_the_london_underground;
window.__selftest = T; document.title = 'selftest ' + (T.PASS ? 'PASS' : 'FAIL');
}
// LIGHT A REPOSITORY, TESTED. ?selftest=repo:<name>, or repo:* for the largest one. Two questions.
// ONE, the picture: walking outward from the centre, a pixel is green if and only if the key at
// that pixel's centre belongs to that repository. A pixel whose radial span straddles a change of
// owner is excluded and counted separately, because at this zoom one pixel covers hundreds of
// millions of addresses and the shader and this loop need not agree on which side of the line it
// falls. Every other pixel must agree exactly.
// TWO, the number: the repository's line total added up through the running totals, which is the
// arithmetic the shading itself is made of, must equal the direct sum of its commits, and both
// must equal what cosmos/repos.tsv declared before any of this was drawn. Three sources, one
// number, or the test fails.
function repoSelftest(name){
const rp = (name === '*') ? repos.reduce((a, b) => b.lines > a.lines ? b : a)
: repos.find(x => x.name.toLowerCase() === name.toLowerCase());
if (!rp) { window.__selftest = { PASS:false, asked_for:name, error:'no repository of that name is on this wafer' };
document.title = 'selftest FAIL'; return; }
let byRunning = 0, directly = 0, n = 0;
for (const c of commits) if (c.repo === rp.i) { byRunning += issuedBelow(c.k1) - issuedBelow(c.k0); directly += c.lines; n++; }
litRepo = rp.i; litK = [-1,-1]; litCi = null; newFrom = -1; flash = 0; pulse = -1; target = null; card.style.display = 'none';
tween = null; { const h = homeCamera(); cx = h.x; cy = h.y; zoom = h.z; } draw();
const W = cv.width, H = cv.height, Rpx = Math.sqrt(SPACE)*zoom;
const col0 = Math.round(W/2 - cx*zoom), row0 = Math.round(H/2 - cy*zoom); // the wafer's own centre, in GL pixels
const span = Math.max(4, Math.floor(Rpx) - 1);
const strip = (x, y, w, h) => { const b = new Uint8Array(w*h*4); gl.readPixels(x, y, w, h, gl.RGBA, gl.UNSIGNED_BYTE, b); return b; };
const east = strip(col0, row0, span, 1), north = strip(col0, row0, 1, span);
let lit = 0, dark = 0, wrong = 0, straddled = 0; const wrongAt = [];
function check(buf, i, wx, wy, hx, hy, where){
const own = ownerAt(Math.hypot(wx, wy));
if (ownerAt(Math.hypot(wx-hx, wy-hy)) !== own || ownerAt(Math.hypot(wx+hx, wy+hy)) !== own) { straddled++; return; }
const r0 = buf[i*4], g0 = buf[i*4+1], b0 = buf[i*4+2];
const green = g0 > 120 && g0 > r0 + 40 && g0 > b0 + 30;
if (green === (own === rp.i)) { green ? lit++ : dark++; }
else { wrong++; if (wrongAt.length < 8) wrongAt.push({ strip:where, pixel_from_centre:i,
key_belongs_to: own === -1 ? 'silence' : (own === -2 ? 'beyond the rim' : repos[own].name),
drawn: green ? 'green' : 'not green', rgb:[r0, g0, b0] }); }
}
const hudWhenLit = hud.textContent; // what the page told the reader while it was lit
const wy0 = cy + (row0 + 0.5 - H/2)/zoom, wx0 = cx + (col0 + 0.5 - W/2)/zoom, h = 0.5/zoom;
for (let i = 0; i < span; i++) check(east, i, cx + (col0 + i + 0.5 - W/2)/zoom, wy0, h, 0, 'east');
for (let i = 0; i < span; i++) check(north, i, wx0, cy + (row0 + i + 0.5 - H/2)/zoom, 0, h, 'north');
{ const hm = homeCamera(); cx = hm.x; cy = hm.y; zoom = hm.z; litRepo = -1; dirty = true; draw(); }
const wpx = widestRunPx(rp.i, Rpx/Math.sqrt(SPACE));
const tooSmall = wpx < 1;
const said = /FINER THAN ONE PIXEL/.test(hudWhenLit);
const T = { repository: rp.name, commits: n, viewport:[W, H], wafer_radius_px: Math.round(Rpx), pixels_walked: 2*span,
// A pixel is green if and only if the key at its centre belongs to this repository. Nothing
// else is asserted: a repository under a pixel wide lights nothing, and the second test is
// that the page says that out loud instead of showing an empty wafer and letting it pass.
T1_no_pixel_disagrees_with_the_keys: wrong === 0,
T2_it_lights_pixels_or_the_page_says_it_is_too_small: lit > 0 || (tooSmall && said),
widest_unbroken_run_px_at_this_zoom: +wpx.toFixed(4), finer_than_one_pixel: tooSmall, the_page_said_so: said,
pixels: { green_and_owned_by_it: lit, not_green_and_not_owned_by_it: dark, disagreed: wrong, straddled_a_boundary_and_excluded: straddled },
first_disagreements: wrongAt,
T3_running_totals_equal_the_direct_sum: byRunning === directly,
T4_and_equal_what_the_belt_declared: directly === rp.lines,
lines_by_running_totals: byRunning, lines_added_directly: directly, lines_declared_by_the_belt: rp.lines };
T.PASS = T.T1_no_pixel_disagrees_with_the_keys && T.T2_it_lights_pixels_or_the_page_says_it_is_too_small
&& T.T3_running_totals_equal_the_direct_sum && T.T4_and_equal_what_the_belt_declared;
window.__selftest = T; document.title = 'selftest ' + (T.PASS ? 'PASS' : 'FAIL');
}
// THE PHONE TEST, run by the page on itself with ?selftest=phone at whatever size the window is.
// It states that size, so the verdict is about a real viewport and not about a claim. Three
// mechanical questions: does any permanent panel cover the wafer, does the card fit on the screen,
// and do a drag and a two finger pinch actually move the camera when the events are dispatched.
function phoneSelftest(){
tween = null; { const h = homeCamera(); cx = h.x; cy = h.y; zoom = h.z; } draw();
const W = innerWidth, H = innerHeight, Rpx = Math.sqrt(SPACE)*zoom;
const scx = (0 - cx)*zoom + W/2, scy = H/2 + cy*zoom; // where the wafer's centre really is on screen
const panels = []; let worst = 1e9;
for (const id of ['top','hud','foot']) { const r = document.getElementById(id).getBoundingClientRect();
const qx = Math.max(r.left, Math.min(scx, r.right)), qy = Math.max(r.top, Math.min(scy, r.bottom));
const clear = Math.hypot(qx - scx, qy - scy) - Rpx; // nearest point of the panel, less the rim radius
panels.push({ panel:id, rect:[r.left, r.top, r.right, r.bottom].map(Math.round), clear_of_the_rim_px:Math.round(clear) });
worst = Math.min(worst, clear); }
const onScreen = scx - Rpx >= -0.5 && scx + Rpx <= W + 0.5 && scy - Rpx >= -0.5 && scy + Rpx <= H + 0.5;
show(address(Math.floor(N/2))); layout();
const cr = card.getBoundingClientRect();
const cardFits = cr.left >= -0.5 && cr.top >= -0.5 && cr.right <= W + 0.5 && cr.bottom <= H + 0.5 && cr.width > 40 && cr.height > 20;
const ev = (t, id, x, y) => cv.dispatchEvent(new PointerEvent(t, { pointerId:id, clientX:x, clientY:y, bubbles:true, pointerType:'touch' }));
const z0 = zoom, cx0 = cx; // one finger: the world must follow it
ev('pointerdown', 11, Math.round(W*0.5), Math.round(H*0.5)); ev('pointermove', 11, Math.round(W*0.5) + 60, Math.round(H*0.5));
const dragged = cx0 - cx; ev('pointerup', 11, Math.round(W*0.5) + 60, Math.round(H*0.5));
const zA = zoom; // two fingers: the distance between them must set the zoom
ev('pointerdown', 21, Math.round(W*0.35), Math.round(H*0.5)); ev('pointerdown', 22, Math.round(W*0.65), Math.round(H*0.5));
const spread = Math.round(W*0.65) - Math.round(W*0.35);
ev('pointermove', 22, Math.round(W*0.35) + 2*spread, Math.round(H*0.5));
const zB = zoom; ev('pointerup', 21, 0, 0); ev('pointerup', 22, 0, 0);
// put the wafer back the way it was found: the test's own light is not part of the record
{ const h = homeCamera(); cx = h.x; cy = h.y; zoom = h.z; atHome = true; litRepo = -1; target = null;
card.style.display = 'none'; dirty = true; draw(); }
// THE PUBLIC FACE, CHECKED ON THE FACE ITSELF. Functions, use cases and disclaimers: what a person
// can do here, what it is for, and what it is not. The placement law, the angle and the unresolved
// pixels are engineering notes and belong in the repository, not in front of a reader.
// PRESENT IS NOT THE SAME AS VISIBLE. textContent returns words that are set to display:none as
// happily as words on the screen, so every check passed while a phone showed no disclaimer at all.
// Ask the layout instead: a node with no client rectangles is not in front of anybody.
const seen = el => { if (!el) return ''; let out = '';
const walk = n => { if (n.nodeType === 3) { const r = document.createRange(); r.selectNodeContents(n);
if (r.getClientRects().length) out += ' ' + n.nodeValue; return; }
if (n.nodeType !== 1 || !n.getClientRects().length) return;
for (const c of n.childNodes) walk(c); };
walk(el); return out.replace(/\s+/g, ' ').trim().toLowerCase(); };
const faceSeen = seen(document.getElementById('foot')) + ' ' + seen(document.getElementById('top'));
// NOTHING MAY RUN OFF THE RIGHT EDGE. A box whose content is wider than the box itself is a box
// with words hidden in it, which is how a cut disclaimer looks to everyone except a test.
const overflows = [];
for (const id of ['top','hud','foot','card']) { const el = document.getElementById(id);
if (el && el.getClientRects().length && el.scrollWidth > el.clientWidth + 1)
overflows.push({ panel:id, content_px:el.scrollWidth, box_px:el.clientWidth }); }
const face = (document.getElementById('foot').textContent + ' ' + document.getElementById('top').textContent).toLowerCase();
const T = { viewport:[W, H], narrow_layout:narrow(), wafer_centre_on_screen:[Math.round(scx), Math.round(scy)], wafer_radius_px:Math.round(Rpx),
T7_the_face_carries_the_disclaimer: face.indexOf('without warranty of any kind') >= 0,
T9_the_disclaimer_is_actually_on_the_screen: faceSeen.indexOf('without warranty of any kind') >= 0,
T10_nothing_is_cut_off_at_the_right_edge: overflows.length === 0, panels_that_overflow: overflows,
visible_face_words: faceSeen.length,
T8_the_face_explains_no_machinery: !/golden|one law|√|sqrt|unresolved pixel/.test(face),
T1_no_permanent_panel_covers_the_wafer: worst >= 0, panels,
T2_the_whole_wafer_is_on_the_screen: onScreen,
T3_the_card_fits: cardFits, card_rect:[cr.left, cr.top, cr.right, cr.bottom].map(Math.round),
T4_one_finger_drags: Math.abs(dragged - 60/z0) < 1e-6, dragged_world_units:+dragged.toFixed(6), expected_world_units:+(60/z0).toFixed(6),
T5_two_fingers_pinch: zB > zA*1.8 && zB <= ZMAX + 1e-9, zoom_before_pinch:+zA.toFixed(6), zoom_after_pinch:+zB.toFixed(6) };
T.PASS = T.T1_no_permanent_panel_covers_the_wafer && T.T2_the_whole_wafer_is_on_the_screen && T.T3_the_card_fits
&& T.T4_one_finger_drags && T.T5_two_fingers_pinch;
T.PASS = T.PASS && T.T7_the_face_carries_the_disclaimer && T.T8_the_face_explains_no_machinery
&& T.T9_the_disclaimer_is_actually_on_the_screen && T.T10_nothing_is_cut_off_at_the_right_edge;
window.__selftest = T; document.title = 'selftest ' + (T.PASS ? 'PASS' : 'FAIL');
}
// LIGHT A PERIOD. "2026-07" or "2026-07-14". Time order makes it one band, so the count is a
// difference of two running totals and the light is one annulus.
function lightTime(y, m, d){
const t0 = Date.UTC(y, m ? m-1 : 0, d || 1)/1000, t1 = d ? t0 + 86400 : Date.UTC(m ? y : y+1, m ? m : 0, 1)/1000;
const i0 = (commits[0].unix >= t0) ? 0 : findBy('unix', t0 - 1) + 1, i1 = (commits[0].unix >= t1) ? 0 : findBy('unix', t1 - 1) + 1;
const label = y + (m ? '-' + String(m).padStart(2,'0') : '') + (d ? '-' + String(d).padStart(2,'0') : '');
litRepo = -1; newFrom = -1; flash = 0; target = null; card.style.display = 'block';
if (i1 <= i0) { litK = [-1,-1]; litCi = null; card.classList.remove('sheet'), card.innerHTML = label + '\nsilence: no commit carries that date'; home(); dirty = true; return null; }
const last = commits[i1-1], lines = last.cum + last.lines - commits[i0].cum, rs = new Set(); for (let i = i0; i < i1; i++) rs.add(commits[i].repo);
litK = [Math.sqrt(commits[i0].k0), Math.sqrt(last.k1)]; litCi = [i0, i1];
card.classList.remove('sheet'), card.innerHTML = 'ENERGISED · ' + label + '\n<b>' + fmt(lines) + '</b> lines in <b>' + fmt(i1 - i0) + '</b> commits across ' + rs.size + ' repositories'
+ '\nkeys ' + fmt(commits[i0].k0) + ' to ' + fmt(last.k1) + ' · one band, because keys run in time order';
home(); dirty = true; return { i0, i1, lines };
}
// TOUCH. Every pointer that is down is held in one map, so one finger drags and two pinch, and a
// mouse is just a pointer with one finger. The pinch keeps the world point between the fingers
// under the fingers, which is the same rule the wheel already obeys, so zooming in on a phone and
// on a desktop land on the same key.
const ZMAX = 60;
let drag = null, moved = 0, pinch = null;
const pts = new Map();
function pinchNow(){ const v = [...pts.values()], a = v[0], b = v[1];
return { d:Math.hypot(a.x-b.x, a.y-b.y), mx:(a.x+b.x)/2, my:(a.y+b.y)/2 }; }
cv.addEventListener('pointerdown', e => {
pts.set(e.pointerId, { x:e.clientX, y:e.clientY });
if (pts.size === 2) { const s = pinchNow(), w = toWorld(s.mx, s.my); pinch = { d0:s.d, z0:zoom, wx:w[0], wy:w[1] }; drag = null; moved = 99; }
else if (pts.size === 1) { drag = [e.clientX, e.clientY]; moved = 0; }
});
addEventListener('pointermove', e => {
if (pts.has(e.pointerId)) pts.set(e.pointerId, { x:e.clientX, y:e.clientY });
if (pinch && pts.size >= 2) { const s = pinchNow(); if (pinch.d0 > 1) {
zoom = Math.max(1e-4, Math.min(ZMAX, pinch.z0 * s.d / pinch.d0));
cx = pinch.wx - (s.mx - innerWidth/2)/zoom; cy = pinch.wy + (s.my - innerHeight/2)/zoom;
atHome = false; tween = null; dirty = true; } return; }
if (!drag) return; moved += Math.abs(e.clientX-drag[0]) + Math.abs(e.clientY-drag[1]);
cx -= (e.clientX-drag[0])/zoom; cy += (e.clientY-drag[1])/zoom; drag = [e.clientX, e.clientY];
atHome = false; tween = null; dirty = true; });
function pointerGone(e){ pts.delete(e.pointerId); if (pts.size < 2) pinch = null; if (pts.size === 0) drag = null; }
addEventListener('pointerup', e => {
if (drag && moved < 4 && N) { const [wx, wy] = toWorld(e.clientX, e.clientY), r = Math.hypot(wx, wy);
if (r*r < SPACE) { let k = zoom >= POINTS_FROM ? keyAt(wx, wy) : -1; const exact = k >= 0; if (!exact) k = Math.floor(r*r);
target = exact ? { x:keyPlace(k)[0], y:keyPlace(k)[1] } : null; show(address(k)); } }
pointerGone(e); });
addEventListener('pointercancel', pointerGone);
addEventListener('wheel', e => { const [wx, wy] = toWorld(e.clientX, e.clientY), f = e.deltaY < 0 ? 1.18 : 1/1.18;
zoom = Math.max(1e-4, Math.min(ZMAX, zoom*f)); cx = wx - (e.clientX - innerWidth/2)/zoom; cy = wy + (e.clientY - innerHeight/2)/zoom;
atHome = false; tween = null; dirty = true; }, { passive:true });
// the tap targets, so a phone can do everything the keyboard can
document.getElementById('keys').addEventListener('click', e => { const k = e.target.getAttribute('data-k'); if (!k) return;
e.stopPropagation(); dispatchEvent(new KeyboardEvent('keydown', { key:k })); });
elTop.addEventListener('click', () => elTop.classList.toggle('open')); // the long subtitle, collapsed by default
// A LINK INSIDE THE CARD IS NOT A DISMISSAL, and neither is reading it: the card is put away with
// its own cross or with Escape, the way the wafer's card is.
card.addEventListener('click', e => {
const a = e.target.closest ? e.target.closest('a') : null;
if (a && a.hasAttribute('data-key')) { e.preventDefault(); goToKey(+a.getAttribute('data-key')); }
});
// GOING TO A KEY, from a link inside a card or from an address a reader arrived with. The camera
// flies, the dot is marked and its card opens: one way of arriving, however the reader got here.
function goToKey(k){
const a = address(k);
if (!a) return;
const p = keyPlace(k);
litK = [k, k + 1]; litCi = null; target = { x:p[0], y:p[1] };
show(a); flyTo(p[0], p[1], Math.max(zoom, 14)); dirty = true;
}
const gbox = document.getElementById('goto'), gin = document.getElementById('gotoin');
gin.addEventListener('keydown', e => { e.stopPropagation(); if (e.key === 'Escape') { gbox.style.display = 'none'; return; }
if (e.key !== 'Enter') return; gbox.style.display = 'none'; const raw = gin.value.trim(), q = raw.replace(/[ ,_]/g,'');
const mt = raw.match(/^(20\d\d)(?:-(\d\d))?(?:-(\d\d))?$/);
if (mt) { lightTime(+mt[1], mt[2] ? +mt[2] : 0, mt[3] ? +mt[3] : 0); return; }
const mnew = raw.toLowerCase().match(/^(?:show\s+)?new(?:\s+code)?(?:\s+(\d+)\s*h?)?$/);
if (mnew) { showNew(mnew[1] ? Number(mnew[1]) : 24); return; }
if (/^\d+$/.test(q)) goKey(Math.min(SPACE-1, Number(q)));
else { const r = repos.find(x => x.name.toLowerCase() === raw.toLowerCase()) || repos.find(x => x.name.toLowerCase().includes(raw.toLowerCase()));
if (r) { litRepo = r.i; target = null; card.style.display = 'none'; home(); dirty = true; } } });
addEventListener('keydown', e => { if (gbox.style.display === 'block') return;
if (e.key === 'd') { detail = !detail; dirty = true; }
else if (e.key === 'r' && N) { const j = Math.floor(Math.random()*N), c = commits[findBy('cum', j)]; goKey(c.k0 + (j - c.cum)); } // uniform over issued lines
else if (e.key === 'n' && N) showNew(24);
else if (e.key === '/') { e.preventDefault(); gbox.style.display = 'block'; gin.value = ''; gin.focus(); }
else if (e.key === 'Backspace') { e.preventDefault(); target = null; litRepo = -1; newFrom = -1; flash = 0; pulse = -1; litK = [-1,-1]; litCi = null; litPath = null; card.style.display = 'none'; home(); } });
requestAnimationFrame(frame);
</script>
</body>
</html>Wafer Development Environment — Proof K0024 Page
A web page in the testcode folder of GlobalGrid2050 that draws link contract, cables, solar and battery storage (BESS), and uses data from the GridAtlas repository. Published at https://globalgrid2050.com/testcode/wafer-development-environment/202609192148-proof-k0024/.
renderglobalgrid2050 / testcode/wafer-development-environment/202609192148-proof-k0024/index.html · lines 1–410 of 1638 · version 2026-09-19 21:48 · Entry point · pattern appFor (shared by 9 files)
- What it does
- It draws link contract, cables, solar and battery storage (BESS). Defines 76 functions or classes, including buildLink, complaints, parseLink, fmt, day. Side effects: changes the web page (DOM); makes network requests.
- Why it exists in the grid workflow
- Domain stage experimental (path word 'testcode'): work its own path marks as experimental (sandbox, prototype, archive or similar words); by this evidence it is not part of a production workflow. Domain terms in the code: cables, solar, battery storage (BESS).
- Inputs & outputs
- In: data source: gridatlas data; JSON file link-contract.json; form fields (user input). Out: web page; WebGL/WebGPU drawing.
- Downstream impact
- Used directly by 5 files: GlobalGrid2050 Homepage Before Four Nests (globalgrid2050, https://globalgrid2050.com/homepage-before-four-nests-20260925.html); Homepage Versions — Before Refresh Page (globalgrid2050, https://globalgrid2050.com/homepage_versions/20260922-before-refresh/); Homepage V123 (globalgrid2050, https://globalgrid2050.com/homepage_versions/homepage_v123.html); Homepage V124 (globalgrid2050, https://globalgrid2050.com/homepage_versions/homepage_v124.html); and 1 more. Reached from 83 other entry points, including GlobalGrid2050 Historical Builds (globalgrid2050, https://globalgrid2050.com/historical_builds.html); Homepage V037 (globalgrid2050, https://globalgrid2050.com/homepage_versions/homepage_v037.html); Homepage V038 (globalgrid2050, https://globalgrid2050.com/homepage_versions/homepage_v038.html). It is itself an entry point, published at https://globalgrid2050.com/testcode/wafer-development-environment/202609192148-proof-k0024/.
- What it achieves
- It builds link (`buildLink`), parses link (`parseLink`) and sets tag (`setTag`). Its `lightTime` function gives commit period summary or null from year, optional month and optional day (VEDIC: period). It reads `cosmos/link-contract.json`. It responds to error, webglcontextlost and resize events.
- Why it matters
- Loaded by the GlobalGrid2050 Homepage Before Four Nests page at https://globalgrid2050.com/homepage-before-four-nests-20260925.html and 4 other pages.
- Application
- globalgrid2050 · testcode/wafer-development-environment/202609192148-proof-k0024 · page
- 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
- Cable Geometry Visualiser V5 (estate URL), GridAtlas — Atlas Page (estate URL), GlobalGrid2050 — Cable Geometry Page (estate URL)
- Used by
- linked from GlobalGrid2050 Homepage Before Four Nests (link), linked from Homepage Versions — Before Refresh Page (link), linked from Homepage V123 (link), linked from Homepage V124 (link), linked from Homepage V125 (link)
- Produces
- buildLink, complaints, parseLink, fmt, day, words, prog, U, tsv, appFor, narrow, resize
- Defines here
- buildLink, complaints, parseLink, fmt, day, words, prog, U, tsv
- Cannot conclude
- Whether this code runs, is used by a live app today, or is correct. This is a static reading.
- Evidence
- globalgrid2050@0aca5121f0795e469b6cf4fc3d3b628edba8d883 testcode/wafer-development-environment/202609192148-proof-k0024/index.html:1-410 · blob 56c818bedba56454098d4fc38959370fed6848e6 · GitHub at these lines
- State
- achieves: code · context: readme_derived · stage: output · effects: dom, network · domain stage: experimental · users: none · canonical: production_core
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1,viewport-fit=cover">
<title>Kuiper belt</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}
/* ===== THE POP CARD =========================================================================
The wafer's card, class for class. Black ground, a #444 edge, monospace, an amber title, grey
detail, cyan for anything that leads somewhere, and a state chip written from one place so the
card can never say two things at once. Nothing here is a new idea; it is the card this estate
already argued through, brought over rather than approximated for a third time. */
#card{position:fixed;z-index:10;left:8px;right:8px;bottom:8px;
max-height:64vh;overflow:auto;-webkit-overflow-scrolling:touch;overscroll-behavior:contain;
background:#000;color:#d8dee9;border:1px solid #444;border-radius:4px;
font:12px/1.45 ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;
padding:8px 10px 12px;box-shadow:0 1px 8px #000c;white-space:normal;display:none;max-width:none}
#card .cc-x{position:sticky;float:right;top:0;background:#000;border:0;color:#888;font:inherit;
font-size:18px;cursor:pointer;padding:0 6px;line-height:1.2}
#card .cc-title{display:inline;color:#ffd54a;font-size:13px;font-weight:bold}
#card .cc-grey{color:#888}
#card .cc-amber{color:#ffae00}
#card .cc-small{color:#666;font-size:10.5px;margin:.2rem 0}
#card .cc-tagline{margin:.35rem 0 .25rem}
#card .cc-tag{display:inline-block;font:600 10px/1 ui-monospace,monospace;padding:.2rem .35rem;
border:1px solid currentColor;border-radius:3px;margin-right:.4rem;letter-spacing:.06em}
#card .cc-tag[data-s="WAIT"]{color:#9aa3b5} #card .cc-tag[data-s="LOAD"]{color:#ffd54a}
#card .cc-tag[data-s="OK"]{color:#00ffff} #card .cc-tag[data-s="EMPTY"]{color:#b39ddb}
#card .cc-tag[data-s="FAIL"]{color:#ff9f43}
#card .cc-row{margin:.25rem 0;overflow-wrap:anywhere}
#card .cc-dl{display:grid;grid-template-columns:auto 1fr;gap:.15rem .6rem;margin:.4rem 0}
#card .cc-dl dt{color:#888}
#card .cc-dl dd{margin:0;overflow-wrap:anywhere}
#card .cc-link,#card a{color:#00ffff}
#card .cc-codehead{color:#888;font-size:11px;overflow-wrap:anywhere;margin:.4rem 0 .2rem}
#card .cc-check{color:#aaa;font-size:11px;margin:.1rem 0 .3rem}
/* ONE <pre>, ONE TEXT NODE. The numbers are part of the text, so copying the code copies what is
on the screen, and the tapped line is marked by a bar placed from the line height. */
#card .cc-code{position:relative;max-height:34vh;overflow:auto;margin:0;padding:6px 8px;
background:#0a0a0a;border:1px solid #333;
font:11px/16px ui-monospace,Consolas,monospace;white-space:pre;tab-size:4;color:#d8dee9}
#card .cc-hi{position:absolute;left:0;right:0;min-width:100%;pointer-events:none}
#card .cc-hi-target{background:#ffd54a26;border-left:3px solid #ffd54a}
#card .cc-refuse{color:#ffae00;overflow-wrap:anywhere}
/* THE APP TILE: the biggest thing on the card, and the whole of it is the tap target. A person who
signs should see in ten seconds what this is for and where to open it. */
#card .cc-tile{display:block;border:1px solid #00ffff;border-radius:6px;padding:14px 14px 12px;
margin:4px 0 10px;text-decoration:none;background:#061018;clear:both}
#card .cc-tile-name{font:800 22px/1.1 -apple-system,'Segoe UI',sans-serif;color:#fff;letter-spacing:.06em;margin-bottom:.6rem}
#card .cc-tile-part{color:#00ffff;font-size:10.5px;letter-spacing:.12em;text-transform:uppercase;margin-bottom:.3rem}
#card .cc-source{margin-top:.5rem;text-align:right;font-size:10.5px}
#card .cc-source a{color:#666}
#card .cc-tile-what{color:#d8dee9;font-size:13px;margin:0 0 .75rem;line-height:1.4}
#card .cc-tile-open{display:block;text-align:center;padding:.65rem 0;border:1px solid #00ffff;
border-radius:4px;color:#00ffff;font-weight:bold;letter-spacing:.08em;font-size:13px}
#card .cc-notile{clear:both;margin:4px 0 10px;padding:10px 12px;border:1px solid #333;border-radius:6px;color:#aaa}
/* THE BRAND BLOCK, COPIED FROM GRIDATLAS AS IT STANDS. Not redesigned, and no logo invented. */
#card .scada-brand{display:flex;align-items:center;gap:8px;padding-bottom:8px;margin-bottom:8px;border-bottom:1px solid #222;flex-shrink:0}
#card .scada-brand-main{font-family:-apple-system,sans-serif;font-size:11px;font-weight:800;color:#fff;letter-spacing:4px;text-transform:uppercase}
#card .scada-brand-sub{font-family:-apple-system,sans-serif;font-size:6px;color:#555;letter-spacing:2px;text-transform:uppercase}
#card .cc-plain{color:#d8dee9;margin:.2rem 0 .4rem}
#card .cc-q{margin-top:.5rem;border-top:1px solid #333;padding-top:.3rem}
#card .cc-q summary{color:#00ffff;cursor:pointer;letter-spacing:.06em;padding:.4rem 0}
#card .cc-disclaimer{color:#888;font-size:10.5px;margin-top:.4rem;border-left:2px solid #444;padding-left:.4rem}
#card .popup-btn{display:block;width:100%;margin:.4rem 0;padding:.45rem 0;font:inherit;font-size:11px;
font-weight:bold;border:1px solid #00ffff;border-radius:3px;background:#0a0a0a;color:#00ffff;
cursor:pointer;letter-spacing:.06em}
/* THE CARD IS A WINDOW, the way the wafer's card is a window: it opens in a corner rather than
across the work, it carries nothing but what was asked for, and it can be dragged by its bar,
folded to the bar, thrown wide or put away. touch-action:none on the bar is load bearing: without
it a finger scrolls the page instead of moving the card. */
#use{margin-top:5px;color:#8fb3bd;max-width:62ch}
#foot .short{display:none}
#foot,#foot span{overflow-wrap:anywhere}
#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}
#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{max-height:58vh}
#foot{padding:7px 10px}
#foot .long{display:none} #foot .short{display:block;margin-top:6px}
#keys button{padding:9px 11px}
#goto{min-width:0;left:8px;right:8px;transform:none;top:30%}
}
@media (min-width:760px){
/* ON A WIDE SCREEN IT IS A COLUMN ON THE RIGHT, out of the way of the thing it describes. */
#card{left:auto;right:14px;width:34rem;max-width:calc(100vw - 28px);bottom:auto;top:96px;max-height:72vh}
}
</style>
</head>
<body>
<canvas id="c"></canvas><canvas id="o"></canvas>
<div id="top"><div id="big">loading</div><div id="sub"> </div>
<div id="use">The engineering behind this site: every calculation, drawing and data set, in the order it was built. Tap a dot to see the work and its date. Not a design and not a connection offer.</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="Backspace">whole view</button></div>
<span class="long"><b>tap a dot</b> to light its repository · <b>drag</b> to move · <b>pinch or scroll</b> to zoom
· <b>n</b> new code · <b>r</b> random line · <b>/</b> find a key, a repository or a month
· <b>backspace</b> whole view · provided as is, without warranty of any kind; a chart, not a design</span>
<span class="short">provided as is, without warranty of any kind; a chart, not a design</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' });
// A PAGE THAT THROWS MUST SAY SO. It used to sit at "starting" for ever, which reads as a slow
// network rather than as a page that fell over on its first line.
addEventListener('error', ev => { const h = document.getElementById('hud');
if (h) h.textContent = 'THIS PAGE STOPPED: ' + (ev.message || ev.error) + ' (' + (ev.filename||'') + ':' + (ev.lineno||0) + ')'; });
const hud = document.getElementById('hud'), big = document.getElementById('big'),
sub = document.getElementById('sub'), card = document.getElementById('card');
// ================= THE LINK CONTRACT =================================================
// ONE PLACE WHERE AN ADDRESS IS MADE AND ONE PLACE WHERE IT IS READ. Before this, a link was an
// agreement between two halves of this file that never met: one half wrote a question mark and a
// parameter name, the other half looked one up, and nothing checked that the two still agreed.
// The parameters are DATA, so a new one is a row and not a new idea; build and parse are the only
// two functions that touch an address; and the page proves on itself that parsing a link it built
// returns exactly what it started with. cosmos/link-contract.json is the same table published for
// anything that cannot read this page.
const LINK = Object.freeze({
params: Object.freeze({
key: Object.freeze({ kind:'whole number', note:'one line of one piece of work' }),
path: Object.freeze({ kind:'text', note:'a file or folder whose work is highlighted' }),
selftest: Object.freeze({ kind:'text', note:'ask the page to check itself and say so in its title' })
})
});
// AN UNKNOWN PARAMETER IS REFUSED, NOT IGNORED. A link that carries something nobody reads looks
// like it works and does nothing, which is the failure this contract exists to prevent.
function buildLink(o, base){
const q = new URLSearchParams();
for (const k of Object.keys(o || {}))
if (!Object.prototype.hasOwnProperty.call(LINK.params, k))
throw new Error('buildLink: no parameter called ' + k + '; the contract has ' + Object.keys(LINK.params).join(', '));
// THE ORDER IS THE CONTRACT'S, NOT THE CALLER'S, so the same request always makes the same address
// and two links can be compared as text.
for (const k of Object.keys(LINK.params)) {
const v = (o || {})[k];
if (v === undefined || v === null || v === '') continue;
if (LINK.params[k].kind === 'whole number' && !/^[0-9]+$/.test(String(v)))
throw new Error('buildLink: ' + k + ' is a whole number, not ' + v);
q.set(k, String(v));
}
const tail = q.toString();
return (base ? String(base) : '') + (tail ? '?' + tail : '');
}
// WHAT AN ADDRESS ASKED FOR THAT THIS PAGE CANNOT ANSWER, in sentences it can put on the screen.
// Two kinds: a name the contract has no row for, and a value of the wrong kind for a name it has.
function complaints(href){
const u = new URL(String(href), 'https://example.invalid/'), said = [], unknown = [];
for (const k of u.searchParams.keys())
if (!Object.prototype.hasOwnProperty.call(LINK.params, k) && unknown.indexOf(k) < 0) unknown.push(k);
if (unknown.length)
said.push('This address asks for ' + unknown.join(', ') + ', which this page does not use.');
for (const k of Object.keys(LINK.params)) {
const raw = u.searchParams.get(k);
if (raw !== null && raw !== '' && parseLink(href)[k] === null)
said.push('This address gives ' + k + ' as "' + raw + '", and ' + k + ' is a ' + LINK.params[k].kind + '.');
}
return said;
}
function parseLink(href){
const u = new URL(String(href), 'https://example.invalid/');
const out = {};
for (const k of Object.keys(LINK.params)) {
const raw = u.searchParams.get(k);
if (raw === null || raw === '') { out[k] = null; continue; }
out[k] = LINK.params[k].kind === 'whole number'
? (/^[0-9]+$/.test(raw) ? Number(raw) : null)
: raw;
}
return out;
}
// ================= end of the link contract ==========================================
const fmt = n => Math.round(n).toLocaleString('en-GB');
// A DAY A PERSON CAN READ. Every date on this page comes through here, so the card header and
// the readout can never disagree about how a day is written.
const MON = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
function day(unix){ if (!unix) return ''; const t = new Date(unix * 1000);
return t.getUTCDate() + ' ' + MON[t.getUTCMonth()] + ' ' + t.getUTCFullYear(); }
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); }
if (!gl) { hud.textContent = 'WebGL2 is not available. Refusing rather than drawing a fraction.'; throw 0; }
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;
uniform sampler2D u_pathf; uniform int u_litPath; // one texel per commit: did this page's path change in it
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 PAGE IS A SCATTER, NOT A BAND. A repository is a contiguous span and a month is an annulus,
// but one file is neither: it was touched on nineteen separate days, so it lights nineteen separate
// runs of keys with other people's work between them. The flag rides in its own texture, one texel
// per commit, so the commit table that every other reading depends on is not touched to do it.
if (u_litPath == 1) { float kc = r*r; int i = find(kc); vec4 c = C(i);
if (kc <= c.g && texelFetch(u_pathf, ivec2(i % ${TW}, i / ${TW}), 0).r > 0.5)
col = mix(col, vec3(1.0,0.17,0.84), u_points > 0.5 ? 0.12 : 0.80); }
// 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;
hud.textContent = '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 = [];
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'),
tsv('cosmos/cards/list.tsv').catch(() => []),
tsv('cosmos/public.tsv').catch(() => []),
tsv('cosmos/apps.tsv').catch(() => []),
tsv('cosmos/journeys.tsv').catch(() => []),
tsv('cosmos/pages.tsv').catch(() => []),
tsv('cosmos/work-pages.tsv').catch(() => []),
tsv('cosmos/work-fronts.tsv').catch(() => [])]).then(([rr, ww, cc, pp, aa, jj, pg, wp, wf]) => {
// WORK THAT ONLY REACHES THE FRONT DOOR OF ITS SITE. Walking up from it found no page before the top.
// That is not a page of its own and is never counted or shown as one; it is a front door, said so.
for (const p of wf) frontOfWork[p[0]] = p[1];
// THE NEAREST PAGE TO EVERY PIECE OF WORK, worked out beforehand from where its files sit and
// written down only where the address answered. This page looks the answer up and never guesses.
for (const p of pg) pageById[p[0]] = { address:p[1], title:p[2] || '' };
for (const p of wp) if (pageById[p[1]]) pageOfWork[p[0]] = pageById[p[1]];
// WHAT EACH APPLICATION DOES FOR A PROJECT, in one plain sentence, from the table that is checked
// for truth. Matched by the address the application is opened at, never by its name; an
// application with no checked sentence gets none, rather than one written here to fill the space.
for (const p of jj) if (p[0] !== 'journey' && p[4] && !whatItDoes[p[4]]) whatItDoes[p[4]] = p[3];
// THE APPLICATIONS, AS DATA: a name for the button, a repository, the folders inside it that are
// this application (none means all of it), and the address where it runs. A new application is a
// row in that table and never a line of this page.
apps = aa.filter(p => p[0] !== 'app').map(p => ({ app:p[0], button:p[1], repo:(p[2] || '').toLowerCase(),
prefixes:(p[3] || '').split(';').map(x => x.trim()).filter(Boolean), live:p[4] }));
// WHO OWNS EACH PIECE OF WORK, AND WHETHER ANYBODY MAY SEE IT. A link is only honest for a
// repository GitHub says is public: for anything else the address itself would put a private name
// in front of a reader, and the link would be a dead end for everyone but its owner.
const owners = new Map(pp.map(p => [p[0], { owner:p[1], pub:p[2] === 'yes' }]));
cards = cc.map(p => ({ path:p[0], repo:p[1], k0:+p[2], lines:+p[3], file:p[4], commit:p[5],
here:p[6] === 'yes', owner:p[7], unix:+p[8], toolApp:p[9] || '',
page:p[10] ? { address:p[10], title:p[11] || '' } : null }));
repos = rr.map(p => { const o = owners.get(p[1]) || { owner:'', pub:false };
return { i:+p[0], name:p[1], lines:+p[2], seen:0, commits:0, owner:o.owner, pub:o.pub }; });
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++;
if (!repos[c.repo].t0) repos[c.repo].t0 = c.unix; repos[c.repo].t1 = c.unix; // commits are in time order
return c; });
const bad = repos.find(r => r.seen !== r.lines);
if (bad) { hud.textContent = 'REFUSED: the commits of ' + bad.name + ' sum to ' + fmt(bad.seen) + ', the belt says ' + fmt(bad.lines); return; }
N = issued; SPACE = k;
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);
pathFlags = new Float32Array(TW * H); pathTex = gl.createTexture();
gl.activeTexture(gl.TEXTURE1); gl.bindTexture(gl.TEXTURE_2D, pathTex);
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.R32F, TW, H, 0, gl.RED, gl.FLOAT, pathFlags);
pathRows = H; commits.forEach((c, i) => bySha.set(c.sha, i)); gl.activeTexture(gl.TEXTURE0);
big.textContent = 'Engineering record';
sub.textContent = fmt(commits.length) + ' pieces of work across ' + repos.length + ' areas, '
+ new Date(commits[0].unix*1000).toISOString().slice(0,10) + ' to '
+ new Date(commits[commits.length-1].unix*1000).toISOString().slice(0,10)
+ ' · oldest in the middle, newest at the edge';
home(); dirty = true;
// HOW THIS READER ARRIVED, read once, by the contract, and never from the address bar again.
const ARRIVED = parseLink(location.href);
// AND WHAT THE ADDRESS ASKED FOR THAT THIS PAGE CANNOT ANSWER. Building such a link was already
// refused; arriving with one said nothing at all, and saying nothing is how a reader concludes
// that the page is broken rather than that the address is.
{ const said = complaints(location.href);
// KEPT, so the page can be asked afterwards what it said about the address it was given.
window.__arrival = { said, shown:null };
if (said.length) { card.classList.remove('sheet'); card.style.display = 'block';
card.innerHTML = said.map(esc).join('\n')
+ '\nIt shows what it can. An address here may carry ' + Object.keys(LINK.params).join(', ') + '.';
window.__arrival.shown = card.textContent; } }
{ const st = ARRIVED.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 (ARRIVED.selftest === 'new') { selftest = {}; tween = null; setTimeout(() => showNew(24), 300); }
if (ARRIVED.selftest === 'phone') setTimeout(phoneSelftest, 500);
{ const mr = (ARRIVED.selftest || '').match(/^repo:(.+)$/);
if (mr) setTimeout(() => repoSelftest(decodeURIComponent(mr[1])), 500); }
{ const mc = (ARRIVED.selftest || '') === 'card';
// A TEST THAT CANNOT RUN MUST FAIL, NOT GO QUIET. This one threw on a name that did not exist