neuronlayer 0.1.0 → 1.1.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.
Files changed (78) hide show
  1. package/README.md +203 -123
  2. package/dist/index.js +635 -710
  3. package/dist/index.js.map +7 -0
  4. package/package.json +67 -63
  5. package/CONTRIBUTING.md +0 -127
  6. package/esbuild.config.js +0 -26
  7. package/src/cli/commands.ts +0 -382
  8. package/src/core/adr-exporter.ts +0 -253
  9. package/src/core/architecture/architecture-enforcement.ts +0 -228
  10. package/src/core/architecture/duplicate-detector.ts +0 -288
  11. package/src/core/architecture/index.ts +0 -6
  12. package/src/core/architecture/pattern-learner.ts +0 -306
  13. package/src/core/architecture/pattern-library.ts +0 -403
  14. package/src/core/architecture/pattern-validator.ts +0 -324
  15. package/src/core/change-intelligence/bug-correlator.ts +0 -444
  16. package/src/core/change-intelligence/change-intelligence.ts +0 -221
  17. package/src/core/change-intelligence/change-tracker.ts +0 -334
  18. package/src/core/change-intelligence/fix-suggester.ts +0 -340
  19. package/src/core/change-intelligence/index.ts +0 -5
  20. package/src/core/code-verifier.ts +0 -843
  21. package/src/core/confidence/confidence-scorer.ts +0 -251
  22. package/src/core/confidence/conflict-checker.ts +0 -289
  23. package/src/core/confidence/index.ts +0 -5
  24. package/src/core/confidence/source-tracker.ts +0 -263
  25. package/src/core/confidence/warning-detector.ts +0 -241
  26. package/src/core/context-rot/compaction.ts +0 -284
  27. package/src/core/context-rot/context-health.ts +0 -243
  28. package/src/core/context-rot/context-rot-prevention.ts +0 -213
  29. package/src/core/context-rot/critical-context.ts +0 -221
  30. package/src/core/context-rot/drift-detector.ts +0 -255
  31. package/src/core/context-rot/index.ts +0 -7
  32. package/src/core/context.ts +0 -263
  33. package/src/core/decision-extractor.ts +0 -339
  34. package/src/core/decisions.ts +0 -69
  35. package/src/core/deja-vu.ts +0 -421
  36. package/src/core/engine.ts +0 -1455
  37. package/src/core/feature-context.ts +0 -726
  38. package/src/core/ghost-mode.ts +0 -412
  39. package/src/core/learning.ts +0 -485
  40. package/src/core/living-docs/activity-tracker.ts +0 -296
  41. package/src/core/living-docs/architecture-generator.ts +0 -428
  42. package/src/core/living-docs/changelog-generator.ts +0 -348
  43. package/src/core/living-docs/component-generator.ts +0 -230
  44. package/src/core/living-docs/doc-engine.ts +0 -110
  45. package/src/core/living-docs/doc-validator.ts +0 -282
  46. package/src/core/living-docs/index.ts +0 -8
  47. package/src/core/project-manager.ts +0 -297
  48. package/src/core/summarizer.ts +0 -267
  49. package/src/core/test-awareness/change-validator.ts +0 -499
  50. package/src/core/test-awareness/index.ts +0 -5
  51. package/src/index.ts +0 -49
  52. package/src/indexing/ast.ts +0 -563
  53. package/src/indexing/embeddings.ts +0 -85
  54. package/src/indexing/indexer.ts +0 -245
  55. package/src/indexing/watcher.ts +0 -78
  56. package/src/server/gateways/aggregator.ts +0 -374
  57. package/src/server/gateways/index.ts +0 -473
  58. package/src/server/gateways/memory-ghost.ts +0 -343
  59. package/src/server/gateways/memory-query.ts +0 -452
  60. package/src/server/gateways/memory-record.ts +0 -346
  61. package/src/server/gateways/memory-review.ts +0 -410
  62. package/src/server/gateways/memory-status.ts +0 -517
  63. package/src/server/gateways/memory-verify.ts +0 -392
  64. package/src/server/gateways/router.ts +0 -434
  65. package/src/server/gateways/types.ts +0 -610
  66. package/src/server/mcp.ts +0 -154
  67. package/src/server/resources.ts +0 -85
  68. package/src/server/tools.ts +0 -2261
  69. package/src/storage/database.ts +0 -262
  70. package/src/storage/tier1.ts +0 -135
  71. package/src/storage/tier2.ts +0 -764
  72. package/src/storage/tier3.ts +0 -123
  73. package/src/types/documentation.ts +0 -619
  74. package/src/types/index.ts +0 -222
  75. package/src/utils/config.ts +0 -193
  76. package/src/utils/files.ts +0 -117
  77. package/src/utils/time.ts +0 -37
  78. package/src/utils/tokens.ts +0 -52
