I’ve spent hours and days trying to make a simple-as-possible tool for gemini-3-flash-preview to be able to edit text files using surgical line edits with this approach.
When i load a text file i prepend the line numbers so each line is like
1 | First Line
2 | Second Line
Then on the tool ‘editTextResource’ i have 3 parameters
Lines to be deleted: (from-to)
Lines to be inserted: (insertAt + newContent)
Lines to be replaced: [from-to] newContent
The prependign of line numbers is not a problem as gemini can easily see whats a line number and what is the content of the file.
The problem is that very very often, it gets the line numbers wrong or that instead of replacing the one line that needs changing, it tries to replace the entire block around the line that needs replacing
I also have a “findAndReplace” tool but it also fails sometimes becaues if the block to replace is too big, gemini can get like one character wrong and the ‘find’ part fails.
Has anybody succeeded in implementing such a tool that can edit a file without having to write the entire file?