Edit File Tool
edit_file tool¶
PRD¶
We want to now create an edit_file tool that will enable LLMs to edit files.
edit_filetool will be used to edit a file. It can edit any UTF-8 files just like how it can read them inread_filetool. LLM must read a file at least once before editing it.- The file must exist. If it doesn't exist,
edit_filetool will return an error. - The
edit_filetool will take 4 inputs:path,oldString,newString,shouldReplaceAll.pathis the absolute or relative path to the file to edit.oldStringis the string to replace.newStringis the string to replace with.shouldReplaceAllis a boolean that indicates whether to replace all occurrences ofoldStringwithnewString.
- The tool will return
successflag,path, andreplacementCount. - The
edit_filetool must use the existing permission mechanisms that are already used in other tools. - The UI for
edit_filewill be very specific and different from other tools:- When LLM wants to use
edit_filetool, the REPL will first show the tool call like how it's done forwrite_filetool. - After that, REPL will show the changes being made like a diff in Github pull request. To achieve this, we need to make sure the UI is neat and colored properly to provide a seamless experience to the users.
- For now, we will show the full diff in a card. We will not implement collapse feature.
- The diff also needs to show line numbers on the left from the file.
- Finally, the existing permission card will be rendered if user has not already given session permission for the
edit_filetool. If user gives permission, then only the file will be edited. If user denies, then an error will be returned and passed to LLM. - If session permission is granted for writing, only diff will be shown, and the file will be edited directly.
- When LLM wants to use
- It's important that the UI experience is seamless for the user.
Execution¶
- First, we have got rid of operations.go. So we don't need to have EditOperation anymore in the plan.
- About showing diff, is there anything we can reuse, like a library or so? Manually implementing the diff is complicated.
- We are managing editLines through permissionRequester. Why not treat it as a segment?
- We are still implementing the interface by
REPLPermissionRequester. Can we have a completely decoupled approach? - The types and interface outlined in Step 1 should not be in permission.go. Let's put it in its own file.
- Review the entire plan and make sure diff generation and UI rendering for diff are decoupled from permission mechanism.
- Ok let's implement the plan.
- It seems when permission is already given for edit_file tool in the session, the diff is not shown. Find out why.