4ea76365cd
Move the hash-anchored edit core (hash computation, validation, edit operations, text normalization, chunk formatter, diff utilities, and a runtime-aware xxHash32 binding) into a new @oh-my-opencode/hashline-core workspace package. The src/tools/hashline-edit/ surface becomes a set of thin re-export shims, so existing import paths in the plugin keep working while the pure logic lives behind a stable package boundary that has no opencode runtime dependencies. Tests: bun test packages/hashline-core src/tools/hashline-edit
32 lines
948 B
TypeScript
32 lines
948 B
TypeScript
import { computeLineHash } from "./hash-computation"
|
|
|
|
export function generateHashlineDiff(oldContent: string, newContent: string, filePath: string): string {
|
|
const oldLines = oldContent.split("\n")
|
|
const newLines = newContent.split("\n")
|
|
|
|
const parts: string[] = [`--- ${filePath}\n+++ ${filePath}\n`]
|
|
const maxLines = Math.max(oldLines.length, newLines.length)
|
|
|
|
for (let i = 0; i < maxLines; i += 1) {
|
|
const oldLine = oldLines[i] ?? ""
|
|
const newLine = newLines[i] ?? ""
|
|
const lineNum = i + 1
|
|
const hash = computeLineHash(lineNum, newLine)
|
|
|
|
if (i >= oldLines.length) {
|
|
parts.push(`+ ${lineNum}#${hash}|${newLine}\n`)
|
|
continue
|
|
}
|
|
if (i >= newLines.length) {
|
|
parts.push(`- ${lineNum}# |${oldLine}\n`)
|
|
continue
|
|
}
|
|
if (oldLine !== newLine) {
|
|
parts.push(`- ${lineNum}# |${oldLine}\n`)
|
|
parts.push(`+ ${lineNum}#${hash}|${newLine}\n`)
|
|
}
|
|
}
|
|
|
|
return parts.join("")
|
|
}
|