claude-flow-novice 2.14.8 → 2.14.10

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 (45) hide show
  1. package/.claude/commands/cfn-loop-cli.md +1 -1
  2. package/.claude/skills/cfn-agent-selector/SKILL.md +2 -2
  3. package/.claude/skills/cfn-agent-selector/SKILL.md.backup_before_replace +91 -0
  4. package/.claude/skills/cfn-loop-orchestration/orchestrate.sh +72 -5
  5. package/README.md +4 -4
  6. package/README.md.backup_before_replace +781 -0
  7. package/claude-assets/agents/AGENT_LIFECYCLE.md +3 -3
  8. package/claude-assets/agents/AGENT_LIFECYCLE.md.backup_before_replace +530 -0
  9. package/claude-assets/agents/README-AGENT_LIFECYCLE.md +3 -3
  10. package/claude-assets/agents/README-AGENT_LIFECYCLE.md.backup_before_replace +522 -0
  11. package/claude-assets/agents/cfn-dev-team/CLAUDE.md +3 -3
  12. package/claude-assets/agents/cfn-dev-team/CLAUDE.md.backup_before_replace +1086 -0
  13. package/claude-assets/agents/cfn-dev-team/README.md +1 -1
  14. package/claude-assets/agents/cfn-dev-team/README.md.backup_before_replace +116 -0
  15. package/claude-assets/agents/cfn-dev-team/coordinators/cfn-v3-coordinator.md +2 -2
  16. package/claude-assets/agents/cfn-dev-team/coordinators/cfn-v3-coordinator.md.backup_before_replace +451 -0
  17. package/claude-assets/agents/cfn-dev-team/developers/README.md +3 -3
  18. package/claude-assets/agents/cfn-dev-team/developers/README.md.backup_before_replace +69 -0
  19. package/claude-assets/agents/cfn-dev-team/documentation/agent-type-guidelines.md +1 -1
  20. package/claude-assets/agents/cfn-dev-team/documentation/agent-type-guidelines.md.backup_before_replace +465 -0
  21. package/claude-assets/agents/cfn-dev-team/test-agent.md +2 -2
  22. package/claude-assets/agents/cfn-dev-team/test-agent.md.backup_before_replace +141 -0
  23. package/claude-assets/commands/cfn-loop-cli.md +1 -1
  24. package/claude-assets/skills/cfn-agent-selector/SKILL.md +2 -2
  25. package/claude-assets/skills/cfn-agent-selector/SKILL.md.backup_before_replace +91 -0
  26. package/claude-assets/skills/cfn-cli-setup/validate-cli-environment.sh +192 -0
  27. package/claude-assets/skills/cfn-deliverable-validation/confidence-calculator.sh +262 -0
  28. package/claude-assets/skills/cfn-loop-orchestration/orchestrate.sh +72 -5
  29. package/claude-assets/skills/cfn-mcp-container-selector/SKILL.md +555 -0
  30. package/claude-assets/skills/cfn-memory-monitoring/SKILL.md +531 -0
  31. package/claude-assets/skills/cfn-redis-cleanup/cleanup-redis.sh +130 -0
  32. package/claude-assets/skills/cfn-task-decomposition/task-decomposer.sh +279 -0
  33. package/dist/agents/agent-loader.js +165 -146
  34. package/dist/cli/cli-agent-context.js +6 -0
  35. package/dist/cli/cli-agent-context.js.map +1 -1
  36. package/dist/cli/config-manager.js +109 -91
  37. package/dist/cli/config-manager.js.map +1 -1
  38. package/dist/types/index.js +11 -0
  39. package/dist/types/index.js.map +1 -0
  40. package/dist/types/user.js +22 -0
  41. package/dist/types/user.js.map +1 -0
  42. package/package.json +1 -1
  43. package/readme/README.md +1 -1
  44. package/scripts/docker-playwright-fix.sh +312 -0
  45. package/scripts/zone-d-type-fixes.sh +333 -0
@@ -0,0 +1,91 @@
1
+ # Agent Selector Skill
2
+
3
+ **Version:** 1.0.0
4
+ **Purpose:** Select optimal agents for CFN Loop v3 based on task type and requirements
5
+
6
+ ## Overview
7
+
8
+ Recommends Loop 3 (producers) and Loop 2 (evaluators) agents based on:
9
+ - Task type (from task-classifier)
10
+ - Task description keywords
11
+ - Complexity requirements
12
+
13
+ ## Usage
14
+
15
+ ```bash
16
+ AGENTS=$(./.claude/skills/cfn-agent-selector/select-agents.sh \
17
+ --task-type "software-development" \
18
+ --description "Implement JWT authentication with refresh tokens")
19
+
20
+ echo "$AGENTS" | jq '.loop3[]' # ["backend-dev", "security-specialist"]
21
+ echo "$AGENTS" | jq '.loop2[]' # ["reviewer", "tester", "security-auditor"]
22
+ ```
23
+
24
+ ## Output Format
25
+
26
+ ```json
27
+ {
28
+ "loop3": ["agent1", "agent2", "agent3"],
29
+ "loop2": ["validator1", "validator2", "validator3"],
30
+ "loop4": "product-owner",
31
+ "reasoning": "Explanation of agent selection"
32
+ }
33
+ ```
34
+
35
+ ## Agent Selection Rules
36
+
37
+ ### Software Development
38
+ **Base Loop 3:** backend-dev, coder
39
+ **Add if keywords:**
40
+ - "security", "authentication", "JWT" → security-specialist
41
+ - "database", "SQL", "schema" → database-engineer (if exists)
42
+ - "deploy", "CI/CD", "infrastructure" → devops-engineer
43
+ - "frontend", "React", "UI" → react-frontend-engineer
44
+
45
+ **Loop 2:** reviewer, tester, security-auditor
46
+
47
+ ### Content Creation
48
+ **Base Loop 3:** copywriter, content-strategist
49
+ **Add if keywords:**
50
+ - "SEO", "search", "keywords" → seo-specialist
51
+ - "technical", "documentation" → technical-writer (if exists)
52
+
53
+ **Loop 2:** editor, brand-reviewer, compliance-checker
54
+
55
+ ### Research
56
+ **Base Loop 3:** researcher, data-analyst
57
+ **Add if keywords:**
58
+ - "statistics", "data analysis" → statistician (if exists)
59
+ - "domain-specific" → domain-expert
60
+
61
+ **Loop 2:** fact-checker, methodology-reviewer, statistician
62
+
63
+ ### Design
64
+ **Base Loop 3:** ui-designer, ux-researcher
65
+ **Add if keywords:**
66
+ - "visual", "branding" → visual-designer
67
+ - "accessibility" → accessibility-advocate
68
+
69
+ **Loop 2:** accessibility-advocate, design-critic, user-tester
70
+
71
+ ### Infrastructure
72
+ **Base Loop 3:** devops-engineer, terraform-engineer
73
+ **Add if keywords:**
74
+ - "Kubernetes", "k8s", "container" → kubernetes-architect
75
+ - "network", "security" → network-engineer (if exists)
76
+
77
+ **Loop 2:** security-auditor, cost-optimizer, compliance-checker
78
+
79
+ ### Data Engineering
80
+ **Base Loop 3:** data-engineer, pipeline-builder
81
+ **Add if keywords:**
82
+ - "ETL", "transformation" → etl-specialist
83
+ - "streaming", "real-time" → streaming-specialist (if exists)
84
+
85
+ **Loop 2:** data-quality-validator, schema-reviewer, performance-tester
86
+
87
+ ## Integration
88
+
89
+ Used by:
90
+ - `.claude/agents/cfn-v3-coordinator.md` - Agent selection
91
+ - `.claude/skills/cfn-agent-selector/select-agents.sh` - Primary selection script
@@ -0,0 +1,192 @@
1
+ #!/bin/bash
2
+ # CLI Environment Validation Script
3
+ # Ensures required tools are available before agent deployment
4
+
5
+ set -euo pipefail
6
+
7
+ # Colors for output
8
+ RED='\033[0;31m'
9
+ GREEN='\033[0;32m'
10
+ YELLOW='\033[1;33m'
11
+ NC='\033[0m' # No Color
12
+
13
+ # Required tools for CFN Loop CLI agents
14
+ REQUIRED_TOOLS=(
15
+ "rg:ripgrep"
16
+ "git"
17
+ "node"
18
+ "npm"
19
+ "jq"
20
+ "redis-cli"
21
+ "find"
22
+ "grep"
23
+ "sed"
24
+ "awk"
25
+ "sort"
26
+ "uniq"
27
+ "head"
28
+ "tail"
29
+ "wc"
30
+ "xargs"
31
+ )
32
+
33
+ echo -e "${GREEN}🔧 CFN Loop CLI Environment Validation${NC}"
34
+
35
+ # Function to check if a tool is available
36
+ check_tool() {
37
+ local tool_name="$1"
38
+ local tool_description="$2"
39
+
40
+ if command -v "$tool_name" >/dev/null 2>&1; then
41
+ echo -e " ${GREEN}✓${NC} $tool_name ($tool_description)"
42
+ return 0
43
+ else
44
+ echo -e " ${RED}✗${NC} $tool_name ($tool_description) - ${YELLOW}MISSING${NC}"
45
+ return 1
46
+ fi
47
+ }
48
+
49
+ # Function to validate Node.js version
50
+ validate_node_version() {
51
+ if command -v node >/dev/null 2>&1; then
52
+ local node_version=$(node --version 2>/dev/null | sed 's/v//')
53
+ local major_version=$(echo "$node_version" | cut -d. -f1)
54
+
55
+ if [ "$major_version" -ge 18 ]; then
56
+ echo -e " ${GREEN}✓${NC} Node.js v$node_version (>= 18 required)"
57
+ return 0
58
+ else
59
+ echo -e " ${RED}✗${NC} Node.js v$node_version (>= 18 required) - ${YELLOW}VERSION TOO OLD${NC}"
60
+ return 1
61
+ fi
62
+ else
63
+ echo -e " ${RED}✗${NC} Node.js - ${YELLOW}NOT FOUND${NC}"
64
+ return 1
65
+ fi
66
+ }
67
+
68
+ # Function to check PATH for common development directories
69
+ validate_path() {
70
+ echo -e "${YELLOW}Validating PATH...${NC}"
71
+
72
+ # Check for common development tool paths
73
+ local paths_to_check=(
74
+ "/usr/local/bin"
75
+ "/usr/bin"
76
+ "/bin"
77
+ "$HOME/.local/bin"
78
+ "$HOME/.cargo/bin"
79
+ "$HOME/.npm-global/bin"
80
+ "./node_modules/.bin"
81
+ )
82
+
83
+ local found_paths=0
84
+ for path in "${paths_to_check[@]}"; do
85
+ if [ -d "$path" ] && echo "$PATH" | grep -q "$path"; then
86
+ echo -e " ${GREEN}✓${NC} $path in PATH"
87
+ ((found_paths++))
88
+ fi
89
+ done
90
+
91
+ if [ "$found_paths" -eq 0 ]; then
92
+ echo -e " ${YELLOW}⚠${NC} Limited development directories in PATH"
93
+ return 1
94
+ fi
95
+
96
+ return 0
97
+ }
98
+
99
+ # Function to validate Redis connection
100
+ validate_redis() {
101
+ echo -e "${YELLOW}Validating Redis connection...${NC}"
102
+
103
+ if redis-cli ping >/dev/null 2>&1; then
104
+ local redis_info=$(redis-cli info server 2>/dev/null | grep "redis_version" | cut -d: -f2 | tr -d '\r')
105
+ echo -e " ${GREEN}✓${NC} Redis v$redis_info - Connected"
106
+ return 0
107
+ else
108
+ echo -e " ${RED}✗${NC} Redis - ${YELLOW}NOT CONNECTED${NC}"
109
+ return 1
110
+ fi
111
+ }
112
+
113
+ # Function to validate working directory
114
+ validate_working_directory() {
115
+ echo -e "${YELLOW}Validating working directory...${NC}"
116
+
117
+ # Check if we're in a git repository
118
+ if git rev-parse --git-dir >/dev/null 2>&1; then
119
+ echo -e " ${GREEN}✓${NC} Git repository detected"
120
+ else
121
+ echo -e " ${YELLOW}⚠${NC} Not in a git repository"
122
+ fi
123
+
124
+ # Check for claude-flow-novice installation
125
+ if [ -f "package.json" ] && grep -q "claude-flow-novice" package.json; then
126
+ echo -e " ${GREEN}✓${NC} claude-flow-novice dependency found"
127
+ else
128
+ echo -e " ${YELLOW}⚠${NC} claude-flow-novice not found in package.json"
129
+ fi
130
+
131
+ # Check for .claude directory
132
+ if [ -d ".claude" ]; then
133
+ echo -e " ${GREEN}✓${NC} .claude directory found"
134
+ else
135
+ echo -e " ${YELLOW}⚠${NC} .claude directory not found"
136
+ fi
137
+ }
138
+
139
+ # Function to install missing tools (suggestions)
140
+ suggest_installations() {
141
+ echo -e "\n${YELLOW}Installation Suggestions:${NC}"
142
+ echo -e " ${YELLOW}ripgrep:${NC} sudo apt-get install ripgrep # Debian/Ubuntu"
143
+ echo -e " ${YELLOW}ripgrep:${NC} brew install ripgrep # macOS"
144
+ echo -e " ${YELLOW}jq:${NC} sudo apt-get install jq # Debian/Ubuntu"
145
+ echo -e " ${YELLOW}jq:${NC} brew install jq # macOS"
146
+ echo -e " ${YELLOW}Redis:${NC} sudo systemctl start redis # Linux"
147
+ echo -e " ${YELLOW}Redis:${NC} brew services start redis # macOS"
148
+ }
149
+
150
+ # Main validation
151
+ main() {
152
+ local failed=0
153
+
154
+ echo -e "${YELLOW}Checking required tools...${NC}"
155
+ for tool in "${REQUIRED_TOOLS[@]}"; do
156
+ local tool_name=$(echo "$tool" | cut -d: -f1)
157
+ local tool_description=$(echo "$tool" | cut -d: -f2)
158
+
159
+ if ! check_tool "$tool_name" "$tool_description"; then
160
+ ((failed++))
161
+ fi
162
+ done
163
+
164
+ echo -e "\n${YELLOW}Checking Node.js version...${NC}"
165
+ if ! validate_node_version; then
166
+ ((failed++))
167
+ fi
168
+
169
+ echo -e "\n${YELLOW}Checking environment configuration...${NC}"
170
+ if ! validate_path; then
171
+ ((failed++))
172
+ fi
173
+
174
+ if ! validate_redis; then
175
+ ((failed++))
176
+ fi
177
+
178
+ validate_working_directory
179
+
180
+ echo -e "\n${GREEN}=== Validation Summary ===${NC}"
181
+ if [ "$failed" -eq 0 ]; then
182
+ echo -e "${GREEN}✅ All validations passed! CLI environment is ready.${NC}"
183
+ return 0
184
+ else
185
+ echo -e "${RED}❌ $failed validation(s) failed. CLI environment needs setup.${NC}"
186
+ suggest_installations
187
+ return 1
188
+ fi
189
+ }
190
+
191
+ # Run validation
192
+ main "$@"
@@ -0,0 +1,262 @@
1
+ #!/bin/bash
2
+ # Deliverable-Based Confidence Calculator
3
+ # Calculates confidence scores based on actual deliverable completion
4
+
5
+ set -euo pipefail
6
+
7
+ # Arguments
8
+ TASK_ID="$1"
9
+ AGENT_ID="$2"
10
+ EXPECTED_DELIVERABLES="$3" # JSON array of expected files/deliverables
11
+ WORKING_DIR="${4:-$(pwd)}"
12
+
13
+ # Colors for output
14
+ RED='\033[0;31m'
15
+ GREEN='\033[0;32m'
16
+ YELLOW='\033[1;33m'
17
+ BLUE='\033[0;34m'
18
+ NC='\033[0m' # No Color
19
+
20
+ echo -e "${BLUE}📊 Deliverable-Based Confidence Calculator${NC}"
21
+ echo "Task ID: $TASK_ID"
22
+ echo "Agent ID: $AGENT_ID"
23
+ echo "Working Directory: $WORKING_DIR"
24
+ echo ""
25
+
26
+ # Function to check if deliverable exists and is valid
27
+ validate_deliverable() {
28
+ local deliverable="$1"
29
+ local deliverable_path="$WORKING_DIR/$deliverable"
30
+
31
+ # Handle different deliverable types
32
+ case "$deliverable" in
33
+ *.md|*.txt|*.json|*.yaml|*.yml)
34
+ # Text files - check existence and content
35
+ if [ -f "$deliverable_path" ]; then
36
+ local size=$(stat -c%s "$deliverable_path" 2>/dev/null || echo "0")
37
+ if [ "$size" -gt 0 ]; then
38
+ echo "VALID:$size"
39
+ return 0
40
+ fi
41
+ fi
42
+ ;;
43
+ *.sh|*.js|*.ts|*.tsx|*.py)
44
+ # Code files - check existence and basic syntax
45
+ if [ -f "$deliverable_path" ]; then
46
+ local size=$(stat -c%s "$deliverable_path" 2>/dev/null || echo "0")
47
+ if [ "$size" -gt 100 ]; then
48
+ echo "VALID:$size"
49
+ return 0
50
+ fi
51
+ fi
52
+ ;;
53
+ */)
54
+ # Directories - check existence and contents
55
+ if [ -d "$deliverable_path" ]; then
56
+ local file_count=$(find "$deliverable_path" -type f | wc -l)
57
+ if [ "$file_count" -gt 0 ]; then
58
+ echo "VALID:$file_count"
59
+ return 0
60
+ fi
61
+ fi
62
+ ;;
63
+ *.json)
64
+ # JSON files - check validity
65
+ if [ -f "$deliverable_path" ]; then
66
+ if jq empty "$deliverable_path" 2>/dev/null; then
67
+ local size=$(stat -c%s "$deliverable_path" 2>/dev/null || echo "0")
68
+ echo "VALID:$size"
69
+ return 0
70
+ fi
71
+ fi
72
+ ;;
73
+ *)
74
+ # Generic file check
75
+ if [ -f "$deliverable_path" ]; then
76
+ local size=$(stat -c%s "$deliverable_path" 2>/dev/null || echo "0")
77
+ if [ "$size" -gt 0 ]; then
78
+ echo "VALID:$size"
79
+ return 0
80
+ fi
81
+ fi
82
+ ;;
83
+ esac
84
+
85
+ echo "INVALID"
86
+ return 1
87
+ }
88
+
89
+ # Function to calculate quality score based on deliverable characteristics
90
+ calculate_quality_score() {
91
+ local deliverable="$1"
92
+ local deliverable_path="$WORKING_DIR/$deliverable"
93
+
94
+ local quality_score=0.5 # Base score for existing
95
+
96
+ # Size scoring (larger files with meaningful content)
97
+ if [ -f "$deliverable_path" ]; then
98
+ local size=$(stat -c%s "$deliverable_path" 2>/dev/null || echo "0")
99
+
100
+ if [ "$size" -gt 5000 ]; then
101
+ quality_score=0.9 # Substantial content
102
+ elif [ "$size" -gt 1000 ]; then
103
+ quality_score=0.8 # Good content
104
+ elif [ "$size" -gt 100 ]; then
105
+ quality_score=0.7 # Adequate content
106
+ else
107
+ quality_score=0.6 # Minimal content
108
+ fi
109
+ fi
110
+
111
+ # Content-specific scoring
112
+ case "$deliverable" in
113
+ *.md)
114
+ # Markdown files - check for structure
115
+ if grep -q "^#" "$deliverable_path" 2>/dev/null; then
116
+ quality_score=$((quality_score + 10)) # Has headers
117
+ fi
118
+ if grep -q "^```" "$deliverable_path" 2>/dev/null; then
119
+ quality_score=$((quality_score + 5)) # Has code blocks
120
+ fi
121
+ ;;
122
+ *.ts|*.tsx|*.js|*.jsx)
123
+ # Code files - check for functions/exports
124
+ if grep -q "function\|export\|class\|const.*=" "$deliverable_path" 2>/dev/null; then
125
+ quality_score=$((quality_score + 10)) # Has functions/exports
126
+ fi
127
+ ;;
128
+ *.json)
129
+ # JSON files - check for structure
130
+ if jq -e 'type == "object" and keys > 0' "$deliverable_path" >/dev/null 2>&1; then
131
+ quality_score=$((quality_score + 10)) # Has meaningful structure
132
+ fi
133
+ ;;
134
+ esac
135
+
136
+ # Cap at 1.0
137
+ if [ "$quality_score" -gt 100 ]; then
138
+ quality_score=100
139
+ fi
140
+
141
+ echo "$quality_score"
142
+ }
143
+
144
+ # Main confidence calculation
145
+ main() {
146
+ echo -e "${YELLOW}Analyzing expected deliverables...${NC}"
147
+
148
+ # Parse expected deliverables from JSON
149
+ if ! echo "$EXPECTED_DELIVERABLES" | jq empty 2>/dev/null; then
150
+ echo -e "${RED}❌ Invalid JSON in expected deliverables${NC}"
151
+ echo "0.0"
152
+ return 1
153
+ fi
154
+
155
+ local total_deliverables=$(echo "$EXPECTED_DELIVERABLES" | jq 'length')
156
+ local valid_deliverables=0
157
+ local total_quality_score=0
158
+
159
+ echo "Expected deliverables: $total_deliverables"
160
+ echo ""
161
+
162
+ # Check each deliverable
163
+ for ((i=0; i<total_deliverables; i++)); do
164
+ local deliverable=$(echo "$EXPECTED_DELIVERABLES" | jq -r ".[$i]")
165
+
166
+ echo -n " Checking: $deliverable ... "
167
+
168
+ local validation_result=$(validate_deliverable "$deliverable")
169
+
170
+ if [[ "$validation_result" == VALID* ]]; then
171
+ local quality_score=$(calculate_quality_score "$deliverable")
172
+ total_quality_score=$((total_quality_score + quality_score))
173
+ valid_deliverables=$((valid_deliverables + 1))
174
+
175
+ local size=$(echo "$validation_result" | cut -d: -f2)
176
+ echo -e "${GREEN}✓ VALID${NC} (size: $size, quality: $quality_score)"
177
+ else
178
+ echo -e "${RED}✗ MISSING/INVALID${NC}"
179
+ fi
180
+ done
181
+
182
+ echo ""
183
+ echo -e "${YELLOW}Summary:${NC}"
184
+ echo " Valid deliverables: $valid_deliverables/$total_deliverables"
185
+
186
+ # Calculate completion score (0-1)
187
+ local completion_score=0
188
+ if [ "$total_deliverables" -gt 0 ]; then
189
+ completion_score=$(echo "scale=3; $valid_deliverables / $total_deliverables" | bc -l)
190
+ fi
191
+
192
+ # Calculate average quality score (0-1)
193
+ local avg_quality_score=0.5 # Default if no deliverables
194
+ if [ "$valid_deliverables" -gt 0 ]; then
195
+ avg_quality_score=$(echo "scale=3; $total_quality_score / ($valid_deliverables * 100)" | bc -l)
196
+ fi
197
+
198
+ # Calculate final confidence score
199
+ # Weight: 60% completion, 40% quality
200
+ local final_confidence=$(echo "scale=3; ($completion_score * 0.6) + ($avg_quality_score * 0.4)" | bc -l)
201
+
202
+ # Round to 2 decimal places
203
+ final_confidence=$(echo "$final_confidence" | sed 's/^\./0./' | sed 's/\.\([0-9]\{2\}\)[0-9]*$/.\1/')
204
+
205
+ echo " Completion score: $completion_score"
206
+ echo " Quality score: $avg_quality_score"
207
+ echo " Final confidence: $final_confidence"
208
+
209
+ # Validation rules
210
+ if [ "$valid_deliverables" -eq 0 ]; then
211
+ echo -e "${RED}🚨 CRITICAL: No deliverables created - confidence should be 0.0${NC}"
212
+ echo "0.0"
213
+ return 1
214
+ elif (( $(echo "$final_confidence > 0.3" | bc -l) )); then
215
+ if [ "$valid_deliverables" -lt "$((total_deliverables / 2))" ]; then
216
+ echo -e "${YELLOW}⚠️ WARNING: Low deliverable completion (<50%) - confidence should be <= 0.3${NC}"
217
+ fi
218
+ fi
219
+
220
+ echo -e "${GREEN}✓ Calculated confidence: $final_confidence${NC}"
221
+ echo "$final_confidence"
222
+ }
223
+
224
+ # Store results in Redis if available
225
+ store_confidence_result() {
226
+ local confidence="$1"
227
+
228
+ if command -v redis-cli >/dev/null 2>&1; then
229
+ # Store detailed breakdown
230
+ local breakdown=$(cat << EOF
231
+ {
232
+ "task_id": "$TASK_ID",
233
+ "agent_id": "$AGENT_ID",
234
+ "calculated_confidence": $confidence,
235
+ "calculation_method": "deliverable-based",
236
+ "timestamp": "$(date -Iseconds)",
237
+ "working_directory": "$WORKING_DIR",
238
+ "expected_deliverables": $EXPECTED_DELIVERABLES
239
+ }
240
+ EOF
241
+ )
242
+
243
+ redis-cli set "${TASK_ID}:${AGENT_ID}:confidence-breakdown" "$breakdown" >/dev/null 2>&1 || true
244
+ redis-cli set "${TASK_ID}:${AGENT_ID}:confidence-score" "$confidence" >/dev/null 2>&1 || true
245
+
246
+ echo -e "📦 ${BLUE}Stored confidence breakdown in Redis:${NC} ${TASK_ID}:${AGENT_ID}:confidence-breakdown"
247
+ fi
248
+ }
249
+
250
+ # Execute main function
251
+ if [ "$#" -lt 3 ]; then
252
+ echo "Usage: $0 <task_id> <agent_id> <expected_deliverables_json> [working_directory]"
253
+ echo "Example: $0 task-123 agent-1 '[\"file1.txt\", \"script.sh\", \"docs/\"]' /path/to/project"
254
+ exit 1
255
+ fi
256
+
257
+ final_confidence=$(main "$@")
258
+
259
+ # Store results
260
+ store_confidence_result "$final_confidence"
261
+
262
+ echo "$final_confidence"
@@ -66,6 +66,19 @@ LOOP3_FINAL_CONFIDENCE=0.0
66
66
  LOOP2_FINAL_CONSENSUS=0.0
