fix: strengthen codebase_search enforcement throughout conversations (#5486)

This commit is contained in:
Hannes Rudolph 2025-07-08 21:12:53 -06:00 • committed by GitHub
parent f59e837bb0
commit 0028c56711
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 12 additions and 11 deletions

View file

@ -22,9 +22,10 @@ describe("getObjectiveSection", () => {
// Check that the objective includes the codebase_search enforcement
expect(objective).toContain(
"if the task involves understanding existing code or functionality, you MUST use the `codebase_search` tool",
"for ANY exploration of code you haven't examined yet in this conversation, you MUST use the `codebase_search` tool",
)
expect(objective).toContain("BEFORE using any other search or file exploration tools")
expect(objective).toContain("This applies throughout the entire task, not just at the beginning")
})
})

View file

@ -22,11 +22,11 @@ describe("getToolUseGuidelinesSection", () => {
// Check that the guidelines include the codebase_search enforcement
expect(guidelines).toContain(
"IMPORTANT: When starting a new task or when you need to understand existing code/functionality, you MUST use the `codebase_search` tool FIRST",
"CRITICAL: For ANY exploration of code you haven't examined yet in this conversation, you MUST use the `codebase_search` tool FIRST",
)
expect(guidelines).toContain("before any other search tools")
expect(guidelines).toContain("before any other search or file exploration tools")
expect(guidelines).toContain(
"semantic search tool helps you find relevant code based on meaning rather than just keywords",
"semantic search to find relevant code based on meaning rather than just keywords",
)
})
@ -35,7 +35,7 @@ describe("getToolUseGuidelinesSection", () => {
// Check that all numbered items are present
expect(guidelines).toContain("1. In <thinking> tags")
expect(guidelines).toContain("2. **IMPORTANT:")
expect(guidelines).toContain("2. **CRITICAL:")
expect(guidelines).toContain("3. Choose the most appropriate tool")
expect(guidelines).toContain("4. If multiple actions are needed")
expect(guidelines).toContain("5. Formulate your tool use")
@ -50,9 +50,9 @@ describe("getToolUseGuidelinesSection", () => {
// Check that the guidelines do not include the codebase_search enforcement
expect(guidelines).not.toContain(
"IMPORTANT: When starting a new task or when you need to understand existing code/functionality, you MUST use the `codebase_search` tool FIRST",
"CRITICAL: For ANY exploration of code you haven't examined yet in this conversation, you MUST use the `codebase_search` tool FIRST",
)
expect(guidelines).not.toContain("semantic search tool helps you find relevant code based on meaning")
expect(guidelines).not.toContain("semantic search to find relevant code based on meaning")
})
it("should maintain proper numbering without codebase_search", () => {

View file

@ -11,7 +11,7 @@ export function getObjectiveSection(
codeIndexManager.isInitialized
const codebaseSearchInstruction = isCodebaseSearchAvailable
? "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, "
? "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 `====

View file

@ -58,7 +58,7 @@ export function getRulesSection(
codeIndexManager.isInitialized
const codebaseSearchRule = isCodebaseSearchAvailable
? "- **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"
? "- **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 `====

View file

@ -19,10 +19,10 @@ export function getToolUseGuidelinesSection(codeIndexManager?: CodeIndexManager)
// Conditional codebase search guideline
if (isCodebaseSearchAvailable) {
guidelinesList.push(
`${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.`,
`${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.`,
)
guidelinesList.push(
`${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.`,
`${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.`,
)
} else {
guidelinesList.push(