#!/bin/bash

echo "=== 第1章重新审核脚本 ==="
echo "开始时间: $(date)"

# 1. 检查第1章文件
CHAPTER1_FILE="/root/.openclaw/workspace/tomato-novel/books/末日重生-开局囤货十亿物资/chapters/0001_冰点记忆.md"
if [ ! -f "$CHAPTER1_FILE" ]; then
    echo "错误：第1章文件不存在"
    exit 1
fi

echo "✅ 第1章文件存在: $CHAPTER1_FILE"
echo "文件大小: $(wc -l < "$CHAPTER1_FILE") 行"

# 2. 检查修复后的内容
echo -e "\n=== 检查修复内容 ==="
echo "前10行内容:"
head -10 "$CHAPTER1_FILE"

# 3. 检查段落结构
echo -e "\n=== 段落结构分析 ==="
python3 -c "
import re
with open('$CHAPTER1_FILE', 'r', encoding='utf-8') as f:
    lines = f.readlines()

paragraphs = []
current_para = []
for line in lines:
    line = line.strip()
    if not line:
        if current_para:
            paragraphs.append(''.join(current_para))
            current_para = []
    else:
        current_para.append(line)
if current_para:
    paragraphs.append(''.join(current_para))

# 统计短段落
short_count = 0
consecutive_short = 0
max_consecutive = 0
current_streak = 0

for i, para in enumerate(paragraphs):
    # 排除标题
    if para.startswith('# '):
        continue
    
    # 统计中文字符
    chinese_chars = len([c for c in para if '\u4e00' <= c <= '\u9fff'])
    other_chars = len(re.findall(r'[a-zA-Z0-9]', para))
    total = chinese_chars + other_chars
    
    if total < 35:
        short_count += 1
        current_streak += 1
        if current_streak > max_consecutive:
            max_consecutive = current_streak
    else:
        current_streak = 0

total_paras = len([p for p in paragraphs if not p.startswith('# ')])
print(f'总段落数: {total_paras}')
print(f'短段落数(<35字): {short_count}')
print(f'短段落比例: {short_count/total_paras*100:.1f}%')
print(f'最长连续短段落: {max_consecutive}')

# 检查爽点关键词
keywords = ['重生', '先知', '优势', '记忆', '未来', '信息差', '囤货', '物资', '安全屋']
found_keywords = []
for para in paragraphs:
    for kw in keywords:
        if kw in para and kw not in found_keywords:
            found_keywords.append(kw)

print(f'爽点关键词找到: {len(found_keywords)}/{len(keywords)}')
print(f'找到的关键词: {found_keywords}')
"

# 4. 启动 inkos 进行审核
echo -e "\n=== 启动 inkos 审核 ==="
echo "注意：inkos 需要重新启动，审核结果会在日志中显示"

# 5. 建议手动检查项
echo -e "\n=== 手动检查建议 ==="
echo "1. 爽点是否充分：重生优势是否明确展现"
echo "2. 情绪弧线：主角情绪变化是否鲜明"
echo "3. 读者期待：是否建立明确的时间紧迫感"
echo "4. 配角塑造：房东王姐等配角是否立体"
echo "5. 段落结构：是否有过多短段落"

echo -e "\n=== 脚本完成 ==="
echo "结束时间: $(date)"