#!/bin/bash
echo "=== inkos 质量监控 ==="
echo "时间: $(date)"
echo ""

# 检查进程
if ps aux | grep "inkos up" | grep -v grep > /dev/null; then
    PID=$(ps aux | grep "inkos up" | grep -v grep | awk '{print $2}')
    echo "✅ inkos 运行中 (PID: $PID)"
else
    echo "❌ inkos 未运行"
    echo "使用启动命令: bash /root/.openclaw/workspace/start_inkos_with_quality.sh"
    exit 1
fi

# 检查配置
CONFIG_FILE="/root/.openclaw/workspace/tomato-novel/books/末日重生-开局囤货十亿物资/inkos_config.json"
if [ -f "$CONFIG_FILE" ]; then
    echo "✅ 质量配置已加载"
else
    echo "❌ 质量配置未找到"
fi

# 检查最新章节
LATEST_CHAPTER=$(ls -t /root/.openclaw/workspace/tomato-novel/books/末日重生-开局囤货十亿物资/chapters/*.md 2>/dev/null | grep -v "_fixed\|_备份\|_修复\|backup" | head -1)
if [ -f "$LATEST_CHAPTER" ]; then
    CHAPTER_NAME=$(basename "$LATEST_CHAPTER")
    CHAPTER_SIZE=$(wc -c < "$LATEST_CHAPTER")
    echo "📖 最新章节: $CHAPTER_NAME ($CHAPTER_SIZE 字符)"
    
    # 检查质量
    echo ""
    echo "🔍 质量检查:"
    python3 /root/.openclaw/workspace/tomato-novel/scripts/simple_quality_check.py "$LATEST_CHAPTER" | tail -15
else
    echo "📖 未找到章节文件"
fi

# 检查日志
LOG_FILE="/tmp/inkos_quality_startup.log"
if [ -f "$LOG_FILE" ]; then
    echo ""
    echo "📝 最近日志:"
    tail -5 "$LOG_FILE"
fi
