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.
Files changed (272) hide show
  1. package/dist/src/cli/commands/guidance.js +487 -668
  2. package/dist/src/cli/commands/index-validate.js +18 -29
  3. package/dist/src/cli/commands/mcp-troubleshoot.js +230 -282
  4. package/dist/src/cli/commands/neural-goal-init.js +92 -125
  5. package/dist/src/cli/commands/swarm-exec.js +317 -393
  6. package/dist/src/cli/commands/swarm.js +1 -1
  7. package/dist/src/cli/commands/validate-framework.js +983 -1100
  8. package/dist/src/cli/commands/validate.js +144 -223
  9. package/dist/src/cli/simple-commands/__tests__/agent.test.js +265 -277
  10. package/dist/src/cli/simple-commands/__tests__/memory.test.js +6 -7
  11. package/dist/src/cli/simple-commands/__tests__/swarm.test.js +373 -356
  12. package/dist/src/cli/simple-commands/__tests__/task.test.js +6 -7
  13. package/dist/src/cli/simple-commands/agent.js +157 -193
  14. package/dist/src/cli/simple-commands/analysis.js +336 -446
  15. package/dist/src/cli/simple-commands/automation-executor.js +1095 -1339
  16. package/dist/src/cli/simple-commands/automation.js +481 -469
  17. package/dist/src/cli/simple-commands/batch-manager.js +261 -313
  18. package/dist/src/cli/simple-commands/claude-telemetry.js +241 -267
  19. package/dist/src/cli/simple-commands/claude-track.js +68 -90
  20. package/dist/src/cli/simple-commands/concurrent-display.js +266 -320
  21. package/dist/src/cli/simple-commands/config.js +245 -290
  22. package/dist/src/cli/simple-commands/coordination.js +182 -234
  23. package/dist/src/cli/simple-commands/enhanced-ui-views.js +812 -615
  24. package/dist/src/cli/simple-commands/enhanced-webui-complete.js +922 -981
  25. package/dist/src/cli/simple-commands/fix-hook-variables.js +274 -294
  26. package/dist/src/cli/simple-commands/github/gh-coordinator.js +378 -457
  27. package/dist/src/cli/simple-commands/github/github-api.js +535 -574
  28. package/dist/src/cli/simple-commands/github/init.js +276 -303
  29. package/dist/src/cli/simple-commands/github.js +222 -247
  30. package/dist/src/cli/simple-commands/goal.js +51 -63
  31. package/dist/src/cli/simple-commands/hive-mind/auto-save-middleware.js +208 -278
  32. package/dist/src/cli/simple-commands/hive-mind/communication.js +601 -696
  33. package/dist/src/cli/simple-commands/hive-mind/core.js +907 -979
  34. package/dist/src/cli/simple-commands/hive-mind/db-optimizer.js +406 -655
  35. package/dist/src/cli/simple-commands/hive-mind/mcp-wrapper.js +1125 -1245
  36. package/dist/src/cli/simple-commands/hive-mind/memory.js +854 -1090
  37. package/dist/src/cli/simple-commands/hive-mind/performance-optimizer.js +459 -574
  38. package/dist/src/cli/simple-commands/hive-mind/performance-test.js +263 -347
  39. package/dist/src/cli/simple-commands/hive-mind/queen.js +727 -768
  40. package/dist/src/cli/simple-commands/hive-mind/session-manager.js +745 -1049
  41. package/dist/src/cli/simple-commands/hive-mind-optimize.js +227 -283
  42. package/dist/src/cli/simple-commands/hive-mind-wizard.js +174 -217
  43. package/dist/src/cli/simple-commands/hive-mind.js +1842 -2283
  44. package/dist/src/cli/simple-commands/hive.js +90 -79
  45. package/dist/src/cli/simple-commands/hook-safety.js +431 -521
  46. package/dist/src/cli/simple-commands/hooks/session-start-soul.js +203 -254
  47. package/dist/src/cli/simple-commands/hooks.js +1064 -1204
  48. package/dist/src/cli/simple-commands/init/agent-copier.js +294 -319
  49. package/dist/src/cli/simple-commands/init/batch-init.js +496 -562
  50. package/dist/src/cli/simple-commands/init/claude-commands/claude-flow-commands.js +13 -19
  51. package/dist/src/cli/simple-commands/init/claude-commands/optimized-claude-flow-commands.js +13 -19
  52. package/dist/src/cli/simple-commands/init/claude-commands/optimized-slash-commands.js +61 -88
  53. package/dist/src/cli/simple-commands/init/claude-commands/optimized-sparc-commands.js +125 -150
  54. package/dist/src/cli/simple-commands/init/claude-commands/slash-commands.js +42 -49
  55. package/dist/src/cli/simple-commands/init/claude-commands/sparc-commands.js +43 -61
  56. package/dist/src/cli/simple-commands/init/copy-revised-templates.js +141 -147
  57. package/dist/src/cli/simple-commands/init/executable-wrapper.js +31 -44
  58. package/dist/src/cli/simple-commands/init/gitignore-updater.js +64 -90
  59. package/dist/src/cli/simple-commands/init/help.js +104 -107
  60. package/dist/src/cli/simple-commands/init/hive-mind-init.js +509 -528
  61. package/dist/src/cli/simple-commands/init/index.js +1510 -1759
  62. package/dist/src/cli/simple-commands/init/performance-monitor.js +234 -317
  63. package/dist/src/cli/simple-commands/init/rollback/backup-manager.js +441 -504
  64. package/dist/src/cli/simple-commands/init/rollback/index.js +289 -364
  65. package/dist/src/cli/simple-commands/init/rollback/recovery-manager.js +652 -728
  66. package/dist/src/cli/simple-commands/init/rollback/rollback-executor.js +416 -481
  67. package/dist/src/cli/simple-commands/init/rollback/state-tracker.js +369 -448
  68. package/dist/src/cli/simple-commands/init/sparc/roo-readme.js +1 -2
  69. package/dist/src/cli/simple-commands/init/sparc/roomodes-config.js +122 -99
  70. package/dist/src/cli/simple-commands/init/sparc/workflows.js +32 -37
  71. package/dist/src/cli/simple-commands/init/sparc-structure.js +55 -62
  72. package/dist/src/cli/simple-commands/init/template-copier.js +421 -533
  73. package/dist/src/cli/simple-commands/init/templates/coordination-md.js +3 -6
  74. package/dist/src/cli/simple-commands/init/templates/enhanced-templates.js +344 -318
  75. package/dist/src/cli/simple-commands/init/templates/github-safe-enhanced.js +173 -218
  76. package/dist/src/cli/simple-commands/init/templates/github-safe.js +65 -75
  77. package/dist/src/cli/simple-commands/init/templates/memory-bank-md.js +3 -6
  78. package/dist/src/cli/simple-commands/init/templates/readme-files.js +2 -4
  79. package/dist/src/cli/simple-commands/init/templates/safe-hook-patterns.js +187 -230
  80. package/dist/src/cli/simple-commands/init/templates/sparc-modes.js +53 -80
  81. package/dist/src/cli/simple-commands/init/templates/verification-claude-md.js +101 -85
  82. package/dist/src/cli/simple-commands/init/validation/config-validator.js +283 -330
  83. package/dist/src/cli/simple-commands/init/validation/health-checker.js +495 -561
  84. package/dist/src/cli/simple-commands/init/validation/index.js +302 -358
  85. package/dist/src/cli/simple-commands/init/validation/mode-validator.js +308 -359
  86. package/dist/src/cli/simple-commands/init/validation/post-init-validator.js +389 -366
  87. package/dist/src/cli/simple-commands/init/validation/pre-init-validator.js +270 -268
  88. package/dist/src/cli/simple-commands/init/validation/test-runner.js +427 -447
  89. package/dist/src/cli/simple-commands/init.js +1 -2
  90. package/dist/src/cli/simple-commands/mcp-health.js +131 -158
  91. package/dist/src/cli/simple-commands/mcp-integration-layer.js +533 -634
  92. package/dist/src/cli/simple-commands/mcp.js +345 -400
  93. package/dist/src/cli/simple-commands/memory-consolidation.js +426 -537
  94. package/dist/src/cli/simple-commands/memory.js +247 -311
  95. package/dist/src/cli/simple-commands/migrate-hooks.js +39 -46
  96. package/dist/src/cli/simple-commands/monitor.js +294 -363
  97. package/dist/src/cli/simple-commands/neural.js +51 -65
  98. package/dist/src/cli/simple-commands/pair-autofix-only.js +538 -662
  99. package/dist/src/cli/simple-commands/pair-basic.js +528 -656
  100. package/dist/src/cli/simple-commands/pair-old.js +430 -543
  101. package/dist/src/cli/simple-commands/pair-working.js +615 -751
  102. package/dist/src/cli/simple-commands/pair.js +615 -751
  103. package/dist/src/cli/simple-commands/performance-hooks.js +83 -111
  104. package/dist/src/cli/simple-commands/performance-metrics.js +348 -433
  105. package/dist/src/cli/simple-commands/process-ui-enhanced.js +708 -787
  106. package/dist/src/cli/simple-commands/process-ui.js +230 -254
  107. package/dist/src/cli/simple-commands/realtime-update-system.js +525 -611
  108. package/dist/src/cli/simple-commands/sparc/architecture.js +1704 -1530
  109. package/dist/src/cli/simple-commands/sparc/commands.js +438 -516
  110. package/dist/src/cli/simple-commands/sparc/completion.js +1224 -1481
  111. package/dist/src/cli/simple-commands/sparc/coordinator.js +913 -978
  112. package/dist/src/cli/simple-commands/sparc/index.js +241 -298
  113. package/dist/src/cli/simple-commands/sparc/phase-base.js +314 -390
  114. package/dist/src/cli/simple-commands/sparc/pseudocode.js +965 -869
  115. package/dist/src/cli/simple-commands/sparc/refinement.js +980 -1273
  116. package/dist/src/cli/simple-commands/sparc/specification.js +559 -645
  117. package/dist/src/cli/simple-commands/sparc-modes/architect.js +1 -1
  118. package/dist/src/cli/simple-commands/sparc-modes/ask.js +1 -1
  119. package/dist/src/cli/simple-commands/sparc-modes/code.js +1 -1
  120. package/dist/src/cli/simple-commands/sparc-modes/debug.js +1 -1
  121. package/dist/src/cli/simple-commands/sparc-modes/devops.js +1 -1
  122. package/dist/src/cli/simple-commands/sparc-modes/docs-writer.js +1 -1
  123. package/dist/src/cli/simple-commands/sparc-modes/generic.js +1 -1
  124. package/dist/src/cli/simple-commands/sparc-modes/index.js +47 -55
  125. package/dist/src/cli/simple-commands/sparc-modes/integration.js +1 -1
  126. package/dist/src/cli/simple-commands/sparc-modes/mcp.js +1 -1
  127. package/dist/src/cli/simple-commands/sparc-modes/monitoring.js +1 -1
  128. package/dist/src/cli/simple-commands/sparc-modes/optimization.js +1 -1
  129. package/dist/src/cli/simple-commands/sparc-modes/security-review.js +1 -1
  130. package/dist/src/cli/simple-commands/sparc-modes/sparc-orchestrator.js +1 -1
  131. package/dist/src/cli/simple-commands/sparc-modes/spec-pseudocode.js +1 -1
  132. package/dist/src/cli/simple-commands/sparc-modes/supabase-admin.js +1 -1
  133. package/dist/src/cli/simple-commands/sparc-modes/swarm.js +101 -87
  134. package/dist/src/cli/simple-commands/sparc-modes/tdd.js +1 -1
  135. package/dist/src/cli/simple-commands/sparc-modes/tutorial.js +1 -1
  136. package/dist/src/cli/simple-commands/sparc.js +465 -493
  137. package/dist/src/cli/simple-commands/start-ui.js +108 -132
  138. package/dist/src/cli/simple-commands/start-wrapper.js +240 -268
  139. package/dist/src/cli/simple-commands/start.js +1 -1
  140. package/dist/src/cli/simple-commands/status.js +254 -275
  141. package/dist/src/cli/simple-commands/stream-chain-clean.js +128 -171
  142. package/dist/src/cli/simple-commands/stream-chain-fixed.js +61 -82
  143. package/dist/src/cli/simple-commands/stream-chain-real.js +267 -331
  144. package/dist/src/cli/simple-commands/stream-chain-working.js +211 -263
  145. package/dist/src/cli/simple-commands/stream-chain.js +260 -318
  146. package/dist/src/cli/simple-commands/stream-processor.js +290 -315
  147. package/dist/src/cli/simple-commands/swarm-executor.js +189 -222
  148. package/dist/src/cli/simple-commands/swarm-metrics-integration.js +208 -300
  149. package/dist/src/cli/simple-commands/swarm-ui.js +623 -703
  150. package/dist/src/cli/simple-commands/swarm-webui-integration.js +258 -286
  151. package/dist/src/cli/simple-commands/swarm.js +887 -1082
  152. package/dist/src/cli/simple-commands/task.js +161 -206
  153. package/dist/src/cli/simple-commands/timestamp-fix.js +59 -89
  154. package/dist/src/cli/simple-commands/token-tracker.js +258 -316
  155. package/dist/src/cli/simple-commands/tool-execution-framework.js +433 -519
  156. package/dist/src/cli/simple-commands/train-and-stream.js +275 -331
  157. package/dist/src/cli/simple-commands/training-pipeline.js +619 -725
  158. package/dist/src/cli/simple-commands/training.js +170 -227
  159. package/dist/src/cli/simple-commands/verification-hooks.js +261 -284
  160. package/dist/src/cli/simple-commands/verification-integration.js +389 -417
  161. package/dist/src/cli/simple-commands/verification-training-integration.js +486 -606
  162. package/dist/src/cli/simple-commands/verification.js +493 -513
  163. package/dist/src/cli/simple-commands/web-server.js +766 -836
  164. package/dist/src/cli/simple-commands/webui-validator.js +106 -124
  165. package/dist/src/coordination/event-bus/demo-wasm-integration.js +212 -251
  166. package/dist/src/coordination/event-bus/qe-event-bus.js +608 -748
  167. package/dist/src/coordination/event-bus/qe-event-bus.test.js +379 -454
  168. package/dist/src/coordination/iteration-tracker.js +363 -454
  169. package/dist/src/enterprise/analytics-manager.js +1135 -0
  170. package/dist/src/enterprise/audit-manager.js +1115 -0
  171. package/dist/src/enterprise/cloud-manager.js +891 -0
  172. package/dist/src/enterprise/deployment-manager.js +966 -0
  173. package/dist/src/enterprise/index.js +6 -0
  174. package/dist/src/enterprise/project-manager.js +584 -0
  175. package/dist/src/enterprise/security-manager.js +991 -0
  176. package/dist/src/index.js +1 -1
  177. package/dist/src/mcp/DEPRECATED.js +46 -60
  178. package/dist/src/mcp/fixes/mcp-error-fixes.js +115 -134
  179. package/dist/src/mcp/implementations/agent-tracker.js +114 -128
  180. package/dist/src/mcp/implementations/daa-tools.js +292 -350
  181. package/dist/src/mcp/implementations/workflow-tools.js +329 -361
  182. package/dist/src/mcp/mcp-config-manager.js +1183 -1331
  183. package/dist/src/mcp/mcp-server-novice-simplified.js +11 -17
  184. package/dist/src/mcp/mcp-server-novice.js +11 -17
  185. package/dist/src/mcp/mcp-server-sdk.js +11 -17
  186. package/dist/src/mcp/mcp-server.js +1620 -1484
  187. package/dist/src/mcp/ruv-swarm-wrapper.js +209 -239
  188. package/dist/src/memory/advanced-serializer.js +609 -589
  189. package/dist/src/memory/enhanced-examples.js +220 -305
  190. package/dist/src/memory/enhanced-memory.js +295 -336
  191. package/dist/src/memory/enhanced-session-serializer.js +408 -492
  192. package/dist/src/memory/fallback-memory-system.js +900 -1021
  193. package/dist/src/memory/fallback-store.js +93 -131
  194. package/dist/src/memory/high-performance-serialization.js +592 -730
  195. package/dist/src/memory/in-memory-store.js +161 -213
  196. package/dist/src/memory/index.js +123 -157
  197. package/dist/src/memory/lock-free-structures.js +578 -764
  198. package/dist/src/memory/memory-mapped-persistence.js +585 -766
  199. package/dist/src/memory/memory-pressure-manager.js +569 -707
  200. package/dist/src/memory/migration.js +358 -445
  201. package/dist/src/memory/shared-memory.js +641 -768
  202. package/dist/src/memory/sqlite-store.js +245 -325
  203. package/dist/src/memory/sqlite-wrapper.js +122 -151
  204. package/dist/src/memory/swarm-memory.js +470 -603
  205. package/dist/src/memory/test-example.js +126 -134
  206. package/dist/src/memory/ultra-fast-memory-store.js +622 -821
  207. package/dist/src/memory/unified-memory-manager.js +356 -437
  208. package/dist/src/migration/index.js +92 -0
  209. package/dist/src/migration/logger.js +121 -0
  210. package/dist/src/migration/migration-analyzer.js +268 -0
  211. package/dist/src/migration/migration-runner.js +522 -0
  212. package/dist/src/migration/migration-validator.js +285 -0
  213. package/dist/src/migration/progress-reporter.js +150 -0
  214. package/dist/src/migration/rollback-manager.js +321 -0
  215. package/dist/src/migration/tests/migration-system.test.js +7 -0
  216. package/dist/src/migration/types.js +3 -0
  217. package/dist/src/swarm/CodeRefactoringSwarm.js +777 -952
  218. package/dist/src/swarm/__tests__/integration.test.js +227 -0
  219. package/dist/src/swarm/__tests__/prompt-copier.test.js +344 -0
  220. package/dist/src/swarm/advanced-orchestrator.js +1095 -0
  221. package/dist/src/swarm/claude-code-interface.js +961 -0
  222. package/dist/src/swarm/claude-flow-executor.js +229 -0
  223. package/dist/src/swarm/consensus-coordinator.js +475 -0
  224. package/dist/src/swarm/coordinator.js +2993 -0
  225. package/dist/src/swarm/direct-executor.js +1180 -0
  226. package/dist/src/swarm/error-recovery/advanced-error-detection.js +691 -0
  227. package/dist/src/swarm/error-recovery/automated-recovery-workflows.js +998 -0
  228. package/dist/src/swarm/error-recovery/error-recovery-coordinator.js +1197 -0
  229. package/dist/src/swarm/error-recovery/recovery-monitoring.js +772 -0
  230. package/dist/src/swarm/error-recovery/resilience-architecture.js +714 -0
  231. package/dist/src/swarm/error-recovery/self-healing-mechanisms.js +1319 -0
  232. package/dist/src/swarm/error-recovery/test-error-recovery-effectiveness.js +808 -0
  233. package/dist/src/swarm/executor-v2.js +322 -0
  234. package/dist/src/swarm/executor.js +815 -0
  235. package/dist/src/swarm/hive-mind-integration.js +703 -0
  236. package/dist/src/swarm/index.js +41 -0
  237. package/dist/src/swarm/json-output-aggregator.js +267 -0
  238. package/dist/src/swarm/large-scale-coordinator.js +542 -0
  239. package/dist/src/swarm/mcp-integration-wrapper.js +628 -0
  240. package/dist/src/swarm/memory.js +1117 -0
  241. package/dist/src/swarm/optimizations/__tests__/optimization.test.js +348 -0
  242. package/dist/src/swarm/optimizations/async-file-manager.js +285 -0
  243. package/dist/src/swarm/optimizations/circular-buffer.js +162 -0
  244. package/dist/src/swarm/optimizations/connection-pool.js +244 -0
  245. package/dist/src/swarm/optimizations/index.js +28 -0
  246. package/dist/src/swarm/optimizations/optimized-executor.js +320 -0
  247. package/dist/src/swarm/optimizations/ttl-map.js +234 -0
  248. package/dist/src/swarm/prompt-cli.js +200 -0
  249. package/dist/src/swarm/prompt-copier-enhanced.js +202 -0
  250. package/dist/src/swarm/prompt-copier.js +381 -0
  251. package/dist/src/swarm/prompt-manager.js +295 -0
  252. package/dist/src/swarm/prompt-utils.js +310 -0
  253. package/dist/src/swarm/result-aggregator.js +718 -0
  254. package/dist/src/swarm/sparc-executor.js +1568 -0
  255. package/dist/src/swarm/strategies/auto.js +758 -0
  256. package/dist/src/swarm/strategies/base.js +128 -0
  257. package/dist/src/swarm/strategies/research.js +914 -0
  258. package/dist/src/swarm/strategies/strategy-metrics-patch.js +2 -0
  259. package/dist/src/swarm/types.js +52 -0
  260. package/dist/src/swarm/workers/copy-worker.js +56 -0
  261. package/dist/src/utils/__tests__/github-cli-safety-wrapper.test.js +332 -400
  262. package/dist/src/utils/github-cli-safe.js +56 -64
  263. package/dist/src/utils/github-cli-safety-wrapper.js +451 -546
  264. package/dist/src/utils/npx-isolated-cache.js +104 -119
  265. package/dist/src/utils/preference-manager.js +622 -652
  266. package/dist/src/utils/timezone-utils.js +86 -105
  267. package/dist/src/validators/epic-config-schema.js +214 -0
  268. package/dist/src/validators/index.js +10 -0
  269. package/dist/src/validators/swarm-init-validator.js +259 -0
  270. package/dist/src/validators/todowrite-batching-validator.js +215 -0
  271. package/dist/src/validators/todowrite-integration.js +187 -0
  272. package/package.json +2 -2
