Files
tiny-worlds/web/view-story.mjs
mute ccdd9ea129 the roles inventory: every human and inferencer seat named, the vocabulary swept, and the duties audit
the inventory (GM-designed in conversation, 2026-11-19): six human roles -- the developer (maintains the repo, and is the system packages author by consequence: system packages ship in the repo), the deployment operator (maintains a deployment: identities, providers, the registry; filesystem access as recovery; never a reader of runs' private surfaces -- owner-gating holds even against the superuser), the deployment user (any claimed identity; the only reach is the API -- no filesystem, no keys, ever), the package author (an off-platform seat: authorship travels with the files, the machinery sees only the publisher), a run's GM (maintains a run they own -- the same person the machinery records as the run's owner, one role two names, never split; the fork creates a second GM seat over a branching canon), and the reader (defined by the act, membership-free: on-platform any signed-in user, off-platform anyone the story text reaches). The inferencer roles: the assistant, the player, the housekeeper, the curator, the clerk (code, never a model), and the bookkeeper (parked). The example that pinned the mappings: Alice the op forking Bob's Faye into her Kate (hats stack, seats don't), Charlie authoring package files Bob publishes (the author-publisher split), Dave reading the exported story with no invite at all (the reader needs nothing).

the naming convention, stated in AGENTS's header and DICTIONARY both: "GM" always means a run's GM, everywhere; ruling attributions name the developer; the assistant is the assistant; the op stays the op. The role line that is never crossed (developer, 2026-11-19): the assistant is NOT the player -- player-facing instructions are for the assistant to understand how the player would interpret them, never to follow. The root prompts and every model-facing string were already correct (GM there was always the run's GM) and are untouched; the packages' fiction is exempt from the term lint (rule 4 scopes to the substrate: README and the root prompts); the records keep their day's words -- DECISIONS gained one dated header note mapping the old usage instead of a rewrite ("GM" in a ruling attribution is the developer, "the agent" is the assistant).

the sweep: 125+ ruling attributions rewritten across living prose and code comments in every spelling the repo used (paren-wrapped, date-first, mid-sentence, line-wrapped); AGENTS.md fully re-voiced (the header rewritten, "the agent" gone, the developer-meaning prose fixed line by line); README's "invited players" became "invited users"; the gm.md carve-out made precise everywhere (the file is the run's GM's private file, the flagging target is the developer, the non-editor is the assistant).

the word retirements, both lint-banned in rule 4 exactly like "window": "agent" (the word did too many jobs at once; every seat is named; the filename AGENTS.md consumed as-is, "Windows" the OS the precedent) and "LLM" (the class word is "inferencer(s)"; "model" kept as the machinery's noun -- a registry entry, never a seat: a model is what the registry lists, an inferencer is who a seat is). The fixes the bans forced: the exposure rule's "internal agents" -> "internal inferencers", the hypothetical "status-keeper agent" -> invocation, the bookkeeper shed its "agent" tag, "player-model" fell to "the player" everywhere including housekeeper.md's one prompt hit, README's "inference key" and its Roles section re-voiced, the #22 attribution comments at the three call sites, and the runtime log markers renamed (llm -> inferencer, a meaning-preserving log rename under the no-legacy rule). DICTIONARY's renames section carries both retirement entries.

the duties audit (along the what-hats-do lines: the developer maintains the repo, the op maintains a deployment, a user's only reach is the API, a run's GM maintains their run). Found and fixed: README's Housekeeping section was pre-split era text -- "every housekeeping pass should end in a commit" and "confess in the commit message" (runs/ is gitignored; the developer's commit duty was assigned to the run flow), the dead packages/<story>/dumps and packages/<story>/db paths (the dump is per-session under runs/<id>/sessions/<n>/), "canon/ stays committed", and "single-human" (multiuser since 2026-11-14) -- rewritten to the current paths with the audit's hat named: the dump cross-check is the operator side's, a run's GM reviews a pass through the server (the housekeeping log, the rendered rings, the story). The CLI-attributed-to-the-GM lines now say what they are: deployment-side filesystem reach, --gm-authorized writes, whoever's hand runs it (the protocol passage, quickstart step 7 -- which also dropped its "commit" -- and the booting intro now names its hat switches: the author's files, the deployment-side create with its API twin named, the GM's start). "The host" -> "the op" in the pitch. One mechanical fiction PARKED on the ROADMAP deferred list instead of fixed: the memory tiers table promises records access "none -- until the GM unlocks it in the story", but no channel exists (records is a creation-time settings bool, settings.json is read-only in the file API) -- build the channel or fix the promise, later. Verified consistent by the audit: the notepad (ONE notepad -- the run's gm.md, owner-writable through its route, seeded from the package copy), the op's non-reader boundary, every provider act, the spec attributions, the reader, the prompts.

verified: typecheck green both programs, check-repo ALL CLEAN with both new bans active, the ban regexes proven by direct test (agent/agents/multi-agent and LLM/LLMs caught; AGENTS.md and the assistant pass), and final greps confirming every remaining "GM" is a protocol term and every remaining "agent"/"LLM" is a quoting entry or a record's day-words. The developer's own edits ride along: the operator queue strike (the inventory line done, the loopback typo, "external sec review"), and the handoff prepared -- the queue renumbered, the fresh-run item's garbled line repaired, the commit count brought current (seven await the push), template and box marked committed, a stray paragraph break fixed. detention stays untracked WIP, untouched.
2026-11-19 09:56:56 +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 (developer,
// 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}`);
}
});