@easbot/memory 0.3.14 → 0.3.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.
Files changed (57) hide show
  1. package/README.en.md +216 -38
  2. package/README.md +213 -38
  3. package/dist/chunks/chunk-3HTZTI7U.cjs +1 -0
  4. package/dist/chunks/chunk-5W4K5UKV.mjs +53 -0
  5. package/dist/chunks/chunk-7XEOH55R.cjs +1 -0
  6. package/dist/chunks/chunk-BWPPLYIF.cjs +1 -0
  7. package/dist/chunks/chunk-FEMOFIOS.mjs +1 -0
  8. package/dist/chunks/chunk-FNT7WEHL.mjs +1 -0
  9. package/dist/chunks/chunk-I5YWAJHW.cjs +32 -0
  10. package/dist/chunks/chunk-JGXW3E73.mjs +59 -0
  11. package/dist/chunks/chunk-MQ72K25M.cjs +59 -0
  12. package/dist/chunks/chunk-NJVXQ7TV.cjs +1 -0
  13. package/dist/chunks/chunk-OWLFPNZG.cjs +1 -0
  14. package/dist/chunks/chunk-PWLSQFYA.mjs +32 -0
  15. package/dist/chunks/chunk-Q2MKNRER.cjs +53 -0
  16. package/dist/chunks/chunk-QF5S5MG7.mjs +0 -0
  17. package/dist/chunks/chunk-URADAZYW.cjs +1 -0
  18. package/dist/chunks/chunk-WQGSYA5D.mjs +1 -0
  19. package/dist/chunks/chunk-YHOJKRHE.mjs +1 -0
  20. package/dist/chunks/chunk-Z3NQERNT.mjs +1 -0
  21. package/dist/chunks/cli-handler-57MKQCNO.cjs +1 -0
  22. package/dist/chunks/cli-handler-WW3I2YV4.mjs +1 -0
  23. package/dist/chunks/config-BFJFRX2C.cjs +1 -0
  24. package/dist/chunks/config-M2KZYVRZ.mjs +1 -0
  25. package/dist/chunks/consolidate-YQ3H643L.cjs +2 -0
  26. package/dist/chunks/consolidate-ZCFRYIWV.mjs +2 -0
  27. package/dist/chunks/doctor-GVSMK4HL.cjs +2 -0
  28. package/dist/chunks/doctor-SPJ64FW3.mjs +2 -0
  29. package/dist/chunks/extract-5VSCY754.mjs +2 -0
  30. package/dist/chunks/extract-E54PPHMQ.cjs +2 -0
  31. package/dist/chunks/forget-AALO5DL5.mjs +3 -0
  32. package/dist/chunks/forget-GEAEUNRH.cjs +3 -0
  33. package/dist/chunks/graph-HSYCZI7R.mjs +3 -0
  34. package/dist/chunks/graph-QEGKUROQ.cjs +3 -0
  35. package/dist/chunks/init-2GZLH6RB.cjs +2 -0
  36. package/dist/chunks/init-U7XRD4MW.mjs +2 -0
  37. package/dist/chunks/interfaces-KNVKCV3Q.cjs +1 -0
  38. package/dist/chunks/interfaces-VBO3Z6QF.mjs +1 -0
  39. package/dist/chunks/mcp-WE7TV32J.cjs +1 -0
  40. package/dist/chunks/mcp-XPTJOCQA.mjs +1 -0
  41. package/dist/chunks/recall-JI2NYDLH.cjs +2 -0
  42. package/dist/chunks/recall-M6SAHHZX.mjs +2 -0
  43. package/dist/chunks/remember-FR5QGXFT.mjs +2 -0
  44. package/dist/chunks/remember-X33PMYA5.cjs +2 -0
  45. package/dist/chunks/status-6XW6Q3TT.mjs +2 -0
  46. package/dist/chunks/status-CPB6XZNU.cjs +2 -0
  47. package/dist/chunks/stdio-server-5LE3HFKN.mjs +1 -0
  48. package/dist/chunks/stdio-server-6PUOFDLR.cjs +1 -0
  49. package/dist/cli.cjs +2 -0
  50. package/dist/cli.d.cts +1 -0
  51. package/dist/cli.d.ts +1 -0
  52. package/dist/cli.mjs +2 -0
  53. package/dist/index.cjs +6 -146
  54. package/dist/index.d.cts +354 -170
  55. package/dist/index.d.ts +354 -170
  56. package/dist/index.mjs +6 -146
  57. package/package.json +21 -14
