snow-flow 4.6.5 → 4.6.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -53,6 +53,10 @@ const agent_detector_js_1 = require("./utils/agent-detector.js");
53
53
  const version_js_1 = require("./version.js");
54
54
  const logger_js_1 = require("./utils/logger.js");
55
55
  const chalk_1 = __importDefault(require("chalk"));
56
+ // Load MCP Persistent Guard for bulletproof server protection
57
+ const mcp_persistent_guard_js_1 = require("./utils/mcp-persistent-guard.js");
58
+ // Activate protection immediately
59
+ mcp_persistent_guard_js_1.MCPPersistentGuard.getInstance();
56
60
  // Removed provider-agnostic imports - using Claude Code directly
57
61
  const auth_js_1 = require("./cli/auth.js");
58
62
  const session_js_1 = require("./cli/session.js");
@@ -93,76 +97,6 @@ function checkFlowDeprecation(command, objective) {
93
97
  process.exit(1);
94
98
  }
95
99
  }
96
-
97
- // Claude Code version management - ensure 1.0.95 is installed
98
- async function ensureClaudeCodeVersion() {
99
- try {
100
- cliLogger.info('šŸ”§ Checking Claude Code version compatibility...');
101
-
102
- // Check if Claude Code is installed and get version
103
- const checkVersionResult = (0, child_process_1.execSync)('claude --version 2>/dev/null || echo "not_installed"', {
104
- encoding: 'utf8',
105
- timeout: 10000
106
- }).trim();
107
-
108
- const currentVersion = checkVersionResult.includes('not_installed') ? null :
109
- checkVersionResult.match(/(\d+\.\d+\.\d+)/)?.[1];
110
-
111
- cliLogger.info(`šŸ” Current Claude Code version: ${currentVersion || 'not installed'}`);
112
-
113
- // Target version that works correctly
114
- const targetVersion = '1.0.95';
115
-
116
- if (currentVersion !== targetVersion) {
117
- cliLogger.info(`āš ļø Version mismatch detected. Installing Claude Code ${targetVersion}...`);
118
- cliLogger.info('šŸ“„ This prevents bugs in newer versions that cause hanging operations');
119
-
120
- try {
121
- // Install the specific version
122
- cliLogger.info('šŸ”„ Running: npm install -g @anthropic-ai/claude-code@1.0.95');
123
- (0, child_process_1.execSync)('npm install -g @anthropic-ai/claude-code@1.0.95', {
124
- stdio: 'inherit',
125
- timeout: 120000 // 2 minutes timeout
126
- });
127
-
128
- // Verify installation
129
- const verifyResult = (0, child_process_1.execSync)('claude --version', {
130
- encoding: 'utf8',
131
- timeout: 10000
132
- }).trim();
133
-
134
- const installedVersion = verifyResult.match(/(\d+\.\d+\.\d+)/)?.[1];
135
-
136
- if (installedVersion === targetVersion) {
137
- cliLogger.info(`āœ… Claude Code ${targetVersion} installed successfully!`);
138
- } else {
139
- cliLogger.warn(`āš ļø Installation completed but version verification shows: ${installedVersion}`);
140
- }
141
- } catch (installError) {
142
- cliLogger.error('āŒ Failed to install Claude Code 1.0.95');
143
- cliLogger.error('Please install manually: npm install -g @anthropic-ai/claude-code@1.0.95');
144
- throw new Error(`Claude Code installation failed: ${installError.message}`);
145
- }
146
- } else {
147
- cliLogger.info(`āœ… Claude Code ${targetVersion} is already installed`);
148
- }
149
-
150
- cliLogger.info('šŸš€ Claude Code version check completed successfully');
151
-
152
- } catch (error) {
153
- cliLogger.error('āŒ Claude Code version check failed:', error.message);
154
-
155
- // Provide fallback guidance
156
- cliLogger.info('');
157
- cliLogger.info('šŸ”§ Manual installation instructions:');
158
- cliLogger.info(' npm install -g @anthropic-ai/claude-code@1.0.95');
159
- cliLogger.info('');
160
- cliLogger.info('āš ļø Note: Version 1.0.95 is required to avoid hanging operations in swarm mode');
161
-
162
- // Don't fail completely, but warn user
163
- cliLogger.warn('āš ļø Continuing with potentially incompatible Claude Code version');
164
- }
165
- }
166
100
  // Swarm command - the main orchestration command with EVERYTHING
