snow-flow 4.6.8 → 4.6.9

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.
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Enhanced Script Executor
3
+ * Captures ALL output from ServiceNow background scripts
4
+ * Consolidates multiple execution methods into one reliable tool
5
+ */
6
+ import { ServiceNowClient } from './servicenow-client.js';
7
+ interface ScriptExecutionResult {
8
+ success: boolean;
9
+ output: string[];
10
+ errors: string[];
11
+ logs: {
12
+ print: string[];
13
+ info: string[];
14
+ warn: string[];
15
+ error: string[];
16
+ debug: string[];
17
+ };
18
+ executionTime: number;
19
+ executionId: string;
20
+ scriptResult?: any;
21
+ error?: string;
22
+ }
23
+ export declare class EnhancedScriptExecutor {
24
+ private client;
25
+ private logger;
26
+ constructor(client: ServiceNowClient);
27
+ /**
28
+ * Execute script and capture ALL output including gs.print, gs.info, etc.
29
+ */
30
+ executeWithFullOutput(script: string, description?: string): Promise<ScriptExecutionResult>;
31
+ }
32
+ export {};
33
+ //# sourceMappingURL=enhanced-script-executor.d.ts.map
@@ -0,0 +1,183 @@
1
+ "use strict";
2
+ /**
3
+ * Enhanced Script Executor
4
+ * Captures ALL output from ServiceNow background scripts
5
+ * Consolidates multiple execution methods into one reliable tool
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.EnhancedScriptExecutor = void 0;
9
+ const logger_js_1 = require("./logger.js");
10
+ class EnhancedScriptExecutor {
11
+ constructor(client) {
12
+ this.client = client;
13
+ this.logger = new logger_js_1.Logger('EnhancedScriptExecutor');
14
+ }
15
+ /**
16
+ * Execute script and capture ALL output including gs.print, gs.info, etc.
17
+ */
18
+ async executeWithFullOutput(script, description) {
19
+ const startTime = Date.now();
20
+ const executionId = `snow_exec_${Date.now()}_${Math.random().toString(36).substring(7)}`;
21
+ this.logger.info(`Executing script with full output capture - ID: ${executionId}`);
22
+ try {
23
+ // Create enhanced wrapper script that captures EVERYTHING
24
+ const enhancedScript = `
25
+ // Enhanced output capture system
26
+ var snowFlowOutput = {
27
+ print: [],
28
+ info: [],
29
+ warn: [],
30
+ error: [],
31
+ debug: [],
32
+ general: [],
33
+ scriptResult: null,
34
+ executionId: '${executionId}',
35
+ startTime: new GlideDateTime().getValue()
36
+ };
37
+
38
+ // Store original functions
39
+ var origPrint = gs.print;
40
+ var origInfo = gs.info;
41
+ var origWarn = gs.warn;
42
+ var origError = gs.error;
43
+ var origDebug = gs.debug;
44
+
45
+ // Override gs functions to capture output
46
+ gs.print = function(message) {
47
+ snowFlowOutput.print.push(String(message));
48
+ snowFlowOutput.general.push('[PRINT] ' + String(message));
49
+ return origPrint.call(this, message);
50
+ };
51
+
52
+ gs.info = function(message) {
53
+ snowFlowOutput.info.push(String(message));
54
+ snowFlowOutput.general.push('[INFO] ' + String(message));
55
+ return origInfo.call(this, message);
56
+ };
57
+
58
+ gs.warn = function(message) {
59
+ snowFlowOutput.warn.push(String(message));
60
+ snowFlowOutput.general.push('[WARN] ' + String(message));
61
+ return origWarn.call(this, message);
62
+ };
63
+
64
+ gs.error = function(message) {
65
+ snowFlowOutput.error.push(String(message));
66
+ snowFlowOutput.general.push('[ERROR] ' + String(message));
67
+ return origError.call(this, message);
68
+ };
69
+
70
+ gs.debug = function(message) {
71
+ snowFlowOutput.debug.push(String(message));
72
+ snowFlowOutput.general.push('[DEBUG] ' + String(message));
73
+ return origDebug.call(this, message);
74
+ };
75
+
76
+ // Execute user script and capture result
77
+ try {
78
+ gs.info('=== SCRIPT EXECUTION START ===');
79
+
80
+ // User's script executed here
81
+ var userScriptResult = (function() {
82
+ ${script}
83
+ })();
84
+
85
+ snowFlowOutput.scriptResult = userScriptResult;
86
+ gs.info('=== SCRIPT EXECUTION SUCCESS ===');
87
+
88
+ } catch(userError) {
89
+ gs.error('=== SCRIPT EXECUTION ERROR ===');
90
+ gs.error('Error: ' + userError.toString());
91
+ if (userError.stack) {
92
+ gs.error('Stack: ' + userError.stack);
93
+ }
94
+ snowFlowOutput.scriptResult = { error: userError.toString(), stack: userError.stack };
95
+ }
96
+
97
+ // Restore original functions
98
+ gs.print = origPrint;
99
+ gs.info = origInfo;
100
+ gs.warn = origWarn;
101
+ gs.error = origError;
102
+ gs.debug = origDebug;
103
+
104
+ // Store output in sys_properties for retrieval
105
+ var outputJson = JSON.stringify(snowFlowOutput);
106
+ gs.setProperty('snow_flow.script_output.' + snowFlowOutput.executionId, outputJson);
107
+
108
+ // Final summary
109
+ gs.info('Snow-Flow: Script execution complete, output stored in sys_properties');
110
+ gs.info('Snow-Flow: Execution ID = ' + snowFlowOutput.executionId);
111
+ gs.info('Snow-Flow: Total output lines = ' + snowFlowOutput.general.length);
112
+ `;
113
+ // Execute the enhanced script
114
+ const executeResponse = await this.client.executeScript(enhancedScript);
115
+ if (!executeResponse.success) {
116
+ throw new Error(`Script execution failed: ${executeResponse.error}`);
117
+ }
118
+ // Wait a bit for execution to complete
119
+ await new Promise(resolve => setTimeout(resolve, 2000));
120
+ // Retrieve the captured output from sys_properties
121
+ const outputProperty = `snow_flow.script_output.${executionId}`;
122
+ const outputResponse = await this.client.getProperty(outputProperty);
123
+ let capturedOutput = {
124
+ print: [],
125
+ info: [],
126
+ warn: [],
127
+ error: [],
128
+ debug: [],
129
+ general: [],
130
+ scriptResult: null
131
+ };
132
+ if (outputResponse.success && outputResponse.value) {
133
+ try {
134
+ capturedOutput = JSON.parse(outputResponse.value);
135
+ }
136
+ catch (parseError) {
137
+ this.logger.warn('Failed to parse captured output, using basic result');
138
+ }
139
+ // Clean up the property
140
+ await this.client.deleteProperty(outputProperty);
141
+ }
142
+ const executionTime = Date.now() - startTime;
143
+ const result = {
144
+ success: true,
145
+ output: capturedOutput.general || [],
146
+ errors: capturedOutput.error || [],
147
+ logs: {
148
+ print: capturedOutput.print || [],
149
+ info: capturedOutput.info || [],
150
+ warn: capturedOutput.warn || [],
151
+ error: capturedOutput.error || [],
152
+ debug: capturedOutput.debug || []
153
+ },
154
+ executionTime,
155
+ executionId,
156
+ scriptResult: capturedOutput.scriptResult
157
+ };
158
+ this.logger.info(`Script execution completed with ${result.output.length} output lines`);
159
+ return result;
160
+ }
161
+ catch (error) {
162
+ const executionTime = Date.now() - startTime;
163
+ this.logger.error(`Script execution failed: ${error.message}`);
164
+ return {
165
+ success: false,
166
+ output: [],
167
+ errors: [error.message],
168
+ logs: {
169
+ print: [],
170
+ info: [],
171
+ warn: [],
172
+ error: [error.message],
173
+ debug: []
174
+ },
175
+ executionTime,
176
+ executionId,
177
+ error: error.message
178
+ };
179
+ }
180
+ }
181
+ }
182
+ exports.EnhancedScriptExecutor = EnhancedScriptExecutor;
183
+ //# sourceMappingURL=enhanced-script-executor.js.map
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Unified Script Executor
3
+ * Single reliable tool to replace all script execution methods
4
+ * Captures COMPLETE output from ServiceNow scripts
5
+ */
6
+ import { ServiceNowClient } from './servicenow-client.js';
7
+ export interface UnifiedScriptResult {
8
+ success: boolean;
9
+ output: string[];
10
+ scriptResult: any;
11
+ executionId: string;
12
+ executionTime: number;
13
+ logs: {
14
+ print: string[];
15
+ info: string[];
16
+ warn: string[];
17
+ error: string[];
18
+ };
19
+ summary: string;
20
+ error?: string;
21
+ }
22
+ export declare class UnifiedScriptExecutor {
23
+ private client;
24
+ private logger;
25
+ constructor(client: ServiceNowClient);
26
+ /**
27
+ * Execute script with complete output capture
28
+ * Replaces: snow_execute_script_with_output, snow_execute_script_sync, snow_execute_background_script
29
+ */
30
+ executeScript(script: string, description?: string): Promise<UnifiedScriptResult>;
31
+ }
32
+ export declare function createUnifiedScriptTool(): {
33
+ name: string;
34
+ description: string;
35
+ inputSchema: {
36
+ type: string;
37
+ properties: {
38
+ script: {
39
+ type: string;
40
+ description: string;
41
+ };
42
+ description: {
43
+ type: string;
44
+ description: string;
45
+ };
46
+ };
47
+ required: string[];
48
+ };
49
+ };
50
+ //# sourceMappingURL=unified-script-executor.d.ts.map
@@ -0,0 +1,182 @@
1
+ "use strict";
2
+ /**
3
+ * Unified Script Executor
4
+ * Single reliable tool to replace all script execution methods
5
+ * Captures COMPLETE output from ServiceNow scripts
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.UnifiedScriptExecutor = void 0;
9
+ exports.createUnifiedScriptTool = createUnifiedScriptTool;
10
+ const logger_js_1 = require("./logger.js");
11
+ class UnifiedScriptExecutor {
12
+ constructor(client) {
13
+ this.client = client;
14
+ this.logger = new logger_js_1.Logger('UnifiedScriptExecutor');
15
+ }
16
+ /**
17
+ * Execute script with complete output capture
18
+ * Replaces: snow_execute_script_with_output, snow_execute_script_sync, snow_execute_background_script
19
+ */
20
+ async executeScript(script, description) {
21
+ const startTime = Date.now();
22
+ const executionId = `unified_${Date.now()}_${Math.random().toString(36).substring(7)}`;
23
+ this.logger.info(`Executing script with unified capture - ID: ${executionId}`);
24
+ try {
25
+ // Enhanced script that captures EVERYTHING
26
+ const captureScript = `
27
+ // Snow-Flow Enhanced Output Capture System
28
+ var snowFlowCapture = {
29
+ print: [],
30
+ info: [],
31
+ warn: [],
32
+ error: [],
33
+ output: [],
34
+ scriptResult: null,
35
+ executionId: '${executionId}',
36
+ success: true,
37
+ startTime: new GlideDateTime().getDisplayValue()
38
+ };
39
+
40
+ // Store original gs methods
41
+ var origPrint = gs.print;
42
+ var origInfo = gs.info;
43
+ var origWarn = gs.warn;
44
+ var origError = gs.error;
45
+
46
+ // Enhanced capture functions
47
+ gs.print = function(msg) {
48
+ var message = String(msg);
49
+ snowFlowCapture.print.push(message);
50
+ snowFlowCapture.output.push('[PRINT] ' + message);
51
+ return origPrint(msg);
52
+ };
53
+
54
+ gs.info = function(msg) {
55
+ var message = String(msg);
56
+ snowFlowCapture.info.push(message);
57
+ snowFlowCapture.output.push('[INFO] ' + message);
58
+ return origInfo(msg);
59
+ };
60
+
61
+ gs.warn = function(msg) {
62
+ var message = String(msg);
63
+ snowFlowCapture.warn.push(message);
64
+ snowFlowCapture.output.push('[WARN] ' + message);
65
+ return origWarn(msg);
66
+ };
67
+
68
+ gs.error = function(msg) {
69
+ var message = String(msg);
70
+ snowFlowCapture.error.push(message);
71
+ snowFlowCapture.output.push('[ERROR] ' + message);
72
+ return origError(msg);
73
+ };
74
+
75
+ // Execute user script
76
+ try {
77
+ gs.info('=== SNOW-FLOW UNIFIED EXECUTION START ===');
78
+
79
+ var result = (function() {
80
+ ${script}
81
+ })();
82
+
83
+ snowFlowCapture.scriptResult = result;
84
+ gs.info('=== SNOW-FLOW EXECUTION SUCCESS ===');
85
+ gs.info('Script Result: ' + (typeof result === 'object' ? JSON.stringify(result) : String(result)));
86
+
87
+ } catch(scriptError) {
88
+ snowFlowCapture.success = false;
89
+ gs.error('=== SNOW-FLOW EXECUTION ERROR ===');
90
+ gs.error('Error: ' + scriptError.toString());
91
+ snowFlowCapture.scriptResult = { error: scriptError.toString() };
92
+ }
93
+
94
+ // Restore original functions
95
+ gs.print = origPrint;
96
+ gs.info = origInfo;
97
+ gs.warn = origWarn;
98
+ gs.error = origError;
99
+
100
+ // Store result in temporary property
101
+ gs.setProperty('snow_flow.unified_output.' + snowFlowCapture.executionId, JSON.stringify(snowFlowCapture));
102
+
103
+ gs.info('Snow-Flow: Unified execution complete, ID = ' + snowFlowCapture.executionId);
104
+ `;
105
+ // Execute the script
106
+ const executeResponse = await this.client.executeScript(captureScript);
107
+ if (!executeResponse.success) {
108
+ throw new Error(`Script execution failed: ${executeResponse.error}`);
109
+ }
110
+ // Wait for completion
111
+ await new Promise(resolve => setTimeout(resolve, 3000));
112
+ // Retrieve captured output
113
+ const outputProperty = `snow_flow.unified_output.${executionId}`;
114
+ const outputResponse = await this.client.getProperty(outputProperty);
115
+ let capturedData = {
116
+ print: [],
117
+ info: [],
118
+ warn: [],
119
+ error: [],
120
+ output: [],
121
+ scriptResult: null,
122
+ success: false
123
+ };
124
+ if (outputResponse.success && outputResponse.value) {
125
+ try {
126
+ capturedData = JSON.parse(outputResponse.value);
127
+ // Clean up
128
+ await this.client.deleteProperty(outputProperty);
129
+ }
130
+ catch (parseError) {
131
+ this.logger.warn('Parse error:', parseError);
132
+ }
133
+ }
134
+ const executionTime = Date.now() - startTime;
135
+ return {
136
+ success: capturedData.success,
137
+ output: capturedData.output || [],
138
+ scriptResult: capturedData.scriptResult,
139
+ executionId,
140
+ executionTime,
141
+ logs: {
142
+ print: capturedData.print || [],
143
+ info: capturedData.info || [],
144
+ warn: capturedData.warn || [],
145
+ error: capturedData.error || []
146
+ },
147
+ summary: `✅ Execution complete: ${capturedData.output?.length || 0} output lines, ${capturedData.error?.length || 0} errors`,
148
+ error: capturedData.success ? undefined : 'Script execution failed'
149
+ };
150
+ }
151
+ catch (error) {
152
+ const executionTime = Date.now() - startTime;
153
+ return {
154
+ success: false,
155
+ output: [],
156
+ scriptResult: null,
157
+ executionId,
158
+ executionTime,
159
+ logs: { print: [], info: [], warn: [], error: [error.message] },
160
+ summary: `❌ Execution failed: ${error.message}`,
161
+ error: error.message
162
+ };
163
+ }
164
+ }
165
+ }
166
+ exports.UnifiedScriptExecutor = UnifiedScriptExecutor;
167
+ // Export as MCP tool helper
168
+ function createUnifiedScriptTool() {
169
+ return {
170
+ name: 'snow_execute_script_unified',
171
+ description: '🚀 UNIFIED: Execute script with complete output capture (replaces all other script tools). ⚠️ ES5 ONLY!',
172
+ inputSchema: {
173
+ type: 'object',
174
+ properties: {
175
+ script: { type: 'string', description: '🚨 ES5 ONLY! JavaScript code (var, function(){}, string concatenation)' },
176
+ description: { type: 'string', description: 'What this script does' }
177
+ },
178
+ required: ['script']
179
+ }
180
+ };
181
+ }
182
+ //# sourceMappingURL=unified-script-executor.js.map
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "snow-flow",
3
- "version": "4.6.8",
4
- "description": "RESTORED CLAUDE CODE VERSION PINNING - v4.6.8 restores automatic Claude Code 1.0.95 installation to swarm command that was lost during refactoring. Now properly integrated in TypeScript source with bulletproof MCP persistence and clean repository structure.",
3
+ "version": "4.6.9",
4
+ "description": "ENHANCED SCRIPT OUTPUT CAPTURE - v4.6.9 adds UnifiedScriptExecutor to capture complete script output including gs.print, gs.info, gs.warn, gs.error and script results. Solves the 'not getting actual output' problem with comprehensive output capture system.",
5
5
  "main": "dist/index.js",
6
6
  "type": "commonjs",
7
7
  "bin": {