1313
1414(defvar ai-code-cli )
1515
16+ (defun ai-code--unsupported-resume (&optional _arg )
17+ (interactive " P" )
18+ (user-error " Backend '%s' does not support resume" (ai-code-current-backend-label)))
19+
20+ ;;;### autoload
21+ (defun ai-code-cli-resume (&optional arg )
22+ " Resume the current backend's CLI session when supported."
23+ (interactive " P" )
24+ (ai-code--unsupported-resume arg))
25+
1626;;;### autoload
1727(defcustom ai-code-backends
1828 '((claude-code
2131 :start claude-code
2232 :switch claude-code-switch-to-buffer
2333 :send claude-code-send-command
34+ :resume claude-code-resume
2435 :config " ~/.claude.json"
2536 :cli " claude" )
2637 (claude-code-ide
2940 :start claude-code-ide--start-if-no-session
3041 :switch claude-code-ide-switch-to-buffer
3142 :send claude-code-ide-send-prompt
43+ :resume claude-code-ide-resume
3244 :config " ~/.claude.json"
3345 :cli " claude" )
3446 (gemini
3749 :start gemini-cli
3850 :switch gemini-cli-switch-to-buffer
3951 :send gemini-cli-send-command
52+ :resume nil
4053 :config " ~/.gemini/settings.json"
4154 :cli " gemini" )
4255 (codex
4558 :start codex-cli
4659 :switch codex-cli-switch-to-buffer
4760 :send codex-cli-send-command
61+ :resume codex-cli-resume
4862 :config " ~/.codex/config.toml"
4963 :cli " codex" ))
5064 " Available AI backends and how to integrate with them.
51- Each entry is (KEY :label STRING :require FEATURE :start FN :switch FN :send FN :cli STRING)."
65+ Each entry is (KEY :label STRING :require FEATURE :start FN :switch FN :send FN :resume FN-or-nil : cli STRING)."
5266 :type '(repeat (list (symbol :tag " Key" )
5367 (const :label ) (string :tag " Label" )
5468 (const :require ) (symbol :tag " Feature to require" )
5569 (const :start ) (symbol :tag " Start function" )
5670 (const :switch ) (symbol :tag " Switch function" )
5771 (const :send ) (symbol :tag " Send function" )
72+ (const :resume ) (choice (symbol :tag " Resume function" ) (const :tag " Not supported" nil ))
5873 (const :cli ) (string :tag " CLI name" )))
5974 :group 'ai-code )
6075
@@ -97,6 +112,7 @@ Sets `ai-code-cli-*' defaliases and updates `ai-code-cli'."
97112 (start (plist-get plist :start ))
98113 (switch (plist-get plist :switch ))
99114 (send (plist-get plist :send ))
115+ (resume (plist-get plist :resume ))
100116 (cli (plist-get plist :cli )))
101117 ; ; If the declared feature is not available after require, inform user to install it.
102118 (when (and feature (not (featurep feature)))
@@ -108,6 +124,17 @@ Sets `ai-code-cli-*' defaliases and updates `ai-code-cli'."
108124 (defalias 'ai-code-cli-start start)
109125 (defalias 'ai-code-cli-switch-to-buffer switch)
110126 (defalias 'ai-code-cli-send-command send)
127+ (when (and resume (not (fboundp resume)))
128+ (user-error " Backend '%s' declares resume function '%s' but it is not callable."
129+ label (symbol-name resume)))
130+ (if resume
131+ (let ((resume resume))
132+ (fset 'ai-code-cli-resume
133+ (lambda (&optional arg )
134+ (interactive " P" )
135+ (let ((current-prefix-arg arg))
136+ (call-interactively resume)))))
137+ (fset 'ai-code-cli-resume #'ai-code--unsupported-resume ))
111138 (setq ai-code-cli cli
112139 ai-code-selected-backend key)
113140 (message " AI Code backend switched to: %s " (plist-get plist :label )))))
0 commit comments