Initial commit
This commit is contained in:
65
hooks/post-write.sh
Executable file
65
hooks/post-write.sh
Executable file
@@ -0,0 +1,65 @@
|
||||
#!/bin/bash
|
||||
# Post-write hook: Auto-format files after writing
|
||||
|
||||
FILE_PATH="$1"
|
||||
|
||||
echo "✨ Post-write processing: $FILE_PATH"
|
||||
|
||||
# Get file extension
|
||||
EXT="${FILE_PATH##*.}"
|
||||
|
||||
# Format based on file type
|
||||
case "$EXT" in
|
||||
js|jsx)
|
||||
if command -v prettier &> /dev/null; then
|
||||
echo " Formatting JavaScript with prettier..."
|
||||
prettier --write "$FILE_PATH" 2>&1 || true
|
||||
echo " ✓ Formatted"
|
||||
fi
|
||||
;;
|
||||
ts|tsx)
|
||||
if command -v prettier &> /dev/null; then
|
||||
echo " Formatting TypeScript with prettier..."
|
||||
prettier --write "$FILE_PATH" 2>&1 || true
|
||||
echo " ✓ Formatted"
|
||||
fi
|
||||
;;
|
||||
py)
|
||||
if command -v black &> /dev/null; then
|
||||
echo " Formatting Python with black..."
|
||||
black -q "$FILE_PATH" 2>&1 || true
|
||||
echo " ✓ Formatted"
|
||||
elif command -v autopep8 &> /dev/null; then
|
||||
echo " Formatting Python with autopep8..."
|
||||
autopep8 --in-place "$FILE_PATH" 2>&1 || true
|
||||
echo " ✓ Formatted"
|
||||
fi
|
||||
;;
|
||||
go)
|
||||
if command -v gofmt &> /dev/null; then
|
||||
echo " Formatting Go with gofmt..."
|
||||
gofmt -w "$FILE_PATH" 2>&1 || true
|
||||
echo " ✓ Formatted"
|
||||
fi
|
||||
;;
|
||||
rs)
|
||||
if command -v rustfmt &> /dev/null; then
|
||||
echo " Formatting Rust with rustfmt..."
|
||||
rustfmt "$FILE_PATH" 2>&1 || true
|
||||
echo " ✓ Formatted"
|
||||
fi
|
||||
;;
|
||||
java)
|
||||
if command -v google-java-format &> /dev/null; then
|
||||
echo " Formatting Java..."
|
||||
google-java-format -i "$FILE_PATH" 2>&1 || true
|
||||
echo " ✓ Formatted"
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
echo " No formatter configured for .$EXT files"
|
||||
;;
|
||||
esac
|
||||
|
||||
echo "✓ Post-write hook completed"
|
||||
exit 0
|
||||
28
hooks/pre-edit.sh
Executable file
28
hooks/pre-edit.sh
Executable file
@@ -0,0 +1,28 @@
|
||||
#!/bin/bash
|
||||
# Pre-edit hook: Validates file before editing
|
||||
|
||||
FILE_PATH="$1"
|
||||
|
||||
echo "🔍 Pre-edit check for: $FILE_PATH"
|
||||
|
||||
# Check if file exists
|
||||
if [ -f "$FILE_PATH" ]; then
|
||||
# Check if tracked by git
|
||||
if git ls-files --error-unmatch "$FILE_PATH" &> /dev/null; then
|
||||
echo "✓ File is tracked by git"
|
||||
else
|
||||
echo "⚠️ Warning: File is not tracked by git"
|
||||
echo " Consider adding it with: git add $FILE_PATH"
|
||||
fi
|
||||
|
||||
# Check file size
|
||||
SIZE=$(wc -c < "$FILE_PATH" 2>/dev/null || echo 0)
|
||||
if [ "$SIZE" -gt 1000000 ]; then
|
||||
echo "⚠️ Warning: Large file ($(echo "scale=2; $SIZE/1024/1024" | bc)MB)"
|
||||
echo " Consider if this should be edited"
|
||||
fi
|
||||
else
|
||||
echo "ℹ️ New file will be created"
|
||||
fi
|
||||
|
||||
exit 0
|
||||
47
hooks/user-prompt-submit.sh
Executable file
47
hooks/user-prompt-submit.sh
Executable file
@@ -0,0 +1,47 @@
|
||||
#!/bin/bash
|
||||
# User prompt submit hook: Logs and validates user prompts
|
||||
|
||||
PROMPT="$1"
|
||||
|
||||
# Create log directory if it doesn't exist
|
||||
LOG_DIR=".claude-plugin/logs"
|
||||
mkdir -p "$LOG_DIR"
|
||||
|
||||
# Log the prompt
|
||||
TIMESTAMP=$(date '+%Y-%m-%d %H:%M:%S')
|
||||
LOG_FILE="$LOG_DIR/prompt-history.log"
|
||||
echo "[$TIMESTAMP] $PROMPT" >> "$LOG_FILE"
|
||||
|
||||
# Check for potentially dangerous commands
|
||||
if echo "$PROMPT" | grep -Eqi "(rm -rf /|format|delete all|drop database)"; then
|
||||
echo "⚠️ WARNING: Detected potentially destructive command!"
|
||||
echo " Please review carefully before proceeding."
|
||||
echo ""
|
||||
fi
|
||||
|
||||
# Check for git force operations
|
||||
if echo "$PROMPT" | grep -Eqi "(git push.*--force|git reset --hard|git clean -fdx)"; then
|
||||
echo "⚠️ WARNING: Detected potentially destructive git operation!"
|
||||
echo " Make sure you understand the consequences."
|
||||
echo ""
|
||||
fi
|
||||
|
||||
# Check for production-related keywords
|
||||
if echo "$PROMPT" | grep -Eqi "(production|prod|live environment)"; then
|
||||
echo "⚠️ CAUTION: Production environment mentioned"
|
||||
echo " Double-check all operations on production systems."
|
||||
echo ""
|
||||
fi
|
||||
|
||||
# Provide helpful tips for common patterns
|
||||
if echo "$PROMPT" | grep -qi "create.*test"; then
|
||||
echo "💡 Tip: Consider using TDD - write tests first!"
|
||||
echo ""
|
||||
fi
|
||||
|
||||
if echo "$PROMPT" | grep -qi "refactor"; then
|
||||
echo "💡 Tip: Make sure tests pass before and after refactoring"
|
||||
echo ""
|
||||
fi
|
||||
|
||||
exit 0
|
||||
Reference in New Issue
Block a user