#!/usr/bin/env bash
# theo post-commit hook

SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
ENV_FILE="$SCRIPT_DIR/.theo-env.sh"

# 加载环境变量（claude 路径、前置 hooksPath）
[[ -f "$ENV_FILE" ]] && source "$ENV_FILE"

# --- 链式调用前置 hook ---
if [[ -n "${THEO_PREVIOUS_HOOKS_PATH:-}" && -x "${THEO_PREVIOUS_HOOKS_PATH}/post-commit" ]]; then
  "${THEO_PREVIOUS_HOOKS_PATH}/post-commit" || true
fi

# --- 后台启动 code review（不阻塞 commit）---
if [[ -x "${THEO_CLAUDE_PATH:-}" ]]; then
  REPO_PATH="$(git rev-parse --show-toplevel 2>/dev/null)"
  nohup "$SCRIPT_DIR/theo-runner" "$REPO_PATH" &>/dev/null &
  disown
fi
