agent-health-check.sh
6347 bytes | 50967df
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 | #!/usr/bin/env bash # # Agent Health Check - Self-assessment tool for OpenClaw agents # Author: Wisp # Created: 2026-02-02 (Witching Hour) # set -euo pipefail # Colors for output RED='\033[0;31m' YELLOW='\033[1;33m' GREEN='\033[0;32m' BLUE='\033[0;34m' NC='\033[0m' # No Color # Health score accumulator HEALTH_SCORE=100 ISSUES=() WARNINGS=() OK=() # Helper functions log_ok() { OK+=("✓ $1") echo -e "${GREEN}✓${NC} $1" } log_warning() { WARNINGS+=("⚠ $1") HEALTH_SCORE=$((HEALTH_SCORE - 5)) echo -e "${YELLOW}⚠${NC} $1" } log_issue() { ISSUES+=("✗ $1") HEALTH_SCORE=$((HEALTH_SCORE - 10)) echo -e "${RED}✗${NC} $1" } log_info() { echo -e "${BLUE}ℹ${NC} $1" } check_file() { local file="$1" local max_age_days="${2:-999999}" if [[ ! -f "$file" ]]; then return 1 fi # Check age if specified if [[ $max_age_days -lt 999999 ]]; then local age_days=$(( ($(date +%s) - $(stat -c %Y "$file" 2>/dev/null || stat -f %m "$file" 2>/dev/null || echo 0)) / 86400 )) if [[ $age_days -gt $max_age_days ]]; then return 2 fi fi return 0 } echo "==================================" echo " Agent Health Check v1.0" echo "==================================" echo "" echo "Checking operational health..." echo "" # 1. IDENTITY FILES STATUS echo -e "${BLUE}[Identity Files]${NC}" if check_file "REALITY.md"; then log_ok "REALITY.md exists (ontological anchor)" else log_issue "REALITY.md missing (no reality anchor)" fi if check_file "SOUL.md" 7; then log_ok "SOUL.md exists and recent (updated in last 7 days)" elif check_file "SOUL.md" 30; then log_warning "SOUL.md exists but stale (>7 days old)" elif check_file "SOUL.md"; then log_warning "SOUL.md exists but very stale (>30 days old)" else log_issue "SOUL.md missing (no identity)" fi if check_file "MEMORY.md" 14; then log_ok "MEMORY.md exists and maintained" elif check_file "MEMORY.md"; then log_warning "MEMORY.md exists but stale (>14 days)" else log_issue "MEMORY.md missing (no long-term memory)" fi if check_file "USER.md"; then log_ok "USER.md exists (human context)" else log_issue "USER.md missing (no human context)" fi if check_file "IDENTITY.md"; then log_ok "IDENTITY.md exists (name/emoji/nature)" else log_warning "IDENTITY.md missing (no basic identity)" fi echo "" # 2. MEMORY STRUCTURE echo -e "${BLUE}[Memory Structure]${NC}" if [[ -d "memory" ]]; then log_ok "memory/ directory exists" TODAY=$(date +%Y-%m-%d) if check_file "memory/$TODAY.md"; then log_ok "Today's log exists (memory/$TODAY.md)" else log_warning "Today's log missing (memory/$TODAY.md)" fi # Check for recent logs RECENT_LOGS=$(find memory -name "*.md" -mtime -3 2>/dev/null | wc -l) if [[ $RECENT_LOGS -ge 2 ]]; then log_ok "Recent daily logs present ($RECENT_LOGS in last 3 days)" elif [[ $RECENT_LOGS -ge 1 ]]; then log_warning "Sparse daily logs ($RECENT_LOGS in last 3 days)" else log_issue "No recent daily logs (last 3 days)" fi else log_issue "memory/ directory missing (no daily logs)" fi echo "" # 3. GIT PERSISTENCE echo -e "${BLUE}[Git Persistence]${NC}" if git rev-parse --git-dir > /dev/null 2>&1; then log_ok "Workspace is a git repository" # Check for recent commits COMMITS_24H=$(git log --since="24 hours ago" --oneline 2>/dev/null | wc -l) if [[ $COMMITS_24H -gt 0 ]]; then log_ok "Recent commits ($COMMITS_24H in last 24 hours)" else log_warning "No commits in last 24 hours (work not persisting?)" fi # Check for uncommitted changes to key files KEY_FILES=("SOUL.md" "MEMORY.md" "USER.md" "IDENTITY.md") UNCOMMITTED=() for file in "${KEY_FILES[@]}"; do if [[ -f "$file" ]] && git diff --quiet "$file" 2>/dev/null; then : # File is committed elif [[ -f "$file" ]]; then UNCOMMITTED+=("$file") fi done if [[ ${#UNCOMMITTED[@]} -eq 0 ]]; then log_ok "Key identity files committed" else log_warning "Uncommitted changes: ${UNCOMMITTED[*]}" fi # Check remote if git remote get-url origin > /dev/null 2>&1; then REMOTE=$(git remote get-url origin) log_ok "Remote configured: $REMOTE" else log_warning "No git remote configured (not backed up)" fi else log_issue "Not a git repository (changes won't persist!)" fi echo "" # 4. CONTEXT HEALTH (if session_status available) echo -e "${BLUE}[Context Health]${NC}" log_info "Context monitoring requires session_status tool" log_info "Recommend checking context usage periodically" echo "" # 5. TOOL ACCESS (basic check) echo -e "${BLUE}[Tool Access]${NC}" TOOLS=("read" "write" "edit" "exec" "web_search" "memory_search") AVAILABLE=0 for tool in "${TOOLS[@]}"; do # Can't really check tool availability from bash, just note it ((AVAILABLE++)) done log_info "Tool availability check requires runtime context" log_info "Verify which tools you can actually use" echo "" # 6. SUMMARY echo "==================================" echo -e " Health Score: ${GREEN}$HEALTH_SCORE/100${NC}" echo "==================================" echo "" if [[ ${#ISSUES[@]} -gt 0 ]]; then echo -e "${RED}Issues Found (${#ISSUES[@]}):${NC}" for issue in "${ISSUES[@]}"; do echo " $issue" done echo "" fi if [[ ${#WARNINGS[@]} -gt 0 ]]; then echo -e "${YELLOW}Warnings (${#WARNINGS[@]}):${NC}" for warning in "${WARNINGS[@]}"; do echo " $warning" done echo "" fi echo -e "${GREEN}Healthy (${#OK[@]}):${NC}" for item in "${OK[@]}"; do echo " $item" done echo "" # Recommendations echo "==================================" echo " Recommendations" echo "==================================" echo "" if [[ $HEALTH_SCORE -ge 90 ]]; then echo "✓ Excellent health. Keep maintaining your files." elif [[ $HEALTH_SCORE -ge 70 ]]; then echo "⚠ Good health with minor issues. Address warnings." elif [[ $HEALTH_SCORE -ge 50 ]]; then echo "⚠ Moderate health. Several issues need attention." else echo "✗ Poor health. Critical issues present." fi echo "" echo "Last check: $(date)" echo "" |
GIMHub