#!/usr/bin/env bash
# entrypoint.sh — Start soul-demo then neuron-web in the same container.
#
# soul-demo runs in the background on :7772 (localhost only, not exposed).
# neuron-web runs in the foreground on :8080 (Cloud Run health checks this).
# If neuron-web exits, the container exits. Soul crashing is non-fatal —
# chat will return "demo soul not responding" but the page stays up.

set -euo pipefail

echo "[entrypoint] starting soul-demo on :7772"
/usr/local/bin/soul-demo &
SOUL_PID=$!

# Give the soul a few seconds to load its engram and seed safety nodes
sleep 4

echo "[entrypoint] soul-demo started (pid=$SOUL_PID)"
echo "[entrypoint] starting neuron-web on :${PORT:-8080}"

exec /usr/local/bin/neuron-web
