aider icon indicating copy to clipboard operation
aider copied to clipboard

Introduce FolderCoder and provide first implementation

Open elifarley opened this issue 1 year ago • 6 comments
trafficstars

This PR refactors the coder system in Aider to use a dynamic, folder-based mechanism for loading prompts. This replaces hardcoded prompt classes with flexible loading from resource directories, making it easier to configure, extend, and maintain different coder types without modifying core code.

Key Changes

• Introduces FolderCoder and AiderFolderCoder as base classes to dynamically load prompts from folders.
• Migrates AskCoder and ArchitectCoder to the new folder-based approach, and adds a new AskFurtherCoder implementation.
• Fixes a minor typo in base_coder.py ("confused" → "confuse") and corrects the usage of a classmethod decorator.
• Adds build automation scripts (Makefile and check-version.sh) for easier development workflows.
• Includes new folder-based prompt resources under aider/resources/folder-coders/ for built-in coders.

Detailed Changes: aider/coders/folder_coder.py

This new file defines two classes for loading prompts from directories, enabling modular prompt management.

FolderCoder

• Purpose: A base class extending Coder (the general class for AI-driven code generation tasks) to load prompts dynamically from a specified folder. • Key Features: • Accepts a prompt_folder_path (a Traversable like a filesystem path or package resource) and an optional edit_format. • Creates a subclass of CoderPrompts using _create_coder_prompts_subclass, which generates a named subclass (e.g., via PascalCase conversion of the coder name) and populates it with prompt content. • Uses load_class_attrs_from_folder to read .txt files from a subfolder (e.g., prompt_folder_path / coder_name), setting each file's content as a class attribute (filename without .txt extension). • Handles errors gracefully (e.g., missing folders or read failures) by returning silently.
• Integrates the new prompts subclass into the coder's initialization via self.gpt_prompts.

AiderFolderCoder

• Purpose: A specialized subclass of FolderCoder for loading Aider's built-in coder prompts from package resources.

• Key Features: • Overrides __init__ to set prompt_folder_path to files("aider.resources.folder-coders"), pointing to the bundled resource directory. • Enables seamless access to predefined prompts without external paths.

New edit format: ask-further

aider --model gemini-1.5-flash --edit-format ask-further aider/coders/folder_coder.py
image image

Benefits and Summary

This refactor promotes extensibility: new coders can be added by simply creating a subfolder with .txt prompt files, reducing boilerplate and centralizing prompt management. No existing functionality is broken, and the system remains backward-compatible. The changes make Aider more maintainable for future coder variants, such as specialized models or custom behaviors.

Note: this is not related to the FolderCode language

elifarley avatar Nov 13 '24 00:11 elifarley

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

:white_check_mark: elifarley
:x: Copilot
You have signed the CLA already but the status is still pending? Let us recheck it.

CLAassistant avatar Nov 13 '24 00:11 CLAassistant

1232就斤斤计较

shinely05 avatar Nov 15 '24 10:11 shinely05

This is super useful

bitnom avatar Feb 11 '25 00:02 bitnom

If it's not too much trouble, would you mind merging the latest master to your branch?

bitnom avatar Feb 11 '25 00:02 bitnom

@elifarley

I have synced/merged your feat/folder-coder and cedarscript branches with the latest main branch:

https://github.com/bitnom/aider/tree/cedarscript (I'm not sure exactly the purpose of this) https://github.com/bitnom/aider/tree/feat/folder-coder

bitnom avatar Feb 11 '25 21:02 bitnom

@bitnom wanna get back to this?

elifarley avatar Nov 10 '25 00:11 elifarley