Compare commits

...

9 Commits

Author SHA1 Message Date
Elephant Lumps aa2e7b758d merge conflicts 2025-05-28 18:02:22 -07:00
Elephant Lumps a38f01beb4 add grep tool new format 2025-05-28 17:56:42 -07:00
Cline Evaluation be353be6c6 using json 2025-05-28 16:12:48 -07:00
Cline Evaluation b299addc53 Merge remote-tracking branch 'origin/main' into add-ls-file-tool-new-format 2025-05-28 16:11:07 -07:00
Elephant Lumps 06a9f7b4d9 use separate function for new format 2025-05-28 15:06:36 -07:00
Elephant Lumps 1a53944eb7 changeset 2025-05-28 14:56:40 -07:00
Elephant Lumps ce0f5ba08e add json tool definition and remove extra '.' 2025-05-28 14:56:09 -07:00
Elephant Lumps c3d0d06761 Merge branch 'main' into add-ls-file-tool-new-format 2025-05-28 13:41:20 -07:00
Elephant Lumps 3d358f9319 add ls file tool description, parsing, and return formatting 2025-05-28 12:23:32 -07:00
6 changed files with 77 additions and 24 deletions
+5
View File
@@ -0,0 +1,5 @@
---
"claude-dev": minor
---
Add grep tool with new parsing format
@@ -558,6 +558,17 @@ export function parseAssistantMessageV3(assistantMessage: string): AssistantMess
partial: true,
}
}
// If this is a Grep invoke, create a search_files tool
if (currentInvokeName === "Grep") {
currentToolUse = {
type: "tool_use",
name: "search_files",
params: {},
partial: true,
}
}
continue
}
}
@@ -599,6 +610,17 @@ export function parseAssistantMessageV3(assistantMessage: string): AssistantMess
currentToolUse.params["recursive"] = "false"
}
// Map parameter to tool params for Grep
if (currentToolUse && currentInvokeName === "Grep") {
if (currentParameterName === "pattern") {
currentToolUse.params["regex"] = value
} else if (currentParameterName === "path") {
currentToolUse.params["path"] = value
} else if (currentParameterName === "include") {
currentToolUse.params["file_pattern"] = value
}
}
currentParameterName = ""
continue
}
@@ -611,7 +633,7 @@ export function parseAssistantMessageV3(assistantMessage: string): AssistantMess
assistantMessage.startsWith(isInvokeClose, currentCharIndex - isInvokeClose.length + 1)
) {
// If we have a tool use from this invoke, finalize it
if (currentToolUse && currentInvokeName === "LS") {
if (currentToolUse && (currentInvokeName === "LS" || currentInvokeName === "Grep")) {
currentToolUse.partial = false
contentBlocks.push(currentToolUse)
currentToolUse = undefined
+6 -18
View File
@@ -9,6 +9,7 @@ import { bashToolDefinition } from "@core/tools/bashTool"
import { readToolDefinition } from "@core/tools/readTool"
import { writeToolDefinition } from "@core/tools/writeTool"
import {lsToolDefinition} from "@core/tools/lsTool"
import { grepToolDefinition } from "@/core/tools/grepTool"
export const SYSTEM_PROMPT_CLAUDE4 = async (
cwd: string,
@@ -116,19 +117,6 @@ Usage:
</diff>
</replace_in_file>
## 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>
## 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:
@@ -543,7 +531,7 @@ In each user message, the environment_details will specify the current mode. The
## What is PLAN MODE?
- While you are usually in ACT MODE, the user may switch to PLAN MODE in order to have a back and forth with you to plan how to best accomplish the task.
- When starting in PLAN MODE, depending on the user's request, you may need to do some information gathering e.g. using read_file or search_files to get more context about the task. You may also ask the user clarifying questions to get a better understanding of the task. You may return mermaid diagrams to visually display your understanding.
- When starting in PLAN MODE, depending on the user's request, you may need to do some information gathering e.g. using read_file or Grep to get more context about the task. You may also ask the user clarifying questions to get a better understanding of the task. You may return mermaid diagrams to visually display your understanding.
- Once you've gained more context about the user's request, you should architect a detailed plan for how you will accomplish the task. Returning mermaid diagrams may be helpful here as well.
- Then you might ask the user if they are pleased with this plan, or if they would like to make any changes. Think of this as a brainstorming session where you can discuss the task and plan the best way to accomplish it.
- If at any point a mermaid diagram would make your plan clearer to help the user quickly see the structure, you are encouraged to include a Mermaid code block in the response. (Note: if you use colors in your mermaid diagrams, be sure to use high contrast colors so the text is readable.)
@@ -557,9 +545,9 @@ CAPABILITIES
supportsBrowserUse ? ", use the browser" : ""
}, read and edit files, and ask follow-up questions. These tools help you effectively accomplish a wide range of tasks, such as writing code, making edits or improvements to existing files, understanding the current state of a project, performing system operations, and much more.
- When the user initially gives you a task, a recursive list of all filepaths in the current working directory ('${cwd.toPosix()}') 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 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.
- You can use search_files to perform regex searches across files in a specified directory, outputting context-rich results that include surrounding lines. This is particularly useful for understanding code patterns, finding specific implementations, or identifying areas that need refactoring.
- You can use Grep to perform regex searches across files in a specified directory, outputting context-rich results that include surrounding lines. This is particularly useful for understanding code patterns, finding specific implementations, or identifying areas that need refactoring.
- You can use the list_code_definition_names tool to get an overview of source code definitions for all files at the top level of a specified directory. This can be particularly useful when you need to understand the broader context and relationships between certain parts of the code. You may need to call this tool multiple times to understand various parts of the codebase related to the task.
- For example, when asked to make edits or improvements you might analyze the file structure in the initial environment_details to get an overview of the project, then use list_code_definition_names to get further insight using source code definitions for files located in relevant directories, then read_file to examine the contents of relevant files, analyze the code and suggest improvements or make necessary edits, then use the replace_in_file tool to implement changes. If you refactored code that could affect other parts of the codebase, you could use search_files to ensure you update other files as needed.
- For example, when asked to make edits or improvements you might analyze the file structure in the initial environment_details to get an overview of the project, then use list_code_definition_names to get further insight using source code definitions for files located in relevant directories, then read_file to examine the contents of relevant files, analyze the code and suggest improvements or make necessary edits, then use the replace_in_file tool to implement changes. If you refactored code that could affect other parts of the codebase, you could use Grep to ensure you update other files as needed.
- You can use the execute_command tool to run commands on the user's computer whenever you feel it can help accomplish the user's task. When you need to execute a CLI command, you must provide a clear explanation of what the command does. Prefer to execute complex CLI commands over creating executable scripts, since they are more flexible and easier to run. Interactive and long-running commands are allowed, since the commands are run in the user's VSCode terminal. The user may keep commands running in the background and you will be kept updated on their status along the way. Each command you execute is run in a new terminal instance.${
supportsBrowserUse
? "\n- You can use the browser_action tool to interact with websites (including html files and locally running development servers) through a Puppeteer-controlled browser when you feel it is necessary in accomplishing the user's task. This tool is particularly useful for web development tasks as it allows you to launch a browser, navigate to pages, interact with elements through clicks and keyboard input, and capture the results through screenshots and console logs. This tool may be useful at key stages of web development tasks-such as after implementing new features, making substantial changes, when troubleshooting issues, or to verify the result of your work. You can analyze the provided screenshots to ensure correct rendering or identify errors, and review console logs for runtime issues.\n - For example, if asked to add a component to a react website, you might create the necessary files, use execute_command to run the site locally, then use browser_action to launch the browser, navigate to the local server, and verify the component renders & functions correctly before closing the browser."
@@ -576,7 +564,7 @@ RULES
- You cannot \`cd\` into a different directory to complete a task. You are stuck operating from '${cwd.toPosix()}', so be sure to pass in the correct 'path' parameter when using tools that require a path.
- Do not use the ~ character or $HOME to refer to the home directory.
- Before using the execute_command tool, you must first think about the SYSTEM INFORMATION context provided to understand the user's environment and tailor your commands to ensure they are compatible with their system. You must also consider if the command you need to run should be executed in a specific directory outside of the current working directory '${cwd.toPosix()}', and if so prepend with \`cd\`'ing into that directory && then executing the command (as one command since you are stuck operating from '${cwd.toPosix()}'). For example, if you needed to run \`npm install\` in a project outside of '${cwd.toPosix()}', you would need to prepend with a \`cd\` i.e. pseudocode for this would be \`cd (path to project) && (command, in this case npm install)\`.
- When using the search_files tool, craft your regex patterns carefully to balance specificity and flexibility. Based on the user's task you may use it to find code patterns, TODO comments, function definitions, or any text-based information across the project. The results include context, so analyze the surrounding code to better understand the matches. Leverage the search_files tool in combination with other tools for more comprehensive analysis. For example, use it to find specific code patterns, then use read_file to examine the full context of interesting matches before using replace_in_file to make informed changes.
- When using the Grep tool, craft your regex patterns carefully to balance specificity and flexibility. Based on the user's task you may use it to find code patterns, TODO comments, function definitions, or any text-based information across the project. The results include context, so analyze the surrounding code to better understand the matches. Leverage the Grep tool in combination with other tools for more comprehensive analysis. For example, use it to find specific code patterns, then use read_file to examine the full context of interesting matches before using replace_in_file to make informed changes.
- When creating a new project (such as an app, website, or any software project), organize all new files within a dedicated project directory unless the user specifies otherwise. Use appropriate file paths when creating files, as the write_to_file tool will automatically create any necessary directories. Structure the project logically, adhering to best practices for the specific type of project being created. Unless otherwise specified, new projects should be easily run without additional setup, for example most projects can be built in HTML, CSS, and JavaScript - which you can open in a browser.
- Be sure to consider the type of project (e.g. Python, JavaScript, web application) when determining the appropriate structure and files to include. Also consider what files may be most relevant to accomplishing the task, for example looking at a project's manifest file would help you understand the project's dependencies, which you could incorporate into any code you write.
- When making changes to code, always consider the context in which the code is being used. Ensure that your changes are compatible with the existing codebase and that they follow the project's coding standards and best practices.
@@ -624,5 +612,5 @@ You accomplish a given task iteratively, breaking it down into clear steps and w
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. You may also provide a CLI command to showcase the result of your task; this can be particularly useful for web development tasks, where you can run e.g. \`open index.html\` to show the website you've built.
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.`
return createAntmlToolPrompt([lsToolDefinition], true, systemPrompt);
return createAntmlToolPrompt([lsToolDefinition, grepToolDefinition], true, systemPrompt);
}
@@ -126,7 +126,9 @@ export function createAntmlToolPrompt(
systemPrompt = '',
): string {
if (toolDefs.length === 0) {
if (!includeInstructions) return '';
if (!includeInstructions) {
return '';
}
const noToolsMessage = [
'In this environment you have access to a set of tools you can use to answer the user\'s question.',
+11 -4
View File
@@ -2715,6 +2715,7 @@ export class Task {
}
}
case "search_files": {
const isClaude4ModelFamily = await this.isClaude4ModelFamily()
const relDirPath: string | undefined = block.params.path
const regex: string | undefined = block.params.regex
const filePattern: string | undefined = block.params.file_pattern
@@ -2742,13 +2743,19 @@ export class Task {
} else {
if (!relDirPath) {
this.consecutiveMistakeCount++
pushToolResult(await this.sayAndCreateMissingParamError("search_files", "path"))
pushToolResult(
await this.sayAndCreateMissingParamError("search_files", "path"),
isClaude4ModelFamily,
)
await this.saveCheckpoint()
break
}
if (!regex) {
this.consecutiveMistakeCount++
pushToolResult(await this.sayAndCreateMissingParamError("search_files", "regex"))
pushToolResult(
await this.sayAndCreateMissingParamError("search_files", "regex"),
isClaude4ModelFamily,
)
await this.saveCheckpoint()
break
}
@@ -2786,12 +2793,12 @@ export class Task {
}
telemetryService.captureToolUsage(this.taskId, block.name, false, true)
}
pushToolResult(results)
pushToolResult(results, isClaude4ModelFamily)
await this.saveCheckpoint()
break
}
} catch (error) {
await handleError("searching files", error)
await handleError("searching files", error, isClaude4ModelFamily)
await this.saveCheckpoint()
break
}
+29
View File
@@ -0,0 +1,29 @@
import { ToolDefinition } from "@core/prompts/model_prompts/jsonToolToXml"
export const grepToolDefinition: ToolDefinition = {
name: "Grep",
descriptionForAgent: `- Fast content search tool that works with any codebase size
- Searches file contents using regular expressions
- Supports full regex syntax (eg. "log.*Error", "function\\\\s+\\\\w+", etc.)
- Filter files by pattern with the include parameter (eg. "*.js", "*.{ts,tsx}")
- Returns file paths with at least one match
- Use this tool when you need to find files containing specific patterns`,
inputSchema: {
type: "object",
properties: {
pattern: {
type: "string",
description: "The regular expression pattern to search for in file contents",
},
path: {
type: "string",
description: "The directory to search in.",
},
include: {
type: "string",
description: "File pattern to filter which files to search (e.g., '*.js' for JavaScript files)",
},
},
required: ["pattern", "path"],
},
}