FROM node:22-slim AS builder

WORKDIR /app
COPY package.json package-lock.json* ./
RUN npm ci
COPY tsconfig.json ./
COPY src/ ./src/
RUN npm run build

FROM node:22-slim

RUN groupadd -g 1001 axon && useradd -u 1001 -g axon -m axon
WORKDIR /app
COPY package.json package-lock.json* ./
RUN npm ci --omit=dev && npm cache clean --force
COPY --from=builder /app/dist ./dist

# Claude SDK needs .claude/ directory tree (auth + debug logs)
RUN mkdir -p /home/axon/.claude/debug && chown -R axon:axon /home/axon/.claude

USER axon
EXPOSE 3000
CMD ["node", "dist/index.js"]
