claude-flow-novice 2.15.1 → 2.15.3
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/.claude/cfn-extras/agents/google-sheets-specialist.md +614 -0
- package/.claude/commands/cfn/create-handoff.md +224 -0
- package/.claude/hooks/cfn-BACKUP_USAGE.md +243 -243
- package/.claude/hooks/cfn-invoke-security-validation.sh +69 -69
- package/.claude/hooks/cfn-post-edit-cfn-retrospective.sh +78 -78
- package/.claude/hooks/cfn-post-edit.config.json +44 -44
- package/.claude/skills/agent-lifecycle/SKILL.md +60 -0
- package/.claude/skills/agent-lifecycle/execute-lifecycle-hook.sh +573 -0
- package/.claude/skills/agent-lifecycle/simple-audit.sh +31 -0
- package/.claude/skills/cfn-hybrid-routing/check-dependencies.sh +51 -51
- package/.claude/skills/cfn-loop-validation/orchestrate-cfn-loop.sh +252 -252
- package/.claude/skills/cfn-redis-coordination/agent-recovery.sh +74 -74
- package/.claude/skills/cfn-redis-coordination/get-context.sh +112 -112
- package/.claude/skills/cfn-transparency-middleware/middleware-config.sh +28 -28
- package/.claude/skills/cfn-transparency-middleware/performance-benchmark.sh +78 -78
- package/.claude/skills/cfn-transparency-middleware/test-integration.sh +161 -161
- package/.claude/skills/cfn-transparency-middleware/test-transparency-skill.sh +367 -367
- package/.claude/skills/cfn-transparency-middleware/tests/input-validation.sh +92 -92
- package/.claude/skills/cfn-transparency-middleware/wrap-agent.sh +131 -131
- package/claude-assets/agents/cfn-dev-team/coordinators/handoff-coordinator.md +662 -0
- package/claude-assets/agents/cfn-dev-team/dev-ops/docker-specialist.md +29 -0
- package/claude-assets/cfn-extras/agents/google-sheets-specialist.md +614 -0
- package/claude-assets/commands/cfn/create-handoff.md +224 -0
- package/claude-assets/hooks/cfn-BACKUP_USAGE.md +243 -243
- package/claude-assets/hooks/cfn-invoke-security-validation.sh +69 -69
- package/claude-assets/hooks/cfn-post-edit-cfn-retrospective.sh +78 -78
- package/claude-assets/hooks/cfn-post-edit.config.json +44 -44
- package/claude-assets/hooks/cfn-post-execution/memory-cleanup.sh +19 -19
- package/claude-assets/hooks/cfn-pre-execution/memory-check.sh +19 -19
- package/claude-assets/skills/agent-lifecycle/execute-lifecycle-hook.sh +572 -572
- package/claude-assets/skills/agent-lifecycle/simple-audit.sh +30 -30
- package/claude-assets/skills/cfn-automatic-memory-persistence/persist-agent-output.sh +48 -48
- package/claude-assets/skills/cfn-automatic-memory-persistence/query-agent-history.sh +34 -34
- package/claude-assets/skills/cfn-deliverable-validation/confidence-calculator.sh +261 -261
- package/claude-assets/skills/cfn-expert-update/update-expert.sh +345 -345
- package/claude-assets/skills/cfn-hybrid-routing/check-dependencies.sh +51 -51
- package/claude-assets/skills/cfn-intervention-detector/detect-intervention.sh +110 -110
- package/claude-assets/skills/cfn-intervention-orchestrator/execute-intervention.sh +58 -58
- package/claude-assets/skills/cfn-loop-validation/orchestrate-cfn-loop.sh +252 -252
- package/claude-assets/skills/cfn-loop2-output-processing/process-validator-output.sh +275 -275
- package/claude-assets/skills/cfn-memory-management/check-memory.sh +159 -159
- package/claude-assets/skills/cfn-memory-management/cleanup-memory.sh +196 -196
- package/claude-assets/skills/cfn-node-heap-sizer/task-mode-heap-limiter.sh +325 -325
- package/claude-assets/skills/cfn-playbook-auto-update/auto-update-playbook.sh +85 -85
- package/claude-assets/skills/cfn-redis-coordination/agent-recovery.sh +74 -74
- package/claude-assets/skills/cfn-redis-coordination/get-context.sh +112 -112
- package/claude-assets/skills/cfn-scope-simplifier/simplify-scope.sh +67 -67
- package/claude-assets/skills/cfn-specialist-injection/recommend-specialist.sh +56 -56
- package/claude-assets/skills/cfn-standardized-error-handling/capture-agent-error.sh +86 -86
- package/claude-assets/skills/cfn-standardized-error-handling/test-error-handling.sh +165 -165
- package/claude-assets/skills/cfn-task-config-init/initialize-config.sh +264 -264
- package/claude-assets/skills/cfn-task-decomposition/task-decomposer.sh +278 -278
- package/claude-assets/skills/cfn-transparency-middleware/middleware-config.sh +28 -28
- package/claude-assets/skills/cfn-transparency-middleware/performance-benchmark.sh +78 -78
- package/claude-assets/skills/cfn-transparency-middleware/test-integration.sh +161 -161
- package/claude-assets/skills/cfn-transparency-middleware/test-transparency-skill.sh +367 -367
- package/claude-assets/skills/cfn-transparency-middleware/tests/input-validation.sh +92 -92
- package/claude-assets/skills/cfn-transparency-middleware/wrap-agent.sh +131 -131
- package/claude-assets/skills/docker-build/SKILL.md +96 -203
- package/claude-assets/skills/docker-build/build.sh +73 -73
- package/claude-assets/skills/integration/agent-handoff.sh +494 -0
- package/claude-assets/skills/integration/file-operations.sh +414 -0
- package/claude-assets/skills/workflow-codification/APPROVAL_WORKFLOW.md +806 -0
- package/claude-assets/skills/workflow-codification/COST_TRACKING.md +637 -0
- package/claude-assets/skills/workflow-codification/EDGE_CASE_TRACKING.md +404 -0
- package/claude-assets/skills/workflow-codification/README_PHASE4.md +457 -0
- package/claude-assets/skills/workflow-codification/SKILL.md +110 -0
- package/claude-assets/skills/workflow-codification/analyze-patterns.sh +899 -0
- package/claude-assets/skills/workflow-codification/approval-workflow.sh +514 -0
- package/claude-assets/skills/workflow-codification/generate-skill-update.sh +525 -0
- package/claude-assets/skills/workflow-codification/review-skill.sh +643 -0
- package/claude-assets/skills/workflow-codification/templates/email-notification.txt +114 -0
- package/claude-assets/skills/workflow-codification/templates/slack-notification.md +85 -0
- package/claude-assets/skills/workflow-codification/test-integration.sh +281 -0
- package/claude-assets/skills/workflow-codification/track-cost-savings.sh +445 -0
- package/claude-assets/skills/workflow-codification/track-edge-case.sh +323 -0
- package/dist/agents/agent-loader.js +165 -146
- package/dist/agents/agent-loader.js.map +1 -1
- package/dist/cli/config-manager.js +91 -109
- package/dist/cli/config-manager.js.map +1 -1
- package/dist/integration/DatabaseHandoff.js +507 -0
- package/dist/integration/DatabaseHandoff.js.map +1 -0
- package/dist/integration/StandardAdapter.js +291 -0
- package/dist/integration/StandardAdapter.js.map +1 -0
- package/dist/lib/agent-output-parser.js +518 -0
- package/dist/lib/agent-output-parser.js.map +1 -0
- package/dist/lib/agent-output-validator.js +950 -0
- package/dist/lib/agent-output-validator.js.map +1 -0
- package/dist/lib/artifact-registry.js +443 -0
- package/dist/lib/artifact-registry.js.map +1 -0
- package/dist/lib/config-validator.js +687 -0
- package/dist/lib/config-validator.js.map +1 -0
- package/dist/types/agent-output.js +44 -0
- package/dist/types/agent-output.js.map +1 -0
- package/dist/types/config.js +28 -0
- package/dist/types/config.js.map +1 -0
- package/package.json +2 -1
- package/scripts/artifact-cleanup.sh +392 -0
- package/scripts/build-linux.sh +78 -0
- package/scripts/deploy-production.sh +355 -355
- package/scripts/docker-playwright-fix.sh +311 -311
- package/scripts/docker-rebuild-all-agents.sh +127 -127
- package/scripts/memory-leak-prevention.sh +305 -305
- package/scripts/migrate-artifacts.sh +563 -0
- package/scripts/migrate-yaml-to-json.sh +465 -0
- package/scripts/run-marketing-tests.sh +42 -42
- package/scripts/update_paths.sh +46 -46
|
@@ -1,197 +1,197 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
|
|
3
|
-
# Memory Cleanup Script for CFN Operations
|
|
4
|
-
# Post-execution hook to clean up memory resources
|
|
5
|
-
|
|
6
|
-
set -euo pipefail
|
|
7
|
-
|
|
8
|
-
# Configuration
|
|
9
|
-
CLEANUP_DELAY=5 # Seconds to wait before cleanup
|
|
10
|
-
LOG_FILE="/tmp/cfn-memory-cleanup.log"
|
|
11
|
-
PROFILE_DIR="/tmp/claude-memory-profiles"
|
|
12
|
-
|
|
13
|
-
# Colors
|
|
14
|
-
GREEN='\033[0;32m'
|
|
15
|
-
YELLOW='\033[1;33m'
|
|
16
|
-
BLUE='\033[0;34m'
|
|
17
|
-
NC='\033[0m'
|
|
18
|
-
|
|
19
|
-
log() {
|
|
20
|
-
echo "$(date '+%Y-%m-%d %H:%M:%S') - $1" >> "$LOG_FILE"
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
cleanup_temp_files() {
|
|
24
|
-
log "Cleaning up temporary files"
|
|
25
|
-
|
|
26
|
-
# Clean old profile files (older than 24 hours)
|
|
27
|
-
if [[ -d "$PROFILE_DIR" ]]; then
|
|
28
|
-
local old_profiles=$(find "$PROFILE_DIR" -name "*.heapprofile" -mtime +1 2>/dev/null || true)
|
|
29
|
-
if [[ -n "$old_profiles" ]]; then
|
|
30
|
-
echo "$old_profiles" | xargs rm -f 2>/dev/null || true
|
|
31
|
-
log "Removed old heap profiles"
|
|
32
|
-
fi
|
|
33
|
-
fi
|
|
34
|
-
|
|
35
|
-
# Clean temp directories
|
|
36
|
-
find /tmp -name "claude-*" -type d -mtime +1 -exec rm -rf {} + 2>/dev/null || true
|
|
37
|
-
find /tmp -name "*claude*" -type f -mtime +1 -delete 2>/dev/null || true
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
cleanup_zombie_processes() {
|
|
41
|
-
log "Checking for zombie Claude processes"
|
|
42
|
-
|
|
43
|
-
local zombie_pids=$(ps aux | awk '$8 ~ /^Z/ && $11 ~ /claude/ {print $2}' || true)
|
|
44
|
-
|
|
45
|
-
if [[ -n "$zombie_pids" ]]; then
|
|
46
|
-
echo -e "${YELLOW}Found zombie Claude processes: $zombie_pids${NC}"
|
|
47
|
-
# Zombies can't be killed directly, but we can log them
|
|
48
|
-
log "Zombie processes detected: $zombie_pids"
|
|
49
|
-
fi
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
cleanup_hanging_processes() {
|
|
53
|
-
log "Checking for hanging Claude processes"
|
|
54
|
-
|
|
55
|
-
# Find processes that have been running > 2 hours
|
|
56
|
-
local hanging_pids=$(ps -eo pid,etime,cmd | awk '$3 ~ /claude/ && $2 ~ /([0-9]{2}:|[0-9]{3}-)/ {print $1}' || true)
|
|
57
|
-
|
|
58
|
-
if [[ -n "$hanging_pids" ]]; then
|
|
59
|
-
echo -e "${YELLOW}Found long-running Claude processes: $hanging_pids${NC}"
|
|
60
|
-
|
|
61
|
-
for pid in $hanging_pids; do
|
|
62
|
-
if kill -0 "$pid" 2>/dev/null; then
|
|
63
|
-
local process_info=$(ps -p "$pid" -o pid,etime,pcpu,rss,cmd --no-headers)
|
|
64
|
-
echo " PID $pid: $process_info"
|
|
65
|
-
|
|
66
|
-
# Check if process is consuming excessive memory (>4GB)
|
|
67
|
-
local rss_kb=$(ps -p "$pid" -o rss= --no-headers 2>/dev/null || echo "0")
|
|
68
|
-
local rss_mb=$((rss_kb / 1024))
|
|
69
|
-
|
|
70
|
-
if [[ $rss_mb -gt 4096 ]]; then
|
|
71
|
-
echo -e "${YELLOW} ⚠️ High memory usage: ${rss_mb}MB${NC}"
|
|
72
|
-
log "High memory process detected: PID $pid, Memory: ${rss_mb}MB"
|
|
73
|
-
|
|
74
|
-
# Ask user before killing (interactive mode)
|
|
75
|
-
if [[ -t 0 ]]; then
|
|
76
|
-
echo -n "Kill this process? (y/N): "
|
|
77
|
-
read -r response
|
|
78
|
-
if [[ "$response" =~ ^[Yy]$ ]]; then
|
|
79
|
-
kill -TERM "$pid" 2>/dev/null || true
|
|
80
|
-
sleep 2
|
|
81
|
-
kill -KILL "$pid" 2>/dev/null || true
|
|
82
|
-
echo "Process $pid terminated"
|
|
83
|
-
log "Terminated high memory process: PID $pid"
|
|
84
|
-
fi
|
|
85
|
-
else
|
|
86
|
-
# Non-interactive mode - just log
|
|
87
|
-
log "High memory process (non-interactive): PID $pid, Memory: ${rss_mb}MB"
|
|
88
|
-
fi
|
|
89
|
-
fi
|
|
90
|
-
fi
|
|
91
|
-
done
|
|
92
|
-
fi
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
cleanup_network_resources() {
|
|
96
|
-
log "Cleaning up network resources"
|
|
97
|
-
|
|
98
|
-
# Find and close hanging network connections
|
|
99
|
-
local hanging_connections=$(netstat -tnp 2>/dev/null | grep 'ESTABLISHED' | grep 'claude' || true)
|
|
100
|
-
|
|
101
|
-
if [[ -n "$hanging_connections" ]]; then
|
|
102
|
-
local connection_count=$(echo "$hanging_connections" | wc -l)
|
|
103
|
-
echo -e "${BLUE}Found $connection_count established Claude connections${NC}"
|
|
104
|
-
|
|
105
|
-
# Just log them - don't actively close as it might disrupt valid operations
|
|
106
|
-
log "Active connections: $connection_count"
|
|
107
|
-
fi
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
trim_memory_usage() {
|
|
111
|
-
log "Triggering memory trim operations"
|
|
112
|
-
|
|
113
|
-
# Trigger garbage collection if Node.js processes are running
|
|
114
|
-
local node_pids=$(pgrep -f "node.*claude" || true)
|
|
115
|
-
|
|
116
|
-
if [[ -n "$node_pids" ]]; then
|
|
117
|
-
echo -e "${BLUE}Triggering garbage collection for Node.js processes${NC}"
|
|
118
|
-
|
|
119
|
-
while read -r pid; do
|
|
120
|
-
if [[ -n "$pid" ]] && kill -0 "$pid" 2>/dev/null; then
|
|
121
|
-
# Send SIGUSR2 to trigger heap dump (if the process is configured to handle it)
|
|
122
|
-
kill -USR2 "$pid" 2>/dev/null || true
|
|
123
|
-
log "Sent memory trim signal to PID $pid"
|
|
124
|
-
fi
|
|
125
|
-
done <<< "$node_pids"
|
|
126
|
-
fi
|
|
127
|
-
|
|
128
|
-
# Linux-specific memory operations
|
|
129
|
-
if [[ -f /proc/sys/vm/drop_caches ]]; then
|
|
130
|
-
# Note: This requires root privileges
|
|
131
|
-
if [[ $EUID -eq 0 ]]; then
|
|
132
|
-
echo -e "${BLUE}Dropping system caches${NC}"
|
|
133
|
-
sync
|
|
134
|
-
echo 3 > /proc/sys/vm/drop_caches 2>/dev/null || true
|
|
135
|
-
log "Dropped system caches"
|
|
136
|
-
else
|
|
137
|
-
echo -e "${YELLOW}System cache drop requires root privileges${NC}"
|
|
138
|
-
fi
|
|
139
|
-
fi
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
generate_cleanup_report() {
|
|
143
|
-
log "Generating cleanup report"
|
|
144
|
-
|
|
145
|
-
echo ""
|
|
146
|
-
echo -e "${GREEN}=== Memory Cleanup Report ===${NC}"
|
|
147
|
-
|
|
148
|
-
# Current memory status
|
|
149
|
-
if command -v free &> /dev/null; then
|
|
150
|
-
echo -e "${BLUE}Current Memory Status:${NC}"
|
|
151
|
-
free -h
|
|
152
|
-
echo ""
|
|
153
|
-
fi
|
|
154
|
-
|
|
155
|
-
# Claude processes
|
|
156
|
-
local claude_pids=$(pgrep -f "claude" || true)
|
|
157
|
-
if [[ -n "$claude_pids" ]]; then
|
|
158
|
-
echo -e "${BLUE}Active Claude Processes:${NC}"
|
|
159
|
-
ps -p $claude_pids -o pid,pcpu,rss,etime,cmd 2>/dev/null || true
|
|
160
|
-
echo ""
|
|
161
|
-
else
|
|
162
|
-
echo -e "${GREEN}No active Claude processes found${NC}"
|
|
163
|
-
echo ""
|
|
164
|
-
fi
|
|
165
|
-
|
|
166
|
-
# Temporary files
|
|
167
|
-
if [[ -d "$PROFILE_DIR" ]]; then
|
|
168
|
-
local profile_count=$(find "$PROFILE_DIR" -name "*.heapprofile" 2>/dev/null | wc -l)
|
|
169
|
-
echo -e "${BLUE}Profile files: $profile_count${NC}"
|
|
170
|
-
fi
|
|
171
|
-
|
|
172
|
-
echo -e "${GREEN}Cleanup completed${NC}"
|
|
173
|
-
log "Cleanup report generated"
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
main() {
|
|
177
|
-
echo -e "${BLUE}Starting memory cleanup...${NC}"
|
|
178
|
-
log "Memory cleanup started"
|
|
179
|
-
|
|
180
|
-
# Wait a bit to allow processes to finish naturally
|
|
181
|
-
sleep $CLEANUP_DELAY
|
|
182
|
-
|
|
183
|
-
# Perform cleanup operations
|
|
184
|
-
cleanup_temp_files
|
|
185
|
-
cleanup_zombie_processes
|
|
186
|
-
cleanup_hanging_processes
|
|
187
|
-
cleanup_network_resources
|
|
188
|
-
trim_memory_usage
|
|
189
|
-
|
|
190
|
-
# Generate final report
|
|
191
|
-
generate_cleanup_report
|
|
192
|
-
|
|
193
|
-
log "Memory cleanup completed"
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
# Run main function
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
# Memory Cleanup Script for CFN Operations
|
|
4
|
+
# Post-execution hook to clean up memory resources
|
|
5
|
+
|
|
6
|
+
set -euo pipefail
|
|
7
|
+
|
|
8
|
+
# Configuration
|
|
9
|
+
CLEANUP_DELAY=5 # Seconds to wait before cleanup
|
|
10
|
+
LOG_FILE="/tmp/cfn-memory-cleanup.log"
|
|
11
|
+
PROFILE_DIR="/tmp/claude-memory-profiles"
|
|
12
|
+
|
|
13
|
+
# Colors
|
|
14
|
+
GREEN='\033[0;32m'
|
|
15
|
+
YELLOW='\033[1;33m'
|
|
16
|
+
BLUE='\033[0;34m'
|
|
17
|
+
NC='\033[0m'
|
|
18
|
+
|
|
19
|
+
log() {
|
|
20
|
+
echo "$(date '+%Y-%m-%d %H:%M:%S') - $1" >> "$LOG_FILE"
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
cleanup_temp_files() {
|
|
24
|
+
log "Cleaning up temporary files"
|
|
25
|
+
|
|
26
|
+
# Clean old profile files (older than 24 hours)
|
|
27
|
+
if [[ -d "$PROFILE_DIR" ]]; then
|
|
28
|
+
local old_profiles=$(find "$PROFILE_DIR" -name "*.heapprofile" -mtime +1 2>/dev/null || true)
|
|
29
|
+
if [[ -n "$old_profiles" ]]; then
|
|
30
|
+
echo "$old_profiles" | xargs rm -f 2>/dev/null || true
|
|
31
|
+
log "Removed old heap profiles"
|
|
32
|
+
fi
|
|
33
|
+
fi
|
|
34
|
+
|
|
35
|
+
# Clean temp directories
|
|
36
|
+
find /tmp -name "claude-*" -type d -mtime +1 -exec rm -rf {} + 2>/dev/null || true
|
|
37
|
+
find /tmp -name "*claude*" -type f -mtime +1 -delete 2>/dev/null || true
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
cleanup_zombie_processes() {
|
|
41
|
+
log "Checking for zombie Claude processes"
|
|
42
|
+
|
|
43
|
+
local zombie_pids=$(ps aux | awk '$8 ~ /^Z/ && $11 ~ /claude/ {print $2}' || true)
|
|
44
|
+
|
|
45
|
+
if [[ -n "$zombie_pids" ]]; then
|
|
46
|
+
echo -e "${YELLOW}Found zombie Claude processes: $zombie_pids${NC}"
|
|
47
|
+
# Zombies can't be killed directly, but we can log them
|
|
48
|
+
log "Zombie processes detected: $zombie_pids"
|
|
49
|
+
fi
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
cleanup_hanging_processes() {
|
|
53
|
+
log "Checking for hanging Claude processes"
|
|
54
|
+
|
|
55
|
+
# Find processes that have been running > 2 hours
|
|
56
|
+
local hanging_pids=$(ps -eo pid,etime,cmd | awk '$3 ~ /claude/ && $2 ~ /([0-9]{2}:|[0-9]{3}-)/ {print $1}' || true)
|
|
57
|
+
|
|
58
|
+
if [[ -n "$hanging_pids" ]]; then
|
|
59
|
+
echo -e "${YELLOW}Found long-running Claude processes: $hanging_pids${NC}"
|
|
60
|
+
|
|
61
|
+
for pid in $hanging_pids; do
|
|
62
|
+
if kill -0 "$pid" 2>/dev/null; then
|
|
63
|
+
local process_info=$(ps -p "$pid" -o pid,etime,pcpu,rss,cmd --no-headers)
|
|
64
|
+
echo " PID $pid: $process_info"
|
|
65
|
+
|
|
66
|
+
# Check if process is consuming excessive memory (>4GB)
|
|
67
|
+
local rss_kb=$(ps -p "$pid" -o rss= --no-headers 2>/dev/null || echo "0")
|
|
68
|
+
local rss_mb=$((rss_kb / 1024))
|
|
69
|
+
|
|
70
|
+
if [[ $rss_mb -gt 4096 ]]; then
|
|
71
|
+
echo -e "${YELLOW} ⚠️ High memory usage: ${rss_mb}MB${NC}"
|
|
72
|
+
log "High memory process detected: PID $pid, Memory: ${rss_mb}MB"
|
|
73
|
+
|
|
74
|
+
# Ask user before killing (interactive mode)
|
|
75
|
+
if [[ -t 0 ]]; then
|
|
76
|
+
echo -n "Kill this process? (y/N): "
|
|
77
|
+
read -r response
|
|
78
|
+
if [[ "$response" =~ ^[Yy]$ ]]; then
|
|
79
|
+
kill -TERM "$pid" 2>/dev/null || true
|
|
80
|
+
sleep 2
|
|
81
|
+
kill -KILL "$pid" 2>/dev/null || true
|
|
82
|
+
echo "Process $pid terminated"
|
|
83
|
+
log "Terminated high memory process: PID $pid"
|
|
84
|
+
fi
|
|
85
|
+
else
|
|
86
|
+
# Non-interactive mode - just log
|
|
87
|
+
log "High memory process (non-interactive): PID $pid, Memory: ${rss_mb}MB"
|
|
88
|
+
fi
|
|
89
|
+
fi
|
|
90
|
+
fi
|
|
91
|
+
done
|
|
92
|
+
fi
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
cleanup_network_resources() {
|
|
96
|
+
log "Cleaning up network resources"
|
|
97
|
+
|
|
98
|
+
# Find and close hanging network connections
|
|
99
|
+
local hanging_connections=$(netstat -tnp 2>/dev/null | grep 'ESTABLISHED' | grep 'claude' || true)
|
|
100
|
+
|
|
101
|
+
if [[ -n "$hanging_connections" ]]; then
|
|
102
|
+
local connection_count=$(echo "$hanging_connections" | wc -l)
|
|
103
|
+
echo -e "${BLUE}Found $connection_count established Claude connections${NC}"
|
|
104
|
+
|
|
105
|
+
# Just log them - don't actively close as it might disrupt valid operations
|
|
106
|
+
log "Active connections: $connection_count"
|
|
107
|
+
fi
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
trim_memory_usage() {
|
|
111
|
+
log "Triggering memory trim operations"
|
|
112
|
+
|
|
113
|
+
# Trigger garbage collection if Node.js processes are running
|
|
114
|
+
local node_pids=$(pgrep -f "node.*claude" || true)
|
|
115
|
+
|
|
116
|
+
if [[ -n "$node_pids" ]]; then
|
|
117
|
+
echo -e "${BLUE}Triggering garbage collection for Node.js processes${NC}"
|
|
118
|
+
|
|
119
|
+
while read -r pid; do
|
|
120
|
+
if [[ -n "$pid" ]] && kill -0 "$pid" 2>/dev/null; then
|
|
121
|
+
# Send SIGUSR2 to trigger heap dump (if the process is configured to handle it)
|
|
122
|
+
kill -USR2 "$pid" 2>/dev/null || true
|
|
123
|
+
log "Sent memory trim signal to PID $pid"
|
|
124
|
+
fi
|
|
125
|
+
done <<< "$node_pids"
|
|
126
|
+
fi
|
|
127
|
+
|
|
128
|
+
# Linux-specific memory operations
|
|
129
|
+
if [[ -f /proc/sys/vm/drop_caches ]]; then
|
|
130
|
+
# Note: This requires root privileges
|
|
131
|
+
if [[ $EUID -eq 0 ]]; then
|
|
132
|
+
echo -e "${BLUE}Dropping system caches${NC}"
|
|
133
|
+
sync
|
|
134
|
+
echo 3 > /proc/sys/vm/drop_caches 2>/dev/null || true
|
|
135
|
+
log "Dropped system caches"
|
|
136
|
+
else
|
|
137
|
+
echo -e "${YELLOW}System cache drop requires root privileges${NC}"
|
|
138
|
+
fi
|
|
139
|
+
fi
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
generate_cleanup_report() {
|
|
143
|
+
log "Generating cleanup report"
|
|
144
|
+
|
|
145
|
+
echo ""
|
|
146
|
+
echo -e "${GREEN}=== Memory Cleanup Report ===${NC}"
|
|
147
|
+
|
|
148
|
+
# Current memory status
|
|
149
|
+
if command -v free &> /dev/null; then
|
|
150
|
+
echo -e "${BLUE}Current Memory Status:${NC}"
|
|
151
|
+
free -h
|
|
152
|
+
echo ""
|
|
153
|
+
fi
|
|
154
|
+
|
|
155
|
+
# Claude processes
|
|
156
|
+
local claude_pids=$(pgrep -f "claude" || true)
|
|
157
|
+
if [[ -n "$claude_pids" ]]; then
|
|
158
|
+
echo -e "${BLUE}Active Claude Processes:${NC}"
|
|
159
|
+
ps -p $claude_pids -o pid,pcpu,rss,etime,cmd 2>/dev/null || true
|
|
160
|
+
echo ""
|
|
161
|
+
else
|
|
162
|
+
echo -e "${GREEN}No active Claude processes found${NC}"
|
|
163
|
+
echo ""
|
|
164
|
+
fi
|
|
165
|
+
|
|
166
|
+
# Temporary files
|
|
167
|
+
if [[ -d "$PROFILE_DIR" ]]; then
|
|
168
|
+
local profile_count=$(find "$PROFILE_DIR" -name "*.heapprofile" 2>/dev/null | wc -l)
|
|
169
|
+
echo -e "${BLUE}Profile files: $profile_count${NC}"
|
|
170
|
+
fi
|
|
171
|
+
|
|
172
|
+
echo -e "${GREEN}Cleanup completed${NC}"
|
|
173
|
+
log "Cleanup report generated"
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
main() {
|
|
177
|
+
echo -e "${BLUE}Starting memory cleanup...${NC}"
|
|
178
|
+
log "Memory cleanup started"
|
|
179
|
+
|
|
180
|
+
# Wait a bit to allow processes to finish naturally
|
|
181
|
+
sleep $CLEANUP_DELAY
|
|
182
|
+
|
|
183
|
+
# Perform cleanup operations
|
|
184
|
+
cleanup_temp_files
|
|
185
|
+
cleanup_zombie_processes
|
|
186
|
+
cleanup_hanging_processes
|
|
187
|
+
cleanup_network_resources
|
|
188
|
+
trim_memory_usage
|
|
189
|
+
|
|
190
|
+
# Generate final report
|
|
191
|
+
generate_cleanup_report
|
|
192
|
+
|
|
193
|
+
log "Memory cleanup completed"
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
# Run main function
|
|
197
197
|
main "$@"
|