@timmeck/brain 1.9.0 → 2.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 (253) hide show
  1. package/README.md +33 -0
  2. package/brain.log +3876 -0
  3. package/{src/cli/commands/dashboard.ts → dashboard.html} +694 -807
  4. package/dist/api/server.d.ts +4 -18
  5. package/dist/api/server.js +4 -173
  6. package/dist/api/server.js.map +1 -1
  7. package/dist/brain.d.ts +2 -0
  8. package/dist/brain.js +15 -4
  9. package/dist/brain.js.map +1 -1
  10. package/dist/cli/colors.d.ts +4 -25
  11. package/dist/cli/colors.js +3 -89
  12. package/dist/cli/colors.js.map +1 -1
  13. package/dist/cli/commands/dashboard.js +21 -2
  14. package/dist/cli/commands/dashboard.js.map +1 -1
  15. package/dist/cli/commands/peers.d.ts +2 -0
  16. package/dist/cli/commands/peers.js +38 -0
  17. package/dist/cli/commands/peers.js.map +1 -0
  18. package/dist/cli/commands/status.js +0 -1
  19. package/dist/cli/commands/status.js.map +1 -1
  20. package/dist/config.js +2 -29
  21. package/dist/config.js.map +1 -1
  22. package/dist/db/connection.d.ts +1 -2
  23. package/dist/db/connection.js +1 -18
  24. package/dist/db/connection.js.map +1 -1
  25. package/dist/index.js +3 -1
  26. package/dist/index.js.map +1 -1
  27. package/dist/ipc/__tests__/protocol.test.d.ts +1 -0
  28. package/dist/ipc/__tests__/protocol.test.js +117 -0
  29. package/dist/ipc/__tests__/protocol.test.js.map +1 -0
  30. package/dist/ipc/client.d.ts +1 -16
  31. package/dist/ipc/client.js +1 -100
  32. package/dist/ipc/client.js.map +1 -1
  33. package/dist/ipc/protocol.d.ts +1 -8
  34. package/dist/ipc/protocol.js +1 -28
  35. package/dist/ipc/protocol.js.map +1 -1
  36. package/dist/ipc/router.d.ts +2 -0
  37. package/dist/ipc/router.js +30 -0
  38. package/dist/ipc/router.js.map +1 -1
  39. package/dist/ipc/server.d.ts +1 -22
  40. package/dist/ipc/server.js +1 -163
  41. package/dist/ipc/server.js.map +1 -1
  42. package/dist/learning/confidence-scorer.d.ts +2 -5
  43. package/dist/learning/confidence-scorer.js +4 -19
  44. package/dist/learning/confidence-scorer.js.map +1 -1
  45. package/dist/learning/decay.js +2 -3
  46. package/dist/learning/decay.js.map +1 -1
  47. package/dist/learning/learning-engine.d.ts +2 -5
  48. package/dist/learning/learning-engine.js +3 -15
  49. package/dist/learning/learning-engine.js.map +1 -1
  50. package/dist/mcp/http-server.d.ts +1 -7
  51. package/dist/mcp/http-server.js +6 -117
  52. package/dist/mcp/http-server.js.map +1 -1
  53. package/dist/mcp/server.js +5 -61
  54. package/dist/mcp/server.js.map +1 -1
  55. package/dist/mcp/tools.js +36 -0
  56. package/dist/mcp/tools.js.map +1 -1
  57. package/dist/parsing/parsers/compiler.js +1 -1
  58. package/dist/parsing/parsers/compiler.js.map +1 -1
  59. package/dist/research/research-engine.d.ts +2 -6
  60. package/dist/research/research-engine.js +3 -23
  61. package/dist/research/research-engine.js.map +1 -1
  62. package/dist/services/synapse.service.d.ts +3 -3
  63. package/dist/signals/__tests__/fingerprint.test.d.ts +1 -0
  64. package/dist/signals/__tests__/fingerprint.test.js +118 -0
  65. package/dist/signals/__tests__/fingerprint.test.js.map +1 -0
  66. package/dist/synapses/activation.d.ts +3 -13
  67. package/dist/synapses/activation.js +2 -49
  68. package/dist/synapses/activation.js.map +1 -1
  69. package/dist/synapses/decay.d.ts +2 -11
  70. package/dist/synapses/decay.js +2 -26
  71. package/dist/synapses/decay.js.map +1 -1
  72. package/dist/synapses/hebbian.d.ts +2 -13
  73. package/dist/synapses/hebbian.js +2 -35
  74. package/dist/synapses/hebbian.js.map +1 -1
  75. package/dist/synapses/pathfinder.d.ts +2 -14
  76. package/dist/synapses/pathfinder.js +2 -49
  77. package/dist/synapses/pathfinder.js.map +1 -1
  78. package/dist/synapses/synapse-manager.d.ts +7 -23
  79. package/dist/synapses/synapse-manager.js +6 -63
  80. package/dist/synapses/synapse-manager.js.map +1 -1
  81. package/dist/types/ipc.types.d.ts +1 -11
  82. package/dist/utils/__tests__/hash.test.d.ts +1 -0
  83. package/dist/utils/__tests__/hash.test.js +32 -0
  84. package/dist/utils/__tests__/hash.test.js.map +1 -0
  85. package/dist/utils/__tests__/paths.test.d.ts +1 -0
  86. package/dist/utils/__tests__/paths.test.js +75 -0
  87. package/dist/utils/__tests__/paths.test.js.map +1 -0
  88. package/dist/utils/events.d.ts +4 -8
  89. package/dist/utils/events.js +2 -14
  90. package/dist/utils/events.js.map +1 -1
  91. package/dist/utils/hash.d.ts +1 -1
  92. package/dist/utils/hash.js +1 -4
  93. package/dist/utils/hash.js.map +1 -1
  94. package/dist/utils/logger.d.ts +3 -2
  95. package/dist/utils/logger.js +8 -35
  96. package/dist/utils/logger.js.map +1 -1
  97. package/dist/utils/paths.d.ts +2 -1
  98. package/dist/utils/paths.js +4 -13
  99. package/dist/utils/paths.js.map +1 -1
  100. package/eslint.config.js +14 -0
  101. package/package.json +56 -49
  102. package/BRAIN_PLAN.md +0 -3324
  103. package/reddit_post.md +0 -45
  104. package/src/api/server.ts +0 -395
  105. package/src/brain.ts +0 -313
  106. package/src/cli/colors.ts +0 -116
  107. package/src/cli/commands/config.ts +0 -169
  108. package/src/cli/commands/doctor.ts +0 -124
  109. package/src/cli/commands/explain.ts +0 -83
  110. package/src/cli/commands/export.ts +0 -31
  111. package/src/cli/commands/import.ts +0 -199
  112. package/src/cli/commands/insights.ts +0 -65
  113. package/src/cli/commands/learn.ts +0 -24
  114. package/src/cli/commands/modules.ts +0 -53
  115. package/src/cli/commands/network.ts +0 -67
  116. package/src/cli/commands/projects.ts +0 -42
  117. package/src/cli/commands/query.ts +0 -120
  118. package/src/cli/commands/start.ts +0 -105
  119. package/src/cli/commands/status.ts +0 -75
  120. package/src/cli/commands/stop.ts +0 -34
  121. package/src/cli/ipc-helper.ts +0 -22
  122. package/src/cli/update-check.ts +0 -63
  123. package/src/code/analyzer.ts +0 -117
  124. package/src/code/fingerprint.ts +0 -87
  125. package/src/code/matcher.ts +0 -129
  126. package/src/code/parsers/generic.ts +0 -29
  127. package/src/code/parsers/python.ts +0 -54
  128. package/src/code/parsers/typescript.ts +0 -65
  129. package/src/code/registry.ts +0 -60
  130. package/src/code/scorer.ts +0 -120
  131. package/src/config.ts +0 -135
  132. package/src/dashboard/server.ts +0 -142
  133. package/src/db/connection.ts +0 -22
  134. package/src/db/migrations/001_core_schema.ts +0 -120
  135. package/src/db/migrations/002_learning_schema.ts +0 -38
  136. package/src/db/migrations/003_code_schema.ts +0 -53
  137. package/src/db/migrations/004_synapses_schema.ts +0 -57
  138. package/src/db/migrations/005_fts_indexes.ts +0 -78
  139. package/src/db/migrations/006_synapses_phase3.ts +0 -17
  140. package/src/db/migrations/007_feedback.ts +0 -13
  141. package/src/db/migrations/008_git_integration.ts +0 -38
  142. package/src/db/migrations/009_embeddings.ts +0 -8
  143. package/src/db/migrations/index.ts +0 -70
  144. package/src/db/repositories/antipattern.repository.ts +0 -66
  145. package/src/db/repositories/code-module.repository.ts +0 -142
  146. package/src/db/repositories/error.repository.ts +0 -189
  147. package/src/db/repositories/insight.repository.ts +0 -99
  148. package/src/db/repositories/notification.repository.ts +0 -66
  149. package/src/db/repositories/project.repository.ts +0 -93
  150. package/src/db/repositories/rule.repository.ts +0 -108
  151. package/src/db/repositories/solution.repository.ts +0 -154
  152. package/src/db/repositories/synapse.repository.ts +0 -163
  153. package/src/db/repositories/terminal.repository.ts +0 -101
  154. package/src/embeddings/engine.ts +0 -238
  155. package/src/hooks/post-tool-use.ts +0 -92
  156. package/src/hooks/post-write.ts +0 -129
  157. package/src/index.ts +0 -63
  158. package/src/ipc/client.ts +0 -118
  159. package/src/ipc/protocol.ts +0 -35
  160. package/src/ipc/router.ts +0 -133
  161. package/src/ipc/server.ts +0 -176
  162. package/src/learning/confidence-scorer.ts +0 -80
  163. package/src/learning/decay.ts +0 -46
  164. package/src/learning/learning-engine.ts +0 -170
  165. package/src/learning/pattern-extractor.ts +0 -90
  166. package/src/learning/rule-generator.ts +0 -74
  167. package/src/main.rs:10:5 +0 -0
  168. package/src/matching/error-matcher.ts +0 -166
  169. package/src/matching/fingerprint.ts +0 -34
  170. package/src/matching/similarity.ts +0 -61
  171. package/src/matching/tfidf.ts +0 -74
  172. package/src/matching/tokenizer.ts +0 -41
  173. package/src/mcp/auto-detect.ts +0 -93
  174. package/src/mcp/http-server.ts +0 -140
  175. package/src/mcp/server.ts +0 -73
  176. package/src/mcp/tools.ts +0 -328
  177. package/src/parsing/error-parser.ts +0 -28
  178. package/src/parsing/parsers/compiler.ts +0 -93
  179. package/src/parsing/parsers/generic.ts +0 -28
  180. package/src/parsing/parsers/go.ts +0 -97
  181. package/src/parsing/parsers/node.ts +0 -69
  182. package/src/parsing/parsers/python.ts +0 -62
  183. package/src/parsing/parsers/rust.ts +0 -50
  184. package/src/parsing/parsers/shell.ts +0 -42
  185. package/src/parsing/types.ts +0 -47
  186. package/src/research/gap-analyzer.ts +0 -135
  187. package/src/research/insight-generator.ts +0 -123
  188. package/src/research/research-engine.ts +0 -116
  189. package/src/research/synergy-detector.ts +0 -126
  190. package/src/research/template-extractor.ts +0 -130
  191. package/src/research/trend-analyzer.ts +0 -127
  192. package/src/services/analytics.service.ts +0 -226
  193. package/src/services/code.service.ts +0 -271
  194. package/src/services/error.service.ts +0 -266
  195. package/src/services/git.service.ts +0 -132
  196. package/src/services/notification.service.ts +0 -41
  197. package/src/services/prevention.service.ts +0 -159
  198. package/src/services/research.service.ts +0 -98
  199. package/src/services/solution.service.ts +0 -174
  200. package/src/services/synapse.service.ts +0 -59
  201. package/src/services/terminal.service.ts +0 -81
  202. package/src/synapses/activation.ts +0 -80
  203. package/src/synapses/decay.ts +0 -38
  204. package/src/synapses/hebbian.ts +0 -69
  205. package/src/synapses/pathfinder.ts +0 -81
  206. package/src/synapses/synapse-manager.ts +0 -113
  207. package/src/types/code.types.ts +0 -52
  208. package/src/types/config.types.ts +0 -103
  209. package/src/types/error.types.ts +0 -67
  210. package/src/types/ipc.types.ts +0 -8
  211. package/src/types/mcp.types.ts +0 -53
  212. package/src/types/research.types.ts +0 -28
  213. package/src/types/solution.types.ts +0 -30
  214. package/src/types/synapse.types.ts +0 -50
  215. package/src/utils/events.ts +0 -45
  216. package/src/utils/hash.ts +0 -5
  217. package/src/utils/logger.ts +0 -48
  218. package/src/utils/paths.ts +0 -19
  219. package/tests/e2e/test_code_intelligence.py +0 -1015
  220. package/tests/e2e/test_error_memory.py +0 -451
  221. package/tests/e2e/test_full_integration.py +0 -534
  222. package/tests/fixtures/code-modules/modules.ts +0 -83
  223. package/tests/fixtures/errors/go.ts +0 -9
  224. package/tests/fixtures/errors/node.ts +0 -24
  225. package/tests/fixtures/errors/python.ts +0 -21
  226. package/tests/fixtures/errors/rust.ts +0 -25
  227. package/tests/fixtures/errors/shell.ts +0 -15
  228. package/tests/fixtures/solutions/solutions.ts +0 -27
  229. package/tests/helpers/setup-db.ts +0 -52
  230. package/tests/integration/code-flow.test.ts +0 -86
  231. package/tests/integration/error-flow.test.ts +0 -83
  232. package/tests/integration/ipc-flow.test.ts +0 -166
  233. package/tests/integration/learning-cycle.test.ts +0 -82
  234. package/tests/integration/synapse-flow.test.ts +0 -117
  235. package/tests/unit/code/analyzer.test.ts +0 -58
  236. package/tests/unit/code/fingerprint.test.ts +0 -51
  237. package/tests/unit/code/scorer.test.ts +0 -55
  238. package/tests/unit/learning/confidence-scorer.test.ts +0 -60
  239. package/tests/unit/learning/decay.test.ts +0 -45
  240. package/tests/unit/learning/pattern-extractor.test.ts +0 -50
  241. package/tests/unit/matching/error-matcher.test.ts +0 -69
  242. package/tests/unit/matching/fingerprint.test.ts +0 -47
  243. package/tests/unit/matching/similarity.test.ts +0 -65
  244. package/tests/unit/matching/tfidf.test.ts +0 -71
  245. package/tests/unit/matching/tokenizer.test.ts +0 -83
  246. package/tests/unit/parsing/parsers.test.ts +0 -113
  247. package/tests/unit/research/gap-analyzer.test.ts +0 -45
  248. package/tests/unit/research/trend-analyzer.test.ts +0 -45
  249. package/tests/unit/synapses/activation.test.ts +0 -80
  250. package/tests/unit/synapses/decay.test.ts +0 -27
  251. package/tests/unit/synapses/hebbian.test.ts +0 -96
  252. package/tests/unit/synapses/pathfinder.test.ts +0 -72
  253. package/tsconfig.json +0 -18