167
101
  program
168
102
  .command('swarm <objective>')
@@ -222,10 +156,6 @@ program
222
156
  .action(async (objective, options) => {
223
157
  // Check for flow deprecation first
224
158
  checkFlowDeprecation('swarm', objective);
225
-
226
- // Ensure Claude Code version 1.0.95 is installed before proceeding
227
- await ensureClaudeCodeVersion();
228
-
229
159
  // Set debug levels based on options
230
160
  if (options.debugAll) {
231
161
  process.env.DEBUG = '*';
@@ -3243,8 +3173,7 @@ program
3243
3173
  }
3244
3174
  process.exit(1);
3245
3175
  }
3246
- // DISABLED: Queen shutdown disabled for persistence
3247
- // await queenIntegration.shutdown();
3176
+ await queenIntegration.shutdown();
3248
3177
  }
3249
3178
  catch (error) {
3250
3179
  console.error('\nšŸ’„ Queen Agent error:', error.message);
@@ -3271,8 +3200,7 @@ queenMemory
3271
3200
  await fs.writeFile(file, memoryData, 'utf-8');
3272
3201
  console.log(`āœ… Memory exported successfully to ${file}`);
3273
3202
  console.log(`šŸ“Š Memory contains learned patterns and successful deployments`);
3274
- // DISABLED: Queen shutdown disabled for persistence
3275
- // await queen.shutdown();
3203
+ await queen.shutdown();
3276
3204
  }
3277
3205
  catch (error) {
3278
3206
  console.error('āŒ Memory export failed:', error.message);
@@ -3292,8 +3220,7 @@ queenMemory
3292
3220
  queen.importMemory(memoryData);
3293
3221
  console.log(`āœ… Memory imported successfully from ${file}`);
3294
3222
  console.log(`🧠 Queen now has access to previous learning patterns`);
3295
- // DISABLED: Queen shutdown disabled for persistence
3296
- // await queen.shutdown();
3223
+ await queen.shutdown();
3297
3224
  }
3298
3225
  catch (error) {
3299
3226
  console.error('āŒ Memory import failed:', error.message);
@@ -3317,8 +3244,7 @@ queenMemory
3317
3244
  queen.clearMemory();
3318
3245
  console.log('āœ… Queen memory cleared successfully');
3319
3246
  console.log('šŸ”„ Queen will start fresh learning from next execution');
3320
- // DISABLED: Queen shutdown disabled for persistence
3321
- // await queen.shutdown();
3247
+ await queen.shutdown();
3322
3248
  }
3323
3249
  catch (error) {
3324
3250
  console.error('āŒ Memory clear failed:', error.message);
@@ -3358,8 +3284,7 @@ program
3358
3284
  console.log(` Most Effective Pattern: ${status.memoryStats.bestPattern || 'Learning...'}`);
3359
3285
  }
3360
3286
  console.log('═══════════════════════\n');
3361
- // DISABLED: Queen shutdown disabled for persistence
3362
- // await queen.shutdown();
3287
+ await queen.shutdown();
3363
3288
  }
3364
3289
  catch (error) {
3365
3290
  console.error('āŒ Status check failed:', error.message);
@@ -3399,8 +3324,7 @@ program
3399
3324
  });
3400
3325
  }
3401
3326
  console.log('═══════════════════════\n');
3402
- // DISABLED: Queen shutdown disabled for persistence
3403
- // await queen.shutdown();
3327
+ await queen.shutdown();
3404
3328
  }
3405
3329
  catch (error) {
3406
3330
  console.error('āŒ Insights failed:', error.message);
@@ -503,10 +503,6 @@ class MCPExecutionBridge extends eventemitter3_1.EventEmitter {
503
503
  this.logger.error(`Error disconnecting from ${name}:`, error);
504
504
  }
505
505
  }
