feat: use selected Magit hunks for agent explain, change, and test actions - #508
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 27b9b5a6f8
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| emacs -Q --batch -L . \ | ||
| --eval "(progn (require 'package) (package-initialize))" \ | ||
| --eval "(progn (require 'bytecomp) (let ((byte-compile-error-on-warn t)) (unless (byte-compile-file \"ai-code-magit.el\") (kill-emacs 1))))" \ | ||
| --eval "(dolist (file '(\"ai-code-change.el\" \"ai-code-discussion.el\" \"ai-code-agile.el\" \"ai-code-file.el\" \"ai-code-prompt-mode.el\")) (unless (byte-compile-file file) (kill-emacs 1)))" \ |
There was a problem hiding this comment.
Enforce warning failures for every modified Lisp file
When any of these five modified modules emits a byte-compilation warning, byte-compile-file can still return an output filename and this CI command succeeds because byte-compile-error-on-warn is bound only in the preceding --eval for ai-code-magit.el. Bind it while compiling this entire touched-file list so newly introduced warnings cannot pass CI.
AGENTS.md reference: AGENTS.md:L12-L16
Useful? React with 👍 / 👎.
| (lambda (&rest _) "0123456789abcdef"))) | ||
| ,@body)))) | ||
|
|
||
| (ert-deftest ai-code-magit-context-current-hunk () |
There was a problem hiding this comment.
Rename the Magit tests to the required test pattern
This and the other new ERT tests use names beginning with ai-code-magit-, whereas the repository requires test names in the test-module--function-name-scenario form. Rename the new test symbols consistently so test discovery and filtering follow the established convention.
AGENTS.md reference: AGENTS.md:L172-L175
Useful? React with 👍 / 👎.
Magit hunks currently fall through to file-oriented actions or scope menus, so users cannot hand a selected patch directly to their coding agent. This PR makes the existing commands use the displayed hunk as their scope.
C-c a xC-c a qC-c a cC-c a tC-c a @A shared extractor captures the current hunk, sibling hunk selections, or a complete enclosing hunk with a focused excerpt. It preserves paths, diff direction/range, revision identity, HEAD and capture time. Context is captured before minibuffer interaction, and patch text stays literal during prompt filepath preprocessing, including when reused from stored context.
Edit and test requests ask the agent to re-read current files, preserve unrelated changes, and avoid staging or committing. The test action leaves production code alone and reports verification commands/results without claiming a test-first cycle for existing code. Tests run in the agent. Historical diffs allow read-only actions and context capture; write actions reject them. Invalid selections and non-text/combined hunks produce actionable errors. Existing file and Dired behavior is retained.
Validation uses GitHub Actions because this workspace has no Emacs executable:
The repository-wide melpazoid job already fails at the unchanged base commit: baseline run. Its package-lint errors concern
anyinai-code-session-link.eland the declared Emacs/compat dependency. This PR does not modify that file.README documentation includes the key mapping, selection rules, snapshot semantics, and test boundaries.