claude-code-toolkit 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 +476 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +183 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/install.d.ts +8 -0
- package/dist/commands/install.d.ts.map +1 -0
- package/dist/commands/install.js +184 -0
- package/dist/commands/install.js.map +1 -0
- package/dist/commands/list.d.ts +2 -0
- package/dist/commands/list.d.ts.map +1 -0
- package/dist/commands/list.js +134 -0
- package/dist/commands/list.js.map +1 -0
- package/dist/commands/template.d.ts +2 -0
- package/dist/commands/template.d.ts.map +1 -0
- package/dist/commands/template.js +299 -0
- package/dist/commands/template.js.map +1 -0
- package/dist/commands/update.d.ts +2 -0
- package/dist/commands/update.d.ts.map +1 -0
- package/dist/commands/update.js +21 -0
- package/dist/commands/update.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +19 -0
- package/dist/index.js.map +1 -0
- package/package.json +65 -0
- package/templates/.claude/hooks/README.md +342 -0
- package/templates/.claude/hooks/custom/intelligent-workflows.sh +336 -0
- package/templates/.claude/hooks/hook-manager.sh +300 -0
- package/templates/.claude/hooks/post-commit/smart-automations.sh +249 -0
- package/templates/.claude/hooks/pre-commit/code-quality-guardian.sh +257 -0
- package/templates/.claude/hooks/pre-push/deployment-guardian.sh +334 -0
- package/templates/.claude/memory/context.md +39 -0
- package/templates/.claude/memory/decisions.md +29 -0
- package/templates/.claude/memory/learnings.md +31 -0
- package/templates/.claude/memory/patterns.md +72 -0
- package/templates/.claude/memory/preferences.md +23 -0
- package/templates/.claude/skills/claude-code-hooks-master/SKILL.md +358 -0
- package/templates/.claude/skills/mobile-ui-ux-master/MobileCardGrid.tsx +270 -0
- package/templates/.claude/skills/mobile-ui-ux-master/SKILL.md +172 -0
- package/templates/.claude/skills/mobile-ui-ux-master/card-grid-template.html +260 -0
- package/templates/.claude/skills/mobile-ui-ux-master/mobile-ux-checklist.md +140 -0
- package/templates/.claude/skills/professional-documentation-writer/SKILL.md +42 -0
- package/templates/AGENTS.md +127 -0
- package/templates/CLAUDE.md +101 -0
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# HOOK: custom-intelligent-workflows
|
|
3
|
+
# DESCRIPTION: AI-powered workflow automation based on file changes and project context
|
|
4
|
+
# AUTHOR: Claude Code Hooks Master
|
|
5
|
+
# VERSION: 1.0.0
|
|
6
|
+
# TRIGGER: Manual execution or integration with file watchers
|
|
7
|
+
|
|
8
|
+
set -e
|
|
9
|
+
|
|
10
|
+
# Colors and logging
|
|
11
|
+
GREEN='\033[0;32m'
|
|
12
|
+
BLUE='\033[0;34m'
|
|
13
|
+
YELLOW='\033[1;33m'
|
|
14
|
+
RED='\033[0;31m'
|
|
15
|
+
PURPLE='\033[0;35m'
|
|
16
|
+
NC='\033[0m'
|
|
17
|
+
|
|
18
|
+
log_info() {
|
|
19
|
+
echo -e "${BLUE}[AI]${NC} $1"
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
log_success() {
|
|
23
|
+
echo -e "${GREEN}[SUCCESS]${NC} $1"
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
log_warn() {
|
|
27
|
+
echo -e "${YELLOW}[WARN]${NC} $1"
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
log_error() {
|
|
31
|
+
echo -e "${RED}[ERROR]${NC} $1"
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
log_ai() {
|
|
35
|
+
echo -e "${PURPLE}[🤖]${NC} $1"
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
# Analyze file changes and determine appropriate actions
|
|
39
|
+
analyze_changes() {
|
|
40
|
+
log_ai "Analyzing recent file changes..."
|
|
41
|
+
|
|
42
|
+
# Get recent changes (last commit or staged files)
|
|
43
|
+
local changed_files
|
|
44
|
+
if git diff --cached --name-only | head -1 > /dev/null 2>&1; then
|
|
45
|
+
# Staged changes
|
|
46
|
+
mapfile -t changed_files < <(git diff --cached --name-only)
|
|
47
|
+
else
|
|
48
|
+
# Last commit changes
|
|
49
|
+
mapfile -t changed_files < <(git diff --name-only HEAD~1 2>/dev/null || git ls-files)
|
|
50
|
+
fi
|
|
51
|
+
|
|
52
|
+
# Categorize changes
|
|
53
|
+
local categories=("ui" "api" "config" "docs" "tests" "security" "performance")
|
|
54
|
+
declare -A change_types
|
|
55
|
+
|
|
56
|
+
for category in "${categories[@]}"; do
|
|
57
|
+
change_types[$category]=0
|
|
58
|
+
done
|
|
59
|
+
|
|
60
|
+
for file in "${changed_files[@]}"; do
|
|
61
|
+
case $file in
|
|
62
|
+
*component*|*ui/*|*screen/*|*view/*)
|
|
63
|
+
((change_types[ui]++))
|
|
64
|
+
;;
|
|
65
|
+
*api/*|*service/*|*endpoint/*)
|
|
66
|
+
((change_types[api]++))
|
|
67
|
+
;;
|
|
68
|
+
*config*|*.env*|package.json|tsconfig.json)
|
|
69
|
+
((change_types[config]++))
|
|
70
|
+
;;
|
|
71
|
+
*README*|*.md|docs/*)
|
|
72
|
+
((change_types[docs]++))
|
|
73
|
+
;;
|
|
74
|
+
*.test.*|*.spec.*|test/*)
|
|
75
|
+
((change_types[tests]++))
|
|
76
|
+
;;
|
|
77
|
+
*auth/*|*security/*|*encrypt*)
|
|
78
|
+
((change_types[security]++))
|
|
79
|
+
;;
|
|
80
|
+
*performance*|*optimize*|*cache*)
|
|
81
|
+
((change_types[performance]++))
|
|
82
|
+
;;
|
|
83
|
+
esac
|
|
84
|
+
done
|
|
85
|
+
|
|
86
|
+
# Determine primary change type
|
|
87
|
+
local max_changes=0
|
|
88
|
+
local primary_type="general"
|
|
89
|
+
|
|
90
|
+
for category in "${!change_types[@]}"; do
|
|
91
|
+
if [ "${change_types[$category]}" -gt "$max_changes" ]; then
|
|
92
|
+
max_changes=${change_types[$category]}
|
|
93
|
+
primary_type=$category
|
|
94
|
+
fi
|
|
95
|
+
done
|
|
96
|
+
|
|
97
|
+
echo "$primary_type"
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
# Trigger appropriate Claude Code agents based on change type
|
|
101
|
+
trigger_agents() {
|
|
102
|
+
local change_type="$1"
|
|
103
|
+
|
|
104
|
+
log_ai "Triggering specialized agents for $change_type changes..."
|
|
105
|
+
|
|
106
|
+
case $change_type in
|
|
107
|
+
ui)
|
|
108
|
+
log_info "UI changes detected - triggering mobile UI specialist"
|
|
109
|
+
if command -v claude_code_run_agent &> /dev/null; then
|
|
110
|
+
claude_code_run_agent "mobile-ui-specialist" "review-ui-consistency" || true
|
|
111
|
+
fi
|
|
112
|
+
;;
|
|
113
|
+
|
|
114
|
+
security)
|
|
115
|
+
log_info "Security changes detected - triggering code reviewer"
|
|
116
|
+
if command -v claude_code_run_agent &> /dev/null; then
|
|
117
|
+
claude_code_run_agent "code-reviewer" "security-audit" || true
|
|
118
|
+
fi
|
|
119
|
+
;;
|
|
120
|
+
|
|
121
|
+
api)
|
|
122
|
+
log_info "API changes detected - triggering documentation agent"
|
|
123
|
+
if command -v claude_code_run_agent &> /dev/null; then
|
|
124
|
+
claude_code_run_agent "doc-writer" "update-api-docs" || true
|
|
125
|
+
fi
|
|
126
|
+
;;
|
|
127
|
+
|
|
128
|
+
tests)
|
|
129
|
+
log_info "Test changes detected - triggering testing agent"
|
|
130
|
+
if command -v claude_code_run_agent &> /dev/null; then
|
|
131
|
+
claude_code_run_agent "test-generator" "validate-test-coverage" || true
|
|
132
|
+
fi
|
|
133
|
+
;;
|
|
134
|
+
|
|
135
|
+
config)
|
|
136
|
+
log_info "Configuration changes detected - triggering code reviewer"
|
|
137
|
+
if command -v claude_code_run_agent &> /dev/null; then
|
|
138
|
+
claude_code_run_agent "code-reviewer" "config-review" || true
|
|
139
|
+
fi
|
|
140
|
+
;;
|
|
141
|
+
|
|
142
|
+
docs)
|
|
143
|
+
log_info "Documentation changes detected - triggering documentation agent"
|
|
144
|
+
if command -v claude_code_run_agent &> /dev/null; then
|
|
145
|
+
claude_code_run_agent "doc-writer" "validate-docs" || true
|
|
146
|
+
fi
|
|
147
|
+
;;
|
|
148
|
+
esac
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
# Intelligent documentation updates
|
|
152
|
+
smart_docs_update() {
|
|
153
|
+
local change_type="$1"
|
|
154
|
+
|
|
155
|
+
log_ai "Analyzing documentation needs..."
|
|
156
|
+
|
|
157
|
+
case $change_type in
|
|
158
|
+
api)
|
|
159
|
+
log_info "API changes - checking if README API section needs updates"
|
|
160
|
+
# Check if API documentation is outdated
|
|
161
|
+
;;
|
|
162
|
+
|
|
163
|
+
ui)
|
|
164
|
+
log_info "UI changes - considering component documentation updates"
|
|
165
|
+
# Check component documentation
|
|
166
|
+
;;
|
|
167
|
+
|
|
168
|
+
config)
|
|
169
|
+
log_info "Config changes - updating configuration documentation"
|
|
170
|
+
# Update config docs
|
|
171
|
+
;;
|
|
172
|
+
esac
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
# Performance monitoring and optimization suggestions
|
|
176
|
+
performance_intelligence() {
|
|
177
|
+
log_ai "Analyzing performance implications..."
|
|
178
|
+
|
|
179
|
+
# Check for potential performance issues
|
|
180
|
+
local perf_issues=()
|
|
181
|
+
|
|
182
|
+
# Large files
|
|
183
|
+
local large_files
|
|
184
|
+
mapfile -t large_files < <(find . -name "*.js" -o -name "*.ts" -o -name "*.jsx" -o -name "*.tsx" | xargs ls -lh | awk '$5 > 500000 {print $9}' | head -3)
|
|
185
|
+
if [ ${#large_files[@]} -gt 0 ]; then
|
|
186
|
+
perf_issues+=("Large files detected: ${large_files[*]}")
|
|
187
|
+
fi
|
|
188
|
+
|
|
189
|
+
# Inefficient patterns
|
|
190
|
+
if git grep -q "for.*in.*array" -- "*.js" "*.ts" "*.jsx" "*.tsx" 2>/dev/null; then
|
|
191
|
+
perf_issues+=("Inefficient array iteration patterns found")
|
|
192
|
+
fi
|
|
193
|
+
|
|
194
|
+
# Bundle analysis (if applicable)
|
|
195
|
+
if [ -f "package.json" ] && grep -q "webpack\|parcel\|vite" package.json; then
|
|
196
|
+
perf_issues+=("Consider bundle size analysis")
|
|
197
|
+
fi
|
|
198
|
+
|
|
199
|
+
if [ ${#perf_issues[@]} -gt 0 ]; then
|
|
200
|
+
log_warn "Performance considerations:"
|
|
201
|
+
for issue in "${perf_issues[@]}"; do
|
|
202
|
+
echo " • $issue"
|
|
203
|
+
done
|
|
204
|
+
|
|
205
|
+
# Suggest Claude Code agent
|
|
206
|
+
if command -v claude_code_run_agent &> /dev/null; then
|
|
207
|
+
claude_code_run_agent "debugger" "performance-review" || true
|
|
208
|
+
fi
|
|
209
|
+
else
|
|
210
|
+
log_success "No performance concerns detected"
|
|
211
|
+
fi
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
# Learning and memory integration
|
|
215
|
+
update_project_memory() {
|
|
216
|
+
log_ai "Updating project learning memory..."
|
|
217
|
+
|
|
218
|
+
local memory_dir=".claude/memory"
|
|
219
|
+
if [ ! -d "$memory_dir" ]; then
|
|
220
|
+
log_warn "Memory system not found - skipping learning updates"
|
|
221
|
+
return 0
|
|
222
|
+
fi
|
|
223
|
+
|
|
224
|
+
# Analyze patterns in recent changes
|
|
225
|
+
local recent_patterns
|
|
226
|
+
recent_patterns=$(git log --oneline -10 | grep -o -E "(feat|fix|refactor|docs|style|test)" | sort | uniq -c | sort -nr)
|
|
227
|
+
|
|
228
|
+
if echo "$recent_patterns" | grep -q "feat"; then
|
|
229
|
+
echo "## $(date) - Feature Development Pattern" >> "$memory_dir/learnings.md"
|
|
230
|
+
echo "**Pattern**: High feature development activity detected" >> "$memory_dir/learnings.md"
|
|
231
|
+
echo "**Context**: Recent commits show active feature development" >> "$memory_dir/learnings.md"
|
|
232
|
+
echo "**Suggestion**: Consider integration testing for new features" >> "$memory_dir/learnings.md"
|
|
233
|
+
echo >> "$memory_dir/learnings.md"
|
|
234
|
+
fi
|
|
235
|
+
|
|
236
|
+
log_success "Project memory updated with recent patterns"
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
# Predictive suggestions
|
|
240
|
+
predictive_suggestions() {
|
|
241
|
+
log_ai "Generating predictive development suggestions..."
|
|
242
|
+
|
|
243
|
+
local suggestions=()
|
|
244
|
+
|
|
245
|
+
# Based on current changes, predict next likely steps
|
|
246
|
+
if git diff --name-only | grep -q "component.*test"; then
|
|
247
|
+
suggestions+=("Consider adding integration tests for the new component")
|
|
248
|
+
fi
|
|
249
|
+
|
|
250
|
+
if git diff --name-only | grep -q "api.*route"; then
|
|
251
|
+
suggestions+=("Don't forget to update API documentation")
|
|
252
|
+
suggestions+=("Consider adding request/response validation")
|
|
253
|
+
fi
|
|
254
|
+
|
|
255
|
+
if git diff --name-only | grep -q "config"; then
|
|
256
|
+
suggestions+=("Test configuration changes across different environments")
|
|
257
|
+
fi
|
|
258
|
+
|
|
259
|
+
if [ ${#suggestions[@]} -gt 0 ]; then
|
|
260
|
+
log_info "🤖 Predictive suggestions for next steps:"
|
|
261
|
+
for suggestion in "${suggestions[@]}"; do
|
|
262
|
+
echo " • $suggestion"
|
|
263
|
+
done
|
|
264
|
+
fi
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
# Workflow optimization
|
|
268
|
+
optimize_workflow() {
|
|
269
|
+
log_ai "Analyzing workflow optimization opportunities..."
|
|
270
|
+
|
|
271
|
+
# Check for repeated patterns that could be automated
|
|
272
|
+
local repeated_actions
|
|
273
|
+
repeated_actions=$(git log --oneline -20 | grep -o -E "(add|update|fix|refactor)" | sort | uniq -c | awk '$1 > 3 {print $2}')
|
|
274
|
+
|
|
275
|
+
if [ -n "$repeated_actions" ]; then
|
|
276
|
+
log_info "🔄 Detected repetitive actions that could be automated:"
|
|
277
|
+
echo "$repeated_actions" | while read -r action; do
|
|
278
|
+
echo " • Frequent '$action' operations - consider creating a custom hook"
|
|
279
|
+
done
|
|
280
|
+
fi
|
|
281
|
+
|
|
282
|
+
# Suggest improvements based on commit patterns
|
|
283
|
+
if git log --oneline -10 | grep -q "WIP\|temp\|fix.*later"; then
|
|
284
|
+
log_warn "Frequent WIP commits detected - consider feature branches"
|
|
285
|
+
fi
|
|
286
|
+
|
|
287
|
+
if git log --oneline -10 | grep -q "merge.*conflict"; then
|
|
288
|
+
log_warn "Merge conflicts detected - consider smaller, focused commits"
|
|
289
|
+
fi
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
# Main execution
|
|
293
|
+
main() {
|
|
294
|
+
log_ai "🧠 Claude Code Intelligent Workflows - Custom Hook"
|
|
295
|
+
echo "======================================================"
|
|
296
|
+
|
|
297
|
+
# Analyze changes
|
|
298
|
+
local change_type
|
|
299
|
+
change_type=$(analyze_changes)
|
|
300
|
+
|
|
301
|
+
log_info "Primary change type detected: $change_type"
|
|
302
|
+
echo
|
|
303
|
+
|
|
304
|
+
# Execute intelligent automations
|
|
305
|
+
trigger_agents "$change_type"
|
|
306
|
+
smart_docs_update "$change_type"
|
|
307
|
+
performance_intelligence
|
|
308
|
+
update_project_memory
|
|
309
|
+
predictive_suggestions
|
|
310
|
+
optimize_workflow
|
|
311
|
+
|
|
312
|
+
echo
|
|
313
|
+
log_success "🎉 Intelligent workflow analysis completed!"
|
|
314
|
+
log_ai "All automations triggered based on your code changes"
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
# Allow manual execution
|
|
318
|
+
if [ "${1:-}" = "--manual" ]; then
|
|
319
|
+
log_info "Manual execution requested"
|
|
320
|
+
main
|
|
321
|
+
elif [ "${1:-}" = "--help" ]; then
|
|
322
|
+
echo "Intelligent Workflows Hook"
|
|
323
|
+
echo "Usage: $0 [--manual] [--help]"
|
|
324
|
+
echo ""
|
|
325
|
+
echo "This hook analyzes code changes and triggers intelligent automations:"
|
|
326
|
+
echo " - Agent triggering based on change types"
|
|
327
|
+
echo " - Smart documentation updates"
|
|
328
|
+
echo " - Performance analysis"
|
|
329
|
+
echo " - Memory system updates"
|
|
330
|
+
echo " - Predictive suggestions"
|
|
331
|
+
echo " - Workflow optimization"
|
|
332
|
+
exit 0
|
|
333
|
+
else
|
|
334
|
+
# Auto-execution mode (would be called by file watchers or CI)
|
|
335
|
+
main
|
|
336
|
+
fi
|
|
@@ -0,0 +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 "$@"
|