name: openhandoff

services:
  backend:
    build:
      context: ..
      dockerfile: factory/docker/backend.dev.Dockerfile
    image: openhandoff-backend-dev
    working_dir: /app
    environment:
      HF_BACKEND_HOST: "0.0.0.0"
      HF_BACKEND_PORT: "7741"
      HF_RIVET_MANAGER_PORT: "8750"
      RIVETKIT_STORAGE_PATH: "/root/.local/share/openhandoff/rivetkit"
      # Pass through credentials needed for agent execution + PR creation in dev/e2e.
      # Do not hardcode secrets; set these in your environment when starting compose.
      ANTHROPIC_API_KEY: "${ANTHROPIC_API_KEY:-}"
      CLAUDE_API_KEY: "${CLAUDE_API_KEY:-${ANTHROPIC_API_KEY:-}}"
      OPENAI_API_KEY: "${OPENAI_API_KEY:-}"
      # sandbox-agent codex plugin currently expects CODEX_API_KEY. Map from OPENAI_API_KEY for convenience.
      CODEX_API_KEY: "${CODEX_API_KEY:-${OPENAI_API_KEY:-}}"
      # Support either GITHUB_TOKEN or GITHUB_PAT in local env files.
      GITHUB_TOKEN: "${GITHUB_TOKEN:-${GITHUB_PAT:-}}"
      GH_TOKEN: "${GH_TOKEN:-${GITHUB_TOKEN:-${GITHUB_PAT:-}}}"
      DAYTONA_ENDPOINT: "${DAYTONA_ENDPOINT:-}"
      DAYTONA_API_KEY: "${DAYTONA_API_KEY:-}"
      HF_DAYTONA_ENDPOINT: "${HF_DAYTONA_ENDPOINT:-}"
      HF_DAYTONA_API_KEY: "${HF_DAYTONA_API_KEY:-}"
    ports:
      - "7741:7741"
      # RivetKit manager (used by browser clients after /api/rivet metadata redirect in dev)
      - "8750:8750"
    volumes:
      - "..:/app"
      # The linked RivetKit checkout resolves from factory packages to /handoff/rivet-checkout in-container.
      - "../../../handoff/rivet-checkout:/handoff/rivet-checkout:ro"
      # Reuse the host Codex auth profile for local sandbox-agent Codex sessions in dev.
      - "${HOME}/.codex:/root/.codex"
      # Keep backend dependency installs Linux-native instead of using host node_modules.
      - "openhandoff_backend_root_node_modules:/app/node_modules"
      - "openhandoff_backend_backend_node_modules:/app/factory/packages/backend/node_modules"
      - "openhandoff_backend_shared_node_modules:/app/factory/packages/shared/node_modules"
      - "openhandoff_backend_persist_rivet_node_modules:/app/sdks/persist-rivet/node_modules"
      - "openhandoff_backend_typescript_node_modules:/app/sdks/typescript/node_modules"
      - "openhandoff_backend_pnpm_store:/root/.local/share/pnpm/store"
      # Persist backend-managed local git clones across container restarts.
      - "openhandoff_git_repos:/root/.local/share/openhandoff/repos"
      # Persist RivetKit local storage across container restarts.
      - "openhandoff_rivetkit_storage:/root/.local/share/openhandoff/rivetkit"

  frontend:
    build:
      context: ..
      dockerfile: factory/docker/frontend.dev.Dockerfile
    working_dir: /app
    depends_on:
      - backend
    environment:
      HOME: "/tmp"
      HF_BACKEND_HTTP: "http://backend:7741"
    ports:
      - "4173:4173"
    volumes:
      - "..:/app"
      # Ensure logs in .openhandoff/ persist on the host even if we change source mounts later.
      - "./.openhandoff:/app/factory/.openhandoff"
      - "../../../handoff/rivet-checkout:/handoff/rivet-checkout:ro"
      # Use Linux-native workspace dependencies inside the container instead of host node_modules.
      - "openhandoff_node_modules:/app/node_modules"
      - "openhandoff_client_node_modules:/app/factory/packages/client/node_modules"
      - "openhandoff_frontend_errors_node_modules:/app/factory/packages/frontend-errors/node_modules"
      - "openhandoff_frontend_node_modules:/app/factory/packages/frontend/node_modules"
      - "openhandoff_shared_node_modules:/app/factory/packages/shared/node_modules"
      - "openhandoff_pnpm_store:/tmp/.local/share/pnpm/store"

volumes:
  openhandoff_backend_root_node_modules: {}
  openhandoff_backend_backend_node_modules: {}
  openhandoff_backend_shared_node_modules: {}
  openhandoff_backend_persist_rivet_node_modules: {}
  openhandoff_backend_typescript_node_modules: {}
  openhandoff_backend_pnpm_store: {}
  openhandoff_git_repos: {}
  openhandoff_rivetkit_storage: {}
  openhandoff_node_modules: {}
  openhandoff_client_node_modules: {}
  openhandoff_frontend_errors_node_modules: {}
  openhandoff_frontend_node_modules: {}
  openhandoff_shared_node_modules: {}
  openhandoff_pnpm_store: {}
