moflo 4.0.1 → 4.0.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.
Files changed (91) hide show
  1. package/.claude/guidance/agent-bootstrap.md +12 -6
  2. package/bin/setup-project.mjs +201 -0
  3. package/package.json +114 -109
  4. package/v3/@claude-flow/cli/dist/src/memory/memory-bridge.js +194 -81
  5. package/v3/@claude-flow/cli/dist/src/memory/memory-initializer.js +1892 -1841
  6. package/v3/@claude-flow/memory/README.md +587 -0
  7. package/v3/@claude-flow/memory/dist/agent-memory-scope.d.ts +131 -0
  8. package/v3/@claude-flow/memory/dist/agent-memory-scope.js +223 -0
  9. package/v3/@claude-flow/memory/dist/agent-memory-scope.test.d.ts +8 -0
  10. package/v3/@claude-flow/memory/dist/agent-memory-scope.test.js +463 -0
  11. package/v3/@claude-flow/memory/dist/agentdb-adapter.d.ts +165 -0
  12. package/v3/@claude-flow/memory/dist/agentdb-adapter.js +806 -0
  13. package/v3/@claude-flow/memory/dist/agentdb-backend.d.ts +214 -0
  14. package/v3/@claude-flow/memory/dist/agentdb-backend.js +844 -0
  15. package/v3/@claude-flow/memory/dist/agentdb-backend.test.d.ts +7 -0
  16. package/v3/@claude-flow/memory/dist/agentdb-backend.test.js +258 -0
  17. package/v3/@claude-flow/memory/dist/application/commands/delete-memory.command.d.ts +65 -0
  18. package/v3/@claude-flow/memory/dist/application/commands/delete-memory.command.js +129 -0
  19. package/v3/@claude-flow/memory/dist/application/commands/store-memory.command.d.ts +48 -0
  20. package/v3/@claude-flow/memory/dist/application/commands/store-memory.command.js +72 -0
  21. package/v3/@claude-flow/memory/dist/application/index.d.ts +12 -0
  22. package/v3/@claude-flow/memory/dist/application/index.js +15 -0
  23. package/v3/@claude-flow/memory/dist/application/queries/search-memory.query.d.ts +72 -0
  24. package/v3/@claude-flow/memory/dist/application/queries/search-memory.query.js +143 -0
  25. package/v3/@claude-flow/memory/dist/application/services/memory-application-service.d.ts +121 -0
  26. package/v3/@claude-flow/memory/dist/application/services/memory-application-service.js +190 -0
  27. package/v3/@claude-flow/memory/dist/auto-memory-bridge.d.ts +226 -0
  28. package/v3/@claude-flow/memory/dist/auto-memory-bridge.js +709 -0
  29. package/v3/@claude-flow/memory/dist/auto-memory-bridge.test.d.ts +8 -0
  30. package/v3/@claude-flow/memory/dist/auto-memory-bridge.test.js +754 -0
  31. package/v3/@claude-flow/memory/dist/benchmark.test.d.ts +2 -0
  32. package/v3/@claude-flow/memory/dist/benchmark.test.js +277 -0
  33. package/v3/@claude-flow/memory/dist/cache-manager.d.ts +134 -0
  34. package/v3/@claude-flow/memory/dist/cache-manager.js +407 -0
  35. package/v3/@claude-flow/memory/dist/controller-registry.d.ts +216 -0
  36. package/v3/@claude-flow/memory/dist/controller-registry.js +893 -0
  37. package/v3/@claude-flow/memory/dist/controller-registry.test.d.ts +14 -0
  38. package/v3/@claude-flow/memory/dist/controller-registry.test.js +636 -0
  39. package/v3/@claude-flow/memory/dist/database-provider.d.ts +87 -0
  40. package/v3/@claude-flow/memory/dist/database-provider.js +410 -0
  41. package/v3/@claude-flow/memory/dist/database-provider.test.d.ts +7 -0
  42. package/v3/@claude-flow/memory/dist/database-provider.test.js +285 -0
  43. package/v3/@claude-flow/memory/dist/domain/entities/memory-entry.d.ts +143 -0
  44. package/v3/@claude-flow/memory/dist/domain/entities/memory-entry.js +226 -0
  45. package/v3/@claude-flow/memory/dist/domain/index.d.ts +11 -0
  46. package/v3/@claude-flow/memory/dist/domain/index.js +12 -0
  47. package/v3/@claude-flow/memory/dist/domain/repositories/memory-repository.interface.d.ts +102 -0
  48. package/v3/@claude-flow/memory/dist/domain/repositories/memory-repository.interface.js +11 -0
  49. package/v3/@claude-flow/memory/dist/domain/services/memory-domain-service.d.ts +105 -0
  50. package/v3/@claude-flow/memory/dist/domain/services/memory-domain-service.js +297 -0
  51. package/v3/@claude-flow/memory/dist/hnsw-index.d.ts +111 -0
  52. package/v3/@claude-flow/memory/dist/hnsw-index.js +781 -0
  53. package/v3/@claude-flow/memory/dist/hnsw-lite.d.ts +23 -0
  54. package/v3/@claude-flow/memory/dist/hnsw-lite.js +168 -0
  55. package/v3/@claude-flow/memory/dist/hybrid-backend.d.ts +245 -0
  56. package/v3/@claude-flow/memory/dist/hybrid-backend.js +569 -0
  57. package/v3/@claude-flow/memory/dist/hybrid-backend.test.d.ts +8 -0
  58. package/v3/@claude-flow/memory/dist/hybrid-backend.test.js +320 -0
  59. package/v3/@claude-flow/memory/dist/index.d.ts +208 -0
  60. package/v3/@claude-flow/memory/dist/index.js +362 -0
  61. package/v3/@claude-flow/memory/dist/infrastructure/index.d.ts +17 -0
  62. package/v3/@claude-flow/memory/dist/infrastructure/index.js +16 -0
  63. package/v3/@claude-flow/memory/dist/infrastructure/repositories/hybrid-memory-repository.d.ts +66 -0
  64. package/v3/@claude-flow/memory/dist/infrastructure/repositories/hybrid-memory-repository.js +409 -0
  65. package/v3/@claude-flow/memory/dist/learning-bridge.d.ts +137 -0
  66. package/v3/@claude-flow/memory/dist/learning-bridge.js +335 -0
  67. package/v3/@claude-flow/memory/dist/learning-bridge.test.d.ts +8 -0
  68. package/v3/@claude-flow/memory/dist/learning-bridge.test.js +578 -0
  69. package/v3/@claude-flow/memory/dist/memory-graph.d.ts +100 -0
  70. package/v3/@claude-flow/memory/dist/memory-graph.js +333 -0
  71. package/v3/@claude-flow/memory/dist/memory-graph.test.d.ts +8 -0
  72. package/v3/@claude-flow/memory/dist/memory-graph.test.js +609 -0
  73. package/v3/@claude-flow/memory/dist/migration.d.ts +68 -0
  74. package/v3/@claude-flow/memory/dist/migration.js +513 -0
  75. package/v3/@claude-flow/memory/dist/persistent-sona.d.ts +144 -0
  76. package/v3/@claude-flow/memory/dist/persistent-sona.js +332 -0
  77. package/v3/@claude-flow/memory/dist/query-builder.d.ts +211 -0
  78. package/v3/@claude-flow/memory/dist/query-builder.js +438 -0
  79. package/v3/@claude-flow/memory/dist/rvf-backend.d.ts +51 -0
  80. package/v3/@claude-flow/memory/dist/rvf-backend.js +481 -0
  81. package/v3/@claude-flow/memory/dist/rvf-learning-store.d.ts +139 -0
  82. package/v3/@claude-flow/memory/dist/rvf-learning-store.js +295 -0
  83. package/v3/@claude-flow/memory/dist/rvf-migration.d.ts +45 -0
  84. package/v3/@claude-flow/memory/dist/rvf-migration.js +254 -0
  85. package/v3/@claude-flow/memory/dist/sqlite-backend.d.ts +121 -0
  86. package/v3/@claude-flow/memory/dist/sqlite-backend.js +564 -0
  87. package/v3/@claude-flow/memory/dist/sqljs-backend.d.ts +128 -0
  88. package/v3/@claude-flow/memory/dist/sqljs-backend.js +601 -0
  89. package/v3/@claude-flow/memory/dist/types.d.ts +484 -0
  90. package/v3/@claude-flow/memory/dist/types.js +58 -0
  91. package/v3/@claude-flow/memory/package.json +46 -0