@@ -1,66 +0,0 @@
1
- import type Database from 'better-sqlite3';
2
- import type { Statement } from 'better-sqlite3';
3
-
4
- export interface AntipatternRecord {
5
- id: number;
6
- pattern: string;
7
- description: string;
8
- severity: string;
9
- suggestion: string | null;
10
- occurrences: number;
11
- project_id: number | null;
12
- global: number;
13
- created_at: string;
14
- }
15
-
16
- type AntipatternCreate = Omit<AntipatternRecord, 'id' | 'created_at'>;
17
- type AntipatternUpdate = Partial<Omit<AntipatternRecord, 'id' | 'created_at'>>;
18
-
19
- export class AntipatternRepository {
20
- private stmts: Record<string, Statement>;
21
-
22
- constructor(private db: Database.Database) {
23
- this.stmts = {
24
- create: db.prepare(`
25
- INSERT INTO antipatterns (pattern, description, severity, suggestion, occurrences, project_id, global)
26
- VALUES (@pattern, @description, @severity, @suggestion, @occurrences, @project_id, @global)
27
- `),
28
- getById: db.prepare('SELECT * FROM antipatterns WHERE id = ?'),
29
- delete: db.prepare('DELETE FROM antipatterns WHERE id = ?'),
30
- findByProject: db.prepare('SELECT * FROM antipatterns WHERE project_id = ? ORDER BY occurrences DESC'),
31
- findGlobal: db.prepare('SELECT * FROM antipatterns WHERE global = 1 ORDER BY occurrences DESC'),
32
- };
33
- }
34
-
35
- create(data: AntipatternCreate): number {
36
- const result = this.stmts.create.run(data);
37
- return result.lastInsertRowid as number;
38
- }
39
-
40
- getById(id: number): AntipatternRecord | undefined {
41
- return this.stmts.getById.get(id) as AntipatternRecord | undefined;
42
- }
43
-
44
- update(id: number, data: AntipatternUpdate): boolean {
45
- const fields = Object.keys(data).filter((key) => (data as Record<string, unknown>)[key] !== undefined);
46
- if (fields.length === 0) return false;
47
-
48
- const setClauses = fields.map((field) => `${field} = @${field}`).join(', ');
49
- const stmt = this.db.prepare(`UPDATE antipatterns SET ${setClauses} WHERE id = @id`);
50
- const result = stmt.run({ ...data, id });
51
- return result.changes > 0;
52
- }
53
-
54
- delete(id: number): boolean {
55
- const result = this.stmts.delete.run(id);
56
- return result.changes > 0;
57
- }
58
-
59
- findByProject(projectId: number): AntipatternRecord[] {
60
- return this.stmts.findByProject.all(projectId) as AntipatternRecord[];
61
- }
62
-
63
- findGlobal(): AntipatternRecord[] {
64
- return this.stmts.findGlobal.all() as AntipatternRecord[];
65
- }
66
- }
@@ -1,142 +0,0 @@
1
- import type Database from 'better-sqlite3';
2
- import type { Statement } from 'better-sqlite3';
3
- import type { CodeModuleRecord } from '../../types/code.types.js';
4
-
5
- type CodeModuleCreate = Omit<CodeModuleRecord, 'id' | 'created_at' | 'updated_at'>;
6
- type CodeModuleUpdate = Partial<Omit<CodeModuleRecord, 'id' | 'created_at'>>;
7
-
8
- export class CodeModuleRepository {
9
- private stmts: Record<string, Statement>;
10
-
11
- constructor(private db: Database.Database) {
12
- this.stmts = {
13
- create: db.prepare(`
14
- INSERT INTO code_modules (project_id, name, file_path, language, fingerprint, description, source_hash, lines_of_code, complexity, reusability_score)
15
- VALUES (@project_id, @name, @file_path, @language, @fingerprint, @description, @source_hash, @lines_of_code, @complexity, @reusability_score)
16
- `),
17
- getById: db.prepare('SELECT * FROM code_modules WHERE id = ?'),
18
- delete: db.prepare('DELETE FROM code_modules WHERE id = ?'),
19
- findByFingerprint: db.prepare('SELECT * FROM code_modules WHERE fingerprint = ?'),
20
- findByProject: db.prepare('SELECT * FROM code_modules WHERE project_id = ? ORDER BY name ASC'),
21
- findAll: db.prepare('SELECT * FROM code_modules ORDER BY name ASC'),
22
- countAll: db.prepare('SELECT COUNT(*) as count FROM code_modules'),
23
- search: db.prepare(`
24
- SELECT cm.* FROM code_modules cm
25
- JOIN code_modules_fts fts ON cm.id = fts.rowid
26
- WHERE code_modules_fts MATCH ?
27
- ORDER BY rank
28
- `),
29
- upsertSimilarity: db.prepare(`
30
- INSERT INTO module_similarities (module_a_id, module_b_id, similarity_score)
31
- VALUES (@module_a_id, @module_b_id, @similarity_score)
32
- ON CONFLICT(module_a_id, module_b_id)
33
- DO UPDATE SET similarity_score = @similarity_score, computed_at = datetime('now')
34
- `),
35
- findSimilarModules: db.prepare(`
36
- SELECT ms.*, cm.name, cm.file_path, cm.language, cm.reusability_score
37
- FROM module_similarities ms
38
- JOIN code_modules cm ON (
39
- CASE WHEN ms.module_a_id = ? THEN ms.module_b_id ELSE ms.module_a_id END
40
- ) = cm.id
41
- WHERE ms.module_a_id = ? OR ms.module_b_id = ?
42
- ORDER BY ms.similarity_score DESC
43
- LIMIT ?
44
- `),
45
- findHighSimilarityPairs: db.prepare(`
46
- SELECT ms.*,
47
- a.name as a_name, a.file_path as a_path,
48
- b.name as b_name, b.file_path as b_path
49
- FROM module_similarities ms
50
- JOIN code_modules a ON ms.module_a_id = a.id
51
- JOIN code_modules b ON ms.module_b_id = b.id
52
- WHERE ms.similarity_score >= ?
53
- ORDER BY ms.similarity_score DESC
54
- LIMIT ?
55
- `),
56
- };
57
- }
58
-
59
- create(data: CodeModuleCreate): number {
60
- const result = this.stmts.create.run(data);
61
- return result.lastInsertRowid as number;
62
- }
63
-
64
- getById(id: number): CodeModuleRecord | undefined {
65
- return this.stmts.getById.get(id) as CodeModuleRecord | undefined;
66
- }
67
-
68
- update(id: number, data: CodeModuleUpdate): boolean {
69
- const fields = Object.keys(data).filter((key) => (data as Record<string, unknown>)[key] !== undefined);
70
- if (fields.length === 0) return false;
71
-
72
- const setClauses = fields.map((field) => `${field} = @${field}`).join(', ');
73
- const stmt = this.db.prepare(
74
- `UPDATE code_modules SET ${setClauses}, updated_at = datetime('now') WHERE id = @id`
75
- );
76
- const result = stmt.run({ ...data, id });
77
- return result.changes > 0;
78
- }
79
-
80
- delete(id: number): boolean {
81
- const result = this.stmts.delete.run(id);
82
- return result.changes > 0;
83
- }
84
-
85
- findByFingerprint(fingerprint: string): CodeModuleRecord | undefined {
86
- return this.stmts.findByFingerprint.get(fingerprint) as CodeModuleRecord | undefined;
87
- }
88
-
89
- findByLanguage(language: string, limit?: number): CodeModuleRecord[] {
90
- const sql = limit
91
- ? 'SELECT * FROM code_modules WHERE language = ? ORDER BY name ASC LIMIT ?'
92
- : 'SELECT * FROM code_modules WHERE language = ? ORDER BY name ASC';
93
- const stmt = this.db.prepare(sql);
94
- return (limit ? stmt.all(language, limit) : stmt.all(language)) as CodeModuleRecord[];
95
- }
96
-
97
- findByProject(projectId: number): CodeModuleRecord[] {
98
- return this.stmts.findByProject.all(projectId) as CodeModuleRecord[];
99
- }
100
-
101
- search(query: string): CodeModuleRecord[] {
102
- return this.stmts.search.all(query) as CodeModuleRecord[];
103
- }
104
-
105
- findAll(limit?: number): CodeModuleRecord[] {
106
- if (limit) {
107
- const stmt = this.db.prepare('SELECT * FROM code_modules ORDER BY name ASC LIMIT ?');
108
- return stmt.all(limit) as CodeModuleRecord[];
109
- }
110
- return this.stmts.findAll.all() as CodeModuleRecord[];
111
- }
112
-
113
- countAll(): number {
114
- return (this.stmts.countAll.get() as { count: number }).count;
115
- }
116
-
117
- upsertSimilarity(moduleAId: number, moduleBId: number, score: number): void {
118
- // Always store with smaller id first for consistency
119
- const [a, b] = moduleAId < moduleBId ? [moduleAId, moduleBId] : [moduleBId, moduleAId];
120
- this.stmts.upsertSimilarity.run({
121
- module_a_id: a,
122
- module_b_id: b,
123
- similarity_score: score,
124
- });
125
- }
126
-
127
- findSimilarModules(moduleId: number, limit: number = 10): Array<{ module_id: number; similarity_score: number; name: string; file_path: string }> {
128
- return this.stmts.findSimilarModules.all(moduleId, moduleId, moduleId, limit) as Array<{
129
- module_id: number; similarity_score: number; name: string; file_path: string;
130
- }>;
131
- }
132
-
133
- findHighSimilarityPairs(minScore: number = 0.75, limit: number = 50): Array<{
134
- module_a_id: number; module_b_id: number; similarity_score: number;
135
- a_name: string; a_path: string; b_name: string; b_path: string;
136
- }> {
137
- return this.stmts.findHighSimilarityPairs.all(minScore, limit) as Array<{
138
- module_a_id: number; module_b_id: number; similarity_score: number;
139
- a_name: string; a_path: string; b_name: string; b_path: string;
140
- }>;
141
- }
142
- }
@@ -1,189 +0,0 @@
1
- import type Database from 'better-sqlite3';
2
- import type { Statement } from 'better-sqlite3';
3
- import type { ErrorRecord } from '../../types/error.types.js';
4
-
5
- type CreateErrorData = Omit<ErrorRecord, 'id' | 'occurrence_count' | 'first_seen' | 'last_seen' | 'resolved' | 'resolved_at'>;
6
- type UpdateErrorData = Partial<Omit<ErrorRecord, 'id' | 'first_seen'>>;
7
-
8
- export class ErrorRepository {
9
- private stmts: Record<string, Statement>;
10
-
11
- constructor(private db: Database.Database) {
12
- this.stmts = {
13
- create: this.db.prepare(`
14
- INSERT INTO errors (project_id, terminal_id, fingerprint, type, message, raw_output, context, file_path, line_number, column_number)
15
- VALUES (@project_id, @terminal_id, @fingerprint, @type, @message, @raw_output, @context, @file_path, @line_number, @column_number)
16
- `),
17
- createChain: this.db.prepare(`
18
- INSERT OR IGNORE INTO error_chains (parent_error_id, child_error_id, relationship)
19
- VALUES (@parent_error_id, @child_error_id, @relationship)
20
- `),
21
- findChainChildren: this.db.prepare(
22
- 'SELECT e.* FROM errors e JOIN error_chains ec ON e.id = ec.child_error_id WHERE ec.parent_error_id = ?'
23
- ),
24
- findChainParents: this.db.prepare(
25
- 'SELECT e.* FROM errors e JOIN error_chains ec ON e.id = ec.parent_error_id WHERE ec.child_error_id = ?'
26
- ),
27
- findRecentByProject: this.db.prepare(
28
- 'SELECT * FROM errors WHERE project_id = ? AND first_seen >= ? ORDER BY first_seen DESC LIMIT ?'
29
- ),
30
- findAllPaginated: this.db.prepare(
31
- 'SELECT * FROM errors ORDER BY last_seen DESC LIMIT ? OFFSET ?'
32
- ),
33
- getById: this.db.prepare(`
34
- SELECT * FROM errors WHERE id = ?
35
- `),
36
- update: this.db.prepare(`
37
- UPDATE errors
38
- SET project_id = COALESCE(@project_id, project_id),
39
- terminal_id = COALESCE(@terminal_id, terminal_id),
40
- fingerprint = COALESCE(@fingerprint, fingerprint),
41
- type = COALESCE(@type, type),
42
- message = COALESCE(@message, message),
43
- raw_output = COALESCE(@raw_output, raw_output),
44
- context = COALESCE(@context, context),
45
- file_path = COALESCE(@file_path, file_path),
46
- line_number = COALESCE(@line_number, line_number),
47
- column_number = COALESCE(@column_number, column_number),
48
- occurrence_count = COALESCE(@occurrence_count, occurrence_count),
49
- last_seen = COALESCE(@last_seen, last_seen),
50
- resolved = COALESCE(@resolved, resolved),
51
- resolved_at = COALESCE(@resolved_at, resolved_at)
52
- WHERE id = @id
53
- `),
54
- delete: this.db.prepare(`
55
- DELETE FROM errors WHERE id = ?
56
- `),
57
- findByFingerprint: this.db.prepare(`
58
- SELECT * FROM errors WHERE fingerprint = ? ORDER BY last_seen DESC
59
- `),
60
- findByProject: this.db.prepare(`
61
- SELECT * FROM errors WHERE project_id = ? ORDER BY last_seen DESC
62
- `),
63
- findUnresolvedAll: this.db.prepare(`
64
- SELECT * FROM errors WHERE resolved = 0 ORDER BY last_seen DESC
65
- `),
66
- findUnresolvedByProject: this.db.prepare(`
67
- SELECT * FROM errors WHERE resolved = 0 AND project_id = ? ORDER BY last_seen DESC
68
- `),
69
- countSinceAll: this.db.prepare(`
70
- SELECT COUNT(*) as count FROM errors WHERE first_seen >= ?
71
- `),
72
- countSinceByProject: this.db.prepare(`
73
- SELECT COUNT(*) as count FROM errors WHERE first_seen >= ? AND project_id = ?
74
- `),
75
- search: this.db.prepare(`
76
- SELECT errors.* FROM errors
77
- JOIN errors_fts ON errors.id = errors_fts.rowid
78
- WHERE errors_fts MATCH ?
79
- ORDER BY rank
80
- `),
81
- incrementOccurrence: this.db.prepare(`
82
- UPDATE errors
83
- SET occurrence_count = occurrence_count + 1,
84
- last_seen = datetime('now')
85
- WHERE id = ?
86
- `),
87
- };
88
- }
89
-
90
- create(data: CreateErrorData): number {
91
- const result = this.stmts.create.run({
92
- project_id: data.project_id,
93
- terminal_id: data.terminal_id ?? null,
94
- fingerprint: data.fingerprint,
95
- type: data.type,
96
- message: data.message,
97
- raw_output: data.raw_output,
98
- context: data.context ?? null,
99
- file_path: data.file_path ?? null,
100
- line_number: data.line_number ?? null,
101
- column_number: data.column_number ?? null,
102
- });
103
- return result.lastInsertRowid as number;
104
- }
105
-
106
- getById(id: number): ErrorRecord | undefined {
107
- return this.stmts.getById.get(id) as ErrorRecord | undefined;
108
- }
109
-
110
- update(id: number, data: UpdateErrorData): void {
111
- this.stmts.update.run({
112
- id,
113
- project_id: data.project_id ?? null,
114
- terminal_id: data.terminal_id ?? null,
115
- fingerprint: data.fingerprint ?? null,
116
- type: data.type ?? null,
117
- message: data.message ?? null,
118
- raw_output: data.raw_output ?? null,
119
- context: data.context ?? null,
120
- file_path: data.file_path ?? null,
121
- line_number: data.line_number ?? null,
122
- column_number: data.column_number ?? null,
123
- occurrence_count: data.occurrence_count ?? null,
124
- last_seen: data.last_seen ?? null,
125
- resolved: data.resolved ?? null,
126
- resolved_at: data.resolved_at ?? null,
127
- });
128
- }
129
-
130
- delete(id: number): void {
131
- this.stmts.delete.run(id);
132
- }
133
-
134
- findByFingerprint(fingerprint: string): ErrorRecord[] {
135
- return this.stmts.findByFingerprint.all(fingerprint) as ErrorRecord[];
136
- }
137
-
138
- findByProject(projectId: number): ErrorRecord[] {
139
- return this.stmts.findByProject.all(projectId) as ErrorRecord[];
140
- }
141
-
142
- findUnresolved(projectId?: number): ErrorRecord[] {
143
- if (projectId !== undefined) {
144
- return this.stmts.findUnresolvedByProject.all(projectId) as ErrorRecord[];
145
- }
146
- return this.stmts.findUnresolvedAll.all() as ErrorRecord[];
147
- }
148
-
149
- countSince(since: string, projectId?: number): number {
150
- if (projectId !== undefined) {
151
- const row = this.stmts.countSinceByProject.get(since, projectId) as { count: number };
152
- return row.count;
153
- }
154
- const row = this.stmts.countSinceAll.get(since) as { count: number };
155
- return row.count;
156
- }
157
-
158
- search(query: string): ErrorRecord[] {
159
- return this.stmts.search.all(query) as ErrorRecord[];
160
- }
161
-
162
- incrementOccurrence(id: number): void {
163
- this.stmts.incrementOccurrence.run(id);
164
- }
165
-
166
- createChain(parentErrorId: number, childErrorId: number, relationship: string = 'caused_by_fix'): void {
167
- this.stmts.createChain.run({
168
- parent_error_id: parentErrorId,
169
- child_error_id: childErrorId,
170
- relationship,
171
- });
172
- }
173
-
174
- findChainChildren(errorId: number): ErrorRecord[] {
175
- return this.stmts.findChainChildren.all(errorId) as ErrorRecord[];
176
- }
177
-
178
- findChainParents(errorId: number): ErrorRecord[] {
179
- return this.stmts.findChainParents.all(errorId) as ErrorRecord[];
180
- }
181
-
182
- findRecentByProject(projectId: number, since: string, limit: number = 10): ErrorRecord[] {
183
- return this.stmts.findRecentByProject.all(projectId, since, limit) as ErrorRecord[];
184
- }
185
-
186
- findAll(limit: number = 100, offset: number = 0): ErrorRecord[] {
187
- return this.stmts.findAllPaginated.all(limit, offset) as ErrorRecord[];
188
- }
189
- }
@@ -1,99 +0,0 @@
1
- import type Database from 'better-sqlite3';
2
- import type { Statement } from 'better-sqlite3';
3
- import type { InsightRecord } from '../../types/research.types.js';
4
-
5
- type InsightCreate = Omit<InsightRecord, 'id' | 'created_at'>;
6
- type InsightUpdate = Partial<Omit<InsightRecord, 'id' | 'created_at'>>;
7
-
8
- export class InsightRepository {
9
- private stmts: Record<string, Statement>;
10
-
11
- constructor(private db: Database.Database) {
12
- this.stmts = {
13
- create: db.prepare(`
14
- INSERT INTO insights (type, title, description, evidence, priority, project_id, active, expires_at)
15
- VALUES (@type, @title, @description, @evidence, @priority, @project_id, @active, @expires_at)
16
- `),
17
- getById: db.prepare('SELECT * FROM insights WHERE id = ?'),
18
- delete: db.prepare('DELETE FROM insights WHERE id = ?'),
19
- findActiveAll: db.prepare(
20
- 'SELECT * FROM insights WHERE active = 1 ORDER BY priority DESC, created_at DESC'
21
- ),
22
- findActiveByProject: db.prepare(
23
- 'SELECT * FROM insights WHERE active = 1 AND project_id = ? ORDER BY priority DESC, created_at DESC'
24
- ),
25
- findByType: db.prepare('SELECT * FROM insights WHERE type = ? ORDER BY priority DESC'),
26
- findByPriority: db.prepare(
27
- 'SELECT * FROM insights WHERE priority >= ? ORDER BY priority DESC, created_at DESC'
28
- ),
29
- expire: db.prepare(
30
- `UPDATE insights SET active = 0 WHERE active = 1 AND expires_at IS NOT NULL AND expires_at < datetime('now')`
31
- ),
32
- };
33
- }
34
-
35
- create(data: InsightCreate): number {
36
- const result = this.stmts.create.run(data);
37
- return result.lastInsertRowid as number;
38
- }
39
-
40
- getById(id: number): InsightRecord | undefined {
41
- return this.stmts.getById.get(id) as InsightRecord | undefined;
42
- }
43
-
44
- update(id: number, data: InsightUpdate): boolean {
45
- const fields = Object.keys(data).filter((key) => (data as Record<string, unknown>)[key] !== undefined);
46
- if (fields.length === 0) return false;
47
-
48
- const setClauses = fields.map((field) => `${field} = @${field}`).join(', ');
49
- const stmt = this.db.prepare(`UPDATE insights SET ${setClauses} WHERE id = @id`);
50
- const result = stmt.run({ ...data, id });
51
- return result.changes > 0;
52
- }
53
-
54
- delete(id: number): boolean {
55
- const result = this.stmts.delete.run(id);
56
- return result.changes > 0;
57
- }
58
-
59
- findActive(projectId?: number): InsightRecord[] {
60
- if (projectId !== undefined) {
61
- return this.stmts.findActiveByProject.all(projectId) as InsightRecord[];
62
- }
63
- return this.stmts.findActiveAll.all() as InsightRecord[];
64
- }
65
-
66
- findByType(type: string): InsightRecord[] {
67
- return this.stmts.findByType.all(type) as InsightRecord[];
68
- }
69
-
70
- findByPriority(minPriority: number): InsightRecord[] {
71
- return this.stmts.findByPriority.all(minPriority) as InsightRecord[];
72
- }
73
-
74
- expire(): number {
75
- const result = this.stmts.expire.run();
76
- return result.changes;
77
- }
78
-
79
- rate(id: number, rating: number, comment?: string): boolean {
80
- const stmt = this.db.prepare(
81
- `UPDATE insights SET rating = ?, rating_comment = ?, rated_at = datetime('now') WHERE id = ?`
82
- );
83
- const result = stmt.run(rating, comment ?? null, id);
84
- return result.changes > 0;
85
- }
86
-
87
- findRated(minRating?: number): InsightRecord[] {
88
- if (minRating !== undefined) {
89
- const stmt = this.db.prepare(
90
- 'SELECT * FROM insights WHERE rating IS NOT NULL AND rating >= ? ORDER BY rating DESC'
91
- );
92
- return stmt.all(minRating) as InsightRecord[];
93
- }
94
- const stmt = this.db.prepare(
95
- 'SELECT * FROM insights WHERE rating IS NOT NULL ORDER BY rating DESC'
96
- );
97
- return stmt.all() as InsightRecord[];
98
- }
99
- }
@@ -1,66 +0,0 @@
1
- import type Database from 'better-sqlite3';
2
- import type { Statement } from 'better-sqlite3';
3
-
4
- export interface NotificationRecord {
5
- id: number;
6
- type: string;
7
- title: string;
8
- message: string;
9
- priority: number;
10
- project_id: number | null;
11
- acknowledged: number;
12
- acknowledged_at: string | null;
13
- created_at: string;
14
- }
15
-
16
- type NotificationCreate = Omit<NotificationRecord, 'id' | 'acknowledged' | 'acknowledged_at' | 'created_at'>;
17
-
18
- export class NotificationRepository {
19
- private stmts: Record<string, Statement>;
20
-
21
- constructor(private db: Database.Database) {
22
- this.stmts = {
23
- create: db.prepare(`
24
- INSERT INTO notifications (type, title, message, priority, project_id)
25
- VALUES (@type, @title, @message, @priority, @project_id)
26
- `),
27
- getById: db.prepare('SELECT * FROM notifications WHERE id = ?'),
28
- delete: db.prepare('DELETE FROM notifications WHERE id = ?'),
29
- findUnacknowledgedAll: db.prepare(
30
- 'SELECT * FROM notifications WHERE acknowledged = 0 ORDER BY priority DESC, created_at DESC'
31
- ),
32
- findUnacknowledgedByProject: db.prepare(
33
- 'SELECT * FROM notifications WHERE acknowledged = 0 AND project_id = ? ORDER BY priority DESC, created_at DESC'
34
- ),
35
- acknowledge: db.prepare(
36
- `UPDATE notifications SET acknowledged = 1, acknowledged_at = datetime('now') WHERE id = ?`
37
- ),
38
- };
39
- }
40
-
41
- create(data: NotificationCreate): number {
42
- const result = this.stmts.create.run(data);
43
- return result.lastInsertRowid as number;
44
- }
45
-
46
- getById(id: number): NotificationRecord | undefined {
47
- return this.stmts.getById.get(id) as NotificationRecord | undefined;
48
- }
49
-
50
- delete(id: number): boolean {
51
- const result = this.stmts.delete.run(id);
52
- return result.changes > 0;
53
- }
54
-
55
- findUnacknowledged(projectId?: number): NotificationRecord[] {
56
- if (projectId !== undefined) {
57
- return this.stmts.findUnacknowledgedByProject.all(projectId) as NotificationRecord[];
58
- }
59
- return this.stmts.findUnacknowledgedAll.all() as NotificationRecord[];
60
- }
61
-
62
- acknowledge(id: number): boolean {
63
- const result = this.stmts.acknowledge.run(id);
64
- return result.changes > 0;
65
- }
66
- }
@@ -1,93 +0,0 @@
1
- import type Database from 'better-sqlite3';
2
- import type { Statement } from 'better-sqlite3';
3
-
4
- export interface ProjectRecord {
5
- id: number;
6
- name: string;
7
- path: string | null;
8
- language: string | null;
9
- framework: string | null;
10
- created_at: string;
11
- updated_at: string;
12
- }
13
-
14
- type CreateProjectData = Omit<ProjectRecord, 'id' | 'created_at' | 'updated_at'>;
15
- type UpdateProjectData = Partial<Omit<ProjectRecord, 'id' | 'created_at'>>;
16
-
17
- export class ProjectRepository {
18
- private stmts: Record<string, Statement>;
19
-
20
- constructor(private db: Database.Database) {
21
- this.stmts = {
22
- create: this.db.prepare(`
23
- INSERT INTO projects (name, path, language, framework)
24
- VALUES (@name, @path, @language, @framework)
25
- `),
26
- getById: this.db.prepare(`
27
- SELECT * FROM projects WHERE id = ?
28
- `),
29
- update: this.db.prepare(`
30
- UPDATE projects
31
- SET name = COALESCE(@name, name),
32
- path = COALESCE(@path, path),
33
- language = COALESCE(@language, language),
34
- framework = COALESCE(@framework, framework),
35
- updated_at = datetime('now')
36
- WHERE id = @id
37
- `),
38
- delete: this.db.prepare(`
39
- DELETE FROM projects WHERE id = ?
40
- `),
41
- findByName: this.db.prepare(`
42
- SELECT * FROM projects WHERE name = ?
43
- `),
44
- findByPath: this.db.prepare(`
45
- SELECT * FROM projects WHERE path = ?
46
- `),
47
- getAll: this.db.prepare(`
48
- SELECT * FROM projects ORDER BY name
49
- `),
50
- };
51
- }
52
-
53
- create(data: CreateProjectData): number {
54
- const result = this.stmts.create.run({
55
- name: data.name,
56
- path: data.path ?? null,
57
- language: data.language ?? null,
58
- framework: data.framework ?? null,
59
- });
60
- return result.lastInsertRowid as number;
61
- }
62
-
63
- getById(id: number): ProjectRecord | undefined {
64
- return this.stmts.getById.get(id) as ProjectRecord | undefined;
65
- }
66
-
67
- update(id: number, data: UpdateProjectData): void {
68
- this.stmts.update.run({
69
- id,
70
- name: data.name ?? null,
71
- path: data.path ?? null,
72
- language: data.language ?? null,
73
- framework: data.framework ?? null,
74
- updated_at: data.updated_at ?? null,
75
- });
76
- }
77
-
78
- delete(id: number): void {
79
- this.stmts.delete.run(id);
80
- }
81
-
82
- findByName(name: string): ProjectRecord | undefined {
83
- return this.stmts.findByName.get(name) as ProjectRecord | undefined;
84
- }
85
-
86
- findByPath(path: string): ProjectRecord | undefined {
87
- return this.stmts.findByPath.get(path) as ProjectRecord | undefined;
88
- }
89
-
90
- getAll(): ProjectRecord[] {
91
- return this.stmts.getAll.all() as ProjectRecord[];
92
- }
93
- }