# Pi Coding Agent - Terminal-based coding harness
FROM ubuntu:24.04

ENV DEBIAN_FRONTEND=noninteractive

# Install base dependencies
RUN apt-get update && apt-get install -y \
    curl \
    wget \
    git \
    neovim \
    ranger \
    tmux \
    htop \
    tree \
    jq \
    ca-certificates \
    python3 \
    python3-pip \
    build-essential \
    && rm -rf /var/lib/apt/lists/*

# Install Node.js (required for Pi)
RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \
    && apt-get install -y nodejs \
    && rm -rf /var/lib/apt/lists/*

# Install Pi Coding Agent globally
RUN npm install -g --ignore-scripts @earendil-works/pi-coding-agent

# Use the shared built-in UID/GID for writable Config Profile mounts.
RUN groupadd -g 1000 user \
    && useradd -m -u 1000 -g 1000 -s /bin/bash user
WORKDIR /home/user

# Set up git
RUN git config --global init.defaultBranch main \
    && git config --global user.email "dev@headquarter.local" \
    && git config --global user.name "Developer"

# Create user-owned default configuration files.
RUN printf '%s\n' 'set -g mouse on' 'set -g default-terminal "screen-256color"' > /home/user/.tmux.conf \
    && mkdir -p /home/user/.config/ranger /home/user/.pi/agent \
    && printf '%s\n' 'set preview_files true' 'set use_preview_script true' > /home/user/.config/ranger/rc.conf \
    && chown -R user:user /home/user

USER user

# Default to bash (Pi is invoked manually via `pi` command)
CMD ["/bin/bash"]