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,809 +1,768 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Queen Coordinator for Hive Mind System
|
|
3
3
|
* Strategic decision-making and swarm coordination
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import EventEmitter from 'events';
|
|
7
|
-
|
|
4
|
+
*/ import EventEmitter from "events";
|
|
8
5
|
/**
|
|
9
6
|
* Queen types and their characteristics
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
7
|
+
*/ const QUEEN_TYPES = {
|
|
8
|
+
strategic: {
|
|
9
|
+
name: 'Strategic Queen',
|
|
10
|
+
traits: [
|
|
11
|
+
'long-term planning',
|
|
12
|
+
'resource optimization',
|
|
13
|
+
'goal alignment'
|
|
14
|
+
],
|
|
15
|
+
decisionWeight: 3,
|
|
16
|
+
consensusThreshold: 0.6
|
|
17
|
+
},
|
|
18
|
+
tactical: {
|
|
19
|
+
name: 'Tactical Queen',
|
|
20
|
+
traits: [
|
|
21
|
+
'task prioritization',
|
|
22
|
+
'workflow optimization',
|
|
23
|
+
'rapid response'
|
|
24
|
+
],
|
|
25
|
+
decisionWeight: 2,
|
|
26
|
+
consensusThreshold: 0.5
|
|
27
|
+
},
|
|
28
|
+
adaptive: {
|
|
29
|
+
name: 'Adaptive Queen',
|
|
30
|
+
traits: [
|
|
31
|
+
'learning',
|
|
32
|
+
'pattern recognition',
|
|
33
|
+
'strategy evolution'
|
|
34
|
+
],
|
|
35
|
+
decisionWeight: 2.5,
|
|
36
|
+
consensusThreshold: 0.55
|
|
37
|
+
}
|
|
30
38
|
};
|
|
31
|
-
|
|
32
39
|
/**
|
|
33
40
|
* QueenCoordinator class
|
|
34
|
-
*/
|
|
35
|
-
|
|
36
|
-
constructor(config = {}) {
|
|
37
|
-
super();
|
|
38
|
-
|
|
39
|
-
this.config = {
|
|
40
|
-
swarmId: config.swarmId,
|
|
41
|
-
type: config.type || 'strategic',
|
|
42
|
-
objective: config.objective || '',
|
|
43
|
-
...QUEEN_TYPES[config.type || 'strategic'],
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
this.state = {
|
|
47
|
-
status: 'initializing',
|
|
48
|
-
decisionsCount: 0,
|
|
49
|
-
strategiesExecuted: 0,
|
|
50
|
-
learningData: new Map(),
|
|
51
|
-
currentStrategy: null,
|
|
52
|
-
taskQueue: [],
|
|
53
|
-
workerAssignments: new Map(),
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
this.strategies = {
|
|
57
|
-
divide_and_conquer: this._divideAndConquerStrategy.bind(this),
|
|
58
|
-
parallel_execution: this._parallelExecutionStrategy.bind(this),
|
|
59
|
-
sequential_refinement: this._sequentialRefinementStrategy.bind(this),
|
|
60
|
-
consensus_driven: this._consensusDrivenStrategy.bind(this),
|
|
61
|
-
adaptive_learning: this._adaptiveLearningStrategy.bind(this),
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
this._initialize();
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
41
|
+
*/ export class QueenCoordinator extends EventEmitter {
|
|
42
|
+
/**
|
|
68
43
|
* Initialize queen coordinator
|
|
69
|
-
*/
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
/**
|
|
44
|
+
*/ _initialize() {
|
|
45
|
+
this.state.status = 'active';
|
|
46
|
+
this.emit('queen:initialized', {
|
|
47
|
+
type: this.config.type,
|
|
48
|
+
traits: this.config.traits
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
79
52
|
* Analyze objective and create strategic plan
|
|
80
|
-
*/
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
return analysis;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/**
|
|
53
|
+
*/ async analyzeObjective(objective) {
|
|
54
|
+
const analysis = {
|
|
55
|
+
objective,
|
|
56
|
+
complexity: this._assessComplexity(objective),
|
|
57
|
+
requiredCapabilities: this._identifyRequiredCapabilities(objective),
|
|
58
|
+
estimatedTasks: this._estimateTaskCount(objective),
|
|
59
|
+
recommendedStrategy: this._selectStrategy(objective),
|
|
60
|
+
resourceRequirements: this._estimateResources(objective)
|
|
61
|
+
};
|
|
62
|
+
// Store analysis for learning
|
|
63
|
+
this.state.learningData.set('objective_analysis', analysis);
|
|
64
|
+
this.emit('objective:analyzed', analysis);
|
|
65
|
+
return analysis;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
99
68
|
* Assess complexity of objective
|
|
100
|
-
*/
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
return 'very_high';
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/**
|
|
69
|
+
*/ _assessComplexity(objective) {
|
|
70
|
+
const complexityFactors = {
|
|
71
|
+
length: objective.length > 100 ? 2 : 1,
|
|
72
|
+
keywords: this._countComplexityKeywords(objective),
|
|
73
|
+
components: this._identifyComponents(objective).length
|
|
74
|
+
};
|
|
75
|
+
const score = Object.values(complexityFactors).reduce((a, b)=>a + b, 0);
|
|
76
|
+
if (score <= 3) return 'low';
|
|
77
|
+
if (score <= 6) return 'medium';
|
|
78
|
+
if (score <= 9) return 'high';
|
|
79
|
+
return 'very_high';
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
117
82
|
* Count complexity keywords
|
|
118
|
-
*/
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
/**
|
|
83
|
+
*/ _countComplexityKeywords(text) {
|
|
84
|
+
const complexKeywords = [
|
|
85
|
+
'complex',
|
|
86
|
+
'advanced',
|
|
87
|
+
'enterprise',
|
|
88
|
+
'distributed',
|
|
89
|
+
'scalable',
|
|
90
|
+
'microservices',
|
|
91
|
+
'architecture',
|
|
92
|
+
'integration',
|
|
93
|
+
'optimization',
|
|
94
|
+
'security',
|
|
95
|
+
'performance',
|
|
96
|
+
'concurrent',
|
|
97
|
+
'real-time'
|
|
98
|
+
];
|
|
99
|
+
const lowerText = text.toLowerCase();
|
|
100
|
+
return complexKeywords.filter((keyword)=>lowerText.includes(keyword)).length;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
141
103
|
* Identify components in objective
|
|
142
|
-
*/
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
104
|
+
*/ _identifyComponents(objective) {
|
|
105
|
+
const components = [];
|
|
106
|
+
const componentKeywords = {
|
|
107
|
+
backend: [
|
|
108
|
+
'api',
|
|
109
|
+
'server',
|
|
110
|
+
'backend',
|
|
111
|
+
'database',
|
|
112
|
+
'service'
|
|
113
|
+
],
|
|
114
|
+
frontend: [
|
|
115
|
+
'ui',
|
|
116
|
+
'frontend',
|
|
117
|
+
'interface',
|
|
118
|
+
'client',
|
|
119
|
+
'web'
|
|
120
|
+
],
|
|
121
|
+
data: [
|
|
122
|
+
'database',
|
|
123
|
+
'data',
|
|
124
|
+
'storage',
|
|
125
|
+
'cache',
|
|
126
|
+
'persistence'
|
|
127
|
+
],
|
|
128
|
+
auth: [
|
|
129
|
+
'auth',
|
|
130
|
+
'security',
|
|
131
|
+
'login',
|
|
132
|
+
'permission',
|
|
133
|
+
'access'
|
|
134
|
+
],
|
|
135
|
+
testing: [
|
|
136
|
+
'test',
|
|
137
|
+
'quality',
|
|
138
|
+
'validation',
|
|
139
|
+
'verify'
|
|
140
|
+
],
|
|
141
|
+
deployment: [
|
|
142
|
+
'deploy',
|
|
143
|
+
'ci/cd',
|
|
144
|
+
'docker',
|
|
145
|
+
'kubernetes'
|
|
146
|
+
],
|
|
147
|
+
monitoring: [
|
|
148
|
+
'monitor',
|
|
149
|
+
'logging',
|
|
150
|
+
'metrics',
|
|
151
|
+
'observability'
|
|
152
|
+
]
|
|
153
|
+
};
|
|
154
|
+
const lowerObjective = objective.toLowerCase();
|
|
155
|
+
Object.entries(componentKeywords).forEach(([component, keywords])=>{
|
|
156
|
+
if (keywords.some((keyword)=>lowerObjective.includes(keyword))) {
|
|
157
|
+
components.push(component);
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
return components;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
167
163
|
* Identify required capabilities
|
|
168
|
-
*/
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
164
|
+
*/ _identifyRequiredCapabilities(objective) {
|
|
165
|
+
const capabilities = new Set();
|
|
166
|
+
const components = this._identifyComponents(objective);
|
|
167
|
+
// Map components to capabilities
|
|
168
|
+
const capabilityMap = {
|
|
169
|
+
backend: [
|
|
170
|
+
'coder',
|
|
171
|
+
'architect',
|
|
172
|
+
'tester'
|
|
173
|
+
],
|
|
174
|
+
frontend: [
|
|
175
|
+
'coder',
|
|
176
|
+
'tester',
|
|
177
|
+
'reviewer'
|
|
178
|
+
],
|
|
179
|
+
data: [
|
|
180
|
+
'architect',
|
|
181
|
+
'analyst',
|
|
182
|
+
'optimizer'
|
|
183
|
+
],
|
|
184
|
+
auth: [
|
|
185
|
+
'architect',
|
|
186
|
+
'coder',
|
|
187
|
+
'tester'
|
|
188
|
+
],
|
|
189
|
+
testing: [
|
|
190
|
+
'tester',
|
|
191
|
+
'reviewer'
|
|
192
|
+
],
|
|
193
|
+
deployment: [
|
|
194
|
+
'architect',
|
|
195
|
+
'optimizer'
|
|
196
|
+
],
|
|
197
|
+
monitoring: [
|
|
198
|
+
'analyst',
|
|
199
|
+
'optimizer'
|
|
200
|
+
]
|
|
201
|
+
};
|
|
202
|
+
components.forEach((component)=>{
|
|
203
|
+
const caps = capabilityMap[component] || [];
|
|
204
|
+
caps.forEach((cap)=>capabilities.add(cap));
|
|
205
|
+
});
|
|
206
|
+
// Always include researcher for initial analysis
|
|
207
|
+
capabilities.add('researcher');
|
|
208
|
+
return Array.from(capabilities);
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
196
211
|
* Estimate number of tasks
|
|
197
|
-
*/
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
return baseTaskCount[complexity] + components * 3;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
/**
|
|
212
|
+
*/ _estimateTaskCount(objective) {
|
|
213
|
+
const complexity = this._assessComplexity(objective);
|
|
214
|
+
const components = this._identifyComponents(objective).length;
|
|
215
|
+
const baseTaskCount = {
|
|
216
|
+
low: 5,
|
|
217
|
+
medium: 10,
|
|
218
|
+
high: 20,
|
|
219
|
+
very_high: 30
|
|
220
|
+
};
|
|
221
|
+
return baseTaskCount[complexity] + components * 3;
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
213
224
|
* Select optimal strategy
|
|
214
|
-
*/
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
if (this.config.type === 'adaptive') {
|
|
236
|
-
return 'adaptive_learning';
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
return 'consensus_driven'; // Default
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
/**
|
|
225
|
+
*/ _selectStrategy(objective) {
|
|
226
|
+
const complexity = this._assessComplexity(objective);
|
|
227
|
+
const components = this._identifyComponents(objective);
|
|
228
|
+
// Strategy selection heuristics
|
|
229
|
+
if (components.length > 3 && complexity !== 'low') {
|
|
230
|
+
return 'divide_and_conquer';
|
|
231
|
+
}
|
|
232
|
+
if (objective.toLowerCase().includes('parallel') || components.length > 5) {
|
|
233
|
+
return 'parallel_execution';
|
|
234
|
+
}
|
|
235
|
+
if (objective.toLowerCase().includes('iterative') || objective.toLowerCase().includes('refine')) {
|
|
236
|
+
return 'sequential_refinement';
|
|
237
|
+
}
|
|
238
|
+
if (this.config.type === 'adaptive') {
|
|
239
|
+
return 'adaptive_learning';
|
|
240
|
+
}
|
|
241
|
+
return 'consensus_driven'; // Default
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
243
244
|
* Estimate resource requirements
|
|
244
|
-
*/
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
/**
|
|
245
|
+
*/ _estimateResources(objective) {
|
|
246
|
+
const complexity = this._assessComplexity(objective);
|
|
247
|
+
const taskCount = this._estimateTaskCount(objective);
|
|
248
|
+
return {
|
|
249
|
+
minWorkers: Math.min(3, Math.ceil(taskCount / 10)),
|
|
250
|
+
optimalWorkers: Math.min(8, Math.ceil(taskCount / 5)),
|
|
251
|
+
estimatedTime: taskCount * 5,
|
|
252
|
+
memoryRequirement: complexity === 'very_high' ? 'high' : 'medium'
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
258
256
|
* Create execution plan
|
|
259
|
-
*/
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
this.emit('plan:created', plan);
|
|
272
|
-
return plan;
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
/**
|
|
257
|
+
*/ async createExecutionPlan(analysis, workers) {
|
|
258
|
+
const strategy = this.strategies[analysis.recommendedStrategy];
|
|
259
|
+
if (!strategy) {
|
|
260
|
+
throw new Error(`Unknown strategy: ${analysis.recommendedStrategy}`);
|
|
261
|
+
}
|
|
262
|
+
const plan = await strategy(analysis, workers);
|
|
263
|
+
this.state.currentStrategy = analysis.recommendedStrategy;
|
|
264
|
+
this.state.strategiesExecuted++;
|
|
265
|
+
this.emit('plan:created', plan);
|
|
266
|
+
return plan;
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
276
269
|
* Divide and conquer strategy
|
|
277
|
-
*/
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
270
|
+
*/ async _divideAndConquerStrategy(analysis, workers) {
|
|
271
|
+
const components = this._identifyComponents(analysis.objective);
|
|
272
|
+
const phases = [];
|
|
273
|
+
// Phase 1: Research and planning
|
|
274
|
+
phases.push({
|
|
275
|
+
name: 'Research and Planning',
|
|
276
|
+
tasks: [
|
|
277
|
+
'Research best practices and patterns',
|
|
278
|
+
'Analyze requirements and constraints',
|
|
279
|
+
'Create high-level architecture design'
|
|
280
|
+
],
|
|
281
|
+
workers: workers.filter((w)=>[
|
|
282
|
+
'researcher',
|
|
283
|
+
'architect'
|
|
284
|
+
].includes(w.type)),
|
|
285
|
+
parallel: true
|
|
286
|
+
});
|
|
287
|
+
// Phase 2: Component development
|
|
288
|
+
components.forEach((component)=>{
|
|
289
|
+
phases.push({
|
|
290
|
+
name: `Develop ${component}`,
|
|
291
|
+
tasks: this._generateComponentTasks(component),
|
|
292
|
+
workers: workers.filter((w)=>[
|
|
293
|
+
'coder',
|
|
294
|
+
'architect'
|
|
295
|
+
].includes(w.type)),
|
|
296
|
+
parallel: true
|
|
297
|
+
});
|
|
298
|
+
});
|
|
299
|
+
// Phase 3: Integration and testing
|
|
300
|
+
phases.push({
|
|
301
|
+
name: 'Integration and Testing',
|
|
302
|
+
tasks: [
|
|
303
|
+
'Integrate components',
|
|
304
|
+
'Write integration tests',
|
|
305
|
+
'Perform end-to-end testing',
|
|
306
|
+
'Fix integration issues'
|
|
307
|
+
],
|
|
308
|
+
workers: workers.filter((w)=>[
|
|
309
|
+
'coder',
|
|
310
|
+
'tester'
|
|
311
|
+
].includes(w.type)),
|
|
312
|
+
parallel: false
|
|
313
|
+
});
|
|
314
|
+
// Phase 4: Optimization and documentation
|
|
315
|
+
phases.push({
|
|
316
|
+
name: 'Optimization and Documentation',
|
|
317
|
+
tasks: [
|
|
318
|
+
'Optimize performance',
|
|
319
|
+
'Document architecture',
|
|
320
|
+
'Create user documentation',
|
|
321
|
+
'Prepare deployment guide'
|
|
322
|
+
],
|
|
323
|
+
workers: workers.filter((w)=>[
|
|
324
|
+
'optimizer',
|
|
325
|
+
'documenter'
|
|
326
|
+
].includes(w.type)),
|
|
327
|
+
parallel: true
|
|
328
|
+
});
|
|
329
|
+
return {
|
|
330
|
+
strategy: 'divide_and_conquer',
|
|
331
|
+
phases,
|
|
332
|
+
estimatedDuration: phases.length * 15,
|
|
333
|
+
parallelism: 'high'
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
339
337
|
* Parallel execution strategy
|
|
340
|
-
*/
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
/**
|
|
338
|
+
*/ async _parallelExecutionStrategy(analysis, workers) {
|
|
339
|
+
const tasks = this._generateAllTasks(analysis);
|
|
340
|
+
const workerGroups = this._groupWorkersByType(workers);
|
|
341
|
+
return {
|
|
342
|
+
strategy: 'parallel_execution',
|
|
343
|
+
phases: [
|
|
344
|
+
{
|
|
345
|
+
name: 'Parallel Execution',
|
|
346
|
+
tasks: tasks,
|
|
347
|
+
workers: workers,
|
|
348
|
+
parallel: true,
|
|
349
|
+
workerAssignment: this._optimizeWorkerAssignment(tasks, workerGroups)
|
|
350
|
+
}
|
|
351
|
+
],
|
|
352
|
+
estimatedDuration: Math.ceil(tasks.length / workers.length) * 10,
|
|
353
|
+
parallelism: 'maximum'
|
|
354
|
+
};
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
362
357
|
* Sequential refinement strategy
|
|
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
|
-
/**
|
|
358
|
+
*/ async _sequentialRefinementStrategy(analysis, workers) {
|
|
359
|
+
const iterations = 3;
|
|
360
|
+
const phases = [];
|
|
361
|
+
for(let i = 0; i < iterations; i++){
|
|
362
|
+
phases.push({
|
|
363
|
+
name: `Iteration ${i + 1}`,
|
|
364
|
+
tasks: [
|
|
365
|
+
`Design iteration ${i + 1}`,
|
|
366
|
+
`Implement features for iteration ${i + 1}`,
|
|
367
|
+
`Test iteration ${i + 1}`,
|
|
368
|
+
`Review and refine iteration ${i + 1}`
|
|
369
|
+
],
|
|
370
|
+
workers: workers,
|
|
371
|
+
parallel: false,
|
|
372
|
+
requiresConsensus: true
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
return {
|
|
376
|
+
strategy: 'sequential_refinement',
|
|
377
|
+
phases,
|
|
378
|
+
estimatedDuration: phases.length * 20,
|
|
379
|
+
parallelism: 'low',
|
|
380
|
+
iterative: true
|
|
381
|
+
};
|
|
382
|
+
}
|
|
383
|
+
/**
|
|
393
384
|
* Consensus-driven strategy
|
|
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
|
-
|
|
421
|
-
};
|
|
422
|
-
}
|
|
423
|
-
|
|
424
|
-
/**
|
|
385
|
+
*/ async _consensusDrivenStrategy(analysis, workers) {
|
|
386
|
+
const decisionPoints = this._identifyDecisionPoints(analysis);
|
|
387
|
+
const phases = [];
|
|
388
|
+
decisionPoints.forEach((decision, index)=>{
|
|
389
|
+
phases.push({
|
|
390
|
+
name: `Decision Phase ${index + 1}: ${decision}`,
|
|
391
|
+
tasks: [
|
|
392
|
+
`Research options for ${decision}`,
|
|
393
|
+
`Analyze trade-offs`,
|
|
394
|
+
`Build consensus on approach`,
|
|
395
|
+
`Implement chosen solution`
|
|
396
|
+
],
|
|
397
|
+
workers: workers,
|
|
398
|
+
parallel: index === 0,
|
|
399
|
+
requiresConsensus: true,
|
|
400
|
+
consensusThreshold: this.config.consensusThreshold
|
|
401
|
+
});
|
|
402
|
+
});
|
|
403
|
+
return {
|
|
404
|
+
strategy: 'consensus_driven',
|
|
405
|
+
phases,
|
|
406
|
+
estimatedDuration: phases.length * 25,
|
|
407
|
+
parallelism: 'medium',
|
|
408
|
+
consensusRequired: true
|
|
409
|
+
};
|
|
410
|
+
}
|
|
411
|
+
/**
|
|
425
412
|
* Adaptive learning strategy
|
|
426
|
-
*/
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
'Implement business logic',
|
|
473
|
-
'Set up database models',
|
|
474
|
-
'Create API tests',
|
|
475
|
-
],
|
|
476
|
-
frontend: [
|
|
477
|
-
'Design UI components',
|
|
478
|
-
'Implement user interface',
|
|
479
|
-
'Add interactivity',
|
|
480
|
-
'Create UI tests',
|
|
481
|
-
],
|
|
482
|
-
data: [
|
|
483
|
-
'Design data schema',
|
|
484
|
-
'Implement data access layer',
|
|
485
|
-
'Set up caching',
|
|
486
|
-
'Optimize queries',
|
|
487
|
-
],
|
|
488
|
-
auth: [
|
|
489
|
-
'Design authentication flow',
|
|
490
|
-
'Implement auth middleware',
|
|
491
|
-
'Add authorization checks',
|
|
492
|
-
'Test security',
|
|
493
|
-
],
|
|
494
|
-
};
|
|
495
|
-
|
|
496
|
-
return (
|
|
497
|
-
taskTemplates[component] || [
|
|
498
|
-
`Design ${component}`,
|
|
499
|
-
`Implement ${component}`,
|
|
500
|
-
`Test ${component}`,
|
|
501
|
-
]
|
|
502
|
-
);
|
|
503
|
-
}
|
|
504
|
-
|
|
505
|
-
/**
|
|
506
|
-
* Generate all tasks based on analysis
|
|
507
|
-
*/
|
|
508
|
-
_generateAllTasks(analysis) {
|
|
509
|
-
const tasks = [];
|
|
510
|
-
const components = this._identifyComponents(analysis.objective);
|
|
511
|
-
|
|
512
|
-
// Add general tasks
|
|
513
|
-
tasks.push('Analyze requirements', 'Design architecture', 'Set up project structure');
|
|
514
|
-
|
|
515
|
-
// Add component tasks
|
|
516
|
-
components.forEach((component) => {
|
|
517
|
-
tasks.push(...this._generateComponentTasks(component));
|
|
518
|
-
});
|
|
519
|
-
|
|
520
|
-
// Add integration tasks
|
|
521
|
-
tasks.push('Integrate components', 'Write tests', 'Document solution');
|
|
522
|
-
|
|
523
|
-
return tasks;
|
|
524
|
-
}
|
|
525
|
-
|
|
526
|
-
/**
|
|
527
|
-
* Group workers by type
|
|
528
|
-
*/
|
|
529
|
-
_groupWorkersByType(workers) {
|
|
530
|
-
const groups = {};
|
|
531
|
-
|
|
532
|
-
workers.forEach((worker) => {
|
|
533
|
-
if (!groups[worker.type]) {
|
|
534
|
-
groups[worker.type] = [];
|
|
535
|
-
}
|
|
536
|
-
groups[worker.type].push(worker);
|
|
537
|
-
});
|
|
538
|
-
|
|
539
|
-
return groups;
|
|
540
|
-
}
|
|
541
|
-
|
|
542
|
-
/**
|
|
543
|
-
* Optimize worker assignment for tasks
|
|
544
|
-
*/
|
|
545
|
-
_optimizeWorkerAssignment(tasks, workerGroups) {
|
|
546
|
-
const assignments = {};
|
|
547
|
-
|
|
548
|
-
tasks.forEach((task) => {
|
|
549
|
-
const bestWorkerType = this._findBestWorkerType(task);
|
|
550
|
-
const availableWorkers = workerGroups[bestWorkerType] || [];
|
|
551
|
-
|
|
552
|
-
if (availableWorkers.length > 0) {
|
|
553
|
-
// Round-robin assignment within type
|
|
554
|
-
const workerIndex =
|
|
555
|
-
Object.keys(assignments).filter((t) => assignments[t].type === bestWorkerType).length %
|
|
556
|
-
availableWorkers.length;
|
|
557
|
-
|
|
558
|
-
assignments[task] = availableWorkers[workerIndex];
|
|
559
|
-
}
|
|
560
|
-
});
|
|
561
|
-
|
|
562
|
-
return assignments;
|
|
563
|
-
}
|
|
564
|
-
|
|
565
|
-
/**
|
|
566
|
-
* Find best worker type for task
|
|
567
|
-
*/
|
|
568
|
-
_findBestWorkerType(task) {
|
|
569
|
-
const taskLower = task.toLowerCase();
|
|
570
|
-
|
|
571
|
-
if (taskLower.includes('research') || taskLower.includes('analyze')) {
|
|
572
|
-
return 'researcher';
|
|
413
|
+
*/ async _adaptiveLearningStrategy(analysis, workers) {
|
|
414
|
+
const learningPhases = [
|
|
415
|
+
{
|
|
416
|
+
name: 'Exploration Phase',
|
|
417
|
+
tasks: [
|
|
418
|
+
'Explore multiple approaches',
|
|
419
|
+
'Experiment with different solutions',
|
|
420
|
+
'Collect performance metrics'
|
|
421
|
+
],
|
|
422
|
+
workers: workers,
|
|
423
|
+
parallel: true,
|
|
424
|
+
learning: true
|
|
425
|
+
},
|
|
426
|
+
{
|
|
427
|
+
name: 'Analysis Phase',
|
|
428
|
+
tasks: [
|
|
429
|
+
'Analyze results',
|
|
430
|
+
'Identify patterns',
|
|
431
|
+
'Select best approaches'
|
|
432
|
+
],
|
|
433
|
+
workers: workers.filter((w)=>[
|
|
434
|
+
'analyst',
|
|
435
|
+
'researcher'
|
|
436
|
+
].includes(w.type)),
|
|
437
|
+
parallel: false,
|
|
438
|
+
learning: true
|
|
439
|
+
},
|
|
440
|
+
{
|
|
441
|
+
name: 'Implementation Phase',
|
|
442
|
+
tasks: [
|
|
443
|
+
'Implement optimized solution',
|
|
444
|
+
'Apply learned patterns',
|
|
445
|
+
'Validate improvements'
|
|
446
|
+
],
|
|
447
|
+
workers: workers,
|
|
448
|
+
parallel: true,
|
|
449
|
+
applyLearning: true
|
|
450
|
+
}
|
|
451
|
+
];
|
|
452
|
+
return {
|
|
453
|
+
strategy: 'adaptive_learning',
|
|
454
|
+
phases: learningPhases,
|
|
455
|
+
estimatedDuration: 45,
|
|
456
|
+
parallelism: 'adaptive',
|
|
457
|
+
learningEnabled: true
|
|
458
|
+
};
|
|
573
459
|
}
|
|
574
|
-
|
|
575
|
-
|
|
460
|
+
/**
|
|
461
|
+
* Generate component-specific tasks
|
|
462
|
+
*/ _generateComponentTasks(component) {
|
|
463
|
+
const taskTemplates = {
|
|
464
|
+
backend: [
|
|
465
|
+
'Design API endpoints',
|
|
466
|
+
'Implement business logic',
|
|
467
|
+
'Set up database models',
|
|
468
|
+
'Create API tests'
|
|
469
|
+
],
|
|
470
|
+
frontend: [
|
|
471
|
+
'Design UI components',
|
|
472
|
+
'Implement user interface',
|
|
473
|
+
'Add interactivity',
|
|
474
|
+
'Create UI tests'
|
|
475
|
+
],
|
|
476
|
+
data: [
|
|
477
|
+
'Design data schema',
|
|
478
|
+
'Implement data access layer',
|
|
479
|
+
'Set up caching',
|
|
480
|
+
'Optimize queries'
|
|
481
|
+
],
|
|
482
|
+
auth: [
|
|
483
|
+
'Design authentication flow',
|
|
484
|
+
'Implement auth middleware',
|
|
485
|
+
'Add authorization checks',
|
|
486
|
+
'Test security'
|
|
487
|
+
]
|
|
488
|
+
};
|
|
489
|
+
return taskTemplates[component] || [
|
|
490
|
+
`Design ${component}`,
|
|
491
|
+
`Implement ${component}`,
|
|
492
|
+
`Test ${component}`
|
|
493
|
+
];
|
|
576
494
|
}
|
|
577
|
-
|
|
578
|
-
|
|
495
|
+
/**
|
|
496
|
+
* Generate all tasks based on analysis
|
|
497
|
+
*/ _generateAllTasks(analysis) {
|
|
498
|
+
const tasks = [];
|
|
499
|
+
const components = this._identifyComponents(analysis.objective);
|
|
500
|
+
// Add general tasks
|
|
501
|
+
tasks.push('Analyze requirements', 'Design architecture', 'Set up project structure');
|
|
502
|
+
// Add component tasks
|
|
503
|
+
components.forEach((component)=>{
|
|
504
|
+
tasks.push(...this._generateComponentTasks(component));
|
|
505
|
+
});
|
|
506
|
+
// Add integration tasks
|
|
507
|
+
tasks.push('Integrate components', 'Write tests', 'Document solution');
|
|
508
|
+
return tasks;
|
|
579
509
|
}
|
|
580
|
-
|
|
581
|
-
|
|
510
|
+
/**
|
|
511
|
+
* Group workers by type
|
|
512
|
+
*/ _groupWorkersByType(workers) {
|
|
513
|
+
const groups = {};
|
|
514
|
+
workers.forEach((worker)=>{
|
|
515
|
+
if (!groups[worker.type]) {
|
|
516
|
+
groups[worker.type] = [];
|
|
517
|
+
}
|
|
518
|
+
groups[worker.type].push(worker);
|
|
519
|
+
});
|
|
520
|
+
return groups;
|
|
582
521
|
}
|
|
583
|
-
|
|
584
|
-
|
|
522
|
+
/**
|
|
523
|
+
* Optimize worker assignment for tasks
|
|
524
|
+
*/ _optimizeWorkerAssignment(tasks, workerGroups) {
|
|
525
|
+
const assignments = {};
|
|
526
|
+
tasks.forEach((task)=>{
|
|
527
|
+
const bestWorkerType = this._findBestWorkerType(task);
|
|
528
|
+
const availableWorkers = workerGroups[bestWorkerType] || [];
|
|
529
|
+
if (availableWorkers.length > 0) {
|
|
530
|
+
// Round-robin assignment within type
|
|
531
|
+
const workerIndex = Object.keys(assignments).filter((t)=>assignments[t].type === bestWorkerType).length % availableWorkers.length;
|
|
532
|
+
assignments[task] = availableWorkers[workerIndex];
|
|
533
|
+
}
|
|
534
|
+
});
|
|
535
|
+
return assignments;
|
|
585
536
|
}
|
|
586
|
-
|
|
587
|
-
|
|
537
|
+
/**
|
|
538
|
+
* Find best worker type for task
|
|
539
|
+
*/ _findBestWorkerType(task) {
|
|
540
|
+
const taskLower = task.toLowerCase();
|
|
541
|
+
if (taskLower.includes('research') || taskLower.includes('analyze')) {
|
|
542
|
+
return 'researcher';
|
|
543
|
+
}
|
|
544
|
+
if (taskLower.includes('design') || taskLower.includes('architect')) {
|
|
545
|
+
return 'architect';
|
|
546
|
+
}
|
|
547
|
+
if (taskLower.includes('implement') || taskLower.includes('code')) {
|
|
548
|
+
return 'coder';
|
|
549
|
+
}
|
|
550
|
+
if (taskLower.includes('test') || taskLower.includes('validate')) {
|
|
551
|
+
return 'tester';
|
|
552
|
+
}
|
|
553
|
+
if (taskLower.includes('optimize') || taskLower.includes('performance')) {
|
|
554
|
+
return 'optimizer';
|
|
555
|
+
}
|
|
556
|
+
if (taskLower.includes('document') || taskLower.includes('write')) {
|
|
557
|
+
return 'documenter';
|
|
558
|
+
}
|
|
559
|
+
return 'coder'; // Default
|
|
588
560
|
}
|
|
589
|
-
|
|
590
|
-
return 'coder'; // Default
|
|
591
|
-
}
|
|
592
|
-
|
|
593
|
-
/**
|
|
561
|
+
/**
|
|
594
562
|
* Identify decision points in objective
|
|
595
|
-
*/
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
decisions.push('Implementation approach');
|
|
625
|
-
}
|
|
626
|
-
|
|
627
|
-
return decisions;
|
|
628
|
-
}
|
|
629
|
-
|
|
630
|
-
/**
|
|
563
|
+
*/ _identifyDecisionPoints(analysis) {
|
|
564
|
+
const decisionKeywords = [
|
|
565
|
+
'choose',
|
|
566
|
+
'select',
|
|
567
|
+
'decide',
|
|
568
|
+
'option',
|
|
569
|
+
'approach',
|
|
570
|
+
'strategy',
|
|
571
|
+
'method',
|
|
572
|
+
'solution',
|
|
573
|
+
'alternative'
|
|
574
|
+
];
|
|
575
|
+
const decisions = [];
|
|
576
|
+
const components = this._identifyComponents(analysis.objective);
|
|
577
|
+
// Architecture decisions
|
|
578
|
+
if (components.length > 2) {
|
|
579
|
+
decisions.push('Architecture pattern selection');
|
|
580
|
+
}
|
|
581
|
+
// Technology decisions
|
|
582
|
+
components.forEach((component)=>{
|
|
583
|
+
decisions.push(`Technology stack for ${component}`);
|
|
584
|
+
});
|
|
585
|
+
// Implementation decisions
|
|
586
|
+
if (analysis.complexity !== 'low') {
|
|
587
|
+
decisions.push('Implementation approach');
|
|
588
|
+
}
|
|
589
|
+
return decisions;
|
|
590
|
+
}
|
|
591
|
+
/**
|
|
631
592
|
* Make strategic decision
|
|
632
|
-
*/
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
this.emit('decision:made', decision);
|
|
654
|
-
return decision;
|
|
655
|
-
}
|
|
656
|
-
|
|
657
|
-
/**
|
|
593
|
+
*/ async makeDecision(topic, options, workerVotes = {}) {
|
|
594
|
+
const decision = {
|
|
595
|
+
topic,
|
|
596
|
+
options,
|
|
597
|
+
workerVotes,
|
|
598
|
+
queenVote: this._calculateQueenVote(topic, options, workerVotes),
|
|
599
|
+
timestamp: Date.now()
|
|
600
|
+
};
|
|
601
|
+
// Calculate final decision with queen's weighted vote
|
|
602
|
+
const finalDecision = this._calculateFinalDecision(decision);
|
|
603
|
+
decision.result = finalDecision;
|
|
604
|
+
this.state.decisionsCount++;
|
|
605
|
+
// Learn from decision
|
|
606
|
+
if (this.config.type === 'adaptive') {
|
|
607
|
+
this._learnFromDecision(decision);
|
|
608
|
+
}
|
|
609
|
+
this.emit('decision:made', decision);
|
|
610
|
+
return decision;
|
|
611
|
+
}
|
|
612
|
+
/**
|
|
658
613
|
* Calculate queen's vote
|
|
659
|
-
*/
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
return options[0]; // Default
|
|
677
|
-
}
|
|
678
|
-
|
|
679
|
-
/**
|
|
614
|
+
*/ _calculateQueenVote(topic, options, workerVotes) {
|
|
615
|
+
// Strategic queen focuses on long-term impact
|
|
616
|
+
if (this.config.type === 'strategic') {
|
|
617
|
+
return this._strategicVote(topic, options);
|
|
618
|
+
}
|
|
619
|
+
// Tactical queen focuses on immediate efficiency
|
|
620
|
+
if (this.config.type === 'tactical') {
|
|
621
|
+
return this._tacticalVote(topic, options, workerVotes);
|
|
622
|
+
}
|
|
623
|
+
// Adaptive queen learns from past decisions
|
|
624
|
+
if (this.config.type === 'adaptive') {
|
|
625
|
+
return this._adaptiveVote(topic, options, workerVotes);
|
|
626
|
+
}
|
|
627
|
+
return options[0]; // Default
|
|
628
|
+
}
|
|
629
|
+
/**
|
|
680
630
|
* Strategic voting logic
|
|
681
|
-
*/
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
631
|
+
*/ _strategicVote(topic, options) {
|
|
632
|
+
// Prefer options that mention long-term benefits
|
|
633
|
+
const strategicKeywords = [
|
|
634
|
+
'scalable',
|
|
635
|
+
'maintainable',
|
|
636
|
+
'extensible',
|
|
637
|
+
'future'
|
|
638
|
+
];
|
|
639
|
+
for (const option of options){
|
|
640
|
+
const optionLower = option.toLowerCase();
|
|
641
|
+
if (strategicKeywords.some((keyword)=>optionLower.includes(keyword))) {
|
|
642
|
+
return option;
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
return options[0];
|
|
646
|
+
}
|
|
647
|
+
/**
|
|
697
648
|
* Tactical voting logic
|
|
698
|
-
*/
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
/**
|
|
649
|
+
*/ _tacticalVote(topic, options, workerVotes) {
|
|
650
|
+
// Follow majority if consensus is strong
|
|
651
|
+
const voteCounts = {};
|
|
652
|
+
Object.values(workerVotes).forEach((vote)=>{
|
|
653
|
+
voteCounts[vote] = (voteCounts[vote] || 0) + 1;
|
|
654
|
+
});
|
|
655
|
+
const sorted = Object.entries(voteCounts).sort((a, b)=>b[1] - a[1]);
|
|
656
|
+
if (sorted.length > 0 && sorted[0][1] > Object.keys(workerVotes).length * 0.6) {
|
|
657
|
+
return sorted[0][0];
|
|
658
|
+
}
|
|
659
|
+
// Otherwise, prefer quick implementation
|
|
660
|
+
const tacticalKeywords = [
|
|
661
|
+
'simple',
|
|
662
|
+
'quick',
|
|
663
|
+
'fast',
|
|
664
|
+
'efficient'
|
|
665
|
+
];
|
|
666
|
+
for (const option of options){
|
|
667
|
+
const optionLower = option.toLowerCase();
|
|
668
|
+
if (tacticalKeywords.some((keyword)=>optionLower.includes(keyword))) {
|
|
669
|
+
return option;
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
return options[0];
|
|
673
|
+
}
|
|
674
|
+
/**
|
|
725
675
|
* Adaptive voting logic
|
|
726
|
-
*/
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
.map(([_, decision]) => decision.result);
|
|
738
|
-
|
|
739
|
-
for (const option of options) {
|
|
740
|
-
if (successfulOptions.includes(option)) {
|
|
741
|
-
return option;
|
|
676
|
+
*/ _adaptiveVote(topic, options, workerVotes) {
|
|
677
|
+
// Check if we've seen similar decisions before
|
|
678
|
+
const similarDecisions = Array.from(this.state.learningData.entries()).filter(([key, value])=>key.includes('decision') && value.topic.includes(topic));
|
|
679
|
+
if (similarDecisions.length > 0) {
|
|
680
|
+
// Use learned preferences
|
|
681
|
+
const successfulOptions = similarDecisions.filter(([_, decision])=>decision.success).map(([_, decision])=>decision.result);
|
|
682
|
+
for (const option of options){
|
|
683
|
+
if (successfulOptions.includes(option)) {
|
|
684
|
+
return option;
|
|
685
|
+
}
|
|
686
|
+
}
|
|
742
687
|
}
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
return options[Math.floor(Math.random() * options.length)];
|
|
748
|
-
}
|
|
749
|
-
|
|
750
|
-
/**
|
|
688
|
+
// Otherwise, explore new option
|
|
689
|
+
return options[Math.floor(Math.random() * options.length)];
|
|
690
|
+
}
|
|
691
|
+
/**
|
|
751
692
|
* Calculate final decision with weighted votes
|
|
752
|
-
*/
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
// Find winner
|
|
766
|
-
const sorted = Object.entries(voteCounts).sort((a, b) => b[1] - a[1]);
|
|
767
|
-
return sorted[0][0];
|
|
768
|
-
}
|
|
769
|
-
|
|
770
|
-
/**
|
|
693
|
+
*/ _calculateFinalDecision(decision) {
|
|
694
|
+
const voteCounts = {};
|
|
695
|
+
// Count worker votes
|
|
696
|
+
Object.values(decision.workerVotes).forEach((vote)=>{
|
|
697
|
+
voteCounts[vote] = (voteCounts[vote] || 0) + 1;
|
|
698
|
+
});
|
|
699
|
+
// Add queen's weighted vote
|
|
700
|
+
voteCounts[decision.queenVote] = (voteCounts[decision.queenVote] || 0) + this.config.decisionWeight;
|
|
701
|
+
// Find winner
|
|
702
|
+
const sorted = Object.entries(voteCounts).sort((a, b)=>b[1] - a[1]);
|
|
703
|
+
return sorted[0][0];
|
|
704
|
+
}
|
|
705
|
+
/**
|
|
771
706
|
* Learn from decision outcomes
|
|
772
|
-
*/
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
}
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
/**
|
|
707
|
+
*/ _learnFromDecision(decision) {
|
|
708
|
+
const key = `decision-${this.state.decisionsCount}`;
|
|
709
|
+
this.state.learningData.set(key, {
|
|
710
|
+
...decision,
|
|
711
|
+
success: true
|
|
712
|
+
});
|
|
713
|
+
}
|
|
714
|
+
/**
|
|
782
715
|
* Update decision outcome
|
|
783
|
-
*/
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
716
|
+
*/ updateDecisionOutcome(decisionId, success, metrics = {}) {
|
|
717
|
+
const key = `decision-${decisionId}`;
|
|
718
|
+
const decision = this.state.learningData.get(key);
|
|
719
|
+
if (decision) {
|
|
720
|
+
decision.success = success;
|
|
721
|
+
decision.metrics = metrics;
|
|
722
|
+
this.emit('learning:updated', {
|
|
723
|
+
decisionId,
|
|
724
|
+
success,
|
|
725
|
+
metrics
|
|
726
|
+
});
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
/**
|
|
796
730
|
* Get queen status
|
|
797
|
-
*/
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
}
|
|
808
|
-
|
|
731
|
+
*/ getStatus() {
|
|
732
|
+
return {
|
|
733
|
+
type: this.config.type,
|
|
734
|
+
name: this.config.name,
|
|
735
|
+
status: this.state.status,
|
|
736
|
+
decisionsCount: this.state.decisionsCount,
|
|
737
|
+
strategiesExecuted: this.state.strategiesExecuted,
|
|
738
|
+
currentStrategy: this.state.currentStrategy,
|
|
739
|
+
learningDataSize: this.state.learningData.size
|
|
740
|
+
};
|
|
741
|
+
}
|
|
742
|
+
constructor(config = {}){
|
|
743
|
+
super();
|
|
744
|
+
this.config = {
|
|
745
|
+
swarmId: config.swarmId,
|
|
746
|
+
type: config.type || 'strategic',
|
|
747
|
+
objective: config.objective || '',
|
|
748
|
+
...QUEEN_TYPES[config.type || 'strategic']
|
|
749
|
+
};
|
|
750
|
+
this.state = {
|
|
751
|
+
status: 'initializing',
|
|
752
|
+
decisionsCount: 0,
|
|
753
|
+
strategiesExecuted: 0,
|
|
754
|
+
learningData: new Map(),
|
|
755
|
+
currentStrategy: null,
|
|
756
|
+
taskQueue: [],
|
|
757
|
+
workerAssignments: new Map()
|
|
758
|
+
};
|
|
759
|
+
this.strategies = {
|
|
760
|
+
divide_and_conquer: this._divideAndConquerStrategy.bind(this),
|
|
761
|
+
parallel_execution: this._parallelExecutionStrategy.bind(this),
|
|
762
|
+
sequential_refinement: this._sequentialRefinementStrategy.bind(this),
|
|
763
|
+
consensus_driven: this._consensusDrivenStrategy.bind(this),
|
|
764
|
+
adaptive_learning: this._adaptiveLearningStrategy.bind(this)
|
|
765
|
+
};
|
|
766
|
+
this._initialize();
|
|
767
|
+
}
|
|
809
768
|
}
|