Skip to content

Feature Proposal: Batch File Refactoring with /add-dir and /batch #4375

@robinson-carusoe

Description

@robinson-carusoe

Feature Proposal: Batch File Refactoring with /add-dir and /batch

I work with a ton of legacy code. When upgrading the code, there are times that I need to apply the same prompt to hundreds of files to bring them up to date. Adding all the files to the context is impossible. Adding each individual file (or a group of them) is tedious.

I just wrote a proof of concept and ran it against one of my repositories. It works like this:

/read-only some-file-with-specific-instructions.md
/add-dir my/dir-with-lots-of-files

/batch make some change that is the same in every one of these files.

Aider then:

  • Stores the prompt in memory
  • Iterates over the list of files collected by /add-dir
  • For each file:
    • Adds the file to the chat context (along with any read-only files)
    • Sends the prompt as a user message to the LLM
    • Waits for the assistant's response
    • Commits the changes
    • Forgets the file from the chat context
    • Resets chat memory to keep context clean per file
  • After all files, clears the queue and prints a summary of results

I run into this problem often, and my initial code worked great on a list of about 80 classes that were using an old framework syntax and all needed to be upgraded to the new syntax.

Is there any interest in seeing a pull request to have this feature in the core?

Command Summary

/add-dir {dir_name} {dir_name}        # Add one or more directories
/drop-dir {dir_name} {dir_name}       # Drop all or some directories from the chat
/ls-dir                               # List the directories in the chat
/ls-dir {dir_name}                    # List the files found in the directory in the chat if present
/batch {prompt}                       # Apply the prompt with a clean context to each file

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions