snow-flow 1.1.78 โ†’ 1.1.80

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/CLAUDE.md CHANGED
@@ -112,6 +112,239 @@ snow-flow queen-memory export my-patterns.json
112
112
  - CHECK current update set before starting work
113
113
  - COMPLETE update sets before moving between environments
114
114
 
115
+ ## ๐Ÿ”’ MANDATORY ServiceNow Development Workflow (v1.1.79+)
116
+
117
+ ### ๐Ÿšจ CRITICAL: All ServiceNow Operations MUST Follow This Workflow
118
+
119
+ **Every single ServiceNow operation must start with authentication validation!** The MCP servers now automatically enforce this workflow.
120
+
121
+ #### **STEP 1: MANDATORY Authentication Validation**
122
+
123
+ ```javascript
124
+ // This happens automatically in ALL MCP tools
125
+ const connectionResult = await validateServiceNowConnection();
126
+ if (!connectionResult.success) {
127
+ return createAuthenticationError(connectionResult.error);
128
+ }
129
+ ```
130
+
131
+ **What This Checks:**
132
+ 1. โœ… **Credentials Exist**: .env file has OAuth settings
133
+ 2. โœ… **OAuth Session Active**: Valid access token exists
134
+ 3. โœ… **Token Valid**: Not expired, auto-refresh if needed
135
+ 4. โœ… **Live Connection**: Actual ServiceNow instance responds
136
+
137
+ **If Authentication Fails, You Get:**
138
+ ```
139
+ โŒ ServiceNow Connection Failed
140
+
141
+ OAuth authentication required. Run "snow-flow auth login" to authenticate.
142
+
143
+ ๐Ÿ”ง To fix this:
144
+
145
+ 1. Ensure .env file has OAuth credentials:
146
+ SNOW_INSTANCE=your-instance.service-now.com
147
+ SNOW_CLIENT_ID=your_oauth_client_id
148
+ SNOW_CLIENT_SECRET=your_oauth_client_secret
149
+
150
+ 2. Authenticate with ServiceNow:
151
+ snow-flow auth login
152
+
153
+ 3. If you still get errors, run diagnostics:
154
+ snow_auth_diagnostics()
155
+ ```
156
+
157
+ #### **STEP 2: Smart Artifact Discovery (DRY Principle)**
158
+
159
+ ```javascript
160
+ // Automatic discovery before creating anything new
161
+ const discovery = await discoverExistingArtifacts(
162
+ type, // 'widget', 'flow', 'script', etc.
163
+ artifactName, // Extracted from instruction/config
164
+ searchTerms // Related keywords for comprehensive search
165
+ );
166
+
167
+ if (discovery.found) {
168
+ console.log(`๐Ÿ” Found ${discovery.artifacts.length} existing artifacts`);
169
+ console.log(`๐Ÿ’ก Suggestions: ${discovery.suggestions.join(', ')}`);
170
+ }
171
+ ```
172
+
173
+ **Discovery Results Include:**
174
+ - ๐Ÿ“‹ **Existing Artifacts**: Similar names and functionality
175
+ - ๐Ÿ’ก **Reuse Suggestions**: "Consider reusing: Widget A, Widget B"
176
+ - ๐Ÿ” **Related Items**: Found by description and keywords
177
+ - โš ๏ธ **Duplication Warnings**: Prevents creating identical artifacts
178
+
179
+ #### **STEP 3: Automatic Update Set Management**
180
+
181
+ ```javascript
182
+ // Automatic Update Set creation and tracking
183
+ const updateSetId = await ensureUpdateSet(context, purpose);
184
+
185
+ // After every deployment
186
+ await trackArtifact(sysId, type, name, updateSetId);
187
+ ```
188
+
189
+ **Update Set Features:**
190
+ - ๐Ÿ“ฆ **Auto-Creation**: Creates Update Set if none exists
191
+ - ๐Ÿท๏ธ **Smart Naming**: `Snow-Flow Widget Deployment - 2024-01-15`
192
+ - ๐Ÿ“‹ **Auto-Tracking**: Every artifact automatically tracked
193
+ - ๐Ÿ”„ **Session Management**: Links to Agent session for coordination
194
+
195
+ ### ๐Ÿ›ก๏ธ Error Recovery Patterns with Specific Next Steps
196
+
197
+ #### **Authentication Errors (403, 401)**
198
+
199
+ ```javascript
200
+ // OLD: Generic error
201
+ โŒ "Authentication failed"
202
+
203
+ // NEW: Specific recovery steps
204
+ โŒ ServiceNow Connection Failed
205
+
206
+ OAuth token expired and refresh failed. Run "snow-flow auth login" to re-authenticate.
207
+
208
+ ๐Ÿ”ง To fix this:
209
+ 1. Check .env credentials are correct
210
+ 2. Run: snow-flow auth login
211
+ 3. If issues persist: snow_auth_diagnostics()
212
+ ```
213
+
214
+ #### **Deployment Errors with Fallback Strategies**
215
+
216
+ ```javascript
217
+ // Automatic fallback strategies
218
+ if (deployment.failed) {
219
+ // Strategy 1: Try global scope
220
+ if (error.includes('insufficient privileges')) {
221
+ await escalateToGlobalScope();
222
+ }
223
+
224
+ // Strategy 2: Manual steps guide
225
+ if (fallback_strategy === 'manual_steps') {
226
+ return createManualStepsGuide(artifact, error);
227
+ }
228
+
229
+ // Strategy 3: Update Set only
230
+ if (fallback_strategy === 'update_set_only') {
231
+ await createUpdateSetWithInstructions(artifact);
232
+ }
233
+ }
234
+ ```
235
+
236
+ #### **Discovery Conflicts with Resolution Options**
237
+
238
+ ```javascript
239
+ // When existing artifacts found
240
+ if (discovery.found) {
241
+ return {
242
+ options: [
243
+ "1. Reuse existing: incident_dashboard_v2 (recommended)",
244
+ "2. Extend existing with new features",
245
+ "3. Create new with different name: incident_dashboard_v3",
246
+ "4. Override existing (not recommended)"
247
+ ],
248
+ recommendations: [
249
+ "โœ… Reusing saves development time",
250
+ "โš ๏ธ Check if existing meets requirements first",
251
+ "๐Ÿ’ก Consider extending instead of duplicating"
252
+ ]
253
+ };
254
+ }
255
+ ```
256
+
257
+ ### ๐Ÿ”ง Enhanced OAuth Implementation (v1.1.79+)
258
+
259
+ #### **Environment Variable Fallback**
260
+
261
+ The OAuth system now properly supports .env fallback:
262
+
263
+ ```javascript
264
+ // 1. Try OAuth tokens from ~/.snow-flow/auth.json
265
+ // 2. Fallback to .env credentials if no tokens
266
+ // 3. Provide specific error messages for each failure
267
+
268
+ async loadCredentials(): Promise<ServiceNowCredentials | null> {
269
+ // Try saved OAuth tokens first
270
+ const tokens = await this.loadTokens();
271
+ if (tokens?.accessToken) {
272
+ return tokens; // โœ… Valid session found
273
+ }
274
+
275
+ // ๐Ÿ”ง NEW: Fallback to .env file
276
+ const envCredentials = this.loadFromEnv();
277
+ if (envCredentials) {
278
+ // Return credentials without accessToken - signals OAuth login needed
279
+ return envCredentials;
280
+ }
281
+
282
+ // โŒ No credentials found anywhere
283
+ return null;
284
+ }
285
+ ```
286
+
287
+ #### **Automatic Token Refresh**
288
+
289
+ ```javascript
290
+ // Smart token management
291
+ if (token.expired) {
292
+ console.log('๐Ÿ”„ Token expired, attempting refresh...');
293
+
294
+ const refreshResult = await oauth.refreshAccessToken();
295
+ if (refreshResult.success) {
296
+ console.log('โœ… Token refreshed successfully');
297
+ } else {
298
+ return authenticationError('Token refresh failed - login required');
299
+ }
300
+ }
301
+ ```
302
+
303
+ ### ๐Ÿ“‹ MANDATORY Pre-Flight Checklist
304
+
305
+ Before ANY ServiceNow development, ensure:
306
+
307
+ #### **Environment Setup**
308
+ - [ ] โœ… `.env` file has SNOW_INSTANCE, SNOW_CLIENT_ID, SNOW_CLIENT_SECRET
309
+ - [ ] โœ… `snow-flow auth login` completed successfully
310
+ - [ ] โœ… `snow_validate_live_connection()` returns success
311
+
312
+ #### **Development Workflow**
313
+ - [ ] โœ… Start with discovery: `snow_find_artifact()` or `snow_comprehensive_search()`
314
+ - [ ] โœ… Check for reusable components before creating new
315
+ - [ ] โœ… Ensure active Update Set before deployment
316
+ - [ ] โœ… Test with mock data first: `snow_test_flow_with_mock()`
317
+
318
+ #### **Deployment Verification**
319
+ - [ ] โœ… All artifacts tracked in Update Set
320
+ - [ ] โœ… Authentication validated before each operation
321
+ - [ ] โœ… Error recovery plan in place
322
+ - [ ] โœ… Rollback strategy documented
323
+
324
+ ### ๐Ÿšจ Queen Agent Must Develop IN ServiceNow First
325
+
326
+ **CRITICAL RULE**: The Queen Agent and all specialists must always develop directly in the live ServiceNow instance using the MCP tools, never create local documentation or placeholder code.
327
+
328
+ ```bash
329
+ # โœ… CORRECT: Live development
330
+ snow-flow queen "create incident widget"
331
+ # โ†’ Queen uses snow_deploy() with real ServiceNow instance
332
+ # โ†’ Creates actual widget in ServiceNow
333
+ # โ†’ Tracks in Update Set
334
+ # โ†’ Returns sys_id and live URL
335
+
336
+ # โŒ INCORRECT: Local/mock development
337
+ # โ†’ Creates local HTML/CSS files
338
+ # โ†’ Uses placeholder data
339
+ # โ†’ No ServiceNow integration
340
+ ```
341
+
342
+ **Why This Matters:**
343
+ - ๐ŸŽฏ **Real Validation**: Only live environment shows real constraints
344
+ - ๐Ÿ”— **Actual Integration**: Real data connections and dependencies
345
+ - ๐Ÿ“‹ **Proper Tracking**: Update Sets only work with live changes
346
+ - ๐Ÿš€ **Immediate Value**: User can see and test results instantly
347
+
115
348
  ## ๐ŸŽฏ Simplified Deployment API (v1.1.73+)
