Guest User

Untitled

a guest
Dec 22nd, 2024
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Autohotkey 2.30 KB | Source Code | 0 0
  1. #Requires AutoHotkey v2.0
  2. #SingleInstance Force
  3.  
  4. ; Register our callback so it is called every time the clipboard changes.
  5. OnClipboardChange(ClipChanged)
  6.  
  7. ClipChanged(DataType)
  8. {
  9.     ; DataType=1 means the clipboard "can be expressed as text".
  10.     ; If it's not text (like an image), skip.
  11.     if (DataType != 1)
  12.         return
  13.    
  14.     currentText := A_Clipboard ?? ""
  15.  
  16.     ; Regex that matches the 3 lines (with any text/newlines in between).
  17.     ; "s)" => '.' can match newlines.
  18.     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\."
  19.  
  20.     ; Does the new clipboard content match the 3 lines?
  21.     if !RegExMatch(currentText, pattern)
  22.         return  ; no match => do nothing
  23.  
  24.     ; Prompt for a custom comment (InputBox returns an object with .Value, .Result)
  25.     response := InputBox('Enter your custom comment:', 'Custom Comment')
  26.     if (response.Result != 'OK' || response.Value = '')
  27.     {
  28.         ; The user canceled or typed nothing
  29.         MsgBox('User canceled or typed nothing.')
  30.         return
  31.     }
  32.  
  33.     ; Build the additional instructions as a single-quoted string so we can use double-quotes freely.
  34.     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.'
  35.         . '`n**Do not** show the entire file--only the "diff".'
  36.         . '`n`n**Before the code block**, include a concise explanation of:'
  37.         . '`n1. The original problem (how it manifested in the code),'
  38.         . '`n2. How your changes solve it.'
  39.         . '`n`n**Do not** include any explanation after the code block.'
  40.         . '`n`nI will pass the patch to the "editor" LLM to apply it.'
  41.  
  42.     ; We do NOT re-insert the 3 matched lines. Instead, we replace them
  43.     ; with a blank line, the user comment, another blank line, then additional text.
  44.     replacementBlock := response.Value . '`n`n' . additionalText
  45.  
  46.     replacedText := RegExReplace(currentText, pattern, replacementBlock)
  47.  
  48.     ; Update the clipboard
  49.     ; (If you want the callbacks to run immediately again, add Sleep 20 after this.)
  50.     A_Clipboard := replacedText
  51.  
  52.     ; MsgBox('Clipboard updated! The three lines have been replaced.')
  53. }
  54.  
Tags: ahk
Advertisement
Add Comment
Please, Sign In to add comment