Refactor viewSourceCodeDefinitionsTopLevel to listCodeDefinitionNames

This commit is contained in:
Saoud Rizwan
2024-08-29 20:53:11 -04:00
parent 2e93928c8f
commit a0f89959a4
5 changed files with 26 additions and 21 deletions

View File

@@ -38,8 +38,8 @@ CAPABILITIES
- You can debug complex issues and providing detailed explanations, offering architectural insights and design patterns.
- You have access to tools that let you execute CLI commands on the user's computer, list files in a directory (top level or recursively), extract source code definitions, read and write 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}') will be included in potentially_relevant_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 working 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.
- You can use the view_source_code_definitions_top_level 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 potentially_relevant_details to get an overview of the project, then use view_source_code_definitions_top_level 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 write_to_file tool to implement changes.
- 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 potentially_relevant_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 write_to_file tool to implement changes.
- The execute_command tool lets you run commands on the user's computer and should be used 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 user has the ability to send input to stdin and terminate the command on their own if needed.
====
@@ -127,15 +127,15 @@ const tools: Tool[] = [
},
},
{
name: "view_source_code_definitions_top_level",
name: "list_code_definition_names",
description:
"Parse all source code files at the top level of the specified directory to extract names of key elements like classes and functions. 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.",
"Lists 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.",
input_schema: {
type: "object",
properties: {
path: {
type: "string",
description: `The path of the directory (relative to the current working directory ${cwd}) to parse top level source code files for to view their definitions`,
description: `The path of the directory (relative to the current working directory ${cwd}) to list top level source code definitions for`,
},
},
required: ["path"],
@@ -684,8 +684,8 @@ export class ClaudeDev {
return this.readFile(toolInput.path)
case "list_files":
return this.listFiles(toolInput.path, toolInput.recursive)
case "view_source_code_definitions_top_level":
return this.viewSourceCodeDefinitionsTopLevel(toolInput.path)
case "list_code_definition_names":
return this.listCodeDefinitionNames(toolInput.path)
case "execute_command":
return this.executeCommand(toolInput.command)
case "ask_followup_question":
@@ -998,11 +998,11 @@ export class ClaudeDev {
}
}
async viewSourceCodeDefinitionsTopLevel(relDirPath?: string): Promise<ToolResponse> {
async listCodeDefinitionNames(relDirPath?: string): Promise<ToolResponse> {
if (relDirPath === undefined) {
await this.say(
"error",
"Claude tried to use view_source_code_definitions_top_level without value for required parameter 'path'. Retrying..."
"Claude tried to use list_code_definition_names without value for required parameter 'path'. Retrying..."
)
return "Error: Missing value for required parameter 'path'. Please retry with complete response."
}
@@ -1011,7 +1011,7 @@ export class ClaudeDev {
const result = await parseSourceCodeForDefinitionsTopLevel(absolutePath)
const message = JSON.stringify({
tool: "viewSourceCodeDefinitionsTopLevel",
tool: "listCodeDefinitionNames",
path: this.getReadablePath(relDirPath),
content: result,
} as ClaudeSayTool)
@@ -1433,9 +1433,14 @@ ${
`
if (verbose) {
const files = await listFiles(cwd, true)
const isDesktop = cwd === path.join(os.homedir(), "Desktop")
const files = await listFiles(cwd, !isDesktop)
const result = this.formatFilesList(cwd, files)
details += `\n# Current Working Directory Project Structure:\n${result}\n`
details += `\n# Current Working Directory ('${cwd}') File Structure:${
isDesktop
? "\n(Desktop so only top-level contents shown for brevity, use list_files to explore further if necessary)"
: ""
}:\n${result}\n`
}
details += "</potentially_relevant_details>"