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 Task Mode Safety - Mode Detection and Enforcement
|
|
3
|
+
# Part of ANTI-023 Memory Leak Protection System
|
|
4
|
+
|
|
5
|
+
set -e
|
|
6
|
+
|
|
7
|
+
# Mode Detection Script for CFN Loop Safety
|
|
8
|
+
|
|
9
|
+
CFN_MODE_SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
10
|
+
|
|
11
|
+
# Mode Detection Function
|
|
12
|
+
detect_execution_mode() {
|
|
13
|
+
local mode=""
|
|
14
|
+
|
|
15
|
+
# 1. Environment variable check
|
|
16
|
+
if [[ -n "${CFN_MODE:-}" ]]; then
|
|
17
|
+
mode="$CFN_MODE"
|
|
18
|
+
echo "🔍 Mode detected from CFN_MODE: $mode" >&2
|
|
19
|
+
echo "$mode" # CRITICAL: Echo detected value for regression testing
|
|
20
|
+
return 0
|
|
21
|
+
fi
|
|
22
|
+
|
|
23
|
+
# 2. Task ID/Agent ID presence check (CLI mode indicators)
|
|
24
|
+
if [[ -n "${TASK_ID:-}" && -n "${AGENT_ID:-}" ]]; then
|
|
25
|
+
mode="cli"
|
|
26
|
+
echo "🔍 Mode detected from TASK_ID/AGENT_ID: $mode" >&2
|
|
27
|
+
echo "$mode" # CRITICAL: Echo detected value for regression testing
|
|
28
|
+
return 0
|
|
29
|
+
fi
|
|
30
|
+
|
|
31
|
+
# 3. Process inspection (check if spawned by Task() tool)
|
|
32
|
+
if [[ "${PPID:-}" -gt 0 ]]; then
|
|
33
|
+
local parent_cmd=$(ps -o comm= -p "$PPID" 2>/dev/null || echo "unknown")
|
|
34
|
+
if [[ "$parent_cmd" == *"claude"* || "$parent_cmd" == *"Task"* ]]; then
|
|
35
|
+
mode="task"
|
|
36
|
+
echo "🔍 Mode detected from parent process: $mode" >&2
|
|
37
|
+
echo "$mode" # CRITICAL: Echo detected value for regression testing
|
|
38
|
+
return 0
|
|
39
|
+
fi
|
|
40
|
+
fi
|
|
41
|
+
|
|
42
|
+
# 4. Check for script calling context (CLI mode indicators)
|
|
43
|
+
if [[ -n "${__CFN_CLI_SPAWN:-}" ]]; then
|
|
44
|
+
mode="cli"
|
|
45
|
+
echo "🔍 Mode detected from CLI spawn marker: $mode" >&2
|
|
46
|
+
echo "$mode" # CRITICAL: Echo detected value for regression testing
|
|
47
|
+
return 0
|
|
48
|
+
fi
|
|
49
|
+
|
|
50
|
+
# 5. Fallback to task mode for safety
|
|
51
|
+
mode="task"
|
|
52
|
+
echo "🔍 Defaulting to safe mode: $mode" >&2
|
|
53
|
+
echo "$mode" # CRITICAL: Echo detected value for regression testing
|
|
54
|
+
return 0
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
# Is Task Mode Function
|
|
58
|
+
is_task_mode() {
|
|
59
|
+
local mode=$(detect_execution_mode)
|
|
60
|
+
[[ "$mode" == "task" ]]
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
# Is CLI Mode Function
|
|
64
|
+
is_cli_mode() {
|
|
65
|
+
local mode=$(detect_execution_mode)
|
|
66
|
+
[[ "$mode" == "cli" ]]
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
# Mode Compliance Enforcement
|
|
70
|
+
enforce_mode_compliance() {
|
|
71
|
+
local operation="$1"
|
|
72
|
+
|
|
73
|
+
if is_task_mode; then
|
|
74
|
+
echo "❌ TASK MODE DETECTED - Redis coordination forbidden" >&2
|
|
75
|
+
echo "🚨 ANTI-023: '$operation' requires CLI mode, detected Task mode" >&2
|
|
76
|
+
echo "💡 Task mode agents should use direct JSON output" >&2
|
|
77
|
+
echo "💡 Switch to CLI mode: use /cfn-loop-cli instead of /cfn-loop-task" >&2
|
|
78
|
+
return 1
|
|
79
|
+
fi
|
|
80
|
+
|
|
81
|
+
if is_cli_mode; then
|
|
82
|
+
echo "✅ CLI mode - '$operation' allowed" >&2
|
|
83
|
+
return 0
|
|
84
|
+
fi
|
|
85
|
+
|
|
86
|
+
# Unknown mode, default to safe (Task mode)
|
|
87
|
+
echo "❓ Unknown mode - defaulting to Task mode safety" >&2
|
|
88
|
+
return 1
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
# Safe Redis Operation Wrapper
|
|
92
|
+
redis_cli_safe() {
|
|
93
|
+
if ! enforce_mode_compliance "redis_cli"; then
|
|
94
|
+
return 1
|
|
95
|
+
fi
|
|
96
|
+
|
|
97
|
+
# CLI mode - Execute Redis command
|
|
98
|
+
redis-cli "$@"
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
# Safe Coordination Operation Wrapper
|
|
102
|
+
cfn_coordination_safe() {
|
|
103
|
+
local operation="$1"
|
|
104
|
+
shift
|
|
105
|
+
|
|
106
|
+
if ! enforce_mode_compliance "coordination"; then
|
|
107
|
+
# Task mode fallback - use file-based signaling
|
|
108
|
+
cfn_task_fallback "$operation" "$@"
|
|
109
|
+
return $?
|
|
110
|
+
fi
|
|
111
|
+
|
|
112
|
+
# CLI mode - Use Redis coordination
|
|
113
|
+
case "$operation" in
|
|
114
|
+
"signal-complete")
|
|
115
|
+
local task_id="$1"
|
|
116
|
+
local agent_id="$2"
|
|
117
|
+
redis_cli_safe LPUSH "swarm:${task_id}:${agent_id}:done" "complete"
|
|
118
|
+
;;
|
|
119
|
+
"store-confidence")
|
|
120
|
+
local task_id="$1"
|
|
121
|
+
local agent_id="$2"
|
|
122
|
+
local confidence="$3"
|
|
123
|
+
redis_cli_safe SET "swarm:${task_id}:${agent_id}:confidence" "$confidence" EX 3600
|
|
124
|
+
;;
|
|
125
|
+
"store-result")
|
|
126
|
+
local task_id="$1"
|
|
127
|
+
local agent_id="$2"
|
|
128
|
+
local result="$3"
|
|
129
|
+
redis_cli_safe HSET "swarm:${task_id}:${agent_id}:result" \
|
|
130
|
+
"confidence" "${result:-0.0}" \
|
|
131
|
+
"timestamp" "$(date -u +%Y-%m-%dT%H:%M:%SZ)"
|
|
132
|
+
;;
|
|
133
|
+
*)
|
|
134
|
+
echo "❌ Unknown coordination operation: $operation" >&2
|
|
135
|
+
return 1
|
|
136
|
+
;;
|
|
137
|
+
esac
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
# Task Mode Fallback Implementation
|
|
141
|
+
cfn_task_fallback() {
|
|
142
|
+
local operation="$1"
|
|
143
|
+
shift
|
|
144
|
+
|
|
145
|
+
local task_id="${TASK_ID:-unknown}"
|
|
146
|
+
local agent_id="${AGENT_ID:-unknown}"
|
|
147
|
+
local timestamp="$(date -u +%Y-%m-%dT%H:%M:%SZ)"
|
|
148
|
+
|
|
149
|
+
mkdir -p "./.claude/task-signals"
|
|
150
|
+
|
|
151
|
+
case "$operation" in
|
|
152
|
+
"signal-complete")
|
|
153
|
+
local signal_file="./.claude/task-signals/${task_id}_${agent_id}_complete.json"
|
|
154
|
+
cat > "$signal_file" <<EOF
|
|
155
|
+
{
|
|
156
|
+
"signal": "complete",
|
|
157
|
+
"task_id": "$task_id",
|
|
158
|
+
"agent_id": "$agent_id",
|
|
159
|
+
"timestamp": "$timestamp",
|
|
160
|
+
"mode": "task"
|
|
161
|
+
}
|
|
162
|
+
EOF
|
|
163
|
+
echo "📝 Task mode completion signal saved: $signal_file" >&2
|
|
164
|
+
;;
|
|
165
|
+
"store-confidence")
|
|
166
|
+
local confidence="$1"
|
|
167
|
+
local confidence_file="./.claude/task-signals/${task_id}_${agent_id}_confidence.json"
|
|
168
|
+
cat > "$confidence_file" <<EOF
|
|
169
|
+
{
|
|
170
|
+
"signal": "confidence",
|
|
171
|
+
"task_id": "$task_id",
|
|
172
|
+
"agent_id": "$agent_id",
|
|
173
|
+
"confidence": $confidence,
|
|
174
|
+
"timestamp": "$timestamp",
|
|
175
|
+
"mode": "task"
|
|
176
|
+
}
|
|
177
|
+
EOF
|
|
178
|
+
echo "📝 Task mode confidence saved: $confidence_file" >&2
|
|
179
|
+
;;
|
|
180
|
+
*)
|
|
181
|
+
echo "❌ Unknown fallback operation: $operation" >&2
|
|
182
|
+
return 1
|
|
183
|
+
;;
|
|
184
|
+
esac
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
# Task Mode Completion Protocol
|
|
188
|
+
task_mode_complete() {
|
|
189
|
+
local confidence="$1"
|
|
190
|
+
local status="${2:-COMPLETE}"
|
|
191
|
+
local summary="${3:-Work completed}"
|
|
192
|
+
shift 3 || true
|
|
193
|
+
local deliverables=("$@")
|
|
194
|
+
|
|
195
|
+
# Validate confidence range
|
|
196
|
+
if ! awk -v conf="$confidence" 'BEGIN { if (conf < 0 || conf > 1) exit 1 }'; then
|
|
197
|
+
echo "❌ Invalid confidence value: $confidence (must be 0.0-1.0)" >&2
|
|
198
|
+
exit 1
|
|
199
|
+
fi
|
|
200
|
+
|
|
201
|
+
# Generate JSON response
|
|
202
|
+
local json_output="{"
|
|
203
|
+
json_output+='"confidence": '"$confidence"','
|
|
204
|
+
json_output+='"status": "'"$status"'",'
|
|
205
|
+
json_output+='"summary": "'"$summary"'",'
|
|
206
|
+
|
|
207
|
+
if [[ ${#deliverables[@]} -gt 0 ]]; then
|
|
208
|
+
json_output+='"deliverables": ['
|
|
209
|
+
local first=true
|
|
210
|
+
for deliverable in "${deliverables[@]}"; do
|
|
211
|
+
if [[ "$first" == true ]]; then
|
|
212
|
+
first=false
|
|
213
|
+
else
|
|
214
|
+
json_output+=","
|
|
215
|
+
fi
|
|
216
|
+
json_output+="\"$deliverable\""
|
|
217
|
+
done
|
|
218
|
+
json_output+="],"
|
|
219
|
+
fi
|
|
220
|
+
|
|
221
|
+
json_output+='"timestamp": "'$(date -u +%Y-%m-%dT%H:%M:%SZ)'",'
|
|
222
|
+
json_output+'"mode": "task"'
|
|
223
|
+
json_output+="}"
|
|
224
|
+
|
|
225
|
+
# Output directly to stdout for Main Chat
|
|
226
|
+
echo "$json_output"
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
# Task Mode Audit Logging
|
|
230
|
+
task_mode_audit() {
|
|
231
|
+
local event="$1"
|
|
232
|
+
local task_id="${TASK_ID:-unknown}"
|
|
233
|
+
local agent_id="${AGENT_ID:-unknown}"
|
|
234
|
+
local data="$2"
|
|
235
|
+
|
|
236
|
+
local audit_file="./.claude/audit/task-mode/${task_id}_${agent_id}_$(date +%Y%m%d_%H%M%S).json"
|
|
237
|
+
mkdir -p "$(dirname "$audit_file")"
|
|
238
|
+
|
|
239
|
+
cat > "$audit_file" <<EOF
|
|
240
|
+
{
|
|
241
|
+
"timestamp": "$(date -u +%Y-%m-%dT%H:%M:%SZ)",
|
|
242
|
+
"event": "$event",
|
|
243
|
+
"task_id": "$task_id",
|
|
244
|
+
"agent_id": "$agent_id",
|
|
245
|
+
"data": $data,
|
|
246
|
+
"mode": "task"
|
|
247
|
+
}
|
|
248
|
+
EOF
|
|
249
|
+
|
|
250
|
+
echo "📝 Task mode audit logged: $audit_file" >&2
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
# Show Usage
|
|
254
|
+
show_usage() {
|
|
255
|
+
cat <<'EOF'
|
|
256
|
+
CFN Task Mode Safety - Mode Detection and Enforcement
|
|
257
|
+
|
|
258
|
+
USAGE:
|
|
259
|
+
source "$(dirname "${BASH_SOURCE[0]}")/mode-detection.sh"
|
|
260
|
+
|
|
261
|
+
# Mode Detection
|
|
262
|
+
detect_execution_mode # Detect current execution mode
|
|
263
|
+
is_task_mode # Check if running in Task mode
|
|
264
|
+
is_cli_mode # Check if running in CLI mode
|
|
265
|
+
|
|
266
|
+
# Enforcement
|
|
267
|
+
enforce_mode_compliance "operation" # Enforce mode compliance
|
|
268
|
+
|
|
269
|
+
# Safe Operations
|
|
270
|
+
redis_cli_safe "command" [args...] # Safe Redis CLI wrapper
|
|
271
|
+
cfn_coordination_safe "operation" [args...] # Safe coordination
|
|
272
|
+
|
|
273
|
+
# Task Mode Specific
|
|
274
|
+
task_mode_complete <confidence> <status> <summary> [deliverables...]
|
|
275
|
+
task_mode_audit <event> <json_data>
|
|
276
|
+
|
|
277
|
+
EXAMPLES:
|
|
278
|
+
# Check mode compliance before Redis operations
|
|
279
|
+
if is_cli_mode; then
|
|
280
|
+
redis_cli_safe LPUSH "swarm:${TASK_ID}:${AGENT_ID}:done" "complete"
|
|
281
|
+
else
|
|
282
|
+
task_mode_complete 0.85 "COMPLETE" "Work done" "file1.js" "file2.js"
|
|
283
|
+
fi
|
|
284
|
+
|
|
285
|
+
# Safe coordination usage
|
|
286
|
+
cfn_coordination_safe "signal-complete" "$TASK_ID" "$AGENT_ID"
|
|
287
|
+
cfn_coordination_safe "store-confidence" "$TASK_ID" "$AGENT_ID" 0.85
|
|
288
|
+
|
|
289
|
+
EOF
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
# Main execution block
|
|
293
|
+
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
|
|
294
|
+
if [[ "$1" == "--help" || "$1" == "-h" ]]; then
|
|
295
|
+
show_usage
|
|
296
|
+
exit 0
|
|
297
|
+
fi
|
|
298
|
+
|
|
299
|
+
# Execute single operation if provided
|
|
300
|
+
if [[ $# -gt 0 ]]; then
|
|
301
|
+
case "$1" in
|
|
302
|
+
"detect")
|
|
303
|
+
detect_execution_mode
|
|
304
|
+
;;
|
|
305
|
+
"is-task")
|
|
306
|
+
is_task_mode; exit $?
|
|
307
|
+
;;
|
|
308
|
+
"is-cli")
|
|
309
|
+
is_cli_mode; exit $?
|
|
310
|
+
;;
|
|
311
|
+
"compliance")
|
|
312
|
+
enforce_mode_compliance "$2"
|
|
313
|
+
;;
|
|
314
|
+
*)
|
|
315
|
+
echo "Unknown operation: $1" >&2
|
|
316
|
+
echo "Use --help for usage information" >&2
|
|
317
|
+
exit 1
|
|
318
|
+
;;
|
|
319
|
+
esac
|
|
320
|
+
else
|
|
321
|
+
echo "CFN Task Mode Safety System" >&2
|
|
322
|
+
echo "Mode: $(detect_execution_mode)" >&2
|
|
323
|
+
echo "Task Mode: $(is_task_mode && echo "YES" || echo "NO")" >&2
|
|
324
|
+
echo "CLI Mode: $(is_cli_mode && echo "YES" || echo "NO")" >&2
|
|
325
|
+
fi
|
|
326
|
+
fi
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# CFN Task Mode Environment Sanitizer
|
|
3
|
+
# Sanitizes and enforces Task-mode environment variables to prevent mode confusion
|
|
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
|
+
# Environment sanitization rules
|
|
12
|
+
sanitize_task_mode_environment() {
|
|
13
|
+
local mode="${1:-auto}"
|
|
14
|
+
|
|
15
|
+
echo "🧹 Sanitizing Task-mode environment..." >&2
|
|
16
|
+
|
|
17
|
+
# 1. Force CFN_MODE=task for Task mode
|
|
18
|
+
if [[ "$mode" == "task" || "$mode" == "auto" ]]; then
|
|
19
|
+
export CFN_MODE="task"
|
|
20
|
+
echo "✅ CFN_MODE forced to: $CFN_MODE" >&2
|
|
21
|
+
fi
|
|
22
|
+
|
|
23
|
+
# 2. Clear inherited CLI-mode variables that could cause mode confusion
|
|
24
|
+
local inherited_vars=(
|
|
25
|
+
"TASK_ID"
|
|
26
|
+
"AGENT_ID"
|
|
27
|
+
"LOOP3_AGENTS"
|
|
28
|
+
"LOOP2_VALIDATORS"
|
|
29
|
+
"PRODUCT_OWNER_ID"
|
|
30
|
+
"COORDINATOR_ID"
|
|
31
|
+
"__CFN_CLI_SPAWN"
|
|
32
|
+
"CFN_CLI_CONTEXT"
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
for var in "${inherited_vars[@]}"; do
|
|
36
|
+
if [[ -n "${!var:-}" ]]; then
|
|
37
|
+
echo "🗑️ Clearing inherited variable: $var (was: ${!var})" >&2
|
|
38
|
+
unset "$var"
|
|
39
|
+
fi
|
|
40
|
+
done
|
|
41
|
+
|
|
42
|
+
# 3. Set Task-mode specific environment
|
|
43
|
+
export __CFN_TASK_MODE="1"
|
|
44
|
+
export __CFN_MODE_ENFORCED="1"
|
|
45
|
+
|
|
46
|
+
# 4. Right-size Node.js heap for Task mode (prevent 16GB default)
|
|
47
|
+
if [[ -z "${NODE_OPTIONS:-}" ]]; then
|
|
48
|
+
export NODE_OPTIONS="--max-old-space-size=2048"
|
|
49
|
+
else
|
|
50
|
+
# Replace any larger heap size with Task-mode appropriate size
|
|
51
|
+
if echo "$NODE_OPTIONS" | grep -q "max-old-space-size"; then
|
|
52
|
+
export NODE_OPTIONS=$(echo "$NODE_OPTIONS" | sed 's/--max-old-space-size=[0-9]*/--max-old-space-size=2048/g')
|
|
53
|
+
else
|
|
54
|
+
export NODE_OPTIONS="$NODE_OPTIONS --max-old-space-size=2048"
|
|
55
|
+
fi
|
|
56
|
+
fi
|
|
57
|
+
echo "✅ NODE_OPTIONS set for Task mode: $NODE_OPTIONS" >&2
|
|
58
|
+
|
|
59
|
+
# 5. Configure Task-mode specific settings
|
|
60
|
+
export CFN_MEMORY_LIMIT="2048" # MB
|
|
61
|
+
export CFN_TIMEOUT="300" # 5 minutes
|
|
62
|
+
export CFN_COORDINATION="file" # Use file-based coordination
|
|
63
|
+
|
|
64
|
+
echo "🎯 Task-mode environment sanitized and locked" >&2
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
# Validate environment is in Task mode
|
|
68
|
+
validate_task_mode_environment() {
|
|
69
|
+
local errors=0
|
|
70
|
+
|
|
71
|
+
echo "🔍 Validating Task-mode environment..." >&2
|
|
72
|
+
|
|
73
|
+
# Check CFN_MODE
|
|
74
|
+
if [[ "${CFN_MODE:-}" != "task" ]]; then
|
|
75
|
+
echo "❌ CFN_MODE should be 'task', got: ${CFN_MODE:-unset}" >&2
|
|
76
|
+
((errors++))
|
|
77
|
+
fi
|
|
78
|
+
|
|
79
|
+
# Check Task-mode markers
|
|
80
|
+
if [[ "${__CFN_TASK_MODE:-}" != "1" ]]; then
|
|
81
|
+
echo "❌ __CFN_TASK_MODE not set" >&2
|
|
82
|
+
((errors++))
|
|
83
|
+
fi
|
|
84
|
+
|
|
85
|
+
# Check for prohibited CLI variables
|
|
86
|
+
local prohibited_vars=(
|
|
87
|
+
"TASK_ID"
|
|
88
|
+
"AGENT_ID"
|
|
89
|
+
"LOOP3_AGENTS"
|
|
90
|
+
"__CFN_CLI_SPAWN"
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
for var in "${prohibited_vars[@]}"; do
|
|
94
|
+
if [[ -n "${!var:-}" ]]; then
|
|
95
|
+
echo "❌ Prohibited CLI variable found: $var=${!var}" >&2
|
|
96
|
+
((errors++))
|
|
97
|
+
fi
|
|
98
|
+
done
|
|
99
|
+
|
|
100
|
+
# Check Node heap size
|
|
101
|
+
if echo "$NODE_OPTIONS" | grep -q "max-old-space-size"; then
|
|
102
|
+
local heap_size=$(echo "$NODE_OPTIONS" | grep -o "max-old-space-size=[0-9]*" | cut -d= -f2)
|
|
103
|
+
if [[ "$heap_size" -gt 4096 ]]; then
|
|
104
|
+
echo "❌ Node heap size too large for Task mode: ${heap_size}MB" >&2
|
|
105
|
+
((errors++))
|
|
106
|
+
fi
|
|
107
|
+
else
|
|
108
|
+
echo "⚠️ No Node heap size specified (should be set to 2048MB)" >&2
|
|
109
|
+
fi
|
|
110
|
+
|
|
111
|
+
if [[ $errors -eq 0 ]]; then
|
|
112
|
+
echo "✅ Task-mode environment validation passed" >&2
|
|
113
|
+
return 0
|
|
114
|
+
else
|
|
115
|
+
echo "❌ Task-mode environment validation failed ($errors errors)" >&2
|
|
116
|
+
return 1
|
|
117
|
+
fi
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
# Execute command in sanitized Task-mode environment
|
|
121
|
+
exec_task_mode_sanitized() {
|
|
122
|
+
local command="$1"
|
|
123
|
+
shift
|
|
124
|
+
|
|
125
|
+
echo "🚀 Executing in sanitized Task-mode environment: $command" >&2
|
|
126
|
+
|
|
127
|
+
# Sanitize environment
|
|
128
|
+
sanitize_task_mode_environment "task"
|
|
129
|
+
|
|
130
|
+
# Validate environment
|
|
131
|
+
if ! validate_task_mode_environment; then
|
|
132
|
+
echo "❌ Environment validation failed, aborting execution" >&2
|
|
133
|
+
return 1
|
|
134
|
+
fi
|
|
135
|
+
|
|
136
|
+
# Execute command with timeout
|
|
137
|
+
local timeout="${CFN_TIMEOUT:-300}"
|
|
138
|
+
echo "⏱️ Timeout set to ${timeout}s" >&2
|
|
139
|
+
|
|
140
|
+
if timeout "$timeout" "$command" "$@"; then
|
|
141
|
+
echo "✅ Command completed successfully" >&2
|
|
142
|
+
return 0
|
|
143
|
+
else
|
|
144
|
+
local exit_code=$?
|
|
145
|
+
if [[ $exit_code -eq 124 ]]; then
|
|
146
|
+
echo "⏰ Command timed out after ${timeout}s" >&2
|
|
147
|
+
else
|
|
148
|
+
echo "❌ Command failed with exit code: $exit_code" >&2
|
|
149
|
+
fi
|
|
150
|
+
return $exit_code
|
|
151
|
+
fi
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
# Show usage
|
|
155
|
+
show_usage() {
|
|
156
|
+
cat <<'EOF'
|
|
157
|
+
CFN Task Mode Environment Sanitizer
|
|
158
|
+
|
|
159
|
+
USAGE:
|
|
160
|
+
source "$(dirname "${BASH_SOURCE[0]}")/task-mode-env-sanitizer.sh"
|
|
161
|
+
|
|
162
|
+
# Environment Sanitization
|
|
163
|
+
sanitize_task_mode_environment [mode] # Sanitize environment (auto|task|cli)
|
|
164
|
+
validate_task_mode_environment # Validate current environment
|
|
165
|
+
|
|
166
|
+
# Command Execution
|
|
167
|
+
exec_task_mode_sanitized <command> [args...] # Execute command in sanitized environment
|
|
168
|
+
|
|
169
|
+
EXAMPLES:
|
|
170
|
+
# Sanitize current shell
|
|
171
|
+
sanitize_task_mode_environment task
|
|
172
|
+
|
|
173
|
+
# Execute validator with sanitized environment
|
|
174
|
+
exec_task_mode_sanitized node validate-code.js
|
|
175
|
+
|
|
176
|
+
# Run with environment validation
|
|
177
|
+
if validate_task_mode_environment; then
|
|
178
|
+
echo "Environment is safe for Task mode"
|
|
179
|
+
fi
|
|
180
|
+
|
|
181
|
+
ENVIRONMENT VARIABLES:
|
|
182
|
+
CFN_MODE # Forced to 'task' for Task mode
|
|
183
|
+
__CFN_TASK_MODE # Set to '1' in Task mode
|
|
184
|
+
NODE_OPTIONS # Limited to 2048MB heap in Task mode
|
|
185
|
+
CFN_MEMORY_LIMIT # Memory limit in MB (default: 2048)
|
|
186
|
+
CFN_TIMEOUT # Command timeout in seconds (default: 300)
|
|
187
|
+
CFN_COORDINATION # Coordination method: 'file' for Task mode
|
|
188
|
+
|
|
189
|
+
EOF
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
# Main execution block
|
|
193
|
+
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
|
|
194
|
+
if [[ "$1" == "--help" || "$1" == "-h" ]]; then
|
|
195
|
+
show_usage
|
|
196
|
+
exit 0
|
|
197
|
+
fi
|
|
198
|
+
|
|
199
|
+
# Execute operation if provided
|
|
200
|
+
if [[ $# -gt 0 ]]; then
|
|
201
|
+
case "$1" in
|
|
202
|
+
"sanitize")
|
|
203
|
+
sanitize_task_mode_environment "${2:-auto}"
|
|
204
|
+
;;
|
|
205
|
+
"validate")
|
|
206
|
+
validate_task_mode_environment
|
|
207
|
+
;;
|
|
208
|
+
"exec")
|
|
209
|
+
shift
|
|
210
|
+
exec_task_mode_sanitized "$@"
|
|
211
|
+
;;
|
|
212
|
+
*)
|
|
213
|
+
echo "Unknown operation: $1" >&2
|
|
214
|
+
echo "Use --help for usage information" >&2
|
|
215
|
+
exit 1
|
|
216
|
+
;;
|
|
217
|
+
esac
|
|
218
|
+
else
|
|
219
|
+
echo "CFN Task Mode Environment Sanitizer" >&2
|
|
220
|
+
echo "Current mode: ${CFN_MODE:-unset}" >&2
|
|
221
|
+
echo "Node options: ${NODE_OPTIONS:-unset}" >&2
|
|
222
|
+
echo "Use --help for usage information" >&2
|
|
223
|
+
fi
|
|
224
|
+
fi
|