name: aeries-3-society
description: "Aeries Phase 3: The Social Layer. Adds Spatial Service and Redis Pub/Sub for agent interactions."
version: 1

vars:
  project_id: "" # Required
  feature_slug: "spatial-social"

steps:
  # --- Infrastructure ---
  add-redis:
    description: "Add Redis for Real-time Events"
    action: api
    method: POST
    endpoint: "/projects/{{ .vars.project_id }}/components"
    body: { type: redis, name: "world-state" }

  add-spatial-svc:
    description: "Add Spatial Service to track positions"
    depends_on: [add-redis]
    action: api
    method: POST
    endpoint: "/projects/{{ .vars.project_id }}/components"
    body: { type: service, name: "spatial-svc" }

  wait-infra:
    action: wait_pipeline
    project_id: "{{ .vars.project_id }}"

  # --- Feature: Proximity Chat ---
  implement-social:
    description: "Agent connects Simulation to Spatial via Redis"
    depends_on: [wait-infra]
    action: api
    method: POST
    endpoint: "/projects/{{ .vars.project_id }}/builds"
    body:
      prompt: "/implement-feature {{ .vars.feature_slug }} --requirements 'Simulation SVC publishes agent moves to Redis. Spatial SVC tracks proximity. If two agents are near, Core UI shows a chat bubble.'"
      auto_commit: true
      auto_push: true
      git_clone_url: "https://git.threesix.ai/jordan/{{ .vars.project_id }}.git"
    outputs:
      - build_id: .data.task_id

  wait-code:
    description: Wait for social layer implementation
    depends_on: [implement-social]
    action: wait_build
    build_id: "{{ .outputs.implement-social.build_id }}"
    max_attempts: 120
    poll_interval: 5

  wait-deploy:
    action: wait_pipeline
    project_id: "{{ .vars.project_id }}"

  # --- Verification ---
  verify-society:
    description: "Test Event Stream"
    depends_on: [wait-deploy]
    action: shell
    command: |
      DOMAIN=$(curl -s "$RDEV_API_URL/projects/{{ .vars.project_id }}" -H "X-API-Key: $RDEV_API_KEY" | jq -r .domain)
      # Check if events endpoint exists
      HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" "https://$DOMAIN/api/events")
      if [[ "$HTTP_CODE" == "200" || "$HTTP_CODE" == "101" ]]; then
        echo "Society Layer Live"
        exit 0
      else
        exit 1
      fi
