
Brainbox
io.github.thebasedcapital由 GitHub 账号 thebasedcapital 发布v0.1.6更新于 Oct 24, 2026
Hebbian memory for AI agents. Learns file patterns, predicts next tools, saves tokens.
概览
为编程助手提供本地过程记忆:记录文件、工具与错误模式,并在助手搜索前召回可能需要的文件。
- 可以做什么
- BrainBox 观察编程助手实际执行的操作并存入本地 SQLite 图:哪些文件被一起读取和编辑、哪些错误由哪些修改修复、哪些工具链被重复使用。在后续任务中,它会提前召回相关文件、预测下一个工具,并可给出错误到修复的过程。它提供 record、recall、explain、error、resolve、predict_next、stats、decay 八个 MCP 工具,同时附带命令行工具。
- 适用场景
- 适合在同一代码库中反复工作、助手需要反复搜索相同文件而消耗大量 token 的场景。它面向编程助手,并可从 git 历史和代码图初始化以缩短冷启动。
- 运行要求
- 以 npm 包 brainbox-hebbian 通过 stdio 在本地运行。需要 macOS 或 Linux 上的 Node.js 22 或更高版本;可选的 FSEvents 文件监视守护进程仅支持 macOS。未声明账号、API 密钥或环境变量。嵌入为可选项,需要下载模型;未启用时召回退化为关键词搜索。
安装
在 SourceWeft 中
- 打开 控制台中的 Brainbox,将其添加到工作区。
- 为需要使用其工具的对话启用该服务。
Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。
其他 MCP 客户端
参照 仓库 中的启动说明。
README
[BrainBox — muscle memory for coding agents]
[npm version] [GitHub stars] [Node 22+] [MCP: 8 tools] [Zero cost, local, SQLite] [MIT license]
Install · How it works · Results · Research · Integrations · Whitepaper
BrainBox is procedural memory for AI coding agents. It watches what the agent actually does and remembers it:
- which files get read and edited together
- which errors were fixed by which edits
- which tool chains the agent repeats
On the next task it puts the right files in front of the agent before it starts searching.
Not a vector database. Not RAG. Hebbian learning on a local SQLite graph. Zero API cost, no GPU, nothing leaves your machine.
Paper
BrainBox: Local Behavioral Memory for Coding Agents (Bhavesh B, 2026). The DOI above covers all versions and resolves to the latest. Latest version: v0.2, doi:10.5281/zenodo.23250505.
Install
That's it. The postinstall script:
- Adds a
PostToolUsehook to~/.claude/settings.json. It learns from every file read, edit, search and command. - Adds a
UserPromptSubmithook. It injects compact recall into prompts, or stays silent once it has learned you ignore it. - Adds a
SessionEndhook. It scores which recalled files you actually opened or edited and compiles procedures. - Registers the MCP server via
claude mcp add, with 8 tools:record,recall,explain,error,resolve,predict_next,stats,decay. - Creates
~/.brainbox/and starts a background download of the embedding model.
Hooks never download models. Until the model is cached (brainbox models pull), recall runs lexical-only. Embeddings come from the optional @huggingface/transformers dependency; if its native modules can't install on your machine (for example, sharp with a system libvips and no build tools), BrainBox still installs and runs with keyword search. brainbox models status shows which mode you are in.
Kill the cold start by seeding from git history and the code graph:
Uninstall: brainbox uninstall removes the hooks and the MCP server and keeps your database.
How it works
[BrainBox pipeline: tool calls → learn → recall → policy → inject, with a feedback loop]
Every tool call is a neuron firing. Files, tools and errors become neurons, and things accessed close together become synapses. A prompt triggers recall, which fuses several ranking channels. A learned policy decides whether injecting is worth the tokens. Feedback on what you actually opened or edited flows back into the graph.
Fire together, wire together
[Hebbian learning: co-accessed files strengthen their synapse across sessions]
Access auth.ts then session.ts across sessions and their synapse strengthens. SNAP plasticity makes strong synapses grow more slowly, so no single connection takes over. Links are directional (STDP): what you open next matters more than what came before.
Spreading activation
[Spreading activation from a seed file over three hops with fan-effect damping]
Recalling one file activates its neighbours for up to 3 hops. Each hop is damped by 1/√degree, so hub files don't flood the results. Each result carries the channel and the edge that produced it. brainbox_explain shows you exactly why a file was recalled.
Superhighways and decay
[Frequently used paths myelinate into superhighways while unused edges decay]
Paths you use often are myelinated into instant-recall superhighways. Recency and frequency follow the ACT-R base-level equation, B = ln Σ tⱼ^-0.5, and unused connections fade. Files recalled but ignored weaken only the edge that surfaced them.
Error → fix immune system
[An error fingerprint is linked to the edits that fixed it and recalled the next time]
When a failed command is followed by edits and a passing rerun, BrainBox stores an error→fix procedure. The procedure is keyed by the error's fingerprint and tracks helpful/harmful outcomes. The next time that error appears, the fix files are recalled at once. Procedures are shown to the agent as quoted observations, never as instructions.
Results
[v0.2 vs v0.1 vs best baseline on real agent trajectories]
brainbox eval replays real coding-agent trajectories in time order. Each task is scored on a fresh in-memory DB trained only on earlier tasks from the same repo, and every system ranks the same candidate set.
v0.1 lost to plain recency on next-file prediction. On the held-out SWE tasks the gap was −.207, 95% CI −.312…−.118. v0.2 is statistically tied with recency there. Next-tool prediction now beats every baseline significantly, and files-read recall leads on both data sources.
Known gap: on local sessions, ranking by edit frequency alone still beats BrainBox for edited files (Δ −.089, CI −.185…0).
Fitting the lexical and Hebbian channel weights to zero scored higher on dev, but recall then ignored the query, so the shipped weights keep them.
Full table, protocol and commands
Probes:
- P1: files edited or read for the task (query = task text)
- P2: next file, step by step
- P3: next tool (top 3)
Baselines: recency, frequency, BM25, EdgeBank and random. Confidence intervals are paired bootstrap 95% CIs, resampled by trajectory.
Datasets:
- Ranking weights were fit only on the dev repos (sqlglot, dvc, streamlink).
- SWE test is 40 held-out tasks from Pillow and conan.
- Local is 97 agent sessions across 5 projects, never used for fitting.
Scores are MRR (P3: MRR@3), with embeddings off.
Code search: on a 30-query code-search set, the default jina-embeddings-v2-base-code reaches Recall@5 0.867, against 0.667 for the previous MiniLM.
Built on research
[Recent papers mapped to the BrainBox subsystems they shaped]
Each v0.2 change maps to a recent paper and was measured with the replay eval:
Also in 0.2:
- Builds on Node 22–26 (better-sqlite3 v13).
- Hooks are written in Claude Code's nested settings format.
- The hook DB lock wait is capped at 100 ms.
- Procedure compilation is 470× faster on large histories.
Integrations
MCP server (any agent)
Kilo / OpenCode (native plugin)
Add to ~/.config/kilo/config.json:
OpenClaw (NeuroVault)
BrainBox can run as an OpenClaw memory slot plugin. See NeuroVault for the reference implementation.
macOS daemon (opt-in)
A system-wide FSEvents file watcher that learns from VS Code, Xcode, vim and the shell, not just agents. It installs a LaunchAgent, so it requires an explicit opt-in:
CLI
Configuration
Gemma profiles are subject to the Gemma Terms of Use.
Algorithm details
The paper's source (v0.2, doi:10.5281/zenodo.23250505) describes the implementation and coverage-conditioned replay results, including uncertainty and provenance limitations. See paper build and evidence notes for the bibliography, aggregate evidence, LaTeX and PDF build.
Architecture
Development
Requirements: Node.js 22+, on macOS or Linux. The FSEvents daemon is macOS-only; everything else is cross-platform.
If BrainBox saved your agent some searching, give it a ⭐ so others can find it.
Built by @thebasedcapital · MIT License
来源:README.md,提交 2585acb
工具
0版本历史
1- v0.1.6最新Sep 16, 2026
评分
已满足适用检查项的 50%
该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。
- 近 30 天内可连通25 分
请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。
- 已声明认证方式10 分
请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。
- 已列出工具15 分
请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。
- 描述必需15 分
- 图标10 分
- 文档15 分
- 许可证10 分