116
349
 
117
350
  ### One Tool for All Deployments
package/dist/cli.js CHANGED
@@ -479,7 +479,14 @@ Task("${taskAnalysis.primaryAgent}", \`
479
479
  3. Store all work progress in Memory with prefix: "agent_${taskAnalysis.primaryAgent}_"
480
480
  4. Update TodoWrite items as you complete tasks
481
481
  5. Coordinate with supporting agents through Memory
482
- ${isAuthenticated ? '6. Use ServiceNow MCP tools for deployment' : '6. Create artifacts in servicenow/ directory'}
482
+
483
+ ๐Ÿ” AUTHENTICATION WORKFLOW (MANDATORY):
484
+ 1. ALWAYS start with an MCP tool to check authentication status
485
+ 2. If any MCP tool returns auth error:
486
+ - The tool will provide SPECIFIC instructions (e.g., "Run snow-flow auth login")
487
+ - Switch to PLANNING MODE - document the COMPLETE solution
488
+ - Store all plans in Memory for future automated deployment
489
+ 3. NEVER skip directly to local files - always try MCP first!
483
490
  \`);
484
491
  \`\`\`
485
492
 
@@ -502,6 +509,11 @@ Task("${agent}", \`
502
509
  4. Enhance/support with your ${agent} expertise
503
510
  5. Store outputs in Memory with prefix: "agent_${agent}_"
504
511
  6. Update relevant TodoWrite items
512
+
513
+ ๐Ÿ” AUTHENTICATION REQUIREMENTS:
514
+ - ALWAYS use MCP tools first - inherit auth status from primary agent
515
+ - If auth fails, contribute to the PLANNING documentation
516
+ - Store all plans in Memory for future deployment
505
517
  \`);
506
518
  \`\`\``).join('\n')}
