FROM localhost/agentcage-nested

RUN apt-get update && apt-get install -y --no-install-recommends git ca-certificates \
    && rm -rf /var/lib/apt/lists/*

WORKDIR /app
RUN git clone https://github.com/qwibitai/nanoclaw.git .
RUN npm install && npm run build

# Patch container-runner.js for agentcage:
#   - --network host so inner containers reach the proxy
#   - forward proxy/cert env vars to inner containers
#   - mount /certs and /agentcage volumes into inner containers
COPY patch-container-runner.js /tmp/patch-container-runner.js
RUN node /tmp/patch-container-runner.js && rm /tmp/patch-container-runner.js

# Write .env with placeholder (proxy swaps for real key)
RUN echo 'ANTHROPIC_API_KEY={{ANTHROPIC_API_KEY}}' > .env

# Create writable dirs (named volumes mount over these)
RUN mkdir -p store groups data
