claude-flow-novice 2.14.6 → 2.14.8

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 (66) hide show
  1. package/.claude/commands/cfn/run-tests.md +119 -0
  2. package/.claude/hooks/cfn-post-edit.config.json +11 -4
  3. package/.claude/skills/cfn-agent-selector/SKILL.md +3 -2
  4. package/.claude/skills/cfn-loop-orchestration/orchestrate.sh +1 -1
  5. package/.claude/skills/cfn-product-owner-decision/execute-decision.sh +207 -113
  6. package/.claude/skills/cfn-product-owner-decision/test-backlog-integration.sh +148 -0
  7. package/.claude/skills/cfn-redis-coordination/report-completion.sh +86 -0
  8. package/.claude/skills/cfn-redis-coordination/store-context.sh +34 -0
  9. package/.claude/skills/pre-edit-backup/backup.sh +130 -0
  10. package/.claude/skills/pre-edit-backup/cleanup.sh +155 -0
  11. package/.claude/skills/pre-edit-backup/restore.sh +128 -0
  12. package/.claude/skills/pre-edit-backup/revert-file.sh +168 -0
  13. package/claude-assets/agents/README-AGENT_LIFECYCLE.md +522 -0
  14. package/claude-assets/agents/cfn-dev-team/coordinators/cfn-v3-coordinator.md +13 -8
  15. package/claude-assets/agents/cfn-dev-team/product-owners/product-owner.md +1 -1
  16. package/claude-assets/agents/cfn-dev-team/test-agent.md +141 -0
  17. package/claude-assets/agents/cfn-dev-team/utility/agent-builder.md +35 -0
  18. package/claude-assets/commands/cfn/run-tests.md +119 -0
  19. package/claude-assets/hooks/cfn-post-edit.config.json +11 -4
  20. package/claude-assets/skills/agent-name-validation/README.md +28 -0
  21. package/claude-assets/skills/agent-name-validation/SKILL.md +168 -0
  22. package/claude-assets/skills/agent-name-validation/validate-agent-names.sh +47 -0
  23. package/claude-assets/skills/cfn-agent-selector/SKILL.md +3 -2
  24. package/claude-assets/skills/cfn-loop-orchestration/orchestrate.sh +1 -1
  25. package/claude-assets/skills/cfn-product-owner-decision/execute-decision.sh +207 -113
  26. package/claude-assets/skills/cfn-product-owner-decision/test-backlog-integration.sh +148 -0
  27. package/claude-assets/skills/cfn-redis-coordination/report-completion.sh +86 -0
  28. package/claude-assets/skills/cfn-redis-coordination/store-context.sh +34 -0
  29. package/claude-assets/skills/cfn-task-classifier/SKILL.md +1 -1
  30. package/claude-assets/skills/cfn-test-runner/SKILL.md +288 -0
  31. package/claude-assets/skills/cfn-test-runner/detect-regressions.sh +55 -0
  32. package/claude-assets/skills/cfn-test-runner/init-benchmark-db.sh +48 -0
  33. package/claude-assets/skills/cfn-test-runner/run-all-tests.sh +222 -0
  34. package/claude-assets/skills/cfn-test-runner/store-benchmarks.sh +55 -0
  35. package/claude-assets/skills/cfn-test-runner/validate-redis-keys.sh +143 -0
  36. package/claude-assets/skills/hook-pipeline/bash-dependency-checker.sh +89 -0
  37. package/claude-assets/skills/hook-pipeline/bash-pipe-safety.sh +69 -0
  38. package/claude-assets/skills/hook-pipeline/enforce-lf.sh +36 -0
  39. package/claude-assets/skills/hook-pipeline/js-promise-safety.sh +110 -0
  40. package/claude-assets/skills/hook-pipeline/python-async-safety.py +124 -0
  41. package/claude-assets/skills/hook-pipeline/python-import-checker.py +114 -0
  42. package/claude-assets/skills/hook-pipeline/python-subprocess-safety.py +77 -0
  43. package/claude-assets/skills/hook-pipeline/rust-command-safety.sh +38 -0
  44. package/claude-assets/skills/hook-pipeline/rust-dependency-checker.sh +50 -0
  45. package/claude-assets/skills/hook-pipeline/rust-future-safety.sh +50 -0
  46. package/dist/agents/agent-loader.js +146 -165
  47. package/dist/agents/agent-loader.js.map +1 -1
  48. package/dist/cli/agent-executor.js +1 -1
  49. package/dist/cli/agent-executor.js.map +1 -1
  50. package/dist/cli/agent-prompt-builder.js +40 -30
  51. package/dist/cli/agent-prompt-builder.js.map +1 -1
  52. package/package.json +2 -1
  53. package/scripts/init-project.js +4 -1
  54. package/scripts/switch-api.sh +7 -7
  55. package/claude-assets/agents/cfn-dev-team/developers/dev-backend-api.md +0 -147
  56. package/claude-assets/agents/cfn-dev-team/developers/frontend/spec-mobile-react-native.md +0 -199
  57. package/claude-assets/agents/cfn-dev-team/documentation/docs-api-openapi.md +0 -98
  58. package/claude-assets/agents/cfn-dev-team/product-owners/product-owner-agent.md +0 -155
  59. package/claude-assets/agents/cfn-dev-team/reviewers/quality/analyze-code-quality.md +0 -141
  60. /package/claude-assets/agents/cfn-dev-team/developers/{backend-dev.md → backend-developer.md} +0 -0
  61. /package/claude-assets/agents/cfn-dev-team/documentation/{api-docs.md → api-documentation.md} +0 -0
  62. /package/claude-assets/agents/cfn-dev-team/documentation/{specification.md → specification-agent.md} +0 -0
  63. /package/claude-assets/agents/cfn-dev-team/reviewers/quality/{code-analyzer.md → code-quality-validator.md} +0 -0
  64. /package/claude-assets/agents/cfn-dev-team/testers/e2e/{playwright-agent.md → playwright-tester.md} +0 -0
  65. /package/claude-assets/agents/cfn-dev-team/testers/unit/{tdd-london-swarm.md → tdd-london-unit-swarm.md} +0 -0
  66. /package/claude-assets/agents/cfn-dev-team/testers/validation/{production-validator.md → validation-production-validator.md} +0 -0
