Document Scriptorium preflight and native integration

This commit is contained in:
2026-11-26 04:40:25 +00:00
parent e9d57fb7aa
commit f930ebf337
14 changed files with 186 additions and 90 deletions

View File

@@ -94,6 +94,11 @@ reruns selected work; dependent invalidation can extend beyond that range.
Bounded starts require valid preceding manifest state. Ordinary execution uses
semantic resume checks rather than rerunning all selected work.
Before stage attempts, `run` inspects requirements for projected Scriptorium
work. Missing required bindings or variables and inspection failures stop the
invocation; warnings alone do not. `artifacts regenerate` uses the same check.
See [operations](operations.md#prompt-requirements-preflight) for recovery.
Analysis-only rebuilding uses `run SESSION --stage analyze --force`; it does
not refresh extraction. Publishing alone uses `run SESSION --stage publish`,
adding `--force` when a rerun is intended. It does not schedule cleanup. See
@@ -135,7 +140,8 @@ Accepts the same stage/range, force, artifact, and context selections as `run`.
Reports execution/reuse actions and reasons, analysis targets, prerequisite work,
and publication mappings through shared planners. Planning reads existing state
without creating a workspace, changing manifests, acquiring execution locks, or
initializing stage adapters. It does not predict unknown output identities.
initializing stage adapters or invoking requirements inspection. It does not
predict unknown output identities.
## Session validate
@@ -143,10 +149,14 @@ initializing stage adapters. It does not predict unknown output identities.
narratio session validate SESSION --session-file ./session.yml
```
Read-only preflight checks configuration and required input, audio,
previous-session, publication, and lock readiness. Material findings remain in
the report regardless of diagnostic visibility. Invalid configuration uses the
native input classification; readiness failures are operational failures.
Read-only validation checks configuration and required input, audio,
previous-session, publication, and lock readiness. It also inspects enabled trim
and analysis definitions and their configured prerequisites, regardless of
output reuse. Missing prompt requirements or unsuccessful inspection invalidate
the report; incomplete or conditional discovery alone is a warning. Material
findings remain in the report regardless of diagnostic visibility. Invalid
configuration uses the native input classification; readiness failures are
operational failures.
## Session status

View File

@@ -534,9 +534,10 @@ for compatibility ownership.
Set `scriptorium.credentials: [OPENROUTER_API_KEY]` in the pipeline file to
forward that provider key to Scriptorium. List additional provider names only
when the selected downstream configuration needs them. The same list applies
to trim bounds generation, analysis (including character families), and their
render-debug calls. Scriptorium retains provider/profile selection; Narratio
does not pass a model-request `--api-key-env` override.
to requirements inspection, trim bounds generation, analysis (including
character families), and their render-debug calls. Scriptorium retains
provider/profile selection; Narratio does not pass a model-request
`--api-key-env` override.
As with Audita and Notarius, names are ConfigKit secret references resolved at
pipeline load time using the configured bootstrap and environment,
@@ -565,6 +566,9 @@ For each `pipeline.scriptorium.artifacts.<name>`:
| `vars` | map | No | values must be string or bool; `session_id` is reserved and overwritten by Narratio |
Narratio adds `session_id=narratio-session-<session_id>` to every Scriptorium request for sticky upstream LLM routing. If an artifact config sets `vars.session_id`, Narratio replaces that value before invoking Scriptorium. Use a different variable name if a prompt needs the raw Narratio session ID as content.
Discovery, preview, and generation receive the same effective variables,
including family member values and explicitly empty strings. Narratio forwards
the sticky value as a template variable, not as a direct session override.
Without `--artifacts`, analyze executes enabled configured artifacts. With an
explicit `--artifacts` list, the exact named configured artifacts are the
@@ -583,6 +587,13 @@ For each artifact input `pipeline.scriptorium.artifacts.<name>.inputs.<input_nam
| `source` | string | Yes | built-in runtime source, prepared input source, `narratio.extraction.<name>`, `narratio.artifact.<name>`, or `narratio.previous_session.artifact.<name>` |
| `required` | bool | No | optional input requirement |
The input map key is the prompt input name; `source` identifies the Narratio
artifact that supplies it. Requirements discovery compares exact input names
with these keys before generated files exist. A required prompt input bound to
an optional source produces a warning when availability is unknown; runtime
resolution may still omit the source. See
[prompt preflight](operations.md#prompt-requirements-preflight).
`artifact` and `path` are obsolete and rejected by strict configuration
loading. Use the canonical `source` identifier to select the input; Narratio
does not provide adapter-specific input passthrough fields.

View File

@@ -23,8 +23,8 @@ focused stage documents.
discovery (`notarius run`).
- [Party](./party.md): canonical campaign roster input.
- [Seriatim](./seriatim.md): merge, normalize, trim, and render operations.
- [Scriptorium](./scriptorium.md): artifact generation and debug rendering
(`scriptorium run|render`).
- [Scriptorium](./scriptorium.md): artifact generation, prepared previews, and
prompt requirements discovery.
- [WhisperX](./whisperx.md): speaker-audio transcription over HTTP.
## Related Canonical Docs

View File

@@ -1,80 +1,53 @@
# Integration: Scriptorium
## Purpose
Define the Scriptorium adapter contract used by `analyze` and trim-bounds generation in `trim`.
## Boundary
## External Boundary
Narratio uses the independently installed Scriptorium v0.16.0 native CLI for
trim bounds and configured analysis artifacts. It invokes `run PROMPT_ID` for
generation, `promptkit show prepared PROMPT_ID` for optional preview, and
`promptkit requirements show PROMPT_ID` for early discovery. Scriptorium owns
prompt, profile, backend, and private configuration resolution. The
[upstream CLI migration guide](https://forge.maximumdirect.net/eric/scriptorium/src/tag/v0.16.0/docs/consumers/upgrading-cli.md)
and [subprocess contract](https://forge.maximumdirect.net/eric/scriptorium/src/tag/v0.16.0/docs/integrations/subprocess.md)
own the native interface and deployment migration.
Narratio invokes Scriptorium as a subprocess in these modes:
Generation selects artifact-only text output. Preview and requirements use
native JSON. Narratio forwards selected configuration and profile identifiers,
sorted repeated `--input-file NAME=PATH` bindings where files are needed, and
repeated `--var KEY=VALUE` assignments. Commas and later equals signs remain
literal. Discovery supplies no input paths and makes no model call. Narratio's
supervisor deadline covers each invocation; generation also forwards the same
duration as `--run-timeout`, separate from Scriptorium's per-attempt timeout.
- `scriptorium run`
- `scriptorium render`
## Streams And Outcomes
The request timeout and parent cancellation bound each invocation. Internal
runner composition is documented in
[the adapter implementation guide](../internal/adapters.md).
Narratio captures stdout directly into the run-local artifact or preview, or
into memory for discovery. Result bytes are preserved and limited to 64 MiB;
they are not diagnostic logs and are not redacted. Treat generated artifacts
and prepared previews as potentially sensitive. Stderr remains separately
bounded and redacted. A capture failure aborts the supervised subprocess.
## 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 list of already-resolved credential references;
- optional working directory.
A successful generation or preview must produce a nonempty result; preview must
also be valid JSON. Narratio validates the result before stage-owned canonical
promotion. A nonzero outcome or delivery failure remains an error even if
stdout contains bytes. Native exit status 4 identifies completed generated
content validation failure; status 2 is a usage or configuration failure.
Invocation records describe the actual arguments and stdout destination.
## 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.
Requirements discovery returns the native inventories, identities,
completeness, and structured issues. A successful partial report is distinct
from a process or decoding failure. Narratio compares the reported requirements
with its intended bindings; discovery does not establish future file availability
or guarantee a later model call. See [preflight internals](../internal/preflight.md)
and the [upstream requirements contract](https://forge.maximumdirect.net/base-layer/commandkit/src/commit/0b53a63648c536afe50c46f948159116f776adae/docs/cli.md#promptkit-requirements).
## 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;
- unresolved or empty selected credential references.
## Credentials And Configuration
Both modes use the shared credential forwarding used by Audita and Notarius:
selected names and captured values augment the minimal child environment, and
all selected values are registered for captured-stream redaction. The adapter
does not reread the parent environment or override Scriptorium's provider
selection with `--api-key-env`. Generated invocation records and result metadata
contain `credential_env_names`, never credential values. This does not scan or
redact files written directly by Scriptorium. Selection semantics belong in
[Scriptorium credentials](../config.md#scriptorium-credentials).
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.
Each artifact result is limited to 64 MiB and must be a regular file without
symlinked path components.
Render behavior:
- subprocess errors propagate;
- output file must exist and be non-empty.
## Deterministic Behavior
- input and var maps are sorted into deterministic `--input` and `--var` CLI args.
- stage wiring adds `session_id=narratio-session-<session_id>` to every Scriptorium request for sticky upstream routing, overriding any configured `vars.session_id`.
- generated invocation YAML (`scriptorium.generated.v1`) is emitted when requested.
- adapter is stateless and does not own artifact-selection policy.
## Configuration
Operator-selected values are defined under `pipeline.scriptorium.*`, including
per-artifact settings under `pipeline.scriptorium.artifacts.*`, in the
[configuration reference](../config.md#pipeline).
Maintained examples with Scriptorium config:
- [Full annotated pipeline](../../examples/pipeline.full.annotated.yml)
- [Production-shaped pipeline](../../examples/pipeline.production.yml)
Selected ConfigKit secret references are forwarded by exact environment name
for discovery, preview, and generation. Their captured values are registered
for stderr diagnostic redaction, while invocation records retain names only.
Narratio does not choose the provider or pass a direct API-key override. This
does not scrub arbitrary result content or files written by Scriptorium. See
[Scriptorium credentials](../config.md#scriptorium-credentials) and
[artifact entries](../config.md#scriptorium-artifact-entries) for Narratio's
configuration and binding semantics.

View File

@@ -61,6 +61,12 @@ state without constructing or invoking stage-execution adapters. The shared
command configuration loader may still use object storage to retrieve a missing
remote session file before planning begins.
Before a run starts stage attempts, the application projects selected work and
uses the invocation's Scriptorium runner for any needed requirements checks.
The same runner is then available to generation. Explicit session validation
uses an invocation-owned factory and the shared checker. See
[preflight internals](preflight.md).
Notarius is composed only when extraction is enabled; the extract stage owns
prepared reference resolution, receipt, bundle, and configured-lane policy.
The adapter validates the ordered selector/absolute-path pairs and is the sole
@@ -98,8 +104,10 @@ in-memory backend without changing package state.
original result classification. Child environments contain only the execution
baseline and adapter-specified values; configured credentials are resolved
once by ConfigKit and passed explicitly as sensitive values. Adapters do not
re-read their named environment references. Stdout and stderr are redacted while streaming into separate
8 MiB diagnostic captures; a bounded wait closes a stream retained by a
re-read their named environment references. Diagnostic-only stdout and stderr
are redacted while streaming into separate 8 MiB captures. Scriptorium result
mode directs stdout to a caller-owned, byte-preserving bounded writer instead;
capture failures use the same abort path. A bounded wait closes a stream retained by a
departed leader's descendant. Unsupported platforms reject owned command
execution.

View File

@@ -28,7 +28,8 @@ progress and artifact services resolve durable inputs and outputs.
The pipeline runner follows one explicit invocation lifecycle: inspect bounded
prerequisites without mutation, prepare the workspace layout, acquire one
session lock, load or create the authoritative session manifest, compose only
session lock, load or create the authoritative session manifest, check projected
Scriptorium work, compose only
the collaborators needed by the selected range, execute each selected stage in
order, finalize terminal state, release resources, and return a possibly partial
summary with preserved failure causes. Narrow terminal local persistence detaches
@@ -45,6 +46,7 @@ failed stage or required manifest save prevents later stages from starting.
| Application orchestration | `internal/app` | Native CommandKit declarations/reporting, lazy configuration selection, secret-file environment loading, production composition, session locking, planning, execution, restore, and user-facing reporting. |
| Configuration | [`internal/config`](configuration.md) | Typed ConfigKit results and lifecycle defaults, imports/overlays, canonical party loading, separate catalog/player/publication derivation, session templating, and validation. |
| Pipeline stages | `internal/stage` | Canonical stage registry, shared stage contract, execution dependencies, and implemented stage behavior. |
| Prompt preflight | [`internal/preflight`](preflight.md) | Assess native prompt requirements against intended bindings for execution and validation. |
| External boundaries | `internal/adapters`, `internal/audio` | WhisperX HTTP, downstream subprocesses, notification, object storage, and S3 audio materialization behind Narratio contracts. |
| Manifests | `internal/manifest` | Durable session progress, stage transitions, validation, and atomic persistence. |
| Artifacts and paths | `internal/artifacts`, `internal/pathsafe` | Artifact identities and resolution, local and remote path/key models, current-state discovery, and confined relative destinations. |
@@ -116,6 +118,8 @@ so any earlier replacement can stale a prior cleanup result.
field ownership, decoding, and source-relative resource semantics.
- [Adapter Internals](adapters.md): external adapter boundaries, composition,
failure behavior, and test surfaces.
- [Preflight Internals](preflight.md): projected target selection and shared
requirements assessment.
- [Artifact Internals](artifacts.md): source identities, runtime catalog,
resolution, previous requirements, and current-state helpers.
- [Manifest Internals](manifest.md): session records, persistence, and execution

View File

@@ -0,0 +1,37 @@
# Internal: Prompt Requirements Preflight
The application selects intended Scriptorium requests after acquiring final
domain configuration. For execution, it projects the bounded plan against a
clone of the locked manifest using the same stage decisions and analysis work
planner as `session plan`. Enabled trim is inspected when projected to run;
analysis targets come from the projected execution order, including scheduled
disabled prerequisites and excluding reusable work. The projection is not an
execution commitment: earlier outputs can change later decisions.
For `session validate`, the application selects enabled definitions and their
configured prerequisite closure independently of output reuse. Both entry
points construct effective contexts through stage-owned helpers and call
`internal/preflight`. Input-map keys remain prompt binding names, distinct from
Narratio source IDs. No artifact is materialized or fetched for this check.
The checker invokes the adapter sequentially and assesses native structured
findings. Definite missing required bindings and unsupplied required variables
are errors. An optional source for a required prompt input, conditional
requirements, incomplete discovery, and discovery issues produce warnings.
It retains earlier findings and underlying inspection errors, and stops on
cancellation. The application formats findings for its invocation reporter or
validation report; the checker does not mutate manifests or acquire config.
The run hook executes before stage attempts or live pre-execution invalidation.
It reuses an injected Scriptorium runner or creates the invocation-owned runner
that generation later uses. Empty target sets invoke no inspector. Validation
uses its own invocation-owned factory and creates no execution workspace,
run directory, lock, report file, or manifest update. Discovery can read
Scriptorium configuration and resources, but does not call a model or establish
future input contents. Actual execution and input resolution remain authoritative.
See the [Scriptorium contract](../integrations/scriptorium.md),
[CLI](../cli.md#session-validate), and [operations](../operations.md#prompt-requirements-preflight).
Implementation and focused tests are in `internal/preflight`,
`internal/app/preflight_targets.go`, `internal/app/runner_preflight.go`,
`internal/app/session_inspection_command.go`, and `internal/stage/scriptorium_vars.go`.

View File

@@ -141,6 +141,10 @@ Supported source families:
- 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.
- shares effective prompt context and variables with requirements inspection;
preview and generation capture their own results separately from stderr logs.
Application preflight selects projected work through the same planner; see
[preflight internals](preflight.md).
## Failure Semantics

View File

@@ -17,6 +17,7 @@ applies a bounds-driven trim.
## Key Behavior
When `trim.enabled=true`:
- shares the effective prompt context with early requirements inspection;
- runs Scriptorium bounds artifact generation;
- optionally runs render-debug output generation;
- validates bounds payload against transcript;
@@ -32,6 +33,12 @@ When `trim.enabled=false`:
- normalized transcript is required input.
- bounds output exists only in enabled trim path.
- render-debug output is diagnostic and not a declared stage output.
- prepared preview and generated bounds use separate result destinations;
Scriptorium stderr and invocation records are the diagnostic references.
The application checks projected bounds requirements before attempting any
stage. See [preflight internals](preflight.md); actual transcript resolution and
bounds validation remain responsibilities of this stage.
## Resume Semantics

View File

@@ -80,6 +80,25 @@ outputs, dependencies, and selected-party members. See
[configuration inspection](cli.md#configuration-inspection) for selection and
comparison details.
### Prompt requirements preflight
Install Scriptorium v0.16.0 and migrate its configuration and prompt definitions
using the [upstream migration guide](https://forge.maximumdirect.net/eric/scriptorium/src/tag/v0.16.0/docs/consumers/upgrading-cli.md).
It must be available before a run whose projected work needs trim or analysis,
and for validation of enabled definitions. Narratio checks requirements before
stage attempts, even when generated transcripts do not yet exist. The check
makes no model call and cannot certify later file contents or generation.
A missing required prompt binding or variable, or a failed inspection, stops
the invocation. Correct the configuration or downstream installation and retry.
An optional source for a required prompt input and incomplete or conditional
discovery are warnings; later input resolution remains authoritative. Early
preflight failure leaves completed stage records and artifact outputs intact,
including during a forced run. `session plan` reports projected work without
invoking Scriptorium. See the [integration contract](integrations/scriptorium.md)
for stream handling and [configuration](config.md#scriptorium-artifact-entries)
for binding names and sources.
## Stage Execution and Continuation Behavior
Canonical stage order:
@@ -545,10 +564,11 @@ reaped, and descendants that keep standard output or error open cannot keep
the invocation blocked. Other operating systems fail closed rather than launch
a command without tree ownership.
Subprocess stdout and stderr diagnostics are separately redacted and capped at
8 MiB per invocation. Narratio does not retain configured credential values in
these logs or their error tails; reaching a capture limit terminates the command
tree and reports which stream exceeded the limit.
Subprocess diagnostic streams are separately redacted and capped at 8 MiB per
invocation. Narratio does not retain configured credential values in these logs
or their error tails; reaching a capture limit terminates the command tree and
reports which stream exceeded the limit. Scriptorium result stdout is captured
separately without redaction; see its [integration contract](integrations/scriptorium.md).
Run-local diagnostics are:

View File

@@ -84,7 +84,7 @@ Check: `go test ./internal/adapters/subprocess`.
## Stage 2: Migrate Scriptorium generation
**Status: Complete.** Trim/analyze diagnostic bookkeeping remains for Stage 3.
**Status: Complete.**
**Purpose:** Make native `run` deliver the artifact through Narratio's result
capture while retaining existing success and failure rules.
@@ -497,6 +497,9 @@ weakening the accepted inspection policy or restoring removed CLI compatibility.
## Stage 12: Update canonical documentation and finish verification
**Status: Complete.** The full test and race suites, vet, build, and supported
target cross-builds passed with Go 1.27.4.
**Purpose:** Hand off a documented, verified native integration.
Read documentation policy and the current canonical documents below. Update them

View File

@@ -1,5 +1,8 @@
# Adopt Scriptorium v0.16 and prompt requirements discovery
**Status: Implemented.** The [integration contract](../integrations/scriptorium.md)
describes current behavior; the baseline below records the prior implementation.
## Purpose
Adopt Scriptorium's native CLI for trim-bounds generation and analysis. Use its
@@ -31,7 +34,7 @@ discovery completeness, and structured issues. Further upstream changes are
unnecessary for this capability. Richer capture diagnostics for malformed
templates remain separate upstream work.
## Current Narratio Behavior
## Reviewed Narratio Behavior
The [Scriptorium integration](../integrations/scriptorium.md) owns the current
contract. Its adapter serves both `trim` and `analyze`, including optional

View File

@@ -744,6 +744,22 @@ manifest-owned.
Relevant references: [Operations: Stage Execution and Continuation Behavior](./operations.md#stage-execution-and-continuation-behavior)
and [Manifest Internals](./internal/manifest.md#transcribe-owned-speaker-state).
## Prompt requirements fail before pipeline work starts
If a run or `session validate` reports a missing prompt input, compare the exact
input name in the finding with the configured binding key, not just the source
ID. Supply a missing required variable, or correct the selected prompt and
profile. An optional source warning means the source may be omitted later; make
it required only if that is the intended configuration. Incomplete discovery
and conditional requirements warn without failing by themselves.
If inspection cannot start or decode a report, check the selected executable,
its native configuration and prompt resources, and the diagnostic context.
The [Scriptorium migration guide](https://forge.maximumdirect.net/eric/scriptorium/src/tag/v0.16.0/docs/consumers/upgrading-cli.md)
explains the v0.16.0 interface and configuration changes. Retry after correcting
the issue; a preflight failure preserves completed output authority. See
[prompt preflight](operations.md#prompt-requirements-preflight).
## Scriptorium returns HTTP 401 during trim or analyze
Check that Narratio's pipeline selects the credential names required by

View File

@@ -220,7 +220,7 @@ notarius:
scriptorium:
binary: scriptorium
# Select provider names provisioned through Narratio's environment/secrets.
# Used for trim, analysis, and render-debug calls; no provider override.
# Used for requirements inspection, trim, analysis, and render-debug calls.
# credentials: [OPENROUTER_API_KEY, RAKESTRAWHOME_API_KEY]
config_path: /usr/local/etc/scriptorium/config.yml
timeout: 10m