@claude-flow/cli 3.0.0-alpha.37 → 3.0.0-alpha.39
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/helpers/README.md +97 -0
- package/.claude/helpers/adr-compliance.sh +186 -0
- package/.claude/helpers/auto-commit.sh +178 -0
- package/.claude/helpers/checkpoint-manager.sh +251 -0
- package/.claude/helpers/daemon-manager.sh +252 -0
- package/.claude/helpers/ddd-tracker.sh +144 -0
- package/.claude/helpers/github-safe.js +106 -0
- package/.claude/helpers/github-setup.sh +28 -0
- package/.claude/helpers/guidance-hook.sh +13 -0
- package/.claude/helpers/guidance-hooks.sh +102 -0
- package/.claude/helpers/health-monitor.sh +108 -0
- package/.claude/helpers/learning-hooks.sh +329 -0
- package/.claude/helpers/learning-optimizer.sh +127 -0
- package/.claude/helpers/learning-service.mjs +1144 -0
- package/.claude/helpers/metrics-db.mjs +488 -0
- package/.claude/helpers/pattern-consolidator.sh +86 -0
- package/.claude/helpers/perf-worker.sh +160 -0
- package/.claude/helpers/quick-start.sh +19 -0
- package/.claude/helpers/security-scanner.sh +127 -0
- package/.claude/helpers/setup-mcp.sh +18 -0
- package/.claude/helpers/standard-checkpoint-hooks.sh +189 -0
- package/.claude/helpers/swarm-comms.sh +353 -0
- package/.claude/helpers/swarm-hooks.sh +761 -0
- package/.claude/helpers/swarm-monitor.sh +211 -0
- package/.claude/helpers/sync-v3-metrics.sh +245 -0
- package/.claude/helpers/update-v3-progress.sh +166 -0
- package/.claude/helpers/v3-quick-status.sh +58 -0
- package/.claude/helpers/v3.sh +111 -0
- package/.claude/helpers/validate-v3-config.sh +216 -0
- package/.claude/helpers/worker-manager.sh +170 -0
- package/dist/src/init/executor.d.ts.map +1 -1
- package/dist/src/init/executor.js +103 -26
- package/dist/src/init/executor.js.map +1 -1
- package/dist/src/init/mcp-generator.js +2 -2
- package/dist/src/init/mcp-generator.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# Claude Flow V3 - Optimized Swarm Communications
|
|
3
|
+
# Non-blocking, batched, priority-based inter-agent messaging
|
|
4
|
+
|
|
5
|
+
set -euo pipefail
|
|
6
|
+
|
|
7
|
+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
8
|
+
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
|
|
9
|
+
SWARM_DIR="$PROJECT_ROOT/.claude-flow/swarm"
|
|
10
|
+
QUEUE_DIR="$SWARM_DIR/queue"
|
|
11
|
+
BATCH_DIR="$SWARM_DIR/batch"
|
|
12
|
+
POOL_FILE="$SWARM_DIR/connection-pool.json"
|
|
13
|
+
|
|
14
|
+
mkdir -p "$QUEUE_DIR" "$BATCH_DIR"
|
|
15
|
+
|
|
16
|
+
# Priority levels
|
|
17
|
+
PRIORITY_CRITICAL=0
|
|
18
|
+
PRIORITY_HIGH=1
|
|
19
|
+
PRIORITY_NORMAL=2
|
|
20
|
+
PRIORITY_LOW=3
|
|
21
|
+
|
|
22
|
+
# Batch settings
|
|
23
|
+
BATCH_SIZE=10
|
|
24
|
+
BATCH_TIMEOUT_MS=100
|
|
25
|
+
|
|
26
|
+
# =============================================================================
|
|
27
|
+
# NON-BLOCKING MESSAGE QUEUE
|
|
28
|
+
# =============================================================================
|
|
29
|
+
|
|
30
|
+
# Enqueue message (instant return, async processing)
|
|
31
|
+
enqueue() {
|
|
32
|
+
local to="${1:-*}"
|
|
33
|
+
local content="${2:-}"
|
|
34
|
+
local priority="${3:-$PRIORITY_NORMAL}"
|
|
35
|
+
local msg_type="${4:-context}"
|
|
36
|
+
|
|
37
|
+
local msg_id="msg_$(date +%s%N)"
|
|
38
|
+
local timestamp=$(date +%s)
|
|
39
|
+
|
|
40
|
+
# Write to priority queue (non-blocking)
|
|
41
|
+
cat > "$QUEUE_DIR/${priority}_${msg_id}.json" << EOF
|
|
42
|
+
{"id":"$msg_id","to":"$to","content":"$content","type":"$msg_type","priority":$priority,"timestamp":$timestamp}
|
|
43
|
+
EOF
|
|
44
|
+
|
|
45
|
+
echo "$msg_id"
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
# Process queue in background
|
|
49
|
+
process_queue() {
|
|
50
|
+
local processed=0
|
|
51
|
+
|
|
52
|
+
# Process by priority (0=critical first)
|
|
53
|
+
for priority in 0 1 2 3; do
|
|
54
|
+
shopt -s nullglob
|
|
55
|
+
for msg_file in "$QUEUE_DIR"/${priority}_*.json; do
|
|
56
|
+
[ -f "$msg_file" ] || continue
|
|
57
|
+
|
|
58
|
+
# Process message
|
|
59
|
+
local msg=$(cat "$msg_file")
|
|
60
|
+
local to=$(echo "$msg" | jq -r '.to' 2>/dev/null)
|
|
61
|
+
|
|
62
|
+
# Route to agent mailbox
|
|
63
|
+
if [ "$to" != "*" ]; then
|
|
64
|
+
mkdir -p "$SWARM_DIR/mailbox/$to"
|
|
65
|
+
mv "$msg_file" "$SWARM_DIR/mailbox/$to/"
|
|
66
|
+
else
|
|
67
|
+
# Broadcast - copy to all agent mailboxes
|
|
68
|
+
for agent_dir in "$SWARM_DIR/mailbox"/*; do
|
|
69
|
+
[ -d "$agent_dir" ] && cp "$msg_file" "$agent_dir/"
|
|
70
|
+
done
|
|
71
|
+
rm "$msg_file"
|
|
72
|
+
fi
|
|
73
|
+
|
|
74
|
+
processed=$((processed + 1))
|
|
75
|
+
done
|
|
76
|
+
done
|
|
77
|
+
|
|
78
|
+
echo "$processed"
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
# =============================================================================
|
|
82
|
+
# MESSAGE BATCHING
|
|
83
|
+
# =============================================================================
|
|
84
|
+
|
|
85
|
+
# Add to batch (collects messages, flushes when full or timeout)
|
|
86
|
+
batch_add() {
|
|
87
|
+
local agent_id="${1:-}"
|
|
88
|
+
local content="${2:-}"
|
|
89
|
+
local batch_file="$BATCH_DIR/${agent_id}.batch"
|
|
90
|
+
|
|
91
|
+
# Append to batch
|
|
92
|
+
echo "$content" >> "$batch_file"
|
|
93
|
+
|
|
94
|
+
# Check batch size
|
|
95
|
+
local count=$(wc -l < "$batch_file" 2>/dev/null || echo "0")
|
|
96
|
+
|
|
97
|
+
if [ "$count" -ge "$BATCH_SIZE" ]; then
|
|
98
|
+
batch_flush "$agent_id"
|
|
99
|
+
fi
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
# Flush batch (send all at once)
|
|
103
|
+
batch_flush() {
|
|
104
|
+
local agent_id="${1:-}"
|
|
105
|
+
local batch_file="$BATCH_DIR/${agent_id}.batch"
|
|
106
|
+
|
|
107
|
+
if [ -f "$batch_file" ]; then
|
|
108
|
+
local content=$(cat "$batch_file")
|
|
109
|
+
rm "$batch_file"
|
|
110
|
+
|
|
111
|
+
# Send as single batched message
|
|
112
|
+
enqueue "$agent_id" "$content" "$PRIORITY_NORMAL" "batch"
|
|
113
|
+
fi
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
# Flush all pending batches
|
|
117
|
+
batch_flush_all() {
|
|
118
|
+
shopt -s nullglob
|
|
119
|
+
for batch_file in "$BATCH_DIR"/*.batch; do
|
|
120
|
+
[ -f "$batch_file" ] || continue
|
|
121
|
+
local agent_id=$(basename "$batch_file" .batch)
|
|
122
|
+
batch_flush "$agent_id"
|
|
123
|
+
done
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
# =============================================================================
|
|
127
|
+
# CONNECTION POOLING
|
|
128
|
+
# =============================================================================
|
|
129
|
+
|
|
130
|
+
# Initialize connection pool
|
|
131
|
+
pool_init() {
|
|
132
|
+
cat > "$POOL_FILE" << EOF
|
|
133
|
+
{
|
|
134
|
+
"maxConnections": 10,
|
|
135
|
+
"activeConnections": 0,
|
|
136
|
+
"available": [],
|
|
137
|
+
"inUse": [],
|
|
138
|
+
"lastUpdated": "$(date -Iseconds)"
|
|
139
|
+
}
|
|
140
|
+
EOF
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
# Get connection from pool (or create new)
|
|
144
|
+
pool_acquire() {
|
|
145
|
+
local agent_id="${1:-}"
|
|
146
|
+
|
|
147
|
+
if [ ! -f "$POOL_FILE" ]; then
|
|
148
|
+
pool_init
|
|
149
|
+
fi
|
|
150
|
+
|
|
151
|
+
# Check for available connection
|
|
152
|
+
local available=$(jq -r '.available[0] // ""' "$POOL_FILE" 2>/dev/null)
|
|
153
|
+
|
|
154
|
+
if [ -n "$available" ]; then
|
|
155
|
+
# Reuse existing connection
|
|
156
|
+
jq ".available = .available[1:] | .inUse += [\"$available\"]" "$POOL_FILE" > "$POOL_FILE.tmp" && mv "$POOL_FILE.tmp" "$POOL_FILE"
|
|
157
|
+
echo "$available"
|
|
158
|
+
else
|
|
159
|
+
# Create new connection ID
|
|
160
|
+
local conn_id="conn_$(date +%s%N | tail -c 8)"
|
|
161
|
+
jq ".inUse += [\"$conn_id\"] | .activeConnections += 1" "$POOL_FILE" > "$POOL_FILE.tmp" && mv "$POOL_FILE.tmp" "$POOL_FILE"
|
|
162
|
+
echo "$conn_id"
|
|
163
|
+
fi
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
# Release connection back to pool
|
|
167
|
+
pool_release() {
|
|
168
|
+
local conn_id="${1:-}"
|
|
169
|
+
|
|
170
|
+
if [ -f "$POOL_FILE" ]; then
|
|
171
|
+
jq ".inUse = (.inUse | map(select(. != \"$conn_id\"))) | .available += [\"$conn_id\"]" "$POOL_FILE" > "$POOL_FILE.tmp" && mv "$POOL_FILE.tmp" "$POOL_FILE"
|
|
172
|
+
fi
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
# =============================================================================
|
|
176
|
+
# ASYNC PATTERN BROADCAST
|
|
177
|
+
# =============================================================================
|
|
178
|
+
|
|
179
|
+
# Broadcast pattern to swarm (non-blocking)
|
|
180
|
+
broadcast_pattern_async() {
|
|
181
|
+
local strategy="${1:-}"
|
|
182
|
+
local domain="${2:-general}"
|
|
183
|
+
local quality="${3:-0.7}"
|
|
184
|
+
|
|
185
|
+
# Fire and forget
|
|
186
|
+
(
|
|
187
|
+
local broadcast_id="pattern_$(date +%s%N)"
|
|
188
|
+
|
|
189
|
+
# Write pattern broadcast
|
|
190
|
+
mkdir -p "$SWARM_DIR/patterns"
|
|
191
|
+
cat > "$SWARM_DIR/patterns/$broadcast_id.json" << EOF
|
|
192
|
+
{"id":"$broadcast_id","strategy":"$strategy","domain":"$domain","quality":$quality,"timestamp":$(date +%s),"status":"pending"}
|
|
193
|
+
EOF
|
|
194
|
+
|
|
195
|
+
# Notify all agents via queue
|
|
196
|
+
enqueue "*" "{\"type\":\"pattern_broadcast\",\"id\":\"$broadcast_id\"}" "$PRIORITY_HIGH" "event"
|
|
197
|
+
|
|
198
|
+
) &
|
|
199
|
+
|
|
200
|
+
echo "pattern_broadcast_queued"
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
# =============================================================================
|
|
204
|
+
# OPTIMIZED CONSENSUS
|
|
205
|
+
# =============================================================================
|
|
206
|
+
|
|
207
|
+
# Start consensus (non-blocking)
|
|
208
|
+
start_consensus_async() {
|
|
209
|
+
local question="${1:-}"
|
|
210
|
+
local options="${2:-}"
|
|
211
|
+
local timeout="${3:-30}"
|
|
212
|
+
|
|
213
|
+
(
|
|
214
|
+
local consensus_id="consensus_$(date +%s%N)"
|
|
215
|
+
mkdir -p "$SWARM_DIR/consensus"
|
|
216
|
+
|
|
217
|
+
cat > "$SWARM_DIR/consensus/$consensus_id.json" << EOF
|
|
218
|
+
{"id":"$consensus_id","question":"$question","options":"$options","votes":{},"timeout":$timeout,"created":$(date +%s),"status":"open"}
|
|
219
|
+
EOF
|
|
220
|
+
|
|
221
|
+
# Notify agents
|
|
222
|
+
enqueue "*" "{\"type\":\"consensus_request\",\"id\":\"$consensus_id\"}" "$PRIORITY_HIGH" "event"
|
|
223
|
+
|
|
224
|
+
# Auto-resolve after timeout (background)
|
|
225
|
+
(
|
|
226
|
+
sleep "$timeout"
|
|
227
|
+
if [ -f "$SWARM_DIR/consensus/$consensus_id.json" ]; then
|
|
228
|
+
jq '.status = "resolved"' "$SWARM_DIR/consensus/$consensus_id.json" > "$SWARM_DIR/consensus/$consensus_id.json.tmp" && mv "$SWARM_DIR/consensus/$consensus_id.json.tmp" "$SWARM_DIR/consensus/$consensus_id.json"
|
|
229
|
+
fi
|
|
230
|
+
) &
|
|
231
|
+
|
|
232
|
+
echo "$consensus_id"
|
|
233
|
+
) &
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
# Vote on consensus (non-blocking)
|
|
237
|
+
vote_async() {
|
|
238
|
+
local consensus_id="${1:-}"
|
|
239
|
+
local vote="${2:-}"
|
|
240
|
+
local agent_id="${AGENTIC_FLOW_AGENT_ID:-anonymous}"
|
|
241
|
+
|
|
242
|
+
(
|
|
243
|
+
local file="$SWARM_DIR/consensus/$consensus_id.json"
|
|
244
|
+
if [ -f "$file" ]; then
|
|
245
|
+
jq ".votes[\"$agent_id\"] = \"$vote\"" "$file" > "$file.tmp" && mv "$file.tmp" "$file"
|
|
246
|
+
fi
|
|
247
|
+
) &
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
# =============================================================================
|
|
251
|
+
# PERFORMANCE METRICS
|
|
252
|
+
# =============================================================================
|
|
253
|
+
|
|
254
|
+
get_comms_stats() {
|
|
255
|
+
local queued=$(ls "$QUEUE_DIR"/*.json 2>/dev/null | wc -l | tr -d '[:space:]')
|
|
256
|
+
queued=${queued:-0}
|
|
257
|
+
local batched=$(ls "$BATCH_DIR"/*.batch 2>/dev/null | wc -l | tr -d '[:space:]')
|
|
258
|
+
batched=${batched:-0}
|
|
259
|
+
local patterns=$(ls "$SWARM_DIR/patterns"/*.json 2>/dev/null | wc -l | tr -d '[:space:]')
|
|
260
|
+
patterns=${patterns:-0}
|
|
261
|
+
local consensus=$(ls "$SWARM_DIR/consensus"/*.json 2>/dev/null | wc -l | tr -d '[:space:]')
|
|
262
|
+
consensus=${consensus:-0}
|
|
263
|
+
|
|
264
|
+
local pool_active=0
|
|
265
|
+
if [ -f "$POOL_FILE" ]; then
|
|
266
|
+
pool_active=$(jq '.activeConnections // 0' "$POOL_FILE" 2>/dev/null | tr -d '[:space:]')
|
|
267
|
+
pool_active=${pool_active:-0}
|
|
268
|
+
fi
|
|
269
|
+
|
|
270
|
+
echo "{\"queue\":$queued,\"batch\":$batched,\"patterns\":$patterns,\"consensus\":$consensus,\"pool\":$pool_active}"
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
# =============================================================================
|
|
274
|
+
# MAIN DISPATCHER
|
|
275
|
+
# =============================================================================
|
|
276
|
+
|
|
277
|
+
case "${1:-help}" in
|
|
278
|
+
# Queue operations
|
|
279
|
+
"enqueue"|"send")
|
|
280
|
+
enqueue "${2:-*}" "${3:-}" "${4:-2}" "${5:-context}"
|
|
281
|
+
;;
|
|
282
|
+
"process")
|
|
283
|
+
process_queue
|
|
284
|
+
;;
|
|
285
|
+
|
|
286
|
+
# Batch operations
|
|
287
|
+
"batch")
|
|
288
|
+
batch_add "${2:-}" "${3:-}"
|
|
289
|
+
;;
|
|
290
|
+
"flush")
|
|
291
|
+
batch_flush_all
|
|
292
|
+
;;
|
|
293
|
+
|
|
294
|
+
# Pool operations
|
|
295
|
+
"acquire")
|
|
296
|
+
pool_acquire "${2:-}"
|
|
297
|
+
;;
|
|
298
|
+
"release")
|
|
299
|
+
pool_release "${2:-}"
|
|
300
|
+
;;
|
|
301
|
+
|
|
302
|
+
# Async operations
|
|
303
|
+
"broadcast-pattern")
|
|
304
|
+
broadcast_pattern_async "${2:-}" "${3:-general}" "${4:-0.7}"
|
|
305
|
+
;;
|
|
306
|
+
"consensus")
|
|
307
|
+
start_consensus_async "${2:-}" "${3:-}" "${4:-30}"
|
|
308
|
+
;;
|
|
309
|
+
"vote")
|
|
310
|
+
vote_async "${2:-}" "${3:-}"
|
|
311
|
+
;;
|
|
312
|
+
|
|
313
|
+
# Stats
|
|
314
|
+
"stats")
|
|
315
|
+
get_comms_stats
|
|
316
|
+
;;
|
|
317
|
+
|
|
318
|
+
"help"|*)
|
|
319
|
+
cat << 'EOF'
|
|
320
|
+
Claude Flow V3 - Optimized Swarm Communications
|
|
321
|
+
|
|
322
|
+
Non-blocking, batched, priority-based inter-agent messaging.
|
|
323
|
+
|
|
324
|
+
Usage: swarm-comms.sh <command> [args]
|
|
325
|
+
|
|
326
|
+
Queue (Non-blocking):
|
|
327
|
+
enqueue <to> <content> [priority] [type] Add to queue (instant return)
|
|
328
|
+
process Process pending queue
|
|
329
|
+
|
|
330
|
+
Batching:
|
|
331
|
+
batch <agent> <content> Add to batch
|
|
332
|
+
flush Flush all batches
|
|
333
|
+
|
|
334
|
+
Connection Pool:
|
|
335
|
+
acquire [agent] Get connection from pool
|
|
336
|
+
release <conn_id> Return connection to pool
|
|
337
|
+
|
|
338
|
+
Async Operations:
|
|
339
|
+
broadcast-pattern <strategy> [domain] [quality] Async pattern broadcast
|
|
340
|
+
consensus <question> <options> [timeout] Start async consensus
|
|
341
|
+
vote <consensus_id> <vote> Vote (non-blocking)
|
|
342
|
+
|
|
343
|
+
Stats:
|
|
344
|
+
stats Get communication stats
|
|
345
|
+
|
|
346
|
+
Priority Levels:
|
|
347
|
+
0 = Critical (processed first)
|
|
348
|
+
1 = High
|
|
349
|
+
2 = Normal (default)
|
|
350
|
+
3 = Low
|
|
351
|
+
EOF
|
|
352
|
+
;;
|
|
353
|
+
esac
|