@smyslenny/agent-memory 4.3.1 → 5.0.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
@@ -39,6 +39,9 @@ interface Memory {
39
39
  agent_id: string;
40
40
  hash: string | null;
41
41
  emotion_tag: string | null;
42
+ source_session: string | null;
43
+ source_context: string | null;
44
+ observed_at: string | null;
42
45
  }
43
46
  interface CreateMemoryInput {
44
47
  content: string;
@@ -49,6 +52,9 @@ interface CreateMemoryInput {
49
52
  agent_id?: string;
50
53
  embedding_provider_id?: string | null;
51
54
  emotion_tag?: string;
55
+ source_session?: string;
56
+ source_context?: string;
57
+ observed_at?: string;
52
58
  }
53
59
  interface UpdateMemoryInput {
54
60
  content?: string;
@@ -82,6 +88,61 @@ declare function countMemories(db: Database.Database, agent_id?: string): {
82
88
  by_priority: Record<string, number>;
83
89
  };
84
90
 
91
+ interface MergePlan {
92
+ strategy: "replace" | "append_evidence" | "synthesize" | "compact_timeline";
93
+ content: string;
94
+ aliases?: string[];
95
+ notes?: string[];
96
+ }
97
+ interface MergeContext {
98
+ existing: Memory;
99
+ incoming: Pick<CreateMemoryInput, "content" | "type" | "source"> & {
100
+ observed_at?: string | null;
101
+ };
102
+ }
103
+ declare function buildMergePlan(context: MergeContext): MergePlan;
104
+
105
+ type GuardAction = "add" | "update" | "skip" | "merge";
106
+ type ConflictType = "negation" | "value" | "status";
107
+ interface ConflictInfo {
108
+ memoryId: string;
109
+ content: string;
110
+ conflict_score: number;
111
+ conflict_type: ConflictType;
112
+ detail: string;
113
+ }
114
+ interface DedupScoreBreakdown {
115
+ semantic_similarity: number;
116
+ lexical_overlap: number;
117
+ uri_scope_match: number;
118
+ entity_overlap: number;
119
+ time_proximity: number;
120
+ dedup_score: number;
121
+ }
122
+ interface GuardResult {
123
+ action: GuardAction;
124
+ reason: string;
125
+ existingId?: string;
126
+ updatedContent?: string;
127
+ mergedContent?: string;
128
+ mergePlan?: MergePlan;
129
+ score?: DedupScoreBreakdown;
130
+ candidates?: Array<{
131
+ memoryId: string;
132
+ dedup_score: number;
133
+ }>;
134
+ conflicts?: ConflictInfo[];
135
+ }
136
+ interface GuardInput extends CreateMemoryInput {
137
+ uri?: string;
138
+ provider?: EmbeddingProvider | null;
139
+ candidateLimit?: number;
140
+ conservative?: boolean;
141
+ now?: string;
142
+ observed_at?: string;
143
+ }
144
+ declare function guard(db: Database.Database, input: GuardInput): Promise<GuardResult>;
145
+
85
146
  interface SyncInput {
86
147
  content: string;
87
148
  type?: CreateMemoryInput["type"];
@@ -93,11 +154,15 @@ interface SyncInput {
93
154
  provider?: EmbeddingProvider | null;
94
155
  conservative?: boolean;
95
156
  emotion_tag?: string;
157
+ source_session?: string;
158
+ source_context?: string;
159
+ observed_at?: string;
96
160
  }
97
161
  interface SyncResult {
98
162
  action: "added" | "updated" | "merged" | "skipped";
99
163
  memoryId?: string;
100
164
  reason: string;
165
+ conflicts?: ConflictInfo[];
101
166
  }
102
167
  /**
103
168
  * Sync a single piece of information into memory.
@@ -121,6 +186,9 @@ interface RememberInput {
121
186
  provider?: EmbeddingProvider | null;
122
187
  conservative?: boolean;
123
188
  emotion_tag?: string;
189
+ source_session?: string;
190
+ source_context?: string;
191
+ observed_at?: string;
124
192
  }
125
193
  declare function rememberMemory(db: Database.Database, input: RememberInput): Promise<SyncResult>;
126
194
 
@@ -138,6 +206,8 @@ declare function searchBM25(db: Database.Database, query: string, opts?: {
138
206
  agent_id?: string;
139
207
  limit?: number;
140
208
  min_vitality?: number;
209
+ after?: string;
210
+ before?: string;
141
211
  }): SearchResult[];
142
212
  /**
143
213
  * Build FTS5 query from natural language.
@@ -199,6 +269,8 @@ declare function searchByVector(db: Database.Database, queryVector: ArrayLike<nu
199
269
  agent_id?: string;
200
270
  limit?: number;
201
271
  min_vitality?: number;
272
+ after?: string;
273
+ before?: string;
202
274
  }): VectorSearchResult[];
203
275
 
204
276
  interface HybridRecallResult {
@@ -208,6 +280,8 @@ interface HybridRecallResult {
208
280
  vector_rank?: number;
209
281
  bm25_score?: number;
210
282
  vector_score?: number;
283
+ related_source_id?: string;
284
+ match_type?: "direct" | "related";
211
285
  }
212
286
  interface HybridRecallResponse {
213
287
  mode: "bm25-only" | "vector-only" | "dual-path";
@@ -223,6 +297,10 @@ interface RecallOptions {
223
297
  vectorLimit?: number;
224
298
  provider?: EmbeddingProvider | null;
225
299
  recordAccess?: boolean;
300
+ related?: boolean;
301
+ after?: string;
302
+ before?: string;
303
+ recency_boost?: number;
226
304
  }
227
305
  interface ReindexOptions {
228
306
  agent_id?: string;
@@ -249,8 +327,9 @@ declare function fusionScore(input: {
249
327
  memory: Memory;
250
328
  bm25Rank?: number;
251
329
  vectorRank?: number;
330
+ recency_boost?: number;
252
331
  }): number;
253
- declare function fuseHybridResults(lexical: SearchResult[], vector: VectorSearchResult[], limit: number): HybridRecallResult[];
332
+ declare function fuseHybridResults(lexical: SearchResult[], vector: VectorSearchResult[], limit: number, recency_boost?: number): HybridRecallResult[];
254
333
  declare function recallMemories(db: Database.Database, query: string, opts?: RecallOptions): Promise<HybridRecallResponse>;
255
334
  declare function reindexEmbeddings(db: Database.Database, opts?: ReindexOptions): Promise<ReindexEmbeddingsResult>;
256
335
  declare function reindexMemorySearch(db: Database.Database, opts?: ReindexOptions): Promise<ReindexSearchResult>;
@@ -265,10 +344,14 @@ interface RecallInput {
265
344
  provider?: EmbeddingProvider | null;
266
345
  recordAccess?: boolean;
267
346
  emotion_tag?: string;
347
+ related?: boolean;
348
+ after?: string;
349
+ before?: string;
350
+ recency_boost?: number;
268
351
  }
269
352
  declare function recallMemory(db: Database.Database, input: RecallInput): Promise<HybridRecallResponse>;
270
353
 
271
- type FeedbackSource = "recall" | "surface";
354
+ type FeedbackSource = "recall" | "surface" | "passive";
272
355
  interface FeedbackEventInput {
273
356
  memory_id: string;
274
357
  source: FeedbackSource;
@@ -289,6 +372,12 @@ interface FeedbackSummary {
289
372
  declare function recordFeedbackEvent(db: Database.Database, input: FeedbackEventInput): FeedbackEventRecord;
290
373
  declare function getFeedbackSummary(db: Database.Database, memoryId: string, agentId?: string): FeedbackSummary;
291
374
  declare function getFeedbackScore(db: Database.Database, memoryId: string, agentId?: string): number;
375
+ /**
376
+ * Record passive feedback for multiple memories.
377
+ * 24h dedup: each memory can receive at most 3 passive feedbacks per 24h window.
378
+ * Uses batch query to avoid N+1.
379
+ */
380
+ declare function recordPassiveFeedback(db: Database.Database, memoryIds: string[], agentId?: string): number;
292
381
 
293
382
  type SurfaceIntent = "factual" | "preference" | "temporal" | "planning" | "design";
294
383
  interface SurfaceInput {
@@ -302,6 +391,10 @@ interface SurfaceInput {
302
391
  provider?: EmbeddingProvider | null;
303
392
  min_vitality?: number;
304
393
  emotion_tag?: string;
394
+ related?: boolean;
395
+ after?: string;
396
+ before?: string;
397
+ recency_boost?: number;
305
398
  }
306
399
  interface SurfaceResult {
307
400
  memory: Memory;
@@ -497,47 +590,6 @@ declare function getPathsByDomain(db: Database.Database, domain: string, agent_i
497
590
  declare function getPathsByPrefix(db: Database.Database, prefix: string, agent_id?: string): Path[];
498
591
  declare function deletePath(db: Database.Database, id: string): boolean;
499
592
 
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
-
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
- }
523
- interface GuardResult {
524
- action: GuardAction;
525
- reason: string;
526
- existingId?: string;
527
- updatedContent?: string;
528
- mergedContent?: string;
529
- mergePlan?: MergePlan;
530
- score?: DedupScoreBreakdown;
531
- }
532
- interface GuardInput extends CreateMemoryInput {
533
- uri?: string;
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>;
540
-
541
593
  interface ExportResult {
542
594
  exported: number;
543
595
  files: string[];
@@ -672,10 +724,22 @@ declare function getDecayedMemories(db: Database.Database, threshold?: number, o
672
724
  interface TidyResult {
673
725
  archived: number;
674
726
  orphansCleaned: number;
727
+ staleDecayed: number;
728
+ }
729
+ interface StaleDetectionResult {
730
+ stale: boolean;
731
+ reason: string;
732
+ decay_factor: number;
675
733
  }
734
+ /**
735
+ * Detect if memory content is stale based on patterns.
736
+ * identity and emotion types never participate in semantic decay.
737
+ */
738
+ declare function isStaleContent(content: string, type: MemoryType): StaleDetectionResult;
676
739
  /**
677
740
  * Run the tidy (deep sleep) cycle:
678
741
  * 1. Archive decayed P3 memories (vitality < threshold)
742
+ * 2. Apply semantic decay to stale content
679
743
  *
680
744
  * Path/orphan cleanup moved to govern.ts in Phase 2.
681
745
  */
@@ -767,4 +831,4 @@ declare function formatNarrativeBoot(layers: {
767
831
  */
768
832
  declare function boot(db: Database.Database, opts?: WarmBootOptions): WarmBootResult;
769
833
 
770
- 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 };
834
+ export { type AgentMemoryHttpServer, type ReflectInput as AppReflectInput, type ReflectProgressEvent as AppReflectProgressEvent, type AutoIngestWatcher, type AutoIngestWatcherOptions, type BootResult, type ConflictInfo, type ConflictType, 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, isStaleContent, listMemories, listPendingEmbeddings, loadWarmBootLayers, markAllEmbeddingsPending, markEmbeddingFailed, markMemoryEmbeddingPending, parseUri, priorityPrior, rankEvictionCandidates, rebuildBm25Index, recallMemories, recallMemory, recordAccess, recordFeedbackEvent, recordPassiveFeedback, reflectMemories, reindexEmbeddings, reindexMemories, reindexMemorySearch, rememberMemory, runAutoIngestWatcher, runDecay, runGovern, runReflectOrchestrator, runTidy, searchBM25, searchByVector, slugify, splitIngestBlocks, startHttpServer, surfaceMemories, syncBatch, syncOne, tokenize, updateMaintenanceCheckpoint, updateMemory, upsertReadyEmbedding };