Files
narratio/docs/internal/stage-prepare.md

121 lines
6.3 KiB
Markdown
Raw Normal View History

2026-05-18 22:03:59 -05:00
# Stage: prepare
## Purpose
Materialize canonical current-session inputs before processing stages.
2026-05-18 22:03:59 -05:00
## Inputs
- resolved campaign, session, and pipeline configuration
- the stable speakers input, inline autocorrection rules, canonical party, and optional glossary selections
- a local or S3 audio source when transcription needs audio
- previous-session input requirements from selected targets and their configured prerequisites
## Outputs
- `inputs/campaign.yml`
- `inputs/session.yml`
- `inputs/pipeline.resolved.yml`
- `inputs/speakers.yml`
- `inputs/autocorrect.yml`
- `inputs/glossaries/{party,campaign,setting,spells,combined}.yml`
- `inputs/players.yml`
- `inputs/party.yml`
- prepared recordings in `audio/` when audio is acquired
- optional `inputs/previous/artifacts/**`
- deterministic `manifest.inputs` entries (checksums + provenance)
## Key Behavior
- validates required config/store state and resolves selected vocabulary before audio work.
- 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.
- 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
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.
- derives the party glossary and resolves the remaining named collections through
`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.
- enforces local audio vs S3 audio mutual exclusivity.
- uses `internal/audio` for read-only source discovery shared with inspection;
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; unresolved speaker-ID
collisions fail before audio materialization.
- 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.
- writes effective autocorrection rules as a Seriatim envelope, with checksum,
size, and source provenance, including an empty list when no rules apply.
- renders standalone effective campaign, session, and canonical party documents,
and deterministically generates the prepared players projection.
- 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).
Bounded reference preparation uses projected work and reused local checkpoint
keys, preserving their history while excluding supplied products' history.
- 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;
- downloads declared previous 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
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
## Invariants
- prepare and restore hydrate canonical `inputs/previous/` state from exact
declared previous-session products.
- managed previous artifacts are stored under `inputs/previous/artifacts/**` without
duplicate `artifacts/artifacts/` nesting.
- managed `inputs/previous/` state represents only the current requirement set.
- `manifest.inputs` ordering is deterministic (`kind`, `path`).
## 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 presence, previous-session identity, the canonical
players projection version, and the effective
previous-artifact requirement set. A change reruns prepare and
stales its fixed descendants. Existing successful records without this
evidence rerun once when selected.
Source ownership and workspace placement are not semantic when logical selection,
canonical names, and effective bytes are equivalent.
The fingerprint deliberately does not read or rehash large audio. Prepared
input checksums remain the content provenance. Before reusing success, prepare
validates every durable prepared copy and compares current stable-input bytes,
effective campaign/session, canonical party, derived-player and resolved glossary
bytes, and, when audio was needed, local audio membership/checksums or S3
key/size/entity-tag identity with that provenance.
Source relocation with equivalent effective documents, names, and bytes remains
reusable; changed or unavailable evidence causes a normal prepare rerun.
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.
## Related Contracts And Tests
- [Configuration](../config.md) owns audio selection, stable input fields, and
previous-session settings.
- [Operations](../operations.md) owns physical input, audio, and
previous-state layout.
- [Storage Internals](storage.md) and [Artifact Internals](artifacts.md) explain
the internal collaborators.
- Implementation and tests: `internal/stage/prepare.go`,
`internal/stage/prepare_test.go`,
`internal/stage/prepare_resume.go`,
`internal/stage/prepare_resume_test.go`,
`internal/stage/semantic_contracts_initial.go`,
`internal/stage/semantic_contracts_initial_test.go`,
`internal/audio/discovery_test.go`, `internal/audio/s3_audio_test.go`,
`internal/previouscache/*_test.go`