Files
openclaw-backups/scripts/heartbeat-model-guard.sh

41 lines
1.4 KiB
Bash
Executable File

#!/bin/bash
# Heartbeat Model Guard - Ensures heartbeat stays on free models
CONFIG_FILE="/home/openclaw/.openclaw/openclaw.json"
FREE_MODEL="kilocode/moonshotai/kimi-k2.5:free"
FALLBACK_MODEL="kilocode/minimax/minimax-m2.5:free"
# Check if jq is available
if ! command -v jq &> /dev/null; then
echo "ERROR: jq not installed"
exit 1
fi
# Get current heartbeat model
CURRENT_MODEL=$(jq -r '.agents.defaults.heartbeat.model // empty' "$CONFIG_FILE" 2>/dev/null)
if [ -z "$CURRENT_MODEL" ]; then
echo "ERROR: Could not read heartbeat model from config"
exit 1
fi
# Check if current model is a free kilocode model
if [[ "$CURRENT_MODEL" == *":free"* ]] || [[ "$CURRENT_MODEL" == *"/free"* ]]; then
echo "OK: heartbeat model already correct ($CURRENT_MODEL)."
exit 0
fi
# Model is not free - need to fix
echo "FIXING: heartbeat model is '$CURRENT_MODEL' - changing to free model..."
# Update to free model
jq --arg model "$FREE_MODEL" '.agents.defaults.heartbeat.model = $model' "$CONFIG_FILE" > "${CONFIG_FILE}.tmp" && mv "${CONFIG_FILE}.tmp" "$CONFIG_FILE"
# Restart gateway
if systemctl --user restart openclaw-gateway 2>/dev/null || sudo systemctl restart openclaw-gateway 2>/dev/null; then
echo "FIXED: heartbeat model corrected to $FREE_MODEL and gateway restarted."
else
echo "ERROR: Updated config but failed to restart gateway."
exit 1
fi