tuna-agent 0.1.172 → 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.
|
@@ -603,91 +603,89 @@ export class ClaudeCodeAdapter {
|
|
|
603
603
|
status: s.status,
|
|
604
604
|
})),
|
|
605
605
|
});
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
description: s.description,
|
|
622
|
-
dependencies: s.dependencies,
|
|
623
|
-
}))),
|
|
624
|
-
});
|
|
625
|
-
const { text: planApproval } = await waitForInput(task.id, pendingInputResolvers);
|
|
626
|
-
console.log(`[ClaudeCode] Plan approval response: ${planApproval.substring(0, 80)}`);
|
|
627
|
-
// If user requests changes, re-plan with feedback and loop
|
|
628
|
-
if (planApproval.toLowerCase() !== 'approve') {
|
|
629
|
-
console.log(`[ClaudeCode] User requested changes — re-planning with feedback`);
|
|
630
|
-
ws.sendPMMessage(task.id, {
|
|
631
|
-
sender: 'pm',
|
|
632
|
-
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
|
+
}))),
|
|
633
621
|
});
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
if (
|
|
638
|
-
|
|
639
|
-
plan.summary = replanResult.plan.summary;
|
|
640
|
-
plan.subtasks = replanResult.plan.subtasks;
|
|
641
|
-
plan.contracts = replanResult.plan.contracts;
|
|
642
|
-
if (replanResult.sessionId) {
|
|
643
|
-
planResult.pmSessionId = replanResult.sessionId;
|
|
644
|
-
}
|
|
645
|
-
// Send updated plan_ready and recurse approval
|
|
646
|
-
ws.sendPlanReady(task.id, {
|
|
647
|
-
summary: plan.summary,
|
|
648
|
-
contracts: plan.contracts,
|
|
649
|
-
subtasks: plan.subtasks.map((s) => ({
|
|
650
|
-
id: s.id, role: s.role, description: s.description,
|
|
651
|
-
cwd: s.cwd, dependencies: s.dependencies, status: s.status,
|
|
652
|
-
})),
|
|
653
|
-
});
|
|
654
|
-
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`);
|
|
655
627
|
ws.sendPMMessage(task.id, {
|
|
656
628
|
sender: 'pm',
|
|
657
|
-
content: `
|
|
658
|
-
});
|
|
659
|
-
await new Promise(resolve => setTimeout(resolve, 100));
|
|
660
|
-
// Ask for approval again
|
|
661
|
-
ws.sendNeedsInput(task.id, {
|
|
662
|
-
subtaskId: 'plan',
|
|
663
|
-
question: plan.summary,
|
|
664
|
-
options: ['Approve', 'Request Changes'],
|
|
665
|
-
context: JSON.stringify(plan.subtasks.map((s) => ({
|
|
666
|
-
id: s.id, role: s.role, description: s.description, dependencies: s.dependencies,
|
|
667
|
-
}))),
|
|
629
|
+
content: `Got it, adjusting the plan based on your feedback...`,
|
|
668
630
|
});
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
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
|
|
672
680
|
ws.sendPMMessage(task.id, {
|
|
673
681
|
sender: 'pm',
|
|
674
|
-
content:
|
|
682
|
+
content: replanResult.response || `I couldn't create an updated plan. Please try creating a new task.`,
|
|
675
683
|
});
|
|
676
|
-
ws.sendTaskFailed(task.id, '
|
|
677
|
-
console.log(`[ClaudeCode] Task ${task.id} — plan rejected twice, closing`);
|
|
684
|
+
ws.sendTaskFailed(task.id, 'Re-planning failed');
|
|
678
685
|
return;
|
|
679
686
|
}
|
|
680
687
|
}
|
|
681
|
-
|
|
682
|
-
// Re-plan didn't produce subtasks — close
|
|
683
|
-
ws.sendPMMessage(task.id, {
|
|
684
|
-
sender: 'pm',
|
|
685
|
-
content: replanResult.response || `I couldn't create an updated plan. Please try creating a new task.`,
|
|
686
|
-
});
|
|
687
|
-
ws.sendTaskFailed(task.id, 'Re-planning failed');
|
|
688
|
-
return;
|
|
689
|
-
}
|
|
690
|
-
}
|
|
688
|
+
} // end approval gate (multi-subtask plans only)
|
|
691
689
|
console.log(`[ClaudeCode] Plan approved — proceeding to execution`);
|
|
692
690
|
// Step 3: Handle plan questions if any — collect answers to pass to subtasks
|
|
693
691
|
const pmAnswers = [];
|