claude-flow-novice 2.14.35 โ†’ 2.14.36

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.
Files changed (39) hide show
  1. package/.claude/commands/CFN_LOOP_TASK_MODE.md +1 -1
  2. package/.claude/commands/switch-api.md +1 -1
  3. package/.claude/skills/cfn-loop-orchestration/orchestrate.sh +2 -1
  4. package/.claude/skills/cfn-loop-validation/config.json +2 -2
  5. package/claude-assets/agents/README-AGENT_LIFECYCLE.md +37 -10
  6. package/claude-assets/agents/README-VALIDATION.md +0 -8
  7. package/claude-assets/agents/cfn-dev-team/README.md +0 -8
  8. package/claude-assets/agents/cfn-dev-team/coordinators/README.md +1 -9
  9. package/claude-assets/agents/cfn-dev-team/developers/README.md +1 -9
  10. package/claude-assets/agents/cfn-dev-team/documentation/README-VALIDATION.md +0 -8
  11. package/claude-assets/agents/cfn-dev-team/documentation/agent-type-guidelines.md +0 -10
  12. package/claude-assets/agents/cfn-dev-team/reviewers/README.md +1 -9
  13. package/claude-assets/agents/cfn-dev-team/reviewers/quality/quality-metrics.md +0 -10
  14. package/claude-assets/agents/cfn-dev-team/test-agent.md +0 -10
  15. package/claude-assets/agents/cfn-dev-team/testers/README.md +1 -9
  16. package/claude-assets/agents/csuite/cto-agent.md +0 -10
  17. package/claude-assets/agents/custom/cfn-system-expert.md +1 -128
  18. package/claude-assets/agents/docker-coordinators/cfn-docker-v3-coordinator.md +1 -5
  19. package/claude-assets/agents/docker-team/csuite/c-suite-template.md +1 -5
  20. package/claude-assets/agents/docker-team/infrastructure/team-coordinator-template.md +1 -5
  21. package/claude-assets/agents/marketing_hybrid/cost_tracker.md +0 -10
  22. package/claude-assets/agents/marketing_hybrid/docker_deployer.md +0 -10
  23. package/claude-assets/agents/marketing_hybrid/zai_worker_spawner.md +0 -10
  24. package/claude-assets/commands/CFN_LOOP_TASK_MODE.md +1 -1
  25. package/claude-assets/commands/switch-api.md +1 -1
  26. package/claude-assets/skills/cfn-loop-orchestration/orchestrate.sh +2 -1
  27. package/claude-assets/skills/cfn-loop-validation/config.json +2 -2
  28. package/claude-assets/skills/cfn-process-instrumentation/instrument-process.sh +324 -322
  29. package/claude-assets/skills/cfn-task-config-init/initialize-config.sh +2 -2
  30. package/claude-assets/skills/cfn-task-mode-sanitize/task-mode-env-sanitizer.sh +213 -182
  31. package/claude-assets/skills/cfn-validation-runner-instrumentation/wrapped-executor.sh +233 -271
  32. package/dist/agents/agent-loader.js +467 -133
  33. package/dist/agents/agent-loader.js.map +1 -1
  34. package/dist/cli/config-manager.js +109 -91
  35. package/dist/cli/config-manager.js.map +1 -1
  36. package/package.json +1 -1
  37. package/scripts/docker-build-mcp.sh +155 -0
  38. package/scripts/docker-test-mcp.sh +260 -0
  39. package/scripts/mcp-health-check.sh +123 -0
@@ -1,224 +1,255 @@
1
- #!/bin/bash
1
+ #!/usr/bin/env bash
2
+
3
+ ##############################################################################
2
4
  # CFN Task Mode Environment Sanitizer
3
- # Sanitizes and enforces Task-mode environment variables to prevent mode confusion
5
+ # Prevents memory leaks and environment contamination in CFN Loop execution
6
+ #
7
+ # Usage:
8
+ # source task-mode-env-sanitizer.sh
9
+ # sanitize_task_mode_environment <mode>
10
+ #
11
+ # Modes:
12
+ # cli - CLI mode execution (production)
13
+ # task - Task mode execution (debugging)
14
+ ##############################################################################
4
15
 
5
16
  set -euo pipefail
6
17
 
