mcp-adr-analysis-server 2.0.21 → 2.1.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 +94 -839
- package/dist/.tsbuildinfo +1 -1
- package/dist/src/config/ai-config.d.ts.map +1 -1
- package/dist/src/config/ai-config.js +9 -9
- package/dist/src/config/ai-config.js.map +1 -1
- package/dist/src/index.d.ts +15 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +1594 -837
- package/dist/src/index.js.map +1 -1
- package/dist/src/prompts/analysis-prompts.d.ts +4 -1
- package/dist/src/prompts/analysis-prompts.d.ts.map +1 -1
- package/dist/src/prompts/analysis-prompts.js +61 -30
- package/dist/src/prompts/analysis-prompts.js.map +1 -1
- package/dist/src/prompts/index.d.ts +17 -1
- package/dist/src/prompts/index.d.ts.map +1 -1
- package/dist/src/prompts/index.js +325 -1
- package/dist/src/prompts/index.js.map +1 -1
- package/dist/src/prompts/rule-generation-prompts.d.ts +5 -1
- package/dist/src/prompts/rule-generation-prompts.d.ts.map +1 -1
- package/dist/src/prompts/rule-generation-prompts.js +5 -1
- package/dist/src/prompts/rule-generation-prompts.js.map +1 -1
- package/dist/src/prompts/security-prompts.d.ts +6 -1
- package/dist/src/prompts/security-prompts.d.ts.map +1 -1
- package/dist/src/prompts/security-prompts.js +6 -1
- package/dist/src/prompts/security-prompts.js.map +1 -1
- package/dist/src/prompts/todo-prompts.d.ts +49 -0
- package/dist/src/prompts/todo-prompts.d.ts.map +1 -0
- package/dist/src/prompts/todo-prompts.js +824 -0
- package/dist/src/prompts/todo-prompts.js.map +1 -0
- package/dist/src/resources/index.d.ts.map +1 -1
- package/dist/src/resources/index.js +9 -7
- package/dist/src/resources/index.js.map +1 -1
- package/dist/src/tools/adr-bootstrap-validation-tool.d.ts +47 -0
- package/dist/src/tools/adr-bootstrap-validation-tool.d.ts.map +1 -0
- package/dist/src/tools/adr-bootstrap-validation-tool.js +979 -0
- package/dist/src/tools/adr-bootstrap-validation-tool.js.map +1 -0
- package/dist/src/tools/adr-suggestion-tool.d.ts +1 -0
- package/dist/src/tools/adr-suggestion-tool.d.ts.map +1 -1
- package/dist/src/tools/adr-suggestion-tool.js +330 -32
- package/dist/src/tools/adr-suggestion-tool.js.map +1 -1
- package/dist/src/tools/content-masking-tool.d.ts +5 -0
- package/dist/src/tools/content-masking-tool.d.ts.map +1 -1
- package/dist/src/tools/content-masking-tool.js +631 -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 +1017 -93
- 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/interactive-adr-planning-tool.d.ts.map +1 -1
- package/dist/src/tools/interactive-adr-planning-tool.js +270 -108
- package/dist/src/tools/interactive-adr-planning-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 +316 -183
- 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/research-integration-tool.d.ts +4 -1
- package/dist/src/tools/research-integration-tool.d.ts.map +1 -1
- package/dist/src/tools/research-integration-tool.js +5 -1
- package/dist/src/tools/research-integration-tool.js.map +1 -1
- package/dist/src/tools/review-existing-adrs-tool.d.ts +19 -0
- package/dist/src/tools/review-existing-adrs-tool.d.ts.map +1 -0
- package/dist/src/tools/review-existing-adrs-tool.js +1204 -0
- package/dist/src/tools/review-existing-adrs-tool.js.map +1 -0
- package/dist/src/tools/rule-generation-tool.d.ts +2 -0
- package/dist/src/tools/rule-generation-tool.d.ts.map +1 -1
- package/dist/src/tools/rule-generation-tool.js +274 -33
- package/dist/src/tools/rule-generation-tool.js.map +1 -1
- package/dist/src/tools/smart-git-push-tool-v2.d.ts +4 -0
- package/dist/src/tools/smart-git-push-tool-v2.d.ts.map +1 -1
- package/dist/src/tools/smart-git-push-tool-v2.js +423 -229
- package/dist/src/tools/smart-git-push-tool-v2.js.map +1 -1
- 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 +241 -235
- package/dist/src/tools/smart-git-push-tool.js.map +1 -1
- package/dist/src/tools/tool-chain-orchestrator.d.ts +2 -2
- package/dist/src/tools/tool-chain-orchestrator.d.ts.map +1 -1
- package/dist/src/tools/tool-chain-orchestrator.js +152 -93
- package/dist/src/tools/tool-chain-orchestrator.js.map +1 -1
- package/dist/src/tools/troubleshoot-guided-workflow-tool.d.ts +22 -13
- package/dist/src/tools/troubleshoot-guided-workflow-tool.d.ts.map +1 -1
- package/dist/src/tools/troubleshoot-guided-workflow-tool.js +660 -28
- package/dist/src/tools/troubleshoot-guided-workflow-tool.js.map +1 -1
- package/dist/src/types/ape-framework.d.ts +93 -0
- package/dist/src/types/ape-framework.d.ts.map +1 -1
- package/dist/src/types/ape-framework.js +10 -10
- package/dist/src/types/ape-framework.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/index.d.ts +129 -3
- package/dist/src/types/index.d.ts.map +1 -1
- package/dist/src/types/index.js +15 -0
- package/dist/src/types/index.js.map +1 -1
- package/dist/src/types/knowledge-generation.d.ts +78 -0
- package/dist/src/types/knowledge-generation.d.ts.map +1 -1
- package/dist/src/types/knowledge-generation.js +10 -6
- package/dist/src/types/knowledge-generation.js.map +1 -1
- 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/reflexion-framework.d.ts +44 -0
- package/dist/src/types/reflexion-framework.d.ts.map +1 -1
- package/dist/src/types/reflexion-framework.js +7 -7
- package/dist/src/types/reflexion-framework.js.map +1 -1
- 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/types/tool-arguments.d.ts +224 -0
- package/dist/src/types/tool-arguments.d.ts.map +1 -0
- package/dist/src/types/tool-arguments.js +6 -0
- package/dist/src/types/tool-arguments.js.map +1 -0
- package/dist/src/utils/actual-file-operations.d.ts.map +1 -1
- package/dist/src/utils/actual-file-operations.js +25 -9
- package/dist/src/utils/actual-file-operations.js.map +1 -1
- package/dist/src/utils/adr-discovery.d.ts +33 -1
- package/dist/src/utils/adr-discovery.d.ts.map +1 -1
- package/dist/src/utils/adr-discovery.js +14 -9
- package/dist/src/utils/adr-discovery.js.map +1 -1
- package/dist/src/utils/adr-suggestions.d.ts +72 -0
- package/dist/src/utils/adr-suggestions.d.ts.map +1 -1
- package/dist/src/utils/adr-suggestions.js +6 -0
- package/dist/src/utils/adr-suggestions.js.map +1 -1
- package/dist/src/utils/cache.d.ts.map +1 -1
- package/dist/src/utils/cache.js +22 -19
- package/dist/src/utils/cache.js.map +1 -1
- package/dist/src/utils/chain-of-thought-template.d.ts +13 -1
- package/dist/src/utils/chain-of-thought-template.d.ts.map +1 -1
- package/dist/src/utils/chain-of-thought-template.js +31 -22
- package/dist/src/utils/chain-of-thought-template.js.map +1 -1
- package/dist/src/utils/config.d.ts.map +1 -1
- package/dist/src/utils/config.js +1 -0
- package/dist/src/utils/config.js.map +1 -1
- package/dist/src/utils/directory-compat.js +1 -1
- package/dist/src/utils/directory-compat.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/file-system.d.ts +182 -34
- package/dist/src/utils/file-system.d.ts.map +1 -1
- package/dist/src/utils/file-system.js +648 -774
- package/dist/src/utils/file-system.js.map +1 -1
- package/dist/src/utils/gitleaks-detector.d.ts +50 -0
- package/dist/src/utils/gitleaks-detector.d.ts.map +1 -0
- package/dist/src/utils/gitleaks-detector.js +334 -0
- package/dist/src/utils/gitleaks-detector.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 +22 -17
- package/dist/src/utils/interactive-approval.js.map +1 -1
- package/dist/src/utils/json-safe.d.ts.map +1 -1
- package/dist/src/utils/json-safe.js +9 -6
- package/dist/src/utils/json-safe.js.map +1 -1
- package/dist/src/utils/knowledge-graph-manager.d.ts +37 -1
- package/dist/src/utils/knowledge-graph-manager.d.ts.map +1 -1
- package/dist/src/utils/knowledge-graph-manager.js +315 -70
- package/dist/src/utils/knowledge-graph-manager.js.map +1 -1
- package/dist/src/utils/location-filter.d.ts +35 -10
- package/dist/src/utils/location-filter.d.ts.map +1 -1
- package/dist/src/utils/location-filter.js +360 -94
- package/dist/src/utils/location-filter.js.map +1 -1
- package/dist/src/utils/mcp-response-validator.d.ts.map +1 -1
- package/dist/src/utils/mcp-response-validator.js +34 -19
- package/dist/src/utils/mcp-response-validator.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 +851 -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 +842 -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 +482 -0
- package/dist/src/utils/memory-relationship-mapper.js.map +1 -0
- package/dist/src/utils/memory-rollback-manager.d.ts +105 -0
- package/dist/src/utils/memory-rollback-manager.d.ts.map +1 -0
- package/dist/src/utils/memory-rollback-manager.js +575 -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/output-masking.d.ts +12 -0
- package/dist/src/utils/output-masking.d.ts.map +1 -1
- package/dist/src/utils/output-masking.js +5 -0
- package/dist/src/utils/output-masking.js.map +1 -1
- 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/release-readiness-detector.d.ts.map +1 -1
- package/dist/src/utils/release-readiness-detector.js +43 -42
- package/dist/src/utils/release-readiness-detector.js.map +1 -1
- package/dist/src/utils/research-integration.d.ts.map +1 -1
- package/dist/src/utils/research-integration.js +73 -44
- package/dist/src/utils/research-integration.js.map +1 -1
- package/dist/src/utils/research-questions.d.ts.map +1 -1
- package/dist/src/utils/research-questions.js +40 -14
- package/dist/src/utils/research-questions.js.map +1 -1
- package/dist/src/utils/ripgrep-wrapper.d.ts +84 -0
- package/dist/src/utils/ripgrep-wrapper.d.ts.map +1 -0
- package/dist/src/utils/ripgrep-wrapper.js +255 -0
- package/dist/src/utils/ripgrep-wrapper.js.map +1 -0
- package/dist/src/utils/rule-generation.d.ts.map +1 -1
- package/dist/src/utils/rule-generation.js +26 -15
- package/dist/src/utils/rule-generation.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/dist/src/utils/tree-sitter-analyzer.d.ts +185 -0
- package/dist/src/utils/tree-sitter-analyzer.d.ts.map +1 -0
- package/dist/src/utils/tree-sitter-analyzer.js +885 -0
- package/dist/src/utils/tree-sitter-analyzer.js.map +1 -0
- package/package.json +51 -10
- 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/enhanced-sensitive-detector.d.ts +0 -61
- package/dist/src/utils/enhanced-sensitive-detector.d.ts.map +0 -1
- package/dist/src/utils/enhanced-sensitive-detector.js +0 -437
- package/dist/src/utils/enhanced-sensitive-detector.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,29 @@
|
|
|
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';
|
|
12
|
+
import { findFiles, findRelatedCode } from '../utils/file-system.js';
|
|
8
13
|
// Structured failure schema
|
|
9
14
|
const FailureInfoSchema = z.object({
|
|
10
|
-
failureType: z
|
|
11
|
-
|
|
15
|
+
failureType: z
|
|
16
|
+
.enum([
|
|
17
|
+
'test_failure',
|
|
18
|
+
'deployment_failure',
|
|
19
|
+
'build_failure',
|
|
20
|
+
'runtime_error',
|
|
21
|
+
'performance_issue',
|
|
22
|
+
'security_issue',
|
|
23
|
+
'other',
|
|
24
|
+
])
|
|
25
|
+
.describe('Type of failure'),
|
|
26
|
+
failureDetails: z
|
|
27
|
+
.object({
|
|
12
28
|
command: z.string().optional().describe('Command that failed'),
|
|
13
29
|
exitCode: z.number().optional().describe('Exit code of failed process'),
|
|
14
30
|
errorMessage: z.string().describe('Primary error message'),
|
|
@@ -16,27 +32,378 @@ const FailureInfoSchema = z.object({
|
|
|
16
32
|
logOutput: z.string().optional().describe('Relevant log output'),
|
|
17
33
|
environment: z.string().optional().describe('Environment where failure occurred'),
|
|
18
34
|
timestamp: z.string().optional().describe('When the failure occurred'),
|
|
19
|
-
affectedFiles: z.array(z.string()).optional().describe('Files involved in the failure')
|
|
20
|
-
})
|
|
21
|
-
|
|
35
|
+
affectedFiles: z.array(z.string()).optional().describe('Files involved in the failure'),
|
|
36
|
+
})
|
|
37
|
+
.describe('Detailed failure information'),
|
|
38
|
+
context: z
|
|
39
|
+
.object({
|
|
22
40
|
recentChanges: z.string().optional().describe('Recent changes that might be related'),
|
|
23
41
|
reproducible: z.boolean().optional().describe('Whether the failure is reproducible'),
|
|
24
42
|
frequency: z.string().optional().describe('How often this failure occurs'),
|
|
25
|
-
impact: z
|
|
26
|
-
|
|
43
|
+
impact: z
|
|
44
|
+
.enum(['low', 'medium', 'high', 'critical'])
|
|
45
|
+
.optional()
|
|
46
|
+
.describe('Impact level of the failure'),
|
|
47
|
+
})
|
|
48
|
+
.optional()
|
|
49
|
+
.describe('Additional context about the failure'),
|
|
27
50
|
});
|
|
28
51
|
// Troubleshooting operation schema
|
|
29
52
|
const TroubleshootSchema = z.object({
|
|
30
|
-
operation: z
|
|
53
|
+
operation: z
|
|
54
|
+
.enum(['analyze_failure', 'generate_test_plan', 'full_workflow'])
|
|
55
|
+
.describe('Type of troubleshooting operation'),
|
|
31
56
|
failure: FailureInfoSchema.optional().describe('Structured failure information (required for analyze_failure and generate_test_plan)'),
|
|
32
57
|
projectPath: z.string().optional().describe('Path to project directory'),
|
|
33
58
|
adrDirectory: z.string().default('docs/adrs').describe('ADR directory path'),
|
|
34
|
-
todoPath: z.string().default('TODO.md').describe('Path to TODO.md file')
|
|
59
|
+
todoPath: z.string().default('TODO.md').describe('Path to TODO.md file'),
|
|
35
60
|
});
|
|
61
|
+
/**
|
|
62
|
+
* Enhanced Troubleshooting Memory Manager with Intelligence
|
|
63
|
+
* Handles memory persistence and intelligent decision-making for troubleshooting
|
|
64
|
+
*/
|
|
65
|
+
class TroubleshootingMemoryManager {
|
|
66
|
+
memoryManager;
|
|
67
|
+
logger;
|
|
68
|
+
constructor() {
|
|
69
|
+
this.memoryManager = new MemoryEntityManager();
|
|
70
|
+
this.logger = new EnhancedLogger();
|
|
71
|
+
}
|
|
72
|
+
async initialize() {
|
|
73
|
+
await this.memoryManager.initialize();
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Store troubleshooting session as memory entity
|
|
77
|
+
*/
|
|
78
|
+
async storeTroubleshootingSession(failure, analysisSteps, effectiveness, resolutionTimeMinutes) {
|
|
79
|
+
try {
|
|
80
|
+
const sessionData = {
|
|
81
|
+
failurePattern: {
|
|
82
|
+
failureType: failure.failureType,
|
|
83
|
+
errorSignature: this.generateErrorSignature(failure),
|
|
84
|
+
frequency: await this.calculateFailureFrequency(failure.failureType),
|
|
85
|
+
environments: failure.failureDetails.environment
|
|
86
|
+
? [failure.failureDetails.environment]
|
|
87
|
+
: [],
|
|
88
|
+
},
|
|
89
|
+
failureDetails: {
|
|
90
|
+
command: failure.failureDetails.command,
|
|
91
|
+
exitCode: failure.failureDetails.exitCode,
|
|
92
|
+
errorMessage: failure.failureDetails.errorMessage,
|
|
93
|
+
stackTrace: failure.failureDetails.stackTrace,
|
|
94
|
+
logOutput: failure.failureDetails.logOutput,
|
|
95
|
+
environment: failure.failureDetails.environment,
|
|
96
|
+
timestamp: failure.failureDetails.timestamp || new Date().toISOString(),
|
|
97
|
+
affectedFiles: failure.failureDetails.affectedFiles || [],
|
|
98
|
+
},
|
|
99
|
+
analysisSteps,
|
|
100
|
+
solutionEffectiveness: effectiveness,
|
|
101
|
+
resolutionTimeMinutes: resolutionTimeMinutes,
|
|
102
|
+
preventionMeasures: this.generatePreventionMeasures(failure),
|
|
103
|
+
relatedADRs: await this.findRelatedADRs(failure),
|
|
104
|
+
environmentContext: this.extractEnvironmentContext(failure),
|
|
105
|
+
followUpActions: await this.determineFollowUpActions(failure, effectiveness),
|
|
106
|
+
};
|
|
107
|
+
await this.memoryManager.upsertEntity({
|
|
108
|
+
type: 'troubleshooting_session',
|
|
109
|
+
title: `Troubleshooting: ${failure.failureType} - ${failure.failureDetails.errorMessage.substring(0, 50)}...`,
|
|
110
|
+
description: `Troubleshooting session for ${failure.failureType} failure in ${failure.failureDetails.environment || 'unknown environment'}`,
|
|
111
|
+
tags: [
|
|
112
|
+
'troubleshooting',
|
|
113
|
+
failure.failureType,
|
|
114
|
+
failure.failureDetails.environment || 'unknown-env',
|
|
115
|
+
effectiveness > 0.7 ? 'effective-solution' : 'needs-improvement',
|
|
116
|
+
],
|
|
117
|
+
sessionData,
|
|
118
|
+
relationships: [],
|
|
119
|
+
context: {
|
|
120
|
+
projectPhase: 'troubleshooting',
|
|
121
|
+
technicalStack: [],
|
|
122
|
+
environmentalFactors: failure.failureDetails.environment
|
|
123
|
+
? [failure.failureDetails.environment]
|
|
124
|
+
: [],
|
|
125
|
+
stakeholders: [],
|
|
126
|
+
},
|
|
127
|
+
accessPattern: {
|
|
128
|
+
lastAccessed: new Date().toISOString(),
|
|
129
|
+
accessCount: 1,
|
|
130
|
+
accessContext: ['troubleshooting-session'],
|
|
131
|
+
},
|
|
132
|
+
evolution: {
|
|
133
|
+
origin: 'created',
|
|
134
|
+
transformations: [
|
|
135
|
+
{
|
|
136
|
+
timestamp: new Date().toISOString(),
|
|
137
|
+
type: 'session_creation',
|
|
138
|
+
description: 'Troubleshooting session created from failure analysis',
|
|
139
|
+
agent: 'troubleshoot-guided-workflow-tool',
|
|
140
|
+
},
|
|
141
|
+
],
|
|
142
|
+
},
|
|
143
|
+
validation: {
|
|
144
|
+
isVerified: effectiveness > 0.5,
|
|
145
|
+
verificationMethod: 'solution-effectiveness-score',
|
|
146
|
+
verificationTimestamp: new Date().toISOString(),
|
|
147
|
+
},
|
|
148
|
+
});
|
|
149
|
+
this.logger.info(`Troubleshooting session stored for ${failure.failureType}`, 'TroubleshootingMemoryManager', {
|
|
150
|
+
failureType: failure.failureType,
|
|
151
|
+
effectiveness,
|
|
152
|
+
followUpActions: sessionData.followUpActions.length,
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
catch (error) {
|
|
156
|
+
this.logger.error('Failed to store troubleshooting session', 'TroubleshootingMemoryManager', error);
|
|
157
|
+
throw error;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Analyze failure patterns and determine intelligent suggestions
|
|
162
|
+
*/
|
|
163
|
+
async analyzeFailurePatterns() {
|
|
164
|
+
try {
|
|
165
|
+
const sessions = await this.memoryManager.queryEntities({
|
|
166
|
+
entityTypes: ['troubleshooting_session'],
|
|
167
|
+
limit: 100,
|
|
168
|
+
sortBy: 'lastModified',
|
|
169
|
+
});
|
|
170
|
+
// Analyze patterns across sessions
|
|
171
|
+
const failureTypes = sessions.entities.map((s) => s.sessionData.failurePattern.failureType);
|
|
172
|
+
const repeatedFailures = this.detectRepeatedFailures(failureTypes);
|
|
173
|
+
const environmentalFactors = this.extractEnvironmentalFactors(sessions.entities);
|
|
174
|
+
const knowledgeGaps = this.detectKnowledgeGaps(sessions.entities);
|
|
175
|
+
// Decision logic for suggestions
|
|
176
|
+
const suggestADR = repeatedFailures.length > 2 || this.detectArchitecturalGaps(sessions.entities);
|
|
177
|
+
const suggestResearch = knowledgeGaps.length > 0;
|
|
178
|
+
return {
|
|
179
|
+
suggestADR,
|
|
180
|
+
suggestResearch,
|
|
181
|
+
patterns: repeatedFailures,
|
|
182
|
+
recommendations: this.generateRecommendations(repeatedFailures, environmentalFactors),
|
|
183
|
+
knowledgeGaps,
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
catch (error) {
|
|
187
|
+
this.logger.error('Failed to analyze failure patterns', 'TroubleshootingMemoryManager', error);
|
|
188
|
+
throw error;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Trigger ADR suggestion based on failure patterns
|
|
193
|
+
*/
|
|
194
|
+
async triggerADRSuggestion(failureContext) {
|
|
195
|
+
try {
|
|
196
|
+
const { suggestAdrs } = await import('./adr-suggestion-tool.js');
|
|
197
|
+
return await suggestAdrs({
|
|
198
|
+
analysisType: 'comprehensive',
|
|
199
|
+
enhancedMode: true,
|
|
200
|
+
knowledgeEnhancement: true,
|
|
201
|
+
conversationContext: {
|
|
202
|
+
userGoals: ['Address recurring failures', 'Improve system reliability'],
|
|
203
|
+
focusAreas: ['architecture', 'reliability', 'troubleshooting'],
|
|
204
|
+
humanRequest: `Create ADR to address recurring ${failureContext.failureType} failures: ${failureContext.failureDetails.errorMessage}`,
|
|
205
|
+
projectPhase: 'improvement',
|
|
206
|
+
constraints: ['Must address root cause', 'Should prevent future occurrences'],
|
|
207
|
+
},
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
catch (error) {
|
|
211
|
+
this.logger.error('Failed to trigger ADR suggestion', 'TroubleshootingMemoryManager', error);
|
|
212
|
+
throw error;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Trigger research question generation for knowledge gaps
|
|
217
|
+
*/
|
|
218
|
+
async triggerResearchGeneration(knowledgeGaps) {
|
|
219
|
+
try {
|
|
220
|
+
const { generateResearchQuestions } = await import('./research-question-tool.js');
|
|
221
|
+
return await generateResearchQuestions({
|
|
222
|
+
analysisType: 'comprehensive',
|
|
223
|
+
researchContext: {
|
|
224
|
+
topic: 'Troubleshooting and System Reliability',
|
|
225
|
+
category: 'operational_excellence',
|
|
226
|
+
scope: 'failure_analysis',
|
|
227
|
+
objectives: [
|
|
228
|
+
'Understand root causes of recurring failures',
|
|
229
|
+
'Identify system reliability improvements',
|
|
230
|
+
'Document troubleshooting best practices',
|
|
231
|
+
'Develop proactive monitoring strategies',
|
|
232
|
+
],
|
|
233
|
+
constraints: ['Must be actionable', 'Should be measurable'],
|
|
234
|
+
timeline: '2-4 weeks',
|
|
235
|
+
},
|
|
236
|
+
problems: knowledgeGaps.map(gap => ({
|
|
237
|
+
id: gap.id,
|
|
238
|
+
description: gap.description,
|
|
239
|
+
category: 'troubleshooting',
|
|
240
|
+
severity: gap.severity,
|
|
241
|
+
context: gap.context,
|
|
242
|
+
})),
|
|
243
|
+
knowledgeEnhancement: true,
|
|
244
|
+
enhancedMode: true,
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
catch (error) {
|
|
248
|
+
this.logger.error('Failed to trigger research generation', 'TroubleshootingMemoryManager', error);
|
|
249
|
+
throw error;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
// Private helper methods
|
|
253
|
+
generateErrorSignature(failure) {
|
|
254
|
+
const errorMsg = failure.failureDetails.errorMessage.toLowerCase();
|
|
255
|
+
const command = failure.failureDetails.command?.toLowerCase() || '';
|
|
256
|
+
return `${failure.failureType}:${command}:${errorMsg.substring(0, 100)}`;
|
|
257
|
+
}
|
|
258
|
+
async calculateFailureFrequency(failureType) {
|
|
259
|
+
try {
|
|
260
|
+
const sessions = await this.memoryManager.queryEntities({
|
|
261
|
+
entityTypes: ['troubleshooting_session'],
|
|
262
|
+
limit: 50,
|
|
263
|
+
});
|
|
264
|
+
return sessions.entities.filter((s) => s.sessionData.failurePattern.failureType === failureType).length;
|
|
265
|
+
}
|
|
266
|
+
catch {
|
|
267
|
+
return 1;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
generatePreventionMeasures(failure) {
|
|
271
|
+
const measures = [];
|
|
272
|
+
switch (failure.failureType) {
|
|
273
|
+
case 'deployment_failure':
|
|
274
|
+
measures.push('Implement deployment health checks');
|
|
275
|
+
measures.push('Add environment validation scripts');
|
|
276
|
+
measures.push('Create deployment rollback procedures');
|
|
277
|
+
break;
|
|
278
|
+
case 'test_failure':
|
|
279
|
+
measures.push('Improve test environment consistency');
|
|
280
|
+
measures.push('Add test data validation');
|
|
281
|
+
measures.push('Implement test isolation mechanisms');
|
|
282
|
+
break;
|
|
283
|
+
case 'build_failure':
|
|
284
|
+
measures.push('Standardize build environment');
|
|
285
|
+
measures.push('Add dependency locking');
|
|
286
|
+
measures.push('Implement build reproducibility checks');
|
|
287
|
+
break;
|
|
288
|
+
case 'performance_issue':
|
|
289
|
+
measures.push('Add performance monitoring');
|
|
290
|
+
measures.push('Implement resource usage alerts');
|
|
291
|
+
measures.push('Create performance regression tests');
|
|
292
|
+
break;
|
|
293
|
+
case 'security_issue':
|
|
294
|
+
measures.push('Enhance security scanning');
|
|
295
|
+
measures.push('Implement security policy enforcement');
|
|
296
|
+
measures.push('Add vulnerability monitoring');
|
|
297
|
+
break;
|
|
298
|
+
default:
|
|
299
|
+
measures.push('Improve monitoring and alerting');
|
|
300
|
+
measures.push('Document troubleshooting procedures');
|
|
301
|
+
measures.push('Create failure response playbooks');
|
|
302
|
+
}
|
|
303
|
+
return measures;
|
|
304
|
+
}
|
|
305
|
+
async findRelatedADRs(_failure) {
|
|
306
|
+
// This would typically search for ADRs related to the failure context
|
|
307
|
+
// For now, return empty array - this will be enhanced when ADR search is integrated
|
|
308
|
+
return [];
|
|
309
|
+
}
|
|
310
|
+
extractEnvironmentContext(failure) {
|
|
311
|
+
return {
|
|
312
|
+
environment: failure.failureDetails.environment,
|
|
313
|
+
command: failure.failureDetails.command,
|
|
314
|
+
exitCode: failure.failureDetails.exitCode,
|
|
315
|
+
timestamp: failure.failureDetails.timestamp,
|
|
316
|
+
reproducible: failure.context?.reproducible,
|
|
317
|
+
frequency: failure.context?.frequency,
|
|
318
|
+
impact: failure.context?.impact,
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
async determineFollowUpActions(failure, effectiveness) {
|
|
322
|
+
const actions = [];
|
|
323
|
+
// Low effectiveness suggests need for research
|
|
324
|
+
if (effectiveness < 0.7) {
|
|
325
|
+
actions.push({
|
|
326
|
+
action: 'Generate research questions to improve troubleshooting approach',
|
|
327
|
+
type: 'research_generation',
|
|
328
|
+
priority: effectiveness < 0.5 ? 'high' : 'medium',
|
|
329
|
+
triggered: false,
|
|
330
|
+
reason: `Solution effectiveness (${effectiveness}) indicates knowledge gaps`,
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
// Architectural failure types suggest ADR needs
|
|
334
|
+
const architecturalTypes = ['deployment_failure', 'performance_issue', 'security_issue'];
|
|
335
|
+
if (architecturalTypes.includes(failure.failureType)) {
|
|
336
|
+
actions.push({
|
|
337
|
+
action: 'Suggest ADR to address architectural concerns',
|
|
338
|
+
type: 'adr_suggestion',
|
|
339
|
+
priority: 'medium',
|
|
340
|
+
triggered: false,
|
|
341
|
+
reason: `${failure.failureType} suggests architectural decision needed`,
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
// Always suggest process improvement for repeated failures
|
|
345
|
+
const frequency = await this.calculateFailureFrequency(failure.failureType);
|
|
346
|
+
if (frequency >= 3) {
|
|
347
|
+
actions.push({
|
|
348
|
+
action: 'Implement process improvements to prevent recurring failures',
|
|
349
|
+
type: 'process_improvement',
|
|
350
|
+
priority: 'high',
|
|
351
|
+
triggered: false,
|
|
352
|
+
reason: `${failure.failureType} has occurred ${frequency} times`,
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
return actions;
|
|
356
|
+
}
|
|
357
|
+
detectRepeatedFailures(failureTypes) {
|
|
358
|
+
const frequency = {};
|
|
359
|
+
failureTypes.forEach(type => {
|
|
360
|
+
frequency[type] = (frequency[type] || 0) + 1;
|
|
361
|
+
});
|
|
362
|
+
return Object.entries(frequency)
|
|
363
|
+
.filter(([_, count]) => count >= 3)
|
|
364
|
+
.map(([type, count]) => ({ type, frequency: count }));
|
|
365
|
+
}
|
|
366
|
+
detectArchitecturalGaps(sessions) {
|
|
367
|
+
const architecturalIndicators = ['deployment_failure', 'performance_issue', 'security_issue'];
|
|
368
|
+
return sessions.some(session => architecturalIndicators.includes(session.sessionData.failurePattern.failureType));
|
|
369
|
+
}
|
|
370
|
+
detectKnowledgeGaps(sessions) {
|
|
371
|
+
const patterns = sessions.filter(session => session.sessionData.solutionEffectiveness < 0.7);
|
|
372
|
+
return patterns.map(pattern => ({
|
|
373
|
+
id: pattern.id,
|
|
374
|
+
description: `Low solution effectiveness for ${pattern.sessionData.failurePattern.failureType}`,
|
|
375
|
+
severity: pattern.sessionData.solutionEffectiveness < 0.5 ? 'high' : 'medium',
|
|
376
|
+
context: pattern.sessionData.failurePattern.failureDetails.errorMessage,
|
|
377
|
+
}));
|
|
378
|
+
}
|
|
379
|
+
extractEnvironmentalFactors(sessions) {
|
|
380
|
+
const factors = new Set();
|
|
381
|
+
sessions.forEach(session => {
|
|
382
|
+
const env = session.sessionData.failurePattern.environments;
|
|
383
|
+
if (env && Array.isArray(env)) {
|
|
384
|
+
env.forEach(e => factors.add(e));
|
|
385
|
+
}
|
|
386
|
+
});
|
|
387
|
+
return Array.from(factors);
|
|
388
|
+
}
|
|
389
|
+
generateRecommendations(repeatedFailures, environmentalFactors) {
|
|
390
|
+
const recommendations = [];
|
|
391
|
+
if (repeatedFailures.length > 0) {
|
|
392
|
+
recommendations.push(`Address recurring ${repeatedFailures[0].type} failures with architectural decision`);
|
|
393
|
+
recommendations.push('Implement prevention measures for top failure patterns');
|
|
394
|
+
}
|
|
395
|
+
if (environmentalFactors.length > 1) {
|
|
396
|
+
recommendations.push('Standardize environments to reduce environment-specific failures');
|
|
397
|
+
}
|
|
398
|
+
recommendations.push('Build knowledge base from troubleshooting sessions');
|
|
399
|
+
recommendations.push('Create automated monitoring for detected failure patterns');
|
|
400
|
+
return recommendations;
|
|
401
|
+
}
|
|
402
|
+
}
|
|
36
403
|
/**
|
|
37
404
|
* Analyze structured failure information
|
|
38
405
|
*/
|
|
39
|
-
async function analyzeFailure(failure) {
|
|
406
|
+
async function analyzeFailure(failure, projectPath = process.cwd()) {
|
|
40
407
|
const report = [
|
|
41
408
|
'# 🚨 Failure Analysis',
|
|
42
409
|
'',
|
|
@@ -44,8 +411,57 @@ async function analyzeFailure(failure) {
|
|
|
44
411
|
'',
|
|
45
412
|
'## Error Details',
|
|
46
413
|
`**Primary Error**: ${failure.failureDetails.errorMessage}`,
|
|
47
|
-
''
|
|
414
|
+
'',
|
|
48
415
|
];
|
|
416
|
+
// Smart Code Linking - find files related to the failure
|
|
417
|
+
let relatedCodeAnalysis = '';
|
|
418
|
+
try {
|
|
419
|
+
// Create context from failure information for Smart Code Linking
|
|
420
|
+
const failureContext = [
|
|
421
|
+
`Failure Type: ${failure.failureType}`,
|
|
422
|
+
`Error Message: ${failure.failureDetails.errorMessage}`,
|
|
423
|
+
failure.failureDetails.command ? `Failed Command: ${failure.failureDetails.command}` : '',
|
|
424
|
+
failure.failureDetails.environment
|
|
425
|
+
? `Environment: ${failure.failureDetails.environment}`
|
|
426
|
+
: '',
|
|
427
|
+
failure.context?.recentChanges ? `Recent Changes: ${failure.context.recentChanges}` : '',
|
|
428
|
+
]
|
|
429
|
+
.filter(Boolean)
|
|
430
|
+
.join('\n');
|
|
431
|
+
// Find related code files using Smart Code Linking
|
|
432
|
+
const relatedCodeResult = await findRelatedCode('troubleshooting-failure-analysis', failureContext, projectPath, {
|
|
433
|
+
useAI: true,
|
|
434
|
+
useRipgrep: true,
|
|
435
|
+
maxFiles: 15,
|
|
436
|
+
includeContent: false,
|
|
437
|
+
});
|
|
438
|
+
if (relatedCodeResult.relatedFiles.length > 0) {
|
|
439
|
+
relatedCodeAnalysis = [
|
|
440
|
+
'',
|
|
441
|
+
'## 🔗 Smart Code Linking Analysis',
|
|
442
|
+
'',
|
|
443
|
+
`Found **${relatedCodeResult.relatedFiles.length}** files potentially related to this failure:`,
|
|
444
|
+
'',
|
|
445
|
+
...relatedCodeResult.relatedFiles
|
|
446
|
+
.slice(0, 10)
|
|
447
|
+
.map((file, index) => `${index + 1}. **${file.path}**`),
|
|
448
|
+
'',
|
|
449
|
+
relatedCodeResult.relatedFiles.length > 10
|
|
450
|
+
? `*Showing top 10 of ${relatedCodeResult.relatedFiles.length} related files*`
|
|
451
|
+
: '',
|
|
452
|
+
'',
|
|
453
|
+
`**Analysis Confidence**: ${(relatedCodeResult.confidence * 100).toFixed(0)}%`,
|
|
454
|
+
`**Keywords Used**: ${relatedCodeResult.keywords?.slice(0, 8).join(', ') || 'N/A'}`,
|
|
455
|
+
'',
|
|
456
|
+
]
|
|
457
|
+
.filter(Boolean)
|
|
458
|
+
.join('\n');
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
catch (error) {
|
|
462
|
+
// Don't fail the analysis if Smart Code Linking fails
|
|
463
|
+
console.warn('Smart Code Linking failed for failure analysis:', error);
|
|
464
|
+
}
|
|
49
465
|
// Add command and exit code if available
|
|
50
466
|
if (failure.failureDetails.command) {
|
|
51
467
|
report.push(`**Failed Command**: \`${failure.failureDetails.command}\``);
|
|
@@ -134,6 +550,10 @@ async function analyzeFailure(failure) {
|
|
|
134
550
|
report.push('3. **Verify configuration and dependencies**');
|
|
135
551
|
report.push('4. **Test in isolated environment**');
|
|
136
552
|
}
|
|
553
|
+
// Add Smart Code Linking analysis to the report
|
|
554
|
+
if (relatedCodeAnalysis) {
|
|
555
|
+
report.push(relatedCodeAnalysis);
|
|
556
|
+
}
|
|
137
557
|
report.push('');
|
|
138
558
|
report.push('*Use `generate_test_plan` operation to get specific commands and validation steps.*');
|
|
139
559
|
return report.join('\n');
|
|
@@ -147,6 +567,40 @@ async function generateTestPlan(failure, args) {
|
|
|
147
567
|
if (!isAIExecutionEnabled(aiConfig)) {
|
|
148
568
|
return generateFallbackTestPlan(failure, args);
|
|
149
569
|
}
|
|
570
|
+
// Smart Code Linking - gather project context for better test plan generation
|
|
571
|
+
let projectContext = '';
|
|
572
|
+
try {
|
|
573
|
+
const projectPath = args.projectPath || process.cwd();
|
|
574
|
+
// Find files related to the failure for better context
|
|
575
|
+
const failureContext = [
|
|
576
|
+
`Failure Type: ${failure.failureType}`,
|
|
577
|
+
`Error Message: ${failure.failureDetails.errorMessage}`,
|
|
578
|
+
failure.failureDetails.command ? `Failed Command: ${failure.failureDetails.command}` : '',
|
|
579
|
+
failure.failureDetails.environment
|
|
580
|
+
? `Environment: ${failure.failureDetails.environment}`
|
|
581
|
+
: '',
|
|
582
|
+
]
|
|
583
|
+
.filter(Boolean)
|
|
584
|
+
.join('\n');
|
|
585
|
+
const relatedCodeResult = await findRelatedCode('test-plan-generation', failureContext, projectPath, {
|
|
586
|
+
useAI: true,
|
|
587
|
+
useRipgrep: true,
|
|
588
|
+
maxFiles: 8,
|
|
589
|
+
includeContent: false,
|
|
590
|
+
});
|
|
591
|
+
if (relatedCodeResult.relatedFiles.length > 0) {
|
|
592
|
+
projectContext =
|
|
593
|
+
`\n\nProject Context (Smart Code Linking found ${relatedCodeResult.relatedFiles.length} related files):\n` +
|
|
594
|
+
relatedCodeResult.relatedFiles
|
|
595
|
+
.slice(0, 5)
|
|
596
|
+
.map(file => `- ${file.path}`)
|
|
597
|
+
.join('\n');
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
catch (error) {
|
|
601
|
+
// Don't fail test plan generation if Smart Code Linking fails
|
|
602
|
+
console.warn('Smart Code Linking failed for test plan generation:', error);
|
|
603
|
+
}
|
|
150
604
|
const systemPrompt = `You are an expert debugging assistant. Analyze the structured failure information and generate specific, actionable test commands.
|
|
151
605
|
|
|
152
606
|
Return a JSON response with this exact structure:
|
|
@@ -183,28 +637,28 @@ Be specific and contextual based on the actual failure details provided.`;
|
|
|
183
637
|
- Environment: ${failure.failureDetails.environment || 'N/A'}
|
|
184
638
|
- Project Path: ${args.projectPath || '.'}
|
|
185
639
|
${failure.failureDetails.stackTrace ? `- Stack Trace: ${failure.failureDetails.stackTrace.substring(0, 500)}...` : ''}
|
|
186
|
-
${failure.context?.recentChanges ? `- Recent Changes: ${failure.context.recentChanges}` : ''}
|
|
640
|
+
${failure.context?.recentChanges ? `- Recent Changes: ${failure.context.recentChanges}` : ''}${projectContext}
|
|
187
641
|
|
|
188
|
-
Generate specific test commands to diagnose and resolve this failure.`;
|
|
642
|
+
Generate specific test commands to diagnose and resolve this failure. Use the project context above to provide more targeted and relevant test commands.`;
|
|
189
643
|
try {
|
|
190
644
|
const response = await fetch(aiConfig.baseURL + '/chat/completions', {
|
|
191
645
|
method: 'POST',
|
|
192
646
|
headers: {
|
|
193
|
-
|
|
647
|
+
Authorization: `Bearer ${aiConfig.apiKey}`,
|
|
194
648
|
'Content-Type': 'application/json',
|
|
195
649
|
'HTTP-Referer': aiConfig.siteUrl || '',
|
|
196
|
-
'X-Title': aiConfig.siteName || ''
|
|
650
|
+
'X-Title': aiConfig.siteName || '',
|
|
197
651
|
},
|
|
198
652
|
body: JSON.stringify({
|
|
199
653
|
model: getRecommendedModel('analysis'),
|
|
200
654
|
messages: [
|
|
201
655
|
{ role: 'system', content: systemPrompt },
|
|
202
|
-
{ role: 'user', content: failureContext }
|
|
656
|
+
{ role: 'user', content: failureContext },
|
|
203
657
|
],
|
|
204
658
|
temperature: 0.2,
|
|
205
659
|
max_tokens: 2000,
|
|
206
|
-
response_format: { type: 'json_object' }
|
|
207
|
-
})
|
|
660
|
+
response_format: { type: 'json_object' },
|
|
661
|
+
}),
|
|
208
662
|
});
|
|
209
663
|
if (!response.ok) {
|
|
210
664
|
throw new Error(`OpenRouter API error: ${response.status}`);
|
|
@@ -217,7 +671,7 @@ Generate specific test commands to diagnose and resolve this failure.`;
|
|
|
217
671
|
const aiPlan = JSON.parse(planContent);
|
|
218
672
|
return formatAITestPlan(aiPlan.testPlan, args.projectPath || '.');
|
|
219
673
|
}
|
|
220
|
-
catch
|
|
674
|
+
catch {
|
|
221
675
|
// Fallback to hardcoded templates if AI fails
|
|
222
676
|
return generateFallbackTestPlan(failure, args);
|
|
223
677
|
}
|
|
@@ -233,7 +687,7 @@ function formatAITestPlan(testPlan, projectPath) {
|
|
|
233
687
|
testPlan.summary || 'AI analysis of the failure',
|
|
234
688
|
'',
|
|
235
689
|
`**Priority**: ${testPlan.priority?.toUpperCase() || 'MEDIUM'}`,
|
|
236
|
-
''
|
|
690
|
+
'',
|
|
237
691
|
];
|
|
238
692
|
if (testPlan.testSections && Array.isArray(testPlan.testSections)) {
|
|
239
693
|
testPlan.testSections.forEach((section, index) => {
|
|
@@ -300,7 +754,7 @@ function generateFallbackTestPlan(failure, args) {
|
|
|
300
754
|
`## For Failure Type: ${failure.failureType.toUpperCase()}`,
|
|
301
755
|
'',
|
|
302
756
|
'## Specific Commands to Execute',
|
|
303
|
-
''
|
|
757
|
+
'',
|
|
304
758
|
];
|
|
305
759
|
const projectPath = args.projectPath || '.';
|
|
306
760
|
switch (failure.failureType) {
|
|
@@ -436,7 +890,8 @@ function generateFallbackTestPlan(failure, args) {
|
|
|
436
890
|
/**
|
|
437
891
|
* Run the full troubleshooting workflow with actual tool integration
|
|
438
892
|
*/
|
|
439
|
-
async function runFullWorkflow(
|
|
893
|
+
async function runFullWorkflow(args) {
|
|
894
|
+
const projectPath = args.projectPath || process.cwd();
|
|
440
895
|
const report = [
|
|
441
896
|
'# 🔧 Guided Troubleshooting Workflow',
|
|
442
897
|
'',
|
|
@@ -447,8 +902,67 @@ async function runFullWorkflow(_args) {
|
|
|
447
902
|
'4. 🔄 Generate targeted questions',
|
|
448
903
|
'5. 🔄 ADR validation',
|
|
449
904
|
'6. 🔄 Guided recommendations',
|
|
450
|
-
''
|
|
905
|
+
'',
|
|
451
906
|
];
|
|
907
|
+
// Smart Code Linking - discover project structure for troubleshooting context
|
|
908
|
+
try {
|
|
909
|
+
// Find project files for comprehensive analysis
|
|
910
|
+
const findResult = await findFiles(projectPath, [
|
|
911
|
+
'**/*.{ts,js,py,yml,yaml,json,md}',
|
|
912
|
+
'!**/node_modules/**',
|
|
913
|
+
'!**/dist/**',
|
|
914
|
+
'!**/build/**',
|
|
915
|
+
]);
|
|
916
|
+
if (findResult.files.length > 0) {
|
|
917
|
+
report.push('## 📊 Project Discovery');
|
|
918
|
+
report.push(`Found **${findResult.files.length}** relevant files in project:`);
|
|
919
|
+
// Categorize files by type for troubleshooting context
|
|
920
|
+
const filesByType = findResult.files.reduce((acc, file) => {
|
|
921
|
+
const ext = file.path.split('.').pop()?.toLowerCase() || 'other';
|
|
922
|
+
acc[ext] = (acc[ext] || 0) + 1;
|
|
923
|
+
return acc;
|
|
924
|
+
}, {});
|
|
925
|
+
report.push('');
|
|
926
|
+
Object.entries(filesByType)
|
|
927
|
+
.sort(([, a], [, b]) => b - a)
|
|
928
|
+
.slice(0, 8)
|
|
929
|
+
.forEach(([ext, count]) => {
|
|
930
|
+
report.push(`- **${ext.toUpperCase()}**: ${count} files`);
|
|
931
|
+
});
|
|
932
|
+
report.push('');
|
|
933
|
+
// Smart Code Linking for general troubleshooting context
|
|
934
|
+
const troubleshootingContext = [
|
|
935
|
+
'troubleshooting workflow',
|
|
936
|
+
'error handling',
|
|
937
|
+
'logging',
|
|
938
|
+
'monitoring',
|
|
939
|
+
'testing',
|
|
940
|
+
'deployment',
|
|
941
|
+
'configuration',
|
|
942
|
+
].join(' ');
|
|
943
|
+
const relatedCodeResult = await findRelatedCode('troubleshooting-workflow-context', troubleshootingContext, projectPath, {
|
|
944
|
+
useAI: true,
|
|
945
|
+
useRipgrep: true,
|
|
946
|
+
maxFiles: 10,
|
|
947
|
+
includeContent: false,
|
|
948
|
+
});
|
|
949
|
+
if (relatedCodeResult.relatedFiles.length > 0) {
|
|
950
|
+
report.push('## 🔗 Troubleshooting-Relevant Files');
|
|
951
|
+
report.push('Files that may be relevant for troubleshooting:');
|
|
952
|
+
report.push('');
|
|
953
|
+
relatedCodeResult.relatedFiles.slice(0, 8).forEach((file, index) => {
|
|
954
|
+
report.push(`${index + 1}. **${file.path}**`);
|
|
955
|
+
});
|
|
956
|
+
report.push('');
|
|
957
|
+
report.push(`**Analysis Confidence**: ${(relatedCodeResult.confidence * 100).toFixed(0)}%`);
|
|
958
|
+
report.push('');
|
|
959
|
+
}
|
|
960
|
+
}
|
|
961
|
+
}
|
|
962
|
+
catch (error) {
|
|
963
|
+
// Don't fail the workflow if Smart Code Linking fails
|
|
964
|
+
console.warn('Smart Code Linking failed for workflow analysis:', error);
|
|
965
|
+
}
|
|
452
966
|
// Legacy workflow - simplified for backwards compatibility
|
|
453
967
|
// Legacy full workflow - provides overview of troubleshooting approach
|
|
454
968
|
report.push('## Step 2: Baseline Reality Check');
|
|
@@ -478,7 +992,123 @@ async function runFullWorkflow(_args) {
|
|
|
478
992
|
return report.join('\n');
|
|
479
993
|
}
|
|
480
994
|
/**
|
|
481
|
-
*
|
|
995
|
+
* Enhanced troubleshooting workflow with memory integration and intelligent decision triggering
|
|
996
|
+
*/
|
|
997
|
+
export async function troubleshootGuidedWorkflowEnhanced(args) {
|
|
998
|
+
try {
|
|
999
|
+
const validatedArgs = TroubleshootSchema.parse(args);
|
|
1000
|
+
// Initialize memory manager if enabled
|
|
1001
|
+
let memoryManager = null;
|
|
1002
|
+
if (args.enableMemoryIntegration !== false) {
|
|
1003
|
+
memoryManager = new TroubleshootingMemoryManager();
|
|
1004
|
+
await memoryManager.initialize();
|
|
1005
|
+
}
|
|
1006
|
+
// Execute original troubleshooting logic
|
|
1007
|
+
const result = await troubleshootGuidedWorkflow(validatedArgs);
|
|
1008
|
+
// Enhanced memory integration and intelligent suggestions
|
|
1009
|
+
if (memoryManager && validatedArgs.failure && args.solutionEffectiveness !== undefined) {
|
|
1010
|
+
try {
|
|
1011
|
+
// Store troubleshooting session
|
|
1012
|
+
await memoryManager.storeTroubleshootingSession(validatedArgs.failure, ['Analysis completed', 'Test plan generated', 'Solution provided'], args.solutionEffectiveness, args.resolutionTimeMinutes);
|
|
1013
|
+
// Analyze patterns and trigger intelligent suggestions
|
|
1014
|
+
const patternAnalysis = await memoryManager.analyzeFailurePatterns();
|
|
1015
|
+
// Enhance result with intelligent suggestions
|
|
1016
|
+
const enhancedResult = {
|
|
1017
|
+
...result,
|
|
1018
|
+
memoryIntegration: {
|
|
1019
|
+
sessionStored: true,
|
|
1020
|
+
patternAnalysis: {
|
|
1021
|
+
repeatedFailures: patternAnalysis.patterns.length,
|
|
1022
|
+
suggestionsTriggered: [],
|
|
1023
|
+
recommendations: patternAnalysis.recommendations,
|
|
1024
|
+
},
|
|
1025
|
+
},
|
|
1026
|
+
};
|
|
1027
|
+
// Trigger ADR suggestion if patterns detected
|
|
1028
|
+
if (patternAnalysis.suggestADR) {
|
|
1029
|
+
try {
|
|
1030
|
+
const adrSuggestion = await memoryManager.triggerADRSuggestion(validatedArgs.failure);
|
|
1031
|
+
enhancedResult.memoryIntegration.patternAnalysis.suggestionsTriggered.push({
|
|
1032
|
+
type: 'adr_suggestion',
|
|
1033
|
+
reason: 'Recurring failure patterns detected',
|
|
1034
|
+
patterns: patternAnalysis.patterns,
|
|
1035
|
+
suggestion: adrSuggestion,
|
|
1036
|
+
});
|
|
1037
|
+
}
|
|
1038
|
+
catch (error) {
|
|
1039
|
+
console.warn('Failed to trigger ADR suggestion:', error);
|
|
1040
|
+
}
|
|
1041
|
+
}
|
|
1042
|
+
// Trigger research generation if knowledge gaps detected
|
|
1043
|
+
if (patternAnalysis.suggestResearch) {
|
|
1044
|
+
try {
|
|
1045
|
+
const researchSuggestion = await memoryManager.triggerResearchGeneration(patternAnalysis.knowledgeGaps);
|
|
1046
|
+
enhancedResult.memoryIntegration.patternAnalysis.suggestionsTriggered.push({
|
|
1047
|
+
type: 'research_suggestion',
|
|
1048
|
+
reason: 'Knowledge gaps identified in troubleshooting',
|
|
1049
|
+
gaps: patternAnalysis.knowledgeGaps,
|
|
1050
|
+
suggestion: researchSuggestion,
|
|
1051
|
+
});
|
|
1052
|
+
}
|
|
1053
|
+
catch (error) {
|
|
1054
|
+
console.warn('Failed to trigger research generation:', error);
|
|
1055
|
+
}
|
|
1056
|
+
}
|
|
1057
|
+
// Add intelligent suggestions to the content
|
|
1058
|
+
if (enhancedResult.memoryIntegration.patternAnalysis.suggestionsTriggered.length > 0) {
|
|
1059
|
+
const originalContent = enhancedResult.content[0].text;
|
|
1060
|
+
const suggestions = enhancedResult.memoryIntegration.patternAnalysis.suggestionsTriggered;
|
|
1061
|
+
const suggestionText = [
|
|
1062
|
+
'',
|
|
1063
|
+
'---',
|
|
1064
|
+
'',
|
|
1065
|
+
'## 🧠 Intelligent Suggestions (Memory-Enhanced)',
|
|
1066
|
+
'',
|
|
1067
|
+
'Based on analysis of historical troubleshooting patterns:',
|
|
1068
|
+
'',
|
|
1069
|
+
];
|
|
1070
|
+
suggestions.forEach((suggestion) => {
|
|
1071
|
+
suggestionText.push(`### ${suggestion.type === 'adr_suggestion' ? '📋 ADR Suggestion' : '🔬 Research Suggestion'}`);
|
|
1072
|
+
suggestionText.push(`**Reason**: ${suggestion.reason}`);
|
|
1073
|
+
suggestionText.push('');
|
|
1074
|
+
if (suggestion.type === 'adr_suggestion' && suggestion.patterns) {
|
|
1075
|
+
suggestionText.push(`**Patterns Detected**: ${suggestion.patterns.map((p) => `${p.type} (${p.frequency}x)`).join(', ')}`);
|
|
1076
|
+
suggestionText.push('**Recommendation**: Create architectural decision to address recurring failures');
|
|
1077
|
+
}
|
|
1078
|
+
else if (suggestion.type === 'research_suggestion' && suggestion.gaps) {
|
|
1079
|
+
suggestionText.push(`**Knowledge Gaps**: ${suggestion.gaps.length} areas identified`);
|
|
1080
|
+
suggestionText.push('**Recommendation**: Generate research questions to improve troubleshooting effectiveness');
|
|
1081
|
+
}
|
|
1082
|
+
suggestionText.push('');
|
|
1083
|
+
});
|
|
1084
|
+
if (enhancedResult.memoryIntegration.patternAnalysis.recommendations.length > 0) {
|
|
1085
|
+
suggestionText.push('### 💡 Additional Recommendations');
|
|
1086
|
+
enhancedResult.memoryIntegration.patternAnalysis.recommendations.forEach((rec) => {
|
|
1087
|
+
suggestionText.push(`- ${rec}`);
|
|
1088
|
+
});
|
|
1089
|
+
suggestionText.push('');
|
|
1090
|
+
}
|
|
1091
|
+
suggestionText.push('*These suggestions are generated automatically based on troubleshooting session analysis and failure pattern recognition.*');
|
|
1092
|
+
enhancedResult.content[0].text = originalContent + suggestionText.join('\n');
|
|
1093
|
+
}
|
|
1094
|
+
return enhancedResult;
|
|
1095
|
+
}
|
|
1096
|
+
catch (memoryError) {
|
|
1097
|
+
console.warn('Memory integration failed, continuing with standard workflow:', memoryError);
|
|
1098
|
+
return result;
|
|
1099
|
+
}
|
|
1100
|
+
}
|
|
1101
|
+
return result;
|
|
1102
|
+
}
|
|
1103
|
+
catch (error) {
|
|
1104
|
+
if (error instanceof z.ZodError) {
|
|
1105
|
+
throw new McpAdrError(`Invalid input: ${error.errors.map(e => e.message).join(', ')}`, 'INVALID_INPUT');
|
|
1106
|
+
}
|
|
1107
|
+
throw new McpAdrError(`Enhanced troubleshooting workflow failed: ${error instanceof Error ? error.message : String(error)}`, 'TROUBLESHOOTING_ERROR');
|
|
1108
|
+
}
|
|
1109
|
+
}
|
|
1110
|
+
/**
|
|
1111
|
+
* Main troubleshooting workflow function (original implementation)
|
|
482
1112
|
*/
|
|
483
1113
|
export async function troubleshootGuidedWorkflow(args) {
|
|
484
1114
|
try {
|
|
@@ -489,7 +1119,7 @@ export async function troubleshootGuidedWorkflow(args) {
|
|
|
489
1119
|
if (!validatedArgs.failure) {
|
|
490
1120
|
throw new McpAdrError('Failure information is required for analyze_failure operation', 'INVALID_INPUT');
|
|
491
1121
|
}
|
|
492
|
-
result = await analyzeFailure(validatedArgs.failure);
|
|
1122
|
+
result = await analyzeFailure(validatedArgs.failure, validatedArgs.projectPath);
|
|
493
1123
|
break;
|
|
494
1124
|
case 'generate_test_plan':
|
|
495
1125
|
if (!validatedArgs.failure) {
|
|
@@ -504,10 +1134,12 @@ export async function troubleshootGuidedWorkflow(args) {
|
|
|
504
1134
|
throw new McpAdrError(`Unknown operation: ${validatedArgs.operation}`, 'INVALID_INPUT');
|
|
505
1135
|
}
|
|
506
1136
|
return {
|
|
507
|
-
content: [
|
|
1137
|
+
content: [
|
|
1138
|
+
{
|
|
508
1139
|
type: 'text',
|
|
509
|
-
text: result
|
|
510
|
-
}
|
|
1140
|
+
text: result,
|
|
1141
|
+
},
|
|
1142
|
+
],
|
|
511
1143
|
};
|
|
512
1144
|
}
|
|
513
1145
|
catch (error) {
|