Tool names in builtinTools are lowercase ('grep', 'glob') but truncator
hooks were checking for capitalized names ('Grep', 'Glob'), causing
truncation to never trigger and resulting in context window overflow.
🤖 GENERATED WITH ASSISTANCE OF [OhMyOpenCode](https://github.com/code-yeongyu/oh-my-opencode)
41 lines
1001 B
TypeScript
41 lines
1001 B
TypeScript
import type { PluginInput } from "@opencode-ai/plugin"
|
|
import { createDynamicTruncator } from "../shared/dynamic-truncator"
|
|
|
|
const TRUNCATABLE_TOOLS = [
|
|
"grep",
|
|
"Grep",
|
|
"safe_grep",
|
|
"glob",
|
|
"Glob",
|
|
"safe_glob",
|
|
"lsp_find_references",
|
|
"lsp_document_symbols",
|
|
"lsp_workspace_symbols",
|
|
"lsp_diagnostics",
|
|
"ast_grep_search",
|
|
]
|
|
|
|
export function createToolOutputTruncatorHook(ctx: PluginInput) {
|
|
const truncator = createDynamicTruncator(ctx)
|
|
|
|
const toolExecuteAfter = async (
|
|
input: { tool: string; sessionID: string; callID: string },
|
|
output: { title: string; output: string; metadata: unknown }
|
|
) => {
|
|
if (!TRUNCATABLE_TOOLS.includes(input.tool)) return
|
|
|
|
try {
|
|
const { result, truncated } = await truncator.truncate(input.sessionID, output.output)
|
|
if (truncated) {
|
|
output.output = result
|
|
}
|
|
} catch {
|
|
// Graceful degradation - don't break tool execution
|
|
}
|
|
}
|
|
|
|
return {
|
|
"tool.execute.after": toolExecuteAfter,
|
|
}
|
|
}
|