7
- # Script configuration
8
- SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
9
- PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
18
+ # Global state tracking
19
+ declare -A CFN_SANITIZER_STATE
20
+ CFN_SANITIZER_STATE["initialized"]=false
21
+ CFN_SANITIZER_STATE["mode"]=""
22
+ CFN_SANITIZER_STATE["start_time"]=$(date +%s)
23
+
24
+ # Memory leak prevention thresholds
25
+ readonly MAX_AGENT_PROCESSES=50
26
+ readonly MAX_MEMORY_MB=4096
27
+ readonly MAX_RUNTIME_SECONDS=3600 # 1 hour
28
+
29
+ ##############################################################################
30
+ # Core Sanitization Functions
31
+ ##############################################################################
10
32
 
11
- # Environment sanitization rules
12
33
  sanitize_task_mode_environment() {
13
- local mode="${1:-auto}"
34
+ local mode="${1:-task}"
35
+
36
+ # Initialize sanitizer state
37
+ CFN_SANITIZER_STATE["mode"]="$mode"
38
+ CFN_SANITIZER_STATE["initialized"]=true
39
+
40
+ echo "๐Ÿงน CFN Environment Sanitizer v1.0.0" >&2
41
+ echo " Mode: $mode" >&2
42
+ echo " PID: $$" >&2
43
+ echo " Start: $(date -u +%Y-%m-%dT%H:%M:%SZ)" >&2
44
+
45
+ # Apply mode-specific sanitization
46
+ case "$mode" in
47
+ "cli")
48
+ sanitize_cli_environment
49
+ ;;
50
+ "task")
51
+ sanitize_task_environment
52
+ ;;
53
+ *)
54
+ echo "โš ๏ธ Unknown mode: $mode, applying default sanitization" >&2
55
+ sanitize_default_environment
56
+ ;;
57
+ esac
58
+
59
+ # Setup monitoring and cleanup hooks
60
+ setup_environment_monitoring
61
+ setup_cleanup_hooks
62
+
63
+ echo "โœ… Environment sanitization complete" >&2
64
+ }
14
65
 
15
- echo "๐Ÿงน Sanitizing Task-mode environment..." >&2
66
+ sanitize_cli_environment() {
67
+ echo " Applying CLI mode sanitization..." >&2
16
68
 
17
- # 1. Force CFN_MODE=task for Task mode
18
- if [[ "$mode" == "task" || "$mode" == "auto" ]]; then
19
- export CFN_MODE="task"
20
- echo "โœ… CFN_MODE forced to: $CFN_MODE" >&2
21
- fi
69
+ # Clear any previous agent state
70
+ unset AGENT_ID 2>/dev/null || true
71
+ unset TASK_ID 2>/dev/null || true
72
+ unset SWARM_ID 2>/dev/null || true
22
73
 
23
- # 2. Clear inherited CLI-mode variables that could cause mode confusion
24
- local inherited_vars=(
25
- "TASK_ID"
26
- "AGENT_ID"
27
- "LOOP3_AGENTS"
28
- "LOOP2_VALIDATORS"
29
- "PRODUCT_OWNER_ID"
30
- "COORDINATOR_ID"
31
- "__CFN_CLI_SPAWN"
32
- "CFN_CLI_CONTEXT"
33
- )
34
-
35
- for var in "${inherited_vars[@]}"; do
36
- if [[ -n "${!var:-}" ]]; then
37
- echo "๐Ÿ—‘๏ธ Clearing inherited variable: $var (was: ${!var})" >&2
38
- unset "$var"
39
- fi
40
- done
41
-
42
- # 3. Set Task-mode specific environment
43
- export __CFN_TASK_MODE="1"
44
- export __CFN_MODE_ENFORCED="1"
45
-
46
- # 4. Right-size Node.js heap for Task mode (prevent 16GB default)
47
- if [[ -z "${NODE_OPTIONS:-}" ]]; then
48
- export NODE_OPTIONS="--max-old-space-size=2048"
49
- else
50
- # Replace any larger heap size with Task-mode appropriate size
51
- if echo "$NODE_OPTIONS" | grep -q "max-old-space-size"; then
52
- export NODE_OPTIONS=$(echo "$NODE_OPTIONS" | sed 's/--max-old-space-size=[0-9]*/--max-old-space-size=2048/g')
53
- else
54
- export NODE_OPTIONS="$NODE_OPTIONS --max-old-space-size=2048"
55
- fi
56
- fi
57
- echo "โœ… NODE_OPTIONS set for Task mode: $NODE_OPTIONS" >&2
74
+ # Optimize for production CLI execution
75
+ export CFN_MODE="cli"
76
+ export CFN_SANITIZER_ACTIVE=true
58
77
 
59
- # 5. Configure Task-mode specific settings
60
- export CFN_MEMORY_LIMIT="2048" # MB
61
- export CFN_TIMEOUT="300" # 5 minutes
62
- export CFN_COORDINATION="file" # Use file-based coordination
78
+ # Set conservative resource limits
79
+ ulimit -u $MAX_AGENT_PROCESSES 2>/dev/null || true
80
+ ulimit -v $((MAX_MEMORY_MB * 1024)) 2>/dev/null || true
63
81
 
64
- echo "๐ŸŽฏ Task-mode environment sanitized and locked" >&2
82
+ # Disable debug features in production
83
+ export CFN_DEBUG=false
84
+ export CFN_VERBOSE=false
65
85
  }
