Code Engineering
The small-diff alternative to file_write — exact-string replace with a single-match safety rule.
file_editMost agent edits are tiny — fix this line, rename this token here. file_edit makes that the cheap path: send the old slice and the new slice, get a guaranteed targeted change.
WORKSPACE_WRITE permission. Refuses to edit outside the optional projectRoot. Refuses files matching sensitive-content patterns (.env, credentials, secret, password, private_key, .pem, .key, .p12, .jks, .keystore, id_rsa, id_ed25519). Complement to file_write — use file_edit for targeted modifications, file_write for new files or full rewrites.
When a user asks:
In UserService.java, change MAX_RETRIES from 3 to 5.
the agent calls the tool:
file_edit(file="src/main/java/.../UserService.java", old_string="MAX_RETRIES = 3", new_string="MAX_RETRIES = 5")and gets back: 1 replacement in UserService.java (line 42)
Real scenarios where agents put this tool to work.
Implementation lives at swarmai-tools/src/main/java/ai/intelliswarm/swarmai/tool/code/edit/FileEditTool.java in the swarm-ai repository.