mcp-adr-analysis-server 2.0.21 → 2.0.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/.tsbuildinfo +1 -1
- package/dist/src/index.d.ts +9 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +1380 -781
- package/dist/src/index.js.map +1 -1
- package/dist/src/tools/adr-suggestion-tool.d.ts.map +1 -1
- package/dist/src/tools/adr-suggestion-tool.js +32 -30
- package/dist/src/tools/adr-suggestion-tool.js.map +1 -1
- package/dist/src/tools/content-masking-tool.d.ts +4 -0
- package/dist/src/tools/content-masking-tool.d.ts.map +1 -1
- package/dist/src/tools/content-masking-tool.js +531 -28
- package/dist/src/tools/content-masking-tool.js.map +1 -1
- package/dist/src/tools/deployment-readiness-tool.d.ts +8 -5
- package/dist/src/tools/deployment-readiness-tool.d.ts.map +1 -1
- package/dist/src/tools/deployment-readiness-tool.js +741 -79
- package/dist/src/tools/deployment-readiness-tool.js.map +1 -1
- package/dist/src/tools/environment-analysis-tool.d.ts +4 -0
- package/dist/src/tools/environment-analysis-tool.d.ts.map +1 -1
- package/dist/src/tools/environment-analysis-tool.js +568 -24
- package/dist/src/tools/environment-analysis-tool.js.map +1 -1
- package/dist/src/tools/mcp-planning-tool.d.ts.map +1 -1
- package/dist/src/tools/mcp-planning-tool.js +298 -173
- package/dist/src/tools/mcp-planning-tool.js.map +1 -1
- package/dist/src/tools/memory-loading-tool.d.ts +60 -0
- package/dist/src/tools/memory-loading-tool.d.ts.map +1 -0
- package/dist/src/tools/memory-loading-tool.js +457 -0
- package/dist/src/tools/memory-loading-tool.js.map +1 -0
- package/dist/src/tools/smart-git-push-tool.d.ts +3 -0
- package/dist/src/tools/smart-git-push-tool.d.ts.map +1 -1
- package/dist/src/tools/smart-git-push-tool.js +177 -223
- package/dist/src/tools/smart-git-push-tool.js.map +1 -1
- package/dist/src/tools/troubleshoot-guided-workflow-tool.d.ts +20 -11
- package/dist/src/tools/troubleshoot-guided-workflow-tool.d.ts.map +1 -1
- package/dist/src/tools/troubleshoot-guided-workflow-tool.js +506 -22
- package/dist/src/tools/troubleshoot-guided-workflow-tool.js.map +1 -1
- package/dist/src/types/enhanced-errors.d.ts +173 -0
- package/dist/src/types/enhanced-errors.d.ts.map +1 -0
- package/dist/src/types/enhanced-errors.js +668 -0
- package/dist/src/types/enhanced-errors.js.map +1 -0
- package/dist/src/types/knowledge-graph-schemas.d.ts +92 -0
- package/dist/src/types/knowledge-graph-schemas.d.ts.map +1 -1
- package/dist/src/types/knowledge-graph-schemas.js +45 -17
- package/dist/src/types/knowledge-graph-schemas.js.map +1 -1
- package/dist/src/types/memory-entities.d.ts +7209 -0
- package/dist/src/types/memory-entities.d.ts.map +1 -0
- package/dist/src/types/memory-entities.js +395 -0
- package/dist/src/types/memory-entities.js.map +1 -0
- package/dist/src/types/todo-json-schemas.d.ts +7 -653
- package/dist/src/types/todo-json-schemas.d.ts.map +1 -1
- package/dist/src/types/todo-json-schemas.js +6 -110
- package/dist/src/types/todo-json-schemas.js.map +1 -1
- package/dist/src/utils/enhanced-logging.d.ts +195 -0
- package/dist/src/utils/enhanced-logging.d.ts.map +1 -0
- package/dist/src/utils/enhanced-logging.js +449 -0
- package/dist/src/utils/enhanced-logging.js.map +1 -0
- package/dist/src/utils/interactive-approval.d.ts +1 -1
- package/dist/src/utils/interactive-approval.d.ts.map +1 -1
- package/dist/src/utils/interactive-approval.js +20 -16
- package/dist/src/utils/interactive-approval.js.map +1 -1
- package/dist/src/utils/knowledge-graph-manager.d.ts +23 -1
- package/dist/src/utils/knowledge-graph-manager.d.ts.map +1 -1
- package/dist/src/utils/knowledge-graph-manager.js +297 -69
- package/dist/src/utils/knowledge-graph-manager.js.map +1 -1
- package/dist/src/utils/memory-entity-manager.d.ts +134 -0
- package/dist/src/utils/memory-entity-manager.d.ts.map +1 -0
- package/dist/src/utils/memory-entity-manager.js +848 -0
- package/dist/src/utils/memory-entity-manager.js.map +1 -0
- package/dist/src/utils/memory-health-scoring.d.ts +125 -0
- package/dist/src/utils/memory-health-scoring.d.ts.map +1 -0
- package/dist/src/utils/memory-health-scoring.js +277 -0
- package/dist/src/utils/memory-health-scoring.js.map +1 -0
- package/dist/src/utils/memory-migration-manager.d.ts +93 -0
- package/dist/src/utils/memory-migration-manager.d.ts.map +1 -0
- package/dist/src/utils/memory-migration-manager.js +834 -0
- package/dist/src/utils/memory-migration-manager.js.map +1 -0
- package/dist/src/utils/memory-relationship-mapper.d.ts +87 -0
- package/dist/src/utils/memory-relationship-mapper.d.ts.map +1 -0
- package/dist/src/utils/memory-relationship-mapper.js +481 -0
- package/dist/src/utils/memory-relationship-mapper.js.map +1 -0
- package/dist/src/utils/memory-rollback-manager.d.ts +93 -0
- package/dist/src/utils/memory-rollback-manager.d.ts.map +1 -0
- package/dist/src/utils/memory-rollback-manager.js +542 -0
- package/dist/src/utils/memory-rollback-manager.js.map +1 -0
- package/dist/src/utils/memory-transformation.d.ts +59 -0
- package/dist/src/utils/memory-transformation.d.ts.map +1 -0
- package/dist/src/utils/memory-transformation.js +742 -0
- package/dist/src/utils/memory-transformation.js.map +1 -0
- package/dist/src/utils/prompt-execution.d.ts.map +1 -1
- package/dist/src/utils/prompt-execution.js +72 -51
- package/dist/src/utils/prompt-execution.js.map +1 -1
- package/dist/src/utils/todo-file-watcher.d.ts +11 -23
- package/dist/src/utils/todo-file-watcher.d.ts.map +1 -1
- package/dist/src/utils/todo-file-watcher.js +18 -156
- package/dist/src/utils/todo-file-watcher.js.map +1 -1
- package/package.json +22 -6
- package/dist/src/tools/smart-score-tool.d.ts +0 -173
- package/dist/src/tools/smart-score-tool.d.ts.map +0 -1
- package/dist/src/tools/smart-score-tool.js +0 -681
- package/dist/src/tools/smart-score-tool.js.map +0 -1
- package/dist/src/tools/todo-management-tool-v2.d.ts +0 -368
- package/dist/src/tools/todo-management-tool-v2.d.ts.map +0 -1
- package/dist/src/tools/todo-management-tool-v2.js +0 -922
- package/dist/src/tools/todo-management-tool-v2.js.map +0 -1
- package/dist/src/utils/project-health-scoring.d.ts +0 -177
- package/dist/src/utils/project-health-scoring.d.ts.map +0 -1
- package/dist/src/utils/project-health-scoring.js +0 -370
- package/dist/src/utils/project-health-scoring.js.map +0 -1
- package/dist/src/utils/todo-json-manager.d.ts +0 -71
- package/dist/src/utils/todo-json-manager.d.ts.map +0 -1
- package/dist/src/utils/todo-json-manager.js +0 -396
- package/dist/src/utils/todo-json-manager.js.map +0 -1
- package/dist/src/utils/todo-markdown-converter.d.ts +0 -16
- package/dist/src/utils/todo-markdown-converter.d.ts.map +0 -1
- package/dist/src/utils/todo-markdown-converter.js +0 -362
- package/dist/src/utils/todo-markdown-converter.js.map +0 -1
- package/dist/src/utils/todo-migration.d.ts +0 -47
- package/dist/src/utils/todo-migration.d.ts.map +0 -1
- package/dist/src/utils/todo-migration.js +0 -261
- package/dist/src/utils/todo-migration.js.map +0 -1
|
@@ -2,13 +2,28 @@
|
|
|
2
2
|
* MCP Tool for guided troubleshooting workflow
|
|
3
3
|
* Provides systematic troubleshooting with ADR/TODO alignment
|
|
4
4
|
* Integrates with other MCP tools for comprehensive analysis
|
|
5
|
+
* Enhanced with memory integration and intelligent decision capabilities
|
|
5
6
|
*/
|
|
6
7
|
import { z } from 'zod';
|
|
7
8
|
import { McpAdrError } from '../types/index.js';
|
|
9
|
+
import { MemoryEntityManager } from '../utils/memory-entity-manager.js';
|
|
10
|
+
// Note: Memory entity types are imported implicitly through MemoryEntityManager
|
|
11
|
+
import { EnhancedLogger } from '../utils/enhanced-logging.js';
|
|
8
12
|
// Structured failure schema
|
|
9
13
|
const FailureInfoSchema = z.object({
|
|
10
|
-
failureType: z
|
|
11
|
-
|
|
14
|
+
failureType: z
|
|
15
|
+
.enum([
|
|
16
|
+
'test_failure',
|
|
17
|
+
'deployment_failure',
|
|
18
|
+
'build_failure',
|
|
19
|
+
'runtime_error',
|
|
20
|
+
'performance_issue',
|
|
21
|
+
'security_issue',
|
|
22
|
+
'other',
|
|
23
|
+
])
|
|
24
|
+
.describe('Type of failure'),
|
|
25
|
+
failureDetails: z
|
|
26
|
+
.object({
|
|
12
27
|
command: z.string().optional().describe('Command that failed'),
|
|
13
28
|
exitCode: z.number().optional().describe('Exit code of failed process'),
|
|
14
29
|
errorMessage: z.string().describe('Primary error message'),
|
|
@@ -16,23 +31,374 @@ const FailureInfoSchema = z.object({
|
|
|
16
31
|
logOutput: z.string().optional().describe('Relevant log output'),
|
|
17
32
|
environment: z.string().optional().describe('Environment where failure occurred'),
|
|
18
33
|
timestamp: z.string().optional().describe('When the failure occurred'),
|
|
19
|
-
affectedFiles: z.array(z.string()).optional().describe('Files involved in the failure')
|
|
20
|
-
})
|
|
21
|
-
|
|
34
|
+
affectedFiles: z.array(z.string()).optional().describe('Files involved in the failure'),
|
|
35
|
+
})
|
|
36
|
+
.describe('Detailed failure information'),
|
|
37
|
+
context: z
|
|
38
|
+
.object({
|
|
22
39
|
recentChanges: z.string().optional().describe('Recent changes that might be related'),
|
|
23
40
|
reproducible: z.boolean().optional().describe('Whether the failure is reproducible'),
|
|
24
41
|
frequency: z.string().optional().describe('How often this failure occurs'),
|
|
25
|
-
impact: z
|
|
26
|
-
|
|
42
|
+
impact: z
|
|
43
|
+
.enum(['low', 'medium', 'high', 'critical'])
|
|
44
|
+
.optional()
|
|
45
|
+
.describe('Impact level of the failure'),
|
|
46
|
+
})
|
|
47
|
+
.optional()
|
|
48
|
+
.describe('Additional context about the failure'),
|
|
27
49
|
});
|
|
28
50
|
// Troubleshooting operation schema
|
|
29
51
|
const TroubleshootSchema = z.object({
|
|
30
|
-
operation: z
|
|
52
|
+
operation: z
|
|
53
|
+
.enum(['analyze_failure', 'generate_test_plan', 'full_workflow'])
|
|
54
|
+
.describe('Type of troubleshooting operation'),
|
|
31
55
|
failure: FailureInfoSchema.optional().describe('Structured failure information (required for analyze_failure and generate_test_plan)'),
|
|
32
56
|
projectPath: z.string().optional().describe('Path to project directory'),
|
|
33
57
|
adrDirectory: z.string().default('docs/adrs').describe('ADR directory path'),
|
|
34
|
-
todoPath: z.string().default('TODO.md').describe('Path to TODO.md file')
|
|
58
|
+
todoPath: z.string().default('TODO.md').describe('Path to TODO.md file'),
|
|
35
59
|
});
|
|
60
|
+
/**
|
|
61
|
+
* Enhanced Troubleshooting Memory Manager with Intelligence
|
|
62
|
+
* Handles memory persistence and intelligent decision-making for troubleshooting
|
|
63
|
+
*/
|
|
64
|
+
class TroubleshootingMemoryManager {
|
|
65
|
+
memoryManager;
|
|
66
|
+
logger;
|
|
67
|
+
constructor() {
|
|
68
|
+
this.memoryManager = new MemoryEntityManager();
|
|
69
|
+
this.logger = new EnhancedLogger();
|
|
70
|
+
}
|
|
71
|
+
async initialize() {
|
|
72
|
+
await this.memoryManager.initialize();
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Store troubleshooting session as memory entity
|
|
76
|
+
*/
|
|
77
|
+
async storeTroubleshootingSession(failure, analysisSteps, effectiveness, resolutionTimeMinutes) {
|
|
78
|
+
try {
|
|
79
|
+
const sessionData = {
|
|
80
|
+
failurePattern: {
|
|
81
|
+
failureType: failure.failureType,
|
|
82
|
+
errorSignature: this.generateErrorSignature(failure),
|
|
83
|
+
frequency: await this.calculateFailureFrequency(failure.failureType),
|
|
84
|
+
environments: failure.failureDetails.environment
|
|
85
|
+
? [failure.failureDetails.environment]
|
|
86
|
+
: [],
|
|
87
|
+
},
|
|
88
|
+
failureDetails: {
|
|
89
|
+
command: failure.failureDetails.command,
|
|
90
|
+
exitCode: failure.failureDetails.exitCode,
|
|
91
|
+
errorMessage: failure.failureDetails.errorMessage,
|
|
92
|
+
stackTrace: failure.failureDetails.stackTrace,
|
|
93
|
+
logOutput: failure.failureDetails.logOutput,
|
|
94
|
+
environment: failure.failureDetails.environment,
|
|
95
|
+
timestamp: failure.failureDetails.timestamp || new Date().toISOString(),
|
|
96
|
+
affectedFiles: failure.failureDetails.affectedFiles || [],
|
|
97
|
+
},
|
|
98
|
+
analysisSteps,
|
|
99
|
+
solutionEffectiveness: effectiveness,
|
|
100
|
+
resolutionTimeMinutes: resolutionTimeMinutes,
|
|
101
|
+
preventionMeasures: this.generatePreventionMeasures(failure),
|
|
102
|
+
relatedADRs: await this.findRelatedADRs(failure),
|
|
103
|
+
environmentContext: this.extractEnvironmentContext(failure),
|
|
104
|
+
followUpActions: await this.determineFollowUpActions(failure, effectiveness),
|
|
105
|
+
};
|
|
106
|
+
await this.memoryManager.upsertEntity({
|
|
107
|
+
type: 'troubleshooting_session',
|
|
108
|
+
title: `Troubleshooting: ${failure.failureType} - ${failure.failureDetails.errorMessage.substring(0, 50)}...`,
|
|
109
|
+
description: `Troubleshooting session for ${failure.failureType} failure in ${failure.failureDetails.environment || 'unknown environment'}`,
|
|
110
|
+
tags: [
|
|
111
|
+
'troubleshooting',
|
|
112
|
+
failure.failureType,
|
|
113
|
+
failure.failureDetails.environment || 'unknown-env',
|
|
114
|
+
effectiveness > 0.7 ? 'effective-solution' : 'needs-improvement',
|
|
115
|
+
],
|
|
116
|
+
sessionData,
|
|
117
|
+
relationships: [],
|
|
118
|
+
context: {
|
|
119
|
+
projectPhase: 'troubleshooting',
|
|
120
|
+
technicalStack: [],
|
|
121
|
+
environmentalFactors: failure.failureDetails.environment
|
|
122
|
+
? [failure.failureDetails.environment]
|
|
123
|
+
: [],
|
|
124
|
+
stakeholders: [],
|
|
125
|
+
},
|
|
126
|
+
accessPattern: {
|
|
127
|
+
lastAccessed: new Date().toISOString(),
|
|
128
|
+
accessCount: 1,
|
|
129
|
+
accessContext: ['troubleshooting-session'],
|
|
130
|
+
},
|
|
131
|
+
evolution: {
|
|
132
|
+
origin: 'created',
|
|
133
|
+
transformations: [
|
|
134
|
+
{
|
|
135
|
+
timestamp: new Date().toISOString(),
|
|
136
|
+
type: 'session_creation',
|
|
137
|
+
description: 'Troubleshooting session created from failure analysis',
|
|
138
|
+
agent: 'troubleshoot-guided-workflow-tool',
|
|
139
|
+
},
|
|
140
|
+
],
|
|
141
|
+
},
|
|
142
|
+
validation: {
|
|
143
|
+
isVerified: effectiveness > 0.5,
|
|
144
|
+
verificationMethod: 'solution-effectiveness-score',
|
|
145
|
+
verificationTimestamp: new Date().toISOString(),
|
|
146
|
+
},
|
|
147
|
+
});
|
|
148
|
+
this.logger.info(`Troubleshooting session stored for ${failure.failureType}`, 'TroubleshootingMemoryManager', {
|
|
149
|
+
failureType: failure.failureType,
|
|
150
|
+
effectiveness,
|
|
151
|
+
followUpActions: sessionData.followUpActions.length,
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
catch (error) {
|
|
155
|
+
this.logger.error('Failed to store troubleshooting session', 'TroubleshootingMemoryManager', error);
|
|
156
|
+
throw error;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Analyze failure patterns and determine intelligent suggestions
|
|
161
|
+
*/
|
|
162
|
+
async analyzeFailurePatterns() {
|
|
163
|
+
try {
|
|
164
|
+
const sessions = await this.memoryManager.queryEntities({
|
|
165
|
+
entityTypes: ['troubleshooting_session'],
|
|
166
|
+
limit: 100,
|
|
167
|
+
sortBy: 'lastModified',
|
|
168
|
+
});
|
|
169
|
+
// Analyze patterns across sessions
|
|
170
|
+
const failureTypes = sessions.entities.map((s) => s.sessionData.failurePattern.failureType);
|
|
171
|
+
const repeatedFailures = this.detectRepeatedFailures(failureTypes);
|
|
172
|
+
const environmentalFactors = this.extractEnvironmentalFactors(sessions.entities);
|
|
173
|
+
const knowledgeGaps = this.detectKnowledgeGaps(sessions.entities);
|
|
174
|
+
// Decision logic for suggestions
|
|
175
|
+
const suggestADR = repeatedFailures.length > 2 || this.detectArchitecturalGaps(sessions.entities);
|
|
176
|
+
const suggestResearch = knowledgeGaps.length > 0;
|
|
177
|
+
return {
|
|
178
|
+
suggestADR,
|
|
179
|
+
suggestResearch,
|
|
180
|
+
patterns: repeatedFailures,
|
|
181
|
+
recommendations: this.generateRecommendations(repeatedFailures, environmentalFactors),
|
|
182
|
+
knowledgeGaps,
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
catch (error) {
|
|
186
|
+
this.logger.error('Failed to analyze failure patterns', 'TroubleshootingMemoryManager', error);
|
|
187
|
+
throw error;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Trigger ADR suggestion based on failure patterns
|
|
192
|
+
*/
|
|
193
|
+
async triggerADRSuggestion(failureContext) {
|
|
194
|
+
try {
|
|
195
|
+
const { suggestAdrs } = await import('./adr-suggestion-tool.js');
|
|
196
|
+
return await suggestAdrs({
|
|
197
|
+
analysisType: 'comprehensive',
|
|
198
|
+
enhancedMode: true,
|
|
199
|
+
knowledgeEnhancement: true,
|
|
200
|
+
conversationContext: {
|
|
201
|
+
userGoals: ['Address recurring failures', 'Improve system reliability'],
|
|
202
|
+
focusAreas: ['architecture', 'reliability', 'troubleshooting'],
|
|
203
|
+
humanRequest: `Create ADR to address recurring ${failureContext.failureType} failures: ${failureContext.failureDetails.errorMessage}`,
|
|
204
|
+
projectPhase: 'improvement',
|
|
205
|
+
constraints: ['Must address root cause', 'Should prevent future occurrences'],
|
|
206
|
+
},
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
catch (error) {
|
|
210
|
+
this.logger.error('Failed to trigger ADR suggestion', 'TroubleshootingMemoryManager', error);
|
|
211
|
+
throw error;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Trigger research question generation for knowledge gaps
|
|
216
|
+
*/
|
|
217
|
+
async triggerResearchGeneration(knowledgeGaps) {
|
|
218
|
+
try {
|
|
219
|
+
const { generateResearchQuestions } = await import('./research-question-tool.js');
|
|
220
|
+
return await generateResearchQuestions({
|
|
221
|
+
analysisType: 'comprehensive',
|
|
222
|
+
researchContext: {
|
|
223
|
+
topic: 'Troubleshooting and System Reliability',
|
|
224
|
+
category: 'operational_excellence',
|
|
225
|
+
scope: 'failure_analysis',
|
|
226
|
+
objectives: [
|
|
227
|
+
'Understand root causes of recurring failures',
|
|
228
|
+
'Identify system reliability improvements',
|
|
229
|
+
'Document troubleshooting best practices',
|
|
230
|
+
'Develop proactive monitoring strategies',
|
|
231
|
+
],
|
|
232
|
+
constraints: ['Must be actionable', 'Should be measurable'],
|
|
233
|
+
timeline: '2-4 weeks',
|
|
234
|
+
},
|
|
235
|
+
problems: knowledgeGaps.map(gap => ({
|
|
236
|
+
id: gap.id,
|
|
237
|
+
description: gap.description,
|
|
238
|
+
category: 'troubleshooting',
|
|
239
|
+
severity: gap.severity,
|
|
240
|
+
context: gap.context,
|
|
241
|
+
})),
|
|
242
|
+
knowledgeEnhancement: true,
|
|
243
|
+
enhancedMode: true,
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
catch (error) {
|
|
247
|
+
this.logger.error('Failed to trigger research generation', 'TroubleshootingMemoryManager', error);
|
|
248
|
+
throw error;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
// Private helper methods
|
|
252
|
+
generateErrorSignature(failure) {
|
|
253
|
+
const errorMsg = failure.failureDetails.errorMessage.toLowerCase();
|
|
254
|
+
const command = failure.failureDetails.command?.toLowerCase() || '';
|
|
255
|
+
return `${failure.failureType}:${command}:${errorMsg.substring(0, 100)}`;
|
|
256
|
+
}
|
|
257
|
+
async calculateFailureFrequency(failureType) {
|
|
258
|
+
try {
|
|
259
|
+
const sessions = await this.memoryManager.queryEntities({
|
|
260
|
+
entityTypes: ['troubleshooting_session'],
|
|
261
|
+
limit: 50,
|
|
262
|
+
});
|
|
263
|
+
return sessions.entities.filter((s) => s.sessionData.failurePattern.failureType === failureType).length;
|
|
264
|
+
}
|
|
265
|
+
catch {
|
|
266
|
+
return 1;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
generatePreventionMeasures(failure) {
|
|
270
|
+
const measures = [];
|
|
271
|
+
switch (failure.failureType) {
|
|
272
|
+
case 'deployment_failure':
|
|
273
|
+
measures.push('Implement deployment health checks');
|
|
274
|
+
measures.push('Add environment validation scripts');
|
|
275
|
+
measures.push('Create deployment rollback procedures');
|
|
276
|
+
break;
|
|
277
|
+
case 'test_failure':
|
|
278
|
+
measures.push('Improve test environment consistency');
|
|
279
|
+
measures.push('Add test data validation');
|
|
280
|
+
measures.push('Implement test isolation mechanisms');
|
|
281
|
+
break;
|
|
282
|
+
case 'build_failure':
|
|
283
|
+
measures.push('Standardize build environment');
|
|
284
|
+
measures.push('Add dependency locking');
|
|
285
|
+
measures.push('Implement build reproducibility checks');
|
|
286
|
+
break;
|
|
287
|
+
case 'performance_issue':
|
|
288
|
+
measures.push('Add performance monitoring');
|
|
289
|
+
measures.push('Implement resource usage alerts');
|
|
290
|
+
measures.push('Create performance regression tests');
|
|
291
|
+
break;
|
|
292
|
+
case 'security_issue':
|
|
293
|
+
measures.push('Enhance security scanning');
|
|
294
|
+
measures.push('Implement security policy enforcement');
|
|
295
|
+
measures.push('Add vulnerability monitoring');
|
|
296
|
+
break;
|
|
297
|
+
default:
|
|
298
|
+
measures.push('Improve monitoring and alerting');
|
|
299
|
+
measures.push('Document troubleshooting procedures');
|
|
300
|
+
measures.push('Create failure response playbooks');
|
|
301
|
+
}
|
|
302
|
+
return measures;
|
|
303
|
+
}
|
|
304
|
+
async findRelatedADRs(_failure) {
|
|
305
|
+
// This would typically search for ADRs related to the failure context
|
|
306
|
+
// For now, return empty array - this will be enhanced when ADR search is integrated
|
|
307
|
+
return [];
|
|
308
|
+
}
|
|
309
|
+
extractEnvironmentContext(failure) {
|
|
310
|
+
return {
|
|
311
|
+
environment: failure.failureDetails.environment,
|
|
312
|
+
command: failure.failureDetails.command,
|
|
313
|
+
exitCode: failure.failureDetails.exitCode,
|
|
314
|
+
timestamp: failure.failureDetails.timestamp,
|
|
315
|
+
reproducible: failure.context?.reproducible,
|
|
316
|
+
frequency: failure.context?.frequency,
|
|
317
|
+
impact: failure.context?.impact,
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
async determineFollowUpActions(failure, effectiveness) {
|
|
321
|
+
const actions = [];
|
|
322
|
+
// Low effectiveness suggests need for research
|
|
323
|
+
if (effectiveness < 0.7) {
|
|
324
|
+
actions.push({
|
|
325
|
+
action: 'Generate research questions to improve troubleshooting approach',
|
|
326
|
+
type: 'research_generation',
|
|
327
|
+
priority: effectiveness < 0.5 ? 'high' : 'medium',
|
|
328
|
+
triggered: false,
|
|
329
|
+
reason: `Solution effectiveness (${effectiveness}) indicates knowledge gaps`,
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
// Architectural failure types suggest ADR needs
|
|
333
|
+
const architecturalTypes = ['deployment_failure', 'performance_issue', 'security_issue'];
|
|
334
|
+
if (architecturalTypes.includes(failure.failureType)) {
|
|
335
|
+
actions.push({
|
|
336
|
+
action: 'Suggest ADR to address architectural concerns',
|
|
337
|
+
type: 'adr_suggestion',
|
|
338
|
+
priority: 'medium',
|
|
339
|
+
triggered: false,
|
|
340
|
+
reason: `${failure.failureType} suggests architectural decision needed`,
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
// Always suggest process improvement for repeated failures
|
|
344
|
+
const frequency = await this.calculateFailureFrequency(failure.failureType);
|
|
345
|
+
if (frequency >= 3) {
|
|
346
|
+
actions.push({
|
|
347
|
+
action: 'Implement process improvements to prevent recurring failures',
|
|
348
|
+
type: 'process_improvement',
|
|
349
|
+
priority: 'high',
|
|
350
|
+
triggered: false,
|
|
351
|
+
reason: `${failure.failureType} has occurred ${frequency} times`,
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
return actions;
|
|
355
|
+
}
|
|
356
|
+
detectRepeatedFailures(failureTypes) {
|
|
357
|
+
const frequency = {};
|
|
358
|
+
failureTypes.forEach(type => {
|
|
359
|
+
frequency[type] = (frequency[type] || 0) + 1;
|
|
360
|
+
});
|
|
361
|
+
return Object.entries(frequency)
|
|
362
|
+
.filter(([_, count]) => count >= 3)
|
|
363
|
+
.map(([type, count]) => ({ type, frequency: count }));
|
|
364
|
+
}
|
|
365
|
+
detectArchitecturalGaps(sessions) {
|
|
366
|
+
const architecturalIndicators = ['deployment_failure', 'performance_issue', 'security_issue'];
|
|
367
|
+
return sessions.some(session => architecturalIndicators.includes(session.sessionData.failurePattern.failureType));
|
|
368
|
+
}
|
|
369
|
+
detectKnowledgeGaps(sessions) {
|
|
370
|
+
const patterns = sessions.filter(session => session.sessionData.solutionEffectiveness < 0.7);
|
|
371
|
+
return patterns.map(pattern => ({
|
|
372
|
+
id: pattern.id,
|
|
373
|
+
description: `Low solution effectiveness for ${pattern.sessionData.failurePattern.failureType}`,
|
|
374
|
+
severity: pattern.sessionData.solutionEffectiveness < 0.5 ? 'high' : 'medium',
|
|
375
|
+
context: pattern.sessionData.failurePattern.failureDetails.errorMessage,
|
|
376
|
+
}));
|
|
377
|
+
}
|
|
378
|
+
extractEnvironmentalFactors(sessions) {
|
|
379
|
+
const factors = new Set();
|
|
380
|
+
sessions.forEach(session => {
|
|
381
|
+
const env = session.sessionData.failurePattern.environments;
|
|
382
|
+
if (env && Array.isArray(env)) {
|
|
383
|
+
env.forEach(e => factors.add(e));
|
|
384
|
+
}
|
|
385
|
+
});
|
|
386
|
+
return Array.from(factors);
|
|
387
|
+
}
|
|
388
|
+
generateRecommendations(repeatedFailures, environmentalFactors) {
|
|
389
|
+
const recommendations = [];
|
|
390
|
+
if (repeatedFailures.length > 0) {
|
|
391
|
+
recommendations.push(`Address recurring ${repeatedFailures[0].type} failures with architectural decision`);
|
|
392
|
+
recommendations.push('Implement prevention measures for top failure patterns');
|
|
393
|
+
}
|
|
394
|
+
if (environmentalFactors.length > 1) {
|
|
395
|
+
recommendations.push('Standardize environments to reduce environment-specific failures');
|
|
396
|
+
}
|
|
397
|
+
recommendations.push('Build knowledge base from troubleshooting sessions');
|
|
398
|
+
recommendations.push('Create automated monitoring for detected failure patterns');
|
|
399
|
+
return recommendations;
|
|
400
|
+
}
|
|
401
|
+
}
|
|
36
402
|
/**
|
|
37
403
|
* Analyze structured failure information
|
|
38
404
|
*/
|
|
@@ -44,7 +410,7 @@ async function analyzeFailure(failure) {
|
|
|
44
410
|
'',
|
|
45
411
|
'## Error Details',
|
|
46
412
|
`**Primary Error**: ${failure.failureDetails.errorMessage}`,
|
|
47
|
-
''
|
|
413
|
+
'',
|
|
48
414
|
];
|
|
49
415
|
// Add command and exit code if available
|
|
50
416
|
if (failure.failureDetails.command) {
|
|
@@ -190,21 +556,21 @@ Generate specific test commands to diagnose and resolve this failure.`;
|
|
|
190
556
|
const response = await fetch(aiConfig.baseURL + '/chat/completions', {
|
|
191
557
|
method: 'POST',
|
|
192
558
|
headers: {
|
|
193
|
-
|
|
559
|
+
Authorization: `Bearer ${aiConfig.apiKey}`,
|
|
194
560
|
'Content-Type': 'application/json',
|
|
195
561
|
'HTTP-Referer': aiConfig.siteUrl || '',
|
|
196
|
-
'X-Title': aiConfig.siteName || ''
|
|
562
|
+
'X-Title': aiConfig.siteName || '',
|
|
197
563
|
},
|
|
198
564
|
body: JSON.stringify({
|
|
199
565
|
model: getRecommendedModel('analysis'),
|
|
200
566
|
messages: [
|
|
201
567
|
{ role: 'system', content: systemPrompt },
|
|
202
|
-
{ role: 'user', content: failureContext }
|
|
568
|
+
{ role: 'user', content: failureContext },
|
|
203
569
|
],
|
|
204
570
|
temperature: 0.2,
|
|
205
571
|
max_tokens: 2000,
|
|
206
|
-
response_format: { type: 'json_object' }
|
|
207
|
-
})
|
|
572
|
+
response_format: { type: 'json_object' },
|
|
573
|
+
}),
|
|
208
574
|
});
|
|
209
575
|
if (!response.ok) {
|
|
210
576
|
throw new Error(`OpenRouter API error: ${response.status}`);
|
|
@@ -233,7 +599,7 @@ function formatAITestPlan(testPlan, projectPath) {
|
|
|
233
599
|
testPlan.summary || 'AI analysis of the failure',
|
|
234
600
|
'',
|
|
235
601
|
`**Priority**: ${testPlan.priority?.toUpperCase() || 'MEDIUM'}`,
|
|
236
|
-
''
|
|
602
|
+
'',
|
|
237
603
|
];
|
|
238
604
|
if (testPlan.testSections && Array.isArray(testPlan.testSections)) {
|
|
239
605
|
testPlan.testSections.forEach((section, index) => {
|
|
@@ -300,7 +666,7 @@ function generateFallbackTestPlan(failure, args) {
|
|
|
300
666
|
`## For Failure Type: ${failure.failureType.toUpperCase()}`,
|
|
301
667
|
'',
|
|
302
668
|
'## Specific Commands to Execute',
|
|
303
|
-
''
|
|
669
|
+
'',
|
|
304
670
|
];
|
|
305
671
|
const projectPath = args.projectPath || '.';
|
|
306
672
|
switch (failure.failureType) {
|
|
@@ -447,7 +813,7 @@ async function runFullWorkflow(_args) {
|
|
|
447
813
|
'4. 🔄 Generate targeted questions',
|
|
448
814
|
'5. 🔄 ADR validation',
|
|
449
815
|
'6. 🔄 Guided recommendations',
|
|
450
|
-
''
|
|
816
|
+
'',
|
|
451
817
|
];
|
|
452
818
|
// Legacy workflow - simplified for backwards compatibility
|
|
453
819
|
// Legacy full workflow - provides overview of troubleshooting approach
|
|
@@ -478,7 +844,123 @@ async function runFullWorkflow(_args) {
|
|
|
478
844
|
return report.join('\n');
|
|
479
845
|
}
|
|
480
846
|
/**
|
|
481
|
-
*
|
|
847
|
+
* Enhanced troubleshooting workflow with memory integration and intelligent decision triggering
|
|
848
|
+
*/
|
|
849
|
+
export async function troubleshootGuidedWorkflowEnhanced(args) {
|
|
850
|
+
try {
|
|
851
|
+
const validatedArgs = TroubleshootSchema.parse(args);
|
|
852
|
+
// Initialize memory manager if enabled
|
|
853
|
+
let memoryManager = null;
|
|
854
|
+
if (args.enableMemoryIntegration !== false) {
|
|
855
|
+
memoryManager = new TroubleshootingMemoryManager();
|
|
856
|
+
await memoryManager.initialize();
|
|
857
|
+
}
|
|
858
|
+
// Execute original troubleshooting logic
|
|
859
|
+
const result = await troubleshootGuidedWorkflow(validatedArgs);
|
|
860
|
+
// Enhanced memory integration and intelligent suggestions
|
|
861
|
+
if (memoryManager && validatedArgs.failure && args.solutionEffectiveness !== undefined) {
|
|
862
|
+
try {
|
|
863
|
+
// Store troubleshooting session
|
|
864
|
+
await memoryManager.storeTroubleshootingSession(validatedArgs.failure, ['Analysis completed', 'Test plan generated', 'Solution provided'], args.solutionEffectiveness, args.resolutionTimeMinutes);
|
|
865
|
+
// Analyze patterns and trigger intelligent suggestions
|
|
866
|
+
const patternAnalysis = await memoryManager.analyzeFailurePatterns();
|
|
867
|
+
// Enhance result with intelligent suggestions
|
|
868
|
+
const enhancedResult = {
|
|
869
|
+
...result,
|
|
870
|
+
memoryIntegration: {
|
|
871
|
+
sessionStored: true,
|
|
872
|
+
patternAnalysis: {
|
|
873
|
+
repeatedFailures: patternAnalysis.patterns.length,
|
|
874
|
+
suggestionsTriggered: [],
|
|
875
|
+
recommendations: patternAnalysis.recommendations,
|
|
876
|
+
},
|
|
877
|
+
},
|
|
878
|
+
};
|
|
879
|
+
// Trigger ADR suggestion if patterns detected
|
|
880
|
+
if (patternAnalysis.suggestADR) {
|
|
881
|
+
try {
|
|
882
|
+
const adrSuggestion = await memoryManager.triggerADRSuggestion(validatedArgs.failure);
|
|
883
|
+
enhancedResult.memoryIntegration.patternAnalysis.suggestionsTriggered.push({
|
|
884
|
+
type: 'adr_suggestion',
|
|
885
|
+
reason: 'Recurring failure patterns detected',
|
|
886
|
+
patterns: patternAnalysis.patterns,
|
|
887
|
+
suggestion: adrSuggestion,
|
|
888
|
+
});
|
|
889
|
+
}
|
|
890
|
+
catch (error) {
|
|
891
|
+
console.warn('Failed to trigger ADR suggestion:', error);
|
|
892
|
+
}
|
|
893
|
+
}
|
|
894
|
+
// Trigger research generation if knowledge gaps detected
|
|
895
|
+
if (patternAnalysis.suggestResearch) {
|
|
896
|
+
try {
|
|
897
|
+
const researchSuggestion = await memoryManager.triggerResearchGeneration(patternAnalysis.knowledgeGaps);
|
|
898
|
+
enhancedResult.memoryIntegration.patternAnalysis.suggestionsTriggered.push({
|
|
899
|
+
type: 'research_suggestion',
|
|
900
|
+
reason: 'Knowledge gaps identified in troubleshooting',
|
|
901
|
+
gaps: patternAnalysis.knowledgeGaps,
|
|
902
|
+
suggestion: researchSuggestion,
|
|
903
|
+
});
|
|
904
|
+
}
|
|
905
|
+
catch (error) {
|
|
906
|
+
console.warn('Failed to trigger research generation:', error);
|
|
907
|
+
}
|
|
908
|
+
}
|
|
909
|
+
// Add intelligent suggestions to the content
|
|
910
|
+
if (enhancedResult.memoryIntegration.patternAnalysis.suggestionsTriggered.length > 0) {
|
|
911
|
+
const originalContent = enhancedResult.content[0].text;
|
|
912
|
+
const suggestions = enhancedResult.memoryIntegration.patternAnalysis.suggestionsTriggered;
|
|
913
|
+
const suggestionText = [
|
|
914
|
+
'',
|
|
915
|
+
'---',
|
|
916
|
+
'',
|
|
917
|
+
'## 🧠 Intelligent Suggestions (Memory-Enhanced)',
|
|
918
|
+
'',
|
|
919
|
+
'Based on analysis of historical troubleshooting patterns:',
|
|
920
|
+
'',
|
|
921
|
+
];
|
|
922
|
+
suggestions.forEach((suggestion) => {
|
|
923
|
+
suggestionText.push(`### ${suggestion.type === 'adr_suggestion' ? '📋 ADR Suggestion' : '🔬 Research Suggestion'}`);
|
|
924
|
+
suggestionText.push(`**Reason**: ${suggestion.reason}`);
|
|
925
|
+
suggestionText.push('');
|
|
926
|
+
if (suggestion.type === 'adr_suggestion' && suggestion.patterns) {
|
|
927
|
+
suggestionText.push(`**Patterns Detected**: ${suggestion.patterns.map((p) => `${p.type} (${p.frequency}x)`).join(', ')}`);
|
|
928
|
+
suggestionText.push('**Recommendation**: Create architectural decision to address recurring failures');
|
|
929
|
+
}
|
|
930
|
+
else if (suggestion.type === 'research_suggestion' && suggestion.gaps) {
|
|
931
|
+
suggestionText.push(`**Knowledge Gaps**: ${suggestion.gaps.length} areas identified`);
|
|
932
|
+
suggestionText.push('**Recommendation**: Generate research questions to improve troubleshooting effectiveness');
|
|
933
|
+
}
|
|
934
|
+
suggestionText.push('');
|
|
935
|
+
});
|
|
936
|
+
if (enhancedResult.memoryIntegration.patternAnalysis.recommendations.length > 0) {
|
|
937
|
+
suggestionText.push('### 💡 Additional Recommendations');
|
|
938
|
+
enhancedResult.memoryIntegration.patternAnalysis.recommendations.forEach((rec) => {
|
|
939
|
+
suggestionText.push(`- ${rec}`);
|
|
940
|
+
});
|
|
941
|
+
suggestionText.push('');
|
|
942
|
+
}
|
|
943
|
+
suggestionText.push('*These suggestions are generated automatically based on troubleshooting session analysis and failure pattern recognition.*');
|
|
944
|
+
enhancedResult.content[0].text = originalContent + suggestionText.join('\n');
|
|
945
|
+
}
|
|
946
|
+
return enhancedResult;
|
|
947
|
+
}
|
|
948
|
+
catch (memoryError) {
|
|
949
|
+
console.warn('Memory integration failed, continuing with standard workflow:', memoryError);
|
|
950
|
+
return result;
|
|
951
|
+
}
|
|
952
|
+
}
|
|
953
|
+
return result;
|
|
954
|
+
}
|
|
955
|
+
catch (error) {
|
|
956
|
+
if (error instanceof z.ZodError) {
|
|
957
|
+
throw new McpAdrError(`Invalid input: ${error.errors.map(e => e.message).join(', ')}`, 'INVALID_INPUT');
|
|
958
|
+
}
|
|
959
|
+
throw new McpAdrError(`Enhanced troubleshooting workflow failed: ${error instanceof Error ? error.message : String(error)}`, 'TROUBLESHOOTING_ERROR');
|
|
960
|
+
}
|
|
961
|
+
}
|
|
962
|
+
/**
|
|
963
|
+
* Main troubleshooting workflow function (original implementation)
|
|
482
964
|
*/
|
|
483
965
|
export async function troubleshootGuidedWorkflow(args) {
|
|
484
966
|
try {
|
|
@@ -504,10 +986,12 @@ export async function troubleshootGuidedWorkflow(args) {
|
|
|
504
986
|
throw new McpAdrError(`Unknown operation: ${validatedArgs.operation}`, 'INVALID_INPUT');
|
|
505
987
|
}
|
|
506
988
|
return {
|
|
507
|
-
content: [
|
|
989
|
+
content: [
|
|
990
|
+
{
|
|
508
991
|
type: 'text',
|
|
509
|
-
text: result
|
|
510
|
-
}
|
|
992
|
+
text: result,
|
|
993
|
+
},
|
|
994
|
+
],
|
|
511
995
|
};
|
|
512
996
|
}
|
|
513
997
|
catch (error) {
|