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,323 +1,325 @@
1
- #!/usr/bin/env bash
2
-
3
- ##############################################################################
4
- # CFN Process Instrumentation
5
- # Part of ANTI-023 Memory Leak Protection System
6
- #
7
- # Provides process instrumentation, monitoring, and automatic resource limiting
8
- # for CFN Loop agents and orchestration processes.
9
- #
10
- # Usage:
11
- # source ./instrument-process.sh [--agent-id <id>] [--memory-limit <size>]
12
- # ./instrument-process.sh --monitor-pid <pid>
13
- ##############################################################################
14
-
15
- set -euo pipefail
16
-
17
- # Configuration
18
- SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
19
- PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
20
-
21
- # Default limits
22
- DEFAULT_MEMORY_LIMIT="2G"
23
- DEFAULT_CPU_LIMIT="80%"
24
- DEFAULT_TIMEOUT="600"
25
-
26
- # Process tracking
27
- AGENT_ID="${AGENT_ID:-$(hostname)-$$}"
28
- MONITOR_PID=""
29
- MEMORY_LIMIT="${CFN_MEMORY_LIMIT:-$DEFAULT_MEMORY_LIMIT}"
30
- CPU_LIMIT="${CFN_CPU_LIMIT:-$DEFAULT_CPU_LIMIT}"
31
- TIMEOUT="${CFN_TIMEOUT:-$DEFAULT_TIMEOUT}"
32
-
33
- # Telemetry storage
34
- TELEMETRY_DIR="${CFN_TELEMETRY_DIR:-/tmp/cfn-telemetry}"
35
- METRICS_FILE="$TELEMETRY_DIR/metrics_${AGENT_ID}.json"
36
-
37
- # Color coding
38
- readonly RED='\033[0;31m'
39
- readonly GREEN='\033[0;32m'
40
- readonly YELLOW='\033[1;33m'
41
- readonly BLUE='\033[0;34m'
42
- readonly NC='\033[0m'
43
-
44
- # Logging functions
45
- log_info() {
46
- echo -e "${BLUE}[INSTRUMENT]${NC} $1" >&2
47
- }
48
-
49
- log_success() {
50
- echo -e "${GREEN}[INSTRUMENT]${NC} $1" >&2
51
- }
52
-
53
- log_warning() {
54
- echo -e "${YELLOW}[INSTRUMENT]${NC} $1" >&2
55
- }
56
-
57
- log_error() {
58
- echo -e "${RED}[INSTRUMENT]${NC} $1" >&2
59
- }
60
-
61
- # Initialize telemetry directory
62
- init_telemetry() {
63
- mkdir -p "$TELEMETRY_DIR"
64
-
65
- # Create metrics file with initial structure
66
- cat > "$METRICS_FILE" << EOF
67
- {
68
- "agent_id": "$AGENT_ID",
69
- "start_time": "$(date -Iseconds)",
70
- "process_id": "$$",
71
- "memory_limit": "$MEMORY_LIMIT",
72
- "cpu_limit": "$CPU_LIMIT",
73
- "timeout": "$TIMEOUT",
74
- "samples": []
75
- }
76
- EOF
77
- }
78
-
79
- # Collect process metrics
80
- collect_metrics() {
81
- local pid="${1:-$$}"
82
- local timestamp="$(date -Iseconds)"
83
-
84
- # Get process statistics
85
- local mem_usage=""
86
- local cpu_usage=""
87
- local open_files=""
88
- local threads=""
89
-
90
- if command -v ps >/dev/null 2>&1; then
91
- mem_usage=$(ps -p "$pid" -o rss= 2>/dev/null | tr -d ' ' || echo "0")
92
- cpu_usage=$(ps -p "$pid" -o %cpu= 2>/dev/null | tr -d ' ' || echo "0")
93
- fi
94
-
95
- if command -v lsof >/dev/null 2>&1; then
96
- open_files=$(lsof -p "$pid" 2>/dev/null | wc -l || echo "0")
97
- fi
98
-
99
- if [[ -f "/proc/$pid/status" ]]; then
100
- threads=$(grep "^Threads:" "/proc/$pid/status" | awk '{print $2}' || echo "0")
101
- fi
102
-
103
- # Create metrics entry
104
- local metrics_entry=$(cat << EOF
105
- {
106
- "timestamp": "$timestamp",
107
- "memory_kb": "$mem_usage",
108
- "cpu_percent": "$cpu_usage",
109
- "open_files": "$open_files",
110
- "threads": "$threads"
111
- }
112
- EOF
113
- )
114
-
115
- # Update metrics file
116
- if [[ -f "$METRICS_FILE" ]]; then
117
- # Use jq to safely append to samples array
118
- if command -v jq >/dev/null 2>&1; then
119
- jq --argjson entry "$metrics_entry" '.samples += [$entry]' "$METRICS_FILE" > "$METRICS_FILE.tmp" && \
120
- mv "$METRICS_FILE.tmp" "$METRICS_FILE"
121
- else
122
- # Fallback without jq
123
- echo "Warning: jq not available, using simple append" >&2
124
- echo "$metrics_entry" >> "$METRICS_FILE.raw"
125
- fi
126
- fi
127
- }
128
-
129
- # Check resource limits
130
- check_limits() {
131
- local pid="${1:-$$}"
132
-
133
- # Memory limit check
134
- if command -v ps >/dev/null 2>&1; then
135
- local mem_kb=$(ps -p "$pid" -o rss= 2>/dev/null | tr -d ' ' || echo "0")
136
- local mem_mb=$((mem_kb / 1024))
137
-
138
- case "$MEMORY_LIMIT" in
139
- *G|*g)
140
- local limit_mb=$((${MEMORY_LIMIT%[Gg]*} * 1024))
141
- ;;
142
- *M|*m)
143
- local limit_mb=$((${MEMORY_LIMIT%[Mm]*}))
144
- ;;
145
- *)
146
- local limit_mb=2048 # Default 2GB
147
- ;;
148
- esac
149
-
150
- if [[ $mem_mb -gt $limit_mb ]]; then
151
- log_warning "Memory limit exceeded: ${mem_mb}MB > ${limit_mb}MB"
152
- return 1
153
- fi
154
- fi
155
-
156
- # CPU limit check
157
- if command -v ps >/dev/null 2>&1; then
158
- local cpu_percent=$(ps -p "$pid" -o %cpu= 2>/dev/null | tr -d ' ' || echo "0")
159
- local cpu_limit_num=$((${CPU_LIMIT%\%}))
160
-
161
- if (( $(echo "$cpu_percent > $cpu_limit_num" | bc -l) )); then
162
- log_warning "CPU limit exceeded: ${cpu_percent}% > ${CPU_LIMIT}"
163
- return 1
164
- fi
165
- fi
166
-
167
- return 0
168
- }
169
-
170
- # Start background monitoring
171
- start_monitoring() {
172
- local pid="${1:-$$}"
173
- local interval="${2:-30}" # Check every 30 seconds
174
-
175
- log_info "Starting process monitoring for PID $pid (interval: ${interval}s)"
176
-
177
- # Start monitoring in background
178
- (
179
- while true; do
180
- if ! kill -0 "$pid" 2>/dev/null; then
181
- log_info "Process $pid no longer exists, stopping monitoring"
182
- break
183
- fi
184
-
185
- collect_metrics "$pid"
186
-
187
- if ! check_limits "$pid"; then
188
- log_error "Resource limits exceeded, terminating process $pid"
189
- kill -TERM "$pid" 2>/dev/null || true
190
- break
191
- fi
192
-
193
- sleep "$interval"
194
- done
195
- ) &
196
-
197
- MONITOR_PID=$!
198
- echo "$MONITOR_PID"
199
- }
200
-
201
- # Stop monitoring
202
- stop_monitoring() {
203
- if [[ -n "$MONITOR_PID" ]] && kill -0 "$MONITOR_PID" 2>/dev/null; then
204
- kill "$MONITOR_PID" 2>/dev/null || true
205
- log_info "Stopped monitoring (PID: $MONITOR_PID)"
206
- fi
207
- }
208
-
209
- # Generate final report
210
- generate_report() {
211
- local exit_code="${1:-0}"
212
-
213
- if [[ -f "$METRICS_FILE" ]]; then
214
- # Update with final information
215
- if command -v jq >/dev/null 2>&1; then
216
- jq --arg end_time "$(date -Iseconds)" \
217
- --arg exit_code "$exit_code" \
218
- '.end_time = $end_time | .exit_code = $exit_code' \
219
- "$METRICS_FILE" > "$METRICS_FILE.tmp" && \
220
- mv "$METRICS_FILE.tmp" "$METRICS_FILE"
221
- fi
222
-
223
- log_success "Process report generated: $METRICS_FILE"
224
-
225
- # Print summary
226
- if command -v jq >/dev/null 2>&1; then
227
- local samples=$(jq '.samples | length' "$METRICS_FILE")
228
- echo "📊 Process Metrics Summary:" >&2
229
- echo " Agent ID: $AGENT_ID" >&2
230
- echo " Samples: $samples" >&2
231
- echo " Exit Code: $exit_code" >&2
232
- fi
233
- fi
234
- }
235
-
236
- # Monitor existing process
237
- monitor_pid() {
238
- local pid="$1"
239
-
240
- log_info "Monitoring existing process: PID $pid"
241
-
242
- if ! kill -0 "$pid" 2>/dev/null; then
243
- log_error "Process $pid does not exist"
244
- return 1
245
- fi
246
-
247
- # Start monitoring
248
- local monitor_pid=$(start_monitoring "$pid")
249
-
250
- # Wait for process to complete
251
- while kill -0 "$pid" 2>/dev/null; do
252
- sleep 5
253
- done
254
-
255
- # Stop monitoring
256
- stop_monitoring
257
-
258
- log_success "Process monitoring completed for PID $pid"
259
- }
260
-
261
- # Main execution
262
- main() {
263
- local action="${1:-"instrument"}"
264
-
265
- case "$action" in
266
- "instrument")
267
- init_telemetry
268
- local monitor_pid=$(start_monitoring)
269
-
270
- # Set up cleanup traps
271
- trap 'stop_monitoring; generate_report $?' EXIT
272
- trap 'stop_monitoring; generate_report 1' INT TERM
273
-
274
- log_success "Process instrumentation started for $AGENT_ID"
275
- ;;
276
- "monitor-pid")
277
- if [[ -z "${2:-}" ]]; then
278
- log_error "PID required for monitor-pid action"
279
- exit 1
280
- fi
281
- monitor_pid "$2"
282
- ;;
283
- "--help"|"-h")
284
- cat << EOF
285
- CFN Process Instrumentation Script
286
-
287
- Usage:
288
- $0 # Instrument current process
289
- $0 monitor-pid <pid> # Monitor existing process
290
- $0 --help # Show this help
291
-
292
- Environment Variables:
293
- AGENT_ID # Agent identifier (default: hostname-PID)
294
- CFN_MEMORY_LIMIT # Memory limit (default: 2G)
295
- CFN_CPU_LIMIT # CPU limit (default: 80%)
296
- CFN_TIMEOUT # Timeout in seconds (default: 600)
297
- CFN_TELEMETRY_DIR # Telemetry storage directory
298
-
299
- This script provides process monitoring and resource limit enforcement
300
- for CFN Loop agents and orchestration processes.
301
- EOF
302
- ;;
303
- *)
304
- log_error "Unknown action: $action"
305
- exit 1
306
- ;;
307
- esac
308
- }
309
-
310
- # Execute main function if run directly
311
- if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
312
- main "$@"
313
- else
314
- # When sourced, automatically instrument current process
315
- init_telemetry
316
- local monitor_pid=$(start_monitoring)
317
-
318
- # Set up cleanup traps
319
- trap 'stop_monitoring; generate_report $?' EXIT
320
- trap 'stop_monitoring; generate_report 1' INT TERM
321
-
322
- log_info "Process instrumentation enabled for $AGENT_ID"
1
+ #!/usr/bin/env bash
2
+
3
+ ##############################################################################
4
+ # CFN Process Instrumentation
5
+ # Part of ANTI-023 Memory Leak Protection System
6
+ #
7
+ # Provides process instrumentation, monitoring, and automatic resource limiting
8
+ # for CFN Loop agents and orchestration processes.
9
+ #
10
+ # Usage:
11
+ # source ./instrument-process.sh [--agent-id <id>] [--memory-limit <size>]
12
+ # ./instrument-process.sh --monitor-pid <pid>
13
+ ##############################################################################
14
+
15
+ set -euo pipefail
16
+
17
+ # Configuration
18
+ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
19
+ PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
20
+
21
+ # Default limits
22
+ DEFAULT_MEMORY_LIMIT="2G"
23
+ DEFAULT_CPU_LIMIT="80%"
24
+ DEFAULT_TIMEOUT="600"
25
+
26
+ # Process tracking
27
+ AGENT_ID="${AGENT_ID:-$(hostname)-$$}"
28
+ MONITOR_PID=""
29
+ MEMORY_LIMIT="${CFN_MEMORY_LIMIT:-$DEFAULT_MEMORY_LIMIT}"
30
+ CPU_LIMIT="${CFN_CPU_LIMIT:-$DEFAULT_CPU_LIMIT}"
31
+ TIMEOUT="${CFN_TIMEOUT:-$DEFAULT_TIMEOUT}"
32
+
33
+ # Telemetry storage
34
+ TELEMETRY_DIR="${CFN_TELEMETRY_DIR:-/tmp/cfn-telemetry}"
35
+ METRICS_FILE="$TELEMETRY_DIR/metrics_${AGENT_ID}.json"
36
+
37
+ # Color coding
38
+ readonly RED='\033[0;31m'
39
+ readonly GREEN='\033[0;32m'
40
+ readonly YELLOW='\033[1;33m'
41
+ readonly BLUE='\033[0;34m'
42
+ readonly NC='\033[0m'
43
+
44
+ # Logging functions
45
+ log_info() {
46
+ echo -e "${BLUE}[INSTRUMENT]${NC} $1" >&2
47
+ }
48
+
49
+ log_success() {
50
+ echo -e "${GREEN}[INSTRUMENT]${NC} $1" >&2
51
+ }
52
+
53
+ log_warning() {
54
+ echo -e "${YELLOW}[INSTRUMENT]${NC} $1" >&2
55
+ }
56
+
57
+ log_error() {
58
+ echo -e "${RED}[INSTRUMENT]${NC} $1" >&2
59
+ }
60
+
61
+ # Initialize telemetry directory
62
+ init_telemetry() {
63
+ mkdir -p "$TELEMETRY_DIR"
64
+
65
+ # Create metrics file with initial structure
66
+ cat > "$METRICS_FILE" << EOF
67
+ {
68
+ "agent_id": "$AGENT_ID",
69
+ "start_time": "$(date -Iseconds)",
70
+ "process_id": "$$",
71
+ "memory_limit": "$MEMORY_LIMIT",
72
+ "cpu_limit": "$CPU_LIMIT",
73
+ "timeout": "$TIMEOUT",
74
+ "samples": []
75
+ }
76
+ EOF
77
+ }
78
+
79
+ # Collect process metrics
80
+ collect_metrics() {
81
+ local pid="${1:-$$}"
82
+ local timestamp="$(date -Iseconds)"
83
+
84
+ # Get process statistics
85
+ local mem_usage=""
86
+ local cpu_usage=""
87
+ local open_files=""
88
+ local threads=""
89
+
90
+ if command -v ps >/dev/null 2>&1; then
91
+ mem_usage=$(ps -p "$pid" -o rss= 2>/dev/null | tr -d ' ' || echo "0")
92
+ cpu_usage=$(ps -p "$pid" -o %cpu= 2>/dev/null | tr -d ' ' || echo "0")
93
+ fi
94
+
95
+ if command -v lsof >/dev/null 2>&1; then
96
+ open_files=$(lsof -p "$pid" 2>/dev/null | wc -l || echo "0")
97
+ fi
98
+
99
+ if [[ -f "/proc/$pid/status" ]]; then
100
+ threads=$(grep "^Threads:" "/proc/$pid/status" | awk '{print $2}' || echo "0")
101
+ fi
102
+
103
+ # Create metrics entry
104
+ local metrics_entry=$(cat << EOF
105
+ {
106
+ "timestamp": "$timestamp",
107
+ "memory_kb": "$mem_usage",
108
+ "cpu_percent": "$cpu_usage",
109
+ "open_files": "$open_files",
110
+ "threads": "$threads"
111
+ }
112
+ EOF
113
+ )
114
+
115
+ # Update metrics file
116
+ if [[ -f "$METRICS_FILE" ]]; then
117
+ # Use jq to safely append to samples array
118
+ if command -v jq >/dev/null 2>&1; then
119
+ jq --argjson entry "$metrics_entry" '.samples += [$entry]' "$METRICS_FILE" > "$METRICS_FILE.tmp" && \
120
+ mv "$METRICS_FILE.tmp" "$METRICS_FILE"
121
+ else
122
+ # Fallback without jq
123
+ echo "Warning: jq not available, using simple append" >&2
124
+ echo "$metrics_entry" >> "$METRICS_FILE.raw"
125
+ fi
126
+ fi
127
+ }
128
+
129
+ # Check resource limits
130
+ check_limits() {
131
+ local pid="${1:-$$}"
132
+
133
+ # Memory limit check
134
+ if command -v ps >/dev/null 2>&1; then
135
+ local mem_kb=$(ps -p "$pid" -o rss= 2>/dev/null | tr -d ' ' || echo "0")
136
+ local mem_mb=$((mem_kb / 1024))
137
+
138
+ case "$MEMORY_LIMIT" in
139
+ *G|*g)
140
+ local limit_mb=$((${MEMORY_LIMIT%[Gg]*} * 1024))
141
+ ;;
142
+ *M|*m)
143
+ local limit_mb=$((${MEMORY_LIMIT%[Mm]*}))
144
+ ;;
145
+ *)
146
+ local limit_mb=2048 # Default 2GB
147
+ ;;
148
+ esac
149
+
150
+ if [[ $mem_mb -gt $limit_mb ]]; then
151
+ log_warning "Memory limit exceeded: ${mem_mb}MB > ${limit_mb}MB"
152
+ return 1
153
+ fi
154
+ fi
155
+
156
+ # CPU limit check
157
+ if command -v ps >/dev/null 2>&1; then
158
+ local cpu_percent=$(ps -p "$pid" -o %cpu= 2>/dev/null | tr -d ' ' || echo "0")
159
+ local cpu_limit_num=$((${CPU_LIMIT%\%}))
160
+
161
+ if (( $(echo "$cpu_percent > $cpu_limit_num" | bc -l) )); then
162
+ log_warning "CPU limit exceeded: ${cpu_percent}% > ${CPU_LIMIT}"
163
+ return 1
164
+ fi
165
+ fi
166
+
167
+ return 0
168
+ }
169
+
170
+ # Start background monitoring
171
+ start_monitoring() {
172
+ local pid="${1:-$$}"
173
+ local interval="${2:-30}" # Check every 30 seconds
174
+
175
+ log_info "Starting process monitoring for PID $pid (interval: ${interval}s)"
176
+
177
+ # Start monitoring in background
178
+ (
179
+ while true; do
180
+ if ! kill -0 "$pid" 2>/dev/null; then
181
+ log_info "Process $pid no longer exists, stopping monitoring"
182
+ break
183
+ fi
184
+
185
+ collect_metrics "$pid"
186
+
187
+ if ! check_limits "$pid"; then
188
+ log_error "Resource limits exceeded, terminating process $pid"
189
+ kill -TERM "$pid" 2>/dev/null || true
190
+ break
191
+ fi
192
+
193
+ sleep "$interval"
194
+ done
195
+ ) &
196
+
197
+ MONITOR_PID=$!
198
+ echo "$MONITOR_PID"
199
+ }
200
+
201
+ # Stop monitoring
202
+ stop_monitoring() {
203
+ if [[ -n "$MONITOR_PID" ]] && kill -0 "$MONITOR_PID" 2>/dev/null; then
204
+ kill "$MONITOR_PID" 2>/dev/null || true
205
+ log_info "Stopped monitoring (PID: $MONITOR_PID)"
206
+ fi
207
+ }
208
+
209
+ # Generate final report
210
+ generate_report() {
211
+ local exit_code="${1:-0}"
212
+
213
+ if [[ -f "$METRICS_FILE" ]]; then
214
+ # Update with final information
215
+ if command -v jq >/dev/null 2>&1; then
216
+ jq --arg end_time "$(date -Iseconds)" \
217
+ --arg exit_code "$exit_code" \
218
+ '.end_time = $end_time | .exit_code = $exit_code' \
219
+ "$METRICS_FILE" > "$METRICS_FILE.tmp" && \
220
+ mv "$METRICS_FILE.tmp" "$METRICS_FILE"
221
+ fi
222
+
223
+ log_success "Process report generated: $METRICS_FILE"
224
+
225
+ # Print summary
226
+ if command -v jq >/dev/null 2>&1; then
227
+ local samples=$(jq '.samples | length' "$METRICS_FILE")
228
+ echo "📊 Process Metrics Summary:" >&2
229
+ echo " Agent ID: $AGENT_ID" >&2
230
+ echo " Samples: $samples" >&2
231
+ echo " Exit Code: $exit_code" >&2
232
+ fi
233
+ fi
234
+ }
235
+
236
+ # Monitor existing process
237
+ monitor_pid() {
238
+ local pid="$1"
239
+
240
+ log_info "Monitoring existing process: PID $pid"
241
+
242
+ if ! kill -0 "$pid" 2>/dev/null; then
243
+ log_error "Process $pid does not exist"
244
+ return 1
245
+ fi
246
+
247
+ # Start monitoring
248
+ local monitor_pid=$(start_monitoring "$pid")
249
+
250
+ # Wait for process to complete
251
+ while kill -0 "$pid" 2>/dev/null; do
252
+ sleep 5
253
+ done
254
+
255
+ # Stop monitoring
256
+ stop_monitoring
257
+
258
+ log_success "Process monitoring completed for PID $pid"
259
+ }
260
+
261
+ # Main execution
262
+ main() {
263
+ local action="${1:-"instrument"}"
264
+
265
+ case "$action" in
266
+ "instrument")
267
+ init_telemetry
268
+ local monitor_pid=$(start_monitoring)
269
+
270
+ # Set up cleanup traps
271
+ trap 'stop_monitoring; generate_report $?' EXIT
272
+ trap 'stop_monitoring; generate_report 1' INT TERM
273
+
274
+ log_success "Process instrumentation started for $AGENT_ID"
275
+ ;;
276
+ "monitor-pid")
277
+ if [[ -z "${2:-}" ]]; then
278
+ log_error "PID required for monitor-pid action"
279
+ exit 1
280
+ fi
281
+ monitor_pid "$2"
282
+ ;;
283
+ "--help"|"-h")
284
+ cat << EOF
285
+ CFN Process Instrumentation Script
286
+
287
+ Usage:
288
+ $0 # Instrument current process
289
+ $0 monitor-pid <pid> # Monitor existing process
290
+ $0 --help # Show this help
291
+
292
+ Environment Variables:
293
+ AGENT_ID # Agent identifier (default: hostname-PID)
294
+ CFN_MEMORY_LIMIT # Memory limit (default: 2G)
295
+ CFN_CPU_LIMIT # CPU limit (default: 80%)
296
+ CFN_TIMEOUT # Timeout in seconds (default: 600)
297
+ CFN_TELEMETRY_DIR # Telemetry storage directory
298
+
299
+ This script provides process monitoring and resource limit enforcement
300
+ for CFN Loop agents and orchestration processes.
301
+ EOF
302
+ ;;
303
+ *)
304
+ log_error "Unknown action: $action"
305
+ exit 1
306
+ ;;
307
+ esac
308
+ }
309
+
310
+ # Execute main function if run directly
311
+ if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
312
+ main "$@"
313
+ else
314
+ # When sourced, automatically instrument current process
315
+ init_telemetry
316
+ # BUG #12 FIX: Removed local to prevent bash from blocking on background process
317
+ # The function sets global MONITOR_PID which is used by cleanup traps
318
+ start_monitoring >/dev/null
319
+
320
+ # Set up cleanup traps
321
+ trap 'stop_monitoring; generate_report $?' EXIT
322
+ trap 'stop_monitoring; generate_report 1' INT TERM
323
+
324
+ log_info "Process instrumentation enabled for $AGENT_ID"
323
325
  fi
@@ -186,8 +186,8 @@ select_agents() {
186
186
  fi
187
187
 
188
188
  # Loop 2 validators (adaptive scaling)
189
- # Standard: 3-5 files → add system-architect, security
190
- loop2+=("system-architect" "security-specialist")
189
+ # Standard: 3-5 files → add architect, security
190
+ loop2+=("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