-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall-code-execution-hooks.sh
More file actions
executable file
·96 lines (82 loc) · 3.03 KB
/
install-code-execution-hooks.sh
File metadata and controls
executable file
·96 lines (82 loc) · 3.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/bin/bash
# Install Code Execution and Pre-Tool-Use Hooks for StackMemory
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
CLAUDE_HOOKS_DIR="$HOME/.claude/hooks"
echo "🚀 Installing StackMemory Code Execution Hooks"
echo "============================================"
# Create hooks directory if it doesn't exist
if [ ! -d "$CLAUDE_HOOKS_DIR" ]; then
echo "Creating Claude hooks directory..."
mkdir -p "$CLAUDE_HOOKS_DIR"
fi
# Build the project first to ensure handlers are compiled
echo ""
echo "📦 Building project..."
cd "$PROJECT_ROOT"
npm run build
# Install pre-tool-use hook
echo ""
echo "🔒 Installing pre-tool-use hook..."
if [ -f "$PROJECT_ROOT/templates/claude-hooks/pre-tool-use" ]; then
# Backup existing hook if present
if [ -f "$CLAUDE_HOOKS_DIR/pre-tool-use" ]; then
echo " Backing up existing pre-tool-use hook..."
cp "$CLAUDE_HOOKS_DIR/pre-tool-use" "$CLAUDE_HOOKS_DIR/pre-tool-use.backup.$(date +%Y%m%d_%H%M%S)"
fi
# Copy new hook
cp "$PROJECT_ROOT/templates/claude-hooks/pre-tool-use" "$CLAUDE_HOOKS_DIR/"
chmod +x "$CLAUDE_HOOKS_DIR/pre-tool-use"
echo " ✅ pre-tool-use hook installed"
else
echo " ❌ pre-tool-use hook not found"
fi
# Create configuration file
echo ""
echo "⚙️ Setting up configuration..."
STACKMEMORY_CONFIG_DIR="$HOME/.stackmemory"
mkdir -p "$STACKMEMORY_CONFIG_DIR"
# Create mode configuration
cat > "$STACKMEMORY_CONFIG_DIR/tool-mode.conf" << EOF
# StackMemory Tool Mode Configuration
# Options: permissive (default), restrictive, code_only
STACKMEMORY_TOOL_MODE=permissive
EOF
echo " ✅ Configuration created at $STACKMEMORY_CONFIG_DIR/tool-mode.conf"
# Test code execution handler
echo ""
echo "🧪 Testing code execution handler..."
node "$PROJECT_ROOT/scripts/test-code-execution.js" 2>/dev/null || {
echo " ⚠️ Code execution test failed - handler may need dependencies"
echo " Run: node scripts/test-code-execution.js for details"
}
# Display usage information
echo ""
echo "📝 Installation Complete!"
echo ""
echo "Usage:"
echo "------"
echo "1. Set tool mode (optional):"
echo " export STACKMEMORY_TOOL_MODE=permissive # Default - all tools allowed"
echo " export STACKMEMORY_TOOL_MODE=restrictive # Block dangerous tools"
echo " export STACKMEMORY_TOOL_MODE=code_only # Only code execution allowed"
echo ""
echo "2. Or edit: ~/.stackmemory/tool-mode.conf"
echo ""
echo "3. View tool usage logs:"
echo " tail -f ~/.stackmemory/tool-use.log"
echo ""
echo "4. Test code execution:"
echo " node $PROJECT_ROOT/scripts/test-code-execution.js"
echo ""
echo "Modes:"
echo "------"
echo "• permissive: All tools allowed, dangerous ones logged"
echo "• restrictive: Blocks Bash, Write, Edit, Delete, WebFetch"
echo "• code_only: Only Python/JavaScript execution (pure computation)"
echo ""
echo "The code_only mode creates a restricted environment similar to"
echo "execute_code_py, where Claude can only perform computations."
echo ""
echo "✨ Ready to use with Claude Code!"