#!/bin/bash # ============================================================================= # Happy Agent Bootstrap - Run from anywhere # ============================================================================= # curl -fsSL https://bac.al/start-agent | bash # curl -fsSL https://bac.al/start-agent | bash -s -- -p "Fix the bugs" # ============================================================================= set -euo pipefail IMAGE="${HAPPY_AGENT_IMAGE:-ghcr.io/aronchick/overseer:latest}" CONFIG_DIR="${HAPPY_CONFIG_DIR:-$HOME/.agent}" CONTAINER_NAME="happy-agent" echo "🤖 Happy Agent Bootstrap" echo "━━━━━━━━━━━━━━━━━━━━━━━━" # ----------------------------------------------------------------------------- # Check Docker # ----------------------------------------------------------------------------- if ! command -v docker &>/dev/null; then echo "❌ Docker not found. Installing..." curl -fsSL https://get.docker.com | sh sudo usermod -aG docker "$USER" echo "⚠ Docker installed. Logout/login for group changes, then re-run." exit 1 fi # ----------------------------------------------------------------------------- # Setup config directory # ----------------------------------------------------------------------------- mkdir -p "$CONFIG_DIR" if [[ ! -f "$CONFIG_DIR/.env" ]]; then echo "" echo "📝 First run - setting up config at $CONFIG_DIR/.env" echo "" # Can't prompt for input when piped if [[ ! -t 0 ]]; then echo "❌ Config file not found and can't prompt for keys (no TTY)." echo "" echo " Create config first:" echo " mkdir -p $CONFIG_DIR" echo " cat > $CONFIG_DIR/.env << 'EOF'" echo " ANTHROPIC_API_KEY=sk-ant-..." echo " HAPPY_API_KEY=" echo " GITHUB_TOKEN=ghp_..." echo " EOF" echo " chmod 600 $CONFIG_DIR/.env" echo "" echo " Then re-run this script." exit 1 fi read -rp "ANTHROPIC_API_KEY: " ANTHROPIC_KEY read -rp "HAPPY_API_KEY (optional, press enter to skip): " HAPPY_KEY read -rp "GITHUB_TOKEN (optional, press enter to skip): " GITHUB_KEY cat > "$CONFIG_DIR/.env" << EOF # Happy Agent Configuration ANTHROPIC_API_KEY=$ANTHROPIC_KEY HAPPY_API_KEY=$HAPPY_KEY GITHUB_TOKEN=$GITHUB_KEY EOF chmod 600 "$CONFIG_DIR/.env" echo "✓ Config saved to $CONFIG_DIR/.env" fi # ----------------------------------------------------------------------------- # Auth to ghcr.io if needed # ----------------------------------------------------------------------------- if ! docker pull "$IMAGE" 2>/dev/null; then echo "" echo "🔐 Need GitHub auth for container registry." echo " Create a PAT with read:packages scope at:" echo " https://github.com/settings/tokens/new" echo "" read -rsp "GitHub PAT: " GITHUB_PAT echo "" echo "$GITHUB_PAT" | docker login ghcr.io -u aronchick --password-stdin docker pull "$IMAGE" fi # ----------------------------------------------------------------------------- # Stop existing container if running # ----------------------------------------------------------------------------- docker stop "$CONTAINER_NAME" 2>/dev/null || true docker rm "$CONTAINER_NAME" 2>/dev/null || true # ----------------------------------------------------------------------------- # Determine workspace # ----------------------------------------------------------------------------- WORKSPACE="${HAPPY_WORKSPACE:-$(pwd)}" echo "" echo "📁 Workspace: $WORKSPACE" echo "⚙️ Config: $CONFIG_DIR" echo "" # ----------------------------------------------------------------------------- # Run container # ----------------------------------------------------------------------------- DOCKER_ARGS=( --name "$CONTAINER_NAME" --hostname happy -v "$CONFIG_DIR:/config:ro" -v "$WORKSPACE:/workspace" -w /workspace ) # Mount git/ssh config if available [[ -f "$HOME/.gitconfig" ]] && DOCKER_ARGS+=(-v "$HOME/.gitconfig:/root/.gitconfig:ro") [[ -d "$HOME/.ssh" ]] && DOCKER_ARGS+=(-v "$HOME/.ssh:/root/.ssh:ro") # Check if we have arguments (prompt mode) if [[ $# -gt 0 ]]; then echo "🚀 Running with prompt..." exec docker run --rm "${DOCKER_ARGS[@]}" "$IMAGE" "$@" else # Interactive mode requires a TTY if [[ -t 0 ]]; then echo "🚀 Starting interactive session..." exec docker run -it --rm "${DOCKER_ARGS[@]}" "$IMAGE" else echo "" echo "❌ Interactive mode requires a terminal." echo "" echo " Options:" echo " 1. Run with a prompt:" echo " curl -fsSL https://bac.al/start-agent | bash -s -- -p \"Your task here\"" echo "" echo " 2. Download and run directly:" echo " curl -fsSL https://bac.al/start-agent -o start-agent && chmod +x start-agent && ./start-agent" echo "" exit 1 fi fi