FROM node:22-slim

# Install claude CLI
RUN npm install -g @anthropic-ai/claude-code 2>/dev/null || true

# Install curl for healthcheck
RUN apt-get update && apt-get install -y curl && rm -rf /var/lib/apt/lists/*

WORKDIR /app

# Install dependencies
COPY package.json ./
COPY client/package.json ./client/
RUN npm install && cd client && npm install

# Copy source and build
COPY . .
RUN cd client && npx vite build

# Create data and uploads dirs owned by node user
RUN mkdir -p data uploads && chown -R node:node /app

# Run as non-root (required for Claude CLI bypassPermissions)
USER node

EXPOSE 3400
ENV NODE_ENV=production
CMD ["node", "--import", "tsx/esm", "server/index.ts"]
