claude-flow-novice 2.14.35 → 2.14.37

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 (56) hide show
  1. package/.claude/commands/CFN_LOOP_TASK_MODE.md +1 -1
  2. package/.claude/commands/cfn-loop-cli.md +491 -456
  3. package/.claude/commands/switch-api.md +1 -1
  4. package/.claude/skills/cfn-loop-orchestration/orchestrate.sh +2 -1
  5. package/.claude/skills/cfn-loop-validation/config.json +2 -2
  6. package/.claude/skills/cfn-redis-coordination/invoke-waiting-mode.sh +220 -220
  7. package/claude-assets/agents/README-AGENT_LIFECYCLE.md +37 -10
  8. package/claude-assets/agents/README-VALIDATION.md +0 -8
  9. package/claude-assets/agents/cfn-dev-team/README.md +0 -8
  10. package/claude-assets/agents/cfn-dev-team/coordinators/README.md +1 -9
  11. package/claude-assets/agents/cfn-dev-team/developers/README.md +1 -9
  12. package/claude-assets/agents/cfn-dev-team/documentation/README-VALIDATION.md +0 -8
  13. package/claude-assets/agents/cfn-dev-team/documentation/agent-type-guidelines.md +0 -10
  14. package/claude-assets/agents/cfn-dev-team/reviewers/README.md +1 -9
  15. package/claude-assets/agents/cfn-dev-team/reviewers/quality/quality-metrics.md +0 -10
  16. package/claude-assets/agents/cfn-dev-team/test-agent.md +0 -10
  17. package/claude-assets/agents/cfn-dev-team/testers/README.md +1 -9
  18. package/claude-assets/agents/csuite/cto-agent.md +0 -10
  19. package/claude-assets/agents/custom/cfn-system-expert.md +1 -128
  20. package/claude-assets/agents/custom/claude-code-expert.md +151 -2
  21. package/claude-assets/agents/docker-coordinators/cfn-docker-v3-coordinator.md +39 -3
  22. package/claude-assets/agents/docker-team/csuite/c-suite-template.md +1 -5
  23. package/claude-assets/agents/docker-team/infrastructure/team-coordinator-template.md +1 -5
  24. package/claude-assets/agents/marketing_hybrid/cost_tracker.md +0 -10
  25. package/claude-assets/agents/marketing_hybrid/docker_deployer.md +0 -10
  26. package/claude-assets/agents/marketing_hybrid/zai_worker_spawner.md +0 -10
  27. package/claude-assets/commands/CFN_LOOP_TASK_MODE.md +1 -1
  28. package/claude-assets/commands/cfn-loop-cli.md +491 -456
  29. package/claude-assets/commands/switch-api.md +1 -1
  30. package/claude-assets/skills/cfn-error-logging/SKILL.md +339 -0
  31. package/claude-assets/skills/cfn-error-logging/cleanup-error-logs.sh +334 -0
  32. package/claude-assets/skills/cfn-error-logging/integrate-cli.sh +232 -0
  33. package/claude-assets/skills/cfn-error-logging/integrate-docker.sh +294 -0
  34. package/claude-assets/skills/cfn-error-logging/invoke-error-logging.sh +839 -0
  35. package/claude-assets/skills/cfn-error-logging/test-error-logging.sh +475 -0
  36. package/claude-assets/skills/cfn-loop-orchestration/orchestrate.sh +2 -1
  37. package/claude-assets/skills/cfn-loop-validation/config.json +2 -2
  38. package/claude-assets/skills/cfn-process-instrumentation/instrument-process.sh +326 -322
  39. package/claude-assets/skills/cfn-redis-coordination/invoke-waiting-mode.sh +220 -220
  40. package/claude-assets/skills/cfn-task-config-init/initialize-config.sh +2 -2
  41. package/claude-assets/skills/cfn-task-mode-sanitize/task-mode-env-sanitizer.sh +224 -181
  42. package/claude-assets/skills/cfn-validation-runner-instrumentation/wrapped-executor.sh +235 -271
  43. package/dist/agents/agent-loader.js +467 -133
  44. package/dist/agents/agent-loader.js.map +1 -1
  45. package/dist/cli/config-manager.js +109 -91
  46. package/dist/cli/config-manager.js.map +1 -1
  47. package/dist/hello.js +27 -3
  48. package/dist/hello.js.map +1 -1
  49. package/dist/server.js +194 -0
  50. package/dist/server.js.map +1 -0
  51. package/dist/server.test.js +207 -0
  52. package/dist/server.test.js.map +1 -0
  53. package/package.json +2 -1
  54. package/scripts/docker-build-mcp.sh +155 -0
  55. package/scripts/docker-test-mcp.sh +260 -0
  56. package/scripts/mcp-health-check.sh +123 -0
