branch: elpa/aidermacs
commit 5b812f26e5a7b28db679620b57cef5ebf5920d19
Author: Mingde (Matthew) Zeng <matthew...@posteo.net>
Commit: Mingde (Matthew) Zeng <matthew...@posteo.net>

    Check udiff cases
---
 aidermacs-backends.el | 25 +++++++++++++++++++++++--
 aidermacs.el          | 24 ++++++++++++++++++++++--
 2 files changed, 45 insertions(+), 4 deletions(-)

diff --git a/aidermacs-backends.el b/aidermacs-backends.el
index 4a4879e1fb..d401343172 100644
--- a/aidermacs-backends.el
+++ b/aidermacs-backends.el
@@ -108,7 +108,9 @@ Remove any files that don't exist."
   "Parse OUTPUT for files and add them to `aidermacs--tracked-files'."
   (when output
     (let ((lines (split-string output "\n"))
-          (last-line ""))
+          (last-line "")
+          (in-udiff nil)
+          (current-udiff-file nil))
       (dolist (line lines)
         (cond
          ;; Applied edit to <filename>
@@ -153,7 +155,26 @@ Remove any files that don't exist."
          ;; <file> is already in the chat as an editable file
          ((string-match "\\(\\./\\)?\\(.+\\) is already in the chat as an 
editable file" line)
           (when-let ((file (match-string 2 line)))
-            (add-to-list 'aidermacs--tracked-files file))))
+            (add-to-list 'aidermacs--tracked-files file)))
+ 
+         ;; Handle udiff format
+         ;; Detect start of udiff with "--- filename"
+         ((string-match "^--- \\(\\./\\)?\\(.+\\)" line)
+          (setq in-udiff t
+                current-udiff-file (match-string 2 line)))
+
+         ;; Confirm udiff file with "+++ filename" line
+         ((and in-udiff
+               current-udiff-file
+               (string-match "^\\+\\+\\+ \\(\\./\\)?\\(.+\\)" line))
+          (let ((plus-file (match-string 2 line)))
+            ;; Only add if the filenames match (ignoring ./ prefix)
+            (when (string= (file-name-nondirectory current-udiff-file)
+                           (file-name-nondirectory plus-file))
+              (add-to-list 'aidermacs--tracked-files current-udiff-file)
+              (setq in-udiff nil
+                    current-udiff-file nil)))))
+
         (setq last-line line))
 
       ;; Verify all tracked files exist
diff --git a/aidermacs.el b/aidermacs.el
index 9c3936c12d..5b292468ad 100644
--- a/aidermacs.el
+++ b/aidermacs.el
@@ -388,7 +388,9 @@ Returns a list of files that have been modified according 
to the output."
         (output aidermacs--current-output))
     (when output
       (let ((lines (split-string output "\n"))
-            (last-line ""))
+            (last-line "")
+            (in-udiff nil)
+            (current-udiff-file nil))
         (dolist (line lines)
           (cond
            ;; Case 1: Look for "Applied edit to <filename>" pattern
@@ -400,7 +402,25 @@ Returns a list of files that have been modified according 
to the output."
            ((string-match "^```" line)
             (let ((potential-file (string-trim last-line)))
               (when (not (string-empty-p potential-file))
-                (push potential-file edited-files)))))
+                (push potential-file edited-files))))
+
+           ;; Case 3: Handle udiff format
+           ;; Detect start of udiff with "--- filename"
+           ((string-match "^--- \\(\\./\\)?\\(.+\\)" line)
+            (setq in-udiff t
+                  current-udiff-file (match-string 2 line)))
+
+           ;; Confirm udiff file with "+++ filename" line
+           ((and in-udiff
+                 current-udiff-file
+                 (string-match "^\\+\\+\\+ \\(\\./\\)?\\(.+\\)" line))
+            (let ((plus-file (match-string 2 line)))
+              ;; Only add if the filenames match (ignoring ./ prefix)
+              (when (string= (file-name-nondirectory current-udiff-file)
+                             (file-name-nondirectory plus-file))
+                (push current-udiff-file edited-files)
+                (setq in-udiff nil
+                      current-udiff-file nil)))))
 
           (setq last-line line))))
 

Reply via email to