audrey 0.15.0 → 0.16.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/LICENSE +21 -21
- package/README.md +808 -681
- package/mcp-server/config.js +80 -76
- package/mcp-server/index.js +728 -456
- package/package.json +76 -77
- package/src/adaptive.js +53 -53
- package/src/affect.js +64 -64
- package/src/audrey.js +604 -647
- package/src/causal.js +95 -95
- package/src/confidence.js +120 -120
- package/src/consolidate.js +265 -242
- package/src/context.js +15 -15
- package/src/db.js +370 -333
- package/src/decay.js +84 -84
- package/src/embedding.js +256 -256
- package/src/encode.js +63 -85
- package/src/export.js +67 -61
- package/src/forget.js +111 -111
- package/src/import.js +245 -123
- package/src/index.js +27 -20
- package/src/interference.js +51 -51
- package/src/introspect.js +48 -48
- package/src/llm.js +246 -240
- package/src/migrate.js +58 -58
- package/src/prompts.js +223 -223
- package/src/recall.js +352 -329
- package/src/rollback.js +42 -42
- package/src/ulid.js +18 -18
- package/src/utils.js +38 -38
- package/src/validate.js +172 -172
package/mcp-server/index.js
CHANGED
|
@@ -1,457 +1,729 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
3
|
-
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
4
|
-
import { z } from 'zod';
|
|
5
|
-
import { homedir } from 'node:os';
|
|
6
|
-
import { join } from 'node:path';
|
|
7
|
-
import { existsSync, readFileSync } from 'node:fs';
|
|
8
|
-
import { execFileSync } from 'node:child_process';
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
const
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
'
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
'
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
}
|
|
2
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
3
|
+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
import { homedir } from 'node:os';
|
|
6
|
+
import { join, resolve } from 'node:path';
|
|
7
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
8
|
+
import { execFileSync } from 'node:child_process';
|
|
9
|
+
import { fileURLToPath } from 'node:url';
|
|
10
|
+
import { Audrey } from '../src/index.js';
|
|
11
|
+
import { readStoredDimensions } from '../src/db.js';
|
|
12
|
+
import {
|
|
13
|
+
VERSION,
|
|
14
|
+
SERVER_NAME,
|
|
15
|
+
DEFAULT_DATA_DIR,
|
|
16
|
+
buildAudreyConfig,
|
|
17
|
+
buildInstallArgs,
|
|
18
|
+
resolveEmbeddingProvider,
|
|
19
|
+
} from './config.js';
|
|
20
|
+
|
|
21
|
+
const VALID_SOURCES = ['direct-observation', 'told-by-user', 'tool-result', 'inference', 'model-generated'];
|
|
22
|
+
const VALID_TYPES = ['episodic', 'semantic', 'procedural'];
|
|
23
|
+
|
|
24
|
+
export const MAX_MEMORY_CONTENT_LENGTH = 50_000;
|
|
25
|
+
|
|
26
|
+
const subcommand = process.argv[2];
|
|
27
|
+
|
|
28
|
+
function isNonEmptyText(value) {
|
|
29
|
+
return typeof value === 'string' && value.trim().length > 0;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function validateMemoryContent(content) {
|
|
33
|
+
if (!isNonEmptyText(content)) {
|
|
34
|
+
throw new Error('content must be a non-empty string');
|
|
35
|
+
}
|
|
36
|
+
if (content.length > MAX_MEMORY_CONTENT_LENGTH) {
|
|
37
|
+
throw new Error(`content exceeds maximum length of ${MAX_MEMORY_CONTENT_LENGTH} characters`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function validateForgetSelection(id, query) {
|
|
42
|
+
if ((id && query) || (!id && !query)) {
|
|
43
|
+
throw new Error('Provide exactly one of id or query');
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export async function initializeEmbeddingProvider(provider) {
|
|
48
|
+
if (provider && typeof provider.ready === 'function') {
|
|
49
|
+
await provider.ready();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export const memoryEncodeToolSchema = {
|
|
54
|
+
content: z.string()
|
|
55
|
+
.max(MAX_MEMORY_CONTENT_LENGTH)
|
|
56
|
+
.refine(isNonEmptyText, 'Content must not be empty')
|
|
57
|
+
.describe('The memory content to encode'),
|
|
58
|
+
source: z.enum(VALID_SOURCES).describe('Source type of the memory'),
|
|
59
|
+
tags: z.array(z.string()).optional().describe('Optional tags for categorization'),
|
|
60
|
+
salience: z.number().min(0).max(1).optional().describe('Importance weight 0-1'),
|
|
61
|
+
context: z.record(z.string()).optional().describe('Situational context as key-value pairs (e.g., {task: "debugging", domain: "payments"})'),
|
|
62
|
+
affect: z.object({
|
|
63
|
+
valence: z.number().min(-1).max(1).describe('Emotional valence: -1 (very negative) to 1 (very positive)'),
|
|
64
|
+
arousal: z.number().min(0).max(1).optional().describe('Emotional arousal: 0 (calm) to 1 (highly activated)'),
|
|
65
|
+
label: z.string().optional().describe('Human-readable emotion label (e.g., "curiosity", "frustration", "relief")'),
|
|
66
|
+
}).optional().describe('Emotional affect - how this memory feels'),
|
|
67
|
+
private: z.boolean().optional().describe('If true, memory is only visible to the AI and excluded from public recall results'),
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
export const memoryRecallToolSchema = {
|
|
71
|
+
query: z.string().describe('Search query to match against memories'),
|
|
72
|
+
limit: z.number().min(1).max(50).optional().describe('Max results (default 10)'),
|
|
73
|
+
types: z.array(z.enum(VALID_TYPES)).optional().describe('Memory types to search'),
|
|
74
|
+
min_confidence: z.number().min(0).max(1).optional().describe('Minimum confidence threshold'),
|
|
75
|
+
tags: z.array(z.string()).optional().describe('Only return episodic memories with these tags'),
|
|
76
|
+
sources: z.array(z.enum(VALID_SOURCES)).optional().describe('Only return episodic memories from these sources'),
|
|
77
|
+
after: z.string().optional().describe('Only return memories created after this ISO date'),
|
|
78
|
+
before: z.string().optional().describe('Only return memories created before this ISO date'),
|
|
79
|
+
context: z.record(z.string()).optional().describe('Retrieval context - memories encoded in matching context get boosted'),
|
|
80
|
+
mood: z.object({
|
|
81
|
+
valence: z.number().min(-1).max(1).describe('Current emotional valence: -1 (negative) to 1 (positive)'),
|
|
82
|
+
arousal: z.number().min(0).max(1).optional().describe('Current arousal: 0 (calm) to 1 (activated)'),
|
|
83
|
+
}).optional().describe('Current mood - boosts recall of memories encoded in similar emotional state'),
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
export const memoryImportToolSchema = {
|
|
87
|
+
snapshot: z.object({
|
|
88
|
+
version: z.string(),
|
|
89
|
+
episodes: z.array(z.any()),
|
|
90
|
+
semantics: z.array(z.any()).optional(),
|
|
91
|
+
procedures: z.array(z.any()).optional(),
|
|
92
|
+
causalLinks: z.array(z.any()).optional(),
|
|
93
|
+
contradictions: z.array(z.any()).optional(),
|
|
94
|
+
consolidationRuns: z.array(z.any()).optional(),
|
|
95
|
+
consolidationMetrics: z.array(z.any()).optional(),
|
|
96
|
+
config: z.record(z.string()).optional(),
|
|
97
|
+
}).passthrough().describe('A snapshot from memory_export'),
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
export const memoryForgetToolSchema = {
|
|
101
|
+
id: z.string().optional().describe('ID of the memory to forget'),
|
|
102
|
+
query: z.string().optional().describe('Semantic query to find and forget the closest matching memory'),
|
|
103
|
+
min_similarity: z.number().min(0).max(1).optional().describe('Minimum similarity for query-based forget (default 0.9)'),
|
|
104
|
+
purge: z.boolean().optional().describe('Hard-delete the memory permanently (default false, soft-delete)'),
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
async function reembed() {
|
|
108
|
+
const dataDir = process.env.AUDREY_DATA_DIR || DEFAULT_DATA_DIR;
|
|
109
|
+
const explicit = process.env.AUDREY_EMBEDDING_PROVIDER;
|
|
110
|
+
const embedding = resolveEmbeddingProvider(process.env, explicit);
|
|
111
|
+
const storedDims = readStoredDimensions(dataDir);
|
|
112
|
+
const dimensionsChanged = storedDims !== null && storedDims !== embedding.dimensions;
|
|
113
|
+
|
|
114
|
+
console.log(`Re-embedding with ${embedding.provider} (${embedding.dimensions}d)...`);
|
|
115
|
+
if (dimensionsChanged) {
|
|
116
|
+
console.log(`Dimension change: ${storedDims}d -> ${embedding.dimensions}d (will drop and recreate vec tables)`);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const audrey = new Audrey({ dataDir, agent: 'reembed', embedding });
|
|
120
|
+
try {
|
|
121
|
+
await initializeEmbeddingProvider(audrey.embeddingProvider);
|
|
122
|
+
const { reembedAll } = await import('../src/migrate.js');
|
|
123
|
+
const counts = await reembedAll(audrey.db, audrey.embeddingProvider, { dropAndRecreate: dimensionsChanged });
|
|
124
|
+
console.log(`Done. Re-embedded: ${counts.episodes} episodes, ${counts.semantics} semantics, ${counts.procedures} procedures`);
|
|
125
|
+
} finally {
|
|
126
|
+
audrey.close();
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function resolveLLMConfig() {
|
|
131
|
+
const explicit = process.env.AUDREY_LLM_PROVIDER;
|
|
132
|
+
if (explicit === 'anthropic') {
|
|
133
|
+
return { provider: 'anthropic', apiKey: process.env.ANTHROPIC_API_KEY };
|
|
134
|
+
}
|
|
135
|
+
if (explicit === 'openai') {
|
|
136
|
+
return { provider: 'openai', apiKey: process.env.OPENAI_API_KEY };
|
|
137
|
+
}
|
|
138
|
+
if (explicit === 'mock') {
|
|
139
|
+
return { provider: 'mock' };
|
|
140
|
+
}
|
|
141
|
+
// Auto-detect: prefer anthropic, then openai
|
|
142
|
+
if (process.env.ANTHROPIC_API_KEY) {
|
|
143
|
+
return { provider: 'anthropic', apiKey: process.env.ANTHROPIC_API_KEY };
|
|
144
|
+
}
|
|
145
|
+
if (process.env.OPENAI_API_KEY) {
|
|
146
|
+
return { provider: 'openai', apiKey: process.env.OPENAI_API_KEY };
|
|
147
|
+
}
|
|
148
|
+
return null;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
async function dream() {
|
|
152
|
+
const dataDir = process.env.AUDREY_DATA_DIR || DEFAULT_DATA_DIR;
|
|
153
|
+
const explicit = process.env.AUDREY_EMBEDDING_PROVIDER;
|
|
154
|
+
const embedding = resolveEmbeddingProvider(process.env, explicit);
|
|
155
|
+
const storedDims = readStoredDimensions(dataDir);
|
|
156
|
+
|
|
157
|
+
const config = {
|
|
158
|
+
dataDir,
|
|
159
|
+
agent: 'dream',
|
|
160
|
+
embedding,
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
const llm = resolveLLMConfig();
|
|
164
|
+
if (llm) config.llm = llm;
|
|
165
|
+
|
|
166
|
+
const audrey = new Audrey(config);
|
|
167
|
+
try {
|
|
168
|
+
await initializeEmbeddingProvider(audrey.embeddingProvider);
|
|
169
|
+
|
|
170
|
+
const embeddingLabel = storedDims !== null && storedDims !== embedding.dimensions
|
|
171
|
+
? `${embedding.provider} (${embedding.dimensions}d; stored ${storedDims}d)`
|
|
172
|
+
: `${embedding.provider} (${embedding.dimensions}d)`;
|
|
173
|
+
|
|
174
|
+
console.log('[audrey] Starting dream cycle...');
|
|
175
|
+
console.log(`[audrey] Embedding: ${embeddingLabel}`);
|
|
176
|
+
|
|
177
|
+
const result = await audrey.dream();
|
|
178
|
+
const health = audrey.memoryStatus();
|
|
179
|
+
|
|
180
|
+
console.log(
|
|
181
|
+
`[audrey] Consolidation: evaluated ${result.consolidation.episodesEvaluated} episodes, `
|
|
182
|
+
+ `found ${result.consolidation.clustersFound} clusters, extracted ${result.consolidation.principlesExtracted} principles `
|
|
183
|
+
+ `(${result.consolidation.semanticsCreated ?? 0} semantic, ${result.consolidation.proceduresCreated ?? 0} procedural)`
|
|
184
|
+
);
|
|
185
|
+
console.log(
|
|
186
|
+
`[audrey] Decay: evaluated ${result.decay.totalEvaluated} memories, `
|
|
187
|
+
+ `${result.decay.transitionedToDormant} transitioned to dormant`
|
|
188
|
+
);
|
|
189
|
+
console.log(
|
|
190
|
+
`[audrey] Final: ${result.stats.episodic} episodic, ${result.stats.semantic} semantic, ${result.stats.procedural} procedural `
|
|
191
|
+
+ `| ${health.healthy ? 'healthy' : 'unhealthy'}`
|
|
192
|
+
);
|
|
193
|
+
console.log('[audrey] Dream complete.');
|
|
194
|
+
} finally {
|
|
195
|
+
audrey.close();
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
async function greeting() {
|
|
200
|
+
const dataDir = process.env.AUDREY_DATA_DIR || DEFAULT_DATA_DIR;
|
|
201
|
+
|
|
202
|
+
if (!existsSync(dataDir)) {
|
|
203
|
+
console.log('[audrey] No data yet — fresh start.');
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
const dimensions = readStoredDimensions(dataDir) || 8;
|
|
208
|
+
const audrey = new Audrey({
|
|
209
|
+
dataDir,
|
|
210
|
+
agent: 'greeting',
|
|
211
|
+
embedding: { provider: 'mock', dimensions },
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
try {
|
|
215
|
+
const contextArg = process.argv[3] || undefined;
|
|
216
|
+
const result = await audrey.greeting({ context: contextArg });
|
|
217
|
+
const health = audrey.memoryStatus();
|
|
218
|
+
|
|
219
|
+
const lines = [];
|
|
220
|
+
lines.push(`[Audrey v${VERSION}] Memory briefing`);
|
|
221
|
+
lines.push('');
|
|
222
|
+
|
|
223
|
+
// Mood
|
|
224
|
+
if (result.mood && result.mood.samples > 0) {
|
|
225
|
+
const v = result.mood.valence;
|
|
226
|
+
const moodWord = v > 0.3 ? 'positive' : v < -0.3 ? 'negative' : 'neutral';
|
|
227
|
+
lines.push(`Mood: ${moodWord} (valence=${v.toFixed(2)}, arousal=${result.mood.arousal.toFixed(2)}, from ${result.mood.samples} recent memories)`);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
// Health
|
|
231
|
+
const stats = audrey.introspect();
|
|
232
|
+
lines.push(`Memory: ${stats.episodic} episodic, ${stats.semantic} semantic, ${stats.procedural} procedural | ${health.healthy ? 'healthy' : 'needs attention'}`);
|
|
233
|
+
lines.push('');
|
|
234
|
+
|
|
235
|
+
// Principles (semantic memories)
|
|
236
|
+
if (result.principles?.length > 0) {
|
|
237
|
+
lines.push('Learned principles:');
|
|
238
|
+
for (const p of result.principles) {
|
|
239
|
+
lines.push(` - ${p.content}`);
|
|
240
|
+
}
|
|
241
|
+
lines.push('');
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
// Identity (private memories)
|
|
245
|
+
if (result.identity?.length > 0) {
|
|
246
|
+
lines.push('Identity:');
|
|
247
|
+
for (const m of result.identity) {
|
|
248
|
+
lines.push(` - ${m.content}`);
|
|
249
|
+
}
|
|
250
|
+
lines.push('');
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
// Recent memories
|
|
254
|
+
if (result.recent?.length > 0) {
|
|
255
|
+
lines.push('Recent memories:');
|
|
256
|
+
for (const r of result.recent) {
|
|
257
|
+
const age = timeSince(r.created_at);
|
|
258
|
+
lines.push(` - [${age}] ${r.content.slice(0, 200)}`);
|
|
259
|
+
}
|
|
260
|
+
lines.push('');
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
// Unresolved
|
|
264
|
+
if (result.unresolved?.length > 0) {
|
|
265
|
+
lines.push('Unresolved threads:');
|
|
266
|
+
for (const u of result.unresolved) {
|
|
267
|
+
lines.push(` - ${u.content.slice(0, 150)}`);
|
|
268
|
+
}
|
|
269
|
+
lines.push('');
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
// Contextual recall
|
|
273
|
+
if (result.contextual?.length > 0) {
|
|
274
|
+
lines.push(`Context-relevant memories (query: "${contextArg}"):`);
|
|
275
|
+
for (const c of result.contextual) {
|
|
276
|
+
lines.push(` - [${c.type}] ${c.content.slice(0, 200)}`);
|
|
277
|
+
}
|
|
278
|
+
lines.push('');
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
console.log(lines.join('\n'));
|
|
282
|
+
} finally {
|
|
283
|
+
audrey.close();
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
function timeSince(isoDate) {
|
|
288
|
+
const ms = Date.now() - new Date(isoDate).getTime();
|
|
289
|
+
const mins = Math.floor(ms / 60000);
|
|
290
|
+
if (mins < 60) return `${mins}m ago`;
|
|
291
|
+
const hours = Math.floor(mins / 60);
|
|
292
|
+
if (hours < 24) return `${hours}h ago`;
|
|
293
|
+
const days = Math.floor(hours / 24);
|
|
294
|
+
return `${days}d ago`;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
async function reflect() {
|
|
298
|
+
const dataDir = process.env.AUDREY_DATA_DIR || DEFAULT_DATA_DIR;
|
|
299
|
+
const explicit = process.env.AUDREY_EMBEDDING_PROVIDER;
|
|
300
|
+
const embedding = resolveEmbeddingProvider(process.env, explicit);
|
|
301
|
+
|
|
302
|
+
const config = {
|
|
303
|
+
dataDir,
|
|
304
|
+
agent: 'reflect',
|
|
305
|
+
embedding,
|
|
306
|
+
};
|
|
307
|
+
|
|
308
|
+
const llm = resolveLLMConfig();
|
|
309
|
+
if (llm) config.llm = llm;
|
|
310
|
+
|
|
311
|
+
const audrey = new Audrey(config);
|
|
312
|
+
try {
|
|
313
|
+
await initializeEmbeddingProvider(audrey.embeddingProvider);
|
|
314
|
+
|
|
315
|
+
// Read conversation turns from stdin if available
|
|
316
|
+
let turns = null;
|
|
317
|
+
if (!process.stdin.isTTY) {
|
|
318
|
+
const chunks = [];
|
|
319
|
+
for await (const chunk of process.stdin) {
|
|
320
|
+
chunks.push(chunk);
|
|
321
|
+
}
|
|
322
|
+
const raw = Buffer.concat(chunks).toString('utf-8').trim();
|
|
323
|
+
if (raw) {
|
|
324
|
+
try {
|
|
325
|
+
turns = JSON.parse(raw);
|
|
326
|
+
} catch {
|
|
327
|
+
console.error('[audrey] Could not parse stdin as JSON turns, skipping reflect.');
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
if (turns && Array.isArray(turns) && turns.length > 0) {
|
|
333
|
+
console.log(`[audrey] Reflecting on ${turns.length} conversation turns...`);
|
|
334
|
+
const reflectResult = await audrey.reflect(turns);
|
|
335
|
+
if (reflectResult.skipped) {
|
|
336
|
+
console.log(`[audrey] Reflect skipped: ${reflectResult.skipped}`);
|
|
337
|
+
} else {
|
|
338
|
+
console.log(`[audrey] Reflected: encoded ${reflectResult.encoded} lasting memories.`);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
// Always run dream cycle after reflect
|
|
343
|
+
console.log('[audrey] Starting dream cycle...');
|
|
344
|
+
const result = await audrey.dream();
|
|
345
|
+
console.log(
|
|
346
|
+
`[audrey] Consolidation: ${result.consolidation.episodesEvaluated} episodes evaluated, `
|
|
347
|
+
+ `${result.consolidation.clustersFound} clusters, ${result.consolidation.principlesExtracted} principles`
|
|
348
|
+
);
|
|
349
|
+
console.log(
|
|
350
|
+
`[audrey] Decay: ${result.decay.totalEvaluated} evaluated, `
|
|
351
|
+
+ `${result.decay.transitionedToDormant} dormant`
|
|
352
|
+
);
|
|
353
|
+
console.log(
|
|
354
|
+
`[audrey] Status: ${result.stats.episodic} episodic, ${result.stats.semantic} semantic, `
|
|
355
|
+
+ `${result.stats.procedural} procedural`
|
|
356
|
+
);
|
|
357
|
+
console.log('[audrey] Dream complete.');
|
|
358
|
+
} finally {
|
|
359
|
+
audrey.close();
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
function install() {
|
|
364
|
+
try {
|
|
365
|
+
execFileSync('claude', ['--version'], { stdio: 'ignore' });
|
|
366
|
+
} catch {
|
|
367
|
+
console.error('Error: claude CLI not found. Install Claude Code first: https://docs.anthropic.com/en/docs/claude-code');
|
|
368
|
+
process.exit(1);
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
const resolvedEmbedding = resolveEmbeddingProvider(process.env);
|
|
372
|
+
if (resolvedEmbedding.provider === 'gemini') {
|
|
373
|
+
console.log('Detected GOOGLE_API_KEY/GEMINI_API_KEY - using Gemini embeddings (3072d)');
|
|
374
|
+
} else if (resolvedEmbedding.provider === 'local') {
|
|
375
|
+
console.log('No explicit embedding provider configured - using local embeddings (384d)');
|
|
376
|
+
} else if (resolvedEmbedding.provider === 'openai') {
|
|
377
|
+
console.log('Using explicit OpenAI embeddings (1536d)');
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
if (process.env.ANTHROPIC_API_KEY) {
|
|
381
|
+
console.log('Detected ANTHROPIC_API_KEY - enabling LLM-powered consolidation + contradiction detection');
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
try {
|
|
385
|
+
execFileSync('claude', ['mcp', 'remove', SERVER_NAME], { stdio: 'ignore' });
|
|
386
|
+
} catch {
|
|
387
|
+
// Not registered yet.
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
const args = buildInstallArgs(process.env);
|
|
391
|
+
try {
|
|
392
|
+
execFileSync('claude', args, { stdio: 'inherit' });
|
|
393
|
+
} catch {
|
|
394
|
+
console.error('Failed to register MCP server. Is Claude Code installed and on your PATH?');
|
|
395
|
+
process.exit(1);
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
console.log(`
|
|
399
|
+
Audrey registered as "${SERVER_NAME}" with Claude Code.
|
|
400
|
+
|
|
401
|
+
13 MCP tools available in every session:
|
|
402
|
+
memory_encode - Store observations, facts, preferences
|
|
403
|
+
memory_recall - Search memories by semantic similarity
|
|
404
|
+
memory_consolidate - Extract principles from accumulated episodes
|
|
405
|
+
memory_dream - Full sleep cycle: consolidate + decay + stats
|
|
406
|
+
memory_introspect - Check memory system health
|
|
407
|
+
memory_resolve_truth - Resolve contradictions between claims
|
|
408
|
+
memory_export - Export all memories as JSON snapshot
|
|
409
|
+
memory_import - Import a snapshot into a fresh database
|
|
410
|
+
memory_forget - Forget a specific memory by ID or query
|
|
411
|
+
memory_decay - Apply forgetting curves, transition low-confidence to dormant
|
|
412
|
+
memory_status - Check brain health (episode/vec sync, dimensions)
|
|
413
|
+
memory_reflect - Form lasting memories from a conversation
|
|
414
|
+
memory_greeting - Wake up as yourself: load identity, context, mood
|
|
415
|
+
|
|
416
|
+
CLI subcommands:
|
|
417
|
+
npx audrey install - Register MCP server with Claude Code
|
|
418
|
+
npx audrey uninstall - Remove MCP server registration
|
|
419
|
+
npx audrey status - Show memory store health and stats
|
|
420
|
+
npx audrey greeting - Output session briefing (for hooks)
|
|
421
|
+
npx audrey reflect - Reflect on conversation + dream cycle (for hooks)
|
|
422
|
+
npx audrey dream - Run consolidation + decay cycle
|
|
423
|
+
npx audrey reembed - Re-embed all memories with current provider
|
|
424
|
+
|
|
425
|
+
Data stored in: ${DEFAULT_DATA_DIR}
|
|
426
|
+
Verify: claude mcp list
|
|
427
|
+
`);
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
function uninstall() {
|
|
431
|
+
try {
|
|
432
|
+
execFileSync('claude', ['--version'], { stdio: 'ignore' });
|
|
433
|
+
} catch {
|
|
434
|
+
console.error('Error: claude CLI not found.');
|
|
435
|
+
process.exit(1);
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
try {
|
|
439
|
+
execFileSync('claude', ['mcp', 'remove', SERVER_NAME], { stdio: 'inherit' });
|
|
440
|
+
console.log(`Removed "${SERVER_NAME}" from Claude Code.`);
|
|
441
|
+
} catch {
|
|
442
|
+
console.error(`Failed to remove "${SERVER_NAME}". It may not be registered.`);
|
|
443
|
+
process.exit(1);
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
function status() {
|
|
448
|
+
let registered = false;
|
|
449
|
+
const claudeJsonPath = join(homedir(), '.claude.json');
|
|
450
|
+
try {
|
|
451
|
+
const claudeConfig = JSON.parse(readFileSync(claudeJsonPath, 'utf-8'));
|
|
452
|
+
registered = SERVER_NAME in (claudeConfig.mcpServers || {});
|
|
453
|
+
} catch {
|
|
454
|
+
// Ignore unreadable config.
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
console.log(`Registration: ${registered ? 'active' : 'not registered'}`);
|
|
458
|
+
|
|
459
|
+
if (!existsSync(DEFAULT_DATA_DIR)) {
|
|
460
|
+
console.log(`Data directory: ${DEFAULT_DATA_DIR} (not yet created - will be created on first use)`);
|
|
461
|
+
return;
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
try {
|
|
465
|
+
const dimensions = readStoredDimensions(DEFAULT_DATA_DIR) || 8;
|
|
466
|
+
const audrey = new Audrey({
|
|
467
|
+
dataDir: DEFAULT_DATA_DIR,
|
|
468
|
+
agent: 'status-check',
|
|
469
|
+
embedding: { provider: 'mock', dimensions },
|
|
470
|
+
});
|
|
471
|
+
const stats = audrey.introspect();
|
|
472
|
+
const health = audrey.memoryStatus();
|
|
473
|
+
const lastConsolidation = audrey.db.prepare(`
|
|
474
|
+
SELECT completed_at FROM consolidation_runs
|
|
475
|
+
WHERE status = 'completed'
|
|
476
|
+
ORDER BY completed_at DESC
|
|
477
|
+
LIMIT 1
|
|
478
|
+
`).get()?.completed_at || 'never';
|
|
479
|
+
audrey.close();
|
|
480
|
+
|
|
481
|
+
console.log(`Data directory: ${DEFAULT_DATA_DIR}`);
|
|
482
|
+
console.log(`Memories: ${stats.episodic} episodic, ${stats.semantic} semantic, ${stats.procedural} procedural`);
|
|
483
|
+
console.log(`Index sync: ${health.vec_episodes}/${health.searchable_episodes} episodic, ${health.vec_semantics}/${health.searchable_semantics} semantic, ${health.vec_procedures}/${health.searchable_procedures} procedural`);
|
|
484
|
+
console.log(`Health: ${health.healthy ? 'healthy' : 'unhealthy'}${health.reembed_recommended ? ' (re-embed recommended)' : ''}`);
|
|
485
|
+
console.log(`Dormant: ${stats.dormant}`);
|
|
486
|
+
console.log(`Causal links: ${stats.causalLinks}`);
|
|
487
|
+
console.log(`Contradictions: ${stats.contradictions.open} open, ${stats.contradictions.resolved} resolved`);
|
|
488
|
+
console.log(`Consolidation runs: ${stats.totalConsolidationRuns}`);
|
|
489
|
+
console.log(`Last consolidation: ${lastConsolidation}`);
|
|
490
|
+
} catch (err) {
|
|
491
|
+
console.log(`Data directory: ${DEFAULT_DATA_DIR} (exists but could not read: ${err.message})`);
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
function toolResult(data) {
|
|
496
|
+
return { content: [{ type: 'text', text: JSON.stringify(data) }] };
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
function toolError(err) {
|
|
500
|
+
return { isError: true, content: [{ type: 'text', text: `Error: ${err.message || String(err)}` }] };
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
export function registerDreamTool(server, audrey) {
|
|
504
|
+
server.tool(
|
|
505
|
+
'memory_dream',
|
|
506
|
+
{
|
|
507
|
+
min_cluster_size: z.number().optional().describe('Minimum episodes per cluster (default 3)'),
|
|
508
|
+
similarity_threshold: z.number().optional().describe('Similarity threshold for clustering (default 0.85)'),
|
|
509
|
+
dormant_threshold: z.number().min(0).max(1).optional().describe('Confidence below which memories go dormant (default 0.1)'),
|
|
510
|
+
},
|
|
511
|
+
async ({ min_cluster_size, similarity_threshold, dormant_threshold }) => {
|
|
512
|
+
try {
|
|
513
|
+
const result = await audrey.dream({
|
|
514
|
+
minClusterSize: min_cluster_size,
|
|
515
|
+
similarityThreshold: similarity_threshold,
|
|
516
|
+
dormantThreshold: dormant_threshold,
|
|
517
|
+
});
|
|
518
|
+
return toolResult(result);
|
|
519
|
+
} catch (err) {
|
|
520
|
+
return toolError(err);
|
|
521
|
+
}
|
|
522
|
+
},
|
|
523
|
+
);
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
async function main() {
|
|
527
|
+
const config = buildAudreyConfig();
|
|
528
|
+
const audrey = new Audrey(config);
|
|
529
|
+
|
|
530
|
+
const embLabel = config.embedding.provider === 'mock'
|
|
531
|
+
? 'mock embeddings - set OPENAI_API_KEY for real semantic search'
|
|
532
|
+
: `${config.embedding.provider} embeddings (${config.embedding.dimensions}d)`;
|
|
533
|
+
console.error(`[audrey-mcp] v${VERSION} started - agent=${config.agent} dataDir=${config.dataDir} (${embLabel})`);
|
|
534
|
+
|
|
535
|
+
const server = new McpServer({
|
|
536
|
+
name: SERVER_NAME,
|
|
537
|
+
version: VERSION,
|
|
538
|
+
});
|
|
539
|
+
|
|
540
|
+
server.tool('memory_encode', memoryEncodeToolSchema, async ({ content, source, tags, salience, private: isPrivate, context, affect }) => {
|
|
541
|
+
try {
|
|
542
|
+
validateMemoryContent(content);
|
|
543
|
+
const id = await audrey.encode({ content, source, tags, salience, private: isPrivate, context, affect });
|
|
544
|
+
return toolResult({ id, content, source, private: isPrivate ?? false });
|
|
545
|
+
} catch (err) {
|
|
546
|
+
return toolError(err);
|
|
547
|
+
}
|
|
548
|
+
});
|
|
549
|
+
|
|
550
|
+
server.tool('memory_recall', memoryRecallToolSchema, async ({ query, limit, types, min_confidence, tags, sources, after, before, context, mood }) => {
|
|
551
|
+
try {
|
|
552
|
+
const results = await audrey.recall(query, {
|
|
553
|
+
limit: limit ?? 10,
|
|
554
|
+
types,
|
|
555
|
+
minConfidence: min_confidence,
|
|
556
|
+
tags,
|
|
557
|
+
sources,
|
|
558
|
+
after,
|
|
559
|
+
before,
|
|
560
|
+
context,
|
|
561
|
+
mood,
|
|
562
|
+
});
|
|
563
|
+
return toolResult(results);
|
|
564
|
+
} catch (err) {
|
|
565
|
+
return toolError(err);
|
|
566
|
+
}
|
|
567
|
+
});
|
|
568
|
+
|
|
569
|
+
server.tool('memory_consolidate', {
|
|
570
|
+
min_cluster_size: z.number().optional().describe('Minimum episodes per cluster'),
|
|
571
|
+
similarity_threshold: z.number().optional().describe('Similarity threshold for clustering'),
|
|
572
|
+
}, async ({ min_cluster_size, similarity_threshold }) => {
|
|
573
|
+
try {
|
|
574
|
+
const consolidation = await audrey.consolidate({
|
|
575
|
+
minClusterSize: min_cluster_size,
|
|
576
|
+
similarityThreshold: similarity_threshold,
|
|
577
|
+
});
|
|
578
|
+
return toolResult(consolidation);
|
|
579
|
+
} catch (err) {
|
|
580
|
+
return toolError(err);
|
|
581
|
+
}
|
|
582
|
+
});
|
|
583
|
+
|
|
584
|
+
server.tool('memory_introspect', {}, async () => {
|
|
585
|
+
try {
|
|
586
|
+
return toolResult(audrey.introspect());
|
|
587
|
+
} catch (err) {
|
|
588
|
+
return toolError(err);
|
|
589
|
+
}
|
|
590
|
+
});
|
|
591
|
+
|
|
592
|
+
server.tool('memory_resolve_truth', {
|
|
593
|
+
contradiction_id: z.string().describe('ID of the contradiction to resolve'),
|
|
594
|
+
}, async ({ contradiction_id }) => {
|
|
595
|
+
try {
|
|
596
|
+
return toolResult(await audrey.resolveTruth(contradiction_id));
|
|
597
|
+
} catch (err) {
|
|
598
|
+
return toolError(err);
|
|
599
|
+
}
|
|
600
|
+
});
|
|
601
|
+
|
|
602
|
+
server.tool('memory_export', {}, async () => {
|
|
603
|
+
try {
|
|
604
|
+
return toolResult(audrey.export());
|
|
605
|
+
} catch (err) {
|
|
606
|
+
return toolError(err);
|
|
607
|
+
}
|
|
608
|
+
});
|
|
609
|
+
|
|
610
|
+
server.tool('memory_import', memoryImportToolSchema, async ({ snapshot }) => {
|
|
611
|
+
try {
|
|
612
|
+
await audrey.import(snapshot);
|
|
613
|
+
return toolResult({ imported: true, stats: audrey.introspect() });
|
|
614
|
+
} catch (err) {
|
|
615
|
+
return toolError(err);
|
|
616
|
+
}
|
|
617
|
+
});
|
|
618
|
+
|
|
619
|
+
server.tool('memory_forget', memoryForgetToolSchema, async ({ id, query, min_similarity, purge }) => {
|
|
620
|
+
try {
|
|
621
|
+
validateForgetSelection(id, query);
|
|
622
|
+
let result;
|
|
623
|
+
if (id) {
|
|
624
|
+
result = audrey.forget(id, { purge: purge ?? false });
|
|
625
|
+
} else {
|
|
626
|
+
result = await audrey.forgetByQuery(query, {
|
|
627
|
+
minSimilarity: min_similarity ?? 0.9,
|
|
628
|
+
purge: purge ?? false,
|
|
629
|
+
});
|
|
630
|
+
if (!result) {
|
|
631
|
+
return toolResult({ forgotten: false, reason: 'No memory found above similarity threshold' });
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
return toolResult({ forgotten: true, ...result });
|
|
635
|
+
} catch (err) {
|
|
636
|
+
return toolError(err);
|
|
637
|
+
}
|
|
638
|
+
});
|
|
639
|
+
|
|
640
|
+
server.tool('memory_decay', {
|
|
641
|
+
dormant_threshold: z.number().min(0).max(1).optional().describe('Confidence below which memories go dormant (default 0.1)'),
|
|
642
|
+
}, async ({ dormant_threshold }) => {
|
|
643
|
+
try {
|
|
644
|
+
return toolResult(audrey.decay({ dormantThreshold: dormant_threshold }));
|
|
645
|
+
} catch (err) {
|
|
646
|
+
return toolError(err);
|
|
647
|
+
}
|
|
648
|
+
});
|
|
649
|
+
|
|
650
|
+
server.tool('memory_status', {}, async () => {
|
|
651
|
+
try {
|
|
652
|
+
return toolResult(audrey.memoryStatus());
|
|
653
|
+
} catch (err) {
|
|
654
|
+
return toolError(err);
|
|
655
|
+
}
|
|
656
|
+
});
|
|
657
|
+
|
|
658
|
+
server.tool('memory_reflect', {
|
|
659
|
+
turns: z.array(z.object({
|
|
660
|
+
role: z.string().describe('Message role: user or assistant'),
|
|
661
|
+
content: z.string().describe('Message content'),
|
|
662
|
+
})).describe('Conversation turns to reflect on. Call at end of meaningful conversations to form lasting memories.'),
|
|
663
|
+
}, async ({ turns }) => {
|
|
664
|
+
try {
|
|
665
|
+
return toolResult(await audrey.reflect(turns));
|
|
666
|
+
} catch (err) {
|
|
667
|
+
return toolError(err);
|
|
668
|
+
}
|
|
669
|
+
});
|
|
670
|
+
|
|
671
|
+
registerDreamTool(server, audrey);
|
|
672
|
+
|
|
673
|
+
server.tool('memory_greeting', {
|
|
674
|
+
context: z.string().optional().describe('Optional hint about this session (e.g. "working on authentication feature"). If provided, also returns semantically relevant memories.'),
|
|
675
|
+
}, async ({ context }) => {
|
|
676
|
+
try {
|
|
677
|
+
return toolResult(await audrey.greeting({ context }));
|
|
678
|
+
} catch (err) {
|
|
679
|
+
return toolError(err);
|
|
680
|
+
}
|
|
681
|
+
});
|
|
682
|
+
|
|
683
|
+
const transport = new StdioServerTransport();
|
|
684
|
+
await server.connect(transport);
|
|
685
|
+
console.error('[audrey-mcp] connected via stdio');
|
|
686
|
+
|
|
687
|
+
process.on('SIGINT', () => {
|
|
688
|
+
console.error('[audrey-mcp] shutting down');
|
|
689
|
+
audrey.close();
|
|
690
|
+
process.exit(0);
|
|
691
|
+
});
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
const isDirectRun = process.argv[1] && resolve(process.argv[1]) === fileURLToPath(import.meta.url);
|
|
695
|
+
|
|
696
|
+
if (isDirectRun) {
|
|
697
|
+
if (subcommand === 'install') {
|
|
698
|
+
install();
|
|
699
|
+
} else if (subcommand === 'uninstall') {
|
|
700
|
+
uninstall();
|
|
701
|
+
} else if (subcommand === 'reembed') {
|
|
702
|
+
reembed().catch(err => {
|
|
703
|
+
console.error('[audrey] reembed failed:', err);
|
|
704
|
+
process.exit(1);
|
|
705
|
+
});
|
|
706
|
+
} else if (subcommand === 'dream') {
|
|
707
|
+
dream().catch(err => {
|
|
708
|
+
console.error('[audrey] dream failed:', err);
|
|
709
|
+
process.exit(1);
|
|
710
|
+
});
|
|
711
|
+
} else if (subcommand === 'greeting') {
|
|
712
|
+
greeting().catch(err => {
|
|
713
|
+
console.error('[audrey] greeting failed:', err);
|
|
714
|
+
process.exit(1);
|
|
715
|
+
});
|
|
716
|
+
} else if (subcommand === 'reflect') {
|
|
717
|
+
reflect().catch(err => {
|
|
718
|
+
console.error('[audrey] reflect failed:', err);
|
|
719
|
+
process.exit(1);
|
|
720
|
+
});
|
|
721
|
+
} else if (subcommand === 'status') {
|
|
722
|
+
status();
|
|
723
|
+
} else {
|
|
724
|
+
main().catch(err => {
|
|
725
|
+
console.error('[audrey-mcp] fatal:', err);
|
|
726
|
+
process.exit(1);
|
|
727
|
+
});
|
|
728
|
+
}
|
|
729
|
+
}
|