@@ -1,224 +1,267 @@
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
74
+ # Optimize for production CLI execution
75
+ export CFN_MODE="cli"
76
+ export CFN_SANITIZER_ACTIVE=true
41
77
 
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
78
+ # NOTE: DO NOT set ulimit -u as it causes fork failures
79
+ # The MAX_AGENT_PROCESSES constant is for monitoring only, not for ulimit
80
+ # Setting ulimit -u to a low value (50) when 200+ processes exist causes all forks to fail
81
+ # Instead, we monitor process count and warn if exceeded
58
82
 
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
83
+ # Set conservative memory limit only
84
+ ulimit -v $((MAX_MEMORY_MB * 1024)) 2>/dev/null || true
63
85
 
64
- echo "🎯 Task-mode environment sanitized and locked" >&2
86
+ # Disable debug features in production
87
+ export CFN_DEBUG=false
88
+ export CFN_VERBOSE=false
65
89
  }
66
90
 
67
- # Validate environment is in Task mode
68
- validate_task_mode_environment() {
69
- local errors=0
91
+ sanitize_task_environment() {
92
+ echo " Applying Task mode sanitization..." >&2
70
93
 
71
- echo "🔍 Validating Task-mode environment..." >&2
94
+ # Task mode allows more debugging
95
+ export CFN_MODE="task"
96
+ export CFN_SANITIZER_ACTIVE=true
72
97
 
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
98
+ # More permissive limits for debugging
99
+ # NOTE: DO NOT set ulimit -u (see CLI mode comment above)
100
+ ulimit -v $((MAX_MEMORY_MB * 1024 * 2)) 2>/dev/null || true
78
101
 
79
- # Check Task-mode markers
80
- if [[ "${__CFN_TASK_MODE:-}" != "1" ]]; then
81
- echo "❌ __CFN_TASK_MODE not set" >&2
82
- ((errors++))
83
- fi
102
+ # Enable debug features for task mode
103
+ export CFN_DEBUG=${CFN_DEBUG:-true}
104
+ export CFN_VERBOSE=${CFN_VERBOSE:-true}
105
+ }
84
106
 
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
107
+ sanitize_default_environment() {
108
+ echo " Applying default sanitization..." >&2
99
109
 
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
110
+ # Basic sanitization for unknown modes
111
+ export CFN_MODE="unknown"
112
+ export CFN_SANITIZER_ACTIVE=true
110
113
 
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
117
- fi
114
+ # Conservative limits
115
+ # NOTE: DO NOT set ulimit -u (see CLI mode comment above)
118
116
  }
119
117
 
120
- # Execute command in sanitized Task-mode environment
121
- exec_task_mode_sanitized() {
122
- local command="$1"
123
- shift
118
+ ##############################################################################
119
+ # Environment Monitoring
120
+ ##############################################################################
121
+
122
+ setup_environment_monitoring() {
123
+ # Start background monitoring if available
124
+ if command -v timeout >/dev/null 2>&1; then
125
+ (
126
+ sleep $MAX_RUNTIME_SECONDS
127
+ if [[ "${CFN_SANITIZER_STATE[initialized]}" == "true" ]]; then
128
+ echo "⚠️ CFN Environment timeout reached, forcing cleanup" >&2
129
+ force_environment_cleanup
130
+ fi
131
+ ) &
132
+ echo " Started runtime monitoring (${MAX_RUNTIME_SECONDS}s)" >&2
133
+ fi
134
+ }
124
135
 
125
- echo "🚀 Executing in sanitized Task-mode environment: $command" >&2
136
+ setup_cleanup_hooks() {
137
+ # Setup cleanup trap for graceful shutdown
138
+ trap 'environment_cleanup_on_exit' EXIT
139
+ trap 'environment_cleanup_on_signal INT' INT
140
+ trap 'environment_cleanup_on_signal TERM' TERM
141
+ trap 'environment_cleanup_on_signal HUP' HUP
142
+ }
126
143
 
127
- # Sanitize environment
128
- sanitize_task_mode_environment "task"
144
+ environment_cleanup_on_exit() {
145
+ echo "🧹 CFN Environment cleanup on exit" >&2
146
+
147
+ # Calculate runtime
148
+ local end_time=$(date +%s)
149
+ local runtime=$((end_time - CFN_SANITIZER_STATE["start_time"]))
150
+ echo " Runtime: ${runtime}s" >&2
151
+
152
+ # Mode-specific cleanup
153
+ case "${CFN_SANITIZER_STATE[mode]}" in
154
+ "cli")
155
+ cleanup_cli_environment
156
+ ;;
157
+ "task")
158
+ cleanup_task_environment
159
+ ;;
160
+ esac
161
+
162
+ # Clear sanitizer state
163
+ CFN_SANITIZER_STATE["initialized"]=false
164
+ echo "✅ Environment cleanup complete" >&2
165
+ }
129
166
 
