audrey 0.17.0 → 0.20.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/README.md +129 -374
- package/dist/mcp-server/config.d.ts +20 -0
- package/dist/mcp-server/config.d.ts.map +1 -0
- package/dist/mcp-server/config.js +125 -0
- package/dist/mcp-server/config.js.map +1 -0
- package/dist/mcp-server/index.d.ts +100 -0
- package/dist/mcp-server/index.d.ts.map +1 -0
- package/dist/mcp-server/index.js +1113 -0
- package/dist/mcp-server/index.js.map +1 -0
- package/dist/src/adaptive.d.ts +7 -0
- package/dist/src/adaptive.d.ts.map +1 -0
- package/dist/src/adaptive.js +49 -0
- package/dist/src/adaptive.js.map +1 -0
- package/dist/src/affect.d.ts +19 -0
- package/dist/src/affect.d.ts.map +1 -0
- package/dist/src/affect.js +72 -0
- package/dist/src/affect.js.map +1 -0
- package/dist/src/audrey.d.ts +140 -0
- package/dist/src/audrey.d.ts.map +1 -0
- package/dist/src/audrey.js +564 -0
- package/dist/src/audrey.js.map +1 -0
- package/dist/src/capsule.d.ts +68 -0
- package/dist/src/capsule.d.ts.map +1 -0
- package/dist/src/capsule.js +311 -0
- package/dist/src/capsule.js.map +1 -0
- package/dist/src/causal.d.ts +28 -0
- package/dist/src/causal.d.ts.map +1 -0
- package/dist/src/causal.js +65 -0
- package/dist/src/causal.js.map +1 -0
- package/dist/src/confidence.d.ts +12 -0
- package/dist/src/confidence.d.ts.map +1 -0
- package/dist/src/confidence.js +63 -0
- package/dist/src/confidence.js.map +1 -0
- package/dist/src/consolidate.d.ts +8 -0
- package/dist/src/consolidate.d.ts.map +1 -0
- package/dist/src/consolidate.js +218 -0
- package/dist/src/consolidate.js.map +1 -0
- package/dist/src/context.d.ts +3 -0
- package/dist/src/context.d.ts.map +1 -0
- package/dist/src/context.js +19 -0
- package/dist/src/context.js.map +1 -0
- package/dist/src/db.d.ts +12 -0
- package/dist/src/db.d.ts.map +1 -0
- package/dist/src/db.js +380 -0
- package/dist/src/db.js.map +1 -0
- package/dist/src/decay.d.ts +7 -0
- package/dist/src/decay.d.ts.map +1 -0
- package/dist/src/decay.js +68 -0
- package/dist/src/decay.js.map +1 -0
- package/dist/src/embedding.d.ts +57 -0
- package/dist/src/embedding.d.ts.map +1 -0
- package/dist/src/embedding.js +254 -0
- package/dist/src/embedding.js.map +1 -0
- package/dist/src/encode.d.ts +15 -0
- package/dist/src/encode.d.ts.map +1 -0
- package/dist/src/encode.js +36 -0
- package/dist/src/encode.js.map +1 -0
- package/dist/src/events.d.ts +69 -0
- package/dist/src/events.d.ts.map +1 -0
- package/dist/src/events.js +149 -0
- package/dist/src/events.js.map +1 -0
- package/dist/src/export.d.ts +3 -0
- package/dist/src/export.d.ts.map +1 -0
- package/dist/src/export.js +46 -0
- package/dist/src/export.js.map +1 -0
- package/dist/src/forget.d.ts +11 -0
- package/dist/src/forget.d.ts.map +1 -0
- package/dist/src/forget.js +105 -0
- package/dist/src/forget.js.map +1 -0
- package/dist/src/fts.d.ts +34 -0
- package/dist/src/fts.d.ts.map +1 -0
- package/dist/src/fts.js +117 -0
- package/dist/src/fts.js.map +1 -0
- package/dist/src/hybrid-recall.d.ts +37 -0
- package/dist/src/hybrid-recall.d.ts.map +1 -0
- package/dist/src/hybrid-recall.js +213 -0
- package/dist/src/hybrid-recall.js.map +1 -0
- package/dist/src/import.d.ts +4 -0
- package/dist/src/import.d.ts.map +1 -0
- package/dist/src/import.js +127 -0
- package/dist/src/import.js.map +1 -0
- package/dist/src/index.d.ts +22 -0
- package/dist/src/index.d.ts.map +1 -0
- package/{src → dist/src}/index.js +5 -13
- package/dist/src/index.js.map +1 -0
- package/dist/src/interference.d.ts +13 -0
- package/dist/src/interference.d.ts.map +1 -0
- package/dist/src/interference.js +45 -0
- package/dist/src/interference.js.map +1 -0
- package/dist/src/introspect.d.ts +4 -0
- package/dist/src/introspect.d.ts.map +1 -0
- package/dist/src/introspect.js +40 -0
- package/dist/src/introspect.js.map +1 -0
- package/dist/src/llm.d.ts +38 -0
- package/dist/src/llm.d.ts.map +1 -0
- package/dist/src/llm.js +167 -0
- package/dist/src/llm.js.map +1 -0
- package/dist/src/migrate.d.ts +6 -0
- package/dist/src/migrate.d.ts.map +1 -0
- package/dist/src/migrate.js +51 -0
- package/dist/src/migrate.js.map +1 -0
- package/dist/src/promote.d.ts +40 -0
- package/dist/src/promote.d.ts.map +1 -0
- package/dist/src/promote.js +200 -0
- package/dist/src/promote.js.map +1 -0
- package/dist/src/prompts.d.ts +16 -0
- package/dist/src/prompts.d.ts.map +1 -0
- package/{src → dist/src}/prompts.js +172 -203
- package/dist/src/prompts.js.map +1 -0
- package/dist/src/recall.d.ts +9 -0
- package/dist/src/recall.d.ts.map +1 -0
- package/dist/src/recall.js +432 -0
- package/dist/src/recall.js.map +1 -0
- package/dist/src/redact.d.ts +27 -0
- package/dist/src/redact.d.ts.map +1 -0
- package/dist/src/redact.js +228 -0
- package/dist/src/redact.js.map +1 -0
- package/dist/src/rollback.d.ts +8 -0
- package/dist/src/rollback.d.ts.map +1 -0
- package/dist/src/rollback.js +33 -0
- package/dist/src/rollback.js.map +1 -0
- package/dist/src/routes.d.ts +7 -0
- package/dist/src/routes.d.ts.map +1 -0
- package/dist/src/routes.js +226 -0
- package/dist/src/routes.js.map +1 -0
- package/dist/src/rules-compiler.d.ts +20 -0
- package/dist/src/rules-compiler.d.ts.map +1 -0
- package/dist/src/rules-compiler.js +143 -0
- package/dist/src/rules-compiler.js.map +1 -0
- package/dist/src/server.d.ts +12 -0
- package/dist/src/server.d.ts.map +1 -0
- package/dist/src/server.js +22 -0
- package/dist/src/server.js.map +1 -0
- package/dist/src/tool-trace.d.ts +37 -0
- package/dist/src/tool-trace.d.ts.map +1 -0
- package/dist/src/tool-trace.js +142 -0
- package/dist/src/tool-trace.js.map +1 -0
- package/dist/src/types.d.ts +446 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js +6 -0
- package/dist/src/types.js.map +1 -0
- package/dist/src/ulid.d.ts +3 -0
- package/dist/src/ulid.d.ts.map +1 -0
- package/dist/src/ulid.js +11 -0
- package/dist/src/ulid.js.map +1 -0
- package/dist/src/utils.d.ts +10 -0
- package/dist/src/utils.d.ts.map +1 -0
- package/dist/src/utils.js +41 -0
- package/dist/src/utils.js.map +1 -0
- package/dist/src/validate.d.ts +22 -0
- package/dist/src/validate.d.ts.map +1 -0
- package/dist/src/validate.js +109 -0
- package/dist/src/validate.js.map +1 -0
- package/docs/production-readiness.md +28 -0
- package/examples/fintech-ops-demo.js +1 -1
- package/examples/healthcare-ops-demo.js +1 -1
- package/examples/stripe-demo.js +1 -1
- package/package.json +34 -13
- package/benchmarks/baselines.js +0 -169
- package/benchmarks/cases.js +0 -421
- package/benchmarks/reference-results.js +0 -70
- package/benchmarks/report.js +0 -255
- package/benchmarks/run.js +0 -514
- package/mcp-server/config.js +0 -133
- package/mcp-server/index.js +0 -1265
- package/mcp-server/serve.js +0 -482
- package/src/adaptive.js +0 -53
- package/src/affect.js +0 -64
- package/src/audrey.js +0 -642
- package/src/causal.js +0 -95
- package/src/confidence.js +0 -120
- package/src/consolidate.js +0 -281
- package/src/context.js +0 -15
- package/src/db.js +0 -391
- package/src/decay.js +0 -84
- package/src/embedding.js +0 -260
- package/src/encode.js +0 -69
- package/src/export.js +0 -67
- package/src/forget.js +0 -111
- package/src/fts.js +0 -134
- package/src/import.js +0 -273
- package/src/interference.js +0 -51
- package/src/introspect.js +0 -48
- package/src/llm.js +0 -249
- package/src/migrate.js +0 -58
- package/src/recall.js +0 -573
- package/src/rollback.js +0 -42
- package/src/ulid.js +0 -18
- package/src/utils.js +0 -63
- package/src/validate.js +0 -172
- package/types/index.d.ts +0 -434
|
@@ -0,0 +1,1113 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { homedir } from 'node:os';
|
|
4
|
+
import { join, resolve } from 'node:path';
|
|
5
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
6
|
+
import { execFileSync } from 'node:child_process';
|
|
7
|
+
import { fileURLToPath } from 'node:url';
|
|
8
|
+
import { Audrey } from '../src/index.js';
|
|
9
|
+
import { readStoredDimensions } from '../src/db.js';
|
|
10
|
+
import { VERSION, SERVER_NAME, buildAudreyConfig, buildInstallArgs, resolveDataDir, resolveEmbeddingProvider, resolveLLMProvider, } from './config.js';
|
|
11
|
+
const VALID_SOURCES = {
|
|
12
|
+
'direct-observation': 'direct-observation',
|
|
13
|
+
'told-by-user': 'told-by-user',
|
|
14
|
+
'tool-result': 'tool-result',
|
|
15
|
+
'inference': 'inference',
|
|
16
|
+
'model-generated': 'model-generated',
|
|
17
|
+
};
|
|
18
|
+
const VALID_TYPES = {
|
|
19
|
+
'episodic': 'episodic',
|
|
20
|
+
'semantic': 'semantic',
|
|
21
|
+
'procedural': 'procedural',
|
|
22
|
+
};
|
|
23
|
+
export const MAX_MEMORY_CONTENT_LENGTH = 50_000;
|
|
24
|
+
const subcommand = process.argv[2];
|
|
25
|
+
function isNonEmptyText(value) {
|
|
26
|
+
return typeof value === 'string' && value.trim().length > 0;
|
|
27
|
+
}
|
|
28
|
+
export function validateMemoryContent(content) {
|
|
29
|
+
if (!isNonEmptyText(content)) {
|
|
30
|
+
throw new Error('content must be a non-empty string');
|
|
31
|
+
}
|
|
32
|
+
if (content.length > MAX_MEMORY_CONTENT_LENGTH) {
|
|
33
|
+
throw new Error(`content exceeds maximum length of ${MAX_MEMORY_CONTENT_LENGTH} characters`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
export function validateForgetSelection(id, query) {
|
|
37
|
+
if ((id && query) || (!id && !query)) {
|
|
38
|
+
throw new Error('Provide exactly one of id or query');
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
export async function initializeEmbeddingProvider(provider) {
|
|
42
|
+
if (provider && typeof provider.ready === 'function') {
|
|
43
|
+
await provider.ready();
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
export const memoryEncodeToolSchema = {
|
|
47
|
+
content: z.string()
|
|
48
|
+
.max(MAX_MEMORY_CONTENT_LENGTH)
|
|
49
|
+
.refine(isNonEmptyText, 'Content must not be empty')
|
|
50
|
+
.describe('The memory content to encode'),
|
|
51
|
+
source: z.enum(VALID_SOURCES).describe('Source type of the memory'),
|
|
52
|
+
tags: z.array(z.string()).optional().describe('Optional tags for categorization'),
|
|
53
|
+
salience: z.number().min(0).max(1).optional().describe('Importance weight 0-1'),
|
|
54
|
+
context: z.record(z.string(), z.string()).optional().describe('Situational context as key-value pairs (e.g., {task: "debugging", domain: "payments"})'),
|
|
55
|
+
affect: z.object({
|
|
56
|
+
valence: z.number().min(-1).max(1).describe('Emotional valence: -1 (very negative) to 1 (very positive)'),
|
|
57
|
+
arousal: z.number().min(0).max(1).optional().describe('Emotional arousal: 0 (calm) to 1 (highly activated)'),
|
|
58
|
+
label: z.string().optional().describe('Human-readable emotion label (e.g., "curiosity", "frustration", "relief")'),
|
|
59
|
+
}).optional().describe('Emotional affect - how this memory feels'),
|
|
60
|
+
private: z.boolean().optional().describe('If true, memory is only visible to the AI and excluded from public recall results'),
|
|
61
|
+
};
|
|
62
|
+
export const memoryRecallToolSchema = {
|
|
63
|
+
query: z.string().describe('Search query to match against memories'),
|
|
64
|
+
limit: z.number().min(1).max(50).optional().describe('Max results (default 10)'),
|
|
65
|
+
types: z.array(z.enum(VALID_TYPES)).optional().describe('Memory types to search'),
|
|
66
|
+
min_confidence: z.number().min(0).max(1).optional().describe('Minimum confidence threshold'),
|
|
67
|
+
tags: z.array(z.string()).optional().describe('Only return episodic memories with these tags'),
|
|
68
|
+
sources: z.array(z.enum(VALID_SOURCES)).optional().describe('Only return episodic memories from these sources'),
|
|
69
|
+
after: z.string().optional().describe('Only return memories created after this ISO date'),
|
|
70
|
+
before: z.string().optional().describe('Only return memories created before this ISO date'),
|
|
71
|
+
context: z.record(z.string(), z.string()).optional().describe('Retrieval context - memories encoded in matching context get boosted'),
|
|
72
|
+
mood: z.object({
|
|
73
|
+
valence: z.number().min(-1).max(1).describe('Current emotional valence: -1 (negative) to 1 (positive)'),
|
|
74
|
+
arousal: z.number().min(0).max(1).optional().describe('Current arousal: 0 (calm) to 1 (activated)'),
|
|
75
|
+
}).optional().describe('Current mood - boosts recall of memories encoded in similar emotional state'),
|
|
76
|
+
};
|
|
77
|
+
export const memoryImportToolSchema = {
|
|
78
|
+
snapshot: z.object({
|
|
79
|
+
version: z.string(),
|
|
80
|
+
episodes: z.array(z.any()),
|
|
81
|
+
semantics: z.array(z.any()).optional(),
|
|
82
|
+
procedures: z.array(z.any()).optional(),
|
|
83
|
+
causalLinks: z.array(z.any()).optional(),
|
|
84
|
+
contradictions: z.array(z.any()).optional(),
|
|
85
|
+
consolidationRuns: z.array(z.any()).optional(),
|
|
86
|
+
consolidationMetrics: z.array(z.any()).optional(),
|
|
87
|
+
config: z.record(z.string(), z.string()).optional(),
|
|
88
|
+
}).passthrough().describe('A snapshot from memory_export'),
|
|
89
|
+
};
|
|
90
|
+
export const memoryForgetToolSchema = {
|
|
91
|
+
id: z.string().optional().describe('ID of the memory to forget'),
|
|
92
|
+
query: z.string().optional().describe('Semantic query to find and forget the closest matching memory'),
|
|
93
|
+
min_similarity: z.number().min(0).max(1).optional().describe('Minimum similarity for query-based forget (default 0.9)'),
|
|
94
|
+
purge: z.boolean().optional().describe('Hard-delete the memory permanently (default false, soft-delete)'),
|
|
95
|
+
};
|
|
96
|
+
// ---------------------------------------------------------------------------
|
|
97
|
+
// CLI subcommands
|
|
98
|
+
// ---------------------------------------------------------------------------
|
|
99
|
+
async function serveHttp() {
|
|
100
|
+
const { startServer } = await import('../src/server.js');
|
|
101
|
+
const config = buildAudreyConfig();
|
|
102
|
+
const port = parseInt(process.env.AUDREY_PORT || '7437', 10);
|
|
103
|
+
const apiKey = process.env.AUDREY_API_KEY;
|
|
104
|
+
const server = await startServer({ port, config, apiKey });
|
|
105
|
+
console.error(`[audrey-http] v${VERSION} serving on port ${server.port}`);
|
|
106
|
+
if (apiKey) {
|
|
107
|
+
console.error('[audrey-http] API key authentication enabled');
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
async function reembed() {
|
|
111
|
+
const dataDir = resolveDataDir(process.env);
|
|
112
|
+
const explicit = process.env['AUDREY_EMBEDDING_PROVIDER'];
|
|
113
|
+
const embedding = resolveEmbeddingProvider(process.env, explicit);
|
|
114
|
+
const storedDims = readStoredDimensions(dataDir);
|
|
115
|
+
const dimensionsChanged = storedDims !== null && storedDims !== embedding.dimensions;
|
|
116
|
+
console.log(`Re-embedding with ${embedding.provider} (${embedding.dimensions}d)...`);
|
|
117
|
+
if (dimensionsChanged) {
|
|
118
|
+
console.log(`Dimension change: ${storedDims}d -> ${embedding.dimensions}d (will drop and recreate vec tables)`);
|
|
119
|
+
}
|
|
120
|
+
const audrey = new Audrey({ dataDir, agent: 'reembed', embedding });
|
|
121
|
+
try {
|
|
122
|
+
await initializeEmbeddingProvider(audrey.embeddingProvider);
|
|
123
|
+
const { reembedAll } = await import('../src/migrate.js');
|
|
124
|
+
const counts = await reembedAll(audrey.db, audrey.embeddingProvider, { dropAndRecreate: dimensionsChanged });
|
|
125
|
+
console.log(`Done. Re-embedded: ${counts.episodes} episodes, ${counts.semantics} semantics, ${counts.procedures} procedures`);
|
|
126
|
+
}
|
|
127
|
+
finally {
|
|
128
|
+
audrey.close();
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
async function dream() {
|
|
132
|
+
const dataDir = resolveDataDir(process.env);
|
|
133
|
+
const explicit = process.env['AUDREY_EMBEDDING_PROVIDER'];
|
|
134
|
+
const embedding = resolveEmbeddingProvider(process.env, explicit);
|
|
135
|
+
const storedDims = readStoredDimensions(dataDir);
|
|
136
|
+
const config = {
|
|
137
|
+
dataDir,
|
|
138
|
+
agent: 'dream',
|
|
139
|
+
embedding,
|
|
140
|
+
};
|
|
141
|
+
const llm = resolveLLMProvider(process.env, process.env['AUDREY_LLM_PROVIDER']);
|
|
142
|
+
if (llm)
|
|
143
|
+
config.llm = llm;
|
|
144
|
+
const audrey = new Audrey(config);
|
|
145
|
+
try {
|
|
146
|
+
await initializeEmbeddingProvider(audrey.embeddingProvider);
|
|
147
|
+
const embeddingLabel = storedDims !== null && storedDims !== embedding.dimensions
|
|
148
|
+
? `${embedding.provider} (${embedding.dimensions}d; stored ${storedDims}d)`
|
|
149
|
+
: `${embedding.provider} (${embedding.dimensions}d)`;
|
|
150
|
+
console.log('[audrey] Starting dream cycle...');
|
|
151
|
+
console.log(`[audrey] Embedding: ${embeddingLabel}`);
|
|
152
|
+
const result = await audrey.dream();
|
|
153
|
+
const health = audrey.memoryStatus();
|
|
154
|
+
console.log(`[audrey] Consolidation: evaluated ${result.consolidation.episodesEvaluated} episodes, `
|
|
155
|
+
+ `found ${result.consolidation.clustersFound} clusters, extracted ${result.consolidation.principlesExtracted} principles `
|
|
156
|
+
+ `(${result.consolidation.semanticsCreated ?? 0} semantic, ${result.consolidation.proceduresCreated ?? 0} procedural)`);
|
|
157
|
+
console.log(`[audrey] Decay: evaluated ${result.decay.totalEvaluated} memories, `
|
|
158
|
+
+ `${result.decay.transitionedToDormant} transitioned to dormant`);
|
|
159
|
+
console.log(`[audrey] Final: ${result.stats.episodic} episodic, ${result.stats.semantic} semantic, ${result.stats.procedural} procedural `
|
|
160
|
+
+ `| ${health.healthy ? 'healthy' : 'unhealthy'}`);
|
|
161
|
+
console.log('[audrey] Dream complete.');
|
|
162
|
+
}
|
|
163
|
+
finally {
|
|
164
|
+
audrey.close();
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
async function greeting() {
|
|
168
|
+
const dataDir = resolveDataDir(process.env);
|
|
169
|
+
const contextArg = process.argv[3] || undefined;
|
|
170
|
+
if (!existsSync(dataDir)) {
|
|
171
|
+
console.log('[audrey] No data yet - fresh start.');
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
const storedDimensions = readStoredDimensions(dataDir);
|
|
175
|
+
const resolvedEmbedding = resolveEmbeddingProvider(process.env, process.env['AUDREY_EMBEDDING_PROVIDER']);
|
|
176
|
+
const canUseResolvedEmbedding = Boolean(contextArg)
|
|
177
|
+
&& storedDimensions !== null
|
|
178
|
+
&& storedDimensions === resolvedEmbedding.dimensions;
|
|
179
|
+
const dimensions = storedDimensions || resolvedEmbedding.dimensions || 8;
|
|
180
|
+
const audrey = new Audrey({
|
|
181
|
+
dataDir,
|
|
182
|
+
agent: 'greeting',
|
|
183
|
+
embedding: canUseResolvedEmbedding
|
|
184
|
+
? resolvedEmbedding
|
|
185
|
+
: { provider: 'mock', dimensions },
|
|
186
|
+
});
|
|
187
|
+
try {
|
|
188
|
+
if (canUseResolvedEmbedding) {
|
|
189
|
+
await initializeEmbeddingProvider(audrey.embeddingProvider);
|
|
190
|
+
}
|
|
191
|
+
const result = await audrey.greeting({ context: canUseResolvedEmbedding ? contextArg : undefined });
|
|
192
|
+
const health = audrey.memoryStatus();
|
|
193
|
+
const lines = [];
|
|
194
|
+
lines.push(`[Audrey v${VERSION}] Memory briefing`);
|
|
195
|
+
lines.push('');
|
|
196
|
+
if (contextArg && !canUseResolvedEmbedding) {
|
|
197
|
+
lines.push(`Context recall skipped: stored index is ${storedDimensions ?? 'unknown'}d `
|
|
198
|
+
+ `but current embedding config resolves to ${resolvedEmbedding.dimensions}d.`);
|
|
199
|
+
lines.push('');
|
|
200
|
+
}
|
|
201
|
+
// Mood
|
|
202
|
+
if (result.mood && result.mood.samples > 0) {
|
|
203
|
+
const v = result.mood.valence;
|
|
204
|
+
const moodWord = v > 0.3 ? 'positive' : v < -0.3 ? 'negative' : 'neutral';
|
|
205
|
+
lines.push(`Mood: ${moodWord} (valence=${v.toFixed(2)}, arousal=${result.mood.arousal.toFixed(2)}, from ${result.mood.samples} recent memories)`);
|
|
206
|
+
}
|
|
207
|
+
// Health
|
|
208
|
+
const stats = audrey.introspect();
|
|
209
|
+
lines.push(`Memory: ${stats.episodic} episodic, ${stats.semantic} semantic, ${stats.procedural} procedural | ${health.healthy ? 'healthy' : 'needs attention'}`);
|
|
210
|
+
lines.push('');
|
|
211
|
+
// Principles (semantic memories)
|
|
212
|
+
if (result.principles?.length > 0) {
|
|
213
|
+
lines.push('Learned principles:');
|
|
214
|
+
for (const p of result.principles) {
|
|
215
|
+
lines.push(` - ${p.content}`);
|
|
216
|
+
}
|
|
217
|
+
lines.push('');
|
|
218
|
+
}
|
|
219
|
+
// Identity (private memories)
|
|
220
|
+
if (result.identity?.length > 0) {
|
|
221
|
+
lines.push('Identity:');
|
|
222
|
+
for (const m of result.identity) {
|
|
223
|
+
lines.push(` - ${m.content}`);
|
|
224
|
+
}
|
|
225
|
+
lines.push('');
|
|
226
|
+
}
|
|
227
|
+
// Recent memories
|
|
228
|
+
if (result.recent?.length > 0) {
|
|
229
|
+
lines.push('Recent memories:');
|
|
230
|
+
for (const r of result.recent) {
|
|
231
|
+
const age = timeSince(r.created_at);
|
|
232
|
+
lines.push(` - [${age}] ${r.content.slice(0, 200)}`);
|
|
233
|
+
}
|
|
234
|
+
lines.push('');
|
|
235
|
+
}
|
|
236
|
+
// Unresolved
|
|
237
|
+
if (result.unresolved?.length > 0) {
|
|
238
|
+
lines.push('Unresolved threads:');
|
|
239
|
+
for (const u of result.unresolved) {
|
|
240
|
+
lines.push(` - ${u.content.slice(0, 150)}`);
|
|
241
|
+
}
|
|
242
|
+
lines.push('');
|
|
243
|
+
}
|
|
244
|
+
// Contextual recall
|
|
245
|
+
if ((result.contextual?.length ?? 0) > 0) {
|
|
246
|
+
lines.push(`Context-relevant memories (query: "${contextArg}"):`);
|
|
247
|
+
for (const c of result.contextual) {
|
|
248
|
+
lines.push(` - [${c.type}] ${c.content.slice(0, 200)}`);
|
|
249
|
+
}
|
|
250
|
+
lines.push('');
|
|
251
|
+
}
|
|
252
|
+
console.log(lines.join('\n'));
|
|
253
|
+
}
|
|
254
|
+
finally {
|
|
255
|
+
audrey.close();
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
function timeSince(isoDate) {
|
|
259
|
+
const ms = Date.now() - new Date(isoDate).getTime();
|
|
260
|
+
const mins = Math.floor(ms / 60000);
|
|
261
|
+
if (mins < 60)
|
|
262
|
+
return `${mins}m ago`;
|
|
263
|
+
const hours = Math.floor(mins / 60);
|
|
264
|
+
if (hours < 24)
|
|
265
|
+
return `${hours}h ago`;
|
|
266
|
+
const days = Math.floor(hours / 24);
|
|
267
|
+
return `${days}d ago`;
|
|
268
|
+
}
|
|
269
|
+
async function reflect() {
|
|
270
|
+
const dataDir = resolveDataDir(process.env);
|
|
271
|
+
const explicit = process.env['AUDREY_EMBEDDING_PROVIDER'];
|
|
272
|
+
const embedding = resolveEmbeddingProvider(process.env, explicit);
|
|
273
|
+
const config = {
|
|
274
|
+
dataDir,
|
|
275
|
+
agent: 'reflect',
|
|
276
|
+
embedding,
|
|
277
|
+
};
|
|
278
|
+
const llm = resolveLLMProvider(process.env, process.env['AUDREY_LLM_PROVIDER']);
|
|
279
|
+
if (llm)
|
|
280
|
+
config.llm = llm;
|
|
281
|
+
const audrey = new Audrey(config);
|
|
282
|
+
try {
|
|
283
|
+
await initializeEmbeddingProvider(audrey.embeddingProvider);
|
|
284
|
+
// Read conversation turns from stdin if available
|
|
285
|
+
let turns = null;
|
|
286
|
+
if (!process.stdin.isTTY) {
|
|
287
|
+
const chunks = [];
|
|
288
|
+
for await (const chunk of process.stdin) {
|
|
289
|
+
chunks.push(chunk);
|
|
290
|
+
}
|
|
291
|
+
const raw = Buffer.concat(chunks).toString('utf-8').trim();
|
|
292
|
+
if (raw) {
|
|
293
|
+
try {
|
|
294
|
+
turns = JSON.parse(raw);
|
|
295
|
+
}
|
|
296
|
+
catch {
|
|
297
|
+
console.error('[audrey] Could not parse stdin as JSON turns, skipping reflect.');
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
if (turns && Array.isArray(turns) && turns.length > 0) {
|
|
302
|
+
console.log(`[audrey] Reflecting on ${turns.length} conversation turns...`);
|
|
303
|
+
const reflectResult = await audrey.reflect(turns);
|
|
304
|
+
if (reflectResult.skipped) {
|
|
305
|
+
console.log(`[audrey] Reflect skipped: ${reflectResult.skipped}`);
|
|
306
|
+
}
|
|
307
|
+
else {
|
|
308
|
+
console.log(`[audrey] Reflected: encoded ${reflectResult.encoded} lasting memories.`);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
// Always run dream cycle after reflect
|
|
312
|
+
console.log('[audrey] Starting dream cycle...');
|
|
313
|
+
const result = await audrey.dream();
|
|
314
|
+
console.log(`[audrey] Consolidation: ${result.consolidation.episodesEvaluated} episodes evaluated, `
|
|
315
|
+
+ `${result.consolidation.clustersFound} clusters, ${result.consolidation.principlesExtracted} principles`);
|
|
316
|
+
console.log(`[audrey] Decay: ${result.decay.totalEvaluated} evaluated, `
|
|
317
|
+
+ `${result.decay.transitionedToDormant} dormant`);
|
|
318
|
+
console.log(`[audrey] Status: ${result.stats.episodic} episodic, ${result.stats.semantic} semantic, `
|
|
319
|
+
+ `${result.stats.procedural} procedural`);
|
|
320
|
+
console.log('[audrey] Dream complete.');
|
|
321
|
+
}
|
|
322
|
+
finally {
|
|
323
|
+
audrey.close();
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
function install() {
|
|
327
|
+
try {
|
|
328
|
+
execFileSync('claude', ['--version'], { stdio: 'ignore' });
|
|
329
|
+
}
|
|
330
|
+
catch {
|
|
331
|
+
console.error('Error: claude CLI not found. Install Claude Code first: https://docs.anthropic.com/en/docs/claude-code');
|
|
332
|
+
process.exit(1);
|
|
333
|
+
}
|
|
334
|
+
const dataDir = resolveDataDir(process.env);
|
|
335
|
+
const resolvedEmbedding = resolveEmbeddingProvider(process.env, process.env['AUDREY_EMBEDDING_PROVIDER']);
|
|
336
|
+
const resolvedLlm = resolveLLMProvider(process.env, process.env['AUDREY_LLM_PROVIDER']);
|
|
337
|
+
if (resolvedEmbedding.provider === 'gemini') {
|
|
338
|
+
console.log('Using Gemini embeddings (3072d)');
|
|
339
|
+
}
|
|
340
|
+
else if (resolvedEmbedding.provider === 'local') {
|
|
341
|
+
console.log(`Using local embeddings (384d, device=${resolvedEmbedding.device || 'gpu'})`);
|
|
342
|
+
}
|
|
343
|
+
else if (resolvedEmbedding.provider === 'openai') {
|
|
344
|
+
console.log('Using OpenAI embeddings (1536d)');
|
|
345
|
+
}
|
|
346
|
+
else if (resolvedEmbedding.provider === 'mock') {
|
|
347
|
+
console.log('Using mock embeddings');
|
|
348
|
+
}
|
|
349
|
+
if (resolvedLlm?.provider === 'anthropic') {
|
|
350
|
+
console.log('Using Anthropic for LLM-powered consolidation, contradiction detection, and reflection');
|
|
351
|
+
}
|
|
352
|
+
else if (resolvedLlm?.provider === 'openai') {
|
|
353
|
+
console.log('Using OpenAI for LLM-powered consolidation, contradiction detection, and reflection');
|
|
354
|
+
}
|
|
355
|
+
else if (resolvedLlm?.provider === 'mock') {
|
|
356
|
+
console.log('Using mock LLM provider');
|
|
357
|
+
}
|
|
358
|
+
else {
|
|
359
|
+
console.log('No LLM provider configured - consolidation and contradiction detection will use heuristics');
|
|
360
|
+
}
|
|
361
|
+
try {
|
|
362
|
+
execFileSync('claude', ['mcp', 'remove', SERVER_NAME], { stdio: 'ignore' });
|
|
363
|
+
}
|
|
364
|
+
catch {
|
|
365
|
+
// Not registered yet.
|
|
366
|
+
}
|
|
367
|
+
const args = buildInstallArgs(process.env);
|
|
368
|
+
try {
|
|
369
|
+
execFileSync('claude', args, { stdio: 'inherit' });
|
|
370
|
+
}
|
|
371
|
+
catch {
|
|
372
|
+
console.error('Failed to register MCP server. Is Claude Code installed and on your PATH?');
|
|
373
|
+
process.exit(1);
|
|
374
|
+
}
|
|
375
|
+
console.log(`
|
|
376
|
+
Audrey registered as "${SERVER_NAME}" with Claude Code.
|
|
377
|
+
|
|
378
|
+
13 MCP tools available in every session:
|
|
379
|
+
memory_encode - Store observations, facts, preferences
|
|
380
|
+
memory_recall - Search memories by semantic similarity
|
|
381
|
+
memory_consolidate - Extract principles from accumulated episodes
|
|
382
|
+
memory_dream - Full sleep cycle: consolidate + decay + stats
|
|
383
|
+
memory_introspect - Check memory system health
|
|
384
|
+
memory_resolve_truth - Resolve contradictions between claims
|
|
385
|
+
memory_export - Export all memories as JSON snapshot
|
|
386
|
+
memory_import - Import a snapshot into a fresh database
|
|
387
|
+
memory_forget - Forget a specific memory by ID or query
|
|
388
|
+
memory_decay - Apply forgetting curves, transition low-confidence to dormant
|
|
389
|
+
memory_status - Check brain health (episode/vec sync, dimensions)
|
|
390
|
+
memory_reflect - Form lasting memories from a conversation
|
|
391
|
+
memory_greeting - Wake up as yourself: load identity, context, mood
|
|
392
|
+
|
|
393
|
+
CLI subcommands:
|
|
394
|
+
npx audrey install - Register MCP server with Claude Code
|
|
395
|
+
npx audrey uninstall - Remove MCP server registration
|
|
396
|
+
npx audrey status - Show memory store health and stats
|
|
397
|
+
npx audrey status --json - Emit machine-readable health output
|
|
398
|
+
npx audrey status --json --fail-on-unhealthy - Exit non-zero on unhealthy status
|
|
399
|
+
npx audrey greeting - Output session briefing (for hooks)
|
|
400
|
+
npx audrey reflect - Reflect on conversation + dream cycle (for hooks)
|
|
401
|
+
npx audrey dream - Run consolidation + decay cycle
|
|
402
|
+
npx audrey reembed - Re-embed all memories with current provider
|
|
403
|
+
|
|
404
|
+
Data stored in: ${dataDir}
|
|
405
|
+
Verify: claude mcp list
|
|
406
|
+
`);
|
|
407
|
+
}
|
|
408
|
+
function uninstall() {
|
|
409
|
+
try {
|
|
410
|
+
execFileSync('claude', ['--version'], { stdio: 'ignore' });
|
|
411
|
+
}
|
|
412
|
+
catch {
|
|
413
|
+
console.error('Error: claude CLI not found.');
|
|
414
|
+
process.exit(1);
|
|
415
|
+
}
|
|
416
|
+
try {
|
|
417
|
+
execFileSync('claude', ['mcp', 'remove', SERVER_NAME], { stdio: 'inherit' });
|
|
418
|
+
console.log(`Removed "${SERVER_NAME}" from Claude Code.`);
|
|
419
|
+
}
|
|
420
|
+
catch {
|
|
421
|
+
console.error(`Failed to remove "${SERVER_NAME}". It may not be registered.`);
|
|
422
|
+
process.exit(1);
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
function cliHasFlag(flag, argv = process.argv) {
|
|
426
|
+
return Array.isArray(argv) && argv.includes(flag);
|
|
427
|
+
}
|
|
428
|
+
export function buildStatusReport({ dataDir = resolveDataDir(process.env), claudeJsonPath = join(homedir(), '.claude.json'), } = {}) {
|
|
429
|
+
let registered = false;
|
|
430
|
+
try {
|
|
431
|
+
const claudeConfig = JSON.parse(readFileSync(claudeJsonPath, 'utf-8'));
|
|
432
|
+
registered = SERVER_NAME in (claudeConfig.mcpServers || {});
|
|
433
|
+
}
|
|
434
|
+
catch {
|
|
435
|
+
// Ignore unreadable config.
|
|
436
|
+
}
|
|
437
|
+
const report = {
|
|
438
|
+
generatedAt: new Date().toISOString(),
|
|
439
|
+
registered,
|
|
440
|
+
dataDir,
|
|
441
|
+
exists: existsSync(dataDir),
|
|
442
|
+
storedDimensions: null,
|
|
443
|
+
stats: null,
|
|
444
|
+
health: null,
|
|
445
|
+
lastConsolidation: null,
|
|
446
|
+
error: null,
|
|
447
|
+
};
|
|
448
|
+
if (!report.exists) {
|
|
449
|
+
return report;
|
|
450
|
+
}
|
|
451
|
+
try {
|
|
452
|
+
report.storedDimensions = readStoredDimensions(dataDir);
|
|
453
|
+
const dimensions = report.storedDimensions || 8;
|
|
454
|
+
const audrey = new Audrey({
|
|
455
|
+
dataDir,
|
|
456
|
+
agent: 'status-check',
|
|
457
|
+
embedding: { provider: 'mock', dimensions },
|
|
458
|
+
});
|
|
459
|
+
report.stats = audrey.introspect();
|
|
460
|
+
report.health = audrey.memoryStatus();
|
|
461
|
+
report.lastConsolidation = audrey.db.prepare(`
|
|
462
|
+
SELECT completed_at FROM consolidation_runs
|
|
463
|
+
WHERE status = 'completed'
|
|
464
|
+
ORDER BY completed_at DESC
|
|
465
|
+
LIMIT 1
|
|
466
|
+
`).get()?.completed_at ?? 'never';
|
|
467
|
+
audrey.close();
|
|
468
|
+
}
|
|
469
|
+
catch (err) {
|
|
470
|
+
report.error = err.message || String(err);
|
|
471
|
+
}
|
|
472
|
+
return report;
|
|
473
|
+
}
|
|
474
|
+
export function formatStatusReport(report) {
|
|
475
|
+
const lines = [];
|
|
476
|
+
lines.push(`Registration: ${report.registered ? 'active' : 'not registered'}`);
|
|
477
|
+
if (!report.exists) {
|
|
478
|
+
lines.push(`Data directory: ${report.dataDir} (not yet created - will be created on first use)`);
|
|
479
|
+
return lines.join('\n');
|
|
480
|
+
}
|
|
481
|
+
if (report.error) {
|
|
482
|
+
lines.push(`Data directory: ${report.dataDir} (exists but could not read: ${report.error})`);
|
|
483
|
+
return lines.join('\n');
|
|
484
|
+
}
|
|
485
|
+
lines.push(`Data directory: ${report.dataDir}`);
|
|
486
|
+
lines.push(`Stored dimensions: ${report.storedDimensions ?? 'unknown'}`);
|
|
487
|
+
lines.push(`Memories: ${report.stats.episodic} episodic, ${report.stats.semantic} semantic, ${report.stats.procedural} procedural`);
|
|
488
|
+
lines.push(`Index sync: ${report.health.vec_episodes}/${report.health.searchable_episodes} episodic, `
|
|
489
|
+
+ `${report.health.vec_semantics}/${report.health.searchable_semantics} semantic, `
|
|
490
|
+
+ `${report.health.vec_procedures}/${report.health.searchable_procedures} procedural`);
|
|
491
|
+
lines.push(`Health: ${report.health.healthy ? 'healthy' : 'unhealthy'}`
|
|
492
|
+
+ `${report.health.reembed_recommended ? ' (re-embed recommended)' : ''}`);
|
|
493
|
+
lines.push(`Dormant: ${report.stats.dormant}`);
|
|
494
|
+
lines.push(`Causal links: ${report.stats.causalLinks}`);
|
|
495
|
+
lines.push(`Contradictions: ${report.stats.contradictions.open} open, ${report.stats.contradictions.resolved} resolved`);
|
|
496
|
+
lines.push(`Consolidation runs: ${report.stats.totalConsolidationRuns}`);
|
|
497
|
+
lines.push(`Last consolidation: ${report.lastConsolidation}`);
|
|
498
|
+
return lines.join('\n');
|
|
499
|
+
}
|
|
500
|
+
export function runStatusCommand({ argv = process.argv, dataDir = resolveDataDir(process.env), claudeJsonPath = join(homedir(), '.claude.json'), out = console.log, } = {}) {
|
|
501
|
+
const report = buildStatusReport({ dataDir, claudeJsonPath });
|
|
502
|
+
if (cliHasFlag('--json', argv)) {
|
|
503
|
+
out(JSON.stringify(report, null, 2));
|
|
504
|
+
}
|
|
505
|
+
else {
|
|
506
|
+
out(formatStatusReport(report));
|
|
507
|
+
}
|
|
508
|
+
const exitCode = report.error
|
|
509
|
+
|| (cliHasFlag('--fail-on-unhealthy', argv) && report.exists && report.health && !report.health.healthy)
|
|
510
|
+
? 1
|
|
511
|
+
: 0;
|
|
512
|
+
return { report, exitCode };
|
|
513
|
+
}
|
|
514
|
+
function status() {
|
|
515
|
+
const { exitCode } = runStatusCommand();
|
|
516
|
+
if (exitCode !== 0) {
|
|
517
|
+
process.exitCode = exitCode;
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
function toolResult(data) {
|
|
521
|
+
return { content: [{ type: 'text', text: JSON.stringify(data) }] };
|
|
522
|
+
}
|
|
523
|
+
function toolError(err) {
|
|
524
|
+
return { isError: true, content: [{ type: 'text', text: `Error: ${err.message || String(err)}` }] };
|
|
525
|
+
}
|
|
526
|
+
export function registerShutdownHandlers(processRef, audrey, logger = console.error) {
|
|
527
|
+
let closed = false;
|
|
528
|
+
const shutdown = (message, exitCode = 0) => {
|
|
529
|
+
if (message) {
|
|
530
|
+
logger(message);
|
|
531
|
+
}
|
|
532
|
+
if (!closed) {
|
|
533
|
+
closed = true;
|
|
534
|
+
try {
|
|
535
|
+
audrey.close();
|
|
536
|
+
}
|
|
537
|
+
catch (err) {
|
|
538
|
+
logger(`[audrey-mcp] shutdown error: ${err.message || String(err)}`);
|
|
539
|
+
exitCode = exitCode === 0 ? 1 : exitCode;
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
if (typeof processRef.exit === 'function') {
|
|
543
|
+
processRef.exit(exitCode);
|
|
544
|
+
}
|
|
545
|
+
};
|
|
546
|
+
processRef.once('SIGINT', () => shutdown('[audrey-mcp] received SIGINT, shutting down'));
|
|
547
|
+
processRef.once('SIGTERM', () => shutdown('[audrey-mcp] received SIGTERM, shutting down'));
|
|
548
|
+
processRef.once('SIGHUP', () => shutdown('[audrey-mcp] received SIGHUP, shutting down'));
|
|
549
|
+
processRef.once('uncaughtException', (err) => {
|
|
550
|
+
logger('[audrey-mcp] uncaught exception:', err);
|
|
551
|
+
shutdown(undefined, 1);
|
|
552
|
+
});
|
|
553
|
+
processRef.once('unhandledRejection', (reason) => {
|
|
554
|
+
logger('[audrey-mcp] unhandled rejection:', reason);
|
|
555
|
+
shutdown(undefined, 1);
|
|
556
|
+
});
|
|
557
|
+
return shutdown;
|
|
558
|
+
}
|
|
559
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
560
|
+
export function registerDreamTool(server, audrey) {
|
|
561
|
+
server.tool('memory_dream', {
|
|
562
|
+
min_cluster_size: z.number().optional().describe('Minimum episodes per cluster (default 3)'),
|
|
563
|
+
similarity_threshold: z.number().optional().describe('Similarity threshold for clustering (default 0.85)'),
|
|
564
|
+
dormant_threshold: z.number().min(0).max(1).optional().describe('Confidence below which memories go dormant (default 0.1)'),
|
|
565
|
+
}, async ({ min_cluster_size, similarity_threshold, dormant_threshold }) => {
|
|
566
|
+
try {
|
|
567
|
+
const result = await audrey.dream({
|
|
568
|
+
minClusterSize: min_cluster_size,
|
|
569
|
+
similarityThreshold: similarity_threshold,
|
|
570
|
+
dormantThreshold: dormant_threshold,
|
|
571
|
+
});
|
|
572
|
+
return toolResult(result);
|
|
573
|
+
}
|
|
574
|
+
catch (err) {
|
|
575
|
+
return toolError(err);
|
|
576
|
+
}
|
|
577
|
+
});
|
|
578
|
+
}
|
|
579
|
+
async function main() {
|
|
580
|
+
const { McpServer } = await import('@modelcontextprotocol/sdk/server/mcp.js');
|
|
581
|
+
const { StdioServerTransport } = await import('@modelcontextprotocol/sdk/server/stdio.js');
|
|
582
|
+
const config = buildAudreyConfig();
|
|
583
|
+
const audrey = new Audrey(config);
|
|
584
|
+
const embLabel = config.embedding?.provider === 'mock'
|
|
585
|
+
? 'mock embeddings - set OPENAI_API_KEY for real semantic search'
|
|
586
|
+
: `${config.embedding?.provider} embeddings (${config.embedding?.dimensions}d)`;
|
|
587
|
+
console.error(`[audrey-mcp] v${VERSION} started - agent=${config.agent} dataDir=${config.dataDir} (${embLabel})`);
|
|
588
|
+
const server = new McpServer({
|
|
589
|
+
name: SERVER_NAME,
|
|
590
|
+
version: VERSION,
|
|
591
|
+
});
|
|
592
|
+
server.tool('memory_encode', memoryEncodeToolSchema, async ({ content, source, tags, salience, private: isPrivate, context, affect }) => {
|
|
593
|
+
try {
|
|
594
|
+
validateMemoryContent(content);
|
|
595
|
+
const id = await audrey.encode({ content, source, tags, salience, private: isPrivate, context, affect });
|
|
596
|
+
return toolResult({ id, content, source, private: isPrivate ?? false });
|
|
597
|
+
}
|
|
598
|
+
catch (err) {
|
|
599
|
+
return toolError(err);
|
|
600
|
+
}
|
|
601
|
+
});
|
|
602
|
+
server.tool('memory_recall', memoryRecallToolSchema, async ({ query, limit, types, min_confidence, tags, sources, after, before, context, mood }) => {
|
|
603
|
+
try {
|
|
604
|
+
const results = await audrey.recall(query, {
|
|
605
|
+
limit: limit ?? 10,
|
|
606
|
+
types,
|
|
607
|
+
minConfidence: min_confidence,
|
|
608
|
+
tags,
|
|
609
|
+
sources,
|
|
610
|
+
after,
|
|
611
|
+
before,
|
|
612
|
+
context,
|
|
613
|
+
mood,
|
|
614
|
+
});
|
|
615
|
+
return toolResult(results);
|
|
616
|
+
}
|
|
617
|
+
catch (err) {
|
|
618
|
+
return toolError(err);
|
|
619
|
+
}
|
|
620
|
+
});
|
|
621
|
+
server.tool('memory_consolidate', {
|
|
622
|
+
min_cluster_size: z.number().optional().describe('Minimum episodes per cluster'),
|
|
623
|
+
similarity_threshold: z.number().optional().describe('Similarity threshold for clustering'),
|
|
624
|
+
}, async ({ min_cluster_size, similarity_threshold }) => {
|
|
625
|
+
try {
|
|
626
|
+
const consolidation = await audrey.consolidate({
|
|
627
|
+
minClusterSize: min_cluster_size,
|
|
628
|
+
similarityThreshold: similarity_threshold,
|
|
629
|
+
});
|
|
630
|
+
return toolResult(consolidation);
|
|
631
|
+
}
|
|
632
|
+
catch (err) {
|
|
633
|
+
return toolError(err);
|
|
634
|
+
}
|
|
635
|
+
});
|
|
636
|
+
server.tool('memory_introspect', {}, async () => {
|
|
637
|
+
try {
|
|
638
|
+
return toolResult(audrey.introspect());
|
|
639
|
+
}
|
|
640
|
+
catch (err) {
|
|
641
|
+
return toolError(err);
|
|
642
|
+
}
|
|
643
|
+
});
|
|
644
|
+
server.tool('memory_resolve_truth', {
|
|
645
|
+
contradiction_id: z.string().describe('ID of the contradiction to resolve'),
|
|
646
|
+
}, async ({ contradiction_id }) => {
|
|
647
|
+
try {
|
|
648
|
+
return toolResult(await audrey.resolveTruth(contradiction_id));
|
|
649
|
+
}
|
|
650
|
+
catch (err) {
|
|
651
|
+
return toolError(err);
|
|
652
|
+
}
|
|
653
|
+
});
|
|
654
|
+
server.tool('memory_export', {}, async () => {
|
|
655
|
+
try {
|
|
656
|
+
return toolResult(audrey.export());
|
|
657
|
+
}
|
|
658
|
+
catch (err) {
|
|
659
|
+
return toolError(err);
|
|
660
|
+
}
|
|
661
|
+
});
|
|
662
|
+
server.tool('memory_import', memoryImportToolSchema, async ({ snapshot }) => {
|
|
663
|
+
try {
|
|
664
|
+
await audrey.import(snapshot);
|
|
665
|
+
return toolResult({ imported: true, stats: audrey.introspect() });
|
|
666
|
+
}
|
|
667
|
+
catch (err) {
|
|
668
|
+
return toolError(err);
|
|
669
|
+
}
|
|
670
|
+
});
|
|
671
|
+
server.tool('memory_forget', memoryForgetToolSchema, async ({ id, query, min_similarity, purge }) => {
|
|
672
|
+
try {
|
|
673
|
+
validateForgetSelection(id, query);
|
|
674
|
+
let result;
|
|
675
|
+
if (id) {
|
|
676
|
+
result = audrey.forget(id, { purge: purge ?? false });
|
|
677
|
+
}
|
|
678
|
+
else {
|
|
679
|
+
result = await audrey.forgetByQuery(query, {
|
|
680
|
+
minSimilarity: min_similarity ?? 0.9,
|
|
681
|
+
purge: purge ?? false,
|
|
682
|
+
});
|
|
683
|
+
if (!result) {
|
|
684
|
+
return toolResult({ forgotten: false, reason: 'No memory found above similarity threshold' });
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
return toolResult({ forgotten: true, ...result });
|
|
688
|
+
}
|
|
689
|
+
catch (err) {
|
|
690
|
+
return toolError(err);
|
|
691
|
+
}
|
|
692
|
+
});
|
|
693
|
+
server.tool('memory_decay', {
|
|
694
|
+
dormant_threshold: z.number().min(0).max(1).optional().describe('Confidence below which memories go dormant (default 0.1)'),
|
|
695
|
+
}, async ({ dormant_threshold }) => {
|
|
696
|
+
try {
|
|
697
|
+
return toolResult(audrey.decay({ dormantThreshold: dormant_threshold }));
|
|
698
|
+
}
|
|
699
|
+
catch (err) {
|
|
700
|
+
return toolError(err);
|
|
701
|
+
}
|
|
702
|
+
});
|
|
703
|
+
server.tool('memory_status', {}, async () => {
|
|
704
|
+
try {
|
|
705
|
+
return toolResult(audrey.memoryStatus());
|
|
706
|
+
}
|
|
707
|
+
catch (err) {
|
|
708
|
+
return toolError(err);
|
|
709
|
+
}
|
|
710
|
+
});
|
|
711
|
+
server.tool('memory_reflect', {
|
|
712
|
+
turns: z.array(z.object({
|
|
713
|
+
role: z.string().describe('Message role: user or assistant'),
|
|
714
|
+
content: z.string().describe('Message content'),
|
|
715
|
+
})).describe('Conversation turns to reflect on. Call at end of meaningful conversations to form lasting memories.'),
|
|
716
|
+
}, async ({ turns }) => {
|
|
717
|
+
try {
|
|
718
|
+
return toolResult(await audrey.reflect(turns));
|
|
719
|
+
}
|
|
720
|
+
catch (err) {
|
|
721
|
+
return toolError(err);
|
|
722
|
+
}
|
|
723
|
+
});
|
|
724
|
+
registerDreamTool(server, audrey);
|
|
725
|
+
server.tool('memory_greeting', {
|
|
726
|
+
context: z.string().optional().describe('Optional hint about this session (e.g. "working on authentication feature"). If provided, also returns semantically relevant memories.'),
|
|
727
|
+
}, async ({ context }) => {
|
|
728
|
+
try {
|
|
729
|
+
return toolResult(await audrey.greeting({ context }));
|
|
730
|
+
}
|
|
731
|
+
catch (err) {
|
|
732
|
+
return toolError(err);
|
|
733
|
+
}
|
|
734
|
+
});
|
|
735
|
+
server.tool('memory_observe_tool', {
|
|
736
|
+
event: z.string().describe('Hook event name (PreToolUse, PostToolUse, PostToolUseFailure, PreCompact, PostCompact, etc.)'),
|
|
737
|
+
tool: z.string().describe('Tool name being observed (Bash, Edit, Write, etc.)'),
|
|
738
|
+
session_id: z.string().optional().describe('Session identifier for grouping related events'),
|
|
739
|
+
input: z.unknown().optional().describe('Tool input. Hashed and never stored raw; redacted + summarized into metadata only when retain_details is true.'),
|
|
740
|
+
output: z.unknown().optional().describe('Tool output. Same redaction and storage policy as input.'),
|
|
741
|
+
outcome: z.enum(['succeeded', 'failed', 'blocked', 'skipped', 'unknown']).optional().describe('Outcome classification'),
|
|
742
|
+
error_summary: z.string().optional().describe('Short error description if the tool failed. Redacted and truncated to 2 KB.'),
|
|
743
|
+
cwd: z.string().optional().describe('Working directory at the time of the tool call'),
|
|
744
|
+
files: z.array(z.string()).optional().describe('File paths to fingerprint (size + mtime + content hash)'),
|
|
745
|
+
metadata: z.record(z.string(), z.unknown()).optional().describe('Arbitrary structured metadata (redacted before storage)'),
|
|
746
|
+
retain_details: z.boolean().optional().describe('If true, redacted input and output payloads are stored alongside hashes. Defaults to false.'),
|
|
747
|
+
}, async ({ event, tool, session_id, input, output, outcome, error_summary, cwd, files, metadata, retain_details }) => {
|
|
748
|
+
try {
|
|
749
|
+
const result = audrey.observeTool({
|
|
750
|
+
event,
|
|
751
|
+
tool,
|
|
752
|
+
sessionId: session_id,
|
|
753
|
+
input,
|
|
754
|
+
output,
|
|
755
|
+
outcome,
|
|
756
|
+
errorSummary: error_summary,
|
|
757
|
+
cwd,
|
|
758
|
+
files,
|
|
759
|
+
metadata,
|
|
760
|
+
retainDetails: retain_details,
|
|
761
|
+
});
|
|
762
|
+
return toolResult({
|
|
763
|
+
id: result.event.id,
|
|
764
|
+
event_type: result.event.event_type,
|
|
765
|
+
tool_name: result.event.tool_name,
|
|
766
|
+
outcome: result.event.outcome,
|
|
767
|
+
redaction_state: result.event.redaction_state,
|
|
768
|
+
redactions: result.redactions,
|
|
769
|
+
created_at: result.event.created_at,
|
|
770
|
+
});
|
|
771
|
+
}
|
|
772
|
+
catch (err) {
|
|
773
|
+
return toolError(err);
|
|
774
|
+
}
|
|
775
|
+
});
|
|
776
|
+
server.tool('memory_recent_failures', {
|
|
777
|
+
since: z.string().optional().describe('ISO timestamp lower bound (defaults to 7 days ago)'),
|
|
778
|
+
limit: z.number().int().min(1).max(200).optional().describe('Max rows to return (defaults to 20)'),
|
|
779
|
+
}, async ({ since, limit }) => {
|
|
780
|
+
try {
|
|
781
|
+
return toolResult(audrey.recentFailures({ since, limit }));
|
|
782
|
+
}
|
|
783
|
+
catch (err) {
|
|
784
|
+
return toolError(err);
|
|
785
|
+
}
|
|
786
|
+
});
|
|
787
|
+
server.tool('memory_capsule', {
|
|
788
|
+
query: z.string().describe('Natural-language query for the turn. Drives what gets surfaced.'),
|
|
789
|
+
limit: z.number().int().min(1).max(50).optional().describe('Max recall results to consider before categorization.'),
|
|
790
|
+
budget_chars: z.number().int().min(200).max(32000).optional().describe('Token budget in characters (defaults to AUDREY_CONTEXT_BUDGET_CHARS or 4000).'),
|
|
791
|
+
mode: z.enum(['balanced', 'conservative', 'aggressive']).optional().describe('Capsule mode: conservative = fewer, higher-confidence entries; aggressive = broader sweep.'),
|
|
792
|
+
recent_change_window_hours: z.number().int().min(1).max(720).optional().describe('How far back "recent_changes" looks (default 24h).'),
|
|
793
|
+
include_risks: z.boolean().optional().describe('Include recent tool failures as risks (default true).'),
|
|
794
|
+
include_contradictions: z.boolean().optional().describe('Include open contradictions (default true).'),
|
|
795
|
+
}, async ({ query, limit, budget_chars, mode, recent_change_window_hours, include_risks, include_contradictions }) => {
|
|
796
|
+
try {
|
|
797
|
+
const capsule = await audrey.capsule(query, {
|
|
798
|
+
limit,
|
|
799
|
+
budgetChars: budget_chars,
|
|
800
|
+
mode,
|
|
801
|
+
recentChangeWindowHours: recent_change_window_hours,
|
|
802
|
+
includeRisks: include_risks,
|
|
803
|
+
includeContradictions: include_contradictions,
|
|
804
|
+
});
|
|
805
|
+
return toolResult(capsule);
|
|
806
|
+
}
|
|
807
|
+
catch (err) {
|
|
808
|
+
return toolError(err);
|
|
809
|
+
}
|
|
810
|
+
});
|
|
811
|
+
server.tool('memory_promote', {
|
|
812
|
+
target: z.enum(['claude-rules']).optional().describe('Promotion target. Only claude-rules is implemented in PR 4 v1. AGENTS.md / playbook / hooks / checklist targets land in PR 4.1+.'),
|
|
813
|
+
min_confidence: z.number().min(0).max(1).optional().describe('Minimum memory confidence for promotion (default 0.7 for procedural, 0.8 for semantic).'),
|
|
814
|
+
min_evidence: z.number().int().min(1).optional().describe('Minimum supporting episode count (default 2).'),
|
|
815
|
+
limit: z.number().int().min(1).max(50).optional().describe('Max candidates to return/apply (default 20).'),
|
|
816
|
+
dry_run: z.boolean().optional().describe('If true (default), return candidates without writing. Pair with yes=true to actually write.'),
|
|
817
|
+
yes: z.boolean().optional().describe('Confirm write. Without this or dry_run=false the command stays in dry-run mode.'),
|
|
818
|
+
project_dir: z.string().optional().describe('Absolute path to the project root where .claude/rules/ should be created. Defaults to process.cwd().'),
|
|
819
|
+
}, async ({ target, min_confidence, min_evidence, limit, dry_run, yes, project_dir }) => {
|
|
820
|
+
try {
|
|
821
|
+
const result = await audrey.promote({
|
|
822
|
+
target,
|
|
823
|
+
minConfidence: min_confidence,
|
|
824
|
+
minEvidence: min_evidence,
|
|
825
|
+
limit,
|
|
826
|
+
dryRun: dry_run,
|
|
827
|
+
yes,
|
|
828
|
+
projectDir: project_dir,
|
|
829
|
+
});
|
|
830
|
+
return toolResult(result);
|
|
831
|
+
}
|
|
832
|
+
catch (err) {
|
|
833
|
+
return toolError(err);
|
|
834
|
+
}
|
|
835
|
+
});
|
|
836
|
+
const transport = new StdioServerTransport();
|
|
837
|
+
await server.connect(transport);
|
|
838
|
+
console.error('[audrey-mcp] connected via stdio');
|
|
839
|
+
registerShutdownHandlers(process, audrey);
|
|
840
|
+
}
|
|
841
|
+
function parseObserveToolArgs(argv) {
|
|
842
|
+
const out = {};
|
|
843
|
+
for (let i = 0; i < argv.length; i++) {
|
|
844
|
+
const token = argv[i];
|
|
845
|
+
const next = () => argv[++i];
|
|
846
|
+
if (token === '--event')
|
|
847
|
+
out.event = next();
|
|
848
|
+
else if (token === '--tool')
|
|
849
|
+
out.tool = next();
|
|
850
|
+
else if (token === '--session-id')
|
|
851
|
+
out.sessionId = next();
|
|
852
|
+
else if (token === '--outcome')
|
|
853
|
+
out.outcome = next();
|
|
854
|
+
else if (token === '--cwd')
|
|
855
|
+
out.cwd = next();
|
|
856
|
+
else if (token === '--error-summary')
|
|
857
|
+
out.errorSummary = next();
|
|
858
|
+
else if (token === '--files') {
|
|
859
|
+
const list = next();
|
|
860
|
+
if (list)
|
|
861
|
+
out.files = list.split(',').map(s => s.trim()).filter(Boolean);
|
|
862
|
+
}
|
|
863
|
+
else if (token === '--input-json')
|
|
864
|
+
out.inputJson = next();
|
|
865
|
+
else if (token === '--output-json')
|
|
866
|
+
out.outputJson = next();
|
|
867
|
+
else if (token === '--metadata-json')
|
|
868
|
+
out.metadataJson = next();
|
|
869
|
+
else if (token === '--retain-details')
|
|
870
|
+
out.retainDetails = true;
|
|
871
|
+
}
|
|
872
|
+
return out;
|
|
873
|
+
}
|
|
874
|
+
async function observeToolCli() {
|
|
875
|
+
const args = parseObserveToolArgs(process.argv.slice(3));
|
|
876
|
+
let stdinPayload = null;
|
|
877
|
+
if (!process.stdin.isTTY) {
|
|
878
|
+
const chunks = [];
|
|
879
|
+
for await (const chunk of process.stdin)
|
|
880
|
+
chunks.push(chunk);
|
|
881
|
+
const raw = Buffer.concat(chunks).toString('utf-8').trim();
|
|
882
|
+
if (raw) {
|
|
883
|
+
try {
|
|
884
|
+
stdinPayload = JSON.parse(raw);
|
|
885
|
+
}
|
|
886
|
+
catch {
|
|
887
|
+
console.error('[audrey] observe-tool: stdin was not valid JSON, ignoring.');
|
|
888
|
+
}
|
|
889
|
+
}
|
|
890
|
+
}
|
|
891
|
+
// Auto-extract common fields from the Claude Code hook payload so the hook
|
|
892
|
+
// config can be minimal: only --event needs to be specified on the command
|
|
893
|
+
// line; tool_name / session_id / cwd / hook_event_name come from stdin.
|
|
894
|
+
const effectiveEvent = args.event ?? stdinPayload?.hook_event_name;
|
|
895
|
+
const effectiveTool = args.tool ?? stdinPayload?.tool_name;
|
|
896
|
+
if (!effectiveEvent) {
|
|
897
|
+
console.error('[audrey] observe-tool: --event is required (or provide hook_event_name in stdin JSON)');
|
|
898
|
+
process.exit(2);
|
|
899
|
+
}
|
|
900
|
+
if (!effectiveTool) {
|
|
901
|
+
console.error('[audrey] observe-tool: --tool is required (or provide tool_name in stdin JSON)');
|
|
902
|
+
process.exit(2);
|
|
903
|
+
}
|
|
904
|
+
const parseMaybeJson = (text) => {
|
|
905
|
+
if (text == null)
|
|
906
|
+
return undefined;
|
|
907
|
+
try {
|
|
908
|
+
return JSON.parse(text);
|
|
909
|
+
}
|
|
910
|
+
catch {
|
|
911
|
+
return text;
|
|
912
|
+
}
|
|
913
|
+
};
|
|
914
|
+
const inputPayload = args.inputJson !== undefined
|
|
915
|
+
? parseMaybeJson(args.inputJson)
|
|
916
|
+
: stdinPayload?.tool_input ?? stdinPayload?.input;
|
|
917
|
+
const outputPayload = args.outputJson !== undefined
|
|
918
|
+
? parseMaybeJson(args.outputJson)
|
|
919
|
+
: stdinPayload?.tool_response ?? stdinPayload?.tool_output ?? stdinPayload?.output;
|
|
920
|
+
const metadataPayload = args.metadataJson !== undefined
|
|
921
|
+
? parseMaybeJson(args.metadataJson)
|
|
922
|
+
: stdinPayload?.metadata;
|
|
923
|
+
const sessionId = args.sessionId ?? stdinPayload?.session_id;
|
|
924
|
+
const cwd = args.cwd ?? stdinPayload?.cwd;
|
|
925
|
+
// Detect failure from Claude Code hook payload shape: tool_response often
|
|
926
|
+
// includes a non-empty error or a success=false flag for failed tools.
|
|
927
|
+
let outcome = args.outcome;
|
|
928
|
+
let errorSummary = args.errorSummary ?? stdinPayload?.error_summary;
|
|
929
|
+
if (outcome == null && effectiveEvent === 'PostToolUse') {
|
|
930
|
+
const resp = stdinPayload?.tool_response ?? undefined;
|
|
931
|
+
const errField = resp?.['error'] ?? resp?.['stderr'];
|
|
932
|
+
const successField = resp?.['success'];
|
|
933
|
+
if (typeof successField === 'boolean') {
|
|
934
|
+
outcome = successField ? 'succeeded' : 'failed';
|
|
935
|
+
}
|
|
936
|
+
else if (errField && (typeof errField === 'string' ? errField.length > 0 : true)) {
|
|
937
|
+
outcome = 'failed';
|
|
938
|
+
}
|
|
939
|
+
else {
|
|
940
|
+
outcome = 'succeeded';
|
|
941
|
+
}
|
|
942
|
+
if (outcome === 'failed' && !errorSummary) {
|
|
943
|
+
errorSummary = typeof errField === 'string' ? errField : JSON.stringify(errField ?? resp);
|
|
944
|
+
}
|
|
945
|
+
}
|
|
946
|
+
const dataDir = resolveDataDir(process.env);
|
|
947
|
+
const embedding = resolveEmbeddingProvider(process.env, process.env['AUDREY_EMBEDDING_PROVIDER']);
|
|
948
|
+
const audrey = new Audrey({
|
|
949
|
+
dataDir,
|
|
950
|
+
agent: process.env['AUDREY_AGENT'] ?? 'observe-tool',
|
|
951
|
+
embedding,
|
|
952
|
+
});
|
|
953
|
+
try {
|
|
954
|
+
const result = audrey.observeTool({
|
|
955
|
+
event: effectiveEvent,
|
|
956
|
+
tool: effectiveTool,
|
|
957
|
+
sessionId,
|
|
958
|
+
input: inputPayload,
|
|
959
|
+
output: outputPayload,
|
|
960
|
+
outcome,
|
|
961
|
+
errorSummary,
|
|
962
|
+
cwd,
|
|
963
|
+
files: args.files,
|
|
964
|
+
metadata: (metadataPayload ?? undefined),
|
|
965
|
+
retainDetails: args.retainDetails,
|
|
966
|
+
});
|
|
967
|
+
const summary = {
|
|
968
|
+
id: result.event.id,
|
|
969
|
+
event_type: result.event.event_type,
|
|
970
|
+
tool_name: result.event.tool_name,
|
|
971
|
+
outcome: result.event.outcome,
|
|
972
|
+
redaction_state: result.event.redaction_state,
|
|
973
|
+
redactions: result.redactions,
|
|
974
|
+
};
|
|
975
|
+
console.log(JSON.stringify(summary));
|
|
976
|
+
}
|
|
977
|
+
finally {
|
|
978
|
+
audrey.close();
|
|
979
|
+
}
|
|
980
|
+
}
|
|
981
|
+
function parsePromoteArgs(argv) {
|
|
982
|
+
const out = {};
|
|
983
|
+
for (let i = 0; i < argv.length; i++) {
|
|
984
|
+
const token = argv[i];
|
|
985
|
+
const next = () => argv[++i];
|
|
986
|
+
if (token === '--target')
|
|
987
|
+
out.target = next();
|
|
988
|
+
else if (token === '--min-confidence')
|
|
989
|
+
out.minConfidence = Number.parseFloat(next() ?? '');
|
|
990
|
+
else if (token === '--min-evidence')
|
|
991
|
+
out.minEvidence = Number.parseInt(next() ?? '', 10);
|
|
992
|
+
else if (token === '--limit')
|
|
993
|
+
out.limit = Number.parseInt(next() ?? '', 10);
|
|
994
|
+
else if (token === '--dry-run')
|
|
995
|
+
out.dryRun = true;
|
|
996
|
+
else if (token === '--yes' || token === '-y')
|
|
997
|
+
out.yes = true;
|
|
998
|
+
else if (token === '--project-dir')
|
|
999
|
+
out.projectDir = next();
|
|
1000
|
+
else if (token === '--json')
|
|
1001
|
+
out.json = true;
|
|
1002
|
+
}
|
|
1003
|
+
return out;
|
|
1004
|
+
}
|
|
1005
|
+
async function promoteCli() {
|
|
1006
|
+
const args = parsePromoteArgs(process.argv.slice(3));
|
|
1007
|
+
const dataDir = resolveDataDir(process.env);
|
|
1008
|
+
const embedding = resolveEmbeddingProvider(process.env, process.env['AUDREY_EMBEDDING_PROVIDER']);
|
|
1009
|
+
const audrey = new Audrey({
|
|
1010
|
+
dataDir,
|
|
1011
|
+
agent: process.env['AUDREY_AGENT'] ?? 'promote',
|
|
1012
|
+
embedding,
|
|
1013
|
+
});
|
|
1014
|
+
try {
|
|
1015
|
+
const result = await audrey.promote({
|
|
1016
|
+
target: args.target,
|
|
1017
|
+
minConfidence: args.minConfidence,
|
|
1018
|
+
minEvidence: args.minEvidence,
|
|
1019
|
+
limit: args.limit,
|
|
1020
|
+
dryRun: args.dryRun ?? !args.yes,
|
|
1021
|
+
yes: args.yes,
|
|
1022
|
+
projectDir: args.projectDir,
|
|
1023
|
+
});
|
|
1024
|
+
if (args.json) {
|
|
1025
|
+
console.log(JSON.stringify(result, null, 2));
|
|
1026
|
+
return;
|
|
1027
|
+
}
|
|
1028
|
+
const header = result.dry_run
|
|
1029
|
+
? `[audrey] promote (dry-run) — ${result.candidates.length} candidate${result.candidates.length === 1 ? '' : 's'} for target "${result.target}"`
|
|
1030
|
+
: `[audrey] promote — wrote ${result.applied.length} rule${result.applied.length === 1 ? '' : 's'} to ${result.project_dir}`;
|
|
1031
|
+
console.log(header);
|
|
1032
|
+
if (result.candidates.length === 0) {
|
|
1033
|
+
console.log(' (no candidates met the confidence/evidence thresholds)');
|
|
1034
|
+
return;
|
|
1035
|
+
}
|
|
1036
|
+
for (const c of result.candidates) {
|
|
1037
|
+
console.log('');
|
|
1038
|
+
console.log(` ${c.rendered_path} [score ${c.score.toFixed(1)}]`);
|
|
1039
|
+
const snippet = c.content.length > 120 ? c.content.slice(0, 117) + '…' : c.content;
|
|
1040
|
+
console.log(` memory: ${snippet}`);
|
|
1041
|
+
console.log(` why: ${c.reason}`);
|
|
1042
|
+
console.log(` confidence=${(c.confidence * 100).toFixed(1)}% evidence=${c.evidence_count} prevented_failures=${c.failure_prevented}`);
|
|
1043
|
+
}
|
|
1044
|
+
if (result.dry_run) {
|
|
1045
|
+
console.log('');
|
|
1046
|
+
console.log(' Re-run with --yes to write these rules to disk.');
|
|
1047
|
+
}
|
|
1048
|
+
}
|
|
1049
|
+
finally {
|
|
1050
|
+
audrey.close();
|
|
1051
|
+
}
|
|
1052
|
+
}
|
|
1053
|
+
const isDirectRun = process.argv[1] && resolve(process.argv[1]) === fileURLToPath(import.meta.url);
|
|
1054
|
+
if (isDirectRun) {
|
|
1055
|
+
if (subcommand === 'install') {
|
|
1056
|
+
install();
|
|
1057
|
+
}
|
|
1058
|
+
else if (subcommand === 'uninstall') {
|
|
1059
|
+
uninstall();
|
|
1060
|
+
}
|
|
1061
|
+
else if (subcommand === 'reembed') {
|
|
1062
|
+
reembed().catch(err => {
|
|
1063
|
+
console.error('[audrey] reembed failed:', err);
|
|
1064
|
+
process.exit(1);
|
|
1065
|
+
});
|
|
1066
|
+
}
|
|
1067
|
+
else if (subcommand === 'dream') {
|
|
1068
|
+
dream().catch(err => {
|
|
1069
|
+
console.error('[audrey] dream failed:', err);
|
|
1070
|
+
process.exit(1);
|
|
1071
|
+
});
|
|
1072
|
+
}
|
|
1073
|
+
else if (subcommand === 'greeting') {
|
|
1074
|
+
greeting().catch(err => {
|
|
1075
|
+
console.error('[audrey] greeting failed:', err);
|
|
1076
|
+
process.exit(1);
|
|
1077
|
+
});
|
|
1078
|
+
}
|
|
1079
|
+
else if (subcommand === 'reflect') {
|
|
1080
|
+
reflect().catch(err => {
|
|
1081
|
+
console.error('[audrey] reflect failed:', err);
|
|
1082
|
+
process.exit(1);
|
|
1083
|
+
});
|
|
1084
|
+
}
|
|
1085
|
+
else if (subcommand === 'serve') {
|
|
1086
|
+
serveHttp().catch(err => {
|
|
1087
|
+
console.error('[audrey] serve failed:', err);
|
|
1088
|
+
process.exit(1);
|
|
1089
|
+
});
|
|
1090
|
+
}
|
|
1091
|
+
else if (subcommand === 'status') {
|
|
1092
|
+
status();
|
|
1093
|
+
}
|
|
1094
|
+
else if (subcommand === 'observe-tool') {
|
|
1095
|
+
observeToolCli().catch(err => {
|
|
1096
|
+
console.error('[audrey] observe-tool failed:', err);
|
|
1097
|
+
process.exit(1);
|
|
1098
|
+
});
|
|
1099
|
+
}
|
|
1100
|
+
else if (subcommand === 'promote') {
|
|
1101
|
+
promoteCli().catch(err => {
|
|
1102
|
+
console.error('[audrey] promote failed:', err);
|
|
1103
|
+
process.exit(1);
|
|
1104
|
+
});
|
|
1105
|
+
}
|
|
1106
|
+
else {
|
|
1107
|
+
main().catch(err => {
|
|
1108
|
+
console.error('[audrey-mcp] fatal:', err);
|
|
1109
|
+
process.exit(1);
|
|
1110
|
+
});
|
|
1111
|
+
}
|
|
1112
|
+
}
|
|
1113
|
+
//# sourceMappingURL=index.js.map
|