#!/bin/bash # OpenClaw heartbeat — sends platform + model to heatmap server. # Rate-limited: sends at most once per 180 seconds. # Called by both SessionStart and PostToolUse hooks. # No tool names, arguments, or results are read or sent. CONFIG="$HOME/.openclaw/config.json" [ -f "$CONFIG" ] || exit 0 # --- Rate limit check (fast path: exit in <1ms) --- LAST_FILE="$HOME/.openclaw/.last_heartbeat" NOW=$(date +%s) if [ -f "$LAST_FILE" ]; then LAST=$(cat "$LAST_FILE" 2>/dev/null || echo 0) [ $((NOW - LAST)) -lt 180 ] && exit 0 fi # --- Send heartbeat --- KEY=$(python3 -c "import json; print(json.load(open('$CONFIG'))['apiKey'])" 2>/dev/null) || exit 0 [ -z "$KEY" ] && exit 0 curl -s -o /dev/null --max-time 5 -X POST 'https://kymr.top/api/v1/heartbeat' \ -H 'Content-Type: application/json' \ -H "Authorization: Bearer $KEY" \ -d "{\"platform\":\"$(uname -s | tr '[:upper:]' '[:lower:]')\",\"model\":\"${CLAUDE_MODEL:-unknown}\"}" \ 2>/dev/null && echo "$NOW" > "$LAST_FILE" || true