neuralbrain 0.0.0-stage → 0.0.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 (293) hide show
  1. package/.dockerignore +11 -0
  2. package/.env.example +245 -0
  3. package/Dockerfile +65 -0
  4. package/LICENSE +44 -0
  5. package/README.md +312 -2
  6. package/dist/ai/chat.d.ts +45 -0
  7. package/dist/ai/chat.d.ts.map +1 -0
  8. package/dist/ai/chat.js +153 -0
  9. package/dist/ai/chat.js.map +1 -0
  10. package/dist/ai/circuitBreaker.d.ts +35 -0
  11. package/dist/ai/circuitBreaker.d.ts.map +1 -0
  12. package/dist/ai/circuitBreaker.js +95 -0
  13. package/dist/ai/circuitBreaker.js.map +1 -0
  14. package/dist/ai/config.d.ts +88 -0
  15. package/dist/ai/config.d.ts.map +1 -0
  16. package/dist/ai/config.js +255 -0
  17. package/dist/ai/config.js.map +1 -0
  18. package/dist/ai/vendors.d.ts +58 -0
  19. package/dist/ai/vendors.d.ts.map +1 -0
  20. package/dist/ai/vendors.js +223 -0
  21. package/dist/ai/vendors.js.map +1 -0
  22. package/dist/app.d.ts +4 -0
  23. package/dist/app.d.ts.map +1 -0
  24. package/dist/app.js +1013 -0
  25. package/dist/app.js.map +1 -0
  26. package/dist/cli.d.ts +133 -0
  27. package/dist/cli.d.ts.map +1 -0
  28. package/dist/cli.js +912 -0
  29. package/dist/cli.js.map +1 -0
  30. package/dist/consolidation/candidates.d.ts +34 -0
  31. package/dist/consolidation/candidates.d.ts.map +1 -0
  32. package/dist/consolidation/candidates.js +150 -0
  33. package/dist/consolidation/candidates.js.map +1 -0
  34. package/dist/consolidation/fixtures.d.ts +25 -0
  35. package/dist/consolidation/fixtures.d.ts.map +1 -0
  36. package/dist/consolidation/fixtures.js +400 -0
  37. package/dist/consolidation/fixtures.js.map +1 -0
  38. package/dist/consolidation/gate.d.ts +39 -0
  39. package/dist/consolidation/gate.d.ts.map +1 -0
  40. package/dist/consolidation/gate.js +286 -0
  41. package/dist/consolidation/gate.js.map +1 -0
  42. package/dist/consolidation/runner.d.ts +63 -0
  43. package/dist/consolidation/runner.d.ts.map +1 -0
  44. package/dist/consolidation/runner.js +171 -0
  45. package/dist/consolidation/runner.js.map +1 -0
  46. package/dist/dashboard/clientScript.d.ts +2 -0
  47. package/dist/dashboard/clientScript.d.ts.map +1 -0
  48. package/dist/dashboard/clientScript.js +4212 -0
  49. package/dist/dashboard/clientScript.js.map +1 -0
  50. package/dist/dashboard/html.d.ts +2 -0
  51. package/dist/dashboard/html.d.ts.map +1 -0
  52. package/dist/dashboard/html.js +554 -0
  53. package/dist/dashboard/html.js.map +1 -0
  54. package/dist/dashboard/styles.d.ts +2 -0
  55. package/dist/dashboard/styles.d.ts.map +1 -0
  56. package/dist/dashboard/styles.js +1283 -0
  57. package/dist/dashboard/styles.js.map +1 -0
  58. package/dist/index.d.ts +3 -0
  59. package/dist/index.d.ts.map +1 -0
  60. package/dist/index.js +124 -0
  61. package/dist/index.js.map +1 -0
  62. package/dist/learning/embedWorker.d.ts +58 -0
  63. package/dist/learning/embedWorker.d.ts.map +1 -0
  64. package/dist/learning/embedWorker.js +552 -0
  65. package/dist/learning/embedWorker.js.map +1 -0
  66. package/dist/learning/embedding.d.ts +52 -0
  67. package/dist/learning/embedding.d.ts.map +1 -0
  68. package/dist/learning/embedding.js +511 -0
  69. package/dist/learning/embedding.js.map +1 -0
  70. package/dist/learning/engine.d.ts +20 -0
  71. package/dist/learning/engine.d.ts.map +1 -0
  72. package/dist/learning/engine.js +69 -0
  73. package/dist/learning/engine.js.map +1 -0
  74. package/dist/learning/search.d.ts +4 -0
  75. package/dist/learning/search.d.ts.map +1 -0
  76. package/dist/learning/search.js +509 -0
  77. package/dist/learning/search.js.map +1 -0
  78. package/dist/learning/storeMeta.d.ts +11 -0
  79. package/dist/learning/storeMeta.d.ts.map +1 -0
  80. package/dist/learning/storeMeta.js +100 -0
  81. package/dist/learning/storeMeta.js.map +1 -0
  82. package/dist/learning/types.d.ts +101 -0
  83. package/dist/learning/types.d.ts.map +1 -0
  84. package/dist/learning/types.js +3 -0
  85. package/dist/learning/types.js.map +1 -0
  86. package/dist/lib/brainHome.d.ts +28 -0
  87. package/dist/lib/brainHome.d.ts.map +1 -0
  88. package/dist/lib/brainHome.js +104 -0
  89. package/dist/lib/brainHome.js.map +1 -0
  90. package/dist/lib/db.d.ts +10 -0
  91. package/dist/lib/db.d.ts.map +1 -0
  92. package/dist/lib/db.js +589 -0
  93. package/dist/lib/db.js.map +1 -0
  94. package/dist/lib/logger.d.ts +3 -0
  95. package/dist/lib/logger.d.ts.map +1 -0
  96. package/dist/lib/logger.js +11 -0
  97. package/dist/lib/logger.js.map +1 -0
  98. package/dist/lib/projectSlug.d.ts +61 -0
  99. package/dist/lib/projectSlug.d.ts.map +1 -0
  100. package/dist/lib/projectSlug.js +273 -0
  101. package/dist/lib/projectSlug.js.map +1 -0
  102. package/dist/lib/redactSecrets.d.ts +7 -0
  103. package/dist/lib/redactSecrets.d.ts.map +1 -0
  104. package/dist/lib/redactSecrets.js +90 -0
  105. package/dist/lib/redactSecrets.js.map +1 -0
  106. package/dist/lib/scope.d.ts +54 -0
  107. package/dist/lib/scope.d.ts.map +1 -0
  108. package/dist/lib/scope.js +103 -0
  109. package/dist/lib/scope.js.map +1 -0
  110. package/dist/lib/spool.d.ts +23 -0
  111. package/dist/lib/spool.d.ts.map +1 -0
  112. package/dist/lib/spool.js +317 -0
  113. package/dist/lib/spool.js.map +1 -0
  114. package/dist/lib/sqlite.d.ts +50 -0
  115. package/dist/lib/sqlite.d.ts.map +1 -0
  116. package/dist/lib/sqlite.js +130 -0
  117. package/dist/lib/sqlite.js.map +1 -0
  118. package/dist/lib/tls.d.ts +34 -0
  119. package/dist/lib/tls.d.ts.map +1 -0
  120. package/dist/lib/tls.js +212 -0
  121. package/dist/lib/tls.js.map +1 -0
  122. package/dist/mcp/server.d.ts +231 -0
  123. package/dist/mcp/server.d.ts.map +1 -0
  124. package/dist/mcp/server.js +615 -0
  125. package/dist/mcp/server.js.map +1 -0
  126. package/dist/memory/actionStore.d.ts +75 -0
  127. package/dist/memory/actionStore.d.ts.map +1 -0
  128. package/dist/memory/actionStore.js +239 -0
  129. package/dist/memory/actionStore.js.map +1 -0
  130. package/dist/memory/deadLetterStore.d.ts +30 -0
  131. package/dist/memory/deadLetterStore.d.ts.map +1 -0
  132. package/dist/memory/deadLetterStore.js +91 -0
  133. package/dist/memory/deadLetterStore.js.map +1 -0
  134. package/dist/memory/embedQueueStore.d.ts +32 -0
  135. package/dist/memory/embedQueueStore.d.ts.map +1 -0
  136. package/dist/memory/embedQueueStore.js +143 -0
  137. package/dist/memory/embedQueueStore.js.map +1 -0
  138. package/dist/memory/failurePatternStore.d.ts +37 -0
  139. package/dist/memory/failurePatternStore.d.ts.map +1 -0
  140. package/dist/memory/failurePatternStore.js +179 -0
  141. package/dist/memory/failurePatternStore.js.map +1 -0
  142. package/dist/memory/graphStore.d.ts +38 -0
  143. package/dist/memory/graphStore.d.ts.map +1 -0
  144. package/dist/memory/graphStore.js +229 -0
  145. package/dist/memory/graphStore.js.map +1 -0
  146. package/dist/memory/noteStore.d.ts +58 -0
  147. package/dist/memory/noteStore.d.ts.map +1 -0
  148. package/dist/memory/noteStore.js +280 -0
  149. package/dist/memory/noteStore.js.map +1 -0
  150. package/dist/memory/observationStore.d.ts +40 -0
  151. package/dist/memory/observationStore.d.ts.map +1 -0
  152. package/dist/memory/observationStore.js +213 -0
  153. package/dist/memory/observationStore.js.map +1 -0
  154. package/dist/memory/projectRename.d.ts +14 -0
  155. package/dist/memory/projectRename.d.ts.map +1 -0
  156. package/dist/memory/projectRename.js +105 -0
  157. package/dist/memory/projectRename.js.map +1 -0
  158. package/dist/memory/rollupSweeper.d.ts +36 -0
  159. package/dist/memory/rollupSweeper.d.ts.map +1 -0
  160. package/dist/memory/rollupSweeper.js +235 -0
  161. package/dist/memory/rollupSweeper.js.map +1 -0
  162. package/dist/memory/sessionStore.d.ts +81 -0
  163. package/dist/memory/sessionStore.d.ts.map +1 -0
  164. package/dist/memory/sessionStore.js +285 -0
  165. package/dist/memory/sessionStore.js.map +1 -0
  166. package/dist/memory/trajectoryStore.d.ts +86 -0
  167. package/dist/memory/trajectoryStore.d.ts.map +1 -0
  168. package/dist/memory/trajectoryStore.js +528 -0
  169. package/dist/memory/trajectoryStore.js.map +1 -0
  170. package/dist/middleware/auth.d.ts +30 -0
  171. package/dist/middleware/auth.d.ts.map +1 -0
  172. package/dist/middleware/auth.js +387 -0
  173. package/dist/middleware/auth.js.map +1 -0
  174. package/dist/middleware/rateLimiter.d.ts +13 -0
  175. package/dist/middleware/rateLimiter.d.ts.map +1 -0
  176. package/dist/middleware/rateLimiter.js +153 -0
  177. package/dist/middleware/rateLimiter.js.map +1 -0
  178. package/dist/middleware/tracing.d.ts +15 -0
  179. package/dist/middleware/tracing.d.ts.map +1 -0
  180. package/dist/middleware/tracing.js +53 -0
  181. package/dist/middleware/tracing.js.map +1 -0
  182. package/dist/routes/dashboard.d.ts +2 -0
  183. package/dist/routes/dashboard.d.ts.map +1 -0
  184. package/dist/routes/dashboard.js +443 -0
  185. package/dist/routes/dashboard.js.map +1 -0
  186. package/dist/routes/learning.d.ts +2 -0
  187. package/dist/routes/learning.d.ts.map +1 -0
  188. package/dist/routes/learning.js +46 -0
  189. package/dist/routes/learning.js.map +1 -0
  190. package/dist/routes/mcp.d.ts +8 -0
  191. package/dist/routes/mcp.d.ts.map +1 -0
  192. package/dist/routes/mcp.js +316 -0
  193. package/dist/routes/mcp.js.map +1 -0
  194. package/dist/routes/memories.d.ts +2 -0
  195. package/dist/routes/memories.d.ts.map +1 -0
  196. package/dist/routes/memories.js +33 -0
  197. package/dist/routes/memories.js.map +1 -0
  198. package/dist/scripts/createApiKey.d.ts +2 -0
  199. package/dist/scripts/createApiKey.d.ts.map +1 -0
  200. package/dist/scripts/createApiKey.js +78 -0
  201. package/dist/scripts/createApiKey.js.map +1 -0
  202. package/dist/scripts/doctor.d.ts +24 -0
  203. package/dist/scripts/doctor.d.ts.map +1 -0
  204. package/dist/scripts/doctor.js +332 -0
  205. package/dist/scripts/doctor.js.map +1 -0
  206. package/dist/scripts/installAgent.d.ts +80 -0
  207. package/dist/scripts/installAgent.d.ts.map +1 -0
  208. package/dist/scripts/installAgent.js +1046 -0
  209. package/dist/scripts/installAgent.js.map +1 -0
  210. package/dist/scripts/migrateAgentMemory.d.ts +16 -0
  211. package/dist/scripts/migrateAgentMemory.d.ts.map +1 -0
  212. package/dist/scripts/migrateAgentMemory.js +209 -0
  213. package/dist/scripts/migrateAgentMemory.js.map +1 -0
  214. package/dist/scripts/smokeTest.d.ts +16 -0
  215. package/dist/scripts/smokeTest.d.ts.map +1 -0
  216. package/dist/scripts/smokeTest.js +150 -0
  217. package/dist/scripts/smokeTest.js.map +1 -0
  218. package/docker-compose.qdrant-port.yml +7 -0
  219. package/docker-compose.yml +107 -0
  220. package/npm-shrinkwrap.json +7635 -0
  221. package/package.json +107 -4
  222. package/plugin/hooks/postToolUse.js +513 -0
  223. package/plugin/hooks/sessionStart.js +416 -0
  224. package/plugin/hooks/sessionStop.js +346 -0
  225. package/plugin/hooks.json +30 -0
  226. package/plugin/mcp_config.json +13 -0
  227. package/plugin/plugin.json +15 -0
  228. package/plugin/rules/AGENTS.md +66 -0
  229. package/plugin/skills/brain-memory/REFERENCE.md +64 -0
  230. package/plugin/skills/brain-memory/SKILL.md +68 -0
  231. package/plugin/skills/brain-memory/TROUBLESHOOTING.md +24 -0
  232. package/plugin/skills/digest/SKILL.md +54 -0
  233. package/plugin/skills/digest/TROUBLESHOOTING.md +24 -0
  234. package/plugin/skills/handoff/SKILL.md +59 -0
  235. package/plugin/skills/handoff/TROUBLESHOOTING.md +24 -0
  236. package/plugin/skills/save/SKILL.md +76 -0
  237. package/plugin/skills/save/TROUBLESHOOTING.md +24 -0
  238. package/plugin/skills/search/SKILL.md +60 -0
  239. package/plugin/skills/search/TROUBLESHOOTING.md +24 -0
  240. package/src/ai/chat.ts +214 -0
  241. package/src/ai/circuitBreaker.ts +120 -0
  242. package/src/ai/config.ts +311 -0
  243. package/src/ai/vendors.ts +292 -0
  244. package/src/app.ts +1150 -0
  245. package/src/cli.ts +1080 -0
  246. package/src/consolidation/candidates.ts +219 -0
  247. package/src/consolidation/fixtures.ts +461 -0
  248. package/src/consolidation/gate.ts +408 -0
  249. package/src/consolidation/runner.ts +220 -0
  250. package/src/dashboard/clientScript.ts +4208 -0
  251. package/src/dashboard/html.ts +550 -0
  252. package/src/dashboard/styles.ts +1279 -0
  253. package/src/index.ts +139 -0
  254. package/src/learning/embedWorker.ts +651 -0
  255. package/src/learning/embedding.ts +522 -0
  256. package/src/learning/engine.ts +86 -0
  257. package/src/learning/search.ts +568 -0
  258. package/src/learning/storeMeta.ts +147 -0
  259. package/src/learning/types.ts +111 -0
  260. package/src/lib/brainHome.ts +101 -0
  261. package/src/lib/db.ts +627 -0
  262. package/src/lib/logger.ts +7 -0
  263. package/src/lib/projectSlug.ts +286 -0
  264. package/src/lib/redactSecrets.ts +87 -0
  265. package/src/lib/scope.ts +121 -0
  266. package/src/lib/spool.ts +372 -0
  267. package/src/lib/sqlite.ts +158 -0
  268. package/src/lib/tls.ts +252 -0
  269. package/src/mcp/server.ts +793 -0
  270. package/src/memory/actionStore.ts +378 -0
  271. package/src/memory/deadLetterStore.ts +141 -0
  272. package/src/memory/embedQueueStore.ts +176 -0
  273. package/src/memory/failurePatternStore.ts +221 -0
  274. package/src/memory/graphStore.ts +352 -0
  275. package/src/memory/noteStore.ts +403 -0
  276. package/src/memory/observationStore.ts +303 -0
  277. package/src/memory/projectRename.ts +147 -0
  278. package/src/memory/rollupSweeper.ts +309 -0
  279. package/src/memory/sessionStore.ts +410 -0
  280. package/src/memory/trajectoryStore.ts +775 -0
  281. package/src/middleware/auth.ts +450 -0
  282. package/src/middleware/rateLimiter.ts +186 -0
  283. package/src/middleware/tracing.ts +70 -0
  284. package/src/routes/dashboard.ts +496 -0
  285. package/src/routes/learning.ts +51 -0
  286. package/src/routes/mcp.ts +349 -0
  287. package/src/routes/memories.ts +33 -0
  288. package/src/scripts/createApiKey.ts +109 -0
  289. package/src/scripts/doctor.ts +359 -0
  290. package/src/scripts/installAgent.ts +1278 -0
  291. package/src/scripts/migrateAgentMemory.ts +263 -0
  292. package/src/scripts/smokeTest.ts +189 -0
  293. package/tsconfig.json +21 -0
