fix(hashline-edit): stabilize TUI diff metadata and output flow

Align edit/write hashline handling with TUI expectations by preserving metadata through tool execution, keeping unified diff raw to avoid duplicated line numbers, and tightening read/write/edit outputs plus tests for reliable agent operation.
This commit is contained in:
YeonGyu-Kim
2026-02-19 17:09:46 +09:00
parent 52029a0d42
commit 6869a2c0b5
7 changed files with 443 additions and 167 deletions
@@ -113,6 +113,26 @@ describe("createHashlineReadEnhancerHook", () => {
expect(lines[1]).toMatch(/^2:[a-f0-9]{2}\|const y = 2$/)
})
it("should transform numbered write lines even when header lines come first", async () => {
//#given
const hook = createHashlineReadEnhancerHook(mockCtx, createMockConfig(true))
const input = { tool: "write", sessionID, callID: "call-1" }
const output = {
title: "Write",
output: ["# Wrote /tmp/demo-edit.txt", "1: This is line one", "2: This is line two"].join("\n"),
metadata: {},
}
//#when
await hook["tool.execute.after"](input, output)
//#then
const lines = output.output.split("\n")
expect(lines[0]).toBe("# Wrote /tmp/demo-edit.txt")
expect(lines[1]).toMatch(/^1:[a-f0-9]{2}\|This is line one$/)
expect(lines[2]).toMatch(/^2:[a-f0-9]{2}\|This is line two$/)
})
it("should skip non-read tools", async () => {
//#given
const hook = createHashlineReadEnhancerHook(mockCtx, createMockConfig(true))