claude-flow-novice 1.3.0 → 1.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-flow-novice/preferences/generation.json +147 -0
- package/.claude-flow-novice/preferences/language-configs/javascript.json +51 -0
- package/.claude-flow-novice/preferences/language-configs/python.json +50 -0
- package/.claude-flow-novice/preferences/language-configs/rust.json +237 -0
- package/.claude-flow-novice/preferences/language-configs/typescript.json +54 -0
- package/.claude-flow-novice/preferences/project-local.json +91 -0
- package/.claude-flow-novice/preferences/resource-delegation.json +120 -0
- package/.claude-flow-novice/preferences/team-shared.json +195 -0
- package/.claude-flow-novice/preferences/user-global.json +247 -0
- package/.claude-flow-novice/templates/claude-md-templates/CLAUDE-JAVASCRIPT.md +769 -0
- package/.claude-flow-novice/templates/claude-md-templates/CLAUDE-PYTHON.md +1214 -0
- package/.claude-flow-novice/templates/claude-md-templates/CLAUDE-RUST.md +475 -0
- package/.claude-flow-novice/templates/claude-md-templates/CLAUDE-TYPESCRIPT.md +851 -0
- package/.claude-flow-novice/templates/claude-md-templates/README.md +263 -0
- package/CLAUDE.md +81 -0
- package/README-NPM.md +0 -0
- package/package.json +11 -7
- package/scripts/build/README.md +167 -0
- package/scripts/build/build-config.js +27 -0
- package/scripts/build/build-prompt-copier.sh +30 -0
- package/scripts/build/performance-monitor.js +869 -0
- package/scripts/build/prepare-publish.js +150 -0
- package/scripts/build/typescript-fixer.js +621 -0
- package/scripts/build/unified-builder.sh +428 -0
- package/scripts/build/update-bin-version.js +32 -0
- package/scripts/dev/README.md +264 -0
- package/scripts/dev/claude-flow-wrapper.sh +35 -0
- package/scripts/dev/claude-monitor.py +419 -0
- package/scripts/dev/claude-sparc.sh +562 -0
- package/scripts/dev/claude-wrapper.sh +17 -0
- package/scripts/dev/demo-phase3-compliance.js +172 -0
- package/scripts/dev/demo-task-system.ts +224 -0
- package/scripts/dev/deployment-validator.js +315 -0
- package/scripts/dev/spawn-claude-terminal.sh +32 -0
- package/scripts/dev/start-portal.sh +506 -0
- package/scripts/dev/start-web-ui.js +15 -0
- package/scripts/dev/stop-portal.sh +311 -0
- package/scripts/dev/validate-examples.ts +288 -0
- package/scripts/dev/validate-phase2.cjs +451 -0
- package/scripts/dev/validate-phase2.js +785 -0
- package/scripts/dev/validate-phase3.cjs +208 -0
- package/scripts/dev/validate-security-remediation.js +1 -0
- package/scripts/legacy/README.md +272 -0
- package/scripts/legacy/batch-fix-ts.sh +54 -0
- package/scripts/legacy/build-migration.sh +105 -0
- package/scripts/legacy/build-monitor.js +209 -0
- package/scripts/legacy/build-with-filter.sh +84 -0
- package/scripts/legacy/build-workaround.sh +71 -0
- package/scripts/legacy/fix-ts-advanced.js +358 -0
- package/scripts/legacy/fix-ts-final.sh +50 -0
- package/scripts/legacy/fix-ts-targeted.sh +49 -0
- package/scripts/legacy/fix-typescript-errors.js +305 -0
- package/scripts/legacy/force-build.sh +63 -0
- package/scripts/legacy/optimize-performance.js +400 -0
- package/scripts/legacy/performance-monitor.js +263 -0
- package/scripts/legacy/performance-monitoring.js +532 -0
- package/scripts/legacy/performance-test-runner.js +645 -0
- package/scripts/legacy/quick-fix-ts.js +281 -0
- package/scripts/legacy/safe-build.sh +63 -0
- package/scripts/migration/README.md +434 -0
- package/scripts/migration/install-arm64.js +78 -0
- package/scripts/migration/install.js +83 -0
- package/scripts/migration/migrate-hooks.js +173 -0
- package/scripts/migration/migration-examples.ts +318 -0
- package/scripts/optimization/build-optimizer.js +438 -0
- package/scripts/optimization/config-validator.js +761 -0
- package/scripts/optimization/test-optimization.js +432 -0
- package/scripts/optimization/unified-activation.js +839 -0
- package/scripts/performance/ACTIVATION_COMMANDS.md +292 -0
- package/scripts/performance/sqlite-enhanced-activation.sh +583 -0
- package/scripts/performance/test-enhanced-backend.sh +504 -0
- package/scripts/performance-test-runner.js +698 -0
- package/scripts/security/README.md +339 -0
- package/scripts/security/install-git-hooks.sh +132 -0
- package/scripts/security/ruv-swarm-safe.js +74 -0
- package/scripts/test/README.md +236 -0
- package/scripts/test/check-links.ts +274 -0
- package/scripts/test/check-performance-regression.ts +168 -0
- package/scripts/test/coverage-report.ts +692 -0
- package/scripts/test/generate-swarm-tests.js +633 -0
- package/scripts/test/integration-test-validation.cjs +253 -0
- package/scripts/test/load-test-swarm.js +576 -0
- package/scripts/test/run-phase3-compliance-tests.js +427 -0
- package/scripts/test/test-batch-tasks.ts +29 -0
- package/scripts/test/test-byzantine-resolution.js +246 -0
- package/scripts/test/test-claude-spawn-options.sh +63 -0
- package/scripts/test/test-cli-wizard.js +331 -0
- package/scripts/test/test-comprehensive.js +401 -0
- package/scripts/test/test-coordination-features.ts +238 -0
- package/scripts/test/test-fallback-systems.js +276 -0
- package/scripts/test/test-init-command.ts +302 -0
- package/scripts/test/test-mcp.ts +251 -0
- package/scripts/test/test-runner.ts +568 -0
- package/scripts/test/test-swarm-integration.sh +92 -0
- package/scripts/test/test-swarm.ts +142 -0
- package/scripts/test/validation-summary.ts +408 -0
- package/scripts/utils/README.md +261 -0
- package/scripts/utils/clean-build-artifacts.sh +94 -0
- package/scripts/utils/cleanup-root.sh +69 -0
- package/scripts/utils/fix-cliffy-imports.js +307 -0
- package/scripts/utils/fix-duplicate-imports.js +114 -0
- package/scripts/utils/fix-error-handling.cjs +70 -0
- package/scripts/utils/fix-import-paths.js +104 -0
- package/scripts/utils/fix-imports.js +116 -0
- package/scripts/utils/fix-shebang.js +78 -0
- package/scripts/utils/fix-test-modules.js +27 -0
- package/scripts/utils/fix-timezone-issue-246.js +200 -0
- package/scripts/utils/fix-ts-comprehensive.py +182 -0
- package/scripts/utils/fix-ts-targeted-batch.js +250 -0
- package/scripts/utils/remove-benchmark-conflicts.sh +140 -0
- package/scripts/utils/simple-test-fixer.js +190 -0
- package/scripts/utils/validate-metrics-structure.cjs +144 -0
- package/scripts/verify-mcp-server.js +86 -0
- package/src/cli/simple-commands/__tests__/agent.test.js +291 -0
- package/src/cli/simple-commands/__tests__/memory.test.js +8 -0
- package/src/cli/simple-commands/__tests__/swarm.test.js +371 -0
- package/src/cli/simple-commands/__tests__/task.test.js +8 -0
- package/src/cli/simple-commands/agent.js +216 -0
- package/src/cli/simple-commands/analysis.js +570 -0
- package/src/cli/simple-commands/automation-executor.js +1603 -0
- package/src/cli/simple-commands/automation.js +627 -0
- package/src/cli/simple-commands/batch-manager.js +338 -0
- package/src/cli/simple-commands/claude-telemetry.js +311 -0
- package/src/cli/simple-commands/claude-track.js +102 -0
- package/src/cli/simple-commands/concurrent-display.js +348 -0
- package/src/cli/simple-commands/config.js +319 -0
- package/src/cli/simple-commands/coordination.js +307 -0
- package/src/cli/simple-commands/enhanced-ui-views.js +654 -0
- package/src/cli/simple-commands/enhanced-webui-complete.js +1038 -0
- package/src/cli/simple-commands/fix-hook-variables.js +363 -0
- package/src/cli/simple-commands/github/gh-coordinator.js +605 -0
- package/src/cli/simple-commands/github/github-api.js +624 -0
- package/src/cli/simple-commands/github/init.js +543 -0
- package/src/cli/simple-commands/github.js +377 -0
- package/src/cli/simple-commands/goal.js +145 -0
- package/src/cli/simple-commands/hive-mind/auto-save-middleware.js +311 -0
- package/src/cli/simple-commands/hive-mind/communication.js +740 -0
- package/src/cli/simple-commands/hive-mind/core.js +1031 -0
- package/src/cli/simple-commands/hive-mind/db-optimizer.js +872 -0
- package/src/cli/simple-commands/hive-mind/mcp-wrapper.js +1364 -0
- package/src/cli/simple-commands/hive-mind/memory.js +1292 -0
- package/src/cli/simple-commands/hive-mind/performance-optimizer.js +618 -0
- package/src/cli/simple-commands/hive-mind/performance-test.js +373 -0
- package/src/cli/simple-commands/hive-mind/queen.js +809 -0
- package/src/cli/simple-commands/hive-mind/session-manager.js +1223 -0
- package/src/cli/simple-commands/hive-mind-optimize.js +361 -0
- package/src/cli/simple-commands/hive-mind-wizard.js +281 -0
- package/src/cli/simple-commands/hive-mind.js +3112 -0
- package/src/cli/simple-commands/hive.js +140 -0
- package/src/cli/simple-commands/hook-safety.js +671 -0
- package/src/cli/simple-commands/hooks.js +1268 -0
- package/src/cli/simple-commands/init/.claude/checkpoints/1756224542.json +7 -0
- package/src/cli/simple-commands/init/.claude/checkpoints/1756224544.json +8 -0
- package/src/cli/simple-commands/init/README.md +106 -0
- package/src/cli/simple-commands/init/VALIDATION_ROLLBACK.md +488 -0
- package/src/cli/simple-commands/init/agent-copier.js +347 -0
- package/src/cli/simple-commands/init/batch-init.js +663 -0
- package/src/cli/simple-commands/init/claude-commands/claude-flow-commands.js +438 -0
- package/src/cli/simple-commands/init/claude-commands/optimized-claude-flow-commands.js +876 -0
- package/src/cli/simple-commands/init/claude-commands/optimized-slash-commands.js +356 -0
- package/src/cli/simple-commands/init/claude-commands/optimized-sparc-commands.js +501 -0
- package/src/cli/simple-commands/init/claude-commands/slash-commands.js +57 -0
- package/src/cli/simple-commands/init/claude-commands/sparc-commands.js +296 -0
- package/src/cli/simple-commands/init/copy-revised-templates.js +175 -0
- package/src/cli/simple-commands/init/executable-wrapper.js +122 -0
- package/src/cli/simple-commands/init/gitignore-updater.js +137 -0
- package/src/cli/simple-commands/init/help.js +110 -0
- package/src/cli/simple-commands/init/hive-mind-init.js +749 -0
- package/src/cli/simple-commands/init/index.js +1953 -0
- package/src/cli/simple-commands/init/performance-monitor.js +344 -0
- package/src/cli/simple-commands/init/rollback/backup-manager.js +542 -0
- package/src/cli/simple-commands/init/rollback/index.js +399 -0
- package/src/cli/simple-commands/init/rollback/recovery-manager.js +778 -0
- package/src/cli/simple-commands/init/rollback/rollback-executor.js +521 -0
- package/src/cli/simple-commands/init/rollback/state-tracker.js +486 -0
- package/src/cli/simple-commands/init/sparc/roo-readme.js +61 -0
- package/src/cli/simple-commands/init/sparc/roomodes-config.js +102 -0
- package/src/cli/simple-commands/init/sparc/workflows.js +40 -0
- package/src/cli/simple-commands/init/sparc-structure.js +68 -0
- package/src/cli/simple-commands/init/template-copier.js +640 -0
- package/src/cli/simple-commands/init/templates/CLAUDE.md +1185 -0
- package/src/cli/simple-commands/init/templates/CLAUDE.md.optimized +265 -0
- package/src/cli/simple-commands/init/templates/claude-flow-universal +81 -0
- package/src/cli/simple-commands/init/templates/claude-flow.bat +18 -0
- package/src/cli/simple-commands/init/templates/claude-flow.ps1 +24 -0
- package/src/cli/simple-commands/init/templates/claude-md.js +1101 -0
- package/src/cli/simple-commands/init/templates/commands/analysis/bottleneck-detect.md +162 -0
- package/src/cli/simple-commands/init/templates/commands/automation/auto-agent.md +122 -0
- package/src/cli/simple-commands/init/templates/commands/coordination/swarm-init.md +85 -0
- package/src/cli/simple-commands/init/templates/commands/github/github-swarm.md +121 -0
- package/src/cli/simple-commands/init/templates/commands/helpers/standard-checkpoint-hooks.sh +179 -0
- package/src/cli/simple-commands/init/templates/commands/hooks/notification.md +113 -0
- package/src/cli/simple-commands/init/templates/commands/hooks/post-command.md +116 -0
- package/src/cli/simple-commands/init/templates/commands/hooks/post-edit.md +117 -0
- package/src/cli/simple-commands/init/templates/commands/hooks/post-task.md +112 -0
- package/src/cli/simple-commands/init/templates/commands/hooks/pre-command.md +113 -0
- package/src/cli/simple-commands/init/templates/commands/hooks/pre-edit.md +113 -0
- package/src/cli/simple-commands/init/templates/commands/hooks/pre-search.md +112 -0
- package/src/cli/simple-commands/init/templates/commands/hooks/pre-task.md +111 -0
- package/src/cli/simple-commands/init/templates/commands/hooks/session-end.md +118 -0
- package/src/cli/simple-commands/init/templates/commands/hooks/session-restore.md +118 -0
- package/src/cli/simple-commands/init/templates/commands/hooks/session-start.md +117 -0
- package/src/cli/simple-commands/init/templates/coordination-md.js +340 -0
- package/src/cli/simple-commands/init/templates/coordination.md +16 -0
- package/src/cli/simple-commands/init/templates/enhanced-templates.js +2347 -0
- package/src/cli/simple-commands/init/templates/github-safe-enhanced.js +331 -0
- package/src/cli/simple-commands/init/templates/github-safe.js +106 -0
- package/src/cli/simple-commands/init/templates/memory-bank-md.js +259 -0
- package/src/cli/simple-commands/init/templates/memory-bank.md +16 -0
- package/src/cli/simple-commands/init/templates/readme-files.js +72 -0
- package/src/cli/simple-commands/init/templates/safe-hook-patterns.js +430 -0
- package/src/cli/simple-commands/init/templates/settings.json +109 -0
- package/src/cli/simple-commands/init/templates/settings.json.enhanced +35 -0
- package/src/cli/simple-commands/init/templates/sparc-modes.js +1401 -0
- package/src/cli/simple-commands/init/templates/verification-claude-md.js +432 -0
- package/src/cli/simple-commands/init/validation/config-validator.js +354 -0
- package/src/cli/simple-commands/init/validation/health-checker.js +599 -0
- package/src/cli/simple-commands/init/validation/index.js +388 -0
- package/src/cli/simple-commands/init/validation/mode-validator.js +387 -0
- package/src/cli/simple-commands/init/validation/post-init-validator.js +390 -0
- package/src/cli/simple-commands/init/validation/pre-init-validator.js +290 -0
- package/src/cli/simple-commands/init/validation/test-runner.js +488 -0
- package/src/cli/simple-commands/init.js +4 -0
- package/src/cli/simple-commands/mcp-health.js +163 -0
- package/src/cli/simple-commands/mcp-integration-layer.js +689 -0
- package/src/cli/simple-commands/mcp.js +420 -0
- package/src/cli/simple-commands/memory-consolidation.js +631 -0
- package/src/cli/simple-commands/memory.js +345 -0
- package/src/cli/simple-commands/migrate-hooks.js +63 -0
- package/src/cli/simple-commands/monitor.js +417 -0
- package/src/cli/simple-commands/neural.js +148 -0
- package/src/cli/simple-commands/pair-autofix-only.js +755 -0
- package/src/cli/simple-commands/pair-basic.js +751 -0
- package/src/cli/simple-commands/pair-old.js +623 -0
- package/src/cli/simple-commands/pair-working.js +849 -0
- package/src/cli/simple-commands/pair.js +849 -0
- package/src/cli/simple-commands/performance-hooks.js +149 -0
- package/src/cli/simple-commands/performance-metrics.js +601 -0
- package/src/cli/simple-commands/process-ui-enhanced.js +821 -0
- package/src/cli/simple-commands/process-ui.js +274 -0
- package/src/cli/simple-commands/realtime-update-system.js +659 -0
- package/src/cli/simple-commands/sparc/architecture.js +1750 -0
- package/src/cli/simple-commands/sparc/commands.js +575 -0
- package/src/cli/simple-commands/sparc/completion.js +1831 -0
- package/src/cli/simple-commands/sparc/coordinator.js +1045 -0
- package/src/cli/simple-commands/sparc/index.js +321 -0
- package/src/cli/simple-commands/sparc/phase-base.js +430 -0
- package/src/cli/simple-commands/sparc/pseudocode.js +984 -0
- package/src/cli/simple-commands/sparc/refinement.js +1856 -0
- package/src/cli/simple-commands/sparc/specification.js +736 -0
- package/src/cli/simple-commands/sparc-modes/architect.js +125 -0
- package/src/cli/simple-commands/sparc-modes/ask.js +126 -0
- package/src/cli/simple-commands/sparc-modes/code.js +148 -0
- package/src/cli/simple-commands/sparc-modes/debug.js +112 -0
- package/src/cli/simple-commands/sparc-modes/devops.js +137 -0
- package/src/cli/simple-commands/sparc-modes/docs-writer.js +38 -0
- package/src/cli/simple-commands/sparc-modes/generic.js +34 -0
- package/src/cli/simple-commands/sparc-modes/index.js +201 -0
- package/src/cli/simple-commands/sparc-modes/integration.js +55 -0
- package/src/cli/simple-commands/sparc-modes/mcp.js +38 -0
- package/src/cli/simple-commands/sparc-modes/monitoring.js +38 -0
- package/src/cli/simple-commands/sparc-modes/optimization.js +38 -0
- package/src/cli/simple-commands/sparc-modes/security-review.js +130 -0
- package/src/cli/simple-commands/sparc-modes/sparc-orchestrator.js +167 -0
- package/src/cli/simple-commands/sparc-modes/spec-pseudocode.js +38 -0
- package/src/cli/simple-commands/sparc-modes/supabase-admin.js +149 -0
- package/src/cli/simple-commands/sparc-modes/swarm.js +436 -0
- package/src/cli/simple-commands/sparc-modes/tdd.js +112 -0
- package/src/cli/simple-commands/sparc-modes/tutorial.js +277 -0
- package/src/cli/simple-commands/sparc.js +530 -0
- package/src/cli/simple-commands/start-ui.js +147 -0
- package/src/cli/simple-commands/start-wrapper.js +285 -0
- package/src/cli/simple-commands/start.js +2 -0
- package/src/cli/simple-commands/status.js +303 -0
- package/src/cli/simple-commands/stream-chain-clean.js +221 -0
- package/src/cli/simple-commands/stream-chain-fixed.js +89 -0
- package/src/cli/simple-commands/stream-chain-real.js +408 -0
- package/src/cli/simple-commands/stream-chain-working.js +323 -0
- package/src/cli/simple-commands/stream-chain.js +491 -0
- package/src/cli/simple-commands/stream-processor.js +340 -0
- package/src/cli/simple-commands/swarm-executor.js +253 -0
- package/src/cli/simple-commands/swarm-metrics-integration.js +371 -0
- package/src/cli/simple-commands/swarm-ui.js +741 -0
- package/src/cli/simple-commands/swarm-webui-integration.js +311 -0
- package/src/cli/simple-commands/swarm.js +2277 -0
- package/src/cli/simple-commands/task.js +228 -0
- package/src/cli/simple-commands/templates/mle-star-workflow.json +294 -0
- package/src/cli/simple-commands/timestamp-fix.js +104 -0
- package/src/cli/simple-commands/token-tracker.js +372 -0
- package/src/cli/simple-commands/tool-execution-framework.js +555 -0
- package/src/cli/simple-commands/train-and-stream.js +354 -0
- package/src/cli/simple-commands/training-pipeline.js +874 -0
- package/src/cli/simple-commands/training.js +288 -0
- package/src/cli/simple-commands/verification-hooks.js +336 -0
- package/src/cli/simple-commands/verification-integration.js +464 -0
- package/src/cli/simple-commands/verification-training-integration.js +646 -0
- package/src/cli/simple-commands/verification.js +551 -0
- package/src/cli/simple-commands/web-server.js +929 -0
- package/src/cli/simple-commands/webui-validator.js +136 -0
- package/src/language/README.md +503 -0
- package/src/language/claude-md-generator.js +618 -0
- package/src/language/cli.js +422 -0
- package/src/language/example.js +347 -0
- package/src/language/integration-system.js +619 -0
- package/src/language/language-detector.js +581 -0
|
@@ -0,0 +1,741 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Enhanced Swarm UI with real-time monitoring and control
|
|
5
|
+
* Uses blessed for terminal UI
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const blessed = require('blessed');
|
|
9
|
+
const fs = require('fs').promises;
|
|
10
|
+
const path = require('path');
|
|
11
|
+
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');
|
|
400
|
+
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
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
} catch (e) {
|
|
421
|
+
// No agents directory
|
|
422
|
+
}
|
|
423
|
+
} catch (e) {
|
|
424
|
+
// Skip invalid config files
|
|
425
|
+
}
|
|
426
|
+
}
|
|
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
|
+
}
|
|
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();
|
|
465
|
+
}
|
|
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');
|
|
566
|
+
}
|
|
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) {
|
|
578
|
+
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');
|
|
588
|
+
}
|
|
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
|
+
}
|
|
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 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}`);
|
|
627
|
+
}
|
|
628
|
+
});
|
|
629
|
+
});
|
|
630
|
+
}
|
|
631
|
+
},
|
|
632
|
+
);
|
|
633
|
+
} else {
|
|
634
|
+
// Unix-like systems: Use ps and grep
|
|
635
|
+
exec('ps aux | grep "claude-flow 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
|
+
}
|
|
649
|
+
});
|
|
650
|
+
}
|
|
651
|
+
});
|
|
652
|
+
}
|
|
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');
|
|
663
|
+
} else {
|
|
664
|
+
if (stdout) this.log(`Output: ${stdout.trim()}`);
|
|
665
|
+
if (stderr) this.log(`Error: ${stderr.trim()}`, 'warn');
|
|
666
|
+
}
|
|
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
|
+
}
|
|
688
|
+
|
|
689
|
+
if (this.logBox) {
|
|
690
|
+
this.logBox.log(coloredMessage);
|
|
691
|
+
this.screen.render();
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
cleanup() {
|
|
696
|
+
if (this.updateInterval) {
|
|
697
|
+
clearInterval(this.updateInterval);
|
|
698
|
+
}
|
|
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');
|
|
705
|
+
}
|
|
706
|
+
} catch (err) {
|
|
707
|
+
// Ignore errors during cleanup
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
this.activeProcesses.clear();
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
// Main execution
|
|
715
|
+
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
|
+
}
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
// Handle uncaught exceptions
|
|
727
|
+
process.on('uncaughtException', (error) => {
|
|
728
|
+
console.error('Uncaught exception:', error);
|
|
729
|
+
process.exit(1);
|
|
730
|
+
});
|
|
731
|
+
|
|
732
|
+
process.on('unhandledRejection', (error) => {
|
|
733
|
+
console.error('Unhandled rejection:', error);
|
|
734
|
+
process.exit(1);
|
|
735
|
+
});
|
|
736
|
+
|
|
737
|
+
if (require.main === module) {
|
|
738
|
+
main();
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
module.exports = SwarmUI;
|