@@ -0,0 +1,119 @@
1
+ ---
2
+ name: run-tests
3
+ description: Run CFN test suites with benchmarking and regression detection
4
+ category: testing
5
+ ---
6
+
7
+ # Run CFN Tests
8
+
9
+ Execute CFN test suites (Hello World + CFN E2E) with automatic benchmarking and regression detection.
10
+
11
+ ## Usage
12
+
13
+ ```bash
14
+ # Run all tests
15
+ /run-tests
16
+
17
+ # Run specific suite
18
+ /run-tests hello-world
19
+ /run-tests cfn-e2e
20
+
21
+ # With benchmarking
22
+ /run-tests --benchmark
23
+
24
+ # With regression detection
25
+ /run-tests --detect-regressions --threshold 0.10
26
+ ```
27
+
28
+ ## Execution
29
+
30
+ ```bash
31
+ ./.claude/skills/cfn-test-runner/run-all-tests.sh \
32
+ --suite {{arg1:-all}} \
33
+ {{#if benchmark}}--benchmark{{/if}} \
34
+ {{#if detect-regressions}}--detect-regressions --threshold {{threshold:-0.10}}{{/if}}
35
+ ```
36
+
37
+ ## Test Suites
38
+
39
+ ### Hello World (4 tests)
40
+ - Layer 0: Tool Validation (60s)
41
+ - Layer 5: Coordinator Spawning (120s)
42
+ - Layer 6: Review Handoff (180s)
43
+ - Layer 7: Error Retry (150s)
44
+
45
+ ### CFN E2E (9 tests)
46
+ - Coordinator → Orchestrator handoff
47
+ - Loop 3 → Gate Check
48
+ - Gate Pass → Loop 2
49
+ - Loop 2 → Product Owner
50
+ - Product Owner Decision
51
+ - Iteration Cycle
52
+ - Redis Key Structure
53
+ - Error Recovery
54
+ - Cleanup
55
+
56
+ ## Benchmarking
57
+
58
+ Results stored in `.artifacts/test-benchmarks.db`:
59
+ - Test run history (30 days)
60
+ - Success rate trends
61
+ - Duration tracking
62
+ - Git commit correlation
63
+
64
+ ## Regression Detection
65
+
66
+ Automatic alerts for:
67
+ - Test failures (was passing)
68
+ - Performance degradation (>10% slower)
69
+ - Success rate drops (>10% decrease)
70
+
71
+ View regressions:
72
+ ```sql
73
+ sqlite3 .artifacts/test-benchmarks.db "SELECT * FROM regression_alerts WHERE acknowledged = 0"
74
+ ```
75
+
76
+ ## Examples
77
+
78
+ **Standard test run:**
79
+ ```
80
+ /run-tests
81
+ ```
82
+
83
+ **With full benchmarking:**
84
+ ```
85
+ /run-tests --benchmark --detect-regressions
86
+ ```
87
+
88
+ **Specific suite only:**
89
+ ```
90
+ /run-tests cfn-e2e --benchmark
91
+ ```
92
+
93
+ ## Output
94
+
95
+ ```
96
+ ==========================================
97
+ CFN Test Suite Runner
98
+ ==========================================
99
+ Suite: all
100
+ Benchmark: true
101
+ Detect Regressions: true
102
+ Git: main @ abc123
103
+
104
+ Hello World: 4 passed, 0 failed, 0 skipped (494s)
105
+ CFN E2E: 7 passed, 0 failed, 2 skipped (356s)
106
+
107
+ ==========================================
108
+ Test Summary
109
+ ==========================================
110
+ Total: 13 tests
111
+ Passed: 11
112
+ Failed: 0
113
+ Skipped: 2
114
+ Duration: 850s
115
+ Success Rate: 84.6%
116
+
117
+ ✅ Benchmark stored (run_id: 42)
118
+ ✅ No regressions detected
119
+ ```
@@ -3,12 +3,14 @@
3
3
  "version": "2.0.0",
