feat(coding-agent): redesigned hashline edit API with discriminated unions and improved hash algorithm

- Redesigned hashline edit API to use discriminated union variants (replaceLine, replaceLines, insertAfter, insertBefore, substr) instead of nested src/dst structure.
- Changed hash algorithm from xxHash64 hex to xxHash32 base36 encoding and increased hash length from 2 to 3 characters.
- Added substr edit variant to match and replace content by unique substring when line hashes are unavailable.
- Implemented line relocation heuristics to resolve stale line references when hash uniquely identifies a moved line.
- Moved substr needle search from edit application phase to pre-validation phase for earlier error detection.
- Migrated hashline edit type definitions from manual TypeScript interfaces to schema-derived types using Static<typeof schema> pattern.
This commit is contained in:
can1357
2026-02-11 08:12:08 +01:00
parent bf9ee97d22
commit 269f7de483
10 changed files with 408 additions and 277 deletions
+2 -1
View File
@@ -9,8 +9,9 @@ import { resolveToCwd } from "../tools/path-utils";
import { previewPatch } from "./applicator";
import { DEFAULT_FUZZY_THRESHOLD, findMatch } from "./fuzzy";
import { applyHashlineEdits } from "./hashline";
import type { HashlineEdit } from "./index";
import { adjustIndentation, normalizeToLF, stripBom } from "./normalize";
import type { DiffError, DiffResult, HashlineEdit, PatchInput } from "./types";
import type { DiffError, DiffResult, PatchInput } from "./types";
import { EditMatchError } from "./types";
// ═══════════════════════════════════════════════════════════════════════════