aidermacs

repository·main·Indexed 21 days ago

https://github.com/matthewzmd/aidermacs

An Emacs-native integration for the Aider AI pair programming tool. It provides an Emacs-centric workflow featuring a transient menu for core commands, deep integration with Ediff, specialized file management (including read-only and external files), and support for Architect mode. It includes a Prompt Files minor mode, Tramp support for remote files, and configurable terminal backends via comint or vterm.

Tokens
4K
Snippets
18
Records
25
Agent score
25%

What's inside aidermacs

  1. Configure Architect Mode with specialized models

    main

    Architect mode uses two models: an Architect model for reasoning and an Editor model for code generation. This mode is enabled by setting aidermacs-default-chat-mode to 'architect.

    Key Variables:

    • aidermacs-default-chat-mode: Set to 'architect to use this mode by default.
    • aidermacs-architect-model: Specifies the model for high-level reasoning.
    • aidermacs-editor-model: Specifies the model for code generation (defaults to aidermacs-default-model).

    Switching Modes:

    • Persistently: M-x aidermacs-switch-to-architect-mode (3 in transient menu).
    • Temporarily: M-x aidermacs-architect-this-code (r in transient menu).

    Confirmation: By default, Architect mode requires confirmation before applying changes. To skip this, use: (setq aidermacs-auto-accept-architect t)

    ;; 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")
    
    ;; Optional: Set specific model for code generation
    (setq aidermacs-editor-model "deepseek/deepseek-chat")
  2. Enable File Watching for AI Instructions

    main

    When aidermacs-watch-files is enabled, Aidermacs watches your repository for specific comment-based instructions. This feature currently requires the vterm backend.

    Instruction Syntax: Use one-liner comments that start or end with AI, AI!, or AI?:

    • # Instruction AI!: Triggers Aider to make changes to the code.
    • # Question AI?: Triggers Aider to answer the question.
    • # Instruction AI: General instruction.
    ;; Enable file watching
    (setq aidermacs-watch-files t)
  3. Key differences between Aidermacs and Aider CLI

    main

    While Aidermacs integrates with the Aider CLI, it is designed as an Emacs-native experience rather than a CLI mirror. Key features include:

    • Ediff Integration: Automatically uses Emacs' ediff for seamless code review and diffing of AI-generated changes.
    • Multiline Input: Handles complex, multiline prompts natively within Emacs, bypassing terminal limitations.
    • Terminal Backends: Supports both comint and vterm backends.
    • File Management: Provides specialized Emacs commands for adding/dropping files and managing sessions.
    • Model Selection: Features intelligent, real-time model discovery and compatibility checking.
  4. Understand Configuration Precedence

    main

    Aidermacs follows a strict hierarchy to determine settings.

    1. Highest Priority: Aider Configuration File (.aider.conf.yml) If a config file is found, Aidermacs ignores its own Emacs variables (like aidermacs-default-model). You should define all settings in the .aider.conf.yml to avoid conflicts.

    2. Second Priority: Emacs Configuration (if no .aider.conf.yml is used) If no config file is present, settings are applied in this order:

    • Emacs Variables (e.g., setq aidermacs-default-model)
    • Environment Variables (e.g., AIDER_MODEL)
    • Built-in Defaults
  5. Manage Files and Context in Aidermacs

    main

    Effective AI interaction requires managing which files the AI can see and edit.

    File Access Modes

    • Editable Files: Add files normally to allow the AI to both read and modify them.
    • Read-Only Files: To allow the AI to read a file without permission to edit it, prefix any 'Add File' command with C-u.
    • Session Scratchpads: Use the S command in the transient menu to create scratchpads. These are useful for pasting notes or documentation that the AI can use as read-only context.
    • External Files: Use the G (Add File to Session) command to include files that are outside the current project root or are listed in .gitignore.

    Best Practices

    While the AI may infer context, manually specifying files (especially in complex projects) provides more precise control over the AI's scope.

  6. Use Dynamic Model Selection in Solo Mode

    main

    In solo (non-Architect) mode, Aidermacs can automatically discover and fetch available models from providers like OpenAI, Anthropic, DeepSeek, Google Gemini, and OpenRouter. It caches these lists and handles authentication via your .bashrc keys.

    To change models during a session:

    1. Run M-x aidermacs-change-model or press o in the transient menu.
    2. Choose between pre-configured models or dynamically fetched models.
  7. Install Aider using uv for Python 3.12 compatibility

    main

    Aider currently only supports Python 3.12. If you are using Python 3.13, it is recommended to use uv to install a specific Python 3.12 version of aider-chat to avoid compatibility issues.

    uv tool install --force --python python3.12 aider-chat@latest
  8. Configure Aidermacs for Spacemacs

    main

    For Spacemacs users, add aidermacs to your dotspacemacs-additional-packages and set your preferred keybindings in dotspacemacs/user-config.

    1. Add Package

    dotspacemacs-additional-packages '((
      aidermacs :variables
                  aidermacs-default-chat-mode 'architect
                  aidermacs-default-model "sonnet")
    ))

    2. Set Keybindings

    (defun dotspacemacs/user-config ()
      ;; Example: bind to SPC a a
      (spacemacs/set-leader-keys "aa" 'aidermacs-transient-menu)
    )
    dotspacemacs-additional-packages '((
      aidermacs :variables
                  aidermacs-default-chat-mode 'architect
                  aidermacs-default-model "sonnet")
    ))
    
    (defun dotspacemacs/user-config ()
      (spacemacs/set-leader-keys "aa" 'aidermacs-transient-menu)
    )
  9. Install Aidermacs

    main

    To use Aidermacs, ensure you meet the following requirements and follow the installation steps below.

    Requirements

    Installation

    • MELPA/Non-GNU ELPA: Download via your preferred package manager.
    • Manual: Clone the repository manually.

    Basic Configuration

    Add the following to your init.el to bind the transient menu and set up API keys:

    (use-package aidermacs
      :bind (("C-c a" . aidermacs-transient-menu))
      :config
      ; Set API_KEY in .bashrc (automatically picked up) or via setenv
      (setenv "ANTHROPIC_API_KEY" "sk-...")
      (setenv "OPENROUTER_API_KEY" (my-get-openrouter-api-key))
      :custom
      (aidermacs-default-chat-mode 'architect)
      (aidermacs-default-model "sonnet"))
    (use-package aidermacs
      :bind (("C-c a" . aidermacs-transient-menu))
      :config
      (setenv "ANTHROPIC_API_KEY" "sk-...")
      (setenv "OPENROUTER_API_KEY" (my-get-openrouter-api-key))
      :custom
      (aidermacs-default-chat-mode 'architect)
      (aidermacs-default-model "sonnet"))
  10. Use Aidermacs with Remote Files via Tramp

    main

    Aidermacs supports remote files through Emacs' Tramp mode (SSH, Docker, etc.). When you open a remote file, Aidermacs automatically detects the remote context, localizes file paths, and applies edits directly to the remote system.

    ;; Open a remote file via SSH
    (find-file "/ssh:user@remotehost:/path/to/file.py")
    
    ;; Start Aidermacs session
    M-x aidermacs-transient-menu
  11. Use Prompt Files Minor Mode

    main

    Aidermacs includes a minor mode specifically for working with Aider-related files like .aider.prompt.org, .aider.chat.md, .aider.chat.history.md, and .aider.input.history.

    When this mode is active, use the following keybindings:

    • C-c C-n or C-<return>: Send line/region line-by-line
    • C-c C-c: Send block/region as a whole
    • C-c C-z: Switch to the Aidermacs buffer

    To create a new prompt file, use M-x aidermacs-open-prompt-file.

  12. Use the Aidermacs Transient Menu

    main

    The primary interface for Aidermacs is the aidermacs-transient-menu. You can access it via M-x aidermacs-transient-menu or a custom keybinding.

    Core Commands

    • a: Start/Open Session (auto-detects project root)
    • .: Start in Current Directory (useful for monorepos)
    • l: Clear Chat History
    • s: Reset Session
    • x: Exit Session

    Persistent Modes

    • 1: Code Mode
    • 2: Chat/Ask Mode
    • 3: Architect Mode
    • 4: Help Mode

    Utilities

    • ^: Show Last Commit (if auto-commits enabled)
    • u: Undo Last Commit (if auto-commits enabled)
    • R: Refresh Repo Map
    • h: Session History
    • o: Change Main Model
    • v: Send Voice Command
    • W: Fetch Web Content
    • ?: Aider Meta-level Help

    File Actions

    • f: Add File (prefix with C-u for read-only)
    • F: Add Current File
    • d: Add From Directory
    • w: Add From Window
    • m: Add From Dired (marked)
    • j: Drop File
    • J: Drop Current File
    • k: Drop From Dired (marked)
    • K: Drop All Files
    • S: Create Session Scratchpad
    • G: Add File to Session (includes files outside project/gitignore)
    • A: List Added Files

    Code Actions

    • c: Code Change
    • e: Question Code
    • r: Architect Change
    • q: General Question
    • p: Question This Symbol
    • g: Accept Proposed Changes
    • i: Implement TODO
    • t: Write Test
    • T: Fix Test
    • !: Debug Exception