4
4
  "pipeline": "config/hooks/post-edit-pipeline.js",
5
5
  "triggerOn": ["Edit", "Write", "MultiEdit"],
6
- "fileTypes": [".ts", ".tsx", ".js", ".jsx", ".json", ".md"],
6
+ "fileTypes": [".ts", ".tsx", ".js", ".jsx", ".json", ".md", ".sh", ".bash", ".py", ".rs"],
7
7
  "blocking": false,
8
8
  "exitCodes": {
9
9
  "0": "SUCCESS",
10
10
  "1": "ERROR",
11
- "2": "SYNTAX_ERROR"
11
+ "2": "SYNTAX_ERROR",
12
+ "9": "BASH_VALIDATOR_ERROR",
13
+ "10": "BASH_VALIDATOR_WARNING"
12
14
  },
13
15
  "redis": {
14
16
  "enabled": true,
@@ -26,12 +28,17 @@
26
28
  "enabled": true,
27
29
  "noEmit": true,
28
30
  "skipLibCheck": true
31
+ },
32
+ "bash": {
33
+ "enabled": true,
34
+ "validators": ["pipe-safety", "dependency-checker", "line-endings"],
35
+ "timeout": 5000
29
36
  }
30
37
  },
31
38
  "feedback": {
32
39
  "provideSuggestions": true,
33
40
  "autoFixable": ["LINT_ISSUES"],
34
- "nonBlocking": ["TYPE_WARNING", "LINT_ISSUES"],
35
- "blocking": ["SYNTAX_ERROR"]
41
+ "nonBlocking": ["TYPE_WARNING", "LINT_ISSUES", "BASH_VALIDATOR_WARNING"],
42
+ "blocking": ["SYNTAX_ERROR", "BASH_VALIDATOR_ERROR"]
36
43
  }
37
44
  }
@@ -13,7 +13,7 @@ Recommends Loop 3 (producers) and Loop 2 (evaluators) agents based on:
13
13
  ## Usage
14
14
 
