opencode-brainboxBrainbox as opencode's native memory backend: graph recall with confidence grades and evidence tags, WakeBrief injection at session start, and a digest filed at session end for server-side dreaming.
0
122
近 7 天 3
31.6
生态多维模型
29 天前
2026-07-21
快速安装与配置
opencode.json写入当前项目的 opencode.json,只对这个仓库生效。
opencode.json
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["opencode-brainbox@0.1.0"]
}写入 ~/.config/opencode/opencode.json,对所有项目生效。
~/.config/opencode/opencode.json
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["opencode-brainbox@0.1.0"]
}若你要在本地改造这个插件,先装到项目里再从本地路径引用。
shell
pnpm add -D opencode-brainboxopencode 启动时会通过内嵌运行时自动加载 npm 依赖并缓存至本地目录,无需手动在全局环境执行安装。
Brainbox as opencode's native memory backend.
A Tier-2 memory integration — not just an on-demand tool, but a plugin that:
- exposes
brainbox_recall/brainbox_store/brainbox_gettools the model can call, - auto-injects a WakeBrief into the system prompt at session start (recalled context, before turn 1), and
- files a digest at session end for Brainbox's server-side dream cycle.
Ported from openclaw-brainbox onto opencode's
@opencode-ai/plugin hook surface. Same transport client, same never-throws + cooldown contract.
Install
From a local checkout, reference it in ~/.config/opencode/opencode.jsonc:
{
"plugin": [
["file:///Users/you/opencode-brainbox/index.js", { "baseUrl": "https://brainbox-mcp.thexi.dev" }]
]
}
(Non-secret options only — the API key comes from the environment, never the config file.)
Auth — never put the key in plaintext config
The bbk_ tenant key is read from BRAINBOX_BBK (or BRAINBOX_KEY). On macOS, keep it in the
Keychain and export it at launch:
# one-time: store the key (service name matches the openclaw plugin's convention)
security add-generic-password -a "$USER" -s brainbox-api-key -w 'bbk_...' -U
# per shell / wrapper, before running opencode:
export BRAINBOX_BBK="$(security find-generic-password -s brainbox-api-key -w)"
opencode run -m openrouter/z-ai/glm-5.2 "…"
Hooks used (@opencode-ai/plugin)
| Behaviour | Hook |
|---|---|
| recall / store / get tools | tool |
| WakeBrief injection at session start | experimental.chat.system.transform |
| open session + capture user text | chat.message |
| digest + continuous-encoder turn sync | experimental.text.complete |
| carry recalled context across compaction | experimental.session.compacting |
| file digest on explicit session end | event (session.deleted) |
| best-effort close on teardown | dispose |
Note on session end: opencode has no explicit "session ended" hook. For headless
opencode run(one-shot),disposefires on process exit — an exact, clean end. For the long-lived TUI, the digest is filed onsession.deletedand ondispose. Server-side lazy-close + TTL sweep means a missed end degrades, never corrupts.
Transport
brainbox_recall→ RESTPOST /ask(salience-ranked recall, confidence grades, evidence tags, honest abstention).brainbox_store/brainbox_getand the session tools → the worker's/mcpdoor (hand-rolled JSON-RPC streamable-HTTP client, no SDK).
All tools never throw: on any backend failure they return { disabled: true, unavailable: true, error } and open a cooldown window (default 60s) so a dead backend costs one timeout, not one per
turn.
Memory-free runs
Set BRAINBOX_RECALL=off to disable the read paths (recall tool + WakeBrief injection) for a run;
writes still flow. For a fully memory-free run, simply don't load the plugin. This switch carries no
mode semantics — it's plain ergonomics.
Config options
| key | default | |
|---|---|---|
baseUrl |
https://brainbox-mcp.thexi.dev |
|
apiKey |
— | prefer ${BRAINBOX_BBK} env; a literal bbk_… is accepted |
requestTimeoutMs |
8000 |
per-request timeout |
failureCooldownMs |
60000 |
backoff after a backend failure |
sessionChoreography |
true |
set false for tools-only (no WakeBrief / digest) |
turnSync |
true |
continuous-encoder per-turn ingest |