neuronlayer 0.1.9 → 0.2.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.
Potentially problematic release.
This version of neuronlayer might be problematic. Click here for more details.
- package/README.md +3 -2
- package/dist/index.js +172 -90
- package/dist/index.js.map +7 -0
- package/package.json +6 -1
- package/esbuild.config.js +0 -26
- package/src/cli/commands.ts +0 -573
- package/src/core/adr-exporter.ts +0 -253
- package/src/core/architecture/architecture-enforcement.ts +0 -228
- package/src/core/architecture/duplicate-detector.ts +0 -288
- package/src/core/architecture/index.ts +0 -6
- package/src/core/architecture/pattern-learner.ts +0 -306
- package/src/core/architecture/pattern-library.ts +0 -403
- package/src/core/architecture/pattern-validator.ts +0 -324
- package/src/core/change-intelligence/bug-correlator.ts +0 -544
- package/src/core/change-intelligence/change-intelligence.ts +0 -264
- package/src/core/change-intelligence/change-tracker.ts +0 -334
- package/src/core/change-intelligence/fix-suggester.ts +0 -340
- package/src/core/change-intelligence/index.ts +0 -5
- package/src/core/code-verifier.ts +0 -843
- package/src/core/confidence/confidence-scorer.ts +0 -251
- package/src/core/confidence/conflict-checker.ts +0 -289
- package/src/core/confidence/index.ts +0 -5
- package/src/core/confidence/source-tracker.ts +0 -263
- package/src/core/confidence/warning-detector.ts +0 -241
- package/src/core/context-rot/compaction.ts +0 -284
- package/src/core/context-rot/context-health.ts +0 -243
- package/src/core/context-rot/context-rot-prevention.ts +0 -213
- package/src/core/context-rot/critical-context.ts +0 -221
- package/src/core/context-rot/drift-detector.ts +0 -255
- package/src/core/context-rot/index.ts +0 -7
- package/src/core/context.ts +0 -263
- package/src/core/decision-extractor.ts +0 -339
- package/src/core/decisions.ts +0 -69
- package/src/core/deja-vu.ts +0 -421
- package/src/core/engine.ts +0 -1646
- package/src/core/feature-context.ts +0 -726
- package/src/core/ghost-mode.ts +0 -465
- package/src/core/learning.ts +0 -519
- package/src/core/living-docs/activity-tracker.ts +0 -296
- package/src/core/living-docs/architecture-generator.ts +0 -428
- package/src/core/living-docs/changelog-generator.ts +0 -348
- package/src/core/living-docs/component-generator.ts +0 -230
- package/src/core/living-docs/doc-engine.ts +0 -134
- package/src/core/living-docs/doc-validator.ts +0 -282
- package/src/core/living-docs/index.ts +0 -8
- package/src/core/project-manager.ts +0 -301
- package/src/core/refresh/activity-gate.ts +0 -256
- package/src/core/refresh/git-staleness-checker.ts +0 -108
- package/src/core/refresh/index.ts +0 -27
- package/src/core/summarizer.ts +0 -290
- package/src/core/test-awareness/change-validator.ts +0 -499
- package/src/core/test-awareness/index.ts +0 -5
- package/src/index.ts +0 -90
- package/src/indexing/ast.ts +0 -868
- package/src/indexing/embeddings.ts +0 -85
- package/src/indexing/indexer.ts +0 -270
- package/src/indexing/watcher.ts +0 -78
- package/src/server/gateways/aggregator.ts +0 -374
- package/src/server/gateways/index.ts +0 -473
- package/src/server/gateways/memory-ghost.ts +0 -343
- package/src/server/gateways/memory-query.ts +0 -452
- package/src/server/gateways/memory-record.ts +0 -346
- package/src/server/gateways/memory-review.ts +0 -410
- package/src/server/gateways/memory-status.ts +0 -517
- package/src/server/gateways/memory-verify.ts +0 -392
- package/src/server/gateways/router.ts +0 -434
- package/src/server/gateways/types.ts +0 -610
- package/src/server/http.ts +0 -228
- package/src/server/mcp.ts +0 -154
- package/src/server/resources.ts +0 -85
- package/src/server/tools.ts +0 -2460
- package/src/storage/database.ts +0 -271
- package/src/storage/tier1.ts +0 -135
- package/src/storage/tier2.ts +0 -972
- package/src/storage/tier3.ts +0 -123
- package/src/types/documentation.ts +0 -619
- package/src/types/index.ts +0 -222
- package/src/utils/config.ts +0 -194
- package/src/utils/files.ts +0 -117
- package/src/utils/time.ts +0 -37
- package/src/utils/tokens.ts +0 -52
|
@@ -1,340 +0,0 @@
|
|
|
1
|
-
import type Database from 'better-sqlite3';
|
|
2
|
-
import type { FixSuggestion, PastBug, Change } from '../../types/documentation.js';
|
|
3
|
-
import type { BugCorrelator } from './bug-correlator.js';
|
|
4
|
-
import type { ChangeTracker } from './change-tracker.js';
|
|
5
|
-
|
|
6
|
-
// Common fix patterns
|
|
7
|
-
const FIX_PATTERNS = [
|
|
8
|
-
{
|
|
9
|
-
errorPattern: /cannot read (?:property |properties of )['"]?(\w+)['"]? of (?:undefined|null)/i,
|
|
10
|
-
suggestions: [
|
|
11
|
-
{
|
|
12
|
-
fix: 'Add optional chaining (?.) before accessing the property',
|
|
13
|
-
diff: '+ obj?.property instead of obj.property',
|
|
14
|
-
confidence: 85
|
|
15
|
-
},
|
|
16
|
-
{
|
|
17
|
-
fix: 'Add null/undefined check before accessing',
|
|
18
|
-
diff: '+ if (obj && obj.property) { ... }',
|
|
19
|
-
confidence: 80
|
|
20
|
-
}
|
|
21
|
-
]
|
|
22
|
-
},
|
|
23
|
-
{
|
|
24
|
-
errorPattern: /(\w+) is not defined/i,
|
|
25
|
-
suggestions: [
|
|
26
|
-
{
|
|
27
|
-
fix: 'Add missing import statement',
|
|
28
|
-
diff: '+ import { $1 } from "module"',
|
|
29
|
-
confidence: 75
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
fix: 'Declare the variable before use',
|
|
33
|
-
diff: '+ const $1 = ...',
|
|
34
|
-
confidence: 70
|
|
35
|
-
}
|
|
36
|
-
]
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
errorPattern: /(\w+) is not a function/i,
|
|
40
|
-
suggestions: [
|
|
41
|
-
{
|
|
42
|
-
fix: 'Check if the method exists on the object',
|
|
43
|
-
diff: '+ if (typeof obj.method === "function") { obj.method() }',
|
|
44
|
-
confidence: 70
|
|
45
|
-
},
|
|
46
|
-
{
|
|
47
|
-
fix: 'Verify the import is correct',
|
|
48
|
-
diff: 'Check that the function is exported from the source module',
|
|
49
|
-
confidence: 65
|
|
50
|
-
}
|
|
51
|
-
]
|
|
52
|
-
},
|
|
53
|
-
{
|
|
54
|
-
errorPattern: /unexpected token/i,
|
|
55
|
-
suggestions: [
|
|
56
|
-
{
|
|
57
|
-
fix: 'Check for JSON.parse on invalid JSON',
|
|
58
|
-
diff: '+ try { JSON.parse(data) } catch { ... }',
|
|
59
|
-
confidence: 70
|
|
60
|
-
},
|
|
61
|
-
{
|
|
62
|
-
fix: 'Validate data before parsing',
|
|
63
|
-
diff: '+ if (typeof data === "string" && data.startsWith("{")) { ... }',
|
|
64
|
-
confidence: 65
|
|
65
|
-
}
|
|
66
|
-
]
|
|
67
|
-
},
|
|
68
|
-
{
|
|
69
|
-
errorPattern: /timeout|timed out/i,
|
|
70
|
-
suggestions: [
|
|
71
|
-
{
|
|
72
|
-
fix: 'Increase timeout value',
|
|
73
|
-
diff: '+ timeout: 30000 // Increase from default',
|
|
74
|
-
confidence: 60
|
|
75
|
-
},
|
|
76
|
-
{
|
|
77
|
-
fix: 'Add retry logic',
|
|
78
|
-
diff: '+ for (let i = 0; i < 3; i++) { try { ... } catch { await delay(1000) } }',
|
|
79
|
-
confidence: 55
|
|
80
|
-
}
|
|
81
|
-
]
|
|
82
|
-
},
|
|
83
|
-
{
|
|
84
|
-
errorPattern: /ECONNREFUSED|connection refused/i,
|
|
85
|
-
suggestions: [
|
|
86
|
-
{
|
|
87
|
-
fix: 'Verify the service is running',
|
|
88
|
-
diff: 'Check that the database/API server is started',
|
|
89
|
-
confidence: 80
|
|
90
|
-
},
|
|
91
|
-
{
|
|
92
|
-
fix: 'Check port and host configuration',
|
|
93
|
-
diff: 'Verify PORT and HOST environment variables',
|
|
94
|
-
confidence: 75
|
|
95
|
-
}
|
|
96
|
-
]
|
|
97
|
-
},
|
|
98
|
-
{
|
|
99
|
-
errorPattern: /out of memory|heap/i,
|
|
100
|
-
suggestions: [
|
|
101
|
-
{
|
|
102
|
-
fix: 'Process data in chunks',
|
|
103
|
-
diff: '+ for (const chunk of chunks(data, 1000)) { process(chunk) }',
|
|
104
|
-
confidence: 70
|
|
105
|
-
},
|
|
106
|
-
{
|
|
107
|
-
fix: 'Increase Node.js memory limit',
|
|
108
|
-
diff: '+ node --max-old-space-size=4096 app.js',
|
|
109
|
-
confidence: 60
|
|
110
|
-
}
|
|
111
|
-
]
|
|
112
|
-
},
|
|
113
|
-
{
|
|
114
|
-
errorPattern: /module not found|cannot find module/i,
|
|
115
|
-
suggestions: [
|
|
116
|
-
{
|
|
117
|
-
fix: 'Install missing package',
|
|
118
|
-
diff: '+ npm install <package-name>',
|
|
119
|
-
confidence: 85
|
|
120
|
-
},
|
|
121
|
-
{
|
|
122
|
-
fix: 'Check import path is correct',
|
|
123
|
-
diff: 'Verify relative path (./module vs ../module)',
|
|
124
|
-
confidence: 75
|
|
125
|
-
}
|
|
126
|
-
]
|
|
127
|
-
},
|
|
128
|
-
{
|
|
129
|
-
errorPattern: /type.*is not assignable/i,
|
|
130
|
-
suggestions: [
|
|
131
|
-
{
|
|
132
|
-
fix: 'Add type assertion',
|
|
133
|
-
diff: '+ value as ExpectedType',
|
|
134
|
-
confidence: 60
|
|
135
|
-
},
|
|
136
|
-
{
|
|
137
|
-
fix: 'Fix the type definition',
|
|
138
|
-
diff: 'Update interface/type to match actual data',
|
|
139
|
-
confidence: 70
|
|
140
|
-
}
|
|
141
|
-
]
|
|
142
|
-
},
|
|
143
|
-
{
|
|
144
|
-
errorPattern: /async|await|promise/i,
|
|
145
|
-
suggestions: [
|
|
146
|
-
{
|
|
147
|
-
fix: 'Add await keyword',
|
|
148
|
-
diff: '+ const result = await asyncFunction()',
|
|
149
|
-
confidence: 75
|
|
150
|
-
},
|
|
151
|
-
{
|
|
152
|
-
fix: 'Handle promise rejection',
|
|
153
|
-
diff: '+ .catch(err => console.error(err))',
|
|
154
|
-
confidence: 70
|
|
155
|
-
}
|
|
156
|
-
]
|
|
157
|
-
}
|
|
158
|
-
];
|
|
159
|
-
|
|
160
|
-
export class FixSuggester {
|
|
161
|
-
private db: Database.Database;
|
|
162
|
-
private bugCorrelator: BugCorrelator;
|
|
163
|
-
private changeTracker: ChangeTracker;
|
|
164
|
-
|
|
165
|
-
constructor(
|
|
166
|
-
db: Database.Database,
|
|
167
|
-
bugCorrelator: BugCorrelator,
|
|
168
|
-
changeTracker: ChangeTracker
|
|
169
|
-
) {
|
|
170
|
-
this.db = db;
|
|
171
|
-
this.bugCorrelator = bugCorrelator;
|
|
172
|
-
this.changeTracker = changeTracker;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
suggestFix(error: string, context?: string): FixSuggestion[] {
|
|
176
|
-
const suggestions: FixSuggestion[] = [];
|
|
177
|
-
|
|
178
|
-
// 1. Check for similar bugs with fixes
|
|
179
|
-
const pastBugs = this.bugCorrelator.findSimilarBugs(error, 5);
|
|
180
|
-
for (const bug of pastBugs) {
|
|
181
|
-
if (bug.fix || bug.fixDiff) {
|
|
182
|
-
suggestions.push({
|
|
183
|
-
confidence: bug.similarity,
|
|
184
|
-
fix: bug.fix || 'Apply similar fix',
|
|
185
|
-
reason: `Fixed similar issue on ${bug.date.toLocaleDateString()}`,
|
|
186
|
-
diff: bug.fixDiff,
|
|
187
|
-
pastFix: {
|
|
188
|
-
date: bug.date,
|
|
189
|
-
file: bug.file || 'unknown',
|
|
190
|
-
bugId: bug.id
|
|
191
|
-
},
|
|
192
|
-
source: 'history'
|
|
193
|
-
});
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
// 2. Check for pattern-based suggestions
|
|
198
|
-
for (const { errorPattern, suggestions: patternSuggestions } of FIX_PATTERNS) {
|
|
199
|
-
const match = error.match(errorPattern);
|
|
200
|
-
if (match) {
|
|
201
|
-
for (const suggestion of patternSuggestions) {
|
|
202
|
-
// Replace $1 with captured group if present
|
|
203
|
-
let fix = suggestion.fix;
|
|
204
|
-
let diff = suggestion.diff;
|
|
205
|
-
if (match[1]) {
|
|
206
|
-
fix = fix.replace('$1', match[1]);
|
|
207
|
-
diff = diff.replace('$1', match[1]);
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
suggestions.push({
|
|
211
|
-
confidence: suggestion.confidence,
|
|
212
|
-
fix,
|
|
213
|
-
reason: 'Common fix for this error type',
|
|
214
|
-
diff,
|
|
215
|
-
source: 'pattern'
|
|
216
|
-
});
|
|
217
|
-
}
|
|
218
|
-
break; // Only use first matching pattern
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
// 3. Check if recent changes can be reverted
|
|
223
|
-
if (suggestions.length < 3) {
|
|
224
|
-
const revertSuggestion = this.checkRevertOption(error);
|
|
225
|
-
if (revertSuggestion) {
|
|
226
|
-
suggestions.push(revertSuggestion);
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
// 4. Add general suggestions based on context
|
|
231
|
-
if (context) {
|
|
232
|
-
const contextSuggestion = this.getContextBasedSuggestion(error, context);
|
|
233
|
-
if (contextSuggestion) {
|
|
234
|
-
suggestions.push(contextSuggestion);
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
// Sort by confidence
|
|
239
|
-
suggestions.sort((a, b) => b.confidence - a.confidence);
|
|
240
|
-
|
|
241
|
-
// Return top 5
|
|
242
|
-
return suggestions.slice(0, 5);
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
private checkRevertOption(error: string): FixSuggestion | null {
|
|
246
|
-
// Check if a recent change might have caused this
|
|
247
|
-
const keywords = error.split(/\s+/)
|
|
248
|
-
.filter(w => w.length > 3)
|
|
249
|
-
.slice(0, 5);
|
|
250
|
-
|
|
251
|
-
const recentChanges = this.changeTracker.getRecentChanges(24);
|
|
252
|
-
|
|
253
|
-
for (const change of recentChanges) {
|
|
254
|
-
const changeText = `${change.file} ${change.diff}`.toLowerCase();
|
|
255
|
-
const matchCount = keywords.filter(k => changeText.includes(k.toLowerCase())).length;
|
|
256
|
-
|
|
257
|
-
if (matchCount >= 2 && change.linesRemoved > 0) {
|
|
258
|
-
return {
|
|
259
|
-
confidence: 50,
|
|
260
|
-
fix: `Consider reverting recent change in ${change.file}`,
|
|
261
|
-
reason: `This file was modified ${Math.round((Date.now() - change.timestamp.getTime()) / (1000 * 60 * 60))}h ago and may have introduced the issue`,
|
|
262
|
-
diff: `git revert ${change.commitHash}`,
|
|
263
|
-
pastFix: {
|
|
264
|
-
date: change.timestamp,
|
|
265
|
-
file: change.file
|
|
266
|
-
},
|
|
267
|
-
source: 'history'
|
|
268
|
-
};
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
return null;
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
private getContextBasedSuggestion(error: string, context: string): FixSuggestion | null {
|
|
276
|
-
const contextLower = context.toLowerCase();
|
|
277
|
-
const errorLower = error.toLowerCase();
|
|
278
|
-
|
|
279
|
-
// Database-related
|
|
280
|
-
if (contextLower.includes('database') || contextLower.includes('query')) {
|
|
281
|
-
if (errorLower.includes('timeout')) {
|
|
282
|
-
return {
|
|
283
|
-
confidence: 55,
|
|
284
|
-
fix: 'Add database index or optimize query',
|
|
285
|
-
reason: 'Database timeouts often indicate missing indexes',
|
|
286
|
-
diff: 'CREATE INDEX idx_column ON table(column)',
|
|
287
|
-
source: 'general'
|
|
288
|
-
};
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
// API-related
|
|
293
|
-
if (contextLower.includes('api') || contextLower.includes('fetch')) {
|
|
294
|
-
if (errorLower.includes('undefined') || errorLower.includes('null')) {
|
|
295
|
-
return {
|
|
296
|
-
confidence: 55,
|
|
297
|
-
fix: 'Add response validation before accessing data',
|
|
298
|
-
reason: 'API responses should be validated before use',
|
|
299
|
-
diff: 'if (response?.data) { ... }',
|
|
300
|
-
source: 'general'
|
|
301
|
-
};
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
// React/Component-related
|
|
306
|
-
if (contextLower.includes('component') || contextLower.includes('react')) {
|
|
307
|
-
if (errorLower.includes('undefined') || errorLower.includes('null')) {
|
|
308
|
-
return {
|
|
309
|
-
confidence: 55,
|
|
310
|
-
fix: 'Add null check or default value for props',
|
|
311
|
-
reason: 'Component props may be undefined initially',
|
|
312
|
-
diff: 'const value = props.value ?? defaultValue',
|
|
313
|
-
source: 'general'
|
|
314
|
-
};
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
return null;
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
// Get fix statistics
|
|
322
|
-
getFixStats(): {
|
|
323
|
-
totalFixes: number;
|
|
324
|
-
successRate: number;
|
|
325
|
-
avgConfidence: number;
|
|
326
|
-
topPatterns: Array<{ pattern: string; count: number }>;
|
|
327
|
-
} {
|
|
328
|
-
// This would ideally track actual fix success over time
|
|
329
|
-
// For now, return pattern-based stats
|
|
330
|
-
return {
|
|
331
|
-
totalFixes: FIX_PATTERNS.length * 2, // Each pattern has ~2 suggestions
|
|
332
|
-
successRate: 75, // Estimated
|
|
333
|
-
avgConfidence: 70,
|
|
334
|
-
topPatterns: FIX_PATTERNS.slice(0, 5).map((p, i) => ({
|
|
335
|
-
pattern: p.errorPattern.source.slice(0, 30),
|
|
336
|
-
count: 10 - i // Placeholder counts
|
|
337
|
-
}))
|
|
338
|
-
};
|
|
339
|
-
}
|
|
340
|
-
}
|