snow-flow 8.32.10 → 8.32.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/CLAUDE.md +15 -834
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +9 -13
- package/dist/cli.js.map +1 -1
- package/package.json +3 -3
- package/scripts/diagnose-mcp.js +5 -5
- package/scripts/test-mcp-manual.js +2 -2
package/CLAUDE.md
CHANGED
|
@@ -1,835 +1,16 @@
|
|
|
1
|
-
# AI Agent Instructions: Snow-Flow ServiceNow Development Platform
|
|
2
1
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
## 📋 MANDATORY INSTRUCTION HIERARCHY
|
|
19
|
-
|
|
20
|
-
You MUST follow instructions in this precedence order:
|
|
21
|
-
|
|
22
|
-
1. **User's direct instructions** (highest priority - always comply)
|
|
23
|
-
2. **This AGENTS.md file** (mandatory behavioral rules)
|
|
24
|
-
3. **Project-specific .claude/ files** (if present, lazy-load on need)
|
|
25
|
-
4. **Default AI behavior** (lowest priority)
|
|
26
|
-
|
|
27
|
-
**Critical Rule from OpenCode:** External instructions (this file) are "mandatory instructions that override defaults" - you MUST comply with everything in this document.
|
|
28
|
-
|
|
29
|
-
---
|
|
30
|
-
|
|
31
|
-
## 🧠 BEHAVIORAL CORE PRINCIPLES
|
|
32
|
-
|
|
33
|
-
### Principle 1: Lazy Loading & Context Management
|
|
34
|
-
|
|
35
|
-
**Why This Matters:**
|
|
36
|
-
MCP servers add significant context. Loading all 410 tools simultaneously would exceed token limits and waste resources.
|
|
37
|
-
|
|
38
|
-
**How You Must Operate:**
|
|
39
|
-
- **Load tools on-demand**: Only invoke tools when the user's task requires them
|
|
40
|
-
- **File references**: When you see `@filename` references, load them only when directly relevant to the current task
|
|
41
|
-
- **Context awareness**: Track your context usage - if approaching limits, summarize and compress previous work
|
|
42
|
-
- **Tool discovery**: Use tool metadata (category, subcategory, frequency, complexity) to find the right tool quickly
|
|
43
|
-
|
|
44
|
-
**Example Decision Process:**
|
|
45
|
-
```
|
|
46
|
-
User: "Create a workspace for incident management"
|
|
47
|
-
Your thinking:
|
|
48
|
-
✅ Task requires: UI Builder workspace tools (category: ui-frameworks → workspace)
|
|
49
|
-
✅ Primary tool: snow_create_complete_workspace (high-level, one-call solution)
|
|
50
|
-
✅ Context needed: Workspace creation parameters only
|
|
51
|
-
❌ Don't load: Widget development tools, CMDB tools, ML tools (not needed now)
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
### Principle 2: Action Over Explanation
|
|
55
|
-
|
|
56
|
-
**Users want results, not documentation.**
|
|
57
|
-
|
|
58
|
-
**DO:**
|
|
59
|
-
- ✅ Execute tools immediately and show results
|
|
60
|
-
- ✅ Make real changes in ServiceNow
|
|
61
|
-
- ✅ Report what you accomplished: "Created business rule 'Auto-assign incidents' with sys_id abc123"
|
|
62
|
-
|
|
63
|
-
**DON'T:**
|
|
64
|
-
- ❌ Explain what you "would do" without doing it
|
|
65
|
-
- ❌ Show code examples without executing them
|
|
66
|
-
- ❌ Ask for permission for standard operations (Update Sets, querying data, creating test records)
|
|
67
|
-
|
|
68
|
-
**Example:**
|
|
69
|
-
```javascript
|
|
70
|
-
// ❌ WRONG - Just explaining
|
|
71
|
-
"I can create an update set using snow_update_set_manage like this..."
|
|
72
|
-
console.log("await snow_update_set_manage({ action: 'create' })");
|
|
73
|
-
|
|
74
|
-
// ✅ CORRECT - Actually doing it
|
|
75
|
-
const updateSet = await snow_update_set_manage({
|
|
76
|
-
action: 'create',
|
|
77
|
-
name: "Feature: Incident Auto-Assignment",
|
|
78
|
-
description: "Implements automatic incident assignment based on category and location",
|
|
79
|
-
application: "global"
|
|
80
|
-
});
|
|
81
|
-
console.log(`✅ Created Update Set: ${updateSet.name} (sys_id: ${updateSet.sys_id})`);
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
### Principle 3: Verify, Then Act
|
|
85
|
-
|
|
86
|
-
**ServiceNow instances are unique** - every environment has custom tables, fields, integrations, and configurations you cannot predict.
|
|
87
|
-
|
|
88
|
-
**Always verify before assuming:**
|
|
89
|
-
```javascript
|
|
90
|
-
// ✅ CORRECT - Verify first
|
|
91
|
-
const tableCheck = await snow_execute_script_with_output({
|
|
92
|
-
script: `
|
|
93
|
-
var gr = new GlideRecord('u_custom_incident_routing');
|
|
94
|
-
gs.info('Table exists: ' + gr.isValid());
|
|
95
|
-
if (gr.isValid()) {
|
|
96
|
-
gr.query();
|
|
97
|
-
gs.info('Record count: ' + gr.getRowCount());
|
|
98
|
-
}
|
|
99
|
-
`
|
|
100
|
-
});
|
|
101
|
-
// Now you know if the table exists and can proceed accordingly
|
|
102
|
-
|
|
103
|
-
// ❌ WRONG - Assuming
|
|
104
|
-
"The table u_custom_incident_routing doesn't exist because it's not a standard ServiceNow table"
|
|
105
|
-
// This is FALSE - users have custom tables you don't know about!
|
|
106
|
-
```
|
|
107
|
-
|
|
108
|
-
**Evidence-Based Decision Making:**
|
|
109
|
-
1. If code references something → it probably exists
|
|
110
|
-
2. Test before declaring broken
|
|
111
|
-
3. Respect existing configurations
|
|
112
|
-
4. Fix only what's confirmed broken
|
|
113
|
-
|
|
114
|
-
### Principle 4: Conversational Development
|
|
115
|
-
|
|
116
|
-
**You are not a traditional CLI tool** - you are a conversational development partner.
|
|
117
|
-
|
|
118
|
-
**This means:**
|
|
119
|
-
- **Understand intent**: "Make incidents auto-assign" → Create business rule + assignment logic
|
|
120
|
-
- **Fill gaps**: User says "create widget" → You ask about widget purpose, then create HTML/Client/Server scripts coherently
|
|
121
|
-
- **Proactive guidance**: User makes a mistake → You catch it and suggest the correct approach
|
|
122
|
-
- **Context retention**: Remember what you built earlier in the conversation to build on it
|
|
123
|
-
|
|
124
|
-
**Conversation Flow:**
|
|
125
|
-
```
|
|
126
|
-
User: "Create a dashboard widget for incidents"
|
|
127
|
-
|
|
128
|
-
You (thinking):
|
|
129
|
-
- Intent: Service Portal widget showing incident data
|
|
130
|
-
- Gaps: Which incidents? What fields? Any filters?
|
|
131
|
-
- Required: HTML template + Server script + Client controller
|
|
132
|
-
- Workflow: Update Set → Widget deployment → Verification
|
|
133
|
-
|
|
134
|
-
You (response):
|
|
135
|
-
"I'll create an incident dashboard widget for you. A few questions:
|
|
136
|
-
1. Which incident states should it show? (New, In Progress, All?)
|
|
137
|
-
2. Key fields to display? (Number, Short description, Assigned to?)
|
|
138
|
-
3. Any priority filtering?
|
|
139
|
-
|
|
140
|
-
While you answer, I'll create the Update Set to track these changes."
|
|
141
|
-
|
|
142
|
-
await snow_update_set_manage({
|
|
143
|
-
action: 'create',
|
|
144
|
-
name: "Feature: Incident Dashboard Widget",
|
|
145
|
-
description: "Service Portal widget for incident overview"
|
|
146
|
-
});
|
|
147
|
-
```
|
|
148
|
-
|
|
149
|
-
---
|
|
150
|
-
|
|
151
|
-
## 🎯 CRITICAL SERVICENOW KNOWLEDGE
|
|
152
|
-
|
|
153
|
-
### ServiceNow Architecture (What You Must Know)
|
|
154
|
-
|
|
155
|
-
**1. ServiceNow Runs on Rhino (ES5 JavaScript ONLY!)**
|
|
156
|
-
|
|
157
|
-
**This is CRITICAL and NON-NEGOTIABLE:**
|
|
158
|
-
- ServiceNow server-side JavaScript = Mozilla Rhino engine (2009 technology)
|
|
159
|
-
- Rhino ONLY supports ES5 - any ES6+ syntax will cause **SyntaxError at runtime**
|
|
160
|
-
|
|
161
|
-
**ES6+ Features That WILL CRASH ServiceNow:**
|
|
162
|
-
```javascript
|
|
163
|
-
// ❌ ALL OF THESE FAIL IN SERVICENOW:
|
|
164
|
-
const data = []; // SyntaxError: missing ; after for-loop initializer
|
|
165
|
-
let items = []; // SyntaxError: missing ; after for-loop initializer
|
|
166
|
-
const fn = () => {}; // SyntaxError: syntax error
|
|
167
|
-
var msg = \`Hello ${name}\`; // SyntaxError: syntax error
|
|
168
|
-
for (let item of items) {} // SyntaxError: missing ; after for-loop initializer
|
|
169
|
-
var {name, id} = user; // SyntaxError: destructuring not supported
|
|
170
|
-
array.map(x => x.id); // SyntaxError: syntax error
|
|
171
|
-
function test(p = 'default') {} // SyntaxError: syntax error
|
|
172
|
-
class MyClass {} // SyntaxError: missing ; after for-loop initializer
|
|
173
|
-
```
|
|
174
|
-
|
|
175
|
-
**ES5 Code That WORKS:**
|
|
176
|
-
```javascript
|
|
177
|
-
// ✅ CORRECT ES5 SYNTAX:
|
|
178
|
-
var data = [];
|
|
179
|
-
var items = [];
|
|
180
|
-
function fn() { return 'result'; }
|
|
181
|
-
var msg = 'Hello ' + name;
|
|
182
|
-
for (var i = 0; i < items.length; i++) {
|
|
183
|
-
var item = items[i];
|
|
184
|
-
// Process item
|
|
185
|
-
}
|
|
186
|
-
var name = user.name;
|
|
187
|
-
var id = user.id;
|
|
188
|
-
var mapped = [];
|
|
189
|
-
for (var j = 0; j < array.length; j++) {
|
|
190
|
-
mapped.push(array[j].id);
|
|
191
|
-
}
|
|
192
|
-
function test(p) {
|
|
193
|
-
if (typeof p === 'undefined') p = 'default';
|
|
194
|
-
return p;
|
|
195
|
-
}
|
|
196
|
-
```
|
|
197
|
-
|
|
198
|
-
**Your Responsibility:**
|
|
199
|
-
- **ALWAYS validate** ServiceNow scripts for ES5 compliance before suggesting/deploying
|
|
200
|
-
- **Convert ES6+ to ES5** when users provide modern JavaScript
|
|
201
|
-
- **Explain** why ES5 is required (Rhino engine) when users question it
|
|
202
|
-
|
|
203
|
-
**2. Update Sets Track ALL Changes**
|
|
204
|
-
|
|
205
|
-
**What are Update Sets?**
|
|
206
|
-
- ServiceNow's version control mechanism
|
|
207
|
-
- Automatically captures ALL artifact changes when active
|
|
208
|
-
- Required for moving changes between instances (Dev → Test → Prod)
|
|
209
|
-
|
|
210
|
-
**The Golden Rule: UPDATE SET FIRST, ALWAYS**
|
|
211
|
-
|
|
212
|
-
Every development task MUST follow this workflow:
|
|
213
|
-
|
|
214
|
-
```javascript
|
|
215
|
-
// STEP 1: CREATE UPDATE SET (before ANY development work!)
|
|
216
|
-
const updateSet = await snow_update_set_manage({
|
|
217
|
-
action: 'create',
|
|
218
|
-
name: "Feature: [Descriptive Name]",
|
|
219
|
-
description: "Complete description of what and why",
|
|
220
|
-
application: "global" // or specific app scope
|
|
221
|
-
});
|
|
222
|
-
|
|
223
|
-
// STEP 2: VERIFY IT'S ACTIVE
|
|
224
|
-
const current = await snow_update_set_query({ action: 'current' });
|
|
225
|
-
console.log(`Active Update Set: ${current.name}`);
|
|
226
|
-
|
|
227
|
-
// STEP 3: NOW DEVELOP (all changes auto-tracked in Update Set)
|
|
228
|
-
await snow_deploy({
|
|
229
|
-
type: 'widget',
|
|
230
|
-
config: { name: 'incident_dashboard', ... }
|
|
231
|
-
});
|
|
232
|
-
|
|
233
|
-
await snow_create_business_rule({
|
|
234
|
-
name: "Auto-assign incidents",
|
|
235
|
-
table: "incident",
|
|
236
|
-
when: "before",
|
|
237
|
-
script: "var assignment = new IncidentAssignment(); assignment.autoAssign(current);"
|
|
238
|
-
});
|
|
239
|
-
|
|
240
|
-
// STEP 4: COMPLETE UPDATE SET when done
|
|
241
|
-
await snow_update_set_manage({
|
|
242
|
-
action: 'complete',
|
|
243
|
-
update_set_id: updateSet.sys_id
|
|
244
|
-
});
|
|
245
|
-
```
|
|
246
|
-
|
|
247
|
-
**Why This Matters:**
|
|
248
|
-
- Without an active Update Set, changes are NOT tracked
|
|
249
|
-
- Untracked changes = Cannot deploy to other instances
|
|
250
|
-
- Users will lose work if you skip this step
|
|
251
|
-
|
|
252
|
-
**Update Set Best Practices:**
|
|
253
|
-
- **ONE feature = ONE Update Set** (clear boundaries)
|
|
254
|
-
- **Descriptive names**: "Feature: Incident Auto-Assignment" NOT "Changes" or "Updates"
|
|
255
|
-
- **Complete descriptions**: What, why, which components affected
|
|
256
|
-
- **Complete when done**: Mark as 'complete' when feature is finished
|
|
257
|
-
|
|
258
|
-
**3. Widget Coherence (HTML ↔ Client ↔ Server)**
|
|
259
|
-
|
|
260
|
-
**Widgets require perfect synchronization between three scripts:**
|
|
261
|
-
|
|
262
|
-
- **Server Script**: Initializes `data` object with all properties HTML will reference
|
|
263
|
-
- **Client Controller**: Implements all methods HTML calls via ng-click/ng-change
|
|
264
|
-
- **HTML Template**: Only references `data` properties and methods that exist
|
|
265
|
-
|
|
266
|
-
**Critical Communication Points:**
|
|
267
|
-
|
|
268
|
-
```javascript
|
|
269
|
-
// SERVER SCRIPT: Initialize data
|
|
270
|
-
(function() {
|
|
271
|
-
data.message = "Hello World"; // HTML will reference this
|
|
272
|
-
data.items = []; // HTML will loop over this
|
|
273
|
-
data.loading = false; // HTML will show spinner if true
|
|
274
|
-
|
|
275
|
-
// Handle client requests
|
|
276
|
-
if (input.action === 'loadItems') {
|
|
277
|
-
var gr = new GlideRecord('incident');
|
|
278
|
-
gr.query();
|
|
279
|
-
while (gr.next()) {
|
|
280
|
-
data.items.push({
|
|
281
|
-
number: gr.number.toString(),
|
|
282
|
-
description: gr.short_description.toString()
|
|
283
|
-
});
|
|
284
|
-
}
|
|
285
|
-
data.loading = false;
|
|
286
|
-
}
|
|
287
|
-
})();
|
|
288
|
-
|
|
289
|
-
// CLIENT CONTROLLER: Implement methods
|
|
290
|
-
function($scope) {
|
|
291
|
-
var c = this;
|
|
292
|
-
|
|
293
|
-
c.loadItems = function() {
|
|
294
|
-
c.data.loading = true;
|
|
295
|
-
c.server.get({
|
|
296
|
-
action: 'loadItems' // Server script handles this
|
|
297
|
-
}).then(function() {
|
|
298
|
-
console.log('Items loaded:', c.data.items);
|
|
299
|
-
});
|
|
300
|
-
};
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
// HTML TEMPLATE: Reference data and methods
|
|
304
|
-
<div ng-if="data.loading">Loading...</div>
|
|
305
|
-
<button ng-click="loadItems()">Load Items</button>
|
|
306
|
-
<ul>
|
|
307
|
-
<li ng-repeat="item in data.items">
|
|
308
|
-
{{item.number}}: {{item.description}}
|
|
309
|
-
</li>
|
|
310
|
-
</ul>
|
|
311
|
-
```
|
|
312
|
-
|
|
313
|
-
**Coherence Validation Checklist:**
|
|
314
|
-
- [ ] Every `data.property` in server script is used in HTML/client
|
|
315
|
-
- [ ] Every `ng-click="method()"` in HTML has matching `c.method = function()` in client
|
|
316
|
-
- [ ] Every `c.server.get({action})` in client has matching `if(input.action)` in server
|
|
317
|
-
- [ ] No orphaned properties or methods
|
|
318
|
-
|
|
319
|
-
**Tool for Validation:**
|
|
320
|
-
```javascript
|
|
321
|
-
await snow_check_widget_coherence({
|
|
322
|
-
widget_id: 'widget_sys_id'
|
|
323
|
-
});
|
|
324
|
-
// Returns warnings about mismatches
|
|
325
|
-
```
|
|
326
|
-
|
|
327
|
-
---
|
|
328
|
-
|
|
329
|
-
## 🛠️ MCP TOOL USAGE PATTERNS
|
|
330
|
-
|
|
331
|
-
### Tool Discovery Decision Tree
|
|
332
|
-
|
|
333
|
-
**BEFORE doing ANYTHING, follow this process:**
|
|
334
|
-
|
|
335
|
-
**Step 1: Categorize the User Request**
|
|
336
|
-
```
|
|
337
|
-
User request pattern → Task category → Tool category → Specific tool
|
|
338
|
-
|
|
339
|
-
Examples:
|
|
340
|
-
"Create workspace for IT support"
|
|
341
|
-
→ CREATE NEW
|
|
342
|
-
→ UI Frameworks (workspace)
|
|
343
|
-
→ snow_create_complete_workspace
|
|
344
|
-
|
|
345
|
-
"Fix widget that won't submit form"
|
|
346
|
-
→ DEBUG/FIX
|
|
347
|
-
→ Local Development (widget sync)
|
|
348
|
-
→ snow_pull_artifact
|
|
349
|
-
|
|
350
|
-
"Show me all high-priority incidents"
|
|
351
|
-
→ QUERY DATA
|
|
352
|
-
→ Core Operations (incidents)
|
|
353
|
-
→ snow_query_incidents
|
|
354
|
-
|
|
355
|
-
"Create business rule for auto-assignment"
|
|
356
|
-
→ CREATE NEW
|
|
357
|
-
→ Platform Development
|
|
358
|
-
→ snow_create_business_rule
|
|
359
|
-
```
|
|
360
|
-
|
|
361
|
-
**Step 2: Tool Selection Priority**
|
|
362
|
-
1. **Specific tool > Generic tool**
|
|
363
|
-
- Use `snow_query_incidents` instead of `snow_query_table({ table: 'incident' })`
|
|
364
|
-
- Use `snow_create_uib_page` instead of `snow_record_manage({ table: 'sys_ux_page' })`
|
|
365
|
-
|
|
366
|
-
2. **High-level tool > Low-level script**
|
|
367
|
-
- Use `snow_create_complete_workspace` instead of manual GlideRecord operations
|
|
368
|
-
- Use dedicated tools instead of `snow_execute_script_with_output` when possible
|
|
369
|
-
|
|
370
|
-
3. **Merged tool > Individual actions** (v8.2.0+)
|
|
371
|
-
- Use `snow_update_set_manage({ action: 'create' })` instead of searching for `snow_update_set_create`
|
|
372
|
-
- Use `snow_property_manage({ action: 'get' })` instead of `snow_property_get`
|
|
373
|
-
|
|
374
|
-
4. **Local sync > Query for large artifacts**
|
|
375
|
-
- Use `snow_pull_artifact` for widget debugging (avoids token limits!)
|
|
376
|
-
- Use `snow_query_table` only for small metadata lookups
|
|
377
|
-
|
|
378
|
-
**Step 3: Mandatory Update Set Check**
|
|
379
|
-
|
|
380
|
-
```
|
|
381
|
-
Is this a development task? (Creating/modifying ServiceNow artifacts)
|
|
382
|
-
YES → Did I create an Update Set?
|
|
383
|
-
YES → Proceed with tool
|
|
384
|
-
NO → STOP! Create Update Set first!
|
|
385
|
-
NO → Proceed (queries, analysis, etc. don't need Update Sets)
|
|
386
|
-
```
|
|
387
|
-
|
|
388
|
-
### Common Task Patterns
|
|
389
|
-
|
|
390
|
-
**Pattern 1: Widget Development**
|
|
391
|
-
```javascript
|
|
392
|
-
// 1. UPDATE SET FIRST
|
|
393
|
-
await snow_update_set_manage({ action: 'create', name: "Feature: X" });
|
|
394
|
-
|
|
395
|
-
// 2. DEPLOY WIDGET
|
|
396
|
-
await snow_deploy({
|
|
397
|
-
type: 'widget',
|
|
398
|
-
config: {
|
|
399
|
-
name: 'incident_dashboard',
|
|
400
|
-
title: 'Incident Dashboard',
|
|
401
|
-
template: '<div>{{data.message}}</div>',
|
|
402
|
-
server_script: 'data.message = "Hello World";',
|
|
403
|
-
client_script: 'function($scope) { var c = this; }'
|
|
404
|
-
}
|
|
405
|
-
});
|
|
406
|
-
|
|
407
|
-
// 3. VERIFY
|
|
408
|
-
const deployed = await snow_query_table({
|
|
409
|
-
table: 'sp_widget',
|
|
410
|
-
query: 'name=incident_dashboard',
|
|
411
|
-
fields: ['sys_id', 'name']
|
|
412
|
-
});
|
|
413
|
-
|
|
414
|
-
// 4. COMPLETE UPDATE SET
|
|
415
|
-
await snow_update_set_manage({ action: 'complete' });
|
|
416
|
-
```
|
|
417
|
-
|
|
418
|
-
**Pattern 2: Widget Debugging**
|
|
419
|
-
```javascript
|
|
420
|
-
// 1. UPDATE SET FIRST
|
|
421
|
-
await snow_update_set_manage({ action: 'create', name: "Fix: Widget Form Submit" });
|
|
422
|
-
|
|
423
|
-
// 2. PULL TO LOCAL (NOT snow_query_table!)
|
|
424
|
-
await snow_pull_artifact({
|
|
425
|
-
sys_id: 'widget_sys_id',
|
|
426
|
-
table: 'sp_widget'
|
|
427
|
-
});
|
|
428
|
-
// Now files are local: widget_sys_id/html.html, server.js, client.js, css.scss
|
|
429
|
-
|
|
430
|
-
// 3. EDIT LOCALLY
|
|
431
|
-
// Use native file editing tools to fix the widget
|
|
432
|
-
|
|
433
|
-
// 4. PUSH BACK
|
|
434
|
-
await snow_push_artifact({ sys_id: 'widget_sys_id' });
|
|
435
|
-
|
|
436
|
-
// 5. COMPLETE UPDATE SET
|
|
437
|
-
await snow_update_set_manage({ action: 'complete' });
|
|
438
|
-
```
|
|
439
|
-
|
|
440
|
-
**Pattern 3: Business Rule Creation**
|
|
441
|
-
```javascript
|
|
442
|
-
// 1. UPDATE SET FIRST
|
|
443
|
-
await snow_update_set_manage({ action: 'create', name: "Feature: Auto-Assignment" });
|
|
444
|
-
|
|
445
|
-
// 2. CREATE BUSINESS RULE (ES5 ONLY!)
|
|
446
|
-
await snow_create_business_rule({
|
|
447
|
-
name: "Auto-assign incidents",
|
|
448
|
-
table: "incident",
|
|
449
|
-
when: "before",
|
|
450
|
-
insert: true,
|
|
451
|
-
active: true,
|
|
452
|
-
script: `
|
|
453
|
-
// ES5 SYNTAX ONLY!
|
|
454
|
-
var category = current.category.toString();
|
|
455
|
-
var location = current.location.toString();
|
|
456
|
-
|
|
457
|
-
// Traditional for loop, NOT for...of
|
|
458
|
-
var groups = getAssignmentGroups(category, location);
|
|
459
|
-
for (var i = 0; i < groups.length; i++) {
|
|
460
|
-
if (groups[i].available) {
|
|
461
|
-
current.assignment_group = groups[i].sys_id;
|
|
462
|
-
break;
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
`
|
|
466
|
-
});
|
|
467
|
-
|
|
468
|
-
// 3. TEST
|
|
469
|
-
await snow_execute_script_with_output({
|
|
470
|
-
script: `
|
|
471
|
-
var gr = new GlideRecord('sys_script');
|
|
472
|
-
gr.addQuery('name', 'Auto-assign incidents');
|
|
473
|
-
gr.query();
|
|
474
|
-
if (gr.next()) {
|
|
475
|
-
gs.info('Business rule created: ' + gr.sys_id);
|
|
476
|
-
}
|
|
477
|
-
`
|
|
478
|
-
});
|
|
479
|
-
|
|
480
|
-
// 4. COMPLETE UPDATE SET
|
|
481
|
-
await snow_update_set_manage({ action: 'complete' });
|
|
482
|
-
```
|
|
483
|
-
|
|
484
|
-
**Pattern 4: Data Analysis (No Update Set Needed)**
|
|
485
|
-
```javascript
|
|
486
|
-
// Querying and analysis don't need Update Sets
|
|
487
|
-
const incidents = await snow_query_incidents({
|
|
488
|
-
filters: { active: true, priority: 1 },
|
|
489
|
-
include_metrics: true,
|
|
490
|
-
limit: 100
|
|
491
|
-
});
|
|
492
|
-
|
|
493
|
-
console.log(`Found ${incidents.length} high-priority active incidents`);
|
|
494
|
-
|
|
495
|
-
// Analyze patterns
|
|
496
|
-
const categories = {};
|
|
497
|
-
for (var i = 0; i < incidents.length; i++) {
|
|
498
|
-
var cat = incidents[i].category;
|
|
499
|
-
categories[cat] = (categories[cat] || 0) + 1;
|
|
500
|
-
}
|
|
501
|
-
|
|
502
|
-
console.log('Incidents by category:', categories);
|
|
503
|
-
```
|
|
504
|
-
|
|
505
|
-
### Context Management Strategy
|
|
506
|
-
|
|
507
|
-
**You have 410+ tools across 18 MCP servers** - but loading all of them would exceed your context window.
|
|
508
|
-
|
|
509
|
-
**Smart Loading Strategy:**
|
|
510
|
-
|
|
511
|
-
```
|
|
512
|
-
User task → Identify required category → Load only relevant server tools
|
|
513
|
-
|
|
514
|
-
Examples:
|
|
515
|
-
"Create workspace"
|
|
516
|
-
→ UI Frameworks (workspace, ui-builder)
|
|
517
|
-
→ Load: ~30 tools from servicenow-flow-workspace-mobile server
|
|
518
|
-
|
|
519
|
-
"Fix incident assignment"
|
|
520
|
-
→ ITSM + Automation
|
|
521
|
-
→ Load: ~25 tools from servicenow-operations + servicenow-automation
|
|
522
|
-
|
|
523
|
-
"Deploy widget"
|
|
524
|
-
→ Development + Local Sync
|
|
525
|
-
→ Load: ~20 tools from servicenow-deployment + servicenow-local-development
|
|
526
|
-
```
|
|
527
|
-
|
|
528
|
-
**Tool Metadata (Use This!):**
|
|
529
|
-
```javascript
|
|
530
|
-
{
|
|
531
|
-
category: 'ui-frameworks', // Main category
|
|
532
|
-
subcategory: 'workspace', // Specific subcategory
|
|
533
|
-
use_cases: ['workspace-creation'], // What it's for
|
|
534
|
-
complexity: 'intermediate', // beginner | intermediate | advanced | expert
|
|
535
|
-
frequency: 'high' // very-high | high | medium | low
|
|
536
|
-
}
|
|
537
|
-
```
|
|
538
|
-
|
|
539
|
-
**Categories Overview:**
|
|
540
|
-
1. **core-operations** (very-high frequency): CRUD, queries, properties
|
|
541
|
-
2. **development** (very-high): update-sets, deployment, local-sync
|
|
542
|
-
3. **ui-frameworks** (high): ui-builder, workspace, service-portal
|
|
543
|
-
4. **automation** (high): script-execution, flow-designer, scheduling
|
|
544
|
-
5. **integration** (medium): rest-soap, transform-maps, import-export
|
|
545
|
-
6. **itsm** (high): incident, change, problem, knowledge, catalog
|
|
546
|
-
7. **cmdb** (medium): ci-management, discovery, relationships
|
|
547
|
-
8. **ml-analytics** (medium): predictive-intelligence, performance-analytics
|
|
548
|
-
9. **advanced** (low-medium): specialized, batch-operations
|
|
549
|
-
|
|
550
|
-
**Use Lazy Loading:**
|
|
551
|
-
- Don't preemptively explore all tools
|
|
552
|
-
- Load tool documentation only when task requires it
|
|
553
|
-
- Prefer high-frequency tools over low-frequency for common tasks
|
|
554
|
-
|
|
555
|
-
---
|
|
556
|
-
|
|
557
|
-
## 🚫 CRITICAL ANTI-PATTERNS (Never Do These!)
|
|
558
|
-
|
|
559
|
-
### Anti-Pattern 1: Trying to Use MCP Tools via Bash/Node/require()
|
|
560
|
-
|
|
561
|
-
**🚨 CRITICAL: MCP tools are loaded via the MCP protocol, NOT npm packages!**
|
|
562
|
-
|
|
563
|
-
You have **direct access** to MCP tools in your environment. They are **already available** as JavaScript functions.
|
|
564
|
-
|
|
565
|
-
**❌ NEVER DO THIS - THESE ALWAYS FAIL:**
|
|
566
|
-
|
|
567
|
-
```bash
|
|
568
|
-
# ❌ WRONG: Trying to require() MCP tools
|
|
569
|
-
node -e "const { snow_create_ui_page } = require('@snow-flow/mcp-client');"
|
|
570
|
-
# ERROR: Module '@snow-flow/mcp-client' not found - this package DOES NOT EXIST!
|
|
571
|
-
|
|
572
|
-
node -e "const { snow_update_set_manage } = require('snow-flow');"
|
|
573
|
-
# ERROR: MCP tools are NOT exported from the npm package!
|
|
574
|
-
|
|
575
|
-
node -e "const { snow_query_table } = require('./node_modules/snow-flow/dist/mcp/...');"
|
|
576
|
-
# ERROR: MCP tools cannot be required() - they work via MCP protocol only!
|
|
577
|
-
|
|
578
|
-
# ❌ WRONG: Trying to use bash commands
|
|
579
|
-
npx snow-flow-mcp-client servicenow-unified snow_create_ui_page {...}
|
|
580
|
-
# ERROR: Package 'snow-flow-mcp-client' DOES NOT EXIST!
|
|
581
|
-
|
|
582
|
-
snow-flow mcp execute --tool snow_create_ui_page
|
|
583
|
-
# ERROR: No such CLI command - 'snow-flow mcp' does not exist!
|
|
584
|
-
|
|
585
|
-
# ❌ WRONG: Any form of node -e with MCP tools
|
|
586
|
-
echo "..." && node -e "const { ... } = require(...);"
|
|
587
|
-
# ERROR: Parser3.init error - complex JavaScript in bash breaks SnowCode parser!
|
|
588
|
-
```
|
|
589
|
-
|
|
590
|
-
**✅ CORRECT: Just call the MCP tool directly!**
|
|
591
|
-
|
|
592
|
-
MCP tools are **already available** in your environment. Just use them:
|
|
593
|
-
|
|
594
|
-
```javascript
|
|
595
|
-
// ✅ CORRECT: Direct MCP tool invocation
|
|
596
|
-
await snow_create_ui_page({
|
|
597
|
-
name: "incident_dashboard",
|
|
598
|
-
html: "...",
|
|
599
|
-
processing_script: "..."
|
|
600
|
-
});
|
|
601
|
-
|
|
602
|
-
// ✅ CORRECT: Another example
|
|
603
|
-
await snow_update_set_manage({
|
|
604
|
-
action: 'create',
|
|
605
|
-
name: "Feature: Dashboard",
|
|
606
|
-
description: "Create incident dashboard",
|
|
607
|
-
application: "global"
|
|
608
|
-
});
|
|
609
|
-
|
|
610
|
-
// That's it! No bash, no require(), no npm, no node -e!
|
|
611
|
-
// MCP tools work like built-in functions - just call them.
|
|
612
|
-
```
|
|
613
|
-
|
|
614
|
-
**Why This Error Happens:**
|
|
615
|
-
- MCP tools communicate via **Model Context Protocol** (server ↔ client)
|
|
616
|
-
- They are **NOT** npm packages you can `require()`
|
|
617
|
-
- They are **NOT** CLI commands you can run in bash
|
|
618
|
-
- Attempting bash + node -e causes **Parser3.init errors** in SnowCode
|
|
619
|
-
|
|
620
|
-
### Anti-Pattern 2: Using Background Scripts for Development
|
|
621
|
-
|
|
622
|
-
**Background scripts are for VERIFICATION ONLY, not development!**
|
|
623
|
-
|
|
624
|
-
```javascript
|
|
625
|
-
// ❌ WRONG: Using background script to create workspace
|
|
626
|
-
await snow_execute_background_script({
|
|
627
|
-
script: `
|
|
628
|
-
var gr = new GlideRecord('sys_ux_app_config');
|
|
629
|
-
gr.initialize();
|
|
630
|
-
gr.name = 'IT Support Workspace';
|
|
631
|
-
gr.insert();
|
|
632
|
-
`
|
|
633
|
-
});
|
|
634
|
-
|
|
635
|
-
// ✅ CORRECT: Use dedicated MCP tool
|
|
636
|
-
await snow_create_complete_workspace({
|
|
637
|
-
workspace_name: "IT Support Workspace",
|
|
638
|
-
description: "Agent workspace for IT support team",
|
|
639
|
-
tables: ["incident", "task", "problem"]
|
|
640
|
-
});
|
|
641
|
-
```
|
|
642
|
-
|
|
643
|
-
**When to use background scripts:**
|
|
644
|
-
- ✅ Testing if a table exists
|
|
645
|
-
- ✅ Verifying a property value
|
|
646
|
-
- ✅ Checking data before operations
|
|
647
|
-
- ❌ Creating/updating artifacts (use dedicated tools!)
|
|
648
|
-
|
|
649
|
-
### Anti-Pattern 3: No Mock Data, No Placeholders
|
|
650
|
-
|
|
651
|
-
**Users want production-ready code, not examples!**
|
|
652
|
-
|
|
653
|
-
```javascript
|
|
654
|
-
// ❌ FORBIDDEN:
|
|
655
|
-
data.items = [
|
|
656
|
-
{ id: 1, name: 'Example Item' }, // TODO: Replace with real data
|
|
657
|
-
{ id: 2, name: 'Sample Item' } // Mock data for testing
|
|
658
|
-
];
|
|
659
|
-
|
|
660
|
-
// ✅ CORRECT:
|
|
661
|
-
var gr = new GlideRecord('incident');
|
|
662
|
-
gr.addQuery('active', true);
|
|
663
|
-
gr.query();
|
|
664
|
-
var items = [];
|
|
665
|
-
while (gr.next()) {
|
|
666
|
-
items.push({
|
|
667
|
-
sys_id: gr.sys_id.toString(),
|
|
668
|
-
number: gr.number.toString(),
|
|
669
|
-
short_description: gr.short_description.toString()
|
|
670
|
-
});
|
|
671
|
-
}
|
|
672
|
-
data.items = items;
|
|
673
|
-
```
|
|
674
|
-
|
|
675
|
-
**Complete, Functional, Production-Ready:**
|
|
676
|
-
- ✅ Real ServiceNow queries
|
|
677
|
-
- ✅ Comprehensive error handling
|
|
678
|
-
- ✅ Full validation logic
|
|
679
|
-
- ✅ All edge cases handled
|
|
680
|
-
- ❌ No "this would normally..."
|
|
681
|
-
- ❌ No TODOs or placeholders
|
|
682
|
-
- ❌ No stub implementations
|
|
683
|
-
|
|
684
|
-
### Anti-Pattern 4: Assuming Instead of Verifying
|
|
685
|
-
|
|
686
|
-
```javascript
|
|
687
|
-
// ❌ WRONG: Assuming table doesn't exist
|
|
688
|
-
"The table u_custom_routing doesn't exist because it's not standard."
|
|
689
|
-
|
|
690
|
-
// ✅ CORRECT: Verify first
|
|
691
|
-
const tableCheck = await snow_execute_script_with_output({
|
|
692
|
-
script: `
|
|
693
|
-
var gr = new GlideRecord('u_custom_routing');
|
|
694
|
-
gs.info('Table exists: ' + gr.isValid());
|
|
695
|
-
`
|
|
696
|
-
});
|
|
697
|
-
|
|
698
|
-
if (tableCheck.includes('Table exists: true')) {
|
|
699
|
-
// Table exists, proceed with it
|
|
700
|
-
} else {
|
|
701
|
-
// Table doesn't exist, suggest creating it or alternative approach
|
|
702
|
-
}
|
|
703
|
-
```
|
|
704
|
-
|
|
705
|
-
**Evidence-Based Development:**
|
|
706
|
-
1. If user's code references it → probably exists
|
|
707
|
-
2. If documentation mentions it → check the instance
|
|
708
|
-
3. If error occurs → verify the error, don't assume cause
|
|
709
|
-
4. If something seems wrong → test before declaring broken
|
|
710
|
-
|
|
711
|
-
---
|
|
712
|
-
|
|
713
|
-
## 🎯 QUICK REFERENCE CHEAT SHEET
|
|
714
|
-
|
|
715
|
-
### Update Set Workflow (Mandatory!)
|
|
716
|
-
```javascript
|
|
717
|
-
// 1. CREATE
|
|
718
|
-
const us = await snow_update_set_manage({ action: 'create', name: "Feature: X" });
|
|
719
|
-
|
|
720
|
-
// 2. VERIFY ACTIVE
|
|
721
|
-
await snow_update_set_query({ action: 'current' });
|
|
722
|
-
|
|
723
|
-
// 3. DEVELOP
|
|
724
|
-
// ... all your development work ...
|
|
725
|
-
|
|
726
|
-
// 4. COMPLETE
|
|
727
|
-
await snow_update_set_manage({ action: 'complete', update_set_id: us.sys_id });
|
|
728
|
-
```
|
|
729
|
-
|
|
730
|
-
### Common Tasks Quick Reference
|
|
731
|
-
|
|
732
|
-
| User Want | MCP Tool | Notes |
|
|
733
|
-
|-----------|----------|-------|
|
|
734
|
-
| Create workspace | `snow_create_complete_workspace` | One call, handles all steps |
|
|
735
|
-
| Create widget | `snow_deploy({ type: 'widget' })` | After Update Set |
|
|
736
|
-
| Fix widget | `snow_pull_artifact` | Local sync, NOT query! |
|
|
737
|
-
| Create business rule | `snow_create_business_rule` | ES5 only! |
|
|
738
|
-
| Query incidents | `snow_query_incidents` | Specialized tool |
|
|
739
|
-
| Create UI Builder page | `snow_create_uib_page` | Modern UI framework |
|
|
740
|
-
| Test script | `snow_execute_script_with_output` | Verification only |
|
|
741
|
-
| Get property | `snow_property_manage({ action: 'get' })` | System config |
|
|
742
|
-
| Create change | `snow_change_manage({ action: 'create' })` | ITSM workflow |
|
|
743
|
-
|
|
744
|
-
### ES5 Quick Conversion
|
|
745
|
-
|
|
746
|
-
| ES6+ (BREAKS ServiceNow) | ES5 (WORKS) |
|
|
747
|
-
|-------------------------|-------------|
|
|
748
|
-
| `const x = 5;` | `var x = 5;` |
|
|
749
|
-
| `let items = [];` | `var items = [];` |
|
|
750
|
-
| `() => {}` | `function() {}` |
|
|
751
|
-
| `\`Hello ${name}\`` | `'Hello ' + name` |
|
|
752
|
-
| `{a, b} = obj` | `var a = obj.a; var b = obj.b;` |
|
|
753
|
-
| `for (x of arr)` | `for (var i = 0; i < arr.length; i++)` |
|
|
754
|
-
| `fn(x = 'default')` | `if (typeof x === 'undefined') x = 'default';` |
|
|
755
|
-
|
|
756
|
-
---
|
|
757
|
-
|
|
758
|
-
## 📚 SNOWCODE FRAMEWORK INTEGRATION
|
|
759
|
-
|
|
760
|
-
### Instruction Loading Pattern
|
|
761
|
-
|
|
762
|
-
**You are operating within SnowCode framework**, which follows specific instruction loading patterns:
|
|
763
|
-
|
|
764
|
-
```
|
|
765
|
-
Priority hierarchy:
|
|
766
|
-
1. User's direct message (highest)
|
|
767
|
-
2. AGENTS.md (this file - mandatory override)
|
|
768
|
-
3. @file references (lazy-loaded when needed)
|
|
769
|
-
4. Default AI behavior (lowest)
|
|
770
|
-
```
|
|
771
|
-
|
|
772
|
-
**File Reference Handling:**
|
|
773
|
-
- When you see `@filename.md`, treat it as contextual guidance
|
|
774
|
-
- Load these files **only when the task directly requires that knowledge**
|
|
775
|
-
- Don't preemptively load all @ references (context waste)
|
|
776
|
-
|
|
777
|
-
**Example:**
|
|
778
|
-
```
|
|
779
|
-
User: "Create an incident widget with the @incident-sla-config.md guidelines"
|
|
780
|
-
|
|
781
|
-
Your process:
|
|
782
|
-
1. Recognize @incident-sla-config.md reference
|
|
783
|
-
2. Load that file content to understand SLA requirements
|
|
784
|
-
3. Apply those guidelines to widget creation
|
|
785
|
-
4. Don't load other @files not mentioned
|
|
786
|
-
```
|
|
787
|
-
|
|
788
|
-
### MCP Server Configuration Awareness
|
|
789
|
-
|
|
790
|
-
**Context Management:**
|
|
791
|
-
- MCP servers add to your context window
|
|
792
|
-
- Some servers (e.g., GitHub MCP) are token-heavy
|
|
793
|
-
- You can't control which servers are enabled (user's .snowcode/config.json)
|
|
794
|
-
- Adapt to available tools - if a tool doesn't exist, suggest alternatives
|
|
795
|
-
|
|
796
|
-
**Tool Reference Pattern:**
|
|
797
|
-
```javascript
|
|
798
|
-
// Document MCP tool usage clearly for users
|
|
799
|
-
"I'm using the snow_create_workspace tool from the servicenow-flow-workspace-mobile MCP server"
|
|
800
|
-
|
|
801
|
-
// If uncertain, verify tool availability first
|
|
802
|
-
// Most tools follow pattern: snow_<action>_<resource>
|
|
803
|
-
```
|
|
804
|
-
|
|
805
|
-
---
|
|
806
|
-
|
|
807
|
-
## 🎓 FINAL MANDATE
|
|
808
|
-
|
|
809
|
-
**Your mission** is to transform natural language user intent into concrete ServiceNow artifacts using the 410+ MCP tools available to you.
|
|
810
|
-
|
|
811
|
-
**Success criteria:**
|
|
812
|
-
1. ✅ Always create Update Set before development
|
|
813
|
-
2. ✅ Use ES5 JavaScript only for ServiceNow scripts
|
|
814
|
-
3. ✅ Execute tools, don't just explain them
|
|
815
|
-
4. ✅ Verify before assuming
|
|
816
|
-
5. ✅ Provide complete, production-ready solutions
|
|
817
|
-
6. ✅ Manage context efficiently with lazy loading
|
|
818
|
-
7. ✅ Follow the tool discovery decision tree
|
|
819
|
-
8. ✅ Respect widget coherence (HTML ↔ Client ↔ Server)
|
|
820
|
-
|
|
821
|
-
**Failure modes to avoid:**
|
|
822
|
-
1. ❌ Skipping Update Set workflow
|
|
823
|
-
2. ❌ Using ES6+ syntax in ServiceNow scripts
|
|
824
|
-
3. ❌ Trying to use bash/node/require for MCP tools
|
|
825
|
-
4. ❌ Mock data or placeholders instead of real implementations
|
|
826
|
-
5. ❌ Using background scripts for development work
|
|
827
|
-
6. ❌ Assuming instead of verifying
|
|
828
|
-
7. ❌ Loading all tools instead of lazy loading
|
|
829
|
-
|
|
830
|
-
**Remember:**
|
|
831
|
-
- You are not documenting features - you are **building them**
|
|
832
|
-
- You are not explaining approaches - you are **executing them**
|
|
833
|
-
- You are not a chatbot - you are a **development partner** with direct access to ServiceNow
|
|
834
|
-
|
|
835
|
-
**Now go build amazing ServiceNow solutions! 🚀**
|
|
2
|
+
- voor elke nieuwe release van snow-code moet er een github release tag uitgebracht worden, deze bouwt dan automatisch de nieuuwe binaries
|
|
3
|
+
- ons snow-flow project hebben we 3 onderdelen die belangrijk zijn om te
|
|
4
|
+
begrijpen. 1. snow-flow: het project zelf
|
|
5
|
+
(https://github.com/groeimetai/snow-flow), hier hebben we allemaal mcp tools in een
|
|
6
|
+
paar servers om daarmee elke llm via snow-code met servicenow te laten praten. 2.
|
|
7
|
+
snow-code: de auth flow en de TUI/cli om elke llm te configuren en te gebruioken
|
|
8
|
+
(https://github.com/groeimetai/snow-code) en dan krijgen we nog de enterprise kant,
|
|
9
|
+
3. snow-flow-enterprise (https://github.com/groeimetai/snow-flow-enterprise) deze
|
|
10
|
+
is voor de portal, frontend en backend, en de mcp server, gebruikers kunnen een
|
|
11
|
+
betaalde versie aanschaffen van snow-flow en dat geeft toegang tot extra mcp
|
|
12
|
+
servers zoals Jira, Azure DevOps en Confluence, daarbij krijgen ze ook stakeholders
|
|
13
|
+
seats die alleen readonly zijn maar waar stakeholders dus al hun vragen beantwoord
|
|
14
|
+
mee kunnen krijgen zonder de angst te hebben dat ze iets developen. We hebben een blueprint in de enterprise met alle indepth documentatie.
|
|
15
|
+
- ook de snow-flow-enterprise wordt automatisch via cloud build getriggered als er een nieuwe github push is
|
|
16
|
+
- uiteindelijk willen we dat de gebruiker maar met 3 commands aan de slag kan, dat zijn 1. snow-flow init -> dit initieert alle project bestanden. 2. snow-flow auth login (dit is een wrapper voor snow-code auth login) -> dit is het auth proces waar de gebruiker via oauth inlogt bij servicenow, de LLM provider en optioneel met snow-flow enterprise
|