Files
interactive-story/frontend/src/pages/NewCampaign.jsx
T
JesseMarkowitzandClaude Opus 5 144406cd48 M11: what the server will actually read
The release-validation milestone, and the thing it had to settle first was
whether any of the earlier evidence meant what it said. M8 measured a deployment
enforcing a 4,096-token input window while the application budgeted 16,384.
Every request returned 200. What Ollama does with the excess is drop the oldest
tokens, and the oldest tokens here are the system block — the narrator's rules
and the campaign canon. A hundred-turn certification against that server would
have looked perfect and proved nothing, which is why this milestone could not
begin with a hundred turns.

So the application asks now. Ollama's window is a property of how a model was
loaded rather than of the request — sending num_ctx is accepted, ignored, and
worse, reloads the model at the server's own default — so the only honest move
is to find out and then tell the truth about it. /api/ps reports what a resident
model is being served with, /api/show what an unloaded one will load with, both
on the same host inference already uses, through the same endpoint policy and
the same TLS trust store. A verified window is a ceiling on the budget; an
unverified one leaves the budget alone and is recorded as unverified in the
turn's own provenance, so an old turn can be asked afterwards whether it was
built against a checked window. There is no third behaviour, and in particular
no hard-coded 4,096: a number the server did not say would be right on one
machine and wrong on the next.

The proof that this is doing something is a campaign whose canon sits at the
front of the prompt, 120 turns of history, and a 4,096-token window. The canon
is still there afterwards and the oldest history is gone. The same campaign
built the old way produces a prompt more than twice the window — the defect,
reproduced, so the fix is measured against it rather than asserted.

Two defects the validation found on its own, and they are the same defect twice:
something was true and nobody was told. A manual state correction of four
changes with one bad reference applied three, returned 201, and said nothing —
while recording the refusal on the audit row nobody reads. It came to light
because the identity diagnostic's own fixture was refused that way and the whole
run proceeded on a campaign with no scene, which would have read as a model
failure. And the narration-length setting moved no number: brief, medium and
long each became one English sentence, while the numeric hint the model actually
reads was derived from the global reply cap and said the same thing for all
three. Both now say what they did.

The other two post-M8 findings are closed as well. The tab said AI D&D, which no
document had ever claimed it did not; it says Interactive Story now, with the
open campaign first, and the name is the owner's decision rather than a
find-and-replace to something narrower than the engine. After an Undo the reader
could not tell where they had landed; the control row now ends with
"Moment 11 · later story ahead", from the server's own answer, in the word the
transcript already uses, with none of head, branch or depth anywhere near it.

The identity diagnostic exists and the root cause does not. That campaign was
destroyed, so no cause can be established — what M11 owes the finding is
something that can classify the next occurrence, and a diagnostic that makes only
the judgements a program can honestly make: duplicate keys, shared names,
protagonist drift, state and context disagreeing. Whether prose misattributed a
line is left to a person reading it beside its prompt, because a regex cannot
read dialogue and one that pretended to would produce exactly the confident wrong
answer this finding is about. Its detectors are proved to fire against a planted
second Alice.

Two entities may still share a display name. That was checked first, as the
finding asked, and left permitted: a mother and a daughter, or a stranger giving
a false name, are ordinary fiction, and refusing them to guard against a model
mistake would refuse the wrong thing. What was missing was that it happened
silently. It is reported now.

Evidence, not inference: a hundred accepted turns against a real narrator with
genuine process restarts; a real browser against the built SPA; a container with
no network at all; a campaign moved into a data directory that never existed.
Each was discarded and re-run whenever the product changed under it, and the runs
that were thrown away are listed in the report with the reason, along with ten
defects in the harnesses themselves — because a harness that has only ever
agreed with itself is not evidence, and two of M8's five harness defects were
masking real ones.

No dependency was added, removed or upgraded. No acceptance test was retired,
relaxed or reclassified. M11 is implemented and verified; it is not accepted, and
there is no release tag.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Qyn3oRd4D6pi72nKBG725B
2026-09-07 14:01:20 -04:00

