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.
Files changed (66) hide show
  1. package/.claude/commands/CFN_LOOP_TASK_MODE.md +119 -0
  2. package/.claude/skills/cfn-agent-spawning/spawn-agent.sh +12 -0
  3. package/.claude/skills/cfn-agent-spawning/spawn-agent.sh.backup +273 -0
  4. package/.claude/skills/cfn-hybrid-routing/README.md +1 -1
  5. package/.claude/skills/cfn-loop-orchestration/orchestrate.sh +95 -15
  6. package/.claude/skills/cfn-loop-orchestration/orchestrate.sh.backup +76 -11
  7. package/.claude/skills/cfn-loop-orchestration/orchestrate.sh.backup2 +959 -0
  8. package/.claude/skills/cfn-loop-orchestration/orchestrate.sh.clean +949 -0
  9. package/.claude/skills/cfn-product-owner-decision/execute-decision.sh +82 -10
  10. package/claude-assets/agents/cfn-dev-team/architecture/base-template-generator.md +7 -33
  11. package/claude-assets/agents/cfn-dev-team/architecture/planner.md +7 -47
  12. package/claude-assets/agents/cfn-dev-team/architecture/system-architect.md +7 -33
  13. package/claude-assets/agents/cfn-dev-team/coordinators/cfn-frontend-coordinator.md +88 -23
  14. package/claude-assets/agents/cfn-dev-team/coordinators/cfn-v3-coordinator.md +59 -23
  15. package/claude-assets/agents/cfn-dev-team/coordinators/consensus-builder.md +43 -39
  16. package/claude-assets/agents/cfn-dev-team/coordinators/epic-creator.md +69 -0
  17. package/claude-assets/agents/cfn-dev-team/coordinators/multi-sprint-coordinator.md +65 -1
  18. package/claude-assets/agents/cfn-dev-team/developers/frontend/mobile-dev.md +7 -47
  19. package/claude-assets/agents/cfn-dev-team/developers/frontend/typescript-specialist.md +7 -26
  20. package/claude-assets/agents/cfn-dev-team/developers/rust-developer.md +7 -47
  21. package/claude-assets/agents/cfn-dev-team/product-owners/cto-agent.md +7 -19
  22. package/claude-assets/agents/cfn-dev-team/product-owners/power-user-persona.md +9 -49
  23. package/claude-assets/agents/cfn-dev-team/product-owners/product-owner.md +407 -22
  24. package/claude-assets/agents/cfn-dev-team/reviewers/quality/code-quality-validator.md +7 -66
  25. package/claude-assets/agents/cfn-dev-team/reviewers/quality/perf-analyzer.md +7 -76
  26. package/claude-assets/agents/cfn-dev-team/reviewers/quality/performance-benchmarker.md +8 -2
  27. package/claude-assets/agents/cfn-dev-team/reviewers/quality/security-specialist.md +7 -66
  28. package/claude-assets/agents/cfn-dev-team/reviewers/reviewer.md +7 -78
  29. package/claude-assets/agents/cfn-dev-team/testers/e2e/playwright-tester.md +7 -18
  30. package/claude-assets/agents/cfn-dev-team/testers/interaction-tester.md +7 -18
  31. package/claude-assets/agents/cfn-dev-team/testers/tester.md +7 -77
  32. package/claude-assets/agents/cfn-dev-team/testers/unit/tdd-london-unit-swarm.md +7 -18
  33. package/claude-assets/agents/cfn-dev-team/testers/validation/validation-production-validator.md +7 -19
  34. package/claude-assets/agents/cfn-dev-team/testing/test-validation-agent.md +7 -44
  35. package/claude-assets/agents/cfn-dev-team/utility/agent-builder.md +35 -111
  36. package/claude-assets/agents/cfn-dev-team/utility/analyst.md +7 -47
  37. package/claude-assets/agents/cfn-dev-team/utility/code-booster.md +7 -40
  38. package/claude-assets/agents/cfn-dev-team/utility/context-curator.md +7 -47
  39. package/claude-assets/commands/CFN_LOOP_TASK_MODE.md +119 -0
  40. package/claude-assets/skills/cfn-agent-spawning/spawn-agent.sh +12 -0
  41. package/claude-assets/skills/cfn-agent-spawning/spawn-agent.sh.backup +273 -0
  42. package/claude-assets/skills/cfn-environment-sanitization/SKILL.md +200 -0
  43. package/claude-assets/skills/cfn-environment-sanitization/sanitize-environment.sh +244 -0
  44. package/claude-assets/skills/cfn-hybrid-routing/README.md +1 -1
  45. package/claude-assets/skills/cfn-loop-orchestration/orchestrate.sh +95 -15
  46. package/claude-assets/skills/cfn-loop-orchestration/orchestrate.sh.backup +76 -11
  47. package/claude-assets/skills/cfn-loop-orchestration/orchestrate.sh.backup2 +959 -0
  48. package/claude-assets/skills/cfn-loop-orchestration/orchestrate.sh.clean +949 -0
  49. package/claude-assets/skills/cfn-node-heap-sizer/task-mode-heap-limiter.sh +326 -0
  50. package/claude-assets/skills/cfn-process-instrumentation/SKILL.md +279 -0
  51. package/claude-assets/skills/cfn-process-instrumentation/instrument-process.sh +323 -0
  52. package/claude-assets/skills/cfn-product-owner-decision/execute-decision.sh +82 -10
  53. package/claude-assets/skills/cfn-task-audit/get-audit-data.sh +376 -0
  54. package/claude-assets/skills/cfn-task-audit/store-task-audit.sh +184 -0
  55. package/claude-assets/skills/cfn-task-mode-safety/cli-coordination.sh +519 -0
  56. package/claude-assets/skills/cfn-task-mode-safety/mode-detection.sh +326 -0
  57. package/claude-assets/skills/cfn-task-mode-sanitize/task-mode-env-sanitizer.sh +224 -0
  58. package/claude-assets/skills/cfn-telemetry/collect-metrics.sh +249 -0
  59. package/claude-assets/skills/cfn-telemetry/start-telemetry.sh +111 -0
  60. package/claude-assets/skills/cfn-validation-runner-instrumentation/wrapped-executor.sh +327 -0
  61. package/dist/cli/config-manager.js +109 -91
  62. package/dist/cli/config-manager.js.map +1 -1
  63. package/package.json +1 -1
  64. package/scripts/mode-detection.sh +321 -0
  65. package/scripts/spawn-worker.sh +8 -0
  66. package/scripts/track-zai-costs-simple.sh +8 -0
@@ -0,0 +1,323 @@
1
+ #!/usr/bin/env bash
2
+
3
+ ##############################################################################
4
+ # CFN Process Instrumentation
5
+ # Part of ANTI-023 Memory Leak Protection System
6
+ #
7
+ # Provides process instrumentation, monitoring, and automatic resource limiting
8
+ # for CFN Loop agents and orchestration processes.
9
+ #
10
+ # Usage:
11
+ # source ./instrument-process.sh [--agent-id <id>] [--memory-limit <size>]
12
+ # ./instrument-process.sh --monitor-pid <pid>
13
+ ##############################################################################
14
+
15
+ set -euo pipefail
16
+
17
+ # Configuration
18
+ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
19
+ PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
20
+
21
+ # Default limits
22
+ DEFAULT_MEMORY_LIMIT="2G"
23
+ DEFAULT_CPU_LIMIT="80%"
24
+ DEFAULT_TIMEOUT="600"
25
+
26
+ # Process tracking
27
+ AGENT_ID="${AGENT_ID:-$(hostname)-$$}"
28
+ MONITOR_PID=""
29
+ MEMORY_LIMIT="${CFN_MEMORY_LIMIT:-$DEFAULT_MEMORY_LIMIT}"
30
+ CPU_LIMIT="${CFN_CPU_LIMIT:-$DEFAULT_CPU_LIMIT}"
31
+ TIMEOUT="${CFN_TIMEOUT:-$DEFAULT_TIMEOUT}"
32
+
33
+ # Telemetry storage
34
+ TELEMETRY_DIR="${CFN_TELEMETRY_DIR:-/tmp/cfn-telemetry}"
35
+ METRICS_FILE="$TELEMETRY_DIR/metrics_${AGENT_ID}.json"
36
+
37
+ # Color coding
38
+ readonly RED='\033[0;31m'
39
+ readonly GREEN='\033[0;32m'
40
+ readonly YELLOW='\033[1;33m'
41
+ readonly BLUE='\033[0;34m'
42
+ readonly NC='\033[0m'
43
+
44
+ # Logging functions
45
+ log_info() {
46
+ echo -e "${BLUE}[INSTRUMENT]${NC} $1" >&2
47
+ }
48
+
49
+ log_success() {
50
+ echo -e "${GREEN}[INSTRUMENT]${NC} $1" >&2
51
+ }
52
+
53
+ log_warning() {
54
+ echo -e "${YELLOW}[INSTRUMENT]${NC} $1" >&2
55
+ }
56
+
57
+ log_error() {
58
+ echo -e "${RED}[INSTRUMENT]${NC} $1" >&2
59
+ }
60
+
61
+ # Initialize telemetry directory
62
+ init_telemetry() {
63
+ mkdir -p "$TELEMETRY_DIR"
64
+
65
+ # Create metrics file with initial structure
66
+ cat > "$METRICS_FILE" << EOF
67
+ {
68
+ "agent_id": "$AGENT_ID",
69
+ "start_time": "$(date -Iseconds)",
70
+ "process_id": "$$",
71
+ "memory_limit": "$MEMORY_LIMIT",
72
+ "cpu_limit": "$CPU_LIMIT",
73
+ "timeout": "$TIMEOUT",
74
+ "samples": []
75
+ }
76
+ EOF
77
+ }
78
+
79
+ # Collect process metrics
80
+ collect_metrics() {
81
+ local pid="${1:-$$}"
82
+ local timestamp="$(date -Iseconds)"
83
+
84
+ # Get process statistics
85
+ local mem_usage=""
86
+ local cpu_usage=""
87
+ local open_files=""
88
+ local threads=""
89
+
90
+ if command -v ps >/dev/null 2>&1; then
91
+ mem_usage=$(ps -p "$pid" -o rss= 2>/dev/null | tr -d ' ' || echo "0")
92
+ cpu_usage=$(ps -p "$pid" -o %cpu= 2>/dev/null | tr -d ' ' || echo "0")
93
+ fi
94
+
95
+ if command -v lsof >/dev/null 2>&1; then
96
+ open_files=$(lsof -p "$pid" 2>/dev/null | wc -l || echo "0")
97
+ fi
98
+
99
+ if [[ -f "/proc/$pid/status" ]]; then
100
+ threads=$(grep "^Threads:" "/proc/$pid/status" | awk '{print $2}' || echo "0")
101
+ fi
102
+
103
+ # Create metrics entry
104
+ local metrics_entry=$(cat << EOF
105
+ {
106
+ "timestamp": "$timestamp",
107
+ "memory_kb": "$mem_usage",
108
+ "cpu_percent": "$cpu_usage",
109
+ "open_files": "$open_files",
110
+ "threads": "$threads"
111
+ }
112
+ EOF
113
+ )
114
+
115
+ # Update metrics file
116
+ if [[ -f "$METRICS_FILE" ]]; then
117
+ # Use jq to safely append to samples array
118
+ if command -v jq >/dev/null 2>&1; then
119
+ jq --argjson entry "$metrics_entry" '.samples += [$entry]' "$METRICS_FILE" > "$METRICS_FILE.tmp" && \
120
+ mv "$METRICS_FILE.tmp" "$METRICS_FILE"
121
+ else
122
+ # Fallback without jq
123
+ echo "Warning: jq not available, using simple append" >&2
124
+ echo "$metrics_entry" >> "$METRICS_FILE.raw"
125
+ fi
126
+ fi
127
+ }
128
+
129
+ # Check resource limits
130
+ check_limits() {
131
+ local pid="${1:-$$}"
132
+
133
+ # Memory limit check
134
+ if command -v ps >/dev/null 2>&1; then
135
+ local mem_kb=$(ps -p "$pid" -o rss= 2>/dev/null | tr -d ' ' || echo "0")
136
+ local mem_mb=$((mem_kb / 1024))
137
+
138
+ case "$MEMORY_LIMIT" in
139
+ *G|*g)
140
+ local limit_mb=$((${MEMORY_LIMIT%[Gg]*} * 1024))
141
+ ;;
142
+ *M|*m)
143
+ local limit_mb=$((${MEMORY_LIMIT%[Mm]*}))
144
+ ;;
145
+ *)
146
+ local limit_mb=2048 # Default 2GB
147
+ ;;
148
+ esac
149
+
150
+ if [[ $mem_mb -gt $limit_mb ]]; then
151
+ log_warning "Memory limit exceeded: ${mem_mb}MB > ${limit_mb}MB"
152
+ return 1
153
+ fi
154
+ fi
155
+
156
+ # CPU limit check
157
+ if command -v ps >/dev/null 2>&1; then
158
+ local cpu_percent=$(ps -p "$pid" -o %cpu= 2>/dev/null | tr -d ' ' || echo "0")
159
+ local cpu_limit_num=$((${CPU_LIMIT%\%}))
160
+
161
+ if (( $(echo "$cpu_percent > $cpu_limit_num" | bc -l) )); then
162
+ log_warning "CPU limit exceeded: ${cpu_percent}% > ${CPU_LIMIT}"
163
+ return 1
164
+ fi
165
+ fi
166
+
167
+ return 0
168
+ }
169
+
170
+ # Start background monitoring
171
+ start_monitoring() {
172
+ local pid="${1:-$$}"
173
+ local interval="${2:-30}" # Check every 30 seconds
174
+
175
+ log_info "Starting process monitoring for PID $pid (interval: ${interval}s)"
176
+
177
+ # Start monitoring in background
178
+ (
179
+ while true; do
180
+ if ! kill -0 "$pid" 2>/dev/null; then
181
+ log_info "Process $pid no longer exists, stopping monitoring"
182
+ break
183
+ fi
184
+
185
+ collect_metrics "$pid"
186
+
187
+ if ! check_limits "$pid"; then
188
+ log_error "Resource limits exceeded, terminating process $pid"
189
+ kill -TERM "$pid" 2>/dev/null || true
190
+ break
191
+ fi
192
+
193
+ sleep "$interval"
194
+ done
195
+ ) &
196
+
197
+ MONITOR_PID=$!
198
+ echo "$MONITOR_PID"
199
+ }
200
+
201
+ # Stop monitoring
202
+ stop_monitoring() {
203
+ if [[ -n "$MONITOR_PID" ]] && kill -0 "$MONITOR_PID" 2>/dev/null; then
204
+ kill "$MONITOR_PID" 2>/dev/null || true
205
+ log_info "Stopped monitoring (PID: $MONITOR_PID)"
206
+ fi
207
+ }
208
+
209
+ # Generate final report
210
+ generate_report() {
211
+ local exit_code="${1:-0}"
212
+
213
+ if [[ -f "$METRICS_FILE" ]]; then
214
+ # Update with final information
215
+ if command -v jq >/dev/null 2>&1; then
216
+ jq --arg end_time "$(date -Iseconds)" \
217
+ --arg exit_code "$exit_code" \
218
+ '.end_time = $end_time | .exit_code = $exit_code' \
219
+ "$METRICS_FILE" > "$METRICS_FILE.tmp" && \
220
+ mv "$METRICS_FILE.tmp" "$METRICS_FILE"
221
+ fi
222
+
223
+ log_success "Process report generated: $METRICS_FILE"
224
+
225
+ # Print summary
226
+ if command -v jq >/dev/null 2>&1; then
227
+ local samples=$(jq '.samples | length' "$METRICS_FILE")
228
+ echo "📊 Process Metrics Summary:" >&2
229
+ echo " Agent ID: $AGENT_ID" >&2
230
+ echo " Samples: $samples" >&2
231
+ echo " Exit Code: $exit_code" >&2
232
+ fi
233
+ fi
234
+ }
235
+
236
+ # Monitor existing process
237
+ monitor_pid() {
238
+ local pid="$1"
239
+
240
+ log_info "Monitoring existing process: PID $pid"
241
+
242
+ if ! kill -0 "$pid" 2>/dev/null; then
243
+ log_error "Process $pid does not exist"
244
+ return 1
245
+ fi
246
+
247
+ # Start monitoring
248
+ local monitor_pid=$(start_monitoring "$pid")
249
+
250
+ # Wait for process to complete
251
+ while kill -0 "$pid" 2>/dev/null; do
252
+ sleep 5
253
+ done
254
+
255
+ # Stop monitoring
256
+ stop_monitoring
257
+
258
+ log_success "Process monitoring completed for PID $pid"
259
+ }
260
+
261
+ # Main execution
262
+ main() {
263
+ local action="${1:-"instrument"}"
264
+
265
+ case "$action" in
266
+ "instrument")
267
+ init_telemetry
268
+ local monitor_pid=$(start_monitoring)
269
+
270
+ # Set up cleanup traps
271
+ trap 'stop_monitoring; generate_report $?' EXIT
272
+ trap 'stop_monitoring; generate_report 1' INT TERM
273
+
274
+ log_success "Process instrumentation started for $AGENT_ID"
275
+ ;;
276
+ "monitor-pid")
277
+ if [[ -z "${2:-}" ]]; then
278
+ log_error "PID required for monitor-pid action"
279
+ exit 1
280
+ fi
281
+ monitor_pid "$2"
282
+ ;;
283
+ "--help"|"-h")
284
+ cat << EOF
285
+ CFN Process Instrumentation Script
286
+
287
+ Usage:
288
+ $0 # Instrument current process
289
+ $0 monitor-pid <pid> # Monitor existing process
290
+ $0 --help # Show this help
291
+
292
+ Environment Variables:
293
+ AGENT_ID # Agent identifier (default: hostname-PID)
294
+ CFN_MEMORY_LIMIT # Memory limit (default: 2G)
295
+ CFN_CPU_LIMIT # CPU limit (default: 80%)
296
+ CFN_TIMEOUT # Timeout in seconds (default: 600)
297
+ CFN_TELEMETRY_DIR # Telemetry storage directory
298
+
299
+ This script provides process monitoring and resource limit enforcement
300
+ for CFN Loop agents and orchestration processes.
301
+ EOF
302
+ ;;
303
+ *)
304
+ log_error "Unknown action: $action"
305
+ exit 1
306
+ ;;
307
+ esac
308
+ }
309
+
310
+ # Execute main function if run directly
311
+ if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
312
+ main "$@"
313
+ else
314
+ # When sourced, automatically instrument current process
315
+ init_telemetry
316
+ local monitor_pid=$(start_monitoring)
317
+
318
+ # Set up cleanup traps
319
+ trap 'stop_monitoring; generate_report $?' EXIT
320
+ trap 'stop_monitoring; generate_report 1' INT TERM
321
+
322
+ log_info "Process instrumentation enabled for $AGENT_ID"
323
+ fi
@@ -77,10 +77,49 @@ echo -e "${YELLOW}📥 Retrieving Loop 2 context...${NC}"
77
77
  LOOP2_FEEDBACK=$(redis-cli HGET "swarm:${TASK_ID}:loop2:consensus" "feedback" || echo "")
78
78
  TASK_CONTEXT=$(redis-cli HGETALL "swarm:${TASK_ID}:context" || echo "")
79
79
 
80
- # Build Product Owner context
80
+ # Retrieve comprehensive audit trail data
81
+ echo -e "${YELLOW}🔍 Retrieving audit trail data for informed decision-making...${NC}"
82
+ set +e
83
+ AUDIT_DATA=$(./.claude/skills/cfn-task-audit/get-audit-data.sh \
84
+ --task-id "$TASK_ID" \
85
+ --mode combined \
86
+ --format json 2>/dev/null || echo "[]")
87
+
88
+ AUDIT_SUMMARY=$(./.claude/skills/cfn-task-audit/get-audit-data.sh \
89
+ --task-id "$TASK_ID" \
90
+ --mode combined \
91
+ --format summary 2>/dev/null || echo "No audit data available")
92
+ set -e
93
+
94
+ # Analyze audit data for patterns
95
+ AUDIT_INSIGHTS=""
96
+ if [ "$AUDIT_DATA" != "[]" ]; then
97
+ # Extract key patterns from audit data
98
+ PREVIOUS_DECISIONS=$(echo "$AUDIT_DATA" | jq -r '.[] | select(.agent_type == "product-owner") | .decision' 2>/dev/null | tr '\n' ', ' | sed 's/,$//' || echo "None")
99
+ AGENT_PERFORMANCE=$(echo "$AUDIT_DATA" | jq -r 'group_by(.agent_type) | map({agent: .[0].agent_type, avg_confidence: map(.confidence) | add / length}) | sort_by(.avg_confidence) | reverse | .[0:3] | .[] | "\(.agent): \(.avg_confidence)"' 2>/dev/null || echo "No performance data")
100
+
101
+ # Check for repeating concerns
102
+ REPEATING_CONCERNS=$(echo "$AUDIT_DATA" | jq -r '.[] | select(.agent_type == "reviewer" or .agent_type == "tester") | .reasoning | scan("security|performance|scope|quality|bug")' 2>/dev/null | sort | uniq -c | sort -nr | head -3 | awk '{print $2 " (" $1 "x)"}' | tr '\n' ', ' | sed 's/,$//' || echo "No repeating concerns")
103
+
104
+ AUDIT_INSIGHTS="
105
+ AUDIT TRAIL INSIGHTS:
106
+ - Previous Product Owner Decisions: $PREVIOUS_DECISIONS
107
+ - Top Performing Agents: $AGENT_PERFORMANCE
108
+ - Repeating Concerns: $REPEATING_CONCERNS
109
+ - Total Audit Records: $(echo "$AUDIT_DATA" | jq '. | length' 2>/dev/null || echo "0")
110
+
111
+ Audit Summary:
112
+ $AUDIT_SUMMARY
113
+ "
114
+ else
115
+ AUDIT_INSIGHTS="AUDIT TRAIL: No historical data available for this task."
116
+ fi
117
+
118
+ # Build enhanced Product Owner context with audit insights
81
119
  PO_CONTEXT="
