fix(hashline-read-enhancer): simplify write tool output to line count summary

Replace full hashlined file content in write tool response with a simple
'File written successfully. N lines written.' summary to reduce context
bloat.
This commit is contained in:
minpeter 2026-02-24 15:58:36 +09:00
parent 2aeb96c3f6
commit c6a69899d8
2 changed files with 7 additions and 11 deletions

View File

@ -1,6 +1,5 @@
import type { PluginInput } from "@opencode-ai/plugin" import type { PluginInput } from "@opencode-ai/plugin"
import { computeLineHash } from "../../tools/hashline-edit/hash-computation" import { computeLineHash } from "../../tools/hashline-edit/hash-computation"
import { toHashlineContent } from "../../tools/hashline-edit/diff-utils"
interface HashlineReadEnhancerConfig { interface HashlineReadEnhancerConfig {
hashline_edit?: { enabled: boolean } hashline_edit?: { enabled: boolean }
@ -137,10 +136,6 @@ function extractFilePath(metadata: unknown): string | undefined {
} }
async function appendWriteHashlineOutput(output: { output: string; metadata: unknown }): Promise<void> { async function appendWriteHashlineOutput(output: { output: string; metadata: unknown }): Promise<void> {
if (output.output.includes("Updated file (LINE#ID|content):")) {
return
}
const filePath = extractFilePath(output.metadata) const filePath = extractFilePath(output.metadata)
if (!filePath) { if (!filePath) {
return return
@ -152,8 +147,8 @@ async function appendWriteHashlineOutput(output: { output: string; metadata: unk
} }
const content = await file.text() const content = await file.text()
const hashlined = toHashlineContent(content) const lineCount = content === "" ? 0 : content.split("\n").length
output.output = `${output.output}\n\nUpdated file (LINE#ID|content):\n${hashlined}` output.output = `File written successfully. ${lineCount} lines written.`
} }
export function createHashlineReadEnhancerHook( export function createHashlineReadEnhancerHook(

View File

@ -164,7 +164,7 @@ describe("hashline-read-enhancer", () => {
expect(lines[2]).toMatch(/^2#[ZPMQVRWSNKTXJBYH]{2}\|const y = 2$/) expect(lines[2]).toMatch(/^2#[ZPMQVRWSNKTXJBYH]{2}\|const y = 2$/)
}) })
it("appends LINE#ID output for write tool using metadata filepath", async () => { it("appends simple summary for write tool instead of full hashlined content", async () => {
//#given //#given
const hook = createHashlineReadEnhancerHook(mockCtx(), { hashline_edit: { enabled: true } }) const hook = createHashlineReadEnhancerHook(mockCtx(), { hashline_edit: { enabled: true } })
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "hashline-write-")) const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "hashline-write-"))
@ -181,9 +181,10 @@ describe("hashline-read-enhancer", () => {
await hook["tool.execute.after"](input, output) await hook["tool.execute.after"](input, output)
//#then //#then
expect(output.output).toContain("Updated file (LINE#ID|content):") expect(output.output).toContain("File written successfully.")
expect(output.output).toMatch(/1#[ZPMQVRWSNKTXJBYH]{2}\|const x = 1/) expect(output.output).toContain("2 lines written.")
expect(output.output).toMatch(/2#[ZPMQVRWSNKTXJBYH]{2}\|const y = 2/) expect(output.output).not.toContain("Updated file (LINE#ID|content):")
expect(output.output).not.toContain("const x = 1")
fs.rmSync(tempDir, { recursive: true, force: true }) fs.rmSync(tempDir, { recursive: true, force: true })
}) })