@timmeck/brain 1.8.5 → 2.0.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 (221) hide show
  1. package/.dockerignore +11 -0
  2. package/Dockerfile +21 -0
  3. package/README.md +19 -0
  4. package/assets/brain-avatar-256.png +0 -0
  5. package/assets/brain-avatar-512.png +0 -0
  6. package/assets/brain-avatar.png +0 -0
  7. package/brain.log +1164 -0
  8. package/{src/cli/commands/dashboard.ts → dashboard.html} +688 -807
  9. package/dist/api/server.d.ts +4 -18
  10. package/dist/api/server.js +4 -173
  11. package/dist/api/server.js.map +1 -1
  12. package/dist/brain.d.ts +6 -0
  13. package/dist/brain.js +56 -4
  14. package/dist/brain.js.map +1 -1
  15. package/dist/cli/colors.d.ts +4 -25
  16. package/dist/cli/colors.js +3 -89
  17. package/dist/cli/colors.js.map +1 -1
  18. package/dist/cli/commands/peers.d.ts +2 -0
  19. package/dist/cli/commands/peers.js +38 -0
  20. package/dist/cli/commands/peers.js.map +1 -0
  21. package/dist/cli/commands/start.js +54 -17
  22. package/dist/cli/commands/start.js.map +1 -1
  23. package/dist/db/connection.d.ts +1 -2
  24. package/dist/db/connection.js +1 -18
  25. package/dist/db/connection.js.map +1 -1
  26. package/dist/index.js +3 -1
  27. package/dist/index.js.map +1 -1
  28. package/dist/ipc/__tests__/protocol.test.d.ts +1 -0
  29. package/dist/ipc/__tests__/protocol.test.js +117 -0
  30. package/dist/ipc/__tests__/protocol.test.js.map +1 -0
  31. package/dist/ipc/client.d.ts +1 -16
  32. package/dist/ipc/client.js +1 -100
  33. package/dist/ipc/client.js.map +1 -1
  34. package/dist/ipc/protocol.d.ts +1 -8
  35. package/dist/ipc/protocol.js +1 -28
  36. package/dist/ipc/protocol.js.map +1 -1
  37. package/dist/ipc/router.js +8 -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/mcp/http-server.d.ts +1 -7
  43. package/dist/mcp/http-server.js +6 -117
  44. package/dist/mcp/http-server.js.map +1 -1
  45. package/dist/mcp/server.js +5 -61
  46. package/dist/mcp/server.js.map +1 -1
  47. package/dist/signals/__tests__/fingerprint.test.d.ts +1 -0
  48. package/dist/signals/__tests__/fingerprint.test.js +118 -0
  49. package/dist/signals/__tests__/fingerprint.test.js.map +1 -0
  50. package/dist/types/ipc.types.d.ts +1 -11
  51. package/dist/utils/__tests__/hash.test.d.ts +1 -0
  52. package/dist/utils/__tests__/hash.test.js +32 -0
  53. package/dist/utils/__tests__/hash.test.js.map +1 -0
  54. package/dist/utils/__tests__/paths.test.d.ts +1 -0
  55. package/dist/utils/__tests__/paths.test.js +75 -0
  56. package/dist/utils/__tests__/paths.test.js.map +1 -0
  57. package/dist/utils/events.d.ts +4 -8
  58. package/dist/utils/events.js +2 -14
  59. package/dist/utils/events.js.map +1 -1
  60. package/dist/utils/hash.d.ts +1 -1
  61. package/dist/utils/hash.js +1 -4
  62. package/dist/utils/hash.js.map +1 -1
  63. package/dist/utils/logger.d.ts +3 -2
  64. package/dist/utils/logger.js +8 -35
  65. package/dist/utils/logger.js.map +1 -1
  66. package/dist/utils/paths.d.ts +2 -1
  67. package/dist/utils/paths.js +4 -13
  68. package/dist/utils/paths.js.map +1 -1
  69. package/gen_avatar.py +142 -0
  70. package/package.json +2 -1
  71. package/BRAIN_PLAN.md +0 -3324
  72. package/src/api/server.ts +0 -395
  73. package/src/brain.ts +0 -266
  74. package/src/cli/colors.ts +0 -116
  75. package/src/cli/commands/config.ts +0 -169
  76. package/src/cli/commands/doctor.ts +0 -124
  77. package/src/cli/commands/explain.ts +0 -83
  78. package/src/cli/commands/export.ts +0 -31
  79. package/src/cli/commands/import.ts +0 -199
  80. package/src/cli/commands/insights.ts +0 -65
  81. package/src/cli/commands/learn.ts +0 -24
  82. package/src/cli/commands/modules.ts +0 -53
  83. package/src/cli/commands/network.ts +0 -67
  84. package/src/cli/commands/projects.ts +0 -42
  85. package/src/cli/commands/query.ts +0 -120
  86. package/src/cli/commands/start.ts +0 -62
  87. package/src/cli/commands/status.ts +0 -75
  88. package/src/cli/commands/stop.ts +0 -34
  89. package/src/cli/ipc-helper.ts +0 -22
  90. package/src/cli/update-check.ts +0 -63
  91. package/src/code/analyzer.ts +0 -117
  92. package/src/code/fingerprint.ts +0 -87
  93. package/src/code/matcher.ts +0 -129
  94. package/src/code/parsers/generic.ts +0 -29
  95. package/src/code/parsers/python.ts +0 -54
  96. package/src/code/parsers/typescript.ts +0 -65
  97. package/src/code/registry.ts +0 -60
  98. package/src/code/scorer.ts +0 -120
  99. package/src/config.ts +0 -135
  100. package/src/dashboard/server.ts +0 -142
  101. package/src/db/connection.ts +0 -22
  102. package/src/db/migrations/001_core_schema.ts +0 -120
  103. package/src/db/migrations/002_learning_schema.ts +0 -38
  104. package/src/db/migrations/003_code_schema.ts +0 -53
  105. package/src/db/migrations/004_synapses_schema.ts +0 -57
  106. package/src/db/migrations/005_fts_indexes.ts +0 -78
  107. package/src/db/migrations/006_synapses_phase3.ts +0 -17
  108. package/src/db/migrations/007_feedback.ts +0 -13
  109. package/src/db/migrations/008_git_integration.ts +0 -38
  110. package/src/db/migrations/009_embeddings.ts +0 -8
  111. package/src/db/migrations/index.ts +0 -70
  112. package/src/db/repositories/antipattern.repository.ts +0 -66
  113. package/src/db/repositories/code-module.repository.ts +0 -142
  114. package/src/db/repositories/error.repository.ts +0 -189
  115. package/src/db/repositories/insight.repository.ts +0 -99
  116. package/src/db/repositories/notification.repository.ts +0 -66
  117. package/src/db/repositories/project.repository.ts +0 -93
  118. package/src/db/repositories/rule.repository.ts +0 -108
  119. package/src/db/repositories/solution.repository.ts +0 -154
  120. package/src/db/repositories/synapse.repository.ts +0 -163
  121. package/src/db/repositories/terminal.repository.ts +0 -101
  122. package/src/embeddings/engine.ts +0 -238
  123. package/src/hooks/post-tool-use.ts +0 -92
  124. package/src/hooks/post-write.ts +0 -129
  125. package/src/index.ts +0 -63
  126. package/src/ipc/client.ts +0 -118
  127. package/src/ipc/protocol.ts +0 -35
  128. package/src/ipc/router.ts +0 -133
  129. package/src/ipc/server.ts +0 -176
  130. package/src/learning/confidence-scorer.ts +0 -80
  131. package/src/learning/decay.ts +0 -46
  132. package/src/learning/learning-engine.ts +0 -170
  133. package/src/learning/pattern-extractor.ts +0 -90
  134. package/src/learning/rule-generator.ts +0 -74
  135. package/src/main.rs:10:5 +0 -0
  136. package/src/matching/error-matcher.ts +0 -166
  137. package/src/matching/fingerprint.ts +0 -34
  138. package/src/matching/similarity.ts +0 -61
  139. package/src/matching/tfidf.ts +0 -74
  140. package/src/matching/tokenizer.ts +0 -41
  141. package/src/mcp/auto-detect.ts +0 -93
  142. package/src/mcp/http-server.ts +0 -140
  143. package/src/mcp/server.ts +0 -73
  144. package/src/mcp/tools.ts +0 -328
  145. package/src/parsing/error-parser.ts +0 -28
  146. package/src/parsing/parsers/compiler.ts +0 -93
  147. package/src/parsing/parsers/generic.ts +0 -28
  148. package/src/parsing/parsers/go.ts +0 -97
  149. package/src/parsing/parsers/node.ts +0 -69
  150. package/src/parsing/parsers/python.ts +0 -62
  151. package/src/parsing/parsers/rust.ts +0 -50
  152. package/src/parsing/parsers/shell.ts +0 -42
  153. package/src/parsing/types.ts +0 -47
  154. package/src/research/gap-analyzer.ts +0 -135
  155. package/src/research/insight-generator.ts +0 -123
  156. package/src/research/research-engine.ts +0 -116
  157. package/src/research/synergy-detector.ts +0 -126
  158. package/src/research/template-extractor.ts +0 -130
  159. package/src/research/trend-analyzer.ts +0 -127
  160. package/src/services/analytics.service.ts +0 -226
  161. package/src/services/code.service.ts +0 -271
  162. package/src/services/error.service.ts +0 -266
  163. package/src/services/git.service.ts +0 -132
  164. package/src/services/notification.service.ts +0 -41
  165. package/src/services/prevention.service.ts +0 -159
  166. package/src/services/research.service.ts +0 -98
  167. package/src/services/solution.service.ts +0 -174
  168. package/src/services/synapse.service.ts +0 -59
  169. package/src/services/terminal.service.ts +0 -81
  170. package/src/synapses/activation.ts +0 -80
  171. package/src/synapses/decay.ts +0 -38
  172. package/src/synapses/hebbian.ts +0 -69
  173. package/src/synapses/pathfinder.ts +0 -81
  174. package/src/synapses/synapse-manager.ts +0 -113
  175. package/src/types/code.types.ts +0 -52
  176. package/src/types/config.types.ts +0 -103
  177. package/src/types/error.types.ts +0 -67
  178. package/src/types/ipc.types.ts +0 -8
  179. package/src/types/mcp.types.ts +0 -53
  180. package/src/types/research.types.ts +0 -28
  181. package/src/types/solution.types.ts +0 -30
  182. package/src/types/synapse.types.ts +0 -50
  183. package/src/utils/events.ts +0 -45
  184. package/src/utils/hash.ts +0 -5
  185. package/src/utils/logger.ts +0 -48
  186. package/src/utils/paths.ts +0 -19
  187. package/tests/e2e/test_code_intelligence.py +0 -1015
  188. package/tests/e2e/test_error_memory.py +0 -451
  189. package/tests/e2e/test_full_integration.py +0 -534
  190. package/tests/fixtures/code-modules/modules.ts +0 -83
  191. package/tests/fixtures/errors/go.ts +0 -9
  192. package/tests/fixtures/errors/node.ts +0 -24
  193. package/tests/fixtures/errors/python.ts +0 -21
  194. package/tests/fixtures/errors/rust.ts +0 -25
  195. package/tests/fixtures/errors/shell.ts +0 -15
  196. package/tests/fixtures/solutions/solutions.ts +0 -27
  197. package/tests/helpers/setup-db.ts +0 -52
  198. package/tests/integration/code-flow.test.ts +0 -86
  199. package/tests/integration/error-flow.test.ts +0 -83
  200. package/tests/integration/ipc-flow.test.ts +0 -166
  201. package/tests/integration/learning-cycle.test.ts +0 -82
  202. package/tests/integration/synapse-flow.test.ts +0 -117
  203. package/tests/unit/code/analyzer.test.ts +0 -58
  204. package/tests/unit/code/fingerprint.test.ts +0 -51
  205. package/tests/unit/code/scorer.test.ts +0 -55
  206. package/tests/unit/learning/confidence-scorer.test.ts +0 -60
  207. package/tests/unit/learning/decay.test.ts +0 -45
  208. package/tests/unit/learning/pattern-extractor.test.ts +0 -50
  209. package/tests/unit/matching/error-matcher.test.ts +0 -69
  210. package/tests/unit/matching/fingerprint.test.ts +0 -47
  211. package/tests/unit/matching/similarity.test.ts +0 -65
  212. package/tests/unit/matching/tfidf.test.ts +0 -71
  213. package/tests/unit/matching/tokenizer.test.ts +0 -83
  214. package/tests/unit/parsing/parsers.test.ts +0 -113
  215. package/tests/unit/research/gap-analyzer.test.ts +0 -45
  216. package/tests/unit/research/trend-analyzer.test.ts +0 -45
  217. package/tests/unit/synapses/activation.test.ts +0 -80
  218. package/tests/unit/synapses/decay.test.ts +0 -27
  219. package/tests/unit/synapses/hebbian.test.ts +0 -96
  220. package/tests/unit/synapses/pathfinder.test.ts +0 -72
  221. package/tsconfig.json +0 -18
@@ -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
- }
@@ -1,45 +0,0 @@
1
- import { EventEmitter } from 'node:events';
2
-
3
- export interface BrainEvents {
4
- 'error:reported': { errorId: number; projectId: number; fingerprint: string };
5
- 'error:resolved': { errorId: number; solutionId: number };
6
- 'solution:applied': { errorId: number; solutionId: number; success: boolean };
7
- 'solution:created': { solutionId: number };
8
- 'module:registered': { moduleId: number; projectId: number };
9
- 'module:updated': { moduleId: number };
10
- 'synapse:created': { synapseId: number; sourceType: string; targetType: string };
11
- 'synapse:strengthened': { synapseId: number; newWeight: number };
12
- 'insight:created': { insightId: number; type: string };
13
- 'rule:learned': { ruleId: number; pattern: string };
14
- 'terminal:connected': { terminalId: number; uuid: string };
15
- 'terminal:disconnected': { terminalId: number };
16
- }
17
-
18
- export type BrainEventName = keyof BrainEvents;
19
-
20
- export class TypedEventBus extends EventEmitter {
21
- emit<K extends BrainEventName>(event: K, data: BrainEvents[K]): boolean {
22
- return super.emit(event, data);
23
- }
24
-
25
- on<K extends BrainEventName>(event: K, listener: (data: BrainEvents[K]) => void): this {
26
- return super.on(event, listener);
27
- }
28
-
29
- once<K extends BrainEventName>(event: K, listener: (data: BrainEvents[K]) => void): this {
30
- return super.once(event, listener);
31
- }
32
-
33
- off<K extends BrainEventName>(event: K, listener: (data: BrainEvents[K]) => void): this {
34
- return super.off(event, listener);
35
- }
36
- }
37
-
38
- let busInstance: TypedEventBus | null = null;
39
-
40
- export function getEventBus(): TypedEventBus {
41
- if (!busInstance) {
42
- busInstance = new TypedEventBus();
43
- }
44
- return busInstance;
45
- }
package/src/utils/hash.ts DELETED
@@ -1,5 +0,0 @@
1
- import { createHash } from 'node:crypto';
2
-
3
- export function sha256(input: string): string {
4
- return createHash('sha256').update(input).digest('hex');
5
- }
@@ -1,48 +0,0 @@
1
- import winston from 'winston';
2
- import path from 'node:path';
3
- import { getDataDir } from './paths.js';
4
-
5
- const { combine, timestamp, printf, colorize } = winston.format;
6
-
7
- const logFormat = printf(({ level, message, timestamp, ...meta }) => {
8
- const metaStr = Object.keys(meta).length ? ` ${JSON.stringify(meta)}` : '';
9
- return `${timestamp} [${level}]${metaStr} ${message}`;
10
- });
11
-
12
- let loggerInstance: winston.Logger | null = null;
13
-
14
- export function createLogger(opts?: { level?: string; file?: string; maxSize?: number; maxFiles?: number }): winston.Logger {
15
- if (loggerInstance) return loggerInstance;
16
-
17
- const level = opts?.level ?? process.env['BRAIN_LOG_LEVEL'] ?? 'info';
18
- const logFile = opts?.file ?? path.join(getDataDir(), 'brain.log');
19
- const maxSize = opts?.maxSize ?? 10 * 1024 * 1024; // 10MB
20
- const maxFiles = opts?.maxFiles ?? 3;
21
-
22
- const transports: winston.transport[] = [
23
- new winston.transports.File({
24
- filename: logFile,
25
- maxsize: maxSize,
26
- maxFiles,
27
- format: combine(timestamp(), logFormat),
28
- }),
29
- ];
30
-
31
- if (process.env['NODE_ENV'] !== 'production') {
32
- transports.push(
33
- new winston.transports.Console({
34
- format: combine(colorize(), timestamp(), logFormat),
35
- })
36
- );
37
- }
38
-
39
- loggerInstance = winston.createLogger({ level, transports });
40
- return loggerInstance;
41
- }
42
-
43
- export function getLogger(): winston.Logger {
44
- if (!loggerInstance) {
45
- return createLogger();
46
- }
47
- return loggerInstance;
48
- }
@@ -1,19 +0,0 @@
1
- import path from 'node:path';
2
- import os from 'node:os';
3
-
4
- export function normalizePath(filePath: string): string {
5
- return filePath.replace(/\\/g, '/');
6
- }
7
-
8
- export function getDataDir(): string {
9
- const envDir = process.env['BRAIN_DATA_DIR'];
10
- if (envDir) return path.resolve(envDir);
11
- return path.join(os.homedir(), '.brain');
12
- }
13
-
14
- export function getPipeName(name: string = 'brain'): string {
15
- if (process.platform === 'win32') {
16
- return `\\\\.\\pipe\\${name}`;
17
- }
18
- return path.join(os.tmpdir(), `${name}.sock`);
19
- }