erosolar-cli 1.3.6 → 1.3.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/StringUtils.d.ts +8 -0
- package/dist/StringUtils.d.ts.map +1 -0
- package/dist/StringUtils.js +11 -0
- package/dist/StringUtils.js.map +1 -0
- package/dist/alpha-zero/index.d.ts +1 -1
- package/dist/alpha-zero/index.js +1 -1
- package/dist/capabilities/index.d.ts +1 -1
- package/dist/capabilities/index.d.ts.map +1 -1
- package/dist/capabilities/index.js +1 -1
- package/dist/capabilities/index.js.map +1 -1
- package/dist/capabilities/skillCapability.d.ts +2 -6
- package/dist/capabilities/skillCapability.d.ts.map +1 -1
- package/dist/capabilities/skillCapability.js +70 -20
- package/dist/capabilities/skillCapability.js.map +1 -1
- package/dist/core/agent.d.ts +16 -0
- package/dist/core/agent.d.ts.map +1 -1
- package/dist/core/agent.js +171 -54
- package/dist/core/agent.js.map +1 -1
- package/dist/core/contextManager.js +6 -6
- package/dist/core/contextManager.js.map +1 -1
- package/dist/core/contextWindow.d.ts +6 -0
- package/dist/core/contextWindow.d.ts.map +1 -1
- package/dist/core/contextWindow.js +12 -4
- package/dist/core/contextWindow.js.map +1 -1
- package/dist/plugins/tools/skills/skillPlugin.js +2 -2
- package/dist/plugins/tools/skills/skillPlugin.js.map +1 -1
- package/dist/shell/interactiveShell.d.ts +19 -0
- package/dist/shell/interactiveShell.d.ts.map +1 -1
- package/dist/shell/interactiveShell.js +178 -1
- package/dist/shell/interactiveShell.js.map +1 -1
- package/dist/skills/skillRepository.d.ts +99 -23
- package/dist/skills/skillRepository.d.ts.map +1 -1
- package/dist/skills/skillRepository.js +213 -329
- package/dist/skills/skillRepository.js.map +1 -1
- package/dist/tools/skillTools.d.ts.map +1 -1
- package/dist/tools/skillTools.js +24 -62
- package/dist/tools/skillTools.js.map +1 -1
- package/package.json +21 -5
- package/scripts/ai-code-reviewer.mjs +343 -0
- package/scripts/code-intelligence-enhancer.mjs +415 -0
- package/scripts/dev-productivity-booster.mjs +342 -0
- package/dist/ui/advancedPrompt.d.ts +0 -58
- package/dist/ui/advancedPrompt.d.ts.map +0 -1
- package/dist/ui/advancedPrompt.js +0 -219
- package/dist/ui/advancedPrompt.js.map +0 -1
- package/dist/ui/overlay/OverlayManager.d.ts +0 -105
- package/dist/ui/overlay/OverlayManager.d.ts.map +0 -1
- package/dist/ui/overlay/OverlayManager.js +0 -291
- package/dist/ui/overlay/OverlayManager.js.map +0 -1
|
@@ -0,0 +1,415 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Code Intelligence Enhancer
|
|
5
|
+
*
|
|
6
|
+
* Advanced code analysis and improvement suggestions
|
|
7
|
+
* that integrate with Erosolar's existing intelligence engine.
|
|
8
|
+
*
|
|
9
|
+
* Features:
|
|
10
|
+
* - Automated code smell detection
|
|
11
|
+
* - Performance optimization analysis
|
|
12
|
+
* - Memory usage patterns
|
|
13
|
+
* - API design validation
|
|
14
|
+
* - Test coverage analysis
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { readFileSync, existsSync, readdirSync } from 'fs';
|
|
18
|
+
import { join, dirname, extname } from 'path';
|
|
19
|
+
import { fileURLToPath } from 'url';
|
|
20
|
+
|
|
21
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
22
|
+
const __dirname = dirname(__filename);
|
|
23
|
+
|
|
24
|
+
class CodeIntelligenceEnhancer {
|
|
25
|
+
constructor() {
|
|
26
|
+
this.projectRoot = join(__dirname, '..');
|
|
27
|
+
this.analysisCache = new Map();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async analyzeProject() {
|
|
31
|
+
console.log('🔍 Analyzing project for intelligence enhancements...\n');
|
|
32
|
+
|
|
33
|
+
const srcFiles = this.findSourceFiles();
|
|
34
|
+
const analysis = await this.analyzeFiles(srcFiles);
|
|
35
|
+
const insights = this.generateInsights(analysis);
|
|
36
|
+
|
|
37
|
+
return {
|
|
38
|
+
timestamp: new Date().toISOString(),
|
|
39
|
+
filesAnalyzed: srcFiles.length,
|
|
40
|
+
analysis,
|
|
41
|
+
insights
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
findSourceFiles() {
|
|
46
|
+
const srcDir = join(this.projectRoot, 'src');
|
|
47
|
+
const files = [];
|
|
48
|
+
|
|
49
|
+
const walk = (dir) => {
|
|
50
|
+
const items = readdirSync(dir, { withFileTypes: true });
|
|
51
|
+
|
|
52
|
+
for (const item of items) {
|
|
53
|
+
const fullPath = join(dir, item.name);
|
|
54
|
+
|
|
55
|
+
if (item.isDirectory()) {
|
|
56
|
+
walk(fullPath);
|
|
57
|
+
} else if (item.isFile() && extname(item.name) === '.ts') {
|
|
58
|
+
files.push(fullPath);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
walk(srcDir);
|
|
64
|
+
return files;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
async analyzeFiles(files) {
|
|
68
|
+
const analysis = {
|
|
69
|
+
architecture: {},
|
|
70
|
+
performance: {},
|
|
71
|
+
maintainability: {},
|
|
72
|
+
security: {},
|
|
73
|
+
patterns: {}
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
for (const file of files.slice(0, 50)) { // Limit for performance
|
|
77
|
+
const relativePath = file.replace(this.projectRoot + '/', '');
|
|
78
|
+
const fileAnalysis = await this.analyzeFile(file);
|
|
79
|
+
|
|
80
|
+
this.aggregateAnalysis(analysis, fileAnalysis, relativePath);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return analysis;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
async analyzeFile(filePath) {
|
|
87
|
+
if (this.analysisCache.has(filePath)) {
|
|
88
|
+
return this.analysisCache.get(filePath);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const content = readFileSync(filePath, 'utf8');
|
|
92
|
+
const lines = content.split('\n');
|
|
93
|
+
|
|
94
|
+
const analysis = {
|
|
95
|
+
file: filePath,
|
|
96
|
+
lines: lines.length,
|
|
97
|
+
functions: this.countFunctions(content),
|
|
98
|
+
classes: this.countClasses(content),
|
|
99
|
+
interfaces: this.countInterfaces(content),
|
|
100
|
+
imports: this.countImports(content),
|
|
101
|
+
complexity: this.calculateFileComplexity(content),
|
|
102
|
+
dependencies: this.analyzeDependencies(content),
|
|
103
|
+
patterns: this.analyzePatterns(content),
|
|
104
|
+
performance: this.analyzePerformance(content),
|
|
105
|
+
security: this.analyzeSecurity(content)
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
this.analysisCache.set(filePath, analysis);
|
|
109
|
+
return analysis;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
countFunctions(content) {
|
|
113
|
+
const functionRegex = /(?:function|const|let|var)\s+([a-zA-Z_$][a-zA-Z0-9_$]*)\s*[=:]?\s*(?:\([^)]*\)\s*=>|function\s*(?:\([^)]*\))?)/g;
|
|
114
|
+
return (content.match(functionRegex) || []).length;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
countClasses(content) {
|
|
118
|
+
return (content.match(/\bclass\s+[A-Za-z_$][A-Za-z0-9_$]*/g) || []).length;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
countInterfaces(content) {
|
|
122
|
+
return (content.match(/\binterface\s+[A-Za-z_$][A-Za-z0-9_$]*/g) || []).length;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
countImports(content) {
|
|
126
|
+
return (content.match(/import\s+(?:{[^}]*}|[^{}\s]+)\s+from\s+['"]([^'"]+)['"]/g) || []).length;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
calculateFileComplexity(content) {
|
|
130
|
+
let complexity = 0;
|
|
131
|
+
const lines = content.split('\n');
|
|
132
|
+
|
|
133
|
+
lines.forEach(line => {
|
|
134
|
+
const trimmed = line.trim();
|
|
135
|
+
|
|
136
|
+
// Control flow complexity
|
|
137
|
+
if (trimmed.match(/\b(?:if|for|while|switch)\b/)) complexity += 1;
|
|
138
|
+
if (trimmed.match(/&&|\|\|/)) complexity += 0.5;
|
|
139
|
+
if (trimmed.match(/\bcatch\b/)) complexity += 1;
|
|
140
|
+
if (trimmed.match(/\bawait\b/)) complexity += 0.5;
|
|
141
|
+
|
|
142
|
+
// Function complexity
|
|
143
|
+
if (trimmed.match(/=>/)) complexity += 0.5;
|
|
144
|
+
if (trimmed.match(/\bfunction\b/)) complexity += 1;
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
return Math.round(complexity);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
analyzeDependencies(content) {
|
|
151
|
+
const dependencies = new Set();
|
|
152
|
+
const importRegex = /import\s+.*from\s+['"]([^'"]+)['"]/g;
|
|
153
|
+
let match;
|
|
154
|
+
|
|
155
|
+
while ((match = importRegex.exec(content)) !== null) {
|
|
156
|
+
dependencies.add(match[1]);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
return Array.from(dependencies);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
analyzePatterns(content) {
|
|
163
|
+
const patterns = [];
|
|
164
|
+
|
|
165
|
+
// Check for async patterns
|
|
166
|
+
if (content.includes('async') && content.includes('await')) {
|
|
167
|
+
patterns.push('async-await');
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// Check for error handling
|
|
171
|
+
if (content.includes('try') && content.includes('catch')) {
|
|
172
|
+
patterns.push('error-handling');
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// Check for TypeScript features
|
|
176
|
+
if (content.includes('interface') || content.includes('type ')) {
|
|
177
|
+
patterns.push('typescript-types');
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// Check for modern JS features
|
|
181
|
+
if (content.includes('=>')) {
|
|
182
|
+
patterns.push('arrow-functions');
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
return patterns;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
analyzePerformance(content) {
|
|
189
|
+
const issues = [];
|
|
190
|
+
const lines = content.split('\n');
|
|
191
|
+
|
|
192
|
+
lines.forEach((line, index) => {
|
|
193
|
+
const lineNumber = index + 1;
|
|
194
|
+
|
|
195
|
+
// Check for potential performance issues
|
|
196
|
+
if (line.includes('.forEach(') && !line.includes('//')) {
|
|
197
|
+
issues.push({
|
|
198
|
+
type: 'FOREACH_LOOP',
|
|
199
|
+
severity: 'LOW',
|
|
200
|
+
line: lineNumber,
|
|
201
|
+
message: 'forEach loop detected',
|
|
202
|
+
suggestion: 'Consider using for...of for better performance'
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
if (line.includes('JSON.parse(') && line.includes('JSON.stringify(')) {
|
|
207
|
+
issues.push({
|
|
208
|
+
type: 'DEEP_CLONE',
|
|
209
|
+
severity: 'MEDIUM',
|
|
210
|
+
line: lineNumber,
|
|
211
|
+
message: 'Deep clone using JSON methods',
|
|
212
|
+
suggestion: 'Consider structuredClone() or manual cloning'
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
return issues;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
analyzeSecurity(content) {
|
|
221
|
+
const issues = [];
|
|
222
|
+
const lines = content.split('\n');
|
|
223
|
+
|
|
224
|
+
lines.forEach((line, index) => {
|
|
225
|
+
const lineNumber = index + 1;
|
|
226
|
+
|
|
227
|
+
// Security checks
|
|
228
|
+
if (line.includes('eval(') || line.includes('Function(')) {
|
|
229
|
+
issues.push({
|
|
230
|
+
type: 'DYNAMIC_CODE_EXECUTION',
|
|
231
|
+
severity: 'HIGH',
|
|
232
|
+
line: lineNumber,
|
|
233
|
+
message: 'Dynamic code execution detected',
|
|
234
|
+
suggestion: 'Avoid eval() and Function() constructors'
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
if (line.includes('process.env') && !line.includes('require')) {
|
|
239
|
+
issues.push({
|
|
240
|
+
type: 'ENV_VAR_USAGE',
|
|
241
|
+
severity: 'INFO',
|
|
242
|
+
line: lineNumber,
|
|
243
|
+
message: 'Environment variable usage',
|
|
244
|
+
suggestion: 'Ensure proper validation of env vars'
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
return issues;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
aggregateAnalysis(analysis, fileAnalysis, filePath) {
|
|
253
|
+
// Aggregate architecture metrics
|
|
254
|
+
analysis.architecture.totalFiles = (analysis.architecture.totalFiles || 0) + 1;
|
|
255
|
+
analysis.architecture.totalLines = (analysis.architecture.totalLines || 0) + fileAnalysis.lines;
|
|
256
|
+
analysis.architecture.totalFunctions = (analysis.architecture.totalFunctions || 0) + fileAnalysis.functions;
|
|
257
|
+
|
|
258
|
+
// Track patterns
|
|
259
|
+
fileAnalysis.patterns.forEach(pattern => {
|
|
260
|
+
analysis.patterns[pattern] = (analysis.patterns[pattern] || 0) + 1;
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
// Track performance issues
|
|
264
|
+
if (fileAnalysis.performance.length > 0) {
|
|
265
|
+
analysis.performance.issues = (analysis.performance.issues || []).concat(
|
|
266
|
+
fileAnalysis.performance.map(issue => ({
|
|
267
|
+
...issue,
|
|
268
|
+
file: filePath
|
|
269
|
+
}))
|
|
270
|
+
);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
// Track security issues
|
|
274
|
+
if (fileAnalysis.security.length > 0) {
|
|
275
|
+
analysis.security.issues = (analysis.security.issues || []).concat(
|
|
276
|
+
fileAnalysis.security.map(issue => ({
|
|
277
|
+
...issue,
|
|
278
|
+
file: filePath
|
|
279
|
+
}))
|
|
280
|
+
);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
generateInsights(analysis) {
|
|
285
|
+
const insights = [];
|
|
286
|
+
|
|
287
|
+
// Architecture insights
|
|
288
|
+
const avgFunctionsPerFile = analysis.architecture.totalFunctions / analysis.architecture.totalFiles;
|
|
289
|
+
if (avgFunctionsPerFile > 10) {
|
|
290
|
+
insights.push({
|
|
291
|
+
type: 'ARCHITECTURE',
|
|
292
|
+
title: 'High function density',
|
|
293
|
+
description: `Average of ${avgFunctionsPerFile.toFixed(1)} functions per file`,
|
|
294
|
+
recommendation: 'Consider splitting large files into smaller modules'
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
// Pattern insights
|
|
299
|
+
const asyncCount = analysis.patterns['async-await'] || 0;
|
|
300
|
+
if (asyncCount > 0) {
|
|
301
|
+
insights.push({
|
|
302
|
+
type: 'PATTERN',
|
|
303
|
+
title: 'Async/await usage',
|
|
304
|
+
description: `${asyncCount} files use async/await patterns`,
|
|
305
|
+
recommendation: 'Ensure proper error handling for async operations'
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
// Performance insights
|
|
310
|
+
if (analysis.performance.issues && analysis.performance.issues.length > 0) {
|
|
311
|
+
insights.push({
|
|
312
|
+
type: 'PERFORMANCE',
|
|
313
|
+
title: 'Performance optimizations available',
|
|
314
|
+
description: `${analysis.performance.issues.length} performance suggestions`,
|
|
315
|
+
recommendation: 'Review and implement performance improvements'
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
// Security insights
|
|
320
|
+
if (analysis.security.issues && analysis.security.issues.length > 0) {
|
|
321
|
+
const highSeverity = analysis.security.issues.filter(i => i.severity === 'HIGH').length;
|
|
322
|
+
if (highSeverity > 0) {
|
|
323
|
+
insights.push({
|
|
324
|
+
type: 'SECURITY',
|
|
325
|
+
title: 'Security concerns detected',
|
|
326
|
+
description: `${highSeverity} high-severity security issues`,
|
|
327
|
+
recommendation: 'Address security issues immediately'
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
return insights;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
formatReport(report) {
|
|
336
|
+
const output = [];
|
|
337
|
+
|
|
338
|
+
output.push('╔══════════════════════════════════════════════════════════════════════════════╗');
|
|
339
|
+
output.push('║ CODE INTELLIGENCE ENHANCEMENT REPORT ║');
|
|
340
|
+
output.push('╚══════════════════════════════════════════════════════════════════════════════╝\n');
|
|
341
|
+
|
|
342
|
+
output.push('📊 PROJECT OVERVIEW');
|
|
343
|
+
output.push('─'.repeat(60));
|
|
344
|
+
output.push(`Files analyzed: ${report.filesAnalyzed}`);
|
|
345
|
+
output.push(`Total lines: ${report.analysis.architecture.totalLines}`);
|
|
346
|
+
output.push(`Total functions: ${report.analysis.architecture.totalFunctions}`);
|
|
347
|
+
output.push('');
|
|
348
|
+
|
|
349
|
+
output.push('🔍 KEY INSIGHTS');
|
|
350
|
+
output.push('─'.repeat(60));
|
|
351
|
+
|
|
352
|
+
if (report.insights.length === 0) {
|
|
353
|
+
output.push('✅ No significant issues detected');
|
|
354
|
+
} else {
|
|
355
|
+
report.insights.forEach(insight => {
|
|
356
|
+
const icon = {
|
|
357
|
+
'ARCHITECTURE': '🏗️',
|
|
358
|
+
'PATTERN': '🔍',
|
|
359
|
+
'PERFORMANCE': '⚡',
|
|
360
|
+
'SECURITY': '🔒'
|
|
361
|
+
}[insight.type] || '📝';
|
|
362
|
+
|
|
363
|
+
output.push(`${icon} ${insight.title}`);
|
|
364
|
+
output.push(` ${insight.description}`);
|
|
365
|
+
output.push(` → ${insight.recommendation}`);
|
|
366
|
+
output.push('');
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
// Performance issues
|
|
371
|
+
if (report.analysis.performance.issues && report.analysis.performance.issues.length > 0) {
|
|
372
|
+
output.push('⚡ PERFORMANCE SUGGESTIONS');
|
|
373
|
+
output.push('─'.repeat(60));
|
|
374
|
+
|
|
375
|
+
report.analysis.performance.issues.slice(0, 5).forEach(issue => {
|
|
376
|
+
const severityIcon = issue.severity === 'HIGH' ? '🔴' : issue.severity === 'MEDIUM' ? '🟡' : '🔵';
|
|
377
|
+
output.push(`${severityIcon} ${issue.file}:${issue.line}`);
|
|
378
|
+
output.push(` ${issue.message}`);
|
|
379
|
+
output.push(` → ${issue.suggestion}`);
|
|
380
|
+
});
|
|
381
|
+
output.push('');
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
output.push('🚀 RECOMMENDED ACTIONS');
|
|
385
|
+
output.push('─'.repeat(60));
|
|
386
|
+
output.push('• Run "npm run ai-code-review" for detailed file analysis');
|
|
387
|
+
output.push('• Use "npm run complexity-check" for complexity analysis');
|
|
388
|
+
output.push('• Run tests with "npm test" to verify functionality');
|
|
389
|
+
output.push('• Consider adding more unit tests for critical paths');
|
|
390
|
+
|
|
391
|
+
output.push('\n' + '═'.repeat(60));
|
|
392
|
+
|
|
393
|
+
return output.join('\n');
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
// CLI interface
|
|
398
|
+
async function main() {
|
|
399
|
+
const enhancer = new CodeIntelligenceEnhancer();
|
|
400
|
+
|
|
401
|
+
try {
|
|
402
|
+
const report = await enhancer.analyzeProject();
|
|
403
|
+
console.log(enhancer.formatReport(report));
|
|
404
|
+
} catch (error) {
|
|
405
|
+
console.error('❌ Error:', error.message);
|
|
406
|
+
process.exit(1);
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
// Run if called directly
|
|
411
|
+
if (import.meta.url === `file://${process.argv[1]}`) {
|
|
412
|
+
main();
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
export { CodeIntelligenceEnhancer };
|