claude-flow-novice 2.14.28 → 2.14.29
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/commands/CFN_LOOP_TASK_MODE.md +119 -0
- package/.claude/skills/cfn-agent-spawning/spawn-agent.sh +12 -0
- package/.claude/skills/cfn-agent-spawning/spawn-agent.sh.backup +273 -0
- package/.claude/skills/cfn-hybrid-routing/README.md +1 -1
- package/.claude/skills/cfn-loop-orchestration/orchestrate.sh +95 -15
- package/.claude/skills/cfn-loop-orchestration/orchestrate.sh.backup +76 -11
- package/.claude/skills/cfn-loop-orchestration/orchestrate.sh.backup2 +959 -0
- package/.claude/skills/cfn-loop-orchestration/orchestrate.sh.clean +949 -0
- package/.claude/skills/cfn-product-owner-decision/execute-decision.sh +82 -10
- package/claude-assets/agents/cfn-dev-team/architecture/base-template-generator.md +7 -33
- package/claude-assets/agents/cfn-dev-team/architecture/planner.md +7 -47
- package/claude-assets/agents/cfn-dev-team/architecture/system-architect.md +7 -33
- package/claude-assets/agents/cfn-dev-team/coordinators/cfn-frontend-coordinator.md +88 -23
- package/claude-assets/agents/cfn-dev-team/coordinators/cfn-v3-coordinator.md +59 -23
- package/claude-assets/agents/cfn-dev-team/coordinators/consensus-builder.md +43 -39
- package/claude-assets/agents/cfn-dev-team/coordinators/epic-creator.md +69 -0
- package/claude-assets/agents/cfn-dev-team/coordinators/multi-sprint-coordinator.md +65 -1
- package/claude-assets/agents/cfn-dev-team/developers/frontend/mobile-dev.md +7 -47
- package/claude-assets/agents/cfn-dev-team/developers/frontend/typescript-specialist.md +7 -26
- package/claude-assets/agents/cfn-dev-team/developers/rust-developer.md +7 -47
- package/claude-assets/agents/cfn-dev-team/product-owners/cto-agent.md +7 -19
- package/claude-assets/agents/cfn-dev-team/product-owners/power-user-persona.md +9 -49
- package/claude-assets/agents/cfn-dev-team/product-owners/product-owner.md +407 -22
- package/claude-assets/agents/cfn-dev-team/reviewers/quality/code-quality-validator.md +7 -66
- package/claude-assets/agents/cfn-dev-team/reviewers/quality/perf-analyzer.md +7 -76
- package/claude-assets/agents/cfn-dev-team/reviewers/quality/performance-benchmarker.md +8 -2
- package/claude-assets/agents/cfn-dev-team/reviewers/quality/security-specialist.md +7 -66
- package/claude-assets/agents/cfn-dev-team/reviewers/reviewer.md +7 -78
- package/claude-assets/agents/cfn-dev-team/testers/e2e/playwright-tester.md +7 -18
- package/claude-assets/agents/cfn-dev-team/testers/interaction-tester.md +7 -18
- package/claude-assets/agents/cfn-dev-team/testers/tester.md +7 -77
- package/claude-assets/agents/cfn-dev-team/testers/unit/tdd-london-unit-swarm.md +7 -18
- package/claude-assets/agents/cfn-dev-team/testers/validation/validation-production-validator.md +7 -19
- package/claude-assets/agents/cfn-dev-team/testing/test-validation-agent.md +7 -44
- package/claude-assets/agents/cfn-dev-team/utility/agent-builder.md +35 -111
- package/claude-assets/agents/cfn-dev-team/utility/analyst.md +7 -47
- package/claude-assets/agents/cfn-dev-team/utility/code-booster.md +7 -40
- package/claude-assets/agents/cfn-dev-team/utility/context-curator.md +7 -47
- package/claude-assets/commands/CFN_LOOP_TASK_MODE.md +119 -0
- package/claude-assets/skills/cfn-agent-spawning/spawn-agent.sh +12 -0
- package/claude-assets/skills/cfn-agent-spawning/spawn-agent.sh.backup +273 -0
- package/claude-assets/skills/cfn-environment-sanitization/SKILL.md +200 -0
- package/claude-assets/skills/cfn-environment-sanitization/sanitize-environment.sh +244 -0
- package/claude-assets/skills/cfn-hybrid-routing/README.md +1 -1
- package/claude-assets/skills/cfn-loop-orchestration/orchestrate.sh +95 -15
- package/claude-assets/skills/cfn-loop-orchestration/orchestrate.sh.backup +76 -11
- package/claude-assets/skills/cfn-loop-orchestration/orchestrate.sh.backup2 +959 -0
- package/claude-assets/skills/cfn-loop-orchestration/orchestrate.sh.clean +949 -0
- package/claude-assets/skills/cfn-node-heap-sizer/task-mode-heap-limiter.sh +326 -0
- package/claude-assets/skills/cfn-process-instrumentation/SKILL.md +279 -0
- package/claude-assets/skills/cfn-process-instrumentation/instrument-process.sh +323 -0
- package/claude-assets/skills/cfn-product-owner-decision/execute-decision.sh +82 -10
- package/claude-assets/skills/cfn-task-audit/get-audit-data.sh +376 -0
- package/claude-assets/skills/cfn-task-audit/store-task-audit.sh +184 -0
- package/claude-assets/skills/cfn-task-mode-safety/cli-coordination.sh +519 -0
- package/claude-assets/skills/cfn-task-mode-safety/mode-detection.sh +326 -0
- package/claude-assets/skills/cfn-task-mode-sanitize/task-mode-env-sanitizer.sh +224 -0
- package/claude-assets/skills/cfn-telemetry/collect-metrics.sh +249 -0
- package/claude-assets/skills/cfn-telemetry/start-telemetry.sh +111 -0
- package/claude-assets/skills/cfn-validation-runner-instrumentation/wrapped-executor.sh +327 -0
- package/dist/cli/config-manager.js +109 -91
- package/dist/cli/config-manager.js.map +1 -1
- package/package.json +1 -1
- package/scripts/mode-detection.sh +321 -0
- package/scripts/spawn-worker.sh +8 -0
- package/scripts/track-zai-costs-simple.sh +8 -0
|
@@ -35,6 +35,125 @@ Task Mode: Main Chat coordinates directly and spawns agents via Task() tool with
|
|
|
35
35
|
|
|
36
36
|
---
|
|
37
37
|
|
|
38
|
+
## ANTI-023 Memory Leak Protection (v2.14.28)
|
|
39
|
+
|
|
40
|
+
**Critical Fix**: Prevents Task Mode agents from executing CLI coordination scripts that cause memory leaks.
|
|
41
|
+
|
|
42
|
+
### Three-Layer Defense System
|
|
43
|
+
|
|
44
|
+
#### Layer 1: Agent Documentation
|
|
45
|
+
**Task Mode agents use mode-specific completion protocols:**
|
|
46
|
+
```markdown
|
|
47
|
+
## ⚠️ CRITICAL: Mode-Specific Completion Protocol
|
|
48
|
+
|
|
49
|
+
**Task Mode (95%):** Spawned via `Task("agent", "...")` in Main Chat
|
|
50
|
+
- Return structured JSON output directly
|
|
51
|
+
- ❌ DO NOT: Use Redis commands, bash scripts, CLI tools
|
|
52
|
+
- ✅ Main Chat receives output automatically
|
|
53
|
+
|
|
54
|
+
**CLI Mode (5%):** Spawned via `npx claude-flow-novice agent-spawn`
|
|
55
|
+
- Use Redis signals and completion scripts
|
|
56
|
+
- ✅ CLI coordination allowed
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
#### Layer 2: Agent-Level Detection
|
|
60
|
+
**Automatic detection functions prevent CLI usage:**
|
|
61
|
+
```bash
|
|
62
|
+
detect_task_mode_and_exit() {
|
|
63
|
+
if [[ -z "${TASK_ID:-}" || -z "${AGENT_ID:-}" ]]; then
|
|
64
|
+
echo "❌ TASK MODE DETECTED - CLI commands forbidden"
|
|
65
|
+
exit 1
|
|
66
|
+
fi
|
|
67
|
+
}
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
#### Layer 3: Code-Level Runtime Blocking
|
|
71
|
+
**Coordination scripts include early exit checks:**
|
|
72
|
+
```bash
|
|
73
|
+
# ⚠️ ANTI-023 MEMORY LEAK PROTECTION
|
|
74
|
+
if [[ -z "${TASK_ID:-}" || -z "${AGENT_ID:-}" ]]; then
|
|
75
|
+
echo "❌ TASK MODE DETECTED - Redis coordination forbidden"
|
|
76
|
+
exit 1
|
|
77
|
+
fi
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### Memory Impact Resolution
|
|
81
|
+
- **Before Fix**: Up to 23GB memory consumption per hanging agent
|
|
82
|
+
- **After Fix**: <100MB normal usage with complete audit trails
|
|
83
|
+
- **Detection Logic**: Environment variable presence indicates spawn mode
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
## Audit Trail Architecture (New v2.14.28)
|
|
88
|
+
|
|
89
|
+
### Dual-Mode Storage System
|
|
90
|
+
|
|
91
|
+
**Design Principle**: Both Task Mode and CLI Mode create complete audit trails for compliance and debugging.
|
|
92
|
+
|
|
93
|
+
#### Task Mode Storage (Main Chat Managed)
|
|
94
|
+
```bash
|
|
95
|
+
# After Task Mode agent completion, Main Chat stores audit data
|
|
96
|
+
./.claude/skills/cfn-task-audit/store-task-audit.sh \
|
|
97
|
+
--task-id "$TASK_ID" \
|
|
98
|
+
--agent-type "$AGENT_TYPE" \
|
|
99
|
+
--output "$AGENT_OUTPUT" \
|
|
100
|
+
--mode "Task"
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
**Storage Locations:**
|
|
104
|
+
- **Redis**: Fast access (`swarm:${TASK_ID}:${AGENT_TYPE}:audit`)
|
|
105
|
+
- **SQLite**: Permanent audit trail (`agent_audit` table)
|
|
106
|
+
- **Files**: Structured logs (`.claude/logs/task-audit/`)
|
|
107
|
+
|
|
108
|
+
#### CLI Mode Storage (Agent Managed)
|
|
109
|
+
```bash
|
|
110
|
+
# CLI agents continue using existing Redis coordination
|
|
111
|
+
redis-cli HSET "swarm:${TASK_ID}:${AGENT_ID}:result" \
|
|
112
|
+
"decision" "$DECISION" \
|
|
113
|
+
"mode" "CLI"
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### Combined Audit Retrieval
|
|
117
|
+
```bash
|
|
118
|
+
# Retrieve complete audit trail from both modes
|
|
119
|
+
get-audit-data.sh --task-id "$TASK_ID" --mode "combined"
|
|
120
|
+
|
|
121
|
+
# Returns unified decision data:
|
|
122
|
+
{
|
|
123
|
+
"task_mode_data": [...],
|
|
124
|
+
"cli_mode_data": [...],
|
|
125
|
+
"complete_audit_trail": true,
|
|
126
|
+
"execution_summary": {...}
|
|
127
|
+
}
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
### Audit Data Structure
|
|
131
|
+
```json
|
|
132
|
+
{
|
|
133
|
+
"task_id": "task-123",
|
|
134
|
+
"agent_type": "reviewer",
|
|
135
|
+
"decision": "PROCEED",
|
|
136
|
+
"reasoning": "Code meets quality standards",
|
|
137
|
+
"confidence": 0.92,
|
|
138
|
+
"mode": "Task|CLI",
|
|
139
|
+
"deliverables": ["file.ts", "test.ts"],
|
|
140
|
+
"timestamp": "2025-11-06T15:30:00Z",
|
|
141
|
+
"metadata": {
|
|
142
|
+
"stored_via": "store-task-audit.sh",
|
|
143
|
+
"version": "1.0.0"
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### Benefits
|
|
149
|
+
- **✅ Complete Coverage**: Both execution modes fully audited
|
|
150
|
+
- **✅ Memory Safe**: ANTI-023 protection maintained
|
|
151
|
+
- **✅ Compliance Ready**: Full audit trail for enterprise requirements
|
|
152
|
+
- **✅ Debugging Support**: Replay capability for complex issues
|
|
153
|
+
- **✅ Performance**: Fast Redis access + persistent SQLite storage
|
|
154
|
+
|
|
155
|
+
---
|
|
156
|
+
|
|
38
157
|
## Agent Specialization
|
|
39
158
|
|
|
40
159
|
### Loop 3 (Implementation)
|
|
@@ -5,6 +5,18 @@
|
|
|
5
5
|
|
|
6
6
|
set -euo pipefail
|
|
7
7
|
|
|
8
|
+
|
|
9
|
+
# ⚠️ ANTI-023 MEMORY LEAK PROTECTION: Environment Sanitization
|
|
10
|
+
# Load and apply environment sanitization to prevent memory leaks
|
|
11
|
+
# shellcheck source=../cfn-environment-sanitization/sanitize-environment.sh
|
|
12
|
+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
13
|
+
if [[ -f "$SCRIPT_DIR/../cfn-environment-sanitization/sanitize-environment.sh" ]]; then
|
|
14
|
+
source "$SCRIPT_DIR/../cfn-environment-sanitization/sanitize-environment.sh" --strict
|
|
15
|
+
echo "✅ Agent spawning environment sanitized" >&2
|
|
16
|
+
else
|
|
17
|
+
echo "⚠️ Environment sanitization not available - proceeding without protection" >&2
|
|
18
|
+
fi
|
|
19
|
+
|
|
8
20
|
# ⚠️ ANTI-023 MEMORY LEAK PROTECTION: Block Task Mode agents
|
|
9
21
|
# Task Mode agents spawn via Task() tool and should NOT use agent spawning CLI
|
|
10
22
|
if [[ -z "${1:-}" || -z "${TASK_ID:-}" ]]; then
|
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
# Agent Spawning CLI Wrapper
|
|
4
|
+
# Enables agents to spawn other agents or stop existing agents via simple CLI interface
|
|
5
|
+
|
|
6
|
+
set -euo pipefail
|
|
7
|
+
|
|
8
|
+
# ⚠️ ANTI-023 MEMORY LEAK PROTECTION: Block Task Mode agents
|
|
9
|
+
# Task Mode agents spawn via Task() tool and should NOT use agent spawning CLI
|
|
10
|
+
if [[ -z "${1:-}" || -z "${TASK_ID:-}" ]]; then
|
|
11
|
+
echo "❌ TASK MODE DETECTED - Agent spawning CLI forbidden" >&2
|
|
12
|
+
echo "🚨 ANTI-023: This script is for CLI-spawned coordinators only" >&2
|
|
13
|
+
echo "💡 Task Mode agent spawning should be handled directly by Main Chat" >&2
|
|
14
|
+
echo "🔧 Agent spawned via Task() tool - use Task() tool for spawning instead" >&2
|
|
15
|
+
exit 1
|
|
16
|
+
fi
|
|
17
|
+
|
|
18
|
+
# ============================================================================
|
|
19
|
+
# LOGGING FUNCTIONS
|
|
20
|
+
# ============================================================================
|
|
21
|
+
log_error() {
|
|
22
|
+
echo "[ERROR] $*" >&2
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
log_warning() {
|
|
26
|
+
echo "[WARNING] $*" >&2
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
log_info() {
|
|
30
|
+
echo "[INFO] $*"
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
# ============================================================================
|
|
34
|
+
# DEPENDENCY CHECKS
|
|
35
|
+
# ============================================================================
|
|
36
|
+
|
|
37
|
+
check_dependencies() {
|
|
38
|
+
local missing_deps=()
|
|
39
|
+
|
|
40
|
+
# Check bash version
|
|
41
|
+
if [[ "${BASH_VERSINFO[0]}" -lt 4 ]]; then
|
|
42
|
+
missing_deps+=("bash>=4.0")
|
|
43
|
+
fi
|
|
44
|
+
|
|
45
|
+
# Check required command-line tools
|
|
46
|
+
local required_tools=("npx" "node" "grep" "sed")
|
|
47
|
+
for tool in "${required_tools[@]}"; do
|
|
48
|
+
if ! command -v "$tool" &> /dev/null; then
|
|
49
|
+
missing_deps+=("$tool")
|
|
50
|
+
fi
|
|
51
|
+
done
|
|
52
|
+
|
|
53
|
+
# Check required Node.js modules
|
|
54
|
+
local node_modules=(
|
|
55
|
+
"redis"
|
|
56
|
+
"dotenv"
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
for module in "${node_modules[@]}"; do
|
|
60
|
+
if [[ ! -d "node_modules/$module" ]]; then
|
|
61
|
+
missing_deps+=("$module")
|
|
62
|
+
fi
|
|
63
|
+
done
|
|
64
|
+
|
|
65
|
+
# Specific Claude Flow dependencies
|
|
66
|
+
local claude_deps=(
|
|
67
|
+
"Task tool"
|
|
68
|
+
"session-manager.js"
|
|
69
|
+
"redis-coordination scripts"
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
# Use current directory as PROJECT_ROOT if not set
|
|
73
|
+
PROJECT_ROOT="${PROJECT_ROOT:-$(pwd)}"
|
|
74
|
+
|
|
75
|
+
for dep in "${claude_deps[@]}"; do
|
|
76
|
+
if [[ ! -d "$PROJECT_ROOT/.claude" ]]; then
|
|
77
|
+
missing_deps+=("$dep")
|
|
78
|
+
fi
|
|
79
|
+
done
|
|
80
|
+
|
|
81
|
+
# Report missing dependencies
|
|
82
|
+
if [[ ${#missing_deps[@]} -gt 0 ]]; then
|
|
83
|
+
log_error "Missing Dependencies:"
|
|
84
|
+
for dep in "${missing_deps[@]}"; do
|
|
85
|
+
echo " - $dep"
|
|
86
|
+
done
|
|
87
|
+
|
|
88
|
+
log_warning "Recommended Installation:"
|
|
89
|
+
echo " 1. Install Node.js and npm (latest LTS version)"
|
|
90
|
+
echo " 2. Run: npm install redis dotenv"
|
|
91
|
+
echo " 3. Clone Claude Flow Novice repository"
|
|
92
|
+
|
|
93
|
+
exit 1
|
|
94
|
+
fi
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
# ============================================================================
|
|
98
|
+
# AGENT SPAWNING FUNCTIONS
|
|
99
|
+
# ============================================================================
|
|
100
|
+
|
|
101
|
+
# Spawn agents via CLI
|
|
102
|
+
spawn_agents() {
|
|
103
|
+
local task="$1"
|
|
104
|
+
local agents="$2"
|
|
105
|
+
local agent_id="${3:-main}"
|
|
106
|
+
local provider="${4:-zai}"
|
|
107
|
+
local redis_channel="${5:-}"
|
|
108
|
+
|
|
109
|
+
log_info "Spawning agents: $agents"
|
|
110
|
+
log_info "Task: $task"
|
|
111
|
+
|
|
112
|
+
# Build spawn command
|
|
113
|
+
local spawn_cmd="npx claude-flow-spawn \"$task\" --agents=$agents --provider=$provider"
|
|
114
|
+
|
|
115
|
+
# Add optional Redis channel
|
|
116
|
+
if [[ -n "$redis_channel" ]]; then
|
|
117
|
+
spawn_cmd="$spawn_cmd --redis-channel=$redis_channel"
|
|
118
|
+
fi
|
|
119
|
+
|
|
120
|
+
# Execute spawn
|
|
121
|
+
eval "$spawn_cmd"
|
|
122
|
+
local exit_code=$?
|
|
123
|
+
|
|
124
|
+
if [[ $exit_code -eq 0 ]]; then
|
|
125
|
+
log_info "Agents spawned successfully"
|
|
126
|
+
else
|
|
127
|
+
log_error "Failed to spawn agents (exit code: $exit_code)"
|
|
128
|
+
exit $exit_code
|
|
129
|
+
fi
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
# Stop agent by task ID
|
|
133
|
+
stop_agent() {
|
|
134
|
+
local task_id="$1"
|
|
135
|
+
|
|
136
|
+
log_info "Stopping agent: $task_id"
|
|
137
|
+
npx claude-flow-spawn --stop="$task_id"
|
|
138
|
+
|
|
139
|
+
if [[ $? -eq 0 ]]; then
|
|
140
|
+
log_info "Agent stopped successfully"
|
|
141
|
+
else
|
|
142
|
+
log_error "Failed to stop agent"
|
|
143
|
+
exit 1
|
|
144
|
+
fi
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
# Stop all agents
|
|
148
|
+
stop_all_agents() {
|
|
149
|
+
log_info "Stopping all agents"
|
|
150
|
+
npx claude-flow-spawn --stop-all
|
|
151
|
+
|
|
152
|
+
if [[ $? -eq 0 ]]; then
|
|
153
|
+
log_info "All agents stopped"
|
|
154
|
+
else
|
|
155
|
+
log_error "Failed to stop all agents"
|
|
156
|
+
exit 1
|
|
157
|
+
fi
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
# Configuration handler function
|
|
161
|
+
handle_config() {
|
|
162
|
+
local action="$1"
|
|
163
|
+
local key="${2:-}"
|
|
164
|
+
local value="${3:-}"
|
|
165
|
+
|
|
166
|
+
case "$action" in
|
|
167
|
+
list)
|
|
168
|
+
# Placeholder: List configuration (modify as needed)
|
|
169
|
+
echo "redis_host=localhost"
|
|
170
|
+
echo "redis_port=6379"
|
|
171
|
+
;;
|
|
172
|
+
get)
|
|
173
|
+
# Placeholder: Return config value (modify as needed)
|
|
174
|
+
case "$key" in
|
|
175
|
+
redis_host)
|
|
176
|
+
echo "localhost"
|
|
177
|
+
;;
|
|
178
|
+
*)
|
|
179
|
+
log_error "Unknown config key: $key"
|
|
180
|
+
exit 1
|
|
181
|
+
;;
|
|
182
|
+
esac
|
|
183
|
+
;;
|
|
184
|
+
set)
|
|
185
|
+
# Placeholder: Set config value (modify as needed)
|
|
186
|
+
log_info "Setting $key to $value"
|
|
187
|
+
;;
|
|
188
|
+
*)
|
|
189
|
+
log_error "Invalid config action: $action"
|
|
190
|
+
exit 1
|
|
191
|
+
;;
|
|
192
|
+
esac
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
# Main function to include dependency check and argument parsing
|
|
196
|
+
main() {
|
|
197
|
+
check_dependencies # Dependency check before processing
|
|
198
|
+
|
|
199
|
+
# Parse arguments
|
|
200
|
+
case "${1:-}" in
|
|
201
|
+
--check-dependencies)
|
|
202
|
+
log_info "Dependencies checked successfully"
|
|
203
|
+
;;
|
|
204
|
+
--config)
|
|
205
|
+
shift
|
|
206
|
+
handle_config "$@"
|
|
207
|
+
;;
|
|
208
|
+
--task)
|
|
209
|
+
shift
|
|
210
|
+
local task="$1"
|
|
211
|
+
shift
|
|
212
|
+
local agents=""
|
|
213
|
+
local agent_id="main"
|
|
214
|
+
local provider="zai"
|
|
215
|
+
local redis_channel=""
|
|
216
|
+
|
|
217
|
+
# Parse remaining arguments
|
|
218
|
+
while [[ $# -gt 0 ]]; do
|
|
219
|
+
case "$1" in
|
|
220
|
+
--agents)
|
|
221
|
+
agents="$2"
|
|
222
|
+
shift 2
|
|
223
|
+
;;
|
|
224
|
+
--agent-id)
|
|
225
|
+
agent_id="$2"
|
|
226
|
+
shift 2
|
|
227
|
+
;;
|
|
228
|
+
--provider)
|
|
229
|
+
provider="$2"
|
|
230
|
+
shift 2
|
|
231
|
+
;;
|
|
232
|
+
--redis-channel)
|
|
233
|
+
redis_channel="$2"
|
|
234
|
+
shift 2
|
|
235
|
+
;;
|
|
236
|
+
*)
|
|
237
|
+
log_error "Unknown argument: $1"
|
|
238
|
+
exit 1
|
|
239
|
+
;;
|
|
240
|
+
esac
|
|
241
|
+
done
|
|
242
|
+
|
|
243
|
+
# Validate required arguments
|
|
244
|
+
if [[ -z "$task" ]] || [[ -z "$agents" ]]; then
|
|
245
|
+
log_error "Missing required arguments: --task and --agents"
|
|
246
|
+
exit 1
|
|
247
|
+
fi
|
|
248
|
+
|
|
249
|
+
# Spawn agents
|
|
250
|
+
spawn_agents "$task" "$agents" "$agent_id" "$provider" "$redis_channel"
|
|
251
|
+
;;
|
|
252
|
+
--stop)
|
|
253
|
+
shift
|
|
254
|
+
stop_agent "$1"
|
|
255
|
+
;;
|
|
256
|
+
--stop-all)
|
|
257
|
+
stop_all_agents
|
|
258
|
+
;;
|
|
259
|
+
*)
|
|
260
|
+
log_error "Unknown argument: $1"
|
|
261
|
+
echo "Usage:"
|
|
262
|
+
echo " spawn-agent.sh --task \"Task description\" --agents coder,tester [--provider zai] [--redis-channel channel]"
|
|
263
|
+
echo " spawn-agent.sh --stop <task-id>"
|
|
264
|
+
echo " spawn-agent.sh --stop-all"
|
|
265
|
+
echo " spawn-agent.sh --check-dependencies"
|
|
266
|
+
echo " spawn-agent.sh --config list|get|set"
|
|
267
|
+
exit 1
|
|
268
|
+
;;
|
|
269
|
+
esac
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
# Run main function
|
|
273
|
+
main "$@"
|
|
@@ -21,6 +21,10 @@
|
|
|
21
21
|
|
|
22
22
|
set -euo pipefail
|
|
23
23
|
|
|
24
|
+
# Determine PROJECT_ROOT first before any other operations
|
|
25
|
+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
26
|
+
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
|
|
27
|
+
|
|
24
28
|
# ⚠️ ANTI-023 MEMORY LEAK PROTECTION: Block Task Mode agents
|
|
25
29
|
# Task Mode agents spawn via Task() tool and should NOT use orchestration scripts
|
|
26
30
|
if [[ -z "${TASK_ID:-}" || -z "${LOOP3_AGENTS:-}" ]]; then
|
|
@@ -31,14 +35,39 @@ if [[ -z "${TASK_ID:-}" || -z "${LOOP3_AGENTS:-}" ]]; then
|
|
|
31
35
|
exit 1
|
|
32
36
|
fi
|
|
33
37
|
|
|
38
|
+
# ⚠️ ANTI-023 MEMORY LEAK PROTECTION: Environment Sanitization
|
|
39
|
+
# Load and apply environment sanitization to prevent memory leaks
|
|
40
|
+
if [[ -f "$PROJECT_ROOT/.claude/skills/cfn-task-mode-sanitize/task-mode-env-sanitizer.sh" ]]; then
|
|
41
|
+
source "$PROJECT_ROOT/.claude/skills/cfn-task-mode-sanitize/task-mode-env-sanitizer.sh"
|
|
42
|
+
sanitize_task_mode_environment "cli"
|
|
43
|
+
echo "✅ Environment sanitization applied" >&2
|
|
44
|
+
else
|
|
45
|
+
echo "⚠️ Environment sanitization not available - proceeding without protection" >&2
|
|
46
|
+
fi
|
|
47
|
+
|
|
48
|
+
# ⚠️ ANTI-023 MEMORY LEAK PROTECTION: Process Instrumentation
|
|
49
|
+
# Load process instrumentation and monitoring for the orchestrator
|
|
50
|
+
if [[ -f "$PROJECT_ROOT/.claude/skills/cfn-validation-runner-instrumentation/wrapped-executor.sh" ]]; then
|
|
51
|
+
source "$PROJECT_ROOT/.claude/skills/cfn-validation-runner-instrumentation/wrapped-executor.sh"
|
|
52
|
+
echo "✅ Orchestrator process instrumentation enabled" >&2
|
|
53
|
+
else
|
|
54
|
+
echo "⚠️ Process instrumentation not available - proceeding without monitoring" >&2
|
|
55
|
+
fi
|
|
56
|
+
|
|
57
|
+
# ⚠️ ANTI-023 MEMORY LEAK PROTECTION: Environment Configuration
|
|
58
|
+
# Set stabilization environment variables with sensible defaults
|
|
59
|
+
export CFN_VALIDATION_TIMEOUT="${CFN_VALIDATION_TIMEOUT:-300}" # 5 minutes
|
|
60
|
+
export CFN_MEMORY_LIMIT="${CFN_MEMORY_LIMIT:-2048}" # 2GB memory limit
|
|
61
|
+
export CFN_CPU_LIMIT="${CFN_CPU_LIMIT:-80}" # 80% CPU limit
|
|
62
|
+
export CFN_TELEMETRY_DIR="${CFN_TELEMETRY_DIR:-$PROJECT_ROOT/.artifacts/telemetry}"
|
|
63
|
+
mkdir -p "$CFN_TELEMETRY_DIR"
|
|
64
|
+
|
|
34
65
|
# Load security utilities
|
|
35
66
|
# shellcheck source=./security_utils.sh
|
|
36
67
|
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/security_utils.sh"
|
|
37
68
|
|
|
38
|
-
# Determine script directory
|
|
39
|
-
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
40
69
|
HELPERS_DIR="$SCRIPT_DIR/helpers"
|
|
41
|
-
|
|
70
|
+
REDIS_COORD_SKILL="$PROJECT_ROOT/.claude/skills/cfn-redis-coordination"
|
|
42
71
|
|
|
43
72
|
# Configuration
|
|
44
73
|
TASK_ID=""
|
|
@@ -250,6 +279,16 @@ if [ -z "$TASK_ID" ] || [ -z "$LOOP3_AGENTS" ] || [ -z "$LOOP2_AGENTS" ] || [ -z
|
|
|
250
279
|
exit 1
|
|
251
280
|
fi
|
|
252
281
|
|
|
282
|
+
# ⚠️ ANTI-023 MEMORY LEAK PROTECTION: Process Instrumentation
|
|
283
|
+
# Load process instrumentation and monitoring for the orchestrator
|
|
284
|
+
# shellcheck source=../cfn-process-instrumentation/instrument-process.sh
|
|
285
|
+
if [[ -f "$PROJECT_ROOT/.claude/skills/cfn-process-instrumentation/instrument-process.sh" ]]; then
|
|
286
|
+
source "$PROJECT_ROOT/.claude/skills/cfn-process-instrumentation/instrument-process.sh"
|
|
287
|
+
echo "✅ Orchestrator process instrumentation enabled" >&2
|
|
288
|
+
else
|
|
289
|
+
echo "⚠️ Process instrumentation not available - proceeding without monitoring" >&2
|
|
290
|
+
fi
|
|
291
|
+
|
|
253
292
|
# Get thresholds for mode
|
|
254
293
|
# Add additional mode validation with safe fallback
|
|
255
294
|
case "$MODE" in
|
|
@@ -435,12 +474,22 @@ function spawn_loop3_agents() {
|
|
|
435
474
|
safe_task_id=$(sanitize_input "$task_id") || continue
|
|
436
475
|
safe_agent_id=$(sanitize_input "$UNIQUE_AGENT_ID") || continue
|
|
437
476
|
|
|
438
|
-
# Spawn agent in background with
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
477
|
+
# Spawn agent in background with process instrumentation and memory limits
|
|
478
|
+
if command -v execute_instrumented >/dev/null 2>&1; then
|
|
479
|
+
execute_instrumented "npx" "$CFN_VALIDATION_TIMEOUT" "$CFN_MEMORY_LIMIT" \
|
|
480
|
+
claude-flow-novice agent "$safe_agent_type" \
|
|
481
|
+
--task-id "$safe_task_id" \
|
|
482
|
+
--agent-id "$safe_agent_id" \
|
|
483
|
+
--iteration "$iteration" \
|
|
484
|
+
--context "$(build_agent_context "$safe_task_id" "$iteration" "$safe_agent_type" "" "loop3")" &
|
|
485
|
+
else
|
|
486
|
+
# Fallback to raw spawn if instrumentation unavailable
|
|
487
|
+
npx claude-flow-novice agent "$safe_agent_type" \
|
|
488
|
+
--task-id "$safe_task_id" \
|
|
489
|
+
--agent-id "$safe_agent_id" \
|
|
490
|
+
--iteration "$iteration" \
|
|
491
|
+
--context "$(build_agent_context "$safe_task_id" "$iteration" "$safe_agent_type" "" "loop3")" &
|
|
492
|
+
fi
|
|
444
493
|
|
|
445
494
|
# Store PID for monitoring using unique agent ID
|
|
446
495
|
AGENT_PID=$!
|
|
@@ -450,6 +499,17 @@ function spawn_loop3_agents() {
|
|
|
450
499
|
--value "{\"pid\": $AGENT_PID}" \
|
|
451
500
|
--namespace "swarm" >/dev/null
|
|
452
501
|
|
|
502
|
+
# ⚠️ ANTI-023 MEMORY LEAK PROTECTION: Start telemetry monitoring
|
|
503
|
+
if [[ -f "$PROJECT_ROOT/.claude/skills/cfn-telemetry/collect-metrics.sh" ]]; then
|
|
504
|
+
MONITOR_PID=$("$PROJECT_ROOT/.claude/skills/cfn-telemetry/collect-metrics.sh" start-monitoring "$UNIQUE_AGENT_ID" "$AGENT_PID" "$iteration" "$safe_agent_type")
|
|
505
|
+
"$REDIS_COORD_SKILL/store-context.sh" \
|
|
506
|
+
--task-id "$task_id" \
|
|
507
|
+
--key "${UNIQUE_AGENT_ID}:monitor_pid" \
|
|
508
|
+
--value "{\"pid\": $MONITOR_PID}" \
|
|
509
|
+
--namespace "swarm" >/dev/null
|
|
510
|
+
echo "🔍 Started monitoring for $UNIQUE_AGENT_ID (Agent PID: $AGENT_PID, Monitor PID: $MONITOR_PID)" >&2
|
|
511
|
+
fi
|
|
512
|
+
|
|
453
513
|
# Store agent ID mapping for later retrieval using Redis SADD for set storage
|
|
454
514
|
redis-cli SADD "swarm:${task_id}:loop3:agent_ids:iteration${iteration}" "$UNIQUE_AGENT_ID" >/dev/null
|
|
455
515
|
done
|
|
@@ -524,6 +584,16 @@ function wait_for_agents() {
|
|
|
524
584
|
wait "$pid" 2>/dev/null || true
|
|
525
585
|
done
|
|
526
586
|
|
|
587
|
+
# ⚠️ ANTI-023 MEMORY LEAK PROTECTION: Stop monitoring for all agents
|
|
588
|
+
echo " Stopping telemetry monitoring for Loop 3 agents..." >&2
|
|
589
|
+
for unique_agent_id in "${AGENT_IDS[@]}"; do
|
|
590
|
+
local monitor_pid=$("$REDIS_COORD_SKILL/get-context.sh" --task-id "$task_id" --key "${unique_agent_id}:monitor_pid" --namespace "swarm" 2>/dev/null | jq -r '.pid // 0' || echo "0")
|
|
591
|
+
if [[ "$monitor_pid" -gt 0 ]] && kill -0 "$monitor_pid" 2>/dev/null; then
|
|
592
|
+
"$PROJECT_ROOT/.claude/skills/cfn-telemetry/collect-metrics.sh" stop-monitoring "$monitor_pid" >/dev/null 2>&1 || true
|
|
593
|
+
echo " Stopped monitoring for $unique_agent_id (Monitor PID: $monitor_pid)" >&2
|
|
594
|
+
fi
|
|
595
|
+
done
|
|
596
|
+
|
|
527
597
|
# Calculate actual elapsed time
|
|
528
598
|
local end_time=$(date +%s)
|
|
529
599
|
local elapsed=$((end_time - start_time))
|
|
@@ -668,12 +738,22 @@ function spawn_loop2_agents() {
|
|
|
668
738
|
|
|
669
739
|
echo " Spawning: $agent_type (ID: $UNIQUE_VALIDATOR_ID)"
|
|
670
740
|
|
|
671
|
-
# Spawn
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
741
|
+
# Spawn validator in background with process instrumentation and memory limits
|
|
742
|
+
if command -v execute_instrumented >/dev/null 2>&1; then
|
|
743
|
+
execute_instrumented "npx" "$CFN_VALIDATION_TIMEOUT" "$CFN_MEMORY_LIMIT" \
|
|
744
|
+
claude-flow-novice agent "$agent_type" \
|
|
745
|
+
--task-id "$task_id" \
|
|
746
|
+
--agent-id "$UNIQUE_VALIDATOR_ID" \
|
|
747
|
+
--iteration "$iteration" \
|
|
748
|
+
--context "$(build_agent_context "$task_id" "$iteration" "$agent_type" "" "loop2")" &
|
|
749
|
+
else
|
|
750
|
+
# Fallback to raw spawn if instrumentation unavailable
|
|
751
|
+
npx claude-flow-novice agent "$agent_type" \
|
|
752
|
+
--task-id "$task_id" \
|
|
753
|
+
--agent-id "$UNIQUE_VALIDATOR_ID" \
|
|
754
|
+
--iteration "$iteration" \
|
|
755
|
+
--context "$(build_agent_context "$task_id" "$iteration" "$agent_type" "" "loop2")" &
|
|
756
|
+
fi
|
|
677
757
|
|
|
678
758
|
# Store PID for monitoring using unique agent ID
|
|
679
759
|
AGENT_PID=$!
|