@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,38 +0,0 @@
1
- import type { SynapseRepository } from '../db/repositories/synapse.repository.js';
2
-
3
- export interface DecayConfig {
4
- decayHalfLifeDays: number;
5
- decayAfterDays: number;
6
- pruneThreshold: number;
7
- }
8
-
9
- export function timeDecayFactor(lastActivatedAt: string, halfLifeDays: number): number {
10
- const now = Date.now();
11
- const activated = new Date(lastActivatedAt).getTime();
12
- const ageDays = (now - activated) / (1000 * 60 * 60 * 24);
13
- return Math.pow(0.5, ageDays / halfLifeDays);
14
- }
15
-
16
- export function decayAll(repo: SynapseRepository, config: DecayConfig): { decayed: number; pruned: number } {
17
- const cutoff = new Date();
18
- cutoff.setDate(cutoff.getDate() - config.decayAfterDays);
19
-
20
- const stale = repo.findInactiveSince(cutoff.toISOString());
21
- let pruned = 0;
22
- let decayed = 0;
23
-
24
- for (const synapse of stale) {
25
- const factor = timeDecayFactor(synapse.last_activated_at, config.decayHalfLifeDays);
26
- const newWeight = synapse.weight * factor;
27
-
28
- if (newWeight < config.pruneThreshold) {
29
- repo.delete(synapse.id);
30
- pruned++;
31
- } else {
32
- repo.update(synapse.id, { weight: newWeight });
33
- decayed++;
34
- }
35
- }
36
-
37
- return { decayed, pruned };
38
- }
@@ -1,69 +0,0 @@
1
- import type { SynapseRecord, NodeType, SynapseType } from '../types/synapse.types.js';
2
- import type { SynapseRepository } from '../db/repositories/synapse.repository.js';
3
-
4
- export interface HebbianConfig {
5
- initialWeight: number;
6
- learningRate: number;
7
- pruneThreshold: number;
8
- }
9
-
10
- export interface NodeRef {
11
- type: NodeType;
12
- id: number;
13
- }
14
-
15
- export function strengthen(
16
- repo: SynapseRepository,
17
- source: NodeRef,
18
- target: NodeRef,
19
- synapseType: SynapseType,
20
- config: HebbianConfig,
21
- context?: Record<string, unknown>,
22
- ): SynapseRecord {
23
- const existing = repo.findBySourceTarget(
24
- source.type, source.id, target.type, target.id, synapseType,
25
- );
26
-
27
- if (existing) {
28
- // Hebbian: weight grows logarithmically, saturates at 1.0
29
- const newWeight = Math.min(
30
- 1.0,
31
- existing.weight + (1.0 - existing.weight) * config.learningRate,
32
- );
33
- repo.update(existing.id, {
34
- weight: newWeight,
35
- activation_count: existing.activation_count + 1,
36
- last_activated_at: new Date().toISOString(),
37
- });
38
- return { ...existing, weight: newWeight, activation_count: existing.activation_count + 1 };
39
- }
40
-
41
- const id = repo.create({
42
- source_type: source.type,
43
- source_id: source.id,
44
- target_type: target.type,
45
- target_id: target.id,
46
- synapse_type: synapseType,
47
- weight: config.initialWeight,
48
- metadata: context ? JSON.stringify(context) : null,
49
- });
50
-
51
- return repo.getById(id)!;
52
- }
53
-
54
- export function weaken(
55
- repo: SynapseRepository,
56
- synapseId: number,
57
- config: HebbianConfig,
58
- factor: number = 0.5,
59
- ): void {
60
- const synapse = repo.getById(synapseId);
61
- if (!synapse) return;
62
-
63
- const newWeight = synapse.weight * factor;
64
- if (newWeight < config.pruneThreshold) {
65
- repo.delete(synapseId);
66
- } else {
67
- repo.update(synapseId, { weight: newWeight });
68
- }
69
- }
@@ -1,81 +0,0 @@
1
- import type { NodeType, SynapseRecord } from '../types/synapse.types.js';
2
- import type { SynapseRepository } from '../db/repositories/synapse.repository.js';
3
-
4
- export interface PathNode {
5
- type: NodeType;
6
- id: number;
7
- }
8
-
9
- export interface SynapsePath {
10
- from: PathNode;
11
- to: PathNode;
12
- synapses: SynapseRecord[];
13
- totalWeight: number;
14
- hops: number;
15
- }
16
-
17
- export function findPath(
18
- repo: SynapseRepository,
19
- from: PathNode,
20
- to: PathNode,
21
- maxDepth: number = 5,
22
- ): SynapsePath | null {
23
- const visited = new Set<string>();
24
-
25
- const queue: Array<{
26
- node: PathNode;
27
- path: SynapseRecord[];
28
- totalWeight: number;
29
- }> = [{ node: from, path: [], totalWeight: 1.0 }];
30
-
31
- let bestPath: SynapsePath | null = null;
32
-
33
- while (queue.length > 0) {
34
- const current = queue.shift()!;
35
- const key = `${current.node.type}:${current.node.id}`;
36
-
37
- if (visited.has(key)) continue;
38
- visited.add(key);
39
-
40
- if (current.node.type === to.type && current.node.id === to.id) {
41
- if (!bestPath || current.totalWeight > bestPath.totalWeight) {
42
- bestPath = {
43
- from,
44
- to,
45
- synapses: current.path,
46
- totalWeight: current.totalWeight,
47
- hops: current.path.length,
48
- };
49
- }
50
- continue;
51
- }
52
-
53
- if (current.path.length >= maxDepth) continue;
54
-
55
- const outgoing = repo.getOutgoing(current.node.type, current.node.id);
56
- for (const synapse of outgoing) {
57
- const targetKey = `${synapse.target_type}:${synapse.target_id}`;
58
- if (!visited.has(targetKey)) {
59
- queue.push({
60
- node: { type: synapse.target_type, id: synapse.target_id },
61
- path: [...current.path, synapse],
62
- totalWeight: current.totalWeight * synapse.weight,
63
- });
64
- }
65
- }
66
-
67
- const incoming = repo.getIncoming(current.node.type, current.node.id);
68
- for (const synapse of incoming) {
69
- const sourceKey = `${synapse.source_type}:${synapse.source_id}`;
70
- if (!visited.has(sourceKey)) {
71
- queue.push({
72
- node: { type: synapse.source_type, id: synapse.source_id },
73
- path: [...current.path, synapse],
74
- totalWeight: current.totalWeight * synapse.weight,
75
- });
76
- }
77
- }
78
- }
79
-
80
- return bestPath;
81
- }
@@ -1,113 +0,0 @@
1
- import type { SynapsesConfig } from '../types/config.types.js';
2
- import type { NodeType, SynapseType, SynapseRecord, NetworkStats } from '../types/synapse.types.js';
3
- import type { SynapseRepository } from '../db/repositories/synapse.repository.js';
4
- import { strengthen, weaken, type NodeRef } from './hebbian.js';
5
- import { decayAll } from './decay.js';
6
- import { spreadingActivation, type ActivationResult } from './activation.js';
7
- import { findPath, type SynapsePath } from './pathfinder.js';
8
- import { getLogger } from '../utils/logger.js';
9
-
10
- export class SynapseManager {
11
- private logger = getLogger();
12
-
13
- constructor(
14
- private repo: SynapseRepository,
15
- private config: SynapsesConfig,
16
- ) {}
17
-
18
- strengthen(
19
- source: NodeRef,
20
- target: NodeRef,
21
- synapseType: SynapseType,
22
- context?: Record<string, unknown>,
23
- ): SynapseRecord {
24
- this.logger.debug(`Strengthening synapse ${source.type}:${source.id} --${synapseType}--> ${target.type}:${target.id}`);
25
- return strengthen(this.repo, source, target, synapseType, {
26
- initialWeight: this.config.initialWeight,
27
- learningRate: this.config.learningRate,
28
- pruneThreshold: this.config.pruneThreshold,
29
- }, context);
30
- }
31
-
32
- weaken(synapseId: number, factor: number = 0.5): void {
33
- this.logger.debug(`Weakening synapse ${synapseId} by factor ${factor}`);
34
- weaken(this.repo, synapseId, {
35
- initialWeight: this.config.initialWeight,
36
- learningRate: this.config.learningRate,
37
- pruneThreshold: this.config.pruneThreshold,
38
- }, factor);
39
- }
40
-
41
- find(
42
- source: NodeRef,
43
- target: NodeRef,
44
- synapseType: SynapseType,
45
- ): SynapseRecord | undefined {
46
- return this.repo.findBySourceTarget(
47
- source.type, source.id, target.type, target.id, synapseType,
48
- );
49
- }
50
-
51
- activate(
52
- startNode: NodeRef,
53
- maxDepth?: number,
54
- minWeight?: number,
55
- ): ActivationResult[] {
56
- return spreadingActivation(
57
- this.repo,
58
- startNode,
59
- maxDepth ?? this.config.maxDepth,
60
- minWeight ?? this.config.minActivationWeight,
61
- );
62
- }
63
-
64
- findPath(from: NodeRef, to: NodeRef, maxDepth?: number): SynapsePath | null {
65
- return findPath(this.repo, from, to, maxDepth ?? this.config.maxDepth + 2);
66
- }
67
-
68
- runDecay(): { decayed: number; pruned: number } {
69
- this.logger.info('Running synapse decay cycle');
70
- const result = decayAll(this.repo, {
71
- decayHalfLifeDays: this.config.decayHalfLifeDays,
72
- decayAfterDays: this.config.decayAfterDays,
73
- pruneThreshold: this.config.pruneThreshold,
74
- });
75
- this.logger.info(`Decay complete: ${result.decayed} decayed, ${result.pruned} pruned`);
76
- return result;
77
- }
78
-
79
- getErrorContext(errorId: number): {
80
- solutions: ActivationResult[];
81
- relatedErrors: ActivationResult[];
82
- relevantModules: ActivationResult[];
83
- preventionRules: ActivationResult[];
84
- insights: ActivationResult[];
85
- } {
86
- const all = this.activate({ type: 'error', id: errorId });
87
- return {
88
- solutions: all.filter(a => a.node.type === 'solution'),
89
- relatedErrors: all.filter(a => a.node.type === 'error'),
90
- relevantModules: all.filter(a => a.node.type === 'code_module'),
91
- preventionRules: all.filter(a => a.node.type === 'rule'),
92
- insights: all.filter(a => a.node.type === 'insight'),
93
- };
94
- }
95
-
96
- getStrongestSynapses(limit: number = 20): SynapseRecord[] {
97
- return this.repo.topByWeight(limit);
98
- }
99
-
100
- getDiverseSynapses(perType: number = 25): SynapseRecord[] {
101
- return this.repo.topDiverse(perType);
102
- }
103
-
104
- getNetworkStats(): NetworkStats {
105
- return {
106
- totalNodes: this.repo.countNodes(),
107
- totalSynapses: this.repo.totalCount(),
108
- avgWeight: this.repo.avgWeight(),
109
- nodesByType: {} as Record<NodeType, number>,
110
- synapsesByType: this.repo.countByType() as Record<SynapseType, number>,
111
- };
112
- }
113
- }
@@ -1,52 +0,0 @@
1
- export interface CodeModuleRecord {
2
- id: number;
3
- project_id: number;
4
- name: string;
5
- file_path: string;
6
- language: string;
7
- fingerprint: string;
8
- description: string | null;
9
- source_hash: string;
10
- lines_of_code: number;
11
- complexity: number | null;
12
- reusability_score: number;
13
- created_at: string;
14
- updated_at: string;
15
- }
16
-
17
- export interface ModuleUsage {
18
- id: number;
19
- module_id: number;
20
- used_in_project_id: number;
21
- used_in_file: string;
22
- usage_type: string;
23
- first_used: string;
24
- last_used: string;
25
- }
26
-
27
- export interface ModuleSimilarity {
28
- id: number;
29
- module_a_id: number;
30
- module_b_id: number;
31
- similarity_score: number;
32
- computed_at: string;
33
- }
34
-
35
- export interface CodeUnit {
36
- name: string;
37
- filePath: string;
38
- language: string;
39
- source: string;
40
- exports: ExportInfo[];
41
- }
42
-
43
- export interface ExportInfo {
44
- name: string;
45
- type: 'function' | 'class' | 'constant' | 'type' | 'interface' | 'variable';
46
- }
47
-
48
- export interface ReusabilitySignal {
49
- name: string;
50
- score: number;
51
- reason: string;
52
- }
@@ -1,103 +0,0 @@
1
- export interface IpcConfig {
2
- pipeName: string;
3
- timeout: number;
4
- }
5
-
6
- export interface LearningConfig {
7
- intervalMs: number;
8
- minOccurrences: number;
9
- minSuccessRate: number;
10
- minConfidence: number;
11
- pruneThreshold: number;
12
- maxRejectionRate: number;
13
- decayHalfLifeDays: number;
14
- }
15
-
16
- export interface TerminalConfig {
17
- staleTimeout: number;
18
- maxConnected: number;
19
- }
20
-
21
- export interface MatchingConfig {
22
- fingerprintFields: string[];
23
- similarityThreshold: number;
24
- maxResults: number;
25
- crossProjectMatching: boolean;
26
- crossProjectWeight: number;
27
- }
28
-
29
- export interface CodeConfig {
30
- supportedLanguages: string[];
31
- maxModuleSize: number;
32
- similarityThreshold: number;
33
- }
34
-
35
- export interface SynapsesConfig {
36
- initialWeight: number;
37
- learningRate: number;
38
- decayHalfLifeDays: number;
39
- pruneThreshold: number;
40
- decayAfterDays: number;
41
- maxDepth: number;
42
- minActivationWeight: number;
43
- }
44
-
45
- export interface ResearchConfig {
46
- intervalMs: number;
47
- initialDelayMs: number;
48
- minDataPoints: number;
49
- trendWindowDays: number;
50
- gapMinOccurrences: number;
51
- synergyMinWeight: number;
52
- templateMinAdaptations: number;
53
- insightExpiryDays: number;
54
- }
55
-
56
- export interface LogConfig {
57
- level: string;
58
- file: string;
59
- maxSize: number;
60
- maxFiles: number;
61
- }
62
-
63
- export interface RetentionConfig {
64
- errorDays: number;
65
- solutionDays: number;
66
- insightDays: number;
67
- }
68
-
69
- export interface ApiConfig {
70
- port: number;
71
- enabled: boolean;
72
- apiKey?: string;
73
- }
74
-
75
- export interface McpHttpConfig {
76
- port: number;
77
- enabled: boolean;
78
- }
79
-
80
- export interface EmbeddingsConfig {
81
- enabled: boolean;
82
- modelName: string;
83
- cacheDir: string;
84
- sweepIntervalMs: number;
85
- batchSize: number;
86
- }
87
-
88
- export interface BrainConfig {
89
- dataDir: string;
90
- dbPath: string;
91
- ipc: IpcConfig;
92
- api: ApiConfig;
93
- mcpHttp: McpHttpConfig;
94
- embeddings: EmbeddingsConfig;
95
- learning: LearningConfig;
96
- terminal: TerminalConfig;
97
- matching: MatchingConfig;
98
- code: CodeConfig;
99
- synapses: SynapsesConfig;
100
- research: ResearchConfig;
101
- log: LogConfig;
102
- retention: RetentionConfig;
103
- }
@@ -1,67 +0,0 @@
1
- export interface ErrorRecord {
2
- id: number;
3
- project_id: number;
4
- terminal_id: number | null;
5
- fingerprint: string;
6
- type: string;
7
- message: string;
8
- raw_output: string;
9
- context: string | null;
10
- file_path: string | null;
11
- line_number: number | null;
12
- column_number: number | null;
13
- occurrence_count: number;
14
- first_seen: string;
15
- last_seen: string;
16
- resolved: number;
17
- resolved_at: string | null;
18
- }
19
-
20
- export interface StackFrame {
21
- file: string;
22
- line: number;
23
- column: number | null;
24
- function_name: string | null;
25
- source: string | null;
26
- }
27
-
28
- export interface ParsedError {
29
- type: string;
30
- message: string;
31
- fingerprint: string;
32
- stackFrames: StackFrame[];
33
- filePath: string | null;
34
- lineNumber: number | null;
35
- columnNumber: number | null;
36
- context: string | null;
37
- }
38
-
39
- export interface ErrorParser {
40
- name: string;
41
- canParse(raw: string): boolean;
42
- parse(raw: string): ParsedError | null;
43
- }
44
-
45
- export interface MatchSignal {
46
- field: string;
47
- similarity: number;
48
- weight: number;
49
- }
50
-
51
- export interface MatchResult {
52
- errorId: number;
53
- score: number;
54
- signals: MatchSignal[];
55
- }
56
-
57
- export interface ErrorSolutionPair {
58
- error: ErrorRecord;
59
- solutionIds: number[];
60
- }
61
-
62
- export interface Pattern {
63
- type: string;
64
- message: string;
65
- count: number;
66
- lastSeen: string;
67
- }
@@ -1,8 +0,0 @@
1
- export interface IpcMessage {
2
- id: string;
3
- type: 'request' | 'response' | 'notification';
4
- method?: string;
5
- params?: unknown;
6
- result?: unknown;
7
- error?: { code: number; message: string };
8
- }
@@ -1,53 +0,0 @@
1
- export interface HookInput {
2
- tool: string;
3
- arguments: Record<string, unknown>;
4
- }
5
-
6
- export interface ReportErrorParams {
7
- project: string;
8
- error_output: string;
9
- file_path?: string;
10
- terminal_id?: string;
11
- }
12
-
13
- export interface GetSolutionsParams {
14
- error_output?: string;
15
- error_id?: number;
16
- project?: string;
17
- }
18
-
19
- export interface ApplySolutionParams {
20
- error_id: number;
21
- solution_id: number;
22
- terminal_id?: string;
23
- }
24
-
25
- export interface RegisterModuleParams {
26
- project: string;
27
- name: string;
28
- file_path: string;
29
- language: string;
30
- source: string;
31
- description?: string;
32
- }
33
-
34
- export interface SearchModulesParams {
35
- query: string;
36
- language?: string;
37
- project?: string;
38
- limit?: number;
39
- }
40
-
41
- export interface GetInsightsParams {
42
- project?: string;
43
- type?: string;
44
- active_only?: boolean;
45
- limit?: number;
46
- }
47
-
48
- export interface GetNetworkParams {
49
- node_type: string;
50
- node_id: number;
51
- depth?: number;
52
- min_weight?: number;
53
- }
@@ -1,28 +0,0 @@
1
- export type InsightType = 'pattern' | 'correlation' | 'suggestion' | 'warning' | 'optimization' | 'trend' | 'gap' | 'synergy' | 'template_candidate' | 'project_suggestion';
2
-
3
- export interface InsightRecord {
4
- id: number;
5
- type: InsightType;
6
- title: string;
7
- description: string;
8
- evidence: string;
9
- priority: number;
10
- project_id: number | null;
11
- active: number;
12
- expires_at: string | null;
13
- created_at: string;
14
- }
15
-
16
- export interface ResearchCycleResult {
17
- insightsGenerated: number;
18
- patternsFound: number;
19
- correlationsFound: number;
20
- duration: number;
21
- }
22
-
23
- export interface ProjectTemplateSuggestion {
24
- name: string;
25
- description: string;
26
- basedOn: string[];
27
- confidence: number;
28
- }
@@ -1,30 +0,0 @@
1
- export interface SolutionRecord {
2
- id: number;
3
- description: string;
4
- commands: string | null;
5
- code_change: string | null;
6
- source: string;
7
- confidence: number;
8
- success_count: number;
9
- fail_count: number;
10
- created_at: string;
11
- updated_at: string;
12
- }
13
-
14
- export interface ErrorSolution {
15
- id: number;
16
- error_id: number;
17
- solution_id: number;
18
- applied_at: string | null;
19
- success: number | null;
20
- }
21
-
22
- export interface SolutionAttempt {
23
- id: number;
24
- error_solution_id: number;
25
- terminal_id: number | null;
26
- attempted_at: string;
27
- success: number;
28
- output: string | null;
29
- duration_ms: number | null;
30
- }
@@ -1,50 +0,0 @@
1
- export type NodeType = 'error' | 'solution' | 'code_module' | 'rule' | 'antipattern' | 'project' | 'insight';
2
-
3
- export type SynapseType =
4
- | 'solves'
5
- | 'causes'
6
- | 'similar_to'
7
- | 'uses_module'
8
- | 'depends_on'
9
- | 'derived_from'
10
- | 'co_occurs'
11
- | 'prevents'
12
- | 'improves'
13
- | 'generalizes'
14
- | 'cross_project';
15
-
16
- export interface SynapseRecord {
17
- id: number;
18
- source_type: NodeType;
19
- source_id: number;
20
- target_type: NodeType;
21
- target_id: number;
22
- synapse_type: SynapseType;
23
- weight: number;
24
- activation_count: number;
25
- last_activated_at: string;
26
- metadata: string | null;
27
- created_at: string;
28
- updated_at: string;
29
- }
30
-
31
- export interface ActivationResult {
32
- nodeType: NodeType;
33
- nodeId: number;
34
- activationStrength: number;
35
- path: SynapsePath;
36
- }
37
-
38
- export interface SynapsePath {
39
- nodes: Array<{ type: NodeType; id: number }>;
40
- totalWeight: number;
41
- hops: number;
42
- }
43
-
44
- export interface NetworkStats {
45
- totalNodes: number;
46
- totalSynapses: number;
47
- avgWeight: number;
48
- nodesByType: Record<NodeType, number>;
49
- synapsesByType: Record<SynapseType, number>;
50
- }