#!/usr/bin/env bash set -euo pipefail ROOT="$(cd "$(dirname "$0")/.." && pwd)" NODE_BIN="${NODE_BIN:-/opt/homebrew/opt/node@24/bin/node}" RUNNER="${ROOT}/scripts/run-cursor-chat-bridge-prod.sh" LABEL="${MEMIND_CURSOR_CHAT_BRIDGE_LABEL:-cn.tkmind.cursor-chat-bridge}" PLIST="$HOME/Library/LaunchAgents/${LABEL}.plist" LOG="$HOME/Library/Logs/memind-cursor-chat-bridge.log" GUI="gui/$(id -u)" PORT="${MEMIND_CURSOR_CHAT_BRIDGE_PORT:-18040}" mkdir -p "$HOME/Library/LaunchAgents" "$HOME/Library/Logs" if [[ ! -x "$NODE_BIN" ]]; then NODE_BIN="$(command -v node)" fi if [[ ! -f "$RUNNER" ]]; then echo "cursor chat bridge runner not found: $RUNNER" >&2 exit 1 fi chmod +x "$RUNNER" cat > "$PLIST" < Label $LABEL ProgramArguments /bin/bash $RUNNER WorkingDirectory $ROOT RunAtLoad KeepAlive ThrottleInterval 10 StandardOutPath $LOG StandardErrorPath $LOG EnvironmentVariables PATH /opt/homebrew/bin:/opt/homebrew/opt/node@24/bin:/usr/local/bin:/usr/bin:/bin MEMIND_CURSOR_CHAT_BRIDGE_ENABLED 1 MEMIND_CURSOR_CHAT_BRIDGE_ENTRYPOINT 1 MEMIND_CURSOR_CHAT_BRIDGE_PORT $PORT EOF plutil -lint "$PLIST" launchctl bootout "$GUI/$LABEL" 2>/dev/null || true launchctl bootstrap "$GUI" "$PLIST" launchctl enable "$GUI/$LABEL" launchctl kickstart -k "$GUI/$LABEL" echo "installed $PLIST" echo "runner: $RUNNER" echo "port: $PORT" echo "log: $LOG"