#!/usr/bin/env bash set -euo pipefail # Dev safety rail: kill stale VK dev runners + free ports, then restart. # # Goals: # - Prevent “port capture” (something else bound to :3001 / :3000) # - Prevent duplicate watchers (tsx watch / vite / concurrently) # - Be SAFE: only target this repo’s processes + the configured ports REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" # 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-clean] ERROR: pnpm not found in PATH and /opt/homebrew/bin/pnpm missing" >&2 exit 1 fi SERVER_PORT="${PORT:-3001}" WEB_PORT="${WEB_PORT:-3000}" echo "[dev-clean] repo=${REPO_ROOT}" echo "[dev-clean] ports: server=${SERVER_PORT} web=${WEB_PORT}" kill_listeners() { local port="$1" local pids pids="$(lsof -nP -iTCP:"${port}" -sTCP:LISTEN -t 2>/dev/null || true)" if [[ -n "${pids}" ]]; then echo "[dev-clean] killing listeners on :${port}: ${pids}" # shellcheck disable=SC2086 kill ${pids} 2>/dev/null || true fi } kill_repo_watchers() { python3 - <