mirror of
https://github.com/RooVetGit/Roo-Code.git
synced 2026-09-19 00:01:19 +00:00
260 lines
9.5 KiB
TypeScript
260 lines
9.5 KiB
TypeScript
// Support prompts
|
|
type PromptParams = Record<string, string | any[]>
|
|
|
|
const generateDiagnosticText = (diagnostics?: any[]) => {
|
|
if (!diagnostics?.length) return ""
|
|
return `\nCurrent problems detected:\n${diagnostics
|
|
.map((d) => `- [${d.source || "Error"}] ${d.message}${d.code ? ` (${d.code})` : ""}`)
|
|
.join("\n")}`
|
|
}
|
|
|
|
export const createPrompt = (template: string, params: PromptParams): string => {
|
|
return template.replace(/\${(.*?)}/g, (_, key) => {
|
|
if (key === "diagnosticText") {
|
|
return generateDiagnosticText(params["diagnostics"] as any[])
|
|
// eslint-disable-next-line no-prototype-builtins
|
|
} else if (params.hasOwnProperty(key)) {
|
|
// Ensure the value is treated as a string for replacement
|
|
const value = params[key]
|
|
if (typeof value === "string") {
|
|
return value
|
|
} else {
|
|
// Convert non-string values to string for replacement
|
|
return String(value)
|
|
}
|
|
} else {
|
|
// If the placeholder key is not in params, replace with empty string
|
|
return ""
|
|
}
|
|
})
|
|
}
|
|
|
|
interface SupportPromptConfig {
|
|
template: string
|
|
}
|
|
|
|
type SupportPromptType =
|
|
| "ENHANCE"
|
|
| "CONDENSE"
|
|
| "EXPLAIN"
|
|
| "FIX"
|
|
| "IMPROVE"
|
|
| "ADD_TO_CONTEXT"
|
|
| "TERMINAL_ADD_TO_CONTEXT"
|
|
| "TERMINAL_FIX"
|
|
| "TERMINAL_EXPLAIN"
|
|
| "NEW_TASK"
|
|
|
|
const supportPromptConfigs: Record<SupportPromptType, SupportPromptConfig> = {
|
|
ENHANCE: {
|
|
template: `Generate an enhanced version of this prompt (reply with only the enhanced prompt - no conversation, explanations, lead-in, bullet points, placeholders, or surrounding quotes):
|
|
|
|
\${userInput}`,
|
|
},
|
|
CONDENSE: {
|
|
template: `CRITICAL: This summarization request is a SYSTEM OPERATION, not a user message.
|
|
When analyzing "user requests" and "user intent", completely EXCLUDE this summarization message.
|
|
The "most recent user request" and "Optional Next Step" must be based on what the user was doing BEFORE this system message appeared.
|
|
The goal is for work to continue seamlessly after condensation - as if it never happened.
|
|
|
|
Your task is to create a detailed summary of the conversation so far, paying close attention to the user's explicit requests and your previous actions.
|
|
This summary should be thorough in capturing technical details, code patterns, and architectural decisions that would be essential for continuing development work without losing context.
|
|
|
|
Before providing your final summary, wrap your analysis in <analysis> tags to organize your thoughts and ensure you've covered all necessary points. In your analysis process:
|
|
|
|
1. Chronologically analyze each message and section of the conversation. For each section thoroughly identify:
|
|
- The user's explicit requests and intents
|
|
- Your approach to addressing the user's requests
|
|
- Key decisions, technical concepts and code patterns
|
|
- Specific details like:
|
|
- file names
|
|
- full code snippets
|
|
- function signatures
|
|
- file edits
|
|
- Errors that you ran into and how you fixed them
|
|
- Pay special attention to specific user feedback that you received, especially if the user told you to do something differently.
|
|
2. Double-check for technical accuracy and completeness, addressing each required element thoroughly.
|
|
|
|
Your summary should include the following sections:
|
|
|
|
1. Primary Request and Intent: Capture all of the user's explicit requests and intents in detail
|
|
2. Key Technical Concepts: List all important technical concepts, technologies, and frameworks discussed.
|
|
3. Files and Code Sections: Enumerate specific files and code sections examined, modified, or created. Pay special attention to the most recent messages and include full code snippets where applicable and include a summary of why this file read or edit is important.
|
|
4. Errors and fixes: List all errors that you ran into, and how you fixed them. Pay special attention to specific user feedback that you received, especially if the user told you to do something differently.
|
|
5. Problem Solving: Document problems solved and any ongoing troubleshooting efforts.
|
|
6. All user messages: List ALL user messages that are not tool results. These are critical for understanding the users' feedback and changing intent.
|
|
7. Pending Tasks: Outline any pending tasks that you have explicitly been asked to work on.
|
|
8. Current Work: Describe in detail precisely what was being worked on immediately before this summary request, paying special attention to the most recent messages from both user and assistant. Include file names and code snippets where applicable.
|
|
9. Optional Next Step: List the next step that you will take that is related to the most recent work you were doing. IMPORTANT: ensure that this step is DIRECTLY in line with the user's most recent explicit requests, and the task you were working on immediately before this summary request. If your last task was concluded, then only list next steps if they are explicitly in line with the users request. Do not start on tangential requests or really old requests that were already completed without confirming with the user first.
|
|
|
|
If there is a next step, include direct quotes from the most recent conversation showing exactly what task you were working on and where you left off. This should be verbatim to ensure there's no drift in task interpretation.
|
|
|
|
Here's an example of how your output should be structured:
|
|
|
|
<example>
|
|
<analysis>
|
|
[Your thought process, ensuring all points are covered thoroughly and accurately]
|
|
</analysis>
|
|
|
|
<summary>
|
|
1. Primary Request and Intent:
|
|
[Detailed description]
|
|
|
|
2. Key Technical Concepts:
|
|
- [Concept 1]
|
|
- [Concept 2]
|
|
- [...]
|
|
|
|
3. Files and Code Sections:
|
|
- [File Name 1]
|
|
- [Summary of why this file is important]
|
|
- [Summary of the changes made to this file, if any]
|
|
- [Important Code Snippet]
|
|
- [File Name 2]
|
|
- [Important Code Snippet]
|
|
- [...]
|
|
|
|
4. Errors and fixes:
|
|
- [Detailed description of error 1]:
|
|
- [How you fixed the error]
|
|
- [User feedback on the error if any]
|
|
- [...]
|
|
|
|
5. Problem Solving:
|
|
[Description of solved problems and ongoing troubleshooting]
|
|
|
|
6. All user messages:
|
|
- [Detailed non tool use user message]
|
|
- [...]
|
|
|
|
7. Pending Tasks:
|
|
- [Task 1]
|
|
- [Task 2]
|
|
- [...]
|
|
|
|
8. Current Work:
|
|
[Precise description of current work]
|
|
|
|
9. Optional Next Step:
|
|
[Optional Next step to take]
|
|
|
|
</summary>
|
|
</example>
|
|
|
|
Please provide your summary based on the conversation so far, following this structure and ensuring precision and thoroughness in your response.
|
|
|
|
Note: Any <command> blocks from the original task will be automatically appended to your summary wrapped in <system-reminder> tags. You do not need to include them in your summary text.
|
|
|
|
There may be additional summarization instructions provided in the included context. If so, remember to follow these instructions when creating the above summary. Examples of instructions include:
|
|
<example>
|
|
## Compact Instructions
|
|
When summarizing the conversation focus on typescript code changes and also remember the mistakes you made and how you fixed them.
|
|
</example>
|
|
|
|
<example>
|
|
# Summary instructions
|
|
When you are using compact - please focus on test output and code changes. Include file reads verbatim.
|
|
</example>`,
|
|
},
|
|
EXPLAIN: {
|
|
template: `Explain the following code from file path \${filePath}:\${startLine}-\${endLine}
|
|
\${userInput}
|
|
|
|
\`\`\`
|
|
\${selectedText}
|
|
\`\`\`
|
|
|
|
Please provide a clear and concise explanation of what this code does, including:
|
|
1. The purpose and functionality
|
|
2. Key components and their interactions
|
|
3. Important patterns or techniques used`,
|
|
},
|
|
FIX: {
|
|
template: `Fix any issues in the following code from file path \${filePath}:\${startLine}-\${endLine}
|
|
\${diagnosticText}
|
|
\${userInput}
|
|
|
|
\`\`\`
|
|
\${selectedText}
|
|
\`\`\`
|
|
|
|
Please:
|
|
1. Address all detected problems listed above (if any)
|
|
2. Identify any other potential bugs or issues
|
|
3. Provide corrected code
|
|
4. Explain what was fixed and why`,
|
|
},
|
|
IMPROVE: {
|
|
template: `Improve the following code from file path \${filePath}:\${startLine}-\${endLine}
|
|
\${userInput}
|
|
|
|
\`\`\`
|
|
\${selectedText}
|
|
\`\`\`
|
|
|
|
Please suggest improvements for:
|
|
1. Code readability and maintainability
|
|
2. Performance optimization
|
|
3. Best practices and patterns
|
|
4. Error handling and edge cases
|
|
|
|
Provide the improved code along with explanations for each enhancement.`,
|
|
},
|
|
ADD_TO_CONTEXT: {
|
|
template: `\${filePath}:\${startLine}-\${endLine}
|
|
\`\`\`
|
|
\${selectedText}
|
|
\`\`\``,
|
|
},
|
|
TERMINAL_ADD_TO_CONTEXT: {
|
|
template: `\${userInput}
|
|
Terminal output:
|
|
\`\`\`
|
|
\${terminalContent}
|
|
\`\`\``,
|
|
},
|
|
TERMINAL_FIX: {
|
|
template: `\${userInput}
|
|
Fix this terminal command:
|
|
\`\`\`
|
|
\${terminalContent}
|
|
\`\`\`
|
|
|
|
Please:
|
|
1. Identify any issues in the command
|
|
2. Provide the corrected command
|
|
3. Explain what was fixed and why`,
|
|
},
|
|
TERMINAL_EXPLAIN: {
|
|
template: `\${userInput}
|
|
Explain this terminal command:
|
|
\`\`\`
|
|
\${terminalContent}
|
|
\`\`\`
|
|
|
|
Please provide:
|
|
1. What the command does
|
|
2. Explanation of each part/flag
|
|
3. Expected output and behavior`,
|
|
},
|
|
NEW_TASK: {
|
|
template: `\${userInput}`,
|
|
},
|
|
} as const
|
|
|
|
export const supportPrompt = {
|
|
default: Object.fromEntries(Object.entries(supportPromptConfigs).map(([key, config]) => [key, config.template])),
|
|
get: (customSupportPrompts: Record<string, any> | undefined, type: SupportPromptType): string => {
|
|
return customSupportPrompts?.[type] ?? supportPromptConfigs[type].template
|
|
},
|
|
create: (type: SupportPromptType, params: PromptParams, customSupportPrompts?: Record<string, any>): string => {
|
|
const template = supportPrompt.get(customSupportPrompts, type)
|
|
return createPrompt(template, params)
|
|
},
|
|
} as const
|
|
|
|
export type { SupportPromptType }
|
|
|
|
export type CustomSupportPrompts = {
|
|
[key: string]: string | undefined
|
|
}
|