[["$node_major"=~ ^[0-9]+$ &&"$node_minor"=~ ^[0-9]+$ ]]|| fail "the active Node.js version could not be read. Check that node works and is on PATH, then retry."
release_json="$(curl -fsSL --proto '=https' --tlsv1.2 --retry 3 -H 'Accept: application/vnd.github+json'"https://api.github.com/repos/$REPOSITORY/releases/latest")"|| fail "the latest REA release could not be resolved. Check network access or pass --version VERSION, then retry."
tag="$(printf'%s'"$release_json"| node -e 'let s="";process.stdin.on("data",c=>s+=c).on("end",()=>{const v=JSON.parse(s).tag_name;if(typeof v!=="string")process.exit(1);process.stdout.write(v)})' 2>/dev/null)"|| fail "the release response was invalid. Retry later or pass --version VERSION."
[["$tag"=~ ^rea-agents-([0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?)$ ]]|| fail "the latest release tag was invalid. Retry later or pass --version VERSION."
npm install --global "${prefix_args[@]}""$PACKAGE@$version"|| fail "npm could not install REA. Check registry access and npm permissions, then retry."
[[ -x "$install_bin"]]|| fail "npm completed without installing the rea command. Check the npm global bin directory and PATH, then retry."
installed_version="$("$install_bin" --version 2>/dev/null | tr -d '[:space:]')"|| fail "the installed REA version could not be read. Reinstall the requested version, then retry."
[["$installed_version"=="$version"]]|| fail "installed version $installed_version does not match $version. Reinstall the requested version, then retry."