AI Agent Hub
Back to plugins
⚙️

apply-patch

Workflow Updated 2026.08.25

Run the following command in DeepSeek Harness:

dsh plugin install JohnXu22786/apply-patch

Paste the following prompt into your AI chat to install this plugin:

Run dsh plugin install JohnXu22786/apply-patch inside DeepSeek Harness to install this plugin; full source at https://github.com/JohnXu22786/apply-patch .

About this plugin

DeepSeek Harness ships string-level edit and write tools, yet it has long lacked a structured diff-applier that commits git-format unified patches to the real filesystem. apply-patch closes that gap with a self-contained, zero-dependency parser that understands every block a git diff can produce: multi-file and multi-hunk payloads, adds, deletes, renames, copies, old/new modes, index SHAs, /dev/null creates and deletes, binary labels, quoted paths with spaces, and the classic bare ---/+++ form. Each hunk header is validated against its actual body line counts during a single parse pass, so a truncated or corrupted patch fails immediately with the exact offending line number rather than misapplying silently.

The write path is strictly all-or-nothing. Every file is parsed, read, and transformed in memory first; any hunk conflict or structural violation rejects the entire patch before a single byte touches disk. Hunk location works in three escalating tiers: exact match at the anchor, exact match elsewhere with line-offset correction, and a GNU-patch-style fuzzy match that drops only leading context lines while requiring deletions to match exactly, so no fuzzy path can ever delete the wrong content. Before each guarded write the file identity is re-probed using the same recipe the official dsh filesystem uses, and any drift aborts with STALE and rolls back. The reverse patch and undo journal are written before the first mutation, guaranteeing a byte-exact restoration path even for creates, deletes, renames, copies, and permission changes.

The plugin exposes four tools directly on the harness registry: patch_apply for atomic application with undo journaling, patch_dry_run for static conflict reporting without touching the disk, patch_reverse for generating a validated reverse patch, and patch_stat for summarising file, hunk, and line counts. If your dsh workflow regularly consumes git format-patch output, CI-produced unified diffs, or hand-rolled multi-file patches targeting mixed CRLF and LF files, paths with spaces, or binary-labelled targets, apply-patch gives you a single, dependency-free step from diff text to verified filesystem state.

Use Cases

  • Apply CI-generated unified diffs to a local codebase atomically within a dsh workflow
  • Commit multi-file model-generated patches to disk without breaking byte-level fidelity of mixed CRLF/LF files
  • Pre-validate a git format-patch for applicability, reporting conflicts without touching the filesystem

Best For

  • Workflow builders who routinely consume git diff output inside dsh
  • Engineering teams requiring a zero-dependency, auditable patch-application pipeline
  • Developers working with mixed CRLF/LF encodings, binary labels, or paths containing spaces