claude-flow-novice 2.14.28 → 2.14.30

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 (164) hide show
  1. package/.claude/cfn-agents-ignore/cfn-seo-team/AGENT_CREATION_REPORT.md +4 -14
  2. package/.claude/cfn-agents-ignore/cfn-seo-team/AGENT_CREATION_REPORT.md.backup +481 -0
  3. package/.claude/cfn-agents-ignore/cfn-seo-team/DELEGATION_MATRIX.md +3 -4
  4. package/.claude/cfn-agents-ignore/cfn-seo-team/DELEGATION_MATRIX.md.backup +371 -0
  5. package/.claude/cfn-agents-ignore/cfn-seo-team/INTEGRATION_REQUIREMENTS.md +20 -26
  6. package/.claude/cfn-agents-ignore/cfn-seo-team/INTEGRATION_REQUIREMENTS.md.backup +637 -0
  7. package/.claude/cfn-agents-ignore/cfn-seo-team/cfn-seo-coordinator.md +295 -50
  8. package/.claude/cfn-agents-ignore/cfn-seo-team/cfn-seo-coordinator.md.backup +398 -0
  9. package/.claude/cfn-agents-ignore/cfn-seo-team/competitive-seo-analyst.md +27 -25
  10. package/.claude/cfn-agents-ignore/cfn-seo-team/competitive-seo-analyst.md.backup +401 -0
  11. package/.claude/cfn-agents-ignore/cfn-seo-team/content-atomization-specialist.md +5 -106
  12. package/.claude/cfn-agents-ignore/cfn-seo-team/content-atomization-specialist.md.backup +552 -0
  13. package/.claude/cfn-agents-ignore/cfn-seo-team/content-seo-strategist.md +5 -25
  14. package/.claude/cfn-agents-ignore/cfn-seo-team/content-seo-strategist.md.backup +223 -0
  15. package/.claude/cfn-agents-ignore/cfn-seo-team/eeat-content-auditor.md +5 -27
  16. package/.claude/cfn-agents-ignore/cfn-seo-team/eeat-content-auditor.md.backup +367 -0
  17. package/.claude/cfn-agents-ignore/cfn-seo-team/geo-optimization-expert.md +5 -27
  18. package/.claude/cfn-agents-ignore/cfn-seo-team/geo-optimization-expert.md.backup +247 -0
  19. package/.claude/cfn-agents-ignore/cfn-seo-team/link-building-specialist.md +5 -27
  20. package/.claude/cfn-agents-ignore/cfn-seo-team/link-building-specialist.md.backup +269 -0
  21. package/.claude/cfn-agents-ignore/cfn-seo-team/local-seo-optimizer.md +5 -25
  22. package/.claude/cfn-agents-ignore/cfn-seo-team/local-seo-optimizer.md.backup +311 -0
  23. package/.claude/cfn-agents-ignore/cfn-seo-team/programmatic-seo-engineer.md +6 -26
  24. package/.claude/cfn-agents-ignore/cfn-seo-team/programmatic-seo-engineer.md.backup +222 -0
  25. package/.claude/cfn-agents-ignore/cfn-seo-team/schema-markup-engineer.md +5 -25
  26. package/.claude/cfn-agents-ignore/cfn-seo-team/schema-markup-engineer.md.backup +408 -0
  27. package/.claude/cfn-agents-ignore/cfn-seo-team/seo-analytics-specialist.md +6 -26
  28. package/.claude/cfn-agents-ignore/cfn-seo-team/seo-analytics-specialist.md.backup +354 -0
  29. package/.claude/cfn-agents-ignore/cfn-seo-team/seo-validators/accessibility-validator.md +4 -4
  30. package/.claude/cfn-agents-ignore/cfn-seo-team/seo-validators/accessibility-validator.md.backup +561 -0
  31. package/.claude/cfn-agents-ignore/cfn-seo-team/seo-validators/audience-validator.md +2 -2
  32. package/.claude/cfn-agents-ignore/cfn-seo-team/seo-validators/audience-validator.md.backup +480 -0
  33. package/.claude/cfn-agents-ignore/cfn-seo-team/seo-validators/branding-validator.md +1 -1
  34. package/.claude/cfn-agents-ignore/cfn-seo-team/seo-validators/branding-validator.md.backup +448 -0
  35. package/.claude/cfn-agents-ignore/cfn-seo-team/seo-validators/humanizer-validator.md +2 -2
  36. package/.claude/cfn-agents-ignore/cfn-seo-team/seo-validators/humanizer-validator.md.backup +329 -0
  37. package/.claude/cfn-agents-ignore/cfn-seo-team/technical-seo-specialist.md +361 -199
  38. package/.claude/cfn-agents-ignore/cfn-seo-team/technical-seo-specialist.md.backup +208 -0
  39. package/.claude/commands/CFN_LOOP_TASK_MODE.md +100 -11
  40. package/.claude/commands/cfn-mode.md +2 -2
  41. package/.claude/skills/cfn-agent-spawning/spawn-agent.sh +12 -0
  42. package/.claude/skills/cfn-agent-spawning/spawn-agent.sh.backup +273 -0
  43. package/.claude/skills/cfn-hybrid-routing/README.md +1 -1
  44. package/.claude/skills/cfn-loop-orchestration/orchestrate.sh +95 -15
  45. package/.claude/skills/cfn-loop-orchestration/orchestrate.sh.backup +76 -11
  46. package/.claude/skills/cfn-loop-orchestration/orchestrate.sh.backup2 +959 -0
  47. package/.claude/skills/cfn-loop-orchestration/orchestrate.sh.clean +949 -0
  48. package/.claude/skills/cfn-product-owner-decision/execute-decision.sh +82 -10
  49. package/claude-assets/agents/cfn-dev-team/CLAUDE.md +24 -14
  50. package/claude-assets/agents/cfn-dev-team/architecture/api-designer-persona.md +0 -7
  51. package/claude-assets/agents/cfn-dev-team/architecture/base-template-generator.md +12 -38
  52. package/claude-assets/agents/cfn-dev-team/architecture/goal-planner.md +0 -10
  53. package/claude-assets/agents/cfn-dev-team/architecture/planner.md +7 -57
  54. package/claude-assets/agents/cfn-dev-team/architecture/system-architect.md +8 -45
  55. package/claude-assets/agents/cfn-dev-team/coordinators/cfn-frontend-coordinator.md +365 -25
  56. package/claude-assets/agents/cfn-dev-team/coordinators/cfn-v3-coordinator.md +504 -448
  57. package/claude-assets/agents/cfn-dev-team/coordinators/consensus-builder.md +428 -167
  58. package/claude-assets/agents/cfn-dev-team/coordinators/multi-sprint-coordinator.md +472 -20
  59. package/claude-assets/agents/cfn-dev-team/dev-ops/devops-engineer.md +5 -5
  60. package/claude-assets/agents/cfn-dev-team/dev-ops/docker-specialist.md +5 -7
  61. package/claude-assets/agents/cfn-dev-team/dev-ops/kubernetes-specialist.md +0 -6
  62. package/claude-assets/agents/cfn-dev-team/dev-ops/monitoring-specialist.md +3 -3
  63. package/claude-assets/agents/cfn-dev-team/developers/api-gateway-specialist.md +13 -14
  64. package/claude-assets/agents/cfn-dev-team/developers/data/data-engineer.md +0 -6
  65. package/claude-assets/agents/cfn-dev-team/developers/database/database-architect.md +2 -2
  66. package/claude-assets/agents/cfn-dev-team/developers/frontend/mobile-dev.md +10 -56
  67. package/claude-assets/agents/cfn-dev-team/developers/frontend/typescript-specialist.md +7 -26
  68. package/claude-assets/agents/cfn-dev-team/developers/rust-developer.md +8 -48
  69. package/claude-assets/agents/cfn-dev-team/documentation/api-documentation.md +1 -1
  70. package/claude-assets/agents/cfn-dev-team/documentation/pseudocode.md +3 -11
  71. package/claude-assets/agents/cfn-dev-team/documentation/specification-agent.md +6 -16
  72. package/claude-assets/agents/cfn-dev-team/product-owners/cto-agent.md +7 -19
  73. package/claude-assets/agents/cfn-dev-team/product-owners/power-user-persona.md +9 -49
  74. package/claude-assets/agents/cfn-dev-team/product-owners/product-owner.md +291 -86
  75. package/claude-assets/agents/cfn-dev-team/reviewers/quality/code-quality-validator.md +9 -81
  76. package/claude-assets/agents/cfn-dev-team/reviewers/quality/cyclomatic-complexity-reducer.md +4 -64
  77. package/claude-assets/agents/cfn-dev-team/reviewers/quality/perf-analyzer.md +7 -87
  78. package/claude-assets/agents/cfn-dev-team/reviewers/quality/performance-benchmarker.md +8 -12
  79. package/claude-assets/agents/cfn-dev-team/reviewers/quality/security-specialist.md +11 -129
  80. package/claude-assets/agents/cfn-dev-team/reviewers/reviewer.md +231 -280
  81. package/claude-assets/agents/cfn-dev-team/testers/api-testing-specialist.md +0 -6
  82. package/claude-assets/agents/cfn-dev-team/testers/chaos-engineering-specialist.md +0 -6
  83. package/claude-assets/agents/cfn-dev-team/testers/e2e/playwright-tester.md +7 -32
  84. package/claude-assets/agents/cfn-dev-team/testers/interaction-tester.md +9 -47
  85. package/claude-assets/agents/cfn-dev-team/testers/load-testing-specialist.md +0 -6
  86. package/claude-assets/agents/cfn-dev-team/testers/playwright-tester.md +12 -28
  87. package/claude-assets/agents/cfn-dev-team/testers/tester.md +167 -236
  88. package/claude-assets/agents/cfn-dev-team/testers/unit/tdd-london-unit-swarm.md +7 -27
  89. package/claude-assets/agents/cfn-dev-team/testers/validation/validation-production-validator.md +7 -19
  90. package/claude-assets/agents/cfn-dev-team/testing/test-validation-agent.md +10 -47
  91. package/claude-assets/agents/cfn-dev-team/utility/agent-builder.md +40 -116
  92. package/claude-assets/agents/cfn-dev-team/utility/analyst.md +7 -47
  93. package/claude-assets/agents/cfn-dev-team/utility/code-booster.md +7 -40
  94. package/claude-assets/agents/cfn-dev-team/utility/context-curator.md +7 -47
  95. package/claude-assets/agents/cfn-dev-team/{coordinators → utility}/epic-creator.md +29 -0
  96. package/claude-assets/cfn-agents-ignore/cfn-seo-team/AGENT_CREATION_REPORT.md +4 -14
  97. package/claude-assets/cfn-agents-ignore/cfn-seo-team/AGENT_CREATION_REPORT.md.backup +481 -0
  98. package/claude-assets/cfn-agents-ignore/cfn-seo-team/DELEGATION_MATRIX.md +3 -4
  99. package/claude-assets/cfn-agents-ignore/cfn-seo-team/DELEGATION_MATRIX.md.backup +371 -0
  100. package/claude-assets/cfn-agents-ignore/cfn-seo-team/INTEGRATION_REQUIREMENTS.md +20 -26
  101. package/claude-assets/cfn-agents-ignore/cfn-seo-team/INTEGRATION_REQUIREMENTS.md.backup +637 -0
  102. package/claude-assets/cfn-agents-ignore/cfn-seo-team/cfn-seo-coordinator.md +295 -50
  103. package/claude-assets/cfn-agents-ignore/cfn-seo-team/cfn-seo-coordinator.md.backup +398 -0
  104. package/claude-assets/cfn-agents-ignore/cfn-seo-team/competitive-seo-analyst.md +27 -25
  105. package/claude-assets/cfn-agents-ignore/cfn-seo-team/competitive-seo-analyst.md.backup +401 -0
  106. package/claude-assets/cfn-agents-ignore/cfn-seo-team/content-atomization-specialist.md +5 -106
  107. package/claude-assets/cfn-agents-ignore/cfn-seo-team/content-atomization-specialist.md.backup +552 -0
  108. package/claude-assets/cfn-agents-ignore/cfn-seo-team/content-seo-strategist.md +5 -25
  109. package/claude-assets/cfn-agents-ignore/cfn-seo-team/content-seo-strategist.md.backup +223 -0
  110. package/claude-assets/cfn-agents-ignore/cfn-seo-team/eeat-content-auditor.md +5 -27
  111. package/claude-assets/cfn-agents-ignore/cfn-seo-team/eeat-content-auditor.md.backup +367 -0
  112. package/claude-assets/cfn-agents-ignore/cfn-seo-team/geo-optimization-expert.md +5 -27
  113. package/claude-assets/cfn-agents-ignore/cfn-seo-team/geo-optimization-expert.md.backup +247 -0
  114. package/claude-assets/cfn-agents-ignore/cfn-seo-team/link-building-specialist.md +5 -27
  115. package/claude-assets/cfn-agents-ignore/cfn-seo-team/link-building-specialist.md.backup +269 -0
  116. package/claude-assets/cfn-agents-ignore/cfn-seo-team/local-seo-optimizer.md +5 -25
  117. package/claude-assets/cfn-agents-ignore/cfn-seo-team/local-seo-optimizer.md.backup +311 -0
  118. package/claude-assets/cfn-agents-ignore/cfn-seo-team/programmatic-seo-engineer.md +6 -26
  119. package/claude-assets/cfn-agents-ignore/cfn-seo-team/programmatic-seo-engineer.md.backup +222 -0
  120. package/claude-assets/cfn-agents-ignore/cfn-seo-team/schema-markup-engineer.md +5 -25
  121. package/claude-assets/cfn-agents-ignore/cfn-seo-team/schema-markup-engineer.md.backup +408 -0
  122. package/claude-assets/cfn-agents-ignore/cfn-seo-team/seo-analytics-specialist.md +6 -26
  123. package/claude-assets/cfn-agents-ignore/cfn-seo-team/seo-analytics-specialist.md.backup +354 -0
  124. package/claude-assets/cfn-agents-ignore/cfn-seo-team/seo-validators/accessibility-validator.md +4 -4
  125. package/claude-assets/cfn-agents-ignore/cfn-seo-team/seo-validators/accessibility-validator.md.backup +561 -0
  126. package/claude-assets/cfn-agents-ignore/cfn-seo-team/seo-validators/audience-validator.md +2 -2
  127. package/claude-assets/cfn-agents-ignore/cfn-seo-team/seo-validators/audience-validator.md.backup +480 -0
  128. package/claude-assets/cfn-agents-ignore/cfn-seo-team/seo-validators/branding-validator.md +1 -1
  129. package/claude-assets/cfn-agents-ignore/cfn-seo-team/seo-validators/branding-validator.md.backup +448 -0
  130. package/claude-assets/cfn-agents-ignore/cfn-seo-team/seo-validators/humanizer-validator.md +2 -2
  131. package/claude-assets/cfn-agents-ignore/cfn-seo-team/seo-validators/humanizer-validator.md.backup +329 -0
  132. package/claude-assets/cfn-agents-ignore/cfn-seo-team/technical-seo-specialist.md +361 -199
  133. package/claude-assets/cfn-agents-ignore/cfn-seo-team/technical-seo-specialist.md.backup +208 -0
  134. package/claude-assets/commands/CFN_LOOP_TASK_MODE.md +100 -11
  135. package/claude-assets/commands/cfn-mode.md +2 -2
  136. package/claude-assets/skills/cfn-agent-spawning/spawn-agent.sh +12 -0
  137. package/claude-assets/skills/cfn-agent-spawning/spawn-agent.sh.backup +273 -0
  138. package/claude-assets/skills/cfn-environment-sanitization/SKILL.md +200 -0
  139. package/claude-assets/skills/cfn-environment-sanitization/sanitize-environment.sh +244 -0
  140. package/claude-assets/skills/cfn-hybrid-routing/README.md +1 -1
  141. package/claude-assets/skills/cfn-loop-orchestration/orchestrate.sh +95 -15
  142. package/claude-assets/skills/cfn-loop-orchestration/orchestrate.sh.backup +76 -11
  143. package/claude-assets/skills/cfn-loop-orchestration/orchestrate.sh.backup2 +959 -0
  144. package/claude-assets/skills/cfn-loop-orchestration/orchestrate.sh.clean +949 -0
  145. package/claude-assets/skills/cfn-node-heap-sizer/task-mode-heap-limiter.sh +326 -0
  146. package/claude-assets/skills/cfn-process-instrumentation/SKILL.md +279 -0
  147. package/claude-assets/skills/cfn-process-instrumentation/instrument-process.sh +323 -0
  148. package/claude-assets/skills/cfn-product-owner-decision/execute-decision.sh +82 -10
  149. package/claude-assets/skills/cfn-task-audit/get-audit-data.sh +376 -0
  150. package/claude-assets/skills/cfn-task-audit/store-task-audit.sh +184 -0
  151. package/claude-assets/skills/cfn-task-mode-safety/cli-coordination.sh +519 -0
  152. package/claude-assets/skills/cfn-task-mode-safety/mode-detection.sh +326 -0
  153. package/claude-assets/skills/cfn-task-mode-sanitize/task-mode-env-sanitizer.sh +224 -0
  154. package/claude-assets/skills/cfn-telemetry/collect-metrics.sh +249 -0
  155. package/claude-assets/skills/cfn-telemetry/start-telemetry.sh +111 -0
  156. package/claude-assets/skills/cfn-validation-runner-instrumentation/wrapped-executor.sh +327 -0
  157. package/dist/agents/agent-loader.js +146 -165
  158. package/dist/agents/agent-loader.js.map +1 -1
  159. package/dist/cli/config-manager.js +109 -91
  160. package/dist/cli/config-manager.js.map +1 -1
  161. package/package.json +1 -1
  162. package/scripts/mode-detection.sh +321 -0
  163. package/scripts/spawn-worker.sh +8 -0
  164. package/scripts/track-zai-costs-simple.sh +8 -0
