@slorenzot/memento-core 0.1.0 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +444 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,444 @@
|
|
|
1
|
+
# @slorenzot/memento-core
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@slorenzot/memento-core)
|
|
4
|
+
[](https://creativecommons.org/licenses/by-nc-nd/4.0/)
|
|
5
|
+
[](https://www.typescriptlang.org/)
|
|
6
|
+
|
|
7
|
+
> Core memory engine with SQLite FTS5 search, session management, and observation persistence for AI coding agents.
|
|
8
|
+
|
|
9
|
+
## 🚀 Instalación
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
# Using Bun (recomendado)
|
|
13
|
+
bun add @slorenzot/memento-core
|
|
14
|
+
|
|
15
|
+
# Using npm
|
|
16
|
+
npm install @slorenzot/memento-core
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## 💡 Uso Básico
|
|
20
|
+
|
|
21
|
+
### TypeScript
|
|
22
|
+
```typescript
|
|
23
|
+
import { MemoryEngine } from '@slorenzot/memento-core';
|
|
24
|
+
|
|
25
|
+
// Inicializar motor de memoria
|
|
26
|
+
const memory = new MemoryEngine('./data/memento.db');
|
|
27
|
+
|
|
28
|
+
// Crear una observación
|
|
29
|
+
const observation = await memory.createObservation({
|
|
30
|
+
title: 'Decisión de arquitectura',
|
|
31
|
+
content: 'Usar SQLite como motor de base de datos',
|
|
32
|
+
type: 'decision',
|
|
33
|
+
topicKey: 'architecture',
|
|
34
|
+
projectId: 'my-project'
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
console.log('Observación guardada:', observation);
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### Shell/Bun
|
|
41
|
+
```bash
|
|
42
|
+
# Ejecutar script TypeScript con motor de memoria
|
|
43
|
+
bun run memory-script.ts
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## 🔧 API Esencial
|
|
47
|
+
|
|
48
|
+
### Clase Principal
|
|
49
|
+
|
|
50
|
+
#### `MemoryEngine(dbPath?: string)`
|
|
51
|
+
|
|
52
|
+
Constructor del motor de memoria.
|
|
53
|
+
|
|
54
|
+
**Parámetros:**
|
|
55
|
+
- `dbPath` (opcional): Ruta al archivo de base de datos SQLite. Default: `'./data/memento.db'`
|
|
56
|
+
|
|
57
|
+
**Ejemplo:**
|
|
58
|
+
```typescript
|
|
59
|
+
const memory = new MemoryEngine('./custom/path.db');
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
#### Métodos de Observaciones
|
|
65
|
+
|
|
66
|
+
##### `createObservation(data)`
|
|
67
|
+
|
|
68
|
+
Crea una nueva observación en la memoria.
|
|
69
|
+
|
|
70
|
+
**Parámetros:**
|
|
71
|
+
```typescript
|
|
72
|
+
{
|
|
73
|
+
title: string;
|
|
74
|
+
content: string;
|
|
75
|
+
type: 'decision' | 'bug' | 'discovery' | 'note';
|
|
76
|
+
topicKey?: string | null;
|
|
77
|
+
projectId: string;
|
|
78
|
+
sessionId?: number;
|
|
79
|
+
metadata?: Record<string, unknown>;
|
|
80
|
+
}
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
**Retorna:** `Promise<Observation>`
|
|
84
|
+
|
|
85
|
+
**Ejemplo:**
|
|
86
|
+
```typescript
|
|
87
|
+
const observation = await memory.createObservation({
|
|
88
|
+
title: 'Bug encontrado',
|
|
89
|
+
content: 'Error de conexión al servidor',
|
|
90
|
+
type: 'bug',
|
|
91
|
+
projectId: 'project-123',
|
|
92
|
+
metadata: { severity: 'high', priority: 1 }
|
|
93
|
+
});
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
---
|
|
97
|
+
|
|
98
|
+
##### `search(params)`
|
|
99
|
+
|
|
100
|
+
Busca observaciones usando búsqueda full-text FTS5.
|
|
101
|
+
|
|
102
|
+
**Parámetros:**
|
|
103
|
+
```typescript
|
|
104
|
+
{
|
|
105
|
+
query?: string;
|
|
106
|
+
type?: 'decision' | 'bug' | 'discovery' | 'note';
|
|
107
|
+
projectId?: string;
|
|
108
|
+
topicKey?: string;
|
|
109
|
+
limit?: number;
|
|
110
|
+
offset?: number;
|
|
111
|
+
}
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
**Retorna:** `Promise<SearchResult>`
|
|
115
|
+
|
|
116
|
+
**Ejemplo:**
|
|
117
|
+
```typescript
|
|
118
|
+
const results = await memory.search({
|
|
119
|
+
query: 'arquitectura base de datos',
|
|
120
|
+
type: 'decision',
|
|
121
|
+
projectId: 'project-123',
|
|
122
|
+
limit: 10
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
console.log(`Encontrados ${results.total} observaciones:`);
|
|
126
|
+
results.observations.forEach(obs => console.log(obs.title));
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
---
|
|
130
|
+
|
|
131
|
+
##### `getObservation(id)`
|
|
132
|
+
|
|
133
|
+
Obtiene una observación por su ID.
|
|
134
|
+
|
|
135
|
+
**Parámetros:**
|
|
136
|
+
- `id`: ID numérico de la observación
|
|
137
|
+
|
|
138
|
+
**Retorna:** `Promise<Observation | null>`
|
|
139
|
+
|
|
140
|
+
**Ejemplo:**
|
|
141
|
+
```typescript
|
|
142
|
+
const observation = await memory.getObservation(123);
|
|
143
|
+
if (observation) {
|
|
144
|
+
console.log('Observación encontrada:', observation.title);
|
|
145
|
+
}
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
---
|
|
149
|
+
|
|
150
|
+
##### `updateObservation(id, updates)`
|
|
151
|
+
|
|
152
|
+
Actualiza una observación existente.
|
|
153
|
+
|
|
154
|
+
**Parámetros:**
|
|
155
|
+
- `id`: ID numérico de la observación
|
|
156
|
+
- `updates`: Objeto con campos a actualizar
|
|
157
|
+
|
|
158
|
+
**Retorna:** `Promise<Observation>`
|
|
159
|
+
|
|
160
|
+
**Ejemplo:**
|
|
161
|
+
```typescript
|
|
162
|
+
const updated = await memory.updateObservation(123, {
|
|
163
|
+
title: 'Título actualizado',
|
|
164
|
+
content: 'Contenido modificado'
|
|
165
|
+
});
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
---
|
|
169
|
+
|
|
170
|
+
##### `deleteObservation(id)`
|
|
171
|
+
|
|
172
|
+
Elimina una observación por su ID.
|
|
173
|
+
|
|
174
|
+
**Parámetros:**
|
|
175
|
+
- `id`: ID numérico de la observación
|
|
176
|
+
|
|
177
|
+
**Retorna:** `Promise<void>`
|
|
178
|
+
|
|
179
|
+
**Ejemplo:**
|
|
180
|
+
```typescript
|
|
181
|
+
await memory.deleteObservation(123);
|
|
182
|
+
console.log('Observación eliminada');
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
---
|
|
186
|
+
|
|
187
|
+
#### Métodos de Sesiones
|
|
188
|
+
|
|
189
|
+
##### `createSession(data)`
|
|
190
|
+
|
|
191
|
+
Crea una nueva sesión para seguimiento de conversaciones.
|
|
192
|
+
|
|
193
|
+
**Parámetros:**
|
|
194
|
+
```typescript
|
|
195
|
+
{
|
|
196
|
+
projectId: string;
|
|
197
|
+
metadata?: Record<string, unknown>;
|
|
198
|
+
}
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
**Retorna:** `Promise<Session>`
|
|
202
|
+
|
|
203
|
+
**Ejemplo:**
|
|
204
|
+
```typescript
|
|
205
|
+
const session = await memory.createSession({
|
|
206
|
+
projectId: 'my-project',
|
|
207
|
+
metadata: { agent: 'claude', userId: 'user-123' }
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
console.log('Sesión iniciada:', session.uuid);
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
---
|
|
214
|
+
|
|
215
|
+
##### `getSession(id)`
|
|
216
|
+
|
|
217
|
+
Obtiene una sesión por su ID.
|
|
218
|
+
|
|
219
|
+
**Parámetros:**
|
|
220
|
+
- `id`: ID numérico de la sesión
|
|
221
|
+
|
|
222
|
+
**Retorna:** `Promise<Session | null>`
|
|
223
|
+
|
|
224
|
+
**Ejemplo:**
|
|
225
|
+
```typescript
|
|
226
|
+
const session = await memory.getSession(456);
|
|
227
|
+
if (session) {
|
|
228
|
+
console.log('Sesión encontrada:', session.uuid);
|
|
229
|
+
}
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
---
|
|
233
|
+
|
|
234
|
+
##### `endSession(id)`
|
|
235
|
+
|
|
236
|
+
Finaliza una sesión activa.
|
|
237
|
+
|
|
238
|
+
**Parámetros:**
|
|
239
|
+
- `id`: ID numérico de la sesión
|
|
240
|
+
|
|
241
|
+
**Retorna:** `Promise<Session>`
|
|
242
|
+
|
|
243
|
+
**Ejemplo:**
|
|
244
|
+
```typescript
|
|
245
|
+
const endedSession = await memory.endSession(456);
|
|
246
|
+
console.log('Sesión finalizada:', endedSession.endedAt);
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
---
|
|
250
|
+
|
|
251
|
+
#### Método de Cierre
|
|
252
|
+
|
|
253
|
+
##### `close()`
|
|
254
|
+
|
|
255
|
+
Cierra la conexión con la base de datos.
|
|
256
|
+
|
|
257
|
+
**Retorna:** `void`
|
|
258
|
+
|
|
259
|
+
**Ejemplo:**
|
|
260
|
+
```typescript
|
|
261
|
+
// En cleanup de aplicación
|
|
262
|
+
memory.close();
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
---
|
|
266
|
+
|
|
267
|
+
## 📝 Tipos Principales
|
|
268
|
+
|
|
269
|
+
```typescript
|
|
270
|
+
interface Observation {
|
|
271
|
+
id: number;
|
|
272
|
+
uuid: string;
|
|
273
|
+
sessionId: number;
|
|
274
|
+
title: string;
|
|
275
|
+
content: string;
|
|
276
|
+
type: 'decision' | 'bug' | 'discovery' | 'note';
|
|
277
|
+
topicKey: string | null;
|
|
278
|
+
projectId: string;
|
|
279
|
+
createdAt: Date;
|
|
280
|
+
metadata: Record<string, unknown>;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
interface Session {
|
|
284
|
+
id: number;
|
|
285
|
+
uuid: string;
|
|
286
|
+
projectId: string;
|
|
287
|
+
startedAt: Date;
|
|
288
|
+
endedAt: Date | null;
|
|
289
|
+
metadata: Record<string, unknown>;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
interface SearchParams {
|
|
293
|
+
query?: string;
|
|
294
|
+
type?: Observation['type'];
|
|
295
|
+
projectId?: string;
|
|
296
|
+
topicKey?: string;
|
|
297
|
+
limit?: number;
|
|
298
|
+
offset?: number;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
interface SearchResult {
|
|
302
|
+
observations: Observation[];
|
|
303
|
+
total: number;
|
|
304
|
+
}
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
## ⚡ Ejemplos Prácticos
|
|
308
|
+
|
|
309
|
+
### Ejemplo 1: Flujo Completo de Memoria
|
|
310
|
+
|
|
311
|
+
```typescript
|
|
312
|
+
import { MemoryEngine } from '@slorenzot/memento-core';
|
|
313
|
+
|
|
314
|
+
const memory = new MemoryEngine('./memory.db');
|
|
315
|
+
|
|
316
|
+
// Crear sesión para seguimiento
|
|
317
|
+
const session = await memory.createSession({
|
|
318
|
+
projectId: 'my-app',
|
|
319
|
+
metadata: { agent: 'claude' }
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
// Guardar observaciones durante el trabajo
|
|
323
|
+
await memory.createObservation({
|
|
324
|
+
sessionId: session.id,
|
|
325
|
+
title: 'Configuración de servidor',
|
|
326
|
+
content: 'Usar Express.js con middleware de seguridad',
|
|
327
|
+
type: 'decision',
|
|
328
|
+
projectId: 'my-app',
|
|
329
|
+
topicKey: 'backend'
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
await memory.createObservation({
|
|
333
|
+
sessionId: session.id,
|
|
334
|
+
title: 'Bug en autenticación',
|
|
335
|
+
content: 'El JWT no expira correctamente',
|
|
336
|
+
type: 'bug',
|
|
337
|
+
projectId: 'my-app',
|
|
338
|
+
topicKey: 'security'
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
// Buscar decisiones relacionadas
|
|
342
|
+
const decisions = await memory.search({
|
|
343
|
+
type: 'decision',
|
|
344
|
+
projectId: 'my-app'
|
|
345
|
+
});
|
|
346
|
+
|
|
347
|
+
console.log('Decisiones tomadas:', decisions.observations);
|
|
348
|
+
|
|
349
|
+
// Finalizar sesión
|
|
350
|
+
await memory.endSession(session.id);
|
|
351
|
+
|
|
352
|
+
// Cerrar conexión
|
|
353
|
+
memory.close();
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
### Ejemplo 2: Búsqueda Avanzada
|
|
357
|
+
|
|
358
|
+
```typescript
|
|
359
|
+
import { MemoryEngine } from '@slorenzot/memento-core';
|
|
360
|
+
|
|
361
|
+
const memory = new MemoryEngine('./memory.db');
|
|
362
|
+
|
|
363
|
+
// Búsqueda compleja con múltiples filtros
|
|
364
|
+
const results = await memory.search({
|
|
365
|
+
query: 'base de datos arquitectura',
|
|
366
|
+
type: 'decision',
|
|
367
|
+
projectId: 'my-app',
|
|
368
|
+
limit: 5,
|
|
369
|
+
offset: 10
|
|
370
|
+
});
|
|
371
|
+
|
|
372
|
+
console.log(`Total de resultados: ${results.total}`);
|
|
373
|
+
results.observations.forEach((obs, index) => {
|
|
374
|
+
console.log(`${index + 1}. ${obs.title}`);
|
|
375
|
+
console.log(` ${obs.content.substring(0, 100)}...`);
|
|
376
|
+
console.log(` Tipo: ${obs.type} | Tópico: ${obs.topicKey}`);
|
|
377
|
+
});
|
|
378
|
+
|
|
379
|
+
memory.close();
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
## ⚠️ Licencia Restrictiva
|
|
383
|
+
|
|
384
|
+
Este paquete está bajo **Licencia CC BY-NC-ND 4.0**:
|
|
385
|
+
- ✅ **Uso personal y educacional permitido**
|
|
386
|
+
- ✅ **Compartir con atribución al autor**
|
|
387
|
+
- ❌ **Uso comercial NO permitido**
|
|
388
|
+
- ❌ **Modificaciones o forks NO permitidos**
|
|
389
|
+
|
|
390
|
+
**Autor**: Soulberto Lorenzo (slorenzot@gmail.com)
|
|
391
|
+
|
|
392
|
+
## 🔄 Dependencias
|
|
393
|
+
|
|
394
|
+
### Dependencias Principales
|
|
395
|
+
- `zod` - Validación de esquemas
|
|
396
|
+
- `nanoid` - Generación de IDs únicos
|
|
397
|
+
|
|
398
|
+
### Peer Dependencies
|
|
399
|
+
- `bun` v1.0+ (recomendado)
|
|
400
|
+
- `node` v20+ (compatible)
|
|
401
|
+
|
|
402
|
+
## 🛠️ Desarrollo
|
|
403
|
+
|
|
404
|
+
```bash
|
|
405
|
+
# Clonar el proyecto
|
|
406
|
+
git clone https://github.com/slorenzot/memento.git
|
|
407
|
+
cd memento/packages/core
|
|
408
|
+
|
|
409
|
+
# Instalar dependencias
|
|
410
|
+
bun install
|
|
411
|
+
|
|
412
|
+
# Desarrollo
|
|
413
|
+
bun run dev
|
|
414
|
+
|
|
415
|
+
# Build
|
|
416
|
+
bun run build
|
|
417
|
+
|
|
418
|
+
# Tests
|
|
419
|
+
bun test
|
|
420
|
+
```
|
|
421
|
+
|
|
422
|
+
## 📋 Changelog
|
|
423
|
+
|
|
424
|
+
### [0.1.0] - 2024-04-04
|
|
425
|
+
- **Added**: Versión inicial del motor de memoria
|
|
426
|
+
- **Added**: SQLite con FTS5 para búsqueda full-text
|
|
427
|
+
- **Added**: Gestión de sesiones y observaciones
|
|
428
|
+
- **Added**: Soporte completo de TypeScript
|
|
429
|
+
|
|
430
|
+
## 👤 Autor
|
|
431
|
+
|
|
432
|
+
**Soulberto Lorenzo**
|
|
433
|
+
- GitHub: [@slorenzot](https://github.com/slorenzot)
|
|
434
|
+
- Email: slorenzot@gmail.com
|
|
435
|
+
|
|
436
|
+
## 📄 Licencia
|
|
437
|
+
|
|
438
|
+
Este paquete está bajo Licencia **Creative Commons Attribution-NonCommercial-NoDerivs 4.0 International**.
|
|
439
|
+
|
|
440
|
+
[Ver Licencia Completa](https://github.com/slorenzot/memento/blob/main/LICENSE)
|
|
441
|
+
|
|
442
|
+
---
|
|
443
|
+
|
|
444
|
+
**⚠️ Importante**: Este paquete tiene licencia restrictiva. Respeta los términos de la licencia CC BY-NC-ND 4.0.
|