services:
  redis:
    image: redis:7
    container_name: agent-system-redis
    ports:
      - "6379:6379"
    restart: unless-stopped

  webui:
    build: ./webui
    container_name: agent-system-webui
    ports:
      - "18180:8080"
    environment:
      # Empty by default (standalone/dev mode: reads/mutates local ACTIONS_DIR).
      # Set on mirror nodes (see hosts/<node>/runtime/agent-system/) to make
      # this panel read actions from world/actions.json and proxy approve/
      # reject to the VPS control-plane instead.
      CONTROL_PLANE_URL: ${CONTROL_PLANE_URL:-}
    volumes:
      - /opt/homelab:/opt/homelab
      # Shared liveness logic — single source of truth, bind-mounted read-only
      # so this image does not carry a second copy of the thresholds/tier logic.
      # web.py imports it defensively; absence degrades to observer status only.
      - ../control-plane/src/liveness.py:/app/liveness.py:ro
    depends_on:
      - redis
    restart: unless-stopped

  runtime-materializer:
    build: ./runtime-materializer
    container_name: agent-system-runtime-materializer
    environment:
      REDIS_HOST: redis
      REDIS_PORT: "6379"
      HOMELAB_WORLD_ROOT: /opt/homelab/world
      WORLD_DIR: /opt/homelab/world
      MATERIALIZE_INTERVAL: "10"
    volumes:
      - /opt/homelab:/opt/homelab
    depends_on:
      - redis
    restart: unless-stopped

  telegram-bot:
    build: ./telegram-bot
    container_name: agent-system-telegram-bot
    environment:
      TELEGRAM_BOT_TOKEN: ${TELEGRAM_BOT_TOKEN}
      TELEGRAM_ALLOWED_USER_IDS: ${TELEGRAM_ALLOWED_USER_IDS}
      CONTROL_PLANE_URL: ${CONTROL_PLANE_URL:-http://webui:8080}
      ENABLE_LLM_FALLBACK: ${ENABLE_LLM_FALLBACK:-false}
      OPENCLAW_BASE_URL: ${OPENCLAW_BASE_URL}
      ACTIONS_ROOT: /opt/homelab/actions
    volumes:
      - /opt/homelab:/opt/homelab
    restart: on-failure
