2026-05-18 22:03:59 -05:00
|
|
|
|
# Stage: prepare
|
|
|
|
|
|
|
|
|
|
|
|
## Purpose
|
2026-05-20 15:17:04 +00:00
|
|
|
|
Materialize canonical current-session input state and provenance before downstream stages run.
|
2026-05-18 22:03:59 -05:00
|
|
|
|
|
2026-05-20 15:17:04 +00:00
|
|
|
|
Prepare owns:
|
|
|
|
|
|
- local input file materialization (`inputs/**`);
|
|
|
|
|
|
- audio input materialization (`audio/**`);
|
|
|
|
|
|
- previous-session cache hydration (`previous/**`) for canonical previous-session artifact sources.
|
|
|
|
|
|
|
|
|
|
|
|
## Inputs and outputs
|
2026-05-18 22:03:59 -05:00
|
|
|
|
Inputs:
|
2026-05-20 15:17:04 +00:00
|
|
|
|
- resolved config/session (`pipeline.yml`, `session.yml`);
|
|
|
|
|
|
- session-local input files (`speakers`, `autocorrect`, `glossary`);
|
2026-05-18 22:03:59 -05:00
|
|
|
|
- audio source:
|
2026-05-20 15:17:04 +00:00
|
|
|
|
- local: `session.inputs.audio_dir` or `session.inputs.audio_files`;
|
|
|
|
|
|
- S3: `session.inputs.audio_s3.prefix`;
|
|
|
|
|
|
- configured enabled Scriptorium artifact inputs (for previous-session requirement scanning);
|
|
|
|
|
|
- remote previous-session current archive state when previous hydration is required.
|
2026-05-18 22:03:59 -05:00
|
|
|
|
|
|
|
|
|
|
Outputs:
|
2026-05-20 15:17:04 +00:00
|
|
|
|
- `inputs/session.yml`;
|
|
|
|
|
|
- `inputs/pipeline.resolved.yml`;
|
|
|
|
|
|
- `inputs/speakers.yml`;
|
|
|
|
|
|
- `inputs/autocorrect.yml`;
|
|
|
|
|
|
- `inputs/glossary.yml`;
|
|
|
|
|
|
- `audio/*.flac` in canonical session `audio/`;
|
|
|
|
|
|
- optional `previous/manifest.json`;
|
|
|
|
|
|
- optional `previous/artifacts/**`;
|
|
|
|
|
|
- deterministic `manifest.Inputs` records with checksums and provenance metadata.
|
2026-05-18 22:03:59 -05:00
|
|
|
|
|
|
|
|
|
|
## Boundaries
|
|
|
|
|
|
Owns:
|
2026-05-20 15:17:04 +00:00
|
|
|
|
- input path resolution and materialization;
|
|
|
|
|
|
- S3 audio list/download/copy flow;
|
|
|
|
|
|
- previous-session artifact requirement collection from enabled configured artifacts;
|
|
|
|
|
|
- previous cache lifecycle when requirements exist (clear and rehydrate managed `previous/` state).
|
2026-05-18 22:03:59 -05:00
|
|
|
|
|
|
|
|
|
|
Does not own:
|
2026-05-20 15:17:04 +00:00
|
|
|
|
- transcript or artifact generation;
|
|
|
|
|
|
- analyze-stage source resolution;
|
|
|
|
|
|
- archive commit behavior.
|
2026-05-18 22:03:59 -05:00
|
|
|
|
|
2026-05-20 15:17:04 +00:00
|
|
|
|
## Config fields used
|
2026-05-18 22:03:59 -05:00
|
|
|
|
- `session.session_id`
|
2026-05-20 15:17:04 +00:00
|
|
|
|
- `session.previous_session_id`
|
2026-05-18 22:03:59 -05:00
|
|
|
|
- `session.campaign`
|
|
|
|
|
|
- `session.inputs.speakers_file`
|
|
|
|
|
|
- `session.inputs.autocorrect_file`
|
|
|
|
|
|
- `session.inputs.glossary_file`
|
|
|
|
|
|
- `session.inputs.audio_dir`
|
|
|
|
|
|
- `session.inputs.audio_files`
|
|
|
|
|
|
- `session.inputs.audio_s3.prefix`
|
|
|
|
|
|
- `pipeline.workspace.root`
|
|
|
|
|
|
- `pipeline.spool.root`
|
|
|
|
|
|
- `pipeline.storage.s3.bucket`
|
|
|
|
|
|
- `pipeline.storage.s3.root_prefix`
|
2026-05-20 15:17:04 +00:00
|
|
|
|
- `pipeline.scriptorium.artifacts.<name>.enabled`
|
|
|
|
|
|
- `pipeline.scriptorium.artifacts.<name>.inputs.<key>.source`
|
|
|
|
|
|
- `pipeline.scriptorium.artifacts.<name>.inputs.<key>.required`
|
2026-05-18 22:03:59 -05:00
|
|
|
|
|
2026-05-20 15:17:04 +00:00
|
|
|
|
## External adapters used
|
|
|
|
|
|
- `storage.ObjectStore` for:
|
|
|
|
|
|
- S3 audio listing/downloads;
|
|
|
|
|
|
- previous-session current pointer/manifest/artifact object checks and downloads.
|
2026-05-18 22:03:59 -05:00
|
|
|
|
|
2026-05-20 15:17:04 +00:00
|
|
|
|
## State and manifest behavior
|
2026-05-18 22:03:59 -05:00
|
|
|
|
- Ensures workspace layout exists.
|
2026-05-20 15:17:04 +00:00
|
|
|
|
- Materializes canonical input files and audio files.
|
|
|
|
|
|
- Scans enabled configured artifact inputs for canonical sources:
|
|
|
|
|
|
- `narratio.previous_session.artifact.<artifact_key>`
|
|
|
|
|
|
- If one or more canonical previous-session requirements exist:
|
|
|
|
|
|
- clears managed `previous/` state;
|
|
|
|
|
|
- hydrates required/optional previous artifacts from the configured previous session’s committed archive current state;
|
|
|
|
|
|
- writes `previous/manifest.json` and hydrated `previous/artifacts/**`;
|
|
|
|
|
|
- records hydrated previous inputs in `manifest.Inputs` with source `previous_session_archive.current`.
|
|
|
|
|
|
- If no canonical previous-session requirements exist, prepare does not manage `previous/`.
|
|
|
|
|
|
- `manifest.Inputs` is sorted deterministically by `(kind, path)`.
|
|
|
|
|
|
|
|
|
|
|
|
## Required and optional previous-session behavior
|
|
|
|
|
|
- `previous_session_id` unset:
|
|
|
|
|
|
- if any referenced previous artifact is required: fail;
|
|
|
|
|
|
- if all referenced previous artifacts are optional: continue and omit them.
|
|
|
|
|
|
- Previous session archive current pointer or manifest missing:
|
|
|
|
|
|
- if any referenced previous artifact is required: fail;
|
|
|
|
|
|
- if all referenced previous artifacts are optional: continue and omit missing ones.
|
|
|
|
|
|
- Missing required previous artifact object: fail.
|
|
|
|
|
|
- Missing optional previous artifact object: omit.
|
|
|
|
|
|
- Downloaded previous artifacts must validate as non-empty files.
|
2026-05-18 22:03:59 -05:00
|
|
|
|
|
2026-05-20 15:17:04 +00:00
|
|
|
|
## Skip and resume behavior
|
|
|
|
|
|
- Runner-level skip remains authoritative:
|
|
|
|
|
|
- if `prepare` already succeeded and run is not forced, `prepare` does not run and no hydration/download occurs.
|
|
|
|
|
|
- If `prepare` runs (including with `--force`), it owns managed `previous/` state for canonical previous-session inputs.
|
2026-05-18 22:03:59 -05:00
|
|
|
|
|
2026-05-20 15:17:04 +00:00
|
|
|
|
## Failure behavior
|
|
|
|
|
|
- Fails on missing required input files, invalid audio-source combinations, empty/duplicate audio inputs, missing object store for S3 modes, and remote access/download/validation errors.
|
|
|
|
|
|
- For required canonical previous-session inputs, analyze-time missing-input guidance is to rerun:
|
|
|
|
|
|
- `narratio run-stage --force prepare`
|
2026-05-18 22:03:59 -05:00
|
|
|
|
|
2026-05-20 15:17:04 +00:00
|
|
|
|
## Tests to inspect before changing
|
2026-05-18 22:03:59 -05:00
|
|
|
|
- `internal/stage/prepare_test.go`
|
2026-05-20 15:17:04 +00:00
|
|
|
|
- `internal/stage/prepare_previous_test.go`
|
|
|
|
|
|
- `internal/artifacts/previous_requirements_test.go`
|
|
|
|
|
|
- `internal/app/runner_test.go`
|
2026-05-18 22:03:59 -05:00
|
|
|
|
|
2026-05-20 15:17:04 +00:00
|
|
|
|
## Architectural invariants
|
2026-05-18 22:03:59 -05:00
|
|
|
|
- `audio_dir`/`audio_files` and `audio_s3` are mutually exclusive.
|
2026-05-20 15:17:04 +00:00
|
|
|
|
- Storage keys are computed by callers using archive/path helpers; storage adapter receives explicit keys.
|
|
|
|
|
|
- `prepare` is the only stage that hydrates canonical previous-session cache state.
|