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,428 +0,0 @@
1
- import { existsSync, readFileSync, readdirSync, statSync } from 'fs';
2
- import { basename, dirname, join } from 'path';
3
- import type { Tier2Storage } from '../../storage/tier2.js';
4
- import type {
5
- ArchitectureDoc,
6
- ArchitectureLayer,
7
- DataFlowStep,
8
- ComponentReference,
9
- DependencyInfo
10
- } from '../../types/documentation.js';
11
-
12
- export class ArchitectureGenerator {
13
- private projectPath: string;
14
- private tier2: Tier2Storage;
15
-
16
- // Layer name mappings (NO-AI)
17
- private static LAYER_MAPPING: Record<string, string> = {
18
- 'server': 'API Layer',
19
- 'api': 'API Layer',
20
- 'routes': 'API Layer',
21
- 'controllers': 'API Layer',
22
- 'core': 'Business Logic',
23
- 'services': 'Business Logic',
24
- 'domain': 'Business Logic',
25
- 'storage': 'Data Layer',
26
- 'db': 'Data Layer',
27
- 'database': 'Data Layer',
28
- 'repositories': 'Data Layer',
29
- 'models': 'Data Layer',
30
- 'utils': 'Utilities',
31
- 'helpers': 'Utilities',
32
- 'lib': 'Utilities',
33
- 'types': 'Type Definitions',
34
- 'interfaces': 'Type Definitions',
35
- 'indexing': 'Indexing Layer',
36
- 'search': 'Indexing Layer',
37
- 'components': 'UI Components',
38
- 'views': 'UI Components',
39
- 'pages': 'UI Components',
40
- 'hooks': 'React Hooks',
41
- 'context': 'State Management',
42
- 'store': 'State Management',
43
- 'config': 'Configuration',
44
- 'cli': 'CLI Interface',
45
- 'commands': 'CLI Interface',
46
- 'test': 'Testing',
47
- 'tests': 'Testing',
48
- '__tests__': 'Testing',
49
- 'spec': 'Testing'
50
- };
51
-
52
- // Layer purpose descriptions
53
- private static LAYER_PURPOSES: Record<string, string> = {
54
- 'API Layer': 'Handles external requests and responses, routing, and protocol handling',
55
- 'Business Logic': 'Core application logic, domain rules, and orchestration',
56
- 'Data Layer': 'Data persistence, database access, and storage management',
57
- 'Utilities': 'Shared utility functions and helper modules',
58
- 'Type Definitions': 'TypeScript interfaces, types, and shared contracts',
59
- 'Indexing Layer': 'Content indexing, search, and retrieval functionality',
60
- 'UI Components': 'User interface components and presentation logic',
61
- 'React Hooks': 'Custom React hooks for state and side effects',
62
- 'State Management': 'Application state management and data flow',
63
- 'Configuration': 'Application configuration and environment setup',
64
- 'CLI Interface': 'Command-line interface and commands',
65
- 'Testing': 'Test files and testing utilities'
66
- };
67
-
68
- constructor(projectPath: string, tier2: Tier2Storage) {
69
- this.projectPath = projectPath;
70
- this.tier2 = tier2;
71
- }
72
-
73
- async generate(): Promise<ArchitectureDoc> {
74
- const layers = this.detectLayers();
75
- const keyComponents = this.extractKeyComponents(layers);
76
- const dataFlow = this.inferDataFlow(layers);
77
- const diagram = this.generateASCIIDiagram(layers, dataFlow);
78
- const dependencies = this.getProjectDependencies();
79
-
80
- return {
81
- name: basename(this.projectPath),
82
- description: this.inferDescription(layers, keyComponents),
83
- diagram,
84
- layers,
85
- dataFlow,
86
- keyComponents,
87
- dependencies,
88
- generatedAt: new Date()
89
- };
90
- }
91
-
92
- private detectLayers(): ArchitectureLayer[] {
93
- const layers: ArchitectureLayer[] = [];
94
- const layerMap = new Map<string, ArchitectureLayer>();
95
-
96
- // Find src directory or use project root
97
- const srcDir = existsSync(join(this.projectPath, 'src'))
98
- ? join(this.projectPath, 'src')
99
- : this.projectPath;
100
-
101
- // Scan top-level directories
102
- try {
103
- const entries = readdirSync(srcDir, { withFileTypes: true });
104
-
105
- for (const entry of entries) {
106
- if (!entry.isDirectory()) continue;
107
-
108
- const dirName = entry.name.toLowerCase();
109
- const layerName = ArchitectureGenerator.LAYER_MAPPING[dirName];
110
-
111
- if (layerName) {
112
- const dirPath = join(srcDir, entry.name);
113
- const relativePath = dirPath.replace(this.projectPath, '').replace(/^[/\\]/, '');
114
- const files = this.getFilesInDirectory(relativePath);
115
-
116
- if (files.length > 0) {
117
- // Group by layer name
118
- if (layerMap.has(layerName)) {
119
- const existing = layerMap.get(layerName)!;
120
- existing.files.push(...files);
121
- } else {
122
- layerMap.set(layerName, {
123
- name: layerName,
124
- directory: relativePath,
125
- files,
126
- purpose: ArchitectureGenerator.LAYER_PURPOSES[layerName] || ''
127
- });
128
- }
129
- }
130
- }
131
- }
132
- } catch {
133
- // Directory scan failed
134
- }
135
-
136
- // Sort layers by typical architecture order
137
- const layerOrder = [
138
- 'CLI Interface',
139
- 'API Layer',
140
- 'UI Components',
141
- 'React Hooks',
142
- 'State Management',
143
- 'Business Logic',
144
- 'Indexing Layer',
145
- 'Data Layer',
146
- 'Configuration',
147
- 'Type Definitions',
148
- 'Utilities',
149
- 'Testing'
150
- ];
151
-
152
- for (const layerName of layerOrder) {
153
- if (layerMap.has(layerName)) {
154
- layers.push(layerMap.get(layerName)!);
155
- }
156
- }
157
-
158
- return layers;
159
- }
160
-
161
- private getFilesInDirectory(relativePath: string): string[] {
162
- const files: string[] = [];
163
- const absolutePath = join(this.projectPath, relativePath);
164
-
165
- try {
166
- const entries = readdirSync(absolutePath, { withFileTypes: true });
167
-
168
- for (const entry of entries) {
169
- if (entry.isFile() && this.isCodeFile(entry.name)) {
170
- files.push(join(relativePath, entry.name));
171
- }
172
- }
173
- } catch {
174
- // Directory read failed
175
- }
176
-
177
- return files;
178
- }
179
-
180
- private isCodeFile(filename: string): boolean {
181
- const codeExtensions = ['.ts', '.js', '.tsx', '.jsx', '.py', '.go', '.rs', '.java'];
182
- return codeExtensions.some(ext => filename.endsWith(ext));
183
- }
184
-
185
- private extractKeyComponents(layers: ArchitectureLayer[]): ComponentReference[] {
186
- const components: ComponentReference[] = [];
187
-
188
- for (const layer of layers) {
189
- for (const filePath of layer.files.slice(0, 5)) { // Limit per layer
190
- const file = this.tier2.getFile(filePath);
191
- if (!file) continue;
192
-
193
- const symbols = this.tier2.getSymbolsByFile(file.id);
194
- const exports = symbols.filter(s => s.exported);
195
-
196
- if (exports.length > 0) {
197
- const mainExport = exports.find(s => s.kind === 'class') || exports[0];
198
-
199
- components.push({
200
- name: mainExport?.name || basename(filePath, '.ts'),
201
- file: filePath,
202
- purpose: this.inferComponentPurpose(filePath, symbols),
203
- exports: exports.map(s => s.name)
204
- });
205
- }
206
- }
207
- }
208
-
209
- return components;
210
- }
211
-
212
- private inferComponentPurpose(filePath: string, symbols: Array<{ name: string; kind: string }>): string {
213
- const name = basename(filePath, '.ts').toLowerCase();
214
- const mainExport = symbols.find(s => s.kind === 'class' || s.kind === 'function');
215
-
216
- if (name.includes('engine')) return 'Main orchestration engine';
217
- if (name.includes('server')) return 'Server implementation';
218
- if (name.includes('storage')) return 'Data storage management';
219
- if (name.includes('indexer')) return 'Content indexing';
220
- if (name.includes('context')) return 'Context management';
221
- if (name.includes('config')) return 'Configuration handling';
222
-
223
- if (mainExport) {
224
- return `Provides ${mainExport.name}`;
225
- }
226
-
227
- return 'Module';
228
- }
229
-
230
- private inferDataFlow(layers: ArchitectureLayer[]): DataFlowStep[] {
231
- const flow: DataFlowStep[] = [];
232
- const layerNames = layers.map(l => l.name);
233
-
234
- // Infer common data flows based on detected layers
235
- if (layerNames.includes('API Layer') && layerNames.includes('Business Logic')) {
236
- flow.push({
237
- from: 'API Layer',
238
- to: 'Business Logic',
239
- description: 'Request handling and routing'
240
- });
241
- }
242
-
243
- if (layerNames.includes('Business Logic') && layerNames.includes('Data Layer')) {
244
- flow.push({
245
- from: 'Business Logic',
246
- to: 'Data Layer',
247
- description: 'Data persistence and retrieval'
248
- });
249
- }
250
-
251
- if (layerNames.includes('Business Logic') && layerNames.includes('Indexing Layer')) {
252
- flow.push({
253
- from: 'Business Logic',
254
- to: 'Indexing Layer',
255
- description: 'Content indexing and search'
256
- });
257
- }
258
-
259
- if (layerNames.includes('CLI Interface') && layerNames.includes('Business Logic')) {
260
- flow.push({
261
- from: 'CLI Interface',
262
- to: 'Business Logic',
263
- description: 'Command execution'
264
- });
265
- }
266
-
267
- if (layerNames.includes('UI Components') && layerNames.includes('State Management')) {
268
- flow.push({
269
- from: 'UI Components',
270
- to: 'State Management',
271
- description: 'UI state updates'
272
- });
273
- }
274
-
275
- return flow;
276
- }
277
-
278
- private generateASCIIDiagram(layers: ArchitectureLayer[], dataFlow: DataFlowStep[]): string {
279
- const maxWidth = 45;
280
- const lines: string[] = [];
281
-
282
- // Header
283
- lines.push('┌' + '─'.repeat(maxWidth) + '┐');
284
- lines.push('│' + this.centerText('PROJECT ARCHITECTURE', maxWidth) + '│');
285
- lines.push('├' + '─'.repeat(maxWidth) + '┤');
286
-
287
- // Each layer
288
- for (let i = 0; i < layers.length; i++) {
289
- const layer = layers[i]!;
290
- const layerName = layer.name;
291
- const fileCount = `(${layer.files.length} files)`;
292
-
293
- // Layer name line
294
- lines.push('│ ' + layerName.padEnd(maxWidth - 4) + ' │');
295
-
296
- // Directory line
297
- lines.push('│ └── ' + layer.directory.padEnd(maxWidth - 8) + ' │');
298
-
299
- // Add connector if there's a next layer with data flow
300
- if (i < layers.length - 1) {
301
- const flowToNext = dataFlow.find(f =>
302
- f.from === layer.name && f.to === layers[i + 1]?.name
303
- );
304
-
305
- if (flowToNext) {
306
- lines.push('│' + this.centerText('│', maxWidth) + '│');
307
- lines.push('│' + this.centerText('▼', maxWidth) + '│');
308
- } else {
309
- lines.push('│' + ' '.repeat(maxWidth) + '│');
310
- }
311
- }
312
- }
313
-
314
- // Footer
315
- lines.push('└' + '─'.repeat(maxWidth) + '┘');
316
-
317
- // Add legend if there are data flows
318
- if (dataFlow.length > 0) {
319
- lines.push('');
320
- lines.push('Data Flow:');
321
- for (const flow of dataFlow) {
322
- lines.push(` ${flow.from} → ${flow.to}`);
323
- lines.push(` ${flow.description}`);
324
- }
325
- }
326
-
327
- return lines.join('\n');
328
- }
329
-
330
- private centerText(text: string, width: number): string {
331
- const padding = Math.max(0, width - text.length);
332
- const leftPad = Math.floor(padding / 2);
333
- const rightPad = padding - leftPad;
334
- return ' '.repeat(leftPad) + text + ' '.repeat(rightPad);
335
- }
336
-
337
- private getProjectDependencies(): DependencyInfo[] {
338
- const deps: DependencyInfo[] = [];
339
-
340
- // Check package.json
341
- const packageJsonPath = join(this.projectPath, 'package.json');
342
- if (existsSync(packageJsonPath)) {
343
- try {
344
- const pkg = JSON.parse(readFileSync(packageJsonPath, 'utf-8'));
345
-
346
- // Runtime dependencies
347
- if (pkg.dependencies) {
348
- for (const [name, version] of Object.entries(pkg.dependencies)) {
349
- deps.push({
350
- name,
351
- version: String(version),
352
- type: 'runtime'
353
- });
354
- }
355
- }
356
-
357
- // Dev dependencies (limit to important ones)
358
- if (pkg.devDependencies) {
359
- const importantDevDeps = ['typescript', 'vitest', 'jest', 'eslint', 'prettier', 'esbuild', 'webpack', 'vite'];
360
- for (const [name, version] of Object.entries(pkg.devDependencies)) {
361
- if (importantDevDeps.some(d => name.includes(d))) {
362
- deps.push({
363
- name,
364
- version: String(version),
365
- type: 'dev'
366
- });
367
- }
368
- }
369
- }
370
- } catch {
371
- // Parse error
372
- }
373
- }
374
-
375
- // Check requirements.txt for Python
376
- const requirementsPath = join(this.projectPath, 'requirements.txt');
377
- if (existsSync(requirementsPath)) {
378
- try {
379
- const content = readFileSync(requirementsPath, 'utf-8');
380
- const lines = content.split('\n').filter(l => l.trim() && !l.startsWith('#'));
381
-
382
- for (const line of lines.slice(0, 20)) {
383
- const match = line.match(/^([a-zA-Z0-9_-]+)(?:[=<>~!]+(.+))?/);
384
- if (match) {
385
- deps.push({
386
- name: match[1]!,
387
- version: match[2],
388
- type: 'runtime'
389
- });
390
- }
391
- }
392
- } catch {
393
- // Read error
394
- }
395
- }
396
-
397
- return deps;
398
- }
399
-
400
- private inferDescription(layers: ArchitectureLayer[], components: ComponentReference[]): string {
401
- const parts: string[] = [];
402
-
403
- // Describe the project type based on layers
404
- const layerNames = layers.map(l => l.name);
405
-
406
- if (layerNames.includes('API Layer') && layerNames.includes('Data Layer')) {
407
- parts.push('Backend application');
408
- } else if (layerNames.includes('UI Components')) {
409
- parts.push('Frontend application');
410
- } else if (layerNames.includes('CLI Interface')) {
411
- parts.push('CLI tool');
412
- }
413
-
414
- // Describe key capabilities
415
- if (layerNames.includes('Indexing Layer')) {
416
- parts.push('with search/indexing capabilities');
417
- }
418
- if (layerNames.includes('State Management')) {
419
- parts.push('with centralized state management');
420
- }
421
-
422
- // File count
423
- const totalFiles = layers.reduce((sum, l) => sum + l.files.length, 0);
424
- parts.push(`(${totalFiles} source files across ${layers.length} layers)`);
425
-
426
- return parts.join(' ');
427
- }
428
- }