package/.dockerignore ADDED
@@ -0,0 +1,11 @@
1
+ node_modules
2
+ dist
3
+ .git
4
+ data/*.db*
5
+ data/models
6
+ *.log
7
+ .env
8
+ .env.local
9
+ .env.*.local
10
+ coverage
11
+ .DS_Store
package/.env.example ADDED
@@ -0,0 +1,245 @@
1
+ # ===========================================================================
2
+ # Neuralbrain — example configuration
3
+ #
4
+ # Three AI-backed functions: summarize | consolidate | embed
5
+ # (There is deliberately no `compress`. Capture never calls a model — see
6
+ # rule 1 in CLAUDE.md. Rolling up old observations is `consolidate` on an
7
+ # age trigger, operating on rows that are already stored.)
8
+ #
9
+ # Copy to .env and edit. Every value below is a default except where marked.
10
+ # ===========================================================================
11
+
12
+
13
+ # ---------------------------------------------------------------------------
14
+ # Service
15
+ # ---------------------------------------------------------------------------
16
+ NODE_ENV=development
17
+ PORT=3737
18
+ # Internal host binding (0.0.0.0 inside container, 127.0.0.1 on local host)
19
+ HOST=127.0.0.1
20
+ # Host binding for published Docker ports (127.0.0.1 binds to localhost only)
21
+ HOST_BIND=127.0.0.1
22
+
23
+ # URL where the Neuralbrain HTTP service is reachable by your agents, MCP, and hooks.
24
+ # Change this to another host/LAN IP or cloud URL (e.g. https://brain.example.com) if running Brain remotely:
25
+ BRAIN_API_URL=http://127.0.0.1:3737
26
+
27
+ # SQLite file — the source of truth. Defaults to ./data/brain.db
28
+ DATABASE_URL=./data/brain.db
29
+
30
+ # Qdrant — an index, rebuildable from SQLite at any time
31
+ # (Use http://localhost:6333 on host; http://qdrant:6333 inside Docker Compose)
32
+ QDRANT_URL=http://localhost:6333
33
+ QDRANT_API_KEY=
34
+
35
+
36
+ # ---------------------------------------------------------------------------
37
+ # AI Endpoints & Remote Models (Ollama, LM Studio, vLLM, etc.)
38
+ # ---------------------------------------------------------------------------
39
+ # NOTE: By default, BRAIN_AI=agent and BRAIN_EMBED=local, so neither BRAIN_ENDPOINT
40
+ # nor cloud API keys are called or required for out-of-the-box operation!
41
+ #
42
+ # Generative chat (BRAIN_AI) and vector embeddings (BRAIN_EMBED) are toggled INDEPENDENTLY:
43
+ # - You can set BRAIN_EMBED=remote (generating embeddings via Ollama or LM Studio) while
44
+ # keeping BRAIN_AI=agent (no remote chat model used).
45
+ # - BRAIN_ENDPOINT serves as the default base URL for any function set to tier `remote`.
46
+ # - If your embedding server runs on a different port or host from your chat server,
47
+ # you can optionally set BRAIN_EMBED_ENDPOINT specifically for embeddings.
48
+
49
+ BRAIN_ENDPOINT=http://localhost:11434/v1
50
+ BRAIN_ENDPOINT_API_KEY= # usually blank; LM Studio/Ollama need no key
51
+
52
+ # Optional: Separate endpoint for embeddings if different from BRAIN_ENDPOINT
53
+ # (used only when BRAIN_EMBED=remote):
54
+ # BRAIN_EMBED_ENDPOINT=http://localhost:11434/v1
55
+ # BRAIN_EMBED_API_KEY=
56
+
57
+ # The one cloud vendor, used wherever a tier resolves to `vendor`
58
+ BRAIN_VENDOR= # openai | anthropic | google
59
+ # The GENERATIVE model only (summarize/consolidate). Defaults per vendor:
60
+ # openai gpt-4o-mini | anthropic claude-3-5-haiku | google gemini-2.0-flash
61
+ # The embedder's model is BRAIN_EMBED_MODEL, never this. One variable cannot
62
+ # mean both: setting a chat model here used to silently re-point the vendor
63
+ # embedder at a model that cannot embed, which store_meta then pinned.
64
+ BRAIN_VENDOR_MODEL=
65
+ OPENAI_API_KEY=
66
+ ANTHROPIC_API_KEY=
67
+ GOOGLE_API_KEY=
68
+
69
+
70
+ # ---------------------------------------------------------------------------
71
+ # Generative functions — tiers: none | agent | remote | vendor
72
+ #
73
+ # none disabled. A finished state, not a broken one.
74
+ # agent the host agent (Claude Code/Desktop, Antigravity) does it over
75
+ # MCP, at session end or before context compaction. No key, no
76
+ # model, and it holds the conversation rather than just the rows.
77
+ # remote a chat model on BRAIN_ENDPOINT.
78
+ # vendor BRAIN_VENDOR.
79
+ #
80
+ # `local` is NOT available here — it means in-process, and only an encoder
81
+ # can load in-process. An embedding model cannot summarise.
82
+ # ---------------------------------------------------------------------------
83
+ BRAIN_AI=agent # default tier for all generative functions
84
+
85
+ # Placeholder: currently no table or leasing surface exists for session-grain summaries;
86
+ # reserved for future session-grain workers. Inherits BRAIN_AI.
87
+ BRAIN_AI_SUMMARIZE= # override; inherits BRAIN_AI (placeholder)
88
+ BRAIN_AI_CONSOLIDATE= # override; inherits BRAIN_AI
89
+
90
+ BRAIN_CHAT_MODEL= # `remote` tier only; a NON-REASONING build
91
+ BRAIN_CHAT_TIMEOUT_MS=60000 # applies to `remote` AND `vendor`
92
+ BRAIN_CHAT_MAX_TOKENS=2000 # raise sharply if the model reasons
93
+
94
+ # Ordered fallback tiers, e.g. `remote,vendor`. Permitted for generative
95
+ # functions because every derived row records the producer that actually
96
+ # answered (rule 6) — unlike the embedder, which may never fall back.
97
+ BRAIN_AI_FALLBACK=
98
+ BRAIN_CHAT_BREAKER_THRESHOLD=3 # failures before the circuit opens
99
+ BRAIN_CHAT_BREAKER_COOLDOWN_MS=30000 # cooldown before one half-open probe
100
+ BRAIN_CHAT_FIELD_CHARS=4000 # per-field cap when rendering a prompt
101
+
102
+ # Probe `reasoning_tokens` on a real response at startup and size the budget
103
+ # from what the endpoint actually does. Do not trust a no-think flag: neither
104
+ # `/no_think` nor `enable_thinking:false` was honoured on tested hardware,
105
+ # and a reasoning build burned 5,820 of 6,000 tokens thinking, returning
106
+ # nothing. Set 0 to skip the probe.
107
+ BRAIN_CHAT_PROBE=1
108
+
109
+
110
+ # ---------------------------------------------------------------------------
111
+ # Embedding — tiers: none | local | local-gpu | remote | vendor
112
+ #
113
+ # none no vectors. SQL + BM25 retrieval only. Needs no model at all;
114
+ # the smallest useful deployment.
115
+ # local in-process CPU ONNX via @huggingface/transformers. Self-contained.
116
+ # local-gpu managed GPU ONNX sidecar (`embedder-gpu` via Docker Compose
117
+ # `gpu` profile). Requires NVIDIA GPU, host drivers, and
118
+ # nvidia-container-toolkit; not available in `local-only` mode.
119
+ # remote an embedding model on BRAIN_EMBED_ENDPOINT or BRAIN_ENDPOINT.
120
+ # Uses an external server (Ollama, LM Studio, etc.).
121
+ # vendor BRAIN_VENDOR (google = gemini-embedding-001).
122
+ #
123
+ # Separate from BRAIN_AI on purpose: this is the one irreversible choice.
124
+ # The resolved identity is pinned in `store_meta` on first use; a later
125
+ # mismatch refuses vector search loudly and points at the re-embed job.
126
+ # It never silently re-points.
127
+ # ---------------------------------------------------------------------------
128
+ BRAIN_EMBED=local
129
+ # Owns "which model" for EVERY embedder tier, vendor included.
130
+ # local / local-gpu -> nomic | minilm
131
+ # remote -> the endpoint's model name
132
+ # vendor -> google gemini-embedding-001 | openai text-embedding-3-small
133
+ BRAIN_EMBED_MODEL=nomic
134
+ BRAIN_EMBED_DIM=512 # nomic Matryoshka: 768|512|256|128|64
135
+
136
+ # Optional overrides for `BRAIN_EMBED=local-gpu` (Docker Compose `gpu` profile):
137
+ # BRAIN_GPU_PORT=7997
138
+ # BRAIN_GPU_ENDPOINT=http://127.0.0.1:7997 # auto-set to http://embedder-gpu:7997 in Docker mode
139
+ # BRAIN_GPU_IMAGE=michaelf34/infinity:latest
140
+ # BRAIN_GPU_MODEL_ID=nomic-ai/nomic-embed-text-v1.5
141
+ # BRAIN_GPU_ENGINE=optimum # optimum (ONNX) | torch
142
+
143
+ # `minilm` (all-MiniLM-L6-v2, 384d) is smaller and ~6x faster, but its
144
+ # 256-wordpiece limit truncates 21% of a real ~200-note corpus. Offered for
145
+ # tight hosts; never selected automatically.
146
+
147
+ BRAIN_EMBED_BATCH=32
148
+ BRAIN_EMBED_CONCURRENCY=4 # workers draining the pending queue
149
+
150
+
151
+ # ---------------------------------------------------------------------------
152
+ # Retention
153
+ # observations high volume, machine-written
154
+ # trajectories one task attempt with an outcome
155
+ # notes authored on purpose — NEVER auto-deleted
156
+ # ---------------------------------------------------------------------------
157
+ BRAIN_OBS_ARCHIVE_DAYS=30
158
+ BRAIN_OBS_DELETE_DAYS=90
159
+
160
+ # OPEN QUESTION: rule 5 says trajectories get "long
161
+ # retention" but names no number. 0 = never delete, pending that decision.
162
+ BRAIN_TRAJECTORY_ARCHIVE_DAYS=180
163
+ BRAIN_TRAJECTORY_DELETE_DAYS=0
164
+
165
+ # A summarised observation archives instead of deleting, so a derived row's
166
+ # sources outlive it (rule 6 requires this to be true).
167
+ BRAIN_KEEP_SUMMARIZED_SOURCES=1
168
+
169
+ # ---------------------------------------------------------------------------
170
+ # Rollup sweeper (D29)
171
+ # A client that crashes mid-task never sends the explicit rollup signal, so
172
+ # without this its observations are captured and then never used. A swept
173
+ # rollup's success is NULL (unknown) — never 1.
174
+ # ---------------------------------------------------------------------------
175
+ BRAIN_ROLLUP_IDLE_MINUTES=30 # session idle before it is swept
176
+ BRAIN_ROLLUP_SWEEP_INTERVAL_MS=300000 # background interval; timer is unref'ed
177
+ BRAIN_DISABLE_ROLLUP_SWEEP= # =1 disables the interval; endpoint still works
178
+
179
+
180
+ # ---------------------------------------------------------------------------
181
+ # Auth and limits
182
+ # ---------------------------------------------------------------------------
183
+ # Optional pre-configured static API key for agents, MCP, and operator dashboard.
184
+ # If set, brain registers this key on startup. If left commented out/unset, you can
185
+ # claim your first key via the dashboard UI or generate one via POST /maintenance/api-keys.
186
+ # BRAIN_API_KEY=your-secret-api-key-here
187
+ BRAIN_REQUIRE_API_KEY=1
188
+
189
+ BRAIN_RATE_LIMIT_WINDOW_MS=60000
190
+ BRAIN_RATE_LIMIT_MAX=100
191
+
192
+ # Paths exempt from rate limiting. Capture MUST be exempt — rule 3 forbids
193
+ # rejecting a write for volume, and hook-driven capture exceeds 100/min in
194
+ # seconds.
195
+ BRAIN_RATE_LIMIT_EXEMPT=/health,/capture
196
+
197
+
198
+ # ---------------------------------------------------------------------------
199
+ # Client spool (transport failures) — 5 MB cap, 168 h max age, dedupe
200
+ # ---------------------------------------------------------------------------
201
+ BRAIN_SPOOL_PATH=~/.neuralbrain/spool
202
+ BRAIN_SPOOL_MAX_BYTES=5242880
203
+ BRAIN_SPOOL_MAX_AGE_HOURS=168
204
+
205
+
206
+ # ===========================================================================
207
+ # Replaced from NeuralSwarm — do NOT set these; they are gone
208
+ #
209
+ # LEARNING_EMBEDDING_PROVIDER -> BRAIN_EMBED + BRAIN_VENDOR
210
+ # OLLAMA_HOST -> BRAIN_ENDPOINT
211
+ # OPENAI_COMPATIBLE_URL -> BRAIN_ENDPOINT
212
+ # OPENAI_COMPATIBLE_API_KEY -> BRAIN_ENDPOINT_API_KEY
213
+ # LEARNING_DIMENSION_PROBE -> replaced by the store_meta check (D7)
214
+ # LEARNING_DISABLE_QDRANT -> BRAIN_EMBED=none
215
+ # LEARNING_DISABLE_HNSW -> BRAIN_EMBED=none
216
+ #
217
+ # LEARNING_DISABLE_HNSW was especially bad: engine.ts assigns to it at
218
+ # runtime (lines 195, 222) to disable Qdrant after a failed dimension probe,
219
+ # so the service rewrote its own configuration and kept serving as though
220
+ # nothing had happened. Replaced by a loud refusal.
221
+ # ===========================================================================
222
+
223
+
224
+ # ===========================================================================
225
+ # Docker Compose Operations
226
+ #
227
+ # Start the entire stack (Brain + Qdrant):
228
+ # docker compose up -d --build
229
+ #
230
+ # Check container health status:
231
+ # docker compose ps
232
+ #
233
+ # Follow logs:
234
+ # docker compose logs -f brain
235
+ #
236
+ # Run operational commands inside the container:
237
+ # # Run health checks & AI conformance doctor
238
+ # docker compose exec brain node dist/scripts/doctor.js [--ai|--no-ai]
239
+ #
240
+ # # Generate a client API key
241
+ # docker compose exec brain node dist/scripts/createApiKey.js --name "my-agent"
242
+ #
243
+ # # Run MCP server over stdio
244
+ # docker compose exec -i -e BRAIN_API_KEY=<key> brain node dist/mcp/server.js
245
+ # ===========================================================================
package/Dockerfile ADDED
@@ -0,0 +1,65 @@
1
+ # Stage 1: Builder
2
+ FROM node:24 AS builder
3
+
4
+ WORKDIR /app
5
+
6
+ # Prevent Docker bridge IPv6 DNS connection timeouts to registry.npmjs.org
7
+ ENV NODE_OPTIONS="--dns-result-order=ipv4first"
8
+
9
+ # Copy package manifests
10
+ COPY package.json npm-shrinkwrap.json ./
11
+
12
+ # Configure npm retry timeouts and install dependencies cleanly using BuildKit cache
13
+ RUN --mount=type=cache,target=/root/.npm \
14
+ npm config set fetch-retry-mintimeout 5000 && \
15
+ npm config set fetch-retry-maxtimeout 10000 && \
16
+ npm ci --no-audit --no-fund --onnxruntime-node-install-cuda=skip
17
+
18
+ # Copy source code and TypeScript config
19
+ COPY . .
20
+
21
+ # Build the TypeScript project
22
+ RUN npm run build
23
+
24
+ # Prune devDependencies to keep only production modules, preserving prebuilt native binaries
25
+ RUN --mount=type=cache,target=/root/.npm \
26
+ npm prune --production --no-audit --no-fund
27
+
28
+ # Stage 2: Runner (lean bookworm-slim reduces image size from ~1.1GB to ~220MB)
29
+ FROM node:24-bookworm-slim AS runner
30
+
31
+ WORKDIR /app
32
+
33
+ # Ensure IPv4 DNS resolution order in runtime as well
34
+ ENV NODE_OPTIONS="--dns-result-order=ipv4first"
35
+
36
+ # Copy production node_modules from builder
37
+ COPY --from=builder /app/node_modules ./node_modules
38
+
39
+ # Copy compiled source code
40
+ COPY --from=builder /app/dist ./dist
41
+ COPY --from=builder /app/package.json ./
42
+
43
+ # Create data and cert directories for SQLite database, models, and TLS certs
44
+ RUN mkdir -p /app/data /app/data/models /app/certs
45
+ RUN chown -R node:node /app/data /app/certs
46
+
47
+ # Use non-root node user for security
48
+ USER node
49
+
50
+ # Expose the API port
51
+ EXPOSE 3000
52
+
53
+ # Set environment variables for the application
54
+ ENV NODE_ENV=production
55
+ ENV HOST=0.0.0.0
56
+ ENV PORT=3000
57
+ ENV DATABASE_URL=/app/data/brain.db
58
+ ENV BRAIN_MODEL_CACHE_DIR=/app/data/models
59
+
60
+ # Healthcheck to probe the Brain service status (supports HTTP and BRAIN_HTTPS=1)
61
+ HEALTHCHECK --interval=10s --timeout=5s --start-period=10s --retries=3 \
62
+ CMD node -e "const https=require('https'),fs=require('fs');if(process.env.BRAIN_HTTPS==='1'||process.env.BRAIN_HTTPS==='true'){const cert=process.env.BRAIN_TLS_CERT||'/app/certs/server.crt';const ca=fs.existsSync(cert)?fs.readFileSync(cert):undefined;const req=https.request({hostname:'127.0.0.1',port:3000,path:'/health',ca},r=>process.exit(r.statusCode===200?0:1));req.on('error',()=>process.exit(1));req.end();}else{fetch('http://127.0.0.1:3000/health').then(r=>process.exit(r.ok?0:1)).catch(()=>process.exit(1));}"
63
+
64
+ # Start the application directly with Node for fast startup and clean signal forwarding
65
+ CMD ["node", "dist/index.js"]
package/LICENSE ADDED
@@ -0,0 +1,44 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Derrick
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
23
+ ---
24
+
25
+ Commons Clause License Condition v1.0
26
+
27
+ The Software is provided to you by the Licensor under the License, as defined
28
+ below, subject to the following condition.
29
+
30
+ Without limiting other conditions in the License, the grant of rights under
31
+ the License will not include, and the License does not grant to you, the right
32
+ to Sell the Software.
33
+
34
+ For purposes of the foregoing, "Sell" means practicing any or all of the
35
+ rights granted to you under the License to provide to third parties, for a
36
+ fee or other consideration (including without limitation fees for hosting or
37
+ consulting/support services related to the Software), a product or service
38
+ whose value derives, entirely or substantially, from the functionality of the
39
+ Software. Any license notice or attribution required by the License must also
40
+ include this Commons Clause License Condition notice.
41
+
42
+ Software: neuralbrain
43
+ License: MIT
44
+ Licensor: Derrick