2026-05-18 22:03:59 -05:00
# Stage: prepare
## Purpose
2026-08-09 21:50:21 +00:00
2026-05-23 12:57:59 +00:00
Materialize canonical current-session inputs before processing stages.
2026-05-18 22:03:59 -05:00
2026-05-23 12:57:59 +00:00
## Inputs
2026-08-09 21:50:21 +00:00
- resolved campaign, session, and pipeline configuration
2026-11-30 00:31:36 +00:00
- the stable speakers input, inline autocorrection rules, canonical party, and optional glossary selections
2026-08-09 21:50:21 +00:00
- one resolved local or S3 audio source
2026-05-23 12:57:59 +00:00
- enabled configured artifact input requirements for previous-session sources
## Outputs
2026-08-09 21:50:21 +00:00
2026-05-23 12:57:59 +00:00
- `inputs/campaign.yml`
- `inputs/session.yml`
- `inputs/pipeline.resolved.yml`
- `inputs/speakers.yml`
- `inputs/autocorrect.yml`
2026-11-30 00:39:39 +00:00
- `inputs/glossaries/{party,campaign,setting,spells,combined}.yml`
2026-05-27 09:34:05 -05:00
- `inputs/players.yml`
- `inputs/party.yml`
2026-05-23 12:57:59 +00:00
- `audio/*.flac`
2026-11-30 00:31:36 +00:00
- optional `inputs/previous/manifest.json`
- optional `inputs/previous/artifacts/**`
2026-05-23 12:57:59 +00:00
- deterministic `manifest.inputs` entries (checksums + provenance)
## Key Behavior
2026-08-09 21:50:21 +00:00
2026-11-27 17:09:21 +00:00
- validates required config/store state and resolves selected vocabulary before audio work.
- derives the party glossary and resolves the remaining named collections through
2026-11-30 00:39:39 +00:00
`internal/glossary` ; writes four individual shared envelopes and a combined
envelope with checksums, sizes, and provenance. The combined record declares
its four individual input dependencies.
2026-05-23 12:57:59 +00:00
- enforces local audio vs S3 audio mutual exclusivity.
2026-08-10 21:53:54 +00:00
- rejects duplicate explicit local audio sources after resolution.
- gives distinct local source paths with the same basename deterministic unique
prepared filenames so neither source is overwritten.
2026-12-01 20:24:09 +00:00
- downloads S3 audio into a temporary sibling before verifying and installing the prepared copy; its recorded identity comes from the same response as the bytes.
2026-11-30 00:31:36 +00:00
- writes effective autocorrection rules as a Seriatim envelope, with checksum,
size, and source provenance, including an empty list when no rules apply.
2026-11-17 22:42:53 +00:00
- renders standalone effective campaign, session, and canonical party documents,
and deterministically generates the prepared players projection.
2026-05-23 12:57:59 +00:00
- scans enabled configured artifact inputs for `narratio.previous_session.artifact.*` requirements.
2026-11-30 00:31:36 +00:00
- clears managed `inputs/previous/` state on every invocation, then, when requirements exist:
2026-08-10 21:20:59 +00:00
- resolves the pointer-selected previous source through the shared resolver;
2026-05-23 12:57:59 +00:00
- downloads previous manifest/artifacts;
- records previous inputs in `manifest.inputs` .
2026-05-18 22:03:59 -05:00
2026-08-10 21:20:59 +00:00
Required previous-session inputs fail when unavailable; optional missing inputs
2026-09-02 13:53:23 +00:00
are typed skipped results. Each requirement resolves only from its unique
`published_output` declaration in the pointer-selected remote commit. Prepare
strips that selected run's immutable `published/` prefix to derive the local
cache path, then validates the committed checksum, size, and generation.
2026-05-18 22:03:59 -05:00
2026-05-23 12:57:59 +00:00
## Invariants
2026-08-09 21:50:21 +00:00
2026-11-30 00:31:36 +00:00
- only `prepare` hydrates canonical `inputs/previous/` state.
- managed previous artifacts are stored under `inputs/previous/artifacts/**` without
2026-08-09 21:50:21 +00:00
duplicate `artifacts/artifacts/` nesting.
2026-11-30 00:31:36 +00:00
- managed `inputs/previous/` state represents only the current requirement set.
2026-05-23 12:57:59 +00:00
- `manifest.inputs` ordering is deterministic (`kind` , `path` ).
2026-08-09 21:50:21 +00:00
2026-08-30 12:54:38 +00:00
## Resume Evidence
Prepare records a versioned semantic-configuration fingerprint for the
resolved campaign/session selection, local-versus-S3 audio mode and canonical
audio names, stable-input ownership/presence, previous-session identity, and
2026-08-30 14:08:35 +00:00
the party mode plus canonical players projection version, and the effective
previous-artifact requirement set. A change reruns prepare and
2026-08-30 12:54:38 +00:00
stales its fixed descendants. Existing successful records without this
evidence rerun once when selected.
2026-11-30 02:40:17 +00:00
Workspace placement are not semantic when logical selection,
2026-11-17 22:42:53 +00:00
canonical names, and effective bytes are equivalent.
2026-08-30 12:54:38 +00:00
The fingerprint deliberately does not read or rehash large audio. Prepared
2026-08-30 18:51:20 +00:00
input checksums remain the content provenance. Before reusing success, prepare
validates every durable prepared copy and compares current stable-input bytes,
2026-11-27 17:09:21 +00:00
effective campaign/session, canonical party, derived-player and resolved glossary
bytes, local audio membership/checksums, or S3 key/size/entity-tag identity with that provenance.
2026-11-17 22:42:53 +00:00
Source relocation with equivalent effective documents, names, and bytes remains
reusable; changed or unavailable evidence causes a normal prepare rerun.
2026-08-30 12:54:38 +00:00
2026-08-09 21:50:21 +00:00
## Related Contracts And Tests
- [Configuration ](../config.md ) owns audio selection, stable input fields, and
previous-session settings.
2026-11-30 02:40:17 +00:00
- [Operations ](../operations.md ) owns physical input, audio, and
2026-08-09 21:50:21 +00:00
previous-state layout.
- [Storage Internals ](storage.md ) and [Artifact Internals ](artifacts.md ) explain
the internal collaborators.
- Implementation and tests: `internal/stage/prepare.go` ,
2026-08-30 12:54:38 +00:00
`internal/stage/prepare_test.go` ,
2026-08-30 18:51:20 +00:00
`internal/stage/prepare_resume.go` ,
`internal/stage/prepare_resume_test.go` ,
2026-08-30 12:54:38 +00:00
`internal/stage/semantic_contracts_initial.go` ,
`internal/stage/semantic_contracts_initial_test.go` ,
`internal/audio/s3_audio_test.go` ,
2026-08-09 21:50:21 +00:00
`internal/previouscache/*_test.go`