-
Notifications
You must be signed in to change notification settings - Fork 34
Add actionable CLI startup diagnostics #457
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
91ad3e3
ac82dfe
3dab256
00c0d3b
69b8f76
52c1052
bcbe0ca
3f70d2d
eca1a6b
67af2e5
a6a9908
5d27a5d
350fcd4
6a54b9e
ea5cdc6
cedf0a3
fefc2a2
960f9d5
a09492f
d8ef0b3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,7 @@ | |
| (require 'ai-code-editor-viewport) | ||
| (require 'ai-code-session) | ||
| (require 'ai-code-session-link) | ||
| (require 'ai-code-startup-diagnostics) | ||
| ;; Terminal-specific implementations live in dedicated modules so this | ||
| ;; file can stay focused on shared session orchestration. | ||
| (require 'ai-code-backends-infra-vterm) | ||
|
|
@@ -1141,7 +1142,7 @@ were non-nil and append that UUID to the default CLI args." | |
| found-resume-switch | ||
| (ai-code-backends-infra--selected-session-id))) | ||
| (prompt-p (or arg selected-session-id)) | ||
| (default-args (mapconcat #'identity | ||
| (default-args (mapconcat #'shell-quote-argument | ||
| (append switches | ||
| (and selected-session-id | ||
| (list selected-session-id))) | ||
|
|
@@ -1152,8 +1153,11 @@ were non-nil and append that UUID to the default CLI args." | |
| (resolved-args (if prompt-p | ||
| (split-string-shell-command prompt-args) | ||
| switches)) | ||
| (command (mapconcat #'identity | ||
| (cons program resolved-args) | ||
| (resolved-program (if (string-prefix-p "~" program) | ||
| (expand-file-name program) | ||
| program)) | ||
| (command (mapconcat #'shell-quote-argument | ||
| (cons resolved-program resolved-args) | ||
| " "))) | ||
| (list :command command :args resolved-args))) | ||
|
|
||
|
|
@@ -1311,14 +1315,19 @@ behavior." | |
| buffer working-dir prefix task-file) | ||
| (ai-code-backends-infra--display-buffer-in-side-window buffer)) | ||
|
|
||
| (defun ai-code-backends-infra--handle-session-start-failure (buffer session-key process-table) | ||
| "Handle startup failure for BUFFER and SESSION-KEY in PROCESS-TABLE." | ||
| (remhash session-key process-table) | ||
| (if (buffer-live-p buffer) | ||
| (progn | ||
| (pop-to-buffer buffer) | ||
| (message "CLI failed to start - see buffer for error details")) | ||
| (message "CLI failed to start - process exited immediately"))) | ||
| (defun ai-code-backends-infra--handle-session-start-failure | ||
| (buffer session-key process-table prefix command) | ||
| "Handle startup failure for BUFFER and SESSION-KEY in PROCESS-TABLE. | ||
| PREFIX identifies the backend that attempted to start. | ||
| COMMAND is the launch command supplied to the terminal backend." | ||
| (let ((process (gethash session-key process-table)) | ||
| (backend (or prefix | ||
| (when (buffer-live-p buffer) | ||
| (with-current-buffer buffer | ||
| ai-code-backends-infra--session-prefix))))) | ||
| (remhash session-key process-table) | ||
| (ai-code-startup-diagnostics-report | ||
| buffer process backend command))) | ||
|
|
||
| (defun ai-code-backends-infra--start-cli-session (options arg) | ||
| "Start a generic CLI session described by OPTIONS and prefix ARG. | ||
|
|
@@ -1474,36 +1483,60 @@ TASK-FILE and SOURCE-BUFFER preserve file-to-session binding." | |
| (if (file-remote-p working-dir) | ||
| env-vars | ||
| (ai-code-editor-viewport-environment env-vars))) | ||
| (buffer-and-process | ||
| (ai-code-backends-infra--create-terminal-session | ||
| resolved-buffer-name working-dir command editor-environment)) | ||
| (new-buffer (car buffer-and-process)) | ||
| (process (cdr buffer-and-process))) | ||
| (puthash session-key process process-table) | ||
| ;; Wait for initialization before checking process status | ||
| (sleep-for ai-code-backends-infra-terminal-initialization-delay) | ||
| ;; Check if process is still alive after initialization delay | ||
| (if (and process (process-live-p process)) | ||
| (progn | ||
| (ai-code-backends-infra--finalize-started-session | ||
| new-buffer | ||
| process | ||
| working-dir | ||
| resolved-buffer-name | ||
| process-table | ||
| resolved-instance | ||
| prefix | ||
| escape-fn | ||
| cleanup-fn | ||
| multiline-input-sequence | ||
| post-start-fn | ||
| task-file) | ||
| (ai-code-backends-infra--remember-file-session-buffer | ||
| prefix source-buffer new-buffer)) | ||
| (ai-code-backends-infra--handle-session-start-failure | ||
| new-buffer | ||
| session-key | ||
| process-table)))) | ||
| buffer-and-process | ||
| startup-failed) | ||
| (condition-case err | ||
| (setq buffer-and-process | ||
| (ai-code-backends-infra--create-terminal-session | ||
| resolved-buffer-name working-dir command editor-environment)) | ||
| (error | ||
| (unwind-protect | ||
| (let ((failure-buffer (get-buffer resolved-buffer-name))) | ||
| (if failure-buffer | ||
| (progn | ||
| (ai-code-backends-infra--handle-session-start-failure | ||
|
Comment on lines
+1495
to
+1497
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When Ghostel is installed but lacks Useful? React with 👍 / 👎. |
||
| failure-buffer | ||
| session-key | ||
| process-table | ||
| prefix | ||
| command) | ||
| (setq startup-failed t)) | ||
| (signal (car err) (cdr err)))) | ||
| (when cleanup-fn | ||
| (funcall cleanup-fn))))) | ||
| (unless startup-failed | ||
| (let ((new-buffer (car buffer-and-process)) | ||
| (process (cdr buffer-and-process))) | ||
| (puthash session-key process process-table) | ||
| ;; Wait for initialization before checking process status | ||
| (sleep-for ai-code-backends-infra-terminal-initialization-delay) | ||
| ;; Check if process is still alive after initialization delay | ||
| (if (and process (process-live-p process)) | ||
| (progn | ||
| (ai-code-backends-infra--finalize-started-session | ||
| new-buffer | ||
| process | ||
| working-dir | ||
| resolved-buffer-name | ||
| process-table | ||
| resolved-instance | ||
| prefix | ||
| escape-fn | ||
| cleanup-fn | ||
| multiline-input-sequence | ||
| post-start-fn | ||
| task-file) | ||
| (ai-code-backends-infra--remember-file-session-buffer | ||
| prefix source-buffer new-buffer)) | ||
| (unwind-protect | ||
| (ai-code-backends-infra--handle-session-start-failure | ||
| new-buffer | ||
| session-key | ||
| process-table | ||
| prefix | ||
| command) | ||
| (when cleanup-fn | ||
| (funcall cleanup-fn)))))))) | ||
|
|
||
| (defun ai-code-backends-infra--toggle-or-create-session (working-dir buffer-name process-table command | ||
| &optional escape-fn cleanup-fn | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a backend program is configured as
~/bin/codexand a prefix invocation selects a remote working directory, this expands~beforeai-code-backends-infra--session-working-directoryhas chosen that directory. The resulting command therefore contains a path resolved for the source buffer—often a local home path or a different TRAMP host—which is then executed in the selected remote session and fails unless both homes happen to match. Defer expansion until the working directory is known or leave remote shell expansion intact.Useful? React with 👍 / 👎.