git apply --unidiff-zero places an add-only hunk, which has no context to match, at its new-side start line. That line counts every earlier hunk of the diff, so each hunk select() dropped shifted the later add-only hunks down by its size: on the real README a staged node landed in the wrong Mermaid subgraph. renumber() rewrites each kept header from the old start plus the net lines of the hunks kept before it (+1 for a pure insertion, -1 for a pure deletion), with counts that match the kept lines. A new test drops an early hunk and a line of a mixed one and compares the whole staged file; against the previous script it fails with the line one place too low.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>