branch: elpa/aidermacs
commit 581c74dad30a66ccd16b02a1b5ff77405e2d6ae9
Author: Mingde (Matthew) Zeng <matthew...@posteo.net>
Commit: Mingde (Matthew) Zeng <matthew...@posteo.net>

    Add Separate Reasoner/Editing mode!
    
    Fixes #22
---
 README.md           | 88 ++++++++++++++++++++++++++++++++---------------------
 aidermacs-models.el | 35 ++++++++++++++++++---
 aidermacs.el        | 25 +++++++++------
 3 files changed, 100 insertions(+), 48 deletions(-)

diff --git a/README.md b/README.md
index 7171b188a4..a0cc1bef40 100644
--- a/README.md
+++ b/README.md
@@ -16,7 +16,7 @@ Key features:
 
 ## Why Aidermacs?
 
-Aidermacs delivers an Emacs-centric experience by deeply integrating with 
Emacs paradigms, made by Emacs users, for Emacs users. This includes 
intelligent model selection, flexible terminal backend support (comint and 
vterm), smarter syntax highlighting, enhanced file management, streamlined 
transient menus, and more.
+Aidermacs delivers an Emacs-centric experience by deeply integrating with 
Emacs paradigms, made by Emacs users, for Emacs users. This includes ability to 
separate reasoning and code editing model, intelligent model selection, 
flexible terminal backend support (comint and vterm), smarter syntax 
highlighting, enhanced file management, streamlined transient menus, and more.
 
 ### Community-Driven Development
 
@@ -46,6 +46,13 @@ Your contributions are essential to making Aidermacs the 
best AI pair programmin
   (global-set-key (kbd "C-c a") 'aidermacs-transient-menu))
 ```
 
+### Sample Config With Doom Emacs
+```emacs-lisp
+(package! aidermacs :recipe (:host github :repo "MatthewZMD/aidermacs" :files 
("*.el")))
+```
+
+## Configuration
+
 ### Default Model Selection
 
 You can customize the default AI model used by Aidermacs by setting the 
`aidermacs-default-model` variable:
@@ -56,24 +63,43 @@ You can customize the default AI model used by Aidermacs by 
setting the `aiderma
 
 This allows you to easily switch between different AI models without modifying 
the `aidermacs-extra-args` variable.
 
-### Customizing Aider Options with `aidermacs-extra-args`
+### Dynamic Model Selection
 
-The `aidermacs-extra-args` variable allows you to pass any command-line 
options supported by Aider. See the [Aider configuration 
documentation](https://aider.chat/docs/config/options.html) for a full list of 
available options.
+Aidermacs provides intelligent model selection for the solo (non-Architect) 
mode that automatically detects and integrates with multiple AI providers:
 
-For example, to set the verbosity:
+- Automatically fetches available models from supported providers (OpenAI, 
Anthropic, DeepSeek, Google Gemini, OpenRouter)
+- Caches model lists for quick access
+- Supports both popular pre-configured models and dynamically discovered ones
+- Handles API keys and authentication automatically
+- Provides model compatibility checking
 
-```emacs-lisp
-(setq aidermacs-extra-args '("--verbose"))
-```
+The dynamic model selection is only for the solo (non-Architect) mode.
 
-These arguments will be appended to the Aider command when it is run. Note 
that the `--model` argument is automatically handled by 
`aidermacs-default-model` and should not be included in `aidermacs-extra-args`.
+To change models in solo mode:
+1. Use `M-x aidermacs-change-model` or press `o` in the transient menu
+2. Select from either:
+   - Popular pre-configured models (fast)
+   - Dynamically fetched models from all supported providers (comprehensive)
+
+The system will automatically filter models to only show ones that are:
+- Supported by your current Aider version
+- Available through your configured API keys
+- Compatible with your current workflow
+
+### Separating Code Reasoning and Editing
+
+Aidermacs supports an experimental mode that leverages two models for each 
coding task: an Architect model for reasoning and an Editor model for 
generating code edits. This approach has **achieved state-of-the-art (SOTA) 
results on aider's code editing benchmark**, as detailed in [this blog 
post](https://aider.chat/2024/09/26/architect.html).
+
+To enable this mode, set `aidermacs-use-architect-mode` to `t`. You may also 
configure the `aidermacs-architect-model` and `aidermacs-editor-model` 
variables to specify the models to use for the Architect and Editor roles, 
respectively.
+
+When Architect mode is enabled, the `aidermacs-default-model` setting is 
ignored.
 
-### Sample Config With Doom Emacs
 ```emacs-lisp
-(package! aidermacs :recipe (:host github :repo "MatthewZMD/aidermacs" :files 
("*.el")))
+(setq aidermacs-use-architect-mode t)
+(setq aidermacs-architect-model "o1-mini") ; default
+(setq aidermacs-editor-model "anthropic/claude-3-5-sonnet-20241022") ; default
 ```
 
-## Configuration
 
 ### Terminal Backend Selection
 
@@ -112,6 +138,20 @@ When using the comint backend, you can customize the key 
binding for multiline i
 
 This key allows you to enter multiple lines without sending the command to 
Aider. Press `RET` normally to send the command.
 
+
+### Customizing Aider Options with `aidermacs-extra-args`
+
+If the above configurations aren't enough already, the `aidermacs-extra-args` 
variable allows you to pass any command-line options supported by Aider.
+
+See the [Aider configuration 
documentation](https://aider.chat/docs/config/options.html) for a full list of 
available options.
+
+```emacs-lisp
+;; Set the verbosity:
+(setq aidermacs-extra-args '("--verbose"))
+```
+
+These arguments will be appended to the Aider command when it is run. Note 
that the `--model` argument is automatically handled by 
`aidermacs-default-model` and should not be included in `aidermacs-extra-args`.
+
 ## Usage
 
 ### Getting Started
@@ -133,7 +173,7 @@ The main interface to Aidermacs is through its transient 
menu system. Here's a b
 ##### Core Actions
 - `a`: Start/Open Session (auto-detects project root)
 - `.` : Start in Current Directory (good for monorepos)
-- `o`: Change Model
+- `o`: Change Solo Model
 - `s`: Reset Session
 - `x`: Exit Session
 
@@ -159,13 +199,14 @@ The main interface to Aidermacs is through its transient 
menu system. Here's a b
 - `p`: Explain This Symbol
 
 ##### Others
+- `A`: Toggle Architect Mode (Separate Reasoner/Editor)
 - `H`: Session History
 - `L`: Copy Last Aidermacs Output
 - `O`: Clear Model Selection Cache
 - `l`: Clear Buffer
 - `h`: Aider Help
 
-### Working with Code Blocks
+### Working with Prompt Blocks in `.aider*` files
 
 When editing `.aider.prompt.org` or other `.aider*` files, these keybindings 
are available:
 
@@ -182,27 +223,6 @@ The `.aider.prompt.org` file (created with `M-x 
aidermacs-open-prompt-file`) is
 
 The file is automatically recognized and enables Aidermacs minor mode with the 
above keybindings.
 
-### Dynamic Model Selection
-
-Aidermacs provides intelligent model selection that automatically detects and 
integrates with multiple AI providers:
-
-- Automatically fetches available models from supported providers (OpenAI, 
Anthropic, DeepSeek, Google Gemini, OpenRouter)
-- Caches model lists for quick access
-- Supports both popular pre-configured models and dynamically discovered ones
-- Handles API keys and authentication automatically
-- Provides model compatibility checking
-
-To change models:
-1. Use `M-x aidermacs-change-model` or press `o` in the transient menu
-2. Select from either:
-   - Popular pre-configured models (fast)
-   - Dynamically fetched models from all supported providers (comprehensive)
-
-The system will automatically filter models to only show ones that are:
-- Supported by your current Aider version
-- Available through your configured API keys
-- Compatible with your current workflow
-
 ## Aidermacs vs aider.el
 
 Aidermacs is designed to provide a more Emacs-native experience while still 
integrating with [Aider](https://github.com/paul-gauthier/aider). It began as a 
fork of [aider.el](https://github.com/tninja/aider.el), but has since diverged 
significantly to prioritize Emacs workflow integration.
diff --git a/aidermacs-models.el b/aidermacs-models.el
index fbd0052fee..c682061fa0 100644
--- a/aidermacs-models.el
+++ b/aidermacs-models.el
@@ -11,15 +11,44 @@
 
 ;;; Code:
 
+(require 'json)
+(require 'url)
+
 (defgroup aidermacs-models nil
   "Model selection customization for aidermacs."
   :group 'aidermacs)
 
 (defcustom aidermacs-default-model "anthropic/claude-3-5-sonnet-20241022"
-  "Default AI model to use for aidermacs sessions."
+  "Default AI model to use for aidermacs sessions when not in Architect mode."
+  :type 'string
+  :group 'aidermacs-models)
+
+(defcustom aidermacs-architect-model "o1-mini"
+  "Default AI model to use for architectural reasoning in aidermacs sessions."
+  :type 'string
+  :group 'aidermacs-models)
+
+(defcustom aidermacs-editor-model "anthropic/claude-3-5-sonnet-20241022"
+  "Default AI model to use for code editing in aidermacs sessions."
   :type 'string
   :group 'aidermacs-models)
 
+(defcustom aidermacs-use-architect-mode nil
+  "If non-nil, use separate Architect/Editor mode."
+  :type 'boolean
+  :group 'aidermacs-models)
+
+(defun aidermacs-toggle-architect-mode ()
+  "Toggle the `aidermacs-use-architect-mode` variable."
+  (interactive)
+  (setq aidermacs-use-architect-mode (not aidermacs-use-architect-mode))
+  (message "Architect Mode: %s" (if aidermacs-use-architect-mode "ON" "OFF"))
+  (when (get-buffer (aidermacs-buffer-name))
+    (when (yes-or-no-p
+           (format "Aidermacs Architect Mode %s. Change will take affect next 
session. Close the session now? "
+                   (if aidermacs-use-architect-mode "ON" "OFF")))
+      (aidermacs-exit))))
+
 (defcustom aidermacs-popular-models
   '("anthropic/claude-3-5-sonnet-20241022"
     "o3-mini"
@@ -36,9 +65,6 @@ Also based on aidermacs LLM benchmark: 
https://aidermacs.chat/docs/leaderboards/
 (defvar aidermacs--cached-models aidermacs-popular-models
   "Cache of available AI models.")
 
-(require 'json)
-(require 'url)
-
 (defun aidermacs--fetch-openai-compatible-models (url)
   "Fetch available models from an OpenAI compatible API endpoint at URL.
 URL should be the base API endpoint, e.g. https://api.openai.com/v1.
@@ -145,6 +171,7 @@ Returns a list of model names with appropriate prefixes 
based on the API provide
       (aidermacs--select-model)
     (aidermacs--get-available-models)))
 
+
 (provide 'aidermacs-models)
 
 ;;; aidermacs-models.el ends here
diff --git a/aidermacs.el b/aidermacs.el
index 6935745da2..3add7c2637 100644
--- a/aidermacs.el
+++ b/aidermacs.el
@@ -65,7 +65,6 @@ When nil, disable auto-commits requiring manual git commits."
       default-directory))
 
 
-
 (defcustom aidermacs-language-name-map '(("elisp" . "emacs-lisp")
                                          ("bash" . "sh")
                                          ("objective-c" . "objc")
@@ -105,7 +104,6 @@ This function can be customized or redefined by the user."
   ;; Ensure the alias is always available in both compiled and interpreted 
modes.
   (defalias 'aidermacs-read-string 'aidermacs-plain-read-string))
 
-
 ;; Transient menu for aidermacs commands
 ;; The instruction in the autoload comment is needed, see
 ;; https://github.com/magit/transient/issues/280.
@@ -148,7 +146,7 @@ This function can be customized or redefined by the user."
    ["Core Actions"
     ("a" "Start/Open Session" aidermacs-run)
     ("." "Start in Current Dir" aidermacs-run-in-current-dir)
-    ("o" "Change Model" aidermacs-change-model)
+    ("o" "Change Solo Model" aidermacs-change-model)
     ("s" "Reset Session" aidermacs-reset)
     ("x" "Exit Session" aidermacs-exit)]
 
@@ -170,6 +168,7 @@ This function can be customized or redefined by the user."
     ("p" "Explain This Symbol" aidermacs-explain-symbol-under-point)]
 
    ["Others"
+    ("A" "Toggle Architect Mode (Separate Reasoner/Editor)" 
aidermacs-toggle-architect-mode)
     ("H" "Session History" aidermacs-show-output-history)
     ("L" "Copy Last Aidermacs Output" aidermacs-get-last-output)
     ("O" "Clear Model Selection Cache" aidermacs-clear-model-cache)
@@ -226,13 +225,19 @@ Prefers existing sessions closer to current directory."
   (interactive)
   (let* ((buffer-name (aidermacs-buffer-name))
          (has-model-arg (seq-position aidermacs-extra-args "--model"))
-         (final-args (append (unless has-model-arg
-                             (list "--model" aidermacs-default-model))
-                           (unless aidermacs-auto-commits
-                             '("--no-auto-commits"))
-                           (when aidermacs-subtree-only
-                             '("--subtree-only"))
-                           aidermacs-extra-args)))
+         (final-args (append
+                      (when aidermacs-use-architect-mode
+                        (list "--architect"
+                              "--model" aidermacs-architect-model
+                              "--editor-model" aidermacs-editor-model))
+                      (unless aidermacs-use-architect-mode
+                        (unless has-model-arg
+                          (list "--model" aidermacs-default-model)))
+                      (unless aidermacs-auto-commits
+                        '("--no-auto-commits"))
+                      (when aidermacs-subtree-only
+                        '("--subtree-only"))
+                      aidermacs-extra-args)))
     ;; Check if a matching buffer exists (handled by aidermacs-buffer-name)
     (if (get-buffer buffer-name)
         (aidermacs-switch-to-buffer)

Reply via email to