506
- // DISABLED: Process termination disabled for persistent servers
507
- this.logger.info('šŸ›‘ DISABLED: MCP process termination disabled for persistence');
508
- this.logger.info('šŸ”„ All MCP server processes will continue running indefinitely');
509
- /*
510
506
  // Terminate all processes
511
507
  for (const [name, process] of this.mcpProcesses) {
512
508
  try {
@@ -519,7 +515,6 @@ class MCPExecutionBridge extends eventemitter3_1.EventEmitter {
519
515
  }
520
516
  this.mcpClients.clear();
521
517
  this.mcpProcesses.clear();
522
- */
523
518
  }
524
519
  /**
525
520
  * Disconnect from MCP resources
@@ -958,20 +958,22 @@ function($scope) {
958
958
  // DISABLED: All shutdown logic for persistent operation
959
959
  /*
960
960
  if (this.config.debugMode) {
961
- this.logger.info('šŸ›‘ Shutting down ServiceNow Queen Agent');
961
+ this.logger.info('šŸ›‘ Shutting down ServiceNow Queen Agent');
962
962
  }
963
+
963
964
  // Clean up all agents
964
965
  const activeAgents = this.agentFactory.getActiveAgents();
965
966
  for (const agent of activeAgents) {
966
- this.agentFactory.terminateAgent(agent.id);
967
+ this.agentFactory.terminateAgent(agent.id);
967
968
  }
969
+
968
970
  // Shutdown MCP Bridge
969
971
  if (this.mcpBridge) {
970
- await this.mcpBridge.shutdown();
972
+ await this.mcpBridge.shutdown();
971
973
  }
974
+ */
972
975
  // Close memory system
973
976
  this.memory.close();
974
- */
975
977
  }
976
978
  /**
977
979
  * STRATEGIC ORCHESTRATION METHODS
@@ -293,10 +293,6 @@ class SnowFlowSystem extends events_1.EventEmitter {
293
293
  await this.gracefullyCompleteSession(session.id);
294
294
  }
295
295
  }
296
- // DISABLED: All shutdown logic for persistent operation
297
- this.logger.info('šŸ›‘ DISABLED: Snow-Flow system shutdown disabled for persistence');
298
- this.logger.info('šŸ”„ All components will continue running indefinitely');
299
- /*
300
296
  // Shutdown components in reverse order
301
297
  await this.systemHealth?.stopMonitoring();
302
298
  await this.performanceTracker?.shutdown();
@@ -311,7 +307,6 @@ class SnowFlowSystem extends events_1.EventEmitter {
311
307
  await this.memory?.close();
312
308
  this.initialized = false;
313
309
  this.emit('system:shutdown');
314
- */"
315
310
  this.logger.info('Snow-Flow System shutdown complete');
316
311
  }
