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,1045 +1,980 @@
|
|
|
1
1
|
// SPARC Coordinator
|
|
2
2
|
// Integrates SPARC methodology with swarm system for enhanced coordination
|
|
3
|
-
|
|
4
|
-
import { SparcPhase } from './phase-base.js';
|
|
5
|
-
|
|
6
3
|
export class SparcCoordinator {
|
|
7
|
-
|
|
8
|
-
this.phases = phases;
|
|
9
|
-
this.options = options;
|
|
10
|
-
this.swarmId = null;
|
|
11
|
-
this.agents = [];
|
|
12
|
-
this.phaseAgents = new Map();
|
|
13
|
-
this.coordination = {
|
|
14
|
-
strategy: 'adaptive',
|
|
15
|
-
topology: 'hierarchical',
|
|
16
|
-
communication: 'event-driven',
|
|
17
|
-
loadBalancing: 'capability-based',
|
|
18
|
-
};
|
|
19
|
-
this.metrics = {
|
|
20
|
-
phaseExecutions: 0,
|
|
21
|
-
agentUtilization: {},
|
|
22
|
-
coordinationEfficiency: 0,
|
|
23
|
-
qualityGates: [],
|
|
24
|
-
learningData: [],
|
|
25
|
-
};
|
|
26
|
-
this.neuralContext = null;
|
|
27
|
-
this.swarmEnabled = options.swarmEnabled || false;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
4
|
+
/**
|
|
31
5
|
* Initialize swarm for SPARC execution
|
|
32
|
-
*/
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
console.log('✅ SPARC Swarm coordination initialized');
|
|
61
|
-
} catch (error) {
|
|
62
|
-
console.warn(`⚠️ Swarm initialization failed: ${error.message}`);
|
|
63
|
-
console.log('🔄 Falling back to standalone mode');
|
|
64
|
-
this.swarmEnabled = false;
|
|
6
|
+
*/ async initializeSwarm() {
|
|
7
|
+
if (!this.swarmEnabled) {
|
|
8
|
+
console.log('🔄 SPARC running in standalone mode');
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
console.log('🐝 Initializing SPARC Swarm Coordination');
|
|
12
|
+
try {
|
|
13
|
+
// Initialize swarm using ruv-swarm hooks
|
|
14
|
+
const swarmConfig = {
|
|
15
|
+
topology: this.coordination.topology,
|
|
16
|
+
maxAgents: this.calculateOptimalAgentCount(),
|
|
17
|
+
strategy: 'sparc_methodology',
|
|
18
|
+
communication: this.coordination.communication,
|
|
19
|
+
loadBalancing: this.coordination.loadBalancing
|
|
20
|
+
};
|
|
21
|
+
this.swarmId = await this.executeSwarmHook('swarm_init', swarmConfig);
|
|
22
|
+
console.log(`🆔 Swarm initialized: ${this.swarmId}`);
|
|
23
|
+
// Spawn specialized SPARC agents
|
|
24
|
+
await this.spawnSparcAgents();
|
|
25
|
+
// Setup inter-phase coordination
|
|
26
|
+
await this.setupPhaseCoordination();
|
|
27
|
+
console.log('✅ SPARC Swarm coordination initialized');
|
|
28
|
+
} catch (error) {
|
|
29
|
+
console.warn(`⚠️ Swarm initialization failed: ${error.message}`);
|
|
30
|
+
console.log('🔄 Falling back to standalone mode');
|
|
31
|
+
this.swarmEnabled = false;
|
|
32
|
+
}
|
|
65
33
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
/**
|
|
34
|
+
/**
|
|
69
35
|
* Calculate optimal agent count based on SPARC phases
|
|
70
|
-
*/
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/**
|
|
36
|
+
*/ calculateOptimalAgentCount() {
|
|
37
|
+
const baseAgents = Object.keys(this.phases).length; // One per phase
|
|
38
|
+
const complexityMultiplier = this.assessTaskComplexity();
|
|
39
|
+
const parallelismFactor = this.options.parallelExecution ? 2 : 1;
|
|
40
|
+
return Math.min(20, Math.max(5, baseAgents * complexityMultiplier * parallelismFactor));
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
80
43
|
* Assess task complexity for agent allocation
|
|
81
|
-
*/
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
if (matchedKeywords.length >= 1) return 2; // Medium complexity
|
|
98
|
-
return 1; // Low complexity
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
/**
|
|
44
|
+
*/ assessTaskComplexity() {
|
|
45
|
+
const taskDescription = this.options.taskDescription || '';
|
|
46
|
+
const complexityKeywords = [
|
|
47
|
+
'complex',
|
|
48
|
+
'enterprise',
|
|
49
|
+
'scalable',
|
|
50
|
+
'distributed',
|
|
51
|
+
'microservice',
|
|
52
|
+
'integration'
|
|
53
|
+
];
|
|
54
|
+
const matchedKeywords = complexityKeywords.filter((keyword)=>taskDescription.toLowerCase().includes(keyword));
|
|
55
|
+
if (matchedKeywords.length >= 3) return 3; // High complexity
|
|
56
|
+
if (matchedKeywords.length >= 1) return 2; // Medium complexity
|
|
57
|
+
return 1; // Low complexity
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
102
60
|
* Spawn specialized SPARC agents
|
|
103
|
-
*/
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
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
|
-
|
|
167
|
-
|
|
168
|
-
|
|
61
|
+
*/ async spawnSparcAgents() {
|
|
62
|
+
const agentTypes = [
|
|
63
|
+
{
|
|
64
|
+
type: 'sparc_specification',
|
|
65
|
+
role: 'Requirements Analyst',
|
|
66
|
+
capabilities: [
|
|
67
|
+
'analysis',
|
|
68
|
+
'documentation',
|
|
69
|
+
'validation'
|
|
70
|
+
]
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
type: 'sparc_pseudocode',
|
|
74
|
+
role: 'Logic Designer',
|
|
75
|
+
capabilities: [
|
|
76
|
+
'design',
|
|
77
|
+
'flowcharts',
|
|
78
|
+
'algorithms'
|
|
79
|
+
]
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
type: 'sparc_architecture',
|
|
83
|
+
role: 'System Architect',
|
|
84
|
+
capabilities: [
|
|
85
|
+
'architecture',
|
|
86
|
+
'design_patterns',
|
|
87
|
+
'scalability'
|
|
88
|
+
]
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
type: 'sparc_refinement',
|
|
92
|
+
role: 'TDD Engineer',
|
|
93
|
+
capabilities: [
|
|
94
|
+
'testing',
|
|
95
|
+
'refactoring',
|
|
96
|
+
'code_quality'
|
|
97
|
+
]
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
type: 'sparc_completion',
|
|
101
|
+
role: 'Integration Specialist',
|
|
102
|
+
capabilities: [
|
|
103
|
+
'integration',
|
|
104
|
+
'deployment',
|
|
105
|
+
'validation'
|
|
106
|
+
]
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
type: 'sparc_coordinator',
|
|
110
|
+
role: 'SPARC Orchestrator',
|
|
111
|
+
capabilities: [
|
|
112
|
+
'coordination',
|
|
113
|
+
'monitoring',
|
|
114
|
+
'optimization'
|
|
115
|
+
]
|
|
116
|
+
}
|
|
117
|
+
];
|
|
118
|
+
for (const agentSpec of agentTypes){
|
|
119
|
+
try {
|
|
120
|
+
const agentId = await this.executeSwarmHook('agent_spawn', {
|
|
121
|
+
type: agentSpec.type,
|
|
122
|
+
role: agentSpec.role,
|
|
123
|
+
capabilities: agentSpec.capabilities,
|
|
124
|
+
maxConcurrentTasks: this.getAgentConcurrency(agentSpec.type),
|
|
125
|
+
specialization: 'sparc_methodology'
|
|
126
|
+
});
|
|
127
|
+
const agent = {
|
|
128
|
+
id: agentId,
|
|
129
|
+
type: agentSpec.type,
|
|
130
|
+
role: agentSpec.role,
|
|
131
|
+
capabilities: agentSpec.capabilities,
|
|
132
|
+
status: 'ready',
|
|
133
|
+
currentPhase: null,
|
|
134
|
+
assignedTasks: [],
|
|
135
|
+
performance: {
|
|
136
|
+
tasksCompleted: 0,
|
|
137
|
+
averageTime: 0,
|
|
138
|
+
qualityScore: 1.0,
|
|
139
|
+
efficiency: 1.0
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
this.agents.push(agent);
|
|
143
|
+
console.log(` 🤖 Spawned ${agentSpec.role} (${agentSpec.type})`);
|
|
144
|
+
} catch (error) {
|
|
145
|
+
console.warn(`⚠️ Failed to spawn ${agentSpec.role}: ${error.message}`);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
169
148
|
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
/**
|
|
149
|
+
/**
|
|
173
150
|
* Get agent concurrency based on type
|
|
174
|
-
*/
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
/**
|
|
151
|
+
*/ getAgentConcurrency(agentType) {
|
|
152
|
+
const concurrencyMap = {
|
|
153
|
+
sparc_specification: 2,
|
|
154
|
+
sparc_pseudocode: 1,
|
|
155
|
+
sparc_architecture: 3,
|
|
156
|
+
sparc_refinement: 4,
|
|
157
|
+
sparc_completion: 2,
|
|
158
|
+
sparc_coordinator: 1
|
|
159
|
+
};
|
|
160
|
+
return concurrencyMap[agentType] || 2;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
189
163
|
* Setup phase coordination
|
|
190
|
-
*/
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
164
|
+
*/ async setupPhaseCoordination() {
|
|
165
|
+
// Map agents to phases
|
|
166
|
+
for (const agent of this.agents){
|
|
167
|
+
const phaseName = agent.type.replace('sparc_', '');
|
|
168
|
+
if (this.phases[phaseName]) {
|
|
169
|
+
if (!this.phaseAgents.has(phaseName)) {
|
|
170
|
+
this.phaseAgents.set(phaseName, []);
|
|
171
|
+
}
|
|
172
|
+
this.phaseAgents.get(phaseName).push(agent);
|
|
173
|
+
}
|
|
198
174
|
}
|
|
199
|
-
|
|
200
|
-
|
|
175
|
+
// Setup phase dependencies
|
|
176
|
+
await this.executeSwarmHook('setup_dependencies', {
|
|
177
|
+
phases: Object.keys(this.phases),
|
|
178
|
+
dependencies: {
|
|
179
|
+
pseudocode: [
|
|
180
|
+
'specification'
|
|
181
|
+
],
|
|
182
|
+
architecture: [
|
|
183
|
+
'specification',
|
|
184
|
+
'pseudocode'
|
|
185
|
+
],
|
|
186
|
+
refinement: [
|
|
187
|
+
'specification',
|
|
188
|
+
'pseudocode',
|
|
189
|
+
'architecture'
|
|
190
|
+
],
|
|
191
|
+
completion: [
|
|
192
|
+
'specification',
|
|
193
|
+
'pseudocode',
|
|
194
|
+
'architecture',
|
|
195
|
+
'refinement'
|
|
196
|
+
]
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
// Setup quality gates between phases
|
|
200
|
+
await this.setupQualityGates();
|
|
201
201
|
}
|
|
202
|
-
|
|
203
|
-
// Setup phase dependencies
|
|
204
|
-
await this.executeSwarmHook('setup_dependencies', {
|
|
205
|
-
phases: Object.keys(this.phases),
|
|
206
|
-
dependencies: {
|
|
207
|
-
pseudocode: ['specification'],
|
|
208
|
-
architecture: ['specification', 'pseudocode'],
|
|
209
|
-
refinement: ['specification', 'pseudocode', 'architecture'],
|
|
210
|
-
completion: ['specification', 'pseudocode', 'architecture', 'refinement'],
|
|
211
|
-
},
|
|
212
|
-
});
|
|
213
|
-
|
|
214
|
-
// Setup quality gates between phases
|
|
215
|
-
await this.setupQualityGates();
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
/**
|
|
202
|
+
/**
|
|
219
203
|
* Setup quality gates between phases
|
|
220
|
-
*/
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
204
|
+
*/ async setupQualityGates() {
|
|
205
|
+
const qualityGates = [
|
|
206
|
+
{
|
|
207
|
+
phase: 'specification',
|
|
208
|
+
criteria: [
|
|
209
|
+
'requirements_complete',
|
|
210
|
+
'acceptance_criteria_defined'
|
|
211
|
+
],
|
|
212
|
+
threshold: 0.9
|
|
213
|
+
},
|
|
214
|
+
{
|
|
215
|
+
phase: 'pseudocode',
|
|
216
|
+
criteria: [
|
|
217
|
+
'flow_diagram_complete',
|
|
218
|
+
'algorithms_defined'
|
|
219
|
+
],
|
|
220
|
+
threshold: 0.85
|
|
221
|
+
},
|
|
222
|
+
{
|
|
223
|
+
phase: 'architecture',
|
|
224
|
+
criteria: [
|
|
225
|
+
'components_defined',
|
|
226
|
+
'patterns_selected'
|
|
227
|
+
],
|
|
228
|
+
threshold: 0.85
|
|
229
|
+
},
|
|
230
|
+
{
|
|
231
|
+
phase: 'refinement',
|
|
232
|
+
criteria: [
|
|
233
|
+
'tests_passing',
|
|
234
|
+
'code_quality_acceptable'
|
|
235
|
+
],
|
|
236
|
+
threshold: 0.8
|
|
237
|
+
},
|
|
238
|
+
{
|
|
239
|
+
phase: 'completion',
|
|
240
|
+
criteria: [
|
|
241
|
+
'validation_passed',
|
|
242
|
+
'deployment_successful'
|
|
243
|
+
],
|
|
244
|
+
threshold: 0.9
|
|
245
|
+
}
|
|
246
|
+
];
|
|
247
|
+
for (const gate of qualityGates){
|
|
248
|
+
await this.executeSwarmHook('register_quality_gate', gate);
|
|
249
|
+
}
|
|
252
250
|
}
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
/**
|
|
251
|
+
/**
|
|
256
252
|
* Pre-phase coordination
|
|
257
|
-
*/
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
neuralContext: this.neuralContext,
|
|
280
|
-
},
|
|
281
|
-
});
|
|
282
|
-
} catch (error) {
|
|
283
|
-
console.warn(`⚠️ Pre-phase coordination failed for ${phaseName}: ${error.message}`);
|
|
253
|
+
*/ async prePhase(phaseName) {
|
|
254
|
+
if (!this.swarmEnabled) return;
|
|
255
|
+
console.log(`🔄 Pre-phase coordination: ${phaseName}`);
|
|
256
|
+
try {
|
|
257
|
+
// Load neural context for the phase
|
|
258
|
+
await this.loadNeuralContext(phaseName);
|
|
259
|
+
// Assign agents to phase
|
|
260
|
+
await this.assignAgentsToPhase(phaseName);
|
|
261
|
+
// Prepare phase environment
|
|
262
|
+
await this.preparePhaseEnvironment(phaseName);
|
|
263
|
+
// Store phase initiation in memory
|
|
264
|
+
await this.executeSwarmHook('memory_store', {
|
|
265
|
+
key: `sparc_phase_${phaseName}_start`,
|
|
266
|
+
value: {
|
|
267
|
+
timestamp: Date.now(),
|
|
268
|
+
agents: this.phaseAgents.get(phaseName)?.map((a)=>a.id) || [],
|
|
269
|
+
neuralContext: this.neuralContext
|
|
270
|
+
}
|
|
271
|
+
});
|
|
272
|
+
} catch (error) {
|
|
273
|
+
console.warn(`⚠️ Pre-phase coordination failed for ${phaseName}: ${error.message}`);
|
|
274
|
+
}
|
|
284
275
|
}
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
/**
|
|
276
|
+
/**
|
|
288
277
|
* Load neural context for phase
|
|
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
|
-
insights: [],
|
|
315
|
-
recommendations: [],
|
|
316
|
-
confidence: 0.5,
|
|
317
|
-
};
|
|
278
|
+
*/ async loadNeuralContext(phaseName) {
|
|
279
|
+
try {
|
|
280
|
+
const neuralData = await this.executeSwarmHook('neural_load_context', {
|
|
281
|
+
phase: phaseName,
|
|
282
|
+
methodology: 'sparc',
|
|
283
|
+
taskType: this.classifyTaskType()
|
|
284
|
+
});
|
|
285
|
+
this.neuralContext = {
|
|
286
|
+
phase: phaseName,
|
|
287
|
+
patterns: neuralData.patterns || [],
|
|
288
|
+
insights: neuralData.insights || [],
|
|
289
|
+
recommendations: neuralData.recommendations || [],
|
|
290
|
+
confidence: neuralData.confidence || 0.5
|
|
291
|
+
};
|
|
292
|
+
console.log(`🧠 Neural context loaded for ${phaseName} (confidence: ${this.neuralContext.confidence.toFixed(2)})`);
|
|
293
|
+
} catch (error) {
|
|
294
|
+
console.warn(`⚠️ Neural context loading failed: ${error.message}`);
|
|
295
|
+
this.neuralContext = {
|
|
296
|
+
phase: phaseName,
|
|
297
|
+
patterns: [],
|
|
298
|
+
insights: [],
|
|
299
|
+
recommendations: [],
|
|
300
|
+
confidence: 0.5
|
|
301
|
+
};
|
|
302
|
+
}
|
|
318
303
|
}
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
/**
|
|
304
|
+
/**
|
|
322
305
|
* Classify task type for neural learning
|
|
323
|
-
*/
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
return 'general_development';
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
/**
|
|
306
|
+
*/ classifyTaskType() {
|
|
307
|
+
const taskDescription = this.options.taskDescription || '';
|
|
308
|
+
const taskLower = taskDescription.toLowerCase();
|
|
309
|
+
if (taskLower.includes('api') || taskLower.includes('service')) return 'api_development';
|
|
310
|
+
if (taskLower.includes('ui') || taskLower.includes('frontend')) return 'frontend_development';
|
|
311
|
+
if (taskLower.includes('data') || taskLower.includes('database')) return 'data_management';
|
|
312
|
+
if (taskLower.includes('test') || taskLower.includes('testing')) return 'testing';
|
|
313
|
+
if (taskLower.includes('deploy') || taskLower.includes('infrastructure')) return 'deployment';
|
|
314
|
+
return 'general_development';
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
338
317
|
* Assign agents to phase
|
|
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
|
-
priority: this.getPhasePriority(phaseName),
|
|
366
|
-
context: this.neuralContext,
|
|
367
|
-
});
|
|
368
|
-
}
|
|
318
|
+
*/ async assignAgentsToPhase(phaseName) {
|
|
319
|
+
const phaseAgents = this.phaseAgents.get(phaseName) || [];
|
|
320
|
+
for (const agent of phaseAgents){
|
|
321
|
+
agent.currentPhase = phaseName;
|
|
322
|
+
agent.status = 'assigned';
|
|
323
|
+
await this.executeSwarmHook('agent_assign', {
|
|
324
|
+
agentId: agent.id,
|
|
325
|
+
phase: phaseName,
|
|
326
|
+
priority: this.getPhasePriority(phaseName),
|
|
327
|
+
context: this.neuralContext
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
// If no dedicated agents, assign general coordinator
|
|
331
|
+
if (phaseAgents.length === 0) {
|
|
332
|
+
const coordinator = this.agents.find((a)=>a.type === 'sparc_coordinator');
|
|
333
|
+
if (coordinator) {
|
|
334
|
+
coordinator.currentPhase = phaseName;
|
|
335
|
+
coordinator.status = 'assigned';
|
|
336
|
+
await this.executeSwarmHook('agent_assign', {
|
|
337
|
+
agentId: coordinator.id,
|
|
338
|
+
phase: phaseName,
|
|
339
|
+
priority: this.getPhasePriority(phaseName),
|
|
340
|
+
context: this.neuralContext
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
}
|
|
369
344
|
}
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
/**
|
|
345
|
+
/**
|
|
373
346
|
* Get phase priority for scheduling
|
|
374
|
-
*/
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
/**
|
|
347
|
+
*/ getPhasePriority(phaseName) {
|
|
348
|
+
const priorities = {
|
|
349
|
+
specification: 5,
|
|
350
|
+
pseudocode: 4,
|
|
351
|
+
architecture: 4,
|
|
352
|
+
refinement: 3,
|
|
353
|
+
completion: 2
|
|
354
|
+
};
|
|
355
|
+
return priorities[phaseName] || 1;
|
|
356
|
+
}
|
|
357
|
+
/**
|
|
388
358
|
* Prepare phase environment
|
|
389
|
-
*/
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
359
|
+
*/ async preparePhaseEnvironment(phaseName) {
|
|
360
|
+
// Create phase-specific workspace
|
|
361
|
+
await this.executeSwarmHook('create_workspace', {
|
|
362
|
+
phase: phaseName,
|
|
363
|
+
namespace: this.options.namespace || 'sparc',
|
|
364
|
+
isolation: true
|
|
365
|
+
});
|
|
366
|
+
// Load previous phase artifacts
|
|
367
|
+
const dependencies = this.getPhaseDependencies(phaseName);
|
|
368
|
+
for (const dependency of dependencies){
|
|
369
|
+
await this.executeSwarmHook('load_artifacts', {
|
|
370
|
+
fromPhase: dependency,
|
|
371
|
+
toPhase: phaseName,
|
|
372
|
+
artifactTypes: [
|
|
373
|
+
'outputs',
|
|
374
|
+
'decisions',
|
|
375
|
+
'validations'
|
|
376
|
+
]
|
|
377
|
+
});
|
|
378
|
+
}
|
|
406
379
|
}
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
/**
|
|
380
|
+
/**
|
|
410
381
|
* Get phase dependencies
|
|
411
|
-
*/
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
382
|
+
*/ getPhaseDependencies(phaseName) {
|
|
383
|
+
const dependencies = {
|
|
384
|
+
specification: [],
|
|
385
|
+
pseudocode: [
|
|
386
|
+
'specification'
|
|
387
|
+
],
|
|
388
|
+
architecture: [
|
|
389
|
+
'specification',
|
|
390
|
+
'pseudocode'
|
|
391
|
+
],
|
|
392
|
+
refinement: [
|
|
393
|
+
'specification',
|
|
394
|
+
'pseudocode',
|
|
395
|
+
'architecture'
|
|
396
|
+
],
|
|
397
|
+
completion: [
|
|
398
|
+
'specification',
|
|
399
|
+
'pseudocode',
|
|
400
|
+
'architecture',
|
|
401
|
+
'refinement'
|
|
402
|
+
]
|
|
403
|
+
};
|
|
404
|
+
return dependencies[phaseName] || [];
|
|
405
|
+
}
|
|
406
|
+
/**
|
|
425
407
|
* Post-phase coordination
|
|
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
|
-
// Prepare handoff to next phase
|
|
460
|
-
await this.preparePhaseHandoff(phaseName, result);
|
|
461
|
-
|
|
462
|
-
// Update metrics
|
|
463
|
-
this.updateCoordinationMetrics(phaseName, result, validation);
|
|
464
|
-
} catch (error) {
|
|
465
|
-
console.warn(`⚠️ Post-phase coordination failed for ${phaseName}: ${error.message}`);
|
|
408
|
+
*/ async postPhase(phaseName, result) {
|
|
409
|
+
if (!this.swarmEnabled) return;
|
|
410
|
+
console.log(`✅ Post-phase coordination: ${phaseName}`);
|
|
411
|
+
try {
|
|
412
|
+
// Validate phase results
|
|
413
|
+
const validation = await this.validatePhaseResults(phaseName, result);
|
|
414
|
+
// Update agent performance
|
|
415
|
+
await this.updateAgentPerformance(phaseName, result, validation);
|
|
416
|
+
// Store phase completion in memory
|
|
417
|
+
await this.executeSwarmHook('memory_store', {
|
|
418
|
+
key: `sparc_phase_${phaseName}_complete`,
|
|
419
|
+
value: {
|
|
420
|
+
timestamp: Date.now(),
|
|
421
|
+
result: result,
|
|
422
|
+
validation: validation,
|
|
423
|
+
agents: this.phaseAgents.get(phaseName)?.map((a)=>({
|
|
424
|
+
id: a.id,
|
|
425
|
+
performance: a.performance
|
|
426
|
+
})) || []
|
|
427
|
+
}
|
|
428
|
+
});
|
|
429
|
+
// Neural learning from phase execution
|
|
430
|
+
if (this.options.neuralLearning) {
|
|
431
|
+
await this.recordNeuralLearning(phaseName, result, validation);
|
|
432
|
+
}
|
|
433
|
+
// Prepare handoff to next phase
|
|
434
|
+
await this.preparePhaseHandoff(phaseName, result);
|
|
435
|
+
// Update metrics
|
|
436
|
+
this.updateCoordinationMetrics(phaseName, result, validation);
|
|
437
|
+
} catch (error) {
|
|
438
|
+
console.warn(`⚠️ Post-phase coordination failed for ${phaseName}: ${error.message}`);
|
|
439
|
+
}
|
|
466
440
|
}
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
/**
|
|
441
|
+
/**
|
|
470
442
|
* Validate phase results
|
|
471
|
-
*/
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
validation.score = result ? 85 : 0;
|
|
443
|
+
*/ async validatePhaseResults(phaseName, result) {
|
|
444
|
+
const validation = {
|
|
445
|
+
phase: phaseName,
|
|
446
|
+
passed: true,
|
|
447
|
+
score: 0,
|
|
448
|
+
issues: [],
|
|
449
|
+
recommendations: []
|
|
450
|
+
};
|
|
451
|
+
try {
|
|
452
|
+
// Execute swarm-based validation
|
|
453
|
+
const swarmValidation = await this.executeSwarmHook('validate_phase', {
|
|
454
|
+
phase: phaseName,
|
|
455
|
+
result: result,
|
|
456
|
+
criteria: this.getValidationCriteria(phaseName)
|
|
457
|
+
});
|
|
458
|
+
validation.passed = swarmValidation.passed;
|
|
459
|
+
validation.score = swarmValidation.score;
|
|
460
|
+
validation.issues = swarmValidation.issues || [];
|
|
461
|
+
validation.recommendations = swarmValidation.recommendations || [];
|
|
462
|
+
} catch (error) {
|
|
463
|
+
console.warn(`⚠️ Swarm validation failed: ${error.message}`);
|
|
464
|
+
// Fallback to basic validation
|
|
465
|
+
validation.passed = !!result;
|
|
466
|
+
validation.score = result ? 85 : 0;
|
|
467
|
+
}
|
|
468
|
+
return validation;
|
|
498
469
|
}
|
|
499
|
-
|
|
500
|
-
return validation;
|
|
501
|
-
}
|
|
502
|
-
|
|
503
|
-
/**
|
|
470
|
+
/**
|
|
504
471
|
* Get validation criteria for phase
|
|
505
|
-
*/
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
472
|
+
*/ getValidationCriteria(phaseName) {
|
|
473
|
+
const criteria = {
|
|
474
|
+
specification: {
|
|
475
|
+
requiredFields: [
|
|
476
|
+
'requirements',
|
|
477
|
+
'acceptanceCriteria',
|
|
478
|
+
'userStories'
|
|
479
|
+
],
|
|
480
|
+
qualityThresholds: {
|
|
481
|
+
completeness: 0.9,
|
|
482
|
+
clarity: 0.8
|
|
483
|
+
}
|
|
484
|
+
},
|
|
485
|
+
pseudocode: {
|
|
486
|
+
requiredFields: [
|
|
487
|
+
'flowDiagram',
|
|
488
|
+
'pseudocode',
|
|
489
|
+
'algorithms'
|
|
490
|
+
],
|
|
491
|
+
qualityThresholds: {
|
|
492
|
+
completeness: 0.85,
|
|
493
|
+
complexity: 0.7
|
|
494
|
+
}
|
|
495
|
+
},
|
|
496
|
+
architecture: {
|
|
497
|
+
requiredFields: [
|
|
498
|
+
'systemDesign',
|
|
499
|
+
'components',
|
|
500
|
+
'designPatterns'
|
|
501
|
+
],
|
|
502
|
+
qualityThresholds: {
|
|
503
|
+
modularity: 0.8,
|
|
504
|
+
scalability: 0.75
|
|
505
|
+
}
|
|
506
|
+
},
|
|
507
|
+
refinement: {
|
|
508
|
+
requiredFields: [
|
|
509
|
+
'testResults',
|
|
510
|
+
'codeQuality',
|
|
511
|
+
'implementations'
|
|
512
|
+
],
|
|
513
|
+
qualityThresholds: {
|
|
514
|
+
testCoverage: 0.8,
|
|
515
|
+
codeQuality: 0.75
|
|
516
|
+
}
|
|
517
|
+
},
|
|
518
|
+
completion: {
|
|
519
|
+
requiredFields: [
|
|
520
|
+
'validation',
|
|
521
|
+
'deployment',
|
|
522
|
+
'documentation'
|
|
523
|
+
],
|
|
524
|
+
qualityThresholds: {
|
|
525
|
+
completeness: 0.9,
|
|
526
|
+
readiness: 0.85
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
};
|
|
530
|
+
return criteria[phaseName] || {
|
|
531
|
+
requiredFields: [],
|
|
532
|
+
qualityThresholds: {}
|
|
533
|
+
};
|
|
534
|
+
}
|
|
535
|
+
/**
|
|
534
536
|
* Update agent performance metrics
|
|
535
|
-
*/
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
await this.executeSwarmHook('update_agent_performance', {
|
|
557
|
-
agentId: agent.id,
|
|
558
|
-
performance: agent.performance,
|
|
559
|
-
phase: phaseName,
|
|
560
|
-
});
|
|
537
|
+
*/ async updateAgentPerformance(phaseName, result, validation) {
|
|
538
|
+
const phaseAgents = this.phaseAgents.get(phaseName) || [];
|
|
539
|
+
for (const agent of phaseAgents){
|
|
540
|
+
agent.performance.tasksCompleted += 1;
|
|
541
|
+
// Update quality score based on validation
|
|
542
|
+
const qualityScore = validation.score / 100;
|
|
543
|
+
agent.performance.qualityScore = (agent.performance.qualityScore + qualityScore) / 2;
|
|
544
|
+
// Update efficiency based on execution time
|
|
545
|
+
const executionTime = Date.now() - this.getPhaseStartTime(phaseName);
|
|
546
|
+
const expectedTime = this.getExpectedPhaseTime(phaseName);
|
|
547
|
+
const efficiency = Math.min(1, expectedTime / executionTime);
|
|
548
|
+
agent.performance.efficiency = (agent.performance.efficiency + efficiency) / 2;
|
|
549
|
+
// Update average time
|
|
550
|
+
agent.performance.averageTime = (agent.performance.averageTime + executionTime) / 2;
|
|
551
|
+
// Store performance update
|
|
552
|
+
await this.executeSwarmHook('update_agent_performance', {
|
|
553
|
+
agentId: agent.id,
|
|
554
|
+
performance: agent.performance,
|
|
555
|
+
phase: phaseName
|
|
556
|
+
});
|
|
557
|
+
}
|
|
561
558
|
}
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
/**
|
|
559
|
+
/**
|
|
565
560
|
* Get phase start time
|
|
566
|
-
*/
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
/**
|
|
561
|
+
*/ getPhaseStartTime(phaseName) {
|
|
562
|
+
// This would typically be stored in memory or agent state
|
|
563
|
+
return Date.now() - 5 * 60 * 1000; // Default to 5 minutes ago
|
|
564
|
+
}
|
|
565
|
+
/**
|
|
573
566
|
* Get expected phase execution time
|
|
574
|
-
*/
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
}
|
|
586
|
-
|
|
587
|
-
/**
|
|
567
|
+
*/ getExpectedPhaseTime(phaseName) {
|
|
568
|
+
const expectedTimes = {
|
|
569
|
+
specification: 10 * 60 * 1000,
|
|
570
|
+
pseudocode: 5 * 60 * 1000,
|
|
571
|
+
architecture: 15 * 60 * 1000,
|
|
572
|
+
refinement: 20 * 60 * 1000,
|
|
573
|
+
completion: 10 * 60 * 1000
|
|
574
|
+
};
|
|
575
|
+
return expectedTimes[phaseName] || 10 * 60 * 1000;
|
|
576
|
+
}
|
|
577
|
+
/**
|
|
588
578
|
* Record neural learning from phase execution
|
|
589
|
-
*/
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
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
|
-
console.log(`🧠 Neural learning recorded for ${phaseName}`);
|
|
624
|
-
} catch (error) {
|
|
625
|
-
console.warn(`⚠️ Neural learning failed: ${error.message}`);
|
|
579
|
+
*/ async recordNeuralLearning(phaseName, result, validation) {
|
|
580
|
+
try {
|
|
581
|
+
const learningData = {
|
|
582
|
+
phase: phaseName,
|
|
583
|
+
taskType: this.classifyTaskType(),
|
|
584
|
+
methodology: 'sparc',
|
|
585
|
+
execution: {
|
|
586
|
+
result: result,
|
|
587
|
+
validation: validation,
|
|
588
|
+
timestamp: Date.now()
|
|
589
|
+
},
|
|
590
|
+
context: {
|
|
591
|
+
taskDescription: this.options.taskDescription,
|
|
592
|
+
neuralContext: this.neuralContext,
|
|
593
|
+
agentPerformance: this.getAgentPerformanceData(phaseName)
|
|
594
|
+
},
|
|
595
|
+
outcomes: {
|
|
596
|
+
success: validation.passed,
|
|
597
|
+
quality: validation.score,
|
|
598
|
+
efficiency: this.calculatePhaseEfficiency(phaseName),
|
|
599
|
+
learnings: this.extractLearnings(phaseName, result, validation)
|
|
600
|
+
}
|
|
601
|
+
};
|
|
602
|
+
await this.executeSwarmHook('neural_record_learning', learningData);
|
|
603
|
+
// Train neural patterns based on this execution
|
|
604
|
+
await this.executeSwarmHook('neural_train', {
|
|
605
|
+
data: learningData,
|
|
606
|
+
updateWeights: true,
|
|
607
|
+
savePattern: true
|
|
608
|
+
});
|
|
609
|
+
console.log(`🧠 Neural learning recorded for ${phaseName}`);
|
|
610
|
+
} catch (error) {
|
|
611
|
+
console.warn(`⚠️ Neural learning failed: ${error.message}`);
|
|
612
|
+
}
|
|
626
613
|
}
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
/**
|
|
614
|
+
/**
|
|
630
615
|
* Get agent performance data for phase
|
|
631
|
-
*/
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
}
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
/**
|
|
616
|
+
*/ getAgentPerformanceData(phaseName) {
|
|
617
|
+
const phaseAgents = this.phaseAgents.get(phaseName) || [];
|
|
618
|
+
return phaseAgents.map((agent)=>({
|
|
619
|
+
id: agent.id,
|
|
620
|
+
type: agent.type,
|
|
621
|
+
performance: agent.performance
|
|
622
|
+
}));
|
|
623
|
+
}
|
|
624
|
+
/**
|
|
642
625
|
* Calculate phase efficiency
|
|
643
|
-
*/
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
const avgEfficiency =
|
|
649
|
-
phaseAgents.reduce((sum, agent) => sum + agent.performance.efficiency, 0) /
|
|
650
|
-
phaseAgents.length;
|
|
651
|
-
return avgEfficiency;
|
|
652
|
-
}
|
|
653
|
-
|
|
654
|
-
/**
|
|
655
|
-
* Extract learnings from phase execution
|
|
656
|
-
*/
|
|
657
|
-
extractLearnings(phaseName, result, validation) {
|
|
658
|
-
const learnings = [];
|
|
659
|
-
|
|
660
|
-
if (validation.passed) {
|
|
661
|
-
learnings.push(`${phaseName} phase executed successfully`);
|
|
662
|
-
if (validation.score > 90) {
|
|
663
|
-
learnings.push(`High quality output achieved in ${phaseName}`);
|
|
664
|
-
}
|
|
665
|
-
} else {
|
|
666
|
-
learnings.push(`${phaseName} phase encountered issues: ${validation.issues.join(', ')}`);
|
|
626
|
+
*/ calculatePhaseEfficiency(phaseName) {
|
|
627
|
+
const phaseAgents = this.phaseAgents.get(phaseName) || [];
|
|
628
|
+
if (phaseAgents.length === 0) return 0.5;
|
|
629
|
+
const avgEfficiency = phaseAgents.reduce((sum, agent)=>sum + agent.performance.efficiency, 0) / phaseAgents.length;
|
|
630
|
+
return avgEfficiency;
|
|
667
631
|
}
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
632
|
+
/**
|
|
633
|
+
* Extract learnings from phase execution
|
|
634
|
+
*/ extractLearnings(phaseName, result, validation) {
|
|
635
|
+
const learnings = [];
|
|
636
|
+
if (validation.passed) {
|
|
637
|
+
learnings.push(`${phaseName} phase executed successfully`);
|
|
638
|
+
if (validation.score > 90) {
|
|
639
|
+
learnings.push(`High quality output achieved in ${phaseName}`);
|
|
640
|
+
}
|
|
641
|
+
} else {
|
|
642
|
+
learnings.push(`${phaseName} phase encountered issues: ${validation.issues.join(', ')}`);
|
|
643
|
+
}
|
|
644
|
+
if (validation.recommendations.length > 0) {
|
|
645
|
+
learnings.push(`Recommendations for ${phaseName}: ${validation.recommendations.join(', ')}`);
|
|
646
|
+
}
|
|
647
|
+
return learnings;
|
|
671
648
|
}
|
|
672
|
-
|
|
673
|
-
return learnings;
|
|
674
|
-
}
|
|
675
|
-
|
|
676
|
-
/**
|
|
649
|
+
/**
|
|
677
650
|
* Prepare handoff to next phase
|
|
678
|
-
*/
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
context: result,
|
|
701
|
-
});
|
|
651
|
+
*/ async preparePhaseHandoff(phaseName, result) {
|
|
652
|
+
const nextPhase = this.getNextPhase(phaseName);
|
|
653
|
+
if (!nextPhase) return;
|
|
654
|
+
// Prepare artifacts for next phase
|
|
655
|
+
await this.executeSwarmHook('prepare_handoff', {
|
|
656
|
+
fromPhase: phaseName,
|
|
657
|
+
toPhase: nextPhase,
|
|
658
|
+
artifacts: {
|
|
659
|
+
outputs: result,
|
|
660
|
+
decisions: this.extractDecisions(result),
|
|
661
|
+
context: this.neuralContext
|
|
662
|
+
}
|
|
663
|
+
});
|
|
664
|
+
// Pre-warm next phase agents
|
|
665
|
+
const nextPhaseAgents = this.phaseAgents.get(nextPhase) || [];
|
|
666
|
+
for (const agent of nextPhaseAgents){
|
|
667
|
+
await this.executeSwarmHook('agent_prewarm', {
|
|
668
|
+
agentId: agent.id,
|
|
669
|
+
phase: nextPhase,
|
|
670
|
+
context: result
|
|
671
|
+
});
|
|
672
|
+
}
|
|
702
673
|
}
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
/**
|
|
674
|
+
/**
|
|
706
675
|
* Get next phase in SPARC sequence
|
|
707
|
-
*/
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
676
|
+
*/ getNextPhase(currentPhase) {
|
|
677
|
+
const sequence = [
|
|
678
|
+
'specification',
|
|
679
|
+
'pseudocode',
|
|
680
|
+
'architecture',
|
|
681
|
+
'refinement',
|
|
682
|
+
'completion'
|
|
683
|
+
];
|
|
684
|
+
const currentIndex = sequence.indexOf(currentPhase);
|
|
685
|
+
return currentIndex >= 0 && currentIndex < sequence.length - 1 ? sequence[currentIndex + 1] : null;
|
|
686
|
+
}
|
|
687
|
+
/**
|
|
717
688
|
* Extract decisions from phase result
|
|
718
|
-
*/
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
rationale: gate.rationale || 'Quality assurance',
|
|
735
|
-
impact: gate.impact || 'process',
|
|
736
|
-
})),
|
|
737
|
-
);
|
|
689
|
+
*/ extractDecisions(result) {
|
|
690
|
+
const decisions = [];
|
|
691
|
+
if (result.architecturalDecisions) {
|
|
692
|
+
decisions.push(...result.architecturalDecisions);
|
|
693
|
+
}
|
|
694
|
+
if (result.designDecisions) {
|
|
695
|
+
decisions.push(...result.designDecisions);
|
|
696
|
+
}
|
|
697
|
+
if (result.qualityGates) {
|
|
698
|
+
decisions.push(...result.qualityGates.map((gate)=>({
|
|
699
|
+
decision: `Quality gate: ${gate.name}`,
|
|
700
|
+
rationale: gate.rationale || 'Quality assurance',
|
|
701
|
+
impact: gate.impact || 'process'
|
|
702
|
+
})));
|
|
703
|
+
}
|
|
704
|
+
return decisions;
|
|
738
705
|
}
|
|
739
|
-
|
|
740
|
-
return decisions;
|
|
741
|
-
}
|
|
742
|
-
|
|
743
|
-
/**
|
|
706
|
+
/**
|
|
744
707
|
* Update coordination metrics
|
|
745
|
-
*/
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
708
|
+
*/ updateCoordinationMetrics(phaseName, result, validation) {
|
|
709
|
+
this.metrics.phaseExecutions += 1;
|
|
710
|
+
// Update agent utilization
|
|
711
|
+
const phaseAgents = this.phaseAgents.get(phaseName) || [];
|
|
712
|
+
for (const agent of phaseAgents){
|
|
713
|
+
if (!this.metrics.agentUtilization[agent.id]) {
|
|
714
|
+
this.metrics.agentUtilization[agent.id] = {
|
|
715
|
+
phases: 0,
|
|
716
|
+
totalTime: 0,
|
|
717
|
+
quality: 0
|
|
718
|
+
};
|
|
719
|
+
}
|
|
720
|
+
this.metrics.agentUtilization[agent.id].phases += 1;
|
|
721
|
+
this.metrics.agentUtilization[agent.id].quality += validation.score;
|
|
722
|
+
}
|
|
723
|
+
// Update coordination efficiency
|
|
724
|
+
const efficiency = this.calculatePhaseEfficiency(phaseName);
|
|
725
|
+
this.metrics.coordinationEfficiency = (this.metrics.coordinationEfficiency + efficiency) / 2;
|
|
726
|
+
// Record quality gate
|
|
727
|
+
this.metrics.qualityGates.push({
|
|
728
|
+
phase: phaseName,
|
|
729
|
+
passed: validation.passed,
|
|
730
|
+
score: validation.score,
|
|
731
|
+
timestamp: Date.now()
|
|
732
|
+
});
|
|
733
|
+
// Record learning data
|
|
734
|
+
if (validation.passed) {
|
|
735
|
+
this.metrics.learningData.push({
|
|
736
|
+
phase: phaseName,
|
|
737
|
+
success: true,
|
|
738
|
+
quality: validation.score,
|
|
739
|
+
patterns: this.neuralContext?.patterns || []
|
|
740
|
+
});
|
|
741
|
+
}
|
|
779
742
|
}
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
/**
|
|
743
|
+
/**
|
|
783
744
|
* Finalize coordination
|
|
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
|
-
preserveData: true,
|
|
816
|
-
});
|
|
817
|
-
|
|
818
|
-
console.log('✅ SPARC coordination finalized');
|
|
819
|
-
} catch (error) {
|
|
820
|
-
console.warn(`⚠️ Coordination finalization failed: ${error.message}`);
|
|
745
|
+
*/ async finalize() {
|
|
746
|
+
if (!this.swarmEnabled) return;
|
|
747
|
+
console.log('🏁 Finalizing SPARC coordination');
|
|
748
|
+
try {
|
|
749
|
+
// Generate coordination report
|
|
750
|
+
const report = await this.generateCoordinationReport();
|
|
751
|
+
// Store final metrics
|
|
752
|
+
await this.executeSwarmHook('memory_store', {
|
|
753
|
+
key: 'sparc_coordination_final',
|
|
754
|
+
value: {
|
|
755
|
+
metrics: this.metrics,
|
|
756
|
+
report: report,
|
|
757
|
+
timestamp: Date.now()
|
|
758
|
+
}
|
|
759
|
+
});
|
|
760
|
+
// Shutdown agents
|
|
761
|
+
for (const agent of this.agents){
|
|
762
|
+
await this.executeSwarmHook('agent_shutdown', {
|
|
763
|
+
agentId: agent.id,
|
|
764
|
+
graceful: true
|
|
765
|
+
});
|
|
766
|
+
}
|
|
767
|
+
// Shutdown swarm
|
|
768
|
+
await this.executeSwarmHook('swarm_shutdown', {
|
|
769
|
+
swarmId: this.swarmId,
|
|
770
|
+
preserveData: true
|
|
771
|
+
});
|
|
772
|
+
console.log('✅ SPARC coordination finalized');
|
|
773
|
+
} catch (error) {
|
|
774
|
+
console.warn(`⚠️ Coordination finalization failed: ${error.message}`);
|
|
775
|
+
}
|
|
821
776
|
}
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
/**
|
|
777
|
+
/**
|
|
825
778
|
* Generate coordination report
|
|
826
|
-
*/
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
}
|
|
844
|
-
|
|
845
|
-
/**
|
|
779
|
+
*/ async generateCoordinationReport() {
|
|
780
|
+
const report = {
|
|
781
|
+
summary: {
|
|
782
|
+
phasesExecuted: this.metrics.phaseExecutions,
|
|
783
|
+
agentsUtilized: Object.keys(this.metrics.agentUtilization).length,
|
|
784
|
+
coordinationEfficiency: this.metrics.coordinationEfficiency,
|
|
785
|
+
qualityGatesPassed: this.metrics.qualityGates.filter((g)=>g.passed).length,
|
|
786
|
+
totalQualityGates: this.metrics.qualityGates.length
|
|
787
|
+
},
|
|
788
|
+
agentPerformance: this.calculateAgentPerformanceSummary(),
|
|
789
|
+
phaseAnalysis: this.analyzePhasePerformance(),
|
|
790
|
+
recommendations: this.generateRecommendations(),
|
|
791
|
+
neuralInsights: this.extractNeuralInsights()
|
|
792
|
+
};
|
|
793
|
+
return report;
|
|
794
|
+
}
|
|
795
|
+
/**
|
|
846
796
|
* Calculate agent performance summary
|
|
847
|
-
*/
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
797
|
+
*/ calculateAgentPerformanceSummary() {
|
|
798
|
+
const summary = {};
|
|
799
|
+
for (const agent of this.agents){
|
|
800
|
+
summary[agent.id] = {
|
|
801
|
+
type: agent.type,
|
|
802
|
+
role: agent.role,
|
|
803
|
+
tasksCompleted: agent.performance.tasksCompleted,
|
|
804
|
+
averageQuality: agent.performance.qualityScore,
|
|
805
|
+
efficiency: agent.performance.efficiency,
|
|
806
|
+
averageTime: agent.performance.averageTime
|
|
807
|
+
};
|
|
808
|
+
}
|
|
809
|
+
return summary;
|
|
860
810
|
}
|
|
861
|
-
|
|
862
|
-
return summary;
|
|
863
|
-
}
|
|
864
|
-
|
|
865
|
-
/**
|
|
811
|
+
/**
|
|
866
812
|
* Analyze phase performance
|
|
867
|
-
*/
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
analysis[phase].averageScore = analysis[phase].totalScore / analysis[phase].executions;
|
|
889
|
-
analysis[phase].successRate = analysis[phase].passed / analysis[phase].executions;
|
|
813
|
+
*/ analyzePhasePerformance() {
|
|
814
|
+
const analysis = {};
|
|
815
|
+
for (const gate of this.metrics.qualityGates){
|
|
816
|
+
if (!analysis[gate.phase]) {
|
|
817
|
+
analysis[gate.phase] = {
|
|
818
|
+
executions: 0,
|
|
819
|
+
passed: 0,
|
|
820
|
+
averageScore: 0,
|
|
821
|
+
totalScore: 0
|
|
822
|
+
};
|
|
823
|
+
}
|
|
824
|
+
analysis[gate.phase].executions += 1;
|
|
825
|
+
if (gate.passed) analysis[gate.phase].passed += 1;
|
|
826
|
+
analysis[gate.phase].totalScore += gate.score;
|
|
827
|
+
}
|
|
828
|
+
// Calculate averages
|
|
829
|
+
for (const phase of Object.keys(analysis)){
|
|
830
|
+
analysis[phase].averageScore = analysis[phase].totalScore / analysis[phase].executions;
|
|
831
|
+
analysis[phase].successRate = analysis[phase].passed / analysis[phase].executions;
|
|
832
|
+
}
|
|
833
|
+
return analysis;
|
|
890
834
|
}
|
|
891
|
-
|
|
892
|
-
return analysis;
|
|
893
|
-
}
|
|
894
|
-
|
|
895
|
-
/**
|
|
835
|
+
/**
|
|
896
836
|
* Generate recommendations for improvement
|
|
897
|
-
*/
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
// Analyze quality gates
|
|
918
|
-
const qualityGateSuccess =
|
|
919
|
-
this.metrics.qualityGates.filter((g) => g.passed).length / this.metrics.qualityGates.length;
|
|
920
|
-
if (qualityGateSuccess < 0.8) {
|
|
921
|
-
recommendations.push('Review quality gate criteria and provide additional agent training');
|
|
837
|
+
*/ generateRecommendations() {
|
|
838
|
+
const recommendations = [];
|
|
839
|
+
// Analyze agent utilization
|
|
840
|
+
const avgUtilization = Object.values(this.metrics.agentUtilization).reduce((sum, agent)=>sum + agent.phases, 0) / Object.keys(this.metrics.agentUtilization).length;
|
|
841
|
+
if (avgUtilization < 2) {
|
|
842
|
+
recommendations.push('Consider reducing agent count for better utilization');
|
|
843
|
+
} else if (avgUtilization > 4) {
|
|
844
|
+
recommendations.push('Consider increasing agent count to distribute load');
|
|
845
|
+
}
|
|
846
|
+
// Analyze coordination efficiency
|
|
847
|
+
if (this.metrics.coordinationEfficiency < 0.7) {
|
|
848
|
+
recommendations.push('Improve coordination efficiency through better task decomposition');
|
|
849
|
+
}
|
|
850
|
+
// Analyze quality gates
|
|
851
|
+
const qualityGateSuccess = this.metrics.qualityGates.filter((g)=>g.passed).length / this.metrics.qualityGates.length;
|
|
852
|
+
if (qualityGateSuccess < 0.8) {
|
|
853
|
+
recommendations.push('Review quality gate criteria and provide additional agent training');
|
|
854
|
+
}
|
|
855
|
+
return recommendations;
|
|
922
856
|
}
|
|
923
|
-
|
|
924
|
-
return recommendations;
|
|
925
|
-
}
|
|
926
|
-
|
|
927
|
-
/**
|
|
857
|
+
/**
|
|
928
858
|
* Extract neural insights
|
|
929
|
-
*/
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
insights.push('High quality outcomes consistently achieved');
|
|
945
|
-
} else if (avgQuality < 70) {
|
|
946
|
-
insights.push('Quality improvements needed in execution');
|
|
859
|
+
*/ extractNeuralInsights() {
|
|
860
|
+
const insights = [];
|
|
861
|
+
// Pattern analysis
|
|
862
|
+
const successfulPatterns = this.metrics.learningData.filter((d)=>d.success);
|
|
863
|
+
if (successfulPatterns.length > 0) {
|
|
864
|
+
insights.push(`${successfulPatterns.length} successful execution patterns identified`);
|
|
865
|
+
}
|
|
866
|
+
// Quality analysis
|
|
867
|
+
const avgQuality = this.metrics.learningData.reduce((sum, d)=>sum + d.quality, 0) / this.metrics.learningData.length;
|
|
868
|
+
if (avgQuality > 85) {
|
|
869
|
+
insights.push('High quality outcomes consistently achieved');
|
|
870
|
+
} else if (avgQuality < 70) {
|
|
871
|
+
insights.push('Quality improvements needed in execution');
|
|
872
|
+
}
|
|
873
|
+
return insights;
|
|
947
874
|
}
|
|
948
|
-
|
|
949
|
-
return insights;
|
|
950
|
-
}
|
|
951
|
-
|
|
952
|
-
/**
|
|
875
|
+
/**
|
|
953
876
|
* Execute swarm hook with error handling
|
|
954
|
-
*/
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
877
|
+
*/ async executeSwarmHook(hookName, data = {}) {
|
|
878
|
+
if (!this.swarmEnabled) {
|
|
879
|
+
throw new Error('Swarm not enabled');
|
|
880
|
+
}
|
|
881
|
+
try {
|
|
882
|
+
const { spawn } = await import("child_process");
|
|
883
|
+
return new Promise((resolve, reject)=>{
|
|
884
|
+
const args = [
|
|
885
|
+
'ruv-swarm',
|
|
886
|
+
'hook',
|
|
887
|
+
hookName
|
|
888
|
+
];
|
|
889
|
+
// Add data as JSON argument
|
|
890
|
+
if (Object.keys(data).length > 0) {
|
|
891
|
+
args.push('--data', JSON.stringify(data));
|
|
892
|
+
}
|
|
893
|
+
const process = spawn('npx', args, {
|
|
894
|
+
stdio: 'pipe'
|
|
895
|
+
});
|
|
896
|
+
let output = '';
|
|
897
|
+
let error = '';
|
|
898
|
+
process.stdout.on('data', (data)=>{
|
|
899
|
+
output += data.toString();
|
|
900
|
+
});
|
|
901
|
+
process.stderr.on('data', (data)=>{
|
|
902
|
+
error += data.toString();
|
|
903
|
+
});
|
|
904
|
+
process.on('close', (code)=>{
|
|
905
|
+
if (code === 0) {
|
|
906
|
+
try {
|
|
907
|
+
const result = JSON.parse(output);
|
|
908
|
+
resolve(result);
|
|
909
|
+
} catch (parseError) {
|
|
910
|
+
resolve(output.trim());
|
|
911
|
+
}
|
|
912
|
+
} else {
|
|
913
|
+
reject(new Error(`Hook ${hookName} failed: ${error}`));
|
|
914
|
+
}
|
|
915
|
+
});
|
|
916
|
+
process.on('error', (err)=>{
|
|
917
|
+
reject(err);
|
|
918
|
+
});
|
|
919
|
+
});
|
|
920
|
+
} catch (error) {
|
|
921
|
+
throw new Error(`Failed to execute swarm hook ${hookName}: ${error.message}`);
|
|
969
922
|
}
|
|
970
|
-
|
|
971
|
-
const process = spawn('npx', args, {
|
|
972
|
-
stdio: 'pipe',
|
|
973
|
-
});
|
|
974
|
-
|
|
975
|
-
let output = '';
|
|
976
|
-
let error = '';
|
|
977
|
-
|
|
978
|
-
process.stdout.on('data', (data) => {
|
|
979
|
-
output += data.toString();
|
|
980
|
-
});
|
|
981
|
-
|
|
982
|
-
process.stderr.on('data', (data) => {
|
|
983
|
-
error += data.toString();
|
|
984
|
-
});
|
|
985
|
-
|
|
986
|
-
process.on('close', (code) => {
|
|
987
|
-
if (code === 0) {
|
|
988
|
-
try {
|
|
989
|
-
const result = JSON.parse(output);
|
|
990
|
-
resolve(result);
|
|
991
|
-
} catch (parseError) {
|
|
992
|
-
resolve(output.trim());
|
|
993
|
-
}
|
|
994
|
-
} else {
|
|
995
|
-
reject(new Error(`Hook ${hookName} failed: ${error}`));
|
|
996
|
-
}
|
|
997
|
-
});
|
|
998
|
-
|
|
999
|
-
process.on('error', (err) => {
|
|
1000
|
-
reject(err);
|
|
1001
|
-
});
|
|
1002
|
-
});
|
|
1003
|
-
} catch (error) {
|
|
1004
|
-
throw new Error(`Failed to execute swarm hook ${hookName}: ${error.message}`);
|
|
1005
923
|
}
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
/**
|
|
924
|
+
/**
|
|
1009
925
|
* Record learning from SPARC execution
|
|
1010
|
-
*/
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
console.warn(`⚠️ Failed to record learning: ${error.message}`);
|
|
926
|
+
*/ async recordLearning(learningData) {
|
|
927
|
+
if (!this.options.neuralLearning) return;
|
|
928
|
+
try {
|
|
929
|
+
await this.executeSwarmHook('neural_record_learning', {
|
|
930
|
+
methodology: 'sparc',
|
|
931
|
+
data: learningData,
|
|
932
|
+
timestamp: Date.now()
|
|
933
|
+
});
|
|
934
|
+
} catch (error) {
|
|
935
|
+
console.warn(`⚠️ Failed to record learning: ${error.message}`);
|
|
936
|
+
}
|
|
1022
937
|
}
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
/**
|
|
938
|
+
/**
|
|
1026
939
|
* Get coordination status
|
|
1027
|
-
*/
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
940
|
+
*/ getStatus() {
|
|
941
|
+
return {
|
|
942
|
+
swarmEnabled: this.swarmEnabled,
|
|
943
|
+
swarmId: this.swarmId,
|
|
944
|
+
agentCount: this.agents.length,
|
|
945
|
+
phaseAgents: Object.fromEntries(Array.from(this.phaseAgents.entries()).map(([phase, agents])=>[
|
|
946
|
+
phase,
|
|
947
|
+
agents.map((a)=>({
|
|
948
|
+
id: a.id,
|
|
949
|
+
type: a.type,
|
|
950
|
+
status: a.status
|
|
951
|
+
}))
|
|
952
|
+
])),
|
|
953
|
+
metrics: this.metrics,
|
|
954
|
+
coordination: this.coordination
|
|
955
|
+
};
|
|
956
|
+
}
|
|
957
|
+
constructor(phases, options = {}){
|
|
958
|
+
this.phases = phases;
|
|
959
|
+
this.options = options;
|
|
960
|
+
this.swarmId = null;
|
|
961
|
+
this.agents = [];
|
|
962
|
+
this.phaseAgents = new Map();
|
|
963
|
+
this.coordination = {
|
|
964
|
+
strategy: 'adaptive',
|
|
965
|
+
topology: 'hierarchical',
|
|
966
|
+
communication: 'event-driven',
|
|
967
|
+
loadBalancing: 'capability-based'
|
|
968
|
+
};
|
|
969
|
+
this.metrics = {
|
|
970
|
+
phaseExecutions: 0,
|
|
971
|
+
agentUtilization: {},
|
|
972
|
+
coordinationEfficiency: 0,
|
|
973
|
+
qualityGates: [],
|
|
974
|
+
learningData: []
|
|
975
|
+
};
|
|
976
|
+
this.neuralContext = null;
|
|
977
|
+
this.swarmEnabled = options.swarmEnabled || false;
|
|
978
|
+
}
|
|
1043
979
|
}
|
|
1044
|
-
|
|
1045
980
|
export default SparcCoordinator;
|