Skip to content

Commit 8986333

Browse files
feat: Add Sweep prediction hook for Claude Code
- post-edit-sweep.js hook runs after Edit/Write operations - Tracks recent diffs and runs background predictions - Shows prediction hints in Claude Code - install-sweep-hook.sh for easy installation
1 parent c376c6c commit 8986333

2 files changed

Lines changed: 451 additions & 0 deletions

File tree

scripts/install-sweep-hook.sh

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#!/bin/bash
2+
# Install Sweep prediction hook for Claude Code
3+
4+
set -e
5+
6+
HOOK_DIR="$HOME/.claude/hooks"
7+
SWEEP_DIR="$HOME/.stackmemory/sweep"
8+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
9+
REPO_DIR="$(dirname "$SCRIPT_DIR")"
10+
11+
echo "Installing Sweep prediction hook for Claude Code..."
12+
13+
# Create directories
14+
mkdir -p "$HOOK_DIR"
15+
mkdir -p "$SWEEP_DIR"
16+
17+
# Copy hook script
18+
cp "$REPO_DIR/templates/claude-hooks/post-edit-sweep.js" "$HOOK_DIR/"
19+
chmod +x "$HOOK_DIR/post-edit-sweep.js"
20+
21+
# Copy Python prediction script
22+
cp "$REPO_DIR/packages/sweep-addon/python/sweep_predict.py" "$SWEEP_DIR/"
23+
24+
# Update hooks.json if it exists, otherwise create it
25+
HOOKS_JSON="$HOME/.claude/hooks.json"
26+
if [ -f "$HOOKS_JSON" ]; then
27+
# Check if post-tool-use already configured
28+
if grep -q "post-tool-use" "$HOOKS_JSON"; then
29+
echo "Note: post-tool-use hook already configured in $HOOKS_JSON"
30+
echo "You may need to manually add the sweep hook."
31+
else
32+
echo "Adding sweep hook to $HOOKS_JSON..."
33+
# Use node to safely update JSON
34+
node -e "
35+
const fs = require('fs');
36+
const hooks = JSON.parse(fs.readFileSync('$HOOKS_JSON', 'utf-8'));
37+
hooks['post-tool-use'] = '$HOOK_DIR/post-edit-sweep.js';
38+
fs.writeFileSync('$HOOKS_JSON', JSON.stringify(hooks, null, 2));
39+
console.log('Updated hooks.json');
40+
"
41+
fi
42+
else
43+
echo "Creating $HOOKS_JSON..."
44+
cat > "$HOOKS_JSON" << 'EOF'
45+
{
46+
"post-tool-use": "~/.claude/hooks/post-edit-sweep.js"
47+
}
48+
EOF
49+
fi
50+
51+
# Check Python dependencies
52+
echo ""
53+
echo "Checking Python dependencies..."
54+
if python3 -c "import llama_cpp" 2>/dev/null; then
55+
echo " llama-cpp-python: installed"
56+
else
57+
echo " llama-cpp-python: NOT INSTALLED"
58+
echo " Run: pip install llama-cpp-python"
59+
fi
60+
61+
if python3 -c "import huggingface_hub" 2>/dev/null; then
62+
echo " huggingface_hub: installed"
63+
else
64+
echo " huggingface_hub: NOT INSTALLED"
65+
echo " Run: pip install huggingface_hub"
66+
fi
67+
68+
# Check model
69+
MODEL_PATH="$HOME/.stackmemory/models/sweep/sweep-next-edit-1.5b.q8_0.v2.gguf"
70+
if [ -f "$MODEL_PATH" ]; then
71+
echo " Model: downloaded"
72+
else
73+
echo " Model: NOT DOWNLOADED"
74+
echo " Run: stackmemory sweep setup --download"
75+
fi
76+
77+
echo ""
78+
echo "Installation complete!"
79+
echo ""
80+
echo "Hook installed at: $HOOK_DIR/post-edit-sweep.js"
81+
echo "Python script at: $SWEEP_DIR/sweep_predict.py"
82+
echo ""
83+
echo "Usage:"
84+
echo " - Hook runs automatically after Edit/Write operations"
85+
echo " - Predictions appear after 2+ edits in session"
86+
echo " - Check status: node $HOOK_DIR/post-edit-sweep.js --status"
87+
echo " - Clear state: node $HOOK_DIR/post-edit-sweep.js --clear"
88+
echo " - Disable: export SWEEP_ENABLED=false"
89+
echo ""

0 commit comments

Comments
 (0)