Files
stack/src/run-agent.sh
T

44 lines
1.4 KiB
Bash
Executable File

#!/bin/sh
# Agent dispatcher inside the container.
#
# Headless (default): loads the contract-generated system prompt, then
# dispatches one request to /opt/mosaic/adapters/<MOSAIC_ADAPTER>/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
node /opt/mosaic/processing-control/entrypoint.mjs /var/lib/mosaic
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
: "${MOSAIC_SYSTEM_PROMPT_FILE:?run-agent: MOSAIC_SYSTEM_PROMPT_FILE is required}"
/opt/mosaic/src/load-contracts.sh /opt/mosaic/contracts "$MOSAIC_SYSTEM_PROMPT_FILE"
export MOSAIC_SYSTEM_PROMPT_FILE
exec "$ADAPTER_SCRIPT"