67
67
  DELIVERABLES_VERIFIED=false
68
68
 
69
+ # Cleanup Redis keys before exit
70
+ cleanup_redis_keys() {
71
+ if [ -n "$TASK_ID" ]; then
72
+ echo "🧹 Cleaning up Redis keys for task $TASK_ID"
73
+ # Set TTL on remaining task keys (1 hour)
74
+ redis-cli keys "swarm:${TASK_ID}:*" 2>/dev/null | xargs -I {} redis-cli expire {} 3600 2>/dev/null || true
75
+ redis-cli keys "cfn_loop:task:${TASK_ID}:*" 2>/dev/null | xargs -I {} redis-cli expire {} 3600 2>/dev/null || true
76
+ fi
77
+ }
78
+
79
+ # Trap cleanup on script exit
80
+ trap cleanup_redis_keys EXIT
81
+
69
82
  ##############################################################################
70
83
  # Argument Parsing
71
84
  ##############################################################################
@@ -694,6 +707,17 @@ EOF
694
707
  # Main CFN Loop
695
708
  ##############################################################################
696
709
 
710
+ # Validate CLI environment before spawning agents
711
+ echo "🔧 Validating CLI environment..."
712
+ if [ -f "$PROJECT_ROOT/.claude/skills/cfn-cli-setup/validate-cli-environment.sh" ]; then
713
+ if ! bash "$PROJECT_ROOT/.claude/skills/cfn-cli-setup/validate-cli-environment.sh"; then
714
+ echo "❌ CLI environment validation failed. Agents may not have required tools."
715
+ echo "⚠️ Continuing anyway, but expect potential tool failures..."
716
+ fi
717
+ else
718
+ echo "⚠️ CLI environment validation script not found. Skipping validation."
719
+ fi
720
+
697
721
  # Store context in Redis
698
722
  store_context "$TASK_ID"
699
723
 
@@ -751,11 +775,41 @@ for ((ITERATION=1; ITERATION<=MAX_ITERATIONS; ITERATION++)); do
751
775
  --agents "$LOOP3_IDS" \
752
776
  --threshold "$GATE" \
753
777
  --min-quorum "$MIN_QUORUM_LOOP3"; then
754
- # Gate passed - store confidence
755
- LOOP3_FINAL_CONFIDENCE=$("$REDIS_COORD_SKILL/invoke-waiting-mode.sh" collect \
756
- --task-id "$TASK_ID" \
757
- --agent-ids "$LOOP3_IDS" \
758
- --min-quorum "$MIN_QUORUM_LOOP3")
778
+ # Gate passed - validate confidence based on deliverables
779
+ echo "🔍 Validating agent confidence scores against deliverables..."
780
+
781
+ # Re-calculate confidence based on actual deliverables
782
+ if [ -n "$EXPECTED_FILES" ] && [ -f "$PROJECT_ROOT/.claude/skills/cfn-deliverable-validation/confidence-calculator.sh" ]; then
783
+ VALIDATED_CONFIDENCE=0
784
+
785
+ for agent_id in ${LOOP3_IDS//,/ }; do
786
+ # Get agent's reported confidence
787
+ agent_confidence=$(redis-cli get "swarm:${TASK_ID}:${agent_id}:confidence" 2>/dev/null || echo "0.5")
788
+
789
+ # Calculate deliverable-based confidence
790
+ deliverable_confidence=$("$PROJECT_ROOT/.claude/skills/cfn-deliverable-validation/confidence-calculator.sh" \
791
+ "$TASK_ID" "$agent_id" "$EXPECTED_FILES" "$PROJECT_ROOT")
792
+
793
+ echo " Agent $agent_id: reported=$agent_confidence, deliverable-based=$deliverable_confidence"
794
+
795
+ # Use the lower of the two scores (inflation prevention)
796
+ if (( $(echo "$deliverable_confidence < $agent_confidence" | bc -l) )); then
797
+ echo " ⚠️ Downgrading confidence for $agent_id (inflated score detected)"
798
+ VALIDATED_CONFIDENCE=$deliverable_confidence
799
+ else
800
+ VALIDATED_CONFIDENCE=$agent_confidence
801
+ fi
802
+ done
803
+
804
+ LOOP3_FINAL_CONFIDENCE=$VALIDATED_CONFIDENCE
805
+ echo "✅ Final validated Loop 3 confidence: $LOOP3_FINAL_CONFIDENCE"
806
+ else
807
+ # Store confidence (fallback method)
808
+ LOOP3_FINAL_CONFIDENCE=$("$REDIS_COORD_SKILL/invoke-waiting-mode.sh" collect \
809
+ --task-id "$TASK_ID" \
810
+ --agent-ids "$LOOP3_IDS" \
811
+ --min-quorum "$MIN_QUORUM_LOOP3")
812
+ fi
759
813
  else
760
814
  # Gate failed - iterate Loop 3
761
815
  echo "❌ Gate check failed - iterating Loop 3"
@@ -878,6 +932,19 @@ EOF
878
932
  esac
879
933
  done
880
934
 
935
+ # Cleanup Redis keys before exit
936
+ cleanup_redis_keys() {
937
+ if [ -n "$TASK_ID" ]; then
938
+ echo "🧹 Cleaning up Redis keys for task $TASK_ID"
939
+ # Set TTL on remaining task keys (1 hour)
940
+ redis-cli keys "swarm:${TASK_ID}:*" 2>/dev/null | xargs -I {} redis-cli expire {} 3600 2>/dev/null || true
941
+ redis-cli keys "cfn_loop:task:${TASK_ID}:*" 2>/dev/null | xargs -I {} redis-cli expire {} 3600 2>/dev/null || true
942
+ fi
943
+ }
944
+
945
+ # Trap cleanup on script exit
946
+ trap cleanup_redis_keys EXIT
947
+
881
948
  # Max iterations reached without success
882
949
  echo "❌ Max iterations ($MAX_ITERATIONS) reached without PROCEED decision"
883
950
  output_result "failed"