Files
tiny-worlds/web/view-story.mjs
T
mute e763d6c146 the access round: spectator mode removed and reads made story-only -- the table, raw session, carryover, files, status, and the notepad are owner-only; the story is the one public read (any signed-in user, fork button on it that copies the run that made the story, never the view); #28's human-side open read overturned with the ruling, gm.md stays never model-facing; non-owners land in the story view (play/setup redirect on the 403, home cards link there directly), the story view names its owner and stands alone on the story response, which now carries display/owner/ownerName; the table gains a raw tab -- the whole log as it rode the wire (thinking, every variant block, every reminder copy, full tool results, rides inline) next to the curated projection, live sessions only, sticky across turn re-renders; --debug mode for easy testing: every request is a fixed superuser that bypasses the users db entirely, no invite dance, loopback-bound regardless of config (found live: the SPA boot only asked the server who it was when a token existed, so tokenless browsers never learned they were the debug user -- boot now always asks); lint rule 10: no laptop-visible facts anywhere and all commits always from Mute -- the username and home paths are derived at runtime so the checker never contains them, scanned over the tracked tree, every historical blob, and commit messages, identity enforced on author and committer on every ref plus git config; the queue split: resolved questions relocated to DECISIONS.md verbatim by number (day's words kept, reversals annotate never rewrite, the agenda/reminder trio gets its own section), QUESTIONS is open items only (stale OPENs resolved on the way: #10 by the 2026-11-13 pairing default, #11 by the raw tab); smoke reworked to the story-only battery -- ash 403s on every run surface, 200 on the story alone, the ownerless-run check rides the runs list; all twelve QUESTIONS-number citations re-pointed at DECISIONS; smoke ALL PASS in a worktree (111 checks), two-user browser pass (the non-owner's whole run surface is a 403 detail and a 200 story, back-to-table hidden, owner views intact), raw-tab browser pass (curated table leak-free, raw shows the whole variants block, tabs vanish on dormancy), typecheck green on both programs, check-repo clean
2026-11-15 22:37:06 +00:00

83 lines
3.3 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';
import { renderContent } from './transcript.mjs';
/** @typedef {import('./shapes.mjs').StoryResponse} StoryResponse */
/** @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);
renderContent(body, turn.text, { extract: turn.who === 'gm' });
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}`);
}
});