claude-flow-novice 1.3.0 → 1.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-flow-novice/preferences/generation.json +147 -0
- package/.claude-flow-novice/preferences/language-configs/javascript.json +51 -0
- package/.claude-flow-novice/preferences/language-configs/python.json +50 -0
- package/.claude-flow-novice/preferences/language-configs/rust.json +237 -0
- package/.claude-flow-novice/preferences/language-configs/typescript.json +54 -0
- package/.claude-flow-novice/preferences/project-local.json +91 -0
- package/.claude-flow-novice/preferences/resource-delegation.json +120 -0
- package/.claude-flow-novice/preferences/team-shared.json +195 -0
- package/.claude-flow-novice/preferences/user-global.json +247 -0
- package/.claude-flow-novice/templates/claude-md-templates/CLAUDE-JAVASCRIPT.md +769 -0
- package/.claude-flow-novice/templates/claude-md-templates/CLAUDE-PYTHON.md +1214 -0
- package/.claude-flow-novice/templates/claude-md-templates/CLAUDE-RUST.md +475 -0
- package/.claude-flow-novice/templates/claude-md-templates/CLAUDE-TYPESCRIPT.md +851 -0
- package/.claude-flow-novice/templates/claude-md-templates/README.md +263 -0
- package/CLAUDE.md +81 -0
- package/README-NPM.md +0 -0
- package/package.json +11 -7
- package/scripts/build/README.md +167 -0
- package/scripts/build/build-config.js +27 -0
- package/scripts/build/build-prompt-copier.sh +30 -0
- package/scripts/build/performance-monitor.js +869 -0
- package/scripts/build/prepare-publish.js +150 -0
- package/scripts/build/typescript-fixer.js +621 -0
- package/scripts/build/unified-builder.sh +428 -0
- package/scripts/build/update-bin-version.js +32 -0
- package/scripts/dev/README.md +264 -0
- package/scripts/dev/claude-flow-wrapper.sh +35 -0
- package/scripts/dev/claude-monitor.py +419 -0
- package/scripts/dev/claude-sparc.sh +562 -0
- package/scripts/dev/claude-wrapper.sh +17 -0
- package/scripts/dev/demo-phase3-compliance.js +172 -0
- package/scripts/dev/demo-task-system.ts +224 -0
- package/scripts/dev/deployment-validator.js +315 -0
- package/scripts/dev/spawn-claude-terminal.sh +32 -0
- package/scripts/dev/start-portal.sh +506 -0
- package/scripts/dev/start-web-ui.js +15 -0
- package/scripts/dev/stop-portal.sh +311 -0
- package/scripts/dev/validate-examples.ts +288 -0
- package/scripts/dev/validate-phase2.cjs +451 -0
- package/scripts/dev/validate-phase2.js +785 -0
- package/scripts/dev/validate-phase3.cjs +208 -0
- package/scripts/dev/validate-security-remediation.js +1 -0
- package/scripts/legacy/README.md +272 -0
- package/scripts/legacy/batch-fix-ts.sh +54 -0
- package/scripts/legacy/build-migration.sh +105 -0
- package/scripts/legacy/build-monitor.js +209 -0
- package/scripts/legacy/build-with-filter.sh +84 -0
- package/scripts/legacy/build-workaround.sh +71 -0
- package/scripts/legacy/fix-ts-advanced.js +358 -0
- package/scripts/legacy/fix-ts-final.sh +50 -0
- package/scripts/legacy/fix-ts-targeted.sh +49 -0
- package/scripts/legacy/fix-typescript-errors.js +305 -0
- package/scripts/legacy/force-build.sh +63 -0
- package/scripts/legacy/optimize-performance.js +400 -0
- package/scripts/legacy/performance-monitor.js +263 -0
- package/scripts/legacy/performance-monitoring.js +532 -0
- package/scripts/legacy/performance-test-runner.js +645 -0
- package/scripts/legacy/quick-fix-ts.js +281 -0
- package/scripts/legacy/safe-build.sh +63 -0
- package/scripts/migration/README.md +434 -0
- package/scripts/migration/install-arm64.js +78 -0
- package/scripts/migration/install.js +83 -0
- package/scripts/migration/migrate-hooks.js +173 -0
- package/scripts/migration/migration-examples.ts +318 -0
- package/scripts/optimization/build-optimizer.js +438 -0
- package/scripts/optimization/config-validator.js +761 -0
- package/scripts/optimization/test-optimization.js +432 -0
- package/scripts/optimization/unified-activation.js +839 -0
- package/scripts/performance/ACTIVATION_COMMANDS.md +292 -0
- package/scripts/performance/sqlite-enhanced-activation.sh +583 -0
- package/scripts/performance/test-enhanced-backend.sh +504 -0
- package/scripts/performance-test-runner.js +698 -0
- package/scripts/security/README.md +339 -0
- package/scripts/security/install-git-hooks.sh +132 -0
- package/scripts/security/ruv-swarm-safe.js +74 -0
- package/scripts/test/README.md +236 -0
- package/scripts/test/check-links.ts +274 -0
- package/scripts/test/check-performance-regression.ts +168 -0
- package/scripts/test/coverage-report.ts +692 -0
- package/scripts/test/generate-swarm-tests.js +633 -0
- package/scripts/test/integration-test-validation.cjs +253 -0
- package/scripts/test/load-test-swarm.js +576 -0
- package/scripts/test/run-phase3-compliance-tests.js +427 -0
- package/scripts/test/test-batch-tasks.ts +29 -0
- package/scripts/test/test-byzantine-resolution.js +246 -0
- package/scripts/test/test-claude-spawn-options.sh +63 -0
- package/scripts/test/test-cli-wizard.js +331 -0
- package/scripts/test/test-comprehensive.js +401 -0
- package/scripts/test/test-coordination-features.ts +238 -0
- package/scripts/test/test-fallback-systems.js +276 -0
- package/scripts/test/test-init-command.ts +302 -0
- package/scripts/test/test-mcp.ts +251 -0
- package/scripts/test/test-runner.ts +568 -0
- package/scripts/test/test-swarm-integration.sh +92 -0
- package/scripts/test/test-swarm.ts +142 -0
- package/scripts/test/validation-summary.ts +408 -0
- package/scripts/utils/README.md +261 -0
- package/scripts/utils/clean-build-artifacts.sh +94 -0
- package/scripts/utils/cleanup-root.sh +69 -0
- package/scripts/utils/fix-cliffy-imports.js +307 -0
- package/scripts/utils/fix-duplicate-imports.js +114 -0
- package/scripts/utils/fix-error-handling.cjs +70 -0
- package/scripts/utils/fix-import-paths.js +104 -0
- package/scripts/utils/fix-imports.js +116 -0
- package/scripts/utils/fix-shebang.js +78 -0
- package/scripts/utils/fix-test-modules.js +27 -0
- package/scripts/utils/fix-timezone-issue-246.js +200 -0
- package/scripts/utils/fix-ts-comprehensive.py +182 -0
- package/scripts/utils/fix-ts-targeted-batch.js +250 -0
- package/scripts/utils/remove-benchmark-conflicts.sh +140 -0
- package/scripts/utils/simple-test-fixer.js +190 -0
- package/scripts/utils/validate-metrics-structure.cjs +144 -0
- package/scripts/verify-mcp-server.js +86 -0
- package/src/cli/simple-commands/__tests__/agent.test.js +291 -0
- package/src/cli/simple-commands/__tests__/memory.test.js +8 -0
- package/src/cli/simple-commands/__tests__/swarm.test.js +371 -0
- package/src/cli/simple-commands/__tests__/task.test.js +8 -0
- package/src/cli/simple-commands/agent.js +216 -0
- package/src/cli/simple-commands/analysis.js +570 -0
- package/src/cli/simple-commands/automation-executor.js +1603 -0
- package/src/cli/simple-commands/automation.js +627 -0
- package/src/cli/simple-commands/batch-manager.js +338 -0
- package/src/cli/simple-commands/claude-telemetry.js +311 -0
- package/src/cli/simple-commands/claude-track.js +102 -0
- package/src/cli/simple-commands/concurrent-display.js +348 -0
- package/src/cli/simple-commands/config.js +319 -0
- package/src/cli/simple-commands/coordination.js +307 -0
- package/src/cli/simple-commands/enhanced-ui-views.js +654 -0
- package/src/cli/simple-commands/enhanced-webui-complete.js +1038 -0
- package/src/cli/simple-commands/fix-hook-variables.js +363 -0
- package/src/cli/simple-commands/github/gh-coordinator.js +605 -0
- package/src/cli/simple-commands/github/github-api.js +624 -0
- package/src/cli/simple-commands/github/init.js +543 -0
- package/src/cli/simple-commands/github.js +377 -0
- package/src/cli/simple-commands/goal.js +145 -0
- package/src/cli/simple-commands/hive-mind/auto-save-middleware.js +311 -0
- package/src/cli/simple-commands/hive-mind/communication.js +740 -0
- package/src/cli/simple-commands/hive-mind/core.js +1031 -0
- package/src/cli/simple-commands/hive-mind/db-optimizer.js +872 -0
- package/src/cli/simple-commands/hive-mind/mcp-wrapper.js +1364 -0
- package/src/cli/simple-commands/hive-mind/memory.js +1292 -0
- package/src/cli/simple-commands/hive-mind/performance-optimizer.js +618 -0
- package/src/cli/simple-commands/hive-mind/performance-test.js +373 -0
- package/src/cli/simple-commands/hive-mind/queen.js +809 -0
- package/src/cli/simple-commands/hive-mind/session-manager.js +1223 -0
- package/src/cli/simple-commands/hive-mind-optimize.js +361 -0
- package/src/cli/simple-commands/hive-mind-wizard.js +281 -0
- package/src/cli/simple-commands/hive-mind.js +3112 -0
- package/src/cli/simple-commands/hive.js +140 -0
- package/src/cli/simple-commands/hook-safety.js +671 -0
- package/src/cli/simple-commands/hooks.js +1268 -0
- package/src/cli/simple-commands/init/.claude/checkpoints/1756224542.json +7 -0
- package/src/cli/simple-commands/init/.claude/checkpoints/1756224544.json +8 -0
- package/src/cli/simple-commands/init/README.md +106 -0
- package/src/cli/simple-commands/init/VALIDATION_ROLLBACK.md +488 -0
- package/src/cli/simple-commands/init/agent-copier.js +347 -0
- package/src/cli/simple-commands/init/batch-init.js +663 -0
- package/src/cli/simple-commands/init/claude-commands/claude-flow-commands.js +438 -0
- package/src/cli/simple-commands/init/claude-commands/optimized-claude-flow-commands.js +876 -0
- package/src/cli/simple-commands/init/claude-commands/optimized-slash-commands.js +356 -0
- package/src/cli/simple-commands/init/claude-commands/optimized-sparc-commands.js +501 -0
- package/src/cli/simple-commands/init/claude-commands/slash-commands.js +57 -0
- package/src/cli/simple-commands/init/claude-commands/sparc-commands.js +296 -0
- package/src/cli/simple-commands/init/copy-revised-templates.js +175 -0
- package/src/cli/simple-commands/init/executable-wrapper.js +122 -0
- package/src/cli/simple-commands/init/gitignore-updater.js +137 -0
- package/src/cli/simple-commands/init/help.js +110 -0
- package/src/cli/simple-commands/init/hive-mind-init.js +749 -0
- package/src/cli/simple-commands/init/index.js +1953 -0
- package/src/cli/simple-commands/init/performance-monitor.js +344 -0
- package/src/cli/simple-commands/init/rollback/backup-manager.js +542 -0
- package/src/cli/simple-commands/init/rollback/index.js +399 -0
- package/src/cli/simple-commands/init/rollback/recovery-manager.js +778 -0
- package/src/cli/simple-commands/init/rollback/rollback-executor.js +521 -0
- package/src/cli/simple-commands/init/rollback/state-tracker.js +486 -0
- package/src/cli/simple-commands/init/sparc/roo-readme.js +61 -0
- package/src/cli/simple-commands/init/sparc/roomodes-config.js +102 -0
- package/src/cli/simple-commands/init/sparc/workflows.js +40 -0
- package/src/cli/simple-commands/init/sparc-structure.js +68 -0
- package/src/cli/simple-commands/init/template-copier.js +640 -0
- package/src/cli/simple-commands/init/templates/CLAUDE.md +1185 -0
- package/src/cli/simple-commands/init/templates/CLAUDE.md.optimized +265 -0
- package/src/cli/simple-commands/init/templates/claude-flow-universal +81 -0
- package/src/cli/simple-commands/init/templates/claude-flow.bat +18 -0
- package/src/cli/simple-commands/init/templates/claude-flow.ps1 +24 -0
- package/src/cli/simple-commands/init/templates/claude-md.js +1101 -0
- package/src/cli/simple-commands/init/templates/commands/analysis/bottleneck-detect.md +162 -0
- package/src/cli/simple-commands/init/templates/commands/automation/auto-agent.md +122 -0
- package/src/cli/simple-commands/init/templates/commands/coordination/swarm-init.md +85 -0
- package/src/cli/simple-commands/init/templates/commands/github/github-swarm.md +121 -0
- package/src/cli/simple-commands/init/templates/commands/helpers/standard-checkpoint-hooks.sh +179 -0
- package/src/cli/simple-commands/init/templates/commands/hooks/notification.md +113 -0
- package/src/cli/simple-commands/init/templates/commands/hooks/post-command.md +116 -0
- package/src/cli/simple-commands/init/templates/commands/hooks/post-edit.md +117 -0
- package/src/cli/simple-commands/init/templates/commands/hooks/post-task.md +112 -0
- package/src/cli/simple-commands/init/templates/commands/hooks/pre-command.md +113 -0
- package/src/cli/simple-commands/init/templates/commands/hooks/pre-edit.md +113 -0
- package/src/cli/simple-commands/init/templates/commands/hooks/pre-search.md +112 -0
- package/src/cli/simple-commands/init/templates/commands/hooks/pre-task.md +111 -0
- package/src/cli/simple-commands/init/templates/commands/hooks/session-end.md +118 -0
- package/src/cli/simple-commands/init/templates/commands/hooks/session-restore.md +118 -0
- package/src/cli/simple-commands/init/templates/commands/hooks/session-start.md +117 -0
- package/src/cli/simple-commands/init/templates/coordination-md.js +340 -0
- package/src/cli/simple-commands/init/templates/coordination.md +16 -0
- package/src/cli/simple-commands/init/templates/enhanced-templates.js +2347 -0
- package/src/cli/simple-commands/init/templates/github-safe-enhanced.js +331 -0
- package/src/cli/simple-commands/init/templates/github-safe.js +106 -0
- package/src/cli/simple-commands/init/templates/memory-bank-md.js +259 -0
- package/src/cli/simple-commands/init/templates/memory-bank.md +16 -0
- package/src/cli/simple-commands/init/templates/readme-files.js +72 -0
- package/src/cli/simple-commands/init/templates/safe-hook-patterns.js +430 -0
- package/src/cli/simple-commands/init/templates/settings.json +109 -0
- package/src/cli/simple-commands/init/templates/settings.json.enhanced +35 -0
- package/src/cli/simple-commands/init/templates/sparc-modes.js +1401 -0
- package/src/cli/simple-commands/init/templates/verification-claude-md.js +432 -0
- package/src/cli/simple-commands/init/validation/config-validator.js +354 -0
- package/src/cli/simple-commands/init/validation/health-checker.js +599 -0
- package/src/cli/simple-commands/init/validation/index.js +388 -0
- package/src/cli/simple-commands/init/validation/mode-validator.js +387 -0
- package/src/cli/simple-commands/init/validation/post-init-validator.js +390 -0
- package/src/cli/simple-commands/init/validation/pre-init-validator.js +290 -0
- package/src/cli/simple-commands/init/validation/test-runner.js +488 -0
- package/src/cli/simple-commands/init.js +4 -0
- package/src/cli/simple-commands/mcp-health.js +163 -0
- package/src/cli/simple-commands/mcp-integration-layer.js +689 -0
- package/src/cli/simple-commands/mcp.js +420 -0
- package/src/cli/simple-commands/memory-consolidation.js +631 -0
- package/src/cli/simple-commands/memory.js +345 -0
- package/src/cli/simple-commands/migrate-hooks.js +63 -0
- package/src/cli/simple-commands/monitor.js +417 -0
- package/src/cli/simple-commands/neural.js +148 -0
- package/src/cli/simple-commands/pair-autofix-only.js +755 -0
- package/src/cli/simple-commands/pair-basic.js +751 -0
- package/src/cli/simple-commands/pair-old.js +623 -0
- package/src/cli/simple-commands/pair-working.js +849 -0
- package/src/cli/simple-commands/pair.js +849 -0
- package/src/cli/simple-commands/performance-hooks.js +149 -0
- package/src/cli/simple-commands/performance-metrics.js +601 -0
- package/src/cli/simple-commands/process-ui-enhanced.js +821 -0
- package/src/cli/simple-commands/process-ui.js +274 -0
- package/src/cli/simple-commands/realtime-update-system.js +659 -0
- package/src/cli/simple-commands/sparc/architecture.js +1750 -0
- package/src/cli/simple-commands/sparc/commands.js +575 -0
- package/src/cli/simple-commands/sparc/completion.js +1831 -0
- package/src/cli/simple-commands/sparc/coordinator.js +1045 -0
- package/src/cli/simple-commands/sparc/index.js +321 -0
- package/src/cli/simple-commands/sparc/phase-base.js +430 -0
- package/src/cli/simple-commands/sparc/pseudocode.js +984 -0
- package/src/cli/simple-commands/sparc/refinement.js +1856 -0
- package/src/cli/simple-commands/sparc/specification.js +736 -0
- package/src/cli/simple-commands/sparc-modes/architect.js +125 -0
- package/src/cli/simple-commands/sparc-modes/ask.js +126 -0
- package/src/cli/simple-commands/sparc-modes/code.js +148 -0
- package/src/cli/simple-commands/sparc-modes/debug.js +112 -0
- package/src/cli/simple-commands/sparc-modes/devops.js +137 -0
- package/src/cli/simple-commands/sparc-modes/docs-writer.js +38 -0
- package/src/cli/simple-commands/sparc-modes/generic.js +34 -0
- package/src/cli/simple-commands/sparc-modes/index.js +201 -0
- package/src/cli/simple-commands/sparc-modes/integration.js +55 -0
- package/src/cli/simple-commands/sparc-modes/mcp.js +38 -0
- package/src/cli/simple-commands/sparc-modes/monitoring.js +38 -0
- package/src/cli/simple-commands/sparc-modes/optimization.js +38 -0
- package/src/cli/simple-commands/sparc-modes/security-review.js +130 -0
- package/src/cli/simple-commands/sparc-modes/sparc-orchestrator.js +167 -0
- package/src/cli/simple-commands/sparc-modes/spec-pseudocode.js +38 -0
- package/src/cli/simple-commands/sparc-modes/supabase-admin.js +149 -0
- package/src/cli/simple-commands/sparc-modes/swarm.js +436 -0
- package/src/cli/simple-commands/sparc-modes/tdd.js +112 -0
- package/src/cli/simple-commands/sparc-modes/tutorial.js +277 -0
- package/src/cli/simple-commands/sparc.js +530 -0
- package/src/cli/simple-commands/start-ui.js +147 -0
- package/src/cli/simple-commands/start-wrapper.js +285 -0
- package/src/cli/simple-commands/start.js +2 -0
- package/src/cli/simple-commands/status.js +303 -0
- package/src/cli/simple-commands/stream-chain-clean.js +221 -0
- package/src/cli/simple-commands/stream-chain-fixed.js +89 -0
- package/src/cli/simple-commands/stream-chain-real.js +408 -0
- package/src/cli/simple-commands/stream-chain-working.js +323 -0
- package/src/cli/simple-commands/stream-chain.js +491 -0
- package/src/cli/simple-commands/stream-processor.js +340 -0
- package/src/cli/simple-commands/swarm-executor.js +253 -0
- package/src/cli/simple-commands/swarm-metrics-integration.js +371 -0
- package/src/cli/simple-commands/swarm-ui.js +741 -0
- package/src/cli/simple-commands/swarm-webui-integration.js +311 -0
- package/src/cli/simple-commands/swarm.js +2277 -0
- package/src/cli/simple-commands/task.js +228 -0
- package/src/cli/simple-commands/templates/mle-star-workflow.json +294 -0
- package/src/cli/simple-commands/timestamp-fix.js +104 -0
- package/src/cli/simple-commands/token-tracker.js +372 -0
- package/src/cli/simple-commands/tool-execution-framework.js +555 -0
- package/src/cli/simple-commands/train-and-stream.js +354 -0
- package/src/cli/simple-commands/training-pipeline.js +874 -0
- package/src/cli/simple-commands/training.js +288 -0
- package/src/cli/simple-commands/verification-hooks.js +336 -0
- package/src/cli/simple-commands/verification-integration.js +464 -0
- package/src/cli/simple-commands/verification-training-integration.js +646 -0
- package/src/cli/simple-commands/verification.js +551 -0
- package/src/cli/simple-commands/web-server.js +929 -0
- package/src/cli/simple-commands/webui-validator.js +136 -0
- package/src/language/README.md +503 -0
- package/src/language/claude-md-generator.js +618 -0
- package/src/language/cli.js +422 -0
- package/src/language/example.js +347 -0
- package/src/language/integration-system.js +619 -0
- package/src/language/language-detector.js +581 -0
|
@@ -0,0 +1,1364 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP Tool Wrapper for Hive Mind System
|
|
3
|
+
* Wraps all 87 MCP tools for coordinated swarm usage
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { spawn } from 'child_process';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* MCP Tool categories and their methods
|
|
10
|
+
*/
|
|
11
|
+
const MCP_TOOLS = {
|
|
12
|
+
swarm: [
|
|
13
|
+
'swarm_init',
|
|
14
|
+
'agent_spawn',
|
|
15
|
+
'task_orchestrate',
|
|
16
|
+
'swarm_status',
|
|
17
|
+
'agent_list',
|
|
18
|
+
'agent_metrics',
|
|
19
|
+
'swarm_monitor',
|
|
20
|
+
'topology_optimize',
|
|
21
|
+
'load_balance',
|
|
22
|
+
'coordination_sync',
|
|
23
|
+
'swarm_scale',
|
|
24
|
+
'swarm_destroy',
|
|
25
|
+
],
|
|
26
|
+
neural: [
|
|
27
|
+
'neural_status',
|
|
28
|
+
'neural_train',
|
|
29
|
+
'neural_patterns',
|
|
30
|
+
'neural_predict',
|
|
31
|
+
'model_load',
|
|
32
|
+
'model_save',
|
|
33
|
+
'wasm_optimize',
|
|
34
|
+
'inference_run',
|
|
35
|
+
'pattern_recognize',
|
|
36
|
+
'cognitive_analyze',
|
|
37
|
+
'learning_adapt',
|
|
38
|
+
'neural_compress',
|
|
39
|
+
'ensemble_create',
|
|
40
|
+
'transfer_learn',
|
|
41
|
+
'neural_explain',
|
|
42
|
+
],
|
|
43
|
+
memory: [
|
|
44
|
+
'memory_usage',
|
|
45
|
+
'memory_search',
|
|
46
|
+
'memory_persist',
|
|
47
|
+
'memory_namespace',
|
|
48
|
+
'memory_backup',
|
|
49
|
+
'memory_restore',
|
|
50
|
+
'memory_compress',
|
|
51
|
+
'memory_sync',
|
|
52
|
+
'cache_manage',
|
|
53
|
+
'state_snapshot',
|
|
54
|
+
'context_restore',
|
|
55
|
+
'memory_analytics',
|
|
56
|
+
],
|
|
57
|
+
performance: [
|
|
58
|
+
'performance_report',
|
|
59
|
+
'bottleneck_analyze',
|
|
60
|
+
'token_usage',
|
|
61
|
+
'benchmark_run',
|
|
62
|
+
'metrics_collect',
|
|
63
|
+
'trend_analysis',
|
|
64
|
+
'cost_analysis',
|
|
65
|
+
'quality_assess',
|
|
66
|
+
'error_analysis',
|
|
67
|
+
'usage_stats',
|
|
68
|
+
'health_check',
|
|
69
|
+
],
|
|
70
|
+
github: [
|
|
71
|
+
'github_repo_analyze',
|
|
72
|
+
'github_pr_manage',
|
|
73
|
+
'github_issue_track',
|
|
74
|
+
'github_release_coord',
|
|
75
|
+
'github_workflow_auto',
|
|
76
|
+
'github_code_review',
|
|
77
|
+
'github_sync_coord',
|
|
78
|
+
'github_metrics',
|
|
79
|
+
],
|
|
80
|
+
workflow: [
|
|
81
|
+
'workflow_create',
|
|
82
|
+
'workflow_execute',
|
|
83
|
+
'workflow_export',
|
|
84
|
+
'automation_setup',
|
|
85
|
+
'pipeline_create',
|
|
86
|
+
'scheduler_manage',
|
|
87
|
+
'trigger_setup',
|
|
88
|
+
'workflow_template',
|
|
89
|
+
'batch_process',
|
|
90
|
+
'parallel_execute',
|
|
91
|
+
],
|
|
92
|
+
daa: [
|
|
93
|
+
'daa_agent_create',
|
|
94
|
+
'daa_capability_match',
|
|
95
|
+
'daa_resource_alloc',
|
|
96
|
+
'daa_lifecycle_manage',
|
|
97
|
+
'daa_communication',
|
|
98
|
+
'daa_consensus',
|
|
99
|
+
'daa_fault_tolerance',
|
|
100
|
+
'daa_optimization',
|
|
101
|
+
],
|
|
102
|
+
system: [
|
|
103
|
+
'terminal_execute',
|
|
104
|
+
'config_manage',
|
|
105
|
+
'features_detect',
|
|
106
|
+
'security_scan',
|
|
107
|
+
'backup_create',
|
|
108
|
+
'restore_system',
|
|
109
|
+
'log_analysis',
|
|
110
|
+
'diagnostic_run',
|
|
111
|
+
],
|
|
112
|
+
sparc: ['sparc_mode'],
|
|
113
|
+
task: ['task_status', 'task_results'],
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* MCPToolWrapper class for unified MCP tool access
|
|
118
|
+
*/
|
|
119
|
+
export class MCPToolWrapper {
|
|
120
|
+
constructor(config = {}) {
|
|
121
|
+
this.config = {
|
|
122
|
+
parallel: true,
|
|
123
|
+
timeout: 60000,
|
|
124
|
+
retryCount: 3,
|
|
125
|
+
...config,
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
this.toolStats = new Map();
|
|
129
|
+
this.parallelQueue = [];
|
|
130
|
+
this.executing = false;
|
|
131
|
+
|
|
132
|
+
/** @type {import('better-sqlite3').Database | null} */
|
|
133
|
+
this.memoryDb = null;
|
|
134
|
+
|
|
135
|
+
// Initialize memory store for fallback
|
|
136
|
+
this.memoryStore = new Map();
|
|
137
|
+
|
|
138
|
+
// Initialize real memory storage
|
|
139
|
+
this.initializeMemoryStorage();
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Initialize real memory storage using SQLite
|
|
144
|
+
*/
|
|
145
|
+
async initializeMemoryStorage() {
|
|
146
|
+
try {
|
|
147
|
+
const { createDatabase, isSQLiteAvailable } = await import(
|
|
148
|
+
'../../../memory/sqlite-wrapper.js'
|
|
149
|
+
);
|
|
150
|
+
const path = await import('path');
|
|
151
|
+
const fs = await import('fs');
|
|
152
|
+
|
|
153
|
+
// Check if SQLite is available
|
|
154
|
+
const sqliteAvailable = await isSQLiteAvailable();
|
|
155
|
+
if (!sqliteAvailable) {
|
|
156
|
+
throw new Error('SQLite not available');
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// Create .hive-mind directory if it doesn't exist
|
|
160
|
+
const hiveMindDir = path.join(process.cwd(), '.hive-mind');
|
|
161
|
+
if (!fs.existsSync(hiveMindDir)) {
|
|
162
|
+
fs.mkdirSync(hiveMindDir, { recursive: true });
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// Initialize SQLite database
|
|
166
|
+
const dbPath = path.join(hiveMindDir, 'memory.db');
|
|
167
|
+
this.memoryDb = await createDatabase(dbPath);
|
|
168
|
+
|
|
169
|
+
// Create memories table
|
|
170
|
+
this.memoryDb.exec(`
|
|
171
|
+
CREATE TABLE IF NOT EXISTS memories (
|
|
172
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
173
|
+
namespace TEXT NOT NULL,
|
|
174
|
+
key TEXT NOT NULL,
|
|
175
|
+
value TEXT NOT NULL,
|
|
176
|
+
type TEXT DEFAULT 'knowledge',
|
|
177
|
+
timestamp INTEGER NOT NULL,
|
|
178
|
+
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
179
|
+
UNIQUE(namespace, key)
|
|
180
|
+
)
|
|
181
|
+
`);
|
|
182
|
+
|
|
183
|
+
// Real memory storage initialized with SQLite
|
|
184
|
+
} catch (error) {
|
|
185
|
+
console.warn(
|
|
186
|
+
'Failed to initialize SQLite storage, falling back to in-memory:',
|
|
187
|
+
error.message,
|
|
188
|
+
);
|
|
189
|
+
this.memoryDb = null;
|
|
190
|
+
this.memoryStore = new Map(); // Fallback to in-memory storage
|
|
191
|
+
|
|
192
|
+
// Log Windows-specific help if applicable
|
|
193
|
+
if (process.platform === 'win32') {
|
|
194
|
+
console.info(`
|
|
195
|
+
Windows users: For persistent storage, please see installation guide:
|
|
196
|
+
https://github.com/ruvnet/claude-code-flow/docs/windows-installation.md
|
|
197
|
+
`);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Execute MCP tool with automatic retry and error handling
|
|
204
|
+
*/
|
|
205
|
+
async executeTool(toolName, params = {}) {
|
|
206
|
+
const startTime = Date.now();
|
|
207
|
+
let lastError = null;
|
|
208
|
+
|
|
209
|
+
for (let attempt = 1; attempt <= this.config.retryCount; attempt++) {
|
|
210
|
+
try {
|
|
211
|
+
const result = await this._executeToolInternal(toolName, params);
|
|
212
|
+
|
|
213
|
+
// Track statistics
|
|
214
|
+
this._trackToolUsage(toolName, Date.now() - startTime, true);
|
|
215
|
+
|
|
216
|
+
return result;
|
|
217
|
+
} catch (error) {
|
|
218
|
+
lastError = error;
|
|
219
|
+
console.error(`Attempt ${attempt} failed for ${toolName}:`, error.message);
|
|
220
|
+
|
|
221
|
+
if (attempt < this.config.retryCount) {
|
|
222
|
+
// Exponential backoff
|
|
223
|
+
await new Promise((resolve) => setTimeout(resolve, Math.pow(2, attempt) * 1000));
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// Track failure
|
|
229
|
+
this._trackToolUsage(toolName, Date.now() - startTime, false);
|
|
230
|
+
|
|
231
|
+
throw new Error(
|
|
232
|
+
`Failed to execute ${toolName} after ${this.config.retryCount} attempts: ${lastError.message}`,
|
|
233
|
+
);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Execute multiple tools in parallel with optimized batching
|
|
238
|
+
*/
|
|
239
|
+
async executeParallel(toolCalls) {
|
|
240
|
+
if (!this.config.parallel) {
|
|
241
|
+
// Execute sequentially if parallel is disabled
|
|
242
|
+
const results = [];
|
|
243
|
+
for (const call of toolCalls) {
|
|
244
|
+
results.push(await this.executeTool(call.tool, call.params));
|
|
245
|
+
}
|
|
246
|
+
return results;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
if (!Array.isArray(toolCalls) || toolCalls.length === 0) {
|
|
250
|
+
return [];
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
const startTime = Date.now();
|
|
254
|
+
|
|
255
|
+
// Intelligent concurrency limit based on tool types
|
|
256
|
+
const concurrencyLimit = this._calculateOptimalConcurrency(toolCalls);
|
|
257
|
+
|
|
258
|
+
// Group tools by priority and dependency
|
|
259
|
+
const toolGroups = this._groupToolsByPriority(toolCalls);
|
|
260
|
+
const allResults = [];
|
|
261
|
+
|
|
262
|
+
try {
|
|
263
|
+
// Execute high-priority tools first
|
|
264
|
+
for (const group of toolGroups) {
|
|
265
|
+
const groupResults = [];
|
|
266
|
+
|
|
267
|
+
for (let i = 0; i < group.length; i += concurrencyLimit) {
|
|
268
|
+
const batch = group.slice(i, i + concurrencyLimit);
|
|
269
|
+
|
|
270
|
+
// Execute batch with timeout and retry logic
|
|
271
|
+
const batchPromises = batch.map((call) =>
|
|
272
|
+
this._executeWithTimeout(call, this.config.timeout),
|
|
273
|
+
);
|
|
274
|
+
|
|
275
|
+
const batchResults = await Promise.allSettled(batchPromises);
|
|
276
|
+
|
|
277
|
+
// Process results and handle failures
|
|
278
|
+
for (let j = 0; j < batchResults.length; j++) {
|
|
279
|
+
const result = batchResults[j];
|
|
280
|
+
if (result.status === 'fulfilled') {
|
|
281
|
+
groupResults.push(result.value);
|
|
282
|
+
} else {
|
|
283
|
+
console.warn(`Tool execution failed: ${batch[j].tool}`, result.reason);
|
|
284
|
+
groupResults.push({ error: result.reason.message, tool: batch[j].tool });
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
allResults.push(...groupResults);
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
// Track performance metrics
|
|
293
|
+
const executionTime = Date.now() - startTime;
|
|
294
|
+
this._trackBatchPerformance(toolCalls.length, executionTime, concurrencyLimit);
|
|
295
|
+
|
|
296
|
+
return allResults;
|
|
297
|
+
} catch (error) {
|
|
298
|
+
console.error('Parallel execution failed:', error);
|
|
299
|
+
throw error;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* Calculate optimal concurrency based on tool types
|
|
305
|
+
*/
|
|
306
|
+
_calculateOptimalConcurrency(toolCalls) {
|
|
307
|
+
const toolTypes = toolCalls.map((call) => this._getToolCategory(call.tool));
|
|
308
|
+
const uniqueTypes = new Set(toolTypes);
|
|
309
|
+
|
|
310
|
+
// Heavy operations (neural, github) need lower concurrency
|
|
311
|
+
const heavyTypes = ['neural', 'github', 'workflow'];
|
|
312
|
+
const hasHeavyOps = toolTypes.some((type) => heavyTypes.includes(type));
|
|
313
|
+
|
|
314
|
+
if (hasHeavyOps) {
|
|
315
|
+
return Math.min(3, Math.max(1, Math.floor(toolCalls.length / 2)));
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
// Light operations (memory, performance) can handle higher concurrency
|
|
319
|
+
return Math.min(8, Math.max(2, Math.floor(toolCalls.length / 1.5)));
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* Group tools by execution priority
|
|
324
|
+
*/
|
|
325
|
+
_groupToolsByPriority(toolCalls) {
|
|
326
|
+
const priorities = {
|
|
327
|
+
critical: [], // swarm_init, swarm_destroy
|
|
328
|
+
high: [], // agent_spawn, memory operations
|
|
329
|
+
medium: [], // task operations, monitoring
|
|
330
|
+
low: [], // analytics, reporting
|
|
331
|
+
};
|
|
332
|
+
|
|
333
|
+
toolCalls.forEach((call) => {
|
|
334
|
+
const category = this._getToolCategory(call.tool);
|
|
335
|
+
const tool = call.tool;
|
|
336
|
+
|
|
337
|
+
if (['swarm_init', 'swarm_destroy', 'memory_backup'].includes(tool)) {
|
|
338
|
+
priorities.critical.push(call);
|
|
339
|
+
} else if (['agent_spawn', 'memory_usage', 'neural_train'].includes(tool)) {
|
|
340
|
+
priorities.high.push(call);
|
|
341
|
+
} else if (category === 'performance' || tool.includes('report')) {
|
|
342
|
+
priorities.low.push(call);
|
|
343
|
+
} else {
|
|
344
|
+
priorities.medium.push(call);
|
|
345
|
+
}
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
// Return groups in priority order, filtering empty groups
|
|
349
|
+
return [priorities.critical, priorities.high, priorities.medium, priorities.low].filter(
|
|
350
|
+
(group) => group.length > 0,
|
|
351
|
+
);
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* Execute tool with timeout wrapper
|
|
356
|
+
*/
|
|
357
|
+
async _executeWithTimeout(call, timeout) {
|
|
358
|
+
return new Promise((resolve, reject) => {
|
|
359
|
+
const timer = setTimeout(() => {
|
|
360
|
+
reject(new Error(`Tool ${call.tool} timed out after ${timeout}ms`));
|
|
361
|
+
}, timeout);
|
|
362
|
+
|
|
363
|
+
this.executeTool(call.tool, call.params)
|
|
364
|
+
.then((result) => {
|
|
365
|
+
clearTimeout(timer);
|
|
366
|
+
resolve(result);
|
|
367
|
+
})
|
|
368
|
+
.catch((error) => {
|
|
369
|
+
clearTimeout(timer);
|
|
370
|
+
reject(error);
|
|
371
|
+
});
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
/**
|
|
376
|
+
* Track batch execution performance
|
|
377
|
+
*/
|
|
378
|
+
_trackBatchPerformance(toolCount, executionTime, concurrency) {
|
|
379
|
+
if (!this.batchStats) {
|
|
380
|
+
this.batchStats = {
|
|
381
|
+
totalBatches: 0,
|
|
382
|
+
totalTools: 0,
|
|
383
|
+
totalTime: 0,
|
|
384
|
+
avgConcurrency: 0,
|
|
385
|
+
avgToolsPerBatch: 0,
|
|
386
|
+
avgTimePerTool: 0,
|
|
387
|
+
};
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
this.batchStats.totalBatches++;
|
|
391
|
+
this.batchStats.totalTools += toolCount;
|
|
392
|
+
this.batchStats.totalTime += executionTime;
|
|
393
|
+
this.batchStats.avgConcurrency =
|
|
394
|
+
(this.batchStats.avgConcurrency * (this.batchStats.totalBatches - 1) + concurrency) /
|
|
395
|
+
this.batchStats.totalBatches;
|
|
396
|
+
this.batchStats.avgToolsPerBatch = this.batchStats.totalTools / this.batchStats.totalBatches;
|
|
397
|
+
this.batchStats.avgTimePerTool = this.batchStats.totalTime / this.batchStats.totalTools;
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
/**
|
|
401
|
+
* Internal tool execution
|
|
402
|
+
*/
|
|
403
|
+
async _executeToolInternal(toolName, params) {
|
|
404
|
+
const toolCategory = this._getToolCategory(toolName);
|
|
405
|
+
if (!toolCategory) {
|
|
406
|
+
throw new Error(`Unknown MCP tool: ${toolName}`);
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
// Handle memory operations with real storage
|
|
410
|
+
if (toolName === 'memory_usage') {
|
|
411
|
+
if (params.action === 'store') {
|
|
412
|
+
return await this.storeMemory(params.namespace, params.key, params.value, params.type);
|
|
413
|
+
} else if (params.action === 'retrieve') {
|
|
414
|
+
return await this.retrieveMemory(params.namespace, params.key);
|
|
415
|
+
}
|
|
416
|
+
} else if (toolName === 'memory_search') {
|
|
417
|
+
return await this.searchMemory(params.namespace, params.pattern);
|
|
418
|
+
} else if (toolName === 'swarm_status') {
|
|
419
|
+
return await this.getSwarmStatus(params);
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
// For other tools, use mock responses
|
|
423
|
+
console.log(`Executing MCP tool: mcp__claude-flow__${toolName} with params:`, params);
|
|
424
|
+
|
|
425
|
+
// Simulate async execution for non-memory tools
|
|
426
|
+
await new Promise((resolve) => setTimeout(resolve, Math.random() * 500));
|
|
427
|
+
|
|
428
|
+
// Mock response based on tool type
|
|
429
|
+
const mockResponse = this._getMockResponse(toolName, params);
|
|
430
|
+
return mockResponse;
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
/**
|
|
434
|
+
* Get tool category
|
|
435
|
+
*/
|
|
436
|
+
_getToolCategory(toolName) {
|
|
437
|
+
for (const [category, tools] of Object.entries(MCP_TOOLS)) {
|
|
438
|
+
if (tools.includes(toolName)) {
|
|
439
|
+
return category;
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
return null;
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
/**
|
|
446
|
+
* Get mock response for demonstration
|
|
447
|
+
*/
|
|
448
|
+
_getMockResponse(toolName, params) {
|
|
449
|
+
// Mock responses for different tool types
|
|
450
|
+
const mockResponses = {
|
|
451
|
+
swarm_init: {
|
|
452
|
+
swarmId: `swarm-${Date.now()}`,
|
|
453
|
+
topology: params.topology || 'hierarchical',
|
|
454
|
+
status: 'initialized',
|
|
455
|
+
},
|
|
456
|
+
agent_spawn: {
|
|
457
|
+
agentId: `agent-${Date.now()}-${Math.random().toString(36).substring(2, 11)}`,
|
|
458
|
+
type: params.type,
|
|
459
|
+
status: 'active',
|
|
460
|
+
},
|
|
461
|
+
task_orchestrate: {
|
|
462
|
+
taskId: `task-${Date.now()}`,
|
|
463
|
+
status: 'orchestrated',
|
|
464
|
+
strategy: params.strategy || 'parallel',
|
|
465
|
+
},
|
|
466
|
+
memory_usage: {
|
|
467
|
+
action: params.action,
|
|
468
|
+
result: params.action === 'store' ? 'stored' : 'retrieved',
|
|
469
|
+
data: params.value || null,
|
|
470
|
+
},
|
|
471
|
+
neural_status: {
|
|
472
|
+
status: 'ready',
|
|
473
|
+
models: 27,
|
|
474
|
+
accuracy: 0.848,
|
|
475
|
+
},
|
|
476
|
+
};
|
|
477
|
+
|
|
478
|
+
return mockResponses[toolName] || { status: 'success', toolName };
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
/**
|
|
482
|
+
* Track tool usage statistics
|
|
483
|
+
*/
|
|
484
|
+
_trackToolUsage(toolName, duration, success) {
|
|
485
|
+
if (!this.toolStats.has(toolName)) {
|
|
486
|
+
this.toolStats.set(toolName, {
|
|
487
|
+
calls: 0,
|
|
488
|
+
successes: 0,
|
|
489
|
+
failures: 0,
|
|
490
|
+
totalDuration: 0,
|
|
491
|
+
avgDuration: 0,
|
|
492
|
+
});
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
const stats = this.toolStats.get(toolName);
|
|
496
|
+
stats.calls++;
|
|
497
|
+
if (success) {
|
|
498
|
+
stats.successes++;
|
|
499
|
+
} else {
|
|
500
|
+
stats.failures++;
|
|
501
|
+
}
|
|
502
|
+
stats.totalDuration += duration;
|
|
503
|
+
stats.avgDuration = stats.totalDuration / stats.calls;
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
/**
|
|
507
|
+
* Get comprehensive tool statistics
|
|
508
|
+
*/
|
|
509
|
+
getStatistics() {
|
|
510
|
+
const toolStats = {};
|
|
511
|
+
this.toolStats.forEach((value, key) => {
|
|
512
|
+
toolStats[key] = { ...value };
|
|
513
|
+
});
|
|
514
|
+
|
|
515
|
+
return {
|
|
516
|
+
tools: toolStats,
|
|
517
|
+
batch: this.batchStats || {
|
|
518
|
+
totalBatches: 0,
|
|
519
|
+
totalTools: 0,
|
|
520
|
+
totalTime: 0,
|
|
521
|
+
avgConcurrency: 0,
|
|
522
|
+
avgToolsPerBatch: 0,
|
|
523
|
+
avgTimePerTool: 0,
|
|
524
|
+
},
|
|
525
|
+
spawn: this.spawnStats || {
|
|
526
|
+
totalSpawns: 0,
|
|
527
|
+
totalAgents: 0,
|
|
528
|
+
totalTime: 0,
|
|
529
|
+
avgTimePerAgent: 0,
|
|
530
|
+
bestTime: 0,
|
|
531
|
+
worstTime: 0,
|
|
532
|
+
},
|
|
533
|
+
performance: {
|
|
534
|
+
totalCalls: Array.from(this.toolStats.values()).reduce((sum, stat) => sum + stat.calls, 0),
|
|
535
|
+
successRate: this._calculateOverallSuccessRate(),
|
|
536
|
+
avgLatency: this._calculateAvgLatency(),
|
|
537
|
+
throughput: this._calculateThroughput(),
|
|
538
|
+
},
|
|
539
|
+
};
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
/**
|
|
543
|
+
* Calculate overall success rate
|
|
544
|
+
*/
|
|
545
|
+
_calculateOverallSuccessRate() {
|
|
546
|
+
const total = Array.from(this.toolStats.values()).reduce((sum, stat) => sum + stat.calls, 0);
|
|
547
|
+
const successes = Array.from(this.toolStats.values()).reduce(
|
|
548
|
+
(sum, stat) => sum + stat.successes,
|
|
549
|
+
0,
|
|
550
|
+
);
|
|
551
|
+
|
|
552
|
+
return total > 0 ? ((successes / total) * 100).toFixed(2) : 100;
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
/**
|
|
556
|
+
* Calculate average latency
|
|
557
|
+
*/
|
|
558
|
+
_calculateAvgLatency() {
|
|
559
|
+
const stats = Array.from(this.toolStats.values()).filter((stat) => stat.calls > 0);
|
|
560
|
+
if (stats.length === 0) return 0;
|
|
561
|
+
|
|
562
|
+
const totalLatency = stats.reduce((sum, stat) => sum + stat.avgDuration, 0);
|
|
563
|
+
return (totalLatency / stats.length).toFixed(2);
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
/**
|
|
567
|
+
* Calculate throughput (operations per second)
|
|
568
|
+
*/
|
|
569
|
+
_calculateThroughput() {
|
|
570
|
+
const batchStats = this.batchStats;
|
|
571
|
+
if (!batchStats || batchStats.totalTime === 0) return 0;
|
|
572
|
+
|
|
573
|
+
return (batchStats.totalTools / (batchStats.totalTime / 1000)).toFixed(2);
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
/**
|
|
577
|
+
* Create batch of tool calls for parallel execution
|
|
578
|
+
*/
|
|
579
|
+
createBatch(calls) {
|
|
580
|
+
return calls.map((call) => ({
|
|
581
|
+
tool: call.tool,
|
|
582
|
+
params: call.params || {},
|
|
583
|
+
}));
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
/**
|
|
587
|
+
* Execute swarm initialization sequence with optimization
|
|
588
|
+
*/
|
|
589
|
+
async initializeSwarm(config) {
|
|
590
|
+
const swarmId = config.swarmId || `swarm-${Date.now()}`;
|
|
591
|
+
const startTime = Date.now();
|
|
592
|
+
|
|
593
|
+
try {
|
|
594
|
+
// Phase 1: Critical initialization (sequential)
|
|
595
|
+
const criticalOps = [
|
|
596
|
+
{
|
|
597
|
+
tool: 'swarm_init',
|
|
598
|
+
params: {
|
|
599
|
+
topology: config.topology || 'hierarchical',
|
|
600
|
+
maxAgents: config.maxAgents || 8,
|
|
601
|
+
strategy: 'auto',
|
|
602
|
+
swarmId,
|
|
603
|
+
},
|
|
604
|
+
},
|
|
605
|
+
];
|
|
606
|
+
|
|
607
|
+
const [swarmInitResult] = await this.executeParallel(criticalOps);
|
|
608
|
+
|
|
609
|
+
// Phase 2: Supporting services (parallel)
|
|
610
|
+
const supportingOps = [
|
|
611
|
+
{
|
|
612
|
+
tool: 'memory_namespace',
|
|
613
|
+
params: {
|
|
614
|
+
action: 'create',
|
|
615
|
+
namespace: swarmId,
|
|
616
|
+
maxSize: config.memorySize || 100,
|
|
617
|
+
},
|
|
618
|
+
},
|
|
619
|
+
{ tool: 'neural_status', params: {} },
|
|
620
|
+
{ tool: 'performance_report', params: { format: 'summary' } },
|
|
621
|
+
{ tool: 'features_detect', params: { component: 'swarm' } },
|
|
622
|
+
];
|
|
623
|
+
|
|
624
|
+
const supportingResults = await this.executeParallel(supportingOps);
|
|
625
|
+
|
|
626
|
+
// Store initialization metadata
|
|
627
|
+
const initTime = Date.now() - startTime;
|
|
628
|
+
await this.storeMemory(
|
|
629
|
+
swarmId,
|
|
630
|
+
'init_performance',
|
|
631
|
+
{
|
|
632
|
+
initTime,
|
|
633
|
+
topology: config.topology || 'hierarchical',
|
|
634
|
+
maxAgents: config.maxAgents || 8,
|
|
635
|
+
timestamp: Date.now(),
|
|
636
|
+
},
|
|
637
|
+
'metrics',
|
|
638
|
+
);
|
|
639
|
+
|
|
640
|
+
// Store swarm status
|
|
641
|
+
await this.storeMemory(swarmId, 'status', 'active', 'status');
|
|
642
|
+
|
|
643
|
+
// Store swarm config
|
|
644
|
+
await this.storeMemory(
|
|
645
|
+
swarmId,
|
|
646
|
+
'config',
|
|
647
|
+
{
|
|
648
|
+
topology: config.topology || 'hierarchical',
|
|
649
|
+
maxAgents: config.maxAgents || 8,
|
|
650
|
+
strategy: config.strategy || 'auto',
|
|
651
|
+
createdAt: Date.now(),
|
|
652
|
+
},
|
|
653
|
+
'config',
|
|
654
|
+
);
|
|
655
|
+
|
|
656
|
+
return [swarmInitResult, ...supportingResults];
|
|
657
|
+
} catch (error) {
|
|
658
|
+
console.error('Swarm initialization failed:', error);
|
|
659
|
+
throw error;
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
/**
|
|
664
|
+
* Spawn multiple agents in parallel with optimization
|
|
665
|
+
*/
|
|
666
|
+
async spawnAgents(types, swarmId) {
|
|
667
|
+
if (!Array.isArray(types) || types.length === 0) {
|
|
668
|
+
return [];
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
const startTime = Date.now();
|
|
672
|
+
|
|
673
|
+
// Optimize agent spawning by grouping similar types
|
|
674
|
+
const groupedTypes = this._groupAgentTypes(types);
|
|
675
|
+
const allResults = [];
|
|
676
|
+
|
|
677
|
+
try {
|
|
678
|
+
// Spawn each group in parallel
|
|
679
|
+
for (const group of groupedTypes) {
|
|
680
|
+
const batch = group.map((type) => ({
|
|
681
|
+
tool: 'agent_spawn',
|
|
682
|
+
params: {
|
|
683
|
+
type,
|
|
684
|
+
swarmId,
|
|
685
|
+
timestamp: Date.now(),
|
|
686
|
+
batchId: `batch-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`,
|
|
687
|
+
},
|
|
688
|
+
}));
|
|
689
|
+
|
|
690
|
+
const groupResults = await this.executeParallel(batch);
|
|
691
|
+
allResults.push(...groupResults);
|
|
692
|
+
|
|
693
|
+
// Store agent information in memory
|
|
694
|
+
for (const result of groupResults) {
|
|
695
|
+
if (result && result.agentId && !result.error) {
|
|
696
|
+
await this.storeMemory(
|
|
697
|
+
swarmId,
|
|
698
|
+
`agent-${result.agentId}`,
|
|
699
|
+
{
|
|
700
|
+
id: result.agentId,
|
|
701
|
+
type: result.type,
|
|
702
|
+
status: result.status || 'active',
|
|
703
|
+
createdAt: Date.now(),
|
|
704
|
+
},
|
|
705
|
+
'agent',
|
|
706
|
+
);
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
// Track spawn performance
|
|
712
|
+
const spawnTime = Date.now() - startTime;
|
|
713
|
+
this._trackSpawnPerformance(types.length, spawnTime);
|
|
714
|
+
|
|
715
|
+
return allResults;
|
|
716
|
+
} catch (error) {
|
|
717
|
+
console.error('Agent spawning failed:', error);
|
|
718
|
+
throw error;
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
/**
|
|
723
|
+
* Group agent types for optimized spawning
|
|
724
|
+
*/
|
|
725
|
+
_groupAgentTypes(types) {
|
|
726
|
+
// Group complementary agent types that work well together
|
|
727
|
+
const groups = {
|
|
728
|
+
development: ['coder', 'architect', 'reviewer'],
|
|
729
|
+
analysis: ['researcher', 'analyst', 'optimizer'],
|
|
730
|
+
quality: ['tester', 'documenter'],
|
|
731
|
+
coordination: ['coordinator'],
|
|
732
|
+
};
|
|
733
|
+
|
|
734
|
+
const result = [];
|
|
735
|
+
const remaining = [...types];
|
|
736
|
+
|
|
737
|
+
// Create groups of complementary agents
|
|
738
|
+
Object.values(groups).forEach((groupTypes) => {
|
|
739
|
+
const groupAgents = remaining.filter((type) => groupTypes.includes(type));
|
|
740
|
+
if (groupAgents.length > 0) {
|
|
741
|
+
result.push(groupAgents);
|
|
742
|
+
groupAgents.forEach((type) => {
|
|
743
|
+
const index = remaining.indexOf(type);
|
|
744
|
+
if (index > -1) remaining.splice(index, 1);
|
|
745
|
+
});
|
|
746
|
+
}
|
|
747
|
+
});
|
|
748
|
+
|
|
749
|
+
// Add remaining agents as individual groups
|
|
750
|
+
remaining.forEach((type) => result.push([type]));
|
|
751
|
+
|
|
752
|
+
return result;
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
/**
|
|
756
|
+
* Track agent spawn performance
|
|
757
|
+
*/
|
|
758
|
+
_trackSpawnPerformance(agentCount, spawnTime) {
|
|
759
|
+
if (!this.spawnStats) {
|
|
760
|
+
this.spawnStats = {
|
|
761
|
+
totalSpawns: 0,
|
|
762
|
+
totalAgents: 0,
|
|
763
|
+
totalTime: 0,
|
|
764
|
+
avgTimePerAgent: 0,
|
|
765
|
+
bestTime: Infinity,
|
|
766
|
+
worstTime: 0,
|
|
767
|
+
};
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
this.spawnStats.totalSpawns++;
|
|
771
|
+
this.spawnStats.totalAgents += agentCount;
|
|
772
|
+
this.spawnStats.totalTime += spawnTime;
|
|
773
|
+
this.spawnStats.avgTimePerAgent = this.spawnStats.totalTime / this.spawnStats.totalAgents;
|
|
774
|
+
this.spawnStats.bestTime = Math.min(this.spawnStats.bestTime, spawnTime);
|
|
775
|
+
this.spawnStats.worstTime = Math.max(this.spawnStats.worstTime, spawnTime);
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
/**
|
|
779
|
+
* Store data in collective memory (REAL IMPLEMENTATION)
|
|
780
|
+
*/
|
|
781
|
+
async storeMemory(swarmId, key, value, type = 'knowledge') {
|
|
782
|
+
try {
|
|
783
|
+
// Don't reinitialize if we already have storage
|
|
784
|
+
if (!this.memoryDb && !this.memoryStore) {
|
|
785
|
+
await this.initializeMemoryStorage();
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
const timestamp = Date.now();
|
|
789
|
+
const valueStr = typeof value === 'string' ? value : JSON.stringify(value);
|
|
790
|
+
|
|
791
|
+
if (this.memoryDb) {
|
|
792
|
+
// SQLite storage
|
|
793
|
+
const stmt = this.memoryDb.prepare(`
|
|
794
|
+
INSERT OR REPLACE INTO memories (namespace, key, value, type, timestamp)
|
|
795
|
+
VALUES (?, ?, ?, ?, ?)
|
|
796
|
+
`);
|
|
797
|
+
|
|
798
|
+
const result = stmt.run(swarmId, key, valueStr, type, timestamp);
|
|
799
|
+
|
|
800
|
+
return {
|
|
801
|
+
success: true,
|
|
802
|
+
action: 'store',
|
|
803
|
+
namespace: swarmId,
|
|
804
|
+
key,
|
|
805
|
+
type,
|
|
806
|
+
timestamp,
|
|
807
|
+
id: result.lastInsertRowid,
|
|
808
|
+
};
|
|
809
|
+
} else {
|
|
810
|
+
// Fallback in-memory storage
|
|
811
|
+
const memoryKey = `${swarmId}:${key}`;
|
|
812
|
+
this.memoryStore.set(memoryKey, {
|
|
813
|
+
namespace: swarmId,
|
|
814
|
+
key,
|
|
815
|
+
value: valueStr,
|
|
816
|
+
type,
|
|
817
|
+
timestamp,
|
|
818
|
+
});
|
|
819
|
+
|
|
820
|
+
return {
|
|
821
|
+
success: true,
|
|
822
|
+
action: 'store',
|
|
823
|
+
namespace: swarmId,
|
|
824
|
+
key,
|
|
825
|
+
type,
|
|
826
|
+
timestamp,
|
|
827
|
+
};
|
|
828
|
+
}
|
|
829
|
+
} catch (error) {
|
|
830
|
+
console.error('Error storing memory:', error);
|
|
831
|
+
throw error;
|
|
832
|
+
}
|
|
833
|
+
}
|
|
834
|
+
|
|
835
|
+
/**
|
|
836
|
+
* Retrieve data from collective memory (REAL IMPLEMENTATION)
|
|
837
|
+
*/
|
|
838
|
+
async retrieveMemory(swarmId, key) {
|
|
839
|
+
try {
|
|
840
|
+
// Don't reinitialize if we already have storage
|
|
841
|
+
if (!this.memoryDb && !this.memoryStore) {
|
|
842
|
+
await this.initializeMemoryStorage();
|
|
843
|
+
}
|
|
844
|
+
|
|
845
|
+
if (this.memoryDb) {
|
|
846
|
+
// SQLite retrieval
|
|
847
|
+
const stmt = this.memoryDb.prepare(`
|
|
848
|
+
SELECT * FROM memories WHERE namespace = ? AND key = ?
|
|
849
|
+
`);
|
|
850
|
+
|
|
851
|
+
const row = stmt.get(swarmId, key);
|
|
852
|
+
if (row) {
|
|
853
|
+
try {
|
|
854
|
+
return {
|
|
855
|
+
...row,
|
|
856
|
+
value: JSON.parse(row.value),
|
|
857
|
+
};
|
|
858
|
+
} catch {
|
|
859
|
+
return row;
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
} else {
|
|
863
|
+
// Fallback in-memory retrieval
|
|
864
|
+
const memoryKey = `${swarmId}:${key}`;
|
|
865
|
+
const memory = this.memoryStore.get(memoryKey);
|
|
866
|
+
if (memory) {
|
|
867
|
+
try {
|
|
868
|
+
return {
|
|
869
|
+
...memory,
|
|
870
|
+
value: JSON.parse(memory.value),
|
|
871
|
+
};
|
|
872
|
+
} catch {
|
|
873
|
+
return memory;
|
|
874
|
+
}
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
|
|
878
|
+
return null;
|
|
879
|
+
} catch (error) {
|
|
880
|
+
console.error('Error retrieving memory:', error);
|
|
881
|
+
throw error;
|
|
882
|
+
}
|
|
883
|
+
}
|
|
884
|
+
|
|
885
|
+
/**
|
|
886
|
+
* Search collective memory (REAL IMPLEMENTATION)
|
|
887
|
+
*/
|
|
888
|
+
async searchMemory(swarmId, pattern) {
|
|
889
|
+
try {
|
|
890
|
+
// Don't reinitialize if we already have storage
|
|
891
|
+
if (!this.memoryDb && !this.memoryStore) {
|
|
892
|
+
await this.initializeMemoryStorage();
|
|
893
|
+
}
|
|
894
|
+
|
|
895
|
+
let results = [];
|
|
896
|
+
|
|
897
|
+
if (this.memoryDb) {
|
|
898
|
+
// SQLite search
|
|
899
|
+
let query, params;
|
|
900
|
+
|
|
901
|
+
if (pattern && pattern.trim()) {
|
|
902
|
+
// Search with pattern
|
|
903
|
+
query = `
|
|
904
|
+
SELECT * FROM memories
|
|
905
|
+
WHERE namespace = ? AND (key LIKE ? OR value LIKE ? OR type LIKE ?)
|
|
906
|
+
ORDER BY timestamp DESC
|
|
907
|
+
LIMIT 50
|
|
908
|
+
`;
|
|
909
|
+
const searchPattern = `%${pattern}%`;
|
|
910
|
+
params = [swarmId, searchPattern, searchPattern, searchPattern];
|
|
911
|
+
} else {
|
|
912
|
+
// Get all memories for namespace
|
|
913
|
+
query = `
|
|
914
|
+
SELECT * FROM memories
|
|
915
|
+
WHERE namespace = ?
|
|
916
|
+
ORDER BY timestamp DESC
|
|
917
|
+
LIMIT 50
|
|
918
|
+
`;
|
|
919
|
+
params = [swarmId];
|
|
920
|
+
}
|
|
921
|
+
|
|
922
|
+
const stmt = this.memoryDb.prepare(query);
|
|
923
|
+
results = stmt.all(...params);
|
|
924
|
+
|
|
925
|
+
// Parse JSON values where possible
|
|
926
|
+
results = results.map((row) => {
|
|
927
|
+
try {
|
|
928
|
+
return {
|
|
929
|
+
...row,
|
|
930
|
+
value: JSON.parse(row.value),
|
|
931
|
+
};
|
|
932
|
+
} catch {
|
|
933
|
+
return row;
|
|
934
|
+
}
|
|
935
|
+
});
|
|
936
|
+
} else {
|
|
937
|
+
// Fallback in-memory search
|
|
938
|
+
for (const [memKey, memory] of this.memoryStore) {
|
|
939
|
+
if (memory.namespace === swarmId) {
|
|
940
|
+
if (
|
|
941
|
+
!pattern ||
|
|
942
|
+
memory.key.includes(pattern) ||
|
|
943
|
+
memory.value.includes(pattern) ||
|
|
944
|
+
memory.type.includes(pattern)
|
|
945
|
+
) {
|
|
946
|
+
try {
|
|
947
|
+
results.push({
|
|
948
|
+
...memory,
|
|
949
|
+
value: JSON.parse(memory.value),
|
|
950
|
+
});
|
|
951
|
+
} catch {
|
|
952
|
+
results.push(memory);
|
|
953
|
+
}
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
}
|
|
957
|
+
|
|
958
|
+
// Sort by timestamp descending
|
|
959
|
+
results.sort((a, b) => b.timestamp - a.timestamp);
|
|
960
|
+
results = results.slice(0, 50);
|
|
961
|
+
}
|
|
962
|
+
|
|
963
|
+
return {
|
|
964
|
+
success: true,
|
|
965
|
+
namespace: swarmId,
|
|
966
|
+
pattern: pattern || '',
|
|
967
|
+
total: results.length,
|
|
968
|
+
results: results,
|
|
969
|
+
};
|
|
970
|
+
} catch (error) {
|
|
971
|
+
console.error('Error searching memory:', error);
|
|
972
|
+
throw error;
|
|
973
|
+
}
|
|
974
|
+
}
|
|
975
|
+
|
|
976
|
+
/**
|
|
977
|
+
* Orchestrate task with monitoring and optimization
|
|
978
|
+
*/
|
|
979
|
+
async orchestrateTask(task, strategy = 'parallel', metadata = {}) {
|
|
980
|
+
const taskId = metadata.taskId || `task-${Date.now()}`;
|
|
981
|
+
const swarmId = metadata.swarmId || 'default-swarm';
|
|
982
|
+
const complexity = metadata.complexity || 'medium';
|
|
983
|
+
|
|
984
|
+
// Store task information
|
|
985
|
+
await this.storeMemory(
|
|
986
|
+
swarmId,
|
|
987
|
+
`task-${taskId}`,
|
|
988
|
+
{
|
|
989
|
+
id: taskId,
|
|
990
|
+
task,
|
|
991
|
+
strategy,
|
|
992
|
+
status: 'pending',
|
|
993
|
+
priority: metadata.priority || 5,
|
|
994
|
+
complexity,
|
|
995
|
+
createdAt: Date.now(),
|
|
996
|
+
},
|
|
997
|
+
'task',
|
|
998
|
+
);
|
|
999
|
+
|
|
1000
|
+
// Adjust monitoring frequency based on task complexity
|
|
1001
|
+
const monitoringInterval =
|
|
1002
|
+
{
|
|
1003
|
+
low: 10000,
|
|
1004
|
+
medium: 5000,
|
|
1005
|
+
high: 2000,
|
|
1006
|
+
}[complexity] || 5000;
|
|
1007
|
+
|
|
1008
|
+
const batch = [
|
|
1009
|
+
{
|
|
1010
|
+
tool: 'task_orchestrate',
|
|
1011
|
+
params: {
|
|
1012
|
+
task,
|
|
1013
|
+
strategy,
|
|
1014
|
+
taskId,
|
|
1015
|
+
priority: metadata.priority || 5,
|
|
1016
|
+
estimatedDuration: metadata.estimatedDuration || 30000,
|
|
1017
|
+
},
|
|
1018
|
+
},
|
|
1019
|
+
{
|
|
1020
|
+
tool: 'swarm_monitor',
|
|
1021
|
+
params: {
|
|
1022
|
+
interval: monitoringInterval,
|
|
1023
|
+
taskId,
|
|
1024
|
+
metrics: ['performance', 'progress', 'bottlenecks'],
|
|
1025
|
+
},
|
|
1026
|
+
},
|
|
1027
|
+
// Add performance tracking for high-priority tasks
|
|
1028
|
+
...(metadata.priority > 7
|
|
1029
|
+
? [
|
|
1030
|
+
{
|
|
1031
|
+
tool: 'performance_report',
|
|
1032
|
+
params: { format: 'detailed', taskId },
|
|
1033
|
+
},
|
|
1034
|
+
]
|
|
1035
|
+
: []),
|
|
1036
|
+
];
|
|
1037
|
+
|
|
1038
|
+
const results = await this.executeParallel(batch);
|
|
1039
|
+
|
|
1040
|
+
// Update task status
|
|
1041
|
+
await this.storeMemory(
|
|
1042
|
+
swarmId,
|
|
1043
|
+
`task-${taskId}`,
|
|
1044
|
+
{
|
|
1045
|
+
id: taskId,
|
|
1046
|
+
task,
|
|
1047
|
+
strategy,
|
|
1048
|
+
status: 'in_progress',
|
|
1049
|
+
priority: metadata.priority || 5,
|
|
1050
|
+
complexity,
|
|
1051
|
+
createdAt: Date.now(),
|
|
1052
|
+
},
|
|
1053
|
+
'task',
|
|
1054
|
+
);
|
|
1055
|
+
|
|
1056
|
+
return results;
|
|
1057
|
+
}
|
|
1058
|
+
|
|
1059
|
+
/**
|
|
1060
|
+
* Analyze performance bottlenecks
|
|
1061
|
+
*/
|
|
1062
|
+
async analyzePerformance(swarmId) {
|
|
1063
|
+
const batch = [
|
|
1064
|
+
{ tool: 'bottleneck_analyze', params: { component: swarmId } },
|
|
1065
|
+
{ tool: 'performance_report', params: { format: 'detailed' } },
|
|
1066
|
+
{ tool: 'token_usage', params: { operation: swarmId } },
|
|
1067
|
+
];
|
|
1068
|
+
|
|
1069
|
+
return await this.executeParallel(batch);
|
|
1070
|
+
}
|
|
1071
|
+
|
|
1072
|
+
/**
|
|
1073
|
+
* GitHub integration for code operations
|
|
1074
|
+
*/
|
|
1075
|
+
async githubOperations(repo, operation, params = {}) {
|
|
1076
|
+
const githubTools = {
|
|
1077
|
+
analyze: 'github_repo_analyze',
|
|
1078
|
+
pr: 'github_pr_manage',
|
|
1079
|
+
issue: 'github_issue_track',
|
|
1080
|
+
review: 'github_code_review',
|
|
1081
|
+
};
|
|
1082
|
+
|
|
1083
|
+
const tool = githubTools[operation];
|
|
1084
|
+
if (!tool) {
|
|
1085
|
+
throw new Error(`Unknown GitHub operation: ${operation}`);
|
|
1086
|
+
}
|
|
1087
|
+
|
|
1088
|
+
return await this.executeTool(tool, { repo, ...params });
|
|
1089
|
+
}
|
|
1090
|
+
|
|
1091
|
+
/**
|
|
1092
|
+
* Neural network operations
|
|
1093
|
+
*/
|
|
1094
|
+
async neuralOperation(operation, params = {}) {
|
|
1095
|
+
const neuralTools = {
|
|
1096
|
+
train: 'neural_train',
|
|
1097
|
+
predict: 'neural_predict',
|
|
1098
|
+
analyze: 'neural_patterns',
|
|
1099
|
+
optimize: 'wasm_optimize',
|
|
1100
|
+
};
|
|
1101
|
+
|
|
1102
|
+
const tool = neuralTools[operation];
|
|
1103
|
+
if (!tool) {
|
|
1104
|
+
throw new Error(`Unknown neural operation: ${operation}`);
|
|
1105
|
+
}
|
|
1106
|
+
|
|
1107
|
+
return await this.executeTool(tool, params);
|
|
1108
|
+
}
|
|
1109
|
+
|
|
1110
|
+
/**
|
|
1111
|
+
* Clean up and destroy swarm
|
|
1112
|
+
*/
|
|
1113
|
+
async destroySwarm(swarmId) {
|
|
1114
|
+
const batch = [
|
|
1115
|
+
{ tool: 'swarm_destroy', params: { swarmId } },
|
|
1116
|
+
{
|
|
1117
|
+
tool: 'memory_namespace',
|
|
1118
|
+
params: {
|
|
1119
|
+
action: 'delete',
|
|
1120
|
+
namespace: swarmId,
|
|
1121
|
+
},
|
|
1122
|
+
},
|
|
1123
|
+
{
|
|
1124
|
+
tool: 'cache_manage',
|
|
1125
|
+
params: {
|
|
1126
|
+
action: 'clear',
|
|
1127
|
+
key: `swarm-${swarmId}`,
|
|
1128
|
+
},
|
|
1129
|
+
},
|
|
1130
|
+
];
|
|
1131
|
+
|
|
1132
|
+
return await this.executeParallel(batch);
|
|
1133
|
+
}
|
|
1134
|
+
|
|
1135
|
+
/**
|
|
1136
|
+
* Get real swarm status from memory storage
|
|
1137
|
+
*/
|
|
1138
|
+
async getSwarmStatus(params = {}) {
|
|
1139
|
+
try {
|
|
1140
|
+
// Don't reinitialize if we already have storage
|
|
1141
|
+
if (!this.memoryDb && !this.memoryStore) {
|
|
1142
|
+
await this.initializeMemoryStorage();
|
|
1143
|
+
}
|
|
1144
|
+
|
|
1145
|
+
const swarms = [];
|
|
1146
|
+
let activeAgents = 0;
|
|
1147
|
+
let totalTasks = 0;
|
|
1148
|
+
let completedTasks = 0;
|
|
1149
|
+
|
|
1150
|
+
if (this.memoryDb) {
|
|
1151
|
+
// Get all unique swarm namespaces
|
|
1152
|
+
const namespacesQuery = this.memoryDb.prepare(`
|
|
1153
|
+
SELECT DISTINCT namespace FROM memories
|
|
1154
|
+
WHERE namespace LIKE 'swarm-%' OR namespace LIKE 'hive-%'
|
|
1155
|
+
ORDER BY timestamp DESC
|
|
1156
|
+
`);
|
|
1157
|
+
const namespaces = namespacesQuery.all();
|
|
1158
|
+
|
|
1159
|
+
// For each swarm, gather its information
|
|
1160
|
+
for (const { namespace } of namespaces) {
|
|
1161
|
+
const swarmId = namespace;
|
|
1162
|
+
|
|
1163
|
+
// Get swarm metadata
|
|
1164
|
+
const metadataQuery = this.memoryDb.prepare(`
|
|
1165
|
+
SELECT key, value, type, timestamp FROM memories
|
|
1166
|
+
WHERE namespace = ? AND (
|
|
1167
|
+
key IN ('init_performance', 'config', 'status', 'agents', 'tasks', 'topology')
|
|
1168
|
+
OR key LIKE 'agent-%'
|
|
1169
|
+
OR key LIKE 'task-%'
|
|
1170
|
+
)
|
|
1171
|
+
`);
|
|
1172
|
+
const swarmData = metadataQuery.all(swarmId);
|
|
1173
|
+
|
|
1174
|
+
// Parse swarm information
|
|
1175
|
+
let swarmInfo = {
|
|
1176
|
+
id: swarmId,
|
|
1177
|
+
name: swarmId,
|
|
1178
|
+
status: 'unknown',
|
|
1179
|
+
agents: 0,
|
|
1180
|
+
tasks: { total: 0, completed: 0, pending: 0, failed: 0 },
|
|
1181
|
+
topology: 'hierarchical',
|
|
1182
|
+
createdAt: null,
|
|
1183
|
+
lastActivity: null,
|
|
1184
|
+
memoryUsage: swarmData.length,
|
|
1185
|
+
};
|
|
1186
|
+
|
|
1187
|
+
// Process swarm data
|
|
1188
|
+
for (const record of swarmData) {
|
|
1189
|
+
try {
|
|
1190
|
+
const value =
|
|
1191
|
+
typeof record.value === 'string' ? JSON.parse(record.value) : record.value;
|
|
1192
|
+
|
|
1193
|
+
switch (record.key) {
|
|
1194
|
+
case 'init_performance':
|
|
1195
|
+
swarmInfo.createdAt = value.timestamp;
|
|
1196
|
+
swarmInfo.topology = value.topology || 'hierarchical';
|
|
1197
|
+
break;
|
|
1198
|
+
case 'status':
|
|
1199
|
+
swarmInfo.status = value;
|
|
1200
|
+
break;
|
|
1201
|
+
case 'config':
|
|
1202
|
+
swarmInfo.topology = value.topology || swarmInfo.topology;
|
|
1203
|
+
break;
|
|
1204
|
+
}
|
|
1205
|
+
|
|
1206
|
+
// Count agents
|
|
1207
|
+
if (record.key.startsWith('agent-')) {
|
|
1208
|
+
swarmInfo.agents++;
|
|
1209
|
+
activeAgents++;
|
|
1210
|
+
}
|
|
1211
|
+
|
|
1212
|
+
// Count tasks
|
|
1213
|
+
if (record.key.startsWith('task-')) {
|
|
1214
|
+
swarmInfo.tasks.total++;
|
|
1215
|
+
totalTasks++;
|
|
1216
|
+
if (value.status === 'completed') {
|
|
1217
|
+
swarmInfo.tasks.completed++;
|
|
1218
|
+
completedTasks++;
|
|
1219
|
+
} else if (value.status === 'failed') {
|
|
1220
|
+
swarmInfo.tasks.failed++;
|
|
1221
|
+
} else if (value.status === 'pending' || value.status === 'in_progress') {
|
|
1222
|
+
swarmInfo.tasks.pending++;
|
|
1223
|
+
}
|
|
1224
|
+
}
|
|
1225
|
+
|
|
1226
|
+
// Track last activity
|
|
1227
|
+
if (record.timestamp > (swarmInfo.lastActivity || 0)) {
|
|
1228
|
+
swarmInfo.lastActivity = record.timestamp;
|
|
1229
|
+
}
|
|
1230
|
+
} catch (e) {
|
|
1231
|
+
// Skip invalid JSON values
|
|
1232
|
+
}
|
|
1233
|
+
}
|
|
1234
|
+
|
|
1235
|
+
// Determine swarm status based on activity
|
|
1236
|
+
if (swarmInfo.status === 'unknown') {
|
|
1237
|
+
const now = Date.now();
|
|
1238
|
+
const lastActivityAge = now - (swarmInfo.lastActivity || 0);
|
|
1239
|
+
|
|
1240
|
+
if (lastActivityAge < 60000) {
|
|
1241
|
+
// Active within last minute
|
|
1242
|
+
swarmInfo.status = 'active';
|
|
1243
|
+
} else if (lastActivityAge < 300000) {
|
|
1244
|
+
// Active within last 5 minutes
|
|
1245
|
+
swarmInfo.status = 'idle';
|
|
1246
|
+
} else {
|
|
1247
|
+
swarmInfo.status = 'inactive';
|
|
1248
|
+
}
|
|
1249
|
+
}
|
|
1250
|
+
|
|
1251
|
+
swarms.push(swarmInfo);
|
|
1252
|
+
}
|
|
1253
|
+
|
|
1254
|
+
// Get recent activity logs
|
|
1255
|
+
const activityQuery = this.memoryDb.prepare(`
|
|
1256
|
+
SELECT namespace, key, type, timestamp FROM memories
|
|
1257
|
+
WHERE (namespace LIKE 'swarm-%' OR namespace LIKE 'hive-%')
|
|
1258
|
+
AND timestamp > ?
|
|
1259
|
+
ORDER BY timestamp DESC
|
|
1260
|
+
LIMIT 10
|
|
1261
|
+
`);
|
|
1262
|
+
const recentActivity = activityQuery.all(Date.now() - 300000); // Last 5 minutes
|
|
1263
|
+
|
|
1264
|
+
return {
|
|
1265
|
+
swarms,
|
|
1266
|
+
activeAgents,
|
|
1267
|
+
totalTasks,
|
|
1268
|
+
completedTasks,
|
|
1269
|
+
pendingTasks: totalTasks - completedTasks,
|
|
1270
|
+
recentActivity: recentActivity.map((r) => ({
|
|
1271
|
+
swarmId: r.namespace,
|
|
1272
|
+
action: r.key,
|
|
1273
|
+
type: r.type,
|
|
1274
|
+
timestamp: r.timestamp,
|
|
1275
|
+
})),
|
|
1276
|
+
summary: {
|
|
1277
|
+
totalSwarms: swarms.length,
|
|
1278
|
+
activeSwarms: swarms.filter((s) => s.status === 'active').length,
|
|
1279
|
+
idleSwarms: swarms.filter((s) => s.status === 'idle').length,
|
|
1280
|
+
inactiveSwarms: swarms.filter((s) => s.status === 'inactive').length,
|
|
1281
|
+
},
|
|
1282
|
+
};
|
|
1283
|
+
} else {
|
|
1284
|
+
// Fallback to in-memory storage
|
|
1285
|
+
const swarmMap = new Map();
|
|
1286
|
+
|
|
1287
|
+
for (const [key, memory] of this.memoryStore) {
|
|
1288
|
+
const namespace = memory.namespace;
|
|
1289
|
+
if (namespace && (namespace.startsWith('swarm-') || namespace.startsWith('hive-'))) {
|
|
1290
|
+
if (!swarmMap.has(namespace)) {
|
|
1291
|
+
swarmMap.set(namespace, {
|
|
1292
|
+
id: namespace,
|
|
1293
|
+
name: namespace,
|
|
1294
|
+
status: 'active',
|
|
1295
|
+
agents: 0,
|
|
1296
|
+
tasks: { total: 0, completed: 0, pending: 0, failed: 0 },
|
|
1297
|
+
memoryUsage: 0,
|
|
1298
|
+
});
|
|
1299
|
+
}
|
|
1300
|
+
|
|
1301
|
+
const swarm = swarmMap.get(namespace);
|
|
1302
|
+
swarm.memoryUsage++;
|
|
1303
|
+
|
|
1304
|
+
if (memory.key.startsWith('agent-')) {
|
|
1305
|
+
swarm.agents++;
|
|
1306
|
+
activeAgents++;
|
|
1307
|
+
}
|
|
1308
|
+
|
|
1309
|
+
if (memory.key.startsWith('task-')) {
|
|
1310
|
+
swarm.tasks.total++;
|
|
1311
|
+
totalTasks++;
|
|
1312
|
+
try {
|
|
1313
|
+
const taskData = JSON.parse(memory.value);
|
|
1314
|
+
if (taskData.status === 'completed') {
|
|
1315
|
+
swarm.tasks.completed++;
|
|
1316
|
+
completedTasks++;
|
|
1317
|
+
} else if (taskData.status === 'failed') {
|
|
1318
|
+
swarm.tasks.failed++;
|
|
1319
|
+
} else if (taskData.status === 'pending' || taskData.status === 'in_progress') {
|
|
1320
|
+
swarm.tasks.pending++;
|
|
1321
|
+
}
|
|
1322
|
+
} catch (e) {
|
|
1323
|
+
// Skip invalid JSON
|
|
1324
|
+
}
|
|
1325
|
+
}
|
|
1326
|
+
}
|
|
1327
|
+
}
|
|
1328
|
+
|
|
1329
|
+
return {
|
|
1330
|
+
swarms: Array.from(swarmMap.values()),
|
|
1331
|
+
activeAgents,
|
|
1332
|
+
totalTasks,
|
|
1333
|
+
completedTasks,
|
|
1334
|
+
pendingTasks: totalTasks - completedTasks,
|
|
1335
|
+
summary: {
|
|
1336
|
+
totalSwarms: swarmMap.size,
|
|
1337
|
+
activeSwarms: swarmMap.size,
|
|
1338
|
+
},
|
|
1339
|
+
};
|
|
1340
|
+
}
|
|
1341
|
+
} catch (error) {
|
|
1342
|
+
console.error('Error getting swarm status:', error);
|
|
1343
|
+
// Return empty status on error
|
|
1344
|
+
return {
|
|
1345
|
+
swarms: [],
|
|
1346
|
+
activeAgents: 0,
|
|
1347
|
+
totalTasks: 0,
|
|
1348
|
+
completedTasks: 0,
|
|
1349
|
+
pendingTasks: 0,
|
|
1350
|
+
recentActivity: [],
|
|
1351
|
+
summary: {
|
|
1352
|
+
totalSwarms: 0,
|
|
1353
|
+
activeSwarms: 0,
|
|
1354
|
+
idleSwarms: 0,
|
|
1355
|
+
inactiveSwarms: 0,
|
|
1356
|
+
},
|
|
1357
|
+
error: error.message,
|
|
1358
|
+
};
|
|
1359
|
+
}
|
|
1360
|
+
}
|
|
1361
|
+
}
|
|
1362
|
+
|
|
1363
|
+
// Export tool categories for reference
|
|
1364
|
+
export { MCP_TOOLS };
|