@@ -0,0 +1,438 @@
1
+ /**
2
+ * V3 Query Builder
3
+ *
4
+ * Fluent API for building memory queries with filter chaining,
5
+ * sorting options, and pagination support.
6
+ *
7
+ * @module v3/memory/query-builder
8
+ */
9
+ /**
10
+ * Fluent query builder for constructing memory queries
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * const query = new QueryBuilder()
15
+ * .semantic('user authentication patterns')
16
+ * .inNamespace('security')
17
+ * .withTags(['auth', 'patterns'])
18
+ * .ofType('semantic')
19
+ * .limit(10)
20
+ * .threshold(0.8)
21
+ * .build();
22
+ * ```
23
+ */
24
+ export class QueryBuilder {
25
+ state;
26
+ constructor() {
27
+ this.state = {
28
+ type: 'hybrid',
29
+ tags: [],
30
+ metadata: {},
31
+ limit: 10,
32
+ offset: 0,
33
+ includeExpired: false,
34
+ sortDirection: 'desc',
35
+ };
36
+ }
37
+ /**
38
+ * Create a semantic (vector similarity) query
39
+ */
40
+ semantic(content) {
41
+ this.state.type = 'semantic';
42
+ this.state.content = content;
43
+ return this;
44
+ }
45
+ /**
46
+ * Create a semantic query with pre-computed embedding
47
+ */
48
+ semanticWithEmbedding(embedding) {
49
+ this.state.type = 'semantic';
50
+ this.state.embedding = embedding;
51
+ return this;
52
+ }
53
+ /**
54
+ * Create an exact key match query
55
+ */
56
+ exact(key) {
57
+ this.state.type = 'exact';
58
+ this.state.key = key;
59
+ return this;
60
+ }
61
+ /**
62
+ * Create a key prefix match query
63
+ */
64
+ prefix(keyPrefix) {
65
+ this.state.type = 'prefix';
66
+ this.state.keyPrefix = keyPrefix;
67
+ return this;
68
+ }
69
+ /**
70
+ * Create a tag-based query
71
+ */
72
+ byTags(tags) {
73
+ this.state.type = 'tag';
74
+ this.state.tags = tags;
75
+ return this;
76
+ }
77
+ /**
78
+ * Create a hybrid query (semantic + filters)
79
+ */
80
+ hybrid(content) {
81
+ this.state.type = 'hybrid';
82
+ this.state.content = content;
83
+ return this;
84
+ }
85
+ /**
86
+ * Filter by namespace
87
+ */
88
+ inNamespace(namespace) {
89
+ this.state.namespace = namespace;
90
+ return this;
91
+ }
92
+ /**
93
+ * Add tag filter (entries must have all specified tags)
94
+ */
95
+ withTags(tags) {
96
+ this.state.tags = [...this.state.tags, ...tags];
97
+ return this;
98
+ }
99
+ /**
100
+ * Add a single tag filter
101
+ */
102
+ withTag(tag) {
103
+ this.state.tags.push(tag);
104
+ return this;
105
+ }
106
+ /**
107
+ * Filter by memory type
108
+ */
109
+ ofType(type) {
110
+ this.state.memoryType = type;
111
+ return this;
112
+ }
113
+ /**
114
+ * Filter by access level
115
+ */
116
+ withAccessLevel(level) {
117
+ this.state.accessLevel = level;
118
+ return this;
119
+ }
120
+ /**
121
+ * Filter by owner
122
+ */
123
+ ownedBy(ownerId) {
124
+ this.state.ownerId = ownerId;
125
+ return this;
126
+ }
127
+ /**
128
+ * Filter by metadata field
129
+ */
130
+ whereMetadata(key, value) {
131
+ this.state.metadata[key] = value;
132
+ return this;
133
+ }
134
+ /**
135
+ * Filter by creation date range
136
+ */
137
+ createdBetween(after, before) {
138
+ this.state.createdAfter = after instanceof Date ? after.getTime() : after;
139
+ if (before !== undefined) {
140
+ this.state.createdBefore = before instanceof Date ? before.getTime() : before;
141
+ }
142
+ return this;
143
+ }
144
+ /**
145
+ * Filter entries created after a date
146
+ */
147
+ createdAfter(date) {
148
+ this.state.createdAfter = date instanceof Date ? date.getTime() : date;
149
+ return this;
150
+ }
151
+ /**
152
+ * Filter entries created before a date
153
+ */
154
+ createdBefore(date) {
155
+ this.state.createdBefore = date instanceof Date ? date.getTime() : date;
156
+ return this;
157
+ }
158
+ /**
159
+ * Filter by update date range
160
+ */
161
+ updatedBetween(after, before) {
162
+ this.state.updatedAfter = after instanceof Date ? after.getTime() : after;
163
+ if (before !== undefined) {
164
+ this.state.updatedBefore = before instanceof Date ? before.getTime() : before;
165
+ }
166
+ return this;
167
+ }
168
+ /**
169
+ * Filter entries updated in the last N milliseconds
170
+ */
171
+ updatedWithin(milliseconds) {
172
+ this.state.updatedAfter = Date.now() - milliseconds;
173
+ return this;
174
+ }
175
+ /**
176
+ * Set maximum number of results
177
+ */
178
+ limit(count) {
179
+ this.state.limit = Math.max(1, count);
180
+ return this;
181
+ }
182
+ /**
183
+ * Set pagination offset
184
+ */
185
+ offset(count) {
186
+ this.state.offset = Math.max(0, count);
187
+ return this;
188
+ }
189
+ /**
190
+ * Set pagination with page number and size
191
+ */
192
+ page(pageNumber, pageSize) {
193
+ this.state.limit = Math.max(1, pageSize);
194
+ this.state.offset = Math.max(0, (pageNumber - 1) * pageSize);
195
+ return this;
196
+ }
197
+ /**
198
+ * Set minimum similarity threshold for semantic search
199
+ */
200
+ threshold(minScore) {
201
+ this.state.threshold = Math.max(0, Math.min(1, minScore));
202
+ return this;
203
+ }
204
+ /**
205
+ * Include expired entries in results
206
+ */
207
+ includeExpired(include = true) {
208
+ this.state.includeExpired = include;
209
+ return this;
210
+ }
211
+ /**
212
+ * Set distance metric for semantic search
213
+ */
214
+ withMetric(metric) {
215
+ this.state.distanceMetric = metric;
216
+ return this;
217
+ }
218
+ /**
219
+ * Sort results by field
220
+ */
221
+ sortBy(field, direction = 'desc') {
222
+ this.state.sortField = field;
223
+ this.state.sortDirection = direction;
224
+ return this;
225
+ }
226
+ /**
227
+ * Sort by creation date (newest first)
228
+ */
229
+ newestFirst() {
230
+ return this.sortBy('createdAt', 'desc');
231
+ }
232
+ /**
233
+ * Sort by creation date (oldest first)
234
+ */
235
+ oldestFirst() {
236
+ return this.sortBy('createdAt', 'asc');
237
+ }
238
+ /**
239
+ * Sort by relevance score (highest first)
240
+ */
241
+ mostRelevant() {
242
+ return this.sortBy('score', 'desc');
243
+ }
244
+ /**
245
+ * Sort by access count (most accessed first)
246
+ */
247
+ mostAccessed() {
248
+ return this.sortBy('accessCount', 'desc');
249
+ }
250
+ /**
251
+ * Sort by last accessed time (most recent first)
252
+ */
253
+ recentlyAccessed() {
254
+ return this.sortBy('lastAccessedAt', 'desc');
255
+ }
256
+ /**
257
+ * Build the final query object
258
+ */
259
+ build() {
260
+ const query = {
261
+ type: this.state.type,
262
+ limit: this.state.limit,
263
+ };
264
+ // Add optional fields
265
+ if (this.state.content)
266
+ query.content = this.state.content;
267
+ if (this.state.embedding)
268
+ query.embedding = this.state.embedding;
269
+ if (this.state.key)
270
+ query.key = this.state.key;
271
+ if (this.state.keyPrefix)
272
+ query.keyPrefix = this.state.keyPrefix;
273
+ if (this.state.namespace)
274
+ query.namespace = this.state.namespace;
275
+ if (this.state.tags.length > 0)
276
+ query.tags = this.state.tags;
277
+ if (this.state.memoryType)
278
+ query.memoryType = this.state.memoryType;
279
+ if (this.state.accessLevel)
280
+ query.accessLevel = this.state.accessLevel;
281
+ if (this.state.ownerId)
282
+ query.ownerId = this.state.ownerId;
283
+ if (Object.keys(this.state.metadata).length > 0) {
284
+ query.metadata = this.state.metadata;
285
+ }
286
+ if (this.state.createdAfter)
287
+ query.createdAfter = this.state.createdAfter;
288
+ if (this.state.createdBefore)
289
+ query.createdBefore = this.state.createdBefore;
290
+ if (this.state.updatedAfter)
291
+ query.updatedAfter = this.state.updatedAfter;
292
+ if (this.state.updatedBefore)
293
+ query.updatedBefore = this.state.updatedBefore;
294
+ if (this.state.offset > 0)
295
+ query.offset = this.state.offset;
296
+ if (this.state.threshold !== undefined)
297
+ query.threshold = this.state.threshold;
298
+ if (this.state.includeExpired)
299
+ query.includeExpired = this.state.includeExpired;
300
+ if (this.state.distanceMetric)
301
+ query.distanceMetric = this.state.distanceMetric;
302
+ return query;
303
+ }
304
+ /**
305
+ * Clone this builder
306
+ */
307
+ clone() {
308
+ const cloned = new QueryBuilder();
309
+ cloned.state = {
310
+ ...this.state,
311
+ tags: [...this.state.tags],
312
+ metadata: { ...this.state.metadata },
313
+ };
314
+ return cloned;
315
+ }
316
+ /**
317
+ * Reset the builder to initial state
318
+ */
319
+ reset() {
320
+ this.state = {
321
+ type: 'hybrid',
322
+ tags: [],
323
+ metadata: {},
324
+ limit: 10,
325
+ offset: 0,
326
+ includeExpired: false,
327
+ sortDirection: 'desc',
328
+ };
329
+ return this;
330
+ }
331
+ }
332
+ /**
333
+ * Convenience function to create a new query builder
334
+ */
335
+ export function query() {
336
+ return new QueryBuilder();
337
+ }
338
+ /**
339
+ * Predefined query templates for common use cases
340
+ */
341
+ export const QueryTemplates = {
342
+ /**
343
+ * Find recent entries in a namespace
344
+ */
345
+ recentInNamespace(namespace, limit = 10) {
346
+ return query()
347
+ .inNamespace(namespace)
348
+ .newestFirst()
349
+ .limit(limit)
350
+ .build();
351
+ },
352
+ /**
353
+ * Find entries by exact key
354
+ */
355
+ byKey(namespace, key) {
356
+ return query()
357
+ .exact(key)
358
+ .inNamespace(namespace)
359
+ .limit(1)
360
+ .build();
361
+ },
362
+ /**
363
+ * Semantic search with threshold
364
+ */
365
+ semanticSearch(content, namespace, threshold = 0.7, limit = 10) {
366
+ const builder = query()
367
+ .semantic(content)
368
+ .threshold(threshold)
369
+ .limit(limit);
370
+ if (namespace) {
371
+ builder.inNamespace(namespace);
372
+ }
373
+ return builder.build();
374
+ },
375
+ /**
376
+ * Find entries with specific tags
377
+ */
378
+ withTags(tags, namespace, limit = 10) {
379
+ const builder = query()
380
+ .byTags(tags)
381
+ .limit(limit);
382
+ if (namespace) {
383
+ builder.inNamespace(namespace);
384
+ }
385
+ return builder.build();
386
+ },
387
+ /**
388
+ * Find entries owned by a specific agent
389
+ */
390
+ ownedBy(ownerId, namespace, limit = 10) {
391
+ const builder = query()
392
+ .ownedBy(ownerId)
393
+ .newestFirst()
394
+ .limit(limit);
395
+ if (namespace) {
396
+ builder.inNamespace(namespace);
397
+ }
398
+ return builder.build();
399
+ },
400
+ /**
401
+ * Find episodic memories within a time range
402
+ */
403
+ episodicInRange(after, before, limit = 100) {
404
+ return query()
405
+ .ofType('episodic')
406
+ .createdBetween(after, before)
407
+ .oldestFirst()
408
+ .limit(limit)
409
+ .build();
410
+ },
411
+ /**
412
+ * Find hot entries (frequently accessed)
413
+ */
414
+ hotEntries(namespace, limit = 10) {
415
+ const builder = query()
416
+ .mostAccessed()
417
+ .limit(limit);
418
+ if (namespace) {
419
+ builder.inNamespace(namespace);
420
+ }
421
+ return builder.build();
422
+ },
423
+ /**
424
+ * Find stale entries (not accessed recently)
425
+ */
426
+ staleEntries(staleThresholdMs, namespace, limit = 100) {
427
+ const builder = query()
428
+ .updatedBetween(0, Date.now() - staleThresholdMs)
429
+ .sortBy('lastAccessedAt', 'asc')
430
+ .limit(limit);
431
+ if (namespace) {
432
+ builder.inNamespace(namespace);
433
+ }
434
+ return builder.build();
435
+ },
436
+ };
437
+ export default QueryBuilder;
438
+ //# sourceMappingURL=query-builder.js.map
@@ -0,0 +1,51 @@
1
+ import type { IMemoryBackend, MemoryEntry, MemoryEntryUpdate, MemoryQuery, SearchOptions, SearchResult, BackendStats, HealthCheckResult } from './types.js';
2
+ export interface RvfBackendConfig {
3
+ databasePath: string;
4
+ dimensions?: number;
5
+ metric?: 'cosine' | 'euclidean' | 'dot';
6
+ quantization?: 'fp32' | 'fp16' | 'int8';
7
+ hnswM?: number;
8
+ hnswEfConstruction?: number;
9
+ maxElements?: number;
10
+ verbose?: boolean;
11
+ defaultNamespace?: string;
12
+ autoPersistInterval?: number;
13
+ }
14
+ export declare class RvfBackend implements IMemoryBackend {
15
+ private entries;
16
+ private keyIndex;
17
+ private hnswIndex;
18
+ private nativeDb;
19
+ private config;
20
+ private initialized;
21
+ private dirty;
22
+ private persisting;
23
+ private persistTimer;
24
+ private queryTimes;
25
+ private searchTimes;
26
+ constructor(config: RvfBackendConfig);
27
+ initialize(): Promise<void>;
28
+ shutdown(): Promise<void>;
29
+ store(entry: MemoryEntry): Promise<void>;
30
+ get(id: string): Promise<MemoryEntry | null>;
31
+ getByKey(namespace: string, key: string): Promise<MemoryEntry | null>;
32
+ update(id: string, updateData: MemoryEntryUpdate): Promise<MemoryEntry | null>;
33
+ delete(id: string): Promise<boolean>;
34
+ query(q: MemoryQuery): Promise<MemoryEntry[]>;
35
+ search(embedding: Float32Array, options: SearchOptions): Promise<SearchResult[]>;
36
+ bulkInsert(entries: MemoryEntry[]): Promise<void>;
37
+ bulkDelete(ids: string[]): Promise<number>;
38
+ count(namespace?: string): Promise<number>;
39
+ listNamespaces(): Promise<string[]>;
40
+ clearNamespace(namespace: string): Promise<number>;
41
+ getStats(): Promise<BackendStats>;
42
+ healthCheck(): Promise<HealthCheckResult>;
43
+ private tryNativeInit;
44
+ private compositeKey;
45
+ private bruteForceSearch;
46
+ private recordTiming;
47
+ private avg;
48
+ private loadFromDisk;
49
+ private persistToDisk;
50
+ }
51
+ //# sourceMappingURL=rvf-backend.d.ts.map