Skip to content

Feat: Pre-fill derive topics from the scope at point; add learning tests to the TDD menu - #521

Merged
tninja merged 2 commits into
mainfrom
kang_feat_11
Sep 26, 2026
Merged

tninja merged 2 commits into
mainfrom
kang_feat_11

Conversation

@tninja

@tninja tninja commented Sep 26, 2026

Copy link
Copy Markdown
Owner

Two follow-ups to #517 that make topic-based derivation quicker to reach from code.

Pre-fill the topic from the scope at point. Every derive command in ai-code-doc.el starts by asking for a topic, and when you invoke one from a source file the topic you want is usually the function or class you are standing in, so typing it by hand is busywork. The new ai-code--topic-at-point reuses ai-code--current-qualified-scope-name (Tree-sitter first, then which-function) and, in prog-mode buffers, returns something like Service.run (src/Service.java), with the path relative to the Git root (just the scope name when the buffer visits no file). The two topic readers use it differently:

  • Document topics (ai-code--read-document-topic): an empty topic there means "whole repository", so silently pre-filling would change the default. It first asks Scope document to "Service.run (src/Service.java)"? — n keeps the whole-repo document without reading a topic, y pre-fills the topic for editing.
  • Unit test topics (ai-code--read-unit-test-topic): the topic is required anyway, so it is pre-filled directly with no extra question.

Outside prog-mode, or when no scope is found, both prompts behave exactly as before.

Learning tests in C-c a t. ai-code-derive-topic-unit-tests was only reachable from the architecture menu (C-c a A), but test-related actions are naturally looked for in the TDD menu. ai-code-tdd-cycle now ends with 6. Learning tests (Derive unit tests as a tutorial for a topic), which dispatches to the same command; the C-c a A entry stays. In Magit buffers C-c a t keeps its existing hunk-based path, so the option is not offered there.

Verification.

  • New tests, each written first as a failing test: three in test/test_ai-code-doc.el (accepting and declining the scope question, no offer outside prog-mode, unit test topic pre-fill) and one in test/test_ai-code-agile.el (last TDD choice and its dispatch).
  • Full suite: emacs -batch -L . --eval '(setq package-user-dir (expand-file-name "no-such-elpa" temporary-file-directory) native-comp-enable-subr-trampolines nil)' -l ert --eval "(mapc #'load-file (file-expand-wildcards \"test/test_*.el\"))" -f ert-run-tests-batch-and-exit → 1586 tests, 0 unexpected, 13 skipped. Disabling subr trampolines is only a local workaround for native-comp errors when cl-letf stubs completing-read / read-string.
  • Byte-compile and checkdoc on the touched files add no new warnings (the helper uses when-let* to avoid the when-let obsolescence warning in newer Emacs).

Known caveat, left alone on purpose: with behavior auto-presets enabled, ai-code-tdd-cycle maps to the tdd-dev preset, so a learning-test prompt started from C-c a t also picks up +tdd. README.org is not updated for either change yet.

@tninja
tninja merged commit b9843a8 into main Sep 26, 2026
6 checks passed

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5682e93c12

ℹ️ 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".

Comment thread ai-code-doc.el
(when-let* ((scope (ai-code--current-qualified-scope-name)))
(if buffer-file-name
(format "%s (%s)" scope
(file-relative-name buffer-file-name (ai-code--git-root)))

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 Normalize the file before computing the topic path

When a repository is opened through a directory symlink, ai-code--git-root returns the canonical file-truename, while buffer-file-name can retain the symlinked path. Relativizing those two different path namespaces produces a value such as ../../repo-alias/src/Service.java instead of src/Service.java, so accepting the pre-filled topic sends the AI a misleading path outside the reported repository root. Normalize the visited file with buffer-file-truename or file-truename before calling file-relative-name.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant