Skip to content

Commit 2368cbc

Browse files
tninjaCopilot
andauthored
Chore: Allow non-git files in repo context candidates (#313)
* Allow non-git files in repo context candidates * fix review feedback for add-context repo root selection Agent-Logs-Url: https://github.com/tninja/ai-code-interface.el/sessions/b13eebd1-acc6-49e4-b542-e671bb7b0563 Co-authored-by: tninja <714625+tninja@users.noreply.github.com> * style: align indentation in add-context updates and test Agent-Logs-Url: https://github.com/tninja/ai-code-interface.el/sessions/b13eebd1-acc6-49e4-b542-e671bb7b0563 Co-authored-by: tninja <714625+tninja@users.noreply.github.com> * docs: update HISTORY for non-git context candidates Agent-Logs-Url: https://github.com/tninja/ai-code-interface.el/sessions/c4c90fbb-a847-42a1-85b1-c5b889ac3ed8 Co-authored-by: tninja <714625+tninja@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: tninja <714625+tninja@users.noreply.github.com>
1 parent 68ccbe6 commit 2368cbc

3 files changed

Lines changed: 48 additions & 4 deletions

File tree

HISTORY.org

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
- Fix: Enable ghostel full-redraw mode for Claude Code and Copilot CLI sessions
77
- Refactor: Use Ghostel public API for sending input
88
- Chore: Notify on response and beep before D-Bus
9+
- Chore: Allow adding non-git files and directories to existing repo context candidates
910

1011
** 1.72
1112
- Chore: Add action intent prompt to TODO implementation flow

ai-code-file.el

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,9 @@ Otherwise, ask AI to generate a build command."
473473

474474
;;;###autoload
475475
(defun ai-code-add-context ()
476-
"Capture current buffer context and store it per Git repository.
476+
"Capture current buffer context and store it per selected repository root.
477+
If current buffer is not inside a Git repository, select from known repository
478+
roots gathered from existing context entries and visible/session buffers.
477479
When no region is selected, use the full file path and current function
478480
\(if any). When a region is active, use the file path with line range
479481
in the form filepath#Lstart-Lend."
@@ -495,9 +497,18 @@ in the form filepath#Lstart-Lend."
495497
(when (and root (not (member root roots)))
496498
(push root roots)))))))
497499
(nreverse roots)))
498-
(ordered-roots (if (and current-root (member current-root all-roots))
499-
(cons current-root (remove current-root all-roots))
500-
all-roots))
500+
(existing-roots (let ((roots '()))
501+
(maphash (lambda (root _contexts)
502+
(when (and (stringp root)
503+
(not (member root roots)))
504+
(push root roots)))
505+
ai-code--repo-context-info)
506+
(sort roots #'string<)))
507+
(candidate-roots (sort (delete-dups (append existing-roots all-roots))
508+
#'string<))
509+
(ordered-roots (if (and current-root (member current-root candidate-roots))
510+
(cons current-root (remove current-root candidate-roots))
511+
candidate-roots))
501512
(repo-root (cond
502513
((null ordered-roots)
503514
(user-error "Not inside a Git repository"))

test/test_ai-code-file.el

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,38 @@ everything is cleaned up afterward."
675675
(ai-code-context-action '(4))
676676
(should completing-read-called))))
677677

678+
(ert-deftest ai-code-test-add-context-allows-non-git-file-for-existing-repo-context ()
679+
"Test `ai-code-add-context' can add a non-git file to an existing repo context."
680+
(let ((ai-code--repo-context-info (make-hash-table :test #'equal))
681+
(repo-root "/tmp/existing-repo/")
682+
(new-file (make-temp-file "ai-code-context-"))
683+
(completing-read-called nil))
684+
(unwind-protect
685+
(with-temp-buffer
686+
(setq buffer-file-name new-file)
687+
(puthash repo-root
688+
'("/tmp/existing-repo/lib/existing-context.el")
689+
ai-code--repo-context-info)
690+
(cl-letf (((symbol-function 'ai-code--git-root)
691+
(lambda (&optional _dir) nil))
692+
((symbol-function 'walk-windows)
693+
(lambda (&rest _args) nil))
694+
((symbol-function 'completing-read)
695+
(lambda (&rest _args)
696+
(setq completing-read-called t)
697+
repo-root))
698+
((symbol-function 'derived-mode-p)
699+
(lambda (&rest _args) nil))
700+
((symbol-function 'message)
701+
(lambda (&rest _args) nil)))
702+
(ai-code-add-context)
703+
(should-not completing-read-called)
704+
(should (equal (gethash repo-root ai-code--repo-context-info)
705+
(list new-file
706+
"/tmp/existing-repo/lib/existing-context.el")))))
707+
(when (file-exists-p new-file)
708+
(delete-file new-file)))))
709+
678710
(ert-deftest ai-code-test-build-or-test-project-dispatches-test-project ()
679711
"Test selecting \"Test project\" dispatches to `ai-code-test-project'."
680712
(let ((test-project-called nil)

0 commit comments

Comments
 (0)