-
Notifications
You must be signed in to change notification settings - Fork 51
Description
Detailed here:
Custom editing tool for viewing, creating and editing files
- State is persistent across command calls and discussions with the user
- If
path
is a file,view
displays the result of applyingcat -n
. Ifpath
is a directory,view
lists non-hidden files and directories up to 2 levels deep - The
create
command cannot be used if the specifiedpath
already exists as a file - If a
command
generates a long output, it will be truncated and marked with<response clipped>
- The
undo_edit
command will revert the last edit made to the file atpath
Notes for using the str_replace
command:
- The
old_str
parameter should match EXACTLY one or more consecutive lines from the original file. Be mindful of whitespaces! - If the
old_str
parameter is not unique in the file, the replacement will not be performed. Make sure to include enough context inold_str
to make it unique - The
new_str
parameter should contain the edited lines that should replace theold_str
Input tool schema:
{
"properties": {
"command": {
"description": "The commands to run. Allowed options are: view
, create
, str_replace
, insert
, undo_edit
.",
"enum": ["view", "create", "str_replace", "insert", "undo_edit"],
"type": "string",
},
"file_text": {
"description": "Required parameter of create
command, with the content of the file to be created.",
"type": "string",
},
"insert_line": {
"description": "Required parameter of insert
command. The new_str
will be inserted AFTER the line insert_line
of path
.",
"type": "integer",
},
"new_str": {
"description": "Optional parameter of str_replace
command containing the new string (if not given, no string will be added). Required parameter of insert
command containing the string to insert.",
"type": "string",
},
"old_str": {
"description": "Required parameter of str_replace
command containing the string in path
to replace.",
"type": "string",
},
"path": {
"description": "Absolute path to file or directory, e.g. /repo/file.py
or /repo
.",
"type": "string",
},
"view_range": {
"description": "Optional parameter of view
command when path
points to a file. If none is given, the full file is shown. If provided, the file will be shown in the indicated line number range, e.g. [11, 12] will show lines 11 and 12. Indexing at 1 to start. Setting [start_line, -1]
shows all lines from start_line
to the end of the file.",
"items": {"type": "integer"},
"type": "array",
},
},
"required": ["command", "path"],
"type": "object",
}
More details here
The Text Editor Tool provides functionality for viewing and editing text files:
const textEditorTool = anthropic.tools.textEditor_20241022({
execute: async ({
command,
path,
file_text,
insert_line,
new_str,
old_str,
view_range,
}) => {
// Implement your text editing logic here
// Return the result of the text editing operation
},
});
Parameters:
command ('view' | 'create' | 'str_replace' | 'insert' | 'undo_edit'): The command to run.
path (string): Absolute path to file or directory, e.g. /repo/file.py or /repo.
file_text (string, optional): Required for create command, with the content of the file to be created.
insert_line (number, optional): Required for insert command. The line number after which to insert the new string.
new_str (string, optional): New string for str_replace or insert commands.
old_str (string, optional): Required for str_replace command, containing the string to replace.
view_range (number[], optional): Optional for view command to specify line range to show.