Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion ai-code.el
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,26 @@ ARG is the prefix argument."
(string-match-p "\\S-" clipboard-context))
(concat "\n\nClipboard context:\n"
clipboard-context)))))
(ai-code--insert-prompt final-prompt)))))
(ai-code--insert-prompt final-prompt)))))

(defconst ai-code-session-checkpoint-prompt
(concat
"Please stop and output a CHECKPOINT:\n"
"- Goal\n"
"- Files changed\n"
"- Current hypothesis\n"
"- Tests/build result\n"
"- Blockers\n"
"- Recommended next action\n"
"Do not continue editing after this checkpoint")
"Prompt sent by `ai-code-session-checkpoint'.")

;;;###autoload
(defun ai-code-session-checkpoint ()
"Ask the active AI session to summarize its current state and stop editing."
(interactive)
(ai-code-cli-send-command ai-code-session-checkpoint-prompt)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Route checkpoint prompt through session-aware prompt sender

ai-code-session-checkpoint sends directly via ai-code-cli-send-command, which only resolves sessions for the current project context, so this command errors in cases where users have a visible AI session from another directory. Other prompt flows use ai-code--send-prompt (via ai-code--insert-prompt) to detect and target the visible session buffer first, which is exactly the long-idle resume scenario this feature is meant to support. In practice, invoking checkpoint from a buffer without a matching project session can fail with “No … session for this project” instead of checkpointing the active visible session.

Useful? React with 👍 / 👎.

(ai-code-cli-switch-to-buffer))

(defun ai-code--emacs-runtime-debug-prompt (description eval-available-p)
"Return an Emacs runtime debugging prompt from DESCRIPTION.
Expand Down Expand Up @@ -420,6 +439,7 @@ Shows the current backend label to the right."
(transient-define-group ai-code--menu-other-tools
(ai-code--infix-toggle-auto-follow-up)
("." "Init projectile and gtags" ai-code-init-project)
("P" "AI session checkpoint" ai-code-session-checkpoint)
("e" "Debug exception (C-u: clipboard)" ai-code-investigate-exception)
("f" "Fix Flycheck errors in scope" ai-code-flycheck-fix-errors-in-scope)
("k" "Copy Cur File Name (C-u: full)" ai-code-copy-buffer-file-name-to-clipboard)
Expand Down
27 changes: 27 additions & 0 deletions test/test_ai-code.el
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,33 @@
(should (equal (plist-get (cdr suffix) :description)
"Debug Emacs runtime"))))

(ert-deftest ai-code-test-session-checkpoint-sends-fixed-checkpoint-prompt ()
"Test that session checkpoint sends the expected fixed prompt."
(let (sent-command switched)
(cl-letf (((symbol-function 'ai-code-cli-send-command)
(lambda (command)
(setq sent-command command)))
((symbol-function 'ai-code-cli-switch-to-buffer)
(lambda (&rest _args)
(setq switched t))))
(ai-code-session-checkpoint))
(should
(equal sent-command
"Please stop and output a CHECKPOINT:\n- Goal\n- Files changed\n- Current hypothesis\n- Tests/build result\n- Blockers\n- Recommended next action\nDo not continue editing after this checkpoint"))
(should switched)))

(ert-deftest ai-code-test-menu-other-tools-includes-session-checkpoint-entry ()
"Test that the Other Tools menu exposes AI session checkpoint."
(let* ((suffix (transient-get-suffix 'ai-code--menu-other-tools "P"))
(definition (if (keywordp (car-safe (cdr suffix)))
(cdr suffix)
(nth 2 suffix))))
(should suffix)
(should (eq (plist-get definition :command)
'ai-code-session-checkpoint))
(should (equal (plist-get definition :description)
Comment on lines +205 to +210
"AI session checkpoint"))))

(ert-deftest ai-code-test-menu-prefix-command-default-layout ()
"Test that the default menu layout uses the original transient."
(let ((ai-code-menu-layout 'default))
Expand Down