diff --git a/.changeset/free-ducks-camp.md b/.changeset/free-ducks-camp.md new file mode 100644 index 00000000..4fdeaf96 --- /dev/null +++ b/.changeset/free-ducks-camp.md @@ -0,0 +1,5 @@ +--- +"claude-dev": patch +--- + +Created model-family breakouts for deep-planning prompting, and laid groundwork for similar changes for other slash commands. diff --git a/.changeset/swift-seas-work.md b/.changeset/swift-seas-work.md new file mode 100644 index 00000000..4d165091 --- /dev/null +++ b/.changeset/swift-seas-work.md @@ -0,0 +1,5 @@ +--- +"claude-dev": patch +--- + +Adjusted prompting around focus chain, particularly for next-get/native tool calling models. diff --git a/src/core/prompts/commands.ts b/src/core/prompts/commands.ts index 8280d47e..b18292a1 100644 --- a/src/core/prompts/commands.ts +++ b/src/core/prompts/commands.ts @@ -1,4 +1,5 @@ -import { getShell } from "@utils/shell" +import type { ApiProviderInfo } from "@/core/api" +import { getDeepPlanningPrompt } from "./commands/deep-planning" export const newTaskToolResponse = () => ` @@ -208,256 +209,12 @@ cline "" \n ` -export const deepPlanningToolResponse = (focusChainSettings?: { enabled: boolean }) => { - const detectedShell = getShell() - - // FIXME: detectedShell returns a non-string value on some Windows machines - let isPowerShell = false - try { - isPowerShell = - detectedShell != null && - typeof detectedShell === "string" && - (detectedShell.toLowerCase().includes("powershell") || detectedShell.toLowerCase().includes("pwsh")) - } catch {} - - return ` -Your task is to create a comprehensive implementation plan before writing any code. This process has four distinct steps that must be completed in order. - -Your behavior should be methodical and thorough - take time to understand the codebase completely before making any recommendations. The quality of your investigation directly impacts the success of the implementation. - -## STEP 1: Silent Investigation - - -until explicitly instructed by the user to proceed with coding. -You must thoroughly understand the existing codebase before proposing any changes. -Perform your research without commentary or narration. Execute commands and read files without explaining what you're about to do. Only speak up if you have specific questions for the user. - - -### Required Research Activities -You must use the read_file tool to examine relevant source files, configuration files, and documentation. You must use terminal commands to gather information about the codebase structure and patterns. All terminal output must be piped to cat for visibility. - -### Essential Terminal Commands -First, determine the language(s) used in the codebase, then execute these commands to build your understanding. You must tailor them to the codebase and ensure the output is not overly verbose. For example, you should exclude dependency folders such as node_modules, venv or php vendor, etc. These are only examples, the exact commands will differ depending on the codebase. - -${ - isPowerShell - ? ` -# Discover project structure and file types -Get-ChildItem -Recurse -Include "*.py","*.js","*.ts","*.java","*.cpp","*.go" | Select-Object -First 30 | Select-Object FullName - -# Find all class and function definitions -Get-ChildItem -Recurse -Include "*.py","*.js","*.ts","*.java","*.cpp","*.go" | Select-String -Pattern "class|function|def|interface|struct" - -# Analyze import patterns and dependencies -Get-ChildItem -Recurse -Include "*.py","*.js","*.ts","*.java","*.cpp" | Select-String -Pattern "import|from|require|#include" | Sort-Object | Get-Unique - -# Find dependency manifests -Get-ChildItem -Recurse -Include "requirements*.txt","package.json","Cargo.toml","pom.xml","Gemfile","go.mod" | Get-Content - -# Identify technical debt and TODOs -Get-ChildItem -Recurse -Include "*.py","*.js","*.ts","*.java","*.cpp","*.go" | Select-String -Pattern "TODO|FIXME|XXX|HACK|NOTE" -` - : ` -# Discover project structure and file types -find . -type f -name "*.py" -o -name "*.js" -o -name "*.ts" -o -name "*.java" -o -name "*.cpp" -o -name "*.go" | head -30 | cat - -# Find all class and function definitions -grep -r "class\|function\|def\|interface\|struct\|func\|type.*struct\|type.*interface" --include="*.py" --include="*.js" --include="*.ts" --include="*.java" --include="*.cpp" --include="*.go" . | cat - -# Analyze import patterns and dependencies -grep -r "import\|from\|require\|#include" --include="*.py" --include="*.js" --include="*.ts" --include="*.java" --include="*.cpp" . | sort | uniq | cat - -# Find dependency manifests -find . -name "requirements*.txt" -o -name "package.json" -o -name "Cargo.toml" -o -name "pom.xml" -o -name "Gemfile" -o -name "go.mod" | xargs cat - -# Identify technical debt and TODOs -grep -r "TODO\|FIXME\|XXX\|HACK\|NOTE" --include="*.py" --include="*.js" --include="*.ts" --include="*.java" --include="*.cpp" --include="*.go" . | cat -` -} - - -## STEP 2: Discussion and Questions - -Ask the user brief, targeted questions that will influence your implementation plan. Keep your questions concise and conversational. Ask only essential questions needed to create an accurate plan. - -**Ask questions only when necessary for:** -- Clarifying ambiguous requirements or specifications -- Choosing between multiple equally valid implementation approaches -- Confirming assumptions about existing system behavior or constraints -- Understanding preferences for specific technical decisions that will affect the implementation - -Your questions should be direct and specific. Avoid long explanations or multiple questions in one response. - -## STEP 3: Create Implementation Plan Document - -Create a structured markdown document containing your complete implementation plan. The document must follow this exact format with clearly marked sections: - -### Document Structure Requirements - -Your implementation plan must be saved as implementation_plan.md, and *must* be structured as follows: - - -# Implementation Plan - -[Overview] -Single sentence describing the overall goal. - -Multiple paragraphs outlining the scope, context, and high-level approach. Explain why this implementation is needed and how it fits into the existing system. - -[Types] -Single sentence describing the type system changes. - -Detailed type definitions, interfaces, enums, or data structures with complete specifications. Include field names, types, validation rules, and relationships. - -[Files] -Single sentence describing file modifications. - -Detailed breakdown: -- New files to be created (with full paths and purpose) -- Existing files to be modified (with specific changes) -- Files to be deleted or moved -- Configuration file updates - -[Functions] -Single sentence describing function modifications. - -Detailed breakdown: -- New functions (name, signature, file path, purpose) -- Modified functions (exact name, current file path, required changes) -- Removed functions (name, file path, reason, migration strategy) - -[Classes] -Single sentence describing class modifications. - -Detailed breakdown: -- New classes (name, file path, key methods, inheritance) -- Modified classes (exact name, file path, specific modifications) -- Removed classes (name, file path, replacement strategy) - -[Dependencies] -Single sentence describing dependency modifications. - -Details of new packages, version changes, and integration requirements. - -[Testing] -Single sentence describing testing approach. - -Test file requirements, existing test modifications, and validation strategies. - -[Implementation Order] -Single sentence describing the implementation sequence. - -Numbered steps showing the logical order of changes to minimize conflicts and ensure successful integration. - - -## STEP 4: Create Implementation Task - -Use the new_task command to create a task for implementing the plan. The task must include a list that breaks down the implementation into trackable steps. - -### Task Creation Requirements - -Your new task should be self-contained and reference the plan document rather than requiring additional codebase investigation. Include these specific instructions in the task description: - -**Plan Document Navigation Commands:** -The implementation agent should use these commands to read specific sections of the implementation plan. You should adapt these examples to conform to the structure of the .md file you createdm, and explicitly provide them when creating the new task: - -${ - isPowerShell - ? ` -# Read Overview section -$content = Get-Content implementation_plan.md; $start = ($content | Select-String -Pattern '\\[Overview\\]').LineNumber; $end = ($content | Select-String -Pattern '\\[Types\\]').LineNumber; $content[($start-1)..($end-2)] - -# Read Types section -$content = Get-Content implementation_plan.md; $start = ($content | Select-String -Pattern '\\[Types\\]').LineNumber; $end = ($content | Select-String -Pattern '\\[Files\\]').LineNumber; $content[($start-1)..($end-2)] - -# Read Files section -$content = Get-Content implementation_plan.md; $start = ($content | Select-String -Pattern '\\[Files\\]').LineNumber; $end = ($content | Select-String -Pattern '\\[Functions\\]').LineNumber; $content[($start-1)..($end-2)] - -# Read Functions section -$content = Get-Content implementation_plan.md; $start = ($content | Select-String -Pattern '\\[Functions\\]').LineNumber; $end = ($content | Select-String -Pattern '\\[Classes\\]').LineNumber; $content[($start-1)..($end-2)] - -# Read Classes section -$content = Get-Content implementation_plan.md; $start = ($content | Select-String -Pattern '\\[Classes\\]').LineNumber; $end = ($content | Select-String -Pattern '\\[Dependencies\\]').LineNumber; $content[($start-1)..($end-2)] - -# Read Dependencies section -$content = Get-Content implementation_plan.md; $start = ($content | Select-String -Pattern '\\[Dependencies\\]').LineNumber; $end = ($content | Select-String -Pattern '\\[Testing\\]').LineNumber; $content[($start-1)..($end-2)] - -# Read Testing section -$content = Get-Content implementation_plan.md; $start = ($content | Select-String -Pattern '\\[Testing\\]').LineNumber; $end = ($content | Select-String -Pattern '\\[Implementation Order\\]').LineNumber; $content[($start-1)..($end-2)] - -# Read Implementation Order section -$content = Get-Content implementation_plan.md; $start = ($content | Select-String -Pattern '\\[Implementation Order\\]').LineNumber; $content[($start-1)..($content.Length-1)] -` - : ` -# Read Overview section -sed -n '/\[Overview\]/,/\[Types\]/p' implementation_plan.md | head -n 1 | cat - -# Read Types section -sed -n '/\[Types\]/,/\[Files\]/p' implementation_plan.md | head -n 1 | cat - -# Read Files section -sed -n '/\[Files\]/,/\[Functions\]/p' implementation_plan.md | head -n 1 | cat - -# Read Functions section -sed -n '/\[Functions\]/,/\[Classes\]/p' implementation_plan.md | head -n 1 | cat - -# Read Classes section -sed -n '/\[Classes\]/,/\[Dependencies\]/p' implementation_plan.md | head -n 1 | cat - -# Read Dependencies section -sed -n '/\[Dependencies\]/,/\[Testing\]/p' implementation_plan.md | head -n 1 | cat - -# Read Testing section -sed -n '/\[Testing\]/,/\[Implementation Order\]/p' implementation_plan.md | head -n 1 | cat - -# Read Implementation Order section -sed -n '/\[Implementation Order\]/,$p' implementation_plan.md | cat -` -} - - -**Task Progress Format:** - -You absolutely must include the task_progress contents in context when creating the new task. When providing it, do not wrap it in XML tags- instead provide it like this: - - -task_progress Items: -- [ ] Step 1: Brief description of first implementation step -- [ ] Step 2: Brief description of second implementation step -- [ ] Step 3: Brief description of third implementation step -- [ ] Step N: Brief description of final implementation step - - -You also MUST include the path to the markdown file you have created in your new task prompt. You should do this as follows: - -Refer to @path/to/file/markdown.md for a complete breakdown of the task requirements and steps. You should periodically read this file again. - -${ - focusChainSettings?.enabled - ? ` -**Task Progress Parameter:** -When creating the new task, you must include a task_progress parameter that breaks down the implementation into trackable steps. This should follow the standard Markdown checklist format with "- [ ]" for incomplete items.` - : "" -} - - - -### Mode Switching - -When creating the new task, request a switch to "act mode" if you are currently in "plan mode". This ensures the implementation agent operates in execution mode rather than planning mode. - - -## Quality Standards - -You must be specific with exact file paths, function names, and class names. You must be comprehensive and avoid assuming implicit understanding. You must be practical and consider real-world constraints and edge cases. You must use precise technical language and avoid ambiguity. - -Your implementation plan should be detailed enough that another developer could execute it without additional investigation. - ---- - -**Execute all four steps in sequence. Your role is to plan thoroughly, not to implement. Code creation begins only after the new task is created and you receive explicit instruction to proceed.** - -Below is the user's input when they indicated that they wanted to create a comprehensive implementation plan. -\n -` +/** + * Generates the deep-planning slash command response with model-family-aware variant selection + * @param focusChainSettings Optional focus chain settings to include in the prompt + * @param providerInfo Optional API provider info for model family detection + * @returns The deep-planning prompt string with appropriate variant and focus chain settings applied + */ +export const deepPlanningToolResponse = (focusChainSettings?: { enabled: boolean }, providerInfo?: ApiProviderInfo) => { + return getDeepPlanningPrompt(focusChainSettings, providerInfo) } diff --git a/src/core/prompts/commands/deep-planning/index.ts b/src/core/prompts/commands/deep-planning/index.ts new file mode 100644 index 00000000..c24c7f82 --- /dev/null +++ b/src/core/prompts/commands/deep-planning/index.ts @@ -0,0 +1,37 @@ +import type { ApiProviderInfo } from "@/core/api" +import type { SystemPromptContext } from "@/core/prompts/system-prompt/types" +import { getDeepPlanningRegistry } from "./registry" + +/** + * Generates the deep-planning slash command response with model-family-aware variant selection + * @param focusChainSettings Optional focus chain settings to include in the prompt + * @param providerInfo Optional API provider info for model family detection + * @returns The deep-planning prompt string with appropriate variant and focus chain settings applied + */ +export function getDeepPlanningPrompt(focusChainSettings?: { enabled: boolean }, providerInfo?: ApiProviderInfo): string { + // Create context for variant selection + const context: SystemPromptContext = { + providerInfo: providerInfo || ({} as ApiProviderInfo), + ide: "vscode", + } + + // Get the appropriate variant from registry + const registry = getDeepPlanningRegistry() + const variant = registry.get(context) + + // Apply focus chain settings to template + let template = variant.template + + // Replace the FOCUS_CHAIN_PARAM placeholder with actual content or empty string + const focusChainParam = focusChainSettings?.enabled + ? `**Task Progress Parameter:** +When creating the new task, you must include a task_progress parameter that breaks down the implementation into trackable steps. This parameter should be included inside the tool call, but not located inside of other content/argument blocks. This should follow the standard Markdown checklist format with "- [ ]" for incomplete items.` + : "" + + template = template.replace("{{FOCUS_CHAIN_PARAM}}", focusChainParam) + + return template +} + +// Export types for external use +export type { DeepPlanningRegistry, DeepPlanningVariant } from "./types" diff --git a/src/core/prompts/commands/deep-planning/registry.ts b/src/core/prompts/commands/deep-planning/registry.ts new file mode 100644 index 00000000..635e74cb --- /dev/null +++ b/src/core/prompts/commands/deep-planning/registry.ts @@ -0,0 +1,92 @@ +import type { SystemPromptContext } from "@/core/prompts/system-prompt/types" +import type { DeepPlanningVariant, DeepPlanningRegistry as IDeepPlanningRegistry } from "./types" +import { createAnthropicVariant, createGeminiVariant, createGenericVariant, createGPT5Variant } from "./variants" + +/** + * Singleton registry for managing deep-planning prompt variants + * Selects appropriate variant based on model family detection + */ +class DeepPlanningRegistry implements IDeepPlanningRegistry { + private static instance: DeepPlanningRegistry | null = null + private variants: Map = new Map() + private genericVariant: DeepPlanningVariant + + private constructor() { + // Initialize all variants + this.registerVariant(createAnthropicVariant()) + this.registerVariant(createGeminiVariant()) + this.registerVariant(createGPT5Variant()) + + // Generic variant must be registered last as fallback + const genericVariant = createGenericVariant() + this.registerVariant(genericVariant) + this.genericVariant = genericVariant + } + + /** + * Get the singleton instance of the registry + */ + public static getInstance(): DeepPlanningRegistry { + if (!DeepPlanningRegistry.instance) { + DeepPlanningRegistry.instance = new DeepPlanningRegistry() + } + return DeepPlanningRegistry.instance + } + + /** + * Register a new variant in the registry + */ + public register(variant: DeepPlanningVariant): void { + this.registerVariant(variant) + } + + /** + * Internal method to register a variant + */ + private registerVariant(variant: DeepPlanningVariant): void { + this.variants.set(variant.id, variant) + } + + /** + * Get the appropriate variant based on the system prompt context + * Uses matcher functions to determine which variant to use + * Falls back to generic variant if no match or on error + */ + public get(context: SystemPromptContext): DeepPlanningVariant { + try { + // Try each variant's matcher function (except generic which is last) + for (const variant of this.variants.values()) { + // Skip generic variant in iteration (it's the fallback) + if (variant.id === "generic") { + continue + } + + // Test if this variant matches the context + if (variant.matcher(context)) { + return variant + } + } + + // No match found, return generic variant + return this.genericVariant + } catch (error) { + // On any error, safely fall back to generic variant + console.warn("Error selecting deep-planning variant, falling back to generic:", error) + return this.genericVariant + } + } + + /** + * Get all registered variants + */ + public getAll(): DeepPlanningVariant[] { + return Array.from(this.variants.values()) + } +} + +/** + * Export singleton instance getter + */ +export function getDeepPlanningRegistry(): DeepPlanningRegistry { + return DeepPlanningRegistry.getInstance() +} diff --git a/src/core/prompts/commands/deep-planning/types.ts b/src/core/prompts/commands/deep-planning/types.ts new file mode 100644 index 00000000..3563edd2 --- /dev/null +++ b/src/core/prompts/commands/deep-planning/types.ts @@ -0,0 +1,38 @@ +import type { SystemPromptContext } from "@/core/prompts/system-prompt/types" + +/** + * Configuration for a deep-planning prompt variant + */ +export interface DeepPlanningVariant { + /** Unique identifier for this variant (e.g., "anthropic", "gemini", "gpt-5", "generic") */ + id: string + + /** Human-readable description of this variant */ + description: string + + /** The model family this variant is designed for */ + family: string + + /** Version number for this variant */ + version: number + + /** Matcher function to determine if this variant should be used */ + matcher: (context: SystemPromptContext) => boolean + + /** The complete prompt template string */ + template: string +} + +/** + * Registry for deep-planning prompt variants + */ +export interface DeepPlanningRegistry { + /** Get the appropriate variant based on context */ + get(context: SystemPromptContext): DeepPlanningVariant + + /** Register a new variant */ + register(variant: DeepPlanningVariant): void + + /** Get all registered variants */ + getAll(): DeepPlanningVariant[] +} diff --git a/src/core/prompts/commands/deep-planning/variants/anthropic.ts b/src/core/prompts/commands/deep-planning/variants/anthropic.ts new file mode 100644 index 00000000..6069d13c --- /dev/null +++ b/src/core/prompts/commands/deep-planning/variants/anthropic.ts @@ -0,0 +1,277 @@ +import { isAnthropicModelId } from "@utils/model-utils" +import { getShell } from "@utils/shell" +import type { SystemPromptContext } from "@/core/prompts/system-prompt/types" +import type { DeepPlanningVariant } from "../types" + +/** + * Creates the Anthropic Claude variant for deep-planning prompt + * This variant is optimized for Claude models + */ +export function createAnthropicVariant(): DeepPlanningVariant { + return { + id: "anthropic", + description: "Deep-planning variant optimized for Anthropic Claude models", + family: "anthropic", + version: 1, + matcher: (context: SystemPromptContext) => { + const modelId = context.providerInfo?.model?.id + if (!modelId) { + return false + } + return isAnthropicModelId(modelId) + }, + template: generateTemplate(), + } +} + +/** + * Generates the deep-planning template with shell-specific commands + */ +function generateTemplate(): string { + const detectedShell = getShell() + + // FIXME: detectedShell returns a non-string value on some Windows machines + let isPowerShell = false + try { + isPowerShell = + detectedShell != null && + typeof detectedShell === "string" && + (detectedShell.toLowerCase().includes("powershell") || detectedShell.toLowerCase().includes("pwsh")) + } catch {} + + return ` +Your task is to create a comprehensive implementation plan before writing any code. This process has four distinct steps that must be completed in order. + +Your behavior should be methodical and thorough - take time to understand the codebase completely before making any recommendations. The quality of your investigation directly impacts the success of the implementation. + +## STEP 1: Silent Investigation + + +until explicitly instructed by the user to proceed with coding. +You must thoroughly understand the existing codebase before proposing any changes. +Perform your research without commentary or narration. Execute commands and read files without explaining what you're about to do. Only speak up if you have specific questions for the user. + + +### Required Research Activities +You must use the read_file tool to examine relevant source files, configuration files, and documentation. You must use terminal commands to gather information about the codebase structure and patterns. All terminal output must be piped to cat for visibility. + +### Essential Terminal Commands +First, determine the language(s) used in the codebase, then execute these commands to build your understanding. You must tailor them to the codebase and ensure the output is not overly verbose. For example, you should exclude dependency folders such as node_modules, venv or php vendor, etc. These are only examples, the exact commands will differ depending on the codebase. + +${ + isPowerShell + ? // PowerShell-specific commands + + `# Discover project structure and file types +Get-ChildItem -Recurse -Include "*.py","*.js","*.ts","*.java","*.cpp","*.go" | Select-Object -First 30 | Select-Object FullName + +# Find all class and function definitions +Get-ChildItem -Recurse -Include "*.py","*.js","*.ts","*.java","*.cpp","*.go" | Select-String -Pattern "class|function|def|interface|struct" + +# Analyze import patterns and dependencies +Get-ChildItem -Recurse -Include "*.py","*.js","*.ts","*.java","*.cpp" | Select-String -Pattern "import|from|require|#include" | Sort-Object | Get-Unique + +# Find dependency manifests +Get-ChildItem -Recurse -Include "requirements*.txt","package.json","Cargo.toml","pom.xml","Gemfile","go.mod" | Get-Content + +# Identify technical debt and TODOs +Get-ChildItem -Recurse -Include "*.py","*.js","*.ts","*.java","*.cpp","*.go" | Select-String -Pattern "TODO|FIXME|XXX|HACK|NOTE" +` + : // bash/zsh-specific commands + `# Discover project structure and file types +find . -type f -name "*.py" -o -name "*.js" -o -name "*.ts" -o -name "*.java" -o -name "*.cpp" -o -name "*.go" | head -30 | cat + +# Find all class and function definitions +grep -r "class\\|function\\|def\\|interface\\|struct\\|func\\|type.*struct\\|type.*interface" --include="*.py" --include="*.js" --include="*.ts" --include="*.java" --include="*.cpp" --include="*.go" . | cat + +# Analyze import patterns and dependencies +grep -r "import\\|from\\|require\\|#include" --include="*.py" --include="*.js" --include="*.ts" --include="*.java" --include="*.cpp" . | sort | uniq | cat + +# Find dependency manifests +find . -name "requirements*.txt" -o -name "package.json" -o -name "Cargo.toml" -o -name "pom.xml" -o -name "Gemfile" -o -name "go.mod" | xargs cat + +# Identify technical debt and TODOs +grep -r "TODO\\|FIXME\\|XXX\\|HACK\\|NOTE" --include="*.py" --include="*.js" --include="*.ts" --include="*.java" --include="*.cpp" --include="*.go" . | cat +` +} + + +## STEP 2: Discussion and Questions + +Ask the user brief, targeted questions that will influence your implementation plan. Keep your questions concise and conversational. Ask only essential questions needed to create an accurate plan. + +**Ask questions only when necessary for:** +- Clarifying ambiguous requirements or specifications +- Choosing between multiple equally valid implementation approaches +- Confirming assumptions about existing system behavior or constraints +- Understanding preferences for specific technical decisions that will affect the implementation + +Your questions should be direct and specific. Avoid long explanations or multiple questions in one response. + +## STEP 3: Create Implementation Plan Document + +Create a structured markdown document containing your complete implementation plan. The document must follow this exact format with clearly marked sections: + +### Document Structure Requirements + +Your implementation plan must be saved as implementation_plan.md, and *must* be structured as follows: + + +# Implementation Plan + +[Overview] +Single sentence describing the overall goal. + +Multiple paragraphs outlining the scope, context, and high-level approach. Explain why this implementation is needed and how it fits into the existing system. + +[Types] +Single sentence describing the type system changes. + +Detailed type definitions, interfaces, enums, or data structures with complete specifications. Include field names, types, validation rules, and relationships. + +[Files] +Single sentence describing file modifications. + +Detailed breakdown: +- New files to be created (with full paths and purpose) +- Existing files to be modified (with specific changes) +- Files to be deleted or moved +- Configuration file updates + +[Functions] +Single sentence describing function modifications. + +Detailed breakdown: +- New functions (name, signature, file path, purpose) +- Modified functions (exact name, current file path, required changes) +- Removed functions (name, file path, reason, migration strategy) + +[Classes] +Single sentence describing class modifications. + +Detailed breakdown: +- New classes (name, file path, key methods, inheritance) +- Modified classes (exact name, file path, specific modifications) +- Removed classes (name, file path, replacement strategy) + +[Dependencies] +Single sentence describing dependency modifications. + +Details of new packages, version changes, and integration requirements. + +[Testing] +Single sentence describing testing approach. + +Test file requirements, existing test modifications, and validation strategies. + +[Implementation Order] +Single sentence describing the implementation sequence. + +Numbered steps showing the logical order of changes to minimize conflicts and ensure successful integration. + + +## STEP 4: Create Implementation Task + +Use the new_task command to create a task for implementing the plan. The task must include a list that breaks down the implementation into trackable steps. + +### Task Creation Requirements + +Your new task should be self-contained and reference the plan document rather than requiring additional codebase investigation. Include these specific instructions in the task description: + +**Plan Document Navigation Commands:** +The implementation agent should use these commands to read specific sections of the implementation plan. You should adapt these examples to conform to the structure of the .md file you created, and explicitly provide them when creating the new task: + +${ + isPowerShell + ? ` +# Read Overview section +$content = Get-Content implementation_plan.md; $start = ($content | Select-String -Pattern '\\[Overview\\]').LineNumber; $end = ($content | Select-String -Pattern '\\[Types\\]').LineNumber; $content[($start-1)..($end-2)] + +# Read Types section +$content = Get-Content implementation_plan.md; $start = ($content | Select-String -Pattern '\\[Types\\]').LineNumber; $end = ($content | Select-String -Pattern '\\[Files\\]').LineNumber; $content[($start-1)..($end-2)] + +# Read Files section +$content = Get-Content implementation_plan.md; $start = ($content | Select-String -Pattern '\\[Files\\]').LineNumber; $end = ($content | Select-String -Pattern '\\[Functions\\]').LineNumber; $content[($start-1)..($end-2)] + +# Read Functions section +$content = Get-Content implementation_plan.md; $start = ($content | Select-String -Pattern '\\[Functions\\]').LineNumber; $end = ($content | Select-String -Pattern '\\[Classes\\]').LineNumber; $content[($start-1)..($end-2)] + +# Read Classes section +$content = Get-Content implementation_plan.md; $start = ($content | Select-String -Pattern '\\[Classes\\]').LineNumber; $end = ($content | Select-String -Pattern '\\[Dependencies\\]').LineNumber; $content[($start-1)..($end-2)] + +# Read Dependencies section +$content = Get-Content implementation_plan.md; $start = ($content | Select-String -Pattern '\\[Dependencies\\]').LineNumber; $end = ($content | Select-String -Pattern '\\[Testing\\]').LineNumber; $content[($start-1)..($end-2)] + +# Read Testing section +$content = Get-Content implementation_plan.md; $start = ($content | Select-String -Pattern '\\[Testing\\]').LineNumber; $end = ($content | Select-String -Pattern '\\[Implementation Order\\]').LineNumber; $content[($start-1)..($end-2)] + +# Read Implementation Order section +$content = Get-Content implementation_plan.md; $start = ($content | Select-String -Pattern '\\[Implementation Order\\]').LineNumber; $content[($start-1)..($content.Length-1)] +` + : ` +# Read Overview section +sed -n '/\\[Overview\\]/,/\\[Types\\]/p' implementation_plan.md | head -n 1 | cat + +# Read Types section +sed -n '/\\[Types\\]/,/\\[Files\\]/p' implementation_plan.md | head -n 1 | cat + +# Read Files section +sed -n '/\\[Files\\]/,/\\[Functions\\]/p' implementation_plan.md | head -n 1 | cat + +# Read Functions section +sed -n '/\\[Functions\\]/,/\\[Classes\\]/p' implementation_plan.md | head -n 1 | cat + +# Read Classes section +sed -n '/\\[Classes\\]/,/\\[Dependencies\\]/p' implementation_plan.md | head -n 1 | cat + +# Read Dependencies section +sed -n '/\\[Dependencies\\]/,/\\[Testing\\]/p' implementation_plan.md | head -n 1 | cat + +# Read Testing section +sed -n '/\\[Testing\\]/,/\\[Implementation Order\\]/p' implementation_plan.md | head -n 1 | cat + +# Read Implementation Order section +sed -n '/\\[Implementation Order\\]/,$p' implementation_plan.md | cat +` +} + + +**Task Progress Format:** + +You absolutely must include the task_progress contents in context when creating the new task. When providing it, do not wrap it in XML tags- instead provide it like this: + + +task_progress Items: +- [ ] Step 1: Brief description of first implementation step +- [ ] Step 2: Brief description of second implementation step +- [ ] Step 3: Brief description of third implementation step +- [ ] Step N: Brief description of final implementation step + + +You also MUST include the path to the markdown file you have created in your new task prompt. You should do this as follows: + +Refer to @path/to/file/markdown.md for a complete breakdown of the task requirements and steps. You should periodically read this file again. + +{{FOCUS_CHAIN_PARAM}} + + + +### Mode Switching + +When creating the new task, request a switch to "act mode" if you are currently in "plan mode". This ensures the implementation agent operates in execution mode rather than planning mode. + + +## Quality Standards + +You must be specific with exact file paths, function names, and class names. You must be comprehensive and avoid assuming implicit understanding. You must be practical and consider real-world constraints and edge cases. You must use precise technical language and avoid ambiguity. + +Your implementation plan should be detailed enough that another developer could execute it without additional investigation. + +--- + +**Execute all four steps in sequence. Your role is to plan thoroughly, not to implement. Code creation begins only after the new task is created and you receive explicit instruction to proceed.** + +Below is the user's input when they indicated that they wanted to create a comprehensive implementation plan. + +` +} diff --git a/src/core/prompts/commands/deep-planning/variants/gemini.ts b/src/core/prompts/commands/deep-planning/variants/gemini.ts new file mode 100644 index 00000000..1c636fc3 --- /dev/null +++ b/src/core/prompts/commands/deep-planning/variants/gemini.ts @@ -0,0 +1,285 @@ +import { isGemini2dot5ModelFamily } from "@utils/model-utils" +import { getShell } from "@utils/shell" +import type { SystemPromptContext } from "@/core/prompts/system-prompt/types" +import type { DeepPlanningVariant } from "../types" + +/** + * Creates the Google Gemini 2.5 variant for deep-planning prompt + * This variant is optimized for Gemini 2.5 models + */ +export function createGeminiVariant(): DeepPlanningVariant { + return { + id: "gemini", + description: "Deep-planning variant optimized for Google Gemini 2.5 models", + family: "gemini", + version: 1, + matcher: (context: SystemPromptContext) => { + const modelId = context.providerInfo?.model?.id + if (!modelId) { + return false + } + return isGemini2dot5ModelFamily(modelId) + }, + template: generateTemplate(), + } +} + +/** + * Generates the deep-planning template with shell-specific commands + */ +function generateTemplate(): string { + const detectedShell = getShell() + + // FIXME: detectedShell returns a non-string value on some Windows machines + let isPowerShell = false + try { + isPowerShell = + detectedShell != null && + typeof detectedShell === "string" && + (detectedShell.toLowerCase().includes("powershell") || detectedShell.toLowerCase().includes("pwsh")) + } catch {} + + return ` +Your task is to create a comprehensive implementation plan before writing any code. This process has four distinct steps that must be completed in order. + +Your behavior should be methodical and thorough - take time to understand the codebase completely before making any recommendations. The quality of your investigation directly impacts the success of the implementation. + +## STEP 1: Silent Investigation + + +until explicitly instructed by the user to proceed with coding. +You must thoroughly understand the existing codebase before proposing any changes. +Perform your research without commentary or narration. Execute commands and read files without explaining what you're about to do. Only speak up if you have specific questions for the user. + + +### Required Research Activities +You must first use the read_file tool to examine several source files, configuration files, and documentation to better inform subsequent research steps. You should only use read_file to prepare for more granular searching. Use this tool to determine the language(s) used in the codebase, and to identify the domain(s) relevant to the user's request. + +You must then use terminal commands to gather information about the codebase structure and patterns relevant to the user's request. All terminal output must be piped to cat for visibility. +You will tailor these commands to explore and identify key functions, classes, methods, types, and variables that are directly, or indirectly related to the task. +These commands must be crafted to not produce exceptionally long or verbose search results. For example, you should exclude dependency folders such as node_modules, venv or php vendor, etc. Carefully consider the scope of search patterns. Use the results of your read_file tool calls to tailor the commands for balanced search result lengths. If a command returns no results, you may loosen the search patterns or scope slightly. If a command returns hundreds or thousands of results, you should adjust subsequent commands to be more targeted. + +Execute these commands to build your understanding. Adjust subsequent commands based on the output you have received from each previous command, informing the scope and direction of your search. + +Here are some example commands, remember to adjust them as instructed previously: + +${ + isPowerShell + ? // PowerShell-specific commands + ` +# Discover project structure and file types +Get-ChildItem -Recurse -Include "*.py","*.js","*.ts","*.java","*.cpp","*.go" | Select-Object -First 30 | Select-Object FullName + +# Find all class and function definitions +Get-ChildItem -Recurse -Include "*.py","*.js","*.ts","*.java","*.cpp","*.go" | Select-String -Pattern "class|function|def|interface|struct" + +# Analyze import patterns and dependencies +Get-ChildItem -Recurse -Include "*.py","*.js","*.ts","*.java","*.cpp" | Select-String -Pattern "import|from|require|#include" | Sort-Object | Get-Unique + +# Find dependency manifests +Get-ChildItem -Recurse -Include "requirements*.txt","package.json","Cargo.toml","pom.xml","Gemfile","go.mod" | Get-Content + +# Identify technical debt and TODOs +Get-ChildItem -Recurse -Include "*.py","*.js","*.ts","*.java","*.cpp","*.go" | Select-String -Pattern "TODO|FIXME|XXX|HACK|NOTE" +` + : // bash/zsh-specific commands + ` +# Discover project structure and file types +find . -type f -name "*.py" -o -name "*.js" -o -name "*.ts" -o -name "*.java" -o -name "*.cpp" -o -name "*.go" | head -30 | cat + +# Find all class and function definitions +grep -r "class\\|function\\|def\\|interface\\|struct\\|func\\|type.*struct\\|type.*interface" --include="*.py" --include="*.js" --include="*.ts" --include="*.java" --include="*.cpp" --include="*.go" . | cat + +# Analyze import patterns and dependencies +grep -r "import\\|from\\|require\\|#include" --include="*.py" --include="*.js" --include="*.ts" --include="*.java" --include="*.cpp" . | sort | uniq | cat + +# Find dependency manifests +find . -name "requirements*.txt" -o -name "package.json" -o -name "Cargo.toml" -o -name "pom.xml" -o -name "Gemfile" -o -name "go.mod" | xargs cat + +# Identify technical debt and TODOs +grep -r "TODO\\|FIXME\\|XXX\\|HACK\\|NOTE" --include="*.py" --include="*.js" --include="*.ts" --include="*.java" --include="*.cpp" --include="*.go" . | cat +` +} + + +## STEP 2: Discussion and Questions + +Ask the user brief, targeted questions that will influence your implementation plan. Keep your questions concise and conversational. Ask only essential questions needed to create an accurate plan. + +**Ask questions only when necessary for:** +- Clarifying ambiguous requirements or specifications +- Choosing between multiple equally valid implementation approaches +- Confirming assumptions about existing system behavior or constraints +- Understanding preferences for specific technical decisions that will affect the implementation + +Your questions should be direct and specific. Avoid long explanations or multiple questions in one response. + +## STEP 3: Create Implementation Plan Document + +Create a structured markdown document containing your complete implementation plan. The document must follow this exact format with clearly marked sections: + +### Document Structure Requirements + +Your implementation plan must be saved as implementation_plan.md, and *must* be structured as follows: + + +# Implementation Plan + +[Overview] +Single sentence describing the overall goal. + +Multiple paragraphs outlining the scope, context, and high-level approach. Explain why this implementation is needed and how it fits into the existing system. + +[Types] +Single sentence describing the type system changes. + +Detailed type definitions, interfaces, enums, or data structures with complete specifications. Include field names, types, validation rules, and relationships. + +[Files] +Single sentence describing file modifications. + +Detailed breakdown: +- New files to be created (with full paths and purpose) +- Existing files to be modified (with specific changes) +- Files to be deleted or moved +- Configuration file updates + +[Functions] +Single sentence describing function modifications. + +Detailed breakdown: +- New functions (name, signature, file path, purpose) +- Modified functions (exact name, current file path, required changes) +- Removed functions (name, file path, reason, migration strategy) + +[Classes] +Single sentence describing class modifications. + +Detailed breakdown: +- New classes (name, file path, key methods, inheritance) +- Modified classes (exact name, file path, specific modifications) +- Removed classes (name, file path, replacement strategy) + +[Dependencies] +Single sentence describing dependency modifications. + +Details of new packages, version changes, and integration requirements. + +[Testing] +Single sentence describing testing approach. + +Test file requirements, existing test modifications, and validation strategies. + +[Implementation Order] +Single sentence describing the implementation sequence. + +Numbered steps showing the logical order of changes to minimize conflicts and ensure successful integration. + + +## STEP 4: Create Implementation Task + +Use the new_task command to create a task for implementing the plan. The task must include a list that breaks down the implementation into trackable steps. + +### Task Creation Requirements + +Your new task should be self-contained and reference the plan document rather than requiring additional codebase investigation. Include these specific instructions in the task description: + +**Plan Document Navigation Commands:** +The implementation agent should use these commands to read specific sections of the implementation plan. You should adapt these examples to conform to the structure of the .md file you created, and explicitly provide them when creating the new task: + +${ + isPowerShell + ? // PowerShell-specific commands + ` +# Read Overview section +$content = Get-Content implementation_plan.md; $start = ($content | Select-String -Pattern '\\[Overview\\]').LineNumber; $end = ($content | Select-String -Pattern '\\[Types\\]').LineNumber; $content[($start-1)..($end-2)] + +# Read Types section +$content = Get-Content implementation_plan.md; $start = ($content | Select-String -Pattern '\\[Types\\]').LineNumber; $end = ($content | Select-String -Pattern '\\[Files\\]').LineNumber; $content[($start-1)..($end-2)] + +# Read Files section +$content = Get-Content implementation_plan.md; $start = ($content | Select-String -Pattern '\\[Files\\]').LineNumber; $end = ($content | Select-String -Pattern '\\[Functions\\]').LineNumber; $content[($start-1)..($end-2)] + +# Read Functions section +$content = Get-Content implementation_plan.md; $start = ($content | Select-String -Pattern '\\[Functions\\]').LineNumber; $end = ($content | Select-String -Pattern '\\[Classes\\]').LineNumber; $content[($start-1)..($end-2)] + +# Read Classes section +$content = Get-Content implementation_plan.md; $start = ($content | Select-String -Pattern '\\[Classes\\]').LineNumber; $end = ($content | Select-String -Pattern '\\[Dependencies\\]').LineNumber; $content[($start-1)..($end-2)] + +# Read Dependencies section +$content = Get-Content implementation_plan.md; $start = ($content | Select-String -Pattern '\\[Dependencies\\]').LineNumber; $end = ($content | Select-String -Pattern '\\[Testing\\]').LineNumber; $content[($start-1)..($end-2)] + +# Read Testing section +$content = Get-Content implementation_plan.md; $start = ($content | Select-String -Pattern '\\[Testing\\]').LineNumber; $end = ($content | Select-String -Pattern '\\[Implementation Order\\]').LineNumber; $content[($start-1)..($end-2)] + +# Read Implementation Order section +$content = Get-Content implementation_plan.md; $start = ($content | Select-String -Pattern '\\[Implementation Order\\]').LineNumber; $content[($start-1)..($content.Length-1)] +` + : // bash/zsh-specific commands + ` +# Read Overview section +sed -n '/\\[Overview\\]/,/\\[Types\\]/p' implementation_plan.md | head -n 1 | cat + +# Read Types section +sed -n '/\\[Types\\]/,/\\[Files\\]/p' implementation_plan.md | head -n 1 | cat + +# Read Files section +sed -n '/\\[Files\\]/,/\\[Functions\\]/p' implementation_plan.md | head -n 1 | cat + +# Read Functions section +sed -n '/\\[Functions\\]/,/\\[Classes\\]/p' implementation_plan.md | head -n 1 | cat + +# Read Classes section +sed -n '/\\[Classes\\]/,/\\[Dependencies\\]/p' implementation_plan.md | head -n 1 | cat + +# Read Dependencies section +sed -n '/\\[Dependencies\\]/,/\\[Testing\\]/p' implementation_plan.md | head -n 1 | cat + +# Read Testing section +sed -n '/\\[Testing\\]/,/\\[Implementation Order\\]/p' implementation_plan.md | head -n 1 | cat + +# Read Implementation Order section +sed -n '/\\[Implementation Order\\]/,$p' implementation_plan.md | cat +` +} + + +**Task Progress Format:** + +You absolutely must include the task_progress contents in context when creating the new task. When providing it, do not wrap it in XML tags- instead provide it like this: + + +task_progress Items: +- [ ] Step 1: Brief description of first implementation step +- [ ] Step 2: Brief description of second implementation step +- [ ] Step 3: Brief description of third implementation step +- [ ] Step N: Brief description of final implementation step + + +You also MUST include the path to the markdown file you have created in your new task prompt. You should do this as follows: + +Refer to @path/to/file/markdown.md for a complete breakdown of the task requirements and steps. You should periodically read this file again. + +{{FOCUS_CHAIN_PARAM}} + + + +### Mode Switching + +When creating the new task, request a switch to "act mode" if you are currently in "plan mode". This ensures the implementation agent operates in execution mode rather than planning mode. + + +## Quality Standards + +You must be specific with exact file paths, function names, and class names. You must be comprehensive and avoid assuming implicit understanding. You must be practical and consider real-world constraints and edge cases. You must use precise technical language and avoid ambiguity. + +Your implementation plan should be detailed enough that another developer could execute it without additional investigation. + +--- + +**Execute all four steps in sequence. Your role is to plan thoroughly, not to implement. Code creation begins only after the new task is created and you receive explicit instruction to proceed.** + +Below is the user's input when they indicated that they wanted to create a comprehensive implementation plan. + +` +} diff --git a/src/core/prompts/commands/deep-planning/variants/generic.ts b/src/core/prompts/commands/deep-planning/variants/generic.ts new file mode 100644 index 00000000..c352604b --- /dev/null +++ b/src/core/prompts/commands/deep-planning/variants/generic.ts @@ -0,0 +1,268 @@ +import { getShell } from "@utils/shell" +import type { DeepPlanningVariant } from "../types" + +/** + * Creates the generic fallback variant for deep-planning prompt + * This variant is used when no specific model family matcher applies + */ +export function createGenericVariant(): DeepPlanningVariant { + return { + id: "generic", + description: "Generic fallback variant for deep-planning prompt, used for all models", + family: "generic", + version: 1, + matcher: () => true, // Always matches as fallback + template: generateTemplate(), + } +} + +/** + * Generates the deep-planning template with shell-specific commands + */ +function generateTemplate(): string { + const detectedShell = getShell() + + // FIXME: detectedShell returns a non-string value on some Windows machines + let isPowerShell = false + try { + isPowerShell = + detectedShell != null && + typeof detectedShell === "string" && + (detectedShell.toLowerCase().includes("powershell") || detectedShell.toLowerCase().includes("pwsh")) + } catch {} + + return ` +Your task is to create a comprehensive implementation plan before writing any code. This process has four distinct steps that must be completed in order. + +Your behavior should be methodical and thorough - take time to understand the codebase completely before making any recommendations. The quality of your investigation directly impacts the success of the implementation. + +## STEP 1: Silent Investigation + + +until explicitly instructed by the user to proceed with coding. +You must thoroughly understand the existing codebase before proposing any changes. +Perform your research without commentary or narration. Execute commands and read files without explaining what you're about to do. Only speak up if you have specific questions for the user. + + +### Required Research Activities +You must use the read_file tool to examine relevant source files, configuration files, and documentation. You must use terminal commands to gather information about the codebase structure and patterns. All terminal output must be piped to cat for visibility. + +### Essential Terminal Commands +First, determine the language(s) used in the codebase, then execute these commands to build your understanding. You must tailor them to the codebase and ensure the output is not overly verbose. For example, you should exclude dependency folders such as node_modules, venv or php vendor, etc. These are only examples, the exact commands will differ depending on the codebase. + +${ + isPowerShell + ? ` +# Discover project structure and file types +Get-ChildItem -Recurse -Include "*.py","*.js","*.ts","*.java","*.cpp","*.go" | Select-Object -First 30 | Select-Object FullName + +# Find all class and function definitions +Get-ChildItem -Recurse -Include "*.py","*.js","*.ts","*.java","*.cpp","*.go" | Select-String -Pattern "class|function|def|interface|struct" + +# Analyze import patterns and dependencies +Get-ChildItem -Recurse -Include "*.py","*.js","*.ts","*.java","*.cpp" | Select-String -Pattern "import|from|require|#include" | Sort-Object | Get-Unique + +# Find dependency manifests +Get-ChildItem -Recurse -Include "requirements*.txt","package.json","Cargo.toml","pom.xml","Gemfile","go.mod" | Get-Content + +# Identify technical debt and TODOs +Get-ChildItem -Recurse -Include "*.py","*.js","*.ts","*.java","*.cpp","*.go" | Select-String -Pattern "TODO|FIXME|XXX|HACK|NOTE" +` + : ` +# Discover project structure and file types +find . -type f -name "*.py" -o -name "*.js" -o -name "*.ts" -o -name "*.java" -o -name "*.cpp" -o -name "*.go" | head -30 | cat + +# Find all class and function definitions +grep -r "class\\|function\\|def\\|interface\\|struct\\|func\\|type.*struct\\|type.*interface" --include="*.py" --include="*.js" --include="*.ts" --include="*.java" --include="*.cpp" --include="*.go" . | cat + +# Analyze import patterns and dependencies +grep -r "import\\|from\\|require\\|#include" --include="*.py" --include="*.js" --include="*.ts" --include="*.java" --include="*.cpp" . | sort | uniq | cat + +# Find dependency manifests +find . -name "requirements*.txt" -o -name "package.json" -o -name "Cargo.toml" -o -name "pom.xml" -o -name "Gemfile" -o -name "go.mod" | xargs cat + +# Identify technical debt and TODOs +grep -r "TODO\\|FIXME\\|XXX\\|HACK\\|NOTE" --include="*.py" --include="*.js" --include="*.ts" --include="*.java" --include="*.cpp" --include="*.go" . | cat +` +} + + +## STEP 2: Discussion and Questions + +Ask the user brief, targeted questions that will influence your implementation plan. Keep your questions concise and conversational. Ask only essential questions needed to create an accurate plan. + +**Ask questions only when necessary for:** +- Clarifying ambiguous requirements or specifications +- Choosing between multiple equally valid implementation approaches +- Confirming assumptions about existing system behavior or constraints +- Understanding preferences for specific technical decisions that will affect the implementation + +Your questions should be direct and specific. Avoid long explanations or multiple questions in one response. + +## STEP 3: Create Implementation Plan Document + +Create a structured markdown document containing your complete implementation plan. The document must follow this exact format with clearly marked sections: + +### Document Structure Requirements + +Your implementation plan must be saved as implementation_plan.md, and *must* be structured as follows: + + +# Implementation Plan + +[Overview] +Single sentence describing the overall goal. + +Multiple paragraphs outlining the scope, context, and high-level approach. Explain why this implementation is needed and how it fits into the existing system. + +[Types] +Single sentence describing the type system changes. + +Detailed type definitions, interfaces, enums, or data structures with complete specifications. Include field names, types, validation rules, and relationships. + +[Files] +Single sentence describing file modifications. + +Detailed breakdown: +- New files to be created (with full paths and purpose) +- Existing files to be modified (with specific changes) +- Files to be deleted or moved +- Configuration file updates + +[Functions] +Single sentence describing function modifications. + +Detailed breakdown: +- New functions (name, signature, file path, purpose) +- Modified functions (exact name, current file path, required changes) +- Removed functions (name, file path, reason, migration strategy) + +[Classes] +Single sentence describing class modifications. + +Detailed breakdown: +- New classes (name, file path, key methods, inheritance) +- Modified classes (exact name, file path, specific modifications) +- Removed classes (name, file path, replacement strategy) + +[Dependencies] +Single sentence describing dependency modifications. + +Details of new packages, version changes, and integration requirements. + +[Testing] +Single sentence describing testing approach. + +Test file requirements, existing test modifications, and validation strategies. + +[Implementation Order] +Single sentence describing the implementation sequence. + +Numbered steps showing the logical order of changes to minimize conflicts and ensure successful integration. + + +## STEP 4: Create Implementation Task + +Use the new_task command to create a task for implementing the plan. The task must include a list that breaks down the implementation into trackable steps. + +### Task Creation Requirements + +Your new task should be self-contained and reference the plan document rather than requiring additional codebase investigation. Include these specific instructions in the task description: + +**Plan Document Navigation Commands:** +The implementation agent should use these commands to read specific sections of the implementation plan. You should adapt these examples to conform to the structure of the .md file you created, and explicitly provide them when creating the new task: + +${ + isPowerShell + ? ` +# Read Overview section +$content = Get-Content implementation_plan.md; $start = ($content | Select-String -Pattern '\\[Overview\\]').LineNumber; $end = ($content | Select-String -Pattern '\\[Types\\]').LineNumber; $content[($start-1)..($end-2)] + +# Read Types section +$content = Get-Content implementation_plan.md; $start = ($content | Select-String -Pattern '\\[Types\\]').LineNumber; $end = ($content | Select-String -Pattern '\\[Files\\]').LineNumber; $content[($start-1)..($end-2)] + +# Read Files section +$content = Get-Content implementation_plan.md; $start = ($content | Select-String -Pattern '\\[Files\\]').LineNumber; $end = ($content | Select-String -Pattern '\\[Functions\\]').LineNumber; $content[($start-1)..($end-2)] + +# Read Functions section +$content = Get-Content implementation_plan.md; $start = ($content | Select-String -Pattern '\\[Functions\\]').LineNumber; $end = ($content | Select-String -Pattern '\\[Classes\\]').LineNumber; $content[($start-1)..($end-2)] + +# Read Classes section +$content = Get-Content implementation_plan.md; $start = ($content | Select-String -Pattern '\\[Classes\\]').LineNumber; $end = ($content | Select-String -Pattern '\\[Dependencies\\]').LineNumber; $content[($start-1)..($end-2)] + +# Read Dependencies section +$content = Get-Content implementation_plan.md; $start = ($content | Select-String -Pattern '\\[Dependencies\\]').LineNumber; $end = ($content | Select-String -Pattern '\\[Testing\\]').LineNumber; $content[($start-1)..($end-2)] + +# Read Testing section +$content = Get-Content implementation_plan.md; $start = ($content | Select-String -Pattern '\\[Testing\\]').LineNumber; $end = ($content | Select-String -Pattern '\\[Implementation Order\\]').LineNumber; $content[($start-1)..($end-2)] + +# Read Implementation Order section +$content = Get-Content implementation_plan.md; $start = ($content | Select-String -Pattern '\\[Implementation Order\\]').LineNumber; $content[($start-1)..($content.Length-1)] +` + : ` +# Read Overview section +sed -n '/\\[Overview\\]/,/\\[Types\\]/p' implementation_plan.md | head -n 1 | cat + +# Read Types section +sed -n '/\\[Types\\]/,/\\[Files\\]/p' implementation_plan.md | head -n 1 | cat + +# Read Files section +sed -n '/\\[Files\\]/,/\\[Functions\\]/p' implementation_plan.md | head -n 1 | cat + +# Read Functions section +sed -n '/\\[Functions\\]/,/\\[Classes\\]/p' implementation_plan.md | head -n 1 | cat + +# Read Classes section +sed -n '/\\[Classes\\]/,/\\[Dependencies\\]/p' implementation_plan.md | head -n 1 | cat + +# Read Dependencies section +sed -n '/\\[Dependencies\\]/,/\\[Testing\\]/p' implementation_plan.md | head -n 1 | cat + +# Read Testing section +sed -n '/\\[Testing\\]/,/\\[Implementation Order\\]/p' implementation_plan.md | head -n 1 | cat + +# Read Implementation Order section +sed -n '/\\[Implementation Order\\]/,$p' implementation_plan.md | cat +` +} + + +**Task Progress Format:** + +You absolutely must include the task_progress contents in context when creating the new task. When providing it, do not wrap it in XML tags- instead provide it like this: + + +task_progress Items: +- [ ] Step 1: Brief description of first implementation step +- [ ] Step 2: Brief description of second implementation step +- [ ] Step 3: Brief description of third implementation step +- [ ] Step N: Brief description of final implementation step + + +You also MUST include the path to the markdown file you have created in your new task prompt. You should do this as follows: + +Refer to @path/to/file/markdown.md for a complete breakdown of the task requirements and steps. You should periodically read this file again. + +{{FOCUS_CHAIN_PARAM}} + + + +### Mode Switching + +When creating the new task, request a switch to "act mode" if you are currently in "plan mode". This ensures the implementation agent operates in execution mode rather than planning mode. + + +## Quality Standards + +You must be specific with exact file paths, function names, and class names. You must be comprehensive and avoid assuming implicit understanding. You must be practical and consider real-world constraints and edge cases. You must use precise technical language and avoid ambiguity. + +Your implementation plan should be detailed enough that another developer could execute it without additional investigation. + +--- + +**Execute all four steps in sequence. Your role is to plan thoroughly, not to implement. Code creation begins only after the new task is created and you receive explicit instruction to proceed.** + +Below is the user's input when they indicated that they wanted to create a comprehensive implementation plan. + +` +} diff --git a/src/core/prompts/commands/deep-planning/variants/gpt5.ts b/src/core/prompts/commands/deep-planning/variants/gpt5.ts new file mode 100644 index 00000000..794d2b49 --- /dev/null +++ b/src/core/prompts/commands/deep-planning/variants/gpt5.ts @@ -0,0 +1,273 @@ +import { isGPT5ModelFamily } from "@utils/model-utils" +import { getShell } from "@utils/shell" +import type { SystemPromptContext } from "@/core/prompts/system-prompt/types" +import type { DeepPlanningVariant } from "../types" + +/** + * Creates the OpenAI GPT-5 variant for deep-planning prompt + * This variant is optimized for GPT-5 models + */ +export function createGPT5Variant(): DeepPlanningVariant { + return { + id: "gpt-5", + description: "Deep-planning variant optimized for OpenAI GPT-5 models", + family: "gpt-5", + version: 1, + matcher: (context: SystemPromptContext) => { + const modelId = context.providerInfo?.model?.id + if (!modelId) { + return false + } + return isGPT5ModelFamily(modelId) + }, + template: generateTemplate(), + } +} + +/** + * Generates the deep-planning template with shell-specific commands + */ +function generateTemplate(): string { + const detectedShell = getShell() + + // FIXME: detectedShell returns a non-string value on some Windows machines + let isPowerShell = false + try { + isPowerShell = + detectedShell != null && + typeof detectedShell === "string" && + (detectedShell.toLowerCase().includes("powershell") || detectedShell.toLowerCase().includes("pwsh")) + } catch {} + + return ` +Your task is to create a comprehensive implementation plan before writing any code. This process has four distinct steps that must be completed in order. + +Your behavior should be methodical and thorough - take time to understand the codebase completely before making any recommendations. The quality of your investigation directly impacts the success of the implementation. + +## STEP 1: Silent Investigation + + +until explicitly instructed by the user to proceed with coding. +You must thoroughly understand the existing codebase before proposing any changes. +Perform your research without commentary or narration. Execute commands and read files without explaining what you're about to do. Only speak up if you have specific questions for the user. + + +### Required Research Activities +You MUST first use the read_file tool to examine several source files, configuration files, and documentation to better inform subsequent research steps. You should only use read_file to prepare for more granular searching. Use this tool to determine the language(s) used in the codebase, and to identify the domain(s) relevant to the user's request. + +You must then use terminal commands to gather information about the codebase structure and patterns relevant to the user's request. All terminal output must be piped to cat for visibility. +You will tailor these commands to explore and identify key functions, classes, methods, types, and variables that are directly, or indirectly related to the task. +These commands must be crafted to not produce exceptionally long or verbose search results. For example, you should exclude dependency folders such as node_modules, venv or php vendor, etc. Carefully consider the scope of search patterns. Use the results of your read_file tool calls to tailor the commands for balanced search result lengths. If a command returns no results, you may loosen the search patterns or scope slightly. If a command returns hundreds or thousands of results, you should adjust subsequent commands to be more targeted. +Execute these commands to build your understanding. Adjust subsequent commands based on the output you have recieved from each previous command, informing the scope and direction of your search. +You should only execute one command at a time for the first several commands. Do not chain search commands until you have executed and interpreted the results of several search commands. + +Here are some example commands, remember to adjust them as instructed previously: +${ + isPowerShell + ? // PowerShell-specific commands + ` +# Discover project structure and file types +Get-ChildItem -Recurse -Include "*.py","*.js","*.ts","*.java","*.cpp","*.go" | Select-Object -First 30 | Select-Object FullName + +# Find all class and function definitions +Get-ChildItem -Recurse -Include "*.py","*.js","*.ts","*.java","*.cpp","*.go" | Select-String -Pattern "class|function|def|interface|struct" + +# Analyze import patterns and dependencies +Get-ChildItem -Recurse -Include "*.py","*.js","*.ts","*.java","*.cpp" | Select-String -Pattern "import|from|require|#include" | Sort-Object | Get-Unique + +# Find dependency manifests +Get-ChildItem -Recurse -Include "requirements*.txt","package.json","Cargo.toml","pom.xml","Gemfile","go.mod" | Get-Content + +# Identify technical debt and TODOs +Get-ChildItem -Recurse -Include "*.py","*.js","*.ts","*.java","*.cpp","*.go" | Select-String -Pattern "TODO|FIXME|XXX|HACK|NOTE" +` + : // bash/zsh-specific commands + ` +# Discover project structure and file types +find . -type f -name "*.py" -o -name "*.js" -o -name "*.ts" -o -name "*.java" -o -name "*.cpp" -o -name "*.go" | head -30 | cat + +# Find all class and function definitions +grep -r "class\\|function\\|def\\|interface\\|struct\\|func\\|type.*struct\\|type.*interface" --include="*.py" --include="*.js" --include="*.ts" --include="*.java" --include="*.cpp" --include="*.go" . | cat + +# Analyze import patterns and dependencies +grep -r "import\\|from\\|require\\|#include" --include="*.py" --include="*.js" --include="*.ts" --include="*.java" --include="*.cpp" . | sort | uniq | cat + +# Find dependency manifests +find . -name "requirements*.txt" -o -name "package.json" -o -name "Cargo.toml" -o -name "pom.xml" -o -name "Gemfile" -o -name "go.mod" | xargs cat + +# Identify technical debt and TODOs +grep -r "TODO\\|FIXME\\|XXX\\|HACK\\|NOTE" --include="*.py" --include="*.js" --include="*.ts" --include="*.java" --include="*.cpp" --include="*.go" . | cat +` +} + + +## STEP 2: Discussion and Questions + +Ask the user brief, targeted questions that will influence your implementation plan. Keep your questions concise and conversational. Ask only essential questions needed to create an accurate plan. + +**Ask questions only when necessary for:** +- Clarifying ambiguous requirements or specifications +- Choosing between multiple equally valid implementation approaches +- Confirming assumptions about existing system behavior or constraints +- Understanding preferences for specific technical decisions that will affect the implementation + +Your questions should be direct and specific. Avoid long explanations or multiple questions in one response. + +## STEP 3: Create Implementation Plan Document + +Create a structured markdown document containing your complete implementation plan. The document must follow this exact format with clearly marked sections: + +### Document Structure Requirements + +Your implementation plan must be saved as implementation_plan.md, and *must* be structured as follows: + + +# Implementation Plan + +[Overview] +Single sentence describing the overall goal. + +Multiple paragraphs outlining the scope, context, and high-level approach. Explain why this implementation is needed and how it fits into the existing system. + +[Types] +Single sentence describing the type system changes. + +Detailed type definitions, interfaces, enums, or data structures with complete specifications. Include field names, types, validation rules, and relationships. + +[Files] +Single sentence describing file modifications. + +Detailed breakdown: +- New files to be created (with full paths and purpose) +- Existing files to be modified (with specific changes) +- Files to be deleted or moved +- Configuration file updates + +[Functions] +Single sentence describing function modifications. + +Detailed breakdown: +- New functions (name, signature, file path, purpose) +- Modified functions (exact name, current file path, required changes) +- Removed functions (name, file path, reason, migration strategy) + +[Classes] +Single sentence describing class modifications. + +Detailed breakdown: +- New classes (name, file path, key methods, inheritance) +- Modified classes (exact name, file path, specific modifications) +- Removed classes (name, file path, replacement strategy) + +[Dependencies] +Single sentence describing dependency modifications. + +Details of new packages, version changes, and integration requirements. + +[Implementation Order] +Single sentence describing the implementation sequence. + +Numbered steps showing the logical order of changes to minimize conflicts and ensure successful integration. + + +## STEP 4: Create Implementation Task + +Use the new_task command to create a task for implementing the plan. The task must include a list that breaks down the implementation into trackable steps. + +### Task Creation Requirements + +Your new task should be self-contained and reference the plan document rather than requiring additional codebase investigation. Include these specific instructions in the task description: + +**Plan Document Navigation Commands:** +The implementation agent should use these commands to read specific sections of the implementation plan. You should adapt these examples to conform to the structure of the .md file you created, and explicitly provide them when creating the new task: + +${ + isPowerShell + ? // PowerShell-specific commands + ` +# Read Overview section +$content = Get-Content implementation_plan.md; $start = ($content | Select-String -Pattern '\\[Overview\\]').LineNumber; $end = ($content | Select-String -Pattern '\\[Types\\]').LineNumber; $content[($start-1)..($end-2)] + +# Read Types section +$content = Get-Content implementation_plan.md; $start = ($content | Select-String -Pattern '\\[Types\\]').LineNumber; $end = ($content | Select-String -Pattern '\\[Files\\]').LineNumber; $content[($start-1)..($end-2)] + +# Read Files section +$content = Get-Content implementation_plan.md; $start = ($content | Select-String -Pattern '\\[Files\\]').LineNumber; $end = ($content | Select-String -Pattern '\\[Functions\\]').LineNumber; $content[($start-1)..($end-2)] + +# Read Functions section +$content = Get-Content implementation_plan.md; $start = ($content | Select-String -Pattern '\\[Functions\\]').LineNumber; $end = ($content | Select-String -Pattern '\\[Classes\\]').LineNumber; $content[($start-1)..($end-2)] + +# Read Classes section +$content = Get-Content implementation_plan.md; $start = ($content | Select-String -Pattern '\\[Classes\\]').LineNumber; $end = ($content | Select-String -Pattern '\\[Dependencies\\]').LineNumber; $content[($start-1)..($end-2)] + +# Read Dependencies section +$content = Get-Content implementation_plan.md; $start = ($content | Select-String -Pattern '\\[Dependencies\\]').LineNumber; $end = ($content | Select-String -Pattern '\\[Testing\\]').LineNumber; $content[($start-1)..($end-2)] + +# Read Implementation Order section +$content = Get-Content implementation_plan.md; $start = ($content | Select-String -Pattern '\\[Implementation Order\\]').LineNumber; $content[($start-1)..($content.Length-1)] +` + : // bash/zsh-specific commands + ` +# Read Overview section +sed -n '/\\[Overview\\]/,/\\[Types\\]/p' implementation_plan.md | head -n 1 | cat + +# Read Types section +sed -n '/\\[Types\\]/,/\\[Files\\]/p' implementation_plan.md | head -n 1 | cat + +# Read Files section +sed -n '/\\[Files\\]/,/\\[Functions\\]/p' implementation_plan.md | head -n 1 | cat + +# Read Functions section +sed -n '/\\[Functions\\]/,/\\[Classes\\]/p' implementation_plan.md | head -n 1 | cat + +# Read Classes section +sed -n '/\\[Classes\\]/,/\\[Dependencies\\]/p' implementation_plan.md | head -n 1 | cat + +# Read Dependencies section +sed -n '/\\[Dependencies\\]/,/\\[Testing\\]/p' implementation_plan.md | head -n 1 | cat + +# Read Implementation Order section +sed -n '/\\[Implementation Order\\]/,$p' implementation_plan.md | cat +` +} + + +**Task Progress Format:** + +You absolutely must include the task_progress contents in context when creating the new task. When providing it, do not wrap it in XML tags- instead provide it like this: + + +task_progress Items: +- [ ] Step 1: Brief description of first implementation step +- [ ] Step 2: Brief description of second implementation step +- [ ] Step 3: Brief description of third implementation step +- [ ] Step N: Brief description of final implementation step + + +You also MUST include the path to the markdown file you have created in your new task prompt. You should do this as follows: + +Refer to @path/to/file/markdown.md for a complete breakdown of the task requirements and steps. You should periodically read this file again. + +{{FOCUS_CHAIN_PARAM}} + + + +### Mode Switching + +When creating the new task, request a switch to "act mode" if you are currently in "plan mode". This ensures the implementation agent operates in execution mode rather than planning mode. + + +## Quality Standards + +You must be specific with exact file paths, function names, and class names. You must be comprehensive and avoid assuming implicit understanding. You must be practical and consider real-world constraints and edge cases. You must use precise technical language and avoid ambiguity. + +Your implementation plan should be detailed enough that another developer could execute it without additional investigation. + +--- + +**Execute all four steps in sequence. Your role is to plan thoroughly, not to implement. Code creation begins only after the new task is created and you receive explicit instruction to proceed.** + +Below is the user's input when they indicated that they wanted to create a comprehensive implementation plan. + +` +} diff --git a/src/core/prompts/commands/deep-planning/variants/index.ts b/src/core/prompts/commands/deep-planning/variants/index.ts new file mode 100644 index 00000000..53d65ba3 --- /dev/null +++ b/src/core/prompts/commands/deep-planning/variants/index.ts @@ -0,0 +1,8 @@ +/** + * Export for all deep-planning prompt variants + */ + +export { createAnthropicVariant } from "./anthropic" +export { createGeminiVariant } from "./gemini" +export { createGenericVariant } from "./generic" +export { createGPT5Variant } from "./gpt5" diff --git a/src/core/slash-commands/index.ts b/src/core/slash-commands/index.ts index c72e5782..ffe83ae0 100644 --- a/src/core/slash-commands/index.ts +++ b/src/core/slash-commands/index.ts @@ -1,5 +1,6 @@ import { ClineRulesToggles } from "@shared/cline-rules" import fs from "fs/promises" +import type { ApiProviderInfo } from "@/core/api" import { telemetryService } from "@/services/telemetry" import { condenseToolResponse, @@ -20,6 +21,7 @@ export async function parseSlashCommands( globalWorkflowToggles: ClineRulesToggles, ulid: string, focusChainSettings?: { enabled: boolean }, + providerInfo?: ApiProviderInfo, ): Promise<{ processedText: string; needsClinerulesFileCheck: boolean }> { const SUPPORTED_DEFAULT_COMMANDS = ["newtask", "smol", "compact", "newrule", "reportbug", "deep-planning", "subagent"] @@ -29,7 +31,7 @@ export async function parseSlashCommands( compact: condenseToolResponse(focusChainSettings), newrule: newRuleToolResponse(), reportbug: reportBugToolResponse(), - "deep-planning": deepPlanningToolResponse(focusChainSettings), + "deep-planning": deepPlanningToolResponse(focusChainSettings, providerInfo), subagent: subagentToolResponse(), } diff --git a/src/core/task/index.ts b/src/core/task/index.ts index 4e2b4c4c..4653a19b 100644 --- a/src/core/task/index.ts +++ b/src/core/task/index.ts @@ -3196,6 +3196,7 @@ export class Task { globalWorkflowToggles, this.ulid, this.stateManager.getGlobalSettingsKey("focusChainSettings"), + this.getCurrentProviderInfo(), ) if (needsCheck) {