Runbook Scripts
Shell script steps use an optional initial comment/blank header, after the shebang
Runbook script declarations
Shell script steps use an optional initial comment/blank header, after the shebang and before the first shell statement:
#!/usr/bin/env bash
# aiwg-requires: common.sh
# aiwg-requires: service-helpers.sh
# aiwg-run-as: root
set -euo pipefail
restart_service
`aiwg-requires` is repeatable. Each value must match `^[A-Za-z0-9_.-]+\.sh$`. Resolve the script itself with realpath, then resolve each library relative to that script's directory. Every library must exist, be a regular file, and resolve inside that directory. Absolute paths, traversal, missing files, directories, and symlinks escaping the directory are refused before any execution. Symlinks whose targets remain inside the directory are permitted. Libraries are prepended in declaration order, with a newline after each, followed by the original script. Repeated declarations remain repeated; dependencies are not expanded recursively.
`aiwg-run-as` accepts only `root`, selecting `sudo -n bash -s` on the target. Without it, use `bash -s` as the configured execution user. Empty, unknown, or conflicting values are refused. Failure of non-interactive sudo fails the step; there is no password prompt or fallback. Script bodies are opaque to header parsing; marker-looking text after the first shell statement is not metadata.
The existing `ops-runbook-executor` must call the deterministic helper:
node "$AIWG_ROOT/agentic/code/frameworks/ops-complete/tools/runbook-script.mjs" "$SCRIPT" "$CONFIGURED_USER"
Plugin installations ship the same helper at `tools/runbook-script.mjs` within the plugin. It reads local UTF-8 scripts and returns JSON `{plan, payload}`; it never runs a script, SSH, or sudo. A refusal exits nonzero without a payload. The existing Markdown runbook format remains unchanged; OpsPlaybook schemas describe capability bindings rather than these shell comment declarations.
Before running, present `plan.script`, ordered `plan.libraries` (names, resolved paths and SHA-256 digests), `plan.runAs`, `plan.command` argv and `plan.payloadDigest`. Review the full payload under existing safety gates. Stream the exact returned payload snapshot to the planned command on the selected host, using the configured user for the connection. Never evaluate JSON as shell code, interpolate payload text into a command, or rebuild it from mutable paths after planning. Any input change requires validation and a new plan.
Include the plan fields and execution outcome in each step's evidence, through the existing ops evidence boundary. Store only bounded redacted output and digests, not the raw payload. Apply the same preparation to verification and rollback scripts. Inline steps with dependencies require a declared source directory and a materialized local script before validation.
This convention credits the BT6 workspace, whose host runner introduced `bt6-requires` and `bt6-run-as: root` in bt6-ops #43. AIWG uses the neutral `aiwg-` prefix and adds realpath containment validation (AIWG #4636).