@easbot/memory 0.3.14 → 0.3.17

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 +296 -38
  2. package/README.md +292 -37
  3. package/dist/chunks/chunk-BSKFK4RC.mjs +1 -0
  4. package/dist/chunks/chunk-CPRDIUQ4.cjs +1 -0
  5. package/dist/chunks/chunk-DFWC6WII.mjs +53 -0
  6. package/dist/chunks/chunk-DXU5WPK3.cjs +42 -0
  7. package/dist/chunks/chunk-EECBJNZI.mjs +59 -0
  8. package/dist/chunks/chunk-FMEXQ5YE.cjs +59 -0
  9. package/dist/chunks/chunk-HQBRVVXS.mjs +1 -0
  10. package/dist/chunks/chunk-HSK27DQ7.cjs +1 -0
  11. package/dist/chunks/chunk-I6XVFDN2.mjs +42 -0
  12. package/dist/chunks/chunk-MWRDF6VN.mjs +1 -0
  13. package/dist/chunks/chunk-NVGACA7W.cjs +1 -0
  14. package/dist/chunks/chunk-OIUUTVLL.cjs +53 -0
  15. package/dist/chunks/chunk-QF5S5MG7.mjs +0 -0
  16. package/dist/chunks/chunk-QNDG7BTB.cjs +1 -0
  17. package/dist/chunks/chunk-RSJ2KT6X.cjs +1 -0
  18. package/dist/chunks/chunk-TPSRK4M3.mjs +1 -0
  19. package/dist/chunks/chunk-URADAZYW.cjs +1 -0
  20. package/dist/chunks/chunk-WDVDYZ25.mjs +1 -0
  21. package/dist/chunks/cli-handler-6VTKYXXM.mjs +1 -0
  22. package/dist/chunks/cli-handler-HNPA3STD.cjs +1 -0
  23. package/dist/chunks/config-2SQJYVTO.mjs +1 -0
  24. package/dist/chunks/config-RPPQ73HK.cjs +1 -0
  25. package/dist/chunks/consolidate-6P7LUPPL.cjs +2 -0
  26. package/dist/chunks/consolidate-NYH4IKJK.mjs +2 -0
  27. package/dist/chunks/doctor-IJJ5UYGT.cjs +2 -0
  28. package/dist/chunks/doctor-MZSZGVRL.mjs +2 -0
  29. package/dist/chunks/extract-6B7OD3VK.mjs +2 -0
  30. package/dist/chunks/extract-ERTOHQV6.cjs +2 -0
  31. package/dist/chunks/forget-A4UJI3LE.mjs +3 -0
  32. package/dist/chunks/forget-KLFM5SBQ.cjs +3 -0
  33. package/dist/chunks/graph-P5ZHB4ZM.cjs +3 -0
  34. package/dist/chunks/graph-XZ46LEO7.mjs +3 -0
  35. package/dist/chunks/init-CCOSHE3F.cjs +3 -0
  36. package/dist/chunks/init-WEPU32KF.mjs +3 -0
  37. package/dist/chunks/interfaces-LPJU4KS3.mjs +1 -0
  38. package/dist/chunks/interfaces-XWE45ENK.cjs +1 -0
  39. package/dist/chunks/mcp-BOD4ZOZS.mjs +1 -0
  40. package/dist/chunks/mcp-BXVXTUJK.cjs +1 -0
  41. package/dist/chunks/recall-BV4Z7HUJ.mjs +2 -0
  42. package/dist/chunks/recall-FEINUJKO.cjs +2 -0
  43. package/dist/chunks/remember-ESVRA73C.mjs +2 -0
  44. package/dist/chunks/remember-YNSY2JJB.cjs +2 -0
  45. package/dist/chunks/status-KVM7I6YC.cjs +2 -0
  46. package/dist/chunks/status-QQZS3ZCN.mjs +2 -0
  47. package/dist/chunks/stdio-server-MQKTUGNG.cjs +1 -0
  48. package/dist/chunks/stdio-server-ZLMSUTC5.mjs +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 +403 -170
  55. package/dist/index.d.ts +403 -170
  56. package/dist/index.mjs +6 -146
  57. package/package.json +21 -14
package/dist/index.d.ts CHANGED
@@ -1,7 +1,11 @@
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 { EmbeddingModel, LanguageModel } from 'ai';
4
4
  export { EmbeddingModel, LanguageModel } from 'ai';
5
+ import { BuildPromptOptions } from '@easbot/utils';
6
+ import { ZodTypeAny } from 'zod';
7
+ import { StdioServerConfig } from '@easbot/mcp';
8
+ import { SyncSqliteConnection } from '@easbot/database';
5
9
 
