Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/core/prompts/__tests__/system-prompt.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ describe("SYSTEM_PROMPT", () => {
)

expect(prompt).toContain("update_todo_list")
expect(prompt).toContain("## update_todo_list")
expect(prompt).toContain('<tool name="update_todo_list">')
})

it("should include update_todo_list tool when todoListEnabled is undefined", async () => {
Expand Down Expand Up @@ -669,7 +669,7 @@ describe("SYSTEM_PROMPT", () => {
)

expect(prompt).toContain("update_todo_list")
expect(prompt).toContain("## update_todo_list")
expect(prompt).toContain('<tool name="update_todo_list">')
})

afterAll(() => {
Expand Down
8 changes: 4 additions & 4 deletions src/core/prompts/sections/capabilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ export function getCapabilitiesSection(
diffStrategy?: DiffStrategy,
codeIndexManager?: CodeIndexManager,
): string {
return `====

CAPABILITIES
return `<section name="CAPABILITIES">

- You have access to tools that let you execute CLI commands on the user's computer, list files, view source code definitions, regex search${
supportsComputerUse ? ", use the browser" : ""
Expand All @@ -38,5 +36,7 @@ CAPABILITIES
- You have access to MCP servers that may provide additional tools and resources. Each server may provide different capabilities that you can use to accomplish tasks more effectively.
`
: ""
}`
}

</section>`
}
6 changes: 3 additions & 3 deletions src/core/prompts/sections/markdown-formatting.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export function markdownFormattingSection(): string {
return `====
return `<section name="MARKDOWN RULES">

MARKDOWN RULES
ALL responses MUST show ANY \`language construct\` OR filename reference as clickable, exactly as [\`filename OR language.declaration()\`](relative/file/path.ext:line); line is required for \`syntax\` and optional for filename links. This applies to ALL markdown responses and ALSO those in <attempt_completion>

ALL responses MUST show ANY \`language construct\` OR filename reference as clickable, exactly as [\`filename OR language.declaration()\`](relative/file/path.ext:line); line is required for \`syntax\` and optional for filename links. This applies to ALL markdown responses and ALSO those in <attempt_completion>`
</section>`
}
15 changes: 11 additions & 4 deletions src/core/prompts/sections/mcp-servers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export async function getMcpServersSection(
.join("\n\n")}`
: "(No MCP servers currently connected)"

const baseSection = `MCP SERVERS
const baseSection = `<section name="MCP SERVERS">

The Model Context Protocol (MCP) enables communication between the system and MCP servers that provide additional tools and resources to extend your capabilities. MCP servers can be one of two types:

Expand All @@ -60,20 +60,27 @@ The Model Context Protocol (MCP) enables communication between the system and MC

When a server is connected, you can use the server's tools via the \`use_mcp_tool\` tool, and access the server's resources via the \`access_mcp_resource\` tool.

${connectedServers}`
${connectedServers}

</section>`

if (!enableMcpServerCreation) {
return baseSection
}

// Remove the closing </section> tag from baseSection and add the additional content
const baseSectionWithoutClosing = baseSection.replace("</section>", "")

return (
baseSection +
baseSectionWithoutClosing +
`
## Creating an MCP Server

The user may ask you something along the lines of "add a tool" that does some function, in other words to create an MCP server that provides tools and resources that may connect to external APIs for example. If they do, you should obtain detailed instructions on this topic using the fetch_instructions tool, like this:
<fetch_instructions>
<task>create_mcp_server</task>
</fetch_instructions>`
</fetch_instructions>

</section>`
)
}
7 changes: 3 additions & 4 deletions src/core/prompts/sections/modes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ export async function getModesSection(context: vscode.ExtensionContext): Promise
// Get all modes with their overrides from extension state
const allModes = await getAllModesWithPrompts(context)

let modesContent = `====

MODES
let modesContent = `<section name="MODES">

- These are the currently available modes:
${allModes
Expand All @@ -37,7 +35,8 @@ If the user asks you to create or edit a new mode for this project, you should r
<fetch_instructions>
<task>create_mode</task>
</fetch_instructions>
`

</section>`

return modesContent
}
8 changes: 4 additions & 4 deletions src/core/prompts/sections/objective.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ export function getObjectiveSection(
? "First, for ANY exploration of code you haven't examined yet in this conversation, you MUST use the `codebase_search` tool to search for relevant code based on the task's intent BEFORE using any other search or file exploration tools. This applies throughout the entire task, not just at the beginning - whenever you need to explore a new area of code, codebase_search must come first. Then, "
: "First, "

return `====

OBJECTIVE
return `<section name="OBJECTIVE">

You accomplish a given task iteratively, breaking it down into clear steps and working through them methodically.

1. Analyze the user's task and set clear, achievable goals to accomplish it. Prioritize these goals in a logical order.
2. Work through these goals sequentially, utilizing available tools one at a time as necessary. Each goal should correspond to a distinct step in your problem-solving process. You will be informed on the work completed and what's remaining as you go.
3. Remember, you have extensive capabilities with access to a wide range of tools that can be used in powerful and clever ways as necessary to accomplish each goal. Before calling a tool, do some analysis within <thinking></thinking> tags. ${codebaseSearchInstruction}analyze the file structure provided in environment_details to gain context and insights for proceeding effectively. Next, think about which of the provided tools is the most relevant tool to accomplish the user's task. Go through each of the required parameters of the relevant tool and determine if the user has directly provided or given enough information to infer a value. When deciding if the parameter can be inferred, carefully consider all the context to see if it supports a specific value. If all of the required parameters are present or can be reasonably inferred, close the thinking tag and proceed with the tool use. BUT, if one of the values for a required parameter is missing, DO NOT invoke the tool (not even with fillers for the missing params) and instead, ask the user to provide the missing parameters using the ask_followup_question tool. DO NOT ask for more information on optional parameters if it is not provided.
4. Once you've completed the user's task, you must use the attempt_completion tool to present the result of the task to the user.
5. The user may provide feedback, which you can use to make improvements and try again. But DO NOT continue in pointless back and forth conversations, i.e. don't end your responses with questions or offers for further assistance.`
5. The user may provide feedback, which you can use to make improvements and try again. But DO NOT continue in pointless back and forth conversations, i.e. don't end your responses with questions or offers for further assistance.

</section>`
}
8 changes: 4 additions & 4 deletions src/core/prompts/sections/rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,7 @@ export function getRulesSection(
? "- **CRITICAL: For ANY exploration of code you haven't examined yet in this conversation, you MUST use the `codebase_search` tool FIRST before using search_files or other file exploration tools.** This requirement applies throughout the entire conversation, not just when starting a task. The codebase_search tool uses semantic search to find relevant code based on meaning, not just keywords, making it much more effective for understanding how features are implemented. Even if you've already explored some parts of the codebase, any new area or functionality you need to understand requires using codebase_search first.\n"
: ""

return `====

RULES
return `<section name="RULES">

- The project base directory is: ${cwd.toPosix()}
- All file paths must be relative to this directory. However, commands may change directories in terminals, so respect working directory specified by the response to <execute_command>.
Expand Down Expand Up @@ -96,5 +94,7 @@ ${getEditingInstructions(diffStrategy)}
supportsComputerUse
? " Then if you want to test your work, you might use browser_action to launch the site, wait for the user's response confirming the site was launched along with a screenshot, then perhaps e.g., click a button to test functionality if needed, wait for the user's response confirming the button was clicked along with a screenshot of the new state, before finally closing the browser."
: ""
}`
}

</section>`
}
8 changes: 4 additions & 4 deletions src/core/prompts/sections/system-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ import osName from "os-name"
import { getShell } from "../../../utils/shell"

export function getSystemInfoSection(cwd: string): string {
let details = `====

SYSTEM INFORMATION
let details = `<section name="SYSTEM INFORMATION">

Operating System: ${osName()}
Default Shell: ${getShell()}
Home Directory: ${os.homedir().toPosix()}
Current Workspace Directory: ${cwd.toPosix()}

The Current Workspace Directory is the active VS Code project directory, and is therefore the default directory for all tool operations. New terminals will be created in the current workspace directory, however if you change directories in a terminal it will then have a different working directory; changing directories in a terminal does not modify the workspace directory, because you do not have access to change the workspace directory. When the user initially gives you a task, a recursive list of all filepaths in the current workspace directory ('/test/path') will be included in environment_details. This provides an overview of the project's file structure, offering key insights into the project from directory/file names (how developers conceptualize and organize their code) and file extensions (the language used). This can also guide decision-making on which files to explore further. If you need to further explore directories such as outside the current workspace directory, you can use the list_files tool. If you pass 'true' for the recursive parameter, it will list files recursively. Otherwise, it will list files at the top level, which is better suited for generic directories where you don't necessarily need the nested structure, like the Desktop.`
The Current Workspace Directory is the active VS Code project directory, and is therefore the default directory for all tool operations. New terminals will be created in the current workspace directory, however if you change directories in a terminal it will then have a different working directory; changing directories in a terminal does not modify the workspace directory, because you do not have access to change the workspace directory. When the user initially gives you a task, a recursive list of all filepaths in the current workspace directory ('/test/path') will be included in environment_details. This provides an overview of the project's file structure, offering key insights into the project from directory/file names (how developers conceptualize and organize their code) and file extensions (the language used). This can also guide decision-making on which files to explore further. If you need to further explore directories such as outside the current workspace directory, you can use the list_files tool. If you pass 'true' for the recursive parameter, it will list files recursively. Otherwise, it will list files at the top level, which is better suited for generic directories where you don't necessarily need the nested structure, like the Desktop.

</section>`

return details
}
8 changes: 4 additions & 4 deletions src/core/prompts/sections/tool-use.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
export function getSharedToolUseSection(): string {
return `====

TOOL USE
return `<section name="TOOL USE">

You have access to a set of tools that are executed upon the user's approval. You can use one tool per message, and will receive the result of that tool use in the user's response. You use tools step-by-step to accomplish a given task, with each tool use informed by the result of the previous tool use.

Expand All @@ -15,5 +13,7 @@ Tool uses are formatted using XML-style tags. The tool name itself becomes the X
...
</actual_tool_name>

Always use the actual tool name as the XML tag name for proper parsing and execution.`
Always use the actual tool name as the XML tag name for proper parsing and execution.

</section>`
}
8 changes: 5 additions & 3 deletions src/core/prompts/tools/access-mcp-resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ export function getAccessMcpResourceDescription(args: ToolArgs): string | undefi
if (!args.mcpHub) {
return undefined
}
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.
return `<tool name="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.</description>
Parameters:
- server_name: (required) The name of the MCP server providing the resource
- uri: (required) The URI identifying the specific resource to access
Expand All @@ -20,5 +20,7 @@ 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>`
</access_mcp_resource>

</tool>`
}
8 changes: 5 additions & 3 deletions src/core/prompts/tools/ask-followup-question.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export function getAskFollowupQuestionDescription(): string {
return `## ask_followup_question
Description: Ask the user a question to gather additional information needed to complete the task. Use when you need clarification or more details to proceed effectively.
return `<tool name="ask_followup_question">
<description>Ask the user a question to gather additional information needed to complete the task. Use when you need clarification or more details to proceed effectively.</description>

Parameters:
- question: (required) A clear, specific question addressing the information needed
Expand All @@ -23,5 +23,7 @@ Example:
<suggest>./config/frontend-config.json</suggest>
<suggest>./frontend-config.json</suggest>
</follow_up>
</ask_followup_question>`
</ask_followup_question>

</tool>`
}
10 changes: 6 additions & 4 deletions src/core/prompts/tools/attempt-completion.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { ToolArgs } from "./types"

export function getAttemptCompletionDescription(args?: ToolArgs): 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. 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.
return `<tool name="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. The user may respond with feedback if they are not satisfied with the result, which you can use to make improvements and try again.</description>
<important>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.</important>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this intentional? I notice this tool uses an <important> tag for critical notes while other tools embed important information directly in the <description> tag. Could we consider standardizing this approach across all tools for consistency?

For example, other tools include warnings like "IMPORTANT: You can read a maximum of 5 files..." directly in the description, but here we have a separate <important> tag.

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.
Usage:
Expand All @@ -18,5 +18,7 @@ Example: Requesting to attempt completion with a result
<result>
I've updated the CSS
</result>
</attempt_completion>`
</attempt_completion>

</tool>`
}
10 changes: 7 additions & 3 deletions src/core/prompts/tools/browser-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ export function getBrowserActionDescription(args: ToolArgs): string | undefined
if (!args.supportsComputerUse) {
return undefined
}
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.
return `<tool name="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.</description>
<important>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to my comment on attempt-completion.ts - this tool uses both <description> and <important> tags, creating a mixed content structure. While this provides good separation of concerns, it differs from the pattern used in most other tools.

Could we consider either:

  1. Moving all tools to use the <important> tag pattern for consistency, or
  2. Embedding the important notes in the description like other tools do?

