Files
interactive-story/backend/app/media/__init__.py
T
JesseMarkowitzandClaude Opus 5 1013c94eb1
CI / Backend tests (push) Canceled after 0s
CI / Frontend lint + build (push) Canceled after 0s
CI / Docker image builds (push) Canceled after 0s
M10: the seam for media, and no media
The media extension contract asks for a scene snapshot a future image or video
provider could be handed: location, who is present, what they hold, what must
stay true, and where in the story it sits. Building one was the milestone's
obvious first task, and it was the wrong one. That snapshot has existed since
M5. `narrative_state["scene"]` holds the summary, the location, the cast and the
coordinate it was written at; a validated `set_scene` event writes it, every
position snapshots it, and every head move restores it. It survives Undo, Redo,
Retry, divergence, Save Point restore and a process restart because it is the
authoritative state rather than a copy of it.

So there is no scenes table here. A second scene store would have been a second
answer to "where is the story now", with its own lineage rules to get wrong —
and the lineage rules are the expensive part, which is the argument for reusing
the ones that already work rather than against it. The Scene Packet is derived
on read, and its identity is computed from the campaign and the position rather
than allocated: the same position yields the same id in another process, after a
restart, and after the packet is thrown away and rebuilt, with no row to keep in
step. That is the part of a future media_assets table that would be expensive to
retrofit, so it is fixed now even though the table is not built.

One table, then: visual_profiles, the only thing the contract's scene list asks
for that nothing already stored. Campaign-scoped and not per-position, because a
character does not change appearance when the story forks — a reader who
diverged would otherwise lose their cast, and the same descriptors would land in
every per-position snapshot, measured at 245 copies of 367 bytes in a 120-turn
campaign to say something that never varies. Keyed by the M5 entity key rather
than a new identity namespace, and one table for characters, locations and items
alike, because a location is an entity with a type and splitting them would
reintroduce the genre shape M5 spent a milestone removing.

What the packet leaves out is the more interesting half. Not the transcript, and
not imported knowledge — none of it, not merely the sources marked hidden. The
rule is what the story established at this position, not everything the narrator
was told, and drawing it by class is what makes it hold for a secret nobody
thought to mark. A hidden Canon source proves it, with a positive control
showing the narrator did receive the sentinel the packet does not carry. Once a
validated event puts the observer in the room, the observer is in the packet:
that is no longer narrator-only knowledge, and a packet that hid it would be
hiding the story from itself.

The providers are contracts and nothing else. Protocols for image, video, audio,
speech and transcription, an empty registry, no adapter, no dependency, no
socket, and no media setting to point anywhere — a setting that exists can be
pointed at a cloud by mistake. A future provider endpoint must be loopback,
stricter than narration's trusted-LAN allowance, because a picture of a scene
carries the scene with it. Transcription returns an editable draft with no
commit method, so STT structurally cannot bypass the authoritative path.

Nothing here can write the story. Not by convention: no module under media/
imports the code that writes state, no media event type exists in the state
vocabulary, and every test in the authority suite compares the authoritative
document byte for byte either side of a media operation — including one where a
provider insists Alice is in a red coat in a corridor, and the campaign goes on
disagreeing.

One defect, found by the milestone's own tests. M10 first added a migration
creating an index that create_all already builds from the column, so an upgraded
database ended up with two indexes and a fresh install with one. Comparing the
two schemas is what caught it; neither database examined alone would have. The
migration is gone rather than renamed, and the right number of migrations for a
new table whose indexes are declared on its columns is zero.

Backend 1,191 passed / 14 skipped / 0 failed, 89 of them M10's. Frontend 145
passed. Lint, production build and Docker build clean. No frontend file changed:
M10 adds no reader-facing surface, and ordinary play — turns, state, memory,
knowledge, Undo, Redo, Retry, Save Point restore, restart — runs with no media
configuration, no warning, no connection attempt and no media row written.

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

67 lines
3.3 KiB
Python

"""M10: the seam a future media provider plugs into, and nothing behind it.
This package is **readiness, not media**. Nothing here generates an image, a
video, audio, speech or a transcription; nothing here opens a socket; nothing
here is required for the storyteller to run. A campaign plays exactly as it did
in M9 with none of this configured, which is M10's central acceptance
condition — see `test_m10_no_media.py`.
## What M10 found already built, and therefore did not build again
The largest finding of the milestone is how little of it needed inventing.
`MEDIA-EXTENSION-CONTRACT.md` §5 asks the story system to persist a structured
scene snapshot with a campaign, a lineage, a source position, a location and the
characters present. **All of that already exists**, and has since M5:
state["scene"] = {"summary": …, "location": <entity key>,
"present": [<entity keys>],
"at": {"branch_id": …, "depth": …}}
written only by the validated `set_scene` typed event (ADR 010), snapshotted per
node in `actions.narrative_state_after` (M5), restored on every head movement by
`attempts.restore_state` (M3/M4), and carried per position in the M9 v3 bundle.
So it is already authoritative, already lineage-safe, already survives Undo,
Redo, Save Point restore, divergence and restart, and already round-trips into a
clean data directory.
Building a `scenes` table beside that would have been a second representation of
information the application already stores authoritatively — the one thing the
M10 brief forbids — and it would have needed its own lineage rules, its own
restore path and its own bundle carriage, each a chance to disagree with the
state document. **So M10 stores no scene rows.** It reads the scene that is
already there.
## What was actually missing
Three things, and this package is each of them:
* `profiles.py` — **visual profiles.** Stable descriptors for how an entity
*looks*, which nothing recorded. Campaign-scoped rather than per-position,
because a character does not change appearance when the story forks (K02, K03).
* `packet.py` — **the Scene Packet.** A bounded, provider-neutral,
hidden-information-safe view of one scene, built on demand from authoritative
state. Persisted nowhere, because it is a pure function of things that are.
* `providers.py` — **the provider contracts.** Types and protocols for image,
video, audio, TTS and STT, with no provider vocabulary anywhere in them, plus
the loopback-only endpoint rule the media contract asks for.
## The authority direction, which never reverses
accepted story -> narrative state -> scene packet -> future provider
Every arrow points away from authority. A visual profile is not a story fact; a
scene packet is a read; a future asset would be a depiction. Nothing in this
package writes `narrative_state`, emits a state event, or moves the head — and
`test_m10_authority.py` asserts that by running each operation and comparing the
authoritative document byte for byte either side.
That is the rule `MEDIA-EXTENSION-CONTRACT.md` §35 and §49 state, and the reason
it is enforced structurally rather than by convention: the only code that may
change authoritative state is the M5 event pipeline, and nothing here imports
it.
"""
from . import packet, profiles, providers
__all__ = ["packet", "profiles", "providers"]