#!/usr/bin/env bash set -euo pipefail ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" BACKEND_DIR="$ROOT_DIR/backend" FRONTEND_DIR="$ROOT_DIR/frontend" AGENT_DIR="$ROOT_DIR/agent-server" BACKEND_HOST="${BACKEND_HOST:-127.0.0.1}" BACKEND_PORT="${BACKEND_PORT:-8000}" AGENT_HOST="${AGENT_HOST:-127.0.0.1}" AGENT_PORT="${AGENT_PORT:-8010}" FRONTEND_HOST="${FRONTEND_HOST:-127.0.0.1}" FRONTEND_PORT="${FRONTEND_PORT:-5173}" RUN_NAME="${RUN_NAME:-frontend_split_motor_7nm}" cleanup() { if [[ -n "${AGENT_PID:-}" ]]; then kill "$AGENT_PID" 2>/dev/null || true fi if [[ -n "${BACKEND_PID:-}" ]]; then kill "$BACKEND_PID" 2>/dev/null || true fi } trap cleanup EXIT INT TERM if [[ ! -d "$FRONTEND_DIR/node_modules" ]]; then echo "Installing frontend dependencies..." (cd "$FRONTEND_DIR" && npm install) fi echo "Starting backend on http://$BACKEND_HOST:$BACKEND_PORT" ( cd "$BACKEND_DIR" python -m src.dev_server --host "$BACKEND_HOST" --port "$BACKEND_PORT" --run-name "$RUN_NAME" ) & BACKEND_PID=$! echo "Starting agent server on http://$AGENT_HOST:$AGENT_PORT" ( cd "$AGENT_DIR" if [[ ! -d node_modules ]]; then npm install fi CAD_AGENT_STUDIO_CONFIG="$ROOT_DIR/llm.config.yaml" ORBIT_PROJECT_ROOT="$ROOT_DIR" TOOLCHAIN_URL="http://$BACKEND_HOST:$BACKEND_PORT" AGENT_HOST="$AGENT_HOST" AGENT_PORT="$AGENT_PORT" npm run dev ) & AGENT_PID=$! echo "Starting frontend on http://$FRONTEND_HOST:$FRONTEND_PORT" cd "$FRONTEND_DIR" BACKEND_HOST="$BACKEND_HOST" BACKEND_PORT="$BACKEND_PORT" AGENT_HOST="$AGENT_HOST" AGENT_PORT="$AGENT_PORT" FRONTEND_HOST="$FRONTEND_HOST" FRONTEND_PORT="$FRONTEND_PORT" npm run dev -- --host "$FRONTEND_HOST" --port "$FRONTEND_PORT" --strictPort