Files
oh-my-opencode-free-fork/src/hooks/tool-output-truncator.ts
YeonGyu-Kim 03a450131d refactor(hooks): improve interactive bash session tracking and command parsing
- Replace regex-based session extraction with quote-aware tokenizer
- Add proper tmux global options handling (-L, -S, -f, -c, -T)
- Add normalizeSessionName to strip :window and .pane suffixes
- Add findSubcommand for proper subcommand detection
- Add early error output return to avoid false state tracking
- Fix tool-output-truncator to exclude grep/Grep from generic truncation
- Fix todo-continuation-enforcer to clear reminded state on assistant response
- Add proper parallel stdout/stderr reading in interactive_bash tool
- Improve error handling with proper exit code checking

🤖 GENERATED WITH ASSISTANCE OF [OhMyOpenCode](https://github.com/code-yeongyu/oh-my-opencode)
2025-12-15 19:14:06 +09:00

42 lines
1.1 KiB
TypeScript

import type { PluginInput } from "@opencode-ai/plugin"
import { createDynamicTruncator } from "../shared/dynamic-truncator"
// Note: "grep" and "Grep" are handled by dedicated grep-output-truncator.ts
const TRUNCATABLE_TOOLS = [
"safe_grep",
"glob",
"Glob",
"safe_glob",
"lsp_find_references",
"lsp_document_symbols",
"lsp_workspace_symbols",
"lsp_diagnostics",
"ast_grep_search",
"interactive_bash",
"Interactive_bash",
]
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,
}
}