feat(diff): hashline anchor comment localization (experimental, opt-in) - #706
Open
adlternative wants to merge 1 commit into
Open
feat(diff): hashline anchor comment localization (experimental, opt-in)#706adlternative wants to merge 1 commit into
adlternative wants to merge 1 commit into
Conversation
|
huzhening.hzn seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
Add an opt-in anchor-based localization path for code_comment, adapted from the hashline protocol (github.com/RimuruW/pi-hashline-edit): - internal/hashline: xxh32 context hashes (prev\0curr\0next -> 2 chars) per line; AnnotateDiff renders new-side diff lines as "LINE#HASH:..."; ResolveSpec strictly verifies anchors against new file content. - resolver: new highest-priority resolveFromAnchor step. Two-factor validation: hash is the checksum, existing_code acts as a text hint that can veto hash collisions. On mismatch it falls back to the existing hunk/file/relocation pipeline, so behavior is never worse than baseline. All paths now record LlmComment.LocMethod. - agent: OCR_HASHLINE_ANCHORS=1 gates anchor annotation of the diff in the main task prompt and injected diff map. - code_comment: parse optional "anchor" parameter; example tools.json with the anchor schema under examples/hashline_anchors. Measured on real commit corpora replayed through the production resolver: existing_code text matching localizes 63-74% (1 line) / 82-93% (3 lines) of added-line comments to the correct line (errors are silent first-match picks); verified anchors localize 100%, with a ~0.5% hash false-accept rate that the text-hint veto further reduces. Diff annotation costs +26% tokens on the diff, offset in end-to-end runs by fewer file_read round-trips (-25% total input tokens in a 5x5 A/B).
adlternative
force-pushed
the
adl/dev/hashline-anchor-localization
branch
from
August 3, 2026 14:08
65d6b35 to
a5da81b
Compare
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.
What
Adds an opt-in, anchor-based comment localization path for
code_comment, adapted from the hashline protocol (RimuruW/pi-hashline-edit).When
OCR_HASHLINE_ANCHORS=1is set, the diff shown to the model renders every new-file line with a short anchor prefix:The anchor hash is computed from the line and its two neighbors (
xxh32(prev\0curr\0next)→ 2 chars), so identical lines in different contexts get different anchors. The model localizes a comment by copying the anchor ("anchor": "42#KT"or a range"42#KT-45#MQ") instead of quoting a code snippet.Why
The current
existing_codetext-matching pipeline resolves ambiguous matches by silently picking the first occurrence. Replaying real commit corpora through the productionResolveComment:existing_code, 1 lineexisting_code, 3 lines41.5% of added lines in the TS corpus are not the first occurrence of their normalized content (imports,
}, boilerplate) — exactly the silent-mislocation surface.How
internal/hashline(new): context hashing, strictResolveSpecverification,AnnotateDiff.resolver.go: new highest-priorityresolveFromAnchorstep with two-factor validation — the hash is the checksum (both endpoints must verify),existing_codeacts as a text hint that can veto hash collisions. On any mismatch it falls back to the existing hunk/file/relocation pipeline, so behavior is never worse than baseline. All resolution paths now recordLlmComment.LocMethod(anchor/hunk/file/relocation/anchor_hint_veto) for observability.agent.go: env-gated annotation of{{diff}}and the injected diff map.examples/hashline_anchors/: anchor-awaretools.json+ usage docs.Cost / risk
file_readround-trips to confirm positions — and output tokens were flat.Testing
go test ./...passes; new unit tests for hashing round-trips, collision behavior, diff annotation, and resolver anchor/veto/fallback paths.