2026-05-23 13:01:17 +00:00
# Integration: Scriptorium
2026-05-18 22:03:59 -05:00
## Purpose
2026-05-23 13:01:17 +00:00
Define the Scriptorium adapter contract used by `analyze` and trim-bounds generation in `trim` .
2026-05-18 22:03:59 -05:00
2026-08-09 21:41:23 +00:00
## External Boundary
2026-05-18 22:03:59 -05:00
2026-08-09 21:41:23 +00:00
Narratio invokes Scriptorium as a subprocess in these modes:
2026-05-18 22:03:59 -05:00
2026-05-23 13:01:17 +00:00
- `scriptorium run`
- `scriptorium render`
2026-05-18 22:03:59 -05:00
2026-08-09 21:41:23 +00:00
The request timeout and parent cancellation bound each invocation. Internal
runner composition is documented in
[the adapter implementation guide ](../internal/adapters.md ).
2026-05-23 13:01:17 +00:00
## Request Contract
Both request types carry:
- binary/config/prompt/profile IDs;
- input map and vars map;
- output path;
- timeout;
- generated config + stdout/stderr log paths;
- optional API-key env var name;
- optional working directory.
2026-05-18 22:03:59 -05:00
2026-05-23 13:01:17 +00:00
## Result Contract
`ArtifactResult` returns:
- output/log/generated-config paths;
- exit code and duration;
- command mode (`run` or `render` );
- prompt/profile provenance;
- `ValidationFailed` marker;
- metadata map.
2026-05-18 22:03:59 -05:00
2026-05-23 13:01:17 +00:00
## Validation and Failure Semantics
Request validation fails for:
- missing binary, prompt id, or output path;
- non-positive timeout;
- empty input/var names;
- empty input path values;
- missing required credential env var when `APIKeyEnv` is set.
2026-05-18 22:03:59 -05:00
2026-05-23 13:01:17 +00:00
Run behavior:
- subprocess errors propagate with context;
- `run` exit code `2` is mapped to `ValidationFailed=true` ;
- successful subprocess still fails if output file is missing or empty.
2026-05-18 22:03:59 -05:00
2026-05-23 13:01:17 +00:00
Render behavior:
- subprocess errors propagate;
- output file must exist and be non-empty.
2026-05-18 22:03:59 -05:00
2026-05-23 13:01:17 +00:00
## Deterministic Behavior
- input and var maps are sorted into deterministic `--input` and `--var` CLI args.
2026-07-02 21:04:37 -05:00
- stage wiring adds `session_id=narratio-session-<session_id>` to every Scriptorium request for sticky upstream routing, overriding any configured `vars.session_id` .
2026-05-23 13:01:17 +00:00
- generated invocation YAML (`scriptorium.generated.v1` ) is emitted when requested.
- adapter is stateless and does not own artifact-selection policy.
2026-05-18 22:03:59 -05:00
2026-08-09 21:41:23 +00:00
## Configuration
Operator-selected values are defined under `pipeline.scriptorium.*` , including
per-artifact settings under `pipeline.scriptorium.artifacts.*` , in the
[configuration reference ](../config.md#pipeline ).
2026-05-18 22:03:59 -05:00
2026-05-23 13:01:17 +00:00
Maintained examples with Scriptorium config:
2026-08-09 21:50:21 +00:00
- [Full annotated pipeline ](../../examples/pipeline.full.annotated.yml )
- [Production-shaped pipeline ](../../examples/pipeline.production.yml )