@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.
@@ -1,249 +1,249 @@
1
- #!/bin/bash
2
- # HOOK: post-commit-smart-automations
3
- # DESCRIPTION: Intelligent post-commit automations for documentation, notifications, and workflow optimization
4
- # AUTHOR: Claude Code Hooks Master
5
- # VERSION: 1.0.0
6
-
7
- set -e
8
-
9
- # Colors for output
10
- GREEN='\033[0;32m'
11
- BLUE='\033[0;34m'
12
- YELLOW='\033[1;33m'
13
- RED='\033[0;31m'
14
- NC='\033[0m'
15
-
16
- log_info() {
17
- echo -e "${BLUE}[AUTO]${NC} $1"
18
- }
19
-
20
- log_success() {
21
- echo -e "${GREEN}[DONE]${NC} $1"
22
- }
23
-
24
- log_warn() {
25
- echo -e "${YELLOW}[WARN]${NC} $1"
26
- }
27
-
28
- # Get commit information
29
- get_commit_info() {
30
- COMMIT_HASH=$(git rev-parse HEAD)
31
- COMMIT_MSG=$(git log -1 --pretty=%B)
32
- COMMIT_AUTHOR=$(git log -1 --pretty=%an)
33
- COMMIT_EMAIL=$(git log -1 --pretty=%ae)
34
- CHANGED_FILES=$(git diff --name-only HEAD~1)
35
- }
36
-
37
- # Analyze commit type and impact
38
- analyze_commit_impact() {
39
- local commit_msg="$1"
40
- local changed_files="$2"
41
-
42
- # Determine commit type
43
- if echo "$commit_msg" | grep -q -i "feat\|feature\|add"; then
44
- COMMIT_TYPE="feature"
45
- elif echo "$commit_msg" | grep -q -i "fix\|bug\|hotfix"; then
46
- COMMIT_TYPE="fix"
47
- elif echo "$commit_msg" | grep -q -i "docs\|documentation"; then
48
- COMMIT_TYPE="docs"
49
- elif echo "$commit_msg" | grep -q -i "test\|spec"; then
50
- COMMIT_TYPE="test"
51
- elif echo "$commit_msg" | grep -q -i "refactor\|style"; then
52
- COMMIT_TYPE="refactor"
53
- else
54
- COMMIT_TYPE="other"
55
- fi
56
-
57
- # Determine impact level
58
- if echo "$changed_files" | grep -q -E "(package\.json|core|config|src/index)"; then
59
- IMPACT_LEVEL="high"
60
- elif echo "$changed_files" | grep -q -E "(src/|components/|api/)"; then
61
- IMPACT_LEVEL="medium"
62
- else
63
- IMPACT_LEVEL="low"
64
- fi
65
- }
66
-
67
- # Documentation automation
68
- run_docs_automation() {
69
- log_info "Running documentation automation..."
70
-
71
- # Check if documentation needs updating
72
- if echo "$CHANGED_FILES" | grep -q -E "\.(js|ts|py)$"; then
73
- log_info "Code changes detected - checking documentation needs..."
74
-
75
- # Trigger Claude Code documentation skill
76
- if command -v claude_code_run_skill &> /dev/null; then
77
- log_info "Using Claude Code documentation skill..."
78
- claude_code_run_skill "professional-documentation-writer" "update-api-docs" || true
79
- else
80
- log_warn "Claude Code skills not available - skipping automated docs"
81
- fi
82
- fi
83
-
84
- # Update README if necessary
85
- if echo "$CHANGED_FILES" | grep -q -E "(README|readme)"; then
86
- log_info "README changes detected - validating format..."
87
- # Could add README validation here
88
- fi
89
-
90
- log_success "Documentation automation completed"
91
- }
92
-
93
- # Memory system integration
94
- update_memory_system() {
95
- log_info "Updating project memory system..."
96
-
97
- local memory_dir=".claude/memory"
98
- if [ ! -d "$memory_dir" ]; then
99
- log_warn "Memory system not found - skipping memory updates"
100
- return 0
101
- fi
102
-
103
- # Add to decisions memory for architectural decisions
104
- if echo "$COMMIT_MSG" | grep -q -i "decision\|architect\|design"; then
105
- {
106
- echo "## $(date '+%Y-%m-%d %H:%M:%S') - Architecture Decision"
107
- echo "**Decision**: $COMMIT_MSG"
108
- echo "**Files Changed**: $CHANGED_FILES"
109
- echo "**Impact**: $IMPACT_LEVEL"
110
- echo
111
- } >> "$memory_dir/decisions.md"
112
- log_success "Added to decisions memory"
113
- fi
114
-
115
- # Add to learnings memory for insights
116
- if echo "$COMMIT_MSG" | grep -q -i "learn\|discover\|find\|improve"; then
117
- {
118
- echo "## $(date '+%Y-%m-%d %H:%M:%S') - Development Learning"
119
- echo "**Insight**: $COMMIT_MSG"
120
- echo "**Context**: Commit $COMMIT_HASH"
121
- echo "**Files**: $CHANGED_FILES"
122
- echo
123
- } >> "$memory_dir/learnings.md"
124
- log_success "Added to learnings memory"
125
- fi
126
-
127
- # Update context with recent changes
128
- {
129
- echo "## Recent Changes"
130
- echo "- $(date '+%Y-%m-%d'): $COMMIT_MSG"
131
- echo " - Type: $COMMIT_TYPE, Impact: $IMPACT_LEVEL"
132
- echo " - Files: $(echo "$CHANGED_FILES" | wc -l) files changed"
133
- } >> "$memory_dir/context.md"
134
- }
135
-
136
- # Notification system
137
- send_notifications() {
138
- log_info "Sending notifications..."
139
-
140
- # Skip notifications for low-impact changes
141
- if [ "$IMPACT_LEVEL" = "low" ] && [ "$COMMIT_TYPE" = "other" ]; then
142
- log_info "Low-impact change - skipping notifications"
143
- return 0
144
- fi
145
-
146
- # In a real implementation, you would integrate with:
147
- # - Slack/Discord webhooks
148
- # - Email notifications
149
- # - Project management tools (Jira, Linear, etc.)
150
- # - CI/CD status updates
151
-
152
- log_info "Would notify team about: $COMMIT_TYPE change ($IMPACT_LEVEL impact)"
153
- log_info "Commit: $COMMIT_HASH by $COMMIT_AUTHOR"
154
-
155
- # Example notification payload (you would send this to your notification service)
156
- local notification_data="{
157
- \"commit\": \"$COMMIT_HASH\",
158
- \"author\": \"$COMMIT_AUTHOR\",
159
- \"message\": \"$COMMIT_MSG\",
160
- \"type\": \"$COMMIT_TYPE\",
161
- \"impact\": \"$IMPACT_LEVEL\",
162
- \"files_changed\": $(echo "$CHANGED_FILES" | wc -l)
163
- }"
164
-
165
- # For now, just log what would be sent
166
- log_success "Notification prepared (integrate with your notification service)"
167
- }
168
-
169
- # Backup automation
170
- run_backup_automation() {
171
- # Only backup for significant changes
172
- if [ "$IMPACT_LEVEL" != "high" ]; then
173
- return 0
174
- fi
175
-
176
- log_info "Running backup automation for high-impact change..."
177
-
178
- local backup_dir=".claude/backups"
179
- mkdir -p "$backup_dir"
180
-
181
- local timestamp=$(date '+%Y%m%d_%H%M%S')
182
- local backup_file="$backup_dir/backup_$timestamp.tar.gz"
183
-
184
- # Create backup of critical files
185
- if [ -d "src" ] && [ -d "package.json" ]; then
186
- tar -czf "$backup_file" src/ package.json tsconfig.json 2>/dev/null || true
187
- log_success "Backup created: $backup_file"
188
- fi
189
- }
190
-
191
- # Performance monitoring
192
- update_performance_metrics() {
193
- local metrics_file=".claude/metrics/commit-metrics.json"
194
-
195
- mkdir -p "$(dirname "$metrics_file")"
196
-
197
- # Calculate some basic metrics
198
- local commit_size=$(echo "$CHANGED_FILES" | wc -l)
199
- local test_files=$(echo "$CHANGED_FILES" | grep -c "\.test\." || echo "0")
200
- local config_files=$(echo "$CHANGED_FILES" | grep -c -E "(package\.json|config|\.env)" || echo "0")
201
-
202
- # Create/update metrics
203
- local metrics="{
204
- \"timestamp\": \"$(date -Iseconds)\",
205
- \"commit_hash\": \"$COMMIT_HASH\",
206
- \"commit_type\": \"$COMMIT_TYPE\",
207
- \"impact_level\": \"$IMPACT_LEVEL\",
208
- \"files_changed\": $commit_size,
209
- \"test_files\": $test_files,
210
- \"config_files\": $config_files,
211
- \"author\": \"$COMMIT_AUTHOR\"
212
- }"
213
-
214
- echo "$metrics" >> "$metrics_file"
215
- log_success "Performance metrics updated"
216
- }
217
-
218
- # Main execution
219
- main() {
220
- log_info "🤖 Claude Code Smart Automations - Post-commit Hook"
221
- echo "======================================================="
222
-
223
- # Get commit information
224
- get_commit_info
225
-
226
- # Analyze commit
227
- analyze_commit_impact "$COMMIT_MSG" "$CHANGED_FILES"
228
-
229
- log_info "Commit Analysis:"
230
- echo " Type: $COMMIT_TYPE"
231
- echo " Impact: $IMPACT_LEVEL"
232
- echo " Author: $COMMIT_AUTHOR"
233
- echo " Files: $(echo "$CHANGED_FILES" | wc -l)"
234
- echo
235
-
236
- # Run automations based on commit characteristics
237
- run_docs_automation
238
- update_memory_system
239
- send_notifications
240
- run_backup_automation
241
- update_performance_metrics
242
-
243
- echo
244
- log_success "🎉 All post-commit automations completed successfully!"
245
- log_info "Commit $COMMIT_HASH processed and automated workflows triggered"
246
- }
247
-
248
- # Run main function
249
- main "$@"
1
+ #!/bin/bash
2
+ # HOOK: post-commit-smart-automations
3
+ # DESCRIPTION: Intelligent post-commit automations for documentation, notifications, and workflow optimization
4
+ # AUTHOR: Claude Code Hooks Master
5
+ # VERSION: 1.0.0
6
+
7
+ set -e
8
+
9
+ # Colors for output
10
+ GREEN='\033[0;32m'
11
+ BLUE='\033[0;34m'
12
+ YELLOW='\033[1;33m'
13
+ RED='\033[0;31m'
14
+ NC='\033[0m'
15
+
16
+ log_info() {
17
+ echo -e "${BLUE}[AUTO]${NC} $1"
18
+ }
19
+
20
+ log_success() {
21
+ echo -e "${GREEN}[DONE]${NC} $1"
22
+ }
23
+
24
+ log_warn() {
25
+ echo -e "${YELLOW}[WARN]${NC} $1"
26
+ }
27
+
28
+ # Get commit information
29
+ get_commit_info() {
30
+ COMMIT_HASH=$(git rev-parse HEAD)
31
+ COMMIT_MSG=$(git log -1 --pretty=%B)
32
+ COMMIT_AUTHOR=$(git log -1 --pretty=%an)
33
+ COMMIT_EMAIL=$(git log -1 --pretty=%ae)
34
+ CHANGED_FILES=$(git diff --name-only HEAD~1)
35
+ }
36
+
37
+ # Analyze commit type and impact
38
+ analyze_commit_impact() {
39
+ local commit_msg="$1"
40
+ local changed_files="$2"
41
+
42
+ # Determine commit type
43
+ if echo "$commit_msg" | grep -q -i "feat\|feature\|add"; then
44
+ COMMIT_TYPE="feature"
45
+ elif echo "$commit_msg" | grep -q -i "fix\|bug\|hotfix"; then
46
+ COMMIT_TYPE="fix"
47
+ elif echo "$commit_msg" | grep -q -i "docs\|documentation"; then
48
+ COMMIT_TYPE="docs"
49
+ elif echo "$commit_msg" | grep -q -i "test\|spec"; then
50
+ COMMIT_TYPE="test"
51
+ elif echo "$commit_msg" | grep -q -i "refactor\|style"; then
52
+ COMMIT_TYPE="refactor"
53
+ else
54
+ COMMIT_TYPE="other"
55
+ fi
56
+
57
+ # Determine impact level
58
+ if echo "$changed_files" | grep -q -E "(package\.json|core|config|src/index)"; then
59
+ IMPACT_LEVEL="high"
60
+ elif echo "$changed_files" | grep -q -E "(src/|components/|api/)"; then
61
+ IMPACT_LEVEL="medium"
62
+ else
63
+ IMPACT_LEVEL="low"
64
+ fi
65
+ }
66
+
67
+ # Documentation automation
68
+ run_docs_automation() {
69
+ log_info "Running documentation automation..."
70
+
71
+ # Check if documentation needs updating
72
+ if echo "$CHANGED_FILES" | grep -q -E "\.(js|ts|py)$"; then
73
+ log_info "Code changes detected - checking documentation needs..."
74
+
75
+ # Trigger Claude Code documentation skill
76
+ if command -v claude_code_run_skill &> /dev/null; then
77
+ log_info "Using Claude Code documentation skill..."
78
+ claude_code_run_skill "professional-documentation-writer" "update-api-docs" || true
79
+ else
80
+ log_warn "Claude Code skills not available - skipping automated docs"
81
+ fi
82
+ fi
83
+
84
+ # Update README if necessary
85
+ if echo "$CHANGED_FILES" | grep -q -E "(README|readme)"; then
86
+ log_info "README changes detected - validating format..."
87
+ # Could add README validation here
88
+ fi
89
+
90
+ log_success "Documentation automation completed"
91
+ }
92
+
93
+ # Memory system integration
94
+ update_memory_system() {
95
+ log_info "Updating project memory system..."
96
+
97
+ local memory_dir=".claude/memory"
98
+ if [ ! -d "$memory_dir" ]; then
99
+ log_warn "Memory system not found - skipping memory updates"
100
+ return 0
101
+ fi
102
+
103
+ # Add to decisions memory for architectural decisions
104
+ if echo "$COMMIT_MSG" | grep -q -i "decision\|architect\|design"; then
105
+ {
106
+ echo "## $(date '+%Y-%m-%d %H:%M:%S') - Architecture Decision"
107
+ echo "**Decision**: $COMMIT_MSG"
108
+ echo "**Files Changed**: $CHANGED_FILES"
109
+ echo "**Impact**: $IMPACT_LEVEL"
110
+ echo
111
+ } >> "$memory_dir/decisions.md"
112
+ log_success "Added to decisions memory"
113
+ fi
114
+
115
+ # Add to learnings memory for insights
116
+ if echo "$COMMIT_MSG" | grep -q -i "learn\|discover\|find\|improve"; then
117
+ {
118
+ echo "## $(date '+%Y-%m-%d %H:%M:%S') - Development Learning"
119
+ echo "**Insight**: $COMMIT_MSG"
120
+ echo "**Context**: Commit $COMMIT_HASH"
121
+ echo "**Files**: $CHANGED_FILES"
122
+ echo
123
+ } >> "$memory_dir/learnings.md"
124
+ log_success "Added to learnings memory"
125
+ fi
126
+
127
+ # Update context with recent changes
128
+ {
129
+ echo "## Recent Changes"
130
+ echo "- $(date '+%Y-%m-%d'): $COMMIT_MSG"
131
+ echo " - Type: $COMMIT_TYPE, Impact: $IMPACT_LEVEL"
132
+ echo " - Files: $(echo "$CHANGED_FILES" | wc -l) files changed"
133
+ } >> "$memory_dir/context.md"
134
+ }
135
+
136
+ # Notification system
137
+ send_notifications() {
138
+ log_info "Sending notifications..."
139
+
140
+ # Skip notifications for low-impact changes
141
+ if [ "$IMPACT_LEVEL" = "low" ] && [ "$COMMIT_TYPE" = "other" ]; then
142
+ log_info "Low-impact change - skipping notifications"
143
+ return 0
144
+ fi
145
+
146
+ # In a real implementation, you would integrate with:
147
+ # - Slack/Discord webhooks
148
+ # - Email notifications
149
+ # - Project management tools (Jira, Linear, etc.)
150
+ # - CI/CD status updates
151
+
152
+ log_info "Would notify team about: $COMMIT_TYPE change ($IMPACT_LEVEL impact)"
153
+ log_info "Commit: $COMMIT_HASH by $COMMIT_AUTHOR"
154
+
155
+ # Example notification payload (you would send this to your notification service)
156
+ local notification_data="{
157
+ \"commit\": \"$COMMIT_HASH\",
158
+ \"author\": \"$COMMIT_AUTHOR\",
159
+ \"message\": \"$COMMIT_MSG\",
160
+ \"type\": \"$COMMIT_TYPE\",
161
+ \"impact\": \"$IMPACT_LEVEL\",
162
+ \"files_changed\": $(echo "$CHANGED_FILES" | wc -l)
163
+ }"
164
+
165
+ # For now, just log what would be sent
166
+ log_success "Notification prepared (integrate with your notification service)"
167
+ }
168
+
169
+ # Backup automation
170
+ run_backup_automation() {
171
+ # Only backup for significant changes
172
+ if [ "$IMPACT_LEVEL" != "high" ]; then
173
+ return 0
174
+ fi
175
+
176
+ log_info "Running backup automation for high-impact change..."
177
+
178
+ local backup_dir=".claude/backups"
179
+ mkdir -p "$backup_dir"
180
+
181
+ local timestamp=$(date '+%Y%m%d_%H%M%S')
182
+ local backup_file="$backup_dir/backup_$timestamp.tar.gz"
183
+
184
+ # Create backup of critical files
185
+ if [ -d "src" ] && [ -d "package.json" ]; then
186
+ tar -czf "$backup_file" src/ package.json tsconfig.json 2>/dev/null || true
187
+ log_success "Backup created: $backup_file"
188
+ fi
189
+ }
190
+
191
+ # Performance monitoring
192
+ update_performance_metrics() {
193
+ local metrics_file=".claude/metrics/commit-metrics.json"
194
+
195
+ mkdir -p "$(dirname "$metrics_file")"
196
+
197
+ # Calculate some basic metrics
198
+ local commit_size=$(echo "$CHANGED_FILES" | wc -l)
199
+ local test_files=$(echo "$CHANGED_FILES" | grep -c "\.test\." || echo "0")
200
+ local config_files=$(echo "$CHANGED_FILES" | grep -c -E "(package\.json|config|\.env)" || echo "0")
201
+
202
+ # Create/update metrics
203
+ local metrics="{
204
+ \"timestamp\": \"$(date -Iseconds)\",
205
+ \"commit_hash\": \"$COMMIT_HASH\",
206
+ \"commit_type\": \"$COMMIT_TYPE\",
207
+ \"impact_level\": \"$IMPACT_LEVEL\",
208
+ \"files_changed\": $commit_size,
209
+ \"test_files\": $test_files,
210
+ \"config_files\": $config_files,
211
+ \"author\": \"$COMMIT_AUTHOR\"
212
+ }"
213
+
214
+ echo "$metrics" >> "$metrics_file"
215
+ log_success "Performance metrics updated"
216
+ }
217
+
218
+ # Main execution
219
+ main() {
220
+ log_info "🤖 Claude Code Smart Automations - Post-commit Hook"
221
+ echo "======================================================="
222
+
223
+ # Get commit information
224
+ get_commit_info
225
+
226
+ # Analyze commit
227
+ analyze_commit_impact "$COMMIT_MSG" "$CHANGED_FILES"
228
+
229
+ log_info "Commit Analysis:"
230
+ echo " Type: $COMMIT_TYPE"
231
+ echo " Impact: $IMPACT_LEVEL"
232
+ echo " Author: $COMMIT_AUTHOR"
233
+ echo " Files: $(echo "$CHANGED_FILES" | wc -l)"
234
+ echo
235
+
236
+ # Run automations based on commit characteristics
237
+ run_docs_automation
238
+ update_memory_system
239
+ send_notifications
240
+ run_backup_automation
241
+ update_performance_metrics
242
+
243
+ echo
244
+ log_success "🎉 All post-commit automations completed successfully!"
245
+ log_info "Commit $COMMIT_HASH processed and automated workflows triggered"
246
+ }
247
+
248
+ # Run main function
249
+ main "$@"