82
120
  You are the Product Owner making a strategic decision for CFN Loop iteration $ITERATION of $MAX_ITERATIONS.
83
121
 
122
+ CURRENT ITERATION DATA:
84
123
  Loop 2 Consensus: $CONSENSUS
85
124
  Threshold: $THRESHOLD
86
125
  Success Criteria: ${SUCCESS_CRITERIA:-"Not specified"}
@@ -91,15 +130,26 @@ $LOOP2_FEEDBACK
91
130
  Task Context:
92
131
  $TASK_CONTEXT
93
132
 
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
133
+ $AUDIT_INSIGHTS
134
+
135
+ ENHANCED DECISION FRAMEWORK:
136
+ Use the audit trail insights to inform your decision. Consider:
137
+ - Are there repeating concerns that suggest systematic issues?
138
+ - Which agents have performed well on similar tasks?
139
+ - Do previous decisions show a pattern of success or failure?
140
+ - Are there cross-mode inconsistencies that need attention?
141
+
142
+ DECISION OPTIONS:
143
+ - PROCEED: Quality threshold met, deliverables complete, audit shows positive trajectory
144
+ - ITERATE: Improvements needed, iterations remaining, audit shows recoverable issues
145
+ - ABORT: Max iterations reached, systematic failure, or audit shows insurmountable barriers
98
146
 
