#!/bin/bash

echo "=== 启动 inkos (正确方式) ==="
echo "时间: $(date)"
echo ""

BOOK_DIR="/root/.openclaw/workspace/tomato-novel/books/末日重生-开局囤货十亿物资"
CONFIG_FILE="$BOOK_DIR/inkos_config.json"

# 1. 进入书籍目录
cd "$BOOK_DIR" || {
    echo "❌ 错误：无法进入书籍目录"
    exit 1
}

# 2. 检查配置
if [ ! -f "$CONFIG_FILE" ]; then
    echo "❌ 错误：配置文件不存在"
    exit 1
fi

echo "✅ 书籍目录: $BOOK_DIR"
echo "✅ 配置文件: $CONFIG_FILE"
echo ""

# 3. 启动 inkos
echo "3. 启动 inkos..."
nohup inkos up > /tmp/inkos_startup_correct.log 2>&1 &

sleep 5

# 4. 检查进程
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 启动成功"
    echo "✅ PID: $PID"
    echo "✅ 日志: /tmp/inkos_startup_correct.log"
else
    echo "❌ inkos 启动失败"
    echo "查看日志: /tmp/inkos_startup_correct.log"
    exit 1
fi

echo ""
echo "=== inkos 已启动 ==="
echo "📋 当前配置:"
echo "   - 平台: tomato (番茄小说)"
echo "   - 质量关卡: strict (严格)"
echo "   - 自动修复: 启用"
echo ""
echo "🎯 监控命令: bash /root/.openclaw/workspace/inkos_quality_monitor.sh"
echo "🛑 停止命令: pkill -f 'inkos up'"
echo "📊 质量检查: python3 /root/.openclaw/workspace/tomato-novel/scripts/simple_quality_check.py <章节文件>"