peppa/scripts/install-launchd.sh
Асель 8dc82859c7 PEP-36 stage 1: run Peppa with Node 26 type stripping instead of tsx
- tsconfig: erasableSyntaxOnly + verbatimModuleSyntax; parameter properties
  rewritten (BugsinkError, GiteaError, GiteaClient, OAuthError, TelegramError,
  TelegramApi, MockGitea)
- bin wrappers (peppa, peppa-mcp, peppa-hook, peppa-bot, testkit mocks,
  peppa-dev): `node --import scripts/lib/require-node.mjs` (clear error on
  Node < 26, PEPPA_NODE overrides the binary); package scripts and tests on
  `node` / `node --test`; tsx removed
- install-launchd.sh pins PEPPA_NODE (checked absolute path) in the plists
- fix a race the faster hooks exposed: the prompt hook answered every pending
  question, including a PM question raised after Peppa itself pasted text
  into the terminal; sendToSession now logs `input_sent` and the hook only
  answers questions older than that input
- change pep-36-lightweight-stack: stage 1 done, hook start numbers

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-13 16:51:22 +05:00

64 lines
2.8 KiB
Bash
Executable File

#!/usr/bin/env bash
# Installs Peppa's launchd agents (start at login, restart on crash):
# quest.telecom.peppa.watchdog — session watchdog under caffeinate -i (no idle sleep)
# quest.telecom.peppa.web — Next.js platform on :3100 (needs `pnpm --filter @peppa/web build`)
# quest.telecom.peppa.bot — Telegram bot (TELEGRAM_BOT_TOKEN in .env)
# Usage: scripts/install-launchd.sh [watchdog] [web] [bot] (default: all)
# Remove: launchctl bootout gui/$(id -u)/<label> && rm ~/Library/LaunchAgents/<label>.plist
set -euo pipefail
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
mkdir -p "$HOME/Library/LaunchAgents" "$HOME/.peppa"
PATH_ENV="$HOME/.local/bin:/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin"
# Bot and watchdog run TypeScript straight from source with Node's type stripping (PEP-36):
# pin the Node that was checked here, so launchd does not depend on what PATH finds later.
NODE_BIN="${PEPPA_NODE:-$(PATH="$PATH_ENV" command -v node || true)}"
[ -x "$NODE_BIN" ] || { echo "node not found (set PEPPA_NODE)" >&2; exit 1; }
"$NODE_BIN" --import "$ROOT/scripts/lib/require-node.mjs" -e 0 || exit 1
install_agent() { # label log workdir args...
local label=$1 log=$2 workdir=$3; shift 3
local plist="$HOME/Library/LaunchAgents/$label.plist" args=""
for a in "$@"; do args+=" <string>$a</string>"$'\n'; done
cat > "$plist" <<PLIST
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key><string>$label</string>
<key>ProgramArguments</key>
<array>
$args </array>
<key>WorkingDirectory</key><string>$workdir</string>
<key>EnvironmentVariables</key>
<dict>
<key>PATH</key><string>$PATH_ENV</string>
<key>PEPPA_NODE</key><string>$NODE_BIN</string>
</dict>
<key>RunAtLoad</key><true/>
<key>KeepAlive</key><true/>
<key>StandardOutPath</key><string>$HOME/.peppa/$log</string>
<key>StandardErrorPath</key><string>$HOME/.peppa/$log</string>
</dict>
</plist>
PLIST
launchctl bootout "gui/$(id -u)/$label" 2>/dev/null || true
launchctl bootstrap "gui/$(id -u)" "$plist"
echo "installed $label (log: ~/.peppa/$log)"
}
SERVICES=("$@")
[ ${#SERVICES[@]} -eq 0 ] && SERVICES=(watchdog web bot)
for s in "${SERVICES[@]}"; do
case "$s" in
watchdog)
install_agent quest.telecom.peppa.watchdog watchdog.log "$ROOT" \
/usr/bin/caffeinate -i "$ROOT/packages/cli/bin/peppa" watchdog ;;
web)
install_agent quest.telecom.peppa.web web.log "$ROOT/apps/web" \
/bin/bash -c "set -a; . '$ROOT/.env'; set +a; exec '$ROOT/apps/web/node_modules/.bin/next' start -p 3100" ;;
bot)
install_agent quest.telecom.peppa.bot bot.log "$ROOT" "$ROOT/apps/bot/bin/peppa-bot" ;;
*) echo "unknown service $s" >&2; exit 1 ;;
esac
done