nexo-brain 1.5.2 → 1.5.4

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
@@ -130,10 +130,22 @@ Like a human brain, NEXO Brain has automated processes that run while you're not
130
130
  |------|---------|---------------|
131
131
  | 03:00 | Decay + memory consolidation + merge duplicates + dreaming | Deep sleep consolidation |
132
132
  | 04:00 | Clean expired data, prune redundant memories | Synaptic pruning |
133
+ | 04:30 | **Deep Sleep** — analyze full session transcripts for uncaptured corrections, protocol violations, missed commitments | REM sleep review |
133
134
  | 07:00 | Self-audit, health checks, metrics | Waking up + orientation |
134
135
  | 23:30 | Process day's events, extract patterns | Pre-sleep reflection |
135
136
  | Boot | Catch-up: run anything missed while computer was off | -- |
136
137
 
138
+ #### Deep Sleep (v1.5.2)
139
+
140
+ Deep Sleep reads your **complete session transcripts** (not just the diary summary) and finds what the agent missed during the day:
141
+
142
+ - **Uncaptured corrections** — user corrections the agent didn't save as learnings
143
+ - **Protocol violations** — guard_check skipped, trust not adjusted, change_log omitted
144
+ - **Missed commitments** — things mentioned but never tracked as followups
145
+ - **Quality issues** — agent declaring "done" when work wasn't complete
146
+
147
+ Uses Claude CLI in `--bare` mode (no hooks, no CLAUDE.md interference). Catch-up system re-runs yesterday if the Mac was off.
148
+
137
149
  If your Mac was asleep during any scheduled process, NEXO Brain catches up in order when it wakes.
138
150
 
139
151
  ## Cognitive Cortex
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nexo-brain",
3
- "version": "1.5.2",
3
+ "version": "1.5.4",
4
4
  "mcpName": "io.github.wazionapps/nexo",
5
5
  "description": "NEXO — Cognitive co-operator for Claude Code. Atkinson-Shiffrin memory, semantic RAG, knowledge graph, HNSW vector indexing, trust scoring, and metacognitive error prevention.",
