tuna-agent 0.1.171 → 0.1.173
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.
|
@@ -474,10 +474,9 @@ export class ClaudeCodeAdapter {
|
|
|
474
474
|
// Step 1: Planning
|
|
475
475
|
console.log(`[ClaudeCode] Starting planning for task ${task.id}`);
|
|
476
476
|
ws.sendProgress(task.id, 'planning', { startedAt: new Date().toISOString() });
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
});
|
|
477
|
+
// No generic canned "thinking" line — it breaks the agent's persona voice.
|
|
478
|
+
// The agent's own (persona-driven) output leads instead. The 'planning' status
|
|
479
|
+
// above already signals activity to the app/Discord.
|
|
481
480
|
let planFirstChunkIso = '';
|
|
482
481
|
let planChunkCount = 0;
|
|
483
482
|
let planResult = await planTask(task, (event, data) => {
|
|
@@ -604,91 +603,89 @@ export class ClaudeCodeAdapter {
|
|
|
604
603
|
status: s.status,
|
|
605
604
|
})),
|
|
606
605
|
});
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
description: s.description,
|
|
623
|
-
dependencies: s.dependencies,
|
|
624
|
-
}))),
|
|
625
|
-
});
|
|
626
|
-
const { text: planApproval } = await waitForInput(task.id, pendingInputResolvers);
|
|
627
|
-
console.log(`[ClaudeCode] Plan approval response: ${planApproval.substring(0, 80)}`);
|
|
628
|
-
// If user requests changes, re-plan with feedback and loop
|
|
629
|
-
if (planApproval.toLowerCase() !== 'approve') {
|
|
630
|
-
console.log(`[ClaudeCode] User requested changes — re-planning with feedback`);
|
|
631
|
-
ws.sendPMMessage(task.id, {
|
|
632
|
-
sender: 'pm',
|
|
633
|
-
content: `Got it, adjusting the plan based on your feedback...`,
|
|
606
|
+
// Auto-approve single-subtask ('self') plans — no plan-review friction for
|
|
607
|
+
// simple own-domain work. Only complex multi-subtask builds ask for approval.
|
|
608
|
+
if (plan.subtasks.length > 1) {
|
|
609
|
+
// Step 2: Wait for user to approve the plan
|
|
610
|
+
console.log(`[ClaudeCode] Waiting for plan approval for task ${task.id}`);
|
|
611
|
+
ws.sendNeedsInput(task.id, {
|
|
612
|
+
subtaskId: 'plan',
|
|
613
|
+
question: plan.summary,
|
|
614
|
+
options: ['Approve', 'Request Changes'],
|
|
615
|
+
context: JSON.stringify(plan.subtasks.map((s) => ({
|
|
616
|
+
id: s.id,
|
|
617
|
+
role: s.role,
|
|
618
|
+
description: s.description,
|
|
619
|
+
dependencies: s.dependencies,
|
|
620
|
+
}))),
|
|
634
621
|
});
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
if (
|
|
639
|
-
|
|
640
|
-
plan.summary = replanResult.plan.summary;
|
|
641
|
-
plan.subtasks = replanResult.plan.subtasks;
|
|
642
|
-
plan.contracts = replanResult.plan.contracts;
|
|
643
|
-
if (replanResult.sessionId) {
|
|
644
|
-
planResult.pmSessionId = replanResult.sessionId;
|
|
645
|
-
}
|
|
646
|
-
// Send updated plan_ready and recurse approval
|
|
647
|
-
ws.sendPlanReady(task.id, {
|
|
648
|
-
summary: plan.summary,
|
|
649
|
-
contracts: plan.contracts,
|
|
650
|
-
subtasks: plan.subtasks.map((s) => ({
|
|
651
|
-
id: s.id, role: s.role, description: s.description,
|
|
652
|
-
cwd: s.cwd, dependencies: s.dependencies, status: s.status,
|
|
653
|
-
})),
|
|
654
|
-
});
|
|
655
|
-
const updatedRoles = plan.subtasks.map((s) => s.role).join(', ');
|
|
622
|
+
const { text: planApproval } = await waitForInput(task.id, pendingInputResolvers);
|
|
623
|
+
console.log(`[ClaudeCode] Plan approval response: ${planApproval.substring(0, 80)}`);
|
|
624
|
+
// If user requests changes, re-plan with feedback and loop
|
|
625
|
+
if (planApproval.toLowerCase() !== 'approve') {
|
|
626
|
+
console.log(`[ClaudeCode] User requested changes — re-planning with feedback`);
|
|
656
627
|
ws.sendPMMessage(task.id, {
|
|
657
628
|
sender: 'pm',
|
|
658
|
-
content: `
|
|
629
|
+
content: `Got it, adjusting the plan based on your feedback...`,
|
|
659
630
|
});
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
ws.
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
631
|
+
ws.sendProgress(task.id, 'planning', { startedAt: new Date().toISOString() });
|
|
632
|
+
const replanResult = await chatWithPM(planResult.pmSessionId || '', task.repoPath, `The user wants changes to the plan. Their feedback: "${planApproval}"\n\nPlease create an updated execution plan as JSON.`, signal, (chunk) => { ws.sendPMStream(task.id, chunk); });
|
|
633
|
+
ws.sendPMStreamEnd(task.id, `pm-replan-${Date.now()}`);
|
|
634
|
+
if (replanResult.plan && replanResult.plan.subtasks.length > 0) {
|
|
635
|
+
// Replace plan with updated version
|
|
636
|
+
plan.summary = replanResult.plan.summary;
|
|
637
|
+
plan.subtasks = replanResult.plan.subtasks;
|
|
638
|
+
plan.contracts = replanResult.plan.contracts;
|
|
639
|
+
if (replanResult.sessionId) {
|
|
640
|
+
planResult.pmSessionId = replanResult.sessionId;
|
|
641
|
+
}
|
|
642
|
+
// Send updated plan_ready and recurse approval
|
|
643
|
+
ws.sendPlanReady(task.id, {
|
|
644
|
+
summary: plan.summary,
|
|
645
|
+
contracts: plan.contracts,
|
|
646
|
+
subtasks: plan.subtasks.map((s) => ({
|
|
647
|
+
id: s.id, role: s.role, description: s.description,
|
|
648
|
+
cwd: s.cwd, dependencies: s.dependencies, status: s.status,
|
|
649
|
+
})),
|
|
650
|
+
});
|
|
651
|
+
const updatedRoles = plan.subtasks.map((s) => s.role).join(', ');
|
|
652
|
+
ws.sendPMMessage(task.id, {
|
|
653
|
+
sender: 'pm',
|
|
654
|
+
content: `Updated plan: ${plan.summary}\n\n${plan.subtasks.length} session${plan.subtasks.length > 1 ? 's' : ''}: ${updatedRoles}.`,
|
|
655
|
+
});
|
|
656
|
+
await new Promise(resolve => setTimeout(resolve, 100));
|
|
657
|
+
// Ask for approval again
|
|
658
|
+
ws.sendNeedsInput(task.id, {
|
|
659
|
+
subtaskId: 'plan',
|
|
660
|
+
question: plan.summary,
|
|
661
|
+
options: ['Approve', 'Request Changes'],
|
|
662
|
+
context: JSON.stringify(plan.subtasks.map((s) => ({
|
|
663
|
+
id: s.id, role: s.role, description: s.description, dependencies: s.dependencies,
|
|
664
|
+
}))),
|
|
665
|
+
});
|
|
666
|
+
const { text: secondApproval } = await waitForInput(task.id, pendingInputResolvers);
|
|
667
|
+
console.log(`[ClaudeCode] Second plan approval: ${secondApproval.substring(0, 80)}`);
|
|
668
|
+
if (secondApproval.toLowerCase() !== 'approve') {
|
|
669
|
+
ws.sendPMMessage(task.id, {
|
|
670
|
+
sender: 'pm',
|
|
671
|
+
content: `Understood. I'll cancel this task. You can create a new one when ready.`,
|
|
672
|
+
});
|
|
673
|
+
ws.sendTaskFailed(task.id, 'Plan not approved by user');
|
|
674
|
+
console.log(`[ClaudeCode] Task ${task.id} — plan rejected twice, closing`);
|
|
675
|
+
return;
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
else {
|
|
679
|
+
// Re-plan didn't produce subtasks — close
|
|
673
680
|
ws.sendPMMessage(task.id, {
|
|
674
681
|
sender: 'pm',
|
|
675
|
-
content:
|
|
682
|
+
content: replanResult.response || `I couldn't create an updated plan. Please try creating a new task.`,
|
|
676
683
|
});
|
|
677
|
-
ws.sendTaskFailed(task.id, '
|
|
678
|
-
console.log(`[ClaudeCode] Task ${task.id} — plan rejected twice, closing`);
|
|
684
|
+
ws.sendTaskFailed(task.id, 'Re-planning failed');
|
|
679
685
|
return;
|
|
680
686
|
}
|
|
681
687
|
}
|
|
682
|
-
|
|
683
|
-
// Re-plan didn't produce subtasks — close
|
|
684
|
-
ws.sendPMMessage(task.id, {
|
|
685
|
-
sender: 'pm',
|
|
686
|
-
content: replanResult.response || `I couldn't create an updated plan. Please try creating a new task.`,
|
|
687
|
-
});
|
|
688
|
-
ws.sendTaskFailed(task.id, 'Re-planning failed');
|
|
689
|
-
return;
|
|
690
|
-
}
|
|
691
|
-
}
|
|
688
|
+
} // end approval gate (multi-subtask plans only)
|
|
692
689
|
console.log(`[ClaudeCode] Plan approved — proceeding to execution`);
|
|
693
690
|
// Step 3: Handle plan questions if any — collect answers to pass to subtasks
|
|
694
691
|
const pmAnswers = [];
|