veritas-kanban/scripts/dev-watchdog.sh
Brad Groux eeb11ba219 feat(US-1600): Complete SOP Sprint + fix GH-86 & GH-87
Documentation (8 new files in docs/):
- GETTING-STARTED.md: 5-min quickstart, BoardKit insights, sanity checks
- SOP-agent-task-workflow.md: Full lifecycle (claim → work → complete)
- SOP-sprint-planning.md: Epic → sprint → task hierarchy + estimation
- SOP-multi-agent-orchestration.md: PM + worker roles, handoff patterns
- SOP-cross-model-code-review.md: Claude ↔ GPT gate, checklist, RF-002 ref
- BEST-PRACTICES.md: 10 DOs + 10 DON'Ts based on real usage
- EXAMPLES-agent-workflows.md: 6 copy/pasteable recipes (feature, bug fix, docs, audit, content, research)
- TIPS-AND-TRICKS.md: CLI shortcuts, keyboard shortcuts, integrations (MCP, git worktrees, Obsidian)
- README.md: Added 'Documentation Map' linking all new docs

Bug Fixes:
- fix(GH-86): BulkActionsBar now handles archive errors gracefully
  * Per-task error tracking (replaces Promise.all)
  * Toast notifications on success/partial/failure
  * Logs individual failures to console

- fix(GH-87): Sidebar metrics now stay in sync with board state
  * Invalidate metrics cache when task status changes
  * Prevents up-to-30s lag in sidebar counts
  * Preserves timer state during mutations

Scripts:
- scripts/dev-clean.sh: Added explicit pnpm path resolution for launchd
- scripts/dev-watchdog.sh: Fixed restart storm prevention + pnpm path

BREAKING: None
TESTING:
- Manual: Bulk archive Done column tasks, verify toasts appear
- Manual: Move tasks between columns, verify sidebar counts update <2s
- Unit: Consider regression tests for metrics invalidation
2026-02-04 08:18:01 -06:00

64 lines
2 KiB
Bash
Executable file

#!/usr/bin/env bash
set -euo pipefail
# Simple dev watchdog:
# - polls http://localhost:${PORT}/api/health
# - if unhealthy for N consecutive checks, runs `pnpm dev:clean`
#
# Intended for macOS launchd or manual terminal use.
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
PORT="${PORT:-3001}"
INTERVAL_SECONDS="${WATCHDOG_INTERVAL_SECONDS:-30}"
FAIL_THRESHOLD="${WATCHDOG_FAIL_THRESHOLD:-3}"
# launchd sessions often have a minimal PATH; resolve pnpm explicitly.
PNPM_BIN="$(command -v pnpm || true)"
if [[ -z "${PNPM_BIN}" && -x "/opt/homebrew/bin/pnpm" ]]; then
PNPM_BIN="/opt/homebrew/bin/pnpm"
fi
if [[ -z "${PNPM_BIN}" ]]; then
echo "[dev-watchdog] ERROR: pnpm not found in PATH and /opt/homebrew/bin/pnpm missing" >&2
exit 1
fi
URL="http://localhost:${PORT}/api/health"
fails=0
LOCK_FILE="${WATCHDOG_LOCK_FILE:-/tmp/veritas-kanban-dev-clean.lock}"
echo "[dev-watchdog] repo=${REPO_ROOT}"
echo "[dev-watchdog] url=${URL} interval=${INTERVAL_SECONDS}s threshold=${FAIL_THRESHOLD}"
while true; do
http_code="$(curl -s -o /dev/null -w '%{http_code}' "${URL}" || true)"
if [[ "${http_code}" == "200" ]]; then
fails=0
else
fails=$((fails+1))
echo "[dev-watchdog] health check failed (http=${http_code}) fails=${fails}/${FAIL_THRESHOLD}"
fi
if [[ "${fails}" -ge "${FAIL_THRESHOLD}" ]]; then
echo "[dev-watchdog] unhealthy threshold reached -> restarting via scripts/dev-clean.sh"
# Prevent restart storms (e.g., if health endpoint is down for an extended period)
if [[ -f "${LOCK_FILE}" ]]; then
lock_pid="$(cat "${LOCK_FILE}" 2>/dev/null || true)"
if [[ -n "${lock_pid}" ]] && kill -0 "${lock_pid}" 2>/dev/null; then
echo "[dev-watchdog] restart already in progress (pid=${lock_pid}); waiting"
fails=0
sleep "${INTERVAL_SECONDS}"
continue
fi
fi
cd "${REPO_ROOT}"
# Run dev-clean in background so the watchdog can keep monitoring.
(bash "${REPO_ROOT}/scripts/dev-clean.sh") &
echo $! > "${LOCK_FILE}"
fails=0
fi
sleep "${INTERVAL_SECONDS}"
done