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

2.5 KiB

Scriptorium Adapter Internals

internal/adapters/scriptorium translates Weather Reporter render requests to Scriptorium process arguments and translates process results back to local types. The external CLI and output contract belongs to the Scriptorium integration guide; prompts, template inputs, and report ownership remain outside this adapter.

Request-to-command translation

Runner accepts a binary, config path, profile, timeout, extra arguments, and an injectable command executor. Its defaults are the scriptorium binary and the real ExecRunner. Optional configuration flags are placed before the operation-specific arguments, and extra arguments are appended last.

Local operation Required values Translated arguments
Render prompt ID, data-package path render [--config …] [--profile …] --prompt <id> --input data_package=<path> --format json [extra …]
Run prompt ID, data-package path, output path run [--config …] [--profile …] --prompt <id> --input data_package=<path> --out <path> [extra …]
StructuredRun prompt ID, data-package path, output path Same translation as Run

Blank required values fail before a command starts. The adapter does not add schema flags or interpret a prompt's payload; it only gives Scriptorium the named data_package input.

Command execution and result translation

ExecRunner uses exec.CommandContext, never a shell. A positive configured timeout creates a child context. Standard output and standard error are captured independently, each with a 1 MiB limit, and the executed command is retained for diagnostics.

RenderResult, RunResult, and StructuredRunResult expose the command, captured output, truncation markers, and exit code. Run results also retain the requested output path. Exit status zero is successful. A nonzero process exit returns its result and an error, while a start failure, cancellation, or deadline failure returns no result and the execution error.

The adapter does not parse rendered JSON, validate a generated report, write state, or upload a report. Those responsibilities sit with application orchestration, state internals, and the relevant delivery adapter.

Verification

Focused tests cover argument order, validation, bounded capture, timeout and cancellation handling, and exit-status translation:

go test ./internal/adapters/scriptorium