From d7c333733066e26a1bc0d3e738c4d49adf612ff0 Mon Sep 17 00:00:00 2001 From: Kacper Date: Mon, 26 Jan 2026 19:53:07 +0100 Subject: [PATCH] refactor(auto-mode): Enhance revision prompt customization and task format validation - Updated the revision prompt generation to utilize a customizable template, allowing for dynamic insertion of plan version, previous plan content, user feedback, and task format examples. - Added validation to ensure the presence of a tasks block in the revised specification, with clear instructions on the required format to prevent execution issues. - Introduced logging for scenarios where no tasks are found in the revised plan, warning about potential fallback to single-agent execution. --- apps/server/src/services/auto-mode-service.ts | 81 +++++++++++++++---- libs/prompts/src/defaults.ts | 16 +++- 2 files changed, 81 insertions(+), 16 deletions(-) diff --git a/apps/server/src/services/auto-mode-service.ts b/apps/server/src/services/auto-mode-service.ts index 1fae8907e..36ae4a2e4 100644 --- a/apps/server/src/services/auto-mode-service.ts +++ b/apps/server/src/services/auto-mode-service.ts @@ -4597,21 +4597,54 @@ This mock response was generated because AUTOMAKER_MOCK_AGENT=true was set. planVersion, }); - // Build revision prompt - let revisionPrompt = `The user has requested revisions to the plan/specification. - -## Previous Plan (v${planVersion - 1}) -${hasEdits ? approvalResult.editedPlan : currentPlanContent} - -## User Feedback -${approvalResult.feedback || 'Please revise the plan based on the edits above.'} + // Build revision prompt using customizable template + const revisionPrompts = await getPromptCustomization( + this.settingsService, + '[AutoMode]' + ); -## Instructions -Please regenerate the specification incorporating the user's feedback. -Keep the same format with the \`\`\`tasks block for task definitions. -After generating the revised spec, output: -"[SPEC_GENERATED] Please review the revised specification above." -`; + // Get task format example based on planning mode + const taskFormatExample = + planningMode === 'full' + ? `\`\`\`tasks +## Phase 1: Foundation +- [ ] T001: [Description] | File: [path/to/file] +- [ ] T002: [Description] | File: [path/to/file] + +## Phase 2: Core Implementation +- [ ] T003: [Description] | File: [path/to/file] +- [ ] T004: [Description] | File: [path/to/file] +\`\`\`` + : `\`\`\`tasks +- [ ] T001: [Description] | File: [path/to/file] +- [ ] T002: [Description] | File: [path/to/file] +- [ ] T003: [Description] | File: [path/to/file] +\`\`\``; + + let revisionPrompt = revisionPrompts.taskExecution.planRevisionTemplate; + revisionPrompt = revisionPrompt.replace( + /\{\{planVersion\}\}/g, + String(planVersion - 1) + ); + revisionPrompt = revisionPrompt.replace( + /\{\{previousPlan\}\}/g, + hasEdits + ? approvalResult.editedPlan || currentPlanContent + : currentPlanContent + ); + revisionPrompt = revisionPrompt.replace( + /\{\{userFeedback\}\}/g, + approvalResult.feedback || + 'Please revise the plan based on the edits above.' + ); + revisionPrompt = revisionPrompt.replace( + /\{\{planningMode\}\}/g, + planningMode + ); + revisionPrompt = revisionPrompt.replace( + /\{\{taskFormatExample\}\}/g, + taskFormatExample + ); // Update status to regenerating await this.updateFeaturePlanSpec(projectPath, featureId, { @@ -4663,6 +4696,26 @@ After generating the revised spec, output: const revisedTasks = parseTasksFromSpec(currentPlanContent); logger.info(`Revised plan has ${revisedTasks.length} tasks`); + // Warn if no tasks found in spec/full mode - this may cause fallback to single-agent + if ( + revisedTasks.length === 0 && + (planningMode === 'spec' || planningMode === 'full') + ) { + logger.warn( + `WARNING: Revised plan in ${planningMode} mode has no tasks! ` + + `This will cause fallback to single-agent execution. ` + + `The AI may have omitted the required \`\`\`tasks block.` + ); + this.emitAutoModeEvent('plan_revision_warning', { + featureId, + projectPath, + branchName, + planningMode, + warning: + 'Revised plan missing tasks block - will use single-agent execution', + }); + } + // Update planSpec with revised content await this.updateFeaturePlanSpec(projectPath, featureId, { status: 'generated', diff --git a/libs/prompts/src/defaults.ts b/libs/prompts/src/defaults.ts index 48772de9c..bcbc6febd 100644 --- a/libs/prompts/src/defaults.ts +++ b/libs/prompts/src/defaults.ts @@ -965,8 +965,20 @@ export const DEFAULT_PLAN_REVISION_TEMPLATE = `The user has requested revisions ## Instructions Please regenerate the specification incorporating the user's feedback. -Keep the same format with the \`\`\`tasks block for task definitions. -After generating the revised spec, output: +**Current planning mode: {{planningMode}}** + +**CRITICAL REQUIREMENT**: Your revised specification MUST include a \`\`\`tasks code block containing task definitions in the EXACT format shown below. This is MANDATORY - without the tasks block, the system cannot track or execute tasks properly. + +### Required Task Format +{{taskFormatExample}} + +**IMPORTANT**: +1. The \`\`\`tasks block must appear in your response +2. Each task MUST start with "- [ ] T###:" where ### is a sequential number (T001, T002, T003, etc.) +3. Each task MUST include "| File:" followed by the primary file path +4. Tasks should be ordered by dependencies (foundational tasks first) + +After generating the revised spec with the tasks block, output: "[SPEC_GENERATED] Please review the revised specification above."`; export const DEFAULT_CONTINUATION_AFTER_APPROVAL_TEMPLATE = `The plan/specification has been approved. Now implement it.