tuna-agent 0.1.44 → 0.1.45
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,6 +26,8 @@ export declare class ClaudeCodeAdapter implements AgentAdapter {
|
|
|
26
26
|
private static readonly PATTERN_CHECK_INTERVAL;
|
|
27
27
|
private metricsMap;
|
|
28
28
|
private currentAgentId;
|
|
29
|
+
/** Folder basename of current agent (e.g. "co-founder"). Used as Mem0 user_id. */
|
|
30
|
+
private currentAgentName;
|
|
29
31
|
/** Returns metrics for the currently active agent, initializing if needed. */
|
|
30
32
|
private get metrics();
|
|
31
33
|
constructor(config: AgentConfig);
|
|
@@ -14,9 +14,11 @@ export class ClaudeCodeAdapter {
|
|
|
14
14
|
agentConfig;
|
|
15
15
|
taskCount = 0;
|
|
16
16
|
static PATTERN_CHECK_INTERVAL = 5; // Check patterns every N tasks
|
|
17
|
-
// Per-agent
|
|
17
|
+
// Per-agent state (one daemon handles multiple agents)
|
|
18
18
|
metricsMap = new Map();
|
|
19
19
|
currentAgentId = '';
|
|
20
|
+
/** Folder basename of current agent (e.g. "co-founder"). Used as Mem0 user_id. */
|
|
21
|
+
currentAgentName = '';
|
|
20
22
|
/** Returns metrics for the currently active agent, initializing if needed. */
|
|
21
23
|
get metrics() {
|
|
22
24
|
if (!this.metricsMap.has(this.currentAgentId)) {
|
|
@@ -85,8 +87,10 @@ export class ClaudeCodeAdapter {
|
|
|
85
87
|
: undefined;
|
|
86
88
|
// Default mode: direct chat with Claude CLI (no PM layer)
|
|
87
89
|
// Only use PM planning when mode is explicitly 'tuna'
|
|
88
|
-
// Set current agent context
|
|
90
|
+
// Set current agent context (metrics + Mem0 identity)
|
|
89
91
|
this.currentAgentId = task.agentId || '';
|
|
92
|
+
const defaultWorkspaceEarly = path.join(os.homedir(), 'tuna-workspace');
|
|
93
|
+
this.currentAgentName = path.basename(task.repoPath || defaultWorkspaceEarly);
|
|
90
94
|
if (task.mode !== 'tuna') {
|
|
91
95
|
console.log(`[ClaudeCode] Agent Team mode — direct chat with Claude CLI`);
|
|
92
96
|
ws.sendProgress(task.id, 'executing', { startedAt: new Date().toISOString() });
|
|
@@ -107,12 +111,10 @@ export class ClaudeCodeAdapter {
|
|
|
107
111
|
}
|
|
108
112
|
}
|
|
109
113
|
// Pre-task Memory Recall: search Mem0 for relevant past learnings
|
|
110
|
-
const defaultWorkspaceForRecall = path.join(os.homedir(), 'tuna-workspace');
|
|
111
|
-
const recallAgentName = path.basename(task.repoPath || defaultWorkspaceForRecall);
|
|
112
114
|
if (process.env.MEM0_SSH_HOST && task.description.length >= 20) {
|
|
113
115
|
try {
|
|
114
116
|
const { callMem0SearchMemory } = await import('../mcp/setup.js');
|
|
115
|
-
const memories = await callMem0SearchMemory(task.description,
|
|
117
|
+
const memories = await callMem0SearchMemory(task.description, this.currentAgentName, 5);
|
|
116
118
|
if (memories.length > 0) {
|
|
117
119
|
const memoryContext = memories.map(m => `- ${m}`).join('\n');
|
|
118
120
|
userMessage = `${task.description}\n\n<past_learnings>\nRelevant lessons from previous tasks:\n${memoryContext}\n</past_learnings>`;
|
|
@@ -140,11 +142,10 @@ export class ClaudeCodeAdapter {
|
|
|
140
142
|
if (round === 0) {
|
|
141
143
|
writeAgentFolderMcpConfig(cwd, this.agentConfig);
|
|
142
144
|
// Seed memoryCount from Mem0 so it survives daemon restarts (non-blocking)
|
|
143
|
-
|
|
144
|
-
fetchMem0Count(agentFolderName).then(count => {
|
|
145
|
+
fetchMem0Count(this.currentAgentName).then(count => {
|
|
145
146
|
if (count > this.metrics.memoryCount) {
|
|
146
147
|
this.metrics.memoryCount = count;
|
|
147
|
-
console.log(`[Metrics] Seeded memoryCount=${count} from Mem0 for "${
|
|
148
|
+
console.log(`[Metrics] Seeded memoryCount=${count} from Mem0 for "${this.currentAgentName}"`);
|
|
148
149
|
}
|
|
149
150
|
}).catch(() => { });
|
|
150
151
|
}
|
|
@@ -749,9 +750,8 @@ export class ClaudeCodeAdapter {
|
|
|
749
750
|
return;
|
|
750
751
|
}
|
|
751
752
|
// Step 2: Store the AI-generated reflection in Mem0
|
|
752
|
-
const agentFolderNameForReflection = path.basename(cwd);
|
|
753
753
|
console.log(`[Reflection] Storing: "${aiReflection.substring(0, 100)}..."`);
|
|
754
|
-
await callMem0AddMemory(aiReflection,
|
|
754
|
+
await callMem0AddMemory(aiReflection, this.currentAgentName);
|
|
755
755
|
this.metrics.reflectionCount++;
|
|
756
756
|
this.metrics.memoryCount++;
|
|
757
757
|
this.metrics.lastReflectionAt = new Date().toISOString();
|
|
@@ -765,7 +765,7 @@ export class ClaudeCodeAdapter {
|
|
|
765
765
|
? `Task failed: "${task.description.substring(0, 150)}". Error: ${resultSummary.substring(0, 200)}`
|
|
766
766
|
: `Task completed: "${task.description.substring(0, 150)}". Result: ${resultSummary.substring(0, 200)}`;
|
|
767
767
|
const { callMem0AddMemory } = await import('../mcp/setup.js');
|
|
768
|
-
await callMem0AddMemory(fallback,
|
|
768
|
+
await callMem0AddMemory(fallback, this.currentAgentName);
|
|
769
769
|
}
|
|
770
770
|
catch {
|
|
771
771
|
// Both AI and fallback failed — give up silently
|
|
@@ -788,7 +788,7 @@ export class ClaudeCodeAdapter {
|
|
|
788
788
|
try {
|
|
789
789
|
console.log(`[Rating→Mem0] Storing rating for task "${data.taskTitle}" (${data.score > 0 ? '👍' : '👎'})`);
|
|
790
790
|
const { callMem0AddMemory } = await import('../mcp/setup.js');
|
|
791
|
-
await callMem0AddMemory(memoryText,
|
|
791
|
+
await callMem0AddMemory(memoryText, this.currentAgentName);
|
|
792
792
|
console.log(`[Rating→Mem0] Rating stored successfully`);
|
|
793
793
|
}
|
|
794
794
|
catch (err) {
|
|
@@ -808,7 +808,7 @@ export class ClaudeCodeAdapter {
|
|
|
808
808
|
try {
|
|
809
809
|
console.log(`[Self-Improve] Running pattern detection (every ${ClaudeCodeAdapter.PATTERN_CHECK_INTERVAL} tasks, count=${this.taskCount})`);
|
|
810
810
|
const { callMem0Patterns } = await import('../mcp/setup.js');
|
|
811
|
-
const patterns = await callMem0Patterns(
|
|
811
|
+
const patterns = await callMem0Patterns(this.currentAgentName, 3);
|
|
812
812
|
if (patterns.length === 0) {
|
|
813
813
|
console.log(`[Self-Improve] No patterns detected yet`);
|
|
814
814
|
return;
|