branch: elpa/aidermacs
commit 6cfc8bfa46ad4074213effa45a0fe8e8e12a526e
Author: u-yuta <u-y...@users.noreply.github.com>
Commit: Matthew Zeng <matthew...@posteo.net>

    Fix model inheritance to dynamically use default model values
    
    - Change architect/editor/weak model defaults from direct reference to nil
    - Add getter functions to dynamically fall back to aidermacs-default-model
    - Update aidermacs-run to use these getter functions
    - Update README to reflect the new model inheritance behavior
    
    This ensures that when users set aidermacs-default-model, the change is
    automatically reflected in architect/editor models unless they're explicitly
    configured with their own values.
---
 README.md           | 13 ++++++++-----
 aidermacs-models.el | 48 ++++++++++++++++++++++++++++++++++--------------
 aidermacs.el        |  4 ++--
 3 files changed, 44 insertions(+), 21 deletions(-)

diff --git a/README.md b/README.md
index 92024ba628..26cf06baf9 100644
--- a/README.md
+++ b/README.md
@@ -227,10 +227,13 @@ You can switch to it persistently by `M-x 
aidermacs-switch-to-architect-mode` (`
 
 You can configure each model independently:
 ```emacs-lisp
-;; Architect model for reasoning (initially defaults to 
aidermacs-default-model)
-(setq aidermacs-architect-model "sonnet")
+;; Default model used for all modes unless overridden
+(setq aidermacs-default-model "sonnet")
+
+;; Optional: Set specific model for architect reasoning
+(setq aidermacs-architect-model "deepseek/deepseek-reasoner")
 
-;; Editor model for code generation (initially defaults to 
aidermacs-default-model)
+;; Optional: Set specific model for code generation
 (setq aidermacs-editor-model "deepseek/deepseek-chat")
 ```
 
@@ -239,9 +242,9 @@ The model hierarchy works as follows:
     - The Architect model handles high-level reasoning and solution design
     - The Editor model executes the actual code changes
 - When Architect mode is disabled, only `aidermacs-default-model` is used
-- You can configure both models independently or let them default to 
`aidermacs-default-model`
+- You can configure specific models or let them automatically use the default 
model
 
-*Note: The architect and editor models only inherit from 
`aidermacs-default-model` when first initialized. Changing 
`aidermacs-default-model` later will not update the other models. For 
consistent behavior, set each model explicitly.*
+Models will reflect changes to `aidermacs-default-model` unless they've been 
explicitly set to a different value.
 
 *Note: These configurations will be overwritten by the existence of an 
`.aider.conf.yml` file (see 
[details](#Overwrite-Configuration-with-Configuration-File)).*
 
diff --git a/aidermacs-models.el b/aidermacs-models.el
index f588c273d3..2aa79f0c2a 100644
--- a/aidermacs-models.el
+++ b/aidermacs-models.el
@@ -46,25 +46,39 @@
   "Default AI model to use for aidermacs sessions when not in Architect mode."
   :type 'string)
 
-(defcustom aidermacs-architect-model aidermacs-default-model
+(defcustom aidermacs-architect-model nil
   "Default reasoning AI model to use for architect mode.
-Defaults to `aidermacs-default-model' if not explicitly set."
-  :type 'string)
+If nil, uses the value of `aidermacs-default-model'."
+  :type '(choice (const :tag "Use default model" nil)
+                 (string :tag "Specific model")))
 
-(defcustom aidermacs-editor-model aidermacs-default-model
+(defcustom aidermacs-editor-model nil 
   "Default editing AI model to use for architect mode.
-Defaults to `aidermacs-default-model' if not explicitly set."
-  :type 'string)
+If nil, uses the value of `aidermacs-default-model'."
+  :type '(choice (const :tag "Use default model" nil)
+                 (string :tag "Specific model")))
 
 (defcustom aidermacs-weak-model nil
   "Default weak AI model to use.
-This is the model to use for commit messages and chat history summarization.
-When nil, Aider sets it automatically based on the default model."
-  :type 'string)
+If nil, uses a model automatically selected based on the default model."
+  :type '(choice (const :tag "Use default model" nil)
+                 (string :tag "Specific model")))
 
 (defvar aidermacs--cached-models nil
   "Cache of available AI models.")
 
+(defun aidermacs-get-architect-model ()
+  "Get the effective architect model, falling back to default if not set."
+  (or aidermacs-architect-model aidermacs-default-model))
+
+(defun aidermacs-get-editor-model ()
+  "Get the effective editor model, falling back to default if not set."
+  (or aidermacs-editor-model aidermacs-default-model))
+
+(defun aidermacs-get-weak-model ()
+  "Get the effective weak model, falling back to default if not set."
+  (or aidermacs-weak-model aidermacs-default-model))
+
 (defconst aidermacs--api-providers
   '(("https://openrouter.ai/api/v1"; . ((hostname . "openrouter.ai")
                                        (prefix . "openrouter")
@@ -158,8 +172,7 @@ API provider."
                   models))))))
 
 (defun aidermacs--select-model (&optional set-weak-model)
-  "Provide model selection with completion, handling main/weak/editor models.
-When SET-WEAK-MODEL is non-nil, only allow setting the weak model."
+  "Provide model selection with completion, handling main/weak/editor models."
   (condition-case nil
       (let* ((aider-version (aidermacs-aider-version))
              (supports-specific-model (version<= "0.78.0" aider-version))
@@ -178,12 +191,19 @@ When SET-WEAK-MODEL is non-nil, only allow setting the 
weak model."
         (when model
           (cond
            (set-weak-model
+            (setq aidermacs-weak-model model)
             (aidermacs--send-command (format "/weak-model %s" model)))
            ((and is-architect-mode supports-specific-model)
             (pcase model-type
-              ("Main/Reasoning Model" (aidermacs--send-command (format "/model 
%s" model)))
-              ("Editing Model" (aidermacs--send-command (format "/editor-model 
%s" model)))))
-           (t (aidermacs--send-command (format "/model %s" model))))))
+              ("Main/Reasoning Model" 
+               (setq aidermacs-architect-model model)
+               (aidermacs--send-command (format "/model %s" model)))
+              ("Editing Model"
+               (setq aidermacs-editor-model model)
+               (aidermacs--send-command (format "/editor-model %s" model)))))
+           (t 
+            (setq aidermacs-default-model model)
+            (aidermacs--send-command (format "/model %s" model))))))
     (quit (message "Model selection cancelled"))))
 
 (defun aidermacs--get-available-models ()
diff --git a/aidermacs.el b/aidermacs.el
index ec264bf428..ffa3d92ee8 100644
--- a/aidermacs.el
+++ b/aidermacs.el
@@ -297,8 +297,8 @@ This function sets up the appropriate arguments and 
launches the process."
             (append
              (if aidermacs-use-architect-mode
                  (list "--architect"
-                       "--model" aidermacs-architect-model
-                       "--editor-model" aidermacs-editor-model)
+                       "--model" (aidermacs-get-architect-model)
+                       "--editor-model" (aidermacs-get-editor-model))
                (unless has-model-arg
                  (list "--model" aidermacs-default-model)))
              (unless aidermacs-auto-commits

Reply via email to