@localtech/claude-code-toolkit 1.0.5 → 1.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +70 -15
- package/dist/cli.js +20 -3
- package/dist/cli.js.map +1 -1
- package/dist/commands/list.js +4 -4
- package/dist/commands/list.js.map +1 -1
- package/dist/commands/template.js +20 -2
- package/dist/commands/template.js.map +1 -1
- package/dist/commands/update.d.ts.map +1 -1
- package/dist/commands/update.js +4 -3
- package/dist/commands/update.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/package.json +4 -3
- package/templates/.claude/hooks/custom/intelligent-workflows.sh +336 -336
- package/templates/.claude/hooks/hook-manager.sh +300 -300
- package/templates/.claude/hooks/post-commit/smart-automations.sh +249 -249
- package/templates/.claude/hooks/pre-commit/code-quality-guardian.sh +257 -257
- package/templates/.claude/hooks/pre-push/deployment-guardian.sh +334 -334
|
@@ -1,300 +1,300 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
# HOOK: hook-manager
|
|
3
|
-
# DESCRIPTION: Central hook management and orchestration system
|
|
4
|
-
# AUTHOR: Claude Code Hooks Master
|
|
5
|
-
# VERSION: 1.0.0
|
|
6
|
-
|
|
7
|
-
set -e
|
|
8
|
-
|
|
9
|
-
# Colors and logging
|
|
10
|
-
GREEN='\033[0;32m'
|
|
11
|
-
BLUE='\033[0;34m'
|
|
12
|
-
YELLOW='\033[1;33m'
|
|
13
|
-
RED='\033[0;31m'
|
|
14
|
-
PURPLE='\033[0;35m'
|
|
15
|
-
NC='\033[0m'
|
|
16
|
-
|
|
17
|
-
log_info() {
|
|
18
|
-
echo -e "${BLUE}[HOOKS]${NC} $1"
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
log_success() {
|
|
22
|
-
echo -e "${GREEN}[SUCCESS]${NC} $1"
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
log_warn() {
|
|
26
|
-
echo -e "${YELLOW}[WARN]${NC} $1"
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
log_error() {
|
|
30
|
-
echo -e "${RED}[ERROR]${NC} $1"
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
log_ai() {
|
|
34
|
-
echo -e "${PURPLE}[🤖]${NC} $1"
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
# Hook configuration
|
|
38
|
-
HOOK_DIR=".claude/hooks"
|
|
39
|
-
declare -A HOOK_TYPES=(
|
|
40
|
-
["pre-commit"]="code-quality-guardian.sh"
|
|
41
|
-
["post-commit"]="smart-automations.sh"
|
|
42
|
-
["pre-push"]="deployment-guardian.sh"
|
|
43
|
-
["custom"]="intelligent-workflows.sh"
|
|
44
|
-
)
|
|
45
|
-
|
|
46
|
-
# Make hooks executable
|
|
47
|
-
setup_hooks() {
|
|
48
|
-
log_info "Setting up Claude Code hooks..."
|
|
49
|
-
|
|
50
|
-
for hook_type in "${!HOOK_TYPES[@]}"; do
|
|
51
|
-
local hook_file="$HOOK_DIR/$hook_type/${HOOK_TYPES[$hook_type]}"
|
|
52
|
-
|
|
53
|
-
if [ -f "$hook_file" ]; then
|
|
54
|
-
chmod +x "$hook_file"
|
|
55
|
-
log_success "Made $hook_type hook executable"
|
|
56
|
-
else
|
|
57
|
-
log_warn "Hook file not found: $hook_file"
|
|
58
|
-
fi
|
|
59
|
-
done
|
|
60
|
-
|
|
61
|
-
log_success "Hook setup completed"
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
# Install git hooks
|
|
65
|
-
install_git_hooks() {
|
|
66
|
-
log_info "Installing Git hooks integration..."
|
|
67
|
-
|
|
68
|
-
local git_hooks_dir=".git/hooks"
|
|
69
|
-
if [ ! -d "$git_hooks_dir" ]; then
|
|
70
|
-
log_error "Git repository not found - cannot install hooks"
|
|
71
|
-
return 1
|
|
72
|
-
fi
|
|
73
|
-
|
|
74
|
-
# Create pre-commit hook
|
|
75
|
-
cat > "$git_hooks_dir/pre-commit" << 'EOF'
|
|
76
|
-
#!/bin/bash
|
|
77
|
-
# Claude Code Pre-commit Hook
|
|
78
|
-
|
|
79
|
-
# Get the directory where this script is located
|
|
80
|
-
HOOK_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/../../.claude/hooks"
|
|
81
|
-
PRE_COMMIT_HOOK="$HOOK_DIR/pre-commit/code-quality-guardian.sh"
|
|
82
|
-
|
|
83
|
-
if [ -x "$PRE_COMMIT_HOOK" ]; then
|
|
84
|
-
echo "Running Claude Code pre-commit quality checks..."
|
|
85
|
-
if ! "$PRE_COMMIT_HOOK"; then
|
|
86
|
-
echo "Pre-commit checks failed. Please fix issues and try again."
|
|
87
|
-
exit 1
|
|
88
|
-
fi
|
|
89
|
-
else
|
|
90
|
-
echo "Warning: Claude Code pre-commit hook not found or not executable"
|
|
91
|
-
fi
|
|
92
|
-
EOF
|
|
93
|
-
|
|
94
|
-
# Create post-commit hook
|
|
95
|
-
cat > "$git_hooks_dir/post-commit" << 'EOF'
|
|
96
|
-
#!/bin/bash
|
|
97
|
-
# Claude Code Post-commit Hook
|
|
98
|
-
|
|
99
|
-
HOOK_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/../../.claude/hooks"
|
|
100
|
-
POST_COMMIT_HOOK="$HOOK_DIR/post-commit/smart-automations.sh"
|
|
101
|
-
|
|
102
|
-
if [ -x "$POST_COMMIT_HOOK" ]; then
|
|
103
|
-
echo "Running Claude Code post-commit automations..."
|
|
104
|
-
"$POST_COMMIT_HOOK" &
|
|
105
|
-
else
|
|
106
|
-
echo "Warning: Claude Code post-commit hook not found"
|
|
107
|
-
fi
|
|
108
|
-
EOF
|
|
109
|
-
|
|
110
|
-
# Create pre-push hook
|
|
111
|
-
cat > "$git_hooks_dir/pre-push" << 'EOF'
|
|
112
|
-
#!/bin/bash
|
|
113
|
-
# Claude Code Pre-push Hook
|
|
114
|
-
|
|
115
|
-
HOOK_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/../../.claude/hooks"
|
|
116
|
-
PRE_PUSH_HOOK="$HOOK_DIR/pre-push/deployment-guardian.sh"
|
|
117
|
-
|
|
118
|
-
if [ -x "$PRE_PUSH_HOOK" ]; then
|
|
119
|
-
echo "Running Claude Code pre-push deployment checks..."
|
|
120
|
-
if ! "$PRE_PUSH_HOOK"; then
|
|
121
|
-
echo "Pre-push checks failed. Please fix issues and try again."
|
|
122
|
-
exit 1
|
|
123
|
-
fi
|
|
124
|
-
else
|
|
125
|
-
echo "Warning: Claude Code pre-push hook not found or not executable"
|
|
126
|
-
fi
|
|
127
|
-
EOF
|
|
128
|
-
|
|
129
|
-
# Make git hooks executable
|
|
130
|
-
chmod +x "$git_hooks_dir/pre-commit"
|
|
131
|
-
chmod +x "$git_hooks_dir/post-commit"
|
|
132
|
-
chmod +x "$git_hooks_dir/pre-push"
|
|
133
|
-
|
|
134
|
-
log_success "Git hooks installed successfully"
|
|
135
|
-
log_info "Hooks will now run automatically on git operations"
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
# Test all hooks
|
|
139
|
-
test_hooks() {
|
|
140
|
-
log_info "Testing all Claude Code hooks..."
|
|
141
|
-
|
|
142
|
-
local test_results=()
|
|
143
|
-
|
|
144
|
-
for hook_type in "${!HOOK_TYPES[@]}"; do
|
|
145
|
-
local hook_file="$HOOK_DIR/$hook_type/${HOOK_TYPES[$hook_type]}"
|
|
146
|
-
|
|
147
|
-
if [ -f "$hook_file" ]; then
|
|
148
|
-
log_info "Testing $hook_type hook..."
|
|
149
|
-
|
|
150
|
-
# Basic syntax check
|
|
151
|
-
if bash -n "$hook_file" 2>/dev/null; then
|
|
152
|
-
log_success "$hook_type hook syntax is valid"
|
|
153
|
-
test_results+=("$hook_type: PASS")
|
|
154
|
-
else
|
|
155
|
-
log_error "$hook_type hook has syntax errors"
|
|
156
|
-
test_results+=("$hook_type: FAIL - Syntax Error")
|
|
157
|
-
fi
|
|
158
|
-
|
|
159
|
-
# Check if executable
|
|
160
|
-
if [ -x "$hook_file" ]; then
|
|
161
|
-
log_success "$hook_type hook is executable"
|
|
162
|
-
else
|
|
163
|
-
log_warn "$hook_type hook is not executable"
|
|
164
|
-
fi
|
|
165
|
-
else
|
|
166
|
-
log_error "$hook_type hook file not found: $hook_file"
|
|
167
|
-
test_results+=("$hook_type: FAIL - Missing")
|
|
168
|
-
fi
|
|
169
|
-
done
|
|
170
|
-
|
|
171
|
-
echo
|
|
172
|
-
log_info "Hook Test Results:"
|
|
173
|
-
for result in "${test_results[@]}"; do
|
|
174
|
-
echo " $result"
|
|
175
|
-
done
|
|
176
|
-
|
|
177
|
-
# Check for failures
|
|
178
|
-
if echo "${test_results[@]}" | grep -q "FAIL"; then
|
|
179
|
-
log_error "Some hooks have issues - please fix before using"
|
|
180
|
-
return 1
|
|
181
|
-
else
|
|
182
|
-
log_success "All hooks are properly configured!"
|
|
183
|
-
fi
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
# Run specific hook manually
|
|
187
|
-
run_hook() {
|
|
188
|
-
local hook_type="$1"
|
|
189
|
-
|
|
190
|
-
if [ -z "$hook_type" ]; then
|
|
191
|
-
log_error "Please specify a hook type to run"
|
|
192
|
-
echo "Available hooks: ${!HOOK_TYPES[*]}"
|
|
193
|
-
return 1
|
|
194
|
-
fi
|
|
195
|
-
|
|
196
|
-
if [ -z "${HOOK_TYPES[$hook_type]}" ]; then
|
|
197
|
-
log_error "Unknown hook type: $hook_type"
|
|
198
|
-
echo "Available hooks: ${!HOOK_TYPES[*]}"
|
|
199
|
-
return 1
|
|
200
|
-
fi
|
|
201
|
-
|
|
202
|
-
local hook_file="$HOOK_DIR/$hook_type/${HOOK_TYPES[$hook_type]}"
|
|
203
|
-
|
|
204
|
-
if [ ! -f "$hook_file" ]; then
|
|
205
|
-
log_error "Hook file not found: $hook_file"
|
|
206
|
-
return 1
|
|
207
|
-
fi
|
|
208
|
-
|
|
209
|
-
if [ ! -x "$hook_file" ]; then
|
|
210
|
-
log_error "Hook file is not executable: $hook_file"
|
|
211
|
-
return 1
|
|
212
|
-
fi
|
|
213
|
-
|
|
214
|
-
log_info "Running $hook_type hook manually..."
|
|
215
|
-
"$hook_file"
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
# Show hook status
|
|
219
|
-
status() {
|
|
220
|
-
log_info "Claude Code Hooks Status"
|
|
221
|
-
echo "=========================="
|
|
222
|
-
|
|
223
|
-
for hook_type in "${!HOOK_TYPES[@]}"; do
|
|
224
|
-
local hook_file="$HOOK_DIR/$hook_type/${HOOK_TYPES[$hook_type]}"
|
|
225
|
-
|
|
226
|
-
echo
|
|
227
|
-
echo "$hook_type hook:"
|
|
228
|
-
echo " File: $hook_file"
|
|
229
|
-
|
|
230
|
-
if [ -f "$hook_file" ]; then
|
|
231
|
-
echo " Status: ✅ Exists"
|
|
232
|
-
|
|
233
|
-
if [ -x "$hook_file" ]; then
|
|
234
|
-
echo " Executable: ✅ Yes"
|
|
235
|
-
else
|
|
236
|
-
echo " Executable: ❌ No"
|
|
237
|
-
fi
|
|
238
|
-
|
|
239
|
-
# Check git hook integration
|
|
240
|
-
local git_hook=".git/hooks/$hook_type"
|
|
241
|
-
if [ -x "$git_hook" ] && [ -f "$git_hook" ]; then
|
|
242
|
-
echo " Git Integration: ✅ Installed"
|
|
243
|
-
else
|
|
244
|
-
echo " Git Integration: ❌ Not installed"
|
|
245
|
-
fi
|
|
246
|
-
else
|
|
247
|
-
echo " Status: ❌ Missing"
|
|
248
|
-
fi
|
|
249
|
-
done
|
|
250
|
-
|
|
251
|
-
echo
|
|
252
|
-
log_info "Quick Actions:"
|
|
253
|
-
echo " Setup hooks: $0 setup"
|
|
254
|
-
echo " Install git hooks: $0 install"
|
|
255
|
-
echo " Test hooks: $0 test"
|
|
256
|
-
echo " Run hook: $0 run <hook-type>"
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
# Main command dispatcher
|
|
260
|
-
main() {
|
|
261
|
-
case "${1:-}" in
|
|
262
|
-
setup)
|
|
263
|
-
setup_hooks
|
|
264
|
-
;;
|
|
265
|
-
install)
|
|
266
|
-
install_git_hooks
|
|
267
|
-
;;
|
|
268
|
-
test)
|
|
269
|
-
test_hooks
|
|
270
|
-
;;
|
|
271
|
-
run)
|
|
272
|
-
run_hook "$2"
|
|
273
|
-
;;
|
|
274
|
-
status|"")
|
|
275
|
-
status
|
|
276
|
-
;;
|
|
277
|
-
help|--help|-h)
|
|
278
|
-
echo "Claude Code Hooks Manager"
|
|
279
|
-
echo "Usage: $0 <command> [options]"
|
|
280
|
-
echo ""
|
|
281
|
-
echo "Commands:"
|
|
282
|
-
echo " setup - Make all hooks executable"
|
|
283
|
-
echo " install - Install git hooks integration"
|
|
284
|
-
echo " test - Test all hooks for issues"
|
|
285
|
-
echo " run <type> - Run specific hook manually"
|
|
286
|
-
echo " status - Show hooks status (default)"
|
|
287
|
-
echo " help - Show this help"
|
|
288
|
-
echo ""
|
|
289
|
-
echo "Hook Types: ${!HOOK_TYPES[*]}"
|
|
290
|
-
;;
|
|
291
|
-
*)
|
|
292
|
-
log_error "Unknown command: $1"
|
|
293
|
-
echo "Run '$0 help' for usage information"
|
|
294
|
-
exit 1
|
|
295
|
-
;;
|
|
296
|
-
esac
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
# Run main function
|
|
300
|
-
main "$@"
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# HOOK: hook-manager
|
|
3
|
+
# DESCRIPTION: Central hook management and orchestration system
|
|
4
|
+
# AUTHOR: Claude Code Hooks Master
|
|
5
|
+
# VERSION: 1.0.0
|
|
6
|
+
|
|
7
|
+
set -e
|
|
8
|
+
|
|
9
|
+
# Colors and logging
|
|
10
|
+
GREEN='\033[0;32m'
|
|
11
|
+
BLUE='\033[0;34m'
|
|
12
|
+
YELLOW='\033[1;33m'
|
|
13
|
+
RED='\033[0;31m'
|
|
14
|
+
PURPLE='\033[0;35m'
|
|
15
|
+
NC='\033[0m'
|
|
16
|
+
|
|
17
|
+
log_info() {
|
|
18
|
+
echo -e "${BLUE}[HOOKS]${NC} $1"
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
log_success() {
|
|
22
|
+
echo -e "${GREEN}[SUCCESS]${NC} $1"
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
log_warn() {
|
|
26
|
+
echo -e "${YELLOW}[WARN]${NC} $1"
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
log_error() {
|
|
30
|
+
echo -e "${RED}[ERROR]${NC} $1"
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
log_ai() {
|
|
34
|
+
echo -e "${PURPLE}[🤖]${NC} $1"
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
# Hook configuration
|
|
38
|
+
HOOK_DIR=".claude/hooks"
|
|
39
|
+
declare -A HOOK_TYPES=(
|
|
40
|
+
["pre-commit"]="code-quality-guardian.sh"
|
|
41
|
+
["post-commit"]="smart-automations.sh"
|
|
42
|
+
["pre-push"]="deployment-guardian.sh"
|
|
43
|
+
["custom"]="intelligent-workflows.sh"
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
# Make hooks executable
|
|
47
|
+
setup_hooks() {
|
|
48
|
+
log_info "Setting up Claude Code hooks..."
|
|
49
|
+
|
|
50
|
+
for hook_type in "${!HOOK_TYPES[@]}"; do
|
|
51
|
+
local hook_file="$HOOK_DIR/$hook_type/${HOOK_TYPES[$hook_type]}"
|
|
52
|
+
|
|
53
|
+
if [ -f "$hook_file" ]; then
|
|
54
|
+
chmod +x "$hook_file"
|
|
55
|
+
log_success "Made $hook_type hook executable"
|
|
56
|
+
else
|
|
57
|
+
log_warn "Hook file not found: $hook_file"
|
|
58
|
+
fi
|
|
59
|
+
done
|
|
60
|
+
|
|
61
|
+
log_success "Hook setup completed"
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
# Install git hooks
|
|
65
|
+
install_git_hooks() {
|
|
66
|
+
log_info "Installing Git hooks integration..."
|
|
67
|
+
|
|
68
|
+
local git_hooks_dir=".git/hooks"
|
|
69
|
+
if [ ! -d "$git_hooks_dir" ]; then
|
|
70
|
+
log_error "Git repository not found - cannot install hooks"
|
|
71
|
+
return 1
|
|
72
|
+
fi
|
|
73
|
+
|
|
74
|
+
# Create pre-commit hook
|
|
75
|
+
cat > "$git_hooks_dir/pre-commit" << 'EOF'
|
|
76
|
+
#!/bin/bash
|
|
77
|
+
# Claude Code Pre-commit Hook
|
|
78
|
+
|
|
79
|
+
# Get the directory where this script is located
|
|
80
|
+
HOOK_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/../../.claude/hooks"
|
|
81
|
+
PRE_COMMIT_HOOK="$HOOK_DIR/pre-commit/code-quality-guardian.sh"
|
|
82
|
+
|
|
83
|
+
if [ -x "$PRE_COMMIT_HOOK" ]; then
|
|
84
|
+
echo "Running Claude Code pre-commit quality checks..."
|
|
85
|
+
if ! "$PRE_COMMIT_HOOK"; then
|
|
86
|
+
echo "Pre-commit checks failed. Please fix issues and try again."
|
|
87
|
+
exit 1
|
|
88
|
+
fi
|
|
89
|
+
else
|
|
90
|
+
echo "Warning: Claude Code pre-commit hook not found or not executable"
|
|
91
|
+
fi
|
|
92
|
+
EOF
|
|
93
|
+
|
|
94
|
+
# Create post-commit hook
|
|
95
|
+
cat > "$git_hooks_dir/post-commit" << 'EOF'
|
|
96
|
+
#!/bin/bash
|
|
97
|
+
# Claude Code Post-commit Hook
|
|
98
|
+
|
|
99
|
+
HOOK_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/../../.claude/hooks"
|
|
100
|
+
POST_COMMIT_HOOK="$HOOK_DIR/post-commit/smart-automations.sh"
|
|
101
|
+
|
|
102
|
+
if [ -x "$POST_COMMIT_HOOK" ]; then
|
|
103
|
+
echo "Running Claude Code post-commit automations..."
|
|
104
|
+
"$POST_COMMIT_HOOK" &
|
|
105
|
+
else
|
|
106
|
+
echo "Warning: Claude Code post-commit hook not found"
|
|
107
|
+
fi
|
|
108
|
+
EOF
|
|
109
|
+
|
|
110
|
+
# Create pre-push hook
|
|
111
|
+
cat > "$git_hooks_dir/pre-push" << 'EOF'
|
|
112
|
+
#!/bin/bash
|
|
113
|
+
# Claude Code Pre-push Hook
|
|
114
|
+
|
|
115
|
+
HOOK_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/../../.claude/hooks"
|
|
116
|
+
PRE_PUSH_HOOK="$HOOK_DIR/pre-push/deployment-guardian.sh"
|
|
117
|
+
|
|
118
|
+
if [ -x "$PRE_PUSH_HOOK" ]; then
|
|
119
|
+
echo "Running Claude Code pre-push deployment checks..."
|
|
120
|
+
if ! "$PRE_PUSH_HOOK"; then
|
|
121
|
+
echo "Pre-push checks failed. Please fix issues and try again."
|
|
122
|
+
exit 1
|
|
123
|
+
fi
|
|
124
|
+
else
|
|
125
|
+
echo "Warning: Claude Code pre-push hook not found or not executable"
|
|
126
|
+
fi
|
|
127
|
+
EOF
|
|
128
|
+
|
|
129
|
+
# Make git hooks executable
|
|
130
|
+
chmod +x "$git_hooks_dir/pre-commit"
|
|
131
|
+
chmod +x "$git_hooks_dir/post-commit"
|
|
132
|
+
chmod +x "$git_hooks_dir/pre-push"
|
|
133
|
+
|
|
134
|
+
log_success "Git hooks installed successfully"
|
|
135
|
+
log_info "Hooks will now run automatically on git operations"
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
# Test all hooks
|
|
139
|
+
test_hooks() {
|
|
140
|
+
log_info "Testing all Claude Code hooks..."
|
|
141
|
+
|
|
142
|
+
local test_results=()
|
|
143
|
+
|
|
144
|
+
for hook_type in "${!HOOK_TYPES[@]}"; do
|
|
145
|
+
local hook_file="$HOOK_DIR/$hook_type/${HOOK_TYPES[$hook_type]}"
|
|
146
|
+
|
|
147
|
+
if [ -f "$hook_file" ]; then
|
|
148
|
+
log_info "Testing $hook_type hook..."
|
|
149
|
+
|
|
150
|
+
# Basic syntax check
|
|
151
|
+
if bash -n "$hook_file" 2>/dev/null; then
|
|
152
|
+
log_success "$hook_type hook syntax is valid"
|
|
153
|
+
test_results+=("$hook_type: PASS")
|
|
154
|
+
else
|
|
155
|
+
log_error "$hook_type hook has syntax errors"
|
|
156
|
+
test_results+=("$hook_type: FAIL - Syntax Error")
|
|
157
|
+
fi
|
|
158
|
+
|
|
159
|
+
# Check if executable
|
|
160
|
+
if [ -x "$hook_file" ]; then
|
|
161
|
+
log_success "$hook_type hook is executable"
|
|
162
|
+
else
|
|
163
|
+
log_warn "$hook_type hook is not executable"
|
|
164
|
+
fi
|
|
165
|
+
else
|
|
166
|
+
log_error "$hook_type hook file not found: $hook_file"
|
|
167
|
+
test_results+=("$hook_type: FAIL - Missing")
|
|
168
|
+
fi
|
|
169
|
+
done
|
|
170
|
+
|
|
171
|
+
echo
|
|
172
|
+
log_info "Hook Test Results:"
|
|
173
|
+
for result in "${test_results[@]}"; do
|
|
174
|
+
echo " $result"
|
|
175
|
+
done
|
|
176
|
+
|
|
177
|
+
# Check for failures
|
|
178
|
+
if echo "${test_results[@]}" | grep -q "FAIL"; then
|
|
179
|
+
log_error "Some hooks have issues - please fix before using"
|
|
180
|
+
return 1
|
|
181
|
+
else
|
|
182
|
+
log_success "All hooks are properly configured!"
|
|
183
|
+
fi
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
# Run specific hook manually
|
|
187
|
+
run_hook() {
|
|
188
|
+
local hook_type="$1"
|
|
189
|
+
|
|
190
|
+
if [ -z "$hook_type" ]; then
|
|
191
|
+
log_error "Please specify a hook type to run"
|
|
192
|
+
echo "Available hooks: ${!HOOK_TYPES[*]}"
|
|
193
|
+
return 1
|
|
194
|
+
fi
|
|
195
|
+
|
|
196
|
+
if [ -z "${HOOK_TYPES[$hook_type]}" ]; then
|
|
197
|
+
log_error "Unknown hook type: $hook_type"
|
|
198
|
+
echo "Available hooks: ${!HOOK_TYPES[*]}"
|
|
199
|
+
return 1
|
|
200
|
+
fi
|
|
201
|
+
|
|
202
|
+
local hook_file="$HOOK_DIR/$hook_type/${HOOK_TYPES[$hook_type]}"
|
|
203
|
+
|
|
204
|
+
if [ ! -f "$hook_file" ]; then
|
|
205
|
+
log_error "Hook file not found: $hook_file"
|
|
206
|
+
return 1
|
|
207
|
+
fi
|
|
208
|
+
|
|
209
|
+
if [ ! -x "$hook_file" ]; then
|
|
210
|
+
log_error "Hook file is not executable: $hook_file"
|
|
211
|
+
return 1
|
|
212
|
+
fi
|
|
213
|
+
|
|
214
|
+
log_info "Running $hook_type hook manually..."
|
|
215
|
+
"$hook_file"
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
# Show hook status
|
|
219
|
+
status() {
|
|
220
|
+
log_info "Claude Code Hooks Status"
|
|
221
|
+
echo "=========================="
|
|
222
|
+
|
|
223
|
+
for hook_type in "${!HOOK_TYPES[@]}"; do
|
|
224
|
+
local hook_file="$HOOK_DIR/$hook_type/${HOOK_TYPES[$hook_type]}"
|
|
225
|
+
|
|
226
|
+
echo
|
|
227
|
+
echo "$hook_type hook:"
|
|
228
|
+
echo " File: $hook_file"
|
|
229
|
+
|
|
230
|
+
if [ -f "$hook_file" ]; then
|
|
231
|
+
echo " Status: ✅ Exists"
|
|
232
|
+
|
|
233
|
+
if [ -x "$hook_file" ]; then
|
|
234
|
+
echo " Executable: ✅ Yes"
|
|
235
|
+
else
|
|
236
|
+
echo " Executable: ❌ No"
|
|
237
|
+
fi
|
|
238
|
+
|
|
239
|
+
# Check git hook integration
|
|
240
|
+
local git_hook=".git/hooks/$hook_type"
|
|
241
|
+
if [ -x "$git_hook" ] && [ -f "$git_hook" ]; then
|
|
242
|
+
echo " Git Integration: ✅ Installed"
|
|
243
|
+
else
|
|
244
|
+
echo " Git Integration: ❌ Not installed"
|
|
245
|
+
fi
|
|
246
|
+
else
|
|
247
|
+
echo " Status: ❌ Missing"
|
|
248
|
+
fi
|
|
249
|
+
done
|
|
250
|
+
|
|
251
|
+
echo
|
|
252
|
+
log_info "Quick Actions:"
|
|
253
|
+
echo " Setup hooks: $0 setup"
|
|
254
|
+
echo " Install git hooks: $0 install"
|
|
255
|
+
echo " Test hooks: $0 test"
|
|
256
|
+
echo " Run hook: $0 run <hook-type>"
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
# Main command dispatcher
|
|
260
|
+
main() {
|
|
261
|
+
case "${1:-}" in
|
|
262
|
+
setup)
|
|
263
|
+
setup_hooks
|
|
264
|
+
;;
|
|
265
|
+
install)
|
|
266
|
+
install_git_hooks
|
|
267
|
+
;;
|
|
268
|
+
test)
|
|
269
|
+
test_hooks
|
|
270
|
+
;;
|
|
271
|
+
run)
|
|
272
|
+
run_hook "$2"
|
|
273
|
+
;;
|
|
274
|
+
status|"")
|
|
275
|
+
status
|
|
276
|
+
;;
|
|
277
|
+
help|--help|-h)
|
|
278
|
+
echo "Claude Code Hooks Manager"
|
|
279
|
+
echo "Usage: $0 <command> [options]"
|
|
280
|
+
echo ""
|
|
281
|
+
echo "Commands:"
|
|
282
|
+
echo " setup - Make all hooks executable"
|
|
283
|
+
echo " install - Install git hooks integration"
|
|
284
|
+
echo " test - Test all hooks for issues"
|
|
285
|
+
echo " run <type> - Run specific hook manually"
|
|
286
|
+
echo " status - Show hooks status (default)"
|
|
287
|
+
echo " help - Show this help"
|
|
288
|
+
echo ""
|
|
289
|
+
echo "Hook Types: ${!HOOK_TYPES[*]}"
|
|
290
|
+
;;
|
|
291
|
+
*)
|
|
292
|
+
log_error "Unknown command: $1"
|
|
293
|
+
echo "Run '$0 help' for usage information"
|
|
294
|
+
exit 1
|
|
295
|
+
;;
|
|
296
|
+
esac
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
# Run main function
|
|
300
|
+
main "$@"
|