nexo-brain 2.4.0 → 2.5.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.
Files changed (80) hide show
  1. package/README.md +65 -2
  2. package/bin/nexo-brain.js +208 -11
  3. package/bin/nexo.js +55 -0
  4. package/community/skills/.gitkeep +1 -0
  5. package/package.json +5 -2
  6. package/src/auto_update.py +158 -8
  7. package/src/cli.py +605 -0
  8. package/src/cognitive/_ingest.py +1 -1
  9. package/src/cognitive/_memory.py +4 -4
  10. package/src/crons/manifest.json +8 -0
  11. package/src/dashboard/app.py +700 -35
  12. package/src/dashboard/templates/adaptive.html +112 -218
  13. package/src/dashboard/templates/artifacts.html +133 -0
  14. package/src/dashboard/templates/backups.html +136 -0
  15. package/src/dashboard/templates/base.html +413 -0
  16. package/src/dashboard/templates/calendar.html +523 -654
  17. package/src/dashboard/templates/chat.html +356 -0
  18. package/src/dashboard/templates/claims.html +259 -0
  19. package/src/dashboard/templates/cortex.html +262 -0
  20. package/src/dashboard/templates/credentials.html +128 -0
  21. package/src/dashboard/templates/crons.html +370 -0
  22. package/src/dashboard/templates/dashboard.html +383 -578
  23. package/src/dashboard/templates/dreams.html +252 -0
  24. package/src/dashboard/templates/email.html +160 -0
  25. package/src/dashboard/templates/evolution.html +189 -0
  26. package/src/dashboard/templates/feed.html +249 -0
  27. package/src/dashboard/templates/followup_health.html +170 -0
  28. package/src/dashboard/templates/graph.html +191 -269
  29. package/src/dashboard/templates/guard.html +259 -0
  30. package/src/dashboard/templates/inbox.html +220 -346
  31. package/src/dashboard/templates/memory.html +317 -197
  32. package/src/dashboard/templates/operations.html +521 -698
  33. package/src/dashboard/templates/plugins.html +185 -0
  34. package/src/dashboard/templates/rules.html +246 -0
  35. package/src/dashboard/templates/sentiment.html +247 -0
  36. package/src/dashboard/templates/sessions.html +215 -182
  37. package/src/dashboard/templates/skills.html +329 -0
  38. package/src/dashboard/templates/somatic.html +68 -172
  39. package/src/dashboard/templates/triggers.html +133 -0
  40. package/src/dashboard/templates/trust.html +360 -0
  41. package/src/db/__init__.py +5 -0
  42. package/src/db/_schema.py +16 -1
  43. package/src/db/_sessions.py +22 -0
  44. package/src/db/_skills.py +980 -274
  45. package/src/doctor/__init__.py +1 -0
  46. package/src/doctor/formatters.py +52 -0
  47. package/src/doctor/models.py +44 -0
  48. package/src/doctor/orchestrator.py +42 -0
  49. package/src/doctor/providers/__init__.py +1 -0
  50. package/src/doctor/providers/boot.py +206 -0
  51. package/src/doctor/providers/deep.py +292 -0
  52. package/src/doctor/providers/runtime.py +686 -0
  53. package/src/hooks/post-compact.sh +5 -1
  54. package/src/hooks/pre-compact.sh +1 -1
  55. package/src/plugins/doctor.py +36 -0
  56. package/src/plugins/evolution.py +2 -1
  57. package/src/plugins/skills.py +135 -175
  58. package/src/requirements.txt +1 -0
  59. package/src/script_registry.py +322 -0
  60. package/src/scripts/deep-sleep/apply_findings.py +63 -48
  61. package/src/scripts/deep-sleep/extract-prompt.md +14 -0
  62. package/src/scripts/deep-sleep/synthesize-prompt.md +36 -0
  63. package/src/scripts/deep-sleep/synthesize.py +37 -1
  64. package/src/scripts/nexo-dashboard.sh +29 -0
  65. package/src/scripts/nexo-day-orchestrator.sh +139 -0
  66. package/src/scripts/nexo-evolution-run.py +2 -1
  67. package/src/scripts/nexo-learning-housekeep.py +1 -1
  68. package/src/scripts/nexo-watchdog.sh +1 -1
  69. package/src/server.py +9 -5
  70. package/src/skills/run-runtime-doctor/guide.md +12 -0
  71. package/src/skills/run-runtime-doctor/script.py +21 -0
  72. package/src/skills/run-runtime-doctor/skill.json +25 -0
  73. package/src/skills_runtime.py +347 -0
  74. package/src/tools_menu.py +3 -2
  75. package/src/tools_sessions.py +126 -0
  76. package/src/user_context.py +46 -0
  77. package/templates/nexo_helper.py +45 -0
  78. package/templates/script-template.py +44 -0
  79. package/templates/skill-script-template.py +39 -0
  80. package/templates/skill-template.md +33 -0
@@ -1,198 +1,318 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8">
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <title>NEXO Brain Cognitive Memory</title>
7
- <link rel="icon" type="image/svg+xml" href="/static/favicon.svg">
8
- <script src="https://cdn.tailwindcss.com"></script>
9
- <script>tailwind.config={theme:{extend:{fontFamily:{display:['Space Grotesk','system-ui','sans-serif'],mono:['JetBrains Mono','monospace']}}}}</script>
10
- <link href="https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap" rel="stylesheet">
11
- </head>
12
- <body class="bg-gray-950 text-slate-200">
13
-
14
- <!-- Sidebar: 56px icon-only fixed left -->
15
- <aside class="fixed left-0 top-0 bottom-0 w-14 bg-slate-900 border-r border-slate-800 flex flex-col items-center py-4 z-50">
16
- <!-- Logo -->
17
- <a href="/" class="mb-6 flex items-center justify-center w-8 h-8">
18
- <img src="/static/nexo-logo.png" alt="NEXO" class="w-7 h-7" onerror="this.style.display='none';this.nextElementSibling.style.display='flex'">
19
- <div style="display:none" class="w-7 h-7 rounded-lg bg-violet-600 items-center justify-center text-white text-xs font-bold font-display">N</div>
20
- </a>
21
-
22
- <!-- Nav icons -->
23
- <nav class="flex flex-col items-center gap-1 flex-1">
24
- <!-- Dashboard -->
25
- <a href="/" title="Dashboard" class="w-9 h-9 flex items-center justify-center rounded-lg text-slate-400 hover:text-slate-200 hover:bg-slate-800 transition-colors">
26
- <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="7" height="7"/><rect x="14" y="3" width="7" height="7"/><rect x="14" y="14" width="7" height="7"/><rect x="3" y="14" width="7" height="7"/></svg>
27
- </a>
28
- <!-- Operations -->
29
- <a href="/ops" title="Operations" class="w-9 h-9 flex items-center justify-center rounded-lg text-slate-400 hover:text-slate-200 hover:bg-slate-800 transition-colors">
30
- <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round"><line x1="8" y1="6" x2="21" y2="6"/><line x1="8" y1="12" x2="21" y2="12"/><line x1="8" y1="18" x2="21" y2="18"/><line x1="3" y1="6" x2="3.01" y2="6"/><line x1="3" y1="12" x2="3.01" y2="12"/><line x1="3" y1="18" x2="3.01" y2="18"/></svg>
31
- </a>
32
- <!-- Calendar -->
33
- <a href="/calendar" title="Calendar" class="w-9 h-9 flex items-center justify-center rounded-lg text-slate-400 hover:text-slate-200 hover:bg-slate-800 transition-colors">
34
- <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="4" width="18" height="18" rx="2"/><line x1="16" y1="2" x2="16" y2="6"/><line x1="8" y1="2" x2="8" y2="6"/><line x1="3" y1="10" x2="21" y2="10"/></svg>
35
- </a>
36
- <!-- Inbox -->
37
- <a href="/inbox" title="Inbox" class="w-9 h-9 flex items-center justify-center rounded-lg text-slate-400 hover:text-slate-200 hover:bg-slate-800 transition-colors">
38
- <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round"><polyline points="22 12 16 12 14 15 10 15 8 12 2 12"/><path d="M5.45 5.11L2 12v6a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6l-3.45-6.89A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z"/></svg>
39
- </a>
40
-
41
- <div class="w-6 h-px bg-slate-800 my-1"></div>
42
-
43
- <!-- Memory — ACTIVE -->
44
- <a href="/memory" title="Memory" class="w-9 h-9 flex items-center justify-center rounded-lg bg-violet-600/20 text-violet-400 transition-colors">
45
- <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round"><path d="M12 2a7 7 0 0 1 7 7c0 2.38-1.19 4.47-3 5.74V17a1 1 0 0 1-1 1H9a1 1 0 0 1-1-1v-2.26C6.19 13.47 5 11.38 5 9a7 7 0 0 1 7-7z"/><path d="M9 21h6"/><path d="M10 21v1a1 1 0 0 0 1 1h2a1 1 0 0 0 1-1v-1"/></svg>
46
- </a>
47
- <!-- Graph -->
48
- <a href="/graph" title="Knowledge Graph" class="w-9 h-9 flex items-center justify-center rounded-lg text-slate-400 hover:text-slate-200 hover:bg-slate-800 transition-colors">
49
- <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"/><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"/></svg>
50
- </a>
51
- <!-- Sessions -->
52
- <a href="/sessions" title="Sessions" class="w-9 h-9 flex items-center justify-center rounded-lg text-slate-400 hover:text-slate-200 hover:bg-slate-800 transition-colors">
53
- <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><polyline points="12 6 12 12 16 14"/></svg>
54
- </a>
55
- <!-- Somatic -->
56
- <a href="/somatic" title="Somatic" class="w-9 h-9 flex items-center justify-center rounded-lg text-slate-400 hover:text-slate-200 hover:bg-slate-800 transition-colors">
57
- <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round"><path d="M20.84 4.61a5.5 5.5 0 0 0-7.78 0L12 5.67l-1.06-1.06a5.5 5.5 0 0 0-7.78 7.78l1.06 1.06L12 21.23l7.78-7.78 1.06-1.06a5.5 5.5 0 0 0 0-7.78z"/></svg>
58
- </a>
59
- <!-- Adaptive -->
60
- <a href="/adaptive" title="Adaptive" class="w-9 h-9 flex items-center justify-center rounded-lg text-slate-400 hover:text-slate-200 hover:bg-slate-800 transition-colors">
61
- <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="3"/><path d="M12 1v4M12 19v4M4.22 4.22l2.83 2.83M16.95 16.95l2.83 2.83M1 12h4M19 12h4M4.22 19.78l2.83-2.83M16.95 7.05l2.83-2.83"/></svg>
62
- </a>
63
- </nav>
64
-
65
- <!-- Trust score -->
66
- <div class="flex flex-col items-center gap-0.5 mt-2">
67
- <span class="text-xs font-display font-semibold text-slate-500 uppercase tracking-widest">Trust</span>
68
- <span id="trust-score" class="text-sm font-mono font-bold text-violet-400">--</span>
1
+ {% extends "base.html" %}
2
+
3
+ {% block title %}Memory Flow{% endblock %}
4
+ {% block page_title %}Memory Flow{% endblock %}
5
+
6
+ {% block head %}
7
+ <style>
8
+ .flow-connector {
9
+ position: absolute;
10
+ height: 3px;
11
+ background: linear-gradient(90deg, var(--from), var(--to));
12
+ top: 50%;
13
+ transform: translateY(-50%);
14
+ border-radius: 2px;
15
+ overflow: hidden;
16
+ }
17
+ .flow-connector::after {
18
+ content: '';
19
+ position: absolute;
20
+ top: 0; left: -100%; width: 60%; height: 100%;
21
+ background: linear-gradient(90deg, transparent, rgba(255,255,255,0.4), transparent);
22
+ animation: flowPulse 2s ease-in-out infinite;
23
+ }
24
+ @keyframes flowPulse {
25
+ 0% { left: -60%; }
26
+ 100% { left: 160%; }
27
+ }
28
+ .flow-box {
29
+ transition: transform 0.2s, box-shadow 0.2s;
30
+ }
31
+ .flow-box:hover {
32
+ transform: translateY(-2px);
33
+ box-shadow: 0 8px 25px rgba(0,0,0,0.3);
34
+ }
35
+ .memory-card {
36
+ transition: all 0.2s ease;
37
+ cursor: pointer;
38
+ }
39
+ .memory-card:hover {
40
+ border-color: rgba(124,58,237,0.4);
41
+ box-shadow: 0 0 20px rgba(124,58,237,0.1);
42
+ }
43
+ .memory-card .full-content {
44
+ max-height: 0;
45
+ overflow: hidden;
46
+ transition: max-height 0.3s ease;
47
+ }
48
+ .memory-card.expanded .full-content {
49
+ max-height: 500px;
50
+ }
51
+ .strength-bar {
52
+ transition: width 0.8s ease-out;
53
+ }
54
+ @keyframes countUp {
55
+ from { opacity: 0; transform: translateY(10px); }
56
+ to { opacity: 1; transform: translateY(0); }
57
+ }
58
+ .count-animate {
59
+ animation: countUp 0.5s ease-out forwards;
60
+ }
61
+ </style>
62
+ {% endblock %}
63
+
64
+ {% block header_actions %}
65
+ <div class="flex items-center gap-2">
66
+ <input type="text" id="search-input" placeholder="Search memories..."
67
+ class="bg-slate-800 border border-slate-700 rounded-lg px-3 py-1.5 text-xs text-slate-200 placeholder-slate-500 focus:outline-none focus:ring-1 focus:ring-violet-500 w-64"
68
+ onkeydown="if(event.key==='Enter')searchMemories()">
69
+ <button onclick="searchMemories()" class="px-3 py-1.5 text-xs bg-violet-600 text-white rounded-lg hover:bg-violet-500 transition-colors font-medium">Search</button>
70
+ </div>
71
+ {% endblock %}
72
+
73
+ {% block content %}
74
+ <!-- Flow Diagram -->
75
+ <div class="mb-6">
76
+ <h2 class="text-xs uppercase tracking-wider text-slate-500 font-semibold mb-4">Memory Pipeline</h2>
77
+ <div class="relative flex items-center justify-center gap-0 py-6 px-4" id="flow-diagram">
78
+ <!-- STM Box -->
79
+ <div class="flow-box bg-cyan-500/10 border border-cyan-500/30 rounded-xl p-5 text-center min-w-[140px] z-10">
80
+ <div class="text-xs uppercase tracking-wider text-cyan-400 font-semibold mb-1">STM</div>
81
+ <div class="text-3xl font-display font-bold text-cyan-300 count-animate" id="count-stm">--</div>
82
+ <div class="text-[10px] text-cyan-500/60 mt-1">Short-Term</div>
83
+ </div>
84
+
85
+ <!-- Arrow STM -> LTM -->
86
+ <div class="flex flex-col items-center mx-2 z-10">
87
+ <div class="text-[10px] text-emerald-400 font-mono font-semibold mb-1" id="count-promoted">--</div>
88
+ <div class="w-24 h-[3px] rounded-full relative overflow-hidden bg-gradient-to-r from-cyan-500 to-violet-500">
89
+ <div class="absolute top-0 left-0 w-1/2 h-full bg-gradient-to-r from-transparent via-white/40 to-transparent" style="animation: flowPulse 2s ease-in-out infinite;"></div>
90
+ </div>
91
+ <div class="text-[10px] text-slate-600 mt-1">promoted</div>
92
+ </div>
93
+
94
+ <!-- LTM Box -->
95
+ <div class="flow-box bg-violet-500/10 border border-violet-500/30 rounded-xl p-5 text-center min-w-[140px] z-10">
96
+ <div class="text-xs uppercase tracking-wider text-violet-400 font-semibold mb-1">LTM</div>
97
+ <div class="text-3xl font-display font-bold text-violet-300 count-animate" id="count-ltm">--</div>
98
+ <div class="text-[10px] text-violet-500/60 mt-1">Long-Term</div>
99
+ </div>
100
+
101
+ <!-- Arrow to Dreamed -->
102
+ <div class="flex flex-col items-center mx-2 z-10">
103
+ <div class="text-[10px] text-indigo-400 font-mono font-semibold mb-1" id="count-dreamed">--</div>
104
+ <div class="w-16 h-[3px] rounded-full bg-gradient-to-r from-violet-500 to-indigo-500 relative overflow-hidden">
105
+ <div class="absolute top-0 left-0 w-1/2 h-full bg-gradient-to-r from-transparent via-white/30 to-transparent" style="animation: flowPulse 3s ease-in-out infinite;"></div>
106
+ </div>
107
+ <div class="text-[10px] text-slate-600 mt-1">dreamed</div>
108
+ </div>
109
+
110
+ <!-- Dreamed Box -->
111
+ <div class="flow-box bg-indigo-500/10 border border-indigo-500/30 rounded-xl p-5 text-center min-w-[130px] z-10">
112
+ <div class="text-xs uppercase tracking-wider text-indigo-400 font-semibold mb-1">Dreamed</div>
113
+ <div class="text-3xl font-display font-bold text-indigo-300 count-animate" id="count-dreamed-box">--</div>
114
+ <div class="text-[10px] text-indigo-500/60 mt-1">Insights</div>
115
+ </div>
116
+
117
+ <!-- Quarantine Branch (below STM) -->
118
+ <div class="absolute left-[calc(50%-280px)] top-[calc(100%-10px)] flex flex-col items-center z-10" id="quarantine-branch">
119
+ <div class="w-[3px] h-8 bg-gradient-to-b from-cyan-500/50 to-amber-500/50 rounded-full"></div>
120
+ <div class="flow-box bg-amber-500/10 border border-amber-500/30 rounded-xl p-4 text-center min-w-[120px]">
121
+ <div class="text-xs uppercase tracking-wider text-amber-400 font-semibold mb-1">Quarantine</div>
122
+ <div class="text-2xl font-display font-bold text-amber-300 count-animate" id="count-quarantine">--</div>
123
+ <div class="text-[10px] text-amber-500/60 mt-1">Pending Review</div>
124
+ </div>
125
+ </div>
126
+ </div>
127
+ </div>
128
+
129
+ <!-- Two-column: STM and LTM Recent -->
130
+ <div class="grid grid-cols-1 lg:grid-cols-2 gap-5 mb-6" id="columns-area">
131
+ <!-- Recent STM -->
132
+ <div>
133
+ <h2 class="text-xs uppercase tracking-wider text-slate-500 font-semibold mb-3 flex items-center gap-2">
134
+ <span class="w-2 h-2 rounded-full bg-cyan-400 glow-dot" style="color:#22d3ee"></span>
135
+ Recent STM
136
+ </h2>
137
+ <div class="space-y-2" id="stm-list">
138
+ <div class="text-xs text-slate-600 text-center py-8">Loading...</div>
139
+ </div>
140
+ </div>
141
+
142
+ <!-- Recent LTM -->
143
+ <div>
144
+ <h2 class="text-xs uppercase tracking-wider text-slate-500 font-semibold mb-3 flex items-center gap-2">
145
+ <span class="w-2 h-2 rounded-full bg-violet-400 glow-dot" style="color:#a78bfa"></span>
146
+ Recent LTM
147
+ </h2>
148
+ <div class="space-y-2" id="ltm-list">
149
+ <div class="text-xs text-slate-600 text-center py-8">Loading...</div>
150
+ </div>
151
+ </div>
152
+ </div>
153
+
154
+ <!-- Quarantine Items -->
155
+ <div class="mb-6" id="quarantine-section">
156
+ <h2 class="text-xs uppercase tracking-wider text-slate-500 font-semibold mb-3 flex items-center gap-2">
157
+ <span class="w-2 h-2 rounded-full bg-amber-400 glow-dot" style="color:#fbbf24"></span>
158
+ Quarantine Queue
159
+ </h2>
160
+ <div class="space-y-2" id="quarantine-list">
161
+ <div class="text-xs text-slate-600 text-center py-4">Loading...</div>
162
+ </div>
163
+ </div>
164
+
165
+ <!-- Search Results (hidden by default) -->
166
+ <div class="mb-6 hidden" id="search-results-section">
167
+ <div class="flex items-center justify-between mb-3">
168
+ <h2 class="text-xs uppercase tracking-wider text-slate-500 font-semibold flex items-center gap-2">
169
+ Search Results
170
+ <span class="text-violet-400 font-mono" id="search-count"></span>
171
+ </h2>
172
+ <button onclick="clearSearch()" class="text-xs text-slate-500 hover:text-slate-300 transition-colors">Clear</button>
173
+ </div>
174
+ <div class="space-y-2" id="search-results"></div>
175
+ </div>
176
+ {% endblock %}
177
+
178
+ {% block scripts %}
179
+ <script>
180
+ const REFRESH_MS = 60000;
181
+
182
+ function sourceTypeBadge(type) {
183
+ const map = {
184
+ learning: 'bg-blue-500/10 text-blue-400',
185
+ feedback: 'bg-pink-500/10 text-pink-400',
186
+ preference: 'bg-violet-500/10 text-violet-400',
187
+ diary: 'bg-cyan-500/10 text-cyan-400',
188
+ decision: 'bg-amber-500/10 text-amber-400',
189
+ };
190
+ return map[type] || 'bg-slate-700 text-slate-400';
191
+ }
192
+
193
+ function renderMemoryCard(m) {
194
+ const content = m.content || '';
195
+ const snippet = content.length > 180 ? content.substring(0, 180) + '...' : content;
196
+ const hasMore = content.length > 180;
197
+ const strength = m.strength != null ? m.strength : null;
198
+ const sourceType = m.source_type || 'unknown';
199
+ const domain = m.domain || '';
200
+ const created = m.created_at ? relativeTime(m.created_at) : '';
201
+
202
+ return `<div class="memory-card bg-slate-900/50 border border-slate-800/50 rounded-xl p-4" onclick="this.classList.toggle('expanded')">
203
+ <div class="flex items-center gap-2 mb-2 flex-wrap">
204
+ <span class="text-[10px] px-1.5 py-0.5 rounded font-medium ${sourceTypeBadge(sourceType)}">${escapeHtml(sourceType)}</span>
205
+ ${domain ? `<span class="text-[10px] px-1.5 py-0.5 rounded bg-slate-800 text-slate-500">${escapeHtml(domain)}</span>` : ''}
206
+ <span class="text-[10px] text-slate-600 ml-auto font-mono">${escapeHtml(created)}</span>
207
+ </div>
208
+ <p class="text-sm text-slate-300 leading-relaxed">${escapeHtml(snippet)}</p>
209
+ ${hasMore ? `<div class="full-content mt-2 pt-2 border-t border-slate-800/50">
210
+ <p class="text-sm text-slate-300 leading-relaxed whitespace-pre-wrap">${escapeHtml(content)}</p>
211
+ </div>
212
+ <div class="text-[10px] text-violet-400 mt-1">Click to expand</div>` : ''}
213
+ ${strength != null ? `<div class="mt-2 flex items-center gap-2">
214
+ <span class="text-[10px] text-slate-600">Strength</span>
215
+ <div class="flex-1 h-1.5 bg-slate-800 rounded-full overflow-hidden">
216
+ <div class="strength-bar h-full rounded-full ${strength > 0.7 ? 'bg-emerald-500' : strength > 0.4 ? 'bg-violet-500' : 'bg-amber-500'}" style="width:${(strength * 100).toFixed(0)}%"></div>
69
217
  </div>
70
- </aside>
71
-
72
- <!-- Main content -->
73
- <main class="ml-14 min-h-screen bg-gray-950 text-slate-200">
74
- <header class="h-12 border-b border-slate-800/50 flex items-center gap-4 px-6">
75
- <h1 class="text-sm font-display font-semibold">Memory</h1>
76
- <div class="flex-1 flex items-center gap-2 max-w-xl">
77
- <input type="text" id="query" placeholder="Search cognitive memories..."
78
- class="flex-1 bg-slate-800 border border-slate-700 rounded-lg px-3 py-1.5 text-xs text-slate-200 placeholder-slate-500 focus:outline-none focus:ring-1 focus:ring-violet-500"
79
- onkeydown="if(event.key==='Enter')search()">
80
- <select id="store" class="bg-slate-800 border border-slate-700 rounded-lg px-2 py-1.5 text-xs text-slate-200 focus:outline-none focus:ring-1 focus:ring-violet-500">
81
- <option value="both">Both</option>
82
- <option value="stm">STM</option>
83
- <option value="ltm">LTM</option>
84
- </select>
85
- <button onclick="search()" class="px-3 py-1.5 text-xs bg-violet-600 text-white rounded-lg hover:bg-violet-500 transition-colors">Search</button>
86
- </div>
87
- <span id="count" class="text-xs text-slate-500 font-mono"></span>
88
- </header>
89
-
90
- <div id="results" class="p-6 space-y-2 max-w-4xl"></div>
91
- <div id="empty" class="p-12 text-center text-slate-500 text-sm">Search your cognitive memories</div>
92
- </main>
93
-
94
- <script>
95
- function escapeHtml(text) {
96
- const el = document.createElement('div');
97
- el.textContent = text || '';
98
- return el.innerHTML;
99
- }
100
-
101
- function scoreColor(score) {
102
- if (score > 0.8) return 'text-emerald-400';
103
- if (score > 0.6) return 'text-amber-400';
104
- return 'text-red-400';
105
- }
106
-
107
- function storeBadge(store) {
108
- if ((store || '').toLowerCase() === 'stm') return 'bg-cyan-500/10 text-cyan-400';
109
- return 'bg-violet-500/10 text-violet-400';
110
- }
111
-
112
- function typeBadge(type) {
113
- const map = {
114
- learning: 'bg-blue-500/10 text-blue-400',
115
- feedback: 'bg-pink-500/10 text-pink-400',
116
- preference: 'bg-violet-500/10 text-violet-400',
117
- diary: 'bg-cyan-500/10 text-cyan-400',
118
- decision: 'bg-amber-500/10 text-amber-400',
119
- change: 'bg-slate-700 text-slate-400'
120
- };
121
- return map[type] || 'bg-slate-700 text-slate-400';
122
- }
123
-
124
- function renderCard(m) {
125
- const score = m.score || m.similarity || 0;
126
- const store = (m.store || 'ltm').toUpperCase();
127
- const source_type = m.source_type || 'unknown';
128
- const content = m.content || '';
129
- const domain = m.domain || '';
130
- const created_at = m.created_at || '';
131
- const strength = m.strength;
132
-
133
- const strengthBar = strength !== undefined
134
- ? `<div class="mt-2 flex items-center gap-2">
135
- <span class="text-xs text-slate-500">Strength</span>
136
- <div class="flex-1 h-1 bg-slate-800 rounded-full overflow-hidden">
137
- <div class="h-full bg-violet-500 rounded-full" style="width:${strength * 100}%"></div>
138
- </div>
139
- <span class="text-xs text-slate-500 font-mono">${strength.toFixed(2)}</span>
140
- </div>`
141
- : '';
142
-
143
- return `<div class="bg-slate-900/50 border border-slate-800/50 rounded-lg p-4">
144
- <div class="flex items-center gap-2 mb-1.5 flex-wrap">
145
- <span class="text-xs font-mono ${scoreColor(score)}">${score.toFixed(3)}</span>
146
- <span class="text-xs px-1.5 py-0.5 rounded ${storeBadge(store)}">${store}</span>
147
- <span class="text-xs px-1.5 py-0.5 rounded ${typeBadge(source_type)}">${escapeHtml(source_type)}</span>
148
- ${domain ? `<span class="text-xs px-1.5 py-0.5 rounded bg-slate-800 text-slate-500">${escapeHtml(domain)}</span>` : ''}
149
- <span class="text-xs text-slate-600 ml-auto">${escapeHtml(created_at)}</span>
150
- </div>
151
- <p class="text-sm text-slate-200 leading-relaxed whitespace-pre-wrap">${escapeHtml(content)}</p>
152
- ${strengthBar}
153
- </div>`;
154
- }
155
-
156
- async function search() {
157
- const q = document.getElementById('query').value.trim();
158
- if (!q) return;
159
- const store = document.getElementById('store').value;
160
- const countEl = document.getElementById('count');
161
- const resultsEl = document.getElementById('results');
162
- const emptyEl = document.getElementById('empty');
163
-
164
- countEl.textContent = 'Searching...';
165
- emptyEl.style.display = 'none';
166
- resultsEl.innerHTML = '';
167
-
168
- try {
169
- const resp = await fetch(`/api/memories?q=${encodeURIComponent(q)}&store=${store}&limit=30`);
170
- const data = await resp.json();
171
- const results = data.results || [];
172
-
173
- countEl.textContent = `${data.count || results.length} results`;
174
-
175
- if (results.length === 0) {
176
- resultsEl.innerHTML = '';
177
- emptyEl.textContent = 'No memories found';
178
- emptyEl.style.display = 'block';
179
- } else {
180
- resultsEl.innerHTML = results.map(renderCard).join('');
181
- emptyEl.style.display = 'none';
182
- }
183
- } catch (err) {
184
- countEl.textContent = '';
185
- resultsEl.innerHTML = `<div class="text-xs text-red-400 p-3 bg-red-500/10 rounded-lg border border-red-500/20">Error: ${escapeHtml(err.message)}</div>`;
186
- emptyEl.style.display = 'none';
187
- }
188
- }
189
-
190
- // Load trust score
191
- fetch('/api/stats').then(r => r.json()).then(data => {
192
- if (data.trust_score != null) {
193
- document.getElementById('trust-score').textContent = Math.round(data.trust_score);
194
- }
195
- }).catch(() => {});
196
- </script>
197
- </body>
198
- </html>
218
+ <span class="text-[10px] text-slate-500 font-mono">${strength.toFixed(2)}</span>
219
+ </div>` : ''}
220
+ </div>`;
221
+ }
222
+
223
+ function renderQuarantineCard(m) {
224
+ const content = m.content || '';
225
+ const reason = m.quarantine_reason || m.reason || 'Unknown reason';
226
+ return `<div class="bg-amber-500/5 border border-amber-500/20 rounded-xl p-4">
227
+ <div class="flex items-center gap-2 mb-2">
228
+ <span class="text-[10px] px-1.5 py-0.5 rounded bg-amber-500/10 text-amber-400 font-medium">quarantine</span>
229
+ <span class="text-[10px] text-amber-500/60 ml-auto">${escapeHtml(reason)}</span>
230
+ </div>
231
+ <p class="text-sm text-slate-400 leading-relaxed">${escapeHtml(content.length > 200 ? content.substring(0, 200) + '...' : content)}</p>
232
+ </div>`;
233
+ }
234
+
235
+ async function loadFlow() {
236
+ const data = await fetchJSON('/api/memory/flow');
237
+ if (!data) return;
238
+
239
+ const c = data.counts || {};
240
+ animateCount('count-stm', c.stm || 0);
241
+ animateCount('count-ltm', c.ltm || 0);
242
+ animateCount('count-quarantine', c.quarantine || 0);
243
+ animateCount('count-dreamed-box', c.dreamed || 0);
244
+ document.getElementById('count-promoted').textContent = formatNumber(c.promoted || 0);
245
+ document.getElementById('count-dreamed').textContent = formatNumber(c.dreamed || 0);
246
+
247
+ // STM recent
248
+ const stmList = document.getElementById('stm-list');
249
+ const stmItems = data.stm_recent || [];
250
+ stmList.innerHTML = stmItems.length === 0
251
+ ? '<div class="text-xs text-slate-600 text-center py-6">No recent STM memories</div>'
252
+ : stmItems.map(renderMemoryCard).join('');
253
+
254
+ // LTM recent
255
+ const ltmList = document.getElementById('ltm-list');
256
+ const ltmItems = data.ltm_recent || [];
257
+ ltmList.innerHTML = ltmItems.length === 0
258
+ ? '<div class="text-xs text-slate-600 text-center py-6">No recent LTM memories</div>'
259
+ : ltmItems.map(renderMemoryCard).join('');
260
+
261
+ // Quarantine
262
+ const qList = document.getElementById('quarantine-list');
263
+ const qItems = data.quarantine || [];
264
+ qList.innerHTML = qItems.length === 0
265
+ ? '<div class="text-xs text-slate-600 text-center py-4">No items in quarantine</div>'
266
+ : qItems.map(renderQuarantineCard).join('');
267
+ }
268
+
269
+ function animateCount(id, target) {
270
+ const el = document.getElementById(id);
271
+ if (!el) return;
272
+ const start = parseInt(el.textContent) || 0;
273
+ if (start === target) { el.textContent = formatNumber(target); return; }
274
+ const duration = 600;
275
+ const startTime = performance.now();
276
+ function step(now) {
277
+ const progress = Math.min((now - startTime) / duration, 1);
278
+ const eased = 1 - Math.pow(1 - progress, 3);
279
+ el.textContent = formatNumber(Math.round(start + (target - start) * eased));
280
+ if (progress < 1) requestAnimationFrame(step);
281
+ }
282
+ requestAnimationFrame(step);
283
+ }
284
+
285
+ async function searchMemories() {
286
+ const q = document.getElementById('search-input').value.trim();
287
+ if (!q) return;
288
+
289
+ const section = document.getElementById('search-results-section');
290
+ const results = document.getElementById('search-results');
291
+ const count = document.getElementById('search-count');
292
+
293
+ section.classList.remove('hidden');
294
+ results.innerHTML = '<div class="text-xs text-slate-500 text-center py-4">Searching...</div>';
295
+
296
+ const data = await fetchJSON(`/api/memories?q=${encodeURIComponent(q)}&limit=30`);
297
+ if (!data) {
298
+ results.innerHTML = '<div class="text-xs text-red-400 text-center py-4">Search failed</div>';
299
+ return;
300
+ }
301
+
302
+ const items = data.results || [];
303
+ count.textContent = `(${items.length})`;
304
+ results.innerHTML = items.length === 0
305
+ ? '<div class="text-xs text-slate-600 text-center py-6">No memories found</div>'
306
+ : items.map(renderMemoryCard).join('');
307
+ }
308
+
309
+ function clearSearch() {
310
+ document.getElementById('search-results-section').classList.add('hidden');
311
+ document.getElementById('search-input').value = '';
312
+ }
313
+
314
+ // Init
315
+ loadFlow();
316
+ setInterval(loadFlow, REFRESH_MS);
317
+ </script>
318
+ {% endblock %}