source dump of claude code
at main 170 lines 7.8 kB view raw
1import { isPlanModeInterviewPhaseEnabled } from '../../utils/planModeV2.js' 2import { ASK_USER_QUESTION_TOOL_NAME } from '../AskUserQuestionTool/prompt.js' 3 4const WHAT_HAPPENS_SECTION = `## What Happens in Plan Mode 5 6In plan mode, you'll: 71. Thoroughly explore the codebase using Glob, Grep, and Read tools 82. Understand existing patterns and architecture 93. Design an implementation approach 104. Present your plan to the user for approval 115. Use ${ASK_USER_QUESTION_TOOL_NAME} if you need to clarify approaches 126. Exit plan mode with ExitPlanMode when ready to implement 13 14` 15 16function getEnterPlanModeToolPromptExternal(): string { 17 // When interview phase is enabled, omit the "What Happens" section — 18 // detailed workflow instructions arrive via the plan_mode attachment (messages.ts). 19 const whatHappens = isPlanModeInterviewPhaseEnabled() 20 ? '' 21 : WHAT_HAPPENS_SECTION 22 23 return `Use this tool proactively when you're about to start a non-trivial implementation task. Getting user sign-off on your approach before writing code prevents wasted effort and ensures alignment. This tool transitions you into plan mode where you can explore the codebase and design an implementation approach for user approval. 24 25## When to Use This Tool 26 27**Prefer using EnterPlanMode** for implementation tasks unless they're simple. Use it when ANY of these conditions apply: 28 291. **New Feature Implementation**: Adding meaningful new functionality 30 - Example: "Add a logout button" - where should it go? What should happen on click? 31 - Example: "Add form validation" - what rules? What error messages? 32 332. **Multiple Valid Approaches**: The task can be solved in several different ways 34 - Example: "Add caching to the API" - could use Redis, in-memory, file-based, etc. 35 - Example: "Improve performance" - many optimization strategies possible 36 373. **Code Modifications**: Changes that affect existing behavior or structure 38 - Example: "Update the login flow" - what exactly should change? 39 - Example: "Refactor this component" - what's the target architecture? 40 414. **Architectural Decisions**: The task requires choosing between patterns or technologies 42 - Example: "Add real-time updates" - WebSockets vs SSE vs polling 43 - Example: "Implement state management" - Redux vs Context vs custom solution 44 455. **Multi-File Changes**: The task will likely touch more than 2-3 files 46 - Example: "Refactor the authentication system" 47 - Example: "Add a new API endpoint with tests" 48 496. **Unclear Requirements**: You need to explore before understanding the full scope 50 - Example: "Make the app faster" - need to profile and identify bottlenecks 51 - Example: "Fix the bug in checkout" - need to investigate root cause 52 537. **User Preferences Matter**: The implementation could reasonably go multiple ways 54 - If you would use ${ASK_USER_QUESTION_TOOL_NAME} to clarify the approach, use EnterPlanMode instead 55 - Plan mode lets you explore first, then present options with context 56 57## When NOT to Use This Tool 58 59Only skip EnterPlanMode for simple tasks: 60- Single-line or few-line fixes (typos, obvious bugs, small tweaks) 61- Adding a single function with clear requirements 62- Tasks where the user has given very specific, detailed instructions 63- Pure research/exploration tasks (use the Agent tool with explore agent instead) 64 65${whatHappens}## Examples 66 67### GOOD - Use EnterPlanMode: 68User: "Add user authentication to the app" 69- Requires architectural decisions (session vs JWT, where to store tokens, middleware structure) 70 71User: "Optimize the database queries" 72- Multiple approaches possible, need to profile first, significant impact 73 74User: "Implement dark mode" 75- Architectural decision on theme system, affects many components 76 77User: "Add a delete button to the user profile" 78- Seems simple but involves: where to place it, confirmation dialog, API call, error handling, state updates 79 80User: "Update the error handling in the API" 81- Affects multiple files, user should approve the approach 82 83### BAD - Don't use EnterPlanMode: 84User: "Fix the typo in the README" 85- Straightforward, no planning needed 86 87User: "Add a console.log to debug this function" 88- Simple, obvious implementation 89 90User: "What files handle routing?" 91- Research task, not implementation planning 92 93## Important Notes 94 95- This tool REQUIRES user approval - they must consent to entering plan mode 96- If unsure whether to use it, err on the side of planning - it's better to get alignment upfront than to redo work 97- Users appreciate being consulted before significant changes are made to their codebase 98` 99} 100 101function getEnterPlanModeToolPromptAnt(): string { 102 // When interview phase is enabled, omit the "What Happens" section — 103 // detailed workflow instructions arrive via the plan_mode attachment (messages.ts). 104 const whatHappens = isPlanModeInterviewPhaseEnabled() 105 ? '' 106 : WHAT_HAPPENS_SECTION 107 108 return `Use this tool when a task has genuine ambiguity about the right approach and getting user input before coding would prevent significant rework. This tool transitions you into plan mode where you can explore the codebase and design an implementation approach for user approval. 109 110## When to Use This Tool 111 112Plan mode is valuable when the implementation approach is genuinely unclear. Use it when: 113 1141. **Significant Architectural Ambiguity**: Multiple reasonable approaches exist and the choice meaningfully affects the codebase 115 - Example: "Add caching to the API" - Redis vs in-memory vs file-based 116 - Example: "Add real-time updates" - WebSockets vs SSE vs polling 117 1182. **Unclear Requirements**: You need to explore and clarify before you can make progress 119 - Example: "Make the app faster" - need to profile and identify bottlenecks 120 - Example: "Refactor this module" - need to understand what the target architecture should be 121 1223. **High-Impact Restructuring**: The task will significantly restructure existing code and getting buy-in first reduces risk 123 - Example: "Redesign the authentication system" 124 - Example: "Migrate from one state management approach to another" 125 126## When NOT to Use This Tool 127 128Skip plan mode when you can reasonably infer the right approach: 129- The task is straightforward even if it touches multiple files 130- The user's request is specific enough that the implementation path is clear 131- You're adding a feature with an obvious implementation pattern (e.g., adding a button, a new endpoint following existing conventions) 132- Bug fixes where the fix is clear once you understand the bug 133- Research/exploration tasks (use the Agent tool instead) 134- The user says something like "can we work on X" or "let's do X" — just get started 135 136When in doubt, prefer starting work and using ${ASK_USER_QUESTION_TOOL_NAME} for specific questions over entering a full planning phase. 137 138${whatHappens}## Examples 139 140### GOOD - Use EnterPlanMode: 141User: "Add user authentication to the app" 142- Genuinely ambiguous: session vs JWT, where to store tokens, middleware structure 143 144User: "Redesign the data pipeline" 145- Major restructuring where the wrong approach wastes significant effort 146 147### BAD - Don't use EnterPlanMode: 148User: "Add a delete button to the user profile" 149- Implementation path is clear; just do it 150 151User: "Can we work on the search feature?" 152- User wants to get started, not plan 153 154User: "Update the error handling in the API" 155- Start working; ask specific questions if needed 156 157User: "Fix the typo in the README" 158- Straightforward, no planning needed 159 160## Important Notes 161 162- This tool REQUIRES user approval - they must consent to entering plan mode 163` 164} 165 166export function getEnterPlanModeToolPrompt(): string { 167 return process.env.USER_TYPE === 'ant' 168 ? getEnterPlanModeToolPromptAnt() 169 : getEnterPlanModeToolPromptExternal() 170}