snow-flow 2.0.2 → 2.0.4
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/mcp-config.json → .mcp.json} +13 -12
- package/.releaserc.json +47 -0
- package/README.md +48 -1
- package/package.json +1 -1
- package/.claude/claude-settings.json +0 -15
- package/.claude/commands/analysis/README.md +0 -9
- package/.claude/commands/automation/README.md +0 -9
- package/.claude/commands/github/README.md +0 -11
- package/.claude/commands/helpers/standard-checkpoint-hooks.sh +0 -179
- package/.claude/commands/hooks/README.md +0 -11
- package/.claude/commands/monitoring/README.md +0 -9
- package/.claude/commands/optimization/README.md +0 -9
- package/.claude/commands/training/README.md +0 -9
- package/.claude/commands/workflows/README.md +0 -9
- package/.claude/config.json +0 -36
- package/.claude/helpers/github-setup.sh +0 -28
- package/.claude/helpers/quick-start.sh +0 -19
- package/.claude/helpers/setup-mcp.sh +0 -18
- package/.claude/settings.json +0 -114
- package/.claude/settings.local.json +0 -33
- package/.claude-flow/metrics/agent-metrics.json +0 -1
- package/.claude-flow/metrics/performance.json +0 -9
- package/.claude-flow/metrics/system-metrics.json +0 -15986
- package/.claude-flow/metrics/task-metrics.json +0 -10
- package/.roo/README.md +0 -402
- package/.roo/mcp-list.txt +0 -257
- package/.roo/mcp.json +0 -32
- package/.roo/workflows/basic-tdd.json +0 -32
- package/.roomodes +0 -201
- package/CLAUDE.md +0 -393
- package/bin/snow-flow.js +0 -3
- package/dist/cli.js.bak +0 -2052
- package/dist/config/snow-flow-config.d.ts +0 -1492
- package/dist/config/snow-flow-config.js +0 -938
- package/scripts/create-env.js +0 -91
- package/scripts/postinstall.js +0 -30
- package/scripts/register-mcp-servers.js +0 -210
- package/scripts/reset-mcp-servers.js +0 -246
- package/scripts/setup-mcp.js +0 -106
- package/scripts/update-version.js +0 -31
- package/src/agents/README.md +0 -192
- package/src/agents/base-agent.ts +0 -251
- package/src/agents/coordinator.ts +0 -971
- package/src/agents/index.ts +0 -18
- package/src/agents/queen-403-handler.ts +0 -230
- package/src/agents/queen-agent.ts +0 -1399
- package/src/agents/script-writer-agent.ts +0 -769
- package/src/agents/security-agent.ts +0 -726
- package/src/agents/widget-creator-agent.ts +0 -568
- package/src/api/error-handling.ts +0 -1758
- package/src/api/natural-language-mapper.ts +0 -630
- package/src/api/performance-optimizer.ts +0 -891
- package/src/api/transaction-manager.ts +0 -754
- package/src/cli/deploy-artifact.ts +0 -304
- package/src/cli/snow-flow-cli-integration.ts +0 -434
- package/src/cli.ts +0 -4455
- package/src/cli.ts.bak +0 -5616
- package/src/compliance/advanced-compliance-system.ts +0 -1268
- package/src/compliance/index.ts +0 -19
- package/src/config/snow-flow-config.ts +0 -1019
- package/src/documentation/index.ts +0 -16
- package/src/documentation/self-documenting-system.ts +0 -1421
- package/src/dynamic-version.ts +0 -44
- package/src/healing/index.ts +0 -20
- package/src/healing/self-healing-system.ts +0 -1435
- package/src/health/README.md +0 -161
- package/src/health/system-health.ts +0 -995
- package/src/index.ts +0 -60
- package/src/intelligence/acl-analyzer.ts +0 -377
- package/src/intelligence/auto-resolution-engine.ts +0 -643
- package/src/intelligence/gap-analysis-engine.ts +0 -488
- package/src/intelligence/manual-instructions-generator.ts +0 -744
- package/src/intelligence/mcp-coverage-analyzer.ts +0 -708
- package/src/intelligence/multi-pass-requirements-analyzer.ts +0 -603
- package/src/intelligence/performance-recommendations-engine.ts +0 -1223
- package/src/intelligence/requirements-analyzer.ts +0 -1148
- package/src/intelligence/task-analyzer.ts +0 -628
- package/src/managers/scope-manager.ts +0 -555
- package/src/mcp/advanced/servicenow-advanced-features-mcp.ts +0 -16110
- package/src/mcp/base-mcp-server.ts +0 -660
- package/src/mcp/http-transport-wrapper.ts +0 -426
- package/src/mcp/service-discovery-client.ts +0 -312
- package/src/mcp/servicenow-automation-mcp-refactored.ts +0 -678
- package/src/mcp/servicenow-automation-mcp.ts +0 -838
- package/src/mcp/servicenow-deployment-mcp-refactored.ts +0 -1292
- package/src/mcp/servicenow-deployment-mcp.ts +0 -7244
- package/src/mcp/servicenow-graph-memory-mcp-refactored.ts +0 -721
- package/src/mcp/servicenow-graph-memory-mcp.ts +0 -832
- package/src/mcp/servicenow-integration-mcp-refactored.ts +0 -655
- package/src/mcp/servicenow-integration-mcp.ts +0 -819
- package/src/mcp/servicenow-intelligent-mcp-refactored.ts +0 -977
- package/src/mcp/servicenow-intelligent-mcp.ts +0 -4638
- package/src/mcp/servicenow-mcp-server.ts +0 -728
- package/src/mcp/servicenow-memory-mcp.ts +0 -474
- package/src/mcp/servicenow-operations-mcp-refactored.ts +0 -1995
- package/src/mcp/servicenow-operations-mcp.ts +0 -3384
- package/src/mcp/servicenow-platform-development-mcp-refactored.ts +0 -611
- package/src/mcp/servicenow-platform-development-mcp.ts +0 -970
- package/src/mcp/servicenow-progressive-indexer.ts +0 -370
- package/src/mcp/servicenow-reporting-analytics-mcp-refactored.ts +0 -695
- package/src/mcp/servicenow-reporting-analytics-mcp.ts +0 -1123
- package/src/mcp/servicenow-security-compliance-mcp-refactored.ts +0 -642
- package/src/mcp/servicenow-security-compliance-mcp.ts +0 -1157
- package/src/mcp/servicenow-update-set-mcp-refactored.ts +0 -751
- package/src/mcp/servicenow-update-set-mcp.ts +0 -811
- package/src/mcp/shared/agent-context-provider.ts +0 -365
- package/src/mcp/shared/base-mcp-server.ts +0 -2463
- package/src/mcp/shared/mcp-memory-manager.ts +0 -540
- package/src/mcp/shared/mcp-resource-manager.ts +0 -367
- package/src/mcp/snow-flow-mcp.ts +0 -911
- package/src/mcp/start-all-mcp-servers.ts +0 -102
- package/src/mcp/start-servicenow-mcp.ts +0 -67
- package/src/monitoring/enhanced-monitoring-system.ts +0 -1345
- package/src/monitoring/performance-tracker.ts +0 -777
- package/src/optimization/cost-optimization-engine.ts +0 -1125
- package/src/optimization/index.ts +0 -10
- package/src/queen/README.md +0 -403
- package/src/queen/agent-factory.ts +0 -574
- package/src/queen/index.ts +0 -94
- package/src/queen/mcp-execution-bridge.ts +0 -681
- package/src/queen/neural-learning.ts +0 -319
- package/src/queen/parallel-agent-engine.ts +0 -848
- package/src/queen/queen-memory-system.ts +0 -490
- package/src/queen/queen-memory.ts +0 -456
- package/src/queen/servicenow-queen.ts +0 -1029
- package/src/queen/types.ts +0 -87
- package/src/rollback/smart-rollback-system.ts +0 -866
- package/src/schemas/deployment.schema.json +0 -58
- package/src/schemas/flow.schema.json +0 -79
- package/src/schemas/widget.schema.json +0 -72
- package/src/snow-flow-system.ts +0 -541
- package/src/sparc/sparc-help.ts +0 -49
- package/src/sparc/team-sparc.ts +0 -88
- package/src/strategies/global-scope-strategy.ts +0 -736
- package/src/templates/base/application.template.json +0 -45
- package/src/templates/base/business_rule.template.json +0 -33
- package/src/templates/base/script_include.template.json +0 -18
- package/src/templates/base/table.template.json +0 -64
- package/src/templates/base/widget.template.json +0 -25
- package/src/templates/patterns/composite.incident-management.template.json +0 -140
- package/src/templates/patterns/widget.dashboard.template.json +0 -238
- package/src/templates/patterns/widget.datatable.template.json +0 -292
- package/src/testing/integration-test-suite.ts +0 -1276
- package/src/types/index.ts +0 -183
- package/src/types/neo4j-driver.d.ts +0 -23
- package/src/types/servicenow.types.ts +0 -307
- package/src/types/snow-flow.types.ts +0 -186
- package/src/types/todo.types.ts +0 -70
- package/src/utils/action-type-cache.ts +0 -286
- package/src/utils/agent-detector.ts +0 -573
- package/src/utils/artifact-tracker.ts +0 -379
- package/src/utils/dependency-detector.ts +0 -233
- package/src/utils/deployment-metadata-handler.ts +0 -518
- package/src/utils/error-recovery.ts +0 -680
- package/src/utils/logger.ts +0 -60
- package/src/utils/mcp-auth-middleware.ts +0 -262
- package/src/utils/mcp-config-manager.ts +0 -270
- package/src/utils/mcp-server-manager.ts +0 -446
- package/src/utils/mcp-tool-registry.ts +0 -298
- package/src/utils/migrate-snow-flow.ts +0 -98
- package/src/utils/oauth-html-templates.ts +0 -188
- package/src/utils/scope-utils.ts +0 -443
- package/src/utils/servicenow-client.ts +0 -3321
- package/src/utils/servicenow-id-generator.ts +0 -181
- package/src/utils/snow-memory-manager.ts +0 -605
- package/src/utils/snow-oauth.ts +0 -797
- package/src/utils/template-engine.ts +0 -463
- package/src/utils/theme-manager.ts +0 -295
- package/src/utils/unified-auth-store.ts +0 -222
- package/src/utils/update-set-importer.ts +0 -422
- package/src/utils/update-set-xml-packager.ts +0 -371
- package/src/utils/widget-template-generator.ts +0 -1744
- package/src/version.ts +0 -1950
|
@@ -1,555 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Scope Manager for ServiceNow Artifact Deployment
|
|
3
|
-
*
|
|
4
|
-
* Centralized management of deployment scopes, providing intelligent
|
|
5
|
-
* scope selection and management capabilities.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { GlobalScopeStrategy, ScopeType, ScopeConfiguration, GlobalScopeDeploymentResult } from '../strategies/global-scope-strategy.js';
|
|
9
|
-
import { ServiceNowClient } from '../utils/servicenow-client.js';
|
|
10
|
-
import { Logger } from '../utils/logger.js';
|
|
11
|
-
|
|
12
|
-
export interface ScopeManagerOptions {
|
|
13
|
-
defaultScope?: ScopeType;
|
|
14
|
-
allowFallback?: boolean;
|
|
15
|
-
validatePermissions?: boolean;
|
|
16
|
-
enableMigration?: boolean;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export interface ScopeDecision {
|
|
20
|
-
selectedScope: ScopeType;
|
|
21
|
-
confidence: number;
|
|
22
|
-
rationale: string;
|
|
23
|
-
fallbackScope?: ScopeType;
|
|
24
|
-
validationResult: any;
|
|
25
|
-
recommendations: string[];
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export interface DeploymentContext {
|
|
29
|
-
artifactType: string;
|
|
30
|
-
artifactData: any;
|
|
31
|
-
userPreferences?: ScopeConfiguration;
|
|
32
|
-
projectScope?: ScopeType;
|
|
33
|
-
environmentType?: 'development' | 'testing' | 'production';
|
|
34
|
-
complianceRequirements?: string[];
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export class ScopeManager {
|
|
38
|
-
private strategy: GlobalScopeStrategy;
|
|
39
|
-
private client: ServiceNowClient;
|
|
40
|
-
private logger: Logger;
|
|
41
|
-
private options: ScopeManagerOptions;
|
|
42
|
-
private scopeCache: Map<string, ScopeDecision> = new Map();
|
|
43
|
-
|
|
44
|
-
constructor(options: ScopeManagerOptions = {}) {
|
|
45
|
-
this.strategy = new GlobalScopeStrategy();
|
|
46
|
-
this.client = new ServiceNowClient();
|
|
47
|
-
this.logger = new Logger('ScopeManager');
|
|
48
|
-
this.options = {
|
|
49
|
-
defaultScope: ScopeType.GLOBAL,
|
|
50
|
-
allowFallback: true,
|
|
51
|
-
validatePermissions: true,
|
|
52
|
-
enableMigration: false,
|
|
53
|
-
...options
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
this.logger.info('ScopeManager initialized', { options: this.options });
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Make intelligent scope decision based on context
|
|
61
|
-
*/
|
|
62
|
-
async makeScopeDecision(context: DeploymentContext): Promise<ScopeDecision> {
|
|
63
|
-
const cacheKey = this.generateCacheKey(context);
|
|
64
|
-
|
|
65
|
-
// Check cache first
|
|
66
|
-
if (this.scopeCache.has(cacheKey)) {
|
|
67
|
-
const cached = this.scopeCache.get(cacheKey)!;
|
|
68
|
-
this.logger.info('Using cached scope decision', { selectedScope: cached.selectedScope });
|
|
69
|
-
return cached;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
this.logger.info('Making scope decision', {
|
|
73
|
-
artifactType: context.artifactType,
|
|
74
|
-
artifactName: context.artifactData.name,
|
|
75
|
-
environmentType: context.environmentType
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
// Step 1: Analyze artifact requirements
|
|
79
|
-
const scopeConfig = await this.strategy.analyzeScopeRequirements(
|
|
80
|
-
context.artifactType,
|
|
81
|
-
context.artifactData
|
|
82
|
-
);
|
|
83
|
-
|
|
84
|
-
// Step 2: Apply user preferences and project scope
|
|
85
|
-
const adjustedConfig = this.applyUserPreferences(scopeConfig, context);
|
|
86
|
-
|
|
87
|
-
// Step 3: Validate permissions if enabled
|
|
88
|
-
let validationResult: any = { isValid: true, issues: [], warnings: [] };
|
|
89
|
-
if (this.options.validatePermissions) {
|
|
90
|
-
validationResult = await this.strategy.validateScopePermissions(adjustedConfig);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
// Step 4: Make final decision
|
|
94
|
-
const decision = this.makeFinalDecision(adjustedConfig, validationResult, context);
|
|
95
|
-
|
|
96
|
-
// Step 5: Cache the decision
|
|
97
|
-
this.scopeCache.set(cacheKey, decision);
|
|
98
|
-
|
|
99
|
-
this.logger.info('Scope decision made', {
|
|
100
|
-
selectedScope: decision.selectedScope,
|
|
101
|
-
confidence: decision.confidence,
|
|
102
|
-
rationale: decision.rationale
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
return decision;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* Deploy artifact using intelligent scope management
|
|
110
|
-
*/
|
|
111
|
-
async deployWithScopeManagement(context: DeploymentContext): Promise<GlobalScopeDeploymentResult> {
|
|
112
|
-
this.logger.info('Starting scope-managed deployment', {
|
|
113
|
-
artifactType: context.artifactType,
|
|
114
|
-
artifactName: context.artifactData.name
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
// Make scope decision
|
|
118
|
-
const decision = await this.makeScopeDecision(context);
|
|
119
|
-
|
|
120
|
-
// Prepare deployment configuration
|
|
121
|
-
const deploymentConfig: ScopeConfiguration = {
|
|
122
|
-
type: decision.selectedScope,
|
|
123
|
-
fallbackToGlobal: this.options.allowFallback && decision.fallbackScope !== undefined,
|
|
124
|
-
permissions: decision.validationResult.permissions || []
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
// Add environment-specific configurations
|
|
128
|
-
if (context.environmentType === 'production') {
|
|
129
|
-
deploymentConfig.permissions?.push('production_deployment');
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
// Add compliance requirements
|
|
133
|
-
if (context.complianceRequirements) {
|
|
134
|
-
deploymentConfig.permissions?.push(...context.complianceRequirements);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
// Execute deployment
|
|
138
|
-
const result = await this.strategy.deployWithGlobalScope(
|
|
139
|
-
context.artifactType,
|
|
140
|
-
context.artifactData,
|
|
141
|
-
deploymentConfig
|
|
142
|
-
);
|
|
143
|
-
|
|
144
|
-
// Log deployment outcome
|
|
145
|
-
this.logger.info('Scope-managed deployment completed', {
|
|
146
|
-
success: result.success,
|
|
147
|
-
actualScope: result.scope,
|
|
148
|
-
fallbackApplied: result.fallbackApplied
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
return result;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
/**
|
|
155
|
-
* Migrate existing artifacts to optimal scope
|
|
156
|
-
*/
|
|
157
|
-
async migrateArtifactsToOptimalScope(artifacts: any[]): Promise<any> {
|
|
158
|
-
if (!this.options.enableMigration) {
|
|
159
|
-
throw new Error('Migration is not enabled in scope manager options');
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
this.logger.info('Starting artifact migration', { count: artifacts.length });
|
|
163
|
-
|
|
164
|
-
const migrationResults = {
|
|
165
|
-
totalArtifacts: artifacts.length,
|
|
166
|
-
successful: 0,
|
|
167
|
-
failed: 0,
|
|
168
|
-
skipped: 0,
|
|
169
|
-
details: [] as any[]
|
|
170
|
-
};
|
|
171
|
-
|
|
172
|
-
for (const artifact of artifacts) {
|
|
173
|
-
try {
|
|
174
|
-
const context: DeploymentContext = {
|
|
175
|
-
artifactType: artifact.sys_class_name || artifact.type,
|
|
176
|
-
artifactData: artifact,
|
|
177
|
-
environmentType: 'development' // Safe default for migration
|
|
178
|
-
};
|
|
179
|
-
|
|
180
|
-
const decision = await this.makeScopeDecision(context);
|
|
181
|
-
|
|
182
|
-
// Only migrate if the optimal scope is different from current
|
|
183
|
-
if (this.shouldMigrateArtifact(artifact, decision)) {
|
|
184
|
-
const migrationResult = await this.migrateArtifact(artifact, decision);
|
|
185
|
-
migrationResults.details.push(migrationResult);
|
|
186
|
-
|
|
187
|
-
if (migrationResult.success) {
|
|
188
|
-
migrationResults.successful++;
|
|
189
|
-
} else {
|
|
190
|
-
migrationResults.failed++;
|
|
191
|
-
}
|
|
192
|
-
} else {
|
|
193
|
-
migrationResults.skipped++;
|
|
194
|
-
migrationResults.details.push({
|
|
195
|
-
artifactId: artifact.sys_id,
|
|
196
|
-
name: artifact.name,
|
|
197
|
-
currentScope: artifact.sys_scope,
|
|
198
|
-
recommendedScope: decision.selectedScope,
|
|
199
|
-
action: 'skipped',
|
|
200
|
-
reason: 'Already in optimal scope'
|
|
201
|
-
});
|
|
202
|
-
}
|
|
203
|
-
} catch (error) {
|
|
204
|
-
migrationResults.failed++;
|
|
205
|
-
migrationResults.details.push({
|
|
206
|
-
artifactId: artifact.sys_id,
|
|
207
|
-
name: artifact.name,
|
|
208
|
-
action: 'failed',
|
|
209
|
-
error: error instanceof Error ? error.message : String(error)
|
|
210
|
-
});
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
this.logger.info('Migration completed', {
|
|
215
|
-
successful: migrationResults.successful,
|
|
216
|
-
failed: migrationResults.failed,
|
|
217
|
-
skipped: migrationResults.skipped
|
|
218
|
-
});
|
|
219
|
-
|
|
220
|
-
return migrationResults;
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
/**
|
|
224
|
-
* Get scope recommendations for a project
|
|
225
|
-
*/
|
|
226
|
-
async getProjectScopeRecommendations(projectArtifacts: any[]): Promise<any> {
|
|
227
|
-
this.logger.info('Generating project scope recommendations', {
|
|
228
|
-
artifactCount: projectArtifacts.length
|
|
229
|
-
});
|
|
230
|
-
|
|
231
|
-
const recommendations = {
|
|
232
|
-
overallScope: ScopeType.GLOBAL,
|
|
233
|
-
confidence: 0,
|
|
234
|
-
artifactBreakdown: {
|
|
235
|
-
global: 0,
|
|
236
|
-
application: 0,
|
|
237
|
-
mixed: 0
|
|
238
|
-
},
|
|
239
|
-
recommendations: [] as string[],
|
|
240
|
-
risks: [] as string[],
|
|
241
|
-
benefits: [] as string[]
|
|
242
|
-
};
|
|
243
|
-
|
|
244
|
-
const decisions: ScopeDecision[] = [];
|
|
245
|
-
|
|
246
|
-
// Analyze each artifact
|
|
247
|
-
for (const artifact of projectArtifacts) {
|
|
248
|
-
const context: DeploymentContext = {
|
|
249
|
-
artifactType: artifact.sys_class_name || artifact.type,
|
|
250
|
-
artifactData: artifact
|
|
251
|
-
};
|
|
252
|
-
|
|
253
|
-
const decision = await this.makeScopeDecision(context);
|
|
254
|
-
decisions.push(decision);
|
|
255
|
-
|
|
256
|
-
if (decision.selectedScope === ScopeType.GLOBAL) {
|
|
257
|
-
recommendations.artifactBreakdown.global++;
|
|
258
|
-
} else if (decision.selectedScope === ScopeType.APPLICATION) {
|
|
259
|
-
recommendations.artifactBreakdown.application++;
|
|
260
|
-
} else {
|
|
261
|
-
recommendations.artifactBreakdown.mixed++;
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
// Calculate overall recommendation
|
|
266
|
-
const globalRatio = recommendations.artifactBreakdown.global / projectArtifacts.length;
|
|
267
|
-
const applicationRatio = recommendations.artifactBreakdown.application / projectArtifacts.length;
|
|
268
|
-
|
|
269
|
-
if (globalRatio > 0.6) {
|
|
270
|
-
recommendations.overallScope = ScopeType.GLOBAL;
|
|
271
|
-
recommendations.confidence = globalRatio;
|
|
272
|
-
recommendations.recommendations.push('Deploy entire project to global scope for consistency');
|
|
273
|
-
recommendations.benefits.push('Simplified deployment and maintenance');
|
|
274
|
-
recommendations.benefits.push('Better cross-application integration');
|
|
275
|
-
} else if (applicationRatio > 0.6) {
|
|
276
|
-
recommendations.overallScope = ScopeType.APPLICATION;
|
|
277
|
-
recommendations.confidence = applicationRatio;
|
|
278
|
-
recommendations.recommendations.push('Deploy project to dedicated application scope');
|
|
279
|
-
recommendations.benefits.push('Better isolation and security');
|
|
280
|
-
recommendations.benefits.push('Easier application lifecycle management');
|
|
281
|
-
} else {
|
|
282
|
-
recommendations.overallScope = ScopeType.AUTO;
|
|
283
|
-
recommendations.confidence = 0.5;
|
|
284
|
-
recommendations.recommendations.push('Use mixed scope strategy - deploy artifacts to optimal individual scopes');
|
|
285
|
-
recommendations.risks.push('Mixed scope may complicate maintenance');
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
// Add specific recommendations
|
|
289
|
-
if (recommendations.artifactBreakdown.global > 0) {
|
|
290
|
-
recommendations.recommendations.push('Ensure global scope permissions are available');
|
|
291
|
-
}
|
|
292
|
-
if (recommendations.artifactBreakdown.application > 0) {
|
|
293
|
-
recommendations.recommendations.push('Consider creating dedicated application scope');
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
return recommendations;
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
/**
|
|
300
|
-
* Validate scope configuration
|
|
301
|
-
*/
|
|
302
|
-
async validateScopeConfiguration(config: ScopeConfiguration): Promise<any> {
|
|
303
|
-
this.logger.info('Validating scope configuration', { type: config.type });
|
|
304
|
-
|
|
305
|
-
const validation = {
|
|
306
|
-
isValid: true,
|
|
307
|
-
issues: [] as string[],
|
|
308
|
-
warnings: [] as string[],
|
|
309
|
-
recommendations: [] as string[]
|
|
310
|
-
};
|
|
311
|
-
|
|
312
|
-
// Validate scope type
|
|
313
|
-
if (!Object.values(ScopeType).includes(config.type)) {
|
|
314
|
-
validation.isValid = false;
|
|
315
|
-
validation.issues.push(`Invalid scope type: ${config.type}`);
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
// Validate application scope requirements
|
|
319
|
-
if (config.type === ScopeType.APPLICATION) {
|
|
320
|
-
if (!config.applicationId && !config.applicationName) {
|
|
321
|
-
validation.warnings.push('Application scope specified but no application ID or name provided');
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
// Validate permissions
|
|
326
|
-
if (config.permissions && config.permissions.length > 0) {
|
|
327
|
-
const permissionValidation = await this.validatePermissions(config.permissions);
|
|
328
|
-
if (!permissionValidation.isValid) {
|
|
329
|
-
validation.isValid = false;
|
|
330
|
-
validation.issues.push(...permissionValidation.issues);
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
// Validate global domain
|
|
335
|
-
if (config.type === ScopeType.GLOBAL && config.globalDomain !== 'global') {
|
|
336
|
-
validation.warnings.push('Global scope should use "global" domain');
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
return validation;
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
/**
|
|
343
|
-
* Clear scope cache
|
|
344
|
-
*/
|
|
345
|
-
clearScopeCache(): void {
|
|
346
|
-
this.scopeCache.clear();
|
|
347
|
-
this.logger.info('Scope cache cleared');
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
/**
|
|
351
|
-
* Get scope statistics
|
|
352
|
-
*/
|
|
353
|
-
getScopeStatistics(): any {
|
|
354
|
-
const stats = {
|
|
355
|
-
cacheSize: this.scopeCache.size,
|
|
356
|
-
scopeDistribution: {
|
|
357
|
-
global: 0,
|
|
358
|
-
application: 0,
|
|
359
|
-
auto: 0
|
|
360
|
-
},
|
|
361
|
-
averageConfidence: 0
|
|
362
|
-
};
|
|
363
|
-
|
|
364
|
-
let totalConfidence = 0;
|
|
365
|
-
for (const decision of this.scopeCache.values()) {
|
|
366
|
-
totalConfidence += decision.confidence;
|
|
367
|
-
|
|
368
|
-
if (decision.selectedScope === ScopeType.GLOBAL) {
|
|
369
|
-
stats.scopeDistribution.global++;
|
|
370
|
-
} else if (decision.selectedScope === ScopeType.APPLICATION) {
|
|
371
|
-
stats.scopeDistribution.application++;
|
|
372
|
-
} else {
|
|
373
|
-
stats.scopeDistribution.auto++;
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
stats.averageConfidence = this.scopeCache.size > 0 ? totalConfidence / this.scopeCache.size : 0;
|
|
378
|
-
|
|
379
|
-
return stats;
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
/**
|
|
383
|
-
* Private helper methods
|
|
384
|
-
*/
|
|
385
|
-
|
|
386
|
-
private generateCacheKey(context: DeploymentContext): string {
|
|
387
|
-
return `${context.artifactType}:${context.artifactData.name}:${context.environmentType || 'default'}`;
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
private applyUserPreferences(config: ScopeConfiguration, context: DeploymentContext): ScopeConfiguration {
|
|
391
|
-
if (!context.userPreferences) {
|
|
392
|
-
return config;
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
// Override with user preferences
|
|
396
|
-
return {
|
|
397
|
-
...config,
|
|
398
|
-
...context.userPreferences
|
|
399
|
-
};
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
private makeFinalDecision(
|
|
403
|
-
config: ScopeConfiguration,
|
|
404
|
-
validation: any,
|
|
405
|
-
context: DeploymentContext
|
|
406
|
-
): ScopeDecision {
|
|
407
|
-
let selectedScope = config.type;
|
|
408
|
-
let confidence = 0.8;
|
|
409
|
-
let rationale = 'Based on artifact _analysis';
|
|
410
|
-
let fallbackScope: ScopeType | undefined;
|
|
411
|
-
|
|
412
|
-
// Apply validation results
|
|
413
|
-
if (!validation.isValid) {
|
|
414
|
-
if (validation.canCreateGlobal && config.type === ScopeType.APPLICATION) {
|
|
415
|
-
selectedScope = ScopeType.GLOBAL;
|
|
416
|
-
fallbackScope = ScopeType.APPLICATION;
|
|
417
|
-
confidence = 0.6;
|
|
418
|
-
rationale = 'Fallback to global scope due to permission issues';
|
|
419
|
-
} else if (validation.canCreateScoped && config.type === ScopeType.GLOBAL) {
|
|
420
|
-
selectedScope = ScopeType.APPLICATION;
|
|
421
|
-
fallbackScope = ScopeType.GLOBAL;
|
|
422
|
-
confidence = 0.6;
|
|
423
|
-
rationale = 'Fallback to application scope due to permission issues';
|
|
424
|
-
} else {
|
|
425
|
-
confidence = 0.3;
|
|
426
|
-
rationale = 'Limited options due to permission constraints';
|
|
427
|
-
}
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
// Apply environment-specific rules
|
|
431
|
-
if (context.environmentType === 'production') {
|
|
432
|
-
// Production deployments prefer global scope for stability
|
|
433
|
-
if (selectedScope === ScopeType.APPLICATION && validation.canCreateGlobal) {
|
|
434
|
-
selectedScope = ScopeType.GLOBAL;
|
|
435
|
-
confidence = Math.max(confidence, 0.7);
|
|
436
|
-
rationale += ' (production environment preference)';
|
|
437
|
-
}
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
// Apply project scope preferences
|
|
441
|
-
if (context.projectScope) {
|
|
442
|
-
if (context.projectScope === ScopeType.GLOBAL && validation.canCreateGlobal) {
|
|
443
|
-
selectedScope = ScopeType.GLOBAL;
|
|
444
|
-
confidence = Math.max(confidence, 0.8);
|
|
445
|
-
rationale += ' (project scope preference)';
|
|
446
|
-
} else if (context.projectScope === ScopeType.APPLICATION && validation.canCreateScoped) {
|
|
447
|
-
selectedScope = ScopeType.APPLICATION;
|
|
448
|
-
confidence = Math.max(confidence, 0.8);
|
|
449
|
-
rationale += ' (project scope preference)';
|
|
450
|
-
}
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
const recommendations: string[] = [];
|
|
454
|
-
|
|
455
|
-
// Generate recommendations
|
|
456
|
-
if (confidence < 0.5) {
|
|
457
|
-
recommendations.push('Consider reviewing permissions or scope configuration');
|
|
458
|
-
}
|
|
459
|
-
if (fallbackScope) {
|
|
460
|
-
recommendations.push(`Consider ${fallbackScope} scope as alternative`);
|
|
461
|
-
}
|
|
462
|
-
if (validation.warnings && validation.warnings.length > 0) {
|
|
463
|
-
recommendations.push(...validation.warnings);
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
return {
|
|
467
|
-
selectedScope,
|
|
468
|
-
confidence,
|
|
469
|
-
rationale,
|
|
470
|
-
fallbackScope,
|
|
471
|
-
validationResult: validation,
|
|
472
|
-
recommendations
|
|
473
|
-
};
|
|
474
|
-
}
|
|
475
|
-
|
|
476
|
-
private shouldMigrateArtifact(artifact: any, decision: ScopeDecision): boolean {
|
|
477
|
-
const currentScope = artifact.sys_scope;
|
|
478
|
-
const recommendedScope = decision.selectedScope;
|
|
479
|
-
|
|
480
|
-
// Don't migrate if confidence is too low
|
|
481
|
-
if (decision.confidence < 0.7) {
|
|
482
|
-
return false;
|
|
483
|
-
}
|
|
484
|
-
|
|
485
|
-
// Don't migrate if already in optimal scope
|
|
486
|
-
if (currentScope === 'global' && recommendedScope === ScopeType.GLOBAL) {
|
|
487
|
-
return false;
|
|
488
|
-
}
|
|
489
|
-
|
|
490
|
-
if (currentScope !== 'global' && recommendedScope === ScopeType.APPLICATION) {
|
|
491
|
-
return false;
|
|
492
|
-
}
|
|
493
|
-
|
|
494
|
-
return true;
|
|
495
|
-
}
|
|
496
|
-
|
|
497
|
-
private async migrateArtifact(artifact: any, decision: ScopeDecision): Promise<any> {
|
|
498
|
-
// This is a simplified migration - in practice, this would involve
|
|
499
|
-
// complex operations like dependency checking, data migration, etc.
|
|
500
|
-
|
|
501
|
-
const migrationResult = {
|
|
502
|
-
artifactId: artifact.sys_id,
|
|
503
|
-
name: artifact.name,
|
|
504
|
-
currentScope: artifact.sys_scope,
|
|
505
|
-
targetScope: decision.selectedScope,
|
|
506
|
-
success: false,
|
|
507
|
-
action: 'migrate',
|
|
508
|
-
details: {}
|
|
509
|
-
};
|
|
510
|
-
|
|
511
|
-
try {
|
|
512
|
-
// Create new artifact in target scope
|
|
513
|
-
const newArtifactData = {
|
|
514
|
-
...artifact,
|
|
515
|
-
sys_scope: decision.selectedScope === ScopeType.GLOBAL ? 'global' : decision.selectedScope,
|
|
516
|
-
name: `${artifact.name}_migrated`
|
|
517
|
-
// 🔧 TEST-001 FIX: Remove sys_id property instead of setting to undefined
|
|
518
|
-
// This prevents "sys_id undefined" errors in testing tools
|
|
519
|
-
};
|
|
520
|
-
|
|
521
|
-
// 🔧 TEST-001 FIX: Explicitly delete sys_id so ServiceNow generates a new one
|
|
522
|
-
delete newArtifactData.sys_id;
|
|
523
|
-
|
|
524
|
-
const deploymentResult = await this.strategy.deployWithGlobalScope(
|
|
525
|
-
artifact.sys_class_name || artifact.type,
|
|
526
|
-
newArtifactData,
|
|
527
|
-
{ type: decision.selectedScope }
|
|
528
|
-
);
|
|
529
|
-
|
|
530
|
-
migrationResult.success = deploymentResult.success;
|
|
531
|
-
migrationResult.details = deploymentResult;
|
|
532
|
-
|
|
533
|
-
// In a real implementation, you would also:
|
|
534
|
-
// 1. Update references to the old artifact
|
|
535
|
-
// 2. Deactivate or delete the old artifact
|
|
536
|
-
// 3. Verify the migration worked correctly
|
|
537
|
-
|
|
538
|
-
} catch (error) {
|
|
539
|
-
migrationResult.success = false;
|
|
540
|
-
migrationResult.details = { error: error instanceof Error ? error.message : String(error) };
|
|
541
|
-
}
|
|
542
|
-
|
|
543
|
-
return migrationResult;
|
|
544
|
-
}
|
|
545
|
-
|
|
546
|
-
private async validatePermissions(permissions: string[]): Promise<any> {
|
|
547
|
-
// Simplified permission validation
|
|
548
|
-
// In practice, this would check actual ServiceNow permissions
|
|
549
|
-
return {
|
|
550
|
-
isValid: true,
|
|
551
|
-
issues: [],
|
|
552
|
-
warnings: []
|
|
553
|
-
};
|
|
554
|
-
}
|
|
555
|
-
}
|