claude-flow-novice 2.14.32 → 2.14.33
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/skills/pre-edit-backup/backup.sh +107 -0
- package/claude-assets/agents/cfn-dev-team/coordinators/cfn-v3-coordinator.md +71 -9
- package/claude-assets/skills/cfn-redis-data-extraction/SKILL.md +442 -0
- package/claude-assets/skills/cfn-redis-data-extraction/extract.sh +306 -0
- package/claude-assets/skills/hook-pipeline/security-scanner.sh +102 -0
- package/claude-assets/skills/pre-edit-backup/backup.sh +107 -0
- package/package.json +13 -4
- package/scripts/deploy-production.sh +356 -0
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
##############################################################################
|
|
4
|
+
# Pre-Edit Backup Script - Creates safe file backups before modifications
|
|
5
|
+
# Version: 1.0.0
|
|
6
|
+
##############################################################################
|
|
7
|
+
|
|
8
|
+
set -euo pipefail
|
|
9
|
+
|
|
10
|
+
# Function to create backup of a file before editing
|
|
11
|
+
create_backup() {
|
|
12
|
+
local file_path="$1"
|
|
13
|
+
local agent_id="${2:-unknown}"
|
|
14
|
+
local project_root="${3:-$(pwd)}"
|
|
15
|
+
|
|
16
|
+
# Validate inputs
|
|
17
|
+
if [[ -z "$file_path" ]]; then
|
|
18
|
+
echo "Error: File path is required" >&2
|
|
19
|
+
exit 1
|
|
20
|
+
fi
|
|
21
|
+
|
|
22
|
+
# Check if file exists
|
|
23
|
+
if [[ ! -f "$file_path" ]]; then
|
|
24
|
+
echo "Warning: File does not exist: $file_path" >&2
|
|
25
|
+
# Create empty backup path for new files
|
|
26
|
+
echo "$project_root/.backups/$agent_id/new-file-$(date +%s)-$(echo "$file_path" | tr '/' '_' | tr ' ' '_')"
|
|
27
|
+
return 0
|
|
28
|
+
fi
|
|
29
|
+
|
|
30
|
+
# Create backup directory structure
|
|
31
|
+
local backup_dir="$project_root/.backups/$agent_id"
|
|
32
|
+
local timestamp=$(date +%s)
|
|
33
|
+
local file_hash=$(md5sum "$file_path" | cut -d' ' -f1)
|
|
34
|
+
local backup_name="${timestamp}_${file_hash}"
|
|
35
|
+
|
|
36
|
+
# Create full backup path
|
|
37
|
+
local full_backup_path="$backup_dir/$backup_name"
|
|
38
|
+
|
|
39
|
+
# Create backup directory
|
|
40
|
+
mkdir -p "$full_backup_path"
|
|
41
|
+
|
|
42
|
+
# Copy original file to backup location
|
|
43
|
+
cp "$file_path" "$full_backup_path/original"
|
|
44
|
+
|
|
45
|
+
# Store backup metadata
|
|
46
|
+
cat > "$full_backup_path/metadata.json" << EOF
|
|
47
|
+
{
|
|
48
|
+
"timestamp": "$timestamp",
|
|
49
|
+
"agent_id": "$agent_id",
|
|
50
|
+
"original_file": "$file_path",
|
|
51
|
+
"file_hash": "$file_hash",
|
|
52
|
+
"backup_path": "$full_backup_path",
|
|
53
|
+
"created_at": "$(date -u +%Y-%m-%dT%H:%M:%SZ)"
|
|
54
|
+
}
|
|
55
|
+
EOF
|
|
56
|
+
|
|
57
|
+
# Create revert script
|
|
58
|
+
cat > "$full_backup_path/revert.sh" << EOF
|
|
59
|
+
#!/bin/bash
|
|
60
|
+
# Revert script for $file_path
|
|
61
|
+
set -euo pipefail
|
|
62
|
+
|
|
63
|
+
echo "Reverting file: $file_path"
|
|
64
|
+
cp "$full_backup_path/original" "$file_path"
|
|
65
|
+
echo "✅ File reverted successfully"
|
|
66
|
+
EOF
|
|
67
|
+
|
|
68
|
+
chmod +x "$full_backup_path/revert.sh"
|
|
69
|
+
|
|
70
|
+
# Output backup path for caller
|
|
71
|
+
echo "$full_backup_path"
|
|
72
|
+
|
|
73
|
+
echo "✅ Backup created: $full_backup_path" >&2
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
# Main execution
|
|
77
|
+
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
|
|
78
|
+
# Script called directly
|
|
79
|
+
if [[ $# -lt 1 ]]; then
|
|
80
|
+
echo "Usage: $0 <file_path> [--agent-id <id>] [--project-root <path>]" >&2
|
|
81
|
+
exit 1
|
|
82
|
+
fi
|
|
83
|
+
|
|
84
|
+
file_path="$1"
|
|
85
|
+
agent_id="unknown"
|
|
86
|
+
project_root="$(pwd)"
|
|
87
|
+
|
|
88
|
+
# Parse optional arguments
|
|
89
|
+
while [[ $# -gt 0 ]]; do
|
|
90
|
+
case $1 in
|
|
91
|
+
--agent-id)
|
|
92
|
+
agent_id="$2"
|
|
93
|
+
shift 2
|
|
94
|
+
;;
|
|
95
|
+
--project-root)
|
|
96
|
+
project_root="$2"
|
|
97
|
+
shift 2
|
|
98
|
+
;;
|
|
99
|
+
*)
|
|
100
|
+
# Skip unknown arguments
|
|
101
|
+
shift
|
|
102
|
+
;;
|
|
103
|
+
esac
|
|
104
|
+
done
|
|
105
|
+
|
|
106
|
+
create_backup "$file_path" "$agent_id" "$project_root"
|
|
107
|
+
fi
|
|
@@ -16,18 +16,16 @@ You coordinate CFN Loop v3 execution with Redis-based agent orchestration and CL
|
|
|
16
16
|
|
|
17
17
|
Orchestrate CFN Loop v3 execution using Redis coordination for CLI agent spawning, context management, and consensus collection.
|
|
18
18
|
|
|
19
|
-
## Mode
|
|
19
|
+
## CLI Mode Execution (Coordinator is ALWAYS CLI Mode)
|
|
20
20
|
|
|
21
|
-
**CLI
|
|
21
|
+
**IMPORTANT:** This coordinator agent is **ALWAYS CLI mode**. Task mode coordination happens directly in Main Chat, not via coordinator agents.
|
|
22
|
+
|
|
23
|
+
When spawned via CLI (`npx claude-flow-novice agent-spawn`), implement full Redis coordination:
|
|
22
24
|
- Use Redis coordination for agent spawning
|
|
23
25
|
- Store context in Redis for swarm recovery
|
|
24
26
|
- Collect confidence scores via Redis signals
|
|
25
27
|
- Use background execution with monitoring
|
|
26
|
-
|
|
27
|
-
**Task Mode (Debugging):**
|
|
28
|
-
- Direct Task() spawning (no Redis needed)
|
|
29
|
-
- Main Chat handles coordination
|
|
30
|
-
- Simple JSON response only
|
|
28
|
+
- **ALWAYS invoke the orchestrator** - never handle tasks directly
|
|
31
29
|
|
|
32
30
|
## Redis Coordination Protocols
|
|
33
31
|
|
|
@@ -494,11 +492,75 @@ Extract deliverables from task description:
|
|
|
494
492
|
- Estimate iteration count
|
|
495
493
|
- Provide reasoning for choices
|
|
496
494
|
|
|
495
|
+
## Execution Steps (CLI Mode Only)
|
|
496
|
+
|
|
497
|
+
**CRITICAL:** This coordinator is ALWAYS CLI mode. There is no Task Mode execution path.
|
|
498
|
+
|
|
499
|
+
### Step 1: Task Classification (REQUIRED)
|
|
500
|
+
```bash
|
|
501
|
+
# Classify task type (use hardcoded defaults if script fails)
|
|
502
|
+
TASK_TYPE="infrastructure" # Default fallback
|
|
503
|
+
if [[ -f ".claude/skills/task-classifier/classify-task.sh" ]]; then
|
|
504
|
+
CLASSIFIED_TYPE=$(bash .claude/skills/task-classifier/classify-task.sh "$TASK_DESCRIPTION" 2>/dev/null || echo "")
|
|
505
|
+
[[ -n "$CLASSIFIED_TYPE" ]] && TASK_TYPE="$CLASSIFIED_TYPE"
|
|
506
|
+
fi
|
|
507
|
+
```
|
|
508
|
+
|
|
509
|
+
### Step 2: Agent Selection with Fallback (REQUIRED)
|
|
510
|
+
```bash
|
|
511
|
+
# Select agents with hardcoded fallbacks (never fail)
|
|
512
|
+
LOOP3_AGENTS="terraform-engineer,devops-engineer" # Infrastructure default
|
|
513
|
+
LOOP2_AGENTS="security-auditor,compliance-checker,cost-optimizer" # Validation default
|
|
514
|
+
PRODUCT_OWNER="product-owner"
|
|
515
|
+
|
|
516
|
+
# Try dynamic selection but fall back to defaults
|
|
517
|
+
if [[ -f ".claude/skills/cfn-agent-selector/select-agents.sh" ]]; then
|
|
518
|
+
SELECTED_AGENTS=$(bash .claude/skills/cfn-agent-selector/select-agents.sh --task-type "$TASK_TYPE" --description "$TASK_DESCRIPTION" 2>/dev/null || echo "")
|
|
519
|
+
if [[ -n "$SELECTED_AGENTS" ]]; then
|
|
520
|
+
PARSED_AGENTS=$(echo "$SELECTED_AGENTS" | jq -r '.loop3 // empty | join(",")')
|
|
521
|
+
[[ -n "$PARSED_AGENTS" ]] && LOOP3_AGENTS="$PARSED_AGENTS"
|
|
522
|
+
|
|
523
|
+
PARSED_AGENTS=$(echo "$SELECTED_AGENTS" | jq -r '.loop2 // empty | join(",")')
|
|
524
|
+
[[ -n "$PARSED_AGENTS" ]] && LOOP2_AGENTS="$PARSED_AGENTS"
|
|
525
|
+
fi
|
|
526
|
+
fi
|
|
527
|
+
```
|
|
528
|
+
|
|
529
|
+
### Step 3: INVOKE ORCHESTRATOR (MANDATORY - NOT OPTIONAL)
|
|
530
|
+
|
|
531
|
+
**CRITICAL:** You MUST invoke orchestrator by iteration 3. DO NOT complete tasks directly.
|
|
532
|
+
|
|
533
|
+
```bash
|
|
534
|
+
# ALWAYS invoke orchestrator - this is your ONLY responsibility
|
|
535
|
+
./.claude/skills/cfn-loop-orchestration/orchestrate.sh \
|
|
536
|
+
--task-id "$TASK_ID" \
|
|
537
|
+
--mode "standard" \
|
|
538
|
+
--loop3-agents "$LOOP3_AGENTS" \
|
|
539
|
+
--loop2-agents "$LOOP2_AGENTS" \
|
|
540
|
+
--product-owner "$PRODUCT_OWNER" \
|
|
541
|
+
--max-iterations 10 \
|
|
542
|
+
--success-criteria '{"deliverables":[],"acceptanceCriteria":["Implementation complete"]}'
|
|
543
|
+
|
|
544
|
+
# The orchestrator handles ALL CFN Loop execution including:
|
|
545
|
+
# - Loop 3 agent spawning and iteration
|
|
546
|
+
# - Loop 2 validator spawning and consensus
|
|
547
|
+
# - Product Owner decision (PROCEED/ITERATE/ABORT)
|
|
548
|
+
# - Git commit and push (on PROCEED)
|
|
549
|
+
# - Sprint summary generation
|
|
550
|
+
|
|
551
|
+
# Your job is complete after invoking this command - DO NOT wait for results
|
|
552
|
+
```
|
|
553
|
+
|
|
554
|
+
**EXECUTION GUARANTEE:**
|
|
555
|
+
- If steps 1-2 fail, use hardcoded defaults and proceed to step 3
|
|
556
|
+
- **Never exit without invoking orchestrator**
|
|
557
|
+
- **Orchestrator invocation MUST happen by iteration 3**
|
|
558
|
+
- This coordinator's ONLY job is to configure and invoke the orchestrator
|
|
559
|
+
|
|
497
560
|
## Success Metrics
|
|
498
561
|
|
|
499
562
|
- Agent selections match domain expertise
|
|
500
563
|
- Validation criteria cover all critical requirements
|
|
501
564
|
- Deliverable list is comprehensive
|
|
502
565
|
- Confidence score ≥ 0.85 in analysis quality
|
|
503
|
-
|
|
504
|
-
Provide structured output with confidence score based on analysis completeness and agent selection appropriateness.
|
|
566
|
+
- **CRITICAL: Orchestrator invoked successfully**
|
|
@@ -0,0 +1,442 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: cfn-redis-data-extraction
|
|
3
|
+
description: Extract complete Redis coordination data from completed CFN Loop tasks and structure into comprehensive JSON analysis files
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
author: CFN System
|
|
6
|
+
category: coordination
|
|
7
|
+
tags: [cfn, redis, data-extraction, coordination, loop-analysis]
|
|
8
|
+
|
|
9
|
+
# CFN Redis Data Extraction Skill
|
|
10
|
+
|
|
11
|
+
## Purpose
|
|
12
|
+
|
|
13
|
+
Extracts complete Redis coordination data from completed CFN Loop tasks and structures it into comprehensive JSON files for analysis, auditing, and performance tracking.
|
|
14
|
+
|
|
15
|
+
## When to Use
|
|
16
|
+
|
|
17
|
+
- **Mandatory**: Execute after each completed CFN Loop task
|
|
18
|
+
- **Timing**: After Product Owner decision, before Redis cleanup
|
|
19
|
+
- **Trigger**: Main Chat coordination after loop completion
|
|
20
|
+
- **Scope**: All Redis keys for a specific task ID
|
|
21
|
+
|
|
22
|
+
## Usage
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
# Extract data from completed CFN Loop
|
|
26
|
+
npx claude-flow-novice skill cfn-redis-data-extraction --task-id "cfn-cli-XXXXXXX-XXXXX"
|
|
27
|
+
|
|
28
|
+
# Extract with custom output directory
|
|
29
|
+
npx claude-flow-novice skill cfn-redis-data-extraction \
|
|
30
|
+
--task-id "cfn-cli-XXXXXXX-XXXXX" \
|
|
31
|
+
--output-dir "./analysis/loop-data"
|
|
32
|
+
|
|
33
|
+
# Extract multiple tasks
|
|
34
|
+
npx claude-flow-novice skill cfn-redis-data-extraction \
|
|
35
|
+
--task-ids "cfn-cli-XXXXXXX-XXXXX,cfn-cli-YYYYYYY-YYYYY"
|
|
36
|
+
|
|
37
|
+
# Extract with detailed performance metrics
|
|
38
|
+
npx claude-flow-novice skill cfn-redis-data-extraction \
|
|
39
|
+
--task-id "cfn-cli-XXXXXXX-XXXXX" \
|
|
40
|
+
--include-performance=true
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Implementation
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
#!/bin/bash
|
|
47
|
+
# CFN Redis Data Extraction Script
|
|
48
|
+
|
|
49
|
+
set -euo pipefail
|
|
50
|
+
|
|
51
|
+
# Default values
|
|
52
|
+
OUTPUT_DIR="./analysis/cfn-loop-data"
|
|
53
|
+
INCLUDE_PERFORMANCE=false
|
|
54
|
+
TASK_IDS=()
|
|
55
|
+
VERBOSE=false
|
|
56
|
+
|
|
57
|
+
# Parse arguments
|
|
58
|
+
while [[ $# -gt 0 ]]; do
|
|
59
|
+
case $1 in
|
|
60
|
+
--task-id)
|
|
61
|
+
TASK_IDS+=("$2")
|
|
62
|
+
shift 2
|
|
63
|
+
;;
|
|
64
|
+
--task-ids)
|
|
65
|
+
IFS=',' read -ra TASK_IDS <<< "$2"
|
|
66
|
+
shift 2
|
|
67
|
+
;;
|
|
68
|
+
--output-dir)
|
|
69
|
+
OUTPUT_DIR="$2"
|
|
70
|
+
shift 2
|
|
71
|
+
;;
|
|
72
|
+
--include-performance)
|
|
73
|
+
INCLUDE_PERFORMANCE=true
|
|
74
|
+
shift
|
|
75
|
+
;;
|
|
76
|
+
--verbose)
|
|
77
|
+
VERBOSE=true
|
|
78
|
+
shift
|
|
79
|
+
;;
|
|
80
|
+
-h|--help)
|
|
81
|
+
echo "Usage: $0 --task-id <TASK_ID> [--output-dir <DIR>] [--include-performance] [--verbose]"
|
|
82
|
+
exit 0
|
|
83
|
+
;;
|
|
84
|
+
*)
|
|
85
|
+
echo "Unknown option: $1"
|
|
86
|
+
exit 1
|
|
87
|
+
;;
|
|
88
|
+
esac
|
|
89
|
+
done
|
|
90
|
+
|
|
91
|
+
# Validate required arguments
|
|
92
|
+
if [[ ${#TASK_IDS[@]} -eq 0 ]]; then
|
|
93
|
+
echo "Error: --task-id or --task-ids is required"
|
|
94
|
+
exit 1
|
|
95
|
+
fi
|
|
96
|
+
|
|
97
|
+
# Create output directory
|
|
98
|
+
mkdir -p "$OUTPUT_DIR"
|
|
99
|
+
|
|
100
|
+
# Redis connection check
|
|
101
|
+
if ! redis-cli ping > /dev/null 2>&1; then
|
|
102
|
+
echo "Error: Redis is not accessible"
|
|
103
|
+
exit 1
|
|
104
|
+
fi
|
|
105
|
+
|
|
106
|
+
# Function to extract task data
|
|
107
|
+
extract_task_data() {
|
|
108
|
+
local task_id="$1"
|
|
109
|
+
local output_file="$OUTPUT_DIR/cfn-loop-${task_id}-extracted.json"
|
|
110
|
+
|
|
111
|
+
[[ "$VERBOSE" == true ]] && echo "Extracting data for task: $task_id"
|
|
112
|
+
|
|
113
|
+
# Get all Redis keys for the task
|
|
114
|
+
local redis_keys
|
|
115
|
+
redis_keys=$(redis-cli keys "*${task_id}*" 2>/dev/null | sort)
|
|
116
|
+
|
|
117
|
+
if [[ -z "$redis_keys" ]]; then
|
|
118
|
+
echo "Warning: No Redis keys found for task: $task_id"
|
|
119
|
+
return 1
|
|
120
|
+
fi
|
|
121
|
+
|
|
122
|
+
# Initialize JSON structure
|
|
123
|
+
local json_data
|
|
124
|
+
json_data=$(cat << EOF
|
|
125
|
+
{
|
|
126
|
+
"task_id": "$task_id",
|
|
127
|
+
"extraction_timestamp": "$(date -u +%Y-%m-%dT%H:%M:%SZ)",
|
|
128
|
+
"extraction_version": "1.0.0",
|
|
129
|
+
"redis_keys_analyzed": $(echo "$redis_keys" | wc -l),
|
|
130
|
+
"agents": {},
|
|
131
|
+
"metadata": {},
|
|
132
|
+
"summary": {}
|
|
133
|
+
}
|
|
134
|
+
EOF
|
|
135
|
+
)
|
|
136
|
+
|
|
137
|
+
# Process each Redis key
|
|
138
|
+
local agent_count=0
|
|
139
|
+
local completion_signals=0
|
|
140
|
+
local total_confidence=0
|
|
141
|
+
local confidence_count=0
|
|
142
|
+
|
|
143
|
+
while IFS= read -r key; do
|
|
144
|
+
[[ -z "$key" ]] && continue
|
|
145
|
+
|
|
146
|
+
# Skip if not a swarm key
|
|
147
|
+
[[ ! "$key" =~ ^swarm: ]] && continue
|
|
148
|
+
|
|
149
|
+
# Extract agent information from key
|
|
150
|
+
local agent_type=""
|
|
151
|
+
local agent_id=""
|
|
152
|
+
local loop_number=""
|
|
153
|
+
local data_type=""
|
|
154
|
+
|
|
155
|
+
if [[ "$key" =~ ^swarm:([^:]+):([^:]+):([^:]+)$ ]]; then
|
|
156
|
+
agent_id="${BASH_REMATCH[2]}"
|
|
157
|
+
data_type="${BASH_REMATCH[3]}"
|
|
158
|
+
|
|
159
|
+
# Determine agent type and loop
|
|
160
|
+
if [[ "$agent_id" =~ ^cfn-v3-coordinator ]]; then
|
|
161
|
+
agent_type="coordinator"
|
|
162
|
+
loop_number="coordination"
|
|
163
|
+
elif [[ "$agent_id" =~ -validation$ ]]; then
|
|
164
|
+
agent_type="${agent_id%-validation}"
|
|
165
|
+
loop_number="2"
|
|
166
|
+
elif [[ "$agent_id" =~ -1$ ]] || [[ "$agent_id" =~ -2$ ]] || [[ "$agent_id" =~ -3$ ]]; then
|
|
167
|
+
agent_type="${agent_id%-1}"
|
|
168
|
+
agent_type="${agent_type%-2}"
|
|
169
|
+
agent_type="${agent_type%-3}"
|
|
170
|
+
loop_number="3"
|
|
171
|
+
elif [[ "$agent_id" =~ product-owner$ ]]; then
|
|
172
|
+
agent_type="product-owner"
|
|
173
|
+
loop_number="4"
|
|
174
|
+
else
|
|
175
|
+
agent_type="$agent_id"
|
|
176
|
+
loop_number="unknown"
|
|
177
|
+
fi
|
|
178
|
+
|
|
179
|
+
# Initialize agent in JSON if not exists
|
|
180
|
+
if [[ ! "$json_data" =~ "\"$agent_id\":" ]]; then
|
|
181
|
+
((agent_count++))
|
|
182
|
+
json_data=$(echo "$json_data" | jq ".agents += {\"$agent_id\": {\"agent_type\": \"$agent_type\", \"loop\": \"$loop_number\", \"data\": {}}}")
|
|
183
|
+
fi
|
|
184
|
+
|
|
185
|
+
# Extract data based on type
|
|
186
|
+
case "$data_type" in
|
|
187
|
+
"confidence")
|
|
188
|
+
local confidence
|
|
189
|
+
confidence=$(redis-cli get "$key" 2>/dev/null || echo "null")
|
|
190
|
+
json_data=$(echo "$json_data" | jq ".agents[\"$agent_id\"].confidence = $confidence")
|
|
191
|
+
total_confidence=$(echo "$total_confidence + $confidence" | bc -l 2>/dev/null || echo "$total_confidence")
|
|
192
|
+
((confidence_count++))
|
|
193
|
+
;;
|
|
194
|
+
"done")
|
|
195
|
+
local completion_signal
|
|
196
|
+
completion_signal=$(redis-cli lrange "$key" 0 -1 2>/dev/null | head -1 || echo "null")
|
|
197
|
+
json_data=$(echo "$json_data" | jq ".agents[\"$agent_id\"].completion_signal = \"$completion_signal\"")
|
|
198
|
+
((completion_signals++))
|
|
199
|
+
;;
|
|
200
|
+
"messages")
|
|
201
|
+
local messages_json="[]"
|
|
202
|
+
local message_count
|
|
203
|
+
message_count=$(redis-cli llen "$key" 2>/dev/null || echo "0")
|
|
204
|
+
|
|
205
|
+
if [[ "$message_count" -gt 0 ]]; then
|
|
206
|
+
messages_json=$(redis-cli lrange "$key" 0 -1 2>/dev/null | jq -R . | jq -s .)
|
|
207
|
+
fi
|
|
208
|
+
|
|
209
|
+
json_data=$(echo "$json_data" | jq ".agents[\"$agent_id\"].messages = $messages_json")
|
|
210
|
+
;;
|
|
211
|
+
"result")
|
|
212
|
+
local result
|
|
213
|
+
result=$(redis-cli get "$key" 2>/dev/null || echo "null")
|
|
214
|
+
json_data=$(echo "$json_data" | jq ".agents[\"$agent_id\"].result = \"$result\"")
|
|
215
|
+
;;
|
|
216
|
+
esac
|
|
217
|
+
fi
|
|
218
|
+
done <<< "$redis_keys"
|
|
219
|
+
|
|
220
|
+
# Calculate averages and summary
|
|
221
|
+
local avg_confidence="0"
|
|
222
|
+
if [[ "$confidence_count" -gt 0 ]]; then
|
|
223
|
+
avg_confidence=$(echo "scale=3; $total_confidence / $confidence_count" | bc -l)
|
|
224
|
+
fi
|
|
225
|
+
|
|
226
|
+
# Extract task context if available
|
|
227
|
+
local task_context
|
|
228
|
+
task_context=$(redis-cli get "cfn_loop:task:$task_id:context" 2>/dev/null || echo "{}")
|
|
229
|
+
|
|
230
|
+
# Update summary
|
|
231
|
+
json_data=$(echo "$json_data" | jq "
|
|
232
|
+
.summary += {
|
|
233
|
+
\"total_agents\": $agent_count,
|
|
234
|
+
\"completion_signals\": $completion_signals,
|
|
235
|
+
\"average_confidence\": $avg_confidence,
|
|
236
|
+
\"confidence_scores_count\": $confidence_count,
|
|
237
|
+
\"extraction_status\": \"success\"
|
|
238
|
+
}
|
|
239
|
+
")
|
|
240
|
+
|
|
241
|
+
# Add task context
|
|
242
|
+
json_data=$(echo "$json_data" | jq ".metadata.task_context = \"$task_context\"")
|
|
243
|
+
|
|
244
|
+
# Add performance metrics if requested
|
|
245
|
+
if [[ "$INCLUDE_PERFORMANCE" == true ]]; then
|
|
246
|
+
local performance_metrics
|
|
247
|
+
performance_metrics=$(cat << EOF
|
|
248
|
+
{
|
|
249
|
+
"redis_memory_usage": $(redis-cli info memory 2>/dev/null | grep "used_memory_human" | cut -d: -f2 | tr -d '\r' || echo "\"unknown\""),
|
|
250
|
+
"redis_connected_clients": $(redis-cli info clients 2>/dev/null | grep "connected_clients" | cut -d: -f2 | tr -d '\r' || echo "0"),
|
|
251
|
+
"extraction_duration_ms": 0
|
|
252
|
+
}
|
|
253
|
+
EOF
|
|
254
|
+
)
|
|
255
|
+
json_data=$(echo "$json_data" | jq ".metadata.performance = $performance_metrics")
|
|
256
|
+
fi
|
|
257
|
+
|
|
258
|
+
# Write to file
|
|
259
|
+
echo "$json_data" | jq '.' > "$output_file"
|
|
260
|
+
|
|
261
|
+
[[ "$VERBOSE" == true ]] && echo "Data extracted to: $output_file"
|
|
262
|
+
|
|
263
|
+
# Generate summary report
|
|
264
|
+
local summary_file="$OUTPUT_DIR/cfn-loop-${task_id}-summary.txt"
|
|
265
|
+
cat > "$summary_file" << EOF
|
|
266
|
+
CFN Loop Data Extraction Summary
|
|
267
|
+
================================
|
|
268
|
+
|
|
269
|
+
Task ID: $task_id
|
|
270
|
+
Extraction Time: $(date -u +%Y-%m-%dT%H:%M:%SZ)
|
|
271
|
+
Output File: $output_file
|
|
272
|
+
|
|
273
|
+
Statistics:
|
|
274
|
+
- Redis Keys Analyzed: $(echo "$redis_keys" | wc -l)
|
|
275
|
+
- Total Agents: $agent_count
|
|
276
|
+
- Completion Signals: $completion_signals
|
|
277
|
+
- Average Confidence: $avg_confidence
|
|
278
|
+
- Confidence Scores: $confidence_count
|
|
279
|
+
|
|
280
|
+
Agent Types:
|
|
281
|
+
$(echo "$json_data" | jq -r '.agents | to_entries[] | "- \(.key): \(.value.agent_type) (Loop \(.value.loop))"')
|
|
282
|
+
|
|
283
|
+
Status: Successfully extracted
|
|
284
|
+
EOF
|
|
285
|
+
|
|
286
|
+
[[ "$VERBOSE" == true ]] && echo "Summary report generated: $summary_file"
|
|
287
|
+
|
|
288
|
+
return 0
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
# Main execution
|
|
292
|
+
echo "CFN Redis Data Extraction Started"
|
|
293
|
+
echo "================================="
|
|
294
|
+
echo "Output Directory: $OUTPUT_DIR"
|
|
295
|
+
echo "Include Performance: $INCLUDE_PERFORMANCE"
|
|
296
|
+
echo ""
|
|
297
|
+
|
|
298
|
+
# Process each task
|
|
299
|
+
for task_id in "${TASK_IDS[@]}"; do
|
|
300
|
+
echo "Processing task: $task_id"
|
|
301
|
+
if extract_task_data "$task_id"; then
|
|
302
|
+
echo "✅ Successfully extracted data for: $task_id"
|
|
303
|
+
else
|
|
304
|
+
echo "❌ Failed to extract data for: $task_id"
|
|
305
|
+
fi
|
|
306
|
+
echo ""
|
|
307
|
+
done
|
|
308
|
+
|
|
309
|
+
echo "CFN Redis Data Extraction Completed"
|
|
310
|
+
echo "==================================="
|
|
311
|
+
echo "Output Directory: $OUTPUT_DIR"
|
|
312
|
+
echo "Files Generated:"
|
|
313
|
+
find "$OUTPUT_DIR" -name "cfn-loop-*.json" -o -name "cfn-loop-*.txt" | while read -r file; do
|
|
314
|
+
echo " - $file"
|
|
315
|
+
done
|
|
316
|
+
|
|
317
|
+
exit 0
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
## Parameters
|
|
321
|
+
|
|
322
|
+
| Parameter | Type | Required | Description |
|
|
323
|
+
|-----------|------|----------|-------------|
|
|
324
|
+
| `--task-id` | string | Yes | Single CFN Loop task ID to extract |
|
|
325
|
+
| `--task-ids` | string | No | Comma-separated list of task IDs |
|
|
326
|
+
| `--output-dir` | string | No | Output directory (default: ./analysis/cfn-loop-data) |
|
|
327
|
+
| `--include-performance` | boolean | No | Include Redis performance metrics |
|
|
328
|
+
| `--verbose` | boolean | No | Enable verbose output |
|
|
329
|
+
|
|
330
|
+
## Output Structure
|
|
331
|
+
|
|
332
|
+
The skill generates two files per task:
|
|
333
|
+
|
|
334
|
+
### 1. Main JSON Data File
|
|
335
|
+
`cfn-loop-{task_id}-extracted.json`
|
|
336
|
+
|
|
337
|
+
```json
|
|
338
|
+
{
|
|
339
|
+
"task_id": "cfn-cli-543042-13483",
|
|
340
|
+
"extraction_timestamp": "2025-11-09T04:56:00Z",
|
|
341
|
+
"extraction_version": "1.0.0",
|
|
342
|
+
"redis_keys_analyzed": 44,
|
|
343
|
+
"agents": {
|
|
344
|
+
"cfn-v3-coordinator-1": {
|
|
345
|
+
"agent_type": "coordinator",
|
|
346
|
+
"loop": "coordination",
|
|
347
|
+
"confidence": 0.85,
|
|
348
|
+
"completion_signal": "complete",
|
|
349
|
+
"messages": [...],
|
|
350
|
+
"result": "..."
|
|
351
|
+
},
|
|
352
|
+
"agent-id-2": {
|
|
353
|
+
"agent_type": "frontend-developer",
|
|
354
|
+
"loop": "3",
|
|
355
|
+
"confidence": 0.92,
|
|
356
|
+
"completion_signal": "complete"
|
|
357
|
+
}
|
|
358
|
+
},
|
|
359
|
+
"metadata": {
|
|
360
|
+
"task_context": "...",
|
|
361
|
+
"performance": {
|
|
362
|
+
"redis_memory_usage": "2.5M",
|
|
363
|
+
"redis_connected_clients": 12
|
|
364
|
+
}
|
|
365
|
+
},
|
|
366
|
+
"summary": {
|
|
367
|
+
"total_agents": 11,
|
|
368
|
+
"completion_signals": 11,
|
|
369
|
+
"average_confidence": 0.86,
|
|
370
|
+
"extraction_status": "success"
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
```
|
|
374
|
+
|
|
375
|
+
### 2. Summary Text File
|
|
376
|
+
`cfn-loop-{task_id}-summary.txt`
|
|
377
|
+
|
|
378
|
+
Human-readable summary with key statistics and agent information.
|
|
379
|
+
|
|
380
|
+
## Integration Points
|
|
381
|
+
|
|
382
|
+
### CFN Loop Completion Workflow
|
|
383
|
+
```bash
|
|
384
|
+
# After Product Owner decision, before Redis cleanup
|
|
385
|
+
./.claude/skills/cfn-redis-data-extraction/extract.sh \
|
|
386
|
+
--task-id "$TASK_ID" \
|
|
387
|
+
--output-dir "./analysis/loops" \
|
|
388
|
+
--include-performance=true
|
|
389
|
+
|
|
390
|
+
# Then proceed with Redis cleanup
|
|
391
|
+
redis-cli DEL "cfn_loop:task:$TASK_ID:*" "swarm:$TASK_ID:*"
|
|
392
|
+
```
|
|
393
|
+
|
|
394
|
+
### Main Chat Automation
|
|
395
|
+
```bash
|
|
396
|
+
# Automatic extraction after loop completion
|
|
397
|
+
npx claude-flow-novice skill cfn-redis-data-extraction \
|
|
398
|
+
--task-id "cfn-cli-XXXXXXX-XXXXX" \
|
|
399
|
+
--verbose
|
|
400
|
+
```
|
|
401
|
+
|
|
402
|
+
## Error Handling
|
|
403
|
+
|
|
404
|
+
- **Redis Unavailable**: Graceful exit with error message
|
|
405
|
+
- **No Keys Found**: Warning message, continue processing
|
|
406
|
+
- **Invalid JSON**: Fallback to basic text extraction
|
|
407
|
+
- **Permission Issues**: Directory creation with appropriate permissions
|
|
408
|
+
|
|
409
|
+
## Performance Considerations
|
|
410
|
+
|
|
411
|
+
- **Large Key Sets**: Processes keys in batches to avoid memory issues
|
|
412
|
+
- **Concurrent Access**: Uses read-only Redis operations
|
|
413
|
+
- **File Size**: JSON files are compressed and structured efficiently
|
|
414
|
+
- **Extraction Time**: Typically <5 seconds per task
|
|
415
|
+
|
|
416
|
+
## Validation
|
|
417
|
+
|
|
418
|
+
The skill includes built-in validation:
|
|
419
|
+
- Redis connectivity check
|
|
420
|
+
- JSON structure validation
|
|
421
|
+
- Data completeness verification
|
|
422
|
+
- Output file creation confirmation
|
|
423
|
+
|
|
424
|
+
## Maintenance
|
|
425
|
+
|
|
426
|
+
- **Version Tracking**: Each extraction includes version metadata
|
|
427
|
+
- **Backward Compatibility**: Supports multiple extraction formats
|
|
428
|
+
- **Cleanup**: Old files can be archived or cleaned up automatically
|
|
429
|
+
- **Monitoring**: Integration with system monitoring for extraction success rates
|
|
430
|
+
|
|
431
|
+
## Related Skills
|
|
432
|
+
|
|
433
|
+
- `cfn-redis-coordination` - For understanding Redis coordination patterns
|
|
434
|
+
- `cfn-loop-validation` - For validating loop execution
|
|
435
|
+
- `cfn-agent-spawning` - For understanding agent lifecycle
|
|
436
|
+
|
|
437
|
+
## Dependencies
|
|
438
|
+
|
|
439
|
+
- `redis-cli` - Redis command-line interface
|
|
440
|
+
- `jq` - JSON processor for data manipulation
|
|
441
|
+
- `bc` - Basic calculator for confidence averaging
|
|
442
|
+
- Standard Unix utilities (grep, awk, sed)
|