fix(hashline): accept legacy hashes for indented anchors

Keep persisted LINE#ID anchors working after strict whitespace hashing by falling back to the legacy hash for validation-only lookups.

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
YeonGyu-Kim
2026-03-14 13:42:17 +09:00
parent f03de4f8a8
commit bbd2e86499
4 changed files with 43 additions and 11 deletions
+10 -2
View File
@@ -3,14 +3,22 @@ import { createHashlineChunkFormatter } from "./hashline-chunk-formatter"
const RE_SIGNIFICANT = /[\p{L}\p{N}]/u
export function computeLineHash(lineNumber: number, content: string): string {
const stripped = content.replace(/\r/g, "").trimEnd()
function computeNormalizedLineHash(lineNumber: number, normalizedContent: string): string {
const stripped = normalizedContent
const seed = RE_SIGNIFICANT.test(stripped) ? 0 : lineNumber
const hash = Bun.hash.xxHash32(stripped, seed)
const index = hash % 256
return HASHLINE_DICT[index]
}
export function computeLineHash(lineNumber: number, content: string): string {
return computeNormalizedLineHash(lineNumber, content.replace(/\r/g, "").trimEnd())
}
export function computeLegacyLineHash(lineNumber: number, content: string): string {
return computeNormalizedLineHash(lineNumber, content.replace(/\r/g, "").trim())
}
export function formatHashLine(lineNumber: number, content: string): string {
const hash = computeLineHash(lineNumber, content)
return `${lineNumber}#${hash}|${content}`