#!/usr/bin/env bash
# Start the LensMCP dev cluster gateway for the project Claude Code is open in.
# The gateway reads every project.json `cluster` decl, launches each app/service under
# its host on :443, and serves the per-project lens dashboard at lensmcp.local/<key>/.
set -euo pipefail

PROJECT_DIR="${CLAUDE_PROJECT_DIR:-$PWD}"
BIN="$PROJECT_DIR/node_modules/lensmcp/bin.js"

if [ ! -f "$BIN" ]; then
  echo "✗ lensmcp is not installed in $PROJECT_DIR (no node_modules/lensmcp/bin.js)." >&2
  echo "  Install it as a dev dependency:  yarn add -D lensmcp" >&2
  echo "  (the gateway is a dev-only tool — never a prod/CI dependency)." >&2
  exit 1
fi

exec node "$BIN" gateway start --cwd "$PROJECT_DIR"