@@ -1,346 +0,0 @@
1
- /**
2
- * Memory Record Gateway
3
- *
4
- * Routes to: record_decision, record_decision_with_author, learn_pattern,
5
- * mark_context_useful, set_feature_context, mark_critical, add_pattern_example
6
- *
7
- * Smart Decision Detection: Auto-detects when content looks like a decision
8
- */
9
-
10
- import type { MemoryLayerEngine } from '../../core/engine.js';
11
- import type { MemoryRecordInput, MemoryRecordResponse } from './types.js';
12
- import { detectRecordType, validateRecordInput } from './router.js';
13
-
14
- // Patterns that indicate decision-like content
15
- const DECISION_PATTERNS = [
16
- /we('ll| will) use/i,
17
- /decided to/i,
18
- /going with/i,
19
- /instead of/i,
20
- /because.*better/i,
21
- /chose/i,
22
- /choosing/i,
23
- /prefer/i,
24
- /preferring/i,
25
- /let's use/i,
26
- /we should use/i,
27
- /the approach is/i,
28
- /our strategy is/i,
29
- /we're using/i,
30
- /will implement.*using/i,
31
- /architecture.*decision/i,
32
- /technical.*decision/i,
33
- ];
34
-
35
- /**
36
- * Check if content looks like an architectural decision
37
- */
38
- function looksLikeDecision(content: string): boolean {
39
- return DECISION_PATTERNS.some(re => re.test(content));
40
- }
41
-
42
- /**
43
- * Extract a potential title from decision-like content
44
- */
45
- function extractDecisionTitle(content: string): string | null {
46
- // Try to find a clear decision statement
47
- const patterns = [
48
- /(?:decided to|we'll|we will|going with|chose|choosing)\s+(.+?)(?:\.|$)/i,
49
- /(?:use|using)\s+(\w+(?:\s+\w+){0,3})\s+(?:for|instead|because)/i,
50
- /(?:prefer|preferring)\s+(.+?)\s+(?:over|instead|to)/i,
51
- ];
52
-
53
- for (const pattern of patterns) {
54
- const match = content.match(pattern);
55
- if (match && match[1]) {
56
- // Capitalize first letter and clean up
57
- const title = match[1].trim();
58
- return title.charAt(0).toUpperCase() + title.slice(1);
59
- }
60
- }
61
-
62
- // Fallback: use first sentence, truncated
63
- const firstSentence = content.split(/[.!?]/)[0];
64
- if (firstSentence && firstSentence.length > 0) {
65
- return firstSentence.slice(0, 50) + (firstSentence.length > 50 ? '...' : '');
66
- }
67
-
68
- return null;
69
- }
70
-
71
- /**
72
- * Handle a memory_record gateway call
73
- */
74
- export async function handleMemoryRecord(
75
- engine: MemoryLayerEngine,
76
- input: MemoryRecordInput
77
- ): Promise<MemoryRecordResponse> {
78
- // Validate input
79
- const validation = validateRecordInput(input);
80
- if (!validation.valid) {
81
- return {
82
- success: false,
83
- type: validation.type,
84
- message: validation.error || 'Invalid input',
85
- };
86
- }
87
-
88
- let recordType = validation.type;
89
- let warnings: MemoryRecordResponse['warnings'] = undefined;
90
-
91
- // Smart Decision Detection: Check if content looks like a decision
92
- if (recordType !== 'decision' && looksLikeDecision(input.content)) {
93
- if (!input.title) {
94
- // Content looks like a decision but no title - add hint
95
- const suggestedTitle = extractDecisionTitle(input.content);
96
- warnings = [{
97
- type: 'hint',
98
- message: `This looks like an architectural decision. ${suggestedTitle
99
- ? `Suggested title: "${suggestedTitle}". `
100
- : ''}Add a title to save it as a decision.`,
101
- severity: 'low',
102
- }];
103
-
104
- // If the caller didn't specify a type and it looks like a decision, offer to record it
105
- if (!input.type && suggestedTitle) {
106
- // Auto-upgrade to decision if we can extract a title
107
- recordType = 'decision';
108
- input.title = suggestedTitle;
109
- }
110
- } else {
111
- // Has title and looks like decision - treat as decision
112
- recordType = 'decision';
113
- }
114
- }
115
-
116
- // Pre-check conflicts for decisions
117
- if (recordType === 'decision' && input.code) {
118
- const conflicts = await engine.checkCodeConflicts(input.code);
119
- if (conflicts.hasConflicts) {
120
- const conflictWarnings = conflicts.conflicts.map(c => ({
121
- type: 'conflict' as const,
122
- message: `Conflicts with decision "${c.decisionTitle}": ${c.conflictDescription}`,
123
- severity: c.severity as 'low' | 'medium' | 'high',
124
- }));
125
- warnings = warnings ? [...warnings, ...conflictWarnings] : conflictWarnings;
126
- }
127
- }
128
-
129
- // Route to appropriate recording method
130
- switch (recordType) {
131
- case 'decision':
132
- return handleRecordDecision(engine, input, warnings);
133
-
134
- case 'pattern':
135
- return handleRecordPattern(engine, input);
136
-
137
- case 'example':
138
- return handleRecordPatternExample(engine, input);
139
-
140
- case 'feedback':
141
- return handleRecordFeedback(engine, input);
142
-
143
- case 'feature':
144
- return handleRecordFeature(engine, input);
145
-
146
- case 'critical':
147
- return handleRecordCritical(engine, input);
148
-
149
- default:
150
- return {
151
- success: false,
152
- type: recordType,
153
- message: `Unknown record type: ${recordType}`,
154
- };
155
- }
156
- }
157
-
158
- /**
159
- * Record a decision
160
- */
161
- async function handleRecordDecision(
162
- engine: MemoryLayerEngine,
163
- input: MemoryRecordInput,
164
- warnings?: MemoryRecordResponse['warnings']
165
- ): Promise<MemoryRecordResponse> {
166
- const title = input.title!;
167
- const description = input.content;
168
-
169
- let decision;
170
-
171
- if (input.author) {
172
- // Use author-attributed decision recording
173
- decision = await engine.recordDecisionWithAuthor(
174
- title,
175
- description,
176
- input.author,
177
- input.files,
178
- input.tags,
179
- input.status || 'accepted'
180
- );
181
- } else {
182
- // Use simple decision recording
183
- decision = await engine.recordDecision(
184
- title,
185
- description,
186
- input.files,
187
- input.tags
188
- );
189
- }
190
-
191
- return {
192
- success: true,
193
- type: 'decision',
194
- id: decision.id,
195
- message: `Decision recorded: "${title}"`,
196
- warnings,
197
- record: {
198
- id: decision.id,
199
- title: decision.title,
200
- description: decision.description,
201
- author: decision.author,
202
- status: decision.status,
203
- files: decision.files,
204
- tags: decision.tags,
205
- created_at: decision.createdAt.toISOString(),
206
- },
207
- };
208
- }
209
-
210
- /**
211
- * Record a pattern
212
- */
213
- async function handleRecordPattern(
214
- engine: MemoryLayerEngine,
215
- input: MemoryRecordInput
216
- ): Promise<MemoryRecordResponse> {
217
- const code = input.code!;
218
- const name = input.pattern_name || input.title!;
219
- const description = input.content || undefined;
220
- const category = input.category || undefined;
221
-
222
- const result = engine.learnPattern(code, name, description, category);
223
-
224
- return {
225
- success: result.success,
226
- type: 'pattern',
227
- id: result.patternId,
228
- message: result.message,
229
- };
230
- }
231
-
232
- /**
233
- * Add an example to a pattern
234
- */
235
- async function handleRecordPatternExample(
236
- engine: MemoryLayerEngine,
237
- input: MemoryRecordInput
238
- ): Promise<MemoryRecordResponse> {
239
- const patternId = input.pattern_id!;
240
- const code = input.code!;
241
- const explanation = input.explanation || input.content;
242
- const isAntiPattern = input.is_anti_pattern || false;
243
-
244
- const success = engine.addPatternExample(patternId, code, explanation, isAntiPattern);
245
-
246
- if (!success) {
247
- return {
248
- success: false,
249
- type: 'example',
250
- message: `Pattern not found: ${patternId}`,
251
- };
252
- }
253
-
254
- return {
255
- success: true,
256
- type: 'example',
257
- message: `${isAntiPattern ? 'Anti-pattern' : 'Example'} added to pattern ${patternId}`,
258
- record: {
259
- pattern_id: patternId,
260
- is_anti_pattern: isAntiPattern,
261
- },
262
- };
263
- }
264
-
265
- /**
266
- * Record feedback about context usefulness
267
- */
268
- async function handleRecordFeedback(
269
- engine: MemoryLayerEngine,
270
- input: MemoryRecordInput
271
- ): Promise<MemoryRecordResponse> {
272
- const query = input.query || input.content;
273
- const wasUseful = input.was_useful!;
274
-
275
- engine.markContextUsefulness(query, wasUseful);
276
-
277
- return {
278
- success: true,
279
- type: 'feedback',
280
- message: `Feedback recorded: context was ${wasUseful ? 'useful' : 'not useful'}`,
281
- record: {
282
- query,
283
- was_useful: wasUseful,
284
- },
285
- };
286
- }
287
-
288
- /**
289
- * Start tracking a feature context
290
- */
291
- async function handleRecordFeature(
292
- engine: MemoryLayerEngine,
293
- input: MemoryRecordInput
294
- ): Promise<MemoryRecordResponse> {
295
- const name = input.content;
296
-
297
- const context = engine.startFeatureContext(name);
298
-
299
- // Track initial files if provided
300
- if (input.files && input.files.length > 0) {
301
- for (const file of input.files) {
302
- engine.trackFileOpened(file);
303
- }
304
- }
305
-
306
- return {
307
- success: true,
308
- type: 'feature',
309
- id: context.id,
310
- message: `Now tracking feature: "${name}"`,
311
- record: {
312
- id: context.id,
313
- name: context.name,
314
- files: input.files || [],
315
- },
316
- };
317
- }
318
-
319
- /**
320
- * Mark content as critical (never compressed)
321
- */
322
- async function handleRecordCritical(
323
- engine: MemoryLayerEngine,
324
- input: MemoryRecordInput
325
- ): Promise<MemoryRecordResponse> {
326
- const content = input.content;
327
- const type = input.critical_type;
328
- const reason = input.reason;
329
-
330
- const critical = engine.markCritical(content, { type, reason });
331
-
332
- return {
333
- success: true,
334
- type: 'critical',
335
- id: critical.id,
336
- message: `Marked as critical: "${content.slice(0, 50)}${content.length > 50 ? '...' : ''}"`,
337
- record: {
338
- id: critical.id,
339
- type: critical.type,
340
- content: critical.content,
341
- reason: critical.reason,
342
- never_compress: critical.neverCompress,
343
- created_at: critical.createdAt.toISOString(),
344
- },
345
- };
346
- }