# Edge MCP — regenerate the tools folder when the commit message opts in.
#
# Opt-in only: this runs the analysis agent ONLY when the just-made commit
# message contains the marker `[edge-mcp]`. Every other commit is untouched.
# Output lands as UNCOMMITTED changes to your tools folder (e.g.
# `src/edge-mcp/tools/`) for you to review and commit separately (a post-commit
# hook cannot amend the commit).
#
# Installed/updated by `edge-mcp install-hook`. Do not edit between the markers.
if git log -1 --pretty=%B | grep -q '\[edge-mcp\]'; then
  echo "[edge-mcp] commit marker found — regenerating tools…"
  if [ -x "node_modules/.bin/edge-mcp" ]; then
    node_modules/.bin/edge-mcp generate
    status=$?
  else
    npx --no-install edge-mcp generate
    status=$?
  fi
  if [ "$status" -eq 0 ]; then
    echo "[edge-mcp] done — review the changes to your tools folder and commit them."
  else
    echo "[edge-mcp] generate FAILED — tools were NOT regenerated (see the error above)."
    echo "[edge-mcp] Your commit is unaffected; re-run 'npx edge-mcp generate' once it's fixed."
  fi
fi
