Skip to content

Edit tool converts CRLF files to LF #774

Open

Description

@RaphaelFakhri

Editing a file that uses CRLF line endings with the edit tool rewrites the whole file with LF line endings. The tool docstring says the original line ending is restored after replacement, but Path.read_text() reads in universal-newline mode, so \r\n is already \n when detect_line_ending() runs and LF is always chosen.

Reproduction

import asyncio
from pathlib import Path
from tau_coding.tools import create_edit_tool

path = Path("crlf.txt")
path.write_bytes(b"alpha\r\nbeta\r\n")
tool = create_edit_tool(cwd=".")
asyncio.run(tool.execute("call", {"path": "crlf.txt", "edits": [{"oldText": "alpha", "newText": "one"}]}))
print(path.read_bytes())

Expected: b"one\r\nbeta\r\n"

Actual: b"one\nbeta\n"

Impact

Any edit to a CRLF file produces a diff that touches every line. On Windows, Path.write_text() also translates \n to \r\n on write, so the restore step could produce \r\r\n once detection works.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions