nexo-brain 6.0.2 → 6.0.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.
- package/.claude-plugin/plugin.json +1 -1
- package/README.md +3 -1
- package/bin/nexo-brain.js +28 -1
- package/package.json +1 -1
- package/src/auto_update.py +62 -0
- package/src/plugins/guard.py +55 -2
- package/src/resonance_map.py +22 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nexo-brain",
|
|
3
|
-
"version": "6.0.
|
|
3
|
+
"version": "6.0.3",
|
|
4
4
|
"description": "Local cognitive runtime for Claude Code \u2014 persistent memory, overnight learning, doctor diagnostics, personal scripts, recovery-aware jobs, startup preflight, and optional dashboard/power helper.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "NEXO Brain",
|
package/README.md
CHANGED
|
@@ -18,7 +18,9 @@
|
|
|
18
18
|
|
|
19
19
|
[Watch the overview video](https://nexo-brain.com/watch/) · [Watch on YouTube](https://www.youtube.com/watch?v=i2lkGhKyVqI) · [Open the infographic](https://nexo-brain.com/assets/nexo-brain-infographic-v5.png)
|
|
20
20
|
|
|
21
|
-
Version `6.0.
|
|
21
|
+
Version `6.0.3` is the current packaged-runtime line: double-fix release. (1) `resonance_tiers.json` is now published to `~/.nexo/brain/resonance_tiers.json` — the public contract path defined by v6.0.0 and consumed by NEXO Desktop ≥ 0.12.0. Pre-v6.0.3 the installer wrote it to `~/.nexo/resonance_tiers.json`, so Desktop failed to start Claude with *"NEXO Brain contract missing"* on every fresh install and every update from 6.0.0 / 6.0.1 / 6.0.2 unless the user copied the file by hand. An idempotent migration in `auto_update.py` promotes legacy runtimes on `nexo update`. (2) `nexo_guard_check` now persists the caller's SID on every `guard_checks` row (env `NEXO_SID` → env `CLAUDE_SESSION_ID` via `sessions.external_session_id` → most-recently-updated `sessions` row). Pre-v6.0.3 it hardcoded `session_id=""`, so `hook_guardrails._session_has_guard_check` never matched and strict-protocol sessions tripped *"no guard_check seen for this session"* after every successful call.
|
|
22
|
+
|
|
23
|
+
Previously in `6.0.2`: adds the reserved caller prefix `personal/*` so scripts living in `~/.nexo/scripts/` can invoke the automation backend with their own caller id without editing `src/resonance_map.py`. New kwarg `tier` (`"maximo"` / `"alto"` / `"medio"` / `"bajo"`) on `run_automation_prompt`, `run_automation_interactive`, `nexo_helper.run_automation_text`, `nexo_helper.run_automation_json`, and `nexo-agent-run.py --tier`. Precedence for `personal/*` callers: explicit `tier=` → explicit `reasoning_effort=` → `calibration.preferences.default_resonance` → `DEFAULT_RESONANCE` (`alto`). Registered callers keep their behaviour unchanged. New guide: [`docs/personal-scripts-guide.md`](docs/personal-scripts-guide.md).
|
|
22
24
|
|
|
23
25
|
Previously in `6.0.1`: hotfix on top of the 6.0.0 release. `protocol_settings.py` now treats the process as interactive when **either** stdin+stdout are TTYs **or** `NEXO_INTERACTIVE=1` is exported — closes the gap where NEXO Desktop 0.12.0 spawned `claude` through pipes and Brain fell back to `lenient` even with a human in the loop. The `PostToolUse` hook also gains an inbox autodetect stage: when the session has unread `nexo_send` messages and has gone 60s+ without a heartbeat, it emits a `systemMessage` asking the agent to run `nexo_heartbeat` and consume them. Rate-limited to one reminder per minute per SID (new `hook_inbox_reminders` table, migration m42). Added `sessions.last_heartbeat_ts`, stamped by every successful heartbeat. `NEXO_INTERACTIVE` is an internal Brain↔Electron contract — not user-facing, not a resurrection of the removed `NEXO_PROTOCOL_STRICTNESS`.
|
|
24
26
|
|
package/bin/nexo-brain.js
CHANGED
|
@@ -235,7 +235,6 @@ function getCoreRuntimeFlatFiles(srcDir = path.join(__dirname, "..", "src")) {
|
|
|
235
235
|
"runtime_power.py",
|
|
236
236
|
"requirements.txt",
|
|
237
237
|
"model_defaults.json",
|
|
238
|
-
"resonance_tiers.json",
|
|
239
238
|
];
|
|
240
239
|
const discoveredRootModules = fs.existsSync(srcDir)
|
|
241
240
|
? fs.readdirSync(srcDir)
|
|
@@ -257,6 +256,29 @@ function getCoreRuntimePackages() {
|
|
|
257
256
|
return ["db", "cognitive", "doctor"];
|
|
258
257
|
}
|
|
259
258
|
|
|
259
|
+
// Brain contracts — files the NEXO Brain publishes to consumers like
|
|
260
|
+
// NEXO Desktop under ~/.nexo/brain/. These are NOT code (they live outside
|
|
261
|
+
// getCoreRuntimeFlatFiles for that reason) but data contracts with a stable
|
|
262
|
+
// path that external clients read. Keep in sync with docs/contracts/.
|
|
263
|
+
function publishBrainContracts(srcDir = path.join(__dirname, "..", "src"), nexoHome = NEXO_HOME) {
|
|
264
|
+
const brainDir = path.join(nexoHome, "brain");
|
|
265
|
+
fs.mkdirSync(brainDir, { recursive: true });
|
|
266
|
+
const contracts = ["resonance_tiers.json"];
|
|
267
|
+
contracts.forEach((name) => {
|
|
268
|
+
const src = path.join(srcDir, name);
|
|
269
|
+
if (fs.existsSync(src)) {
|
|
270
|
+
fs.copyFileSync(src, path.join(brainDir, name));
|
|
271
|
+
}
|
|
272
|
+
});
|
|
273
|
+
// Clean up legacy location: before v6.0.3 the file was written to
|
|
274
|
+
// NEXO_HOME/resonance_tiers.json. Remove it so only the contract path
|
|
275
|
+
// remains authoritative.
|
|
276
|
+
const legacy = path.join(nexoHome, "resonance_tiers.json");
|
|
277
|
+
if (fs.existsSync(legacy)) {
|
|
278
|
+
try { fs.unlinkSync(legacy); } catch (_) { /* best-effort */ }
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
260
282
|
function resolveLaunchAgentPath(home) {
|
|
261
283
|
const parts = ["/opt/homebrew/bin", "/usr/local/bin", "/usr/bin", "/bin",
|
|
262
284
|
path.join(home, ".local/bin"), path.join(home, ".nexo/bin")];
|
|
@@ -1654,6 +1676,8 @@ async function main() {
|
|
|
1654
1676
|
copyDirRec(pkgSrc, path.join(NEXO_HOME, pkg));
|
|
1655
1677
|
}
|
|
1656
1678
|
});
|
|
1679
|
+
// Publish Brain contracts to ~/.nexo/brain/ (read by NEXO Desktop et al.)
|
|
1680
|
+
publishBrainContracts(srcDir, NEXO_HOME);
|
|
1657
1681
|
log(" Core files updated.");
|
|
1658
1682
|
|
|
1659
1683
|
// Reconcile Python dependencies after updating code (mirrors fresh-install logic)
|
|
@@ -2490,6 +2514,9 @@ async function main() {
|
|
|
2490
2514
|
}
|
|
2491
2515
|
});
|
|
2492
2516
|
|
|
2517
|
+
// Publish Brain contracts to ~/.nexo/brain/ (read by NEXO Desktop et al.)
|
|
2518
|
+
publishBrainContracts(srcDir, NEXO_HOME);
|
|
2519
|
+
|
|
2493
2520
|
// Runtime CLI wrapper lives in NEXO_HOME/bin so it survives npx installs.
|
|
2494
2521
|
const runtimeCli = [
|
|
2495
2522
|
"#!/usr/bin/env bash",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nexo-brain",
|
|
3
|
-
"version": "6.0.
|
|
3
|
+
"version": "6.0.3",
|
|
4
4
|
"mcpName": "io.github.wazionapps/nexo",
|
|
5
5
|
"description": "NEXO Brain \u2014 Shared brain for AI agents. Persistent memory, semantic RAG, natural forgetting, metacognitive guard, trust scoring, 150+ MCP tools. Works with Claude Code, Codex, Claude Desktop & any MCP client. 100% local, free.",
|
|
6
6
|
"homepage": "https://nexo-brain.com",
|
package/src/auto_update.py
CHANGED
|
@@ -973,6 +973,57 @@ def _migrate_effort_to_resonance(dest: Path = NEXO_HOME) -> list[str]:
|
|
|
973
973
|
return actions
|
|
974
974
|
|
|
975
975
|
|
|
976
|
+
def _relocate_resonance_tiers_contract(dest: Path = NEXO_HOME) -> list[str]:
|
|
977
|
+
"""Ensure ``resonance_tiers.json`` lives at the public contract path
|
|
978
|
+
``NEXO_HOME/brain/resonance_tiers.json`` and purge the legacy copy at
|
|
979
|
+
``NEXO_HOME/resonance_tiers.json``.
|
|
980
|
+
|
|
981
|
+
Context: v6.0.0 defined the public contract (read by NEXO Desktop) as
|
|
982
|
+
``~/.nexo/brain/resonance_tiers.json`` but the installer kept copying
|
|
983
|
+
the file to ``~/.nexo/resonance_tiers.json`` (legacy flat-file layout),
|
|
984
|
+
so Desktop failed with *"NEXO Brain contract missing"* until the user
|
|
985
|
+
moved the file by hand. v6.0.3 publishes straight to ``brain/`` and
|
|
986
|
+
this migration reconciles existing runtimes.
|
|
987
|
+
|
|
988
|
+
Idempotent: no-op once the contract file is in ``brain/`` and the
|
|
989
|
+
legacy file is gone. Never raises — migration must not block an update.
|
|
990
|
+
"""
|
|
991
|
+
actions: list[str] = []
|
|
992
|
+
brain_dir = dest / "brain"
|
|
993
|
+
contract_path = brain_dir / "resonance_tiers.json"
|
|
994
|
+
legacy_path = dest / "resonance_tiers.json"
|
|
995
|
+
|
|
996
|
+
try:
|
|
997
|
+
brain_dir.mkdir(parents=True, exist_ok=True)
|
|
998
|
+
except Exception as exc:
|
|
999
|
+
actions.append(f"resonance-contract-relocate-warning:mkdir:{exc.__class__.__name__}")
|
|
1000
|
+
return actions
|
|
1001
|
+
|
|
1002
|
+
# If the contract already exists in brain/, just drop the legacy copy.
|
|
1003
|
+
if contract_path.is_file():
|
|
1004
|
+
if legacy_path.is_file():
|
|
1005
|
+
try:
|
|
1006
|
+
legacy_path.unlink()
|
|
1007
|
+
actions.append("resonance-contract-relocate:legacy-removed")
|
|
1008
|
+
except Exception as exc:
|
|
1009
|
+
actions.append(f"resonance-contract-relocate-warning:unlink:{exc.__class__.__name__}")
|
|
1010
|
+
return actions
|
|
1011
|
+
|
|
1012
|
+
# Contract missing from brain/ — promote the legacy file if present.
|
|
1013
|
+
if legacy_path.is_file():
|
|
1014
|
+
try:
|
|
1015
|
+
contract_path.write_bytes(legacy_path.read_bytes())
|
|
1016
|
+
legacy_path.unlink()
|
|
1017
|
+
actions.append("resonance-contract-relocate:moved-to-brain")
|
|
1018
|
+
except Exception as exc:
|
|
1019
|
+
actions.append(f"resonance-contract-relocate-warning:move:{exc.__class__.__name__}")
|
|
1020
|
+
# If neither exists, the caller (nexo-brain.js publishBrainContracts)
|
|
1021
|
+
# will write it from the package source on the next install pass; nothing
|
|
1022
|
+
# for this Python migration to do.
|
|
1023
|
+
|
|
1024
|
+
return actions
|
|
1025
|
+
|
|
1026
|
+
|
|
976
1027
|
def _bootstrap_profile_from_calibration_meta(dest: Path = NEXO_HOME) -> list[str]:
|
|
977
1028
|
"""Create ``brain/profile.json`` from ``calibration.json`` fields when the
|
|
978
1029
|
profile file does not exist yet.
|
|
@@ -2894,6 +2945,17 @@ def _run_runtime_post_sync(dest: Path = NEXO_HOME, progress_fn=None) -> tuple[bo
|
|
|
2894
2945
|
except Exception as exc:
|
|
2895
2946
|
actions.append(f"profile-bootstrap-warning:{exc.__class__.__name__}")
|
|
2896
2947
|
|
|
2948
|
+
# v6.0.3 — relocate resonance_tiers.json from NEXO_HOME root (pre-v6.0.3
|
|
2949
|
+
# layout) to NEXO_HOME/brain/ (public contract path consumed by
|
|
2950
|
+
# NEXO Desktop). Idempotent; safe no-op once the move is done.
|
|
2951
|
+
try:
|
|
2952
|
+
_emit_progress(progress_fn, "Relocating resonance_tiers contract to brain/...")
|
|
2953
|
+
reloc_actions = _relocate_resonance_tiers_contract(dest)
|
|
2954
|
+
for action in reloc_actions:
|
|
2955
|
+
actions.append(action)
|
|
2956
|
+
except Exception as exc:
|
|
2957
|
+
actions.append(f"resonance-contract-relocate-warning:{exc.__class__.__name__}")
|
|
2958
|
+
|
|
2897
2959
|
# v6.0.0 purge — drop legacy fields that moved elsewhere in v6.
|
|
2898
2960
|
# client_runtime_profiles.*.{model,reasoning_effort} → resonance_tiers.json.
|
|
2899
2961
|
# preferences.protocol_strictness → TTY/no-TTY detection.
|
package/src/plugins/guard.py
CHANGED
|
@@ -11,6 +11,55 @@ from pathlib import Path
|
|
|
11
11
|
from db import get_db, find_similar_learnings, extract_keywords, search_learnings, search_changes
|
|
12
12
|
|
|
13
13
|
|
|
14
|
+
def _resolve_active_sid(conn) -> str:
|
|
15
|
+
"""Resolve the SID of the caller invoking this guard check.
|
|
16
|
+
|
|
17
|
+
Order of precedence:
|
|
18
|
+
1. ``NEXO_SID`` env var (headless crons + wrapped CLI set this).
|
|
19
|
+
2. ``CLAUDE_SESSION_ID`` env var translated via
|
|
20
|
+
``sessions.external_session_id`` / ``sessions.claude_session_id``.
|
|
21
|
+
3. The most-recently-updated session in ``sessions`` (fallback for
|
|
22
|
+
MCP tool calls where the broker doesn't forward env vars but a
|
|
23
|
+
single active session exists).
|
|
24
|
+
|
|
25
|
+
Returns an empty string if nothing resolves. The caller MUST handle
|
|
26
|
+
the empty-string case explicitly — persisting ``session_id=""`` was
|
|
27
|
+
the v6.0.2 bug that left ``missing_file_guard`` blind to successful
|
|
28
|
+
guard checks.
|
|
29
|
+
"""
|
|
30
|
+
env_sid = (os.environ.get("NEXO_SID") or "").strip()
|
|
31
|
+
if env_sid.startswith("nexo-"):
|
|
32
|
+
return env_sid
|
|
33
|
+
|
|
34
|
+
external_candidates = [env_sid] if env_sid else []
|
|
35
|
+
claude_sid = (os.environ.get("CLAUDE_SESSION_ID") or "").strip()
|
|
36
|
+
if claude_sid:
|
|
37
|
+
external_candidates.append(claude_sid)
|
|
38
|
+
for cand in external_candidates:
|
|
39
|
+
try:
|
|
40
|
+
row = conn.execute(
|
|
41
|
+
"SELECT sid FROM sessions "
|
|
42
|
+
"WHERE external_session_id = ? OR claude_session_id = ? "
|
|
43
|
+
"ORDER BY last_update_epoch DESC LIMIT 1",
|
|
44
|
+
(cand, cand),
|
|
45
|
+
).fetchone()
|
|
46
|
+
except Exception:
|
|
47
|
+
row = None
|
|
48
|
+
if row and row["sid"]:
|
|
49
|
+
return str(row["sid"])
|
|
50
|
+
|
|
51
|
+
try:
|
|
52
|
+
row = conn.execute(
|
|
53
|
+
"SELECT sid FROM sessions "
|
|
54
|
+
"ORDER BY last_update_epoch DESC LIMIT 1"
|
|
55
|
+
).fetchone()
|
|
56
|
+
except Exception:
|
|
57
|
+
row = None
|
|
58
|
+
if row and row["sid"]:
|
|
59
|
+
return str(row["sid"])
|
|
60
|
+
return ""
|
|
61
|
+
|
|
62
|
+
|
|
14
63
|
def _split_applies_to(applies_to: str) -> list[str]:
|
|
15
64
|
return [item.strip() for item in str(applies_to or "").split(",") if item.strip()]
|
|
16
65
|
|
|
@@ -370,11 +419,15 @@ def handle_guard_check(files: str = "", area: str = "", include_schemas: str = "
|
|
|
370
419
|
(time.time(), lid)
|
|
371
420
|
)
|
|
372
421
|
|
|
373
|
-
# Log the guard check
|
|
422
|
+
# Log the guard check — v6.0.3 fix: resolve the caller's SID instead of
|
|
423
|
+
# inserting the empty string. Pre-v6.0.3 every row landed with
|
|
424
|
+
# session_id='' so missing_file_guard could not find the guard call
|
|
425
|
+
# from hook_guardrails._session_has_guard_check and blocked forever.
|
|
426
|
+
active_sid = _resolve_active_sid(conn)
|
|
374
427
|
conn.execute(
|
|
375
428
|
"INSERT INTO guard_checks (session_id, files, area, learnings_returned, blocking_rules_returned) "
|
|
376
429
|
"VALUES (?, ?, ?, ?, ?)",
|
|
377
|
-
(
|
|
430
|
+
(active_sid, files, area, len(result["learnings"]) + len(result["universal_rules"]),
|
|
378
431
|
len(result["blocking_rules"]))
|
|
379
432
|
)
|
|
380
433
|
conn.commit()
|
package/src/resonance_map.py
CHANGED
|
@@ -46,6 +46,7 @@ future scripts from silently inheriting the wrong tier.
|
|
|
46
46
|
from __future__ import annotations
|
|
47
47
|
|
|
48
48
|
import json
|
|
49
|
+
import os
|
|
49
50
|
from pathlib import Path
|
|
50
51
|
from typing import Tuple
|
|
51
52
|
|
|
@@ -65,7 +66,27 @@ from typing import Tuple
|
|
|
65
66
|
|
|
66
67
|
TIERS = ("maximo", "alto", "medio", "bajo")
|
|
67
68
|
|
|
68
|
-
|
|
69
|
+
# Resolution order for the contract file:
|
|
70
|
+
# 1) ~/.nexo/brain/resonance_tiers.json (v6.0.3+ public contract path, shared
|
|
71
|
+
# with NEXO Desktop and any external client)
|
|
72
|
+
# 2) Legacy NEXO_HOME/resonance_tiers.json (pre-v6.0.3 runtime layout)
|
|
73
|
+
# 3) Package source src/resonance_tiers.json (dev checkouts / tests)
|
|
74
|
+
def _resolve_resonance_path() -> Path:
|
|
75
|
+
nexo_home = os.environ.get("NEXO_HOME") or str(Path.home() / ".nexo")
|
|
76
|
+
candidates = [
|
|
77
|
+
Path(nexo_home) / "brain" / "resonance_tiers.json",
|
|
78
|
+
Path(nexo_home) / "resonance_tiers.json",
|
|
79
|
+
Path(__file__).resolve().parent / "resonance_tiers.json",
|
|
80
|
+
]
|
|
81
|
+
for candidate in candidates:
|
|
82
|
+
if candidate.is_file():
|
|
83
|
+
return candidate
|
|
84
|
+
# No contract present: return the canonical path so the ValueError raised
|
|
85
|
+
# at load time points at where the contract should live.
|
|
86
|
+
return candidates[0]
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
_RESONANCE_JSON_PATH = _resolve_resonance_path()
|
|
69
90
|
|
|
70
91
|
|
|
71
92
|
def _normalize_tier_entry(entry: dict) -> dict[str, tuple[str, str]]:
|