@memextend/claude-code 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/mcp/server.ts"],"names":[],"mappings":""}
@@ -0,0 +1,330 @@
1
+ // packages/adapters/claude-code/src/mcp/server.ts
2
+ // Copyright (c) 2026 ZodTTD LLC. MIT License.
3
+ import { Server } from '@modelcontextprotocol/sdk/server/index.js';
4
+ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
5
+ import { CallToolRequestSchema, ListToolsRequestSchema, } from '@modelcontextprotocol/sdk/types.js';
6
+ import { createHash, randomUUID } from 'crypto';
7
+ import { existsSync } from 'fs';
8
+ import { join, basename } from 'path';
9
+ import { homedir } from 'os';
10
+ import { execSync } from 'child_process';
11
+ import { SQLiteStorage, LanceDBStorage, MemoryRetriever, createEmbedFunction } from '@memextend/core';
12
+ /**
13
+ * Get the current project ID based on working directory.
14
+ * Tries multiple methods to determine the project context.
15
+ */
16
+ function getCurrentProjectId() {
17
+ // Try environment variable first (if Claude Code ever provides one)
18
+ const envCwd = process.env.CLAUDE_CODE_CWD || process.env.CLAUDE_CWD || process.env.PWD;
19
+ if (envCwd && existsSync(envCwd)) {
20
+ // Try to get git root for consistent project identification
21
+ try {
22
+ const gitRoot = execSync('git rev-parse --show-toplevel', {
23
+ cwd: envCwd,
24
+ encoding: 'utf-8',
25
+ stdio: ['pipe', 'pipe', 'pipe']
26
+ }).trim();
27
+ return {
28
+ id: createHash('sha256').update(gitRoot).digest('hex').slice(0, 16),
29
+ name: basename(gitRoot),
30
+ path: gitRoot
31
+ };
32
+ }
33
+ catch {
34
+ // Not a git repo, use the directory directly
35
+ return {
36
+ id: createHash('sha256').update(envCwd).digest('hex').slice(0, 16),
37
+ name: basename(envCwd),
38
+ path: envCwd
39
+ };
40
+ }
41
+ }
42
+ // Fallback: use process.cwd() which might work in some cases
43
+ const cwd = process.cwd();
44
+ if (cwd && cwd !== '/' && !cwd.includes('.cache')) {
45
+ try {
46
+ const gitRoot = execSync('git rev-parse --show-toplevel', {
47
+ cwd,
48
+ encoding: 'utf-8',
49
+ stdio: ['pipe', 'pipe', 'pipe']
50
+ }).trim();
51
+ return {
52
+ id: createHash('sha256').update(gitRoot).digest('hex').slice(0, 16),
53
+ name: basename(gitRoot),
54
+ path: gitRoot
55
+ };
56
+ }
57
+ catch {
58
+ return {
59
+ id: createHash('sha256').update(cwd).digest('hex').slice(0, 16),
60
+ name: basename(cwd),
61
+ path: cwd
62
+ };
63
+ }
64
+ }
65
+ // Ultimate fallback
66
+ return {
67
+ id: 'default',
68
+ name: 'Unknown Project',
69
+ path: ''
70
+ };
71
+ }
72
+ const MEMEXTEND_DIR = join(homedir(), '.memextend');
73
+ const DB_PATH = join(MEMEXTEND_DIR, 'memextend.db');
74
+ const VECTORS_PATH = join(MEMEXTEND_DIR, 'vectors');
75
+ const MODELS_PATH = join(MEMEXTEND_DIR, 'models');
76
+ // Lazy-loaded storage instances
77
+ let sqlite = null;
78
+ let lancedb = null;
79
+ let retriever = null;
80
+ let embedder = null;
81
+ async function getStorage() {
82
+ if (!sqlite || !lancedb || !retriever || !embedder) {
83
+ if (!existsSync(DB_PATH)) {
84
+ throw new Error('memextend not initialized. Run `memextend init` first.');
85
+ }
86
+ sqlite = new SQLiteStorage(DB_PATH);
87
+ lancedb = await LanceDBStorage.create(VECTORS_PATH);
88
+ embedder = await createEmbedFunction(MODELS_PATH);
89
+ retriever = new MemoryRetriever(sqlite, lancedb, embedder.embedQuery);
90
+ }
91
+ return { sqlite, lancedb, retriever, embedder };
92
+ }
93
+ const server = new Server({
94
+ name: 'memextend',
95
+ version: '0.1.0',
96
+ }, {
97
+ capabilities: {
98
+ tools: {},
99
+ },
100
+ });
101
+ // List available tools
102
+ server.setRequestHandler(ListToolsRequestSchema, async () => {
103
+ return {
104
+ tools: [
105
+ {
106
+ name: 'memextend_search',
107
+ description: 'Search through your memories. Use this to recall past work, decisions, or context.',
108
+ inputSchema: {
109
+ type: 'object',
110
+ properties: {
111
+ query: {
112
+ type: 'string',
113
+ description: 'Search query (e.g., "Redis caching", "authentication setup")',
114
+ },
115
+ limit: {
116
+ type: 'number',
117
+ description: 'Maximum number of results (default: 5)',
118
+ },
119
+ },
120
+ required: ['query'],
121
+ },
122
+ },
123
+ {
124
+ name: 'memextend_save',
125
+ description: 'Save a memory for this project. Use this to remember important decisions, patterns, or context. IMPORTANT: You must provide the projectId - use the project/repo name from the current working directory (e.g., "memextend", "my-app").',
126
+ inputSchema: {
127
+ type: 'object',
128
+ properties: {
129
+ content: {
130
+ type: 'string',
131
+ description: 'The memory content to save',
132
+ },
133
+ projectId: {
134
+ type: 'string',
135
+ description: 'Project name/identifier (REQUIRED - use the repo or folder name, e.g., "memextend", "my-project")',
136
+ },
137
+ },
138
+ required: ['content', 'projectId'],
139
+ },
140
+ },
141
+ {
142
+ name: 'memextend_save_global',
143
+ description: 'Save a global preference or fact that applies across all projects.',
144
+ inputSchema: {
145
+ type: 'object',
146
+ properties: {
147
+ content: {
148
+ type: 'string',
149
+ description: 'The preference or fact to remember globally',
150
+ },
151
+ type: {
152
+ type: 'string',
153
+ enum: ['preference', 'pattern', 'fact'],
154
+ description: 'Type of global memory',
155
+ },
156
+ },
157
+ required: ['content', 'type'],
158
+ },
159
+ },
160
+ {
161
+ name: 'memextend_forget',
162
+ description: 'Delete a specific memory by ID.',
163
+ inputSchema: {
164
+ type: 'object',
165
+ properties: {
166
+ memoryId: {
167
+ type: 'string',
168
+ description: 'The ID of the memory to delete',
169
+ },
170
+ },
171
+ required: ['memoryId'],
172
+ },
173
+ },
174
+ {
175
+ name: 'memextend_status',
176
+ description: 'Get memextend status and memory statistics.',
177
+ inputSchema: {
178
+ type: 'object',
179
+ properties: {},
180
+ },
181
+ },
182
+ ],
183
+ };
184
+ });
185
+ // Handle tool calls
186
+ server.setRequestHandler(CallToolRequestSchema, async (request) => {
187
+ const { name, arguments: args } = request.params;
188
+ try {
189
+ switch (name) {
190
+ case 'memextend_search': {
191
+ const { retriever } = await getStorage();
192
+ const query = args?.query;
193
+ const limit = args?.limit ?? 5;
194
+ // Try to scope search to current project
195
+ const detected = getCurrentProjectId();
196
+ const projectId = detected.id !== 'default' ? detected.id : undefined;
197
+ const results = await retriever.hybridSearch(query, { limit, projectId });
198
+ if (results.length === 0) {
199
+ return { content: [{ type: 'text', text: 'No memories found matching your query.' }] };
200
+ }
201
+ const formatted = results.map((r, i) => {
202
+ const date = new Date(r.memory.createdAt).toLocaleDateString();
203
+ return `${i + 1}. [${date}] (score: ${r.score.toFixed(3)})\n ${r.memory.content.split('\n')[0]}`;
204
+ }).join('\n\n');
205
+ return { content: [{ type: 'text', text: `Found ${results.length} memories:\n\n${formatted}` }] };
206
+ }
207
+ case 'memextend_save': {
208
+ const { sqlite, lancedb, embedder } = await getStorage();
209
+ const content = args?.content;
210
+ const projectIdArg = args?.projectId;
211
+ // Validate projectId is provided
212
+ if (!projectIdArg || projectIdArg.trim() === '') {
213
+ return { content: [{ type: 'text', text: 'projectId is required. Please provide the project/repo name (e.g., "memextend", "my-app").' }], isError: true };
214
+ }
215
+ const projectName = projectIdArg.trim();
216
+ // Try to find existing project by name first (to match hook-created projects)
217
+ const existingByName = sqlite.getProjectByName(projectName);
218
+ let projectId;
219
+ if (existingByName) {
220
+ // Use the existing project's ID (matches what hooks created)
221
+ projectId = existingByName.id;
222
+ }
223
+ else {
224
+ // Create new project with hash-based ID
225
+ projectId = createHash('sha256').update(projectName.toLowerCase()).digest('hex').slice(0, 16);
226
+ sqlite.insertProject({
227
+ id: projectId,
228
+ name: projectName,
229
+ path: '', // No path available from MCP
230
+ createdAt: new Date().toISOString()
231
+ });
232
+ }
233
+ // Validate content
234
+ if (!content || content.length < 10) {
235
+ return { content: [{ type: 'text', text: 'Memory content too short (minimum 10 characters).' }], isError: true };
236
+ }
237
+ if (content.length > 50000) {
238
+ return { content: [{ type: 'text', text: 'Memory content too long (maximum 50KB).' }], isError: true };
239
+ }
240
+ const memoryId = randomUUID();
241
+ sqlite.insertMemory({
242
+ id: memoryId,
243
+ projectId,
244
+ content,
245
+ type: 'manual',
246
+ sourceTool: null,
247
+ createdAt: new Date().toISOString(),
248
+ sessionId: null,
249
+ metadata: null,
250
+ });
251
+ const vector = await embedder.embed(content);
252
+ await lancedb.insertVector(memoryId, vector);
253
+ return { content: [{ type: 'text', text: `Memory saved to "${projectName}" with ID: ${memoryId}` }] };
254
+ }
255
+ case 'memextend_save_global': {
256
+ const { sqlite } = await getStorage();
257
+ const content = args?.content;
258
+ const type = args?.type;
259
+ // Validate content
260
+ if (!content || content.length < 5) {
261
+ return { content: [{ type: 'text', text: 'Content too short (minimum 5 characters).' }], isError: true };
262
+ }
263
+ if (content.length > 10000) {
264
+ return { content: [{ type: 'text', text: 'Content too long (maximum 10KB for global profiles).' }], isError: true };
265
+ }
266
+ const profileId = randomUUID();
267
+ sqlite.insertGlobalProfile({
268
+ id: profileId,
269
+ key: type,
270
+ content,
271
+ createdAt: new Date().toISOString(),
272
+ });
273
+ return { content: [{ type: 'text', text: `Global ${type} saved: "${content}"` }] };
274
+ }
275
+ case 'memextend_forget': {
276
+ const { sqlite, lancedb } = await getStorage();
277
+ const memoryId = args?.memoryId;
278
+ const deleted = sqlite.deleteMemory(memoryId);
279
+ if (deleted) {
280
+ // Also delete the vector embedding
281
+ await lancedb.deleteVector(memoryId);
282
+ return { content: [{ type: 'text', text: `Memory ${memoryId} deleted.` }] };
283
+ }
284
+ else {
285
+ return { content: [{ type: 'text', text: `Memory ${memoryId} not found.` }] };
286
+ }
287
+ }
288
+ case 'memextend_status': {
289
+ const { sqlite, lancedb, embedder } = await getStorage();
290
+ const memoryCount = sqlite.getMemoryCount();
291
+ const vectorCount = await lancedb.getVectorCount();
292
+ // Debug: show project detection info
293
+ const detected = getCurrentProjectId();
294
+ return {
295
+ content: [{
296
+ type: 'text',
297
+ text: `memextend Status:
298
+ - Total memories: ${memoryCount}
299
+ - Vector embeddings: ${vectorCount}
300
+ - Using real embeddings: ${embedder.isReal ? 'Yes' : 'No (fallback mode)'}
301
+ - Database: ${DB_PATH}
302
+ - Vectors: ${VECTORS_PATH}
303
+
304
+ Project Detection:
305
+ - Detected ID: ${detected.id}
306
+ - Detected name: ${detected.name}
307
+ - Detected path: ${detected.path || '(none)'}
308
+ - PWD env: ${process.env.PWD || '(not set)'}
309
+ - CLAUDE_CWD env: ${process.env.CLAUDE_CWD || '(not set)'}
310
+ - CLAUDE_CODE_CWD env: ${process.env.CLAUDE_CODE_CWD || '(not set)'}
311
+ - process.cwd(): ${process.cwd()}`
312
+ }]
313
+ };
314
+ }
315
+ default:
316
+ return { content: [{ type: 'text', text: `Unknown tool: ${name}` }], isError: true };
317
+ }
318
+ }
319
+ catch (error) {
320
+ const message = error instanceof Error ? error.message : 'Unknown error';
321
+ return { content: [{ type: 'text', text: `Error: ${message}` }], isError: true };
322
+ }
323
+ });
324
+ // Start server
325
+ async function main() {
326
+ const transport = new StdioServerTransport();
327
+ await server.connect(transport);
328
+ }
329
+ main().catch(console.error);
330
+ //# sourceMappingURL=server.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/mcp/server.ts"],"names":[],"mappings":"AAAA,kDAAkD;AAClD,8CAA8C;AAE9C,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EACL,qBAAqB,EACrB,sBAAsB,GACvB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAChC,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,MAAM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,CAAC,GAAG,CAAC,UAAU,IAAI,WAAW;yBAChC,OAAO,CAAC,GAAG,CAAC,eAAe,IAAI,WAAW;mBAChD,OAAO,CAAC,GAAG,EAAE,EAAE;yBACvB,CAAC;iBACH,CAAC;YACJ,CAAC;YAED;gBACE,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,iBAAiB,IAAI,EAAE,EAAE,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;QACzF,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe,CAAC;QACzE,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,OAAO,EAAE,EAAE,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;IACnF,CAAC;AACH,CAAC,CAAC,CAAC;AAEH,eAAe;AACf,KAAK,UAAU,IAAI;IACjB,MAAM,SAAS,GAAG,IAAI,oBAAoB,EAAE,CAAC;IAC7C,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;AAClC,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC"}
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "@memextend/claude-code",
3
+ "version": "0.1.0",
4
+ "description": "Claude Code adapter for memextend - hooks and MCP server for persistent AI memory",
5
+ "author": "ZodTTD LLC <repo@zodttd.com>",
6
+ "license": "MIT",
7
+ "type": "module",
8
+ "main": "dist/index.js",
9
+ "types": "dist/index.d.ts",
10
+ "scripts": {
11
+ "build": "tsc && npm run build:hooks",
12
+ "build:hooks": "node scripts/build-hooks.js",
13
+ "test": "vitest run"
14
+ },
15
+ "dependencies": {
16
+ "@memextend/core": "^0.1.0",
17
+ "@modelcontextprotocol/sdk": "^1.0.0"
18
+ },
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "https://github.com/zodttd/memextend.git",
22
+ "directory": "packages/adapters/claude-code"
23
+ },
24
+ "bugs": {
25
+ "url": "https://github.com/zodttd/memextend/issues"
26
+ },
27
+ "homepage": "https://github.com/zodttd/memextend#readme",
28
+ "keywords": [
29
+ "memextend",
30
+ "claude-code",
31
+ "claude",
32
+ "anthropic",
33
+ "ai-memory",
34
+ "mcp",
35
+ "model-context-protocol",
36
+ "hooks"
37
+ ],
38
+ "files": [
39
+ "dist",
40
+ "scripts",
41
+ "README.md"
42
+ ],
43
+ "engines": {
44
+ "node": ">=18.0.0"
45
+ },
46
+ "publishConfig": {
47
+ "access": "public"
48
+ }
49
+ }
@@ -0,0 +1,65 @@
1
+ // Build script for bundling hooks and MCP server with esbuild
2
+ // Copyright (c) 2026 ZodTTD LLC. MIT License.
3
+
4
+ import { build } from 'esbuild';
5
+ import { join, dirname } from 'path';
6
+ import { fileURLToPath } from 'url';
7
+ import { mkdir } from 'fs/promises';
8
+
9
+ const __dirname = dirname(fileURLToPath(import.meta.url));
10
+ const srcDir = join(__dirname, '..', 'src');
11
+ const distDir = join(__dirname, '..', 'dist');
12
+
13
+ const commonOptions = {
14
+ bundle: true,
15
+ platform: 'node',
16
+ target: 'node18',
17
+ format: 'cjs',
18
+ external: ['better-sqlite3', 'node-llama-cpp', '@lancedb/lancedb'],
19
+ logLevel: 'warning',
20
+ };
21
+
22
+ async function buildHooks() {
23
+ const hooksDir = join(distDir, 'hooks');
24
+ await mkdir(hooksDir, { recursive: true });
25
+
26
+ const hooks = ['session-start', 'stop', 'pre-compact'];
27
+
28
+ for (const hook of hooks) {
29
+ try {
30
+ await build({
31
+ ...commonOptions,
32
+ entryPoints: [join(srcDir, 'hooks', `${hook}.ts`)],
33
+ outfile: join(hooksDir, `${hook}.cjs`),
34
+ });
35
+ console.log(`✓ Built hooks/${hook}.cjs`);
36
+ } catch (e) {
37
+ console.log(`✗ Skipping ${hook} (error: ${e.message})`);
38
+ }
39
+ }
40
+ }
41
+
42
+ async function buildMCP() {
43
+ const mcpDir = join(distDir, 'mcp');
44
+ await mkdir(mcpDir, { recursive: true });
45
+
46
+ try {
47
+ await build({
48
+ ...commonOptions,
49
+ entryPoints: [join(srcDir, 'mcp', 'server.ts')],
50
+ outfile: join(mcpDir, 'server.cjs'),
51
+ });
52
+ console.log(`✓ Built mcp/server.cjs`);
53
+ } catch (e) {
54
+ console.log(`✗ Skipping MCP server (error: ${e.message})`);
55
+ }
56
+ }
57
+
58
+ async function main() {
59
+ console.log('Building memextend Claude Code adapter...\n');
60
+ await buildHooks();
61
+ await buildMCP();
62
+ console.log('\nBuild complete!');
63
+ }
64
+
65
+ main().catch(console.error);