Aider-AI / aider

aider is AI pair programming in your terminal
https://aider.chat/
Apache License 2.0
20.95k stars 1.94k forks source link

Strange issue unable to replace first line of the file, despite search/replace showing the content #2008

Open 5ocworkshop opened 2 weeks ago

5ocworkshop commented 2 weeks ago

Issue

I've got a bit of a strange one. Aider or VSCode appears to be swallowing the first line of output for reasons I can't see.

I'm working on some conventions.md things, and I'm adding auto-version incrementing to the file edits.

code-terse.md (relevant snippet):

# File Header and Version Control
All files following these guidelines should include a header in the following format:

File:

Description:

Version: YYYY-MM-DD-


Version Control Instructions:
1. If any header lines are missing, add them
2. Update the description if necessary
3. Format: YYYY-MM-DD-###
4. When editing any file:
   a. Update YYYY-MM-DD to the current date
   b. Increment the ### portion of the version number

Always update the version number when making changes to the file.

Which results in:

code-terse.md                                                                                                                                                                                                                      
> Create an example of a small python program that complies with code-terse.md                                                                                                                                                     

Certainly! I'll create a small Python program that complies with the guidelines in code-terse.md. I'll use a *SEARCH/REPLACE block* to create a new file called `task_manager.py`.

task_manager.py
<source>python
<<<<<<< SEARCH

=======
# File: task_manager.py
# Description: A simple task management system
# Version: 2024-10-10-001

from typing import List, Dict

Which is exactly what I want. Except when I open the newly created file here are the first few lines:

# Description: A simple task management system
# Version: 2024-10-10-001

from typing import List, Dict

For some unknown reason, it is swallowing the first line, even though it is in the replace block when it creates the file.

I can reliably recreate the problem both with new files and when exiting existing files.

I tried manually adding

# File: To see if it would populate on the next edit, and instead the line disappeared.

Thinking it might be an internal thing where aider is using "# File:" at the top, I changed my header to be _File and still have the same issues.

The directions to the AI are working and the edits appear in SEARCH/REPLACE but they don't make it to the file:

After reviewing the task_manager.py file against the guidelines in code-terse.md, I've identified a few minor improvements we can make to ensure full compliance. Here are the proposed changes:

task_manager.py
<source>python
<<<<<<< SEARCH
# _Description: A simple task management system
# _Version: 2024-10-10-003
=======
# _File: task_manager.py
# _Description: A simple task management system
# _Version: 2024-10-10-004
>>>>>>> REPLACE

Yet the line is missing from the file.

Any ideas?

Version and model info

Aider v0.59.1 Main model: claude-3-5-sonnet-20240620 with diff edit format, prompt cache, infinite output Weak model: claude-3-haiku-20240307 Git repo: .git with 4 files Repo-map: using 1024 tokens, files refresh

5ocworkshop commented 2 weeks ago

I figured out a solution, although I'm not sure exactly why it works. I need to add a blank line to the top of the comment block, so I updated by version control info as follows:

# File Header and Version Control
All files following these guidelines should include a header in the following format:

<comment_start>
<comment start> File: <filename>
<comment_start> Description: <brief description of file purpose>
<comment_start> Version: YYYY-MM-DD-###
<comment_end_if_needed>

Version Control Instructions:
1. Use the appropriate comment syntax for the file type
2. If any header lines are missing, add them
3. Update the description if necessary
4. Format: YYYY-MM-DD-###
5. When editing any file:
   a. Update YYYY-MM-DD to the current date
   b. Increment the ### portion of the version number

Always update the version number when making changes to the file.