#!/bin/bash # PKM Toolbox — start the local dev server on this Mac. # # How to use: double-click this file in Finder. macOS will open it in Terminal, # ask permission once, and then the launchd job is loaded. From then on the # merged app at http://localhost:8000/ comes up at every login automatically. # # This file is downloaded by the cloud (production) Settings tab when local # dev is detected as not running. It's deliberately small + self-contained. set -e REPO="/Volumes/satopkm/justinsato/Projects/ACTIVE/02-pkm.cleaner.engine" PLIST_SRC="$REPO/utils/launchd/com.justinsato.pkl.console.plist" PLIST_DST="$HOME/Library/LaunchAgents/com.justinsato.pkl.console.plist" echo "=== PKM Toolbox local launcher ===" if [ ! -d "$REPO" ]; then echo "✗ Repo not found at $REPO" echo " Plug in the satopkm SSD and re-run this file." read -n 1 -s -r -p "Press any key to close…" exit 1 fi # Copy plist into LaunchAgents if it isn't there or is stale. mkdir -p "$HOME/Library/LaunchAgents" if [ ! -f "$PLIST_DST" ] || ! cmp -s "$PLIST_SRC" "$PLIST_DST"; then echo "→ Installing LaunchAgent at $PLIST_DST" cp "$PLIST_SRC" "$PLIST_DST" fi # Unload first to ignore any stale state, then load fresh. launchctl unload "$PLIST_DST" 2>/dev/null || true launchctl load "$PLIST_DST" # Wait up to 10s for the server to come up. for i in $(seq 1 20); do if curl -s --max-time 1 http://127.0.0.1:8000/api/feature-flags > /dev/null 2>&1; then echo "✓ Local server up at http://localhost:8000/" # Open the page in the default browser. open "http://localhost:8000/" 2>/dev/null || true echo "" echo "It will auto-start on every login. To stop it:" echo " launchctl unload $PLIST_DST" read -n 1 -s -r -p "Press any key to close…" exit 0 fi sleep 0.5 done echo "✗ Server didn't come up within 10s. Check logs:" echo " tail -30 /tmp/pkl_console.err" read -n 1 -s -r -p "Press any key to close…" exit 1