@monoes/memory 1.0.15 → 1.0.16
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 +8 -12
- package/dist/cache-manager.d.ts +0 -36
- package/dist/cache-manager.d.ts.map +1 -1
- package/dist/cache-manager.js +0 -78
- package/dist/cache-manager.js.map +1 -1
- package/dist/index.d.ts +8 -189
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -326
- package/dist/index.js.map +1 -1
- package/dist/sqlite-backend.d.ts.map +1 -1
- package/dist/sqlite-backend.js +2 -3
- package/dist/sqlite-backend.js.map +1 -1
- package/package.json +1 -1
- package/dist/controller-registry.d.ts +0 -206
- package/dist/controller-registry.d.ts.map +0 -1
- package/dist/controller-registry.js +0 -497
- package/dist/controller-registry.js.map +0 -1
- package/dist/database-provider.d.ts +0 -86
- package/dist/database-provider.d.ts.map +0 -1
- package/dist/database-provider.js +0 -397
- package/dist/database-provider.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,342 +1,28 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @monomind/memory -
|
|
2
|
+
* @monomind/memory - Persistent Memory Backends for Monomind
|
|
3
3
|
*
|
|
4
|
-
* Provides
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* the live bridge path; the migration escape hatch for legacy LanceDB stores
|
|
8
|
-
* is gone too — migrate before upgrading past this point if you still have
|
|
9
|
-
* one). UnifiedMemoryService below is backed by SQLiteBackend. It is still
|
|
10
|
-
* not the live CLI memory path — the CLI's
|
|
11
|
-
* memory-bridge.ts talks to SQLiteBackend/SqlJsBackend directly and does not
|
|
12
|
-
* go through this class — but external @monomind/memory consumers who
|
|
13
|
-
* instantiate it now get the current engine, not the legacy adapter.
|
|
4
|
+
* Provides SQLite-backed memory engines (better-sqlite3 native driver with
|
|
5
|
+
* sql.js WASM fallback), dense vector embeddings storage, pure-JS HNSW indexing,
|
|
6
|
+
* document chunking/retrieval, and cross-session checkpointers.
|
|
14
7
|
*
|
|
15
8
|
* @module @monomind/memory
|
|
16
|
-
*
|
|
17
|
-
* @example
|
|
18
|
-
* ```typescript
|
|
19
|
-
* import { UnifiedMemoryService, query, QueryTemplates } from '@monomind/memory';
|
|
20
|
-
*
|
|
21
|
-
* // Initialize the memory service
|
|
22
|
-
* const memory = new UnifiedMemoryService({
|
|
23
|
-
* dimensions: 1536,
|
|
24
|
-
* cacheEnabled: true,
|
|
25
|
-
* embeddingGenerator: async (text) => embeddings.embed(text),
|
|
26
|
-
* });
|
|
27
|
-
*
|
|
28
|
-
* await memory.initialize();
|
|
29
|
-
*
|
|
30
|
-
* // Store entries
|
|
31
|
-
* await memory.store({
|
|
32
|
-
* key: 'auth-patterns',
|
|
33
|
-
* content: 'OAuth 2.0 implementation patterns for secure authentication',
|
|
34
|
-
* tags: ['auth', 'security', 'patterns'],
|
|
35
|
-
* });
|
|
36
|
-
*
|
|
37
|
-
* // Semantic search
|
|
38
|
-
* const results = await memory.semanticSearch('user authentication best practices', 5);
|
|
39
|
-
*
|
|
40
|
-
* // Query with fluent builder
|
|
41
|
-
* const entries = await memory.query(
|
|
42
|
-
* query()
|
|
43
|
-
* .semantic('security vulnerabilities')
|
|
44
|
-
* .inNamespace('security')
|
|
45
|
-
* .withTags(['critical'])
|
|
46
|
-
* .threshold(0.8)
|
|
47
|
-
* .limit(10)
|
|
48
|
-
* .build()
|
|
49
|
-
* );
|
|
50
|
-
* ```
|
|
51
9
|
*/
|
|
52
|
-
// Utility Functions and Constants
|
|
10
|
+
// Utility Functions and Constants
|
|
53
11
|
export { generateMemoryId, createDefaultEntry, PERFORMANCE_TARGETS, } from './types.js';
|
|
54
|
-
// ===== Controller Registry (ADR-053) =====
|
|
55
|
-
export { ControllerRegistry, INIT_LEVELS } from './controller-registry.js';
|
|
56
12
|
// ===== Core Components =====
|
|
57
|
-
|
|
13
|
+
import { SQLiteBackend } from './sqlite-backend.js';
|
|
14
|
+
export { SQLiteBackend };
|
|
58
15
|
export { SqlJsBackend } from './sqljs-backend.js';
|
|
59
16
|
export { HNSWIndex } from './hnsw-index.js';
|
|
60
|
-
export { CacheManager
|
|
17
|
+
export { CacheManager } from './cache-manager.js';
|
|
61
18
|
export { QueryBuilder, query, QueryTemplates } from './query-builder.js';
|
|
62
19
|
export { MemoryMigrator, createMigrator, migrateMultipleSources } from './migration.js';
|
|
63
|
-
|
|
64
|
-
// ===== Graph Checkpointing (Task 08) =====
|
|
20
|
+
// ===== Graph Checkpointing =====
|
|
65
21
|
export { SwarmCheckpointer } from './checkpointer.js';
|
|
66
|
-
// =====
|
|
22
|
+
// ===== Document Chunker & Knowledge Base =====
|
|
67
23
|
export { chunkDocument, KnowledgeStore, KnowledgeRetriever } from './knowledge/index.js';
|
|
68
|
-
// =====
|
|
69
|
-
import { EventEmitter } from 'node:events';
|
|
70
|
-
import { createDefaultEntry, } from './types.js';
|
|
71
|
-
import { SQLiteBackend } from './sqlite-backend.js';
|
|
72
|
-
import { MemoryMigrator } from './migration.js';
|
|
73
|
-
/**
|
|
74
|
-
* Unified Memory Service
|
|
75
|
-
*
|
|
76
|
-
* High-level interface for the V1 memory system, backed by SQLiteBackend.
|
|
77
|
-
* Provides a simple API for common operations with automatic embedding support.
|
|
78
|
-
*
|
|
79
|
-
* RETENTION NOTE (2026-07) — read before deleting this as "dead code":
|
|
80
|
-
*
|
|
81
|
-
* This class, the four `create*Service` factories below, and the package's
|
|
82
|
-
* default export have ZERO callers inside this monorepo. The live CLI memory
|
|
83
|
-
* path is `packages/@monomind/cli/src/memory/memory-bridge.ts`, which
|
|
84
|
-
* constructs SQLiteBackend/SqlJsBackend directly and never touches this class.
|
|
85
|
-
* Every in-repo import of `@monoes/memory` pulls a *different* symbol
|
|
86
|
-
* (SwarmCheckpointer, SQLiteBackend, HNSWIndex, chunkDocument).
|
|
87
|
-
*
|
|
88
|
-
* It is nevertheless RETAINED DELIBERATELY, not by accident: `@monoes/memory`
|
|
89
|
-
* is published to npm, and this is its documented headline API, its module
|
|
90
|
-
* docblock example, and its `export default`. Deleting it is a breaking change
|
|
91
|
-
* to a published package's primary entry point, which is a different decision
|
|
92
|
-
* from removing unreachable *internal* code — and the usual justification for
|
|
93
|
-
* deleting dead code (it has silently rotted) does not apply here, because
|
|
94
|
-
* `src/index.test.ts` now covers the whole surface: lifecycle, the full
|
|
95
|
-
* IMemoryBackend implementation, every convenience method, sharing, and all
|
|
96
|
-
* four factories.
|
|
97
|
-
*
|
|
98
|
-
* If you do decide to remove it, treat it as a semver-major change to
|
|
99
|
-
* @monoes/memory and delete `src/index.test.ts` with it.
|
|
100
|
-
*/
|
|
101
|
-
export class UnifiedMemoryService extends EventEmitter {
|
|
102
|
-
adapter;
|
|
103
|
-
config;
|
|
104
|
-
initialized = false;
|
|
105
|
-
constructor(config = {}) {
|
|
106
|
-
super();
|
|
107
|
-
this.config = {
|
|
108
|
-
dimensions: 1536,
|
|
109
|
-
autoEmbed: true,
|
|
110
|
-
...config,
|
|
111
|
-
};
|
|
112
|
-
this.adapter = new SQLiteBackend({
|
|
113
|
-
databasePath: this.config.persistenceEnabled === false ? ':memory:' : (this.config.persistencePath ?? ':memory:'),
|
|
114
|
-
defaultNamespace: this.config.defaultNamespace ?? 'default',
|
|
115
|
-
embeddingGenerator: this.config.embeddingGenerator,
|
|
116
|
-
});
|
|
117
|
-
// Forward adapter events
|
|
118
|
-
this.adapter.on('entry:stored', (data) => this.emit('entry:stored', data));
|
|
119
|
-
this.adapter.on('entry:updated', (data) => this.emit('entry:updated', data));
|
|
120
|
-
this.adapter.on('entry:deleted', (data) => this.emit('entry:deleted', data));
|
|
121
|
-
}
|
|
122
|
-
// ===== Lifecycle =====
|
|
123
|
-
async initialize() {
|
|
124
|
-
if (this.initialized)
|
|
125
|
-
return;
|
|
126
|
-
await this.adapter.initialize();
|
|
127
|
-
this.initialized = true;
|
|
128
|
-
this.emit('initialized');
|
|
129
|
-
}
|
|
130
|
-
async shutdown() {
|
|
131
|
-
if (!this.initialized)
|
|
132
|
-
return;
|
|
133
|
-
await this.adapter.shutdown();
|
|
134
|
-
this.initialized = false;
|
|
135
|
-
this.emit('shutdown');
|
|
136
|
-
}
|
|
137
|
-
// ===== IMemoryBackend Implementation =====
|
|
138
|
-
async store(entry) {
|
|
139
|
-
return this.adapter.store(entry);
|
|
140
|
-
}
|
|
141
|
-
async get(id) {
|
|
142
|
-
return this.adapter.get(id);
|
|
143
|
-
}
|
|
144
|
-
async getByKey(namespace, key) {
|
|
145
|
-
return this.adapter.getByKey(namespace, key);
|
|
146
|
-
}
|
|
147
|
-
async update(id, update) {
|
|
148
|
-
return this.adapter.update(id, update);
|
|
149
|
-
}
|
|
150
|
-
async delete(id) {
|
|
151
|
-
return this.adapter.delete(id);
|
|
152
|
-
}
|
|
153
|
-
async query(query) {
|
|
154
|
-
return this.adapter.query(query);
|
|
155
|
-
}
|
|
156
|
-
async search(embedding, options) {
|
|
157
|
-
return this.adapter.search(embedding, options);
|
|
158
|
-
}
|
|
159
|
-
async bulkInsert(entries) {
|
|
160
|
-
return this.adapter.bulkInsert(entries);
|
|
161
|
-
}
|
|
162
|
-
async bulkDelete(ids) {
|
|
163
|
-
return this.adapter.bulkDelete(ids);
|
|
164
|
-
}
|
|
165
|
-
async count(namespace) {
|
|
166
|
-
return this.adapter.count(namespace);
|
|
167
|
-
}
|
|
168
|
-
async listNamespaces() {
|
|
169
|
-
return this.adapter.listNamespaces();
|
|
170
|
-
}
|
|
171
|
-
async clearNamespace(namespace) {
|
|
172
|
-
return this.adapter.clearNamespace(namespace);
|
|
173
|
-
}
|
|
174
|
-
async getStats() {
|
|
175
|
-
return this.adapter.getStats();
|
|
176
|
-
}
|
|
177
|
-
async healthCheck() {
|
|
178
|
-
return this.adapter.healthCheck();
|
|
179
|
-
}
|
|
180
|
-
// ===== Convenience Methods =====
|
|
181
|
-
/**
|
|
182
|
-
* Store an entry from simple input
|
|
183
|
-
*/
|
|
184
|
-
async storeEntry(input) {
|
|
185
|
-
const entry = createDefaultEntry(input);
|
|
186
|
-
await this.adapter.store(entry);
|
|
187
|
-
return entry;
|
|
188
|
-
}
|
|
189
|
-
/**
|
|
190
|
-
* Semantic search by content string
|
|
191
|
-
*/
|
|
192
|
-
async semanticSearch(content, k = 10, threshold) {
|
|
193
|
-
const gen = this.config.embeddingGenerator;
|
|
194
|
-
if (!gen)
|
|
195
|
-
return [];
|
|
196
|
-
const embedding = await gen(content);
|
|
197
|
-
return this.adapter.search(embedding, { k, threshold });
|
|
198
|
-
}
|
|
199
|
-
/**
|
|
200
|
-
* Find similar entries to a given entry
|
|
201
|
-
*/
|
|
202
|
-
async findSimilar(id, k = 5) {
|
|
203
|
-
const entry = await this.get(id);
|
|
204
|
-
if (!entry || !entry.embedding) {
|
|
205
|
-
return [];
|
|
206
|
-
}
|
|
207
|
-
const results = await this.search(entry.embedding, { k: k + 1 });
|
|
208
|
-
// Filter out the source entry
|
|
209
|
-
return results.filter((r) => r.entry.id !== id).slice(0, k);
|
|
210
|
-
}
|
|
211
|
-
/**
|
|
212
|
-
* Get or create an entry
|
|
213
|
-
*/
|
|
214
|
-
async getOrCreate(namespace, key, creator) {
|
|
215
|
-
const existing = await this.getByKey(namespace, key);
|
|
216
|
-
if (existing)
|
|
217
|
-
return existing;
|
|
218
|
-
const input = await creator();
|
|
219
|
-
return this.storeEntry({ ...input, namespace, key });
|
|
220
|
-
}
|
|
221
|
-
/**
|
|
222
|
-
* Append content to an existing entry
|
|
223
|
-
*/
|
|
224
|
-
async appendContent(id, content) {
|
|
225
|
-
const entry = await this.get(id);
|
|
226
|
-
if (!entry)
|
|
227
|
-
return null;
|
|
228
|
-
return this.update(id, {
|
|
229
|
-
content: entry.content + '\n' + content,
|
|
230
|
-
});
|
|
231
|
-
}
|
|
232
|
-
/**
|
|
233
|
-
* Add tags to an existing entry
|
|
234
|
-
*/
|
|
235
|
-
async addTags(id, tags) {
|
|
236
|
-
const entry = await this.get(id);
|
|
237
|
-
if (!entry)
|
|
238
|
-
return null;
|
|
239
|
-
const newTags = [...new Set([...entry.tags, ...tags])];
|
|
240
|
-
return this.update(id, { tags: newTags });
|
|
241
|
-
}
|
|
242
|
-
/**
|
|
243
|
-
* Remove tags from an existing entry
|
|
244
|
-
*/
|
|
245
|
-
async removeTags(id, tags) {
|
|
246
|
-
const entry = await this.get(id);
|
|
247
|
-
if (!entry)
|
|
248
|
-
return null;
|
|
249
|
-
const newTags = entry.tags.filter((t) => !tags.includes(t));
|
|
250
|
-
return this.update(id, { tags: newTags });
|
|
251
|
-
}
|
|
252
|
-
// ===== Migration =====
|
|
253
|
-
/**
|
|
254
|
-
* Migrate from a legacy memory source
|
|
255
|
-
*/
|
|
256
|
-
async migrateFrom(source, sourcePath, options = {}) {
|
|
257
|
-
const migrator = new MemoryMigrator(this.adapter, { source, sourcePath, ...options }, this.config.embeddingGenerator);
|
|
258
|
-
// Forward migration events
|
|
259
|
-
migrator.on('migration:started', (data) => this.emit('migration:started', data));
|
|
260
|
-
migrator.on('migration:progress', (data) => this.emit('migration:progress', data));
|
|
261
|
-
migrator.on('migration:completed', (data) => this.emit('migration:completed', data));
|
|
262
|
-
migrator.on('migration:failed', (data) => this.emit('migration:failed', data));
|
|
263
|
-
migrator.on('migration:error', (data) => this.emit('migration:error', data));
|
|
264
|
-
migrator.on('migration:warning', (data) => this.emit('migration:warning', data));
|
|
265
|
-
return migrator.migrate();
|
|
266
|
-
}
|
|
267
|
-
// ===== Cross-Agent Memory Sharing =====
|
|
268
|
-
/**
|
|
269
|
-
* Share an entry with another agent
|
|
270
|
-
*/
|
|
271
|
-
async shareWith(id, agentId) {
|
|
272
|
-
const entry = await this.get(id);
|
|
273
|
-
if (!entry)
|
|
274
|
-
return null;
|
|
275
|
-
const sharedWith = entry.metadata.sharedWith || [];
|
|
276
|
-
if (!sharedWith.includes(agentId)) {
|
|
277
|
-
sharedWith.push(agentId);
|
|
278
|
-
}
|
|
279
|
-
return this.update(id, {
|
|
280
|
-
metadata: { ...entry.metadata, sharedWith },
|
|
281
|
-
});
|
|
282
|
-
}
|
|
283
|
-
/**
|
|
284
|
-
* Get entries shared with a specific agent
|
|
285
|
-
*/
|
|
286
|
-
async getSharedWith(agentId) {
|
|
287
|
-
const all = await this.query({ type: 'hybrid', limit: 10000 });
|
|
288
|
-
return all.filter((entry) => {
|
|
289
|
-
const sharedWith = entry.metadata.sharedWith || [];
|
|
290
|
-
return sharedWith.includes(agentId);
|
|
291
|
-
});
|
|
292
|
-
}
|
|
293
|
-
// ===== Utility =====
|
|
294
|
-
/**
|
|
295
|
-
* Get the underlying adapter for advanced operations
|
|
296
|
-
*/
|
|
297
|
-
getAdapter() {
|
|
298
|
-
return this.adapter;
|
|
299
|
-
}
|
|
300
|
-
/**
|
|
301
|
-
* Check if the service is initialized
|
|
302
|
-
*/
|
|
303
|
-
isInitialized() {
|
|
304
|
-
return this.initialized;
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
// ===== Factory Functions =====
|
|
308
|
-
/**
|
|
309
|
-
* Create a simple in-memory service (for testing)
|
|
310
|
-
*/
|
|
311
|
-
export function createInMemoryService() {
|
|
312
|
-
return new UnifiedMemoryService({ persistenceEnabled: false });
|
|
313
|
-
}
|
|
314
|
-
/**
|
|
315
|
-
* Create a persistent memory service
|
|
316
|
-
*/
|
|
317
|
-
export function createPersistentService(path) {
|
|
318
|
-
return new UnifiedMemoryService({ persistenceEnabled: true, persistencePath: path });
|
|
319
|
-
}
|
|
320
|
-
/**
|
|
321
|
-
* Create a memory service with embedding support
|
|
322
|
-
*/
|
|
323
|
-
export function createEmbeddingService(embeddingGenerator, dimensions = 1536) {
|
|
324
|
-
return new UnifiedMemoryService({ embeddingGenerator, dimensions, autoEmbed: true });
|
|
325
|
-
}
|
|
326
|
-
/**
|
|
327
|
-
* Create a SQLite-backed memory service with persistence
|
|
328
|
-
*/
|
|
329
|
-
export function createHybridService(databasePath, embeddingGenerator, dimensions = 1536) {
|
|
330
|
-
return new UnifiedMemoryService({
|
|
331
|
-
embeddingGenerator,
|
|
332
|
-
dimensions,
|
|
333
|
-
autoEmbed: true,
|
|
334
|
-
persistenceEnabled: true,
|
|
335
|
-
persistencePath: databasePath,
|
|
336
|
-
});
|
|
337
|
-
}
|
|
338
|
-
// ===== Prompt Version Management (Task 24) =====
|
|
24
|
+
// ===== Prompt Version Management =====
|
|
339
25
|
export { PromptVersionStore } from './prompt-version-store.js';
|
|
340
26
|
// Default export
|
|
341
|
-
export default
|
|
27
|
+
export default SQLiteBackend;
|
|
342
28
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAuDH,kCAAkC;AAClC,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,mBAAmB,GACpB,MAAM,YAAY,CAAC;AAEpB,8BAA8B;AAC9B,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,CAAC;AAEzB,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEzE,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AAExF,kCAAkC;AAClC,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAGtD,gDAAgD;AAChD,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAUzF,wCAAwC;AACxC,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAO/D,iBAAiB;AACjB,eAAe,aAAa,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sqlite-backend.d.ts","sourceRoot":"","sources":["../src/sqlite-backend.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;
|
|
1
|
+
{"version":3,"file":"sqlite-backend.d.ts","sourceRoot":"","sources":["../src/sqlite-backend.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAWH,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAsB,KAAK,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACrE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAErD;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,4DAA4D;IAC5D,YAAY,EAAE,MAAM,CAAC;IAErB,6CAA6C;IAC7C,OAAO,EAAE,OAAO,CAAC;IAEjB,gCAAgC;IAChC,QAAQ,EAAE,OAAO,CAAC;IAElB,wBAAwB;IACxB,gBAAgB,EAAE,MAAM,CAAC;IAEzB,+DAA+D;IAC/D,kBAAkB,CAAC,EAAE,kBAAkB,CAAC;IAExC,0CAA0C;IAC1C,UAAU,EAAE,MAAM,CAAC;IAEnB,6BAA6B;IAC7B,OAAO,EAAE,OAAO,CAAC;IAEjB;;;;uCAImC;IACnC,aAAa,EAAE,MAAM,CAAC;CACvB;AAYD;;;;;GAKG;AACH,qBAAa,aAAc,SAAQ,UAAU;IAC3C,OAAO,CAAC,YAAY,CAAsB;IAE1C,YAAY,MAAM,GAAE,OAAO,CAAC,mBAAmB,CAAM,EASpD;IAED,UAAgB,UAAU,IAAI,OAAO,CAAC,SAAS,CAAC,CAkC/C;CACF;eAEc,aAAa"}
|
package/dist/sqlite-backend.js
CHANGED
|
@@ -10,9 +10,8 @@
|
|
|
10
10
|
*
|
|
11
11
|
* @module v1/memory/sqlite-backend
|
|
12
12
|
*/
|
|
13
|
-
// better-sqlite3 is an OPTIONAL dependency — sql.js is the documented fallback
|
|
14
|
-
//
|
|
15
|
-
// routinely fails to build native modules. This import must therefore be lazy.
|
|
13
|
+
// better-sqlite3 is an OPTIONAL dependency — sql.js is the documented fallback
|
|
14
|
+
// on platforms where native compilation is unavailable. This import must therefore be lazy.
|
|
16
15
|
//
|
|
17
16
|
// It used to be a static top-level import, and because index.ts re-exports
|
|
18
17
|
// SQLiteBackend, that made `import '@monoes/memory'` throw
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sqlite-backend.js","sourceRoot":"","sources":["../src/sqlite-backend.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH
|
|
1
|
+
{"version":3,"file":"sqlite-backend.js","sourceRoot":"","sources":["../src/sqlite-backend.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,+EAA+E;AAC/E,4FAA4F;AAC5F,EAAE;AACF,2EAA2E;AAC3E,2DAA2D;AAC3D,8EAA8E;AAC9E,6EAA6E;AAC7E,qEAAqE;AACrE,2CAA2C;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,kBAAkB,EAAkB,MAAM,iBAAiB,CAAC;AAoCrE,MAAM,cAAc,GAAwB;IAC1C,YAAY,EAAE,UAAU;IACxB,OAAO,EAAE,IAAI;IACb,QAAQ,EAAE,IAAI;IACd,gBAAgB,EAAE,SAAS;IAC3B,UAAU,EAAE,OAAO;IACnB,OAAO,EAAE,KAAK;IACd,aAAa,EAAE,CAAC;CACjB,CAAC;AAEF;;;;;GAKG;AACH,MAAM,OAAO,aAAc,SAAQ,UAAU;IACnC,YAAY,CAAsB;IAE1C,YAAY,MAAM,GAAiC,EAAE;QACnD,MAAM,MAAM,GAAG,EAAE,GAAG,cAAc,EAAE,GAAG,MAAM,EAAE,CAAC;QAChD,KAAK,CAAC;YACJ,gBAAgB,EAAE,MAAM,CAAC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AAC;QAED,OAAO,IAAI,kBAAkB,CAAC,EAAW,CAAC,CAAC;IAC7C,CAAC;CACF;AAED,eAAe,aAAa,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@monoes/memory",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.16",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Memory module - JSON pattern store, SQLite + embeddings backend, and a standalone pure-JS HNSW index; not a single unified backend",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -1,206 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ControllerRegistry - Central controller lifecycle management for memory backend
|
|
3
|
-
*
|
|
4
|
-
* Wraps the configured memory backend (SQLite via better-sqlite3/sql.js as of
|
|
5
|
-
* 2026-07; LanceDB support was fully removed) and adds CLI-specific controllers from
|
|
6
|
-
* @monomind/memory. Manages initialization (level-based ordering), health
|
|
7
|
-
* checks, and graceful shutdown.
|
|
8
|
-
*
|
|
9
|
-
* Per ADR-053: Replaces memory-initializer.js's raw sql.js usage with a unified
|
|
10
|
-
* controller ecosystem routing all memory operations through a single backend.
|
|
11
|
-
*
|
|
12
|
-
* @module @monomind/memory/controller-registry
|
|
13
|
-
*/
|
|
14
|
-
import { EventEmitter } from 'node:events';
|
|
15
|
-
import type { IMemoryBackend, EmbeddingGenerator, SONAMode } from './types.js';
|
|
16
|
-
import type { CacheConfig } from './types.js';
|
|
17
|
-
/**
|
|
18
|
-
* Memory controllers
|
|
19
|
-
*/
|
|
20
|
-
export type MemoryControllerName = 'reasoningBank' | 'skills' | 'reflexion' | 'causalGraph' | 'causalRecall' | 'learningSystem' | 'explainableRecall' | 'nightlyLearner' | 'graphTransformer' | 'mutationGuard' | 'attestationLog' | 'vectorBackend' | 'graphAdapter';
|
|
21
|
-
/**
|
|
22
|
-
* CLI-layer controllers (from @monomind/memory or new)
|
|
23
|
-
*/
|
|
24
|
-
export type CLIControllerName = 'learningBridge' | 'tieredCache' | 'hybridSearch' | 'federatedSession' | 'semanticRouter' | 'sonaTrajectory' | 'hierarchicalMemory' | 'memoryConsolidation' | 'batchOperations' | 'contextSynthesizer' | 'gnnService' | 'sonaOptimizer' | 'mmrDiversityRanker' | 'guardedVectorBackend';
|
|
25
|
-
/**
|
|
26
|
-
* All controller names
|
|
27
|
-
*/
|
|
28
|
-
export type ControllerName = MemoryControllerName | CLIControllerName;
|
|
29
|
-
/**
|
|
30
|
-
* Initialization level for dependency ordering
|
|
31
|
-
*/
|
|
32
|
-
export interface InitLevel {
|
|
33
|
-
level: number;
|
|
34
|
-
controllers: ControllerName[];
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Individual controller health status
|
|
38
|
-
*/
|
|
39
|
-
export interface ControllerHealth {
|
|
40
|
-
name: ControllerName;
|
|
41
|
-
status: 'healthy' | 'degraded' | 'unavailable';
|
|
42
|
-
initTimeMs: number;
|
|
43
|
-
error?: string;
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Aggregated health report for all controllers
|
|
47
|
-
*/
|
|
48
|
-
export interface RegistryHealthReport {
|
|
49
|
-
status: 'healthy' | 'degraded' | 'unhealthy';
|
|
50
|
-
controllers: ControllerHealth[];
|
|
51
|
-
storageBackendAvailable: boolean;
|
|
52
|
-
initTimeMs: number;
|
|
53
|
-
timestamp: number;
|
|
54
|
-
activeControllers: number;
|
|
55
|
-
totalControllers: number;
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Runtime configuration for controller activation
|
|
59
|
-
*/
|
|
60
|
-
export interface RuntimeConfig {
|
|
61
|
-
/** Database path for the memory backend (SQLite as of 2026-07) */
|
|
62
|
-
dbPath?: string;
|
|
63
|
-
/** Vector dimension (default: 384 for MiniLM) */
|
|
64
|
-
dimension?: number;
|
|
65
|
-
/** Embedding generator function */
|
|
66
|
-
embeddingGenerator?: EmbeddingGenerator;
|
|
67
|
-
/** Memory backend config */
|
|
68
|
-
memory?: {
|
|
69
|
-
enableHNSW?: boolean;
|
|
70
|
-
tieredCache?: Partial<CacheConfig>;
|
|
71
|
-
};
|
|
72
|
-
/** Neural config */
|
|
73
|
-
neural?: {
|
|
74
|
-
enabled?: boolean;
|
|
75
|
-
modelPath?: string;
|
|
76
|
-
sonaMode?: SONAMode;
|
|
77
|
-
};
|
|
78
|
-
/** Controllers to explicitly enable/disable */
|
|
79
|
-
controllers?: Partial<Record<ControllerName, boolean>>;
|
|
80
|
-
/** Backend instance to use (if pre-created) */
|
|
81
|
-
backend?: IMemoryBackend;
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Level-based initialization order per ADR-053.
|
|
85
|
-
* Controllers at each level can be initialized in parallel.
|
|
86
|
-
* Each level must complete before the next begins.
|
|
87
|
-
*/
|
|
88
|
-
export declare const INIT_LEVELS: InitLevel[];
|
|
89
|
-
/**
|
|
90
|
-
* Central registry for memory backend controller lifecycle management.
|
|
91
|
-
*
|
|
92
|
-
* Handles:
|
|
93
|
-
* - Level-based initialization ordering (levels 0-6)
|
|
94
|
-
* - Graceful degradation (each controller fails independently)
|
|
95
|
-
* - Config-driven activation (controllers only instantiate when enabled)
|
|
96
|
-
* - Health check aggregation across all controllers
|
|
97
|
-
* - Ordered shutdown (reverse initialization order)
|
|
98
|
-
*
|
|
99
|
-
* @example
|
|
100
|
-
* ```typescript
|
|
101
|
-
* const registry = new ControllerRegistry();
|
|
102
|
-
* await registry.initialize({
|
|
103
|
-
* dbPath: './data/memory.db',
|
|
104
|
-
* dimension: 384,
|
|
105
|
-
* memory: {
|
|
106
|
-
* enableHNSW: true,
|
|
107
|
-
* learningBridge: { sonaMode: 'balanced' },
|
|
108
|
-
* * },
|
|
109
|
-
* });
|
|
110
|
-
*
|
|
111
|
-
* const reasoning = registry.get<ReasoningBank>('reasoningBank');
|
|
112
|
-
*
|
|
113
|
-
* await registry.shutdown();
|
|
114
|
-
* ```
|
|
115
|
-
*/
|
|
116
|
-
export declare class ControllerRegistry extends EventEmitter {
|
|
117
|
-
private controllers;
|
|
118
|
-
private backend;
|
|
119
|
-
private config;
|
|
120
|
-
private initialized;
|
|
121
|
-
private initTimeMs;
|
|
122
|
-
/**
|
|
123
|
-
* Initialize all controllers in level-based order.
|
|
124
|
-
*
|
|
125
|
-
* Each level's controllers are initialized in parallel within the level.
|
|
126
|
-
* Failures are isolated: a controller that fails to init is marked as
|
|
127
|
-
* unavailable but does not block other controllers.
|
|
128
|
-
*/
|
|
129
|
-
initialize(config?: RuntimeConfig): Promise<void>;
|
|
130
|
-
/**
|
|
131
|
-
* Shutdown all controllers in reverse initialization order.
|
|
132
|
-
*/
|
|
133
|
-
shutdown(): Promise<void>;
|
|
134
|
-
/**
|
|
135
|
-
* Get a controller instance by name.
|
|
136
|
-
* Returns null if the controller is not initialized or unavailable.
|
|
137
|
-
*/
|
|
138
|
-
get<T>(name: ControllerName): T | null;
|
|
139
|
-
/**
|
|
140
|
-
* Check if a controller is enabled and initialized.
|
|
141
|
-
*/
|
|
142
|
-
isEnabled(name: ControllerName): boolean;
|
|
143
|
-
/**
|
|
144
|
-
* Aggregate health check across all controllers.
|
|
145
|
-
*/
|
|
146
|
-
healthCheck(): Promise<RegistryHealthReport>;
|
|
147
|
-
/**
|
|
148
|
-
* Get the underlying memory backend instance.
|
|
149
|
-
*/
|
|
150
|
-
/**
|
|
151
|
-
* Get the memory backend.
|
|
152
|
-
*/
|
|
153
|
-
getBackend(): IMemoryBackend | null;
|
|
154
|
-
/**
|
|
155
|
-
* Check if the registry is initialized.
|
|
156
|
-
*/
|
|
157
|
-
isInitialized(): boolean;
|
|
158
|
-
/**
|
|
159
|
-
* Get the number of active (successfully initialized) controllers.
|
|
160
|
-
*/
|
|
161
|
-
getActiveCount(): number;
|
|
162
|
-
/**
|
|
163
|
-
* List all registered controller names and their status.
|
|
164
|
-
*/
|
|
165
|
-
listControllers(): Array<{
|
|
166
|
-
name: ControllerName;
|
|
167
|
-
enabled: boolean;
|
|
168
|
-
level: number;
|
|
169
|
-
}>;
|
|
170
|
-
/**
|
|
171
|
-
* Check whether a controller should be initialized based on config.
|
|
172
|
-
*/
|
|
173
|
-
private isControllerEnabled;
|
|
174
|
-
/**
|
|
175
|
-
* Initialize a single controller with error isolation.
|
|
176
|
-
*/
|
|
177
|
-
private initController;
|
|
178
|
-
/**
|
|
179
|
-
* Factory method to create a controller instance.
|
|
180
|
-
* Handles CLI-layer controllers; internal controllers are
|
|
181
|
-
* accessed via backend.getController().
|
|
182
|
-
*/
|
|
183
|
-
private createController;
|
|
184
|
-
/**
|
|
185
|
-
* Shutdown a single controller gracefully.
|
|
186
|
-
*/
|
|
187
|
-
private shutdownController;
|
|
188
|
-
/**
|
|
189
|
-
* Create an EmbeddingService for controllers that need it.
|
|
190
|
-
* Uses the config's embedding generator or creates a minimal local service.
|
|
191
|
-
*/
|
|
192
|
-
private createEmbeddingService;
|
|
193
|
-
/**
|
|
194
|
-
* Lightweight in-memory tiered store (fallback when HierarchicalMemory
|
|
195
|
-
* cannot be initialized from legacy module).
|
|
196
|
-
* Enforces per-tier size limits to prevent unbounded memory growth.
|
|
197
|
-
*/
|
|
198
|
-
private createTieredMemoryStub;
|
|
199
|
-
/**
|
|
200
|
-
* No-op consolidation stub (fallback when MemoryConsolidation
|
|
201
|
-
* cannot be initialized from legacy module).
|
|
202
|
-
*/
|
|
203
|
-
private createConsolidationStub;
|
|
204
|
-
}
|
|
205
|
-
export default ControllerRegistry;
|
|
206
|
-
//# sourceMappingURL=controller-registry.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"controller-registry.d.ts","sourceRoot":"","sources":["../src/controller-registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,KAAK,EACV,cAAc,EAId,kBAAkB,EAClB,QAAQ,EACT,MAAM,YAAY,CAAC;AAEpB,OAAO,KAAK,EAAE,WA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