#!/bin/bash
# Ezra Self-Check Script
# Runs daily to verify health and generate status report

REPORT_FILE="/root/wizards/ezra/reports/self-check-$(date +%Y%m%d).txt"
mkdir -p /root/wizards/ezra/reports

echo "=== Ezra Self-Check Report ===" > $REPORT_FILE
echo "Date: $(date)" >> $REPORT_FILE
echo "" >> $REPORT_FILE

echo "=== Process Status ===" >> $REPORT_FILE
ps aux | grep -E "hermes|llama-server" | grep -v grep >> $REPORT_FILE
echo "" >> $REPORT_FILE

echo "=== Local LLM Status ===" >> $REPORT_FILE
curl -s http://127.0.0.1:11435/health >> $REPORT_FILE 2>/dev/null || echo "LLM not responding" >> $REPORT_FILE
echo "" >> $REPORT_FILE

echo "=== Skill Count ===" >> $REPORT_FILE
ls /root/.hermes/skills/ | wc -l >> $REPORT_FILE
echo "" >> $REPORT_FILE

echo "=== Config Backups ===" >> $REPORT_FILE
ls -la /root/.hermes/config.yaml* >> $REPORT_FILE
echo "" >> $REPORT_FILE

echo "=== Disk Usage ===" >> $REPORT_FILE
df -h /root >> $REPORT_FILE
echo "" >> $REPORT_FILE

echo "=== Recent Sessions ===" >> $REPORT_FILE
ls -lt /root/.hermes/sessions/ 2>/dev/null | head -5 >> $REPORT_FILE || echo "No sessions directory" >> $REPORT_FILE

echo "Report saved to: $REPORT_FILE"
