Skip to content

Commit 633c65c

Browse files
authored
Feat: Add discussion follow-up suggestions (#283)
* Add discussion follow-up suggestions * Record follow-up suffix and broaden follow-ups * Remove legacy discussion auto follow up toggle * Revert "Remove legacy discussion auto follow up toggle" This reverts commit a4d133a. * Update doc * update approval for codex
1 parent 7f3f558 commit 633c65c

File tree

5 files changed

+295
-37
lines changed

5 files changed

+295
-37
lines changed

HISTORY.org

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

44
** Main branch change
5+
- Feat: Add optional numbered next-step suggestions for discussion prompts via `ai-code-discussion-auto-follow-up-enabled`
6+
- Reuse GPTel prompt classification when available, add a transient toggle on `C-c a F`, and record the follow-up suffix in prompt history
57

68
** 1.68
79
- UX: TDD Harness loop externalize the long prompt

README.org

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ Enable installation of packages from MELPA by adding an entry to package-archive
106106
;; (ai-code-prompt-filepath-completion-mode -1)
107107
;; Optional: Ask AI to run test after code changes, for a tighter build-test loop
108108
(setq ai-code-auto-test-type 'ask-me)
109+
;; Optional: Offer numbered next steps for discussion prompts at send time
110+
;; Customize `ai-code-discussion-auto-follow-up-enabled` to non-nil
111+
;; or set it directly like this:
112+
;; (setq ai-code-discussion-auto-follow-up-enabled t)
109113
;; Optional: In AI session buffers, SPC in Evil normal state triggers the prompt-enter UI
110114
(with-eval-after-load 'evil (ai-code-backends-infra-evil-setup))
111115
;; Optional: Turn on auto-revert buffer, so that the AI code change automatically appears in the buffer
@@ -132,7 +136,7 @@ Enable installation of packages from MELPA by adding an entry to package-archive
132136
- ai-code-task-use-gptel-filename: When non-nil, file name created by `ai-code-create-or-open-task-file` or `ai-code-create-file-or-dir` will have auto-generated filenames created by GPTel
133137
- ai-code-notes-use-gptel-headline: When non-nil, notes created by `ai-code-take-notes` will have auto-generated headlines created by GPTel
134138
- ai-code-use-gptel-headline: When non-nil, prompts sent to the AI will have auto-generated headlines created by GPTel, providing better organization and readability in the prompt file
135-
- ai-code-use-gptel-classify-prompt: When no nil, and `ai-code-auto-test-type` is not nil, classify whether the current prompt is about code changes and need to trigger following test
139+
- ai-code-use-gptel-classify-prompt: When non-nil, and `ai-code-auto-test-type` or `ai-code-discussion-auto-follow-up-enabled` is non-nil, classify whether the current prompt is about code changes so test prompts or discussion follow-up suggestions are only added when relevant
136140
- `flycheck`: To enable the `ai-code-flycheck-fix-errors-in-scope` command.
137141
- `yasnippet`: For snippet support in the prompt file. A library of snippets is included.
138142
- (emacs built-in) abbrev + skeleton is also a good way to expand prompt. [[./etc/prompt_expand_with_abbrev_skeleton.el][example abbrev to solve / iterate leetcode problem with tdd (need to set ai-code-auto-test-type with tdd)]], [[./examples/leetcode][example problem resolved]]
@@ -161,6 +165,7 @@ Enable installation of packages from MELPA by adding an entry to package-archive
161165
- *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.
162166
- Relevant packages for TODO: [[https://github.com/tarsius/hl-todo][hl-todo]], [[https://github.com/alphapapa/magit-todos][magit-todos]]
163167
- *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.
168+
- *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.
164169
- *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.
165170
- *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.
166171
- *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.
@@ -293,11 +298,14 @@ To expose your own Emacs function as a tool, use =ai-code-mcp-make-tool=.
293298

294299
*** Harness Engineering Practice
295300

296-
Harness engineering is about building a reliable loop around the model, so the AI does not stop at /make a change/ but continues into /verify the change and react to the result/. In this package, the clearest example is the auto test loop.
301+
Harness engineering is about building a reliable loop around the model, so the AI does not stop at /make a change/ but continues into /verify the change and react to the result/. In this package, the clearest examples are the auto test loop for code changes and the optional next-step loop for discussion prompts.
297302

298-
Instead of manually telling the AI what to do after every edit, you can make test follow-up part of the workflow:
303+
Instead of manually telling the AI what to do after every code change or discussion turn, you can make follow-up part of the workflow:
299304

300305
- `ai-code-auto-test-type`: choose how code-change prompts should continue after the edit. You can ask the AI to run tests after the change, use TDD Red+Green, use Red+Green+Blue with refactoring, turn it off, or decide case by case with `ask-me`.
306+
- `ai-code-discussion-auto-follow-up-enabled`: when non-nil, discussion-style prompts can offer a send-time choice to append 2-3 numbered candidate next steps. You can customize this variable directly or toggle it from the transient menu with `C-c a F`.
307+
- `ai-code-next-step-suggestion-suffix`: customize the exact instruction appended for those numbered next-step suggestions.
308+
- `ai-code-use-gptel-classify-prompt`: when paired with the settings above, GPTel can classify prompts so code-change prompts skip discussion follow-up suggestions and discussion prompts skip test follow-up.
301309
- `ai-code-tdd-cycle`: run a guided TDD flow from the menu, including separate Red, Green, Blue stages or the combined one-prompt flows.
302310
- `ai-code-build-or-test-project`: run build/test explicitly from `C-c a b` when you want a direct verification step in the middle of the loop.
303311
- `ai-code-prompt-suffix`: add persistent project rules when needed, so repeated instructions such as response language, coding constraints, or test expectations do not have to be retyped in every prompt.
@@ -321,7 +329,7 @@ The benefit is practical:
321329
- more consistent AI behavior because verification is part of the workflow
322330
- easier to let the AI continue with the next step after a failed or passing test
323331

324-
This is why features such as `ai-code-auto-test-type` and `ai-code-tdd-cycle` fit the idea of harness engineering: they turn testing and follow-up into part of the system, not an afterthought in each prompt.
332+
This is why features such as `ai-code-auto-test-type`, `ai-code-discussion-auto-follow-up-enabled`, and `ai-code-tdd-cycle` fit the idea of harness engineering: they turn testing and follow-up into part of the system, not an afterthought in each prompt.
325333

326334
Nit: During using auto test feature, I prefer to turn off the approval request from AI, it will make the whole process more smooth. Eg. for Codex CLI, it is
327335

@@ -459,7 +467,7 @@ When working with multiple AI sessions, it can be useful to receive desktop noti
459467

460468
- A: Enable auto-approval for your active AI coding CLI. For example, in Codex CLI, you can enable the following flag.
461469
#+begin_src elisp
462-
(setq ai-code-codex-cli-program-switches '("--full-auto"))
470+
(setq ai-code-codex-cli-program-switches '("-a" "never"))
463471
#+end_src
464472

465473
** AI Assisted Programming related books

ai-code-prompt-mode.el

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
(defvar ai-code-prompt-suffix)
1818
(defvar ai-code-auto-test-type)
1919
(defvar ai-code-auto-test-suffix)
20+
(defvar ai-code-discussion-auto-follow-up-enabled)
21+
(defvar ai-code-discussion-auto-follow-up-suffix)
2022
(defvar ai-code-use-prompt-suffix)
2123

2224
(declare-function yas-load-directory "yasnippet" (dir))
@@ -162,15 +164,15 @@ Only works when gptel package is installed, otherwise shows error message."
162164
(insert (format ":AGENT: %s\n" label))
163165
(insert ":END:\n")))
164166

165-
(defun ai-code--append-prompt-to-buffer (prompt-text)
166-
"Append formatted PROMPT-TEXT to the end of the current buffer.
167-
This includes generating a headline and formatting the prompt.
168-
Returns the full prompt text with suffix for sending to AI."
167+
(defun ai-code--append-prompt-to-buffer (stored-prompt-text)
168+
"Append formatted STORED-PROMPT-TEXT to the end of the current buffer.
169+
This includes generating a headline and formatting the prompt text
170+
that should be recorded in the prompt history file."
169171
(goto-char (point-max))
170172
(insert "\n\n")
171-
(ai-code--generate-prompt-headline prompt-text)
173+
(ai-code--generate-prompt-headline stored-prompt-text)
172174
(ai-code--insert-backend-label-drawer)
173-
(ai-code--format-and-insert-prompt prompt-text))
175+
(ai-code--format-and-insert-prompt stored-prompt-text))
174176

175177
(defun ai-code--send-prompt (full-prompt)
176178
"Send FULL-PROMPT to AI."
@@ -181,9 +183,15 @@ Returns the full prompt text with suffix for sending to AI."
181183
"Write PROMPT-TEXT to the AI prompt file."
182184
(let* ((suffix-parts (delq nil (list ai-code-prompt-suffix
183185
(when ai-code-auto-test-type
184-
ai-code-auto-test-suffix))))
186+
ai-code-auto-test-suffix)
187+
(when ai-code-discussion-auto-follow-up-enabled
188+
ai-code-discussion-auto-follow-up-suffix))))
185189
(suffix (when (and ai-code-use-prompt-suffix suffix-parts)
186190
(mapconcat #'identity suffix-parts "\n")))
191+
;; Keep the recorded prompt aligned with the exact suffixes sent to AI.
192+
(stored-prompt (if suffix
193+
(concat prompt-text "\n" suffix)
194+
prompt-text))
187195
(full-prompt (concat (if suffix
188196
(concat prompt-text "\n" suffix)
189197
prompt-text) "\n"))
@@ -192,7 +200,7 @@ Returns the full prompt text with suffix for sending to AI."
192200
(if prompt-file
193201
(let ((buffer (ai-code--get-prompt-buffer prompt-file)))
194202
(with-current-buffer buffer
195-
(ai-code--append-prompt-to-buffer prompt-text)
203+
(ai-code--append-prompt-to-buffer stored-prompt)
196204
(save-buffer)
197205
(message "Prompt added to %s" prompt-file))
198206
(let ((default-directory original-default-directory))
@@ -458,8 +466,8 @@ It trims leading/trailing whitespace."
458466
(message "No text in the current block to send."))))
459467

460468
(defun ai-code--mark-prompt-block ()
461-
"Mark a code block. A code block is defined as multiple lines without empty lines inside,
462-
but with empty lines before and after the block."
469+
"Mark the current prompt block.
470+
A prompt block is multiple non-empty lines surrounded by empty lines."
463471
(interactive)
464472
(let ((start (point))
465473
(end (point)))

0 commit comments

Comments
 (0)