tuna-agent 0.1.47 → 0.1.48

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,62 @@ 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 { execFile, 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');
248
276
  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) => {
277
+ execFile(claudeBin, ['-p', prompt, '--output-format', 'text'], { timeout: 60000 }, (err, stdout) => {
265
278
  if (err) {
266
- console.warn(`[Mem0 Reflect] Failed: ${err.message}`);
279
+ console.warn(`[Mem0 Reflect] Claude CLI failed: ${err.message}`);
267
280
  resolve('');
268
281
  return;
269
282
  }
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 {
283
+ const reflection = stdout.trim();
284
+ if (!reflection) {
287
285
  resolve('');
286
+ return;
288
287
  }
288
+ console.log(`[Mem0 Reflect] Generated: "${reflection.substring(0, 100)}..."`);
289
+ resolve(reflection);
289
290
  });
290
- // Send input via stdin
291
- child.stdin?.write(input);
292
- child.stdin?.end();
293
291
  });
294
292
  }
295
293
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tuna-agent",
3
- "version": "0.1.47",
3
+ "version": "0.1.48",
4
4
  "description": "Tuna Agent - Run AI coding tasks on your machine",
5
5
  "bin": {
6
6
  "tuna-agent": "dist/cli/index.js"