Skip to content

chore(tools): Use content-addressed IDs for diff hunks#580

Merged
JeanMertz merged 2 commits intomainfrom
prr146
Apr 28, 2026
Merged

chore(tools): Use content-addressed IDs for diff hunks#580
JeanMertz merged 2 commits intomainfrom
prr146

Conversation

@JeanMertz
Copy link
Copy Markdown
Collaborator

Replace positional integer patch IDs with 12-char SHA1 hex hashes derived from the hunk text itself.

Positional IDs are fragile: staging one hunk removes it from the listing and renumbers every hunk after it. This means a stale ID silently aliases to a different hunk, producing incorrect staging. Content-addressed IDs decouple identity from snapshot ordering — the same logical change always has the same ID, and a staged hunk simply disappears from the next listing rather than shifting its neighbours.

A new hunk module provides hunk_id(), split_hunks(), and diff_header(). list_patches now assigns IDs via hunk_id(); stage_patch and stage_patch_lines look up hunks by ID and fail loudly when a stale or unknown ID is passed, instructing the agent to re-run git_list_patches. Hunks are always emitted in file order when assembling a multi-hunk patch, regardless of the order IDs were requested, satisfying git apply's monotonic-line requirement.

The tool schema and docs for git_stage_patch and git_stage_patch_lines are updated to reflect the new string type for patch IDs, with updated examples using hex strings.

Replace positional integer patch IDs with 12-char SHA1 hex hashes
derived from the hunk text itself.

Positional IDs are fragile: staging one hunk removes it from the listing
and renumbers every hunk after it. This means a stale ID silently
aliases to a different hunk, producing incorrect staging.
Content-addressed IDs decouple identity from snapshot ordering — the
same logical change always has the same ID, and a staged hunk simply
disappears from the next listing rather than shifting its neighbours.

A new `hunk` module provides `hunk_id()`, `split_hunks()`, and
`diff_header()`. `list_patches` now assigns IDs via `hunk_id()`;
`stage_patch` and `stage_patch_lines` look up hunks by ID and fail
loudly when a stale or unknown ID is passed, instructing the agent to
re-run `git_list_patches`. Hunks are always emitted in file order when
assembling a multi-hunk patch, regardless of the order IDs were
requested, satisfying `git apply`'s monotonic-line requirement.

The tool schema and docs for `git_stage_patch` and
`git_stage_patch_lines` are updated to reflect the new `string` type for
patch IDs, with updated examples using hex strings.

Signed-off-by: Jean Mertz <git@jeanmertz.com>
Signed-off-by: Jean Mertz <git@jeanmertz.com>
@JeanMertz JeanMertz merged commit 352142e into main Apr 28, 2026
13 checks passed
@JeanMertz JeanMertz deleted the prr146 branch April 28, 2026 06:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant