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,46 +1,25 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Hive Mind command for Claude-Flow v2.0.0
|
|
3
3
|
* Advanced swarm intelligence with collective decision-making
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import ora from 'ora';
|
|
14
|
-
import { args, cwd, exit, writeTextFile, readTextFile, mkdirAsync } from '../node-compat.js';
|
|
15
|
-
import {
|
|
16
|
-
isInteractive,
|
|
17
|
-
isRawModeSupported,
|
|
18
|
-
warnNonInteractive,
|
|
19
|
-
checkNonInteractiveAuth,
|
|
20
|
-
} from '../utils/interactive-detector.js';
|
|
21
|
-
import {
|
|
22
|
-
safeInteractive,
|
|
23
|
-
nonInteractiveProgress,
|
|
24
|
-
nonInteractiveSelect,
|
|
25
|
-
} from '../utils/safe-interactive.js';
|
|
26
|
-
|
|
4
|
+
*/ import { existsSync, mkdirSync } from "fs";
|
|
5
|
+
import { writeFile } from "node:fs/promises";
|
|
6
|
+
import path from "path";
|
|
7
|
+
import inquirer from "inquirer";
|
|
8
|
+
import chalk from "chalk";
|
|
9
|
+
import ora from "ora";
|
|
10
|
+
import { cwd, exit, mkdirAsync } from "../node-compat.js";
|
|
11
|
+
import { warnNonInteractive } from "../utils/interactive-detector.js";
|
|
12
|
+
import { safeInteractive } from "../utils/safe-interactive.js";
|
|
27
13
|
// Import SQLite for persistence
|
|
28
|
-
import Database from
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
import {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
import {
|
|
35
|
-
import { HiveMindCore } from './hive-mind/core.js';
|
|
36
|
-
import { QueenCoordinator } from './hive-mind/queen.js';
|
|
37
|
-
import { CollectiveMemory } from './hive-mind/memory.js';
|
|
38
|
-
import { SwarmCommunication } from './hive-mind/communication.js';
|
|
39
|
-
import { HiveMindSessionManager } from './hive-mind/session-manager.js';
|
|
40
|
-
import { createAutoSaveMiddleware } from './hive-mind/auto-save-middleware.js';
|
|
41
|
-
|
|
14
|
+
import Database from "better-sqlite3";
|
|
15
|
+
import { HiveMindCore } from "./hive-mind/core.js";
|
|
16
|
+
import { QueenCoordinator } from "./hive-mind/queen.js";
|
|
17
|
+
import { CollectiveMemory } from "./hive-mind/memory.js";
|
|
18
|
+
import { SwarmCommunication } from "./hive-mind/communication.js";
|
|
19
|
+
import { HiveMindSessionManager } from "./hive-mind/session-manager.js";
|
|
20
|
+
import { createAutoSaveMiddleware } from "./hive-mind/auto-save-middleware.js";
|
|
42
21
|
function showHiveMindHelp() {
|
|
43
|
-
|
|
22
|
+
console.log(`
|
|
44
23
|
${chalk.yellow('🧠 Claude Flow Hive Mind System')}
|
|
45
24
|
|
|
46
25
|
${chalk.bold('USAGE:')}
|
|
@@ -114,26 +93,23 @@ ${chalk.bold('For more information:')}
|
|
|
114
93
|
${chalk.blue('https://github.com/ruvnet/claude-flow/tree/main/docs/hive-mind')}
|
|
115
94
|
`);
|
|
116
95
|
}
|
|
117
|
-
|
|
118
96
|
/**
|
|
119
97
|
* Initialize hive mind system
|
|
120
|
-
*/
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
// Create tables
|
|
136
|
-
db.exec(`
|
|
98
|
+
*/ async function initHiveMind(flags) {
|
|
99
|
+
const spinner = ora('Initializing Hive Mind system...').start();
|
|
100
|
+
try {
|
|
101
|
+
// Create hive mind directory structure
|
|
102
|
+
const hiveMindDir = path.join(cwd(), '.hive-mind');
|
|
103
|
+
if (!existsSync(hiveMindDir)) {
|
|
104
|
+
mkdirSync(hiveMindDir, {
|
|
105
|
+
recursive: true
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
// Initialize SQLite database
|
|
109
|
+
const dbPath = path.join(hiveMindDir, 'hive.db');
|
|
110
|
+
const db = new Database(dbPath);
|
|
111
|
+
// Create tables
|
|
112
|
+
db.exec(`
|
|
137
113
|
CREATE TABLE IF NOT EXISTS swarms (
|
|
138
114
|
id TEXT PRIMARY KEY,
|
|
139
115
|
name TEXT NOT NULL,
|
|
@@ -198,103 +174,108 @@ async function initHiveMind(flags) {
|
|
|
198
174
|
FOREIGN KEY (swarm_id) REFERENCES swarms(id)
|
|
199
175
|
);
|
|
200
176
|
`);
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
);
|
|
234
|
-
console.log(
|
|
235
|
-
' 2. Use ' + chalk.cyan('claude-flow-novice hive-mind wizard') + ' for interactive setup',
|
|
236
|
-
);
|
|
237
|
-
} catch (error) {
|
|
238
|
-
spinner.fail('Failed to initialize Hive Mind system');
|
|
239
|
-
console.error(chalk.red('Error:'), error.message);
|
|
240
|
-
exit(1);
|
|
241
|
-
}
|
|
177
|
+
db.close();
|
|
178
|
+
// Create configuration file
|
|
179
|
+
const config = {
|
|
180
|
+
version: '2.0.0',
|
|
181
|
+
initialized: new Date().toISOString(),
|
|
182
|
+
defaults: {
|
|
183
|
+
queenType: 'strategic',
|
|
184
|
+
maxWorkers: 8,
|
|
185
|
+
consensusAlgorithm: 'majority',
|
|
186
|
+
memorySize: 100,
|
|
187
|
+
autoScale: true,
|
|
188
|
+
encryption: false
|
|
189
|
+
},
|
|
190
|
+
mcpTools: {
|
|
191
|
+
enabled: true,
|
|
192
|
+
parallel: true,
|
|
193
|
+
timeout: 60000
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
await writeFile(path.join(hiveMindDir, 'config.json'), JSON.stringify(config, null, 2));
|
|
197
|
+
spinner.succeed('Hive Mind system initialized successfully!');
|
|
198
|
+
console.log('\n' + chalk.green('✓') + ' Created .hive-mind directory');
|
|
199
|
+
console.log(chalk.green('✓') + ' Initialized SQLite database');
|
|
200
|
+
console.log(chalk.green('✓') + ' Created configuration file');
|
|
201
|
+
console.log('\n' + chalk.yellow('Next steps:'));
|
|
202
|
+
console.log(' 1. Run ' + chalk.cyan('claude-flow-novice hive-mind spawn') + ' to create your first swarm');
|
|
203
|
+
console.log(' 2. Use ' + chalk.cyan('claude-flow-novice hive-mind wizard') + ' for interactive setup');
|
|
204
|
+
} catch (error) {
|
|
205
|
+
spinner.fail('Failed to initialize Hive Mind system');
|
|
206
|
+
console.error(chalk.red('Error:'), error.message);
|
|
207
|
+
exit(1);
|
|
208
|
+
}
|
|
242
209
|
}
|
|
243
|
-
|
|
244
210
|
/**
|
|
245
211
|
* Interactive wizard for hive mind operations
|
|
246
|
-
*/
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
// Interactive version
|
|
250
|
-
async function (flags = {}) {
|
|
212
|
+
*/ // Wrapped wizard function that handles non-interactive environments
|
|
213
|
+
const hiveMindWizard = safeInteractive(// Interactive version
|
|
214
|
+
async function(flags = {}) {
|
|
251
215
|
console.log(chalk.yellow('\n🧙 Hive Mind Interactive Wizard\n'));
|
|
252
|
-
|
|
253
216
|
const { action } = await inquirer.prompt([
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
217
|
+
{
|
|
218
|
+
type: 'list',
|
|
219
|
+
name: 'action',
|
|
220
|
+
message: 'What would you like to do?',
|
|
221
|
+
choices: [
|
|
222
|
+
{
|
|
223
|
+
name: '🐝 Create new swarm',
|
|
224
|
+
value: 'spawn'
|
|
225
|
+
},
|
|
226
|
+
{
|
|
227
|
+
name: '📊 View swarm status',
|
|
228
|
+
value: 'status'
|
|
229
|
+
},
|
|
230
|
+
{
|
|
231
|
+
name: '🧠 Manage collective memory',
|
|
232
|
+
value: 'memory'
|
|
233
|
+
},
|
|
234
|
+
{
|
|
235
|
+
name: '🤝 View consensus decisions',
|
|
236
|
+
value: 'consensus'
|
|
237
|
+
},
|
|
238
|
+
{
|
|
239
|
+
name: '📈 Performance metrics',
|
|
240
|
+
value: 'metrics'
|
|
241
|
+
},
|
|
242
|
+
{
|
|
243
|
+
name: '🔧 Configure hive mind',
|
|
244
|
+
value: 'config'
|
|
245
|
+
},
|
|
246
|
+
{
|
|
247
|
+
name: '❌ Exit',
|
|
248
|
+
value: 'exit'
|
|
249
|
+
}
|
|
250
|
+
]
|
|
251
|
+
}
|
|
268
252
|
]);
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
break;
|
|
253
|
+
switch(action){
|
|
254
|
+
case 'spawn':
|
|
255
|
+
await spawnSwarmWizard();
|
|
256
|
+
break;
|
|
257
|
+
case 'status':
|
|
258
|
+
await showStatus({});
|
|
259
|
+
break;
|
|
260
|
+
case 'memory':
|
|
261
|
+
await manageMemoryWizard();
|
|
262
|
+
break;
|
|
263
|
+
case 'consensus':
|
|
264
|
+
await showConsensus({});
|
|
265
|
+
break;
|
|
266
|
+
case 'metrics':
|
|
267
|
+
await showMetrics({});
|
|
268
|
+
break;
|
|
269
|
+
case 'config':
|
|
270
|
+
await configureWizard();
|
|
271
|
+
break;
|
|
272
|
+
case 'exit':
|
|
273
|
+
console.log(chalk.gray('Exiting wizard...'));
|
|
274
|
+
break;
|
|
292
275
|
}
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
async function (flags = {}) {
|
|
276
|
+
}, // Non-interactive fallback
|
|
277
|
+
async function(flags = {}) {
|
|
296
278
|
console.log(chalk.yellow('\n🧙 Hive Mind - Non-Interactive Mode\n'));
|
|
297
|
-
|
|
298
279
|
// Default to creating a swarm with sensible defaults
|
|
299
280
|
console.log(chalk.cyan('Creating new swarm with default settings...'));
|
|
300
281
|
console.log(chalk.gray('Use command-line flags to customize:'));
|
|
@@ -302,251 +283,277 @@ const hiveMindWizard = safeInteractive(
|
|
|
302
283
|
console.log(chalk.gray(' --queen-type strategic Set queen type'));
|
|
303
284
|
console.log(chalk.gray(' --max-workers 8 Set worker count'));
|
|
304
285
|
console.log();
|
|
305
|
-
|
|
306
286
|
const objective = flags.objective || 'General task coordination';
|
|
307
287
|
const config = {
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
288
|
+
name: flags.name || `swarm-${Date.now()}`,
|
|
289
|
+
queenType: flags.queenType || flags['queen-type'] || 'strategic',
|
|
290
|
+
maxWorkers: parseInt(flags.maxWorkers || flags['max-workers'] || '8'),
|
|
291
|
+
consensusAlgorithm: flags.consensus || flags.consensusAlgorithm || 'majority',
|
|
292
|
+
autoScale: flags.autoScale || flags['auto-scale'] || false,
|
|
293
|
+
namespace: flags.namespace || 'default',
|
|
294
|
+
verbose: flags.verbose || false,
|
|
295
|
+
encryption: flags.encryption || false
|
|
316
296
|
};
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
297
|
+
await spawnSwarm([
|
|
298
|
+
objective
|
|
299
|
+
], {
|
|
300
|
+
...flags,
|
|
301
|
+
name: config.name,
|
|
302
|
+
queenType: config.queenType,
|
|
303
|
+
maxWorkers: config.maxWorkers,
|
|
304
|
+
consensusAlgorithm: config.consensusAlgorithm,
|
|
305
|
+
autoScale: config.autoScale,
|
|
306
|
+
encryption: config.encryption,
|
|
307
|
+
nonInteractive: true
|
|
327
308
|
});
|
|
328
|
-
|
|
329
|
-
);
|
|
330
|
-
|
|
309
|
+
});
|
|
331
310
|
/**
|
|
332
311
|
* Spawn swarm wizard
|
|
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
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
{
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
312
|
+
*/ async function spawnSwarmWizard() {
|
|
313
|
+
const answers = await inquirer.prompt([
|
|
314
|
+
{
|
|
315
|
+
type: 'input',
|
|
316
|
+
name: 'objective',
|
|
317
|
+
message: 'What is the swarm objective?',
|
|
318
|
+
validate: (input)=>input.trim().length > 0 || 'Please enter an objective'
|
|
319
|
+
},
|
|
320
|
+
{
|
|
321
|
+
type: 'input',
|
|
322
|
+
name: 'name',
|
|
323
|
+
message: 'Swarm name (optional):',
|
|
324
|
+
default: (answers)=>`swarm-${Date.now()}`
|
|
325
|
+
},
|
|
326
|
+
{
|
|
327
|
+
type: 'list',
|
|
328
|
+
name: 'queenType',
|
|
329
|
+
message: 'Select queen coordinator type:',
|
|
330
|
+
choices: [
|
|
331
|
+
{
|
|
332
|
+
name: 'Strategic - High-level planning and coordination',
|
|
333
|
+
value: 'strategic'
|
|
334
|
+
},
|
|
335
|
+
{
|
|
336
|
+
name: 'Tactical - Detailed task management',
|
|
337
|
+
value: 'tactical'
|
|
338
|
+
},
|
|
339
|
+
{
|
|
340
|
+
name: 'Adaptive - Learns and adapts strategies',
|
|
341
|
+
value: 'adaptive'
|
|
342
|
+
}
|
|
343
|
+
],
|
|
344
|
+
default: 'strategic'
|
|
345
|
+
},
|
|
346
|
+
{
|
|
347
|
+
type: 'number',
|
|
348
|
+
name: 'maxWorkers',
|
|
349
|
+
message: 'Maximum number of worker agents:',
|
|
350
|
+
default: 8,
|
|
351
|
+
validate: (input)=>input > 0 && input <= 20 || 'Please enter a number between 1 and 20'
|
|
352
|
+
},
|
|
353
|
+
{
|
|
354
|
+
type: 'checkbox',
|
|
355
|
+
name: 'workerTypes',
|
|
356
|
+
message: 'Select worker agent types:',
|
|
357
|
+
choices: [
|
|
358
|
+
{
|
|
359
|
+
name: 'Researcher',
|
|
360
|
+
value: 'researcher',
|
|
361
|
+
checked: true
|
|
362
|
+
},
|
|
363
|
+
{
|
|
364
|
+
name: 'Coder',
|
|
365
|
+
value: 'coder',
|
|
366
|
+
checked: true
|
|
367
|
+
},
|
|
368
|
+
{
|
|
369
|
+
name: 'Analyst',
|
|
370
|
+
value: 'analyst',
|
|
371
|
+
checked: true
|
|
372
|
+
},
|
|
373
|
+
{
|
|
374
|
+
name: 'Tester',
|
|
375
|
+
value: 'tester',
|
|
376
|
+
checked: true
|
|
377
|
+
},
|
|
378
|
+
{
|
|
379
|
+
name: 'Architect',
|
|
380
|
+
value: 'architect'
|
|
381
|
+
},
|
|
382
|
+
{
|
|
383
|
+
name: 'Reviewer',
|
|
384
|
+
value: 'reviewer'
|
|
385
|
+
},
|
|
386
|
+
{
|
|
387
|
+
name: 'Optimizer',
|
|
388
|
+
value: 'optimizer'
|
|
389
|
+
},
|
|
390
|
+
{
|
|
391
|
+
name: 'Documenter',
|
|
392
|
+
value: 'documenter'
|
|
393
|
+
}
|
|
394
|
+
]
|
|
395
|
+
},
|
|
396
|
+
{
|
|
397
|
+
type: 'list',
|
|
398
|
+
name: 'consensusAlgorithm',
|
|
399
|
+
message: 'Consensus algorithm for decisions:',
|
|
400
|
+
choices: [
|
|
401
|
+
{
|
|
402
|
+
name: 'Majority - Simple majority voting',
|
|
403
|
+
value: 'majority'
|
|
404
|
+
},
|
|
405
|
+
{
|
|
406
|
+
name: 'Weighted - Expertise-weighted voting',
|
|
407
|
+
value: 'weighted'
|
|
408
|
+
},
|
|
409
|
+
{
|
|
410
|
+
name: 'Byzantine - Fault-tolerant consensus',
|
|
411
|
+
value: 'byzantine'
|
|
412
|
+
}
|
|
413
|
+
],
|
|
414
|
+
default: 'majority'
|
|
415
|
+
},
|
|
416
|
+
{
|
|
417
|
+
type: 'confirm',
|
|
418
|
+
name: 'autoScale',
|
|
419
|
+
message: 'Enable auto-scaling?',
|
|
420
|
+
default: true
|
|
421
|
+
},
|
|
422
|
+
{
|
|
423
|
+
type: 'confirm',
|
|
424
|
+
name: 'monitor',
|
|
425
|
+
message: 'Launch monitoring dashboard?',
|
|
426
|
+
default: true
|
|
427
|
+
}
|
|
428
|
+
]);
|
|
429
|
+
// Spawn the swarm with collected parameters
|
|
430
|
+
await spawnSwarm([
|
|
431
|
+
answers.objective
|
|
432
|
+
], {
|
|
433
|
+
name: answers.name,
|
|
434
|
+
queenType: answers.queenType,
|
|
435
|
+
'queen-type': answers.queenType,
|
|
436
|
+
maxWorkers: answers.maxWorkers,
|
|
437
|
+
'max-workers': answers.maxWorkers,
|
|
438
|
+
workerTypes: answers.workerTypes.join(','),
|
|
439
|
+
consensus: answers.consensusAlgorithm,
|
|
440
|
+
autoScale: answers.autoScale,
|
|
441
|
+
'auto-scale': answers.autoScale,
|
|
442
|
+
monitor: answers.monitor,
|
|
443
|
+
namespace: answers.namespace || 'default',
|
|
444
|
+
verbose: answers.verbose || false
|
|
445
|
+
});
|
|
421
446
|
}
|
|
422
|
-
|
|
423
447
|
/**
|
|
424
448
|
* Spawn a hive mind swarm
|
|
425
|
-
*/
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
console.log('Example: claude-flow-novice hive-mind spawn "Build REST API"');
|
|
449
|
+
*/ async function spawnSwarm(args, flags) {
|
|
450
|
+
const objective = args.join(' ').trim();
|
|
451
|
+
// Check for non-interactive mode FIRST
|
|
452
|
+
const isNonInteractive = flags['non-interactive'] || flags.nonInteractive;
|
|
453
|
+
if (!objective && !flags.wizard) {
|
|
454
|
+
if (isNonInteractive) {
|
|
455
|
+
console.error(chalk.red('Error: Objective required in non-interactive mode'));
|
|
456
|
+
console.log('Usage: claude-flow-novice hive-mind spawn "Your objective" --non-interactive');
|
|
457
|
+
} else {
|
|
458
|
+
console.error(chalk.red('Error: Please provide an objective or use --wizard flag'));
|
|
459
|
+
console.log('Example: claude-flow-novice hive-mind spawn "Build REST API"');
|
|
460
|
+
}
|
|
461
|
+
return;
|
|
439
462
|
}
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
// Log non-interactive mode status
|
|
444
|
-
if (isNonInteractive && flags.verbose) {
|
|
445
|
-
console.log(chalk.cyan('🤖 Running in non-interactive mode'));
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
// Validate parameters
|
|
449
|
-
if (flags.verbose) {
|
|
450
|
-
console.log(chalk.gray('🔍 Debug: Parsed flags:'));
|
|
451
|
-
console.log(chalk.gray(JSON.stringify(flags, null, 2)));
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
// Validate queen type
|
|
455
|
-
const validQueenTypes = ['strategic', 'tactical', 'adaptive'];
|
|
456
|
-
const queenType = flags.queenType || flags['queen-type'] || 'strategic';
|
|
457
|
-
if (!validQueenTypes.includes(queenType)) {
|
|
458
|
-
console.error(
|
|
459
|
-
chalk.red(
|
|
460
|
-
`Error: Invalid queen type '${queenType}'. Must be one of: ${validQueenTypes.join(', ')}`,
|
|
461
|
-
),
|
|
462
|
-
);
|
|
463
|
-
return;
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
// Validate max workers
|
|
467
|
-
const maxWorkers = parseInt(flags.maxWorkers || flags['max-workers'] || '8');
|
|
468
|
-
if (isNaN(maxWorkers) || maxWorkers < 1 || maxWorkers > 20) {
|
|
469
|
-
console.error(chalk.red('Error: max-workers must be a number between 1 and 20'));
|
|
470
|
-
return;
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
// Validate consensus algorithm
|
|
474
|
-
const validConsensusTypes = ['majority', 'weighted', 'byzantine'];
|
|
475
|
-
const consensusAlgorithm = flags.consensus || flags.consensusAlgorithm || 'majority';
|
|
476
|
-
if (!validConsensusTypes.includes(consensusAlgorithm)) {
|
|
477
|
-
console.error(
|
|
478
|
-
chalk.red(
|
|
479
|
-
`Error: Invalid consensus algorithm '${consensusAlgorithm}'. Must be one of: ${validConsensusTypes.join(', ')}`,
|
|
480
|
-
),
|
|
481
|
-
);
|
|
482
|
-
return;
|
|
483
|
-
}
|
|
484
|
-
|
|
485
|
-
const spinner = ora('Spawning Hive Mind swarm...').start();
|
|
486
|
-
|
|
487
|
-
try {
|
|
488
|
-
// Initialize hive mind core with error handling
|
|
489
|
-
let hiveMind;
|
|
490
|
-
try {
|
|
491
|
-
spinner.text = 'Initializing Hive Mind Core...';
|
|
492
|
-
hiveMind = new HiveMindCore({
|
|
493
|
-
objective,
|
|
494
|
-
name: flags.name || `hive-${Date.now()}`,
|
|
495
|
-
queenType: flags.queenType || flags['queen-type'] || 'strategic',
|
|
496
|
-
maxWorkers: parseInt(flags.maxWorkers || flags['max-workers'] || '8'),
|
|
497
|
-
consensusAlgorithm: flags.consensus || flags.consensusAlgorithm || 'majority',
|
|
498
|
-
autoScale:
|
|
499
|
-
flags.autoScale !== undefined
|
|
500
|
-
? flags.autoScale
|
|
501
|
-
: flags['auto-scale'] !== undefined
|
|
502
|
-
? flags['auto-scale']
|
|
503
|
-
: true,
|
|
504
|
-
namespace: flags.namespace || 'default',
|
|
505
|
-
encryption: flags.encryption || false,
|
|
506
|
-
});
|
|
507
|
-
} catch (error) {
|
|
508
|
-
console.error('HiveMindCore initialization failed:', error);
|
|
509
|
-
throw new Error(`Failed to initialize HiveMindCore: ${error.message}`);
|
|
463
|
+
// Log non-interactive mode status
|
|
464
|
+
if (isNonInteractive && flags.verbose) {
|
|
465
|
+
console.log(chalk.cyan('🤖 Running in non-interactive mode'));
|
|
510
466
|
}
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
const dbPath = path.join(dbDir, 'hive.db');
|
|
516
|
-
|
|
517
|
-
// Ensure .hive-mind directory exists
|
|
518
|
-
if (!existsSync(dbDir)) {
|
|
519
|
-
mkdirSync(dbDir, { recursive: true });
|
|
467
|
+
// Validate parameters
|
|
468
|
+
if (flags.verbose) {
|
|
469
|
+
console.log(chalk.gray('🔍 Debug: Parsed flags:'));
|
|
470
|
+
console.log(chalk.gray(JSON.stringify(flags, null, 2)));
|
|
520
471
|
}
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
472
|
+
// Validate queen type
|
|
473
|
+
const validQueenTypes = [
|
|
474
|
+
'strategic',
|
|
475
|
+
'tactical',
|
|
476
|
+
'adaptive'
|
|
477
|
+
];
|
|
478
|
+
const queenType = flags.queenType || flags['queen-type'] || 'strategic';
|
|
479
|
+
if (!validQueenTypes.includes(queenType)) {
|
|
480
|
+
console.error(chalk.red(`Error: Invalid queen type '${queenType}'. Must be one of: ${validQueenTypes.join(', ')}`));
|
|
481
|
+
return;
|
|
482
|
+
}
|
|
483
|
+
// Validate max workers
|
|
484
|
+
const maxWorkers = parseInt(flags.maxWorkers || flags['max-workers'] || '8');
|
|
485
|
+
if (isNaN(maxWorkers) || maxWorkers < 1 || maxWorkers > 20) {
|
|
486
|
+
console.error(chalk.red('Error: max-workers must be a number between 1 and 20'));
|
|
487
|
+
return;
|
|
488
|
+
}
|
|
489
|
+
// Validate consensus algorithm
|
|
490
|
+
const validConsensusTypes = [
|
|
491
|
+
'majority',
|
|
492
|
+
'weighted',
|
|
493
|
+
'byzantine'
|
|
494
|
+
];
|
|
495
|
+
const consensusAlgorithm = flags.consensus || flags.consensusAlgorithm || 'majority';
|
|
496
|
+
if (!validConsensusTypes.includes(consensusAlgorithm)) {
|
|
497
|
+
console.error(chalk.red(`Error: Invalid consensus algorithm '${consensusAlgorithm}'. Must be one of: ${validConsensusTypes.join(', ')}`));
|
|
498
|
+
return;
|
|
499
|
+
}
|
|
500
|
+
const spinner = ora('Spawning Hive Mind swarm...').start();
|
|
524
501
|
try {
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
// Test the database with a simple query
|
|
528
|
-
db.prepare('SELECT 1').get();
|
|
529
|
-
spinner.text = 'Database connection established';
|
|
530
|
-
} catch (error) {
|
|
531
|
-
console.warn('Database issue detected, recreating...', error.message);
|
|
532
|
-
spinner.text = 'Recreating database...';
|
|
533
|
-
// Remove corrupted database
|
|
534
|
-
if (existsSync(dbPath)) {
|
|
502
|
+
// Initialize hive mind core with error handling
|
|
503
|
+
let hiveMind;
|
|
535
504
|
try {
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
505
|
+
spinner.text = 'Initializing Hive Mind Core...';
|
|
506
|
+
hiveMind = new HiveMindCore({
|
|
507
|
+
objective,
|
|
508
|
+
name: flags.name || `hive-${Date.now()}`,
|
|
509
|
+
queenType: flags.queenType || flags['queen-type'] || 'strategic',
|
|
510
|
+
maxWorkers: parseInt(flags.maxWorkers || flags['max-workers'] || '8'),
|
|
511
|
+
consensusAlgorithm: flags.consensus || flags.consensusAlgorithm || 'majority',
|
|
512
|
+
autoScale: flags.autoScale !== undefined ? flags.autoScale : flags['auto-scale'] !== undefined ? flags['auto-scale'] : true,
|
|
513
|
+
namespace: flags.namespace || 'default',
|
|
514
|
+
encryption: flags.encryption || false
|
|
515
|
+
});
|
|
516
|
+
} catch (error) {
|
|
517
|
+
console.error('HiveMindCore initialization failed:', error);
|
|
518
|
+
throw new Error(`Failed to initialize HiveMindCore: ${error.message}`);
|
|
540
519
|
}
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
520
|
+
spinner.text = 'Setting up database connection...';
|
|
521
|
+
// Initialize database connection
|
|
522
|
+
const dbDir = path.join(cwd(), '.hive-mind');
|
|
523
|
+
const dbPath = path.join(dbDir, 'hive.db');
|
|
524
|
+
// Ensure .hive-mind directory exists
|
|
525
|
+
if (!existsSync(dbDir)) {
|
|
526
|
+
mkdirSync(dbDir, {
|
|
527
|
+
recursive: true
|
|
528
|
+
});
|
|
529
|
+
}
|
|
530
|
+
// Check if database file exists and try to create a clean one if needed
|
|
531
|
+
let db;
|
|
532
|
+
try {
|
|
533
|
+
spinner.text = 'Creating database connection...';
|
|
534
|
+
db = new Database(dbPath);
|
|
535
|
+
// Test the database with a simple query
|
|
536
|
+
db.prepare('SELECT 1').get();
|
|
537
|
+
spinner.text = 'Database connection established';
|
|
538
|
+
} catch (error) {
|
|
539
|
+
console.warn('Database issue detected, recreating...', error.message);
|
|
540
|
+
spinner.text = 'Recreating database...';
|
|
541
|
+
// Remove corrupted database
|
|
542
|
+
if (existsSync(dbPath)) {
|
|
543
|
+
try {
|
|
544
|
+
const fs = await import("fs");
|
|
545
|
+
fs.unlinkSync(dbPath);
|
|
546
|
+
} catch (e) {
|
|
547
|
+
console.warn('Could not remove corrupted database:', e.message);
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
// Create new database
|
|
551
|
+
db = new Database(dbPath);
|
|
552
|
+
}
|
|
553
|
+
// Initialize database schema if not exists
|
|
554
|
+
spinner.text = 'Creating database schema...';
|
|
555
|
+
try {
|
|
556
|
+
db.exec(`
|
|
550
557
|
CREATE TABLE IF NOT EXISTS swarms (
|
|
551
558
|
id TEXT PRIMARY KEY,
|
|
552
559
|
name TEXT NOT NULL,
|
|
@@ -649,356 +656,326 @@ async function spawnSwarm(args, flags) {
|
|
|
649
656
|
FOREIGN KEY (session_id) REFERENCES sessions(id)
|
|
650
657
|
);
|
|
651
658
|
`);
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
db.prepare(
|
|
665
|
-
`
|
|
659
|
+
spinner.text = 'Database schema created successfully';
|
|
660
|
+
} catch (error) {
|
|
661
|
+
console.error('Database schema creation failed:', error);
|
|
662
|
+
throw new Error(`Failed to create database schema: ${error.message}`);
|
|
663
|
+
}
|
|
664
|
+
// Create swarm record with safe ID generation
|
|
665
|
+
spinner.text = 'Creating swarm record...';
|
|
666
|
+
const timestamp = Date.now();
|
|
667
|
+
const randomPart = Math.random().toString(36).substring(2, 11); // Use substring instead of substr
|
|
668
|
+
const swarmId = `swarm-${timestamp}-${randomPart}`;
|
|
669
|
+
try {
|
|
670
|
+
db.prepare(`
|
|
666
671
|
INSERT INTO swarms (id, name, objective, queen_type)
|
|
667
672
|
VALUES (?, ?, ?, ?)
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
role: 'queen',
|
|
722
|
-
status: 'active',
|
|
723
|
-
capabilities: JSON.stringify(['coordination', 'planning', 'decision-making']),
|
|
724
|
-
};
|
|
725
|
-
|
|
726
|
-
db.prepare(
|
|
727
|
-
`
|
|
673
|
+
`).run(swarmId, hiveMind.config.name, objective, hiveMind.config.queenType);
|
|
674
|
+
} catch (error) {
|
|
675
|
+
console.error('Failed to create swarm record:', error);
|
|
676
|
+
throw new Error(`Failed to create swarm record: ${error.message}`);
|
|
677
|
+
}
|
|
678
|
+
// Create session for this swarm
|
|
679
|
+
spinner.text = 'Creating session tracking...';
|
|
680
|
+
const sessionManager = new HiveMindSessionManager();
|
|
681
|
+
const sessionId = await sessionManager.createSession(swarmId, hiveMind.config.name, objective, {
|
|
682
|
+
queenType: hiveMind.config.queenType,
|
|
683
|
+
maxWorkers: hiveMind.config.maxWorkers,
|
|
684
|
+
consensusAlgorithm: hiveMind.config.consensusAlgorithm,
|
|
685
|
+
autoScale: hiveMind.config.autoScale,
|
|
686
|
+
encryption: hiveMind.config.encryption,
|
|
687
|
+
workerTypes: flags.workerTypes
|
|
688
|
+
});
|
|
689
|
+
spinner.text = 'Session tracking established...';
|
|
690
|
+
// Initialize auto-save middleware (use the same session manager)
|
|
691
|
+
const autoSave = createAutoSaveMiddleware(sessionId, sessionManager, {
|
|
692
|
+
saveInterval: 30000,
|
|
693
|
+
autoStart: true
|
|
694
|
+
});
|
|
695
|
+
// Close session manager after auto-save is set up
|
|
696
|
+
// sessionManager.close(); // Don't close yet as auto-save needs it
|
|
697
|
+
// Track initial swarm creation
|
|
698
|
+
autoSave.trackChange('swarm_created', {
|
|
699
|
+
swarmId,
|
|
700
|
+
swarmName: hiveMind.config.name,
|
|
701
|
+
objective,
|
|
702
|
+
workerCount: hiveMind.config.maxWorkers
|
|
703
|
+
});
|
|
704
|
+
spinner.text = 'Initializing Queen coordinator...';
|
|
705
|
+
// Initialize Queen
|
|
706
|
+
const queen = new QueenCoordinator({
|
|
707
|
+
swarmId,
|
|
708
|
+
type: hiveMind.config.queenType,
|
|
709
|
+
objective
|
|
710
|
+
});
|
|
711
|
+
// Spawn Queen agent
|
|
712
|
+
const queenAgent = {
|
|
713
|
+
id: `queen-${swarmId}`,
|
|
714
|
+
swarmId,
|
|
715
|
+
name: 'Queen Coordinator',
|
|
716
|
+
type: 'coordinator',
|
|
717
|
+
role: 'queen',
|
|
718
|
+
status: 'active',
|
|
719
|
+
capabilities: JSON.stringify([
|
|
720
|
+
'coordination',
|
|
721
|
+
'planning',
|
|
722
|
+
'decision-making'
|
|
723
|
+
])
|
|
724
|
+
};
|
|
725
|
+
db.prepare(`
|
|
728
726
|
INSERT INTO agents (id, swarm_id, name, type, role, status, capabilities)
|
|
729
727
|
VALUES (?, ?, ?, ?, ?, ?, ?)
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
workers.push(worker);
|
|
757
|
-
|
|
758
|
-
db.prepare(
|
|
759
|
-
`
|
|
728
|
+
`).run(...Object.values(queenAgent));
|
|
729
|
+
spinner.text = 'Spawning worker agents...';
|
|
730
|
+
// Determine worker types
|
|
731
|
+
const workerTypes = flags.workerTypes ? flags.workerTypes.split(',') : [
|
|
732
|
+
'researcher',
|
|
733
|
+
'coder',
|
|
734
|
+
'analyst',
|
|
735
|
+
'tester'
|
|
736
|
+
];
|
|
737
|
+
// Spawn worker agents
|
|
738
|
+
const workers = [];
|
|
739
|
+
for(let i = 0; i < Math.min(workerTypes.length, hiveMind.config.maxWorkers); i++){
|
|
740
|
+
const workerType = workerTypes[i % workerTypes.length];
|
|
741
|
+
const workerId = `worker-${swarmId}-${i}`;
|
|
742
|
+
const worker = {
|
|
743
|
+
id: workerId,
|
|
744
|
+
swarmId,
|
|
745
|
+
name: `${workerType.charAt(0).toUpperCase() + workerType.slice(1)} Worker ${i + 1}`,
|
|
746
|
+
type: workerType,
|
|
747
|
+
role: 'worker',
|
|
748
|
+
status: 'idle',
|
|
749
|
+
capabilities: JSON.stringify(getAgentCapabilities(workerType))
|
|
750
|
+
};
|
|
751
|
+
workers.push(worker);
|
|
752
|
+
db.prepare(`
|
|
760
753
|
INSERT INTO agents (id, swarm_id, name, type, role, status, capabilities)
|
|
761
754
|
VALUES (?, ?, ?, ?, ?, ?, ?)
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
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
|
-
|
|
755
|
+
`).run(...Object.values(worker));
|
|
756
|
+
// Track agent spawning for auto-save
|
|
757
|
+
autoSave.trackAgentActivity(workerId, 'spawned', {
|
|
758
|
+
type: workerType,
|
|
759
|
+
name: worker.name
|
|
760
|
+
});
|
|
761
|
+
}
|
|
762
|
+
spinner.text = 'Initializing collective memory...';
|
|
763
|
+
// Initialize collective memory
|
|
764
|
+
const memory = new CollectiveMemory({
|
|
765
|
+
swarmId,
|
|
766
|
+
maxSize: flags.memorySize || 100
|
|
767
|
+
});
|
|
768
|
+
// Store initial context
|
|
769
|
+
memory.store('objective', objective, 'context');
|
|
770
|
+
memory.store('queen_type', hiveMind.config.queenType, 'config');
|
|
771
|
+
memory.store('worker_count', workers.length, 'metrics');
|
|
772
|
+
memory.store('session_id', sessionId, 'system');
|
|
773
|
+
spinner.text = 'Establishing communication channels...';
|
|
774
|
+
// Initialize communication system
|
|
775
|
+
const communication = new SwarmCommunication({
|
|
776
|
+
swarmId,
|
|
777
|
+
encryption: hiveMind.config.encryption
|
|
778
|
+
});
|
|
779
|
+
db.close();
|
|
780
|
+
spinner.succeed('Hive Mind swarm spawned successfully!');
|
|
781
|
+
// Display swarm summary
|
|
782
|
+
console.log('\n' + chalk.bold('🐝 Swarm Summary:'));
|
|
783
|
+
console.log(chalk.gray('─'.repeat(50)));
|
|
784
|
+
console.log(chalk.cyan('Swarm ID:'), swarmId);
|
|
785
|
+
console.log(chalk.cyan('Session ID:'), sessionId);
|
|
786
|
+
console.log(chalk.cyan('Name:'), hiveMind.config.name);
|
|
787
|
+
console.log(chalk.cyan('Objective:'), objective);
|
|
788
|
+
console.log(chalk.cyan('Queen Type:'), hiveMind.config.queenType);
|
|
789
|
+
console.log(chalk.cyan('Workers:'), workers.length);
|
|
790
|
+
console.log(chalk.cyan('Worker Types:'), workerTypes.join(', '));
|
|
791
|
+
console.log(chalk.cyan('Consensus:'), hiveMind.config.consensusAlgorithm);
|
|
792
|
+
console.log(chalk.cyan('Auto-scaling:'), hiveMind.config.autoScale ? 'Enabled' : 'Disabled');
|
|
793
|
+
console.log(chalk.gray('─'.repeat(50)));
|
|
794
|
+
// Launch monitoring if requested
|
|
795
|
+
if (flags.monitor) {
|
|
796
|
+
console.log('\n' + chalk.yellow('Launching monitoring dashboard...'));
|
|
797
|
+
// TODO: Implement monitoring dashboard
|
|
798
|
+
}
|
|
799
|
+
// Enhanced coordination instructions with MCP tools
|
|
800
|
+
console.log('\n' + chalk.green('✓') + ' Swarm is ready for coordination');
|
|
801
|
+
console.log(chalk.gray('Use "claude-flow-novice hive-mind status" to view swarm activity'));
|
|
802
|
+
console.log(chalk.gray('Session auto-save enabled - progress saved every 30 seconds'));
|
|
803
|
+
console.log(chalk.blue('💡 To pause:') + ' Press Ctrl+C to safely pause and resume later');
|
|
804
|
+
console.log(chalk.blue('💡 To resume:') + ' claude-flow-novice hive-mind resume ' + sessionId);
|
|
805
|
+
// Set up SIGINT handler for automatic session pausing
|
|
806
|
+
let isExiting = false;
|
|
807
|
+
const sigintHandler = async ()=>{
|
|
808
|
+
if (isExiting) return;
|
|
809
|
+
isExiting = true;
|
|
810
|
+
console.log('\n\n' + chalk.yellow('⏸️ Pausing session...'));
|
|
811
|
+
try {
|
|
812
|
+
// Save current checkpoint using the existing session manager
|
|
813
|
+
// const sessionManager = new HiveMindSessionManager(); // Use existing one
|
|
814
|
+
// Create checkpoint data
|
|
815
|
+
const checkpointData = {
|
|
816
|
+
timestamp: new Date().toISOString(),
|
|
817
|
+
swarmId,
|
|
818
|
+
objective,
|
|
819
|
+
workerCount: workers.length,
|
|
820
|
+
workerTypes,
|
|
821
|
+
status: 'paused_by_user',
|
|
822
|
+
reason: 'User pressed Ctrl+C'
|
|
823
|
+
};
|
|
824
|
+
// Save checkpoint
|
|
825
|
+
await sessionManager.saveCheckpoint(sessionId, 'auto-pause', checkpointData);
|
|
826
|
+
// Pause the session
|
|
827
|
+
await sessionManager.pauseSession(sessionId);
|
|
828
|
+
// Close session manager
|
|
829
|
+
sessionManager.close();
|
|
830
|
+
console.log(chalk.green('✓') + ' Session paused successfully');
|
|
831
|
+
console.log(chalk.cyan('\nTo resume this session, run:'));
|
|
832
|
+
console.log(chalk.bold(` claude-flow-novice hive-mind resume ${sessionId}`));
|
|
833
|
+
console.log();
|
|
834
|
+
// Clean up auto-save if active
|
|
835
|
+
if (global.autoSaveInterval) {
|
|
836
|
+
clearInterval(global.autoSaveInterval);
|
|
837
|
+
}
|
|
838
|
+
process.exit(0);
|
|
839
|
+
} catch (error) {
|
|
840
|
+
console.error(chalk.red('Error pausing session:'), error.message);
|
|
841
|
+
process.exit(1);
|
|
842
|
+
}
|
|
846
843
|
};
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
//
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
console.log(chalk.green('✓') + ' Session paused successfully');
|
|
858
|
-
console.log(chalk.cyan('\nTo resume this session, run:'));
|
|
859
|
-
console.log(chalk.bold(` claude-flow-novice hive-mind resume ${sessionId}`));
|
|
860
|
-
console.log();
|
|
861
|
-
|
|
862
|
-
// Clean up auto-save if active
|
|
863
|
-
if (global.autoSaveInterval) {
|
|
864
|
-
clearInterval(global.autoSaveInterval);
|
|
844
|
+
// Register SIGINT handler
|
|
845
|
+
process.on('SIGINT', sigintHandler);
|
|
846
|
+
process.on('SIGTERM', sigintHandler);
|
|
847
|
+
// Offer to spawn Claude Code instances with coordination instructions
|
|
848
|
+
// Spawn Claude if --claude or --spawn flag is set
|
|
849
|
+
if (flags.claude || flags.spawn) {
|
|
850
|
+
await spawnClaudeCodeInstances(swarmId, hiveMind.config.name, objective, workers, flags);
|
|
851
|
+
} else {
|
|
852
|
+
console.log('\n' + chalk.blue('💡 Pro Tip:') + ' Add --claude to spawn coordinated Claude Code instances');
|
|
853
|
+
console.log(chalk.gray(' claude-flow-novice hive-mind spawn "objective" --claude'));
|
|
865
854
|
}
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
await spawnClaudeCodeInstances(swarmId, hiveMind.config.name, objective, workers, flags);
|
|
882
|
-
} else {
|
|
883
|
-
console.log(
|
|
884
|
-
'\n' +
|
|
885
|
-
chalk.blue('💡 Pro Tip:') +
|
|
886
|
-
' Add --claude to spawn coordinated Claude Code instances',
|
|
887
|
-
);
|
|
888
|
-
console.log(chalk.gray(' claude-flow-novice hive-mind spawn "objective" --claude'));
|
|
889
|
-
}
|
|
890
|
-
} catch (error) {
|
|
891
|
-
spinner.fail('Failed to spawn Hive Mind swarm');
|
|
892
|
-
console.error(chalk.red('Error:'), error.message);
|
|
893
|
-
|
|
894
|
-
// If error contains "sha3", provide specific guidance
|
|
895
|
-
if (error.message.includes('sha3') || error.message.includes('SHA3')) {
|
|
896
|
-
console.error('\n🔍 SHA3 Function Error Detected');
|
|
897
|
-
console.error('This appears to be a SQLite extension or better-sqlite3 configuration issue.');
|
|
898
|
-
console.error('\nPossible solutions:');
|
|
899
|
-
console.error('1. Try removing the corrupted database: rm -rf .hive-mind/');
|
|
900
|
-
console.error('2. Reinstall better-sqlite3: npm reinstall better-sqlite3');
|
|
901
|
-
console.error('3. Check if any SQLite extensions are conflicting');
|
|
902
|
-
console.error('\n🚨 Detailed error:');
|
|
903
|
-
console.error(error.stack || error.message);
|
|
855
|
+
} catch (error) {
|
|
856
|
+
spinner.fail('Failed to spawn Hive Mind swarm');
|
|
857
|
+
console.error(chalk.red('Error:'), error.message);
|
|
858
|
+
// If error contains "sha3", provide specific guidance
|
|
859
|
+
if (error.message.includes('sha3') || error.message.includes('SHA3')) {
|
|
860
|
+
console.error('\n🔍 SHA3 Function Error Detected');
|
|
861
|
+
console.error('This appears to be a SQLite extension or better-sqlite3 configuration issue.');
|
|
862
|
+
console.error('\nPossible solutions:');
|
|
863
|
+
console.error('1. Try removing the corrupted database: rm -rf .hive-mind/');
|
|
864
|
+
console.error('2. Reinstall better-sqlite3: npm reinstall better-sqlite3');
|
|
865
|
+
console.error('3. Check if any SQLite extensions are conflicting');
|
|
866
|
+
console.error('\n🚨 Detailed error:');
|
|
867
|
+
console.error(error.stack || error.message);
|
|
868
|
+
}
|
|
869
|
+
exit(1);
|
|
904
870
|
}
|
|
905
|
-
|
|
906
|
-
exit(1);
|
|
907
|
-
}
|
|
908
871
|
}
|
|
909
|
-
|
|
910
872
|
/**
|
|
911
873
|
* Get agent capabilities based on type
|
|
912
|
-
*/
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
874
|
+
*/ function getAgentCapabilities(type) {
|
|
875
|
+
const capabilities = {
|
|
876
|
+
researcher: [
|
|
877
|
+
'web-search',
|
|
878
|
+
'data-gathering',
|
|
879
|
+
'analysis',
|
|
880
|
+
'synthesis'
|
|
881
|
+
],
|
|
882
|
+
coder: [
|
|
883
|
+
'code-generation',
|
|
884
|
+
'implementation',
|
|
885
|
+
'refactoring',
|
|
886
|
+
'debugging'
|
|
887
|
+
],
|
|
888
|
+
analyst: [
|
|
889
|
+
'data-analysis',
|
|
890
|
+
'pattern-recognition',
|
|
891
|
+
'reporting',
|
|
892
|
+
'visualization'
|
|
893
|
+
],
|
|
894
|
+
tester: [
|
|
895
|
+
'test-generation',
|
|
896
|
+
'quality-assurance',
|
|
897
|
+
'bug-detection',
|
|
898
|
+
'validation'
|
|
899
|
+
],
|
|
900
|
+
architect: [
|
|
901
|
+
'system-design',
|
|
902
|
+
'architecture',
|
|
903
|
+
'planning',
|
|
904
|
+
'documentation'
|
|
905
|
+
],
|
|
906
|
+
reviewer: [
|
|
907
|
+
'code-review',
|
|
908
|
+
'quality-check',
|
|
909
|
+
'feedback',
|
|
910
|
+
'improvement'
|
|
911
|
+
],
|
|
912
|
+
optimizer: [
|
|
913
|
+
'performance-tuning',
|
|
914
|
+
'optimization',
|
|
915
|
+
'profiling',
|
|
916
|
+
'enhancement'
|
|
917
|
+
],
|
|
918
|
+
documenter: [
|
|
919
|
+
'documentation',
|
|
920
|
+
'explanation',
|
|
921
|
+
'tutorial-creation',
|
|
922
|
+
'knowledge-base'
|
|
923
|
+
]
|
|
924
|
+
};
|
|
925
|
+
return capabilities[type] || [
|
|
926
|
+
'general'
|
|
927
|
+
];
|
|
926
928
|
}
|
|
927
|
-
|
|
928
929
|
/**
|
|
929
930
|
* Show hive mind status
|
|
930
|
-
*/
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
const db = new Database(dbPath);
|
|
942
|
-
|
|
943
|
-
// Get active swarms
|
|
944
|
-
const swarms = db
|
|
945
|
-
.prepare(
|
|
946
|
-
`
|
|
931
|
+
*/ async function showStatus(flags) {
|
|
932
|
+
try {
|
|
933
|
+
const dbPath = path.join(cwd(), '.hive-mind', 'hive.db');
|
|
934
|
+
if (!existsSync(dbPath)) {
|
|
935
|
+
console.error(chalk.red('Error: Hive Mind not initialized'));
|
|
936
|
+
console.log('Run "claude-flow-novice hive-mind init" first');
|
|
937
|
+
return;
|
|
938
|
+
}
|
|
939
|
+
const db = new Database(dbPath);
|
|
940
|
+
// Get active swarms
|
|
941
|
+
const swarms = db.prepare(`
|
|
947
942
|
SELECT * FROM swarms
|
|
948
943
|
WHERE status = 'active'
|
|
949
944
|
ORDER BY created_at DESC
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
console.log(chalk.cyan('Queen Type:'), swarm.queen_type);
|
|
968
|
-
console.log(chalk.cyan('Status:'), chalk.green(swarm.status));
|
|
969
|
-
console.log(chalk.cyan('Created:'), new Date(swarm.created_at).toLocaleString());
|
|
970
|
-
|
|
971
|
-
// Get agents
|
|
972
|
-
const agents = db
|
|
973
|
-
.prepare(
|
|
974
|
-
`
|
|
945
|
+
`).all();
|
|
946
|
+
if (swarms.length === 0) {
|
|
947
|
+
console.log(chalk.gray('No active swarms found'));
|
|
948
|
+
db.close();
|
|
949
|
+
return;
|
|
950
|
+
}
|
|
951
|
+
console.log(chalk.bold('\n🐝 Active Hive Mind Swarms\n'));
|
|
952
|
+
for (const swarm of swarms){
|
|
953
|
+
console.log(chalk.yellow('═'.repeat(60)));
|
|
954
|
+
console.log(chalk.cyan('Swarm:'), swarm.name);
|
|
955
|
+
console.log(chalk.cyan('ID:'), swarm.id);
|
|
956
|
+
console.log(chalk.cyan('Objective:'), swarm.objective);
|
|
957
|
+
console.log(chalk.cyan('Queen Type:'), swarm.queen_type);
|
|
958
|
+
console.log(chalk.cyan('Status:'), chalk.green(swarm.status));
|
|
959
|
+
console.log(chalk.cyan('Created:'), new Date(swarm.created_at).toLocaleString());
|
|
960
|
+
// Get agents
|
|
961
|
+
const agents = db.prepare(`
|
|
975
962
|
SELECT * FROM agents
|
|
976
963
|
WHERE swarm_id = ?
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
workers.forEach((worker) => {
|
|
993
|
-
const statusColor =
|
|
994
|
-
worker.status === 'active' ? 'green' : worker.status === 'busy' ? 'yellow' : 'gray';
|
|
995
|
-
console.log(` - ${worker.name} (${worker.type}) ${chalk[statusColor](worker.status)}`);
|
|
996
|
-
});
|
|
997
|
-
|
|
998
|
-
// Get task statistics
|
|
999
|
-
const taskStats = db
|
|
1000
|
-
.prepare(
|
|
1001
|
-
`
|
|
964
|
+
`).all(swarm.id);
|
|
965
|
+
console.log('\n' + chalk.bold('Agents:'));
|
|
966
|
+
// Group by role
|
|
967
|
+
const queen = agents.find((a)=>a.role === 'queen');
|
|
968
|
+
const workers = agents.filter((a)=>a.role === 'worker');
|
|
969
|
+
if (queen) {
|
|
970
|
+
console.log(' ' + chalk.magenta('👑 Queen:'), queen.name, chalk.gray(`(${queen.status})`));
|
|
971
|
+
}
|
|
972
|
+
console.log(' ' + chalk.blue('🐝 Workers:'));
|
|
973
|
+
workers.forEach((worker)=>{
|
|
974
|
+
const statusColor = worker.status === 'active' ? 'green' : worker.status === 'busy' ? 'yellow' : 'gray';
|
|
975
|
+
console.log(` - ${worker.name} (${worker.type}) ${chalk[statusColor](worker.status)}`);
|
|
976
|
+
});
|
|
977
|
+
// Get task statistics
|
|
978
|
+
const taskStats = db.prepare(`
|
|
1002
979
|
SELECT
|
|
1003
980
|
COUNT(*) as total,
|
|
1004
981
|
SUM(CASE WHEN status = 'completed' THEN 1 ELSE 0 END) as completed,
|
|
@@ -1006,234 +983,153 @@ async function showStatus(flags) {
|
|
|
1006
983
|
SUM(CASE WHEN status = 'pending' THEN 1 ELSE 0 END) as pending
|
|
1007
984
|
FROM tasks
|
|
1008
985
|
WHERE swarm_id = ?
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
console.log(` Pending: ${chalk.gray(taskStats.pending)}`);
|
|
1018
|
-
|
|
1019
|
-
// Get memory stats
|
|
1020
|
-
const memoryCount = db
|
|
1021
|
-
.prepare(
|
|
1022
|
-
`
|
|
986
|
+
`).get(swarm.id);
|
|
987
|
+
console.log('\n' + chalk.bold('Tasks:'));
|
|
988
|
+
console.log(` Total: ${taskStats.total}`);
|
|
989
|
+
console.log(` Completed: ${chalk.green(taskStats.completed)}`);
|
|
990
|
+
console.log(` In Progress: ${chalk.yellow(taskStats.in_progress)}`);
|
|
991
|
+
console.log(` Pending: ${chalk.gray(taskStats.pending)}`);
|
|
992
|
+
// Get memory stats
|
|
993
|
+
const memoryCount = db.prepare(`
|
|
1023
994
|
SELECT COUNT(*) as count FROM collective_memory
|
|
1024
995
|
WHERE swarm_id = ?
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
console.log(` Entries: ${memoryCount.count}`);
|
|
1031
|
-
|
|
1032
|
-
// Get consensus stats
|
|
1033
|
-
const consensusCount = db
|
|
1034
|
-
.prepare(
|
|
1035
|
-
`
|
|
996
|
+
`).get(swarm.id);
|
|
997
|
+
console.log('\n' + chalk.bold('Collective Memory:'));
|
|
998
|
+
console.log(` Entries: ${memoryCount.count}`);
|
|
999
|
+
// Get consensus stats
|
|
1000
|
+
const consensusCount = db.prepare(`
|
|
1036
1001
|
SELECT COUNT(*) as count FROM consensus_decisions
|
|
1037
1002
|
WHERE swarm_id = ?
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1003
|
+
`).get(swarm.id);
|
|
1004
|
+
console.log('\n' + chalk.bold('Consensus Decisions:'));
|
|
1005
|
+
console.log(` Total: ${consensusCount.count}`);
|
|
1006
|
+
}
|
|
1007
|
+
console.log(chalk.yellow('═'.repeat(60)) + '\n');
|
|
1008
|
+
db.close();
|
|
1009
|
+
} catch (error) {
|
|
1010
|
+
console.error(chalk.red('Error:'), error.message);
|
|
1011
|
+
exit(1);
|
|
1044
1012
|
}
|
|
1045
|
-
|
|
1046
|
-
console.log(chalk.yellow('═'.repeat(60)) + '\n');
|
|
1047
|
-
|
|
1048
|
-
db.close();
|
|
1049
|
-
} catch (error) {
|
|
1050
|
-
console.error(chalk.red('Error:'), error.message);
|
|
1051
|
-
exit(1);
|
|
1052
|
-
}
|
|
1053
1013
|
}
|
|
1054
|
-
|
|
1055
1014
|
/**
|
|
1056
1015
|
* Show consensus decisions
|
|
1057
|
-
*/
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
const decisions = db
|
|
1064
|
-
.prepare(
|
|
1065
|
-
`
|
|
1016
|
+
*/ async function showConsensus(flags) {
|
|
1017
|
+
try {
|
|
1018
|
+
const dbPath = path.join(cwd(), '.hive-mind', 'hive.db');
|
|
1019
|
+
const db = new Database(dbPath);
|
|
1020
|
+
const decisions = db.prepare(`
|
|
1066
1021
|
SELECT cd.*, s.name as swarm_name
|
|
1067
1022
|
FROM consensus_decisions cd
|
|
1068
1023
|
JOIN swarms s ON cd.swarm_id = s.id
|
|
1069
1024
|
ORDER BY cd.created_at DESC
|
|
1070
1025
|
LIMIT 20
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
console.log(chalk.gray('No consensus decisions found'));
|
|
1077
|
-
db.close();
|
|
1078
|
-
return;
|
|
1079
|
-
}
|
|
1080
|
-
|
|
1081
|
-
console.log(chalk.bold('\n🤝 Recent Consensus Decisions\n'));
|
|
1082
|
-
|
|
1083
|
-
decisions.forEach((decision) => {
|
|
1084
|
-
console.log(chalk.yellow('─'.repeat(50)));
|
|
1085
|
-
console.log(chalk.cyan('Swarm:'), decision.swarm_name);
|
|
1086
|
-
console.log(chalk.cyan('Topic:'), decision.topic);
|
|
1087
|
-
console.log(chalk.cyan('Decision:'), decision.decision);
|
|
1088
|
-
console.log(chalk.cyan('Algorithm:'), decision.algorithm);
|
|
1089
|
-
console.log(chalk.cyan('Confidence:'), `${(decision.confidence * 100).toFixed(1)}%`);
|
|
1090
|
-
console.log(chalk.cyan('Time:'), new Date(decision.created_at).toLocaleString());
|
|
1091
|
-
|
|
1092
|
-
if (decision.votes) {
|
|
1093
|
-
const votes = JSON.parse(decision.votes);
|
|
1094
|
-
console.log(chalk.cyan('Votes:'));
|
|
1095
|
-
|
|
1096
|
-
// Handle vote summary format (for/against/abstain/details)
|
|
1097
|
-
if (votes.for !== undefined || votes.against !== undefined || votes.abstain !== undefined) {
|
|
1098
|
-
console.log(` - for: ${votes.for || 0}`);
|
|
1099
|
-
console.log(` - against: ${votes.against || 0}`);
|
|
1100
|
-
console.log(` - abstain: ${votes.abstain || 0}`);
|
|
1101
|
-
|
|
1102
|
-
// Display vote details properly if they exist
|
|
1103
|
-
if (votes.details && Array.isArray(votes.details)) {
|
|
1104
|
-
console.log(' - details:');
|
|
1105
|
-
votes.details.forEach((detail, index) => {
|
|
1106
|
-
if (typeof detail === 'object') {
|
|
1107
|
-
// Extract available fields
|
|
1108
|
-
const agent =
|
|
1109
|
-
detail.agentId ||
|
|
1110
|
-
detail.agent ||
|
|
1111
|
-
detail.id ||
|
|
1112
|
-
detail.name ||
|
|
1113
|
-
`agent-${index + 1}`;
|
|
1114
|
-
const vote = detail.vote || detail.choice || detail.decision || 'unknown';
|
|
1115
|
-
const reason = detail.reason || detail.justification || detail.rationale;
|
|
1116
|
-
|
|
1117
|
-
// Build display string
|
|
1118
|
-
let displayString = ` ${index + 1}. Agent: ${agent}, Vote: ${vote}`;
|
|
1119
|
-
|
|
1120
|
-
// Add reason if available
|
|
1121
|
-
if (reason && reason !== 'N/A' && reason !== '') {
|
|
1122
|
-
displayString += `, Reason: ${reason}`;
|
|
1123
|
-
}
|
|
1124
|
-
|
|
1125
|
-
console.log(displayString);
|
|
1126
|
-
} else {
|
|
1127
|
-
console.log(` ${index + 1}. ${detail}`);
|
|
1128
|
-
}
|
|
1129
|
-
});
|
|
1130
|
-
}
|
|
1131
|
-
} else {
|
|
1132
|
-
// Handle individual agent votes format
|
|
1133
|
-
Object.entries(votes).forEach(([agent, vote]) => {
|
|
1134
|
-
console.log(` - ${agent}: ${vote}`);
|
|
1135
|
-
});
|
|
1026
|
+
`).all();
|
|
1027
|
+
if (decisions.length === 0) {
|
|
1028
|
+
console.log(chalk.gray('No consensus decisions found'));
|
|
1029
|
+
db.close();
|
|
1030
|
+
return;
|
|
1136
1031
|
}
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1032
|
+
console.log(chalk.bold('\n🤝 Recent Consensus Decisions\n'));
|
|
1033
|
+
decisions.forEach((decision)=>{
|
|
1034
|
+
console.log(chalk.yellow('─'.repeat(50)));
|
|
1035
|
+
console.log(chalk.cyan('Swarm:'), decision.swarm_name);
|
|
1036
|
+
console.log(chalk.cyan('Topic:'), decision.topic);
|
|
1037
|
+
console.log(chalk.cyan('Decision:'), decision.decision);
|
|
1038
|
+
console.log(chalk.cyan('Algorithm:'), decision.algorithm);
|
|
1039
|
+
console.log(chalk.cyan('Confidence:'), `${(decision.confidence * 100).toFixed(1)}%`);
|
|
1040
|
+
console.log(chalk.cyan('Time:'), new Date(decision.created_at).toLocaleString());
|
|
1041
|
+
if (decision.votes) {
|
|
1042
|
+
const votes = JSON.parse(decision.votes);
|
|
1043
|
+
console.log(chalk.cyan('Votes:'));
|
|
1044
|
+
// Handle vote summary format (for/against/abstain/details)
|
|
1045
|
+
if (votes.for !== undefined || votes.against !== undefined || votes.abstain !== undefined) {
|
|
1046
|
+
console.log(` - for: ${votes.for || 0}`);
|
|
1047
|
+
console.log(` - against: ${votes.against || 0}`);
|
|
1048
|
+
console.log(` - abstain: ${votes.abstain || 0}`);
|
|
1049
|
+
// Display vote details properly if they exist
|
|
1050
|
+
if (votes.details && Array.isArray(votes.details)) {
|
|
1051
|
+
console.log(' - details:');
|
|
1052
|
+
votes.details.forEach((detail, index)=>{
|
|
1053
|
+
if (typeof detail === 'object') {
|
|
1054
|
+
// Extract available fields
|
|
1055
|
+
const agent = detail.agentId || detail.agent || detail.id || detail.name || `agent-${index + 1}`;
|
|
1056
|
+
const vote = detail.vote || detail.choice || detail.decision || 'unknown';
|
|
1057
|
+
const reason = detail.reason || detail.justification || detail.rationale;
|
|
1058
|
+
// Build display string
|
|
1059
|
+
let displayString = ` ${index + 1}. Agent: ${agent}, Vote: ${vote}`;
|
|
1060
|
+
// Add reason if available
|
|
1061
|
+
if (reason && reason !== 'N/A' && reason !== '') {
|
|
1062
|
+
displayString += `, Reason: ${reason}`;
|
|
1063
|
+
}
|
|
1064
|
+
console.log(displayString);
|
|
1065
|
+
} else {
|
|
1066
|
+
console.log(` ${index + 1}. ${detail}`);
|
|
1067
|
+
}
|
|
1068
|
+
});
|
|
1069
|
+
}
|
|
1070
|
+
} else {
|
|
1071
|
+
// Handle individual agent votes format
|
|
1072
|
+
Object.entries(votes).forEach(([agent, vote])=>{
|
|
1073
|
+
console.log(` - ${agent}: ${vote}`);
|
|
1074
|
+
});
|
|
1075
|
+
}
|
|
1076
|
+
}
|
|
1077
|
+
});
|
|
1078
|
+
console.log(chalk.yellow('─'.repeat(50)) + '\n');
|
|
1079
|
+
db.close();
|
|
1080
|
+
} catch (error) {
|
|
1081
|
+
console.error(chalk.red('Error:'), error.message);
|
|
1082
|
+
exit(1);
|
|
1083
|
+
}
|
|
1147
1084
|
}
|
|
1148
|
-
|
|
1149
1085
|
/**
|
|
1150
1086
|
* Show performance metrics
|
|
1151
|
-
*/
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
// Get overall metrics
|
|
1158
|
-
const overallStats = db
|
|
1159
|
-
.prepare(
|
|
1160
|
-
`
|
|
1087
|
+
*/ async function showMetrics(flags) {
|
|
1088
|
+
try {
|
|
1089
|
+
const dbPath = path.join(cwd(), '.hive-mind', 'hive.db');
|
|
1090
|
+
const db = new Database(dbPath);
|
|
1091
|
+
// Get overall metrics
|
|
1092
|
+
const overallStats = db.prepare(`
|
|
1161
1093
|
SELECT
|
|
1162
1094
|
(SELECT COUNT(*) FROM swarms) as total_swarms,
|
|
1163
1095
|
(SELECT COUNT(*) FROM agents) as total_agents,
|
|
1164
1096
|
(SELECT COUNT(*) FROM tasks) as total_tasks,
|
|
1165
1097
|
(SELECT COUNT(*) FROM tasks WHERE status = 'completed') as completed_tasks
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
console.log(chalk.bold('\n📊 Hive Mind Performance Metrics\n'));
|
|
1171
|
-
|
|
1172
|
-
// Get task status breakdown
|
|
1173
|
-
const taskBreakdown = db
|
|
1174
|
-
.prepare(
|
|
1175
|
-
`
|
|
1098
|
+
`).get();
|
|
1099
|
+
console.log(chalk.bold('\n📊 Hive Mind Performance Metrics\n'));
|
|
1100
|
+
// Get task status breakdown
|
|
1101
|
+
const taskBreakdown = db.prepare(`
|
|
1176
1102
|
SELECT
|
|
1177
1103
|
status,
|
|
1178
1104
|
COUNT(*) as count
|
|
1179
1105
|
FROM tasks
|
|
1180
1106
|
GROUP BY status
|
|
1181
1107
|
ORDER BY count DESC
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
const percentage =
|
|
1203
|
-
overallStats.total_tasks > 0
|
|
1204
|
-
? ((status.count / overallStats.total_tasks) * 100).toFixed(1)
|
|
1205
|
-
: '0';
|
|
1206
|
-
const statusColor =
|
|
1207
|
-
status.status === 'completed'
|
|
1208
|
-
? 'green'
|
|
1209
|
-
: status.status === 'in_progress'
|
|
1210
|
-
? 'yellow'
|
|
1211
|
-
: status.status === 'failed'
|
|
1212
|
-
? 'red'
|
|
1213
|
-
: 'gray';
|
|
1214
|
-
console.log(
|
|
1215
|
-
` ${chalk[statusColor](status.status.charAt(0).toUpperCase() + status.status.slice(1))}: ${status.count} (${percentage}%)`,
|
|
1216
|
-
);
|
|
1217
|
-
});
|
|
1218
|
-
}
|
|
1219
|
-
|
|
1220
|
-
// Get agent performance (check for completed_at column)
|
|
1221
|
-
let agentPerf = [];
|
|
1222
|
-
try {
|
|
1223
|
-
// Check if completed_at exists
|
|
1224
|
-
const hasCompletedAt = db
|
|
1225
|
-
.prepare(
|
|
1226
|
-
`
|
|
1108
|
+
`).all();
|
|
1109
|
+
console.log(chalk.cyan('Overall Statistics:'));
|
|
1110
|
+
console.log(` Total Swarms: ${overallStats.total_swarms}`);
|
|
1111
|
+
console.log(` Total Agents: ${overallStats.total_agents}`);
|
|
1112
|
+
console.log(` Total Tasks: ${overallStats.total_tasks}`);
|
|
1113
|
+
console.log(` Completed Tasks: ${overallStats.completed_tasks}`);
|
|
1114
|
+
console.log(` Success Rate: ${overallStats.total_tasks > 0 ? (overallStats.completed_tasks / overallStats.total_tasks * 100).toFixed(1) + '%' : 'N/A'}`);
|
|
1115
|
+
if (taskBreakdown.length > 0) {
|
|
1116
|
+
console.log('\n' + chalk.cyan('Task Status Breakdown:'));
|
|
1117
|
+
taskBreakdown.forEach((status)=>{
|
|
1118
|
+
const percentage = overallStats.total_tasks > 0 ? (status.count / overallStats.total_tasks * 100).toFixed(1) : '0';
|
|
1119
|
+
const statusColor = status.status === 'completed' ? 'green' : status.status === 'in_progress' ? 'yellow' : status.status === 'failed' ? 'red' : 'gray';
|
|
1120
|
+
console.log(` ${chalk[statusColor](status.status.charAt(0).toUpperCase() + status.status.slice(1))}: ${status.count} (${percentage}%)`);
|
|
1121
|
+
});
|
|
1122
|
+
}
|
|
1123
|
+
// Get agent performance (check for completed_at column)
|
|
1124
|
+
let agentPerf = [];
|
|
1125
|
+
try {
|
|
1126
|
+
// Check if completed_at exists
|
|
1127
|
+
const hasCompletedAt = db.prepare(`
|
|
1227
1128
|
SELECT COUNT(*) as count FROM pragma_table_info('tasks')
|
|
1228
1129
|
WHERE name = 'completed_at'
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
if (hasCompletedAt && hasCompletedAt.count > 0) {
|
|
1234
|
-
agentPerf = db
|
|
1235
|
-
.prepare(
|
|
1236
|
-
`
|
|
1130
|
+
`).get();
|
|
1131
|
+
if (hasCompletedAt && hasCompletedAt.count > 0) {
|
|
1132
|
+
agentPerf = db.prepare(`
|
|
1237
1133
|
SELECT
|
|
1238
1134
|
a.name,
|
|
1239
1135
|
a.type,
|
|
@@ -1248,14 +1144,10 @@ async function showMetrics(flags) {
|
|
|
1248
1144
|
HAVING tasks_assigned > 0
|
|
1249
1145
|
ORDER BY tasks_completed DESC
|
|
1250
1146
|
LIMIT 10
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
// Simpler query without completed_at
|
|
1256
|
-
agentPerf = db
|
|
1257
|
-
.prepare(
|
|
1258
|
-
`
|
|
1147
|
+
`).all();
|
|
1148
|
+
} else {
|
|
1149
|
+
// Simpler query without completed_at
|
|
1150
|
+
agentPerf = db.prepare(`
|
|
1259
1151
|
SELECT
|
|
1260
1152
|
a.name,
|
|
1261
1153
|
a.type,
|
|
@@ -1268,35 +1160,24 @@ async function showMetrics(flags) {
|
|
|
1268
1160
|
HAVING tasks_assigned > 0
|
|
1269
1161
|
ORDER BY tasks_completed DESC
|
|
1270
1162
|
LIMIT 10
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
} catch (error) {
|
|
1276
|
-
console.warn('Could not get agent performance:', error.message);
|
|
1277
|
-
}
|
|
1278
|
-
|
|
1279
|
-
if (agentPerf.length > 0) {
|
|
1280
|
-
console.log('\n' + chalk.cyan('Top Performing Agents:'));
|
|
1281
|
-
agentPerf.forEach((agent, index) => {
|
|
1282
|
-
const successRate =
|
|
1283
|
-
agent.tasks_assigned > 0
|
|
1284
|
-
? ((agent.tasks_completed / agent.tasks_assigned) * 100).toFixed(1)
|
|
1285
|
-
: '0';
|
|
1286
|
-
console.log(` ${index + 1}. ${agent.name} (${agent.type})`);
|
|
1287
|
-
console.log(
|
|
1288
|
-
` Tasks: ${agent.tasks_completed}/${agent.tasks_assigned} (${successRate}%)`,
|
|
1289
|
-
);
|
|
1290
|
-
if (agent.avg_completion_minutes) {
|
|
1291
|
-
console.log(` Avg Time: ${agent.avg_completion_minutes.toFixed(1)} minutes`);
|
|
1163
|
+
`).all();
|
|
1164
|
+
}
|
|
1165
|
+
} catch (error) {
|
|
1166
|
+
console.warn('Could not get agent performance:', error.message);
|
|
1292
1167
|
}
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1168
|
+
if (agentPerf.length > 0) {
|
|
1169
|
+
console.log('\n' + chalk.cyan('Top Performing Agents:'));
|
|
1170
|
+
agentPerf.forEach((agent, index)=>{
|
|
1171
|
+
const successRate = agent.tasks_assigned > 0 ? (agent.tasks_completed / agent.tasks_assigned * 100).toFixed(1) : '0';
|
|
1172
|
+
console.log(` ${index + 1}. ${agent.name} (${agent.type})`);
|
|
1173
|
+
console.log(` Tasks: ${agent.tasks_completed}/${agent.tasks_assigned} (${successRate}%)`);
|
|
1174
|
+
if (agent.avg_completion_minutes) {
|
|
1175
|
+
console.log(` Avg Time: ${agent.avg_completion_minutes.toFixed(1)} minutes`);
|
|
1176
|
+
}
|
|
1177
|
+
});
|
|
1178
|
+
}
|
|
1179
|
+
// Get swarm performance
|
|
1180
|
+
const swarmPerf = db.prepare(`
|
|
1300
1181
|
SELECT
|
|
1301
1182
|
s.name,
|
|
1302
1183
|
s.objective,
|
|
@@ -1309,76 +1190,50 @@ async function showMetrics(flags) {
|
|
|
1309
1190
|
WHERE s.status = 'active'
|
|
1310
1191
|
ORDER BY s.created_at DESC
|
|
1311
1192
|
LIMIT 5
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
);
|
|
1331
|
-
});
|
|
1332
|
-
}
|
|
1333
|
-
|
|
1334
|
-
// Get performance insights
|
|
1335
|
-
let avgTaskTime = { avg_minutes: null };
|
|
1336
|
-
try {
|
|
1337
|
-
// Check if completed_at exists
|
|
1338
|
-
const hasCompletedAt = db
|
|
1339
|
-
.prepare(
|
|
1340
|
-
`
|
|
1193
|
+
`).all();
|
|
1194
|
+
if (swarmPerf.length > 0) {
|
|
1195
|
+
console.log('\n' + chalk.cyan('Active Swarm Performance:'));
|
|
1196
|
+
swarmPerf.forEach((swarm)=>{
|
|
1197
|
+
const successRate = swarm.task_count > 0 ? (swarm.completed_count / swarm.task_count * 100).toFixed(1) : '0';
|
|
1198
|
+
console.log(`\n ${chalk.yellow(swarm.name)}`);
|
|
1199
|
+
console.log(` Objective: ${swarm.objective.substring(0, 50)}...`);
|
|
1200
|
+
console.log(` Agents: ${swarm.agent_count}, Tasks: ${swarm.completed_count}/${swarm.task_count} (${successRate}%)`);
|
|
1201
|
+
console.log(` Memory: ${swarm.memory_entries} entries, Consensus: ${swarm.consensus_count} decisions`);
|
|
1202
|
+
});
|
|
1203
|
+
}
|
|
1204
|
+
// Get performance insights
|
|
1205
|
+
let avgTaskTime = {
|
|
1206
|
+
avg_minutes: null
|
|
1207
|
+
};
|
|
1208
|
+
try {
|
|
1209
|
+
// Check if completed_at exists
|
|
1210
|
+
const hasCompletedAt = db.prepare(`
|
|
1341
1211
|
SELECT COUNT(*) as count FROM pragma_table_info('tasks')
|
|
1342
1212
|
WHERE name = 'completed_at'
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
if (hasCompletedAt && hasCompletedAt.count > 0) {
|
|
1348
|
-
avgTaskTime = db
|
|
1349
|
-
.prepare(
|
|
1350
|
-
`
|
|
1213
|
+
`).get();
|
|
1214
|
+
if (hasCompletedAt && hasCompletedAt.count > 0) {
|
|
1215
|
+
avgTaskTime = db.prepare(`
|
|
1351
1216
|
SELECT
|
|
1352
1217
|
AVG(CASE WHEN completed_at IS NOT NULL
|
|
1353
1218
|
THEN (julianday(completed_at) - julianday(created_at)) * 24 * 60
|
|
1354
1219
|
ELSE NULL END) as avg_minutes
|
|
1355
1220
|
FROM tasks
|
|
1356
1221
|
WHERE status = 'completed'
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
try {
|
|
1368
|
-
// Check if completed_at exists
|
|
1369
|
-
const hasCompletedAt = db
|
|
1370
|
-
.prepare(
|
|
1371
|
-
`
|
|
1222
|
+
`).get();
|
|
1223
|
+
}
|
|
1224
|
+
} catch (error) {
|
|
1225
|
+
console.warn('Could not calculate average task time:', error.message);
|
|
1226
|
+
}
|
|
1227
|
+
// Get agent type performance
|
|
1228
|
+
let agentTypePerf = [];
|
|
1229
|
+
try {
|
|
1230
|
+
// Check if completed_at exists
|
|
1231
|
+
const hasCompletedAt = db.prepare(`
|
|
1372
1232
|
SELECT COUNT(*) as count FROM pragma_table_info('tasks')
|
|
1373
1233
|
WHERE name = 'completed_at'
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
if (hasCompletedAt && hasCompletedAt.count > 0) {
|
|
1379
|
-
agentTypePerf = db
|
|
1380
|
-
.prepare(
|
|
1381
|
-
`
|
|
1234
|
+
`).get();
|
|
1235
|
+
if (hasCompletedAt && hasCompletedAt.count > 0) {
|
|
1236
|
+
agentTypePerf = db.prepare(`
|
|
1382
1237
|
SELECT
|
|
1383
1238
|
a.type,
|
|
1384
1239
|
COUNT(t.id) as total_tasks,
|
|
@@ -1391,14 +1246,10 @@ async function showMetrics(flags) {
|
|
|
1391
1246
|
GROUP BY a.type
|
|
1392
1247
|
HAVING total_tasks > 0
|
|
1393
1248
|
ORDER BY completed_tasks DESC
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
// Simpler query without completed_at
|
|
1399
|
-
agentTypePerf = db
|
|
1400
|
-
.prepare(
|
|
1401
|
-
`
|
|
1249
|
+
`).all();
|
|
1250
|
+
} else {
|
|
1251
|
+
// Simpler query without completed_at
|
|
1252
|
+
agentTypePerf = db.prepare(`
|
|
1402
1253
|
SELECT
|
|
1403
1254
|
a.type,
|
|
1404
1255
|
COUNT(t.id) as total_tasks,
|
|
@@ -1409,824 +1260,686 @@ async function showMetrics(flags) {
|
|
|
1409
1260
|
GROUP BY a.type
|
|
1410
1261
|
HAVING total_tasks > 0
|
|
1411
1262
|
ORDER BY completed_tasks DESC
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1263
|
+
`).all();
|
|
1264
|
+
}
|
|
1265
|
+
} catch (error) {
|
|
1266
|
+
console.warn('Could not get agent type performance:', error.message);
|
|
1267
|
+
}
|
|
1268
|
+
if (avgTaskTime.avg_minutes) {
|
|
1269
|
+
console.log('\n' + chalk.cyan('Performance Insights:'));
|
|
1270
|
+
console.log(` Average Task Completion Time: ${avgTaskTime.avg_minutes.toFixed(1)} minutes`);
|
|
1271
|
+
if (agentTypePerf.length > 0) {
|
|
1272
|
+
console.log('\n' + chalk.cyan('Agent Type Performance:'));
|
|
1273
|
+
agentTypePerf.forEach((type)=>{
|
|
1274
|
+
const successRate = type.total_tasks > 0 ? (type.completed_tasks / type.total_tasks * 100).toFixed(1) : '0';
|
|
1275
|
+
console.log(` ${type.type.charAt(0).toUpperCase() + type.type.slice(1)}: ${type.completed_tasks}/${type.total_tasks} (${successRate}%)`);
|
|
1276
|
+
if (type.avg_completion_minutes) {
|
|
1277
|
+
console.log(` Average time: ${type.avg_completion_minutes.toFixed(1)} minutes`);
|
|
1278
|
+
}
|
|
1279
|
+
});
|
|
1280
|
+
}
|
|
1281
|
+
}
|
|
1282
|
+
console.log('\n');
|
|
1283
|
+
db.close();
|
|
1416
1284
|
} catch (error) {
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
if (avgTaskTime.avg_minutes) {
|
|
1421
|
-
console.log('\n' + chalk.cyan('Performance Insights:'));
|
|
1422
|
-
console.log(` Average Task Completion Time: ${avgTaskTime.avg_minutes.toFixed(1)} minutes`);
|
|
1423
|
-
|
|
1424
|
-
if (agentTypePerf.length > 0) {
|
|
1425
|
-
console.log('\n' + chalk.cyan('Agent Type Performance:'));
|
|
1426
|
-
agentTypePerf.forEach((type) => {
|
|
1427
|
-
const successRate =
|
|
1428
|
-
type.total_tasks > 0
|
|
1429
|
-
? ((type.completed_tasks / type.total_tasks) * 100).toFixed(1)
|
|
1430
|
-
: '0';
|
|
1431
|
-
console.log(
|
|
1432
|
-
` ${type.type.charAt(0).toUpperCase() + type.type.slice(1)}: ${type.completed_tasks}/${type.total_tasks} (${successRate}%)`,
|
|
1433
|
-
);
|
|
1434
|
-
if (type.avg_completion_minutes) {
|
|
1435
|
-
console.log(` Average time: ${type.avg_completion_minutes.toFixed(1)} minutes`);
|
|
1436
|
-
}
|
|
1437
|
-
});
|
|
1438
|
-
}
|
|
1285
|
+
console.error(chalk.red('Error:'), error.message);
|
|
1286
|
+
exit(1);
|
|
1439
1287
|
}
|
|
1440
|
-
|
|
1441
|
-
console.log('\n');
|
|
1442
|
-
db.close();
|
|
1443
|
-
} catch (error) {
|
|
1444
|
-
console.error(chalk.red('Error:'), error.message);
|
|
1445
|
-
exit(1);
|
|
1446
|
-
}
|
|
1447
1288
|
}
|
|
1448
|
-
|
|
1449
1289
|
/**
|
|
1450
1290
|
* Manage collective memory wizard
|
|
1451
|
-
*/
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1291
|
+
*/ async function manageMemoryWizard() {
|
|
1292
|
+
console.log(chalk.blue('\n🧠 Collective Memory Management\n'));
|
|
1293
|
+
const { action } = await inquirer.prompt([
|
|
1294
|
+
{
|
|
1295
|
+
type: 'list',
|
|
1296
|
+
name: 'action',
|
|
1297
|
+
message: 'What would you like to do with collective memory?',
|
|
1298
|
+
choices: [
|
|
1299
|
+
{
|
|
1300
|
+
name: '📋 View all memories',
|
|
1301
|
+
value: 'list'
|
|
1302
|
+
},
|
|
1303
|
+
{
|
|
1304
|
+
name: '🔍 Search memories',
|
|
1305
|
+
value: 'search'
|
|
1306
|
+
},
|
|
1307
|
+
{
|
|
1308
|
+
name: '💾 Store new memory',
|
|
1309
|
+
value: 'store'
|
|
1310
|
+
},
|
|
1311
|
+
{
|
|
1312
|
+
name: '📊 Memory statistics',
|
|
1313
|
+
value: 'stats'
|
|
1314
|
+
},
|
|
1315
|
+
{
|
|
1316
|
+
name: '🗑️ Clean old memories',
|
|
1317
|
+
value: 'clean'
|
|
1318
|
+
},
|
|
1319
|
+
{
|
|
1320
|
+
name: '📤 Export memory backup',
|
|
1321
|
+
value: 'export'
|
|
1322
|
+
},
|
|
1323
|
+
{
|
|
1324
|
+
name: '⬅️ Back to main menu',
|
|
1325
|
+
value: 'back'
|
|
1326
|
+
}
|
|
1327
|
+
]
|
|
1328
|
+
}
|
|
1329
|
+
]);
|
|
1330
|
+
switch(action){
|
|
1331
|
+
case 'list':
|
|
1332
|
+
await listMemories();
|
|
1333
|
+
break;
|
|
1334
|
+
case 'search':
|
|
1335
|
+
await searchMemories();
|
|
1336
|
+
break;
|
|
1337
|
+
case 'store':
|
|
1338
|
+
await storeMemoryWizard();
|
|
1339
|
+
break;
|
|
1340
|
+
case 'stats':
|
|
1341
|
+
await showMemoryStats();
|
|
1342
|
+
break;
|
|
1343
|
+
case 'clean':
|
|
1344
|
+
await cleanMemories();
|
|
1345
|
+
break;
|
|
1346
|
+
case 'export':
|
|
1347
|
+
await exportMemoryBackup();
|
|
1348
|
+
break;
|
|
1349
|
+
case 'back':
|
|
1350
|
+
await hiveMindWizard();
|
|
1351
|
+
return;
|
|
1352
|
+
}
|
|
1353
|
+
// Ask if user wants to continue
|
|
1354
|
+
const { continue: continueAction } = await inquirer.prompt([
|
|
1355
|
+
{
|
|
1356
|
+
type: 'confirm',
|
|
1357
|
+
name: 'continue',
|
|
1358
|
+
message: 'Would you like to perform another memory operation?',
|
|
1359
|
+
default: true
|
|
1360
|
+
}
|
|
1361
|
+
]);
|
|
1362
|
+
if (continueAction) {
|
|
1363
|
+
await manageMemoryWizard();
|
|
1364
|
+
}
|
|
1509
1365
|
}
|
|
1510
|
-
|
|
1511
1366
|
/**
|
|
1512
1367
|
* Configure hive mind wizard
|
|
1513
|
-
*/
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
console.log(chalk.yellow('Configuration wizard coming soon...'));
|
|
1368
|
+
*/ async function configureWizard() {
|
|
1369
|
+
// TODO: Implement configuration wizard
|
|
1370
|
+
console.log(chalk.yellow('Configuration wizard coming soon...'));
|
|
1517
1371
|
}
|
|
1518
|
-
|
|
1519
1372
|
/**
|
|
1520
1373
|
* Main hive mind command handler
|
|
1521
|
-
*/
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
subcommand === '
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
case 'metrics':
|
|
1590
|
-
await showMetrics(flags);
|
|
1591
|
-
break;
|
|
1592
|
-
|
|
1593
|
-
case 'wizard':
|
|
1594
|
-
await hiveMindWizard(flags);
|
|
1595
|
-
break;
|
|
1596
|
-
|
|
1597
|
-
case 'help':
|
|
1598
|
-
case '--help':
|
|
1599
|
-
case '-h':
|
|
1600
|
-
showHiveMindHelp();
|
|
1601
|
-
break;
|
|
1602
|
-
|
|
1603
|
-
default:
|
|
1604
|
-
console.error(chalk.red(`Unknown subcommand: ${subcommand}`));
|
|
1605
|
-
console.log('Run "claude-flow-novice hive-mind help" for usage information');
|
|
1606
|
-
exit(1);
|
|
1607
|
-
}
|
|
1608
|
-
}
|
|
1609
|
-
|
|
1374
|
+
*/ export async function hiveMindCommand(args, flags) {
|
|
1375
|
+
const subcommand = args[0];
|
|
1376
|
+
const subArgs = args.slice(1);
|
|
1377
|
+
// Handle help flags
|
|
1378
|
+
if (!subcommand || subcommand === '--help' || subcommand === '-h' || subcommand === 'help' || flags.help) {
|
|
1379
|
+
showHiveMindHelp();
|
|
1380
|
+
return;
|
|
1381
|
+
}
|
|
1382
|
+
// Warn about non-interactive environments for certain commands
|
|
1383
|
+
if (subcommand === 'spawn' && (flags.claude || flags.spawn) || subcommand === 'wizard') {
|
|
1384
|
+
warnNonInteractive('hive-mind ' + subcommand);
|
|
1385
|
+
}
|
|
1386
|
+
switch(subcommand){
|
|
1387
|
+
case 'init':
|
|
1388
|
+
await initHiveMind(flags);
|
|
1389
|
+
break;
|
|
1390
|
+
case 'spawn':
|
|
1391
|
+
// Check for non-interactive mode FIRST (like alpha.83)
|
|
1392
|
+
if (flags['non-interactive'] || flags.nonInteractive) {
|
|
1393
|
+
// In non-interactive mode, skip wizard and use defaults
|
|
1394
|
+
if (subArgs.length === 0) {
|
|
1395
|
+
console.error(chalk.red('Error: Objective required in non-interactive mode'));
|
|
1396
|
+
console.log('Usage: claude-flow-novice hive-mind spawn "Your objective" --non-interactive');
|
|
1397
|
+
return;
|
|
1398
|
+
}
|
|
1399
|
+
await spawnSwarm(subArgs, flags);
|
|
1400
|
+
} else if (flags.wizard || subArgs.length === 0) {
|
|
1401
|
+
await spawnSwarmWizard();
|
|
1402
|
+
} else {
|
|
1403
|
+
await spawnSwarm(subArgs, flags);
|
|
1404
|
+
}
|
|
1405
|
+
break;
|
|
1406
|
+
case 'status':
|
|
1407
|
+
await showStatus(flags);
|
|
1408
|
+
break;
|
|
1409
|
+
case 'sessions':
|
|
1410
|
+
await showSessions(flags);
|
|
1411
|
+
break;
|
|
1412
|
+
case 'resume':
|
|
1413
|
+
await resumeSession(subArgs, flags);
|
|
1414
|
+
break;
|
|
1415
|
+
case 'stop':
|
|
1416
|
+
await stopSession(subArgs, flags);
|
|
1417
|
+
break;
|
|
1418
|
+
case 'consensus':
|
|
1419
|
+
await showConsensus(flags);
|
|
1420
|
+
break;
|
|
1421
|
+
case 'memory':
|
|
1422
|
+
await manageMemoryWizard();
|
|
1423
|
+
break;
|
|
1424
|
+
case 'metrics':
|
|
1425
|
+
await showMetrics(flags);
|
|
1426
|
+
break;
|
|
1427
|
+
case 'wizard':
|
|
1428
|
+
await hiveMindWizard(flags);
|
|
1429
|
+
break;
|
|
1430
|
+
case 'help':
|
|
1431
|
+
case '--help':
|
|
1432
|
+
case '-h':
|
|
1433
|
+
showHiveMindHelp();
|
|
1434
|
+
break;
|
|
1435
|
+
default:
|
|
1436
|
+
console.error(chalk.red(`Unknown subcommand: ${subcommand}`));
|
|
1437
|
+
console.log('Run "claude-flow-novice hive-mind help" for usage information');
|
|
1438
|
+
exit(1);
|
|
1439
|
+
}
|
|
1440
|
+
}
|
|
1610
1441
|
/**
|
|
1611
1442
|
* List all memories in the collective memory store
|
|
1612
|
-
*/
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
const db = new Database(dbPath);
|
|
1620
|
-
|
|
1621
|
-
const memories = db
|
|
1622
|
-
.prepare(
|
|
1623
|
-
`
|
|
1443
|
+
*/ async function listMemories() {
|
|
1444
|
+
try {
|
|
1445
|
+
console.log(chalk.blue('\n📋 Collective Memory Store\n'));
|
|
1446
|
+
// Read directly from hive.db collective_memory table
|
|
1447
|
+
const dbPath = path.join(cwd(), '.hive-mind', 'hive.db');
|
|
1448
|
+
const db = new Database(dbPath);
|
|
1449
|
+
const memories = db.prepare(`
|
|
1624
1450
|
SELECT cm.*, s.name as swarm_name
|
|
1625
1451
|
FROM collective_memory cm
|
|
1626
1452
|
LEFT JOIN swarms s ON cm.swarm_id = s.id
|
|
1627
1453
|
ORDER BY cm.created_at DESC
|
|
1628
1454
|
LIMIT 50
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1455
|
+
`).all();
|
|
1456
|
+
db.close();
|
|
1457
|
+
if (!memories || memories.length === 0) {
|
|
1458
|
+
console.log(chalk.yellow('No memories found in the collective store.'));
|
|
1459
|
+
console.log(chalk.gray('Try storing some memories first using the "💾 Store new memory" option.'));
|
|
1460
|
+
return;
|
|
1461
|
+
}
|
|
1462
|
+
console.log(chalk.gray(`Found ${memories.length} memories in the collective store:\n`));
|
|
1463
|
+
memories.forEach((memory, index)=>{
|
|
1464
|
+
console.log(chalk.cyan(`${index + 1}. ${memory.key}`));
|
|
1465
|
+
console.log(` Swarm: ${memory.swarm_name || memory.swarm_id}`);
|
|
1466
|
+
console.log(` Type: ${memory.type || 'knowledge'}`);
|
|
1467
|
+
console.log(` Created: ${new Date(memory.created_at).toLocaleString()}`);
|
|
1468
|
+
console.log(` Created by: ${memory.created_by || 'system'}`);
|
|
1469
|
+
// Parse and display value
|
|
1470
|
+
let displayValue = memory.value;
|
|
1471
|
+
try {
|
|
1472
|
+
const parsed = JSON.parse(memory.value);
|
|
1473
|
+
displayValue = JSON.stringify(parsed);
|
|
1474
|
+
} catch {
|
|
1475
|
+
// Keep as string
|
|
1476
|
+
}
|
|
1477
|
+
if (displayValue.length > 100) {
|
|
1478
|
+
console.log(` Value: ${displayValue.substring(0, 100)}...`);
|
|
1479
|
+
} else {
|
|
1480
|
+
console.log(` Value: ${displayValue}`);
|
|
1481
|
+
}
|
|
1482
|
+
if (memory.confidence !== null && memory.confidence !== 1) {
|
|
1483
|
+
console.log(` Confidence: ${(memory.confidence * 100).toFixed(1)}%`);
|
|
1484
|
+
}
|
|
1485
|
+
console.log('');
|
|
1486
|
+
});
|
|
1487
|
+
} catch (error) {
|
|
1488
|
+
console.error(chalk.red('Error listing memories:'), error.message);
|
|
1489
|
+
console.log(chalk.gray('This might be because no memories have been stored yet.'));
|
|
1641
1490
|
}
|
|
1642
|
-
|
|
1643
|
-
console.log(chalk.gray(`Found ${memories.length} memories in the collective store:\n`));
|
|
1644
|
-
|
|
1645
|
-
memories.forEach((memory, index) => {
|
|
1646
|
-
console.log(chalk.cyan(`${index + 1}. ${memory.key}`));
|
|
1647
|
-
console.log(` Swarm: ${memory.swarm_name || memory.swarm_id}`);
|
|
1648
|
-
console.log(` Type: ${memory.type || 'knowledge'}`);
|
|
1649
|
-
console.log(` Created: ${new Date(memory.created_at).toLocaleString()}`);
|
|
1650
|
-
console.log(` Created by: ${memory.created_by || 'system'}`);
|
|
1651
|
-
|
|
1652
|
-
// Parse and display value
|
|
1653
|
-
let displayValue = memory.value;
|
|
1654
|
-
try {
|
|
1655
|
-
const parsed = JSON.parse(memory.value);
|
|
1656
|
-
displayValue = JSON.stringify(parsed);
|
|
1657
|
-
} catch {
|
|
1658
|
-
// Keep as string
|
|
1659
|
-
}
|
|
1660
|
-
|
|
1661
|
-
if (displayValue.length > 100) {
|
|
1662
|
-
console.log(` Value: ${displayValue.substring(0, 100)}...`);
|
|
1663
|
-
} else {
|
|
1664
|
-
console.log(` Value: ${displayValue}`);
|
|
1665
|
-
}
|
|
1666
|
-
|
|
1667
|
-
if (memory.confidence !== null && memory.confidence !== 1) {
|
|
1668
|
-
console.log(` Confidence: ${(memory.confidence * 100).toFixed(1)}%`);
|
|
1669
|
-
}
|
|
1670
|
-
|
|
1671
|
-
console.log('');
|
|
1672
|
-
});
|
|
1673
|
-
} catch (error) {
|
|
1674
|
-
console.error(chalk.red('Error listing memories:'), error.message);
|
|
1675
|
-
console.log(chalk.gray('This might be because no memories have been stored yet.'));
|
|
1676
|
-
}
|
|
1677
1491
|
}
|
|
1678
|
-
|
|
1679
1492
|
/**
|
|
1680
1493
|
* Search memories by keyword
|
|
1681
|
-
*/
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
const db = new Database(dbPath);
|
|
1698
|
-
|
|
1699
|
-
const searchPattern = `%${searchTerm}%`;
|
|
1700
|
-
const memories = db
|
|
1701
|
-
.prepare(
|
|
1702
|
-
`
|
|
1494
|
+
*/ async function searchMemories() {
|
|
1495
|
+
try {
|
|
1496
|
+
const { searchTerm } = await inquirer.prompt([
|
|
1497
|
+
{
|
|
1498
|
+
type: 'input',
|
|
1499
|
+
name: 'searchTerm',
|
|
1500
|
+
message: 'Enter search term:',
|
|
1501
|
+
validate: (input)=>input.length > 0
|
|
1502
|
+
}
|
|
1503
|
+
]);
|
|
1504
|
+
console.log(chalk.blue(`\n🔍 Searching for: "${searchTerm}"\n`));
|
|
1505
|
+
// Search directly in hive.db collective_memory table
|
|
1506
|
+
const dbPath = path.join(cwd(), '.hive-mind', 'hive.db');
|
|
1507
|
+
const db = new Database(dbPath);
|
|
1508
|
+
const searchPattern = `%${searchTerm}%`;
|
|
1509
|
+
const memories = db.prepare(`
|
|
1703
1510
|
SELECT cm.*, s.name as swarm_name
|
|
1704
1511
|
FROM collective_memory cm
|
|
1705
1512
|
LEFT JOIN swarms s ON cm.swarm_id = s.id
|
|
1706
1513
|
WHERE cm.key LIKE ? OR cm.value LIKE ? OR cm.type LIKE ?
|
|
1707
1514
|
ORDER BY cm.created_at DESC
|
|
1708
1515
|
LIMIT 50
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1516
|
+
`).all(searchPattern, searchPattern, searchPattern);
|
|
1517
|
+
db.close();
|
|
1518
|
+
if (!memories || memories.length === 0) {
|
|
1519
|
+
console.log(chalk.yellow('No memories found matching your search.'));
|
|
1520
|
+
return;
|
|
1521
|
+
}
|
|
1522
|
+
console.log(chalk.gray(`Found ${memories.length} memories matching "${searchTerm}":\n`));
|
|
1523
|
+
memories.forEach((memory, index)=>{
|
|
1524
|
+
console.log(chalk.green(`${index + 1}. ${memory.key}`));
|
|
1525
|
+
console.log(` Swarm: ${memory.swarm_name || memory.swarm_id}`);
|
|
1526
|
+
console.log(` Type: ${memory.type || 'knowledge'}`);
|
|
1527
|
+
console.log(` Created: ${new Date(memory.created_at).toLocaleString()}`);
|
|
1528
|
+
// Parse and display value with highlighting
|
|
1529
|
+
let displayValue = memory.value;
|
|
1530
|
+
try {
|
|
1531
|
+
const parsed = JSON.parse(memory.value);
|
|
1532
|
+
displayValue = JSON.stringify(parsed, null, 2);
|
|
1533
|
+
} catch {
|
|
1534
|
+
// Keep as string
|
|
1535
|
+
}
|
|
1536
|
+
console.log(` Value: ${displayValue}`);
|
|
1537
|
+
console.log('');
|
|
1538
|
+
});
|
|
1539
|
+
} catch (error) {
|
|
1540
|
+
console.error(chalk.red('Error searching memories:'), error.message);
|
|
1718
1541
|
}
|
|
1719
|
-
|
|
1720
|
-
console.log(chalk.gray(`Found ${memories.length} memories matching "${searchTerm}":\n`));
|
|
1721
|
-
|
|
1722
|
-
memories.forEach((memory, index) => {
|
|
1723
|
-
console.log(chalk.green(`${index + 1}. ${memory.key}`));
|
|
1724
|
-
console.log(` Swarm: ${memory.swarm_name || memory.swarm_id}`);
|
|
1725
|
-
console.log(` Type: ${memory.type || 'knowledge'}`);
|
|
1726
|
-
console.log(` Created: ${new Date(memory.created_at).toLocaleString()}`);
|
|
1727
|
-
|
|
1728
|
-
// Parse and display value with highlighting
|
|
1729
|
-
let displayValue = memory.value;
|
|
1730
|
-
try {
|
|
1731
|
-
const parsed = JSON.parse(memory.value);
|
|
1732
|
-
displayValue = JSON.stringify(parsed, null, 2);
|
|
1733
|
-
} catch {
|
|
1734
|
-
// Keep as string
|
|
1735
|
-
}
|
|
1736
|
-
|
|
1737
|
-
console.log(` Value: ${displayValue}`);
|
|
1738
|
-
console.log('');
|
|
1739
|
-
});
|
|
1740
|
-
} catch (error) {
|
|
1741
|
-
console.error(chalk.red('Error searching memories:'), error.message);
|
|
1742
|
-
}
|
|
1743
1542
|
}
|
|
1744
|
-
|
|
1745
1543
|
/**
|
|
1746
1544
|
* Store new memory wizard
|
|
1747
|
-
*/
|
|
1748
|
-
async function storeMemoryWizard() {
|
|
1749
|
-
try {
|
|
1750
|
-
const answers = await inquirer.prompt([
|
|
1751
|
-
{
|
|
1752
|
-
type: 'input',
|
|
1753
|
-
name: 'key',
|
|
1754
|
-
message: 'Memory key (identifier):',
|
|
1755
|
-
validate: (input) => input.length > 0,
|
|
1756
|
-
},
|
|
1757
|
-
{
|
|
1758
|
-
type: 'list',
|
|
1759
|
-
name: 'category',
|
|
1760
|
-
message: 'Memory category:',
|
|
1761
|
-
choices: [
|
|
1762
|
-
'consensus',
|
|
1763
|
-
'decision',
|
|
1764
|
-
'pattern',
|
|
1765
|
-
'learning',
|
|
1766
|
-
'coordination',
|
|
1767
|
-
'performance',
|
|
1768
|
-
'configuration',
|
|
1769
|
-
'general',
|
|
1770
|
-
],
|
|
1771
|
-
},
|
|
1772
|
-
{
|
|
1773
|
-
type: 'editor',
|
|
1774
|
-
name: 'value',
|
|
1775
|
-
message: 'Memory content (JSON or text):',
|
|
1776
|
-
},
|
|
1777
|
-
]);
|
|
1778
|
-
|
|
1779
|
-
const mcpWrapper = await getMcpWrapper();
|
|
1780
|
-
let memoryValue;
|
|
1781
|
-
|
|
1782
|
-
// Try to parse as JSON, fall back to string
|
|
1545
|
+
*/ async function storeMemoryWizard() {
|
|
1783
1546
|
try {
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1547
|
+
const answers = await inquirer.prompt([
|
|
1548
|
+
{
|
|
1549
|
+
type: 'input',
|
|
1550
|
+
name: 'key',
|
|
1551
|
+
message: 'Memory key (identifier):',
|
|
1552
|
+
validate: (input)=>input.length > 0
|
|
1553
|
+
},
|
|
1554
|
+
{
|
|
1555
|
+
type: 'list',
|
|
1556
|
+
name: 'category',
|
|
1557
|
+
message: 'Memory category:',
|
|
1558
|
+
choices: [
|
|
1559
|
+
'consensus',
|
|
1560
|
+
'decision',
|
|
1561
|
+
'pattern',
|
|
1562
|
+
'learning',
|
|
1563
|
+
'coordination',
|
|
1564
|
+
'performance',
|
|
1565
|
+
'configuration',
|
|
1566
|
+
'general'
|
|
1567
|
+
]
|
|
1568
|
+
},
|
|
1569
|
+
{
|
|
1570
|
+
type: 'editor',
|
|
1571
|
+
name: 'value',
|
|
1572
|
+
message: 'Memory content (JSON or text):'
|
|
1573
|
+
}
|
|
1574
|
+
]);
|
|
1575
|
+
const mcpWrapper = await getMcpWrapper();
|
|
1576
|
+
let memoryValue;
|
|
1577
|
+
// Try to parse as JSON, fall back to string
|
|
1578
|
+
try {
|
|
1579
|
+
memoryValue = JSON.parse(answers.value);
|
|
1580
|
+
} catch {
|
|
1581
|
+
memoryValue = answers.value;
|
|
1582
|
+
}
|
|
1583
|
+
await mcpWrapper.storeMemory('hive-mind', answers.key, memoryValue, answers.category);
|
|
1584
|
+
console.log(chalk.green(`\n✅ Memory stored successfully!`));
|
|
1585
|
+
console.log(`Key: ${answers.key}`);
|
|
1586
|
+
console.log(`Category: ${answers.category}`);
|
|
1587
|
+
} catch (error) {
|
|
1588
|
+
console.error(chalk.red('Error storing memory:'), error.message);
|
|
1787
1589
|
}
|
|
1788
|
-
|
|
1789
|
-
await mcpWrapper.storeMemory('hive-mind', answers.key, memoryValue, answers.category);
|
|
1790
|
-
|
|
1791
|
-
console.log(chalk.green(`\n✅ Memory stored successfully!`));
|
|
1792
|
-
console.log(`Key: ${answers.key}`);
|
|
1793
|
-
console.log(`Category: ${answers.category}`);
|
|
1794
|
-
} catch (error) {
|
|
1795
|
-
console.error(chalk.red('Error storing memory:'), error.message);
|
|
1796
|
-
}
|
|
1797
1590
|
}
|
|
1798
|
-
|
|
1799
1591
|
/**
|
|
1800
1592
|
* Show memory statistics
|
|
1801
|
-
*/
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1593
|
+
*/ async function showMemoryStats() {
|
|
1594
|
+
try {
|
|
1595
|
+
console.log(chalk.blue('\n📊 Memory Statistics\n'));
|
|
1596
|
+
const mcpWrapper = await getMcpWrapper();
|
|
1597
|
+
// Search for all memories with an empty pattern to get everything
|
|
1598
|
+
const searchResult = await mcpWrapper.searchMemory('hive-mind', '');
|
|
1599
|
+
// Handle different possible response structures
|
|
1600
|
+
let memories = [];
|
|
1601
|
+
if (searchResult && Array.isArray(searchResult.results)) {
|
|
1602
|
+
memories = searchResult.results;
|
|
1603
|
+
} else if (searchResult && Array.isArray(searchResult)) {
|
|
1604
|
+
memories = searchResult;
|
|
1605
|
+
} else if (searchResult && searchResult.data && Array.isArray(searchResult.data)) {
|
|
1606
|
+
memories = searchResult.data;
|
|
1607
|
+
}
|
|
1608
|
+
if (!memories || memories.length === 0) {
|
|
1609
|
+
console.log(chalk.yellow('No memories found.'));
|
|
1610
|
+
console.log(chalk.gray('Use "Store new memory" to create your first memory.'));
|
|
1611
|
+
return;
|
|
1612
|
+
}
|
|
1613
|
+
// Calculate statistics
|
|
1614
|
+
const stats = {
|
|
1615
|
+
total: memories.length,
|
|
1616
|
+
categories: {},
|
|
1617
|
+
oldestDate: null,
|
|
1618
|
+
newestDate: null,
|
|
1619
|
+
totalSize: 0
|
|
1620
|
+
};
|
|
1621
|
+
memories.forEach((memory)=>{
|
|
1622
|
+
// Count by category
|
|
1623
|
+
const category = memory.category || memory.type || 'general';
|
|
1624
|
+
stats.categories[category] = (stats.categories[category] || 0) + 1;
|
|
1625
|
+
// Track dates
|
|
1626
|
+
const date = new Date(memory.timestamp || Date.now());
|
|
1627
|
+
if (!stats.oldestDate || date < stats.oldestDate) {
|
|
1628
|
+
stats.oldestDate = date;
|
|
1629
|
+
}
|
|
1630
|
+
if (!stats.newestDate || date > stats.newestDate) {
|
|
1631
|
+
stats.newestDate = date;
|
|
1632
|
+
}
|
|
1633
|
+
// Estimate size
|
|
1634
|
+
stats.totalSize += JSON.stringify(memory).length;
|
|
1635
|
+
});
|
|
1636
|
+
console.log(chalk.cyan('Total memories:'), stats.total);
|
|
1637
|
+
console.log(chalk.cyan('Estimated size:'), `${(stats.totalSize / 1024).toFixed(2)} KB`);
|
|
1638
|
+
console.log(chalk.cyan('Date range:'), `${stats.oldestDate?.toLocaleDateString()} - ${stats.newestDate?.toLocaleDateString()}`);
|
|
1639
|
+
console.log(chalk.cyan('\nBy category:'));
|
|
1640
|
+
Object.entries(stats.categories).forEach(([category, count])=>{
|
|
1641
|
+
console.log(` ${category}: ${count}`);
|
|
1642
|
+
});
|
|
1643
|
+
} catch (error) {
|
|
1644
|
+
console.error(chalk.red('Error getting memory stats:'), error.message);
|
|
1825
1645
|
}
|
|
1826
|
-
|
|
1827
|
-
// Calculate statistics
|
|
1828
|
-
const stats = {
|
|
1829
|
-
total: memories.length,
|
|
1830
|
-
categories: {},
|
|
1831
|
-
oldestDate: null,
|
|
1832
|
-
newestDate: null,
|
|
1833
|
-
totalSize: 0,
|
|
1834
|
-
};
|
|
1835
|
-
|
|
1836
|
-
memories.forEach((memory) => {
|
|
1837
|
-
// Count by category
|
|
1838
|
-
const category = memory.category || memory.type || 'general';
|
|
1839
|
-
stats.categories[category] = (stats.categories[category] || 0) + 1;
|
|
1840
|
-
|
|
1841
|
-
// Track dates
|
|
1842
|
-
const date = new Date(memory.timestamp || Date.now());
|
|
1843
|
-
if (!stats.oldestDate || date < stats.oldestDate) {
|
|
1844
|
-
stats.oldestDate = date;
|
|
1845
|
-
}
|
|
1846
|
-
if (!stats.newestDate || date > stats.newestDate) {
|
|
1847
|
-
stats.newestDate = date;
|
|
1848
|
-
}
|
|
1849
|
-
|
|
1850
|
-
// Estimate size
|
|
1851
|
-
stats.totalSize += JSON.stringify(memory).length;
|
|
1852
|
-
});
|
|
1853
|
-
|
|
1854
|
-
console.log(chalk.cyan('Total memories:'), stats.total);
|
|
1855
|
-
console.log(chalk.cyan('Estimated size:'), `${(stats.totalSize / 1024).toFixed(2)} KB`);
|
|
1856
|
-
console.log(
|
|
1857
|
-
chalk.cyan('Date range:'),
|
|
1858
|
-
`${stats.oldestDate?.toLocaleDateString()} - ${stats.newestDate?.toLocaleDateString()}`,
|
|
1859
|
-
);
|
|
1860
|
-
|
|
1861
|
-
console.log(chalk.cyan('\nBy category:'));
|
|
1862
|
-
Object.entries(stats.categories).forEach(([category, count]) => {
|
|
1863
|
-
console.log(` ${category}: ${count}`);
|
|
1864
|
-
});
|
|
1865
|
-
} catch (error) {
|
|
1866
|
-
console.error(chalk.red('Error getting memory stats:'), error.message);
|
|
1867
|
-
}
|
|
1868
1646
|
}
|
|
1869
|
-
|
|
1870
1647
|
/**
|
|
1871
1648
|
* Clean old memories
|
|
1872
|
-
*/
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
})
|
|
1922
|
-
|
|
1923
|
-
if (oldMemories.length === 0) {
|
|
1924
|
-
console.log(chalk.yellow('\n🎉 No old memories found to clean.'));
|
|
1925
|
-
return;
|
|
1649
|
+
*/ async function cleanMemories() {
|
|
1650
|
+
try {
|
|
1651
|
+
const { days } = await inquirer.prompt([
|
|
1652
|
+
{
|
|
1653
|
+
type: 'number',
|
|
1654
|
+
name: 'days',
|
|
1655
|
+
message: 'Remove memories older than how many days?',
|
|
1656
|
+
default: 30,
|
|
1657
|
+
validate: (input)=>input > 0
|
|
1658
|
+
}
|
|
1659
|
+
]);
|
|
1660
|
+
const { confirm } = await inquirer.prompt([
|
|
1661
|
+
{
|
|
1662
|
+
type: 'confirm',
|
|
1663
|
+
name: 'confirm',
|
|
1664
|
+
message: `Are you sure you want to delete memories older than ${days} days?`,
|
|
1665
|
+
default: false
|
|
1666
|
+
}
|
|
1667
|
+
]);
|
|
1668
|
+
if (!confirm) {
|
|
1669
|
+
console.log(chalk.yellow('Operation cancelled.'));
|
|
1670
|
+
return;
|
|
1671
|
+
}
|
|
1672
|
+
const mcpWrapper = await getMcpWrapper();
|
|
1673
|
+
// Get all memories first
|
|
1674
|
+
const searchResult = await mcpWrapper.searchMemory('hive-mind', '');
|
|
1675
|
+
// Handle different possible response structures
|
|
1676
|
+
let memories = [];
|
|
1677
|
+
if (searchResult && Array.isArray(searchResult.results)) {
|
|
1678
|
+
memories = searchResult.results;
|
|
1679
|
+
} else if (searchResult && Array.isArray(searchResult)) {
|
|
1680
|
+
memories = searchResult;
|
|
1681
|
+
} else if (searchResult && searchResult.data && Array.isArray(searchResult.data)) {
|
|
1682
|
+
memories = searchResult.data;
|
|
1683
|
+
}
|
|
1684
|
+
const cutoffDate = new Date();
|
|
1685
|
+
cutoffDate.setDate(cutoffDate.getDate() - days);
|
|
1686
|
+
// Filter memories older than cutoff date
|
|
1687
|
+
const oldMemories = memories.filter((memory)=>{
|
|
1688
|
+
const memoryDate = new Date(memory.timestamp || 0);
|
|
1689
|
+
return memoryDate < cutoffDate;
|
|
1690
|
+
});
|
|
1691
|
+
if (oldMemories.length === 0) {
|
|
1692
|
+
console.log(chalk.yellow('\n🎉 No old memories found to clean.'));
|
|
1693
|
+
return;
|
|
1694
|
+
}
|
|
1695
|
+
console.log(chalk.green(`\n✅ Found ${oldMemories.length} old memories to clean.`));
|
|
1696
|
+
console.log(chalk.gray('Note: Individual memory deletion not yet implemented in MCPWrapper.'));
|
|
1697
|
+
console.log(chalk.gray('Consider implementing batch deletion or memory lifecycle management.'));
|
|
1698
|
+
} catch (error) {
|
|
1699
|
+
console.error(chalk.red('Error cleaning memories:'), error.message);
|
|
1926
1700
|
}
|
|
1927
|
-
|
|
1928
|
-
console.log(chalk.green(`\n✅ Found ${oldMemories.length} old memories to clean.`));
|
|
1929
|
-
console.log(chalk.gray('Note: Individual memory deletion not yet implemented in MCPWrapper.'));
|
|
1930
|
-
console.log(chalk.gray('Consider implementing batch deletion or memory lifecycle management.'));
|
|
1931
|
-
} catch (error) {
|
|
1932
|
-
console.error(chalk.red('Error cleaning memories:'), error.message);
|
|
1933
|
-
}
|
|
1934
1701
|
}
|
|
1935
|
-
|
|
1936
1702
|
/**
|
|
1937
1703
|
* Export memory backup
|
|
1938
|
-
*/
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1704
|
+
*/ async function exportMemoryBackup() {
|
|
1705
|
+
try {
|
|
1706
|
+
const { filename } = await inquirer.prompt([
|
|
1707
|
+
{
|
|
1708
|
+
type: 'input',
|
|
1709
|
+
name: 'filename',
|
|
1710
|
+
message: 'Export filename:',
|
|
1711
|
+
default: `hive-mind-memory-backup-${new Date().toISOString().split('T')[0]}.json`
|
|
1712
|
+
}
|
|
1713
|
+
]);
|
|
1714
|
+
const mcpWrapper = await getMcpWrapper();
|
|
1715
|
+
// Get all memories using search
|
|
1716
|
+
const searchResult = await mcpWrapper.searchMemory('hive-mind', '');
|
|
1717
|
+
// Handle different possible response structures
|
|
1718
|
+
let memories = [];
|
|
1719
|
+
if (searchResult && Array.isArray(searchResult.results)) {
|
|
1720
|
+
memories = searchResult.results;
|
|
1721
|
+
} else if (searchResult && Array.isArray(searchResult)) {
|
|
1722
|
+
memories = searchResult;
|
|
1723
|
+
} else if (searchResult && searchResult.data && Array.isArray(searchResult.data)) {
|
|
1724
|
+
memories = searchResult.data;
|
|
1725
|
+
}
|
|
1726
|
+
const backup = {
|
|
1727
|
+
exportDate: new Date().toISOString(),
|
|
1728
|
+
version: '1.0',
|
|
1729
|
+
totalMemories: memories.length,
|
|
1730
|
+
namespace: 'hive-mind',
|
|
1731
|
+
memories: memories
|
|
1732
|
+
};
|
|
1733
|
+
const fs = await import("fs");
|
|
1734
|
+
fs.writeFileSync(filename, JSON.stringify(backup, null, 2));
|
|
1735
|
+
console.log(chalk.green(`\n✅ Memory backup exported to: ${filename}`));
|
|
1736
|
+
console.log(chalk.cyan(`Exported ${memories.length} memories`));
|
|
1737
|
+
} catch (error) {
|
|
1738
|
+
console.error(chalk.red('Error exporting memory backup:'), error.message);
|
|
1963
1739
|
}
|
|
1964
|
-
|
|
1965
|
-
const backup = {
|
|
1966
|
-
exportDate: new Date().toISOString(),
|
|
1967
|
-
version: '1.0',
|
|
1968
|
-
totalMemories: memories.length,
|
|
1969
|
-
namespace: 'hive-mind',
|
|
1970
|
-
memories: memories,
|
|
1971
|
-
};
|
|
1972
|
-
|
|
1973
|
-
const fs = await import('fs');
|
|
1974
|
-
fs.writeFileSync(filename, JSON.stringify(backup, null, 2));
|
|
1975
|
-
|
|
1976
|
-
console.log(chalk.green(`\n✅ Memory backup exported to: ${filename}`));
|
|
1977
|
-
console.log(chalk.cyan(`Exported ${memories.length} memories`));
|
|
1978
|
-
} catch (error) {
|
|
1979
|
-
console.error(chalk.red('Error exporting memory backup:'), error.message);
|
|
1980
|
-
}
|
|
1981
1740
|
}
|
|
1982
|
-
|
|
1983
1741
|
/**
|
|
1984
1742
|
* Get active session ID for a swarm
|
|
1985
|
-
*/
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
}
|
|
1743
|
+
*/ async function getActiveSessionId(swarmId) {
|
|
1744
|
+
const sessionManager = new HiveMindSessionManager();
|
|
1745
|
+
try {
|
|
1746
|
+
const sessions = await sessionManager.getActiveSessions();
|
|
1747
|
+
const activeSession = sessions.find((s)=>s.swarm_id === swarmId && s.status === 'active');
|
|
1748
|
+
return activeSession ? activeSession.id : null;
|
|
1749
|
+
} finally{
|
|
1750
|
+
sessionManager.close();
|
|
1751
|
+
}
|
|
1995
1752
|
}
|
|
1996
|
-
|
|
1997
1753
|
/**
|
|
1998
1754
|
* Spawn Claude Code with Hive Mind coordination instructions
|
|
1999
|
-
*/
|
|
2000
|
-
|
|
2001
|
-
console.log('\n' + chalk.bold('🚀 Launching Claude Code with Hive Mind Coordination'));
|
|
2002
|
-
console.log(chalk.gray('─'.repeat(60)));
|
|
2003
|
-
|
|
2004
|
-
const spinner = ora('Preparing Hive Mind coordination prompt...').start();
|
|
2005
|
-
|
|
2006
|
-
try {
|
|
2007
|
-
// Generate comprehensive Hive Mind prompt
|
|
2008
|
-
const workerGroups = groupWorkersByType(workers);
|
|
2009
|
-
const hiveMindPrompt = generateHiveMindPrompt(
|
|
2010
|
-
swarmId,
|
|
2011
|
-
swarmName,
|
|
2012
|
-
objective,
|
|
2013
|
-
workers,
|
|
2014
|
-
workerGroups,
|
|
2015
|
-
flags,
|
|
2016
|
-
);
|
|
2017
|
-
|
|
2018
|
-
spinner.succeed('Hive Mind coordination prompt ready!');
|
|
2019
|
-
|
|
2020
|
-
// Display coordination summary
|
|
2021
|
-
console.log('\n' + chalk.bold('🧠 Hive Mind Configuration'));
|
|
1755
|
+
*/ async function spawnClaudeCodeInstances(swarmId, swarmName, objective, workers, flags) {
|
|
1756
|
+
console.log('\n' + chalk.bold('🚀 Launching Claude Code with Hive Mind Coordination'));
|
|
2022
1757
|
console.log(chalk.gray('─'.repeat(60)));
|
|
2023
|
-
|
|
2024
|
-
console.log(chalk.cyan('Objective:'), objective);
|
|
2025
|
-
console.log(chalk.cyan('Queen Type:'), flags.queenType || 'strategic');
|
|
2026
|
-
console.log(chalk.cyan('Worker Count:'), workers.length);
|
|
2027
|
-
console.log(chalk.cyan('Worker Types:'), Object.keys(workerGroups).join(', '));
|
|
2028
|
-
console.log(chalk.cyan('Consensus Algorithm:'), flags.consensus || 'majority');
|
|
2029
|
-
console.log(chalk.cyan('MCP Tools:'), 'Full Claude-Flow integration enabled');
|
|
2030
|
-
|
|
1758
|
+
const spinner = ora('Preparing Hive Mind coordination prompt...').start();
|
|
2031
1759
|
try {
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
}
|
|
2069
|
-
|
|
2070
|
-
// Add auto-permission flag BEFORE the prompt
|
|
2071
|
-
if (flags['dangerously-skip-permissions'] !== false && !flags['no-auto-permissions']) {
|
|
2072
|
-
claudeArgs.push('--dangerously-skip-permissions');
|
|
2073
|
-
if (!isNonInteractive) {
|
|
2074
|
-
console.log(
|
|
2075
|
-
chalk.yellow(
|
|
2076
|
-
'🔓 Using --dangerously-skip-permissions by default for seamless hive-mind execution',
|
|
2077
|
-
),
|
|
2078
|
-
);
|
|
2079
|
-
}
|
|
2080
|
-
}
|
|
2081
|
-
|
|
2082
|
-
// Add the prompt as the LAST argument
|
|
2083
|
-
claudeArgs.push(hiveMindPrompt);
|
|
2084
|
-
|
|
2085
|
-
// Spawn claude with properly ordered arguments
|
|
2086
|
-
const claudeProcess = childSpawn('claude', claudeArgs, {
|
|
2087
|
-
stdio: 'inherit',
|
|
2088
|
-
shell: false,
|
|
2089
|
-
});
|
|
2090
|
-
|
|
2091
|
-
// Track child process PID in session
|
|
2092
|
-
const sessionManager = new HiveMindSessionManager();
|
|
2093
|
-
const sessionId = await getActiveSessionId(swarmId);
|
|
2094
|
-
if (sessionId && claudeProcess.pid) {
|
|
2095
|
-
sessionManager.addChildPid(sessionId, claudeProcess.pid);
|
|
2096
|
-
}
|
|
2097
|
-
|
|
2098
|
-
// Set up SIGINT handler for automatic session pausing
|
|
2099
|
-
let isExiting = false;
|
|
2100
|
-
const sigintHandler = async () => {
|
|
2101
|
-
if (isExiting) return;
|
|
2102
|
-
isExiting = true;
|
|
2103
|
-
|
|
2104
|
-
console.log('\n\n' + chalk.yellow('⏸️ Pausing session and terminating Claude Code...'));
|
|
2105
|
-
|
|
2106
|
-
try {
|
|
2107
|
-
// Terminate Claude Code process
|
|
2108
|
-
if (claudeProcess && !claudeProcess.killed) {
|
|
2109
|
-
claudeProcess.kill('SIGTERM');
|
|
1760
|
+
// Generate comprehensive Hive Mind prompt
|
|
1761
|
+
const workerGroups = groupWorkersByType(workers);
|
|
1762
|
+
const hiveMindPrompt = generateHiveMindPrompt(swarmId, swarmName, objective, workers, workerGroups, flags);
|
|
1763
|
+
spinner.succeed('Hive Mind coordination prompt ready!');
|
|
1764
|
+
// Display coordination summary
|
|
1765
|
+
console.log('\n' + chalk.bold('🧠 Hive Mind Configuration'));
|
|
1766
|
+
console.log(chalk.gray('─'.repeat(60)));
|
|
1767
|
+
console.log(chalk.cyan('Swarm ID:'), swarmId);
|
|
1768
|
+
console.log(chalk.cyan('Objective:'), objective);
|
|
1769
|
+
console.log(chalk.cyan('Queen Type:'), flags.queenType || 'strategic');
|
|
1770
|
+
console.log(chalk.cyan('Worker Count:'), workers.length);
|
|
1771
|
+
console.log(chalk.cyan('Worker Types:'), Object.keys(workerGroups).join(', '));
|
|
1772
|
+
console.log(chalk.cyan('Consensus Algorithm:'), flags.consensus || 'majority');
|
|
1773
|
+
console.log(chalk.cyan('MCP Tools:'), 'Full Claude-Flow integration enabled');
|
|
1774
|
+
try {
|
|
1775
|
+
// ALWAYS save the prompt file first (fix for issue #330)
|
|
1776
|
+
// Ensure sessions directory exists
|
|
1777
|
+
const sessionsDir = path.join('.hive-mind', 'sessions');
|
|
1778
|
+
await mkdirAsync(sessionsDir, {
|
|
1779
|
+
recursive: true
|
|
1780
|
+
});
|
|
1781
|
+
const promptFile = path.join(sessionsDir, `hive-mind-prompt-${swarmId}.txt`);
|
|
1782
|
+
await writeFile(promptFile, hiveMindPrompt, 'utf8');
|
|
1783
|
+
console.log(chalk.green(`\n✓ Hive Mind prompt saved to: ${promptFile}`));
|
|
1784
|
+
// Check if claude command exists
|
|
1785
|
+
const { spawn: childSpawn, execSync } = await import("child_process");
|
|
1786
|
+
let claudeAvailable = false;
|
|
1787
|
+
try {
|
|
1788
|
+
execSync('which claude', {
|
|
1789
|
+
stdio: 'ignore'
|
|
1790
|
+
});
|
|
1791
|
+
claudeAvailable = true;
|
|
1792
|
+
} catch {
|
|
1793
|
+
console.log(chalk.yellow('\n⚠️ Claude Code CLI not found in PATH'));
|
|
1794
|
+
console.log(chalk.gray('Install it with: npm install -g @anthropic-ai/claude-code'));
|
|
1795
|
+
console.log(chalk.gray('\nFalling back to displaying instructions...'));
|
|
2110
1796
|
}
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
1797
|
+
if (claudeAvailable && !flags.dryRun) {
|
|
1798
|
+
// Check if we should run in non-interactive mode
|
|
1799
|
+
// Respect --non-interactive flag regardless of --claude
|
|
1800
|
+
const isNonInteractive = flags['non-interactive'] || flags.nonInteractive;
|
|
1801
|
+
// Build arguments in correct order: flags first, then prompt
|
|
1802
|
+
const claudeArgs = [];
|
|
1803
|
+
// Add non-interactive flags FIRST if needed
|
|
1804
|
+
if (isNonInteractive) {
|
|
1805
|
+
claudeArgs.push('-p'); // Print mode
|
|
1806
|
+
claudeArgs.push('--output-format', 'stream-json'); // JSON streaming
|
|
1807
|
+
claudeArgs.push('--verbose'); // Verbose output
|
|
1808
|
+
console.log(chalk.cyan('🤖 Running in non-interactive mode'));
|
|
1809
|
+
}
|
|
1810
|
+
// Add auto-permission flag BEFORE the prompt
|
|
1811
|
+
if (flags['dangerously-skip-permissions'] !== false && !flags['no-auto-permissions']) {
|
|
1812
|
+
claudeArgs.push('--dangerously-skip-permissions');
|
|
1813
|
+
if (!isNonInteractive) {
|
|
1814
|
+
console.log(chalk.yellow('🔓 Using --dangerously-skip-permissions by default for seamless hive-mind execution'));
|
|
1815
|
+
}
|
|
1816
|
+
}
|
|
1817
|
+
// Add the prompt as the LAST argument
|
|
1818
|
+
claudeArgs.push(hiveMindPrompt);
|
|
1819
|
+
// Spawn claude with properly ordered arguments
|
|
1820
|
+
const claudeProcess = childSpawn('claude', claudeArgs, {
|
|
1821
|
+
stdio: 'inherit',
|
|
1822
|
+
shell: false
|
|
1823
|
+
});
|
|
1824
|
+
// Track child process PID in session
|
|
1825
|
+
const sessionManager = new HiveMindSessionManager();
|
|
1826
|
+
const sessionId = await getActiveSessionId(swarmId);
|
|
1827
|
+
if (sessionId && claudeProcess.pid) {
|
|
1828
|
+
sessionManager.addChildPid(sessionId, claudeProcess.pid);
|
|
1829
|
+
}
|
|
1830
|
+
// Set up SIGINT handler for automatic session pausing
|
|
1831
|
+
let isExiting = false;
|
|
1832
|
+
const sigintHandler = async ()=>{
|
|
1833
|
+
if (isExiting) return;
|
|
1834
|
+
isExiting = true;
|
|
1835
|
+
console.log('\n\n' + chalk.yellow('⏸️ Pausing session and terminating Claude Code...'));
|
|
1836
|
+
try {
|
|
1837
|
+
// Terminate Claude Code process
|
|
1838
|
+
if (claudeProcess && !claudeProcess.killed) {
|
|
1839
|
+
claudeProcess.kill('SIGTERM');
|
|
1840
|
+
}
|
|
1841
|
+
// Save checkpoint and pause session
|
|
1842
|
+
if (sessionId) {
|
|
1843
|
+
const checkpointData = {
|
|
1844
|
+
timestamp: new Date().toISOString(),
|
|
1845
|
+
swarmId,
|
|
1846
|
+
objective,
|
|
1847
|
+
status: 'paused_by_user',
|
|
1848
|
+
reason: 'User pressed Ctrl+C during Claude Code execution',
|
|
1849
|
+
claudePid: claudeProcess.pid
|
|
1850
|
+
};
|
|
1851
|
+
await sessionManager.saveCheckpoint(sessionId, 'auto-pause-claude', checkpointData);
|
|
1852
|
+
await sessionManager.pauseSession(sessionId);
|
|
1853
|
+
console.log(chalk.green('✓') + ' Session paused successfully');
|
|
1854
|
+
console.log(chalk.cyan('\nTo resume this session, run:'));
|
|
1855
|
+
console.log(chalk.bold(` claude-flow-novice hive-mind resume ${sessionId}`));
|
|
1856
|
+
}
|
|
1857
|
+
sessionManager.close();
|
|
1858
|
+
process.exit(0);
|
|
1859
|
+
} catch (error) {
|
|
1860
|
+
console.error(chalk.red('Error pausing session:'), error.message);
|
|
1861
|
+
sessionManager.close();
|
|
1862
|
+
process.exit(1);
|
|
1863
|
+
}
|
|
1864
|
+
};
|
|
1865
|
+
// Register SIGINT handler
|
|
1866
|
+
process.on('SIGINT', sigintHandler);
|
|
1867
|
+
process.on('SIGTERM', sigintHandler);
|
|
1868
|
+
// Handle stdout
|
|
1869
|
+
if (claudeProcess.stdout) {
|
|
1870
|
+
claudeProcess.stdout.on('data', (data)=>{
|
|
1871
|
+
console.log(data.toString());
|
|
1872
|
+
});
|
|
1873
|
+
}
|
|
1874
|
+
// Handle stderr
|
|
1875
|
+
if (claudeProcess.stderr) {
|
|
1876
|
+
claudeProcess.stderr.on('data', (data)=>{
|
|
1877
|
+
console.error(chalk.red(data.toString()));
|
|
1878
|
+
});
|
|
1879
|
+
}
|
|
1880
|
+
// Handle process exit
|
|
1881
|
+
claudeProcess.on('exit', (code)=>{
|
|
1882
|
+
// Remove child PID from session
|
|
1883
|
+
if (sessionId && claudeProcess.pid) {
|
|
1884
|
+
sessionManager.removeChildPid(sessionId, claudeProcess.pid);
|
|
1885
|
+
sessionManager.close();
|
|
1886
|
+
}
|
|
1887
|
+
if (code === 0) {
|
|
1888
|
+
console.log(chalk.green('\n✓ Claude Code completed successfully'));
|
|
1889
|
+
} else if (code !== null) {
|
|
1890
|
+
console.log(chalk.red(`\n✗ Claude Code exited with code ${code}`));
|
|
1891
|
+
}
|
|
1892
|
+
});
|
|
1893
|
+
console.log(chalk.green('\n✓ Claude Code launched with Hive Mind coordination'));
|
|
1894
|
+
console.log(chalk.blue(' The Queen coordinator will orchestrate all worker agents'));
|
|
1895
|
+
console.log(chalk.blue(' Use MCP tools for collective intelligence and task distribution'));
|
|
1896
|
+
console.log(chalk.gray(` Prompt file saved at: ${promptFile}`));
|
|
1897
|
+
} else if (flags.dryRun) {
|
|
1898
|
+
console.log(chalk.blue('\nDry run - would execute Claude Code with prompt:'));
|
|
1899
|
+
console.log(chalk.gray('Prompt length:'), hiveMindPrompt.length, 'characters');
|
|
1900
|
+
console.log(chalk.gray('\nFirst 500 characters of prompt:'));
|
|
1901
|
+
console.log(chalk.yellow(hiveMindPrompt.substring(0, 500) + '...'));
|
|
1902
|
+
console.log(chalk.gray(`\nFull prompt saved to: ${promptFile}`));
|
|
1903
|
+
} else {
|
|
1904
|
+
// Claude not available - show instructions with already saved prompt
|
|
1905
|
+
console.log(chalk.yellow('\n📋 Manual Execution Instructions:'));
|
|
1906
|
+
console.log(chalk.gray('─'.repeat(50)));
|
|
1907
|
+
console.log(chalk.gray('1. Install Claude Code:'));
|
|
1908
|
+
console.log(chalk.green(' npm install -g @anthropic-ai/claude-code'));
|
|
1909
|
+
console.log(chalk.gray('\n2. Run with the saved prompt:'));
|
|
1910
|
+
console.log(chalk.green(` claude < ${promptFile}`));
|
|
1911
|
+
console.log(chalk.gray('\n3. Or copy the prompt manually:'));
|
|
1912
|
+
console.log(chalk.green(` cat ${promptFile} | claude`));
|
|
1913
|
+
console.log(chalk.gray('\n4. With auto-permissions:'));
|
|
1914
|
+
console.log(chalk.green(` claude --dangerously-skip-permissions < ${promptFile}`));
|
|
2129
1915
|
}
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
}
|
|
2138
|
-
};
|
|
2139
|
-
|
|
2140
|
-
// Register SIGINT handler
|
|
2141
|
-
process.on('SIGINT', sigintHandler);
|
|
2142
|
-
process.on('SIGTERM', sigintHandler);
|
|
2143
|
-
|
|
2144
|
-
// Handle stdout
|
|
2145
|
-
if (claudeProcess.stdout) {
|
|
2146
|
-
claudeProcess.stdout.on('data', (data) => {
|
|
2147
|
-
console.log(data.toString());
|
|
2148
|
-
});
|
|
2149
|
-
}
|
|
2150
|
-
|
|
2151
|
-
// Handle stderr
|
|
2152
|
-
if (claudeProcess.stderr) {
|
|
2153
|
-
claudeProcess.stderr.on('data', (data) => {
|
|
2154
|
-
console.error(chalk.red(data.toString()));
|
|
2155
|
-
});
|
|
1916
|
+
} catch (error) {
|
|
1917
|
+
console.error(chalk.red('\nFailed to launch Claude Code:'), error.message);
|
|
1918
|
+
// Save prompt as fallback
|
|
1919
|
+
const promptFile = `hive-mind-prompt-${swarmId}-fallback.txt`;
|
|
1920
|
+
await writeFile(promptFile, hiveMindPrompt, 'utf8');
|
|
1921
|
+
console.log(chalk.green(`\n✓ Prompt saved to: ${promptFile}`));
|
|
1922
|
+
console.log(chalk.yellow('\nYou can run Claude Code manually with the saved prompt'));
|
|
2156
1923
|
}
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
sessionManager.close();
|
|
2164
|
-
}
|
|
2165
|
-
|
|
2166
|
-
if (code === 0) {
|
|
2167
|
-
console.log(chalk.green('\n✓ Claude Code completed successfully'));
|
|
2168
|
-
} else if (code !== null) {
|
|
2169
|
-
console.log(chalk.red(`\n✗ Claude Code exited with code ${code}`));
|
|
2170
|
-
}
|
|
2171
|
-
});
|
|
2172
|
-
|
|
2173
|
-
console.log(chalk.green('\n✓ Claude Code launched with Hive Mind coordination'));
|
|
2174
|
-
console.log(chalk.blue(' The Queen coordinator will orchestrate all worker agents'));
|
|
2175
|
-
console.log(
|
|
2176
|
-
chalk.blue(' Use MCP tools for collective intelligence and task distribution'),
|
|
2177
|
-
);
|
|
2178
|
-
console.log(chalk.gray(` Prompt file saved at: ${promptFile}`));
|
|
2179
|
-
} else if (flags.dryRun) {
|
|
2180
|
-
console.log(chalk.blue('\nDry run - would execute Claude Code with prompt:'));
|
|
2181
|
-
console.log(chalk.gray('Prompt length:'), hiveMindPrompt.length, 'characters');
|
|
2182
|
-
console.log(chalk.gray('\nFirst 500 characters of prompt:'));
|
|
2183
|
-
console.log(chalk.yellow(hiveMindPrompt.substring(0, 500) + '...'));
|
|
2184
|
-
console.log(chalk.gray(`\nFull prompt saved to: ${promptFile}`));
|
|
2185
|
-
} else {
|
|
2186
|
-
// Claude not available - show instructions with already saved prompt
|
|
2187
|
-
console.log(chalk.yellow('\n📋 Manual Execution Instructions:'));
|
|
2188
|
-
console.log(chalk.gray('─'.repeat(50)));
|
|
2189
|
-
console.log(chalk.gray('1. Install Claude Code:'));
|
|
2190
|
-
console.log(chalk.green(' npm install -g @anthropic-ai/claude-code'));
|
|
2191
|
-
console.log(chalk.gray('\n2. Run with the saved prompt:'));
|
|
2192
|
-
console.log(chalk.green(` claude < ${promptFile}`));
|
|
2193
|
-
console.log(chalk.gray('\n3. Or copy the prompt manually:'));
|
|
2194
|
-
console.log(chalk.green(` cat ${promptFile} | claude`));
|
|
2195
|
-
console.log(chalk.gray('\n4. With auto-permissions:'));
|
|
2196
|
-
console.log(chalk.green(` claude --dangerously-skip-permissions < ${promptFile}`));
|
|
2197
|
-
}
|
|
1924
|
+
console.log('\n' + chalk.bold('💡 Pro Tips:'));
|
|
1925
|
+
console.log(chalk.gray('─'.repeat(30)));
|
|
1926
|
+
console.log('• Use --auto-spawn to launch instances automatically');
|
|
1927
|
+
console.log('• Add --verbose for detailed coordination context');
|
|
1928
|
+
console.log('• Monitor with: claude-flow-novice hive-mind status');
|
|
1929
|
+
console.log('• Share memories: mcp__ruv-swarm__memory_usage');
|
|
2198
1930
|
} catch (error) {
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
// Save prompt as fallback
|
|
2202
|
-
const promptFile = `hive-mind-prompt-${swarmId}-fallback.txt`;
|
|
2203
|
-
await writeFile(promptFile, hiveMindPrompt, 'utf8');
|
|
2204
|
-
console.log(chalk.green(`\n✓ Prompt saved to: ${promptFile}`));
|
|
2205
|
-
console.log(chalk.yellow('\nYou can run Claude Code manually with the saved prompt'));
|
|
1931
|
+
spinner.fail('Failed to prepare Claude Code coordination');
|
|
1932
|
+
console.error(chalk.red('Error:'), error.message);
|
|
2206
1933
|
}
|
|
2207
|
-
|
|
2208
|
-
console.log('\n' + chalk.bold('💡 Pro Tips:'));
|
|
2209
|
-
console.log(chalk.gray('─'.repeat(30)));
|
|
2210
|
-
console.log('• Use --auto-spawn to launch instances automatically');
|
|
2211
|
-
console.log('• Add --verbose for detailed coordination context');
|
|
2212
|
-
console.log('• Monitor with: claude-flow-novice hive-mind status');
|
|
2213
|
-
console.log('• Share memories: mcp__ruv-swarm__memory_usage');
|
|
2214
|
-
} catch (error) {
|
|
2215
|
-
spinner.fail('Failed to prepare Claude Code coordination');
|
|
2216
|
-
console.error(chalk.red('Error:'), error.message);
|
|
2217
|
-
}
|
|
2218
1934
|
}
|
|
2219
|
-
|
|
2220
1935
|
/**
|
|
2221
1936
|
* Generate comprehensive Hive Mind prompt for Claude Code
|
|
2222
|
-
*/
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
return `🧠 HIVE MIND COLLECTIVE INTELLIGENCE SYSTEM
|
|
1937
|
+
*/ function generateHiveMindPrompt(swarmId, swarmName, objective, workers, workerGroups, flags) {
|
|
1938
|
+
const currentTime = new Date().toISOString();
|
|
1939
|
+
const workerTypes = Object.keys(workerGroups);
|
|
1940
|
+
const queenType = flags.queenType || 'strategic';
|
|
1941
|
+
const consensusAlgorithm = flags.consensus || 'majority';
|
|
1942
|
+
return `🧠 HIVE MIND COLLECTIVE INTELLIGENCE SYSTEM
|
|
2230
1943
|
═══════════════════════════════════════════════
|
|
2231
1944
|
|
|
2232
1945
|
You are the Queen coordinator of a Hive Mind swarm with collective intelligence capabilities.
|
|
@@ -2241,7 +1954,7 @@ HIVE MIND CONFIGURATION:
|
|
|
2241
1954
|
⏰ Initialized: ${currentTime}
|
|
2242
1955
|
|
|
2243
1956
|
WORKER DISTRIBUTION:
|
|
2244
|
-
${workerTypes.map((type)
|
|
1957
|
+
${workerTypes.map((type)=>`• ${type}: ${workerGroups[type].length} agents`).join('\n')}
|
|
2245
1958
|
|
|
2246
1959
|
🔧 AVAILABLE MCP TOOLS FOR HIVE MIND COORDINATION:
|
|
2247
1960
|
|
|
@@ -2283,14 +1996,14 @@ As the Queen coordinator, you must:
|
|
|
2283
1996
|
|
|
2284
1997
|
Step 1: Optional MCP Coordination Setup (Single Message):
|
|
2285
1998
|
[MCP Tools - Coordination Only]:
|
|
2286
|
-
${workerTypes.map((type)
|
|
1999
|
+
${workerTypes.map((type)=>` mcp__claude-flow__agent_spawn { "type": "${type}", "count": ${workerGroups[type].length} }`).join('\n')}
|
|
2287
2000
|
mcp__claude-flow__memory_store { "key": "hive/objective", "value": "${objective}" }
|
|
2288
2001
|
mcp__claude-flow__memory_store { "key": "hive/queen", "value": "${queenType}" }
|
|
2289
2002
|
mcp__claude-flow__swarm_think { "topic": "initial_strategy" }
|
|
2290
2003
|
|
|
2291
2004
|
Step 2: REQUIRED - Spawn ACTUAL Agents with Claude Code's Task Tool (Single Message):
|
|
2292
2005
|
[Claude Code Task Tool - CONCURRENT Agent Execution]:
|
|
2293
|
-
${workerTypes.map((type)
|
|
2006
|
+
${workerTypes.map((type)=>` Task("${type.charAt(0).toUpperCase() + type.slice(1)} Agent", "You are a ${type} in the hive. Coordinate via hooks. ${getWorkerTypeInstructions(type).split('\n')[0]}", "${type}")`).join('\n')}
|
|
2294
2007
|
|
|
2295
2008
|
Step 3: Batch ALL Todos Together (Single TodoWrite Call):
|
|
2296
2009
|
TodoWrite { "todos": [
|
|
@@ -2311,33 +2024,21 @@ As the Queen coordinator, you must:
|
|
|
2311
2024
|
- Coordinate strategy with swarm_think
|
|
2312
2025
|
|
|
2313
2026
|
3. **QUEEN LEADERSHIP PATTERNS**:
|
|
2314
|
-
${
|
|
2315
|
-
queenType === 'strategic'
|
|
2316
|
-
? `
|
|
2027
|
+
${queenType === 'strategic' ? `
|
|
2317
2028
|
- Focus on high-level planning and coordination
|
|
2318
2029
|
- Delegate implementation details to workers
|
|
2319
2030
|
- Monitor overall progress and adjust strategy
|
|
2320
|
-
- Make executive decisions when consensus fails`
|
|
2321
|
-
|
|
2322
|
-
}
|
|
2323
|
-
${
|
|
2324
|
-
queenType === 'tactical'
|
|
2325
|
-
? `
|
|
2031
|
+
- Make executive decisions when consensus fails` : ''}
|
|
2032
|
+
${queenType === 'tactical' ? `
|
|
2326
2033
|
- Manage detailed task breakdowns and assignments
|
|
2327
2034
|
- Closely monitor worker progress and efficiency
|
|
2328
2035
|
- Optimize resource allocation and load balancing
|
|
2329
|
-
- Intervene directly when workers need guidance`
|
|
2330
|
-
|
|
2331
|
-
}
|
|
2332
|
-
${
|
|
2333
|
-
queenType === 'adaptive'
|
|
2334
|
-
? `
|
|
2036
|
+
- Intervene directly when workers need guidance` : ''}
|
|
2037
|
+
${queenType === 'adaptive' ? `
|
|
2335
2038
|
- Learn from swarm performance and adapt strategies
|
|
2336
2039
|
- Experiment with different coordination patterns
|
|
2337
2040
|
- Use neural training to improve over time
|
|
2338
|
-
- Balance between strategic and tactical approaches`
|
|
2339
|
-
: ''
|
|
2340
|
-
}
|
|
2041
|
+
- Balance between strategic and tactical approaches` : ''}
|
|
2341
2042
|
|
|
2342
2043
|
4. **WORKER COORDINATION**:
|
|
2343
2044
|
- Spawn workers based on task requirements
|
|
@@ -2421,64 +2122,51 @@ Initialize the swarm now with the configuration above. Use your collective intel
|
|
|
2421
2122
|
|
|
2422
2123
|
Remember: You are not just coordinating agents - you are orchestrating a collective intelligence that is greater than the sum of its parts.`;
|
|
2423
2124
|
}
|
|
2424
|
-
|
|
2425
2125
|
/**
|
|
2426
2126
|
* Generate comprehensive coordination instructions for Claude Code instances
|
|
2427
|
-
*/
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
}
|
|
2454
|
-
};
|
|
2127
|
+
*/ function generateCoordinationInstructions(swarmId, swarmName, objective, workers) {
|
|
2128
|
+
return {
|
|
2129
|
+
swarmId,
|
|
2130
|
+
swarmName,
|
|
2131
|
+
objective,
|
|
2132
|
+
hiveMindEndpoint: 'ws://localhost:3000/hive-mind',
|
|
2133
|
+
mcpTools: [
|
|
2134
|
+
'mcp__ruv-swarm__memory_usage',
|
|
2135
|
+
'mcp__ruv-swarm__swarm_monitor',
|
|
2136
|
+
'mcp__ruv-swarm__task_orchestrate',
|
|
2137
|
+
'mcp__ruv-swarm__neural_train',
|
|
2138
|
+
'mcp__ruv-swarm__consensus_vote',
|
|
2139
|
+
'mcp__ruv-swarm__agent_spawn',
|
|
2140
|
+
'mcp__ruv-swarm__swarm_status'
|
|
2141
|
+
],
|
|
2142
|
+
coordinationProtocol: {
|
|
2143
|
+
memoryNamespace: `hive-mind-${swarmId}`,
|
|
2144
|
+
consensusThreshold: 0.7,
|
|
2145
|
+
taskUpdateInterval: 30000,
|
|
2146
|
+
healthCheckInterval: 60000
|
|
2147
|
+
},
|
|
2148
|
+
workerCapabilities: workers.map((w)=>({
|
|
2149
|
+
id: w.id,
|
|
2150
|
+
type: w.type,
|
|
2151
|
+
capabilities: JSON.parse(w.capabilities)
|
|
2152
|
+
}))
|
|
2153
|
+
};
|
|
2455
2154
|
}
|
|
2456
|
-
|
|
2457
2155
|
/**
|
|
2458
2156
|
* Group workers by type for specialized spawning
|
|
2459
|
-
*/
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
}, {});
|
|
2157
|
+
*/ function groupWorkersByType(workers) {
|
|
2158
|
+
return workers.reduce((groups, worker)=>{
|
|
2159
|
+
if (!groups[worker.type]) {
|
|
2160
|
+
groups[worker.type] = [];
|
|
2161
|
+
}
|
|
2162
|
+
groups[worker.type].push(worker);
|
|
2163
|
+
return groups;
|
|
2164
|
+
}, {});
|
|
2468
2165
|
}
|
|
2469
|
-
|
|
2470
2166
|
/**
|
|
2471
2167
|
* Create Claude Code spawn command with coordination context
|
|
2472
|
-
*/
|
|
2473
|
-
|
|
2474
|
-
swarmId,
|
|
2475
|
-
swarmName,
|
|
2476
|
-
objective,
|
|
2477
|
-
workerType,
|
|
2478
|
-
typeWorkers,
|
|
2479
|
-
instructions,
|
|
2480
|
-
) {
|
|
2481
|
-
const context = `You are a ${workerType} agent in the "${swarmName}" Hive Mind swarm.
|
|
2168
|
+
*/ function createClaudeCodeSpawnCommand(swarmId, swarmName, objective, workerType, typeWorkers, instructions) {
|
|
2169
|
+
const context = `You are a ${workerType} agent in the "${swarmName}" Hive Mind swarm.
|
|
2482
2170
|
|
|
2483
2171
|
🎯 MISSION: ${objective}
|
|
2484
2172
|
|
|
@@ -2517,376 +2205,274 @@ ${getWorkerTypeInstructions(workerType)}
|
|
|
2517
2205
|
- Learn from patterns via neural_train
|
|
2518
2206
|
|
|
2519
2207
|
Remember: You are part of a COLLECTIVE INTELLIGENCE. Your individual success depends on swarm coordination!`;
|
|
2520
|
-
|
|
2521
|
-
|
|
2522
|
-
|
|
2523
|
-
|
|
2524
|
-
|
|
2525
|
-
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
count: typeWorkers.length,
|
|
2529
|
-
};
|
|
2208
|
+
const command = `claude code --context "${context.replace(/"/g, '\\"')}"`;
|
|
2209
|
+
return {
|
|
2210
|
+
title: `${workerType.toUpperCase()} Agent (${typeWorkers.length} instance${typeWorkers.length > 1 ? 's' : ''})`,
|
|
2211
|
+
command,
|
|
2212
|
+
context,
|
|
2213
|
+
workerType,
|
|
2214
|
+
count: typeWorkers.length
|
|
2215
|
+
};
|
|
2530
2216
|
}
|
|
2531
|
-
|
|
2532
2217
|
/**
|
|
2533
2218
|
* Get specialized instructions for each worker type
|
|
2534
|
-
*/
|
|
2535
|
-
|
|
2536
|
-
|
|
2537
|
-
researcher: `- Conduct thorough research using WebSearch and WebFetch
|
|
2219
|
+
*/ function getWorkerTypeInstructions(workerType) {
|
|
2220
|
+
const instructions = {
|
|
2221
|
+
researcher: `- Conduct thorough research using WebSearch and WebFetch
|
|
2538
2222
|
- Document findings in structured formats
|
|
2539
2223
|
- Validate source credibility and relevance
|
|
2540
2224
|
- Synthesize insights from multiple sources
|
|
2541
2225
|
- Share research methodology and results`,
|
|
2542
|
-
|
|
2543
|
-
coder: `- Write clean, maintainable, well-documented code
|
|
2226
|
+
coder: `- Write clean, maintainable, well-documented code
|
|
2544
2227
|
- Follow project conventions and best practices
|
|
2545
2228
|
- Test implementations thoroughly
|
|
2546
2229
|
- Document code changes and decisions
|
|
2547
2230
|
- Review and optimize existing code`,
|
|
2548
|
-
|
|
2549
|
-
analyst: `- Analyze data patterns and trends
|
|
2231
|
+
analyst: `- Analyze data patterns and trends
|
|
2550
2232
|
- Create comprehensive reports and visualizations
|
|
2551
2233
|
- Identify key insights and recommendations
|
|
2552
2234
|
- Validate analytical methodologies
|
|
2553
2235
|
- Correlate findings across data sources`,
|
|
2554
|
-
|
|
2555
|
-
tester: `- Design comprehensive test strategies
|
|
2236
|
+
tester: `- Design comprehensive test strategies
|
|
2556
2237
|
- Execute functional, integration, and performance tests
|
|
2557
2238
|
- Document test results and issues
|
|
2558
2239
|
- Verify bug fixes and improvements
|
|
2559
2240
|
- Ensure quality standards and coverage`,
|
|
2560
|
-
|
|
2561
|
-
coordinator: `- Monitor overall progress and coordination
|
|
2241
|
+
coordinator: `- Monitor overall progress and coordination
|
|
2562
2242
|
- Facilitate communication between agents
|
|
2563
2243
|
- Resolve conflicts and blockers
|
|
2564
2244
|
- Optimize resource allocation
|
|
2565
2245
|
- Ensure alignment with objectives`,
|
|
2566
|
-
|
|
2567
|
-
architect: `- Design system architecture and components
|
|
2246
|
+
architect: `- Design system architecture and components
|
|
2568
2247
|
- Define technical standards and patterns
|
|
2569
2248
|
- Create implementation guidelines
|
|
2570
2249
|
- Review and approve design decisions
|
|
2571
|
-
- Ensure scalability and maintainability
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
return (
|
|
2575
|
-
instructions[workerType] ||
|
|
2576
|
-
`- Execute tasks according to ${workerType} best practices
|
|
2250
|
+
- Ensure scalability and maintainability`
|
|
2251
|
+
};
|
|
2252
|
+
return instructions[workerType] || `- Execute tasks according to ${workerType} best practices
|
|
2577
2253
|
- Collaborate effectively with team members
|
|
2578
2254
|
- Document work and share insights
|
|
2579
2255
|
- Maintain quality standards
|
|
2580
|
-
- Contribute to collective objectives
|
|
2581
|
-
);
|
|
2256
|
+
- Contribute to collective objectives`;
|
|
2582
2257
|
}
|
|
2583
|
-
|
|
2584
2258
|
/**
|
|
2585
2259
|
* Show all hive mind sessions
|
|
2586
|
-
*/
|
|
2587
|
-
|
|
2588
|
-
|
|
2589
|
-
|
|
2590
|
-
|
|
2591
|
-
|
|
2592
|
-
|
|
2593
|
-
|
|
2594
|
-
|
|
2595
|
-
|
|
2260
|
+
*/ async function showSessions(flags) {
|
|
2261
|
+
try {
|
|
2262
|
+
const sessionManager = new HiveMindSessionManager();
|
|
2263
|
+
const sessions = await sessionManager.getActiveSessions();
|
|
2264
|
+
if (sessions.length === 0) {
|
|
2265
|
+
console.log(chalk.gray('No active or paused sessions found'));
|
|
2266
|
+
sessionManager.close();
|
|
2267
|
+
return;
|
|
2268
|
+
}
|
|
2269
|
+
console.log(chalk.bold('\n🗂️ Hive Mind Sessions\n'));
|
|
2270
|
+
sessions.forEach((session, index)=>{
|
|
2271
|
+
const statusColor = session.status === 'active' ? 'green' : session.status === 'paused' ? 'yellow' : 'gray';
|
|
2272
|
+
const statusIcon = session.status === 'active' ? '🟢' : session.status === 'paused' ? '🟡' : '⚫';
|
|
2273
|
+
console.log(chalk.yellow('═'.repeat(60)));
|
|
2274
|
+
console.log(`${statusIcon} ${chalk.bold(session.swarm_name)}`);
|
|
2275
|
+
console.log(chalk.cyan('Session ID:'), session.id);
|
|
2276
|
+
console.log(chalk.cyan('Status:'), chalk[statusColor](session.status));
|
|
2277
|
+
console.log(chalk.cyan('Objective:'), session.objective);
|
|
2278
|
+
console.log(chalk.cyan('Progress:'), `${session.completion_percentage}%`);
|
|
2279
|
+
console.log(chalk.cyan('Created:'), new Date(session.created_at).toLocaleString());
|
|
2280
|
+
console.log(chalk.cyan('Last Updated:'), new Date(session.updated_at).toLocaleString());
|
|
2281
|
+
if (session.paused_at) {
|
|
2282
|
+
console.log(chalk.cyan('Paused At:'), new Date(session.paused_at).toLocaleString());
|
|
2283
|
+
}
|
|
2284
|
+
console.log('\n' + chalk.bold('Progress:'));
|
|
2285
|
+
console.log(` Agents: ${session.agent_count || 0}`);
|
|
2286
|
+
console.log(` Tasks: ${session.completed_tasks || 0}/${session.task_count || 0}`);
|
|
2287
|
+
if (session.checkpoint_data) {
|
|
2288
|
+
console.log('\n' + chalk.bold('Last Checkpoint:'));
|
|
2289
|
+
console.log(chalk.gray(JSON.stringify(session.checkpoint_data, null, 2).substring(0, 200) + '...'));
|
|
2290
|
+
}
|
|
2291
|
+
});
|
|
2292
|
+
console.log(chalk.yellow('═'.repeat(60)) + '\n');
|
|
2293
|
+
console.log(chalk.blue('💡 Tips:'));
|
|
2294
|
+
console.log(' • Resume a session: claude-flow-novice hive-mind resume <session-id>');
|
|
2295
|
+
console.log(' • View session details: claude-flow-novice hive-mind status');
|
|
2296
|
+
sessionManager.close();
|
|
2297
|
+
} catch (error) {
|
|
2298
|
+
console.error(chalk.red('Error:'), error.message);
|
|
2299
|
+
exit(1);
|
|
2596
2300
|
}
|
|
2597
|
-
|
|
2598
|
-
console.log(chalk.bold('\n🗂️ Hive Mind Sessions\n'));
|
|
2599
|
-
|
|
2600
|
-
sessions.forEach((session, index) => {
|
|
2601
|
-
const statusColor =
|
|
2602
|
-
session.status === 'active' ? 'green' : session.status === 'paused' ? 'yellow' : 'gray';
|
|
2603
|
-
const statusIcon =
|
|
2604
|
-
session.status === 'active' ? '🟢' : session.status === 'paused' ? '🟡' : '⚫';
|
|
2605
|
-
|
|
2606
|
-
console.log(chalk.yellow('═'.repeat(60)));
|
|
2607
|
-
console.log(`${statusIcon} ${chalk.bold(session.swarm_name)}`);
|
|
2608
|
-
console.log(chalk.cyan('Session ID:'), session.id);
|
|
2609
|
-
console.log(chalk.cyan('Status:'), chalk[statusColor](session.status));
|
|
2610
|
-
console.log(chalk.cyan('Objective:'), session.objective);
|
|
2611
|
-
console.log(chalk.cyan('Progress:'), `${session.completion_percentage}%`);
|
|
2612
|
-
console.log(chalk.cyan('Created:'), new Date(session.created_at).toLocaleString());
|
|
2613
|
-
console.log(chalk.cyan('Last Updated:'), new Date(session.updated_at).toLocaleString());
|
|
2614
|
-
|
|
2615
|
-
if (session.paused_at) {
|
|
2616
|
-
console.log(chalk.cyan('Paused At:'), new Date(session.paused_at).toLocaleString());
|
|
2617
|
-
}
|
|
2618
|
-
|
|
2619
|
-
console.log('\n' + chalk.bold('Progress:'));
|
|
2620
|
-
console.log(` Agents: ${session.agent_count || 0}`);
|
|
2621
|
-
console.log(` Tasks: ${session.completed_tasks || 0}/${session.task_count || 0}`);
|
|
2622
|
-
|
|
2623
|
-
if (session.checkpoint_data) {
|
|
2624
|
-
console.log('\n' + chalk.bold('Last Checkpoint:'));
|
|
2625
|
-
console.log(
|
|
2626
|
-
chalk.gray(JSON.stringify(session.checkpoint_data, null, 2).substring(0, 200) + '...'),
|
|
2627
|
-
);
|
|
2628
|
-
}
|
|
2629
|
-
});
|
|
2630
|
-
|
|
2631
|
-
console.log(chalk.yellow('═'.repeat(60)) + '\n');
|
|
2632
|
-
|
|
2633
|
-
console.log(chalk.blue('💡 Tips:'));
|
|
2634
|
-
console.log(' • Resume a session: claude-flow-novice hive-mind resume <session-id>');
|
|
2635
|
-
console.log(' • View session details: claude-flow-novice hive-mind status');
|
|
2636
|
-
|
|
2637
|
-
sessionManager.close();
|
|
2638
|
-
} catch (error) {
|
|
2639
|
-
console.error(chalk.red('Error:'), error.message);
|
|
2640
|
-
exit(1);
|
|
2641
|
-
}
|
|
2642
2301
|
}
|
|
2643
|
-
|
|
2644
2302
|
/**
|
|
2645
2303
|
* Resume a paused hive mind session
|
|
2646
|
-
*/
|
|
2647
|
-
|
|
2648
|
-
|
|
2649
|
-
|
|
2650
|
-
|
|
2651
|
-
|
|
2652
|
-
|
|
2653
|
-
console.log('Run "claude-flow-novice hive-mind sessions" to see available sessions');
|
|
2654
|
-
return;
|
|
2655
|
-
}
|
|
2656
|
-
|
|
2657
|
-
const spinner = ora('Resuming Hive Mind session...').start();
|
|
2658
|
-
|
|
2659
|
-
try {
|
|
2660
|
-
const sessionManager = new HiveMindSessionManager();
|
|
2661
|
-
|
|
2662
|
-
// Get session details
|
|
2663
|
-
const session = await sessionManager.getSession(sessionId);
|
|
2664
|
-
|
|
2665
|
-
if (!session) {
|
|
2666
|
-
spinner.fail(`Session ${sessionId} not found`);
|
|
2667
|
-
console.log('\nRun "claude-flow-novice hive-mind sessions" to see available sessions');
|
|
2668
|
-
sessionManager.close();
|
|
2669
|
-
return;
|
|
2304
|
+
*/ async function resumeSession(args, flags) {
|
|
2305
|
+
const sessionId = args[0];
|
|
2306
|
+
if (!sessionId) {
|
|
2307
|
+
console.error(chalk.red('Error: Please provide a session ID'));
|
|
2308
|
+
console.log('Usage: claude-flow-novice hive-mind resume <session-id>');
|
|
2309
|
+
console.log('Run "claude-flow-novice hive-mind sessions" to see available sessions');
|
|
2310
|
+
return;
|
|
2670
2311
|
}
|
|
2671
|
-
|
|
2672
|
-
|
|
2673
|
-
|
|
2674
|
-
|
|
2675
|
-
|
|
2676
|
-
|
|
2677
|
-
|
|
2678
|
-
|
|
2679
|
-
|
|
2680
|
-
|
|
2681
|
-
|
|
2682
|
-
|
|
2683
|
-
|
|
2684
|
-
|
|
2685
|
-
|
|
2686
|
-
|
|
2687
|
-
|
|
2688
|
-
|
|
2689
|
-
|
|
2690
|
-
|
|
2691
|
-
|
|
2692
|
-
|
|
2693
|
-
|
|
2694
|
-
|
|
2695
|
-
|
|
2696
|
-
|
|
2697
|
-
|
|
2698
|
-
|
|
2699
|
-
|
|
2700
|
-
|
|
2701
|
-
|
|
2702
|
-
|
|
2703
|
-
|
|
2704
|
-
|
|
2705
|
-
|
|
2706
|
-
|
|
2707
|
-
|
|
2708
|
-
|
|
2709
|
-
|
|
2710
|
-
|
|
2711
|
-
|
|
2712
|
-
|
|
2713
|
-
|
|
2714
|
-
|
|
2715
|
-
|
|
2716
|
-
|
|
2717
|
-
|
|
2718
|
-
|
|
2719
|
-
|
|
2720
|
-
|
|
2721
|
-
|
|
2722
|
-
|
|
2723
|
-
|
|
2724
|
-
|
|
2725
|
-
|
|
2726
|
-
|
|
2727
|
-
|
|
2728
|
-
|
|
2729
|
-
|
|
2730
|
-
|
|
2731
|
-
|
|
2732
|
-
|
|
2733
|
-
|
|
2734
|
-
console.log(
|
|
2735
|
-
'\n' +
|
|
2736
|
-
chalk.blue('💡 Pro Tip:') +
|
|
2737
|
-
' Add --claude to spawn Claude Code with restored context',
|
|
2738
|
-
);
|
|
2739
|
-
console.log(chalk.gray(' claude-flow-novice hive-mind resume ' + sessionId + ' --claude'));
|
|
2312
|
+
const spinner = ora('Resuming Hive Mind session...').start();
|
|
2313
|
+
try {
|
|
2314
|
+
const sessionManager = new HiveMindSessionManager();
|
|
2315
|
+
// Get session details
|
|
2316
|
+
const session = await sessionManager.getSession(sessionId);
|
|
2317
|
+
if (!session) {
|
|
2318
|
+
spinner.fail(`Session ${sessionId} not found`);
|
|
2319
|
+
console.log('\nRun "claude-flow-novice hive-mind sessions" to see available sessions');
|
|
2320
|
+
sessionManager.close();
|
|
2321
|
+
return;
|
|
2322
|
+
}
|
|
2323
|
+
// Allow resuming any session regardless of status
|
|
2324
|
+
spinner.text = `Resuming session from status: ${session.status}...`;
|
|
2325
|
+
if (session.status === 'stopped') {
|
|
2326
|
+
spinner.text = 'Restarting stopped session with original configuration...';
|
|
2327
|
+
}
|
|
2328
|
+
// Resume the session
|
|
2329
|
+
const resumedSession = await sessionManager.resumeSession(sessionId);
|
|
2330
|
+
spinner.succeed('Session resumed successfully!');
|
|
2331
|
+
// Display session summary
|
|
2332
|
+
console.log('\n' + chalk.bold('📋 Resumed Session Summary:'));
|
|
2333
|
+
console.log(chalk.gray('─'.repeat(50)));
|
|
2334
|
+
console.log(chalk.cyan('Session ID:'), sessionId);
|
|
2335
|
+
console.log(chalk.cyan('Swarm Name:'), resumedSession.swarm_name);
|
|
2336
|
+
console.log(chalk.cyan('Objective:'), resumedSession.objective);
|
|
2337
|
+
console.log(chalk.cyan('Progress:'), `${resumedSession.statistics.completionPercentage}%`);
|
|
2338
|
+
console.log(chalk.cyan('Active Agents:'), `${resumedSession.statistics.activeAgents}/${resumedSession.statistics.totalAgents}`);
|
|
2339
|
+
console.log(chalk.cyan('Tasks:'), `${resumedSession.statistics.completedTasks}/${resumedSession.statistics.totalTasks} completed`);
|
|
2340
|
+
console.log(chalk.gray('─'.repeat(50)));
|
|
2341
|
+
// Show task breakdown
|
|
2342
|
+
console.log('\n' + chalk.bold('📊 Task Status:'));
|
|
2343
|
+
console.log(` ✅ Completed: ${resumedSession.statistics.completedTasks}`);
|
|
2344
|
+
console.log(` 🔄 In Progress: ${resumedSession.statistics.inProgressTasks}`);
|
|
2345
|
+
console.log(` ⏳ Pending: ${resumedSession.statistics.pendingTasks}`);
|
|
2346
|
+
// Show recent activity
|
|
2347
|
+
if (resumedSession.recentLogs && resumedSession.recentLogs.length > 0) {
|
|
2348
|
+
console.log('\n' + chalk.bold('📜 Recent Activity:'));
|
|
2349
|
+
resumedSession.recentLogs.slice(0, 5).forEach((log)=>{
|
|
2350
|
+
const timestamp = new Date(log.timestamp).toLocaleTimeString();
|
|
2351
|
+
console.log(` [${timestamp}] ${log.message}`);
|
|
2352
|
+
});
|
|
2353
|
+
}
|
|
2354
|
+
// Restore checkpoint if available
|
|
2355
|
+
if (resumedSession.checkpoint_data) {
|
|
2356
|
+
console.log('\n' + chalk.bold('♻️ Restoring from checkpoint...'));
|
|
2357
|
+
console.log(chalk.gray('Checkpoint data available for restoration'));
|
|
2358
|
+
}
|
|
2359
|
+
sessionManager.close();
|
|
2360
|
+
// Offer to spawn Claude Code with restored context
|
|
2361
|
+
if (flags.claude || flags.spawn) {
|
|
2362
|
+
console.log('\n' + chalk.yellow('🚀 Launching Claude Code with restored context...'));
|
|
2363
|
+
// Generate prompt with session context
|
|
2364
|
+
const restoredPrompt = generateRestoredSessionPrompt(resumedSession);
|
|
2365
|
+
// Launch Claude Code with restored context
|
|
2366
|
+
await launchClaudeWithContext(restoredPrompt, flags, sessionId);
|
|
2367
|
+
} else {
|
|
2368
|
+
console.log('\n' + chalk.blue('💡 Pro Tip:') + ' Add --claude to spawn Claude Code with restored context');
|
|
2369
|
+
console.log(chalk.gray(' claude-flow-novice hive-mind resume ' + sessionId + ' --claude'));
|
|
2370
|
+
}
|
|
2371
|
+
} catch (error) {
|
|
2372
|
+
spinner.fail('Failed to resume session');
|
|
2373
|
+
console.error(chalk.red('Error:'), error.message);
|
|
2374
|
+
exit(1);
|
|
2740
2375
|
}
|
|
2741
|
-
} catch (error) {
|
|
2742
|
-
spinner.fail('Failed to resume session');
|
|
2743
|
-
console.error(chalk.red('Error:'), error.message);
|
|
2744
|
-
exit(1);
|
|
2745
|
-
}
|
|
2746
2376
|
}
|
|
2747
|
-
|
|
2748
2377
|
/**
|
|
2749
2378
|
* Stop a hive mind session
|
|
2750
|
-
*/
|
|
2751
|
-
|
|
2752
|
-
|
|
2753
|
-
|
|
2754
|
-
|
|
2755
|
-
|
|
2756
|
-
|
|
2757
|
-
|
|
2758
|
-
|
|
2759
|
-
|
|
2760
|
-
|
|
2761
|
-
|
|
2762
|
-
|
|
2763
|
-
|
|
2764
|
-
|
|
2765
|
-
|
|
2766
|
-
|
|
2767
|
-
|
|
2768
|
-
|
|
2769
|
-
|
|
2770
|
-
|
|
2771
|
-
|
|
2772
|
-
|
|
2773
|
-
|
|
2379
|
+
*/ async function stopSession(args, flags) {
|
|
2380
|
+
const sessionId = args[0];
|
|
2381
|
+
if (!sessionId) {
|
|
2382
|
+
console.error(chalk.red('Error: Please provide a session ID'));
|
|
2383
|
+
console.log('Usage: claude-flow-novice hive-mind stop <session-id>');
|
|
2384
|
+
console.log('Run "claude-flow-novice hive-mind sessions" to see available sessions');
|
|
2385
|
+
return;
|
|
2386
|
+
}
|
|
2387
|
+
const spinner = ora('Stopping Hive Mind session...').start();
|
|
2388
|
+
try {
|
|
2389
|
+
const sessionManager = new HiveMindSessionManager();
|
|
2390
|
+
// Get session details
|
|
2391
|
+
const session = await sessionManager.getSession(sessionId);
|
|
2392
|
+
if (!session) {
|
|
2393
|
+
spinner.fail(`Session ${sessionId} not found`);
|
|
2394
|
+
console.log('\nRun "claude-flow-novice hive-mind sessions" to see available sessions');
|
|
2395
|
+
sessionManager.close();
|
|
2396
|
+
return;
|
|
2397
|
+
}
|
|
2398
|
+
// Stop the session
|
|
2399
|
+
await sessionManager.stopSession(sessionId);
|
|
2400
|
+
spinner.succeed('Session stopped successfully!');
|
|
2401
|
+
// Display session summary
|
|
2402
|
+
console.log('\n' + chalk.bold('🛑 Stopped Session Summary:'));
|
|
2403
|
+
console.log(chalk.gray('─'.repeat(50)));
|
|
2404
|
+
console.log(chalk.cyan('Session ID:'), sessionId);
|
|
2405
|
+
console.log(chalk.cyan('Swarm Name:'), session.swarm_name || 'Unknown');
|
|
2406
|
+
console.log(chalk.cyan('Final Status:'), 'Stopped');
|
|
2407
|
+
console.log(chalk.cyan('Active Agents:'), session.statistics ? session.statistics.activeAgents : 0);
|
|
2408
|
+
console.log(chalk.gray('─'.repeat(50)));
|
|
2409
|
+
console.log('\n' + chalk.yellow('💡 Session has been stopped and all processes cleaned up.'));
|
|
2410
|
+
console.log(chalk.gray('To resume this session later, use: claude-flow-novice hive-mind resume ' + sessionId));
|
|
2411
|
+
sessionManager.close();
|
|
2412
|
+
} catch (error) {
|
|
2413
|
+
spinner.fail('Failed to stop session');
|
|
2414
|
+
console.error(chalk.red('Error:'), error.message);
|
|
2415
|
+
exit(1);
|
|
2774
2416
|
}
|
|
2775
|
-
|
|
2776
|
-
// Stop the session
|
|
2777
|
-
await sessionManager.stopSession(sessionId);
|
|
2778
|
-
|
|
2779
|
-
spinner.succeed('Session stopped successfully!');
|
|
2780
|
-
|
|
2781
|
-
// Display session summary
|
|
2782
|
-
console.log('\n' + chalk.bold('🛑 Stopped Session Summary:'));
|
|
2783
|
-
console.log(chalk.gray('─'.repeat(50)));
|
|
2784
|
-
console.log(chalk.cyan('Session ID:'), sessionId);
|
|
2785
|
-
console.log(chalk.cyan('Swarm Name:'), session.swarm_name || 'Unknown');
|
|
2786
|
-
console.log(chalk.cyan('Final Status:'), 'Stopped');
|
|
2787
|
-
console.log(
|
|
2788
|
-
chalk.cyan('Active Agents:'),
|
|
2789
|
-
session.statistics ? session.statistics.activeAgents : 0,
|
|
2790
|
-
);
|
|
2791
|
-
console.log(chalk.gray('─'.repeat(50)));
|
|
2792
|
-
|
|
2793
|
-
console.log('\n' + chalk.yellow('💡 Session has been stopped and all processes cleaned up.'));
|
|
2794
|
-
console.log(
|
|
2795
|
-
chalk.gray('To resume this session later, use: claude-flow-novice hive-mind resume ' + sessionId),
|
|
2796
|
-
);
|
|
2797
|
-
|
|
2798
|
-
sessionManager.close();
|
|
2799
|
-
} catch (error) {
|
|
2800
|
-
spinner.fail('Failed to stop session');
|
|
2801
|
-
console.error(chalk.red('Error:'), error.message);
|
|
2802
|
-
exit(1);
|
|
2803
|
-
}
|
|
2804
2417
|
}
|
|
2805
|
-
|
|
2806
2418
|
/**
|
|
2807
2419
|
* Generate prompt for restored session
|
|
2808
|
-
*/
|
|
2809
|
-
|
|
2810
|
-
|
|
2811
|
-
|
|
2812
|
-
|
|
2813
|
-
|
|
2814
|
-
|
|
2815
|
-
|
|
2816
|
-
|
|
2817
|
-
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
|
|
2821
|
-
|
|
2822
|
-
|
|
2823
|
-
|
|
2824
|
-
|
|
2825
|
-
|
|
2826
|
-
|
|
2827
|
-
|
|
2828
|
-
|
|
2829
|
-
|
|
2830
|
-
|
|
2831
|
-
|
|
2832
|
-
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
|
|
2836
|
-
|
|
2837
|
-
|
|
2838
|
-
const
|
|
2839
|
-
return
|
|
2840
|
-
|
|
2841
|
-
|
|
2842
|
-
|
|
2843
|
-
|
|
2844
|
-
|
|
2845
|
-
|
|
2846
|
-
|
|
2847
|
-
|
|
2848
|
-
|
|
2849
|
-
|
|
2850
|
-
|
|
2851
|
-
|
|
2852
|
-
|
|
2853
|
-
|
|
2854
|
-
.
|
|
2855
|
-
|
|
2856
|
-
|
|
2857
|
-
|
|
2858
|
-
|
|
2859
|
-
|
|
2860
|
-
|
|
2861
|
-
const
|
|
2862
|
-
|
|
2863
|
-
|
|
2864
|
-
.join('\n');
|
|
2865
|
-
};
|
|
2866
|
-
|
|
2867
|
-
// Format activity logs with more detail
|
|
2868
|
-
const formatActivityLogs = (logs, limit = 20) => {
|
|
2869
|
-
if (!logs.length) return 'No activity logs found';
|
|
2870
|
-
const displayLogs = logs.slice(0, limit);
|
|
2871
|
-
return displayLogs
|
|
2872
|
-
.map((log) => {
|
|
2873
|
-
const timestamp = new Date(log.timestamp).toLocaleTimeString();
|
|
2874
|
-
const agent = log.agent_id ? allAgents.find((a) => a.id === log.agent_id) : null;
|
|
2875
|
-
return `[${timestamp}] ${log.message}${agent ? ` (by ${agent.name})` : ''}${log.data ? ` - ${JSON.stringify(log.data)}` : ''}`;
|
|
2876
|
-
})
|
|
2877
|
-
.join('\n');
|
|
2878
|
-
};
|
|
2879
|
-
|
|
2880
|
-
// Extract metadata if available
|
|
2881
|
-
const metadata = session.metadata || {};
|
|
2882
|
-
const metadataStr =
|
|
2883
|
-
Object.keys(metadata).length > 0
|
|
2884
|
-
? Object.entries(metadata)
|
|
2885
|
-
.map(([k, v]) => `• ${k}: ${typeof v === 'object' ? JSON.stringify(v) : v}`)
|
|
2886
|
-
.join('\n')
|
|
2887
|
-
: 'No metadata available';
|
|
2888
|
-
|
|
2889
|
-
return `🔄 RESUMING HIVE MIND SESSION
|
|
2420
|
+
*/ function generateRestoredSessionPrompt(session) {
|
|
2421
|
+
// Get all agents, not just active ones
|
|
2422
|
+
const allAgents = session.agents || [];
|
|
2423
|
+
const activeAgents = allAgents.filter((a)=>a.status === 'active' || a.status === 'busy');
|
|
2424
|
+
const idleAgents = allAgents.filter((a)=>a.status === 'idle');
|
|
2425
|
+
// Get all tasks categorized by status
|
|
2426
|
+
const allTasks = session.tasks || [];
|
|
2427
|
+
const completedTasks = allTasks.filter((t)=>t.status === 'completed');
|
|
2428
|
+
const inProgressTasks = allTasks.filter((t)=>t.status === 'in_progress');
|
|
2429
|
+
const pendingTasks = allTasks.filter((t)=>t.status === 'pending');
|
|
2430
|
+
// Calculate session duration
|
|
2431
|
+
const sessionStart = new Date(session.created_at);
|
|
2432
|
+
const sessionPaused = session.paused_at ? new Date(session.paused_at) : new Date();
|
|
2433
|
+
const duration = Math.round((sessionPaused - sessionStart) / 1000 / 60); // minutes
|
|
2434
|
+
// Get more checkpoint history
|
|
2435
|
+
const checkpointHistory = session.checkpoints || [];
|
|
2436
|
+
// Get more activity logs
|
|
2437
|
+
const activityLogs = session.recentLogs || [];
|
|
2438
|
+
// Format agent details with their current tasks
|
|
2439
|
+
const formatAgentDetails = (agents)=>{
|
|
2440
|
+
if (!agents.length) return 'No agents found';
|
|
2441
|
+
return agents.map((agent)=>{
|
|
2442
|
+
const agentTasks = allTasks.filter((t)=>t.agent_id === agent.id);
|
|
2443
|
+
const currentTask = agentTasks.find((t)=>t.status === 'in_progress');
|
|
2444
|
+
return `• ${agent.name} (${agent.type}) - ${agent.status}${currentTask ? `\n └─ Working on: ${currentTask.description}` : ''}`;
|
|
2445
|
+
}).join('\n');
|
|
2446
|
+
};
|
|
2447
|
+
// Format task details with more information
|
|
2448
|
+
const formatTaskDetails = (tasks, limit = 15)=>{
|
|
2449
|
+
if (!tasks.length) return 'No tasks found';
|
|
2450
|
+
const displayTasks = tasks.slice(0, limit);
|
|
2451
|
+
return displayTasks.map((task)=>{
|
|
2452
|
+
const agent = allAgents.find((a)=>a.id === task.agent_id);
|
|
2453
|
+
return `• [${task.priority?.toUpperCase() || 'NORMAL'}] ${task.description}${agent ? ` (Assigned to: ${agent.name})` : ''}${task.created_at ? ` - Created: ${new Date(task.created_at).toLocaleTimeString()}` : ''}`;
|
|
2454
|
+
}).join('\n') + (tasks.length > limit ? `\n... and ${tasks.length - limit} more tasks` : '');
|
|
2455
|
+
};
|
|
2456
|
+
// Format checkpoint details
|
|
2457
|
+
const formatCheckpoints = (checkpoints, limit = 5)=>{
|
|
2458
|
+
if (!checkpoints.length) return 'No checkpoints found';
|
|
2459
|
+
const displayCheckpoints = checkpoints.slice(0, limit);
|
|
2460
|
+
return displayCheckpoints.map((cp)=>`• ${cp.checkpoint_name} - ${new Date(cp.created_at).toLocaleString()}`).join('\n');
|
|
2461
|
+
};
|
|
2462
|
+
// Format activity logs with more detail
|
|
2463
|
+
const formatActivityLogs = (logs, limit = 20)=>{
|
|
2464
|
+
if (!logs.length) return 'No activity logs found';
|
|
2465
|
+
const displayLogs = logs.slice(0, limit);
|
|
2466
|
+
return displayLogs.map((log)=>{
|
|
2467
|
+
const timestamp = new Date(log.timestamp).toLocaleTimeString();
|
|
2468
|
+
const agent = log.agent_id ? allAgents.find((a)=>a.id === log.agent_id) : null;
|
|
2469
|
+
return `[${timestamp}] ${log.message}${agent ? ` (by ${agent.name})` : ''}${log.data ? ` - ${JSON.stringify(log.data)}` : ''}`;
|
|
2470
|
+
}).join('\n');
|
|
2471
|
+
};
|
|
2472
|
+
// Extract metadata if available
|
|
2473
|
+
const metadata = session.metadata || {};
|
|
2474
|
+
const metadataStr = Object.keys(metadata).length > 0 ? Object.entries(metadata).map(([k, v])=>`• ${k}: ${typeof v === 'object' ? JSON.stringify(v) : v}`).join('\n') : 'No metadata available';
|
|
2475
|
+
return `🔄 RESUMING HIVE MIND SESSION
|
|
2890
2476
|
═══════════════════════════════════
|
|
2891
2477
|
|
|
2892
2478
|
You are resuming a Hive Mind session with comprehensive context:
|
|
@@ -2907,7 +2493,7 @@ You are resuming a Hive Mind session with comprehensive context:
|
|
|
2907
2493
|
📊 TASK STATISTICS:
|
|
2908
2494
|
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
2909
2495
|
• Total Tasks: ${session.statistics.totalTasks}
|
|
2910
|
-
• Completed: ${completedTasks.length} (${session.statistics.totalTasks > 0 ? Math.round(
|
|
2496
|
+
• Completed: ${completedTasks.length} (${session.statistics.totalTasks > 0 ? Math.round(completedTasks.length / session.statistics.totalTasks * 100) : 0}%)
|
|
2911
2497
|
• In Progress: ${inProgressTasks.length}
|
|
2912
2498
|
• Pending: ${pendingTasks.length}
|
|
2913
2499
|
|
|
@@ -2974,139 +2560,112 @@ ${formatActivityLogs(activityLogs, 20)}
|
|
|
2974
2560
|
|
|
2975
2561
|
Resume the hive mind operation with full context awareness and continue working towards the objective.`;
|
|
2976
2562
|
}
|
|
2977
|
-
|
|
2978
2563
|
/**
|
|
2979
2564
|
* Launch Claude Code with context
|
|
2980
|
-
*/
|
|
2981
|
-
async function launchClaudeWithContext(prompt, flags, sessionId) {
|
|
2982
|
-
try {
|
|
2983
|
-
// ALWAYS save the prompt file first (fix for issue #330)
|
|
2984
|
-
// Ensure sessions directory exists
|
|
2985
|
-
const sessionsDir = path.join('.hive-mind', 'sessions');
|
|
2986
|
-
await mkdirAsync(sessionsDir, { recursive: true });
|
|
2987
|
-
const promptFile = path.join(sessionsDir, `hive-mind-resume-${sessionId}-${Date.now()}.txt`);
|
|
2988
|
-
await writeFile(promptFile, prompt);
|
|
2989
|
-
console.log(chalk.green(`\n✓ Session context saved to: ${promptFile}`));
|
|
2990
|
-
|
|
2991
|
-
const { spawn: childSpawn, execSync } = await import('child_process');
|
|
2992
|
-
let claudeAvailable = false;
|
|
2993
|
-
|
|
2565
|
+
*/ async function launchClaudeWithContext(prompt, flags, sessionId) {
|
|
2994
2566
|
try {
|
|
2995
|
-
|
|
2996
|
-
|
|
2997
|
-
|
|
2998
|
-
|
|
2999
|
-
|
|
3000
|
-
|
|
3001
|
-
|
|
3002
|
-
|
|
3003
|
-
|
|
3004
|
-
|
|
3005
|
-
|
|
3006
|
-
console.log(chalk.blue('\n🔍 Debug: About to spawn Claude Code process...'));
|
|
3007
|
-
console.log(chalk.gray(` Session ID: ${sessionId}`));
|
|
3008
|
-
console.log(chalk.gray(` Process ID: ${process.pid}`));
|
|
3009
|
-
|
|
3010
|
-
// Remove --print to allow interactive session (same as initial spawn)
|
|
3011
|
-
const claudeArgs = [prompt];
|
|
3012
|
-
|
|
3013
|
-
// Add --dangerously-skip-permissions by default for hive-mind operations
|
|
3014
|
-
// unless explicitly disabled with --no-auto-permissions
|
|
3015
|
-
if (!flags['no-auto-permissions']) {
|
|
3016
|
-
claudeArgs.push('--dangerously-skip-permissions');
|
|
3017
|
-
console.log(
|
|
3018
|
-
chalk.yellow(
|
|
3019
|
-
'🔓 Using --dangerously-skip-permissions by default for seamless hive-mind execution',
|
|
3020
|
-
),
|
|
3021
|
-
);
|
|
3022
|
-
}
|
|
3023
|
-
|
|
3024
|
-
console.log(
|
|
3025
|
-
chalk.blue('🔍 Debug: Spawning with args:'),
|
|
3026
|
-
claudeArgs.slice(0, 1).map((a) => a.substring(0, 50) + '...'),
|
|
3027
|
-
);
|
|
3028
|
-
|
|
3029
|
-
// Use 'inherit' for interactive session (same as initial spawn)
|
|
3030
|
-
const claudeProcess = childSpawn('claude', claudeArgs, {
|
|
3031
|
-
stdio: 'inherit',
|
|
3032
|
-
shell: false,
|
|
3033
|
-
});
|
|
3034
|
-
|
|
3035
|
-
console.log(chalk.blue('🔍 Debug: Claude process spawned with PID:'), claudeProcess.pid);
|
|
3036
|
-
|
|
3037
|
-
// Track child process PID in session (same as initial spawn)
|
|
3038
|
-
const sessionManager = new HiveMindSessionManager();
|
|
3039
|
-
if (claudeProcess.pid) {
|
|
3040
|
-
const sessions = await sessionManager.getActiveSessions();
|
|
3041
|
-
const currentSession = sessions.find((s) => s.id === sessionId);
|
|
3042
|
-
if (currentSession) {
|
|
3043
|
-
await sessionManager.addChildPid(currentSession.id, claudeProcess.pid);
|
|
3044
|
-
}
|
|
3045
|
-
}
|
|
3046
|
-
|
|
3047
|
-
// Set up SIGINT handler for automatic session pausing (same as initial spawn)
|
|
3048
|
-
let isExiting = false;
|
|
3049
|
-
const sigintHandler = async () => {
|
|
3050
|
-
if (isExiting) return;
|
|
3051
|
-
isExiting = true;
|
|
3052
|
-
|
|
3053
|
-
console.log('\n\n' + chalk.yellow('⏸️ Pausing session and terminating Claude Code...'));
|
|
3054
|
-
|
|
2567
|
+
// ALWAYS save the prompt file first (fix for issue #330)
|
|
2568
|
+
// Ensure sessions directory exists
|
|
2569
|
+
const sessionsDir = path.join('.hive-mind', 'sessions');
|
|
2570
|
+
await mkdirAsync(sessionsDir, {
|
|
2571
|
+
recursive: true
|
|
2572
|
+
});
|
|
2573
|
+
const promptFile = path.join(sessionsDir, `hive-mind-resume-${sessionId}-${Date.now()}.txt`);
|
|
2574
|
+
await writeFile(promptFile, prompt);
|
|
2575
|
+
console.log(chalk.green(`\n✓ Session context saved to: ${promptFile}`));
|
|
2576
|
+
const { spawn: childSpawn, execSync } = await import("child_process");
|
|
2577
|
+
let claudeAvailable = false;
|
|
3055
2578
|
try {
|
|
3056
|
-
|
|
3057
|
-
|
|
3058
|
-
|
|
3059
|
-
|
|
3060
|
-
|
|
3061
|
-
|
|
3062
|
-
|
|
3063
|
-
|
|
3064
|
-
|
|
3065
|
-
console.log(chalk.cyan('\nTo resume this session, run:'));
|
|
3066
|
-
console.log(chalk.bold(` claude-flow-novice hive-mind resume ${sessionId}`));
|
|
3067
|
-
console.log();
|
|
3068
|
-
|
|
3069
|
-
process.exit(0);
|
|
3070
|
-
} catch (error) {
|
|
3071
|
-
console.error(chalk.red('Error during shutdown:'), error.message);
|
|
3072
|
-
process.exit(1);
|
|
2579
|
+
execSync('which claude', {
|
|
2580
|
+
stdio: 'ignore'
|
|
2581
|
+
});
|
|
2582
|
+
claudeAvailable = true;
|
|
2583
|
+
} catch {
|
|
2584
|
+
console.log(chalk.yellow('\n⚠️ Claude Code CLI not found'));
|
|
2585
|
+
console.log(chalk.gray('Install Claude Code: npm install -g @anthropic-ai/claude-code'));
|
|
2586
|
+
console.log(chalk.gray(`Run with: claude < ${promptFile}`));
|
|
2587
|
+
return;
|
|
3073
2588
|
}
|
|
3074
|
-
|
|
3075
|
-
|
|
3076
|
-
|
|
3077
|
-
|
|
3078
|
-
|
|
3079
|
-
|
|
3080
|
-
|
|
3081
|
-
|
|
3082
|
-
|
|
3083
|
-
|
|
3084
|
-
|
|
3085
|
-
|
|
3086
|
-
|
|
3087
|
-
|
|
3088
|
-
|
|
3089
|
-
|
|
3090
|
-
|
|
3091
|
-
|
|
2589
|
+
if (claudeAvailable && !flags.dryRun) {
|
|
2590
|
+
// Debug logging to track spawn calls
|
|
2591
|
+
console.log(chalk.blue('\n🔍 Debug: About to spawn Claude Code process...'));
|
|
2592
|
+
console.log(chalk.gray(` Session ID: ${sessionId}`));
|
|
2593
|
+
console.log(chalk.gray(` Process ID: ${process.pid}`));
|
|
2594
|
+
// Remove --print to allow interactive session (same as initial spawn)
|
|
2595
|
+
const claudeArgs = [
|
|
2596
|
+
prompt
|
|
2597
|
+
];
|
|
2598
|
+
// Add --dangerously-skip-permissions by default for hive-mind operations
|
|
2599
|
+
// unless explicitly disabled with --no-auto-permissions
|
|
2600
|
+
if (!flags['no-auto-permissions']) {
|
|
2601
|
+
claudeArgs.push('--dangerously-skip-permissions');
|
|
2602
|
+
console.log(chalk.yellow('🔓 Using --dangerously-skip-permissions by default for seamless hive-mind execution'));
|
|
2603
|
+
}
|
|
2604
|
+
console.log(chalk.blue('🔍 Debug: Spawning with args:'), claudeArgs.slice(0, 1).map((a)=>a.substring(0, 50) + '...'));
|
|
2605
|
+
// Use 'inherit' for interactive session (same as initial spawn)
|
|
2606
|
+
const claudeProcess = childSpawn('claude', claudeArgs, {
|
|
2607
|
+
stdio: 'inherit',
|
|
2608
|
+
shell: false
|
|
2609
|
+
});
|
|
2610
|
+
console.log(chalk.blue('🔍 Debug: Claude process spawned with PID:'), claudeProcess.pid);
|
|
2611
|
+
// Track child process PID in session (same as initial spawn)
|
|
2612
|
+
const sessionManager = new HiveMindSessionManager();
|
|
2613
|
+
if (claudeProcess.pid) {
|
|
2614
|
+
const sessions = await sessionManager.getActiveSessions();
|
|
2615
|
+
const currentSession = sessions.find((s)=>s.id === sessionId);
|
|
2616
|
+
if (currentSession) {
|
|
2617
|
+
await sessionManager.addChildPid(currentSession.id, claudeProcess.pid);
|
|
2618
|
+
}
|
|
2619
|
+
}
|
|
2620
|
+
// Set up SIGINT handler for automatic session pausing (same as initial spawn)
|
|
2621
|
+
let isExiting = false;
|
|
2622
|
+
const sigintHandler = async ()=>{
|
|
2623
|
+
if (isExiting) return;
|
|
2624
|
+
isExiting = true;
|
|
2625
|
+
console.log('\n\n' + chalk.yellow('⏸️ Pausing session and terminating Claude Code...'));
|
|
2626
|
+
try {
|
|
2627
|
+
// Terminate Claude Code process if still running
|
|
2628
|
+
if (claudeProcess && !claudeProcess.killed) {
|
|
2629
|
+
claudeProcess.kill('SIGTERM');
|
|
2630
|
+
}
|
|
2631
|
+
// Clean up and close session manager
|
|
2632
|
+
sessionManager.close();
|
|
2633
|
+
console.log(chalk.green('✓') + ' Session paused successfully');
|
|
2634
|
+
console.log(chalk.cyan('\nTo resume this session, run:'));
|
|
2635
|
+
console.log(chalk.bold(` claude-flow-novice hive-mind resume ${sessionId}`));
|
|
2636
|
+
console.log();
|
|
2637
|
+
process.exit(0);
|
|
2638
|
+
} catch (error) {
|
|
2639
|
+
console.error(chalk.red('Error during shutdown:'), error.message);
|
|
2640
|
+
process.exit(1);
|
|
2641
|
+
}
|
|
2642
|
+
};
|
|
2643
|
+
process.on('SIGINT', sigintHandler);
|
|
2644
|
+
process.on('SIGTERM', sigintHandler);
|
|
2645
|
+
// Handle process exit (same as initial spawn)
|
|
2646
|
+
claudeProcess.on('exit', async (code, signal)=>{
|
|
2647
|
+
if (!isExiting) {
|
|
2648
|
+
console.log('\n' + chalk.yellow('Claude Code has exited'));
|
|
2649
|
+
// Clean up signal handlers
|
|
2650
|
+
process.removeListener('SIGINT', sigintHandler);
|
|
2651
|
+
process.removeListener('SIGTERM', sigintHandler);
|
|
2652
|
+
// Close session manager
|
|
2653
|
+
sessionManager.close();
|
|
2654
|
+
process.exit(code || 0);
|
|
2655
|
+
}
|
|
2656
|
+
});
|
|
2657
|
+
console.log(chalk.green('\n✓ Claude Code launched with restored session context'));
|
|
2658
|
+
console.log(chalk.gray(` Prompt file saved at: ${promptFile}`));
|
|
3092
2659
|
}
|
|
3093
|
-
|
|
3094
|
-
|
|
3095
|
-
console.log(chalk.green('\n✓ Claude Code launched with restored session context'));
|
|
3096
|
-
console.log(chalk.gray(` Prompt file saved at: ${promptFile}`));
|
|
2660
|
+
} catch (error) {
|
|
2661
|
+
console.error(chalk.red('Failed to launch Claude Code:'), error.message);
|
|
3097
2662
|
}
|
|
3098
|
-
} catch (error) {
|
|
3099
|
-
console.error(chalk.red('Failed to launch Claude Code:'), error.message);
|
|
3100
|
-
}
|
|
3101
2663
|
}
|
|
3102
|
-
|
|
3103
2664
|
/**
|
|
3104
2665
|
* Get MCP wrapper instance
|
|
3105
|
-
*/
|
|
3106
|
-
|
|
3107
|
-
|
|
3108
|
-
return new MCPToolWrapper();
|
|
2666
|
+
*/ async function getMcpWrapper() {
|
|
2667
|
+
const { MCPToolWrapper } = await import("./hive-mind/mcp-wrapper.js");
|
|
2668
|
+
return new MCPToolWrapper();
|
|
3109
2669
|
}
|
|
3110
|
-
|
|
3111
2670
|
// Export for testing
|
|
3112
2671
|
export { showHiveMindHelp, initHiveMind, spawnSwarm, showStatus };
|