130
- # Validate environment
131
- if ! validate_task_mode_environment; then
132
- echo " Environment validation failed, aborting execution" >&2
133
- return 1
134
- fi
167
+ environment_cleanup_on_signal() {
168
+ local signal="$1"
169
+ echo "🧹 CFN Environment cleanup on signal: $signal" >&2
170
+ environment_cleanup_on_exit
171
+ exit 130
172
+ }
135
173
 
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
174
+ cleanup_cli_environment() {
175
+ echo " CLI mode cleanup..." >&2
176
+
177
+ # Clean up any lingering agent processes (using /proc to avoid fork)
178
+ # This approach reads /proc directly instead of calling external pgrep command
179
+ # to prevent kernel fork rate limiting in nested process chains
180
+ local agent_pids=""
181
+ for pid in /proc/[0-9]*/; do
182
+ [[ -e "$pid/cmdline" ]] || continue
183
+ if grep -q "claude-flow-novice.*agent" "$pid/cmdline" 2>/dev/null; then
184
+ local pid_num=$(basename "$pid")
185
+ agent_pids="$agent_pids $pid_num"
149
186
  fi
150
- return $exit_code
187
+ done
188
+
189
+ if [[ -n "$agent_pids" ]]; then
190
+ echo " Warning: Found agent processes:$agent_pids" >&2
151
191
  fi
152
192
  }
153
193
 
154
- # Show usage
155
- show_usage() {
156
- cat <<'EOF'
157
- CFN Task Mode Environment Sanitizer
194
+ cleanup_task_environment() {
195
+ echo " Task mode cleanup..." >&2
196
+ # Task mode cleanup - more permissive
197
+ }
158
198
 
159
- USAGE:
160
- source "$(dirname "${BASH_SOURCE[0]}")/task-mode-env-sanitizer.sh"
199
+ force_environment_cleanup() {
200
+ echo "🚨 Force cleanup triggered!" >&2
161
201
 
162
- # Environment Sanitization
163
- sanitize_task_mode_environment [mode] # Sanitize environment (auto|task|cli)
164
- validate_task_mode_environment # Validate current environment
202
+ # Kill any remaining processes in this process group
203
+ if [[ -n "${CFN_PROCESS_GROUP:-}" ]]; then
204
+ kill -TERM -$CFN_PROCESS_GROUP 2>/dev/null || true
205
+ sleep 2
206
+ kill -KILL -$CFN_PROCESS_GROUP 2>/dev/null || true
207
+ fi
165
208
 
166
- # Command Execution
167
- exec_task_mode_sanitized <command> [args...] # Execute command in sanitized environment
209
+ # Force exit
210
+ exit 1
211
+ }
168
212
 
169
- EXAMPLES:
170
- # Sanitize current shell
171
- sanitize_task_mode_environment task
213
+ ##############################################################################
214
+ # Utility Functions
215
+ ##############################################################################
172
216
 
173
- # Execute validator with sanitized environment
174
- exec_task_mode_sanitized node validate-code.js
217
+ check_environment_health() {
218
+ local mode="${1:-${CFN_SANITIZER_STATE[mode]}}"
175
219
 
176
- # Run with environment validation
177
- if validate_task_mode_environment; then
178
- echo "Environment is safe for Task mode"
220
+ if [[ "${CFN_SANITIZER_STATE[initialized]}" != "true" ]]; then
221
+ echo "❌ Environment sanitizer not initialized" >&2
222
+ return 1
179
223
  fi
180
224
 
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
225
+ # Check memory usage
226
+ if command -v ps >/dev/null 2>&1; then
227
+ local memory_mb=$(ps -o rss= -p $$ 2>/dev/null | awk '{print $1/1024}' || echo "0")
228
+ if (( $(echo "$memory_mb > $MAX_MEMORY_MB" | bc -l 2>/dev/null || echo "0") )); then
229
+ echo "⚠️ High memory usage: ${memory_mb}MB" >&2
230
+ fi
231
+ fi
188
232
 
189
- EOF
233
+ # Check process count
234
+ if command -v ps >/dev/null 2>&1; then
235
+ local process_count=$(ps -eo pid=,ppid= | grep -c "^[[:space:]]*$$[[:space:]]" || echo "0")
236
+ if (( process_count > MAX_AGENT_PROCESSES )); then
237
+ echo "⚠️ High process count: $process_count" >&2
238
+ fi
239
+ fi
240
+
241
+ echo "✅ Environment health check passed" >&2
242
+ return 0
190
243
  }
191
244
 
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
245
+ get_sanitizer_info() {
246
+ echo "CFN Environment Sanitizer Info:"
247
+ echo " Initialized: ${CFN_SANITIZER_STATE[initialized]}"
248
+ echo " Mode: ${CFN_SANITIZER_STATE[mode]}"
249
+ echo " Start Time: ${CFN_SANITIZER_STATE[start_time]}"
250
+ echo " PID: $$"
251
+ echo " Runtime: $(($(date +%s) - CFN_SANITIZER_STATE[start_time]))s"
252
+ }
198
253
 
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
254
+ ##############################################################################
255
+ # Auto-initialization for safety
256
+ ##############################################################################
257
+
258
+ # If script is sourced (not executed), make sanitizer available
259
+ if [[ "${BASH_SOURCE[0]}" != "${0}" ]]; then
260
+ echo "🔧 CFN Environment Sanitizer loaded" >&2
261
+ echo " Use: sanitize_task_mode_environment <mode>" >&2
262
+ fi
263
+
264
+ # If script is executed directly, run with default mode
265
+ if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
266
+ sanitize_task_mode_environment "${1:-task}"
224
267
  fi