atlas-pipeline-mcp 1.0.16 → 1.0.18
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 +45 -1
- package/dist/mcp.js +263 -0
- package/dist/mcp.js.map +1 -1
- package/dist/providers/llm-provider.d.ts +60 -25
- package/dist/providers/llm-provider.d.ts.map +1 -1
- package/dist/providers/llm-provider.js +154 -73
- package/dist/providers/llm-provider.js.map +1 -1
- package/dist/server.js +3 -3
- package/dist/server.js.map +1 -1
- package/dist/tools/context.js.map +1 -1
- package/dist/tools/critique.d.ts.map +1 -1
- package/dist/tools/critique.js +4 -3
- package/dist/tools/critique.js.map +1 -1
- package/dist/tools/debug.d.ts +101 -0
- package/dist/tools/debug.d.ts.map +1 -0
- package/dist/tools/debug.js +712 -0
- package/dist/tools/debug.js.map +1 -0
- package/dist/tools/decompose.d.ts.map +1 -1
- package/dist/tools/decompose.js +40 -28
- package/dist/tools/decompose.js.map +1 -1
- package/dist/tools/docs.d.ts +94 -0
- package/dist/tools/docs.d.ts.map +1 -0
- package/dist/tools/docs.js +508 -0
- package/dist/tools/docs.js.map +1 -0
- package/dist/tools/explain.d.ts +82 -0
- package/dist/tools/explain.d.ts.map +1 -0
- package/dist/tools/explain.js +543 -0
- package/dist/tools/explain.js.map +1 -0
- package/dist/tools/intent.d.ts.map +1 -1
- package/dist/tools/intent.js +33 -20
- package/dist/tools/intent.js.map +1 -1
- package/dist/tools/optimize.d.ts.map +1 -1
- package/dist/tools/optimize.js +18 -3
- package/dist/tools/optimize.js.map +1 -1
- package/dist/tools/security.d.ts +45 -0
- package/dist/tools/security.d.ts.map +1 -0
- package/dist/tools/security.js +417 -0
- package/dist/tools/security.js.map +1 -0
- package/dist/tools/testgen.d.ts +52 -0
- package/dist/tools/testgen.d.ts.map +1 -0
- package/dist/tools/testgen.js +413 -0
- package/dist/tools/testgen.js.map +1 -0
- package/dist/tools/think.d.ts +187 -0
- package/dist/tools/think.d.ts.map +1 -0
- package/dist/tools/think.js +432 -0
- package/dist/tools/think.js.map +1 -0
- package/dist/tools/variants.d.ts.map +1 -1
- package/dist/tools/variants.js +41 -29
- package/dist/tools/variants.js.map +1 -1
- package/dist/types.d.ts +77 -20
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +21 -0
- package/dist/types.js.map +1 -1
- package/dist/utils.d.ts +108 -12
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +302 -68
- package/dist/utils.js.map +1 -1
- package/package.json +2 -3
|
@@ -0,0 +1,543 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Atlas Server - Code Explanation Tool
|
|
3
|
+
*
|
|
4
|
+
* Intelligent code explanation capabilities:
|
|
5
|
+
* - Line-by-line explanation
|
|
6
|
+
* - Algorithm analysis
|
|
7
|
+
* - Complexity analysis (Big O)
|
|
8
|
+
* - Design pattern identification
|
|
9
|
+
* - Dependency explanation
|
|
10
|
+
* - Beginner-friendly mode
|
|
11
|
+
*/
|
|
12
|
+
import { getActiveProvider, isNoLLMMode } from '../providers/index.js';
|
|
13
|
+
import { logger } from '../utils.js';
|
|
14
|
+
// ============================================================================
|
|
15
|
+
// Code Explanation
|
|
16
|
+
// ============================================================================
|
|
17
|
+
/**
|
|
18
|
+
* Generate an explanation for the given code
|
|
19
|
+
*/
|
|
20
|
+
export async function explainCode(code, options = {}) {
|
|
21
|
+
const { level = 'intermediate', type = 'overview', language, focusArea, includeComplexity = true, includePatterns = true, } = options;
|
|
22
|
+
logger.debug({ level, type, codeLength: code.length }, 'Starting code explanation');
|
|
23
|
+
// Detect language
|
|
24
|
+
const detectedLanguage = language ?? detectLanguage(code);
|
|
25
|
+
// Analyze code structure
|
|
26
|
+
const structure = analyzeCodeStructure(code, detectedLanguage);
|
|
27
|
+
// Generate explanation
|
|
28
|
+
let explanation;
|
|
29
|
+
if (!isNoLLMMode()) {
|
|
30
|
+
try {
|
|
31
|
+
explanation = await explainWithAI(code, {
|
|
32
|
+
level,
|
|
33
|
+
type,
|
|
34
|
+
language: detectedLanguage,
|
|
35
|
+
focusArea,
|
|
36
|
+
includeComplexity,
|
|
37
|
+
includePatterns,
|
|
38
|
+
structure,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
logger.warn({ error }, 'AI explanation failed, using heuristic explanation');
|
|
43
|
+
explanation = generateHeuristicExplanation(code, detectedLanguage, level, type, structure);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
explanation = generateHeuristicExplanation(code, detectedLanguage, level, type, structure);
|
|
48
|
+
}
|
|
49
|
+
return {
|
|
50
|
+
explanation,
|
|
51
|
+
metadata: {
|
|
52
|
+
level,
|
|
53
|
+
type,
|
|
54
|
+
language: detectedLanguage,
|
|
55
|
+
lineCount: code.split('\n').length,
|
|
56
|
+
},
|
|
57
|
+
generatedAt: new Date().toISOString(),
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
function analyzeCodeStructure(code, language) {
|
|
61
|
+
const structure = {
|
|
62
|
+
functions: [],
|
|
63
|
+
classes: [],
|
|
64
|
+
imports: [],
|
|
65
|
+
controlFlow: [],
|
|
66
|
+
loops: [],
|
|
67
|
+
conditionals: 0,
|
|
68
|
+
complexity: 1, // Base complexity
|
|
69
|
+
};
|
|
70
|
+
const lines = code.split('\n');
|
|
71
|
+
if (['typescript', 'javascript'].includes(language.toLowerCase())) {
|
|
72
|
+
// Analyze functions
|
|
73
|
+
const funcRegex = /(?:export\s+)?(?:async\s+)?function\s+(\w+)\s*\(([^)]*)\)(?:\s*:\s*([^{]+))?/g;
|
|
74
|
+
let match;
|
|
75
|
+
while ((match = funcRegex.exec(code)) !== null) {
|
|
76
|
+
const lineStart = code.substring(0, match.index).split('\n').length;
|
|
77
|
+
structure.functions.push({
|
|
78
|
+
name: match[1],
|
|
79
|
+
params: match[2] ? match[2].split(',').map(p => p.trim()) : [],
|
|
80
|
+
returnType: match[3]?.trim(),
|
|
81
|
+
isAsync: match[0].includes('async'),
|
|
82
|
+
lineStart,
|
|
83
|
+
lineEnd: lineStart + 10, // Approximate
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
// Analyze arrow functions
|
|
87
|
+
const arrowRegex = /(?:export\s+)?(?:const|let)\s+(\w+)\s*=\s*(?:async\s+)?\([^)]*\)\s*(?::\s*[^=]+)?\s*=>/g;
|
|
88
|
+
while ((match = arrowRegex.exec(code)) !== null) {
|
|
89
|
+
const lineStart = code.substring(0, match.index).split('\n').length;
|
|
90
|
+
structure.functions.push({
|
|
91
|
+
name: match[1],
|
|
92
|
+
params: [],
|
|
93
|
+
isAsync: match[0].includes('async'),
|
|
94
|
+
lineStart,
|
|
95
|
+
lineEnd: lineStart + 10,
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
// Analyze imports
|
|
99
|
+
const importRegex = /import\s+(?:(\w+)|{([^}]+)}|(\*\s+as\s+\w+))\s+from\s+['"]([^'"]+)['"]/g;
|
|
100
|
+
while ((match = importRegex.exec(code)) !== null) {
|
|
101
|
+
structure.imports.push({
|
|
102
|
+
module: match[4],
|
|
103
|
+
items: match[2] ? match[2].split(',').map(i => i.trim()) : [match[1] ?? match[3] ?? 'default'],
|
|
104
|
+
isDefault: !!match[1],
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
// Analyze classes
|
|
108
|
+
const classRegex = /class\s+(\w+)/g;
|
|
109
|
+
while ((match = classRegex.exec(code)) !== null) {
|
|
110
|
+
const lineStart = code.substring(0, match.index).split('\n').length;
|
|
111
|
+
structure.classes.push({
|
|
112
|
+
name: match[1],
|
|
113
|
+
methods: [],
|
|
114
|
+
properties: [],
|
|
115
|
+
lineStart,
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
// Analyze loops
|
|
119
|
+
const forLoopRegex = /\bfor\s*\(/g;
|
|
120
|
+
let depth = 0;
|
|
121
|
+
while ((match = forLoopRegex.exec(code)) !== null) {
|
|
122
|
+
const lineNumber = code.substring(0, match.index).split('\n').length;
|
|
123
|
+
// Check if nested by looking at bracket depth
|
|
124
|
+
const beforeCode = code.substring(0, match.index);
|
|
125
|
+
const openBrackets = (beforeCode.match(/{/g) || []).length;
|
|
126
|
+
const closeBrackets = (beforeCode.match(/}/g) || []).length;
|
|
127
|
+
const nested = openBrackets - closeBrackets > 1;
|
|
128
|
+
structure.loops.push({
|
|
129
|
+
type: 'for',
|
|
130
|
+
lineNumber,
|
|
131
|
+
nested,
|
|
132
|
+
});
|
|
133
|
+
if (nested)
|
|
134
|
+
structure.complexity += 2;
|
|
135
|
+
else
|
|
136
|
+
structure.complexity += 1;
|
|
137
|
+
}
|
|
138
|
+
const whileRegex = /\bwhile\s*\(/g;
|
|
139
|
+
while ((match = whileRegex.exec(code)) !== null) {
|
|
140
|
+
const lineNumber = code.substring(0, match.index).split('\n').length;
|
|
141
|
+
structure.loops.push({
|
|
142
|
+
type: 'while',
|
|
143
|
+
lineNumber,
|
|
144
|
+
nested: false,
|
|
145
|
+
});
|
|
146
|
+
structure.complexity += 1;
|
|
147
|
+
}
|
|
148
|
+
// Count conditionals
|
|
149
|
+
structure.conditionals = (code.match(/\bif\s*\(|\belse\s+if\s*\(|\?\s*[^:]+\s*:/g) || []).length;
|
|
150
|
+
structure.complexity += structure.conditionals;
|
|
151
|
+
// Analyze control flow
|
|
152
|
+
if (code.includes('try'))
|
|
153
|
+
structure.controlFlow.push('exception handling');
|
|
154
|
+
if (code.includes('async'))
|
|
155
|
+
structure.controlFlow.push('async/await');
|
|
156
|
+
if (code.includes('.then'))
|
|
157
|
+
structure.controlFlow.push('promises');
|
|
158
|
+
if (code.includes('callback'))
|
|
159
|
+
structure.controlFlow.push('callbacks');
|
|
160
|
+
if (code.includes('yield'))
|
|
161
|
+
structure.controlFlow.push('generators');
|
|
162
|
+
if (code.includes('Observable') || code.includes('subscribe'))
|
|
163
|
+
structure.controlFlow.push('reactive');
|
|
164
|
+
}
|
|
165
|
+
return structure;
|
|
166
|
+
}
|
|
167
|
+
// ============================================================================
|
|
168
|
+
// AI Explanation
|
|
169
|
+
// ============================================================================
|
|
170
|
+
async function explainWithAI(code, options) {
|
|
171
|
+
const provider = await getActiveProvider();
|
|
172
|
+
const levelInstructions = {
|
|
173
|
+
beginner: 'Explain like I\'m new to programming. Define all technical terms. Use simple analogies.',
|
|
174
|
+
intermediate: 'Assume basic programming knowledge. Focus on the logic and architecture.',
|
|
175
|
+
expert: 'Be concise and technical. Focus on advanced patterns, edge cases, and optimizations.',
|
|
176
|
+
};
|
|
177
|
+
const prompt = `Explain this ${options.language} code.
|
|
178
|
+
|
|
179
|
+
## Code
|
|
180
|
+
\`\`\`${options.language}
|
|
181
|
+
${code}
|
|
182
|
+
\`\`\`
|
|
183
|
+
|
|
184
|
+
## Explanation Level
|
|
185
|
+
${levelInstructions[options.level]}
|
|
186
|
+
|
|
187
|
+
## Explanation Type
|
|
188
|
+
${options.type === 'line-by-line' ? 'Explain each significant line or block of code.' : ''}
|
|
189
|
+
${options.type === 'algorithm' ? 'Focus on the algorithm, data structures, and computational logic.' : ''}
|
|
190
|
+
${options.type === 'detailed' ? 'Provide comprehensive explanation of all aspects.' : ''}
|
|
191
|
+
${options.type === 'overview' ? 'Provide a high-level overview of what the code does.' : ''}
|
|
192
|
+
|
|
193
|
+
${options.focusArea ? `## Focus on: ${options.focusArea}` : ''}
|
|
194
|
+
|
|
195
|
+
## Code Structure Found
|
|
196
|
+
- Functions: ${options.structure.functions.map(f => f.name).join(', ') || 'none'}
|
|
197
|
+
- Classes: ${options.structure.classes.map(c => c.name).join(', ') || 'none'}
|
|
198
|
+
- Loops: ${options.structure.loops.length}
|
|
199
|
+
- Conditionals: ${options.structure.conditionals}
|
|
200
|
+
- Estimated complexity: ${options.structure.complexity}
|
|
201
|
+
|
|
202
|
+
## Output Format
|
|
203
|
+
{
|
|
204
|
+
"summary": "One-line summary",
|
|
205
|
+
"purpose": "What problem does this code solve?",
|
|
206
|
+
"howItWorks": "Step-by-step explanation of the logic",
|
|
207
|
+
"sections": [
|
|
208
|
+
{
|
|
209
|
+
"title": "Section name",
|
|
210
|
+
"lineRange": {"start": 1, "end": 10},
|
|
211
|
+
"code": "relevant code snippet",
|
|
212
|
+
"explanation": "what this section does",
|
|
213
|
+
"keyPoints": ["key point 1", "key point 2"]
|
|
214
|
+
}
|
|
215
|
+
],
|
|
216
|
+
${options.includeComplexity ? `"complexity": {
|
|
217
|
+
"time": "O(n)",
|
|
218
|
+
"space": "O(1)",
|
|
219
|
+
"explanation": "Why this complexity"
|
|
220
|
+
},` : ''}
|
|
221
|
+
${options.includePatterns ? `"patterns": [
|
|
222
|
+
{"name": "pattern name", "type": "creational|structural|behavioral|architectural", "description": "how it's used", "locationHint": "where in the code"}
|
|
223
|
+
],` : ''}
|
|
224
|
+
"dependencies": [
|
|
225
|
+
{"name": "module", "type": "import|external|internal", "purpose": "why it's needed", "required": true}
|
|
226
|
+
],
|
|
227
|
+
"suggestions": ["improvement suggestion"],
|
|
228
|
+
"glossary": [
|
|
229
|
+
{"term": "technical term", "definition": "simple definition", "example": "usage example"}
|
|
230
|
+
]
|
|
231
|
+
}`;
|
|
232
|
+
const response = await provider.completeJson(prompt, {
|
|
233
|
+
systemPrompt: `You are a patient, expert programming tutor. Explain code clearly at the ${options.level} level. Return valid JSON only.`,
|
|
234
|
+
temperature: 0.4,
|
|
235
|
+
maxTokens: 4096,
|
|
236
|
+
});
|
|
237
|
+
if (response.data) {
|
|
238
|
+
return response.data;
|
|
239
|
+
}
|
|
240
|
+
throw new Error('Failed to generate explanation with AI');
|
|
241
|
+
}
|
|
242
|
+
// ============================================================================
|
|
243
|
+
// Heuristic Explanation
|
|
244
|
+
// ============================================================================
|
|
245
|
+
function generateHeuristicExplanation(code, language, level, type, structure) {
|
|
246
|
+
const lines = code.split('\n');
|
|
247
|
+
// Generate summary
|
|
248
|
+
const summary = generateSummary(structure);
|
|
249
|
+
// Generate purpose
|
|
250
|
+
const purpose = generatePurpose(structure);
|
|
251
|
+
// Generate how it works
|
|
252
|
+
const howItWorks = generateHowItWorks(structure, language);
|
|
253
|
+
// Generate sections
|
|
254
|
+
const sections = generateSections(code, structure, level);
|
|
255
|
+
// Generate complexity analysis
|
|
256
|
+
const complexity = generateComplexityAnalysis(structure);
|
|
257
|
+
// Generate patterns
|
|
258
|
+
const patterns = detectPatterns(code, language);
|
|
259
|
+
// Generate dependency info
|
|
260
|
+
const dependencies = structure.imports.map(imp => ({
|
|
261
|
+
name: imp.module,
|
|
262
|
+
type: imp.module.startsWith('.') ? 'internal' : 'external',
|
|
263
|
+
purpose: `Imports ${imp.items.join(', ')}`,
|
|
264
|
+
required: true,
|
|
265
|
+
}));
|
|
266
|
+
// Generate suggestions
|
|
267
|
+
const suggestions = generateSuggestions(structure, code);
|
|
268
|
+
// Generate glossary for beginners
|
|
269
|
+
const glossary = level === 'beginner' ? generateGlossary(code, language) : undefined;
|
|
270
|
+
return {
|
|
271
|
+
summary,
|
|
272
|
+
purpose,
|
|
273
|
+
howItWorks,
|
|
274
|
+
sections,
|
|
275
|
+
complexity,
|
|
276
|
+
patterns,
|
|
277
|
+
dependencies,
|
|
278
|
+
suggestions,
|
|
279
|
+
glossary,
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
function generateSummary(structure) {
|
|
283
|
+
const parts = [];
|
|
284
|
+
if (structure.functions.length > 0) {
|
|
285
|
+
parts.push(`${structure.functions.length} function(s)`);
|
|
286
|
+
}
|
|
287
|
+
if (structure.classes.length > 0) {
|
|
288
|
+
parts.push(`${structure.classes.length} class(es)`);
|
|
289
|
+
}
|
|
290
|
+
if (structure.loops.length > 0) {
|
|
291
|
+
parts.push(`iterative logic`);
|
|
292
|
+
}
|
|
293
|
+
if (structure.controlFlow.includes('async/await')) {
|
|
294
|
+
parts.push(`async operations`);
|
|
295
|
+
}
|
|
296
|
+
return `This code contains ${parts.join(', ') || 'basic logic'}.`;
|
|
297
|
+
}
|
|
298
|
+
function generatePurpose(structure) {
|
|
299
|
+
const mainFunc = structure.functions[0];
|
|
300
|
+
if (mainFunc) {
|
|
301
|
+
return `The main purpose is to implement ${humanizeName(mainFunc.name)} functionality.`;
|
|
302
|
+
}
|
|
303
|
+
if (structure.classes.length > 0) {
|
|
304
|
+
return `Defines the ${structure.classes[0].name} class for encapsulating related functionality.`;
|
|
305
|
+
}
|
|
306
|
+
return 'This code implements specific business logic or utility functions.';
|
|
307
|
+
}
|
|
308
|
+
function generateHowItWorks(structure, language) {
|
|
309
|
+
const steps = [];
|
|
310
|
+
if (structure.imports.length > 0) {
|
|
311
|
+
steps.push(`1. Imports dependencies: ${structure.imports.map(i => i.module).join(', ')}`);
|
|
312
|
+
}
|
|
313
|
+
if (structure.classes.length > 0) {
|
|
314
|
+
steps.push(`2. Defines class(es): ${structure.classes.map(c => c.name).join(', ')}`);
|
|
315
|
+
}
|
|
316
|
+
if (structure.functions.length > 0) {
|
|
317
|
+
for (const [i, func] of structure.functions.entries()) {
|
|
318
|
+
steps.push(`${steps.length + 1}. Function \`${func.name}\`: ${humanizeName(func.name)}`);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
if (structure.loops.length > 0) {
|
|
322
|
+
steps.push(`${steps.length + 1}. Uses ${structure.loops.length} loop(s) for iteration`);
|
|
323
|
+
}
|
|
324
|
+
if (structure.controlFlow.length > 0) {
|
|
325
|
+
steps.push(`${steps.length + 1}. Control flow includes: ${structure.controlFlow.join(', ')}`);
|
|
326
|
+
}
|
|
327
|
+
return steps.join('\n') || 'The code executes sequentially from top to bottom.';
|
|
328
|
+
}
|
|
329
|
+
function generateSections(code, structure, level) {
|
|
330
|
+
const sections = [];
|
|
331
|
+
const lines = code.split('\n');
|
|
332
|
+
// Imports section
|
|
333
|
+
if (structure.imports.length > 0) {
|
|
334
|
+
const importLines = lines.filter(l => l.includes('import '));
|
|
335
|
+
sections.push({
|
|
336
|
+
title: 'Dependencies',
|
|
337
|
+
lineRange: { start: 1, end: Math.min(structure.imports.length + 1, lines.length) },
|
|
338
|
+
code: importLines.join('\n'),
|
|
339
|
+
explanation: 'This section imports external modules and dependencies needed by the code.',
|
|
340
|
+
keyPoints: structure.imports.map(i => `${i.module}: provides ${i.items.join(', ')}`),
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
// Function sections
|
|
344
|
+
for (const func of structure.functions) {
|
|
345
|
+
const funcCode = lines.slice(func.lineStart - 1, func.lineEnd).join('\n');
|
|
346
|
+
sections.push({
|
|
347
|
+
title: `Function: ${func.name}`,
|
|
348
|
+
lineRange: { start: func.lineStart, end: func.lineEnd },
|
|
349
|
+
code: funcCode,
|
|
350
|
+
explanation: `${humanizeName(func.name)}. ${func.isAsync ? 'This is an async function that returns a Promise.' : ''}`,
|
|
351
|
+
keyPoints: [
|
|
352
|
+
`Parameters: ${func.params.length > 0 ? func.params.join(', ') : 'none'}`,
|
|
353
|
+
`Returns: ${func.returnType ?? 'unspecified'}`,
|
|
354
|
+
func.isAsync ? 'Asynchronous execution' : 'Synchronous execution',
|
|
355
|
+
],
|
|
356
|
+
});
|
|
357
|
+
}
|
|
358
|
+
// Class sections
|
|
359
|
+
for (const cls of structure.classes) {
|
|
360
|
+
sections.push({
|
|
361
|
+
title: `Class: ${cls.name}`,
|
|
362
|
+
lineRange: { start: cls.lineStart, end: cls.lineStart + 20 },
|
|
363
|
+
code: `class ${cls.name} { ... }`,
|
|
364
|
+
explanation: `Defines the ${cls.name} class which encapsulates related data and behavior.`,
|
|
365
|
+
keyPoints: [
|
|
366
|
+
'Classes group related functionality together',
|
|
367
|
+
'Methods define what actions the class can perform',
|
|
368
|
+
'Properties store the class state',
|
|
369
|
+
],
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
return sections;
|
|
373
|
+
}
|
|
374
|
+
function generateComplexityAnalysis(structure) {
|
|
375
|
+
// Estimate time complexity based on loops
|
|
376
|
+
let timeComplexity = 'O(1)';
|
|
377
|
+
let spaceComplexity = 'O(1)';
|
|
378
|
+
let explanation = 'Constant time - no significant loops or recursion detected.';
|
|
379
|
+
const nestedLoops = structure.loops.filter(l => l.nested).length;
|
|
380
|
+
const regularLoops = structure.loops.filter(l => !l.nested).length;
|
|
381
|
+
if (nestedLoops > 0) {
|
|
382
|
+
timeComplexity = `O(n^${nestedLoops + 1})`;
|
|
383
|
+
explanation = `Polynomial time due to ${nestedLoops + 1} nested loops.`;
|
|
384
|
+
}
|
|
385
|
+
else if (regularLoops > 0) {
|
|
386
|
+
timeComplexity = 'O(n)';
|
|
387
|
+
explanation = 'Linear time - iterates through input once.';
|
|
388
|
+
}
|
|
389
|
+
if (regularLoops > 0) {
|
|
390
|
+
spaceComplexity = 'O(n)';
|
|
391
|
+
}
|
|
392
|
+
return {
|
|
393
|
+
time: timeComplexity,
|
|
394
|
+
space: spaceComplexity,
|
|
395
|
+
explanation,
|
|
396
|
+
bestCase: timeComplexity,
|
|
397
|
+
worstCase: timeComplexity,
|
|
398
|
+
averageCase: timeComplexity,
|
|
399
|
+
};
|
|
400
|
+
}
|
|
401
|
+
function detectPatterns(code, language) {
|
|
402
|
+
const patterns = [];
|
|
403
|
+
// Singleton pattern
|
|
404
|
+
if (code.includes('getInstance') || code.includes('static instance')) {
|
|
405
|
+
patterns.push({
|
|
406
|
+
name: 'Singleton',
|
|
407
|
+
type: 'creational',
|
|
408
|
+
description: 'Ensures only one instance of a class exists.',
|
|
409
|
+
locationHint: 'Look for getInstance() method or static instance property.',
|
|
410
|
+
});
|
|
411
|
+
}
|
|
412
|
+
// Factory pattern
|
|
413
|
+
if (code.includes('create') && code.includes('return new')) {
|
|
414
|
+
patterns.push({
|
|
415
|
+
name: 'Factory',
|
|
416
|
+
type: 'creational',
|
|
417
|
+
description: 'Creates objects without specifying exact class.',
|
|
418
|
+
locationHint: 'Functions that return new instances of different types.',
|
|
419
|
+
});
|
|
420
|
+
}
|
|
421
|
+
// Observer pattern
|
|
422
|
+
if (code.includes('subscribe') || code.includes('addEventListener') || code.includes('emit')) {
|
|
423
|
+
patterns.push({
|
|
424
|
+
name: 'Observer',
|
|
425
|
+
type: 'behavioral',
|
|
426
|
+
description: 'Objects subscribe to events and get notified of changes.',
|
|
427
|
+
locationHint: 'Look for subscribe/emit or addEventListener methods.',
|
|
428
|
+
});
|
|
429
|
+
}
|
|
430
|
+
// Strategy pattern
|
|
431
|
+
if (code.includes('strategy') || (code.includes('interface') && code.match(/execute|run|process/))) {
|
|
432
|
+
patterns.push({
|
|
433
|
+
name: 'Strategy',
|
|
434
|
+
type: 'behavioral',
|
|
435
|
+
description: 'Allows selecting algorithm at runtime.',
|
|
436
|
+
locationHint: 'Multiple implementations of the same interface.',
|
|
437
|
+
});
|
|
438
|
+
}
|
|
439
|
+
// Decorator pattern
|
|
440
|
+
if (code.includes('@') || code.includes('wrapper') || code.includes('decorator')) {
|
|
441
|
+
patterns.push({
|
|
442
|
+
name: 'Decorator',
|
|
443
|
+
type: 'structural',
|
|
444
|
+
description: 'Adds behavior to objects dynamically.',
|
|
445
|
+
locationHint: 'Look for @ syntax or wrapper functions.',
|
|
446
|
+
});
|
|
447
|
+
}
|
|
448
|
+
// Module pattern (common in JS)
|
|
449
|
+
if (code.includes('export') && code.includes('import')) {
|
|
450
|
+
patterns.push({
|
|
451
|
+
name: 'Module',
|
|
452
|
+
type: 'architectural',
|
|
453
|
+
description: 'Encapsulates code and exposes public API.',
|
|
454
|
+
locationHint: 'File-level exports and imports.',
|
|
455
|
+
});
|
|
456
|
+
}
|
|
457
|
+
return patterns;
|
|
458
|
+
}
|
|
459
|
+
function generateSuggestions(structure, code) {
|
|
460
|
+
const suggestions = [];
|
|
461
|
+
if (structure.complexity > 10) {
|
|
462
|
+
suggestions.push('Consider breaking down complex functions into smaller, focused functions.');
|
|
463
|
+
}
|
|
464
|
+
if (structure.loops.some(l => l.nested)) {
|
|
465
|
+
suggestions.push('Nested loops may impact performance. Consider using maps or memoization.');
|
|
466
|
+
}
|
|
467
|
+
if (!code.includes('try') && structure.controlFlow.includes('async/await')) {
|
|
468
|
+
suggestions.push('Add error handling (try/catch) for async operations.');
|
|
469
|
+
}
|
|
470
|
+
if (structure.functions.some(f => f.params.length > 4)) {
|
|
471
|
+
suggestions.push('Functions with many parameters could use an options object instead.');
|
|
472
|
+
}
|
|
473
|
+
if (!code.includes('const') && code.includes('let')) {
|
|
474
|
+
suggestions.push('Prefer const over let when variables are not reassigned.');
|
|
475
|
+
}
|
|
476
|
+
return suggestions;
|
|
477
|
+
}
|
|
478
|
+
function generateGlossary(code, language) {
|
|
479
|
+
const glossary = [];
|
|
480
|
+
if (code.includes('async')) {
|
|
481
|
+
glossary.push({
|
|
482
|
+
term: 'async',
|
|
483
|
+
definition: 'A keyword that marks a function as asynchronous, meaning it returns a Promise.',
|
|
484
|
+
example: 'async function fetchData() { }',
|
|
485
|
+
});
|
|
486
|
+
}
|
|
487
|
+
if (code.includes('await')) {
|
|
488
|
+
glossary.push({
|
|
489
|
+
term: 'await',
|
|
490
|
+
definition: 'Pauses execution until a Promise resolves, then returns its value.',
|
|
491
|
+
example: 'const data = await fetchData();',
|
|
492
|
+
});
|
|
493
|
+
}
|
|
494
|
+
if (code.includes('=>')) {
|
|
495
|
+
glossary.push({
|
|
496
|
+
term: 'Arrow function (=>)',
|
|
497
|
+
definition: 'A shorter syntax for writing functions.',
|
|
498
|
+
example: 'const add = (a, b) => a + b;',
|
|
499
|
+
});
|
|
500
|
+
}
|
|
501
|
+
if (code.includes('map(')) {
|
|
502
|
+
glossary.push({
|
|
503
|
+
term: 'map()',
|
|
504
|
+
definition: 'Creates a new array by applying a function to each element.',
|
|
505
|
+
example: '[1, 2, 3].map(x => x * 2) // [2, 4, 6]',
|
|
506
|
+
});
|
|
507
|
+
}
|
|
508
|
+
if (code.includes('filter(')) {
|
|
509
|
+
glossary.push({
|
|
510
|
+
term: 'filter()',
|
|
511
|
+
definition: 'Creates a new array with elements that pass a test.',
|
|
512
|
+
example: '[1, 2, 3, 4].filter(x => x > 2) // [3, 4]',
|
|
513
|
+
});
|
|
514
|
+
}
|
|
515
|
+
if (code.includes('reduce(')) {
|
|
516
|
+
glossary.push({
|
|
517
|
+
term: 'reduce()',
|
|
518
|
+
definition: 'Reduces an array to a single value by applying a function.',
|
|
519
|
+
example: '[1, 2, 3].reduce((sum, x) => sum + x, 0) // 6',
|
|
520
|
+
});
|
|
521
|
+
}
|
|
522
|
+
return glossary;
|
|
523
|
+
}
|
|
524
|
+
function humanizeName(name) {
|
|
525
|
+
return name
|
|
526
|
+
.replace(/([A-Z])/g, ' $1')
|
|
527
|
+
.replace(/_/g, ' ')
|
|
528
|
+
.toLowerCase()
|
|
529
|
+
.trim();
|
|
530
|
+
}
|
|
531
|
+
function detectLanguage(code) {
|
|
532
|
+
if (code.includes('interface ') || code.includes(': string') || code.includes(': number')) {
|
|
533
|
+
return 'typescript';
|
|
534
|
+
}
|
|
535
|
+
if (code.includes('def ') && code.includes(':')) {
|
|
536
|
+
return 'python';
|
|
537
|
+
}
|
|
538
|
+
if (code.includes('func ') && code.includes('package ')) {
|
|
539
|
+
return 'go';
|
|
540
|
+
}
|
|
541
|
+
return 'javascript';
|
|
542
|
+
}
|
|
543
|
+
//# sourceMappingURL=explain.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"explain.js","sourceRoot":"","sources":["../../src/tools/explain.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACvE,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AA8ErC,+EAA+E;AAC/E,mBAAmB;AACnB,+EAA+E;AAE/E;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,IAAY,EACZ,UAA8B,EAAE;IAEhC,MAAM,EACJ,KAAK,GAAG,cAAc,EACtB,IAAI,GAAG,UAAU,EACjB,QAAQ,EACR,SAAS,EACT,iBAAiB,GAAG,IAAI,EACxB,eAAe,GAAG,IAAI,GACvB,GAAG,OAAO,CAAC;IAEZ,MAA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AE,GAAG,CAAC;SAClB,WAAW,EAAE;SACb,IAAI,EAAE,CAAC;AACZ,CAAC;AAED,SAAS,cAAc,CAAC,IAAY;IAClC,IAAI,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC;QAC1F,OAAO,YAAY,CAAC;IACtB,CAAC;IACD,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QAChD,OAAO,QAAQ,CAAC;IAClB,CAAC;IACD,IAAI,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC;QACxD,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,YAAY,CAAC;AACtB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"intent.d.ts","sourceRoot":"","sources":["../../src/tools/intent.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EACV,cAAc,EACd,UAAU,EACV,eAAe,
|
|
1
|
+
{"version":3,"file":"intent.d.ts","sourceRoot":"","sources":["../../src/tools/intent.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EACV,cAAc,EACd,UAAU,EACV,eAAe,EAEhB,MAAM,aAAa,CAAC;AA6BrB;;GAEG;AACH,QAAA,MAAM,eAAe,EAAE,MAAM,CAAC,UAAU,EAAE,GAAG,CAAC,MAAM,CAAC,CAWpD,CAAC;AAEF;;GAEG;AACH,QAAA,MAAM,eAAe,EAAE,MAAM,CAAC,eAAe,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,CAoB9D,CAAC;AAMF;;GAEG;AACH,wBAAsB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,CAuB1E;AA2OD,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,CAAC"}
|
package/dist/tools/intent.js
CHANGED
|
@@ -7,7 +7,9 @@
|
|
|
7
7
|
* - Whether clarification is needed
|
|
8
8
|
* - Confidence level of the analysis
|
|
9
9
|
*/
|
|
10
|
-
import {
|
|
10
|
+
import { createConfidence } from '../types.js';
|
|
11
|
+
import { getActiveProvider, isNoLLMMode } from '../providers/index.js';
|
|
12
|
+
import { PromptTemplates } from './ollama.js';
|
|
11
13
|
import { logger } from '../utils.js';
|
|
12
14
|
// ============================================================================
|
|
13
15
|
// Constants (Module-level for performance)
|
|
@@ -146,7 +148,7 @@ function heuristicAnalysis(query) {
|
|
|
146
148
|
function createUnknownIntent(query) {
|
|
147
149
|
return {
|
|
148
150
|
primaryIntent: 'unknown',
|
|
149
|
-
confidence: 0.1,
|
|
151
|
+
confidence: createConfidence(0.1),
|
|
150
152
|
entities: [],
|
|
151
153
|
keywords: extractKeywords(query),
|
|
152
154
|
requiresClarification: true,
|
|
@@ -157,8 +159,14 @@ function createUnknownIntent(query) {
|
|
|
157
159
|
* LLM-enhanced intent analysis for complex queries
|
|
158
160
|
*/
|
|
159
161
|
async function llmIntentAnalysis(query, heuristicResult) {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
+
// Check if we're in no-LLM mode - return heuristic result
|
|
163
|
+
if (isNoLLMMode()) {
|
|
164
|
+
logger.debug('No LLM available, using heuristic result for intent analysis');
|
|
165
|
+
return heuristicResult;
|
|
166
|
+
}
|
|
167
|
+
try {
|
|
168
|
+
const provider = await getActiveProvider();
|
|
169
|
+
const prompt = `Analyze this developer query and extract intent information.
|
|
162
170
|
|
|
163
171
|
Query: "${query}"
|
|
164
172
|
|
|
@@ -175,22 +183,27 @@ Provide a JSON response with:
|
|
|
175
183
|
"requiresClarification": true/false,
|
|
176
184
|
"clarifyingQuestions": ["question 1", "question 2"] // only if requiresClarification is true
|
|
177
185
|
}`;
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
186
|
+
const response = await provider.completeJson(prompt, {
|
|
187
|
+
systemPrompt: PromptTemplates.intentAnalysis,
|
|
188
|
+
temperature: 0.3,
|
|
189
|
+
});
|
|
190
|
+
if (response.data) {
|
|
191
|
+
return {
|
|
192
|
+
primaryIntent: response.data.primaryIntent,
|
|
193
|
+
confidence: createConfidence(Math.min(1, Math.max(0, response.data.confidence))),
|
|
194
|
+
entities: heuristicResult.entities, // Keep heuristic entities
|
|
195
|
+
keywords: response.data.keywords || heuristicResult.keywords,
|
|
196
|
+
requiresClarification: response.data.requiresClarification,
|
|
197
|
+
clarifyingQuestions: response.data.clarifyingQuestions,
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
// Fallback to heuristic if parsing failed
|
|
201
|
+
return heuristicResult;
|
|
202
|
+
}
|
|
203
|
+
catch (error) {
|
|
204
|
+
logger.warn({ error }, 'LLM intent analysis failed, using heuristic result');
|
|
205
|
+
return heuristicResult;
|
|
191
206
|
}
|
|
192
|
-
// Fallback to heuristic if parsing failed
|
|
193
|
-
return heuristicResult;
|
|
194
207
|
}
|
|
195
208
|
/**
|
|
196
209
|
* Extract entities from query text
|
|
@@ -242,7 +255,7 @@ function calculateConfidence(hasKeywordMatch, hasEntities, keywordScore) {
|
|
|
242
255
|
if (hasEntities) {
|
|
243
256
|
confidence += 0.2;
|
|
244
257
|
}
|
|
245
|
-
return Math.min(1, confidence);
|
|
258
|
+
return createConfidence(Math.min(1, confidence));
|
|
246
259
|
}
|
|
247
260
|
/**
|
|
248
261
|
* Generate clarifying questions based on intent
|