Skip to content

Commit c3e41c8

Browse files
committed
feat: truncate all the tool outputs
1 parent 08957ce commit c3e41c8

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

src/config/schema.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ export const ExperimentalConfigSchema = z.object({
113113
preemptive_compaction: z.boolean().optional(),
114114
/** Threshold percentage to trigger preemptive compaction (default: 0.80) */
115115
preemptive_compaction_threshold: z.number().min(0.5).max(0.95).optional(),
116+
/** Truncate all tool outputs, not just whitelisted tools (default: false) */
117+
truncate_all_tool_outputs: z.boolean().optional(),
116118
})
117119

118120
export const OhMyOpenCodeConfigSchema = z.object({

src/hooks/tool-output-truncator.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { PluginInput } from "@opencode-ai/plugin"
2+
import type { ExperimentalConfig } from "../config/schema"
23
import { createDynamicTruncator } from "../shared/dynamic-truncator"
34

45
const TRUNCATABLE_TOOLS = [
@@ -17,14 +18,19 @@ const TRUNCATABLE_TOOLS = [
1718
"Interactive_bash",
1819
]
1920

20-
export function createToolOutputTruncatorHook(ctx: PluginInput) {
21+
interface ToolOutputTruncatorOptions {
22+
experimental?: ExperimentalConfig
23+
}
24+
25+
export function createToolOutputTruncatorHook(ctx: PluginInput, options?: ToolOutputTruncatorOptions) {
2126
const truncator = createDynamicTruncator(ctx)
27+
const truncateAll = options?.experimental?.truncate_all_tool_outputs ?? false
2228

2329
const toolExecuteAfter = async (
2430
input: { tool: string; sessionID: string; callID: string },
2531
output: { title: string; output: string; metadata: unknown }
2632
) => {
27-
if (!TRUNCATABLE_TOOLS.includes(input.tool)) return
33+
if (!truncateAll && !TRUNCATABLE_TOOLS.includes(input.tool)) return
2834

2935
try {
3036
const { result, truncated } = await truncator.truncate(input.sessionID, output.output)

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ const OhMyOpenCodePlugin: Plugin = async (ctx) => {
251251
? createCommentCheckerHooks()
252252
: null;
253253
const toolOutputTruncator = isHookEnabled("tool-output-truncator")
254-
? createToolOutputTruncatorHook(ctx)
254+
? createToolOutputTruncatorHook(ctx, { experimental: pluginConfig.experimental })
255255
: null;
256256
const directoryAgentsInjector = isHookEnabled("directory-agents-injector")
257257
? createDirectoryAgentsInjectorHook(ctx)

0 commit comments

Comments
 (0)