#!/usr/bin/env bash

devflow_resolve_node() {
  local plugin_root="${1:-}"
  local marker="${plugin_root}/.devflow-hook-node"
  local candidate=""

  if [ -n "${DEVFLOW_HOOK_NODE:-}" ] && [ -x "${DEVFLOW_HOOK_NODE}" ]; then
    printf '%s\n' "${DEVFLOW_HOOK_NODE}"
    return 0
  fi
  if [ -f "$marker" ]; then
    IFS= read -r candidate < "$marker" || candidate=""
    if [ -n "$candidate" ] && [ -x "$candidate" ]; then
      printf '%s\n' "$candidate"
      return 0
    fi
  fi
  candidate="${HOME:-}/.hermes/node/bin/node"
  if [ -x "$candidate" ]; then
    printf '%s\n' "$candidate"
    return 0
  fi
  command -v node 2>/dev/null
}
