/ scripts / setup / start.sh
start.sh
  1  #!/bin/bash
  2  
  3  # ECHO - Master Startup Script
  4  #
  5  # This script does everything needed to start the ECHO system:
  6  # 1. Checks prerequisites (PostgreSQL, Redis)
  7  # 2. Builds all agents with latest code
  8  # 3. Starts all 9 agents as background processes
  9  # 4. Ready for orchestrator to run
 10  #
 11  # Usage:
 12  #   ./start.sh
 13  
 14  set -e
 15  
 16  ECHO_ROOT="/Users/pranav/Documents/echo"
 17  
 18  # Color output
 19  GREEN='\033[0;32m'
 20  RED='\033[0;31m'
 21  YELLOW='\033[1;33m'
 22  BLUE='\033[0;34m'
 23  NC='\033[0m' # No Color
 24  
 25  echo ""
 26  echo "================================================================================"
 27  echo -e "${BLUE}ECHO - Complete System Startup${NC}"
 28  echo "================================================================================"
 29  echo ""
 30  
 31  # Step 1: Check prerequisites
 32  echo -e "${BLUE}Step 1/3: Checking Prerequisites${NC}"
 33  echo "--------------------------------------------------------------------------------"
 34  
 35  # Check PostgreSQL
 36  if ! pg_isready -h localhost >/dev/null 2>&1; then
 37      echo -e "${RED}✗ PostgreSQL is not running${NC}"
 38      echo "  Start it: brew services start postgresql@14"
 39      exit 1
 40  fi
 41  echo -e "${GREEN}✓ PostgreSQL is running${NC}"
 42  
 43  # Check Redis
 44  if ! redis-cli ping >/dev/null 2>&1; then
 45      echo -e "${RED}✗ Redis is not running${NC}"
 46      echo "  Start it: brew services start redis"
 47      exit 1
 48  fi
 49  echo -e "${GREEN}✓ Redis is running${NC}"
 50  
 51  # Check database exists
 52  if ! psql -h localhost -U postgres -lqt | cut -d \| -f 1 | grep -qw echo_org; then
 53      echo -e "${RED}✗ Database 'echo_org' does not exist${NC}"
 54      echo "  Run: cd shared && mix ecto.create && mix ecto.migrate"
 55      exit 1
 56  fi
 57  echo -e "${GREEN}✓ Database 'echo_org' exists${NC}"
 58  
 59  echo ""
 60  
 61  # Step 2: Build all agents
 62  echo -e "${BLUE}Step 2/3: Building All Agents${NC}"
 63  echo "--------------------------------------------------------------------------------"
 64  
 65  # Kill any existing agents first
 66  if pgrep -f "apps/" > /dev/null 2>&1; then
 67      echo -e "${YELLOW}⧗ Stopping existing agents...${NC}"
 68      pkill -f "apps/" || true
 69      sleep 2
 70      echo -e "${GREEN}✓ Existing agents stopped${NC}"
 71  fi
 72  
 73  # Build agents
 74  echo -e "${YELLOW}⧗ Building all 9 agents...${NC}"
 75  
 76  cd "$ECHO_ROOT"
 77  
 78  AGENTS=(
 79      "ceo"
 80      "cto"
 81      "chro"
 82      "operations_head"
 83      "product_manager"
 84      "senior_architect"
 85      "uiux_engineer"
 86      "senior_developer"
 87      "test_lead"
 88  )
 89  
 90  BUILD_FAILED=0
 91  
 92  # First, rebuild shared library with new config
 93  echo -e "${YELLOW}  ⧗ Rebuilding shared library...${NC}"
 94  cd "$ECHO_ROOT/shared"
 95  if mix deps.get > /dev/null 2>&1 && mix compile > /dev/null 2>&1; then
 96      echo -e "${GREEN}  ✓ shared library${NC}"
 97  else
 98      echo -e "${RED}  ✗ shared library (build failed)${NC}"
 99      exit 1
100  fi
101  
102  cd "$ECHO_ROOT"
103  
104  # Now build each agent
105  for agent in "${AGENTS[@]}"; do
106      cd "apps/$agent"
107  
108      # Clean corrupted caches, get deps, build
109      if rm -rf _build deps > /dev/null 2>&1 && \
110         mix deps.get > /dev/null 2>&1 && \
111         mix escript.build > /dev/null 2>&1; then
112          echo -e "${GREEN}  ✓ $agent${NC}"
113      else
114          echo -e "${RED}  ✗ $agent (build failed)${NC}"
115          BUILD_FAILED=1
116      fi
117  
118      cd "$ECHO_ROOT"
119  done
120  
121  if [ $BUILD_FAILED -eq 1 ]; then
122      echo ""
123      echo -e "${RED}Some agents failed to build. Fix errors and try again.${NC}"
124      exit 1
125  fi
126  
127  echo -e "${GREEN}✓ All 9 agents built successfully${NC}"
128  echo ""
129  
130  # Step 3: Start all agents
131  echo -e "${BLUE}Step 3/3: Starting All Agents${NC}"
132  echo "--------------------------------------------------------------------------------"
133  
134  ./scripts/run_day1_with_agents.sh
135  
136  # This script will keep running (agents are running)
137  # User will Ctrl+C to stop