Add Codex CLI agent support to project launcher

This commit is contained in:
Fabio Scotto di Santolo
2026-04-26 19:39:14 +02:00
parent d7415abf1c
commit 5aa3dff38b
4 changed files with 26 additions and 13 deletions

0
.codex Normal file
View File

View File

@@ -105,8 +105,8 @@
(define-key projectile-command-map (kbd "v") #'fscotto/project-multi-vterm) (define-key projectile-command-map (kbd "v") #'fscotto/project-multi-vterm)
(define-key projectile-command-map (kbd "V") nil) (define-key projectile-command-map (kbd "V") nil)
(define-key projectile-command-map (kbd "x") #'fscotto/project-external-terminal) (define-key projectile-command-map (kbd "x") #'fscotto/project-external-terminal)
(define-key projectile-command-map (kbd "a") #'fscotto/project-opencode-dwim) (define-key projectile-command-map (kbd "a") #'fscotto/project-agent-dwim)
(define-key projectile-command-map (kbd "A") #'fscotto/project-opencode-session) (define-key projectile-command-map (kbd "A") #'fscotto/project-agent-session)
(define-key projectile-command-map (kbd "g") #'fscotto/project-magit-status)) (define-key projectile-command-map (kbd "g") #'fscotto/project-magit-status))
;;;; LSP ;;;; LSP

View File

@@ -128,16 +128,19 @@ Each entry is a cons cell of display string and session id."
"Return the latest saved OpenCode session id for the current project." "Return the latest saved OpenCode session id for the current project."
(cdr (car (fscotto/opencode-session-candidates (fscotto/project-root))))) (cdr (car (fscotto/opencode-session-candidates (fscotto/project-root)))))
(defun fscotto/project-opencode-dwim () (defun fscotto/project-agent-dwim ()
"Open the most useful OpenCode session for the current project. "Choose an agent for the current project and launch it externally."
Resume the latest saved session when available, otherwise create a new one."
(interactive) (interactive)
(let ((agent (completing-read "Agent: " '("Codex" "OpenCode") nil t)))
(pcase agent
("OpenCode"
(let ((session-id (fscotto/project-opencode-latest-session-id))) (let ((session-id (fscotto/project-opencode-latest-session-id)))
(if session-id (if session-id
(fscotto/launch-external-terminal (list "opencode" "--session" session-id) (fscotto/launch-external-terminal (list "opencode" "--session" session-id)
(fscotto/project-root)) (fscotto/project-root))
(fscotto/project-opencode)))) (fscotto/project-opencode))))
("Codex"
(fscotto/launch-external-terminal '("codex" "resume" "--last"))))))
(defun fscotto/project-opencode-session () (defun fscotto/project-opencode-session ()
"Resume a saved OpenCode session for the current project." "Resume a saved OpenCode session for the current project."
@@ -151,6 +154,16 @@ Resume the latest saved session when available, otherwise create a new one."
(fscotto/launch-external-terminal (list "opencode" "--session" session-id) (fscotto/launch-external-terminal (list "opencode" "--session" session-id)
project-directory)))) project-directory))))
(defun fscotto/project-agent-session ()
"Choose an agent and resume a saved session for the current project."
(interactive)
(let ((agent (completing-read "Agent session: " '("Codex" "OpenCode") nil t)))
(pcase agent
("OpenCode"
(fscotto/project-opencode-session))
("Codex"
(fscotto/launch-external-terminal '("codex" "resume"))))))
(defun fscotto/project-external-terminal () (defun fscotto/project-external-terminal ()
"Open the external terminal in project root." "Open the external terminal in project root."
(interactive) (interactive)

View File

@@ -145,8 +145,8 @@
"C-c p t" "Test" "C-c p t" "Test"
"C-c p v" "Open multi-vterm in project" "C-c p v" "Open multi-vterm in project"
"C-c p x" "Open external term" "C-c p x" "Open external term"
"C-c p a" "OpenCode (dwim)" "C-c p a" "Choose agent"
"C-c p A" "Choose OpenCode session" "C-c p A" "Choose agent session"
"C-c p e" "Edit project config" "C-c p e" "Edit project config"
"C-c p g" "Project Git status" "C-c p g" "Project Git status"
"C-c p 4" "Other Window" "C-c p 4" "Other Window"