99
147
  Output format:
100
148
  Decision: PROCEED|ITERATE|ABORT
101
- Reasoning: [your explanation]
149
+ Reasoning: [your explanation + audit insights]
102
150
  Confidence: [0.0-1.0]
151
+ Audit Analysis: [brief summary of how audit data influenced your decision]
152
+ Agent Performance: [any observations about agent reliability from audit trail]
103
153
  "
104
154
 
105
155
  # Spawn Product Owner agent
@@ -144,6 +194,12 @@ else
144
194
 
145
195
  # Parse confidence
146
196
  CONFIDENCE=$(echo "$PO_OUTPUT" | grep -oE "Confidence:\s*[0-9]+\.?[0-9]*" | grep -oE "[0-9]+\.?[0-9]*" || echo "0.85")
197
+
198
+ # Parse audit analysis (enhanced output)
199
+ AUDIT_ANALYSIS=$(echo "$PO_OUTPUT" | grep -oiE "Audit Analysis:\s*.*" | sed 's/Audit Analysis:\s*//' || echo "No audit analysis provided")
200
+
201
+ # Parse agent performance observations
202
+ AGENT_PERFORMANCE_OBSERVATIONS=$(echo "$PO_OUTPUT" | grep -oiE "Agent Performance:\s*.*" | sed 's/Agent Performance:\s*//' || echo "No agent performance observations")
147
203
  else
