claude-flow-novice 2.14.30 → 2.14.32
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-data/cfn-loop.db +0 -0
- package/.claude/commands/CFN_LOOP_TASK_MODE.md +1 -1
- package/.claude/skills/cfn-agent-discovery/agents-registry.json +10 -9
- package/.claude/skills/cfn-docker-agent-spawning/SKILL.md +394 -0
- package/.claude/skills/cfn-docker-agent-spawning/spawn-agent.sh +521 -0
- package/.claude/skills/cfn-docker-loop-orchestration/SKILL.md +449 -0
- package/.claude/skills/cfn-docker-loop-orchestration/orchestrate.sh +787 -0
- package/.claude/skills/cfn-docker-redis-coordination/SKILL.md +435 -0
- package/.claude/skills/cfn-docker-redis-coordination/coordinate.sh +635 -0
- package/.claude/skills/cfn-docker-skill-mcp-selection/SKILL.md +289 -0
- package/.claude/skills/cfn-docker-skill-mcp-selection/skill-mcp-selector.js +472 -0
- package/.claude/skills/cfn-loop-validation/config.json +2 -2
- package/README.md +95 -0
- package/claude-assets/agents/README-AGENT_LIFECYCLE.md +10 -37
- package/claude-assets/agents/README-VALIDATION.md +8 -0
- package/claude-assets/agents/cfn-dev-team/CLAUDE.md +10 -9
- package/claude-assets/agents/cfn-dev-team/README.md +8 -0
- package/claude-assets/agents/cfn-dev-team/architecture/base-template-generator.md +2 -9
- package/claude-assets/agents/cfn-dev-team/coordinators/README.md +9 -1
- package/claude-assets/agents/cfn-dev-team/dev-ops/devops-engineer.md +7 -12
- package/claude-assets/agents/cfn-dev-team/dev-ops/docker-specialist.md +10 -5
- package/claude-assets/agents/cfn-dev-team/dev-ops/github-commit-agent.md +11 -10
- package/claude-assets/agents/cfn-dev-team/dev-ops/monitoring-specialist.md +10 -5
- package/claude-assets/agents/cfn-dev-team/developers/README.md +9 -1
- package/claude-assets/agents/cfn-dev-team/developers/api-gateway-specialist.md +2 -5
- package/claude-assets/agents/cfn-dev-team/developers/backend-developer.md +11 -6
- package/claude-assets/agents/cfn-dev-team/developers/database/database-architect.md +2 -5
- package/claude-assets/agents/cfn-dev-team/developers/frontend/mobile-dev.md +2 -19
- package/claude-assets/agents/cfn-dev-team/developers/frontend/react-frontend-engineer.md +11 -6
- package/claude-assets/agents/cfn-dev-team/developers/frontend/ui-designer.md +9 -23
- package/claude-assets/agents/cfn-dev-team/developers/graphql-specialist.md +10 -5
- package/claude-assets/agents/cfn-dev-team/developers/rust-developer.md +2 -9
- package/claude-assets/agents/cfn-dev-team/documentation/README-VALIDATION.md +8 -0
- package/claude-assets/agents/cfn-dev-team/documentation/agent-type-guidelines.md +10 -0
- package/claude-assets/agents/cfn-dev-team/documentation/pseudocode.md +2 -9
- package/claude-assets/agents/cfn-dev-team/product-owners/accessibility-advocate-persona.md +11 -6
- package/claude-assets/agents/cfn-dev-team/product-owners/cto-agent.md +0 -5
- package/claude-assets/agents/cfn-dev-team/product-owners/power-user-persona.md +0 -3
- package/claude-assets/agents/cfn-dev-team/product-owners/product-owner.md +2 -8
- package/claude-assets/agents/cfn-dev-team/reviewers/README.md +9 -1
- package/claude-assets/agents/cfn-dev-team/reviewers/quality/quality-metrics.md +10 -0
- package/claude-assets/agents/cfn-dev-team/test-agent.md +10 -0
- package/claude-assets/agents/cfn-dev-team/testers/README.md +9 -1
- package/claude-assets/agents/cfn-dev-team/utility/analyst.md +0 -7
- package/claude-assets/agents/cfn-dev-team/utility/code-booster.md +1 -38
- package/claude-assets/agents/cfn-dev-team/utility/memory-leak-specialist.md +10 -5
- package/claude-assets/agents/cfn-dev-team/utility/researcher.md +8 -34
- package/claude-assets/agents/cfn-dev-team/utility/z-ai-specialist.md +10 -5
- package/claude-assets/agents/csuite/cto-agent.md +10 -0
- package/claude-assets/agents/custom/cfn-system-expert.md +128 -1
- package/claude-assets/agents/docker-coordinators/cfn-docker-v3-coordinator.md +5 -1
- package/claude-assets/agents/docker-team/csuite/c-suite-template.md +5 -1
- package/claude-assets/agents/docker-team/infrastructure/team-coordinator-template.md +5 -1
- package/claude-assets/agents/marketing_hybrid/cost_tracker.md +10 -0
- package/claude-assets/agents/marketing_hybrid/docker_deployer.md +10 -0
- package/claude-assets/agents/marketing_hybrid/zai_worker_spawner.md +10 -0
- package/claude-assets/agents/project-only-agents/npm-package-specialist.md +9 -26
- package/claude-assets/commands/CFN_LOOP_TASK_MODE.md +1 -1
- package/claude-assets/hooks/cfn-post-execution/memory-cleanup.sh +20 -0
- package/claude-assets/hooks/cfn-pre-execution/memory-check.sh +20 -0
- package/claude-assets/skills/agent-lifecycle/SKILL.md +60 -0
- package/claude-assets/skills/agent-lifecycle/execute-lifecycle-hook.sh +573 -0
- package/claude-assets/skills/agent-lifecycle/simple-audit.sh +31 -0
- package/claude-assets/skills/cfn-agent-discovery/agents-registry.json +10 -9
- package/claude-assets/skills/cfn-docker-agent-spawning/spawn-agent.sh +70 -10
- package/claude-assets/skills/cfn-loop-validation/config.json +2 -2
- package/claude-assets/skills/cfn-memory-management/SKILL.md +271 -0
- package/claude-assets/skills/cfn-memory-management/check-memory.sh +160 -0
- package/claude-assets/skills/cfn-memory-management/cleanup-memory.sh +197 -0
- package/claude-assets/skills/cfn-task-config-init/initialize-config.sh +2 -2
- package/dist/agents/agent-loader.js +165 -146
- package/dist/agents/agent-loader.js.map +1 -1
- package/dist/cli/agent-command.js +44 -2
- package/dist/cli/agent-command.js.map +1 -1
- package/dist/cli/config-manager.js +91 -109
- package/dist/cli/config-manager.js.map +1 -1
- package/dist/cli/index.js +29 -2
- package/dist/cli/index.js.map +1 -1
- package/package.json +10 -2
- package/readme/README.md +71 -14
- package/scripts/memory-leak-prevention.sh +306 -0
|
@@ -0,0 +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
|
|
197
|
+
main "$@"
|
|
@@ -186,8 +186,8 @@ select_agents() {
|
|
|
186
186
|
fi
|
|
187
187
|
|
|
188
188
|
# Loop 2 validators (adaptive scaling)
|
|
189
|
-
# Standard: 3-5 files → add architect, security
|
|
190
|
-
loop2+=("architect" "security-specialist")
|
|
189
|
+
# Standard: 3-5 files → add system-architect, security
|
|
190
|
+
loop2+=("system-architect" "security-specialist")
|
|
191
191
|
|
|
192
192
|
# Complex/Enterprise: >5 files → add code-analyzer
|
|
193
193
|
if echo "$description" | grep -iq "large\|complex\|enterprise"; then
|
|
@@ -1,12 +1,145 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
/**
|
|
2
3
|
* Dynamic Agent Loader - Reads agent definitions from .claude/agents/ directory
|
|
3
4
|
* Single source of truth for agent types in the system
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
*/ var __awaiter = this && this.__awaiter || function(thisArg, _arguments, P, generator) {
|
|
6
|
+
function adopt(value) {
|
|
7
|
+
return value instanceof P ? value : new P(function(resolve) {
|
|
8
|
+
resolve(value);
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
return new (P || (P = Promise))(function(resolve, reject) {
|
|
12
|
+
function fulfilled(value) {
|
|
13
|
+
try {
|
|
14
|
+
step(generator.next(value));
|
|
15
|
+
} catch (e) {
|
|
16
|
+
reject(e);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function rejected(value) {
|
|
20
|
+
try {
|
|
21
|
+
step(generator["throw"](value));
|
|
22
|
+
} catch (e) {
|
|
23
|
+
reject(e);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function step(result) {
|
|
27
|
+
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
28
|
+
}
|
|
29
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
var __generator = this && this.__generator || function(thisArg, body) {
|
|
33
|
+
var _ = {
|
|
34
|
+
label: 0,
|
|
35
|
+
sent: function() {
|
|
36
|
+
if (t[0] & 1) throw t[1];
|
|
37
|
+
return t[1];
|
|
38
|
+
},
|
|
39
|
+
trys: [],
|
|
40
|
+
ops: []
|
|
41
|
+
}, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
42
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
43
|
+
return this;
|
|
44
|
+
}), g;
|
|
45
|
+
function verb(n) {
|
|
46
|
+
return function(v) {
|
|
47
|
+
return step([
|
|
48
|
+
n,
|
|
49
|
+
v
|
|
50
|
+
]);
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
function step(op) {
|
|
54
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
55
|
+
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
56
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
57
|
+
if (y = 0, t) op = [
|
|
58
|
+
op[0] & 2,
|
|
59
|
+
t.value
|
|
60
|
+
];
|
|
61
|
+
switch(op[0]){
|
|
62
|
+
case 0:
|
|
63
|
+
case 1:
|
|
64
|
+
t = op;
|
|
65
|
+
break;
|
|
66
|
+
case 4:
|
|
67
|
+
_.label++;
|
|
68
|
+
return {
|
|
69
|
+
value: op[1],
|
|
70
|
+
done: false
|
|
71
|
+
};
|
|
72
|
+
case 5:
|
|
73
|
+
_.label++;
|
|
74
|
+
y = op[1];
|
|
75
|
+
op = [
|
|
76
|
+
0
|
|
77
|
+
];
|
|
78
|
+
continue;
|
|
79
|
+
case 7:
|
|
80
|
+
op = _.ops.pop();
|
|
81
|
+
_.trys.pop();
|
|
82
|
+
continue;
|
|
83
|
+
default:
|
|
84
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
85
|
+
_ = 0;
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
89
|
+
_.label = op[1];
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
93
|
+
_.label = t[1];
|
|
94
|
+
t = op;
|
|
95
|
+
break;
|
|
96
|
+
}
|
|
97
|
+
if (t && _.label < t[2]) {
|
|
98
|
+
_.label = t[2];
|
|
99
|
+
_.ops.push(op);
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
if (t[2]) _.ops.pop();
|
|
103
|
+
_.trys.pop();
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
op = body.call(thisArg, _);
|
|
107
|
+
} catch (e) {
|
|
108
|
+
op = [
|
|
109
|
+
6,
|
|
110
|
+
e
|
|
111
|
+
];
|
|
112
|
+
y = 0;
|
|
113
|
+
} finally{
|
|
114
|
+
f = t = 0;
|
|
115
|
+
}
|
|
116
|
+
if (op[0] & 5) throw op[1];
|
|
117
|
+
return {
|
|
118
|
+
value: op[0] ? op[1] : void 0,
|
|
119
|
+
done: true
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
var __spreadArray = this && this.__spreadArray || function(to, from, pack) {
|
|
124
|
+
if (pack || arguments.length === 2) for(var i = 0, l = from.length, ar; i < l; i++){
|
|
125
|
+
if (ar || !(i in from)) {
|
|
126
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
127
|
+
ar[i] = from[i];
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
131
|
+
};
|
|
132
|
+
Object.defineProperty(exports, "__esModule", {
|
|
133
|
+
value: true
|
|
134
|
+
});
|
|
135
|
+
exports.refreshAgents = exports.getAgentsByCategory = exports.isValidAgentType = exports.searchAgents = exports.getAgentCategories = exports.getAllAgents = exports.getAgent = exports.getAvailableAgentTypes = exports.agentLoader = exports.AgentLoader = void 0;
|
|
136
|
+
exports.resolveLegacyAgentType = resolveLegacyAgentType;
|
|
137
|
+
var node_fs_1 = require("node:fs");
|
|
138
|
+
var glob_1 = require("glob");
|
|
139
|
+
var node_path_1 = require("node:path");
|
|
140
|
+
var yaml_1 = require("yaml");
|
|
8
141
|
// Legacy agent type mapping for backward compatibility
|
|
9
|
-
|
|
142
|
+
var LEGACY_AGENT_MAPPING = {
|
|
10
143
|
analyst: 'code-analyzer',
|
|
11
144
|
coordinator: 'hierarchical-coordinator',
|
|
12
145
|
optimizer: 'perf-analyzer',
|
|
@@ -17,38 +150,40 @@ const LEGACY_AGENT_MAPPING = {
|
|
|
17
150
|
};
|
|
18
151
|
/**
|
|
19
152
|
* Resolve legacy agent types to current equivalents
|
|
20
|
-
*/
|
|
153
|
+
*/ function resolveLegacyAgentType(legacyType) {
|
|
21
154
|
return LEGACY_AGENT_MAPPING[legacyType] || legacyType;
|
|
22
155
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
156
|
+
var AgentLoader = /** @class */ function() {
|
|
157
|
+
function AgentLoader() {
|
|
158
|
+
this.agentCache = new Map();
|
|
159
|
+
this.categoriesCache = [];
|
|
160
|
+
this.lastLoadTime = 0;
|
|
161
|
+
this.CACHE_EXPIRY = 60000; // 1 minute cache
|
|
162
|
+
}
|
|
163
|
+
AgentLoader.prototype.getAgentsDirectory = function() {
|
|
164
|
+
var currentDir = process.cwd();
|
|
30
165
|
while(currentDir !== '/'){
|
|
31
|
-
|
|
32
|
-
if (existsSync(claudeAgentsPath)) {
|
|
166
|
+
var claudeAgentsPath = (0, node_path_1.resolve)(currentDir, '.claude', 'agents');
|
|
167
|
+
if ((0, node_fs_1.existsSync)(claudeAgentsPath)) {
|
|
33
168
|
return claudeAgentsPath;
|
|
34
169
|
}
|
|
35
|
-
currentDir = dirname(currentDir);
|
|
170
|
+
currentDir = (0, node_path_1.dirname)(currentDir);
|
|
36
171
|
}
|
|
37
|
-
return resolve(process.cwd(), '.claude', 'agents');
|
|
38
|
-
}
|
|
39
|
-
parseAgentFile(filePath) {
|
|
172
|
+
return (0, node_path_1.resolve)(process.cwd(), '.claude', 'agents');
|
|
173
|
+
};
|
|
174
|
+
AgentLoader.prototype.parseAgentFile = function(filePath) {
|
|
40
175
|
try {
|
|
41
|
-
|
|
42
|
-
|
|
176
|
+
var content = (0, node_fs_1.readFileSync)(filePath, 'utf-8');
|
|
177
|
+
var frontmatterMatch = content.match(/^---\r?\n([\s\S]*?)\r?\n---\r?\n([\s\S]*)$/);
|
|
43
178
|
if (!frontmatterMatch) {
|
|
44
|
-
console.warn(
|
|
179
|
+
console.warn("No frontmatter found in ".concat(filePath));
|
|
45
180
|
return null;
|
|
46
181
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
182
|
+
var yamlContent = frontmatterMatch[1], markdownContent = frontmatterMatch[2];
|
|
183
|
+
var frontmatter = (0, yaml_1.parse)(yamlContent);
|
|
184
|
+
var description = frontmatter.description;
|
|
50
185
|
if (!frontmatter.name || !description) {
|
|
51
|
-
console.warn(
|
|
186
|
+
console.warn("Missing required fields (name, description) in ".concat(filePath));
|
|
52
187
|
return null;
|
|
53
188
|
}
|
|
54
189
|
return {
|
|
@@ -69,129 +204,13 @@ export class AgentLoader {
|
|
|
69
204
|
content: markdownContent.trim()
|
|
70
205
|
};
|
|
71
206
|
} catch (error) {
|
|
72
|
-
console.error(
|
|
207
|
+
console.error("Error parsing agent file ".concat(filePath, ":"), error);
|
|
73
208
|
return null;
|
|
74
209
|
}
|
|
75
|
-
}
|
|
76
|
-
parseTools(frontmatter) {
|
|
77
|
-
|
|
210
|
+
};
|
|
211
|
+
AgentLoader.prototype.parseTools = function(frontmatter) {
|
|
212
|
+
var extractTools = function(input) {
|
|
78
213
|
if (Array.isArray(input)) return input.map(String);
|
|
79
|
-
if (typeof input === 'string') {
|
|
80
|
-
return input.split(/[,\s]+/).map((t)=>t.trim()).filter((t)=>t.length > 0);
|
|
81
|
-
}
|
|
82
|
-
return [];
|
|
83
|
-
};
|
|
84
|
-
// Safely handle tools and capabilities.tools
|
|
85
|
-
const toolsFromFrontmatter = frontmatter.tools ? extractTools(frontmatter.tools) : [];
|
|
86
|
-
const toolsFromCapabilities = frontmatter.capabilities && typeof frontmatter.capabilities === 'object' ? extractTools(Object(frontmatter.capabilities).tools) : [];
|
|
87
|
-
return [
|
|
88
|
-
...toolsFromFrontmatter,
|
|
89
|
-
...toolsFromCapabilities
|
|
90
|
-
];
|
|
91
|
-
}
|
|
92
|
-
async loadAgents() {
|
|
93
|
-
const agentsDir = this.getAgentsDirectory();
|
|
94
|
-
if (!existsSync(agentsDir)) {
|
|
95
|
-
console.warn(`Agents directory not found: ${agentsDir}`);
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
const agentFiles = await new Promise((resolve, reject)=>{
|
|
99
|
-
glob('**/*.md', {
|
|
100
|
-
cwd: agentsDir,
|
|
101
|
-
ignore: [
|
|
102
|
-
'**/README.md',
|
|
103
|
-
'**/MIGRATION_SUMMARY.md'
|
|
104
|
-
],
|
|
105
|
-
absolute: true
|
|
106
|
-
}, (err, matches)=>{
|
|
107
|
-
if (err) reject(err);
|
|
108
|
-
else resolve(matches);
|
|
109
|
-
});
|
|
110
|
-
});
|
|
111
|
-
this.agentCache.clear();
|
|
112
|
-
this.categoriesCache = [];
|
|
113
|
-
const categoryMap = new Map();
|
|
114
|
-
for (const filePath of agentFiles){
|
|
115
|
-
const agent = this.parseAgentFile(filePath);
|
|
116
|
-
if (agent) {
|
|
117
|
-
this.agentCache.set(agent.name, agent);
|
|
118
|
-
const relativePath = filePath.replace(agentsDir, '');
|
|
119
|
-
const pathParts = relativePath.split('/');
|
|
120
|
-
const category = pathParts[1] || 'uncategorized';
|
|
121
|
-
if (!categoryMap.has(category)) {
|
|
122
|
-
categoryMap.set(category, []);
|
|
123
|
-
}
|
|
124
|
-
categoryMap.get(category).push(agent);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
this.categoriesCache = Array.from(categoryMap.entries()).map(([name, agents])=>({
|
|
128
|
-
name,
|
|
129
|
-
agents: agents.sort((a, b)=>a.name.localeCompare(b.name))
|
|
130
|
-
}));
|
|
131
|
-
this.lastLoadTime = Date.now();
|
|
132
|
-
}
|
|
133
|
-
// Rest of the methods remain similar to the original implementation
|
|
134
|
-
needsRefresh() {
|
|
135
|
-
return Date.now() - this.lastLoadTime > this.CACHE_EXPIRY;
|
|
136
|
-
}
|
|
137
|
-
async ensureLoaded() {
|
|
138
|
-
if (this.agentCache.size === 0 || this.needsRefresh()) {
|
|
139
|
-
await this.loadAgents();
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
async getAvailableAgentTypes() {
|
|
143
|
-
await this.ensureLoaded();
|
|
144
|
-
const currentTypes = Array.from(this.agentCache.keys());
|
|
145
|
-
const legacyTypes = Object.keys(LEGACY_AGENT_MAPPING);
|
|
146
|
-
return Array.from(new Set([
|
|
147
|
-
...currentTypes,
|
|
148
|
-
...legacyTypes
|
|
149
|
-
])).sort();
|
|
150
|
-
}
|
|
151
|
-
async getAgent(name) {
|
|
152
|
-
await this.ensureLoaded();
|
|
153
|
-
return this.agentCache.get(name) || this.agentCache.get(resolveLegacyAgentType(name)) || null;
|
|
154
|
-
}
|
|
155
|
-
async getAllAgents() {
|
|
156
|
-
await this.ensureLoaded();
|
|
157
|
-
return Array.from(this.agentCache.values()).sort((a, b)=>a.name.localeCompare(b.name));
|
|
158
|
-
}
|
|
159
|
-
async getAgentCategories() {
|
|
160
|
-
await this.ensureLoaded();
|
|
161
|
-
return this.categoriesCache;
|
|
162
|
-
}
|
|
163
|
-
async searchAgents(query) {
|
|
164
|
-
await this.ensureLoaded();
|
|
165
|
-
const lowerQuery = query.toLowerCase();
|
|
166
|
-
return Array.from(this.agentCache.values()).filter((agent)=>agent.name.toLowerCase().includes(lowerQuery) || agent.description.toLowerCase().includes(lowerQuery) || agent.capabilities?.some((cap)=>cap.toLowerCase().includes(lowerQuery)));
|
|
167
|
-
}
|
|
168
|
-
async isValidAgentType(name) {
|
|
169
|
-
await this.ensureLoaded();
|
|
170
|
-
return this.agentCache.has(name) || this.agentCache.has(resolveLegacyAgentType(name));
|
|
171
|
-
}
|
|
172
|
-
async getAgentsByCategory(category) {
|
|
173
|
-
const categories = await this.getAgentCategories();
|
|
174
|
-
const found = categories.find((cat)=>cat.name === category);
|
|
175
|
-
return found?.agents || [];
|
|
176
|
-
}
|
|
177
|
-
async refresh() {
|
|
178
|
-
this.lastLoadTime = 0;
|
|
179
|
-
await this.loadAgents();
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
// Singleton instance
|
|
183
|
-
export const agentLoader = new AgentLoader();
|
|
184
|
-
// Convenience exports for use in other modules
|
|
185
|
-
export const getAvailableAgentTypes = ()=>agentLoader.getAvailableAgentTypes();
|
|
186
|
-
export const getAgent = (name)=>agentLoader.getAgent(name);
|
|
187
|
-
export const getAllAgents = ()=>agentLoader.getAllAgents();
|
|
188
|
-
export const getAgentCategories = ()=>agentLoader.getAgentCategories();
|
|
189
|
-
export const searchAgents = (query)=>agentLoader.searchAgents(query);
|
|
190
|
-
export const isValidAgentType = (name)=>agentLoader.isValidAgentType(name);
|
|
191
|
-
export const getAgentsByCategory = (category)=>agentLoader.getAgentsByCategory(category);
|
|
192
|
-
export const refreshAgents = ()=>agentLoader.refresh();
|
|
193
|
-
|
|
194
|
-
//# sourceMappingURL=agent-loader.js.map.isArray(input)) return input.map(String);
|
|
195
214
|
if (typeof input === 'string') {
|
|
196
215
|
return input.split(/[,\s]+/).map(function(t) {
|
|
197
216
|
return t.trim();
|