peppa/scripts/install-launchd.sh
Асель 9cf0d53303 Add Telegram bot: pairing, durable outbox, answers from buttons and replies
- bot: own Bot API client, long polling with persisted offset, updates
  claimed before acting (no replay after restart), outbox with retries
  (429 retry_after, 5xx), /start pairing code (hashed, single use, 10 min),
  only the paired chat/user is served
- PM questions rendered per kind: approve button / reply to reject,
  option buttons, allow/always/deny, alerts with continue or resume/stop;
  messages are closed with who answered what, incl. terminal answers
- stopping/resuming a session expires its open questions
- CLI: peppa telegram pair|status|unpair; launchd agent for the bot
- testkit: mock-telegram + 11 bot journeys (32 e2e tests, all green)
- fix: keep the tmux server alive when empty (exit-empty off) — a new
  session could die with a server shutting down after the last kill
- fix: test env must load before runner modules (no leaks to real tmux)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 20:26:58 +05:00

56 lines
2.3 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"
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></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