Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add rename file action #46

Merged
merged 8 commits into from
Sep 12, 2023
Merged

Add rename file action #46

merged 8 commits into from
Sep 12, 2023

Conversation

PCSwingle
Copy link
Member

No description provided.

Copy link
Member

@biobootloader biobootloader left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

I tried it out to see what would happen if I asked for a change and a rename in the same file, and I end up not seeing the rename change at all? See result and log below. In this case what I think we should do is display "Rename x.py -> y.py" above the list of changes (if any) for that file (aka, that would replace the usual line showing which file is being changed above other changes).

image image

@PCSwingle
Copy link
Member Author

The model hasn't given the rename file action by the time we've streamed the file name for the previous response; additionally, since the model's responses are applied in order, I think it's best to keep the change files the same as they are. I'm going to fix it to print the rename file action, but not change the other actions at all.

@biobootloader
Copy link
Member

@PCSwingle

The model hasn't given the rename file action by the time we've streamed the file name for the previous response

ah...

additionally, since the model's responses are applied in order

within a file we sort changes, but you mean the order that we change files?

@biobootloader
Copy link
Member

I tried running this again and it still doesn't show me the rename? And then I applied all changes and it crashed after deleting the file (but not making a new one):

image image

@PCSwingle PCSwingle force-pushed the add-rename-file branch 2 times, most recently from bc66ef6 to 91aa136 Compare August 26, 2023 18:53
@PCSwingle
Copy link
Member Author

PCSwingle commented Aug 26, 2023

Just tried your prompt and it worked? Maybe it got fixed when I rebased on main (since there were a lot of path changes and things that I had to change) or I fixed it a few weeks ago and forgot. If you have the logs from that run still though I can see if I can reproduce it.

Copy link
Member

@biobootloader biobootloader left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works for me now! Ready to merge after fixing conflict

…de removing rename files, printing rename file changes, and add a test
@PCSwingle
Copy link
Member Author

@waydegg just finished fixing merge conflicts; would love to get your feedback on this PR before I merge it!

@@ -205,8 +205,16 @@ def user_filter_changes(
indices = []
for index, change in enumerate(code_changes, start=1):
print_change(change)
# Allowing the user to remove rename file changes introduces a lot of edge cases
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What edge cases have you discovered/thought about so far?

One that comes to mind is a file being renamed and imports not being updated accordingly.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking more edge cases in how we handle it; the big one being that if we don't rename the file, then any changes the model suggests that try to change the renamed file will be trying to change a non-existent file. It gets worse if the model is renaming multiple files to similar names, or one file twice, and so on.

Copy link
Contributor

@waydegg waydegg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a few comments but I don't think there's anything preventing these changes to be merged. The updated system prompt seems to hold up pretty well for complex instructions I've thrown at it form just manually testing so great work!

@@ -86,7 +86,7 @@ def _get_files(
files = {}
for file in files_direct:
if file.path not in excluded_files | excluded_files_from_dir:
files[file.path] = file
files[Path(os.path.realpath(file.path))] = file
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the thinking for using realpath here? Are there issues with using symbolic links?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or did you mean to use relpath instead?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well the real reason was because we were actually just putting a relative Path in there (when it was supposed to be an absolute path!); but yeah, the reason I use realpath instead of abspath is because of symlinks

Comment on lines +88 to 91
abs_path = self.config.git_root / delete_change.file
if not abs_path.exists():
logging.error(f"Path {abs_path} non-existent on delete")
return
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of using self.config.git_root / delete_change.file we can use os.path.abspath(delete_change.file) to handle deletes for files outside of a repo. I know we already have this behavior in the main branch but I just noticed it lol. Pretty sure we're assuming all files are under a git repo across Mentat so it might be better to address this separately.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is actually necessary; abspath appends the CWD to the beginning of the path, which might not necessarily be the current git repo (it could be a subdirectory). This does remind me though, I don't think we have any tests where we run mentat from a subdiretory of the git repo it's actually in; we should probably think about adding some of those!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we have any tests where we run mentat from a subdiretory of the git repo it's actually in; we should probably think about adding some of those!

@PCSwingle can you add an issue for this

@PCSwingle PCSwingle merged commit 705d65b into main Sep 12, 2023
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants