claude-flow-novice 2.15.2 → 2.15.3

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 (98) hide show
  1. package/.claude/hooks/cfn-BACKUP_USAGE.md +243 -243
  2. package/.claude/hooks/cfn-invoke-security-validation.sh +69 -69
  3. package/.claude/hooks/cfn-post-edit-cfn-retrospective.sh +78 -78
  4. package/.claude/hooks/cfn-post-edit.config.json +44 -44
  5. package/.claude/skills/agent-lifecycle/SKILL.md +60 -0
  6. package/.claude/skills/agent-lifecycle/execute-lifecycle-hook.sh +573 -0
  7. package/.claude/skills/agent-lifecycle/simple-audit.sh +31 -0
  8. package/.claude/skills/cfn-hybrid-routing/check-dependencies.sh +51 -51
  9. package/.claude/skills/cfn-loop-validation/orchestrate-cfn-loop.sh +252 -252
  10. package/.claude/skills/cfn-redis-coordination/agent-recovery.sh +74 -74
  11. package/.claude/skills/cfn-redis-coordination/get-context.sh +112 -112
  12. package/.claude/skills/cfn-transparency-middleware/middleware-config.sh +28 -28
  13. package/.claude/skills/cfn-transparency-middleware/performance-benchmark.sh +78 -78
  14. package/.claude/skills/cfn-transparency-middleware/test-integration.sh +161 -161
  15. package/.claude/skills/cfn-transparency-middleware/test-transparency-skill.sh +367 -367
  16. package/.claude/skills/cfn-transparency-middleware/tests/input-validation.sh +92 -92
  17. package/.claude/skills/cfn-transparency-middleware/wrap-agent.sh +131 -131
  18. package/claude-assets/hooks/cfn-BACKUP_USAGE.md +243 -243
  19. package/claude-assets/hooks/cfn-invoke-security-validation.sh +69 -69
  20. package/claude-assets/hooks/cfn-post-edit-cfn-retrospective.sh +78 -78
  21. package/claude-assets/hooks/cfn-post-edit.config.json +44 -44
  22. package/claude-assets/hooks/cfn-post-execution/memory-cleanup.sh +19 -19
  23. package/claude-assets/hooks/cfn-pre-execution/memory-check.sh +19 -19
  24. package/claude-assets/skills/agent-lifecycle/execute-lifecycle-hook.sh +572 -572
  25. package/claude-assets/skills/agent-lifecycle/simple-audit.sh +30 -30
  26. package/claude-assets/skills/cfn-automatic-memory-persistence/persist-agent-output.sh +48 -48
  27. package/claude-assets/skills/cfn-automatic-memory-persistence/query-agent-history.sh +34 -34
  28. package/claude-assets/skills/cfn-deliverable-validation/confidence-calculator.sh +261 -261
  29. package/claude-assets/skills/cfn-expert-update/update-expert.sh +345 -345
  30. package/claude-assets/skills/cfn-hybrid-routing/check-dependencies.sh +51 -51
  31. package/claude-assets/skills/cfn-intervention-detector/detect-intervention.sh +110 -110
  32. package/claude-assets/skills/cfn-intervention-orchestrator/execute-intervention.sh +58 -58
  33. package/claude-assets/skills/cfn-loop-validation/orchestrate-cfn-loop.sh +252 -252
  34. package/claude-assets/skills/cfn-loop2-output-processing/process-validator-output.sh +275 -275
  35. package/claude-assets/skills/cfn-memory-management/check-memory.sh +159 -159
  36. package/claude-assets/skills/cfn-memory-management/cleanup-memory.sh +196 -196
  37. package/claude-assets/skills/cfn-node-heap-sizer/task-mode-heap-limiter.sh +325 -325
  38. package/claude-assets/skills/cfn-playbook-auto-update/auto-update-playbook.sh +85 -85
  39. package/claude-assets/skills/cfn-redis-coordination/agent-recovery.sh +74 -74
  40. package/claude-assets/skills/cfn-redis-coordination/get-context.sh +112 -112
  41. package/claude-assets/skills/cfn-scope-simplifier/simplify-scope.sh +67 -67
  42. package/claude-assets/skills/cfn-specialist-injection/recommend-specialist.sh +56 -56
  43. package/claude-assets/skills/cfn-standardized-error-handling/capture-agent-error.sh +86 -86
  44. package/claude-assets/skills/cfn-standardized-error-handling/test-error-handling.sh +165 -165
  45. package/claude-assets/skills/cfn-task-config-init/initialize-config.sh +264 -264
  46. package/claude-assets/skills/cfn-task-decomposition/task-decomposer.sh +278 -278
  47. package/claude-assets/skills/cfn-transparency-middleware/middleware-config.sh +28 -28
  48. package/claude-assets/skills/cfn-transparency-middleware/performance-benchmark.sh +78 -78
  49. package/claude-assets/skills/cfn-transparency-middleware/test-integration.sh +161 -161
  50. package/claude-assets/skills/cfn-transparency-middleware/test-transparency-skill.sh +367 -367
  51. package/claude-assets/skills/cfn-transparency-middleware/tests/input-validation.sh +92 -92
  52. package/claude-assets/skills/cfn-transparency-middleware/wrap-agent.sh +131 -131
  53. package/claude-assets/skills/docker-build/SKILL.md +96 -203
  54. package/claude-assets/skills/docker-build/build.sh +73 -73
  55. package/claude-assets/skills/integration/agent-handoff.sh +494 -0
  56. package/claude-assets/skills/integration/file-operations.sh +414 -0
  57. package/claude-assets/skills/workflow-codification/APPROVAL_WORKFLOW.md +806 -0
  58. package/claude-assets/skills/workflow-codification/COST_TRACKING.md +637 -0
  59. package/claude-assets/skills/workflow-codification/EDGE_CASE_TRACKING.md +404 -0
  60. package/claude-assets/skills/workflow-codification/README_PHASE4.md +457 -0
  61. package/claude-assets/skills/workflow-codification/SKILL.md +110 -0
  62. package/claude-assets/skills/workflow-codification/analyze-patterns.sh +899 -0
  63. package/claude-assets/skills/workflow-codification/approval-workflow.sh +514 -0
  64. package/claude-assets/skills/workflow-codification/generate-skill-update.sh +525 -0
  65. package/claude-assets/skills/workflow-codification/review-skill.sh +643 -0
  66. package/claude-assets/skills/workflow-codification/templates/email-notification.txt +114 -0
  67. package/claude-assets/skills/workflow-codification/templates/slack-notification.md +85 -0
  68. package/claude-assets/skills/workflow-codification/test-integration.sh +281 -0
  69. package/claude-assets/skills/workflow-codification/track-cost-savings.sh +445 -0
  70. package/claude-assets/skills/workflow-codification/track-edge-case.sh +323 -0
  71. package/dist/cli/config-manager.js +91 -109
  72. package/dist/cli/config-manager.js.map +1 -1
  73. package/dist/integration/DatabaseHandoff.js +507 -0
  74. package/dist/integration/DatabaseHandoff.js.map +1 -0
  75. package/dist/integration/StandardAdapter.js +291 -0
  76. package/dist/integration/StandardAdapter.js.map +1 -0
  77. package/dist/lib/agent-output-parser.js +518 -0
  78. package/dist/lib/agent-output-parser.js.map +1 -0
  79. package/dist/lib/agent-output-validator.js +950 -0
  80. package/dist/lib/agent-output-validator.js.map +1 -0
  81. package/dist/lib/artifact-registry.js +443 -0
  82. package/dist/lib/artifact-registry.js.map +1 -0
  83. package/dist/lib/config-validator.js +687 -0
  84. package/dist/lib/config-validator.js.map +1 -0
  85. package/dist/types/agent-output.js +44 -0
  86. package/dist/types/agent-output.js.map +1 -0
  87. package/dist/types/config.js +28 -0
  88. package/dist/types/config.js.map +1 -0
  89. package/package.json +2 -1
  90. package/scripts/artifact-cleanup.sh +392 -0
  91. package/scripts/deploy-production.sh +355 -355
  92. package/scripts/docker-playwright-fix.sh +311 -311
  93. package/scripts/docker-rebuild-all-agents.sh +127 -127
  94. package/scripts/memory-leak-prevention.sh +305 -305
  95. package/scripts/migrate-artifacts.sh +563 -0
  96. package/scripts/migrate-yaml-to-json.sh +465 -0
  97. package/scripts/run-marketing-tests.sh +42 -42
  98. package/scripts/update_paths.sh +46 -46
