In this section
- Android Journey render · kuiper-belt / editions/202611012135/handoff/10-integration/android-journey.cjs lines 457–474
- Lead Test test · kuiper-belt / editions/202611012135/handoff/12-see-through-reader/lead-test.cjs lines 1–191
- Rerun render · kuiper-belt / editions/202611012135/handoff/12-see-through-reader/rerun.cjs lines 1–60
- Shots render · kuiper-belt / editions/202611012135/handoff/12-see-through-reader/shots.cjs lines 1–27
- Test test · kuiper-belt / editions/202611012135/handoff/12-see-through-reader/test.cjs lines 1–251
- Hello render · kuiper-belt / editions/202611012135/modules/202611012145-hello.js lines 1–19
- Loader render · kuiper-belt / editions/202611012135/modules/202611012145-loader.js lines 1–133
Android Journey
A JavaScript module in the handoff folder of Kuiper Belt that runs device (`runDevice`), opens panel (`openPanel`), converts to screen (`toScreen`) and calculates planar distances.
renderkuiper-belt / editions/202611012135/handoff/10-integration/android-journey.cjs · lines 457–474 of 474 · version 2026-11-01 21:35 (continued from section 1514) · Entry point · pattern errPush (shared by 2 files)
- What it does
- It draws its content. Defines 36 functions or classes, including flag, slug, sleep, probeFn, R. Uses libraries playwright, fs, path. Side effects: changes the web page (DOM); reads or writes files; makes network requests; starts processes.
- Why it exists in the grid workflow
- Domain stage agent_infra (path word 'handoff'): AI-agent memory, coordination and code audit (the multi-agent journey named in Ventus Ltd's brief).
- Inputs & outputs
- In: JSON file keys.json; JSON file modules.json; command-line arguments. Out: JSON file report.json; canvas drawing.
- Downstream impact
- It is itself an entry point (JavaScript module); no other file was found loading it.
- What it achieves
- It runs device (`runDevice`) and opens panel (`openPanel`). Defines `flag`, `slug`, `sleep` and 30 more. It reads `keys.json`.
- Why it matters
- No other file in the estate was found to import it; it is an entry point.
- Application
- kuiper-belt · editions/202611012135/handoff/10-integration · JavaScript module
- Uses
- playwright, fs, path
- Used by
- none found
- Produces
- flag, slug, sleep, probeFn, R, vis, q, panelEl, panelOpen, cq, hitAt, waferFromPng
- Defines here
- none
- 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/202611012135/handoff/10-integration/android-journey.cjs:457-474 · blob 0b81d694b81c29ec664b1b0cd87eebe8c2ec92b2 · GitHub at these lines
- State
- achieves: name · context: readme_derived · stage: output · effects: dom, filesystem, network, process · domain stage: agent_infra · users: ai_agent · canonical: unknown
report.consoleErrors = errors.slice(); report.offPageErrors = offPageErrors.slice(); report.pass = steps.every(s => s.pass); report.passed = steps.filter(s => s.pass).length; report.failed = steps.filter(s => !s.pass).length;
report.finishedAt = new Date().toISOString();
await context.close();
return report;
}
(async () => {
fs.mkdirSync(OUT, { recursive: true });
const browser = await chromium.launch({ args: ['--use-gl=angle', '--use-angle=swiftshader', '--enable-unsafe-swiftshader', '--ignore-gpu-blocklist'] });
const out = { url: URL0, outdir: OUT, generatedAt: new Date().toISOString(), devices: [] };
try { for (const d of DEVICES) { out.devices.push(await runDevice(browser, d)); fs.writeFileSync(path.join(OUT, 'report.json'), JSON.stringify(out, null, 1)); } }
finally { await browser.close(); }
out.pass = out.devices.every(d => d.pass);
out.summary = out.devices.map(d => ({ device: d.device, passed: d.passed, failed: d.failed, failedSteps: d.steps.filter(s => !s.pass).map(s => s.id), consoleErrors: d.consoleErrors.length }));
fs.writeFileSync(path.join(OUT, 'report.json'), JSON.stringify(out, null, 1));
console.log(JSON.stringify(out, null, 1));
process.exit(out.pass ? 0 : 1);
})().catch(e => { console.error(e); process.exit(2); });Lead Test
A JavaScript module in the handoff folder of Kuiper Belt that tests wafer meta and substations.
testkuiper-belt / editions/202611012135/handoff/12-see-through-reader/lead-test.cjs · lines 1–191 of 191 · version 2026-11-01 21:35 · Entry point · pattern repoCount (shared by 2 files)
- What it does
- It tests wafer meta and substations. Defines 12 functions or classes, including sleep, fmt, key, repoCount, rows. Uses libraries playwright, fs, path. Side effects: changes the web page (DOM); reads or writes files; starts processes.
- Why it exists in the grid workflow
- Domain stage agent_infra (path word 'handoff'): AI-agent memory, coordination and code audit (the multi-agent journey named in Ventus Ltd's brief). Domain terms in the code: substations.
- Inputs & outputs
- In: JSON file wafer-meta.json; command-line arguments. Out: JSON file report.json.
- Downstream impact
- It is itself an entry point (JavaScript module); no other file was found loading it.
- What it achieves
- It is built from the repo count helper (`repoCount`), the rows step (`rows`) and the check step (`check`). Defines `sleep`, `fmt`, `key` and 8 more.
- Why it matters
- No other file in the estate was found to import it; it is an entry point.
- Application
- kuiper-belt · editions/202611012135/handoff/12-see-through-reader · JavaScript module
- Uses
- playwright, fs, path
- Used by
- none found
- Produces
- sleep, fmt, key, repoCount, rows, check, newPage, done, open, st, shot, waitArrive
- Defines here
- sleep, fmt, key, repoCount, rows, check, newPage, done, open, st, shot, waitArrive
- 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/202611012135/handoff/12-see-through-reader/lead-test.cjs:1-191 · blob fa802f51130f935aa41436d4643497165b83aac2 · GitHub at these lines
- State
- achieves: name · context: readme_derived · stage: output · effects: dom, filesystem, process · domain stage: agent_infra · users: ai_agent · canonical: unknown
#!/usr/bin/env node
// test.cjs Opus team 12 "See Through hash reader": every hash form of see-through/202611020012/ on Pixel 7, through the
// stable pointer see-through/ served from the kuiper-belt root. Real touch for taps. Zero console errors apart from the
// sandbox's blocked map hosts (listed in IGNORE). Usage: node test.cjs [base=http://127.0.0.1:8601] [outdir]
'use strict';
const { chromium, devices } = require('playwright');
const fs = require('fs'), path = require('path');
const BASE = process.argv[2] || 'http://127.0.0.1:8601';
const OUT = path.resolve(process.argv[3] || '/tmp/nl010-opus/team-12/tester/out');
const ROOT = process.env.KB_ROOT || '/home/user/estate/kuiper-belt';
const STAMP = '202611020012', NRULE = 20000, NSUB = 5800;
const IGNORE = /basemaps\.cartocdn\.com/;
fs.mkdirSync(OUT, { recursive: true });
const sleep = ms => new Promise(r => setTimeout(r, ms));
const meta = JSON.parse(fs.readFileSync(path.join(ROOT, 'cosmos/wafer-meta.json'), 'utf8'));
const SPACE = meta.address_space;
const fmt = n => Number(n).toLocaleString('en-US');
const key = (j, sp) => Math.floor((j + 0.5) * sp / NRULE);
// independent count for #repo=gridatlas: walk cosmos/wafer.tsv as the engine does, count the phone's 12,900 star keys inside
function repoCount(name, np) {
const rows = f => fs.readFileSync(path.join(ROOT, 'cosmos', f), 'utf8').split('\n').filter(l => l && l[0] !== '#').map(l => l.split('\t'));
const ri = +rows('repos.tsv').find(r => r[1].toLowerCase() === name)[0];
const ranges = []; let k = 0;
for (const p of rows('wafer.tsv')) { k += +p[4]; const k0 = k; k += +p[1]; if (+p[2] === ri) ranges.push([k0, k]); }
let n = 0;
for (let q = 0; q < np; q++) { const ki = (np < NRULE && q >= NSUB) ? NSUB + 2 * (q - NSUB) : q, kk = key(ki, SPACE); if (ranges.some(r => kk >= r[0] && kk < r[1])) n++; }
return n;
}
const results = []; const errors = [];
function check(name, ok, got) { results.push({ name, ok: !!ok, got }); console.log((ok ? 'PASS ' : 'FAIL ') + name + ' ' + JSON.stringify(got)); }
(async () => {
// one browser per case: the 3D rise of an arrival keeps SwiftShader's GPU process busy for minutes, and that process is
// shared by every page of a browser, so a fresh browser keeps one case from stalling the next
async function newPage() {
const browser = await chromium.launch({ args: ['--use-gl=angle', '--use-angle=swiftshader', '--enable-unsafe-swiftshader', '--ignore-gpu-blocklist'] });
const ctx = await browser.newContext({ ...devices['Pixel 7'] });
const page = await ctx.newPage(); page.__b = browser; return page;
}
const done = async page => { await page.__b.close().catch(() => {}); };
async function open(hash, opts = {}) {
const page = await newPage();
page.on('console', m => { if (m.type() === 'error' && !IGNORE.test(m.text() + ' ' + JSON.stringify(m.location()))) errors.push({ hash, text: m.text(), url: m.location().url }); });
page.on('pageerror', e => errors.push({ hash, text: 'pageerror ' + e.message }));
page.on('requestfailed', r => { if (!IGNORE.test(r.url())) errors.push({ hash, text: 'requestfailed ' + r.url() + ' ' + (r.failure() || {}).errorText, soft: true }); });
if (opts.route) await opts.route(page);
await page.goto(BASE + (opts.path || '/see-through/') + hash, { waitUntil: 'load' });
await page.waitForFunction(() => window.__descent && window.__descent.state(), null, { timeout: 30000 });
await sleep(opts.wait || 7000);
return page;
}
const st = p => p.evaluate(() => window.__descent.state());
async function shot(page, name) { // CDP capture: Playwright's own screenshot waits on a frame the 3D WebGL rise may hold for minutes under SwiftShader
try { await page.screenshot({ path: path.join(OUT, name + '.png'), timeout: 60000 }); return; } catch (e) { console.log('playwright screenshot slow, CDP: ' + name); }
try { const c = await page.context().newCDPSession(page);
const r = await Promise.race([c.send('Page.captureScreenshot', { format: 'png' }), sleep(90000).then(() => null)]);
if (r) fs.writeFileSync(path.join(OUT, name + '.png'), Buffer.from(r.data, 'base64')); else console.log('screenshot timed out: ' + name);
await c.detach().catch(() => {});
} catch (e) { console.log('screenshot failed: ' + name + ' ' + e.message); }
}
async function waitArrive(page, t = 120000) { try { await page.waitForFunction(() => { const s = window.__descent.state(); return s.T >= 0 && s.D > 7.99 && !s.flight; }, null, { timeout: t }); } catch (e) {} }
const k1182 = key(1182, SPACE), k1368 = key(1368, SPACE), old1182 = key(1182, 59637070538);
// pointer: forwards search and hash to the stamp
let p = await open('#sub=Drax', { wait: 1500 });
await waitArrive(p);
let s = await st(p);
check('#sub=Drax flies to 1182 Drax, D 8', s.T === 1182 && s.name === 'Drax' && s.D > 7.99, { T: s.T, name: s.name, D: s.D });
const wantHash = '#key=' + k1182 + '&space=' + SPACE + '&sub=Drax';
const h = await p.evaluate(() => location.hash), lk = await p.evaluate(() => window.__descent.link());
check('arrival writes ' + wantHash, h === wantHash && lk === wantHash, { hash: h, link: lk, space: s.space, spaceSource: s.spaceSource });
check('spaceSource wafer-meta, space = cosmos address_space', s.spaceSource === 'wafer-meta' && s.space === SPACE, { space: s.space, src: s.spaceSource });
await done(p);
// the STAR KEY row (with view=kuiper, so the page stays in the 2D kuiper view instead of rising into 3D, whose WebGL under
// SwiftShader holds the renderer for minutes; the rise is unchanged from 202610050609)
p = await open('#sub=Drax&view=kuiper', { path: '/see-through/?from=test', wait: 1500 });
check('pointer forwards search+hash to ' + STAMP, p.url().includes('/see-through/' + STAMP + '/?from=test#sub=Drax&view=kuiper'), p.url());
await waitArrive(p); await sleep(2500);
s = await st(p);
check('#sub=Drax&view=kuiper: arrives at 1182 in the kuiper view', s.T === 1182 && s.view === 'kuiper' && !s.in3d, { T: s.T, view: s.view, in3d: s.in3d });
const row = await p.evaluate(() => { const a = document.querySelector('a[data-st="kuiper-key"]'); if (!a) return null; const r = a.getBoundingClientRect(); return { text: a.textContent, href: a.getAttribute('href'), h: r.height, x: r.left + r.width / 2, y: r.top + r.height / 2, vis: getComputedStyle(a).display !== 'none' }; });
check('STAR KEY row: text, href ../../editions/#key=<k>, >= 44 px', row && row.vis && row.text === 'STAR KEY ' + fmt(k1182) + ' · OPEN IT ON THE KUIPER' && row.href === '../../editions/#key=' + k1182 && row.h >= 44, row);
await shot(p, '01-sub-drax-star-key-row');
if (row) {
await p.touchscreen.tap(row.x, row.y);
await p.waitForURL(/\/editions\/\d{12}\/#key=/, { timeout: 90000 }).catch(() => {});
check('tap on the row opens the Kuiper at #key=<k> through the editions pointer', /\/editions\/\d{12}\/#key=(\d+)$/.test(p.url()) && p.url().endsWith('#key=' + k1182), p.url());
await p.goBack({ timeout: 90000 }).catch(e => console.log('goBack: ' + e.message.split('\n')[0])); await sleep(4000);
check('back returns to See Through', p.url().includes('/see-through/' + STAMP + '/'), p.url());
}
await done(p);
for (const [hash, test, label] of [
['#sub=xyzzy', s => s.T === -1 && s.note === 'NO SUBSTATION NAME HERE CONTAINS THAT. TRY ANOTHER NAME', '#sub=xyzzy refusal words, no flight'],
['#sub=Hinkley', s => s.T === 1892, '#sub=Hinkley first substring match 1892'],
['#sub=Cowley', s => s.T === 201, '#sub=Cowley 201'],
]) { p = await open(hash, { wait: 3000 }); await sleep(1500); s = await st(p); check(label, test(s), { T: s.T, name: s.name, note: s.note }); await done(p); }
// key: a line of code, one amber ring at KuiperLaw.place(k)
p = await open('#key=36064705400');
s = await st(p);
const ring = await p.evaluate(() => {
const d = window.__descent, s = d.state(), Rw = Math.sqrt(s.space + 0.5), ks = s.Rpx / Rw;
const a = window.KuiperLaw.place(d.subKey(0)), sa = d.screenOf(0), cx = sa[0] - a.x * ks, cy = sa[1] + a.y * ks;
const b = window.KuiperLaw.place(d.subKey(1)), sb = d.screenOf(1);
const k = window.KuiperLaw.place(36064705400), r = d.ring();
return { ring: r, want: { x: cx + k.x * ks, y: cy - k.y * ks }, starCheck: Math.hypot(sb[0] - (cx + b.x * ks), sb[1] - (cy - b.y * ks)) };
});
const rd = ring.ring ? Math.hypot(ring.ring.x - ring.want.x, ring.ring.y - ring.want.y) : 99;
check('#key=36064705400: note, T -1, D 0, ring within 1 px of KuiperLaw.place(k)', s.T === -1 && s.D < 0.01 && s.note === 'KEY 36,064,705,400 · A LINE OF CODE, NOT A SUBSTATION' && rd <= 1 && ring.starCheck <= 1, { note: s.note, D: s.D, ringPx: +rd.toFixed(3), star1Px: +ring.starCheck.toFixed(3) });
await shot(p, '02-key-line-of-code-amber-ring');
await done(p);
p = await open('#key=' + k1182); s = await st(p);
let box = await p.evaluate(() => document.querySelector('input').value);
check('#key=<subKey 1182>: box Drax, THE STAR THAT LANDS ON DRAX', box === 'Drax' && s.note.startsWith('THE STAR THAT LANDS ON DRAX') && s.T === -1, { box, note: s.note });
await done(p);
p = await open('#key=' + SPACE); s = await st(p);
check('#key=<SPACE>: IS BEYOND THIS SKY', /^KEY [\d,]+ IS BEYOND THIS SKY/.test(s.note), { note: s.note });
await done(p);
p = await open('#key=' + old1182 + '&space=59637070538'); s = await st(p);
box = await p.evaluate(() => document.querySelector('input').value);
check('#key=<old key>&space=59637070538: SPACE remap to the star of Drax', box === 'Drax' && s.note.startsWith('STAR KEY REMAPPED · SKY 59,637,070,538 → ' + fmt(SPACE)), { box, note: s.note });
await shot(p, '03-key-space-remap');
await done(p);
p = await open('#key=' + k1368 + '&space=' + SPACE + '&sub=Drax', { wait: 2000 }); await waitArrive(p); s = await st(p);
check('#key=<subKey 1368>&space&sub=Drax: identity wins, flies to 1368 (the second Drax)', s.T === 1368 && s.name === 'Drax', { T: s.T, name: s.name });
await done(p);
const want = repoCount('gridatlas', 12900);
p = await open('#repo=gridatlas', { wait: 9000 }); s = await st(p);
const lit = await p.evaluate(() => window.__descent.repoLit());
check('#repo=gridatlas: note count equals the count from wafer.tsv (' + want + ')', s.note === 'GRIDATLAS · ' + fmt(want) + ' OF 12,900 STARS' && lit === want && s.NP === 12900, { note: s.note, lit });
await shot(p, '04-repo-gridatlas-lit');
await done(p);
p = await open('#repo=nosuchrepo', { wait: 9000 }); s = await st(p);
check('#repo=nosuchrepo refusal', s.note === 'NO REPOSITORY CALLED NOSUCHREPO', { note: s.note }); await done(p);
p = await open('#sub=Cowley&view=sat', { wait: 2000 }); await waitArrive(p); await sleep(1500); s = await st(p);
check('#sub=Cowley&view=sat: view after the flight', s.T === 201 && s.view === 'sat', { T: s.T, view: s.view }); await done(p);
p = await open('#bogus=1'); s = await st(p);
check('#bogus=1: LINK FIELD BOGUS NOT UNDERSTOOD', s.note === 'LINK FIELD BOGUS NOT UNDERSTOOD', { note: s.note }); await done(p);
// hashchange on a loaded page
p = await open(''); await p.evaluate(() => { location.hash = '#sub=Drax'; }); await waitArrive(p); s = await st(p);
check('hashchange #sub=Drax on an open page flies', s.T === 1182, { T: s.T }); await done(p);
// the sky: adopted from wafer-meta when it differs; frozen when it cannot be read
p = await open('', { route: pg => pg.route('**/cosmos/wafer-meta.json', r => r.fulfill({ contentType: 'application/json', body: JSON.stringify({ ...meta, address_space: SPACE + 1000 }) })) });
s = await st(p); let sk = await p.evaluate(() => window.__descent.subKey(1182));
check('wafer-meta address_space adopted at run time', s.space === SPACE + 1000 && s.spaceSource === 'wafer-meta' && sk === key(1182, SPACE + 1000), { space: s.space, src: s.spaceSource, k1182: sk });
await done(p);
p = await open('', { route: pg => pg.route('**/cosmos/wafer-meta.json', r => r.abort()) });
s = await st(p);
check('wafer-meta blocked: frozen sky', s.space === 63340120796 && s.spaceSource === 'frozen', { space: s.space, src: s.spaceSource });
await done(p);
errors.splice(0, errors.length, ...errors.filter(e => !(e.hash === '' && /wafer-meta/.test(e.text + ' ' + (e.url || ''))))); // the deliberate abort above
// the X at the stars stage: opened directly -> the editions pointer; from the Kuiper -> history.back()
p = await open('');
const xl = await p.evaluate(() => { const b = [...document.querySelectorAll('button')].find(b => b.textContent === 'X'); const r = b.getBoundingClientRect(); return { label: b.getAttribute('aria-label'), x: r.left + r.width / 2, y: r.top + r.height / 2 }; });
await p.touchscreen.tap(xl.x, xl.y);
await p.waitForURL(/\/editions\/\d{12}\//, { timeout: 90000 }).catch(() => {});
check('X at the stars (opened directly): aria-label "back to the Kuiper", lands on editions/', xl.label === 'back to the Kuiper' && /\/editions\/\d{12}\//.test(p.url()), { label: xl.label, url: p.url() });
await done(p);
p = await newPage();
p.on('pageerror', e => errors.push({ hash: 'X-referrer', text: 'pageerror ' + e.message }));
await p.goto(BASE + '/editions/202611012135/', { waitUntil: 'load' }); await sleep(3000);
await p.evaluate(u => { location.href = u; }, BASE + '/see-through/');
await p.waitForFunction(() => window.__descent && window.__descent.state(), null, { timeout: 30000 }); await sleep(5000);
const xb = await p.evaluate(() => { const b = [...document.querySelectorAll('button')].find(b => b.textContent === 'X'); const r = b.getBoundingClientRect(); return { x: r.left + r.width / 2, y: r.top + r.height / 2 }; });
await p.touchscreen.tap(xb.x, xb.y);
await p.waitForURL(/\/editions\/202611012135\//, { timeout: 90000 }).catch(() => {});
check('X at the stars (from the Kuiper): history.back() to the edition', p.url().endsWith('/editions/202611012135/'), p.url());
await done(p);
const hard = errors.filter(e => !e.soft);
check('zero console errors apart from ' + IGNORE.source, hard.length === 0, hard.slice(0, 6));
const report = { device: 'Pixel 7', base: BASE, stamp: STAMP, space: SPACE, when: new Date().toISOString(), pass: results.every(r => r.ok), n: results.length, failed: results.filter(r => !r.ok).length, results, softRequestFailures: errors.filter(e => e.soft) };
fs.writeFileSync(path.join(OUT, 'report.json'), JSON.stringify(report, null, 1));
console.log('RESULT ' + (report.pass ? 'PASS' : 'FAIL') + ' ' + (report.n - report.failed) + '/' + report.n);
process.exit(report.pass ? 0 : 1);
})().catch(e => { console.error(e); process.exit(2); });Rerun
A JavaScript module in the handoff folder of Kuiper Belt that reads wafer meta and report rerun.
renderkuiper-belt / editions/202611012135/handoff/12-see-through-reader/rerun.cjs · lines 1–60 of 60 · version 2026-11-01 21:35 · Not reached from any entry point (candidate for review) · pattern arrived (shared by 2 files)
- What it does
- It loads wafer meta and report rerun. Defines 6 functions or classes, including sleep, check, newPage, ready, arrived. Uses libraries playwright, fs. Side effects: changes the web page (DOM); reads or writes files; starts processes.
- Why it exists in the grid workflow
- Domain stage agent_infra (path word 'handoff'): AI-agent memory, coordination and code audit (the multi-agent journey named in Ventus Ltd's brief).
- Inputs & outputs
- In: JSON file wafer-meta.json. Out: JSON file report-rerun.json.
- What it achieves
- It is built from the sleep step (`sleep`), the check step (`check`) and the new page helper (`newPage`). The four steps of `test.cjs` run 1 that failed on time under load 40-60 (round trip by the STAR KEY row, #view=sat after the flight, the X at the stars both ways), with long waits; same assertions as `test.cjs`. It reads `/home/user/estate/kuiper-belt/cosmos/wafer-meta.json` and writes `/tmp/nl010-opus/team-12/tester/out/report-rerun.json`.
- Why it matters
- No other file in the estate was found to import it.
- Application
- kuiper-belt · editions/202611012135/handoff/12-see-through-reader · JavaScript module
- Uses
- playwright, fs
- Used by
- none found
- Produces
- sleep, check, newPage, ready, arrived, xbtn
- Defines here
- sleep, check, newPage, ready, arrived, xbtn
- 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/202611012135/handoff/12-see-through-reader/rerun.cjs:1-60 · blob 512eaf36dbcafe9847e5b1a8c8cd5c8cce4f68b5 · GitHub at these lines
- State
- achieves: comment · context: readme_derived · stage: output · effects: dom, filesystem, process · domain stage: agent_infra · users: ai_agent · canonical: unreached_review
// rerun.cjs: the four steps of test.cjs run 1 that failed on time under load 40-60 (round trip by the STAR KEY row, #view=sat
// after the flight, the X at the stars both ways), with long waits; same assertions as test.cjs. Pixel 7, real touch.
'use strict';
const { chromium, devices } = require('playwright');
const fs = require('fs');
const BASE = 'http://127.0.0.1:8601', STAMP = '202611020012', IGNORE = /basemaps\.cartocdn\.com/;
const sleep = ms => new Promise(r => setTimeout(r, ms));
const SPACE = JSON.parse(fs.readFileSync('/home/user/estate/kuiper-belt/cosmos/wafer-meta.json', 'utf8')).address_space;
const k1182 = Math.floor(1182.5 * SPACE / 20000);
const results = [], errors = [];
const check = (n, ok, got) => { results.push({ name: n, ok: !!ok, got }); console.log((ok ? 'PASS ' : 'FAIL ') + n + ' ' + JSON.stringify(got)); };
async function newPage(tag) {
const b = await chromium.launch({ args: ['--use-gl=angle', '--use-angle=swiftshader', '--enable-unsafe-swiftshader', '--ignore-gpu-blocklist'] });
const p = await (await b.newContext({ ...devices['Pixel 7'] })).newPage(); p.__b = b;
p.on('console', m => { if (m.type() === 'error' && !IGNORE.test(m.text() + ' ' + m.location().url)) errors.push({ tag, text: m.text(), url: m.location().url }); });
p.on('pageerror', e => errors.push({ tag, text: 'pageerror ' + e.message }));
return p;
}
const ready = p => p.waitForFunction(() => window.__descent && window.__descent.state(), null, { timeout: 120000 });
const arrived = p => p.waitForFunction(() => { const s = window.__descent.state(); return s.T >= 0 && s.D > 7.99 && !s.flight; }, null, { timeout: 180000 });
const xbtn = p => p.evaluate(() => { const b = [...document.querySelectorAll('button')].find(b => b.textContent === 'X'); const r = b.getBoundingClientRect(); return { label: b.getAttribute('aria-label'), x: r.left + r.width / 2, y: r.top + r.height / 2 }; });
(async () => {
let p = await newPage('roundtrip');
await p.goto(BASE + '/see-through/#sub=Drax&view=kuiper'); await ready(p); await arrived(p); await sleep(2500);
const row = await p.evaluate(() => { const a = document.querySelector('a[data-st="kuiper-key"]'); const r = a.getBoundingClientRect(); return { text: a.textContent, href: a.getAttribute('href'), h: r.height, x: r.left + r.width / 2, y: r.top + r.height / 2 }; });
await p.touchscreen.tap(row.x, row.y);
await p.waitForURL(/\/editions\/\d{12}\/#key=/, { timeout: 180000 }).catch(() => {});
check('tap on STAR KEY row opens the Kuiper at #key=' + k1182 + ' through the editions pointer', /\/editions\/\d{12}\/#key=\d+$/.test(p.url()) && p.url().endsWith('#key=' + k1182), { row, url: p.url() });
await sleep(5000);
await p.goBack({ timeout: 180000 }).catch(e => console.log('goBack: ' + e.message.split('\n')[0]));
await p.waitForURL(/\/see-through\/202611020012\//, { timeout: 120000 }).catch(() => {});
check('back returns to See Through', p.url().includes('/see-through/' + STAMP + '/'), p.url());
await p.__b.close();
p = await newPage('sat');
await p.goto(BASE + '/see-through/#sub=Cowley&view=sat'); await ready(p); await arrived(p); await sleep(1500);
let s = await p.evaluate(() => window.__descent.state());
check('#sub=Cowley&view=sat: view after the flight', s.T === 201 && s.view === 'sat', { T: s.T, view: s.view });
await p.__b.close();
p = await newPage('x-direct');
await p.goto(BASE + '/see-through/'); await ready(p); await sleep(8000);
let x = await xbtn(p); await p.touchscreen.tap(x.x, x.y);
await p.waitForURL(/\/editions\/\d{12}\//, { timeout: 120000 }).catch(() => {});
check('X at the stars (opened directly): aria-label "back to the Kuiper", lands on editions/', x.label === 'back to the Kuiper' && /\/editions\/\d{12}\//.test(p.url()), { label: x.label, url: p.url() });
await p.__b.close();
p = await newPage('x-referrer');
await p.goto(BASE + '/editions/202611012135/'); await sleep(5000);
await p.evaluate(u => { location.href = u; }, BASE + '/see-through/');
await p.waitForURL(/\/see-through\/202611020012\//, { timeout: 120000 }); await ready(p); await sleep(8000);
x = await xbtn(p); await p.touchscreen.tap(x.x, x.y);
await p.waitForURL(/\/editions\/202611012135\//, { timeout: 120000 }).catch(() => {});
check('X at the stars (from the Kuiper): history.back() to the edition', p.url().endsWith('/editions/202611012135/'), p.url());
await p.__b.close();
check('zero console errors on See Through pages apart from ' + IGNORE.source, errors.filter(e => /see-through/.test(e.url || '') || /pageerror/.test(e.text)).length === 0, errors.slice(0, 8));
fs.writeFileSync('/tmp/nl010-opus/team-12/tester/out/report-rerun.json', JSON.stringify({ when: new Date().toISOString(), results, errors }, null, 1));
console.log('RESULT ' + (results.every(r => r.ok) ? 'PASS' : 'FAIL') + ' ' + results.filter(r => r.ok).length + '/' + results.length);
})().catch(e => { console.error(e); process.exit(2); });Shots
A JavaScript module in the handoff folder of Kuiper Belt. It is built from the sleep step (`sleep`).
renderkuiper-belt / editions/202611012135/handoff/12-see-through-reader/shots.cjs · lines 1–27 of 27 · version 2026-11-01 21:35 · Not reached from any entry point (candidate for review)
- What it does
- Defines sleep. Uses libraries playwright, path, fs. Side effects: changes the web page (DOM); reads or writes files.
- Why it exists in the grid workflow
- Domain stage agent_infra (path word 'handoff'): AI-agent memory, coordination and code audit (the multi-agent journey named in Ventus Ltd's brief).
- Inputs & outputs
- In: command-line arguments.
- What it achieves
- The four hand-off screenshots (Pixel 7, CSS scale), one browser each; harness flags as `test.cjs`.
- Why it matters
- No other file in the estate was found to import it.
- Application
- kuiper-belt · editions/202611012135/handoff/12-see-through-reader · JavaScript module
- Uses
- playwright, path, fs
- Used by
- none found
- Produces
- sleep
- Defines here
- sleep
- 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/202611012135/handoff/12-see-through-reader/shots.cjs:1-27 · blob 8113a28fd5815ea8eef801fbf7b9aa0582f0e1b2 · GitHub at these lines
- State
- achieves: comment · context: readme_derived · stage: output · effects: dom, filesystem · domain stage: agent_infra · users: ai_agent · canonical: unreached_review
// shots.cjs: the four hand-off screenshots (Pixel 7, CSS scale), one browser each; harness flags as test.cjs
const { chromium, devices } = require('playwright');
const path = require('path'), fs = require('fs');
const OUT = process.argv[2] || '/tmp/nl010-opus/team-12/tester/shots'; fs.mkdirSync(OUT, { recursive: true });
const BASE = 'http://127.0.0.1:8601/see-through/';
const sleep = ms => new Promise(r => setTimeout(r, ms));
const cases = [
['01-sub-drax-star-key-row', '#sub=Drax&view=kuiper', 'arrive'],
['02-key-line-of-code-amber-ring', '#key=36064705400', 'stars'],
['03-key-space-remap', '#key=' + Math.floor(1182.5 * 59637070538 / 20000) + '&space=59637070538', 'stars'],
['04-repo-gridatlas-lit', '#repo=gridatlas', 'stars'],
];
(async () => {
for (const [name, hash, mode] of cases) {
const b = await chromium.launch({ args: ['--use-gl=angle', '--use-angle=swiftshader', '--enable-unsafe-swiftshader', '--ignore-gpu-blocklist'] });
const p = await (await b.newContext({ ...devices['Pixel 7'] })).newPage();
await p.goto(BASE + hash);
await p.waitForFunction(() => window.__descent && window.__descent.state(), null, { timeout: 60000 });
if (mode === 'arrive') await p.waitForFunction(() => { const s = window.__descent.state(); return s.T >= 0 && s.D > 7.99 && !s.flight; }, null, { timeout: 90000 }).catch(() => {});
await sleep(mode === 'arrive' ? 3000 : 9000);
const s = await p.evaluate(() => window.__descent.state());
let ok = false;
for (let a = 0; a < 3 && !ok; a++) { try { await p.screenshot({ path: path.join(OUT, name + '.png'), scale: 'css', timeout: 120000 }); ok = true; } catch (e) { console.log(name, 'retry', a); } }
console.log(name, ok ? 'OK' : 'FAILED', JSON.stringify({ T: s.T, note: s.note, view: s.view }));
await b.close();
}
})();Test
A JavaScript module in the handoff folder of Kuiper Belt that tests wafer meta and substations.
testkuiper-belt / editions/202611012135/handoff/12-see-through-reader/test.cjs · lines 1–251 of 251 · version 2026-11-01 21:35 · Entry point · pattern repoCount (shared by 2 files)
- What it does
- It tests wafer meta and substations. Defines 18 functions or classes, including flag, sleep, fmt, keyOf, repoCount. Uses libraries playwright, fs, path, http. Side effects: changes the web page (DOM); reads or writes files; starts processes.
- Why it exists in the grid workflow
- Domain stage agent_infra (path word 'handoff'): AI-agent memory, coordination and code audit (the multi-agent journey named in Ventus Ltd's brief). Domain terms in the code: substations. README: "The test is `handoff/02-card/test.cjs` (B1–B7, Pixel 7 and Galaxy S24, all 344 placed bodies)."
- Inputs & outputs
- In: JSON file wafer-meta.json; command-line arguments. Out: JSON file report.json; canvas drawing.
- Downstream impact
- It is itself an entry point (JavaScript module); no other file was found loading it.
- What it achieves
- It sets hash (`setHash`) and is built from the flag step (`flag`) and the sleep step (`sleep`). The README says: The test is `handoff/02-card/test.cjs` (B1–B7, Pixel 7 and Galaxy S24, all 344 placed bodies).
- Why it matters
- No other file in the estate was found to import it; it is an entry point.
- Application
- kuiper-belt · editions/202611012135/handoff/12-see-through-reader · JavaScript module
- Uses
- playwright, fs, path, http
- Used by
- none found
- Produces
- flag, sleep, fmt, keyOf, repoCount, rows, head, probe, amberAt, lawAt, check, open
- Defines here
- flag, sleep, fmt, keyOf, repoCount, rows, head, probe, amberAt, lawAt, check, open, done, shot, P, setHash, arrived, slug
- 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/202611012135/handoff/12-see-through-reader/test.cjs:1-251 · blob 4dc5a599d64c9fbd26b3f01ebe2ed89ad98ef621 · GitHub at these lines
- State
- achieves: readme · context: readme_derived · stage: output · effects: dom, filesystem, process · domain stage: agent_infra · users: ai_agent · canonical: unknown
#!/usr/bin/env node
// test.cjs Opus team 12 "See Through hash reader" (NL-010): the hand-off test of see-through/<stamp>/, measured, not
// eyeballed. Written by OPUS-12 tester in the form of FIXES/NL-009/android-journey.cjs (Playwright, real touch for taps,
// a JSON report, exit 0 only when every check passed), building on the lead's draft (/tmp/nl010-opus/team-12/tester).
//
// node test.cjs [baseUrl] [outdir] [--img <dir>] [--devices "Pixel 7,Galaxy S24"]
//
// baseUrl the kuiper-belt repository root as served (default http://127.0.0.1:8611/, OPUS-12 tester's port:
// python3 -m http.server 8611 --bind 127.0.0.1 from /home/user/estate/kuiper-belt)
// outdir screenshots and report.json (default /tmp/nl010-opus/team-12/tester/run)
// --img also write the four hand-off screenshots (PNG, CSS-pixel scale, each < 300 KB) into this folder
// --devices default "Pixel 7" (one device at a time, sequentially; the machine is shared)
//
// The grammar is FIXES/NL-010/team-3/STEPS.md step 5.5 (the table) with acceptance A3 and the 5.8 b row; the folder and
// the pointer are handoff/12-see-through-reader/PLAN.md. The stamp is read from the pointer see-through/index.html.
//
// Cases (each a fresh browser: the 3D rise after an arrival holds SwiftShader's GPU process, shared by a browser's pages):
// C1 <stamp>/#sub=Drax the typed name: box "Drax", flight to 1182, D 8, name Drax; the link written on
// arrival (#key=<subKey 1182>&space=<SPACE>&sub=Drax) = __descent.link();
// the row "STAR KEY <k> · OPEN IT ON THE KUIPER", an <a> to ../../editions/#key=<k>,
// >= 44 px, visible, resolving to <base>editions/#key=<k> (HEAD 200)
// C2 <stamp>/#key=<subKey 1182>&space=63340120796
// the selected star: T -1, D 0 (nothing moves), box "Drax", note
// "THE STAR THAT LANDS ON DRAX. PRESS GO"; sky = wafer-meta address_space
// C3 <stamp>/#key=<subKey 201> a star key in See Through's own sky without &space: box "Cowley Substation",
// note "THE STAR THAT LANDS ON COWLEY SUBSTATION. PRESS GO"; then, on the same page by
// hashchange: #key=36064705400 (a line of code: note, one amber ring within 1 px
// of KuiperLaw.place, measured from the canvas pixels), #key=<SPACE> (beyond the
// sky), #key=<old key of 1182>&space=59637070538 (remap to Drax), #sub=xyzzy
// (refusal, no flight), #repo=nosuchrepo, #bogus=1 (field named)
// C4 <stamp>/#repo=gridatlas the lit repository: note "GRIDATLAS · <n> OF 12,900 STARS" with n equal to the
// count recomputed here from cosmos/wafer.tsv + repos.tsv, __descent.repoLit() = n,
// lit marks measured on the canvas
// C5 <stamp>/#view=3d the view: no target, so the existing caption "CHOOSE A SUBSTATION FIRST", view
// not 3d, T -1
// C6 see-through/?via=pointer#sub=Drax&view=map
// the pointer forwards search + hash to <stamp>/ unchanged; arrival at 1182 in the
// map view; a real touch on the STAR KEY row opens ../../editions/#key=<k>
// static the pointer's three places (meta refresh, <a href>, location.replace with search + hash) name <stamp>, and
// <stamp>/index.html exists
// errors zero console errors and page errors on See Through, apart from the sandbox's blocked map host
// basemaps.cartocdn.com, which is logged separately (report.blocked); failed requests are logged (report.requests)
'use strict';
const { chromium, devices } = require('playwright');
const fs = require('fs'), path = require('path'), http = require('http');
const argv = process.argv.slice(2);
const positional = []; for (let i = 0; i < argv.length; i++) { if (argv[i].startsWith('--')) i++; else positional.push(argv[i]); }
const flag = n => { const i = argv.indexOf(n); return i >= 0 ? argv[i + 1] : null; };
const BASE = (positional[0] || 'http://127.0.0.1:8611/').replace(/\/?$/, '/');
const OUT = path.resolve(positional[1] || '/tmp/nl010-opus/team-12/tester/run');
const IMG = flag('--img') ? path.resolve(flag('--img')) : null;
const DEVICES = String(flag('--devices') || 'Pixel 7').split(',').map(s => s.trim()).filter(Boolean);
const ROOT = process.env.KB_ROOT || path.resolve(__dirname, '../../../..');
const BLOCKED = /basemaps\.cartocdn\.com/;
const NRULE = 20000, NSUB = 5800, OLD_SPACE = 59637070538;
const ARGS = ['--use-gl=angle', '--use-angle=swiftshader', '--enable-unsafe-swiftshader', '--ignore-gpu-blocklist'];
const sleep = ms => new Promise(r => setTimeout(r, ms));
const fmt = n => Number(n).toLocaleString('en-GB');
const keyOf = (j, sp) => Number(((2n * BigInt(j) + 1n) * BigInt(sp)) / (2n * BigInt(NRULE))); // floor((j + 0.5) * sp / 20000), exact
fs.mkdirSync(OUT, { recursive: true }); if (IMG) fs.mkdirSync(IMG, { recursive: true });
// ---------------------------------------------------------------- static facts from the repository (measured here)
const pointer = fs.readFileSync(path.join(ROOT, 'see-through/index.html'), 'utf8');
const stamps = [(pointer.match(/url=(\d{12})\//) || [])[1], (pointer.match(/href="(\d{12})\/"/) || [])[1], (pointer.match(/location\.replace\('(\d{12})\/' \+ location\.search \+ location\.hash\)/) || [])[1]];
const STAMP = stamps[0];
const SPACE = JSON.parse(fs.readFileSync(path.join(ROOT, 'cosmos/wafer-meta.json'), 'utf8')).address_space;
const FROZEN = +((fs.readFileSync(path.join(ROOT, 'see-through', String(STAMP), 'kuiper-law.js'), 'utf8').match(/const SPACE = (\d+);/) || [])[1]);
function repoCount(name, np, sp) { // the engine's walk (kuiper-belt editions/202611012027/index.html:203-208), independently
const rows = f => fs.readFileSync(path.join(ROOT, 'cosmos', f), 'utf8').split('\n').filter(l => l && l[0] !== '#').map(l => l.split('\t'));
const ri = +rows('repos.tsv').find(r => r[1].toLowerCase() === name)[0];
const ranges = []; let k = 0;
for (const p of rows('wafer.tsv')) { k += +p[4]; const k0 = k; k += +p[1]; if (+p[2] === ri && k > k0) ranges.push([k0, k]); }
let n = 0;
for (let q = 0; q < np; q++) { const ki = (np < NRULE && q >= NSUB) ? NSUB + 2 * (q - NSUB) : q, kk = keyOf(ki, sp); if (ranges.some(r => kk >= r[0] && kk < r[1])) n++; }
return { n, ranges: ranges.length };
}
const head = u => new Promise(res => { const r = http.request(u, { method: 'HEAD' }, x => { res(x.statusCode); x.resume(); }); r.on('error', () => res(0)); r.end(); });
// ---------------------------------------------------------------- in-page probes
function probe() {
const d = window.__descent, s = d.state(), inp = document.querySelector('input');
const a = document.querySelector('a[data-st="kuiper-key"]');
let row = null;
if (a) { const r = a.getBoundingClientRect(), cs = getComputedStyle(a);
row = { text: a.textContent, href: a.getAttribute('href'), abs: a.href, h: +r.height.toFixed(1), w: +r.width.toFixed(1), x: r.left + r.width / 2, y: r.top + r.height / 2,
vis: cs.display !== 'none' && r.height > 0 && r.top >= 0 && r.bottom <= innerHeight, hit: (() => { const e = document.elementFromPoint(r.left + r.width / 2, r.top + r.height / 2); return e === a || a.contains(e); })() }; }
return { T: s.T, D: s.D, name: s.name, view: s.view, in3d: s.in3d, NP: s.NP, note: s.note, cap: s.cap, space: s.space, spaceSource: s.spaceSource,
noteFit: (() => { if (!s.note) return null; const e = [...document.querySelectorAll('div,span')].find(x => x.children.length === 0 && x.textContent === s.note); if (!e) return null;
const r = e.getBoundingClientRect(), rg = document.createRange(); rg.selectNodeContents(e); const t = rg.getBoundingClientRect();
return { textRight: +t.right.toFixed(1), boxRight: +r.right.toFixed(1), innerWidth, fits: t.right <= Math.min(innerWidth, r.right) + 0.5 && t.left >= 0 }; })(),
box: inp ? inp.value : null, hash: location.hash, href: location.href, link: d.link(), ring: d.ring(), lit: d.repoLit(), row, mapState: s.mapState };
}
// amber (#ffb000) pixels on the See Through canvas inside a box around (x, y) CSS px; centroid in CSS px
function amberAt(arg) {
const cv = document.querySelector('canvas[aria-label="See through the universe to one substation"]'); const r = cv.getBoundingClientRect(), sc = cv.width / r.width;
const g = cv.getContext('2d'), half = arg.half;
const x0 = Math.max(0, Math.round((arg.x - half - r.left) * sc)), y0 = Math.max(0, Math.round((arg.y - half - r.top) * sc));
const w = Math.min(cv.width - x0, Math.round(2 * half * sc)), h = Math.min(cv.height - y0, Math.round(2 * half * sc));
const px = g.getImageData(x0, y0, w, h).data; let n = 0, sx = 0, sy = 0;
for (let y = 0; y < h; y++) for (let x = 0; x < w; x++) { const i = (y * w + x) * 4; if (px[i] > 200 && px[i + 1] > 120 && px[i + 1] < 210 && px[i + 2] < 90) { n++; sx += x; sy += y; } }
const cx = n ? x0 + sx / n : 0, cy = n ? y0 + sy / n : 0; let rs = 0; // mean distance of the amber pixels from their centroid
for (let y = 0; y < h; y++) for (let x = 0; x < w; x++) { const i = (y * w + x) * 4; if (px[i] > 200 && px[i + 1] > 120 && px[i + 1] < 210 && px[i + 2] < 90) rs += Math.hypot(x - (cx - x0), y - (cy - y0)); }
return { n, x: n ? r.left + cx / sc : null, y: n ? r.top + cy / sc : null, radius: n ? +(rs / n / sc).toFixed(2) : null, scale: sc };
}
// the expected screen position of KuiperLaw.place(k) at the stars stage, from two substations' own screen positions
function lawAt(k) {
const d = window.__descent, s = d.state(), ks = s.Rpx / Math.sqrt(s.space + 0.5);
const a = window.KuiperLaw.place(d.subKey(0)), sa = d.screenOf(0), cx = sa[0] - a.x * ks, cy = sa[1] + a.y * ks;
const b = window.KuiperLaw.place(d.subKey(1)), sb = d.screenOf(1), p = window.KuiperLaw.place(k);
return { x: cx + p.x * ks, y: cy - p.y * ks, star1: Math.hypot(sb[0] - (cx + b.x * ks), sb[1] - (cy - b.y * ks)) };
}
// ---------------------------------------------------------------- run
(async () => {
const report = { base: BASE, stamp: STAMP, space: SPACE, frozen: FROZEN, when: new Date().toISOString(), devices: {} };
for (const DEV of DEVICES) {
const results = [], errors = [], blocked = [], requests = [], timings = {};
const check = (name, ok, got) => { results.push({ name, ok: !!ok, got }); console.log('[' + DEV + '] ' + (ok ? 'PASS ' : 'FAIL ') + name + ' ' + JSON.stringify(got)); };
let live = true; // false once a page has left See Through on purpose (the row's tap): the edition's console is not this team's
async function open(urlPath, ready, tag) {
const browser = await chromium.launch({ args: ARGS });
const ctx = await browser.newContext({ ...devices[DEV] });
const page = await ctx.newPage(); page.__b = browser; live = true; page.__navs = [];
page.on('framenavigated', f => { if (f === page.mainFrame()) page.__navs.push(f.url()); });
page.on('console', m => { if (m.type() !== 'error') return; const e = { tag, text: m.text().slice(0, 300), url: m.location().url };
if (BLOCKED.test(e.text + ' ' + e.url)) blocked.push(e); else if (live) errors.push(e); else requests.push({ ...e, afterLeaving: true }); });
page.on('pageerror', e => { if (live) errors.push({ tag, text: 'pageerror ' + e.message }); });
page.on('requestfailed', r => { const e = { tag, url: r.url().slice(0, 200), err: (r.failure() || {}).errorText }; if (BLOCKED.test(e.url)) blocked.push(e); else requests.push(e); });
const t0 = Date.now();
await page.goto(BASE + urlPath, { waitUntil: 'load', timeout: 180000 });
await page.waitForFunction(() => window.__descent && window.__descent.state(), null, { timeout: 120000 });
await page.waitForFunction(ready, null, { timeout: 150000, polling: 500 }).catch(() => console.log('[' + DEV + '] ready condition not met: ' + tag));
timings[tag] = Date.now() - t0;
await sleep(7000); // settle
return page;
}
const done = async p => { await p.__b.close().catch(() => {}); };
async function shot(page, name, toImg = true) { // CSS-pixel PNG; CDP fallback when the WebGL renderer holds Playwright's frame wait
const file = path.join(OUT, slug(DEV) + '-' + name + '.png');
try { await page.screenshot({ path: file, scale: 'css', timeout: 180000 }); }
catch (e) { try { const c = await page.context().newCDPSession(page); const r = await Promise.race([c.send('Page.captureScreenshot', { format: 'png' }), sleep(180000).then(() => null)]); if (r) fs.writeFileSync(file, Buffer.from(r.data, 'base64')); else console.log('screenshot timed out ' + name); await c.detach().catch(() => {}); } catch (e2) { console.log('screenshot failed ' + name); retu … [line shortened here: 407 characters; full line on GitHub]
if (toImg && IMG && DEV === DEVICES[0] && fs.existsSync(file)) fs.copyFileSync(file, path.join(IMG, name + '.png'));
}
const P = p => p.evaluate(probe);
const setHash = async (p, h, ready) => { await p.evaluate(x => { location.hash = x; }, h); await p.waitForFunction(ready, null, { timeout: 60000, polling: 300 }).catch(() => {}); await sleep(2500); return P(p); };
const k1182 = keyOf(1182, SPACE), k201 = keyOf(201, SPACE), old1182 = keyOf(1182, OLD_SPACE);
const arrived = () => { const s = window.__descent.state(); return s.T >= 0 && s.D > 7.99 && !s.flight; };
// static: the pointer
check('pointer see-through/index.html names one stamp in its three places, forwarding search + hash; ' + STAMP + '/index.html exists',
stamps.every(x => x && x === STAMP) && fs.existsSync(path.join(ROOT, 'see-through', STAMP, 'index.html')), { stamps });
check('the sky: frozen SPACE of ' + STAMP + '/kuiper-law.js equals cosmos/wafer-meta.json address_space', FROZEN === SPACE, { frozen: FROZEN, wafer: SPACE });
// C1 #sub=Drax: the typed name
let p = await open('see-through/' + STAMP + '/#sub=Drax', arrived, 'C1 #sub=Drax');
let s = await P(p);
const want1 = '#key=' + k1182 + '&space=' + SPACE + '&sub=Drax';
check('C1 #sub=Drax: box "Drax", flight to 1182 Drax, D 8 (' + timings['C1 #sub=Drax'] + ' ms from goto)', s.box === 'Drax' && s.T === 1182 && s.name === 'Drax' && s.D > 7.99, { box: s.box, T: s.T, name: s.name, D: s.D, view: s.view });
check('C1 arrival writes ' + want1 + ' (= __descent.link())', s.hash === want1 && s.link === want1, { hash: s.hash, link: s.link });
check('C1 sky: space = address_space, spaceSource wafer-meta', s.space === SPACE && s.spaceSource === 'wafer-meta', { space: s.space, src: s.spaceSource });
const rowText = 'STAR KEY ' + fmt(k1182) + ' · OPEN IT ON THE KUIPER', rowAbs = BASE + 'editions/#key=' + k1182;
check('C1 row "' + rowText + '": <a href="../../editions/#key=' + k1182 + '">, visible, >= 44 px, not covered', s.row && s.row.text === rowText && s.row.href === '../../editions/#key=' + k1182 && s.row.abs === rowAbs && s.row.vis && s.row.hit && s.row.h >= 44, s.row);
check('C1 the row resolves to ' + rowAbs + ', HEAD 200', (await head(BASE + 'editions/')) === 200, { abs: s.row && s.row.abs });
await shot(p, 'c1-sub-drax-landing', false); // after the auto 3D rise SwiftShader may hold the frame; the hand-off image is C6's
await done(p);
// C2 #key=<subKey 1182>&space=<SPACE>: the selected star
p = await open('see-through/' + STAMP + '/#key=' + k1182 + '&space=' + SPACE, () => !!window.__descent.state().note, 'C2 #key&space');
s = await P(p);
check('C2 #key=' + k1182 + '&space=' + SPACE + ': nothing moves (T -1, D 0), box "Drax", note "THE STAR THAT LANDS ON DRAX. PRESS GO"',
s.T === -1 && s.D < 0.01 && s.box === 'Drax' && s.note === 'THE STAR THAT LANDS ON DRAX. PRESS GO' && s.space === SPACE && s.spaceSource === 'wafer-meta', { T: s.T, D: s.D, box: s.box, note: s.note, space: s.space, src: s.spaceSource, ring: s.ring });
const law2 = await p.evaluate(lawAt, k1182), amb2 = await p.evaluate(amberAt, { x: law2.x, y: law2.y, half: 16 });
report.findingRingOnStarKey = report.findingRingOnStarKey || { device: DEV, ring: s.ring, amberPx: amb2.n, note: 'STEPS 5.5 table: "one amber ring is drawn at KuiperLaw.place(key)" for any key at D 0; A3 asserts box and note only' };
await shot(p, '02-key-space-selected-star');
await done(p);
// C3 #key=<subKey 201> without &space, then the refusals by hashchange on the same page
p = await open('see-through/' + STAMP + '/#key=' + k201, () => !!window.__descent.state().note, 'C3 #key own sky');
s = await P(p);
const n201 = await p.evaluate(() => window.__descent.sub(201).name);
check('C3 #key=' + k201 + ' (no &space): T -1, D 0, box "Cowley Substation", note "THE STAR THAT LANDS ON COWLEY SUBSTATION. PRESS GO"',
n201 === 'Cowley Substation' && s.T === -1 && s.D < 0.01 && s.box === 'Cowley Substation' && s.note === 'THE STAR THAT LANDS ON COWLEY SUBSTATION. PRESS GO', { name201: n201, T: s.T, box: s.box, note: s.note });
s = await setHash(p, '#key=36064705400', () => /LINE OF CODE/.test(window.__descent.state().note));
const law3 = await p.evaluate(lawAt, 36064705400);
let amb3 = { n: 0 }; // the canvas repaints on the page's own frame; under load the first repaint after the hashchange can lag
for (let t = 0; t < 20 && amb3.n < 20; t++) { amb3 = await p.evaluate(amberAt, { x: law3.x, y: law3.y, half: 16 }); if (amb3.n < 20) await sleep(1500); }
const rd = s.ring ? Math.hypot(s.ring.x - law3.x, s.ring.y - law3.y) : 99, pd = amb3.n ? Math.hypot(amb3.x - law3.x, amb3.y - law3.y) : 99;
check('C3 hashchange #key=36064705400: note "KEY 36,064,705,400 · A LINE OF CODE, NOT A SUBSTATION", T -1, D 0, one amber ring within 1 px of KuiperLaw.place(k) (__descent.ring()); on the canvas an amber ring of radius 10 px centred within 2 px of it (pixel centroid; anti-aliasing against the cyan stars moves a thresholded centroid by up to ~2 px)',
s.note === 'KEY 36,064,705,400 · A LINE OF CODE, NOT A SUBSTATION' && s.T === -1 && s.D < 0.01 && rd <= 1 && pd <= 2 && Math.abs(amb3.radius - 10) <= 1.5 && law3.star1 <= 1 && amb3.n >= 20,
{ note: s.note, noteFit: s.noteFit, ringStatePx: +rd.toFixed(3), ringCanvasPx: +pd.toFixed(3), ringRadiusPx: amb3.radius, amberPx: amb3.n, starCheckPx: +law3.star1.toFixed(3) });
await shot(p, '03-key-own-sky-amber-ring');
s = await setHash(p, '#key=' + SPACE, () => /BEYOND/.test(window.__descent.state().note));
check('C3 hashchange #key=<SPACE>: "KEY ' + fmt(SPACE) + ' IS BEYOND THIS SKY"', s.note === 'KEY ' + fmt(SPACE) + ' IS BEYOND THIS SKY', { note: s.note });
s = await setHash(p, '#key=' + old1182 + '&space=' + OLD_SPACE, () => /REMAPPED/.test(window.__descent.state().note));
check('C3 hashchange #key=' + old1182 + '&space=' + OLD_SPACE + ': remapped to the star of Drax', s.box === 'Drax' && s.note === 'STAR KEY REMAPPED · SKY ' + fmt(OLD_SPACE) + ' → ' + fmt(SPACE) + ' · THE STAR THAT LANDS ON DRAX. PRESS GO', { box: s.box, note: s.note });
s = await setHash(p, '#sub=xyzzy', () => /NO SUBSTATION/.test(window.__descent.state().note));
check('C3 hashchange #sub=xyzzy: refusal words, no flight', s.T === -1 && s.D < 0.01 && s.note === 'NO SUBSTATION NAME HERE CONTAINS THAT. TRY ANOTHER NAME', { T: s.T, note: s.note });
s = await setHash(p, '#repo=nosuchrepo', () => /NO REPOSITORY/.test(window.__descent.state().note));
check('C3 hashchange #repo=nosuchrepo: "NO REPOSITORY CALLED NOSUCHREPO"', s.note === 'NO REPOSITORY CALLED NOSUCHREPO', { note: s.note });
s = await setHash(p, '#bogus=1', () => /LINK FIELD/.test(window.__descent.state().note));
check('C3 hashchange #bogus=1 (after #repo=nosuchrepo on the same page): "LINK FIELD BOGUS NOT UNDERSTOOD" (a re-read link replaces the earlier note)', s.note === 'LINK FIELD BOGUS NOT UNDERSTOOD', { note: s.note });
await done(p);
// C4 #repo=gridatlas: the lit repository
p = await open('see-through/' + STAMP + '/#repo=gridatlas', () => !!window.__descent.state().note, 'C4 #repo=gridatlas');
s = await P(p);
const rc = repoCount('gridatlas', s.NP, SPACE);
const marks = await p.evaluate(() => { const d = window.__descent, s = d.state(); let lit = 0, tot = 0; // amber 3 px marks at lit stars
const cv = document.querySelector('canvas[aria-label="See through the universe to one substation"]'), r = cv.getBoundingClientRect(), sc = cv.width / r.width, g = cv.getContext('2d'), px = g.getImageData(0, 0, cv.width, cv.height).data;
for (let y = 0; y < cv.height; y++) for (let x = 0; x < cv.width; x++) { const i = (y * cv.width + x) * 4; if (px[i] > 200 && px[i + 1] > 120 && px[i + 1] < 210 && px[i + 2] < 90) lit++; }
return { amberPx: lit, NP: s.NP }; });
check('C4 #repo=gridatlas: note "GRIDATLAS · ' + fmt(rc.n) + ' OF ' + fmt(s.NP) + ' STARS", n = the count from cosmos/wafer.tsv (' + rc.ranges + ' ranges), repoLit() = n, marks drawn',
s.NP === 12900 && s.note === 'GRIDATLAS · ' + fmt(rc.n) + ' OF 12,900 STARS' && s.lit === rc.n && rc.n > 0 && marks.amberPx > rc.n && s.T === -1, { note: s.note, lit: s.lit, want: rc.n, amberPx: marks.amberPx });
await shot(p, '04-repo-gridatlas-lit');
await done(p);
// C5 #view=3d: the view, before a target
p = await open('see-through/' + STAMP + '/#view=3d', () => window.__descent.state().cap === 'CHOOSE A SUBSTATION FIRST', 'C5 #view=3d');
s = await P(p);
check('C5 #view=3d without a target: caption "CHOOSE A SUBSTATION FIRST", view not 3d, T -1, D 0, no "LINK FIELD" note',
s.cap === 'CHOOSE A SUBSTATION FIRST' && s.view !== '3d' && !s.in3d && s.T === -1 && s.D < 0.01 && !/LINK FIELD/.test(s.note), { cap: s.cap, view: s.view, in3d: s.in3d, T: s.T, note: s.note });
await done(p);
// C6 the pointer forwards search + hash; the row's real touch leads home by key
const fwd = 'see-through/' + STAMP + '/?via=pointer#sub=Drax&view=map';
p = await open('see-through/?via=pointer#sub=Drax&view=map', arrived, 'C6 pointer');
s = await P(p);
const pnavs = p.__navs.slice();
check('C6 pointer see-through/?via=pointer#sub=Drax&view=map forwards to ' + fwd + ' (search and hash kept; the hash then rewritten on arrival)',
pnavs.includes(BASE + fwd) && s.href === BASE + 'see-through/' + STAMP + '/?via=pointer' + want1, { navs: pnavs, now: s.href });
check('C6 arrival at 1182 in the map view (view field after the flight)', s.T === 1182 && s.view === 'map' && !s.in3d, { T: s.T, view: s.view, in3d: s.in3d });
await shot(p, '01-sub-drax-landing-star-key-row');
if (s.row && s.row.vis) {
const n0 = p.__navs.length; live = false;
await p.touchscreen.tap(s.row.x, s.row.y);
await p.waitForURL(/\/editions\/\d{12}\/#key=\d+$/, { timeout: 60000, waitUntil: 'commit' }).catch(() => {});
const navs = p.__navs.slice(n0);
check('C6 a real touch on the STAR KEY row opens ' + rowAbs + ' (then the editions pointer forwards the hash)', navs[0] === rowAbs && p.url().endsWith('#key=' + k1182), { navs, url: p.url() });
} else check('C6 a real touch on the STAR KEY row', false, { row: s.row });
await done(p);
check('zero console errors and page errors on See Through apart from ' + BLOCKED.source + ' (' + blocked.length + ' blocked, logged)', errors.length === 0, errors.slice(0, 8));
report.devices[DEV] = { pass: results.every(r => r.ok), n: results.length, failed: results.filter(r => !r.ok).length, timings, results, errors, blocked, requests };
}
report.pass = Object.values(report.devices).every(d => d.pass);
fs.writeFileSync(path.join(OUT, 'report.json'), JSON.stringify(report, null, 1));
console.log('RESULT ' + (report.pass ? 'PASS' : 'FAIL') + ' ' + Object.entries(report.devices).map(([d, r]) => d + ' ' + (r.n - r.failed) + '/' + r.n).join(', '));
process.exit(report.pass ? 0 : 1);
})().catch(e => { console.error(e); process.exit(2); });
function slug(s) { return s.toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-|-$/g, ''); }Hello
A JavaScript file in the editions folder of Kuiper Belt that uses SHA-256.
renderkuiper-belt / editions/202611012135/modules/202611012145-hello.js · lines 1–19 of 19 · version 2026-11-01 21:45 · Not reached from any entry point (candidate for review)
- What it does
- It draws its content. Side effects: changes the web page (DOM).
- 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).
- What it achieves
- On the wafer, and exposes `inspect`. before PR A; its sha256 stays in `handoff/04-loader/MODULE.sha256`.
- Why it matters
- No other file in the estate was found to import it.
- Application
- kuiper-belt · editions/202611012135/modules · script
- Uses
- none found
- Used by
- none found
- Produces
- none declared
- Defines here
- none
- 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/202611012135/modules/202611012145-hello.js:1-19 · blob 5a413b5cd63ff3949e627b8df2e67c319fff8cc1 · GitHub at these lines
- State
- achieves: comment · context: readme_derived · stage: output · effects: dom · domain stage: agent_infra · users: ai_agent · canonical: unreached_review
/* kuiper module hello, generation 202611012145 (UTC), Apache-2.0 (kuiper-belt) */
// The loader's proof (Opus team 4, NL-010 step 4): registers once, draws one cyan ring at keyPlace(0), the first key
// on the wafer, and exposes inspect(). requires: keyPlace, cam, draw, redraw. provides: hello. Removed from `order`
// before PR A; its sha256 stays in handoff/04-loader/MODULE.sha256. Hooks: kuiper.hooks.v1 (handoff/04-loader/HOOKS.md).
(function () {
'use strict';
let frames = 0, host = null;
KY.register({ schema: 'kuiper.module.v1', id: 'hello', generation: '202611012145',
requires: ['keyPlace', 'cam', 'draw', 'redraw'], provides: ['hello'],
install(KY) {
host = document.createElement('div'); host.id = 'ky-hello'; host.hidden = true; document.body.appendChild(host);
const p = KY.hooks.keyPlace(0);
KY.draw.add(function (o2) { const c = KY.cam, x = (p[0] - c.x) * c.zoom + o2.canvas.width / 2, y = o2.canvas.height / 2 - (p[1] - c.y) * c.zoom;
o2.strokeStyle = '#2ee6e6'; o2.lineWidth = 2; o2.beginPath(); o2.arc(x, y, 18, 0, 6.2832); o2.stroke(); frames++; }, 100);
KY.redraw();
return { key: 0, place: p };
},
inspect() { return { id: 'hello', ring_at_key: 0, frames_drawn: frames, host: !!host && host.isConnected }; } });
})();Loader
A JavaScript file in the editions folder of Kuiper Belt that works with ky line (`kyLine`) and ky refuse (`kyRefuse`), using SHA-256.
renderkuiper-belt / editions/202611012135/modules/202611012145-loader.js · lines 1–133 of 133 · version 2026-11-01 21:45 · Not reached from any entry point (candidate for review) · pattern kyInject (shared by 5 files)
- What it does
- It draws its content. Defines 6 functions or classes, including kyLine, kyRefuse, kyHex, kyInject, se. 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).
- Inputs & outputs
- In: JSON file modules.json.
- What it achieves
- It is built from the ky line helper (`kyLine`), the ky refuse helper (`kyRefuse`) and the ky hex helper (`kyHex`). Integrator as `handoff/04-loader/index.html.patch`. The bytes between the two marker lines below are byte-identical to the block the patch inserts in `editions/202611012135/index.html` before `requestAnimationFrame`(frame). It reads `modules.json`. It responds to error events.
- Why it matters
- No other file in the estate was found to import it.
- Application
- kuiper-belt · editions/202611012135/modules · script
- Uses
- none found
- Used by
- none found
- Produces
- kyLine, kyRefuse, kyHex, kyInject, se, kyAdmit
- Defines here
- kyLine, kyRefuse, kyHex, kyInject, se, kyAdmit
- 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/202611012135/modules/202611012145-loader.js:1-133 · blob e4d43598c54f3f846cb35218b3543f45042de7e3 · GitHub at these lines
- State
- achieves: comment · context: readme_derived · stage: output · effects: dom, network · domain stage: agent_infra · users: ai_agent · canonical: unreached_review
/* kuiper loader reference, generation 202611012145 (UTC), Apache-2.0 (kuiper-belt) */
// NOT A MODULE and never fetched: the reviewable copy of the hook table and loader that Opus team 4 hands to the
// integrator as handoff/04-loader/index.html.patch. The bytes between the two marker lines below are byte-identical
// to the block the patch inserts in editions/202611012135/index.html before requestAnimationFrame(frame); the block
// runs only inside that page script, where the engine names it closes over (cx, litRepo, PANELS, refuse, kyWafer, ...)
// are in scope. Listed in modules.json under "references", not in "order" (E6 checks the two copies agree).
// ======================================== KUIPER HOOK TABLE AND LOADER kuiper.hooks.v1 · begin (Opus team 4, step 4)
// Engine lines this patch changes: the wafer promise (one line after `let N = 0`, and kyWaferOk/kyWaferNo at the belt
// check, after `N = issued` and in the wafer.tsv catch), and the NL-009 round-1 fixes folded in by team 4: 09-robust
// (refuse() for the WebGL, context-lost, belt and wafer.tsv refusals, given slots here) and 04-touch (viewport, tap slop
// and tapUp). Nothing else above is changed. Everything a module
// may reach is in window.KY, built here after every wrap of the edition layer and frozen; the loader admits the
// modules of modules.json in `order`, each only when its bytes hash as recorded and every hook it requires exists,
// and refuses in words while the rest runs. Apache-2.0 (kuiper-belt). The same bytes, between the same two marker
// lines, are modules/202611012145-loader.js (the reviewable reference; it is never fetched). Lessons, cited:
// gridatlas@5ec7f62 atlas/index.html:39-44 (no-store, schema), :65-67 (missing id refused), :78-81 (hash in the
// browser), :82-83 (one blob script per cartridge), :104-114 (one published state); menu-bar.js:37-38 (never twice);
// atlas/modules/202610291043-uk-lightning-overlay.js:393-400 (one frozen API). The anti-lesson: learn-the-kuiper
// modes.html:16-24 skips a missing module silently; this loader says why, on screen.
const KY_EDITION = '202611012135';
const KY_NAMES = Object.freeze(['keyPlace', 'address', 'describe', 'findBy', 'flyTo', 'home', 'homeCamera', 'safeBox',
'lightTime', 'showNew', 'goKey', 'fmt', 'words', 'esc', 'cv', 'ov', 'o2', 'hud', 'big', 'sub', 'card', 'gbox', 'gin',
'SPACE', 'N', 'repos', 'commits', 'wafer', 'cam', 'lit', 'sel', 'redraw', 'draw', 'panels', 'refuse']);
const kyDraw = [], kyLines = [];
let kyAdmitting = null, kyInstalling = null;
function kyLine(t){ kyLines.push(t); if (!N) hud.textContent += '\n' + t; dirty = true; }
// the one wrap of draw: module painters run after the engine's and the edition's overlay, in ascending order;
// a painter that throws is taken out and named, the frame goes on
{ const _draw = draw; draw = function(){ _draw();
if (kyLines.length) hud.textContent += '\nMODULES · ' + kyLines.join('\n');
for (const d of kyDraw.slice()) { try { d.fn(o2, KY); }
catch (e) { kyDraw.splice(kyDraw.indexOf(d), 1); kyLine(d.id + ' draw threw ' + (e && e.message || e) + ' · painter removed'); } } }; }
const KY_STATE = { schema: 'kuiper.modules.v1', edition: KY_EDITION, hooks: 'kuiper.hooks.v1', order: [], admitted: [],
refused: [], failures: [], done: false, timings: { loader_start_ms: Math.round(performance.now()) } };
const KY_MODULES = {};
const KY = Object.freeze({
schema: 'kuiper.hooks.v1', edition: KY_EDITION,
hooks: Object.freeze({
keyPlace, address, describe, findBy, flyTo, home, homeCamera, safeBox, lightTime, showNew, goKey, fmt, words, esc,
cv, ov, o2, hud, big, sub, card, gbox, gin,
get SPACE(){ return SPACE; }, get N(){ return N; }, get repos(){ return repos; }, get commits(){ return commits; },
wafer: kyWafer }),
cam: Object.freeze({ get x(){ return cx; }, get y(){ return cy; }, get zoom(){ return zoom; }, get atHome(){ return atHome; }, set atHome(v){ atHome = !!v; } }),
lit: Object.freeze({ get repo(){ return litRepo; }, set repo(v){ litRepo = v; dirty = true; },
get K(){ return litK; }, get Ci(){ return litCi; },
set period(p){ if (p == null) { litK = [-1, -1]; litCi = null; dirty = true; } else lightTime(+p.y, +p.m || 0, +p.d || 0); } }),
sel: Object.freeze({ get target(){ return target; }, set target(t){ target = t; dirty = true; } }),
redraw(){ dirty = true; },
draw: Object.freeze({ add(fn, order){ if (typeof fn !== 'function') throw new TypeError('KY.draw.add needs a function');
kyDraw.push({ fn, order: +order || 0, id: kyInstalling || 'module' }); kyDraw.sort((a, b) => a.order - b.order); dirty = true; } }),
// once the shell (team 1, id kuiper-shell) is admitted the bar and its panels are its own: add() forwards into the
// shell's panel of that name (handoff/01-shell/REQUESTS.md item 2); a name the shell does not have falls back here
panels: Object.freeze({ add(name, el, title){ const sh = KY_MODULES['kuiper-shell'], sp = sh && sh.api && typeof sh.api.panel === 'function' ? sh.api.panel(name) : null;
if (sp) { sp.appendChild(el); KY.redraw(); return el; }
if (PANELS[name]) throw new Error('panel ' + name + ' exists');
el.classList.add('gm-panel'); el.setAttribute('role', 'region'); el.setAttribute('aria-label', String(title || name));
if (!el.isConnected) document.body.appendChild(el); PANELS[name] = el; placePanels(); return el; },
set: setPanel, place: placePanels }),
refuse(text, slot){ if (typeof slot !== 'string' || !/^[a-z0-9-]+$/.test(slot) || slot === 'engine' || slot === 'modules')
throw new TypeError('KY.refuse(text, slot): slot is the module id; engine and modules are the page\'s'); refuse(String(text || ''), slot); },
names: KY_NAMES,
register(m){ if (!kyAdmitting) { kyLine('a registration outside admission ignored: ' + (m && m.id)); return false; }
if (kyAdmitting.reg) { kyAdmitting.twice = true; return false; } kyAdmitting.reg = m; return true; },
modules: KY_MODULES,
inspect(){ return JSON.parse(JSON.stringify(KY_STATE)); } });
window.KY = KY; window.__KUIPER_MODULES__ = KY_MODULES; window.__KUIPER_EDITION__ = KY_STATE;
// one strip, role=alert, for refused modules; the engine's own refusals keep their slot in the same strip
function kyRefuse(t){ refuse(t, 'modules'); }
const kyHex = b => [...new Uint8Array(b)].map(x => x.toString(16).padStart(2, '0')).join('');
function kyInject(id, buf){ return new Promise(ok => { const s = document.createElement('script'), u = URL.createObjectURL(new Blob([buf], { type: 'text/javascript' })), st = { loaded: false, error: null };
const se = e => { if (e.filename === u) { st.error = st.error || String(e.message || 'error').replace(/^Uncaught /, ''); e.preventDefault(); } }, fin = l => { removeEventListener('error', se, true); URL.revokeObjectURL(u); st.loaded = l; ok(st); };
addEventListener('error', se, true); s.dataset.kyModule = id; s.src = u; s.onload = () => fin(true); s.onerror = () => fin(false); document.head.appendChild(s); }); } // a module's own script error is its refusal, not the page's error
async function kyAdmit(id, rec, provided){
if (!rec) return 'in order but not in modules';
const path = String(rec.path || ''), file = path.split('/').pop();
if (!/^modules\/[a-z0-9][a-z0-9.-]*\.js$/.test(path) || path.includes('..')) return 'bad path ' + path;
if (!/^\d{12}$/.test(rec.generation || '')) return 'generation ' + rec.generation + ' is not twelve digits';
const fd = file.match(/^(\d{12})-/); if (fd && fd[1] !== rec.generation) return 'stamp mismatch: generation ' + rec.generation + ', file name ' + fd[1];
if (!/^[0-9a-f]{64}$/.test(rec.sha256 || '')) return 'sha256 is not 64 hex';
if (!String(rec.licence || '').trim()) return 'no licence'; for (const f of ['requires', 'provides']) if (rec[f] != null && !Array.isArray(rec[f])) return f + ' is not a list';
for (const r of rec.requires || []) if (!provided.has(r)) return 'missing hook ' + r;
let res; try { res = await fetch(path, { cache: 'no-store' }); } catch (e) { return 'fetch failed ' + (e && e.message || e); }
if (!res.ok) return 'HTTP ' + res.status;
const buf = await res.arrayBuffer(), sha = kyHex(await crypto.subtle.digest('SHA-256', buf));
if (sha !== rec.sha256) return 'sha256 mismatch';
if (buf.byteLength !== rec.bytes) return 'bytes ' + buf.byteLength + ' ≠ manifest ' + rec.bytes;
if (rec.byte_budget && buf.byteLength > rec.byte_budget) return 'over byte_budget ' + buf.byteLength + ' > ' + rec.byte_budget;
const head = new TextDecoder().decode(buf.slice(0, 200)).split('\n')[0].match(/^\/\* kuiper module ([a-z0-9-]+), generation (\d{12}) \(UTC\),/);
if (!head) return 'no header line'; if (head[1] !== id) return 'header names ' + head[1] + ' ≠ ' + id;
if (head[2] !== rec.generation) return 'stamp mismatch: generation ' + rec.generation + ', header ' + head[2];
kyAdmitting = { id }; let reg, twice;
let inj; try { inj = await kyInject(id, buf); } finally { reg = kyAdmitting.reg; twice = kyAdmitting.twice; kyAdmitting = null; } if (!inj.loaded) return 'script did not load'; if (inj.error) return 'script error: ' + inj.error;
if (!reg) return 'no registration';
if (twice) return 'registered twice';
if (reg.schema !== 'kuiper.module.v1') return 'schema ' + reg.schema;
if (reg.id !== id) return 'id ' + reg.id + ' ≠ ' + id; for (const f of ['requires', 'provides']) if (reg[f] != null && !Array.isArray(reg[f])) return 'registration ' + f + ' is not a list';
if (reg.generation !== rec.generation) return 'stamp mismatch: generation ' + rec.generation + ', registration ' + reg.generation;
for (const r of reg.requires || []) { if (!(rec.requires || []).includes(r)) return 'requires ' + r + ' not in the manifest'; if (!provided.has(r)) return 'missing hook ' + r; }
if (typeof reg.install !== 'function') return 'no install';
let api; kyInstalling = id;
try { api = reg.install(KY); } catch (e) { return 'install threw ' + (e && e.message || e); } finally { kyInstalling = null; }
const ready = Promise.resolve(api);
ready.catch(e => { KY_STATE.failures.push({ id, why: 'install rejected ' + (e && e.message || e) }); kyLine(id + ' install rejected: ' + (e && e.message || e)); });
Object.defineProperty(KY_MODULES, id, { enumerable: true, value: Object.freeze({ id, generation: rec.generation, sha256: sha,
api: (api && typeof api.then === 'function') ? undefined : api, ready, inspect: typeof reg.inspect === 'function' ? reg.inspect : () => ({}) }) });
for (const p of [id, ...(reg.provides || []), ...(rec.provides || [])]) provided.add(p);
return null;
}
(async function kyLoad(){
let m;
try { const r = await fetch('modules.json', { cache: 'no-store' }); if (!r.ok) throw new Error('modules.json HTTP ' + r.status); m = await r.json(); if (!m || typeof m !== 'object') throw new Error('modules.json is not an object'); }
catch (e) { m = { error: e && e.message || String(e) }; }
const shape = m.error ? m.error : m.schema !== 'kuiper.modules.v1' ? 'schema ' + m.schema : m.hooks !== 'kuiper.hooks.v1' ? 'hooks ' + m.hooks
: m.edition !== KY_EDITION ? 'edition ' + m.edition + ' ≠ page ' + KY_EDITION : !Array.isArray(m.order) || !Array.isArray(m.modules) ? 'order and modules must be lists'
: !crypto.subtle ? 'no crypto.subtle (not a secure context)' : null;
if (shape) { KY_STATE.whole = shape; KY_STATE.done = true; kyRefuse('MODULES NOT ADMITTED: ' + shape + ' · the wafer is unchanged'); kyLine('modules not admitted: ' + shape); return; }
KY_STATE.order = m.order.slice();
const provided = new Set(KY_NAMES), seen = new Set();
for (const id of m.order) {
let why; try { why = seen.has(id) ? 'in order twice' : await kyAdmit(id, m.modules.find(x => x && x.id === id), provided); } catch (e) { kyAdmitting = kyInstalling = null; why = 'loader error ' + (e && e.message || e); }
const t = Math.round(performance.now()); seen.add(id);
if (why) { KY_STATE.refused.push({ id, why, t_ms: t }); kyLine(id + ' refused: ' + why); }
else { KY_STATE.admitted.push({ id, sha256: KY_MODULES[id].sha256, t_ms: t }); kyLine(id + ' admitted · ' + KY_MODULES[id].sha256.slice(0, 12)); }
}
KY_STATE.timings.last_admitted_ms = KY_STATE.admitted.length ? KY_STATE.admitted[KY_STATE.admitted.length - 1].t_ms : null;
KY_STATE.timings.loader_end_ms = Math.round(performance.now());
KY_STATE.bytes = m.modules.filter(x => x && KY_MODULES[x.id]).reduce((a, x) => a + (x.bytes || 0), 0);
KY_STATE.byte_budget = m.modules.filter(x => x && KY_MODULES[x.id]).reduce((a, x) => a + (x.byte_budget || 0), 0);
KY_STATE.done = true; for (const k of ['order', 'admitted', 'refused', 'timings']) Object.freeze(KY_STATE[k]); // KY.modules stays open: the shell publishes .menuBar there (01-shell REQUESTS 2)
if (KY_STATE.refused.length) kyRefuse(KY_STATE.refused.length + ' module' + (KY_STATE.refused.length > 1 ? 's' : '') + ' refused: '
+ KY_STATE.refused.map(x => x.id + ' (' + x.why + ')').join('; ') + ' · the wafer, the bar and every admitted module keep working');
})();
// ======================================== KUIPER HOOK TABLE AND LOADER kuiper.hooks.v1 · end