claude-flow-novice 2.14.28 → 2.14.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/commands/CFN_LOOP_TASK_MODE.md +119 -0
- package/.claude/skills/cfn-agent-spawning/spawn-agent.sh +12 -0
- package/.claude/skills/cfn-agent-spawning/spawn-agent.sh.backup +273 -0
- package/.claude/skills/cfn-hybrid-routing/README.md +1 -1
- package/.claude/skills/cfn-loop-orchestration/orchestrate.sh +95 -15
- package/.claude/skills/cfn-loop-orchestration/orchestrate.sh.backup +76 -11
- package/.claude/skills/cfn-loop-orchestration/orchestrate.sh.backup2 +959 -0
- package/.claude/skills/cfn-loop-orchestration/orchestrate.sh.clean +949 -0
- package/.claude/skills/cfn-product-owner-decision/execute-decision.sh +82 -10
- package/claude-assets/agents/cfn-dev-team/architecture/base-template-generator.md +7 -33
- package/claude-assets/agents/cfn-dev-team/architecture/planner.md +7 -47
- package/claude-assets/agents/cfn-dev-team/architecture/system-architect.md +7 -33
- package/claude-assets/agents/cfn-dev-team/coordinators/cfn-frontend-coordinator.md +88 -23
- package/claude-assets/agents/cfn-dev-team/coordinators/cfn-v3-coordinator.md +59 -23
- package/claude-assets/agents/cfn-dev-team/coordinators/consensus-builder.md +43 -39
- package/claude-assets/agents/cfn-dev-team/coordinators/epic-creator.md +69 -0
- package/claude-assets/agents/cfn-dev-team/coordinators/multi-sprint-coordinator.md +65 -1
- package/claude-assets/agents/cfn-dev-team/developers/frontend/mobile-dev.md +7 -47
- package/claude-assets/agents/cfn-dev-team/developers/frontend/typescript-specialist.md +7 -26
- package/claude-assets/agents/cfn-dev-team/developers/rust-developer.md +7 -47
- package/claude-assets/agents/cfn-dev-team/product-owners/cto-agent.md +7 -19
- package/claude-assets/agents/cfn-dev-team/product-owners/power-user-persona.md +9 -49
- package/claude-assets/agents/cfn-dev-team/product-owners/product-owner.md +407 -22
- package/claude-assets/agents/cfn-dev-team/reviewers/quality/code-quality-validator.md +7 -66
- package/claude-assets/agents/cfn-dev-team/reviewers/quality/perf-analyzer.md +7 -76
- package/claude-assets/agents/cfn-dev-team/reviewers/quality/performance-benchmarker.md +8 -2
- package/claude-assets/agents/cfn-dev-team/reviewers/quality/security-specialist.md +7 -66
- package/claude-assets/agents/cfn-dev-team/reviewers/reviewer.md +7 -78
- package/claude-assets/agents/cfn-dev-team/testers/e2e/playwright-tester.md +7 -18
- package/claude-assets/agents/cfn-dev-team/testers/interaction-tester.md +7 -18
- package/claude-assets/agents/cfn-dev-team/testers/tester.md +7 -77
- package/claude-assets/agents/cfn-dev-team/testers/unit/tdd-london-unit-swarm.md +7 -18
- package/claude-assets/agents/cfn-dev-team/testers/validation/validation-production-validator.md +7 -19
- package/claude-assets/agents/cfn-dev-team/testing/test-validation-agent.md +7 -44
- package/claude-assets/agents/cfn-dev-team/utility/agent-builder.md +35 -111
- package/claude-assets/agents/cfn-dev-team/utility/analyst.md +7 -47
- package/claude-assets/agents/cfn-dev-team/utility/code-booster.md +7 -40
- package/claude-assets/agents/cfn-dev-team/utility/context-curator.md +7 -47
- package/claude-assets/commands/CFN_LOOP_TASK_MODE.md +119 -0
- package/claude-assets/skills/cfn-agent-spawning/spawn-agent.sh +12 -0
- package/claude-assets/skills/cfn-agent-spawning/spawn-agent.sh.backup +273 -0
- package/claude-assets/skills/cfn-environment-sanitization/SKILL.md +200 -0
- package/claude-assets/skills/cfn-environment-sanitization/sanitize-environment.sh +244 -0
- package/claude-assets/skills/cfn-hybrid-routing/README.md +1 -1
- package/claude-assets/skills/cfn-loop-orchestration/orchestrate.sh +95 -15
- package/claude-assets/skills/cfn-loop-orchestration/orchestrate.sh.backup +76 -11
- package/claude-assets/skills/cfn-loop-orchestration/orchestrate.sh.backup2 +959 -0
- package/claude-assets/skills/cfn-loop-orchestration/orchestrate.sh.clean +949 -0
- package/claude-assets/skills/cfn-node-heap-sizer/task-mode-heap-limiter.sh +326 -0
- package/claude-assets/skills/cfn-process-instrumentation/SKILL.md +279 -0
- package/claude-assets/skills/cfn-process-instrumentation/instrument-process.sh +323 -0
- package/claude-assets/skills/cfn-product-owner-decision/execute-decision.sh +82 -10
- package/claude-assets/skills/cfn-task-audit/get-audit-data.sh +376 -0
- package/claude-assets/skills/cfn-task-audit/store-task-audit.sh +184 -0
- package/claude-assets/skills/cfn-task-mode-safety/cli-coordination.sh +519 -0
- package/claude-assets/skills/cfn-task-mode-safety/mode-detection.sh +326 -0
- package/claude-assets/skills/cfn-task-mode-sanitize/task-mode-env-sanitizer.sh +224 -0
- package/claude-assets/skills/cfn-telemetry/collect-metrics.sh +249 -0
- package/claude-assets/skills/cfn-telemetry/start-telemetry.sh +111 -0
- package/claude-assets/skills/cfn-validation-runner-instrumentation/wrapped-executor.sh +327 -0
- package/dist/cli/config-manager.js +109 -91
- package/dist/cli/config-manager.js.map +1 -1
- package/package.json +1 -1
- package/scripts/mode-detection.sh +321 -0
- package/scripts/spawn-worker.sh +8 -0
- package/scripts/track-zai-costs-simple.sh +8 -0
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# CFN Node.js Heap Size Limiter for Task Mode
|
|
3
|
+
# Dynamically adjusts NODE_OPTIONS based on execution mode to prevent memory bloat
|
|
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
|
+
|
|
11
|
+
# Mode-based heap sizes (in MB)
|
|
12
|
+
declare -A HEAP_SIZES=(
|
|
13
|
+
["task"]="2048" # 2GB for Task mode (conservative)
|
|
14
|
+
["cli"]="8192" # 8GB for CLI mode (production)
|
|
15
|
+
["debug"]="1024" # 1GB for debugging (minimal)
|
|
16
|
+
["test"]="3072" # 3GB for testing (moderate)
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
# Default heap sizes by tool type
|
|
20
|
+
declare -A TOOL_HEAPS=(
|
|
21
|
+
["node"]="2048"
|
|
22
|
+
["bun"]="3072"
|
|
23
|
+
["playwright"]="4096"
|
|
24
|
+
["test"]="1536"
|
|
25
|
+
["validator"]="1024"
|
|
26
|
+
["reviewer"]="1024"
|
|
27
|
+
["tester"]="1024"
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
# Function to detect current execution mode
|
|
31
|
+
detect_execution_mode() {
|
|
32
|
+
# Use existing mode detection if available
|
|
33
|
+
if [[ -f "$PROJECT_ROOT/.claude/skills/cfn-task-mode-safety/mode-detection.sh" ]]; then
|
|
34
|
+
source "$PROJECT_ROOT/.claude/skills/cfn-task-mode-safety/mode-detection.sh"
|
|
35
|
+
detect_execution_mode 2>/dev/null && return 0
|
|
36
|
+
fi
|
|
37
|
+
|
|
38
|
+
# Fallback detection
|
|
39
|
+
if [[ -n "${CFN_MODE:-}" ]]; then
|
|
40
|
+
echo "$CFN_MODE"
|
|
41
|
+
elif [[ -n "${TASK_ID:-}" && -n "${AGENT_ID:-}" ]]; then
|
|
42
|
+
echo "cli"
|
|
43
|
+
else
|
|
44
|
+
echo "task" # Safe default
|
|
45
|
+
fi
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
# Function to determine tool type from command line
|
|
49
|
+
detect_tool_type() {
|
|
50
|
+
local command="$1"
|
|
51
|
+
local command_name=$(basename "$command")
|
|
52
|
+
|
|
53
|
+
case "$command_name" in
|
|
54
|
+
"node"|"bun")
|
|
55
|
+
# Look at script name to determine tool type
|
|
56
|
+
if [[ $# -gt 1 ]]; then
|
|
57
|
+
local script_name=$(basename "$2" | tr '[:upper:]' '[:lower:]')
|
|
58
|
+
case "$script_name" in
|
|
59
|
+
*"test"*) echo "test" ;;
|
|
60
|
+
*"validator"*) echo "validator" ;;
|
|
61
|
+
*"reviewer"*) echo "reviewer" ;;
|
|
62
|
+
*"tester"*) echo "tester" ;;
|
|
63
|
+
*) echo "$command_name" ;;
|
|
64
|
+
esac
|
|
65
|
+
else
|
|
66
|
+
echo "$command_name"
|
|
67
|
+
fi
|
|
68
|
+
;;
|
|
69
|
+
"npx")
|
|
70
|
+
if [[ $# -gt 1 ]]; then
|
|
71
|
+
local tool_name=$(basename "$2" | tr '[:upper:]' '[:lower:]')
|
|
72
|
+
case "$tool_name" in
|
|
73
|
+
*"playwright"*) echo "playwright" ;;
|
|
74
|
+
*) echo "npx" ;;
|
|
75
|
+
esac
|
|
76
|
+
else
|
|
77
|
+
echo "npx"
|
|
78
|
+
fi
|
|
79
|
+
;;
|
|
80
|
+
*)
|
|
81
|
+
echo "unknown"
|
|
82
|
+
;;
|
|
83
|
+
esac
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
# Function to calculate appropriate heap size
|
|
87
|
+
calculate_heap_size() {
|
|
88
|
+
local mode="$1"
|
|
89
|
+
local tool_type="$2"
|
|
90
|
+
local override_heap="${3:-}"
|
|
91
|
+
|
|
92
|
+
# Use override if provided
|
|
93
|
+
if [[ -n "$override_heap" && "$override_heap" =~ ^[0-9]+$ ]]; then
|
|
94
|
+
echo "$override_heap"
|
|
95
|
+
return 0
|
|
96
|
+
fi
|
|
97
|
+
|
|
98
|
+
# Use tool-specific heap size if available
|
|
99
|
+
local tool_heap="${TOOL_HEAPS[$tool_type]:-}"
|
|
100
|
+
if [[ -n "$tool_heap" ]]; then
|
|
101
|
+
echo "$tool_heap"
|
|
102
|
+
return 0
|
|
103
|
+
fi
|
|
104
|
+
|
|
105
|
+
# Fall back to mode-based heap size
|
|
106
|
+
echo "${HEAP_SIZES[$mode]:-2048}"
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
# Function to configure NODE_OPTIONS
|
|
110
|
+
configure_node_options() {
|
|
111
|
+
local mode="$1"
|
|
112
|
+
local tool_type="$2"
|
|
113
|
+
local heap_size="$3"
|
|
114
|
+
|
|
115
|
+
echo "🎛️ Configuring Node.js heap size for Task mode..." >&2
|
|
116
|
+
|
|
117
|
+
# Base NODE_OPTIONS
|
|
118
|
+
local node_opts="${NODE_OPTIONS:-}"
|
|
119
|
+
|
|
120
|
+
# Remove existing heap size settings
|
|
121
|
+
node_opts=$(echo "$node_opts" | sed 's/--max-old-space-size=[0-9]*//g')
|
|
122
|
+
node_opts=$(echo "$node_opts" | sed 's/--max-semi-space-size=[0-9]*//g')
|
|
123
|
+
|
|
124
|
+
# Add new heap size
|
|
125
|
+
node_opts="$node_opts --max-old-space-size=$heap_size"
|
|
126
|
+
|
|
127
|
+
# Add semi-space size (quarter of heap size)
|
|
128
|
+
local semi_space=$((heap_size / 4))
|
|
129
|
+
node_opts="$node_opts --max-semi-space-size=$semi_space"
|
|
130
|
+
|
|
131
|
+
# Add Task mode specific optimizations
|
|
132
|
+
if [[ "$mode" == "task" ]]; then
|
|
133
|
+
node_opts="$node_opts --optimize-for-size"
|
|
134
|
+
node_opts="$node_opts --max-executable-size=512"
|
|
135
|
+
node_opts="$node_opts --gc-interval=100"
|
|
136
|
+
fi
|
|
137
|
+
|
|
138
|
+
# Export updated NODE_OPTIONS
|
|
139
|
+
export NODE_OPTIONS="$node_opts"
|
|
140
|
+
|
|
141
|
+
echo "✅ NODE_OPTIONS configured: $NODE_OPTIONS" >&2
|
|
142
|
+
echo " Mode: $mode" >&2
|
|
143
|
+
echo " Tool: $tool_type" >&2
|
|
144
|
+
echo " Heap: ${heap_size}MB" >&2
|
|
145
|
+
echo " Semi-space: ${semi_space}MB" >&2
|
|
146
|
+
|
|
147
|
+
# Log configuration
|
|
148
|
+
if [[ -n "${CFN_VALIDATION_LOG_DIR:-}" ]]; then
|
|
149
|
+
local log_file="$CFN_VALIDATION_LOG_DIR/heap-config_$(date +%Y%m%d_%H%M%S).log"
|
|
150
|
+
mkdir -p "$(dirname "$log_file")"
|
|
151
|
+
cat > "$log_file" <<EOF
|
|
152
|
+
{
|
|
153
|
+
"timestamp": "$(date -u +%Y-%m-%dT%H:%M:%SZ)",
|
|
154
|
+
"mode": "$mode",
|
|
155
|
+
"tool_type": "$tool_type",
|
|
156
|
+
"heap_size_mb": $heap_size,
|
|
157
|
+
"semi_space_size_mb": $semi_space,
|
|
158
|
+
"node_options": "$NODE_OPTIONS",
|
|
159
|
+
"command": "${BASH_SOURCE[*]}",
|
|
160
|
+
"pid": $$,
|
|
161
|
+
"ppid": ${PPID:-0}
|
|
162
|
+
}
|
|
163
|
+
EOF
|
|
164
|
+
echo "📝 Heap configuration logged: $log_file" >&2
|
|
165
|
+
fi
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
# Function to validate heap size
|
|
169
|
+
validate_heap_configuration() {
|
|
170
|
+
local current_heap="${NODE_OPTIONS:-}"
|
|
171
|
+
|
|
172
|
+
if echo "$current_heap" | grep -q "max-old-space-size"; then
|
|
173
|
+
local heap_value=$(echo "$current_heap" | grep -o "max-old-space-size=[0-9]*" | cut -d= -f2)
|
|
174
|
+
local mode=$(detect_execution_mode)
|
|
175
|
+
local max_heap="${HEAP_SIZES[$mode]:-2048}"
|
|
176
|
+
|
|
177
|
+
if [[ "$heap_value" -gt "$max_heap" ]]; then
|
|
178
|
+
echo "⚠️ Heap size ($heap_value MB) exceeds recommended maximum for $mode mode ($max_heap MB)" >&2
|
|
179
|
+
return 1
|
|
180
|
+
else
|
|
181
|
+
echo "✅ Heap size ($heap_value MB) within recommended limits for $mode mode" >&2
|
|
182
|
+
return 0
|
|
183
|
+
fi
|
|
184
|
+
else
|
|
185
|
+
echo "⚠️ No heap size configured in NODE_OPTIONS" >&2
|
|
186
|
+
return 1
|
|
187
|
+
fi
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
# Main heap limiting function
|
|
191
|
+
limit_node_heap() {
|
|
192
|
+
local command="$1"
|
|
193
|
+
local heap_override="${2:-}"
|
|
194
|
+
|
|
195
|
+
# Detect execution mode
|
|
196
|
+
local mode=$(detect_execution_mode)
|
|
197
|
+
|
|
198
|
+
# Detect tool type
|
|
199
|
+
local tool_type=$(detect_tool_type "$command" "${@:2}")
|
|
200
|
+
|
|
201
|
+
# Calculate appropriate heap size
|
|
202
|
+
local heap_size=$(calculate_heap_size "$mode" "$tool_type" "$heap_override")
|
|
203
|
+
|
|
204
|
+
# Configure NODE_OPTIONS
|
|
205
|
+
configure_node_options "$mode" "$tool_type" "$heap_size"
|
|
206
|
+
|
|
207
|
+
echo "🎯 Node.js heap size limited to ${heap_size}MB for $tool_type in $mode mode" >&2
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
# Function to execute command with heap limiting
|
|
211
|
+
exec_with_heap_limit() {
|
|
212
|
+
local command="$1"
|
|
213
|
+
local heap_override="${2:-}"
|
|
214
|
+
shift 2
|
|
215
|
+
local args=("$@")
|
|
216
|
+
|
|
217
|
+
# Apply heap limiting
|
|
218
|
+
limit_node_heap "$command" "$heap_override"
|
|
219
|
+
|
|
220
|
+
# Execute command
|
|
221
|
+
echo "🚀 Executing: $command ${args[*]}" >&2
|
|
222
|
+
echo " NODE_OPTIONS: $NODE_OPTIONS" >&2
|
|
223
|
+
|
|
224
|
+
# Use wrapped executor if available
|
|
225
|
+
if [[ -f "$PROJECT_ROOT/.claude/skills/cfn-validation-runner-instrumentation/wrapped-executor.sh" ]]; then
|
|
226
|
+
source "$PROJECT_ROOT/.claude/skills/cfn-validation-runner-instrumentation/wrapped-executor.sh"
|
|
227
|
+
execute_instrumented "$command" 300 2048 "${args[@]}"
|
|
228
|
+
else
|
|
229
|
+
"$command" "${args[@]}"
|
|
230
|
+
fi
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
# Show usage
|
|
234
|
+
show_usage() {
|
|
235
|
+
cat <<'EOF'
|
|
236
|
+
CFN Node.js Heap Size Limiter for Task Mode
|
|
237
|
+
|
|
238
|
+
USAGE:
|
|
239
|
+
source "$(dirname "${BASH_SOURCE[0]}")/task-mode-heap-limiter.sh"
|
|
240
|
+
|
|
241
|
+
# Configuration
|
|
242
|
+
limit_node_heap <command> [heap_override_mb] # Limit heap size for command
|
|
243
|
+
configure_node_options <mode> <tool_type> <size> # Configure NODE_OPTIONS
|
|
244
|
+
validate_heap_configuration # Validate current configuration
|
|
245
|
+
|
|
246
|
+
# Execution
|
|
247
|
+
exec_with_heap_limit <command> [heap_override] [args...]
|
|
248
|
+
|
|
249
|
+
ENVIRONMENT VARIABLES:
|
|
250
|
+
NODE_OPTIONS # Modified to include heap size limits
|
|
251
|
+
CFN_MODE # Detected or set execution mode
|
|
252
|
+
CFN_VALIDATION_LOG_DIR # Directory for heap configuration logs
|
|
253
|
+
|
|
254
|
+
HEAP SIZES BY MODE:
|
|
255
|
+
task: 2048 MB (conservative)
|
|
256
|
+
cli: 8192 MB (production)
|
|
257
|
+
debug: 1024 MB (minimal)
|
|
258
|
+
test: 3072 MB (moderate)
|
|
259
|
+
|
|
260
|
+
HEAP SIZES BY TOOL TYPE:
|
|
261
|
+
node: 2048 MB
|
|
262
|
+
bun: 3072 MB
|
|
263
|
+
playwright: 4096 MB
|
|
264
|
+
test: 1536 MB
|
|
265
|
+
validator: 1024 MB
|
|
266
|
+
reviewer: 1024 MB
|
|
267
|
+
tester: 1024 MB
|
|
268
|
+
|
|
269
|
+
EXAMPLES:
|
|
270
|
+
# Limit heap for Node.js execution
|
|
271
|
+
limit_node_heap "node" 1024
|
|
272
|
+
node script.js
|
|
273
|
+
|
|
274
|
+
# Execute with automatic heap limiting
|
|
275
|
+
exec_with_heap_limit "bun" "build.ts"
|
|
276
|
+
|
|
277
|
+
# Custom heap size
|
|
278
|
+
exec_with_heap_limit "node" "4096" "heavy-script.js"
|
|
279
|
+
|
|
280
|
+
# Configure manually
|
|
281
|
+
configure_node_options "task" "validator" 1024
|
|
282
|
+
|
|
283
|
+
# Validate current configuration
|
|
284
|
+
validate_heap_configuration
|
|
285
|
+
|
|
286
|
+
EOF
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
# Main execution block
|
|
290
|
+
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
|
|
291
|
+
if [[ "$1" == "--help" || "$1" == "-h" ]]; then
|
|
292
|
+
show_usage
|
|
293
|
+
exit 0
|
|
294
|
+
fi
|
|
295
|
+
|
|
296
|
+
# Execute operation if provided
|
|
297
|
+
if [[ $# -gt 0 ]]; then
|
|
298
|
+
case "$1" in
|
|
299
|
+
"limit")
|
|
300
|
+
shift
|
|
301
|
+
limit_node_heap "$@"
|
|
302
|
+
;;
|
|
303
|
+
"configure")
|
|
304
|
+
shift
|
|
305
|
+
configure_node_options "$@"
|
|
306
|
+
;;
|
|
307
|
+
"validate")
|
|
308
|
+
validate_heap_configuration
|
|
309
|
+
;;
|
|
310
|
+
"exec")
|
|
311
|
+
shift
|
|
312
|
+
exec_with_heap_limit "$@"
|
|
313
|
+
;;
|
|
314
|
+
*)
|
|
315
|
+
echo "Unknown command: $1" >&2
|
|
316
|
+
echo "Use --help for usage information" >&2
|
|
317
|
+
exit 1
|
|
318
|
+
;;
|
|
319
|
+
esac
|
|
320
|
+
else
|
|
321
|
+
echo "CFN Node.js Heap Size Limiter for Task Mode" >&2
|
|
322
|
+
echo "Current mode: $(detect_execution_mode)" >&2
|
|
323
|
+
echo "Current NODE_OPTIONS: ${NODE_OPTIONS:-unset}" >&2
|
|
324
|
+
echo "Use --help for usage information" >&2
|
|
325
|
+
fi
|
|
326
|
+
fi
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
# CFN Process Instrumentation Skill
|
|
2
|
+
|
|
3
|
+
## Purpose
|
|
4
|
+
|
|
5
|
+
Provides comprehensive process instrumentation, monitoring, and automatic resource limiting for CFN Loop agents and orchestration processes. This skill is essential for detecting and preventing memory leaks before they impact system performance.
|
|
6
|
+
|
|
7
|
+
## Core Functions
|
|
8
|
+
|
|
9
|
+
### Process Monitoring
|
|
10
|
+
- Real-time memory usage tracking
|
|
11
|
+
- CPU utilization monitoring
|
|
12
|
+
- File handle and thread tracking
|
|
13
|
+
- Automatic resource limit enforcement
|
|
14
|
+
|
|
15
|
+
### Telemetry Collection
|
|
16
|
+
- Structured metrics collection in JSON format
|
|
17
|
+
- Time-series data for performance analysis
|
|
18
|
+
- Process lifecycle tracking
|
|
19
|
+
- Exit code and duration recording
|
|
20
|
+
|
|
21
|
+
### Resource Limiting
|
|
22
|
+
- Memory limit enforcement with automatic termination
|
|
23
|
+
- CPU usage throttling and monitoring
|
|
24
|
+
- Timeout protection for long-running processes
|
|
25
|
+
- Configurable limits per agent type
|
|
26
|
+
|
|
27
|
+
## Usage Patterns
|
|
28
|
+
|
|
29
|
+
### Automatic Instrumentation
|
|
30
|
+
```bash
|
|
31
|
+
#!/usr/bin/env bash
|
|
32
|
+
|
|
33
|
+
# Source to automatically instrument current process
|
|
34
|
+
source "./cfn-process-instrumentation/instrument-process.sh"
|
|
35
|
+
|
|
36
|
+
# Rest of script runs with monitoring
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### Manual Process Monitoring
|
|
40
|
+
```bash
|
|
41
|
+
# Monitor specific PID
|
|
42
|
+
./cfn-process-instrumentation/instrument-process.sh monitor-pid 12345
|
|
43
|
+
|
|
44
|
+
# Instrument with custom limits
|
|
45
|
+
AGENT_ID="my-agent" CFN_MEMORY_LIMIT="1G" \
|
|
46
|
+
./instrument-process.sh
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Integration in Agent Spawning
|
|
50
|
+
```bash
|
|
51
|
+
#!/usr/bin/env bash
|
|
52
|
+
|
|
53
|
+
# Load instrumentation before spawning agent
|
|
54
|
+
source "./cfn-process-instrumentation/instrument-process.sh"
|
|
55
|
+
|
|
56
|
+
# Spawn agent with monitoring
|
|
57
|
+
npx claude-flow-novice agent "$AGENT_TYPE" \
|
|
58
|
+
--max-memory "$CFN_MEMORY_LIMIT" \
|
|
59
|
+
--timeout "$CFN_TIMEOUT"
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Configuration
|
|
63
|
+
|
|
64
|
+
### Environment Variables
|
|
65
|
+
- `AGENT_ID`: Unique identifier for the agent process
|
|
66
|
+
- `CFN_MEMORY_LIMIT`: Memory limit (default: 2G, formats: 2G, 2048M, etc.)
|
|
67
|
+
- `CFN_CPU_LIMIT`: CPU usage limit as percentage (default: 80%)
|
|
68
|
+
- `CFN_TIMEOUT`: Maximum execution time in seconds (default: 600)
|
|
69
|
+
- `CFN_TELEMETRY_DIR`: Directory for metrics storage (default: /tmp/cfn-telemetry)
|
|
70
|
+
|
|
71
|
+
### Resource Limits
|
|
72
|
+
The skill enforces configurable limits:
|
|
73
|
+
- **Memory**: Prevents OOM conditions with automatic termination
|
|
74
|
+
- **CPU**: Throttles excessive CPU usage
|
|
75
|
+
- **Timeout**: Kills processes that exceed time limits
|
|
76
|
+
- **File Handles**: Monitors for file descriptor leaks
|
|
77
|
+
|
|
78
|
+
## Telemetry Data Structure
|
|
79
|
+
|
|
80
|
+
### Metrics Format
|
|
81
|
+
```json
|
|
82
|
+
{
|
|
83
|
+
"agent_id": "agent-123",
|
|
84
|
+
"start_time": "2025-01-06T10:00:00Z",
|
|
85
|
+
"process_id": "12345",
|
|
86
|
+
"memory_limit": "2G",
|
|
87
|
+
"cpu_limit": "80%",
|
|
88
|
+
"timeout": "600",
|
|
89
|
+
"end_time": "2025-01-06T10:05:00Z",
|
|
90
|
+
"exit_code": "0",
|
|
91
|
+
"samples": [
|
|
92
|
+
{
|
|
93
|
+
"timestamp": "2025-01-06T10:01:00Z",
|
|
94
|
+
"memory_kb": "102400",
|
|
95
|
+
"cpu_percent": "15.5",
|
|
96
|
+
"open_files": "45",
|
|
97
|
+
"threads": "8"
|
|
98
|
+
}
|
|
99
|
+
]
|
|
100
|
+
}
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### Collected Metrics
|
|
104
|
+
- **Memory Usage**: RSS memory in kilobytes
|
|
105
|
+
- **CPU Usage**: Percentage of CPU utilization
|
|
106
|
+
- **Open Files**: Number of open file descriptors
|
|
107
|
+
- **Threads**: Number of active threads
|
|
108
|
+
- **Timestamp**: ISO 8601 formatted time
|
|
109
|
+
|
|
110
|
+
## Integration Points
|
|
111
|
+
|
|
112
|
+
### Orchestration Scripts
|
|
113
|
+
```bash
|
|
114
|
+
#!/usr/bin/env bash
|
|
115
|
+
|
|
116
|
+
# Load instrumentation for orchestrator
|
|
117
|
+
source "./cfn-process-instrumentation/instrument-process.sh"
|
|
118
|
+
|
|
119
|
+
# Orchestrator runs with monitoring
|
|
120
|
+
echo "Starting orchestration with process monitoring"
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### Agent Templates
|
|
124
|
+
```bash
|
|
125
|
+
#!/usr/bin/env bash
|
|
126
|
+
|
|
127
|
+
# All agents get automatic instrumentation
|
|
128
|
+
source "./cfn-process-instrumentation/instrument-process.sh"
|
|
129
|
+
|
|
130
|
+
# Agent execution code
|
|
131
|
+
echo "Agent execution monitored and resource-limited"
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
### CFN Loop Integration
|
|
135
|
+
- **Loop 1**: Orchestration process monitoring
|
|
136
|
+
- **Loop 2**: Validator process tracking
|
|
137
|
+
- **Loop 3**: Implementation agent monitoring
|
|
138
|
+
- **Loop 4**: Product Owner process tracking
|
|
139
|
+
|
|
140
|
+
## Safety Features
|
|
141
|
+
|
|
142
|
+
### Graceful Shutdown
|
|
143
|
+
- SIGTERM sent before SIGKILL
|
|
144
|
+
- Cleanup traps for proper resource release
|
|
145
|
+
- Final report generation on exit
|
|
146
|
+
|
|
147
|
+
### Error Handling
|
|
148
|
+
- Missing tools handled gracefully
|
|
149
|
+
- Fallback behavior when utilities unavailable
|
|
150
|
+
- Comprehensive error logging
|
|
151
|
+
|
|
152
|
+
### Resource Protection
|
|
153
|
+
- Automatic termination on limit violation
|
|
154
|
+
- Background monitoring with minimal overhead
|
|
155
|
+
- Process group management for cleanup
|
|
156
|
+
|
|
157
|
+
## Performance Considerations
|
|
158
|
+
|
|
159
|
+
### Monitoring Overhead
|
|
160
|
+
- Minimal impact on agent performance (<1% CPU)
|
|
161
|
+
- Efficient metric collection with native tools
|
|
162
|
+
- Configurable monitoring intervals (default: 30s)
|
|
163
|
+
|
|
164
|
+
### Storage Efficiency
|
|
165
|
+
- JSON metrics with compact storage
|
|
166
|
+
- Automatic cleanup of old telemetry files
|
|
167
|
+
- Configurable retention policies
|
|
168
|
+
|
|
169
|
+
### Network Independence
|
|
170
|
+
- No external dependencies for monitoring
|
|
171
|
+
- Local process inspection only
|
|
172
|
+
- Works in isolated environments
|
|
173
|
+
|
|
174
|
+
## Usage Examples
|
|
175
|
+
|
|
176
|
+
### Basic Agent Monitoring
|
|
177
|
+
```bash
|
|
178
|
+
#!/usr/bin/env bash
|
|
179
|
+
|
|
180
|
+
# Simple agent with monitoring
|
|
181
|
+
source "./cfn-process-instrumentation/instrument-process.sh"
|
|
182
|
+
|
|
183
|
+
# Agent work here
|
|
184
|
+
echo "Performing agent tasks..."
|
|
185
|
+
|
|
186
|
+
# Monitoring and cleanup automatic
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
### Custom Resource Limits
|
|
190
|
+
```bash
|
|
191
|
+
#!/usr/bin/env bash
|
|
192
|
+
|
|
193
|
+
# Agent with custom limits
|
|
194
|
+
export CFN_MEMORY_LIMIT="1G"
|
|
195
|
+
export CFN_CPU_LIMIT="60%"
|
|
196
|
+
export CFN_TIMEOUT="300"
|
|
197
|
+
|
|
198
|
+
source "./cfn-process-instrumentation/instrument-process.sh"
|
|
199
|
+
|
|
200
|
+
# Agent runs with stricter limits
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
### Background Process Monitoring
|
|
204
|
+
```bash
|
|
205
|
+
#!/usr/bin/env bash
|
|
206
|
+
|
|
207
|
+
# Start long-running process
|
|
208
|
+
./long-running-task &
|
|
209
|
+
TASK_PID=$!
|
|
210
|
+
|
|
211
|
+
# Monitor the background process
|
|
212
|
+
./cfn-process-instrumentation/instrument-process.sh monitor-pid $TASK_PID
|
|
213
|
+
|
|
214
|
+
# Wait for completion
|
|
215
|
+
wait $TASK_PID
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
## Monitoring and Alerting
|
|
219
|
+
|
|
220
|
+
### Threshold Alerts
|
|
221
|
+
- Memory usage approaching limits
|
|
222
|
+
- CPU usage sustained at high levels
|
|
223
|
+
- File descriptor count growing unexpectedly
|
|
224
|
+
- Process hanging without activity
|
|
225
|
+
|
|
226
|
+
### Telemetry Analysis
|
|
227
|
+
```bash
|
|
228
|
+
# Analyze metrics for trends
|
|
229
|
+
jq '.samples | map(.memory_kb) | add / length' /tmp/cfn-telemetry/metrics_*.json
|
|
230
|
+
|
|
231
|
+
# Find processes with high memory usage
|
|
232
|
+
find /tmp/cfn-telemetry -name "*.json" -exec jq 'if (.samples | length) > 0 then (.samples[-1].memory_kb | tonumber) else 0 end' {} \;
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
### Integration with Monitoring Systems
|
|
236
|
+
- JSON metrics compatible with log aggregators
|
|
237
|
+
- Time-series data for graphing tools
|
|
238
|
+
- Structured alerts for DevOps monitoring
|
|
239
|
+
|
|
240
|
+
## Troubleshooting
|
|
241
|
+
|
|
242
|
+
### Common Issues
|
|
243
|
+
1. **High monitoring overhead**: Increase monitoring interval
|
|
244
|
+
2. **Missing tools**: Install ps, lsof, jq for full functionality
|
|
245
|
+
3. **Permission denied**: Check file system permissions for telemetry directory
|
|
246
|
+
4. **Process termination**: Review and adjust resource limits
|
|
247
|
+
|
|
248
|
+
### Debug Mode
|
|
249
|
+
```bash
|
|
250
|
+
# Enable detailed logging
|
|
251
|
+
export CFN_DEBUG=1
|
|
252
|
+
source "./cfn-process-instrumentation/instrument-process.sh"
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
### Manual Inspection
|
|
256
|
+
```bash
|
|
257
|
+
# Check current metrics
|
|
258
|
+
cat /tmp/cfn-telemetry/metrics_*.json | jq .
|
|
259
|
+
|
|
260
|
+
# Monitor process manually
|
|
261
|
+
ps -p $$ -o pid,rss,pcpu,nlwp,fd
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
## Security Considerations
|
|
265
|
+
|
|
266
|
+
### Data Protection
|
|
267
|
+
- Telemetry stored in local filesystem only
|
|
268
|
+
- No network transmission of metrics
|
|
269
|
+
- Configurable storage location
|
|
270
|
+
|
|
271
|
+
### Process Isolation
|
|
272
|
+
- Each agent tracked independently
|
|
273
|
+
- No cross-agent data sharing
|
|
274
|
+
- Clean separation of metrics
|
|
275
|
+
|
|
276
|
+
### Access Control
|
|
277
|
+
- File permissions restricted to agent user
|
|
278
|
+
- No privileged operations required
|
|
279
|
+
- Safe execution in untrusted environments
|