-
Notifications
You must be signed in to change notification settings - Fork 22
insert after tool: followups from Nikola's review #157
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request includes several follow-up changes from a previous review, such as improving input validation by using NonEmptyString and refining tool descriptions. While these are positive changes, a critical issue has been introduced by removing a validation check in the InsertAfterSubstringTool. This removal causes the tool to fail silently if the target substring is not found in the file, which is a regression and also breaks an existing unit test. My review includes a high-severity comment to restore this check. I have also included a medium-severity suggestion to improve consistency in how tool descriptions are formatted.
| if not tool_input.insert_after_substring: | ||
| raise ToolError("No insertion was done because the specified substring wasn't provided") | ||
| try: | ||
| content = await asyncio.to_thread(tool_input.file.read_text) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing the check for the substring's existence introduces a silent failure. If insert_after_substring is not found in the file content, content.replace(...) will do nothing, and the file will be overwritten with its original content. The tool will report success, which is misleading for the user as no insertion happened.
This change also appears to break the test_insert_after_substring_missing unit test, which specifically checks for a ToolError in this scenario. Please restore the check to ensure the tool provides accurate feedback.
content = await asyncio.to_thread(tool_input.file.read_text)
if tool_input.insert_after_substring not in content:
raise ToolError("No insertion was done because the specified substring wasn't present")There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
whoops
| description = """ | ||
| Inserts the provided text new_string on a new line after the first | ||
| occurrence of the specified substring insert_after_substring. The insertion | ||
| Inserts the provided text `new_string` on a new line after the first | ||
| occurrence of the specified substring `insert_after_substring`. The insertion | ||
| happens only once. | ||
| """ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For consistency with other tools in this file (like InsertTool, which was changed in this PR to have a single-line description), it would be better to make this multi-line description a single-line string as well.
description = "Inserts the provided text `new_string` on a new line after the first occurrence of the specified substring `insert_after_substring`. The insertion happens only once."Signed-off-by: Tomas Tomecek <[email protected]> Assisted-by: Cursor(Claude)
5ddc51f to
f6398f9
Compare
|
/gemini review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request follows up on a previous review, introducing several good improvements. The use of NonEmptyString for validating tool inputs is a great change, making the code cleaner by allowing the removal of redundant manual checks. The descriptions for tools have also been updated for better clarity. I have one minor suggestion regarding the formatting of a multi-line description string to improve consistency and maintainability.
| description = """ | ||
| Inserts the provided text new_string on a new line after the first | ||
| occurrence of the specified substring insert_after_substring. The insertion | ||
| Inserts the provided text `new_string` on a new line after the first | ||
| occurrence of the specified substring `insert_after_substring`. The insertion | ||
| happens only once. | ||
| """ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To improve consistency and avoid potential whitespace issues with triple-quoted strings, it's better to define this long description using implicit string concatenation inside parentheses. This is a common Python idiom for long strings and aligns with the style of other descriptions in the file.
| description = """ | |
| Inserts the provided text new_string on a new line after the first | |
| occurrence of the specified substring insert_after_substring. The insertion | |
| Inserts the provided text `new_string` on a new line after the first | |
| occurrence of the specified substring `insert_after_substring`. The insertion | |
| happens only once. | |
| """ | |
| description = ( | |
| "Inserts the provided text `new_string` on a new line after the first " | |
| "occurrence of the specified substring `insert_after_substring`. The insertion " | |
| "happens only once." | |
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think the extra whitespace matters.
No description provided.