6
10
  type MemoryCategory = 'user_preference' | 'task_context' | 'technical_fact' | 'decision' | 'relationship' | 'reminder' | 'error_pattern' | 'workflow' | 'exploration_finding' | 'experience_summary' | 'tool_usage' | 'skill_creation' | 'test' | 'other';
7
11
  declare const MEMORY_CATEGORIES: MemoryCategory[];
@@ -56,54 +60,6 @@ interface MemoryRecallResult {
56
60
  }>;
57
61
  }
58
62
  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
63
  declare class MemoryError extends Error {
108
64
  readonly code: string;
109
65
  cause?: Error | undefined;
@@ -146,6 +102,7 @@ interface MemoryNode {
146
102
  properties?: Record<string, unknown>;
147
103
  createdAt: string;
148
104
  updatedAt: string;
105
+ ownerAgentId?: string | null;
149
106
  }
150
107
  interface MemoryEdge {
151
108
  id: number;
@@ -164,6 +121,8 @@ interface NodeQueryFilter {
164
121
  name?: string;
165
122
  type?: string;
166
123
  limit?: number;
124
+ scope?: 'agent_only' | 'shared_only' | 'both';
125
+ agentId?: string;
167
126
  }
168
127
  interface EdgeQueryFilter {
169
128
  ids?: number[];
@@ -195,157 +154,431 @@ declare function closeTokenizer(): Promise<void>;
195
154
  declare function toFtsTokens(text: string): string;
196
155
  declare function toFtsTokensForSearch(text: string): string;
197
156
 
157
+ interface LlmModels {
158
+ embeddingLlm?: EmbeddingModel;
159
+ graphLlm?: LanguageModel;
160
+ }
161
+ interface LlmOptions {
162
+ maxOutputTokens?: number;
163
+ temperature?: number;
164
+ }
165
+ interface LlmInitConfig {
166
+ models: LlmModels;
167
+ options?: {
168
+ graph?: LlmOptions;
169
+ embedding?: LlmOptions;
170
+ };
171
+ }
172
+ declare namespace Llm {
173
+ function init(config: LlmInitConfig): void;
174
+ function isInitialized(): boolean;
175
+ function reset(): void;
176
+ function capabilities(): {
177
+ embedding: boolean;
178
+ graph: boolean;
179
+ };
180
+ function embedText(value: string): Promise<Float32Array>;
181
+ function embedTexts(values: string[]): Promise<Float32Array[]>;
182
+ function generateGraph(chunks: string[], entityTypes: ReadonlyArray<{
183
+ type: string;
184
+ rule: string;
185
+ }>, relationTypes: ReadonlyArray<{
186
+ type: string;
187
+ rule: string;
188
+ }>, options?: BuildPromptOptions & LlmOptions): Promise<string>;
189
+ function generate(prompt: string, options?: LlmOptions): Promise<string>;
190
+ const embed: typeof embedText;
191
+ const embedMany: typeof embedTexts;
192
+ }
193
+
194
+ interface MemoryServiceContext {
195
+ workspaceDir: string;
196
+ rootDir: string;
197
+ dbPath: string;
198
+ locale: 'zh-CN' | 'en-US';
199
+ remote: boolean;
200
+ config?: MemoryKnowledgeConfigWithModels;
201
+ agentId?: string;
202
+ }
203
+ 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';
204
+ type KGScope = 'agent_only' | 'shared_only' | 'both';
205
+ interface RecallParams {
206
+ query: string;
207
+ category?: MemoryCategory;
208
+ minImportance?: number;
209
+ fromTime?: string;
210
+ toTime?: string;
211
+ maxResults?: number;
212
+ minScore?: number;
213
+ includeGraph?: boolean;
214
+ depth?: number;
215
+ includeShared?: boolean;
216
+ }
217
+ interface RecallResult {
218
+ hits: MemoryRecallResult[];
219
+ total: number;
220
+ truncated: boolean;
221
+ durationMs: number;
222
+ graph?: {
223
+ nodes: MemoryNode[];
224
+ edges: MemoryEdge[];
225
+ };
226
+ warnings?: string[];
227
+ }
228
+ interface RememberParams {
229
+ content: string;
230
+ category: MemoryCategory;
231
+ importance?: number;
232
+ tags?: string[];
233
+ sessionId?: string;
234
+ msgId?: string;
235
+ parentMsgId?: string;
236
+ skipDedup?: boolean;
237
+ extractGraph?: boolean;
238
+ }
239
+ interface RememberResult {
240
+ fact: MemoryFact;
241
+ filePath: string;
242
+ deduplicated: boolean;
243
+ nodeIds?: number[];
244
+ vectorsWritten: number;
245
+ vectorDims: number;
246
+ }
247
+ interface ForgetParams {
248
+ factId?: string;
249
+ category?: MemoryCategory;
250
+ fromTime?: string;
251
+ toTime?: string;
252
+ maxDelete?: number;
253
+ dryRun?: boolean;
254
+ force?: boolean;
255
+ }
256
+ interface ForgetResult {
257
+ deletedCount: number;
258
+ deletedIds: string[];
259
+ dryRun: boolean;
260
+ truncatedCount: number;
261
+ }
262
+ interface ExtractParams {
263
+ sessionId: string;
264
+ lastN?: number;
265
+ fromMessageId?: string;
266
+ writeToDisk?: boolean;
267
+ }
268
+ interface ExtractResult {
269
+ extractedCount: number;
270
+ factIds: string[];
271
+ entities: Array<{
272
+ id: number;
273
+ name: string;
274
+ type: string;
275
+ }>;
276
+ relations: Array<{
277
+ source: string;
278
+ target: string;
279
+ relation: string;
280
+ }>;
281
+ messageRange: {
282
+ fromMessageId: string;
283
+ toMessageId: string;
284
+ };
285
+ durationMs: number;
286
+ }
287
+ interface ConsolidateParams {
288
+ windowDays?: number;
289
+ dryRun?: boolean;
290
+ }
291
+ interface ConsolidateResult {
292
+ totalFacts: number;
293
+ dedupedCount: number;
294
+ compressedCount: number;
295
+ archivedCount: number;
296
+ skippedCount: number;
297
+ durationMs: number;
298
+ }
299
+ interface GraphQueryParams {
300
+ query: string;
301
+ type?: string;
302
+ depth?: number;
303
+ maxNodes?: number;
304
+ scope?: KGScope;
305
+ relation?: string;
306
+ }
307
+ interface GraphQueryResult {
308
+ root: MemoryNode | null;
309
+ nodes: MemoryNode[];
310
+ edges: MemoryEdge[];
311
+ truncated: boolean;
312
+ totalNodes: number;
313
+ totalEdges: number;
314
+ scope: KGScope;
315
+ durationMs: number;
316
+ }
317
+ type StatusParams = {};
318
+ interface StatusResult {
319
+ dbPath: string;
320
+ workspaceDir: string;
321
+ factsCount: number;
322
+ nodesCount: number;
323
+ edgesCount: number;
324
+ factsByCategory: Record<MemoryCategory, number>;
325
+ ftsAvailable: boolean;
326
+ vectorEnabled: boolean;
327
+ kgScopeEnabled: boolean;
328
+ healthy: boolean;
329
+ meta: Record<string, string>;
330
+ }
331
+ type DoctorParams = {};
332
+ interface DoctorResult {
333
+ healthy: boolean;
334
+ checks: Array<{
335
+ name: string;
336
+ passed: boolean;
337
+ message: string;
338
+ details?: Record<string, unknown>;
339
+ severity?: 'error' | 'info';
340
+ }>;
341
+ }
342
+ interface InitParams {
343
+ dbPath?: string;
344
+ workspaceDir?: string;
345
+ archiveDays?: number;
346
+ force?: boolean;
347
+ }
348
+ interface InitResult {
349
+ initialized: boolean;
350
+ dbPath: string;
351
+ configPath: string;
352
+ workspaceDir: string;
353
+ tablesCreated: number;
354
+ migrationsApplied: number;
355
+ durationMs: number;
356
+ configCreated: boolean;
357
+ }
358
+
359
+ declare function recall(ctx: MemoryServiceContext, params: RecallParams): Promise<RecallResult>;
360
+
361
+ declare function remember(ctx: MemoryServiceContext, params: RememberParams): Promise<RememberResult>;
362
+
363
+ declare function forget(ctx: MemoryServiceContext, params: ForgetParams): Promise<ForgetResult>;
364
+
365
+ declare function extract(ctx: MemoryServiceContext, params: ExtractParams): Promise<ExtractResult>;
366
+
367
+ declare function consolidate(ctx: MemoryServiceContext, params?: ConsolidateParams): Promise<ConsolidateResult>;
368
+
369
+ declare function graphQuery(ctx: MemoryServiceContext, params: GraphQueryParams): Promise<GraphQueryResult>;
370
+
371
+ declare function status(ctx: MemoryServiceContext, _params?: StatusParams): Promise<StatusResult>;
372
+
373
+ declare function doctor(ctx: MemoryServiceContext, _params?: DoctorParams): Promise<DoctorResult>;
374
+
375
+ declare function init(ctx: MemoryServiceContext, params?: InitParams): Promise<InitResult>;
376
+
377
+ type OpScope = 'read' | 'write' | 'admin';
378
+ interface OpAnnotations {
379
+ localOnly?: boolean;
380
+ requiresAgentId?: boolean;
381
+ defaultDescription?: string;
382
+ readOnlyHint?: boolean;
383
+ destructiveHint?: boolean;
384
+ idempotentHint?: boolean;
385
+ }
386
+ interface OpHandlerContext {
387
+ agentId?: string;
388
+ isTrustedLocal?: boolean;
389
+ signal?: AbortSignal;
390
+ workspaceDir?: string;
391
+ rootDir?: string;
392
+ dbPath?: string;
393
+ locale?: 'zh-CN' | 'en-US';
394
+ remote?: boolean;
395
+ config?: unknown;
396
+ }
397
+ interface MemoryOp<TSchema extends ZodTypeAny | undefined = undefined, TResult = unknown> {
398
+ name: string;
399
+ scope: OpScope;
400
+ schema?: TSchema;
401
+ annotations: OpAnnotations;
402
+ handler: (args: unknown, ctx: OpHandlerContext) => Promise<TResult>;
403
+ }
404
+
405
+ declare const OP_REGISTRY: Record<string, MemoryOp<never, unknown>>;
406
+ declare const ALL_OPS: readonly MemoryOp<never, unknown>[];
407
+ declare function executeOp<TResult = unknown>(name: string, args: unknown, ctx: OpHandlerContext): Promise<TResult>;
408
+
409
+ interface PendingFile {
410
+ path: string;
411
+ lastEventAt: number;
412
+ }
413
+
414
+ interface RenderOptions {
415
+ pendingFiles?: PendingFile[];
416
+ toolName?: string;
417
+ softLimit?: number;
418
+ hardCeiling?: number;
419
+ sync?: boolean;
420
+ writeToDisk?: boolean;
421
+ }
422
+ type RenderRecallCtx = {
423
+ query: string;
424
+ agentId: string;
425
+ scope: 'agent_only' | 'shared_only' | 'both';
426
+ } & RenderOptions;
427
+
428
+ declare function renderOperationMarkdown(opName: string, payload: unknown, ctx?: RenderRecallCtx | RenderOptions): Promise<string>;
429
+
430
+ interface CommandHelp {
431
+ i18nKey: string;
432
+ name: string;
433
+ description: string;
434
+ group: 'lifecycle' | 'memory' | 'session' | 'graph' | 'external';
435
+ }
436
+ declare const COMMANDS_HELP: readonly CommandHelp[];
437
+ interface MemoryCliDeps {
438
+ version: string;
439
+ cwd?: string;
440
+ locale?: string;
441
+ }
442
+ interface MemoryCliResult {
443
+ code: number;
444
+ handled: boolean;
445
+ command: string | null;
446
+ }
447
+ declare function renderBanner(): void;
448
+ declare function renderHelp(): void;
449
+ declare function handleMemoryCli(args: string[], deps?: MemoryCliDeps): Promise<MemoryCliResult>;
450
+
451
+ interface MemoryMcpCtxConfig {
452
+ agentId: string;
453
+ dbPath: string;
454
+ workspaceDir: string;
455
+ isRemote?: boolean;
456
+ }
457
+ declare namespace MemoryStdioServer {
458
+ interface StartResult {
459
+ id: string;
460
+ name: string;
461
+ version: string;
462
+ tools: string[];
463
+ }
464
+ function start(config: StdioServerConfig, ctxConfigOrLegacy?: MemoryMcpCtxConfig): Promise<StartResult>;
465
+ function getToolNames(): string[];
466
+ }
467
+
468
+ declare function setGlobalAdapter(global: IGlobal | null): void;
469
+ declare function resetGlobalAdapter(): void;
470
+ declare function getGlobal(): IGlobal;
471
+ declare function setInstanceAdapter(instance: IInstance | null): void;
472
+ declare function resetInstanceAdapter(): void;
473
+ declare function getInstance(): IInstance;
474
+ declare function getHomeDir(): string;
475
+ declare function getXdgData(): string;
476
+ declare function getMemoryDir(): string;
477
+ declare function getMemoryDbPath(input?: string | {
478
+ dir?: string;
479
+ workspaceDir?: string;
480
+ }): string;
481
+
482
+ type MigrationDb = SyncSqliteConnection;
483
+ declare const LATEST_SCHEMA_VERSION = 2;
484
+ interface SchemaMigration {
485
+ id: number;
486
+ description: string;
487
+ up: readonly string[];
488
+ }
489
+ declare const MIGRATIONS: readonly SchemaMigration[];
490
+ interface MigrationReport {
491
+ applied: number[];
492
+ pending: number[];
493
+ errors: Array<{
494
+ migrationId: number;
495
+ sql: string;
496
+ error: string;
497
+ }>;
498
+ currentVersion: number;
499
+ targetVersion: number;
500
+ }
501
+ declare function runMigrations(db: MigrationDb, target?: number, opts?: {
502
+ dryRun?: boolean;
503
+ }): MigrationReport;
504
+ declare function readCurrentSchemaVersion(db: MigrationDb): number;
505
+
198
506
  declare class MemoryDatabaseManager {
199
507
  private db;
200
508
  private readonly storagePath;
509
+ private readonly backend;
201
510
  private initialized;
202
511
  private initPromise;
203
512
  constructor(storagePath: string);
204
513
  initialize(): Promise<void>;
205
514
  private doInitialize;
206
- private openDatabaseAsync;
207
- private createTables;
515
+ private openConnection;
516
+ private applyPragmas;
517
+ private runAllMigrations;
208
518
  query<T>(sql: string, params?: unknown[]): T[];
519
+ agentFilter(agentId: string | null | undefined): {
520
+ where: string;
521
+ params: string[];
522
+ };
209
523
  run(sql: string, params?: unknown[]): {
210
524
  lastID: number;
211
525
  changes: number;
212
526
  };
213
527
  transaction<T>(fn: () => T): T;
214
- prepare(sql: string): Database.Statement;
528
+ prepare(sql: string): ReturnType<SyncSqliteConnection['prepare']>;
215
529
  exec(sql: string): void;
216
- getDb(): Database.Database;
530
+ getDb(): SyncSqliteConnection;
217
531
  getPath(): string;
532
+ getSchemaVersion(): number;
218
533
  close(): void;
219
534
  healthCheck(): boolean;
220
535
  getMeta(key: string): string | null;
221
536
  setMeta(key: string, value: string): void;
222
537
  }
223
538
 
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
539
  declare class GraphStore {
259
540
  private db;
260
- constructor(db: Database$1);
261
- upsertNode(name: string, type: string, properties?: Record<string, unknown>): Promise<number>;
541
+ constructor(db: SyncSqliteConnection);
542
+ upsertNode(name: string, type: string, properties?: Record<string, unknown>, ownerAgentId?: string | null): Promise<number>;
262
543
  deleteNode(id: number): Promise<void>;
263
544
  upsertEdge(source: number, target: number, relation: string, properties?: Record<string, unknown>): Promise<number>;
264
545
  queryNodes(filter?: NodeQueryFilter): Promise<MemoryNode[]>;
265
546
  queryEdges(filter?: EdgeQueryFilter): Promise<MemoryEdge[]>;
266
547
  queryNeighbors(nodeId: number, depth?: number, options?: {
267
548
  maxEdgesPerNode?: number;
549
+ agentId?: string;
550
+ scope?: 'agent_only' | 'shared_only' | 'both';
268
551
  }): Promise<MemoryNodeWithEdges[]>;
269
552
  }
270
553
 
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>;
554
+ type HookName = 'session-start' | 'session-end' | 'pre-compact' | 'post-tool-failure';
555
+ interface HookContext {
556
+ agentId?: string;
557
+ sessionId?: string;
558
+ toolName?: string;
559
+ error?: string;
560
+ messagePreview?: string;
561
+ contextPreview?: string;
562
+ extras?: Record<string, unknown>;
563
+ }
564
+ interface HookResult {
565
+ ok: boolean;
566
+ injected?: string;
567
+ logLine?: string;
568
+ error?: string;
569
+ }
570
+ type HookHandler = (ctx: HookContext) => Promise<HookResult>;
571
+ interface RegisteredHook {
572
+ name: HookName;
573
+ handler: HookHandler;
574
+ registeredAt: string;
575
+ }
576
+
577
+ declare function registerHook(name: HookName, handler: HookHandler): void;
578
+ declare function unregisterHook(name: HookName): boolean;
579
+ declare function listHooks(): readonly RegisteredHook[];
580
+ declare function registerAllDefaultHooks(): void;
581
+ declare function clearAllHooks(): void;
582
+ declare function dispatchHook(name: HookName, ctx: HookContext): Promise<HookResult>;
350
583
 
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 };
584
+ 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, Llm, type LlmInitConfig, type LlmModels, type LlmOptions, 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 };