Repository: All-Hands-AI/OpenHands

Issue #4506: FE: Display file edit diff in the file viewer
Created: 2024-10-21T21:37:15Z
What problem or use case are you trying to solve?
In #3985, we introduce a FileEditAction:

  
    
      OpenHands/openhands/events/action/files.py
    
    
        Lines 49 to 74
      in
      da548d3
    
  
  
    

        
          
           @dataclass 
        

        
          
           class FileEditAction(Action): 
        

        
          
               """Edits a file by provided a draft at a given path. 
        

        
          
            
        

        
          
               Can be set to edit specific lines using start and end (1-index, inclusive) if the file is too long. 
        

        
          
               Default lines 1:-1 (whole file). 
        

        
          
            
        

        
          
               If start is set to -1, the FileEditAction will simply append the content to the file. 
        

        
          
               """ 
        

        
          
            
        

        
          
               path: str 
        

        
          
               content: str 
        

        
          
               start: int = 1 
        

        
          
               end: int = -1 
        

        
          
               thought: str = '' 
        

        
          
               action: str = ActionType.EDIT 
        

        
          
               runnable: ClassVar[bool] = True 
        

        
          
               security_risk: ActionSecurityRisk | None = None 
        

        
          
            
        

        
          
               def __repr__(self) -> str: 
        

        
          
                   ret = '**FileEditAction**\n' 
        

        
          
                   ret += f'Thought: {self.thought}\n' 
        

        
          
                   ret += f'Range: [L{self.start}:L{self.end}]\n' 
        

        
          
                   ret += f'Path: [{self.path}]\n' 
        

        
          
                   ret += f'Content:\n```\n{self.content}\n```\n' 
        

        
          
                   return ret 
        
    
  


And a FileEditObservation (where obs.content is a git patch):

  
    
      OpenHands/openhands/events/observation/files.py
    
    
        Lines 32 to 41
      in
      da548d3
    
  
  
    

        
          
           @dataclass 
        

        
          
           class FileEditObservation(Observation): 
        

        
          
               """This data class represents a file edit operation""" 
        

        
          
            
        

        
          
               # content: str will be a unified diff patch string include NO context lines 
        

        
          
               path: str 
        

        
          
               prev_exist: bool 
        

        
          
               old_content: str 
        

        
          
               new_content: str 
        

        
          
               observation: str = ObservationType.EDIT 
        
    
  


We should display these properly in the UI.
Describe the UX of the solution you'd like
Ideally, whenever there's a FileEditAction, we automatically pop up the file that's being edited.
When editing is completed, we visualize the edits similar to below:

Do you have thoughts on the technical implementation?
Describe alternatives you've considered
Additional context

Duplicate issue #5716: [Feature Request]: Diff view of work in progress
Created: 2024-12-20T19:22:35Z
What problem or use case are you trying to solve?
In #5508, we introduce a way to display file read/write/edit in the UI:


Describe the UX of the solution you'd like
We want a button near these file view/edit -- when clicked, we jump to the corresponding file in the workspace tab. Ideally, we should show the git diff as well in the file viewer.
Do you have thoughts on the technical implementation?
Describe alternatives you've considered
Additional context

Closing comment (2025-03-25T15:02:31Z): This PR was originally for opening a file on the editor when the agent makes a change to it. We are technically replacing that with the diff view functionality. So since the rename, yes, it is a duplicate of #4506