#!/usr/bin/env bash # Install Goose v1.49 (goose serve) as a local LaunchAgent on loopback :18049. set -euo pipefail ROOT="$(cd "$(dirname "$0")/.." && pwd)" PORT="${GOOSE_V149_PORT:-18049}" LABEL="${GOOSE_V149_LAUNCHD_LABEL:-com.tkmind.local-goose-v149}" LAUNCHD_DIR="${HOME}/Library/LaunchAgents" PLIST="${LAUNCHD_DIR}/${LABEL}.plist" RUN_SCRIPT="${ROOT}/scripts/run-goosed-v149-local.sh" LOG_ROOT="${GOOSE_V149_RUNTIME_ROOT:-/tmp/goose-v149-runtime}" GUI="gui/$(id -u)" usage() { cat </dev/null || true rm -f "${PLIST}" if lsof -nP -iTCP:"${PORT}" -sTCP:LISTEN >/dev/null 2>&1; then lsof -ti "TCP:${PORT}" -sTCP:LISTEN | xargs kill -TERM 2>/dev/null || true fi echo "[install-local-goose-v149] uninstalled ${LABEL}" } if [[ "${1:-}" == "--uninstall" ]]; then uninstall exit 0 fi if [[ "${1:-}" == "-h" || "${1:-}" == "--help" ]]; then usage exit 0 fi if [[ ! -x "${RUN_SCRIPT}" ]]; then echo "run script missing: ${RUN_SCRIPT}" >&2 exit 1 fi for blocked in 18006 18007 18008 18009 18010 18011 18012 18013 18014 8081; do if [[ "${PORT}" == "${blocked}" ]]; then echo "refusing stable/production port ${PORT}" >&2 exit 1 fi done mkdir -p "${LAUNCHD_DIR}" "${LOG_ROOT}" cat > "${PLIST}" < Label ${LABEL} ProgramArguments /bin/bash ${RUN_SCRIPT} WorkingDirectory ${ROOT} RunAtLoad KeepAlive StandardOutPath ${LOG_ROOT}/goose-v149.launchd.log StandardErrorPath ${LOG_ROOT}/goose-v149.launchd.err.log EnvironmentVariables PATH /opt/homebrew/bin:/opt/homebrew/opt/node@24/bin:/usr/local/bin:/usr/bin:/bin GOOSE_V149_ALLOW_REAL_LLM 1 GOOSE_V149_PORT ${PORT} GOOSE_SERVER__SECRET_KEY local-dev-secret GOOSE_V149_RUNTIME_ROOT ${LOG_ROOT} EOF plutil -lint "${PLIST}" >/dev/null launchctl bootout "${GUI}/${LABEL}" 2>/dev/null || true launchctl bootstrap "${GUI}" "${PLIST}" launchctl enable "${GUI}/${LABEL}" launchctl kickstart -k "${GUI}/${LABEL}" echo "[install-local-goose-v149] installed ${LABEL} on https://127.0.0.1:${PORT}" echo "Verify: curl -sk https://127.0.0.1:${PORT}/status -H 'X-Secret-Key: local-dev-secret'"