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

4.5 KiB

Stage: analyze

Purpose

Execute selected configured Scriptorium artifacts in dependency order and materialize outputs.

Inputs

  • configured artifacts from pipeline.scriptorium.artifacts
  • optional selected artifact keys supplied through the stage environment
  • built-in, configured, extraction, and previous-session source references in artifact inputs

Supported source families:

  • built-ins: narratio.transcript.*, narratio.bounds.session
  • prepared stable inputs: narratio.input.players, narratio.input.party, narratio.input.glossary, narratio.input.spell_catalog
  • configured artifacts: narratio.artifact.<key>
  • extraction lanes: narratio.extraction.<key>
  • previous-session cache: narratio.previous_session.artifact.<key>

Outputs

  • one materialized output per executed configured artifact (output_path)
  • stage metadata describing selected/generated/reused artifacts

Key Behavior

  • when Scriptorium is absent or no configured artifact is executable, completes successfully with no outputs and records explanatory metadata. This is not an explicit self-skip: both manifests record success, satisfy publish's prerequisite, and an ordinary later run reuses the result until forced.
  • builds a runtime artifact catalog containing built-ins, configured artifacts, and configured extraction lanes. Extraction availability is hydrated only from compatible successful extraction evidence.
  • uses enabled configured artifacts by default. An explicit --artifacts selection is a one-invocation override: it makes exactly the named configured artifacts executable even when disabled, and does not automatically include dependencies. A selected artifact's dependencies must instead already be available to the catalog.
  • makes a non-executable configured artifact reusable only when its current manifest record and durable output pass the configured-artifact evidence contract; an incidental or stale canonical file is unavailable.
  • validates selected artifact dependency order (cycle-safe topo ordering).
  • resolves required/optional inputs per artifact source definition into an ordered semantic identity. Each identity records the configured input name, canonical source ID, required policy, explicit presence, source contract, checksum, size, and a source-based logical identity. Workspace paths and producer run IDs are excluded.
  • orders input identities by configured input name independently of Go map iteration. Runtime adapter paths remain a separate execution-only map.
  • omits an unavailable optional input from the adapter request while retaining explicit absence in its semantic identity; an unavailable required input fails.
  • resolves prepared stable input sources through the shared manifest-authoritative identity resolver; it does not accept incidental files or fall back to campaign/session source paths.
  • reuses checksums and sizes from validated prepared, extraction, and current configured-artifact evidence. Other resolved inputs are hashed as confined regular files with streaming reads and the central resolved-artifact size limit.
  • resolves previous-session sources from local previous/ cache only.
  • runs optional render-debug, then artifact execution.
  • validates non-empty output files and materializes canonical outputs.

Failure Semantics

  • required missing configured/previous-session inputs fail.
  • missing required prepared stable input source includes prepare rerun guidance.
  • missing required previous-session source includes prepare rerun guidance.
  • missing required narratio.transcript.final_markdown or narratio.transcript.final_trimmed_markdown inputs includes render rerun guidance.
  • dependency cycles or unavailable required dependencies fail.
  • adapter validation failures fail stage.

Invariants

  • analyze performs no remote storage calls for previous-session source resolution.
  • input-identity resolution is read-only: it does not invoke adapters, materialize outputs, update status, or create run records.
  • output provenance and metadata are deterministic per execution.
  • Configuration owns artifact fields and source-selection rules.
  • CLI owns user-visible artifact selection.
  • Scriptorium owns the subprocess contract.
  • Implementation and tests: internal/stage/analyze.go, internal/stage/analyze_input_identity.go, internal/stage/analyze_test.go, internal/stage/analyze_input_identity_test.go