nexo-brain 0.8.9 → 0.9.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 +14 -6
- package/bin/nexo-brain.js +8 -2
- package/package.json +1 -1
- package/src/__pycache__/db.cpython-314.pyc +0 -0
- package/src/__pycache__/tools_credentials.cpython-314.pyc +0 -0
- package/src/db.py +178 -5
- package/src/plugins/__pycache__/episodic_memory.cpython-314.pyc +0 -0
- package/src/plugins/episodic_memory.py +118 -20
- package/src/tools_credentials.py +4 -0
package/README.md
CHANGED
|
@@ -1,16 +1,22 @@
|
|
|
1
1
|
# NEXO Brain — Your AI Gets a Brain
|
|
2
2
|
|
|
3
|
-
[](https://www.npmjs.com/package/nexo-brain)
|
|
4
4
|
[](https://github.com/wazionapps/nexo/blob/main/benchmarks/locomo/results/)
|
|
5
5
|
[](https://github.com/snap-research/locomo/issues/33)
|
|
6
6
|
[](https://github.com/wazionapps/nexo/stargazers)
|
|
7
7
|
[](https://opensource.org/licenses/MIT)
|
|
8
8
|
|
|
9
|
-
> **v0.8.
|
|
9
|
+
> **v0.8.10** — Knowledge Graph (988 bi-temporal nodes, D3 visualization), Web Dashboard (6 pages at localhost:6174), Cross-Platform support (Linux + Windows + WSL), Session keepalive, PEP 668 compliance, full English translation, and 4 new KG tools.
|
|
10
10
|
|
|
11
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.**
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
<p align="center">
|
|
14
|
+
<a href="https://www.youtube.com/watch?v=J0hCWnYU4UY">
|
|
15
|
+
<img src="assets/nexo-brain-infographic-v4.png" alt="NEXO Brain Architecture" width="700">
|
|
16
|
+
</a>
|
|
17
|
+
</p>
|
|
18
|
+
|
|
19
|
+
[Watch the 1-minute overview on YouTube](https://www.youtube.com/watch?v=J0hCWnYU4UY) · [Watch the full deep-dive](https://www.youtube.com/watch?v=-uvhicUhGTY)
|
|
14
20
|
|
|
15
21
|
Every time you close a session, everything is lost. Your agent doesn't remember yesterday's decisions, repeats the same mistakes, and starts from zero. NEXO Brain fixes this with a cognitive architecture modeled after how human memory actually works.
|
|
16
22
|
|
|
@@ -257,7 +263,7 @@ npx nexo-brain # detects v0.5.0, migrates automatically
|
|
|
257
263
|
- **Never touches your data** (memories, learnings, preferences)
|
|
258
264
|
- Saves updated CLAUDE.md as reference (doesn't overwrite customizations)
|
|
259
265
|
|
|
260
|
-
## Knowledge Graph & Dashboard (v0.8
|
|
266
|
+
## Knowledge Graph & Dashboard (v0.8)
|
|
261
267
|
|
|
262
268
|
### Knowledge Graph
|
|
263
269
|
A bi-temporal entity-relationship graph with 988 nodes and 896 edges. Entities and relationships carry both valid-time (when the fact was true) and system-time (when it was recorded), enabling temporal queries like "what did we know about X last Tuesday?". BFS traversal discovers multi-hop connections between concepts. Event-sourced edges with smart dedup (ADD/UPDATE/NOOP) prevent redundant writes while preserving full history.
|
|
@@ -268,7 +274,9 @@ A bi-temporal entity-relationship graph with 988 nodes and 896 edges. Entities a
|
|
|
268
274
|
A visual interface at `localhost:6174` with 6 pages: Overview (system health at a glance), Graph (interactive D3.js visualization of the knowledge graph), Memory (browse and search all memory stores), Somatic (pain map per file/area), Adaptive (personality signals and weights), and Sessions (active and historical sessions). Built with FastAPI backend and D3.js frontend.
|
|
269
275
|
|
|
270
276
|
### Cross-Platform Support
|
|
271
|
-
|
|
277
|
+
Full Linux support and Windows via WSL. The installer detects the platform and configures the appropriate process manager (LaunchAgents on macOS, catch-up on startup for Linux). PEP 668 compliance (venv on Ubuntu 24.04+). Session keepalive prevents phantom sessions during long tasks. Opportunistic maintenance runs cognitive processes when resources are available.
|
|
278
|
+
|
|
279
|
+
> **Windows users:** NEXO Brain requires [WSL (Windows Subsystem for Linux)](https://learn.microsoft.com/en-us/windows/wsl/install). Install WSL first, then run `npx nexo-brain` inside the Ubuntu/WSL terminal.
|
|
272
280
|
|
|
273
281
|
### Storage Router
|
|
274
282
|
A new abstraction layer routes storage operations through a unified interface, making the system multi-tenant ready. Each operator's data is isolated while sharing the same cognitive engine.
|
|
@@ -343,7 +351,7 @@ That's it. No need to run `claude` manually. Atlas will greet you immediately
|
|
|
343
351
|
|
|
344
352
|
### Requirements
|
|
345
353
|
|
|
346
|
-
- **macOS
|
|
354
|
+
- **macOS or Linux** (Windows via [WSL](https://learn.microsoft.com/en-us/windows/wsl/install))
|
|
347
355
|
- **Node.js 18+** (for the installer)
|
|
348
356
|
- **Claude Opus (latest version) strongly recommended.** NEXO Brain provides 109+ MCP tools across 19 categories. This cognitive load requires a top-tier model with large context window. Smaller models (Haiku, Sonnet) may struggle with tool selection and produce inconsistent results. Opus handles all 109+ tools without hesitation.
|
|
349
357
|
- Python 3, Homebrew, and Claude Code are installed automatically if missing.
|
package/bin/nexo-brain.js
CHANGED
|
@@ -77,8 +77,14 @@ async function main() {
|
|
|
77
77
|
|
|
78
78
|
// Check prerequisites
|
|
79
79
|
const platform = process.platform;
|
|
80
|
-
if (platform
|
|
81
|
-
log(
|
|
80
|
+
if (platform === "win32") {
|
|
81
|
+
log("Windows detected. NEXO Brain requires WSL (Windows Subsystem for Linux).");
|
|
82
|
+
log("Install WSL: https://learn.microsoft.com/en-us/windows/wsl/install");
|
|
83
|
+
log("Then run this command inside WSL (Ubuntu terminal), not PowerShell/CMD.");
|
|
84
|
+
process.exit(1);
|
|
85
|
+
}
|
|
86
|
+
if (platform !== "darwin" && platform !== "linux") {
|
|
87
|
+
log(`Unsupported platform: ${platform}. NEXO supports macOS and Linux (Windows via WSL).`);
|
|
82
88
|
process.exit(1);
|
|
83
89
|
}
|
|
84
90
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nexo-brain",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.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": {
|
|
Binary file
|
|
Binary file
|
package/src/db.py
CHANGED
|
@@ -898,6 +898,36 @@ def _m8_adaptive_log_and_somatic(conn):
|
|
|
898
898
|
conn.execute("CREATE INDEX IF NOT EXISTS idx_somatic_events_projected ON somatic_events(projected)")
|
|
899
899
|
|
|
900
900
|
|
|
901
|
+
def _m10_diary_archive(conn):
|
|
902
|
+
"""Permanent diary archive — diaries are never truly deleted, just moved here."""
|
|
903
|
+
conn.execute("""
|
|
904
|
+
CREATE TABLE IF NOT EXISTS diary_archive (
|
|
905
|
+
id INTEGER PRIMARY KEY,
|
|
906
|
+
session_id TEXT NOT NULL,
|
|
907
|
+
created_at TEXT NOT NULL,
|
|
908
|
+
decisions TEXT NOT NULL,
|
|
909
|
+
discarded TEXT,
|
|
910
|
+
pending TEXT,
|
|
911
|
+
context_next TEXT,
|
|
912
|
+
summary TEXT NOT NULL,
|
|
913
|
+
mental_state TEXT,
|
|
914
|
+
domain TEXT,
|
|
915
|
+
user_signals TEXT,
|
|
916
|
+
self_critique TEXT DEFAULT '',
|
|
917
|
+
source TEXT DEFAULT 'claude',
|
|
918
|
+
archived_at TEXT DEFAULT (datetime('now'))
|
|
919
|
+
)
|
|
920
|
+
""")
|
|
921
|
+
conn.execute("""
|
|
922
|
+
CREATE INDEX IF NOT EXISTS idx_diary_archive_created
|
|
923
|
+
ON diary_archive (created_at)
|
|
924
|
+
""")
|
|
925
|
+
conn.execute("""
|
|
926
|
+
CREATE INDEX IF NOT EXISTS idx_diary_archive_domain
|
|
927
|
+
ON diary_archive (domain)
|
|
928
|
+
""")
|
|
929
|
+
|
|
930
|
+
|
|
901
931
|
def _m9_maintenance_schedule(conn):
|
|
902
932
|
conn.execute("""
|
|
903
933
|
CREATE TABLE IF NOT EXISTS maintenance_schedule (
|
|
@@ -931,6 +961,7 @@ MIGRATIONS = [
|
|
|
931
961
|
(7, "diary_source_and_draft", _m7_diary_source_and_draft),
|
|
932
962
|
(8, "adaptive_log_and_somatic", _m8_adaptive_log_and_somatic),
|
|
933
963
|
(9, "maintenance_schedule", _m9_maintenance_schedule),
|
|
964
|
+
(10, "diary_archive", _m10_diary_archive),
|
|
934
965
|
]
|
|
935
966
|
|
|
936
967
|
|
|
@@ -1763,7 +1794,12 @@ def delete_credential(service: str, key: str = None) -> bool:
|
|
|
1763
1794
|
|
|
1764
1795
|
|
|
1765
1796
|
def get_credential(service: str, key: str = None) -> list[dict]:
|
|
1766
|
-
"""Get credential(s). If key=None, return all for the service.
|
|
1797
|
+
"""Get credential(s). If key=None, return all for the service.
|
|
1798
|
+
|
|
1799
|
+
When exact match fails, performs fuzzy search across service, key,
|
|
1800
|
+
and notes fields. Returns results tagged with _fuzzy=True so
|
|
1801
|
+
the caller can differentiate suggestions from exact hits.
|
|
1802
|
+
"""
|
|
1767
1803
|
conn = get_db()
|
|
1768
1804
|
if key:
|
|
1769
1805
|
rows = conn.execute(
|
|
@@ -1773,7 +1809,29 @@ def get_credential(service: str, key: str = None) -> list[dict]:
|
|
|
1773
1809
|
rows = conn.execute(
|
|
1774
1810
|
"SELECT * FROM credentials WHERE service = ?", (service,)
|
|
1775
1811
|
).fetchall()
|
|
1776
|
-
|
|
1812
|
+
if rows:
|
|
1813
|
+
return [dict(r) for r in rows]
|
|
1814
|
+
|
|
1815
|
+
# Fuzzy fallback: search term in service, key and notes (not value — too noisy)
|
|
1816
|
+
# Prioritize: service/key matches first, notes-only matches second
|
|
1817
|
+
term = f"%{service}%"
|
|
1818
|
+
fuzzy_rows = conn.execute(
|
|
1819
|
+
"SELECT *, "
|
|
1820
|
+
"CASE WHEN service LIKE ? THEN 0 "
|
|
1821
|
+
" WHEN key LIKE ? THEN 1 "
|
|
1822
|
+
" ELSE 2 END AS _rank "
|
|
1823
|
+
"FROM credentials WHERE "
|
|
1824
|
+
"service LIKE ? OR key LIKE ? OR notes LIKE ? "
|
|
1825
|
+
"ORDER BY _rank ASC, service ASC, key ASC",
|
|
1826
|
+
(term, term, term, term, term),
|
|
1827
|
+
).fetchall()
|
|
1828
|
+
results = []
|
|
1829
|
+
for r in fuzzy_rows:
|
|
1830
|
+
d = dict(r)
|
|
1831
|
+
d["_fuzzy"] = True
|
|
1832
|
+
d.pop("_rank", None)
|
|
1833
|
+
results.append(d)
|
|
1834
|
+
return results
|
|
1777
1835
|
|
|
1778
1836
|
|
|
1779
1837
|
def list_credentials(service: str = None) -> list[dict]:
|
|
@@ -2262,15 +2320,37 @@ def search_decisions(query: str = '', domain: str = '', days: int = 30) -> list[
|
|
|
2262
2320
|
# ── Session Diary ────────────────────────────────────────────────
|
|
2263
2321
|
|
|
2264
2322
|
def cleanup_old_diaries(retention_days: int = 180) -> int:
|
|
2265
|
-
"""
|
|
2323
|
+
"""Archive then delete session_diary entries older than retention_days.
|
|
2324
|
+
|
|
2325
|
+
Diaries are moved to diary_archive (permanent) before being removed from
|
|
2326
|
+
the active session_diary table. Nothing is ever truly lost.
|
|
2327
|
+
"""
|
|
2266
2328
|
conn = get_db()
|
|
2329
|
+
cutoff = f"-{retention_days} days"
|
|
2330
|
+
|
|
2331
|
+
# Archive before deleting — permanent subconscious memory
|
|
2332
|
+
try:
|
|
2333
|
+
conn.execute("""
|
|
2334
|
+
INSERT OR IGNORE INTO diary_archive
|
|
2335
|
+
(id, session_id, created_at, decisions, discarded, pending,
|
|
2336
|
+
context_next, summary, mental_state, domain, user_signals,
|
|
2337
|
+
self_critique, source)
|
|
2338
|
+
SELECT id, session_id, created_at, decisions, discarded, pending,
|
|
2339
|
+
context_next, summary, mental_state, domain, user_signals,
|
|
2340
|
+
self_critique, source
|
|
2341
|
+
FROM session_diary
|
|
2342
|
+
WHERE created_at < datetime('now', ?)
|
|
2343
|
+
""", (cutoff,))
|
|
2344
|
+
except Exception:
|
|
2345
|
+
pass # Table may not exist yet (pre-migration)
|
|
2346
|
+
|
|
2267
2347
|
ids = [str(r[0]) for r in conn.execute(
|
|
2268
2348
|
"SELECT id FROM session_diary WHERE created_at < datetime('now', ?)",
|
|
2269
|
-
(
|
|
2349
|
+
(cutoff,)
|
|
2270
2350
|
).fetchall()]
|
|
2271
2351
|
cursor = conn.execute(
|
|
2272
2352
|
"DELETE FROM session_diary WHERE created_at < datetime('now', ?)",
|
|
2273
|
-
(
|
|
2353
|
+
(cutoff,)
|
|
2274
2354
|
)
|
|
2275
2355
|
for did in ids:
|
|
2276
2356
|
conn.execute("DELETE FROM unified_search WHERE source = 'diary' AND source_id = ?", (did,))
|
|
@@ -2309,6 +2389,99 @@ def check_session_has_diary(session_id: str) -> bool:
|
|
|
2309
2389
|
return row is not None
|
|
2310
2390
|
|
|
2311
2391
|
|
|
2392
|
+
# ── Diary Archive (permanent subconscious) ──────────────────────
|
|
2393
|
+
|
|
2394
|
+
|
|
2395
|
+
def diary_archive_search(query: str = '', domain: str = '',
|
|
2396
|
+
year: int = 0, month: int = 0,
|
|
2397
|
+
limit: int = 20) -> list[dict]:
|
|
2398
|
+
"""Search the permanent diary archive. Supports text search, domain filter, and date filter.
|
|
2399
|
+
|
|
2400
|
+
Args:
|
|
2401
|
+
query: Text to search in summary, decisions, mental_state, pending
|
|
2402
|
+
domain: Filter by domain (e.g. 'wazion', 'my-store')
|
|
2403
|
+
year: Filter by year (e.g. 2026)
|
|
2404
|
+
month: Filter by month (1-12), requires year
|
|
2405
|
+
limit: Max results (default 20)
|
|
2406
|
+
"""
|
|
2407
|
+
conn = get_db()
|
|
2408
|
+
try:
|
|
2409
|
+
conn.execute("SELECT 1 FROM diary_archive LIMIT 1")
|
|
2410
|
+
except Exception:
|
|
2411
|
+
return [] # Table doesn't exist yet
|
|
2412
|
+
|
|
2413
|
+
conditions = []
|
|
2414
|
+
params = []
|
|
2415
|
+
|
|
2416
|
+
if query:
|
|
2417
|
+
words = query.strip().split()
|
|
2418
|
+
for word in words:
|
|
2419
|
+
conditions.append(
|
|
2420
|
+
"(summary LIKE ? OR decisions LIKE ? OR mental_state LIKE ? "
|
|
2421
|
+
"OR pending LIKE ? OR self_critique LIKE ?)"
|
|
2422
|
+
)
|
|
2423
|
+
w = f"%{word}%"
|
|
2424
|
+
params.extend([w, w, w, w, w])
|
|
2425
|
+
|
|
2426
|
+
if domain:
|
|
2427
|
+
conditions.append("domain = ?")
|
|
2428
|
+
params.append(domain)
|
|
2429
|
+
|
|
2430
|
+
if year:
|
|
2431
|
+
if month:
|
|
2432
|
+
date_start = f"{year:04d}-{month:02d}-01"
|
|
2433
|
+
if month == 12:
|
|
2434
|
+
date_end = f"{year + 1:04d}-01-01"
|
|
2435
|
+
else:
|
|
2436
|
+
date_end = f"{year:04d}-{month + 1:02d}-01"
|
|
2437
|
+
conditions.append("created_at >= ? AND created_at < ?")
|
|
2438
|
+
params.extend([date_start, date_end])
|
|
2439
|
+
else:
|
|
2440
|
+
conditions.append("created_at >= ? AND created_at < ?")
|
|
2441
|
+
params.extend([f"{year:04d}-01-01", f"{year + 1:04d}-01-01"])
|
|
2442
|
+
|
|
2443
|
+
where = " AND ".join(conditions) if conditions else "1=1"
|
|
2444
|
+
|
|
2445
|
+
rows = conn.execute(f"""
|
|
2446
|
+
SELECT id, session_id, created_at, summary, decisions, domain,
|
|
2447
|
+
mental_state, pending, self_critique, source
|
|
2448
|
+
FROM diary_archive
|
|
2449
|
+
WHERE {where}
|
|
2450
|
+
ORDER BY created_at DESC
|
|
2451
|
+
LIMIT ?
|
|
2452
|
+
""", params + [limit]).fetchall()
|
|
2453
|
+
return [dict(r) for r in rows]
|
|
2454
|
+
|
|
2455
|
+
|
|
2456
|
+
def diary_archive_read(diary_id: int) -> dict | None:
|
|
2457
|
+
"""Read a single archived diary entry by ID — full content."""
|
|
2458
|
+
conn = get_db()
|
|
2459
|
+
try:
|
|
2460
|
+
row = conn.execute(
|
|
2461
|
+
"SELECT * FROM diary_archive WHERE id = ?", (diary_id,)
|
|
2462
|
+
).fetchone()
|
|
2463
|
+
return dict(row) if row else None
|
|
2464
|
+
except Exception:
|
|
2465
|
+
return None
|
|
2466
|
+
|
|
2467
|
+
|
|
2468
|
+
def diary_archive_stats() -> dict:
|
|
2469
|
+
"""Get archive statistics: count, date range, domains."""
|
|
2470
|
+
conn = get_db()
|
|
2471
|
+
try:
|
|
2472
|
+
count = conn.execute("SELECT COUNT(*) FROM diary_archive").fetchone()[0]
|
|
2473
|
+
if count == 0:
|
|
2474
|
+
return {"count": 0, "oldest": None, "newest": None, "domains": []}
|
|
2475
|
+
oldest = conn.execute("SELECT MIN(created_at) FROM diary_archive").fetchone()[0]
|
|
2476
|
+
newest = conn.execute("SELECT MAX(created_at) FROM diary_archive").fetchone()[0]
|
|
2477
|
+
domains = [r[0] for r in conn.execute(
|
|
2478
|
+
"SELECT DISTINCT domain FROM diary_archive WHERE domain IS NOT NULL AND domain != '' ORDER BY domain"
|
|
2479
|
+
).fetchall()]
|
|
2480
|
+
return {"count": count, "oldest": oldest, "newest": newest, "domains": domains}
|
|
2481
|
+
except Exception:
|
|
2482
|
+
return {"count": 0, "oldest": None, "newest": None, "domains": []}
|
|
2483
|
+
|
|
2484
|
+
|
|
2312
2485
|
# ── Session Diary Drafts ─────────────────────────────────────────
|
|
2313
2486
|
|
|
2314
2487
|
|
|
Binary file
|
|
@@ -163,11 +163,11 @@ def handle_memory_review_queue(days: int = 0) -> str:
|
|
|
163
163
|
def handle_session_diary_write(decisions: str, summary: str,
|
|
164
164
|
discarded: str = '', pending: str = '',
|
|
165
165
|
context_next: str = '', mental_state: str = '',
|
|
166
|
-
|
|
166
|
+
user_signals: str = '',
|
|
167
167
|
domain: str = '',
|
|
168
168
|
session_id: str = '',
|
|
169
169
|
self_critique: str = '') -> str:
|
|
170
|
-
"""Write session diary entry at end of session.
|
|
170
|
+
"""Write session diary entry at end of session. Mandatory before closing.
|
|
171
171
|
|
|
172
172
|
Args:
|
|
173
173
|
decisions: What was decided and why (JSON array or structured text)
|
|
@@ -176,16 +176,16 @@ def handle_session_diary_write(decisions: str, summary: str,
|
|
|
176
176
|
pending: Items left unresolved, with doubt level
|
|
177
177
|
context_next: What the next session should know to continue effectively
|
|
178
178
|
mental_state: Internal state to transfer — thread of thought, tone, observations not yet shared, momentum. Written in first person as NEXO.
|
|
179
|
-
|
|
180
|
-
domain: Project context
|
|
179
|
+
user_signals: Observable signals from the user during session — response speed (fast='s' vs detailed explanations), tone (direct, frustrated, exploratory, excited), corrections given, topics they initiated vs topics NEXO initiated. Factual observations only, not interpretations.
|
|
180
|
+
domain: Project context (e.g. project name, area)
|
|
181
181
|
session_id: Current session ID
|
|
182
|
-
self_critique: MANDATORY. Honest post-mortem: What should I have done proactively? Did
|
|
182
|
+
self_critique: MANDATORY. Honest post-mortem: What should I have done proactively? Did the user ask for something I should have detected? Did I repeat known errors? What concrete rule would prevent the recurrence? If clean session: 'No self-critique — clean session.'
|
|
183
183
|
"""
|
|
184
184
|
sid = session_id or 'unknown'
|
|
185
185
|
# Clean up draft — manual diary supersedes it
|
|
186
186
|
from db import delete_diary_draft
|
|
187
187
|
delete_diary_draft(sid)
|
|
188
|
-
result = write_session_diary(sid, decisions, summary, discarded, pending, context_next, mental_state, domain=domain, user_signals=
|
|
188
|
+
result = write_session_diary(sid, decisions, summary, discarded, pending, context_next, mental_state, domain=domain, user_signals=user_signals, self_critique=self_critique)
|
|
189
189
|
if "error" in result:
|
|
190
190
|
return f"ERROR: {result['error']}"
|
|
191
191
|
_cognitive_ingest_safe(summary, "diary", f"diary#{result.get('id','')}", f"Session {sid} summary", domain)
|
|
@@ -256,8 +256,8 @@ def handle_session_diary_read(session_id: str = '', last_n: int = 3, last_day: b
|
|
|
256
256
|
lines.append(f" For next session: {d['context_next'][:200]}")
|
|
257
257
|
if d.get('mental_state'):
|
|
258
258
|
lines.append(f" Mental state: {d['mental_state'][:300]}")
|
|
259
|
-
if d.get('
|
|
260
|
-
lines.append(f"
|
|
259
|
+
if d.get('user_signals'):
|
|
260
|
+
lines.append(f" User signals: {d['user_signals'][:300]}")
|
|
261
261
|
return "\n".join(lines)
|
|
262
262
|
|
|
263
263
|
|
|
@@ -271,7 +271,7 @@ def handle_change_log(files: str, what_changed: str, why: str,
|
|
|
271
271
|
files: File path(s) modified (comma-separated if multiple)
|
|
272
272
|
what_changed: What was modified — functions, lines, behavior change
|
|
273
273
|
why: WHY this change was needed — the root cause, not just "fix bug"
|
|
274
|
-
triggered_by: What triggered this — bug report, metric,
|
|
274
|
+
triggered_by: What triggered this — bug report, metric, user request, followup ID
|
|
275
275
|
affects: What systems/users/flows this change impacts
|
|
276
276
|
risks: What could go wrong — regressions, edge cases, dependencies
|
|
277
277
|
verify: How to verify this works — what to check, followup ID if created
|
|
@@ -351,8 +351,18 @@ def handle_recall(query: str, days: int = 30) -> str:
|
|
|
351
351
|
days: Look back N days (default 30)
|
|
352
352
|
"""
|
|
353
353
|
results = recall(query, days)
|
|
354
|
-
|
|
355
|
-
|
|
354
|
+
|
|
355
|
+
# Fallback to diary archive if few results (subconscious memory)
|
|
356
|
+
archive_results = []
|
|
357
|
+
if len(results) < 5:
|
|
358
|
+
try:
|
|
359
|
+
from db import diary_archive_search
|
|
360
|
+
archive_results = diary_archive_search(query=query, limit=5)
|
|
361
|
+
except Exception:
|
|
362
|
+
pass
|
|
363
|
+
|
|
364
|
+
if not results and not archive_results:
|
|
365
|
+
return f"No results for '{query}' in the last {days} days or in the archive."
|
|
356
366
|
|
|
357
367
|
# v1.2: Passive rehearsal — strengthen matching cognitive memories
|
|
358
368
|
try:
|
|
@@ -365,18 +375,19 @@ def handle_recall(query: str, days: int = 30) -> str:
|
|
|
365
375
|
pass
|
|
366
376
|
|
|
367
377
|
SOURCE_LABELS = {
|
|
368
|
-
'change_log': '[
|
|
369
|
-
'change': '[
|
|
378
|
+
'change_log': '[CHANGE]',
|
|
379
|
+
'change': '[CHANGE]',
|
|
370
380
|
'decision': '[DECISION]',
|
|
371
381
|
'learning': '[LEARNING]',
|
|
372
382
|
'followup': '[FOLLOWUP]',
|
|
373
|
-
'diary': '[
|
|
374
|
-
'
|
|
375
|
-
'
|
|
383
|
+
'diary': '[DIARY]',
|
|
384
|
+
'diary_archive': '[ARCHIVE]',
|
|
385
|
+
'entity': '[ENTITY]',
|
|
386
|
+
'file': '[FILE]',
|
|
376
387
|
'code': '[CODE]',
|
|
377
388
|
}
|
|
378
389
|
|
|
379
|
-
lines = [f"RECALL '{query}' — {len(results)}
|
|
390
|
+
lines = [f"RECALL '{query}' — {len(results)} result(s):"]
|
|
380
391
|
for r in results:
|
|
381
392
|
source = r.get('source', '?')
|
|
382
393
|
label = SOURCE_LABELS.get(source, f"[{source.upper()}]")
|
|
@@ -389,8 +400,93 @@ def handle_recall(query: str, days: int = 30) -> str:
|
|
|
389
400
|
lines.append(f" {title}")
|
|
390
401
|
if snippet:
|
|
391
402
|
lines.append(f" {snippet}")
|
|
392
|
-
|
|
393
|
-
|
|
403
|
+
|
|
404
|
+
if archive_results:
|
|
405
|
+
lines.append(f"\n--- SUBCONSCIOUS (diary archive) — {len(archive_results)} result(s) ---")
|
|
406
|
+
for r in archive_results:
|
|
407
|
+
lines.append(f"\n [ARCHIVE] #{r['id']} ({r['created_at'][:10]}) [{r.get('domain', '?')}]")
|
|
408
|
+
lines.append(f" {r['summary'][:200]}")
|
|
409
|
+
elif len(results) < 5:
|
|
410
|
+
lines.append(f"\n Only {len(results)} results. Diary archive empty (auto-populated after 180 days).")
|
|
411
|
+
return "\n".join(lines)
|
|
412
|
+
|
|
413
|
+
|
|
414
|
+
def handle_diary_archive_search(
|
|
415
|
+
query: str = "",
|
|
416
|
+
domain: str = "",
|
|
417
|
+
year: int = 0,
|
|
418
|
+
month: int = 0,
|
|
419
|
+
limit: int = 20
|
|
420
|
+
) -> str:
|
|
421
|
+
"""Search the permanent diary archive (subconscious memory). Use for 'last year', 'months ago', 'in February', etc.
|
|
422
|
+
|
|
423
|
+
Args:
|
|
424
|
+
query: Text to search in diary content
|
|
425
|
+
domain: Filter by project domain (e.g. 'wazion', 'my-store')
|
|
426
|
+
year: Filter by year (e.g. 2026)
|
|
427
|
+
month: Filter by month (1-12), requires year
|
|
428
|
+
limit: Max results (default 20)
|
|
429
|
+
"""
|
|
430
|
+
from db import diary_archive_search, diary_archive_stats
|
|
431
|
+
|
|
432
|
+
if not query and not domain and not year:
|
|
433
|
+
stats = diary_archive_stats()
|
|
434
|
+
if stats["count"] == 0:
|
|
435
|
+
return "Archive empty — diaries are archived automatically after 180 days."
|
|
436
|
+
return (
|
|
437
|
+
f"DIARY ARCHIVE STATS:\n"
|
|
438
|
+
f" Total: {stats['count']} archived diaries\n"
|
|
439
|
+
f" Range: {stats['oldest']} -> {stats['newest']}\n"
|
|
440
|
+
f" Domains: {', '.join(stats['domains']) if stats['domains'] else 'N/A'}\n"
|
|
441
|
+
f"\nUse query, domain, year/month to search."
|
|
442
|
+
)
|
|
443
|
+
|
|
444
|
+
results = diary_archive_search(query=query, domain=domain, year=year, month=month, limit=limit)
|
|
445
|
+
if not results:
|
|
446
|
+
return f"No results in archive for: query='{query}' domain='{domain}' year={year} month={month}"
|
|
447
|
+
|
|
448
|
+
lines = [f"DIARY ARCHIVE — {len(results)} result(s):"]
|
|
449
|
+
for r in results:
|
|
450
|
+
lines.append(f"\n [#{r['id']}] {r['created_at'][:10]} [{r.get('domain', '?')}]")
|
|
451
|
+
lines.append(f" {r['summary'][:200]}")
|
|
452
|
+
if r.get('decisions'):
|
|
453
|
+
lines.append(f" Decisions: {r['decisions'][:150]}")
|
|
454
|
+
if r.get('mental_state'):
|
|
455
|
+
lines.append(f" State: {r['mental_state'][:100]}")
|
|
456
|
+
return "\n".join(lines)
|
|
457
|
+
|
|
458
|
+
|
|
459
|
+
def handle_diary_archive_read(diary_id: int = 0) -> str:
|
|
460
|
+
"""Read a single archived diary entry in full detail.
|
|
461
|
+
|
|
462
|
+
Args:
|
|
463
|
+
diary_id: The archive diary ID (from search results)
|
|
464
|
+
"""
|
|
465
|
+
if not diary_id:
|
|
466
|
+
return "ERROR: diary_id required. Use nexo_diary_archive_search to find IDs."
|
|
467
|
+
|
|
468
|
+
from db import diary_archive_read
|
|
469
|
+
entry = diary_archive_read(diary_id)
|
|
470
|
+
if not entry:
|
|
471
|
+
return f"Diary #{diary_id} not found in the archive."
|
|
472
|
+
|
|
473
|
+
lines = [f"DIARY ARCHIVE #{entry['id']} — {entry['created_at']}"]
|
|
474
|
+
lines.append(f" Session: {entry['session_id']}")
|
|
475
|
+
lines.append(f" Domain: {entry.get('domain', 'N/A')}")
|
|
476
|
+
lines.append(f" Source: {entry.get('source', 'N/A')}")
|
|
477
|
+
lines.append(f"\nSUMMARY:\n {entry['summary']}")
|
|
478
|
+
if entry.get('decisions'):
|
|
479
|
+
lines.append(f"\nDECISIONS:\n {entry['decisions']}")
|
|
480
|
+
if entry.get('pending'):
|
|
481
|
+
lines.append(f"\nPENDING:\n {entry['pending']}")
|
|
482
|
+
if entry.get('mental_state'):
|
|
483
|
+
lines.append(f"\nMENTAL STATE:\n {entry['mental_state']}")
|
|
484
|
+
if entry.get('self_critique'):
|
|
485
|
+
lines.append(f"\nSELF-CRITIQUE:\n {entry['self_critique']}")
|
|
486
|
+
if entry.get('user_signals'):
|
|
487
|
+
lines.append(f"\nUSER SIGNALS:\n {entry['user_signals']}")
|
|
488
|
+
if entry.get('context_next'):
|
|
489
|
+
lines.append(f"\nCONTEXT FOR NEXT SESSION:\n {entry['context_next']}")
|
|
394
490
|
return "\n".join(lines)
|
|
395
491
|
|
|
396
492
|
|
|
@@ -404,5 +500,7 @@ TOOLS = [
|
|
|
404
500
|
(handle_memory_review_queue, "nexo_memory_review_queue", "Show decisions and learnings that are due for review"),
|
|
405
501
|
(handle_session_diary_write, "nexo_session_diary_write", "Write end-of-session diary with decisions, discards, and context for next session"),
|
|
406
502
|
(handle_session_diary_read, "nexo_session_diary_read", "Read recent session diaries for context continuity"),
|
|
407
|
-
(handle_recall, "nexo_recall", "Search across ALL NEXO memory — changes, decisions, learnings, followups, diary, entities, .md files, code files. For deep historical context (older sessions, past work), also
|
|
503
|
+
(handle_recall, "nexo_recall", "Search across ALL NEXO memory — changes, decisions, learnings, followups, diary, entities, .md files, code files. For deep historical context (older sessions, past work), also searches the diary archive."),
|
|
504
|
+
(handle_diary_archive_search, "nexo_diary_archive_search", "Search the permanent diary archive (subconscious memory). Diaries older than 180d are moved here forever. Use for historical lookups: 'last year', 'months ago', 'in February', etc."),
|
|
505
|
+
(handle_diary_archive_read, "nexo_diary_archive_read", "Read a single archived diary entry in full detail. Get the ID from diary_archive_search."),
|
|
408
506
|
]
|
package/src/tools_credentials.py
CHANGED
|
@@ -9,7 +9,11 @@ def handle_credential_get(service: str, key: str = '') -> str:
|
|
|
9
9
|
if not results:
|
|
10
10
|
target = f"{service}/{key}" if key else service
|
|
11
11
|
return f"ERROR: No credentials found for '{target}'."
|
|
12
|
+
is_fuzzy = any(r.get("_fuzzy") for r in results)
|
|
12
13
|
lines = []
|
|
14
|
+
if is_fuzzy:
|
|
15
|
+
lines.append(f"No exact match for '{service}'. Similar results ({len(results)}):")
|
|
16
|
+
lines.append("")
|
|
13
17
|
for r in results:
|
|
14
18
|
lines.append(f"CREDENTIAL {r['service']}/{r['key']}:")
|
|
15
19
|
lines.append(f" Value: {r['value']}")
|