/ scripts / setup / setup.sh
setup.sh
  1  #!/bin/bash
  2  # Setup script for ECHO agents in Claude Desktop
  3  
  4  set -e
  5  
  6  # Colors
  7  RED='\033[0;31m'
  8  GREEN='\033[0;32m'
  9  YELLOW='\033[1;33m'
 10  BLUE='\033[0;34m'
 11  NC='\033[0m' # No Color
 12  
 13  echo -e "${BLUE}╺━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╸${NC}"
 14  echo -e "${BLUE}  ECHO - Claude Desktop Setup${NC}"
 15  echo -e "${BLUE}╺━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╸${NC}"
 16  echo ""
 17  
 18  # Detect OS and set config path
 19  if [[ "$OSTYPE" == "darwin"* ]]; then
 20      CONFIG_DIR="$HOME/Library/Application Support/Claude"
 21  elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
 22      CONFIG_DIR="$HOME/.config/Claude"
 23  else
 24      echo -e "${RED}✗ Unsupported OS: $OSTYPE${NC}"
 25      exit 1
 26  fi
 27  
 28  CONFIG_FILE="$CONFIG_DIR/claude_desktop_config.json"
 29  
 30  echo -e "${YELLOW}Step 1: Checking prerequisites...${NC}"
 31  echo ""
 32  
 33  # Check PostgreSQL
 34  echo -n "  PostgreSQL... "
 35  if pg_isready -q; then
 36      echo -e "${GREEN}✓${NC}"
 37  else
 38      echo -e "${RED}✗ Not running${NC}"
 39      echo -e "${YELLOW}  Start with: brew services start postgresql${NC}"
 40      exit 1
 41  fi
 42  
 43  # Check Redis
 44  echo -n "  Redis... "
 45  if redis-cli ping > /dev/null 2>&1; then
 46      echo -e "${GREEN}✓${NC}"
 47  else
 48      echo -e "${RED}✗ Not running${NC}"
 49      echo -e "${YELLOW}  Start with: brew services start redis${NC}"
 50      exit 1
 51  fi
 52  
 53  # Check database exists
 54  echo -n "  Database (echo_org_dev)... "
 55  if psql -lqt | cut -d \| -f 1 | grep -qw echo_org_dev; then
 56      echo -e "${GREEN}✓${NC}"
 57  else
 58      echo -e "${YELLOW}! Not found - will create${NC}"
 59      cd apps/echo_shared
 60      mix ecto.create
 61      mix ecto.migrate
 62      cd ../..
 63  fi
 64  
 65  # Check if agents are built
 66  echo ""
 67  echo -e "${YELLOW}Step 2: Checking agent executables...${NC}"
 68  echo ""
 69  
 70  AGENTS=("ceo" "cto" "product_manager")
 71  MISSING_AGENTS=()
 72  
 73  for agent in "${AGENTS[@]}"; do
 74      echo -n "  $agent... "
 75      if [[ -x "apps/$agent/$agent" ]]; then
 76          echo -e "${GREEN}✓${NC}"
 77      else
 78          echo -e "${YELLOW}! Not built${NC}"
 79          MISSING_AGENTS+=("$agent")
 80      fi
 81  done
 82  
 83  if [[ ${#MISSING_AGENTS[@]} -gt 0 ]]; then
 84      echo ""
 85      echo -e "${YELLOW}Building missing agents...${NC}"
 86      for agent in "${MISSING_AGENTS[@]}"; do
 87          echo "  Building $agent..."
 88          cd "apps/$agent"
 89          mix deps.get > /dev/null 2>&1
 90          mix escript.build
 91          cd ../..
 92      done
 93      echo -e "${GREEN}✓ All agents built${NC}"
 94  fi
 95  
 96  # Get absolute path to ECHO directory
 97  ECHO_DIR=$(pwd)
 98  
 99  echo ""
100  echo -e "${YELLOW}Step 3: Creating Claude Desktop configuration...${NC}"
101  echo ""
102  
103  # Create config directory if it doesn't exist
104  mkdir -p "$CONFIG_DIR"
105  
106  # Backup existing config if it exists
107  if [[ -f "$CONFIG_FILE" ]]; then
108      BACKUP_FILE="${CONFIG_FILE}.backup.$(date +%Y%m%d_%H%M%S)"
109      echo -e "${YELLOW}  Backing up existing config to:${NC}"
110      echo "  $BACKUP_FILE"
111      cp "$CONFIG_FILE" "$BACKUP_FILE"
112  
113      # Try to merge with existing config
114      echo -e "${YELLOW}  Merging with existing configuration...${NC}"
115  
116      # Create temporary config with ECHO agents
117      cat > /tmp/echo_agents.json << EOF
118  {
119    "echo-ceo": {
120      "command": "$ECHO_DIR/apps/ceo/ceo",
121      "env": {
122        "DB_HOST": "localhost",
123        "DB_PORT": "5432",
124        "DB_NAME": "echo_org_dev",
125        "DB_USER": "postgres",
126        "DB_PASSWORD": "postgres",
127        "REDIS_HOST": "localhost",
128        "REDIS_PORT": "6379"
129      }
130    },
131    "echo-cto": {
132      "command": "$ECHO_DIR/apps/cto/cto",
133      "env": {
134        "DB_HOST": "localhost",
135        "DB_PORT": "5432",
136        "DB_NAME": "echo_org_dev",
137        "DB_USER": "postgres",
138        "DB_PASSWORD": "postgres",
139        "REDIS_HOST": "localhost",
140        "REDIS_PORT": "6379"
141      }
142    },
143    "echo-product-manager": {
144      "command": "$ECHO_DIR/apps/product_manager/product_manager",
145      "env": {
146        "DB_HOST": "localhost",
147        "DB_PORT": "5432",
148        "DB_NAME": "echo_org_dev",
149        "DB_USER": "postgres",
150        "DB_PASSWORD": "postgres",
151        "REDIS_HOST": "localhost",
152        "REDIS_PORT": "6379"
153      }
154    }
155  }
156  EOF
157  
158      # Merge configurations using jq if available
159      if command -v jq &> /dev/null; then
160          jq -s '.[0].mcpServers + .[1] | {mcpServers: .}' "$CONFIG_FILE" /tmp/echo_agents.json > /tmp/merged_config.json
161          mv /tmp/merged_config.json "$CONFIG_FILE"
162          echo -e "${GREEN}  ✓ Merged with existing servers${NC}"
163      else
164          echo -e "${YELLOW}  ! jq not found - creating new config (old config backed up)${NC}"
165          cat > "$CONFIG_FILE" << EOF
166  {
167    "mcpServers": {
168      "echo-ceo": {
169        "command": "$ECHO_DIR/apps/ceo/ceo",
170        "env": {
171          "DB_HOST": "localhost",
172          "DB_PORT": "5432",
173          "DB_NAME": "echo_org_dev",
174          "DB_USER": "postgres",
175          "DB_PASSWORD": "postgres",
176          "REDIS_HOST": "localhost",
177          "REDIS_PORT": "6379"
178        }
179      },
180      "echo-cto": {
181        "command": "$ECHO_DIR/apps/cto/cto",
182        "env": {
183          "DB_HOST": "localhost",
184          "DB_PORT": "5432",
185          "DB_NAME": "echo_org_dev",
186          "DB_USER": "postgres",
187          "DB_PASSWORD": "postgres",
188          "REDIS_HOST": "localhost",
189          "REDIS_PORT": "6379"
190        }
191      },
192      "echo-product-manager": {
193        "command": "$ECHO_DIR/apps/product_manager/product_manager",
194        "env": {
195          "DB_HOST": "localhost",
196          "DB_PORT": "5432",
197          "DB_NAME": "echo_org_dev",
198          "DB_USER": "postgres",
199          "DB_PASSWORD": "postgres",
200          "REDIS_HOST": "localhost",
201          "REDIS_PORT": "6379"
202        }
203      }
204    }
205  }
206  EOF
207      fi
208      rm -f /tmp/echo_agents.json
209  else
210      # Create new config
211      cat > "$CONFIG_FILE" << EOF
212  {
213    "mcpServers": {
214      "echo-ceo": {
215        "command": "$ECHO_DIR/apps/ceo/ceo",
216        "env": {
217          "DB_HOST": "localhost",
218          "DB_PORT": "5432",
219          "DB_NAME": "echo_org_dev",
220          "DB_USER": "postgres",
221          "DB_PASSWORD": "postgres",
222          "REDIS_HOST": "localhost",
223          "REDIS_PORT": "6379"
224        }
225      },
226      "echo-cto": {
227        "command": "$ECHO_DIR/apps/cto/cto",
228        "env": {
229          "DB_HOST": "localhost",
230          "DB_PORT": "5432",
231          "DB_NAME": "echo_org_dev",
232          "DB_USER": "postgres",
233          "DB_PASSWORD": "postgres",
234          "REDIS_HOST": "localhost",
235          "REDIS_PORT": "6379"
236        }
237      },
238      "echo-product-manager": {
239        "command": "$ECHO_DIR/apps/product_manager/product_manager",
240        "env": {
241          "DB_HOST": "localhost",
242          "DB_PORT": "5432",
243          "DB_NAME": "echo_org_dev",
244          "DB_USER": "postgres",
245          "DB_PASSWORD": "postgres",
246          "REDIS_HOST": "localhost",
247          "REDIS_PORT": "6379"
248        }
249      }
250    }
251  }
252  EOF
253  fi
254  
255  echo -e "${GREEN}  ✓ Configuration created at:${NC}"
256  echo "  $CONFIG_FILE"
257  
258  echo ""
259  echo -e "${YELLOW}Step 4: Testing agent executables...${NC}"
260  echo ""
261  
262  for agent in "${AGENTS[@]}"; do
263      echo -n "  Testing $agent... "
264      if timeout 2s "apps/$agent/$agent" < /dev/null > /dev/null 2>&1; then
265          echo -e "${GREEN}✓${NC}"
266      else
267          # Agent should timeout waiting for stdin, which is expected
268          echo -e "${GREEN}✓ (waiting for input)${NC}"
269      fi
270  done
271  
272  echo ""
273  echo -e "${GREEN}╺━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╸${NC}"
274  echo -e "${GREEN}  Setup Complete!${NC}"
275  echo -e "${GREEN}╺━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╸${NC}"
276  echo ""
277  echo -e "${BLUE}Next steps:${NC}"
278  echo ""
279  echo "  1. ${YELLOW}Restart Claude Desktop completely${NC}"
280  echo "     (Quit and reopen, not just close window)"
281  echo ""
282  echo "  2. ${YELLOW}Verify agents are connected:${NC}"
283  echo "     In Claude Desktop, ask: 'List all available MCP tools'"
284  echo ""
285  echo "  3. ${YELLOW}Try a simple test:${NC}"
286  echo "     'Use the CEO agent to review organizational health'"
287  echo ""
288  echo "  4. ${YELLOW}Monitor system health:${NC}"
289  echo "     Run: ./echo.sh summary"
290  echo ""
291  echo -e "${BLUE}Documentation:${NC}"
292  echo "  - CLAUDE_DESKTOP_SETUP.md - Detailed setup guide"
293  echo "  - DEMO_GUIDE.md - Demo scenarios and examples"
294  echo "  - AGENT_INTEGRATION_GUIDE.md - Agent implementation details"
295  echo ""
296  echo -e "${YELLOW}Configuration file:${NC} $CONFIG_FILE"
297  echo ""
298  echo -e "${GREEN}Happy collaborating with ECHO agents! 🤖${NC}"
299  echo ""