tuna-agent 0.1.47 → 0.1.49

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.
@@ -26,9 +26,9 @@ export declare function callMem0Patterns(agentName: string, minCluster?: number)
26
26
  sources: string[];
27
27
  }>>;
28
28
  /**
29
- * Generate AI-powered reflection from task results using Ollama.
30
- * Calls mem0-reflect script on relabs01 via SSH.
31
- * Returns a concise lesson learned, or empty string if nothing meaningful.
29
+ * Generate AI-powered reflection from task results using Claude CLI (-p mode).
30
+ * Spawns `claude -p <prompt>` locally uses existing Claude subscription, no extra cost.
31
+ * Returns a concise lesson learned, or empty string on failure.
32
32
  */
33
33
  export declare function callMem0Reflect(taskDesc: string, resultSummary: string, status: 'done' | 'failed'): Promise<string>;
34
34
  /**
package/dist/mcp/setup.js CHANGED
@@ -232,64 +232,80 @@ export async function callMem0Patterns(agentName, minCluster = 3) {
232
232
  });
233
233
  }
234
234
  /**
235
- * Generate AI-powered reflection from task results using Ollama.
236
- * Calls mem0-reflect script on relabs01 via SSH.
237
- * Returns a concise lesson learned, or empty string if nothing meaningful.
235
+ * Generate AI-powered reflection from task results using Claude CLI (-p mode).
236
+ * Spawns `claude -p <prompt>` locally uses existing Claude subscription, no extra cost.
237
+ * Returns a concise lesson learned, or empty string on failure.
238
238
  */
239
239
  export async function callMem0Reflect(taskDesc, resultSummary, status) {
240
- if (!MEM0_SSH_HOST)
241
- return '';
242
- const { execFile } = await import('child_process');
243
- const input = JSON.stringify({
244
- task: taskDesc.substring(0, 300),
245
- result: resultSummary.substring(0, 500),
246
- status,
247
- });
240
+ const { execSync } = await import('child_process');
241
+ // Resolve claude binary path (same search logic as claude-cli.ts)
242
+ let claudeBin = 'claude';
243
+ try {
244
+ const searchPaths = [
245
+ process.env.PATH,
246
+ '/opt/homebrew/bin',
247
+ '/usr/local/bin',
248
+ `${process.env.HOME}/.local/bin`,
249
+ `${process.env.HOME}/.npm-global/bin`,
250
+ '/usr/bin',
251
+ ].filter(Boolean).join(':');
252
+ claudeBin = execSync('which claude', {
253
+ encoding: 'utf-8',
254
+ env: { ...process.env, PATH: searchPaths },
255
+ stdio: ['ignore', 'pipe', 'ignore'],
256
+ }).trim();
257
+ }
258
+ catch { /* fall back to 'claude' */ }
259
+ const prompt = [
260
+ 'You are an AI agent reflecting on a completed task.',
261
+ 'Extract 1-2 concise, actionable lessons learned that would help with similar future tasks.',
262
+ '',
263
+ `Task: ${taskDesc.substring(0, 300)}`,
264
+ `Status: ${status}`,
265
+ `Result summary: ${resultSummary.substring(0, 600)}`,
266
+ '',
267
+ 'Rules:',
268
+ '- ALWAYS extract at least 1 lesson — there is always something to note',
269
+ '- Be specific: tool names, patterns, pitfalls, or key findings worth remembering',
270
+ '- If task failed: focus on what went wrong and how to avoid it next time',
271
+ '- If task succeeded: note the approach or insight that was most useful',
272
+ '- Keep each lesson to 1 sentence, no bullet points, no preamble',
273
+ '',
274
+ 'Lessons learned:',
275
+ ].join('\n');
276
+ // Use spawn with stdin='ignore' — execFile keeps stdin pipe open which causes claude to hang/SIGTERM
277
+ const { spawn } = await import('child_process');
248
278
  return new Promise((resolve) => {
249
- let cmd;
250
- let args;
251
- let options = {};
252
- if (MEM0_SSH_HOST === 'local') {
253
- cmd = 'mem0-reflect';
254
- args = [];
255
- options.env = { ...process.env };
256
- }
257
- else {
258
- cmd = 'ssh';
259
- args = ['-p', MEM0_SSH_PORT, '-o', 'StrictHostKeyChecking=no'];
260
- if (MEM0_SSH_KEY)
261
- args.push('-i', MEM0_SSH_KEY);
262
- args.push(MEM0_SSH_HOST, 'mem0-reflect');
263
- }
264
- const child = execFile(cmd, args, { ...options, timeout: 90000 }, (err, stdout) => {
265
- if (err) {
266
- console.warn(`[Mem0 Reflect] Failed: ${err.message}`);
279
+ const child = spawn(claudeBin, ['-p', prompt, '--output-format', 'text'], { stdio: ['ignore', 'pipe', 'pipe'] });
280
+ let stdout = '';
281
+ let stderr = '';
282
+ child.stdout.on('data', (d) => { stdout += d.toString(); });
283
+ child.stderr.on('data', (d) => { stderr += d.toString(); });
284
+ const timer = setTimeout(() => {
285
+ child.kill();
286
+ console.warn('[Mem0 Reflect] Claude CLI timed out after 60s');
287
+ resolve('');
288
+ }, 60000);
289
+ child.on('close', (code) => {
290
+ clearTimeout(timer);
291
+ if (code !== 0) {
292
+ console.warn(`[Mem0 Reflect] Claude CLI exited ${code}: ${stderr.substring(0, 200)}`);
267
293
  resolve('');
268
294
  return;
269
295
  }
270
- try {
271
- const data = JSON.parse(stdout.trim());
272
- if (data.error) {
273
- console.warn(`[Mem0 Reflect] Error: ${data.error}`);
274
- resolve('');
275
- return;
276
- }
277
- if (data.skipped) {
278
- console.log(`[Mem0 Reflect] Skipped — nothing meaningful to learn`);
279
- resolve('');
280
- return;
281
- }
282
- // Clean up: remove trailing SKIP if LLM appended it
283
- let reflection = (data.reflection || '').replace(/\s*SKIP\s*$/i, '').trim();
284
- resolve(reflection);
285
- }
286
- catch {
296
+ const reflection = stdout.trim();
297
+ if (!reflection) {
287
298
  resolve('');
299
+ return;
288
300
  }
301
+ console.log(`[Mem0 Reflect] Generated: "${reflection.substring(0, 100)}..."`);
302
+ resolve(reflection);
303
+ });
304
+ child.on('error', (err) => {
305
+ clearTimeout(timer);
306
+ console.warn(`[Mem0 Reflect] Spawn error: ${err.message}`);
307
+ resolve('');
289
308
  });
290
- // Send input via stdin
291
- child.stdin?.write(input);
292
- child.stdin?.end();
293
309
  });
294
310
  }
295
311
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tuna-agent",
3
- "version": "0.1.47",
3
+ "version": "0.1.49",
4
4
  "description": "Tuna Agent - Run AI coding tasks on your machine",
5
5
  "bin": {
6
6
  "tuna-agent": "dist/cli/index.js"