Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds repo-local “backend affinity” so ai-code remembers and reuses the previously used AI backend per Git repository, preventing backend switches in one repo from affecting active sessions in another.
Changes:
- Track
(git-root . backend)mappings and compute an “effective backend” per current repo. - Automatically activate the effective backend on CLI actions (start/resume/switch/send) and remember backend choices per repo.
- Add an ERT test covering cross-repo backend selection behavior.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
ai-code-backends.el |
Implements repo-local backend affinity and uses it when selecting/activating backends. |
ai-code.el |
Updates the transient menu area with a new comment near backend selection. |
test/test_ai-code-backends.el |
Adds an ERT test to ensure backend switches don’t bleed across repos. |
Comments suppressed due to low confidence (2)
test/test_ai-code-backends.el:116
- This test relies on the global
ai-code--repo-backend-alistbeing empty, but it isn't reset/bound here. If any other test (or prior interactive runs) populates it, this test can become order-dependent/flaky. Bindai-code--repo-backend-alistto nil within thelet*(and optionally restore it withunwind-protect) to fully isolate state.
(let* ((ai-code-backends
'((backend-a
:label "Backend A"
:start ai-code-test-backend-a-start
:switch ai-code-test-backend-a-switch
:send ai-code-test-backend-a-send
:resume nil
:cli "a")
(backend-b
:label "Backend B"
:start ai-code-test-backend-b-start
:switch ai-code-test-backend-b-switch
:send ai-code-test-backend-b-send
:resume nil
:cli "b")))
(ai-code-selected-backend 'backend-a)
(ai-code--cli-start-fn #'ignore)
(ai-code--cli-switch-fn #'ignore)
(ai-code--cli-send-fn #'ignore)
(ai-code--cli-resume-fn #'ignore)
(repo-root "/repo-a/")
(start-calls nil))
ai-code.el:414
- The added "DONE:" block comment reads like a PR requirement / scratch note and is extremely long and unstructured for in-code documentation. Please remove it (or replace with a short, polished comment if needed) to avoid permanently embedding PR-specific text into the transient menu definition.
;; DONE: I want ai-code-select-backend (and ai-code--select-backend-description) should keep same backend for the git repo which already started ai-code-cli session, unless user explicitly want to switch in side that git repo. Eg. switch backend in git repo B should not switch backend in git repo A which already has a session, and next time user start session in repo A, it should use the same backend as before. This will be more intelligent and user friendly, and also avoid the problem that user switch backend in one repo but forget to switch back when work on another repo which already has session.
("s" ai-code-select-backend :description ai-code--select-backend-description)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I want ai-code-select-backend (and ai-code--select-backend-description) should keep same backend for the git repo which already started ai-code-cli session, unless user explicitly want to switch in side that git repo. Eg. switch backend in git repo B should not switch backend in git repo A which already has a session, and next time user start session in repo A, it should use the same backend as before. This will be more intelligent and user friendly, and also avoid the problem that user switch backend in one repo but forget to switch back when work on another repo which already has session.