507
519
 
@@ -545,7 +557,9 @@ ${hasIntelligentFeatures ? `โœ… **INTELLIGENT MODE ACTIVE** - The following feat
545
557
 
546
558
  ## ๐ŸŽฏ ServiceNow Execution Strategy
547
559
 
548
- ${isAuthenticated ? `### โœ… Live ServiceNow Integration Active
560
+ ### ๐Ÿš€ MANDATORY: Live ServiceNow Development First!
561
+
562
+ **CRITICAL RULE**: All agents MUST attempt to use ServiceNow MCP tools first, regardless of authentication status.
549
563
 
550
564
  ${hasIntelligentFeatures ? `#### ๐Ÿง  Intelligent Orchestration Available
551
565
  Use the unified orchestration tool for complete automation:
@@ -565,9 +579,17 @@ snow_orchestrate_development({
565
579
  \`\`\`
566
580
  ` : ''}
567
581
 
568
- #### ServiceNow MCP Tools Available
569
- Your agents have access to comprehensive MCP tools:
582
+ #### ServiceNow MCP Tools (ALWAYS TRY THESE FIRST!)
583
+ ${isAuthenticated ? 'โœ… Authentication detected - full deployment capabilities' : 'โš ๏ธ No authentication detected - MCP tools will provide specific instructions if auth needed'}
584
+
585
+ Your agents MUST use these MCP tools IN THIS ORDER:
570
586
 
587
+ ๐Ÿ” **PRE-FLIGHT CHECKS** (Always do first!):
588
+ 1. \`snow_find_artifact\` with a simple query to test authentication
589
+ 2. If auth fails, the tool provides specific instructions
590
+ 3. Continue with appropriate strategy based on auth status
591
+
592
+ ๐Ÿ“ฆ **CORE DEVELOPMENT TOOLS**:
571
593
  1. **Deployment Tools** (servicenow-deployment-mcp)
572
594
  - \`snow_deploy\` - Unified deployment for all artifact types
573
595
  - \`snow_preview_widget\` - Preview widgets before deployment
@@ -588,6 +610,12 @@ Your agents have access to comprehensive MCP tools:
588
610
  - \`snow_update_set_add_artifact\` - Track artifacts
589
611
  - \`snow_update_set_complete\` - Complete update sets
590
612
 
613
+ ๐Ÿšจ **ERROR RECOVERY PATTERNS**:
614
+ - Auth Error โ†’ Document complete solution โ†’ Store in Memory โ†’ Guide user
615
+ - Permission Error โ†’ Try global scope โ†’ Document if fails
616
+ - Not Found โ†’ Create new โ†’ Track in Update Set
617
+ - Any Error โ†’ Provide SPECIFIC next steps, not generic messages
618
+
591
619
  ${options.autoDeploy ? `
592
620
  #### โš ๏ธ AUTO-DEPLOYMENT ACTIVE โš ๏ธ
593
621
  - Real artifacts will be created in ServiceNow
@@ -598,17 +626,18 @@ ${options.autoDeploy ? `
598
626
  - No real artifacts will be created
599
627
  - Analysis and recommendations only
600
628
  - Use --auto-deploy to enable deployment
601
- `}` : `### โŒ ServiceNow Integration Disabled
629
+ `}
630
+ ${!isAuthenticated ? `### โŒ ServiceNow Integration Disabled
602
631
 
603
- #### File-Based Development Mode
604
- Agents will create artifacts as files in these directories:
605
- - \`servicenow/widgets/\` - Widget definitions
606
- - \`servicenow/flows/\` - Flow configurations
607
- - \`servicenow/scripts/\` - Script files
608
- - \`servicenow/apps/\` - Application definitions
632
+ #### Planning Mode (Auth Required)
633
+ When authentication is not available, agents will:
634
+ 1. Document the COMPLETE solution architecture
635
+ 2. Create detailed implementation guides
636
+ 3. Store all plans in Memory for future deployment
637
+ 4. Provide SPECIFIC instructions: "Run snow-flow auth login"
609
638
 
610
- Run \`snow-flow auth login\` to enable live ServiceNow integration.
611
- `}
639
+ โš ๏ธ IMPORTANT: This is a FALLBACK mode only!
640
+ Agents must ALWAYS try MCP tools first!` : ''}
612
641
 
613
642
  ## ๐Ÿ‘‘ Queen Agent Coordination Instructions
614
643
 
@@ -730,6 +759,81 @@ Your Queen Agent orchestration is successful when:
730
759
  5. **Validate outputs** before marking complete
731
760
  6. **Store all decisions** in Memory for audit trail
732
761
 
762
+ ## ๐Ÿ“‹ Agent-Specific Authentication & Discovery Workflows
763
+
764
+ ### ๐Ÿ› ๏ธ Widget Creator Agent
765
+ \`\`\`javascript
766
+ // Pre-flight check
767
+ const authCheck = await snow_find_artifact({ query: "test auth", type: "widget" });
768
+ if (authCheck.error?.includes("OAuth")) {
769
+ // Switch to planning mode
770
+ Memory.store("widget_plan", {
771
+ html_template: "<!-- Complete HTML structure -->",
772
+ server_script: "// Complete server logic",
773
+ client_script: "// Complete client controller",
774
+ css_styles: "/* Complete styles */",
775
+ deployment_instructions: "Run snow-flow auth login, then use snow_deploy"
776
+ });
777
+ TodoWrite([{ content: "Widget plan ready - auth required for deployment", status: "completed" }]);
778
+ } else {
779
+ // Continue with live development
780
+ const existing = await snow_comprehensive_search({ query: "similar widget" });
781
+ // ... proceed with snow_deploy
782
+ }
783
+ \`\`\`
784
+
785
+ ### ๐Ÿ”„ Flow Builder Agent
786
+ \`\`\`javascript
787
+ // Check existing flows first
788
+ const flows = await snow_discover_existing_flows({ flow_purpose: "objective" });
789
+ if (flows.error?.includes("OAuth")) {
790
+ // Document flow architecture
791
+ Memory.store("flow_plan", {
792
+ trigger: "When record created on [table]",
793
+ steps: ["Step 1: Validate data", "Step 2: Process", "Step 3: Notify"],
794
+ natural_language: "Complete flow instruction for snow_create_flow",
795
+ deployment_command: "snow_create_flow with instruction from Memory"
796
+ });
797
+ } else {
798
+ // Create flow directly
799
+ await snow_create_flow({ instruction: "natural language description" });
800
+ }
801
+ \`\`\`
802
+
803
+ ### ๐Ÿ“ Script Writer Agent
804
+ \`\`\`javascript
805
+ // Verify permissions
806
+ const permCheck = await snow_get_by_sysid({
807
+ sys_id: "test",
808
+ table: "sys_script_include"
809
+ });
810
+ if (permCheck.error?.includes("OAuth")) {
811
+ // Complete script documentation
812
+ Memory.store("script_solution", {
813
+ script_type: "Business Rule/Script Include/etc",
814
+ code: "// Complete implementation",
815
+ when: "before/after/async",
816
+ table: "target_table",
817
+ deployment_ready: true
818
+ });
819
+ }
820
+ \`\`\`
821
+
822
+ ### ๐Ÿงช Tester Agent
823
+ \`\`\`javascript
824
+ // Tester can start with mock (always works)
825
+ const mockTest = await snow_test_flow_with_mock({
826
+ flow_id: "flow_name",
827
+ test_inputs: { /* test data */ }
828
+ });
829
+ // Then try comprehensive if authenticated
830
+ const liveTest = await snow_comprehensive_flow_test({ flow_sys_id: "id" });
831
+ if (liveTest.error) {
832
+ // Document test results from mock only
833
+ Memory.store("test_results", mockTest);
834
+ }
835
+ \`\`\`
836
+
733
837
  ## ๐Ÿš€ Begin Orchestration
734
838
 
735
839
  Now execute this Queen Agent orchestration plan: