u/Character-Chicken522

▲ 3 r/devops

**TL;DR:** `fedit` is a small Go CLI that does line-addressable file edits (show / insert / delete / replace / replaceall / map / find / insertafter / insertbefore / write). It also ships an **MCP server** so Claude/Cursor/etc. can call the same ops as tools instead of regenerating whole files. MIT, single binary, no deps. Repo: https://github.com/amalexico/fedit

---

### Why this exists

Like a lot of you, I've been letting LLMs touch my configs — Terraform modules, Helm values, nginx blocks, GitHub Actions workflows, Ansible playbooks. The failure mode is always the same:

- I ask for a 3-line change in a 400-line file.

- The model rewrites the whole file.

- Two unrelated keys get reordered, a comment vanishes, an indent flips from 2→4 spaces somewhere on line 217, and a heredoc gets "helpfully" reformatted.

- `terraform plan` now wants to recreate half my infra. Cool.

The root cause: text generation is non-deterministic and whole-file rewrites have no surgical primitives. So I gave the model surgical primitives.

### What fedit does

Ten operations, all addressable by line number **or** by content match:

```

show Display lines (whole file or range)

insert Insert after line N

delete Delete line N or range

replace Replace line range

replaceall Global find-and-replace

write Overwrite file

map Structural overview (functions/classes/blocks)

find Find lines matching substring

insertafter Insert after a matching line ← preferred

insertbefore Insert before a matching line ← preferred

```

`map` understands 17 languages: Go, HTML, SQL, Python, JS, TS, CSS, Rust, Java, C#, YAML, TOML, Markdown, Ruby, PHP, Dockerfile, Makefile. So an agent can ask "where's the `resource "aws_s3_bucket"` block?" and get an answer without reading the whole file into context.

Every mutation supports `-v` which prints a `=== STATS ===` block (op, file, match, line delta, elapsed) so the agent can verify its own edit landed.

### Demo (4-op workflow)

![demo](https://raw.githubusercontent.com/amalexico/fedit/main/demo.gif)

Recorded with vhs — `demo.tape` is in the repo if you want to reproduce it.

### MCP server mode

`fedit mcp` starts a JSON-RPC 2.0 server on stdin/stdout exposing all 10 ops as MCP tools (`fedit_show`, `fedit_insertafter`, `fedit_replaceall`, etc.). Drop it in your Claude Desktop / Cursor / Continue config and the model edits files through tool calls instead of regenerating them.

There's also a `SKILL.md` (Anthropic Agent Skills format) in the repo so Claude picks up the usage conventions automatically.

### Benchmark

I ran the same 7 editing tasks (T1–T7: insert middleware, delete dead handler, rename across file, swap a YAML key, etc.) across **Claude, ChatGPT, and Gemini**, comparing free-form whole-file edits vs. fedit-mediated edits. Full table is in the README. Short version: free-form rewrites silently corrupted unrelated lines on 4–6 of 7 tasks depending on the model; fedit-mediated edits were byte-exact on all 7 across all three.

Not claiming this is rigorous science — it's a reproducible smoke test. Tape is in the repo, run it yourself.

### Install

```bash

go install github.com/amalexico/fedit@latest

```

Single binary, no runtime deps, MIT license.

### What I'd love feedback on

  1. Op set — anything missing for your IaC / config workflows? (someone in r/golang asked for `swap-lines`, considering it)

  2. The `map` language list — what should I add? Thinking HCL/Terraform next, given the audience here.

  3. MCP tool schemas — if you've wired this kind of thing into an agent before, am I exposing the right surface area?

---

*Disclosure: I used LLM assistance writing parts of fedit and this post. The benchmark, tape, and code are mine and reproducible from the repo.*

u/Character-Chicken522 — 20 days ago
▲ 5 r/golang

I needed a way to make precise, scriptable file edits without sed/awk regex headaches — especially when working with AI coding assistants that say "insert this after line 47" but the file has shifted.

So I built fedit — a single Go binary with zero dependencies.

What it does:

  • 11 operations: show, find, insert, insertafter, insertbefore, replace, replaceall, delete, write, map
  • Content-based matching: insertafter -match "server {" finds the right spot regardless of line numbers
  • 17 language mappers: map -lang go shows all functions, types, imports at a glance. Also supports Python, Rust, Java, TypeScript, SQL, YAML, TOML, HTML, CSS, and more
  • -v flag: verify every mutation — see exactly what changed before moving on
  • -nth flag: target the 1st, 2nd, or last occurrence of a match

Install:

go install github.com/amalexico/fedit@latest

Example workflow:

fedit -file main.go -op map -lang go          # see structure
fedit -file main.go -op find -match "TODO"     # find all TODOs
fedit -file config.yaml -op replaceall -match "v1.1" -text "v1.2" -v

It's ~1600 lines of pure stdlib Go. No third-party imports. MIT licensed.

GitHub: github.com/amalexico/fedit

Built this as a side tool while working on a larger project (Amalex Handler — a self-hosted file transfer platform, also in Go). fedit turned out to be useful enough on its own that I cleaned it up and open-sourced it.

Happy to answer questions about the implementation. The mappers use simple line-by-line regex — no AST parsing — which keeps it fast and portable.

reddit.com
u/Character-Chicken522 — 24 days ago