| title | Interactive diffs | |
|---|---|---|
| description | Design for reviewing and accepting agent-proposed file changes in the TUI. | |
| product | drover-code | |
| audience | platform-operator | |
| doc_type | how-to | |
| topics |
|
|
| surface | repo-docs |
The Interactive Diffs feature allows users to review and selectively apply agent-proposed file edits at a hunk-by-hunk level before they are written to disk. This functionality mirrors industry best practices for safe, auditable autonomous coding agents and integrates deeply with Drover Code's TUI.
- Responsibility: Parses unified diffs generated by the
fs.PreviewEditfunction. - Implementation: Processes standard patch format headers (
@@ -start,length +start,length @@) and correctly parses contextual lines, deletions (-), and additions (+). - Data Model: Extracted
Hunks containOldStart,OldLines,RawLines, and independentAcceptedandRejectedtoggles.
- Responsibility: Displays the interactive diff review prompt.
- Keybindings:
j/korUp/Downarrow keys to navigate hunks.Spaceortto toggle hunk selection (Accept/Reject).Ato accept all,Rto reject all,Cto clear selections.Enterto confirm and apply the selected hunks.qorEscto cancel the interactive diff session.
- Integration: The
diffModelintercepts key events inside the main TUI loop whenm.showingDiff == true, deferring regular TUI logic until the user commits to a decision.
- Responsibility: Safely mutates the file on disk by strictly applying the
Acceptedhunks. - Safety Mechanism: Reverses hunk application (from bottom to top) to ensure line-numbering mutations do not offset prior hunks. Context lines are verified and selectively managed without relying on an external unified diff utility that could overwrite or squash the user's intent.
- Atomicity: Follows
toolutil.WriteAtomicprinciples by writing to a temporary file before renaming it to the final destination, avoiding partial file corruption if an interrupt occurs.
- Responsibility: Bypasses tool execution when the interactive diff has manually applied the changes.
- Workflow:
- The LLM invokes
edit_file. - The TUI detects the permission request for
edit_file, intercepts the request, and previews the file usingfs.PreviewEdit(). - The
DiffModelis presented. - Upon
Enter, the TUI writes to disk and returns the newtools.AppliedManuallydecision. - The execution engine recognizes
tools.AppliedManuallyand directly injects a successToolResultBlockinto the prompt buffer, skipping the actualedit_fileexecution.
- The LLM invokes
- Unit Testing: Verified via
internal/tui/diff/diff_test.go, which specifically tests the parser for accurate line counts and the Patch Applier for executing simulated diff patches on isolated files. - Fuzz/End-To-End Testing: The main test harnesses ensure the compilation integrity of the new interactive UI integrations across all terminal architectures without crashing.
This module strictly acts within the established layer-6 Governance policies. Agents still cannot bypass file execution without TUI rendering. In automated (headless) workflows, tools.AppliedManually is skipped entirely, forcing adherence to standard policy engine rules.