66
86
 
67
- # Validate environment is in Task mode
68
- validate_task_mode_environment() {
69
- local errors=0
87
+ sanitize_task_environment() {
88
+ echo " Applying Task mode sanitization..." >&2
70
89
 
71
- echo "๐Ÿ” Validating Task-mode environment..." >&2
90
+ # Task mode allows more debugging
91
+ export CFN_MODE="task"
92
+ export CFN_SANITIZER_ACTIVE=true
72
93
 
73
- # Check CFN_MODE
74
- if [[ "${CFN_MODE:-}" != "task" ]]; then
75
- echo "โŒ CFN_MODE should be 'task', got: ${CFN_MODE:-unset}" >&2
76
- ((errors++))
77
- fi
94
+ # More permissive limits for debugging
95
+ ulimit -u $((MAX_AGENT_PROCESSES * 2)) 2>/dev/null || true
96
+ ulimit -v $((MAX_MEMORY_MB * 1024 * 2)) 2>/dev/null || true
78
97
 
79
- # Check Task-mode markers
80
- if [[ "${__CFN_TASK_MODE:-}" != "1" ]]; then
81
- echo "โŒ __CFN_TASK_MODE not set" >&2
82
- ((errors++))
83
- fi
98
+ # Enable debug features for task mode
99
+ export CFN_DEBUG=${CFN_DEBUG:-true}
100
+ export CFN_VERBOSE=${CFN_VERBOSE:-true}
101
+ }
84
102
 
85
- # Check for prohibited CLI variables
86
- local prohibited_vars=(
87
- "TASK_ID"
88
- "AGENT_ID"
89
- "LOOP3_AGENTS"
90
- "__CFN_CLI_SPAWN"
91
- )
92
-
93
- for var in "${prohibited_vars[@]}"; do
94
- if [[ -n "${!var:-}" ]]; then
95
- echo "โŒ Prohibited CLI variable found: $var=${!var}" >&2
96
- ((errors++))
97
- fi
98
- done
99
-
100
- # Check Node heap size
101
- if echo "$NODE_OPTIONS" | grep -q "max-old-space-size"; then
102
- local heap_size=$(echo "$NODE_OPTIONS" | grep -o "max-old-space-size=[0-9]*" | cut -d= -f2)
103
- if [[ "$heap_size" -gt 4096 ]]; then
104
- echo "โŒ Node heap size too large for Task mode: ${heap_size}MB" >&2
105
- ((errors++))
106
- fi
107
- else
108
- echo "โš ๏ธ No Node heap size specified (should be set to 2048MB)" >&2
109
- fi
103
+ sanitize_default_environment() {
104
+ echo " Applying default sanitization..." >&2
110
105
 
111
- if [[ $errors -eq 0 ]]; then
112
- echo "โœ… Task-mode environment validation passed" >&2
113
- return 0
114
- else
115
- echo "โŒ Task-mode environment validation failed ($errors errors)" >&2
116
- return 1
106
+ # Basic sanitization for unknown modes
107
+ export CFN_MODE="unknown"
108
+ export CFN_SANITIZER_ACTIVE=true
109
+
110
+ # Conservative limits
111
+ ulimit -u $MAX_AGENT_PROCESSES 2>/dev/null || true
112
+ }
113
+
114
+ ##############################################################################
115
+ # Environment Monitoring
116
+ ##############################################################################
117
+
118
+ setup_environment_monitoring() {
119
+ # Start background monitoring if available
120
+ if command -v timeout >/dev/null 2>&1; then
121
+ (
122
+ sleep $MAX_RUNTIME_SECONDS
123
+ if [[ "${CFN_SANITIZER_STATE[initialized]}" == "true" ]]; then
124
+ echo "โš ๏ธ CFN Environment timeout reached, forcing cleanup" >&2
125
+ force_environment_cleanup
126
+ fi
127
+ ) &
128
+ echo " Started runtime monitoring (${MAX_RUNTIME_SECONDS}s)" >&2
117
129
  fi
118
130
  }
119
131
 
120
- # Execute command in sanitized Task-mode environment
121
- exec_task_mode_sanitized() {
122
- local command="$1"
123
- shift
132
+ setup_cleanup_hooks() {
133
+ # Setup cleanup trap for graceful shutdown
134
+ trap 'environment_cleanup_on_exit' EXIT
135
+ trap 'environment_cleanup_on_signal INT' INT
136
+ trap 'environment_cleanup_on_signal TERM' TERM
137
+ trap 'environment_cleanup_on_signal HUP' HUP
138
+ }
124
139
 
125
- echo "๐Ÿš€ Executing in sanitized Task-mode environment: $command" >&2
140
+ environment_cleanup_on_exit() {
141
+ echo "๐Ÿงน CFN Environment cleanup on exit" >&2
142
+
143
+ # Calculate runtime
144
+ local end_time=$(date +%s)
145
+ local runtime=$((end_time - CFN_SANITIZER_STATE["start_time"]))
146
+ echo " Runtime: ${runtime}s" >&2
147
+
148
+ # Mode-specific cleanup
149
+ case "${CFN_SANITIZER_STATE[mode]}" in
150
+ "cli")
151
+ cleanup_cli_environment
152
+ ;;
153
+ "task")
154
+ cleanup_task_environment
155
+ ;;
156
+ esac
157
+
158
+ # Clear sanitizer state
159
+ CFN_SANITIZER_STATE["initialized"]=false
160
+ echo "โœ… Environment cleanup complete" >&2
161
+ }
126
162
 