148
204
  echo -e "${RED}❌ ERROR: Product Owner output file missing or empty${NC}"
149
205
  echo "Expected: $PO_OUTPUT_FILE"
@@ -167,6 +223,11 @@ fi
167
223
  echo -e "${GREEN}✅ Product Owner Decision: $DECISION_TYPE${NC}"
168
224
  echo "Reasoning: $REASONING"
169
225
  echo "Confidence: $CONFIDENCE"
226
+ if [ "$AUDIT_DATA" != "[]" ]; then
227
+ echo -e "${BLUE}📊 Audit Analysis: $AUDIT_ANALYSIS${NC}"
228
+ echo -e "${BLUE}🏆 Agent Performance: $AGENT_PERFORMANCE_OBSERVATIONS${NC}"
229
+ echo -e "${BLUE}📈 Audit Records Analyzed: $(echo "$AUDIT_DATA" | jq '. | length' 2>/dev/null || echo "0")${NC}"
230
+ fi
170
231
 
171
232
  # Deliverable verification for PROCEED decisions
172
233
  if [ "$DECISION_TYPE" = "PROCEED" ]; then
@@ -254,7 +315,7 @@ else
254
315
  echo -e "${GREEN}No deferred items detected in Product Owner output${NC}"
255
316
  fi
256
317
 
