Files
claude-howto/ja/06-hooks/validate-prompt.sh
JiangCheng 1d1df9235b feat(i18n): Add Japanese (ja/) translation (#105)
- Translate all 101 markdown files: P1 core, all 10 modules, examples,
  auxiliary docs (CONTRIBUTING, CODE_OF_CONDUCT, SECURITY, CLAUDE.md, etc.),
  peripheral docs (.github/, docs/, resources/, scripts/)
- Translate comments and user-facing messages in 06-hooks/*.sh examples
- Copy 05-mcp/*.json examples (standard JSON, no comments)
- Update root README.md language switcher to include 日本語
- Add ja/TRANSLATION_NOTES.md (glossary + style guide)

All translations pass pre-commit quality gates (markdown-lint,
cross-references, mermaid-syntax, link-check, build-epub).
2026-04-30 00:16:46 +02:00

55 lines
1.8 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
# ユーザプロンプトを検証する
# フックUserPromptSubmit
#
# 標準入力の JSON からユーザプロンプトを読み取り、危険な操作をブロックする。
#
# 対応macOS、Linux、WindowsGit Bash
# Claude Code フックプロトコルに従い、標準入力から JSON を読み取る
INPUT=$(cat)
# JSON 入力からプロンプト本文を抽出
# Claude Code は UserPromptSubmit を "user_prompt" で送る(無ければ "prompt" にフォールバック)
PROMPT=$(echo "$INPUT" | sed -n 's/.*"user_prompt"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p' | head -1)
if [ -z "$PROMPT" ]; then
PROMPT=$(echo "$INPUT" | sed -n 's/.*"prompt"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p' | head -1)
fi
if [ -z "$PROMPT" ]; then
exit 0
fi
# 危険な操作の検出
DANGEROUS_PATTERNS=(
"rm -rf /"
"delete database"
"drop database"
"format disk"
"dd if="
)
for pattern in "${DANGEROUS_PATTERNS[@]}"; do
if echo "$PROMPT" | grep -qi "$pattern"; then
printf '{"decision": "block", "reason": "危険な操作を検出: %s"}' "$pattern"
exit 0
fi
done
# 本番デプロイの検出
if echo "$PROMPT" | grep -qiE "(deploy|push).*production"; then
if [ ! -f ".deployment-approved" ]; then
echo '{"decision": "block", "reason": "本番デプロイには承認が必要です。続行するには .deployment-approved ファイルを作成してください。"}'
exit 0
fi
fi
# 特定操作におけるコンテキスト要件のチェック
if echo "$PROMPT" | grep -qi "refactor"; then
if [ ! -d "tests" ] && [ ! -d "test" ]; then
printf '{"additionalContext": "警告: テスト無しのリファクタリングはリスクを伴います。先にテストを書くことを検討してください。"}'
fi
fi
exit 0