snow-flow 3.4.39 → 3.5.0

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/README.md CHANGED
@@ -361,9 +361,9 @@ await snow_query_table({
361
361
 
362
362
  ### Core Commands
363
363
  ```bash
364
- snow-flow start # Start orchestration system
365
- snow-flow status # System status
366
- snow-flow monitor # Real-time monitoring
364
+ snow-flow swarm "<objective>" # Execute multi-agent swarm
365
+ snow-flow auth login # Authenticate with ServiceNow
366
+ snow-flow init # Initialize project
367
367
  ```
368
368
 
369
369
  ### Agent Management
@@ -450,14 +450,16 @@ ServiceNow uses Rhino engine. Always use ES5 syntax:
450
450
  # Enable verbose logging
451
451
  export DEBUG=snow-flow:*
452
452
 
453
- # Check configuration
454
- snow-flow config validate
453
+ # Check version and help
454
+ snow-flow --version
455
+ snow-flow --help
455
456
 
456
- # Test ServiceNow connection
457
- snow-flow test connection
457
+ # Test authentication
458
+ snow-flow auth login
459
+ snow-flow auth status
458
460
 
459
- # View logs
460
- snow-flow logs --tail 100
461
+ # Re-initialize if needed
462
+ snow-flow init
461
463
  ```
462
464
 
463
465
  ## Project Structure
package/dist/index.d.ts CHANGED
@@ -6,7 +6,11 @@ export * from './types/index.js';
6
6
  export { ServiceNowOAuth } from './utils/snow-oauth.js';
7
7
  export { ServiceNowClient } from './utils/servicenow-client.js';
8
8
  export { Logger } from './utils/logger.js';
9
+ export { ArtifactLocalSync } from './utils/artifact-local-sync.js';
10
+ export { SmartFieldFetcher } from './utils/smart-field-fetcher.js';
11
+ export * from './utils/artifact-sync/artifact-registry.js';
9
12
  export { ServiceNowMCPServer } from './mcp/servicenow-mcp-server.js';
13
+ export { ServiceNowLocalDevelopmentMCP } from './mcp/servicenow-local-development-mcp.js';
10
14
  export { SnowFlowSystem, snowFlowSystem } from './snow-flow-system.js';
11
15
  export { SnowFlowConfig, snowFlowConfig } from './config/snow-flow-config.js';
12
16
  export { MemorySystem } from './memory/memory-system.js';
package/dist/index.js CHANGED
@@ -18,7 +18,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
18
18
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
19
19
  };
20
20
  Object.defineProperty(exports, "__esModule", { value: true });
21
- exports.SystemHealth = exports.PerformanceTracker = exports.FALLBACK_STRATEGIES = exports.ErrorRecovery = exports.MemorySystem = exports.snowFlowConfig = exports.SnowFlowConfig = exports.snowFlowSystem = exports.SnowFlowSystem = exports.ServiceNowMCPServer = exports.Logger = exports.ServiceNowClient = exports.ServiceNowOAuth = void 0;
21
+ exports.SystemHealth = exports.PerformanceTracker = exports.FALLBACK_STRATEGIES = exports.ErrorRecovery = exports.MemorySystem = exports.snowFlowConfig = exports.SnowFlowConfig = exports.snowFlowSystem = exports.SnowFlowSystem = exports.ServiceNowLocalDevelopmentMCP = exports.ServiceNowMCPServer = exports.SmartFieldFetcher = exports.ArtifactLocalSync = exports.Logger = exports.ServiceNowClient = exports.ServiceNowOAuth = void 0;
22
22
  // Export main types
23
23
  __exportStar(require("./types/index.js"), exports);
24
24
  // Export utilities
@@ -28,9 +28,17 @@ var servicenow_client_js_1 = require("./utils/servicenow-client.js");
28
28
  Object.defineProperty(exports, "ServiceNowClient", { enumerable: true, get: function () { return servicenow_client_js_1.ServiceNowClient; } });
29
29
  var logger_js_1 = require("./utils/logger.js");
30
30
  Object.defineProperty(exports, "Logger", { enumerable: true, get: function () { return logger_js_1.Logger; } });
31
- // Export MCP server
31
+ // Export artifact sync system
32
+ var artifact_local_sync_js_1 = require("./utils/artifact-local-sync.js");
33
+ Object.defineProperty(exports, "ArtifactLocalSync", { enumerable: true, get: function () { return artifact_local_sync_js_1.ArtifactLocalSync; } });
34
+ var smart_field_fetcher_js_1 = require("./utils/smart-field-fetcher.js");
35
+ Object.defineProperty(exports, "SmartFieldFetcher", { enumerable: true, get: function () { return smart_field_fetcher_js_1.SmartFieldFetcher; } });
36
+ __exportStar(require("./utils/artifact-sync/artifact-registry.js"), exports);
37
+ // Export MCP servers
32
38
  var servicenow_mcp_server_js_1 = require("./mcp/servicenow-mcp-server.js");
33
39
  Object.defineProperty(exports, "ServiceNowMCPServer", { enumerable: true, get: function () { return servicenow_mcp_server_js_1.ServiceNowMCPServer; } });
40
+ var servicenow_local_development_mcp_js_1 = require("./mcp/servicenow-local-development-mcp.js");
41
+ Object.defineProperty(exports, "ServiceNowLocalDevelopmentMCP", { enumerable: true, get: function () { return servicenow_local_development_mcp_js_1.ServiceNowLocalDevelopmentMCP; } });
34
42
  // Snow-Flow System Integration (New)
35
43
  var snow_flow_system_js_1 = require("./snow-flow-system.js");
36
44
  Object.defineProperty(exports, "SnowFlowSystem", { enumerable: true, get: function () { return snow_flow_system_js_1.SnowFlowSystem; } });
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Smart Query Enhancement for MCP Operations
3
+ *
4
+ * Automatically handles large artifact queries by intelligent field splitting
5
+ * while maintaining context relationships for Claude.
6
+ */
7
+ import { MCPToolResult } from '../shared/mcp-types';
8
+ export declare class SmartQueryEnhancement {
9
+ private smartFetcher;
10
+ constructor(serviceNowClient: any);
11
+ /**
12
+ * Enhance snow_query_table to handle large artifacts intelligently
13
+ */
14
+ enhanceQueryTable(originalArgs: any): Promise<MCPToolResult>;
15
+ /**
16
+ * Generate context message for widget fetch
17
+ */
18
+ private generateWidgetContextMessage;
19
+ /**
20
+ * Generate context message for flow fetch
21
+ */
22
+ private generateFlowContextMessage;
23
+ /**
24
+ * Generate context message for business rule fetch
25
+ */
26
+ private generateBusinessRuleContextMessage;
27
+ /**
28
+ * Execute original query when smart fetch not needed
29
+ */
30
+ private executeOriginalQuery;
31
+ /**
32
+ * Search within specific fields
33
+ */
34
+ searchInFields(args: {
35
+ table: string;
36
+ field: string;
37
+ searchTerm: string;
38
+ additionalQuery?: string;
39
+ }): Promise<MCPToolResult>;
40
+ }
41
+ /**
42
+ * Helper to detect if a query will likely exceed token limits
43
+ */
44
+ export declare function willExceedTokenLimit(fields: string[], table: string): boolean;
45
+ /**
46
+ * Generate hint for Claude about using smart fetch
47
+ */
48
+ export declare function generateSmartFetchHint(): string;
49
+ //# sourceMappingURL=smart-query-enhancement.d.ts.map
@@ -0,0 +1,233 @@
1
+ "use strict";
2
+ /**
3
+ * Smart Query Enhancement for MCP Operations
4
+ *
5
+ * Automatically handles large artifact queries by intelligent field splitting
6
+ * while maintaining context relationships for Claude.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.SmartQueryEnhancement = void 0;
10
+ exports.willExceedTokenLimit = willExceedTokenLimit;
11
+ exports.generateSmartFetchHint = generateSmartFetchHint;
12
+ const smart_field_fetcher_1 = require("../../utils/smart-field-fetcher");
13
+ class SmartQueryEnhancement {
14
+ constructor(serviceNowClient) {
15
+ this.smartFetcher = new smart_field_fetcher_1.SmartFieldFetcher(serviceNowClient);
16
+ }
17
+ /**
18
+ * Enhance snow_query_table to handle large artifacts intelligently
19
+ */
20
+ async enhanceQueryTable(originalArgs) {
21
+ const { table, query, fields, limit } = originalArgs;
22
+ // Check if this is a single record query with many fields
23
+ const isSingleRecordQuery = query?.includes('sys_id=') && limit === 1;
24
+ const hasLargeFields = fields?.some((f) => ['template', 'script', 'client_script', 'css', 'definition', 'data_table'].includes(f));
25
+ if (isSingleRecordQuery && hasLargeFields) {
26
+ // Extract sys_id from query
27
+ const sys_id = query.match(/sys_id=([a-f0-9]{32})/)?.[1];
28
+ if (sys_id) {
29
+ console.log(`\n🎯 Detected large artifact query for ${table}. Using smart fetch strategy...`);
30
+ // Use smart fetcher based on table type
31
+ let result;
32
+ let contextMessage = '';
33
+ switch (table) {
34
+ case 'sp_widget':
35
+ result = await this.smartFetcher.fetchWidget(sys_id);
36
+ contextMessage = this.generateWidgetContextMessage(result);
37
+ break;
38
+ case 'sys_hub_flow':
39
+ result = await this.smartFetcher.fetchFlow(sys_id);
40
+ contextMessage = this.generateFlowContextMessage(result);
41
+ break;
42
+ case 'sys_script':
43
+ result = await this.smartFetcher.fetchBusinessRule(sys_id);
44
+ contextMessage = this.generateBusinessRuleContextMessage(result);
45
+ break;
46
+ default:
47
+ // Fall back to original query
48
+ return this.executeOriginalQuery(originalArgs);
49
+ }
50
+ return {
51
+ success: true,
52
+ result: result,
53
+ message: contextMessage,
54
+ _meta: {
55
+ strategy: 'smart_chunked_fetch',
56
+ total_groups: Object.keys(result._field_groups || {}).length,
57
+ coherence_hints: result._coherence_hints,
58
+ context_preserved: true
59
+ }
60
+ };
61
+ }
62
+ }
63
+ // For non-large queries, use original method
64
+ return this.executeOriginalQuery(originalArgs);
65
+ }
66
+ /**
67
+ * Generate context message for widget fetch
68
+ */
69
+ generateWidgetContextMessage(widget) {
70
+ const groups = widget._field_groups || {};
71
+ const fetchedFields = [];
72
+ const failedFields = [];
73
+ for (const [groupName, groupData] of Object.entries(groups)) {
74
+ const data = groupData;
75
+ if (data._fetched_individually) {
76
+ for (const [field, status] of Object.entries(data._field_status || {})) {
77
+ if (status === 'success') {
78
+ fetchedFields.push(field);
79
+ }
80
+ else {
81
+ failedFields.push(field);
82
+ }
83
+ }
84
+ }
85
+ else if (data.fields) {
86
+ fetchedFields.push(...data.fields);
87
+ }
88
+ }
89
+ let message = `
90
+ 🧩 **Widget ${widget.name || widget.sys_id} - Smart Fetch Complete**
91
+
92
+ ✅ **Successfully fetched ${fetchedFields.length} fields in chunks to avoid token limits**
93
+
94
+ 📋 **Field Groups Retrieved:**
95
+ ${Object.entries(groups).map(([name, data]) => `• **${name}**: ${data.description}`).join('\n')}
96
+
97
+ 🔗 **IMPORTANT Context Relationships:**
98
+ • **Template HTML** (template field) contains:
99
+ - Angular bindings like {{data.propertyName}} that reference server script data
100
+ - ng-click directives that call client script methods
101
+ - CSS classes defined in the css field
102
+
103
+ • **Server Script** (script field) contains:
104
+ - ES5-only code that initializes the data object
105
+ - Handles input.action requests from client script
106
+ - Sets all data.* properties referenced in template
107
+
108
+ • **Client Script** (client_script field) contains:
109
+ - AngularJS controller with \$scope methods
110
+ - Methods called by template ng-click events
111
+ - Uses c.server.get({action: 'name'}) to call server script
112
+
113
+ • **CSS** (css field) contains:
114
+ - Styles for classes used in template HTML
115
+
116
+ ⚠️ **These fields work together as one cohesive unit!**
117
+ When making changes, ensure:
118
+ 1. Every {{data.x}} in template has matching data.x in server script
119
+ 2. Every ng-click="method()" in template has matching \$scope.method in client script
120
+ 3. Every c.server.get({action: 'x'}) in client has matching if(input.action=='x') in server
121
+ 4. CSS classes in template are defined in css field
122
+ `;
123
+ if (failedFields.length > 0) {
124
+ message += `\n\n⚠️ **Failed to fetch:** ${failedFields.join(', ')} (too large or restricted)`;
125
+ }
126
+ if (widget._coherence_hints?.length > 0) {
127
+ message += `\n\n🔍 **Detected Coherence Patterns:**\n${widget._coherence_hints.map((h) => `• ${h}`).join('\n')}`;
128
+ }
129
+ return message;
130
+ }
131
+ /**
132
+ * Generate context message for flow fetch
133
+ */
134
+ generateFlowContextMessage(flow) {
135
+ return `
136
+ 🔄 **Flow ${flow.name || flow.sys_id} - Smart Fetch Complete**
137
+
138
+ ✅ **Successfully fetched flow in chunks**
139
+
140
+ The 'definition' field contains the complete flow JSON structure with:
141
+ • All steps and their configurations
142
+ • Conditions and triggers
143
+ • Actions and data pills
144
+ • Subflow references
145
+
146
+ This flow ${flow.active ? 'is ACTIVE' : 'is INACTIVE'} and triggers on: ${flow.trigger_type || 'Unknown'}
147
+ `;
148
+ }
149
+ /**
150
+ * Generate context message for business rule fetch
151
+ */
152
+ generateBusinessRuleContextMessage(rule) {
153
+ return `
154
+ 📜 **Business Rule ${rule.name || rule.sys_id} - Smart Fetch Complete**
155
+
156
+ ✅ **Successfully fetched business rule in chunks**
157
+
158
+ • **Table:** ${rule.collection}
159
+ • **Active:** ${rule.active ? 'Yes' : 'No'}
160
+ • **When:** ${rule.when}
161
+ • **Order:** ${rule.order}
162
+
163
+ The 'script' field contains ES5-only code with access to:
164
+ • **current** - The current record being processed
165
+ • **previous** - The previous values (for updates)
166
+ • **gs** - GlideSystem object for server-side APIs
167
+ • **g_scratchpad** - For passing data to client scripts
168
+ `;
169
+ }
170
+ /**
171
+ * Execute original query when smart fetch not needed
172
+ */
173
+ async executeOriginalQuery(args) {
174
+ // This would call the original snow_query_table implementation
175
+ // For now, return a placeholder
176
+ return {
177
+ success: true,
178
+ result: { message: 'Original query executed' },
179
+ message: 'Query executed normally without smart chunking'
180
+ };
181
+ }
182
+ /**
183
+ * Search within specific fields
184
+ */
185
+ async searchInFields(args) {
186
+ const results = await this.smartFetcher.searchInField(args.table, args.field, args.searchTerm, args.additionalQuery);
187
+ return {
188
+ success: true,
189
+ result: results,
190
+ message: `Found ${results.length} matches for "${args.searchTerm}" in ${args.table}.${args.field}`
191
+ };
192
+ }
193
+ }
194
+ exports.SmartQueryEnhancement = SmartQueryEnhancement;
195
+ /**
196
+ * Helper to detect if a query will likely exceed token limits
197
+ */
198
+ function willExceedTokenLimit(fields, table) {
199
+ const LARGE_FIELDS = {
200
+ 'sp_widget': ['template', 'script', 'client_script', 'css', 'data_table'],
201
+ 'sys_hub_flow': ['definition', 'compiled_definition'],
202
+ 'sys_script': ['script', 'condition'],
203
+ 'sys_script_include': ['script'],
204
+ 'sys_ui_page': ['html', 'client_script', 'processing_script']
205
+ };
206
+ const tableFields = LARGE_FIELDS[table] || [];
207
+ const hasMultipleLargeFields = fields.filter(f => tableFields.includes(f)).length >= 2;
208
+ return hasMultipleLargeFields;
209
+ }
210
+ /**
211
+ * Generate hint for Claude about using smart fetch
212
+ */
213
+ function generateSmartFetchHint() {
214
+ return `
215
+ 💡 **Smart Fetch Available for Large Artifacts**
216
+
217
+ When you encounter "exceeds maximum allowed tokens" errors, I can automatically:
218
+ 1. Split the query into intelligent field groups
219
+ 2. Fetch each group separately to stay under limits
220
+ 3. Maintain full context about field relationships
221
+ 4. Provide coherence validation hints
222
+
223
+ **Supported tables with smart fetch:**
224
+ • sp_widget - Fetches template, scripts, CSS separately but maintains widget coherence
225
+ • sys_hub_flow - Handles large flow definitions
226
+ • sys_script - Manages business rules with large scripts
227
+ • sys_script_include - Script includes with extensive code
228
+ • sys_ui_page - UI pages with HTML, CSS, and scripts
229
+
230
+ The smart fetch ensures you get ALL necessary data while respecting token limits!
231
+ `;
232
+ }
233
+ //# sourceMappingURL=smart-query-enhancement.js.map
@@ -0,0 +1,48 @@
1
+ /**
2
+ * ServiceNow Local Development MCP Server
3
+ *
4
+ * Bridges ServiceNow artifacts with Claude Code's native file tools
5
+ * by creating temporary local files that can be edited with full
6
+ * Claude Code capabilities, then synced back to ServiceNow.
7
+ *
8
+ * THIS IS THE KEY TO POWERFUL SERVICENOW DEVELOPMENT!
9
+ */
10
+ import { BaseMCPServer } from './base-mcp-server';
11
+ export declare class ServiceNowLocalDevelopmentMCP extends BaseMCPServer {
12
+ private syncManager;
13
+ constructor();
14
+ protected initializeTools(): Promise<void>;
15
+ /**
16
+ * DYNAMIC pull artifact to local files
17
+ */
18
+ private pullArtifact;
19
+ /**
20
+ * Push artifact changes back to ServiceNow
21
+ */
22
+ private pushArtifact;
23
+ /**
24
+ * Get sync status
25
+ */
26
+ private getSyncStatus;
27
+ /**
28
+ * Cleanup local files
29
+ */
30
+ private cleanup;
31
+ /**
32
+ * List supported artifact types
33
+ */
34
+ private listSupportedArtifacts;
35
+ /**
36
+ * Validate artifact coherence
37
+ */
38
+ private validateCoherence;
39
+ /**
40
+ * Convert modern JS to ES5
41
+ */
42
+ private convertToES5;
43
+ /**
44
+ * Search in widgets (like Claude Code search)
45
+ */
46
+ private searchInWidgets;
47
+ }
48
+ //# sourceMappingURL=servicenow-local-development-mcp.d.ts.map