claude-flow-novice 2.0.3 → 2.0.4
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/dist/src/cli/commands/guidance.js +487 -668
- package/dist/src/cli/commands/index-validate.js +18 -29
- package/dist/src/cli/commands/mcp-troubleshoot.js +230 -282
- package/dist/src/cli/commands/neural-goal-init.js +92 -125
- package/dist/src/cli/commands/swarm-exec.js +317 -393
- package/dist/src/cli/commands/swarm.js +1 -1
- package/dist/src/cli/commands/validate-framework.js +983 -1100
- package/dist/src/cli/commands/validate.js +144 -223
- package/dist/src/cli/simple-commands/__tests__/agent.test.js +265 -277
- package/dist/src/cli/simple-commands/__tests__/memory.test.js +6 -7
- package/dist/src/cli/simple-commands/__tests__/swarm.test.js +373 -356
- package/dist/src/cli/simple-commands/__tests__/task.test.js +6 -7
- package/dist/src/cli/simple-commands/agent.js +157 -193
- package/dist/src/cli/simple-commands/analysis.js +336 -446
- package/dist/src/cli/simple-commands/automation-executor.js +1095 -1339
- package/dist/src/cli/simple-commands/automation.js +481 -469
- package/dist/src/cli/simple-commands/batch-manager.js +261 -313
- package/dist/src/cli/simple-commands/claude-telemetry.js +241 -267
- package/dist/src/cli/simple-commands/claude-track.js +68 -90
- package/dist/src/cli/simple-commands/concurrent-display.js +266 -320
- package/dist/src/cli/simple-commands/config.js +245 -290
- package/dist/src/cli/simple-commands/coordination.js +182 -234
- package/dist/src/cli/simple-commands/enhanced-ui-views.js +812 -615
- package/dist/src/cli/simple-commands/enhanced-webui-complete.js +922 -981
- package/dist/src/cli/simple-commands/fix-hook-variables.js +274 -294
- package/dist/src/cli/simple-commands/github/gh-coordinator.js +378 -457
- package/dist/src/cli/simple-commands/github/github-api.js +535 -574
- package/dist/src/cli/simple-commands/github/init.js +276 -303
- package/dist/src/cli/simple-commands/github.js +222 -247
- package/dist/src/cli/simple-commands/goal.js +51 -63
- package/dist/src/cli/simple-commands/hive-mind/auto-save-middleware.js +208 -278
- package/dist/src/cli/simple-commands/hive-mind/communication.js +601 -696
- package/dist/src/cli/simple-commands/hive-mind/core.js +907 -979
- package/dist/src/cli/simple-commands/hive-mind/db-optimizer.js +406 -655
- package/dist/src/cli/simple-commands/hive-mind/mcp-wrapper.js +1125 -1245
- package/dist/src/cli/simple-commands/hive-mind/memory.js +854 -1090
- package/dist/src/cli/simple-commands/hive-mind/performance-optimizer.js +459 -574
- package/dist/src/cli/simple-commands/hive-mind/performance-test.js +263 -347
- package/dist/src/cli/simple-commands/hive-mind/queen.js +727 -768
- package/dist/src/cli/simple-commands/hive-mind/session-manager.js +745 -1049
- package/dist/src/cli/simple-commands/hive-mind-optimize.js +227 -283
- package/dist/src/cli/simple-commands/hive-mind-wizard.js +174 -217
- package/dist/src/cli/simple-commands/hive-mind.js +1842 -2283
- package/dist/src/cli/simple-commands/hive.js +90 -79
- package/dist/src/cli/simple-commands/hook-safety.js +431 -521
- package/dist/src/cli/simple-commands/hooks/session-start-soul.js +203 -254
- package/dist/src/cli/simple-commands/hooks.js +1064 -1204
- package/dist/src/cli/simple-commands/init/agent-copier.js +294 -319
- package/dist/src/cli/simple-commands/init/batch-init.js +496 -562
- package/dist/src/cli/simple-commands/init/claude-commands/claude-flow-commands.js +13 -19
- package/dist/src/cli/simple-commands/init/claude-commands/optimized-claude-flow-commands.js +13 -19
- package/dist/src/cli/simple-commands/init/claude-commands/optimized-slash-commands.js +61 -88
- package/dist/src/cli/simple-commands/init/claude-commands/optimized-sparc-commands.js +125 -150
- package/dist/src/cli/simple-commands/init/claude-commands/slash-commands.js +42 -49
- package/dist/src/cli/simple-commands/init/claude-commands/sparc-commands.js +43 -61
- package/dist/src/cli/simple-commands/init/copy-revised-templates.js +141 -147
- package/dist/src/cli/simple-commands/init/executable-wrapper.js +31 -44
- package/dist/src/cli/simple-commands/init/gitignore-updater.js +64 -90
- package/dist/src/cli/simple-commands/init/help.js +104 -107
- package/dist/src/cli/simple-commands/init/hive-mind-init.js +509 -528
- package/dist/src/cli/simple-commands/init/index.js +1510 -1759
- package/dist/src/cli/simple-commands/init/performance-monitor.js +234 -317
- package/dist/src/cli/simple-commands/init/rollback/backup-manager.js +441 -504
- package/dist/src/cli/simple-commands/init/rollback/index.js +289 -364
- package/dist/src/cli/simple-commands/init/rollback/recovery-manager.js +652 -728
- package/dist/src/cli/simple-commands/init/rollback/rollback-executor.js +416 -481
- package/dist/src/cli/simple-commands/init/rollback/state-tracker.js +369 -448
- package/dist/src/cli/simple-commands/init/sparc/roo-readme.js +1 -2
- package/dist/src/cli/simple-commands/init/sparc/roomodes-config.js +122 -99
- package/dist/src/cli/simple-commands/init/sparc/workflows.js +32 -37
- package/dist/src/cli/simple-commands/init/sparc-structure.js +55 -62
- package/dist/src/cli/simple-commands/init/template-copier.js +421 -533
- package/dist/src/cli/simple-commands/init/templates/coordination-md.js +3 -6
- package/dist/src/cli/simple-commands/init/templates/enhanced-templates.js +344 -318
- package/dist/src/cli/simple-commands/init/templates/github-safe-enhanced.js +173 -218
- package/dist/src/cli/simple-commands/init/templates/github-safe.js +65 -75
- package/dist/src/cli/simple-commands/init/templates/memory-bank-md.js +3 -6
- package/dist/src/cli/simple-commands/init/templates/readme-files.js +2 -4
- package/dist/src/cli/simple-commands/init/templates/safe-hook-patterns.js +187 -230
- package/dist/src/cli/simple-commands/init/templates/sparc-modes.js +53 -80
- package/dist/src/cli/simple-commands/init/templates/verification-claude-md.js +101 -85
- package/dist/src/cli/simple-commands/init/validation/config-validator.js +283 -330
- package/dist/src/cli/simple-commands/init/validation/health-checker.js +495 -561
- package/dist/src/cli/simple-commands/init/validation/index.js +302 -358
- package/dist/src/cli/simple-commands/init/validation/mode-validator.js +308 -359
- package/dist/src/cli/simple-commands/init/validation/post-init-validator.js +389 -366
- package/dist/src/cli/simple-commands/init/validation/pre-init-validator.js +270 -268
- package/dist/src/cli/simple-commands/init/validation/test-runner.js +427 -447
- package/dist/src/cli/simple-commands/init.js +1 -2
- package/dist/src/cli/simple-commands/mcp-health.js +131 -158
- package/dist/src/cli/simple-commands/mcp-integration-layer.js +533 -634
- package/dist/src/cli/simple-commands/mcp.js +345 -400
- package/dist/src/cli/simple-commands/memory-consolidation.js +426 -537
- package/dist/src/cli/simple-commands/memory.js +247 -311
- package/dist/src/cli/simple-commands/migrate-hooks.js +39 -46
- package/dist/src/cli/simple-commands/monitor.js +294 -363
- package/dist/src/cli/simple-commands/neural.js +51 -65
- package/dist/src/cli/simple-commands/pair-autofix-only.js +538 -662
- package/dist/src/cli/simple-commands/pair-basic.js +528 -656
- package/dist/src/cli/simple-commands/pair-old.js +430 -543
- package/dist/src/cli/simple-commands/pair-working.js +615 -751
- package/dist/src/cli/simple-commands/pair.js +615 -751
- package/dist/src/cli/simple-commands/performance-hooks.js +83 -111
- package/dist/src/cli/simple-commands/performance-metrics.js +348 -433
- package/dist/src/cli/simple-commands/process-ui-enhanced.js +708 -787
- package/dist/src/cli/simple-commands/process-ui.js +230 -254
- package/dist/src/cli/simple-commands/realtime-update-system.js +525 -611
- package/dist/src/cli/simple-commands/sparc/architecture.js +1704 -1530
- package/dist/src/cli/simple-commands/sparc/commands.js +438 -516
- package/dist/src/cli/simple-commands/sparc/completion.js +1224 -1481
- package/dist/src/cli/simple-commands/sparc/coordinator.js +913 -978
- package/dist/src/cli/simple-commands/sparc/index.js +241 -298
- package/dist/src/cli/simple-commands/sparc/phase-base.js +314 -390
- package/dist/src/cli/simple-commands/sparc/pseudocode.js +965 -869
- package/dist/src/cli/simple-commands/sparc/refinement.js +980 -1273
- package/dist/src/cli/simple-commands/sparc/specification.js +559 -645
- package/dist/src/cli/simple-commands/sparc-modes/architect.js +1 -1
- package/dist/src/cli/simple-commands/sparc-modes/ask.js +1 -1
- package/dist/src/cli/simple-commands/sparc-modes/code.js +1 -1
- package/dist/src/cli/simple-commands/sparc-modes/debug.js +1 -1
- package/dist/src/cli/simple-commands/sparc-modes/devops.js +1 -1
- package/dist/src/cli/simple-commands/sparc-modes/docs-writer.js +1 -1
- package/dist/src/cli/simple-commands/sparc-modes/generic.js +1 -1
- package/dist/src/cli/simple-commands/sparc-modes/index.js +47 -55
- package/dist/src/cli/simple-commands/sparc-modes/integration.js +1 -1
- package/dist/src/cli/simple-commands/sparc-modes/mcp.js +1 -1
- package/dist/src/cli/simple-commands/sparc-modes/monitoring.js +1 -1
- package/dist/src/cli/simple-commands/sparc-modes/optimization.js +1 -1
- package/dist/src/cli/simple-commands/sparc-modes/security-review.js +1 -1
- package/dist/src/cli/simple-commands/sparc-modes/sparc-orchestrator.js +1 -1
- package/dist/src/cli/simple-commands/sparc-modes/spec-pseudocode.js +1 -1
- package/dist/src/cli/simple-commands/sparc-modes/supabase-admin.js +1 -1
- package/dist/src/cli/simple-commands/sparc-modes/swarm.js +101 -87
- package/dist/src/cli/simple-commands/sparc-modes/tdd.js +1 -1
- package/dist/src/cli/simple-commands/sparc-modes/tutorial.js +1 -1
- package/dist/src/cli/simple-commands/sparc.js +465 -493
- package/dist/src/cli/simple-commands/start-ui.js +108 -132
- package/dist/src/cli/simple-commands/start-wrapper.js +240 -268
- package/dist/src/cli/simple-commands/start.js +1 -1
- package/dist/src/cli/simple-commands/status.js +254 -275
- package/dist/src/cli/simple-commands/stream-chain-clean.js +128 -171
- package/dist/src/cli/simple-commands/stream-chain-fixed.js +61 -82
- package/dist/src/cli/simple-commands/stream-chain-real.js +267 -331
- package/dist/src/cli/simple-commands/stream-chain-working.js +211 -263
- package/dist/src/cli/simple-commands/stream-chain.js +260 -318
- package/dist/src/cli/simple-commands/stream-processor.js +290 -315
- package/dist/src/cli/simple-commands/swarm-executor.js +189 -222
- package/dist/src/cli/simple-commands/swarm-metrics-integration.js +208 -300
- package/dist/src/cli/simple-commands/swarm-ui.js +623 -703
- package/dist/src/cli/simple-commands/swarm-webui-integration.js +258 -286
- package/dist/src/cli/simple-commands/swarm.js +887 -1082
- package/dist/src/cli/simple-commands/task.js +161 -206
- package/dist/src/cli/simple-commands/timestamp-fix.js +59 -89
- package/dist/src/cli/simple-commands/token-tracker.js +258 -316
- package/dist/src/cli/simple-commands/tool-execution-framework.js +433 -519
- package/dist/src/cli/simple-commands/train-and-stream.js +275 -331
- package/dist/src/cli/simple-commands/training-pipeline.js +619 -725
- package/dist/src/cli/simple-commands/training.js +170 -227
- package/dist/src/cli/simple-commands/verification-hooks.js +261 -284
- package/dist/src/cli/simple-commands/verification-integration.js +389 -417
- package/dist/src/cli/simple-commands/verification-training-integration.js +486 -606
- package/dist/src/cli/simple-commands/verification.js +493 -513
- package/dist/src/cli/simple-commands/web-server.js +766 -836
- package/dist/src/cli/simple-commands/webui-validator.js +106 -124
- package/dist/src/coordination/event-bus/demo-wasm-integration.js +212 -251
- package/dist/src/coordination/event-bus/qe-event-bus.js +608 -748
- package/dist/src/coordination/event-bus/qe-event-bus.test.js +379 -454
- package/dist/src/coordination/iteration-tracker.js +363 -454
- package/dist/src/enterprise/analytics-manager.js +1135 -0
- package/dist/src/enterprise/audit-manager.js +1115 -0
- package/dist/src/enterprise/cloud-manager.js +891 -0
- package/dist/src/enterprise/deployment-manager.js +966 -0
- package/dist/src/enterprise/index.js +6 -0
- package/dist/src/enterprise/project-manager.js +584 -0
- package/dist/src/enterprise/security-manager.js +991 -0
- package/dist/src/index.js +1 -1
- package/dist/src/mcp/DEPRECATED.js +46 -60
- package/dist/src/mcp/fixes/mcp-error-fixes.js +115 -134
- package/dist/src/mcp/implementations/agent-tracker.js +114 -128
- package/dist/src/mcp/implementations/daa-tools.js +292 -350
- package/dist/src/mcp/implementations/workflow-tools.js +329 -361
- package/dist/src/mcp/mcp-config-manager.js +1183 -1331
- package/dist/src/mcp/mcp-server-novice-simplified.js +11 -17
- package/dist/src/mcp/mcp-server-novice.js +11 -17
- package/dist/src/mcp/mcp-server-sdk.js +11 -17
- package/dist/src/mcp/mcp-server.js +1620 -1484
- package/dist/src/mcp/ruv-swarm-wrapper.js +209 -239
- package/dist/src/memory/advanced-serializer.js +609 -589
- package/dist/src/memory/enhanced-examples.js +220 -305
- package/dist/src/memory/enhanced-memory.js +295 -336
- package/dist/src/memory/enhanced-session-serializer.js +408 -492
- package/dist/src/memory/fallback-memory-system.js +900 -1021
- package/dist/src/memory/fallback-store.js +93 -131
- package/dist/src/memory/high-performance-serialization.js +592 -730
- package/dist/src/memory/in-memory-store.js +161 -213
- package/dist/src/memory/index.js +123 -157
- package/dist/src/memory/lock-free-structures.js +578 -764
- package/dist/src/memory/memory-mapped-persistence.js +585 -766
- package/dist/src/memory/memory-pressure-manager.js +569 -707
- package/dist/src/memory/migration.js +358 -445
- package/dist/src/memory/shared-memory.js +641 -768
- package/dist/src/memory/sqlite-store.js +245 -325
- package/dist/src/memory/sqlite-wrapper.js +122 -151
- package/dist/src/memory/swarm-memory.js +470 -603
- package/dist/src/memory/test-example.js +126 -134
- package/dist/src/memory/ultra-fast-memory-store.js +622 -821
- package/dist/src/memory/unified-memory-manager.js +356 -437
- package/dist/src/migration/index.js +92 -0
- package/dist/src/migration/logger.js +121 -0
- package/dist/src/migration/migration-analyzer.js +268 -0
- package/dist/src/migration/migration-runner.js +522 -0
- package/dist/src/migration/migration-validator.js +285 -0
- package/dist/src/migration/progress-reporter.js +150 -0
- package/dist/src/migration/rollback-manager.js +321 -0
- package/dist/src/migration/tests/migration-system.test.js +7 -0
- package/dist/src/migration/types.js +3 -0
- package/dist/src/swarm/CodeRefactoringSwarm.js +777 -952
- package/dist/src/swarm/__tests__/integration.test.js +227 -0
- package/dist/src/swarm/__tests__/prompt-copier.test.js +344 -0
- package/dist/src/swarm/advanced-orchestrator.js +1095 -0
- package/dist/src/swarm/claude-code-interface.js +961 -0
- package/dist/src/swarm/claude-flow-executor.js +229 -0
- package/dist/src/swarm/consensus-coordinator.js +475 -0
- package/dist/src/swarm/coordinator.js +2993 -0
- package/dist/src/swarm/direct-executor.js +1180 -0
- package/dist/src/swarm/error-recovery/advanced-error-detection.js +691 -0
- package/dist/src/swarm/error-recovery/automated-recovery-workflows.js +998 -0
- package/dist/src/swarm/error-recovery/error-recovery-coordinator.js +1197 -0
- package/dist/src/swarm/error-recovery/recovery-monitoring.js +772 -0
- package/dist/src/swarm/error-recovery/resilience-architecture.js +714 -0
- package/dist/src/swarm/error-recovery/self-healing-mechanisms.js +1319 -0
- package/dist/src/swarm/error-recovery/test-error-recovery-effectiveness.js +808 -0
- package/dist/src/swarm/executor-v2.js +322 -0
- package/dist/src/swarm/executor.js +815 -0
- package/dist/src/swarm/hive-mind-integration.js +703 -0
- package/dist/src/swarm/index.js +41 -0
- package/dist/src/swarm/json-output-aggregator.js +267 -0
- package/dist/src/swarm/large-scale-coordinator.js +542 -0
- package/dist/src/swarm/mcp-integration-wrapper.js +628 -0
- package/dist/src/swarm/memory.js +1117 -0
- package/dist/src/swarm/optimizations/__tests__/optimization.test.js +348 -0
- package/dist/src/swarm/optimizations/async-file-manager.js +285 -0
- package/dist/src/swarm/optimizations/circular-buffer.js +162 -0
- package/dist/src/swarm/optimizations/connection-pool.js +244 -0
- package/dist/src/swarm/optimizations/index.js +28 -0
- package/dist/src/swarm/optimizations/optimized-executor.js +320 -0
- package/dist/src/swarm/optimizations/ttl-map.js +234 -0
- package/dist/src/swarm/prompt-cli.js +200 -0
- package/dist/src/swarm/prompt-copier-enhanced.js +202 -0
- package/dist/src/swarm/prompt-copier.js +381 -0
- package/dist/src/swarm/prompt-manager.js +295 -0
- package/dist/src/swarm/prompt-utils.js +310 -0
- package/dist/src/swarm/result-aggregator.js +718 -0
- package/dist/src/swarm/sparc-executor.js +1568 -0
- package/dist/src/swarm/strategies/auto.js +758 -0
- package/dist/src/swarm/strategies/base.js +128 -0
- package/dist/src/swarm/strategies/research.js +914 -0
- package/dist/src/swarm/strategies/strategy-metrics-patch.js +2 -0
- package/dist/src/swarm/types.js +52 -0
- package/dist/src/swarm/workers/copy-worker.js +56 -0
- package/dist/src/utils/__tests__/github-cli-safety-wrapper.test.js +332 -400
- package/dist/src/utils/github-cli-safe.js +56 -64
- package/dist/src/utils/github-cli-safety-wrapper.js +451 -546
- package/dist/src/utils/npx-isolated-cache.js +104 -119
- package/dist/src/utils/preference-manager.js +622 -652
- package/dist/src/utils/timezone-utils.js +86 -105
- package/dist/src/validators/epic-config-schema.js +214 -0
- package/dist/src/validators/index.js +10 -0
- package/dist/src/validators/swarm-init-validator.js +259 -0
- package/dist/src/validators/todowrite-batching-validator.js +215 -0
- package/dist/src/validators/todowrite-integration.js +187 -0
- package/package.json +2 -2
|
@@ -1,150 +1,121 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Swarm command wrapper for simple CLI
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import
|
|
8
|
-
import { open } from 'fs/promises';
|
|
9
|
-
import process from 'process';
|
|
10
|
-
import path from 'path';
|
|
11
|
-
|
|
3
|
+
*/ import { mkdirAsync, writeTextFile, exit } from "../node-compat.js";
|
|
4
|
+
import { spawn } from "child_process";
|
|
5
|
+
import { existsSync, chmodSync, statSync } from "fs";
|
|
6
|
+
import { open } from "node:fs/promises";
|
|
7
|
+
import process from "process";
|
|
12
8
|
/**
|
|
13
9
|
* Detects if the environment is headless (non-interactive)
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
existsSync('/.dockerenv') ||
|
|
34
|
-
(existsSync('/proc/1/cgroup') &&
|
|
35
|
-
require('fs').readFileSync('/proc/1/cgroup', 'utf8').includes('docker'));
|
|
36
|
-
|
|
37
|
-
// Check TTY availability
|
|
38
|
-
const hasTTY = process.stdin.isTTY && process.stdout.isTTY;
|
|
39
|
-
|
|
40
|
-
return isCI || isDocker || !hasTTY;
|
|
10
|
+
*/ function isHeadlessEnvironment() {
|
|
11
|
+
// Check for common CI environment variables
|
|
12
|
+
const ciEnvironments = [
|
|
13
|
+
'CI',
|
|
14
|
+
'GITHUB_ACTIONS',
|
|
15
|
+
'GITLAB_CI',
|
|
16
|
+
'JENKINS_URL',
|
|
17
|
+
'CIRCLECI',
|
|
18
|
+
'TRAVIS',
|
|
19
|
+
'BUILDKITE',
|
|
20
|
+
'DRONE',
|
|
21
|
+
'DOCKER_CONTAINER'
|
|
22
|
+
];
|
|
23
|
+
const isCI = ciEnvironments.some((env)=>process.env[env]);
|
|
24
|
+
// Check if running in Docker
|
|
25
|
+
const isDocker = existsSync('/.dockerenv') || existsSync('/proc/1/cgroup') && require('fs').readFileSync('/proc/1/cgroup', 'utf8').includes('docker');
|
|
26
|
+
// Check TTY availability
|
|
27
|
+
const hasTTY = process.stdin.isTTY && process.stdout.isTTY;
|
|
28
|
+
return isCI || isDocker || !hasTTY;
|
|
41
29
|
}
|
|
42
|
-
|
|
43
30
|
/**
|
|
44
31
|
* Basic swarm implementation for fallback scenarios
|
|
45
|
-
*/
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
const isHeadless = isHeadlessEnvironment();
|
|
56
|
-
|
|
57
|
-
// Configure for headless mode
|
|
58
|
-
if (isHeadless) {
|
|
59
|
-
console.log('🤖 Headless environment detected - running in non-interactive mode');
|
|
60
|
-
flags = {
|
|
61
|
-
...flags,
|
|
62
|
-
'non-interactive': true,
|
|
63
|
-
'output-format': flags['output-format'] || 'stream-json', // Use stream-json for Claude compatibility
|
|
64
|
-
'no-auto-permissions': false,
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// Set up graceful shutdown handlers
|
|
69
|
-
const cleanup = () => {
|
|
70
|
-
console.log('\n🛑 Shutting down swarm gracefully...');
|
|
71
|
-
process.exit(0);
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
process.on('SIGTERM', cleanup);
|
|
75
|
-
process.on('SIGINT', cleanup);
|
|
76
|
-
|
|
77
|
-
try {
|
|
78
|
-
// Try to use the swarm executor
|
|
79
|
-
const { executeSwarm } = await import('./swarm-executor.js');
|
|
80
|
-
|
|
81
|
-
console.log(`🐝 Starting basic swarm execution...`);
|
|
82
|
-
console.log(`📋 Objective: ${objective}`);
|
|
83
|
-
console.log(`🎯 Strategy: ${flags.strategy || 'auto'}`);
|
|
84
|
-
console.log(`🏗️ Mode: ${flags.mode || 'centralized'}`);
|
|
85
|
-
console.log(`🤖 Max Agents: ${flags['max-agents'] || 5}`);
|
|
86
|
-
|
|
32
|
+
*/ async function basicSwarmNew(args, flags) {
|
|
33
|
+
const objective = (args || []).join(' ').trim();
|
|
34
|
+
if (!objective) {
|
|
35
|
+
console.error('❌ Usage: swarm <objective>');
|
|
36
|
+
showSwarmHelp();
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
const isHeadless = isHeadlessEnvironment();
|
|
40
|
+
// Configure for headless mode
|
|
87
41
|
if (isHeadless) {
|
|
88
|
-
|
|
89
|
-
|
|
42
|
+
console.log('🤖 Headless environment detected - running in non-interactive mode');
|
|
43
|
+
flags = {
|
|
44
|
+
...flags,
|
|
45
|
+
'non-interactive': true,
|
|
46
|
+
'output-format': flags['output-format'] || 'stream-json',
|
|
47
|
+
'no-auto-permissions': false
|
|
48
|
+
};
|
|
90
49
|
}
|
|
91
|
-
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
await fs.writeFile(flags['output-file'], JSON.stringify(output, null, 2));
|
|
110
|
-
console.log(`✅ Output saved to: ${flags['output-file']}`);
|
|
111
|
-
} else {
|
|
112
|
-
console.log(JSON.stringify(output, null, 2));
|
|
113
|
-
}
|
|
114
|
-
} else {
|
|
115
|
-
// Text mode output
|
|
116
|
-
if (result.success) {
|
|
117
|
-
console.log(`\n✅ Swarm execution completed successfully!`);
|
|
118
|
-
if (result.summary) {
|
|
119
|
-
console.log(` Duration: ${result.summary.duration}`);
|
|
120
|
-
console.log(` Agents: ${result.summary.totalAgents}`);
|
|
121
|
-
console.log(` Tasks: ${result.summary.totalTasks}`);
|
|
50
|
+
// Set up graceful shutdown handlers
|
|
51
|
+
const cleanup = ()=>{
|
|
52
|
+
console.log('\n🛑 Shutting down swarm gracefully...');
|
|
53
|
+
process.exit(0);
|
|
54
|
+
};
|
|
55
|
+
process.on('SIGTERM', cleanup);
|
|
56
|
+
process.on('SIGINT', cleanup);
|
|
57
|
+
try {
|
|
58
|
+
// Try to use the swarm executor
|
|
59
|
+
const { executeSwarm } = await import("./swarm-executor.js");
|
|
60
|
+
console.log(`🐝 Starting basic swarm execution...`);
|
|
61
|
+
console.log(`📋 Objective: ${objective}`);
|
|
62
|
+
console.log(`🎯 Strategy: ${flags.strategy || 'auto'}`);
|
|
63
|
+
console.log(`🏗️ Mode: ${flags.mode || 'centralized'}`);
|
|
64
|
+
console.log(`🤖 Max Agents: ${flags['max-agents'] || 5}`);
|
|
65
|
+
if (isHeadless) {
|
|
66
|
+
console.log(`🖥️ Headless Mode: Enabled`);
|
|
67
|
+
console.log(`📄 Output Format: ${flags['output-format']}`);
|
|
122
68
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
69
|
+
const result = await executeSwarm(objective, flags);
|
|
70
|
+
// Handle output based on format
|
|
71
|
+
if (flags['output-format'] === 'json') {
|
|
72
|
+
// In JSON mode, output clean JSON
|
|
73
|
+
const output = {
|
|
74
|
+
success: result.success,
|
|
75
|
+
swarmId: result.summary?.swarmId,
|
|
76
|
+
objective: objective,
|
|
77
|
+
duration: result.summary?.duration,
|
|
78
|
+
agents: result.summary?.totalAgents,
|
|
79
|
+
tasks: result.summary?.totalTasks,
|
|
80
|
+
timestamp: new Date().toISOString()
|
|
81
|
+
};
|
|
82
|
+
if (flags['output-file']) {
|
|
83
|
+
const fs = await import("node:fs/promises");
|
|
84
|
+
await fs.writeFile(flags['output-file'], JSON.stringify(output, null, 2));
|
|
85
|
+
console.log(`✅ Output saved to: ${flags['output-file']}`);
|
|
86
|
+
} else {
|
|
87
|
+
console.log(JSON.stringify(output, null, 2));
|
|
88
|
+
}
|
|
89
|
+
} else {
|
|
90
|
+
// Text mode output
|
|
91
|
+
if (result.success) {
|
|
92
|
+
console.log(`\n✅ Swarm execution completed successfully!`);
|
|
93
|
+
if (result.summary) {
|
|
94
|
+
console.log(` Duration: ${result.summary.duration}`);
|
|
95
|
+
console.log(` Agents: ${result.summary.totalAgents}`);
|
|
96
|
+
console.log(` Tasks: ${result.summary.totalTasks}`);
|
|
97
|
+
}
|
|
98
|
+
} else {
|
|
99
|
+
console.error(`\n❌ Swarm execution failed: ${result.error}`);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return result;
|
|
103
|
+
} catch (error) {
|
|
104
|
+
console.error(`❌ Basic swarm execution error: ${error.message}`);
|
|
105
|
+
// In headless mode, ensure we output JSON error
|
|
106
|
+
if (flags['output-format'] === 'json') {
|
|
107
|
+
const errorOutput = {
|
|
108
|
+
success: false,
|
|
109
|
+
error: error.message,
|
|
110
|
+
timestamp: new Date().toISOString()
|
|
111
|
+
};
|
|
112
|
+
console.log(JSON.stringify(errorOutput, null, 2));
|
|
113
|
+
}
|
|
114
|
+
throw error;
|
|
140
115
|
}
|
|
141
|
-
|
|
142
|
-
throw error;
|
|
143
|
-
}
|
|
144
116
|
}
|
|
145
|
-
|
|
146
117
|
function showSwarmHelp() {
|
|
147
|
-
|
|
118
|
+
console.log(`
|
|
148
119
|
🐝 Claude Flow Advanced Swarm System
|
|
149
120
|
|
|
150
121
|
USAGE:
|
|
@@ -250,136 +221,114 @@ For complete documentation and examples:
|
|
|
250
221
|
https://github.com/ruvnet/claude-code-flow/docs/swarm.md
|
|
251
222
|
`);
|
|
252
223
|
}
|
|
253
|
-
|
|
254
224
|
export async function swarmCommand(args, flags) {
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
// Handle health check first
|
|
268
|
-
if (flags && flags['health-check']) {
|
|
269
|
-
try {
|
|
270
|
-
// Quick health check for Docker/K8s
|
|
271
|
-
console.log(
|
|
272
|
-
JSON.stringify({
|
|
273
|
-
status: 'healthy',
|
|
274
|
-
service: 'claude-flow-swarm',
|
|
275
|
-
version: process.env.npm_package_version || '2.0.0',
|
|
276
|
-
timestamp: new Date().toISOString(),
|
|
277
|
-
}),
|
|
278
|
-
);
|
|
279
|
-
process.exit(0);
|
|
280
|
-
} catch (error) {
|
|
281
|
-
console.error(
|
|
282
|
-
JSON.stringify({
|
|
283
|
-
status: 'unhealthy',
|
|
284
|
-
error: error.message,
|
|
285
|
-
timestamp: new Date().toISOString(),
|
|
286
|
-
}),
|
|
287
|
-
);
|
|
288
|
-
process.exit(1);
|
|
225
|
+
// Handle headless mode early
|
|
226
|
+
if (flags && flags.headless) {
|
|
227
|
+
const isHeadless = isHeadlessEnvironment();
|
|
228
|
+
// Configure for headless mode
|
|
229
|
+
flags = {
|
|
230
|
+
...flags,
|
|
231
|
+
'non-interactive': true,
|
|
232
|
+
'output-format': flags['output-format'] || 'stream-json',
|
|
233
|
+
'no-auto-permissions': false
|
|
234
|
+
};
|
|
289
235
|
}
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
236
|
+
// Handle health check first
|
|
237
|
+
if (flags && flags['health-check']) {
|
|
238
|
+
try {
|
|
239
|
+
// Quick health check for Docker/K8s
|
|
240
|
+
console.log(JSON.stringify({
|
|
241
|
+
status: 'healthy',
|
|
242
|
+
service: 'claude-flow-swarm',
|
|
243
|
+
version: process.env.npm_package_version || '2.0.0',
|
|
244
|
+
timestamp: new Date().toISOString()
|
|
245
|
+
}));
|
|
246
|
+
process.exit(0);
|
|
247
|
+
} catch (error) {
|
|
248
|
+
console.error(JSON.stringify({
|
|
249
|
+
status: 'unhealthy',
|
|
250
|
+
error: error.message,
|
|
251
|
+
timestamp: new Date().toISOString()
|
|
252
|
+
}));
|
|
253
|
+
process.exit(1);
|
|
254
|
+
}
|
|
305
255
|
}
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
//
|
|
357
|
-
flags
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
256
|
+
const objective = (args || []).join(' ').trim();
|
|
257
|
+
if (!objective) {
|
|
258
|
+
console.error('❌ Usage: swarm <objective>');
|
|
259
|
+
showSwarmHelp();
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
// Force headless mode if flag is set
|
|
263
|
+
if (flags && flags.headless) {
|
|
264
|
+
const isHeadless = isHeadlessEnvironment();
|
|
265
|
+
if (!isHeadless) {
|
|
266
|
+
console.log('🤖 Forcing headless mode as requested');
|
|
267
|
+
}
|
|
268
|
+
flags = {
|
|
269
|
+
...flags,
|
|
270
|
+
'non-interactive': true,
|
|
271
|
+
'output-format': flags['output-format'] || 'json',
|
|
272
|
+
'no-auto-permissions': false
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
// Handle JSON output format
|
|
276
|
+
const outputFormat = flags && flags['output-format'];
|
|
277
|
+
const outputFile = flags && flags['output-file'];
|
|
278
|
+
const isJsonOutput = outputFormat === 'json';
|
|
279
|
+
const isNonInteractive = isJsonOutput || flags && flags['no-interactive'];
|
|
280
|
+
const useJsonLogs = flags && flags['json-logs'];
|
|
281
|
+
// Override console.log for JSON logs if requested
|
|
282
|
+
if (useJsonLogs) {
|
|
283
|
+
const originalLog = console.log;
|
|
284
|
+
const originalError = console.error;
|
|
285
|
+
console.log = (...args)=>{
|
|
286
|
+
originalLog(JSON.stringify({
|
|
287
|
+
level: 'info',
|
|
288
|
+
message: args.join(' '),
|
|
289
|
+
timestamp: new Date().toISOString(),
|
|
290
|
+
service: 'claude-flow-swarm'
|
|
291
|
+
}));
|
|
292
|
+
};
|
|
293
|
+
console.error = (...args)=>{
|
|
294
|
+
originalError(JSON.stringify({
|
|
295
|
+
level: 'error',
|
|
296
|
+
message: args.join(' '),
|
|
297
|
+
timestamp: new Date().toISOString(),
|
|
298
|
+
service: 'claude-flow-swarm'
|
|
299
|
+
}));
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
// Handle analysis/read-only mode
|
|
303
|
+
const isAnalysisMode = flags && (flags.analysis || flags['read-only']);
|
|
304
|
+
const analysisMode = isAnalysisMode ? 'analysis' : 'standard';
|
|
305
|
+
// For JSON output, allow using Claude with stream-json format
|
|
306
|
+
// Only force executor mode if explicitly using 'json' format (not 'stream-json')
|
|
307
|
+
if (flags && flags['output-format'] === 'json' && !(flags && flags.executor)) {
|
|
308
|
+
// Keep backward compatibility - regular 'json' format uses executor
|
|
309
|
+
flags = {
|
|
310
|
+
...flags || {},
|
|
311
|
+
executor: true
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
// Check if we should use the old executor (opt-in with --executor flag)
|
|
315
|
+
if (flags && flags.executor) {
|
|
362
316
|
// Continue with the old swarm executor implementation below
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
const enableSparc =
|
|
379
|
-
flags.sparc !== false && (strategy === 'development' || strategy === 'auto');
|
|
380
|
-
|
|
381
|
-
// Build the complete swarm prompt before checking for claude
|
|
382
|
-
const swarmPrompt = `You are orchestrating a Claude Flow Swarm using Claude Code's Task tool for agent execution.
|
|
317
|
+
} else {
|
|
318
|
+
// Default behavior: spawn Claude Code with comprehensive swarm MCP instructions
|
|
319
|
+
try {
|
|
320
|
+
const { execSync, spawn } = await import("child_process");
|
|
321
|
+
// Get configuration values first
|
|
322
|
+
const strategy = flags.strategy || 'auto';
|
|
323
|
+
const mode = flags.mode || 'centralized';
|
|
324
|
+
const maxAgents = flags['max-agents'] || 5;
|
|
325
|
+
// Get strategy-specific guidance
|
|
326
|
+
const strategyGuidance = getStrategyGuidance(strategy, objective);
|
|
327
|
+
const modeGuidance = getModeGuidance(mode);
|
|
328
|
+
const agentRecommendations = getAgentRecommendations(strategy, maxAgents, objective);
|
|
329
|
+
const enableSparc = flags.sparc !== false && (strategy === 'development' || strategy === 'auto');
|
|
330
|
+
// Build the complete swarm prompt before checking for claude
|
|
331
|
+
const swarmPrompt = `You are orchestrating a Claude Flow Swarm using Claude Code's Task tool for agent execution.
|
|
383
332
|
|
|
384
333
|
🚨 CRITICAL INSTRUCTION: Use Claude Code's Task Tool for ALL Agent Spawning!
|
|
385
334
|
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
@@ -399,9 +348,7 @@ export async function swarmCommand(args, flags) {
|
|
|
399
348
|
- Testing Mode: ${flags.testing || false}
|
|
400
349
|
- Analysis Mode: ${isAnalysisMode ? 'ENABLED (Read-Only)' : 'DISABLED'}
|
|
401
350
|
|
|
402
|
-
${
|
|
403
|
-
isAnalysisMode
|
|
404
|
-
? `🔍 ANALYSIS MODE CONSTRAINTS:
|
|
351
|
+
${isAnalysisMode ? `🔍 ANALYSIS MODE CONSTRAINTS:
|
|
405
352
|
|
|
406
353
|
⚠️ READ-ONLY MODE ACTIVE - NO CODE MODIFICATIONS ALLOWED
|
|
407
354
|
|
|
@@ -434,9 +381,7 @@ ALL AGENTS MUST OPERATE IN READ-ONLY MODE. Focus on:
|
|
|
434
381
|
|
|
435
382
|
Generate comprehensive reports instead of making changes.
|
|
436
383
|
|
|
437
|
-
`
|
|
438
|
-
: ''
|
|
439
|
-
}🚨 CRITICAL: PARALLEL EXECUTION IS MANDATORY! 🚨
|
|
384
|
+
` : ''}🚨 CRITICAL: PARALLEL EXECUTION IS MANDATORY! 🚨
|
|
440
385
|
|
|
441
386
|
📋 CLAUDE-FLOW SWARM BATCHTOOL INSTRUCTIONS
|
|
442
387
|
|
|
@@ -647,9 +592,7 @@ ${agentRecommendations}
|
|
|
647
592
|
- Tools: agent_communicate, memory_store/retrieve
|
|
648
593
|
|
|
649
594
|
⚡ EXECUTION WORKFLOW - ALWAYS USE BATCHTOOL:
|
|
650
|
-
${
|
|
651
|
-
enableSparc
|
|
652
|
-
? `
|
|
595
|
+
${enableSparc ? `
|
|
653
596
|
1. SPARC METHODOLOGY WITH PARALLEL EXECUTION:
|
|
654
597
|
|
|
655
598
|
S - Specification Phase (Single BatchTool):
|
|
@@ -697,8 +640,7 @@ ${
|
|
|
697
640
|
mcp__claude-flow__memory_retrieve { pattern: "**/*" }
|
|
698
641
|
TodoWrite { todos: [{content: "Final review", status: "completed"}] }
|
|
699
642
|
\`\`\`
|
|
700
|
-
`
|
|
701
|
-
: `
|
|
643
|
+
` : `
|
|
702
644
|
1. STANDARD SWARM EXECUTION WITH PARALLEL OPERATIONS:
|
|
703
645
|
|
|
704
646
|
Initial Setup (Single BatchTool):
|
|
@@ -726,8 +668,7 @@ ${
|
|
|
726
668
|
mcp__claude-flow__agent_communicate { to: "all", message: "Status update" }
|
|
727
669
|
mcp__claude-flow__memory_store { key: "progress", value: {...} }
|
|
728
670
|
\`\`\`
|
|
729
|
-
`
|
|
730
|
-
}
|
|
671
|
+
`}
|
|
731
672
|
|
|
732
673
|
🤝 AGENT TYPES & THEIR MCP TOOL USAGE:
|
|
733
674
|
|
|
@@ -792,243 +733,207 @@ Use hierarchical keys for organization:
|
|
|
792
733
|
Start by spawning a coordinator agent and creating the initial task structure. Use the MCP tools to orchestrate the swarm, coordinate agents, and track progress. Remember to store important decisions and artifacts in collective memory for other agents to access.
|
|
793
734
|
|
|
794
735
|
The swarm should be self-documenting - use memory_store to save all important information, decisions, and results throughout the execution.`;
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
claudeArgs.push('--dangerously-skip-permissions');
|
|
957
|
-
if (!isNonInteractive) {
|
|
958
|
-
console.log(
|
|
959
|
-
'🔓 Using --dangerously-skip-permissions by default for seamless swarm execution',
|
|
960
|
-
);
|
|
736
|
+
// If --claude flag is used, force Claude Code even if CLI not available
|
|
737
|
+
if (flags && flags.claude) {
|
|
738
|
+
// --claude flag means interactive mode, so don't apply non-interactive
|
|
739
|
+
console.log('🐝 Launching Claude Flow Swarm System...');
|
|
740
|
+
console.log(`📋 Objective: ${objective}`);
|
|
741
|
+
console.log(`🎯 Strategy: ${strategy}`);
|
|
742
|
+
console.log(`🏗️ Mode: ${mode}`);
|
|
743
|
+
console.log(`🤖 Max Agents: ${maxAgents}\n`);
|
|
744
|
+
console.log('🚀 Launching Claude Code with Swarm Coordination');
|
|
745
|
+
console.log('─'.repeat(60));
|
|
746
|
+
// Build arguments properly: for interactive mode, prompt can be first
|
|
747
|
+
const claudeArgs = [];
|
|
748
|
+
// Add auto-permission flag first
|
|
749
|
+
if (flags['dangerously-skip-permissions'] !== false && !flags['no-auto-permissions']) {
|
|
750
|
+
claudeArgs.push('--dangerously-skip-permissions');
|
|
751
|
+
console.log('🔓 Using --dangerously-skip-permissions by default for seamless swarm execution');
|
|
752
|
+
}
|
|
753
|
+
// Add the prompt (for interactive mode, position doesn't matter as much)
|
|
754
|
+
claudeArgs.push(swarmPrompt);
|
|
755
|
+
// --claude flag means interactive mode, so don't add non-interactive flags
|
|
756
|
+
// For --claude interactive mode, spawn Claude directly
|
|
757
|
+
// Temporarily disable telemetry to avoid console output interference
|
|
758
|
+
const claudeEnv = {
|
|
759
|
+
...process.env
|
|
760
|
+
};
|
|
761
|
+
// Remove telemetry env vars to prevent console output
|
|
762
|
+
delete claudeEnv.CLAUDE_CODE_ENABLE_TELEMETRY;
|
|
763
|
+
delete claudeEnv.OTEL_METRICS_EXPORTER;
|
|
764
|
+
delete claudeEnv.OTEL_LOGS_EXPORTER;
|
|
765
|
+
const claudeProcess = spawn('claude', claudeArgs, {
|
|
766
|
+
stdio: 'inherit',
|
|
767
|
+
shell: false,
|
|
768
|
+
env: claudeEnv
|
|
769
|
+
});
|
|
770
|
+
console.log('\n✓ Claude Code launched with swarm coordination prompt!');
|
|
771
|
+
console.log(' The swarm coordinator will orchestrate all agent tasks');
|
|
772
|
+
console.log(' Use MCP tools for coordination and memory sharing');
|
|
773
|
+
console.log('\n💡 Pro Tips:');
|
|
774
|
+
console.log('─'.repeat(30));
|
|
775
|
+
console.log('• Use TodoWrite to track parallel tasks');
|
|
776
|
+
console.log('• Store results with mcp__claude-flow__memory_usage');
|
|
777
|
+
console.log('• Monitor progress with mcp__claude-flow__swarm_monitor');
|
|
778
|
+
console.log('• Check task status with mcp__claude-flow__task_status');
|
|
779
|
+
// Set up clean termination
|
|
780
|
+
const cleanup = ()=>{
|
|
781
|
+
console.log('\n🛑 Shutting down swarm gracefully...');
|
|
782
|
+
if (claudeProcess && !claudeProcess.killed) {
|
|
783
|
+
claudeProcess.kill('SIGTERM');
|
|
784
|
+
}
|
|
785
|
+
process.exit(0);
|
|
786
|
+
};
|
|
787
|
+
process.on('SIGINT', cleanup);
|
|
788
|
+
process.on('SIGTERM', cleanup);
|
|
789
|
+
// Wait for claude to exit
|
|
790
|
+
claudeProcess.on('exit', (code)=>{
|
|
791
|
+
if (code === 0) {
|
|
792
|
+
console.log('\n✓ Swarm execution completed successfully');
|
|
793
|
+
} else if (code !== null) {
|
|
794
|
+
console.log(`\n✗ Swarm execution exited with code ${code}`);
|
|
795
|
+
}
|
|
796
|
+
process.exit(code || 0);
|
|
797
|
+
});
|
|
798
|
+
// Handle spawn errors (e.g., claude not found)
|
|
799
|
+
claudeProcess.on('error', (err)=>{
|
|
800
|
+
if (err.code === 'ENOENT') {
|
|
801
|
+
console.error('\n❌ Claude Code CLI not found. Please install Claude Code:');
|
|
802
|
+
console.error(' https://claude.ai/download');
|
|
803
|
+
} else {
|
|
804
|
+
console.error('\n❌ Failed to launch Claude Code:', err.message);
|
|
805
|
+
}
|
|
806
|
+
process.exit(1);
|
|
807
|
+
});
|
|
808
|
+
return;
|
|
809
|
+
}
|
|
810
|
+
// Check if we're in non-interactive/headless mode FIRST (like alpha.83)
|
|
811
|
+
const isNonInteractive = flags['no-interactive'] || flags['non-interactive'] || flags['output-format'] === 'stream-json' || isHeadlessEnvironment();
|
|
812
|
+
// Check if claude command exists
|
|
813
|
+
let claudeAvailable = false;
|
|
814
|
+
try {
|
|
815
|
+
execSync('which claude', {
|
|
816
|
+
stdio: 'ignore'
|
|
817
|
+
});
|
|
818
|
+
claudeAvailable = true;
|
|
819
|
+
} catch {
|
|
820
|
+
if (!isNonInteractive) {
|
|
821
|
+
console.log('⚠️ Claude Code CLI not found in PATH');
|
|
822
|
+
console.log('Install it with: npm install -g @anthropic-ai/claude-code');
|
|
823
|
+
console.log('Or use --claude flag to open Claude Code CLI');
|
|
824
|
+
console.log('\nWould spawn Claude Code with swarm objective:');
|
|
825
|
+
console.log(`📋 Objective: ${objective}`);
|
|
826
|
+
console.log('\nOptions:');
|
|
827
|
+
console.log(' • Use --executor flag for built-in executor: claude-flow-novice swarm "objective" --executor');
|
|
828
|
+
console.log(' • Use --claude flag to open Claude Code CLI: claude-flow-novice swarm "objective" --claude');
|
|
829
|
+
} else {
|
|
830
|
+
// In non-interactive mode, output JSON error
|
|
831
|
+
console.error(JSON.stringify({
|
|
832
|
+
error: 'Claude Code CLI not found',
|
|
833
|
+
message: 'Install with: npm install -g @anthropic-ai/claude-code',
|
|
834
|
+
fallback: 'Use --executor flag for built-in executor'
|
|
835
|
+
}));
|
|
836
|
+
}
|
|
837
|
+
return;
|
|
838
|
+
}
|
|
839
|
+
// Claude is available, use it to run swarm
|
|
840
|
+
if (!isNonInteractive) {
|
|
841
|
+
console.log('🐝 Launching Claude Flow Swarm System...');
|
|
842
|
+
console.log(`📋 Objective: ${objective}`);
|
|
843
|
+
console.log(`🎯 Strategy: ${flags.strategy || 'auto'}`);
|
|
844
|
+
console.log(`🏗️ Mode: ${flags.mode || 'centralized'}`);
|
|
845
|
+
console.log(`🤖 Max Agents: ${flags['max-agents'] || 5}`);
|
|
846
|
+
if (isAnalysisMode) {
|
|
847
|
+
console.log(`🔍 Analysis Mode: ENABLED (Read-Only - No Code Changes)`);
|
|
848
|
+
}
|
|
849
|
+
console.log();
|
|
850
|
+
} else {
|
|
851
|
+
// Non-interactive mode output
|
|
852
|
+
console.log('🤖 Running in non-interactive mode with Claude');
|
|
853
|
+
console.log('📋 Command: claude [prompt] -p --output-format stream-json --verbose');
|
|
854
|
+
}
|
|
855
|
+
// Continue with the default swarm behavior if not using --claude flag
|
|
856
|
+
// Build arguments in correct order: flags first, then prompt
|
|
857
|
+
const claudeArgs = [];
|
|
858
|
+
// Add non-interactive flags FIRST if needed
|
|
859
|
+
if (isNonInteractive) {
|
|
860
|
+
claudeArgs.push('-p'); // Print mode
|
|
861
|
+
claudeArgs.push('--output-format', 'stream-json'); // JSON streaming
|
|
862
|
+
claudeArgs.push('--verbose'); // Verbose output
|
|
863
|
+
}
|
|
864
|
+
// Add auto-permission flag BEFORE the prompt
|
|
865
|
+
if (flags['dangerously-skip-permissions'] !== false && !flags['no-auto-permissions']) {
|
|
866
|
+
claudeArgs.push('--dangerously-skip-permissions');
|
|
867
|
+
if (!isNonInteractive) {
|
|
868
|
+
console.log('🔓 Using --dangerously-skip-permissions by default for seamless swarm execution');
|
|
869
|
+
}
|
|
870
|
+
}
|
|
871
|
+
// Add the prompt as the LAST argument
|
|
872
|
+
claudeArgs.push(swarmPrompt);
|
|
873
|
+
// Spawn claude with properly ordered arguments
|
|
874
|
+
const claudeProcess = spawn('claude', claudeArgs, {
|
|
875
|
+
stdio: 'inherit',
|
|
876
|
+
shell: false
|
|
877
|
+
});
|
|
878
|
+
if (!isNonInteractive) {
|
|
879
|
+
console.log('✓ Claude Code launched with swarm coordination prompt!');
|
|
880
|
+
console.log('\n🚀 The swarm coordination instructions have been injected into Claude Code');
|
|
881
|
+
console.log(' The prompt includes:');
|
|
882
|
+
console.log(' • Strategy-specific guidance for', strategy);
|
|
883
|
+
console.log(' • Coordination patterns for', mode, 'mode');
|
|
884
|
+
console.log(' • Recommended agents and MCP tool usage');
|
|
885
|
+
console.log(' • Complete workflow documentation\n');
|
|
886
|
+
}
|
|
887
|
+
// Handle process events
|
|
888
|
+
claudeProcess.on('error', (err)=>{
|
|
889
|
+
console.error('❌ Failed to launch Claude Code:', err.message);
|
|
890
|
+
});
|
|
891
|
+
// Don't wait for completion - let it run
|
|
892
|
+
return;
|
|
893
|
+
} catch (error) {
|
|
894
|
+
console.error('❌ Failed to spawn Claude Code:', error.message);
|
|
895
|
+
console.log('\nFalling back to built-in executor...');
|
|
896
|
+
// Fall through to executor implementation
|
|
961
897
|
}
|
|
962
|
-
}
|
|
963
|
-
|
|
964
|
-
// Add the prompt as the LAST argument
|
|
965
|
-
claudeArgs.push(swarmPrompt);
|
|
966
|
-
|
|
967
|
-
// Spawn claude with properly ordered arguments
|
|
968
|
-
const claudeProcess = spawn('claude', claudeArgs, {
|
|
969
|
-
stdio: 'inherit',
|
|
970
|
-
shell: false,
|
|
971
|
-
});
|
|
972
|
-
|
|
973
|
-
if (!isNonInteractive) {
|
|
974
|
-
console.log('✓ Claude Code launched with swarm coordination prompt!');
|
|
975
|
-
console.log('\n🚀 The swarm coordination instructions have been injected into Claude Code');
|
|
976
|
-
console.log(' The prompt includes:');
|
|
977
|
-
console.log(' • Strategy-specific guidance for', strategy);
|
|
978
|
-
console.log(' • Coordination patterns for', mode, 'mode');
|
|
979
|
-
console.log(' • Recommended agents and MCP tool usage');
|
|
980
|
-
console.log(' • Complete workflow documentation\n');
|
|
981
|
-
}
|
|
982
|
-
|
|
983
|
-
// Handle process events
|
|
984
|
-
claudeProcess.on('error', (err) => {
|
|
985
|
-
console.error('❌ Failed to launch Claude Code:', err.message);
|
|
986
|
-
});
|
|
987
|
-
|
|
988
|
-
// Don't wait for completion - let it run
|
|
989
|
-
return;
|
|
990
|
-
} catch (error) {
|
|
991
|
-
console.error('❌ Failed to spawn Claude Code:', error.message);
|
|
992
|
-
console.log('\nFalling back to built-in executor...');
|
|
993
|
-
// Fall through to executor implementation
|
|
994
898
|
}
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
899
|
+
// Check if we should run in background mode
|
|
900
|
+
if (flags && flags.background && !process.env.CLAUDE_SWARM_NO_BG) {
|
|
901
|
+
// Check if we're in Deno environment
|
|
902
|
+
if (typeof Deno !== 'undefined') {
|
|
903
|
+
// In Deno, spawn a new process for true background execution
|
|
904
|
+
const objective = (args || []).join(' ').trim();
|
|
905
|
+
const swarmId = `swarm_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
|
|
906
|
+
const swarmRunDir = `./swarm-runs/${swarmId}`;
|
|
907
|
+
// Create swarm directory
|
|
908
|
+
await mkdirAsync(swarmRunDir, {
|
|
909
|
+
recursive: true
|
|
910
|
+
});
|
|
911
|
+
console.log(`🐝 Launching swarm in background mode...`);
|
|
912
|
+
console.log(`📋 Objective: ${objective}`);
|
|
913
|
+
console.log(`🆔 Swarm ID: ${swarmId}`);
|
|
914
|
+
console.log(`📁 Results: ${swarmRunDir}`);
|
|
915
|
+
// Build command args without background flag (to prevent infinite loop)
|
|
916
|
+
const commandArgs = [
|
|
917
|
+
'run',
|
|
918
|
+
'--allow-all',
|
|
919
|
+
import.meta.url,
|
|
920
|
+
objective
|
|
921
|
+
];
|
|
922
|
+
const newFlags = {
|
|
923
|
+
...flags
|
|
924
|
+
};
|
|
925
|
+
delete newFlags.background; // Remove background flag
|
|
926
|
+
for (const [key, value] of Object.entries(newFlags)){
|
|
927
|
+
commandArgs.push(`--${key}`);
|
|
928
|
+
if (value !== true) {
|
|
929
|
+
commandArgs.push(String(value));
|
|
930
|
+
}
|
|
931
|
+
}
|
|
932
|
+
// Create log file
|
|
933
|
+
const logFile = `${swarmRunDir}/swarm.log`;
|
|
934
|
+
const logHandle = await open(logFile, 'w');
|
|
935
|
+
// Create a script to run the swarm without background flag
|
|
936
|
+
const scriptContent = `#!/usr/bin/env -S deno run --allow-all
|
|
1032
937
|
import { swarmCommand } from "${import.meta.url}";
|
|
1033
938
|
import { cwd, exit, existsSync } from '../node-compat.js';
|
|
1034
939
|
import process from 'process';
|
|
@@ -1043,64 +948,53 @@ process.env.CLAUDE_SWARM_NO_BG = 'true';
|
|
|
1043
948
|
// Run the swarm
|
|
1044
949
|
await swarmCommand(args, flags);
|
|
1045
950
|
`;
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
const output = await bgProcess.output();
|
|
1094
|
-
console.log(decoder.decode(output.stdout));
|
|
1095
|
-
|
|
1096
|
-
// Exit immediately after launching
|
|
1097
|
-
exit(0);
|
|
1098
|
-
} catch (error) {
|
|
1099
|
-
// Fallback: create a double-fork pattern using a shell script
|
|
1100
|
-
console.log(`\n⚠️ Background script not found, using fallback method`);
|
|
1101
|
-
|
|
1102
|
-
// Create a shell script that will run the swarm
|
|
1103
|
-
const shellScript = `#!/bin/bash
|
|
951
|
+
const scriptPath = `${swarmRunDir}/run-swarm.js`;
|
|
952
|
+
await writeTextFile(scriptPath, scriptContent);
|
|
953
|
+
// Save process info first
|
|
954
|
+
await writeTextFile(`${swarmRunDir}/process.json`, JSON.stringify({
|
|
955
|
+
swarmId: swarmId,
|
|
956
|
+
objective: objective,
|
|
957
|
+
startTime: new Date().toISOString(),
|
|
958
|
+
logFile: logFile,
|
|
959
|
+
status: 'starting'
|
|
960
|
+
}, null, 2));
|
|
961
|
+
// Close log handle before spawning
|
|
962
|
+
logHandle.close();
|
|
963
|
+
// Use the bash script for true background execution
|
|
964
|
+
const binDir = new URL('../../../bin/', import.meta.url).pathname;
|
|
965
|
+
const bgScriptPath = `${binDir}claude-flow-swarm-bg`;
|
|
966
|
+
try {
|
|
967
|
+
// Check if the background script exists
|
|
968
|
+
statSync(bgScriptPath);
|
|
969
|
+
// Build command args for the background script
|
|
970
|
+
const bgArgs = [
|
|
971
|
+
objective
|
|
972
|
+
];
|
|
973
|
+
for (const [key, value] of Object.entries(newFlags)){
|
|
974
|
+
bgArgs.push(`--${key}`);
|
|
975
|
+
if (value !== true) {
|
|
976
|
+
bgArgs.push(String(value));
|
|
977
|
+
}
|
|
978
|
+
}
|
|
979
|
+
// Use the bash background script
|
|
980
|
+
const bgProcess = spawn(bgScriptPath, bgArgs, {
|
|
981
|
+
stdio: [
|
|
982
|
+
'ignore',
|
|
983
|
+
'pipe',
|
|
984
|
+
'pipe'
|
|
985
|
+
]
|
|
986
|
+
});
|
|
987
|
+
// Read and display output
|
|
988
|
+
const decoder = new TextDecoder();
|
|
989
|
+
const output = await bgProcess.output();
|
|
990
|
+
console.log(decoder.decode(output.stdout));
|
|
991
|
+
// Exit immediately after launching
|
|
992
|
+
exit(0);
|
|
993
|
+
} catch (error) {
|
|
994
|
+
// Fallback: create a double-fork pattern using a shell script
|
|
995
|
+
console.log(`\n⚠️ Background script not found, using fallback method`);
|
|
996
|
+
// Create a shell script that will run the swarm
|
|
997
|
+
const shellScript = `#!/bin/bash
|
|
1104
998
|
# Double fork to detach from parent
|
|
1105
999
|
(
|
|
1106
1000
|
(
|
|
@@ -1110,262 +1004,231 @@ await swarmCommand(args, flags);
|
|
|
1110
1004
|
)
|
|
1111
1005
|
exit 0
|
|
1112
1006
|
`;
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
exit(0);
|
|
1132
|
-
}
|
|
1133
|
-
}
|
|
1134
|
-
|
|
1135
|
-
// Node.js environment - use background script
|
|
1136
|
-
const { execSync } = await import('child_process');
|
|
1137
|
-
const path = await import('path');
|
|
1138
|
-
const fs = await import('fs');
|
|
1139
|
-
|
|
1140
|
-
const objective = (args || []).join(' ').trim();
|
|
1141
|
-
|
|
1142
|
-
// Get the claude-flow-swarm-bg script path
|
|
1143
|
-
const bgScriptPath = path.join(
|
|
1144
|
-
path.dirname(new URL(import.meta.url).pathname),
|
|
1145
|
-
'../../../bin/claude-flow-swarm-bg',
|
|
1146
|
-
);
|
|
1147
|
-
|
|
1148
|
-
// Check if background script exists
|
|
1149
|
-
if (fs.existsSync(bgScriptPath)) {
|
|
1150
|
-
// Build command args
|
|
1151
|
-
const commandArgs = [objective];
|
|
1152
|
-
for (const [key, value] of Object.entries(flags)) {
|
|
1153
|
-
if (key !== 'background') {
|
|
1154
|
-
// Skip background flag
|
|
1155
|
-
commandArgs.push(`--${key}`);
|
|
1156
|
-
if (value !== true) {
|
|
1157
|
-
commandArgs.push(String(value));
|
|
1158
|
-
}
|
|
1007
|
+
const shellScriptPath = `${swarmRunDir}/launch-background.sh`;
|
|
1008
|
+
await writeTextFile(shellScriptPath, shellScript);
|
|
1009
|
+
chmodSync(shellScriptPath, 0o755);
|
|
1010
|
+
// Execute the shell script
|
|
1011
|
+
const shellProcess = spawn('bash', [
|
|
1012
|
+
shellScriptPath
|
|
1013
|
+
], {
|
|
1014
|
+
stdio: 'ignore',
|
|
1015
|
+
detached: true
|
|
1016
|
+
});
|
|
1017
|
+
shellProcess.unref();
|
|
1018
|
+
console.log(`\n✅ Swarm launched in background!`);
|
|
1019
|
+
console.log(`📄 Logs: tail -f ${logFile}`);
|
|
1020
|
+
console.log(`📊 Status: claude-flow-novice swarm status ${swarmId}`);
|
|
1021
|
+
console.log(`\nThe swarm will continue running independently.`);
|
|
1022
|
+
// Exit immediately
|
|
1023
|
+
exit(0);
|
|
1024
|
+
}
|
|
1159
1025
|
}
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1026
|
+
// Node.js environment - use background script
|
|
1027
|
+
const { execSync } = await import("child_process");
|
|
1028
|
+
const path = await import("path");
|
|
1029
|
+
const fs = await import("fs");
|
|
1030
|
+
const objective = (args || []).join(' ').trim();
|
|
1031
|
+
// Get the claude-flow-swarm-bg script path
|
|
1032
|
+
const bgScriptPath = path.join(path.dirname(new URL(import.meta.url).pathname), '../../../bin/claude-flow-swarm-bg');
|
|
1033
|
+
// Check if background script exists
|
|
1034
|
+
if (fs.existsSync(bgScriptPath)) {
|
|
1035
|
+
// Build command args
|
|
1036
|
+
const commandArgs = [
|
|
1037
|
+
objective
|
|
1038
|
+
];
|
|
1039
|
+
for (const [key, value] of Object.entries(flags)){
|
|
1040
|
+
if (key !== 'background') {
|
|
1041
|
+
// Skip background flag
|
|
1042
|
+
commandArgs.push(`--${key}`);
|
|
1043
|
+
if (value !== true) {
|
|
1044
|
+
commandArgs.push(String(value));
|
|
1045
|
+
}
|
|
1046
|
+
}
|
|
1047
|
+
}
|
|
1048
|
+
// Execute the background script
|
|
1049
|
+
try {
|
|
1050
|
+
execSync(`"${bgScriptPath}" ${commandArgs.map((arg)=>`"${arg}"`).join(' ')}`, {
|
|
1051
|
+
stdio: 'inherit'
|
|
1052
|
+
});
|
|
1053
|
+
} catch (error) {
|
|
1054
|
+
console.error('Failed to launch background swarm:', error.message);
|
|
1055
|
+
}
|
|
1056
|
+
} else {
|
|
1057
|
+
// Fallback to simple message
|
|
1058
|
+
console.log(`🐝 Background mode requested`);
|
|
1059
|
+
console.log(`📋 Objective: ${objective}`);
|
|
1060
|
+
console.log(`\n⚠️ Background execution requires the claude-flow-swarm-bg script.`);
|
|
1061
|
+
console.log(`\nFor true background execution, use:`);
|
|
1062
|
+
console.log(` nohup claude-flow-novice swarm "${objective}" ${Object.entries(flags).filter(([k, v])=>k !== 'background' && v).map(([k, v])=>`--${k}${v !== true ? ` ${v}` : ''}`).join(' ')} > swarm.log 2>&1 &`);
|
|
1063
|
+
}
|
|
1064
|
+
return;
|
|
1182
1065
|
}
|
|
1183
|
-
return;
|
|
1184
|
-
}
|
|
1185
|
-
|
|
1186
|
-
try {
|
|
1187
|
-
// Try to load the compiled JavaScript module first
|
|
1188
|
-
let swarmAction;
|
|
1189
1066
|
try {
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
const module = await import(distPath);
|
|
1193
|
-
swarmAction = module.swarmAction;
|
|
1194
|
-
} catch (distError) {
|
|
1195
|
-
// Instead of immediately falling back to basic mode,
|
|
1196
|
-
// continue to the Claude integration below
|
|
1197
|
-
console.log('📦 Compiled swarm module not found, checking for Claude CLI...');
|
|
1198
|
-
}
|
|
1199
|
-
|
|
1200
|
-
// Only call swarmAction if it was successfully loaded
|
|
1201
|
-
if (swarmAction) {
|
|
1202
|
-
// Create command context compatible with TypeScript version
|
|
1203
|
-
const ctx = {
|
|
1204
|
-
args: args || [],
|
|
1205
|
-
flags: flags || {},
|
|
1206
|
-
command: 'swarm',
|
|
1207
|
-
};
|
|
1208
|
-
|
|
1209
|
-
await swarmAction(ctx);
|
|
1210
|
-
return; // Exit after successful execution
|
|
1211
|
-
}
|
|
1212
|
-
} catch (error) {
|
|
1213
|
-
// If import fails (e.g., in node_modules), provide inline implementation
|
|
1214
|
-
if (
|
|
1215
|
-
error.code === 'ERR_MODULE_NOT_FOUND' ||
|
|
1216
|
-
error.code === 'ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING' ||
|
|
1217
|
-
error.code === 'ERR_UNKNOWN_FILE_EXTENSION'
|
|
1218
|
-
) {
|
|
1219
|
-
// Provide a basic swarm implementation that works without TypeScript imports
|
|
1220
|
-
const objective = (args || []).join(' ').trim();
|
|
1221
|
-
|
|
1222
|
-
if (!objective) {
|
|
1223
|
-
console.error('❌ Usage: swarm <objective>');
|
|
1224
|
-
showSwarmHelp();
|
|
1225
|
-
return;
|
|
1226
|
-
}
|
|
1227
|
-
|
|
1228
|
-
// Try to use the swarm executor directly
|
|
1229
|
-
try {
|
|
1230
|
-
const { executeSwarm } = await import('./swarm-executor.js');
|
|
1231
|
-
const result = await executeSwarm(objective, flags);
|
|
1232
|
-
|
|
1233
|
-
// If execution was successful, exit
|
|
1234
|
-
if (result && result.success) {
|
|
1235
|
-
return;
|
|
1236
|
-
}
|
|
1237
|
-
} catch (execError) {
|
|
1238
|
-
console.log(`⚠️ Swarm executor error: ${execError.message}`);
|
|
1239
|
-
// If swarm executor fails, try to create files directly
|
|
1067
|
+
// Try to load the compiled JavaScript module first
|
|
1068
|
+
let swarmAction;
|
|
1240
1069
|
try {
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1070
|
+
// Try the compiled version first (for production/npm packages)
|
|
1071
|
+
const distPath = new URL('../../../dist/cli/commands/swarm-new.js', import.meta.url);
|
|
1072
|
+
const module = await import(distPath);
|
|
1073
|
+
swarmAction = module.swarmAction;
|
|
1074
|
+
} catch (distError) {
|
|
1075
|
+
// Instead of immediately falling back to basic mode,
|
|
1076
|
+
// continue to the Claude integration below
|
|
1077
|
+
console.log('📦 Compiled swarm module not found, checking for Claude CLI...');
|
|
1246
1078
|
}
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
// Generate swarm ID
|
|
1258
|
-
const swarmId = `swarm_${Math.random().toString(36).substring(2, 11)}_${Math.random().toString(36).substring(2, 11)}`;
|
|
1259
|
-
|
|
1260
|
-
if (flags['dry-run']) {
|
|
1261
|
-
console.log(`🆔 Swarm ID: ${swarmId}`);
|
|
1262
|
-
console.log(`📊 Max Tasks: ${flags['max-tasks'] || 100}`);
|
|
1263
|
-
console.log(`⏰ Timeout: ${flags.timeout || 60} minutes`);
|
|
1264
|
-
console.log(`🔄 Parallel: ${flags.parallel || false}`);
|
|
1265
|
-
console.log(`🌐 Distributed: ${flags.distributed || false}`);
|
|
1266
|
-
console.log(`🔍 Monitoring: ${flags.monitor || false}`);
|
|
1267
|
-
console.log(`👥 Review Mode: ${flags.review || false}`);
|
|
1268
|
-
console.log(`🧪 Testing: ${flags.testing || false}`);
|
|
1269
|
-
console.log(`🧠 Memory Namespace: ${flags['memory-namespace'] || 'swarm'}`);
|
|
1270
|
-
console.log(`💾 Persistence: ${flags.persistence !== false}`);
|
|
1271
|
-
console.log(`🔒 Encryption: ${flags.encryption || false}`);
|
|
1272
|
-
console.log(`📊 Quality Threshold: ${flags['quality-threshold'] || 0.8}`);
|
|
1273
|
-
console.log();
|
|
1274
|
-
console.log('🎛️ Coordination Strategy:');
|
|
1275
|
-
console.log(` • Agent Selection: ${flags['agent-selection'] || 'capability-based'}`);
|
|
1276
|
-
console.log(` • Task Scheduling: ${flags['task-scheduling'] || 'priority'}`);
|
|
1277
|
-
console.log(` • Load Balancing: ${flags['load-balancing'] || 'work-stealing'}`);
|
|
1278
|
-
console.log(` • Fault Tolerance: ${flags['fault-tolerance'] || 'retry'}`);
|
|
1279
|
-
console.log(` • Communication: ${flags.communication || 'event-driven'}`);
|
|
1280
|
-
console.log('⚠️ DRY RUN - Advanced Swarm Configuration');
|
|
1281
|
-
return;
|
|
1282
|
-
}
|
|
1283
|
-
|
|
1284
|
-
// For actual execution in npm context, try to find and run swarm-demo.ts
|
|
1285
|
-
try {
|
|
1286
|
-
const path = await import('path');
|
|
1287
|
-
const { fileURLToPath } = await import('url');
|
|
1288
|
-
const fs = await import('fs');
|
|
1289
|
-
const { spawn } = await import('child_process');
|
|
1290
|
-
|
|
1291
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
1292
|
-
const __dirname = path.dirname(__filename);
|
|
1293
|
-
|
|
1294
|
-
// Look for swarm-demo.ts in the package
|
|
1295
|
-
const possiblePaths = [
|
|
1296
|
-
path.join(__dirname, '../../../swarm-demo.ts'),
|
|
1297
|
-
path.join(__dirname, '../../swarm-demo.ts'),
|
|
1298
|
-
];
|
|
1299
|
-
|
|
1300
|
-
let swarmDemoPath = null;
|
|
1301
|
-
for (const p of possiblePaths) {
|
|
1302
|
-
if (fs.existsSync(p)) {
|
|
1303
|
-
swarmDemoPath = p;
|
|
1304
|
-
break;
|
|
1305
|
-
}
|
|
1079
|
+
// Only call swarmAction if it was successfully loaded
|
|
1080
|
+
if (swarmAction) {
|
|
1081
|
+
// Create command context compatible with TypeScript version
|
|
1082
|
+
const ctx = {
|
|
1083
|
+
args: args || [],
|
|
1084
|
+
flags: flags || {},
|
|
1085
|
+
command: 'swarm'
|
|
1086
|
+
};
|
|
1087
|
+
await swarmAction(ctx);
|
|
1088
|
+
return; // Exit after successful execution
|
|
1306
1089
|
}
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1090
|
+
} catch (error) {
|
|
1091
|
+
// If import fails (e.g., in node_modules), provide inline implementation
|
|
1092
|
+
if (error.code === 'ERR_MODULE_NOT_FOUND' || error.code === 'ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING' || error.code === 'ERR_UNKNOWN_FILE_EXTENSION') {
|
|
1093
|
+
// Provide a basic swarm implementation that works without TypeScript imports
|
|
1094
|
+
const objective = (args || []).join(' ').trim();
|
|
1095
|
+
if (!objective) {
|
|
1096
|
+
console.error('❌ Usage: swarm <objective>');
|
|
1097
|
+
showSwarmHelp();
|
|
1098
|
+
return;
|
|
1315
1099
|
}
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1100
|
+
// Try to use the swarm executor directly
|
|
1101
|
+
try {
|
|
1102
|
+
const { executeSwarm } = await import("./swarm-executor.js");
|
|
1103
|
+
const result = await executeSwarm(objective, flags);
|
|
1104
|
+
// If execution was successful, exit
|
|
1105
|
+
if (result && result.success) {
|
|
1106
|
+
return;
|
|
1107
|
+
}
|
|
1108
|
+
} catch (execError) {
|
|
1109
|
+
console.log(`⚠️ Swarm executor error: ${execError.message}`);
|
|
1110
|
+
// If swarm executor fails, try to create files directly
|
|
1111
|
+
try {
|
|
1112
|
+
await createSwarmFiles(objective, flags);
|
|
1113
|
+
return;
|
|
1114
|
+
} catch (createError) {
|
|
1115
|
+
console.log(`⚠️ Direct file creation error: ${createError.message}`);
|
|
1116
|
+
// Continue with fallback implementation
|
|
1117
|
+
}
|
|
1330
1118
|
}
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1119
|
+
// Provide a basic inline swarm implementation for npm packages
|
|
1120
|
+
console.log('🐝 Launching swarm system...');
|
|
1121
|
+
console.log(`📋 Objective: ${objective}`);
|
|
1122
|
+
console.log(`🎯 Strategy: ${flags.strategy || 'auto'}`);
|
|
1123
|
+
console.log(`🏗️ Mode: ${flags.mode || 'centralized'}`);
|
|
1124
|
+
console.log(`🤖 Max Agents: ${flags['max-agents'] || 5}`);
|
|
1125
|
+
console.log();
|
|
1126
|
+
// Generate swarm ID
|
|
1127
|
+
const swarmId = `swarm_${Math.random().toString(36).substring(2, 11)}_${Math.random().toString(36).substring(2, 11)}`;
|
|
1128
|
+
if (flags['dry-run']) {
|
|
1129
|
+
console.log(`🆔 Swarm ID: ${swarmId}`);
|
|
1130
|
+
console.log(`📊 Max Tasks: ${flags['max-tasks'] || 100}`);
|
|
1131
|
+
console.log(`⏰ Timeout: ${flags.timeout || 60} minutes`);
|
|
1132
|
+
console.log(`🔄 Parallel: ${flags.parallel || false}`);
|
|
1133
|
+
console.log(`🌐 Distributed: ${flags.distributed || false}`);
|
|
1134
|
+
console.log(`🔍 Monitoring: ${flags.monitor || false}`);
|
|
1135
|
+
console.log(`👥 Review Mode: ${flags.review || false}`);
|
|
1136
|
+
console.log(`🧪 Testing: ${flags.testing || false}`);
|
|
1137
|
+
console.log(`🧠 Memory Namespace: ${flags['memory-namespace'] || 'swarm'}`);
|
|
1138
|
+
console.log(`💾 Persistence: ${flags.persistence !== false}`);
|
|
1139
|
+
console.log(`🔒 Encryption: ${flags.encryption || false}`);
|
|
1140
|
+
console.log(`📊 Quality Threshold: ${flags['quality-threshold'] || 0.8}`);
|
|
1141
|
+
console.log();
|
|
1142
|
+
console.log('🎛️ Coordination Strategy:');
|
|
1143
|
+
console.log(` • Agent Selection: ${flags['agent-selection'] || 'capability-based'}`);
|
|
1144
|
+
console.log(` • Task Scheduling: ${flags['task-scheduling'] || 'priority'}`);
|
|
1145
|
+
console.log(` • Load Balancing: ${flags['load-balancing'] || 'work-stealing'}`);
|
|
1146
|
+
console.log(` • Fault Tolerance: ${flags['fault-tolerance'] || 'retry'}`);
|
|
1147
|
+
console.log(` • Communication: ${flags.communication || 'event-driven'}`);
|
|
1148
|
+
console.log('⚠️ DRY RUN - Advanced Swarm Configuration');
|
|
1149
|
+
return;
|
|
1150
|
+
}
|
|
1151
|
+
// For actual execution in npm context, try to find and run swarm-demo.ts
|
|
1152
|
+
try {
|
|
1153
|
+
const path = await import("path");
|
|
1154
|
+
const { fileURLToPath } = await import("url");
|
|
1155
|
+
const fs = await import("fs");
|
|
1156
|
+
const { spawn } = await import("child_process");
|
|
1157
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
1158
|
+
const __dirname = path.dirname(__filename);
|
|
1159
|
+
// Look for swarm-demo.ts in the package
|
|
1160
|
+
const possiblePaths = [
|
|
1161
|
+
path.join(__dirname, '../../../swarm-demo.ts'),
|
|
1162
|
+
path.join(__dirname, '../../swarm-demo.ts')
|
|
1163
|
+
];
|
|
1164
|
+
let swarmDemoPath = null;
|
|
1165
|
+
for (const p of possiblePaths){
|
|
1166
|
+
if (fs.existsSync(p)) {
|
|
1167
|
+
swarmDemoPath = p;
|
|
1168
|
+
break;
|
|
1169
|
+
}
|
|
1170
|
+
}
|
|
1171
|
+
if (swarmDemoPath && Deno) {
|
|
1172
|
+
// Run swarm-demo.ts directly with Deno
|
|
1173
|
+
const swarmArgs = [
|
|
1174
|
+
objective
|
|
1175
|
+
];
|
|
1176
|
+
for (const [key, value] of Object.entries(flags || {})){
|
|
1177
|
+
swarmArgs.push(`--${key}`);
|
|
1178
|
+
if (value !== true) {
|
|
1179
|
+
swarmArgs.push(String(value));
|
|
1180
|
+
}
|
|
1181
|
+
}
|
|
1182
|
+
console.log('🚀 Starting advanced swarm execution...');
|
|
1183
|
+
const swarmProcess = spawn('node', [
|
|
1184
|
+
swarmDemoPath,
|
|
1185
|
+
...swarmArgs
|
|
1186
|
+
], {
|
|
1187
|
+
stdio: 'inherit'
|
|
1188
|
+
});
|
|
1189
|
+
swarmProcess.on('error', (err)=>{
|
|
1190
|
+
console.error('❌ Failed to launch swarm:', err.message);
|
|
1191
|
+
});
|
|
1192
|
+
swarmProcess.on('exit', (code)=>{
|
|
1193
|
+
if (code !== 0) {
|
|
1194
|
+
console.error(`❌ Swarm exited with code ${code}`);
|
|
1195
|
+
}
|
|
1196
|
+
});
|
|
1197
|
+
return;
|
|
1198
|
+
}
|
|
1199
|
+
} catch (e) {
|
|
1200
|
+
// Fallback to basic message if can't run swarm-demo.ts
|
|
1201
|
+
}
|
|
1202
|
+
// Try to use Claude wrapper approach like SPARC does
|
|
1203
|
+
try {
|
|
1204
|
+
const { execSync } = await import("child_process");
|
|
1205
|
+
// Check if claude command exists
|
|
1206
|
+
try {
|
|
1207
|
+
execSync('which claude', {
|
|
1208
|
+
stdio: 'ignore'
|
|
1209
|
+
});
|
|
1210
|
+
} catch (e) {
|
|
1211
|
+
// Claude not found, show fallback message
|
|
1212
|
+
console.log(`✅ Swarm initialized with ID: ${swarmId}`);
|
|
1213
|
+
console.log('\n⚠️ Note: Advanced swarm features require Claude or local installation.');
|
|
1214
|
+
console.log('Install Claude: https://claude.ai/code');
|
|
1215
|
+
console.log('Or install locally: npm install -g claude-flow@latest');
|
|
1216
|
+
console.log('\nThe swarm system would coordinate the following:');
|
|
1217
|
+
console.log('1. Agent spawning and task distribution');
|
|
1218
|
+
console.log('2. Parallel execution of subtasks');
|
|
1219
|
+
console.log('3. Memory sharing between agents');
|
|
1220
|
+
console.log('4. Progress monitoring and reporting');
|
|
1221
|
+
console.log('5. Result aggregation and quality checks');
|
|
1222
|
+
return;
|
|
1223
|
+
}
|
|
1224
|
+
// Claude is available, use it to run swarm
|
|
1225
|
+
console.log('🚀 Launching swarm via Claude wrapper...');
|
|
1226
|
+
if (flags.sparc !== false) {
|
|
1227
|
+
console.log('🧪 SPARC methodology enabled - using full TDD workflow');
|
|
1228
|
+
}
|
|
1229
|
+
// Build the prompt for Claude using SPARC methodology
|
|
1230
|
+
const enableSparc = flags.sparc !== false;
|
|
1231
|
+
const swarmPrompt = `Execute a swarm coordination task using ${enableSparc ? 'the full SPARC methodology' : 'standard approach'}:
|
|
1369
1232
|
|
|
1370
1233
|
OBJECTIVE: ${objective}
|
|
1371
1234
|
|
|
@@ -1377,9 +1240,7 @@ CONFIGURATION:
|
|
|
1377
1240
|
- Quality Threshold: ${flags['quality-threshold'] || 0.8}
|
|
1378
1241
|
${enableSparc ? '- SPARC Enabled: YES - Use full Specification, Pseudocode, Architecture, Refinement (TDD), Completion methodology' : ''}
|
|
1379
1242
|
|
|
1380
|
-
${
|
|
1381
|
-
enableSparc
|
|
1382
|
-
? `
|
|
1243
|
+
${enableSparc ? `
|
|
1383
1244
|
SPARC METHODOLOGY REQUIREMENTS:
|
|
1384
1245
|
|
|
1385
1246
|
1. SPECIFICATION PHASE:
|
|
@@ -1411,9 +1272,7 @@ SPARC METHODOLOGY REQUIREMENTS:
|
|
|
1411
1272
|
- Create comprehensive documentation
|
|
1412
1273
|
- Perform end-to-end testing
|
|
1413
1274
|
- Validate against original requirements
|
|
1414
|
-
`
|
|
1415
|
-
: ''
|
|
1416
|
-
}
|
|
1275
|
+
` : ''}
|
|
1417
1276
|
|
|
1418
1277
|
EXECUTION APPROACH:
|
|
1419
1278
|
1. Analyze the objective and break it down into specific tasks
|
|
@@ -1436,62 +1295,56 @@ IMPORTANT:
|
|
|
1436
1295
|
- Make the code production-ready, not just examples
|
|
1437
1296
|
|
|
1438
1297
|
Begin execution now. Create all necessary files and provide a complete, working solution.`;
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1298
|
+
// Execute Claude non-interactively by piping the prompt
|
|
1299
|
+
const { spawn } = await import("child_process");
|
|
1300
|
+
const claudeArgs = [];
|
|
1301
|
+
// Add auto-permission flag by default for swarm mode (unless explicitly disabled)
|
|
1302
|
+
if (flags['dangerously-skip-permissions'] !== false && !flags['no-auto-permissions']) {
|
|
1303
|
+
claudeArgs.push('--dangerously-skip-permissions');
|
|
1304
|
+
}
|
|
1305
|
+
// Spawn claude process
|
|
1306
|
+
const claudeProcess = spawn('claude', claudeArgs, {
|
|
1307
|
+
stdio: [
|
|
1308
|
+
'pipe',
|
|
1309
|
+
'inherit',
|
|
1310
|
+
'inherit'
|
|
1311
|
+
],
|
|
1312
|
+
shell: false
|
|
1313
|
+
});
|
|
1314
|
+
// Write the prompt to stdin and close it
|
|
1315
|
+
claudeProcess.stdin.write(swarmPrompt);
|
|
1316
|
+
claudeProcess.stdin.end();
|
|
1317
|
+
// Wait for the process to complete
|
|
1318
|
+
await new Promise((resolve, reject)=>{
|
|
1319
|
+
claudeProcess.on('close', (code)=>{
|
|
1320
|
+
if (code === 0) {
|
|
1321
|
+
resolve();
|
|
1322
|
+
} else {
|
|
1323
|
+
reject(new Error(`Claude process exited with code ${code}`));
|
|
1324
|
+
}
|
|
1325
|
+
});
|
|
1326
|
+
claudeProcess.on('error', (err)=>{
|
|
1327
|
+
reject(err);
|
|
1328
|
+
});
|
|
1329
|
+
});
|
|
1330
|
+
} catch (error) {
|
|
1331
|
+
// Fallback if Claude execution fails
|
|
1332
|
+
console.log(`✅ Swarm initialized with ID: ${swarmId}`);
|
|
1333
|
+
console.log('\n⚠️ Note: Advanced swarm features require Claude or local installation.');
|
|
1334
|
+
console.log('Install Claude: https://claude.ai/code');
|
|
1335
|
+
console.log('Or install locally: npm install -g claude-flow@latest');
|
|
1336
|
+
console.log('\nThe swarm system would coordinate the following:');
|
|
1337
|
+
console.log('1. Agent spawning and task distribution');
|
|
1338
|
+
console.log('2. Parallel execution of subtasks');
|
|
1339
|
+
console.log('3. Memory sharing between agents');
|
|
1340
|
+
console.log('4. Progress monitoring and reporting');
|
|
1341
|
+
console.log('5. Result aggregation and quality checks');
|
|
1467
1342
|
}
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
});
|
|
1474
|
-
} catch (error) {
|
|
1475
|
-
// Fallback if Claude execution fails
|
|
1476
|
-
console.log(`✅ Swarm initialized with ID: ${swarmId}`);
|
|
1477
|
-
console.log('\n⚠️ Note: Advanced swarm features require Claude or local installation.');
|
|
1478
|
-
console.log('Install Claude: https://claude.ai/code');
|
|
1479
|
-
console.log('Or install locally: npm install -g claude-flow@latest');
|
|
1480
|
-
console.log('\nThe swarm system would coordinate the following:');
|
|
1481
|
-
console.log('1. Agent spawning and task distribution');
|
|
1482
|
-
console.log('2. Parallel execution of subtasks');
|
|
1483
|
-
console.log('3. Memory sharing between agents');
|
|
1484
|
-
console.log('4. Progress monitoring and reporting');
|
|
1485
|
-
console.log('5. Result aggregation and quality checks');
|
|
1486
|
-
}
|
|
1487
|
-
|
|
1488
|
-
return;
|
|
1489
|
-
}
|
|
1490
|
-
|
|
1491
|
-
console.error('Swarm command error:', error);
|
|
1492
|
-
|
|
1493
|
-
// Fallback to comprehensive help if there's an import error
|
|
1494
|
-
console.log(`
|
|
1343
|
+
return;
|
|
1344
|
+
}
|
|
1345
|
+
console.error('Swarm command error:', error);
|
|
1346
|
+
// Fallback to comprehensive help if there's an import error
|
|
1347
|
+
console.log(`
|
|
1495
1348
|
🐝 Claude Flow Advanced Swarm System
|
|
1496
1349
|
|
|
1497
1350
|
USAGE:
|
|
@@ -1568,48 +1421,40 @@ ADVANCED OPTIONS:
|
|
|
1568
1421
|
For complete documentation and examples:
|
|
1569
1422
|
https://github.com/ruvnet/claude-code-flow/docs/swarm.md
|
|
1570
1423
|
`);
|
|
1571
|
-
|
|
1424
|
+
}
|
|
1572
1425
|
}
|
|
1573
|
-
|
|
1574
1426
|
// Function to create swarm files directly
|
|
1575
1427
|
async function createSwarmFiles(objective, flags) {
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
await fs.promises.mkdir(apiDir, { recursive: true });
|
|
1607
|
-
|
|
1608
|
-
console.log(`\n🏗️ Creating REST API...`);
|
|
1609
|
-
console.log(` 🤖 Agent developer-1: Creating server implementation`);
|
|
1610
|
-
|
|
1611
|
-
// Create server.js
|
|
1612
|
-
const serverCode = `const express = require('express');
|
|
1428
|
+
const fs = await import("fs");
|
|
1429
|
+
const path = await import("path");
|
|
1430
|
+
const swarmId = `swarm_${Math.random().toString(36).substring(2, 11)}_${Math.random().toString(36).substring(2, 11)}`;
|
|
1431
|
+
console.log(`🐝 Swarm Execution Started: ${swarmId}`);
|
|
1432
|
+
console.log(`📋 Objective: ${objective}`);
|
|
1433
|
+
console.log(`🎯 Strategy: ${flags.strategy || 'auto'}`);
|
|
1434
|
+
// Extract target directory from objective
|
|
1435
|
+
const targetMatch = objective.match(/in\s+([^\s]+)\/?$/i);
|
|
1436
|
+
let targetDir = targetMatch ? targetMatch[1] : 'output';
|
|
1437
|
+
// Resolve relative paths
|
|
1438
|
+
if (!targetDir.startsWith('/')) {
|
|
1439
|
+
targetDir = path.join(process.cwd(), targetDir);
|
|
1440
|
+
}
|
|
1441
|
+
console.log(`📁 Target directory: ${targetDir}`);
|
|
1442
|
+
// Ensure target directory exists
|
|
1443
|
+
await fs.promises.mkdir(targetDir, {
|
|
1444
|
+
recursive: true
|
|
1445
|
+
});
|
|
1446
|
+
// Determine what to build based on objective
|
|
1447
|
+
const isRestAPI = objective.toLowerCase().includes('rest api') || objective.toLowerCase().includes('api');
|
|
1448
|
+
if (isRestAPI) {
|
|
1449
|
+
// Create REST API
|
|
1450
|
+
const apiDir = path.join(targetDir, 'rest-api');
|
|
1451
|
+
await fs.promises.mkdir(apiDir, {
|
|
1452
|
+
recursive: true
|
|
1453
|
+
});
|
|
1454
|
+
console.log(`\n🏗️ Creating REST API...`);
|
|
1455
|
+
console.log(` 🤖 Agent developer-1: Creating server implementation`);
|
|
1456
|
+
// Create server.js
|
|
1457
|
+
const serverCode = `const express = require('express');
|
|
1613
1458
|
const app = express();
|
|
1614
1459
|
const port = process.env.PORT || 3000;
|
|
1615
1460
|
|
|
@@ -1664,47 +1509,45 @@ app.listen(port, () => {
|
|
|
1664
1509
|
|
|
1665
1510
|
module.exports = app;
|
|
1666
1511
|
`;
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
// Create README
|
|
1707
|
-
const readme = `# REST API
|
|
1512
|
+
await fs.promises.writeFile(path.join(apiDir, 'server.js'), serverCode);
|
|
1513
|
+
console.log(` ✅ Created: server.js`);
|
|
1514
|
+
// Create package.json
|
|
1515
|
+
const packageJson = {
|
|
1516
|
+
name: 'rest-api',
|
|
1517
|
+
version: '1.0.0',
|
|
1518
|
+
description: 'REST API created by Claude Flow Swarm',
|
|
1519
|
+
main: 'server.js',
|
|
1520
|
+
scripts: {
|
|
1521
|
+
start: 'node server.js',
|
|
1522
|
+
dev: 'nodemon server.js',
|
|
1523
|
+
test: 'jest'
|
|
1524
|
+
},
|
|
1525
|
+
keywords: [
|
|
1526
|
+
'rest',
|
|
1527
|
+
'api',
|
|
1528
|
+
'swarm',
|
|
1529
|
+
'claude-flow'
|
|
1530
|
+
],
|
|
1531
|
+
author: 'Claude Flow Swarm',
|
|
1532
|
+
license: 'MIT',
|
|
1533
|
+
dependencies: {
|
|
1534
|
+
express: '^4.18.2'
|
|
1535
|
+
},
|
|
1536
|
+
devDependencies: {
|
|
1537
|
+
nodemon: '^3.0.1',
|
|
1538
|
+
jest: '^29.7.0',
|
|
1539
|
+
supertest: '^6.3.3'
|
|
1540
|
+
},
|
|
1541
|
+
swarmMetadata: {
|
|
1542
|
+
swarmId,
|
|
1543
|
+
strategy: flags.strategy || 'development',
|
|
1544
|
+
created: new Date().toISOString()
|
|
1545
|
+
}
|
|
1546
|
+
};
|
|
1547
|
+
await fs.promises.writeFile(path.join(apiDir, 'package.json'), JSON.stringify(packageJson, null, 2));
|
|
1548
|
+
console.log(` ✅ Created: package.json`);
|
|
1549
|
+
// Create README
|
|
1550
|
+
const readme = `# REST API
|
|
1708
1551
|
|
|
1709
1552
|
This REST API was created by the Claude Flow Swarm system.
|
|
1710
1553
|
|
|
@@ -1736,18 +1579,15 @@ npm start
|
|
|
1736
1579
|
---
|
|
1737
1580
|
Created by Claude Flow Swarm
|
|
1738
1581
|
`;
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
console.log(`\n🏗️ Creating application...`);
|
|
1749
|
-
|
|
1750
|
-
const appCode = `// Application created by Claude Flow Swarm
|
|
1582
|
+
await fs.promises.writeFile(path.join(apiDir, 'README.md'), readme);
|
|
1583
|
+
console.log(` ✅ Created: README.md`);
|
|
1584
|
+
console.log(`\n✅ Swarm completed successfully!`);
|
|
1585
|
+
console.log(`📁 Files created in: ${apiDir}`);
|
|
1586
|
+
console.log(`🆔 Swarm ID: ${swarmId}`);
|
|
1587
|
+
} else {
|
|
1588
|
+
// Create generic application
|
|
1589
|
+
console.log(`\n🏗️ Creating application...`);
|
|
1590
|
+
const appCode = `// Application created by Claude Flow Swarm
|
|
1751
1591
|
// Objective: ${objective}
|
|
1752
1592
|
// Swarm ID: ${swarmId}
|
|
1753
1593
|
|
|
@@ -1758,43 +1598,34 @@ function main() {
|
|
|
1758
1598
|
|
|
1759
1599
|
main();
|
|
1760
1600
|
`;
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
);
|
|
1784
|
-
console.log(` ✅ Created: package.json`);
|
|
1785
|
-
|
|
1786
|
-
console.log(`\n✅ Swarm completed successfully!`);
|
|
1787
|
-
console.log(`📁 Files created in: ${targetDir}`);
|
|
1788
|
-
console.log(`🆔 Swarm ID: ${swarmId}`);
|
|
1789
|
-
}
|
|
1601
|
+
await fs.promises.writeFile(path.join(targetDir, 'app.js'), appCode);
|
|
1602
|
+
console.log(` ✅ Created: app.js`);
|
|
1603
|
+
const packageJson = {
|
|
1604
|
+
name: 'swarm-app',
|
|
1605
|
+
version: '1.0.0',
|
|
1606
|
+
description: `Application created by Claude Flow Swarm: ${objective}`,
|
|
1607
|
+
main: 'app.js',
|
|
1608
|
+
scripts: {
|
|
1609
|
+
start: 'node app.js'
|
|
1610
|
+
},
|
|
1611
|
+
swarmMetadata: {
|
|
1612
|
+
swarmId,
|
|
1613
|
+
objective,
|
|
1614
|
+
created: new Date().toISOString()
|
|
1615
|
+
}
|
|
1616
|
+
};
|
|
1617
|
+
await fs.promises.writeFile(path.join(targetDir, 'package.json'), JSON.stringify(packageJson, null, 2));
|
|
1618
|
+
console.log(` ✅ Created: package.json`);
|
|
1619
|
+
console.log(`\n✅ Swarm completed successfully!`);
|
|
1620
|
+
console.log(`📁 Files created in: ${targetDir}`);
|
|
1621
|
+
console.log(`🆔 Swarm ID: ${swarmId}`);
|
|
1622
|
+
}
|
|
1790
1623
|
}
|
|
1791
|
-
|
|
1792
1624
|
/**
|
|
1793
1625
|
* Get strategy-specific guidance for swarm execution
|
|
1794
|
-
*/
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
auto: `🤖 AUTO STRATEGY - INTELLIGENT TASK ANALYSIS:
|
|
1626
|
+
*/ function getStrategyGuidance(strategy, objective) {
|
|
1627
|
+
const guidanceMap = {
|
|
1628
|
+
auto: `🤖 AUTO STRATEGY - INTELLIGENT TASK ANALYSIS:
|
|
1798
1629
|
The swarm will analyze "${objective}" and automatically determine the best approach.
|
|
1799
1630
|
|
|
1800
1631
|
ANALYSIS APPROACH:
|
|
@@ -1808,8 +1639,7 @@ MCP TOOL PATTERN:
|
|
|
1808
1639
|
- Use task_create to build a hierarchical task structure
|
|
1809
1640
|
- Spawn agents with agent_spawn based on detected requirements
|
|
1810
1641
|
- Monitor with swarm_monitor and adjust strategy as needed`,
|
|
1811
|
-
|
|
1812
|
-
research: `🔬 RESEARCH STRATEGY - INFORMATION GATHERING & ANALYSIS:
|
|
1642
|
+
research: `🔬 RESEARCH STRATEGY - INFORMATION GATHERING & ANALYSIS:
|
|
1813
1643
|
Optimized for: "${objective}"
|
|
1814
1644
|
|
|
1815
1645
|
RESEARCH PHASES:
|
|
@@ -1829,8 +1659,7 @@ MCP TOOL USAGE:
|
|
|
1829
1659
|
- memory_search: Find related information across research
|
|
1830
1660
|
- agent_communicate: Share discoveries between researchers
|
|
1831
1661
|
- task_create: Break research into focused sub-investigations`,
|
|
1832
|
-
|
|
1833
|
-
development: `💻 DEVELOPMENT STRATEGY - SOFTWARE CREATION:
|
|
1662
|
+
development: `💻 DEVELOPMENT STRATEGY - SOFTWARE CREATION:
|
|
1834
1663
|
Building: "${objective}"
|
|
1835
1664
|
|
|
1836
1665
|
DEVELOPMENT WORKFLOW:
|
|
@@ -1852,8 +1681,7 @@ MCP TOOL USAGE:
|
|
|
1852
1681
|
- task_create: Create implementation tasks with dependencies
|
|
1853
1682
|
- agent_assign: Assign specific components to developers
|
|
1854
1683
|
- swarm_monitor: Track build progress and blockers`,
|
|
1855
|
-
|
|
1856
|
-
analysis: `📊 ANALYSIS STRATEGY - DATA EXAMINATION:
|
|
1684
|
+
analysis: `📊 ANALYSIS STRATEGY - DATA EXAMINATION:
|
|
1857
1685
|
Analyzing: "${objective}"
|
|
1858
1686
|
|
|
1859
1687
|
ANALYSIS FRAMEWORK:
|
|
@@ -1875,8 +1703,7 @@ MCP TOOL USAGE:
|
|
|
1875
1703
|
- memory_retrieve: Access historical analysis
|
|
1876
1704
|
- task_create: Define analysis pipelines
|
|
1877
1705
|
- agent_coordinate: Sync analysis phases`,
|
|
1878
|
-
|
|
1879
|
-
testing: `🧪 TESTING STRATEGY - QUALITY ASSURANCE:
|
|
1706
|
+
testing: `🧪 TESTING STRATEGY - QUALITY ASSURANCE:
|
|
1880
1707
|
Testing: "${objective}"
|
|
1881
1708
|
|
|
1882
1709
|
TESTING PHASES:
|
|
@@ -1898,8 +1725,7 @@ MCP TOOL USAGE:
|
|
|
1898
1725
|
- memory_store: Save test results and bug reports
|
|
1899
1726
|
- agent_communicate: Report bugs to developers
|
|
1900
1727
|
- swarm_monitor: Track testing coverage and progress`,
|
|
1901
|
-
|
|
1902
|
-
optimization: `⚡ OPTIMIZATION STRATEGY - PERFORMANCE IMPROVEMENT:
|
|
1728
|
+
optimization: `⚡ OPTIMIZATION STRATEGY - PERFORMANCE IMPROVEMENT:
|
|
1903
1729
|
Optimizing: "${objective}"
|
|
1904
1730
|
|
|
1905
1731
|
OPTIMIZATION PROCESS:
|
|
@@ -1921,8 +1747,7 @@ MCP TOOL USAGE:
|
|
|
1921
1747
|
- task_create: Create optimization tasks by priority
|
|
1922
1748
|
- swarm_monitor: Track performance improvements
|
|
1923
1749
|
- agent_communicate: Coordinate optimization efforts`,
|
|
1924
|
-
|
|
1925
|
-
maintenance: `🔧 MAINTENANCE STRATEGY - SYSTEM UPKEEP:
|
|
1750
|
+
maintenance: `🔧 MAINTENANCE STRATEGY - SYSTEM UPKEEP:
|
|
1926
1751
|
Maintaining: "${objective}"
|
|
1927
1752
|
|
|
1928
1753
|
MAINTENANCE WORKFLOW:
|
|
@@ -1943,18 +1768,15 @@ MCP TOOL USAGE:
|
|
|
1943
1768
|
- memory_retrieve: Access system history
|
|
1944
1769
|
- task_create: Schedule maintenance tasks
|
|
1945
1770
|
- agent_assign: Delegate specific updates
|
|
1946
|
-
- memory_store: Document all changes
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
return guidanceMap[strategy] || guidanceMap['auto'];
|
|
1771
|
+
- memory_store: Document all changes`
|
|
1772
|
+
};
|
|
1773
|
+
return guidanceMap[strategy] || guidanceMap['auto'];
|
|
1950
1774
|
}
|
|
1951
|
-
|
|
1952
1775
|
/**
|
|
1953
1776
|
* Get mode-specific guidance for coordination
|
|
1954
|
-
*/
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
centralized: `🎯 CENTRALIZED MODE - SINGLE COORDINATOR:
|
|
1777
|
+
*/ function getModeGuidance(mode) {
|
|
1778
|
+
const modeMap = {
|
|
1779
|
+
centralized: `🎯 CENTRALIZED MODE - SINGLE COORDINATOR:
|
|
1958
1780
|
All decisions flow through one coordinator agent.
|
|
1959
1781
|
|
|
1960
1782
|
COORDINATION PATTERN:
|
|
@@ -1974,8 +1796,7 @@ BEST FOR:
|
|
|
1974
1796
|
- Small to medium projects
|
|
1975
1797
|
- Well-defined objectives
|
|
1976
1798
|
- Clear task dependencies`,
|
|
1977
|
-
|
|
1978
|
-
distributed: `🌐 DISTRIBUTED MODE - MULTIPLE COORDINATORS:
|
|
1799
|
+
distributed: `🌐 DISTRIBUTED MODE - MULTIPLE COORDINATORS:
|
|
1979
1800
|
Multiple coordinators share responsibility by domain.
|
|
1980
1801
|
|
|
1981
1802
|
COORDINATION PATTERN:
|
|
@@ -1996,8 +1817,7 @@ BEST FOR:
|
|
|
1996
1817
|
- Multiple workstreams
|
|
1997
1818
|
- Complex systems
|
|
1998
1819
|
- High availability needs`,
|
|
1999
|
-
|
|
2000
|
-
hierarchical: `🏗️ HIERARCHICAL MODE - TREE STRUCTURE:
|
|
1820
|
+
hierarchical: `🏗️ HIERARCHICAL MODE - TREE STRUCTURE:
|
|
2001
1821
|
Agents organized in management layers.
|
|
2002
1822
|
|
|
2003
1823
|
COORDINATION PATTERN:
|
|
@@ -2018,8 +1838,7 @@ BEST FOR:
|
|
|
2018
1838
|
- Multi-team efforts
|
|
2019
1839
|
- Complex hierarchies
|
|
2020
1840
|
- Phased deliveries`,
|
|
2021
|
-
|
|
2022
|
-
mesh: `🔗 MESH MODE - PEER-TO-PEER:
|
|
1841
|
+
mesh: `🔗 MESH MODE - PEER-TO-PEER:
|
|
2023
1842
|
Agents coordinate directly without central authority.
|
|
2024
1843
|
|
|
2025
1844
|
COORDINATION PATTERN:
|
|
@@ -2040,8 +1859,7 @@ BEST FOR:
|
|
|
2040
1859
|
- Exploratory work
|
|
2041
1860
|
- Innovation tasks
|
|
2042
1861
|
- Small expert teams`,
|
|
2043
|
-
|
|
2044
|
-
hybrid: `🎨 HYBRID MODE - MIXED STRATEGIES:
|
|
1862
|
+
hybrid: `🎨 HYBRID MODE - MIXED STRATEGIES:
|
|
2045
1863
|
Combine different coordination patterns as needed.
|
|
2046
1864
|
|
|
2047
1865
|
COORDINATION PATTERN:
|
|
@@ -2060,18 +1878,15 @@ BEST FOR:
|
|
|
2060
1878
|
- Complex projects
|
|
2061
1879
|
- Uncertain requirements
|
|
2062
1880
|
- Long-term efforts
|
|
2063
|
-
- Diverse objectives
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
return modeMap[mode] || modeMap['centralized'];
|
|
1881
|
+
- Diverse objectives`
|
|
1882
|
+
};
|
|
1883
|
+
return modeMap[mode] || modeMap['centralized'];
|
|
2067
1884
|
}
|
|
2068
|
-
|
|
2069
1885
|
/**
|
|
2070
1886
|
* Get agent recommendations based on strategy
|
|
2071
|
-
*/
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
auto: `
|
|
1887
|
+
*/ function getAgentRecommendations(strategy, maxAgents, objective) {
|
|
1888
|
+
const recommendations = {
|
|
1889
|
+
auto: `
|
|
2075
1890
|
🤖 RECOMMENDED AGENT COMPOSITION (Auto-detected):
|
|
2076
1891
|
⚡ SPAWN ALL AGENTS IN ONE BATCH - Copy this entire block:
|
|
2077
1892
|
|
|
@@ -2090,8 +1905,7 @@ function getAgentRecommendations(strategy, maxAgents, objective) {
|
|
|
2090
1905
|
{"id": "4", "content": "Spawn additional agents as needed", "status": "pending", "priority": "medium"}
|
|
2091
1906
|
]}
|
|
2092
1907
|
\`\`\``,
|
|
2093
|
-
|
|
2094
|
-
research: `
|
|
1908
|
+
research: `
|
|
2095
1909
|
🔬 RECOMMENDED RESEARCH AGENTS:
|
|
2096
1910
|
⚡ SPAWN ALL AGENTS IN ONE BATCH - Copy this entire block:
|
|
2097
1911
|
|
|
@@ -2115,8 +1929,7 @@ function getAgentRecommendations(strategy, maxAgents, objective) {
|
|
|
2115
1929
|
{"id": "5", "content": "Compile and synthesize insights", "status": "pending", "priority": "medium"}
|
|
2116
1930
|
]}
|
|
2117
1931
|
\`\`\``,
|
|
2118
|
-
|
|
2119
|
-
development: `
|
|
1932
|
+
development: `
|
|
2120
1933
|
💻 RECOMMENDED DEVELOPMENT AGENTS:
|
|
2121
1934
|
⚡ SPAWN ALL AGENTS IN ONE BATCH - Copy this entire block:
|
|
2122
1935
|
|
|
@@ -2140,8 +1953,7 @@ function getAgentRecommendations(strategy, maxAgents, objective) {
|
|
|
2140
1953
|
{"id": "5", "content": "Create comprehensive tests", "status": "pending", "priority": "medium"}
|
|
2141
1954
|
]}
|
|
2142
1955
|
\`\`\``,
|
|
2143
|
-
|
|
2144
|
-
analysis: `
|
|
1956
|
+
analysis: `
|
|
2145
1957
|
📊 RECOMMENDED ANALYSIS AGENTS:
|
|
2146
1958
|
⚡ SPAWN ALL AGENTS IN ONE BATCH - Copy this entire block:
|
|
2147
1959
|
|
|
@@ -2165,8 +1977,7 @@ function getAgentRecommendations(strategy, maxAgents, objective) {
|
|
|
2165
1977
|
{"id": "5", "content": "Generate business insights", "status": "pending", "priority": "medium"}
|
|
2166
1978
|
]}
|
|
2167
1979
|
\`\`\``,
|
|
2168
|
-
|
|
2169
|
-
testing: `
|
|
1980
|
+
testing: `
|
|
2170
1981
|
🧪 RECOMMENDED TESTING AGENTS:
|
|
2171
1982
|
⚡ SPAWN ALL AGENTS IN ONE BATCH - Copy this entire block:
|
|
2172
1983
|
|
|
@@ -2190,8 +2001,7 @@ function getAgentRecommendations(strategy, maxAgents, objective) {
|
|
|
2190
2001
|
{"id": "5", "content": "Execute security audit", "status": "pending", "priority": "high"}
|
|
2191
2002
|
]}
|
|
2192
2003
|
\`\`\``,
|
|
2193
|
-
|
|
2194
|
-
optimization: `
|
|
2004
|
+
optimization: `
|
|
2195
2005
|
⚡ RECOMMENDED OPTIMIZATION AGENTS:
|
|
2196
2006
|
⚡ SPAWN ALL AGENTS IN ONE BATCH - Copy this entire block:
|
|
2197
2007
|
|
|
@@ -2215,8 +2025,7 @@ function getAgentRecommendations(strategy, maxAgents, objective) {
|
|
|
2215
2025
|
{"id": "5", "content": "Tune system parameters", "status": "pending", "priority": "medium"}
|
|
2216
2026
|
]}
|
|
2217
2027
|
\`\`\``,
|
|
2218
|
-
|
|
2219
|
-
maintenance: `
|
|
2028
|
+
maintenance: `
|
|
2220
2029
|
🔧 RECOMMENDED MAINTENANCE AGENTS:
|
|
2221
2030
|
⚡ SPAWN ALL AGENTS IN ONE BATCH - Copy this entire block:
|
|
2222
2031
|
|
|
@@ -2239,39 +2048,35 @@ function getAgentRecommendations(strategy, maxAgents, objective) {
|
|
|
2239
2048
|
{"id": "4", "content": "Run regression tests", "status": "pending", "priority": "high"},
|
|
2240
2049
|
{"id": "5", "content": "Update documentation", "status": "pending", "priority": "medium"}
|
|
2241
2050
|
]}
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
return recommendations[strategy] || recommendations['auto'];
|
|
2051
|
+
\`\`\``
|
|
2052
|
+
};
|
|
2053
|
+
return recommendations[strategy] || recommendations['auto'];
|
|
2246
2054
|
}
|
|
2247
|
-
|
|
2248
2055
|
// Allow direct execution
|
|
2249
2056
|
if (import.meta.main) {
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
args.push(arg);
|
|
2057
|
+
// When called directly as a script, parse all arguments
|
|
2058
|
+
const args = [];
|
|
2059
|
+
const flags = {};
|
|
2060
|
+
// Parse arguments and flags
|
|
2061
|
+
for(let i = 0; i < args.length; i++){
|
|
2062
|
+
const arg = args[i];
|
|
2063
|
+
if (arg.startsWith('--')) {
|
|
2064
|
+
const flagName = arg.substring(2);
|
|
2065
|
+
const nextArg = args[i + 1];
|
|
2066
|
+
if (nextArg && !nextArg.startsWith('--')) {
|
|
2067
|
+
flags[flagName] = nextArg;
|
|
2068
|
+
i++; // Skip the next argument
|
|
2069
|
+
} else {
|
|
2070
|
+
flags[flagName] = true;
|
|
2071
|
+
}
|
|
2072
|
+
} else {
|
|
2073
|
+
args.push(arg);
|
|
2074
|
+
}
|
|
2269
2075
|
}
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
await swarmCommand([objective], flags);
|
|
2076
|
+
// The objective is all non-flag arguments joined
|
|
2077
|
+
const objective = args.join(' ');
|
|
2078
|
+
// Execute the swarm command
|
|
2079
|
+
await swarmCommand([
|
|
2080
|
+
objective
|
|
2081
|
+
], flags);
|
|
2277
2082
|
}
|