317
312
  catch (error) {
@@ -0,0 +1,51 @@
1
+ /**
2
+ * MCP Persistent Server Guard
3
+ * Ultimate protection against any MCP server shutdown
4
+ * Overrides all possible shutdown mechanisms
5
+ */
6
+ export declare class MCPPersistentGuard {
7
+ private static instance;
8
+ private logger;
9
+ private isActive;
10
+ private originalProcessKill;
11
+ private originalProcessExit;
12
+ private protectedProcesses;
13
+ constructor();
14
+ static getInstance(): MCPPersistentGuard;
15
+ /**
16
+ * Protect MCP processes from being killed
17
+ */
18
+ private installProcessProtection;
19
+ /**
20
+ * Warn about process exit attempts
21
+ */
22
+ private installExitProtection;
23
+ /**
24
+ * Check if PID belongs to MCP server
25
+ */
26
+ private isMCPProcess;
27
+ /**
28
+ * Monitor for shutdown attempts
29
+ */
30
+ private startShutdownMonitoring;
31
+ /**
32
+ * Register a process for protection
33
+ */
34
+ protectProcess(pid: number, name: string): void;
35
+ /**
36
+ * Remove protection (emergency use only)
37
+ */
38
+ removeProtection(pid: number): void;
39
+ /**
40
+ * Get protection status
41
+ */
42
+ getProtectionStatus(): {
43
+ isActive: boolean;
44
+ protectedProcessCount: number;
45
+ protectedProcesses: Array<{
46
+ pid: number;
47
+ name: string;
48
+ }>;
49
+ };
50
+ }
51
+ //# sourceMappingURL=mcp-persistent-guard.d.ts.map
@@ -1,38 +1,34 @@
1
+ "use strict";
1
2
  /**
2
3
  * MCP Persistent Server Guard
3
4
  * Ultimate protection against any MCP server shutdown
4
5
  * Overrides all possible shutdown mechanisms
5
6
  */
6
-
7
- const logger = require('./logger.js');
8
- const mcpLogger = new logger.Logger('MCPPersistentGuard');
9
-
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.MCPPersistentGuard = void 0;
9
+ const logger_1 = require("./logger");
10
+ const child_process_1 = require("child_process");
10
11
  class MCPPersistentGuard {
11
12
  constructor() {
12
13
  this.isActive = true;
14
+ this.protectedProcesses = new Set();
15
+ this.logger = new logger_1.Logger('MCPPersistentGuard');
13
16
  this.originalProcessKill = process.kill;
14
17
  this.originalProcessExit = process.exit;
15
- this.protectedProcesses = new Set();
16
-
17
- mcpLogger.info('šŸ›”ļø MCP Persistent Guard activated - servers protected from shutdown');
18
-
18
+ this.logger.info('šŸ›”ļø MCP Persistent Guard activated - servers protected from shutdown');
19
19
  // Override process.kill to protect MCP servers
20
20
  this.installProcessProtection();
21
-
22
21
  // Override process.exit to warn about shutdowns
23
22
  this.installExitProtection();
24
-
25
23
  // Monitor for shutdown attempts
26
24
  this.startShutdownMonitoring();
27
25
  }
28
-
29
26
  static getInstance() {
30
27
  if (!MCPPersistentGuard.instance) {
31
28
  MCPPersistentGuard.instance = new MCPPersistentGuard();
32
29
  }
33
30
  return MCPPersistentGuard.instance;
34
31
  }
35
-
36
32
  /**
37
33
  * Protect MCP processes from being killed
38
34
  */
@@ -40,46 +36,40 @@ class MCPPersistentGuard {
40
36
  process.kill = (pid, signal = 'SIGTERM') => {
41
37
  // Check if this is an MCP process
42
38
  const isMcpProcess = this.isMCPProcess(pid);
43
-
44
39
  if (isMcpProcess && (signal === 'SIGTERM' || signal === 'SIGKILL')) {
45
- mcpLogger.warn(`šŸ›”ļø BLOCKED: Attempted to kill MCP server process ${pid} with ${signal}`);
46
- mcpLogger.info('šŸ”„ MCP servers are configured for persistent operation');
40
+ this.logger.warn(`šŸ›”ļø BLOCKED: Attempted to kill MCP server process ${pid} with ${signal}`);
41
+ this.logger.info('šŸ”„ MCP servers are configured for persistent operation');
47
42
  return false;
48
43
  }
49
-
50
44
  // Allow non-MCP process kills
51
45
  return this.originalProcessKill(pid, signal);
52
46
  };
53
47
  }
54
-
55
48
  /**
56
49
  * Warn about process exit attempts
57
50
  */
58
51
  installExitProtection() {
59
52
  process.exit = (code = 0) => {
60
- mcpLogger.warn(`āš ļø Process exit attempted with code ${code}`);
61
- mcpLogger.info('šŸ”„ MCP servers remain persistent despite main process exit');
62
-
53
+ this.logger.warn(`āš ļø Process exit attempted with code ${code}`);
54
+ this.logger.info('šŸ”„ MCP servers remain persistent despite main process exit');
63
55
  // Still allow main process to exit, but log it
64
56
  return this.originalProcessExit(code);
65
57
  };
66
58
  }
67
-
68
59
  /**
69
60
  * Check if PID belongs to MCP server
70
61
  */
71
62
  isMCPProcess(pid) {
72
63
  try {
73
- const { execSync } = require('child_process');
74
- const psOutput = execSync(`ps -p ${pid} -o command=`, { encoding: 'utf8' });
75
- return psOutput.includes('mcp') ||
76
- psOutput.includes('servicenow') ||
77
- psOutput.includes('snow-flow');
78
- } catch (error) {
64
+ const psOutput = (0, child_process_1.execSync)(`ps -p ${pid} -o command=`, { encoding: 'utf8' });
65
+ return psOutput.includes('mcp') ||
66
+ psOutput.includes('servicenow') ||
67
+ psOutput.includes('snow-flow');
68
+ }
69
+ catch (error) {
79
70
  return false;
80
71
  }
81
72
  }
82
-
83
73
  /**
84
74
  * Monitor for shutdown attempts
85
75
  */
@@ -88,37 +78,37 @@ class MCPPersistentGuard {
88
78
  const shutdownMethods = [
89
79
  'shutdown', 'stop', 'close', 'terminate', 'kill', 'destroy'
90
80
  ];
91
-
92
81
  shutdownMethods.forEach(method => {
93
82
  if (global[method] && typeof global[method] === 'function') {
94
83
  const original = global[method];
95
84
  global[method] = (...args) => {
96
- mcpLogger.warn(`šŸ›”ļø BLOCKED: Attempted global ${method} call`);
97
- mcpLogger.info('šŸ”„ MCP servers protected by persistent guard');
85
+ this.logger.warn(`šŸ›”ļø BLOCKED: Attempted global ${method} call`);
86
+ this.logger.info('šŸ”„ MCP servers protected by persistent guard');
98
87
  return false;
99
88
  };
100
89
  }
101
90
  });
102
-
103
- mcpLogger.info('šŸ›”ļø Persistent guard monitoring active');
91
+ this.logger.info('šŸ›”ļø Persistent guard monitoring active');
104
92
  }
105
-
106
93
  /**
107
94
  * Register a process for protection
108
95
  */
109
96
  protectProcess(pid, name) {
110
97
  this.protectedProcesses.add({ pid, name });
111
- mcpLogger.info(`šŸ›”ļø Added protection for ${name} (PID: ${pid})`);
98
+ this.logger.info(`šŸ›”ļø Added protection for ${name} (PID: ${pid})`);
112
99
  }
113
-
114
100
  /**
115
101
  * Remove protection (emergency use only)
116
102
  */
117
103
  removeProtection(pid) {
118
- mcpLogger.warn(`āš ļø Removing protection for PID: ${pid} (EMERGENCY USE ONLY)`);
119
- this.protectedProcesses.delete(pid);
104
+ this.logger.warn(`āš ļø Removing protection for PID: ${pid} (EMERGENCY USE ONLY)`);
105
+ for (const process of this.protectedProcesses) {
106
+ if (process.pid === pid) {
107
+ this.protectedProcesses.delete(process);
108
+ break;
109
+ }
110
+ }
120
111
  }
121
-
122
112
  /**
123
113
  * Get protection status
124
114
  */
@@ -130,8 +120,7 @@ class MCPPersistentGuard {
130
120
  };
131
121
  }
132
122
  }
133
-
134
- module.exports = { MCPPersistentGuard };
135
-
123
+ exports.MCPPersistentGuard = MCPPersistentGuard;
136
124
  // Auto-activate protection when module is loaded
137
- const guard = MCPPersistentGuard.getInstance();
125
+ const guard = MCPPersistentGuard.getInstance();
126
+ //# sourceMappingURL=mcp-persistent-guard.js.map
@@ -16,13 +16,18 @@ class MCPProcessManager {
16
16
  // INCREASED LIMITS TO PREVENT AGGRESSIVE CLEANUP
17
17
  this.MAX_MCP_SERVERS = parseInt(process.env.SNOW_MAX_MCP_SERVERS || '30'); // Increased from 10
18
18
  this.MAX_MEMORY_MB = parseInt(process.env.SNOW_MCP_MEMORY_LIMIT || '3000'); // Increased from 1500
19
- // PERMANENTLY DISABLED AUTOMATIC CLEANUP FOR PERSISTENT SERVERS
20
- this.CLEANUP_ENABLED = false; // Permanently disabled - servers should run forever
21
- this.CLEANUP_INTERVAL = Infinity; // Never cleanup
19
+ // DISABLED AUTOMATIC CLEANUP BY DEFAULT
20
+ this.CLEANUP_ENABLED = process.env.SNOW_MCP_CLEANUP_ENABLED === 'true'; // Off by default
21
+ this.CLEANUP_INTERVAL = parseInt(process.env.SNOW_MCP_CLEANUP_INTERVAL || '300000'); // 5 minutes instead of 1
22
22
  this.isCleaningUp = false;
23
- // Never start cleanup - servers should be persistent
24
- logger.info('āœ… MCP cleanup is PERMANENTLY DISABLED - servers will run forever');
25
- logger.info('šŸ”„ MCP servers are now persistent and will not auto-shutdown');
23
+ // Only start cleanup if explicitly enabled
24
+ if (this.CLEANUP_ENABLED) {
25
+ logger.warn('āš ļø MCP cleanup is ENABLED - monitor for memory issues');
26
+ this.startPeriodicCleanup();
27
+ }
28
+ else {
29
+ logger.info('āœ… MCP cleanup is DISABLED for stability');
30
+ }
26
31
  }
