nexo-brain 0.5.0 → 0.7.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.
package/README.md CHANGED
@@ -1,8 +1,12 @@
1
1
  # NEXO Brain — Your AI Gets a Brain
2
2
 
3
+ [![npm v0.6.0](https://img.shields.io/npm/v/nexo-brain?label=npm&color=purple)](https://www.npmjs.com/package/nexo-brain)
4
+ [![F1 0.588 on LoCoMo](https://img.shields.io/badge/LoCoMo_F1-0.588-brightgreen)](https://github.com/wazionapps/nexo/blob/main/benchmarks/locomo/results/)
5
+ [![+55% vs GPT-4](https://img.shields.io/badge/vs_GPT--4-%2B55%25-blue)](https://github.com/snap-research/locomo/issues/33)
3
6
  [![GitHub stars](https://img.shields.io/github/stars/wazionapps/nexo?style=social)](https://github.com/wazionapps/nexo/stargazers)
4
7
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
- [![GitHub Sponsors](https://img.shields.io/badge/Sponsor-%E2%9D%A4-pink)](https://github.com/sponsors/wazionapps)
8
+
9
+ > **v0.6.0** — Now ships with **full orchestration**: 5 automated hooks, mandatory post-mortem with self-critique, pre-compaction context preservation, reflection engine, and auto-migration. Plus: F1 **0.588** on [LoCoMo](https://github.com/snap-research/locomo) (ACL 2024) — outperforms GPT-4 by 55%. Runs on CPU. [Full results](benchmarks/locomo/results/)
6
10
 
7
11
  **NEXO Brain transforms any MCP-compatible AI agent from a stateless assistant into a cognitive partner that remembers, learns, forgets, adapts, and builds a relationship with you over time.**
8
12
 
@@ -72,7 +76,7 @@ NEXO Brain uses **Ebbinghaus forgetting curves** — memories naturally fade ove
72
76
 
73
77
  ### Semantic Search (Finding by Meaning)
74
78
 
75
- NEXO Brain doesn't search by keywords. It searches by **meaning** using vector embeddings (fastembed, 384 dimensions).
79
+ NEXO Brain doesn't search by keywords. It searches by **meaning** using vector embeddings (fastembed, 768 dimensions).
76
80
 
77
81
  Example: If you search for "deploy problems", NEXO Brain will find a memory about "SSH connection timeout on production server" — even though they share zero words. This is how human associative memory works.
78
82
 
@@ -126,9 +130,9 @@ Like a human brain, NEXO Brain has automated processes that run while you're not
126
130
 
127
131
  If your Mac was asleep during any scheduled process, NEXO Brain catches up in order when it wakes.
128
132
 
129
- ## Cognitive Features (v0.3.1)
133
+ ## Cognitive Features
130
134
 
131
- NEXO Brain v0.3.1 adds 21 cognitive tools on top of the 76 base tools, bringing the total to **97+ MCP tools**. These features implement cognitive science concepts that go beyond basic memory:
135
+ NEXO Brain provides 21 cognitive tools on top of the 76 base tools, totaling **97+ MCP tools**. These features implement cognitive science concepts that go beyond basic memory:
132
136
 
133
137
  ### Input Pipeline
134
138
 
@@ -144,6 +148,9 @@ NEXO Brain v0.3.1 adds 21 cognitive tools on top of the 76 base tools, bringing
144
148
  | Feature | What It Does |
145
149
  |---------|-------------|
146
150
  | **Pin / Snooze / Archive** | Granular lifecycle states for memories. Pin = never decays (critical knowledge). Snooze = temporarily hidden (revisit later). Archive = cold storage (searchable but inactive). |
151
+ | **Intelligent Chunking** | Adaptive chunking that respects sentence and paragraph boundaries. Produces semantically coherent chunks instead of arbitrary token splits, reducing retrieval noise. |
152
+ | **Adaptive Decay** | Decay rate adapts per memory based on access patterns: frequently-accessed memories decay slower, rarely-accessed ones fade faster. Prevents permanent clutter while keeping active knowledge sharp. |
153
+ | **Auto-Migration** | Formal schema migration system (schema_migrations table) tracks all database changes. Safe, reversible schema evolution for production systems — upgrades never lose data. |
147
154
  | **Auto-Merge Duplicates** | Batch cosine deduplication during the 03:00 sleep cycle. Respects sibling discrimination — similar memories about different contexts are kept separate. |
148
155
  | **Memory Dreaming** | Discovers hidden connections between recent memories during the 03:00 sleep cycle. Surfaces non-obvious patterns like "these three bugs all relate to the same root cause." |
149
156
 
@@ -152,6 +159,10 @@ NEXO Brain v0.3.1 adds 21 cognitive tools on top of the 76 base tools, bringing
152
159
  | Feature | What It Does |
153
160
  |---------|-------------|
154
161
  | **HyDE Query Expansion** | Generates hypothetical answer embeddings for richer semantic search. Instead of searching for "deploy error", it imagines what a helpful memory about deploy errors would look like, then searches for that. |
162
+ | **Hybrid Search (FTS5+BM25+RRF)** | Combines dense vector search with BM25 keyword search via Reciprocal Rank Fusion. Outperforms pure semantic search on precise terminology and code identifiers. |
163
+ | **Cross-Encoder Reranking** | After initial vector retrieval, a cross-encoder model rescores candidates for precision. The top-k results are reordered by true semantic relevance before being returned to the agent. |
164
+ | **Multi-Query Decomposition** | Complex questions are automatically split into sub-queries. Each component is retrieved independently, then fused for a higher-quality answer — improves recall on multi-faceted prompts. |
165
+ | **Temporal Indexing** | Memories are indexed by time in addition to semantics. Time-sensitive queries ("what did we decide last Tuesday?") use temporal proximity scoring alongside semantic similarity. |
155
166
  | **Spreading Activation** | Graph-based co-activation network. Memories retrieved together reinforce each other's connections, building an associative web that improves over time. |
156
167
  | **Recall Explanations** | Transparent score breakdown for every retrieval result. Shows exactly why a memory was returned: semantic similarity, recency, access frequency, and co-activation bonuses. |
157
168
 
@@ -161,6 +172,7 @@ NEXO Brain v0.3.1 adds 21 cognitive tools on top of the 76 base tools, bringing
161
172
  |---------|-------------|
162
173
  | **Prospective Memory** | Context-triggered reminders that fire when conversation topics match, not just by date. "Remind me about X when we discuss Y" works naturally. |
163
174
  | **Hook Auto-capture** | Extracts decisions, corrections, and factual statements from conversations automatically. You don't need to explicitly say "remember this" — the system detects what's worth storing. |
175
+ | **Session Summaries** | Automatic end-of-session summarization that distills key decisions, errors, and follow-ups into a compact diary entry. The next session starts with full context — not a cold slate. |
164
176
 
165
177
  ## Benchmark: LoCoMo (ACL 2024)
166
178
 
@@ -168,21 +180,83 @@ NEXO Brain was evaluated on [LoCoMo](https://github.com/snap-research/locomo) (A
168
180
 
169
181
  | System | F1 | Adversarial | Hardware |
170
182
  |---|---|---|---|
183
+ | **NEXO Brain v0.5.0** | **0.588** | **93.3%** | **CPU only** |
171
184
  | GPT-4 (128K full context) | 0.379 | — | GPU cloud |
172
185
  | Gemini Pro 1.0 | 0.313 | — | GPU cloud |
173
- | **NEXO Brain** | **0.297** | **89.2%** | **CPU only** |
174
186
  | LLaMA-3 70B | 0.295 | — | A100 GPU |
175
187
  | GPT-3.5 + Contriever RAG | 0.283 | — | GPU |
176
188
 
189
+ **+55% vs GPT-4. Running entirely on CPU.**
190
+
177
191
  **Key findings:**
178
- - Matches 70B-parameter models running entirely on CPU with 384-dim embeddings
179
- - 89.2% adversarial rejection rate — reliably says "I don't know" when information isn't available
180
- - 25s ingestion for 10 full conversations (no GPU, no batching)
181
- - 58.9% temporal recall on "when did X happen?" questions
192
+ - Outperforms GPT-4 (128K full context) by 55% on F1 score
193
+ - 93.3% adversarial rejection rate — reliably says "I don't know" when information isn't available
194
+ - 74.9% recall across 1,986 questions
195
+ - Open-domain F1: 0.637 | Multi-hop F1: 0.333 | Temporal F1: 0.326
196
+ - Runs on CPU with 768-dim embeddings (BAAI/bge-base-en-v1.5) — no GPU required
182
197
  - First MCP memory server benchmarked on a peer-reviewed dataset
183
198
 
184
199
  Full results in [`benchmarks/locomo/results/`](benchmarks/locomo/results/).
185
200
 
201
+ ## Full Orchestration System (v0.6.0)
202
+
203
+ Memory alone doesn't make a co-operator. What makes the difference is the **behavioral loop** — the automated discipline that ensures every session starts informed, runs with guardrails, and ends with self-reflection.
204
+
205
+ ### 5 Automated Hooks
206
+
207
+ These fire automatically at key moments in every Claude Code session:
208
+
209
+ | Hook | When | What It Does |
210
+ |------|------|-------------|
211
+ | **SessionStart** | Session opens | Generates a briefing from SQLite: overdue reminders, today's tasks, pending followups, active sessions |
212
+ | **Stop** | Session ends | Mandatory post-mortem: self-critique (5 questions), session buffer entry, followup creation, proactive seeds for next session |
213
+ | **PostToolUse** | After each tool call | Captures meaningful mutations to the Sensory Register |
214
+ | **PreCompact** | Before context compression | Saves checkpoint, reminds operator to write diary — prevents losing the thread |
215
+ | **Caffeinate** | Always (optional) | Keeps Mac awake for nocturnal cognitive processes |
216
+
217
+ ### The Session Lifecycle
218
+
219
+ ```
220
+ Session starts
221
+
222
+ SessionStart hook generates briefing
223
+
224
+ Operator reads diary, reminders, followups
225
+
226
+ Heartbeat on every interaction (sentiment, context shifts)
227
+
228
+ Guard check before every code edit
229
+
230
+ PreCompact hook saves context if conversation is compressed
231
+
232
+ Stop hook triggers mandatory post-mortem:
233
+ - Self-critique: 5 questions about what could be better
234
+ - Session buffer: structured entry for the reflection engine
235
+ - Followups: anything promised gets scheduled
236
+ - Proactive seeds: what can the next session do without being asked?
237
+
238
+ Reflection engine processes buffer (after 3+ sessions)
239
+
240
+ Nocturnal processes: decay, consolidation, self-audit, dreaming
241
+ ```
242
+
243
+ ### Reflection Engine
244
+
245
+ After 3+ sessions accumulate, the stop hook triggers `nexo-reflection.py`:
246
+ - Extracts recurring tasks, error patterns, mood trends
247
+ - Updates `user_model.json` with observed behavior
248
+ - No LLM required — runs as pure Python
249
+
250
+ ### Auto-Migration
251
+
252
+ Existing users upgrading from v0.5.0:
253
+ ```bash
254
+ npx nexo-brain # detects v0.5.0, migrates automatically
255
+ ```
256
+ - Updates hooks, core files, plugins, scripts
257
+ - **Never touches your data** (memories, learnings, preferences)
258
+ - Saves updated CLAUDE.md as reference (doesn't overwrite customizations)
259
+
186
260
  ## Quick Start
187
261
 
188
262
  ### Claude Code (Primary)
@@ -233,10 +307,12 @@ That's it. No need to run `claude` manually. Atlas will greet you immediately
233
307
  | Cognitive engine | Python: fastembed, numpy, vector search | pip packages |
234
308
  | MCP server | 97+ tools for memory, cognition, learning, guard | ~/.nexo/ |
235
309
  | Plugins | Guard, episodic memory, cognitive memory, entities, preferences | ~/.nexo/plugins/ |
236
- | Hooks | Session capture, briefing, stop detection | ~/.nexo/hooks/ |
310
+ | Hooks (5) | SessionStart briefing, Stop post-mortem, PostToolUse capture, PreCompact checkpoint, Caffeinate | ~/.nexo/hooks/ |
311
+ | Reflection engine | Processes session buffer, extracts patterns, updates user model | ~/.nexo/scripts/ |
312
+ | CLAUDE.md | Complete operator instructions (Codex, hooks, guard, trust, memory) | ~/.claude/CLAUDE.md |
237
313
  | LaunchAgents | Decay, sleep, audit, postmortem, catch-up | ~/Library/LaunchAgents/ |
238
314
  | Auto-update | Checks for new versions at boot | Built into catch-up |
239
- | Claude Code config | MCP server + hooks registered | ~/.claude/settings.json |
315
+ | Claude Code config | MCP server + 5 hooks registered | ~/.claude/settings.json |
240
316
 
241
317
  ### Requirements
242
318
 
package/bin/nexo-brain.js CHANGED
@@ -75,6 +75,120 @@ async function main() {
75
75
  process.exit(1);
76
76
  }
77
77
 
78
+ // Auto-migration: detect existing installation
79
+ const versionFile = path.join(NEXO_HOME, "version.json");
80
+ if (fs.existsSync(versionFile)) {
81
+ try {
82
+ const installed = JSON.parse(fs.readFileSync(versionFile, "utf8"));
83
+ const currentPkg = JSON.parse(fs.readFileSync(path.join(__dirname, "..", "package.json"), "utf8"));
84
+ const installedVersion = installed.version || "0.0.0";
85
+ const currentVersion = currentPkg.version;
86
+
87
+ if (installedVersion !== currentVersion) {
88
+ log(`Existing installation detected: v${installedVersion} → v${currentVersion}`);
89
+ log("Running auto-migration...");
90
+
91
+ // Update hooks
92
+ const hooksSrc = path.join(__dirname, "..", "src", "hooks");
93
+ const hooksDest = path.join(NEXO_HOME, "hooks");
94
+ fs.mkdirSync(hooksDest, { recursive: true });
95
+ ["session-start.sh", "capture-session.sh", "session-stop.sh", "pre-compact.sh", "caffeinate-guard.sh"].forEach((h) => {
96
+ const src = path.join(hooksSrc, h);
97
+ const dest = path.join(hooksDest, h);
98
+ if (fs.existsSync(src)) {
99
+ fs.copyFileSync(src, dest);
100
+ fs.chmodSync(dest, "755");
101
+ }
102
+ });
103
+ log(" Hooks updated.");
104
+
105
+ // Update core Python files
106
+ const srcDir = path.join(__dirname, "..", "src");
107
+ ["server.py", "db.py", "plugin_loader.py", "cognitive.py",
108
+ "tools_sessions.py", "tools_coordination.py", "tools_reminders.py",
109
+ "tools_reminders_crud.py", "tools_learnings.py", "tools_credentials.py",
110
+ "tools_task_history.py", "tools_menu.py"].forEach((f) => {
111
+ const src = path.join(srcDir, f);
112
+ if (fs.existsSync(src)) {
113
+ fs.copyFileSync(src, path.join(NEXO_HOME, f));
114
+ }
115
+ });
116
+ log(" Core files updated.");
117
+
118
+ // Update plugins
119
+ const pluginsSrc = path.join(srcDir, "plugins");
120
+ const pluginsDest = path.join(NEXO_HOME, "plugins");
121
+ fs.mkdirSync(pluginsDest, { recursive: true });
122
+ if (fs.existsSync(pluginsSrc)) {
123
+ fs.readdirSync(pluginsSrc).filter(f => f.endsWith(".py")).forEach((f) => {
124
+ fs.copyFileSync(path.join(pluginsSrc, f), path.join(pluginsDest, f));
125
+ });
126
+ }
127
+ log(" Plugins updated.");
128
+
129
+ // Update scripts
130
+ const scriptsSrc = path.join(srcDir, "scripts");
131
+ const scriptsDest = path.join(NEXO_HOME, "scripts");
132
+ fs.mkdirSync(scriptsDest, { recursive: true });
133
+ if (fs.existsSync(scriptsSrc)) {
134
+ fs.readdirSync(scriptsSrc).filter(f => f.endsWith(".py") || f.endsWith(".sh")).forEach((f) => {
135
+ fs.copyFileSync(path.join(scriptsSrc, f), path.join(scriptsDest, f));
136
+ });
137
+ }
138
+ log(" Scripts updated.");
139
+
140
+ // Add PreCompact hook to settings.json if missing
141
+ let settings = {};
142
+ if (fs.existsSync(CLAUDE_SETTINGS)) {
143
+ try { settings = JSON.parse(fs.readFileSync(CLAUDE_SETTINGS, "utf8")); } catch {}
144
+ }
145
+ if (settings.hooks && !settings.hooks.PreCompact) {
146
+ settings.hooks.PreCompact = [];
147
+ }
148
+ if (settings.hooks && settings.hooks.PreCompact) {
149
+ const hookPath = path.join(hooksDest, "pre-compact.sh");
150
+ if (!settings.hooks.PreCompact.some((h) => h.command && h.command.includes("pre-compact.sh"))) {
151
+ settings.hooks.PreCompact.push({
152
+ type: "command",
153
+ command: `bash ${hookPath}`,
154
+ });
155
+ fs.writeFileSync(CLAUDE_SETTINGS, JSON.stringify(settings, null, 2));
156
+ log(" PreCompact hook added to Claude Code settings.");
157
+ }
158
+ }
159
+
160
+ // Update version file
161
+ fs.writeFileSync(versionFile, JSON.stringify({
162
+ version: currentVersion,
163
+ installed_at: installed.installed_at,
164
+ updated_at: new Date().toISOString(),
165
+ migrated_from: installedVersion,
166
+ }, null, 2));
167
+
168
+ // Save updated CLAUDE.md template as reference (don't overwrite user's)
169
+ const templateSrc = path.join(__dirname, "..", "templates", "CLAUDE.md.template");
170
+ if (fs.existsSync(templateSrc)) {
171
+ const operatorName = installed.operator_name || "NEXO";
172
+ let claudeMd = fs.readFileSync(templateSrc, "utf8")
173
+ .replace(/\{\{NAME\}\}/g, operatorName)
174
+ .replace(/\{\{NEXO_HOME\}\}/g, NEXO_HOME);
175
+ fs.writeFileSync(path.join(NEXO_HOME, "CLAUDE.md.updated"), claudeMd);
176
+ log(` Updated CLAUDE.md template saved to ~/.nexo/CLAUDE.md.updated`);
177
+ log(` Review and merge changes into your ~/.claude/CLAUDE.md if desired.`);
178
+ }
179
+
180
+ console.log("");
181
+ log(`Migration complete: v${installedVersion} → v${currentVersion}`);
182
+ log("Your data (memories, learnings, preferences) is untouched.");
183
+ console.log("");
184
+ rl.close();
185
+ return;
186
+ }
187
+ } catch (e) {
188
+ // Version file corrupt — proceed with fresh install
189
+ }
190
+ }
191
+
78
192
  // Find or install Homebrew (needed for Python)
79
193
  let hasBrew = run("which brew");
80
194
  if (!hasBrew) {
@@ -249,6 +363,7 @@ async function main() {
249
363
  JSON.stringify({
250
364
  version: pkg.version,
251
365
  installed_at: new Date().toISOString(),
366
+ operator_name: operatorName,
252
367
  files_updated: 0,
253
368
  }, null, 2)
254
369
  );
@@ -421,7 +536,7 @@ Operator name: ${operatorName}
421
536
  const hooksSrcDir = path.join(__dirname, "..", "src", "hooks");
422
537
  const hooksDestDir = path.join(NEXO_HOME, "hooks");
423
538
  fs.mkdirSync(hooksDestDir, { recursive: true });
424
- ["session-start.sh", "capture-session.sh", "session-stop.sh"].forEach((h) => {
539
+ ["session-start.sh", "capture-session.sh", "session-stop.sh", "pre-compact.sh"].forEach((h) => {
425
540
  const src = path.join(hooksSrcDir, h);
426
541
  const dest = path.join(hooksDestDir, h);
427
542
  if (fs.existsSync(src)) {
@@ -460,6 +575,16 @@ Operator name: ${operatorName}
460
575
  settings.hooks.Stop.push(stopHook);
461
576
  }
462
577
 
578
+ // PreCompact hook (saves context before conversation compression)
579
+ if (!settings.hooks.PreCompact) settings.hooks.PreCompact = [];
580
+ const preCompactHook = {
581
+ type: "command",
582
+ command: `bash ${path.join(hooksDestDir, "pre-compact.sh")}`,
583
+ };
584
+ if (!settings.hooks.PreCompact.some((h) => h.command && h.command.includes("pre-compact.sh"))) {
585
+ settings.hooks.PreCompact.push(preCompactHook);
586
+ }
587
+
463
588
  const settingsDir = path.dirname(CLAUDE_SETTINGS);
464
589
  fs.mkdirSync(settingsDir, { recursive: true });
465
590
  fs.writeFileSync(CLAUDE_SETTINGS, JSON.stringify(settings, null, 2));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nexo-brain",
3
- "version": "0.5.0",
3
+ "version": "0.7.0",
4
4
  "mcpName": "io.github.wazionapps/nexo",
5
5
  "description": "NEXO — Cognitive co-operator for Claude Code. Atkinson-Shiffrin memory, semantic RAG, trust scoring, and metacognitive error prevention.",
6
6
  "bin": {