#Requires AutoHotkey v2.0 #SingleInstance Force ; Register our callback so it is called every time the clipboard changes. OnClipboardChange(ClipChanged) ClipChanged(DataType) { ; DataType=1 means the clipboard "can be expressed as text". ; If it's not text (like an image), skip. if (DataType != 1) return currentText := A_Clipboard ?? "" ; Regex that matches the 3 lines (with any text/newlines in between). ; "s)" => '.' can match newlines. pattern := "s)Just tell me how to edit the files to make the changes\..*Don't give me back entire files\..*Just show me the edits I need to make\." ; Does the new clipboard content match the 3 lines? if !RegExMatch(currentText, pattern) return ; no match => do nothing ; Prompt for a custom comment (InputBox returns an object with .Value, .Result) response := InputBox('Enter your custom comment:', 'Custom Comment') if (response.Result != 'OK' || response.Value = '') { ; The user canceled or typed nothing MsgBox('User canceled or typed nothing.') return } ; Build the additional instructions as a single-quoted string so we can use double-quotes freely. additionalText := 'Please provide a single fenced code block with the **unified diff** ("diff --git") patch, showing only the necessary edits and a few lines of context.' . '`n**Do not** show the entire file--only the "diff".' . '`n`n**Before the code block**, include a concise explanation of:' . '`n1. The original problem (how it manifested in the code),' . '`n2. How your changes solve it.' . '`n`n**Do not** include any explanation after the code block.' . '`n`nI will pass the patch to the "editor" LLM to apply it.' ; We do NOT re-insert the 3 matched lines. Instead, we replace them ; with a blank line, the user comment, another blank line, then additional text. replacementBlock := response.Value . '`n`n' . additionalText replacedText := RegExReplace(currentText, pattern, replacementBlock) ; Update the clipboard ; (If you want the callbacks to run immediately again, add Sleep 20 after this.) A_Clipboard := replacedText ; MsgBox('Clipboard updated! The three lines have been replaced.') }