Skip to content

Prompt for working directory on prefixed AI CLI start/resume#416

Draft
tninja with Copilot wants to merge 5 commits into
mainfrom
copilot/tninja-address-current-directory-issue
Draft

Prompt for working directory on prefixed AI CLI start/resume#416
tninja with Copilot wants to merge 5 commits into
mainfrom
copilot/tninja-address-current-directory-issue

Conversation

Copilot AI commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Starting or resuming an AI CLI session could inherit default-directory from an unrelated Emacs context, including $HOME. This change makes prefixed start/resume flows ask for the working directory explicitly while preserving the existing args prompt.

  • Behavior change

    • C-u on start/resume now keeps the current CLI-args prompt and then prompts for a working directory.
    • The directory prompt is prefilled from the existing project-aware default, so users can accept it or override it.
  • Shared startup flow

    • Moved working-directory resolution in the shared backend infra to occur after CLI arg resolution.
    • Applied the behavior centrally so generic CLI backends inherit it without per-backend special handling.
  • Resume/session selection

    • Resume picker now prefers the last accessed matching session buffer, so a custom working directory selected during resume continues targeting the intended session.
  • Docs and coverage

    • Updated affected start/resume docstrings to describe the new C-u behavior.
    • Added focused tests for prompt ordering, directory prompting, and resume-buffer selection.
;; Before:
;; C-u C-c a a  => prompt for CLI args only

;; After:
;; C-u C-c a a
;;   1. prompt for CLI args
;;   2. prompt for working directory (prefilled with current default)

Copilot AI changed the title [WIP] Fix starting directory for agent to match active buffer Prompt for working directory on prefixed AI CLI start/resume Jul 2, 2026
Copilot AI requested a review from tninja July 2, 2026 18:32
Copilot finished work on behalf of tninja July 2, 2026 18:32
@tninja tninja requested a review from Copilot July 3, 2026 14:05

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR improves native CLI backend session startup/resume reliability by ensuring prefixed start/resume flows explicitly prompt for a working directory (avoiding accidental inheritance of unrelated default-directory), while preserving existing CLI-args prompting behavior.

Changes:

  • Updates shared backend infra startup flow so CLI args are resolved first, then (when prefixed) the working directory is prompted with a project-aware default.
  • Enhances resume picker behavior to prefer the last accessed matching session buffer for a backend.
  • Updates docstrings and adds ERT coverage for prompt ordering, directory prompting, and resume-buffer selection.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
ai-code-backends-infra.el Adds optional working-directory prompting and reorders startup resolution; prefers last accessed session buffer in resume picker.
ai-code-backends.el Updates user-facing start/resume docstrings about prefix behavior and adds a compile-time var declaration.
ai-code-opencode.el Updates resume docstring to reflect new prefix behavior.
ai-code-kilo.el Updates resume docstring to reflect new prefix behavior.
test/test_ai-code-backends-infra.el Adds/updates tests for directory prompting, prompt ordering, and resume picker buffer preference.

Comment on lines +191 to +194
((symbol-function 'read-directory-name)
(lambda (prompt &optional dir default-filename mustmatch initial)
(setq seen (list prompt dir default-filename mustmatch initial))
"/custom/")))
Comment thread ai-code-backends.el
Comment on lines 118 to +121
"Start the current backend's CLI session when supported.
Argument ARG is passed to the backend's start function."
Argument ARG is passed to the backend's start function.
Interactively, a prefix argument keeps the existing CLI-args prompt and
also prompts for the working directory before the session starts."
Copilot finished work on behalf of tninja July 3, 2026 14:09
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.

C-a a starting point is in current directory of active buffer

3 participants