Skip to content

Diff view#370

Open
Niduank wants to merge 18 commits intomainfrom
132-experimental-add-diff-view
Open

Diff view#370
Niduank wants to merge 18 commits intomainfrom
132-experimental-add-diff-view

Conversation

@Niduank
Copy link
Collaborator

@Niduank Niduank commented Jul 31, 2025

No description provided.

Niduank added 17 commits July 31, 2025 12:30
# Conflicts:
#	macos/Onit/Data/Fetching/Endpoints/ChatStreaming/OpenAIChatStreamingEndpoint.swift
#	macos/Onit/Data/Tools/CalendarTool.swift
#	macos/Onit/Data/Tools/DiffTool.swift
#	macos/Onit/Data/Tools/ToolRouter.swift
#	macos/Onit/UI/Panels/State/OnitPanelState+Chat.swift
* Revert DiffTool to avoid conflicts
* Prevent double tool execution when stream is finished
* Remove unnecessary isComplete variable in ToolCallResult
# Conflicts:
#	macos/Onit/UI/Prompt/Generated/GeneratedContentView.swift
* WIP: UI - Display DiffTool call
* WIP: UI - NotepadView looks like design
* DiffTool compute a character sequence diff instead of character diff
* Store in database the approved/changed diff operation
* Pass the content's mimeType to the LLM

# Conflicts:
#	macos/Onit/Data/Tools/DiffTool.swift
* Add replace operation in DiffTool
* Re-work the indexes offset
* Add support for tables (containing text)
* Add support for non-text elements
* Display loader & alert if error occurs on document update
* Insert enabled only when some change are approved
* Make sure invisible characters are not replaced by LLM.
* Create a valid JSON of toolArguments while streaming
* DiffTool: Fix rebase issue + crash when one argument is empty
* Display automatically the DiffView after DiffTool succeeded
* UI - Handle streaming correctly
* UI - Close the diff view when panel is closed.
* API - User message structured
* DiffTool - Add app name in arguments (used for text insertion).
* Performance
- Throttle of 300ms
- Don't execute tool if arguments didn't change
- Don't re-draw the view during streaming
* Move reused code around DiffSegment in DiffSegmentUtils
* Supporting DiffRevision (variant)
* UI - Show diff button in GeneratedToolbar
* UI - Show revision toggle in diff view
* UI - Show generated text in Chat
* Sometimes DiffTool is not called - improve its description
* Close the DiffView when "Switch to Chat" is clicked
* UI Improvement - NotepadWindow is now resizable
* UI Improvement - NotepadWindow is sticky to onitPanel (listen resize and move)
* UI DiffView - Display alerts on insertion errors
* UI QuickEdit - Display DiffTool
* UI QuickEdit - Display DiffButton in generated toolbar
* Clean - Move the diff preview generation in Response's model and reuse it everywhere
* Feature Copy & Insert - As Prompt.generation is now returning the response diff preview or text -> The copy and insert feature will works with diff preview.
* Feature Tethered - Handle correctly app minimized, app moved
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Greptile Summary

This PR implements a comprehensive diff view feature that allows users to review and selectively apply text changes generated by AI tools. The implementation includes:

Core Architecture:

  • New DiffTool that generates structured text operations (insert, delete, replace) using an optimized LCS-based diff algorithm
  • DiffViewModel for managing diff state with SwiftData persistence through DiffRevision and DiffChangeState models
  • DiffView component providing an interactive interface with approve/reject controls, keyboard shortcuts, and preview functionality
  • NotepadWindowController as a singleton floating panel manager for displaying diff content

Google Docs Integration:

  • New service layer with GoogleDocumentServiceProtocol, GoogleDocumentManager, and specialized services (GoogleDocsService, GoogleSheetsService, GoogleSlidesService)
  • Complex text reconstruction logic to map between plain text positions and Google Docs API indices
  • GoogleDocsParser for converting JSON responses into structured Swift models
  • Comprehensive data structures mirroring Google API schemas for Docs, Sheets, and Slides operations

UI Integration:

  • ToolCallHandlerView routing system that displays DiffToolView for diff operations
  • Diff buttons in toolbars (GeneratedToolbar, QuickEditResponseView) that open the notepad window
  • Panel state management updates with isDiffViewActive tracking and panelFrameDidChange delegate notifications
  • New color assets for diff visualization (diffBgGreen, diffBgRed, AcceptBG, etc.)

Tool Call Enhancements:

  • Enhanced tool execution with duplicate prevention using hash-based tracking
  • JSON validation and repair in StreamToolAccumulator for handling partial streaming data
  • Automatic diff window opening when diff tools complete execution

The feature integrates seamlessly with the existing chat interface, accessibility parsing system, and panel management architecture while maintaining separation of concerns through proper MVVM patterns.

Confidence score: 2/5

• This PR introduces significant complexity with several concerning implementation issues that could cause crashes or data corruption in production.
• Critical issues include unsafe string manipulation in DiffSegmentUtils, potential index bounds errors in StreamToolAccumulator, system color usage violations in DiffTextView, and complex offset calculations in GoogleDocsService that may fail.
• Files requiring immediate attention: DiffSegmentUtils.swift, StreamToolAccumulator.swift, DiffTextView.swift, GoogleDocsService.swift, DiffViewModel.swift, and ChatEndpointMessagesBuilder.swift.

Context used:

Rule - Use optional chaining syntax action?() instead of explicit nil checking with if-let statements for optional closures. (link)

58 files reviewed, 44 comments

Edit Code Review Bot Settings | Greptile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant