humemory 0.2.1

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 (81) hide show
  1. package/.githooks/post-commit +22 -0
  2. package/AGENTS.md +328 -0
  3. package/CHANGELOG.md +198 -0
  4. package/LICENSE +21 -0
  5. package/README.md +488 -0
  6. package/bin/humemory.js +19 -0
  7. package/dist/agent/claude-hook.d.ts +15 -0
  8. package/dist/agent/claude-hook.js +38 -0
  9. package/dist/agent/commit-closer.d.ts +60 -0
  10. package/dist/agent/commit-closer.js +125 -0
  11. package/dist/agent/learning-extractor.d.ts +10 -0
  12. package/dist/agent/learning-extractor.js +75 -0
  13. package/dist/agent/session-context.d.ts +63 -0
  14. package/dist/agent/session-context.js +216 -0
  15. package/dist/agent/session-parser.d.ts +12 -0
  16. package/dist/agent/session-parser.js +85 -0
  17. package/dist/api/dream-routes.d.ts +7 -0
  18. package/dist/api/dream-routes.js +40 -0
  19. package/dist/api/intentions-routes.d.ts +23 -0
  20. package/dist/api/intentions-routes.js +252 -0
  21. package/dist/api/memory-routes.d.ts +10 -0
  22. package/dist/api/memory-routes.js +277 -0
  23. package/dist/api/scripts-routes.d.ts +13 -0
  24. package/dist/api/scripts-routes.js +129 -0
  25. package/dist/api/server.d.ts +33 -0
  26. package/dist/api/server.js +157 -0
  27. package/dist/cli/index.d.ts +2 -0
  28. package/dist/cli/index.js +798 -0
  29. package/dist/core/clock.d.ts +38 -0
  30. package/dist/core/clock.js +52 -0
  31. package/dist/core/cue-arg.d.ts +19 -0
  32. package/dist/core/cue-arg.js +72 -0
  33. package/dist/core/cues.d.ts +138 -0
  34. package/dist/core/cues.js +372 -0
  35. package/dist/core/decay.d.ts +49 -0
  36. package/dist/core/decay.js +157 -0
  37. package/dist/core/dreamer.d.ts +114 -0
  38. package/dist/core/dreamer.js +427 -0
  39. package/dist/core/embeddings.d.ts +79 -0
  40. package/dist/core/embeddings.js +133 -0
  41. package/dist/core/event-bus.d.ts +71 -0
  42. package/dist/core/event-bus.js +67 -0
  43. package/dist/core/hybrid.d.ts +33 -0
  44. package/dist/core/hybrid.js +63 -0
  45. package/dist/core/llm-generator.d.ts +18 -0
  46. package/dist/core/llm-generator.js +69 -0
  47. package/dist/core/sanitize.d.ts +57 -0
  48. package/dist/core/sanitize.js +87 -0
  49. package/dist/core/scripts.d.ts +55 -0
  50. package/dist/core/scripts.js +96 -0
  51. package/dist/core/search.d.ts +42 -0
  52. package/dist/core/search.js +173 -0
  53. package/dist/core/trust.d.ts +48 -0
  54. package/dist/core/trust.js +57 -0
  55. package/dist/core/types.d.ts +333 -0
  56. package/dist/core/types.js +1 -0
  57. package/dist/core/vector-clusterer.d.ts +53 -0
  58. package/dist/core/vector-clusterer.js +113 -0
  59. package/dist/index.d.ts +28 -0
  60. package/dist/index.js +18 -0
  61. package/dist/mcp/server.d.ts +22 -0
  62. package/dist/mcp/server.js +158 -0
  63. package/dist/store/sqlite.d.ts +240 -0
  64. package/dist/store/sqlite.js +1653 -0
  65. package/docs/TESTING.md +244 -0
  66. package/package.json +95 -0
  67. package/public/app/galaxy-f42190mq.js +10 -0
  68. package/public/app/index-2cf31xxn.css +1 -0
  69. package/public/app/index-epqg22cp.js +1 -0
  70. package/public/app/index-f9h80bzq.js +12 -0
  71. package/public/app/index-gbfwa9vq.js +2 -0
  72. package/public/app/index-kvhc17mz.js +2 -0
  73. package/public/app/index-pbd5t4dj.js +2 -0
  74. package/public/app/index.html +12 -0
  75. package/public/app/promenade-cnzzpm73.js +4111 -0
  76. package/public/app/river-tyawhh8w.js +13 -0
  77. package/public/session.html +659 -0
  78. package/scripts/consolidate.js +46 -0
  79. package/scripts/hook-post-commit.ts +80 -0
  80. package/scripts/hook-session-start.ts +92 -0
  81. package/scripts/hook-session.ts +60 -0
