variant round: roll retired, chance is variant literature (strict parse, crypto pick on reception, picked-only rendering, /story variance metric); entity round: /story the whole deliverable, /table the play projection, the slidwin carry (smart contwin cutoff, whole exchanges, housekeeper reads session-minus-tail); dormant-session rework: universal session lifecycle (dormant->live->finished, sessions/<n> storage), move-at-stop, start lint + auto-send rule, rebaseable housekeeping, turn-0 -> carryover.jsonl, seed -> memory.json, draft-only save-package; format house rules enforced by the nine-rule check-repo (ascii bytes, no text-mutating css); smoke 105/105 + restart + reminder + browser pass green, irene hand-migrated to the new layout
2026-11-15 14:35:00 +00:00
|
|
|
// web/router.mjs -- path routing and the view lifecycle.
|
2026-11-14 23:48:27 +00:00
|
|
|
//
|
|
|
|
|
// Views register { el, enter, leave? } at boot (app.mjs). render()
|
|
|
|
|
// routes the path, then show() runs the previous view's leave and
|
variant round: roll retired, chance is variant literature (strict parse, crypto pick on reception, picked-only rendering, /story variance metric); entity round: /story the whole deliverable, /table the play projection, the slidwin carry (smart contwin cutoff, whole exchanges, housekeeper reads session-minus-tail); dormant-session rework: universal session lifecycle (dormant->live->finished, sessions/<n> storage), move-at-stop, start lint + auto-send rule, rebaseable housekeeping, turn-0 -> carryover.jsonl, seed -> memory.json, draft-only save-package; format house rules enforced by the nine-rule check-repo (ascii bytes, no text-mutating css); smoke 105/105 + restart + reminder + browser pass green, irene hand-migrated to the new layout
2026-11-15 14:35:00 +00:00
|
|
|
// the next view's enter -- each view owns its own teardown, so the
|
2026-11-14 23:48:27 +00:00
|
|
|
// router never has to know a pane's internals. Stale async work is
|
|
|
|
|
// dropped by the seq guard: a view captures seq at enter and checks
|
|
|
|
|
// it after every await.
|
|
|
|
|
|
|
|
|
|
import { $ } from './dom.mjs';
|
|
|
|
|
import { state } from './state.mjs';
|
|
|
|
|
import { banner, hideBanner, renderMeter, setWho, setSessionInfo } from './chrome.mjs';
|
|
|
|
|
import { logEvent } from './log.mjs';
|
|
|
|
|
|
jsdoc typing round, phases 3-4: the clerk (tool/memory.mjs) and the SPA (web/) typed under strict -- row shapes local to their owners (the clerk's five tables in its header; the SPA's response envelopes in the new web/shapes.mjs, the server's shared shapes imported at their use sites: User, LogEvent, JobState, HttpError); the db boundary cast at every .get()/.all(), fail as @returns {never} so guard-narrowing works; web via a second tsconfig (tsconfig.web.json: DOM libs in their own program, node types riding along because shapes.mjs's Provider typedef pulls provider.mjs in), npm run typecheck runs both; every non-annotation delta audited onto a small intended list (COUNT(*) Number() wraps, impossible-path guards, ?? ''/?? undefined null-absorbers, the RewordOp reason fix -- the validator demands it, the reminder-find naming its tag); smoke 110/110 + restart + reminder + repo checks + a zero-console-error browser pass green; the typing round is complete
2026-11-15 19:57:07 +00:00
|
|
|
/** One registered view: its pane element id, its enter (arg = the
|
|
|
|
|
* path-captured run id), and its optional leave. */
|
|
|
|
|
/** @typedef {{ el: string, enter: (arg: ?string, seq: number) => void|Promise<void>, leave?: () => void }} ViewDef */
|
|
|
|
|
|
|
|
|
|
/** @type {Record<string, ViewDef>} */
|
2026-11-14 23:48:27 +00:00
|
|
|
const views = {};
|
jsdoc typing round, phases 3-4: the clerk (tool/memory.mjs) and the SPA (web/) typed under strict -- row shapes local to their owners (the clerk's five tables in its header; the SPA's response envelopes in the new web/shapes.mjs, the server's shared shapes imported at their use sites: User, LogEvent, JobState, HttpError); the db boundary cast at every .get()/.all(), fail as @returns {never} so guard-narrowing works; web via a second tsconfig (tsconfig.web.json: DOM libs in their own program, node types riding along because shapes.mjs's Provider typedef pulls provider.mjs in), npm run typecheck runs both; every non-annotation delta audited onto a small intended list (COUNT(*) Number() wraps, impossible-path guards, ?? ''/?? undefined null-absorbers, the RewordOp reason fix -- the validator demands it, the reminder-find naming its tag); smoke 110/110 + restart + reminder + repo checks + a zero-console-error browser pass green; the typing round is complete
2026-11-15 19:57:07 +00:00
|
|
|
/** @param {Record<string, ViewDef>} map */
|
2026-11-14 23:48:27 +00:00
|
|
|
export function registerViews(map) { Object.assign(views, map); }
|
|
|
|
|
|
jsdoc typing round, phases 3-4: the clerk (tool/memory.mjs) and the SPA (web/) typed under strict -- row shapes local to their owners (the clerk's five tables in its header; the SPA's response envelopes in the new web/shapes.mjs, the server's shared shapes imported at their use sites: User, LogEvent, JobState, HttpError); the db boundary cast at every .get()/.all(), fail as @returns {never} so guard-narrowing works; web via a second tsconfig (tsconfig.web.json: DOM libs in their own program, node types riding along because shapes.mjs's Provider typedef pulls provider.mjs in), npm run typecheck runs both; every non-annotation delta audited onto a small intended list (COUNT(*) Number() wraps, impossible-path guards, ?? ''/?? undefined null-absorbers, the RewordOp reason fix -- the validator demands it, the reminder-find naming its tag); smoke 110/110 + restart + reminder + repo checks + a zero-console-error browser pass green; the typing round is complete
2026-11-15 19:57:07 +00:00
|
|
|
/** @param {string} p */
|
2026-11-14 23:48:27 +00:00
|
|
|
export function navigate(p) {
|
|
|
|
|
history.pushState({}, '', p);
|
|
|
|
|
render();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
window.addEventListener('popstate', () => render());
|
|
|
|
|
|
jsdoc typing round, phases 3-4: the clerk (tool/memory.mjs) and the SPA (web/) typed under strict -- row shapes local to their owners (the clerk's five tables in its header; the SPA's response envelopes in the new web/shapes.mjs, the server's shared shapes imported at their use sites: User, LogEvent, JobState, HttpError); the db boundary cast at every .get()/.all(), fail as @returns {never} so guard-narrowing works; web via a second tsconfig (tsconfig.web.json: DOM libs in their own program, node types riding along because shapes.mjs's Provider typedef pulls provider.mjs in), npm run typecheck runs both; every non-annotation delta audited onto a small intended list (COUNT(*) Number() wraps, impossible-path guards, ?? ''/?? undefined null-absorbers, the RewordOp reason fix -- the validator demands it, the reminder-find naming its tag); smoke 110/110 + restart + reminder + repo checks + a zero-console-error browser pass green; the typing round is complete
2026-11-15 19:57:07 +00:00
|
|
|
/** @returns {Promise<void>} */
|
2026-11-14 23:48:27 +00:00
|
|
|
export async function render() {
|
|
|
|
|
const seq = ++state.seq;
|
|
|
|
|
hideBanner();
|
2026-11-19 11:11:23 +00:00
|
|
|
// the package list moved to /packages (2026-11-19): old muscle
|
|
|
|
|
// memory lands there, the URL honest
|
|
|
|
|
if (location.pathname === '/new') history.replaceState({}, '', '/packages');
|
2026-11-14 23:48:27 +00:00
|
|
|
const p = location.pathname;
|
jsdoc typing round, phases 3-4: the clerk (tool/memory.mjs) and the SPA (web/) typed under strict -- row shapes local to their owners (the clerk's five tables in its header; the SPA's response envelopes in the new web/shapes.mjs, the server's shared shapes imported at their use sites: User, LogEvent, JobState, HttpError); the db boundary cast at every .get()/.all(), fail as @returns {never} so guard-narrowing works; web via a second tsconfig (tsconfig.web.json: DOM libs in their own program, node types riding along because shapes.mjs's Provider typedef pulls provider.mjs in), npm run typecheck runs both; every non-annotation delta audited onto a small intended list (COUNT(*) Number() wraps, impossible-path guards, ?? ''/?? undefined null-absorbers, the RewordOp reason fix -- the validator demands it, the reminder-find naming its tag); smoke 110/110 + restart + reminder + repo checks + a zero-console-error browser pass green; the typing round is complete
2026-11-15 19:57:07 +00:00
|
|
|
/** @type {?string} */
|
2026-11-14 23:48:27 +00:00
|
|
|
let name = null;
|
jsdoc typing round, phases 3-4: the clerk (tool/memory.mjs) and the SPA (web/) typed under strict -- row shapes local to their owners (the clerk's five tables in its header; the SPA's response envelopes in the new web/shapes.mjs, the server's shared shapes imported at their use sites: User, LogEvent, JobState, HttpError); the db boundary cast at every .get()/.all(), fail as @returns {never} so guard-narrowing works; web via a second tsconfig (tsconfig.web.json: DOM libs in their own program, node types riding along because shapes.mjs's Provider typedef pulls provider.mjs in), npm run typecheck runs both; every non-annotation delta audited onto a small intended list (COUNT(*) Number() wraps, impossible-path guards, ?? ''/?? undefined null-absorbers, the RewordOp reason fix -- the validator demands it, the reminder-find naming its tag); smoke 110/110 + restart + reminder + repo checks + a zero-console-error browser pass green; the typing round is complete
2026-11-15 19:57:07 +00:00
|
|
|
/** @type {?string} */
|
2026-11-14 23:48:27 +00:00
|
|
|
let arg = null;
|
|
|
|
|
let m;
|
|
|
|
|
if (p === '/') name = 'home';
|
2026-11-19 11:11:23 +00:00
|
|
|
else if (p === '/packages') name = 'packages';
|
|
|
|
|
else if ((m = p.match(/^\/packages\/([a-z0-9-]+)$/))) { name = 'pkgedit'; arg = m[1]; }
|
2026-11-14 23:48:27 +00:00
|
|
|
else if ((m = p.match(/^\/runs\/([a-z0-9-]+)\/setup$/))) { name = 'setup'; arg = m[1]; }
|
variant round: roll retired, chance is variant literature (strict parse, crypto pick on reception, picked-only rendering, /story variance metric); entity round: /story the whole deliverable, /table the play projection, the slidwin carry (smart contwin cutoff, whole exchanges, housekeeper reads session-minus-tail); dormant-session rework: universal session lifecycle (dormant->live->finished, sessions/<n> storage), move-at-stop, start lint + auto-send rule, rebaseable housekeeping, turn-0 -> carryover.jsonl, seed -> memory.json, draft-only save-package; format house rules enforced by the nine-rule check-repo (ascii bytes, no text-mutating css); smoke 105/105 + restart + reminder + browser pass green, irene hand-migrated to the new layout
2026-11-15 14:35:00 +00:00
|
|
|
else if ((m = p.match(/^\/runs\/([a-z0-9-]+)\/story$/))) { name = 'story'; arg = m[1]; }
|
2026-11-14 23:48:27 +00:00
|
|
|
else if ((m = p.match(/^\/runs\/([a-z0-9-]+)$/))) { name = 'play'; arg = m[1]; }
|
|
|
|
|
else return navigate('/');
|
jsdoc typing round, phases 3-4: the clerk (tool/memory.mjs) and the SPA (web/) typed under strict -- row shapes local to their owners (the clerk's five tables in its header; the SPA's response envelopes in the new web/shapes.mjs, the server's shared shapes imported at their use sites: User, LogEvent, JobState, HttpError); the db boundary cast at every .get()/.all(), fail as @returns {never} so guard-narrowing works; web via a second tsconfig (tsconfig.web.json: DOM libs in their own program, node types riding along because shapes.mjs's Provider typedef pulls provider.mjs in), npm run typecheck runs both; every non-annotation delta audited onto a small intended list (COUNT(*) Number() wraps, impossible-path guards, ?? ''/?? undefined null-absorbers, the RewordOp reason fix -- the validator demands it, the reminder-find naming its tag); smoke 110/110 + restart + reminder + repo checks + a zero-console-error browser pass green; the typing round is complete
2026-11-15 19:57:07 +00:00
|
|
|
if (!name) return; // unreachable: the routing always names a view or navigates home
|
2026-11-14 23:48:27 +00:00
|
|
|
if (!state.me) name = 'claim'; // signed out: every path leads to the claim
|
|
|
|
|
await show(name, arg, seq);
|
|
|
|
|
}
|
|
|
|
|
|
jsdoc typing round, phases 3-4: the clerk (tool/memory.mjs) and the SPA (web/) typed under strict -- row shapes local to their owners (the clerk's five tables in its header; the SPA's response envelopes in the new web/shapes.mjs, the server's shared shapes imported at their use sites: User, LogEvent, JobState, HttpError); the db boundary cast at every .get()/.all(), fail as @returns {never} so guard-narrowing works; web via a second tsconfig (tsconfig.web.json: DOM libs in their own program, node types riding along because shapes.mjs's Provider typedef pulls provider.mjs in), npm run typecheck runs both; every non-annotation delta audited onto a small intended list (COUNT(*) Number() wraps, impossible-path guards, ?? ''/?? undefined null-absorbers, the RewordOp reason fix -- the validator demands it, the reminder-find naming its tag); smoke 110/110 + restart + reminder + repo checks + a zero-console-error browser pass green; the typing round is complete
2026-11-15 19:57:07 +00:00
|
|
|
/** @param {string} name @param {?string} arg @param {number} seq @returns {Promise<void>} */
|
2026-11-14 23:48:27 +00:00
|
|
|
async function show(name, arg, seq) {
|
|
|
|
|
const prev = state.view;
|
|
|
|
|
if (prev && prev !== name && views[prev].leave) views[prev].leave();
|
|
|
|
|
state.view = name;
|
|
|
|
|
for (const [n, v] of Object.entries(views)) $(v.el).hidden = n !== name;
|
|
|
|
|
document.body.classList.toggle('play', name === 'play');
|
|
|
|
|
setWho(state.me);
|
|
|
|
|
setSessionInfo('');
|
|
|
|
|
renderMeter(null);
|
|
|
|
|
await views[name].enter(arg, seq);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// a run that vanished under us (deleted, 404): leave loudly for home.
|
variant round: roll retired, chance is variant literature (strict parse, crypto pick on reception, picked-only rendering, /story variance metric); entity round: /story the whole deliverable, /table the play projection, the slidwin carry (smart contwin cutoff, whole exchanges, housekeeper reads session-minus-tail); dormant-session rework: universal session lifecycle (dormant->live->finished, sessions/<n> storage), move-at-stop, start lint + auto-send rule, rebaseable housekeeping, turn-0 -> carryover.jsonl, seed -> memory.json, draft-only save-package; format house rules enforced by the nine-rule check-repo (ascii bytes, no text-mutating css); smoke 105/105 + restart + reminder + browser pass green, irene hand-migrated to the new layout
2026-11-15 14:35:00 +00:00
|
|
|
// render() clears the banner first -- set it after the navigate.
|
jsdoc typing round, phases 3-4: the clerk (tool/memory.mjs) and the SPA (web/) typed under strict -- row shapes local to their owners (the clerk's five tables in its header; the SPA's response envelopes in the new web/shapes.mjs, the server's shared shapes imported at their use sites: User, LogEvent, JobState, HttpError); the db boundary cast at every .get()/.all(), fail as @returns {never} so guard-narrowing works; web via a second tsconfig (tsconfig.web.json: DOM libs in their own program, node types riding along because shapes.mjs's Provider typedef pulls provider.mjs in), npm run typecheck runs both; every non-annotation delta audited onto a small intended list (COUNT(*) Number() wraps, impossible-path guards, ?? ''/?? undefined null-absorbers, the RewordOp reason fix -- the validator demands it, the reminder-find naming its tag); smoke 110/110 + restart + reminder + repo checks + a zero-console-error browser pass green; the typing round is complete
2026-11-15 19:57:07 +00:00
|
|
|
/** @param {string} id @param {string} from */
|
2026-11-14 23:48:27 +00:00
|
|
|
export function runGone(id, from) {
|
|
|
|
|
navigate('/');
|
variant round: roll retired, chance is variant literature (strict parse, crypto pick on reception, picked-only rendering, /story variance metric); entity round: /story the whole deliverable, /table the play projection, the slidwin carry (smart contwin cutoff, whole exchanges, housekeeper reads session-minus-tail); dormant-session rework: universal session lifecycle (dormant->live->finished, sessions/<n> storage), move-at-stop, start lint + auto-send rule, rebaseable housekeeping, turn-0 -> carryover.jsonl, seed -> memory.json, draft-only save-package; format house rules enforced by the nine-rule check-repo (ascii bytes, no text-mutating css); smoke 105/105 + restart + reminder + browser pass green, irene hand-migrated to the new layout
2026-11-15 14:35:00 +00:00
|
|
|
banner(`run ${id} is gone -- deleted?`);
|
2026-11-14 23:48:27 +00:00
|
|
|
logEvent('nav', `left ${from} for home: run gone (404)`);
|
|
|
|
|
}
|