snow-flow 3.4.36 → 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 +414 -287
- package/dist/cli/deploy-artifact.js +2 -2
- package/dist/index.d.ts +4 -0
- package/dist/index.js +10 -2
- package/dist/mcp/enhancements/smart-query-enhancement.d.ts +49 -0
- package/dist/mcp/enhancements/smart-query-enhancement.js +233 -0
- package/dist/mcp/servicenow-deployment-mcp.js +1 -1
- package/dist/mcp/servicenow-local-development-mcp.d.ts +48 -0
- package/dist/mcp/servicenow-local-development-mcp.js +570 -0
- package/dist/mcp/servicenow-mcp-server.js +2 -2
- package/dist/queen/agent-factory.js +134 -52
- package/dist/queen/queen-knowledge-base.d.ts +151 -0
- package/dist/queen/queen-knowledge-base.js +283 -0
- package/dist/queen/servicenow-queen.d.ts +129 -2
- package/dist/queen/servicenow-queen.js +1069 -618
- package/dist/services/widget-deployment-service.d.ts +1 -1
- package/dist/services/widget-deployment-service.js +1 -1
- package/dist/templates/claude-md-template.d.ts +1 -1
- package/dist/templates/claude-md-template.js +2 -2
- package/dist/types/servicenow.types.d.ts +1 -1
- package/dist/utils/artifact-local-sync.d.ts +115 -0
- package/dist/utils/artifact-local-sync.js +705 -0
- package/dist/utils/artifact-sync/artifact-registry.d.ts +66 -0
- package/dist/utils/artifact-sync/artifact-registry.js +450 -0
- package/dist/utils/artifact-sync/index.d.ts +33 -0
- package/dist/utils/artifact-sync/index.js +52 -0
- package/dist/utils/dependency-detector.d.ts +1 -1
- package/dist/utils/dependency-detector.js +1 -1
- package/dist/utils/mcp-tool-registry.js +109 -0
- package/dist/utils/servicenow-client.d.ts +1 -1
- package/dist/utils/servicenow-client.js +4 -8
- package/dist/utils/smart-field-fetcher.d.ts +68 -0
- package/dist/utils/smart-field-fetcher.js +395 -0
- package/package.json +2 -2
- package/website/.dockerignore +64 -0
- package/website/Dockerfile +36 -0
- package/website/README.md +40 -1
- package/website/cloudbuild.yaml +69 -0
- package/website/components/README.md +419 -0
- package/website/components/code-display/CodeDisplay.css +583 -0
- package/website/components/code-display/CodeDisplay.html +200 -0
- package/website/components/code-display/CodeDisplay.js +375 -0
- package/website/components/code-display/CodeDisplay.jsx +268 -0
- package/website/components/demo/ComponentLibraryDemo.html +845 -0
- package/website/components/feature-cards/FeatureCards.css +573 -0
- package/website/components/feature-cards/FeatureCards.html +247 -0
- package/website/components/feature-cards/FeatureCards.js +382 -0
- package/website/components/feature-cards/FeatureCards.jsx +235 -0
- package/website/components/hero/Hero.css +558 -0
- package/website/components/hero/Hero.html +98 -0
- package/website/components/hero/Hero.js +415 -0
- package/website/components/hero/Hero.jsx +214 -0
- package/website/components/interactive/InteractiveElements.css +776 -0
- package/website/components/interactive/InteractiveElements.html +283 -0
- package/website/components/interactive/InteractiveElements.js +489 -0
- package/website/components/interactive/InteractiveElements.jsx +444 -0
- package/website/components/layout/LayoutComponents.css +697 -0
- package/website/components/layout/LayoutComponents.html +374 -0
- package/website/components/layout/LayoutComponents.js +447 -0
- package/website/components/layout/LayoutComponents.jsx +379 -0
- package/website/components/navigation/Navigation.css +383 -0
- package/website/components/navigation/Navigation.html +89 -0
- package/website/components/navigation/Navigation.js +248 -0
- package/website/components/navigation/Navigation.jsx +124 -0
- package/website/css/animations.css +854 -0
- package/website/css/style.css +1010 -924
- package/website/index.html +728 -412
- package/website/js/animations.js +707 -0
- package/website/js/main.js +333 -381
- package/website/mcp-servers.html +310 -0
- package/website/nginx.conf +116 -0
- package/website/service.yaml +61 -0
|
@@ -3,16 +3,51 @@
|
|
|
3
3
|
* ServiceNow Queen Agent
|
|
4
4
|
* Central coordination point for the ServiceNow hive-mind
|
|
5
5
|
*/
|
|
6
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
7
|
+
if (k2 === undefined) k2 = k;
|
|
8
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
9
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
10
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
11
|
+
}
|
|
12
|
+
Object.defineProperty(o, k2, desc);
|
|
13
|
+
}) : (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
o[k2] = m[k];
|
|
16
|
+
}));
|
|
17
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
18
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
19
|
+
}) : function(o, v) {
|
|
20
|
+
o["default"] = v;
|
|
21
|
+
});
|
|
22
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
23
|
+
var ownKeys = function(o) {
|
|
24
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
25
|
+
var ar = [];
|
|
26
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
27
|
+
return ar;
|
|
28
|
+
};
|
|
29
|
+
return ownKeys(o);
|
|
30
|
+
};
|
|
31
|
+
return function (mod) {
|
|
32
|
+
if (mod && mod.__esModule) return mod;
|
|
33
|
+
var result = {};
|
|
34
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
35
|
+
__setModuleDefault(result, mod);
|
|
36
|
+
return result;
|
|
37
|
+
};
|
|
38
|
+
})();
|
|
6
39
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
40
|
exports.ServiceNowQueen = void 0;
|
|
8
41
|
const queen_memory_1 = require("./queen-memory");
|
|
9
42
|
const neural_learning_1 = require("./neural-learning");
|
|
10
43
|
const agent_factory_1 = require("./agent-factory");
|
|
11
44
|
const mcp_execution_bridge_1 = require("./mcp-execution-bridge");
|
|
45
|
+
const queen_knowledge_base_1 = require("./queen-knowledge-base");
|
|
12
46
|
const theme_manager_1 = require("../utils/theme-manager");
|
|
13
47
|
const dependency_detector_1 = require("../utils/dependency-detector");
|
|
14
48
|
// Gap Analysis Engine removed - using direct MCP approach
|
|
15
49
|
const logger_1 = require("../utils/logger");
|
|
50
|
+
const crypto = __importStar(require("crypto"));
|
|
16
51
|
class ServiceNowQueen {
|
|
17
52
|
constructor(config = {}) {
|
|
18
53
|
this.config = {
|
|
@@ -38,12 +73,38 @@ class ServiceNowQueen {
|
|
|
38
73
|
}
|
|
39
74
|
}
|
|
40
75
|
/**
|
|
41
|
-
* Main entry point: Execute ServiceNow objective with
|
|
76
|
+
* Main entry point: Execute ServiceNow objective with STRATEGIC ORCHESTRATION
|
|
77
|
+
*
|
|
78
|
+
* This is where the Queen Agent demonstrates true helicopter-view thinking:
|
|
79
|
+
* - Deep problem analysis beyond surface requirements
|
|
80
|
+
* - Strategic risk assessment and mitigation planning
|
|
81
|
+
* - Holistic solution architecture considering all stakeholders
|
|
82
|
+
* - Proactive bottleneck identification and resolution
|
|
83
|
+
* - Comprehensive orchestration of specialized agents
|
|
42
84
|
*/
|
|
43
85
|
async executeObjective(objective) {
|
|
44
86
|
const taskId = this.generateTaskId();
|
|
45
87
|
const startTime = Date.now();
|
|
46
88
|
try {
|
|
89
|
+
// 🧠 STRATEGIC PHASE 1: DEEP PROBLEM ANALYSIS
|
|
90
|
+
this.logger.info(`👑 QUEEN STRATEGIC ANALYSIS INITIATED`);
|
|
91
|
+
this.logger.info(`🎯 Objective: ${objective}`);
|
|
92
|
+
this.logger.info(`🧠 Analyzing: What is the REAL problem we're solving here?`);
|
|
93
|
+
// Analyze what the user ACTUALLY needs vs what they asked for
|
|
94
|
+
const problemAnalysis = await this.performDeepProblemAnalysis(objective);
|
|
95
|
+
this.logger.info(`📊 Problem Complexity: ${problemAnalysis.complexity} | Business Impact: ${problemAnalysis.businessImpact}`);
|
|
96
|
+
this.logger.info(`🎯 Core Problem: ${problemAnalysis.coreProblem}`);
|
|
97
|
+
this.logger.info(`👥 Stakeholders: ${problemAnalysis.stakeholders.join(', ')}`);
|
|
98
|
+
// 🧠 STRATEGIC PHASE 2: RISK & CONSTRAINT ASSESSMENT
|
|
99
|
+
this.logger.info(`🔍 STRATEGIC RISK ASSESSMENT`);
|
|
100
|
+
const riskAssessment = await this.performRiskAssessment(objective, problemAnalysis);
|
|
101
|
+
this.logger.info(`⚠️ Risk Level: ${riskAssessment.overallRisk} | Critical Risks: ${riskAssessment.criticalRisks.length}`);
|
|
102
|
+
if (riskAssessment.criticalRisks.length > 0) {
|
|
103
|
+
this.logger.info(`🚨 CRITICAL RISKS IDENTIFIED:`);
|
|
104
|
+
riskAssessment.criticalRisks.forEach(risk => {
|
|
105
|
+
this.logger.info(` • ${risk.description} (Impact: ${risk.impact}, Likelihood: ${risk.likelihood})`);
|
|
106
|
+
});
|
|
107
|
+
}
|
|
47
108
|
if (this.config.debugMode) {
|
|
48
109
|
this.logger.info(`🎯 Queen analyzing objective: ${objective}`);
|
|
49
110
|
this.logger.info(`🚨 ENFORCING MCP-FIRST WORKFLOW`);
|
|
@@ -107,279 +168,255 @@ class ServiceNowQueen {
|
|
|
107
168
|
status: 'analyzing'
|
|
108
169
|
};
|
|
109
170
|
this.activeTasks.set(taskId, task);
|
|
110
|
-
//
|
|
111
|
-
this.logger.info(
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
;
|
|
127
|
-
this.
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
this.
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
if (
|
|
134
|
-
this.logger.info(
|
|
135
|
-
gapAnalysisResult.nextSteps.manual.forEach(step => this.logger.info(` • ${step}`));
|
|
136
|
-
if (gapAnalysisResult.manualGuides) {
|
|
137
|
-
this.logger.info('\n📚 Detailed manual guides available in gap _analysis result');
|
|
138
|
-
}
|
|
171
|
+
// 🧠 PHASE 5: STRATEGIC SOLUTION ARCHITECTURE
|
|
172
|
+
this.logger.info(`🧠 Strategic Solution Architecture based on analysis...`);
|
|
173
|
+
this.logger.info(`🎯 Mitigation Strategies: ${riskAssessment.mitigationStrategies.join(', ')}`);
|
|
174
|
+
// Strategic solution design based on deep analysis
|
|
175
|
+
const solutionArchitecture = await this.designSolutionArchitecture(problemAnalysis, riskAssessment);
|
|
176
|
+
this.logger.info(`🏗️ Solution Architecture: ${solutionArchitecture.approach}`);
|
|
177
|
+
this.logger.info(`👥 Recommended Team: ${solutionArchitecture.recommendedAgents.join(', ')}`);
|
|
178
|
+
// Store strategic analysis in task
|
|
179
|
+
task.strategicAnalysis = {
|
|
180
|
+
problemAnalysis,
|
|
181
|
+
riskAssessment,
|
|
182
|
+
solutionArchitecture
|
|
183
|
+
};
|
|
184
|
+
// Phase 6: Spawn optimal agent swarm
|
|
185
|
+
const agents = this.spawnOptimalSwarm(task, _analysis);
|
|
186
|
+
// Phase 7: Execute coordinated deployment
|
|
187
|
+
task.status = 'executing';
|
|
188
|
+
const result = await this.coordinateExecution(task, agents, _analysis);
|
|
189
|
+
// Phase 8: Learn from execution
|
|
190
|
+
const duration = Date.now() - startTime;
|
|
191
|
+
this.learnFromExecution(task, agents, result, duration, null);
|
|
192
|
+
task.status = 'completed';
|
|
193
|
+
task.result = result;
|
|
194
|
+
if (this.config.debugMode) {
|
|
195
|
+
this.logger.info(`✅ Queen completed objective in ${duration}ms`);
|
|
139
196
|
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
197
|
+
return result;
|
|
198
|
+
}
|
|
199
|
+
catch (error) {
|
|
200
|
+
const duration = Date.now() - startTime;
|
|
201
|
+
await this.handleExecutionFailure(taskId, objective, error, duration);
|
|
202
|
+
throw error;
|
|
203
|
+
}
|
|
204
|
+
finally {
|
|
205
|
+
this.cleanupTask(taskId);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
spawnOptimalSwarm(task, _analysis) {
|
|
209
|
+
if (this.config.debugMode) {
|
|
210
|
+
this.logger.info(`🐛 Spawning swarm for ${task.type} task (complexity: ${_analysis.estimatedComplexity})`);
|
|
211
|
+
}
|
|
212
|
+
// Use learned patterns or optimal sequence
|
|
213
|
+
const agentTypes = _analysis.suggestedPattern?.agentSequence ||
|
|
214
|
+
this.agentFactory.getOptimalAgentSequence(task.type, _analysis.estimatedComplexity);
|
|
215
|
+
// Spawn agent swarm
|
|
216
|
+
const agents = this.agentFactory.spawnAgentSwarm(agentTypes, task.id);
|
|
217
|
+
if (this.config.debugMode) {
|
|
218
|
+
this.logger.info(`👥 Spawned ${agents.length} agents: ${agents.map(a => a.type).join(', ')}`);
|
|
219
|
+
}
|
|
220
|
+
return agents;
|
|
221
|
+
}
|
|
222
|
+
async coordinateExecution(task, agents, _analysis) {
|
|
223
|
+
const results = [];
|
|
224
|
+
try {
|
|
225
|
+
// Execute agents in optimal sequence
|
|
226
|
+
if (this.shouldExecuteInParallel(agents)) {
|
|
227
|
+
results.push(...await this.executeAgentsInParallel(agents, task.objective));
|
|
144
228
|
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
this.logger.info('\n💡 Recommendations:');
|
|
148
|
-
gapAnalysisResult.nextSteps.recommendations.forEach(rec => this.logger.info(` • ${rec}`));
|
|
229
|
+
else {
|
|
230
|
+
results.push(...await this.executeAgentsSequentially(agents, task.objective));
|
|
149
231
|
}
|
|
150
|
-
//
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
const duration = Date.now() - startTime;
|
|
164
|
-
this.learnFromExecution(task, agents, result, duration, null);
|
|
165
|
-
task.status = 'completed';
|
|
166
|
-
task.result = result;
|
|
167
|
-
if (this.config.debugMode) {
|
|
168
|
-
this.logger.info(`✅ Queen completed objective in ${duration}ms`);
|
|
232
|
+
// Coordinate final deployment using MCP tools
|
|
233
|
+
const deploymentResult = await this.executeFinalDeployment(task, results, _analysis);
|
|
234
|
+
return {
|
|
235
|
+
taskId: task.id,
|
|
236
|
+
objective: task.objective,
|
|
237
|
+
agentResults: results,
|
|
238
|
+
deploymentResult,
|
|
239
|
+
artifacts: task.artifacts
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
catch (error) {
|
|
243
|
+
// Attempt recovery or fallback
|
|
244
|
+
return await this.attemptRecovery(task, agents, error);
|
|
169
245
|
}
|
|
170
|
-
return result;
|
|
171
246
|
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
247
|
+
shouldExecuteInParallel(agents) {
|
|
248
|
+
// Parallel execution for independent agents
|
|
249
|
+
const independentAgents = ['researcher', 'tester', 'script-writer'];
|
|
250
|
+
return agents.some(agent => independentAgents.includes(agent.type));
|
|
176
251
|
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
finally {
|
|
181
|
-
this.cleanupTask(taskId);
|
|
182
|
-
}
|
|
183
|
-
spawnOptimalSwarm(task, types_1.ServiceNowTask, _analysis, types_1.TaskAnalysis);
|
|
184
|
-
types_1.Agent[];
|
|
185
|
-
{
|
|
186
|
-
if (this.config.debugMode) {
|
|
187
|
-
this.logger.info(`🐛 Spawning swarm for ${task.type} task (complexity: ${_analysis.estimatedComplexity})`);
|
|
188
|
-
}
|
|
189
|
-
// Use learned patterns or optimal sequence
|
|
190
|
-
const agentTypes = _analysis.suggestedPattern?.agentSequence ||
|
|
191
|
-
this.agentFactory.getOptimalAgentSequence(task.type, _analysis.estimatedComplexity);
|
|
192
|
-
// Spawn agent swarm
|
|
193
|
-
const agents = this.agentFactory.spawnAgentSwarm(agentTypes, task.id);
|
|
194
|
-
if (this.config.debugMode) {
|
|
195
|
-
this.logger.info(`👥 Spawned ${agents.length} agents: ${agents.map(a => a.type).join(', ')}`);
|
|
196
|
-
}
|
|
197
|
-
return agents;
|
|
198
|
-
}
|
|
199
|
-
async;
|
|
200
|
-
coordinateExecution(task, types_1.ServiceNowTask, agents, types_1.Agent[], _analysis, types_1.TaskAnalysis);
|
|
201
|
-
Promise < any > {
|
|
202
|
-
const: results, any, []: = [],
|
|
203
|
-
try: {
|
|
204
|
-
: .shouldExecuteInParallel(agents)
|
|
205
|
-
}
|
|
206
|
-
};
|
|
207
|
-
{
|
|
208
|
-
results.push(...await this.executeAgentsInParallel(agents, task.objective));
|
|
209
|
-
}
|
|
210
|
-
{
|
|
211
|
-
results.push(...await this.executeAgentsSequentially(agents, task.objective));
|
|
212
|
-
}
|
|
213
|
-
// Coordinate final deployment using MCP tools
|
|
214
|
-
const deploymentResult = await this.executeFinalDeployment(task, results, _analysis);
|
|
215
|
-
return {
|
|
216
|
-
taskId: task.id,
|
|
217
|
-
objective: task.objective,
|
|
218
|
-
agentResults: results,
|
|
219
|
-
deploymentResult,
|
|
220
|
-
artifacts: task.artifacts
|
|
221
|
-
};
|
|
222
|
-
try { }
|
|
223
|
-
catch (error) {
|
|
224
|
-
// Attempt recovery or fallback
|
|
225
|
-
return await this.attemptRecovery(task, agents, error);
|
|
226
|
-
}
|
|
227
|
-
shouldExecuteInParallel(agents, types_1.Agent[]);
|
|
228
|
-
boolean;
|
|
229
|
-
{
|
|
230
|
-
// Parallel execution for independent agents
|
|
231
|
-
const independentAgents = ['researcher', 'tester', 'script-writer'];
|
|
232
|
-
return agents.some(agent => independentAgents.includes(agent.type));
|
|
233
|
-
}
|
|
234
|
-
async;
|
|
235
|
-
executeAgentsInParallel(agents, types_1.Agent[], objective, string);
|
|
236
|
-
Promise < any[] > {
|
|
237
|
-
: .config.debugMode
|
|
238
|
-
};
|
|
239
|
-
{
|
|
240
|
-
this.logger.info('⚡ Executing agents in parallel');
|
|
241
|
-
}
|
|
242
|
-
const promises = agents.map(agent => this.agentFactory.executeAgentTask(agent.id, objective));
|
|
243
|
-
return await Promise.all(promises);
|
|
244
|
-
async;
|
|
245
|
-
executeAgentsSequentially(agents, types_1.Agent[], objective, string);
|
|
246
|
-
Promise < any[] > {
|
|
247
|
-
: .config.debugMode
|
|
248
|
-
};
|
|
249
|
-
{
|
|
250
|
-
this.logger.info('🔄 Executing agents sequentially');
|
|
251
|
-
}
|
|
252
|
-
const results = [];
|
|
253
|
-
for (const agent of agents) {
|
|
254
|
-
const result = await this.agentFactory.executeAgentTask(agent.id, objective);
|
|
255
|
-
results.push(result);
|
|
256
|
-
// Allow agents to coordinate between executions
|
|
257
|
-
this.facilitateAgentCoordination(agent, results);
|
|
258
|
-
}
|
|
259
|
-
return results;
|
|
260
|
-
facilitateAgentCoordination(currentAgent, types_1.Agent, previousResults, any[]);
|
|
261
|
-
void {
|
|
262
|
-
// Send relevant results to collaborative agents
|
|
263
|
-
const: activeAgents = this.agentFactory.getActiveAgents(),
|
|
264
|
-
for(, agent, of, activeAgents) {
|
|
265
|
-
if (agent.id !== currentAgent.id) {
|
|
266
|
-
this.agentFactory.sendAgentMessage(currentAgent.id, agent.id, 'result', {
|
|
267
|
-
results: previousResults.slice(-1)[0], // Latest result
|
|
268
|
-
fromAgent: currentAgent.type
|
|
269
|
-
});
|
|
252
|
+
async executeAgentsInParallel(agents, objective) {
|
|
253
|
+
if (this.config.debugMode) {
|
|
254
|
+
this.logger.info('⚡ Executing agents in parallel');
|
|
270
255
|
}
|
|
256
|
+
const promises = agents.map(agent => this.agentFactory.executeAgentTask(agent.id, objective));
|
|
257
|
+
return await Promise.all(promises);
|
|
271
258
|
}
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
// Execute deployment using the unified deployment API
|
|
285
|
-
const deploymentResult = await this.executeDeploymentPlan(deploymentPlan);
|
|
286
|
-
// Track artifacts created
|
|
287
|
-
if (deploymentResult.sys_id) {
|
|
288
|
-
task.artifacts.push(deploymentResult.sys_id);
|
|
289
|
-
// Store artifact in memory for future reference
|
|
290
|
-
this.memory.storeArtifact({
|
|
291
|
-
type: task.type,
|
|
292
|
-
name: deploymentResult.name || task.objective,
|
|
293
|
-
sys_id: deploymentResult.sys_id,
|
|
294
|
-
config: deploymentResult.config || {},
|
|
295
|
-
dependencies: _analysis.dependencies
|
|
296
|
-
});
|
|
259
|
+
async executeAgentsSequentially(agents, objective) {
|
|
260
|
+
if (this.config.debugMode) {
|
|
261
|
+
this.logger.info('🔄 Executing agents sequentially');
|
|
262
|
+
}
|
|
263
|
+
const results = [];
|
|
264
|
+
for (const agent of agents) {
|
|
265
|
+
const result = await this.agentFactory.executeAgentTask(agent.id, objective);
|
|
266
|
+
results.push(result);
|
|
267
|
+
// Allow agents to coordinate between executions
|
|
268
|
+
this.facilitateAgentCoordination(agent, results);
|
|
269
|
+
}
|
|
270
|
+
return results;
|
|
297
271
|
}
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
272
|
+
facilitateAgentCoordination(currentAgent, previousResults) {
|
|
273
|
+
// Send relevant results to collaborative agents
|
|
274
|
+
const activeAgents = this.agentFactory.getActiveAgents();
|
|
275
|
+
for (const agent of activeAgents) {
|
|
276
|
+
if (agent.id !== currentAgent.id) {
|
|
277
|
+
this.agentFactory.sendAgentMessage(currentAgent.id, agent.id, 'result', {
|
|
278
|
+
results: previousResults.slice(-1)[0], // Latest result
|
|
279
|
+
fromAgent: currentAgent.type
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
}
|
|
303
283
|
}
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
284
|
+
async executeFinalDeployment(task, agentResults, _analysis) {
|
|
285
|
+
if (this.config.debugMode) {
|
|
286
|
+
this.logger.info('🚀 Executing final deployment with MCP tools');
|
|
287
|
+
}
|
|
288
|
+
// The Queen coordinates the actual MCP tool calls based on agent recommendations
|
|
289
|
+
const deploymentPlan = this.createDeploymentPlan(task, agentResults, _analysis);
|
|
290
|
+
try {
|
|
291
|
+
// Execute deployment using the unified deployment API
|
|
292
|
+
const deploymentResult = await this.executeDeploymentPlan(deploymentPlan);
|
|
293
|
+
// Track artifacts created
|
|
294
|
+
if (deploymentResult.sys_id) {
|
|
295
|
+
task.artifacts.push(deploymentResult.sys_id);
|
|
296
|
+
// Store artifact in memory for future reference
|
|
297
|
+
this.memory.storeArtifact({
|
|
298
|
+
type: task.type,
|
|
299
|
+
name: deploymentResult.name || task.objective,
|
|
300
|
+
sys_id: deploymentResult.sys_id,
|
|
301
|
+
config: deploymentResult.config || {},
|
|
302
|
+
dependencies: _analysis.dependencies
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
return deploymentResult;
|
|
306
|
+
}
|
|
307
|
+
catch (error) {
|
|
308
|
+
if (this.config.debugMode) {
|
|
309
|
+
console.error('❌ Deployment failed:', error);
|
|
310
|
+
}
|
|
311
|
+
throw error;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
createDeploymentPlan(task, agentResults, _analysis) {
|
|
315
|
+
// Determine optimal approach based on knowledge base
|
|
316
|
+
const hasExistingArtifact = task.objective.toLowerCase().includes('update') ||
|
|
317
|
+
task.objective.toLowerCase().includes('edit') ||
|
|
318
|
+
task.objective.toLowerCase().includes('modify') ||
|
|
319
|
+
task.objective.toLowerCase().includes('change');
|
|
320
|
+
const requiresRefactoring = task.objective.toLowerCase().includes('refactor') ||
|
|
321
|
+
task.objective.toLowerCase().includes('rename') ||
|
|
322
|
+
task.objective.toLowerCase().includes('reorganize');
|
|
323
|
+
const userMentionedModifications = task.objective.toLowerCase().includes('i modified') ||
|
|
324
|
+
task.objective.toLowerCase().includes('i changed') ||
|
|
325
|
+
task.objective.toLowerCase().includes('i updated') ||
|
|
326
|
+
task.objective.toLowerCase().includes('aangepast') ||
|
|
327
|
+
task.objective.toLowerCase().includes('zelf');
|
|
328
|
+
const approach = (0, queen_knowledge_base_1.determineOptimalApproach)(task.objective, task.type, {
|
|
329
|
+
hasExistingArtifact,
|
|
330
|
+
complexity: _analysis.estimatedComplexity > 7 ? 'high' :
|
|
331
|
+
_analysis.estimatedComplexity > 4 ? 'medium' : 'low',
|
|
332
|
+
requiresRefactoring,
|
|
333
|
+
userMentionedModifications
|
|
334
|
+
});
|
|
335
|
+
if (this.config.debugMode) {
|
|
336
|
+
this.logger.info(`🎨 Optimal approach: ${approach}`);
|
|
337
|
+
this.logger.info(`🔍 Artifact sync available: ${queen_knowledge_base_1.QUEEN_KNOWLEDGE_BASE.artifactCapabilities[this.getTableForType(task.type)]?.localSync}`);
|
|
338
|
+
}
|
|
339
|
+
// If local sync is optimal and available
|
|
340
|
+
if (approach === 'Local Sync Development' && hasExistingArtifact) {
|
|
341
|
+
const table = this.getTableForType(task.type);
|
|
342
|
+
if (queen_knowledge_base_1.QUEEN_KNOWLEDGE_BASE.artifactCapabilities[table]?.localSync) {
|
|
343
|
+
return {
|
|
344
|
+
type: 'local-sync',
|
|
345
|
+
approach: approach,
|
|
346
|
+
mcpTool: 'snow_pull_artifact',
|
|
347
|
+
workflow: queen_knowledge_base_1.QUEEN_KNOWLEDGE_BASE.developmentPatterns.widgetDevelopment.approaches[0].workflow,
|
|
348
|
+
config: {
|
|
349
|
+
table: table,
|
|
350
|
+
sys_id: this.extractSysIdFromObjective(task.objective)
|
|
351
|
+
}
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
// Extract deployment instructions from agent results
|
|
356
|
+
const widgetCreator = agentResults.find(r => r.agentType === 'widget-creator');
|
|
357
|
+
const flowBuilder = agentResults.find(r => r.agentType === 'flow-builder');
|
|
358
|
+
const scriptWriter = agentResults.find(r => r.agentType === 'script-writer');
|
|
359
|
+
const catalogManager = agentResults.find(r => r.agentType === 'catalog-manager');
|
|
360
|
+
if (task.type === 'widget' && widgetCreator) {
|
|
361
|
+
return {
|
|
362
|
+
type: 'widget',
|
|
363
|
+
mcpTool: 'snow_deploy',
|
|
364
|
+
config: this.extractWidgetConfig(task.objective, agentResults),
|
|
365
|
+
autoPermissions: this.config.autoPermissions // Pass auto-permissions flag for dependency handling
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
// Flow creation is no longer supported - use ServiceNow Flow Designer directly
|
|
369
|
+
if (task.type === 'flow') {
|
|
370
|
+
throw new Error('Flow creation is no longer supported in Snow-Flow. Please use ServiceNow Flow Designer directly.');
|
|
371
|
+
}
|
|
372
|
+
if (task.type === 'script' && scriptWriter) {
|
|
373
|
+
return {
|
|
374
|
+
type: 'script',
|
|
375
|
+
mcpTool: 'snow_create_script_include',
|
|
376
|
+
config: this.extractScriptConfig(task.objective, agentResults)
|
|
377
|
+
};
|
|
378
|
+
}
|
|
379
|
+
// Default deployment plan
|
|
315
380
|
return {
|
|
316
|
-
type:
|
|
381
|
+
type: task.type,
|
|
317
382
|
mcpTool: 'snow_deploy',
|
|
318
|
-
|
|
319
|
-
autoPermissions: this.config.autoPermissions // Pass auto-permissions flag for dependency handling
|
|
383
|
+
instruction: task.objective
|
|
320
384
|
};
|
|
321
385
|
}
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
386
|
+
extractWidgetConfig(objective, agentResults) {
|
|
387
|
+
// Extract widget configuration from agent results
|
|
388
|
+
const widgetResult = agentResults.find(r => r.agentType === 'widget-creator');
|
|
389
|
+
return {
|
|
390
|
+
name: this.generateArtifactName(objective, 'widget'),
|
|
391
|
+
title: this.generateArtifactTitle(objective),
|
|
392
|
+
template: this.generateWidgetTemplate(objective),
|
|
393
|
+
css: this.generateWidgetCss(objective),
|
|
394
|
+
client_script: this.generateClientScript(objective),
|
|
395
|
+
script: this.generateServerScript(objective), // ServiceNow uses 'script' field, not 'server_script'
|
|
396
|
+
demo_data: this.generateDemoData(objective)
|
|
397
|
+
};
|
|
325
398
|
}
|
|
326
|
-
|
|
399
|
+
extractScriptConfig(objective, agentResults) {
|
|
327
400
|
return {
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
401
|
+
name: this.generateArtifactName(objective, 'script'),
|
|
402
|
+
description: `Auto-generated script for: ${objective}`,
|
|
403
|
+
script: this.generateScriptCode(objective)
|
|
331
404
|
};
|
|
332
405
|
}
|
|
333
|
-
//
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
{
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
title: this.generateArtifactTitle(objective),
|
|
348
|
-
template: this.generateWidgetTemplate(objective),
|
|
349
|
-
css: this.generateWidgetCss(objective),
|
|
350
|
-
client_script: this.generateClientScript(objective),
|
|
351
|
-
server_script: this.generateServerScript(objective),
|
|
352
|
-
demo_data: this.generateDemoData(objective)
|
|
353
|
-
};
|
|
354
|
-
}
|
|
355
|
-
extractScriptConfig(objective, string, agentResults, any[]);
|
|
356
|
-
any;
|
|
357
|
-
{
|
|
358
|
-
return {
|
|
359
|
-
name: this.generateArtifactName(objective, 'script'),
|
|
360
|
-
description: `Auto-generated script for: ${objective}`,
|
|
361
|
-
script: this.generateScriptCode(objective)
|
|
362
|
-
};
|
|
363
|
-
}
|
|
364
|
-
generateArtifactName(objective, string, type, string);
|
|
365
|
-
string;
|
|
366
|
-
{
|
|
367
|
-
const words = objective.toLowerCase().replace(/[^a-z\s]/g, '').split(/\s+/).filter(w => w.length > 2);
|
|
368
|
-
const key_words = words.slice(0, 3).join('_');
|
|
369
|
-
return `${key_words}_${type}`;
|
|
370
|
-
}
|
|
371
|
-
generateArtifactTitle(objective, string);
|
|
372
|
-
string;
|
|
373
|
-
{
|
|
374
|
-
return objective.charAt(0).toUpperCase() + objective.slice(1);
|
|
375
|
-
}
|
|
376
|
-
generateWidgetTemplate(objective, string);
|
|
377
|
-
string;
|
|
378
|
-
{
|
|
379
|
-
const isChart = objective.toLowerCase().includes('chart') || objective.toLowerCase().includes('graph');
|
|
380
|
-
const isDashboard = objective.toLowerCase().includes('dashboard');
|
|
381
|
-
if (isChart) {
|
|
382
|
-
return `
|
|
406
|
+
// Simple artifact generation based on objective analysis
|
|
407
|
+
generateArtifactName(objective, type) {
|
|
408
|
+
const words = objective.toLowerCase().replace(/[^a-z\s]/g, '').split(/\s+/).filter(w => w.length > 2);
|
|
409
|
+
const key_words = words.slice(0, 3).join('_');
|
|
410
|
+
return `${key_words}_${type}`;
|
|
411
|
+
}
|
|
412
|
+
generateArtifactTitle(objective) {
|
|
413
|
+
return objective.charAt(0).toUpperCase() + objective.slice(1);
|
|
414
|
+
}
|
|
415
|
+
generateWidgetTemplate(objective) {
|
|
416
|
+
const isChart = objective.toLowerCase().includes('chart') || objective.toLowerCase().includes('graph');
|
|
417
|
+
const isDashboard = objective.toLowerCase().includes('dashboard');
|
|
418
|
+
if (isChart) {
|
|
419
|
+
return `
|
|
383
420
|
<div class="panel panel-default">
|
|
384
421
|
<div class="panel-heading">
|
|
385
422
|
<h3 class="panel-title">{{data.title || '${this.generateArtifactTitle(objective)}'}}</h3>
|
|
@@ -388,9 +425,9 @@ string;
|
|
|
388
425
|
<canvas id="chart-{{::data.widget_id}}" width="400" height="200"></canvas>
|
|
389
426
|
</div>
|
|
390
427
|
</div>`;
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
428
|
+
}
|
|
429
|
+
if (isDashboard) {
|
|
430
|
+
return `
|
|
394
431
|
<div class="row">
|
|
395
432
|
<div class="col-md-12">
|
|
396
433
|
<div class="panel panel-default">
|
|
@@ -410,8 +447,8 @@ string;
|
|
|
410
447
|
</div>
|
|
411
448
|
</div>
|
|
412
449
|
</div>`;
|
|
413
|
-
|
|
414
|
-
|
|
450
|
+
}
|
|
451
|
+
return `
|
|
415
452
|
<div class="panel panel-default">
|
|
416
453
|
<div class="panel-heading">
|
|
417
454
|
<h3 class="panel-title">{{data.title || '${this.generateArtifactTitle(objective)}'}}</h3>
|
|
@@ -430,11 +467,9 @@ string;
|
|
|
430
467
|
</div>
|
|
431
468
|
</div>
|
|
432
469
|
</div>`;
|
|
433
|
-
}
|
|
434
|
-
generateWidgetCss(objective
|
|
435
|
-
|
|
436
|
-
{
|
|
437
|
-
return `
|
|
470
|
+
}
|
|
471
|
+
generateWidgetCss(objective) {
|
|
472
|
+
return `
|
|
438
473
|
.panel {
|
|
439
474
|
margin-bottom: 20px;
|
|
440
475
|
border-radius: 6px;
|
|
@@ -466,13 +501,11 @@ string;
|
|
|
466
501
|
margin-bottom: 15px;
|
|
467
502
|
}
|
|
468
503
|
}`;
|
|
469
|
-
}
|
|
470
|
-
generateClientScript(objective
|
|
471
|
-
|
|
472
|
-
{
|
|
473
|
-
|
|
474
|
-
if (isChart) {
|
|
475
|
-
return `
|
|
504
|
+
}
|
|
505
|
+
generateClientScript(objective) {
|
|
506
|
+
const isChart = objective.toLowerCase().includes('chart') || objective.toLowerCase().includes('graph');
|
|
507
|
+
if (isChart) {
|
|
508
|
+
return `
|
|
476
509
|
function($scope) {
|
|
477
510
|
var c = this;
|
|
478
511
|
|
|
@@ -501,8 +534,8 @@ function($scope) {
|
|
|
501
534
|
}
|
|
502
535
|
};
|
|
503
536
|
}`;
|
|
504
|
-
|
|
505
|
-
|
|
537
|
+
}
|
|
538
|
+
return `
|
|
506
539
|
function($scope) {
|
|
507
540
|
var c = this;
|
|
508
541
|
|
|
@@ -522,13 +555,11 @@ function($scope) {
|
|
|
522
555
|
c.server.refresh();
|
|
523
556
|
};
|
|
524
557
|
}`;
|
|
525
|
-
}
|
|
526
|
-
generateServerScript(objective
|
|
527
|
-
|
|
528
|
-
{
|
|
529
|
-
|
|
530
|
-
if (lowerObjective.includes('incident')) {
|
|
531
|
-
return `
|
|
558
|
+
}
|
|
559
|
+
generateServerScript(objective) {
|
|
560
|
+
const lowerObjective = objective.toLowerCase();
|
|
561
|
+
if (lowerObjective.includes('incident')) {
|
|
562
|
+
return `
|
|
532
563
|
(function() {
|
|
533
564
|
data.title = options.title || 'Incidents Dashboard';
|
|
534
565
|
data.widget_id = gs.generateGUID();
|
|
@@ -569,8 +600,8 @@ string;
|
|
|
569
600
|
data.chartType = 'doughnut';
|
|
570
601
|
}
|
|
571
602
|
})();`;
|
|
572
|
-
|
|
573
|
-
|
|
603
|
+
}
|
|
604
|
+
return `
|
|
574
605
|
(function() {
|
|
575
606
|
data.title = options.title || '${this.generateArtifactTitle(objective)}';
|
|
576
607
|
data.widget_id = gs.generateGUID();
|
|
@@ -591,24 +622,20 @@ string;
|
|
|
591
622
|
}
|
|
592
623
|
];
|
|
593
624
|
})();`;
|
|
594
|
-
}
|
|
595
|
-
generateDemoData(objective
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
generateScriptCode(objective, string);
|
|
609
|
-
string;
|
|
610
|
-
{
|
|
611
|
-
return `
|
|
625
|
+
}
|
|
626
|
+
generateDemoData(objective) {
|
|
627
|
+
return {
|
|
628
|
+
title: this.generateArtifactTitle(objective),
|
|
629
|
+
items: [
|
|
630
|
+
{
|
|
631
|
+
title: 'Demo Item 1',
|
|
632
|
+
description: 'Sample data for testing the widget'
|
|
633
|
+
}
|
|
634
|
+
]
|
|
635
|
+
};
|
|
636
|
+
}
|
|
637
|
+
generateScriptCode(objective) {
|
|
638
|
+
return `
|
|
612
639
|
// Auto-generated script for: ${objective}
|
|
613
640
|
// Generated by ServiceNow Queen Agent
|
|
614
641
|
|
|
@@ -621,331 +648,755 @@ string;
|
|
|
621
648
|
message: 'Script executed successfully'
|
|
622
649
|
};
|
|
623
650
|
})();`;
|
|
624
|
-
}
|
|
625
|
-
async;
|
|
626
|
-
executeDeploymentPlan(plan, any);
|
|
627
|
-
Promise < any > {
|
|
628
|
-
: .config.debugMode
|
|
629
|
-
};
|
|
630
|
-
{
|
|
631
|
-
this.logger.info('🚀 Executing deployment plan with MCP Bridge');
|
|
632
|
-
}
|
|
633
|
-
// Create agent recommendation from plan
|
|
634
|
-
const recommendation = {
|
|
635
|
-
agentId: 'queen-agent',
|
|
636
|
-
agentType: 'queen',
|
|
637
|
-
action: `deploy-${plan.type}`,
|
|
638
|
-
tool: plan.mcpTool,
|
|
639
|
-
server: this.getServerForTool(plan.mcpTool),
|
|
640
|
-
params: plan.config || {},
|
|
641
|
-
reasoning: `Deploying ${plan.type} artifact as requested`,
|
|
642
|
-
confidence: 0.95
|
|
643
|
-
};
|
|
644
|
-
// Execute through MCP bridge
|
|
645
|
-
const result = await this.mcpBridge.executeAgentRecommendation({ id: 'queen-agent', type: 'queen' }, recommendation);
|
|
646
|
-
if (result.success && result.toolResult) {
|
|
647
|
-
const deploymentResult = {
|
|
648
|
-
success: true,
|
|
649
|
-
type: plan.type,
|
|
650
|
-
name: plan.config?.name || result.toolResult.name,
|
|
651
|
-
sys_id: result.toolResult.sys_id, // Real sys_id from ServiceNow!
|
|
652
|
-
config: plan.config,
|
|
653
|
-
mcpTool: plan.mcpTool,
|
|
654
|
-
executionTime: result.executionTime
|
|
655
|
-
};
|
|
656
|
-
// Handle dependency injection for widgets
|
|
657
|
-
if (plan.type === 'widget' && plan.config) {
|
|
658
|
-
await this.handleWidgetDependencies(plan.config, plan.autoPermissions);
|
|
659
651
|
}
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
}
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
};
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
this.
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
// Create MCP tools wrapper for theme manager
|
|
697
|
-
const mcpTools = {
|
|
698
|
-
snow_find_artifact: async (params) => {
|
|
652
|
+
async executeDeploymentPlan(plan) {
|
|
653
|
+
// Handle local sync workflow for artifact editing
|
|
654
|
+
if (plan.type === 'local-sync') {
|
|
655
|
+
if (this.config.debugMode) {
|
|
656
|
+
this.logger.info('🔄 Executing Local Sync Development workflow');
|
|
657
|
+
this.logger.info('📁 Artifact will be synced to local files for editing');
|
|
658
|
+
}
|
|
659
|
+
// Create recommendation for local sync
|
|
660
|
+
const recommendation = {
|
|
661
|
+
agentId: 'queen-agent',
|
|
662
|
+
agentType: 'queen',
|
|
663
|
+
action: 'local-sync',
|
|
664
|
+
tool: 'snow_pull_artifact',
|
|
665
|
+
server: 'servicenow-local-development',
|
|
666
|
+
params: plan.config,
|
|
667
|
+
reasoning: 'Syncing artifact to local files for advanced editing with Claude Code',
|
|
668
|
+
confidence: 0.95
|
|
669
|
+
};
|
|
670
|
+
// Execute pull through MCP bridge
|
|
671
|
+
const result = await this.mcpBridge.executeAgentRecommendation({ id: 'queen-agent', type: 'queen' }, recommendation);
|
|
672
|
+
if (result.success) {
|
|
673
|
+
return {
|
|
674
|
+
success: true,
|
|
675
|
+
type: 'local-sync',
|
|
676
|
+
approach: plan.approach,
|
|
677
|
+
message: 'Artifact synced to local files. Edit with Claude Code, then use snow_push_artifact to sync back.',
|
|
678
|
+
localPath: result.toolResult?.localPath,
|
|
679
|
+
files: result.toolResult?.files
|
|
680
|
+
};
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
// Execute real MCP tools through the bridge
|
|
684
|
+
if (this.config.debugMode) {
|
|
685
|
+
this.logger.info('🚀 Executing deployment plan with MCP Bridge');
|
|
686
|
+
}
|
|
687
|
+
// Create agent recommendation from plan
|
|
699
688
|
const recommendation = {
|
|
700
689
|
agentId: 'queen-agent',
|
|
701
690
|
agentType: 'queen',
|
|
702
|
-
action:
|
|
703
|
-
tool:
|
|
704
|
-
server:
|
|
705
|
-
params,
|
|
706
|
-
reasoning:
|
|
691
|
+
action: `deploy-${plan.type}`,
|
|
692
|
+
tool: plan.mcpTool,
|
|
693
|
+
server: this.getServerForTool(plan.mcpTool),
|
|
694
|
+
params: plan.config || {},
|
|
695
|
+
reasoning: `Deploying ${plan.type} artifact as requested`,
|
|
707
696
|
confidence: 0.95
|
|
708
697
|
};
|
|
698
|
+
// Execute through MCP bridge
|
|
709
699
|
const result = await this.mcpBridge.executeAgentRecommendation({ id: 'queen-agent', type: 'queen' }, recommendation);
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
700
|
+
if (result.success && result.toolResult) {
|
|
701
|
+
const deploymentResult = {
|
|
702
|
+
success: true,
|
|
703
|
+
type: plan.type,
|
|
704
|
+
name: plan.config?.name || result.toolResult.name,
|
|
705
|
+
sys_id: result.toolResult.sys_id, // Real sys_id from ServiceNow!
|
|
706
|
+
config: plan.config,
|
|
707
|
+
mcpTool: plan.mcpTool,
|
|
708
|
+
executionTime: result.executionTime
|
|
709
|
+
};
|
|
710
|
+
// Handle dependency injection for widgets
|
|
711
|
+
if (plan.type === 'widget' && plan.config) {
|
|
712
|
+
await this.handleWidgetDependencies(plan.config, plan.autoPermissions);
|
|
713
|
+
}
|
|
714
|
+
return deploymentResult;
|
|
715
|
+
}
|
|
716
|
+
else {
|
|
717
|
+
throw new Error(`MCP execution failed: ${result.error || 'Unknown error'}`);
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
getServerForTool(tool) {
|
|
721
|
+
// Map tools to their servers
|
|
722
|
+
const toolServerMap = {
|
|
723
|
+
'snow_deploy': 'deployment',
|
|
724
|
+
'snow_deploy_widget': 'deployment',
|
|
725
|
+
'snow_deploy_flow': 'deployment',
|
|
726
|
+
'snow_find_artifact': 'intelligent',
|
|
727
|
+
'snow_update_set_create': 'update-set',
|
|
728
|
+
'snow_get_by_sysid': 'intelligent',
|
|
729
|
+
'snow_edit_by_sysid': 'intelligent'
|
|
722
730
|
};
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
731
|
+
return toolServerMap[tool] || 'deployment';
|
|
732
|
+
}
|
|
733
|
+
async handleWidgetDependencies(widgetConfig, autoPermissions) {
|
|
734
|
+
try {
|
|
735
|
+
// Detect dependencies in widget code
|
|
736
|
+
const dependencies = dependency_detector_1.DependencyDetector.analyzeWidget(widgetConfig);
|
|
737
|
+
if (dependencies.length === 0) {
|
|
738
|
+
return; // No dependencies needed
|
|
739
|
+
}
|
|
740
|
+
this.logger.info(`\n📦 Detected ${dependencies.length} external dependencies in widget:`);
|
|
741
|
+
dependencies.forEach(dep => {
|
|
742
|
+
this.logger.info(` • ${dep.name} - ${dep.description}`);
|
|
743
|
+
});
|
|
744
|
+
// Create MCP tools wrapper for theme manager
|
|
745
|
+
const mcpTools = {
|
|
746
|
+
snow_find_artifact: async (params) => {
|
|
747
|
+
const recommendation = {
|
|
748
|
+
agentId: 'queen-agent',
|
|
749
|
+
agentType: 'queen',
|
|
750
|
+
action: 'find-theme',
|
|
751
|
+
tool: 'snow_find_artifact',
|
|
752
|
+
server: 'intelligent',
|
|
753
|
+
params,
|
|
754
|
+
reasoning: 'Finding Service Portal theme for dependency injection',
|
|
755
|
+
confidence: 0.95
|
|
756
|
+
};
|
|
757
|
+
const result = await this.mcpBridge.executeAgentRecommendation({ id: 'queen-agent', type: 'queen' }, recommendation);
|
|
758
|
+
return result.toolResult;
|
|
759
|
+
},
|
|
760
|
+
snow_comprehensive_search: async (params) => {
|
|
761
|
+
const recommendation = {
|
|
762
|
+
agentId: 'queen-agent',
|
|
763
|
+
agentType: 'queen',
|
|
764
|
+
action: 'search-themes',
|
|
765
|
+
tool: 'snow_comprehensive_search',
|
|
766
|
+
server: 'intelligent',
|
|
767
|
+
params,
|
|
768
|
+
reasoning: 'Searching for Service Portal themes',
|
|
769
|
+
confidence: 0.95
|
|
770
|
+
};
|
|
771
|
+
const result = await this.mcpBridge.executeAgentRecommendation({ id: 'queen-agent', type: 'queen' }, recommendation);
|
|
772
|
+
return result.toolResult;
|
|
773
|
+
},
|
|
774
|
+
snow_get_by_sysid: async (params) => {
|
|
775
|
+
const recommendation = {
|
|
776
|
+
agentId: 'queen-agent',
|
|
777
|
+
agentType: 'queen',
|
|
778
|
+
action: 'get-theme',
|
|
779
|
+
tool: 'snow_get_by_sysid',
|
|
780
|
+
server: 'intelligent',
|
|
781
|
+
params,
|
|
782
|
+
reasoning: 'Getting Service Portal theme details',
|
|
783
|
+
confidence: 0.95
|
|
784
|
+
};
|
|
785
|
+
const result = await this.mcpBridge.executeAgentRecommendation({ id: 'queen-agent', type: 'queen' }, recommendation);
|
|
786
|
+
return result.toolResult;
|
|
787
|
+
},
|
|
788
|
+
snow_edit_by_sysid: async (params) => {
|
|
789
|
+
const recommendation = {
|
|
790
|
+
agentId: 'queen-agent',
|
|
791
|
+
agentType: 'queen',
|
|
792
|
+
action: 'update-theme',
|
|
793
|
+
tool: 'snow_edit_by_sysid',
|
|
794
|
+
server: 'intelligent',
|
|
795
|
+
params,
|
|
796
|
+
reasoning: 'Updating Service Portal theme with dependencies',
|
|
797
|
+
confidence: 0.95
|
|
798
|
+
};
|
|
799
|
+
const result = await this.mcpBridge.executeAgentRecommendation({ id: 'queen-agent', type: 'queen' }, recommendation);
|
|
800
|
+
return result.toolResult;
|
|
801
|
+
}
|
|
802
|
+
};
|
|
803
|
+
// Update theme with dependencies
|
|
804
|
+
const result = await theme_manager_1.ServicePortalThemeManager.updateThemeWithDependencies(dependencies, mcpTools, {
|
|
805
|
+
autoPermissions,
|
|
806
|
+
skipPrompt: autoPermissions, // Skip prompt if auto-permissions enabled
|
|
807
|
+
useMinified: true
|
|
808
|
+
});
|
|
809
|
+
if (result.success) {
|
|
810
|
+
this.logger.info(`✅ ${result.message}`);
|
|
811
|
+
}
|
|
812
|
+
else {
|
|
813
|
+
this.logger.warn(`⚠️ Dependencies not installed: ${result.message}`);
|
|
814
|
+
this.logger.info('💡 You may need to manually add these dependencies to your Service Portal theme');
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
catch (error) {
|
|
818
|
+
console.error('❌ Error handling widget dependencies:', error.message);
|
|
819
|
+
// Don't fail the deployment, just warn
|
|
820
|
+
this.logger.warn('⚠️ Widget deployed successfully but dependencies may need manual installation');
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
async attemptRecovery(task, agents, error) {
|
|
824
|
+
if (this.config.debugMode) {
|
|
825
|
+
this.logger.info(`🔄 Attempting recovery for task ${task.id}`);
|
|
826
|
+
}
|
|
827
|
+
// Try with reduced complexity or different agent sequence
|
|
828
|
+
const fallbackResult = {
|
|
829
|
+
taskId: task.id,
|
|
830
|
+
objective: task.objective,
|
|
831
|
+
status: 'recovered',
|
|
832
|
+
error: error.message,
|
|
833
|
+
fallbackApplied: true
|
|
736
834
|
};
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
835
|
+
return fallbackResult;
|
|
836
|
+
}
|
|
837
|
+
learnFromExecution(task, agents, result, duration, error) {
|
|
838
|
+
const agentTypes = agents.map(a => a.type);
|
|
839
|
+
if (error) {
|
|
840
|
+
// Learn from failure
|
|
841
|
+
this.neuralLearning.learnFromFailure(task, error.message, agentTypes);
|
|
842
|
+
this.memory.recordTaskCompletion(task.id, task.objective, task.type, agentTypes, false, duration);
|
|
843
|
+
}
|
|
844
|
+
else {
|
|
845
|
+
// Learn from success
|
|
846
|
+
this.neuralLearning.learnFromSuccess(task, duration, agentTypes);
|
|
847
|
+
this.memory.recordTaskCompletion(task.id, task.objective, task.type, agentTypes, true, duration);
|
|
848
|
+
}
|
|
849
|
+
if (this.config.debugMode) {
|
|
850
|
+
this.logger.info(`📚 Queen learned from ${error ? 'failure' : 'success'}: ${task.objective}`);
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
async handleExecutionFailure(taskId, objective, error, duration) {
|
|
854
|
+
const task = this.activeTasks.get(taskId);
|
|
855
|
+
if (task) {
|
|
856
|
+
task.status = 'failed';
|
|
857
|
+
task.error = error.message;
|
|
858
|
+
// Learn from failure
|
|
859
|
+
this.memory.storeLearning(`failure_${task.type}`, `Failed: ${objective} - Error: ${error.message}`, 0.8);
|
|
860
|
+
}
|
|
861
|
+
if (this.config.debugMode) {
|
|
862
|
+
console.error(`❌ Task ${taskId} failed after ${duration}ms:`, error.message);
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
cleanupTask(taskId) {
|
|
866
|
+
this.activeTasks.delete(taskId);
|
|
867
|
+
this.agentFactory.cleanupCompletedAgents();
|
|
868
|
+
}
|
|
869
|
+
generateTaskId() {
|
|
870
|
+
return `task_${Date.now()}_${crypto.randomBytes(4).toString('hex')}`;
|
|
871
|
+
}
|
|
872
|
+
// Public API methods
|
|
873
|
+
getActiveTaskCount() {
|
|
874
|
+
return this.activeTasks.size;
|
|
875
|
+
}
|
|
876
|
+
getTaskStatus(taskId) {
|
|
877
|
+
return this.activeTasks.get(taskId) || null;
|
|
878
|
+
}
|
|
879
|
+
/**
|
|
880
|
+
* Get gap _analysis results for a task
|
|
881
|
+
*/
|
|
882
|
+
getGapAnalysisResults(taskId) {
|
|
883
|
+
const task = this.activeTasks.get(taskId);
|
|
884
|
+
return task?.gapAnalysis || null;
|
|
885
|
+
}
|
|
886
|
+
/**
|
|
887
|
+
* Get all manual guides from gap _analysis for a task
|
|
888
|
+
*/
|
|
889
|
+
getManualConfigurationGuides(taskId) {
|
|
890
|
+
// Get strategic analysis from task
|
|
891
|
+
const task = this.activeTasks.get(taskId);
|
|
892
|
+
const strategicAnalysis = task?.strategicAnalysis;
|
|
893
|
+
return strategicAnalysis?.problemAnalysis?.hiddenRequirements || null;
|
|
894
|
+
}
|
|
895
|
+
getHiveMindStatus() {
|
|
896
|
+
return {
|
|
897
|
+
activeTasks: this.activeTasks.size,
|
|
898
|
+
activeAgents: this.agentFactory.getActiveAgents().length,
|
|
899
|
+
memoryStats: {
|
|
900
|
+
patterns: this.memory['memory'].patterns.length,
|
|
901
|
+
artifacts: this.memory['memory'].artifacts.size,
|
|
902
|
+
learnings: this.memory['memory'].learnings.size
|
|
903
|
+
},
|
|
904
|
+
factoryStats: this.agentFactory.getStatistics(),
|
|
905
|
+
learningInsights: this.neuralLearning.getLearningInsights()
|
|
750
906
|
};
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
}
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
}
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
}
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
}
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
}
|
|
799
|
-
|
|
800
|
-
this
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
{
|
|
806
|
-
|
|
807
|
-
}
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
}
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
}
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
}
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
907
|
+
}
|
|
908
|
+
exportMemory() {
|
|
909
|
+
return this.memory.exportMemory();
|
|
910
|
+
}
|
|
911
|
+
importMemory(memoryData) {
|
|
912
|
+
this.memory.importMemory(memoryData);
|
|
913
|
+
if (this.config.debugMode) {
|
|
914
|
+
this.logger.info('🧠 Queen hive-mind memory imported successfully');
|
|
915
|
+
}
|
|
916
|
+
}
|
|
917
|
+
clearMemory() {
|
|
918
|
+
this.memory.clearMemory();
|
|
919
|
+
// Also reset neural learning weights
|
|
920
|
+
this.neuralLearning = new neural_learning_1.NeuralLearning(this.memory);
|
|
921
|
+
if (this.config.debugMode) {
|
|
922
|
+
this.logger.info('🧠 Queen hive-mind memory cleared - starting fresh');
|
|
923
|
+
}
|
|
924
|
+
}
|
|
925
|
+
getLearningInsights() {
|
|
926
|
+
const neuralInsights = this.neuralLearning.getLearningInsights();
|
|
927
|
+
return {
|
|
928
|
+
successfulPatterns: this.memory['memory'].patterns.slice(0, 5).map(pattern => ({
|
|
929
|
+
description: `${pattern.taskType} deployment using ${pattern.agentSequence.join(' → ')}`,
|
|
930
|
+
successRate: Math.round(pattern.successRate * 100),
|
|
931
|
+
avgDuration: pattern.avgDuration,
|
|
932
|
+
useCount: this.memory.getSuccessRate(pattern.taskType)
|
|
933
|
+
})),
|
|
934
|
+
recommendations: [
|
|
935
|
+
'Use Queen Agent for complex multi-step ServiceNow tasks',
|
|
936
|
+
'Enable --debug mode for detailed hive-mind insights',
|
|
937
|
+
'Export memory regularly to preserve learning patterns',
|
|
938
|
+
'Let Queen analyze objectives for optimal agent coordination'
|
|
939
|
+
],
|
|
940
|
+
commonTasks: Object.entries(neuralInsights.weights || {})
|
|
941
|
+
.map(([type, count]) => ({
|
|
942
|
+
type,
|
|
943
|
+
count: typeof count === 'number' ? count : 0
|
|
944
|
+
}))
|
|
945
|
+
.sort((a, b) => b.count - a.count)
|
|
946
|
+
.slice(0, 5),
|
|
947
|
+
memoryStats: {
|
|
948
|
+
totalPatterns: this.memory['memory'].patterns.length,
|
|
949
|
+
totalArtifacts: this.memory['memory'].artifacts.size,
|
|
950
|
+
totalLearnings: this.memory['memory'].learnings.size
|
|
951
|
+
},
|
|
952
|
+
neuralInsights
|
|
953
|
+
};
|
|
954
|
+
}
|
|
955
|
+
async shutdown() {
|
|
956
|
+
if (this.config.debugMode) {
|
|
957
|
+
this.logger.info('🛑 Shutting down ServiceNow Queen Agent');
|
|
958
|
+
}
|
|
959
|
+
// Clean up all agents
|
|
960
|
+
const activeAgents = this.agentFactory.getActiveAgents();
|
|
961
|
+
for (const agent of activeAgents) {
|
|
962
|
+
this.agentFactory.terminateAgent(agent.id);
|
|
963
|
+
}
|
|
964
|
+
// Shutdown MCP Bridge
|
|
965
|
+
if (this.mcpBridge) {
|
|
966
|
+
await this.mcpBridge.shutdown();
|
|
967
|
+
}
|
|
968
|
+
// Close memory system
|
|
969
|
+
this.memory.close();
|
|
970
|
+
}
|
|
971
|
+
/**
|
|
972
|
+
* STRATEGIC ORCHESTRATION METHODS
|
|
973
|
+
* These methods implement the Queen Agent's strategic thinking capabilities
|
|
974
|
+
*/
|
|
975
|
+
/**
|
|
976
|
+
* Perform deep problem analysis to understand what user ACTUALLY needs
|
|
977
|
+
*/
|
|
978
|
+
async performDeepProblemAnalysis(objective) {
|
|
979
|
+
this.logger.info('🧠 Deep Problem Analysis: Looking beyond surface requirements...');
|
|
980
|
+
// Analyze the objective for hidden complexity and real business needs
|
|
981
|
+
const analysis = {
|
|
982
|
+
coreProblem: this.extractCoreProblem(objective),
|
|
983
|
+
complexity: this.assessObjectiveComplexity(objective),
|
|
984
|
+
businessImpact: this.assessBusinessImpact(objective),
|
|
985
|
+
stakeholders: this.identifyStakeholders(objective),
|
|
986
|
+
hiddenRequirements: this.identifyHiddenRequirements(objective),
|
|
987
|
+
successCriteria: this.defineSuccessCriteria(objective)
|
|
988
|
+
};
|
|
989
|
+
this.logger.info(`🎯 Core Problem Identified: ${analysis.coreProblem}`);
|
|
990
|
+
this.logger.info(`📈 Success Criteria: ${analysis.successCriteria.join(', ')}`);
|
|
991
|
+
return analysis;
|
|
992
|
+
}
|
|
993
|
+
/**
|
|
994
|
+
* Perform comprehensive risk assessment
|
|
995
|
+
*/
|
|
996
|
+
async performRiskAssessment(objective, problemAnalysis) {
|
|
997
|
+
this.logger.info('⚠️ Strategic Risk Assessment: Identifying all potential failure points...');
|
|
998
|
+
const risks = [
|
|
999
|
+
...this.identifyTechnicalRisks(objective, problemAnalysis),
|
|
1000
|
+
...this.identifyBusinessRisks(objective, problemAnalysis),
|
|
1001
|
+
...this.identifyOperationalRisks(objective, problemAnalysis),
|
|
1002
|
+
...this.identifyComplianceRisks(objective, problemAnalysis)
|
|
1003
|
+
];
|
|
1004
|
+
const criticalRisks = risks.filter(risk => risk.impact === 'high' && risk.likelihood === 'high');
|
|
1005
|
+
const overallRisk = this.calculateOverallRisk(risks);
|
|
1006
|
+
return {
|
|
1007
|
+
risks,
|
|
1008
|
+
criticalRisks,
|
|
1009
|
+
overallRisk,
|
|
1010
|
+
mitigationStrategies: this.developMitigationStrategies(criticalRisks)
|
|
1011
|
+
};
|
|
1012
|
+
}
|
|
1013
|
+
/**
|
|
1014
|
+
* Extract the core business problem from user request
|
|
1015
|
+
*/
|
|
1016
|
+
getTableForType(type) {
|
|
1017
|
+
const typeToTable = {
|
|
1018
|
+
'widget': 'sp_widget',
|
|
1019
|
+
'flow': 'sys_hub_flow',
|
|
1020
|
+
'script': 'sys_script_include',
|
|
1021
|
+
'business_rule': 'sys_script',
|
|
1022
|
+
'ui_page': 'sys_ui_page',
|
|
1023
|
+
'client_script': 'sys_script_client',
|
|
1024
|
+
'ui_policy': 'sys_ui_policy',
|
|
1025
|
+
'scheduled_job': 'sysauto_script',
|
|
1026
|
+
'fix_script': 'sys_script_fix'
|
|
1027
|
+
};
|
|
1028
|
+
return typeToTable[type] || 'sys_metadata';
|
|
1029
|
+
}
|
|
1030
|
+
extractSysIdFromObjective(objective) {
|
|
1031
|
+
// Look for sys_id patterns in the objective
|
|
1032
|
+
const sysIdPattern = /[a-f0-9]{32}/i;
|
|
1033
|
+
const match = objective.match(sysIdPattern);
|
|
1034
|
+
return match ? match[0] : undefined;
|
|
1035
|
+
}
|
|
1036
|
+
extractCoreProblem(objective) {
|
|
1037
|
+
const objective_lower = objective.toLowerCase();
|
|
1038
|
+
// Analyze patterns to understand underlying need
|
|
1039
|
+
if (objective_lower.includes('widget') || objective_lower.includes('dashboard')) {
|
|
1040
|
+
return 'Users need better access to information or functionality through improved interface';
|
|
1041
|
+
}
|
|
1042
|
+
else if (objective_lower.includes('workflow') || objective_lower.includes('process')) {
|
|
1043
|
+
return 'Business process efficiency and automation needs improvement';
|
|
1044
|
+
}
|
|
1045
|
+
else if (objective_lower.includes('integration') || objective_lower.includes('api')) {
|
|
1046
|
+
return 'Systems need to communicate effectively to eliminate manual work';
|
|
1047
|
+
}
|
|
1048
|
+
else if (objective_lower.includes('report') || objective_lower.includes('analytics')) {
|
|
1049
|
+
return 'Decision makers need better visibility into business performance';
|
|
1050
|
+
}
|
|
1051
|
+
else if (objective_lower.includes('notification') || objective_lower.includes('alert')) {
|
|
1052
|
+
return 'Stakeholders need timely awareness of important events or status changes';
|
|
1053
|
+
}
|
|
1054
|
+
else {
|
|
1055
|
+
return 'Business capability needs enhancement through ServiceNow platform optimization';
|
|
1056
|
+
}
|
|
1057
|
+
}
|
|
1058
|
+
/**
|
|
1059
|
+
* Assess objective complexity
|
|
1060
|
+
*/
|
|
1061
|
+
assessObjectiveComplexity(objective) {
|
|
1062
|
+
let complexity_score = 0;
|
|
1063
|
+
const high_complexity_indicators = ['integration', 'multiple', 'complex', 'enterprise', 'automated', 'workflow'];
|
|
1064
|
+
const medium_complexity_indicators = ['dashboard', 'report', 'widget', 'form', 'approval'];
|
|
1065
|
+
high_complexity_indicators.forEach(indicator => {
|
|
1066
|
+
if (objective.toLowerCase().includes(indicator))
|
|
1067
|
+
complexity_score += 2;
|
|
1068
|
+
});
|
|
1069
|
+
medium_complexity_indicators.forEach(indicator => {
|
|
1070
|
+
if (objective.toLowerCase().includes(indicator))
|
|
1071
|
+
complexity_score += 1;
|
|
1072
|
+
});
|
|
1073
|
+
if (objective.length > 100)
|
|
1074
|
+
complexity_score += 1;
|
|
1075
|
+
if (objective.split(' ').length > 20)
|
|
1076
|
+
complexity_score += 1;
|
|
1077
|
+
if (complexity_score >= 4)
|
|
1078
|
+
return 'high';
|
|
1079
|
+
if (complexity_score >= 2)
|
|
1080
|
+
return 'medium';
|
|
1081
|
+
return 'low';
|
|
1082
|
+
}
|
|
1083
|
+
/**
|
|
1084
|
+
* Assess business impact
|
|
1085
|
+
*/
|
|
1086
|
+
assessBusinessImpact(objective) {
|
|
1087
|
+
const high_impact_keywords = ['critical', 'urgent', 'production', 'enterprise', 'compliance', 'security'];
|
|
1088
|
+
const medium_impact_keywords = ['efficiency', 'automation', 'improvement', 'optimization', 'user experience'];
|
|
1089
|
+
const objective_lower = objective.toLowerCase();
|
|
1090
|
+
if (high_impact_keywords.some(keyword => objective_lower.includes(keyword)))
|
|
1091
|
+
return 'high';
|
|
1092
|
+
if (medium_impact_keywords.some(keyword => objective_lower.includes(keyword)))
|
|
1093
|
+
return 'medium';
|
|
1094
|
+
return 'low';
|
|
1095
|
+
}
|
|
1096
|
+
/**
|
|
1097
|
+
* Identify stakeholders affected by the change
|
|
1098
|
+
*/
|
|
1099
|
+
identifyStakeholders(objective) {
|
|
1100
|
+
const stakeholders = new Set();
|
|
1101
|
+
const objective_lower = objective.toLowerCase();
|
|
1102
|
+
// Default stakeholders for any ServiceNow change
|
|
1103
|
+
stakeholders.add('End Users');
|
|
1104
|
+
stakeholders.add('System Administrators');
|
|
1105
|
+
// Add specific stakeholders based on objective
|
|
1106
|
+
if (objective_lower.includes('approval'))
|
|
1107
|
+
stakeholders.add('Approvers');
|
|
1108
|
+
if (objective_lower.includes('manager'))
|
|
1109
|
+
stakeholders.add('Managers');
|
|
1110
|
+
if (objective_lower.includes('report') || objective_lower.includes('dashboard'))
|
|
1111
|
+
stakeholders.add('Business Analysts');
|
|
1112
|
+
if (objective_lower.includes('integration'))
|
|
1113
|
+
stakeholders.add('IT Operations');
|
|
1114
|
+
if (objective_lower.includes('security') || objective_lower.includes('compliance'))
|
|
1115
|
+
stakeholders.add('Security Team');
|
|
1116
|
+
if (objective_lower.includes('catalog') || objective_lower.includes('service'))
|
|
1117
|
+
stakeholders.add('Service Desk');
|
|
1118
|
+
return Array.from(stakeholders);
|
|
1119
|
+
}
|
|
1120
|
+
/**
|
|
1121
|
+
* Identify hidden requirements not explicitly stated
|
|
1122
|
+
*/
|
|
1123
|
+
identifyHiddenRequirements(objective) {
|
|
1124
|
+
const hiddenReqs = [];
|
|
1125
|
+
const objective_lower = objective.toLowerCase();
|
|
1126
|
+
// Universal hidden requirements
|
|
1127
|
+
hiddenReqs.push('Solution must be maintainable by current team');
|
|
1128
|
+
hiddenReqs.push('Performance must not degrade existing system');
|
|
1129
|
+
hiddenReqs.push('Solution must be scalable for future growth');
|
|
1130
|
+
// Context-specific hidden requirements
|
|
1131
|
+
if (objective_lower.includes('widget') || objective_lower.includes('portal')) {
|
|
1132
|
+
hiddenReqs.push('Must work across all browsers and devices');
|
|
1133
|
+
hiddenReqs.push('Must meet accessibility standards');
|
|
1134
|
+
}
|
|
1135
|
+
if (objective_lower.includes('integration')) {
|
|
1136
|
+
hiddenReqs.push('Must handle integration failures gracefully');
|
|
1137
|
+
hiddenReqs.push('Must maintain data consistency');
|
|
1138
|
+
}
|
|
1139
|
+
if (objective_lower.includes('workflow') || objective_lower.includes('automation')) {
|
|
1140
|
+
hiddenReqs.push('Must handle exceptions and edge cases');
|
|
1141
|
+
hiddenReqs.push('Must provide clear audit trail');
|
|
1142
|
+
}
|
|
1143
|
+
return hiddenReqs;
|
|
1144
|
+
}
|
|
1145
|
+
/**
|
|
1146
|
+
* Define clear success criteria
|
|
1147
|
+
*/
|
|
1148
|
+
defineSuccessCriteria(objective) {
|
|
1149
|
+
const criteria = [];
|
|
1150
|
+
const objective_lower = objective.toLowerCase();
|
|
1151
|
+
// Universal success criteria
|
|
1152
|
+
criteria.push('Solution deployed without system disruption');
|
|
1153
|
+
criteria.push('All stakeholders can use the solution effectively');
|
|
1154
|
+
criteria.push('Performance meets or exceeds baseline requirements');
|
|
1155
|
+
// Specific success criteria based on objective
|
|
1156
|
+
if (objective_lower.includes('widget') || objective_lower.includes('dashboard')) {
|
|
1157
|
+
criteria.push('Users can access information faster than before');
|
|
1158
|
+
criteria.push('User satisfaction with interface is positive');
|
|
1159
|
+
}
|
|
1160
|
+
if (objective_lower.includes('workflow') || objective_lower.includes('automation')) {
|
|
1161
|
+
criteria.push('Process time reduced compared to manual process');
|
|
1162
|
+
criteria.push('Error rate is lower than manual process');
|
|
1163
|
+
}
|
|
1164
|
+
if (objective_lower.includes('integration')) {
|
|
1165
|
+
criteria.push('Data flows correctly between systems');
|
|
1166
|
+
criteria.push('Integration performs within SLA requirements');
|
|
1167
|
+
}
|
|
1168
|
+
return criteria;
|
|
1169
|
+
}
|
|
1170
|
+
/**
|
|
1171
|
+
* Identify technical risks
|
|
1172
|
+
*/
|
|
1173
|
+
identifyTechnicalRisks(objective, analysis) {
|
|
1174
|
+
const risks = [];
|
|
1175
|
+
const objective_lower = objective.toLowerCase();
|
|
1176
|
+
if (objective_lower.includes('integration')) {
|
|
1177
|
+
risks.push({
|
|
1178
|
+
type: 'technical',
|
|
1179
|
+
description: 'Integration points may fail or perform poorly',
|
|
1180
|
+
impact: 'high',
|
|
1181
|
+
likelihood: 'medium',
|
|
1182
|
+
mitigation: 'Implement robust error handling and monitoring'
|
|
1183
|
+
});
|
|
1184
|
+
}
|
|
1185
|
+
if (objective_lower.includes('widget') || objective_lower.includes('custom')) {
|
|
1186
|
+
risks.push({
|
|
1187
|
+
type: 'technical',
|
|
1188
|
+
description: 'Custom code may conflict with platform updates',
|
|
1189
|
+
impact: 'medium',
|
|
1190
|
+
likelihood: 'medium',
|
|
1191
|
+
mitigation: 'Follow platform best practices and test thoroughly'
|
|
1192
|
+
});
|
|
1193
|
+
}
|
|
1194
|
+
if (analysis.complexity === 'high') {
|
|
1195
|
+
risks.push({
|
|
1196
|
+
type: 'technical',
|
|
1197
|
+
description: 'High complexity increases chance of defects',
|
|
1198
|
+
impact: 'high',
|
|
1199
|
+
likelihood: 'high',
|
|
1200
|
+
mitigation: 'Break down into smaller phases with thorough testing'
|
|
1201
|
+
});
|
|
1202
|
+
}
|
|
1203
|
+
return risks;
|
|
1204
|
+
}
|
|
1205
|
+
/**
|
|
1206
|
+
* Identify business risks
|
|
1207
|
+
*/
|
|
1208
|
+
identifyBusinessRisks(objective, analysis) {
|
|
1209
|
+
const risks = [];
|
|
1210
|
+
if (analysis.businessImpact === 'high') {
|
|
1211
|
+
risks.push({
|
|
1212
|
+
type: 'business',
|
|
1213
|
+
description: 'High business impact means high visibility and pressure',
|
|
1214
|
+
impact: 'high',
|
|
1215
|
+
likelihood: 'medium',
|
|
1216
|
+
mitigation: 'Ensure thorough testing and stakeholder communication'
|
|
1217
|
+
});
|
|
1218
|
+
}
|
|
1219
|
+
if (analysis.stakeholders.length > 5) {
|
|
1220
|
+
risks.push({
|
|
1221
|
+
type: 'business',
|
|
1222
|
+
description: 'Many stakeholders increase coordination complexity',
|
|
1223
|
+
impact: 'medium',
|
|
1224
|
+
likelihood: 'high',
|
|
1225
|
+
mitigation: 'Establish clear communication plan and change management'
|
|
1226
|
+
});
|
|
1227
|
+
}
|
|
1228
|
+
return risks;
|
|
1229
|
+
}
|
|
1230
|
+
/**
|
|
1231
|
+
* Identify operational risks
|
|
1232
|
+
*/
|
|
1233
|
+
identifyOperationalRisks(objective, analysis) {
|
|
1234
|
+
const risks = [];
|
|
1235
|
+
const objective_lower = objective.toLowerCase();
|
|
1236
|
+
if (objective_lower.includes('automation') || objective_lower.includes('workflow')) {
|
|
1237
|
+
risks.push({
|
|
1238
|
+
type: 'operational',
|
|
1239
|
+
description: 'Automated processes may fail and require manual intervention',
|
|
1240
|
+
impact: 'medium',
|
|
1241
|
+
likelihood: 'medium',
|
|
1242
|
+
mitigation: 'Build in manual override capabilities and monitoring'
|
|
1243
|
+
});
|
|
1244
|
+
}
|
|
1245
|
+
return risks;
|
|
1246
|
+
}
|
|
1247
|
+
/**
|
|
1248
|
+
* Identify compliance risks
|
|
1249
|
+
*/
|
|
1250
|
+
identifyComplianceRisks(objective, analysis) {
|
|
1251
|
+
const risks = [];
|
|
1252
|
+
const objective_lower = objective.toLowerCase();
|
|
1253
|
+
if (objective_lower.includes('data') || objective_lower.includes('integration')) {
|
|
1254
|
+
risks.push({
|
|
1255
|
+
type: 'compliance',
|
|
1256
|
+
description: 'Data handling may not meet privacy or security requirements',
|
|
1257
|
+
impact: 'high',
|
|
1258
|
+
likelihood: 'low',
|
|
1259
|
+
mitigation: 'Review with security and compliance teams'
|
|
1260
|
+
});
|
|
1261
|
+
}
|
|
1262
|
+
return risks;
|
|
1263
|
+
}
|
|
1264
|
+
/**
|
|
1265
|
+
* Calculate overall risk level
|
|
1266
|
+
*/
|
|
1267
|
+
calculateOverallRisk(risks) {
|
|
1268
|
+
const high_risk_count = risks.filter(r => r.impact === 'high' && r.likelihood === 'high').length;
|
|
1269
|
+
const medium_risk_count = risks.filter(r => (r.impact === 'high' && r.likelihood === 'medium') ||
|
|
1270
|
+
(r.impact === 'medium' && r.likelihood === 'high')).length;
|
|
1271
|
+
if (high_risk_count > 0)
|
|
1272
|
+
return 'high';
|
|
1273
|
+
if (medium_risk_count > 1)
|
|
1274
|
+
return 'high';
|
|
1275
|
+
if (medium_risk_count > 0 || risks.length > 3)
|
|
1276
|
+
return 'medium';
|
|
1277
|
+
return 'low';
|
|
1278
|
+
}
|
|
1279
|
+
/**
|
|
1280
|
+
* Develop mitigation strategies for critical risks
|
|
1281
|
+
*/
|
|
1282
|
+
developMitigationStrategies(criticalRisks) {
|
|
1283
|
+
const strategies = criticalRisks.map(risk => risk.mitigation);
|
|
1284
|
+
// Add general mitigation strategies
|
|
1285
|
+
strategies.push('Implement comprehensive testing at each phase');
|
|
1286
|
+
strategies.push('Establish rollback procedures before deployment');
|
|
1287
|
+
strategies.push('Monitor solution performance post-deployment');
|
|
1288
|
+
return [...new Set(strategies)]; // Remove duplicates
|
|
1289
|
+
}
|
|
1290
|
+
/**
|
|
1291
|
+
* Design solution architecture based on strategic analysis
|
|
1292
|
+
*/
|
|
1293
|
+
async designSolutionArchitecture(problemAnalysis, riskAssessment) {
|
|
1294
|
+
this.logger.info('🏗️ Designing Strategic Solution Architecture...');
|
|
1295
|
+
// Determine optimal approach based on complexity and risks
|
|
1296
|
+
let approach = 'standard';
|
|
1297
|
+
let recommendedAgents = ['researcher', 'widget-creator', 'tester'];
|
|
1298
|
+
if (problemAnalysis.complexity === 'high' || riskAssessment.overallRisk === 'high') {
|
|
1299
|
+
approach = 'phased-implementation';
|
|
1300
|
+
recommendedAgents = ['researcher', 'app-architect', 'widget-creator', 'security-specialist', 'tester'];
|
|
1301
|
+
}
|
|
1302
|
+
if (riskAssessment.criticalRisks.length > 2) {
|
|
1303
|
+
approach = 'risk-first-architecture';
|
|
1304
|
+
recommendedAgents.unshift('security-specialist');
|
|
1305
|
+
}
|
|
1306
|
+
// Add specialized agents based on problem domain
|
|
1307
|
+
const objective_lower = problemAnalysis.coreProblem.toLowerCase();
|
|
1308
|
+
if (objective_lower.includes('integration')) {
|
|
1309
|
+
recommendedAgents.push('integration-specialist');
|
|
1310
|
+
}
|
|
1311
|
+
if (objective_lower.includes('workflow') || objective_lower.includes('process')) {
|
|
1312
|
+
recommendedAgents.push('flow-builder');
|
|
1313
|
+
}
|
|
1314
|
+
if (objective_lower.includes('performance')) {
|
|
1315
|
+
recommendedAgents.push('performance-specialist');
|
|
1316
|
+
}
|
|
1317
|
+
return {
|
|
1318
|
+
approach,
|
|
1319
|
+
recommendedAgents: [...new Set(recommendedAgents)], // Remove duplicates
|
|
1320
|
+
implementationSteps: this.generateImplementationSteps(approach, problemAnalysis),
|
|
1321
|
+
qualityGates: this.defineQualityGates(problemAnalysis, riskAssessment),
|
|
1322
|
+
monitoringStrategy: this.defineMonitoringStrategy(problemAnalysis)
|
|
1323
|
+
};
|
|
1324
|
+
}
|
|
1325
|
+
/**
|
|
1326
|
+
* Generate implementation steps based on approach
|
|
1327
|
+
*/
|
|
1328
|
+
generateImplementationSteps(approach, problemAnalysis) {
|
|
1329
|
+
const baseSteps = [
|
|
1330
|
+
'Validate requirements with stakeholders',
|
|
1331
|
+
'Create proof of concept',
|
|
1332
|
+
'Implement core functionality',
|
|
1333
|
+
'Conduct security review',
|
|
1334
|
+
'Perform comprehensive testing',
|
|
1335
|
+
'Deploy with monitoring'
|
|
1336
|
+
];
|
|
1337
|
+
if (approach === 'phased-implementation') {
|
|
1338
|
+
return [
|
|
1339
|
+
'Phase 1: Research and architecture design',
|
|
1340
|
+
'Phase 2: Build minimal viable solution',
|
|
1341
|
+
'Phase 3: Add advanced features',
|
|
1342
|
+
'Phase 4: Performance optimization',
|
|
1343
|
+
'Phase 5: Full deployment and monitoring'
|
|
1344
|
+
];
|
|
1345
|
+
}
|
|
1346
|
+
else if (approach === 'risk-first-architecture') {
|
|
1347
|
+
return [
|
|
1348
|
+
'Risk mitigation planning',
|
|
1349
|
+
'Security architecture review',
|
|
1350
|
+
...baseSteps,
|
|
1351
|
+
'Post-deployment risk validation'
|
|
1352
|
+
];
|
|
1353
|
+
}
|
|
1354
|
+
return baseSteps;
|
|
1355
|
+
}
|
|
1356
|
+
/**
|
|
1357
|
+
* Define quality gates based on analysis
|
|
1358
|
+
*/
|
|
1359
|
+
defineQualityGates(problemAnalysis, riskAssessment) {
|
|
1360
|
+
const gates = [
|
|
1361
|
+
'Requirements validation complete',
|
|
1362
|
+
'Architecture review passed',
|
|
1363
|
+
'Code review completed',
|
|
1364
|
+
'Security scan passed',
|
|
1365
|
+
'Performance benchmarks met'
|
|
1366
|
+
];
|
|
1367
|
+
if (riskAssessment.overallRisk === 'high') {
|
|
1368
|
+
gates.unshift('Risk mitigation plan approved');
|
|
1369
|
+
gates.push('Rollback procedures tested');
|
|
1370
|
+
}
|
|
1371
|
+
if (problemAnalysis.businessImpact === 'high') {
|
|
1372
|
+
gates.push('Stakeholder sign-off obtained');
|
|
1373
|
+
gates.push('Production readiness review passed');
|
|
1374
|
+
}
|
|
1375
|
+
return gates;
|
|
1376
|
+
}
|
|
1377
|
+
/**
|
|
1378
|
+
* Define monitoring strategy
|
|
1379
|
+
*/
|
|
1380
|
+
defineMonitoringStrategy(problemAnalysis) {
|
|
1381
|
+
return {
|
|
1382
|
+
metrics: [
|
|
1383
|
+
'System performance indicators',
|
|
1384
|
+
'User experience metrics',
|
|
1385
|
+
'Error rates and failure patterns',
|
|
1386
|
+
'Business impact measurements'
|
|
1387
|
+
],
|
|
1388
|
+
alerting: [
|
|
1389
|
+
'Performance degradation alerts',
|
|
1390
|
+
'Error threshold alerts',
|
|
1391
|
+
'User satisfaction alerts'
|
|
1392
|
+
],
|
|
1393
|
+
reporting: [
|
|
1394
|
+
'Daily operational health reports',
|
|
1395
|
+
'Weekly business impact reports',
|
|
1396
|
+
'Monthly optimization recommendations'
|
|
1397
|
+
]
|
|
1398
|
+
};
|
|
1399
|
+
}
|
|
948
1400
|
}
|
|
949
|
-
|
|
950
|
-
this.memory.close();
|
|
1401
|
+
exports.ServiceNowQueen = ServiceNowQueen;
|
|
951
1402
|
//# sourceMappingURL=servicenow-queen.js.map
|