Skip to content

Commit 73782d9

Browse files
committed
fix: strengthen codebase_search enforcement throughout conversations
- Remove conditional 'when starting a new task' language - Change to 'For ANY exploration of code you haven't examined yet in this conversation' - Add explicit statements that the requirement applies throughout the entire conversation - Update test expectations to match the new enforcement language This ensures codebase_search is used consistently throughout conversations, not just at the beginning of tasks, improving code discovery and understanding.
1 parent 8c1aec1 commit 73782d9

File tree

5 files changed

+12
-11
lines changed

5 files changed

+12
-11
lines changed

src/core/prompts/sections/__tests__/objective.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ describe("getObjectiveSection", () => {
2222

2323
// Check that the objective includes the codebase_search enforcement
2424
expect(objective).toContain(
25-
"if the task involves understanding existing code or functionality, you MUST use the `codebase_search` tool",
25+
"for ANY exploration of code you haven't examined yet in this conversation, you MUST use the `codebase_search` tool",
2626
)
2727
expect(objective).toContain("BEFORE using any other search or file exploration tools")
28+
expect(objective).toContain("This applies throughout the entire task, not just at the beginning")
2829
})
2930
})
3031

src/core/prompts/sections/__tests__/tool-use-guidelines.spec.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ describe("getToolUseGuidelinesSection", () => {
2222

2323
// Check that the guidelines include the codebase_search enforcement
2424
expect(guidelines).toContain(
25-
"IMPORTANT: When starting a new task or when you need to understand existing code/functionality, you MUST use the `codebase_search` tool FIRST",
25+
"CRITICAL: For ANY exploration of code you haven't examined yet in this conversation, you MUST use the `codebase_search` tool FIRST",
2626
)
27-
expect(guidelines).toContain("before any other search tools")
27+
expect(guidelines).toContain("before any other search or file exploration tools")
2828
expect(guidelines).toContain(
29-
"semantic search tool helps you find relevant code based on meaning rather than just keywords",
29+
"semantic search to find relevant code based on meaning rather than just keywords",
3030
)
3131
})
3232

@@ -35,7 +35,7 @@ describe("getToolUseGuidelinesSection", () => {
3535

3636
// Check that all numbered items are present
3737
expect(guidelines).toContain("1. In <thinking> tags")
38-
expect(guidelines).toContain("2. **IMPORTANT:")
38+
expect(guidelines).toContain("2. **CRITICAL:")
3939
expect(guidelines).toContain("3. Choose the most appropriate tool")
4040
expect(guidelines).toContain("4. If multiple actions are needed")
4141
expect(guidelines).toContain("5. Formulate your tool use")
@@ -50,9 +50,9 @@ describe("getToolUseGuidelinesSection", () => {
5050

5151
// Check that the guidelines do not include the codebase_search enforcement
5252
expect(guidelines).not.toContain(
53-
"IMPORTANT: When starting a new task or when you need to understand existing code/functionality, you MUST use the `codebase_search` tool FIRST",
53+
"CRITICAL: For ANY exploration of code you haven't examined yet in this conversation, you MUST use the `codebase_search` tool FIRST",
5454
)
55-
expect(guidelines).not.toContain("semantic search tool helps you find relevant code based on meaning")
55+
expect(guidelines).not.toContain("semantic search to find relevant code based on meaning")
5656
})
5757

5858
it("should maintain proper numbering without codebase_search", () => {

src/core/prompts/sections/objective.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export function getObjectiveSection(
1111
codeIndexManager.isInitialized
1212

1313
const codebaseSearchInstruction = isCodebaseSearchAvailable
14-
? "First, if the task involves understanding existing code or functionality, 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. Then, "
14+
? "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

1717
return `====

src/core/prompts/sections/rules.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export function getRulesSection(
5858
codeIndexManager.isInitialized
5959

6060
const codebaseSearchRule = isCodebaseSearchAvailable
61-
? "- **CRITICAL: When you need to understand existing code or functionality, ALWAYS use the `codebase_search` tool FIRST before using search_files or other file exploration tools.** 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.\n"
61+
? "- **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

6464
return `====

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ export function getToolUseGuidelinesSection(codeIndexManager?: CodeIndexManager)
1919
// Conditional codebase search guideline
2020
if (isCodebaseSearchAvailable) {
2121
guidelinesList.push(
22-
`${itemNumber++}. **IMPORTANT: When starting a new task or when you need to understand existing code/functionality, you MUST use the \`codebase_search\` tool FIRST before any other search tools.** This semantic search tool helps you find relevant code based on meaning rather than just keywords. Only after using codebase_search should you use other tools like search_files, list_files, or read_file for more specific exploration.`,
22+
`${itemNumber++}. **CRITICAL: For ANY exploration of code you haven't examined yet in this conversation, you MUST use the \`codebase_search\` tool FIRST before any other search or file exploration tools.** This applies throughout the entire conversation, not just at the beginning. The codebase_search tool uses semantic search to find relevant code based on meaning rather than just keywords, making it far more effective than regex-based search_files for understanding implementations. Even if you've already explored some code, any new area of exploration requires codebase_search first.`,
2323
)
2424
guidelinesList.push(
25-
`${itemNumber++}. Choose the most appropriate tool based on the task and the tool descriptions provided. Assess if you need additional information to proceed, and which of the available tools would be most effective for gathering this information. For example using the list_files tool is more effective than running a command like \`ls\` in the terminal. It's critical that you think about each available tool and use the one that best fits the current step in the task.`,
25+
`${itemNumber++}. Choose the most appropriate tool based on the task and the tool descriptions provided. After using codebase_search for initial exploration of any new code area, you may then use more specific tools like search_files (for regex patterns), list_files, or read_file for detailed examination. For example, using the list_files tool is more effective than running a command like \`ls\` in the terminal. It's critical that you think about each available tool and use the one that best fits the current step in the task.`,
2626
)
2727
} else {
2828
guidelinesList.push(

0 commit comments

Comments
 (0)