@@ -2,658 +2,572 @@
2
2
  * Real-time Update System for Claude-Flow Web UI
3
3
  * Provides event-driven architecture for live data updates
4
4
  * Supports WebSocket-like functionality and progressive loading
5
- */
6
-
7
- export class RealtimeUpdateSystem {
8
- constructor(ui) {
9
- this.ui = ui;
10
- this.subscribers = new Map(); // Event type -> Set of callbacks
11
- this.updateQueues = new Map(); // View -> Queue of pending updates
12
- this.updateTimers = new Map(); // View -> Timer for batched updates
13
- this.batchDelay = 100; // ms to batch updates
14
- this.eventHistory = []; // Keep last 100 events
15
- this.maxHistorySize = 100;
16
-
17
- // Performance monitoring
18
- this.updateMetrics = {
19
- totalUpdates: 0,
20
- updateLatency: [],
21
- batchedUpdates: 0,
22
- droppedUpdates: 0,
23
- };
24
-
25
- this.initializeSystem();
26
- }
27
-
28
- /**
5
+ */ export class RealtimeUpdateSystem {
6
+ /**
29
7
  * Initialize the real-time update system
30
- */
31
- initializeSystem() {
32
- // Setup system event listeners
33
- this.setupSystemEvents();
34
-
35
- // Initialize update queues for all views
36
- this.initializeUpdateQueues();
37
-
38
- // Start performance monitoring
39
- this.startPerformanceMonitoring();
40
-
41
- this.ui.addLog('success', 'Real-time update system initialized');
42
- }
43
-
44
- /**
8
+ */ initializeSystem() {
9
+ // Setup system event listeners
10
+ this.setupSystemEvents();
11
+ // Initialize update queues for all views
12
+ this.initializeUpdateQueues();
13
+ // Start performance monitoring
14
+ this.startPerformanceMonitoring();
15
+ this.ui.addLog('success', 'Real-time update system initialized');
16
+ }
17
+ /**
45
18
  * Setup system-level event listeners
46
- */
47
- setupSystemEvents() {
48
- // Listen for tool execution events
49
- this.subscribe('tool_start', (data) => {
50
- this.broadcastUpdate('tools', {
51
- type: 'execution_start',
52
- toolName: data.toolName,
53
- executionId: data.executionId,
54
- timestamp: Date.now(),
55
- });
56
- });
57
-
58
- this.subscribe('tool_complete', (data) => {
59
- this.broadcastUpdate('tools', {
60
- type: 'execution_complete',
61
- toolName: data.toolName,
62
- executionId: data.executionId,
63
- result: data.result,
64
- timestamp: Date.now(),
65
- });
66
-
67
- // Update relevant views based on tool type
68
- this.updateRelatedViews(data.toolName, data.result);
69
- });
70
-
71
- this.subscribe('tool_error', (data) => {
72
- this.broadcastUpdate('tools', {
73
- type: 'execution_error',
74
- toolName: data.toolName,
75
- executionId: data.executionId,
76
- error: data.error,
77
- timestamp: Date.now(),
78
- });
79
- });
80
-
81
- // Listen for swarm events
82
- this.subscribe('swarm_status_change', (data) => {
83
- this.broadcastUpdate('orchestration', {
84
- type: 'swarm_update',
85
- swarmId: data.swarmId,
86
- status: data.status,
87
- timestamp: Date.now(),
88
- });
89
- });
90
-
91
- // Listen for memory events
92
- this.subscribe('memory_change', (data) => {
93
- this.broadcastUpdate('memory', {
94
- type: 'memory_update',
95
- namespace: data.namespace,
96
- operation: data.operation,
97
- timestamp: Date.now(),
98
- });
99
- });
100
- }
101
-
102
- /**
19
+ */ setupSystemEvents() {
20
+ // Listen for tool execution events
21
+ this.subscribe('tool_start', (data)=>{
22
+ this.broadcastUpdate('tools', {
23
+ type: 'execution_start',
24
+ toolName: data.toolName,
25
+ executionId: data.executionId,
26
+ timestamp: Date.now()
27
+ });
28
+ });
29
+ this.subscribe('tool_complete', (data)=>{
30
+ this.broadcastUpdate('tools', {
31
+ type: 'execution_complete',
32
+ toolName: data.toolName,
33
+ executionId: data.executionId,
34
+ result: data.result,
35
+ timestamp: Date.now()
36
+ });
37
+ // Update relevant views based on tool type
38
+ this.updateRelatedViews(data.toolName, data.result);
39
+ });
40
+ this.subscribe('tool_error', (data)=>{
41
+ this.broadcastUpdate('tools', {
42
+ type: 'execution_error',
43
+ toolName: data.toolName,
44
+ executionId: data.executionId,
45
+ error: data.error,
46
+ timestamp: Date.now()
47
+ });
48
+ });
49
+ // Listen for swarm events
50
+ this.subscribe('swarm_status_change', (data)=>{
51
+ this.broadcastUpdate('orchestration', {
52
+ type: 'swarm_update',
53
+ swarmId: data.swarmId,
54
+ status: data.status,
55
+ timestamp: Date.now()
56
+ });
57
+ });
58
+ // Listen for memory events
59
+ this.subscribe('memory_change', (data)=>{
60
+ this.broadcastUpdate('memory', {
61
+ type: 'memory_update',
62
+ namespace: data.namespace,
63
+ operation: data.operation,
64
+ timestamp: Date.now()
65
+ });
66
+ });
67
+ }
68
+ /**
103
69
  * Initialize update queues for all views
104
- */
105
- initializeUpdateQueues() {
106
- const views = [
107
- 'neural',
108
- 'analysis',
109
- 'workflow',
110
- 'github',
111
- 'daa',
112
- 'system',
113
- 'tools',
114
- 'orchestration',
115
- 'memory',
116
- ];
117
- views.forEach((view) => {
118
- this.updateQueues.set(view, []);
119
- });
120
- }
121
-
122
- /**
70
+ */ initializeUpdateQueues() {
71
+ const views = [
72
+ 'neural',
73
+ 'analysis',
74
+ 'workflow',
75
+ 'github',
76
+ 'daa',
77
+ 'system',
78
+ 'tools',
79
+ 'orchestration',
80
+ 'memory'
81
+ ];
82
+ views.forEach((view)=>{
83
+ this.updateQueues.set(view, []);
84
+ });
85
+ }
86
+ /**
123
87
  * Subscribe to specific event types
124
- */
125
- subscribe(eventType, callback) {
126
- if (!this.subscribers.has(eventType)) {
127
- this.subscribers.set(eventType, new Set());
88
+ */ subscribe(eventType, callback) {
89
+ if (!this.subscribers.has(eventType)) {
90
+ this.subscribers.set(eventType, new Set());
91
+ }
92
+ this.subscribers.get(eventType).add(callback);
93
+ // Return unsubscribe function
94
+ return ()=>{
95
+ const subs = this.subscribers.get(eventType);
96
+ if (subs) {
97
+ subs.delete(callback);
98
+ }
99
+ };
128
100
  }
129
- this.subscribers.get(eventType).add(callback);
130
-
131
- // Return unsubscribe function
132
- return () => {
133
- const subs = this.subscribers.get(eventType);
134
- if (subs) {
135
- subs.delete(callback);
136
- }
137
- };
138
- }
139
-
140
- /**
101
+ /**
141
102
  * Emit event to all subscribers
142
- */
143
- emit(eventType, data) {
144
- const timestamp = Date.now();
145
-
146
- // Add to event history
147
- this.eventHistory.push({
148
- type: eventType,
149
- data,
150
- timestamp,
151
- });
152
-
153
- // Trim history if too large
154
- if (this.eventHistory.length > this.maxHistorySize) {
155
- this.eventHistory.shift();
156
- }
157
-
158
- // Notify subscribers
159
- const subscribers = this.subscribers.get(eventType);
160
- if (subscribers) {
161
- subscribers.forEach((callback) => {
162
- try {
163
- callback(data, timestamp);
164
- } catch (error) {
165
- console.error(`Error in event subscriber for ${eventType}:`, error);
103
+ */ emit(eventType, data) {
104
+ const timestamp = Date.now();
105
+ // Add to event history
106
+ this.eventHistory.push({
107
+ type: eventType,
108
+ data,
109
+ timestamp
110
+ });
111
+ // Trim history if too large
112
+ if (this.eventHistory.length > this.maxHistorySize) {
113
+ this.eventHistory.shift();
114
+ }
115
+ // Notify subscribers
116
+ const subscribers = this.subscribers.get(eventType);
117
+ if (subscribers) {
118
+ subscribers.forEach((callback)=>{
119
+ try {
120
+ callback(data, timestamp);
121
+ } catch (error) {
122
+ console.error(`Error in event subscriber for ${eventType}:`, error);
123
+ }
124
+ });
166
125
  }
167
- });
168
126
  }
169
- }
170
-
171
- /**
127
+ /**
172
128
  * Broadcast update to specific view
173
- */
174
- broadcastUpdate(viewName, updateData) {
175
- const queue = this.updateQueues.get(viewName);
176
- if (!queue) return;
177
-
178
- // Add update to queue
179
- queue.push({
180
- ...updateData,
181
- id: `update_${Date.now()}_${Math.random().toString(36).substr(2, 6)}`,
182
- });
183
-
184
- // Schedule batched update
185
- this.scheduleBatchedUpdate(viewName);
186
-
187
- this.updateMetrics.totalUpdates++;
188
- }
189
-
190
- /**
129
+ */ broadcastUpdate(viewName, updateData) {
130
+ const queue = this.updateQueues.get(viewName);
131
+ if (!queue) return;
132
+ // Add update to queue
133
+ queue.push({
134
+ ...updateData,
135
+ id: `update_${Date.now()}_${Math.random().toString(36).substr(2, 6)}`
136
+ });
137
+ // Schedule batched update
138
+ this.scheduleBatchedUpdate(viewName);
139
+ this.updateMetrics.totalUpdates++;
140
+ }
141
+ /**
191
142
  * Schedule batched update for a view
192
- */
193
- scheduleBatchedUpdate(viewName) {
194
- // Clear existing timer
195
- const existingTimer = this.updateTimers.get(viewName);
196
- if (existingTimer) {
197
- clearTimeout(existingTimer);
143
+ */ scheduleBatchedUpdate(viewName) {
144
+ // Clear existing timer
145
+ const existingTimer = this.updateTimers.get(viewName);
146
+ if (existingTimer) {
147
+ clearTimeout(existingTimer);
148
+ }
149
+ // Schedule new batched update
150
+ const timer = setTimeout(()=>{
151
+ this.processBatchedUpdates(viewName);
152
+ }, this.batchDelay);
153
+ this.updateTimers.set(viewName, timer);
198
154
  }
199
-
200
- // Schedule new batched update
201
- const timer = setTimeout(() => {
202
- this.processBatchedUpdates(viewName);
203
- }, this.batchDelay);
204
-
205
- this.updateTimers.set(viewName, timer);
206
- }
207
-
208
- /**
155
+ /**
209
156
  * Process batched updates for a view
210
- */
211
- processBatchedUpdates(viewName) {
212
- const queue = this.updateQueues.get(viewName);
213
- if (!queue || queue.length === 0) return;
214
-
215
- const startTime = Date.now();
216
-
217
- // Group updates by type
218
- const groupedUpdates = this.groupUpdatesByType(queue);
219
-
220
- // Apply updates
221
- this.applyUpdatesToView(viewName, groupedUpdates);
222
-
223
- // Clear processed updates
224
- queue.length = 0;
225
-
226
- // Update metrics
227
- const latency = Date.now() - startTime;
228
- this.updateMetrics.updateLatency.push(latency);
229
- this.updateMetrics.batchedUpdates++;
230
-
231
- // Keep only last 100 latency measurements
232
- if (this.updateMetrics.updateLatency.length > 100) {
233
- this.updateMetrics.updateLatency.shift();
157
+ */ processBatchedUpdates(viewName) {
158
+ const queue = this.updateQueues.get(viewName);
159
+ if (!queue || queue.length === 0) return;
160
+ const startTime = Date.now();
161
+ // Group updates by type
162
+ const groupedUpdates = this.groupUpdatesByType(queue);
163
+ // Apply updates
164
+ this.applyUpdatesToView(viewName, groupedUpdates);
165
+ // Clear processed updates
166
+ queue.length = 0;
167
+ // Update metrics
168
+ const latency = Date.now() - startTime;
169
+ this.updateMetrics.updateLatency.push(latency);
170
+ this.updateMetrics.batchedUpdates++;
171
+ // Keep only last 100 latency measurements
172
+ if (this.updateMetrics.updateLatency.length > 100) {
173
+ this.updateMetrics.updateLatency.shift();
174
+ }
175
+ // Clear timer
176
+ this.updateTimers.delete(viewName);
234
177
  }
235
-
236
- // Clear timer
237
- this.updateTimers.delete(viewName);
238
- }
239
-
240
- /**
178
+ /**
241
179
  * Group updates by type for efficient processing
242
- */
243
- groupUpdatesByType(updates) {
244
- const grouped = new Map();
245
-
246
- updates.forEach((update) => {
247
- if (!grouped.has(update.type)) {
248
- grouped.set(update.type, []);
249
- }
250
- grouped.get(update.type).push(update);
251
- });
252
-
253
- return grouped;
254
- }
255
-
256
- /**
180
+ */ groupUpdatesByType(updates) {
181
+ const grouped = new Map();
182
+ updates.forEach((update)=>{
183
+ if (!grouped.has(update.type)) {
184
+ grouped.set(update.type, []);
185
+ }
186
+ grouped.get(update.type).push(update);
187
+ });
188
+ return grouped;
189
+ }
190
+ /**
257
191
  * Apply grouped updates to a specific view
258
- */
259
- applyUpdatesToView(viewName, groupedUpdates) {
260
- try {
261
- // Different views handle updates differently
262
- switch (viewName) {
263
- case 'neural':
264
- this.applyNeuralUpdates(groupedUpdates);
265
- break;
266
- case 'analysis':
267
- this.applyAnalysisUpdates(groupedUpdates);
268
- break;
269
- case 'workflow':
270
- this.applyWorkflowUpdates(groupedUpdates);
271
- break;
272
- case 'tools':
273
- this.applyToolsUpdates(groupedUpdates);
274
- break;
275
- case 'orchestration':
276
- this.applyOrchestrationUpdates(groupedUpdates);
277
- break;
278
- case 'memory':
279
- this.applyMemoryUpdates(groupedUpdates);
280
- break;
281
- default:
282
- this.applyGenericUpdates(viewName, groupedUpdates);
283
- }
284
-
285
- // Trigger UI refresh if this is the current view
286
- if (this.ui.currentView === viewName) {
287
- this.requestUIRefresh();
288
- }
289
- } catch (error) {
290
- console.error(`Error applying updates to ${viewName}:`, error);
291
- this.updateMetrics.droppedUpdates++;
192
+ */ applyUpdatesToView(viewName, groupedUpdates) {
193
+ try {
194
+ // Different views handle updates differently
195
+ switch(viewName){
196
+ case 'neural':
197
+ this.applyNeuralUpdates(groupedUpdates);
198
+ break;
199
+ case 'analysis':
200
+ this.applyAnalysisUpdates(groupedUpdates);
201
+ break;
202
+ case 'workflow':
203
+ this.applyWorkflowUpdates(groupedUpdates);
204
+ break;
205
+ case 'tools':
206
+ this.applyToolsUpdates(groupedUpdates);
207
+ break;
208
+ case 'orchestration':
209
+ this.applyOrchestrationUpdates(groupedUpdates);
210
+ break;
211
+ case 'memory':
212
+ this.applyMemoryUpdates(groupedUpdates);
213
+ break;
214
+ default:
215
+ this.applyGenericUpdates(viewName, groupedUpdates);
216
+ }
217
+ // Trigger UI refresh if this is the current view
218
+ if (this.ui.currentView === viewName) {
219
+ this.requestUIRefresh();
220
+ }
221
+ } catch (error) {
222
+ console.error(`Error applying updates to ${viewName}:`, error);
223
+ this.updateMetrics.droppedUpdates++;
224
+ }
292
225
  }
293
- }
294
-
295
- /**
226
+ /**
296
227
  * Apply neural-specific updates
297
- */
298
- applyNeuralUpdates(groupedUpdates) {
299
- const neuralData = this.ui.enhancedViews?.viewData?.get('neural');
300
- if (!neuralData) return;
301
-
302
- // Handle training job updates
303
- const trainingUpdates = groupedUpdates.get('training_progress');
304
- if (trainingUpdates) {
305
- trainingUpdates.forEach((update) => {
306
- const existingJob = neuralData.trainingJobs.find((job) => job.id === update.jobId);
307
- if (existingJob) {
308
- Object.assign(existingJob, update.data);
309
- } else {
310
- neuralData.trainingJobs.push({
311
- id: update.jobId,
312
- ...update.data,
313
- startTime: update.timestamp,
314
- });
228
+ */ applyNeuralUpdates(groupedUpdates) {
229
+ const neuralData = this.ui.enhancedViews?.viewData?.get('neural');
230
+ if (!neuralData) return;
231
+ // Handle training job updates
232
+ const trainingUpdates = groupedUpdates.get('training_progress');
233
+ if (trainingUpdates) {
234
+ trainingUpdates.forEach((update)=>{
235
+ const existingJob = neuralData.trainingJobs.find((job)=>job.id === update.jobId);
236
+ if (existingJob) {
237
+ Object.assign(existingJob, update.data);
238
+ } else {
239
+ neuralData.trainingJobs.push({
240
+ id: update.jobId,
241
+ ...update.data,
242
+ startTime: update.timestamp
243
+ });
244
+ }
245
+ });
315
246
  }
316
- });
317
- }
318
-
319
- // Handle model updates
320
- const modelUpdates = groupedUpdates.get('model_update');
321
- if (modelUpdates) {
322
- modelUpdates.forEach((update) => {
323
- const existingModel = neuralData.models.find((model) => model.id === update.modelId);
324
- if (existingModel) {
325
- Object.assign(existingModel, update.data);
326
- } else {
327
- neuralData.models.push({
328
- id: update.modelId,
329
- ...update.data,
330
- createdAt: update.timestamp,
331
- });
247
+ // Handle model updates
248
+ const modelUpdates = groupedUpdates.get('model_update');
249
+ if (modelUpdates) {
250
+ modelUpdates.forEach((update)=>{
251
+ const existingModel = neuralData.models.find((model)=>model.id === update.modelId);
252
+ if (existingModel) {
253
+ Object.assign(existingModel, update.data);
254
+ } else {
255
+ neuralData.models.push({
256
+ id: update.modelId,
257
+ ...update.data,
258
+ createdAt: update.timestamp
259
+ });
260
+ }
261
+ });
332
262
  }
333
- });
334
263
  }
335
- }
336
-
337
- /**
264
+ /**
338
265
  * Apply analysis-specific updates
339
- */
340
- applyAnalysisUpdates(groupedUpdates) {
341
- const analysisData = this.ui.enhancedViews?.viewData?.get('analysis');
342
- if (!analysisData) return;
343
-
344
- // Handle performance report updates
345
- const reportUpdates = groupedUpdates.get('performance_report');
346
- if (reportUpdates) {
347
- reportUpdates.forEach((update) => {
348
- analysisData.reports.unshift({
349
- id: update.reportId || `report_${update.timestamp}`,
350
- ...update.data,
351
- timestamp: update.timestamp,
352
- });
353
-
354
- // Keep only last 50 reports
355
- if (analysisData.reports.length > 50) {
356
- analysisData.reports = analysisData.reports.slice(0, 50);
266
+ */ applyAnalysisUpdates(groupedUpdates) {
267
+ const analysisData = this.ui.enhancedViews?.viewData?.get('analysis');
268
+ if (!analysisData) return;
269
+ // Handle performance report updates
270
+ const reportUpdates = groupedUpdates.get('performance_report');
271
+ if (reportUpdates) {
272
+ reportUpdates.forEach((update)=>{
273
+ analysisData.reports.unshift({
274
+ id: update.reportId || `report_${update.timestamp}`,
275
+ ...update.data,
276
+ timestamp: update.timestamp
277
+ });
278
+ // Keep only last 50 reports
279
+ if (analysisData.reports.length > 50) {
280
+ analysisData.reports = analysisData.reports.slice(0, 50);
281
+ }
282
+ });
357
283
  }
358
- });
359
- }
360
-
361
- // Handle metrics updates
362
- const metricsUpdates = groupedUpdates.get('metrics_update');
363
- if (metricsUpdates) {
364
- metricsUpdates.forEach((update) => {
365
- analysisData.metrics.push({
366
- ...update.data,
367
- timestamp: update.timestamp,
368
- });
369
-
370
- // Keep only last 100 metric points
371
- if (analysisData.metrics.length > 100) {
372
- analysisData.metrics.shift();
284
+ // Handle metrics updates
285
+ const metricsUpdates = groupedUpdates.get('metrics_update');
286
+ if (metricsUpdates) {
287
+ metricsUpdates.forEach((update)=>{
288
+ analysisData.metrics.push({
289
+ ...update.data,
290
+ timestamp: update.timestamp
291
+ });
292
+ // Keep only last 100 metric points
293
+ if (analysisData.metrics.length > 100) {
294
+ analysisData.metrics.shift();
295
+ }
296
+ });
373
297
  }
374
- });
375
298
  }
376
- }
377
-
378
- /**
299
+ /**
379
300
  * Apply tools-specific updates
380
- */
381
- applyToolsUpdates(groupedUpdates) {
382
- // Handle execution updates
383
- const executionUpdates = groupedUpdates.get('execution_start');
384
- if (executionUpdates) {
385
- executionUpdates.forEach((update) => {
386
- this.ui.addLog('info', `🔧 Started: ${update.toolName}`);
387
- });
388
- }
389
-
390
- const completionUpdates = groupedUpdates.get('execution_complete');
391
- if (completionUpdates) {
392
- completionUpdates.forEach((update) => {
393
- this.ui.addLog('success', `✅ Completed: ${update.toolName}`);
394
-
395
- // Show result summary if available
396
- if (update.result && update.result.summary) {
397
- this.ui.addLog('info', `📋 ${update.result.summary}`);
301
+ */ applyToolsUpdates(groupedUpdates) {
302
+ // Handle execution updates
303
+ const executionUpdates = groupedUpdates.get('execution_start');
304
+ if (executionUpdates) {
305
+ executionUpdates.forEach((update)=>{
306
+ this.ui.addLog('info', `🔧 Started: ${update.toolName}`);
307
+ });
308
+ }
309
+ const completionUpdates = groupedUpdates.get('execution_complete');
310
+ if (completionUpdates) {
311
+ completionUpdates.forEach((update)=>{
312
+ this.ui.addLog('success', `✅ Completed: ${update.toolName}`);
313
+ // Show result summary if available
314
+ if (update.result && update.result.summary) {
315
+ this.ui.addLog('info', `📋 ${update.result.summary}`);
316
+ }
317
+ });
318
+ }
319
+ const errorUpdates = groupedUpdates.get('execution_error');
320
+ if (errorUpdates) {
321
+ errorUpdates.forEach((update)=>{
322
+ this.ui.addLog('error', `❌ Failed: ${update.toolName} - ${update.error}`);
323
+ });
398
324
  }
399
- });
400
- }
401
-
402
- const errorUpdates = groupedUpdates.get('execution_error');
403
- if (errorUpdates) {
404
- errorUpdates.forEach((update) => {
405
- this.ui.addLog('error', `❌ Failed: ${update.toolName} - ${update.error}`);
406
- });
407
325
  }
408
- }
409
-
410
- /**
326
+ /**
411
327
  * Apply orchestration-specific updates
412
- */
413
- applyOrchestrationUpdates(groupedUpdates) {
414
- // Handle swarm updates
415
- const swarmUpdates = groupedUpdates.get('swarm_update');
416
- if (swarmUpdates) {
417
- swarmUpdates.forEach((update) => {
418
- // Update swarm integration data
419
- if (this.ui.swarmIntegration) {
420
- this.ui.swarmIntegration.updateSwarmStatus();
328
+ */ applyOrchestrationUpdates(groupedUpdates) {
329
+ // Handle swarm updates
330
+ const swarmUpdates = groupedUpdates.get('swarm_update');
331
+ if (swarmUpdates) {
332
+ swarmUpdates.forEach((update)=>{
333
+ // Update swarm integration data
334
+ if (this.ui.swarmIntegration) {
335
+ this.ui.swarmIntegration.updateSwarmStatus();
336
+ }
337
+ this.ui.addLog('info', `🐝 Swarm ${update.swarmId}: ${update.status}`);
338
+ });
421
339
  }
422
-
423
- this.ui.addLog('info', `🐝 Swarm ${update.swarmId}: ${update.status}`);
424
- });
425
340
  }
426
- }
427
-
428
- /**
341
+ /**
429
342
  * Apply memory-specific updates
430
- */
431
- applyMemoryUpdates(groupedUpdates) {
432
- // Handle memory operation updates
433
- const memoryUpdates = groupedUpdates.get('memory_update');
434
- if (memoryUpdates) {
435
- memoryUpdates.forEach((update) => {
436
- // Update memory stats
437
- if (this.ui.memoryStats) {
438
- const namespace = this.ui.memoryStats.namespaces.find(
439
- (ns) => ns.name === update.namespace,
440
- );
441
- if (namespace) {
442
- // Update existing namespace stats
443
- if (update.operation === 'store') {
444
- namespace.entries++;
445
- } else if (update.operation === 'delete') {
446
- namespace.entries = Math.max(0, namespace.entries - 1);
447
- }
448
- }
343
+ */ applyMemoryUpdates(groupedUpdates) {
344
+ // Handle memory operation updates
345
+ const memoryUpdates = groupedUpdates.get('memory_update');
346
+ if (memoryUpdates) {
347
+ memoryUpdates.forEach((update)=>{
348
+ // Update memory stats
349
+ if (this.ui.memoryStats) {
350
+ const namespace = this.ui.memoryStats.namespaces.find((ns)=>ns.name === update.namespace);
351
+ if (namespace) {
352
+ // Update existing namespace stats
353
+ if (update.operation === 'store') {
354
+ namespace.entries++;
355
+ } else if (update.operation === 'delete') {
356
+ namespace.entries = Math.max(0, namespace.entries - 1);
357
+ }
358
+ }
359
+ }
360
+ this.ui.addLog('info', `💾 Memory ${update.operation} in ${update.namespace}`);
361
+ });
449
362
  }
450
-
451
- this.ui.addLog('info', `💾 Memory ${update.operation} in ${update.namespace}`);
452
- });
453
363
  }
454
- }
455
-
456
- /**
364
+ /**
457
365
  * Apply generic updates for other views
458
- */
459
- applyGenericUpdates(viewName, groupedUpdates) {
460
- // Log generic updates
461
- groupedUpdates.forEach((updates, type) => {
462
- updates.forEach((update) => {
463
- this.ui.addLog('info', `📡 ${viewName}: ${type} update`);
464
- });
465
- });
466
- }
467
-
468
- /**
366
+ */ applyGenericUpdates(viewName, groupedUpdates) {
367
+ // Log generic updates
368
+ groupedUpdates.forEach((updates, type)=>{
369
+ updates.forEach((update)=>{
370
+ this.ui.addLog('info', `📡 ${viewName}: ${type} update`);
371
+ });
372
+ });
373
+ }
374
+ /**
469
375
  * Update related views based on tool execution
470
- */
471
- updateRelatedViews(toolName, result) {
472
- // Map tool names to affected views
473
- const toolViewMap = {
474
- // Neural tools affect neural view
475
- neural_train: ['neural'],
476
- neural_predict: ['neural'],
477
- neural_status: ['neural'],
478
- model_save: ['neural'],
479
- model_load: ['neural'],
480
-
481
- // Analysis tools affect analysis view
482
- performance_report: ['analysis'],
483
- bottleneck_analyze: ['analysis'],
484
- token_usage: ['analysis'],
485
- benchmark_run: ['analysis'],
486
-
487
- // Swarm tools affect orchestration view
488
- swarm_init: ['orchestration'],
489
- agent_spawn: ['orchestration'],
490
- task_orchestrate: ['orchestration'],
491
-
492
- // Memory tools affect memory view
493
- memory_usage: ['memory'],
494
- memory_search: ['memory'],
495
- memory_backup: ['memory'],
496
- };
497
-
498
- const affectedViews = toolViewMap[toolName] || [];
499
-
500
- affectedViews.forEach((viewName) => {
501
- this.broadcastUpdate(viewName, {
502
- type: 'tool_result',
503
- toolName,
504
- result,
505
- timestamp: Date.now(),
506
- });
507
- });
508
- }
509
-
510
- /**
376
+ */ updateRelatedViews(toolName, result) {
377
+ // Map tool names to affected views
378
+ const toolViewMap = {
379
+ // Neural tools affect neural view
380
+ neural_train: [
381
+ 'neural'
382
+ ],
383
+ neural_predict: [
384
+ 'neural'
385
+ ],
386
+ neural_status: [
387
+ 'neural'
388
+ ],
389
+ model_save: [
390
+ 'neural'
391
+ ],
392
+ model_load: [
393
+ 'neural'
394
+ ],
395
+ // Analysis tools affect analysis view
396
+ performance_report: [
397
+ 'analysis'
398
+ ],
399
+ bottleneck_analyze: [
400
+ 'analysis'
401
+ ],
402
+ token_usage: [
403
+ 'analysis'
404
+ ],
405
+ benchmark_run: [
406
+ 'analysis'
407
+ ],
408
+ // Swarm tools affect orchestration view
409
+ swarm_init: [
410
+ 'orchestration'
411
+ ],
412
+ agent_spawn: [
413
+ 'orchestration'
414
+ ],
415
+ task_orchestrate: [
416
+ 'orchestration'
417
+ ],
418
+ // Memory tools affect memory view
419
+ memory_usage: [
420
+ 'memory'
421
+ ],
422
+ memory_search: [
423
+ 'memory'
424
+ ],
425
+ memory_backup: [
426
+ 'memory'
427
+ ]
428
+ };
429
+ const affectedViews = toolViewMap[toolName] || [];
430
+ affectedViews.forEach((viewName)=>{
431
+ this.broadcastUpdate(viewName, {
432
+ type: 'tool_result',
433
+ toolName,
434
+ result,
435
+ timestamp: Date.now()
436
+ });
437
+ });
438
+ }
439
+ /**
511
440
  * Request UI refresh (throttled)
512
- */
513
- requestUIRefresh() {
514
- if (this.refreshThrottle) return;
515
-
516
- this.refreshThrottle = setTimeout(() => {
517
- if (this.ui && typeof this.ui.render === 'function') {
518
- this.ui.render();
519
- }
520
- this.refreshThrottle = null;
521
- }, 50); // Throttle to max 20 FPS
522
- }
523
-
524
- /**
441
+ */ requestUIRefresh() {
442
+ if (this.refreshThrottle) return;
443
+ this.refreshThrottle = setTimeout(()=>{
444
+ if (this.ui && typeof this.ui.render === 'function') {
445
+ this.ui.render();
446
+ }
447
+ this.refreshThrottle = null;
448
+ }, 50); // Throttle to max 20 FPS
449
+ }
450
+ /**
525
451
  * Start performance monitoring
526
- */
527
- startPerformanceMonitoring() {
528
- setInterval(() => {
529
- this.reportPerformanceMetrics();
530
- }, 60000); // Report every minute
531
- }
532
-
533
- /**
452
+ */ startPerformanceMonitoring() {
453
+ setInterval(()=>{
454
+ this.reportPerformanceMetrics();
455
+ }, 60000); // Report every minute
456
+ }
457
+ /**
534
458
  * Report performance metrics
535
- */
536
- reportPerformanceMetrics() {
537
- const avgLatency =
538
- this.updateMetrics.updateLatency.length > 0
539
- ? this.updateMetrics.updateLatency.reduce((a, b) => a + b, 0) /
540
- this.updateMetrics.updateLatency.length
541
- : 0;
542
-
543
- const queueSizes = Array.from(this.updateQueues.values()).map((q) => q.length);
544
- const totalQueueSize = queueSizes.reduce((a, b) => a + b, 0);
545
-
546
- this.emit('performance_metrics', {
547
- totalUpdates: this.updateMetrics.totalUpdates,
548
- averageLatency: avgLatency,
549
- batchedUpdates: this.updateMetrics.batchedUpdates,
550
- droppedUpdates: this.updateMetrics.droppedUpdates,
551
- totalQueueSize,
552
- eventHistorySize: this.eventHistory.length,
553
- });
554
- }
555
-
556
- /**
459
+ */ reportPerformanceMetrics() {
460
+ const avgLatency = this.updateMetrics.updateLatency.length > 0 ? this.updateMetrics.updateLatency.reduce((a, b)=>a + b, 0) / this.updateMetrics.updateLatency.length : 0;
461
+ const queueSizes = Array.from(this.updateQueues.values()).map((q)=>q.length);
462
+ const totalQueueSize = queueSizes.reduce((a, b)=>a + b, 0);
463
+ this.emit('performance_metrics', {
464
+ totalUpdates: this.updateMetrics.totalUpdates,
465
+ averageLatency: avgLatency,
466
+ batchedUpdates: this.updateMetrics.batchedUpdates,
467
+ droppedUpdates: this.updateMetrics.droppedUpdates,
468
+ totalQueueSize,
469
+ eventHistorySize: this.eventHistory.length
470
+ });
471
+ }
472
+ /**
557
473
  * Get system status
558
- */
559
- getStatus() {
560
- const queueSizes = {};
561
- this.updateQueues.forEach((queue, viewName) => {
562
- queueSizes[viewName] = queue.length;
563
- });
564
-
565
- return {
566
- subscribers: this.subscribers.size,
567
- queueSizes,
568
- metrics: this.updateMetrics,
569
- eventHistorySize: this.eventHistory.length,
570
- activeTimers: this.updateTimers.size,
571
- };
572
- }
573
-
574
- /**
575
- * Create progressive loading handler
576
- */
577
- createProgressiveLoader(viewName, dataLoader, options = {}) {
578
- const { chunkSize = 10, delay = 100, onProgress = null, onComplete = null } = options;
579
-
580
- return async () => {
581
- try {
582
- const data = await dataLoader();
583
-
584
- if (!Array.isArray(data)) {
585
- // Non-array data, load immediately
586
- this.broadcastUpdate(viewName, {
587
- type: 'data_loaded',
588
- data,
589
- timestamp: Date.now(),
590
- });
591
-
592
- if (onComplete) onComplete(data);
593
- return;
594
- }
595
-
596
- // Progressive loading for arrays
597
- for (let i = 0; i < data.length; i += chunkSize) {
598
- const chunk = data.slice(i, i + chunkSize);
599
-
600
- this.broadcastUpdate(viewName, {
601
- type: 'data_chunk',
602
- chunk,
603
- progress: {
604
- loaded: Math.min(i + chunkSize, data.length),
605
- total: data.length,
606
- percentage: Math.min(((i + chunkSize) / data.length) * 100, 100),
607
- },
608
- timestamp: Date.now(),
609
- });
610
-
611
- if (onProgress) {
612
- onProgress({
613
- loaded: Math.min(i + chunkSize, data.length),
614
- total: data.length,
615
- percentage: Math.min(((i + chunkSize) / data.length) * 100, 100),
616
- });
617
- }
618
-
619
- // Small delay between chunks to prevent blocking
620
- if (i + chunkSize < data.length) {
621
- await new Promise((resolve) => setTimeout(resolve, delay));
622
- }
623
- }
624
-
625
- if (onComplete) onComplete(data);
626
- } catch (error) {
627
- this.broadcastUpdate(viewName, {
628
- type: 'data_error',
629
- error: error.message,
630
- timestamp: Date.now(),
474
+ */ getStatus() {
475
+ const queueSizes = {};
476
+ this.updateQueues.forEach((queue, viewName)=>{
477
+ queueSizes[viewName] = queue.length;
631
478
  });
632
- }
633
- };
634
- }
635
-
636
- /**
479
+ return {
480
+ subscribers: this.subscribers.size,
481
+ queueSizes,
482
+ metrics: this.updateMetrics,
483
+ eventHistorySize: this.eventHistory.length,
484
+ activeTimers: this.updateTimers.size
485
+ };
486
+ }
487
+ /**
488
+ * Create progressive loading handler
489
+ */ createProgressiveLoader(viewName, dataLoader, options = {}) {
490
+ const { chunkSize = 10, delay = 100, onProgress = null, onComplete = null } = options;
491
+ return async ()=>{
492
+ try {
493
+ const data = await dataLoader();
494
+ if (!Array.isArray(data)) {
495
+ // Non-array data, load immediately
496
+ this.broadcastUpdate(viewName, {
497
+ type: 'data_loaded',
498
+ data,
499
+ timestamp: Date.now()
500
+ });
501
+ if (onComplete) onComplete(data);
502
+ return;
503
+ }
504
+ // Progressive loading for arrays
505
+ for(let i = 0; i < data.length; i += chunkSize){
506
+ const chunk = data.slice(i, i + chunkSize);
507
+ this.broadcastUpdate(viewName, {
508
+ type: 'data_chunk',
509
+ chunk,
510
+ progress: {
511
+ loaded: Math.min(i + chunkSize, data.length),
512
+ total: data.length,
513
+ percentage: Math.min((i + chunkSize) / data.length * 100, 100)
514
+ },
515
+ timestamp: Date.now()
516
+ });
517
+ if (onProgress) {
518
+ onProgress({
519
+ loaded: Math.min(i + chunkSize, data.length),
520
+ total: data.length,
521
+ percentage: Math.min((i + chunkSize) / data.length * 100, 100)
522
+ });
523
+ }
524
+ // Small delay between chunks to prevent blocking
525
+ if (i + chunkSize < data.length) {
526
+ await new Promise((resolve)=>setTimeout(resolve, delay));
527
+ }
528
+ }
529
+ if (onComplete) onComplete(data);
530
+ } catch (error) {
531
+ this.broadcastUpdate(viewName, {
532
+ type: 'data_error',
533
+ error: error.message,
534
+ timestamp: Date.now()
535
+ });
536
+ }
537
+ };
538
+ }
539
+ /**
637
540
  * Cleanup resources
638
- */
639
- cleanup() {
640
- // Clear all timers
641
- this.updateTimers.forEach((timer) => clearTimeout(timer));
642
- this.updateTimers.clear();
643
-
644
- // Clear refresh throttle
645
- if (this.refreshThrottle) {
646
- clearTimeout(this.refreshThrottle);
541
+ */ cleanup() {
542
+ // Clear all timers
543
+ this.updateTimers.forEach((timer)=>clearTimeout(timer));
544
+ this.updateTimers.clear();
545
+ // Clear refresh throttle
546
+ if (this.refreshThrottle) {
547
+ clearTimeout(this.refreshThrottle);
548
+ }
549
+ // Clear all subscribers
550
+ this.subscribers.clear();
551
+ // Clear update queues
552
+ this.updateQueues.clear();
553
+ this.ui.addLog('info', 'Real-time update system cleaned up');
554
+ }
555
+ constructor(ui){
556
+ this.ui = ui;
557
+ this.subscribers = new Map(); // Event type -> Set of callbacks
558
+ this.updateQueues = new Map(); // View -> Queue of pending updates
559
+ this.updateTimers = new Map(); // View -> Timer for batched updates
560
+ this.batchDelay = 100; // ms to batch updates
561
+ this.eventHistory = []; // Keep last 100 events
562
+ this.maxHistorySize = 100;
563
+ // Performance monitoring
564
+ this.updateMetrics = {
565
+ totalUpdates: 0,
566
+ updateLatency: [],
567
+ batchedUpdates: 0,
568
+ droppedUpdates: 0
569
+ };
570
+ this.initializeSystem();
647
571
  }
648
-
649
- // Clear all subscribers
650
- this.subscribers.clear();
651
-
652
- // Clear update queues
653
- this.updateQueues.clear();
654
-
655
- this.ui.addLog('info', 'Real-time update system cleaned up');
656
- }
657
572
  }
658
-
659
573
  export default RealtimeUpdateSystem;