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.

Files changed (81) hide show
  1. package/README.md +3 -2
  2. package/dist/index.js +172 -90
  3. package/dist/index.js.map +7 -0
  4. package/package.json +6 -1
  5. package/esbuild.config.js +0 -26
  6. package/src/cli/commands.ts +0 -573
  7. package/src/core/adr-exporter.ts +0 -253
  8. package/src/core/architecture/architecture-enforcement.ts +0 -228
  9. package/src/core/architecture/duplicate-detector.ts +0 -288
  10. package/src/core/architecture/index.ts +0 -6
  11. package/src/core/architecture/pattern-learner.ts +0 -306
  12. package/src/core/architecture/pattern-library.ts +0 -403
  13. package/src/core/architecture/pattern-validator.ts +0 -324
  14. package/src/core/change-intelligence/bug-correlator.ts +0 -544
  15. package/src/core/change-intelligence/change-intelligence.ts +0 -264
  16. package/src/core/change-intelligence/change-tracker.ts +0 -334
  17. package/src/core/change-intelligence/fix-suggester.ts +0 -340
  18. package/src/core/change-intelligence/index.ts +0 -5
  19. package/src/core/code-verifier.ts +0 -843
  20. package/src/core/confidence/confidence-scorer.ts +0 -251
  21. package/src/core/confidence/conflict-checker.ts +0 -289
  22. package/src/core/confidence/index.ts +0 -5
  23. package/src/core/confidence/source-tracker.ts +0 -263
  24. package/src/core/confidence/warning-detector.ts +0 -241
  25. package/src/core/context-rot/compaction.ts +0 -284
  26. package/src/core/context-rot/context-health.ts +0 -243
  27. package/src/core/context-rot/context-rot-prevention.ts +0 -213
  28. package/src/core/context-rot/critical-context.ts +0 -221
  29. package/src/core/context-rot/drift-detector.ts +0 -255
  30. package/src/core/context-rot/index.ts +0 -7
  31. package/src/core/context.ts +0 -263
  32. package/src/core/decision-extractor.ts +0 -339
  33. package/src/core/decisions.ts +0 -69
  34. package/src/core/deja-vu.ts +0 -421
  35. package/src/core/engine.ts +0 -1646
  36. package/src/core/feature-context.ts +0 -726
  37. package/src/core/ghost-mode.ts +0 -465
  38. package/src/core/learning.ts +0 -519
  39. package/src/core/living-docs/activity-tracker.ts +0 -296
  40. package/src/core/living-docs/architecture-generator.ts +0 -428
  41. package/src/core/living-docs/changelog-generator.ts +0 -348
  42. package/src/core/living-docs/component-generator.ts +0 -230
  43. package/src/core/living-docs/doc-engine.ts +0 -134
  44. package/src/core/living-docs/doc-validator.ts +0 -282
  45. package/src/core/living-docs/index.ts +0 -8
  46. package/src/core/project-manager.ts +0 -301
  47. package/src/core/refresh/activity-gate.ts +0 -256
  48. package/src/core/refresh/git-staleness-checker.ts +0 -108
  49. package/src/core/refresh/index.ts +0 -27
  50. package/src/core/summarizer.ts +0 -290
  51. package/src/core/test-awareness/change-validator.ts +0 -499
  52. package/src/core/test-awareness/index.ts +0 -5
  53. package/src/index.ts +0 -90
  54. package/src/indexing/ast.ts +0 -868
  55. package/src/indexing/embeddings.ts +0 -85
  56. package/src/indexing/indexer.ts +0 -270
  57. package/src/indexing/watcher.ts +0 -78
  58. package/src/server/gateways/aggregator.ts +0 -374
  59. package/src/server/gateways/index.ts +0 -473
  60. package/src/server/gateways/memory-ghost.ts +0 -343
  61. package/src/server/gateways/memory-query.ts +0 -452
  62. package/src/server/gateways/memory-record.ts +0 -346
  63. package/src/server/gateways/memory-review.ts +0 -410
  64. package/src/server/gateways/memory-status.ts +0 -517
  65. package/src/server/gateways/memory-verify.ts +0 -392
  66. package/src/server/gateways/router.ts +0 -434
  67. package/src/server/gateways/types.ts +0 -610
  68. package/src/server/http.ts +0 -228
  69. package/src/server/mcp.ts +0 -154
  70. package/src/server/resources.ts +0 -85
  71. package/src/server/tools.ts +0 -2460
  72. package/src/storage/database.ts +0 -271
  73. package/src/storage/tier1.ts +0 -135
  74. package/src/storage/tier2.ts +0 -972
  75. package/src/storage/tier3.ts +0 -123
  76. package/src/types/documentation.ts +0 -619
  77. package/src/types/index.ts +0 -222
  78. package/src/utils/config.ts +0 -194
  79. package/src/utils/files.ts +0 -117
  80. package/src/utils/time.ts +0 -37
  81. package/src/utils/tokens.ts +0 -52
