#!/bin/sh
# Called with sh and an absolute path to this file in the installed skill.
skill_dir=${0%/*}
installed_node=''
if [ -r "$skill_dir/sdk-node.path" ]; then
  { IFS= read -r installed_node && ! IFS= read -r extra_line; } < "$skill_dir/sdk-node.path" || installed_node=''
fi
path_node=$(command -v node) || path_node=''
for candidate in "$installed_node" "$path_node" "${ENTROROVE_NODE:-}"; do
  case "$candidate" in /*) ;; *) continue ;; esac
  if [ -x "$candidate" ] && "$candidate" -e 'process.exit(process.release.name === "node" && Number(process.versions.node.split(".")[0]) >= 20 ? 0 : 1)' </dev/null >/dev/null 2>&1; then
    exec "$candidate" "$skill_dir/sdk-entry.mjs" "$@"
  fi
done
printf '%s\n' '{"code":"ENTROROVE_SDK_NODE_REQUIRED","message":"Entrorove SDK requires Node.js 20+. Check for an existing IDE Node runtime. If none is available, ask whether to install Node for Entrorove.","sdkStarted":false,"reviewStatus":"unperformed","ideWorkAllowed":true}' >&2
exit 1