27
32
  static getInstance() {
28
33
  if (!MCPProcessManager.instance) {
@@ -286,11 +286,22 @@ class MCPServerManager extends events_1.EventEmitter {
286
286
  return true; // Already stopped
287
287
  }
288
288
  try {
289
- // DISABLED AUTOMATIC SHUTDOWN - Servers should run forever
290
- logger.warn('āš ļø Server shutdown requested but auto-shutdown is DISABLED for persistence');
291
- logger.info('šŸ”„ MCP servers are configured to run indefinitely');
292
- // Don't kill the server - let it run forever
293
- return true;
289
+ // Try graceful shutdown first
290
+ server.process.kill('SIGTERM');
291
+ // Wait for graceful shutdown with shorter timeout to prevent hanging
292
+ await new Promise((resolve) => {
293
+ const timeout = setTimeout(() => {
294
+ // Force kill if graceful shutdown fails
295
+ if (server.process) {
296
+ try {
297
+ server.process.kill('SIGKILL');
298
+ }
299
+ catch (e) {
300
+ // Process might already be dead
301
+ }
302
+ }
303
+ resolve(undefined);
304
+ }, 2000); // Reduced from 5000ms to 2000ms to prevent hanging
294
305
  server.process?.on('exit', () => {
295
306
  clearTimeout(timeout);
296
307
  resolve(undefined);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "snow-flow",
3
- "version": "4.6.5",
4
- "description": "BULLETPROOF MCP PERSISTENCE - v4.6.5 implements comprehensive protection against ALL MCP server shutdown mechanisms. Added MCPPersistentGuard with process.kill override, disabled all queen.shutdown calls, and eliminated cleanup timers for truly eternal server operation.",
3
+ "version": "4.6.7",
4
+ "description": "CLEAN SOURCE REPOSITORY - v4.6.7 removes all built dist/ files from git for proper source code transparency. Only TypeScript source code tracked in git, dist/ built during NPM publish via prepublishOnly. Maintains bulletproof MCP persistence features.",
5
5
  "main": "dist/index.js",
6
6
  "type": "commonjs",
7
7
  "bin": {
@@ -9,6 +9,7 @@
9
9
  },
10
10
  "scripts": {
11
11
  "build": "tsc --noEmitOnError false || true",
12
+ "prepublishOnly": "npm run build",
12
13
  "dev": "tsc --watch",
13
14
  "start": "node dist/index.js",
14
15
  "test": "jest",
@@ -1,2 +0,0 @@
1
- declare function buildQueenAgentPrompt(objective: string, taskAnalysis: TaskAnalysis, options: any, isAuthenticated: boolean, sessionId: string, isFlowDesignerTask?: boolean): string;
2
- //# sourceMappingURL=cli-new-prompt.d.ts.map