aboutsummaryrefslogtreecommitdiff
path: root/modules/ai-config.el
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-05-10 02:43:48 -0500
committerCraig Jennings <c@cjennings.net>2026-05-10 02:43:48 -0500
commit0248afe222a0722ec336e8c09269612eb773702b (patch)
tree0108507c9b92616dca51b6c575137785f2f8d4dc /modules/ai-config.el
parentc78574ab7a7bd0f9a6e4a61c6cdcd196257cff8e (diff)
downloaddotemacs-0248afe222a0722ec336e8c09269612eb773702b.tar.gz
dotemacs-0248afe222a0722ec336e8c09269612eb773702b.zip
Move GPTel tool loading into AI config
Move the local GPTel tool wiring out of init.el and into ai-config. The tools directory and feature list are now configurable, missing optional tools are non-fatal, and focused tests cover the loading behavior.
Diffstat (limited to 'modules/ai-config.el')
-rw-r--r--modules/ai-config.el49
1 files changed, 46 insertions, 3 deletions
diff --git a/modules/ai-config.el b/modules/ai-config.el
index 3b0b6e20..98e738ea 100644
--- a/modules/ai-config.el
+++ b/modules/ai-config.el
@@ -34,9 +34,6 @@
(autoload 'cj/gptel-load-conversation "ai-conversations" "Load a saved AI conversation." t)
(autoload 'cj/gptel-delete-conversation "ai-conversations" "Delete a saved AI conversation." t)
-(with-eval-after-load 'gptel
- (require 'ai-conversations))
-
;;; ------------------------- AI Config Helper Functions ------------------------
;; Define variables upfront
@@ -45,6 +42,52 @@
(defvar gptel-claude-backend nil "Claude backend, lazy-initialized.")
(defvar gptel-chatgpt-backend nil "ChatGPT backend, lazy-initialized.")
+(defcustom cj/gptel-tools-directory
+ (expand-file-name "gptel-tools/" user-emacs-directory)
+ "Directory containing optional local GPTel tool modules."
+ :type 'directory
+ :group 'cj)
+
+(defcustom cj/gptel-local-tool-features
+ '(read_buffer
+ read_text_file
+ write_text_file
+ list_directory_files
+ move_to_trash)
+ "Feature symbols for optional local GPTel tool modules."
+ :type '(repeat symbol)
+ :group 'cj)
+
+(defun cj/gptel-load-local-tools
+ (&optional tools-directory tool-features)
+ "Load optional GPTel tools from TOOLS-DIRECTORY.
+TOOL-FEATURES defaults to `cj/gptel-local-tool-features'. Return a list
+of loaded feature symbols. Missing directories or individual optional
+tools are reported with `message' and do not signal."
+ (let ((dir (file-name-as-directory
+ (expand-file-name (or tools-directory cj/gptel-tools-directory))))
+ (features (or tool-features cj/gptel-local-tool-features))
+ (loaded nil))
+ (cond
+ ((not (file-directory-p dir))
+ (message "GPTel tools directory not found: %s" dir)
+ nil)
+ (t
+ (add-to-list 'load-path dir)
+ (dolist (feature features)
+ (condition-case err
+ (if (require feature nil 'noerror)
+ (push feature loaded)
+ (message "Optional GPTel tool not found: %s" feature))
+ (error
+ (message "Failed to load GPTel tool %s: %s"
+ feature
+ (error-message-string err)))))
+ (nreverse loaded)))))
+
+(with-eval-after-load 'gptel
+ (require 'ai-conversations)
+ (cj/gptel-load-local-tools))
(defun cj/auth-source-secret (host user)
"Fetch a secret from auth-source for HOST and USER.