DSH Hub

JohnXu22786/apply-patch

dsh-patch-apply

BundleWorkflow0 GitHub stars· updated 2026-08-20

Apply structured unified diffs (git format) to the real filesystem inside DeepSeek Harness (dsh): multi-file parsing, fuzzy hunk location, all-or-nothing application, dry-run, and reverse-patch undo.

Install

npx @deepseek-ai/dsh plugin --profile <name> add dsh-patch-apply

Restart `dsh web` after install. Bundle APIs can change during the developer preview.

README badge

dsh-patch-apply DSH Hub badge
[![DSH Hub](https://dshhub.dev/badge/apply-patch.svg)](https://dshhub.dev/plugins/apply-patch)

Paste this into your README. The star count updates with every catalog sync.

From the README

Excerpt from JohnXu22786/apply-patch, cleaned of badges and images.

dsh-patch-apply

Apply structured unified diffs (git format) to the real filesystem inside DeepSeek Harness (dsh) — and anywhere else Node runs.

中文文档:README.zh.md

dsh ships string-level edit/write tools but no structured diff-applier that writes to disk. dsh-patch-apply fills that gap: it parses a unified diff, applies every hunk with fuzzy context tolerance and line-offset correction, guards the whole operation so it is all-or-nothing, and records a reverse patch for byte-exact undo.

Zero runtime dependencies. TypeScript sources, plain-object tool definitions, Node's built-in test runner.


Highlights

  • Full git diff coverage — multi-file, multi-hunk, ±/context/add/delete, /dev/null creates & deletes, rename from/to, copy from/to, old mode/new mode, index shas, \ No newline at end of file, binary labels (Binary files … differ, GIT binary patch), quoted paths with spaces. Classic bare ---/+++ patches are accepted too.
  • Self-implemented parser — no heavy dependencies; the parser validates hunk headers against actual body line counts and fails with the precise patch line number on malformed input.
  • Precise hunk location — exact-at-anchor → exact-anywhere (line-offset correction) → fuzzy (leading-context tolerance, GNU-patch style), where deletions can never be fuzzed, so a fuzzy match cannot delete wrong content.
  • All-or-nothing atomicity — every file is parsed and validated in memory before anything is written; any hunk conflict or structural violation means nothing is written.
  • Version guard — uses the identical identity recipe as the official dsh filesystem (dev:ino:size:mtimeNs:ctimeNs, see Version-guard coordination); writes re-check identity at publication time and abort with STALE on drift.
  • Undo everywhere — a reverse patch is computed before mutating and an undo journal is written first; undo restores byte-identical state. Applies to creates, deletes, renames, copies and mode changes too.
  • dry-run — validates applicability statically; reports conflicts (expected vs actual, hunk number, patch line) without touching the disk.
  • CRLF / LF fidelity — files are modelled line-by-line with their own terminators; untouched regions round-trip byte-for-byte, including mixed endings and a missing trailing newline.
  • Binary safety — binary-labelled files are skipped and reported; a text patch aimed at a binary target is detected (NUL bytes / invalid UTF-8) and skipped, never corrupted.

Installation

As a dsh bundle (recommended)

The package is a standard dsh bundle: package.json declares "dsh": { "bundle": { "patch": "./cordis.patch.yml" } }, and the patch inserts one Cordis plugin row whose module exports { name, inject, apply } and registers the four tools on the harness tool registry (ctx.tools).

# published to a registry
dsh plugin --profile <name> add dsh-patch-apply

# straight from this repository
dsh plugin --profile <name> add github:JohnXu22786/apply-patch

# or from a local checkout
dsh plugin --profile <name> add /path/to/apply-patch

Nothing else to configure — the tools patch_apply, patch_dry_run, patch_reverse, patch_stat become available to the model immediately.

Related plugins