aider icon indicating copy to clipboard operation
aider copied to clipboard

/read-only by glob pattern

Open akaihola opened this issue 1 year ago • 9 comments

Work in progress – basic use cases verified, need tests for more complex scenarios

  • [x] remove --force option
  • [ ] debug Windows test failure (see comment below)

This patch modifies the /read-only command to behave like /add by accepting directories and glob patterns.

A directory is walked recursively and all files added:

/read-only tests

This would add all files in tests/, tests/basic/, tests/browser/, tests/fixtures/, tests/help/ and tests/scrape/ when run in the Aider source tree.

A glob pattern is matched against and all matching files added:

/read-only aider/repo*.py

This would add aider/repo.py and aider/repomap.py if used in the Aider source tree.

Both of the above limit to non-ignored files in the repository ~~unless a --force option is provided~~. Non-glob explicit file paths still are added to the read-only file set ~~even if --force is not specified~~. So:

/read-only ~/example.py        # will add since this is not a glob pattern
/read-only dist/aider_chat-0.52.2.dev0-py3-none-any.whl  # will add since this is not a glob pattern
/read-only dist/*.whl          # won't add by glob pattern since `dist/` is in `.gitignore`
/read-only dist                # wont add by directory name since `dist/` is in `.gitignore`

akaihola avatar Aug 25 '24 17:08 akaihola

@akaihola hey, what’s up with this PR? Do you need any help in completing this? I’d really love to see this feature added.

blazer82 avatar Sep 13 '24 05:09 blazer82

I think this functionality is already available in the main bench.

You can get it by installing the latest version from github:

aider --install-main-branch

# or...

python -m pip install --upgrade git+https://github.com/paul-gauthier/aider.git

If you have a chance to try it, let me know if it works better for you.

paul-gauthier avatar Sep 13 '24 13:09 paul-gauthier

I think this functionality is already available in the main bench.

@paul-gauthier, I tested Aider v0.56.1.dev128+g70434fa0. My observations:

  • :green_circle: file path completion works for /read-only
  • :green_circle: /read-only <directory> works: adds the complete directory tree recursively
  • :red_circle: /read-only <wildcard> doesn't work

I'll rebase this branch on main.

Here's an example of wildcards not working yet:

> /add aider/re*.py                                                                                                                                                            

Added aider/report.py to the chat
Added aider/repo.py to the chat
Added aider/repomap.py to the chat
No changes made to git tracked files.
────────────────────────────────────────────────
aider/repo.py aider/repomap.py aider/report.py                                                                                                                                 
> /drop *                                                                                                                                                                      

Removed aider/repo.py from the chat
Removed aider/repomap.py from the chat
Removed aider/report.py from the chat
No changes made to git tracked files.
────────────────────────────────────────────────
> /read-only aider/re*.py                                                                                                                                                      

Path not found: /home/akaihola/aider/aider/re*.py
No changes made to git tracked files.
────────────────────────────────────────────────

akaihola avatar Sep 14 '24 14:09 akaihola

I rebased on main. The basic tests (including ones I added) do pass, and the above example works:

> /read-only aider/re*.py                                                                                                                                                                                                         

Added aider/re*.py to read-only files.
Added aider/re*.py to read-only files.
Added aider/re*.py to read-only files.
No changes made to git tracked files.
──────────────────────────────────────

~~The --force option isn't yet included in tests.~~ (--force option has now been removed)

FYI @blazer82

akaihola avatar Sep 14 '24 14:09 akaihola

@paul-gauthier Thanks, I just tried and as @akaihola mentioned it doesn't work with wildcard patterns like it does for the /add command.

blazer82 avatar Sep 17 '24 12:09 blazer82

I am reluctant to add --switches to / commands. This opens a big can of worms in terms of parsing and consistency.

paul-gauthier avatar Sep 24 '24 21:09 paul-gauthier

I am reluctant to add --switches to / commands. This opens a big can of worms in terms of parsing and consistency.

I rebased on main and removed the --force option.

I guess it's enough that .gitignored files can still be added by providing the exact path, even if glob patterns can't match them.

akaihola avatar Sep 29 '24 13:09 akaihola

The only Windows test which was not cancelled had this test failure, I need to dive in and see what might be causing it:

================================== FAILURES ===================================
_______________ TestCommands.test_cmd_read_only_drop_directory ________________

self = <test_commands.TestCommands testMethod=test_cmd_read_only_drop_directory>

    def test_cmd_read_only_drop_directory(self):
        # NOTE: This test is closely modeled after `test_cmd_add_drop_directory`
        #       but it tests the /read-only command
    
        # Initialize the Commands and InputOutput objects
        io = InputOutput(pretty=False, yes=False)
    
        coder = Coder.create(self.GPT35, None, io)
        commands = Commands(io, coder)
    
        # Create a directory and add files to it using pathlib
        Path("test_dir").mkdir()
        Path("test_dir/another_dir").mkdir()
        Path("test_dir/test_file1.txt").write_text("Test file 1")
        Path("test_dir/test_file2.txt").write_text("Test file 2")
        Path("test_dir/another_dir/test_file.txt").write_text("Test file 3")
    
        # Call the cmd_read_only method with a directory
        commands.cmd_read_only("test_dir test_dir/test_file2.txt")
    
        # Check if the files have been added to the read-only files
        self.assertIn(str(Path("test_dir/test_file1.txt").resolve()), coder.abs_read_only_fnames)
        self.assertIn(str(Path("test_dir/test_file2.txt").resolve()), coder.abs_read_only_fnames)
        self.assertIn(str(Path("test_dir/another_dir/test_file.txt").resolve()), coder.abs_read_only_fnames)
    
        commands.cmd_drop("test_dir/another_dir")
        self.assertIn(str(Path("test_dir/test_file1.txt").resolve()), coder.abs_read_only_fnames)
        self.assertIn(str(Path("test_dir/test_file2.txt").resolve()), coder.abs_read_only_fnames)
>       self.assertNotIn(
            str(Path("test_dir/another_dir/test_file.txt").resolve()), coder.abs_read_only_fnames
        )
E       AssertionError:
        'C:\\Users\\runneradmin\\AppData\\Local\\Temp\\tmpgen16856\\test_dir\\another_dir\\test_file.txt'
        unexpectedly found in {
            'C:\\Users\\runneradmin\\AppData\\Local\\Temp\\tmpgen16856\\test_dir\\test_file2.txt',
            'C:\\Users\\runneradmin\\AppData\\Local\\Temp\\tmpgen16856\\test_dir\\test_file1.txt',
            'C:\\Users\\runneradmin\\AppData\\Local\\Temp\\tmpgen16856\\test_dir\\another_dir\\test_file.txt'
        }

tests\basic\test_commands.py:1064: AssertionError

akaihola avatar Sep 30 '24 13:09 akaihola

Thanks for the work on this. I implemented a pretty simple, streamlined glob expansion (well, aider implemented it). It's in the main branch now.

paul-gauthier avatar Oct 02 '24 16:10 paul-gauthier

I'm closing this issue for now.

If any new related concerns arise, please feel free to comment, and I'll reopen the issue.

fry69 avatar Oct 05 '24 13:10 fry69