@@ -0,0 +1,249 @@
1
+ #!/bin/bash
2
+ # CFN Telemetry Collection System
3
+ # Real-time metrics collection for agent monitoring
4
+
5
+ set -euo pipefail
6
+
7
+ # Configuration
8
+ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
9
+ PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
10
+ TELEMETRY_DIR="${CFN_TELEMETRY_DIR:-$PROJECT_ROOT/.artifacts/telemetry}"
11
+ COLLECTION_INTERVAL="${CFN_TELEMETRY_INTERVAL:-30}" # seconds
12
+
13
+ # Ensure telemetry directory exists
14
+ mkdir -p "$TELEMETRY_DIR"
15
+
16
+ # Function to collect agent metrics
17
+ collect_agent_metrics() {
18
+ local agent_id="$1"
19
+ local agent_pid="$2"
20
+ local iteration="${3:-1}"
21
+ local agent_type="${4:-unknown}"
22
+
23
+ if ! kill -0 "$agent_pid" 2>/dev/null; then
24
+ echo "⚠️ Process $agent_pid no longer running" >&2
25
+ return 1
26
+ fi
27
+
28
+ # Collect memory and CPU usage
29
+ local memory_kb=$(ps -o rss= -p "$agent_pid" 2>/dev/null | tr -d ' ' || echo "0")
30
+ local cpu_percent=$(ps -o %cpu= -p "$agent_pid" 2>/dev/null | tr -d ' ' || echo "0")
31
+ local start_time=$(ps -o lstart= -p "$agent_pid" 2>/dev/null || echo "unknown")
32
+
33
+ # Calculate memory usage percentage
34
+ local memory_limit_kb=$((CFN_MEMORY_LIMIT * 1024))
35
+ local memory_usage_percent=$(echo "scale=1; $memory_kb * 100 / $memory_limit_kb" | bc -l 2>/dev/null || echo "0")
36
+
37
+ # Create metrics record
38
+ local metrics_file="$TELEMETRY_DIR/agent_${agent_id}_$(date +%s).json"
39
+ cat > "$metrics_file" <<EOF
40
+ {
41
+ "timestamp": "$(date -u +%Y-%m-%dT%H:%M:%SZ)",
42
+ "collection_type": "agent_metrics",
43
+ "agent_id": "$agent_id",
44
+ "agent_type": "$agent_type",
45
+ "iteration": $iteration,
46
+ "pid": $agent_pid,
47
+ "process": {
48
+ "start_time": "$start_time",
49
+ "memory_kb": $memory_kb,
50
+ "cpu_percent": $cpu_percent,
51
+ "memory_limit_kb": $memory_limit_kb,
52
+ "memory_usage_percent": $memory_usage_percent
53
+ },
54
+ "limits": {
55
+ "memory_limit_mb": $CFN_MEMORY_LIMIT,
56
+ "timeout_seconds": $CFN_VALIDATION_TIMEOUT,
57
+ "cpu_limit_percent": $CFN_CPU_LIMIT
58
+ },
59
+ "environment": {
60
+ "cfn_mode": "${CFN_MODE:-unset}",
61
+ "task_id": "${TASK_ID:-unset}",
62
+ "validation_timeout": $CFN_VALIDATION_TIMEOUT
63
+ }
64
+ }
65
+ EOF
66
+
67
+ # Log summary
68
+ echo "📊 Collected metrics for $agent_id: ${memory_kb}KB memory, ${cpu_percent}% CPU" >&2
69
+
70
+ # Check for memory limit violations
71
+ if (( $(echo "$memory_usage_percent > 90" | bc -l) )); then
72
+ echo "⚠️ WARNING: $agent_id using ${memory_usage_percent}% of memory limit" >&2
73
+ collect_alert "$agent_id" "memory_warning" "Memory usage at ${memory_usage_percent}%"
74
+ fi
75
+
76
+ return 0
77
+ }
78
+
79
+ # Function to collect system metrics
80
+ collect_system_metrics() {
81
+ local system_file="$TELEMETRY_DIR/system_$(date +%s).json"
82
+
83
+ # System resource usage
84
+ local system_memory=$(free -m | awk 'NR==2{printf "%.1f", $3*100/$2}')
85
+ local system_cpu=$(top -bn1 | grep "Cpu(s)" | awk '{print $2}' | sed 's/%us,//')
86
+ local load_avg=$(uptime | awk -F'load average:' '{print $2}' | tr -d ' ')
87
+
88
+ cat > "$system_file" <<EOF
89
+ {
90
+ "timestamp": "$(date -u +%Y-%m-%dT%H:%M:%SZ)",
91
+ "collection_type": "system_metrics",
92
+ "system": {
93
+ "memory_usage_percent": $system_memory,
94
+ "cpu_usage_percent": ${system_cpu:-0},
95
+ "load_average": "$load_avg"
96
+ },
97
+ "cfn_processes": {
98
+ "active_agents": $(pgrep -f "claude-flow-novice agent" | wc -l || echo 0),
99
+ "orchestrator_processes": $(pgrep -f "orchestrate.sh" | wc -l || echo 0)
100
+ }
101
+ }
102
+ EOF
103
+ }
104
+
105
+ # Function to collect alerts
106
+ collect_alert() {
107
+ local agent_id="$1"
108
+ local alert_type="$2"
109
+ local message="$3"
110
+
111
+ local alert_file="$TELEMETRY_DIR/alert_$(date +%s).json"
112
+ cat > "$alert_file" <<EOF
113
+ {
114
+ "timestamp": "$(date -u +%Y-%m-%dT%H:%M:%SZ)",
115
+ "alert_type": "$alert_type",
116
+ "agent_id": "$agent_id",
117
+ "message": "$message",
118
+ "severity": "warning"
119
+ }
120
+ EOF
121
+
122
+ echo "🚨 ALERT: $alert_type for $agent_id - $message" >&2
123
+ }
124
+
125
+ # Function to start continuous monitoring
126
+ start_monitoring() {
127
+ local agent_id="$1"
128
+ local agent_pid="$2"
129
+ local iteration="${3:-1}"
130
+ local agent_type="${4:-unknown}"
131
+
132
+ echo "🔍 Starting monitoring for $agent_id (PID: $agent_pid)" >&2
133
+
134
+ # Initial metrics collection
135
+ collect_agent_metrics "$agent_id" "$agent_pid" "$iteration" "$agent_type"
136
+
137
+ # Start background monitoring
138
+ (
139
+ while kill -0 "$agent_pid" 2>/dev/null; do
140
+ sleep "$COLLECTION_INTERVAL"
141
+ collect_agent_metrics "$agent_id" "$agent_pid" "$iteration" "$agent_type"
142
+ done
143
+
144
+ # Final metrics when process exits
145
+ collect_agent_metrics "$agent_id" "$agent_pid" "$iteration" "$agent_type"
146
+ echo "✅ Monitoring ended for $agent_id" >&2
147
+ ) &
148
+
149
+ local monitor_pid=$!
150
+ echo "$monitor_pid"
151
+ }
152
+
153
+ # Function to stop monitoring
154
+ stop_monitoring() {
155
+ local monitor_pid="$1"
156
+
157
+ if kill -0 "$monitor_pid" 2>/dev/null; then
158
+ kill "$monitor_pid" 2>/dev/null || true
159
+ wait "$monitor_pid" 2>/dev/null || true
160
+ echo "🛑 Stopped monitoring (PID: $monitor_pid)" >&2
161
+ fi
162
+ }
163
+
164
+ # Function to cleanup old telemetry files
165
+ cleanup_telemetry() {
166
+ local retention_days="${1:-7}"
167
+ local cutoff_time=$(date -d "$retention_days days ago" +%s 2>/dev/null || echo 0)
168
+
169
+ find "$TELEMETRY_DIR" -name "*.json" -type f -mtime "+$retention_days" -delete 2>/dev/null || true
170
+ echo "🧹 Cleaned telemetry files older than $retention_days days" >&2
171
+ }
172
+
173
+ # Function to generate summary report
174
+ generate_summary() {
175
+ local summary_file="$TELEMETRY_DIR/summary_$(date +%s).json"
176
+
177
+ local total_metrics=$(find "$TELEMETRY_DIR" -name "agent_*.json" | wc -l)
178
+ local total_alerts=$(find "$TELEMETRY_DIR" -name "alert_*.json" | wc -l)
179
+ local recent_metrics=$(find "$TELEMETRY_DIR" -name "agent_*.json" -mmin -60 | wc -l)
180
+
181
+ cat > "$summary_file" <<EOF
182
+ {
183
+ "timestamp": "$(date -u +%Y-%m-%dT%H:%M:%SZ)",
184
+ "collection_type": "telemetry_summary",
185
+ "metrics": {
186
+ "total_agent_metrics": $total_metrics,
187
+ "recent_metrics_last_hour": $recent_metrics,
188
+ "total_alerts": $total_alerts
189
+ },
190
+ "system": {
191
+ "telemetry_directory": "$TELEMETRY_DIR",
192
+ "collection_interval_seconds": $COLLECTION_INTERVAL
193
+ }
194
+ }
195
+ EOF
196
+
197
+ echo "📈 Telemetry summary: $total_metrics total metrics, $total_alerts alerts" >&2
198
+ }
199
+
200
+ # Main execution
201
+ if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
202
+ case "${1:-help}" in
203
+ "collect-agent")
204
+ collect_agent_metrics "$2" "$3" "${4:-1}" "${5:-unknown}"
205
+ ;;
206
+ "collect-system")
207
+ collect_system_metrics
208
+ ;;
209
+ "start-monitoring")
210
+ start_monitoring "$2" "$3" "${4:-1}" "${5:-unknown}"
211
+ ;;
212
+ "stop-monitoring")
213
+ stop_monitoring "$2"
214
+ ;;
215
+ "cleanup")
216
+ cleanup_telemetry "${2:-7}"
217
+ ;;
218
+ "summary")
219
+ generate_summary
220
+ ;;
221
+ "help"|"--help"|"-h")
222
+ cat <<'EOF'
223
+ CFN Telemetry Collection System
224
+
225
+ USAGE:
226
+ collect-metrics.sh <command> [args...]
227
+
228
+ COMMANDS:
229
+ collect-agent <agent_id> <pid> [iteration] [type] Collect single agent metrics
230
+ collect-system Collect system metrics
231
+ start-monitoring <agent_id> <pid> [iteration] [type] Start continuous monitoring
232
+ stop-monitoring <monitor_pid> Stop monitoring
233
+ cleanup [days] Clean old telemetry files (default: 7 days)
234
+ summary Generate summary report
235
+
236
+ EXAMPLES:
237
+ collect-metrics.sh collect-agent reviewer_123 45678 1 reviewer
238
+ collect-metrics.sh start-monitoring tester_456 78901
239
+ collect-metrics.sh cleanup 3
240
+
241
+ EOF
242
+ ;;
243
+ *)
244
+ echo "Unknown command: $1" >&2
245
+ echo "Use 'help' for usage information" >&2
246
+ exit 1
247
+ ;;
248
+ esac
249
+ fi
@@ -0,0 +1,111 @@
1
+ #!/bin/bash
2
+
3
+ # Start Telemetry Collection for CFN Stabilization System
4
+ # This script initializes and starts telemetry monitoring for agent execution
5
+
6
+ set -euo pipefail
7
+
8
+ # Required parameters
9
+ TASK_ID="${1:-}"
10
+ AGENT_ID="${2:-}"
11
+
12
+ # Validate required parameters
13
+ if [ -z "$TASK_ID" ] || [ -z "$AGENT_ID" ]; then
14
+ echo "Usage: $0 <task-id> <agent-id>"
15
+ exit 1
16
+ fi
17
+
18
+ # Get telemetry directory from environment or use default
19
+ TELEMETRY_DIR="${CFN_TELEMETRY_DIR:-/tmp/cfn-telemetry}"
20
+ mkdir -p "$TELEMETRY_DIR"
21
+
22
+ # Get current timestamp
23
+ TIMESTAMP=$(date -Iseconds)
24
+
25
+ # Initialize telemetry session
26
+ TELEMETRY_FILE="$TELEMETRY_DIR/${TASK_ID}_${AGENT_ID}_telemetry.json"
27
+
28
+ # Create initial telemetry record
29
+ cat > "$TELEMETRY_FILE" << TELEMETRY_EOF
30
+ {
31
+ "task_id": "$TASK_ID",
32
+ "agent_id": "$AGENT_ID",
33
+ "session_start": "$TIMESTAMP",
34
+ "status": "active",
35
+ "memory_usage": 0,
36
+ "cpu_usage": 0,
37
+ "disk_usage": 0,
38
+ "file_count": 0,
39
+ "metrics": [],
40
+ "events": []
41
+ }
42
+ TELEMETRY_EOF
43
+
44
+ # Start background telemetry collection
45
+ BACKGROUND_PID=$$
46
+ echo "$BACKGROUND_PID" > "$TELEMETRY_DIR/${TASK_ID}_${AGENT_ID}_pid.txt"
47
+
48
+ # Initialize metrics collection
49
+ echo "Starting telemetry collection for task $TASK_ID, agent $AGENT_ID"
50
+
51
+ # Set up monitoring intervals (every 5 seconds)
52
+ INTERVAL=5
53
+
54
+ # Background telemetry monitoring function
55
+ collect_telemetry() {
56
+ local start_time=$(date +%s)
57
+
58
+ while true; do
59
+ current_time=$(date +%s)
60
+ elapsed_time=$((current_time - start_time))
61
+
62
+ # Collect system metrics
63
+ memory_usage=$(free -m | grep Mem | awk '{print $3}')
64
+ cpu_usage=$(top -bn1 | grep "Cpu(s)" | sed "s/.*, *\([0-9.]*\)%* id.*/\1/" | awk '{print 100 - $1}')
65
+ disk_usage=$(df /tmp | tail -1 | awk '{print $5}' | tr -d '%')
66
+ file_count=$(find "$TELEMETRY_DIR" -name "*.json" -type f 2>/dev/null | wc -l)
67
+
68
+ # Create metric record
69
+ metric_record='{
70
+ "timestamp": "'$(date -Iseconds)'",
71
+ "elapsed_seconds": '"$elapsed_time"',
72
+ "memory_usage": '"$memory_usage"',
73
+ "cpu_usage": '"$cpu_usage"',
74
+ "disk_usage": '"$disk_usage"',
75
+ "file_count": '"$file_count"'
76
+ }'
77
+
78
+ # Append to telemetry file
79
+ jq --argjson metric "$metric_record" '.metrics += [$metric]' "$TELEMETRY_FILE" > "$TELEMETRY_FILE.tmp" 2>/dev/null || true
80
+ mv "$TELEMETRY_FILE.tmp" "$TELEMETRY_FILE" 2>/dev/null || true
81
+
82
+ # Sleep for interval
83
+ sleep $INTERVAL
84
+ done
85
+ }
86
+
87
+ # Start telemetry collection in background
88
+ collect_tlemetry &
89
+ TELEMETRY_COLLECTOR_PID=$!
90
+
91
+ # Save collector PID
92
+ echo "$TELEMETRY_COLLECTOR_PID" > "$TELEMETRY_DIR/${TASK_ID}_${AGENT_ID}_collector_pid.txt"
93
+
94
+ # Log telemetry start event
95
+ echo "Telemetry collection started for $TASK_ID:$AGENT_ID (PID: $TELEMETRY_COLLECTOR_PID)"
96
+
97
+ # Keep script running while telemetry is active
98
+ while kill -0 "$TELEMETRY_COLLECTOR_PID" 2>/dev/null; do
99
+ sleep 1
100
+ done
101
+
102
+ # Cleanup when telemetry stops
103
+ TELEMETRY_STOP_TIME=$(date -Iseconds)
104
+ jq --arg stop_time "$TELEMETRY_STOP_TIME" '.session_stop = $stop_time | .status = "stopped"' "$TELEMETRY_FILE" > "$TELEMETRY_FILE.tmp" 2>/dev/null || true
105
+ mv "$TELEMETRY_FILE.tmp" "$TELEMETRY_FILE" 2>/dev/null || true
106
+
107
+ # Remove PID files
108
+ rm -f "$TELEMETRY_DIR/${TASK_ID}_${AGENT_ID}_pid.txt"
109
+ rm -f "$TELEMETRY_DIR/${TASK_ID}_${AGENT_ID}_collector_pid.txt"
110
+
111
+ echo "Telemetry collection stopped for $TASK_ID:$AGENT_ID"
@@ -0,0 +1,327 @@
1
+ #!/bin/bash
2
+ # CFN Validation Runner Instrumentation
3
+ # Wraps Bun/Node/Playwright invocations with logging, timeouts, and cleanup
4
+
5
+ set -euo pipefail
6
+
7
+ # Script configuration
8
+ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
9
+ PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
10
+
11
+ # Configuration defaults
12
+ DEFAULT_TIMEOUT="${CFN_VALIDATION_TIMEOUT:-300}" # 5 minutes
13
+ DEFAULT_MEMORY="${CFN_VALIDATION_MEMORY:-2048}" # 2GB
14
+ LOG_DIR="${CFN_VALIDATION_LOG_DIR:-$PROJECT_ROOT/.claude/logs/validation}"
15
+ MONITOR_INTERVAL="${CFN_MONITOR_INTERVAL:-30}" # 30 seconds
16
+
17
+ # Colors for output
18
+ RED='\033[0;31m'
19
+ GREEN='\033[0;32m'
20
+ YELLOW='\033[1;33m'
21
+ BLUE='\033[0;34m'
22
+ NC='\033[0m' # No Color
23
+
24
+ # Logging functions
25
+ log_info() {
26
+ echo -e "${BLUE}[INFO]${NC} $(date '+%Y-%m-%d %H:%M:%S') - $1" | tee -a "$LOG_FILE"
27
+ }
28
+
29
+ log_success() {
30
+ echo -e "${GREEN}[SUCCESS]${NC} $(date '+%Y-%m-%d %H:%M:%S') - $1" | tee -a "$LOG_FILE"
31
+ }
32
+
33
+ log_error() {
34
+ echo -e "${RED}[ERROR]${NC} $(date '+%Y-%m-%d %H:%M:%S') - $1" | tee -a "$LOG_FILE"
35
+ }
36
+
37
+ log_warning() {
38
+ echo -e "${YELLOW}[WARNING]${NC} $(date '+%Y-%m-%d %H:%M:%S') - $1" | tee -a "$LOG_FILE"
39
+ }
40
+
41
+ # Process monitoring
42
+ monitor_process() {
43
+ local pid="$1"
44
+ local timeout="$2"
45
+ local command_name="$3"
46
+ local log_file="$4"
47
+
48
+ local elapsed=0
49
+ while kill -0 "$pid" 2>/dev/null; do
50
+ if [[ $elapsed -ge $timeout ]]; then
51
+ log_warning "Process $pid ($command_name) exceeded timeout ${timeout}s, terminating..."
52
+
53
+ # Get memory usage before termination
54
+ local memory_usage=$(ps -o rss= -p "$pid" 2>/dev/null | tr -d ' ' || echo "unknown")
55
+ log_error "Memory usage at termination: ${memory_usage}KB"
56
+
57
+ # Terminate the process gracefully
58
+ kill -TERM "$pid" 2>/dev/null || true
59
+ sleep 5
60
+
61
+ # Force kill if still running
62
+ if kill -0 "$pid" 2>/dev/null; then
63
+ log_error "Force killing process $pid ($command_name)"
64
+ kill -KILL "$pid" 2>/dev/null || true
65
+ fi
66
+
67
+ return 124 # Timeout exit code
68
+ fi
69
+
70
+ # Log periodic status
71
+ if [[ $((elapsed % MONITOR_INTERVAL)) -eq 0 && $elapsed -gt 0 ]]; then
72
+ local memory_usage=$(ps -o rss= -p "$pid" 2>/dev/null | tr -d ' ' || echo "unknown")
73
+ log_info "Process $pid ($command_name) running: ${elapsed}s elapsed, ${memory_usage}KB memory"
74
+ fi
75
+
76
+ sleep 1
77
+ ((elapsed++))
78
+ done
79
+
80
+ return 0
81
+ }
82
+
83
+ # Instrumented execution wrapper
84
+ execute_instrumented() {
85
+ local command="$1"
86
+ local timeout="${2:-$DEFAULT_TIMEOUT}"
87
+ local memory_limit="${3:-$DEFAULT_MEMORY}"
88
+ shift 3
89
+ local args=("$@")
90
+
91
+ # Create log directory
92
+ mkdir -p "$LOG_DIR"
93
+
94
+ # Generate unique execution ID
95
+ local execution_id="exec_$(date +%Y%m%d_%H%M%S)_$$"
96
+ local log_file="$LOG_DIR/${execution_id}.log"
97
+ export LOG_FILE="$log_file"
98
+
99
+ # Extract command name for logging
100
+ local command_name=$(basename "$command")
101
+ local full_command="$command ${args[*]}"
102
+
103
+ # Start execution logging
104
+ log_info "=== Starting Instrumented Execution ==="
105
+ log_info "Execution ID: $execution_id"
106
+ log_info "Command: $full_command"
107
+ log_info "Timeout: ${timeout}s"
108
+ log_info "Memory Limit: ${memory_limit}MB"
109
+ log_info "Working Directory: $(pwd)"
110
+ log_info "Environment: CFN_MODE=${CFN_MODE:-unset}, NODE_OPTIONS=${NODE_OPTIONS:-unset}"
111
+
112
+ # Set up resource limits
113
+ local memory_limit_kb=$((memory_limit * 1024))
114
+
115
+ # Start the command with resource limits
116
+ local start_time=$(date +%s)
117
+ log_info "Starting process at $(date)"
118
+
119
+ # Launch command in background with resource limits
120
+ (
121
+ # Apply memory limit
122
+ ulimit -v "$memory_limit_kb" 2>/dev/null || {
123
+ log_warning "Could not set memory limit via ulimit"
124
+ }
125
+
126
+ # Apply Node.js specific memory limit
127
+ if [[ "$command_name" == "node" || "$command_name" == "bun" ]]; then
128
+ export NODE_OPTIONS="${NODE_OPTIONS:-} --max-old-space-size=$memory_limit"
129
+ log_info "Set NODE_OPTIONS: $NODE_OPTIONS"
130
+ fi
131
+
132
+ # Execute the command
133
+ exec "$command" "${args[@]}" 2>&1
134
+ ) &
135
+
136
+ local pid=$!
137
+ log_info "Process started with PID: $pid"
138
+
139
+ # Start monitoring in background
140
+ monitor_process "$pid" "$timeout" "$command_name" "$log_file" &
141
+ local monitor_pid=$!
142
+
143
+ # Wait for command completion
144
+ local exit_code=0
145
+ if wait "$pid" 2>/dev/null; then
146
+ exit_code=$?
147
+ log_success "Process $pid ($command_name) completed successfully"
148
+ else
149
+ exit_code=$?
150
+ if [[ $exit_code -eq 124 ]]; then
151
+ log_error "Process $pid ($command_name) timed out after ${timeout}s"
152
+ else
153
+ log_error "Process $pid ($command_name) failed with exit code: $exit_code"
154
+ fi
155
+ fi
156
+
157
+ # Stop monitoring
158
+ kill "$monitor_pid" 2>/dev/null || true
159
+ wait "$monitor_pid" 2>/dev/null || true
160
+
161
+ # Calculate execution time
162
+ local end_time=$(date +%s)
163
+ local duration=$((end_time - start_time))
164
+
165
+ # Final status logging
166
+ log_info "=== Execution Summary ==="
167
+ log_info "Command: $full_command"
168
+ log_info "Exit Code: $exit_code"
169
+ log_info "Duration: ${duration}s"
170
+ log_info "Memory Limit: ${memory_limit}MB"
171
+
172
+ # Log resource usage summary if available
173
+ if command -v ps >/dev/null 2>&1; then
174
+ local final_memory=$(ps -o rss= -p "$pid" 2>/dev/null | tr -d ' ' || echo "unknown")
175
+ log_info "Final Memory: ${final_memory}KB"
176
+ fi
177
+
178
+ # Cleanup if process is still running
179
+ if kill -0 "$pid" 2>/dev/null; then
180
+ log_warning "Cleaning up still-running process $pid"
181
+ kill -TERM "$pid" 2>/dev/null || true
182
+ sleep 2
183
+ kill -KILL "$pid" 2>/dev/null || true
184
+ fi
185
+
186
+ # Archive log if successful
187
+ if [[ $exit_code -eq 0 ]]; then
188
+ local archive_log="$LOG_DIR/${execution_id}_success.log"
189
+ mv "$log_file" "$archive_log" 2>/dev/null || true
190
+ log_success "Log archived: $archive_log"
191
+ else
192
+ local archive_log="$LOG_DIR/${execution_id}_failed.log"
193
+ mv "$log_file" "$archive_log" 2>/dev/null || true
194
+ log_error "Failed log archived: $archive_log"
195
+ fi
196
+
197
+ return $exit_code
198
+ }
199
+
200
+ # Specific wrappers for common tools
201
+ execute_node() {
202
+ local timeout="${1:-$DEFAULT_TIMEOUT}"
203
+ shift
204
+ log_info "Executing Node.js with instrumentation"
205
+ execute_instrumented "node" "$timeout" "$DEFAULT_MEMORY" "$@"
206
+ }
207
+
208
+ execute_bun() {
209
+ local timeout="${1:-$DEFAULT_TIMEOUT}"
210
+ shift
211
+ log_info "Executing Bun with instrumentation"
212
+ execute_instrumented "bun" "$timeout" "$DEFAULT_MEMORY" "$@"
213
+ }
214
+
215
+ execute_playwright() {
216
+ local timeout="${1:-$DEFAULT_TIMEOUT}"
217
+ shift
218
+ # Playwright may need more memory
219
+ local playwright_memory="${CFN_PLAYWRIGHT_MEMORY:-4096}"
220
+ log_info "Executing Playwright with instrumentation"
221
+ execute_instrumented "npx" "$timeout" "$playwright_memory" "playwright" "$@"
222
+ }
223
+
224
+ execute_npx() {
225
+ local timeout="${1:-$DEFAULT_TIMEOUT}"
226
+ shift
227
+ log_info "Executing NPX with instrumentation"
228
+ execute_instrumented "npx" "$timeout" "$DEFAULT_MEMORY" "$@"
229
+ }
230
+
231
+ # Cleanup old logs
232
+ cleanup_logs() {
233
+ local max_days="${CFN_LOG_RETENTION_DAYS:-7}"
234
+ log_info "Cleaning up logs older than $max_days days"
235
+
236
+ find "$LOG_DIR" -name "*.log" -type f -mtime "+$max_days" -delete 2>/dev/null || true
237
+ log_info "Log cleanup completed"
238
+ }
239
+
240
+ # Show usage
241
+ show_usage() {
242
+ cat <<'EOF'
243
+ CFN Validation Runner Instrumentation
244
+
245
+ USAGE:
246
+ source "$(dirname "${BASH_SOURCE[0]}")/wrapped-executor.sh"
247
+
248
+ # Generic Execution
249
+ execute_instrumented <command> [timeout] [memory_limit] [args...]
250
+
251
+ # Tool-Specific Wrappers
252
+ execute_node [timeout] [args...] # Execute Node.js
253
+ execute_bun [timeout] [args...] # Execute Bun
254
+ execute_playwright [timeout] [args...] # Execute Playwright
255
+ execute_npx [timeout] [args...] # Execute NPX
256
+
257
+ # Maintenance
258
+ cleanup_logs # Clean up old logs
259
+
260
+ ENVIRONMENT VARIABLES:
261
+ CFN_VALIDATION_TIMEOUT # Default timeout in seconds (default: 300)
262
+ CFN_VALIDATION_MEMORY # Default memory limit in MB (default: 2048)
263
+ CFN_VALIDATION_LOG_DIR # Log directory (default: ./.claude/logs/validation)
264
+ CFN_MONITOR_INTERVAL # Monitoring interval in seconds (default: 30)
265
+ CFN_PLAYWRIGHT_MEMORY # Playwright memory limit in MB (default: 4096)
266
+ CFN_LOG_RETENTION_DAYS # Log retention in days (default: 7)
267
+
268
+ EXAMPLES:
269
+ # Execute Node.js script with default settings
270
+ execute_node validate.js
271
+
272
+ # Execute Bun with custom timeout
273
+ execute_bun 600 build.ts
274
+
275
+ # Execute Playwright with longer timeout
276
+ execute_playwright 900 test.spec.js
277
+
278
+ # Generic execution with custom memory limit
279
+ execute_instrumented custom-tool 300 4096 --arg1 --arg2
280
+
281
+ OUTPUT:
282
+ All executions generate detailed logs in ./.claude/logs/validation/
283
+ Logs include: start time, end time, memory usage, exit codes, timeouts
284
+
285
+ EOF
286
+ }
287
+
288
+ # Main execution block
289
+ if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
290
+ if [[ "$1" == "--help" || "$1" == "-h" ]]; then
291
+ show_usage
292
+ exit 0
293
+ fi
294
+
295
+ # Execute operation if provided
296
+ if [[ $# -gt 0 ]]; then
297
+ case "$1" in
298
+ "node")
299
+ shift
300
+ execute_node "$@"
301
+ ;;
302
+ "bun")
303
+ shift
304
+ execute_bun "$@"
305
+ ;;
306
+ "playwright")
307
+ shift
308
+ execute_playwright "$@"
309
+ ;;
310
+ "npx")
311
+ shift
312
+ execute_npx "$@"
313
+ ;;
314
+ "cleanup")
315
+ cleanup_logs
316
+ ;;
317
+ *)
318
+ echo "Unknown command: $1" >&2
319
+ echo "Use --help for usage information" >&2
320
+ exit 1
321
+ ;;
322
+ esac
323
+ else
324
+ echo "CFN Validation Runner Instrumentation" >&2
325
+ echo "Use --help for usage information" >&2
326
+ fi
327
+ fi