基础优化

lzk
lzkk 2 days ago
parent eb83ab5cd3
commit f608d852bf

@ -1,30 +0,0 @@
#!/usr/bin/env bash
# 阻止危险操作(不可恢复的破坏性命令)
# 从 stdin 读取 hook 输入 JSON
input=$(cat 2>/dev/null || echo "{}")
command=$(echo "$input" | python3 -c "import sys,json; print(json.load(sys.stdin).get('tool_input',{}).get('command',''))" 2>/dev/null || echo "")
deny() { echo "{\"permissionDecision\": \"deny\", \"reason\": \"$1\"}"; exit 0; }
# 1. rm -rf / 等根目录删除
echo "$command" | grep -qE 'rm\s+-rf\s+/(\*|\s|$)' &&
deny "禁止 rm -rf / 操作"
# 2. git reset --hard丢失未提交工作
echo "$command" | grep -qE 'git\s+reset\s+--hard' &&
deny "禁止 git reset --hard。请用 git stash 暂存改动"
# 3. git push --force/-f 到 master/main
echo "$command" | grep -qE 'git\s+push\s+.*(--force|-f).*(master|main)' &&
deny "禁止 force push 到 master/main 分支"
# 4. git checkout -- <path>(丢弃未提交改动,不可恢复)
echo "$command" | grep -qE 'git\s+checkout\s+--\s' &&
deny "禁止 git checkout --。用 git stash 暂存改动"
# 5. git clean -fd删除未跟踪文件不可恢复
echo "$command" | grep -qE 'git\s+clean\s+-f' &&
deny "禁止 git clean -f。请手动确认要删除的文件"
echo '{"permissionDecision": "allow"}'

@ -1,32 +0,0 @@
#!/usr/bin/env bash
# 会话启动时的内存/进程守卫
# 1. 检查可用内存,低于 2GB 时警告
# 2. 检查是否有多个 claude 会话在运行
# 输出 JSON 到 stdout警告通过 additionalContext 注入
AVAILABLE_MB=$(awk '/^MemAvailable:/ {print int($2/1024)}' /proc/meminfo 2>/dev/null || echo "0")
CLAUDE_COUNT=$(pgrep -c -f "claude" 2>/dev/null || echo "0")
WARNINGS=""
if [[ "$AVAILABLE_MB" -gt 0 && "$AVAILABLE_MB" -lt 2048 ]]; then
WARNINGS="${WARNINGS}- ⚠ 可用内存仅 ${AVAILABLE_MB}MB建议关闭其他应用后再操作\n"
fi
if [[ "$CLAUDE_COUNT" -gt 2 ]]; then
WARNINGS="${WARNINGS}- ⚠ 检测到 ${CLAUDE_COUNT} 个 claude 会话在运行,多会话可能导致 OOM\n"
fi
if [[ -n "$WARNINGS" ]]; then
cat << EOF
{
"continue": true,
"hookSpecificOutput": {
"hookEventName": "SessionStart",
"additionalContext": "## ⚠ 资源警告\n\n${WARNINGS}"
}
}
EOF
else
echo '{"continue": true}'
fi

@ -1,11 +0,0 @@
#!/usr/bin/env bash
# 每次会话注入核心规范速查
cat << 'EOF'
{
"continue": true,
"hookSpecificOutput": {
"hookEventName": "SessionStart",
"additionalContext": "## 速查\n- 安全优化通用、不投机、不依赖UB\n- 门禁commit前跑 ./2026test.sh -c functional -x && ./2026test.sh -c h_functional -x\n- 性能:改前 ./count_asm.sh 基线 → 实现 → 验证 → 对比\n- 工具查符号用codegraph搜字面量用grep改前 codegraph_impact\n- diff ≤200行大改动分步\n"
}
}
EOF

@ -1,11 +0,0 @@
#!/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, \"systemMessage\": \"## ${count} 个源文件未提交\\n\\n快门禁通过\"}"
fi

@ -1,56 +0,0 @@
{
"disabledMcpjsonServers": ["figma", "react-bits", "chrome"],
"hooks": {
"SessionStart": [
{
"matcher": "",
"hooks": [
{
"type": "command",
"command": "bash .claude/hooks/spec-reminder.sh",
"timeout": 5000
},
{
"type": "command",
"command": "bash .claude/hooks/memory-guard.sh",
"timeout": 3000
}
]
}
],
"PreToolUse": [
{
"matcher": "Bash(rm *)|Bash(git reset *)|Bash(git push *)|Bash(git checkout *)|Bash(git clean *)",
"hooks": [
{
"type": "command",
"command": "bash .claude/hooks/block-destructive.sh",
"timeout": 5000
}
]
},
{
"matcher": "Bash(git commit *)",
"hooks": [
{
"type": "command",
"command": "echo '=== 快门禁 ===' && ./2026test.sh -c functional -x 2>&1 | tail -5 && ./2026test.sh -c h_functional -x 2>&1 | tail -5",
"timeout": 180000
}
]
}
],
"Stop": [
{
"matcher": "",
"hooks": [
{
"type": "command",
"command": "bash .claude/hooks/stop-guard.sh",
"timeout": 3000
}
]
}
]
}
}
Loading…
Cancel
Save