@@ -1,86 +1,86 @@
1
- #!/bin/bash
2
-
3
- # Playbook Auto-Update Script
4
-
5
- set -euo pipefail
6
-
7
- # Validate input
8
- [[ $# -ne 2 ]] && { echo "Usage: $0 --retrospective-json JSON --task-id TASK_ID"; exit 1; }
9
-
10
- # Parse arguments
11
- while [[ $# -gt 0 ]]; do
12
- key="$1"
13
- case $key in
14
- --retrospective-json)
15
- RETROSPECTIVE_JSON="$2"
16
- shift 2
17
- ;;
18
- --task-id)
19
- TASK_ID="$2"
20
- shift 2
21
- ;;
22
- *)
23
- echo "Unknown parameter: $1"
24
- exit 1
25
- ;;
26
- esac
27
- done
28
-
29
- # Validate required parameters
30
- [[ -z "${RETROSPECTIVE_JSON:-}" ]] && { echo "Error: retrospective-json is required"; exit 1; }
31
- [[ -z "${TASK_ID:-}" ]] && { echo "Error: task-id is required"; exit 1; }
32
-
33
- # Playbook path
34
- PLAYBOOK_PATH="/mnt/c/Users/masha/Documents/claude-flow-novice/docs/PLAYBOOK.json"
35
- BACKUP_PATH="/mnt/c/Users/masha/Documents/claude-flow-novice/docs/playbook-backups/PLAYBOOK_${TASK_ID}_$(date +%Y%m%d_%H%M%S).json"
36
-
37
- # Ensure backup directory exists
38
- mkdir -p "$(dirname "$BACKUP_PATH")"
39
-
40
- # Backup current playbook
41
- cp "$PLAYBOOK_PATH" "$BACKUP_PATH"
42
-
43
- # Update playbook with jq
44
- updated_playbook=$(echo "$RETROSPECTIVE_JSON" | jq '
45
- # Update or create tasks record
46
- .tasks //= [] |
47
- .tasks += [{
48
- "task_id": env.TASK_ID,
49
- "sprint_metrics": {
50
- "total_iterations": .velocity.total_iterations,
51
- "confidence_trajectory": .confidence_trajectory,
52
- "final_confidence": .confidence_trajectory["iteration_3"] // 0
53
- },
54
- "agent_performance": .agent_performance,
55
- "patterns_identified": .patterns_identified
56
- }] |
57
-
58
- # Update agent performance tracking
59
- .agent_performance_history //= {} |
60
- reduce .agent_performance.top_performers[] as $agent (
61
- .;
62
- .agent_performance_history[$agent.agent] //= {
63
- "total_tasks": 0,
64
- "avg_confidence": 0
65
- } |
66
- .agent_performance_history[$agent.agent].total_tasks += 1 |
67
- .agent_performance_history[$agent.agent].avg_confidence =
68
- ((.agent_performance_history[$agent.agent].avg_confidence *
69
- (.agent_performance_history[$agent.agent].total_tasks - 1) +
70
- $agent.avg_confidence) /
71
- .agent_performance_history[$agent.agent].total_tasks)
72
- ) |
73
-
74
- # Track successful strategies
75
- .successful_strategies //= [] |
76
- .successful_strategies += .lessons_learned |
77
-
78
- # Remove redundant data to keep playbook lean
79
- del(.feedback_themes, .bottlenecks)
80
- ')
81
-
82
- # Write updated playbook
83
- echo "$updated_playbook" | jq . > "$PLAYBOOK_PATH"
84
-
85
- # Log update
1
+ #!/bin/bash
2
+
3
+ # Playbook Auto-Update Script
4
+
5
+ set -euo pipefail
6
+
7
+ # Validate input
8
+ [[ $# -ne 2 ]] && { echo "Usage: $0 --retrospective-json JSON --task-id TASK_ID"; exit 1; }
9
+
10
+ # Parse arguments
11
+ while [[ $# -gt 0 ]]; do
12
+ key="$1"
13
+ case $key in
14
+ --retrospective-json)
15
+ RETROSPECTIVE_JSON="$2"
16
+ shift 2
17
+ ;;
18
+ --task-id)
19
+ TASK_ID="$2"
20
+ shift 2
21
+ ;;
22
+ *)
23
+ echo "Unknown parameter: $1"
24
+ exit 1
25
+ ;;
26
+ esac
27
+ done
28
+
29
+ # Validate required parameters
30
+ [[ -z "${RETROSPECTIVE_JSON:-}" ]] && { echo "Error: retrospective-json is required"; exit 1; }
31
+ [[ -z "${TASK_ID:-}" ]] && { echo "Error: task-id is required"; exit 1; }
32
+
33
+ # Playbook path
34
+ PLAYBOOK_PATH="/mnt/c/Users/masha/Documents/claude-flow-novice/docs/PLAYBOOK.json"
35
+ BACKUP_PATH="/mnt/c/Users/masha/Documents/claude-flow-novice/docs/playbook-backups/PLAYBOOK_${TASK_ID}_$(date +%Y%m%d_%H%M%S).json"
36
+
37
+ # Ensure backup directory exists
38
+ mkdir -p "$(dirname "$BACKUP_PATH")"
39
+
40
+ # Backup current playbook
41
+ cp "$PLAYBOOK_PATH" "$BACKUP_PATH"
42
+
43
+ # Update playbook with jq
44
+ updated_playbook=$(echo "$RETROSPECTIVE_JSON" | jq '
45
+ # Update or create tasks record
46
+ .tasks //= [] |
47
+ .tasks += [{
48
+ "task_id": env.TASK_ID,
49
+ "sprint_metrics": {
50
+ "total_iterations": .velocity.total_iterations,
51
+ "confidence_trajectory": .confidence_trajectory,
52
+ "final_confidence": .confidence_trajectory["iteration_3"] // 0
53
+ },
54
+ "agent_performance": .agent_performance,
55
+ "patterns_identified": .patterns_identified
56
+ }] |
57
+
58
+ # Update agent performance tracking
59
+ .agent_performance_history //= {} |
60
+ reduce .agent_performance.top_performers[] as $agent (
61
+ .;
62
+ .agent_performance_history[$agent.agent] //= {
63
+ "total_tasks": 0,
64
+ "avg_confidence": 0
65
+ } |
66
+ .agent_performance_history[$agent.agent].total_tasks += 1 |
67
+ .agent_performance_history[$agent.agent].avg_confidence =
68
+ ((.agent_performance_history[$agent.agent].avg_confidence *
69
+ (.agent_performance_history[$agent.agent].total_tasks - 1) +
70
+ $agent.avg_confidence) /
71
+ .agent_performance_history[$agent.agent].total_tasks)
72
+ ) |
73
+
74
+ # Track successful strategies
75
+ .successful_strategies //= [] |
76
+ .successful_strategies += .lessons_learned |
77
+
78
+ # Remove redundant data to keep playbook lean
79
+ del(.feedback_themes, .bottlenecks)
80
+ ')
81
+
82
+ # Write updated playbook
83
+ echo "$updated_playbook" | jq . > "$PLAYBOOK_PATH"
84
+
85
+ # Log update
86
86
  echo "Playbook updated for task $TASK_ID: $BACKUP_PATH → $PLAYBOOK_PATH"
@@ -1,75 +1,75 @@
1
- #!/bin/bash
2
- # Redis Coordination Skill - Agent Emergency Recovery
3
- # Version: 1.0.0
4
- # Last Updated: 2025-10-19
5
-
6
- # Strict error handling
7
- set -euo pipefail
8
-
9
- # Default values
10
- TASK_ID=""
11
- AGENT_ID=""
12
- RECOVERY_MODE="soft" # Options: soft, hard
13
-
14
- # Parse command-line arguments
15
- while [[ $# -gt 0 ]]; do
16
- case "$1" in
17
- --task-id)
18
- TASK_ID="$2"
19
- shift 2
20
- ;;
21
- --agent-id)
22
- AGENT_ID="$2"
23
- shift 2
24
- ;;
25
- --mode)
26
- RECOVERY_MODE="$2"
27
- shift 2
28
- ;;
29
- *)
30
- echo "Unknown parameter: $1"
31
- exit 1
32
- ;;
33
- esac
34
- done
35
-
36
- # Validate required parameters
37
- if [[ -z "$TASK_ID" || -z "$AGENT_ID" ]]; then
38
- echo "Error: task-id and agent-id are required"
39
- exit 1
40
- fi
41
-
42
- # Log recovery attempt
43
- echo "[$(date -u)] Attempting ${RECOVERY_MODE} recovery for agent: ${AGENT_ID}" >> /var/log/claude-flow/agent-recovery.log
44
-
45
- # Retrieve agent context before recovery
46
- AGENT_CONTEXT=$(redis-cli get "swarm:${TASK_ID}:${AGENT_ID}:context")
47
-
48
- # Recovery actions based on mode
49
- case "$RECOVERY_MODE" in
50
- "soft")
51
- # Soft recovery: Spawn new agent with previous context
52
- npx claude-flow@alpha spawn "$AGENT_ID" \
53
- --task-id "$TASK_ID" \
54
- --recovery-context "$AGENT_CONTEXT"
55
- ;;
56
- "hard")
57
- # Hard recovery: Full agent replacement
58
- npx claude-flow@alpha spawn "$AGENT_ID" \
59
- --task-id "$TASK_ID" \
60
- --mode replace \
61
- --recovery-context "$AGENT_CONTEXT"
62
- ;;
63
- *)
64
- echo "Invalid recovery mode: ${RECOVERY_MODE}"
65
- exit 1
66
- ;;
67
- esac
68
-
69
- # Update active agents set
70
- redis-cli sadd "swarm:${TASK_ID}:active-agents" "$AGENT_ID"
71
-
72
- # Log recovery completion
73
- echo "[$(date -u)] Recovery completed for agent: ${AGENT_ID}" >> /var/log/claude-flow/agent-recovery.log
74
-
1
+ #!/bin/bash
2
+ # Redis Coordination Skill - Agent Emergency Recovery
3
+ # Version: 1.0.0
4
+ # Last Updated: 2025-10-19
5
+
6
+ # Strict error handling
7
+ set -euo pipefail
8
+
9
+ # Default values
10
+ TASK_ID=""
11
+ AGENT_ID=""
12
+ RECOVERY_MODE="soft" # Options: soft, hard
13
+
14
+ # Parse command-line arguments
15
+ while [[ $# -gt 0 ]]; do
16
+ case "$1" in
17
+ --task-id)
18
+ TASK_ID="$2"
19
+ shift 2
20
+ ;;
21
+ --agent-id)
22
+ AGENT_ID="$2"
23
+ shift 2
24
+ ;;
25
+ --mode)
26
+ RECOVERY_MODE="$2"
27
+ shift 2
28
+ ;;
29
+ *)
30
+ echo "Unknown parameter: $1"
31
+ exit 1
32
+ ;;
33
+ esac
34
+ done
35
+
36
+ # Validate required parameters
37
+ if [[ -z "$TASK_ID" || -z "$AGENT_ID" ]]; then
38
+ echo "Error: task-id and agent-id are required"
39
+ exit 1
40
+ fi
41
+
42
+ # Log recovery attempt
43
+ echo "[$(date -u)] Attempting ${RECOVERY_MODE} recovery for agent: ${AGENT_ID}" >> /var/log/claude-flow/agent-recovery.log
44
+
45
+ # Retrieve agent context before recovery
46
+ AGENT_CONTEXT=$(redis-cli get "swarm:${TASK_ID}:${AGENT_ID}:context")
47
+
48
+ # Recovery actions based on mode
49
+ case "$RECOVERY_MODE" in
50
+ "soft")
51
+ # Soft recovery: Spawn new agent with previous context
52
+ npx claude-flow@alpha spawn "$AGENT_ID" \
53
+ --task-id "$TASK_ID" \
54
+ --recovery-context "$AGENT_CONTEXT"
55
+ ;;
56
+ "hard")
57
+ # Hard recovery: Full agent replacement
58
+ npx claude-flow@alpha spawn "$AGENT_ID" \
59
+ --task-id "$TASK_ID" \
60
+ --mode replace \
61
+ --recovery-context "$AGENT_CONTEXT"
62
+ ;;
63
+ *)
64
+ echo "Invalid recovery mode: ${RECOVERY_MODE}"
65
+ exit 1
66
+ ;;
67
+ esac
68
+
69
+ # Update active agents set
70
+ redis-cli sadd "swarm:${TASK_ID}:active-agents" "$AGENT_ID"
71
+
72
+ # Log recovery completion
73
+ echo "[$(date -u)] Recovery completed for agent: ${AGENT_ID}" >> /var/log/claude-flow/agent-recovery.log
74
+
75
75
  exit 0
