erosolar-cli 2.0.4 → 2.1.1
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/agents/erosolar-security.rules.json +147 -0
- package/dist/capabilities/enhancedAnalysisCapability.d.ts +13 -0
- package/dist/capabilities/enhancedAnalysisCapability.d.ts.map +1 -0
- package/dist/capabilities/enhancedAnalysisCapability.js +20 -0
- package/dist/capabilities/enhancedAnalysisCapability.js.map +1 -0
- package/dist/capabilities/offsecOpsCapability.d.ts +6 -0
- package/dist/capabilities/offsecOpsCapability.d.ts.map +1 -0
- package/dist/capabilities/offsecOpsCapability.js +20 -0
- package/dist/capabilities/offsecOpsCapability.js.map +1 -0
- package/dist/capabilities/offsecSearchCapability.d.ts +12 -0
- package/dist/capabilities/offsecSearchCapability.d.ts.map +1 -0
- package/dist/capabilities/offsecSearchCapability.js +27 -0
- package/dist/capabilities/offsecSearchCapability.js.map +1 -0
- package/dist/capabilities/taoCapability.d.ts +6 -0
- package/dist/capabilities/taoCapability.d.ts.map +1 -0
- package/dist/capabilities/taoCapability.js +20 -0
- package/dist/capabilities/taoCapability.js.map +1 -0
- package/dist/capabilities/toolRegistry.d.ts +2 -1
- package/dist/capabilities/toolRegistry.d.ts.map +1 -1
- package/dist/capabilities/toolRegistry.js +6 -1
- package/dist/capabilities/toolRegistry.js.map +1 -1
- package/dist/contracts/agent-schemas.json +18 -19
- package/dist/contracts/tools.schema.json +38 -8
- package/dist/core/contextManager.d.ts +8 -2
- package/dist/core/contextManager.d.ts.map +1 -1
- package/dist/core/contextManager.js +15 -2
- package/dist/core/contextManager.js.map +1 -1
- package/dist/core/deepBugAnalyzer.d.ts +128 -0
- package/dist/core/deepBugAnalyzer.d.ts.map +1 -0
- package/dist/core/deepBugAnalyzer.js +406 -0
- package/dist/core/deepBugAnalyzer.js.map +1 -0
- package/dist/core/hypothesisEngine.d.ts +113 -0
- package/dist/core/hypothesisEngine.d.ts.map +1 -0
- package/dist/core/hypothesisEngine.js +264 -0
- package/dist/core/hypothesisEngine.js.map +1 -0
- package/dist/core/intelligentSummarizer.d.ts +79 -0
- package/dist/core/intelligentSummarizer.d.ts.map +1 -0
- package/dist/core/intelligentSummarizer.js +273 -0
- package/dist/core/intelligentSummarizer.js.map +1 -0
- package/dist/core/offsecAlphaZero.d.ts +3 -0
- package/dist/core/offsecAlphaZero.d.ts.map +1 -1
- package/dist/core/offsecAlphaZero.js +166 -5
- package/dist/core/offsecAlphaZero.js.map +1 -1
- package/dist/core/productTestHarness.d.ts +113 -0
- package/dist/core/productTestHarness.d.ts.map +1 -0
- package/dist/core/productTestHarness.js +345 -0
- package/dist/core/productTestHarness.js.map +1 -0
- package/dist/core/toolPatternAnalyzer.d.ts +87 -0
- package/dist/core/toolPatternAnalyzer.d.ts.map +1 -0
- package/dist/core/toolPatternAnalyzer.js +272 -0
- package/dist/core/toolPatternAnalyzer.js.map +1 -0
- package/dist/plugins/tools/enhancedAnalysis/enhancedAnalysisPlugin.d.ts +3 -0
- package/dist/plugins/tools/enhancedAnalysis/enhancedAnalysisPlugin.d.ts.map +1 -0
- package/dist/plugins/tools/enhancedAnalysis/enhancedAnalysisPlugin.js +14 -0
- package/dist/plugins/tools/enhancedAnalysis/enhancedAnalysisPlugin.js.map +1 -0
- package/dist/plugins/tools/enhancedCodeIntelligence/enhancedCodeIntelligencePlugin.d.ts +3 -0
- package/dist/plugins/tools/enhancedCodeIntelligence/enhancedCodeIntelligencePlugin.d.ts.map +1 -0
- package/dist/plugins/tools/enhancedCodeIntelligence/enhancedCodeIntelligencePlugin.js +12 -0
- package/dist/plugins/tools/enhancedCodeIntelligence/enhancedCodeIntelligencePlugin.js.map +1 -0
- package/dist/plugins/tools/enhancedDevWorkflow/enhancedDevWorkflowPlugin.d.ts +3 -0
- package/dist/plugins/tools/enhancedDevWorkflow/enhancedDevWorkflowPlugin.d.ts.map +1 -0
- package/dist/plugins/tools/enhancedDevWorkflow/enhancedDevWorkflowPlugin.js +12 -0
- package/dist/plugins/tools/enhancedDevWorkflow/enhancedDevWorkflowPlugin.js.map +1 -0
- package/dist/plugins/tools/nodeDefaults.d.ts.map +1 -1
- package/dist/plugins/tools/nodeDefaults.js +12 -0
- package/dist/plugins/tools/nodeDefaults.js.map +1 -1
- package/dist/plugins/tools/offsec/offsecOpsPlugin.d.ts +3 -0
- package/dist/plugins/tools/offsec/offsecOpsPlugin.d.ts.map +1 -0
- package/dist/plugins/tools/offsec/offsecOpsPlugin.js +10 -0
- package/dist/plugins/tools/offsec/offsecOpsPlugin.js.map +1 -0
- package/dist/plugins/tools/offsec/offsecSearchPlugin.d.ts +3 -0
- package/dist/plugins/tools/offsec/offsecSearchPlugin.d.ts.map +1 -0
- package/dist/plugins/tools/offsec/offsecSearchPlugin.js +12 -0
- package/dist/plugins/tools/offsec/offsecSearchPlugin.js.map +1 -0
- package/dist/plugins/tools/tao/taoPlugin.d.ts +3 -0
- package/dist/plugins/tools/tao/taoPlugin.d.ts.map +1 -0
- package/dist/plugins/tools/tao/taoPlugin.js +10 -0
- package/dist/plugins/tools/tao/taoPlugin.js.map +1 -0
- package/dist/shell/interactiveShell.d.ts +7 -0
- package/dist/shell/interactiveShell.d.ts.map +1 -1
- package/dist/shell/interactiveShell.js +70 -22
- package/dist/shell/interactiveShell.js.map +1 -1
- package/dist/shell/shellApp.js +1 -1
- package/dist/shell/shellApp.js.map +1 -1
- package/dist/shell/systemPrompt.d.ts.map +1 -1
- package/dist/shell/systemPrompt.js +3 -0
- package/dist/shell/systemPrompt.js.map +1 -1
- package/dist/tools/enhancedAnalysisTools.d.ts +9 -0
- package/dist/tools/enhancedAnalysisTools.d.ts.map +1 -0
- package/dist/tools/enhancedAnalysisTools.js +382 -0
- package/dist/tools/enhancedAnalysisTools.js.map +1 -0
- package/dist/tools/enhancedCodeIntelligenceTools.d.ts +1 -21
- package/dist/tools/enhancedCodeIntelligenceTools.d.ts.map +1 -1
- package/dist/tools/enhancedCodeIntelligenceTools.js +378 -256
- package/dist/tools/enhancedCodeIntelligenceTools.js.map +1 -1
- package/dist/tools/enhancedDevWorkflowTools.d.ts +2 -10
- package/dist/tools/enhancedDevWorkflowTools.d.ts.map +1 -1
- package/dist/tools/enhancedDevWorkflowTools.js +293 -165
- package/dist/tools/enhancedDevWorkflowTools.js.map +1 -1
- package/dist/tools/interactionTools.d.ts.map +1 -1
- package/dist/tools/interactionTools.js +55 -0
- package/dist/tools/interactionTools.js.map +1 -1
- package/dist/tools/offsec/offsecOperationsTools.d.ts +3 -0
- package/dist/tools/offsec/offsecOperationsTools.d.ts.map +1 -0
- package/dist/tools/offsec/offsecOperationsTools.js +333 -0
- package/dist/tools/offsec/offsecOperationsTools.js.map +1 -0
- package/dist/tools/offsecSearchTools.d.ts +3 -0
- package/dist/tools/offsecSearchTools.d.ts.map +1 -0
- package/dist/tools/offsecSearchTools.js +330 -0
- package/dist/tools/offsecSearchTools.js.map +1 -0
- package/dist/tools/taoOperations.d.ts +7 -0
- package/dist/tools/taoOperations.d.ts.map +1 -0
- package/dist/tools/taoOperations.js +744 -0
- package/dist/tools/taoOperations.js.map +1 -0
- package/dist/ui/PromptController.d.ts +5 -1
- package/dist/ui/PromptController.d.ts.map +1 -1
- package/dist/ui/PromptController.js +6 -0
- package/dist/ui/PromptController.js.map +1 -1
- package/dist/ui/ShellUIAdapter.d.ts +10 -6
- package/dist/ui/ShellUIAdapter.d.ts.map +1 -1
- package/dist/ui/ShellUIAdapter.js +68 -66
- package/dist/ui/ShellUIAdapter.js.map +1 -1
- package/dist/ui/UnifiedUIRenderer.d.ts +2 -0
- package/dist/ui/UnifiedUIRenderer.d.ts.map +1 -1
- package/dist/ui/UnifiedUIRenderer.js +22 -0
- package/dist/ui/UnifiedUIRenderer.js.map +1 -1
- package/dist/ui/globalWriteLock.d.ts.map +1 -1
- package/dist/ui/globalWriteLock.js +6 -0
- package/dist/ui/globalWriteLock.js.map +1 -1
- package/dist/ui/streamingFormatter.d.ts +11 -0
- package/dist/ui/streamingFormatter.d.ts.map +1 -1
- package/dist/ui/streamingFormatter.js +27 -1
- package/dist/ui/streamingFormatter.js.map +1 -1
- package/package.json +4 -13
|
@@ -0,0 +1,406 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deep Bug Analyzer with Multi-Causal Investigation
|
|
3
|
+
*
|
|
4
|
+
* This module provides comprehensive bug analysis that investigates multiple
|
|
5
|
+
* potential causes rather than stopping at the first plausible explanation.
|
|
6
|
+
*/
|
|
7
|
+
import { BugHypothesisAnalyzer } from './hypothesisEngine.js';
|
|
8
|
+
import { ProductTestHarness } from './productTestHarness.js';
|
|
9
|
+
/**
|
|
10
|
+
* Deep Bug Analyzer - Investigates multiple potential causes systematically
|
|
11
|
+
*/
|
|
12
|
+
export class DeepBugAnalyzer {
|
|
13
|
+
hypothesisAnalyzer;
|
|
14
|
+
testHarness;
|
|
15
|
+
constructor() {
|
|
16
|
+
this.hypothesisAnalyzer = new BugHypothesisAnalyzer();
|
|
17
|
+
this.testHarness = new ProductTestHarness();
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Analyze a bug by investigating all potential causes
|
|
21
|
+
*/
|
|
22
|
+
async analyze(bug, codeContext, // filename -> content
|
|
23
|
+
depth = 'deep') {
|
|
24
|
+
// Extract observations from bug report
|
|
25
|
+
const observations = this.extractObservations(bug);
|
|
26
|
+
// Generate causal factors across different categories
|
|
27
|
+
const causalFactors = await this.generateCausalFactors(bug, codeContext, observations, depth);
|
|
28
|
+
// Analyze using hypothesis engine
|
|
29
|
+
const { mostLikely, allHypotheses } = await this.hypothesisAnalyzer.analyzeBug(bug.description, observations, async (hypothesis) => this.generateTestsForHypothesis(hypothesis, bug, codeContext));
|
|
30
|
+
// Link hypotheses to causal factors
|
|
31
|
+
this.linkHypothesesToFactors(allHypotheses, causalFactors);
|
|
32
|
+
// Rank causal factors by evidence
|
|
33
|
+
const rankedFactors = this.rankCausalFactors(causalFactors);
|
|
34
|
+
// Generate recommended actions
|
|
35
|
+
const recommendedActions = this.generateRecommendedActions(rankedFactors, allHypotheses);
|
|
36
|
+
// Calculate overall confidence
|
|
37
|
+
const confidence = this.calculateAnalysisConfidence(rankedFactors, allHypotheses);
|
|
38
|
+
// Extract test results
|
|
39
|
+
const testResults = allHypotheses
|
|
40
|
+
.filter(h => h.testResults && h.testResults.length > 0)
|
|
41
|
+
.flatMap(h => h.testResults.map(t => ({
|
|
42
|
+
hypothesis: h.description,
|
|
43
|
+
passed: t.passed,
|
|
44
|
+
output: t.output,
|
|
45
|
+
})));
|
|
46
|
+
return {
|
|
47
|
+
primaryCause: rankedFactors[0] || null,
|
|
48
|
+
contributingFactors: rankedFactors.slice(1),
|
|
49
|
+
allHypotheses,
|
|
50
|
+
testResults,
|
|
51
|
+
recommendedActions,
|
|
52
|
+
confidence,
|
|
53
|
+
analysisDepth: depth,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Extract observations from bug report
|
|
58
|
+
*/
|
|
59
|
+
extractObservations(bug) {
|
|
60
|
+
const observations = [];
|
|
61
|
+
observations.push(`Bug: ${bug.description}`);
|
|
62
|
+
if (bug.expectedBehavior) {
|
|
63
|
+
observations.push(`Expected: ${bug.expectedBehavior}`);
|
|
64
|
+
}
|
|
65
|
+
if (bug.actualBehavior) {
|
|
66
|
+
observations.push(`Actual: ${bug.actualBehavior}`);
|
|
67
|
+
}
|
|
68
|
+
if (bug.stackTrace) {
|
|
69
|
+
observations.push(`Stack trace indicates: ${this.extractKeyFromStackTrace(bug.stackTrace)}`);
|
|
70
|
+
}
|
|
71
|
+
if (bug.environment) {
|
|
72
|
+
Object.entries(bug.environment).forEach(([key, value]) => {
|
|
73
|
+
observations.push(`Environment ${key}: ${value}`);
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
return observations;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Extract key information from stack trace
|
|
80
|
+
*/
|
|
81
|
+
extractKeyFromStackTrace(stackTrace) {
|
|
82
|
+
const lines = stackTrace.split('\n');
|
|
83
|
+
const errorLine = lines[0] || '';
|
|
84
|
+
const firstStackLine = lines.find(l => l.trim().startsWith('at '));
|
|
85
|
+
if (firstStackLine) {
|
|
86
|
+
return `${errorLine} (${firstStackLine.trim()})`;
|
|
87
|
+
}
|
|
88
|
+
return errorLine;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Generate causal factors across different categories
|
|
92
|
+
*/
|
|
93
|
+
async generateCausalFactors(bug, codeContext, observations, depth) {
|
|
94
|
+
const factors = [];
|
|
95
|
+
// Code-level factors
|
|
96
|
+
factors.push(...this.analyzeCodeFactors(bug, codeContext));
|
|
97
|
+
// Configuration factors
|
|
98
|
+
factors.push(...this.analyzeConfigurationFactors(bug));
|
|
99
|
+
// Environment factors
|
|
100
|
+
factors.push(...this.analyzeEnvironmentFactors(bug));
|
|
101
|
+
// Data factors
|
|
102
|
+
factors.push(...this.analyzeDataFactors(bug, observations));
|
|
103
|
+
// Timing/concurrency factors
|
|
104
|
+
factors.push(...this.analyzeTimingFactors(bug));
|
|
105
|
+
// Dependency factors
|
|
106
|
+
if (depth === 'deep' || depth === 'exhaustive') {
|
|
107
|
+
factors.push(...this.analyzeDependencyFactors(bug));
|
|
108
|
+
}
|
|
109
|
+
return factors;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Analyze code-level factors
|
|
113
|
+
*/
|
|
114
|
+
analyzeCodeFactors(bug, codeContext) {
|
|
115
|
+
const factors = [];
|
|
116
|
+
// Check for common code patterns that cause bugs
|
|
117
|
+
for (const [filename, content] of codeContext) {
|
|
118
|
+
// Null/undefined checks
|
|
119
|
+
if (this.hasUncheckedNullAccess(content)) {
|
|
120
|
+
factors.push({
|
|
121
|
+
category: 'code',
|
|
122
|
+
description: `Potential null/undefined access in ${filename}`,
|
|
123
|
+
likelihood: 0.7,
|
|
124
|
+
evidence: ['Code contains property access without null checks'],
|
|
125
|
+
suggestedFix: 'Add null/undefined checks before accessing properties',
|
|
126
|
+
relatedHypotheses: [],
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
// Async/await issues
|
|
130
|
+
if (this.hasMissingAwait(content)) {
|
|
131
|
+
factors.push({
|
|
132
|
+
category: 'code',
|
|
133
|
+
description: `Missing await on async function in ${filename}`,
|
|
134
|
+
likelihood: 0.6,
|
|
135
|
+
evidence: ['Async function called without await'],
|
|
136
|
+
suggestedFix: 'Add await keyword to async function calls',
|
|
137
|
+
relatedHypotheses: [],
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
// Type mismatches
|
|
141
|
+
if (this.hasTypeCoercionIssues(content)) {
|
|
142
|
+
factors.push({
|
|
143
|
+
category: 'code',
|
|
144
|
+
description: `Potential type coercion issue in ${filename}`,
|
|
145
|
+
likelihood: 0.5,
|
|
146
|
+
evidence: ['Code contains == instead of === comparisons'],
|
|
147
|
+
suggestedFix: 'Use strict equality (===) instead of loose equality (==)',
|
|
148
|
+
relatedHypotheses: [],
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return factors;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Check for unchecked null/undefined access
|
|
156
|
+
*/
|
|
157
|
+
hasUncheckedNullAccess(code) {
|
|
158
|
+
// Simple heuristic: look for property access without null checks nearby
|
|
159
|
+
const propertyAccessPattern = /\w+\.\w+/g;
|
|
160
|
+
const nullCheckPattern = /if\s*\([^)]*!==?\s*null|if\s*\([^)]*!==?\s*undefined|\?\./g;
|
|
161
|
+
const hasPropertyAccess = propertyAccessPattern.test(code);
|
|
162
|
+
const hasNullChecks = nullCheckPattern.test(code);
|
|
163
|
+
return hasPropertyAccess && !hasNullChecks;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Check for missing await on async functions
|
|
167
|
+
*/
|
|
168
|
+
hasMissingAwait(code) {
|
|
169
|
+
// Look for async function calls without await
|
|
170
|
+
const asyncCallPattern = /(\w+)\s*\([^)]*\)\s*(?!\.then|\.catch)/g;
|
|
171
|
+
const awaitPattern = /await\s+/g;
|
|
172
|
+
const asyncCalls = code.match(asyncCallPattern) || [];
|
|
173
|
+
const awaits = code.match(awaitPattern) || [];
|
|
174
|
+
return asyncCalls.length > awaits.length;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Check for type coercion issues
|
|
178
|
+
*/
|
|
179
|
+
hasTypeCoercionIssues(code) {
|
|
180
|
+
return /==(?!=)/g.test(code); // Look for == but not ===
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Analyze configuration factors
|
|
184
|
+
*/
|
|
185
|
+
analyzeConfigurationFactors(bug) {
|
|
186
|
+
const factors = [];
|
|
187
|
+
if (bug.environment) {
|
|
188
|
+
// Check for common configuration issues
|
|
189
|
+
const nodeEnv = bug.environment['NODE_ENV'];
|
|
190
|
+
if (nodeEnv === 'production' && bug.description.includes('development')) {
|
|
191
|
+
factors.push({
|
|
192
|
+
category: 'configuration',
|
|
193
|
+
description: 'Environment mismatch: running production code with development expectations',
|
|
194
|
+
likelihood: 0.8,
|
|
195
|
+
evidence: ['NODE_ENV is production but bug mentions development'],
|
|
196
|
+
suggestedFix: 'Ensure environment variables match intended runtime',
|
|
197
|
+
relatedHypotheses: [],
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
return factors;
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Analyze environment factors
|
|
205
|
+
*/
|
|
206
|
+
analyzeEnvironmentFactors(bug) {
|
|
207
|
+
const factors = [];
|
|
208
|
+
if (bug.environment) {
|
|
209
|
+
const nodeVersion = bug.environment['NODE_VERSION'];
|
|
210
|
+
if (nodeVersion && typeof nodeVersion === 'string' && parseFloat(nodeVersion) < 18) {
|
|
211
|
+
factors.push({
|
|
212
|
+
category: 'environment',
|
|
213
|
+
description: 'Node.js version may not support required features',
|
|
214
|
+
likelihood: 0.6,
|
|
215
|
+
evidence: [`Node version ${nodeVersion} is below recommended 18+`],
|
|
216
|
+
suggestedFix: 'Upgrade to Node.js 18 or higher',
|
|
217
|
+
relatedHypotheses: [],
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
return factors;
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Analyze data-related factors
|
|
225
|
+
*/
|
|
226
|
+
analyzeDataFactors(bug, observations) {
|
|
227
|
+
const factors = [];
|
|
228
|
+
// Check for data-related keywords in observations
|
|
229
|
+
const dataKeywords = ['empty', 'null', 'undefined', 'missing', 'invalid'];
|
|
230
|
+
const hasDataIssue = observations.some(obs => dataKeywords.some(keyword => obs.toLowerCase().includes(keyword)));
|
|
231
|
+
if (hasDataIssue) {
|
|
232
|
+
factors.push({
|
|
233
|
+
category: 'data',
|
|
234
|
+
description: 'Input data validation or handling issue',
|
|
235
|
+
likelihood: 0.65,
|
|
236
|
+
evidence: observations.filter(obs => dataKeywords.some(keyword => obs.toLowerCase().includes(keyword))),
|
|
237
|
+
suggestedFix: 'Add input validation and handle edge cases (null, undefined, empty)',
|
|
238
|
+
relatedHypotheses: [],
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
return factors;
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Analyze timing/concurrency factors
|
|
245
|
+
*/
|
|
246
|
+
analyzeTimingFactors(bug) {
|
|
247
|
+
const factors = [];
|
|
248
|
+
const timingKeywords = ['race', 'timing', 'concurrent', 'async', 'promise', 'setTimeout'];
|
|
249
|
+
const hasTimingIssue = timingKeywords.some(keyword => bug.description.toLowerCase().includes(keyword));
|
|
250
|
+
if (hasTimingIssue) {
|
|
251
|
+
factors.push({
|
|
252
|
+
category: 'timing',
|
|
253
|
+
description: 'Race condition or async timing issue',
|
|
254
|
+
likelihood: 0.7,
|
|
255
|
+
evidence: ['Bug description mentions timing-related keywords'],
|
|
256
|
+
suggestedFix: 'Review async code flow and add proper synchronization',
|
|
257
|
+
relatedHypotheses: [],
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
return factors;
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Analyze dependency factors
|
|
264
|
+
*/
|
|
265
|
+
analyzeDependencyFactors(bug) {
|
|
266
|
+
const factors = [];
|
|
267
|
+
// Check stack trace for dependency mentions
|
|
268
|
+
if (bug.stackTrace) {
|
|
269
|
+
const nodeModulesPattern = /node_modules[/\\]([^/\\]+)/g;
|
|
270
|
+
const matches = [...bug.stackTrace.matchAll(nodeModulesPattern)];
|
|
271
|
+
if (matches.length > 0) {
|
|
272
|
+
const dependencies = [...new Set(matches.map(m => m[1]))];
|
|
273
|
+
factors.push({
|
|
274
|
+
category: 'dependency',
|
|
275
|
+
description: `Potential issue in dependencies: ${dependencies.join(', ')}`,
|
|
276
|
+
likelihood: 0.5,
|
|
277
|
+
evidence: [`Stack trace includes: ${dependencies.join(', ')}`],
|
|
278
|
+
suggestedFix: 'Check dependency versions and update if needed',
|
|
279
|
+
relatedHypotheses: [],
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
return factors;
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Generate tests for a hypothesis
|
|
287
|
+
*/
|
|
288
|
+
async generateTestsForHypothesis(hypothesis, bug, codeContext) {
|
|
289
|
+
const tests = [];
|
|
290
|
+
// Generate test based on hypothesis description
|
|
291
|
+
if (hypothesis.description.includes('null')) {
|
|
292
|
+
tests.push({
|
|
293
|
+
name: 'null_input_test',
|
|
294
|
+
description: 'Test with null input',
|
|
295
|
+
execute: async () => {
|
|
296
|
+
// Simple test - in real implementation would execute against actual code
|
|
297
|
+
return !bug.description.toLowerCase().includes('null');
|
|
298
|
+
},
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
if (hypothesis.description.includes('async') || hypothesis.description.includes('timing')) {
|
|
302
|
+
tests.push({
|
|
303
|
+
name: 'async_timing_test',
|
|
304
|
+
description: 'Test async timing behavior',
|
|
305
|
+
execute: async () => {
|
|
306
|
+
return !bug.description.toLowerCase().includes('race');
|
|
307
|
+
},
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
if (hypothesis.description.includes('type')) {
|
|
311
|
+
tests.push({
|
|
312
|
+
name: 'type_check_test',
|
|
313
|
+
description: 'Test type handling',
|
|
314
|
+
execute: async () => {
|
|
315
|
+
return !bug.description.toLowerCase().includes('type error');
|
|
316
|
+
},
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
return tests;
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* Link hypotheses to causal factors
|
|
323
|
+
*/
|
|
324
|
+
linkHypothesesToFactors(hypotheses, factors) {
|
|
325
|
+
for (const hypothesis of hypotheses) {
|
|
326
|
+
for (const factor of factors) {
|
|
327
|
+
// Simple keyword matching - could be more sophisticated
|
|
328
|
+
const hypothesisKeywords = hypothesis.description.toLowerCase().split(' ');
|
|
329
|
+
const factorKeywords = factor.description.toLowerCase().split(' ');
|
|
330
|
+
const overlap = hypothesisKeywords.filter(k => factorKeywords.includes(k));
|
|
331
|
+
if (overlap.length > 2) {
|
|
332
|
+
factor.relatedHypotheses.push(hypothesis.id);
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* Rank causal factors by likelihood and evidence
|
|
339
|
+
*/
|
|
340
|
+
rankCausalFactors(factors) {
|
|
341
|
+
return factors.sort((a, b) => {
|
|
342
|
+
// First sort by likelihood
|
|
343
|
+
if (Math.abs(a.likelihood - b.likelihood) > 0.1) {
|
|
344
|
+
return b.likelihood - a.likelihood;
|
|
345
|
+
}
|
|
346
|
+
// Then by amount of evidence
|
|
347
|
+
return b.evidence.length - a.evidence.length;
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
351
|
+
* Generate recommended actions
|
|
352
|
+
*/
|
|
353
|
+
generateRecommendedActions(factors, hypotheses) {
|
|
354
|
+
const actions = [];
|
|
355
|
+
// Add actions from top causal factors
|
|
356
|
+
factors.slice(0, 5).forEach((factor, index) => {
|
|
357
|
+
if (factor.suggestedFix) {
|
|
358
|
+
actions.push(`${index + 1}. ${factor.suggestedFix} (${(factor.likelihood * 100).toFixed(0)}% likely)`);
|
|
359
|
+
}
|
|
360
|
+
});
|
|
361
|
+
// Add actions from validated hypotheses
|
|
362
|
+
const validated = hypotheses.filter(h => h.status === 'validated');
|
|
363
|
+
if (validated.length > 0) {
|
|
364
|
+
actions.push('\nValidated hypothesis-based actions:');
|
|
365
|
+
validated.forEach(h => {
|
|
366
|
+
actions.push(`- Address: ${h.description}`);
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
return actions;
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* Calculate overall analysis confidence
|
|
373
|
+
*/
|
|
374
|
+
calculateAnalysisConfidence(factors, hypotheses) {
|
|
375
|
+
if (factors.length === 0)
|
|
376
|
+
return 0;
|
|
377
|
+
// Base confidence on top factor likelihood
|
|
378
|
+
const topFactorConfidence = factors[0]?.likelihood || 0;
|
|
379
|
+
// Boost if we have validated hypotheses
|
|
380
|
+
const validatedCount = hypotheses.filter(h => h.status === 'validated').length;
|
|
381
|
+
const validatedBoost = Math.min(0.2, validatedCount * 0.05);
|
|
382
|
+
// Penalty if we have many equally likely factors (uncertainty)
|
|
383
|
+
const topThree = factors.slice(0, 3);
|
|
384
|
+
const likelihoodVariance = this.calculateVariance(topThree.map(f => f.likelihood));
|
|
385
|
+
const uncertaintyPenalty = likelihoodVariance < 0.05 ? 0.1 : 0;
|
|
386
|
+
return Math.max(0, Math.min(1, topFactorConfidence + validatedBoost - uncertaintyPenalty));
|
|
387
|
+
}
|
|
388
|
+
/**
|
|
389
|
+
* Calculate variance of numbers
|
|
390
|
+
*/
|
|
391
|
+
calculateVariance(numbers) {
|
|
392
|
+
if (numbers.length === 0)
|
|
393
|
+
return 0;
|
|
394
|
+
const mean = numbers.reduce((sum, n) => sum + n, 0) / numbers.length;
|
|
395
|
+
const squaredDiffs = numbers.map(n => Math.pow(n - mean, 2));
|
|
396
|
+
return squaredDiffs.reduce((sum, d) => sum + d, 0) / numbers.length;
|
|
397
|
+
}
|
|
398
|
+
/**
|
|
399
|
+
* Clear analysis state
|
|
400
|
+
*/
|
|
401
|
+
clear() {
|
|
402
|
+
this.hypothesisAnalyzer.clear();
|
|
403
|
+
this.testHarness.clear();
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
//# sourceMappingURL=deepBugAnalyzer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deepBugAnalyzer.js","sourceRoot":"","sources":["../../src/core/deepBugAnalyzer.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAoB,qBAAqB,EAAwC,MAAM,uBAAuB,CAAC;AACtH,OAAO,EAAE,kBAAkB,EAA+C,MAAM,yBAAyB,CAAC;AAgC1G;;GAEG;AACH,MAAM,OAAO,eAAe;IAClB,kBAAkB,CAAwB;IAC1C,WAAW,CAAqB;IAExC;QACE,IAAI,CAAC,kBAAkB,GAAG,IAAI,qBAAqB,EAAE,CAAC;QACtD,IAAI,CAAC,WAAW,GAAG,IAAI,kBAAkB,EAAE,CAAC;IAC9C,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,OAAO,CACX,GAAc,EACd,WAAgC,EAAE,sBAAsB;IACxD,QAAwD,MAAM;QAE9D,uCAAuC;QACvC,MAAM,YAAY,GAAG,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,CAAC;QAEnD,sDAAsD;QACtD,MAAM,aAAa,GAAG,MAAM,IAAI,CAAC,qBAAqB,CAAC,GAAG,EAAE,WAAW,EAAE,YAAY,EAAE,KAAK,CAAC,CAAC;QAE9F,kCAAkC;QAClC,MAAM,EAAE,UAAU,EAAE,aAAa,EAAE,GAAG,MAAM,IAAI,CAAC,kBAAkB,CAAC,UAAU,CAC5E,GAAG,CAAC,WAAW,EACf,Y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K;QACH,IAAI,CAAC,kBAAkB,CAAC,KAAK,EAAE,CAAC;QAChC,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC;IAC3B,CAAC;CACF"}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Enhanced AI Reasoning Engine with Hypothesis Testing
|
|
3
|
+
*
|
|
4
|
+
* This module provides multi-hypothesis reasoning capabilities to ensure
|
|
5
|
+
* correct AI operations by testing multiple approaches before settling on
|
|
6
|
+
* a solution.
|
|
7
|
+
*/
|
|
8
|
+
export interface Hypothesis {
|
|
9
|
+
id: string;
|
|
10
|
+
description: string;
|
|
11
|
+
confidence: number;
|
|
12
|
+
evidence: Evidence[];
|
|
13
|
+
testResults?: TestResult[];
|
|
14
|
+
status: 'pending' | 'testing' | 'validated' | 'rejected';
|
|
15
|
+
}
|
|
16
|
+
export interface Evidence {
|
|
17
|
+
type: 'observation' | 'data' | 'test_result' | 'user_feedback';
|
|
18
|
+
content: string;
|
|
19
|
+
weight: number;
|
|
20
|
+
timestamp: Date;
|
|
21
|
+
}
|
|
22
|
+
export interface TestResult {
|
|
23
|
+
testName: string;
|
|
24
|
+
passed: boolean;
|
|
25
|
+
output: string;
|
|
26
|
+
duration: number;
|
|
27
|
+
timestamp: Date;
|
|
28
|
+
}
|
|
29
|
+
export interface HypothesisTest {
|
|
30
|
+
name: string;
|
|
31
|
+
execute: () => Promise<boolean>;
|
|
32
|
+
description: string;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Engine for generating, testing, and validating hypotheses
|
|
36
|
+
*/
|
|
37
|
+
export declare class HypothesisEngine {
|
|
38
|
+
private hypotheses;
|
|
39
|
+
private readonly maxHypotheses;
|
|
40
|
+
constructor(maxHypotheses?: number);
|
|
41
|
+
/**
|
|
42
|
+
* Generate a new hypothesis
|
|
43
|
+
*/
|
|
44
|
+
generateHypothesis(description: string, initialEvidence?: Evidence[]): Hypothesis;
|
|
45
|
+
/**
|
|
46
|
+
* Add evidence to a hypothesis and update confidence
|
|
47
|
+
*/
|
|
48
|
+
addEvidence(hypothesisId: string, evidence: Evidence): void;
|
|
49
|
+
/**
|
|
50
|
+
* Test a hypothesis with a set of tests
|
|
51
|
+
*/
|
|
52
|
+
testHypothesis(hypothesisId: string, tests: HypothesisTest[]): Promise<TestResult[]>;
|
|
53
|
+
/**
|
|
54
|
+
* Get the most promising hypothesis based on confidence
|
|
55
|
+
*/
|
|
56
|
+
getBestHypothesis(): Hypothesis | null;
|
|
57
|
+
/**
|
|
58
|
+
* Get all hypotheses sorted by confidence
|
|
59
|
+
*/
|
|
60
|
+
getAllHypotheses(): Hypothesis[];
|
|
61
|
+
/**
|
|
62
|
+
* Get hypothesis by ID
|
|
63
|
+
*/
|
|
64
|
+
getHypothesis(id: string): Hypothesis | undefined;
|
|
65
|
+
/**
|
|
66
|
+
* Clear all hypotheses
|
|
67
|
+
*/
|
|
68
|
+
clear(): void;
|
|
69
|
+
/**
|
|
70
|
+
* Calculate initial confidence based on evidence
|
|
71
|
+
*/
|
|
72
|
+
private calculateInitialConfidence;
|
|
73
|
+
/**
|
|
74
|
+
* Recalculate confidence based on all evidence
|
|
75
|
+
*/
|
|
76
|
+
private recalculateConfidence;
|
|
77
|
+
/**
|
|
78
|
+
* Prune low-confidence hypotheses if we exceed max
|
|
79
|
+
*/
|
|
80
|
+
private pruneHypotheses;
|
|
81
|
+
/**
|
|
82
|
+
* Generate unique ID for hypothesis
|
|
83
|
+
*/
|
|
84
|
+
private generateId;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Multi-hypothesis bug analyzer
|
|
88
|
+
*/
|
|
89
|
+
export declare class BugHypothesisAnalyzer {
|
|
90
|
+
private engine;
|
|
91
|
+
constructor();
|
|
92
|
+
/**
|
|
93
|
+
* Analyze a bug by generating and testing multiple hypotheses
|
|
94
|
+
*/
|
|
95
|
+
analyzeBug(bugDescription: string, observations: string[], testFunction: (hypothesis: Hypothesis) => Promise<HypothesisTest[]>): Promise<{
|
|
96
|
+
mostLikely: Hypothesis | null;
|
|
97
|
+
allHypotheses: Hypothesis[];
|
|
98
|
+
recommendation: string;
|
|
99
|
+
}>;
|
|
100
|
+
/**
|
|
101
|
+
* Generate multiple hypotheses for a bug
|
|
102
|
+
*/
|
|
103
|
+
private generateBugHypotheses;
|
|
104
|
+
/**
|
|
105
|
+
* Generate recommendation based on hypothesis analysis
|
|
106
|
+
*/
|
|
107
|
+
private generateRecommendation;
|
|
108
|
+
/**
|
|
109
|
+
* Clear analysis state
|
|
110
|
+
*/
|
|
111
|
+
clear(): void;
|
|
112
|
+
}
|
|
113
|
+
//# sourceMappingURL=hypothesisEngine.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hypothesisEngine.d.ts","sourceRoot":"","sources":["../../src/core/hypothesisEngine.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,QAAQ,EAAE,CAAC;IACrB,WAAW,CAAC,EAAE,UAAU,EAAE,CAAC;IAC3B,MAAM,EAAE,SAAS,GAAG,SAAS,GAAG,WAAW,GAAG,UAAU,CAAC;CAC1D;AAED,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,aAAa,GAAG,MAAM,GAAG,aAAa,GAAG,eAAe,CAAC;IAC/D,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,IAAI,CAAC;CACjB;AAED,MAAM,WAAW,UAAU;IACzB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,OAAO,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,IAAI,CAAC;CACjB;AAED,MAAM,WAAW,cAAc;IAC7B,IAA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