Files
tiny-worlds/web/view-story.mjs
T
mute eebc1993dd the night rounds: the GM-input rework and the reasoning-effort knob -- the workbench renders no faces: the composer overlay and the transcript share colour-only tokens (.narration dim, .emph accent), source verbatim, asterisks tinted and kept on screen, so the input's caret can never drift (the old overlay's real bold/italic shifted advance widths -- keeping every character preserved count, not width; the scrollbar-gutter match killed the second drift source); the story view carries its OWN renderer (view-story storyBody/storySpans) -- the book keeps real bold/italic with the asterisks spent, narration italic via #story-scoped CSS, one rule for the tool and typography for the deliverable, deliberately separate; the composer is turn-shaped: rows=6 floor, field-sizing: content grows it with the turn (the thing the GM remembered Firefox doing -- it was never in use), max-height 50vh caps with internal scroll, the footer moved under the transcript's column only so the input's width is the pane's; the transcript's stick-to-bottom was DEAD CODE all along (#transcript has no height or overflow -- main is the scroller, the scrollTop assignments were no-ops in every browser): stickBottom scrolls main and re-asserts next frame (Firefox's scroll anchoring can reclaim a same-tick scroll around a content wipe), main carries overflow-anchor: none; the prose pane drops its machinery by ruling: the status/agenda chips and the retired delta tags strip (the panes carry the derived state), the reminder card never renders (it is the same every turn -- the raw tab keeps every copy), and the status/agenda note receipts (the old delta applies and the whole-list sets alike) skip the prose walk while the raw keeps them; the model dropdown collapsed to one plain list of ids sorted, ceilings riding along (the family grouping left the user guessing what a family name means, and the curator's tier labels only made sense inside their groups); and the reasoning-effort round: the battery probes the ladder (probeEfforts -- each of none/minimal/low/medium/high/xhigh/max measured for mean thinking, two samples, efforts recorded per model, effortDefault the argmax mean over minimal..max, 'none' never a candidate -- it is the off switch; null when the model shows no thinking), the knob is first-class and the GM's alone (GM, 2026-11-16: hidden from the model, not her call -- never in the mind verb, never in the <model> display block, and renderView's via-derived block filters it too, both surfaces; it rides the via record for the raw surfaces), its unset state SENDS the measured max-mean default (the one knob with an honestly nameable default -- the registry measured it; layers run override > deployment > registry per-model, explicit null clears to nothing), the first non-numeric knob (RoleParams carries the string, the /model route validates against the ladder, the knob row a select whose unset label names what rides and rebuilds on model-select change); the GLM ladder verified live by hand before the build (low suppresses to a third of baseline, max elevates about double, the whole ladder accepted on both families without 400s, and reasoning_effort 'none' doubles as a standardized thinking-off switch); the model dropdown, the composer, and the knob UX browser-proven with zero console errors (the pass caught the unreachable-helpers bug: code after a factory's return never runs, a hoisted function referencing the uninitialized const throws silently mid-fill and stale rows render); smoke ALL PASS with the effort battery (the canned mock ladders, the default riding a bare turn's via, the override riding the next turn, the bogus-level 400, the null clear, no reasoning_effort in any <model> block) + restart + reminder + repo checks green, typecheck green on both programs; ROADMAP gains the distant extension point (n-choice inference composed by a turn-editor agent) and the operator's queue moved there from QUESTIONS by the GM; HANDOFF prepared as the handoff (the typing-round bullet trimmed into the rounds list, the server line now truthful -- the debug server runs, the registry bullet carries the six-knob state and the pending-effort refine)
2026-11-16 23:52:58 +00:00

138 lines
5.4 KiB
JavaScript

