Skip to content

Conversation

@understood-the-assignment
Copy link
Contributor

I noticed that Gemini 2.5 Pro kept trying to use insert with insert_line set to -1. This makes sense, because:

  • there is no easy way to append to the end of the file
  • we use -1 to mean "end of file" in other contexts (view_range).

So, let's make -1 do the expected thing!

Copy link
Collaborator

@jamadeo jamadeo left a comment

Choose a reason for hiding this comment

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

I'm not sure I follow

there is no easy way to append to the end of the file

because the tool description does say "the number after which to insert", but if Gemini is trying to do this, we should accommodate. I wonder though, is the Gemini model misinterpreting the index, thinking it's the insert-before?

ambiguous. The entire original string will be replaced with `new_str`.
To use the insert command, you must specify both `insert_line` (the line number after which to insert, 0 for beginning)
To use the insert command, you must specify both `insert_line` (the line number after which to insert, 0 for beginning, -1 for end)
Copy link
Collaborator

Choose a reason for hiding this comment

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

The "correct" way to insert at the end is for the model to pass len(lines). We should still accommodate Gemini but I'd leave this out of the tool description, since the intention is to always use a nonnegative index.

Copy link
Contributor Author

@understood-the-assignment understood-the-assignment Aug 15, 2025

Choose a reason for hiding this comment

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

The "correct" way to insert at the end is for the model to pass len(lines).

This requires that the model knows and keeps track of the exact number of lines in the file, which I think doesn't come "for free", e.g. if the model previously only needed to see the start of the file or some rg results, or if the model modified the file since the last time it looked at it.

In any case, I think appending to a file should be easy for the model to do, but I guess it doesn't have to be using the insert command.

Copy link
Collaborator

Choose a reason for hiding this comment

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

That's a good point and I'm all for making this easier on the model.

@baxen to your knowledge, might this impact the performance of the editor with claude? I know this tool schema closely resembles https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/text-editor-tool#insert . This is a subtle instruction change but would be good to merge with high confidence in no regression.

I noticed that Gemini 2.5 Pro kept trying to use `insert` with
`insert_line` set to -1. This makes sense, because:

- there is no easy way to append to the end of the file
- we use -1 to mean "end of file" in other contexts (`view_range`).

So, let's make -1 do the expected thing!

Signed-off-by: sings-to-bees-on-wednesdays <[email protected]>
ambiguous. The entire original string will be replaced with `new_str`.
To use the insert command, you must specify both `insert_line` (the line number after which to insert, 0 for beginning)
To use the insert command, you must specify both `insert_line` (the line number after which to insert, 0 for beginning, -1 for end)
Copy link
Collaborator

Choose a reason for hiding this comment

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

That's a good point and I'm all for making this easier on the model.

@baxen to your knowledge, might this impact the performance of the editor with claude? I know this tool schema closely resembles https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/text-editor-tool#insert . This is a subtle instruction change but would be good to merge with high confidence in no regression.

@michaelneale
Copy link
Collaborator

agreed - I also noted gpt-oss:20b would do similar things, nice catch

@jamadeo
Copy link
Collaborator

jamadeo commented Aug 20, 2025

Sounds good, let's make it so then

@jamadeo jamadeo merged commit ba0f55d into block:main Aug 20, 2025
9 checks passed
ayax79 pushed a commit to ayax79/goose that referenced this pull request Aug 21, 2025
Signed-off-by: sings-to-bees-on-wednesdays <[email protected]>
Signed-off-by: Jack Wright <[email protected]>
michaelneale added a commit that referenced this pull request Aug 21, 2025
* main:
  docs: add figma tutorial (#4231)
  Add Nix flake for reproducible builds (#4213)
  Enhanced onboarding page visual design (#4156)
  feat: adds mtls to all providers (#2794) (#2799)
  Don't show a confirm dialog for quitting (#4225)
  Fix: Missing smart_approve in CLI /mode help text and error message (#4132)
  Clean up langfuse docs and scripts (#4220)
  feat: add remark-breaks plugin to preserve single newlines in markdown (#4217)
  feat(mcp/developer): accept -1 for insert_line number (#4112)
  Remove dead code and old settings migration (#4180)
  removed tests from lint-staged (#4203)
  docs: openrouter and ollama easy desktop setup (#4195)
  Custom providers update (#4099)
  docs: goose_terminal env var (#4205)
  Desktop alerts when suspicious unicode characters found in Recipe (#4080)
  chore: remove the google drive built-in extension (#4187)
  Move out app init (#4185)
@alexhancock alexhancock mentioned this pull request Aug 22, 2025
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