FROM fedora:44 AS build

RUN dnf update -y \
    && dnf upgrade -y \
    && dnf install curl git -y

# Prepare neovim config files
ARG REPO_URL="https://github.com/Nicoretti/config-files.git"
ARG BRANCH="master"
ARG SUBTREE_PATH=".config/nvim"

WORKDIR /download
RUN git clone --depth 1 --branch ${BRANCH} --no-checkout --filter=blob:none ${REPO_URL} repo

WORKDIR /download/repo
RUN git sparse-checkout set "${SUBTREE_PATH}"
RUN git checkout ${BRANCH}
RUN rm -rf .git

# Prepare AI-Chat binary
WORKDIR /workdir
ADD https://github.com/sigoden/aichat/releases/download/v0.30.0/aichat-v0.30.0-i686-unknown-linux-musl.tar.gz aichat.tar.gz
RUN tar xvf aichat.tar.gz

# --- MAIN IMAGE ----------------------------------------------------------------------------------
FROM fedora:44

RUN dnf update -y \
    && dnf upgrade -y \
    && dnf install curl nodejs git -y

# Install Editor (neovim)
RUN dnf install neovim -y
COPY --from=build /download/repo/.config/nvim /root/.config/nvim
RUN nvim --headless "+Lazy! sync" +qa
ENV EDITOR="nvim"

# Install claude code
RUN tee /etc/yum.repos.d/claude-code.repo <<'EOF'
[claude-code]
name=Claude Code
baseurl=https://downloads.claude.ai/claude-code/rpm/stable
enabled=1
gpgcheck=1
gpgkey=https://downloads.claude.ai/keys/claude-code.asc
EOF
RUN dnf install -y claude-code

# Install Aichat
COPY --from=build /workdir/aichat /usr/local/bin/aichat

WORKDIR /workdir
# Install UV
RUN curl -LsSf https://astral.sh/uv/install.sh | env UV_INSTALL_DIR="/usr/local/bin" sh
# Install llm
RUN uv tool install llm
# Install OpenCode
RUN npm i -g opencode-ai
# Install PI
RUN npm install -g --ignore-scripts @earendil-works/pi-coding-agent
RUN pi install npm:@cgaravitoq/pi-claude-code-auth


WORKDIR /workspace
