Skip to content

Commit d98661a

Browse files
committed
limit tool output
1 parent d966261 commit d98661a

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

packages/opencode/src/config/config.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,6 +1163,12 @@ export namespace Config {
11631163
.describe("Token buffer for compaction. Leaves enough window to avoid overflow during compaction."),
11641164
})
11651165
.optional(),
1166+
toolOutputMaxBytes: z
1167+
.number()
1168+
.int()
1169+
.positive()
1170+
.optional()
1171+
.describe("Maximum bytes for tool output before truncation (default: 51200)"),
11661172
experimental: z
11671173
.object({
11681174
disable_paste_summary: z.boolean().optional(),

packages/opencode/src/tool/truncation.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { Identifier } from "../id/id"
55
import { PermissionNext } from "../permission/next"
66
import type { Agent } from "../agent/agent"
77
import { Scheduler } from "../scheduler"
8+
import { Config } from "../config/config"
89

910
export namespace Truncate {
1011
export const MAX_LINES = 2000
@@ -48,8 +49,9 @@ export namespace Truncate {
4849
}
4950

5051
export async function output(text: string, options: Options = {}, agent?: Agent.Info): Promise<Result> {
52+
const cfg = await Config.get()
5153
const maxLines = options.maxLines ?? MAX_LINES
52-
const maxBytes = options.maxBytes ?? MAX_BYTES
54+
const maxBytes = options.maxBytes ?? cfg.toolOutputMaxBytes ?? MAX_BYTES
5355
const direction = options.direction ?? "head"
5456
const lines = text.split("\n")
5557
const totalBytes = Buffer.byteLength(text, "utf-8")

0 commit comments

Comments
 (0)