Skip to content

Commit 6291f36

Browse files
tninjaCopilot
andauthored
Chore: tweak auto follow up suggestion feature (#329)
* Enable discussion auto follow-up by default * Use y-or-n-p for follow-up choice and update tests * Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * update HISTORY * bump version * fix test --------- Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
1 parent 47133e9 commit 6291f36

4 files changed

Lines changed: 59 additions & 34 deletions

File tree

HISTORY.org

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
* Release history
33

44
** Main branch change
5+
6+
** 1.78
7+
- Chore: tweak auto follow up suggestion feature
8+
- Turn it on by default. This is just about to let user to choose use it or not (in 2).
9+
- Let user use y/n to use it in each non code change question.
510
- Chore: Improve ai-code-implement-todo inside org-mode file
611
- Fix: Make org TODO headline section work well with ai-code-implement-todo + helm
712
- Chore: ai-code-code-change and ai-code-ask-question can trigger ai-code-implement-todo when the cursor is on a TODO comment or TODO org headline

README.org

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,9 @@ Enable installation of packages from MELPA by adding an entry to package-archive
9898
;; (ai-code-prompt-filepath-completion-mode -1)
9999
;; Optional: Ask AI to run test after code changes, for a tighter build-test loop
100100
(setq ai-code-auto-test-type 'ask-me)
101-
;; Optional: Offer numbered next steps for discussion prompts at send time
102-
;; Customize `ai-code-discussion-auto-follow-up-enabled` to non-nil
103-
;; or set it directly like this:
104-
;; (setq ai-code-discussion-auto-follow-up-enabled t)
101+
;; Optional: Disable numbered next steps for discussion prompts at send time
102+
;; (enabled by default)
103+
;; (setq ai-code-discussion-auto-follow-up-enabled nil)
105104
;; Optional: In AI session buffers, SPC in Evil normal state triggers the prompt-enter UI
106105
(with-eval-after-load 'evil (ai-code-backends-infra-evil-setup))
107106
;; Optional: Turn on auto-revert buffer, so that the AI code change automatically appears in the buffer
@@ -163,7 +162,7 @@ Enable installation of packages from MELPA by adding an entry to package-archive
163162
- *Implementing a TODO*: Write a comment in your code, like `;; TODO: Implement caching for this function`. Place your cursor on that line and press `C-c a`, then `i` (`ai-code-implement-todo`). The AI will generate the implementation based on the comment.
164163
- Relevant packages for TODO: [[https://github.com/tarsius/hl-todo][hl-todo]], [[https://github.com/alphapapa/magit-todos][magit-todos]]
165164
- *Asking a Question*: Place your cursor within a function, press `C-c a`, then `q` (`ai-code-ask-question`), type your question, and press Enter. The question, along with context, will be sent to the AI.
166-
- *Discussion follow-up suggestions*: Customize `ai-code-discussion-auto-follow-up-enabled` to non-nil, or set `(setq ai-code-discussion-auto-follow-up-enabled t)`. Then ask a question with `C-c a q` or use `C-c a <SPC>` for a design discussion. When enabled, AI Code asks at send time whether to append 2-3 numbered next-step suggestions, and the transient toggle on `C-c a F` lets you turn the feature on or off from the menu.
165+
- *Discussion follow-up suggestions*: `ai-code-discussion-auto-follow-up-enabled` is enabled by default. Set `(setq ai-code-discussion-auto-follow-up-enabled nil)` to turn it off. Then ask a question with `C-c a q` or use `C-c a <SPC>` for a design discussion. When enabled, AI Code asks at send time whether to append 2-3 numbered next-step suggestions, and the transient toggle on `C-c a F` lets you turn the feature on or off from the menu.
167166
- *Refactoring a Function*: With the cursor in a function, press `C-c a`, then `r` (`ai-code-refactor-book-method`). Select a refactoring technique from the list, provide any required input (e.g., a new method name), and the prompt will be generated.
168167
- *Automatically run tests after change*: When ai-code-auto-test-type is non-nil, AI will automatically run tests after code changes and follow up on results.
169168
- *One-prompt TDD with refactoring*: Press `C-c a`, then `t` (`ai-code-tdd-cycle`) and choose `5. Red + Green + Blue (One prompt)` to generate tests, implement code, run tests, and then refactor the changed code in one flow.

ai-code.el

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
;;; ai-code.el --- Unified interface for AI coding backends such as Codex CLI, Copilot CLI, Claude Code, Gemini CLI, Opencode, Kilo, Grok CLI, etc -*- lexical-binding: t; -*-
22

33
;; Author: Kang Tu <tninja@gmail.com>
4-
;; Version: 1.77
4+
;; Version: 1.78
55
;; Package-Requires: ((emacs "29.1") (transient "0.9.0") (magit "2.1.0"))
66
;; URL: https://github.com/tninja/ai-code-interface.el
77

@@ -59,8 +59,8 @@
5959
;; ;; (ai-code-prompt-filepath-completion-mode -1)
6060
;; ;; Optional: Configure AI test prompting mode (e.g., ask about running tests/TDD) for a tighter build-test loop
6161
;; (setq ai-code-auto-test-type 'ask-me)
62-
;; ;; Optional: Offer numbered next steps for discussion prompts at send time
63-
;; ;; (setq ai-code-discussion-auto-follow-up-enabled t)
62+
;; ;; Optional: Disable numbered next steps for discussion prompts at send time
63+
;; ;; (setq ai-code-discussion-auto-follow-up-enabled nil)
6464
;; ;; Optional: In the AI session buffer (Evil normal state), SPC triggers the prompt entry UI
6565
;; (with-eval-after-load 'evil (ai-code-backends-infra-evil-setup))
6666
;; (global-auto-revert-mode 1)
@@ -176,7 +176,7 @@ See the later `defcustom' for user-facing documentation and default.")
176176
(defvar ai-code-discussion-auto-follow-up-suffix nil
177177
"Send-time prompt suffix that requests numbered next-step suggestions.")
178178

179-
(defvar ai-code-discussion-auto-follow-up-enabled nil
179+
(defvar ai-code-discussion-auto-follow-up-enabled t
180180
"Forward declaration for `ai-code-discussion-auto-follow-up-enabled'.
181181
See the later `defcustom' for user-facing documentation and default.")
182182

@@ -192,11 +192,6 @@ See the later `defcustom' for user-facing documentation and default.")
192192
("Off" . nil))
193193
"Persistent choices for `ai-code-auto-test-type`.")
194194

195-
(defconst ai-code--auto-follow-up-type-ask-choices
196-
'(("Suggest next steps" . t)
197-
("No next-step suggestions" . nil))
198-
"Resolve next-step suggestion choices for `ask-me` mode.")
199-
200195
(defconst ai-code--auto-test-type-legacy-persistent-modes
201196
'(test-after-change tdd tdd-with-refactoring)
202197
"Legacy persistent values still honored for backward compatibility.")
@@ -214,13 +209,7 @@ See the later `defcustom' for user-facing documentation and default.")
214209

215210
(defun ai-code--read-auto-follow-up-choice ()
216211
"Read whether to request numbered next-step suggestions for this send action."
217-
(let* ((choice (completing-read "Discussion follow-up suggestions: "
218-
(mapcar #'car ai-code--auto-follow-up-type-ask-choices)
219-
nil t nil nil
220-
(caar ai-code--auto-follow-up-type-ask-choices)))
221-
(choice-cell (assoc choice ai-code--auto-follow-up-type-ask-choices)))
222-
(and choice-cell
223-
(cdr choice-cell))))
212+
(y-or-n-p "Discussion follow-up suggestions? "))
224213

225214
;;;###autoload
226215
(defcustom ai-code-use-gptel-classify-prompt nil
@@ -409,11 +398,12 @@ Send-time routing uses this result for test and discussion follow-up suffixes."
409398
:set #'ai-code--test-after-code-change--set
410399
:group 'ai-code)
411400

412-
(defcustom ai-code-discussion-auto-follow-up-enabled nil
401+
(defcustom ai-code-discussion-auto-follow-up-enabled t
413402
"When non-nil, prompts may request numbered next-step suggestions.
414-
Customize this to non-nil to turn on the send-time choice globally.
415-
Pair it with `ai-code-use-gptel-classify-prompt` when you want
416-
code-change prompts to skip these discussion follow-up suggestions."
403+
This is enabled by default; customize it to nil to turn the send-time
404+
choice off globally. Pair it with `ai-code-use-gptel-classify-prompt`
405+
when you want code-change prompts to skip these discussion follow-up
406+
suggestions."
417407
:type 'boolean
418408
:set (lambda (symbol value)
419409
(set-default symbol value)

test/test_ai-code.el

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,21 @@
203203
(lambda (&rest _args) "TDD Red + Green + Blue (refactor after Green)")))
204204
(should (eq 'tdd-with-refactoring (ai-code--read-auto-test-type-choice))))))
205205

206+
(ert-deftest ai-code-test-read-auto-follow-up-choice-uses-y-or-n-p ()
207+
"Test that follow-up choice reads a y/n decision."
208+
(let ((asked-prompt nil))
209+
(cl-letf (((symbol-function 'y-or-n-p)
210+
(lambda (prompt)
211+
(setq asked-prompt prompt)
212+
t))
213+
((symbol-function 'completing-read)
214+
(lambda (&rest _args)
215+
(ert-fail "Should not use completing-read for follow-up y/n choice."))))
216+
(should (eq t (ai-code--read-auto-follow-up-choice)))
217+
(should (string-match-p
218+
"\\`Discussion follow-up suggestions\\(?: (y/n)\\)?\\? \\'"
219+
asked-prompt)))))
220+
206221
(ert-deftest ai-code-test-resolve-auto-follow-up-suffix-for-send-off ()
207222
"Test that off mode never resolves a discussion follow-up suffix."
208223
(let ((ai-code-discussion-auto-follow-up-enabled nil)
@@ -217,15 +232,26 @@
217232
(cl-letf (((symbol-function 'ai-code--gptel-classify-prompt-code-change)
218233
(lambda (_prompt-text) 'non-code-change))
219234
((symbol-function 'ai-code--read-auto-follow-up-choice)
220-
(lambda () t)))
235+
(lambda (&rest _args) t)))
221236
(should (string-match-p
222237
"3-4 numbered candidate next[[:space:]\n]+steps"
223238
(ai-code--resolve-auto-follow-up-suffix-for-send
224239
"Explain this function")))
225240
(should (string-match-p
226241
"At least 2 candidates must[[:space:]\n]+be AI-actionable items"
227-
(ai-code--resolve-auto-follow-up-suffix-for-send
228-
"Explain this function"))))))
242+
(ai-code--resolve-auto-follow-up-suffix-for-send
243+
"Explain this function"))))))
244+
245+
(ert-deftest ai-code-test-resolve-auto-follow-up-suffix-calls-choice-reader-without-args ()
246+
"Test that follow-up choice reader is called without extra arguments."
247+
(let ((ai-code-discussion-auto-follow-up-enabled t)
248+
(ai-code-next-step-suggestion-suffix "FOLLOW-UP")
249+
(ai-code-use-gptel-classify-prompt nil))
250+
(cl-letf (((symbol-function 'ai-code--read-auto-follow-up-choice)
251+
(lambda () t)))
252+
(should (equal "FOLLOW-UP"
253+
(ai-code--resolve-auto-follow-up-suffix-for-send
254+
"Explain this function"))))))
229255

230256
(ert-deftest ai-code-test-resolve-auto-follow-up-suffix-for-send-ask-me-code-change-skips ()
231257
"Test that ask-me mode does not offer next-step suggestions for code-change prompts."
@@ -236,7 +262,7 @@
236262
(cl-letf (((symbol-function 'ai-code--gptel-classify-prompt-code-change)
237263
(lambda (_prompt-text) 'code-change))
238264
((symbol-function 'ai-code--read-auto-follow-up-choice)
239-
(lambda ()
265+
(lambda (&rest _args)
240266
(setq asked t)
241267
t)))
242268
(should-not
@@ -253,7 +279,7 @@
253279
(lambda (_prompt-text)
254280
(ert-fail "Should not call GPTel for code-change prompt markers.")))
255281
((symbol-function 'ai-code--read-auto-follow-up-choice)
256-
(lambda ()
282+
(lambda (&rest _args)
257283
(setq asked t)
258284
t)))
259285
(should-not
@@ -268,7 +294,7 @@
268294
(cl-letf (((symbol-function 'ai-code--gptel-classify-prompt-code-change)
269295
(lambda (_prompt-text) 'non-code-change))
270296
((symbol-function 'ai-code--read-auto-follow-up-choice)
271-
(lambda () t)))
297+
(lambda (&rest _args) t)))
272298
(let ((this-command 'ai-code-ask-question))
273299
(should (string-match-p
274300
"The user may also[[:space:]\n]+ignore these options"
@@ -291,7 +317,7 @@
291317
(cl-letf (((symbol-function 'ai-code--gptel-classify-prompt-code-change)
292318
(lambda (_prompt-text) 'non-code-change))
293319
((symbol-function 'ai-code--read-auto-follow-up-choice)
294-
(lambda () t))
320+
(lambda (&rest _args) t))
295321
((symbol-function 'ai-code--get-ai-code-prompt-file-path)
296322
(lambda () nil))
297323
((symbol-function 'ai-code-cli-send-command)
@@ -322,7 +348,7 @@
322348
(cl-letf (((symbol-function 'ai-code--gptel-classify-prompt-code-change)
323349
(lambda (_prompt-text) 'non-code-change))
324350
((symbol-function 'ai-code--read-auto-follow-up-choice)
325-
(lambda () t))
351+
(lambda (&rest _args) t))
326352
((symbol-function 'ai-code--get-ai-code-prompt-file-path)
327353
(lambda () prompt-file))
328354
((symbol-function 'ai-code-cli-send-command)
@@ -352,7 +378,7 @@
352378
(cl-letf (((symbol-function 'ai-code--gptel-classify-prompt-code-change)
353379
(lambda (_prompt-text) 'non-code-change))
354380
((symbol-function 'ai-code--read-auto-follow-up-choice)
355-
(lambda () t))
381+
(lambda (&rest _args) t))
356382
((symbol-function 'ai-code--get-ai-code-prompt-file-path)
357383
(lambda () nil))
358384
((symbol-function 'ai-code-cli-send-command)
@@ -495,6 +521,10 @@
495521
'boolean
496522
(get 'ai-code-discussion-auto-follow-up-enabled 'custom-type))))
497523

524+
(ert-deftest ai-code-test-discussion-auto-follow-up-enabled-default-is-on ()
525+
"Test that discussion auto follow-up defaults to enabled."
526+
(should (eq t (default-value 'ai-code-discussion-auto-follow-up-enabled))))
527+
498528
(ert-deftest ai-code-test-resolve-auto-test-suffix-for-send-ask-me-tdd-with-refactoring ()
499529
"Test that ask-me resolves to the repo-local TDD harness reference."
500530
(let* ((temp-root (make-temp-file "ai-code-harness-root-" t))
@@ -528,6 +558,7 @@
528558
"Test that ask-me no-test choice appends explicit no-test instruction."
529559
(let ((sent-command nil)
530560
(ai-code-auto-test-type 'ask-me)
561+
(ai-code-discussion-auto-follow-up-enabled nil)
531562
(ai-code-use-prompt-suffix t)
532563
(ai-code-prompt-suffix "BASE SUFFIX")
533564
(ai-code-auto-test-suffix "SHOULD NOT APPEAR"))

0 commit comments

Comments
 (0)