diff --git a/.claude/hooks/stop-guard.sh b/.claude/hooks/stop-guard.sh new file mode 100755 index 00000000..6db2e014 --- /dev/null +++ b/.claude/hooks/stop-guard.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash +# 智能 Stop hook:仅 src/ 有未提交改动时提醒门禁 +cd "$(dirname "$0")/../.." 2>/dev/null || true + +count=$( (git diff --name-only HEAD; git diff --cached --name-only) 2>/dev/null | grep -c '^src/') + +if [ "${count:-0}" = "0" ]; then + echo '{"continue": true}' +else + echo "{\"continue\": true, \"hookSpecificOutput\": {\"hookEventName\": \"Stop\", \"additionalContext\": \"## ${count} 个源文件未提交\\n\\n快门禁通过?\"}}" +fi diff --git a/.claude/settings.json b/.claude/settings.json index f93334d4..c6f00da4 100644 --- a/.claude/settings.json +++ b/.claude/settings.json @@ -45,9 +45,9 @@ "matcher": "", "hooks": [ { - "type": "prompt", - "prompt": "在结束本次会话之前,请确认以下事项:\n1. 快门禁是否通过?(./2026test.sh -c functional -x && ./2026test.sh -c h_functional -x)\n2. 指令数是否有退化?(如有优化改动,跑 ./count_asm.sh)\n3. 本次有效的优化是否已记录到 优化记录.md?\n4. 是否有未提交的改动需要处理?\n5. 如有重要经验教训,是否已写入 memory?\n\n请简要回答每个问题(是/否/不适用),然后正常结束。", - "timeout": 15000 + "type": "command", + "command": "bash .claude/hooks/stop-guard.sh", + "timeout": 3000 } ] }