tuna-agent 0.1.69 → 0.1.70

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.
@@ -38,6 +38,8 @@ export declare class ClaudeCodeAdapter implements AgentAdapter {
38
38
  private currentAgentName;
39
39
  /** Returns metrics for the currently active agent, initializing if needed. */
40
40
  private get metrics();
41
+ /** Returns metrics for a specific agent by ID (safe for parallel execution). */
42
+ getMetricsForAgent(agentId: string): AgentMetrics;
41
43
  constructor(config: AgentConfig);
42
44
  /** Resolve CLAUDE.md path — check root first, then .claude/ subfolder. */
43
45
  static resolveClaudeMdPath(folder: string): string;
@@ -23,8 +23,12 @@ export class ClaudeCodeAdapter {
23
23
  currentAgentName = '';
24
24
  /** Returns metrics for the currently active agent, initializing if needed. */
25
25
  get metrics() {
26
- if (!this.metricsMap.has(this.currentAgentId)) {
27
- this.metricsMap.set(this.currentAgentId, {
26
+ return this.getMetricsForAgent(this.currentAgentId);
27
+ }
28
+ /** Returns metrics for a specific agent by ID (safe for parallel execution). */
29
+ getMetricsForAgent(agentId) {
30
+ if (!this.metricsMap.has(agentId)) {
31
+ this.metricsMap.set(agentId, {
28
32
  taskCount: 0,
29
33
  successCount: 0,
30
34
  failCount: 0,
@@ -42,7 +46,7 @@ export class ClaudeCodeAdapter {
42
46
  upSince: new Date().toISOString(),
43
47
  });
44
48
  }
45
- return this.metricsMap.get(this.currentAgentId);
49
+ return this.metricsMap.get(agentId);
46
50
  }
47
51
  constructor(config) {
48
52
  this.agentConfig = config;
@@ -810,22 +814,26 @@ export class ClaudeCodeAdapter {
810
814
  const MIN_DESCRIPTION_LENGTH = 20;
811
815
  if (task.description.length < MIN_DESCRIPTION_LENGTH)
812
816
  return;
817
+ // Derive agent name from cwd (safe for parallel execution — no shared state)
818
+ const agentName = path.basename(cwd) || this.currentAgentName;
819
+ const agentId = task.agentId || this.currentAgentId;
813
820
  try {
814
821
  // Step 1: Generate AI-powered reflection via Ollama
815
822
  console.log(`[Reflection] Generating AI reflection for task ${task.id} (${status}), input: ${resultSummary.substring(0, 150)}...`);
816
823
  const { callMem0Reflect, callMem0AddMemory } = await import('../mcp/setup.js');
817
824
  const aiReflection = await callMem0Reflect(task.description, resultSummary, status);
818
825
  if (!aiReflection) {
819
- this.metrics.reflectionSkipCount++;
826
+ this.getMetricsForAgent(agentId).reflectionSkipCount++;
820
827
  console.log(`[Reflection] No meaningful lesson — skipping storage for task ${task.id}`);
821
828
  return;
822
829
  }
823
830
  // Step 2: Store the AI-generated reflection in Mem0
824
831
  console.log(`[Reflection] Storing: "${aiReflection.substring(0, 100)}..."`);
825
- await callMem0AddMemory(aiReflection, this.currentAgentName);
826
- this.metrics.reflectionCount++;
827
- this.metrics.memoryCount++;
828
- this.metrics.lastReflectionAt = new Date().toISOString();
832
+ await callMem0AddMemory(aiReflection, agentName);
833
+ const m = this.getMetricsForAgent(agentId);
834
+ m.reflectionCount++;
835
+ m.memoryCount++;
836
+ m.lastReflectionAt = new Date().toISOString();
829
837
  console.log(`[Reflection] Stored for task ${task.id}`);
830
838
  }
831
839
  catch (err) {
@@ -836,7 +844,7 @@ export class ClaudeCodeAdapter {
836
844
  ? `Task failed: "${task.description.substring(0, 150)}". Error: ${resultSummary.substring(0, 200)}`
837
845
  : `Task completed: "${task.description.substring(0, 150)}". Result: ${resultSummary.substring(0, 200)}`;
838
846
  const { callMem0AddMemory } = await import('../mcp/setup.js');
839
- await callMem0AddMemory(fallback, this.currentAgentName);
847
+ await callMem0AddMemory(fallback, agentName);
840
848
  }
841
849
  catch {
842
850
  // Both AI and fallback failed — give up silently
@@ -859,7 +867,8 @@ export class ClaudeCodeAdapter {
859
867
  try {
860
868
  console.log(`[Rating→Mem0] Storing rating for task "${data.taskTitle}" (${data.score > 0 ? '👍' : '👎'})`);
861
869
  const { callMem0AddMemory } = await import('../mcp/setup.js');
862
- await callMem0AddMemory(memoryText, this.currentAgentName);
870
+ const agentName = path.basename(data.cwd) || this.currentAgentName;
871
+ await callMem0AddMemory(memoryText, agentName);
863
872
  console.log(`[Rating→Mem0] Rating stored successfully`);
864
873
  }
865
874
  catch (err) {
@@ -897,7 +906,8 @@ export class ClaudeCodeAdapter {
897
906
  try {
898
907
  console.log(`[Self-Improve] Running pattern detection (every ${ClaudeCodeAdapter.PATTERN_CHECK_INTERVAL} tasks, count=${this.taskCount})`);
899
908
  const { callMem0Patterns } = await import('../mcp/setup.js');
900
- const patterns = await callMem0Patterns(this.currentAgentName, 2);
909
+ const agentName = path.basename(cwd) || this.currentAgentName;
910
+ const patterns = await callMem0Patterns(agentName, 2);
901
911
  if (patterns.length === 0) {
902
912
  console.log(`[Self-Improve] No patterns detected yet`);
903
913
  return;
@@ -229,15 +229,8 @@ export async function startDaemon(config) {
229
229
  currentTaskId = task.id;
230
230
  currentTaskAbort = abort;
231
231
  console.log(`[Daemon] Received task: ${task.id} agent=${agentId} — ${task.description.slice(0, 80)} (attachments: ${task.attachments?.length ?? 0}) [active: ${activeTasks}]`);
232
- // Update MCP config with the task's agent ID so knowledge server uses correct attribution
233
- if (task.agentId) {
234
- try {
235
- setupMcpConfig({ ...config, agentId: task.agentId });
236
- }
237
- catch (err) {
238
- console.warn(`[Daemon] MCP config update for task failed (non-fatal):`, err);
239
- }
240
- }
232
+ // MCP config per-agent is handled by writeAgentFolderMcpConfig in adapter
233
+ // (writes per-agent .mcp.json in agent folder — safe for parallel execution)
241
234
  // Run task in background (non-blocking) to allow parallel agent execution
242
235
  (async () => {
243
236
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tuna-agent",
3
- "version": "0.1.69",
3
+ "version": "0.1.70",
4
4
  "description": "Tuna Agent - Run AI coding tasks on your machine",
5
5
  "bin": {
6
6
  "tuna-agent": "dist/cli/index.js"