refactor(hashline-edit): redesign hashline format with CID-based hashing

Breaking Changes:
- Change hashline format from 'lineNum:hex|content' to 'lineNum#CID:content'
- Replace hex-based hashing (00-ff) with CID-based hashing (ZPMQVRWSNKTXJBYH nibbles)
- Simplify constants: HASH_DICT → NIBBLE_STR + HASHLINE_DICT
- Update patterns: HASHLINE_PATTERN → HASHLINE_REF_PATTERN + HASHLINE_OUTPUT_PATTERN

Benefits:
- More compact and memorable CID identifiers
- Better alignment with LSP line reference format (lineNum#ID)
- Improved error messages and diff metadata clarity
- Remove unused toHashlineContent from diff-enhancer hook

Updates:
- Refactor hash-computation for CID generation
- Update all diff-utils to use new format
- Update hook to use raw content instead of hashline format
- Update tests to match new expectations

🤖 Generated with assistance of [OhMyOpenCode](https://github.com/code-yeongyu/oh-my-opencode)
This commit is contained in:
YeonGyu-Kim
2026-02-20 11:07:42 +09:00
parent f4aeee18a4
commit b8a6f10f70
8 changed files with 45 additions and 149 deletions
@@ -1,5 +1,5 @@
import { log } from "../../shared"
import { toHashlineContent, generateUnifiedDiff, countLineDiffs } from "../../tools/hashline-edit/diff-utils"
import { generateUnifiedDiff, countLineDiffs } from "../../tools/hashline-edit/diff-utils"
interface HashlineEditDiffEnhancerConfig {
hashline_edit?: { enabled: boolean }
@@ -86,16 +86,13 @@ export function createHashlineEditDiffEnhancerHook(config: HashlineEditDiffEnhan
}
const { additions, deletions } = countLineDiffs(oldContent, newContent)
const oldHashlined = toHashlineContent(oldContent)
const newHashlined = toHashlineContent(newContent)
const unifiedDiff = generateUnifiedDiff(oldContent, newContent, filePath)
output.metadata.filediff = {
file: filePath,
path: filePath,
before: oldHashlined,
after: newHashlined,
before: oldContent,
after: newContent,
additions,
deletions,
}
@@ -88,8 +88,8 @@ describe("hashline-edit-diff-enhancer", () => {
expect(filediff).toBeDefined()
expect(filediff.file).toBe(tmpFile)
expect(filediff.path).toBe(tmpFile)
expect(filediff.before).toMatch(/^\d+:[a-f0-9]{2}\|/)
expect(filediff.after).toMatch(/^\d+:[a-f0-9]{2}\|/)
expect(filediff.before).toBe(oldContent)
expect(filediff.after).toBe(newContent)
expect(filediff.additions).toBeGreaterThan(0)
expect(filediff.deletions).toBeGreaterThan(0)
@@ -163,7 +163,7 @@ describe("hashline-edit-diff-enhancer", () => {
const filediff = afterOutput.metadata.filediff as FileDiffMetadata
expect(filediff).toBeDefined()
expect(filediff.before).toBe("")
expect(filediff.after).toMatch(/^1:[a-f0-9]{2}\|new content/)
expect(filediff.after).toBe("new content\n")
expect(filediff.additions).toBeGreaterThan(0)
expect(filediff.deletions).toBe(0)
@@ -246,8 +246,8 @@ describe("hashline-edit-diff-enhancer", () => {
})
})
describe("hashline format in filediff", () => {
test("filediff.before and filediff.after are in hashline format", async () => {
describe("raw content in filediff", () => {
test("filediff.before and filediff.after are raw file content", async () => {
//#given - a temp file
const tmpDir = (await import("os")).tmpdir()
const tmpFile = `${tmpDir}/hashline-diff-format-${Date.now()}.ts`
@@ -264,17 +264,10 @@ describe("hashline-edit-diff-enhancer", () => {
const afterOutput = makeAfterOutput()
await hook["tool.execute.after"](input, afterOutput)
//#then - before and after should be in LINE:HASH|content format
//#then - before and after should be raw file content
const filediff = afterOutput.metadata.filediff as { before: string; after: string }
const beforeLines = filediff.before.split("\n").filter(Boolean)
const afterLines = filediff.after.split("\n").filter(Boolean)
for (const line of beforeLines) {
expect(line).toMatch(/^\d+:[a-f0-9]{2}\|/)
}
for (const line of afterLines) {
expect(line).toMatch(/^\d+:[a-f0-9]{2}\|/)
}
expect(filediff.before).toBe(oldContent)
expect(filediff.after).toBe(newContent)
await (await import("fs/promises")).unlink(tmpFile).catch(() => {})
})