Skip to content

Enhance EditTool with robust indentation rebasing #19177

@Thomas-Shephard

Description

@Thomas-Shephard

What would you like to be added?

Improve the EditTool indentation logic to intelligently rebase code blocks to match the target file's indentation. This includes handling multi-line replacements, preserving inline suffixes (like comments), and avoiding double-indentation.

Why is this needed?

The EditTool sometimes produces misaligned code when the AI's proposed new_string indentation doesn't perfectly match the file's context. Adding a robust rebasing step makes the tool more reliable and the resulting diffs cleaner.

Additional context

The implementation adds rebaseIndentation and handleTrailingSpaces utilities to the EditTool and integrates them into the exact, flexible, and regex matching paths.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/agentIssues related to Core Agent, Tools, Memory, Sub-Agents, Hooks, Agent Qualitystatus/need-triageIssues that need to be triaged by the triage automation.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions