feat(dev): add optional file backup watcher to hot-dev

When scripts/watch-backup.sh exists (gitignored, local only), hot-dev
automatically starts a file watcher that backs up source files on every
save to ~/.pulse-backups/. Protects against accidental data loss from
git checkout or other mishaps, regardless of what tool makes the change.
This commit is contained in:
rcourtman 2026-01-22 14:25:21 +00:00
parent 1b2885c484
commit c743bd2c30
2 changed files with 26 additions and 1 deletions

8
.gitignore vendored
View file

@ -196,3 +196,11 @@ measure_sessions.sh
# SQLite temp files
*.db-shm
*.db-wal
# Auto-backup logs
# Local backup scripts (not committed)
scripts/watch-backup.sh
scripts/auto-backup.sh
scripts/safe-checkout.sh
BACKUP_SYSTEM.md

View file

@ -5,6 +5,7 @@
# - Go backend with auto-rebuild on file changes (via inotifywait)
# - Vite frontend dev server with HMR
# - Auto-detection of pulse-pro module for Pro features
# - File backup watcher (if scripts/watch-backup.sh exists)
#
# Environment Variables:
# HOT_DEV_USE_PROD_DATA=true Use /etc/pulse for data (sessions, config, etc.)
@ -575,14 +576,30 @@ cleanup() {
kill "${VITE_PID}" 2>/dev/null || true
fi
# Kill file backup watcher
if [[ -n ${BACKUP_WATCHER_PID:-} ]] && kill -0 "${BACKUP_WATCHER_PID}" 2>/dev/null; then
kill "${BACKUP_WATCHER_PID}" 2>/dev/null || true
fi
# Fallback cleanup
pkill -f "inotifywait.*pulse" 2>/dev/null || true
pkill -f "fswatch.*pulse" 2>/dev/null || true
pkill -f "watch-backup.sh" 2>/dev/null || true
log_info "Hot-dev stopped."
}
trap cleanup INT TERM EXIT
# --- Start File Backup Watcher (optional) ---
BACKUP_SCRIPT="${ROOT_DIR}/scripts/watch-backup.sh"
if [[ -x "${BACKUP_SCRIPT}" ]]; then
log_info "Starting file backup watcher..."
"${BACKUP_SCRIPT}" > /tmp/pulse-watch-backup.log 2>&1 &
BACKUP_WATCHER_PID=$!
log_info "File backups: ~/.pulse-backups (PID: ${BACKUP_WATCHER_PID})"
fi
# --- Start Frontend ---
log_info "Starting frontend with hot-reload on port ${FRONTEND_DEV_PORT}..."