@smyslenny/agent-memory 3.1.0 → 4.1.0-alpha.1

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/dist/index.d.ts CHANGED
@@ -1,5 +1,25 @@
1
- export { D as DbOptions, i as isCountRow, o as openDatabase } from './db-DsY3zz8f.js';
2
1
  import Database from 'better-sqlite3';
2
+ import http from 'node:http';
3
+ export { D as DbOptions, i as isCountRow, o as openDatabase } from './db-DsY3zz8f.js';
4
+
5
+ interface EmbeddingProvider {
6
+ id: string;
7
+ model: string;
8
+ dimension: number;
9
+ embed(texts: string[]): Promise<number[][]>;
10
+ healthcheck?(): Promise<void>;
11
+ }
12
+ interface EmbeddingProviderOptions {
13
+ baseUrl: string;
14
+ model: string;
15
+ dimension: number;
16
+ apiKey?: string;
17
+ endpoint?: string;
18
+ headers?: Record<string, string>;
19
+ fetchImpl?: typeof fetch;
20
+ }
21
+ declare function createOpenAICompatibleEmbeddingProvider(opts: EmbeddingProviderOptions): EmbeddingProvider;
22
+ declare function createLocalHttpEmbeddingProvider(opts: EmbeddingProviderOptions): EmbeddingProvider;
3
23
 
4
24
  type MemoryType = "identity" | "emotion" | "knowledge" | "event";
5
25
  type Priority = 0 | 1 | 2 | 3;
@@ -18,6 +38,7 @@ interface Memory {
18
38
  source: string | null;
19
39
  agent_id: string;
20
40
  hash: string | null;
41
+ emotion_tag: string | null;
21
42
  }
