From 4f088c7ab8febcf16815cf6f173f122c4af08603 Mon Sep 17 00:00:00 2001 From: YeonGyu-Kim Date: Mon, 9 Mar 2026 11:27:58 +0900 Subject: [PATCH] test(plugin): run tool output truncation before claude transcript hooks Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus --- src/plugin/tool-execute-after.test.ts | 35 +++++++++++++++++++++++++++ src/plugin/tool-execute-after.ts | 2 +- 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 src/plugin/tool-execute-after.test.ts diff --git a/src/plugin/tool-execute-after.test.ts b/src/plugin/tool-execute-after.test.ts new file mode 100644 index 000000000..cb70a91f8 --- /dev/null +++ b/src/plugin/tool-execute-after.test.ts @@ -0,0 +1,35 @@ +import { describe, expect, it } from "bun:test" +import { createToolExecuteAfterHandler } from "./tool-execute-after" + +describe("createToolExecuteAfterHandler", () => { + it("#given truncator changes output #when tool.execute.after runs #then claudeCodeHooks receives truncated output", async () => { + const callOrder: string[] = [] + let claudeSawOutput = "" + + const handler = createToolExecuteAfterHandler({ + ctx: { directory: "/repo" } as never, + hooks: { + toolOutputTruncator: { + "tool.execute.after": async (_input, output) => { + callOrder.push("truncator") + output.output = "truncated output" + }, + }, + claudeCodeHooks: { + "tool.execute.after": async (_input, output) => { + callOrder.push("claude") + claudeSawOutput = output.output + }, + }, + } as never, + }) + + await handler( + { tool: "hashline_edit", sessionID: "ses_test", callID: "call_test" }, + { title: "result", output: "original output", metadata: {} } + ) + + expect(callOrder).toEqual(["truncator", "claude"]) + expect(claudeSawOutput).toBe("truncated output") + }) +}) diff --git a/src/plugin/tool-execute-after.ts b/src/plugin/tool-execute-after.ts index 4dfeda03c..1d08d29e5 100644 --- a/src/plugin/tool-execute-after.ts +++ b/src/plugin/tool-execute-after.ts @@ -56,8 +56,8 @@ export function createToolExecuteAfterHandler(args: { } } - await hooks.claudeCodeHooks?.["tool.execute.after"]?.(input, output) await hooks.toolOutputTruncator?.["tool.execute.after"]?.(input, output) + await hooks.claudeCodeHooks?.["tool.execute.after"]?.(input, output) await hooks.preemptiveCompaction?.["tool.execute.after"]?.(input, output) await hooks.contextWindowMonitor?.["tool.execute.after"]?.(input, output) await hooks.commentChecker?.["tool.execute.after"]?.(input, output)