15
15
  ```bash
16
- AGENTS=$(./.claude/skills/agent-selector/select-agents.sh \
16
+ AGENTS=$(./.claude/skills/cfn-agent-selector/select-agents.sh \
17
17
  --task-type "software-development" \
18
18
  --description "Implement JWT authentication with refresh tokens")
19
19
 
@@ -87,4 +87,5 @@ echo "$AGENTS" | jq '.loop2[]' # ["reviewer", "tester", "security-auditor"]
87
87
  ## Integration
88
88
 
89
89
  Used by:
90
- - `.claude/agents/cfn-v3-coordinator.md` - Agent selection
90
+ - `.claude/agents/cfn-v3-coordinator.md` - Agent selection
91
+ - `.claude/skills/cfn-agent-selector/select-agents.sh` - Primary selection script
@@ -635,7 +635,7 @@ function spawn_product_owner() {
635
635
  # BLOCKER #2 FIX: Match execute-decision.sh actual parameters
636
636
  # Required: --task-id, --agent-id, --consensus, --threshold, --iteration, --max-iterations
637
637
  local decision_output
638
- decision_output=$("$SCRIPT_DIR/.claude/skills/cfn-cfn-product-owner-decision/execute-decision.sh" \
638
+ decision_output=$("$SCRIPT_DIR/.claude/skills/cfn-product-owner-decision/execute-decision.sh" \
639
639
  --task-id "$task_id" \
640
640
  --agent-id "$PRODUCT_OWNER" \
641
641
  --consensus "$LOOP2_FINAL_CONSENSUS" \
@@ -1,10 +1,15 @@
1
1
  #!/bin/bash
2
- # Product Owner Decision Skill - Main Execution Wrapper
3
- # Guarantees decision execution via output parsing (solves BUG #11)
2
+ # Product Owner Decision Execution Script
3
+ # Version: 1.0.0
4
+ # Purpose: Execute Product Owner decision with guaranteed Redis coordination
4
5
 
5
6
  set -euo pipefail
6
7
 
7
- SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
8
+ # Colors for output
9
+ RED='\033[0;31m'
10
+ GREEN='\033[0;32m'
11
+ YELLOW='\033[1;33m'
12
+ NC='\033[0m'
8
13
 
9
14
  # Parse arguments
10
15
  TASK_ID=""
@@ -14,7 +19,6 @@ THRESHOLD=""
14
19
  ITERATION=""
15
20
  MAX_ITERATIONS=""
16
21
  SUCCESS_CRITERIA=""
17
- EXPECTED_FILES=""
18
22
 
19
23
  while [[ $# -gt 0 ]]; do
20
24
  case $1 in
@@ -46,12 +50,8 @@ while [[ $# -gt 0 ]]; do
46
50
  SUCCESS_CRITERIA="$2"
47
51
  shift 2
48
52
  ;;
49
- --expected-files)
50
- EXPECTED_FILES="$2"
51
- shift 2
52
- ;;
53
53
  *)
54
- echo "Unknown option: $1" >&2
54
+ echo "Unknown parameter: $1"
55
55
  exit 1
56
56
  ;;
57
57
  esac
@@ -60,142 +60,236 @@ done
60
60
  # Validate required parameters
61
61
  if [ -z "$TASK_ID" ] || [ -z "$AGENT_ID" ] || [ -z "$CONSENSUS" ] || \
62
62
  [ -z "$THRESHOLD" ] || [ -z "$ITERATION" ] || [ -z "$MAX_ITERATIONS" ]; then
63
- echo "ERROR: Missing required parameters" >&2
64
- echo "Usage: $0 --task-id TASK_ID --agent-id AGENT_ID --consensus CONSENSUS --threshold THRESHOLD --iteration ITERATION --max-iterations MAX_ITERATIONS [--success-criteria JSON]" >&2
63
+ echo -e "${RED}❌ ERROR: Missing required parameters${NC}"
64
+ echo "Usage: $0 --task-id <id> --agent-id <id> --consensus <score> --threshold <score> --iteration <num> --max-iterations <num>"
65
65
  exit 1
66
66
  fi
67
67
 
68
- # Retrieve full context from Redis (if available)
69
- REDIS_CONTEXT=$(redis-cli HGET "cfn_loop:task:${TASK_ID}:context" "full_context" 2>/dev/null || echo "{}")
68
+ echo -e "${GREEN}🎯 Product Owner Decision Execution${NC}"
69
+ echo "Task ID: $TASK_ID"
70
+ echo "Agent ID: $AGENT_ID"
71
+ echo "Consensus: $CONSENSUS"
72
+ echo "Threshold: $THRESHOLD"
73
+ echo "Iteration: $ITERATION / $MAX_ITERATIONS"
70
74
 
71
- # Extract scope from Redis context
72
- EPIC_GOAL=$(echo "$REDIS_CONTEXT" | jq -r '.epicGoal // "Task completion"')
73
- IN_SCOPE=$(echo "$REDIS_CONTEXT" | jq -r '.inScope[]?' | sed 's/^/- /' | tr '\n' '\n' || echo "- Core functionality")
74
- OUT_SCOPE=$(echo "$REDIS_CONTEXT" | jq -r '.outOfScope[]?' | sed 's/^/- /' | tr '\n' '\n' || echo "- Advanced features")
75
- DELIVERABLES=$(echo "$REDIS_CONTEXT" | jq -r '.deliverables[]?' | sed 's/^/- /' | tr '\n' '\n' || echo "- Implementation files")
76
- DIRECTORY=$(echo "$REDIS_CONTEXT" | jq -r '.directory // "."')
77
- ACCEPTANCE=$(echo "$REDIS_CONTEXT" | jq -r '.acceptanceCriteria[]?' | sed 's/^/- /' | tr '\n' '\n' || echo "- Tests pass")
75
+ # Retrieve Loop 2 context from Redis
76
+ echo -e "${YELLOW}📥 Retrieving Loop 2 context...${NC}"
77
+ LOOP2_FEEDBACK=$(redis-cli HGET "swarm:${TASK_ID}:loop2:consensus" "feedback" || echo "")
78
+ TASK_CONTEXT=$(redis-cli HGETALL "swarm:${TASK_ID}:context" || echo "")
78
79
 
79
- # Build Product Owner context with full scope information
80
- PO_CONTEXT="CFN Loop iteration $ITERATION complete.
80
+ # Build Product Owner context
81
+ PO_CONTEXT="
82
+ You are the Product Owner making a strategic decision for CFN Loop iteration $ITERATION of $MAX_ITERATIONS.
81
83
 
82
- Epic Goal: $EPIC_GOAL
84
+ Loop 2 Consensus: $CONSENSUS
85
+ Threshold: $THRESHOLD
86
+ Success Criteria: ${SUCCESS_CRITERIA:-"Not specified"}
83
87
 
84
- In-Scope:
85
- $IN_SCOPE
88
+ Loop 2 Feedback:
89
+ $LOOP2_FEEDBACK
86
90
 
87
- Out-of-Scope:
88
- $OUT_SCOPE
91
+ Task Context:
92
+ $TASK_CONTEXT
89
93
 
90
- Deliverables:
91
- $DELIVERABLES
94
+ Make a strategic decision:
95
+ - PROCEED: Quality threshold met, deliverables complete
96
+ - ITERATE: Improvements needed, iterations remaining
97
+ - ABORT: Max iterations reached or unrecoverable failure
92
98
 
93
- Directory: $DIRECTORY
94
-
95
- Acceptance Criteria:
96
- $ACCEPTANCE
99
+ Output format:
100
+ Decision: PROCEED|ITERATE|ABORT
101
+ Reasoning: [your explanation]
102
+ Confidence: [0.0-1.0]
103
+ "
97
104
 
98
- Loop 2 Consensus: $CONSENSUS (threshold: $THRESHOLD)
99
- Current Iteration: $ITERATION
100
- Max Iterations: $MAX_ITERATIONS
105
+ # Spawn Product Owner agent
106
+ echo -e "${YELLOW}🚀 Spawning Product Owner agent...${NC}"
107
+ PO_OUTPUT_FILE="/tmp/product-owner-${TASK_ID}-${ITERATION}.log"
101
108
 
102
- Make your strategic decision: PROCEED, ITERATE, or ABORT
109
+ # Use timeout from agent config
110
+ PO_TIMEOUT=300 # 5 minutes default
103
111
 
104
- Decision Framework:
105
- - PROCEED: Consensus >= $THRESHOLD AND deliverables verified AND acceptance criteria met
106
- - ITERATE: Consensus < $THRESHOLD AND iteration < $MAX_ITERATIONS
107
- - ABORT: Max iterations reached without consensus
112
+ set +e
113
+ timeout "$PO_TIMEOUT" npx claude-flow-novice agent product-owner \
114
+ --task-id "$TASK_ID" \
115
+ --context "$PO_CONTEXT" > "$PO_OUTPUT_FILE" 2>&1
116
+ PO_EXIT_CODE=$?
117
+ set -e
108
118
 
109
- Output format:
110
- Decision: [PROCEED|ITERATE|ABORT]
111
- Reasoning: [explain using GOAP framework]
112
- Confidence: [0.0-1.0]
113
- Next Action: [specific next step - 'proceed to next sprint', 'complete epic', 'iterate on current sprint']
119
+ # Check timeout
120
+ if [ $PO_EXIT_CODE -eq 124 ]; then
121
+ echo -e "${RED}❌ ERROR: Product Owner timed out after ${PO_TIMEOUT}s${NC}"
122
+ DECISION_TYPE="ABORT"
123
+ REASONING="Product Owner decision timeout after ${PO_TIMEOUT}s"
124
+ CONFIDENCE=0.0
125
+ else
126
+ # Parse decision from output
127
+ # Defensive file handling - TEST 5 fix
128
+ if [ -f "$PO_OUTPUT_FILE" ] && [ -s "$PO_OUTPUT_FILE" ]; then
129
+ PO_OUTPUT=$(cat "$PO_OUTPUT_FILE")
114
130
 
115
- CRITICAL: Do NOT ask for user confirmation. Make autonomous decision."
131
+ # Try multiple parsing patterns
132
+ DECISION_TYPE=$(echo "$PO_OUTPUT" | grep -oiE "Decision:\s*(PROCEED|ITERATE|ABORT)" | grep -oiE "(PROCEED|ITERATE|ABORT)" | head -1 | tr '[:lower:]' '[:upper:]' || echo "")
116
133
 
117
- # Get agent timeout (if get_agent_timeout function available)
118
- if command -v get_agent_timeout &>/dev/null; then
119
- PO_TIMEOUT=$(get_agent_timeout "product-owner" "$TASK_ID")
120
- else
121
- PO_TIMEOUT=900 # Default 15 minutes
122
- fi
134
+ if [ -z "$DECISION_TYPE" ]; then
135
+ DECISION_TYPE=$(echo "$PO_OUTPUT" | grep -oE "(PROCEED|ITERATE|ABORT)" | head -1 || echo "")
136
+ fi
123
137
 
124
- # Spawn Product Owner and capture output
125
- PO_OUTPUT=$(timeout "$PO_TIMEOUT" npx claude-flow-novice agent product-owner \
126
- --task-id "$TASK_ID" \
127
- --agent-id "$AGENT_ID" \
128
- --context "$PO_CONTEXT" 2>&1 || true)
138
+ if [ -z "$DECISION_TYPE" ]; then
139
+ DECISION_TYPE=$(echo "$PO_OUTPUT" | grep -oiE "(proceed|iterate|abort)" | head -1 | tr '[:lower:]' '[:upper:]' || echo "")
140
+ fi
129
141
 
130
- # Parse decision using skill parser
131
- DECISION_TYPE=$("$SCRIPT_DIR/parse-decision.sh" --output "$PO_OUTPUT")
142
+ # Parse reasoning
143
+ REASONING=$(echo "$PO_OUTPUT" | grep -oiE "Reasoning:\s*.*" | sed 's/Reasoning:\s*//' || echo "No reasoning provided")
144
+
145
+ # Parse confidence
146
+ CONFIDENCE=$(echo "$PO_OUTPUT" | grep -oE "Confidence:\s*[0-9]+\.?[0-9]*" | grep -oE "[0-9]+\.?[0-9]*" || echo "0.85")
147
+ else
148
+ echo -e "${RED}❌ ERROR: Product Owner output file missing or empty${NC}"
149
+ echo "Expected: $PO_OUTPUT_FILE"
150
+ PO_OUTPUT=""
151
+ DECISION_TYPE="ABORT"
152
+ REASONING="Product Owner output file missing or empty: $PO_OUTPUT_FILE"
153
+ CONFIDENCE=0.0
154
+ fi
155
+ fi
132
156
 
157
+ # Validate decision parsing
133
158
  if [ -z "$DECISION_TYPE" ]; then
134
- echo "❌ ERROR: Could not parse Product Owner decision" >&2
135
- echo "Product Owner output:" >&2
136
- echo "$PO_OUTPUT" >&2
137
-
138
- # Fallback to ABORT on parse failure
159
+ echo -e "${RED}❌ ERROR: Could not parse decision from Product Owner output${NC}"
160
+ echo "Output sample:"
161
+ echo "$PO_OUTPUT" | head -20
139
162
  DECISION_TYPE="ABORT"
140
- REASONING="Failed to parse Product Owner decision from output"
141
- CONFIDENCE=0.50
142
- else
143
- # Extract reasoning (context around decision)
144
- REASONING=$(echo "$PO_OUTPUT" | grep -A5 -i "decision" | tail -5 | tr '\n' ' ' | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
145
- CONFIDENCE=0.90
163
+ REASONING="Failed to parse Product Owner decision"
164
+ CONFIDENCE=0.0
146
165
  fi
147
166
 
148
- # Validate deliverables for PROCEED decisions
167
+ echo -e "${GREEN}✅ Product Owner Decision: $DECISION_TYPE${NC}"
168
+ echo "Reasoning: $REASONING"
169
+ echo "Confidence: $CONFIDENCE"
170
+
171
+ # Deliverable verification for PROCEED decisions
149
172
  if [ "$DECISION_TYPE" = "PROCEED" ]; then
150
- DELIVERABLE_ARGS="--task-id $TASK_ID"
151
- if [ -n "$EXPECTED_FILES" ]; then
152
- DELIVERABLE_ARGS="$DELIVERABLE_ARGS --expected-files $EXPECTED_FILES"
173
+ echo -e "${YELLOW}🔍 Verifying deliverables...${NC}"
174
+
175
+ # Check if task requires implementation (keywords: create, build, implement, generate)
176
+ REQUIRES_IMPLEMENTATION=$(echo "$TASK_CONTEXT" | grep -iE "(create|build|implement|generate|write|add)" || echo "")
177
+
178
+ if [ -n "$REQUIRES_IMPLEMENTATION" ]; then
179
+ # Check git status for file changes
180
+ FILES_CHANGED=$(git status --short | grep -E "^(A|M|\?\?)" | wc -l || echo "0")
181
+
182
+ if [ "$FILES_CHANGED" -eq 0 ]; then
183
+ echo -e "${YELLOW}⚠️ WARNING: No deliverables created (consensus on plans only)${NC}"
184
+ DECISION_TYPE="ITERATE"
185
+ REASONING="Override PROCEED → ITERATE: No files created despite implementation task. Validators approved plans without actual code."
186
+ CONFIDENCE=0.70
187
+
188
+ # Add deliverable requirement to feedback
189
+ DELIVERABLE_FEEDBACK="
190
+ Critical: Task requires implementation but zero files created.
191
+ Next iteration MUST create actual deliverables, not just plans.
192
+ "
193
+ redis-cli HSET "swarm:${TASK_ID}:loop2:consensus" "deliverable_feedback" "$DELIVERABLE_FEEDBACK"
194
+ else
195
+ echo -e "${GREEN}✅ Deliverables verified: $FILES_CHANGED files changed${NC}"
196
+ fi
153
197
  fi
198
+ fi
154
199
 
155
- DELIVERABLE_STATUS=$("$SCRIPT_DIR/validate-deliverables.sh" $DELIVERABLE_ARGS)
156
-
157
- if [ "$DELIVERABLE_STATUS" = "FAILED" ]; then
158
- # Retrieve missing files from Redis (if available)
159
- MISSING_FILES_JSON=$(redis-cli get "swarm:${TASK_ID}:missing-files" 2>/dev/null || echo "[]")
160
- MISSING_FILES_LIST=$(echo "$MISSING_FILES_JSON" | jq -r '.[]' | tr '\n' ', ' | sed 's/,$//')
161
-
162
- # Override PROCEED ITERATE
163
- DECISION_TYPE="ITERATE"
164
- if [ -n "$MISSING_FILES_LIST" ]; then
165
- REASONING="Deliverable verification failed - missing files: $MISSING_FILES_LIST"
200
+ # Process deferred items for backlog
201
+ echo -e "${YELLOW}📋 Processing deferred items for backlog...${NC}"
202
+
203
+ # Extract deferred items from Product Owner output
204
+ # Look for sections: "Out of Scope", "Deferred", "Future Work", "Defer"
205
+ DEFERRED_SECTION=$(echo "$PO_OUTPUT" | grep -iA 20 "out of scope\|deferred\|future work\|defer:" || echo "")
206
+
207
+ if [ -n "$DEFERRED_SECTION" ]; then
208
+ echo -e "${YELLOW}Found deferred items section, extracting items...${NC}"
209
+
210
+ # Parse deferred items (lines starting with -, *, or bullet points after marker)
211
+ DEFERRED_ITEMS=$(echo "$DEFERRED_SECTION" | grep -E "^\s*[-*•]" | sed 's/^\s*[-*•]\s*//' || echo "")
212
+
213
+ if [ -n "$DEFERRED_ITEMS" ]; then
214
+ ITEMS_ADDED=0
215
+
216
+ # Process each deferred item
217
+ while IFS= read -r item; do
218
+ # Skip empty lines or section headers
219
+ if [ -n "$item" ] && ! echo "$item" | grep -iqE "^(out of scope|deferred|future work)" && [ ${#item} -ge 10 ]; then
220
+ echo -e "${YELLOW} Adding to backlog: ${item:0:60}...${NC}"
221
+
222
+ # Invoke backlog skill (defensive - don't fail decision on backlog error)
223
+ set +e
224
+ /mnt/c/Users/masha/Documents/claude-flow-novice/.claude/skills/cfn-backlog-management/add-backlog-item.sh \
225
+ --item "$item" \
226
+ --why "Deferred during Product Owner decision (Task: $TASK_ID, Iteration: $ITERATION)" \
227
+ --solution "To be determined during sprint planning" \
228
+ --priority "P2" \
229
+ --category "Technical-Debt" \
230
+ --sprint "Sprint-Backlog-$ITERATION" \
231
+ --force >/dev/null 2>&1
232
+
233
+ if [ $? -eq 0 ]; then
234
+ ITEMS_ADDED=$((ITEMS_ADDED + 1))
235
+ else
236
+ echo -e "${YELLOW} Warning: Failed to add backlog item (non-critical)${NC}" >&2
237
+ fi
238
+ set -e
239
+ fi
240
+ done <<< "$DEFERRED_ITEMS"
241
+
242
+ if [ $ITEMS_ADDED -gt 0 ]; then
243
+ echo -e "${GREEN}✅ Backlog updated with $ITEMS_ADDED deferred item(s)${NC}"
244
+
245
+ # Store backlog metadata in Redis
246
+ redis-cli HSET "swarm:${TASK_ID}:${AGENT_ID}:result" "backlog_items_added" "$ITEMS_ADDED"
166
247
  else
167
- REASONING="Deliverable verification failed - no files created (consensus on plans only)"
248
+ echo -e "${YELLOW}⚠️ No valid backlog items extracted${NC}"
168
249
  fi
169
- CONFIDENCE=0.75
250
+ else
251
+ echo -e "${YELLOW}⚠️ Deferred section found but no items extracted${NC}"
170
252
  fi
253
+ else
254
+ echo -e "${GREEN}No deferred items detected in Product Owner output${NC}"
171
255
  fi
172
256
 
173
257
  # Build decision JSON
174
- DECISION_JSON=$(jq -n \
175
- --arg decision "$DECISION_TYPE" \
176
- --arg reasoning "${REASONING:-Parsed from Product Owner output}" \
177
- --arg confidence "$CONFIDENCE" \
178
- --arg iteration "$ITERATION" \
179
- --arg consensus "$CONSENSUS" \
180
- '{
181
- decision: $decision,
182
- reasoning: $reasoning,
183
- confidence: ($confidence | tonumber),
184
- iteration: ($iteration | tonumber),
185
- consensus: ($consensus | tonumber),
186
- timestamp: (now | todate)
187
- }')
188
-
189
- # Push decision to Redis (orchestrator's responsibility, not agent's)
190
- DECISION_KEY="swarm:${TASK_ID}:${AGENT_ID}:decision"
191
- echo "$DECISION_JSON" | redis-cli -x LPUSH "$DECISION_KEY" >/dev/null
192
-
193
- # Signal Product Owner completion
194
- redis-cli LPUSH "swarm:${TASK_ID}:${AGENT_ID}:done" "complete" >/dev/null
195
-
196
- # Store decision in metrics
197
- redis-cli LPUSH "swarm:${TASK_ID}:metrics:product_owner_decisions" "$DECISION_JSON" >/dev/null
198
- redis-cli INCR "swarm:metrics:decisions:$(echo "$DECISION_TYPE" | tr '[:upper:]' '[:lower:]')" >/dev/null
258
+ DECISION_JSON=$(cat <<EOF
259
+ {
260
+ "decision": "$DECISION_TYPE",
261
+ "reasoning": "$REASONING",
262
+ "confidence": $CONFIDENCE,
263
+ "iteration": $ITERATION,
264
+ "consensus": $CONSENSUS,
265
+ "threshold": $THRESHOLD,
266
+ "timestamp": $(date +%s)
267
+ }
268
+ EOF
269
+ )
270
+
271
+ # Store decision in Redis
272
+ echo -e "${YELLOW}💾 Storing decision in Redis...${NC}"
273
+ redis-cli LPUSH "swarm:${TASK_ID}:decision" "$DECISION_TYPE"
274
+ redis-cli HSET "swarm:${TASK_ID}:${AGENT_ID}:result" "decision" "$DECISION_TYPE"
275
+ redis-cli HSET "swarm:${TASK_ID}:${AGENT_ID}:result" "reasoning" "$REASONING"
276
+ redis-cli HSET "swarm:${TASK_ID}:${AGENT_ID}:result" "confidence" "$CONFIDENCE"
277
+
278
+ # Store in metrics
279
+ redis-cli LPUSH "swarm:${TASK_ID}:metrics:product_owner_decisions" "$DECISION_JSON"
280
+ redis-cli INCR "swarm:metrics:decisions:$(echo "$DECISION_TYPE" | tr '[:upper:]' '[:lower:]')"
281
+
282
+ # Signal completion
283
+ redis-cli LPUSH "swarm:${TASK_ID}:${AGENT_ID}:done" "complete"
284
+
285
+ # Report confidence (for orchestrator collection)
286
+ ./.claude/skills/cfn-redis-coordination/invoke-waiting-mode.sh report \
287
+ --task-id "$TASK_ID" \
288
+ --agent-id "$AGENT_ID" \
289
+ --confidence "$CONFIDENCE" \
290
+ --iteration "$ITERATION"
199
291
 
200
292
  # Output decision JSON for orchestrator
201
293
  echo "$DECISION_JSON"
294
+
295
+ echo -e "${GREEN}✅ Product Owner decision execution complete${NC}"