# sublimated data analyst agent container
FROM node:22-slim

WORKDIR /app

# Install system packages: python3, postgresql client, curl, jq, sqlite3, csvkit
RUN apt-get update && apt-get install -y --no-install-recommends \
    python3 python3-pip python3-venv \
    postgresql-client \
    curl jq ca-certificates git \
    sqlite3 \
    csvkit \
    && rm -rf /var/lib/apt/lists/*

# Create python venv with data analysis packages
RUN python3 -m venv /opt/pyenv && \
    /opt/pyenv/bin/pip install --no-cache-dir \
    pandas numpy matplotlib seaborn scipy

# Add python venv to PATH
ENV PATH="/opt/pyenv/bin:$PATH"

# Install duckdb CLI
RUN curl -fsSL https://github.com/duckdb/duckdb/releases/download/v1.2.1/duckdb_cli-linux-amd64.zip -o /tmp/duckdb.zip && \
    apt-get update && apt-get install -y --no-install-recommends unzip && \
    unzip /tmp/duckdb.zip -d /usr/local/bin/ && \
    chmod +x /usr/local/bin/duckdb && \
    rm /tmp/duckdb.zip && \
    apt-get purge -y unzip && apt-get autoremove -y && \
    rm -rf /var/lib/apt/lists/*

# Install Claude Code (required by Agent SDK)
RUN npm install -g @anthropic-ai/claude-code

# Install Observable Plot for SVG chart generation
RUN npm install -g @observablehq/plot jsdom

# Copy server code and install dependencies
COPY server/ /app/
RUN npm install

# Copy CLI tools and make executable
COPY tools/ /app/tools/
RUN chmod +x /app/tools/*
ENV PATH="/app/tools:$PATH"

# Create runtime directories and init git repo (claude-code requires git)
RUN mkdir -p /workspace /artifacts && \
    cd /workspace && git init

# Set HOME explicitly for claude-code config
ENV HOME=/root

EXPOSE 8080

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