@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,336 +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
|
|
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
|