mirror of
https://github.com/pacnpal/Roo-Code.git
synced 2025-12-22 21:31:08 -05:00
Chat modes
This commit is contained in:
19
src/core/prompts/tools/access-mcp-resource.ts
Normal file
19
src/core/prompts/tools/access-mcp-resource.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
export function getAccessMcpResourceDescription(): string {
|
||||
return `## access_mcp_resource
|
||||
Description: Request to access a resource provided by a connected MCP server. Resources represent data sources that can be used as context, such as files, API responses, or system information.
|
||||
Parameters:
|
||||
- server_name: (required) The name of the MCP server providing the resource
|
||||
- uri: (required) The URI identifying the specific resource to access
|
||||
Usage:
|
||||
<access_mcp_resource>
|
||||
<server_name>server name here</server_name>
|
||||
<uri>resource URI here</uri>
|
||||
</access_mcp_resource>
|
||||
|
||||
Example: Requesting to access an MCP resource
|
||||
|
||||
<access_mcp_resource>
|
||||
<server_name>weather-server</server_name>
|
||||
<uri>weather://san-francisco/current</uri>
|
||||
</access_mcp_resource>`
|
||||
}
|
||||
15
src/core/prompts/tools/ask-followup-question.ts
Normal file
15
src/core/prompts/tools/ask-followup-question.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
export function getAskFollowupQuestionDescription(): string {
|
||||
return `## ask_followup_question
|
||||
Description: Ask the user a question to gather additional information needed to complete the task. This tool should be used when you encounter ambiguities, need clarification, or require more details to proceed effectively. It allows for interactive problem-solving by enabling direct communication with the user. Use this tool judiciously to maintain a balance between gathering necessary information and avoiding excessive back-and-forth.
|
||||
Parameters:
|
||||
- question: (required) The question to ask the user. This should be a clear, specific question that addresses the information you need.
|
||||
Usage:
|
||||
<ask_followup_question>
|
||||
<question>Your question here</question>
|
||||
</ask_followup_question>
|
||||
|
||||
Example: Requesting to ask the user for the path to the frontend-config.json file
|
||||
<ask_followup_question>
|
||||
<question>What is the path to the frontend-config.json file?</question>
|
||||
</ask_followup_question>`
|
||||
}
|
||||
23
src/core/prompts/tools/attempt-completion.ts
Normal file
23
src/core/prompts/tools/attempt-completion.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
export function getAttemptCompletionDescription(): string {
|
||||
return `## attempt_completion
|
||||
Description: After each tool use, the user will respond with the result of that tool use, i.e. if it succeeded or failed, along with any reasons for failure. Once you've received the results of tool uses and can confirm that the task is complete, use this tool to present the result of your work to the user. Optionally you may provide a CLI command to showcase the result of your work. The user may respond with feedback if they are not satisfied with the result, which you can use to make improvements and try again.
|
||||
IMPORTANT NOTE: This tool CANNOT be used until you've confirmed from the user that any previous tool uses were successful. Failure to do so will result in code corruption and system failure. Before using this tool, you must ask yourself in <thinking></thinking> tags if you've confirmed from the user that any previous tool uses were successful. If not, then DO NOT use this tool.
|
||||
Parameters:
|
||||
- result: (required) The result of the task. Formulate this result in a way that is final and does not require further input from the user. Don't end your result with questions or offers for further assistance.
|
||||
- command: (optional) A CLI command to execute to show a live demo of the result to the user. For example, use \`open index.html\` to display a created html website, or \`open localhost:3000\` to display a locally running development server. But DO NOT use commands like \`echo\` or \`cat\` that merely print text. This command should be valid for the current operating system. Ensure the command is properly formatted and does not contain any harmful instructions.
|
||||
Usage:
|
||||
<attempt_completion>
|
||||
<result>
|
||||
Your final result description here
|
||||
</result>
|
||||
<command>Command to demonstrate result (optional)</command>
|
||||
</attempt_completion>
|
||||
|
||||
Example: Requesting to attempt completion with a result and command
|
||||
<attempt_completion>
|
||||
<result>
|
||||
I've updated the CSS
|
||||
</result>
|
||||
<command>open index.html</command>
|
||||
</attempt_completion>`
|
||||
}
|
||||
47
src/core/prompts/tools/browser-action.ts
Normal file
47
src/core/prompts/tools/browser-action.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
export function getBrowserActionDescription(cwd: string, browserViewportSize: string = "900x600"): string {
|
||||
return `## browser_action
|
||||
Description: Request to interact with a Puppeteer-controlled browser. Every action, except \`close\`, will be responded to with a screenshot of the browser's current state, along with any new console logs. You may only perform one browser action per message, and wait for the user's response including a screenshot and logs to determine the next action.
|
||||
- The sequence of actions **must always start with** launching the browser at a URL, and **must always end with** closing the browser. If you need to visit a new URL that is not possible to navigate to from the current webpage, you must first close the browser, then launch again at the new URL.
|
||||
- While the browser is active, only the \`browser_action\` tool can be used. No other tools should be called during this time. You may proceed to use other tools only after closing the browser. For example if you run into an error and need to fix a file, you must close the browser, then use other tools to make the necessary changes, then re-launch the browser to verify the result.
|
||||
- The browser window has a resolution of **${browserViewportSize}** pixels. When performing any click actions, ensure the coordinates are within this resolution range.
|
||||
- Before clicking on any elements such as icons, links, or buttons, you must consult the provided screenshot of the page to determine the coordinates of the element. The click should be targeted at the **center of the element**, not on its edges.
|
||||
Parameters:
|
||||
- action: (required) The action to perform. The available actions are:
|
||||
* launch: Launch a new Puppeteer-controlled browser instance at the specified URL. This **must always be the first action**.
|
||||
- Use with the \`url\` parameter to provide the URL.
|
||||
- Ensure the URL is valid and includes the appropriate protocol (e.g. http://localhost:3000/page, file:///path/to/file.html, etc.)
|
||||
* click: Click at a specific x,y coordinate.
|
||||
- Use with the \`coordinate\` parameter to specify the location.
|
||||
- Always click in the center of an element (icon, button, link, etc.) based on coordinates derived from a screenshot.
|
||||
* type: Type a string of text on the keyboard. You might use this after clicking on a text field to input text.
|
||||
- Use with the \`text\` parameter to provide the string to type.
|
||||
* scroll_down: Scroll down the page by one page height.
|
||||
* scroll_up: Scroll up the page by one page height.
|
||||
* close: Close the Puppeteer-controlled browser instance. This **must always be the final browser action**.
|
||||
- Example: \`<action>close</action>\`
|
||||
- url: (optional) Use this for providing the URL for the \`launch\` action.
|
||||
* Example: <url>https://example.com</url>
|
||||
- coordinate: (optional) The X and Y coordinates for the \`click\` action. Coordinates should be within the **${browserViewportSize}** resolution.
|
||||
* Example: <coordinate>450,300</coordinate>
|
||||
- text: (optional) Use this for providing the text for the \`type\` action.
|
||||
* Example: <text>Hello, world!</text>
|
||||
Usage:
|
||||
<browser_action>
|
||||
<action>Action to perform (e.g., launch, click, type, scroll_down, scroll_up, close)</action>
|
||||
<url>URL to launch the browser at (optional)</url>
|
||||
<coordinate>x,y coordinates (optional)</coordinate>
|
||||
<text>Text to type (optional)</text>
|
||||
</browser_action>
|
||||
|
||||
Example: Requesting to launch a browser at https://example.com
|
||||
<browser_action>
|
||||
<action>launch</action>
|
||||
<url>https://example.com</url>
|
||||
</browser_action>
|
||||
|
||||
Example: Requesting to click on the element at coordinates 450,300
|
||||
<browser_action>
|
||||
<action>click</action>
|
||||
<coordinate>450,300</coordinate>
|
||||
</browser_action>`
|
||||
}
|
||||
15
src/core/prompts/tools/execute-command.ts
Normal file
15
src/core/prompts/tools/execute-command.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
export function getExecuteCommandDescription(cwd: string): string {
|
||||
return `## execute_command
|
||||
Description: Request to execute a CLI command on the system. Use this when you need to perform system operations or run specific commands to accomplish any step in the user's task. You must tailor your command to the user's system and provide a clear explanation of what the command does. Prefer to execute complex CLI commands over creating executable scripts, as they are more flexible and easier to run. Commands will be executed in the current working directory: ${cwd}
|
||||
Parameters:
|
||||
- command: (required) The CLI command to execute. This should be valid for the current operating system. Ensure the command is properly formatted and does not contain any harmful instructions.
|
||||
Usage:
|
||||
<execute_command>
|
||||
<command>Your command here</command>
|
||||
</execute_command>
|
||||
|
||||
Example: Requesting to execute npm run dev
|
||||
<execute_command>
|
||||
<command>npm run dev</command>
|
||||
</execute_command>`
|
||||
}
|
||||
101
src/core/prompts/tools/index.ts
Normal file
101
src/core/prompts/tools/index.ts
Normal file
@@ -0,0 +1,101 @@
|
||||
import { getExecuteCommandDescription } from './execute-command'
|
||||
import { getReadFileDescription } from './read-file'
|
||||
import { getWriteToFileDescription } from './write-to-file'
|
||||
import { getSearchFilesDescription } from './search-files'
|
||||
import { getListFilesDescription } from './list-files'
|
||||
import { getListCodeDefinitionNamesDescription } from './list-code-definition-names'
|
||||
import { getBrowserActionDescription } from './browser-action'
|
||||
import { getAskFollowupQuestionDescription } from './ask-followup-question'
|
||||
import { getAttemptCompletionDescription } from './attempt-completion'
|
||||
import { getUseMcpToolDescription } from './use-mcp-tool'
|
||||
import { getAccessMcpResourceDescription } from './access-mcp-resource'
|
||||
import { DiffStrategy } from '../../diff/DiffStrategy'
|
||||
import { McpHub } from '../../../services/mcp/McpHub'
|
||||
import { Mode, codeMode, askMode } from '../modes'
|
||||
import { CODE_ALLOWED_TOOLS, READONLY_ALLOWED_TOOLS, ToolName, ReadOnlyToolName } from '../../tool-lists'
|
||||
|
||||
type AllToolNames = ToolName | ReadOnlyToolName;
|
||||
|
||||
// Helper function to safely check if a tool is allowed
|
||||
function hasAllowedTool(tools: readonly string[], tool: AllToolNames): boolean {
|
||||
return tools.includes(tool);
|
||||
}
|
||||
|
||||
export function getToolDescriptionsForMode(
|
||||
mode: Mode,
|
||||
cwd: string,
|
||||
supportsComputerUse: boolean,
|
||||
diffStrategy?: DiffStrategy,
|
||||
browserViewportSize?: string,
|
||||
mcpHub?: McpHub
|
||||
): string {
|
||||
const descriptions = []
|
||||
|
||||
const allowedTools = mode === codeMode ? CODE_ALLOWED_TOOLS : READONLY_ALLOWED_TOOLS;
|
||||
|
||||
// Core tools based on mode
|
||||
if (hasAllowedTool(allowedTools, 'execute_command')) {
|
||||
descriptions.push(getExecuteCommandDescription(cwd));
|
||||
}
|
||||
if (hasAllowedTool(allowedTools, 'read_file')) {
|
||||
descriptions.push(getReadFileDescription(cwd));
|
||||
}
|
||||
if (hasAllowedTool(allowedTools, 'write_to_file')) {
|
||||
descriptions.push(getWriteToFileDescription(cwd));
|
||||
}
|
||||
|
||||
// Optional diff strategy
|
||||
if (diffStrategy && hasAllowedTool(allowedTools, 'apply_diff')) {
|
||||
descriptions.push(diffStrategy.getToolDescription(cwd));
|
||||
}
|
||||
|
||||
// File operation tools
|
||||
if (hasAllowedTool(allowedTools, 'search_files')) {
|
||||
descriptions.push(getSearchFilesDescription(cwd));
|
||||
}
|
||||
if (hasAllowedTool(allowedTools, 'list_files')) {
|
||||
descriptions.push(getListFilesDescription(cwd));
|
||||
}
|
||||
if (hasAllowedTool(allowedTools, 'list_code_definition_names')) {
|
||||
descriptions.push(getListCodeDefinitionNamesDescription(cwd));
|
||||
}
|
||||
|
||||
// Browser actions
|
||||
if (supportsComputerUse && hasAllowedTool(allowedTools, 'browser_action')) {
|
||||
descriptions.push(getBrowserActionDescription(cwd, browserViewportSize));
|
||||
}
|
||||
|
||||
// Common tools at the end
|
||||
if (hasAllowedTool(allowedTools, 'ask_followup_question')) {
|
||||
descriptions.push(getAskFollowupQuestionDescription());
|
||||
}
|
||||
if (hasAllowedTool(allowedTools, 'attempt_completion')) {
|
||||
descriptions.push(getAttemptCompletionDescription());
|
||||
}
|
||||
|
||||
// MCP tools if available
|
||||
if (mcpHub) {
|
||||
if (hasAllowedTool(allowedTools, 'use_mcp_tool')) {
|
||||
descriptions.push(getUseMcpToolDescription());
|
||||
}
|
||||
if (hasAllowedTool(allowedTools, 'access_mcp_resource')) {
|
||||
descriptions.push(getAccessMcpResourceDescription());
|
||||
}
|
||||
}
|
||||
|
||||
return `# Tools\n\n${descriptions.filter(Boolean).join('\n\n')}`
|
||||
}
|
||||
|
||||
export {
|
||||
getExecuteCommandDescription,
|
||||
getReadFileDescription,
|
||||
getWriteToFileDescription,
|
||||
getSearchFilesDescription,
|
||||
getListFilesDescription,
|
||||
getListCodeDefinitionNamesDescription,
|
||||
getBrowserActionDescription,
|
||||
getAskFollowupQuestionDescription,
|
||||
getAttemptCompletionDescription,
|
||||
getUseMcpToolDescription,
|
||||
getAccessMcpResourceDescription
|
||||
}
|
||||
15
src/core/prompts/tools/list-code-definition-names.ts
Normal file
15
src/core/prompts/tools/list-code-definition-names.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
export function getListCodeDefinitionNamesDescription(cwd: string): string {
|
||||
return `## list_code_definition_names
|
||||
Description: Request to list definition names (classes, functions, methods, etc.) used in source code files at the top level of the specified directory. This tool provides insights into the codebase structure and important constructs, encapsulating high-level concepts and relationships that are crucial for understanding the overall architecture.
|
||||
Parameters:
|
||||
- path: (required) The path of the directory (relative to the current working directory ${cwd.toPosix()}) to list top level source code definitions for.
|
||||
Usage:
|
||||
<list_code_definition_names>
|
||||
<path>Directory path here</path>
|
||||
</list_code_definition_names>
|
||||
|
||||
Example: Requesting to list all top level source code definitions in the current directory
|
||||
<list_code_definition_names>
|
||||
<path>.</path>
|
||||
</list_code_definition_names>`
|
||||
}
|
||||
18
src/core/prompts/tools/list-files.ts
Normal file
18
src/core/prompts/tools/list-files.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
export function getListFilesDescription(cwd: string): string {
|
||||
return `## list_files
|
||||
Description: Request to list files and directories within the specified directory. If recursive is true, it will list all files and directories recursively. If recursive is false or not provided, it will only list the top-level contents. Do not use this tool to confirm the existence of files you may have created, as the user will let you know if the files were created successfully or not.
|
||||
Parameters:
|
||||
- path: (required) The path of the directory to list contents for (relative to the current working directory ${cwd.toPosix()})
|
||||
- recursive: (optional) Whether to list files recursively. Use true for recursive listing, false or omit for top-level only.
|
||||
Usage:
|
||||
<list_files>
|
||||
<path>Directory path here</path>
|
||||
<recursive>true or false (optional)</recursive>
|
||||
</list_files>
|
||||
|
||||
Example: Requesting to list all files in the current directory
|
||||
<list_files>
|
||||
<path>.</path>
|
||||
<recursive>false</recursive>
|
||||
</list_files>`
|
||||
}
|
||||
15
src/core/prompts/tools/read-file.ts
Normal file
15
src/core/prompts/tools/read-file.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
export function getReadFileDescription(cwd: string): string {
|
||||
return `## read_file
|
||||
Description: Request to read the contents of a file at the specified path. Use this when you need to examine the contents of an existing file you do not know the contents of, for example to analyze code, review text files, or extract information from configuration files. The output includes line numbers prefixed to each line (e.g. "1 | const x = 1"), making it easier to reference specific lines when creating diffs or discussing code. Automatically extracts raw text from PDF and DOCX files. May not be suitable for other types of binary files, as it returns the raw content as a string.
|
||||
Parameters:
|
||||
- path: (required) The path of the file to read (relative to the current working directory ${cwd})
|
||||
Usage:
|
||||
<read_file>
|
||||
<path>File path here</path>
|
||||
</read_file>
|
||||
|
||||
Example: Requesting to read frontend-config.json
|
||||
<read_file>
|
||||
<path>frontend-config.json</path>
|
||||
</read_file>`
|
||||
}
|
||||
21
src/core/prompts/tools/search-files.ts
Normal file
21
src/core/prompts/tools/search-files.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
export function getSearchFilesDescription(cwd: string): string {
|
||||
return `## search_files
|
||||
Description: Request to perform a regex search across files in a specified directory, providing context-rich results. This tool searches for patterns or specific content across multiple files, displaying each match with encapsulating context.
|
||||
Parameters:
|
||||
- path: (required) The path of the directory to search in (relative to the current working directory ${cwd.toPosix()}). This directory will be recursively searched.
|
||||
- regex: (required) The regular expression pattern to search for. Uses Rust regex syntax.
|
||||
- file_pattern: (optional) Glob pattern to filter files (e.g., '*.ts' for TypeScript files). If not provided, it will search all files (*).
|
||||
Usage:
|
||||
<search_files>
|
||||
<path>Directory path here</path>
|
||||
<regex>Your regex pattern here</regex>
|
||||
<file_pattern>file pattern here (optional)</file_pattern>
|
||||
</search_files>
|
||||
|
||||
Example: Requesting to search for all .ts files in the current directory
|
||||
<search_files>
|
||||
<path>.</path>
|
||||
<regex>.*</regex>
|
||||
<file_pattern>*.ts</file_pattern>
|
||||
</search_files>`
|
||||
}
|
||||
32
src/core/prompts/tools/use-mcp-tool.ts
Normal file
32
src/core/prompts/tools/use-mcp-tool.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
export function getUseMcpToolDescription(): string {
|
||||
return `## use_mcp_tool
|
||||
Description: Request to use a tool provided by a connected MCP server. Each MCP server can provide multiple tools with different capabilities. Tools have defined input schemas that specify required and optional parameters.
|
||||
Parameters:
|
||||
- server_name: (required) The name of the MCP server providing the tool
|
||||
- tool_name: (required) The name of the tool to execute
|
||||
- arguments: (required) A JSON object containing the tool's input parameters, following the tool's input schema
|
||||
Usage:
|
||||
<use_mcp_tool>
|
||||
<server_name>server name here</server_name>
|
||||
<tool_name>tool name here</tool_name>
|
||||
<arguments>
|
||||
{
|
||||
"param1": "value1",
|
||||
"param2": "value2"
|
||||
}
|
||||
</arguments>
|
||||
</use_mcp_tool>
|
||||
|
||||
Example: Requesting to use an MCP tool
|
||||
|
||||
<use_mcp_tool>
|
||||
<server_name>weather-server</server_name>
|
||||
<tool_name>get_forecast</tool_name>
|
||||
<arguments>
|
||||
{
|
||||
"city": "San Francisco",
|
||||
"days": 5
|
||||
}
|
||||
</arguments>
|
||||
</use_mcp_tool>`
|
||||
}
|
||||
38
src/core/prompts/tools/write-to-file.ts
Normal file
38
src/core/prompts/tools/write-to-file.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
export function getWriteToFileDescription(cwd: string): string {
|
||||
return `## write_to_file
|
||||
Description: Request to write full content to a file at the specified path. If the file exists, it will be overwritten with the provided content. If the file doesn't exist, it will be created. This tool will automatically create any directories needed to write the file.
|
||||
Parameters:
|
||||
- path: (required) The path of the file to write to (relative to the current working directory ${cwd.toPosix()})
|
||||
- content: (required) The content to write to the file. ALWAYS provide the COMPLETE intended content of the file, without any truncation or omissions. You MUST include ALL parts of the file, even if they haven't been modified. Do NOT include the line numbers in the content though, just the actual content of the file.
|
||||
- line_count: (required) The number of lines in the file. Make sure to compute this based on the actual content of the file, not the number of lines in the content you're providing.
|
||||
Usage:
|
||||
<write_to_file>
|
||||
<path>File path here</path>
|
||||
<content>
|
||||
Your file content here
|
||||
</content>
|
||||
<line_count>total number of lines in the file, including empty lines</line_count>
|
||||
</write_to_file>
|
||||
|
||||
Example: Requesting to write to frontend-config.json
|
||||
<write_to_file>
|
||||
<path>frontend-config.json</path>
|
||||
<content>
|
||||
{
|
||||
"apiEndpoint": "https://api.example.com",
|
||||
"theme": {
|
||||
"primaryColor": "#007bff",
|
||||
"secondaryColor": "#6c757d",
|
||||
"fontFamily": "Arial, sans-serif"
|
||||
},
|
||||
"features": {
|
||||
"darkMode": true,
|
||||
"notifications": true,
|
||||
"analytics": false
|
||||
},
|
||||
"version": "1.0.0"
|
||||
}
|
||||
</content>
|
||||
<line_count>14</line_count>
|
||||
</write_to_file>`
|
||||
}
|
||||
Reference in New Issue
Block a user