|
|
|
|
@@ -43,7 +43,7 @@ CAPABILITIES
|
|
|
|
|
- You have access to tools that let you execute CLI commands on the user's computer, list files, view source code definitions, regex search${
|
|
|
|
|
supportsImages ? ", inspect websites" : ""
|
|
|
|
|
}, 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 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 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.
|
|
|
|
|
- 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 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 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 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 write_to_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.
|
|
|
|
|
@@ -57,10 +57,10 @@ CAPABILITIES
|
|
|
|
|
|
|
|
|
|
RULES
|
|
|
|
|
|
|
|
|
|
- Your current working directory is: ${cwd}
|
|
|
|
|
- You cannot \`cd\` into a different directory to complete a task. You are stuck operating from '${cwd}', so be sure to pass in the correct 'path' parameter when using tools that require a path.
|
|
|
|
|
- Your current working directory is: ${cwd.toPosix()}
|
|
|
|
|
- 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}', and if so prepend with \`cd\`'ing into that directory && then executing the command (as one command since you are stuck operating from '${cwd}'). For example, if you needed to run \`npm install\` in a project outside of '${cwd}', 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)\`.
|
|
|
|
|
- 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 write_to_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 writing 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.
|
|
|
|
|
- You must try to use multiple tools in one request when possible. For example if you were to create a website, you would use the write_to_file tool to create the necessary files with their appropriate contents all at once. Or if you wanted to analyze a project, you could use the read_file tool multiple times to look at several key files. This will help you accomplish the user's task more efficiently.
|
|
|
|
|
@@ -94,8 +94,8 @@ SYSTEM INFORMATION
|
|
|
|
|
|
|
|
|
|
Operating System: ${osName()}
|
|
|
|
|
Default Shell: ${defaultShell}
|
|
|
|
|
Home Directory: ${os.homedir()}
|
|
|
|
|
Current Working Directory: ${cwd}
|
|
|
|
|
Home Directory: ${os.homedir().toPosix()}
|
|
|
|
|
Current Working Directory: ${cwd.toPosix()}
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
const cwd =
|
|
|
|
|
@@ -104,7 +104,7 @@ const cwd =
|
|
|
|
|
const tools = (supportsImages: boolean): Tool[] => [
|
|
|
|
|
{
|
|
|
|
|
name: "execute_command",
|
|
|
|
|
description: `Execute a CLI command on the system. Use this when you need to perform system operations or run specific commands to accomplish any step in the user's task. You must tailor your command to the user's system and provide a clear explanation of what the command does. Prefer to execute complex CLI commands over creating executable scripts, as they are more flexible and easier to run. Commands will be executed in the current working directory: ${cwd}`,
|
|
|
|
|
description: `Execute a CLI command on the system. Use this when you need to perform system operations or run specific commands to accomplish any step in the user's task. You must tailor your command to the user's system and provide a clear explanation of what the command does. Prefer to execute complex CLI commands over creating executable scripts, as they are more flexible and easier to run. Commands will be executed in the current working directory: ${cwd.toPosix()}`,
|
|
|
|
|
input_schema: {
|
|
|
|
|
type: "object",
|
|
|
|
|
properties: {
|
|
|
|
|
@@ -126,7 +126,7 @@ const tools = (supportsImages: boolean): Tool[] => [
|
|
|
|
|
properties: {
|
|
|
|
|
path: {
|
|
|
|
|
type: "string",
|
|
|
|
|
description: `The path of the file to read (relative to the current working directory ${cwd})`,
|
|
|
|
|
description: `The path of the file to read (relative to the current working directory ${cwd.toPosix()})`,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
required: ["path"],
|
|
|
|
|
@@ -141,7 +141,7 @@ const tools = (supportsImages: boolean): Tool[] => [
|
|
|
|
|
properties: {
|
|
|
|
|
path: {
|
|
|
|
|
type: "string",
|
|
|
|
|
description: `The path of the file to write to (relative to the current working directory ${cwd})`,
|
|
|
|
|
description: `The path of the file to write to (relative to the current working directory ${cwd.toPosix()})`,
|
|
|
|
|
},
|
|
|
|
|
content: {
|
|
|
|
|
type: "string",
|
|
|
|
|
@@ -160,7 +160,7 @@ const tools = (supportsImages: boolean): Tool[] => [
|
|
|
|
|
properties: {
|
|
|
|
|
path: {
|
|
|
|
|
type: "string",
|
|
|
|
|
description: `The path of the directory to search in (relative to the current working directory ${cwd}). This directory will be recursively searched.`,
|
|
|
|
|
description: `The path of the directory to search in (relative to the current working directory ${cwd.toPosix()}). This directory will be recursively searched.`,
|
|
|
|
|
},
|
|
|
|
|
regex: {
|
|
|
|
|
type: "string",
|
|
|
|
|
@@ -184,7 +184,7 @@ const tools = (supportsImages: boolean): Tool[] => [
|
|
|
|
|
properties: {
|
|
|
|
|
path: {
|
|
|
|
|
type: "string",
|
|
|
|
|
description: `The path of the directory to list contents for (relative to the current working directory ${cwd})`,
|
|
|
|
|
description: `The path of the directory to list contents for (relative to the current working directory ${cwd.toPosix()})`,
|
|
|
|
|
},
|
|
|
|
|
recursive: {
|
|
|
|
|
type: "string",
|
|
|
|
|
@@ -205,7 +205,7 @@ const tools = (supportsImages: boolean): Tool[] => [
|
|
|
|
|
properties: {
|
|
|
|
|
path: {
|
|
|
|
|
type: "string",
|
|
|
|
|
description: `The path of the directory (relative to the current working directory ${cwd}) to list top level source code definitions for`,
|
|
|
|
|
description: `The path of the directory (relative to the current working directory ${cwd.toPosix()}) to list top level source code definitions for`,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
required: ["path"],
|
|
|
|
|
@@ -658,7 +658,7 @@ export class ClaudeDev {
|
|
|
|
|
newUserContent.push({
|
|
|
|
|
type: "text",
|
|
|
|
|
text:
|
|
|
|
|
`Task resumption: This autonomous coding task was interrupted ${agoText}. It may or may not be complete, so please reassess the task context. Be aware that the project state may have changed since then. The current working directory is now '${cwd}'. If the task has not been completed, retry the last step before interruption and proceed with completing the task.` +
|
|
|
|
|
`Task resumption: This autonomous coding task was interrupted ${agoText}. It may or may not be complete, so please reassess the task context. Be aware that the project state may have changed since then. The current working directory is now '${cwd.toPosix()}'. If the task has not been completed, retry the last step before interruption and proceed with completing the task.` +
|
|
|
|
|
(responseText
|
|
|
|
|
? `\n\nNew instructions for task continuation:\n<user_message>\n${responseText}\n</user_message>`
|
|
|
|
|
: ""),
|
|
|
|
|
@@ -767,7 +767,7 @@ export class ClaudeDev {
|
|
|
|
|
// Custom error message for this particular case
|
|
|
|
|
await this.say(
|
|
|
|
|
"error",
|
|
|
|
|
`Claude tried to use write_to_file for '${relPath}' without value for required parameter 'content'. This is likely due to reaching the maximum output token limit. Retrying with suggestion to change response size...`
|
|
|
|
|
`Claude tried to use write_to_file for '${relPath.toPosix()}' without value for required parameter 'content'. This is likely due to reaching the maximum output token limit. Retrying with suggestion to change response size...`
|
|
|
|
|
)
|
|
|
|
|
return [
|
|
|
|
|
false,
|
|
|
|
|
@@ -1098,7 +1098,7 @@ export class ClaudeDev {
|
|
|
|
|
const normalizedEditedContent = editedContent.replace(/\r\n|\n/g, newContentEOL)
|
|
|
|
|
const normalizedNewContent = newContent.replace(/\r\n|\n/g, newContentEOL) // just in case the new content has a mix of varying EOL characters
|
|
|
|
|
if (normalizedEditedContent !== normalizedNewContent) {
|
|
|
|
|
const userDiff = diff.createPatch(relPath, normalizedNewContent, normalizedEditedContent)
|
|
|
|
|
const userDiff = diff.createPatch(relPath.toPosix(), normalizedNewContent, normalizedEditedContent)
|
|
|
|
|
await this.say(
|
|
|
|
|
"user_feedback_diff",
|
|
|
|
|
JSON.stringify({
|
|
|
|
|
@@ -1110,14 +1110,14 @@ export class ClaudeDev {
|
|
|
|
|
return [
|
|
|
|
|
false,
|
|
|
|
|
await this.formatToolResult(
|
|
|
|
|
`The user made the following updates to your content:\n\n${userDiff}\n\nThe updated content, which includes both your original modifications and the user's additional edits, has been successfully saved to ${relPath}. (Note this does not mean you need to re-write the file with the user's changes, as they have already been applied to the file.)${newProblemsMessage}`
|
|
|
|
|
`The user made the following updates to your content:\n\n${userDiff}\n\nThe updated content, which includes both your original modifications and the user's additional edits, has been successfully saved to ${relPath.toPosix()}. (Note this does not mean you need to re-write the file with the user's changes, as they have already been applied to the file.)${newProblemsMessage}`
|
|
|
|
|
),
|
|
|
|
|
]
|
|
|
|
|
} else {
|
|
|
|
|
return [
|
|
|
|
|
false,
|
|
|
|
|
await this.formatToolResult(
|
|
|
|
|
`The content was successfully saved to ${relPath}.${newProblemsMessage}`
|
|
|
|
|
`The content was successfully saved to ${relPath.toPosix()}.${newProblemsMessage}`
|
|
|
|
|
),
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
@@ -1177,7 +1177,7 @@ export class ClaudeDev {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
createPrettyPatch(filename = "file", oldStr: string, newStr: string) {
|
|
|
|
|
const patch = diff.createPatch(filename, oldStr, newStr)
|
|
|
|
|
const patch = diff.createPatch(filename.toPosix(), oldStr, newStr)
|
|
|
|
|
const lines = patch.split("\n")
|
|
|
|
|
const prettyPatchLines = lines.slice(4)
|
|
|
|
|
return prettyPatchLines.join("\n")
|
|
|
|
|
@@ -1293,18 +1293,18 @@ export class ClaudeDev {
|
|
|
|
|
const absolutePath = path.resolve(cwd, relPath)
|
|
|
|
|
if (cwd === path.join(os.homedir(), "Desktop")) {
|
|
|
|
|
// User opened vscode without a workspace, so cwd is the Desktop. Show the full absolute path to keep the user aware of where files are being created
|
|
|
|
|
return absolutePath
|
|
|
|
|
return absolutePath.toPosix()
|
|
|
|
|
}
|
|
|
|
|
if (path.normalize(absolutePath) === path.normalize(cwd)) {
|
|
|
|
|
return path.basename(absolutePath)
|
|
|
|
|
return path.basename(absolutePath).toPosix()
|
|
|
|
|
} else {
|
|
|
|
|
// show the relative path to the cwd
|
|
|
|
|
const normalizedRelPath = path.relative(cwd, absolutePath)
|
|
|
|
|
if (absolutePath.includes(cwd)) {
|
|
|
|
|
return normalizedRelPath
|
|
|
|
|
return normalizedRelPath.toPosix()
|
|
|
|
|
} else {
|
|
|
|
|
// we are outside the cwd, so show the absolute path (useful for when claude passes in '../../' for example)
|
|
|
|
|
return absolutePath
|
|
|
|
|
return absolutePath.toPosix()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@@ -1313,12 +1313,12 @@ export class ClaudeDev {
|
|
|
|
|
const sorted = files
|
|
|
|
|
.map((file) => {
|
|
|
|
|
// convert absolute path to relative path
|
|
|
|
|
const relativePath = path.relative(absolutePath, file)
|
|
|
|
|
const relativePath = path.relative(absolutePath, file).toPosix()
|
|
|
|
|
return file.endsWith("/") ? relativePath + "/" : relativePath
|
|
|
|
|
})
|
|
|
|
|
// Sort so files are listed under their respective directories to make it clear what files are children of what directories. Since we build file list top down, even if file list is truncated it will show directories that claude can then explore further.
|
|
|
|
|
.sort((a, b) => {
|
|
|
|
|
const aParts = a.split("/")
|
|
|
|
|
const aParts = a.split("/") // only works if we use toPosix first
|
|
|
|
|
const bParts = b.split("/")
|
|
|
|
|
for (let i = 0; i < Math.min(aParts.length, bParts.length); i++) {
|
|
|
|
|
if (aParts[i] !== bParts[i]) {
|
|
|
|
|
@@ -1999,7 +1999,7 @@ ${this.customInstructions.trim()}
|
|
|
|
|
const visibleFiles = vscode.window.visibleTextEditors
|
|
|
|
|
?.map((editor) => editor.document?.uri?.fsPath)
|
|
|
|
|
.filter(Boolean)
|
|
|
|
|
.map((absolutePath) => path.relative(cwd, absolutePath))
|
|
|
|
|
.map((absolutePath) => path.relative(cwd, absolutePath).toPosix())
|
|
|
|
|
.join("\n")
|
|
|
|
|
if (visibleFiles) {
|
|
|
|
|
details += `\n${visibleFiles}`
|
|
|
|
|
@@ -2012,7 +2012,7 @@ ${this.customInstructions.trim()}
|
|
|
|
|
.flatMap((group) => group.tabs)
|
|
|
|
|
.map((tab) => (tab.input as vscode.TabInputText)?.uri?.fsPath)
|
|
|
|
|
.filter(Boolean)
|
|
|
|
|
.map((absolutePath) => path.relative(cwd, absolutePath))
|
|
|
|
|
.map((absolutePath) => path.relative(cwd, absolutePath).toPosix())
|
|
|
|
|
.join("\n")
|
|
|
|
|
if (openTabs) {
|
|
|
|
|
details += `\n${openTabs}`
|
|
|
|
|
@@ -2106,7 +2106,7 @@ ${this.customInstructions.trim()}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (includeFileDetails) {
|
|
|
|
|
details += `\n\n# Current Working Directory (${cwd}) Files\n`
|
|
|
|
|
details += `\n\n# Current Working Directory (${cwd.toPosix()}) Files\n`
|
|
|
|
|
const isDesktop = cwd === path.join(os.homedir(), "Desktop")
|
|
|
|
|
if (isDesktop) {
|
|
|
|
|
// don't want to immediately access desktop since it would show permission popup
|
|
|
|
|
@@ -2141,7 +2141,7 @@ ${this.customInstructions.trim()}
|
|
|
|
|
await this.say(
|
|
|
|
|
"error",
|
|
|
|
|
`Claude tried to use ${toolName}${
|
|
|
|
|
relPath ? ` for '${relPath}'` : ""
|
|
|
|
|
relPath ? ` for '${relPath.toPosix()}'` : ""
|
|
|
|
|
} without value for required parameter '${paramName}'. Retrying...`
|
|
|
|
|
)
|
|
|
|
|
return await this.formatToolError(
|
|
|
|
|
|