@@ -1,113 +1,113 @@
1
- #!/bin/bash
2
- # Retrieve CFN Loop task context from Redis
3
- # Used by CLI-spawned agents to get structured context from orchestrator
4
- #
5
- # Usage:
6
- # get-context.sh --task-id <id> [--namespace <ns>]
7
- # get-context.sh --task-id <id> --key <key> [--namespace <ns>]
8
- # get-context.sh <task_id> (legacy mode)
9
-
10
- set -euo pipefail
11
-
12
- # Initialize variables
13
- TASK_ID=""
14
- KEY=""
15
- NAMESPACE="swarm"
16
- FORMAT="json" # json or raw
17
-
18
- # Parse arguments
19
- while [[ $# -gt 0 ]]; do
20
- case $1 in
21
- --task-id)
22
- TASK_ID="$2"
23
- shift 2
24
- ;;
25
- --key)
26
- KEY="$2"
27
- shift 2
28
- ;;
29
- --namespace)
30
- NAMESPACE="$2"
31
- shift 2
32
- ;;
33
- --format)
34
- FORMAT="$2"
35
- shift 2
36
- ;;
37
- *)
38
- # Legacy mode: positional argument
39
- if [ -z "$TASK_ID" ]; then
40
- TASK_ID="$1"
41
- fi
42
- shift
43
- ;;
44
- esac
45
- done
46
-
47
- # Validate required arguments
48
- if [ -z "$TASK_ID" ]; then
49
- echo "Error: --task-id or TASK_ID required" >&2
50
- echo "Usage: $0 --task-id <id> [--key <key>] [--namespace <ns>] [--format <json|raw>]" >&2
51
- echo " or: $0 <task_id> (legacy)" >&2
52
- exit 1
53
- fi
54
-
55
- REDIS_KEY="${NAMESPACE}:${TASK_ID}:context"
56
-
57
- # Check if context exists
58
- if ! redis-cli EXISTS "$REDIS_KEY" >/dev/null 2>&1; then
59
- echo "⚠️ No context found for task: $TASK_ID" >&2
60
- exit 1
61
- fi
62
-
63
- # Handle specific key retrieval
64
- if [ -n "$KEY" ]; then
65
- VALUE=$(redis-cli HGET "$REDIS_KEY" "$KEY" 2>/dev/null || echo "")
66
- if [ -z "$VALUE" ]; then
67
- echo "⚠️ Key '$KEY' not found in context for task: $TASK_ID" >&2
68
- exit 1
69
- fi
70
-
71
- if [ "$FORMAT" = "raw" ]; then
72
- echo "$VALUE"
73
- else
74
- echo "{\"$KEY\":$VALUE}"
75
- fi
76
- exit 0
77
- fi
78
-
79
- # Handle full context retrieval
80
- ALL_FIELDS=$(redis-cli HGETALL "$REDIS_KEY" 2>/dev/null || echo "")
81
-
82
- if [ -z "$ALL_FIELDS" ]; then
83
- echo "⚠️ Empty context for task: $TASK_ID" >&2
84
- exit 1
85
- fi
86
-
87
- # Format as JSON
88
- if [ "$FORMAT" = "json" ]; then
89
- echo "{"
90
- first=true
91
- while IFS= read -r field; do
92
- if [ -z "$field" ]; then continue; fi
93
- if [ "$first" = true ]; then
94
- first=false
95
- else
96
- echo ","
97
- fi
98
- # Skip empty lines and properly format JSON values
99
- if [[ $field =~ ^[0-9]+$ ]]; then
100
- # Numeric value
101
- echo -n " \"$field\": $(redis-cli HGET "$REDIS_KEY" "$field")"
102
- else
103
- # String value
104
- value=$(redis-cli HGET "$REDIS_KEY" "$field" | sed 's/"/\\"/g')
105
- echo -n " \"$field\": \"$value\""
106
- fi
107
- done <<< "$ALL_FIELDS"
108
- echo ""
109
- echo "}"
110
- else
111
- # Raw format
112
- redis-cli HGETALL "$REDIS_KEY"
1
+ #!/bin/bash
2
+ # Retrieve CFN Loop task context from Redis
3
+ # Used by CLI-spawned agents to get structured context from orchestrator
4
+ #
5
+ # Usage:
6
+ # get-context.sh --task-id <id> [--namespace <ns>]
7
+ # get-context.sh --task-id <id> --key <key> [--namespace <ns>]
8
+ # get-context.sh <task_id> (legacy mode)
9
+
10
+ set -euo pipefail
11
+
12
+ # Initialize variables
13
+ TASK_ID=""
14
+ KEY=""
15
+ NAMESPACE="swarm"
16
+ FORMAT="json" # json or raw
17
+
18
+ # Parse arguments
19
+ while [[ $# -gt 0 ]]; do
20
+ case $1 in
21
+ --task-id)
22
+ TASK_ID="$2"
23
+ shift 2
24
+ ;;
25
+ --key)
26
+ KEY="$2"
27
+ shift 2
28
+ ;;
29
+ --namespace)
30
+ NAMESPACE="$2"
31
+ shift 2
32
+ ;;
33
+ --format)
34
+ FORMAT="$2"
35
+ shift 2
36
+ ;;
37
+ *)
38
+ # Legacy mode: positional argument
39
+ if [ -z "$TASK_ID" ]; then
40
+ TASK_ID="$1"
41
+ fi
42
+ shift
43
+ ;;
44
+ esac
45
+ done
46
+
47
+ # Validate required arguments
48
+ if [ -z "$TASK_ID" ]; then
49
+ echo "Error: --task-id or TASK_ID required" >&2
50
+ echo "Usage: $0 --task-id <id> [--key <key>] [--namespace <ns>] [--format <json|raw>]" >&2
51
+ echo " or: $0 <task_id> (legacy)" >&2
52
+ exit 1
53
+ fi
54
+
55
+ REDIS_KEY="${NAMESPACE}:${TASK_ID}:context"
56
+
57
+ # Check if context exists
58
+ if ! redis-cli EXISTS "$REDIS_KEY" >/dev/null 2>&1; then
59
+ echo "⚠️ No context found for task: $TASK_ID" >&2
60
+ exit 1
61
+ fi
62
+
63
+ # Handle specific key retrieval
64
+ if [ -n "$KEY" ]; then
65
+ VALUE=$(redis-cli HGET "$REDIS_KEY" "$KEY" 2>/dev/null || echo "")
66
+ if [ -z "$VALUE" ]; then
67
+ echo "⚠️ Key '$KEY' not found in context for task: $TASK_ID" >&2
68
+ exit 1
69
+ fi
70
+
71
+ if [ "$FORMAT" = "raw" ]; then
72
+ echo "$VALUE"
73
+ else
74
+ echo "{\"$KEY\":$VALUE}"
75
+ fi
76
+ exit 0
77
+ fi
78
+
79
+ # Handle full context retrieval
80
+ ALL_FIELDS=$(redis-cli HGETALL "$REDIS_KEY" 2>/dev/null || echo "")
81
+
82
+ if [ -z "$ALL_FIELDS" ]; then
83
+ echo "⚠️ Empty context for task: $TASK_ID" >&2
84
+ exit 1
85
+ fi
86
+
87
+ # Format as JSON
88
+ if [ "$FORMAT" = "json" ]; then
89
+ echo "{"
90
+ first=true
91
+ while IFS= read -r field; do
92
+ if [ -z "$field" ]; then continue; fi
93
+ if [ "$first" = true ]; then
94
+ first=false
95
+ else
96
+ echo ","
97
+ fi
98
+ # Skip empty lines and properly format JSON values
99
+ if [[ $field =~ ^[0-9]+$ ]]; then
100
+ # Numeric value
101
+ echo -n " \"$field\": $(redis-cli HGET "$REDIS_KEY" "$field")"
102
+ else
103
+ # String value
104
+ value=$(redis-cli HGET "$REDIS_KEY" "$field" | sed 's/"/\\"/g')
105
+ echo -n " \"$field\": \"$value\""
106
+ fi
107
+ done <<< "$ALL_FIELDS"
108
+ echo ""
109
+ echo "}"
110
+ else
111
+ # Raw format
112
+ redis-cli HGETALL "$REDIS_KEY"
113
113
  fi