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
@@ -1,741 +1,661 @@
1
1
  #!/usr/bin/env node
2
-
3
2
  /**
4
3
  * Enhanced Swarm UI with real-time monitoring and control
5
4
  * Uses blessed for terminal UI
6
- */
7
-
8
- const blessed = require('blessed');
5
+ */ const blessed = require('blessed');
9
6
  const fs = require('fs').promises;
10
7
  const path = require('path');
11
8
  const { spawn } = require('child_process');
12
-
13
- class SwarmUI {
14
- constructor() {
15
- this.screen = null;
16
- this.swarmData = {
17
- objectives: [],
18
- agents: [],
19
- tasks: [],
20
- status: 'idle',
21
- };
22
- this.selectedObjective = null;
23
- this.updateInterval = null;
24
- this.logBuffer = [];
25
- this.maxLogLines = 100;
26
- this.activeProcesses = new Map(); // Track active processes for cross-platform termination
27
- }
28
-
29
- async init() {
30
- // Create blessed screen
31
- this.screen = blessed.screen({
32
- smartCSR: true,
33
- title: 'Claude Flow - Swarm Control Center',
34
- });
35
-
36
- this.createLayout();
37
- this.bindEvents();
38
- this.startMonitoring();
39
-
40
- this.screen.render();
41
- }
42
-
43
- createLayout() {
44
- // Main container
45
- const mainBox = blessed.box({
46
- parent: this.screen,
47
- top: 0,
48
- left: 0,
49
- width: '100%',
50
- height: '100%',
51
- border: {
52
- type: 'line',
53
- },
54
- style: {
55
- border: {
56
- fg: 'cyan',
57
- },
58
- },
59
- });
60
-
61
- // Header
62
- this.headerBox = blessed.box({
63
- parent: mainBox,
64
- top: 0,
65
- left: 0,
66
- width: '100%',
67
- height: 3,
68
- content: '{center}🐝 Claude Flow Swarm Control Center{/center}',
69
- tags: true,
70
- style: {
71
- fg: 'white',
72
- bg: 'blue',
73
- },
74
- });
75
-
76
- // Status bar
77
- this.statusBox = blessed.box({
78
- parent: mainBox,
79
- top: 2,
80
- left: 0,
81
- width: '100%',
82
- height: 1,
83
- content: 'Status: Initializing...',
84
- style: {
85
- fg: 'yellow',
86
- },
87
- });
88
-
89
- // Left panel - Objectives and Agents
90
- const leftPanel = blessed.box({
91
- parent: mainBox,
92
- top: 3,
93
- left: 0,
94
- width: '30%',
95
- height: '70%',
96
- border: {
97
- type: 'line',
98
- },
99
- label: ' Objectives & Agents ',
100
- style: {
101
- border: {
102
- fg: 'green',
103
- },
104
- },
105
- });
106
-
107
- // Objectives list
108
- this.objectivesList = blessed.list({
109
- parent: leftPanel,
110
- top: 0,
111
- left: 0,
112
- width: '100%',
113
- height: '50%',
114
- label: ' Objectives ',
115
- items: ['No objectives'],
116
- keys: true,
117
- vi: true,
118
- mouse: true,
119
- style: {
120
- selected: {
121
- bg: 'blue',
122
- },
123
- item: {
124
- fg: 'white',
125
- },
126
- },
127
- });
128
-
129
- // Agents list
130
- this.agentsList = blessed.list({
131
- parent: leftPanel,
132
- top: '50%',
133
- left: 0,
134
- width: '100%',
135
- height: '50%',
136
- label: ' Agents ',
137
- items: ['No agents'],
138
- keys: true,
139
- vi: true,
140
- mouse: true,
141
- style: {
142
- selected: {
143
- bg: 'green',
144
- },
145
- item: {
146
- fg: 'white',
147
- },
148
- },
149
- });
150
-
151
- // Center panel - Tasks and Details
152
- const centerPanel = blessed.box({
153
- parent: mainBox,
154
- top: 3,
155
- left: '30%',
156
- width: '40%',
157
- height: '70%',
158
- border: {
159
- type: 'line',
160
- },
161
- label: ' Tasks & Details ',
162
- style: {
163
- border: {
164
- fg: 'yellow',
165
- },
166
- },
167
- });
168
-
169
- // Tasks list
170
- this.tasksList = blessed.list({
171
- parent: centerPanel,
172
- top: 0,
173
- left: 0,
174
- width: '100%',
175
- height: '50%',
176
- label: ' Tasks ',
177
- items: ['No tasks'],
178
- keys: true,
179
- vi: true,
180
- mouse: true,
181
- style: {
182
- selected: {
183
- bg: 'yellow',
184
- fg: 'black',
185
- },
186
- item: {
187
- fg: 'white',
188
- },
189
- },
190
- });
191
-
192
- // Task details
193
- this.taskDetails = blessed.box({
194
- parent: centerPanel,
195
- top: '50%',
196
- left: 0,
197
- width: '100%',
198
- height: '50%',
199
- label: ' Task Details ',
200
- content: 'Select a task to view details',
201
- scrollable: true,
202
- alwaysScroll: true,
203
- keys: true,
204
- vi: true,
205
- mouse: true,
206
- style: {
207
- fg: 'white',
208
- },
209
- });
210
-
211
- // Right panel - Logs and Controls
212
- const rightPanel = blessed.box({
213
- parent: mainBox,
214
- top: 3,
215
- left: '70%',
216
- width: '30%',
217
- height: '70%',
218
- border: {
219
- type: 'line',
220
- },
221
- label: ' Logs & Controls ',
222
- style: {
223
- border: {
224
- fg: 'magenta',
225
- },
226
- },
227
- });
228
-
229
- // Activity logs
230
- this.logBox = blessed.log({
231
- parent: rightPanel,
232
- top: 0,
233
- left: 0,
234
- width: '100%',
235
- height: '60%',
236
- label: ' Activity Log ',
237
- tags: true,
238
- mouse: true,
239
- scrollable: true,
240
- alwaysScroll: true,
241
- style: {
242
- fg: 'white',
243
- },
244
- });
245
-
246
- // Control buttons
247
- this.controlBox = blessed.box({
248
- parent: rightPanel,
249
- top: '60%',
250
- left: 0,
251
- width: '100%',
252
- height: '40%',
253
- label: ' Controls ',
254
- });
255
-
256
- // Create objective button
257
- this.createButton = blessed.button({
258
- parent: this.controlBox,
259
- top: 1,
260
- left: 1,
261
- width: '90%',
262
- height: 3,
263
- content: 'Create Objective',
264
- align: 'center',
265
- style: {
266
- bg: 'blue',
267
- fg: 'white',
268
- focus: {
269
- bg: 'red',
270
- },
271
- },
272
- });
273
-
274
- // Stop swarm button
275
- this.stopButton = blessed.button({
276
- parent: this.controlBox,
277
- top: 5,
278
- left: 1,
279
- width: '90%',
280
- height: 3,
281
- content: 'Stop Swarm',
282
- align: 'center',
283
- style: {
284
- bg: 'red',
285
- fg: 'white',
286
- focus: {
287
- bg: 'yellow',
288
- fg: 'black',
289
- },
290
- },
291
- });
292
-
293
- // Bottom panel - Command input
294
- this.commandBox = blessed.textbox({
295
- parent: mainBox,
296
- bottom: 0,
297
- left: 0,
298
- width: '100%',
299
- height: 3,
300
- label: ' Command Input (Press Enter to execute) ',
301
- keys: true,
302
- mouse: true,
303
- inputOnFocus: true,
304
- style: {
305
- border: {
306
- fg: 'cyan',
307
- },
308
- fg: 'white',
309
- },
310
- });
311
- }
312
-
313
- bindEvents() {
314
- // Screen events
315
- this.screen.key(['escape', 'q', 'C-c'], () => {
316
- this.cleanup();
317
- process.exit(0);
318
- });
319
-
320
- // Objective selection
321
- this.objectivesList.on('select', (item, index) => {
322
- this.selectedObjective = this.swarmData.objectives[index];
323
- this.updateTasksList();
324
- this.log(`Selected objective: ${this.selectedObjective?.description || 'Unknown'}`);
325
- });
326
-
327
- // Task selection
328
- this.tasksList.on('select', (item, index) => {
329
- const task = this.swarmData.tasks[index];
330
- if (task) {
331
- this.updateTaskDetails(task);
332
- }
333
- });
334
-
335
- // Create objective button
336
- this.createButton.on('press', () => {
337
- this.promptCreateObjective();
338
- });
339
-
340
- // Stop swarm button
341
- this.stopButton.on('press', () => {
342
- this.stopSwarm();
343
- });
344
-
345
- // Command input
346
- this.commandBox.on('submit', (value) => {
347
- this.executeCommand(value);
348
- this.commandBox.clearValue();
349
- this.screen.render();
350
- });
351
-
352
- // Focus management
353
- this.screen.key(['tab'], () => {
354
- this.screen.focusNext();
355
- });
356
-
357
- this.screen.key(['S-tab'], () => {
358
- this.screen.focusPrevious();
359
- });
360
- }
361
-
362
- async startMonitoring() {
363
- this.log('Starting swarm monitoring...');
364
-
365
- // Update interval
366
- this.updateInterval = setInterval(() => {
367
- this.updateSwarmData();
368
- }, 2000);
369
-
370
- // Initial update
371
- await this.updateSwarmData();
372
- }
373
-
374
- async updateSwarmData() {
375
- try {
376
- // Load swarm data from file system
377
- const swarmRunsDir = './swarm-runs';
378
-
379
- try {
380
- const runs = await fs.readdir(swarmRunsDir);
381
- this.swarmData.objectives = [];
382
- this.swarmData.agents = [];
383
- this.swarmData.tasks = [];
384
-
385
- for (const runDir of runs) {
386
- const configPath = path.join(swarmRunsDir, runDir, 'config.json');
387
- try {
388
- const configData = await fs.readFile(configPath, 'utf-8');
389
- const config = JSON.parse(configData);
390
-
391
- this.swarmData.objectives.push({
392
- id: config.swarmId,
393
- description: config.objective,
394
- status: 'running',
395
- startTime: config.startTime,
396
- });
397
-
398
- // Load agents
399
- const agentsDir = path.join(swarmRunsDir, runDir, 'agents');
9
+ let SwarmUI = class SwarmUI {
10
+ async init() {
11
+ // Create blessed screen
12
+ this.screen = blessed.screen({
13
+ smartCSR: true,
14
+ title: 'Claude Flow - Swarm Control Center'
15
+ });
16
+ this.createLayout();
17
+ this.bindEvents();
18
+ this.startMonitoring();
19
+ this.screen.render();
20
+ }
21
+ createLayout() {
22
+ // Main container
23
+ const mainBox = blessed.box({
24
+ parent: this.screen,
25
+ top: 0,
26
+ left: 0,
27
+ width: '100%',
28
+ height: '100%',
29
+ border: {
30
+ type: 'line'
31
+ },
32
+ style: {
33
+ border: {
34
+ fg: 'cyan'
35
+ }
36
+ }
37
+ });
38
+ // Header
39
+ this.headerBox = blessed.box({
40
+ parent: mainBox,
41
+ top: 0,
42
+ left: 0,
43
+ width: '100%',
44
+ height: 3,
45
+ content: '{center}🐝 Claude Flow Swarm Control Center{/center}',
46
+ tags: true,
47
+ style: {
48
+ fg: 'white',
49
+ bg: 'blue'
50
+ }
51
+ });
52
+ // Status bar
53
+ this.statusBox = blessed.box({
54
+ parent: mainBox,
55
+ top: 2,
56
+ left: 0,
57
+ width: '100%',
58
+ height: 1,
59
+ content: 'Status: Initializing...',
60
+ style: {
61
+ fg: 'yellow'
62
+ }
63
+ });
64
+ // Left panel - Objectives and Agents
65
+ const leftPanel = blessed.box({
66
+ parent: mainBox,
67
+ top: 3,
68
+ left: 0,
69
+ width: '30%',
70
+ height: '70%',
71
+ border: {
72
+ type: 'line'
73
+ },
74
+ label: ' Objectives & Agents ',
75
+ style: {
76
+ border: {
77
+ fg: 'green'
78
+ }
79
+ }
80
+ });
81
+ // Objectives list
82
+ this.objectivesList = blessed.list({
83
+ parent: leftPanel,
84
+ top: 0,
85
+ left: 0,
86
+ width: '100%',
87
+ height: '50%',
88
+ label: ' Objectives ',
89
+ items: [
90
+ 'No objectives'
91
+ ],
92
+ keys: true,
93
+ vi: true,
94
+ mouse: true,
95
+ style: {
96
+ selected: {
97
+ bg: 'blue'
98
+ },
99
+ item: {
100
+ fg: 'white'
101
+ }
102
+ }
103
+ });
104
+ // Agents list
105
+ this.agentsList = blessed.list({
106
+ parent: leftPanel,
107
+ top: '50%',
108
+ left: 0,
109
+ width: '100%',
110
+ height: '50%',
111
+ label: ' Agents ',
112
+ items: [
113
+ 'No agents'
114
+ ],
115
+ keys: true,
116
+ vi: true,
117
+ mouse: true,
118
+ style: {
119
+ selected: {
120
+ bg: 'green'
121
+ },
122
+ item: {
123
+ fg: 'white'
124
+ }
125
+ }
126
+ });
127
+ // Center panel - Tasks and Details
128
+ const centerPanel = blessed.box({
129
+ parent: mainBox,
130
+ top: 3,
131
+ left: '30%',
132
+ width: '40%',
133
+ height: '70%',
134
+ border: {
135
+ type: 'line'
136
+ },
137
+ label: ' Tasks & Details ',
138
+ style: {
139
+ border: {
140
+ fg: 'yellow'
141
+ }
142
+ }
143
+ });
144
+ // Tasks list
145
+ this.tasksList = blessed.list({
146
+ parent: centerPanel,
147
+ top: 0,
148
+ left: 0,
149
+ width: '100%',
150
+ height: '50%',
151
+ label: ' Tasks ',
152
+ items: [
153
+ 'No tasks'
154
+ ],
155
+ keys: true,
156
+ vi: true,
157
+ mouse: true,
158
+ style: {
159
+ selected: {
160
+ bg: 'yellow',
161
+ fg: 'black'
162
+ },
163
+ item: {
164
+ fg: 'white'
165
+ }
166
+ }
167
+ });
168
+ // Task details
169
+ this.taskDetails = blessed.box({
170
+ parent: centerPanel,
171
+ top: '50%',
172
+ left: 0,
173
+ width: '100%',
174
+ height: '50%',
175
+ label: ' Task Details ',
176
+ content: 'Select a task to view details',
177
+ scrollable: true,
178
+ alwaysScroll: true,
179
+ keys: true,
180
+ vi: true,
181
+ mouse: true,
182
+ style: {
183
+ fg: 'white'
184
+ }
185
+ });
186
+ // Right panel - Logs and Controls
187
+ const rightPanel = blessed.box({
188
+ parent: mainBox,
189
+ top: 3,
190
+ left: '70%',
191
+ width: '30%',
192
+ height: '70%',
193
+ border: {
194
+ type: 'line'
195
+ },
196
+ label: ' Logs & Controls ',
197
+ style: {
198
+ border: {
199
+ fg: 'magenta'
200
+ }
201
+ }
202
+ });
203
+ // Activity logs
204
+ this.logBox = blessed.log({
205
+ parent: rightPanel,
206
+ top: 0,
207
+ left: 0,
208
+ width: '100%',
209
+ height: '60%',
210
+ label: ' Activity Log ',
211
+ tags: true,
212
+ mouse: true,
213
+ scrollable: true,
214
+ alwaysScroll: true,
215
+ style: {
216
+ fg: 'white'
217
+ }
218
+ });
219
+ // Control buttons
220
+ this.controlBox = blessed.box({
221
+ parent: rightPanel,
222
+ top: '60%',
223
+ left: 0,
224
+ width: '100%',
225
+ height: '40%',
226
+ label: ' Controls '
227
+ });
228
+ // Create objective button
229
+ this.createButton = blessed.button({
230
+ parent: this.controlBox,
231
+ top: 1,
232
+ left: 1,
233
+ width: '90%',
234
+ height: 3,
235
+ content: 'Create Objective',
236
+ align: 'center',
237
+ style: {
238
+ bg: 'blue',
239
+ fg: 'white',
240
+ focus: {
241
+ bg: 'red'
242
+ }
243
+ }
244
+ });
245
+ // Stop swarm button
246
+ this.stopButton = blessed.button({
247
+ parent: this.controlBox,
248
+ top: 5,
249
+ left: 1,
250
+ width: '90%',
251
+ height: 3,
252
+ content: 'Stop Swarm',
253
+ align: 'center',
254
+ style: {
255
+ bg: 'red',
256
+ fg: 'white',
257
+ focus: {
258
+ bg: 'yellow',
259
+ fg: 'black'
260
+ }
261
+ }
262
+ });
263
+ // Bottom panel - Command input
264
+ this.commandBox = blessed.textbox({
265
+ parent: mainBox,
266
+ bottom: 0,
267
+ left: 0,
268
+ width: '100%',
269
+ height: 3,
270
+ label: ' Command Input (Press Enter to execute) ',
271
+ keys: true,
272
+ mouse: true,
273
+ inputOnFocus: true,
274
+ style: {
275
+ border: {
276
+ fg: 'cyan'
277
+ },
278
+ fg: 'white'
279
+ }
280
+ });
281
+ }
282
+ bindEvents() {
283
+ // Screen events
284
+ this.screen.key([
285
+ 'escape',
286
+ 'q',
287
+ 'C-c'
288
+ ], ()=>{
289
+ this.cleanup();
290
+ process.exit(0);
291
+ });
292
+ // Objective selection
293
+ this.objectivesList.on('select', (item, index)=>{
294
+ this.selectedObjective = this.swarmData.objectives[index];
295
+ this.updateTasksList();
296
+ this.log(`Selected objective: ${this.selectedObjective?.description || 'Unknown'}`);
297
+ });
298
+ // Task selection
299
+ this.tasksList.on('select', (item, index)=>{
300
+ const task = this.swarmData.tasks[index];
301
+ if (task) {
302
+ this.updateTaskDetails(task);
303
+ }
304
+ });
305
+ // Create objective button
306
+ this.createButton.on('press', ()=>{
307
+ this.promptCreateObjective();
308
+ });
309
+ // Stop swarm button
310
+ this.stopButton.on('press', ()=>{
311
+ this.stopSwarm();
312
+ });
313
+ // Command input
314
+ this.commandBox.on('submit', (value)=>{
315
+ this.executeCommand(value);
316
+ this.commandBox.clearValue();
317
+ this.screen.render();
318
+ });
319
+ // Focus management
320
+ this.screen.key([
321
+ 'tab'
322
+ ], ()=>{
323
+ this.screen.focusNext();
324
+ });
325
+ this.screen.key([
326
+ 'S-tab'
327
+ ], ()=>{
328
+ this.screen.focusPrevious();
329
+ });
330
+ }
331
+ async startMonitoring() {
332
+ this.log('Starting swarm monitoring...');
333
+ // Update interval
334
+ this.updateInterval = setInterval(()=>{
335
+ this.updateSwarmData();
336
+ }, 2000);
337
+ // Initial update
338
+ await this.updateSwarmData();
339
+ }
340
+ async updateSwarmData() {
341
+ try {
342
+ // Load swarm data from file system
343
+ const swarmRunsDir = './swarm-runs';
400
344
  try {
401
- const agents = await fs.readdir(agentsDir);
402
- for (const agentDir of agents) {
403
- const taskPath = path.join(agentsDir, agentDir, 'task.json');
404
- try {
405
- const taskData = await fs.readFile(taskPath, 'utf-8');
406
- const task = JSON.parse(taskData);
407
-
408
- this.swarmData.agents.push({
409
- id: task.agentId,
410
- swarmId: config.swarmId,
411
- status: task.status || 'active',
412
- task: task.task,
413
- });
414
-
415
- this.swarmData.tasks.push(task);
416
- } catch (e) {
417
- // Skip invalid task files
345
+ const runs = await fs.readdir(swarmRunsDir);
346
+ this.swarmData.objectives = [];
347
+ this.swarmData.agents = [];
348
+ this.swarmData.tasks = [];
349
+ for (const runDir of runs){
350
+ const configPath = path.join(swarmRunsDir, runDir, 'config.json');
351
+ try {
352
+ const configData = await fs.readFile(configPath, 'utf-8');
353
+ const config = JSON.parse(configData);
354
+ this.swarmData.objectives.push({
355
+ id: config.swarmId,
356
+ description: config.objective,
357
+ status: 'running',
358
+ startTime: config.startTime
359
+ });
360
+ // Load agents
361
+ const agentsDir = path.join(swarmRunsDir, runDir, 'agents');
362
+ try {
363
+ const agents = await fs.readdir(agentsDir);
364
+ for (const agentDir of agents){
365
+ const taskPath = path.join(agentsDir, agentDir, 'task.json');
366
+ try {
367
+ const taskData = await fs.readFile(taskPath, 'utf-8');
368
+ const task = JSON.parse(taskData);
369
+ this.swarmData.agents.push({
370
+ id: task.agentId,
371
+ swarmId: config.swarmId,
372
+ status: task.status || 'active',
373
+ task: task.task
374
+ });
375
+ this.swarmData.tasks.push(task);
376
+ } catch (e) {
377
+ // Skip invalid task files
378
+ }
379
+ }
380
+ } catch (e) {
381
+ // No agents directory
382
+ }
383
+ } catch (e) {
384
+ // Skip invalid config files
385
+ }
418
386
  }
419
- }
387
+ this.updateDisplay();
420
388
  } catch (e) {
421
- // No agents directory
389
+ // No swarm runs directory
390
+ this.swarmData.status = 'idle';
422
391
  }
423
- } catch (e) {
424
- // Skip invalid config files
425
- }
392
+ } catch (error) {
393
+ this.log(`Error updating swarm data: ${error.message}`, 'error');
426
394
  }
427
-
428
- this.updateDisplay();
429
- } catch (e) {
430
- // No swarm runs directory
431
- this.swarmData.status = 'idle';
432
- }
433
- } catch (error) {
434
- this.log(`Error updating swarm data: ${error.message}`, 'error');
435
395
  }
436
- }
437
-
438
- updateDisplay() {
439
- // Update status
440
- const activeObjectives = this.swarmData.objectives.filter((o) => o.status === 'running').length;
441
- const activeAgents = this.swarmData.agents.filter((a) => a.status === 'active').length;
442
-
443
- this.statusBox.setContent(
444
- `Status: ${this.swarmData.status} | ` +
445
- `Objectives: ${activeObjectives} | ` +
446
- `Agents: ${activeAgents} | ` +
447
- `Tasks: ${this.swarmData.tasks.length}`,
448
- );
449
-
450
- // Update objectives list
451
- const objectiveItems = this.swarmData.objectives.map(
452
- (obj) => `${obj.status === 'running' ? '🟢' : '🔴'} ${obj.description.substring(0, 25)}...`,
453
- );
454
- this.objectivesList.setItems(objectiveItems.length > 0 ? objectiveItems : ['No objectives']);
455
-
456
- // Update agents list
457
- const agentItems = this.swarmData.agents.map(
458
- (agent) => `${agent.status === 'active' ? '🤖' : '💤'} ${agent.id.substring(0, 15)}...`,
459
- );
460
- this.agentsList.setItems(agentItems.length > 0 ? agentItems : ['No agents']);
461
-
462
- // Update tasks list if objective is selected
463
- if (this.selectedObjective) {
464
- this.updateTasksList();
396
+ updateDisplay() {
397
+ // Update status
398
+ const activeObjectives = this.swarmData.objectives.filter((o)=>o.status === 'running').length;
399
+ const activeAgents = this.swarmData.agents.filter((a)=>a.status === 'active').length;
400
+ this.statusBox.setContent(`Status: ${this.swarmData.status} | ` + `Objectives: ${activeObjectives} | ` + `Agents: ${activeAgents} | ` + `Tasks: ${this.swarmData.tasks.length}`);
401
+ // Update objectives list
402
+ const objectiveItems = this.swarmData.objectives.map((obj)=>`${obj.status === 'running' ? '🟢' : '🔴'} ${obj.description.substring(0, 25)}...`);
403
+ this.objectivesList.setItems(objectiveItems.length > 0 ? objectiveItems : [
404
+ 'No objectives'
405
+ ]);
406
+ // Update agents list
407
+ const agentItems = this.swarmData.agents.map((agent)=>`${agent.status === 'active' ? '🤖' : '💤'} ${agent.id.substring(0, 15)}...`);
408
+ this.agentsList.setItems(agentItems.length > 0 ? agentItems : [
409
+ 'No agents'
410
+ ]);
411
+ // Update tasks list if objective is selected
412
+ if (this.selectedObjective) {
413
+ this.updateTasksList();
414
+ }
415
+ this.screen.render();
465
416
  }
466
-
467
- this.screen.render();
468
- }
469
-
470
- updateTasksList() {
471
- if (!this.selectedObjective) return;
472
-
473
- const objectiveTasks = this.swarmData.tasks.filter(
474
- (task) => task.swarmId === this.selectedObjective.id,
475
- );
476
-
477
- const taskItems = objectiveTasks.map((task) => {
478
- const statusIcon =
479
- {
480
- active: '🔄',
481
- completed: '✅',
482
- failed: '❌',
483
- pending: '⏳',
484
- }[task.status] || '❓';
485
-
486
- return `${statusIcon} ${task.task?.type || 'Unknown'}: ${task.task?.description?.substring(0, 20) || 'No description'}...`;
487
- });
488
-
489
- this.tasksList.setItems(taskItems.length > 0 ? taskItems : ['No tasks']);
490
- this.screen.render();
491
- }
492
-
493
- updateTaskDetails(task) {
494
- const details = [
495
- `Task ID: ${task.agentId}`,
496
- `Swarm ID: ${task.swarmId}`,
497
- `Type: ${task.task?.type || 'Unknown'}`,
498
- `Description: ${task.task?.description || 'No description'}`,
499
- `Status: ${task.status || 'Unknown'}`,
500
- `Start Time: ${task.startTime || 'Not started'}`,
501
- '',
502
- 'Task Data:',
503
- JSON.stringify(task.task, null, 2),
504
- ].join('\n');
505
-
506
- this.taskDetails.setContent(details);
507
- this.screen.render();
508
- }
509
-
510
- promptCreateObjective() {
511
- // Create a prompt box
512
- const promptBox = blessed.prompt({
513
- parent: this.screen,
514
- top: 'center',
515
- left: 'center',
516
- width: 60,
517
- height: 10,
518
- label: ' Create New Objective ',
519
- content: 'Enter objective description:',
520
- border: {
521
- type: 'line',
522
- },
523
- style: {
524
- border: {
525
- fg: 'cyan',
526
- },
527
- },
528
- });
529
-
530
- promptBox.input('Enter objective:', '', (err, value) => {
531
- if (!err && value) {
532
- this.createObjective(value);
533
- }
534
- promptBox.destroy();
535
- this.screen.render();
536
- });
537
-
538
- this.screen.render();
539
- }
540
-
541
- async createObjective(description) {
542
- try {
543
- this.log(`Creating objective: ${description}`);
544
-
545
- // Execute swarm command
546
- const args = ['swarm', description, '--ui', '--monitor'];
547
- const process = spawn('claude-flow', args, {
548
- detached: true,
549
- stdio: 'ignore',
550
- });
551
-
552
- process.unref();
553
-
554
- // Track the process for later termination
555
- const processId = `swarm-${Date.now()}`;
556
- this.activeProcesses.set(processId, process);
557
-
558
- this.log(`Launched swarm with PID: ${process.pid} (ID: ${processId})`);
559
-
560
- // Update data after a delay
561
- setTimeout(() => {
562
- this.updateSwarmData();
563
- }, 2000);
564
- } catch (error) {
565
- this.log(`Error creating objective: ${error.message}`, 'error');
417
+ updateTasksList() {
418
+ if (!this.selectedObjective) return;
419
+ const objectiveTasks = this.swarmData.tasks.filter((task)=>task.swarmId === this.selectedObjective.id);
420
+ const taskItems = objectiveTasks.map((task)=>{
421
+ const statusIcon = {
422
+ active: '🔄',
423
+ completed: '✅',
424
+ failed: '❌',
425
+ pending: '⏳'
426
+ }[task.status] || '❓';
427
+ return `${statusIcon} ${task.task?.type || 'Unknown'}: ${task.task?.description?.substring(0, 20) || 'No description'}...`;
428
+ });
429
+ this.tasksList.setItems(taskItems.length > 0 ? taskItems : [
430
+ 'No tasks'
431
+ ]);
432
+ this.screen.render();
566
433
  }
567
- }
568
-
569
- async stopSwarm() {
570
- this.log('Stopping all swarm operations...');
571
-
572
- try {
573
- // Cross-platform process termination
574
- let stoppedCount = 0;
575
-
576
- // First, try to stop tracked processes
577
- for (const [processId, process] of this.activeProcesses) {
434
+ updateTaskDetails(task) {
435
+ const details = [
436
+ `Task ID: ${task.agentId}`,
437
+ `Swarm ID: ${task.swarmId}`,
438
+ `Type: ${task.task?.type || 'Unknown'}`,
439
+ `Description: ${task.task?.description || 'No description'}`,
440
+ `Status: ${task.status || 'Unknown'}`,
441
+ `Start Time: ${task.startTime || 'Not started'}`,
442
+ '',
443
+ 'Task Data:',
444
+ JSON.stringify(task.task, null, 2)
445
+ ].join('\n');
446
+ this.taskDetails.setContent(details);
447
+ this.screen.render();
448
+ }
449
+ promptCreateObjective() {
450
+ // Create a prompt box
451
+ const promptBox = blessed.prompt({
452
+ parent: this.screen,
453
+ top: 'center',
454
+ left: 'center',
455
+ width: 60,
456
+ height: 10,
457
+ label: ' Create New Objective ',
458
+ content: 'Enter objective description:',
459
+ border: {
460
+ type: 'line'
461
+ },
462
+ style: {
463
+ border: {
464
+ fg: 'cyan'
465
+ }
466
+ }
467
+ });
468
+ promptBox.input('Enter objective:', '', (err, value)=>{
469
+ if (!err && value) {
470
+ this.createObjective(value);
471
+ }
472
+ promptBox.destroy();
473
+ this.screen.render();
474
+ });
475
+ this.screen.render();
476
+ }
477
+ async createObjective(description) {
578
478
  try {
579
- // Use process.kill() for cross-platform compatibility
580
- if (process.pid && !process.killed) {
581
- process.kill('SIGTERM');
582
- stoppedCount++;
583
- this.log(`Stopped process ${processId} (PID: ${process.pid})`);
584
- }
585
- } catch (err) {
586
- // Process might already be dead
587
- this.log(`Process ${processId} already terminated`, 'warn');
479
+ this.log(`Creating objective: ${description}`);
480
+ // Execute swarm command
481
+ const args = [
482
+ 'swarm',
483
+ description,
484
+ '--ui',
485
+ '--monitor'
486
+ ];
487
+ const process1 = spawn('claude-flow', args, {
488
+ detached: true,
489
+ stdio: 'ignore'
490
+ });
491
+ process1.unref();
492
+ // Track the process for later termination
493
+ const processId = `swarm-${Date.now()}`;
494
+ this.activeProcesses.set(processId, process1);
495
+ this.log(`Launched swarm with PID: ${process1.pid} (ID: ${processId})`);
496
+ // Update data after a delay
497
+ setTimeout(()=>{
498
+ this.updateSwarmData();
499
+ }, 2000);
500
+ } catch (error) {
501
+ this.log(`Error creating objective: ${error.message}`, 'error');
588
502
  }
589
- }
590
-
591
- // Clear the tracked processes
592
- this.activeProcesses.clear();
593
-
594
- // Also find and stop any orphaned processes
595
- await this.stopOrphanedProcesses();
596
-
597
- this.log(`Swarm operations stopped (${stoppedCount} processes terminated)`);
598
-
599
- // Update display
600
- this.swarmData.status = 'stopped';
601
- this.updateDisplay();
602
- } catch (error) {
603
- this.log(`Error stopping swarm: ${error.message}`, 'error');
604
503
  }
605
- }
606
-
607
- async stopOrphanedProcesses() {
608
- // Cross-platform approach to find and stop orphaned processes
609
- const { exec } = require('child_process');
610
- const os = require('os');
611
-
612
- if (os.platform() === 'win32') {
613
- // Windows: Use wmic to find and kill processes
614
- exec(
615
- 'wmic process where "commandline like \'%claude-flow-novice swarm%\'" get processid',
616
- (error, stdout) => {
617
- if (!error && stdout) {
618
- const pids = stdout
619
- .split('\n')
620
- .map((line) => line.trim())
621
- .filter((line) => /^\d+$/.test(line));
622
-
623
- pids.forEach((pid) => {
624
- exec(`taskkill /F /PID ${pid}`, (killError) => {
625
- if (!killError) {
626
- this.log(`Stopped orphaned process PID: ${pid}`);
504
+ async stopSwarm() {
505
+ this.log('Stopping all swarm operations...');
506
+ try {
507
+ // Cross-platform process termination
508
+ let stoppedCount = 0;
509
+ // First, try to stop tracked processes
510
+ for (const [processId, process1] of this.activeProcesses){
511
+ try {
512
+ // Use process.kill() for cross-platform compatibility
513
+ if (process1.pid && !process1.killed) {
514
+ process1.kill('SIGTERM');
515
+ stoppedCount++;
516
+ this.log(`Stopped process ${processId} (PID: ${process1.pid})`);
517
+ }
518
+ } catch (err) {
519
+ // Process might already be dead
520
+ this.log(`Process ${processId} already terminated`, 'warn');
627
521
  }
628
- });
629
- });
630
- }
631
- },
632
- );
633
- } else {
634
- // Unix-like systems: Use ps and grep
635
- exec('ps aux | grep "claude-flow-novice swarm" | grep -v grep', (error, stdout) => {
636
- if (!error && stdout) {
637
- const lines = stdout.split('\n').filter((line) => line.trim());
638
- lines.forEach((line) => {
639
- const parts = line.split(/\s+/);
640
- const pid = parts[1];
641
- if (pid && /^\d+$/.test(pid)) {
642
- try {
643
- process.kill(parseInt(pid), 'SIGTERM');
644
- this.log(`Stopped orphaned process PID: ${pid}`);
645
- } catch (killError) {
646
- // Process might not exist or no permission
647
- }
648
522
  }
649
- });
523
+ // Clear the tracked processes
524
+ this.activeProcesses.clear();
525
+ // Also find and stop any orphaned processes
526
+ await this.stopOrphanedProcesses();
527
+ this.log(`Swarm operations stopped (${stoppedCount} processes terminated)`);
528
+ // Update display
529
+ this.swarmData.status = 'stopped';
530
+ this.updateDisplay();
531
+ } catch (error) {
532
+ this.log(`Error stopping swarm: ${error.message}`, 'error');
650
533
  }
651
- });
652
534
  }
653
- }
654
-
655
- async executeCommand(command) {
656
- this.log(`Executing command: ${command}`);
657
-
658
- try {
659
- const { exec } = require('child_process');
660
- exec(command, (error, stdout, stderr) => {
661
- if (error) {
662
- this.log(`Command error: ${error.message}`, 'error');
535
+ async stopOrphanedProcesses() {
536
+ // Cross-platform approach to find and stop orphaned processes
537
+ const { exec } = require('child_process');
538
+ const os = require('os');
539
+ if (os.platform() === 'win32') {
540
+ // Windows: Use wmic to find and kill processes
541
+ exec('wmic process where "commandline like \'%claude-flow-novice swarm%\'" get processid', (error, stdout)=>{
542
+ if (!error && stdout) {
543
+ const pids = stdout.split('\n').map((line)=>line.trim()).filter((line)=>/^\d+$/.test(line));
544
+ pids.forEach((pid)=>{
545
+ exec(`taskkill /F /PID ${pid}`, (killError)=>{
546
+ if (!killError) {
547
+ this.log(`Stopped orphaned process PID: ${pid}`);
548
+ }
549
+ });
550
+ });
551
+ }
552
+ });
663
553
  } else {
664
- if (stdout) this.log(`Output: ${stdout.trim()}`);
665
- if (stderr) this.log(`Error: ${stderr.trim()}`, 'warn');
554
+ // Unix-like systems: Use ps and grep
555
+ exec('ps aux | grep "claude-flow-novice swarm" | grep -v grep', (error, stdout)=>{
556
+ if (!error && stdout) {
557
+ const lines = stdout.split('\n').filter((line)=>line.trim());
558
+ lines.forEach((line)=>{
559
+ const parts = line.split(/\s+/);
560
+ const pid = parts[1];
561
+ if (pid && /^\d+$/.test(pid)) {
562
+ try {
563
+ process.kill(parseInt(pid), 'SIGTERM');
564
+ this.log(`Stopped orphaned process PID: ${pid}`);
565
+ } catch (killError) {
566
+ // Process might not exist or no permission
567
+ }
568
+ }
569
+ });
570
+ }
571
+ });
666
572
  }
667
- });
668
- } catch (error) {
669
- this.log(`Failed to execute command: ${error.message}`, 'error');
670
- }
671
- }
672
-
673
- log(message, level = 'info') {
674
- const timestamp = new Date().toLocaleTimeString();
675
- const levelColors = {
676
- info: 'white',
677
- warn: 'yellow',
678
- error: 'red',
679
- success: 'green',
680
- };
681
-
682
- const coloredMessage = `{${levelColors[level] || 'white'}-fg}[${timestamp}] ${message}{/}`;
683
-
684
- this.logBuffer.push(coloredMessage);
685
- if (this.logBuffer.length > this.maxLogLines) {
686
- this.logBuffer.shift();
687
573
  }
688
-
689
- if (this.logBox) {
690
- this.logBox.log(coloredMessage);
691
- this.screen.render();
574
+ async executeCommand(command) {
575
+ this.log(`Executing command: ${command}`);
576
+ try {
577
+ const { exec } = require('child_process');
578
+ exec(command, (error, stdout, stderr)=>{
579
+ if (error) {
580
+ this.log(`Command error: ${error.message}`, 'error');
581
+ } else {
582
+ if (stdout) this.log(`Output: ${stdout.trim()}`);
583
+ if (stderr) this.log(`Error: ${stderr.trim()}`, 'warn');
584
+ }
585
+ });
586
+ } catch (error) {
587
+ this.log(`Failed to execute command: ${error.message}`, 'error');
588
+ }
692
589
  }
693
- }
694
-
695
- cleanup() {
696
- if (this.updateInterval) {
697
- clearInterval(this.updateInterval);
590
+ log(message, level = 'info') {
591
+ const timestamp = new Date().toLocaleTimeString();
592
+ const levelColors = {
593
+ info: 'white',
594
+ warn: 'yellow',
595
+ error: 'red',
596
+ success: 'green'
597
+ };
598
+ const coloredMessage = `{${levelColors[level] || 'white'}-fg}[${timestamp}] ${message}{/}`;
599
+ this.logBuffer.push(coloredMessage);
600
+ if (this.logBuffer.length > this.maxLogLines) {
601
+ this.logBuffer.shift();
602
+ }
603
+ if (this.logBox) {
604
+ this.logBox.log(coloredMessage);
605
+ this.screen.render();
606
+ }
698
607
  }
699
-
700
- // Clean up any remaining processes
701
- for (const [processId, process] of this.activeProcesses) {
702
- try {
703
- if (process.pid && !process.killed) {
704
- process.kill('SIGTERM');
608
+ cleanup() {
609
+ if (this.updateInterval) {
610
+ clearInterval(this.updateInterval);
611
+ }
612
+ // Clean up any remaining processes
613
+ for (const [processId, process1] of this.activeProcesses){
614
+ try {
615
+ if (process1.pid && !process1.killed) {
616
+ process1.kill('SIGTERM');
617
+ }
618
+ } catch (err) {
619
+ // Ignore errors during cleanup
620
+ }
705
621
  }
706
- } catch (err) {
707
- // Ignore errors during cleanup
708
- }
622
+ this.activeProcesses.clear();
709
623
  }
710
- this.activeProcesses.clear();
711
- }
712
- }
713
-
624
+ constructor(){
625
+ this.screen = null;
626
+ this.swarmData = {
627
+ objectives: [],
628
+ agents: [],
629
+ tasks: [],
630
+ status: 'idle'
631
+ };
632
+ this.selectedObjective = null;
633
+ this.updateInterval = null;
634
+ this.logBuffer = [];
635
+ this.maxLogLines = 100;
636
+ this.activeProcesses = new Map(); // Track active processes for cross-platform termination
637
+ }
638
+ };
714
639
  // Main execution
715
640
  async function main() {
716
- const ui = new SwarmUI();
717
-
718
- try {
719
- await ui.init();
720
- } catch (error) {
721
- console.error('Failed to initialize Swarm UI:', error);
722
- process.exit(1);
723
- }
641
+ const ui = new SwarmUI();
642
+ try {
643
+ await ui.init();
644
+ } catch (error) {
645
+ console.error('Failed to initialize Swarm UI:', error);
646
+ process.exit(1);
647
+ }
724
648
  }
725
-
726
649
  // Handle uncaught exceptions
727
- process.on('uncaughtException', (error) => {
728
- console.error('Uncaught exception:', error);
729
- process.exit(1);
650
+ process.on('uncaughtException', (error)=>{
651
+ console.error('Uncaught exception:', error);
652
+ process.exit(1);
730
653
  });
731
-
732
- process.on('unhandledRejection', (error) => {
733
- console.error('Unhandled rejection:', error);
734
- process.exit(1);
654
+ process.on('unhandledRejection', (error)=>{
655
+ console.error('Unhandled rejection:', error);
656
+ process.exit(1);
735
657
  });
736
-
737
658
  if (require.main === module) {
738
- main();
659
+ main();
739
660
  }
740
-
741
661
  module.exports = SwarmUI;