package/dist/index.d.cts CHANGED
@@ -1,6 +1,8 @@
1
- import { KnowledgeSearchOptions, MemoryKnowledgeConfigWithModels } from '@easbot/types';
1
+ import { KnowledgeSearchOptions, MemoryKnowledgeConfigWithModels, IGlobal, IInstance } from '@easbot/types';
2
2
  export { GRAPH_ENTITY_TYPE_DEFINITIONS, GRAPH_RELATION_TYPE_DEFINITIONS } from '@easbot/types';
3
- import Database, { Database as Database$1 } from 'better-sqlite3';
3
+ import { ZodTypeAny } from 'zod';
4
+ import { StdioServerConfig } from '@easbot/mcp';
5
+ import { SyncSqliteConnection } from '@easbot/database';
4
6
  export { EmbeddingModel, LanguageModel } from 'ai';
5
7
 
6
8
  type MemoryCategory = 'user_preference' | 'task_context' | 'technical_fact' | 'decision' | 'relationship' | 'reminder' | 'error_pattern' | 'workflow' | 'exploration_finding' | 'experience_summary' | 'tool_usage' | 'skill_creation' | 'test' | 'other';
@@ -56,54 +58,6 @@ interface MemoryRecallResult {
56
58
  }>;
57
59
  }
58
60
  type MemorySystemConfig = MemoryKnowledgeConfigWithModels;
