Skip to content

Commit a0ae2c6

Browse files
committed
feat: refactor system prompt sections from markdown to XML format
- Replace markdown separators (====) with XML <section> tags - Update all section files to use <section name='SECTION_NAME'> format - Convert tool descriptions from ## toolname to <tool name='toolname'> format - Maintain backward compatibility with existing functionality - Improve semantic structure for better parsing and validation This change provides clearer semantic boundaries between different types of content and makes the prompt structure easier to programmatically parse and manipulate.
1 parent a79c3d0 commit a0ae2c6

27 files changed

+134
-93
lines changed

src/core/prompts/sections/capabilities.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ export function getCapabilitiesSection(
99
diffStrategy?: DiffStrategy,
1010
codeIndexManager?: CodeIndexManager,
1111
): string {
12-
return `====
13-
14-
CAPABILITIES
12+
return `<section name="CAPABILITIES">
1513
1614
- You have access to tools that let you execute CLI commands on the user's computer, list files, view source code definitions, regex search${
1715
supportsComputerUse ? ", use the browser" : ""
@@ -38,5 +36,7 @@ CAPABILITIES
3836
- 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.
3937
`
4038
: ""
41-
}`
39+
}
40+
41+
</section>`
4242
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export function markdownFormattingSection(): string {
2-
return `====
2+
return `<section name="MARKDOWN RULES">
33
4-
MARKDOWN RULES
4+
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>
55
6-
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>`
6+
</section>`
77
}

src/core/prompts/sections/mcp-servers.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export async function getMcpServersSection(
4949
.join("\n\n")}`
5050
: "(No MCP servers currently connected)"
5151

52-
const baseSection = `MCP SERVERS
52+
const baseSection = `<section name="MCP SERVERS">
5353
5454
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:
5555
@@ -60,20 +60,27 @@ The Model Context Protocol (MCP) enables communication between the system and MC
6060
6161
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.
6262
63-
${connectedServers}`
63+
${connectedServers}
64+
65+
</section>`
6466

6567
if (!enableMcpServerCreation) {
6668
return baseSection
6769
}
6870

71+
// Remove the closing </section> tag from baseSection and add the additional content
72+
const baseSectionWithoutClosing = baseSection.replace("</section>", "")
73+
6974
return (
70-
baseSection +
75+
baseSectionWithoutClosing +
7176
`
7277
## Creating an MCP Server
7378
7479
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:
7580
<fetch_instructions>
7681
<task>create_mcp_server</task>
77-
</fetch_instructions>`
82+
</fetch_instructions>
83+
84+
</section>`
7885
)
7986
}

src/core/prompts/sections/modes.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ export async function getModesSection(context: vscode.ExtensionContext): Promise
1313
// Get all modes with their overrides from extension state
1414
const allModes = await getAllModesWithPrompts(context)
1515

16-
let modesContent = `====
17-
18-
MODES
16+
let modesContent = `<section name="MODES">
1917
2018
- These are the currently available modes:
2119
${allModes
@@ -37,7 +35,8 @@ If the user asks you to create or edit a new mode for this project, you should r
3735
<fetch_instructions>
3836
<task>create_mode</task>
3937
</fetch_instructions>
40-
`
38+
39+
</section>`
4140

4241
return modesContent
4342
}

src/core/prompts/sections/objective.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ export function getObjectiveSection(
1414
? "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, "
1515
: "First, "
1616

17-
return `====
18-
19-
OBJECTIVE
17+
return `<section name="OBJECTIVE">
2018
2119
You accomplish a given task iteratively, breaking it down into clear steps and working through them methodically.
2220
2321
1. Analyze the user's task and set clear, achievable goals to accomplish it. Prioritize these goals in a logical order.
2422
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.
2523
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.
2624
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.
27-
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.`
25+
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.
26+
27+
</section>`
2828
}

src/core/prompts/sections/rules.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,7 @@ export function getRulesSection(
6161
? "- **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"
6262
: ""
6363

64-
return `====
65-
66-
RULES
64+
return `<section name="RULES">
6765
6866
- The project base directory is: ${cwd.toPosix()}
6967
- 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>.
@@ -96,5 +94,7 @@ ${getEditingInstructions(diffStrategy)}
9694
supportsComputerUse
9795
? " 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."
9896
: ""
99-
}`
97+
}
98+
99+
</section>`
100100
}

src/core/prompts/sections/system-info.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ import osName from "os-name"
44
import { getShell } from "../../../utils/shell"
55

66
export function getSystemInfoSection(cwd: string): string {
7-
let details = `====
8-
9-
SYSTEM INFORMATION
7+
let details = `<section name="SYSTEM INFORMATION">
108
119
Operating System: ${osName()}
1210
Default Shell: ${getShell()}
1311
Home Directory: ${os.homedir().toPosix()}
1412
Current Workspace Directory: ${cwd.toPosix()}
1513
16-
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.`
14+
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.
15+
16+
</section>`
1717

1818
return details
1919
}

src/core/prompts/sections/tool-use.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
export function getSharedToolUseSection(): string {
2-
return `====
3-
4-
TOOL USE
2+
return `<section name="TOOL USE">
53
64
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.
75
@@ -15,5 +13,7 @@ Tool uses are formatted using XML-style tags. The tool name itself becomes the X
1513
...
1614
</actual_tool_name>
1715
18-
Always use the actual tool name as the XML tag name for proper parsing and execution.`
16+
Always use the actual tool name as the XML tag name for proper parsing and execution.
17+
18+
</section>`
1919
}

src/core/prompts/tools/access-mcp-resource.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ export function getAccessMcpResourceDescription(args: ToolArgs): string | undefi
44
if (!args.mcpHub) {
55
return undefined
66
}
7-
return `## access_mcp_resource
8-
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.
7+
return `<tool name="access_mcp_resource">
8+
<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>
99
Parameters:
1010
- server_name: (required) The name of the MCP server providing the resource
1111
- uri: (required) The URI identifying the specific resource to access
@@ -20,5 +20,7 @@ Example: Requesting to access an MCP resource
2020
<access_mcp_resource>
2121
<server_name>weather-server</server_name>
2222
<uri>weather://san-francisco/current</uri>
23-
</access_mcp_resource>`
23+
</access_mcp_resource>
24+
25+
</tool>`
2426
}

src/core/prompts/tools/ask-followup-question.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export function getAskFollowupQuestionDescription(): string {
2-
return `## ask_followup_question
3-
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.
2+
return `<tool name="ask_followup_question">
3+
<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>
44
55
Parameters:
66
- question: (required) A clear, specific question addressing the information needed
@@ -23,5 +23,7 @@ Example:
2323
<suggest>./config/frontend-config.json</suggest>
2424
<suggest>./frontend-config.json</suggest>
2525
</follow_up>
26-
</ask_followup_question>`
26+
</ask_followup_question>
27+
28+
</tool>`
2729
}

0 commit comments

Comments
 (0)