#!/bin/bash
# Auto-restart wrapper for Claude Task Manager
# Restarts the server when it exits (e.g., when a Claude session kills port 3456)

cd "$(dirname "$0")"
export CTM_HOST="${CTM_HOST:-0.0.0.0}"

while true; do
  node server.js
  EXIT_CODE=$?
  if [ "$EXIT_CODE" -eq 0 ]; then
    echo "  Server exited cleanly. Restarting in 1s..."
  else
    echo "  Server crashed (exit $EXIT_CODE). Restarting in 1s..."
  fi
  sleep 1
done