@@ -1,374 +0,0 @@
1
- /**
2
- * Result Aggregation Utilities
3
- *
4
- * Combines results from multiple internal tools into unified gateway responses.
5
- */
6
-
7
- import type {
8
- MemoryQueryResponse,
9
- MemoryReviewResponse,
10
- MemoryStatusResponse,
11
- } from './types.js';
12
-
13
- // ============================================================================
14
- // Query Result Aggregation
15
- // ============================================================================
16
-
17
- export interface RawContextResult {
18
- context: string;
19
- sources: string[];
20
- tokenCount: number;
21
- decisions: Array<{
22
- id: string;
23
- title: string;
24
- description: string;
25
- createdAt: Date;
26
- }>;
27
- }
28
-
29
- export interface RawSearchResult {
30
- file: string;
31
- preview: string;
32
- similarity: number;
33
- lineStart?: number;
34
- lineEnd?: number;
35
- }
36
-
37
- /**
38
- * Aggregate context and search results into a unified query response
39
- */
40
- export function aggregateQueryResults(
41
- contextResult: RawContextResult | null,
42
- searchResults: RawSearchResult[] | null,
43
- sourcesUsed: string[]
44
- ): Partial<MemoryQueryResponse> {
45
- const response: Partial<MemoryQueryResponse> = {
46
- sources_used: sourcesUsed,
47
- };
48
-
49
- if (contextResult) {
50
- response.context = {
51
- content: contextResult.context,
52
- sources: contextResult.sources,
53
- token_count: contextResult.tokenCount,
54
- decisions: contextResult.decisions.map(d => ({
55
- id: d.id,
56
- title: d.title,
57
- description: d.description,
58
- created_at: d.createdAt.toISOString(),
59
- })),
60
- };
61
- }
62
-
63
- if (searchResults && searchResults.length > 0) {
64
- // Deduplicate search results by file
65
- const seen = new Set<string>();
66
- const deduped: RawSearchResult[] = [];
67
-
68
- for (const result of searchResults) {
69
- const key = `${result.file}:${result.lineStart || 0}`;
70
- if (!seen.has(key)) {
71
- seen.add(key);
72
- deduped.push(result);
73
- }
74
- }
75
-
76
- response.search_results = deduped.map(r => ({
77
- file: r.file,
78
- preview: r.preview,
79
- relevance: r.similarity,
80
- line_start: r.lineStart,
81
- line_end: r.lineEnd,
82
- }));
83
- }
84
-
85
- return response;
86
- }
87
-
88
- /**
89
- * Merge search results from multiple sources, deduplicating and sorting by relevance
90
- */
91
- export function mergeSearchResults(
92
- ...resultSets: (RawSearchResult[] | null)[]
93
- ): RawSearchResult[] {
94
- const merged: Map<string, RawSearchResult> = new Map();
95
-
96
- for (const results of resultSets) {
97
- if (!results) continue;
98
-
99
- for (const result of results) {
100
- const key = `${result.file}:${result.lineStart || 0}`;
101
- const existing = merged.get(key);
102
-
103
- if (!existing || existing.similarity < result.similarity) {
104
- merged.set(key, result);
105
- }
106
- }
107
- }
108
-
109
- // Sort by relevance descending
110
- return Array.from(merged.values()).sort((a, b) => b.similarity - a.similarity);
111
- }
112
-
113
- // ============================================================================
114
- // Review Result Aggregation
115
- // ============================================================================
116
-
117
- export interface PatternValidationResult {
118
- valid: boolean;
119
- score: number;
120
- matchedPattern?: string;
121
- violations: Array<{
122
- rule: string;
123
- message: string;
124
- severity: string;
125
- suggestion?: string;
126
- }>;
127
- }
128
-
129
- export interface ConflictCheckResult {
130
- hasConflicts: boolean;
131
- conflicts: Array<{
132
- decisionId: string;
133
- decisionTitle: string;
134
- conflictDescription: string;
135
- severity: string;
136
- decisionDate: Date;
137
- }>;
138
- }
139
-
140
- export interface ConfidenceCheckResult {
141
- confidence: string;
142
- score: number;
143
- reasoning: string;
144
- }
145
-
146
- export interface TestCheckResult {
147
- safe: boolean;
148
- coveragePercent: number;
149
- wouldFail: Array<{
150
- test: { id: string; name: string; file: string };
151
- reason: string;
152
- suggestedFix?: string;
153
- }>;
154
- suggestedTestUpdates: Array<{
155
- file: string;
156
- testName: string;
157
- before: string;
158
- after: string;
159
- reason: string;
160
- }>;
161
- }
162
-
163
- export interface ExistingFunctionResult {
164
- name: string;
165
- file: string;
166
- line: number;
167
- signature: string;
168
- similarity: number;
169
- }
170
-
171
- /**
172
- * Calculate a unified risk score from review results
173
- *
174
- * Scoring factors:
175
- * - Pattern validation: 0-30 points (based on violations)
176
- * - Conflicts: 0-40 points (critical if conflicts exist)
177
- * - Test impact: 0-20 points (based on failing tests)
178
- * - Confidence: 0-10 points (low confidence adds risk)
179
- */
180
- export function calculateRiskScore(
181
- patternResult: PatternValidationResult | null,
182
- conflicts: ConflictCheckResult | null,
183
- testResult: TestCheckResult | null,
184
- confidence: ConfidenceCheckResult | null
185
- ): number {
186
- let riskScore = 0;
187
-
188
- // Pattern violations (0-30 points)
189
- if (patternResult) {
190
- const violationRisk = Math.min(30, patternResult.violations.length * 10);
191
- // Higher severity violations count more
192
- const severityBonus = patternResult.violations.filter(
193
- v => v.severity === 'high' || v.severity === 'error'
194
- ).length * 5;
195
- riskScore += Math.min(30, violationRisk + severityBonus);
196
- }
197
-
198
- // Conflicts (0-40 points) - conflicts with past decisions are serious
199
- if (conflicts && conflicts.hasConflicts) {
200
- const conflictRisk = Math.min(40, conflicts.conflicts.length * 20);
201
- riskScore += conflictRisk;
202
- }
203
-
204
- // Test impact (0-20 points)
205
- if (testResult && !testResult.safe) {
206
- const testRisk = Math.min(20, testResult.wouldFail.length * 10);
207
- riskScore += testRisk;
208
- }
209
-
210
- // Low confidence (0-10 points)
211
- if (confidence) {
212
- if (confidence.confidence === 'low') {
213
- riskScore += 10;
214
- } else if (confidence.confidence === 'medium') {
215
- riskScore += 5;
216
- }
217
- }
218
-
219
- return Math.min(100, riskScore);
220
- }
221
-
222
- /**
223
- * Determine verdict based on risk score
224
- */
225
- export function getVerdict(riskScore: number): 'approve' | 'warning' | 'reject' {
226
- if (riskScore >= 70) return 'reject';
227
- if (riskScore >= 30) return 'warning';
228
- return 'approve';
229
- }
230
-
231
- /**
232
- * Aggregate review results into a unified response
233
- */
234
- export function aggregateReviewResults(
235
- patternResult: PatternValidationResult | null,
236
- conflicts: ConflictCheckResult | null,
237
- confidence: ConfidenceCheckResult | null,
238
- existingAlternatives: ExistingFunctionResult[] | null,
239
- testResult: TestCheckResult | null,
240
- sourcesUsed: string[]
241
- ): MemoryReviewResponse {
242
- const riskScore = calculateRiskScore(patternResult, conflicts, testResult, confidence);
243
-
244
- const response: MemoryReviewResponse = {
245
- verdict: getVerdict(riskScore),
246
- risk_score: riskScore,
247
- sources_used: sourcesUsed,
248
- };
249
-
250
- if (patternResult) {
251
- response.patterns = {
252
- valid: patternResult.valid,
253
- score: patternResult.score,
254
- matched_pattern: patternResult.matchedPattern,
255
- violations: patternResult.violations,
256
- };
257
- }
258
-
259
- if (conflicts) {
260
- response.conflicts = {
261
- has_conflicts: conflicts.hasConflicts,
262
- conflicts: conflicts.conflicts.map(c => ({
263
- decision_id: c.decisionId,
264
- decision_title: c.decisionTitle,
265
- conflict_description: c.conflictDescription,
266
- severity: c.severity,
267
- })),
268
- };
269
- }
270
-
271
- if (existingAlternatives && existingAlternatives.length > 0) {
272
- response.existing_alternatives = existingAlternatives.map(a => ({
273
- name: a.name,
274
- file: a.file,
275
- line: a.line,
276
- signature: a.signature,
277
- similarity: a.similarity,
278
- }));
279
- }
280
-
281
- if (testResult) {
282
- response.test_impact = {
283
- safe: testResult.safe,
284
- coverage_percent: testResult.coveragePercent,
285
- would_fail: testResult.wouldFail.map(f => ({
286
- test_name: f.test.name,
287
- test_file: f.test.file,
288
- reason: f.reason,
289
- suggested_fix: f.suggestedFix,
290
- })),
291
- suggested_updates: testResult.suggestedTestUpdates.map(u => ({
292
- file: u.file,
293
- test_name: u.testName,
294
- before: u.before,
295
- after: u.after,
296
- reason: u.reason,
297
- })),
298
- };
299
- }
300
-
301
- if (confidence) {
302
- response.confidence = {
303
- level: confidence.confidence,
304
- score: confidence.score,
305
- reasoning: confidence.reasoning,
306
- };
307
- }
308
-
309
- return response;
310
- }
311
-
312
- // ============================================================================
313
- // Status Result Aggregation
314
- // ============================================================================
315
-
316
- /**
317
- * Build a status response from multiple gathered results
318
- */
319
- export function aggregateStatusResults(
320
- results: Record<string, unknown>,
321
- sourcesUsed: string[]
322
- ): MemoryStatusResponse {
323
- const response: MemoryStatusResponse = {
324
- sources_used: sourcesUsed,
325
- };
326
-
327
- // Copy relevant results into response
328
- if (results.project) response.project = results.project as MemoryStatusResponse['project'];
329
- if (results.architecture) response.architecture = results.architecture as MemoryStatusResponse['architecture'];
330
- if (results.changes) response.changes = results.changes as MemoryStatusResponse['changes'];
331
- if (results.activity) response.activity = results.activity as MemoryStatusResponse['activity'];
332
- if (results.changelog) response.changelog = results.changelog as MemoryStatusResponse['changelog'];
333
- if (results.docs) response.docs = results.docs as MemoryStatusResponse['docs'];
334
- if (results.health) response.health = results.health as MemoryStatusResponse['health'];
335
- if (results.patterns) response.patterns = results.patterns as MemoryStatusResponse['patterns'];
336
- if (results.stats) response.stats = results.stats as MemoryStatusResponse['stats'];
337
- if (results.critical) response.critical = results.critical as MemoryStatusResponse['critical'];
338
- if (results.learning) response.learning = results.learning as MemoryStatusResponse['learning'];
339
- if (results.undocumented) response.undocumented = results.undocumented as MemoryStatusResponse['undocumented'];
340
-
341
- return response;
342
- }
343
-
344
- // ============================================================================
345
- // Utility Functions
346
- // ============================================================================
347
-
348
- /**
349
- * Truncate a string to a maximum length with ellipsis
350
- */
351
- export function truncate(str: string, maxLength: number): string {
352
- if (str.length <= maxLength) return str;
353
- return str.slice(0, maxLength - 3) + '...';
354
- }
355
-
356
- /**
357
- * Format a date for display
358
- */
359
- export function formatDate(date: Date): string {
360
- return date.toISOString();
361
- }
362
-
363
- /**
364
- * Calculate time ago string
365
- */
366
- export function timeAgo(date: Date): string {
367
- const seconds = Math.floor((Date.now() - date.getTime()) / 1000);
368
-
369
- if (seconds < 60) return 'just now';
370
- if (seconds < 3600) return `${Math.floor(seconds / 60)}m ago`;
371
- if (seconds < 86400) return `${Math.floor(seconds / 3600)}h ago`;
372
- if (seconds < 604800) return `${Math.floor(seconds / 86400)}d ago`;
373
- return date.toISOString().split('T')[0] || date.toISOString();
374
- }