127
- # Sanitize environment
128
- sanitize_task_mode_environment "task"
163
+ environment_cleanup_on_signal() {
164
+ local signal="$1"
165
+ echo "๐Ÿงน CFN Environment cleanup on signal: $signal" >&2
166
+ environment_cleanup_on_exit
167
+ exit 130
168
+ }
129
169
 
130
- # Validate environment
131
- if ! validate_task_mode_environment; then
132
- echo "โŒ Environment validation failed, aborting execution" >&2
133
- return 1
134
- fi
170
+ cleanup_cli_environment() {
171
+ echo " CLI mode cleanup..." >&2
135
172
 
136
- # Execute command with timeout
137
- local timeout="${CFN_TIMEOUT:-300}"
138
- echo "โฑ๏ธ Timeout set to ${timeout}s" >&2
139
-
140
- if timeout "$timeout" "$command" "$@"; then
141
- echo "โœ… Command completed successfully" >&2
142
- return 0
143
- else
144
- local exit_code=$?
145
- if [[ $exit_code -eq 124 ]]; then
146
- echo "โฐ Command timed out after ${timeout}s" >&2
147
- else
148
- echo "โŒ Command failed with exit code: $exit_code" >&2
173
+ # Clean up any lingering agent processes
174
+ if command -v pgrep >/dev/null 2>&1; then
175
+ local agent_pids=$(pgrep -f "claude-flow-novice.*agent" 2>/dev/null || true)
176
+ if [[ -n "$agent_pids" ]]; then
177
+ echo " Warning: Found agent processes: $agent_pids" >&2
149
178
  fi
150
- return $exit_code
151
179
  fi
152
180
  }
153
181
 
