Coccinelle
$ spatch Community Low RiskCoccinelle (spatch) matches and transforms C code using Semantic Patch Language (SmPL) rules rather than fragile text regexes, widely used in the Linux kernel. By default spatch performs a safe dry-run printing unified diffs to stdout unless --in-place is explicitly passed.
brew install coccinelle spatch parses and diffs large C trees locally; there is no reason to wrap SmPL execution in an MCP server.
Agent-Readiness Checklist
Static evaluation (not yet probed on this host). Run npm run data:probe locally to capture live verification.
FCRS-1.0 6-Dimension Breakdown
Non-interactive, defaults to dry-run unified diffs, and supports --very-quiet and --mode report, though it lacks --json output.
- Defaults to read-only diff stdout;
--very-quietsuppresses progress noise - Outputs unified diff or text reports, not JSON
Safe by default: never touches files on disk unless --in-place is explicitly supplied.
- Read-only dry-run is the default behavior
Available via brew install coccinelle, Linux distro packages, and opam, though Windows requires WSL/Cygwin and OCaml toolchain builds are heavy.
- Primarily macOS and Linux; limited native Windows support
Gold-standard C AST/control-flow refactoring engine capable of transformations impossible with regex.
- Battle-tested across Linux kernel
coccicheckrules
Maintained by the Inria research team and Linux kernel contributors under GPL-2.0.
- Long-term academic and kernel maintenance
Detailed SmPL grammar docs, tutorials, and spatch(1) man page.
- Official documentation and kernel
scripts/coccinelleexamples
Security, Auth & Guardrails
None required; operates strictly on local C source files and .cocci scripts.
100% free, offline, and open-source (GPL-2.0).
# Coccinelle (spatch) Agent Rules - `spatch` defaults to read-only diff output; pass `--very-quiet` to suppress banner noise. - Only add `--in-place` after inspecting the unified diff output on target `.c`/`.h` files.
Agent-Ready Command Recipes
Safe Read-Only Queries
spatch --very-quiet --sp-file rule.cocci --dir src/
Evaluates rule.cocci across src/ and prints unified diffs to stdout without modifying files.
spatch --very-quiet -D report --sp-file check.cocci --dir src/
Emits file:line:col diagnostic findings using the virtual report rule.
Controlled Writes & Previews
spatch --very-quiet --in-place --sp-file rule.cocci --dir src/
Writes the reviewed SmPL transformation directly to matched C files (--in-place).
Strengths for Agents
- + Safe read-only unified diff output by default (
--in-placerequired to mutate files). - + Understands C control flow, types, and macros far better than text-based tools.
Caveats & Pitfalls
- ! Only targets C code and requires writing
.cocciSmPL semantic patch scripts. - ! Lacks
--jsonoutput and native Windows support.