// web/view-story.mjs -- the story: the whole deliverable, read-only.
//
// Every non-dropped literature turn from turn-0 to the last
// recorded, across all sessions in order -- the reading surface the
// adjudication review reads ("machinery seams show as prose seams").
// OOC, tools, verbs, thinking, rings: all out, by ruling; carried
// copies never re-render, each turn appears once from its home
// session. Readable by any signed-in user; the fork button copies
// the run that made the story, never the view.
import { $, el } from './dom.mjs';
import { api } from './client.mjs';
import { state } from './state.mjs';
import { banner } from './chrome.mjs';
import { logEvent } from './log.mjs';
import { navigate, runGone } from './router.mjs';
/** @typedef {import('./shapes.mjs').StoryResponse} StoryResponse */
// the story's own renderer, deliberately not the workbench's (GM,
// 2026-11-16: one rule -- the table and the composer render
// colour-only, source text verbatim; the book is the deliverable and
// earns its typography). Real faces, asterisks spent: *italics* is
// the narration register, **bold** is emphasis, the prose reads like
// print. The server already stripped rides, verbs, and whole OOC
// turns; mid-turn OOC lines and stray tags can still arrive and
// render in their dim style.
/** @param {HTMLElement} target @param {string} text */
function storySpans(target, text) {
const parts = String(text).split(/(\*\*[^*]+\*\*|\*[^*\n]+\*)/g);
for (const p of parts) {
if (!p) continue;
if (p.startsWith('**') && p.endsWith('**')) {
target.appendChild(el('strong', null, p.slice(2, -2)));
} else if (p.startsWith('*') && p.endsWith('*') && p.length > 2) {
target.appendChild(el('em', 'narration', p.slice(1, -1)));
} else {
target.appendChild(document.createTextNode(p));
}
}
}
/** @param {HTMLElement} target @param {string} text */
function storyBody(target, text) {
let narr = false; // an open multi-line narration block
for (const line of String(text ?? '').split('\n')) {
const t = line.trim();
if (!t) { target.appendChild(document.createElement('br')); continue; }
if (t.startsWith('(') || t.startsWith('<')) {
// a mid-turn OOC line or a stray tag -- dim, kept visible
target.appendChild(el('div', 'line ooc', t));
continue;
}
const stars = (line.match(/\*/g) ?? []).length;
if (!narr && (stars % 2 === 0 || !(t.startsWith('*') && !t.startsWith('**')))) {
// balanced spans, or a stray unpaired * mid-line (not a block
// opener -- the stray stays literal)
const d = el('div', 'line speech');
storySpans(d, line);
target.appendChild(d);
continue;
}
// block narration: an unpaired leading * opens it, a trailing * closes
let content = line.replace(/^\s*\*/, '');
narr = true;
if (t.endsWith('*') && !t.endsWith('**')) {
narr = false;
content = content.trimEnd().slice(0, -1);
}
const d = el('div', 'line narration');
storySpans(d, content);
target.appendChild(d);
}
}
/** @type {?string} */ let storyRun = null;
/** @param {?string} id @param {number} seq @returns {Promise<void>} */
export async function enter(id, seq) {
if (id == null) return; // unreachable: the router only enters the story with a run id
storyRun = id;
/** @type {HTMLButtonElement} */ ($('story-fork')).disabled = false;
/** @type {StoryResponse} */ let story;
try {
story = await api(`/runs/${id}/story`);
} catch (e) {
if (e.status === 404) return runGone(id, 'the story view');
return banner(`could not reach the server: ${e.message}`);
}
if (seq !== state.seq) return;
// whose story this is rides the response -- the story is the one
// surface a non-owner gets, so it names its owner
const whose = story.owner == null ? ' -- ownerless'
: (state.me && story.owner !== state.me.id) ? ` -- ${story.ownerName ?? 'another user'}'s` : '';
$('story-title').textContent = `${story.display} -- the story${whose}`;
// "back to the table" is the owner's alone -- for anyone else the
// table would 403 and bounce straight back here
$('story-back').hidden = !(state.me && story.owner === state.me.id);
const box = $('story');
box.textContent = '';
if (!story.sessions.length) {
box.appendChild(el('div', 'hint', 'nothing has happened yet -- the story begins at the table'));
return;
}
for (const [si, s] of story.sessions.entries()) {
if (si > 0) box.appendChild(el('div', 'session-break'));
for (const turn of s.turns) {
const d = el('div', `turn ${turn.who}`);
d.appendChild(el('div', 'who', turn.who === 'gm' ? 'GM' : 'player'));
const body = el('div');
d.appendChild(body);
storyBody(body, turn.text);
box.appendChild(d);
}
}
}
// wired once at module load: the back button returns to the table
$('story-back').addEventListener('click', () => {
if (storyRun) navigate(`/runs/${storyRun}`);
});
// the fork copies the run that made this story and lands you in the
// fork's play view -- any signed-in user, any run
$('story-fork').addEventListener('click', async () => {
if (!storyRun) return;
const btn = /** @type {HTMLButtonElement} */ ($('story-fork'));
btn.disabled = true;
try {
const r = await api(`/runs/${storyRun}/fork`, { method: 'POST', body: {} });
logEvent('nav', `forked ${storyRun} -> ${r.run}`);
navigate(`/runs/${r.run}`);
} catch (e) {
btn.disabled = false;
banner(`the fork failed: ${e.message}`);
}
});