#!/usr/bin/env bash # Changelog sync guard — stop hook (bash 版) input=$(cat) # === 豁免检查 1:环境变量跳过标志 === if [ -n "$CURSOR_SKIP_CHANGELOG" ]; then echo '{}'; exit 0 fi # === 豁免检查 2:从 stdin 解析 composer_mode === mode=$(echo "$input" | python3 -c "import sys,json; print(json.load(sys.stdin).get('composer_mode',''))" 2>/dev/null || echo "") if [ -n "$mode" ] && [ "$mode" != "agent" ]; then echo '{}'; exit 0 fi # === 豁免检查 3:从 stdin 文本匹配 debug 上下文关键词 === if echo "$input" | grep -qiE '"mode"\s*:\s*"debug"|debug[\s_-]?mode|Debug Mode'; then echo '{}'; exit 0 fi changelog=".cursor/changelog/changelog-headlines.md" srcDir="art-agent" # === 豁免检查 4:changelog 文件不存在 === if [ ! -f "$changelog" ]; then echo '{}'; exit 0 fi clMtime=$(stat -c %Y "$changelog" 2>/dev/null || stat -f %m "$changelog" 2>/dev/null) # === 豁免检查 5:ack 标记文件足够新 === ackFile=".cursor/changelog/.changelog-ack" if [ -f "$ackFile" ]; then ackMtime=$(stat -c %Y "$ackFile" 2>/dev/null || stat -f %m "$ackFile" 2>/dev/null) if [ "$ackMtime" -ge "$clMtime" ] 2>/dev/null; then echo '{}'; exit 0 fi fi # === 豁免检查 6:stdin 中无文件编辑证据 === if ! echo "$input" | grep -qE 'StrReplace|Write\s*tool|edit_file|file_write|write_to_file|Created file|Modified file|Wrote contents|"tool"\s*:\s*"(str_replace|write|edit)"'; then echo '{}'; exit 0 fi # === 核心检查:是否有源文件比 changelog 更新 === newerFile=$(find "$srcDir" -type f \( -name "*.py" -o -name "*.tsx" -o -name "*.ts" -o -name "*.css" \) \ ! -path "*/node_modules/*" ! -path "*/.next/*" ! -path "*/__pycache__/*" ! -path "*/venv/*" \ -newer "$changelog" -print -quit 2>/dev/null) if [ -n "$newerFile" ]; then fname=$(basename "$newerFile") msg="[Hook] Source file updated (e.g. $fname) but changelog not synced. Run dev-changelog Skill operation A NOW to write all three changelog layers." echo "{\"followup_message\":\"$msg\"}" else echo '{}' fi exit 0