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.
- package/.claude/commands/CFN_LOOP_TASK_MODE.md +119 -0
- package/.claude/skills/cfn-agent-spawning/spawn-agent.sh +12 -0
- package/.claude/skills/cfn-agent-spawning/spawn-agent.sh.backup +273 -0
- package/.claude/skills/cfn-hybrid-routing/README.md +1 -1
- package/.claude/skills/cfn-loop-orchestration/orchestrate.sh +95 -15
- package/.claude/skills/cfn-loop-orchestration/orchestrate.sh.backup +76 -11
- package/.claude/skills/cfn-loop-orchestration/orchestrate.sh.backup2 +959 -0
- package/.claude/skills/cfn-loop-orchestration/orchestrate.sh.clean +949 -0
- package/.claude/skills/cfn-product-owner-decision/execute-decision.sh +82 -10
- package/claude-assets/agents/cfn-dev-team/architecture/base-template-generator.md +7 -33
- package/claude-assets/agents/cfn-dev-team/architecture/planner.md +7 -47
- package/claude-assets/agents/cfn-dev-team/architecture/system-architect.md +7 -33
- package/claude-assets/agents/cfn-dev-team/coordinators/cfn-frontend-coordinator.md +88 -23
- package/claude-assets/agents/cfn-dev-team/coordinators/cfn-v3-coordinator.md +59 -23
- package/claude-assets/agents/cfn-dev-team/coordinators/consensus-builder.md +43 -39
- package/claude-assets/agents/cfn-dev-team/coordinators/epic-creator.md +69 -0
- package/claude-assets/agents/cfn-dev-team/coordinators/multi-sprint-coordinator.md +65 -1
- package/claude-assets/agents/cfn-dev-team/developers/frontend/mobile-dev.md +7 -47
- package/claude-assets/agents/cfn-dev-team/developers/frontend/typescript-specialist.md +7 -26
- package/claude-assets/agents/cfn-dev-team/developers/rust-developer.md +7 -47
- package/claude-assets/agents/cfn-dev-team/product-owners/cto-agent.md +7 -19
- package/claude-assets/agents/cfn-dev-team/product-owners/power-user-persona.md +9 -49
- package/claude-assets/agents/cfn-dev-team/product-owners/product-owner.md +407 -22
- package/claude-assets/agents/cfn-dev-team/reviewers/quality/code-quality-validator.md +7 -66
- package/claude-assets/agents/cfn-dev-team/reviewers/quality/perf-analyzer.md +7 -76
- package/claude-assets/agents/cfn-dev-team/reviewers/quality/performance-benchmarker.md +8 -2
- package/claude-assets/agents/cfn-dev-team/reviewers/quality/security-specialist.md +7 -66
- package/claude-assets/agents/cfn-dev-team/reviewers/reviewer.md +7 -78
- package/claude-assets/agents/cfn-dev-team/testers/e2e/playwright-tester.md +7 -18
- package/claude-assets/agents/cfn-dev-team/testers/interaction-tester.md +7 -18
- package/claude-assets/agents/cfn-dev-team/testers/tester.md +7 -77
- package/claude-assets/agents/cfn-dev-team/testers/unit/tdd-london-unit-swarm.md +7 -18
- package/claude-assets/agents/cfn-dev-team/testers/validation/validation-production-validator.md +7 -19
- package/claude-assets/agents/cfn-dev-team/testing/test-validation-agent.md +7 -44
- package/claude-assets/agents/cfn-dev-team/utility/agent-builder.md +35 -111
- package/claude-assets/agents/cfn-dev-team/utility/analyst.md +7 -47
- package/claude-assets/agents/cfn-dev-team/utility/code-booster.md +7 -40
- package/claude-assets/agents/cfn-dev-team/utility/context-curator.md +7 -47
- package/claude-assets/commands/CFN_LOOP_TASK_MODE.md +119 -0
- package/claude-assets/skills/cfn-agent-spawning/spawn-agent.sh +12 -0
- package/claude-assets/skills/cfn-agent-spawning/spawn-agent.sh.backup +273 -0
- package/claude-assets/skills/cfn-environment-sanitization/SKILL.md +200 -0
- package/claude-assets/skills/cfn-environment-sanitization/sanitize-environment.sh +244 -0
- package/claude-assets/skills/cfn-hybrid-routing/README.md +1 -1
- package/claude-assets/skills/cfn-loop-orchestration/orchestrate.sh +95 -15
- package/claude-assets/skills/cfn-loop-orchestration/orchestrate.sh.backup +76 -11
- package/claude-assets/skills/cfn-loop-orchestration/orchestrate.sh.backup2 +959 -0
- package/claude-assets/skills/cfn-loop-orchestration/orchestrate.sh.clean +949 -0
- package/claude-assets/skills/cfn-node-heap-sizer/task-mode-heap-limiter.sh +326 -0
- package/claude-assets/skills/cfn-process-instrumentation/SKILL.md +279 -0
- package/claude-assets/skills/cfn-process-instrumentation/instrument-process.sh +323 -0
- package/claude-assets/skills/cfn-product-owner-decision/execute-decision.sh +82 -10
- package/claude-assets/skills/cfn-task-audit/get-audit-data.sh +376 -0
- package/claude-assets/skills/cfn-task-audit/store-task-audit.sh +184 -0
- package/claude-assets/skills/cfn-task-mode-safety/cli-coordination.sh +519 -0
- package/claude-assets/skills/cfn-task-mode-safety/mode-detection.sh +326 -0
- package/claude-assets/skills/cfn-task-mode-sanitize/task-mode-env-sanitizer.sh +224 -0
- package/claude-assets/skills/cfn-telemetry/collect-metrics.sh +249 -0
- package/claude-assets/skills/cfn-telemetry/start-telemetry.sh +111 -0
- package/claude-assets/skills/cfn-validation-runner-instrumentation/wrapped-executor.sh +327 -0
- package/dist/cli/config-manager.js +109 -91
- package/dist/cli/config-manager.js.map +1 -1
- package/package.json +1 -1
- package/scripts/mode-detection.sh +321 -0
- package/scripts/spawn-worker.sh +8 -0
- package/scripts/track-zai-costs-simple.sh +8 -0
|
@@ -122,54 +122,14 @@ async function analyzeWithFallback(system) {
|
|
|
122
122
|
- `agent/${AGENT_ID}/findings/${TASK_ID}`
|
|
123
123
|
- `cfn/phase-${phaseId}/loop3/agent-${AGENT_ID}`
|
|
124
124
|
|
|
125
|
-
##
|
|
125
|
+
## Completion Protocol
|
|
126
126
|
|
|
127
|
-
|
|
127
|
+
Complete your work and provide a structured response with:
|
|
128
|
+
- Confidence score (0.0-1.0) based on work quality
|
|
129
|
+
- Summary of analysis/review completed
|
|
130
|
+
- List of findings or deliverables
|
|
131
|
+
- Any recommendations made
|
|
128
132
|
|
|
129
|
-
|
|
130
|
-
Execute assigned task (system analysis, performance investigation, code quality assessment)
|
|
131
|
-
|
|
132
|
-
### Step 2: Signal Completion
|
|
133
|
-
```bash
|
|
134
|
-
redis-cli lpush "swarm:${TASK_ID}:${AGENT_ID}:done" "complete"
|
|
135
|
-
```
|
|
136
|
-
|
|
137
|
-
### Step 3: Report Confidence Score
|
|
138
|
-
```bash
|
|
139
|
-
./.claude/skills/redis-coordination/invoke-waiting-mode.sh report \
|
|
140
|
-
|
|
141
|
-
**After reporting, exit cleanly. Do NOT enter waiting mode.**
|
|
142
|
-
|
|
143
|
-
**Why This Matters:**
|
|
144
|
-
- Orchestrator collects confidence/consensus scores from Redis
|
|
145
|
-
- Enables adaptive agent specialization for next iteration
|
|
146
|
-
- Prevents orchestrator blocking on wait $PID
|
|
147
|
-
- Coordinator spawns appropriate specialist based on feedback type
|
|
148
|
-
|
|
149
|
-
--task-id "$TASK_ID" \
|
|
150
|
-
--agent-id "$AGENT_ID" \
|
|
151
|
-
--confidence [0.0-1.0] \
|
|
152
|
-
--iteration 1
|
|
153
|
-
```
|
|
154
|
-
|
|
155
|
-
### Step 4: Enter Waiting Mode (for potential iteration)
|
|
156
|
-
```bash
|
|
157
|
-
--task-id "$TASK_ID" \
|
|
158
|
-
--agent-id "$AGENT_ID" \
|
|
159
|
-
--context "iteration-complete"
|
|
160
|
-
```
|
|
161
|
-
|
|
162
|
-
**Why This Matters:**
|
|
163
|
-
- Zero-token blocking coordination (BLPOP waits without API calls)
|
|
164
|
-
- Orchestrator collects confidence/consensus scores automatically
|
|
165
|
-
- Supports autonomous iteration based on quality gates
|
|
166
|
-
- Agent woken instantly (<100ms) if iteration needed
|
|
167
|
-
|
|
168
|
-
**Context Variables:**
|
|
169
|
-
- `TASK_ID`: Provided by orchestrator/coordinator
|
|
170
|
-
- `AGENT_ID`: Your unique agent identifier (e.g., "analyst-1")
|
|
171
|
-
- Confidence: Your self-assessment score (0.0-1.0)
|
|
172
|
-
|
|
173
|
-
See: `.claude/skills/redis-coordination/SKILL.md` for full protocol details
|
|
133
|
+
**Note:** Coordination instructions are provided when spawned via CLI.
|
|
174
134
|
|
|
175
135
|
Remember: Analysis is not about criticism, but about providing a clear path to system improvement through data-driven insights.
|
|
@@ -95,45 +95,12 @@ npx claude-flow@alpha hooks post-edit [FILE_PATH] \
|
|
|
95
95
|
--memory-key "code-booster/${AGENT_ID}/optimization" \
|
|
96
96
|
--structured
|
|
97
97
|
```
|
|
98
|
-
##
|
|
98
|
+
## Completion Protocol
|
|
99
99
|
|
|
100
|
-
|
|
100
|
+
Complete your work and provide a structured response with:
|
|
101
|
+
- Confidence score (0.0-1.0) based on work quality
|
|
102
|
+
- Summary of analysis/review completed
|
|
103
|
+
- List of findings or deliverables
|
|
104
|
+
- Any recommendations made
|
|
101
105
|
|
|
102
|
-
|
|
103
|
-
Execute assigned task (code optimization, WASM acceleration, performance enhancement)
|
|
104
|
-
|
|
105
|
-
### Step 2: Signal Completion
|
|
106
|
-
```bash
|
|
107
|
-
redis-cli lpush "swarm:${TASK_ID}:${AGENT_ID}:done" "complete"
|
|
108
|
-
```
|
|
109
|
-
|
|
110
|
-
### Step 3: Report Confidence Score
|
|
111
|
-
```bash
|
|
112
|
-
./.claude/skills/redis-coordination/invoke-waiting-mode.sh report --task-id "$TASK_ID" --agent-id "$AGENT_ID" --confidence [0.0-1.0] --iteration 1
|
|
113
|
-
|
|
114
|
-
**After reporting, exit cleanly. Do NOT enter waiting mode.**
|
|
115
|
-
|
|
116
|
-
**Why This Matters:**
|
|
117
|
-
- Orchestrator collects confidence/consensus scores from Redis
|
|
118
|
-
- Enables adaptive agent specialization for next iteration
|
|
119
|
-
- Prevents orchestrator blocking on wait $PID
|
|
120
|
-
- Coordinator spawns appropriate specialist based on feedback type
|
|
121
|
-
|
|
122
|
-
```
|
|
123
|
-
|
|
124
|
-
### Step 4: Enter Waiting Mode (for potential iteration)
|
|
125
|
-
```bash
|
|
126
|
-
```
|
|
127
|
-
|
|
128
|
-
**Why This Matters:**
|
|
129
|
-
- Zero-token blocking coordination (BLPOP waits without API calls)
|
|
130
|
-
- Orchestrator collects confidence/consensus scores automatically
|
|
131
|
-
- Supports autonomous iteration based on quality gates
|
|
132
|
-
- Agent woken instantly (<100ms) if iteration needed
|
|
133
|
-
|
|
134
|
-
**Context Variables:**
|
|
135
|
-
- `TASK_ID`: Provided by orchestrator/coordinator
|
|
136
|
-
- `AGENT_ID`: Your unique agent identifier (e.g., "code-booster-1")
|
|
137
|
-
- Confidence: Self-assessment score of optimization quality and performance gain (0.0-1.0)
|
|
138
|
-
|
|
139
|
-
See: `.claude/skills/redis-coordination/SKILL.md` for full protocol details
|
|
106
|
+
**Note:** Coordination instructions are provided when spawned via CLI.
|
|
@@ -45,52 +45,12 @@ Intelligent context merging and prioritization
|
|
|
45
45
|
- No destructive merges
|
|
46
46
|
- Explainable AI principles
|
|
47
47
|
|
|
48
|
-
##
|
|
48
|
+
## Completion Protocol
|
|
49
49
|
|
|
50
|
-
|
|
50
|
+
Complete your work and provide a structured response with:
|
|
51
|
+
- Confidence score (0.0-1.0) based on work quality
|
|
52
|
+
- Summary of analysis/review completed
|
|
53
|
+
- List of findings or deliverables
|
|
54
|
+
- Any recommendations made
|
|
51
55
|
|
|
52
|
-
|
|
53
|
-
Execute assigned task (context merging, prioritization, adaptive learning strategy)
|
|
54
|
-
|
|
55
|
-
### Step 2: Signal Completion
|
|
56
|
-
```bash
|
|
57
|
-
redis-cli lpush "swarm:${TASK_ID}:${AGENT_ID}:done" "complete"
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
### Step 3: Report Confidence Score
|
|
61
|
-
```bash
|
|
62
|
-
./.claude/skills/redis-coordination/invoke-waiting-mode.sh report \
|
|
63
|
-
|
|
64
|
-
**After reporting, exit cleanly. Do NOT enter waiting mode.**
|
|
65
|
-
|
|
66
|
-
**Why This Matters:**
|
|
67
|
-
- Orchestrator collects confidence/consensus scores from Redis
|
|
68
|
-
- Enables adaptive agent specialization for next iteration
|
|
69
|
-
- Prevents orchestrator blocking on wait $PID
|
|
70
|
-
- Coordinator spawns appropriate specialist based on feedback type
|
|
71
|
-
|
|
72
|
-
--task-id "$TASK_ID" \
|
|
73
|
-
--agent-id "$AGENT_ID" \
|
|
74
|
-
--confidence [0.0-1.0] \
|
|
75
|
-
--iteration 1
|
|
76
|
-
```
|
|
77
|
-
|
|
78
|
-
### Step 4: Enter Waiting Mode (for potential iteration)
|
|
79
|
-
```bash
|
|
80
|
-
--task-id "$TASK_ID" \
|
|
81
|
-
--agent-id "$AGENT_ID" \
|
|
82
|
-
--context "iteration-complete"
|
|
83
|
-
```
|
|
84
|
-
|
|
85
|
-
**Why This Matters:**
|
|
86
|
-
- Zero-token blocking coordination (BLPOP waits without API calls)
|
|
87
|
-
- Orchestrator collects confidence/consensus scores automatically
|
|
88
|
-
- Supports autonomous iteration based on quality gates
|
|
89
|
-
- Agent woken instantly (<100ms) if iteration needed
|
|
90
|
-
|
|
91
|
-
**Context Variables:**
|
|
92
|
-
- `TASK_ID`: Provided by orchestrator/coordinator
|
|
93
|
-
- `AGENT_ID`: Your unique agent identifier (e.g., "context-curator-1")
|
|
94
|
-
- Confidence: Your self-assessment score (0.0-1.0)
|
|
95
|
-
|
|
96
|
-
See: `.claude/skills/redis-coordination/SKILL.md` for full protocol details
|
|
56
|
+
**Note:** Coordination instructions are provided when spawned via CLI.
|
|
@@ -35,6 +35,125 @@ Task Mode: Main Chat coordinates directly and spawns agents via Task() tool with
|
|
|
35
35
|
|
|
36
36
|
---
|
|
37
37
|
|
|
38
|
+
## ANTI-023 Memory Leak Protection (v2.14.28)
|
|
39
|
+
|
|
40
|
+
**Critical Fix**: Prevents Task Mode agents from executing CLI coordination scripts that cause memory leaks.
|
|
41
|
+
|
|
42
|
+
### Three-Layer Defense System
|
|
43
|
+
|
|
44
|
+
#### Layer 1: Agent Documentation
|
|
45
|
+
**Task Mode agents use mode-specific completion protocols:**
|
|
46
|
+
```markdown
|
|
47
|
+
## ⚠️ CRITICAL: Mode-Specific Completion Protocol
|
|
48
|
+
|
|
49
|
+
**Task Mode (95%):** Spawned via `Task("agent", "...")` in Main Chat
|
|
50
|
+
- Return structured JSON output directly
|
|
51
|
+
- ❌ DO NOT: Use Redis commands, bash scripts, CLI tools
|
|
52
|
+
- ✅ Main Chat receives output automatically
|
|
53
|
+
|
|
54
|
+
**CLI Mode (5%):** Spawned via `npx claude-flow-novice agent-spawn`
|
|
55
|
+
- Use Redis signals and completion scripts
|
|
56
|
+
- ✅ CLI coordination allowed
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
#### Layer 2: Agent-Level Detection
|
|
60
|
+
**Automatic detection functions prevent CLI usage:**
|
|
61
|
+
```bash
|
|
62
|
+
detect_task_mode_and_exit() {
|
|
63
|
+
if [[ -z "${TASK_ID:-}" || -z "${AGENT_ID:-}" ]]; then
|
|
64
|
+
echo "❌ TASK MODE DETECTED - CLI commands forbidden"
|
|
65
|
+
exit 1
|
|
66
|
+
fi
|
|
67
|
+
}
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
#### Layer 3: Code-Level Runtime Blocking
|
|
71
|
+
**Coordination scripts include early exit checks:**
|
|
72
|
+
```bash
|
|
73
|
+
# ⚠️ ANTI-023 MEMORY LEAK PROTECTION
|
|
74
|
+
if [[ -z "${TASK_ID:-}" || -z "${AGENT_ID:-}" ]]; then
|
|
75
|
+
echo "❌ TASK MODE DETECTED - Redis coordination forbidden"
|
|
76
|
+
exit 1
|
|
77
|
+
fi
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### Memory Impact Resolution
|
|
81
|
+
- **Before Fix**: Up to 23GB memory consumption per hanging agent
|
|
82
|
+
- **After Fix**: <100MB normal usage with complete audit trails
|
|
83
|
+
- **Detection Logic**: Environment variable presence indicates spawn mode
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
## Audit Trail Architecture (New v2.14.28)
|
|
88
|
+
|
|
89
|
+
### Dual-Mode Storage System
|
|
90
|
+
|
|
91
|
+
**Design Principle**: Both Task Mode and CLI Mode create complete audit trails for compliance and debugging.
|
|
92
|
+
|
|
93
|
+
#### Task Mode Storage (Main Chat Managed)
|
|
94
|
+
```bash
|
|
95
|
+
# After Task Mode agent completion, Main Chat stores audit data
|
|
96
|
+
./.claude/skills/cfn-task-audit/store-task-audit.sh \
|
|
97
|
+
--task-id "$TASK_ID" \
|
|
98
|
+
--agent-type "$AGENT_TYPE" \
|
|
99
|
+
--output "$AGENT_OUTPUT" \
|
|
100
|
+
--mode "Task"
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
**Storage Locations:**
|
|
104
|
+
- **Redis**: Fast access (`swarm:${TASK_ID}:${AGENT_TYPE}:audit`)
|
|
105
|
+
- **SQLite**: Permanent audit trail (`agent_audit` table)
|
|
106
|
+
- **Files**: Structured logs (`.claude/logs/task-audit/`)
|
|
107
|
+
|
|
108
|
+
#### CLI Mode Storage (Agent Managed)
|
|
109
|
+
```bash
|
|
110
|
+
# CLI agents continue using existing Redis coordination
|
|
111
|
+
redis-cli HSET "swarm:${TASK_ID}:${AGENT_ID}:result" \
|
|
112
|
+
"decision" "$DECISION" \
|
|
113
|
+
"mode" "CLI"
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### Combined Audit Retrieval
|
|
117
|
+
```bash
|
|
118
|
+
# Retrieve complete audit trail from both modes
|
|
119
|
+
get-audit-data.sh --task-id "$TASK_ID" --mode "combined"
|
|
120
|
+
|
|
121
|
+
# Returns unified decision data:
|
|
122
|
+
{
|
|
123
|
+
"task_mode_data": [...],
|
|
124
|
+
"cli_mode_data": [...],
|
|
125
|
+
"complete_audit_trail": true,
|
|
126
|
+
"execution_summary": {...}
|
|
127
|
+
}
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
### Audit Data Structure
|
|
131
|
+
```json
|
|
132
|
+
{
|
|
133
|
+
"task_id": "task-123",
|
|
134
|
+
"agent_type": "reviewer",
|
|
135
|
+
"decision": "PROCEED",
|
|
136
|
+
"reasoning": "Code meets quality standards",
|
|
137
|
+
"confidence": 0.92,
|
|
138
|
+
"mode": "Task|CLI",
|
|
139
|
+
"deliverables": ["file.ts", "test.ts"],
|
|
140
|
+
"timestamp": "2025-11-06T15:30:00Z",
|
|
141
|
+
"metadata": {
|
|
142
|
+
"stored_via": "store-task-audit.sh",
|
|
143
|
+
"version": "1.0.0"
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### Benefits
|
|
149
|
+
- **✅ Complete Coverage**: Both execution modes fully audited
|
|
150
|
+
- **✅ Memory Safe**: ANTI-023 protection maintained
|
|
151
|
+
- **✅ Compliance Ready**: Full audit trail for enterprise requirements
|
|
152
|
+
- **✅ Debugging Support**: Replay capability for complex issues
|
|
153
|
+
- **✅ Performance**: Fast Redis access + persistent SQLite storage
|
|
154
|
+
|
|
155
|
+
---
|
|
156
|
+
|
|
38
157
|
## Agent Specialization
|
|
39
158
|
|
|
40
159
|
### Loop 3 (Implementation)
|
|
@@ -5,6 +5,18 @@
|
|
|
5
5
|
|
|
6
6
|
set -euo pipefail
|
|
7
7
|
|
|
8
|
+
|
|
9
|
+
# ⚠️ ANTI-023 MEMORY LEAK PROTECTION: Environment Sanitization
|
|
10
|
+
# Load and apply environment sanitization to prevent memory leaks
|
|
11
|
+
# shellcheck source=../cfn-environment-sanitization/sanitize-environment.sh
|
|
12
|
+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
13
|
+
if [[ -f "$SCRIPT_DIR/../cfn-environment-sanitization/sanitize-environment.sh" ]]; then
|
|
14
|
+
source "$SCRIPT_DIR/../cfn-environment-sanitization/sanitize-environment.sh" --strict
|
|
15
|
+
echo "✅ Agent spawning environment sanitized" >&2
|
|
16
|
+
else
|
|
17
|
+
echo "⚠️ Environment sanitization not available - proceeding without protection" >&2
|
|
18
|
+
fi
|
|
19
|
+
|
|
8
20
|
# ⚠️ ANTI-023 MEMORY LEAK PROTECTION: Block Task Mode agents
|
|
9
21
|
# Task Mode agents spawn via Task() tool and should NOT use agent spawning CLI
|
|
10
22
|
if [[ -z "${1:-}" || -z "${TASK_ID:-}" ]]; then
|
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
# Agent Spawning CLI Wrapper
|
|
4
|
+
# Enables agents to spawn other agents or stop existing agents via simple CLI interface
|
|
5
|
+
|
|
6
|
+
set -euo pipefail
|
|
7
|
+
|
|
8
|
+
# ⚠️ ANTI-023 MEMORY LEAK PROTECTION: Block Task Mode agents
|
|
9
|
+
# Task Mode agents spawn via Task() tool and should NOT use agent spawning CLI
|
|
10
|
+
if [[ -z "${1:-}" || -z "${TASK_ID:-}" ]]; then
|
|
11
|
+
echo "❌ TASK MODE DETECTED - Agent spawning CLI forbidden" >&2
|
|
12
|
+
echo "🚨 ANTI-023: This script is for CLI-spawned coordinators only" >&2
|
|
13
|
+
echo "💡 Task Mode agent spawning should be handled directly by Main Chat" >&2
|
|
14
|
+
echo "🔧 Agent spawned via Task() tool - use Task() tool for spawning instead" >&2
|
|
15
|
+
exit 1
|
|
16
|
+
fi
|
|
17
|
+
|
|
18
|
+
# ============================================================================
|
|
19
|
+
# LOGGING FUNCTIONS
|
|
20
|
+
# ============================================================================
|
|
21
|
+
log_error() {
|
|
22
|
+
echo "[ERROR] $*" >&2
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
log_warning() {
|
|
26
|
+
echo "[WARNING] $*" >&2
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
log_info() {
|
|
30
|
+
echo "[INFO] $*"
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
# ============================================================================
|
|
34
|
+
# DEPENDENCY CHECKS
|
|
35
|
+
# ============================================================================
|
|
36
|
+
|
|
37
|
+
check_dependencies() {
|
|
38
|
+
local missing_deps=()
|
|
39
|
+
|
|
40
|
+
# Check bash version
|
|
41
|
+
if [[ "${BASH_VERSINFO[0]}" -lt 4 ]]; then
|
|
42
|
+
missing_deps+=("bash>=4.0")
|
|
43
|
+
fi
|
|
44
|
+
|
|
45
|
+
# Check required command-line tools
|
|
46
|
+
local required_tools=("npx" "node" "grep" "sed")
|
|
47
|
+
for tool in "${required_tools[@]}"; do
|
|
48
|
+
if ! command -v "$tool" &> /dev/null; then
|
|
49
|
+
missing_deps+=("$tool")
|
|
50
|
+
fi
|
|
51
|
+
done
|
|
52
|
+
|
|
53
|
+
# Check required Node.js modules
|
|
54
|
+
local node_modules=(
|
|
55
|
+
"redis"
|
|
56
|
+
"dotenv"
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
for module in "${node_modules[@]}"; do
|
|
60
|
+
if [[ ! -d "node_modules/$module" ]]; then
|
|
61
|
+
missing_deps+=("$module")
|
|
62
|
+
fi
|
|
63
|
+
done
|
|
64
|
+
|
|
65
|
+
# Specific Claude Flow dependencies
|
|
66
|
+
local claude_deps=(
|
|
67
|
+
"Task tool"
|
|
68
|
+
"session-manager.js"
|
|
69
|
+
"redis-coordination scripts"
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
# Use current directory as PROJECT_ROOT if not set
|
|
73
|
+
PROJECT_ROOT="${PROJECT_ROOT:-$(pwd)}"
|
|
74
|
+
|
|
75
|
+
for dep in "${claude_deps[@]}"; do
|
|
76
|
+
if [[ ! -d "$PROJECT_ROOT/.claude" ]]; then
|
|
77
|
+
missing_deps+=("$dep")
|
|
78
|
+
fi
|
|
79
|
+
done
|
|
80
|
+
|
|
81
|
+
# Report missing dependencies
|
|
82
|
+
if [[ ${#missing_deps[@]} -gt 0 ]]; then
|
|
83
|
+
log_error "Missing Dependencies:"
|
|
84
|
+
for dep in "${missing_deps[@]}"; do
|
|
85
|
+
echo " - $dep"
|
|
86
|
+
done
|
|
87
|
+
|
|
88
|
+
log_warning "Recommended Installation:"
|
|
89
|
+
echo " 1. Install Node.js and npm (latest LTS version)"
|
|
90
|
+
echo " 2. Run: npm install redis dotenv"
|
|
91
|
+
echo " 3. Clone Claude Flow Novice repository"
|
|
92
|
+
|
|
93
|
+
exit 1
|
|
94
|
+
fi
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
# ============================================================================
|
|
98
|
+
# AGENT SPAWNING FUNCTIONS
|
|
99
|
+
# ============================================================================
|
|
100
|
+
|
|
101
|
+
# Spawn agents via CLI
|
|
102
|
+
spawn_agents() {
|
|
103
|
+
local task="$1"
|
|
104
|
+
local agents="$2"
|
|
105
|
+
local agent_id="${3:-main}"
|
|
106
|
+
local provider="${4:-zai}"
|
|
107
|
+
local redis_channel="${5:-}"
|
|
108
|
+
|
|
109
|
+
log_info "Spawning agents: $agents"
|
|
110
|
+
log_info "Task: $task"
|
|
111
|
+
|
|
112
|
+
# Build spawn command
|
|
113
|
+
local spawn_cmd="npx claude-flow-spawn \"$task\" --agents=$agents --provider=$provider"
|
|
114
|
+
|
|
115
|
+
# Add optional Redis channel
|
|
116
|
+
if [[ -n "$redis_channel" ]]; then
|
|
117
|
+
spawn_cmd="$spawn_cmd --redis-channel=$redis_channel"
|
|
118
|
+
fi
|
|
119
|
+
|
|
120
|
+
# Execute spawn
|
|
121
|
+
eval "$spawn_cmd"
|
|
122
|
+
local exit_code=$?
|
|
123
|
+
|
|
124
|
+
if [[ $exit_code -eq 0 ]]; then
|
|
125
|
+
log_info "Agents spawned successfully"
|
|
126
|
+
else
|
|
127
|
+
log_error "Failed to spawn agents (exit code: $exit_code)"
|
|
128
|
+
exit $exit_code
|
|
129
|
+
fi
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
# Stop agent by task ID
|
|
133
|
+
stop_agent() {
|
|
134
|
+
local task_id="$1"
|
|
135
|
+
|
|
136
|
+
log_info "Stopping agent: $task_id"
|
|
137
|
+
npx claude-flow-spawn --stop="$task_id"
|
|
138
|
+
|
|
139
|
+
if [[ $? -eq 0 ]]; then
|
|
140
|
+
log_info "Agent stopped successfully"
|
|
141
|
+
else
|
|
142
|
+
log_error "Failed to stop agent"
|
|
143
|
+
exit 1
|
|
144
|
+
fi
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
# Stop all agents
|
|
148
|
+
stop_all_agents() {
|
|
149
|
+
log_info "Stopping all agents"
|
|
150
|
+
npx claude-flow-spawn --stop-all
|
|
151
|
+
|
|
152
|
+
if [[ $? -eq 0 ]]; then
|
|
153
|
+
log_info "All agents stopped"
|
|
154
|
+
else
|
|
155
|
+
log_error "Failed to stop all agents"
|
|
156
|
+
exit 1
|
|
157
|
+
fi
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
# Configuration handler function
|
|
161
|
+
handle_config() {
|
|
162
|
+
local action="$1"
|
|
163
|
+
local key="${2:-}"
|
|
164
|
+
local value="${3:-}"
|
|
165
|
+
|
|
166
|
+
case "$action" in
|
|
167
|
+
list)
|
|
168
|
+
# Placeholder: List configuration (modify as needed)
|
|
169
|
+
echo "redis_host=localhost"
|
|
170
|
+
echo "redis_port=6379"
|
|
171
|
+
;;
|
|
172
|
+
get)
|
|
173
|
+
# Placeholder: Return config value (modify as needed)
|
|
174
|
+
case "$key" in
|
|
175
|
+
redis_host)
|
|
176
|
+
echo "localhost"
|
|
177
|
+
;;
|
|
178
|
+
*)
|
|
179
|
+
log_error "Unknown config key: $key"
|
|
180
|
+
exit 1
|
|
181
|
+
;;
|
|
182
|
+
esac
|
|
183
|
+
;;
|
|
184
|
+
set)
|
|
185
|
+
# Placeholder: Set config value (modify as needed)
|
|
186
|
+
log_info "Setting $key to $value"
|
|
187
|
+
;;
|
|
188
|
+
*)
|
|
189
|
+
log_error "Invalid config action: $action"
|
|
190
|
+
exit 1
|
|
191
|
+
;;
|
|
192
|
+
esac
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
# Main function to include dependency check and argument parsing
|
|
196
|
+
main() {
|
|
197
|
+
check_dependencies # Dependency check before processing
|
|
198
|
+
|
|
199
|
+
# Parse arguments
|
|
200
|
+
case "${1:-}" in
|
|
201
|
+
--check-dependencies)
|
|
202
|
+
log_info "Dependencies checked successfully"
|
|
203
|
+
;;
|
|
204
|
+
--config)
|
|
205
|
+
shift
|
|
206
|
+
handle_config "$@"
|
|
207
|
+
;;
|
|
208
|
+
--task)
|
|
209
|
+
shift
|
|
210
|
+
local task="$1"
|
|
211
|
+
shift
|
|
212
|
+
local agents=""
|
|
213
|
+
local agent_id="main"
|
|
214
|
+
local provider="zai"
|
|
215
|
+
local redis_channel=""
|
|
216
|
+
|
|
217
|
+
# Parse remaining arguments
|
|
218
|
+
while [[ $# -gt 0 ]]; do
|
|
219
|
+
case "$1" in
|
|
220
|
+
--agents)
|
|
221
|
+
agents="$2"
|
|
222
|
+
shift 2
|
|
223
|
+
;;
|
|
224
|
+
--agent-id)
|
|
225
|
+
agent_id="$2"
|
|
226
|
+
shift 2
|
|
227
|
+
;;
|
|
228
|
+
--provider)
|
|
229
|
+
provider="$2"
|
|
230
|
+
shift 2
|
|
231
|
+
;;
|
|
232
|
+
--redis-channel)
|
|
233
|
+
redis_channel="$2"
|
|
234
|
+
shift 2
|
|
235
|
+
;;
|
|
236
|
+
*)
|
|
237
|
+
log_error "Unknown argument: $1"
|
|
238
|
+
exit 1
|
|
239
|
+
;;
|
|
240
|
+
esac
|
|
241
|
+
done
|
|
242
|
+
|
|
243
|
+
# Validate required arguments
|
|
244
|
+
if [[ -z "$task" ]] || [[ -z "$agents" ]]; then
|
|
245
|
+
log_error "Missing required arguments: --task and --agents"
|
|
246
|
+
exit 1
|
|
247
|
+
fi
|
|
248
|
+
|
|
249
|
+
# Spawn agents
|
|
250
|
+
spawn_agents "$task" "$agents" "$agent_id" "$provider" "$redis_channel"
|
|
251
|
+
;;
|
|
252
|
+
--stop)
|
|
253
|
+
shift
|
|
254
|
+
stop_agent "$1"
|
|
255
|
+
;;
|
|
256
|
+
--stop-all)
|
|
257
|
+
stop_all_agents
|
|
258
|
+
;;
|
|
259
|
+
*)
|
|
260
|
+
log_error "Unknown argument: $1"
|
|
261
|
+
echo "Usage:"
|
|
262
|
+
echo " spawn-agent.sh --task \"Task description\" --agents coder,tester [--provider zai] [--redis-channel channel]"
|
|
263
|
+
echo " spawn-agent.sh --stop <task-id>"
|
|
264
|
+
echo " spawn-agent.sh --stop-all"
|
|
265
|
+
echo " spawn-agent.sh --check-dependencies"
|
|
266
|
+
echo " spawn-agent.sh --config list|get|set"
|
|
267
|
+
exit 1
|
|
268
|
+
;;
|
|
269
|
+
esac
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
# Run main function
|
|
273
|
+
main "$@"
|