services:
  code-queue:
    image: unidesk-code-queue:d601
    build:
      context: ../../../..
      dockerfile: src/components/microservices/code-queue/Dockerfile
      args:
        CODE_QUEUE_BASE_IMAGE: ${CODE_QUEUE_BASE_IMAGE:-oven/bun:1-debian}
    container_name: code-queue-backend
    restart: unless-stopped
    mem_limit: "${CODE_QUEUE_MEM_LIMIT:-15g}"
    memswap_limit: "${CODE_QUEUE_MEMSWAP_LIMIT:-16g}"
    env_file:
      - path: ${CODE_QUEUE_ENV_FILE:-../../../../.state/code-queue-d601.env}
        required: false
    ports:
      - "${CODE_QUEUE_HOST_BIND:-127.0.0.1}:${CODE_QUEUE_HOST_PORT:-4222}:4222"
    environment:
      HOST: "0.0.0.0"
      PORT: "4222"
      CODE_QUEUE_DATA_DIR: "/var/lib/unidesk/code-queue"
      CODE_QUEUE_INSTANCE_ID: "${CODE_QUEUE_INSTANCE_ID:-D601}"
      CODE_QUEUE_SCHEDULER_ENABLED: "${CODE_QUEUE_SCHEDULER_ENABLED:-true}"
      CODE_QUEUE_STARTUP_OA_BACKFILL_ENABLED: "${CODE_QUEUE_STARTUP_OA_BACKFILL_ENABLED:-false}"
      CODE_QUEUE_WORKDIR: "${CODE_QUEUE_WORKDIR:-/workspace}"
      UNIDESK_SKILLS_PATH: "${UNIDESK_SKILLS_PATH:-/root/.agents/skills}"
      CODE_QUEUE_RUNNER_SKILLS_SOURCE_PATH: "${CODE_QUEUE_RUNNER_SKILLS_SOURCE_PATH:-/home/ubuntu/.agents/skills}"
      CODE_QUEUE_CODEX_HOME: "/var/lib/unidesk/code-queue/codex-home"
      CODE_QUEUE_OPENCODE_XDG_DIR: "/var/lib/unidesk/code-queue/opencode-xdg"
      CODE_QUEUE_SOURCE_CODEX_CONFIG: "/root/.codex/config.toml"
      CODE_QUEUE_DEFAULT_MODEL: "${CODE_QUEUE_DEFAULT_MODEL:-gpt-5.5}"
      CODE_QUEUE_MODELS: "${CODE_QUEUE_MODELS:-gpt-5.5,gpt-5.4-mini,gpt-5.4,deepseek-chat,minimax-m3,minimax-m2.7}"
      MINIMAX_MODEL: "${MINIMAX_MODEL:-MiniMax-M3}"
      MINIMAX_M3_MODEL: "${MINIMAX_M3_MODEL:-MiniMax-M3}"
      CODE_QUEUE_MODEL_REASONING_EFFORTS: "${CODE_QUEUE_MODEL_REASONING_EFFORTS:-gpt-5.5=xhigh}"
      CODE_QUEUE_SANDBOX: "${CODE_QUEUE_SANDBOX:-danger-full-access}"
      CODE_QUEUE_APPROVAL_POLICY: "${CODE_QUEUE_APPROVAL_POLICY:-never}"
      CODE_QUEUE_MAX_ATTEMPTS: "${CODE_QUEUE_MAX_ATTEMPTS:-10}"
      CODE_QUEUE_MAX_ACTIVE_QUEUES: "${CODE_QUEUE_MAX_ACTIVE_QUEUES:-0}"
      CODE_QUEUE_DATABASE_POOL_MAX: "${CODE_QUEUE_DATABASE_POOL_MAX:-2}"
      NODE_OPTIONS: "${CODE_QUEUE_NODE_OPTIONS:---max-old-space-size=1024}"
      GIT_CONFIG_COUNT: "1"
      GIT_CONFIG_KEY_0: "safe.directory"
      GIT_CONFIG_VALUE_0: "*"
      CODE_QUEUE_IN_MEMORY_OUTPUT_RECORDS: "${CODE_QUEUE_IN_MEMORY_OUTPUT_RECORDS:-10}"
      CODE_QUEUE_IN_MEMORY_EVENT_RECORDS: "${CODE_QUEUE_IN_MEMORY_EVENT_RECORDS:-10}"
      CODE_QUEUE_CODEX_SQLITE_LOG_EXPORT_BATCH_SIZE: "${CODE_QUEUE_CODEX_SQLITE_LOG_EXPORT_BATCH_SIZE:-500}"
      CODE_QUEUE_MAIN_PROVIDER_ID: "${CODE_QUEUE_MAIN_PROVIDER_ID:-D601}"
      CODE_QUEUE_REMOTE_WORKDIR: "${CODE_QUEUE_REMOTE_WORKDIR:-/home/ubuntu}"
      CODE_QUEUE_EXECUTION_PROVIDER_IDS: "${CODE_QUEUE_EXECUTION_PROVIDER_IDS:-D601}"
      CODE_QUEUE_DEV_CONTAINER_MASTER_HOST: "${CODE_QUEUE_DEV_CONTAINER_MASTER_HOST:-74.48.78.17}"
      CODE_QUEUE_DEV_CONTAINER_DEFAULT_PROVIDER_ID: "${CODE_QUEUE_DEV_CONTAINER_DEFAULT_PROVIDER_ID:-D601}"
      CODE_QUEUE_DEV_CONTAINER_IMAGE: "${CODE_QUEUE_DEV_CONTAINER_IMAGE:-}"
      CODE_QUEUE_DEV_CONTAINER_WORKDIR: "${CODE_QUEUE_DEV_CONTAINER_WORKDIR:-/home/ubuntu}"
      CODE_QUEUE_EGRESS_PROXY_ENABLED: "${CODE_QUEUE_EGRESS_PROXY_ENABLED:-true}"
      CODE_QUEUE_EGRESS_PROXY_URL: "${CODE_QUEUE_EGRESS_PROXY_URL:-http://unidesk-provider-gateway-D601:18789}"
      CODE_QUEUE_EGRESS_PROXY_NO_PROXY: "${CODE_QUEUE_EGRESS_PROXY_NO_PROXY:-localhost,127.0.0.1,::1,host.docker.internal,claudeqq,claudeqq.unidesk,claudeqq.unidesk.svc,claudeqq.unidesk.svc.cluster.local,unidesk-provider-gateway-D601,74.48.78.17,backend-core,oa-event-flow,database,hyueapi.com,.hyueapi.com,api.minimaxi.com,.minimaxi.com}"
      HTTP_PROXY: "${CODE_QUEUE_EGRESS_PROXY_URL:-http://unidesk-provider-gateway-D601:18789}"
      HTTPS_PROXY: "${CODE_QUEUE_EGRESS_PROXY_URL:-http://unidesk-provider-gateway-D601:18789}"
      ALL_PROXY: "${CODE_QUEUE_EGRESS_PROXY_URL:-http://unidesk-provider-gateway-D601:18789}"
      http_proxy: "${CODE_QUEUE_EGRESS_PROXY_URL:-http://unidesk-provider-gateway-D601:18789}"
      https_proxy: "${CODE_QUEUE_EGRESS_PROXY_URL:-http://unidesk-provider-gateway-D601:18789}"
      all_proxy: "${CODE_QUEUE_EGRESS_PROXY_URL:-http://unidesk-provider-gateway-D601:18789}"
      NO_PROXY: "${CODE_QUEUE_EGRESS_PROXY_NO_PROXY:-localhost,127.0.0.1,::1,host.docker.internal,claudeqq,claudeqq.unidesk,claudeqq.unidesk.svc,claudeqq.unidesk.svc.cluster.local,unidesk-provider-gateway-D601,74.48.78.17,backend-core,oa-event-flow,database,hyueapi.com,.hyueapi.com,api.minimaxi.com,.minimaxi.com}"
      no_proxy: "${CODE_QUEUE_EGRESS_PROXY_NO_PROXY:-localhost,127.0.0.1,::1,host.docker.internal,claudeqq,claudeqq.unidesk,claudeqq.unidesk.svc,claudeqq.unidesk.svc.cluster.local,unidesk-provider-gateway-D601,74.48.78.17,backend-core,oa-event-flow,database,hyueapi.com,.hyueapi.com,api.minimaxi.com,.minimaxi.com}"
      CODE_QUEUE_WINDOWS_NATIVE_CODEX_DEFAULT_WORKDIR: "${CODE_QUEUE_WINDOWS_NATIVE_CODEX_DEFAULT_WORKDIR:-/mnt/f/Work/ConStart}"
      CODE_QUEUE_WINDOWS_NATIVE_CODEX_BRIDGE_DIR: "${CODE_QUEUE_WINDOWS_NATIVE_CODEX_BRIDGE_DIR:-/home/ubuntu/.unidesk/code-queue/windows-native-codex}"
      CODE_QUEUE_WINDOWS_NATIVE_CODEX_COMMAND: "${CODE_QUEUE_WINDOWS_NATIVE_CODEX_COMMAND:-codex app-server --listen stdio://}"
      CODE_QUEUE_WINDOWS_NATIVE_CODEX_CONNECT_HOST: "${CODE_QUEUE_WINDOWS_NATIVE_CODEX_CONNECT_HOST:-host.docker.internal}"
      CODE_QUEUE_WINDOWS_NATIVE_CODEX_IDLE_TIMEOUT_MS: "${CODE_QUEUE_WINDOWS_NATIVE_CODEX_IDLE_TIMEOUT_MS:-600000}"
      OA_EVENT_FLOW_BASE_URL: "${OA_EVENT_FLOW_BASE_URL:-http://74.48.78.17:4255}"
      CODE_QUEUE_NOTIFY_CLAUDEQQ_ENABLED: "${CODE_QUEUE_NOTIFY_CLAUDEQQ_ENABLED:-true}"
      CODE_QUEUE_NOTIFY_CLAUDEQQ_BASE_URL: "${CODE_QUEUE_NOTIFY_CLAUDEQQ_BASE_URL:-http://claudeqq.unidesk.svc.cluster.local:3290}"
      CODE_QUEUE_NOTIFY_CLAUDEQQ_TARGET_TYPE: "${CODE_QUEUE_NOTIFY_CLAUDEQQ_TARGET_TYPE:-private}"
      CODE_QUEUE_NOTIFY_CLAUDEQQ_USER_ID: "${CODE_QUEUE_NOTIFY_CLAUDEQQ_USER_ID:-645275593}"
      CODE_QUEUE_NOTIFY_CLAUDEQQ_GROUP_ID: "${CODE_QUEUE_NOTIFY_CLAUDEQQ_GROUP_ID:-}"
      CODE_QUEUE_NOTIFY_CLAUDEQQ_MAX_RESPONSE_CHARS: "${CODE_QUEUE_NOTIFY_CLAUDEQQ_MAX_RESPONSE_CHARS:-12000}"
      CODE_QUEUE_NOTIFY_CLAUDEQQ_TIMEOUT_MS: "${CODE_QUEUE_NOTIFY_CLAUDEQQ_TIMEOUT_MS:-15000}"
      CODE_QUEUE_NOTIFY_CLAUDEQQ_SEND_ATTEMPTS: "${CODE_QUEUE_NOTIFY_CLAUDEQQ_SEND_ATTEMPTS:-3}"
      LOG_FILE: "/var/log/unidesk/code-queue.jsonl"
      UNIDESK_LOG_RETENTION_BYTES: "${UNIDESK_LOG_RETENTION_BYTES:-1GiB}"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - ${CODE_QUEUE_REPO_PATH:-../../../..}:/root/unidesk
      - ${CODE_QUEUE_WORKSPACE_PATH:-/home/ubuntu}:/workspace
      - ${CODE_QUEUE_CODEX_CONFIG_PATH:-/home/ubuntu/.codex/config.toml}:/root/.codex/config.toml:ro
      - ${CODE_QUEUE_CODEX_AUTH_PATH:-/home/ubuntu/.codex/auth.json}:/root/.codex/auth.json:ro
      - ${CODE_QUEUE_SKILLS_PATH:-/home/ubuntu/.agents/skills}:/root/.agents/skills:ro
      - ${CODE_QUEUE_SSH_DIR:-/home/ubuntu/.ssh}:/root/.ssh:ro
      - ${CODE_QUEUE_LOG_DIR:-../../../../.state/code-queue/logs}:/var/log/unidesk
      - ${CODE_QUEUE_STATE_DIR:-../../../../.state/code-queue}:/var/lib/unidesk/code-queue
    extra_hosts:
      - "host.docker.internal:host-gateway"
    networks:
      - default
      - provider-gateway
    healthcheck:
      test: ["CMD-SHELL", "curl -fsS --max-time 2 http://127.0.0.1:4222/health >/dev/null"]
      interval: 5s
      timeout: 3s
      retries: 20

networks:
  provider-gateway:
    external: true
    name: ${CODE_QUEUE_PROVIDER_GATEWAY_NETWORK:-unidesk-provider-d601_default}
