FROM node:20-slim

# Install SSH client for remote execution
RUN apt-get update && apt-get install -y openssh-client && rm -rf /var/lib/apt/lists/*

# Create app directory
WORKDIR /app

# Create node user home structure for claude and ssh
RUN mkdir -p /home/node/.local/bin && \
    mkdir -p /home/node/.local/share/claude && \
    mkdir -p /home/node/.claude && \
    mkdir -p /home/node/.config/claude && \
    mkdir -p /home/node/.ssh && \
    chown -R node:node /home/node

# Create symlink for claude binary
RUN ln -s /home/node/.local/share/claude/versions/2.0.67 /home/node/.local/bin/claude

# Copy package files
COPY package*.json ./

# Install dependencies
RUN npm install --production

# Copy app source
COPY . .

# Set ownership
RUN chown -R node:node /app

# Switch to node user
USER node

# Set PATH to include claude
ENV PATH="/home/node/.local/bin:${PATH}"

EXPOSE 3001

CMD ["node", "server.js"]
