feat(review): 新增 /review pre-commit code review slash command

- .claude/commands/review.md: 整合 12 Agent 的 pre-commit review 指令
  + 依 diff 類型路由:critic / db-expert / migration-engineer / tool-expert
  + Phase B 條件觸發 vuln-verifier(critic 發現 🔴 時)
  + ≥10 Python 檔案改派 refactor-specialist 主審
  + 最終判決:BLOCKED / CAUTION / APPROVED

- scripts/tg_notify.sh: Telegram 告警工具
  + 7 個流程節點全部發送告警(啟動/每個 Agent 完成/最終判決)
  + 支援 info/warn/error 三級別 + jq/bash 雙備案解析
  + token 未設定時 exit 0,不阻斷 review 流程

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
ogt
2026-04-22 01:23:57 +08:00
parent 0099543c05
commit a45b61f326
2 changed files with 230 additions and 0 deletions

45
scripts/tg_notify.sh Executable file
View File

@@ -0,0 +1,45 @@
#!/usr/bin/env bash
# scripts/tg_notify.sh — Code Review Telegram 告警工具
# 用法bash scripts/tg_notify.sh <info|warn|error> "<HTML 訊息>"
set -euo pipefail
LEVEL="${1:-info}"
MESSAGE="${2:-}"
TOKEN="${TELEGRAM_BOT_TOKEN:-}"
CHAT_IDS_RAW="${TELEGRAM_CHAT_IDS:-}"
if [[ -z "$TOKEN" ]]; then
echo "[tg_notify] TELEGRAM_BOT_TOKEN 未設定,跳過通知" >&2
exit 0
fi
if [[ -z "$CHAT_IDS_RAW" ]]; then
echo "[tg_notify] TELEGRAM_CHAT_IDS 未設定,跳過通知" >&2
exit 0
fi
case "$LEVEL" in
info) PREFIX="" ;;
warn) PREFIX="⚠️" ;;
error) PREFIX="🚨" ;;
*) PREFIX="📌" ;;
esac
FULL_MSG="${PREFIX} ${MESSAGE}"
# 解析 CHAT_IDS JSON 陣列
if command -v jq &>/dev/null; then
CHAT_IDS=$(echo "$CHAT_IDS_RAW" | jq -r '.[]' 2>/dev/null)
else
CHAT_IDS=$(echo "$CHAT_IDS_RAW" | tr -d '[]" ' | tr ',' '\n')
fi
while IFS= read -r CHAT_ID; do
[[ -z "$CHAT_ID" ]] && continue
curl -s --max-time 10 -X POST \
"https://api.telegram.org/bot${TOKEN}/sendMessage" \
-d "chat_id=${CHAT_ID}" \
--data-urlencode "text=${FULL_MSG}" \
-d "parse_mode=HTML" > /dev/null || \
echo "[tg_notify] 發送到 ${CHAT_ID} 失敗(不阻斷流程)" >&2
done <<< "$CHAT_IDS"