# mend

> A multi-format patch utility for AI edits featuring fuzzy matching and atomic writes.

mend is a paid AI agent skill on Agensi by Haiyang Lan, in LLM Ops. It loads into your AI agent through the Agensi MCP server, always in its latest approved version.

- Price: $12 (one-time purchase)
- Creator: [Haiyang Lan](https://www.agensi.io/creators/haiyang-lan)
- Category: [LLM Ops](https://www.agensi.io/skills/llm-ops)
- Version: 1.1
- Last updated: 2026-11-24
- Security: scan passed (2026-11-24); every new listing is also reviewed by a person
- Listing: https://www.agensi.io/skills/mend
- Tags: llm-ops, patching, node-js, diff, automation

## About this skill

Applying AI-generated edits to a codebase often fails due to line number shifts or varying output formats. This skill provides a single, reliable utility to parse and apply patches regardless of how the LLM formatted them. It handles unified diffs, SEARCH/REPLACE blocks, V4A patches, and JSON tool-call edits using a three-tier fuzzy matching system.

### What it does
- **Multi-format parsing** handles unified diffs, SEARCH/REPLACE blocks, V4A patches, and JSON tool-call edits automatically.
- **Fuzzy matching** implements a three-tier logic that falls back from exact matching to whitespace-tolerant and content-anchored strategies.
- **Atomic writes** ensure all-or-nothing execution per edit, preventing half-written files or corrupted states when a patch fails.
- **Validation** prevents directory traversal by refusing absolute paths or `..` references in patch files.
- **Dry run mode** allows for checking patch applicability without committing any changes to the disk.

### How it works
1. Run the utility via Node.js pointing to a patch file or piping content via standard input.
2. Select a format mode using `--format` or let the tool auto-detect the patch style from the source text.
3. Use the `--check` flag to verify if the patch applies cleanly to the current directory.
4. Review the stdout for status codes like `M` for modified, `A` for added, or `D` for deleted files.

### Frameworks & tools
Built for Node.js 22 using only the standard library. It requires no external dependencies and works entirely offline without network access.

### Why this beats prompting it yourself
LLMs frequently hallucinate line numbers or mix patch formats in a single response. This tool provides a deterministic execution layer that recovers from common LLM formatting errors using content-anchored matching that raw `patch` commands often reject.

### Use cases
- Applying SEARCH/REPLACE blocks generated by Claude or GPT-4o.
- Executing JSON-based tool calls for automated refactoring scripts.
- Patching files where the local source has drifted slightly from the LLM's training data or context window.
- Batch processing multiple diffs in CI/CD pipelines.

### Known limitations
Requires Node.js 22. Paths in patches must be relative and strictly contained within the current working directory.

## How to use this skill

1. Connect your AI agent to Agensi once: add the MCP server https://mcp.agensi.io/mcp/auth and sign in with your Agensi account (OAuth, no API key). Steps for Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and other agents: https://www.agensi.io/docs/mcp-setup
2. Ask your agent: "Use the mend skill from Agensi" and describe your task.
3. Buy it on the listing or let your agent ask you first; your agent then loads it from Agensi when it needs it. Every paid skill has a money-back guarantee: https://www.agensi.io/docs/money-back-guarantee

## Frequently asked questions

### How does Mend handle LLM edits that have incorrect line numbers?

Mend solves the "hallucination" problem where LLMs provide valid code but incorrect line numbers or inconsistent diff formats. It uses a three-tier fuzzy matching system to anchor edits to actual file content rather than unreliable line markers.

### Is Mend compatible with specific AI models or agents?

Mend is a standalone Node.js utility that works with any LLM—including Claude, GPT-4o, and Llama—regardless of whether they output unified diffs, SEARCH/REPLACE blocks, or JSON tool calls. It acts as a deterministic execution layer for any agentic workflow.

### What are the system requirements for running this skill?

No external dependencies are required; Mend is built using the Node.js 22 standard library for maximum security and portability. Simply run it via Node.js pointing to your patch file or pipe the LLM output directly into the utility.

### How does the tool prevent an AI from accidentally editing files outside my project?

Mend includes a built-in validation layer that rejects absolute paths and parent directory references (`..`). This ensures that the AI can only modify files within your designated project folder, preventing unauthorized system access.

### What exactly is included in the purchase?

You receive the full source code of the utility, optimized for Node.js 22, along with documentation on integrating it into your existing CI/CD or agent pipelines. The package is designed for immediate use as a CLI tool or a library module.

### Can I test if a patch will work before it actually modifies my files?

Mend features a 'Dry Run' mode (`--check`) that simulates the entire patching process without writing to disk. This allows your agent to verify if a patch is valid before committing any permanent changes to your codebase.

---

Source: [Agensi](https://www.agensi.io), the marketplace of skills for AI agents. Any MCP-compatible agent (Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and more) connects at https://mcp.agensi.io/mcp/auth and signs in with an Agensi account; setup for every agent: https://www.agensi.io/docs/mcp-setup. Append .md to any skill, guide or docs address on agensi.io for its markdown version.