- 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 **${args.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.
</important>
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**.
Expand Down Expand Up @@ -55,5 +57,7 @@ Example: Requesting to click on the element at coordinates 450,300
<browser_action>
<action>click</action>
<coordinate>450,300</coordinate>
</browser_action>`
</browser_action>

</tool>`
}
7 changes: 4 additions & 3 deletions src/core/prompts/tools/codebase-search.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ToolArgs } from "./types"

export function getCodebaseSearchDescription(args: ToolArgs): string {
return `## codebase_search
Description: Find files most relevant to the search query using semantic search. Searches based on meaning rather than exact text matches. By default searches entire workspace. Reuse the user's exact wording unless there's a clear reason not to - their phrasing often helps semantic search. Queries MUST be in English (translate if needed).
return `<tool name="codebase_search">
<description>Find files most relevant to the search query using semantic search. Searches based on meaning rather than exact text matches. By default searches entire workspace. Reuse the user's exact wording unless there's a clear reason not to - their phrasing often helps semantic search. Queries MUST be in English (translate if needed).</description>

Parameters:
- query: (required) The search query. Reuse the user's exact wording/question format unless there's a clear reason not to.
Expand All @@ -19,5 +19,6 @@ Example:
<query>User login and password hashing</query>
<path>src/auth</path>
</codebase_search>
`

</tool>`
}
Loading
Loading