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,200 @@
|
|
|
1
|
+
# CFN Environment Sanitization Skill
|
|
2
|
+
|
|
3
|
+
## Purpose
|
|
4
|
+
|
|
5
|
+
Automatically sanitizes environment variables and enforces resource limits to prevent memory leaks in CFN Loop orchestration workflows. This is a critical component of the ANTI-023 memory leak protection system.
|
|
6
|
+
|
|
7
|
+
## Core Functions
|
|
8
|
+
|
|
9
|
+
### Environment Sanitization
|
|
10
|
+
- Removes or redacts sensitive environment variables
|
|
11
|
+
- Enforces memory limits for Node.js processes
|
|
12
|
+
- Sets CFN-specific configuration limits
|
|
13
|
+
- Preserves critical coordination variables
|
|
14
|
+
|
|
15
|
+
### Resource Limit Enforcement
|
|
16
|
+
- Node.js heap size: 2GB max
|
|
17
|
+
- Maximum agents: 10 concurrent
|
|
18
|
+
- Operation timeout: 600 seconds
|
|
19
|
+
- Memory limits: 2GB per process
|
|
20
|
+
|
|
21
|
+
### Sensitive Data Protection
|
|
22
|
+
- Detects and redacts passwords, secrets, tokens
|
|
23
|
+
- Validates environment for exposed credentials
|
|
24
|
+
- Prevents sensitive data leakage in logs
|
|
25
|
+
|
|
26
|
+
## Usage Patterns
|
|
27
|
+
|
|
28
|
+
### Integration in Orchestration Scripts
|
|
29
|
+
```bash
|
|
30
|
+
#!/usr/bin/env bash
|
|
31
|
+
|
|
32
|
+
# Load sanitization at script start
|
|
33
|
+
source "$(dirname "$0")/../cfn-environment-sanitization/sanitize-environment.sh"
|
|
34
|
+
|
|
35
|
+
# Rest of orchestration logic...
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### Standalone Validation
|
|
39
|
+
```bash
|
|
40
|
+
# Check current environment state
|
|
41
|
+
./cfn-environment-sanitization/sanitize-environment.sh check
|
|
42
|
+
|
|
43
|
+
# Apply strict sanitization
|
|
44
|
+
./cfn-environment-sanitization/sanitize-environment.sh --strict
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### CFN Loop Integration Points
|
|
48
|
+
- **Orchestration Scripts**: Apply before agent spawning
|
|
49
|
+
- **Agent Spawning**: Enforce limits during process creation
|
|
50
|
+
- **Validation Scripts**: Check environment before operations
|
|
51
|
+
- **Cleanup Scripts**: Sanitize before process exit
|
|
52
|
+
|
|
53
|
+
## Configuration
|
|
54
|
+
|
|
55
|
+
### Environment Variables
|
|
56
|
+
- `CFN_MAX_AGENTS`: Maximum concurrent agents (default: 10)
|
|
57
|
+
- `CFN_TIMEOUT`: Operation timeout in seconds (default: 600)
|
|
58
|
+
- `CFN_MEMORY_LIMIT`: Memory limit per process (default: 2GB)
|
|
59
|
+
- `CFN_MODE`: Execution mode preservation
|
|
60
|
+
- `NODE_OPTIONS`: Node.js runtime options with memory limits
|
|
61
|
+
|
|
62
|
+
### Sanitization Rules
|
|
63
|
+
The script uses a rule-based system for variable handling:
|
|
64
|
+
- `sanitize`: Remove the variable
|
|
65
|
+
- `sanitize_if_sensitive`: Remove if contains sensitive data
|
|
66
|
+
- `preserve`: Keep the variable unchanged
|
|
67
|
+
- `enforce_*`: Set to specific limit value
|
|
68
|
+
|
|
69
|
+
## Safety Features
|
|
70
|
+
|
|
71
|
+
### Strict Mode
|
|
72
|
+
When enabled (`--strict` flag):
|
|
73
|
+
- Validates required CLI mode variables
|
|
74
|
+
- Enforces additional security checks
|
|
75
|
+
- Prevents execution without proper configuration
|
|
76
|
+
|
|
77
|
+
### Environment Validation
|
|
78
|
+
- Detects sensitive data exposure
|
|
79
|
+
- Validates memory limit configuration
|
|
80
|
+
- Checks CFN coordination variables
|
|
81
|
+
|
|
82
|
+
### Automatic Protection
|
|
83
|
+
- Applies sanitization automatically when sourced
|
|
84
|
+
- Preserves critical coordination variables
|
|
85
|
+
- Enforces limits without manual configuration
|
|
86
|
+
|
|
87
|
+
## Integration Requirements
|
|
88
|
+
|
|
89
|
+
### Prerequisites
|
|
90
|
+
- Bash 4.0+ for associative arrays
|
|
91
|
+
- Standard Unix tools (grep, cut, sed)
|
|
92
|
+
- Node.js environment for memory limits
|
|
93
|
+
|
|
94
|
+
### Dependencies
|
|
95
|
+
- CFN Mode Detection skill for coordination
|
|
96
|
+
- CFN Redis Coordination for state management
|
|
97
|
+
- CFN Agent Spawning for process creation
|
|
98
|
+
|
|
99
|
+
## Usage Examples
|
|
100
|
+
|
|
101
|
+
### Orchestration Script Integration
|
|
102
|
+
```bash
|
|
103
|
+
#!/usr/bin/env bash
|
|
104
|
+
|
|
105
|
+
# Load environment sanitization
|
|
106
|
+
source "$(dirname "$0")/../cfn-environment-sanitization/sanitize-environment.sh"
|
|
107
|
+
|
|
108
|
+
# Now safe to proceed with orchestration
|
|
109
|
+
echo "Environment sanitized, starting orchestration..."
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### Agent Spawning with Limits
|
|
113
|
+
```bash
|
|
114
|
+
#!/usr/bin/env bash
|
|
115
|
+
|
|
116
|
+
# Ensure sanitized environment
|
|
117
|
+
source "./cfn-environment-sanitization/sanitize-environment.sh" --strict
|
|
118
|
+
|
|
119
|
+
# Spawn agent with enforced limits
|
|
120
|
+
npx claude-flow-novice agent "$AGENT_TYPE" \
|
|
121
|
+
--max-memory "$CFN_MEMORY_LIMIT" \
|
|
122
|
+
--timeout "$CFN_TIMEOUT"
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### Environment Validation
|
|
126
|
+
```bash
|
|
127
|
+
# Pre-execution validation
|
|
128
|
+
if ! ./cfn-environment-sanitization/sanitize-environment.sh check; then
|
|
129
|
+
echo "Environment validation failed" >&2
|
|
130
|
+
exit 1
|
|
131
|
+
fi
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
## Testing
|
|
135
|
+
|
|
136
|
+
### Unit Tests
|
|
137
|
+
```bash
|
|
138
|
+
# Test sanitization rules
|
|
139
|
+
./tests/test-environment-sanitization.sh
|
|
140
|
+
|
|
141
|
+
# Test sensitive data detection
|
|
142
|
+
./tests/test-sensitive-data-redaction.sh
|
|
143
|
+
|
|
144
|
+
# Test memory limit enforcement
|
|
145
|
+
./tests/test-memory-limits.sh
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### Integration Tests
|
|
149
|
+
```bash
|
|
150
|
+
# Test with orchestration script
|
|
151
|
+
./tests/test-orchestration-integration.sh
|
|
152
|
+
|
|
153
|
+
# Test with agent spawning
|
|
154
|
+
./tests/test-agent-spawning-integration.sh
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
## Troubleshooting
|
|
158
|
+
|
|
159
|
+
### Common Issues
|
|
160
|
+
1. **Missing required variables**: Use strict mode to validate
|
|
161
|
+
2. **Memory limits not applied**: Check Node.js options
|
|
162
|
+
3. **Sensitive data leakage**: Run environment check
|
|
163
|
+
4. **Agent spawning failures**: Verify resource limits
|
|
164
|
+
|
|
165
|
+
### Debug Mode
|
|
166
|
+
```bash
|
|
167
|
+
# Enable debug output
|
|
168
|
+
export CFN_DEBUG=1
|
|
169
|
+
./sanitize-environment.sh --strict
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
## Monitoring and Telemetry
|
|
173
|
+
|
|
174
|
+
### Metrics Collected
|
|
175
|
+
- Environment sanitization changes
|
|
176
|
+
- Resource limit violations
|
|
177
|
+
- Sensitive data detections
|
|
178
|
+
- Memory usage patterns
|
|
179
|
+
|
|
180
|
+
### Log Integration
|
|
181
|
+
- Structured logging with severity levels
|
|
182
|
+
- Integration with CFN logging system
|
|
183
|
+
- Audit trail for security compliance
|
|
184
|
+
|
|
185
|
+
## Security Considerations
|
|
186
|
+
|
|
187
|
+
### Data Protection
|
|
188
|
+
- Automatic redaction of sensitive data
|
|
189
|
+
- Prevention of credential exposure
|
|
190
|
+
- Secure environment variable handling
|
|
191
|
+
|
|
192
|
+
### Resource Protection
|
|
193
|
+
- Memory limit enforcement prevents OOM
|
|
194
|
+
- Timeout protection prevents hanging
|
|
195
|
+
- Agent count limits prevent resource exhaustion
|
|
196
|
+
|
|
197
|
+
### Compliance
|
|
198
|
+
- Audit logging for security reviews
|
|
199
|
+
- Environment state validation
|
|
200
|
+
- Secure by default configuration
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
|
|
3
|
+
##############################################################################
|
|
4
|
+
# CFN Environment Sanitization
|
|
5
|
+
# Part of ANTI-023 Memory Leak Protection System
|
|
6
|
+
#
|
|
7
|
+
# Automatically sanitizes environment variables and prevents memory leaks
|
|
8
|
+
# in CFN Loop orchestration workflows.
|
|
9
|
+
#
|
|
10
|
+
# Usage:
|
|
11
|
+
# source ./sanitize-environment.sh [--strict]
|
|
12
|
+
# ./sanitize-environment.sh --check
|
|
13
|
+
##############################################################################
|
|
14
|
+
|
|
15
|
+
set -euo pipefail
|
|
16
|
+
|
|
17
|
+
# Configuration
|
|
18
|
+
STRICT_MODE=${1:-"false"}
|
|
19
|
+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
20
|
+
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
|
|
21
|
+
|
|
22
|
+
# Environment sanitization rules
|
|
23
|
+
declare -A SANITIZATION_RULES=(
|
|
24
|
+
# Clear potentially problematic variables
|
|
25
|
+
["NODE_OPTIONS"]="sanitize"
|
|
26
|
+
["UV_THREADPOOL_SIZE"]="sanitize"
|
|
27
|
+
["REDIS_URL"]="sanitize_if_sensitive"
|
|
28
|
+
|
|
29
|
+
# Preserve critical CFN variables
|
|
30
|
+
["CFN_MODE"]="preserve"
|
|
31
|
+
["TASK_ID"]="preserve"
|
|
32
|
+
["AGENT_ID"]="preserve"
|
|
33
|
+
["LOOP3_AGENTS"]="preserve"
|
|
34
|
+
["LOOP2_AGENTS"]="preserve"
|
|
35
|
+
["PRODUCT_OWNER"]="preserve"
|
|
36
|
+
|
|
37
|
+
# Memory and process limits
|
|
38
|
+
["NODE_HEAP_LIMIT"]="enforce_2gb"
|
|
39
|
+
["MAX_AGENTS"]="enforce_10"
|
|
40
|
+
["CFN_TIMEOUT"]="enforce_600"
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
# Sensitive patterns to redact
|
|
44
|
+
SENSITIVE_PATTERNS=(
|
|
45
|
+
"password="
|
|
46
|
+
"secret="
|
|
47
|
+
"token="
|
|
48
|
+
"key="
|
|
49
|
+
"auth="
|
|
50
|
+
"credential="
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
# Color coding for output
|
|
54
|
+
readonly RED='\033[0;31m'
|
|
55
|
+
readonly GREEN='\033[0;32m'
|
|
56
|
+
readonly YELLOW='\033[1;33m'
|
|
57
|
+
readonly BLUE='\033[0;34m'
|
|
58
|
+
readonly NC='\033[0m' # No Color
|
|
59
|
+
|
|
60
|
+
# Logging functions
|
|
61
|
+
log_info() {
|
|
62
|
+
echo -e "${BLUE}[SANITIZE]${NC} $1" >&2
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
log_success() {
|
|
66
|
+
echo -e "${GREEN}[SANITIZE]${NC} $1" >&2
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
log_warning() {
|
|
70
|
+
echo -e "${YELLOW}[SANITIZE]${NC} $1" >&2
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
log_error() {
|
|
74
|
+
echo -e "${RED}[SANITIZE]${NC} $1" >&2
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
# Check if value contains sensitive information
|
|
78
|
+
is_sensitive() {
|
|
79
|
+
local value="$1"
|
|
80
|
+
for pattern in "${SENSITIVE_PATTERNS[@]}"; do
|
|
81
|
+
if [[ "$value" =~ $pattern ]]; then
|
|
82
|
+
return 0
|
|
83
|
+
fi
|
|
84
|
+
done
|
|
85
|
+
return 1
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
# Sanitize environment variable
|
|
89
|
+
sanitize_var() {
|
|
90
|
+
local var_name="$1"
|
|
91
|
+
local var_value="${!var_name:-}"
|
|
92
|
+
local rule="${SANITIZATION_RULES[$var_name]:-"preserve"}"
|
|
93
|
+
|
|
94
|
+
case "$rule" in
|
|
95
|
+
"sanitize")
|
|
96
|
+
if [[ -n "$var_value" ]]; then
|
|
97
|
+
log_info "Sanitizing $var_name"
|
|
98
|
+
unset "$var_name"
|
|
99
|
+
fi
|
|
100
|
+
;;
|
|
101
|
+
"sanitize_if_sensitive")
|
|
102
|
+
if is_sensitive "$var_value"; then
|
|
103
|
+
log_warning "Redacting sensitive $var_name"
|
|
104
|
+
unset "$var_name"
|
|
105
|
+
fi
|
|
106
|
+
;;
|
|
107
|
+
"preserve")
|
|
108
|
+
# Keep the variable as-is
|
|
109
|
+
;;
|
|
110
|
+
"enforce_2gb")
|
|
111
|
+
export "$var_name"="${var_value:-2048}"
|
|
112
|
+
log_info "Enforcing 2GB heap limit: $var_name=${!var_name}"
|
|
113
|
+
;;
|
|
114
|
+
"enforce_10")
|
|
115
|
+
export "$var_name"="${var_value:-10}"
|
|
116
|
+
log_info "Enforcing max 10 agents: $var_name=${!var_value}"
|
|
117
|
+
;;
|
|
118
|
+
"enforce_600")
|
|
119
|
+
export "$var_name"="${var_value:-600}"
|
|
120
|
+
log_info "Enforcing 600s timeout: $var_name=${!var_value}"
|
|
121
|
+
;;
|
|
122
|
+
esac
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
# Apply environment sanitization
|
|
126
|
+
sanitize_environment() {
|
|
127
|
+
log_info "Starting environment sanitization..."
|
|
128
|
+
|
|
129
|
+
# Count changes for reporting
|
|
130
|
+
local changes=0
|
|
131
|
+
|
|
132
|
+
for var_name in "${!SANITIZATION_RULES[@]}"; do
|
|
133
|
+
local old_value="${!var_name:-}"
|
|
134
|
+
sanitize_var "$var_name"
|
|
135
|
+
local new_value="${!var_name:-}"
|
|
136
|
+
|
|
137
|
+
if [[ "$old_value" != "$new_value" ]]; then
|
|
138
|
+
((changes++))
|
|
139
|
+
fi
|
|
140
|
+
done
|
|
141
|
+
|
|
142
|
+
# Enforce memory limits for Node.js processes
|
|
143
|
+
export NODE_OPTIONS="--max-old-space-size=2048 --max-new-space-size=512 ${NODE_OPTIONS:-}"
|
|
144
|
+
|
|
145
|
+
# Set CFN-specific limits
|
|
146
|
+
export CFN_MAX_AGENTS="${CFN_MAX_AGENTS:-10}"
|
|
147
|
+
export CFN_TIMEOUT="${CFN_TIMEOUT:-600}"
|
|
148
|
+
export CFN_MEMORY_LIMIT="${CFN_MEMORY_LIMIT:-2GB}"
|
|
149
|
+
|
|
150
|
+
log_success "Environment sanitization complete ($changes changes applied)"
|
|
151
|
+
|
|
152
|
+
if [[ "$STRICT_MODE" == "true" ]]; then
|
|
153
|
+
log_info "Strict mode enabled - additional validations applied"
|
|
154
|
+
|
|
155
|
+
# Validate critical variables are set in CLI mode
|
|
156
|
+
if [[ -n "${TASK_ID:-}" ]]; then
|
|
157
|
+
for required_var in AGENT_ID LOOP3_AGENTS; do
|
|
158
|
+
if [[ -z "${!required_var:-}" ]]; then
|
|
159
|
+
log_error "Required variable $required_var not set in CLI mode"
|
|
160
|
+
return 1
|
|
161
|
+
fi
|
|
162
|
+
done
|
|
163
|
+
fi
|
|
164
|
+
fi
|
|
165
|
+
|
|
166
|
+
return 0
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
# Check current environment state
|
|
170
|
+
check_environment() {
|
|
171
|
+
log_info "Checking environment state..."
|
|
172
|
+
|
|
173
|
+
local issues=0
|
|
174
|
+
|
|
175
|
+
# Check for sensitive data exposure
|
|
176
|
+
for var_name in $(env | grep -E "(password|secret|token|key|auth|credential)" | cut -d= -f1); do
|
|
177
|
+
log_warning "Potential sensitive data in $var_name"
|
|
178
|
+
((issues++))
|
|
179
|
+
done
|
|
180
|
+
|
|
181
|
+
# Check Node.js memory settings
|
|
182
|
+
if [[ -n "${NODE_OPTIONS:-}" && ! "$NODE_OPTIONS" =~ "max-old-space-size" ]]; then
|
|
183
|
+
log_warning "NODE_OPTIONS missing heap limit"
|
|
184
|
+
((issues++))
|
|
185
|
+
fi
|
|
186
|
+
|
|
187
|
+
# Check CFN configuration
|
|
188
|
+
if [[ -z "${CFN_MAX_AGENTS:-}" ]]; then
|
|
189
|
+
log_warning "CFN_MAX_AGENTS not set"
|
|
190
|
+
((issues++))
|
|
191
|
+
fi
|
|
192
|
+
|
|
193
|
+
if [[ $issues -eq 0 ]]; then
|
|
194
|
+
log_success "Environment check passed"
|
|
195
|
+
return 0
|
|
196
|
+
else
|
|
197
|
+
log_error "Environment check failed ($issues issues found)"
|
|
198
|
+
return 1
|
|
199
|
+
fi
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
# Main execution
|
|
203
|
+
main() {
|
|
204
|
+
local action="${1:-"sanitize"}"
|
|
205
|
+
|
|
206
|
+
case "$action" in
|
|
207
|
+
"sanitize")
|
|
208
|
+
sanitize_environment
|
|
209
|
+
;;
|
|
210
|
+
"check")
|
|
211
|
+
check_environment
|
|
212
|
+
;;
|
|
213
|
+
"--strict")
|
|
214
|
+
STRICT_MODE="true"
|
|
215
|
+
sanitize_environment
|
|
216
|
+
;;
|
|
217
|
+
"--help"|"-h")
|
|
218
|
+
cat << EOF
|
|
219
|
+
CFN Environment Sanitization Script
|
|
220
|
+
|
|
221
|
+
Usage:
|
|
222
|
+
$0 # Apply standard sanitization
|
|
223
|
+
$0 --strict # Apply strict sanitization
|
|
224
|
+
$0 check # Check environment state
|
|
225
|
+
$0 --help # Show this help
|
|
226
|
+
|
|
227
|
+
This script sanitizes the environment to prevent memory leaks and
|
|
228
|
+
ensure secure CFN Loop execution.
|
|
229
|
+
EOF
|
|
230
|
+
;;
|
|
231
|
+
*)
|
|
232
|
+
log_error "Unknown action: $action"
|
|
233
|
+
return 1
|
|
234
|
+
;;
|
|
235
|
+
esac
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
# Execute main function if run directly
|
|
239
|
+
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
|
|
240
|
+
main "$@"
|
|
241
|
+
else
|
|
242
|
+
# When sourced, automatically apply sanitization
|
|
243
|
+
sanitize_environment
|
|
244
|
+
fi
|
|
@@ -21,6 +21,10 @@
|
|
|
21
21
|
|
|
22
22
|
set -euo pipefail
|
|
23
23
|
|
|
24
|
+
# Determine PROJECT_ROOT first before any other operations
|
|
25
|
+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
26
|
+
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
|
|
27
|
+
|
|
24
28
|
# ⚠️ ANTI-023 MEMORY LEAK PROTECTION: Block Task Mode agents
|
|
25
29
|
# Task Mode agents spawn via Task() tool and should NOT use orchestration scripts
|
|
26
30
|
if [[ -z "${TASK_ID:-}" || -z "${LOOP3_AGENTS:-}" ]]; then
|
|
@@ -31,14 +35,39 @@ if [[ -z "${TASK_ID:-}" || -z "${LOOP3_AGENTS:-}" ]]; then
|
|
|
31
35
|
exit 1
|
|
32
36
|
fi
|
|
33
37
|
|
|
38
|
+
# ⚠️ ANTI-023 MEMORY LEAK PROTECTION: Environment Sanitization
|
|
39
|
+
# Load and apply environment sanitization to prevent memory leaks
|
|
40
|
+
if [[ -f "$PROJECT_ROOT/.claude/skills/cfn-task-mode-sanitize/task-mode-env-sanitizer.sh" ]]; then
|
|
41
|
+
source "$PROJECT_ROOT/.claude/skills/cfn-task-mode-sanitize/task-mode-env-sanitizer.sh"
|
|
42
|
+
sanitize_task_mode_environment "cli"
|
|
43
|
+
echo "✅ Environment sanitization applied" >&2
|
|
44
|
+
else
|
|
45
|
+
echo "⚠️ Environment sanitization not available - proceeding without protection" >&2
|
|
46
|
+
fi
|
|
47
|
+
|
|
48
|
+
# ⚠️ ANTI-023 MEMORY LEAK PROTECTION: Process Instrumentation
|
|
49
|
+
# Load process instrumentation and monitoring for the orchestrator
|
|
50
|
+
if [[ -f "$PROJECT_ROOT/.claude/skills/cfn-validation-runner-instrumentation/wrapped-executor.sh" ]]; then
|
|
51
|
+
source "$PROJECT_ROOT/.claude/skills/cfn-validation-runner-instrumentation/wrapped-executor.sh"
|
|
52
|
+
echo "✅ Orchestrator process instrumentation enabled" >&2
|
|
53
|
+
else
|
|
54
|
+
echo "⚠️ Process instrumentation not available - proceeding without monitoring" >&2
|
|
55
|
+
fi
|
|
56
|
+
|
|
57
|
+
# ⚠️ ANTI-023 MEMORY LEAK PROTECTION: Environment Configuration
|
|
58
|
+
# Set stabilization environment variables with sensible defaults
|
|
59
|
+
export CFN_VALIDATION_TIMEOUT="${CFN_VALIDATION_TIMEOUT:-300}" # 5 minutes
|
|
60
|
+
export CFN_MEMORY_LIMIT="${CFN_MEMORY_LIMIT:-2048}" # 2GB memory limit
|
|
61
|
+
export CFN_CPU_LIMIT="${CFN_CPU_LIMIT:-80}" # 80% CPU limit
|
|
62
|
+
export CFN_TELEMETRY_DIR="${CFN_TELEMETRY_DIR:-$PROJECT_ROOT/.artifacts/telemetry}"
|
|
63
|
+
mkdir -p "$CFN_TELEMETRY_DIR"
|
|
64
|
+
|
|
34
65
|
# Load security utilities
|
|
35
66
|
# shellcheck source=./security_utils.sh
|
|
36
67
|
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/security_utils.sh"
|
|
37
68
|
|
|
38
|
-
# Determine script directory
|
|
39
|
-
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
40
69
|
HELPERS_DIR="$SCRIPT_DIR/helpers"
|
|
41
|
-
|
|
70
|
+
REDIS_COORD_SKILL="$PROJECT_ROOT/.claude/skills/cfn-redis-coordination"
|
|
42
71
|
|
|
43
72
|
# Configuration
|
|
44
73
|
TASK_ID=""
|
|
@@ -250,6 +279,16 @@ if [ -z "$TASK_ID" ] || [ -z "$LOOP3_AGENTS" ] || [ -z "$LOOP2_AGENTS" ] || [ -z
|
|
|
250
279
|
exit 1
|
|
251
280
|
fi
|
|
252
281
|
|
|
282
|
+
# ⚠️ ANTI-023 MEMORY LEAK PROTECTION: Process Instrumentation
|
|
283
|
+
# Load process instrumentation and monitoring for the orchestrator
|
|
284
|
+
# shellcheck source=../cfn-process-instrumentation/instrument-process.sh
|
|
285
|
+
if [[ -f "$PROJECT_ROOT/.claude/skills/cfn-process-instrumentation/instrument-process.sh" ]]; then
|
|
286
|
+
source "$PROJECT_ROOT/.claude/skills/cfn-process-instrumentation/instrument-process.sh"
|
|
287
|
+
echo "✅ Orchestrator process instrumentation enabled" >&2
|
|
288
|
+
else
|
|
289
|
+
echo "⚠️ Process instrumentation not available - proceeding without monitoring" >&2
|
|
290
|
+
fi
|
|
291
|
+
|
|
253
292
|
# Get thresholds for mode
|
|
254
293
|
# Add additional mode validation with safe fallback
|
|
255
294
|
case "$MODE" in
|
|
@@ -435,12 +474,22 @@ function spawn_loop3_agents() {
|
|
|
435
474
|
safe_task_id=$(sanitize_input "$task_id") || continue
|
|
436
475
|
safe_agent_id=$(sanitize_input "$UNIQUE_AGENT_ID") || continue
|
|
437
476
|
|
|
438
|
-
# Spawn agent in background with
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
477
|
+
# Spawn agent in background with process instrumentation and memory limits
|
|
478
|
+
if command -v execute_instrumented >/dev/null 2>&1; then
|
|
479
|
+
execute_instrumented "npx" "$CFN_VALIDATION_TIMEOUT" "$CFN_MEMORY_LIMIT" \
|
|
480
|
+
claude-flow-novice agent "$safe_agent_type" \
|
|
481
|
+
--task-id "$safe_task_id" \
|
|
482
|
+
--agent-id "$safe_agent_id" \
|
|
483
|
+
--iteration "$iteration" \
|
|
484
|
+
--context "$(build_agent_context "$safe_task_id" "$iteration" "$safe_agent_type" "" "loop3")" &
|
|
485
|
+
else
|
|
486
|
+
# Fallback to raw spawn if instrumentation unavailable
|
|
487
|
+
npx claude-flow-novice agent "$safe_agent_type" \
|
|
488
|
+
--task-id "$safe_task_id" \
|
|
489
|
+
--agent-id "$safe_agent_id" \
|
|
490
|
+
--iteration "$iteration" \
|
|
491
|
+
--context "$(build_agent_context "$safe_task_id" "$iteration" "$safe_agent_type" "" "loop3")" &
|
|
492
|
+
fi
|
|
444
493
|
|
|
445
494
|
# Store PID for monitoring using unique agent ID
|
|
446
495
|
AGENT_PID=$!
|
|
@@ -450,6 +499,17 @@ function spawn_loop3_agents() {
|
|
|
450
499
|
--value "{\"pid\": $AGENT_PID}" \
|
|
451
500
|
--namespace "swarm" >/dev/null
|
|
452
501
|
|
|
502
|
+
# ⚠️ ANTI-023 MEMORY LEAK PROTECTION: Start telemetry monitoring
|
|
503
|
+
if [[ -f "$PROJECT_ROOT/.claude/skills/cfn-telemetry/collect-metrics.sh" ]]; then
|
|
504
|
+
MONITOR_PID=$("$PROJECT_ROOT/.claude/skills/cfn-telemetry/collect-metrics.sh" start-monitoring "$UNIQUE_AGENT_ID" "$AGENT_PID" "$iteration" "$safe_agent_type")
|
|
505
|
+
"$REDIS_COORD_SKILL/store-context.sh" \
|
|
506
|
+
--task-id "$task_id" \
|
|
507
|
+
--key "${UNIQUE_AGENT_ID}:monitor_pid" \
|
|
508
|
+
--value "{\"pid\": $MONITOR_PID}" \
|
|
509
|
+
--namespace "swarm" >/dev/null
|
|
510
|
+
echo "🔍 Started monitoring for $UNIQUE_AGENT_ID (Agent PID: $AGENT_PID, Monitor PID: $MONITOR_PID)" >&2
|
|
511
|
+
fi
|
|
512
|
+
|
|
453
513
|
# Store agent ID mapping for later retrieval using Redis SADD for set storage
|
|
454
514
|
redis-cli SADD "swarm:${task_id}:loop3:agent_ids:iteration${iteration}" "$UNIQUE_AGENT_ID" >/dev/null
|
|
455
515
|
done
|
|
@@ -524,6 +584,16 @@ function wait_for_agents() {
|
|
|
524
584
|
wait "$pid" 2>/dev/null || true
|
|
525
585
|
done
|
|
526
586
|
|
|
587
|
+
# ⚠️ ANTI-023 MEMORY LEAK PROTECTION: Stop monitoring for all agents
|
|
588
|
+
echo " Stopping telemetry monitoring for Loop 3 agents..." >&2
|
|
589
|
+
for unique_agent_id in "${AGENT_IDS[@]}"; do
|
|
590
|
+
local monitor_pid=$("$REDIS_COORD_SKILL/get-context.sh" --task-id "$task_id" --key "${unique_agent_id}:monitor_pid" --namespace "swarm" 2>/dev/null | jq -r '.pid // 0' || echo "0")
|
|
591
|
+
if [[ "$monitor_pid" -gt 0 ]] && kill -0 "$monitor_pid" 2>/dev/null; then
|
|
592
|
+
"$PROJECT_ROOT/.claude/skills/cfn-telemetry/collect-metrics.sh" stop-monitoring "$monitor_pid" >/dev/null 2>&1 || true
|
|
593
|
+
echo " Stopped monitoring for $unique_agent_id (Monitor PID: $monitor_pid)" >&2
|
|
594
|
+
fi
|
|
595
|
+
done
|
|
596
|
+
|
|
527
597
|
# Calculate actual elapsed time
|
|
528
598
|
local end_time=$(date +%s)
|
|
529
599
|
local elapsed=$((end_time - start_time))
|
|
@@ -668,12 +738,22 @@ function spawn_loop2_agents() {
|
|
|
668
738
|
|
|
669
739
|
echo " Spawning: $agent_type (ID: $UNIQUE_VALIDATOR_ID)"
|
|
670
740
|
|
|
671
|
-
# Spawn
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
741
|
+
# Spawn validator in background with process instrumentation and memory limits
|
|
742
|
+
if command -v execute_instrumented >/dev/null 2>&1; then
|
|
743
|
+
execute_instrumented "npx" "$CFN_VALIDATION_TIMEOUT" "$CFN_MEMORY_LIMIT" \
|
|
744
|
+
claude-flow-novice agent "$agent_type" \
|
|
745
|
+
--task-id "$task_id" \
|
|
746
|
+
--agent-id "$UNIQUE_VALIDATOR_ID" \
|
|
747
|
+
--iteration "$iteration" \
|
|
748
|
+
--context "$(build_agent_context "$task_id" "$iteration" "$agent_type" "" "loop2")" &
|
|
749
|
+
else
|
|
750
|
+
# Fallback to raw spawn if instrumentation unavailable
|
|
751
|
+
npx claude-flow-novice agent "$agent_type" \
|
|
752
|
+
--task-id "$task_id" \
|
|
753
|
+
--agent-id "$UNIQUE_VALIDATOR_ID" \
|
|
754
|
+
--iteration "$iteration" \
|
|
755
|
+
--context "$(build_agent_context "$task_id" "$iteration" "$agent_type" "" "loop2")" &
|
|
756
|
+
fi
|
|
677
757
|
|
|
678
758
|
# Store PID for monitoring using unique agent ID
|
|
679
759
|
AGENT_PID=$!
|