Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

What is a good tool interface to apply file updates (patches)? #182

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

Closed
georgeu2000 opened this issue May 17, 2025 · 4 comments
Closed

What is a good tool interface to apply file updates (patches)? #182

georgeu2000 opened this issue May 17, 2025 · 4 comments

Comments

@georgeu2000
Copy link

After working with OpenAI API and Claude 3.7 and defining my own tools, it never knows the correct line number (even if I provide the file with line numbers).

Matching lines does not work so well because of duplicates.

Clearly this is a well-solved problem.

What is the best practice to do file updates? Does Ruby LLM handle this?

@db0sch
Copy link

db0sch commented May 17, 2025

I've been working on the same problem.
And yet, the LLM does not know the lines number. Mostly cause the whole thing is a big ball of text, with text before and after (prompts). You can't rely on the line numbers.
What you must do:
Write a tool that takes 3 parameters:

  • file_path
  • old_string
  • new_string

And in the description of the old_string, specify that the old_string must be unique in the text, and to do that, It should take a couple of lines before and couple of lines after what it actually wants to change, to compose the old_string. That way, in your tool, you can simply gsub the original text with the old_string and the new_string. No line numbers. Just text matching.

Does this make sense for you?

PS: and no, RubyLLM does not takes care of this. This is really the job of the internal implementation of your tool :)

@georgeu2000
Copy link
Author

OK, that sounds like it would work. Thanks.

@db0sch
Copy link

db0sch commented May 17, 2025

Just FYI, I've investigated this a bit.
And that's how some file editing MCPs do it, and also, that's how Zed editor agent does it: https://github.com/zed-industries/zed
Also, you should read this blog post :)
https://radanskoric.com/articles/coding-agent-in-ruby

@georgeu2000
Copy link
Author

I read the blog post. That's how I found out about Ruby LLM, haha.

Repository owner locked and limited conversation to collaborators May 18, 2025
@crmne crmne converted this issue into discussion #185 May 18, 2025

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants