Diff-Apply Workflow

The diff-apply workflow allows you to review AI-suggested changes before they're applied to your codebase, giving you full control over what gets modified.

How It Works

When the AI suggests code changes, Roflow presents them as a unified diff that you can:

  1. Review - See exactly what will change
  2. Accept - Apply the changes to your code
  3. Reject - Discard the changes
  4. Modify - Edit the suggestions before applying

Viewing Diffs

In Chat Panel

When the AI suggests code changes in the chat:

  1. Changes appear as a diff block with syntax highlighting
  2. Green lines (starting with +) show additions
  3. Red lines (starting with -) show deletions
  4. White lines show unchanged context

Split View

Click "View Diff" to open a side-by-side comparison:

  • Left: Your current code
  • Right: Proposed changes
  • Highlighted: Lines that will change

Applying Changes

Apply Entire Diff

Click the "Apply" button to accept all changes:

✓ Applied changes to src/services/PlayerService.lua

The AI will:

  • Update the specified file(s)
  • Preserve your formatting and indentation
  • Create an undo point

Apply Partial Changes

To apply only some changes:

  1. Click "Select Changes"
  2. Check the boxes next to changes you want
  3. Click "Apply Selected"

Rejecting Changes

Reject Entire Diff

Click "Reject" or press Esc to discard all suggestions.

Why Reject?

Common reasons to reject:

  • The changes don't match your requirements
  • You want to try a different approach
  • The AI misunderstood the context
  • You need to provide more information first

After rejecting, you can:

  • Provide more context in the chat
  • Ask the AI to try a different approach
  • Manually implement the changes yourself

Multi-File Changes

When changes span multiple files:

Changes to apply:
  src/services/PlayerService.lua    +12 -4
  src/controllers/GameController.lua +8 -2
  src/types/Player.lua               +5 -0

You can:

  • Apply All: Accept all file changes
  • Review Each: Go through files one by one
  • Select Files: Choose which files to update

Conflict Resolution

When Conflicts Occur

If you've edited a file since the AI's suggestion:

Options:

  1. Review Diff - Check if changes still make sense
  2. Regenerate - Ask AI for updated suggestions
  3. Apply Anyway - Proceed with original suggestion
  4. Reject - Keep your current code

Manual Resolution

If the diff can't be applied automatically:

  1. AI will show you the conflicting sections
  2. You can manually copy and integrate the changes
  3. Or ask the AI to regenerate considering your edits

Undo Changes

Immediate Undo

After applying changes, use:

  • Keyboard: Cmd+Z / Ctrl+Z
  • Menu: Edit > Undo
  • Command: "Undo AI Changes"

This reverts to before the diff was applied.

History

View all AI-applied changes:

  1. Open Command Palette (Cmd+Shift+P / Ctrl+Shift+P)
  2. Type "AI Change History"
  3. Select changes to review or revert

Best Practices

Before Applying

Do:

  • Read through all changes carefully
  • Ensure you understand what will change
  • Check that it matches your requirements
  • Test after applying (if possible)

Don't:

  • Blindly accept without reviewing
  • Apply changes you don't understand
  • Skip testing after major changes

Working with Large Diffs

For changes affecting many lines:

  1. Use Split View - Easier to review side-by-side
  2. Apply Incrementally - Accept file by file
  3. Test Between Applications - Catch issues early
  4. Use Version Control - Commit before applying large changes

Iterative Refinement

The diff-apply workflow supports iteration:

  1. Apply initial changes
  2. Test/review the results
  3. Ask AI to refine
  4. Review new diff
  5. Apply refinements

Diff Viewer Features

Syntax Highlighting

Diffs maintain syntax highlighting for easier reading:

- local player = game.Players.LocalPlayer
+ local Players = game:GetService("Players")
+ local player = Players.LocalPlayer

Context Lines

By default, shows 3 lines of context above and below changes. Adjust in settings:

{
  "roflow.diff.contextLines": 5
}

Inline vs. Side-by-Side

Switch between views:

  • Inline: Changes shown in one panel
  • Side-by-Side: Split view with before/after

Press Cmd+Shift+D / Ctrl+Shift+D to toggle.

Keyboard Shortcuts

Quick actions while reviewing diffs:

| Action | macOS | Windows/Linux | |--------|-------|---------------| | Apply All | Cmd+Enter | Ctrl+Enter | | Reject | Esc | Esc | | Next Change | F7 | F7 | | Previous Change | Shift+F7 | Shift+F7 | | Toggle View | Cmd+Shift+D | Ctrl+Shift+D |

Common Scenarios

Scenario 1: Accepting a Bug Fix

AI: I've identified and fixed the issue:
  function calculateDamage(power, defense)
-   return power - defense
+   return math.max(0, power - defense)
  end

Action: Review → Apply ✓

Scenario 2: Rejecting Overengineering

AI: I've refactored this into a more modular structure:
[Shows 200+ line diff with new abstractions]

Action: Reject → Ask for simpler approach

Scenario 3: Partial Application

AI: I've added type annotations and fixed the bug:

Action:

  • Accept the bug fix
  • Reject some type annotations (prefer manual addition)

Integration with Git

Pre-Commit Review

Before committing AI changes:

  1. Use git diff to review all modifications
  2. Stage changes selectively with git add -p
  3. Commit with descriptive message mentioning AI assistance

Revert if Needed

If issues arise after deploying:

# Revert specific commit
git revert <commit-hash>

# Reset to before AI changes
git reset --hard HEAD~1

Troubleshooting

Diff Won't Apply

Symptoms: "Unable to apply diff" error

Solutions:

  1. File was modified after suggestion
    • Ask AI to regenerate with current file
  2. File encoding issue
    • Check file uses UTF-8 encoding
  3. Line ending mismatch
    • Configure consistent line endings (LF or CRLF)

Changes Look Wrong

If applied changes don't look right:

  1. Undo immediately (Cmd+Z / Ctrl+Z)
  2. Check if file was saved properly
  3. Ask AI to explain what changed
  4. Regenerate suggestions with more context

Lost Suggestions

Can't find the diff you wanted to apply?

  1. Scroll up in chat history
  2. Use Command Palette: "Show AI Suggestions"
  3. Check "AI Change History" for recent suggestions

Next Steps