When using the Edit tool to create new files (with oldString === ""), the tool writes the newString content exactly as provided without ensuring the file ends with a newline character.
Problem Details
In packages/opencode/src/tool/edit.ts (
|
export const EditTool = Tool.define("edit", { |
), the new file creation path (lines ~55-65) handles the case where params.oldString === "":
if (params.oldString === "") {
const existed = await Filesystem.exists(filePath)
contentNew = params.newString
// ...
await Filesystem.write(filePath, params.newString) // ← No EOF newline handling
Unlike the existing file modification path which preserves line ending behavior through detectLineEnding() and convertToLineEnding(), the new file creation path performs no EOF newline validation or enforcement.
Expected Behavior
When creating new files via the Edit tool, the content should automatically have a trailing newline added if one is not present, ensuring consistency with the project's coding standards.
Current Behavior
New files are created with exactly the content provided in newString, regardless of whether it ends with a newline.
Proposed Solution
Add EOF newline enforcement in the new file creation path, similar to how existing file edits handle line endings:
if (params.oldString === "") {
// ... existing code ...
let contentToWrite = params.newString
if (!contentToWrite.endsWith('\n')) {
contentToWrite += '\n'
}
await Filesystem.write(filePath, contentToWrite)
OpenCode version
1.1.56
Steps to reproduce
Let the edit tool create a new text file
Screenshot and/or share link
No response
Operating System
GNU/Linux Archlinux
Terminal
kitty
When using the Edit tool to create new files (with oldString === ""), the tool writes the newString content exactly as provided without ensuring the file ends with a newline character.
Problem Details
In packages/opencode/src/tool/edit.ts (
opencode/packages/opencode/src/tool/edit.ts
Line 37 in 3c96bf8
Unlike the existing file modification path which preserves line ending behavior through detectLineEnding() and convertToLineEnding(), the new file creation path performs no EOF newline validation or enforcement.
Expected Behavior
When creating new files via the Edit tool, the content should automatically have a trailing newline added if one is not present, ensuring consistency with the project's coding standards.
Current Behavior
New files are created with exactly the content provided in newString, regardless of whether it ends with a newline.
Proposed Solution
Add EOF newline enforcement in the new file creation path, similar to how existing file edits handle line endings:
OpenCode version
1.1.56
Steps to reproduce
Let the edit tool create a new text file
Screenshot and/or share link
No response
Operating System
GNU/Linux Archlinux
Terminal
kitty