Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
hunkmodule provideshunk_id(),split_hunks(), anddiff_header().list_patchesnow assigns IDs viahunk_id();stage_patchandstage_patch_lineslook up hunks by ID and fail loudly when a stale or unknown ID is passed, instructing the agent to re-rungit_list_patches. Hunks are always emitted in file order when assembling a multi-hunk patch, regardless of the order IDs were requested, satisfyinggit apply's monotonic-line requirement.The tool schema and docs for
git_stage_patchandgit_stage_patch_linesare updated to reflect the newstringtype for patch IDs, with updated examples using hex strings.