#!/bin/sh # Agent dispatcher inside the container. # # Headless (default): loads the contract-generated system prompt, then # dispatches one request to /opt/mosaic/adapters//adapter.sh # (contract: /opt/mosaic/adapters/README.md). # # Interactive (MOSAIC_INTERACTIVE=1, from scripts/agent.sh): same prompt, # but the adapter opens the full pi TUI with no initial prompt - the human # drives from there. set -eu REQUEST="" if [ "${MOSAIC_INTERACTIVE:-}" != "1" ]; then # Headless: args are the request; default is the startup verification # request used by hello/verify. REQUEST="${*:-Return your startup marker and nothing else.}" export MOSAIC_REQUEST="$REQUEST" fi ADAPTER="${MOSAIC_ADAPTER:-pi}" case "$ADAPTER" in # Allowlist mirrors scripts/mosaic-config.mjs; pattern check first so a # crafted name cannot escape the adapters directory. *[!A-Za-z0-9._-]*|'') echo "run-agent: invalid adapter name: '$ADAPTER'" >&2 exit 2 ;; esac ADAPTER_SCRIPT="/opt/mosaic/adapters/$ADAPTER/adapter.sh" if [ ! -x "$ADAPTER_SCRIPT" ]; then echo "run-agent: unknown or non-executable adapter: $ADAPTER" >&2 exit 2 fi /opt/mosaic/src/load-contracts.sh /opt/mosaic/contracts /var/lib/mosaic/system-prompt.md export MOSAIC_SYSTEM_PROMPT_FILE="/var/lib/mosaic/system-prompt.md" exec "$ADAPTER_SCRIPT"