tuna-agent 0.1.12 → 0.1.14

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.
@@ -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 runClaude({
703
- prompt,
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) {
@@ -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,83 @@ 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
+ let resolved = false;
53
+ const timer = setTimeout(() => { if (!resolved) {
54
+ resolved = true;
55
+ proc.kill();
56
+ reject(new Error('Mem0 call timed out'));
57
+ } }, 15000);
58
+ proc.stderr.on('data', () => { }); // ignore stderr
59
+ const initMsg = JSON.stringify({ jsonrpc: '2.0', id: 1, method: 'initialize', params: { protocolVersion: '2024-11-05', capabilities: {}, clientInfo: { name: 'tuna-agent', version: '1.0' } } });
60
+ const notifyMsg = JSON.stringify({ jsonrpc: '2.0', method: 'notifications/initialized' });
61
+ const addMsg = JSON.stringify({ jsonrpc: '2.0', id: 2, method: 'tools/call', params: { name: 'add_memory', arguments: { text } } });
62
+ let sentAdd = false;
63
+ proc.stdout.on('data', (d) => {
64
+ stdout += d.toString();
65
+ // After init response, send the add_memory call
66
+ if (!sentAdd && stdout.includes('"id":1')) {
67
+ sentAdd = true;
68
+ proc.stdin.write(notifyMsg + '\n');
69
+ proc.stdin.write(addMsg + '\n');
70
+ }
71
+ // After add_memory response, we're done
72
+ if (sentAdd && stdout.includes('"id":2')) {
73
+ if (!resolved) {
74
+ resolved = true;
75
+ clearTimeout(timer);
76
+ proc.stdin.end();
77
+ proc.kill();
78
+ resolve();
79
+ }
80
+ }
81
+ });
82
+ // Send init immediately
83
+ proc.stdin.write(initMsg + '\n');
84
+ proc.on('close', () => {
85
+ if (!resolved) {
86
+ resolved = true;
87
+ clearTimeout(timer);
88
+ resolve();
89
+ }
90
+ });
91
+ proc.on('error', (err) => {
92
+ if (!resolved) {
93
+ resolved = true;
94
+ clearTimeout(timer);
95
+ reject(err);
96
+ }
97
+ });
98
+ });
99
+ }
23
100
  /**
24
101
  * Build Mem0 MCP server config for an agent.
25
102
  * - MEM0_SSH_HOST="local": run mem0-mcp directly (Mem0 infra on same machine)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tuna-agent",
3
- "version": "0.1.12",
3
+ "version": "0.1.14",
4
4
  "description": "Tuna Agent - Run AI coding tasks on your machine",
5
5
  "bin": {
6
6
  "tuna-agent": "dist/cli/index.js"