snow-flow 1.3.11 → 1.3.12

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
@@ -61,6 +61,118 @@ program
61
61
  .name('snow-flow')
62
62
  .description('ServiceNow Multi-Agent Development Framework')
63
63
  .version(version_js_1.VERSION);
64
+ // Helper function to deploy XML to ServiceNow
65
+ async function deployXMLToServiceNow(xmlFile, options = {}) {
66
+ const oauth = new snow_oauth_js_1.ServiceNowOAuth();
67
+ const isAuthenticated = await oauth.getStoredTokens() !== null;
68
+ if (!isAuthenticated) {
69
+ cliLogger.error('❌ Not authenticated. Please run: snow-flow auth login');
70
+ return false;
71
+ }
72
+ try {
73
+ // Initialize ServiceNow client
74
+ const client = new servicenow_client_js_1.ServiceNowClient();
75
+ // Read XML file
76
+ if (!(0, fs_2.existsSync)(xmlFile)) {
77
+ cliLogger.error(`❌ XML file not found: ${xmlFile}`);
78
+ return false;
79
+ }
80
+ cliLogger.info('📄 Reading XML file...');
81
+ const xmlContent = await fs_1.promises.readFile(xmlFile, 'utf-8');
82
+ // Import XML as remote update set
83
+ cliLogger.info('📤 Importing XML to ServiceNow...');
84
+ const importResponse = await client.makeRequest({
85
+ method: 'POST',
86
+ url: '/api/now/table/sys_remote_update_set',
87
+ headers: {
88
+ 'Content-Type': 'application/xml',
89
+ 'Accept': 'application/json'
90
+ },
91
+ data: xmlContent
92
+ });
93
+ if (!importResponse.result || !importResponse.result.sys_id) {
94
+ throw new Error('Failed to import XML update set');
95
+ }
96
+ const remoteUpdateSetId = importResponse.result.sys_id;
97
+ cliLogger.info(`✅ XML imported successfully (sys_id: ${remoteUpdateSetId})`);
98
+ // Load the update set
99
+ cliLogger.info('🔄 Loading update set...');
100
+ await client.makeRequest({
101
+ method: 'PUT',
102
+ url: `/api/now/table/sys_remote_update_set/${remoteUpdateSetId}`,
103
+ data: {
104
+ state: 'loaded'
105
+ }
106
+ });
107
+ // Find the loaded update set
108
+ const loadedResponse = await client.makeRequest({
109
+ method: 'GET',
110
+ url: '/api/now/table/sys_update_set',
111
+ params: {
112
+ sysparm_query: `remote_sys_id=${remoteUpdateSetId}`,
113
+ sysparm_limit: 1
114
+ }
115
+ });
116
+ if (!loadedResponse.result || loadedResponse.result.length === 0) {
117
+ throw new Error('Failed to find loaded update set');
118
+ }
119
+ const updateSetId = loadedResponse.result[0].sys_id;
120
+ const updateSetName = loadedResponse.result[0].name;
121
+ cliLogger.info(`✅ Update set loaded: ${updateSetName}`);
122
+ // Preview if requested
123
+ if (options.preview !== false) {
124
+ cliLogger.info('🔍 Previewing update set...');
125
+ await client.makeRequest({
126
+ method: 'POST',
127
+ url: `/api/now/table/sys_update_set/${updateSetId}/preview`
128
+ });
129
+ // Check preview results
130
+ const previewProblems = await client.makeRequest({
131
+ method: 'GET',
132
+ url: '/api/now/table/sys_update_preview_problem',
133
+ params: {
134
+ sysparm_query: `update_set=${updateSetId}`,
135
+ sysparm_limit: 100
136
+ }
137
+ });
138
+ if (previewProblems.result && previewProblems.result.length > 0) {
139
+ cliLogger.warn('\n⚠️ Preview found problems:');
140
+ previewProblems.result.forEach((p) => {
141
+ cliLogger.warn(` - ${p.type}: ${p.description}`);
142
+ });
143
+ if (options.commit !== false) {
144
+ cliLogger.warn('\n⚠️ Skipping auto-commit due to preview problems');
145
+ cliLogger.info('📋 Review and resolve problems in ServiceNow, then commit manually');
146
+ return false;
147
+ }
148
+ }
149
+ else {
150
+ cliLogger.info('✅ Preview successful - no problems found');
151
+ }
152
+ // Commit if clean and requested
153
+ if (options.commit !== false && (!previewProblems.result || previewProblems.result.length === 0)) {
154
+ cliLogger.info('🚀 Committing update set...');
155
+ await client.makeRequest({
156
+ method: 'POST',
157
+ url: `/api/now/table/sys_update_set/${updateSetId}/commit`
158
+ });
159
+ cliLogger.info('\n✅ Update Set committed successfully!');
160
+ cliLogger.info('📍 Navigate to Flow Designer > Designer to see your flow');
161
+ cliLogger.info('\n🎉 Deployment complete!');
162
+ return true;
163
+ }
164
+ }
165
+ return true;
166
+ }
167
+ catch (error) {
168
+ cliLogger.error('\n❌ Deployment failed:', error instanceof Error ? error.message : String(error));
169
+ cliLogger.info('\n💡 Troubleshooting tips:');
170
+ cliLogger.info(' 1. Check your authentication: snow-flow auth status');
171
+ cliLogger.info(' 2. Verify XML file format is correct');
172
+ cliLogger.info(' 3. Ensure you have required permissions in ServiceNow');
173
+ return false;
174
+ }
175
+ }
64
176
  // Swarm command - the main orchestration command with EVERYTHING
65
177
  program
66
178
  .command('swarm <objective>')
@@ -275,9 +387,27 @@ program
275
387
  // Check if auto-deploy is enabled
276
388
  if (options.autoDeploy !== false) { // Default is true from swarm command
277
389
  cliLogger.info('\n🚀 Auto-Deploy enabled - importing XML to ServiceNow...');
278
- cliLogger.info('\n💡 To deploy, use the following command:');
279
- cliLogger.info(` snow-flow deploy-xml "${result.filePath}"`);
280
- cliLogger.info('\nThis will automatically import, preview, and commit the flow to ServiceNow.');
390
+ // Automatically deploy the XML file
391
+ const deploySuccess = await deployXMLToServiceNow(result.filePath, {
392
+ preview: true,
393
+ commit: true
394
+ });
395
+ if (deploySuccess) {
396
+ cliLogger.info('\n✅ Flow automatically deployed to ServiceNow!');
397
+ cliLogger.info('🎯 The flow is now available in Flow Designer');
398
+ // Store deployment success in memory
399
+ memorySystem.storeLearning(`deployment_${sessionId}`, {
400
+ success: true,
401
+ xml_file: result.filePath,
402
+ deployed_at: new Date().toISOString(),
403
+ flow_name: flowDef.name
404
+ });
405
+ }
406
+ else {
407
+ cliLogger.warn('\n⚠️ Automatic deployment encountered issues');
408
+ cliLogger.info('💡 You can manually deploy later with:');
409
+ cliLogger.info(` snow-flow deploy-xml "${result.filePath}"`);
410
+ }
281
411
  }
282
412
  else {
283
413
  cliLogger.info('📋 Use the import instructions above to deploy to ServiceNow');
@@ -1725,111 +1855,13 @@ program
1725
1855
  .action(async (xmlFile, options) => {
1726
1856
  console.log(`\n📦 Deploying XML Update Set: ${xmlFile}`);
1727
1857
  console.log('='.repeat(60));
1728
- const oauth = new snow_oauth_js_1.ServiceNowOAuth();
1729
- const isAuthenticated = await oauth.getStoredTokens() !== null;
1730
- if (!isAuthenticated) {
1731
- console.log('❌ Not authenticated. Please run: snow-flow auth login');
1732
- return;
1733
- }
1734
- try {
1735
- // Initialize ServiceNow client
1736
- const client = new servicenow_client_js_1.ServiceNowClient();
1737
- // Read XML file
1738
- if (!(0, fs_2.existsSync)(xmlFile)) {
1739
- console.error(`❌ XML file not found: ${xmlFile}`);
1740
- return;
1741
- }
1742
- console.log('📄 Reading XML file...');
1743
- const xmlContent = await fs_1.promises.readFile(xmlFile, 'utf-8');
1744
- // Import XML as remote update set
1745
- console.log('📤 Importing XML to ServiceNow...');
1746
- const importResponse = await client.makeRequest({
1747
- method: 'POST',
1748
- url: '/api/now/table/sys_remote_update_set',
1749
- headers: {
1750
- 'Content-Type': 'application/xml',
1751
- 'Accept': 'application/json'
1752
- },
1753
- data: xmlContent
1754
- });
1755
- if (!importResponse.result || !importResponse.result.sys_id) {
1756
- throw new Error('Failed to import XML update set');
1757
- }
1758
- const remoteUpdateSetId = importResponse.result.sys_id;
1759
- console.log(`✅ XML imported successfully (sys_id: ${remoteUpdateSetId})`);
1760
- // Load the update set
1761
- console.log('🔄 Loading update set...');
1762
- await client.makeRequest({
1763
- method: 'PUT',
1764
- url: `/api/now/table/sys_remote_update_set/${remoteUpdateSetId}`,
1765
- data: {
1766
- state: 'loaded'
1767
- }
1768
- });
1769
- // Find the loaded update set
1770
- const loadedResponse = await client.makeRequest({
1771
- method: 'GET',
1772
- url: '/api/now/table/sys_update_set',
1773
- params: {
1774
- sysparm_query: `remote_sys_id=${remoteUpdateSetId}`,
1775
- sysparm_limit: 1
1776
- }
1777
- });
1778
- if (!loadedResponse.result || loadedResponse.result.length === 0) {
1779
- throw new Error('Failed to find loaded update set');
1780
- }
1781
- const updateSetId = loadedResponse.result[0].sys_id;
1782
- const updateSetName = loadedResponse.result[0].name;
1783
- console.log(`✅ Update set loaded: ${updateSetName}`);
1784
- // Preview if requested
1785
- if (options.preview !== false) {
1786
- console.log('🔍 Previewing update set...');
1787
- await client.makeRequest({
1788
- method: 'POST',
1789
- url: `/api/now/table/sys_update_set/${updateSetId}/preview`
1790
- });
1791
- // Check preview results
1792
- const previewProblems = await client.makeRequest({
1793
- method: 'GET',
1794
- url: '/api/now/table/sys_update_preview_problem',
1795
- params: {
1796
- sysparm_query: `update_set=${updateSetId}`,
1797
- sysparm_limit: 100
1798
- }
1799
- });
1800
- if (previewProblems.result && previewProblems.result.length > 0) {
1801
- console.log('\n⚠️ Preview found problems:');
1802
- previewProblems.result.forEach((p) => {
1803
- console.log(` - ${p.type}: ${p.description}`);
1804
- });
1805
- if (options.commit !== false) {
1806
- console.log('\n⚠️ Skipping auto-commit due to preview problems');
1807
- console.log('📋 Review and resolve problems in ServiceNow, then commit manually');
1808
- return;
1809
- }
1810
- }
1811
- else {
1812
- console.log('✅ Preview successful - no problems found');
1813
- }
1814
- // Commit if clean and requested
1815
- if (options.commit !== false && (!previewProblems.result || previewProblems.result.length === 0)) {
1816
- console.log('🚀 Committing update set...');
1817
- await client.makeRequest({
1818
- method: 'POST',
1819
- url: `/api/now/table/sys_update_set/${updateSetId}/commit`
1820
- });
1821
- console.log('\n✅ Update Set committed successfully!');
1822
- console.log('📍 Navigate to Flow Designer > Designer to see your flow');
1823
- console.log('\n🎉 Deployment complete!');
1824
- }
1825
- }
1826
- }
1827
- catch (error) {
1828
- console.error('\n❌ Deployment failed:', error instanceof Error ? error.message : String(error));
1829
- console.log('\n💡 Troubleshooting tips:');
1830
- console.log(' 1. Check your authentication: snow-flow auth status');
1831
- console.log(' 2. Verify XML file format is correct');
1832
- console.log(' 3. Ensure you have required permissions in ServiceNow');
1858
+ // Use the shared deploy function
1859
+ const success = await deployXMLToServiceNow(xmlFile, {
1860
+ preview: options.preview,
1861
+ commit: options.commit
1862
+ });
1863
+ if (!success) {
1864
+ process.exit(1);
1833
1865
  }
1834
1866
  });
1835
1867
  // Help command
package/dist/version.js CHANGED
@@ -7,12 +7,20 @@ exports.VERSION_INFO = exports.VERSION = void 0;
7
7
  exports.getVersionString = getVersionString;
8
8
  exports.getLatestFeatures = getLatestFeatures;
9
9
  exports.isLatestVersion = isLatestVersion;
10
- exports.VERSION = '1.3.11';
10
+ exports.VERSION = '1.3.12';
11
11
  exports.VERSION_INFO = {
12
12
  version: exports.VERSION,
13
13
  name: 'Snow-Flow',
14
14
  description: 'ServiceNow Queen Agent - Hive-Mind Intelligence for ServiceNow Development',
15
15
  features: {
16
+ '1.3.12': [
17
+ '🚀 AUTO-DEPLOY XML: Swarm command now automatically deploys flow XML to ServiceNow',
18
+ '✨ ZERO MANUAL STEPS: Generate → Import → Preview → Commit all automatic',
19
+ '🎯 SMART ERROR HANDLING: Falls back to manual deployment if issues occur',
20
+ '🔧 SHARED DEPLOYMENT: Both swarm and deploy-xml use same deployment logic',
21
+ '💾 DEPLOYMENT TRACKING: Successful deployments tracked in memory system',
22
+ '✅ COMPLETE AUTOMATION: No more manual "deploy-xml" command needed'
23
+ ],
16
24
  '1.3.11': [
17
25
  '🔥 IMPROVED FLOW GENERATOR: Complete rewrite fixing "too small to work" issue',
18
26
  '✅ V2 TABLE STRUCTURES: Uses sys_hub_action_instance_v2 and sys_hub_trigger_instance_v2',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "snow-flow",
3
- "version": "1.3.11",
3
+ "version": "1.3.12",
4
4
  "description": "ServiceNow Queen Agent - Hive-Mind Intelligence for ServiceNow Development inspired by claude-flow. Transform complex workflows into elegant one-command orchestration.",
5
5
  "main": "dist/index.js",
6
6
  "type": "commonjs",