FROM python:3.12-slim

ARG CODEX_NPM_PACKAGE=@openai/codex

ENV PYTHONDONTWRITEBYTECODE=1 \
    PYTHONUNBUFFERED=1 \
    CODEX_HOME=/root/.codex \
    BOT_STATE_PATH=/app/data/state.json \
    BOT_WORKSPACE_ROOT=/workspaces \
    CODEX_APP_SERVER_URL=ws://127.0.0.1:4500

RUN apt-get update \
    && apt-get install -y --no-install-recommends \
        ca-certificates \
        curl \
        git \
        nodejs \
        npm \
        openssh-client \
    && npm install -g "${CODEX_NPM_PACKAGE}" \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*

WORKDIR /app

COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt

COPY app ./app
COPY scripts ./scripts
COPY README.md ./

RUN mkdir -p /app/data /workspaces /root/.codex \
    && chmod +x /app/scripts/*.sh

CMD ["/app/scripts/start.sh"]
