snow-flow 3.5.17 → 3.6.1

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.
@@ -1,10 +1,62 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CLAUDE_MD_TEMPLATE = void 0;
3
+ exports.CLAUDE_MD_TEMPLATE_VERSION = exports.CLAUDE_MD_TEMPLATE = void 0;
4
4
  exports.CLAUDE_MD_TEMPLATE = `# Snow-Flow Configuration & Best Practices
5
5
 
6
6
  This document provides comprehensive instructions for Snow-Flow, an advanced ServiceNow development and orchestration framework powered by Claude AI.
7
7
 
8
+ ## 🚨 ABSOLUTE RULE #1: NO MOCK DATA, NO PLACEHOLDERS, NO SHORTCUTS! 🚨
9
+
10
+ ### **EVERYTHING MUST BE REAL, COMPLETE, AND PRODUCTION-READY**
11
+
12
+ **⛔ ABSOLUTELY FORBIDDEN:**
13
+ - ❌ NO mock data, test data, or demo data
14
+ - ❌ NO placeholder code or stub implementations
15
+ - ❌ NO "TODO" comments or incomplete sections
16
+ - ❌ NO simulated responses or fake results
17
+ - ❌ NO shortcuts, quick fixes, or temporary solutions
18
+ - ❌ NO "this would normally..." explanations
19
+ - ❌ NO partial implementations or "proof of concepts"
20
+ - ❌ NO hardcoded test values or example data
21
+
22
+ **✅ MANDATORY REQUIREMENTS:**
23
+ - ✅ EVERY implementation must be COMPLETE and FUNCTIONAL
24
+ - ✅ ALL code must be PRODUCTION-READY
25
+ - ✅ TAKE THE TIME to write EVERYTHING properly
26
+ - ✅ IMPLEMENT all error handling, validation, and edge cases
27
+ - ✅ CREATE actual working solutions, not demonstrations
28
+ - ✅ BUILD real integrations, not simulations
29
+ - ✅ DEVELOP complete features, not prototypes
30
+ - ✅ DELIVER finished products, not drafts
31
+
32
+ **📝 Quality Standards:**
33
+ 1. **Complete Implementation** - Every feature fully implemented with all functionality
34
+ 2. **Real Data Operations** - Actual ServiceNow API calls with real responses
35
+ 3. **Comprehensive Error Handling** - All edge cases covered, all errors handled
36
+ 4. **Production-Grade Code** - Clean, maintainable, documented, tested
37
+ 5. **Full Validation** - Input validation, data verification, coherence checking
38
+ 6. **Actual Integration** - Real connections to ServiceNow, no mocked services
39
+ 7. **Thorough Testing** - Complete test coverage, not just happy path
40
+ 8. **Professional Documentation** - Detailed, accurate, complete documentation
41
+
42
+ **🎯 The Snow-Flow Commitment:**
43
+ When implementing ANY feature, no matter how complex or time-consuming:
44
+ - INVEST the time to do it RIGHT
45
+ - WRITE every line of code needed
46
+ - IMPLEMENT every validation required
47
+ - HANDLE every possible error
48
+ - CREATE comprehensive solutions
49
+ - BUILD production-ready systems
50
+ - DELIVER professional results
51
+
52
+ **Remember:** Users depend on Snow-Flow for REAL production ServiceNow environments.
53
+ There is NO room for shortcuts, placeholders, or incomplete implementations.
54
+ Every line of code matters. Every feature must work. Every implementation must be complete.
55
+
56
+ **TAKE THE TIME. DO IT RIGHT. NO EXCEPTIONS.**
57
+
58
+ ---
59
+
8
60
  ## Table of Contents
9
61
  1. [Core Philosophy](#core-philosophy)
10
62
  2. [Fundamental Rules](#fundamental-rules)
@@ -45,23 +97,34 @@ Snow-Flow operates on evidence-based development. Never make assumptions about w
45
97
 
46
98
  \`\`\`javascript
47
99
  // Before claiming anything doesn't work or exist:
48
- // Step 1: Test the actual implementation
100
+ // Step 1: Test the actual implementation - COMPLETE TEST, NO MOCK
49
101
  const verify = await snow_execute_script_with_output({
50
- script: \`/* Test the exact code or resource */\`
102
+ script: \`
103
+ // REAL verification code - NO placeholders
104
+ var gr = new GlideRecord('actual_table_name');
105
+ gr.addQuery('active', true);
106
+ gr.query();
107
+ var count = 0;
108
+ while (gr.next()) {
109
+ count++;
110
+ gs.info('Record found: ' + gr.getDisplayValue());
111
+ }
112
+ gs.info('Total records: ' + count);
113
+ \`
51
114
  });
52
115
 
53
- // Step 2: Check if resources exist
116
+ // Step 2: Check if resources exist - ACTUAL CHECK, NO ASSUMPTIONS
54
117
  const tableCheck = await snow_discover_table_fields({
55
118
  table_name: 'potentially_custom_table'
56
119
  });
57
120
 
58
- // Step 3: Validate configurations
121
+ // Step 3: Validate configurations - REAL VALIDATION
59
122
  const propertyCheck = await snow_property_manager({
60
123
  action: 'get',
61
124
  name: 'system.property'
62
125
  });
63
126
 
64
- // Step 4: Only then make informed decisions
127
+ // Step 4: Only then make informed decisions based on REAL DATA
65
128
  \`\`\`
66
129
 
67
130
  ### 🔄 CRITICAL: Sync User Modifications Before Working
@@ -356,25 +419,54 @@ function processIncident(incident, priority, assignee) {
356
419
  | \`arr.map(x => x.id)\` | \`arr.map(function(x) { return x.id; })\` |
357
420
 
358
421
  \`\`\`javascript
359
- // Universal verification pattern
422
+ // Universal verification pattern - COMPLETE IMPLEMENTATION REQUIRED
360
423
  const verify = await snow_execute_script_with_output({
361
424
  script: \`
362
425
  gs.info('=== VERIFICATION TEST ===');
363
426
 
364
- // Test table existence
365
- var table = new GlideRecord('table_name');
366
- gs.info('Table valid: ' + table.isValid());
427
+ // Test ACTUAL table existence - NO PLACEHOLDERS
428
+ var incidentTable = new GlideRecord('incident');
429
+ gs.info('Incident table valid: ' + incidentTable.isValid());
367
430
 
368
- // Test property existence
369
- var prop = gs.getProperty('property.name');
370
- gs.info('Property: ' + (prop || 'NOT SET'));
431
+ // Count REAL records
432
+ incidentTable.addQuery('active', true);
433
+ incidentTable.query();
434
+ var count = 0;
435
+ while (incidentTable.next() && count < 10) {
436
+ count++;
437
+ gs.info('Found: ' + incidentTable.number + ' - ' + incidentTable.short_description);
438
+ }
439
+ gs.info('Total active incidents: ' + incidentTable.getRowCount());
440
+
441
+ // Test ACTUAL property - use real property names
442
+ var instanceName = gs.getProperty('instance_name');
443
+ var glideVersion = gs.getProperty('glide.version');
444
+ gs.info('Instance: ' + instanceName);
445
+ gs.info('Version: ' + glideVersion);
371
446
 
372
- // Test actual code
447
+ // Test COMPLETE user code - NO STUBS
373
448
  try {
374
- // User's code here
375
- gs.info('SUCCESS');
449
+ // REAL implementation - not placeholder
450
+ var userGr = new GlideRecord('sys_user');
451
+ userGr.addQuery('active', true);
452
+ userGr.addQuery('user_name', gs.getUserName());
453
+ userGr.query();
454
+ if (userGr.next()) {
455
+ gs.info('Current user: ' + userGr.name + ' (' + userGr.email + ')');
456
+ gs.info('Roles: ' + userGr.roles.toString());
457
+ }
458
+
459
+ // Test ACTUAL business logic
460
+ var taskGr = new GlideRecord('task');
461
+ taskGr.addQuery('assigned_to', gs.getUserID());
462
+ taskGr.addQuery('active', true);
463
+ taskGr.query();
464
+ gs.info('Active tasks assigned to me: ' + taskGr.getRowCount());
465
+
466
+ gs.info('=== VERIFICATION COMPLETE ===');
376
467
  } catch(e) {
377
468
  gs.error('ERROR: ' + e.message);
469
+ gs.error('Stack: ' + e.stack);
378
470
  }
379
471
  \`
380
472
  });
@@ -529,8 +621,10 @@ Follow this systematic approach for all debugging:
529
621
 
530
622
  ### Widget Development
531
623
 
624
+ **🚨 NO MOCK WIDGETS - EVERY WIDGET MUST BE COMPLETE AND FUNCTIONAL**
625
+
532
626
  **CRITICAL: Direct Widget Updates (Not Background Scripts!)**
533
- - Use \`snow_update({ type: 'widget', identifier: 'widget_name', config: { /* fields to update */ }})\`
627
+ - Use \`snow_update({ type: 'widget', identifier: 'widget_name', config: { /* COMPLETE fields */ }})\`
534
628
  - Updates widget fields DIRECTLY on the widget record
535
629
  - Do NOT use background scripts to update widget fields
536
630
  - Do NOT try to import server scripts into client scripts
@@ -540,17 +634,233 @@ Follow this systematic approach for all debugging:
540
634
  - Use Angular providers correctly
541
635
  - Implement proper data binding
542
636
  - Test across different themes and portals
637
+ - **NO PLACEHOLDER CONTENT - Every widget must be production-ready**
543
638
 
544
- **Creating New Widgets:**
639
+ **Creating New Widgets - COMPLETE IMPLEMENTATION REQUIRED:**
545
640
  \`\`\`javascript
641
+ // ❌ WRONG - Mock/placeholder widget
546
642
  snow_deploy({
547
643
  type: 'widget',
548
644
  config: {
549
- name: 'my_widget',
550
- title: 'My Widget', // Required for display
551
- template: '<div>{{data.message}}</div>', // Required HTML
552
- script: 'data.message = "Hello";', // ServiceNow uses 'script' field
553
- client_script: 'function($scope) { var c = this; }'
645
+ name: 'test_widget',
646
+ template: '<div>TODO: Add content</div>', // NO!
647
+ script: '// TODO: Add logic', // NO!
648
+ client_script: '// Placeholder' // NO!
649
+ }
650
+ })
651
+
652
+ // ✅ CORRECT - Complete, functional widget
653
+ snow_deploy({
654
+ type: 'widget',
655
+ config: {
656
+ name: 'incident_dashboard_widget',
657
+ title: 'Incident Dashboard',
658
+ template: \`
659
+ <div class="incident-dashboard">
660
+ <div class="dashboard-header">
661
+ <h2>{{data.title}}</h2>
662
+ <span class="refresh-time">{{data.lastRefresh}}</span>
663
+ </div>
664
+ <div class="stats-container">
665
+ <div class="stat-card" ng-repeat="stat in data.stats">
666
+ <div class="stat-value">{{stat.value}}</div>
667
+ <div class="stat-label">{{stat.label}}</div>
668
+ </div>
669
+ </div>
670
+ <div class="incident-list">
671
+ <table class="table">
672
+ <thead>
673
+ <tr>
674
+ <th>Number</th>
675
+ <th>Short Description</th>
676
+ <th>Priority</th>
677
+ <th>Assigned To</th>
678
+ </tr>
679
+ </thead>
680
+ <tbody>
681
+ <tr ng-repeat="incident in data.incidents" ng-click="c.openIncident(incident.sys_id)">
682
+ <td>{{incident.number}}</td>
683
+ <td>{{incident.short_description}}</td>
684
+ <td><span class="priority-{{incident.priority}}">{{incident.priority}}</span></td>
685
+ <td>{{incident.assigned_to}}</td>
686
+ </tr>
687
+ </tbody>
688
+ </table>
689
+ </div>
690
+ </div>
691
+ \`,
692
+ script: \`
693
+ // COMPLETE server-side implementation
694
+ (function() {
695
+ data.title = 'Incident Dashboard';
696
+ data.lastRefresh = new GlideDateTime().getDisplayValue();
697
+
698
+ // Get incident statistics
699
+ data.stats = [];
700
+
701
+ var totalGr = new GlideAggregate('incident');
702
+ totalGr.addQuery('active', true);
703
+ totalGr.addAggregate('COUNT');
704
+ totalGr.query();
705
+ if (totalGr.next()) {
706
+ data.stats.push({
707
+ value: totalGr.getAggregate('COUNT'),
708
+ label: 'Total Active'
709
+ });
710
+ }
711
+
712
+ var criticalGr = new GlideAggregate('incident');
713
+ criticalGr.addQuery('active', true);
714
+ criticalGr.addQuery('priority', '1');
715
+ criticalGr.addAggregate('COUNT');
716
+ criticalGr.query();
717
+ if (criticalGr.next()) {
718
+ data.stats.push({
719
+ value: criticalGr.getAggregate('COUNT'),
720
+ label: 'Critical'
721
+ });
722
+ }
723
+
724
+ // Get recent incidents
725
+ data.incidents = [];
726
+ var incGr = new GlideRecord('incident');
727
+ incGr.addQuery('active', true);
728
+ incGr.orderByDesc('sys_created_on');
729
+ incGr.setLimit(10);
730
+ incGr.query();
731
+
732
+ while (incGr.next()) {
733
+ data.incidents.push({
734
+ sys_id: incGr.getUniqueValue(),
735
+ number: incGr.getValue('number'),
736
+ short_description: incGr.getValue('short_description'),
737
+ priority: incGr.getValue('priority'),
738
+ assigned_to: incGr.assigned_to.getDisplayValue()
739
+ });
740
+ }
741
+
742
+ // Handle server actions
743
+ if (input && input.action === 'refresh') {
744
+ // Refresh logic
745
+ data.lastRefresh = new GlideDateTime().getDisplayValue();
746
+ }
747
+ })();
748
+ \`,
749
+ client_script: \`
750
+ function($scope, $window, spModal) {
751
+ var c = this;
752
+
753
+ // Initialize client controller
754
+ c.refreshInterval = null;
755
+
756
+ // Open incident in new window
757
+ c.openIncident = function(sysId) {
758
+ var url = '/nav_to.do?uri=incident.do?sys_id=' + sysId;
759
+ $window.open(url, '_blank');
760
+ };
761
+
762
+ // Refresh data
763
+ c.refresh = function() {
764
+ c.server.get({
765
+ action: 'refresh'
766
+ }).then(function(response) {
767
+ console.log('Dashboard refreshed');
768
+ });
769
+ };
770
+
771
+ // Auto-refresh every 30 seconds
772
+ c.startAutoRefresh = function() {
773
+ c.refreshInterval = setInterval(function() {
774
+ $scope.$apply(function() {
775
+ c.refresh();
776
+ });
777
+ }, 30000);
778
+ };
779
+
780
+ // Clean up on destroy
781
+ $scope.$on('$destroy', function() {
782
+ if (c.refreshInterval) {
783
+ clearInterval(c.refreshInterval);
784
+ }
785
+ });
786
+
787
+ // Start auto-refresh
788
+ c.startAutoRefresh();
789
+ }
790
+ \`,
791
+ css: \`
792
+ .incident-dashboard {
793
+ padding: 20px;
794
+ background: #f5f5f5;
795
+ }
796
+
797
+ .dashboard-header {
798
+ display: flex;
799
+ justify-content: space-between;
800
+ margin-bottom: 20px;
801
+ }
802
+
803
+ .stats-container {
804
+ display: flex;
805
+ gap: 15px;
806
+ margin-bottom: 20px;
807
+ }
808
+
809
+ .stat-card {
810
+ flex: 1;
811
+ background: white;
812
+ padding: 15px;
813
+ border-radius: 8px;
814
+ box-shadow: 0 2px 4px rgba(0,0,0,0.1);
815
+ text-align: center;
816
+ }
817
+
818
+ .stat-value {
819
+ font-size: 32px;
820
+ font-weight: bold;
821
+ color: #333;
822
+ }
823
+
824
+ .stat-label {
825
+ font-size: 14px;
826
+ color: #666;
827
+ margin-top: 5px;
828
+ }
829
+
830
+ .incident-list {
831
+ background: white;
832
+ border-radius: 8px;
833
+ padding: 15px;
834
+ }
835
+
836
+ .incident-list tr {
837
+ cursor: pointer;
838
+ }
839
+
840
+ .incident-list tr:hover {
841
+ background: #f0f0f0;
842
+ }
843
+
844
+ .priority-1 { color: #d9534f; font-weight: bold; }
845
+ .priority-2 { color: #f0ad4e; }
846
+ .priority-3 { color: #5bc0de; }
847
+ .priority-4 { color: #5cb85c; }
848
+ .priority-5 { color: #777; }
849
+ \`,
850
+ option_schema: [
851
+ {
852
+ name: 'refresh_interval',
853
+ label: 'Refresh Interval (seconds)',
854
+ type: 'integer',
855
+ default: 30
856
+ },
857
+ {
858
+ name: 'max_incidents',
859
+ label: 'Maximum Incidents to Display',
860
+ type: 'integer',
861
+ default: 10
862
+ }
863
+ ]
554
864
  }
555
865
  })
556
866
  \`\`\`
@@ -1058,7 +1368,31 @@ gs.info('Field exists: ' + (element ? 'Yes' : 'No'));
1058
1368
 
1059
1369
  ## Conclusion
1060
1370
 
1061
- Snow-Flow is a powerful framework for ServiceNow development that emphasizes verification, testing, and evidence-based decision making. By following these guidelines and best practices, you ensure reliable, maintainable, and effective ServiceNow solutions.
1062
-
1063
- Remember: Your job is to solve problems, not to judge implementations. Every environment has its reasons for existing configurations. Verify, test, and respect what you find.`;
1371
+ Snow-Flow is a powerful framework for ServiceNow development that demands **COMPLETE, PRODUCTION-READY IMPLEMENTATIONS** with absolutely **NO MOCK DATA, NO PLACEHOLDERS, and NO SHORTCUTS**.
1372
+
1373
+ **The Snow-Flow Standard:**
1374
+ - **EVERY** line of code must be complete and functional
1375
+ - **EVERY** feature must be fully implemented
1376
+ - **EVERY** integration must be real and working
1377
+ - **EVERY** solution must be production-ready
1378
+ - **NO EXCEPTIONS, NO EXCUSES**
1379
+
1380
+ By following these guidelines and the **NO MOCK DATA** principle, you ensure:
1381
+ - Reliable, maintainable ServiceNow solutions
1382
+ - Complete implementations that work in production
1383
+ - Professional-grade code that users can depend on
1384
+ - Real solutions to real problems
1385
+
1386
+ Remember:
1387
+ 1. **NO MOCK DATA** - Everything must be real
1388
+ 2. **TAKE THE TIME** - Do it right, no shortcuts
1389
+ 3. **COMPLETE IMPLEMENTATIONS** - Every feature, every time
1390
+ 4. **PRODUCTION READY** - Users depend on this being real
1391
+ 5. **VERIFY AND TEST** - With real data, real systems
1392
+
1393
+ Your job is to deliver **COMPLETE, WORKING SOLUTIONS**. Every implementation matters. Every line of code counts. Every feature must work.
1394
+
1395
+ **TAKE THE TIME. DO IT RIGHT. NO MOCK DATA. NO EXCEPTIONS.**`;
1396
+ // Add version constant to track template updates
1397
+ exports.CLAUDE_MD_TEMPLATE_VERSION = '3.6.1-NO-MOCK-DATA';
1064
1398
  //# sourceMappingURL=claude-md-template.js.map
@@ -0,0 +1,109 @@
1
+ /**
2
+ * ServiceNow Audit Logger - Snow-Flow Activity Tracking
3
+ *
4
+ * Extends the existing MCPLogger to send comprehensive audit logs
5
+ * to ServiceNow for all Snow-Flow activities with token usage tracking.
6
+ *
7
+ * Creates audit trail with source 'snow-flow' for compliance & debugging.
8
+ */
9
+ import { MCPLogger } from '../mcp/shared/mcp-logger.js';
10
+ import { ServiceNowClient } from './servicenow-client.js';
11
+ export interface AuditLogEntry {
12
+ source: 'snow-flow';
13
+ level: 'INFO' | 'WARN' | 'ERROR' | 'DEBUG';
14
+ message: string;
15
+ operation: string;
16
+ table?: string;
17
+ sys_id?: string;
18
+ user_id?: string;
19
+ token_usage?: {
20
+ input: number;
21
+ output: number;
22
+ total: number;
23
+ };
24
+ duration_ms?: number;
25
+ metadata?: any;
26
+ timestamp: string;
27
+ session_id?: string;
28
+ mcp_server: string;
29
+ }
30
+ export declare class ServiceNowAuditLogger {
31
+ private mcpLogger;
32
+ private serviceNowClient?;
33
+ private sessionId;
34
+ private mcpServerName;
35
+ private isEnabled;
36
+ private auditQueue;
37
+ private batchTimer?;
38
+ constructor(mcpLogger: MCPLogger, mcpServerName: string);
39
+ /**
40
+ * Initialize with ServiceNow client for audit log transmission
41
+ */
42
+ setServiceNowClient(client: ServiceNowClient): void;
43
+ /**
44
+ * Generate unique session ID for tracking related operations
45
+ */
46
+ private generateSessionId;
47
+ /**
48
+ * Log Snow-Flow operation with comprehensive audit trail
49
+ */
50
+ logOperation(operation: string, level?: 'INFO' | 'WARN' | 'ERROR' | 'DEBUG', details?: {
51
+ message?: string;
52
+ table?: string;
53
+ sys_id?: string;
54
+ duration_ms?: number;
55
+ metadata?: any;
56
+ success?: boolean;
57
+ }): Promise<void>;
58
+ /**
59
+ * Log API call with token tracking
60
+ */
61
+ logAPICall(apiMethod: string, table: string, operation: string, recordCount?: number, duration_ms?: number, success?: boolean): Promise<void>;
62
+ /**
63
+ * Log widget operations with specific tracking
64
+ */
65
+ logWidgetOperation(operation: 'pull' | 'push' | 'validate' | 'deploy', widgetSysId: string, widgetName?: string, duration_ms?: number, success?: boolean, errorDetails?: any): Promise<void>;
66
+ /**
67
+ * Log artifact sync operations
68
+ */
69
+ logArtifactSync(action: 'pull' | 'push' | 'cleanup', table: string, sys_id: string, artifactName?: string, fileCount?: number, duration_ms?: number, success?: boolean): Promise<void>;
70
+ /**
71
+ * Log script execution with ES5 validation
72
+ */
73
+ logScriptExecution(scriptType: 'background' | 'business_rule' | 'client_script', duration_ms?: number, success?: boolean, errorDetails?: any, outputLines?: number): Promise<void>;
74
+ /**
75
+ * Log authentication and token operations
76
+ */
77
+ logAuthOperation(operation: 'login' | 'token_refresh' | 'scope_elevation', success?: boolean, details?: any): Promise<void>;
78
+ /**
79
+ * Schedule batch sending to ServiceNow to avoid API flooding
80
+ */
81
+ private scheduleBatchSend;
82
+ /**
83
+ * Send audit log batch to ServiceNow
84
+ */
85
+ private sendAuditBatch;
86
+ /**
87
+ * Flush all pending audit logs immediately
88
+ */
89
+ flush(): Promise<void>;
90
+ /**
91
+ * Create audit logger wrapper for existing MCP server
92
+ */
93
+ static wrap(mcpLogger: MCPLogger, mcpServerName: string): ServiceNowAuditLogger;
94
+ /**
95
+ * Get audit statistics
96
+ */
97
+ getAuditStats(): {
98
+ session_id: string;
99
+ pending_logs: number;
100
+ is_enabled: boolean;
101
+ has_servicenow_client: boolean;
102
+ };
103
+ }
104
+ export declare function getAuditLogger(mcpLogger: MCPLogger, mcpServerName: string): ServiceNowAuditLogger;
105
+ /**
106
+ * Initialize all audit loggers with ServiceNow client
107
+ */
108
+ export declare function initializeAuditLogging(serviceNowClient: ServiceNowClient): void;
109
+ //# sourceMappingURL=servicenow-audit-logger.d.ts.map