@smyslenny/agent-memory 2.2.0 → 3.1.0
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/CHANGELOG.md +45 -41
- package/README.en.md +153 -0
- package/README.md +86 -153
- package/dist/bin/agent-memory.js +28 -534
- package/dist/bin/agent-memory.js.map +1 -1
- package/dist/index.d.ts +50 -167
- package/dist/index.js +289 -692
- package/dist/index.js.map +1 -1
- package/dist/mcp/server.js +584 -748
- package/dist/mcp/server.js.map +1 -1
- package/docs/design/0014-memory-core-dedup.md +722 -0
- package/docs/design/TEMPLATE.md +67 -0
- package/package.json +2 -3
- package/README.zh-CN.md +0 -170
package/dist/index.d.ts
CHANGED
|
@@ -77,51 +77,6 @@ declare function getPathsByDomain(db: Database.Database, domain: string, agent_i
|
|
|
77
77
|
declare function getPathsByPrefix(db: Database.Database, prefix: string, agent_id?: string): Path[];
|
|
78
78
|
declare function deletePath(db: Database.Database, id: string): boolean;
|
|
79
79
|
|
|
80
|
-
type RelationType = "related" | "caused" | "reminds" | "evolved" | "contradicts";
|
|
81
|
-
interface Link {
|
|
82
|
-
agent_id: string;
|
|
83
|
-
source_id: string;
|
|
84
|
-
target_id: string;
|
|
85
|
-
relation: RelationType;
|
|
86
|
-
weight: number;
|
|
87
|
-
created_at: string;
|
|
88
|
-
}
|
|
89
|
-
declare function createLink(db: Database.Database, sourceId: string, targetId: string, relation: RelationType, weight?: number, agent_id?: string): Link;
|
|
90
|
-
declare function getLinks(db: Database.Database, memoryId: string, agent_id?: string): Link[];
|
|
91
|
-
declare function getOutgoingLinks(db: Database.Database, sourceId: string, agent_id?: string): Link[];
|
|
92
|
-
/**
|
|
93
|
-
* Multi-hop traversal: find all memories reachable within N hops
|
|
94
|
-
* Inspired by PowerMem's knowledge graph traversal
|
|
95
|
-
*/
|
|
96
|
-
declare function traverse(db: Database.Database, startId: string, maxHops?: number, agent_id?: string): Array<{
|
|
97
|
-
id: string;
|
|
98
|
-
hop: number;
|
|
99
|
-
relation: string;
|
|
100
|
-
}>;
|
|
101
|
-
declare function deleteLink(db: Database.Database, sourceId: string, targetId: string, agent_id?: string): boolean;
|
|
102
|
-
|
|
103
|
-
type SnapshotAction = "create" | "update" | "delete" | "merge";
|
|
104
|
-
interface Snapshot {
|
|
105
|
-
id: string;
|
|
106
|
-
memory_id: string;
|
|
107
|
-
content: string;
|
|
108
|
-
changed_by: string | null;
|
|
109
|
-
action: SnapshotAction;
|
|
110
|
-
created_at: string;
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* Create a snapshot before modifying a memory.
|
|
114
|
-
* Call this BEFORE any update/delete operation.
|
|
115
|
-
*/
|
|
116
|
-
declare function createSnapshot(db: Database.Database, memoryId: string, action: SnapshotAction, changedBy?: string): Snapshot;
|
|
117
|
-
declare function getSnapshots(db: Database.Database, memoryId: string): Snapshot[];
|
|
118
|
-
declare function getSnapshot(db: Database.Database, id: string): Snapshot | null;
|
|
119
|
-
/**
|
|
120
|
-
* Rollback a memory to a specific snapshot.
|
|
121
|
-
* Creates a new snapshot of the current state before rolling back.
|
|
122
|
-
*/
|
|
123
|
-
declare function rollback(db: Database.Database, snapshotId: string): boolean;
|
|
124
|
-
|
|
125
80
|
type GuardAction = "add" | "update" | "skip" | "merge";
|
|
126
81
|
interface GuardResult {
|
|
127
82
|
action: GuardAction;
|
|
@@ -177,129 +132,62 @@ declare function searchBM25(db: Database.Database, query: string, opts?: {
|
|
|
177
132
|
*/
|
|
178
133
|
declare function tokenize(text: string): string[];
|
|
179
134
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
confidence: number;
|
|
135
|
+
interface IngestBlock {
|
|
136
|
+
title: string;
|
|
137
|
+
content: string;
|
|
184
138
|
}
|
|
185
|
-
|
|
186
|
-
* Classify the intent of a search query.
|
|
187
|
-
* Uses keyword pattern matching + structural analysis.
|
|
188
|
-
* Enhanced for Chinese with jieba-aware token analysis.
|
|
189
|
-
*/
|
|
190
|
-
declare function classifyIntent(query: string): IntentResult;
|
|
191
|
-
/**
|
|
192
|
-
* Get search strategy based on intent
|
|
193
|
-
*/
|
|
194
|
-
declare function getStrategy(intent: SearchIntent): {
|
|
195
|
-
boostRecent: boolean;
|
|
196
|
-
boostPriority: boolean;
|
|
197
|
-
limit: number;
|
|
198
|
-
};
|
|
199
|
-
|
|
200
|
-
interface RerankResult {
|
|
139
|
+
interface IngestExtractedItem {
|
|
201
140
|
index: number;
|
|
202
|
-
|
|
141
|
+
title: string;
|
|
142
|
+
content: string;
|
|
143
|
+
type: MemoryType;
|
|
144
|
+
uri: string;
|
|
203
145
|
}
|
|
204
|
-
interface
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
146
|
+
interface IngestDryRunDetail {
|
|
147
|
+
index: number;
|
|
148
|
+
type: MemoryType;
|
|
149
|
+
uri: string;
|
|
150
|
+
preview: string;
|
|
208
151
|
}
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
/**
|
|
217
|
-
* Optionally rerank results using an external semantic reranker provider.
|
|
218
|
-
* Best-effort: on failure, returns original results unchanged.
|
|
219
|
-
*/
|
|
220
|
-
declare function rerankWithProvider(results: SearchResult[], query: string, provider: RerankProvider): Promise<SearchResult[]>;
|
|
221
|
-
/**
|
|
222
|
-
* Rerank search results based on intent strategy and priority weighting.
|
|
223
|
-
*/
|
|
224
|
-
declare function rerank(results: SearchResult[], opts: {
|
|
225
|
-
intent?: SearchIntent;
|
|
226
|
-
boostRecent: boolean;
|
|
227
|
-
boostPriority: boolean;
|
|
228
|
-
limit: number;
|
|
229
|
-
}): SearchResult[];
|
|
230
|
-
|
|
231
|
-
interface EmbeddingProvider {
|
|
232
|
-
id: string;
|
|
233
|
-
model: string;
|
|
234
|
-
dimension?: number;
|
|
235
|
-
instructionPrefix?: string | null;
|
|
236
|
-
embed(text: string): Promise<number[]>;
|
|
237
|
-
embedQuery?(query: string): Promise<number[]>;
|
|
152
|
+
interface IngestWriteDetail {
|
|
153
|
+
index: number;
|
|
154
|
+
type: MemoryType;
|
|
155
|
+
uri: string;
|
|
156
|
+
action: "added" | "updated" | "merged" | "skipped";
|
|
157
|
+
reason: string;
|
|
158
|
+
memoryId?: string;
|
|
238
159
|
}
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
baseUrl?: string;
|
|
246
|
-
instruction?: string | null;
|
|
247
|
-
}): EmbeddingProvider;
|
|
248
|
-
declare function createDashScopeProvider(opts: {
|
|
249
|
-
apiKey: string;
|
|
250
|
-
model: string;
|
|
251
|
-
baseUrl?: string;
|
|
252
|
-
instruction?: string | null;
|
|
253
|
-
}): EmbeddingProvider;
|
|
254
|
-
|
|
255
|
-
interface HybridSearchOptions {
|
|
256
|
-
agent_id?: string;
|
|
257
|
-
limit?: number;
|
|
258
|
-
bm25CandidateMultiplier?: number;
|
|
259
|
-
semanticCandidates?: number;
|
|
260
|
-
rrfK?: number;
|
|
261
|
-
embeddingProvider?: EmbeddingProvider | null;
|
|
262
|
-
embeddingModel?: string;
|
|
160
|
+
interface IngestResult {
|
|
161
|
+
extracted: number;
|
|
162
|
+
written: number;
|
|
163
|
+
skipped: number;
|
|
164
|
+
dry_run: boolean;
|
|
165
|
+
details: Array<IngestDryRunDetail | IngestWriteDetail>;
|
|
263
166
|
}
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
model: string;
|
|
270
|
-
dim: number;
|
|
271
|
-
vector: Float32Array;
|
|
272
|
-
created_at: string;
|
|
273
|
-
updated_at: string;
|
|
167
|
+
interface IngestRunOptions {
|
|
168
|
+
text: string;
|
|
169
|
+
source?: string;
|
|
170
|
+
dryRun?: boolean;
|
|
171
|
+
agentId?: string;
|
|
274
172
|
}
|
|
275
|
-
declare function
|
|
276
|
-
declare function
|
|
277
|
-
declare function
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
model: string;
|
|
281
|
-
vector: number[] | Float32Array;
|
|
282
|
-
}): void;
|
|
283
|
-
declare function getEmbedding(db: Database.Database, agent_id: string, memory_id: string, model: string): StoredEmbedding | null;
|
|
284
|
-
declare function listEmbeddings(db: Database.Database, agent_id: string, model: string): Array<{
|
|
285
|
-
memory_id: string;
|
|
286
|
-
vector: Float32Array;
|
|
287
|
-
}>;
|
|
173
|
+
declare function slugify(input: string): string;
|
|
174
|
+
declare function classifyIngestType(text: string): MemoryType;
|
|
175
|
+
declare function splitIngestBlocks(text: string): IngestBlock[];
|
|
176
|
+
declare function extractIngestItems(text: string, source?: string): IngestExtractedItem[];
|
|
177
|
+
declare function ingestText(db: Database.Database, options: IngestRunOptions): IngestResult;
|
|
288
178
|
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
scanned: number;
|
|
302
|
-
}>;
|
|
179
|
+
interface AutoIngestWatcherOptions {
|
|
180
|
+
db: Database.Database;
|
|
181
|
+
workspaceDir: string;
|
|
182
|
+
agentId: string;
|
|
183
|
+
debounceMs?: number;
|
|
184
|
+
initialScan?: boolean;
|
|
185
|
+
logger?: Pick<Console, "log" | "warn" | "error">;
|
|
186
|
+
}
|
|
187
|
+
interface AutoIngestWatcher {
|
|
188
|
+
close: () => void;
|
|
189
|
+
}
|
|
190
|
+
declare function runAutoIngestWatcher(options: AutoIngestWatcherOptions): AutoIngestWatcher;
|
|
303
191
|
|
|
304
192
|
/**
|
|
305
193
|
* Calculate vitality using Ebbinghaus forgetting curve.
|
|
@@ -360,30 +248,25 @@ declare function syncBatch(db: Database.Database, inputs: SyncInput[]): SyncResu
|
|
|
360
248
|
interface TidyResult {
|
|
361
249
|
archived: number;
|
|
362
250
|
orphansCleaned: number;
|
|
363
|
-
snapshotsPruned: number;
|
|
364
251
|
}
|
|
365
252
|
/**
|
|
366
253
|
* Run the tidy (deep sleep) cycle:
|
|
367
254
|
* 1. Archive decayed P3 memories (vitality < threshold)
|
|
368
255
|
* 2. Clean orphan paths (paths with no memory)
|
|
369
|
-
* 3. Prune old snapshots (keep last N per memory)
|
|
370
256
|
*/
|
|
371
257
|
declare function runTidy(db: Database.Database, opts?: {
|
|
372
258
|
vitalityThreshold?: number;
|
|
373
|
-
maxSnapshotsPerMemory?: number;
|
|
374
259
|
agent_id?: string;
|
|
375
260
|
}): TidyResult;
|
|
376
261
|
|
|
377
262
|
interface GovernResult {
|
|
378
263
|
orphanPaths: number;
|
|
379
|
-
orphanLinks: number;
|
|
380
264
|
emptyMemories: number;
|
|
381
265
|
}
|
|
382
266
|
/**
|
|
383
267
|
* Run governance checks and cleanup:
|
|
384
268
|
* 1. Remove orphan paths (no parent memory)
|
|
385
|
-
* 2. Remove
|
|
386
|
-
* 3. Remove empty memories (blank content)
|
|
269
|
+
* 2. Remove empty memories (blank content)
|
|
387
270
|
*/
|
|
388
271
|
declare function runGovern(db: Database.Database, opts?: {
|
|
389
272
|
agent_id?: string;
|
|
@@ -402,4 +285,4 @@ declare function boot(db: Database.Database, opts?: {
|
|
|
402
285
|
corePaths?: string[];
|
|
403
286
|
}): BootResult;
|
|
404
287
|
|
|
405
|
-
export { type
|
|
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 };
|