303 lines
12 KiB
React
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/* Starting a campaign, in one screen.
*
* `BROWSER-UX-SPEC.md` §41-42 and §7 of the M8 brief. What it replaced was a
* scenario gallery followed by a placeholder modal: to begin a story you first
* picked a *world*, and to make a world you opened an editor with a JSON stat
* schema, a story-card table and an art picker. That is a fine way to build a
* D&D module and a poor way to start a mystery.
*
* Two rules shaped this form.
*
* **Only the name is required.** Everything else has a sensible blank. A reader
* who types "Westhaven" and presses Start gets a working campaign and can write
* the first line themselves; the rest of the fields are there for someone who
* already knows what they want. §7 is explicit that the data model must not be
* a gate on beginning.
*
* **No genre is privileged.** There is no fantasy vocabulary in the labels, the
* placeholders or the composed instructions — the same form has to fit a
* western and a horror story. Genre and tone are free text with suggestions
* rather than a closed list, because a closed list is a judgement about which
* stories this product is for.
*
* The style answers are composed into the campaign's narrator instructions
* (`ai_instructions`), which is the field the prompt builder already reads. No
* new backend concept was invented to hold "tone" — it is a sentence in the
* instructions, which is what it would have to become anyway.
*/
import { useState } from 'react'
import { useNavigate } from 'react-router-dom'
import { api } from '../api'
import { useToast } from '../components'
import { classifyError } from '../errors'
import { blocksPlay, useModelStatus } from '../modelStatus'
import { ModelSetupNotice } from '../ModelSetupNotice'
const GENRES = [
'Fantasy', 'Science fiction', 'Mystery', 'Historical',
'Western', 'Horror', 'Thriller', 'Literary',
]
const TONES = [
'Grounded and restrained', 'Warm and hopeful', 'Bleak', 'Wry',
'Tense', 'Whimsical', 'Epic',
]
const POV = [
{ value: 'second-present', label: 'Second person, present tense ("You walk…")' },
{ value: 'first-past', label: 'First person, past tense ("I walked…")' },
{ value: 'third-past', label: 'Third person, past tense ("She walked…")' },
{ value: 'third-present', label: 'Third person, present tense ("She walks…")' },
]
const LENGTHS = [
{ value: 'brief', label: 'Brief — a paragraph or two' },
{ value: 'medium', label: 'Medium — two to four paragraphs' },
{ value: 'long', label: 'Long — four or more paragraphs' },
]
const POV_SENTENCE = {
'second-present': 'Write in second person, present tense.',
'first-past': 'Write in first person, past tense.',
'third-past': 'Write in third person, past tense.',
'third-present': 'Write in third person, present tense.',
}
const LENGTH_SENTENCE = {
brief: 'Keep responses brief — one or two paragraphs.',
medium: 'Keep responses to roughly two to four paragraphs.',
long: 'Write at length — four or more paragraphs.',
}
/**
* Turns the style answers into narrator instructions.
*
* Exported because the composition is the one piece of real logic on this
* screen and a component test can check it without rendering anything.
*/
export function composeInstructions({ genre, tone, pov, length, style }) {
const lines = []
if (genre.trim()) lines.push(`This is a ${genre.trim().toLowerCase()} story.`)
if (tone.trim()) lines.push(`The tone is ${tone.trim().toLowerCase()}.`)
if (POV_SENTENCE[pov]) lines.push(POV_SENTENCE[pov])
if (LENGTH_SENTENCE[length]) lines.push(LENGTH_SENTENCE[length])
// Always last, so a reader's own words can override anything above them.
if (style.trim()) lines.push(style.trim())
return lines.join(' ')
}
/** A text field with a datalist of suggestions — open, not a closed set. */
function SuggestField({ id, label, value, onChange, options, placeholder, hint }) {
return (
<div className="field">
<label htmlFor={id}>{label}</label>
<input
id={id}
type="text"
value={value}
list={`${id}-options`}
placeholder={placeholder}
autoComplete="off"
onChange={(e) => onChange(e.target.value)}
/>
<datalist id={`${id}-options`}>
{options.map((o) => <option key={o} value={o} />)}
</datalist>
{hint && <p className="field-hint">{hint}</p>}
</div>
)
}
export default function NewCampaign() {
const navigate = useNavigate()
const toast = useToast()
const { status } = useModelStatus()
const [title, setTitle] = useState('')
const [genre, setGenre] = useState('')
const [tone, setTone] = useState('')
const [pov, setPov] = useState('second-present')
const [length, setLength] = useState('medium')
const [style, setStyle] = useState('')
const [protagonist, setProtagonist] = useState('')
const [pronouns, setPronouns] = useState('')
const [protagonistDesc, setProtagonistDesc] = useState('')
const [opening, setOpening] = useState('')
const [canon, setCanon] = useState('')
const [creating, setCreating] = useState(false)
const start = async (event) => {
event.preventDefault()
if (!title.trim() || creating) return
setCreating(true)
try {
const campaign = await api.createAdventure({
title: title.trim(),
opening: opening.trim(),
// One rule per line is the lightest editor that produces a list, and it
// is what a person writing rules actually does.
canon_rules: canon.split('\n').map((r) => r.trim()).filter(Boolean),
persona_name: protagonist.trim(),
persona_pronouns: pronouns.trim(),
persona_desc: protagonistDesc.trim(),
// M11 (post-M8 finding C): sent as data as well as prose. The sentence
// below still goes into the instructions where the reader can edit it;
// this is what the prompt builder turns into an actual word range.
narration_length: length,
})
const instructions = composeInstructions({ genre, tone, pov, length, style })
if (instructions) {
await api.updateAdventure(campaign.id, { ai_instructions: instructions })
}
navigate(`/play/${campaign.id}`)
} catch (err) {
toast(classifyError(err.message).detail, 'error')
setCreating(false)
}
}
return (
<div className="page setup">
<h1>New campaign</h1>
<p className="setup-lede">
Only a name is needed. Everything else can be changed later, or left to
the story to decide.
</p>
{blocksPlay(status) && <ModelSetupNotice />}
<form onSubmit={start}>
<section className="setup-section">
<h2>Name</h2>
<div className="field">
<label htmlFor="campaign-title">What is this story called?</label>
<input
id="campaign-title"
type="text"
required
autoFocus
maxLength={120}
value={title}
placeholder="The Westhaven Enquiry"
onChange={(e) => setTitle(e.target.value)}
/>
</div>
</section>
<section className="setup-section">
<h2>Story profile</h2>
<div className="field-row">
<SuggestField
id="campaign-genre" label="Genre" value={genre} onChange={setGenre}
options={GENRES} placeholder="Mystery"
/>
<SuggestField
id="campaign-tone" label="Tone" value={tone} onChange={setTone}
options={TONES} placeholder="Grounded and restrained"
/>
</div>
<div className="field-row">
<div className="field">
<label htmlFor="campaign-pov">Voice</label>
<select id="campaign-pov" value={pov} onChange={(e) => setPov(e.target.value)}>
{POV.map((o) => <option key={o.value} value={o.value}>{o.label}</option>)}
</select>
</div>
<div className="field">
<label htmlFor="campaign-length">Narration length</label>
<select
id="campaign-length" value={length}
onChange={(e) => setLength(e.target.value)}
>
{LENGTHS.map((o) => <option key={o.value} value={o.value}>{o.label}</option>)}
</select>
</div>
</div>
<div className="field">
<label htmlFor="campaign-style">Anything else the narrator should know</label>
<textarea
id="campaign-style" rows={2} maxLength={2000} value={style}
placeholder="Never resolve a scene with violence without warning me first."
onChange={(e) => setStyle(e.target.value)}
/>
</div>
</section>
<section className="setup-section">
<h2>Protagonist</h2>
<div className="field-row">
<div className="field">
<label htmlFor="campaign-protagonist">Name</label>
<input
id="campaign-protagonist" type="text" maxLength={80} value={protagonist}
placeholder="Aldric" autoComplete="off"
onChange={(e) => setProtagonist(e.target.value)}
/>
</div>
<div className="field">
<label htmlFor="campaign-pronouns">Pronouns</label>
<input
id="campaign-pronouns" type="text" maxLength={40} value={pronouns}
placeholder="they/them" autoComplete="off"
onChange={(e) => setPronouns(e.target.value)}
/>
</div>
</div>
<div className="field">
<label htmlFor="campaign-protagonist-desc">Who are they?</label>
<textarea
id="campaign-protagonist-desc" rows={2} maxLength={2000} value={protagonistDesc}
placeholder="A traveling investigator, patient and hard to lie to."
onChange={(e) => setProtagonistDesc(e.target.value)}
/>
</div>
</section>
<section className="setup-section">
<h2>Opening scene</h2>
<div className="field">
<label htmlFor="campaign-opening">Where does the story begin?</label>
<textarea
id="campaign-opening" rows={4} maxLength={8000} value={opening}
placeholder={
'You sit at a shared table in the Crooked Lantern Tavern. In your '
+ 'pocket is a small silver key you took from a missing scholar’s desk.'
}
onChange={(e) => setOpening(e.target.value)}
/>
<p className="field-hint">
Left blank, the story opens on an empty page and begins with
whatever you write first.
</p>
</div>
</section>
<section className="setup-section">
<h2>Canon</h2>
<div className="field">
<label htmlFor="campaign-canon">
What is true in this story, and must stay true?
</label>
<textarea
id="campaign-canon" rows={4} maxLength={8000} value={canon}
placeholder={'One rule per line.\nResurrection is impossible.\nNobody in this town owns a car.'}
onChange={(e) => setCanon(e.target.value)}
/>
<p className="field-hint">
One per line. These carry more authority than anything the story
later invents — the narrator is told them, and a turn that
contradicts one is refused. You can change them at any time.
</p>
</div>
</section>
<div className="setup-actions">
<button type="submit" className="primary" disabled={!title.trim() || creating}>
{creating ? 'Starting…' : 'Start campaign'}
</button>
<button type="button" onClick={() => navigate('/')} disabled={creating}>
Cancel
</button>
</div>
</form>
</div>
)
}