154
- # Show usage
155
- show_usage() {
156
- cat <<'EOF'
157
- CFN Task Mode Environment Sanitizer
182
+ cleanup_task_environment() {
183
+ echo " Task mode cleanup..." >&2
184
+ # Task mode cleanup - more permissive
185
+ }
158
186
 
159
- USAGE:
160
- source "$(dirname "${BASH_SOURCE[0]}")/task-mode-env-sanitizer.sh"
187
+ force_environment_cleanup() {
188
+ echo "๐Ÿšจ Force cleanup triggered!" >&2
161
189
 
162
- # Environment Sanitization
163
- sanitize_task_mode_environment [mode] # Sanitize environment (auto|task|cli)
164
- validate_task_mode_environment # Validate current environment
190
+ # Kill any remaining processes in this process group
191
+ if [[ -n "${CFN_PROCESS_GROUP:-}" ]]; then
192
+ kill -TERM -$CFN_PROCESS_GROUP 2>/dev/null || true
193
+ sleep 2
194
+ kill -KILL -$CFN_PROCESS_GROUP 2>/dev/null || true
195
+ fi
165
196
 
166
- # Command Execution
167
- exec_task_mode_sanitized <command> [args...] # Execute command in sanitized environment
197
+ # Force exit
198
+ exit 1
199
+ }
168
200
 
169
- EXAMPLES:
170
- # Sanitize current shell
171
- sanitize_task_mode_environment task
201
+ ##############################################################################
202
+ # Utility Functions
203
+ ##############################################################################
172
204
 
173
- # Execute validator with sanitized environment
174
- exec_task_mode_sanitized node validate-code.js
205
+ check_environment_health() {
206
+ local mode="${1:-${CFN_SANITIZER_STATE[mode]}}"
175
207
 
176
- # Run with environment validation
177
- if validate_task_mode_environment; then
178
- echo "Environment is safe for Task mode"
208
+ if [[ "${CFN_SANITIZER_STATE[initialized]}" != "true" ]]; then
209
+ echo "โŒ Environment sanitizer not initialized" >&2
210
+ return 1
179
211
  fi
180
212
 
181
- ENVIRONMENT VARIABLES:
182
- CFN_MODE # Forced to 'task' for Task mode
183
- __CFN_TASK_MODE # Set to '1' in Task mode
184
- NODE_OPTIONS # Limited to 2048MB heap in Task mode
185
- CFN_MEMORY_LIMIT # Memory limit in MB (default: 2048)
186
- CFN_TIMEOUT # Command timeout in seconds (default: 300)
187
- CFN_COORDINATION # Coordination method: 'file' for Task mode
213
+ # Check memory usage
214
+ if command -v ps >/dev/null 2>&1; then
215
+ local memory_mb=$(ps -o rss= -p $$ 2>/dev/null | awk '{print $1/1024}' || echo "0")
216
+ if (( $(echo "$memory_mb > $MAX_MEMORY_MB" | bc -l 2>/dev/null || echo "0") )); then
217
+ echo "โš ๏ธ High memory usage: ${memory_mb}MB" >&2
218
+ fi
219
+ fi
188
220
 
189
- EOF
221
+ # Check process count
222
+ if command -v ps >/dev/null 2>&1; then
223
+ local process_count=$(ps -eo pid=,ppid= | grep -c "^[[:space:]]*$$[[:space:]]" || echo "0")
224
+ if (( process_count > MAX_AGENT_PROCESSES )); then
225
+ echo "โš ๏ธ High process count: $process_count" >&2
226
+ fi
227
+ fi
228
+
229
+ echo "โœ… Environment health check passed" >&2
230
+ return 0
190
231
  }
191
232
 
192
- # Main execution block
193
- if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
194
- if [[ "$1" == "--help" || "$1" == "-h" ]]; then
195
- show_usage
196
- exit 0
197
- fi
233
+ get_sanitizer_info() {
234
+ echo "CFN Environment Sanitizer Info:"
235
+ echo " Initialized: ${CFN_SANITIZER_STATE[initialized]}"
236
+ echo " Mode: ${CFN_SANITIZER_STATE[mode]}"
237
+ echo " Start Time: ${CFN_SANITIZER_STATE[start_time]}"
238
+ echo " PID: $$"
239
+ echo " Runtime: $(($(date +%s) - CFN_SANITIZER_STATE[start_time]))s"
240
+ }
198
241
 
199
- # Execute operation if provided
200
- if [[ $# -gt 0 ]]; then
201
- case "$1" in
202
- "sanitize")
203
- sanitize_task_mode_environment "${2:-auto}"
204
- ;;
205
- "validate")
206
- validate_task_mode_environment
207
- ;;
208
- "exec")
209
- shift
210
- exec_task_mode_sanitized "$@"
211
- ;;
212
- *)
213
- echo "Unknown operation: $1" >&2
214
- echo "Use --help for usage information" >&2
215
- exit 1
216
- ;;
217
- esac
218
- else
219
- echo "CFN Task Mode Environment Sanitizer" >&2
220
- echo "Current mode: ${CFN_MODE:-unset}" >&2
221
- echo "Node options: ${NODE_OPTIONS:-unset}" >&2
222
- echo "Use --help for usage information" >&2
223
- fi
242
+ ##############################################################################
243
+ # Auto-initialization for safety
244
+ ##############################################################################
245
+
246
+ # If script is sourced (not executed), make sanitizer available
247
+ if [[ "${BASH_SOURCE[0]}" != "${0}" ]]; then
248
+ echo "๐Ÿ”ง CFN Environment Sanitizer loaded" >&2
249
+ echo " Use: sanitize_task_mode_environment <mode>" >&2
250
+ fi
251
+
252
+ # If script is executed directly, run with default mode
253
+ if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
254
+ sanitize_task_mode_environment "${1:-task}"
224
255
  fi