fix(hashline-read-enhancer): skip hashifying OpenCode-truncated lines
This commit is contained in:
parent
ac962d62ab
commit
1785313f3b
@ -13,6 +13,7 @@ const CONTENT_OPEN_TAG = "<content>"
|
|||||||
const CONTENT_CLOSE_TAG = "</content>"
|
const CONTENT_CLOSE_TAG = "</content>"
|
||||||
const FILE_OPEN_TAG = "<file>"
|
const FILE_OPEN_TAG = "<file>"
|
||||||
const FILE_CLOSE_TAG = "</file>"
|
const FILE_CLOSE_TAG = "</file>"
|
||||||
|
const OPENCODE_LINE_TRUNCATION_SUFFIX = "... (line truncated to 2000 chars)"
|
||||||
|
|
||||||
function isReadTool(toolName: string): boolean {
|
function isReadTool(toolName: string): boolean {
|
||||||
return toolName.toLowerCase() === "read"
|
return toolName.toLowerCase() === "read"
|
||||||
@ -56,6 +57,9 @@ function transformLine(line: string): string {
|
|||||||
if (!parsed) {
|
if (!parsed) {
|
||||||
return line
|
return line
|
||||||
}
|
}
|
||||||
|
if (parsed.content.endsWith(OPENCODE_LINE_TRUNCATION_SUFFIX)) {
|
||||||
|
return line
|
||||||
|
}
|
||||||
const hash = computeLineHash(parsed.lineNumber, parsed.content)
|
const hash = computeLineHash(parsed.lineNumber, parsed.content)
|
||||||
return `${parsed.lineNumber}#${hash}|${parsed.content}`
|
return `${parsed.lineNumber}#${hash}|${parsed.content}`
|
||||||
}
|
}
|
||||||
|
|||||||
@ -84,6 +84,33 @@ describe("hashline-read-enhancer", () => {
|
|||||||
expect(lines[7]).toBe("</content>")
|
expect(lines[7]).toBe("</content>")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("keeps OpenCode-truncated lines unhashed while hashifying normal lines", async () => {
|
||||||
|
//#given
|
||||||
|
const hook = createHashlineReadEnhancerHook(mockCtx(), { hashline_edit: { enabled: true } })
|
||||||
|
const input = { tool: "read", sessionID: "s", callID: "c" }
|
||||||
|
const truncatedLine = `${"x".repeat(60)}... (line truncated to 2000 chars)`
|
||||||
|
const output = {
|
||||||
|
title: "demo.ts",
|
||||||
|
output: [
|
||||||
|
"<path>/tmp/demo.ts</path>",
|
||||||
|
"<type>file</type>",
|
||||||
|
"<content>",
|
||||||
|
`1: ${truncatedLine}`,
|
||||||
|
"2: normal line",
|
||||||
|
"</content>",
|
||||||
|
].join("\n"),
|
||||||
|
metadata: {},
|
||||||
|
}
|
||||||
|
|
||||||
|
//#when
|
||||||
|
await hook["tool.execute.after"](input, output)
|
||||||
|
|
||||||
|
//#then
|
||||||
|
const lines = output.output.split("\n")
|
||||||
|
expect(lines[3]).toBe(`1: ${truncatedLine}`)
|
||||||
|
expect(lines[4]).toMatch(/^2#[ZPMQVRWSNKTXJBYH]{2}\|normal line$/)
|
||||||
|
})
|
||||||
|
|
||||||
it("hashifies plain read output without content tags", async () => {
|
it("hashifies plain read output without content tags", async () => {
|
||||||
//#given
|
//#given
|
||||||
const hook = createHashlineReadEnhancerHook(mockCtx(), { hashline_edit: { enabled: true } })
|
const hook = createHashlineReadEnhancerHook(mockCtx(), { hashline_edit: { enabled: true } })
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user