@timmeck/brain 1.8.0 → 1.8.2

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 (177) hide show
  1. package/BRAIN_PLAN.md +3324 -3324
  2. package/LICENSE +21 -21
  3. package/dist/api/server.d.ts +4 -0
  4. package/dist/api/server.js +73 -0
  5. package/dist/api/server.js.map +1 -1
  6. package/dist/brain.js +2 -1
  7. package/dist/brain.js.map +1 -1
  8. package/dist/cli/commands/dashboard.js +606 -572
  9. package/dist/cli/commands/dashboard.js.map +1 -1
  10. package/dist/dashboard/server.js +25 -25
  11. package/dist/db/migrations/001_core_schema.js +115 -115
  12. package/dist/db/migrations/002_learning_schema.js +33 -33
  13. package/dist/db/migrations/003_code_schema.js +48 -48
  14. package/dist/db/migrations/004_synapses_schema.js +52 -52
  15. package/dist/db/migrations/005_fts_indexes.js +73 -73
  16. package/dist/db/migrations/007_feedback.js +8 -8
  17. package/dist/db/migrations/008_git_integration.js +33 -33
  18. package/dist/db/migrations/009_embeddings.js +3 -3
  19. package/dist/db/repositories/antipattern.repository.js +3 -3
  20. package/dist/db/repositories/code-module.repository.js +32 -32
  21. package/dist/db/repositories/notification.repository.js +3 -3
  22. package/dist/db/repositories/project.repository.js +21 -21
  23. package/dist/db/repositories/rule.repository.js +24 -24
  24. package/dist/db/repositories/solution.repository.js +50 -50
  25. package/dist/db/repositories/synapse.repository.js +18 -18
  26. package/dist/db/repositories/terminal.repository.js +24 -24
  27. package/dist/embeddings/engine.d.ts +2 -2
  28. package/dist/embeddings/engine.js +17 -4
  29. package/dist/embeddings/engine.js.map +1 -1
  30. package/dist/index.js +1 -1
  31. package/dist/ipc/server.d.ts +8 -0
  32. package/dist/ipc/server.js +67 -1
  33. package/dist/ipc/server.js.map +1 -1
  34. package/dist/matching/error-matcher.js +5 -5
  35. package/dist/matching/fingerprint.js +6 -1
  36. package/dist/matching/fingerprint.js.map +1 -1
  37. package/dist/mcp/http-server.js +8 -2
  38. package/dist/mcp/http-server.js.map +1 -1
  39. package/dist/services/code.service.d.ts +3 -0
  40. package/dist/services/code.service.js +33 -4
  41. package/dist/services/code.service.js.map +1 -1
  42. package/dist/services/error.service.js +4 -3
  43. package/dist/services/error.service.js.map +1 -1
  44. package/dist/services/git.service.js +14 -14
  45. package/package.json +49 -49
  46. package/src/api/server.ts +395 -321
  47. package/src/brain.ts +266 -265
  48. package/src/cli/colors.ts +116 -116
  49. package/src/cli/commands/config.ts +169 -169
  50. package/src/cli/commands/dashboard.ts +755 -720
  51. package/src/cli/commands/doctor.ts +118 -118
  52. package/src/cli/commands/explain.ts +83 -83
  53. package/src/cli/commands/export.ts +31 -31
  54. package/src/cli/commands/import.ts +199 -199
  55. package/src/cli/commands/insights.ts +65 -65
  56. package/src/cli/commands/learn.ts +24 -24
  57. package/src/cli/commands/modules.ts +53 -53
  58. package/src/cli/commands/network.ts +67 -67
  59. package/src/cli/commands/projects.ts +42 -42
  60. package/src/cli/commands/query.ts +120 -120
  61. package/src/cli/commands/start.ts +62 -62
  62. package/src/cli/commands/status.ts +75 -75
  63. package/src/cli/commands/stop.ts +34 -34
  64. package/src/cli/ipc-helper.ts +22 -22
  65. package/src/cli/update-check.ts +63 -63
  66. package/src/code/fingerprint.ts +87 -87
  67. package/src/code/parsers/generic.ts +29 -29
  68. package/src/code/parsers/python.ts +54 -54
  69. package/src/code/parsers/typescript.ts +65 -65
  70. package/src/code/registry.ts +60 -60
  71. package/src/dashboard/server.ts +142 -142
  72. package/src/db/connection.ts +22 -22
  73. package/src/db/migrations/001_core_schema.ts +120 -120
  74. package/src/db/migrations/002_learning_schema.ts +38 -38
  75. package/src/db/migrations/003_code_schema.ts +53 -53
  76. package/src/db/migrations/004_synapses_schema.ts +57 -57
  77. package/src/db/migrations/005_fts_indexes.ts +78 -78
  78. package/src/db/migrations/006_synapses_phase3.ts +17 -17
  79. package/src/db/migrations/007_feedback.ts +13 -13
  80. package/src/db/migrations/008_git_integration.ts +38 -38
  81. package/src/db/migrations/009_embeddings.ts +8 -8
  82. package/src/db/repositories/antipattern.repository.ts +66 -66
  83. package/src/db/repositories/code-module.repository.ts +142 -142
  84. package/src/db/repositories/notification.repository.ts +66 -66
  85. package/src/db/repositories/project.repository.ts +93 -93
  86. package/src/db/repositories/rule.repository.ts +108 -108
  87. package/src/db/repositories/solution.repository.ts +154 -154
  88. package/src/db/repositories/synapse.repository.ts +153 -153
  89. package/src/db/repositories/terminal.repository.ts +101 -101
  90. package/src/embeddings/engine.ts +238 -217
  91. package/src/index.ts +63 -63
  92. package/src/ipc/client.ts +118 -118
  93. package/src/ipc/protocol.ts +35 -35
  94. package/src/ipc/router.ts +133 -133
  95. package/src/ipc/server.ts +176 -110
  96. package/src/learning/decay.ts +46 -46
  97. package/src/learning/pattern-extractor.ts +90 -90
  98. package/src/learning/rule-generator.ts +74 -74
  99. package/src/matching/error-matcher.ts +5 -5
  100. package/src/matching/fingerprint.ts +34 -29
  101. package/src/matching/similarity.ts +61 -61
  102. package/src/matching/tfidf.ts +74 -74
  103. package/src/matching/tokenizer.ts +41 -41
  104. package/src/mcp/auto-detect.ts +93 -93
  105. package/src/mcp/http-server.ts +140 -137
  106. package/src/mcp/server.ts +73 -73
  107. package/src/parsing/error-parser.ts +28 -28
  108. package/src/parsing/parsers/compiler.ts +93 -93
  109. package/src/parsing/parsers/generic.ts +28 -28
  110. package/src/parsing/parsers/go.ts +97 -97
  111. package/src/parsing/parsers/node.ts +69 -69
  112. package/src/parsing/parsers/python.ts +62 -62
  113. package/src/parsing/parsers/rust.ts +50 -50
  114. package/src/parsing/parsers/shell.ts +42 -42
  115. package/src/parsing/types.ts +47 -47
  116. package/src/research/gap-analyzer.ts +135 -135
  117. package/src/research/insight-generator.ts +123 -123
  118. package/src/research/research-engine.ts +116 -116
  119. package/src/research/synergy-detector.ts +126 -126
  120. package/src/research/template-extractor.ts +130 -130
  121. package/src/research/trend-analyzer.ts +127 -127
  122. package/src/services/code.service.ts +271 -238
  123. package/src/services/error.service.ts +4 -3
  124. package/src/services/git.service.ts +132 -132
  125. package/src/services/notification.service.ts +41 -41
  126. package/src/services/synapse.service.ts +59 -59
  127. package/src/services/terminal.service.ts +81 -81
  128. package/src/synapses/activation.ts +80 -80
  129. package/src/synapses/decay.ts +38 -38
  130. package/src/synapses/hebbian.ts +69 -69
  131. package/src/synapses/pathfinder.ts +81 -81
  132. package/src/synapses/synapse-manager.ts +109 -109
  133. package/src/types/code.types.ts +52 -52
  134. package/src/types/error.types.ts +67 -67
  135. package/src/types/ipc.types.ts +8 -8
  136. package/src/types/mcp.types.ts +53 -53
  137. package/src/types/research.types.ts +28 -28
  138. package/src/types/solution.types.ts +30 -30
  139. package/src/utils/events.ts +45 -45
  140. package/src/utils/hash.ts +5 -5
  141. package/src/utils/logger.ts +48 -48
  142. package/src/utils/paths.ts +19 -19
  143. package/tests/e2e/test_code_intelligence.py +1015 -0
  144. package/tests/e2e/test_error_memory.py +451 -0
  145. package/tests/e2e/test_full_integration.py +534 -0
  146. package/tests/fixtures/code-modules/modules.ts +83 -83
  147. package/tests/fixtures/errors/go.ts +9 -9
  148. package/tests/fixtures/errors/node.ts +24 -24
  149. package/tests/fixtures/errors/python.ts +21 -21
  150. package/tests/fixtures/errors/rust.ts +25 -25
  151. package/tests/fixtures/errors/shell.ts +15 -15
  152. package/tests/fixtures/solutions/solutions.ts +27 -27
  153. package/tests/helpers/setup-db.ts +52 -52
  154. package/tests/integration/code-flow.test.ts +86 -86
  155. package/tests/integration/error-flow.test.ts +83 -83
  156. package/tests/integration/ipc-flow.test.ts +166 -166
  157. package/tests/integration/learning-cycle.test.ts +82 -82
  158. package/tests/integration/synapse-flow.test.ts +117 -117
  159. package/tests/unit/code/analyzer.test.ts +58 -58
  160. package/tests/unit/code/fingerprint.test.ts +51 -51
  161. package/tests/unit/code/scorer.test.ts +55 -55
  162. package/tests/unit/learning/confidence-scorer.test.ts +60 -60
  163. package/tests/unit/learning/decay.test.ts +45 -45
  164. package/tests/unit/learning/pattern-extractor.test.ts +50 -50
  165. package/tests/unit/matching/error-matcher.test.ts +69 -69
  166. package/tests/unit/matching/fingerprint.test.ts +47 -47
  167. package/tests/unit/matching/similarity.test.ts +65 -65
  168. package/tests/unit/matching/tfidf.test.ts +71 -71
  169. package/tests/unit/matching/tokenizer.test.ts +83 -83
  170. package/tests/unit/parsing/parsers.test.ts +113 -113
  171. package/tests/unit/research/gap-analyzer.test.ts +45 -45
  172. package/tests/unit/research/trend-analyzer.test.ts +45 -45
  173. package/tests/unit/synapses/activation.test.ts +80 -80
  174. package/tests/unit/synapses/decay.test.ts +27 -27
  175. package/tests/unit/synapses/hebbian.test.ts +96 -96
  176. package/tests/unit/synapses/pathfinder.test.ts +72 -72
  177. package/tsconfig.json +18 -18
@@ -1,77 +1,77 @@
1
1
  export function up(db) {
2
- db.exec(`
3
- -- Full-text search for errors
4
- CREATE VIRTUAL TABLE IF NOT EXISTS errors_fts USING fts5(
5
- type, message, raw_output, context, file_path,
6
- content='errors',
7
- content_rowid='id'
8
- );
9
-
10
- -- Sync triggers for errors_fts
11
- CREATE TRIGGER IF NOT EXISTS errors_ai AFTER INSERT ON errors BEGIN
12
- INSERT INTO errors_fts(rowid, type, message, raw_output, context, file_path)
13
- VALUES (new.id, new.type, new.message, new.raw_output, new.context, new.file_path);
14
- END;
15
-
16
- CREATE TRIGGER IF NOT EXISTS errors_ad AFTER DELETE ON errors BEGIN
17
- INSERT INTO errors_fts(errors_fts, rowid, type, message, raw_output, context, file_path)
18
- VALUES ('delete', old.id, old.type, old.message, old.raw_output, old.context, old.file_path);
19
- END;
20
-
21
- CREATE TRIGGER IF NOT EXISTS errors_au AFTER UPDATE ON errors BEGIN
22
- INSERT INTO errors_fts(errors_fts, rowid, type, message, raw_output, context, file_path)
23
- VALUES ('delete', old.id, old.type, old.message, old.raw_output, old.context, old.file_path);
24
- INSERT INTO errors_fts(rowid, type, message, raw_output, context, file_path)
25
- VALUES (new.id, new.type, new.message, new.raw_output, new.context, new.file_path);
26
- END;
27
-
28
- -- Full-text search for solutions
29
- CREATE VIRTUAL TABLE IF NOT EXISTS solutions_fts USING fts5(
30
- description, commands, code_change,
31
- content='solutions',
32
- content_rowid='id'
33
- );
34
-
35
- CREATE TRIGGER IF NOT EXISTS solutions_ai AFTER INSERT ON solutions BEGIN
36
- INSERT INTO solutions_fts(rowid, description, commands, code_change)
37
- VALUES (new.id, new.description, new.commands, new.code_change);
38
- END;
39
-
40
- CREATE TRIGGER IF NOT EXISTS solutions_ad AFTER DELETE ON solutions BEGIN
41
- INSERT INTO solutions_fts(solutions_fts, rowid, description, commands, code_change)
42
- VALUES ('delete', old.id, old.description, old.commands, old.code_change);
43
- END;
44
-
45
- CREATE TRIGGER IF NOT EXISTS solutions_au AFTER UPDATE ON solutions BEGIN
46
- INSERT INTO solutions_fts(solutions_fts, rowid, description, commands, code_change)
47
- VALUES ('delete', old.id, old.description, old.commands, old.code_change);
48
- INSERT INTO solutions_fts(rowid, description, commands, code_change)
49
- VALUES (new.id, new.description, new.commands, new.code_change);
50
- END;
51
-
52
- -- Full-text search for code modules
53
- CREATE VIRTUAL TABLE IF NOT EXISTS code_modules_fts USING fts5(
54
- name, file_path, description, language,
55
- content='code_modules',
56
- content_rowid='id'
57
- );
58
-
59
- CREATE TRIGGER IF NOT EXISTS code_modules_ai AFTER INSERT ON code_modules BEGIN
60
- INSERT INTO code_modules_fts(rowid, name, file_path, description, language)
61
- VALUES (new.id, new.name, new.file_path, new.description, new.language);
62
- END;
63
-
64
- CREATE TRIGGER IF NOT EXISTS code_modules_ad AFTER DELETE ON code_modules BEGIN
65
- INSERT INTO code_modules_fts(code_modules_fts, rowid, name, file_path, description, language)
66
- VALUES ('delete', old.id, old.name, old.file_path, old.description, old.language);
67
- END;
68
-
69
- CREATE TRIGGER IF NOT EXISTS code_modules_au AFTER UPDATE ON code_modules BEGIN
70
- INSERT INTO code_modules_fts(code_modules_fts, rowid, name, file_path, description, language)
71
- VALUES ('delete', old.id, old.name, old.file_path, old.description, old.language);
72
- INSERT INTO code_modules_fts(rowid, name, file_path, description, language)
73
- VALUES (new.id, new.name, new.file_path, new.description, new.language);
74
- END;
2
+ db.exec(`
3
+ -- Full-text search for errors
4
+ CREATE VIRTUAL TABLE IF NOT EXISTS errors_fts USING fts5(
5
+ type, message, raw_output, context, file_path,
6
+ content='errors',
7
+ content_rowid='id'
8
+ );
9
+
10
+ -- Sync triggers for errors_fts
11
+ CREATE TRIGGER IF NOT EXISTS errors_ai AFTER INSERT ON errors BEGIN
12
+ INSERT INTO errors_fts(rowid, type, message, raw_output, context, file_path)
13
+ VALUES (new.id, new.type, new.message, new.raw_output, new.context, new.file_path);
14
+ END;
15
+
16
+ CREATE TRIGGER IF NOT EXISTS errors_ad AFTER DELETE ON errors BEGIN
17
+ INSERT INTO errors_fts(errors_fts, rowid, type, message, raw_output, context, file_path)
18
+ VALUES ('delete', old.id, old.type, old.message, old.raw_output, old.context, old.file_path);
19
+ END;
20
+
21
+ CREATE TRIGGER IF NOT EXISTS errors_au AFTER UPDATE ON errors BEGIN
22
+ INSERT INTO errors_fts(errors_fts, rowid, type, message, raw_output, context, file_path)
23
+ VALUES ('delete', old.id, old.type, old.message, old.raw_output, old.context, old.file_path);
24
+ INSERT INTO errors_fts(rowid, type, message, raw_output, context, file_path)
25
+ VALUES (new.id, new.type, new.message, new.raw_output, new.context, new.file_path);
26
+ END;
27
+
28
+ -- Full-text search for solutions
29
+ CREATE VIRTUAL TABLE IF NOT EXISTS solutions_fts USING fts5(
30
+ description, commands, code_change,
31
+ content='solutions',
32
+ content_rowid='id'
33
+ );
34
+
35
+ CREATE TRIGGER IF NOT EXISTS solutions_ai AFTER INSERT ON solutions BEGIN
36
+ INSERT INTO solutions_fts(rowid, description, commands, code_change)
37
+ VALUES (new.id, new.description, new.commands, new.code_change);
38
+ END;
39
+
40
+ CREATE TRIGGER IF NOT EXISTS solutions_ad AFTER DELETE ON solutions BEGIN
41
+ INSERT INTO solutions_fts(solutions_fts, rowid, description, commands, code_change)
42
+ VALUES ('delete', old.id, old.description, old.commands, old.code_change);
43
+ END;
44
+
45
+ CREATE TRIGGER IF NOT EXISTS solutions_au AFTER UPDATE ON solutions BEGIN
46
+ INSERT INTO solutions_fts(solutions_fts, rowid, description, commands, code_change)
47
+ VALUES ('delete', old.id, old.description, old.commands, old.code_change);
48
+ INSERT INTO solutions_fts(rowid, description, commands, code_change)
49
+ VALUES (new.id, new.description, new.commands, new.code_change);
50
+ END;
51
+
52
+ -- Full-text search for code modules
53
+ CREATE VIRTUAL TABLE IF NOT EXISTS code_modules_fts USING fts5(
54
+ name, file_path, description, language,
55
+ content='code_modules',
56
+ content_rowid='id'
57
+ );
58
+
59
+ CREATE TRIGGER IF NOT EXISTS code_modules_ai AFTER INSERT ON code_modules BEGIN
60
+ INSERT INTO code_modules_fts(rowid, name, file_path, description, language)
61
+ VALUES (new.id, new.name, new.file_path, new.description, new.language);
62
+ END;
63
+
64
+ CREATE TRIGGER IF NOT EXISTS code_modules_ad AFTER DELETE ON code_modules BEGIN
65
+ INSERT INTO code_modules_fts(code_modules_fts, rowid, name, file_path, description, language)
66
+ VALUES ('delete', old.id, old.name, old.file_path, old.description, old.language);
67
+ END;
68
+
69
+ CREATE TRIGGER IF NOT EXISTS code_modules_au AFTER UPDATE ON code_modules BEGIN
70
+ INSERT INTO code_modules_fts(code_modules_fts, rowid, name, file_path, description, language)
71
+ VALUES ('delete', old.id, old.name, old.file_path, old.description, old.language);
72
+ INSERT INTO code_modules_fts(rowid, name, file_path, description, language)
73
+ VALUES (new.id, new.name, new.file_path, new.description, new.language);
74
+ END;
75
75
  `);
76
76
  }
77
77
  //# sourceMappingURL=005_fts_indexes.js.map
@@ -1,12 +1,12 @@
1
1
  export function up(db) {
2
- db.exec(`
3
- ALTER TABLE insights ADD COLUMN rating INTEGER DEFAULT NULL;
4
- ALTER TABLE insights ADD COLUMN rating_comment TEXT DEFAULT NULL;
5
- ALTER TABLE insights ADD COLUMN rated_at TEXT DEFAULT NULL;
6
-
7
- ALTER TABLE rules ADD COLUMN rating INTEGER DEFAULT NULL;
8
- ALTER TABLE rules ADD COLUMN rating_comment TEXT DEFAULT NULL;
9
- ALTER TABLE rules ADD COLUMN rated_at TEXT DEFAULT NULL;
2
+ db.exec(`
3
+ ALTER TABLE insights ADD COLUMN rating INTEGER DEFAULT NULL;
4
+ ALTER TABLE insights ADD COLUMN rating_comment TEXT DEFAULT NULL;
5
+ ALTER TABLE insights ADD COLUMN rated_at TEXT DEFAULT NULL;
6
+
7
+ ALTER TABLE rules ADD COLUMN rating INTEGER DEFAULT NULL;
8
+ ALTER TABLE rules ADD COLUMN rating_comment TEXT DEFAULT NULL;
9
+ ALTER TABLE rules ADD COLUMN rated_at TEXT DEFAULT NULL;
10
10
  `);
11
11
  }
12
12
  //# sourceMappingURL=007_feedback.js.map
@@ -1,37 +1,37 @@
1
1
  export function up(db) {
2
- db.exec(`
3
- CREATE TABLE IF NOT EXISTS git_commits (
4
- id INTEGER PRIMARY KEY AUTOINCREMENT,
5
- project_id INTEGER NOT NULL,
6
- commit_hash TEXT NOT NULL,
7
- message TEXT NOT NULL,
8
- author TEXT,
9
- timestamp TEXT NOT NULL,
10
- files_changed INTEGER NOT NULL DEFAULT 0,
11
- insertions INTEGER NOT NULL DEFAULT 0,
12
- deletions INTEGER NOT NULL DEFAULT 0,
13
- created_at TEXT NOT NULL DEFAULT (datetime('now')),
14
- FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE,
15
- UNIQUE(project_id, commit_hash)
16
- );
17
-
18
- CREATE TABLE IF NOT EXISTS error_commits (
19
- id INTEGER PRIMARY KEY AUTOINCREMENT,
20
- error_id INTEGER NOT NULL,
21
- commit_hash TEXT NOT NULL,
22
- relationship TEXT NOT NULL DEFAULT 'introduced_by',
23
- created_at TEXT NOT NULL DEFAULT (datetime('now')),
24
- FOREIGN KEY (error_id) REFERENCES errors(id) ON DELETE CASCADE,
25
- UNIQUE(error_id, commit_hash, relationship)
26
- );
27
-
28
- ALTER TABLE errors ADD COLUMN git_diff TEXT DEFAULT NULL;
29
- ALTER TABLE errors ADD COLUMN git_branch TEXT DEFAULT NULL;
30
-
31
- CREATE INDEX IF NOT EXISTS idx_git_commits_project ON git_commits(project_id);
32
- CREATE INDEX IF NOT EXISTS idx_git_commits_hash ON git_commits(commit_hash);
33
- CREATE INDEX IF NOT EXISTS idx_error_commits_error ON error_commits(error_id);
34
- CREATE INDEX IF NOT EXISTS idx_error_commits_hash ON error_commits(commit_hash);
2
+ db.exec(`
3
+ CREATE TABLE IF NOT EXISTS git_commits (
4
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
5
+ project_id INTEGER NOT NULL,
6
+ commit_hash TEXT NOT NULL,
7
+ message TEXT NOT NULL,
8
+ author TEXT,
9
+ timestamp TEXT NOT NULL,
10
+ files_changed INTEGER NOT NULL DEFAULT 0,
11
+ insertions INTEGER NOT NULL DEFAULT 0,
12
+ deletions INTEGER NOT NULL DEFAULT 0,
13
+ created_at TEXT NOT NULL DEFAULT (datetime('now')),
14
+ FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE,
15
+ UNIQUE(project_id, commit_hash)
16
+ );
17
+
18
+ CREATE TABLE IF NOT EXISTS error_commits (
19
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
20
+ error_id INTEGER NOT NULL,
21
+ commit_hash TEXT NOT NULL,
22
+ relationship TEXT NOT NULL DEFAULT 'introduced_by',
23
+ created_at TEXT NOT NULL DEFAULT (datetime('now')),
24
+ FOREIGN KEY (error_id) REFERENCES errors(id) ON DELETE CASCADE,
25
+ UNIQUE(error_id, commit_hash, relationship)
26
+ );
27
+
28
+ ALTER TABLE errors ADD COLUMN git_diff TEXT DEFAULT NULL;
29
+ ALTER TABLE errors ADD COLUMN git_branch TEXT DEFAULT NULL;
30
+
31
+ CREATE INDEX IF NOT EXISTS idx_git_commits_project ON git_commits(project_id);
32
+ CREATE INDEX IF NOT EXISTS idx_git_commits_hash ON git_commits(commit_hash);
33
+ CREATE INDEX IF NOT EXISTS idx_error_commits_error ON error_commits(error_id);
34
+ CREATE INDEX IF NOT EXISTS idx_error_commits_hash ON error_commits(commit_hash);
35
35
  `);
36
36
  }
37
37
  //# sourceMappingURL=008_git_integration.js.map
@@ -1,7 +1,7 @@
1
1
  export function up(db) {
2
- db.exec(`
3
- ALTER TABLE errors ADD COLUMN embedding BLOB DEFAULT NULL;
4
- ALTER TABLE code_modules ADD COLUMN embedding BLOB DEFAULT NULL;
2
+ db.exec(`
3
+ ALTER TABLE errors ADD COLUMN embedding BLOB DEFAULT NULL;
4
+ ALTER TABLE code_modules ADD COLUMN embedding BLOB DEFAULT NULL;
5
5
  `);
6
6
  }
7
7
  //# sourceMappingURL=009_embeddings.js.map
@@ -4,9 +4,9 @@ export class AntipatternRepository {
4
4
  constructor(db) {
5
5
  this.db = db;
6
6
  this.stmts = {
7
- create: db.prepare(`
8
- INSERT INTO antipatterns (pattern, description, severity, suggestion, occurrences, project_id, global)
9
- VALUES (@pattern, @description, @severity, @suggestion, @occurrences, @project_id, @global)
7
+ create: db.prepare(`
8
+ INSERT INTO antipatterns (pattern, description, severity, suggestion, occurrences, project_id, global)
9
+ VALUES (@pattern, @description, @severity, @suggestion, @occurrences, @project_id, @global)
10
10
  `),
11
11
  getById: db.prepare('SELECT * FROM antipatterns WHERE id = ?'),
12
12
  delete: db.prepare('DELETE FROM antipatterns WHERE id = ?'),
@@ -4,9 +4,9 @@ export class CodeModuleRepository {
4
4
  constructor(db) {
5
5
  this.db = db;
6
6
  this.stmts = {
7
- create: db.prepare(`
8
- INSERT INTO code_modules (project_id, name, file_path, language, fingerprint, description, source_hash, lines_of_code, complexity, reusability_score)
9
- VALUES (@project_id, @name, @file_path, @language, @fingerprint, @description, @source_hash, @lines_of_code, @complexity, @reusability_score)
7
+ create: db.prepare(`
8
+ INSERT INTO code_modules (project_id, name, file_path, language, fingerprint, description, source_hash, lines_of_code, complexity, reusability_score)
9
+ VALUES (@project_id, @name, @file_path, @language, @fingerprint, @description, @source_hash, @lines_of_code, @complexity, @reusability_score)
10
10
  `),
11
11
  getById: db.prepare('SELECT * FROM code_modules WHERE id = ?'),
12
12
  delete: db.prepare('DELETE FROM code_modules WHERE id = ?'),
@@ -14,38 +14,38 @@ export class CodeModuleRepository {
14
14
  findByProject: db.prepare('SELECT * FROM code_modules WHERE project_id = ? ORDER BY name ASC'),
15
15
  findAll: db.prepare('SELECT * FROM code_modules ORDER BY name ASC'),
16
16
  countAll: db.prepare('SELECT COUNT(*) as count FROM code_modules'),
17
- search: db.prepare(`
18
- SELECT cm.* FROM code_modules cm
19
- JOIN code_modules_fts fts ON cm.id = fts.rowid
20
- WHERE code_modules_fts MATCH ?
21
- ORDER BY rank
17
+ search: db.prepare(`
18
+ SELECT cm.* FROM code_modules cm
19
+ JOIN code_modules_fts fts ON cm.id = fts.rowid
20
+ WHERE code_modules_fts MATCH ?
21
+ ORDER BY rank
22
22
  `),
23
- upsertSimilarity: db.prepare(`
24
- INSERT INTO module_similarities (module_a_id, module_b_id, similarity_score)
25
- VALUES (@module_a_id, @module_b_id, @similarity_score)
26
- ON CONFLICT(module_a_id, module_b_id)
27
- DO UPDATE SET similarity_score = @similarity_score, computed_at = datetime('now')
23
+ upsertSimilarity: db.prepare(`
24
+ INSERT INTO module_similarities (module_a_id, module_b_id, similarity_score)
25
+ VALUES (@module_a_id, @module_b_id, @similarity_score)
26
+ ON CONFLICT(module_a_id, module_b_id)
27
+ DO UPDATE SET similarity_score = @similarity_score, computed_at = datetime('now')
28
28
  `),
29
- findSimilarModules: db.prepare(`
30
- SELECT ms.*, cm.name, cm.file_path, cm.language, cm.reusability_score
31
- FROM module_similarities ms
32
- JOIN code_modules cm ON (
33
- CASE WHEN ms.module_a_id = ? THEN ms.module_b_id ELSE ms.module_a_id END
34
- ) = cm.id
35
- WHERE ms.module_a_id = ? OR ms.module_b_id = ?
36
- ORDER BY ms.similarity_score DESC
37
- LIMIT ?
29
+ findSimilarModules: db.prepare(`
30
+ SELECT ms.*, cm.name, cm.file_path, cm.language, cm.reusability_score
31
+ FROM module_similarities ms
32
+ JOIN code_modules cm ON (
33
+ CASE WHEN ms.module_a_id = ? THEN ms.module_b_id ELSE ms.module_a_id END
34
+ ) = cm.id
35
+ WHERE ms.module_a_id = ? OR ms.module_b_id = ?
36
+ ORDER BY ms.similarity_score DESC
37
+ LIMIT ?
38
38
  `),
39
- findHighSimilarityPairs: db.prepare(`
40
- SELECT ms.*,
41
- a.name as a_name, a.file_path as a_path,
42
- b.name as b_name, b.file_path as b_path
43
- FROM module_similarities ms
44
- JOIN code_modules a ON ms.module_a_id = a.id
45
- JOIN code_modules b ON ms.module_b_id = b.id
46
- WHERE ms.similarity_score >= ?
47
- ORDER BY ms.similarity_score DESC
48
- LIMIT ?
39
+ findHighSimilarityPairs: db.prepare(`
40
+ SELECT ms.*,
41
+ a.name as a_name, a.file_path as a_path,
42
+ b.name as b_name, b.file_path as b_path
43
+ FROM module_similarities ms
44
+ JOIN code_modules a ON ms.module_a_id = a.id
45
+ JOIN code_modules b ON ms.module_b_id = b.id
46
+ WHERE ms.similarity_score >= ?
47
+ ORDER BY ms.similarity_score DESC
48
+ LIMIT ?
49
49
  `),
50
50
  };
51
51
  }
@@ -4,9 +4,9 @@ export class NotificationRepository {
4
4
  constructor(db) {
5
5
  this.db = db;
6
6
  this.stmts = {
7
- create: db.prepare(`
8
- INSERT INTO notifications (type, title, message, priority, project_id)
9
- VALUES (@type, @title, @message, @priority, @project_id)
7
+ create: db.prepare(`
8
+ INSERT INTO notifications (type, title, message, priority, project_id)
9
+ VALUES (@type, @title, @message, @priority, @project_id)
10
10
  `),
11
11
  getById: db.prepare('SELECT * FROM notifications WHERE id = ?'),
12
12
  delete: db.prepare('DELETE FROM notifications WHERE id = ?'),
@@ -4,33 +4,33 @@ export class ProjectRepository {
4
4
  constructor(db) {
5
5
  this.db = db;
6
6
  this.stmts = {
7
- create: this.db.prepare(`
8
- INSERT INTO projects (name, path, language, framework)
9
- VALUES (@name, @path, @language, @framework)
7
+ create: this.db.prepare(`
8
+ INSERT INTO projects (name, path, language, framework)
9
+ VALUES (@name, @path, @language, @framework)
10
10
  `),
11
- getById: this.db.prepare(`
12
- SELECT * FROM projects WHERE id = ?
11
+ getById: this.db.prepare(`
12
+ SELECT * FROM projects WHERE id = ?
13
13
  `),
14
- update: this.db.prepare(`
15
- UPDATE projects
16
- SET name = COALESCE(@name, name),
17
- path = COALESCE(@path, path),
18
- language = COALESCE(@language, language),
19
- framework = COALESCE(@framework, framework),
20
- updated_at = datetime('now')
21
- WHERE id = @id
14
+ update: this.db.prepare(`
15
+ UPDATE projects
16
+ SET name = COALESCE(@name, name),
17
+ path = COALESCE(@path, path),
18
+ language = COALESCE(@language, language),
19
+ framework = COALESCE(@framework, framework),
20
+ updated_at = datetime('now')
21
+ WHERE id = @id
22
22
  `),
23
- delete: this.db.prepare(`
24
- DELETE FROM projects WHERE id = ?
23
+ delete: this.db.prepare(`
24
+ DELETE FROM projects WHERE id = ?
25
25
  `),
26
- findByName: this.db.prepare(`
27
- SELECT * FROM projects WHERE name = ?
26
+ findByName: this.db.prepare(`
27
+ SELECT * FROM projects WHERE name = ?
28
28
  `),
29
- findByPath: this.db.prepare(`
30
- SELECT * FROM projects WHERE path = ?
29
+ findByPath: this.db.prepare(`
30
+ SELECT * FROM projects WHERE path = ?
31
31
  `),
32
- getAll: this.db.prepare(`
33
- SELECT * FROM projects ORDER BY name
32
+ getAll: this.db.prepare(`
33
+ SELECT * FROM projects ORDER BY name
34
34
  `),
35
35
  };
36
36
  }
@@ -4,36 +4,36 @@ export class RuleRepository {
4
4
  constructor(db) {
5
5
  this.db = db;
6
6
  this.stmts = {
7
- create: this.db.prepare(`
8
- INSERT INTO rules (pattern, action, description, confidence, occurrences, active, project_id)
9
- VALUES (@pattern, @action, @description, @confidence, @occurrences, @active, @project_id)
7
+ create: this.db.prepare(`
8
+ INSERT INTO rules (pattern, action, description, confidence, occurrences, active, project_id)
9
+ VALUES (@pattern, @action, @description, @confidence, @occurrences, @active, @project_id)
10
10
  `),
11
- getById: this.db.prepare(`
12
- SELECT * FROM rules WHERE id = ?
11
+ getById: this.db.prepare(`
12
+ SELECT * FROM rules WHERE id = ?
13
13
  `),
14
- update: this.db.prepare(`
15
- UPDATE rules
16
- SET pattern = COALESCE(@pattern, pattern),
17
- action = COALESCE(@action, action),
18
- description = COALESCE(@description, description),
19
- confidence = COALESCE(@confidence, confidence),
20
- occurrences = COALESCE(@occurrences, occurrences),
21
- active = COALESCE(@active, active),
22
- project_id = COALESCE(@project_id, project_id),
23
- updated_at = datetime('now')
24
- WHERE id = @id
14
+ update: this.db.prepare(`
15
+ UPDATE rules
16
+ SET pattern = COALESCE(@pattern, pattern),
17
+ action = COALESCE(@action, action),
18
+ description = COALESCE(@description, description),
19
+ confidence = COALESCE(@confidence, confidence),
20
+ occurrences = COALESCE(@occurrences, occurrences),
21
+ active = COALESCE(@active, active),
22
+ project_id = COALESCE(@project_id, project_id),
23
+ updated_at = datetime('now')
24
+ WHERE id = @id
25
25
  `),
26
- delete: this.db.prepare(`
27
- DELETE FROM rules WHERE id = ?
26
+ delete: this.db.prepare(`
27
+ DELETE FROM rules WHERE id = ?
28
28
  `),
29
- findActiveAll: this.db.prepare(`
30
- SELECT * FROM rules WHERE active = 1 ORDER BY confidence DESC
29
+ findActiveAll: this.db.prepare(`
30
+ SELECT * FROM rules WHERE active = 1 ORDER BY confidence DESC
31
31
  `),
32
- findActiveByProject: this.db.prepare(`
33
- SELECT * FROM rules WHERE active = 1 AND (project_id = ? OR project_id IS NULL) ORDER BY confidence DESC
32
+ findActiveByProject: this.db.prepare(`
33
+ SELECT * FROM rules WHERE active = 1 AND (project_id = ? OR project_id IS NULL) ORDER BY confidence DESC
34
34
  `),
35
- findByPattern: this.db.prepare(`
36
- SELECT * FROM rules WHERE pattern = ?
35
+ findByPattern: this.db.prepare(`
36
+ SELECT * FROM rules WHERE pattern = ?
37
37
  `),
38
38
  };
39
39
  }
@@ -4,67 +4,67 @@ export class SolutionRepository {
4
4
  constructor(db) {
5
5
  this.db = db;
6
6
  this.stmts = {
7
- create: this.db.prepare(`
8
- INSERT INTO solutions (description, commands, code_change, source, confidence)
9
- VALUES (@description, @commands, @code_change, @source, @confidence)
7
+ create: this.db.prepare(`
8
+ INSERT INTO solutions (description, commands, code_change, source, confidence)
9
+ VALUES (@description, @commands, @code_change, @source, @confidence)
10
10
  `),
11
- getById: this.db.prepare(`
12
- SELECT * FROM solutions WHERE id = ?
11
+ getById: this.db.prepare(`
12
+ SELECT * FROM solutions WHERE id = ?
13
13
  `),
14
- update: this.db.prepare(`
15
- UPDATE solutions
16
- SET description = COALESCE(@description, description),
17
- commands = COALESCE(@commands, commands),
18
- code_change = COALESCE(@code_change, code_change),
19
- source = COALESCE(@source, source),
20
- confidence = COALESCE(@confidence, confidence),
21
- success_count = COALESCE(@success_count, success_count),
22
- fail_count = COALESCE(@fail_count, fail_count),
23
- updated_at = datetime('now')
24
- WHERE id = @id
14
+ update: this.db.prepare(`
15
+ UPDATE solutions
16
+ SET description = COALESCE(@description, description),
17
+ commands = COALESCE(@commands, commands),
18
+ code_change = COALESCE(@code_change, code_change),
19
+ source = COALESCE(@source, source),
20
+ confidence = COALESCE(@confidence, confidence),
21
+ success_count = COALESCE(@success_count, success_count),
22
+ fail_count = COALESCE(@fail_count, fail_count),
23
+ updated_at = datetime('now')
24
+ WHERE id = @id
25
25
  `),
26
- delete: this.db.prepare(`
27
- DELETE FROM solutions WHERE id = ?
26
+ delete: this.db.prepare(`
27
+ DELETE FROM solutions WHERE id = ?
28
28
  `),
29
- findForError: this.db.prepare(`
30
- SELECT s.* FROM solutions s
31
- JOIN error_solutions es ON s.id = es.solution_id
32
- WHERE es.error_id = ?
33
- ORDER BY s.confidence DESC
29
+ findForError: this.db.prepare(`
30
+ SELECT s.* FROM solutions s
31
+ JOIN error_solutions es ON s.id = es.solution_id
32
+ WHERE es.error_id = ?
33
+ ORDER BY s.confidence DESC
34
34
  `),
35
- linkToError: this.db.prepare(`
36
- INSERT OR IGNORE INTO error_solutions (error_id, solution_id)
37
- VALUES (@error_id, @solution_id)
35
+ linkToError: this.db.prepare(`
36
+ INSERT OR IGNORE INTO error_solutions (error_id, solution_id)
37
+ VALUES (@error_id, @solution_id)
38
38
  `),
39
- recordAttempt: this.db.prepare(`
40
- INSERT INTO solution_attempts (error_solution_id, terminal_id, success, output, duration_ms)
41
- VALUES (@error_solution_id, @terminal_id, @success, @output, @duration_ms)
39
+ recordAttempt: this.db.prepare(`
40
+ INSERT INTO solution_attempts (error_solution_id, terminal_id, success, output, duration_ms)
41
+ VALUES (@error_solution_id, @terminal_id, @success, @output, @duration_ms)
42
42
  `),
43
- getAttempts: this.db.prepare(`
44
- SELECT * FROM solution_attempts WHERE error_solution_id = ? ORDER BY attempted_at DESC
43
+ getAttempts: this.db.prepare(`
44
+ SELECT * FROM solution_attempts WHERE error_solution_id = ? ORDER BY attempted_at DESC
45
45
  `),
46
- getAll: this.db.prepare(`
47
- SELECT * FROM solutions
46
+ getAll: this.db.prepare(`
47
+ SELECT * FROM solutions
48
48
  `),
49
- successRate: this.db.prepare(`
50
- SELECT
51
- COUNT(*) as total,
52
- SUM(CASE WHEN sa.success = 1 THEN 1 ELSE 0 END) as successes
53
- FROM solution_attempts sa
54
- JOIN error_solutions es ON sa.error_solution_id = es.id
55
- WHERE es.solution_id = ?
49
+ successRate: this.db.prepare(`
50
+ SELECT
51
+ COUNT(*) as total,
52
+ SUM(CASE WHEN sa.success = 1 THEN 1 ELSE 0 END) as successes
53
+ FROM solution_attempts sa
54
+ JOIN error_solutions es ON sa.error_solution_id = es.id
55
+ WHERE es.solution_id = ?
56
56
  `),
57
- updateSuccessCount: this.db.prepare(`
58
- UPDATE solutions
59
- SET success_count = success_count + 1,
60
- updated_at = datetime('now')
61
- WHERE id = ?
57
+ updateSuccessCount: this.db.prepare(`
58
+ UPDATE solutions
59
+ SET success_count = success_count + 1,
60
+ updated_at = datetime('now')
61
+ WHERE id = ?
62
62
  `),
63
- updateFailCount: this.db.prepare(`
64
- UPDATE solutions
65
- SET fail_count = fail_count + 1,
66
- updated_at = datetime('now')
67
- WHERE id = ?
63
+ updateFailCount: this.db.prepare(`
64
+ UPDATE solutions
65
+ SET fail_count = fail_count + 1,
66
+ updated_at = datetime('now')
67
+ WHERE id = ?
68
68
  `),
69
69
  };
70
70
  }
@@ -4,32 +4,32 @@ export class SynapseRepository {
4
4
  constructor(db) {
5
5
  this.db = db;
6
6
  this.stmts = {
7
- create: db.prepare(`
8
- INSERT INTO synapses (source_type, source_id, target_type, target_id, synapse_type, weight, metadata)
9
- VALUES (@source_type, @source_id, @target_type, @target_id, @synapse_type, @weight, @metadata)
7
+ create: db.prepare(`
8
+ INSERT INTO synapses (source_type, source_id, target_type, target_id, synapse_type, weight, metadata)
9
+ VALUES (@source_type, @source_id, @target_type, @target_id, @synapse_type, @weight, @metadata)
10
10
  `),
11
11
  getById: db.prepare('SELECT * FROM synapses WHERE id = ?'),
12
12
  delete: db.prepare('DELETE FROM synapses WHERE id = ?'),
13
13
  getOutgoing: db.prepare('SELECT * FROM synapses WHERE source_type = ? AND source_id = ? ORDER BY weight DESC'),
14
14
  getIncoming: db.prepare('SELECT * FROM synapses WHERE target_type = ? AND target_id = ? ORDER BY weight DESC'),
15
- findConnected: db.prepare(`
16
- SELECT * FROM synapses
17
- WHERE (source_type = ? AND source_id = ?) OR (target_type = ? AND target_id = ?)
18
- ORDER BY weight DESC
15
+ findConnected: db.prepare(`
16
+ SELECT * FROM synapses
17
+ WHERE (source_type = ? AND source_id = ?) OR (target_type = ? AND target_id = ?)
18
+ ORDER BY weight DESC
19
19
  `),
20
- findBySourceTarget: db.prepare(`
21
- SELECT * FROM synapses
22
- WHERE source_type = ? AND source_id = ? AND target_type = ? AND target_id = ? AND synapse_type = ?
20
+ findBySourceTarget: db.prepare(`
21
+ SELECT * FROM synapses
22
+ WHERE source_type = ? AND source_id = ? AND target_type = ? AND target_id = ? AND synapse_type = ?
23
23
  `),
24
- findInactiveSince: db.prepare(`
25
- SELECT * FROM synapses WHERE last_activated_at < ?
24
+ findInactiveSince: db.prepare(`
25
+ SELECT * FROM synapses WHERE last_activated_at < ?
26
26
  `),
27
- countNodes: db.prepare(`
28
- SELECT COUNT(*) as count FROM (
29
- SELECT source_type, source_id FROM synapses
30
- UNION
31
- SELECT target_type, target_id FROM synapses
32
- )
27
+ countNodes: db.prepare(`
28
+ SELECT COUNT(*) as count FROM (
29
+ SELECT source_type, source_id FROM synapses
30
+ UNION
31
+ SELECT target_type, target_id FROM synapses
32
+ )
33
33
  `),
34
34
  avgWeight: db.prepare('SELECT AVG(weight) as avg_weight FROM synapses'),
35
35
  countByType: db.prepare('SELECT synapse_type, COUNT(*) as count FROM synapses GROUP BY synapse_type'),