257
- # Build decision JSON
318
+ # Build enhanced decision JSON with audit insights
258
319
  DECISION_JSON=$(cat <<EOF
259
320
  {
260
321
  "decision": "$DECISION_TYPE",
@@ -263,17 +324,25 @@ DECISION_JSON=$(cat <<EOF
263
324
  "iteration": $ITERATION,
264
325
  "consensus": $CONSENSUS,
265
326
  "threshold": $THRESHOLD,
266
- "timestamp": $(date +%s)
327
+ "timestamp": $(date +%s),
328
+ "audit_analysis": "$AUDIT_ANALYSIS",
329
+ "agent_performance_observations": "$AGENT_PERFORMANCE_OBSERVATIONS",
330
+ "audit_records_analyzed": $(echo "$AUDIT_DATA" | jq '. | length' 2>/dev/null || echo "0"),
331
+ "audit_informed": $(if [ "$AUDIT_DATA" != "[]" ]; then echo "true"; else echo "false"; fi)
267
332
  }
268
333
  EOF
269
334
  )
270
335
 
271
- # Store decision in Redis
272
- echo -e "${YELLOW}💾 Storing decision in Redis...${NC}"
336
+ # Store decision in Redis with audit context
337
+ echo -e "${YELLOW}💾 Storing decision in Redis with audit context...${NC}"
273
338
  redis-cli LPUSH "swarm:${TASK_ID}:decision" "$DECISION_TYPE"
274
339
  redis-cli HSET "swarm:${TASK_ID}:${AGENT_ID}:result" "decision" "$DECISION_TYPE"
275
340
  redis-cli HSET "swarm:${TASK_ID}:${AGENT_ID}:result" "reasoning" "$REASONING"
276
341
  redis-cli HSET "swarm:${TASK_ID}:${AGENT_ID}:result" "confidence" "$CONFIDENCE"
342
+ redis-cli HSET "swarm:${TASK_ID}:${AGENT_ID}:result" "audit_analysis" "$AUDIT_ANALYSIS"
343
+ redis-cli HSET "swarm:${TASK_ID}:${AGENT_ID}:result" "agent_performance_observations" "$AGENT_PERFORMANCE_OBSERVATIONS"
344
+ redis-cli HSET "swarm:${TASK_ID}:${AGENT_ID}:result" "audit_records_analyzed" "$(echo "$AUDIT_DATA" | jq '. | length' 2>/dev/null || echo "0")"
345
+ redis-cli HSET "swarm:${TASK_ID}:${AGENT_ID}:result" "audit_informed" "$(if [ "$AUDIT_DATA" != "[]" ]; then echo "true"; else echo "false"; fi)"
277
346
 
278
347
  # Store in metrics
279
348
  redis-cli LPUSH "swarm:${TASK_ID}:metrics:product_owner_decisions" "$DECISION_JSON"
@@ -293,3 +362,6 @@ redis-cli LPUSH "swarm:${TASK_ID}:${AGENT_ID}:done" "complete"
293
362
  echo "$DECISION_JSON"
294
363
 
295
364
  echo -e "${GREEN}✅ Product Owner decision execution complete${NC}"
365
+ if [ "$AUDIT_DATA" != "[]" ]; then
366
+ echo -e "${BLUE}📊 Decision was informed by audit trail analysis${NC}"
367
+ fi