Documentation
¶
Overview ¶
Package apply_patch implements the unified-diff mutation tool.
Single primitive: takes a unified diff, applies it to the working tree. Creates new files, modifies existing, deletes (when patch wipes content or marks file deleted). Fails loud on context mismatch — no fuzzy retry.
Package apply_patch provides patch application primitives plus the LINE#ID anchor system used to reference specific source lines.
LINE#ID format: "<lineNumber>#<3-char tag>", e.g. "42#VKM". The tag is a deterministic content hash of the (normalized) line. Edits that cite a tag which no longer matches the live content are rejected, which catches stale or hallucinated line numbers before they corrupt files.
Algorithm:
- normalize: strip \r, trim trailing space/tab.
- seed: 0 if the line contains any Unicode letter or digit, else the 1-based line number (so blanks and pure-punctuation lines still vary by position).
- h = xxhash32(normalized, seed); idx = h % 4096.
- tag = alphabet[idx/256] + alphabet[(idx/16)%16] + alphabet[idx%16] using the 16-char set "ZPMQVRWSNKTXJBYH". 4096 buckets cuts the birthday-collision probability ~16x vs the prior 256-bucket space.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewWithFilter ¶
NewWithFilter constructs the apply_patch tool with an optional path regex. When pathRe is nil, all paths are allowed (existing behavior). When pathRe is non-nil, the whole batch is rejected if ANY file path in the patch fails the match — no file is touched on rejection. Paths are matched relative to the current working directory when possible.