claude-flow 2.0.0-alpha.36 → 2.0.0-alpha.37

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-flow",
3
- "version": "2.0.0-alpha.36",
3
+ "version": "2.0.0-alpha.37",
4
4
  "description": "Enterprise-grade AI agent orchestration with ruv-swarm integration (Alpha Release)",
5
5
  "main": "cli.mjs",
6
6
  "bin": {
@@ -0,0 +1,74 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * Safe wrapper for ruv-swarm MCP server
5
+ * Handles known logger issue in v1.0.8
6
+ */
7
+
8
+ import { spawn } from 'child_process';
9
+ import { createInterface } from 'readline';
10
+
11
+ console.log('šŸš€ Starting ruv-swarm MCP server with error handling...');
12
+
13
+ const ruvSwarmProcess = spawn('npx', ['ruv-swarm', 'mcp', 'start'], {
14
+ stdio: ['pipe', 'pipe', 'pipe'],
15
+ env: {
16
+ ...process.env,
17
+ MCP_MODE: 'stdio',
18
+ LOG_LEVEL: 'WARN'
19
+ }
20
+ });
21
+
22
+ // Forward stdin to ruv-swarm
23
+ process.stdin.pipe(ruvSwarmProcess.stdin);
24
+
25
+ // Handle stdout (JSON-RPC messages)
26
+ ruvSwarmProcess.stdout.pipe(process.stdout);
27
+
28
+ // Handle stderr with filtering
29
+ const rlErr = createInterface({
30
+ input: ruvSwarmProcess.stderr,
31
+ crlfDelay: Infinity
32
+ });
33
+
34
+ let errorHandled = false;
35
+
36
+ rlErr.on('line', (line) => {
37
+ // Filter out the known logger error
38
+ if (line.includes('logger.logMemoryUsage is not a function')) {
39
+ if (!errorHandled) {
40
+ console.error('āš ļø Known ruv-swarm v1.0.8 logger issue detected - continuing normally');
41
+ console.error('šŸ’” This error does not affect functionality');
42
+ errorHandled = true;
43
+ }
44
+ return;
45
+ }
46
+
47
+ // Forward other stderr output
48
+ process.stderr.write(line + '\n');
49
+ });
50
+
51
+ // Handle process exit
52
+ ruvSwarmProcess.on('exit', (code, signal) => {
53
+ if (code !== null && code !== 0) {
54
+ console.error(`\nāŒ ruv-swarm exited with code ${code}`);
55
+ console.error('šŸ’” Try using: npx claude-flow@alpha mcp start');
56
+ }
57
+ process.exit(code || 0);
58
+ });
59
+
60
+ // Handle errors
61
+ ruvSwarmProcess.on('error', (error) => {
62
+ console.error('āŒ Failed to start ruv-swarm:', error.message);
63
+ console.error('šŸ’” Try using: npx claude-flow@alpha mcp start');
64
+ process.exit(1);
65
+ });
66
+
67
+ // Handle termination signals
68
+ process.on('SIGTERM', () => {
69
+ ruvSwarmProcess.kill('SIGTERM');
70
+ });
71
+
72
+ process.on('SIGINT', () => {
73
+ ruvSwarmProcess.kill('SIGINT');
74
+ });
@@ -0,0 +1,202 @@
1
+ /**
2
+ * Wrapper for ruv-swarm MCP server to handle logger issues
3
+ * This wrapper ensures compatibility and handles known issues in ruv-swarm
4
+ */
5
+
6
+ import { spawn } from 'child_process';
7
+ import { createInterface } from 'readline';
8
+
9
+ export class RuvSwarmWrapper {
10
+ constructor(options = {}) {
11
+ this.options = {
12
+ silent: options.silent || false,
13
+ autoRestart: options.autoRestart !== false,
14
+ maxRestarts: options.maxRestarts || 3,
15
+ restartDelay: options.restartDelay || 1000,
16
+ ...options
17
+ };
18
+
19
+ this.process = null;
20
+ this.restartCount = 0;
21
+ this.isShuttingDown = false;
22
+ }
23
+
24
+ async start() {
25
+ if (this.process) {
26
+ throw new Error('RuvSwarm MCP server is already running');
27
+ }
28
+
29
+ return new Promise((resolve, reject) => {
30
+ try {
31
+ // Spawn ruv-swarm MCP server
32
+ this.process = spawn('npx', ['ruv-swarm', 'mcp', 'start'], {
33
+ stdio: ['pipe', 'pipe', 'pipe'],
34
+ env: {
35
+ ...process.env,
36
+ // Ensure stdio mode for MCP
37
+ MCP_MODE: 'stdio',
38
+ // Set log level to reduce noise
39
+ LOG_LEVEL: 'WARN'
40
+ }
41
+ });
42
+
43
+ let initialized = false;
44
+ let initTimeout;
45
+
46
+ // Handle stdout (JSON-RPC messages)
47
+ const rlOut = createInterface({
48
+ input: this.process.stdout,
49
+ crlfDelay: Infinity
50
+ });
51
+
52
+ rlOut.on('line', (line) => {
53
+ try {
54
+ const message = JSON.parse(line);
55
+
56
+ // Check for initialization
57
+ if (message.method === 'server.initialized' && !initialized) {
58
+ initialized = true;
59
+ clearTimeout(initTimeout);
60
+ resolve({
61
+ process: this.process,
62
+ stdout: this.process.stdout,
63
+ stdin: this.process.stdin
64
+ });
65
+ }
66
+
67
+ // Forward JSON-RPC messages
68
+ process.stdout.write(line + '\n');
69
+ } catch (err) {
70
+ // Not JSON, ignore
71
+ }
72
+ });
73
+
74
+ // Handle stderr (logs and errors)
75
+ const rlErr = createInterface({
76
+ input: this.process.stderr,
77
+ crlfDelay: Infinity
78
+ });
79
+
80
+ rlErr.on('line', (line) => {
81
+ // Filter out known harmless errors
82
+ if (line.includes('logger.logMemoryUsage is not a function')) {
83
+ // This is a known issue in ruv-swarm v1.0.8
84
+ // The server continues to work despite this error
85
+ if (!this.options.silent) {
86
+ console.error('āš ļø Known ruv-swarm logger issue detected (continuing normally)');
87
+ }
88
+ return;
89
+ }
90
+
91
+ // Filter out initialization messages if silent
92
+ if (this.options.silent) {
93
+ if (line.includes('āœ…') || line.includes('🧠') || line.includes('šŸ“Š')) {
94
+ return;
95
+ }
96
+ }
97
+
98
+ // Forward other stderr output
99
+ if (!this.options.silent) {
100
+ process.stderr.write(line + '\n');
101
+ }
102
+ });
103
+
104
+ // Handle process errors
105
+ this.process.on('error', (error) => {
106
+ if (!initialized) {
107
+ clearTimeout(initTimeout);
108
+ reject(new Error(`Failed to start ruv-swarm: ${error.message}`));
109
+ } else {
110
+ console.error('RuvSwarm process error:', error);
111
+ this.handleProcessExit(error.code || 1);
112
+ }
113
+ });
114
+
115
+ // Handle process exit
116
+ this.process.on('exit', (code, signal) => {
117
+ if (!initialized) {
118
+ clearTimeout(initTimeout);
119
+ reject(new Error(`RuvSwarm exited before initialization: code ${code}, signal ${signal}`));
120
+ } else {
121
+ this.handleProcessExit(code || 0);
122
+ }
123
+ });
124
+
125
+ // Set initialization timeout
126
+ initTimeout = setTimeout(() => {
127
+ if (!initialized) {
128
+ this.stop();
129
+ reject(new Error('RuvSwarm initialization timeout'));
130
+ }
131
+ }, 30000); // 30 second timeout
132
+
133
+ } catch (error) {
134
+ reject(error);
135
+ }
136
+ });
137
+ }
138
+
139
+ handleProcessExit(code) {
140
+ this.process = null;
141
+
142
+ if (this.isShuttingDown) {
143
+ return;
144
+ }
145
+
146
+ console.error(`RuvSwarm MCP server exited with code ${code}`);
147
+
148
+ // Auto-restart if enabled and under limit
149
+ if (this.options.autoRestart && this.restartCount < this.options.maxRestarts) {
150
+ this.restartCount++;
151
+ console.log(`Attempting to restart RuvSwarm (attempt ${this.restartCount}/${this.options.maxRestarts})...`);
152
+
153
+ setTimeout(() => {
154
+ this.start().catch(err => {
155
+ console.error('Failed to restart RuvSwarm:', err);
156
+ });
157
+ }, this.options.restartDelay);
158
+ }
159
+ }
160
+
161
+ async stop() {
162
+ this.isShuttingDown = true;
163
+
164
+ if (!this.process) {
165
+ return;
166
+ }
167
+
168
+ return new Promise((resolve) => {
169
+ const killTimeout = setTimeout(() => {
170
+ console.warn('RuvSwarm did not exit gracefully, forcing kill...');
171
+ this.process.kill('SIGKILL');
172
+ }, 5000);
173
+
174
+ this.process.on('exit', () => {
175
+ clearTimeout(killTimeout);
176
+ this.process = null;
177
+ resolve();
178
+ });
179
+
180
+ // Send graceful shutdown signal
181
+ this.process.kill('SIGTERM');
182
+ });
183
+ }
184
+
185
+ isRunning() {
186
+ return this.process !== null && !this.process.killed;
187
+ }
188
+ }
189
+
190
+ // Export a function to start ruv-swarm with error handling
191
+ export async function startRuvSwarmMCP(options = {}) {
192
+ const wrapper = new RuvSwarmWrapper(options);
193
+
194
+ try {
195
+ const result = await wrapper.start();
196
+ console.log('āœ… RuvSwarm MCP server started successfully');
197
+ return { wrapper, ...result };
198
+ } catch (error) {
199
+ console.error('āŒ Failed to start RuvSwarm MCP server:', error.message);
200
+ throw error;
201
+ }
202
+ }