tuna-agent 0.1.11 → 0.1.13
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/dist/agents/claude-code-adapter.js +2 -11
- package/dist/mcp/setup.d.ts +5 -0
- package/dist/mcp/setup.js +61 -2
- package/package.json +1 -1
|
@@ -694,19 +694,10 @@ Instructions:
|
|
|
694
694
|
const sentiment = data.score > 0 ? 'approved (thumbs up)' : 'rejected (thumbs down)';
|
|
695
695
|
const commentPart = data.comment ? ` User feedback: "${data.comment}"` : '';
|
|
696
696
|
const memoryText = `User ${sentiment} task "${data.taskTitle}".${commentPart} Task description: ${data.taskDescription.substring(0, 200)}`;
|
|
697
|
-
const prompt = `Store this user feedback in your memory using the mem0 add_memory tool. Do NOT do anything else.
|
|
698
|
-
|
|
699
|
-
Memory to store: ${memoryText}`;
|
|
700
697
|
try {
|
|
701
698
|
console.log(`[Rating→Mem0] Storing rating for task "${data.taskTitle}" (${data.score > 0 ? '👍' : '👎'})`);
|
|
702
|
-
await
|
|
703
|
-
|
|
704
|
-
cwd: data.cwd,
|
|
705
|
-
maxTurns: 2,
|
|
706
|
-
outputFormat: 'json',
|
|
707
|
-
timeoutMs: 20000,
|
|
708
|
-
permissionMode: 'bypassPermissions',
|
|
709
|
-
});
|
|
699
|
+
const { callMem0AddMemory } = await import('../mcp/setup.js');
|
|
700
|
+
await callMem0AddMemory(memoryText, this.agentConfig.name);
|
|
710
701
|
console.log(`[Rating→Mem0] Rating stored successfully`);
|
|
711
702
|
}
|
|
712
703
|
catch (err) {
|
package/dist/mcp/setup.d.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import type { AgentConfig } from '../types/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Call Mem0 add_memory directly via MCP JSON-RPC (no Claude CLI needed).
|
|
4
|
+
* Spawns mem0-mcp process, sends init + add_memory, reads response.
|
|
5
|
+
*/
|
|
6
|
+
export declare function callMem0AddMemory(text: string, agentName: string): Promise<void>;
|
|
2
7
|
/**
|
|
3
8
|
* Generate MCP server config file for Claude Code.
|
|
4
9
|
* This file is auto-detected by runClaude and passed via --mcp-config.
|
package/dist/mcp/setup.js
CHANGED
|
@@ -20,6 +20,63 @@ const MEM0_ENV_VARS = {
|
|
|
20
20
|
MEM0_NEO4J_USER: 'neo4j',
|
|
21
21
|
MEM0_NEO4J_PASSWORD: 'mem0graph',
|
|
22
22
|
};
|
|
23
|
+
/**
|
|
24
|
+
* Call Mem0 add_memory directly via MCP JSON-RPC (no Claude CLI needed).
|
|
25
|
+
* Spawns mem0-mcp process, sends init + add_memory, reads response.
|
|
26
|
+
*/
|
|
27
|
+
export async function callMem0AddMemory(text, agentName) {
|
|
28
|
+
if (!MEM0_SSH_HOST)
|
|
29
|
+
throw new Error('MEM0_SSH_HOST not configured');
|
|
30
|
+
const { spawn } = await import('child_process');
|
|
31
|
+
const safeAgentName = agentName.replace(/[^a-zA-Z0-9_-]/g, '-').replace(/-+/g, '-').replace(/^-|-$/g, '') || 'agent';
|
|
32
|
+
const envWithUser = { ...MEM0_ENV_VARS, MEM0_USER_ID: safeAgentName };
|
|
33
|
+
let cmd;
|
|
34
|
+
let args;
|
|
35
|
+
let spawnEnv;
|
|
36
|
+
if (MEM0_SSH_HOST === 'local') {
|
|
37
|
+
cmd = 'mem0-mcp';
|
|
38
|
+
args = [];
|
|
39
|
+
spawnEnv = { ...process.env, ...envWithUser };
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
const envString = Object.entries(envWithUser).map(([k, v]) => `${k}=${v}`).join(' ');
|
|
43
|
+
cmd = 'ssh';
|
|
44
|
+
args = ['-p', MEM0_SSH_PORT, '-o', 'StrictHostKeyChecking=no'];
|
|
45
|
+
if (MEM0_SSH_KEY)
|
|
46
|
+
args.push('-i', MEM0_SSH_KEY);
|
|
47
|
+
args.push(MEM0_SSH_HOST, `${envString} mem0-mcp`);
|
|
48
|
+
}
|
|
49
|
+
return new Promise((resolve, reject) => {
|
|
50
|
+
const proc = spawn(cmd, args, { stdio: ['pipe', 'pipe', 'pipe'], env: spawnEnv });
|
|
51
|
+
let stdout = '';
|
|
52
|
+
const timeout = setTimeout(() => { proc.kill(); reject(new Error('Mem0 call timed out')); }, 15000);
|
|
53
|
+
proc.stdout.on('data', (d) => { stdout += d.toString(); });
|
|
54
|
+
proc.stderr.on('data', () => { }); // ignore stderr
|
|
55
|
+
// Send MCP init + add_memory
|
|
56
|
+
const initMsg = JSON.stringify({ jsonrpc: '2.0', id: 1, method: 'initialize', params: { protocolVersion: '2024-11-05', capabilities: {}, clientInfo: { name: 'tuna-agent', version: '1.0' } } });
|
|
57
|
+
const notifyMsg = JSON.stringify({ jsonrpc: '2.0', method: 'notifications/initialized' });
|
|
58
|
+
const addMsg = JSON.stringify({ jsonrpc: '2.0', id: 2, method: 'tools/call', params: { name: 'add_memory', arguments: { text } } });
|
|
59
|
+
proc.stdin.write(initMsg + '\n');
|
|
60
|
+
proc.stdin.write(notifyMsg + '\n');
|
|
61
|
+
proc.stdin.write(addMsg + '\n');
|
|
62
|
+
// Wait for response then close
|
|
63
|
+
const checkDone = () => {
|
|
64
|
+
if (stdout.includes('"id":2') || stdout.includes('"id": 2')) {
|
|
65
|
+
clearTimeout(timeout);
|
|
66
|
+
proc.stdin.end();
|
|
67
|
+
proc.kill();
|
|
68
|
+
if (stdout.includes('"error"')) {
|
|
69
|
+
reject(new Error(`Mem0 error: ${stdout.substring(stdout.lastIndexOf('"error"'), stdout.lastIndexOf('"error"') + 200)}`));
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
resolve();
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
proc.stdout.on('data', checkDone);
|
|
77
|
+
proc.on('close', () => { clearTimeout(timeout); resolve(); });
|
|
78
|
+
});
|
|
79
|
+
}
|
|
23
80
|
/**
|
|
24
81
|
* Build Mem0 MCP server config for an agent.
|
|
25
82
|
* - MEM0_SSH_HOST="local": run mem0-mcp directly (Mem0 infra on same machine)
|
|
@@ -29,7 +86,9 @@ const MEM0_ENV_VARS = {
|
|
|
29
86
|
function buildMem0McpConfig(agentName) {
|
|
30
87
|
if (!MEM0_SSH_HOST)
|
|
31
88
|
return null;
|
|
32
|
-
|
|
89
|
+
// Sanitize agent name for shell safety (replace non-alphanumeric with hyphens)
|
|
90
|
+
const safeAgentName = agentName.replace(/[^a-zA-Z0-9_-]/g, '-').replace(/-+/g, '-').replace(/^-|-$/g, '') || 'agent';
|
|
91
|
+
const envWithUser = { ...MEM0_ENV_VARS, MEM0_USER_ID: safeAgentName };
|
|
33
92
|
if (MEM0_SSH_HOST === 'local') {
|
|
34
93
|
return {
|
|
35
94
|
command: 'mem0-mcp',
|
|
@@ -37,7 +96,7 @@ function buildMem0McpConfig(agentName) {
|
|
|
37
96
|
env: envWithUser,
|
|
38
97
|
};
|
|
39
98
|
}
|
|
40
|
-
const envString = Object.entries(envWithUser).map(([k, v]) => `${k}
|
|
99
|
+
const envString = Object.entries(envWithUser).map(([k, v]) => `${k}=${v}`).join(' ');
|
|
41
100
|
const args = ['-p', MEM0_SSH_PORT, '-o', 'StrictHostKeyChecking=no'];
|
|
42
101
|
if (MEM0_SSH_KEY) {
|
|
43
102
|
args.push('-i', MEM0_SSH_KEY);
|