@@ -0,0 +1,13 @@
1
+ import{a as W,b as A}from"./index-pbd5t4dj.js";import{d as v,e as f,f as p,g as m,h as N,p as h,q as s,r}from"./index-epqg22cp.js";import{t as d,u as w}from"./index-gbfwa9vq.js";import{B as g}from"./index-kvhc17mz.js";var B=86400000,R=90*B;function kq(c={}){return async function($){$.innerHTML="";let{memories:n}=await g.listMemories({limit:500}),M=n.map((q)=>({...q,createdAt:new Date(q.createdAt)})),D=$.clientWidth||1200,E=600,Q={top:40,right:40,bottom:60,left:120},x=D-Q.left-Q.right,P=E-Q.top-Q.bottom,T=P/5,k=N($).append("svg").attr("width",D).attr("height",E).append("g").attr("transform",`translate(${Q.left},${Q.top})`),_=M.map((q)=>new Date(q.createdAt)),o=f(_)??new Date,i=v(_)??new Date,b=r().domain([o,new Date(i.getTime()+R)]).range([0,x]);k.append("g").attr("transform",`translate(0,${P})`).call(p(b).ticks(10).tickFormat(s("%d %b"))).selectAll("text").style("fill","#a1a1aa").style("font-size","11px"),k.append("g").call(m(h().domain([0,5]).range([0,P])).ticks(5).tickFormat((q)=>w[Number(q)]??"")).selectAll("text").style("fill","#a1a1aa").style("font-size","11px");for(let q=0;q<=5;q++)k.append("line").attr("class","river-lane").attr("stroke","#262b38").attr("x1",0).attr("x2",x).attr("y1",q*T).attr("y2",q*T);let l=k.append("line").attr("stroke","#8b5cf6").attr("stroke-width",2).attr("stroke-dasharray","6 4").attr("y1",0).attr("y2",P),a=k.append("g"),J=document.createElement("div");J.className="river-tooltip",J.style.display="none",document.body.appendChild(J);let j=0;function e(q,F){let U=new Date(Date.now()+j),G=W(F,U),z=A(F,U);J.innerHTML=`
2
+ <div style="margin-bottom:.5rem;font-weight:600;">${w[G]}</div>
3
+ <div style="margin-bottom:.5rem;">${F.content.slice(0,100)}${F.content.length>100?"…":""}</div>
4
+ <div style="color:var(--muted);font-size:.8rem;">
5
+ <div>Strength: ${z}/100</div>
6
+ <div>Recalls: ${F.recallCount}</div>
7
+ <div>Encoded: ${new Date(F.createdAt).toLocaleDateString()}</div>
8
+ ${F.photographic?'<div style="color:#8b5cf6;">\uD83D\uDD12 Photographic</div>':""}
9
+ </div>`,J.style.display="block",J.style.left=`${q.pageX+10}px`,J.style.top=`${q.pageY-10}px`}function y(q=0){let F=new Date(Date.now()+q);l.attr("x1",b(F)).attr("x2",b(F));let U=a.selectAll(".river-memory").data(M,(z)=>z.id);U.exit().remove();let G=U.enter().append("g").attr("class","river-memory").style("cursor","pointer").on("click",(z,X)=>c.onSelectMemory?.(X.id)).on("mouseover",(z,X)=>e(z,X)).on("mouseout",()=>{J.style.display="none"});G.append("rect").attr("rx",6).attr("ry",6),G.append("text").attr("font-size","9px").attr("fill","#e4e4e7").attr("text-anchor","middle").attr("dy","0.35em"),G.merge(U).each(function(z){let X=new Date(new Date(z.createdAt).getTime()+q),H=W(z,X),zq=A(z,X),L=b(new Date(z.createdAt)),O=H*T+T/2,S=Math.max(30,Math.min(80,z.content.length/3)),Kq=20,u=N(this);u.select("rect").attr("x",L-S/2).attr("y",O-10).attr("width",S).attr("height",20).attr("fill",d[H]).attr("opacity",Math.max(0.3,zq/100)).attr("stroke",z.photographic?"#8b5cf6":"none").attr("stroke-width",z.photographic?2:0),u.select("text").attr("x",L).attr("y",O).text(z.content.slice(0,12))})}y(0);let K=document.createElement("div");K.className="river-controls",K.innerHTML=`
10
+ <button type="button" data-role="play">▶ Play</button>
11
+ <input type="range" data-role="slider" min="0" max="${R}" value="0" step="${3600000}">
12
+ <span data-role="label">Today</span>
13
+ <button type="button" data-role="reset">↺ Reset</button>`,$.appendChild(K);let I=K.querySelector('[data-role="slider"]'),t=K.querySelector('[data-role="label"]'),V=K.querySelector('[data-role="play"]'),qq=K.querySelector('[data-role="reset"]'),C=null,Y=(q)=>{j=q,I.value=String(q);let F=Math.floor(q/B);t.textContent=F===0?"Today":`D+${F} days`,y(q)},Z=()=>{if(C)clearInterval(C);C=null,V.textContent="▶ Play"};return I.addEventListener("input",()=>Y(Number(I.value))),V.addEventListener("click",()=>{if(C){Z();return}V.textContent="⏸ Pause",C=setInterval(()=>Y(j>=R?0:j+B),200)}),qq.addEventListener("click",()=>{Z(),Y(0)}),()=>{Z(),J.remove(),$.innerHTML=""}}}export{kq as createMount};
@@ -0,0 +1,659 @@
1
+ <!DOCTYPE html>
2
+ <html lang="fr">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>humemory — Session Mnésique</title>
7
+ <style>
8
+ :root {
9
+ --bg: #0f0f14;
10
+ --surface: #1a1a24;
11
+ --surface-2: #252532;
12
+ --text: #e4e4e7;
13
+ --text-muted: #a1a1aa;
14
+ --border: #3f3f4e;
15
+ --primary: #8b5cf6;
16
+ --primary-hover: #7c3aed;
17
+ --encoding: #22c55e;
18
+ --consolidating: #eab308;
19
+ --consolidated: #f97316;
20
+ --fragile: #ef4444;
21
+ --dormant: #6b7280;
22
+ --accent: #06b6d4;
23
+ }
24
+
25
+ * { box-sizing: border-box; margin: 0; padding: 0; }
26
+
27
+ body {
28
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
29
+ background: var(--bg);
30
+ color: var(--text);
31
+ line-height: 1.6;
32
+ }
33
+
34
+ .container {
35
+ max-width: 1200px;
36
+ margin: 0 auto;
37
+ padding: 2rem;
38
+ }
39
+
40
+ header {
41
+ display: flex;
42
+ justify-content: space-between;
43
+ align-items: center;
44
+ margin-bottom: 2rem;
45
+ padding-bottom: 1rem;
46
+ border-bottom: 1px solid var(--border);
47
+ }
48
+
49
+ h1 {
50
+ font-size: 1.75rem;
51
+ font-weight: 600;
52
+ display: flex;
53
+ align-items: center;
54
+ gap: 0.5rem;
55
+ }
56
+
57
+ .logo { font-size: 2rem; }
58
+
59
+ .back-link {
60
+ color: var(--text-muted);
61
+ text-decoration: none;
62
+ display: flex;
63
+ align-items: center;
64
+ gap: 0.5rem;
65
+ }
66
+
67
+ .back-link:hover { color: var(--text); }
68
+
69
+ /* Session Form */
70
+ .session-panel {
71
+ background: var(--surface);
72
+ border: 1px solid var(--border);
73
+ border-radius: 12px;
74
+ padding: 1.5rem;
75
+ margin-bottom: 2rem;
76
+ }
77
+
78
+ .form-group { margin-bottom: 1.5rem; }
79
+
80
+ label {
81
+ display: block;
82
+ font-size: 0.9rem;
83
+ font-weight: 600;
84
+ margin-bottom: 0.5rem;
85
+ color: var(--text-muted);
86
+ text-transform: uppercase;
87
+ letter-spacing: 0.05em;
88
+ }
89
+
90
+ input, select, textarea {
91
+ width: 100%;
92
+ padding: 0.75rem 1rem;
93
+ background: var(--surface-2);
94
+ border: 1px solid var(--border);
95
+ border-radius: 8px;
96
+ color: var(--text);
97
+ font-size: 0.95rem;
98
+ font-family: inherit;
99
+ }
100
+
101
+ input:focus, select:focus, textarea:focus {
102
+ outline: none;
103
+ border-color: var(--primary);
104
+ }
105
+
106
+ textarea {
107
+ min-height: 80px;
108
+ resize: vertical;
109
+ }
110
+
111
+ /* Retrieved Memories */
112
+ .mnemonic-context {
113
+ background: var(--surface);
114
+ border: 1px solid var(--border);
115
+ border-radius: 12px;
116
+ padding: 1.5rem;
117
+ margin-bottom: 2rem;
118
+ }
119
+
120
+ .context-header {
121
+ display: flex;
122
+ justify-content: space-between;
123
+ align-items: center;
124
+ margin-bottom: 1rem;
125
+ padding-bottom: 0.5rem;
126
+ border-bottom: 1px solid var(--border);
127
+ }
128
+
129
+ .context-header h2 {
130
+ font-size: 1.1rem;
131
+ display: flex;
132
+ align-items: center;
133
+ gap: 0.5rem;
134
+ }
135
+
136
+ .memory-cards {
137
+ display: flex;
138
+ flex-direction: column;
139
+ gap: 0.75rem;
140
+ }
141
+
142
+ .memory-card {
143
+ background: var(--surface-2);
144
+ border: 1px solid var(--border);
145
+ border-radius: 8px;
146
+ padding: 1rem;
147
+ display: flex;
148
+ gap: 1rem;
149
+ align-items: flex-start;
150
+ }
151
+
152
+ .memory-card .type-icon {
153
+ font-size: 1.5rem;
154
+ flex-shrink: 0;
155
+ }
156
+
157
+ .memory-card .content {
158
+ flex: 1;
159
+ min-width: 0;
160
+ }
161
+
162
+ .memory-card .content p {
163
+ font-size: 0.95rem;
164
+ margin-bottom: 0.5rem;
165
+ }
166
+
167
+ .memory-card .meta {
168
+ display: flex;
169
+ gap: 1rem;
170
+ font-size: 0.8rem;
171
+ color: var(--text-muted);
172
+ flex-wrap: wrap;
173
+ }
174
+
175
+ .memory-card .meta span {
176
+ display: flex;
177
+ align-items: center;
178
+ gap: 0.25rem;
179
+ }
180
+
181
+ .memory-card .actions {
182
+ display: flex;
183
+ gap: 0.5rem;
184
+ flex-shrink: 0;
185
+ }
186
+
187
+ .memory-card .actions button {
188
+ padding: 0.4rem 0.75rem;
189
+ font-size: 0.8rem;
190
+ background: var(--surface);
191
+ border: 1px solid var(--border);
192
+ border-radius: 6px;
193
+ color: var(--text);
194
+ cursor: pointer;
195
+ }
196
+
197
+ .memory-card .actions button:hover {
198
+ background: var(--primary);
199
+ border-color: var(--primary);
200
+ }
201
+
202
+ .memory-card .actions button.remove {
203
+ background: transparent;
204
+ border-color: var(--fragile);
205
+ color: var(--fragile);
206
+ }
207
+
208
+ .memory-card .actions button.remove:hover {
209
+ background: var(--fragile);
210
+ color: var(--text);
211
+ }
212
+
213
+ /* Context Editor */
214
+ .context-editor {
215
+ background: var(--surface);
216
+ border: 1px solid var(--border);
217
+ border-radius: 12px;
218
+ padding: 1.5rem;
219
+ margin-bottom: 2rem;
220
+ }
221
+
222
+ .context-editor textarea {
223
+ min-height: 150px;
224
+ font-family: 'Monaco', 'Consolas', monospace;
225
+ font-size: 0.9rem;
226
+ }
227
+
228
+ .context-stats {
229
+ display: flex;
230
+ gap: 1rem;
231
+ margin-top: 0.5rem;
232
+ font-size: 0.8rem;
233
+ color: var(--text-muted);
234
+ }
235
+
236
+ /* Action Buttons */
237
+ .actions-row {
238
+ display: flex;
239
+ gap: 1rem;
240
+ flex-wrap: wrap;
241
+ }
242
+
243
+ button.primary {
244
+ padding: 0.75rem 1.5rem;
245
+ background: var(--primary);
246
+ border: none;
247
+ border-radius: 8px;
248
+ color: var(--text);
249
+ font-size: 0.95rem;
250
+ font-weight: 600;
251
+ cursor: pointer;
252
+ display: flex;
253
+ align-items: center;
254
+ gap: 0.5rem;
255
+ }
256
+
257
+ button.primary:hover {
258
+ background: var(--primary-hover);
259
+ }
260
+
261
+ button.secondary {
262
+ padding: 0.75rem 1.5rem;
263
+ background: var(--surface-2);
264
+ border: 1px solid var(--border);
265
+ border-radius: 8px;
266
+ color: var(--text);
267
+ font-size: 0.95rem;
268
+ cursor: pointer;
269
+ display: flex;
270
+ align-items: center;
271
+ gap: 0.5rem;
272
+ }
273
+
274
+ button.secondary:hover {
275
+ background: var(--surface);
276
+ border-color: var(--primary);
277
+ }
278
+
279
+ button:disabled {
280
+ opacity: 0.5;
281
+ cursor: not-allowed;
282
+ }
283
+
284
+ /* Empty state */
285
+ .empty-state {
286
+ text-align: center;
287
+ padding: 3rem 2rem;
288
+ color: var(--text-muted);
289
+ }
290
+
291
+ .empty-state h3 {
292
+ font-size: 1.1rem;
293
+ margin-bottom: 0.5rem;
294
+ color: var(--text);
295
+ }
296
+
297
+ /* Loading */
298
+ .loading {
299
+ text-align: center;
300
+ padding: 2rem;
301
+ color: var(--text-muted);
302
+ }
303
+
304
+ /* Toast notifications */
305
+ .toast {
306
+ position: fixed;
307
+ bottom: 2rem;
308
+ right: 2rem;
309
+ background: var(--surface);
310
+ border: 1px solid var(--border);
311
+ border-radius: 8px;
312
+ padding: 1rem 1.5rem;
313
+ display: none;
314
+ align-items: center;
315
+ gap: 0.75rem;
316
+ box-shadow: 0 4px 12px rgba(0,0,0,0.3);
317
+ }
318
+
319
+ .toast.show { display: flex; }
320
+ .toast.success { border-color: var(--encoding); }
321
+ .toast.error { border-color: var(--fragile); }
322
+
323
+ /* Responsive */
324
+ @media (max-width: 768px) {
325
+ .container { padding: 1rem; }
326
+ .actions-row { flex-direction: column; }
327
+ .memory-card { flex-direction: column; }
328
+ .memory-card .actions { width: 100%; justify-content: flex-end; }
329
+ }
330
+ </style>
331
+ </head>
332
+ <body>
333
+ <div class="container">
334
+ <header>
335
+ <a href="/" class="back-link">← Palais de Mémoire</a>
336
+ <h1><span class="logo">🧠</span> Session Mnésique</h1>
337
+ <div style="width: 100px;"></div>
338
+ </header>
339
+
340
+ <!-- Intention Form -->
341
+ <div class="session-panel">
342
+ <div class="form-group">
343
+ <label for="projectDir">📍 Lieu mental (projet)</label>
344
+ <select id="projectDir">
345
+ <option value="">Tous les projets</option>
346
+ </select>
347
+ </div>
348
+
349
+ <div class="form-group">
350
+ <label for="intentionInput">💭 Ton intention</label>
351
+ <textarea
352
+ id="intentionInput"
353
+ placeholder="Décris ce que tu veux accomplir, explorer ou comprendre..."
354
+ rows="3"
355
+ ></textarea>
356
+ </div>
357
+
358
+ <div class="form-group">
359
+ <label for="memoryTypeFilter">🏷️ Types de mémoire à inclure</label>
360
+ <div style="display: flex; gap: 1rem; flex-wrap: wrap;">
361
+ <label style="display: flex; align-items: center; gap: 0.5rem; text-transform: none; font-weight: normal;">
362
+ <input type="checkbox" value="episodic" checked style="width: auto;">
363
+ 📅 Episodique
364
+ </label>
365
+ <label style="display: flex; align-items: center; gap: 0.5rem; text-transform: none; font-weight: normal;">
366
+ <input type="checkbox" value="semantic" checked style="width: auto;">
367
+ 📖 Sémantique
368
+ </label>
369
+ <label style="display: flex; align-items: center; gap: 0.5rem; text-transform: none; font-weight: normal;">
370
+ <input type="checkbox" value="procedural" checked style="width: auto;">
371
+ ⚡ Procédurale
372
+ </label>
373
+ </div>
374
+ </div>
375
+
376
+ <button class="primary" onclick="buildMnemonicContext()">
377
+ 🔍 Construire le contexte mnésique
378
+ </button>
379
+ </div>
380
+
381
+ <!-- Retrieved Memories -->
382
+ <div class="mnemonic-context" id="mnemonicContext" style="display: none;">
383
+ <div class="context-header">
384
+ <h2>🧠 Contexte mnésique récupéré</h2>
385
+ <span id="memoryCount" style="color: var(--text-muted); font-size: 0.9rem;">0 traces</span>
386
+ </div>
387
+ <div class="memory-cards" id="memoryCards"></div>
388
+ </div>
389
+
390
+ <!-- Context Editor -->
391
+ <div class="context-editor" id="contextEditor" style="display: none;">
392
+ <div class="form-group">
393
+ <label for="contextOutput">📝 Contexte pour l'agent</label>
394
+ <textarea
395
+ id="contextOutput"
396
+ placeholder="Le contexte mnésique sera généré ici..."
397
+ readonly
398
+ ></textarea>
399
+ <div class="context-stats">
400
+ <span id="charCount">0 caractères</span>
401
+ <span id="tokenEstimate">~0 tokens</span>
402
+ </div>
403
+ </div>
404
+
405
+ <div class="actions-row">
406
+ <button class="primary" onclick="copyContext()">
407
+ 📋 Copier le contexte
408
+ </button>
409
+ <button class="secondary" onclick="exportToAgent()">
410
+ 🚀 Envoyer à l'agent
411
+ </button>
412
+ <button class="secondary" onclick="saveAsMemory()">
413
+ 💾 Sauvegarder comme trace
414
+ </button>
415
+ </div>
416
+ </div>
417
+ </div>
418
+
419
+ <!-- Toast -->
420
+ <div class="toast" id="toast">
421
+ <span id="toastIcon">✓</span>
422
+ <span id="toastMessage">Action réussie</span>
423
+ </div>
424
+
425
+ <script>
426
+ const API_BASE = '';
427
+ let allMemories = [];
428
+ let selectedMemories = [];
429
+
430
+ // Load projects
431
+ async function loadProjects() {
432
+ try {
433
+ const response = await fetch(`${API_BASE}/memories`);
434
+ const data = await response.json();
435
+ allMemories = data.memories || [];
436
+
437
+ const projects = [...new Set(allMemories.map(m => m.directory))];
438
+ const select = document.getElementById('projectDir');
439
+ select.innerHTML = '<option value="">Tous les projets</option>' +
440
+ projects.map(p => `<option value="${p}">${p}</option>`).join('');
441
+ } catch (error) {
442
+ console.error('Error loading memories:', error);
443
+ }
444
+ }
445
+
446
+ // Build mnemonic context from intention
447
+ async function buildMnemonicContext() {
448
+ const intention = document.getElementById('intentionInput').value.trim();
449
+ const projectDir = document.getElementById('projectDir').value;
450
+
451
+ const selectedTypes = Array.from(document.querySelectorAll('input[type="checkbox"]:checked'))
452
+ .map(cb => cb.value);
453
+
454
+ if (!intention) {
455
+ showToast('⚠️', 'Décris ton intention d\'abord');
456
+ return;
457
+ }
458
+
459
+ // Extract keywords from intention
460
+ const keywords = extractKeywords(intention);
461
+
462
+ // Search memories
463
+ let memories = allMemories;
464
+
465
+ // Filter by project
466
+ if (projectDir) {
467
+ memories = memories.filter(m => m.directory === projectDir);
468
+ }
469
+
470
+ // Filter by type
471
+ if (selectedTypes.length > 0) {
472
+ memories = memories.filter(m => selectedTypes.includes(m.memoryType));
473
+ }
474
+
475
+ // Score memories by relevance to intention
476
+ const scored = memories.map(m => ({
477
+ memory: m,
478
+ score: calculateRelevance(m, keywords, intention)
479
+ })).filter(m => m.score > 0)
480
+ .sort((a, b) => b.score - a.score)
481
+ .slice(0, 10);
482
+
483
+ if (scored.length === 0) {
484
+ showToast('⚠️', 'Aucune trace pertinente trouvée');
485
+ document.getElementById('mnemonicContext').style.display = 'none';
486
+ document.getElementById('contextEditor').style.display = 'none';
487
+ return;
488
+ }
489
+
490
+ selectedMemories = scored.map(s => s.memory);
491
+ renderMemoryCards(scored);
492
+ buildContextOutput(scored, intention);
493
+
494
+ document.getElementById('mnemonicContext').style.display = 'block';
495
+ document.getElementById('contextEditor').style.display = 'block';
496
+ }
497
+
498
+ // Extract keywords from text
499
+ function extractKeywords(text) {
500
+ return text.toLowerCase()
501
+ .split(/[\s,.;:!?()]+/)
502
+ .filter(w => w.length > 3)
503
+ .filter(w => !['pour', 'dans', 'avec', 'sans', 'sous', 'sur', 'vers', 'chez', 'donc', 'mais', 'nous', 'vous', 'leur', 'leurs', 'cette', 'ces', 'des', 'une', 'tout', 'tous'].includes(w));
504
+ }
505
+
506
+ // Calculate relevance score
507
+ function calculateRelevance(memory, keywords, intention) {
508
+ let score = 0;
509
+
510
+ const content = (memory.content + ' ' + (memory.keywords || []).join(' ') + ' ' + (memory.level3Keywords || '')).toLowerCase();
511
+
512
+ // Keyword matches
513
+ keywords.forEach(kw => {
514
+ if (content.includes(kw)) score += 2;
515
+ });
516
+
517
+ // Intention words in content
518
+ const intentionWords = extractKeywords(intention);
519
+ intentionWords.forEach(w => {
520
+ if (content.includes(w)) score += 1;
521
+ });
522
+
523
+ // Recent recall boost
524
+ if (memory.recallCount > 0) score += memory.recallCount * 0.5;
525
+
526
+ // Saillance boost
527
+ score += memory.saillance / 50;
528
+
529
+ return score;
530
+ }
531
+
532
+ // Render memory cards
533
+ function renderMemoryCards(scored) {
534
+ const container = document.getElementById('memoryCards');
535
+ const typeIcons = { episodic: '📅', semantic: '📖', procedural: '⚡' };
536
+ const typeLabels = { episodic: 'Episodique', semantic: 'Sémantique', procedural: 'Procédurale' };
537
+
538
+ container.innerHTML = scored.map(({ memory, score }) => `
539
+ <div class="memory-card" data-id="${memory.id}">
540
+ <div class="type-icon">${typeIcons[memory.memoryType] || '📄'}</div>
541
+ <div class="content">
542
+ <p>${escapeHtml(memory.content)}</p>
543
+ <div class="meta">
544
+ <span>📍 ${memory.directory.split('/').pop()}</span>
545
+ <span>🏷️ ${typeLabels[memory.memoryType]}</span>
546
+ <span>💪 ${memory.saillance}/100</span>
547
+ <span>🔁 ${memory.recallCount}</span>
548
+ <span>📊 Score: ${Math.round(score)}</span>
549
+ </div>
550
+ </div>
551
+ <div class="actions">
552
+ <button onclick="recallMemory('${memory.id}')">🔄</button>
553
+ <button class="remove" onclick="removeMemory('${memory.id}')">✕</button>
554
+ </div>
555
+ </div>
556
+ `).join('');
557
+
558
+ document.getElementById('memoryCount').textContent = `${scored.length} traces`;
559
+ }
560
+
561
+ // Build context output
562
+ function buildContextOutput(scored, intention) {
563
+ const typeLabels = { episodic: 'Episodique', semantic: 'Sémantique', procedural: 'Procédurale' };
564
+
565
+ let context = `# Contexte Mnésique\n\n`;
566
+ context += `## Intention\n${intention}\n\n`;
567
+ context += `## Traces pertinentes (${scored.length})\n\n`;
568
+
569
+ scored.forEach(({ memory }, i) => {
570
+ context += `### ${i + 1}. [${typeLabels[memory.memoryType]}] ${memory.directory.split('/').pop()}\n`;
571
+ context += `${memory.content}\n\n`;
572
+
573
+ if (memory.keywords && memory.keywords.length > 0) {
574
+ context += `**Indices:** ${memory.keywords.join(', ')}\n\n`;
575
+ }
576
+ });
577
+
578
+ context += `---\n*Généré par humemory le ${new Date().toLocaleString('fr-FR')}*\n`;
579
+
580
+ const textarea = document.getElementById('contextOutput');
581
+ textarea.value = context;
582
+ updateStats(context);
583
+ }
584
+
585
+ function updateStats(text) {
586
+ document.getElementById('charCount').textContent = `${text.length} caractères`;
587
+ // Rough token estimate (1 token ≈ 4 chars in French)
588
+ document.getElementById('tokenEstimate').textContent = `~${Math.round(text.length / 4)} tokens`;
589
+ }
590
+
591
+ // Actions
592
+ function copyContext() {
593
+ const text = document.getElementById('contextOutput').value;
594
+ navigator.clipboard.writeText(text);
595
+ showToast('✓', 'Contexte copié !');
596
+ }
597
+
598
+ function exportToAgent() {
599
+ const text = document.getElementById('contextOutput').value;
600
+ // For now, just copy - could integrate with OpenCode/Claude CLI
601
+ navigator.clipboard.writeText(text);
602
+ showToast('✓', 'Contexte copié ! Colle-le dans ton agent LLM.');
603
+ }
604
+
605
+ function saveAsMemory() {
606
+ const intention = document.getElementById('intentionInput').value;
607
+ const context = document.getElementById('contextOutput').value;
608
+
609
+ // Navigate to main dashboard with pre-filled form
610
+ const params = new URLSearchParams({
611
+ content: `Session: ${intention}`,
612
+ context: context
613
+ });
614
+ window.location.href = `/?${params.toString()}`;
615
+ }
616
+
617
+ async function recallMemory(id) {
618
+ try {
619
+ await fetch(`${API_BASE}/memories/${id}/recall`, { method: 'POST' });
620
+ showToast('✓', 'Trace réactivée !');
621
+ // Refresh
622
+ loadProjects();
623
+ } catch (error) {
624
+ showToast('✕', 'Erreur: ' + error.message);
625
+ }
626
+ }
627
+
628
+ function removeMemory(id) {
629
+ selectedMemories = selectedMemories.filter(m => m.id !== id);
630
+ const card = document.querySelector(`.memory-card[data-id="${id}"]`);
631
+ if (card) card.remove();
632
+
633
+ // Rebuild context
634
+ const scored = selectedMemories.map(m => ({ memory: m, score: 0 }));
635
+ const intention = document.getElementById('intentionInput').value;
636
+ buildContextOutput(scored, intention);
637
+
638
+ document.getElementById('memoryCount').textContent = `${selectedMemories.length} traces`;
639
+ }
640
+
641
+ function showToast(icon, message) {
642
+ const toast = document.getElementById('toast');
643
+ document.getElementById('toastIcon').textContent = icon;
644
+ document.getElementById('toastMessage').textContent = message;
645
+ toast.classList.add('show');
646
+ setTimeout(() => toast.classList.remove('show'), 3000);
647
+ }
648
+
649
+ function escapeHtml(text) {
650
+ const div = document.createElement('div');
651
+ div.textContent = text;
652
+ return div.innerHTML;
653
+ }
654
+
655
+ // Initialize
656
+ loadProjects();
657
+ </script>
658
+ </body>
659
+ </html>