# Adopt Scriptorium v0.16 and prompt requirements discovery ## Purpose Adopt Scriptorium's native CLI for trim-bounds generation and analysis. Use its prompt requirements discovery to identify missing Narratio input bindings before expensive upstream work, including when the eventual input files do not exist. This roadmap defines the target and required changes. A subsequent implementation plan will define implementation stages. The Audita and session workspace roadmaps remain separate scopes. ## Reviewed Baseline Narratio was reviewed at commit `9fa1797`. The reviewed Scriptorium v0.16.0 release identifies commit `0fa538c336fd64be51bc355fd53d3ca19f104d68`. The following upstream documents own Scriptorium's behavior: - [Release notes][release]. - [CLI reference][cli] and [CLI migration guide][migration]. - [Subprocess integration contract][subprocess]. - [Configuration][configuration] and [PromptKit migration guidance][prompts]. - [Native requirements contract][requirements]. Scriptorium implements the previously requested early requirements inspection. It exposes native PromptKit findings through CommandKit, including exact input names, requirement classifications, variable presence, selected identities, 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 The [Scriptorium integration](../integrations/scriptorium.md) owns the current contract. Its adapter serves both `trim` and `analyze`, including optional render-debug calls. - Generation uses the former `run --prompt`, file-valued `--input`, `--timeout`, and `--out` interface. Preview uses the former `render` command. - The adapter classifies exit status 2 as generated-content validation failure. - Scriptorium writes an output file that Narratio validates before promotion. The existing artifact limit is 64 MiB. - Shared subprocess execution captures stdout and stderr as bounded, redacted diagnostics. It has no separate stdout product destination. - Configuration validation checks Narratio's artifact sources and dependencies. It does not ask Scriptorium which prompt input names or variables are required. - Analysis planning expands character families and computes prerequisite closure. `session plan` currently invokes no stage-execution adapters. - Scriptorium credentials use the same explicit forwarding and diagnostic redaction boundary as Audita and Notarius. The current adapter is incompatible with the new CLI. Scriptorium is a separately installed executable; this adoption is an integration and deployment migration, rather than a new Go module dependency. ## Targeted End State ### Native generation and preview Use Scriptorium v0.16's native commands for both trim and analyze: | Existing invocation behavior | Target behavior | | --- | --- | | `run --prompt ID` | `run ID` | | File bindings through `--input NAME=PATH` | Repeated `--input-file NAME=PATH` | | `render --prompt ID` | `promptkit show prepared ID`, using its native structured output | | `--out PATH` | Narratio captures stdout to its run-local destination | | Former duration-valued `--timeout` | Narratio's existing supervisor deadline remains authoritative; generation may also pass `--run-timeout` for the engine budget | | Content-validation failure at status 2 | Content-validation failure at status 4; status 2 retains native usage/configuration meaning | Preserve the distinction between the whole-invocation deadline and native per-attempt provider timeouts. Existing duration settings retain their Narratio meaning. This migration adds no per-attempt timeout setting. Capture generation in automatic/text format so the output file contains artifact bytes, rather than the full native result envelope. Capture prepared preview in the native JSON format. Keep diagnostics separate from these result streams. Invocation records describe the actual native commands and retain credential names only. Keep current stage output validation, successful promotion, failure handling, resume, force, and dependency behavior. A partially delivered stdout file or a file produced with a nonzero outcome does not establish stage completion. Preserve existing treatment of older completed outputs after failed replacement. ### Early prompt requirements inspection Add an adapter operation for: ```sh scriptorium promptkit requirements show PROMPT_ID --format json ``` Supply the same effective configuration, prompt, profile, applicable variables, and session context as the eventual generation request. Preserve qualified IDs and upstream selection semantics. Discovery and execution share request-context construction so character-specific variables and Narratio's session routing value agree. Existing downstream selectors remain authoritative; this work does not introduce another configuration-resolution layer. Inspect named requirements before generated files exist. Discovery reads configuration and prompt resources and makes no model call. ConfigKit's native bootstrap and configuration acquisition still apply. Discovery does not require future artifact payloads or prove execution credentials are ready. Narratio compares required prompt input names with the keys in its effective binding map. For example, a source named `narratio.transcript.final_trimmed_markdown` can satisfy the prompt input `transcript` when explicitly bound under that name. Source identity and binding name remain distinct. Use native variable-presence findings, including explicit empty values. Associate findings with the affected trim prompt or concrete analysis artifact. Retain existing Narratio source validation and dependency planning as their respective authorities. Inspection covers relevant trim generation and effective selected analysis targets, including character-family expansion and required prerequisite work. Unselected integrations and work that will be reused retain their existing execution behavior. Exact automatic invocation points and incomplete-discovery policy are the decisions at the end of this roadmap. ### Native findings and their limits Consume the native report directly. Use structured fields for decisions and upstream explanations for display. Preserve exact names, classifications, nullable metadata, empty inventories, and false values. A complete report describes discovery coverage. Narratio separately determines whether bindings satisfy the discovered requirements. Partial discovery can return status zero and still contain useful findings. An empty partial inventory does not establish that the prompt needs no inputs. Native nonzero outcomes and stderr supply invocation-failure information. Attach Narratio context without parsing diagnostic prose for stable categories. The native report has no Scriptorium-specific schema-version envelope or per-input schema contract; this migration adds neither. Concrete `promptkit requirements validate` remains a separate upstream operation for when files exist. Automatic concrete validation and provider smoke tests are outside this scope. Discovery is an early configuration aid, not a guarantee of later preparation or generation success. ## Required Changes ### Subprocess and adapter boundary Extend the existing subprocess boundary proportionately to support stdout result capture alongside its current diagnostic-only use. Product and machine-readable report capture must preserve result bytes. Diagnostic redaction and its 8 MiB capture policy must not truncate or transform artifact payloads. Retain the existing artifact-size guard, cancellation, owned-process cleanup, credential forwarding, and contextual errors. Keep other adapters' existing diagnostic capture behavior unchanged. Use the same supervised execution machinery for generation, preview, and requirements inspection. Reuse result capture for native reports without introducing a separate limit setting. Update Scriptorium argument construction, exit classification, preview handling, invocation metadata, adapter doubles, and trim/analyze wiring. Required discovery data and transport behavior belong behind the adapter; Narratio's binding and selection decisions belong in the application layer. ### Preflight integration Use existing effective artifact definitions and planners to derive inspection targets and bindings. Avoid a second artifact graph, prompt parser, configuration loader, or persistent discovery cache. A per-invocation inspection result is sufficient; inspect different variable contexts independently where needed. Add contextual operator findings for definite missing bindings and discovery limitations. Keep invocation failures distinct from successful partial reports. Apply the selected entry-point policy without altering unrelated stage selection, manifest transitions, or ordinary configuration inspection. ### Deployment and documentation Coordinate adapter adoption with the installed Scriptorium executable and its native configuration/prompt definitions. Review removed directory settings, native imports, profile identities, source-relative resources, and validation repair budgets through the upstream migration guides. Preserve explicit configuration-path forwarding and existing exact-name credential forwarding. Target the native interface directly. Version probing, legacy command fallbacks, and automatic downstream configuration conversion are outside this scope. Narratio does not acquire ownership of Scriptorium's backend or prompt settings. When implementation lands, update the integration contract and focused adapter, trim, and analyze internal documentation. Update CLI, configuration, operations, and troubleshooting documentation where preflight affects operator behavior. Link upstream for native command and configuration details; document Narratio's binding decisions, execution boundary, and failure context locally. Keep preview placement consistent with the existing debug workflow until the [workspace roadmap](workspace.md) changes it. Its latest-attempt views and layout rules remain owned by that work. The [Audita adoption](audita.md) is independently implementable. ## Verification and Completion Use focused offline tests at the subprocess, adapter, and orchestration boundaries. Cover the consequential migration risks: - File bindings use native file flags; positional prompt selection and preview commands match the selected upstream release. - Artifact stdout is byte-preserving and separate from redacted diagnostics, including payloads larger than the diagnostic capture limit. - Native exit classifications, cancellation, capture failures, partial delivery, and output validation retain correct stage-completion behavior. - Discovery works without generated files and identifies mismatched names, required variables, conditional inputs, and incomplete findings. - Discovery and execution agree on effective request context, including expanded families, selected prerequisites, and session variables. - Selected inspection entry points preserve their documented state effects and avoid generation or paid provider operations. Default tests use subprocess doubles and temporary filesystems. They remain independent of sibling checkouts, installed downstream tools, real credentials, and paid providers. A controlled compatibility check against the selected Scriptorium release can supplement those tests. Completion means trim generation, analysis generation, and optional preview use the native CLI; requirements inspection implements the selected policies; and local integration and operator documentation describe the landed behavior. ## Open Decisions ### Automatic inspection entry points **Recommendation:** Inspect applicable pending Scriptorium work before expensive stage execution, and include requirements findings in `session validate`. Keep ordinary `session plan` independent of subprocess inspection for this scope. This catches definite binding mistakes early while preserving the current planning boundary. A failed required inspection stops the affected execution or validation with context; unrelated stage-only invocations remain unaffected. Scriptorium must consequently be available earlier for an invocation that will need it. Validation inspects enabled trim and analysis definitions; execution uses its selected pending work and prerequisite closure. **Alternative:** Restrict discovery to explicit `session validate`. This preserves execution's current dependency timing and makes checks opt-in, but operators can still discover binding errors only after expensive upstream work if they omit validation. **Alternative:** Also inspect through `session plan` and expose findings with its binding view. This improves planning feedback but introduces downstream process and configuration availability requirements into a currently subprocess-free planning operation. The planning contract and its tests would need an explicit, limited revision for read-only discovery. ### Incomplete or conditional discovery **Recommendation:** Fail for definite missing required bindings or required variables. Display incomplete-discovery issues and unresolved conditional requirements as warnings while allowing execution to proceed when no definite missing requirement is established. This uses native findings without making static analyzability a new validity requirement for prompts. Later preparation and generation remain authoritative for actual requests. **Alternative:** Treat every incomplete report or unresolved conditional requirement as a preflight failure. This offers stricter early checking but can reject valid dynamic templates and restrict supported upstream behavior. Such a restriction requires an explicit operator-policy choice. [release]: https://forge.maximumdirect.net/eric/scriptorium/src/tag/v0.16.0/docs/releases/v0.16.0.md [cli]: https://forge.maximumdirect.net/eric/scriptorium/src/tag/v0.16.0/docs/cli.md [migration]: https://forge.maximumdirect.net/eric/scriptorium/src/tag/v0.16.0/docs/consumers/upgrading-cli.md [subprocess]: https://forge.maximumdirect.net/eric/scriptorium/src/tag/v0.16.0/docs/integrations/subprocess.md [configuration]: https://forge.maximumdirect.net/eric/scriptorium/src/tag/v0.16.0/docs/config.md [prompts]: https://forge.maximumdirect.net/eric/scriptorium/src/tag/v0.16.0/docs/consumers/upgrading-promptkit.md [requirements]: https://forge.maximumdirect.net/base-layer/commandkit/src/commit/0b53a63648c536afe50c46f948159116f776adae/docs/cli.md#promptkit-requirements