22
43
  interface CreateMemoryInput {
23
44
  content: string;
@@ -26,6 +47,8 @@ interface CreateMemoryInput {
26
47
  emotion_val?: number;
27
48
  source?: string;
28
49
  agent_id?: string;
50
+ embedding_provider_id?: string | null;
51
+ emotion_tag?: string;
29
52
  }
30
53
  interface UpdateMemoryInput {
31
54
  content?: string;
@@ -35,6 +58,8 @@ interface UpdateMemoryInput {
35
58
  vitality?: number;
36
59
  stability?: number;
37
60
  source?: string;
61
+ embedding_provider_id?: string | null;
62
+ emotion_tag?: string | null;
38
63
  }
39
64
  declare function contentHash(content: string): string;
40
65
  declare function createMemory(db: Database.Database, input: CreateMemoryInput): Memory | null;
@@ -48,6 +73,7 @@ declare function listMemories(db: Database.Database, opts?: {
48
73
  min_vitality?: number;
49
74
  limit?: number;
50
75
  offset?: number;
76
+ emotion_tag?: string;
51
77
  }): Memory[];
52
78
  declare function recordAccess(db: Database.Database, id: string, growthFactor?: number): void;
53
79
  declare function countMemories(db: Database.Database, agent_id?: string): {
@@ -56,6 +82,400 @@ declare function countMemories(db: Database.Database, agent_id?: string): {
56
82
  by_priority: Record<string, number>;
57
83
  };
58
84
 
85
+ interface SyncInput {
86
+ content: string;
87
+ type?: CreateMemoryInput["type"];
88
+ priority?: CreateMemoryInput["priority"];
89
+ emotion_val?: number;
90
+ uri?: string;
91
+ source?: string;
92
+ agent_id?: string;
93
+ provider?: EmbeddingProvider | null;
94
+ conservative?: boolean;
95
+ emotion_tag?: string;
96
+ }
97
+ interface SyncResult {
98
+ action: "added" | "updated" | "merged" | "skipped";
99
+ memoryId?: string;
100
+ reason: string;
101
+ }
102
+ /**
103
+ * Sync a single piece of information into memory.
104
+ * Runs full Write Guard pipeline before writing.
105
+ */
106
+ declare function syncOne(db: Database.Database, input: SyncInput): Promise<SyncResult>;
107
+ /**
108
+ * Sync multiple items in a batch.
109
+ * Semantic guard may require async provider calls, so batch writes are serialized.
110
+ */
111
+ declare function syncBatch(db: Database.Database, inputs: SyncInput[]): Promise<SyncResult[]>;
112
+
113
+ interface RememberInput {
114
+ content: string;
115
+ type?: MemoryType;
116
+ priority?: Priority;
117
+ emotion_val?: number;
118
+ uri?: string;
119
+ source?: string;
120
+ agent_id?: string;
121
+ provider?: EmbeddingProvider | null;
122
+ conservative?: boolean;
123
+ emotion_tag?: string;
124
+ }
125
+ declare function rememberMemory(db: Database.Database, input: RememberInput): Promise<SyncResult>;
126
+
127
+ interface SearchResult {
128
+ memory: Memory;
129
+ score: number;
130
+ rank: number;
131
+ matchReason: string;
132
+ }
133
+ /**
134
+ * BM25 search using SQLite FTS5.
135
+ * Returns memories ranked by relevance.
136
+ */
137
+ declare function searchBM25(db: Database.Database, query: string, opts?: {
138
+ agent_id?: string;
139
+ limit?: number;
140
+ min_vitality?: number;
141
+ }): SearchResult[];
142
+ /**
143
+ * Build FTS5 query from natural language.
144
+ * Uses jieba for Chinese word segmentation, falls back to bigram splitting.
145
+ */
146
+ declare function buildFtsQuery(text: string): string | null;
147
+ declare function rebuildBm25Index(db: Database.Database, opts?: {
148
+ agent_id?: string;
149
+ }): {
150
+ reindexed: number;
151
+ };
152
+
153
+ type EmbeddingStatus = "pending" | "ready" | "failed";
154
+ interface StoredEmbedding {
155
+ id: string;
156
+ memory_id: string;
157
+ provider_id: string;
158
+ vector: Buffer | null;
159
+ content_hash: string;
160
+ status: EmbeddingStatus;
161
+ created_at: string;
162
+ }
163
+ interface VectorSearchResult {
164
+ memory: Memory;
165
+ similarity: number;
166
+ rank: number;
167
+ provider_id: string;
168
+ }
169
+ interface PendingEmbeddingRecord {
170
+ embeddingId: string;
171
+ memoryId: string;
172
+ content: string;
173
+ contentHash: string;
174
+ providerId: string;
175
+ status: EmbeddingStatus;
176
+ }
177
+ declare function encodeVector(vector: ArrayLike<number>): Buffer;
178
+ declare function decodeVector(blob: Uint8Array | ArrayBuffer): number[];
179
+ declare function cosineSimilarity(a: ArrayLike<number>, b: ArrayLike<number>): number;
180
+ declare function getEmbedding(db: Database.Database, memoryId: string, providerId: string): StoredEmbedding | null;
181
+ declare function markMemoryEmbeddingPending(db: Database.Database, memoryId: string, providerId: string, contentHash: string): void;
182
+ declare function markAllEmbeddingsPending(db: Database.Database, memoryId: string, contentHash: string): number;
183
+ declare function upsertReadyEmbedding(input: {
184
+ db: Database.Database;
185
+ memoryId: string;
186
+ providerId: string;
187
+ vector: ArrayLike<number>;
188
+ contentHash: string;
189
+ }): void;
190
+ declare function markEmbeddingFailed(db: Database.Database, memoryId: string, providerId: string, contentHash: string): void;
191
+ declare function listPendingEmbeddings(db: Database.Database, opts: {
192
+ providerId: string;
193
+ agent_id?: string;
194
+ limit?: number;
195
+ includeFailed?: boolean;
196
+ }): PendingEmbeddingRecord[];
197
+ declare function searchByVector(db: Database.Database, queryVector: ArrayLike<number>, opts: {
198
+ providerId: string;
199
+ agent_id?: string;
200
+ limit?: number;
201
+ min_vitality?: number;
202
+ }): VectorSearchResult[];
203
+
204
+ interface HybridRecallResult {
205
+ memory: Memory;
206
+ score: number;
207
+ bm25_rank?: number;
208
+ vector_rank?: number;
209
+ bm25_score?: number;
210
+ vector_score?: number;
211
+ }
212
+ interface HybridRecallResponse {
213
+ mode: "bm25-only" | "vector-only" | "dual-path";
214
+ providerId: string | null;
215
+ usedVectorSearch: boolean;
216
+ results: HybridRecallResult[];
217
+ }
218
+ interface RecallOptions {
219
+ agent_id?: string;
220
+ limit?: number;
221
+ min_vitality?: number;
222
+ lexicalLimit?: number;
223
+ vectorLimit?: number;
224
+ provider?: EmbeddingProvider | null;
225
+ recordAccess?: boolean;
226
+ }
227
+ interface ReindexOptions {
228
+ agent_id?: string;
229
+ provider?: EmbeddingProvider | null;
230
+ force?: boolean;
231
+ batchSize?: number;
232
+ }
233
+ interface ReindexEmbeddingsResult {
234
+ enabled: boolean;
235
+ providerId: string | null;
236
+ scanned: number;
237
+ pending: number;
238
+ embedded: number;
239
+ failed: number;
240
+ }
241
+ interface ReindexSearchResult {
242
+ fts: {
243
+ reindexed: number;
244
+ };
245
+ embeddings: ReindexEmbeddingsResult;
246
+ }
247
+ declare function priorityPrior(priority: number): number;
248
+ declare function fusionScore(input: {
249
+ memory: Memory;
250
+ bm25Rank?: number;
251
+ vectorRank?: number;
252
+ }): number;
253
+ declare function fuseHybridResults(lexical: SearchResult[], vector: VectorSearchResult[], limit: number): HybridRecallResult[];
254
+ declare function recallMemories(db: Database.Database, query: string, opts?: RecallOptions): Promise<HybridRecallResponse>;
255
+ declare function reindexEmbeddings(db: Database.Database, opts?: ReindexOptions): Promise<ReindexEmbeddingsResult>;
256
+ declare function reindexMemorySearch(db: Database.Database, opts?: ReindexOptions): Promise<ReindexSearchResult>;
257
+
258
+ interface RecallInput {
259
+ query: string;
260
+ limit?: number;
261
+ agent_id?: string;
262
+ min_vitality?: number;
263
+ lexicalLimit?: number;
264
+ vectorLimit?: number;
265
+ provider?: EmbeddingProvider | null;
266
+ recordAccess?: boolean;
267
+ emotion_tag?: string;
268
+ }
269
+ declare function recallMemory(db: Database.Database, input: RecallInput): Promise<HybridRecallResponse>;
270
+
271
+ type FeedbackSource = "recall" | "surface";
272
+ interface FeedbackEventInput {
273
+ memory_id: string;
274
+ source: FeedbackSource;
275
+ useful: boolean;
276
+ agent_id?: string;
277
+ }
278
+ interface FeedbackEventRecord extends FeedbackEventInput {
279
+ id: string;
280
+ created_at: string;
281
+ value: number;
282
+ }
283
+ interface FeedbackSummary {
284
+ total: number;
285
+ useful: number;
286
+ not_useful: number;
287
+ score: number;
288
+ }
289
+ declare function recordFeedbackEvent(db: Database.Database, input: FeedbackEventInput): FeedbackEventRecord;
290
+ declare function getFeedbackSummary(db: Database.Database, memoryId: string, agentId?: string): FeedbackSummary;
291
+ declare function getFeedbackScore(db: Database.Database, memoryId: string, agentId?: string): number;
292
+
293
+ type SurfaceIntent = "factual" | "preference" | "temporal" | "planning" | "design";
294
+ interface SurfaceInput {
295
+ query?: string;
296
+ task?: string;
297
+ recent_turns?: string[];
298
+ intent?: SurfaceIntent;
299
+ types?: MemoryType[];
300
+ limit?: number;
301
+ agent_id?: string;
302
+ provider?: EmbeddingProvider | null;
303
+ min_vitality?: number;
304
+ emotion_tag?: string;
305
+ }
306
+ interface SurfaceResult {
307
+ memory: Memory;
308
+ score: number;
309
+ semantic_score: number;
310
+ lexical_score: number;
311
+ task_match: number;
312
+ vitality: number;
313
+ priority_prior: number;
314
+ feedback_score: number;
315
+ feedback_summary: FeedbackSummary;
316
+ reason_codes: string[];
317
+ lexical_rank?: number;
318
+ semantic_rank?: number;
319
+ semantic_similarity?: number;
320
+ }
321
+ interface SurfaceResponse {
322
+ count: number;
323
+ query?: string;
324
+ task?: string;
325
+ intent?: SurfaceIntent;
326
+ results: SurfaceResult[];
327
+ }
328
+ declare function surfaceMemories(db: Database.Database, input: SurfaceInput): Promise<SurfaceResponse>;
329
+
330
+ type MaintenancePhase = "decay" | "tidy" | "govern" | "all";
331
+ type MaintenanceStatus = "running" | "completed" | "failed";
332
+ type ReflectStep = Exclude<MaintenancePhase, "all">;
333
+ interface ReflectCheckpoint {
334
+ requestedPhase: MaintenancePhase;
335
+ nextPhase: ReflectStep | null;
336
+ completedPhases: ReflectStep[];
337
+ phaseResults: Partial<Record<ReflectStep, unknown>>;
338
+ }
339
+ interface MaintenanceJob {
340
+ job_id: string;
341
+ phase: MaintenancePhase;
342
+ status: MaintenanceStatus;
343
+ checkpoint: ReflectCheckpoint | null;
344
+ error: string | null;
345
+ started_at: string;
346
+ finished_at: string | null;
347
+ }
348
+ declare function createInitialCheckpoint(phase: MaintenancePhase): ReflectCheckpoint;
349
+ declare function createMaintenanceJob(db: Database.Database, phase: MaintenancePhase, checkpoint?: ReflectCheckpoint): MaintenanceJob;
350
+ declare function getMaintenanceJob(db: Database.Database, jobId: string): MaintenanceJob | null;
351
+ declare function findResumableMaintenanceJob(db: Database.Database, phase: MaintenancePhase): MaintenanceJob | null;
352
+ declare function updateMaintenanceCheckpoint(db: Database.Database, jobId: string, checkpoint: ReflectCheckpoint): MaintenanceJob | null;
353
+ declare function failMaintenanceJob(db: Database.Database, jobId: string, error: string, checkpoint?: ReflectCheckpoint | null): MaintenanceJob | null;
354
+ declare function completeMaintenanceJob(db: Database.Database, jobId: string, checkpoint?: ReflectCheckpoint | null): MaintenanceJob | null;
355
+
356
+ interface ReflectStats {
357
+ total: number;
358
+ avgVitality: number;
359
+ }
360
+ interface ReflectRunners {
361
+ decay: (db: Database.Database, opts?: {
362
+ agent_id?: string;
363
+ }) => unknown | Promise<unknown>;
364
+ tidy: (db: Database.Database, opts?: {
365
+ agent_id?: string;
366
+ }) => unknown | Promise<unknown>;
367
+ govern: (db: Database.Database, opts?: {
368
+ agent_id?: string;
369
+ }) => unknown | Promise<unknown>;
370
+ }
371
+ interface ReflectProgressEvent$1 {
372
+ status: "started" | "phase-completed" | "completed" | "failed";
373
+ phase: MaintenancePhase | ReflectStep;
374
+ progress: number;
375
+ jobId?: string;
376
+ detail?: unknown;
377
+ }
378
+ interface ReflectOptions {
379
+ phase: MaintenancePhase;
380
+ agent_id?: string;
381
+ jobId?: string;
382
+ resume?: boolean;
383
+ runners?: Partial<ReflectRunners>;
384
+ onProgress?: (event: ReflectProgressEvent$1) => void;
385
+ }
386
+ interface ReflectRunResult {
387
+ job: MaintenanceJob;
388
+ jobId: string;
389
+ phase: MaintenancePhase;
390
+ resumed: boolean;
391
+ checkpoint: ReflectCheckpoint;
392
+ results: Partial<Record<ReflectStep, unknown>>;
393
+ before: ReflectStats;
394
+ after: ReflectStats;
395
+ }
396
+ declare function runReflectOrchestrator(db: Database.Database, opts: ReflectOptions): Promise<ReflectRunResult>;
397
+
398
+ interface ReflectProgressEvent {
399
+ status: "started" | "phase-completed" | "completed" | "failed";
400
+ phase: MaintenancePhase | ReflectStep;
401
+ progress: number;
402
+ jobId?: string;
403
+ detail?: unknown;
404
+ }
405
+ interface ReflectInput {
406
+ phase: MaintenancePhase;
407
+ agent_id?: string;
408
+ jobId?: string;
409
+ resume?: boolean;
410
+ runners?: Partial<ReflectRunners>;
411
+ onProgress?: (event: ReflectProgressEvent) => void;
412
+ }
413
+ declare function reflectMemories(db: Database.Database, input: ReflectInput): Promise<ReflectRunResult>;
414
+
415
+ interface StatusResult {
416
+ total: number;
417
+ by_type: Record<string, number>;
418
+ by_priority: Record<string, number>;
419
+ paths: number;
420
+ low_vitality: number;
421
+ feedback_events: number;
422
+ agent_id: string;
423
+ }
424
+ declare function getMemoryStatus(db: Database.Database, input?: {
425
+ agent_id?: string;
426
+ }): StatusResult;
427
+
428
+ interface ReindexProgressEvent {
429
+ status: "started" | "stage-completed" | "completed" | "failed";
430
+ stage: "fts" | "embeddings" | "done";
431
+ progress: number;
432
+ detail?: unknown;
433
+ }
434
+ interface ReindexInput {
435
+ agent_id?: string;
436
+ provider?: EmbeddingProvider | null;
437
+ force?: boolean;
438
+ batchSize?: number;
439
+ onProgress?: (event: ReindexProgressEvent) => void;
440
+ }
441
+ declare function reindexMemories(db: Database.Database, input?: ReindexInput): Promise<ReindexSearchResult>;
442
+
443
+ interface HttpJobStatus {
444
+ id: string;
445
+ kind: "reflect" | "reindex";
446
+ status: "running" | "completed" | "failed";
447
+ stage: string;
448
+ progress: number;
449
+ agent_id: string;
450
+ started_at: string;
451
+ finished_at: string | null;
452
+ backend_job_id?: string;
453
+ error?: string;
454
+ result?: unknown;
455
+ }
456
+ interface HttpServerOptions {
457
+ db?: Database.Database;
458
+ dbPath?: string;
459
+ agentId?: string;
460
+ provider?: EmbeddingProvider | null;
461
+ reflectRunners?: Partial<ReflectRunners>;
462
+ }
463
+ interface AgentMemoryHttpServer {
464
+ server: http.Server;
465
+ db: Database.Database;
466
+ jobs: Map<string, HttpJobStatus>;
467
+ listen: (port?: number, host?: string) => Promise<{
468
+ port: number;
469
+ host: string;
470
+ }>;
471
+ close: () => Promise<void>;
472
+ }
473
+ declare function createHttpServer(options?: HttpServerOptions): AgentMemoryHttpServer;
474
+ declare function startHttpServer(options?: HttpServerOptions & {
475
+ port?: number;
476
+ host?: string;
477
+ }): Promise<AgentMemoryHttpServer>;
478
+
59
479
  interface Path {
60
480
  id: string;
61
481
  memory_id: string;
@@ -77,25 +497,46 @@ declare function getPathsByDomain(db: Database.Database, domain: string, agent_i
77
497
  declare function getPathsByPrefix(db: Database.Database, prefix: string, agent_id?: string): Path[];
78
498
  declare function deletePath(db: Database.Database, id: string): boolean;
79
499
 
500
+ interface MergePlan {
501
+ strategy: "replace" | "append_evidence" | "synthesize" | "compact_timeline";
502
+ content: string;
503
+ aliases?: string[];
504
+ notes?: string[];
505
+ }
506
+ interface MergeContext {
507
+ existing: Memory;
508
+ incoming: Pick<CreateMemoryInput, "content" | "type" | "source"> & {
509
+ observed_at?: string | null;
510
+ };
511
+ }
512
+ declare function buildMergePlan(context: MergeContext): MergePlan;
513
+
80
514
  type GuardAction = "add" | "update" | "skip" | "merge";
515
+ interface DedupScoreBreakdown {
516
+ semantic_similarity: number;
517
+ lexical_overlap: number;
518
+ uri_scope_match: number;
519
+ entity_overlap: number;
520
+ time_proximity: number;
521
+ dedup_score: number;
522
+ }
81
523
  interface GuardResult {
82
524
  action: GuardAction;
83
525
  reason: string;
84
526
  existingId?: string;
527
+ updatedContent?: string;
85
528
  mergedContent?: string;
529
+ mergePlan?: MergePlan;
530
+ score?: DedupScoreBreakdown;
86
531
  }
87
- /**
88
- * Write Guard — decides whether to add, update, skip, or merge a memory.
89
- *
90
- * Pipeline:
91
- * 1. Hash dedup (exact content match → skip)
92
- * 2. URI conflict (URI exists → update path)
93
- * 3. BM25 similarity (dynamic threshold → merge or update)
94
- * 4. Four-criterion gate: Specificity, Novelty, Relevance, Coherence
95
- */
96
- declare function guard(db: Database.Database, input: CreateMemoryInput & {
532
+ interface GuardInput extends CreateMemoryInput {
97
533
  uri?: string;
98
- }): GuardResult;
534
+ provider?: EmbeddingProvider | null;
535
+ candidateLimit?: number;
536
+ conservative?: boolean;
537
+ now?: string;
538
+ }
539
+ declare function guard(db: Database.Database, input: GuardInput): Promise<GuardResult>;
99
540
 
100
541
  interface ExportResult {
101
542
  exported: number;
@@ -109,20 +550,33 @@ declare function exportMemories(db: Database.Database, dirPath: string, opts?: {
109
550
  agent_id?: string;
110
551
  }): ExportResult;
111
552
 
112
- interface SearchResult {
113
- memory: Memory;
114
- score: number;
115
- matchReason: string;
553
+ type EmbeddingProviderKind = "openai-compatible" | "local-http";
554
+ interface EmbeddingProviderConfig {
555
+ provider: EmbeddingProviderKind;
556
+ baseUrl: string;
557
+ model: string;
558
+ dimension: number;
559
+ apiKey?: string;
116
560
  }
117
- /**
118
- * BM25 search using SQLite FTS5.
119
- * Returns memories ranked by relevance.
120
- */
121
- declare function searchBM25(db: Database.Database, query: string, opts?: {
122
- agent_id?: string;
123
- limit?: number;
124
- min_vitality?: number;
125
- }): SearchResult[];
561
+ interface EmbeddingProviderFactoryOptions {
562
+ config?: Partial<EmbeddingProviderConfig>;
563
+ env?: NodeJS.ProcessEnv;
564
+ fetchImpl?: typeof fetch;
565
+ }
566
+ declare function getEmbeddingProviderConfigFromEnv(env?: NodeJS.ProcessEnv): EmbeddingProviderConfig | null;
567
+ declare function createEmbeddingProvider(input: EmbeddingProviderConfig, opts?: {
568
+ fetchImpl?: typeof fetch;
569
+ }): EmbeddingProvider;
570
+ declare function getEmbeddingProvider(opts?: EmbeddingProviderFactoryOptions): EmbeddingProvider | null;
571
+ declare function getEmbeddingProviderFromEnv(env?: NodeJS.ProcessEnv): EmbeddingProvider | null;
572
+ declare function getConfiguredEmbeddingProviderId(opts?: {
573
+ config?: Partial<EmbeddingProviderConfig>;
574
+ env?: NodeJS.ProcessEnv;
575
+ }): string | null;
576
+ declare function healthcheckEmbeddingProvider(provider: EmbeddingProvider | null): Promise<{
577
+ enabled: boolean;
578
+ providerId?: string;
579
+ }>;
126
580
 
127
581
  /**
128
582
  * Tokenize text for FTS5 queries.
@@ -132,29 +586,25 @@ declare function searchBM25(db: Database.Database, query: string, opts?: {
132
586
  */
133
587
  declare function tokenize(text: string): string[];
134
588
 
135
- interface IngestBlock {
136
- title: string;
137
- content: string;
138
- }
139
589
  interface IngestExtractedItem {
140
590
  index: number;
141
- title: string;
142
- content: string;
143
591
  type: MemoryType;
144
- uri: string;
592
+ uri?: string;
593
+ content: string;
145
594
  }
146
- interface IngestDryRunDetail {
147
- index: number;
148
- type: MemoryType;
149
- uri: string;
150
- preview: string;
595
+ interface IngestRunOptions {
596
+ text: string;
597
+ source?: string;
598
+ dryRun?: boolean;
599
+ agentId?: string;
151
600
  }
152
601
  interface IngestWriteDetail {
153
602
  index: number;
154
603
  type: MemoryType;
155
- uri: string;
156
- action: "added" | "updated" | "merged" | "skipped";
157
- reason: string;
604
+ uri?: string;
605
+ preview?: string;
606
+ action?: "added" | "updated" | "merged" | "skipped";
607
+ reason?: string;
158
608
  memoryId?: string;
159
609
  }
160
610
  interface IngestResult {
@@ -162,19 +612,16 @@ interface IngestResult {
162
612
  written: number;
163
613
  skipped: number;
164
614
  dry_run: boolean;
165
- details: Array<IngestDryRunDetail | IngestWriteDetail>;
166
- }
167
- interface IngestRunOptions {
168
- text: string;
169
- source?: string;
170
- dryRun?: boolean;
171
- agentId?: string;
615
+ details: IngestWriteDetail[];
172
616
  }
173
617
  declare function slugify(input: string): string;
174
- declare function classifyIngestType(text: string): MemoryType;
175
- declare function splitIngestBlocks(text: string): IngestBlock[];
618
+ declare function classifyIngestType(title: string): MemoryType;
619
+ declare function splitIngestBlocks(text: string): Array<{
620
+ title: string;
621
+ body: string;
622
+ }>;
176
623
  declare function extractIngestItems(text: string, source?: string): IngestExtractedItem[];
177
- declare function ingestText(db: Database.Database, options: IngestRunOptions): IngestResult;
624
+ declare function ingestText(db: Database.Database, options: IngestRunOptions): Promise<IngestResult>;
178
625
 
179
626
  interface AutoIngestWatcherOptions {
180
627
  db: Database.Database;
@@ -221,30 +668,6 @@ declare function getDecayedMemories(db: Database.Database, threshold?: number, o
221
668
  priority: number;
222
669
  }>;
223
670
 
224
- interface SyncInput {
225
- content: string;
226
- type?: CreateMemoryInput["type"];
227
- priority?: CreateMemoryInput["priority"];
228
- emotion_val?: number;
229
- uri?: string;
230
- source?: string;
231
- agent_id?: string;
232
- }
233
- interface SyncResult {
234
- action: "added" | "updated" | "merged" | "skipped";
235
- memoryId?: string;
236
- reason: string;
237
- }
238
- /**
239
- * Sync a single piece of information into memory.
240
- * Runs full Write Guard pipeline before writing.
241
- */
242
- declare function syncOne(db: Database.Database, input: SyncInput): SyncResult;
243
- /**
244
- * Sync multiple items in a batch (within a transaction).
245
- */
246
- declare function syncBatch(db: Database.Database, inputs: SyncInput[]): SyncResult[];
247
-
248
671
  interface TidyResult {
249
672
  archived: number;
250
673
  orphansCleaned: number;
@@ -252,7 +675,8 @@ interface TidyResult {
252
675
  /**
253
676
  * Run the tidy (deep sleep) cycle:
254
677
  * 1. Archive decayed P3 memories (vitality < threshold)
255
- * 2. Clean orphan paths (paths with no memory)
678
+ *
679
+ * Path/orphan cleanup moved to govern.ts in Phase 2.
256
680
  */
257
681
  declare function runTidy(db: Database.Database, opts?: {
258
682
  vitalityThreshold?: number;
@@ -262,27 +686,82 @@ declare function runTidy(db: Database.Database, opts?: {
262
686
  interface GovernResult {
263
687
  orphanPaths: number;
264
688
  emptyMemories: number;
689
+ evicted: number;
265
690
  }
691
+ interface EvictionCandidate {
692
+ memory: Memory;
693
+ redundancy_score: number;
694
+ age_score: number;
695
+ low_feedback_penalty: number;
696
+ low_priority_penalty: number;
697
+ eviction_score: number;
698
+ }
699
+ declare function computeEvictionScore(input: {
700
+ vitality: number;
701
+ redundancy_score: number;
702
+ age_score: number;
703
+ low_feedback_penalty: number;
704
+ low_priority_penalty: number;
705
+ }): number;
706
+ declare function rankEvictionCandidates(db: Database.Database, opts?: {
707
+ agent_id?: string;
708
+ }): EvictionCandidate[];
266
709
  /**
267
710
  * Run governance checks and cleanup:
268
711
  * 1. Remove orphan paths (no parent memory)
269
712
  * 2. Remove empty memories (blank content)
713
+ * 3. Evict low-value memories when over capacity using eviction_score
270
714
  */
271
715
  declare function runGovern(db: Database.Database, opts?: {
272
716
  agent_id?: string;
717
+ maxMemories?: number;
273
718
  }): GovernResult;
274
719
 
275
720
  interface BootResult {
276
721
  identityMemories: Memory[];
277
722
  bootPaths: string[];
278
723
  }
724
+ interface WarmBootOptions {
725
+ agent_id?: string;
726
+ corePaths?: string[];
727
+ format?: "json" | "narrative";
728
+ agent_name?: string;
729
+ }
730
+ interface WarmBootResult extends BootResult {
731
+ narrative?: string;
732
+ layers?: {
733
+ identity: Memory[];
734
+ emotion: Memory[];
735
+ event: Memory[];
736
+ knowledge: Memory[];
737
+ };
738
+ }
739
+ /**
740
+ * Format a relative time string from an ISO date.
741
+ */
742
+ declare function formatRelativeDate(isoDate: string): string;
279
743
  /**
280
- * Load core identity memories at startup.
744
+ * Load layered memories for warm boot.
745
+ */
746
+ declare function loadWarmBootLayers(db: Database.Database, agentId: string): {
747
+ identity: Memory[];
748
+ emotion: Memory[];
749
+ event: Memory[];
750
+ knowledge: Memory[];
751
+ };
752
+ /**
753
+ * Format layered memories as narrative Markdown.
754
+ */
755
+ declare function formatNarrativeBoot(layers: {
756
+ identity: Memory[];
757
+ emotion: Memory[];
758
+ event: Memory[];
759
+ knowledge: Memory[];
760
+ }, agentName: string): string;
761
+ /**
762
+ * Load core identity memories at startup (legacy JSON format).
281
763
  * Returns all P0 (identity) memories + any memories referenced by system://boot.
282
764
  */
283
- declare function boot(db: Database.Database, opts?: {
284
- agent_id?: string;
285
- corePaths?: string[];
286
- }): BootResult;
765
+ declare function boot(db: Database.Database, opts?: WarmBootOptions): WarmBootResult;
287
766
 
288
- export { type AutoIngestWatcher, type AutoIngestWatcherOptions, type BootResult, type CreateMemoryInput, type ExportResult, type GovernResult, type GuardAction, type GuardResult, type IngestExtractedItem, type IngestResult, type IngestRunOptions, type Memory, type MemoryType, type Path, type Priority, type SearchResult, type SyncInput, type SyncResult, type TidyResult, type UpdateMemoryInput, boot, calculateVitality, classifyIngestType, contentHash, countMemories, createMemory, createPath, deleteMemory, deletePath, exportMemories, extractIngestItems, getDecayedMemories, getMemory, getPath, getPathByUri, getPathsByDomain, getPathsByMemory, getPathsByPrefix, guard, ingestText, listMemories, parseUri, recordAccess, runAutoIngestWatcher, runDecay, runGovern, runTidy, searchBM25, slugify, splitIngestBlocks, syncBatch, syncOne, tokenize, updateMemory };
767
+ export { type AgentMemoryHttpServer, type ReflectInput as AppReflectInput, type ReflectProgressEvent as AppReflectProgressEvent, type AutoIngestWatcher, type AutoIngestWatcherOptions, type BootResult, type CreateMemoryInput, type DedupScoreBreakdown, type EmbeddingProvider, type EmbeddingProviderConfig, type EmbeddingProviderKind, type EmbeddingProviderOptions, type EmbeddingStatus, type EvictionCandidate, type ExportResult, type FeedbackEventInput, type FeedbackEventRecord, type FeedbackSource, type FeedbackSummary, type GovernResult, type GuardAction, type GuardInput, type GuardResult, type HttpJobStatus, type HttpServerOptions, type HybridRecallResponse, type HybridRecallResult, type IngestExtractedItem, type IngestResult, type IngestRunOptions, type MaintenanceJob, type MaintenancePhase, type MaintenanceStatus, type Memory, type MemoryType, type MergeContext, type MergePlan, type Path, type PendingEmbeddingRecord, type Priority, type RecallInput, type ReflectCheckpoint, type ReflectOptions, type ReflectProgressEvent$1 as ReflectProgressEvent, type ReflectRunResult, type ReflectRunners, type ReflectStats, type ReflectStep, type ReindexEmbeddingsResult, type ReindexInput, type ReindexProgressEvent, type ReindexSearchResult, type RememberInput, type SearchResult, type StatusResult, type StoredEmbedding, type SurfaceInput, type SurfaceIntent, type SurfaceResponse, type SurfaceResult, type SyncInput, type SyncResult, type TidyResult, type UpdateMemoryInput, type VectorSearchResult, type WarmBootOptions, type WarmBootResult, boot, buildFtsQuery, buildMergePlan, calculateVitality, classifyIngestType, completeMaintenanceJob, computeEvictionScore, contentHash, cosineSimilarity, countMemories, createEmbeddingProvider, createHttpServer, createInitialCheckpoint, createLocalHttpEmbeddingProvider, createMaintenanceJob, createMemory, createOpenAICompatibleEmbeddingProvider, createPath, decodeVector, deleteMemory, deletePath, encodeVector, exportMemories, extractIngestItems, failMaintenanceJob, findResumableMaintenanceJob, formatNarrativeBoot, formatRelativeDate, fuseHybridResults, fusionScore, getConfiguredEmbeddingProviderId, getDecayedMemories, getEmbedding, getEmbeddingProvider, getEmbeddingProviderConfigFromEnv, getEmbeddingProviderFromEnv, getFeedbackScore, getFeedbackSummary, getMaintenanceJob, getMemory, getMemoryStatus, getPath, getPathByUri, getPathsByDomain, getPathsByMemory, getPathsByPrefix, guard, healthcheckEmbeddingProvider, ingestText, listMemories, listPendingEmbeddings, loadWarmBootLayers, markAllEmbeddingsPending, markEmbeddingFailed, markMemoryEmbeddingPending, parseUri, priorityPrior, rankEvictionCandidates, rebuildBm25Index, recallMemories, recallMemory, recordAccess, recordFeedbackEvent, reflectMemories, reindexEmbeddings, reindexMemories, reindexMemorySearch, rememberMemory, runAutoIngestWatcher, runDecay, runGovern, runReflectOrchestrator, runTidy, searchBM25, searchByVector, slugify, splitIngestBlocks, startHttpServer, surfaceMemories, syncBatch, syncOne, tokenize, updateMaintenanceCheckpoint, updateMemory, upsertReadyEmbedding };