@mingxy/cerebro-claude-code 0.3.3

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.
@@ -0,0 +1,20 @@
1
+ {
2
+ "name": "cerebro",
3
+ "owner": {
4
+ "name": "mingxy-cerebro",
5
+ "email": "hi@cerebro.dev"
6
+ },
7
+ "metadata": {
8
+ "description": "Persistent memory for Claude Code — profile injection, auto-save, reasoned recall",
9
+ "version": "0.3.0"
10
+ },
11
+ "plugins": [
12
+ {
13
+ "name": "cerebro",
14
+ "source": "./",
15
+ "description": "Persistent memory plugin — SessionStart profile injection, Stop auto-ingest (incremental cursor), UserPromptSubmit reasoned recall, memory-search/save skills. Survives across sessions, projects, machines.",
16
+ "category": "memory",
17
+ "tags": ["memory", "persistent", "context", "agent-memory", "recall", "profile"]
18
+ }
19
+ ]
20
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "name": "cerebro",
3
+ "description": "Persistent memory for Claude Code — memories survive across sessions, projects, and machines",
4
+ "version": "0.3.3",
5
+ "author": {
6
+ "name": "mingxy-cerebro",
7
+ "email": "hi@cerebro.dev"
8
+ },
9
+ "homepage": "https://github.com/mingxy-cerebro/cerebro-server",
10
+ "repository": "https://github.com/mingxy-cerebro/cerebro-server",
11
+ "license": "Apache-2.0",
12
+ "keywords": ["memory", "persistent", "agent-memory", "context"]
13
+ }
package/.mcp.json ADDED
@@ -0,0 +1,10 @@
1
+ {
2
+ "cerebro": {
3
+ "command": "npx",
4
+ "args": ["-y", "@mingxy/cerebro-mcp@latest"],
5
+ "env": {
6
+ "OMEM_API_KEY": "${OMEM_API_KEY}",
7
+ "OMEM_API_URL": "${OMEM_API_URL:-https://www.mengxy.cc}"
8
+ }
9
+ }
10
+ }
package/README.md ADDED
@@ -0,0 +1,159 @@
1
+ # Cerebro — Claude Code Plugin
2
+
3
+ Persistent memory for Claude Code — memories survive across sessions, projects, and machines.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ # In Claude Code:
9
+ /plugin marketplace add mingxy-cerebro/cerebro-server
10
+ /plugin install cerebro@cerebro
11
+ ```
12
+
13
+ Restart Claude Code after installation.
14
+
15
+ ## Setup
16
+
17
+ Set your Cerebro API key. Two options:
18
+
19
+ **Option A — Environment variables** (recommended, add to `~/.claude/settings.json`):
20
+
21
+ ```json
22
+ {
23
+ "env": {
24
+ "OMEM_API_KEY": "your-api-key",
25
+ "OMEM_API_URL": "https://www.mengxy.cc"
26
+ }
27
+ }
28
+ ```
29
+
30
+ **Option B — Config file** (`~/.config/cerebro/config.json`):
31
+
32
+ ```json
33
+ {
34
+ "connection": { "apiUrl": "https://www.mengxy.cc", "apiKey": "your-api-key" }
35
+ }
36
+ ```
37
+
38
+ **Priority**: env var > config.json > builtin default (`https://www.mengxy.cc`)
39
+
40
+ Get a free API key:
41
+
42
+ ```bash
43
+ curl -X POST https://www.mengxy.cc/v1/tenants \
44
+ -H "Content-Type: application/json" -d "{}"
45
+ ```
46
+
47
+ ## How It Works
48
+
49
+ ### Hook Events
50
+
51
+ | Hook | Trigger | What It Does | Timeout |
52
+ |------|---------|-------------|---------|
53
+ | **SessionStart** | New session | Injects user profile + recent memories + time. Shows connection status via `systemMessage`. | 15s |
54
+ | **UserPromptSubmit** | Each user message | Injects reasoned-recall instruction + keyword nudges. POSTs recall-event to web UI. Zero-blocking (no API search). | 5s |
55
+ | **PreCompact** | Before context compaction | Flushes conversation delta to server (main ingest point). | 30s |
56
+ | **SessionEnd** | Session closes | Final flush of uncommitted conversation delta (backup ingest point). | 30s |
57
+ | **PreToolUse** | Before Skill/Bash tools | Recall-approve audit. | 10s |
58
+
59
+ ### Memory Ingest Architecture
60
+
61
+ Session conversations are saved at two strategic points — **not** every turn:
62
+
63
+ ```
64
+ User talks → [N turns] → PreCompact (flush #1) → Context compressed → [N turns] → SessionEnd (flush #2)
65
+ ↑ Main: saves all delta ↑ Backup: saves remaining delta
66
+ ```
67
+
68
+ - **Cursor-based dedup**: Each session tracks a cursor (last flushed UUID). Only new messages are sent.
69
+ - **Smart filtering**: Inject-echo tags (`<cerebro-*>`, `<system-reminder>`) stripped, thinking blocks dropped, tool results truncated.
70
+ - **Cost-efficient**: Server-side LLM extraction runs only on flush (typically 1-2 times per session), not per turn.
71
+
72
+ ### Memory Recall Architecture
73
+
74
+ - **SessionStart**: Three-way parallel injection (profile + recent memories + semantic search), truncated to 10K chars.
75
+ - **UserPromptSubmit**: Zero-blocking — only injects a local text instruction telling Claude *when* to search (via `memory-search` skill) and *when* to save (via `memory-save` skill). No API call, no 20s delay.
76
+ - **Keyword nudges**: Detects "记住"/"remember" → save nudge; "之前"/"之前"/"recall" → search nudge.
77
+
78
+ ### User Awareness
79
+
80
+ Cerebro shows a status line at session start via Claude Code's `systemMessage`:
81
+
82
+ ```
83
+ 🧠 Cerebro v0.3.0 · Connected · 5 memories · Profile ✓
84
+ ```
85
+
86
+ ### MCP Tools (on-demand)
87
+
88
+ The plugin bundles the `@ourmem/mcp` server:
89
+
90
+ | Tool | Purpose |
91
+ |------|---------|
92
+ | `memory_store` | Save facts, decisions, preferences |
93
+ | `memory_search` | Semantic + keyword hybrid search |
94
+ | `memory_get` | Retrieve memory by ID |
95
+ | `memory_update` | Modify existing memory |
96
+ | `memory_delete` | Remove a memory |
97
+ | `memory_profile` | View induced user-preference profile |
98
+
99
+ ### Skills
100
+
101
+ | Skill | Trigger |
102
+ |-------|---------|
103
+ | `/cerebro:memory-search` | Semantic search by natural-language query |
104
+ | `/cerebro:memory-save` | Manually save a memory |
105
+ | `/cerebro:memory-profile` | View user-preference profile |
106
+
107
+ ## Configuration Reference
108
+
109
+ | Env Var | Config Key | Default | Description |
110
+ |---------|-----------|---------|-------------|
111
+ | `OMEM_API_KEY` | `connection.apiKey` | — | **Required**. API key for Cerebro Server. |
112
+ | `OMEM_API_URL` | `connection.apiUrl` | `https://www.mengxy.cc` | Server URL. |
113
+ | `MEM_RECENT_COUNT` | `injection.recentCount` | `8` | Recent memories to inject at SessionStart. |
114
+ | `MEM_SEARCH_COUNT` | `injection.searchCount` | `8` | Search results at SessionStart. |
115
+ | `MEM_MAX_CONTENT` | `content.maxContentLength` | `3000` | Max chars per memory content. |
116
+ | `MEM_LOG_ENABLED` | `logging.logEnabled` | `true` | Write logs to `~/.config/cerebro/logs/`. |
117
+
118
+ ## Testing
119
+
120
+ ```bash
121
+ # Run all tests (zero dependencies, uses Node.js built-in test runner)
122
+ node --test plugins/claude-code/tests/
123
+ ```
124
+
125
+ ## Requirements
126
+
127
+ - Node.js 18+
128
+ - `OMEM_API_KEY` environment variable
129
+
130
+ ## Plugin Structure
131
+
132
+ ```
133
+ plugins/claude-code/
134
+ ├── .claude-plugin/
135
+ │ └── plugin.json # Plugin manifest
136
+ ├── .mcp.json # MCP server config
137
+ ├── package.json # Version (single source of truth)
138
+ ├── hooks/
139
+ │ ├── hooks.json # Hook event registration
140
+ │ ├── common.mjs # Shared library (config, HTTP, ingest, injection)
141
+ │ ├── session-start.mjs # SessionStart: profile + recent + status toast
142
+ │ ├── user-prompt-submit.mjs # UserPromptSubmit: recall instruction + nudges
143
+ │ ├── pre-compact.mjs # PreCompact: flush delta before compaction
144
+ │ ├── session-end.mjs # SessionEnd: final flush
145
+ │ └── recall-approve.mjs # PreToolUse: audit hook
146
+ ├── tests/
147
+ │ ├── common.test.mjs # Unit tests (cleanText, formatRelativeAge, etc.)
148
+ │ └── hooks.test.mjs # Contract tests (stdin→stdout per hook)
149
+ ├── scripts/
150
+ │ └── web-server.mjs # Local web UI server
151
+ └── skills/
152
+ ├── memory-search/
153
+ ├── memory-save/
154
+ └── memory-profile/
155
+ ```
156
+
157
+ ## License
158
+
159
+ Apache-2.0
package/config.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "language": "en",
3
+ "recall": {
4
+ "enabled": true,
5
+ "prompt": "Before replying, silently assess: would recalling long-term memory substantively help answer this message? Reason first, then decide — do not reflex-search, do not state the reasoning.\n\nRecall (call memory-search skill) ONLY if:\n- References past work, decisions, or context (\"the X from before\", \"that bug\", \"continue\")\n- Touches saved preferences/conventions/patterns (coding style, tool choice, habits)\n- Contains ambiguous historical terms a stored memory could disambiguate\n\nSkip if:\n- Self-contained, trivial, greeting, or meta-question\n- Current conversation has enough context\n- Already recalled on this topic this session, unchanged since\n\nMultiple recalls across turns are fine. Zero recalls all session is fine. Judge actual usefulness, not reflex."
6
+ },
7
+ "nudge": {
8
+ "enabled": true,
9
+ "saveKeywords": ["记住", "记着", "别忘了", "记一下", "remember", "don't forget", "note that"],
10
+ "recallKeywords": ["记得", "之前", "上次", "刚才", "那个", "continue", "recall", "earlier", "the bug from before"],
11
+ "savePrompt": "Detected intent to save info. Use memory-save skill (pick category, use visibility=private for sensitive data).",
12
+ "recallPrompt": "This message may need historical context. If reasoned recall judges relevant, use memory-search skill."
13
+ },
14
+ "sessionStart": {
15
+ "profileEnabled": true,
16
+ "recentActivityEnabled": true
17
+ },
18
+ "stopFlush": {
19
+ "enabled": true,
20
+ "interval": 5
21
+ }
22
+ }