Skip to content

enhancement: implement edit tool (line-oriented editing) #7

Description

@puremachinery

Context

The current file mutation tools are `write_file` (full overwrite) and `replace` (exact string match replacement). The upstream Node.js CLI also provides an `edit` tool that supports line-range-based editing — inserting, deleting, or replacing specific line ranges.

This is a meaningful gap because:

  • `replace` requires the model to reproduce the exact target string, which is fragile for large blocks
  • `write_file` requires rewriting the entire file for a small change
  • Line-oriented editing is a more natural fit for how models think about code modifications

Proposed change

Implement an `edit` tool in `internal/tools/` that accepts:

  • `file_path`: target file
  • `start_line` / `end_line`: line range to operate on
  • `new_content`: replacement content for that range (empty = delete)
  • `insert_before` or `insert_after`: insert mode (alternative to replace)

The tool should:

  • Register in `internal/tools/registry.go`
  • Use the same approval flow as `write_file` and `replace`
  • Validate line numbers against actual file length
  • Handle edge cases (empty file, single-line file, append at end)

Relevant files

  • `internal/tools/registry.go` — tool registration
  • `internal/tools/replace.go` — existing string-replace tool (pattern to follow)
  • `internal/tools/executor.go` — approval flow

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

    enhancementNew feature or requesttoolsBuilt-in tools (read, write, shell, web)upstream-parityFeature present in the upstream Node.js CLI

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions