- 
                Notifications
    
You must be signed in to change notification settings  - Fork 3.7k
 
feat: multi edit and single search and replace tools #7267
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Merged
      
      
    
  
     Merged
                    Changes from 1 commit
      Commits
    
    
            Show all changes
          
          
            16 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      d6ed405
              
                feat: multi edit and single search and replace tools
              
              
                RomneyDa efa6328
              
                feat: UIs and add single replace to default tools
              
              
                RomneyDa 54c16a3
              
                fix: tests and prettier
              
              
                RomneyDa 9b0b581
              
                fix: prettier issues
              
              
                RomneyDa be0c0d5
              
                merge: main
              
              
                RomneyDa 832b2d6
              
                fix: handle apply error for multi/single edit tools
              
              
                RomneyDa 393c06f
              
                feat: unify edit tool apply handling
              
              
                RomneyDa 3b6a290
              
                fix: address bot feedback
              
              
                RomneyDa 4f18953
              
                fix: find and replace utils
              
              
                RomneyDa c3ad86f
              
                fix: gui tests for edit tools
              
              
                RomneyDa 469c0c8
              
                feat: UI for diff tools
              
              
                RomneyDa 07c3930
              
                test: find and replace ui tests
              
              
                RomneyDa 0208969
              
                chore: cleanup console logs
              
              
                RomneyDa 56b7195
              
                fix: cubic feedback
              
              
                RomneyDa ff931ec
              
                Merge pull request #7367 from continuedev/dallin/diff-UI
              
              
                tomasz-stefaniak fc93a2e
              
                fix: make search and replace edit copy less confusing
              
              
                RomneyDa File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
| import { Tool } from "../.."; | ||
| import { BUILT_IN_GROUP_NAME, BuiltInToolNames } from "../builtIn"; | ||
| 
     | 
||
| export interface EditOperation { | ||
| old_string: string; | ||
| new_string: string; | ||
| replace_all?: boolean; | ||
| } | ||
| 
     | 
||
| export interface MultiEditArgs { | ||
| filepath: string; | ||
| edits: EditOperation[]; | ||
| } | ||
| 
     | 
||
| export const multiEditTool: Tool = { | ||
| type: "function", | ||
| displayTitle: "Multi Edit", | ||
| wouldLikeTo: "edit {{{ filepath }}}", | ||
| isCurrently: "editing {{{ filepath }}}", | ||
| hasAlready: "edited {{{ filepath }}}", | ||
| group: BUILT_IN_GROUP_NAME, | ||
| readonly: false, | ||
| isInstant: false, | ||
| function: { | ||
| name: BuiltInToolNames.MultiEdit, | ||
| description: `This is a tool for making multiple edits to a single file in one operation. It | ||
| is built on top of the single find and replace tool and allows you to perform multiple | ||
| find-and-replace operations efficiently. Prefer this tool over the single find and replace tool | ||
| when you need to make multiple edits to the same file. | ||
| Before using this tool: | ||
| 1. Use the read_file tool to understand the file's contents and context | ||
| 2. Verify the directory path is correct | ||
| To make multiple file edits, provide the following: | ||
| 1. filepath: The path to the file to modify (relative to the root of the workspace) | ||
| 2. edits: An array of edit operations to perform, where each edit contains: | ||
| - old_string: The text to replace (must match the file contents exactly, including all whitespace and indentation) | ||
| - new_string: The edited text to replace the old_string | ||
| - replace_all: Replace all occurrences of old_string. This parameter is optional and defaults to false. | ||
| IMPORTANT: | ||
| - All edits are applied in sequence, in the order they are provided | ||
| - Each edit operates on the result of the previous edit | ||
| - All edits must be valid for the operation to succeed - if any edit fails, | ||
| none will be applied | ||
                
      
                  RomneyDa marked this conversation as resolved.
               
          
            Show resolved
            Hide resolved
         | 
||
| - This tool is ideal when you need to make several changes to different parts | ||
| of the same file | ||
| CRITICAL REQUIREMENTS: | ||
| 1. All edits follow the same requirements as the single find and replace tool | ||
| 2. The edits are atomic - either all succeed or none are applied | ||
| 3. Plan your edits carefully to avoid conflicts between sequential operations | ||
| WARNING: | ||
| - The tool will fail if edits.old_string doesn't match the file contents | ||
| exactly (including whitespace) | ||
| - The tool will fail if edits.old_string and edits.new_string are the same | ||
| - Since edits are applied in sequence, ensure that earlier edits don't affect | ||
                
      
                  RomneyDa marked this conversation as resolved.
               
          
            Show resolved
            Hide resolved
         | 
||
| the text that later edits are trying to find | ||
| When making edits: | ||
| - Ensure all edits result in idiomatic, correct code | ||
| - Do not leave the code in a broken state | ||
| - Only use emojis if the user explicitly requests it. Avoid adding emojis to | ||
| files unless asked. | ||
| - Use replace_all for replacing and renaming strings across the file. This | ||
| parameter is useful if you want to rename a variable for instance. | ||
| If you want to create a new file, use: | ||
| - A new file path | ||
| - First edit: empty old_string and the new file's contents as new_string | ||
                
      
                  RomneyDa marked this conversation as resolved.
               
          
            Show resolved
            Hide resolved
         | 
||
| - Subsequent edits: normal edit operations on the created content`, | ||
| parameters: { | ||
| type: "object", | ||
| required: ["filepath", "edits"], | ||
| properties: { | ||
| filepath: { | ||
| type: "string", | ||
| description: | ||
| "The path to the file to modify, relative to the root of the workspace", | ||
| }, | ||
| edits: { | ||
| type: "array", | ||
| description: | ||
| "Array of edit operations to perform sequentially on the file", | ||
| items: { | ||
| type: "object", | ||
| required: ["old_string", "new_string"], | ||
| properties: { | ||
| old_string: { | ||
| type: "string", | ||
| description: "The text to replace", | ||
| }, | ||
| new_string: { | ||
| type: "string", | ||
| description: "The text to replace it with", | ||
| }, | ||
| replace_all: { | ||
| type: "boolean", | ||
| description: | ||
| "Replace all occurrences of old_string (default false)", | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| systemMessageDescription: { | ||
| prefix: `To make multiple edits to a single file, use the ${BuiltInToolNames.MultiEdit} tool with a filepath (relative to the root of the workspace) and an array of edit operations. | ||
| For example, you could respond with:`, | ||
| exampleArgs: [ | ||
| ["filepath", "path/to/file.ts"], | ||
| [ | ||
| "edits", | ||
| `[ | ||
| { "old_string": "const oldVar = 'value'", "new_string": "const newVar = 'updated'" }, | ||
| { "old_string": "oldFunction()", "new_string": "newFunction()", "replace_all": true } | ||
| ]`, | ||
| ], | ||
| ], | ||
| }, | ||
| defaultToolPolicy: "allowedWithPermission", | ||
| }; | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| import { Tool } from "../.."; | ||
| import { BUILT_IN_GROUP_NAME, BuiltInToolNames } from "../builtIn"; | ||
| 
     | 
||
| export interface SingleFindAndReplaceArgs { | ||
| filepath: string; | ||
| old_string: string; | ||
| new_string: string; | ||
| replace_all?: boolean; | ||
| } | ||
| 
     | 
||
| export const singleFindAndReplaceTool: Tool = { | ||
| type: "function", | ||
| displayTitle: "Find and Replace", | ||
| wouldLikeTo: "find and replace in {{{ filepath }}}", | ||
| isCurrently: "finding and replacing in {{{ filepath }}}", | ||
| hasAlready: "found and replaced in {{{ filepath }}}", | ||
| group: BUILT_IN_GROUP_NAME, | ||
| readonly: false, | ||
| isInstant: false, | ||
| function: { | ||
| name: BuiltInToolNames.SingleFindAndReplace, | ||
| description: `Performs exact string replacements in files. | ||
| Usage: | ||
| - You must use your \`read_file\` tool at least once in the conversation before | ||
| editing. This tool will error if you attempt an edit without reading the file. | ||
                
      
                  RomneyDa marked this conversation as resolved.
               
          
            Show resolved
            Hide resolved
         | 
||
| - When editing text from read_file tool output, ensure you preserve the exact | ||
| indentation (tabs/spaces) as it appears AFTER the line number prefix. The line | ||
| number prefix format is: spaces + line number + tab. Everything after that tab | ||
| is the actual file content to match. Never include any part of the line number | ||
| prefix in the old_string or new_string. | ||
| - ALWAYS prefer editing existing files in the codebase. NEVER write new files | ||
| unless explicitly required. | ||
| - Only use emojis if the user explicitly requests it. Avoid adding emojis to | ||
                
      
                  RomneyDa marked this conversation as resolved.
               
          
            Show resolved
            Hide resolved
         | 
||
| files unless asked. | ||
| - The edit will FAIL if \`old_string\` is not unique in the file. Either provide | ||
| a larger string with more surrounding context to make it unique or use | ||
| \`replace_all\` to change every instance of \`old_string\`. | ||
| - Use \`replace_all\` for replacing and renaming strings across the file. This | ||
| parameter is useful if you want to rename a variable for instance.`, | ||
| parameters: { | ||
| type: "object", | ||
| required: ["filepath", "old_string", "new_string"], | ||
| properties: { | ||
| filepath: { | ||
| type: "string", | ||
| description: | ||
| "The path to the file to modify, relative to the root of the workspace", | ||
| }, | ||
| old_string: { | ||
| type: "string", | ||
| description: "The text to replace", | ||
| }, | ||
| new_string: { | ||
| type: "string", | ||
| description: | ||
| "The text to replace it with (must be different from old_string)", | ||
| }, | ||
| replace_all: { | ||
| type: "boolean", | ||
| description: "Replace all occurrences of old_string (default false)", | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| systemMessageDescription: { | ||
| prefix: `To perform exact string replacements in files, use the ${BuiltInToolNames.SingleFindAndReplace} tool with a filepath (relative to the root of the workspace) and the strings to find and replace. | ||
| For example, you could respond with:`, | ||
| exampleArgs: [ | ||
| ["filepath", "path/to/file.ts"], | ||
| ["old_string", "const oldVariable = 'value'"], | ||
| ["new_string", "const newVariable = 'updated'"], | ||
| ["replace_all", "false"], | ||
| ], | ||
| }, | ||
| defaultToolPolicy: "allowedWithPermission", | ||
| }; | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
      
      Oops, something went wrong.
        
    
  
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.