Files
weatherreporter/docs/internal/scriptorium-adapter.md

111 lines
3.6 KiB
Markdown
Raw Normal View History

2026-05-29 17:32:57 +00:00
# Scriptorium Adapter Internals
2026-05-29 19:54:22 +00:00
This document describes the subprocess adapter in
`internal/adapters/scriptorium`.
2026-05-29 17:32:57 +00:00
## Purpose
2026-05-29 19:54:22 +00:00
The adapter runs `scriptorium render` for prompt preflight and `scriptorium run`
2026-06-14 04:55:07 +00:00
for Markdown report generation or structured generated-text output. It isolates
subprocess execution, argv construction, timeout handling, output capture, and
exit-code interpretation from app and domain packages.
2026-05-29 17:32:57 +00:00
2026-05-29 19:54:22 +00:00
## Inputs And Outputs
2026-05-29 17:32:57 +00:00
2026-05-29 19:54:22 +00:00
Inputs:
2026-05-29 17:32:57 +00:00
- prompt ID
2026-06-09 21:37:28 +00:00
- YAML prompt input data package path
- report output path for `run`
2026-06-14 04:55:07 +00:00
- raw generated-text output path for structured `run`
2026-05-29 17:32:57 +00:00
- configured binary, config path, profile, timeout, and extra arguments
2026-05-29 20:49:19 +00:00
- context for cancellation
2026-05-29 17:32:57 +00:00
2026-05-29 19:54:22 +00:00
Outputs:
2026-05-29 17:32:57 +00:00
2026-05-29 19:54:22 +00:00
- argv used for execution
2026-05-29 20:49:19 +00:00
- captured stdout and stderr
- truncation flags for captured output
2026-05-29 17:32:57 +00:00
- exit code
2026-05-29 19:54:22 +00:00
- report output path for `run`
2026-06-14 04:55:07 +00:00
- raw generated-text output path for structured `run`
2026-05-29 17:32:57 +00:00
## Boundaries
2026-05-29 20:49:19 +00:00
`internal/adapters/scriptorium` owns Scriptorium command construction and
subprocess execution. It does not choose report types, build prompt input,
collect weather data, decide workflow order, or persist workflow metadata.
2026-05-29 20:49:19 +00:00
2026-06-14 04:55:07 +00:00
The adapter exposes request and result structs for render, Markdown run, and
structured generated-text run operations. State persistence uses state-owned
artifact shapes; app orchestration converts adapter results before saving.
2026-05-29 19:54:22 +00:00
## Config Fields Used
- `scriptorium.binary`
- `scriptorium.config_path`
- `scriptorium.profile`
- `scriptorium.timeout`
- `scriptorium.extra_args`
2026-05-29 20:49:19 +00:00
## Commands
Render preflight argv starts with:
```text
scriptorium render --prompt <prompt_id> --input data_package=<path> --format json
```
2026-05-29 17:32:57 +00:00
2026-05-29 20:49:19 +00:00
Report generation argv starts with:
2026-05-29 17:32:57 +00:00
2026-05-29 20:49:19 +00:00
```text
scriptorium run --prompt <prompt_id> --input data_package=<path> --out <path>
```
2026-05-29 17:32:57 +00:00
2026-06-14 04:55:07 +00:00
Structured generated-text argv uses the same `scriptorium run` form, with the
`--out` value set to the raw generated-text JSON artifact path. The adapter
does not add `--format`, schema path, or JSON Schema flags for structured
generation; Scriptorium selects the structured output schema from prompt
configuration.
2026-05-29 20:49:19 +00:00
Configured `--config` and `--profile` flags are inserted after the subcommand
and before prompt-specific arguments. Extra arguments are appended after the
built-in arguments.
2026-05-29 17:32:57 +00:00
2026-05-29 20:49:19 +00:00
## Execution Behavior
2026-05-29 20:49:19 +00:00
The adapter runs commands without shell interpolation. The same private
2026-06-14 04:55:07 +00:00
execution path is used by render, Markdown run, and structured run after
command-specific request validation and argv construction.
2026-05-29 20:49:19 +00:00
When `scriptorium.timeout` is greater than zero, each subprocess call uses a
context with that timeout. Stdout and stderr are captured separately, capped at
1 MiB each, and marked as truncated when the cap is reached.
2026-05-29 17:32:57 +00:00
## Failure Behavior
2026-05-29 20:49:19 +00:00
- Missing prompt ID or data package path returns an error before subprocess
execution.
- Missing run output path returns an error before subprocess execution.
- Subprocess start errors, context cancellation, and timeouts are wrapped with
operation context by the caller-facing method.
2026-06-14 04:55:07 +00:00
- Nonzero render, Markdown run, and structured run exits return the captured
result plus an error containing the exit code and stderr.
2026-05-29 17:32:57 +00:00
## Tests
Inspect:
- `internal/adapters/scriptorium/runner_test.go`
- `internal/app/app_test.go`
- `internal/cli/root_test.go`
## Invariants
2026-05-29 19:54:22 +00:00
- No shell interpolation is used.
- The Scriptorium input name is `data_package`.
2026-06-09 21:37:28 +00:00
- The file at the data package path is YAML produced by `internal/promptinput`.
2026-06-14 04:55:07 +00:00
- Render, Markdown run, and structured run preserve command-specific result
structs.
2026-05-29 19:54:22 +00:00
- Scriptorium-specific flags stay inside adapter and config boundaries.