@localtech/claude-code-toolkit 1.0.3 → 1.0.4
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/package.json +1 -1
- 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
package/package.json
CHANGED
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
# Claude Code Hooks Automation System
|
|
2
|
+
|
|
3
|
+
This directory contains a comprehensive automation system that leverages Claude Code hooks to dramatically improve development efficiency, code quality, and workflow intelligence.
|
|
4
|
+
|
|
5
|
+
## 🚀 What Are Claude Code Hooks?
|
|
6
|
+
|
|
7
|
+
Hooks are automated scripts that run at specific points in your development workflow. Unlike traditional Git hooks, Claude Code hooks integrate deeply with AI agents and skills to provide intelligent, context-aware automation.
|
|
8
|
+
|
|
9
|
+
## 🎯 Key Benefits
|
|
10
|
+
|
|
11
|
+
### ⚡ **Development Efficiency**
|
|
12
|
+
- **Automated Quality Checks**: Pre-commit hooks catch issues before they reach CI/CD
|
|
13
|
+
- **Smart Automations**: Post-commit hooks handle documentation, notifications, and cleanup
|
|
14
|
+
- **Deployment Safety**: Pre-push hooks validate code readiness for production
|
|
15
|
+
|
|
16
|
+
### 🧠 **Intelligent Workflows**
|
|
17
|
+
- **Agent Integration**: Hooks automatically trigger appropriate Claude Code agents based on changes
|
|
18
|
+
- **Context Awareness**: Scripts analyze file changes to determine optimal actions
|
|
19
|
+
- **Predictive Suggestions**: AI-powered recommendations for next development steps
|
|
20
|
+
|
|
21
|
+
### 📊 **Quality Assurance**
|
|
22
|
+
- **Consistent Standards**: Enforced coding standards and best practices
|
|
23
|
+
- **Security Validation**: Automated security checks and vulnerability scanning
|
|
24
|
+
- **Performance Monitoring**: Build size and performance regression detection
|
|
25
|
+
|
|
26
|
+
### 🔄 **Workflow Optimization**
|
|
27
|
+
- **Memory Integration**: Project learning and pattern recognition
|
|
28
|
+
- **Documentation Automation**: Auto-generated docs that stay current
|
|
29
|
+
- **Collaboration Enhancement**: Team notifications and coordination
|
|
30
|
+
|
|
31
|
+
## 📁 Hook Structure
|
|
32
|
+
|
|
33
|
+
```
|
|
34
|
+
.claude/hooks/
|
|
35
|
+
├── pre-commit/
|
|
36
|
+
│ └── code-quality-guardian.sh # Quality checks before commits
|
|
37
|
+
├── post-commit/
|
|
38
|
+
│ └── smart-automations.sh # Intelligent post-commit actions
|
|
39
|
+
├── pre-push/
|
|
40
|
+
│ └── deployment-guardian.sh # Deployment validation
|
|
41
|
+
├── custom/
|
|
42
|
+
│ └── intelligent-workflows.sh # AI-powered workflow analysis
|
|
43
|
+
└── hook-manager.sh # Central hook management
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## 🛠️ Quick Setup
|
|
47
|
+
|
|
48
|
+
### 1. Make Hooks Executable
|
|
49
|
+
```bash
|
|
50
|
+
# From your project root
|
|
51
|
+
.claude/hooks/hook-manager.sh setup
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### 2. Install Git Integration
|
|
55
|
+
```bash
|
|
56
|
+
# Install hooks into Git
|
|
57
|
+
.claude/hooks/hook-manager.sh install
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### 3. Test Everything
|
|
61
|
+
```bash
|
|
62
|
+
# Verify all hooks work correctly
|
|
63
|
+
.claude/hooks/hook-manager.sh test
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### 4. Check Status
|
|
67
|
+
```bash
|
|
68
|
+
# See hook status and available commands
|
|
69
|
+
.claude/hooks/hook-manager.sh status
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## 🎭 Hook Types & Timing
|
|
73
|
+
|
|
74
|
+
### 🔍 **Pre-commit Hook** (`code-quality-guardian.sh`)
|
|
75
|
+
**When**: Before code is committed to local repository
|
|
76
|
+
**Purpose**: Quality assurance and consistency validation
|
|
77
|
+
**Checks**:
|
|
78
|
+
- ESLint/Prettier code formatting
|
|
79
|
+
- TypeScript type checking
|
|
80
|
+
- Security vulnerability scanning
|
|
81
|
+
- Performance regression detection
|
|
82
|
+
|
|
83
|
+
**Timing**: < 10 seconds (blocking - prevents bad commits)
|
|
84
|
+
|
|
85
|
+
### 🤖 **Post-commit Hook** (`smart-automations.sh`)
|
|
86
|
+
**When**: After successful commit to local repository
|
|
87
|
+
**Purpose**: Intelligent automations and notifications
|
|
88
|
+
**Actions**:
|
|
89
|
+
- Documentation updates
|
|
90
|
+
- Team notifications
|
|
91
|
+
- Memory system updates
|
|
92
|
+
- Backup creation
|
|
93
|
+
|
|
94
|
+
**Timing**: < 60 seconds (background processing)
|
|
95
|
+
|
|
96
|
+
### 🚀 **Pre-push Hook** (`deployment-guardian.sh`)
|
|
97
|
+
**When**: Before pushing to remote repository
|
|
98
|
+
**Purpose**: Deployment readiness validation
|
|
99
|
+
**Validations**:
|
|
100
|
+
- Comprehensive test suite execution
|
|
101
|
+
- Build verification
|
|
102
|
+
- Security audits
|
|
103
|
+
- Environment-specific checks
|
|
104
|
+
|
|
105
|
+
**Timing**: < 30 seconds (blocking - prevents broken deployments)
|
|
106
|
+
|
|
107
|
+
### 🧠 **Custom Hook** (`intelligent-workflows.sh`)
|
|
108
|
+
**When**: Manual execution or triggered by file changes
|
|
109
|
+
**Purpose**: AI-powered workflow analysis and optimization
|
|
110
|
+
**Capabilities**:
|
|
111
|
+
- Change analysis and categorization
|
|
112
|
+
- Agent triggering based on change types
|
|
113
|
+
- Predictive development suggestions
|
|
114
|
+
- Workflow optimization recommendations
|
|
115
|
+
|
|
116
|
+
## 💡 Usage Examples
|
|
117
|
+
|
|
118
|
+
### Automatic Quality Enforcement
|
|
119
|
+
```bash
|
|
120
|
+
# Try to commit code with linting errors
|
|
121
|
+
git add .
|
|
122
|
+
git commit -m "Add new feature"
|
|
123
|
+
|
|
124
|
+
# Hook automatically runs:
|
|
125
|
+
# ✅ ESLint checks
|
|
126
|
+
# ✅ TypeScript compilation
|
|
127
|
+
# ✅ Security scanning
|
|
128
|
+
# ✅ Formatting validation
|
|
129
|
+
|
|
130
|
+
# If issues found:
|
|
131
|
+
# ❌ Commit blocked with helpful error messages
|
|
132
|
+
# 💡 Suggestions for fixes
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### Intelligent Post-commit Automation
|
|
136
|
+
```bash
|
|
137
|
+
# Commit API changes
|
|
138
|
+
git commit -m "feat: add user authentication endpoint"
|
|
139
|
+
|
|
140
|
+
# Hook automatically:
|
|
141
|
+
# 📚 Updates API documentation
|
|
142
|
+
# 🔔 Notifies team about new endpoint
|
|
143
|
+
# 🧠 Adds to project memory system
|
|
144
|
+
# 💾 Creates backup for high-impact changes
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### Deployment Safety Net
|
|
148
|
+
```bash
|
|
149
|
+
# Push to main branch
|
|
150
|
+
git push origin main
|
|
151
|
+
|
|
152
|
+
# Hook validates:
|
|
153
|
+
# 🧪 Runs full test suite
|
|
154
|
+
# 🏗️ Verifies production build
|
|
155
|
+
# 🔒 Performs security audit
|
|
156
|
+
# 🌍 Checks deployment environment
|
|
157
|
+
|
|
158
|
+
# Only allows push if all checks pass
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
### AI-Powered Workflow Intelligence
|
|
162
|
+
```bash
|
|
163
|
+
# Manual workflow analysis
|
|
164
|
+
.claude/hooks/custom/intelligent-workflows.sh --manual
|
|
165
|
+
|
|
166
|
+
# Analyzes recent changes and:
|
|
167
|
+
# 🎯 Triggers appropriate agents (mobile-ui-specialist for UI changes)
|
|
168
|
+
# 📊 Updates performance metrics
|
|
169
|
+
# 🔮 Provides predictive suggestions
|
|
170
|
+
# 📈 Identifies workflow optimization opportunities
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
## 🔗 Integration with Claude Code Agents
|
|
174
|
+
|
|
175
|
+
Hooks automatically integrate with your specialized agents:
|
|
176
|
+
|
|
177
|
+
### **File Change → Agent Triggering**
|
|
178
|
+
- **UI Changes** → `mobile-ui-specialist` reviews consistency
|
|
179
|
+
- **Security Files** → `code-reviewer` performs security audit
|
|
180
|
+
- **API Changes** → `doc-writer` updates documentation
|
|
181
|
+
- **Test Files** → `test-generator` validates coverage
|
|
182
|
+
|
|
183
|
+
### **Memory System Integration**
|
|
184
|
+
- **Decisions** → Architectural choices automatically logged
|
|
185
|
+
- **Learnings** → Development insights captured
|
|
186
|
+
- **Patterns** → Common solutions tracked
|
|
187
|
+
- **Context** → Project state maintained
|
|
188
|
+
|
|
189
|
+
## ⚙️ Configuration
|
|
190
|
+
|
|
191
|
+
### Environment Variables
|
|
192
|
+
```bash
|
|
193
|
+
# Hook behavior configuration
|
|
194
|
+
CLAUDE_CODE_HOOKS_DEBUG=true # Enable debug logging
|
|
195
|
+
CLAUDE_CODE_HOOKS_STRICT=true # Fail on warnings
|
|
196
|
+
CLAUDE_CODE_AUTO_BACKUP=true # Enable automatic backups
|
|
197
|
+
CLAUDE_CODE_SMART_NOTIFICATIONS=true # Enable team notifications
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
### Hook Customization
|
|
201
|
+
Each hook can be customized by editing the script files:
|
|
202
|
+
- **Thresholds**: Adjust performance limits and quality standards
|
|
203
|
+
- **Integrations**: Add your preferred notification services
|
|
204
|
+
- **Rules**: Modify validation logic for your project needs
|
|
205
|
+
|
|
206
|
+
## 📊 Monitoring & Analytics
|
|
207
|
+
|
|
208
|
+
### Performance Metrics
|
|
209
|
+
Hooks automatically track:
|
|
210
|
+
- Execution times for each validation
|
|
211
|
+
- Success/failure rates
|
|
212
|
+
- Most common issues found
|
|
213
|
+
- Performance trends over time
|
|
214
|
+
|
|
215
|
+
### Quality Analytics
|
|
216
|
+
- Code quality improvement trends
|
|
217
|
+
- Most frequent validation failures
|
|
218
|
+
- Team productivity metrics
|
|
219
|
+
- Deployment success rates
|
|
220
|
+
|
|
221
|
+
## 🐛 Troubleshooting
|
|
222
|
+
|
|
223
|
+
### Common Issues
|
|
224
|
+
|
|
225
|
+
**Hooks not running:**
|
|
226
|
+
```bash
|
|
227
|
+
# Check hook status
|
|
228
|
+
.claude/hooks/hook-manager.sh status
|
|
229
|
+
|
|
230
|
+
# Verify Git hooks are installed
|
|
231
|
+
ls -la .git/hooks/
|
|
232
|
+
|
|
233
|
+
# Test individual hooks
|
|
234
|
+
.claude/hooks/hook-manager.sh test
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
**Slow performance:**
|
|
238
|
+
- Reduce test scope for pre-commit hooks
|
|
239
|
+
- Move heavy operations to post-commit
|
|
240
|
+
- Cache results where possible
|
|
241
|
+
- Use parallel execution for independent checks
|
|
242
|
+
|
|
243
|
+
**False positives:**
|
|
244
|
+
- Adjust validation rules in hook scripts
|
|
245
|
+
- Add project-specific exceptions
|
|
246
|
+
- Fine-tune security scanning rules
|
|
247
|
+
|
|
248
|
+
## 🔧 Advanced Features
|
|
249
|
+
|
|
250
|
+
### Custom Hook Creation
|
|
251
|
+
Create new hooks for specific workflows:
|
|
252
|
+
```bash
|
|
253
|
+
# Create custom hook directory
|
|
254
|
+
mkdir .claude/hooks/custom/my-workflow
|
|
255
|
+
|
|
256
|
+
# Create hook script
|
|
257
|
+
cat > .claude/hooks/custom/my-workflow/my-hook.sh << 'EOF'
|
|
258
|
+
#!/bin/bash
|
|
259
|
+
# Custom workflow hook
|
|
260
|
+
echo "Running custom automation..."
|
|
261
|
+
# Your automation logic here
|
|
262
|
+
EOF
|
|
263
|
+
|
|
264
|
+
# Make executable and test
|
|
265
|
+
chmod +x .claude/hooks/custom/my-workflow/my-hook.sh
|
|
266
|
+
.claude/hooks/hook-manager.sh test
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
### CI/CD Integration
|
|
270
|
+
Hooks work seamlessly with CI/CD pipelines:
|
|
271
|
+
- Local validation before push
|
|
272
|
+
- Consistent standards across team
|
|
273
|
+
- Early issue detection
|
|
274
|
+
- Automated deployment preparation
|
|
275
|
+
|
|
276
|
+
### Multi-environment Support
|
|
277
|
+
Hooks automatically detect environment:
|
|
278
|
+
- **Development**: Relaxed validation, fast feedback
|
|
279
|
+
- **Staging**: Full validation, integration tests
|
|
280
|
+
- **Production**: Strict validation, security audits
|
|
281
|
+
|
|
282
|
+
## 📈 Performance Optimization
|
|
283
|
+
|
|
284
|
+
### Hook Performance Guidelines
|
|
285
|
+
- **Pre-commit**: < 10 seconds (developer experience)
|
|
286
|
+
- **Pre-push**: < 30 seconds (deployment safety)
|
|
287
|
+
- **Post-commit**: < 60 seconds (background tasks)
|
|
288
|
+
- **Custom**: As needed (manual execution)
|
|
289
|
+
|
|
290
|
+
### Optimization Techniques
|
|
291
|
+
- **Caching**: Cache expensive operations
|
|
292
|
+
- **Incremental Checks**: Only check changed files
|
|
293
|
+
- **Parallel Execution**: Run independent validations concurrently
|
|
294
|
+
- **Selective Running**: Skip irrelevant checks based on changes
|
|
295
|
+
|
|
296
|
+
## 🔐 Security Considerations
|
|
297
|
+
|
|
298
|
+
### Safe Hook Practices
|
|
299
|
+
- **Input Validation**: Never trust user-provided data
|
|
300
|
+
- **Permission Limits**: Run with minimal required permissions
|
|
301
|
+
- **Network Security**: Use HTTPS for all external calls
|
|
302
|
+
- **Secret Management**: Never log sensitive information
|
|
303
|
+
|
|
304
|
+
### Audit Trail
|
|
305
|
+
- All hook executions are logged
|
|
306
|
+
- Security events are tracked
|
|
307
|
+
- Performance metrics are monitored
|
|
308
|
+
- Compliance with security policies
|
|
309
|
+
|
|
310
|
+
## 🎯 Success Metrics
|
|
311
|
+
|
|
312
|
+
### Quality Improvements
|
|
313
|
+
- **Reduced Bug Rate**: Fewer issues reaching production
|
|
314
|
+
- **Faster Reviews**: Automated checks catch obvious issues
|
|
315
|
+
- **Consistent Code**: Enforced standards across team
|
|
316
|
+
- **Better Documentation**: Auto-generated docs stay current
|
|
317
|
+
|
|
318
|
+
### Efficiency Gains
|
|
319
|
+
- **Faster Development**: Immediate feedback prevents rework
|
|
320
|
+
- **Reduced Context Switching**: Automated notifications
|
|
321
|
+
- **Better Planning**: Predictive suggestions guide development
|
|
322
|
+
- **Streamlined Deployments**: Automated validation and preparation
|
|
323
|
+
|
|
324
|
+
## 🚀 Getting Started
|
|
325
|
+
|
|
326
|
+
1. **Setup**: Run `.claude/hooks/hook-manager.sh setup`
|
|
327
|
+
2. **Install**: Run `.claude/hooks/hook-manager.sh install`
|
|
328
|
+
3. **Test**: Run `.claude/hooks/hook-manager.sh test`
|
|
329
|
+
4. **Customize**: Modify hooks for your project needs
|
|
330
|
+
5. **Monitor**: Check performance and adjust as needed
|
|
331
|
+
|
|
332
|
+
## 📞 Support
|
|
333
|
+
|
|
334
|
+
For issues or questions:
|
|
335
|
+
- Check hook logs: `.claude/hooks/logs/`
|
|
336
|
+
- Run diagnostics: `.claude/hooks/hook-manager.sh test`
|
|
337
|
+
- View status: `.claude/hooks/hook-manager.sh status`
|
|
338
|
+
- Review documentation in each hook file
|
|
339
|
+
|
|
340
|
+
---
|
|
341
|
+
|
|
342
|
+
**🎉 Enjoy automated development workflows that make you more productive and your code more reliable!**
|
|
@@ -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
|