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.
- package/dist/mcp/setup.d.ts +3 -3
- package/dist/mcp/setup.js +65 -49
- package/package.json +1 -1
package/dist/mcp/setup.d.ts
CHANGED
|
@@ -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
|
|
30
|
-
*
|
|
31
|
-
* Returns a concise lesson learned, or empty string
|
|
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
|
|
236
|
-
*
|
|
237
|
-
* Returns a concise lesson learned, or empty string
|
|
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
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
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
|
-
|
|
250
|
-
let
|
|
251
|
-
let
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
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
|
-
|
|
271
|
-
|
|
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
|
/**
|