#!/usr/bin/env bash # Claude Code Stop hook: when app sources are newer than the installed # AppImage, rebuild and reinstall it so the desktop launcher runs the latest code. set -uo pipefail cd "$(dirname "$0")/../.." # Set when Claude is already continuing because of this hook; don't loop. retry=$(jq -r '.stop_hook_active // false' 2>/dev/null || echo false) bin="$HOME/.local/bin/voipms-desktop.AppImage" changed=$(find src resources package.json electron.vite.config.ts -newer "$bin" -type f -print -quit 2>/dev/null) [ -f "$bin" ] && [ -z "$changed" ] && exit 0 log=$(mktemp -t voipms-install.XXXXXX.log) if npm run install-desktop >"$log" 2>&1; then msg="Rebuilt and reinstalled bubble. Quit and reopen the app to use the new version." if pgrep -f "$bin" >/dev/null; then msg="$msg (It's running now, so restart it.)"; fi printf '{"systemMessage": "%s"}\n' "$msg" else # Exit 2 hands the error back to Claude so it can fix the build. echo "Automatic rebuild (npm run install-desktop) failed; log: $log" >&2 tail -30 "$log" >&2 [ "$retry" = true ] && exit 1 exit 2 fi