Initial commit
This commit is contained in:
55
skills/hook-development/examples/load-context.sh
Executable file
55
skills/hook-development/examples/load-context.sh
Executable file
@@ -0,0 +1,55 @@
|
||||
#!/bin/bash
|
||||
# Example SessionStart hook for loading project context
|
||||
# This script detects project type and sets environment variables
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
# Navigate to project directory
|
||||
cd "$CLAUDE_PROJECT_DIR" || exit 1
|
||||
|
||||
echo "Loading project context..."
|
||||
|
||||
# Detect project type and set environment
|
||||
if [ -f "package.json" ]; then
|
||||
echo "📦 Node.js project detected"
|
||||
echo "export PROJECT_TYPE=nodejs" >> "$CLAUDE_ENV_FILE"
|
||||
|
||||
# Check if TypeScript
|
||||
if [ -f "tsconfig.json" ]; then
|
||||
echo "export USES_TYPESCRIPT=true" >> "$CLAUDE_ENV_FILE"
|
||||
fi
|
||||
|
||||
elif [ -f "Cargo.toml" ]; then
|
||||
echo "🦀 Rust project detected"
|
||||
echo "export PROJECT_TYPE=rust" >> "$CLAUDE_ENV_FILE"
|
||||
|
||||
elif [ -f "go.mod" ]; then
|
||||
echo "🐹 Go project detected"
|
||||
echo "export PROJECT_TYPE=go" >> "$CLAUDE_ENV_FILE"
|
||||
|
||||
elif [ -f "pyproject.toml" ] || [ -f "setup.py" ]; then
|
||||
echo "🐍 Python project detected"
|
||||
echo "export PROJECT_TYPE=python" >> "$CLAUDE_ENV_FILE"
|
||||
|
||||
elif [ -f "pom.xml" ]; then
|
||||
echo "☕ Java (Maven) project detected"
|
||||
echo "export PROJECT_TYPE=java" >> "$CLAUDE_ENV_FILE"
|
||||
echo "export BUILD_SYSTEM=maven" >> "$CLAUDE_ENV_FILE"
|
||||
|
||||
elif [ -f "build.gradle" ] || [ -f "build.gradle.kts" ]; then
|
||||
echo "☕ Java/Kotlin (Gradle) project detected"
|
||||
echo "export PROJECT_TYPE=java" >> "$CLAUDE_ENV_FILE"
|
||||
echo "export BUILD_SYSTEM=gradle" >> "$CLAUDE_ENV_FILE"
|
||||
|
||||
else
|
||||
echo "❓ Unknown project type"
|
||||
echo "export PROJECT_TYPE=unknown" >> "$CLAUDE_ENV_FILE"
|
||||
fi
|
||||
|
||||
# Check for CI configuration
|
||||
if [ -f ".github/workflows" ] || [ -f ".gitlab-ci.yml" ] || [ -f ".circleci/config.yml" ]; then
|
||||
echo "export HAS_CI=true" >> "$CLAUDE_ENV_FILE"
|
||||
fi
|
||||
|
||||
echo "Project context loaded successfully"
|
||||
exit 0
|
||||
43
skills/hook-development/examples/validate-bash.sh
Executable file
43
skills/hook-development/examples/validate-bash.sh
Executable file
@@ -0,0 +1,43 @@
|
||||
#!/bin/bash
|
||||
# Example PreToolUse hook for validating Bash commands
|
||||
# This script demonstrates bash command validation patterns
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
# Read input from stdin
|
||||
input=$(cat)
|
||||
|
||||
# Extract command
|
||||
command=$(echo "$input" | jq -r '.tool_input.command // empty')
|
||||
|
||||
# Validate command exists
|
||||
if [ -z "$command" ]; then
|
||||
echo '{"continue": true}' # No command to validate
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Check for obviously safe commands (quick approval)
|
||||
if [[ "$command" =~ ^(ls|pwd|echo|date|whoami)(\s|$) ]]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Check for destructive operations
|
||||
if [[ "$command" == *"rm -rf"* ]] || [[ "$command" == *"rm -fr"* ]]; then
|
||||
echo '{"hookSpecificOutput": {"permissionDecision": "deny"}, "systemMessage": "Dangerous command detected: rm -rf"}' >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
# Check for other dangerous commands
|
||||
if [[ "$command" == *"dd if="* ]] || [[ "$command" == *"mkfs"* ]] || [[ "$command" == *"> /dev/"* ]]; then
|
||||
echo '{"hookSpecificOutput": {"permissionDecision": "deny"}, "systemMessage": "Dangerous system operation detected"}' >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
# Check for privilege escalation
|
||||
if [[ "$command" == sudo* ]] || [[ "$command" == su* ]]; then
|
||||
echo '{"hookSpecificOutput": {"permissionDecision": "ask"}, "systemMessage": "Command requires elevated privileges"}' >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
# Approve the operation
|
||||
exit 0
|
||||
38
skills/hook-development/examples/validate-write.sh
Executable file
38
skills/hook-development/examples/validate-write.sh
Executable file
@@ -0,0 +1,38 @@
|
||||
#!/bin/bash
|
||||
# Example PreToolUse hook for validating Write/Edit operations
|
||||
# This script demonstrates file write validation patterns
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
# Read input from stdin
|
||||
input=$(cat)
|
||||
|
||||
# Extract file path and content
|
||||
file_path=$(echo "$input" | jq -r '.tool_input.file_path // empty')
|
||||
|
||||
# Validate path exists
|
||||
if [ -z "$file_path" ]; then
|
||||
echo '{"continue": true}' # No path to validate
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Check for path traversal
|
||||
if [[ "$file_path" == *".."* ]]; then
|
||||
echo '{"hookSpecificOutput": {"permissionDecision": "deny"}, "systemMessage": "Path traversal detected in: '"$file_path"'"}' >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
# Check for system directories
|
||||
if [[ "$file_path" == /etc/* ]] || [[ "$file_path" == /sys/* ]] || [[ "$file_path" == /usr/* ]]; then
|
||||
echo '{"hookSpecificOutput": {"permissionDecision": "deny"}, "systemMessage": "Cannot write to system directory: '"$file_path"'"}' >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
# Check for sensitive files
|
||||
if [[ "$file_path" == *.env ]] || [[ "$file_path" == *secret* ]] || [[ "$file_path" == *credentials* ]]; then
|
||||
echo '{"hookSpecificOutput": {"permissionDecision": "ask"}, "systemMessage": "Writing to potentially sensitive file: '"$file_path"'"}' >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
# Approve the operation
|
||||
exit 0
|
||||
Reference in New Issue
Block a user