20. Deep Read: FileEditTool

What FileEditTool Shows

FileEditTool is where safe code modification becomes concrete. It validates old/new strings, checks deny rules, guards against giant files, normalizes paths, tracks file history, integrates with diagnostics and LSP state, and records diffs for the wider session.

Why This Is Worth Studying

  • It makes file modification a structured operation rather than raw write access.
  • It tries to preserve context such as line endings and existing file structure.
  • It turns edit operations into auditable, UI-visible, analytics-visible events.
  • It enforces permission checks before the edit path proceeds.

Main Lesson

The best agent editing tools are not “write text to file.” They are transactional editing pipelines that validate intent, protect boundaries, and preserve enough structure for the rest of the system to stay coherent.

Source Navigation

Recommended Source Files

  • source/tools/FileEditTool/FileEditTool.ts
  • source/tools/FileEditTool/utils.ts
  • source/tools/FileEditTool/types.ts
  • source/tools/BashTool/readOnlyValidation.ts
  • source/services/tools/toolExecution.ts

Next Files to Read

  • source/tools/FileReadTool/FileReadTool.ts
  • source/tools/BashTool/pathValidation.ts
  • source/services/compact/postCompactCleanup.ts