FROM node:22-alpine AS base
WORKDIR /app

FROM base AS deps
COPY package.json package-lock.json* ./
RUN npm install

FROM base AS build
COPY --from=deps /app/node_modules ./node_modules
COPY tsconfig.json ./
COPY src ./src
RUN npx tsc -p tsconfig.json

FROM base AS runtime
ARG RIVET_RUNNER_VERSION=dev
ENV NODE_ENV=production
ENV RIVET_RUNNER_VERSION=$RIVET_RUNNER_VERSION
COPY --from=deps /app/node_modules ./node_modules
COPY --from=build /app/dist ./dist
COPY package.json ./
COPY drizzle/ ./drizzle/

# ── Build-time prompt loading (changes.md §3) ──
# Prompts and agent definitions are copied into the image so they are
# embedded at build time. To update: edit files → rebuild image → rollout.
COPY prompts/ ./prompts/
COPY agents/  ./agents/

EXPOSE 4000
CMD ["node", "dist/index.js"]
