feat: truncate all the tool outputs

This commit is contained in:
YeonGyu-Kim
2025-12-22 14:16:50 +09:00
parent 08957ce1f0
commit c3e41c8363
3 changed files with 11 additions and 3 deletions

View File

@@ -113,6 +113,8 @@ export const ExperimentalConfigSchema = z.object({
preemptive_compaction: z.boolean().optional(),
/** Threshold percentage to trigger preemptive compaction (default: 0.80) */
preemptive_compaction_threshold: z.number().min(0.5).max(0.95).optional(),
/** Truncate all tool outputs, not just whitelisted tools (default: false) */
truncate_all_tool_outputs: z.boolean().optional(),
})
export const OhMyOpenCodeConfigSchema = z.object({

View File

@@ -1,4 +1,5 @@
import type { PluginInput } from "@opencode-ai/plugin"
import type { ExperimentalConfig } from "../config/schema"
import { createDynamicTruncator } from "../shared/dynamic-truncator"
const TRUNCATABLE_TOOLS = [
@@ -17,14 +18,19 @@ const TRUNCATABLE_TOOLS = [
"Interactive_bash",
]
export function createToolOutputTruncatorHook(ctx: PluginInput) {
interface ToolOutputTruncatorOptions {
experimental?: ExperimentalConfig
}
export function createToolOutputTruncatorHook(ctx: PluginInput, options?: ToolOutputTruncatorOptions) {
const truncator = createDynamicTruncator(ctx)
const truncateAll = options?.experimental?.truncate_all_tool_outputs ?? false
const toolExecuteAfter = async (
input: { tool: string; sessionID: string; callID: string },
output: { title: string; output: string; metadata: unknown }
) => {
if (!TRUNCATABLE_TOOLS.includes(input.tool)) return
if (!truncateAll && !TRUNCATABLE_TOOLS.includes(input.tool)) return
try {
const { result, truncated } = await truncator.truncate(input.sessionID, output.output)

View File

@@ -251,7 +251,7 @@ const OhMyOpenCodePlugin: Plugin = async (ctx) => {
? createCommentCheckerHooks()
: null;
const toolOutputTruncator = isHookEnabled("tool-output-truncator")
? createToolOutputTruncatorHook(ctx)
? createToolOutputTruncatorHook(ctx, { experimental: pluginConfig.experimental })
: null;
const directoryAgentsInjector = isHookEnabled("directory-agents-injector")
? createDirectoryAgentsInjectorHook(ctx)