-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Description
Please explain the motivation behind the feature request.
Files created by the text_editor tool within Goose often lack a trailing newline character. While not a critical failure, this behavior is undesirable for several reasons.
Firstly, it leads to minor but persistent warnings, such as \ No newline at end of file in diff output and similar warnings in GitHub's pull request diff views ⛔. These warnings, though benign, can clutter output and signal non-standard file formatting.
Secondly, and more importantly, some POSIX-compliant tools may exhibit undefined behavior when processing files that do not end with a newline. While many commonly used GNU tools are more lenient, certain commands, like IBM's grep, explicitly require input files to terminate with a newline character (e.g., "Input files must end with the newline character." - IBM docs for grep). Ensuring a trailing newline promotes broader compatibility and robustness across different environments and toolchains.
This feature would improve the consistency and quality of files generated by Goose, aligning them with common best practices and POSIX standards, and eliminating unnecessary warnings.
Describe the solution you'd like
I propose adding a guarantee for a trailing newline character during the string normalization process within the text_editor tool. This would ensure that any file created or modified by text_editor automatically includes a trailing newline, regardless of the LLM's raw output.
Describe alternatives you've considered
One alternative considered is relying on the LLM's output to sometimes include a trailing newline. However, this is not a robust solution as the presence of a trailing newline is not guaranteed across different models or specific outputs. Explicitly handling this at the text_editor tool level provides a more reliable and consistent outcome.
Additional context
This behavior can be reproduced using the following steps:
Run a Goose command that creates a new file:
goose run -t 'write hell world in python'
Inspect the created file:
$ cat hello_world.py
#!/usr/bin/env python3
def main():
print("Hello, World!")
if __name__ == "__main__":
main()%
Note the % character at the end of the cat output, indicating the absence of a trailing newline.
For reference, I was using claude-sonnet-4.
- I have verified this does not duplicate an existing feature request