# Base image for Bento-managed agents.
#
# Build once from the bento repo root:
#
#     docker build -t bento-agent-runtime:latest .
#
# Bento spawns one of these per agent (B3a — long-running container per
# agent). The agent's repo is mounted at /app at runtime; `bento serve
# agent.py` is the entrypoint and registers the agent with the hub via
# HTTP, opens an SSE tunnel, and processes triggers.
#
# Bento source is baked into the image. Rebuild when sdk/* changes.
# User code mounted as a volume — no rebuild needed for agent.py edits.

FROM python:3.13-slim

ENV PYTHONDONTWRITEBYTECODE=1 \
    PYTHONUNBUFFERED=1 \
    PIP_NO_CACHE_DIR=1

# git for GitPython (used by bento.hub.repos, harmless inside the agent
# container but pulled in by the install).
RUN apt-get update \
    && apt-get install -y --no-install-recommends git \
    && rm -rf /var/lib/apt/lists/*

# Install bento + all its runtime deps from local source.
WORKDIR /opt/bento
COPY pyproject.toml README.md ./
COPY src/ ./src/
RUN pip install .

# Run as a non-root user. The Claude Code CLI (which claude-agent-sdk
# shells out to) refuses --dangerously-skip-permissions when uid=0,
# which the builder needs for non-interactive Read/Write/Edit. Match
# the typical host user uid on macOS (501) and Linux (1000) — bind
# mounts on OrbStack/Docker Desktop map correctly either way.
RUN useradd -m -u 1000 bento

USER bento
WORKDIR /app
ENV HOME=/home/bento \
    BENTO_HUB=http://host.docker.internal:8000

ENTRYPOINT ["bento", "serve", "agent.py"]
