Initial commit

This commit is contained in:
Zhongwei Li
2025-11-30 08:30:45 +08:00
commit 4b125e7fee
5 changed files with 122 additions and 0 deletions

44
hooks/force-bun.sh Executable file
View File

@@ -0,0 +1,44 @@
#!/bin/bash
set -euo pipefail
suggest_deny() {
local reason="$1"
jq -cn \
--arg reason "$reason" \
'{
"hookSpecificOutput": {
"hookEventName": "PreToolUse",
"permissionDecision": "deny",
"permissionDecisionReason": $reason
}
}'
exit 1
}
# 標準入力から JSON を読み取り
input=$(</dev/stdin)
# コマンドチェックの際に複数行がある場合は最初の行のみを使用
command=$(jq -r '.tool_input.command // empty' <<< "$input")
# 引用符以降は無視する(コミットメッセージとかのコメント文字列に含む場合などの誤検知回避のため)
command=${command%%[\'\"]*}
# コマンドが空の場合は何もチェックしない
[[ -z "$command" ]] && exit 0
# Bun に置き換えを推奨
if [[ $command =~ (^| )(npx|npm\ x|npm\ exec)( ) ]]; then
suggest_deny "Use 'bunx' instead of npx, npm x, or npm exec"
fi
# npm version は許可
if [[ $command =~ npm\ version ]]; then
exit 0
fi
# その他の npm コマンドは Bun を推奨
if [[ $command =~ (^| )npm( ) ]]; then
suggest_deny "Use 'bun' instead of npm"
fi
exit 0

15
hooks/hooks.json Normal file
View File

@@ -0,0 +1,15 @@
{
"hooks": {
"PreToolUse": [
{
"matcher": "Bash",
"hooks": [
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/force-bun.sh"
}
]
}
]
}
}