From 5aa3dff38b329035be37ecdc412f3be644372341 Mon Sep 17 00:00:00 2001 From: Fabio Scotto di Santolo Date: Sun, 26 Apr 2026 19:39:14 +0200 Subject: [PATCH] Add Codex CLI agent support to project launcher --- .codex | 0 .../desktop/.emacs.d/lisp/core/keybindings.el | 4 +-- .../.emacs.d/lisp/misc/custom-functions.el | 31 +++++++++++++------ .../desktop/.emacs.d/lisp/misc/which-key.el | 4 +-- 4 files changed, 26 insertions(+), 13 deletions(-) create mode 100644 .codex diff --git a/.codex b/.codex new file mode 100644 index 0000000..e69de29 diff --git a/dotfiles/desktop/.emacs.d/lisp/core/keybindings.el b/dotfiles/desktop/.emacs.d/lisp/core/keybindings.el index 26641a9..da0df80 100644 --- a/dotfiles/desktop/.emacs.d/lisp/core/keybindings.el +++ b/dotfiles/desktop/.emacs.d/lisp/core/keybindings.el @@ -105,8 +105,8 @@ (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 "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-opencode-session) + (define-key projectile-command-map (kbd "a") #'fscotto/project-agent-dwim) + (define-key projectile-command-map (kbd "A") #'fscotto/project-agent-session) (define-key projectile-command-map (kbd "g") #'fscotto/project-magit-status)) ;;;; LSP diff --git a/dotfiles/desktop/.emacs.d/lisp/misc/custom-functions.el b/dotfiles/desktop/.emacs.d/lisp/misc/custom-functions.el index b8cc697..3b4be57 100644 --- a/dotfiles/desktop/.emacs.d/lisp/misc/custom-functions.el +++ b/dotfiles/desktop/.emacs.d/lisp/misc/custom-functions.el @@ -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." (cdr (car (fscotto/opencode-session-candidates (fscotto/project-root))))) -(defun fscotto/project-opencode-dwim () - "Open the most useful OpenCode session for the current project. - -Resume the latest saved session when available, otherwise create a new one." +(defun fscotto/project-agent-dwim () + "Choose an agent for the current project and launch it externally." (interactive) - (let ((session-id (fscotto/project-opencode-latest-session-id))) - (if session-id - (fscotto/launch-external-terminal (list "opencode" "--session" session-id) - (fscotto/project-root)) - (fscotto/project-opencode)))) + (let ((agent (completing-read "Agent: " '("Codex" "OpenCode") nil t))) + (pcase agent + ("OpenCode" + (let ((session-id (fscotto/project-opencode-latest-session-id))) + (if session-id + (fscotto/launch-external-terminal (list "opencode" "--session" session-id) + (fscotto/project-root)) + (fscotto/project-opencode)))) + ("Codex" + (fscotto/launch-external-terminal '("codex" "resume" "--last")))))) (defun fscotto/project-opencode-session () "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) 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 () "Open the external terminal in project root." (interactive) diff --git a/dotfiles/desktop/.emacs.d/lisp/misc/which-key.el b/dotfiles/desktop/.emacs.d/lisp/misc/which-key.el index 77d5af1..44854c5 100644 --- a/dotfiles/desktop/.emacs.d/lisp/misc/which-key.el +++ b/dotfiles/desktop/.emacs.d/lisp/misc/which-key.el @@ -145,8 +145,8 @@ "C-c p t" "Test" "C-c p v" "Open multi-vterm in project" "C-c p x" "Open external term" - "C-c p a" "OpenCode (dwim)" - "C-c p A" "Choose OpenCode session" + "C-c p a" "Choose agent" + "C-c p A" "Choose agent session" "C-c p e" "Edit project config" "C-c p g" "Project Git status" "C-c p 4" "Other Window"