#!/usr/bin/env sh
# Pre-commit guard: typecheck the MCP server whenever its TS sources are part
# of the commit. Stops type breakage from silently shipping (the bug that bit
# us during MCP stabilization, back when the server lived at packages/hayba).

set -e

cd "$(git rev-parse --show-toplevel)"

# Only bother when hayba-mcp TS sources are part of the commit.
if ! git diff --cached --name-only | grep -qE '^mcp-tools/hayba-mcp/(src/|tsconfig\.json|package\.json)'; then
  exit 0
fi

echo "pre-commit: hayba-mcp TS changed — typechecking"
cd mcp-tools/hayba-mcp
npx tsc --noEmit
