claude-cortex 1.0.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 +291 -0
- package/dist/api/events.d.ts +134 -0
- package/dist/api/events.d.ts.map +1 -0
- package/dist/api/events.js +73 -0
- package/dist/api/events.js.map +1 -0
- package/dist/api/visualization-server.d.ts +11 -0
- package/dist/api/visualization-server.d.ts.map +1 -0
- package/dist/api/visualization-server.js +653 -0
- package/dist/api/visualization-server.js.map +1 -0
- package/dist/context/project-context.d.ts +57 -0
- package/dist/context/project-context.d.ts.map +1 -0
- package/dist/context/project-context.js +135 -0
- package/dist/context/project-context.js.map +1 -0
- package/dist/database/init.d.ts +49 -0
- package/dist/database/init.d.ts.map +1 -0
- package/dist/database/init.js +336 -0
- package/dist/database/init.js.map +1 -0
- package/dist/embeddings/generator.d.ts +20 -0
- package/dist/embeddings/generator.d.ts.map +1 -0
- package/dist/embeddings/generator.js +77 -0
- package/dist/embeddings/generator.js.map +1 -0
- package/dist/embeddings/index.d.ts +2 -0
- package/dist/embeddings/index.d.ts.map +1 -0
- package/dist/embeddings/index.js +2 -0
- package/dist/embeddings/index.js.map +1 -0
- package/dist/errors.d.ts +74 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +131 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +83 -0
- package/dist/index.js.map +1 -0
- package/dist/memory/activation.d.ts +69 -0
- package/dist/memory/activation.d.ts.map +1 -0
- package/dist/memory/activation.js +168 -0
- package/dist/memory/activation.js.map +1 -0
- package/dist/memory/consolidate.d.ts +96 -0
- package/dist/memory/consolidate.d.ts.map +1 -0
- package/dist/memory/consolidate.js +400 -0
- package/dist/memory/consolidate.js.map +1 -0
- package/dist/memory/contradiction.d.ts +69 -0
- package/dist/memory/contradiction.d.ts.map +1 -0
- package/dist/memory/contradiction.js +286 -0
- package/dist/memory/contradiction.js.map +1 -0
- package/dist/memory/decay.d.ts +62 -0
- package/dist/memory/decay.d.ts.map +1 -0
- package/dist/memory/decay.js +184 -0
- package/dist/memory/decay.js.map +1 -0
- package/dist/memory/salience.d.ts +36 -0
- package/dist/memory/salience.d.ts.map +1 -0
- package/dist/memory/salience.js +200 -0
- package/dist/memory/salience.js.map +1 -0
- package/dist/memory/similarity.d.ts +57 -0
- package/dist/memory/similarity.d.ts.map +1 -0
- package/dist/memory/similarity.js +114 -0
- package/dist/memory/similarity.js.map +1 -0
- package/dist/memory/store.d.ts +170 -0
- package/dist/memory/store.d.ts.map +1 -0
- package/dist/memory/store.js +973 -0
- package/dist/memory/store.js.map +1 -0
- package/dist/memory/types.d.ts +91 -0
- package/dist/memory/types.d.ts.map +1 -0
- package/dist/memory/types.js +30 -0
- package/dist/memory/types.js.map +1 -0
- package/dist/server.d.ts +12 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +466 -0
- package/dist/server.js.map +1 -0
- package/dist/tools/context.d.ts +135 -0
- package/dist/tools/context.d.ts.map +1 -0
- package/dist/tools/context.js +273 -0
- package/dist/tools/context.js.map +1 -0
- package/dist/tools/forget.d.ts +53 -0
- package/dist/tools/forget.d.ts.map +1 -0
- package/dist/tools/forget.js +179 -0
- package/dist/tools/forget.js.map +1 -0
- package/dist/tools/recall.d.ts +74 -0
- package/dist/tools/recall.d.ts.map +1 -0
- package/dist/tools/recall.js +140 -0
- package/dist/tools/recall.js.map +1 -0
- package/dist/tools/remember.d.ts +65 -0
- package/dist/tools/remember.d.ts.map +1 -0
- package/dist/tools/remember.js +147 -0
- package/dist/tools/remember.js.map +1 -0
- package/dist/worker/brain-worker.d.ts +100 -0
- package/dist/worker/brain-worker.d.ts.map +1 -0
- package/dist/worker/brain-worker.js +261 -0
- package/dist/worker/brain-worker.js.map +1 -0
- package/dist/worker/link-discovery.d.ts +47 -0
- package/dist/worker/link-discovery.d.ts.map +1 -0
- package/dist/worker/link-discovery.js +103 -0
- package/dist/worker/link-discovery.js.map +1 -0
- package/dist/worker/predictive-consolidation.d.ts +46 -0
- package/dist/worker/predictive-consolidation.d.ts.map +1 -0
- package/dist/worker/predictive-consolidation.js +110 -0
- package/dist/worker/predictive-consolidation.js.map +1 -0
- package/dist/worker/types.d.ts +91 -0
- package/dist/worker/types.d.ts.map +1 -0
- package/dist/worker/types.js +22 -0
- package/dist/worker/types.js.map +1 -0
- package/package.json +59 -0
package/dist/server.js
ADDED
|
@@ -0,0 +1,466 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Claude Memory MCP Server
|
|
3
|
+
*
|
|
4
|
+
* Brain-like memory system for Claude Code.
|
|
5
|
+
* Solves context compaction and memory persistence issues.
|
|
6
|
+
*/
|
|
7
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
8
|
+
import { z } from 'zod';
|
|
9
|
+
import { initDatabase } from './database/init.js';
|
|
10
|
+
import { DEFAULT_CONFIG } from './memory/types.js';
|
|
11
|
+
import { initProjectContext, getActiveProject, setActiveProject, getProjectContextInfo, GLOBAL_PROJECT_SENTINEL, } from './context/project-context.js';
|
|
12
|
+
// Import tools
|
|
13
|
+
import { executeRemember, formatRememberResult } from './tools/remember.js';
|
|
14
|
+
import { executeRecall, formatRecallResult, executeGetMemory, formatMemory } from './tools/recall.js';
|
|
15
|
+
import { executeForget, formatForgetResult } from './tools/forget.js';
|
|
16
|
+
import { executeGetContext, executeStartSession, executeEndSession, executeConsolidate, executeStats, formatStats, executeExport, executeImport, } from './tools/context.js';
|
|
17
|
+
import { generateContextSummary, formatContextSummary, consolidate, fullCleanup } from './memory/consolidate.js';
|
|
18
|
+
import { getHighPriorityMemories, getRecentMemories, getRelatedMemories, createMemoryLink } from './memory/store.js';
|
|
19
|
+
import { detectContradictions } from './memory/contradiction.js';
|
|
20
|
+
import { checkDatabaseSize } from './database/init.js';
|
|
21
|
+
/**
|
|
22
|
+
* Create and configure the MCP server
|
|
23
|
+
*/
|
|
24
|
+
export function createServer(dbPath) {
|
|
25
|
+
// Initialize database
|
|
26
|
+
const config = { ...DEFAULT_CONFIG };
|
|
27
|
+
if (dbPath) {
|
|
28
|
+
config.dbPath = dbPath;
|
|
29
|
+
}
|
|
30
|
+
initDatabase(config.dbPath);
|
|
31
|
+
// Initialize project context (auto-detect from working directory)
|
|
32
|
+
initProjectContext();
|
|
33
|
+
const projectInfo = getProjectContextInfo();
|
|
34
|
+
if (projectInfo.project) {
|
|
35
|
+
console.error(`[claude-cortex] Project: "${projectInfo.project}" (from ${projectInfo.source})`);
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
console.error('[claude-cortex] Project: global scope');
|
|
39
|
+
}
|
|
40
|
+
// Create MCP server
|
|
41
|
+
const server = new McpServer({
|
|
42
|
+
name: 'claude-cortex',
|
|
43
|
+
version: '1.0.0',
|
|
44
|
+
});
|
|
45
|
+
// ============================================
|
|
46
|
+
// TOOLS
|
|
47
|
+
// ============================================
|
|
48
|
+
// Remember - Store a memory
|
|
49
|
+
server.tool('remember', `Store information in memory for later recall. Use this to remember:
|
|
50
|
+
- Architecture decisions ("We're using PostgreSQL for the database")
|
|
51
|
+
- Code patterns ("The auth flow uses JWT tokens")
|
|
52
|
+
- User preferences ("Always use TypeScript strict mode")
|
|
53
|
+
- Error resolutions ("Fixed by updating the dependency")
|
|
54
|
+
- Project context ("This is a React + Node.js project")
|
|
55
|
+
- Important notes ("Remember to test the edge cases")
|
|
56
|
+
|
|
57
|
+
The system automatically detects importance, categorizes, and manages storage.`, {
|
|
58
|
+
title: z.string().describe('Short title for the memory'),
|
|
59
|
+
content: z.string().describe('Detailed content'),
|
|
60
|
+
category: z.enum([
|
|
61
|
+
'architecture', 'pattern', 'preference', 'error',
|
|
62
|
+
'context', 'learning', 'todo', 'note', 'relationship', 'custom'
|
|
63
|
+
]).optional().describe('Category (auto-detected if not provided)'),
|
|
64
|
+
type: z.enum(['short_term', 'long_term', 'episodic']).optional()
|
|
65
|
+
.describe('Memory type (auto-determined if not provided)'),
|
|
66
|
+
project: z.string().optional().describe('Project scope. Auto-detected from working directory if not provided. Use "*" for global.'),
|
|
67
|
+
tags: z.array(z.string()).optional().describe('Tags for categorization'),
|
|
68
|
+
importance: z.enum(['low', 'normal', 'high', 'critical']).optional()
|
|
69
|
+
.describe('Override automatic salience'),
|
|
70
|
+
scope: z.enum(['project', 'global']).optional()
|
|
71
|
+
.describe('Memory scope: project (default) or global (cross-project)'),
|
|
72
|
+
transferable: z.boolean().optional()
|
|
73
|
+
.describe('Whether this memory can be transferred to other projects'),
|
|
74
|
+
}, async (args) => {
|
|
75
|
+
const result = await executeRemember(args);
|
|
76
|
+
return {
|
|
77
|
+
content: [{ type: 'text', text: formatRememberResult(result) }],
|
|
78
|
+
};
|
|
79
|
+
});
|
|
80
|
+
// Recall - Search and retrieve memories
|
|
81
|
+
server.tool('recall', `Search and retrieve memories. Use this to:
|
|
82
|
+
- Find relevant context ("What do I know about auth?")
|
|
83
|
+
- Get recent activity ("What did we work on?")
|
|
84
|
+
- Find decisions ("What architecture decisions were made?")
|
|
85
|
+
|
|
86
|
+
Modes: search (query-based), recent (by time), important (by salience)`, {
|
|
87
|
+
query: z.string().optional().describe('Search query'),
|
|
88
|
+
category: z.enum([
|
|
89
|
+
'architecture', 'pattern', 'preference', 'error',
|
|
90
|
+
'context', 'learning', 'todo', 'note', 'relationship', 'custom'
|
|
91
|
+
]).optional().describe('Filter by category'),
|
|
92
|
+
type: z.enum(['short_term', 'long_term', 'episodic']).optional()
|
|
93
|
+
.describe('Filter by type'),
|
|
94
|
+
project: z.string().optional().describe('Project scope. Auto-detected if not provided. Use "*" for all projects.'),
|
|
95
|
+
tags: z.array(z.string()).optional().describe('Filter by tags'),
|
|
96
|
+
limit: z.number().min(1).max(50).optional().default(10)
|
|
97
|
+
.describe('Max results'),
|
|
98
|
+
includeDecayed: z.boolean().optional().default(false)
|
|
99
|
+
.describe('Include decayed memories'),
|
|
100
|
+
includeGlobal: z.boolean().optional().default(true)
|
|
101
|
+
.describe('Include global memories in search results (default: true)'),
|
|
102
|
+
mode: z.enum(['search', 'recent', 'important']).optional().default('search')
|
|
103
|
+
.describe('Recall mode'),
|
|
104
|
+
}, async (args) => {
|
|
105
|
+
const result = await executeRecall(args);
|
|
106
|
+
return {
|
|
107
|
+
content: [{ type: 'text', text: formatRecallResult(result, true) }],
|
|
108
|
+
};
|
|
109
|
+
});
|
|
110
|
+
// Forget - Delete memories
|
|
111
|
+
server.tool('forget', `Delete memories. Use dryRun: true to preview, confirm: true for bulk.`, {
|
|
112
|
+
id: z.number().optional().describe('Memory ID to delete'),
|
|
113
|
+
query: z.string().optional().describe('Delete matching query'),
|
|
114
|
+
category: z.enum([
|
|
115
|
+
'architecture', 'pattern', 'preference', 'error',
|
|
116
|
+
'context', 'learning', 'todo', 'note', 'relationship', 'custom'
|
|
117
|
+
]).optional().describe('Delete category'),
|
|
118
|
+
project: z.string().optional().describe('Project scope for deletion. Auto-detected if not provided. Use "*" for all projects.'),
|
|
119
|
+
olderThan: z.number().optional().describe('Delete older than N days'),
|
|
120
|
+
belowSalience: z.number().min(0).max(1).optional()
|
|
121
|
+
.describe('Delete below salience'),
|
|
122
|
+
dryRun: z.boolean().optional().default(false)
|
|
123
|
+
.describe('Preview only'),
|
|
124
|
+
confirm: z.boolean().optional().default(false)
|
|
125
|
+
.describe('Confirm bulk delete'),
|
|
126
|
+
}, async (args) => {
|
|
127
|
+
const result = await executeForget(args);
|
|
128
|
+
return {
|
|
129
|
+
content: [{ type: 'text', text: formatForgetResult(result) }],
|
|
130
|
+
};
|
|
131
|
+
});
|
|
132
|
+
// Get Context - THE KEY TOOL
|
|
133
|
+
server.tool('get_context', `Get relevant context from memory. THE KEY TOOL for maintaining context.
|
|
134
|
+
|
|
135
|
+
Use at session start, after compaction, when switching tasks, or to recall project info.
|
|
136
|
+
Returns: architecture decisions, patterns, pending items, recent activity.`, {
|
|
137
|
+
project: z.string().optional().describe('Project scope. Auto-detected if not provided. Use "*" for all projects.'),
|
|
138
|
+
query: z.string().optional().describe('Current task for relevant context'),
|
|
139
|
+
format: z.enum(['summary', 'detailed', 'raw']).optional().default('summary')
|
|
140
|
+
.describe('Output format'),
|
|
141
|
+
}, async (args) => {
|
|
142
|
+
const result = await executeGetContext(args);
|
|
143
|
+
return {
|
|
144
|
+
content: [{
|
|
145
|
+
type: 'text',
|
|
146
|
+
text: result.success ? result.context : `Error: ${result.error}`
|
|
147
|
+
}],
|
|
148
|
+
};
|
|
149
|
+
});
|
|
150
|
+
// Start Session
|
|
151
|
+
server.tool('start_session', 'Start a new coding session. Returns relevant context.', {
|
|
152
|
+
project: z.string().optional().describe('Project scope. Auto-detected if not provided. Use "*" for global.'),
|
|
153
|
+
}, async (args) => {
|
|
154
|
+
const result = await executeStartSession(args);
|
|
155
|
+
return {
|
|
156
|
+
content: [{
|
|
157
|
+
type: 'text',
|
|
158
|
+
text: result.success
|
|
159
|
+
? `Session ${result.sessionId} started.\n\n${result.context}`
|
|
160
|
+
: `Error: ${result.error}`
|
|
161
|
+
}],
|
|
162
|
+
};
|
|
163
|
+
});
|
|
164
|
+
// End Session
|
|
165
|
+
server.tool('end_session', 'End session and trigger consolidation.', {
|
|
166
|
+
sessionId: z.number().describe('Session ID'),
|
|
167
|
+
summary: z.string().optional().describe('Session summary'),
|
|
168
|
+
}, async (args) => {
|
|
169
|
+
const result = executeEndSession(args);
|
|
170
|
+
if (!result.success) {
|
|
171
|
+
return { content: [{ type: 'text', text: `Error: ${result.error}` }] };
|
|
172
|
+
}
|
|
173
|
+
const r = result.consolidationResult;
|
|
174
|
+
return {
|
|
175
|
+
content: [{
|
|
176
|
+
type: 'text',
|
|
177
|
+
text: `Session ended. Consolidation: ${r.consolidated} promoted, ${r.decayed} decayed, ${r.deleted} deleted.`
|
|
178
|
+
}],
|
|
179
|
+
};
|
|
180
|
+
});
|
|
181
|
+
// Consolidate
|
|
182
|
+
server.tool('consolidate', 'Run memory consolidation (like brain sleep). Promotes STM to LTM, decays old memories. Use dryRun to preview.', {
|
|
183
|
+
force: z.boolean().optional().default(false).describe('Force consolidation'),
|
|
184
|
+
dryRun: z.boolean().optional().default(false).describe('Preview what would happen without doing it'),
|
|
185
|
+
}, async (args) => {
|
|
186
|
+
const result = executeConsolidate(args);
|
|
187
|
+
if (!result.success) {
|
|
188
|
+
return { content: [{ type: 'text', text: `Error: ${result.error}` }] };
|
|
189
|
+
}
|
|
190
|
+
// Dry run returns preview
|
|
191
|
+
if (result.preview) {
|
|
192
|
+
const p = result.preview;
|
|
193
|
+
const lines = [
|
|
194
|
+
'## Consolidation Preview (Dry Run)',
|
|
195
|
+
'',
|
|
196
|
+
`Would promote: ${p.toPromote} memories`,
|
|
197
|
+
`Would delete: ${p.toDelete} memories`,
|
|
198
|
+
];
|
|
199
|
+
if (p.promoteList.length > 0) {
|
|
200
|
+
lines.push('', '**To promote:**');
|
|
201
|
+
lines.push(...p.promoteList.map(t => ` - ${t}`));
|
|
202
|
+
}
|
|
203
|
+
if (p.deleteList.length > 0) {
|
|
204
|
+
lines.push('', '**At risk of deletion:**');
|
|
205
|
+
lines.push(...p.deleteList.map(t => ` - ${t}`));
|
|
206
|
+
}
|
|
207
|
+
return { content: [{ type: 'text', text: lines.join('\n') }] };
|
|
208
|
+
}
|
|
209
|
+
// Actual consolidation result
|
|
210
|
+
const r = result.result;
|
|
211
|
+
return {
|
|
212
|
+
content: [{
|
|
213
|
+
type: 'text',
|
|
214
|
+
text: `Consolidation: ${r.consolidated} promoted, ${r.decayed} updated, ${r.deleted} deleted.`
|
|
215
|
+
}],
|
|
216
|
+
};
|
|
217
|
+
});
|
|
218
|
+
// Stats
|
|
219
|
+
server.tool('memory_stats', 'Get memory statistics.', {
|
|
220
|
+
project: z.string().optional().describe('Project scope. Auto-detected if not provided. Use "*" for all projects.'),
|
|
221
|
+
}, async (args) => {
|
|
222
|
+
const result = executeStats(args);
|
|
223
|
+
return {
|
|
224
|
+
content: [{
|
|
225
|
+
type: 'text',
|
|
226
|
+
text: result.success ? formatStats(result.stats) : `Error: ${result.error}`
|
|
227
|
+
}],
|
|
228
|
+
};
|
|
229
|
+
});
|
|
230
|
+
// Get Memory by ID
|
|
231
|
+
server.tool('get_memory', 'Get a specific memory by ID.', {
|
|
232
|
+
id: z.number().describe('Memory ID'),
|
|
233
|
+
}, async (args) => {
|
|
234
|
+
const result = executeGetMemory(args);
|
|
235
|
+
return {
|
|
236
|
+
content: [{
|
|
237
|
+
type: 'text',
|
|
238
|
+
text: result.success ? formatMemory(result.memory, true) : `Error: ${result.error}`
|
|
239
|
+
}],
|
|
240
|
+
};
|
|
241
|
+
});
|
|
242
|
+
// Export memories
|
|
243
|
+
server.tool('export_memories', 'Export memories as JSON for backup.', {
|
|
244
|
+
project: z.string().optional().describe('Project scope. Auto-detected if not provided. Use "*" for all projects.'),
|
|
245
|
+
}, async (args) => {
|
|
246
|
+
const result = executeExport(args);
|
|
247
|
+
return {
|
|
248
|
+
content: [{
|
|
249
|
+
type: 'text',
|
|
250
|
+
text: result.success
|
|
251
|
+
? `Exported ${result.count} memories:\n\n${result.data}`
|
|
252
|
+
: `Error: ${result.error}`
|
|
253
|
+
}],
|
|
254
|
+
};
|
|
255
|
+
});
|
|
256
|
+
// Import memories
|
|
257
|
+
server.tool('import_memories', 'Import memories from JSON.', {
|
|
258
|
+
data: z.string().describe('JSON data'),
|
|
259
|
+
}, async (args) => {
|
|
260
|
+
const result = executeImport(args);
|
|
261
|
+
return {
|
|
262
|
+
content: [{
|
|
263
|
+
type: 'text',
|
|
264
|
+
text: result.success
|
|
265
|
+
? `Imported ${result.imported} memories.`
|
|
266
|
+
: `Error: ${result.error}`
|
|
267
|
+
}],
|
|
268
|
+
};
|
|
269
|
+
});
|
|
270
|
+
// Get Related Memories
|
|
271
|
+
server.tool('get_related', 'Get memories related to a specific memory. Shows connections and relationships.', {
|
|
272
|
+
id: z.number().describe('Memory ID to find relationships for'),
|
|
273
|
+
}, async (args) => {
|
|
274
|
+
const related = getRelatedMemories(args.id);
|
|
275
|
+
if (related.length === 0) {
|
|
276
|
+
return { content: [{ type: 'text', text: 'No related memories found.' }] };
|
|
277
|
+
}
|
|
278
|
+
const lines = [`## Related Memories for ID ${args.id}\n`];
|
|
279
|
+
for (const r of related) {
|
|
280
|
+
const arrow = r.direction === 'outgoing' ? '→' : '←';
|
|
281
|
+
lines.push(`${arrow} **${r.memory.title}** (${r.relationship}, ${(r.strength * 100).toFixed(0)}% strength)`);
|
|
282
|
+
lines.push(` ID: ${r.memory.id} | ${r.memory.category} | ${(r.memory.salience * 100).toFixed(0)}% salience`);
|
|
283
|
+
}
|
|
284
|
+
return { content: [{ type: 'text', text: lines.join('\n') }] };
|
|
285
|
+
});
|
|
286
|
+
// Link Memories
|
|
287
|
+
server.tool('link_memories', 'Create a relationship link between two memories.', {
|
|
288
|
+
sourceId: z.number().describe('Source memory ID'),
|
|
289
|
+
targetId: z.number().describe('Target memory ID'),
|
|
290
|
+
relationship: z.enum(['references', 'extends', 'contradicts', 'related'])
|
|
291
|
+
.describe('Type of relationship'),
|
|
292
|
+
strength: z.number().min(0).max(1).optional().default(0.5)
|
|
293
|
+
.describe('Relationship strength (0-1)'),
|
|
294
|
+
}, async (args) => {
|
|
295
|
+
const link = createMemoryLink(args.sourceId, args.targetId, args.relationship, args.strength);
|
|
296
|
+
if (!link) {
|
|
297
|
+
return { content: [{ type: 'text', text: 'Failed to create link. Memories may not exist or link already exists.' }] };
|
|
298
|
+
}
|
|
299
|
+
return { content: [{ type: 'text', text: `✓ Linked memory ${args.sourceId} → ${args.targetId} (${args.relationship})` }] };
|
|
300
|
+
});
|
|
301
|
+
// Set Project - Switch active project context
|
|
302
|
+
server.tool('set_project', `Switch active project context. Use "${GLOBAL_PROJECT_SENTINEL}" for global/all projects.`, {
|
|
303
|
+
project: z.string().describe(`Project name, or "${GLOBAL_PROJECT_SENTINEL}" for global scope`),
|
|
304
|
+
}, async (args) => {
|
|
305
|
+
const oldProject = getActiveProject();
|
|
306
|
+
setActiveProject(args.project === GLOBAL_PROJECT_SENTINEL ? null : args.project);
|
|
307
|
+
const newProject = getActiveProject();
|
|
308
|
+
return {
|
|
309
|
+
content: [{
|
|
310
|
+
type: 'text',
|
|
311
|
+
text: `Project context changed: ${oldProject || 'global'} → ${newProject || 'global'}`
|
|
312
|
+
}]
|
|
313
|
+
};
|
|
314
|
+
});
|
|
315
|
+
// Get Project - Show current project scope
|
|
316
|
+
server.tool('get_project', 'Show current project scope and detection info.', {}, async () => {
|
|
317
|
+
const info = getProjectContextInfo();
|
|
318
|
+
const lines = [
|
|
319
|
+
`**Current Project:** ${info.project || 'global (all projects)'}`,
|
|
320
|
+
`**Detection Source:** ${info.source}`,
|
|
321
|
+
`**Scope:** ${info.isGlobal ? 'Global - queries return all projects' : `Scoped - queries filtered to "${info.project}"`}`,
|
|
322
|
+
];
|
|
323
|
+
return { content: [{ type: 'text', text: lines.join('\n') }] };
|
|
324
|
+
});
|
|
325
|
+
// ============================================
|
|
326
|
+
// ORGANIC BRAIN TOOLS (Phase 3)
|
|
327
|
+
// ============================================
|
|
328
|
+
// Detect Contradictions - Find conflicting memories
|
|
329
|
+
server.tool('detect_contradictions', `Scan memories for potential contradictions. Finds memories that may contain
|
|
330
|
+
conflicting information about the same topic, such as:
|
|
331
|
+
- Different solutions to the same problem
|
|
332
|
+
- Conflicting recommendations (use X vs don't use X)
|
|
333
|
+
- Opposite decisions or preferences
|
|
334
|
+
|
|
335
|
+
Contradictions are automatically detected during consolidation and linked,
|
|
336
|
+
but you can use this tool to check for new contradictions at any time.`, {
|
|
337
|
+
project: z.string().optional().describe('Filter by project (omit for current project)'),
|
|
338
|
+
category: z.enum([
|
|
339
|
+
'architecture', 'pattern', 'preference', 'error',
|
|
340
|
+
'context', 'learning', 'todo', 'note', 'relationship', 'custom'
|
|
341
|
+
]).optional().describe('Filter by category'),
|
|
342
|
+
minScore: z.number().min(0).max(1).optional().default(0.4)
|
|
343
|
+
.describe('Minimum contradiction score (0-1, default 0.4)'),
|
|
344
|
+
limit: z.number().min(1).max(50).optional().default(10)
|
|
345
|
+
.describe('Maximum results to return'),
|
|
346
|
+
}, async (args) => {
|
|
347
|
+
const project = args.project ?? getActiveProject() ?? undefined;
|
|
348
|
+
const contradictions = detectContradictions({
|
|
349
|
+
project,
|
|
350
|
+
category: args.category,
|
|
351
|
+
minScore: args.minScore,
|
|
352
|
+
limit: args.limit,
|
|
353
|
+
});
|
|
354
|
+
if (contradictions.length === 0) {
|
|
355
|
+
return { content: [{ type: 'text', text: 'No contradictions detected.' }] };
|
|
356
|
+
}
|
|
357
|
+
const lines = ['## Potential Contradictions\n'];
|
|
358
|
+
for (const c of contradictions) {
|
|
359
|
+
lines.push(`### ${c.reason} (${(c.score * 100).toFixed(0)}% confidence)`);
|
|
360
|
+
lines.push(`**Memory A:** [#${c.memoryA.id}] ${c.memoryA.title}`);
|
|
361
|
+
lines.push(`**Memory B:** [#${c.memoryB.id}] ${c.memoryB.title}`);
|
|
362
|
+
if (c.sharedTopics.length > 0) {
|
|
363
|
+
lines.push(`**Shared Topics:** ${c.sharedTopics.join(', ')}`);
|
|
364
|
+
}
|
|
365
|
+
lines.push('');
|
|
366
|
+
}
|
|
367
|
+
lines.push(`\n*Found ${contradictions.length} potential contradiction(s). Use \`get_related\` to see linked contradictions.*`);
|
|
368
|
+
return { content: [{ type: 'text', text: lines.join('\n') }] };
|
|
369
|
+
});
|
|
370
|
+
// ============================================
|
|
371
|
+
// RESOURCES
|
|
372
|
+
// ============================================
|
|
373
|
+
// Project context resource
|
|
374
|
+
server.resource('memory://context', 'memory://context', async () => {
|
|
375
|
+
const summary = await generateContextSummary();
|
|
376
|
+
return {
|
|
377
|
+
contents: [{
|
|
378
|
+
uri: 'memory://context',
|
|
379
|
+
mimeType: 'text/markdown',
|
|
380
|
+
text: formatContextSummary(summary),
|
|
381
|
+
}],
|
|
382
|
+
};
|
|
383
|
+
});
|
|
384
|
+
// Important memories resource
|
|
385
|
+
server.resource('memory://important', 'memory://important', async () => {
|
|
386
|
+
const memories = getHighPriorityMemories(20);
|
|
387
|
+
const text = memories.map(m => `## ${m.title}\n${m.content}\n*${m.category} | ${(m.salience * 100).toFixed(0)}% salience*\n`).join('\n');
|
|
388
|
+
return {
|
|
389
|
+
contents: [{
|
|
390
|
+
uri: 'memory://important',
|
|
391
|
+
mimeType: 'text/markdown',
|
|
392
|
+
text: text || 'No high-priority memories stored yet.',
|
|
393
|
+
}],
|
|
394
|
+
};
|
|
395
|
+
});
|
|
396
|
+
// Recent memories resource
|
|
397
|
+
server.resource('memory://recent', 'memory://recent', async () => {
|
|
398
|
+
const memories = getRecentMemories(15);
|
|
399
|
+
const text = memories.map(m => `- **${m.title}** (${m.category}): ${m.content.slice(0, 100)}...`).join('\n');
|
|
400
|
+
return {
|
|
401
|
+
contents: [{
|
|
402
|
+
uri: 'memory://recent',
|
|
403
|
+
mimeType: 'text/markdown',
|
|
404
|
+
text: text || 'No recent memories.',
|
|
405
|
+
}],
|
|
406
|
+
};
|
|
407
|
+
});
|
|
408
|
+
// ============================================
|
|
409
|
+
// PROMPTS
|
|
410
|
+
// ============================================
|
|
411
|
+
// Context restoration prompt
|
|
412
|
+
server.prompt('restore_context', 'Restore context after compaction or at session start', async () => {
|
|
413
|
+
const summary = await generateContextSummary();
|
|
414
|
+
const context = formatContextSummary(summary);
|
|
415
|
+
return {
|
|
416
|
+
messages: [{
|
|
417
|
+
role: 'user',
|
|
418
|
+
content: {
|
|
419
|
+
type: 'text',
|
|
420
|
+
text: `Please review this context from memory and use it:\n\n${context}`,
|
|
421
|
+
},
|
|
422
|
+
}],
|
|
423
|
+
};
|
|
424
|
+
});
|
|
425
|
+
// Memory search prompt
|
|
426
|
+
server.prompt('search_memory', 'Search memories for information', async () => {
|
|
427
|
+
return {
|
|
428
|
+
messages: [{
|
|
429
|
+
role: 'user',
|
|
430
|
+
content: {
|
|
431
|
+
type: 'text',
|
|
432
|
+
text: `Search my memories for relevant information.`,
|
|
433
|
+
},
|
|
434
|
+
}],
|
|
435
|
+
};
|
|
436
|
+
});
|
|
437
|
+
// ============================================
|
|
438
|
+
// AUTO-CONSOLIDATION (Anti-bloat)
|
|
439
|
+
// ============================================
|
|
440
|
+
// Run initial consolidation on startup
|
|
441
|
+
try {
|
|
442
|
+
const startupResult = consolidate();
|
|
443
|
+
console.error(`[claude-cortex] Startup consolidation: ${startupResult.consolidated} promoted, ${startupResult.deleted} deleted`);
|
|
444
|
+
}
|
|
445
|
+
catch (e) {
|
|
446
|
+
console.error('[claude-cortex] Startup consolidation failed:', e);
|
|
447
|
+
}
|
|
448
|
+
// Check database size on startup
|
|
449
|
+
const sizeInfo = checkDatabaseSize();
|
|
450
|
+
if (sizeInfo.warning || sizeInfo.blocked) {
|
|
451
|
+
console.error(`[claude-cortex] ${sizeInfo.message}`);
|
|
452
|
+
}
|
|
453
|
+
// Schedule periodic consolidation every 4 hours
|
|
454
|
+
const CONSOLIDATION_INTERVAL = 4 * 60 * 60 * 1000; // 4 hours
|
|
455
|
+
setInterval(() => {
|
|
456
|
+
try {
|
|
457
|
+
const result = fullCleanup();
|
|
458
|
+
console.error(`[claude-cortex] Scheduled cleanup: ${result.consolidation.consolidated} promoted, ${result.consolidation.deleted} deleted, ${result.merged} merged, vacuumed: ${result.vacuumed}`);
|
|
459
|
+
}
|
|
460
|
+
catch (e) {
|
|
461
|
+
console.error('[claude-cortex] Scheduled cleanup failed:', e);
|
|
462
|
+
}
|
|
463
|
+
}, CONSOLIDATION_INTERVAL);
|
|
464
|
+
return server;
|
|
465
|
+
}
|
|
466
|
+
//# sourceMappingURL=server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAA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,CAAC,CAAC;QAChE,CAAC;IACH,CAAC,EAAE,sBAAsB,CAAC,CAAC;IAE3B,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Context Tool
|
|
3
|
+
*
|
|
4
|
+
* Manages context injection and session handling.
|
|
5
|
+
* This is the key tool for solving the compaction problem.
|
|
6
|
+
*/
|
|
7
|
+
import { z } from 'zod';
|
|
8
|
+
import { getMemoryStats } from '../memory/store.js';
|
|
9
|
+
import { Memory, ContextSummary, ConsolidationResult } from '../memory/types.js';
|
|
10
|
+
export declare const getContextSchema: z.ZodObject<{
|
|
11
|
+
project: z.ZodOptional<z.ZodString>;
|
|
12
|
+
query: z.ZodOptional<z.ZodString>;
|
|
13
|
+
format: z.ZodDefault<z.ZodOptional<z.ZodEnum<["summary", "detailed", "raw"]>>>;
|
|
14
|
+
}, "strip", z.ZodTypeAny, {
|
|
15
|
+
format: "summary" | "detailed" | "raw";
|
|
16
|
+
project?: string | undefined;
|
|
17
|
+
query?: string | undefined;
|
|
18
|
+
}, {
|
|
19
|
+
project?: string | undefined;
|
|
20
|
+
query?: string | undefined;
|
|
21
|
+
format?: "summary" | "detailed" | "raw" | undefined;
|
|
22
|
+
}>;
|
|
23
|
+
export type GetContextInput = z.infer<typeof getContextSchema>;
|
|
24
|
+
/**
|
|
25
|
+
* Execute the get_context tool
|
|
26
|
+
*/
|
|
27
|
+
export declare function executeGetContext(input: GetContextInput): Promise<{
|
|
28
|
+
success: boolean;
|
|
29
|
+
context?: string;
|
|
30
|
+
summary?: ContextSummary;
|
|
31
|
+
relevantMemories?: Memory[];
|
|
32
|
+
error?: string;
|
|
33
|
+
}>;
|
|
34
|
+
export declare const startSessionSchema: z.ZodObject<{
|
|
35
|
+
project: z.ZodOptional<z.ZodString>;
|
|
36
|
+
}, "strip", z.ZodTypeAny, {
|
|
37
|
+
project?: string | undefined;
|
|
38
|
+
}, {
|
|
39
|
+
project?: string | undefined;
|
|
40
|
+
}>;
|
|
41
|
+
export declare function executeStartSession(input: {
|
|
42
|
+
project?: string;
|
|
43
|
+
}): Promise<{
|
|
44
|
+
success: boolean;
|
|
45
|
+
sessionId?: number;
|
|
46
|
+
context?: string;
|
|
47
|
+
error?: string;
|
|
48
|
+
}>;
|
|
49
|
+
export declare const endSessionSchema: z.ZodObject<{
|
|
50
|
+
sessionId: z.ZodNumber;
|
|
51
|
+
summary: z.ZodOptional<z.ZodString>;
|
|
52
|
+
}, "strip", z.ZodTypeAny, {
|
|
53
|
+
sessionId: number;
|
|
54
|
+
summary?: string | undefined;
|
|
55
|
+
}, {
|
|
56
|
+
sessionId: number;
|
|
57
|
+
summary?: string | undefined;
|
|
58
|
+
}>;
|
|
59
|
+
export declare function executeEndSession(input: {
|
|
60
|
+
sessionId: number;
|
|
61
|
+
summary?: string;
|
|
62
|
+
}): {
|
|
63
|
+
success: boolean;
|
|
64
|
+
consolidationResult?: ConsolidationResult;
|
|
65
|
+
error?: string;
|
|
66
|
+
};
|
|
67
|
+
export declare const consolidateSchema: z.ZodObject<{
|
|
68
|
+
force: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
69
|
+
dryRun: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
70
|
+
}, "strip", z.ZodTypeAny, {
|
|
71
|
+
dryRun: boolean;
|
|
72
|
+
force: boolean;
|
|
73
|
+
}, {
|
|
74
|
+
dryRun?: boolean | undefined;
|
|
75
|
+
force?: boolean | undefined;
|
|
76
|
+
}>;
|
|
77
|
+
export declare function executeConsolidate(input: {
|
|
78
|
+
force?: boolean;
|
|
79
|
+
dryRun?: boolean;
|
|
80
|
+
}): {
|
|
81
|
+
success: boolean;
|
|
82
|
+
result?: ConsolidationResult;
|
|
83
|
+
preview?: {
|
|
84
|
+
toPromote: number;
|
|
85
|
+
toDelete: number;
|
|
86
|
+
promoteList: string[];
|
|
87
|
+
deleteList: string[];
|
|
88
|
+
};
|
|
89
|
+
error?: string;
|
|
90
|
+
};
|
|
91
|
+
export declare const statsSchema: z.ZodObject<{
|
|
92
|
+
project: z.ZodOptional<z.ZodString>;
|
|
93
|
+
}, "strip", z.ZodTypeAny, {
|
|
94
|
+
project?: string | undefined;
|
|
95
|
+
}, {
|
|
96
|
+
project?: string | undefined;
|
|
97
|
+
}>;
|
|
98
|
+
export declare function executeStats(input: {
|
|
99
|
+
project?: string;
|
|
100
|
+
}): {
|
|
101
|
+
success: boolean;
|
|
102
|
+
stats?: ReturnType<typeof getMemoryStats>;
|
|
103
|
+
error?: string;
|
|
104
|
+
};
|
|
105
|
+
export declare function formatStats(stats: ReturnType<typeof getMemoryStats>): string;
|
|
106
|
+
export declare const exportSchema: z.ZodObject<{
|
|
107
|
+
project: z.ZodOptional<z.ZodString>;
|
|
108
|
+
}, "strip", z.ZodTypeAny, {
|
|
109
|
+
project?: string | undefined;
|
|
110
|
+
}, {
|
|
111
|
+
project?: string | undefined;
|
|
112
|
+
}>;
|
|
113
|
+
export declare function executeExport(input: {
|
|
114
|
+
project?: string;
|
|
115
|
+
}): {
|
|
116
|
+
success: boolean;
|
|
117
|
+
data?: string;
|
|
118
|
+
count?: number;
|
|
119
|
+
error?: string;
|
|
120
|
+
};
|
|
121
|
+
export declare const importSchema: z.ZodObject<{
|
|
122
|
+
data: z.ZodString;
|
|
123
|
+
}, "strip", z.ZodTypeAny, {
|
|
124
|
+
data: string;
|
|
125
|
+
}, {
|
|
126
|
+
data: string;
|
|
127
|
+
}>;
|
|
128
|
+
export declare function executeImport(input: {
|
|
129
|
+
data: string;
|
|
130
|
+
}): {
|
|
131
|
+
success: boolean;
|
|
132
|
+
imported?: number;
|
|
133
|
+
error?: string;
|
|
134
|
+
};
|
|
135
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/tools/context.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,E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