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-12-02 15:26:40 +00:00
- a local or S3 audio source when transcription needs audio
2026-12-02 14:37:39 +00:00
- previous-session input requirements from selected targets and their configured prerequisites
2026-05-23 12:57:59 +00:00
## 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-12-02 15:26:40 +00:00
- prepared recordings in `audio/` when audio is acquired
2026-11-30 00:31:36 +00:00
- 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.
2026-12-02 15:26:40 +00:00
- prepares references and history without acquiring audio when a validated
supplied transcript satisfies transcription. Forced or uncovered transcription
requires an audio selection. Preparation metadata records whether audio was
prepared, and reference-only preparation preserves supplied-product records.
2026-12-02 15:39:04 +00:00
- bounded downstream runs may prepare or reuse references under the workspace
lock before readiness checks, even when prepare lies outside the selected range.
Existing audio input records remain available without being recertified by
2026-12-02 17:46:27 +00:00
reference-only preparation. An imported configured or extraction product can
support this workflow without any transcript. Reference-only validation
explicitly excludes audio acquisition and source checks.
2026-11-27 17:09:21 +00:00
- 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-12-02 03:25:20 +00:00
- uses `internal/audio` for read-only source discovery shared with inspection;
rejects duplicate explicit local audio sources after resolution.
2026-08-10 21:53:54 +00:00
- gives distinct local source paths with the same basename deterministic unique
2026-12-02 03:25:20 +00:00
prepared filenames so neither source is overwritten; unresolved speaker-ID
collisions fail before audio materialization.
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-12-02 14:37:39 +00:00
- collects `narratio.previous_session.artifact.*` requirements from the selected
targets and their full prerequisite closure, including disabled prerequisites;
see [previous requirement collection ](artifacts.md#previous-requirement-collection ).
2026-12-02 17:46:27 +00:00
Bounded reference preparation uses the actual projected generation keys,
preserving history needed by new work while excluding reused products' history.
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-12-02 15:50:59 +00:00
- downloads declared previous artifacts;
2026-05-23 12:57:59 +00:00
- 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-12-02 16:49:46 +00:00
- prepare and restore hydrate canonical `inputs/previous/` state from exact
declared previous-session products.
2026-11-30 00:31:36 +00:00
- 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
2026-12-02 16:49:46 +00:00
audio names, stable-input presence, previous-session identity, the canonical
players projection version, and the effective
2026-08-30 14:08:35 +00:00
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-12-02 16:49:46 +00:00
Source ownership and 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
2026-12-02 15:26:40 +00:00
bytes, and, when audio was needed, 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-12-02 13:16:14 +00:00
Confirmed mismatches and sources that cannot be verified have distinct reasons;
the latter retains the inspection error. Planning supplies the same S3 identity
collaborator to this validator without running preparation.
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` ,
2026-12-02 03:25:20 +00:00
`internal/audio/discovery_test.go` , `internal/audio/s3_audio_test.go` ,
2026-08-09 21:50:21 +00:00
`internal/previouscache/*_test.go`