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:
@@ -52,6 +52,14 @@ function transformOutput(output: string): string {
|
||||
return result.join("\n")
|
||||
}
|
||||
|
||||
function transformWriteOutput(output: string): string {
|
||||
if (!output) {
|
||||
return output
|
||||
}
|
||||
const lines = output.split("\n")
|
||||
return lines.map((line) => (READ_LINE_PATTERN.test(line) ? transformLine(line) : line)).join("\n")
|
||||
}
|
||||
|
||||
export function createHashlineReadEnhancerHook(
|
||||
_ctx: PluginInput,
|
||||
config: HashlineReadEnhancerConfig
|
||||
@@ -70,7 +78,7 @@ export function createHashlineReadEnhancerHook(
|
||||
if (!shouldProcess(config)) {
|
||||
return
|
||||
}
|
||||
output.output = transformOutput(output.output)
|
||||
output.output = input.tool.toLowerCase() === "write" ? transformWriteOutput(output.output) : transformOutput(output.output)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user