#!/usr/bin/env bash
# 树修复管线：检测 + VLM 重生成 + 校验 + Q&A 补全
#
# 用法:
#   bash scripts/repair_trees.sh                    # 默认 16 并发续跑
#   bash scripts/repair_trees.sh --dry-run           # 仅检测不修复
#   bash scripts/repair_trees.sh --reaggregate-all   # 强制全量重聚合
#   CONCURRENCY=8 bash scripts/repair_trees.sh       # 自定义并发数
#
# 日志输出:
#   stderr → 终端实时显示
#   logs/repair_trees.log → 完整日志（自动 rotation 50MB）
#   logs/repair_telemetry.db → LLM/VLM 调用遥测
#   logs/repair_progress.json → 断点续跑进度

set -euo pipefail

CONCURRENCY="${CONCURRENCY:-16}"

# shellcheck source=/dev/null
source "$(conda info --base)/etc/profile.d/conda.sh"
conda activate Video-Tree-TRM

python tools/repair_trees.py \
    --videos-dir store/videos \
    --srt-dir data/Video-MME/subtitle \
    --questions-dir store/questions/benchmarks/Video-MME \
    --concurrency "$CONCURRENCY" \
    "$@"
