2026-05-18 22:03:59 -05:00
# Stage: analyze
## Purpose
2026-05-19 19:42:28 -05:00
Execute selected configured Scriptorium artifacts in deterministic dependency order and promote successful outputs to canonical session artifact paths.
2026-05-18 22:03:59 -05:00
2026-05-20 15:17:04 +00:00
## Inputs and outputs
2026-05-18 22:03:59 -05:00
Inputs:
2026-05-20 15:17:04 +00:00
- configured artifact definitions from `pipeline.scriptorium.artifacts` ;
- selected artifact filter (`--artifacts` ) when provided;
- resolved artifact sources from resolver/catalog.
Source types used by analyze:
- built-ins: `narratio.transcript.*` , `narratio.bounds.session` ;
- configured artifacts: `narratio.artifact.<artifact_key>` ;
- canonical previous-session artifacts: `narratio.previous_session.artifact.<artifact_key>` ;
- legacy path-based previous-session source: `previous_session_artifact` (uses `inputs.*.path` ).
2026-05-18 22:03:59 -05:00
Outputs:
2026-05-20 15:17:04 +00:00
- promoted configured artifact files at each configured `output_path` ;
- stage metadata (`generated_artifacts` , `reused_artifacts` , selected/order info).
2026-05-18 22:03:59 -05:00
## Boundaries
Owns:
2026-05-20 15:17:04 +00:00
- runtime artifact catalog construction;
- selected-artifact planning and dependency ordering;
- per-input resolution and required/optional handling;
- Scriptorium render/run invocation;
- run-local output generation and canonical promotion.
2026-05-18 22:03:59 -05:00
Does not own:
2026-05-20 15:17:04 +00:00
- prepare-time previous-session hydration;
- object-store access for previous-session sources;
- archive promotion policy.
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`
- `session.campaign`
- `pipeline.workspace.root`
- `pipeline.scriptorium.binary`
- `pipeline.scriptorium.config_path`
- `pipeline.scriptorium.timeout`
- `pipeline.scriptorium.render_debug`
2026-05-19 19:42:28 -05:00
- `pipeline.scriptorium.artifacts.<name>.*`
2026-05-18 22:03:59 -05:00
2026-05-20 15:17:04 +00:00
## External adapters used
2026-05-18 22:03:59 -05:00
- Scriptorium adapter:
2026-05-20 15:17:04 +00:00
- optional `RenderArtifact` when render-debug is enabled;
- `RunArtifact` for artifact generation.
2026-05-18 22:03:59 -05:00
2026-05-20 15:17:04 +00:00
## State and manifest behavior
- If Scriptorium config is absent, or no artifacts are executable after filtering, analyze returns success metadata with `skipped=true` .
- Builds runtime catalog with built-ins and configured `narratio.artifact.<name>` entries.
- Non-executable configured artifacts may still be marked available from existing canonical output files.
- Resolves canonical previous-session sources from local prepared `previous/` cache:
- prefers manifest-backed previous input paths when present;
- may fall back to current-session `previous/` filesystem paths.
- Analyze does not call object storage for canonical previous-session source resolution.
- Required canonical previous-session input missing:
- fails with guidance to run `narratio run-stage --force prepare` .
- Optional missing sources are omitted from adapter input paths.
2026-05-18 22:03:59 -05:00
2026-05-20 15:17:04 +00:00
## Skip and resume behavior
2026-05-19 19:42:28 -05:00
- Runner-level skip applies when analyze is already `succeeded` and `--force` is not set.
2026-05-20 15:17:04 +00:00
- Analyze is stage-scoped for resume; no per-artifact manifest resume state.
- `--artifacts` filters executable artifacts but does not imply force rerun.
2026-05-18 22:03:59 -05:00
2026-05-20 15:17:04 +00:00
## Failure behavior
- Fails on dependency-order violations, missing required inputs, resolver validation failures, adapter errors, and missing/empty generated outputs.
- Required unavailable configured artifact source (`narratio.artifact.<name>` ) fails before invocation.
- Required canonical previous-session source fails with prepare-rerun guidance.
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/analyze_test.go`
2026-05-19 19:42:28 -05:00
- `internal/artifacts/catalog_test.go`
- `internal/artifacts/artifact_resolver_test.go`
2026-05-20 15:17:04 +00:00
- `internal/app/restore_workflow_test.go`
2026-05-18 22:03:59 -05:00
2026-05-20 15:17:04 +00:00
## Architectural invariants
- Canonical previous-session behavior is local-cache only during analyze.
- Generated outputs are validated and promoted before stage success is recorded.
- Resolver/catalog decisions stay deterministic and validation-gated.