59
- interface IMemorySystem {
60
- remember(fact: Omit<MemoryFact, 'id' | 'createdAt' | 'updatedAt'>): Promise<MemoryFact>;
61
- query(query: string, options?: MemoryQuery): Promise<MemoryRecallResult[]>;
62
- queryEdgesByNodeId(nodeId: number, options?: {
63
- maxDepth?: number;
64
- }): Promise<{
65
- node?: {
66
- id: number;
67
- name: string;
68
- type: string;
69
- };
70
- nodes: MemoryNode[];
71
- edges: MemoryEdge[];
72
- }>;
73
- forget(agentId: string, memoryId: string): Promise<void>;
74
- update(agentId: string, memoryId: string, patch: {
75
- content?: string;
76
- importance?: number;
77
- tags?: string[];
78
- }): Promise<MemoryFact>;
79
- listAgentIds(): Promise<string[]>;
80
- queryForSummary(agentId: string, options?: {
81
- limit?: number;
82
- category?: string;
83
- fromTime?: string;
84
- toTime?: string;
85
- }): Promise<MemoryFact[]>;
86
- archive(): Promise<void>;
87
- clear(): Promise<void>;
88
- close(): Promise<void>;
89
- sync(): Promise<{
90
- synced: number;
91
- created: number;
92
- updated: number;
93
- errors: string[];
94
- }>;
95
- getStatus(): Promise<{
96
- dbPath: string;
97
- workspaceDir: string;
98
- factsCount: number;
99
- nodesCount: number;
100
- edgesCount: number;
101
- embeddingLlmAvailable: boolean;
102
- graphLlmAvailable: boolean;
103
- healthy: boolean;
104
- meta: Record<string, string>;
105
- }>;
106
- }
107
61
  declare class MemoryError extends Error {
108
62
  readonly code: string;
109
63
  cause?: Error | undefined;
@@ -146,6 +100,7 @@ interface MemoryNode {
146
100
  properties?: Record<string, unknown>;
147
101
  createdAt: string;
148
102
  updatedAt: string;
103
+ ownerAgentId?: string | null;
149
104
  }
150
105
  interface MemoryEdge {
151
106
  id: number;
@@ -164,6 +119,8 @@ interface NodeQueryFilter {
164
119
  name?: string;
165
120
  type?: string;
166
121
  limit?: number;
122
+ scope?: 'agent_only' | 'shared_only' | 'both';
123
+ agentId?: string;
167
124
  }
168
125
  interface EdgeQueryFilter {
169
126
  ids?: number[];
@@ -195,157 +152,384 @@ declare function closeTokenizer(): Promise<void>;
195
152
  declare function toFtsTokens(text: string): string;
196
153
  declare function toFtsTokensForSearch(text: string): string;
197
154
 
155
+ interface BaseServiceContext {
156
+ workspaceDir: string;
157
+ rootDir: string;
158
+ }
159
+ interface MemoryServiceContext extends BaseServiceContext {
160
+ dbPath: string;
161
+ locale: 'zh-CN' | 'en-US';
162
+ remote: boolean;
163
+ config?: MemoryKnowledgeConfigWithModels;
164
+ agentId: string;
165
+ }
166
+ type ErrorCode = 'AGENT_ID_REQUIRED' | 'SESSION_ID_REQUIRED' | 'CONTENT_REQUIRED' | 'INTERNAL' | 'NOT_FOUND' | 'AMBIGUOUS' | 'NOT_INDEXED' | 'OPTIONAL_DEP_MISSING' | 'TRUST_DENIED' | 'PATH_TRAVERSAL' | 'CATEGORY_REQUIRED' | 'IMPORTANCE_REQUIRED' | 'TIMERANGE_REQUIRED' | 'INGEST_FAILED' | 'UNSUPPORTED_FORMAT' | 'HAS_REFERENCES' | 'DRY_RUN_NO_DELETE' | 'MAX_DELETE_EXCEEDED' | 'JOB_NOT_FOUND' | 'JOB_TIMEOUT' | 'JOB_FAILED';
167
+ type KGScope = 'agent_only' | 'shared_only' | 'both';
168
+ interface RecallParams {
169
+ query: string;
170
+ category?: MemoryCategory;
171
+ minImportance?: number;
172
+ fromTime?: string;
173
+ toTime?: string;
174
+ maxResults?: number;
175
+ minScore?: number;
176
+ includeGraph?: boolean;
177
+ depth?: number;
178
+ includeShared?: boolean;
179
+ }
180
+ interface RecallResult {
181
+ hits: MemoryRecallResult[];
182
+ total: number;
183
+ truncated: boolean;
184
+ durationMs: number;
185
+ graph?: {
186
+ nodes: MemoryNode[];
187
+ edges: MemoryEdge[];
188
+ };
189
+ warnings?: string[];
190
+ }
191
+ interface RememberParams {
192
+ content: string;
193
+ category: MemoryCategory;
194
+ importance?: number;
195
+ tags?: string[];
196
+ sessionId?: string;
197
+ msgId?: string;
198
+ parentMsgId?: string;
199
+ skipDedup?: boolean;
200
+ extractGraph?: boolean;
201
+ }
202
+ interface RememberResult {
203
+ fact: MemoryFact;
204
+ filePath: string;
205
+ deduplicated: boolean;
206
+ nodeIds?: number[];
207
+ }
208
+ interface ForgetParams {
209
+ factId?: string;
210
+ category?: MemoryCategory;
211
+ fromTime?: string;
212
+ toTime?: string;
213
+ maxDelete?: number;
214
+ dryRun?: boolean;
215
+ force?: boolean;
216
+ }
217
+ interface ForgetResult {
218
+ deletedCount: number;
219
+ deletedIds: string[];
220
+ dryRun: boolean;
221
+ truncatedCount: number;
222
+ }
223
+ interface ExtractParams {
224
+ sessionId: string;
225
+ lastN?: number;
226
+ fromMessageId?: string;
227
+ writeToDisk?: boolean;
228
+ }
229
+ interface ExtractResult {
230
+ extractedCount: number;
231
+ factIds: string[];
232
+ entities: Array<{
233
+ id: number;
234
+ name: string;
235
+ type: string;
236
+ }>;
237
+ relations: Array<{
238
+ source: string;
239
+ target: string;
240
+ relation: string;
241
+ }>;
242
+ messageRange: {
243
+ fromMessageId: string;
244
+ toMessageId: string;
245
+ };
246
+ durationMs: number;
247
+ }
248
+ interface ConsolidateParams {
249
+ windowDays?: number;
250
+ dryRun?: boolean;
251
+ }
252
+ interface ConsolidateResult {
253
+ totalFacts: number;
254
+ dedupedCount: number;
255
+ compressedCount: number;
256
+ archivedCount: number;
257
+ skippedCount: number;
258
+ durationMs: number;
259
+ }
260
+ interface GraphQueryParams {
261
+ query: string;
262
+ type?: string;
263
+ depth?: number;
264
+ maxNodes?: number;
265
+ scope?: KGScope;
266
+ relation?: string;
267
+ }
268
+ interface GraphQueryResult {
269
+ root: MemoryNode | null;
270
+ nodes: MemoryNode[];
271
+ edges: MemoryEdge[];
272
+ truncated: boolean;
273
+ totalNodes: number;
274
+ totalEdges: number;
275
+ scope: KGScope;
276
+ durationMs: number;
277
+ }
278
+ type StatusParams = {};
279
+ interface StatusResult {
280
+ dbPath: string;
281
+ workspaceDir: string;
282
+ factsCount: number;
283
+ nodesCount: number;
284
+ edgesCount: number;
285
+ factsByCategory: Record<MemoryCategory, number>;
286
+ ftsAvailable: boolean;
287
+ vectorEnabled: boolean;
288
+ kgScopeEnabled: boolean;
289
+ healthy: boolean;
290
+ meta: Record<string, string>;
291
+ }
292
+ type DoctorParams = {};
293
+ interface DoctorResult {
294
+ healthy: boolean;
295
+ checks: Array<{
296
+ name: string;
297
+ passed: boolean;
298
+ message: string;
299
+ details?: Record<string, unknown>;
300
+ }>;
301
+ }
302
+ interface InitParams {
303
+ dbPath?: string;
304
+ workspaceDir?: string;
305
+ archiveDays?: number;
306
+ force?: boolean;
307
+ }
308
+ interface InitResult {
309
+ initialized: boolean;
310
+ dbPath: string;
311
+ workspaceDir: string;
312
+ tablesCreated: number;
313
+ migrationsApplied: number;
314
+ durationMs: number;
315
+ }
316
+
317
+ declare function recall(ctx: MemoryServiceContext, params: RecallParams): Promise<RecallResult>;
318
+
319
+ declare function remember(ctx: MemoryServiceContext, params: RememberParams): Promise<RememberResult>;
320
+
321
+ declare function forget(ctx: MemoryServiceContext, params: ForgetParams): Promise<ForgetResult>;
322
+
323
+ declare function extract(ctx: MemoryServiceContext, params: ExtractParams): Promise<ExtractResult>;
324
+
325
+ declare function consolidate(ctx: MemoryServiceContext, params?: ConsolidateParams): Promise<ConsolidateResult>;
326
+
327
+ declare function graphQuery(ctx: MemoryServiceContext, params: GraphQueryParams): Promise<GraphQueryResult>;
328
+
329
+ declare function status(ctx: MemoryServiceContext, _params?: StatusParams): Promise<StatusResult>;
330
+
331
+ declare function doctor(ctx: MemoryServiceContext, _params?: DoctorParams): Promise<DoctorResult>;
332
+
333
+ declare function init(ctx: MemoryServiceContext, params?: InitParams): Promise<InitResult>;
334
+
335
+ type OpScope = 'read' | 'write' | 'admin';
336
+ interface OpAnnotations {
337
+ localOnly?: boolean;
338
+ requiresAgentId?: boolean;
339
+ defaultDescription?: string;
340
+ readOnlyHint?: boolean;
341
+ destructiveHint?: boolean;
342
+ idempotentHint?: boolean;
343
+ }
344
+ interface OpHandlerContext {
345
+ agentId?: string;
346
+ isTrustedLocal?: boolean;
347
+ signal?: AbortSignal;
348
+ workspaceDir?: string;
349
+ rootDir?: string;
350
+ dbPath?: string;
351
+ locale?: 'zh-CN' | 'en-US';
352
+ remote?: boolean;
353
+ config?: unknown;
354
+ }
355
+ interface MemoryOp<TSchema extends ZodTypeAny | undefined = undefined, TResult = unknown> {
356
+ name: string;
357
+ scope: OpScope;
358
+ schema?: TSchema;
359
+ annotations: OpAnnotations;
360
+ handler: (args: unknown, ctx: OpHandlerContext) => Promise<TResult>;
361
+ }
362
+
363
+ declare const OP_REGISTRY: Record<string, MemoryOp<never, unknown>>;
364
+ declare const ALL_OPS: readonly MemoryOp<never, unknown>[];
365
+ declare function executeOp<TResult = unknown>(name: string, args: unknown, ctx: OpHandlerContext): Promise<TResult>;
366
+
367
+ interface PendingFile {
368
+ path: string;
369
+ lastEventAt: number;
370
+ }
371
+
372
+ interface RenderOptions {
373
+ pendingFiles?: PendingFile[];
374
+ toolName?: string;
375
+ softLimit?: number;
376
+ hardCeiling?: number;
377
+ sync?: boolean;
378
+ writeToDisk?: boolean;
379
+ }
380
+ type RenderRecallCtx = {
381
+ query: string;
382
+ agentId: string;
383
+ scope: 'agent_only' | 'shared_only' | 'both';
384
+ } & RenderOptions;
385
+
386
+ declare function renderOperationMarkdown(opName: string, payload: unknown, ctx?: RenderRecallCtx | RenderOptions): Promise<string>;
387
+
388
+ interface CommandHelp {
389
+ i18nKey: string;
390
+ name: string;
391
+ description: string;
392
+ group: 'lifecycle' | 'memory' | 'session' | 'graph' | 'external';
393
+ }
394
+ declare const COMMANDS_HELP: readonly CommandHelp[];
395
+ interface MemoryCliDeps {
396
+ version: string;
397
+ cwd?: string;
398
+ locale?: string;
399
+ }
400
+ interface MemoryCliResult {
401
+ code: number;
402
+ handled: boolean;
403
+ command: string | null;
404
+ }
405
+ declare function renderBanner(): void;
406
+ declare function renderHelp(): void;
407
+ declare function handleMemoryCli(args: string[], deps?: MemoryCliDeps): Promise<MemoryCliResult>;
408
+
409
+ interface MemoryMcpCtxConfig {
410
+ agentId: string;
411
+ dbPath: string;
412
+ workspaceDir: string;
413
+ isRemote?: boolean;
414
+ }
415
+ declare namespace MemoryStdioServer {
416
+ interface StartResult {
417
+ id: string;
418
+ name: string;
419
+ version: string;
420
+ tools: string[];
421
+ }
422
+ function start(config: StdioServerConfig, ctxConfigOrLegacy?: MemoryMcpCtxConfig): Promise<StartResult>;
423
+ function getToolNames(): string[];
424
+ }
425
+
426
+ declare function setGlobalAdapter(global: IGlobal | null): void;
427
+ declare function resetGlobalAdapter(): void;
428
+ declare function getGlobal(): IGlobal;
429
+ declare function setInstanceAdapter(instance: IInstance | null): void;
430
+ declare function resetInstanceAdapter(): void;
431
+ declare function getInstance(): IInstance;
432
+ declare function getHomeDir(): string;
433
+ declare function getXdgData(): string;
434
+ declare function getMemoryDir(): string;
435
+ declare function getMemoryDbPath(): string;
436
+
437
+ type MigrationDb = SyncSqliteConnection;
438
+ declare const LATEST_SCHEMA_VERSION = 2;
439
+ interface SchemaMigration {
440
+ id: number;
441
+ description: string;
442
+ up: readonly string[];
443
+ }
444
+ declare const MIGRATIONS: readonly SchemaMigration[];
445
+ interface MigrationReport {
446
+ applied: number[];
447
+ pending: number[];
448
+ errors: Array<{
449
+ migrationId: number;
450
+ sql: string;
451
+ error: string;
452
+ }>;
453
+ currentVersion: number;
454
+ targetVersion: number;
455
+ }
456
+ declare function runMigrations(db: MigrationDb, target?: number, opts?: {
457
+ dryRun?: boolean;
458
+ }): MigrationReport;
459
+ declare function readCurrentSchemaVersion(db: MigrationDb): number;
460
+
198
461
  declare class MemoryDatabaseManager {
199
462
  private db;
200
463
  private readonly storagePath;
464
+ private readonly backend;
201
465
  private initialized;
202
466
  private initPromise;
203
467
  constructor(storagePath: string);
204
468
  initialize(): Promise<void>;
205
469
  private doInitialize;
206
- private openDatabaseAsync;
207
- private createTables;
470
+ private openConnection;
471
+ private applyPragmas;
472
+ private runAllMigrations;
208
473
  query<T>(sql: string, params?: unknown[]): T[];
209
474
  run(sql: string, params?: unknown[]): {
210
475
  lastID: number;
211
476
  changes: number;
212
477
  };
213
478
  transaction<T>(fn: () => T): T;
214
- prepare(sql: string): Database.Statement;
479
+ prepare(sql: string): ReturnType<SyncSqliteConnection['prepare']>;
215
480
  exec(sql: string): void;
216
- getDb(): Database.Database;
481
+ getDb(): SyncSqliteConnection;
217
482
  getPath(): string;
483
+ getSchemaVersion(): number;
218
484
  close(): void;
219
485
  healthCheck(): boolean;
220
486
  getMeta(key: string): string | null;
221
487
  setMeta(key: string, value: string): void;
222
488
  }
223
489
 
224
- declare class MemoryFormatter {
225
- static generateId(): string;
226
- static serialize(fact: MemoryFact): string;
227
- static serializeFile(facts: MemoryFact[]): string;
228
- static parse(content: string): MemoryFact[];
229
- private static parseFrontmatter;
230
- private static validateFrontmatter;
231
- private static parseArrayField;
232
- }
233
-
234
- declare class MemoryFileManager {
235
- static getMemoryMdPath(workspaceDir: string): string;
236
- static getActiveFilePath(workspaceDir: string, category: MemoryCategory, date?: Date): string;
237
- static getArchiveFilePath(workspaceDir: string, category: MemoryCategory, createdAt: number, filename: string): string;
238
- static readMemoryMd(workspaceDir: string): Promise<string | null>;
239
- static write(workspaceDir: string, fact: MemoryFact): Promise<string>;
240
- static read(filePath: string): Promise<MemoryFact[]>;
241
- static delete(filePath: string, memoryId: string): Promise<void>;
242
- static update(filePath: string, memoryId: string, patch: {
243
- content?: string;
244
- importance?: number;
245
- tags?: string[];
246
- }): Promise<void>;
247
- static listActiveFiles(workspaceDir: string): Promise<string[]>;
248
- private static scanDir;
249
- }
250
-
251
- declare class MemoryArchiver {
252
- private db;
253
- private config;
254
- constructor(db: Database$1, config: MemorySystemConfig);
255
- archive(): Promise<ArchiveResult>;
256
- }
257
-
258
490
  declare class GraphStore {
259
491
  private db;
260
- constructor(db: Database$1);
261
- upsertNode(name: string, type: string, properties?: Record<string, unknown>): Promise<number>;
492
+ constructor(db: SyncSqliteConnection);
493
+ upsertNode(name: string, type: string, properties?: Record<string, unknown>, ownerAgentId?: string | null): Promise<number>;
262
494
  deleteNode(id: number): Promise<void>;
263
495
  upsertEdge(source: number, target: number, relation: string, properties?: Record<string, unknown>): Promise<number>;
264
496
  queryNodes(filter?: NodeQueryFilter): Promise<MemoryNode[]>;
265
497
  queryEdges(filter?: EdgeQueryFilter): Promise<MemoryEdge[]>;
266
498
  queryNeighbors(nodeId: number, depth?: number, options?: {
267
499
  maxEdgesPerNode?: number;
500
+ agentId?: string;
501
+ scope?: 'agent_only' | 'shared_only' | 'both';
268
502
  }): Promise<MemoryNodeWithEdges[]>;
269
503
  }
270
504
 
271
- declare class MemorySystem implements IMemorySystem {
272
- private readonly config;
273
- private readonly db;
274
- private archiver;
275
- private searchEngine;
276
- private graphStore;
277
- private embeddingModel;
278
- private vectorDims;
279
- constructor(config: MemorySystemConfig);
280
- initialize(): Promise<void>;
281
- remember(fact: Omit<MemoryFact, 'id' | 'createdAt' | 'updatedAt'>): Promise<MemoryFact>;
282
- query(query: string, options?: MemoryQuery): Promise<MemoryRecallResult[]>;
283
- queryEdgesByNodeId(nodeId: number, options?: {
284
- maxDepth?: number;
285
- maxEdgesPerNode?: number;
286
- }): Promise<{
287
- node?: {
288
- id: number;
289
- name: string;
290
- type: string;
291
- };
292
- nodes: MemoryNode[];
293
- edges: MemoryEdge[];
294
- }>;
295
- forget(agentId: string, memoryId: string): Promise<void>;
296
- update(agentId: string, memoryId: string, patch: {
297
- content?: string;
298
- importance?: number;
299
- tags?: string[];
300
- }): Promise<MemoryFact>;
301
- listAgentIds(): Promise<string[]>;
302
- queryForSummary(agentId: string, options?: {
303
- limit?: number;
304
- category?: string;
305
- fromTime?: string;
306
- toTime?: string;
307
- }): Promise<MemoryFact[]>;
308
- archive(): Promise<void>;
309
- cleanupOrphanRecords(): Promise<void>;
310
- clear(): Promise<void>;
311
- close(): Promise<void>;
312
- getStatus(): Promise<{
313
- dbPath: string;
314
- workspaceDir: string;
315
- factsCount: number;
316
- nodesCount: number;
317
- edgesCount: number;
318
- embeddingLlmAvailable: boolean;
319
- graphLlmAvailable: boolean;
320
- healthy: boolean;
321
- meta: Record<string, string>;
322
- }>;
323
- sync(): Promise<{
324
- synced: number;
325
- created: number;
326
- updated: number;
327
- errors: string[];
328
- }>;
329
- private hasMemoryFiles;
330
- private clearFiles;
331
- private rowToFact;
332
- private extractEntities;
333
- private extractEntitiesWithLlm;
334
- private buildEntityExtractionPrompt;
335
- private storeEntitiesAndRelations;
336
- private mergeEntitiesAndRelations;
337
- private embed;
338
- private embedAndStore;
339
- private writeVector;
340
- private writeFts;
341
- private parseEntityExtractionResult;
342
- private normalizeExtractionResult;
343
- private sanitizeEntityToken;
344
- private inferEntityType;
345
- private getSearchEngine;
346
- private getGraphStore;
347
- private getArchiver;
348
- }
349
- declare function createMemorySystem(config: MemorySystemConfig): Promise<IMemorySystem>;
505
+ type HookName = 'session-start' | 'session-end' | 'pre-compact' | 'post-tool-failure';
506
+ interface HookContext {
507
+ agentId?: string;
508
+ sessionId?: string;
509
+ toolName?: string;
510
+ error?: string;
511
+ messagePreview?: string;
512
+ contextPreview?: string;
513
+ extras?: Record<string, unknown>;
514
+ }
515
+ interface HookResult {
516
+ ok: boolean;
517
+ injected?: string;
518
+ logLine?: string;
519
+ error?: string;
520
+ }
521
+ type HookHandler = (ctx: HookContext) => Promise<HookResult>;
522
+ interface RegisteredHook {
523
+ name: HookName;
524
+ handler: HookHandler;
525
+ registeredAt: string;
526
+ }
527
+
528
+ declare function registerHook(name: HookName, handler: HookHandler): void;
529
+ declare function unregisterHook(name: HookName): boolean;
530
+ declare function listHooks(): readonly RegisteredHook[];
531
+ declare function registerAllDefaultHooks(): void;
532
+ declare function clearAllHooks(): void;
533
+ declare function dispatchHook(name: HookName, ctx: HookContext): Promise<HookResult>;
350
534
 
351
- export { type ArchiveRecord, type ArchiveResult, type EdgeQueryFilter, GraphStore, type IMemorySystem, MEMORY_CATEGORIES, MemoryArchiver, type MemoryCategory, MemoryDatabaseError, MemoryDatabaseManager, type MemoryEdge, MemoryEmbeddingError, MemoryError, MemoryErrorCode, type MemoryFact, MemoryFileError, MemoryFileManager, MemoryFormatter, type MemoryNode, type MemoryNodeWithEdges, MemoryNotFoundError, MemoryPermissionError, type MemoryQuery, type MemoryRecallResult, MemorySearchError, type MemorySource, MemorySystem, type MemorySystemConfig, MemoryValidationError, type MemoryVector, type NodeQueryFilter, addWord, closeTokenizer, createMemorySystem, initTokenizer, isInitialized, loadCustomDict, toFtsTokens, toFtsTokensForSearch, tokenize, tokenizeForSearch };
535
+ export { ALL_OPS, type ArchiveRecord, type ArchiveResult, COMMANDS_HELP, type CommandHelp, type ConsolidateParams, type ConsolidateResult, type DoctorResult, type EdgeQueryFilter, type ErrorCode, type ExtractParams, type ExtractResult, type ForgetParams, type ForgetResult, type GraphQueryParams, type GraphQueryResult, GraphStore, type HookContext, type HookHandler, type HookName, type HookResult, type InitParams, type InitResult, type KGScope, LATEST_SCHEMA_VERSION, MEMORY_CATEGORIES, MIGRATIONS, type MemoryCategory, type MemoryCliDeps, type MemoryCliResult, MemoryDatabaseError, MemoryDatabaseManager, type MemoryEdge, MemoryEmbeddingError, MemoryError, MemoryErrorCode, type MemoryFact, MemoryFileError, type MemoryNode, type MemoryNodeWithEdges, MemoryNotFoundError, type MemoryOp, MemoryPermissionError, type MemoryQuery, type MemoryRecallResult, MemorySearchError, type MemorySource, MemoryStdioServer, type MemorySystemConfig, MemoryValidationError, type MemoryVector, type NodeQueryFilter, OP_REGISTRY, type OpAnnotations, type OpHandlerContext, type OpScope, type RecallParams, type RecallResult, type RegisteredHook, type RememberParams, type RememberResult, type StatusResult, addWord, clearAllHooks, closeTokenizer, consolidate, dispatchHook, doctor, executeOp, extract, forget, getGlobal, getHomeDir, getInstance, getMemoryDbPath, getMemoryDir, getXdgData, graphQuery, handleMemoryCli, init, initTokenizer, isInitialized, listHooks, loadCustomDict, readCurrentSchemaVersion, recall, registerAllDefaultHooks, registerHook, remember, renderBanner, renderHelp, renderOperationMarkdown, resetGlobalAdapter, resetInstanceAdapter, runMigrations, setGlobalAdapter, setInstanceAdapter, status, toFtsTokens, toFtsTokensForSearch, tokenize, tokenizeForSearch, unregisterHook };