6
6
  "bin": {
@@ -3,6 +3,7 @@ import json, math, re
3
3
  import numpy as np
4
4
  from datetime import datetime, timedelta
5
5
  from cognitive._core import _get_db, embed, cosine_similarity, _blob_to_array, _array_to_blob, EMBEDDING_DIM, DISCRIMINATING_ENTITIES
6
+ from cognitive._ingest import _sanitize_memory_content
6
7
 
7
8
 
8
9
  def _quarantine_stats():
@@ -1,14 +1,13 @@
1
1
  #!/bin/bash
2
- # NEXO Deep Sleep — Complete overnight session transcript analysis
3
- # Reads ALL Claude Code session transcripts from the day, analyzes with
4
- # Claude CLI (bare mode), and applies findings as feedback memories.
2
+ # NEXO Deep Sleep — Complete overnight session analysis
3
+ # Runs at 4:30 AM via LaunchAgent
4
+ # Reads ALL session transcripts from the day, analyzes with Claude CLI,
5
+ # and applies findings (learnings, feedbacks, followups, trust adjustments)
5
6
  #
6
7
  # Features:
7
8
  # - Catch-up: if yesterday was missed (Mac off/asleep), runs it first
8
- # - Uses --bare mode to avoid loading NEXO hooks during analysis
9
- # - Requires ANTHROPIC_API_KEY env var or ~/.claude/anthropic-api-key.txt
10
- #
11
- # Install: Add as LaunchAgent for daily execution (recommended: 4:30 AM)
9
+ # - Logs to ~/claude/logs/deep-sleep.log
10
+ # - Marks completion in .last-run for watchdog monitoring
12
11
 
13
12
  set -euo pipefail
14
13
 
@@ -26,9 +25,11 @@ run_analysis() {
26
25
  local DATE="$1"
27
26
  log "=== Deep Sleep starting for $DATE ==="
28
27
 
28
+ # Step 1: Collect transcripts
29
29
  log "Step 1: Collecting transcripts for $DATE..."
30
30
  python3 "$SCRIPT_DIR/deep-sleep/collect_transcripts.py" "$DATE" 2>&1 | tee -a "$LOG_DIR/deep-sleep.log"
31
31
 
32
+ # Check if transcripts were found
32
33
  if [ ! -f "$DEEP_SLEEP_DIR/$DATE-transcripts.json" ]; then
33
34
  log "No transcripts file generated for $DATE. Skipping."
34
35
  return 0
@@ -40,6 +41,7 @@ run_analysis() {
40
41
  return 0
41
42
  fi
42
43
 
44
+ # Step 2: Analyze with Claude CLI
43
45
  log "Step 2: Analyzing $SESSIONS sessions with Claude CLI..."
44
46
  python3 "$SCRIPT_DIR/deep-sleep/analyze_session.py" "$DATE" 2>&1 | tee -a "$LOG_DIR/deep-sleep.log"
45
47
 
@@ -48,6 +50,7 @@ run_analysis() {
48
50
  return 1
49
51
  fi
50
52
 
53
+ # Step 3: Apply findings
51
54
  log "Step 3: Applying findings for $DATE..."
52
55
  python3 "$SCRIPT_DIR/deep-sleep/apply_findings.py" "$DATE" 2>&1 | tee -a "$LOG_DIR/deep-sleep.log"
53
56
 
@@ -55,22 +58,24 @@ run_analysis() {
55
58
  return 0
56
59
  }
57
60
 
58
- # --- Catch-up: check if yesterday was missed ---
61
+ # --- Catch-up: check if the day before yesterday was missed ---
59
62
  YESTERDAY=$(date -v-1d +%Y-%m-%d 2>/dev/null || date -d "yesterday" +%Y-%m-%d 2>/dev/null)
63
+ DAY_BEFORE=$(date -v-2d +%Y-%m-%d 2>/dev/null || date -d "2 days ago" +%Y-%m-%d 2>/dev/null)
60
64
  LAST_RUN=""
61
65
  if [ -f "$LAST_RUN_FILE" ]; then
62
66
  LAST_RUN=$(cat "$LAST_RUN_FILE")
63
67
  fi
64
68
 
65
- if [ -n "$YESTERDAY" ] && [ "$LAST_RUN" != "$YESTERDAY" ] && [ "$LAST_RUN" != "$TODAY" ]; then
66
- if [ ! -f "$DEEP_SLEEP_DIR/$YESTERDAY-analysis.json" ]; then
67
- log "*** CATCH-UP: $YESTERDAY was missed. Running now. ***"
68
- run_analysis "$YESTERDAY" || log "Catch-up for $YESTERDAY failed."
69
+ if [ -n "$DAY_BEFORE" ] && [ "$LAST_RUN" != "$DAY_BEFORE" ] && [ "$LAST_RUN" != "$YESTERDAY" ]; then
70
+ # Day before yesterday wasn't analyzed — catch up
71
+ if [ ! -f "$DEEP_SLEEP_DIR/$DAY_BEFORE-analysis.json" ]; then
72
+ log "*** CATCH-UP: $DAY_BEFORE was missed. Running now. ***"
73
+ run_analysis "$DAY_BEFORE" || log "Catch-up for $DAY_BEFORE failed."
69
74
  fi
70
75
  fi
71
76
 
72
- # --- Run today's analysis ---
73
- run_analysis "$TODAY"
77
+ # --- Run yesterday's analysis (main task — at 4:30 AM, today has no sessions yet) ---
78
+ run_analysis "$YESTERDAY"
74
79
 
75
- # Mark completion
76
- echo "$TODAY" > "$LAST_RUN_FILE"
80
+ # Mark completion with yesterday's date (what we actually analyzed)
81
+ echo "$YESTERDAY" > "$LAST_RUN_FILE"