feat(hashline-edit): add autocorrect, BOM/CRLF normalization, and file creation support
Implements key features from oh-my-pi to improve agent editing success rates: - Autocorrect v1: single-line merge expansion, wrapped line restoration, paired indent restoration (autocorrect-replacement-lines.ts) - BOM/CRLF normalization: canonicalize on read, restore on write (file-text-canonicalization.ts) - Pre-validate all hashes before mutation (edit-ordering.ts) - File creation via append/prepend operations (new types + executor logic) - Modular refactoring: split edit-operations.ts into focused modules (primitives, ordering, deduplication, diff, executor) - Enhanced tool description with operation choice guide and recovery hints All 50 tests pass. TypeScript clean. Build successful.
This commit is contained in:
@@ -246,6 +246,36 @@ describe("hashline edit operations", () => {
|
||||
const result = applyReplaceLines(lines, anchorFor(lines, 2), anchorFor(lines, 3), ["return 3", "return 4"])
|
||||
|
||||
//#then
|
||||
expect(result).toEqual(["if (x) {", " return 3", "return 4", "}"])
|
||||
expect(result).toEqual(["if (x) {", " return 3", " return 4", "}"])
|
||||
})
|
||||
|
||||
it("applies append and prepend operations", () => {
|
||||
//#given
|
||||
const content = "line 1\nline 2"
|
||||
|
||||
//#when
|
||||
const result = applyHashlineEdits(content, [
|
||||
{ type: "append", text: ["line 3"] },
|
||||
{ type: "prepend", text: ["line 0"] },
|
||||
])
|
||||
|
||||
//#then
|
||||
expect(result).toEqual("line 0\nline 1\nline 2\nline 3")
|
||||
})
|
||||
|
||||
it("autocorrects single-line merged replacement into original line count", () => {
|
||||
//#given
|
||||
const lines = ["const a = 1;", "const b = 2;"]
|
||||
|
||||
//#when
|
||||
const result = applyReplaceLines(
|
||||
lines,
|
||||
anchorFor(lines, 1),
|
||||
anchorFor(lines, 2),
|
||||
"const a = 10; const b = 20;"
|
||||
)
|
||||
|
||||
//#then
|
||||
expect(result).toEqual(["const a = 10;", "const b = 20;"])
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user