# Multi-arch image: linux/amd64 + linux/arm64.
# quantcrypt (PQ crypto) ships manylinux_x86_64 wheels only — installed on
# amd64 at build time; on arm64 it is silently skipped (PQ signing falls back
# to Ed25519-only mode; all other features are unaffected).
FROM python:3.13-slim

ARG TARGETPLATFORM

# Node.js LTS — needed for npx mcp-remote (MCP HTTP/SSE bridge for external servers)
RUN apt-get update && apt-get install -y --no-install-recommends nodejs npm \
    && npm install -g mcp-remote \
    && apt-get clean && rm -rf /var/lib/apt/lists/*

COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv

WORKDIR /app

COPY pyproject.toml README.md ./
COPY src ./src

# Install base package; on amd64 also pull in quantcrypt for PQ crypto support.
RUN uv pip install --system --no-cache ".[websockets]" \
    && if [ "$TARGETPLATFORM" = "linux/amd64" ] || [ -z "$TARGETPLATFORM" ]; then \
         uv pip install --system --no-cache "quantcrypt>=1.0" 2>/dev/null || true; \
       fi

# All HyperMind state (env file, DB, populations, sims) lives here.
# Mount a volume or bind-mount to persist across restarts.
ENV HYPERMIND_HOME=/data
# Informational console narration (communications, tool calls, claims, trust
# events) on by default in containers — set HYPERMIND_CONSOLE=0 to silence.
ENV HYPERMIND_CONSOLE=1
RUN mkdir -p /data

VOLUME ["/data"]

# TCP MCP (JSON-RPC 2.0) on 8484, optional SSE dashboard on 8766
EXPOSE 8484 8766

# Print usage on start so operators know exactly how to configure.
# Pass LLM keys via -e or --env-file; mount /data for persistence.
#
# Quick start:
#   docker run -d \
#     -e OPENAI_API_KEY=sk-... \
#     -v hm-data:/data \
#     -p 8484:8484 -p 8766:8766 \
#     openworkbench/hypermind
#
# With env file (recommended):
#   docker run -d \
#     --env-file .env \
#     -v hm-data:/data \
#     -p 8484:8484 -p 8766:8766 \
#     openworkbench/hypermind
#
# .env file keys:
#   OPENAI_API_KEY=sk-...
#   ANTHROPIC_API_KEY=sk-ant-...   # or use Anthropic
#   OPENAI_BASE_URL=http://...     # local model (Ollama etc.)
#   HYPERMIND_LLM_MODEL=gpt-4o
#   RELATA_URL=http://relata:9090  # optional durable ledger
CMD ["hmctl", "mcp", "serve", "--write", "--log-level", "info"]
